Add a BObjectList<BLayoutItem> to BView::fLayoutData that keeps track of any BLayoutItems that refer to this view that are part of a layout. BLayoutItem does the registering/deregistering of the items, and BView::Private proxies fLayoutData for us. Currently, this is not used anywhere, but there are many places where it will be used soon.

This commit is contained in:
Alex Wilson 2011-09-07 15:02:51 -06:00
parent edb4c8244c
commit bd97b9adba
4 changed files with 47 additions and 2 deletions

View File

@ -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();

View File

@ -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)

View File

@ -9,6 +9,7 @@
#include <Layout.h>
#include <LayoutUtils.h>
#include <View.h>
#include <ViewPrivate.h>
#include <algorithm>
@ -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();
}

View File

@ -34,6 +34,7 @@
#include <MenuBar.h>
#include <Message.h>
#include <MessageQueue.h>
#include <ObjectList.h>
#include <Picture.h>
#include <Point.h>
#include <Polygon.h>
@ -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<BLayoutItem> 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()
{