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; 19*04a0e9c7SJonathan Schleifer 20*04a0e9c7SJonathan Schleifer 21*04a0e9c7SJonathan Schleifer namespace LinearProgramming { 226c4a44e3Sczeidler class Constraint; 23*04a0e9c7SJonathan Schleifer }; 246c4a44e3Sczeidler 25a25ffa4fSAlex Wilson 26419fe0b8SAlex Wilson namespace BPrivate { 27419fe0b8SAlex Wilson class SharedSolver; 28419fe0b8SAlex Wilson }; 29419fe0b8SAlex Wilson 30a25ffa4fSAlex Wilson 318d9b6ef4SClemens Zeidler namespace BALM { 328d9b6ef4SClemens Zeidler 33ef93b55dSClemens Zeidler 34a25ffa4fSAlex Wilson class Column; 350da6f2e9SAlex Wilson class ALMGroup; 36a25ffa4fSAlex Wilson class Row; 37ef93b55dSClemens Zeidler class RowColumnManager; 38ef93b55dSClemens Zeidler 39ef93b55dSClemens Zeidler 409503cf19SClemens Zeidler /*! 419503cf19SClemens Zeidler * A GUI layout engine using the Auckland Layout Model (ALM). 428d9b6ef4SClemens Zeidler */ 438d9b6ef4SClemens Zeidler class BALMLayout : public BAbstractLayout { 448d9b6ef4SClemens Zeidler public: 4575e2dcf8SAlex Wilson BALMLayout(float hSpacing = 0.0f, 4675e2dcf8SAlex Wilson float vSpacing = 0.0f, 47b23e9af5SClemens Zeidler BALMLayout* friendLayout = NULL); 4835bf0b5cSAlex Wilson BALMLayout(BMessage* archive); 498d9b6ef4SClemens Zeidler virtual ~BALMLayout(); 508d9b6ef4SClemens Zeidler 5157014d1fSczeidler BReference<XTab> AddXTab(); 52b50d4ed8SAlex Wilson void AddXTabs(BReference<XTab>* tabs, uint32 count); 5357014d1fSczeidler BReference<YTab> AddYTab(); 54b50d4ed8SAlex Wilson void AddYTabs(BReference<YTab>* tabs, uint32 count); 5557014d1fSczeidler 56ef93b55dSClemens Zeidler int32 CountXTabs() const; 57ef93b55dSClemens Zeidler int32 CountYTabs() const; 58681f48fcSAlex Wilson XTab* XTabAt(int32 index, bool ordered = false); 59bc7956c7SAlex Wilson XTab* XTabAt(int32 index) const; 60681f48fcSAlex Wilson YTab* YTabAt(int32 index, bool ordered = false); 61bc7956c7SAlex Wilson YTab* YTabAt(int32 index) const; 626c4a44e3Sczeidler const XTabList GetXTabs() const; 636c4a44e3Sczeidler const YTabList GetYTabs() const; 64bc7956c7SAlex Wilson 65d7568eabSczeidler int32 IndexOf(XTab* tab, bool ordered = false); 66d7568eabSczeidler int32 IndexOf(YTab* tab, bool ordered = false); 67ef93b55dSClemens Zeidler 686c4a44e3Sczeidler int32 CountConstraints() const; 696c4a44e3Sczeidler Constraint* ConstraintAt(int32 index) const; 706c4a44e3Sczeidler bool AddConstraint(Constraint* constraint); 716c4a44e3Sczeidler bool RemoveConstraint(Constraint* constraint, 726c4a44e3Sczeidler bool deleteConstraint = true); 736c4a44e3Sczeidler 746c4a44e3Sczeidler Constraint* AddConstraint(double coeff1, Variable* var1, 756c4a44e3Sczeidler OperatorType op, double rightSide, 766c4a44e3Sczeidler double penaltyNeg = -1, 776c4a44e3Sczeidler double penaltyPos = -1); 786c4a44e3Sczeidler Constraint* AddConstraint(double coeff1, Variable* var1, 796c4a44e3Sczeidler double coeff2, Variable* var2, 806c4a44e3Sczeidler OperatorType op, double rightSide, 816c4a44e3Sczeidler double penaltyNeg = -1, 826c4a44e3Sczeidler double penaltyPos = -1); 836c4a44e3Sczeidler Constraint* AddConstraint(double coeff1, Variable* var1, 846c4a44e3Sczeidler double coeff2, Variable* var2, 856c4a44e3Sczeidler double coeff3, Variable* var3, 866c4a44e3Sczeidler OperatorType op, double rightSide, 876c4a44e3Sczeidler double penaltyNeg = -1, 886c4a44e3Sczeidler double penaltyPos = -1); 896c4a44e3Sczeidler Constraint* AddConstraint(double coeff1, Variable* var1, 906c4a44e3Sczeidler double coeff2, Variable* var2, 916c4a44e3Sczeidler double coeff3, Variable* var3, 926c4a44e3Sczeidler double coeff4, Variable* var4, 936c4a44e3Sczeidler OperatorType op, double rightSide, 946c4a44e3Sczeidler double penaltyNeg = -1, 956c4a44e3Sczeidler double penaltyPos = -1); 966c4a44e3Sczeidler 978d9b6ef4SClemens Zeidler Row* AddRow(YTab* top, YTab* bottom); 988d9b6ef4SClemens Zeidler Column* AddColumn(XTab* left, XTab* right); 998d9b6ef4SClemens Zeidler 1008d9b6ef4SClemens Zeidler XTab* Left() const; 1018d9b6ef4SClemens Zeidler XTab* Right() const; 1028d9b6ef4SClemens Zeidler YTab* Top() const; 1038d9b6ef4SClemens Zeidler YTab* Bottom() const; 1048d9b6ef4SClemens Zeidler 105a25ffa4fSAlex Wilson LinearProgramming::LinearSpec* Solver() const; 1066c4a44e3Sczeidler LinearProgramming::ResultType ValidateLayout(); 1078d9b6ef4SClemens Zeidler 10875e2dcf8SAlex Wilson void SetInsets(float insets); 10975e2dcf8SAlex Wilson void SetInsets(float x, float y); 11075e2dcf8SAlex Wilson void SetInsets(float left, float top, float right, 11175e2dcf8SAlex Wilson float bottom); 11275e2dcf8SAlex Wilson void GetInsets(float* left, float* top, float* right, 11375e2dcf8SAlex Wilson float* bottom) const; 11496e2013eSClemens Zeidler 11575e2dcf8SAlex Wilson void SetSpacing(float hSpacing, float vSpacing); 11675e2dcf8SAlex Wilson void GetSpacing(float* _hSpacing, 11775e2dcf8SAlex Wilson float* _vSpacing) const; 1185b6fca06SClemens Zeidler 119c3e57dc3Sczeidler Area* AreaFor(int32 id) const; 12070e20761SClemens Zeidler Area* AreaFor(const BView* view) const; 1215b6fca06SClemens Zeidler Area* AreaFor(const BLayoutItem* item) const; 122b7630c4cSczeidler int32 CountAreas() const; 123ef93b55dSClemens Zeidler Area* AreaAt(int32 index) const; 12496e2013eSClemens Zeidler 12570e20761SClemens Zeidler XTab* LeftOf(const BView* view) const; 12670e20761SClemens Zeidler XTab* LeftOf(const BLayoutItem* item) const; 12770e20761SClemens Zeidler XTab* RightOf(const BView* view) const; 12870e20761SClemens Zeidler XTab* RightOf(const BLayoutItem* item) const; 12970e20761SClemens Zeidler YTab* TopOf(const BView* view) const; 13070e20761SClemens Zeidler YTab* TopOf(const BLayoutItem* item) const; 13170e20761SClemens Zeidler YTab* BottomOf(const BView* view) const; 13270e20761SClemens Zeidler YTab* BottomOf(const BLayoutItem* item) const; 13370e20761SClemens Zeidler 13421f083afSClemens Zeidler virtual BLayoutItem* AddView(BView* child); 13521f083afSClemens Zeidler virtual BLayoutItem* AddView(int32 index, BView* child); 13621f083afSClemens Zeidler virtual Area* AddView(BView* view, XTab* left, YTab* top, 13770e20761SClemens Zeidler XTab* right = NULL, YTab* bottom = NULL); 13821f083afSClemens Zeidler virtual Area* AddView(BView* view, Row* row, Column* column); 13921f083afSClemens Zeidler 14021f083afSClemens Zeidler virtual bool AddItem(BLayoutItem* item); 14121f083afSClemens Zeidler virtual bool AddItem(int32 index, BLayoutItem* item); 14221f083afSClemens Zeidler virtual Area* AddItem(BLayoutItem* item, XTab* left, 14370e20761SClemens Zeidler YTab* top, XTab* right = NULL, 14470e20761SClemens Zeidler YTab* bottom = NULL); 14521f083afSClemens Zeidler virtual Area* AddItem(BLayoutItem* item, Row* row, 14621f083afSClemens Zeidler Column* column); 14757014d1fSczeidler 1482bbf8b1fSAlex Wilson struct BadLayoutPolicy; 1492bbf8b1fSAlex Wilson 1502bbf8b1fSAlex Wilson void SetBadLayoutPolicy(BadLayoutPolicy* policy); 1512bbf8b1fSAlex Wilson BadLayoutPolicy* GetBadLayoutPolicy() const; 152b7630c4cSczeidler 15321f083afSClemens Zeidler virtual BSize BaseMinSize(); 15421f083afSClemens Zeidler virtual BSize BaseMaxSize(); 15521f083afSClemens Zeidler virtual BSize BasePreferredSize(); 15621f083afSClemens Zeidler virtual BAlignment BaseAlignment(); 15721f083afSClemens Zeidler 15835bf0b5cSAlex Wilson virtual status_t Archive(BMessage* into, bool deep = true) const; 15935bf0b5cSAlex Wilson static BArchivable* Instantiate(BMessage* archive); 16035bf0b5cSAlex Wilson 161324ce285SAlex Wilson virtual status_t Perform(perform_code d, void* arg); 162324ce285SAlex Wilson 16317499672SAlex Wilson protected: 16421f083afSClemens Zeidler virtual bool ItemAdded(BLayoutItem* item, int32 atIndex); 16521f083afSClemens Zeidler virtual void ItemRemoved(BLayoutItem* item, int32 fromIndex); 16617499672SAlex Wilson 16735bf0b5cSAlex Wilson virtual status_t ItemArchived(BMessage* into, BLayoutItem* item, 16835bf0b5cSAlex Wilson int32 index) const; 16935bf0b5cSAlex Wilson virtual status_t ItemUnarchived(const BMessage* from, 17035bf0b5cSAlex Wilson BLayoutItem* item, int32 index); 17135bf0b5cSAlex Wilson 17235bf0b5cSAlex Wilson virtual status_t AllUnarchived(const BMessage* archive); 17335bf0b5cSAlex Wilson virtual status_t AllArchived(BMessage* archive) const; 17435bf0b5cSAlex Wilson 17517499672SAlex Wilson virtual void LayoutInvalidated(bool children); 17617499672SAlex Wilson virtual void DoLayout(); 17721f083afSClemens Zeidler 1782bbf8b1fSAlex Wilson public: 179015e5f06SAlex Wilson struct BadLayoutPolicy : public BArchivable { 180015e5f06SAlex Wilson BadLayoutPolicy(); 181015e5f06SAlex Wilson BadLayoutPolicy(BMessage* archive); 1822bbf8b1fSAlex Wilson virtual ~BadLayoutPolicy(); 1832bbf8b1fSAlex Wilson /* return false to abandon layout, true to use layout */ 18409e87fa3SAlex Wilson virtual bool OnBadLayout(BALMLayout* layout, 185015e5f06SAlex Wilson LinearProgramming::ResultType result, 186015e5f06SAlex Wilson BLayoutContext* context) = 0; 1872bbf8b1fSAlex Wilson }; 1882bbf8b1fSAlex Wilson 1892bbf8b1fSAlex Wilson struct DefaultPolicy : public BadLayoutPolicy { 190015e5f06SAlex Wilson DefaultPolicy(); 191015e5f06SAlex Wilson DefaultPolicy(BMessage* archive); 1922bbf8b1fSAlex Wilson virtual ~DefaultPolicy(); 19309e87fa3SAlex Wilson virtual bool OnBadLayout(BALMLayout* layout, 194015e5f06SAlex Wilson LinearProgramming::ResultType result, 195015e5f06SAlex Wilson BLayoutContext* context); 196015e5f06SAlex Wilson virtual status_t Archive(BMessage* message, 197015e5f06SAlex Wilson bool deep = false) const; 198015e5f06SAlex Wilson static BArchivable* Instantiate(BMessage* message); 1992bbf8b1fSAlex Wilson }; 2002bbf8b1fSAlex Wilson 2018d9b6ef4SClemens Zeidler private: 202324ce285SAlex Wilson 203324ce285SAlex Wilson // FBC padding 204324ce285SAlex Wilson virtual void _ReservedALMLayout1(); 205324ce285SAlex Wilson virtual void _ReservedALMLayout2(); 206324ce285SAlex Wilson virtual void _ReservedALMLayout3(); 207324ce285SAlex Wilson virtual void _ReservedALMLayout4(); 208324ce285SAlex Wilson virtual void _ReservedALMLayout5(); 209324ce285SAlex Wilson virtual void _ReservedALMLayout6(); 210324ce285SAlex Wilson virtual void _ReservedALMLayout7(); 211324ce285SAlex Wilson virtual void _ReservedALMLayout8(); 212324ce285SAlex Wilson virtual void _ReservedALMLayout9(); 213324ce285SAlex Wilson virtual void _ReservedALMLayout10(); 214324ce285SAlex Wilson 215324ce285SAlex Wilson // forbidden methods 216324ce285SAlex Wilson BALMLayout(const BALMLayout&); 217324ce285SAlex Wilson void operator =(const BALMLayout&); 218324ce285SAlex Wilson 219a9761aedSAlex Wilson private: 220a9761aedSAlex Wilson template <class T> 221a9761aedSAlex Wilson struct TabAddTransaction; 222c761a8a6SAlex Wilson 223a9761aedSAlex Wilson template <class T> 224a9761aedSAlex Wilson friend class TabAddTransaction; 225419fe0b8SAlex Wilson friend class BPrivate::SharedSolver; 226324ce285SAlex Wilson 22757014d1fSczeidler friend class XTab; 22857014d1fSczeidler friend class YTab; 22975e2dcf8SAlex Wilson friend class Area; 23075e2dcf8SAlex Wilson 2316c4a44e3Sczeidler class BALMLayoutSpecListener; 2326c4a44e3Sczeidler friend class BALMLayoutSpecListener; 2336c4a44e3Sczeidler 2347e021d45SAlex Wilson float InsetForTab(XTab* tab) const; 2357e021d45SAlex Wilson float InsetForTab(YTab* tab) const; 23657014d1fSczeidler 237419fe0b8SAlex Wilson void UpdateConstraints(BLayoutContext* context); 238419fe0b8SAlex Wilson 239c761a8a6SAlex Wilson void _RemoveSelfFromTab(XTab* tab); 240c761a8a6SAlex Wilson void _RemoveSelfFromTab(YTab* tab); 241a9761aedSAlex Wilson bool _HasTabInLayout(XTab* tab); 242a9761aedSAlex Wilson bool _HasTabInLayout(YTab* tab); 243a9761aedSAlex Wilson bool _AddedTab(XTab* tab); 244a9761aedSAlex Wilson bool _AddedTab(YTab* tab); 245c761a8a6SAlex Wilson 246574533efSAlex Wilson BLayoutItem* _LayoutItemToAdd(BView* view); 24735bf0b5cSAlex Wilson void _SetSolver(BPrivate::SharedSolver* solver); 24821f083afSClemens Zeidler 249419fe0b8SAlex Wilson BPrivate::SharedSolver* fSolver; 2506c4a44e3Sczeidler BALMLayoutSpecListener* fSpecListener; 2518d9b6ef4SClemens Zeidler 25257014d1fSczeidler BReference<XTab> fLeft; 25357014d1fSczeidler BReference<XTab> fRight; 25457014d1fSczeidler BReference<YTab> fTop; 25557014d1fSczeidler BReference<YTab> fBottom; 2568d9b6ef4SClemens Zeidler BSize fMinSize; 2578d9b6ef4SClemens Zeidler BSize fMaxSize; 2588d9b6ef4SClemens Zeidler BSize fPreferredSize; 25996e2013eSClemens Zeidler 26075e2dcf8SAlex Wilson float fLeftInset; 26175e2dcf8SAlex Wilson float fRightInset; 26275e2dcf8SAlex Wilson float fTopInset; 26375e2dcf8SAlex Wilson float fBottomInset; 26475e2dcf8SAlex Wilson 26575e2dcf8SAlex Wilson float fHSpacing; 26675e2dcf8SAlex Wilson float fVSpacing; 2675b6fca06SClemens Zeidler 268ef93b55dSClemens Zeidler XTabList fXTabList; 269681f48fcSAlex Wilson bool fXTabsSorted; 270681f48fcSAlex Wilson 271ef93b55dSClemens Zeidler YTabList fYTabList; 272681f48fcSAlex Wilson bool fYTabsSorted; 273ef93b55dSClemens Zeidler 2746c4a44e3Sczeidler BObjectList<Constraint> fConstraints; 2756c4a44e3Sczeidler 276ef93b55dSClemens Zeidler RowColumnManager* fRowColumnManager; 277324ce285SAlex Wilson 2782bbf8b1fSAlex Wilson BadLayoutPolicy* fBadLayoutPolicy; 2796c4a44e3Sczeidler 280324ce285SAlex Wilson uint32 _reserved[5]; 2818d9b6ef4SClemens Zeidler }; 2828d9b6ef4SClemens Zeidler 2838d9b6ef4SClemens Zeidler } // namespace BALM 2848d9b6ef4SClemens Zeidler 285b50d4ed8SAlex Wilson 2868d9b6ef4SClemens Zeidler using BALM::BALMLayout; 2878d9b6ef4SClemens Zeidler 288b50d4ed8SAlex Wilson 2898d9b6ef4SClemens Zeidler #endif // ALM_LAYOUT_H 290