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 <Size.h> 118d9b6ef4SClemens Zeidler 128d9b6ef4SClemens Zeidler #include "Area.h" 138d9b6ef4SClemens Zeidler #include "LinearSpec.h" 1470e20761SClemens Zeidler #include "Tab.h" 158d9b6ef4SClemens Zeidler 168d9b6ef4SClemens Zeidler 17a25ffa4fSAlex Wilson class BView; 18a25ffa4fSAlex Wilson class BLayoutItem; 19a25ffa4fSAlex Wilson 20419fe0b8SAlex Wilson namespace BPrivate { 21419fe0b8SAlex Wilson class SharedSolver; 22419fe0b8SAlex Wilson }; 23419fe0b8SAlex Wilson 24a25ffa4fSAlex Wilson 258d9b6ef4SClemens Zeidler namespace BALM { 268d9b6ef4SClemens Zeidler 27ef93b55dSClemens Zeidler 28a25ffa4fSAlex Wilson class Column; 290da6f2e9SAlex Wilson class ALMGroup; 30a25ffa4fSAlex Wilson class Row; 31ef93b55dSClemens Zeidler class RowColumnManager; 32ef93b55dSClemens Zeidler 33ef93b55dSClemens Zeidler 349503cf19SClemens Zeidler /*! 359503cf19SClemens Zeidler * A GUI layout engine using the Auckland Layout Model (ALM). 368d9b6ef4SClemens Zeidler */ 378d9b6ef4SClemens Zeidler class BALMLayout : public BAbstractLayout { 388d9b6ef4SClemens Zeidler public: 3975e2dcf8SAlex Wilson BALMLayout(float hSpacing = 0.0f, 4075e2dcf8SAlex Wilson float vSpacing = 0.0f, 41b23e9af5SClemens Zeidler BALMLayout* friendLayout = NULL); 428d9b6ef4SClemens Zeidler virtual ~BALMLayout(); 438d9b6ef4SClemens Zeidler 4457014d1fSczeidler BReference<XTab> AddXTab(); 45b50d4ed8SAlex Wilson void AddXTabs(BReference<XTab>* tabs, uint32 count); 4657014d1fSczeidler BReference<YTab> AddYTab(); 47b50d4ed8SAlex Wilson void AddYTabs(BReference<YTab>* tabs, uint32 count); 4857014d1fSczeidler 49ef93b55dSClemens Zeidler int32 CountXTabs() const; 50ef93b55dSClemens Zeidler int32 CountYTabs() const; 51681f48fcSAlex Wilson XTab* XTabAt(int32 index, bool ordered = false); 52681f48fcSAlex Wilson YTab* YTabAt(int32 index, bool ordered = false); 53*d7568eabSczeidler int32 IndexOf(XTab* tab, bool ordered = false); 54*d7568eabSczeidler int32 IndexOf(YTab* tab, bool ordered = false); 55ef93b55dSClemens Zeidler 568d9b6ef4SClemens Zeidler Row* AddRow(YTab* top, YTab* bottom); 578d9b6ef4SClemens Zeidler Column* AddColumn(XTab* left, XTab* right); 588d9b6ef4SClemens Zeidler 598d9b6ef4SClemens Zeidler XTab* Left() const; 608d9b6ef4SClemens Zeidler XTab* Right() const; 618d9b6ef4SClemens Zeidler YTab* Top() const; 628d9b6ef4SClemens Zeidler YTab* Bottom() const; 638d9b6ef4SClemens Zeidler 64a25ffa4fSAlex Wilson LinearProgramming::LinearSpec* Solver() const; 658d9b6ef4SClemens Zeidler 6675e2dcf8SAlex Wilson void SetInsets(float insets); 6775e2dcf8SAlex Wilson void SetInsets(float x, float y); 6875e2dcf8SAlex Wilson void SetInsets(float left, float top, float right, 6975e2dcf8SAlex Wilson float bottom); 7075e2dcf8SAlex Wilson void GetInsets(float* left, float* top, float* right, 7175e2dcf8SAlex Wilson float* bottom) const; 7296e2013eSClemens Zeidler 7375e2dcf8SAlex Wilson void SetSpacing(float hSpacing, float vSpacing); 7475e2dcf8SAlex Wilson void GetSpacing(float* _hSpacing, 7575e2dcf8SAlex Wilson float* _vSpacing) const; 765b6fca06SClemens Zeidler 77c3e57dc3Sczeidler Area* AreaFor(int32 id) const; 7870e20761SClemens Zeidler Area* AreaFor(const BView* view) const; 795b6fca06SClemens Zeidler Area* AreaFor(const BLayoutItem* item) const; 80b7630c4cSczeidler int32 CountAreas() const; 81ef93b55dSClemens Zeidler Area* AreaAt(int32 index) const; 8296e2013eSClemens Zeidler 8370e20761SClemens Zeidler XTab* LeftOf(const BView* view) const; 8470e20761SClemens Zeidler XTab* LeftOf(const BLayoutItem* item) const; 8570e20761SClemens Zeidler XTab* RightOf(const BView* view) const; 8670e20761SClemens Zeidler XTab* RightOf(const BLayoutItem* item) const; 8770e20761SClemens Zeidler YTab* TopOf(const BView* view) const; 8870e20761SClemens Zeidler YTab* TopOf(const BLayoutItem* item) const; 8970e20761SClemens Zeidler YTab* BottomOf(const BView* view) const; 9070e20761SClemens Zeidler YTab* BottomOf(const BLayoutItem* item) const; 9170e20761SClemens Zeidler 9221f083afSClemens Zeidler virtual BLayoutItem* AddView(BView* child); 9321f083afSClemens Zeidler virtual BLayoutItem* AddView(int32 index, BView* child); 9421f083afSClemens Zeidler virtual Area* AddView(BView* view, XTab* left, YTab* top, 9570e20761SClemens Zeidler XTab* right = NULL, YTab* bottom = NULL); 9621f083afSClemens Zeidler virtual Area* AddView(BView* view, Row* row, Column* column); 9721f083afSClemens Zeidler 9821f083afSClemens Zeidler virtual bool AddItem(BLayoutItem* item); 9921f083afSClemens Zeidler virtual bool AddItem(int32 index, BLayoutItem* item); 10021f083afSClemens Zeidler virtual Area* AddItem(BLayoutItem* item, XTab* left, 10170e20761SClemens Zeidler YTab* top, XTab* right = NULL, 10270e20761SClemens Zeidler YTab* bottom = NULL); 10321f083afSClemens Zeidler virtual Area* AddItem(BLayoutItem* item, Row* row, 10421f083afSClemens Zeidler Column* column); 10557014d1fSczeidler 106b7630c4cSczeidler bool SaveLayout(BMessage* archive) const; 107b7630c4cSczeidler bool RestoreLayout(const BMessage* archive); 1082bbf8b1fSAlex Wilson struct BadLayoutPolicy; 1092bbf8b1fSAlex Wilson 1102bbf8b1fSAlex Wilson void SetBadLayoutPolicy(BadLayoutPolicy* policy); 1112bbf8b1fSAlex Wilson BadLayoutPolicy* GetBadLayoutPolicy() const; 112b7630c4cSczeidler 11321f083afSClemens Zeidler virtual BSize BaseMinSize(); 11421f083afSClemens Zeidler virtual BSize BaseMaxSize(); 11521f083afSClemens Zeidler virtual BSize BasePreferredSize(); 11621f083afSClemens Zeidler virtual BAlignment BaseAlignment(); 11721f083afSClemens Zeidler 118324ce285SAlex Wilson virtual status_t Perform(perform_code d, void* arg); 119324ce285SAlex Wilson 12017499672SAlex Wilson protected: 12121f083afSClemens Zeidler virtual bool ItemAdded(BLayoutItem* item, int32 atIndex); 12221f083afSClemens Zeidler virtual void ItemRemoved(BLayoutItem* item, int32 fromIndex); 12317499672SAlex Wilson 12417499672SAlex Wilson virtual void LayoutInvalidated(bool children); 12517499672SAlex Wilson virtual void DoLayout(); 12621f083afSClemens Zeidler 1272bbf8b1fSAlex Wilson public: 1282bbf8b1fSAlex Wilson struct BadLayoutPolicy { 1292bbf8b1fSAlex Wilson virtual ~BadLayoutPolicy(); 1302bbf8b1fSAlex Wilson /* return false to abandon layout, true to use layout */ 13109e87fa3SAlex Wilson virtual bool OnBadLayout(BALMLayout* layout, 13209e87fa3SAlex Wilson LinearProgramming::ResultType result, BLayoutContext* context) = 0; 1332bbf8b1fSAlex Wilson }; 1342bbf8b1fSAlex Wilson 1352bbf8b1fSAlex Wilson struct DefaultPolicy : public BadLayoutPolicy { 1362bbf8b1fSAlex Wilson virtual ~DefaultPolicy(); 13709e87fa3SAlex Wilson virtual bool OnBadLayout(BALMLayout* layout, 13809e87fa3SAlex Wilson LinearProgramming::ResultType result, BLayoutContext* context); 1392bbf8b1fSAlex Wilson }; 1402bbf8b1fSAlex Wilson 1418d9b6ef4SClemens Zeidler private: 142324ce285SAlex Wilson 143324ce285SAlex Wilson // FBC padding 144324ce285SAlex Wilson virtual void _ReservedALMLayout1(); 145324ce285SAlex Wilson virtual void _ReservedALMLayout2(); 146324ce285SAlex Wilson virtual void _ReservedALMLayout3(); 147324ce285SAlex Wilson virtual void _ReservedALMLayout4(); 148324ce285SAlex Wilson virtual void _ReservedALMLayout5(); 149324ce285SAlex Wilson virtual void _ReservedALMLayout6(); 150324ce285SAlex Wilson virtual void _ReservedALMLayout7(); 151324ce285SAlex Wilson virtual void _ReservedALMLayout8(); 152324ce285SAlex Wilson virtual void _ReservedALMLayout9(); 153324ce285SAlex Wilson virtual void _ReservedALMLayout10(); 154324ce285SAlex Wilson 155324ce285SAlex Wilson // forbidden methods 156324ce285SAlex Wilson BALMLayout(const BALMLayout&); 157324ce285SAlex Wilson void operator =(const BALMLayout&); 158324ce285SAlex Wilson 159a9761aedSAlex Wilson private: 160a9761aedSAlex Wilson template <class T> 161a9761aedSAlex Wilson struct TabAddTransaction; 162c761a8a6SAlex Wilson 163a9761aedSAlex Wilson template <class T> 164a9761aedSAlex Wilson friend class TabAddTransaction; 165419fe0b8SAlex Wilson friend class BPrivate::SharedSolver; 166324ce285SAlex Wilson 16757014d1fSczeidler friend class XTab; 16857014d1fSczeidler friend class YTab; 16975e2dcf8SAlex Wilson friend class Area; 17075e2dcf8SAlex Wilson 1717e021d45SAlex Wilson float InsetForTab(XTab* tab) const; 1727e021d45SAlex Wilson float InsetForTab(YTab* tab) const; 17357014d1fSczeidler 174419fe0b8SAlex Wilson void UpdateConstraints(BLayoutContext* context); 175419fe0b8SAlex Wilson 176c761a8a6SAlex Wilson void _RemoveSelfFromTab(XTab* tab); 177c761a8a6SAlex Wilson void _RemoveSelfFromTab(YTab* tab); 178a9761aedSAlex Wilson bool _HasTabInLayout(XTab* tab); 179a9761aedSAlex Wilson bool _HasTabInLayout(YTab* tab); 180a9761aedSAlex Wilson bool _AddedTab(XTab* tab); 181a9761aedSAlex Wilson bool _AddedTab(YTab* tab); 182c761a8a6SAlex Wilson 183574533efSAlex Wilson BLayoutItem* _LayoutItemToAdd(BView* view); 18421f083afSClemens Zeidler 185419fe0b8SAlex Wilson BPrivate::SharedSolver* fSolver; 1868d9b6ef4SClemens Zeidler 18757014d1fSczeidler BReference<XTab> fLeft; 18857014d1fSczeidler BReference<XTab> fRight; 18957014d1fSczeidler BReference<YTab> fTop; 19057014d1fSczeidler BReference<YTab> fBottom; 1918d9b6ef4SClemens Zeidler BSize fMinSize; 1928d9b6ef4SClemens Zeidler BSize fMaxSize; 1938d9b6ef4SClemens Zeidler BSize fPreferredSize; 19496e2013eSClemens Zeidler 19575e2dcf8SAlex Wilson float fLeftInset; 19675e2dcf8SAlex Wilson float fRightInset; 19775e2dcf8SAlex Wilson float fTopInset; 19875e2dcf8SAlex Wilson float fBottomInset; 19975e2dcf8SAlex Wilson 20075e2dcf8SAlex Wilson float fHSpacing; 20175e2dcf8SAlex Wilson float fVSpacing; 2025b6fca06SClemens Zeidler 203ef93b55dSClemens Zeidler XTabList fXTabList; 204681f48fcSAlex Wilson bool fXTabsSorted; 205681f48fcSAlex Wilson 206ef93b55dSClemens Zeidler YTabList fYTabList; 207681f48fcSAlex Wilson bool fYTabsSorted; 208ef93b55dSClemens Zeidler 209ef93b55dSClemens Zeidler RowColumnManager* fRowColumnManager; 210324ce285SAlex Wilson 2112bbf8b1fSAlex Wilson BadLayoutPolicy* fBadLayoutPolicy; 212324ce285SAlex Wilson uint32 _reserved[5]; 2138d9b6ef4SClemens Zeidler }; 2148d9b6ef4SClemens Zeidler 2158d9b6ef4SClemens Zeidler } // namespace BALM 2168d9b6ef4SClemens Zeidler 217b50d4ed8SAlex Wilson 2188d9b6ef4SClemens Zeidler using BALM::BALMLayout; 2198d9b6ef4SClemens Zeidler 220b50d4ed8SAlex Wilson 2218d9b6ef4SClemens Zeidler #endif // ALM_LAYOUT_H 222