18d9b6ef4SClemens Zeidler /* 28d9b6ef4SClemens Zeidler * Copyright 2006 - 2010, Haiku, Inc. All rights reserved. 38d9b6ef4SClemens Zeidler * Distributed under the terms of the MIT License. 48d9b6ef4SClemens Zeidler */ 58d9b6ef4SClemens Zeidler #ifndef ALM_LAYOUT_H 68d9b6ef4SClemens Zeidler #define ALM_LAYOUT_H 78d9b6ef4SClemens Zeidler 89503cf19SClemens Zeidler 98d9b6ef4SClemens Zeidler #include <AbstractLayout.h> 108d9b6ef4SClemens Zeidler #include <File.h> 118d9b6ef4SClemens Zeidler #include <List.h> 128d9b6ef4SClemens Zeidler #include <Size.h> 138d9b6ef4SClemens Zeidler #include <SupportDefs.h> 148d9b6ef4SClemens Zeidler #include <View.h> 158d9b6ef4SClemens Zeidler 168d9b6ef4SClemens Zeidler #include "Area.h" 178d9b6ef4SClemens Zeidler #include "Column.h" 188d9b6ef4SClemens Zeidler #include "LinearSpec.h" 198d9b6ef4SClemens Zeidler #include "Row.h" 2070e20761SClemens Zeidler #include "Tab.h" 218d9b6ef4SClemens Zeidler 228d9b6ef4SClemens Zeidler 238d9b6ef4SClemens Zeidler namespace BALM { 248d9b6ef4SClemens Zeidler 259503cf19SClemens Zeidler /*! 269503cf19SClemens Zeidler * A GUI layout engine using the Auckland Layout Model (ALM). 278d9b6ef4SClemens Zeidler */ 288d9b6ef4SClemens Zeidler class BALMLayout : public BAbstractLayout { 298d9b6ef4SClemens Zeidler public: 3096e2013eSClemens Zeidler BALMLayout(float spacing = 0.0f); 318d9b6ef4SClemens Zeidler virtual ~BALMLayout(); 328d9b6ef4SClemens Zeidler 338d9b6ef4SClemens Zeidler XTab* AddXTab(); 348d9b6ef4SClemens Zeidler YTab* AddYTab(); 358d9b6ef4SClemens Zeidler Row* AddRow(); 368d9b6ef4SClemens Zeidler Row* AddRow(YTab* top, YTab* bottom); 378d9b6ef4SClemens Zeidler Column* AddColumn(); 388d9b6ef4SClemens Zeidler Column* AddColumn(XTab* left, XTab* right); 398d9b6ef4SClemens Zeidler 408d9b6ef4SClemens Zeidler XTab* Left() const; 418d9b6ef4SClemens Zeidler XTab* Right() const; 428d9b6ef4SClemens Zeidler YTab* Top() const; 438d9b6ef4SClemens Zeidler YTab* Bottom() const; 448d9b6ef4SClemens Zeidler 458d9b6ef4SClemens Zeidler char* PerformancePath() const; 468d9b6ef4SClemens Zeidler void SetPerformancePath(char* path); 478d9b6ef4SClemens Zeidler 485b6fca06SClemens Zeidler LinearSpec* Solver() const; 498d9b6ef4SClemens Zeidler 5096e2013eSClemens Zeidler void SetInset(float inset); 515b6fca06SClemens Zeidler float Inset() const; 5296e2013eSClemens Zeidler 5396e2013eSClemens Zeidler void SetSpacing(float spacing); 545b6fca06SClemens Zeidler float Spacing() const; 555b6fca06SClemens Zeidler 5670e20761SClemens Zeidler Area* AreaFor(const BView* view) const; 575b6fca06SClemens Zeidler Area* AreaFor(const BLayoutItem* item) const; 585b6fca06SClemens Zeidler Area* CurrentArea() const; 595b6fca06SClemens Zeidler void SetCurrentArea(const Area* area); 6070e20761SClemens Zeidler void SetCurrentArea(const BView* view); 615b6fca06SClemens Zeidler void SetCurrentArea(const BLayoutItem* item); 6296e2013eSClemens Zeidler 6370e20761SClemens Zeidler XTab* LeftOf(const BView* view) const; 6470e20761SClemens Zeidler XTab* LeftOf(const BLayoutItem* item) const; 6570e20761SClemens Zeidler XTab* RightOf(const BView* view) const; 6670e20761SClemens Zeidler XTab* RightOf(const BLayoutItem* item) const; 6770e20761SClemens Zeidler YTab* TopOf(const BView* view) const; 6870e20761SClemens Zeidler YTab* TopOf(const BLayoutItem* item) const; 6970e20761SClemens Zeidler YTab* BottomOf(const BView* view) const; 7070e20761SClemens Zeidler YTab* BottomOf(const BLayoutItem* item) const; 7170e20761SClemens Zeidler 72*37344020SClemens Zeidler void BuildLayout(GroupItem& item, XTab* left = NULL, 73*37344020SClemens Zeidler YTab* top = NULL, XTab* right = NULL, 74*37344020SClemens Zeidler YTab* bottom = NULL); 75*37344020SClemens Zeidler 7621f083afSClemens Zeidler virtual BLayoutItem* AddView(BView* child); 7721f083afSClemens Zeidler virtual BLayoutItem* AddView(int32 index, BView* child); 7821f083afSClemens Zeidler virtual Area* AddView(BView* view, XTab* left, YTab* top, 7970e20761SClemens Zeidler XTab* right = NULL, YTab* bottom = NULL); 8021f083afSClemens Zeidler virtual Area* AddView(BView* view, Row* row, Column* column); 815b6fca06SClemens Zeidler virtual Area* AddViewToRight(BView* view, XTab* right = NULL, 825b6fca06SClemens Zeidler YTab* top = NULL, YTab* bottom = NULL); 835b6fca06SClemens Zeidler virtual Area* AddViewToLeft(BView* view, XTab* left = NULL, 845b6fca06SClemens Zeidler YTab* top = NULL, YTab* bottom = NULL); 855b6fca06SClemens Zeidler virtual Area* AddViewToTop(BView* view, YTab* top = NULL, 865b6fca06SClemens Zeidler XTab* left = NULL, XTab* right = NULL); 875b6fca06SClemens Zeidler virtual Area* AddViewToBottom(BView* view, 8821f083afSClemens Zeidler YTab* bottom = NULL, XTab* left = NULL, 8921f083afSClemens Zeidler XTab* right = NULL); 9021f083afSClemens Zeidler 9121f083afSClemens Zeidler virtual bool AddItem(BLayoutItem* item); 9221f083afSClemens Zeidler virtual bool AddItem(int32 index, BLayoutItem* item); 9321f083afSClemens Zeidler virtual Area* AddItem(BLayoutItem* item, XTab* left, 9470e20761SClemens Zeidler YTab* top, XTab* right = NULL, 9570e20761SClemens Zeidler YTab* bottom = NULL); 9621f083afSClemens Zeidler virtual Area* AddItem(BLayoutItem* item, Row* row, 9721f083afSClemens Zeidler Column* column); 9821f083afSClemens Zeidler virtual Area* AddItemToRight(BLayoutItem* item, 995b6fca06SClemens Zeidler XTab* right = NULL, YTab* top = NULL, 1005b6fca06SClemens Zeidler YTab* bottom = NULL); 10121f083afSClemens Zeidler virtual Area* AddItemToLeft(BLayoutItem* item, 1025b6fca06SClemens Zeidler XTab* left = NULL, YTab* top = NULL, 1035b6fca06SClemens Zeidler YTab* bottom = NULL); 10421f083afSClemens Zeidler virtual Area* AddItemToTop(BLayoutItem* item, 1055b6fca06SClemens Zeidler YTab* top = NULL, XTab* left = NULL, 1065b6fca06SClemens Zeidler XTab* right = NULL); 10721f083afSClemens Zeidler virtual Area* AddItemToBottom(BLayoutItem* item, 1085b6fca06SClemens Zeidler YTab* bottom = NULL, XTab* left = NULL, 1095b6fca06SClemens Zeidler XTab* right = NULL); 11021f083afSClemens Zeidler 11121f083afSClemens Zeidler virtual BSize BaseMinSize(); 11221f083afSClemens Zeidler virtual BSize BaseMaxSize(); 11321f083afSClemens Zeidler virtual BSize BasePreferredSize(); 11421f083afSClemens Zeidler virtual BAlignment BaseAlignment(); 11521f083afSClemens Zeidler 11621f083afSClemens Zeidler virtual void InvalidateLayout(bool children = false); 11721f083afSClemens Zeidler 11821f083afSClemens Zeidler virtual bool ItemAdded(BLayoutItem* item, int32 atIndex); 11921f083afSClemens Zeidler virtual void ItemRemoved(BLayoutItem* item, int32 fromIndex); 12021f083afSClemens Zeidler virtual void DerivedLayoutItems(); 12121f083afSClemens Zeidler 1228d9b6ef4SClemens Zeidler private: 12321f083afSClemens Zeidler /*! Add a view without initialize the Area. */ 12421f083afSClemens Zeidler BLayoutItem* _CreateLayoutItem(BView* view); 12521f083afSClemens Zeidler 1260871de7bSClemens Zeidler void _SolveLayout(); 1270871de7bSClemens Zeidler 1288d9b6ef4SClemens Zeidler void _UpdateAreaConstraints(); 1298d9b6ef4SClemens Zeidler 1300871de7bSClemens Zeidler BSize _CalculateMinSize(); 1310871de7bSClemens Zeidler BSize _CalculateMaxSize(); 1320871de7bSClemens Zeidler BSize _CalculatePreferredSize(); 1338d9b6ef4SClemens Zeidler 134*37344020SClemens Zeidler void _ParseGroupItem(GroupItem& item, XTab* left, 135*37344020SClemens Zeidler YTab* top, XTab* right, YTab* bottom); 1368d9b6ef4SClemens Zeidler 1378d9b6ef4SClemens Zeidler LinearSpec fSolver; 1388d9b6ef4SClemens Zeidler 1398d9b6ef4SClemens Zeidler XTab* fLeft; 1408d9b6ef4SClemens Zeidler XTab* fRight; 1418d9b6ef4SClemens Zeidler YTab* fTop; 1428d9b6ef4SClemens Zeidler YTab* fBottom; 1438d9b6ef4SClemens Zeidler BSize fMinSize; 1448d9b6ef4SClemens Zeidler BSize fMaxSize; 1458d9b6ef4SClemens Zeidler BSize fPreferredSize; 1468d9b6ef4SClemens Zeidler char* fPerformancePath; 14796e2013eSClemens Zeidler 14896e2013eSClemens Zeidler float fInset; 14996e2013eSClemens Zeidler float fSpacing; 1505b6fca06SClemens Zeidler 1515b6fca06SClemens Zeidler Area* fCurrentArea; 1528d9b6ef4SClemens Zeidler }; 1538d9b6ef4SClemens Zeidler 1548d9b6ef4SClemens Zeidler } // namespace BALM 1558d9b6ef4SClemens Zeidler 1568d9b6ef4SClemens Zeidler using BALM::BALMLayout; 1578d9b6ef4SClemens Zeidler 1588d9b6ef4SClemens Zeidler #endif // ALM_LAYOUT_H 159