1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Layout classes
4 // Author: Julian Smart
8 // Copyright: (c) 1998 Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
20 #pragma interface "layout.h"
25 // X stupidly defines these in X.h
33 // ----------------------------------------------------------------------------
34 // forward declrations
35 // ----------------------------------------------------------------------------
37 class WXDLLEXPORT wxWindowBase
;
38 class WXDLLEXPORT wxLayoutConstraints
;
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
44 #define wxLAYOUT_DEFAULT_MARGIN 0
48 wxLeft
, wxTop
, wxRight
, wxBottom
, wxWidth
, wxHeight
,
49 wxCentre
, wxCenter
= wxCentre
, wxCentreX
, wxCentreY
72 #define wxTYPE_SIZER 90
74 // =============================================================================
76 // =============================================================================
78 // ----------------------------------------------------------------------------
79 // wxIndividualLayoutConstraint: a constraint on window position
80 // ----------------------------------------------------------------------------
82 class WXDLLEXPORT wxIndividualLayoutConstraint
: public wxObject
84 DECLARE_DYNAMIC_CLASS(wxIndividualLayoutConstraint
)
87 // To be allowed to modify the internal variables
88 friend class wxIndividualLayoutConstraint_Serialize
;
90 // 'This' window is the parent or sibling of otherWin
91 wxWindowBase
*otherWin
;
94 wxRelationship relationship
;
102 wxIndividualLayoutConstraint();
103 ~wxIndividualLayoutConstraint();
105 void Set(wxRelationship rel
, wxWindowBase
*otherW
, wxEdge otherE
, int val
= 0, int marg
= wxLAYOUT_DEFAULT_MARGIN
);
108 // Sibling relationships
110 void LeftOf(wxWindowBase
*sibling
, int marg
= wxLAYOUT_DEFAULT_MARGIN
);
111 void RightOf(wxWindowBase
*sibling
, int marg
= wxLAYOUT_DEFAULT_MARGIN
);
112 void Above(wxWindowBase
*sibling
, int marg
= wxLAYOUT_DEFAULT_MARGIN
);
113 void Below(wxWindowBase
*sibling
, int marg
= wxLAYOUT_DEFAULT_MARGIN
);
116 // 'Same edge' alignment
118 void SameAs(wxWindowBase
*otherW
, wxEdge edge
, int marg
= wxLAYOUT_DEFAULT_MARGIN
);
120 // The edge is a percentage of the other window's edge
121 void PercentOf(wxWindowBase
*otherW
, wxEdge wh
, int per
);
124 // Edge has absolute value
126 void Absolute(int val
);
129 // Dimension is unconstrained
131 void Unconstrained() { relationship
= wxUnconstrained
; }
134 // Dimension is 'as is' (use current size settings)
136 void AsIs() { relationship
= wxAsIs
; }
141 wxWindowBase
*GetOtherWindow() { return otherWin
; }
142 wxEdge
GetMyEdge() const { return myEdge
; }
143 void SetEdge(wxEdge which
) { myEdge
= which
; }
144 void SetValue(int v
) { value
= v
; }
145 int GetMargin() { return margin
; }
146 void SetMargin(int m
) { margin
= m
; }
147 int GetValue() const { return value
; }
148 int GetPercent() const { return percent
; }
149 int GetOtherEdge() const { return otherEdge
; }
150 bool GetDone() const { return done
; }
151 void SetDone(bool d
) { done
= d
; }
152 wxRelationship
GetRelationship() { return relationship
; }
153 void SetRelationship(wxRelationship r
) { relationship
= r
; }
155 // Reset constraint if it mentions otherWin
156 bool ResetIfWin(wxWindowBase
*otherW
);
158 // Try to satisfy constraint
159 bool SatisfyConstraint(wxLayoutConstraints
*constraints
, wxWindowBase
*win
);
161 // Get the value of this edge or dimension, or if this
162 // is not determinable, -1.
163 int GetEdge(wxEdge which
, wxWindowBase
*thisWin
, wxWindowBase
*other
) const;
166 // ----------------------------------------------------------------------------
167 // wxLayoutConstraints: the complete set of constraints for a window
168 // ----------------------------------------------------------------------------
170 class WXDLLEXPORT wxLayoutConstraints
: public wxObject
172 DECLARE_DYNAMIC_CLASS(wxLayoutConstraints
)
176 wxIndividualLayoutConstraint left
;
177 wxIndividualLayoutConstraint top
;
178 wxIndividualLayoutConstraint right
;
179 wxIndividualLayoutConstraint bottom
;
181 wxIndividualLayoutConstraint width
;
182 wxIndividualLayoutConstraint height
;
183 // Centre constraints
184 wxIndividualLayoutConstraint centreX
;
185 wxIndividualLayoutConstraint centreY
;
187 wxLayoutConstraints();
188 ~wxLayoutConstraints();
190 bool SatisfyConstraints(wxWindowBase
*win
, int *noChanges
);
191 bool AreSatisfied() const
193 return left
.GetDone() && top
.GetDone() && right
.GetDone() &&
194 bottom
.GetDone() && centreX
.GetDone() && centreY
.GetDone();
198 // ----------------------------------------------------------------------------
200 // ----------------------------------------------------------------------------
206 Each sizer has a Layout function.
208 wxExpandSizer::Layout ; E.g. for resizeable windows
210 - parent size must be known (i.e. called
211 from OnSize or explicitly)
212 - call Layout on each child to give it a chance to resize
213 (e.g. child shrinks around its own children):
214 stop when all children return TRUE, or no change
215 - evaluate constraints on self to set size
217 wxShrinkSizer::Layout ; E.g. fit-to-contents windows
218 ; Perhaps 2 rowcols, one above other.
220 - call Layout on each child to give it a chance to resize
221 (e.g. child shrinks around its own children):
222 stop when each returns TRUE, or no change
223 - fit around children
224 (what if some want to be centred? E.g. OK/Cancel rowcol.
225 - done by centring e.g. bottom sizer w.r.t. top sizer.
226 (sibling relationship only))
227 - evaluate own constraints (e.g. may be below another window)
228 - IF parent is a real window (remember: a real window can
229 have only one child sizer, although a sizer can have several child
230 (real) windows), then resize this parent WITHOUT invoking Layout
232 Frame and dialog box OnSizes can check if the sizer is a shrink
233 sizer; if not, can call layout. Maybe have virtual bool AutoSizeLayout()
236 How to relayout if a child sizer/window changes? Need to go all the way
237 to the top of the hierarchy and call Layout() again.
239 wxRowColSizer::Layout
241 - Similar to wxShrinkSizer only instead of shrinking to fit
242 contents, more sophisticated layout of contents, and THEN
243 shrinking (possibly).
244 - Do the same parent window check/setsize as for wxShrinkSizer.
248 class WXDLLEXPORT wxSizer
: public wxWindow
250 DECLARE_DYNAMIC_CLASS(wxSizer
)
253 wxSizerBehaviour sizerBehaviour
;
263 wxSizer(wxWindowBase
*parent
, wxSizerBehaviour behav
= wxSizerNone
);
266 bool Create(wxWindowBase
*parent
, wxSizerBehaviour behav
= wxSizerNone
);
268 virtual void GetSize(int *w
, int *h
) const;
270 virtual void GetClientSize(int *w
, int *h
) const { GetSize(w
, h
); }
272 virtual void GetPosition(int *x
, int *y
) const;
274 void SizerSetSize(int x
, int y
, int w
, int h
) { SetSize(x
, y
, w
, h
); }
275 void SizerMove(int x
, int y
) { Move(x
, y
); }
277 virtual void SetBorder(int w
, int h
);
278 int GetBorderX() { return borderX
; }
279 int GetBorderY() { return borderY
; }
281 virtual void AddSizerChild(wxWindowBase
*child
);
282 virtual void RemoveSizerChild(wxWindowBase
*child
);
284 virtual void SetBehaviour(wxSizerBehaviour b
) { sizerBehaviour
= b
; }
285 virtual wxSizerBehaviour
GetBehaviour() { return sizerBehaviour
; }
287 virtual bool LayoutPhase1(int *);
288 virtual bool LayoutPhase2(int *);
291 virtual void DoSetSize(int x
, int y
,
292 int width
, int height
,
293 int sizeFlags
= wxSIZE_AUTO
);
296 #define wxSIZER_ROWS TRUE
297 #define wxSIZER_COLS FALSE
299 class WXDLLEXPORT wxRowColSizer
: public wxSizer
301 DECLARE_DYNAMIC_CLASS(wxRowColSizer
)
310 // rowOrCol = TRUE to be laid out in rows, otherwise in columns.
312 wxRowColSizer(wxWindowBase
*parent
, bool rowOrCol
= wxSIZER_ROWS
,
313 int rowsOrColSize
= 20, wxSizerBehaviour
= wxSizerShrink
);
316 bool Create(wxWindowBase
*parent
, bool rowOrCol
= wxSIZER_ROWS
,
317 int rowsOrColSize
= 20, wxSizerBehaviour
= wxSizerShrink
);
319 virtual void SetRowOrCol(bool rc
) { rowOrCol
= rc
; }
320 virtual bool GetRowOrCol() { return rowOrCol
; }
321 virtual void SetRowOrColSize(int n
) { rowOrColSize
= n
; }
322 virtual int GetRowOrColSize() { return rowOrColSize
; }
323 virtual void SetSpacing(int x
, int y
) { xSpacing
= x
; ySpacing
= y
; }
324 virtual void GetSpacing(int *x
, int *y
) { *x
= xSpacing
; *y
= ySpacing
; }
326 bool LayoutPhase1(int *);
327 bool LayoutPhase2(int *);
330 class WXDLLEXPORT wxSpacingSizer
: public wxSizer
332 DECLARE_DYNAMIC_CLASS(wxSpacingSizer
)
336 wxSpacingSizer(wxWindowBase
*parent
, wxRelationship rel
, wxWindowBase
*other
, int spacing
);
337 wxSpacingSizer(wxWindowBase
*parent
);
340 bool Create(wxWindowBase
*parent
, wxRelationship rel
, wxWindowBase
*other
, int sp
);
341 bool Create(wxWindowBase
*parent
);
344 // ----------------------------------------------------------------------------
346 // ----------------------------------------------------------------------------
348 #if WXWIN_COMPATIBILITY
349 extern bool WXDLLEXPORT
wxOldDoLayout(wxWindowBase
*win
);
350 #endif // WXWIN_COMPATIBILITY