an eventually opened menu is now quit in BWindow::DispatchMessage()

before sending a B_MOUSE_DOWN message to any other view. This fixes bug 
594 for real and another bug in BMenuBar.  BMenuBar tracking will also 
be simplified a bit because of this. Install items to a NULL window on 
Show() as does R5 (although I don't know why yet). 


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17605 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2006-05-27 09:57:14 +00:00
parent a502e8cd6e
commit e061d1bae5
4 changed files with 37 additions and 13 deletions
+2
View File
@@ -236,6 +236,8 @@ virtual void _ReservedMenu6();
void RedrawAfterSticky(BRect bounds); void RedrawAfterSticky(BRect bounds);
bool OkToProceed(BMenuItem *); bool OkToProceed(BMenuItem *);
void QuitTracking();
status_t ParseMsg(BMessage *msg, int32 *sindex, BMessage *spec, status_t ParseMsg(BMessage *msg, int32 *sindex, BMessage *spec,
int32 *form, const char **prop, int32 *form, const char **prop,
BMenu **tmenu, BMenuItem **titem, int32 *user_data, BMenu **tmenu, BMenuItem **titem, int32 *user_data,
+19 -11
View File
@@ -317,6 +317,7 @@ BMenu::AddItem(BMenuItem *item, int32 index)
if (!_AddItem(item, index)) if (!_AddItem(item, index))
return false; return false;
InvalidateLayout();
if (LockLooper()) { if (LockLooper()) {
if (!Window()->IsHidden()) { if (!Window()->IsHidden()) {
LayoutItems(index); LayoutItems(index);
@@ -432,8 +433,9 @@ BMenu::AddList(BList *list, int32 index)
if (!_AddItem(item, index + i)) if (!_AddItem(item, index + i))
break; break;
} }
} }
InvalidateLayout();
if (locked && Window() != NULL && !Window()->IsHidden()) { if (locked && Window() != NULL && !Window()->IsHidden()) {
// Make sure we update the layout if needed. // Make sure we update the layout if needed.
LayoutItems(index); LayoutItems(index);
@@ -1020,6 +1022,7 @@ BMenu::Show()
void void
BMenu::Show(bool selectFirst) BMenu::Show(bool selectFirst)
{ {
Install(NULL);
_show(selectFirst); _show(selectFirst);
} }
@@ -1028,6 +1031,7 @@ void
BMenu::Hide() BMenu::Hide()
{ {
_hide(); _hide();
Uninstall();
} }
@@ -1302,19 +1306,19 @@ BMenu::_track(int *action, bigtime_t trackTime, long start)
if (locked) if (locked)
UnlockLooper(); UnlockLooper();
if (buttons != 0 && IsStickyMode()) { if (buttons != 0 && IsStickyMode())
fState = MENU_STATE_CLOSED; fState = MENU_STATE_CLOSED;
break; else if (buttons == 0 && !IsStickyMode()) {
} else if (buttons == 0 && !IsStickyMode()) {
if (system_time() < trackTime + 1000000 if (system_time() < trackTime + 1000000
|| (fExtraRect != NULL && fExtraRect->Contains(location))) || (fExtraRect != NULL && fExtraRect->Contains(location)))
SetStickyMode(true); SetStickyMode(true);
else { else
fState = MENU_STATE_CLOSED; fState = MENU_STATE_CLOSED;
break;
}
} }
if (fState == MENU_STATE_CLOSED)
break;
snooze(snoozeAmount); snooze(snoozeAmount);
} }
@@ -1358,10 +1362,6 @@ BMenu::_AddItem(BMenuItem *item, int32 index)
item->SetSuper(this); item->SetSuper(this);
// TODO: Sometimes the menu layout isn't invalidated correctly,
// So we force a rebuild of the whole menu layout. Remove this!
InvalidateLayout();
return true; return true;
} }
@@ -2061,6 +2061,14 @@ BMenu::OkToProceed(BMenuItem* item)
} }
void
BMenu::QuitTracking()
{
fState = MENU_STATE_CLOSED;
}
status_t status_t
BMenu::ParseMsg(BMessage *msg, int32 *sindex, BMessage *spec, BMenu::ParseMsg(BMessage *msg, int32 *sindex, BMessage *spec,
int32 *form, const char **prop, BMenu **tmenu, int32 *form, const char **prop, BMenu **tmenu,
+4 -1
View File
@@ -390,7 +390,7 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu)
// TODO: Cleanup, merge some "if" blocks if possible // TODO: Cleanup, merge some "if" blocks if possible
BMenuItem *resultItem = NULL; BMenuItem *resultItem = NULL;
BWindow *window = Window(); BWindow *window = Window();
int localAction = MENU_STATE_TRACKING; int localAction = fState = MENU_STATE_TRACKING;
while (true) { while (true) {
bigtime_t snoozeAmount = 40000; bigtime_t snoozeAmount = 40000;
bool locked = window->Lock();//WithTimeout(200000) bool locked = window->Lock();//WithTimeout(200000)
@@ -461,6 +461,9 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu)
SetStickyMode(true); SetStickyMode(true);
} }
if (fState == MENU_STATE_CLOSED)
break;
if (snoozeAmount > 0) if (snoozeAmount > 0)
snooze(snoozeAmount); snooze(snoozeAmount);
} }
+12 -1
View File
@@ -26,6 +26,7 @@
#include <AppMisc.h> #include <AppMisc.h>
#include <ApplicationPrivate.h> #include <ApplicationPrivate.h>
#include <InputServerTypes.h> #include <InputServerTypes.h>
#include <MenuPrivate.h>
#include <MessagePrivate.h> #include <MessagePrivate.h>
#include <PortLink.h> #include <PortLink.h>
#include <ServerProtocol.h> #include <ServerProtocol.h>
@@ -317,6 +318,10 @@ BWindow::~BWindow()
{ {
Lock(); Lock();
if (BMenu *menu = dynamic_cast<BMenu *>(fFocus)) {
menu->QuitTracking();
}
// Wait if a menu is still tracking // Wait if a menu is still tracking
if (fMenuSem > 0) { if (fMenuSem > 0) {
while (acquire_sem(fMenuSem) == B_INTERRUPTED) while (acquire_sem(fMenuSem) == B_INTERRUPTED)
@@ -904,6 +909,11 @@ FrameMoved(origin);
case B_MOUSE_DOWN: case B_MOUSE_DOWN:
{ {
// Close an eventually opened menu.
if (BMenu *menu = dynamic_cast<BMenu *>(fFocus)) {
menu->QuitTracking();
}
if (BView *view = dynamic_cast<BView *>(target)) { if (BView *view = dynamic_cast<BView *>(target)) {
BPoint where; BPoint where;
msg->FindPoint("be:view_where", &where); msg->FindPoint("be:view_where", &where);
@@ -1544,7 +1554,8 @@ BWindow::FindView(BPoint point) const
} }
BView *BWindow::CurrentFocus() const BView *
BWindow::CurrentFocus() const
{ {
return fFocus; return fFocus;
} }