2 * Copyright 2010-2014 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * John Scipione, jscipione@gmail.com
7 * Clemens Zeidler, haiku@clemens-zeidler.de
15 #include "ObjectList.h"
16 #include "Referenceable.h"
18 #include "MagneticBorder.h"
20 #include "LinearSpec.h"
27 typedef BObjectList
<SATWindow
> SATWindowList
;
51 WindowArea
* windowArea
;
55 class Crossing
: public BReferenceable
{
57 Crossing(Tab
* vertical
, Tab
* horizontal
);
60 Corner
* GetCorner(Corner::position_t corner
) const;
61 Corner
* GetOppositeCorner(
62 Corner::position_t corner
) const;
64 Corner
* LeftTopCorner()
65 { return &fCorners
[Corner::kLeftTop
]; }
66 Corner
* RightTopCorner()
67 { return &fCorners
[Corner::kRightTop
]; }
68 Corner
* LeftBottomCorner()
69 { return &fCorners
[Corner::kLeftBottom
]; }
70 Corner
* RightBottomCorner()
71 { return &fCorners
[Corner::kRightBottom
]; }
73 Tab
* VerticalTab() const;
74 Tab
* HorizontalTab() const;
80 BReference
<Tab
> fVerticalTab
;
81 BReference
<Tab
> fHorizontalTab
;
85 typedef BObjectList
<Constraint
> ConstraintList
;
88 typedef BObjectList
<Crossing
> CrossingList
;
91 // make all coordinates positive needed for the solver
92 const float kMakePositiveOffset
= 5000;
95 class Tab
: public BReferenceable
{
103 Tab(SATGroup
* group
, Variable
* variable
,
104 orientation_t orientation
);
107 float Position() const;
108 void SetPosition(float position
);
109 orientation_t
Orientation() const;
110 Variable
* Var() { return fVariable
; }
112 //! Caller takes ownership of the constraint.
113 Constraint
* Connect(Variable
* variable
);
115 BReference
<Crossing
> AddCrossing(Tab
* tab
);
116 bool RemoveCrossing(Crossing
* crossing
);
117 int32
FindCrossingIndex(Tab
* tab
);
118 int32
FindCrossingIndex(float tabPosition
);
119 Crossing
* FindCrossing(Tab
* tab
);
120 Crossing
* FindCrossing(float tabPosition
);
122 const CrossingList
* GetCrossingList() const;
124 static int CompareFunction(const Tab
* tab1
,
130 orientation_t fOrientation
;
132 CrossingList fCrossingList
;
136 class WindowArea
: public BReferenceable
{
138 WindowArea(Crossing
* leftTop
,
139 Crossing
* rightTop
, Crossing
* leftBottom
,
140 Crossing
* rightBottom
);
143 bool Init(SATGroup
* group
);
144 SATGroup
* Group() { return fGroup
; }
146 void DoGroupLayout();
147 void UpdateSizeLimits();
148 void UpdateSizeConstaints(const BRect
& frame
);
150 const SATWindowList
& WindowList() { return fWindowList
; }
151 const SATWindowList
& LayerOrder() { return fWindowLayerOrder
; }
152 bool MoveWindowToPosition(SATWindow
* window
,
154 SATWindow
* TopWindow();
156 Crossing
* LeftTopCrossing()
157 { return fLeftTopCrossing
.Get(); }
158 Crossing
* RightTopCrossing()
159 { return fRightTopCrossing
.Get(); }
160 Crossing
* LeftBottomCrossing()
161 { return fLeftBottomCrossing
.Get(); }
162 Crossing
* RightBottomCrossing()
163 { return fRightBottomCrossing
.Get(); }
170 Variable
* LeftVar() { return LeftTab()->Var(); }
171 Variable
* RightVar() { return RightTab()->Var(); }
172 Variable
* TopVar() { return TopTab()->Var(); }
173 Variable
* BottomVar() { return BottomTab()->Var(); }
177 bool PropagateToGroup(SATGroup
* group
);
179 bool MoveToTopLayer(SATWindow
* window
);
182 friend class SATGroup
;
183 void _UninitConstraints();
184 void _UpdateConstraintValues();
186 /*! SATGroup adds new windows to the area. */
187 bool _AddWindow(SATWindow
* window
,
188 SATWindow
* after
= NULL
);
189 /*! After the last window has been removed the WindowArea delete
190 himself and clean up all crossings. */
191 bool _RemoveWindow(SATWindow
* window
);
193 inline void _InitCorners();
194 inline void _CleanupCorners();
195 inline void _SetToWindowCorner(Corner
* corner
);
196 inline void _SetToNeighbourCorner(Corner
* neighbour
);
197 inline void _UnsetWindowCorner(Corner
* corner
);
198 //! opponent is the other neighbour of the neighbour
199 inline void _UnsetNeighbourCorner(Corner
* neighbour
,
202 // Find crossing by tab position in group and if not exist create
204 BReference
<Crossing
> _CrossingByPosition(Crossing
* crossing
,
207 void _MoveToSAT(SATWindow
* topWindow
);
209 BReference
<SATGroup
> fGroup
;
211 SATWindowList fWindowList
;
213 SATWindowList fWindowLayerOrder
;
215 BReference
<Crossing
> fLeftTopCrossing
;
216 BReference
<Crossing
> fRightTopCrossing
;
217 BReference
<Crossing
> fLeftBottomCrossing
;
218 BReference
<Crossing
> fRightBottomCrossing
;
220 Constraint
* fMinWidthConstraint
;
221 Constraint
* fMinHeightConstraint
;
222 Constraint
* fMaxWidthConstraint
;
223 Constraint
* fMaxHeightConstraint
;
224 Constraint
* fWidthConstraint
;
225 Constraint
* fHeightConstraint
;
227 MagneticBorder fMagneticBorder
;
231 typedef BObjectList
<WindowArea
> WindowAreaList
;
232 typedef BObjectList
<Tab
> TabList
;
238 class SATGroup
: public BReferenceable
{
241 friend class WindowArea
;
242 friend class GroupCookie
;
247 LinearSpec
* GetLinearSpec() { return fLinearSpec
; }
249 /*! Create a new WindowArea from the crossing and add the window. */
250 bool AddWindow(SATWindow
* window
, Tab
* left
,
251 Tab
* top
, Tab
* right
, Tab
* bottom
);
252 /*! Add a window to an existing window area. */
253 bool AddWindow(SATWindow
* window
, WindowArea
* area
,
254 SATWindow
* after
= NULL
);
255 /*! If stayBelowMouse is true move the removed window below the
256 cursor if necessary. */
257 bool RemoveWindow(SATWindow
* window
,
258 bool stayBelowMouse
= true);
260 SATWindow
* WindowAt(int32 index
);
262 SATWindow
* ActiveWindow() const;
263 void SetActiveWindow(SATWindow
* window
);
265 const WindowAreaList
& GetAreaList() { return fWindowAreaList
; }
267 /*! \return a sorted tab list. */
268 const TabList
* HorizontalTabs();
269 const TabList
* VerticalTabs();
271 Tab
* FindHorizontalTab(float position
);
272 Tab
* FindVerticalTab(float position
);
274 void WindowAreaRemoved(WindowArea
* area
);
276 static status_t
RestoreGroup(const BMessage
& archive
,
278 status_t
ArchiveGroup(BMessage
& archive
);
281 BReference
<Tab
> _AddHorizontalTab(float position
= 0);
282 BReference
<Tab
> _AddVerticalTab(float position
= 0);
284 bool _RemoveHorizontalTab(Tab
* tab
);
285 bool _RemoveVerticalTab(Tab
* tab
);
287 Tab
* _FindTab(const TabList
& list
, float position
);
289 void _SplitGroupIfNecessary(
290 WindowArea
* removedArea
);
291 void _FillNeighbourList(
292 WindowAreaList
& neighbourWindows
,
294 void _LeftNeighbours(
295 WindowAreaList
& neighbourWindows
,
298 WindowAreaList
& neighbourWindows
,
300 void _RightNeighbours(
301 WindowAreaList
& neighbourWindows
,
303 void _BottomNeighbours(
304 WindowAreaList
& neighbourWindows
,
306 bool _FindConnectedGroup(WindowAreaList
& seedList
,
307 WindowArea
* removedArea
,
308 WindowAreaList
& newGroup
);
309 void _FollowSeed(WindowArea
* area
, WindowArea
* veto
,
310 WindowAreaList
& seedList
,
311 WindowAreaList
& newGroup
);
312 void _SpawnNewGroup(const WindowAreaList
& newGroup
);
314 void _EnsureGroupIsOnScreen(SATGroup
* group
);
315 inline void _CallculateXOffset(BPoint
& offset
, BRect
& frame
,
317 inline void _CallculateYOffset(BPoint
& offset
, BRect
& frame
,
321 WindowAreaList fWindowAreaList
;
322 SATWindowList fSATWindowList
;
324 LinearSpec
* fLinearSpec
;
327 TabList fHorizontalTabs
;
328 bool fHorizontalTabsSorted
;
329 TabList fVerticalTabs
;
330 bool fVerticalTabsSorted
;
332 SATWindow
* fActiveWindow
;
336 typedef BObjectList
<SATGroup
> SATGroupList
;