From 681f48fcbccfa556fe01eab457ca1d549736b19e Mon Sep 17 00:00:00 2001 From: Alex Wilson Date: Tue, 24 Jan 2012 11:19:51 +1300 Subject: [PATCH] Replace BALMLayout::Ordered*Tabs() method with *TabAt(int, bool sorted). --- headers/libs/alm/ALMLayout.h | 10 +++---- src/libs/alm/ALMLayout.cpp | 51 ++++++++++++++++++++---------------- 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/headers/libs/alm/ALMLayout.h b/headers/libs/alm/ALMLayout.h index 0e05005cfc..f24fafd2b6 100644 --- a/headers/libs/alm/ALMLayout.h +++ b/headers/libs/alm/ALMLayout.h @@ -48,11 +48,8 @@ public: int32 CountXTabs() const; int32 CountYTabs() const; - XTab* XTabAt(int32 index) const; - YTab* YTabAt(int32 index) const; - /*! Order the tab list and return a reference to the list. */ - const XTabList& OrderedXTabs(); - const YTabList& OrderedYTabs(); + XTab* XTabAt(int32 index, bool ordered = false); + YTab* YTabAt(int32 index, bool ordered = false); Row* AddRow(YTab* top, YTab* bottom); Column* AddColumn(XTab* left, XTab* right); @@ -202,7 +199,10 @@ private: float fVSpacing; XTabList fXTabList; + bool fXTabsSorted; + YTabList fYTabList; + bool fYTabsSorted; RowColumnManager* fRowColumnManager; diff --git a/src/libs/alm/ALMLayout.cpp b/src/libs/alm/ALMLayout.cpp index 702400aecd..30e72b58f6 100644 --- a/src/libs/alm/ALMLayout.cpp +++ b/src/libs/alm/ALMLayout.cpp @@ -26,6 +26,10 @@ using namespace LinearProgramming; 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 { @@ -136,6 +140,8 @@ BALMLayout::BALMLayout(float hSpacing, float vSpacing, BALMLayout* friendLayout) fBottomInset(0), fHSpacing(BControlLook::ComposeSpacing(hSpacing)), fVSpacing(BControlLook::ComposeSpacing(vSpacing)), + fXTabsSorted(false), + fYTabsSorted(false), fBadLayoutPolicy(new DefaultPolicy()) { fSolver = friendLayout ? friendLayout->fSolver : new SharedSolver(); @@ -190,6 +196,7 @@ BALMLayout::AddXTab() fXTabList.RemoveItem(tab); return NULL; } + fXTabsSorted = false; return tab; } @@ -229,6 +236,7 @@ BALMLayout::AddYTab() fYTabList.RemoveItem(tab); return NULL; } + fYTabsSorted = false; return tab; } @@ -248,21 +256,31 @@ BALMLayout::CountYTabs() const 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); } 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); } -static int -compare_x_tab_func(const XTab* tab1, const XTab* tab2) +int +CompareXTabFunc(const XTab* tab1, const XTab* tab2) { if (tab1->Value() < tab2->Value()) return -1; @@ -272,8 +290,8 @@ compare_x_tab_func(const XTab* tab1, const XTab* tab2) } -static int -compare_y_tab_func(const YTab* tab1, const YTab* tab2) +int +CompareYTabFunc(const YTab* tab1, const YTab* tab2) { if (tab1->Value() < tab2->Value()) 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. * @@ -882,6 +884,8 @@ BALMLayout::LayoutInvalidated(bool children) fMinSize = kUnsetSize; fMaxSize = kUnsetSize; fPreferredSize = kUnsetSize; + fXTabsSorted = false; + fYTabsSorted = false; fSolver->Invalidate(children); } @@ -923,6 +927,9 @@ BALMLayout::DoLayout() // set the calculated positions and sizes for every area for (int32 i = 0; i < CountItems(); i++) AreaFor(ItemAt(i))->_DoLayout(LayoutArea().LeftTop()); + + fXTabsSorted = false; + fYTabsSorted = false; }