Avoid calling ComputeLayout() if the menu is not attached to a BWindow. Small cleanups.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13438 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2005-07-05 11:53:03 +00:00
parent 715166d5b8
commit 2323effaee
+44 -43
View File
@@ -1101,43 +1101,43 @@ BMenu::_track(int *action, long start)
BMenuItem *item = NULL; BMenuItem *item = NULL;
int localAction = MENU_ACT_NONE; int localAction = MENU_ACT_NONE;
do { do {
if (LockLooper()) { if (!LockLooper())
GetMouse(&location, &buttons); break;
if (OverSuper(location)) {
UnlockLooper(); GetMouse(&location, &buttons);
if (OverSuper(location)) {
UnlockLooper();
break;
}
item = HitTestItems(location, B_ORIGIN);
if (item != NULL) {
if (item != fSelected)
SelectItem(item);
} else if (fSelected != NULL) {
BPoint screenLocation = location;
ConvertToScreen(&screenLocation);
if (!OverSubmenu(fSelected, screenLocation))
SelectItem(NULL);
}
if (fSelected != NULL && fSelected->Submenu() != NULL) {
UnlockLooper();
int submenuAction = MENU_ACT_NONE;
BMenuItem *submenuItem = fSelected->Submenu()->_track(&submenuAction);
if (submenuAction == MENU_ACT_CLOSE) {
item = submenuItem;
localAction = submenuAction;
break; break;
} }
item = HitTestItems(location, B_ORIGIN); if (!LockLooper())
break;
if (item != NULL) {
if (item != fSelected)
SelectItem(item);
} else if (fSelected != NULL) {
BPoint screenLocation = location;
ConvertToScreen(&screenLocation);
if (!OverSubmenu(fSelected, screenLocation))
SelectItem(NULL);
}
int submenuAction = MENU_ACT_NONE;
BMenuItem *submenuItem = NULL;
if (fSelected != NULL && fSelected->Submenu() != NULL) {
UnlockLooper();
submenuItem = fSelected->Submenu()->_track(&submenuAction);
if (submenuAction == MENU_ACT_CLOSE) {
item = submenuItem;
localAction = submenuAction;
break;
}
if (!LockLooper())
break;
}
UnlockLooper();
} }
UnlockLooper();
snooze(50000); snooze(50000);
} while (buttons != 0); } while (buttons != 0);
@@ -1166,10 +1166,8 @@ BMenu::_AddItem(BMenuItem *item, int32 index)
{ {
ASSERT(item != NULL); ASSERT(item != NULL);
bool err = fItems.AddItem(item, index); if (!fItems.AddItem(item, index))
return false;
if (!err)
return err;
item->SetSuper(this); item->SetSuper(this);
@@ -1187,7 +1185,7 @@ BMenu::_AddItem(BMenuItem *item, int32 index)
if (root->Window()) if (root->Window())
item->Install(root->Window()); item->Install(root->Window());
return err; return true;
} }
@@ -1223,7 +1221,8 @@ BMenu::RemoveItems(int32 index, int32 count, BMenuItem *_item, bool del)
} }
} }
InvalidateLayout(); if (Window() != NULL && fResizeToFit)
InvalidateLayout();
return result; return result;
} }
@@ -1251,9 +1250,13 @@ void
BMenu::ComputeLayout(int32 index, bool bestFit, bool moveItems, BMenu::ComputeLayout(int32 index, bool bestFit, bool moveItems,
float* width, float* height) float* width, float* height)
{ {
if (Window() == NULL && Parent() == NULL)
return;
// TODO: Take "bestFit", "moveItems", "index" into account, // TODO: Take "bestFit", "moveItems", "index" into account,
// Recalculate only the needed items, // Recalculate only the needed items,
// not the whole layout every time // not the whole layout every time
BRect frame(0, 0, 0, 0); BRect frame(0, 0, 0, 0);
float iWidth, iHeight; float iWidth, iHeight;
BMenuItem *item = NULL; BMenuItem *item = NULL;
@@ -1336,11 +1339,9 @@ BMenu::ComputeLayout(int32 index, bool bestFit, bool moveItems,
if ((ResizingMode() & B_FOLLOW_LEFT_RIGHT) == B_FOLLOW_LEFT_RIGHT) { if ((ResizingMode() & B_FOLLOW_LEFT_RIGHT) == B_FOLLOW_LEFT_RIGHT) {
if (Parent()) if (Parent())
*width = Parent()->Frame().Width() + 1; *width = Parent()->Frame().Width() + 1;
else if (Window()) else
*width = Window()->Frame().Width() + 1; *width = Window()->Frame().Width() + 1;
// TODO: We are left without a valid width here ?!?
*height = frame.Height(); *height = frame.Height();
} else { } else {
*width = frame.Width(); *width = frame.Width();