User BView's layout item tracking functionality to simplify and optimize some methods in BLayout and BView.

Delete BLayout::RemoveViewRecursive() as it is no longer needed.
Add a few TODO's.
This commit is contained in:
Alex Wilson
2011-10-28 14:16:16 -06:00
parent 30b07d019d
commit fa01d08496
4 changed files with 31 additions and 39 deletions
-1
View File
@@ -89,7 +89,6 @@ protected:
private:
friend class BView;
bool RemoveViewRecursive(BView* view);
bool InvalidateLayoutsForView(BView* view);
bool InvalidationLegal();
void SetOwner(BView* owner);
+20 -36
View File
@@ -11,9 +11,9 @@
#include <new>
#include <syslog.h>
#include <AutoDeleter.h>
#include <LayoutContext.h>
#include <Message.h>
#include <AutoDeleter.h>
#include <View.h>
#include <ViewPrivate.h>
@@ -195,10 +195,11 @@ BLayout::RemoveView(BView* child)
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);
BView::Private viewPrivate(child);
for (int32 i = viewPrivate.CountLayoutItems() - 1; i >= 0; i--) {
BLayoutItem* item = viewPrivate.LayoutItemAt(i);
if (item->View() != child)
if (item->Layout() != this)
continue;
RemoveItem(i);
@@ -225,13 +226,15 @@ BLayout::RemoveItem(int32 index)
return NULL;
BLayoutItem* item = (BLayoutItem*)fItems.RemoveItem(index);
// if the item refers to a BView, we make sure it is removed from the
// parent view
// If this is the last item in use that refers to a certain BView,
// that BView now needs to be removed.
BView* view = item->View();
if (view && view->fParent == fTarget)
if (view && BView::Private(view).CountLayoutItems() == 0)
view->_RemoveSelf();
// TODO: Is this the right place/order to call these hooks?
// view->Parent() could be NULL, maybe that's not a problem..
ItemRemoved(item, index);
item->SetLayout(NULL);
InvalidateLayout();
@@ -578,40 +581,20 @@ BLayout::LayoutContext() const
}
bool
BLayout::RemoveViewRecursive(BView* view)
{
bool removed = RemoveView(view);
for (int32 i = fNestedLayouts.CountItems() - 1; i >= 0; i--) {
BLayout* nested = (BLayout*)fNestedLayouts.ItemAt(i);
removed |= nested->RemoveViewRecursive(view);
}
return removed;
}
bool
BLayout::InvalidateLayoutsForView(BView* view)
{
bool found = false;
for (int32 i = fNestedLayouts.CountItems() - 1; i >= 0; i--) {
BLayout* layout = (BLayout*)fNestedLayouts.ItemAt(i);
found |= layout->InvalidateLayoutsForView(view);
}
if (found)
return found;
if (!InvalidationLegal())
BView::Private viewPrivate(view);
int32 count = viewPrivate.CountLayoutItems();
if (count == 0)
return false;
for (int32 i = CountItems() - 1; i >= 0; i--) {
if (ItemAt(i)->View() == view) {
InvalidateLayout();
return true;
}
for (int32 i = 0; i < count; i++) {
BLayout* layout = viewPrivate.LayoutItemAt(i)->Layout();
if (layout->InvalidationLegal())
layout->InvalidateLayout();
}
return found;
return true;
}
@@ -653,3 +636,4 @@ BLayout::SetTarget(BView* target)
InvalidateLayout();
}
}
+3
View File
@@ -168,6 +168,9 @@ BLayoutItem::SetLayout(BLayout* layout)
if (layout)
DetachedFromLayout(layout);
// TODO: is this the right place to do this?
// at this point, this->Layout() will return not exactly truthful
// values... this could cause problems in DetachedFromLayout();
if (BView* view = View()) {
if (layout && !fLayout) {
BView::Private(view).DeregisterLayoutItem(this);
+8 -2
View File
@@ -4022,8 +4022,14 @@ BView::PreviousSibling() const
bool
BView::RemoveSelf()
{
if (fParent && fParent->fLayoutData->fLayout)
return fParent->fLayoutData->fLayout->RemoveViewRecursive(this);
if (fParent && fParent->fLayoutData->fLayout) {
int32 itemCount = fLayoutData->fLayoutItems.CountItems();
for (int32 i = 0; i < itemCount; i++) {
BLayoutItem* item = fLayoutData->fLayoutItems.ItemAt(i);
item->Layout()->RemoveItem(item);
delete item;
}
}
return _RemoveSelf();
}