From 53ada3664c354d41592b2e8a609ce15bc8a88ebe Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Sun, 22 Nov 2015 23:54:05 +0100 Subject: [PATCH] Add sub-menu support --- src/fmenu.cpp | 29 ++++++++++++++++++++++++++--- src/fmenubar.cpp | 6 +++++- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/fmenu.cpp b/src/fmenu.cpp index 9cdc5183..264c0805 100644 --- a/src/fmenu.cpp +++ b/src/fmenu.cpp @@ -989,7 +989,9 @@ void FMenu::onMouseMove (FMouseEvent* ev) { std::vector::const_iterator iter, end; bool focus_changed = false; + bool mouse_over_menu = false; bool mouse_over_submenu = false; + bool mouse_over_supermenu = false; bool hide_sub_menu = false; FMenu* show_sub_menu = 0; FPoint mouse_pos; @@ -999,6 +1001,9 @@ void FMenu::onMouseMove (FMouseEvent* ev) mouse_pos = ev->getPos(); mouse_pos -= FPoint(getRightPadding(),getTopPadding()); + if ( getGeometryGlobal().contains(ev->getGlobalPos()) ) + mouse_over_menu = true; + if ( open_sub_menu ) { const FRect& submenu_geometry = open_sub_menu->getGeometryGlobal(); @@ -1006,6 +1011,13 @@ void FMenu::onMouseMove (FMouseEvent* ev) mouse_over_submenu = true; } + if ( isSubMenu() ) + { + const FRect& supermenu_geometry = getSuperMenu()->getGeometryGlobal(); + if ( supermenu_geometry.contains(ev->getGlobalPos()) ) + mouse_over_supermenu = true; + } + while ( iter != end ) { int x1, x2, y, mouse_x, mouse_y; @@ -1048,7 +1060,7 @@ void FMenu::onMouseMove (FMouseEvent* ev) } else { - if ( getGeometryGlobal().contains(ev->getGlobalPos()) + if ( mouse_over_menu && (*iter)->isEnabled() && (*iter)->isSelected() && ! mouse_over_submenu ) @@ -1074,8 +1086,19 @@ void FMenu::onMouseMove (FMouseEvent* ev) setClickedWidget(open_sub_menu); open_sub_menu->onMouseMove(ev); } - else if ( ! hasSelectedItem() && statusBar() - && getGeometryGlobal().contains(ev->getGlobalPos()) ) + else if ( ! mouse_over_menu && mouse_over_supermenu ) + { + // Mouse event handover to super-menu + FMenu* smenu = dynamic_cast(getSuperMenu()); + const FPoint& g = ev->getGlobalPos(); + const FPoint& p = smenu->globalToLocalPos(g); + int b = ev->getButton(); + ev = new FMouseEvent (MouseMove_Event, p, g, b); + smenu->mouse_down = true; + setClickedWidget(smenu); + smenu->onMouseMove(ev); + } + else if ( ! hasSelectedItem() && statusBar() && mouse_over_menu ) { // Mouse is over border or separator FString msg = getStatusbarMessage(); diff --git a/src/fmenubar.cpp b/src/fmenubar.cpp index 1a7a475b..d5607e8b 100644 --- a/src/fmenubar.cpp +++ b/src/fmenubar.cpp @@ -698,6 +698,7 @@ void FMenuBar::onMouseMove (FMouseEvent* ev) { std::vector::const_iterator iter, end; int mouse_x, mouse_y; + bool mouse_over_menubar = false; bool focus_changed = false; iter = itemlist.begin(); @@ -705,6 +706,9 @@ void FMenuBar::onMouseMove (FMouseEvent* ev) mouse_x = ev->getX(); mouse_y = ev->getY(); + if ( getGeometryGlobal().contains(ev->getGlobalPos()) ) + mouse_over_menubar = true; + while ( iter != end ) { int x1, x2; @@ -746,7 +750,7 @@ void FMenuBar::onMouseMove (FMouseEvent* ev) } else { - if ( getGeometryGlobal().contains(ev->getGlobalPos()) + if ( mouse_over_menubar && (*iter)->isEnabled() && (*iter)->isSelected() ) {