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 * A GUI layout engine using the Auckland Layout Model (ALM). 27 */ 28 class BALMLayout : public BAbstractLayout { 29 public: 30 BALMLayout(float spacing = 0.0f, 31 BALMLayout* friendLayout = NULL); 32 virtual ~BALMLayout(); 33 34 XTab* AddXTab(); 35 YTab* AddYTab(); 36 Row* AddRow(); 37 Row* AddRow(YTab* top, YTab* bottom); 38 Column* AddColumn(); 39 Column* AddColumn(XTab* left, XTab* right); 40 41 XTab* Left() const; 42 XTab* Right() const; 43 YTab* Top() const; 44 YTab* Bottom() const; 45 46 char* PerformancePath() const; 47 void SetPerformancePath(char* path); 48 49 LinearSpec* Solver() const; 50 51 void SetInset(float inset); 52 float Inset() const; 53 54 void SetSpacing(float spacing); 55 float Spacing() const; 56 57 Area* AreaFor(const BView* view) const; 58 Area* AreaFor(const BLayoutItem* item) const; 59 Area* CurrentArea() const; 60 void SetCurrentArea(const Area* area); 61 void SetCurrentArea(const BView* view); 62 void SetCurrentArea(const BLayoutItem* item); 63 64 XTab* LeftOf(const BView* view) const; 65 XTab* LeftOf(const BLayoutItem* item) const; 66 XTab* RightOf(const BView* view) const; 67 XTab* RightOf(const BLayoutItem* item) const; 68 YTab* TopOf(const BView* view) const; 69 YTab* TopOf(const BLayoutItem* item) const; 70 YTab* BottomOf(const BView* view) const; 71 YTab* BottomOf(const BLayoutItem* item) const; 72 73 void BuildLayout(GroupItem& item, XTab* left = NULL, 74 YTab* top = NULL, XTab* right = NULL, 75 YTab* bottom = NULL); 76 77 virtual BLayoutItem* AddView(BView* child); 78 virtual BLayoutItem* AddView(int32 index, BView* child); 79 virtual Area* AddView(BView* view, XTab* left, YTab* top, 80 XTab* right = NULL, YTab* bottom = NULL); 81 virtual Area* AddView(BView* view, Row* row, Column* column); 82 virtual Area* AddViewToRight(BView* view, XTab* right = NULL, 83 YTab* top = NULL, YTab* bottom = NULL); 84 virtual Area* AddViewToLeft(BView* view, XTab* left = NULL, 85 YTab* top = NULL, YTab* bottom = NULL); 86 virtual Area* AddViewToTop(BView* view, YTab* top = NULL, 87 XTab* left = NULL, XTab* right = NULL); 88 virtual Area* AddViewToBottom(BView* view, 89 YTab* bottom = NULL, XTab* left = NULL, 90 XTab* right = NULL); 91 92 virtual bool AddItem(BLayoutItem* item); 93 virtual bool AddItem(int32 index, BLayoutItem* item); 94 virtual Area* AddItem(BLayoutItem* item, XTab* left, 95 YTab* top, XTab* right = NULL, 96 YTab* bottom = NULL); 97 virtual Area* AddItem(BLayoutItem* item, Row* row, 98 Column* column); 99 virtual Area* AddItemToRight(BLayoutItem* item, 100 XTab* right = NULL, YTab* top = NULL, 101 YTab* bottom = NULL); 102 virtual Area* AddItemToLeft(BLayoutItem* item, 103 XTab* left = NULL, YTab* top = NULL, 104 YTab* bottom = NULL); 105 virtual Area* AddItemToTop(BLayoutItem* item, 106 YTab* top = NULL, XTab* left = NULL, 107 XTab* right = NULL); 108 virtual Area* AddItemToBottom(BLayoutItem* item, 109 YTab* bottom = NULL, XTab* left = NULL, 110 XTab* right = NULL); 111 112 virtual BSize BaseMinSize(); 113 virtual BSize BaseMaxSize(); 114 virtual BSize BasePreferredSize(); 115 virtual BAlignment BaseAlignment(); 116 117 virtual void InvalidateLayout(bool children = false); 118 119 virtual bool ItemAdded(BLayoutItem* item, int32 atIndex); 120 virtual void ItemRemoved(BLayoutItem* item, int32 fromIndex); 121 virtual void DerivedLayoutItems(); 122 123 private: 124 /*! Add a view without initialize the Area. */ 125 BLayoutItem* _CreateLayoutItem(BView* view); 126 127 void _SolveLayout(); 128 129 void _UpdateAreaConstraints(); 130 131 BSize _CalculateMinSize(); 132 BSize _CalculateMaxSize(); 133 BSize _CalculatePreferredSize(); 134 135 void _ParseGroupItem(GroupItem& item, XTab* left, 136 YTab* top, XTab* right, YTab* bottom); 137 138 LinearSpec* fSolver; 139 LinearSpec fOwnSolver; 140 141 XTab* fLeft; 142 XTab* fRight; 143 YTab* fTop; 144 YTab* fBottom; 145 BSize fMinSize; 146 BSize fMaxSize; 147 BSize fPreferredSize; 148 char* fPerformancePath; 149 150 float fInset; 151 float fSpacing; 152 153 Area* fCurrentArea; 154 }; 155 156 } // namespace BALM 157 158 using BALM::BALMLayout; 159 160 #endif // ALM_LAYOUT_H 161