]>
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 KB |
14 | |
15 | #ifdef __GNUG__ | |
16 | #pragma interface "layout.h" | |
17 | #endif | |
18 | ||
19 | #include "wx/defs.h" | |
20 | ||
21 | class WXDLLEXPORT wxWindow; | |
22 | ||
23 | // X stupidly defines these in X.h | |
24 | #ifdef Above | |
25 | #undef Above | |
26 | #endif | |
27 | #ifdef Below | |
28 | #undef Below | |
29 | #endif | |
30 | ||
31 | #define wxLAYOUT_DEFAULT_MARGIN 0 | |
32 | ||
33 | enum wxEdge { wxLeft, wxTop, wxRight, wxBottom, wxWidth, wxHeight, | |
34 | wxCentre, wxCenter = wxCentre, wxCentreX, wxCentreY }; | |
35 | enum wxRelationship { wxUnconstrained = 0, | |
36 | wxAsIs, | |
37 | wxPercentOf, | |
38 | wxAbove, | |
39 | wxBelow, | |
40 | wxLeftOf, | |
41 | wxRightOf, | |
42 | wxSameAs, | |
43 | wxAbsolute }; | |
44 | ||
45 | class WXDLLEXPORT wxLayoutConstraints; | |
46 | class WXDLLEXPORT wxIndividualLayoutConstraint: public wxObject | |
47 | { | |
48 | DECLARE_DYNAMIC_CLASS(wxIndividualLayoutConstraint) | |
49 | ||
50 | protected: | |
c2dd8380 GL |
51 | // To be allowed to modify the internal variables |
52 | friend class wxIndividualLayoutConstraint_Serialize; | |
53 | ||
c801d85f KB |
54 | // 'This' window is the parent or sibling of otherWin |
55 | wxWindow *otherWin; | |
56 | ||
57 | wxEdge myEdge; | |
58 | wxRelationship relationship; | |
59 | int margin; | |
60 | int value; | |
61 | int percent; | |
62 | wxEdge otherEdge; | |
63 | bool done; | |
64 | ||
65 | public: | |
a3622daa VZ |
66 | wxIndividualLayoutConstraint(); |
67 | ~wxIndividualLayoutConstraint(); | |
c801d85f KB |
68 | |
69 | void Set(wxRelationship rel, wxWindow *otherW, wxEdge otherE, int val = 0, int marg = wxLAYOUT_DEFAULT_MARGIN); | |
70 | ||
71 | // | |
72 | // Sibling relationships | |
73 | // | |
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); | |
78 | ||
79 | // | |
80 | // 'Same edge' alignment | |
81 | // | |
82 | void SameAs(wxWindow *otherW, wxEdge edge, int marg = wxLAYOUT_DEFAULT_MARGIN); | |
83 | ||
84 | // The edge is a percentage of the other window's edge | |
85 | void PercentOf(wxWindow *otherW, wxEdge wh, int per); | |
86 | ||
87 | // | |
88 | // Edge has absolute value | |
89 | // | |
90 | void Absolute(int val); | |
91 | ||
92 | // | |
93 | // Dimension is unconstrained | |
94 | // | |
a3622daa | 95 | inline void Unconstrained() { relationship = wxUnconstrained; } |
c801d85f KB |
96 | |
97 | // | |
98 | // Dimension is 'as is' (use current size settings) | |
99 | // | |
a3622daa | 100 | inline void AsIs() { relationship = wxAsIs; } |
c801d85f KB |
101 | |
102 | // | |
103 | // Accessors | |
104 | // | |
a3622daa VZ |
105 | inline wxWindow *GetOtherWindow() { return otherWin; } |
106 | inline wxEdge GetMyEdge() const { return myEdge; } | |
c801d85f KB |
107 | inline void SetEdge(wxEdge which) { myEdge = which; } |
108 | inline void SetValue(int v) { value = v; } | |
a3622daa | 109 | inline int GetMargin() { return margin; } |
c801d85f | 110 | inline void SetMargin(int m) { margin = m; } |
a3622daa VZ |
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; } | |
c801d85f | 115 | inline void SetDone(bool d) { done = d; } |
a3622daa | 116 | inline wxRelationship GetRelationship() { return relationship; } |
c801d85f KB |
117 | inline void SetRelationship(wxRelationship r) { relationship = r; } |
118 | ||
119 | // Reset constraint if it mentions otherWin | |
120 | bool ResetIfWin(wxWindow *otherW); | |
121 | ||
122 | // Try to satisfy constraint | |
123 | bool SatisfyConstraint(wxLayoutConstraints *constraints, wxWindow *win); | |
124 | ||
125 | // Get the value of this edge or dimension, or if this | |
126 | // is not determinable, -1. | |
a3622daa | 127 | int GetEdge(wxEdge which, wxWindow *thisWin, wxWindow *other) const; |
c801d85f KB |
128 | }; |
129 | ||
130 | class WXDLLEXPORT wxLayoutConstraints: public wxObject | |
131 | { | |
132 | DECLARE_DYNAMIC_CLASS(wxLayoutConstraints) | |
133 | ||
134 | public: | |
135 | // Edge constraints | |
136 | wxIndividualLayoutConstraint left; | |
137 | wxIndividualLayoutConstraint top; | |
138 | wxIndividualLayoutConstraint right; | |
139 | wxIndividualLayoutConstraint bottom; | |
140 | // Size constraints | |
141 | wxIndividualLayoutConstraint width; | |
142 | wxIndividualLayoutConstraint height; | |
143 | // Centre constraints | |
144 | wxIndividualLayoutConstraint centreX; | |
145 | wxIndividualLayoutConstraint centreY; | |
146 | ||
a3622daa VZ |
147 | wxLayoutConstraints(); |
148 | ~wxLayoutConstraints(); | |
c801d85f KB |
149 | |
150 | bool SatisfyConstraints(wxWindow *win, int *noChanges); | |
a3622daa VZ |
151 | bool AreSatisfied() const |
152 | { | |
153 | return left.GetDone() && top.GetDone() && right.GetDone() && | |
154 | bottom.GetDone() && centreX.GetDone() && centreY.GetDone(); | |
155 | } | |
c801d85f KB |
156 | }; |
157 | ||
158 | bool WXDLLEXPORT wxOldDoLayout(wxWindow *win); | |
159 | ||
160 | /* | |
161 | ||
162 | Algorithm: | |
163 | ||
164 | Each sizer has a Layout function. | |
165 | ||
166 | wxExpandSizer::Layout ; E.g. for resizeable windows | |
a532afbb | 167 | |
c801d85f KB |
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 | |
174 | ||
175 | wxShrinkSizer::Layout ; E.g. fit-to-contents windows | |
176 | ; Perhaps 2 rowcols, one above other. | |
a532afbb | 177 | |
c801d85f KB |
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 | |
189 | again. | |
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() | |
192 | to determine this. | |
193 | ||
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. | |
a532afbb | 196 | |
c801d85f KB |
197 | wxRowColSizer::Layout |
198 | ||
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. | |
a532afbb | 203 | |
c801d85f KB |
204 | */ |
205 | ||
a532afbb VZ |
206 | enum wxSizerBehaviour |
207 | { | |
c801d85f KB |
208 | wxSizerShrink, |
209 | wxSizerExpand, | |
210 | wxSizerNone | |
a532afbb | 211 | }; |
c801d85f KB |
212 | |
213 | #define wxTYPE_SIZER 90 | |
214 | ||
a532afbb | 215 | class WXDLLEXPORT wxSizer : public wxWindow |
c801d85f | 216 | { |
a532afbb | 217 | DECLARE_DYNAMIC_CLASS(wxSizer) |
c801d85f | 218 | |
a532afbb VZ |
219 | protected: |
220 | wxSizerBehaviour sizerBehaviour; | |
221 | int borderX; | |
222 | int borderY; | |
223 | int sizerWidth; | |
224 | int sizerHeight; | |
225 | int sizerX; | |
226 | int sizerY; | |
227 | ||
228 | public: | |
229 | wxSizer(); | |
230 | wxSizer(wxWindow *parent, wxSizerBehaviour behav = wxSizerNone); | |
231 | ~wxSizer(); | |
c801d85f | 232 | |
a532afbb | 233 | bool Create(wxWindow *parent, wxSizerBehaviour behav = wxSizerNone); |
acbd13a3 | 234 | |
a532afbb | 235 | virtual void GetSize(int *w, int *h) const; |
7b218dfa | 236 | |
a532afbb | 237 | virtual void GetClientSize(int *w, int *h) const { GetSize(w, h); } |
acbd13a3 | 238 | |
a532afbb | 239 | virtual void GetPosition(int *x, int *y) const; |
c801d85f | 240 | |
a532afbb VZ |
241 | void SizerSetSize(int x, int y, int w, int h) { SetSize(x, y, w, h); } |
242 | void SizerMove(int x, int y) { Move(x, y); } | |
c801d85f | 243 | |
a532afbb VZ |
244 | virtual void SetBorder(int w, int h); |
245 | int GetBorderX() { return borderX ; } | |
246 | int GetBorderY() { return borderY ; } | |
c801d85f | 247 | |
a532afbb VZ |
248 | virtual void AddSizerChild(wxWindow *child); |
249 | virtual void RemoveSizerChild(wxWindow *child); | |
c801d85f | 250 | |
a532afbb VZ |
251 | virtual void SetBehaviour(wxSizerBehaviour b) { sizerBehaviour = b; } |
252 | virtual wxSizerBehaviour GetBehaviour() { return sizerBehaviour; } | |
c801d85f | 253 | |
a532afbb VZ |
254 | virtual bool LayoutPhase1(int *); |
255 | virtual bool LayoutPhase2(int *); | |
bfc6fde4 VZ |
256 | |
257 | protected: | |
258 | virtual void DoSetSize(int x, int y, | |
259 | int width, int height, | |
260 | int sizeFlags = wxSIZE_AUTO); | |
c801d85f KB |
261 | }; |
262 | ||
263 | #define wxSIZER_ROWS TRUE | |
264 | #define wxSIZER_COLS FALSE | |
265 | ||
a532afbb | 266 | class WXDLLEXPORT wxRowColSizer : public wxSizer |
c801d85f | 267 | { |
a532afbb VZ |
268 | DECLARE_DYNAMIC_CLASS(wxRowColSizer) |
269 | ||
270 | protected: | |
271 | bool rowOrCol; | |
272 | int rowOrColSize; | |
273 | int xSpacing; | |
274 | int ySpacing; | |
275 | ||
276 | public: | |
277 | // rowOrCol = TRUE to be laid out in rows, otherwise in columns. | |
278 | wxRowColSizer(); | |
279 | wxRowColSizer(wxWindow *parent, bool rowOrCol = wxSIZER_ROWS, | |
280 | int rowsOrColSize = 20, wxSizerBehaviour = wxSizerShrink); | |
281 | ~wxRowColSizer(); | |
282 | ||
283 | bool Create(wxWindow *parent, bool rowOrCol = wxSIZER_ROWS, | |
284 | int rowsOrColSize = 20, wxSizerBehaviour = wxSizerShrink); | |
a532afbb VZ |
285 | |
286 | virtual void SetRowOrCol(bool rc) { rowOrCol = rc; } | |
287 | virtual bool GetRowOrCol() { return rowOrCol; } | |
288 | virtual void SetRowOrColSize(int n) { rowOrColSize = n; } | |
289 | virtual int GetRowOrColSize() { return rowOrColSize; } | |
290 | virtual void SetSpacing(int x, int y) { xSpacing = x; ySpacing = y; } | |
291 | virtual void GetSpacing(int *x, int *y) { *x = xSpacing; *y = ySpacing; } | |
292 | ||
293 | bool LayoutPhase1(int *); | |
294 | bool LayoutPhase2(int *); | |
c801d85f KB |
295 | }; |
296 | ||
a532afbb | 297 | class WXDLLEXPORT wxSpacingSizer : public wxSizer |
c801d85f | 298 | { |
a532afbb | 299 | DECLARE_DYNAMIC_CLASS(wxSpacingSizer) |
c801d85f | 300 | |
a532afbb VZ |
301 | public: |
302 | wxSpacingSizer(); | |
303 | wxSpacingSizer(wxWindow *parent, wxRelationship rel, wxWindow *other, int spacing); | |
304 | wxSpacingSizer(wxWindow *parent); | |
305 | ~wxSpacingSizer(); | |
c801d85f | 306 | |
a532afbb VZ |
307 | bool Create(wxWindow *parent, wxRelationship rel, wxWindow *other, int sp); |
308 | bool Create(wxWindow *parent); | |
c801d85f KB |
309 | }; |
310 | ||
311 | #endif | |
34138703 | 312 | // _WX_LAYOUTH__ |