From a0394110da7d51bdae5bb8bc9adb6f1c413bff87 Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Wed, 19 Jan 2005 10:52:40 +0000 Subject: [PATCH] We have submenus working (still not perfect, though) git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10869 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/Menu.cpp | 38 ++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/kits/interface/Menu.cpp b/src/kits/interface/Menu.cpp index 1c6ec8e4e3..55be3d233e 100644 --- a/src/kits/interface/Menu.cpp +++ b/src/kits/interface/Menu.cpp @@ -1085,10 +1085,11 @@ BMenu::_hide() BMenuItem * BMenu::_track(int *action, long start) { - // TODO: Take Sticky mode into account, handle submenus + // TODO: Take Sticky mode into account BPoint location; ulong buttons; BMenuItem *item = NULL; + int localAction = 0; do { if (LockLooper()) { GetMouse(&location, &buttons); @@ -1102,9 +1103,29 @@ BMenu::_track(int *action, long start) // TODO: Sometimes the menu flickers a bit. // try to be smarter and suggest an update area, // instead of invalidating the whole view. - if (item != NULL && item != fSelected) { - SelectItem(item); - Invalidate(); + if (item != NULL) { + if (item != fSelected) { + SelectItem(item); + Invalidate(); + } + + int submenuAction = 0; + BMenuItem *submenuItem = NULL; + // TODO: Review this as it doesn't work very well, + // BMenu::_track() isn't always called when needed. + if (item->Submenu() != NULL) { + UnlockLooper(); + + submenuItem = item->Submenu()->_track(&submenuAction); + if (submenuAction == 5) { + item = submenuItem; + localAction = submenuAction; + break; + } + + if (!LockLooper()) + break; + } } UnlockLooper(); @@ -1117,13 +1138,16 @@ BMenu::_track(int *action, long start) // would be nice. Consider building an enum // with the possible actions, and putting it in a // private, shared header (BMenuBar needs to know about them too). - if (action != NULL) { + if (localAction == 0) { if (buttons != 0) - *action = 0; + localAction = 0; else - *action = 5; + localAction = 5; } + if (action != NULL) + *action = localAction; + if (LockLooper()) { SelectItem(NULL); UnlockLooper();