From f374f0d9f1d089742bdb69f97bb9de4555247167 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 18 Apr 2008 14:44:19 +0000 Subject: [PATCH] * A view can have more than just one LayoutItem, and therefore, we have to remove them all in RemoveView(). * Also, previously, the wrong LayoutItem could be removed if there was any view that had more than one item around. * IOW using BView::RemoveSelf()/RemoveChild() yourself would have leaked memory in the best case, and would otherwise crash your app if there was any view with more than one LayoutItem. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25024 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/Layout.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/kits/interface/Layout.cpp b/src/kits/interface/Layout.cpp index 29e6bdff82..d4254280c4 100644 --- a/src/kits/interface/Layout.cpp +++ b/src/kits/interface/Layout.cpp @@ -67,7 +67,7 @@ BLayout::AddItem(int32 index, BLayoutItem* item) { if (!fView || !item || fItems.HasItem(item)) return false; - + // if the item refers to a BView, we make sure, it is added to the parent // view BView* view = item->View(); @@ -90,15 +90,21 @@ BLayout::AddItem(int32 index, BLayoutItem* item) bool BLayout::RemoveView(BView* child) { - int32 index = IndexOfView(child); - if (index >= 0) { - if (BLayoutItem* item = RemoveItem(index)) { - delete item; - return true; - } + bool removed = false; + + // a view can have any number of layout items - we need to remove them all + for (int32 i = fItems.CountItems(); i-- > 0;) { + BLayoutItem* item = ItemAt(i); + + if (item->View() != child) + continue; + + RemoveItem(i); + removed = true; + delete item; } - return false; + return removed; } // RemoveItem