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