]>
Commit | Line | Data |
---|---|---|
5279a24d RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: sizer.h | |
0c0d686f | 3 | // Purpose: provide wxSizer class for layouting |
5279a24d RR |
4 | // Author: Robert Roebling and Robin Dunn |
5 | // Modified by: | |
0c0d686f | 6 | // Created: |
5279a24d RR |
7 | // RCS-ID: $Id$ |
8 | // Copyright: (c) Robin Dunn, Dirk Holtwick and Robert Roebling | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef __WXSIZER_H__ | |
13 | #define __WXSIZER_H__ | |
14 | ||
15 | #ifdef __GNUG__ | |
16 | #pragma interface "sizer.h" | |
17 | #endif | |
18 | ||
19 | #include "wx/defs.h" | |
20 | ||
21 | #include "wx/window.h" | |
22 | #include "wx/frame.h" | |
23 | #include "wx/dialog.h" | |
24 | ||
25 | //--------------------------------------------------------------------------- | |
26 | // classes | |
27 | //--------------------------------------------------------------------------- | |
28 | ||
27ea1d8a | 29 | class wxStaticBox; |
83edc0a5 | 30 | class wxNotebook; |
27ea1d8a | 31 | |
3417c2cd RR |
32 | class wxSizerItem; |
33 | class wxSizer; | |
92afa2b1 | 34 | class wxBoxSizer; |
27ea1d8a | 35 | class wxStaticBoxSizer; |
5279a24d RR |
36 | |
37 | //--------------------------------------------------------------------------- | |
3417c2cd | 38 | // wxSizerItem |
5279a24d RR |
39 | //--------------------------------------------------------------------------- |
40 | ||
3417c2cd | 41 | class WXDLLEXPORT wxSizerItem: public wxObject |
5279a24d RR |
42 | { |
43 | public: | |
df5ddbca RR |
44 | // spacer |
45 | wxSizerItem( int width, int height, int option, int flag, int border, wxObject* userData); | |
46 | ||
47 | // window | |
48 | wxSizerItem( wxWindow *window, int option, int flag, int border, wxObject* userData ); | |
49 | ||
50 | // subsizer | |
51 | wxSizerItem( wxSizer *sizer, int option, int flag, int border, wxObject* userData ); | |
52 | ||
53 | ~wxSizerItem(); | |
54 | ||
55 | virtual wxSize GetSize(); | |
56 | virtual wxSize CalcMin(); | |
57 | virtual void SetDimension( wxPoint pos, wxSize size ); | |
58 | ||
59 | wxSize GetMinSize() | |
60 | { return m_minSize; } | |
61 | ||
62 | void SetRatio( int width, int height ) | |
63 | // if either of dimensions is zero, ratio is assumed to be 1 | |
64 | // to avoid "divide by zero" errors | |
65 | { m_ratio = (width && height) ? ((float) width / (float) height) : 1; } | |
66 | void SetRatio( wxSize size ) | |
67 | { m_ratio = (size.x && size.y) ? ((float) size.x / (float) size.y) : 1; } | |
68 | void SetRatio( float ratio ) | |
69 | { m_ratio = ratio; } | |
70 | float GetRatio() const | |
71 | { return m_ratio; } | |
72 | ||
73 | bool IsWindow(); | |
74 | bool IsSizer(); | |
75 | bool IsSpacer(); | |
aaf6c39a | 76 | |
df5ddbca RR |
77 | void SetInitSize( int x, int y ) |
78 | { m_minSize.x = x; m_minSize.y = y; } | |
79 | void SetOption( int option ) | |
80 | { m_option = option; } | |
81 | void SetFlag( int flag ) | |
82 | { m_flag = flag; } | |
83 | void SetBorder( int border ) | |
84 | { m_border = border; } | |
85 | ||
86 | wxWindow *GetWindow() const | |
87 | { return m_window; } | |
88 | void SetWindow( wxWindow *window ) | |
89 | { m_window = window; } | |
90 | wxSizer *GetSizer() const | |
91 | { return m_sizer; } | |
92 | void SetSizer( wxSizer *sizer ) | |
93 | { m_sizer = sizer; } | |
94 | int GetOption() const | |
95 | { return m_option; } | |
96 | int GetFlag() const | |
97 | { return m_flag; } | |
98 | int GetBorder() const | |
99 | { return m_border; } | |
100 | wxObject* GetUserData() | |
101 | { return m_userData; } | |
102 | wxPoint GetPosition() | |
103 | { return m_pos; } | |
0c0d686f | 104 | |
c62ac5b6 | 105 | protected: |
df5ddbca RR |
106 | wxWindow *m_window; |
107 | wxSizer *m_sizer; | |
108 | wxSize m_size; | |
109 | wxPoint m_pos; | |
110 | wxSize m_minSize; | |
111 | int m_option; | |
112 | int m_border; | |
113 | int m_flag; | |
114 | // als: aspect ratio can always be calculated from m_size, | |
115 | // but this would cause precision loss when the window | |
116 | // is shrinked. it is safer to preserve initial value. | |
117 | float m_ratio; | |
118 | wxObject *m_userData; | |
119 | ||
120 | private: | |
121 | DECLARE_CLASS(wxSizerItem); | |
c62ac5b6 | 122 | }; |
5279a24d RR |
123 | |
124 | //--------------------------------------------------------------------------- | |
3417c2cd | 125 | // wxSizer |
5279a24d RR |
126 | //--------------------------------------------------------------------------- |
127 | ||
3417c2cd | 128 | class WXDLLEXPORT wxSizer: public wxObject |
5279a24d RR |
129 | { |
130 | public: | |
f6bcfd97 BP |
131 | wxSizer(); |
132 | ~wxSizer(); | |
133 | ||
134 | /* These should be called Append() really. */ | |
135 | virtual void Add( wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); | |
136 | virtual void Add( wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); | |
137 | virtual void Add( int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); | |
138 | ||
139 | virtual void Insert( int before, wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); | |
140 | virtual void Insert( int before, wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); | |
141 | virtual void Insert( int before, int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); | |
142 | ||
143 | virtual void Prepend( wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); | |
144 | virtual void Prepend( wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); | |
145 | virtual void Prepend( int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); | |
146 | ||
147 | virtual bool Remove( wxWindow *window ); | |
148 | virtual bool Remove( wxSizer *sizer ); | |
149 | virtual bool Remove( int pos ); | |
150 | ||
151 | void SetMinSize( int width, int height ) | |
152 | { DoSetMinSize( width, height ); } | |
153 | void SetMinSize( wxSize size ) | |
154 | { DoSetMinSize( size.x, size.y ); } | |
155 | ||
156 | /* Searches recursively */ | |
157 | bool SetItemMinSize( wxWindow *window, int width, int height ) | |
158 | { return DoSetItemMinSize( window, width, height ); } | |
159 | bool SetItemMinSize( wxWindow *window, wxSize size ) | |
160 | { return DoSetItemMinSize( window, size.x, size.y ); } | |
161 | ||
162 | /* Searches recursively */ | |
163 | bool SetItemMinSize( wxSizer *sizer, int width, int height ) | |
164 | { return DoSetItemMinSize( sizer, width, height ); } | |
165 | bool SetItemMinSize( wxSizer *sizer, wxSize size ) | |
166 | { return DoSetItemMinSize( sizer, size.x, size.y ); } | |
167 | ||
168 | bool SetItemMinSize( int pos, int width, int height ) | |
169 | { return DoSetItemMinSize( pos, width, height ); } | |
170 | bool SetItemMinSize( int pos, wxSize size ) | |
171 | { return DoSetItemMinSize( pos, size.x, size.y ); } | |
172 | ||
173 | wxSize GetSize() | |
174 | { return m_size; } | |
175 | wxPoint GetPosition() | |
176 | { return m_position; } | |
177 | ||
178 | /* Calculate the minimal size or return m_minSize if bigger. */ | |
179 | wxSize GetMinSize(); | |
180 | ||
181 | virtual void RecalcSizes() = 0; | |
182 | virtual wxSize CalcMin() = 0; | |
183 | ||
184 | virtual void Layout(); | |
185 | ||
186 | void Fit( wxWindow *window ); | |
187 | void SetSizeHints( wxWindow *window ); | |
188 | ||
189 | wxList& GetChildren() | |
190 | { return m_children; } | |
191 | ||
192 | void SetDimension( int x, int y, int width, int height ); | |
0c0d686f | 193 | |
f6bcfd97 BP |
194 | protected: |
195 | wxSize m_size; | |
196 | wxSize m_minSize; | |
197 | wxPoint m_position; | |
198 | wxList m_children; | |
199 | ||
65ba4113 | 200 | wxSize GetMaxWindowSize( wxWindow *window ); |
f6bcfd97 | 201 | wxSize GetMinWindowSize( wxWindow *window ); |
65ba4113 GT |
202 | wxSize FitSize( wxWindow *window ); |
203 | ||
f6bcfd97 BP |
204 | virtual void DoSetMinSize( int width, int height ); |
205 | virtual bool DoSetItemMinSize( wxWindow *window, int width, int height ); | |
206 | virtual bool DoSetItemMinSize( wxSizer *sizer, int width, int height ); | |
207 | virtual bool DoSetItemMinSize( int pos, int width, int height ); | |
208 | ||
209 | private: | |
210 | DECLARE_CLASS(wxSizer); | |
211 | }; | |
c62ac5b6 | 212 | |
f6bcfd97 BP |
213 | //--------------------------------------------------------------------------- |
214 | // wxGridSizer | |
215 | //--------------------------------------------------------------------------- | |
0c0d686f | 216 | |
f6bcfd97 BP |
217 | class WXDLLEXPORT wxGridSizer: public wxSizer |
218 | { | |
219 | public: | |
220 | wxGridSizer( int rows, int cols, int vgap, int hgap ); | |
221 | wxGridSizer( int cols, int vgap = 0, int hgap = 0 ); | |
222 | ||
223 | void RecalcSizes(); | |
224 | wxSize CalcMin(); | |
225 | ||
226 | void SetCols( int cols ) { m_cols = cols; } | |
227 | void SetRows( int rows ) { m_rows = rows; } | |
228 | void SetVGap( int gap ) { m_vgap = gap; } | |
229 | void SetHGap( int gap ) { m_hgap = gap; } | |
230 | int GetCols() { return m_cols; } | |
231 | int GetRows() { return m_rows; } | |
232 | int GetVGap() { return m_vgap; } | |
233 | int GetHGap() { return m_hgap; } | |
234 | ||
235 | protected: | |
236 | int m_rows; | |
237 | int m_cols; | |
238 | int m_vgap; | |
239 | int m_hgap; | |
240 | ||
241 | void SetItemBounds( wxSizerItem *item, int x, int y, int w, int h ); | |
242 | ||
243 | private: | |
244 | DECLARE_CLASS(wxGridSizer); | |
245 | }; | |
5279a24d | 246 | |
f6bcfd97 BP |
247 | //--------------------------------------------------------------------------- |
248 | // wxFlexGridSizer | |
249 | //--------------------------------------------------------------------------- | |
0c0d686f | 250 | |
f6bcfd97 BP |
251 | class WXDLLEXPORT wxFlexGridSizer: public wxGridSizer |
252 | { | |
253 | public: | |
254 | wxFlexGridSizer( int rows, int cols, int vgap, int hgap ); | |
255 | wxFlexGridSizer( int cols, int vgap = 0, int hgap = 0 ); | |
256 | ~wxFlexGridSizer(); | |
257 | ||
258 | void RecalcSizes(); | |
259 | wxSize CalcMin(); | |
260 | ||
261 | void AddGrowableRow( size_t idx ); | |
262 | void RemoveGrowableRow( size_t idx ); | |
263 | void AddGrowableCol( size_t idx ); | |
264 | void RemoveGrowableCol( size_t idx ); | |
0c0d686f | 265 | |
c62ac5b6 | 266 | protected: |
f6bcfd97 BP |
267 | int *m_rowHeights; |
268 | int *m_colWidths; | |
269 | wxArrayInt m_growableRows; | |
270 | wxArrayInt m_growableCols; | |
271 | ||
272 | void CreateArrays(); | |
273 | ||
274 | private: | |
275 | DECLARE_CLASS(wxFlexGridSizer); | |
c62ac5b6 RR |
276 | }; |
277 | ||
278 | //--------------------------------------------------------------------------- | |
92afa2b1 | 279 | // wxBoxSizer |
c62ac5b6 RR |
280 | //--------------------------------------------------------------------------- |
281 | ||
92afa2b1 | 282 | class WXDLLEXPORT wxBoxSizer: public wxSizer |
61d514bb RR |
283 | { |
284 | public: | |
f6bcfd97 | 285 | wxBoxSizer( int orient ); |
0c0d686f | 286 | |
f6bcfd97 BP |
287 | void RecalcSizes(); |
288 | wxSize CalcMin(); | |
0c0d686f | 289 | |
f6bcfd97 BP |
290 | int GetOrientation() |
291 | { return m_orient; } | |
0c0d686f | 292 | |
61d514bb RR |
293 | protected: |
294 | int m_orient; | |
295 | int m_stretchable; | |
296 | int m_minWidth; | |
297 | int m_minHeight; | |
298 | int m_fixedWidth; | |
299 | int m_fixedHeight; | |
f6bcfd97 BP |
300 | |
301 | private: | |
302 | DECLARE_CLASS(wxBoxSizer); | |
61d514bb | 303 | }; |
0c0d686f | 304 | |
27ea1d8a RR |
305 | //--------------------------------------------------------------------------- |
306 | // wxStaticBoxSizer | |
307 | //--------------------------------------------------------------------------- | |
308 | ||
309 | class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer | |
310 | { | |
311 | public: | |
f6bcfd97 | 312 | wxStaticBoxSizer( wxStaticBox *box, int orient ); |
0c0d686f | 313 | |
f6bcfd97 BP |
314 | void RecalcSizes(); |
315 | wxSize CalcMin(); | |
0c0d686f | 316 | |
f6bcfd97 BP |
317 | wxStaticBox *GetStaticBox() |
318 | { return m_staticBox; } | |
0c0d686f | 319 | |
27ea1d8a | 320 | protected: |
f6bcfd97 BP |
321 | wxStaticBox *m_staticBox; |
322 | ||
323 | private: | |
324 | DECLARE_CLASS(wxStaticBoxSizer); | |
27ea1d8a RR |
325 | }; |
326 | ||
83edc0a5 RR |
327 | //--------------------------------------------------------------------------- |
328 | // wxNotebookSizer | |
329 | //--------------------------------------------------------------------------- | |
330 | ||
65e4f9b9 VS |
331 | #if wxUSE_NOTEBOOK |
332 | ||
83edc0a5 RR |
333 | class WXDLLEXPORT wxNotebookSizer: public wxSizer |
334 | { | |
83edc0a5 | 335 | public: |
f6bcfd97 | 336 | wxNotebookSizer( wxNotebook *nb ); |
83edc0a5 | 337 | |
f6bcfd97 BP |
338 | void RecalcSizes(); |
339 | wxSize CalcMin(); | |
83edc0a5 | 340 | |
f6bcfd97 BP |
341 | wxNotebook *GetNotebook() |
342 | { return m_notebook; } | |
83edc0a5 RR |
343 | |
344 | protected: | |
f6bcfd97 BP |
345 | wxNotebook *m_notebook; |
346 | ||
347 | private: | |
348 | DECLARE_CLASS(wxNotebookSizer); | |
83edc0a5 RR |
349 | }; |
350 | ||
65e4f9b9 VS |
351 | #endif |
352 | ||
353 | ||
5279a24d RR |
354 | #endif |
355 | // __WXSIZER_H__ |