]> git.saurik.com Git - wxWidgets.git/blame - include/wx/layout.h
made pre-compiling the python files optional
[wxWidgets.git] / include / wx / layout.h
CommitLineData
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
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
21class 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
33enum wxEdge { wxLeft, wxTop, wxRight, wxBottom, wxWidth, wxHeight,
34 wxCentre, wxCenter = wxCentre, wxCentreX, wxCentreY };
35enum wxRelationship { wxUnconstrained = 0,
36 wxAsIs,
37 wxPercentOf,
38 wxAbove,
39 wxBelow,
40 wxLeftOf,
41 wxRightOf,
42 wxSameAs,
43 wxAbsolute };
44
45class WXDLLEXPORT wxLayoutConstraints;
46class 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:
a3622daa
VZ
63 wxIndividualLayoutConstraint();
64 ~wxIndividualLayoutConstraint();
c801d85f
KB
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 //
a3622daa 92 inline void Unconstrained() { relationship = wxUnconstrained; }
c801d85f
KB
93
94 //
95 // Dimension is 'as is' (use current size settings)
96 //
a3622daa 97 inline void AsIs() { relationship = wxAsIs; }
c801d85f
KB
98
99 //
100 // Accessors
101 //
a3622daa
VZ
102 inline wxWindow *GetOtherWindow() { return otherWin; }
103 inline wxEdge GetMyEdge() const { return myEdge; }
c801d85f
KB
104 inline void SetEdge(wxEdge which) { myEdge = which; }
105 inline void SetValue(int v) { value = v; }
a3622daa 106 inline int GetMargin() { return margin; }
c801d85f 107 inline void SetMargin(int m) { margin = m; }
a3622daa
VZ
108 inline int GetValue() const { return value; }
109 inline int GetPercent() const { return percent; }
110 inline int GetOtherEdge() const { return otherEdge; }
111 inline bool GetDone() const { return done; }
c801d85f 112 inline void SetDone(bool d) { done = d; }
a3622daa 113 inline wxRelationship GetRelationship() { return relationship; }
c801d85f
KB
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.
a3622daa 124 int GetEdge(wxEdge which, wxWindow *thisWin, wxWindow *other) const;
c801d85f
KB
125};
126
127class 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
a3622daa
VZ
144 wxLayoutConstraints();
145 ~wxLayoutConstraints();
c801d85f
KB
146
147 bool SatisfyConstraints(wxWindow *win, int *noChanges);
a3622daa
VZ
148 bool AreSatisfied() const
149 {
150 return left.GetDone() && top.GetDone() && right.GetDone() &&
151 bottom.GetDone() && centreX.GetDone() && centreY.GetDone();
152 }
c801d85f
KB
153};
154
155bool WXDLLEXPORT wxOldDoLayout(wxWindow *win);
156
157/*
158
159Algorithm:
160
161 Each sizer has a Layout function.
162
163 wxExpandSizer::Layout ; E.g. for resizeable windows
164
165 - parent size must be known (i.e. called
166 from OnSize or explicitly)
167 - call Layout on each child to give it a chance to resize
168 (e.g. child shrinks around its own children):
169 stop when all children return TRUE, or no change
170 - evaluate constraints on self to set size
171
172 wxShrinkSizer::Layout ; E.g. fit-to-contents windows
173 ; Perhaps 2 rowcols, one above other.
174
175 - call Layout on each child to give it a chance to resize
176 (e.g. child shrinks around its own children):
177 stop when each returns TRUE, or no change
178 - fit around children
179 (what if some want to be centred? E.g. OK/Cancel rowcol.
180 - done by centring e.g. bottom sizer w.r.t. top sizer.
181 (sibling relationship only))
182 - evaluate own constraints (e.g. may be below another window)
183 - IF parent is a real window (remember: a real window can
184 have only one child sizer, although a sizer can have several child
185 (real) windows), then resize this parent WITHOUT invoking Layout
186 again.
187 Frame and dialog box OnSizes can check if the sizer is a shrink
188 sizer; if not, can call layout. Maybe have virtual bool AutoSizeLayout()
189 to determine this.
190
191How to relayout if a child sizer/window changes? Need to go all the way
192to the top of the hierarchy and call Layout() again.
193
194 wxRowColSizer::Layout
195
196 - Similar to wxShrinkSizer only instead of shrinking to fit
197 contents, more sophisticated layout of contents, and THEN
198 shrinking (possibly).
199 - Do the same parent window check/setsize as for wxShrinkSizer.
200
201*/
202
203typedef enum {
204 wxSizerShrink,
205 wxSizerExpand,
206 wxSizerNone
207} wxSizerBehaviour;
208
209#define wxTYPE_SIZER 90
210
211class WXDLLEXPORT wxSizer: public wxWindow
212{
213 DECLARE_DYNAMIC_CLASS(wxSizer)
214
215 private:
216 protected:
217 wxSizerBehaviour sizerBehaviour;
218 int borderX;
219 int borderY;
220 int sizerWidth;
221 int sizerHeight;
222 int sizerX;
223 int sizerY;
224 public:
a3622daa 225 wxSizer();
c801d85f 226 wxSizer(wxWindow *parent, wxSizerBehaviour behav = wxSizerNone);
a3622daa 227 ~wxSizer();
c801d85f
KB
228
229 bool Create(wxWindow *parent, wxSizerBehaviour behav = wxSizerNone);
debe6624 230 virtual void SetSize(int x, int y, int w, int h, int flags = wxSIZE_AUTO);
c801d85f 231 // Avoid compiler warning
debe6624
JS
232 void SetSize(int w, int h) { wxWindow::SetSize(w, h); }
233 virtual void Move(int x, int y);
c801d85f
KB
234 virtual void GetSize(int *w, int *h) const;
235 inline virtual void GetClientSize(int *w, int *h) const { GetSize(w, h); }
236 virtual void GetPosition(int *x, int *y) const;
237
debe6624 238 inline void SizerSetSize(int x, int y, int w, int h)
c801d85f 239 { SetSize(x, y, w, h); }
debe6624 240 inline void SizerMove(int x, int y)
c801d85f
KB
241 { Move(x, y); }
242
243 virtual void SetBorder(int w, int h);
a3622daa
VZ
244 inline int GetBorderX() { return borderX ; }
245 inline int GetBorderY() { return borderY ; }
c801d85f
KB
246
247 virtual void AddSizerChild(wxWindow *child);
248 virtual void RemoveSizerChild(wxWindow *child);
249
250 inline virtual void SetBehaviour(wxSizerBehaviour b) { sizerBehaviour = b; }
a3622daa 251 inline virtual wxSizerBehaviour GetBehaviour() { return sizerBehaviour; }
c801d85f
KB
252
253 virtual bool LayoutPhase1(int *);
254 virtual bool LayoutPhase2(int *);
255};
256
257#define wxSIZER_ROWS TRUE
258#define wxSIZER_COLS FALSE
259
260class WXDLLEXPORT wxRowColSizer: public wxSizer
261{
262 DECLARE_DYNAMIC_CLASS(wxRowColSizer)
263
264 private:
265 protected:
266 bool rowOrCol;
267 int rowOrColSize;
268 int xSpacing;
269 int ySpacing;
270 public:
271 // rowOrCol = TRUE to be laid out in rows, otherwise in columns.
a3622daa 272 wxRowColSizer();
c801d85f 273 wxRowColSizer(wxWindow *parent, bool rowOrCol = wxSIZER_ROWS, int rowsOrColSize = 20, wxSizerBehaviour = wxSizerShrink);
a3622daa 274 ~wxRowColSizer();
c801d85f
KB
275
276 bool Create(wxWindow *parent, bool rowOrCol = wxSIZER_ROWS, int rowsOrColSize = 20, wxSizerBehaviour = wxSizerShrink);
debe6624 277 void SetSize(int x, int y, int w, int h, int flags = wxSIZE_AUTO);
c801d85f 278 // Avoid compiler warning
debe6624 279 void SetSize(int w, int h) { wxSizer::SetSize(w, h); }
c801d85f
KB
280
281 inline virtual void SetRowOrCol(bool rc) { rowOrCol = rc; }
a3622daa 282 inline virtual bool GetRowOrCol() { return rowOrCol; }
c801d85f 283 inline virtual void SetRowOrColSize(int n) { rowOrColSize = n; }
a3622daa 284 inline virtual int GetRowOrColSize() { return rowOrColSize; }
c801d85f
KB
285 inline virtual void SetSpacing(int x, int y) { xSpacing = x; ySpacing = y; }
286 inline virtual void GetSpacing(int *x, int *y) { *x = xSpacing; *y = ySpacing; }
287
288 bool LayoutPhase1(int *);
289 bool LayoutPhase2(int *);
290};
291
292class WXDLLEXPORT wxSpacingSizer: public wxSizer
293{
294 DECLARE_DYNAMIC_CLASS(wxSpacingSizer)
295
296 private:
297 protected:
298 public:
a3622daa 299 wxSpacingSizer();
c801d85f
KB
300 wxSpacingSizer(wxWindow *parent, wxRelationship rel, wxWindow *other, int spacing);
301 wxSpacingSizer(wxWindow *parent);
a3622daa 302 ~wxSpacingSizer();
c801d85f
KB
303
304 bool Create(wxWindow *parent, wxRelationship rel, wxWindow *other, int sp);
305 bool Create(wxWindow *parent);
306};
307
308#endif
309 // __LAYOUTH__