]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: layout.h | |
3 | // Purpose: Layout classes | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 29/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1998 Julian Smart | |
a532afbb | 9 | // Licence: wxWindows license |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
34138703 JS |
12 | #ifndef _WX_LAYOUTH__ |
13 | #define _WX_LAYOUTH__ | |
c801d85f | 14 | |
f03fc89f VZ |
15 | // ---------------------------------------------------------------------------- |
16 | // headers | |
17 | // ---------------------------------------------------------------------------- | |
18 | ||
c801d85f | 19 | #ifdef __GNUG__ |
f03fc89f | 20 | #pragma interface "layout.h" |
c801d85f KB |
21 | #endif |
22 | ||
23 | #include "wx/defs.h" | |
24 | ||
c801d85f KB |
25 | // X stupidly defines these in X.h |
26 | #ifdef Above | |
f03fc89f | 27 | #undef Above |
c801d85f KB |
28 | #endif |
29 | #ifdef Below | |
f03fc89f | 30 | #undef Below |
c801d85f KB |
31 | #endif |
32 | ||
f03fc89f VZ |
33 | // ---------------------------------------------------------------------------- |
34 | // forward declrations | |
35 | // ---------------------------------------------------------------------------- | |
36 | ||
37 | class WXDLLEXPORT wxWindowBase; | |
38 | class WXDLLEXPORT wxLayoutConstraints; | |
39 | ||
40 | // ---------------------------------------------------------------------------- | |
41 | // constants | |
42 | // ---------------------------------------------------------------------------- | |
43 | ||
c801d85f KB |
44 | #define wxLAYOUT_DEFAULT_MARGIN 0 |
45 | ||
f03fc89f VZ |
46 | enum wxEdge |
47 | { | |
48 | wxLeft, wxTop, wxRight, wxBottom, wxWidth, wxHeight, | |
49 | wxCentre, wxCenter = wxCentre, wxCentreX, wxCentreY | |
50 | }; | |
c801d85f | 51 | |
f03fc89f | 52 | enum wxRelationship |
c801d85f | 53 | { |
f03fc89f VZ |
54 | wxUnconstrained = 0, |
55 | wxAsIs, | |
56 | wxPercentOf, | |
57 | wxAbove, | |
58 | wxBelow, | |
59 | wxLeftOf, | |
60 | wxRightOf, | |
61 | wxSameAs, | |
62 | wxAbsolute | |
c801d85f KB |
63 | }; |
64 | ||
f03fc89f | 65 | enum wxSizerBehaviour |
c801d85f | 66 | { |
f03fc89f VZ |
67 | wxSizerShrink, |
68 | wxSizerExpand, | |
69 | wxSizerNone | |
c801d85f KB |
70 | }; |
71 | ||
f03fc89f VZ |
72 | #define wxTYPE_SIZER 90 |
73 | ||
74 | // ============================================================================= | |
75 | // classes | |
76 | // ============================================================================= | |
77 | ||
78 | // ---------------------------------------------------------------------------- | |
79 | // wxIndividualLayoutConstraint: a constraint on window position | |
80 | // ---------------------------------------------------------------------------- | |
81 | ||
82 | class WXDLLEXPORT wxIndividualLayoutConstraint : public wxObject | |
83 | { | |
84 | DECLARE_DYNAMIC_CLASS(wxIndividualLayoutConstraint) | |
85 | ||
86 | protected: | |
87 | // To be allowed to modify the internal variables | |
88 | friend class wxIndividualLayoutConstraint_Serialize; | |
89 | ||
90 | // 'This' window is the parent or sibling of otherWin | |
91 | wxWindowBase *otherWin; | |
92 | ||
93 | wxEdge myEdge; | |
94 | wxRelationship relationship; | |
95 | int margin; | |
96 | int value; | |
97 | int percent; | |
98 | wxEdge otherEdge; | |
99 | bool done; | |
100 | ||
101 | public: | |
102 | wxIndividualLayoutConstraint(); | |
103 | ~wxIndividualLayoutConstraint(); | |
104 | ||
105 | void Set(wxRelationship rel, wxWindowBase *otherW, wxEdge otherE, int val = 0, int marg = wxLAYOUT_DEFAULT_MARGIN); | |
106 | ||
107 | // | |
108 | // Sibling relationships | |
109 | // | |
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); | |
114 | ||
115 | // | |
116 | // 'Same edge' alignment | |
117 | // | |
118 | void SameAs(wxWindowBase *otherW, wxEdge edge, int marg = wxLAYOUT_DEFAULT_MARGIN); | |
119 | ||
120 | // The edge is a percentage of the other window's edge | |
121 | void PercentOf(wxWindowBase *otherW, wxEdge wh, int per); | |
122 | ||
123 | // | |
124 | // Edge has absolute value | |
125 | // | |
126 | void Absolute(int val); | |
127 | ||
128 | // | |
129 | // Dimension is unconstrained | |
130 | // | |
131 | void Unconstrained() { relationship = wxUnconstrained; } | |
132 | ||
133 | // | |
134 | // Dimension is 'as is' (use current size settings) | |
135 | // | |
136 | void AsIs() { relationship = wxAsIs; } | |
137 | ||
138 | // | |
139 | // Accessors | |
140 | // | |
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; } | |
154 | ||
155 | // Reset constraint if it mentions otherWin | |
156 | bool ResetIfWin(wxWindowBase *otherW); | |
157 | ||
158 | // Try to satisfy constraint | |
159 | bool SatisfyConstraint(wxLayoutConstraints *constraints, wxWindowBase *win); | |
160 | ||
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; | |
164 | }; | |
165 | ||
166 | // ---------------------------------------------------------------------------- | |
167 | // wxLayoutConstraints: the complete set of constraints for a window | |
168 | // ---------------------------------------------------------------------------- | |
169 | ||
170 | class WXDLLEXPORT wxLayoutConstraints : public wxObject | |
171 | { | |
172 | DECLARE_DYNAMIC_CLASS(wxLayoutConstraints) | |
173 | ||
174 | public: | |
175 | // Edge constraints | |
176 | wxIndividualLayoutConstraint left; | |
177 | wxIndividualLayoutConstraint top; | |
178 | wxIndividualLayoutConstraint right; | |
179 | wxIndividualLayoutConstraint bottom; | |
180 | // Size constraints | |
181 | wxIndividualLayoutConstraint width; | |
182 | wxIndividualLayoutConstraint height; | |
183 | // Centre constraints | |
184 | wxIndividualLayoutConstraint centreX; | |
185 | wxIndividualLayoutConstraint centreY; | |
186 | ||
187 | wxLayoutConstraints(); | |
188 | ~wxLayoutConstraints(); | |
189 | ||
190 | bool SatisfyConstraints(wxWindowBase *win, int *noChanges); | |
191 | bool AreSatisfied() const | |
192 | { | |
193 | return left.GetDone() && top.GetDone() && right.GetDone() && | |
194 | bottom.GetDone() && centreX.GetDone() && centreY.GetDone(); | |
195 | } | |
196 | }; | |
197 | ||
198 | // ---------------------------------------------------------------------------- | |
199 | // sizers | |
200 | // ---------------------------------------------------------------------------- | |
c801d85f KB |
201 | |
202 | /* | |
203 | ||
204 | Algorithm: | |
205 | ||
206 | Each sizer has a Layout function. | |
207 | ||
208 | wxExpandSizer::Layout ; E.g. for resizeable windows | |
a532afbb | 209 | |
c801d85f KB |
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 | |
216 | ||
217 | wxShrinkSizer::Layout ; E.g. fit-to-contents windows | |
218 | ; Perhaps 2 rowcols, one above other. | |
a532afbb | 219 | |
c801d85f KB |
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 | |
231 | again. | |
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() | |
234 | to determine this. | |
235 | ||
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. | |
a532afbb | 238 | |
c801d85f KB |
239 | wxRowColSizer::Layout |
240 | ||
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. | |
a532afbb | 245 | |
c801d85f KB |
246 | */ |
247 | ||
a532afbb | 248 | class WXDLLEXPORT wxSizer : public wxWindow |
c801d85f | 249 | { |
f03fc89f | 250 | DECLARE_DYNAMIC_CLASS(wxSizer) |
c801d85f | 251 | |
a532afbb VZ |
252 | protected: |
253 | wxSizerBehaviour sizerBehaviour; | |
254 | int borderX; | |
255 | int borderY; | |
256 | int sizerWidth; | |
257 | int sizerHeight; | |
258 | int sizerX; | |
259 | int sizerY; | |
260 | ||
261 | public: | |
262 | wxSizer(); | |
f03fc89f | 263 | wxSizer(wxWindowBase *parent, wxSizerBehaviour behav = wxSizerNone); |
a532afbb | 264 | ~wxSizer(); |
c801d85f | 265 | |
f03fc89f | 266 | bool Create(wxWindowBase *parent, wxSizerBehaviour behav = wxSizerNone); |
acbd13a3 | 267 | |
a532afbb | 268 | virtual void GetSize(int *w, int *h) const; |
7b218dfa | 269 | |
a532afbb | 270 | virtual void GetClientSize(int *w, int *h) const { GetSize(w, h); } |
acbd13a3 | 271 | |
a532afbb | 272 | virtual void GetPosition(int *x, int *y) const; |
c801d85f | 273 | |
a532afbb VZ |
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); } | |
c801d85f | 276 | |
a532afbb VZ |
277 | virtual void SetBorder(int w, int h); |
278 | int GetBorderX() { return borderX ; } | |
279 | int GetBorderY() { return borderY ; } | |
c801d85f | 280 | |
f03fc89f VZ |
281 | virtual void AddSizerChild(wxWindowBase *child); |
282 | virtual void RemoveSizerChild(wxWindowBase *child); | |
c801d85f | 283 | |
a532afbb VZ |
284 | virtual void SetBehaviour(wxSizerBehaviour b) { sizerBehaviour = b; } |
285 | virtual wxSizerBehaviour GetBehaviour() { return sizerBehaviour; } | |
c801d85f | 286 | |
a532afbb VZ |
287 | virtual bool LayoutPhase1(int *); |
288 | virtual bool LayoutPhase2(int *); | |
bfc6fde4 VZ |
289 | |
290 | protected: | |
291 | virtual void DoSetSize(int x, int y, | |
292 | int width, int height, | |
293 | int sizeFlags = wxSIZE_AUTO); | |
c801d85f KB |
294 | }; |
295 | ||
296 | #define wxSIZER_ROWS TRUE | |
297 | #define wxSIZER_COLS FALSE | |
298 | ||
a532afbb | 299 | class WXDLLEXPORT wxRowColSizer : public wxSizer |
c801d85f | 300 | { |
f03fc89f | 301 | DECLARE_DYNAMIC_CLASS(wxRowColSizer) |
a532afbb VZ |
302 | |
303 | protected: | |
304 | bool rowOrCol; | |
305 | int rowOrColSize; | |
306 | int xSpacing; | |
307 | int ySpacing; | |
308 | ||
309 | public: | |
310 | // rowOrCol = TRUE to be laid out in rows, otherwise in columns. | |
311 | wxRowColSizer(); | |
f03fc89f | 312 | wxRowColSizer(wxWindowBase *parent, bool rowOrCol = wxSIZER_ROWS, |
a532afbb VZ |
313 | int rowsOrColSize = 20, wxSizerBehaviour = wxSizerShrink); |
314 | ~wxRowColSizer(); | |
315 | ||
f03fc89f | 316 | bool Create(wxWindowBase *parent, bool rowOrCol = wxSIZER_ROWS, |
a532afbb | 317 | int rowsOrColSize = 20, wxSizerBehaviour = wxSizerShrink); |
a532afbb VZ |
318 | |
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; } | |
325 | ||
326 | bool LayoutPhase1(int *); | |
327 | bool LayoutPhase2(int *); | |
c801d85f KB |
328 | }; |
329 | ||
a532afbb | 330 | class WXDLLEXPORT wxSpacingSizer : public wxSizer |
c801d85f | 331 | { |
f03fc89f | 332 | DECLARE_DYNAMIC_CLASS(wxSpacingSizer) |
c801d85f | 333 | |
a532afbb VZ |
334 | public: |
335 | wxSpacingSizer(); | |
f03fc89f VZ |
336 | wxSpacingSizer(wxWindowBase *parent, wxRelationship rel, wxWindowBase *other, int spacing); |
337 | wxSpacingSizer(wxWindowBase *parent); | |
a532afbb | 338 | ~wxSpacingSizer(); |
c801d85f | 339 | |
f03fc89f VZ |
340 | bool Create(wxWindowBase *parent, wxRelationship rel, wxWindowBase *other, int sp); |
341 | bool Create(wxWindowBase *parent); | |
c801d85f KB |
342 | }; |
343 | ||
f03fc89f VZ |
344 | // ---------------------------------------------------------------------------- |
345 | // global functions | |
346 | // ---------------------------------------------------------------------------- | |
347 | ||
348 | #if WXWIN_COMPATIBILITY | |
349 | extern bool WXDLLEXPORT wxOldDoLayout(wxWindowBase *win); | |
350 | #endif // WXWIN_COMPATIBILITY | |
351 | ||
c801d85f | 352 | #endif |
34138703 | 353 | // _WX_LAYOUTH__ |