]> git.saurik.com Git - wxWidgets.git/blob - include/wx/layout.h
* Thread updates and cleanup (m_locked, MUTEX_UNLOCKED added)
[wxWidgets.git] / include / wx / layout.h
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 __LAYOUTH__
13 #define __LAYOUTH__
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:
51 // 'This' window is the parent or sibling of otherWin
52 wxWindow *otherWin;
53
54 wxEdge myEdge;
55 wxRelationship relationship;
56 int margin;
57 int value;
58 int percent;
59 wxEdge otherEdge;
60 bool done;
61
62 public:
63 wxIndividualLayoutConstraint(void);
64 ~wxIndividualLayoutConstraint(void);
65
66 void Set(wxRelationship rel, wxWindow *otherW, wxEdge otherE, int val = 0, int marg = wxLAYOUT_DEFAULT_MARGIN);
67
68 //
69 // Sibling relationships
70 //
71 void LeftOf(wxWindow *sibling, int marg = wxLAYOUT_DEFAULT_MARGIN);
72 void RightOf(wxWindow *sibling, int marg = wxLAYOUT_DEFAULT_MARGIN);
73 void Above(wxWindow *sibling, int marg = wxLAYOUT_DEFAULT_MARGIN);
74 void Below(wxWindow *sibling, int marg = wxLAYOUT_DEFAULT_MARGIN);
75
76 //
77 // 'Same edge' alignment
78 //
79 void SameAs(wxWindow *otherW, wxEdge edge, int marg = wxLAYOUT_DEFAULT_MARGIN);
80
81 // The edge is a percentage of the other window's edge
82 void PercentOf(wxWindow *otherW, wxEdge wh, int per);
83
84 //
85 // Edge has absolute value
86 //
87 void Absolute(int val);
88
89 //
90 // Dimension is unconstrained
91 //
92 inline void Unconstrained(void) { relationship = wxUnconstrained; }
93
94 //
95 // Dimension is 'as is' (use current size settings)
96 //
97 inline void AsIs(void) { relationship = wxAsIs; }
98
99 //
100 // Accessors
101 //
102 inline wxWindow *GetOtherWindow(void) { return otherWin; }
103 inline wxEdge GetMyEdge(void) { return myEdge; }
104 inline void SetEdge(wxEdge which) { myEdge = which; }
105 inline void SetValue(int v) { value = v; }
106 inline int GetMargin(void) { return margin; }
107 inline void SetMargin(int m) { margin = m; }
108 inline int GetValue(void) { return value; }
109 inline int GetPercent(void) { return percent; }
110 inline int GetOtherEdge(void) { return otherEdge; }
111 inline bool GetDone(void) { return done; }
112 inline void SetDone(bool d) { done = d; }
113 inline wxRelationship GetRelationship(void) { return relationship; }
114 inline void SetRelationship(wxRelationship r) { relationship = r; }
115
116 // Reset constraint if it mentions otherWin
117 bool ResetIfWin(wxWindow *otherW);
118
119 // Try to satisfy constraint
120 bool SatisfyConstraint(wxLayoutConstraints *constraints, wxWindow *win);
121
122 // Get the value of this edge or dimension, or if this
123 // is not determinable, -1.
124 int GetEdge(wxEdge which, wxWindow *thisWin, wxWindow *other);
125 };
126
127 class WXDLLEXPORT wxLayoutConstraints: public wxObject
128 {
129 DECLARE_DYNAMIC_CLASS(wxLayoutConstraints)
130
131 public:
132 // Edge constraints
133 wxIndividualLayoutConstraint left;
134 wxIndividualLayoutConstraint top;
135 wxIndividualLayoutConstraint right;
136 wxIndividualLayoutConstraint bottom;
137 // Size constraints
138 wxIndividualLayoutConstraint width;
139 wxIndividualLayoutConstraint height;
140 // Centre constraints
141 wxIndividualLayoutConstraint centreX;
142 wxIndividualLayoutConstraint centreY;
143
144 wxLayoutConstraints(void);
145 ~wxLayoutConstraints(void);
146
147 bool SatisfyConstraints(wxWindow *win, int *noChanges);
148 };
149
150 bool WXDLLEXPORT wxOldDoLayout(wxWindow *win);
151
152 /*
153
154 Algorithm:
155
156 Each sizer has a Layout function.
157
158 wxExpandSizer::Layout ; E.g. for resizeable windows
159
160 - parent size must be known (i.e. called
161 from OnSize or explicitly)
162 - call Layout on each child to give it a chance to resize
163 (e.g. child shrinks around its own children):
164 stop when all children return TRUE, or no change
165 - evaluate constraints on self to set size
166
167 wxShrinkSizer::Layout ; E.g. fit-to-contents windows
168 ; Perhaps 2 rowcols, one above other.
169
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 each returns TRUE, or no change
173 - fit around children
174 (what if some want to be centred? E.g. OK/Cancel rowcol.
175 - done by centring e.g. bottom sizer w.r.t. top sizer.
176 (sibling relationship only))
177 - evaluate own constraints (e.g. may be below another window)
178 - IF parent is a real window (remember: a real window can
179 have only one child sizer, although a sizer can have several child
180 (real) windows), then resize this parent WITHOUT invoking Layout
181 again.
182 Frame and dialog box OnSizes can check if the sizer is a shrink
183 sizer; if not, can call layout. Maybe have virtual bool AutoSizeLayout()
184 to determine this.
185
186 How to relayout if a child sizer/window changes? Need to go all the way
187 to the top of the hierarchy and call Layout() again.
188
189 wxRowColSizer::Layout
190
191 - Similar to wxShrinkSizer only instead of shrinking to fit
192 contents, more sophisticated layout of contents, and THEN
193 shrinking (possibly).
194 - Do the same parent window check/setsize as for wxShrinkSizer.
195
196 */
197
198 typedef enum {
199 wxSizerShrink,
200 wxSizerExpand,
201 wxSizerNone
202 } wxSizerBehaviour;
203
204 #define wxTYPE_SIZER 90
205
206 class WXDLLEXPORT wxSizer: public wxWindow
207 {
208 DECLARE_DYNAMIC_CLASS(wxSizer)
209
210 private:
211 protected:
212 wxSizerBehaviour sizerBehaviour;
213 int borderX;
214 int borderY;
215 int sizerWidth;
216 int sizerHeight;
217 int sizerX;
218 int sizerY;
219 public:
220 wxSizer(void);
221 wxSizer(wxWindow *parent, wxSizerBehaviour behav = wxSizerNone);
222 ~wxSizer(void);
223
224 bool Create(wxWindow *parent, wxSizerBehaviour behav = wxSizerNone);
225 virtual void SetSize(const int x, const int y, const int w, const int h, const int flags = wxSIZE_AUTO);
226 // Avoid compiler warning
227 void SetSize(const int w, const int h) { wxWindow::SetSize(w, h); }
228 virtual void Move(const int x, const int y);
229 virtual void GetSize(int *w, int *h) const;
230 inline virtual void GetClientSize(int *w, int *h) const { GetSize(w, h); }
231 virtual void GetPosition(int *x, int *y) const;
232
233 inline void SizerSetSize(const int x, const int y, const int w, const int h)
234 { SetSize(x, y, w, h); }
235 inline void SizerMove(const int x, const int y)
236 { Move(x, y); }
237
238 virtual void SetBorder(int w, int h);
239 inline int GetBorderX(void) { return borderX ; }
240 inline int GetBorderY(void) { return borderY ; }
241
242 virtual void AddSizerChild(wxWindow *child);
243 virtual void RemoveSizerChild(wxWindow *child);
244
245 inline virtual void SetBehaviour(wxSizerBehaviour b) { sizerBehaviour = b; }
246 inline virtual wxSizerBehaviour GetBehaviour(void) { return sizerBehaviour; }
247
248 virtual bool LayoutPhase1(int *);
249 virtual bool LayoutPhase2(int *);
250 };
251
252 #define wxSIZER_ROWS TRUE
253 #define wxSIZER_COLS FALSE
254
255 class WXDLLEXPORT wxRowColSizer: public wxSizer
256 {
257 DECLARE_DYNAMIC_CLASS(wxRowColSizer)
258
259 private:
260 protected:
261 bool rowOrCol;
262 int rowOrColSize;
263 int xSpacing;
264 int ySpacing;
265 public:
266 // rowOrCol = TRUE to be laid out in rows, otherwise in columns.
267 wxRowColSizer(void);
268 wxRowColSizer(wxWindow *parent, bool rowOrCol = wxSIZER_ROWS, int rowsOrColSize = 20, wxSizerBehaviour = wxSizerShrink);
269 ~wxRowColSizer(void);
270
271 bool Create(wxWindow *parent, bool rowOrCol = wxSIZER_ROWS, int rowsOrColSize = 20, wxSizerBehaviour = wxSizerShrink);
272 void SetSize(const int x, const int y, const int w, const int h, const int flags = wxSIZE_AUTO);
273 // Avoid compiler warning
274 void SetSize(const int w, const int h) { wxSizer::SetSize(w, h); }
275
276 inline virtual void SetRowOrCol(bool rc) { rowOrCol = rc; }
277 inline virtual bool GetRowOrCol(void) { return rowOrCol; }
278 inline virtual void SetRowOrColSize(int n) { rowOrColSize = n; }
279 inline virtual int GetRowOrColSize(void) { return rowOrColSize; }
280 inline virtual void SetSpacing(int x, int y) { xSpacing = x; ySpacing = y; }
281 inline virtual void GetSpacing(int *x, int *y) { *x = xSpacing; *y = ySpacing; }
282
283 bool LayoutPhase1(int *);
284 bool LayoutPhase2(int *);
285 };
286
287 class WXDLLEXPORT wxSpacingSizer: public wxSizer
288 {
289 DECLARE_DYNAMIC_CLASS(wxSpacingSizer)
290
291 private:
292 protected:
293 public:
294 wxSpacingSizer(void);
295 wxSpacingSizer(wxWindow *parent, wxRelationship rel, wxWindow *other, int spacing);
296 wxSpacingSizer(wxWindow *parent);
297 ~wxSpacingSizer(void);
298
299 bool Create(wxWindow *parent, wxRelationship rel, wxWindow *other, int sp);
300 bool Create(wxWindow *parent);
301 };
302
303 #endif
304 // __LAYOUTH__