Devirtualize BLayout::InvalidateLayout(), add a protected hook BLayout::DoLayout(). This will allow for much better control over the propagation of layout invalidations, and therefore cleaner, more optimal code.

This commit is contained in:
Alex Wilson 2011-10-16 22:48:47 -06:00
parent 449f014bcc
commit b38ea98f52
8 changed files with 34 additions and 42 deletions

View File

@ -28,13 +28,12 @@ public:
virtual void GetHeightForWidth(float width, float* min,
float* max, float* preferred);
virtual void InvalidateLayout(bool children = false);
virtual status_t Archive(BMessage* into, bool deep = true) const;
virtual status_t AllUnarchived(const BMessage* from);
static BArchivable* Instantiate(BMessage* from);
protected:
virtual void LayoutInvalidated(bool children = false);
virtual void DoLayout();
virtual bool ItemAdded(BLayoutItem* item, int32 atIndex);
virtual void ItemRemoved(BLayoutItem* item, int32 fromIndex);

View File

@ -48,7 +48,7 @@ public:
// Layouting related methods
virtual void InvalidateLayout(bool children = false);
void InvalidateLayout(bool children = false);
void Relayout(bool immediate = false);
void RequireLayout();
bool IsValid();
@ -73,6 +73,7 @@ protected:
// BLayout hook methods
virtual bool ItemAdded(BLayoutItem* item, int32 atIndex);
virtual void ItemRemoved(BLayoutItem* item, int32 fromIndex);
virtual void LayoutInvalidated(bool children);
virtual void DoLayout() = 0;
virtual void OwnerChanged(BView* was);

View File

@ -38,8 +38,6 @@ public:
virtual void SetFrame(BRect frame);
virtual void InvalidateLayout(bool children = false);
virtual status_t Archive(BMessage* into, bool deep = true) const;
virtual status_t AllArchived(BMessage* into) const;
virtual status_t AllUnarchived(const BMessage* from);
@ -58,6 +56,7 @@ protected:
int32 height;
};
virtual void LayoutInvalidated(bool children = false);
virtual void DoLayout();
BSize AddInsets(BSize size);

View File

@ -174,10 +174,8 @@ BCardLayout::GetHeightForWidth(float width, float* min, float* max,
void
BCardLayout::InvalidateLayout(bool children)
BCardLayout::LayoutInvalidated(bool children)
{
BLayout::InvalidateLayout(children);
fMinMaxValid = false;
}

View File

@ -303,6 +303,7 @@ BLayout::InvalidateLayout(bool children)
return;
fState |= B_LAYOUT_NECESSARY;
LayoutInvalidated(children);
if (children) {
for (int32 i = CountItems() - 1; i >= 0; i--)
@ -522,6 +523,12 @@ BLayout::ItemRemoved(BLayoutItem* item, int32 fromIndex)
}
void
BLayout::LayoutInvalidated(bool children)
{
}
void
BLayout::OwnerChanged(BView* was)
{

View File

@ -546,9 +546,21 @@ BSplitLayout::GetHeightForWidth(float width, float* min, float* max,
void
BSplitLayout::InvalidateLayout(bool children)
BSplitLayout::LayoutInvalidated(bool children)
{
_InvalidateLayout(true, children);
delete fHorizontalLayouter;
delete fVerticalLayouter;
delete fHorizontalLayoutInfo;
delete fVerticalLayoutInfo;
fHorizontalLayouter = NULL;
fVerticalLayouter = NULL;
fHorizontalLayoutInfo = NULL;
fVerticalLayoutInfo = NULL;
_InvalidateCachedHeightForWidth();
fLayoutValid = false;
}
@ -820,28 +832,6 @@ BSplitLayout::ItemRemoved(BLayoutItem* item, int32 atIndex)
}
void
BSplitLayout::_InvalidateLayout(bool invalidateView, bool children)
{
if (invalidateView)
BAbstractLayout::InvalidateLayout(children);
delete fHorizontalLayouter;
delete fVerticalLayouter;
delete fHorizontalLayoutInfo;
delete fVerticalLayoutInfo;
fHorizontalLayouter = NULL;
fVerticalLayouter = NULL;
fHorizontalLayoutInfo = NULL;
fVerticalLayoutInfo = NULL;
_InvalidateCachedHeightForWidth();
fLayoutValid = false;
}
void
BSplitLayout::_InvalidateCachedHeightForWidth()
{

View File

@ -75,8 +75,7 @@ public:
virtual void GetHeightForWidth(float width, float* min,
float* max, float* preferred);
virtual void InvalidateLayout(bool children = false);
virtual void LayoutInvalidated(bool children);
virtual void DoLayout();
// interface for BSplitView

View File

@ -407,14 +407,6 @@ BTwoDimensionalLayout::SetFrame(BRect frame)
}
void
BTwoDimensionalLayout::InvalidateLayout(bool children)
{
BLayout::InvalidateLayout(children);
fLocalLayouter->InvalidateLayout();
}
status_t
BTwoDimensionalLayout::Archive(BMessage* into, bool deep) const
{
@ -464,6 +456,13 @@ BTwoDimensionalLayout::AllUnarchived(const BMessage* from)
}
void
BTwoDimensionalLayout::LayoutInvalidated(bool children)
{
fLocalLayouter->InvalidateLayout();
}
void
BTwoDimensionalLayout::DoLayout()
{