xref: /haiku/headers/libs/alm/Area.h (revision 25a7b01d15612846f332751841da3579db313082)
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 <Referenceable.h>
10 #include <Rect.h>
11 #include <Size.h>
12 #include <String.h>
13 
14 
15 class BLayoutItem;
16 class BView;
17 
18 
19 namespace LinearProgramming {
20 	class LinearSpec;
21 	class Constraint;
22 };
23 
24 namespace BPrivate {
25 	class SharedSolver;
26 };
27 
28 
29 namespace BALM {
30 
31 
32 class Column;
33 class Row;
34 class XTab;
35 class YTab;
36 
37 
38 
39 
40 class RowColumnManager;
41 
42 
43 /**
44  * Rectangular area in the GUI, defined by a tab on each side.
45  */
46 class Area {
47 public:
48 								~Area();
49 
50 			int32				ID() const;
51 			void				SetID(int32 id);
52 
53 			BLayoutItem*		Item();
54 
55 			XTab*				Left() const;
56 			XTab*				Right() const;
57 			YTab*				Top() const;
58 			YTab*				Bottom() const;
59 			void				SetLeft(BReference<XTab> left);
60 			void				SetRight(BReference<XTab> right);
61 			void				SetTop(BReference<YTab> top);
62 			void				SetBottom(BReference<YTab> bottom);
63 
64 			Row*				GetRow() const;
65 			Column*				GetColumn() const;
66 
67 			double				ContentAspectRatio() const;
68 			void				SetContentAspectRatio(double ratio);
69 
70 			BSize				ShrinkPenalties() const;
71 			BSize				GrowPenalties() const;
72 			void				SetShrinkPenalties(BSize shrink);
73 			void				SetGrowPenalties(BSize grow);
74 
75 			void				GetInsets(float* left, float* top, float* right,
76 									float* bottom) const;
77 			float				LeftInset() const;
78 			float				TopInset() const;
79 			float				RightInset() const;
80 			float				BottomInset() const;
81 
82 			void				SetInsets(float insets);
83 			void				SetInsets(float horizontal, float vertical);
84 			void				SetInsets(float left, float top, float right,
85 									float bottom);
86 			void				SetLeftInset(float left);
87 			void				SetTopInset(float top);
88 			void				SetRightInset(float right);
89 			void				SetBottomInset(float bottom);
90 
91 			BString				ToString() const;
92 
93 			LinearProgramming::Constraint*
94 								SetWidthAs(Area* area, float factor = 1.0f);
95 
96 			LinearProgramming::Constraint*
97 								SetHeightAs(Area* area, float factor = 1.0f);
98 
99 			void				InvalidateSizeConstraints();
100 
101 			BRect				Frame() const;
102 
103 private:
104 								Area(BLayoutItem* item);
105 
106 			void				_Init(LinearProgramming::LinearSpec* ls,
107 									XTab* left, YTab* top, XTab* right,
108 									YTab* bottom, RowColumnManager* manager);
109 			void				_Init(LinearProgramming::LinearSpec* ls,
110 									Row* row, Column* column,
111 									RowColumnManager* manager);
112 
113 			void				_DoLayout(const BPoint& offset);
114 
115 			void				_UpdateMinSizeConstraint(BSize min);
116 			void				_UpdateMaxSizeConstraint(BSize max);
117 private:
118 	friend class BALMLayout;
119 	friend class RowColumnManager;
120 	friend class BPrivate::SharedSolver;
121 
122 			BLayoutItem*		fLayoutItem;
123 			int32				fID;
124 
125 			LinearProgramming::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				fLeftTopInset;
139 			BSize				fRightBottomInset;
140 
141 			double				fContentAspectRatio;
142 			RowColumnManager*	fRowColumnManager;
143 
144 			LinearProgramming::Constraint* fMinContentWidth;
145 			LinearProgramming::Constraint* fMaxContentWidth;
146 			LinearProgramming::Constraint* fMinContentHeight;
147 			LinearProgramming::Constraint* fMaxContentHeight;
148 			LinearProgramming::Constraint* fContentAspectRatioC;
149 
150 			uint32				_reserved[2];
151 };
152 
153 }	// namespace BALM
154 
155 using BALM::Area;
156 
157 #endif	// AREA_H
158 
159