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