From 8991f1a2af5d078ed53bf15bd6fcef57b667695c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 7 Jul 2005 02:45:23 +0000 Subject: [PATCH] Implemented basic dynamic item support (IOW the BSlowMenu/BNavMenu stuff is now working as expected), OkToProceed() needs some work, though. Made _AddItem() more safe - the window is now also locked during BList::AddItem() and while getting the window to install the item in. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13516 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/Menu.cpp | 54 ++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/src/kits/interface/Menu.cpp b/src/kits/interface/Menu.cpp index 7f99d0e1ce..dfcd8bd4ba 100644 --- a/src/kits/interface/Menu.cpp +++ b/src/kits/interface/Menu.cpp @@ -268,8 +268,21 @@ void BMenu::AttachedToWindow() { BView::AttachedToWindow(); - - InvalidateLayout(); + + bool aborted = false; + + if (AddDynamicItem(B_INITIAL_ADD)) { + do { + if (!OkToProceed(NULL)) { + AddDynamicItem(B_ABORT); + aborted = true; + break; + } + } while (AddDynamicItem(B_PROCESSING)); + } + + if (!aborted) + InvalidateLayout(); } @@ -1140,32 +1153,44 @@ bool BMenu::_AddItem(BMenuItem *item, int32 index) { ASSERT(item != NULL); - - if (!fItems.AddItem(item, index)) + + bool locked = LockLooper(); + + if (!fItems.AddItem(item, index)) { + if (locked) + UnlockLooper(); return false; + } item->SetSuper(this); - BWindow* window = Window(); - // Make sure we update the layout in case we are already attached. - if (fResizeToFit && window && window->Lock()) { + if (fResizeToFit && locked && Window() != NULL /*&& !Window()->IsHidden()*/) { LayoutItems(index); + //UpdateWindowViewSize(); Invalidate(); - window->Unlock(); } // Find the root menu window, so we can install this item. - BMenu *root = this; + // ToDo: this shouldn't be necessary - the first supermenu is + // already initialized to the same window + BMenu* root = this; while (root->Supermenu()) root = root->Supermenu(); - window = root->Window(); + BWindow* window = root->Window(); + + if (locked) + UnlockLooper(); + + // if we need to install the item in another window, we don't + // want to keep our lock to prevent deadlocks + if (window && window->Lock()) { item->Install(window); window->Unlock(); } - + return true; } @@ -1741,9 +1766,12 @@ BMenu::RedrawAfterSticky(BRect bounds) bool -BMenu::OkToProceed(BMenuItem *) +BMenu::OkToProceed(BMenuItem* item) { - return false; + // ToDo: test if the window could be closed again already + + // ToDo: for now + return true; }