From 1435d9d362638da957697e0ba69933d4d15567c0 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Thu, 22 Feb 2018 01:15:57 +0100 Subject: [PATCH] Generalize mouse event passing in FMenuItem --- ChangeLog | 3 + Makefile.am | 2 +- Makefile.in | 7 +- include/final/fmenuitem.h | 4 +- src/fmenuitem.cpp | 196 ++++++++++++-------------------------- 5 files changed, 70 insertions(+), 142 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6d6e5130..1050e4f4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2017-02-22 Markus Gans + * Generalize mouse event passing in FMenuItem + 2017-02-19 Markus Gans * Refactoring FTerm::init_termcaps * Refactoring FTerm::init_encoding diff --git a/Makefile.am b/Makefile.am index cd81e826..ecf139be 100644 --- a/Makefile.am +++ b/Makefile.am @@ -9,4 +9,4 @@ ACLOCAL_AMFLAGS = -I m4 SUBDIRS = src fonts doc examples docdir = ${datadir}/doc/${PACKAGE} -doc_DATA = AUTHORS COPYING ChangeLog +doc_DATA = AUTHORS COPYING COPYING.LESSER ChangeLog diff --git a/Makefile.in b/Makefile.in index b3290a09..dec5e8e8 100644 --- a/Makefile.in +++ b/Makefile.in @@ -85,8 +85,9 @@ host_triplet = @host@ subdir = . DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ $(top_srcdir)/configure $(am__configure_deps) \ - $(srcdir)/config.h.in AUTHORS COPYING ChangeLog compile \ - config.guess config.sub depcomp install-sh missing ltmain.sh + $(srcdir)/config.h.in AUTHORS COPYING COPYING.LESSER ChangeLog \ + compile config.guess config.sub depcomp install-sh missing \ + ltmain.sh ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/ax_prefix_config_h.m4 \ $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ @@ -354,7 +355,7 @@ top_srcdir = @top_srcdir@ AUTOMAKE_OPTIONS = foreign ACLOCAL_AMFLAGS = -I m4 SUBDIRS = src fonts doc examples -doc_DATA = AUTHORS COPYING ChangeLog +doc_DATA = AUTHORS COPYING COPYING.LESSER ChangeLog all: config.h $(MAKE) $(AM_MAKEFLAGS) all-recursive diff --git a/include/final/fmenuitem.h b/include/final/fmenuitem.h index 8bf29bba..ffd50069 100644 --- a/include/final/fmenuitem.h +++ b/include/final/fmenuitem.h @@ -3,7 +3,7 @@ * * * This file is part of the Final Cut widget toolkit * * * -* Copyright 2015-2017 Markus Gans * +* Copyright 2015-2018 Markus Gans * * * * The Final Cut is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public License * @@ -169,6 +169,8 @@ class FMenuItem : public FWidget void processActivate(); void processDeactivate(); void createDialogList (FMenu*); + template + void passMouseEvent (T, FMouseEvent*, fc::events); // Callback methods void cb_switchToDialog (FWidget*, data_ptr); diff --git a/src/fmenuitem.cpp b/src/fmenuitem.cpp index 410feff0..3e9d1377 100644 --- a/src/fmenuitem.cpp +++ b/src/fmenuitem.cpp @@ -3,7 +3,7 @@ * * * This file is part of the Final Cut widget toolkit * * * -* Copyright 2015-2017 Markus Gans * +* Copyright 2015-2018 Markus Gans * * * * The Final Cut is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public License * @@ -341,72 +341,22 @@ void FMenuItem::onMouseDoubleClick (FMouseEvent* ev) if ( ! super_menu ) return; - const FPoint& t = ev->getTermPos(); - int b = ev->getButton(); - if ( isMenu(super_menu) ) { FMenu* smenu = static_cast(super_menu); - const FPoint& p2 = smenu->termToWidgetPos(t); - - try - { - FMouseEvent* _ev = new FMouseEvent ( fc::MouseDoubleClick_Event - , p2, t, b ); - smenu->onMouseDoubleClick(_ev); - delete _ev; - } - catch (const std::bad_alloc& ex) - { - std::cerr << "not enough memory to alloc " - << ex.what() << std::endl; - } + passMouseEvent (smenu, ev, fc::MouseDoubleClick_Event); } if ( isMenuBar(super_menu) ) { FMenuBar* mbar = static_cast(super_menu); - - if ( mbar ) - { - const FPoint& p2 = mbar->termToWidgetPos(t); - - try - { - FMouseEvent* _ev = new FMouseEvent ( fc::MouseDoubleClick_Event - , p2, t, b ); - mbar->onMouseDoubleClick(_ev); - delete _ev; - } - catch (const std::bad_alloc& ex) - { - std::cerr << "not enough memory to alloc " - << ex.what() << std::endl; - } - } + passMouseEvent (mbar, ev, fc::MouseDoubleClick_Event); } if ( isWindowsMenu(super_menu) ) { FDialog* dgl = static_cast(super_menu); - - if ( dgl ) - { - const FPoint& p2 = dgl->termToWidgetPos(t); - - try - { - FMouseEvent* _ev = new FMouseEvent ( fc::MouseDoubleClick_Event - , p2, t, b ); - dgl->onMouseDoubleClick(_ev); - delete _ev; - } - catch (const std::bad_alloc& ex) - { - std::cerr << "not enough memory to alloc " - << ex.what() << std::endl; - } - } + passMouseEvent (dgl, ev, fc::MouseDoubleClick_Event); } } @@ -416,72 +366,22 @@ void FMenuItem::onMouseDown (FMouseEvent* ev) if ( ! super_menu ) return; - const FPoint& t = ev->getTermPos(); - int b = ev->getButton(); - if ( isMenu(super_menu) ) { FMenu* smenu = static_cast(super_menu); - const FPoint& p2 = smenu->termToWidgetPos(t); - - try - { - FMouseEvent* _ev = new FMouseEvent ( fc::MouseDown_Event - , p2, t, b ); - smenu->onMouseDown(_ev); - delete _ev; - } - catch (const std::bad_alloc& ex) - { - std::cerr << "not enough memory to alloc " - << ex.what() << std::endl; - } + passMouseEvent (smenu, ev, fc::MouseDown_Event); } if ( isMenuBar(super_menu) ) { FMenuBar* mbar = static_cast(super_menu); - - if ( mbar ) - { - const FPoint& p2 = mbar->termToWidgetPos(t); - - try - { - FMouseEvent* _ev = new FMouseEvent ( fc::MouseDown_Event - , p2, t, b ); - mbar->onMouseDown(_ev); - delete _ev; - } - catch (const std::bad_alloc& ex) - { - std::cerr << "not enough memory to alloc " - << ex.what() << std::endl; - } - } + passMouseEvent (mbar, ev, fc::MouseDown_Event); } if ( isWindowsMenu(super_menu) ) { FDialog* dgl = static_cast(super_menu); - - if ( dgl ) - { - const FPoint& p2 = dgl->termToWidgetPos(t); - - try - { - FMouseEvent* _ev = new FMouseEvent ( fc::MouseDown_Event - , p2, t, b ); - dgl->onMouseDown(_ev); - delete _ev; - } - catch (const std::bad_alloc& ex) - { - std::cerr << "not enough memory to alloc " - << ex.what() << std::endl; - } - } + passMouseEvent (dgl, ev, fc::MouseDown_Event); } } @@ -491,34 +391,22 @@ void FMenuItem::onMouseUp (FMouseEvent* ev) if ( ! super_menu ) return; - const FPoint& t = ev->getTermPos(); - int b = ev->getButton(); - if ( isMenu(super_menu) ) { FMenu* smenu = static_cast(super_menu); - const FPoint& p2 = smenu->termToWidgetPos(t); - FMouseEvent* _ev = new FMouseEvent (fc::MouseUp_Event, p2, t, b); - smenu->onMouseUp(_ev); - delete _ev; + passMouseEvent (smenu, ev, fc::MouseUp_Event); } if ( isMenuBar(super_menu) ) { FMenuBar* mbar = static_cast(super_menu); - const FPoint& p2 = mbar->termToWidgetPos(t); - FMouseEvent* _ev = new FMouseEvent (fc::MouseUp_Event, p2, t, b); - mbar->onMouseUp(_ev); - delete _ev; + passMouseEvent (mbar, ev, fc::MouseUp_Event); } if ( isWindowsMenu(super_menu) ) { FDialog* dgl = static_cast(super_menu); - const FPoint& p2 = dgl->termToWidgetPos(t); - FMouseEvent* _ev = new FMouseEvent (fc::MouseUp_Event, p2, t, b); - dgl->onMouseUp(_ev); - delete _ev; + passMouseEvent (dgl, ev, fc::MouseUp_Event); } } @@ -528,34 +416,22 @@ void FMenuItem::onMouseMove (FMouseEvent* ev) if ( ! super_menu ) return; - const FPoint& t = ev->getTermPos(); - int b = ev->getButton(); - if ( isMenu(super_menu) ) { FMenu* smenu = static_cast(super_menu); - const FPoint& p2 = smenu->termToWidgetPos(t); - FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p2, t, b); - smenu->onMouseMove(_ev); - delete _ev; + passMouseEvent (smenu, ev, fc::MouseMove_Event); } if ( isMenuBar(super_menu) ) { FMenuBar* mbar = static_cast(super_menu); - const FPoint& p2 = mbar->termToWidgetPos(t); - FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p2, t, b); - mbar->onMouseMove(_ev); - delete _ev; + passMouseEvent (mbar, ev, fc::MouseMove_Event); } if ( isWindowsMenu(super_menu) ) { FDialog* dgl = static_cast(super_menu); - const FPoint& p2 = dgl->termToWidgetPos(t); - FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p2, t, b); - dgl->onMouseMove(_ev); - delete _ev; + passMouseEvent (dgl, ev, fc::MouseMove_Event); } } @@ -817,6 +693,52 @@ void FMenuItem::createDialogList (FMenu* winmenu) winmenu->calculateDimensions(); } +//---------------------------------------------------------------------- +template +void FMenuItem::passMouseEvent ( T widget, FMouseEvent* ev + , fc::events ev_type ) +{ + if ( ! widget ) + return; + + FMouseEvent* _ev; + const FPoint& t = ev->getTermPos(); + const FPoint& p2 = widget->termToWidgetPos(t); + int b = ev->getButton(); + + try + { + _ev = new FMouseEvent (ev_type, p2, t, b); + } + catch (const std::bad_alloc& ex) + { + std::cerr << "not enough memory to alloc " + << ex.what() << std::endl; + return; + } + + switch ( int(ev_type) ) + { + case fc::MouseDoubleClick_Event: + widget->onMouseDoubleClick(_ev); + break; + + case fc::MouseDown_Event: + widget->onMouseDown(_ev); + break; + + case fc::MouseUp_Event: + widget->onMouseUp(_ev); + break; + + case fc::MouseMove_Event: + widget->onMouseMove(_ev); + break; + } + + delete _ev; +} + //---------------------------------------------------------------------- void FMenuItem::cb_switchToDialog (FWidget*, data_ptr data) {