]>
Commit | Line | Data |
---|---|---|
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 | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_LAYOUTH__ | |
13 | #define _WX_LAYOUTH__ | |
14 | ||
15 | // ---------------------------------------------------------------------------- | |
16 | // headers | |
17 | // ---------------------------------------------------------------------------- | |
18 | ||
19 | #ifdef __GNUG__ | |
20 | #pragma interface "layout.h" | |
21 | #endif | |
22 | ||
23 | #include "wx/defs.h" | |
24 | ||
25 | // X stupidly defines these in X.h | |
26 | #ifdef Above | |
27 | #undef Above | |
28 | #endif | |
29 | #ifdef Below | |
30 | #undef Below | |
31 | #endif | |
32 | ||
33 | // ---------------------------------------------------------------------------- | |
34 | // forward declrations | |
35 | // ---------------------------------------------------------------------------- | |
36 | ||
37 | class WXDLLEXPORT wxWindowBase; | |
38 | class WXDLLEXPORT wxLayoutConstraints; | |
39 | ||
40 | // ---------------------------------------------------------------------------- | |
41 | // constants | |
42 | // ---------------------------------------------------------------------------- | |
43 | ||
44 | #define wxLAYOUT_DEFAULT_MARGIN 0 | |
45 | ||
46 | enum wxEdge | |
47 | { | |
48 | wxLeft, wxTop, wxRight, wxBottom, wxWidth, wxHeight, | |
49 | wxCentre, wxCenter = wxCentre, wxCentreX, wxCentreY | |
50 | }; | |
51 | ||
52 | enum wxRelationship | |
53 | { | |
54 | wxUnconstrained = 0, | |
55 | wxAsIs, | |
56 | wxPercentOf, | |
57 | wxAbove, | |
58 | wxBelow, | |
59 | wxLeftOf, | |
60 | wxRightOf, | |
61 | wxSameAs, | |
62 | wxAbsolute | |
63 | }; | |
64 | ||
65 | enum wxSizerBehaviour | |
66 | { | |
67 | wxSizerShrink, | |
68 | wxSizerExpand, | |
69 | wxSizerNone | |
70 | }; | |
71 | ||
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 | // ---------------------------------------------------------------------------- | |
201 | ||
202 | /* | |
203 | ||
204 | Algorithm: | |
205 | ||
206 | Each sizer has a Layout function. | |
207 | ||
208 | wxExpandSizer::Layout ; E.g. for resizeable windows | |
209 | ||
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. | |
219 | ||
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. | |
238 | ||
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. | |
245 | ||
246 | */ | |
247 | ||
248 | class WXDLLEXPORT wxSizer : public wxWindow | |
249 | { | |
250 | DECLARE_DYNAMIC_CLASS(wxSizer) | |
251 | ||
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(); | |
263 | wxSizer(wxWindowBase *parent, wxSizerBehaviour behav = wxSizerNone); | |
264 | ~wxSizer(); | |
265 | ||
266 | bool Create(wxWindowBase *parent, wxSizerBehaviour behav = wxSizerNone); | |
267 | ||
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; | |
271 | ||
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); } | |
274 | ||
275 | virtual void SetBorder(int w, int h); | |
276 | int GetBorderX() { return borderX ; } | |
277 | int GetBorderY() { return borderY ; } | |
278 | ||
279 | virtual void AddSizerChild(wxWindowBase *child); | |
280 | virtual void RemoveSizerChild(wxWindowBase *child); | |
281 | ||
282 | virtual void SetBehaviour(wxSizerBehaviour b) { sizerBehaviour = b; } | |
283 | virtual wxSizerBehaviour GetBehaviour() { return sizerBehaviour; } | |
284 | ||
285 | virtual bool LayoutPhase1(int *); | |
286 | virtual bool LayoutPhase2(int *); | |
287 | ||
288 | protected: | |
289 | virtual void DoSetSize(int x, int y, | |
290 | int width, int height, | |
291 | int sizeFlags = wxSIZE_AUTO); | |
292 | }; | |
293 | ||
294 | #define wxSIZER_ROWS TRUE | |
295 | #define wxSIZER_COLS FALSE | |
296 | ||
297 | class WXDLLEXPORT wxRowColSizer : public wxSizer | |
298 | { | |
299 | DECLARE_DYNAMIC_CLASS(wxRowColSizer) | |
300 | ||
301 | protected: | |
302 | bool rowOrCol; | |
303 | int rowOrColSize; | |
304 | int xSpacing; | |
305 | int ySpacing; | |
306 | ||
307 | public: | |
308 | // rowOrCol = TRUE to be laid out in rows, otherwise in columns. | |
309 | wxRowColSizer(); | |
310 | wxRowColSizer(wxWindowBase *parent, bool rowOrCol = wxSIZER_ROWS, | |
311 | int rowsOrColSize = 20, wxSizerBehaviour = wxSizerShrink); | |
312 | ~wxRowColSizer(); | |
313 | ||
314 | bool Create(wxWindowBase *parent, bool rowOrCol = wxSIZER_ROWS, | |
315 | int rowsOrColSize = 20, wxSizerBehaviour = wxSizerShrink); | |
316 | ||
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; } | |
323 | ||
324 | bool LayoutPhase1(int *); | |
325 | bool LayoutPhase2(int *); | |
326 | }; | |
327 | ||
328 | class WXDLLEXPORT wxSpacingSizer : public wxSizer | |
329 | { | |
330 | DECLARE_DYNAMIC_CLASS(wxSpacingSizer) | |
331 | ||
332 | public: | |
333 | wxSpacingSizer(); | |
334 | wxSpacingSizer(wxWindowBase *parent, wxRelationship rel, wxWindowBase *other, int spacing); | |
335 | wxSpacingSizer(wxWindowBase *parent); | |
336 | ~wxSpacingSizer(); | |
337 | ||
338 | bool Create(wxWindowBase *parent, wxRelationship rel, wxWindowBase *other, int sp); | |
339 | bool Create(wxWindowBase *parent); | |
340 | }; | |
341 | ||
342 | // ---------------------------------------------------------------------------- | |
343 | // global functions | |
344 | // ---------------------------------------------------------------------------- | |
345 | ||
346 | #if WXWIN_COMPATIBILITY | |
347 | extern bool WXDLLEXPORT wxOldDoLayout(wxWindowBase *win); | |
348 | #endif // WXWIN_COMPATIBILITY | |
349 | ||
350 | #endif | |
351 | // _WX_LAYOUTH__ |