BMenu::_AddItem() keeps the looper locked for the whole time, other changes: let's see if this fixes that bug

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16990 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2006-04-03 19:50:16 +00:00
parent 8da774372c
commit 195f58ddbb
+25 -21
View File
@@ -416,9 +416,10 @@ BMenu::RemoveItems(int32 index, int32 count, bool del)
bool bool
BMenu::RemoveItem(BMenu *submenu) BMenu::RemoveItem(BMenu *submenu)
{ {
for (int32 i = 0; i < fItems.CountItems(); i++) for (int32 i = 0; i < fItems.CountItems(); i++) {
if (static_cast<BMenuItem *>(fItems.ItemAt(i))->Submenu() == submenu) if (static_cast<BMenuItem *>(fItems.ItemAtFast(i))->Submenu() == submenu)
return RemoveItems(i, 1, NULL, false); return RemoveItems(i, 1, NULL, false);
}
return false; return false;
} }
@@ -456,9 +457,10 @@ BMenu::IndexOf(BMenuItem *item) const
int32 int32
BMenu::IndexOf(BMenu *submenu) const BMenu::IndexOf(BMenu *submenu) const
{ {
for (int32 i = 0; i < fItems.CountItems(); i++) for (int32 i = 0; i < fItems.CountItems(); i++) {
if (ItemAt(i)->Submenu() == submenu) if (ItemAt(i)->Submenu() == submenu)
return i; return i;
}
return -1; return -1;
} }
@@ -1088,6 +1090,12 @@ BMenu::_show(bool selectFirstItem)
return false; return false;
} }
// Move the BMenu to 1, 1, if it's attached to a BMenuWindow,
// (that means it's a BMenu, BMenuBars are attached to regular BWindows).
// This is needed to be able to draw the frame around the BMenu.
if (dynamic_cast<BMenuWindow *>(window) != NULL)
MoveTo(1, 1);
// TODO: for some reason, Window() can already be NULL at this point, // TODO: for some reason, Window() can already be NULL at this point,
// which causes a crash in one of the following functions... // which causes a crash in one of the following functions...
// Does this still happens ? // Does this still happens ?
@@ -1230,26 +1238,21 @@ BMenu::_AddItem(BMenuItem *item, int32 index)
window = Superitem()->fWindow; window = Superitem()->fWindow;
else else
window = Window(); window = Window();
if (window != NULL)
if (locked) item->Install(window);
UnlockLooper();
item->SetSuper(this); item->SetSuper(this);
// if we need to install the item in another window, we don't if (locked && window != NULL && !window->IsHidden()) {
// want to keep our lock to prevent deadlocks
if (window && window->Lock()) {
item->Install(window);
// Make sure we update the layout if needed. // Make sure we update the layout if needed.
//if (fResizeToFit) {
LayoutItems(index); LayoutItems(index);
//UpdateWindowViewSize(); //UpdateWindowViewSize();
Invalidate(); Invalidate();
//}
window->Unlock();
} }
if (locked)
UnlockLooper();
return true; return true;
} }
@@ -1303,8 +1306,9 @@ BMenu::RemoveItems(int32 index, int32 count, BMenuItem *item, bool deleteItems)
} }
} }
if (invalidateLayout && locked /*&& fResizeToFit*/) { if (invalidateLayout && locked && window != NULL && !window->IsHidden()) {
LayoutItems(0); LayoutItems(0);
//UpdateWindowViewSize();
Invalidate(); Invalidate();
} }
@@ -1324,12 +1328,6 @@ BMenu::LayoutItems(int32 index)
ComputeLayout(index, fResizeToFit, true, &width, &height); ComputeLayout(index, fResizeToFit, true, &width, &height);
ResizeTo(width, height); ResizeTo(width, height);
// Move the BMenu to 1, 1, if it's attached to a BMenuWindow,
// (that means it's a BMenu, BMenuBars are attached to regular BWindows).
// This is needed to be able to draw the frame around the BMenu.
if (dynamic_cast<BMenuWindow *>(Window()) != NULL)
MoveTo(1, 1);
} }
@@ -1847,6 +1845,12 @@ void
BMenu::UpdateWindowViewSize(bool upWind) BMenu::UpdateWindowViewSize(bool upWind)
{ {
BWindow *window = Window(); BWindow *window = Window();
ASSERT(window != NULL);
if (window == NULL)
return;
bool scroll; bool scroll;
BRect frame = CalcFrame(ScreenLocation(), &scroll); BRect frame = CalcFrame(ScreenLocation(), &scroll);
ResizeTo(frame.Width(), frame.Height()); ResizeTo(frame.Width(), frame.Height());