1 /* 2 * Copyright 2006 - 2010, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef ALM_LAYOUT_H 6 #define ALM_LAYOUT_H 7 8 9 #include <AbstractLayout.h> 10 #include <Size.h> 11 12 #include "Area.h" 13 #include "LinearSpec.h" 14 #include "Tab.h" 15 16 17 class BView; 18 class BLayoutItem; 19 20 21 namespace BALM { 22 23 24 class Column; 25 class ALMGroup; 26 class Row; 27 class RowColumnManager; 28 29 30 /*! 31 * A GUI layout engine using the Auckland Layout Model (ALM). 32 */ 33 class BALMLayout : public BAbstractLayout { 34 public: 35 BALMLayout(float hSpacing = 0.0f, 36 float vSpacing = 0.0f, 37 BALMLayout* friendLayout = NULL); 38 virtual ~BALMLayout(); 39 40 BReference<XTab> AddXTab(); 41 void AddXTabs(BReference<XTab>* tabs, uint32 count); 42 BReference<YTab> AddYTab(); 43 void AddYTabs(BReference<YTab>* tabs, uint32 count); 44 45 int32 CountXTabs() const; 46 int32 CountYTabs() const; 47 XTab* XTabAt(int32 index) const; 48 YTab* YTabAt(int32 index) const; 49 /*! Order the tab list and return a reference to the list. */ 50 const XTabList& OrderedXTabs(); 51 const YTabList& OrderedYTabs(); 52 53 Row* AddRow(YTab* top, YTab* bottom); 54 Column* AddColumn(XTab* left, XTab* right); 55 56 XTab* Left() const; 57 XTab* Right() const; 58 YTab* Top() const; 59 YTab* Bottom() const; 60 61 LinearProgramming::LinearSpec* Solver() const; 62 63 void SetInsets(float insets); 64 void SetInsets(float x, float y); 65 void SetInsets(float left, float top, float right, 66 float bottom); 67 void GetInsets(float* left, float* top, float* right, 68 float* bottom) const; 69 70 void SetSpacing(float hSpacing, float vSpacing); 71 void GetSpacing(float* _hSpacing, 72 float* _vSpacing) const; 73 74 Area* AreaFor(int32 id) const; 75 Area* AreaFor(const BView* view) const; 76 Area* AreaFor(const BLayoutItem* item) const; 77 int32 CountAreas() const; 78 Area* AreaAt(int32 index) const; 79 80 XTab* LeftOf(const BView* view) const; 81 XTab* LeftOf(const BLayoutItem* item) const; 82 XTab* RightOf(const BView* view) const; 83 XTab* RightOf(const BLayoutItem* item) const; 84 YTab* TopOf(const BView* view) const; 85 YTab* TopOf(const BLayoutItem* item) const; 86 YTab* BottomOf(const BView* view) const; 87 YTab* BottomOf(const BLayoutItem* item) const; 88 89 virtual BLayoutItem* AddView(BView* child); 90 virtual BLayoutItem* AddView(int32 index, BView* child); 91 virtual Area* AddView(BView* view, XTab* left, YTab* top, 92 XTab* right = NULL, YTab* bottom = NULL); 93 virtual Area* AddView(BView* view, Row* row, Column* column); 94 95 virtual bool AddItem(BLayoutItem* item); 96 virtual bool AddItem(int32 index, BLayoutItem* item); 97 virtual Area* AddItem(BLayoutItem* item, XTab* left, 98 YTab* top, XTab* right = NULL, 99 YTab* bottom = NULL); 100 virtual Area* AddItem(BLayoutItem* item, Row* row, 101 Column* column); 102 103 bool SaveLayout(BMessage* archive) const; 104 bool RestoreLayout(const BMessage* archive); 105 struct BadLayoutPolicy; 106 107 void SetBadLayoutPolicy(BadLayoutPolicy* policy); 108 BadLayoutPolicy* GetBadLayoutPolicy() const; 109 110 virtual BSize BaseMinSize(); 111 virtual BSize BaseMaxSize(); 112 virtual BSize BasePreferredSize(); 113 virtual BAlignment BaseAlignment(); 114 115 virtual status_t Perform(perform_code d, void* arg); 116 117 protected: 118 virtual bool ItemAdded(BLayoutItem* item, int32 atIndex); 119 virtual void ItemRemoved(BLayoutItem* item, int32 fromIndex); 120 121 virtual void LayoutInvalidated(bool children); 122 virtual void DoLayout(); 123 124 public: 125 struct BadLayoutPolicy { 126 virtual ~BadLayoutPolicy(); 127 /* return false to abandon layout, true to use layout */ 128 virtual bool OnBadLayout(BALMLayout* layout) = 0; 129 }; 130 131 struct DefaultPolicy : public BadLayoutPolicy { 132 virtual ~DefaultPolicy(); 133 virtual bool OnBadLayout(BALMLayout* layout); 134 }; 135 136 private: 137 138 // FBC padding 139 virtual void _ReservedALMLayout1(); 140 virtual void _ReservedALMLayout2(); 141 virtual void _ReservedALMLayout3(); 142 virtual void _ReservedALMLayout4(); 143 virtual void _ReservedALMLayout5(); 144 virtual void _ReservedALMLayout6(); 145 virtual void _ReservedALMLayout7(); 146 virtual void _ReservedALMLayout8(); 147 virtual void _ReservedALMLayout9(); 148 virtual void _ReservedALMLayout10(); 149 150 // forbidden methods 151 BALMLayout(const BALMLayout&); 152 void operator =(const BALMLayout&); 153 154 155 friend class XTab; 156 friend class YTab; 157 friend class Area; 158 159 float InsetForTab(XTab* tab) const; 160 float InsetForTab(YTab* tab) const; 161 162 BLayoutItem* _LayoutItemToAdd(BView* view); 163 164 void _UpdateAreaConstraints(); 165 166 BSize _CalculateMinSize(); 167 BSize _CalculateMaxSize(); 168 BSize _CalculatePreferredSize(); 169 170 bool _TrySolve(); 171 172 LinearProgramming::LinearSpec* fSolver; 173 174 BReference<XTab> fLeft; 175 BReference<XTab> fRight; 176 BReference<YTab> fTop; 177 BReference<YTab> fBottom; 178 BSize fMinSize; 179 BSize fMaxSize; 180 BSize fPreferredSize; 181 182 float fLeftInset; 183 float fRightInset; 184 float fTopInset; 185 float fBottomInset; 186 187 float fHSpacing; 188 float fVSpacing; 189 190 XTabList fXTabList; 191 YTabList fYTabList; 192 193 RowColumnManager* fRowColumnManager; 194 195 BadLayoutPolicy* fBadLayoutPolicy; 196 uint32 _reserved[5]; 197 }; 198 199 } // namespace BALM 200 201 202 using BALM::BALMLayout; 203 204 205 #endif // ALM_LAYOUT_H 206