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: 30*b23e9af5SClemens Zeidler BALMLayout(float spacing = 0.0f, 31*b23e9af5SClemens Zeidler BALMLayout* friendLayout = NULL); 328d9b6ef4SClemens Zeidler virtual ~BALMLayout(); 338d9b6ef4SClemens Zeidler 348d9b6ef4SClemens Zeidler XTab* AddXTab(); 358d9b6ef4SClemens Zeidler YTab* AddYTab(); 368d9b6ef4SClemens Zeidler Row* AddRow(); 378d9b6ef4SClemens Zeidler Row* AddRow(YTab* top, YTab* bottom); 388d9b6ef4SClemens Zeidler Column* AddColumn(); 398d9b6ef4SClemens Zeidler Column* AddColumn(XTab* left, XTab* right); 408d9b6ef4SClemens Zeidler 418d9b6ef4SClemens Zeidler XTab* Left() const; 428d9b6ef4SClemens Zeidler XTab* Right() const; 438d9b6ef4SClemens Zeidler YTab* Top() const; 448d9b6ef4SClemens Zeidler YTab* Bottom() const; 458d9b6ef4SClemens Zeidler 468d9b6ef4SClemens Zeidler char* PerformancePath() const; 478d9b6ef4SClemens Zeidler void SetPerformancePath(char* path); 488d9b6ef4SClemens Zeidler 495b6fca06SClemens Zeidler LinearSpec* Solver() const; 508d9b6ef4SClemens Zeidler 5196e2013eSClemens Zeidler void SetInset(float inset); 525b6fca06SClemens Zeidler float Inset() const; 5396e2013eSClemens Zeidler 5496e2013eSClemens Zeidler void SetSpacing(float spacing); 555b6fca06SClemens Zeidler float Spacing() const; 565b6fca06SClemens Zeidler 5770e20761SClemens Zeidler Area* AreaFor(const BView* view) const; 585b6fca06SClemens Zeidler Area* AreaFor(const BLayoutItem* item) const; 595b6fca06SClemens Zeidler Area* CurrentArea() const; 605b6fca06SClemens Zeidler void SetCurrentArea(const Area* area); 6170e20761SClemens Zeidler void SetCurrentArea(const BView* view); 625b6fca06SClemens Zeidler void SetCurrentArea(const BLayoutItem* item); 6396e2013eSClemens Zeidler 6470e20761SClemens Zeidler XTab* LeftOf(const BView* view) const; 6570e20761SClemens Zeidler XTab* LeftOf(const BLayoutItem* item) const; 6670e20761SClemens Zeidler XTab* RightOf(const BView* view) const; 6770e20761SClemens Zeidler XTab* RightOf(const BLayoutItem* item) const; 6870e20761SClemens Zeidler YTab* TopOf(const BView* view) const; 6970e20761SClemens Zeidler YTab* TopOf(const BLayoutItem* item) const; 7070e20761SClemens Zeidler YTab* BottomOf(const BView* view) const; 7170e20761SClemens Zeidler YTab* BottomOf(const BLayoutItem* item) const; 7270e20761SClemens Zeidler 7337344020SClemens Zeidler void BuildLayout(GroupItem& item, XTab* left = NULL, 7437344020SClemens Zeidler YTab* top = NULL, XTab* right = NULL, 7537344020SClemens Zeidler YTab* bottom = NULL); 7637344020SClemens Zeidler 7721f083afSClemens Zeidler virtual BLayoutItem* AddView(BView* child); 7821f083afSClemens Zeidler virtual BLayoutItem* AddView(int32 index, BView* child); 7921f083afSClemens Zeidler virtual Area* AddView(BView* view, XTab* left, YTab* top, 8070e20761SClemens Zeidler XTab* right = NULL, YTab* bottom = NULL); 8121f083afSClemens Zeidler virtual Area* AddView(BView* view, Row* row, Column* column); 825b6fca06SClemens Zeidler virtual Area* AddViewToRight(BView* view, XTab* right = NULL, 835b6fca06SClemens Zeidler YTab* top = NULL, YTab* bottom = NULL); 845b6fca06SClemens Zeidler virtual Area* AddViewToLeft(BView* view, XTab* left = NULL, 855b6fca06SClemens Zeidler YTab* top = NULL, YTab* bottom = NULL); 865b6fca06SClemens Zeidler virtual Area* AddViewToTop(BView* view, YTab* top = NULL, 875b6fca06SClemens Zeidler XTab* left = NULL, XTab* right = NULL); 885b6fca06SClemens Zeidler virtual Area* AddViewToBottom(BView* view, 8921f083afSClemens Zeidler YTab* bottom = NULL, XTab* left = NULL, 9021f083afSClemens Zeidler XTab* right = NULL); 9121f083afSClemens Zeidler 9221f083afSClemens Zeidler virtual bool AddItem(BLayoutItem* item); 9321f083afSClemens Zeidler virtual bool AddItem(int32 index, BLayoutItem* item); 9421f083afSClemens Zeidler virtual Area* AddItem(BLayoutItem* item, XTab* left, 9570e20761SClemens Zeidler YTab* top, XTab* right = NULL, 9670e20761SClemens Zeidler YTab* bottom = NULL); 9721f083afSClemens Zeidler virtual Area* AddItem(BLayoutItem* item, Row* row, 9821f083afSClemens Zeidler Column* column); 9921f083afSClemens Zeidler virtual Area* AddItemToRight(BLayoutItem* item, 1005b6fca06SClemens Zeidler XTab* right = NULL, YTab* top = NULL, 1015b6fca06SClemens Zeidler YTab* bottom = NULL); 10221f083afSClemens Zeidler virtual Area* AddItemToLeft(BLayoutItem* item, 1035b6fca06SClemens Zeidler XTab* left = NULL, YTab* top = NULL, 1045b6fca06SClemens Zeidler YTab* bottom = NULL); 10521f083afSClemens Zeidler virtual Area* AddItemToTop(BLayoutItem* item, 1065b6fca06SClemens Zeidler YTab* top = NULL, XTab* left = NULL, 1075b6fca06SClemens Zeidler XTab* right = NULL); 10821f083afSClemens Zeidler virtual Area* AddItemToBottom(BLayoutItem* item, 1095b6fca06SClemens Zeidler YTab* bottom = NULL, XTab* left = NULL, 1105b6fca06SClemens Zeidler XTab* right = NULL); 11121f083afSClemens Zeidler 11221f083afSClemens Zeidler virtual BSize BaseMinSize(); 11321f083afSClemens Zeidler virtual BSize BaseMaxSize(); 11421f083afSClemens Zeidler virtual BSize BasePreferredSize(); 11521f083afSClemens Zeidler virtual BAlignment BaseAlignment(); 11621f083afSClemens Zeidler 11721f083afSClemens Zeidler virtual void InvalidateLayout(bool children = false); 11821f083afSClemens Zeidler 11921f083afSClemens Zeidler virtual bool ItemAdded(BLayoutItem* item, int32 atIndex); 12021f083afSClemens Zeidler virtual void ItemRemoved(BLayoutItem* item, int32 fromIndex); 12121f083afSClemens Zeidler virtual void DerivedLayoutItems(); 12221f083afSClemens Zeidler 1238d9b6ef4SClemens Zeidler private: 12421f083afSClemens Zeidler /*! Add a view without initialize the Area. */ 12521f083afSClemens Zeidler BLayoutItem* _CreateLayoutItem(BView* view); 12621f083afSClemens Zeidler 1270871de7bSClemens Zeidler void _SolveLayout(); 1280871de7bSClemens Zeidler 1298d9b6ef4SClemens Zeidler void _UpdateAreaConstraints(); 1308d9b6ef4SClemens Zeidler 1310871de7bSClemens Zeidler BSize _CalculateMinSize(); 1320871de7bSClemens Zeidler BSize _CalculateMaxSize(); 1330871de7bSClemens Zeidler BSize _CalculatePreferredSize(); 1348d9b6ef4SClemens Zeidler 13537344020SClemens Zeidler void _ParseGroupItem(GroupItem& item, XTab* left, 13637344020SClemens Zeidler YTab* top, XTab* right, YTab* bottom); 1378d9b6ef4SClemens Zeidler 138*b23e9af5SClemens Zeidler LinearSpec* fSolver; 139*b23e9af5SClemens Zeidler LinearSpec fOwnSolver; 1408d9b6ef4SClemens Zeidler 1418d9b6ef4SClemens Zeidler XTab* fLeft; 1428d9b6ef4SClemens Zeidler XTab* fRight; 1438d9b6ef4SClemens Zeidler YTab* fTop; 1448d9b6ef4SClemens Zeidler YTab* fBottom; 1458d9b6ef4SClemens Zeidler BSize fMinSize; 1468d9b6ef4SClemens Zeidler BSize fMaxSize; 1478d9b6ef4SClemens Zeidler BSize fPreferredSize; 1488d9b6ef4SClemens Zeidler char* fPerformancePath; 14996e2013eSClemens Zeidler 15096e2013eSClemens Zeidler float fInset; 15196e2013eSClemens Zeidler float fSpacing; 1525b6fca06SClemens Zeidler 1535b6fca06SClemens Zeidler Area* fCurrentArea; 1548d9b6ef4SClemens Zeidler }; 1558d9b6ef4SClemens Zeidler 1568d9b6ef4SClemens Zeidler } // namespace BALM 1578d9b6ef4SClemens Zeidler 1588d9b6ef4SClemens Zeidler using BALM::BALMLayout; 1598d9b6ef4SClemens Zeidler 1608d9b6ef4SClemens Zeidler #endif // ALM_LAYOUT_H 161