xref: /haiku/headers/libs/alm/Area.h (revision fccd8899fcb583bfb73c5c26c9fcd714b963959b)
1 /*
2  * Copyright 2006 - 2010, Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef	AREA_H
6 #define	AREA_H
7 
8 
9 #include <vector>
10 
11 #include <Alignment.h>
12 #include <List.h>
13 #include <Size.h>
14 #include <SupportDefs.h>
15 #include <View.h>
16 
17 #include "Column.h"
18 #include "LinearSpec.h"
19 #include "Row.h"
20 #include "Tab.h"
21 
22 
23 class Constraint;
24 
25 
26 namespace BALM {
27 
28 
29 class GroupItem {
30 public:
31 								GroupItem(BLayoutItem* item);
32 								GroupItem(BView* view);
33 
34 			BLayoutItem*		LayoutItem();
35 			BView*				View();
36 
37 	const	std::vector<GroupItem>&	GroupItems();
38 			enum orientation	Orientation();
39 
40 			GroupItem& 			operator|(const GroupItem& right);
41 			GroupItem& 			operator/(const GroupItem& bottom);
42 private:
43 								GroupItem();
44 
45 			void				_Init(BLayoutItem* item, BView* view,
46 									  enum orientation orien = B_HORIZONTAL);
47 			GroupItem& 			_AddItem(const GroupItem& item,
48 									enum orientation orien);
49 
50 			BLayoutItem*		fLayoutItem;
51 			BView*				fView;
52 
53 			std::vector<GroupItem>	fGroupItems;
54 			enum orientation	fOrientation;
55 };
56 
57 
58 class RowColumnManager;
59 
60 
61 /**
62  * Rectangular area in the GUI, defined by a tab on each side.
63  */
64 class Area {
65 public:
66 								~Area();
67 
68 			BLayoutItem*		Item();
69 
70 			XTab*				Left() const;
71 			XTab*				Right() const;
72 			YTab*				Top() const;
73 			YTab*				Bottom() const;
74 			void				SetLeft(XTab* left);
75 			void				SetRight(XTab* right);
76 			void				SetTop(YTab* top);
77 			void				SetBottom(YTab* bottom);
78 
79 			Row*				GetRow() const;
80 			Column*				GetColumn() const;
81 
82 			double				ContentAspectRatio() const;
83 			void				SetContentAspectRatio(double ratio);
84 
85 			BSize				ShrinkPenalties() const;
86 			BSize				GrowPenalties() const;
87 			void				SetShrinkPenalties(BSize shrink);
88 			void				SetGrowPenalties(BSize grow);
89 
90 			float				LeftInset() const;
91 			float				TopInset() const;
92 			float				RightInset() const;
93 			float				BottomInset() const;
94 			void				SetLeftInset(float left);
95 			void				SetTopInset(float top);
96 			void				SetRightInset(float right);
97 			void				SetBottomInset(float bottom);
98 
99 			BString				ToString() const;
100 
101 			Constraint*			SetWidthAs(Area* area, float factor = 1.0f);
102 			Constraint*			SetHeightAs(Area* area, float factor = 1.0f);
103 
104 			void				InvalidateSizeConstraints();
105 
106 			BRect				Frame() const;
107 			BRect				ItemFrame() const;
108 
109 private:
110 								Area(BLayoutItem* item);
111 
112 			void				_Init(LinearSpec* ls, XTab* left, YTab* top,
113 									XTab* right, YTab* bottom,
114 									RowColumnManager* manager);
115 			void				_Init(LinearSpec* ls, Row* row, Column* column,
116 									RowColumnManager* manager);
117 
118 			void				_DoLayout();
119 
120 			void				_UpdateMinSizeConstraint(BSize min);
121 			void				_UpdateMaxSizeConstraint(BSize max);
122 private:
123 			BLayoutItem*		fLayoutItem;
124 
125 			LinearSpec*			fLS;
126 
127 			BReference<XTab>	fLeft;
128 			BReference<XTab>	fRight;
129 			BReference<YTab>	fTop;
130 			BReference<YTab>	fBottom;
131 
132 			Row*				fRow;
133 			Column*				fColumn;
134 
135 			BSize				fShrinkPenalties;
136 			BSize				fGrowPenalties;
137 
138 			BSize				fTopLeftInset;
139 			BSize				fRightBottomInset;
140 
141 			BObjectList<Constraint>	fConstraints;
142 			Constraint*			fMinContentWidth;
143 			Constraint*			fMaxContentWidth;
144 			Constraint*			fMinContentHeight;
145 			Constraint*			fMaxContentHeight;
146 			double				fContentAspectRatio;
147 			Constraint*			fContentAspectRatioC;
148 
149 			RowColumnManager*	fRowColumnManager;
150 public:
151 	friend class BALMLayout;
152 	friend class RowColumnManager;
153 
154 };
155 
156 }	// namespace BALM
157 
158 using BALM::Area;
159 using BALM::GroupItem;
160 
161 #endif	// AREA_H
162 
163