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 <File.h> 11 #include <List.h> 12 #include <Size.h> 13 #include <SupportDefs.h> 14 #include <View.h> 15 16 #include "Area.h" 17 #include "Column.h" 18 #include "LinearSpec.h" 19 #include "Row.h" 20 #include "Tab.h" 21 22 23 namespace BALM { 24 25 26 class RowColumnManager; 27 28 29 /*! 30 * A GUI layout engine using the Auckland Layout Model (ALM). 31 */ 32 class BALMLayout : public BAbstractLayout { 33 public: 34 BALMLayout(float spacing = 0.0f, 35 BALMLayout* friendLayout = NULL); 36 virtual ~BALMLayout(); 37 38 BReference<XTab> AddXTab(); 39 BReference<YTab> AddYTab(); 40 41 int32 CountXTabs() const; 42 int32 CountYTabs() const; 43 XTab* XTabAt(int32 index) const; 44 YTab* YTabAt(int32 index) const; 45 /*! Order the tab list and return a reference to the list. */ 46 const XTabList& OrderedXTabs(); 47 const YTabList& OrderedYTabs(); 48 49 Row* AddRow(YTab* top, YTab* bottom); 50 Column* AddColumn(XTab* left, XTab* right); 51 52 XTab* Left() const; 53 XTab* Right() const; 54 YTab* Top() const; 55 YTab* Bottom() const; 56 57 char* PerformancePath() const; 58 void SetPerformancePath(char* path); 59 60 LinearSpec* Solver() const; 61 62 void SetInset(float inset); 63 float Inset() const; 64 65 void SetSpacing(float spacing); 66 float Spacing() const; 67 68 Area* AreaFor(const BView* view) const; 69 Area* AreaFor(const BLayoutItem* item) const; 70 Area* AreaAt(int32 index) const; 71 Area* CurrentArea() const; 72 bool SetCurrentArea(const Area* area); 73 bool SetCurrentArea(const BView* view); 74 bool SetCurrentArea(const BLayoutItem* item); 75 76 XTab* LeftOf(const BView* view) const; 77 XTab* LeftOf(const BLayoutItem* item) const; 78 XTab* RightOf(const BView* view) const; 79 XTab* RightOf(const BLayoutItem* item) const; 80 YTab* TopOf(const BView* view) const; 81 YTab* TopOf(const BLayoutItem* item) const; 82 YTab* BottomOf(const BView* view) const; 83 YTab* BottomOf(const BLayoutItem* item) const; 84 85 void BuildLayout(GroupItem& item, XTab* left = NULL, 86 YTab* top = NULL, XTab* right = NULL, 87 YTab* bottom = NULL); 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 virtual Area* AddViewToRight(BView* view, XTab* right = NULL, 95 YTab* top = NULL, YTab* bottom = NULL); 96 virtual Area* AddViewToLeft(BView* view, XTab* left = NULL, 97 YTab* top = NULL, YTab* bottom = NULL); 98 virtual Area* AddViewToTop(BView* view, YTab* top = NULL, 99 XTab* left = NULL, XTab* right = NULL); 100 virtual Area* AddViewToBottom(BView* view, 101 YTab* bottom = NULL, XTab* left = NULL, 102 XTab* right = NULL); 103 104 virtual bool AddItem(BLayoutItem* item); 105 virtual bool AddItem(int32 index, BLayoutItem* item); 106 virtual Area* AddItem(BLayoutItem* item, XTab* left, 107 YTab* top, XTab* right = NULL, 108 YTab* bottom = NULL); 109 virtual Area* AddItem(BLayoutItem* item, Row* row, 110 Column* column); 111 112 virtual Area* AddItemToRight(BLayoutItem* item, 113 XTab* right = NULL, YTab* top = NULL, 114 YTab* bottom = NULL); 115 virtual Area* AddItemToLeft(BLayoutItem* item, 116 XTab* left = NULL, YTab* top = NULL, 117 YTab* bottom = NULL); 118 virtual Area* AddItemToTop(BLayoutItem* item, 119 YTab* top = NULL, XTab* left = NULL, 120 XTab* right = NULL); 121 virtual Area* AddItemToBottom(BLayoutItem* item, 122 YTab* bottom = NULL, XTab* left = NULL, 123 XTab* right = NULL); 124 125 virtual BSize BaseMinSize(); 126 virtual BSize BaseMaxSize(); 127 virtual BSize BasePreferredSize(); 128 virtual BAlignment BaseAlignment(); 129 130 protected: 131 virtual bool ItemAdded(BLayoutItem* item, int32 atIndex); 132 virtual void ItemRemoved(BLayoutItem* item, int32 fromIndex); 133 134 virtual void LayoutInvalidated(bool children); 135 virtual void DoLayout(); 136 137 private: 138 friend class XTab; 139 friend class YTab; 140 141 /*! Add a view without initialize the Area. */ 142 BLayoutItem* _CreateLayoutItem(BView* view); 143 144 void _UpdateAreaConstraints(); 145 146 BSize _CalculateMinSize(); 147 BSize _CalculateMaxSize(); 148 BSize _CalculatePreferredSize(); 149 150 void _ParseGroupItem(GroupItem& item, 151 BReference<XTab> left, BReference<YTab> top, 152 BReference<XTab> right, 153 BReference<YTab> bottom); 154 155 LinearSpec* fSolver; 156 LinearSpec fOwnSolver; 157 158 BReference<XTab> fLeft; 159 BReference<XTab> fRight; 160 BReference<YTab> fTop; 161 BReference<YTab> fBottom; 162 BSize fMinSize; 163 BSize fMaxSize; 164 BSize fPreferredSize; 165 char* fPerformancePath; 166 167 float fInset; 168 float fSpacing; 169 170 Area* fCurrentArea; 171 172 XTabList fXTabList; 173 YTabList fYTabList; 174 175 RowColumnManager* fRowColumnManager; 176 }; 177 178 } // namespace BALM 179 180 using BALM::BALMLayout; 181 182 #endif // ALM_LAYOUT_H 183