diff --git a/headers/libs/alm/ALMLayout.h b/headers/libs/alm/ALMLayout.h index 4aa463ecb2..a7235cfc4e 100644 --- a/headers/libs/alm/ALMLayout.h +++ b/headers/libs/alm/ALMLayout.h @@ -38,28 +38,11 @@ public: Column* AddColumn(); Column* AddColumn(XTab* left, XTab* right); - Area* AddArea(XTab* left, YTab* top, XTab* right, - YTab* bottom, BView* content); - Area* AddArea(Row* row, Column* column, - BView* content); - Area* AreaOf(BView* control); - XTab* Left() const; XTab* Right() const; YTab* Top() const; YTab* Bottom() const; - virtual BSize BaseMinSize(); - virtual BSize BaseMaxSize(); - virtual BSize BasePreferredSize(); - virtual BAlignment BaseAlignment(); - - virtual void InvalidateLayout(bool children = false); - - virtual bool ItemAdded(BLayoutItem* item, int32 atIndex); - virtual void ItemRemoved(BLayoutItem* item, int32 fromIndex); - virtual void DerivedLayoutItems(); - char* PerformancePath() const; void SetPerformancePath(char* path); @@ -71,7 +54,60 @@ public: void SetSpacing(float spacing); float Spacing(); + virtual BLayoutItem* AddView(BView* child); + virtual BLayoutItem* AddView(int32 index, BView* child); + virtual Area* AddView(BView* view, XTab* left, YTab* top, + XTab* right, YTab* bottom); + virtual Area* AddView(BView* view, Row* row, Column* column); + virtual Area* AddViewToRight(BView* view, Area* leftArea, + XTab* right = NULL, YTab* top = NULL, + YTab* bottom = NULL); + virtual Area* AddViewToLeft(BView* view, Area* rightArea, + XTab* left = NULL, YTab* top = NULL, + YTab* bottom = NULL); + virtual Area* AddViewToTop(BView* view, Area* bottomArea, + YTab* top = NULL, XTab* left = NULL, + XTab* right = NULL); + virtual Area* AddViewToBottom(BView* view, Area* topArea, + YTab* bottom = NULL, XTab* left = NULL, + XTab* right = NULL); + + virtual bool AddItem(BLayoutItem* item); + virtual bool AddItem(int32 index, BLayoutItem* item); + virtual Area* AddItem(BLayoutItem* item, XTab* left, + YTab* top, XTab* right, YTab* bottom); + virtual Area* AddItem(BLayoutItem* item, Row* row, + Column* column); + virtual Area* AddItemToRight(BLayoutItem* item, + Area* leftArea, XTab* right = NULL, + YTab* top = NULL, YTab* bottom = NULL); + virtual Area* AddItemToLeft(BLayoutItem* item, + Area* rightArea, XTab* left = NULL, + YTab* top = NULL, YTab* bottom = NULL); + virtual Area* AddItemToTop(BLayoutItem* item, + Area* bottomArea, YTab* top = NULL, + XTab* left = NULL, XTab* right = NULL); + virtual Area* AddItemToBottom(BLayoutItem* item, + Area* topArea, YTab* bottom = NULL, + XTab* left = NULL, XTab* right = NULL); + + virtual Area* AreaOf(BView* control); + + virtual BSize BaseMinSize(); + virtual BSize BaseMaxSize(); + virtual BSize BasePreferredSize(); + virtual BAlignment BaseAlignment(); + + virtual void InvalidateLayout(bool children = false); + + virtual bool ItemAdded(BLayoutItem* item, int32 atIndex); + virtual void ItemRemoved(BLayoutItem* item, int32 fromIndex); + virtual void DerivedLayoutItems(); + private: + /*! Add a view without initialize the Area. */ + BLayoutItem* _CreateLayoutItem(BView* view); + void _SolveLayout(); Area* _AreaForItem(BLayoutItem* item) const; diff --git a/headers/libs/alm/Area.h b/headers/libs/alm/Area.h index c3317b878e..1874d5d3a3 100644 --- a/headers/libs/alm/Area.h +++ b/headers/libs/alm/Area.h @@ -81,9 +81,8 @@ private: Area(BLayoutItem* item); void _Init(LinearSpec* ls, XTab* left, YTab* top, - XTab* right, YTab* bottom, BView* content); - void _Init(LinearSpec* ls, Row* row, Column* column, - BView* content); + XTab* right, YTab* bottom); + void _Init(LinearSpec* ls, Row* row, Column* column); void _DoLayout(); diff --git a/src/libs/alm/ALMLayout.cpp b/src/libs/alm/ALMLayout.cpp index 190cfcce02..b26fbdb276 100644 --- a/src/libs/alm/ALMLayout.cpp +++ b/src/libs/alm/ALMLayout.cpp @@ -11,6 +11,8 @@ #include // for floor #include +#include "ViewLayoutItem.h" + #include "Area.h" #include "Column.h" #include "ResultType.h" @@ -144,6 +146,20 @@ BALMLayout::AddColumn(XTab* left, XTab* right) } +BLayoutItem* +BALMLayout::AddView(BView* child) +{ + return AddView(-1, child); +} + + +BLayoutItem* +BALMLayout::AddView(int32 index, BView* child) +{ + return BAbstractLayout::AddView(index, child); +} + + /** * Adds a new area to the specification, automatically setting preferred size constraints. * @@ -155,17 +171,15 @@ BALMLayout::AddColumn(XTab* left, XTab* right) * @return the new area */ Area* -BALMLayout::AddArea(XTab* left, YTab* top, XTab* right, YTab* bottom, - BView* content) +BALMLayout::AddView(BView* view, XTab* left, YTab* top, XTab* right, + YTab* bottom) { - BLayoutItem* item = AddView(content); - Area* area = _AreaForItem(item); - if (!area) + BLayoutItem* item = _CreateLayoutItem(view); + Area* area = AddItem(item, left, top, right, bottom); + if (!area) { + delete item; return NULL; - - area->_Init(&fSolver, left, top, right, bottom, content); - area->SetDefaultBehavior(); - area->SetAutoPreferredContentSize(false); + } return area; } @@ -179,20 +193,209 @@ BALMLayout::AddArea(XTab* left, YTab* top, XTab* right, YTab* bottom, * @return the new area */ Area* -BALMLayout::AddArea(Row* row, Column* column, BView* content) +BALMLayout::AddView(BView* view, Row* row, Column* column) { - BLayoutItem* item = AddView(content); + BLayoutItem* item = _CreateLayoutItem(view); + Area* area = AddItem(item, row, column); + if (!area) { + delete item; + return NULL; + } + return area; +} + + +Area* +BALMLayout::AddViewToRight(BView* view, Area* leftArea, XTab* right, YTab* top, + YTab* bottom) +{ + BLayoutItem* item = _CreateLayoutItem(view); + Area* area = AddItemToRight(item, leftArea, right, top, bottom); + if (!area) { + delete item; + return NULL; + } + return area; +} + + +Area* +BALMLayout::AddViewToLeft(BView* view, Area* rightArea, XTab* left, YTab* top, + YTab* bottom) +{ + BLayoutItem* item = _CreateLayoutItem(view); + Area* area = AddItemToLeft(item, rightArea, left, top, bottom); + if (!area) { + delete item; + return NULL; + } + return area; +} + + +Area* +BALMLayout::AddViewToTop(BView* view, Area* bottomArea, YTab* top, XTab* left, + XTab* right) +{ + BLayoutItem* item = _CreateLayoutItem(view); + Area* area = AddItemToTop(item, bottomArea, top, left, right); + if (!area) { + delete item; + return NULL; + } + return area; +} + + +Area* +BALMLayout::AddViewToBottom(BView* view, Area* topArea, YTab* bottom, + XTab* left, XTab* right) +{ + BLayoutItem* item = _CreateLayoutItem(view); + Area* area = AddItemToBottom(item, topArea, bottom, left, right); + if (!area) { + delete item; + return NULL; + } + return area; +} + + +bool +BALMLayout::AddItem(BLayoutItem* item) +{ + return AddItem(-1, item); +} + + +bool +BALMLayout::AddItem(int32 index, BLayoutItem* item) +{ + if (!item) + return NULL; + + // simply add the item at the upper right corner of the previous item + // TODO maybe find a more elegant solution + XTab* left = Left(); + YTab* top = Top(); + XTab* right = AddXTab(); + YTab* bottom = AddYTab(); + + // check range + if (index < 0 || index > CountItems()) + index = CountItems(); + + // for index = 0 we already have set the right tabs + if (index != 0) { + BLayoutItem* prevItem = ItemAt(index - 1); + Area* area = _AreaForItem(prevItem); + if (area) { + left = area->Right(); + top = area->Top(); + } + } + Area* area = AddItem(item, left, top, right, bottom); + return area ? true : false; +} + + +Area* +BALMLayout::AddItem(BLayoutItem* item, XTab* left, YTab* top, XTab* right, + YTab* bottom) +{ + if (!BAbstractLayout::AddItem(-1, item)) + return NULL; Area* area = _AreaForItem(item); if (!area) return NULL; - area->_Init(&fSolver, row, column, content); + area->_Init(&fSolver, left, top, right, bottom); area->SetDefaultBehavior(); area->SetAutoPreferredContentSize(false); return area; } +Area* +BALMLayout::AddItem(BLayoutItem* item, Row* row, Column* column) +{ + if (!BAbstractLayout::AddItem(-1, item)) + return NULL; + Area* area = _AreaForItem(item); + if (!area) + return NULL; + + area->_Init(&fSolver, row, column); + area->SetDefaultBehavior(); + area->SetAutoPreferredContentSize(false); + return area; +} + + +Area* +BALMLayout::AddItemToRight(BLayoutItem* item, Area* leftArea, XTab* right, + YTab* top, YTab* bottom) +{ + XTab* left = leftArea->Right(); + if (!right) + right = AddXTab(); + if (!top) + top = leftArea->Top(); + if (!bottom) + bottom = leftArea->Bottom(); + + return AddItem(item, left, top, right, bottom); +} + + +Area* +BALMLayout::AddItemToLeft(BLayoutItem* item, Area* rightArea, XTab* left, + YTab* top, YTab* bottom) +{ + if (!left) + left = AddXTab(); + XTab* right = rightArea->Left(); + if (!top) + top = rightArea->Top(); + if (!bottom) + bottom = rightArea->Bottom(); + + return AddItem(item, left, top, right, bottom); +} + + +Area* +BALMLayout::AddItemToTop(BLayoutItem* item, Area* bottomArea, YTab* top, + XTab* left, XTab* right) +{ + if (!left) + left = bottomArea->Left(); + if (!right) + right = bottomArea->Right(); + if (!top) + top = AddYTab(); + YTab* bottom = bottomArea->Top(); + + return AddItem(item, left, top, right, bottom); +} + + +Area* +BALMLayout::AddItemToBottom(BLayoutItem* item, Area* topArea, YTab* bottom, + XTab* left, XTab* right) +{ + if (!left) + left = topArea->Left(); + if (!right) + right = topArea->Right(); + YTab* top = topArea->Bottom(); + if (!bottom) + bottom = AddYTab(); + + return AddItem(item, left, top, right, bottom); +} + + /** * Finds the area that contains the given control. * @@ -418,6 +621,13 @@ BALMLayout::Spacing() } +BLayoutItem* +BALMLayout::_CreateLayoutItem(BView* view) +{ + return new(std::nothrow) BViewLayoutItem(view); +} + + void BALMLayout::_SolveLayout() { diff --git a/src/libs/alm/Area.cpp b/src/libs/alm/Area.cpp index e4abdd50c0..49b2994429 100644 --- a/src/libs/alm/Area.cpp +++ b/src/libs/alm/Area.cpp @@ -549,8 +549,7 @@ Area::Area(BLayoutItem* item) * Initialize variables. */ void -Area::_Init(LinearSpec* ls, XTab* left, YTab* top, XTab* right, YTab* bottom, - BView* content) +Area::_Init(LinearSpec* ls, XTab* left, YTab* top, XTab* right, YTab* bottom) { fShrinkPenalties = BSize(2, 2); fGrowPenalties = BSize(1, 1); @@ -578,10 +577,9 @@ Area::_Init(LinearSpec* ls, XTab* left, YTab* top, XTab* right, YTab* bottom, void -Area::_Init(LinearSpec* ls, Row* row, Column* column, BView* content) +Area::_Init(LinearSpec* ls, Row* row, Column* column) { - _Init(ls, column->Left(), row->Top(), column->Right(), row->Bottom(), - content); + _Init(ls, column->Left(), row->Top(), column->Right(), row->Bottom()); fRow = row; fColumn = column; } diff --git a/src/libs/alm/Jamfile b/src/libs/alm/Jamfile index ce79d1caf2..de8903ba7f 100644 --- a/src/libs/alm/Jamfile +++ b/src/libs/alm/Jamfile @@ -4,6 +4,7 @@ SetSubDirSupportedPlatformsBeOSCompatible ; UseLibraryHeaders lp_solve linprog alm ; UsePrivateHeaders shared ; +UsePrivateHeaders [ FDirName $(SUBDIR) $(DOTDOT) $(DOTDOT) kits interface ] ; SharedLibrary libalm.so : @@ -16,4 +17,3 @@ SharedLibrary libalm.so : : be liblpsolve55.so liblinprog.so $(TARGET_LIBSUPC++) ; -