diff --git a/headers/private/interface/ViewPrivate.h b/headers/private/interface/ViewPrivate.h index 27474a3152..cd32f93b39 100644 --- a/headers/private/interface/ViewPrivate.h +++ b/headers/private/interface/ViewPrivate.h @@ -66,6 +66,11 @@ public: bool WillLayout(); bool MinMaxValid(); + BLayoutItem* LayoutItemAt(int32 index); + int32 CountLayoutItems(); + void RegisterLayoutItem(BLayoutItem* item); + void DeregisterLayoutItem(BLayoutItem* item); + bool RemoveSelf() { return fView->_RemoveSelf(); diff --git a/src/kits/interface/Layout.cpp b/src/kits/interface/Layout.cpp index a4e974cb24..35a09536ac 100644 --- a/src/kits/interface/Layout.cpp +++ b/src/kits/interface/Layout.cpp @@ -238,7 +238,7 @@ BLayout::RemoveItem(int32 index) BLayoutItem* item = (BLayoutItem*)fItems.RemoveItem(index); - // if the item refers to a BView, we make sure, it is removed from the + // if the item refers to a BView, we make sure it is removed from the // parent view BView* view = item->View(); if (view && view->fParent == fTarget) diff --git a/src/kits/interface/LayoutItem.cpp b/src/kits/interface/LayoutItem.cpp index 23cabe49e2..25ba24243d 100644 --- a/src/kits/interface/LayoutItem.cpp +++ b/src/kits/interface/LayoutItem.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include @@ -166,7 +167,15 @@ BLayoutItem::SetLayout(BLayout* layout) std::swap(fLayout, layout); if (layout) DetachedFromLayout(layout); - + + if (BView* view = View()) { + if (layout && !fLayout) { + BView::Private(view).DeregisterLayoutItem(this); + } else if (fLayout && !layout) { + BView::Private(view).RegisterLayoutItem(this); + } + } + if (fLayout) AttachedToLayout(); } diff --git a/src/kits/interface/View.cpp b/src/kits/interface/View.cpp index 7caad50e84..9ce5062984 100644 --- a/src/kits/interface/View.cpp +++ b/src/kits/interface/View.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -335,6 +336,7 @@ struct BView::LayoutData { fLayoutInvalidationDisabled(0), fLayout(NULL), fLayoutContext(NULL), + fLayoutItems(5, false), fLayoutValid(true), // TODO: Rethink these initial values! fMinMaxValid(true), // fLayoutInProgress(false), @@ -375,6 +377,7 @@ struct BView::LayoutData { int fLayoutInvalidationDisabled; BLayout* fLayout; BLayoutContext* fLayoutContext; + BObjectList fLayoutItems; bool fLayoutValid; bool fMinMaxValid; bool fLayoutInProgress; @@ -5959,6 +5962,34 @@ BView::_PrintTree() // #pragma mark - +BLayoutItem* +BView::Private::LayoutItemAt(int32 index) +{ + return fView->fLayoutData->fLayoutItems.ItemAt(index); +} + + +int32 +BView::Private::CountLayoutItems() +{ + return fView->fLayoutData->fLayoutItems.CountItems(); +} + + +void +BView::Private::RegisterLayoutItem(BLayoutItem* item) +{ + fView->fLayoutData->fLayoutItems.AddItem(item); +} + + +void +BView::Private::DeregisterLayoutItem(BLayoutItem* item) +{ + fView->fLayoutData->fLayoutItems.RemoveItem(item); +} + + bool BView::Private::MinMaxValid() {