Replace BALMLayout::Ordered*Tabs() method with *TabAt(int, bool sorted).

This commit is contained in:
Alex Wilson
2012-05-03 08:45:17 +12:00
parent 6169a6e3d1
commit 681f48fcbc
2 changed files with 34 additions and 27 deletions
+5 -5
View File
@@ -48,11 +48,8 @@ public:
int32 CountXTabs() const; int32 CountXTabs() const;
int32 CountYTabs() const; int32 CountYTabs() const;
XTab* XTabAt(int32 index) const; XTab* XTabAt(int32 index, bool ordered = false);
YTab* YTabAt(int32 index) const; YTab* YTabAt(int32 index, bool ordered = false);
/*! Order the tab list and return a reference to the list. */
const XTabList& OrderedXTabs();
const YTabList& OrderedYTabs();
Row* AddRow(YTab* top, YTab* bottom); Row* AddRow(YTab* top, YTab* bottom);
Column* AddColumn(XTab* left, XTab* right); Column* AddColumn(XTab* left, XTab* right);
@@ -202,7 +199,10 @@ private:
float fVSpacing; float fVSpacing;
XTabList fXTabList; XTabList fXTabList;
bool fXTabsSorted;
YTabList fYTabList; YTabList fYTabList;
bool fYTabsSorted;
RowColumnManager* fRowColumnManager; RowColumnManager* fRowColumnManager;
+29 -22
View File
@@ -26,6 +26,10 @@ using namespace LinearProgramming;
const BSize kUnsetSize(B_SIZE_UNSET, B_SIZE_UNSET); const BSize kUnsetSize(B_SIZE_UNSET, B_SIZE_UNSET);
int CompareXTabFunc(const XTab* tab1, const XTab* tab2);
int CompareYTabFunc(const YTab* tab1, const YTab* tab2);
namespace BALM { namespace BALM {
@@ -136,6 +140,8 @@ BALMLayout::BALMLayout(float hSpacing, float vSpacing, BALMLayout* friendLayout)
fBottomInset(0), fBottomInset(0),
fHSpacing(BControlLook::ComposeSpacing(hSpacing)), fHSpacing(BControlLook::ComposeSpacing(hSpacing)),
fVSpacing(BControlLook::ComposeSpacing(vSpacing)), fVSpacing(BControlLook::ComposeSpacing(vSpacing)),
fXTabsSorted(false),
fYTabsSorted(false),
fBadLayoutPolicy(new DefaultPolicy()) fBadLayoutPolicy(new DefaultPolicy())
{ {
fSolver = friendLayout ? friendLayout->fSolver : new SharedSolver(); fSolver = friendLayout ? friendLayout->fSolver : new SharedSolver();
@@ -190,6 +196,7 @@ BALMLayout::AddXTab()
fXTabList.RemoveItem(tab); fXTabList.RemoveItem(tab);
return NULL; return NULL;
} }
fXTabsSorted = false;
return tab; return tab;
} }
@@ -229,6 +236,7 @@ BALMLayout::AddYTab()
fYTabList.RemoveItem(tab); fYTabList.RemoveItem(tab);
return NULL; return NULL;
} }
fYTabsSorted = false;
return tab; return tab;
} }
@@ -248,21 +256,31 @@ BALMLayout::CountYTabs() const
XTab* XTab*
BALMLayout::XTabAt(int32 index) const BALMLayout::XTabAt(int32 index, bool ordered)
{ {
if (ordered && !fXTabsSorted) {
Layout();
fXTabList.SortItems(CompareXTabFunc);
fXTabsSorted = true;
}
return fXTabList.ItemAt(index); return fXTabList.ItemAt(index);
} }
YTab* YTab*
BALMLayout::YTabAt(int32 index) const BALMLayout::YTabAt(int32 index, bool ordered)
{ {
if (ordered && !fYTabsSorted) {
Layout();
fYTabList.SortItems(CompareYTabFunc);
fYTabsSorted = true;
}
return fYTabList.ItemAt(index); return fYTabList.ItemAt(index);
} }
static int int
compare_x_tab_func(const XTab* tab1, const XTab* tab2) CompareXTabFunc(const XTab* tab1, const XTab* tab2)
{ {
if (tab1->Value() < tab2->Value()) if (tab1->Value() < tab2->Value())
return -1; return -1;
@@ -272,8 +290,8 @@ compare_x_tab_func(const XTab* tab1, const XTab* tab2)
} }
static int int
compare_y_tab_func(const YTab* tab1, const YTab* tab2) CompareYTabFunc(const YTab* tab1, const YTab* tab2)
{ {
if (tab1->Value() < tab2->Value()) if (tab1->Value() < tab2->Value())
return -1; return -1;
@@ -283,22 +301,6 @@ compare_y_tab_func(const YTab* tab1, const YTab* tab2)
} }
const XTabList&
BALMLayout::OrderedXTabs()
{
fXTabList.SortItems(compare_x_tab_func);
return fXTabList;
}
const YTabList&
BALMLayout::OrderedYTabs()
{
fYTabList.SortItems(compare_y_tab_func);
return fYTabList;
}
/** /**
* Adds a new row to the specification that is glued to the given y-tabs. * Adds a new row to the specification that is glued to the given y-tabs.
* *
@@ -882,6 +884,8 @@ BALMLayout::LayoutInvalidated(bool children)
fMinSize = kUnsetSize; fMinSize = kUnsetSize;
fMaxSize = kUnsetSize; fMaxSize = kUnsetSize;
fPreferredSize = kUnsetSize; fPreferredSize = kUnsetSize;
fXTabsSorted = false;
fYTabsSorted = false;
fSolver->Invalidate(children); fSolver->Invalidate(children);
} }
@@ -923,6 +927,9 @@ BALMLayout::DoLayout()
// set the calculated positions and sizes for every area // set the calculated positions and sizes for every area
for (int32 i = 0; i < CountItems(); i++) for (int32 i = 0; i < CountItems(); i++)
AreaFor(ItemAt(i))->_DoLayout(LayoutArea().LeftTop()); AreaFor(ItemAt(i))->_DoLayout(LayoutArea().LeftTop());
fXTabsSorted = false;
fYTabsSorted = false;
} }