1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Layout classes
4 // Author: Julian Smart
8 // Copyright: (c) 1998 Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "layout.h"
21 class WXDLLEXPORT wxWindow
;
23 // X stupidly defines these in X.h
31 #define wxLAYOUT_DEFAULT_MARGIN 0
33 enum wxEdge
{ wxLeft
, wxTop
, wxRight
, wxBottom
, wxWidth
, wxHeight
,
34 wxCentre
, wxCenter
= wxCentre
, wxCentreX
, wxCentreY
};
35 enum wxRelationship
{ wxUnconstrained
= 0,
45 class WXDLLEXPORT wxLayoutConstraints
;
46 class WXDLLEXPORT wxIndividualLayoutConstraint
: public wxObject
48 DECLARE_DYNAMIC_CLASS(wxIndividualLayoutConstraint
)
51 // To be allowed to modify the internal variables
52 friend class wxIndividualLayoutConstraint_Serialize
;
54 // 'This' window is the parent or sibling of otherWin
58 wxRelationship relationship
;
66 wxIndividualLayoutConstraint();
67 ~wxIndividualLayoutConstraint();
69 void Set(wxRelationship rel
, wxWindow
*otherW
, wxEdge otherE
, int val
= 0, int marg
= wxLAYOUT_DEFAULT_MARGIN
);
72 // Sibling relationships
74 void LeftOf(wxWindow
*sibling
, int marg
= wxLAYOUT_DEFAULT_MARGIN
);
75 void RightOf(wxWindow
*sibling
, int marg
= wxLAYOUT_DEFAULT_MARGIN
);
76 void Above(wxWindow
*sibling
, int marg
= wxLAYOUT_DEFAULT_MARGIN
);
77 void Below(wxWindow
*sibling
, int marg
= wxLAYOUT_DEFAULT_MARGIN
);
80 // 'Same edge' alignment
82 void SameAs(wxWindow
*otherW
, wxEdge edge
, int marg
= wxLAYOUT_DEFAULT_MARGIN
);
84 // The edge is a percentage of the other window's edge
85 void PercentOf(wxWindow
*otherW
, wxEdge wh
, int per
);
88 // Edge has absolute value
90 void Absolute(int val
);
93 // Dimension is unconstrained
95 inline void Unconstrained() { relationship
= wxUnconstrained
; }
98 // Dimension is 'as is' (use current size settings)
100 inline void AsIs() { relationship
= wxAsIs
; }
105 inline wxWindow
*GetOtherWindow() { return otherWin
; }
106 inline wxEdge
GetMyEdge() const { return myEdge
; }
107 inline void SetEdge(wxEdge which
) { myEdge
= which
; }
108 inline void SetValue(int v
) { value
= v
; }
109 inline int GetMargin() { return margin
; }
110 inline void SetMargin(int m
) { margin
= m
; }
111 inline int GetValue() const { return value
; }
112 inline int GetPercent() const { return percent
; }
113 inline int GetOtherEdge() const { return otherEdge
; }
114 inline bool GetDone() const { return done
; }
115 inline void SetDone(bool d
) { done
= d
; }
116 inline wxRelationship
GetRelationship() { return relationship
; }
117 inline void SetRelationship(wxRelationship r
) { relationship
= r
; }
119 // Reset constraint if it mentions otherWin
120 bool ResetIfWin(wxWindow
*otherW
);
122 // Try to satisfy constraint
123 bool SatisfyConstraint(wxLayoutConstraints
*constraints
, wxWindow
*win
);
125 // Get the value of this edge or dimension, or if this
126 // is not determinable, -1.
127 int GetEdge(wxEdge which
, wxWindow
*thisWin
, wxWindow
*other
) const;
130 class WXDLLEXPORT wxLayoutConstraints
: public wxObject
132 DECLARE_DYNAMIC_CLASS(wxLayoutConstraints
)
136 wxIndividualLayoutConstraint left
;
137 wxIndividualLayoutConstraint top
;
138 wxIndividualLayoutConstraint right
;
139 wxIndividualLayoutConstraint bottom
;
141 wxIndividualLayoutConstraint width
;
142 wxIndividualLayoutConstraint height
;
143 // Centre constraints
144 wxIndividualLayoutConstraint centreX
;
145 wxIndividualLayoutConstraint centreY
;
147 wxLayoutConstraints();
148 ~wxLayoutConstraints();
150 bool SatisfyConstraints(wxWindow
*win
, int *noChanges
);
151 bool AreSatisfied() const
153 return left
.GetDone() && top
.GetDone() && right
.GetDone() &&
154 bottom
.GetDone() && centreX
.GetDone() && centreY
.GetDone();
158 bool WXDLLEXPORT
wxOldDoLayout(wxWindow
*win
);
164 Each sizer has a Layout function.
166 wxExpandSizer::Layout ; E.g. for resizeable windows
168 - parent size must be known (i.e. called
169 from OnSize or explicitly)
170 - call Layout on each child to give it a chance to resize
171 (e.g. child shrinks around its own children):
172 stop when all children return TRUE, or no change
173 - evaluate constraints on self to set size
175 wxShrinkSizer::Layout ; E.g. fit-to-contents windows
176 ; Perhaps 2 rowcols, one above other.
178 - call Layout on each child to give it a chance to resize
179 (e.g. child shrinks around its own children):
180 stop when each returns TRUE, or no change
181 - fit around children
182 (what if some want to be centred? E.g. OK/Cancel rowcol.
183 - done by centring e.g. bottom sizer w.r.t. top sizer.
184 (sibling relationship only))
185 - evaluate own constraints (e.g. may be below another window)
186 - IF parent is a real window (remember: a real window can
187 have only one child sizer, although a sizer can have several child
188 (real) windows), then resize this parent WITHOUT invoking Layout
190 Frame and dialog box OnSizes can check if the sizer is a shrink
191 sizer; if not, can call layout. Maybe have virtual bool AutoSizeLayout()
194 How to relayout if a child sizer/window changes? Need to go all the way
195 to the top of the hierarchy and call Layout() again.
197 wxRowColSizer::Layout
199 - Similar to wxShrinkSizer only instead of shrinking to fit
200 contents, more sophisticated layout of contents, and THEN
201 shrinking (possibly).
202 - Do the same parent window check/setsize as for wxShrinkSizer.
212 #define wxTYPE_SIZER 90
214 class WXDLLEXPORT wxSizer
: public wxWindow
216 DECLARE_DYNAMIC_CLASS(wxSizer
)
220 wxSizerBehaviour sizerBehaviour
;
229 wxSizer(wxWindow
*parent
, wxSizerBehaviour behav
= wxSizerNone
);
232 bool Create(wxWindow
*parent
, wxSizerBehaviour behav
= wxSizerNone
);
233 virtual void SetSize(int x
, int y
, int w
, int h
, int flags
= wxSIZE_AUTO
);
234 // Avoid compiler warning
235 void SetSize(int w
, int h
) { wxWindow::SetSize(w
, h
); }
236 virtual void Move(int x
, int y
);
237 virtual void GetSize(int *w
, int *h
) const;
238 inline virtual void GetClientSize(int *w
, int *h
) const { GetSize(w
, h
); }
239 virtual void GetPosition(int *x
, int *y
) const;
241 inline void SizerSetSize(int x
, int y
, int w
, int h
)
242 { SetSize(x
, y
, w
, h
); }
243 inline void SizerMove(int x
, int y
)
246 virtual void SetBorder(int w
, int h
);
247 inline int GetBorderX() { return borderX
; }
248 inline int GetBorderY() { return borderY
; }
250 virtual void AddSizerChild(wxWindow
*child
);
251 virtual void RemoveSizerChild(wxWindow
*child
);
253 inline virtual void SetBehaviour(wxSizerBehaviour b
) { sizerBehaviour
= b
; }
254 inline virtual wxSizerBehaviour
GetBehaviour() { return sizerBehaviour
; }
256 virtual bool LayoutPhase1(int *);
257 virtual bool LayoutPhase2(int *);
260 #define wxSIZER_ROWS TRUE
261 #define wxSIZER_COLS FALSE
263 class WXDLLEXPORT wxRowColSizer
: public wxSizer
265 DECLARE_DYNAMIC_CLASS(wxRowColSizer
)
274 // rowOrCol = TRUE to be laid out in rows, otherwise in columns.
276 wxRowColSizer(wxWindow
*parent
, bool rowOrCol
= wxSIZER_ROWS
, int rowsOrColSize
= 20, wxSizerBehaviour
= wxSizerShrink
);
279 bool Create(wxWindow
*parent
, bool rowOrCol
= wxSIZER_ROWS
, int rowsOrColSize
= 20, wxSizerBehaviour
= wxSizerShrink
);
280 void SetSize(int x
, int y
, int w
, int h
, int flags
= wxSIZE_AUTO
);
281 // Avoid compiler warning
282 void SetSize(int w
, int h
) { wxSizer::SetSize(w
, h
); }
284 inline virtual void SetRowOrCol(bool rc
) { rowOrCol
= rc
; }
285 inline virtual bool GetRowOrCol() { return rowOrCol
; }
286 inline virtual void SetRowOrColSize(int n
) { rowOrColSize
= n
; }
287 inline virtual int GetRowOrColSize() { return rowOrColSize
; }
288 inline virtual void SetSpacing(int x
, int y
) { xSpacing
= x
; ySpacing
= y
; }
289 inline virtual void GetSpacing(int *x
, int *y
) { *x
= xSpacing
; *y
= ySpacing
; }
291 bool LayoutPhase1(int *);
292 bool LayoutPhase2(int *);
295 class WXDLLEXPORT wxSpacingSizer
: public wxSizer
297 DECLARE_DYNAMIC_CLASS(wxSpacingSizer
)
303 wxSpacingSizer(wxWindow
*parent
, wxRelationship rel
, wxWindow
*other
, int spacing
);
304 wxSpacingSizer(wxWindow
*parent
);
307 bool Create(wxWindow
*parent
, wxRelationship rel
, wxWindow
*other
, int sp
);
308 bool Create(wxWindow
*parent
);