2 * Copyright 2006 - 2010, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
9 #include <AbstractLayout.h>
13 #include "LinearSpec.h"
21 namespace LinearProgramming
{
37 class RowColumnManager
;
41 * A GUI layout engine using the Auckland Layout Model (ALM).
43 class BALMLayout
: public BAbstractLayout
{
45 BALMLayout(float hSpacing
= 0.0f
,
46 float vSpacing
= 0.0f
,
47 BALMLayout
* friendLayout
= NULL
);
48 BALMLayout(BMessage
* archive
);
49 virtual ~BALMLayout();
51 BReference
<XTab
> AddXTab();
52 void AddXTabs(BReference
<XTab
>* tabs
, uint32 count
);
53 BReference
<YTab
> AddYTab();
54 void AddYTabs(BReference
<YTab
>* tabs
, uint32 count
);
56 int32
CountXTabs() const;
57 int32
CountYTabs() const;
58 XTab
* XTabAt(int32 index
, bool ordered
= false);
59 XTab
* XTabAt(int32 index
) const;
60 YTab
* YTabAt(int32 index
, bool ordered
= false);
61 YTab
* YTabAt(int32 index
) const;
62 const XTabList
GetXTabs() const;
63 const YTabList
GetYTabs() const;
65 int32
IndexOf(XTab
* tab
, bool ordered
= false);
66 int32
IndexOf(YTab
* tab
, bool ordered
= false);
68 int32
CountConstraints() const;
69 Constraint
* ConstraintAt(int32 index
) const;
70 bool AddConstraint(Constraint
* constraint
);
71 bool RemoveConstraint(Constraint
* constraint
,
72 bool deleteConstraint
= true);
74 Constraint
* AddConstraint(double coeff1
, Variable
* var1
,
75 OperatorType op
, double rightSide
,
76 double penaltyNeg
= -1,
77 double penaltyPos
= -1);
78 Constraint
* AddConstraint(double coeff1
, Variable
* var1
,
79 double coeff2
, Variable
* var2
,
80 OperatorType op
, double rightSide
,
81 double penaltyNeg
= -1,
82 double penaltyPos
= -1);
83 Constraint
* AddConstraint(double coeff1
, Variable
* var1
,
84 double coeff2
, Variable
* var2
,
85 double coeff3
, Variable
* var3
,
86 OperatorType op
, double rightSide
,
87 double penaltyNeg
= -1,
88 double penaltyPos
= -1);
89 Constraint
* AddConstraint(double coeff1
, Variable
* var1
,
90 double coeff2
, Variable
* var2
,
91 double coeff3
, Variable
* var3
,
92 double coeff4
, Variable
* var4
,
93 OperatorType op
, double rightSide
,
94 double penaltyNeg
= -1,
95 double penaltyPos
= -1);
97 Row
* AddRow(YTab
* top
, YTab
* bottom
);
98 Column
* AddColumn(XTab
* left
, XTab
* right
);
103 YTab
* Bottom() const;
105 LinearProgramming::LinearSpec
* Solver() const;
106 LinearProgramming::ResultType
ValidateLayout();
108 void SetInsets(float insets
);
109 void SetInsets(float x
, float y
);
110 void SetInsets(float left
, float top
, float right
,
112 void GetInsets(float* left
, float* top
, float* right
,
113 float* bottom
) const;
115 void SetSpacing(float hSpacing
, float vSpacing
);
116 void GetSpacing(float* _hSpacing
,
117 float* _vSpacing
) const;
119 Area
* AreaFor(int32 id
) const;
120 Area
* AreaFor(const BView
* view
) const;
121 Area
* AreaFor(const BLayoutItem
* item
) const;
122 int32
CountAreas() const;
123 Area
* AreaAt(int32 index
) const;
125 XTab
* LeftOf(const BView
* view
) const;
126 XTab
* LeftOf(const BLayoutItem
* item
) const;
127 XTab
* RightOf(const BView
* view
) const;
128 XTab
* RightOf(const BLayoutItem
* item
) const;
129 YTab
* TopOf(const BView
* view
) const;
130 YTab
* TopOf(const BLayoutItem
* item
) const;
131 YTab
* BottomOf(const BView
* view
) const;
132 YTab
* BottomOf(const BLayoutItem
* item
) const;
134 virtual BLayoutItem
* AddView(BView
* child
);
135 virtual BLayoutItem
* AddView(int32 index
, BView
* child
);
136 virtual Area
* AddView(BView
* view
, XTab
* left
, YTab
* top
,
137 XTab
* right
= NULL
, YTab
* bottom
= NULL
);
138 virtual Area
* AddView(BView
* view
, Row
* row
, Column
* column
);
140 virtual bool AddItem(BLayoutItem
* item
);
141 virtual bool AddItem(int32 index
, BLayoutItem
* item
);
142 virtual Area
* AddItem(BLayoutItem
* item
, XTab
* left
,
143 YTab
* top
, XTab
* right
= NULL
,
144 YTab
* bottom
= NULL
);
145 virtual Area
* AddItem(BLayoutItem
* item
, Row
* row
,
148 struct BadLayoutPolicy
;
150 void SetBadLayoutPolicy(BadLayoutPolicy
* policy
);
151 BadLayoutPolicy
* GetBadLayoutPolicy() const;
153 virtual BSize
BaseMinSize();
154 virtual BSize
BaseMaxSize();
155 virtual BSize
BasePreferredSize();
156 virtual BAlignment
BaseAlignment();
158 virtual status_t
Archive(BMessage
* into
, bool deep
= true) const;
159 static BArchivable
* Instantiate(BMessage
* archive
);
161 virtual status_t
Perform(perform_code d
, void* arg
);
164 virtual bool ItemAdded(BLayoutItem
* item
, int32 atIndex
);
165 virtual void ItemRemoved(BLayoutItem
* item
, int32 fromIndex
);
167 virtual status_t
ItemArchived(BMessage
* into
, BLayoutItem
* item
,
169 virtual status_t
ItemUnarchived(const BMessage
* from
,
170 BLayoutItem
* item
, int32 index
);
172 virtual status_t
AllUnarchived(const BMessage
* archive
);
173 virtual status_t
AllArchived(BMessage
* archive
) const;
175 virtual void LayoutInvalidated(bool children
);
176 virtual void DoLayout();
179 struct BadLayoutPolicy
: public BArchivable
{
181 BadLayoutPolicy(BMessage
* archive
);
182 virtual ~BadLayoutPolicy();
183 /* return false to abandon layout, true to use layout */
184 virtual bool OnBadLayout(BALMLayout
* layout
,
185 LinearProgramming::ResultType result
,
186 BLayoutContext
* context
) = 0;
189 struct DefaultPolicy
: public BadLayoutPolicy
{
191 DefaultPolicy(BMessage
* archive
);
192 virtual ~DefaultPolicy();
193 virtual bool OnBadLayout(BALMLayout
* layout
,
194 LinearProgramming::ResultType result
,
195 BLayoutContext
* context
);
196 virtual status_t
Archive(BMessage
* message
,
197 bool deep
= false) const;
198 static BArchivable
* Instantiate(BMessage
* message
);
204 virtual void _ReservedALMLayout1();
205 virtual void _ReservedALMLayout2();
206 virtual void _ReservedALMLayout3();
207 virtual void _ReservedALMLayout4();
208 virtual void _ReservedALMLayout5();
209 virtual void _ReservedALMLayout6();
210 virtual void _ReservedALMLayout7();
211 virtual void _ReservedALMLayout8();
212 virtual void _ReservedALMLayout9();
213 virtual void _ReservedALMLayout10();
216 BALMLayout(const BALMLayout
&);
217 void operator =(const BALMLayout
&);
221 struct TabAddTransaction
;
224 friend class TabAddTransaction
;
225 friend class BPrivate::SharedSolver
;
231 class BALMLayoutSpecListener
;
232 friend class BALMLayoutSpecListener
;
234 float InsetForTab(XTab
* tab
) const;
235 float InsetForTab(YTab
* tab
) const;
237 void UpdateConstraints(BLayoutContext
* context
);
239 void _RemoveSelfFromTab(XTab
* tab
);
240 void _RemoveSelfFromTab(YTab
* tab
);
241 bool _HasTabInLayout(XTab
* tab
);
242 bool _HasTabInLayout(YTab
* tab
);
243 bool _AddedTab(XTab
* tab
);
244 bool _AddedTab(YTab
* tab
);
246 BLayoutItem
* _LayoutItemToAdd(BView
* view
);
247 void _SetSolver(BPrivate::SharedSolver
* solver
);
249 BPrivate::SharedSolver
* fSolver
;
250 BALMLayoutSpecListener
* fSpecListener
;
252 BReference
<XTab
> fLeft
;
253 BReference
<XTab
> fRight
;
254 BReference
<YTab
> fTop
;
255 BReference
<YTab
> fBottom
;
258 BSize fPreferredSize
;
274 BObjectList
<Constraint
> fConstraints
;
276 RowColumnManager
* fRowColumnManager
;
278 BadLayoutPolicy
* fBadLayoutPolicy
;
286 using BALM::BALMLayout
;
289 #endif // ALM_LAYOUT_H