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 DoGetSize(int *w
, int *h
) const;
269 virtual void DoGetClientSize(int *w
, int *h
) const { GetSize(w
, h
); }
270 virtual void DoGetPosition(int *x
, int *y
) const;
272 void SizerSetSize(int x
, int y
, int w
, int h
) { SetSize(x
, y
, w
, h
); }
273 void SizerMove(int x
, int y
) { Move(x
, y
); }
275 virtual void SetBorder(int w
, int h
);
276 int GetBorderX() { return borderX
; }
277 int GetBorderY() { return borderY
; }
279 virtual void AddSizerChild(wxWindowBase
*child
);
280 virtual void RemoveSizerChild(wxWindowBase
*child
);
282 virtual void SetBehaviour(wxSizerBehaviour b
) { sizerBehaviour
= b
; }
283 virtual wxSizerBehaviour
GetBehaviour() { return sizerBehaviour
; }
285 virtual bool LayoutPhase1(int *);
286 virtual bool LayoutPhase2(int *);
289 virtual void DoSetSize(int x
, int y
,
290 int width
, int height
,
291 int sizeFlags
= wxSIZE_AUTO
);
294 #define wxSIZER_ROWS TRUE
295 #define wxSIZER_COLS FALSE
297 class WXDLLEXPORT wxRowColSizer
: public wxSizer
299 DECLARE_DYNAMIC_CLASS(wxRowColSizer
)
308 // rowOrCol = TRUE to be laid out in rows, otherwise in columns.
310 wxRowColSizer(wxWindowBase
*parent
, bool rowOrCol
= wxSIZER_ROWS
,
311 int rowsOrColSize
= 20, wxSizerBehaviour
= wxSizerShrink
);
314 bool Create(wxWindowBase
*parent
, bool rowOrCol
= wxSIZER_ROWS
,
315 int rowsOrColSize
= 20, wxSizerBehaviour
= wxSizerShrink
);
317 virtual void SetRowOrCol(bool rc
) { rowOrCol
= rc
; }
318 virtual bool GetRowOrCol() { return rowOrCol
; }
319 virtual void SetRowOrColSize(int n
) { rowOrColSize
= n
; }
320 virtual int GetRowOrColSize() { return rowOrColSize
; }
321 virtual void SetSpacing(int x
, int y
) { xSpacing
= x
; ySpacing
= y
; }
322 virtual void GetSpacing(int *x
, int *y
) { *x
= xSpacing
; *y
= ySpacing
; }
324 bool LayoutPhase1(int *);
325 bool LayoutPhase2(int *);
328 class WXDLLEXPORT wxSpacingSizer
: public wxSizer
330 DECLARE_DYNAMIC_CLASS(wxSpacingSizer
)
334 wxSpacingSizer(wxWindowBase
*parent
, wxRelationship rel
, wxWindowBase
*other
, int spacing
);
335 wxSpacingSizer(wxWindowBase
*parent
);
338 bool Create(wxWindowBase
*parent
, wxRelationship rel
, wxWindowBase
*other
, int sp
);
339 bool Create(wxWindowBase
*parent
);
342 // ----------------------------------------------------------------------------
344 // ----------------------------------------------------------------------------
346 #if WXWIN_COMPATIBILITY
347 extern bool WXDLLEXPORT
wxOldDoLayout(wxWindowBase
*win
);
348 #endif // WXWIN_COMPATIBILITY