From ebd1a3a1309a2088fac4a5f068a5fb38b3600124 Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Tue, 16 Jan 2007 14:43:01 +0000 Subject: [PATCH] some more work on menus... fixed bug #953 and some more stuff git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19827 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/Menu.cpp | 16 ++++++++++++---- src/kits/interface/MenuBar.cpp | 30 +++++++++++++++++++----------- src/kits/interface/MenuField.cpp | 3 +-- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/src/kits/interface/Menu.cpp b/src/kits/interface/Menu.cpp index 59ad45666b..91cc9c8577 100644 --- a/src/kits/interface/Menu.cpp +++ b/src/kits/interface/Menu.cpp @@ -1321,9 +1321,11 @@ BMenu::_track(int *action, bigtime_t trackTime, long start) } if (fSuper != NULL) { + // Give supermenu the chance to continue tracking *action = fState; if (locked) - UnlockLooper(); + UnlockLooper(); + return NULL; } } @@ -1349,7 +1351,7 @@ BMenu::_track(int *action, bigtime_t trackTime, long start) if (IsStickyMode()) SetStickyMode(false); - + // delete the menu window recycled for all the child menus DeleteMenuWindow(); @@ -1770,7 +1772,13 @@ BMenu::DrawItems(BRect updateRect) int BMenu::State(BMenuItem **item) const { - return 0; + if (fState == MENU_STATE_TRACKING || fState == MENU_STATE_CLOSED) + return fState; + + if (fSelected != NULL && fSelected->Submenu() != NULL) + return fSelected->Submenu()->State(item); + + return fState; } @@ -1933,7 +1941,7 @@ BMenu::_SelectItem(BMenuItem* menuItem, bool showSubmenu, bool selectFirstItem) fSelected->Select(false); BMenu *subMenu = fSelected->Submenu(); if (subMenu != NULL && subMenu->Window() != NULL) - subMenu->_hide(); + subMenu->_hide(); } fSelected = menuItem; diff --git a/src/kits/interface/MenuBar.cpp b/src/kits/interface/MenuBar.cpp index 39d34cc81c..7014b7eef5 100644 --- a/src/kits/interface/MenuBar.cpp +++ b/src/kits/interface/MenuBar.cpp @@ -382,7 +382,7 @@ BMenuBar::TrackTask(void *arg) receive_data(&id, &data, sizeof(data)); BMenuBar *menuBar = data.menuBar; - if (data.useRect) + if (data.useRect) menuBar->fExtraRect = &data.rect; menuBar->SetStickyMode(data.sticky); @@ -433,7 +433,7 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu) BPoint where; ulong buttons; GetMouse(&where, &buttons, true); - + BMenuItem *menuItem = HitTestItems(where, B_ORIGIN); if (menuItem != NULL) { // Select item if: @@ -474,17 +474,24 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu) menu->SetStickyMode(true); int localAction; fChosenItem = menu->_track(&localAction, system_time()); - + if (menu->State(NULL) == MENU_STATE_TRACKING && menu->IsStickyMode()) + menu->SetStickyMode(false); + // check if the user started holding down a mouse button in a submenu if (wasSticky && !IsStickyMode()) buttons = 1; // buttons must have been pressed in the meantime + + if (localAction == MENU_STATE_CLOSED) { + if (fExtraRect != NULL && fExtraRect->Contains(where)) { + SetStickyMode(true); + fExtraRect = NULL; + } else + fState = MENU_STATE_CLOSED; + } - if (localAction == MENU_STATE_CLOSED) - fState = MENU_STATE_CLOSED; - - } else if (menuItem == NULL && fSelected != NULL - && !IsStickyMode() && fState != MENU_STATE_TRACKING_SUBMENU) { + } else if (menuItem == NULL && fSelected != NULL + && !IsStickyMode() /*&& Bounds().Contains(where)*/ && fState != MENU_STATE_TRACKING_SUBMENU) { _SelectItem(NULL); fState = MENU_STATE_TRACKING; } @@ -506,10 +513,11 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu) if (snoozeAmount > 0) snooze(snoozeAmount); } - + if (window->Lock()) { if (fSelected != NULL) - _SelectItem(NULL); + _SelectItem(NULL); + if (fChosenItem != NULL) fChosenItem->Invoke(); RestoreFocus(); @@ -534,7 +542,7 @@ BMenuBar::StealFocus() // We already stole the focus, don't do anything if (fPrevFocusToken != -1) return; - + BWindow *window = Window(); if (window != NULL && window->Lock()) { BView *focus = window->CurrentFocus(); diff --git a/src/kits/interface/MenuField.cpp b/src/kits/interface/MenuField.cpp index 3e5c4d573f..976a02c488 100644 --- a/src/kits/interface/MenuField.cpp +++ b/src/kits/interface/MenuField.cpp @@ -282,8 +282,7 @@ BMenuField::MouseDown(BPoint where) fMenuBar->StartMenuBar(-1, false, true, &bounds); - fMenuTaskID = spawn_thread((thread_func)MenuTask, "_m_task_", - B_NORMAL_PRIORITY, this); + fMenuTaskID = spawn_thread((thread_func)MenuTask, "_m_task_", B_NORMAL_PRIORITY, this); if (fMenuTaskID) resume_thread(fMenuTaskID); }