Use BView's ability to track what layout items reference it to simplify BLayout::IndexOfView(). This also changes the semantics slightly, but I think it is a logical change.

This commit is contained in:
Alex Wilson
2011-10-28 14:16:10 -06:00
parent bd97b9adba
commit ea907ab587
+7 -6
View File
@@ -279,14 +279,15 @@ BLayout::IndexOfView(BView* child) const
if (child == NULL)
return -1;
int itemCount = fItems.CountItems();
// A BView can have many items, so we just do our best and return the
// index of the first one in this layout.
BView::Private viewPrivate(child);
int32 itemCount = viewPrivate.CountLayoutItems();
for (int32 i = 0; i < itemCount; i++) {
BLayoutItem* item = (BLayoutItem*)fItems.ItemAt(i);
if (item->View() == child && (dynamic_cast<BViewLayoutItem*>(item)
|| dynamic_cast<BLayout*>(item)))
return i;
BLayoutItem* item = viewPrivate.LayoutItemAt(i);
if (item->Layout() == this)
return IndexOfItem(item);
}
return -1;
}