]>
Commit | Line | Data |
---|---|---|
5279a24d RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: sizer.h | |
0c0d686f | 3 | // Purpose: provide wxSizer class for layouting |
5279a24d | 4 | // Author: Robert Roebling and Robin Dunn |
566d84a7 | 5 | // Modified by: Ron Lee |
0c0d686f | 6 | // Created: |
5279a24d RR |
7 | // RCS-ID: $Id$ |
8 | // Copyright: (c) Robin Dunn, Dirk Holtwick and Robert Roebling | |
12a3f227 | 9 | // (c) 2003, Ron Lee |
5279a24d RR |
10 | // Licence: wxWindows licence |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | #ifndef __WXSIZER_H__ | |
14 | #define __WXSIZER_H__ | |
15 | ||
af49c4b8 | 16 | #if defined(__GNUG__) && !defined(__APPLE__) |
5279a24d RR |
17 | #pragma interface "sizer.h" |
18 | #endif | |
19 | ||
20 | #include "wx/defs.h" | |
21 | ||
22 | #include "wx/window.h" | |
23 | #include "wx/frame.h" | |
24 | #include "wx/dialog.h" | |
25 | ||
26 | //--------------------------------------------------------------------------- | |
27 | // classes | |
28 | //--------------------------------------------------------------------------- | |
29 | ||
3417c2cd RR |
30 | class wxSizerItem; |
31 | class wxSizer; | |
92afa2b1 | 32 | class wxBoxSizer; |
5279a24d RR |
33 | |
34 | //--------------------------------------------------------------------------- | |
3417c2cd | 35 | // wxSizerItem |
5279a24d RR |
36 | //--------------------------------------------------------------------------- |
37 | ||
3417c2cd | 38 | class WXDLLEXPORT wxSizerItem: public wxObject |
5279a24d RR |
39 | { |
40 | public: | |
df5ddbca | 41 | // spacer |
12a3f227 RL |
42 | wxSizerItem( int width, |
43 | int height, | |
44 | int proportion, | |
45 | int flag, | |
46 | int border, | |
47 | wxObject* userData); | |
df5ddbca RR |
48 | |
49 | // window | |
12a3f227 RL |
50 | wxSizerItem( wxWindow *window, |
51 | int proportion, | |
52 | int flag, | |
53 | int border, | |
54 | wxObject* userData ); | |
df5ddbca RR |
55 | |
56 | // subsizer | |
12a3f227 RL |
57 | wxSizerItem( wxSizer *sizer, |
58 | int proportion, | |
59 | int flag, | |
60 | int border, | |
61 | wxObject* userData ); | |
df5ddbca RR |
62 | |
63 | ~wxSizerItem(); | |
84f7908b RR |
64 | |
65 | virtual void DeleteWindows(); | |
df5ddbca | 66 | |
96fdbb60 RL |
67 | // Enable deleting the SizerItem without destroying the contained sizer. |
68 | void DetachSizer() | |
69 | { m_sizer = 0; } | |
70 | ||
df5ddbca RR |
71 | virtual wxSize GetSize(); |
72 | virtual wxSize CalcMin(); | |
73 | virtual void SetDimension( wxPoint pos, wxSize size ); | |
74 | ||
75 | wxSize GetMinSize() | |
76 | { return m_minSize; } | |
12a3f227 RL |
77 | void SetInitSize( int x, int y ) |
78 | { m_minSize.x = x; m_minSize.y = y; } | |
df5ddbca RR |
79 | |
80 | void SetRatio( int width, int height ) | |
81 | // if either of dimensions is zero, ratio is assumed to be 1 | |
82 | // to avoid "divide by zero" errors | |
83 | { m_ratio = (width && height) ? ((float) width / (float) height) : 1; } | |
84 | void SetRatio( wxSize size ) | |
85 | { m_ratio = (size.x && size.y) ? ((float) size.x / (float) size.y) : 1; } | |
2aab8f16 | 86 | void SetRatio( float ratio ) |
df5ddbca | 87 | { m_ratio = ratio; } |
2aab8f16 | 88 | float GetRatio() const |
df5ddbca RR |
89 | { return m_ratio; } |
90 | ||
91 | bool IsWindow(); | |
92 | bool IsSizer(); | |
93 | bool IsSpacer(); | |
2aab8f16 | 94 | |
12a3f227 RL |
95 | // Deprecated in 2.6, use {G,S}etProportion instead. |
96 | wxDEPRECATED( void SetOption( int option ) ); | |
97 | wxDEPRECATED( int GetOption() const ); | |
98 | ||
99 | void SetProportion( int proportion ) | |
100 | { m_proportion = proportion; } | |
101 | int GetProportion() const | |
102 | { return m_proportion; } | |
df5ddbca RR |
103 | void SetFlag( int flag ) |
104 | { m_flag = flag; } | |
12a3f227 RL |
105 | int GetFlag() const |
106 | { return m_flag; } | |
df5ddbca RR |
107 | void SetBorder( int border ) |
108 | { m_border = border; } | |
12a3f227 RL |
109 | int GetBorder() const |
110 | { return m_border; } | |
df5ddbca RR |
111 | |
112 | wxWindow *GetWindow() const | |
113 | { return m_window; } | |
114 | void SetWindow( wxWindow *window ) | |
115 | { m_window = window; } | |
116 | wxSizer *GetSizer() const | |
117 | { return m_sizer; } | |
118 | void SetSizer( wxSizer *sizer ) | |
119 | { m_sizer = sizer; } | |
12a3f227 RL |
120 | const wxSize &GetSpacer() const |
121 | { return m_size; } | |
122 | void SetSpacer( const wxSize &size ) | |
123 | { m_size = size; m_minSize = size; } | |
124 | ||
125 | void Show ( bool show ); | |
2b5f62a0 VZ |
126 | bool IsShown() const |
127 | { return m_show; } | |
12a3f227 | 128 | |
df5ddbca RR |
129 | wxObject* GetUserData() |
130 | { return m_userData; } | |
131 | wxPoint GetPosition() | |
132 | { return m_pos; } | |
0c0d686f | 133 | |
c62ac5b6 | 134 | protected: |
df5ddbca RR |
135 | wxWindow *m_window; |
136 | wxSizer *m_sizer; | |
137 | wxSize m_size; | |
138 | wxPoint m_pos; | |
139 | wxSize m_minSize; | |
12a3f227 | 140 | int m_proportion; |
df5ddbca RR |
141 | int m_border; |
142 | int m_flag; | |
2b5f62a0 | 143 | |
12a3f227 | 144 | // If true, then this item is considered in the layout |
2b5f62a0 VZ |
145 | // calculation. Otherwise, it is skipped over. |
146 | bool m_show; | |
12a3f227 RL |
147 | |
148 | // Aspect ratio can always be calculated from m_size, | |
149 | // but this would cause precision loss when the window | |
150 | // is shrunk. It is safer to preserve the initial value. | |
df5ddbca | 151 | float m_ratio; |
2b5f62a0 | 152 | |
df5ddbca | 153 | wxObject *m_userData; |
2aab8f16 | 154 | |
12a3f227 | 155 | DECLARE_DYNAMIC_CLASS(wxSizerItem); |
22f3361e | 156 | DECLARE_NO_COPY_CLASS(wxSizerItem) |
c62ac5b6 | 157 | }; |
5279a24d | 158 | |
12a3f227 RL |
159 | WX_DECLARE_EXPORTED_LIST( wxSizerItem, wxSizerItemList ); |
160 | ||
161 | ||
5279a24d | 162 | //--------------------------------------------------------------------------- |
3417c2cd | 163 | // wxSizer |
5279a24d RR |
164 | //--------------------------------------------------------------------------- |
165 | ||
2aab8f16 | 166 | class WXDLLEXPORT wxSizer: public wxObject, public wxClientDataContainer |
5279a24d RR |
167 | { |
168 | public: | |
f6bcfd97 BP |
169 | wxSizer(); |
170 | ~wxSizer(); | |
171 | ||
172 | /* These should be called Append() really. */ | |
12a3f227 RL |
173 | virtual void Add( wxWindow *window, |
174 | int proportion = 0, | |
175 | int flag = 0, | |
176 | int border = 0, | |
177 | wxObject* userData = NULL ); | |
178 | virtual void Add( wxSizer *sizer, | |
179 | int proportion = 0, | |
180 | int flag = 0, | |
181 | int border = 0, | |
182 | wxObject* userData = NULL ); | |
183 | virtual void Add( int width, | |
184 | int height, | |
185 | int proportion = 0, | |
186 | int flag = 0, | |
187 | int border = 0, | |
188 | wxObject* userData = NULL ); | |
189 | virtual void Add( wxSizerItem *item ); | |
190 | ||
191 | virtual void Insert( size_t index, | |
192 | wxWindow *window, | |
193 | int proportion = 0, | |
194 | int flag = 0, | |
195 | int border = 0, | |
196 | wxObject* userData = NULL ); | |
197 | virtual void Insert( size_t index, | |
198 | wxSizer *sizer, | |
199 | int proportion = 0, | |
200 | int flag = 0, | |
201 | int border = 0, | |
202 | wxObject* userData = NULL ); | |
203 | virtual void Insert( size_t index, | |
204 | int width, | |
205 | int height, | |
206 | int proportion = 0, | |
207 | int flag = 0, | |
208 | int border = 0, | |
209 | wxObject* userData = NULL ); | |
210 | virtual void Insert( size_t index, | |
211 | wxSizerItem *item ); | |
212 | ||
213 | virtual void Prepend( wxWindow *window, | |
214 | int proportion = 0, | |
215 | int flag = 0, | |
216 | int border = 0, | |
217 | wxObject* userData = NULL ); | |
218 | virtual void Prepend( wxSizer *sizer, | |
219 | int proportion = 0, | |
220 | int flag = 0, | |
221 | int border = 0, | |
222 | wxObject* userData = NULL ); | |
223 | virtual void Prepend( int width, | |
224 | int height, | |
225 | int proportion = 0, | |
226 | int flag = 0, | |
227 | int border = 0, | |
228 | wxObject* userData = NULL ); | |
229 | virtual void Prepend( wxSizerItem *item ); | |
230 | ||
231 | // Deprecated in 2.6 since historically it does not delete the window, | |
232 | // use Detach instead. | |
233 | wxDEPRECATED( virtual bool Remove( wxWindow *window ) ); | |
f6bcfd97 | 234 | virtual bool Remove( wxSizer *sizer ); |
12a3f227 | 235 | virtual bool Remove( size_t index ); |
00976fe5 | 236 | |
12a3f227 | 237 | virtual bool Detach( wxWindow *window ); |
00976fe5 | 238 | virtual bool Detach( wxSizer *sizer ); |
12a3f227 | 239 | virtual bool Detach( size_t index ); |
00976fe5 | 240 | |
12a3f227 | 241 | virtual void Clear( bool delete_windows=false ); |
84f7908b | 242 | virtual void DeleteWindows(); |
f6bcfd97 BP |
243 | |
244 | void SetMinSize( int width, int height ) | |
245 | { DoSetMinSize( width, height ); } | |
246 | void SetMinSize( wxSize size ) | |
247 | { DoSetMinSize( size.x, size.y ); } | |
1e6feb95 | 248 | |
f6bcfd97 BP |
249 | /* Searches recursively */ |
250 | bool SetItemMinSize( wxWindow *window, int width, int height ) | |
251 | { return DoSetItemMinSize( window, width, height ); } | |
252 | bool SetItemMinSize( wxWindow *window, wxSize size ) | |
253 | { return DoSetItemMinSize( window, size.x, size.y ); } | |
1e6feb95 | 254 | |
f6bcfd97 BP |
255 | /* Searches recursively */ |
256 | bool SetItemMinSize( wxSizer *sizer, int width, int height ) | |
257 | { return DoSetItemMinSize( sizer, width, height ); } | |
258 | bool SetItemMinSize( wxSizer *sizer, wxSize size ) | |
259 | { return DoSetItemMinSize( sizer, size.x, size.y ); } | |
1e6feb95 | 260 | |
12a3f227 RL |
261 | bool SetItemMinSize( size_t index, int width, int height ) |
262 | { return DoSetItemMinSize( index, width, height ); } | |
263 | bool SetItemMinSize( size_t index, wxSize size ) | |
264 | { return DoSetItemMinSize( index, size.x, size.y ); } | |
1e6feb95 | 265 | |
f6bcfd97 BP |
266 | wxSize GetSize() |
267 | { return m_size; } | |
268 | wxPoint GetPosition() | |
269 | { return m_position; } | |
1e6feb95 | 270 | |
f6bcfd97 BP |
271 | /* Calculate the minimal size or return m_minSize if bigger. */ |
272 | wxSize GetMinSize(); | |
273 | ||
274 | virtual void RecalcSizes() = 0; | |
275 | virtual wxSize CalcMin() = 0; | |
276 | ||
277 | virtual void Layout(); | |
278 | ||
e5251d4f | 279 | wxSize Fit( wxWindow *window ); |
566d84a7 | 280 | void FitInside( wxWindow *window ); |
f6bcfd97 | 281 | void SetSizeHints( wxWindow *window ); |
566d84a7 | 282 | void SetVirtualSizeHints( wxWindow *window ); |
f6bcfd97 | 283 | |
12a3f227 | 284 | wxSizerItemList& GetChildren() |
f6bcfd97 BP |
285 | { return m_children; } |
286 | ||
287 | void SetDimension( int x, int y, int width, int height ); | |
0c0d686f | 288 | |
12a3f227 | 289 | // Manage whether individual scene items are considered |
2b5f62a0 | 290 | // in the layout calculations or not. |
12a3f227 RL |
291 | void Show( wxWindow *window, bool show = true ); |
292 | void Show( wxSizer *sizer, bool show = true ); | |
293 | void Show( size_t index, bool show = true ); | |
294 | ||
2b5f62a0 | 295 | void Hide( wxSizer *sizer ) |
12a3f227 RL |
296 | { Show( sizer, false ); } |
297 | void Hide( wxWindow *window ) | |
298 | { Show( window, false ); } | |
299 | void Hide( size_t index ) | |
300 | { Show( index, false ); } | |
2b5f62a0 VZ |
301 | |
302 | bool IsShown( wxWindow *window ); | |
303 | bool IsShown( wxSizer *sizer ); | |
12a3f227 | 304 | bool IsShown( size_t index ); |
2b5f62a0 VZ |
305 | |
306 | // Recursively call wxWindow::Show () on all sizer items. | |
307 | void ShowItems (bool show); | |
308 | ||
f6bcfd97 | 309 | protected: |
12a3f227 RL |
310 | wxSize m_size; |
311 | wxSize m_minSize; | |
312 | wxPoint m_position; | |
313 | wxSizerItemList m_children; | |
f6bcfd97 | 314 | |
65ba4113 | 315 | wxSize GetMaxWindowSize( wxWindow *window ); |
f6bcfd97 | 316 | wxSize GetMinWindowSize( wxWindow *window ); |
566d84a7 RL |
317 | wxSize GetMaxClientSize( wxWindow *window ); |
318 | wxSize GetMinClientSize( wxWindow *window ); | |
65ba4113 | 319 | wxSize FitSize( wxWindow *window ); |
566d84a7 | 320 | wxSize VirtualFitSize( wxWindow *window ); |
65ba4113 | 321 | |
f6bcfd97 BP |
322 | virtual void DoSetMinSize( int width, int height ); |
323 | virtual bool DoSetItemMinSize( wxWindow *window, int width, int height ); | |
324 | virtual bool DoSetItemMinSize( wxSizer *sizer, int width, int height ); | |
12a3f227 | 325 | virtual bool DoSetItemMinSize( size_t index, int width, int height ); |
1e6feb95 | 326 | |
12a3f227 | 327 | DECLARE_DYNAMIC_CLASS(wxSizer); |
f6bcfd97 | 328 | }; |
c62ac5b6 | 329 | |
f6bcfd97 BP |
330 | //--------------------------------------------------------------------------- |
331 | // wxGridSizer | |
332 | //--------------------------------------------------------------------------- | |
0c0d686f | 333 | |
f6bcfd97 BP |
334 | class WXDLLEXPORT wxGridSizer: public wxSizer |
335 | { | |
336 | public: | |
337 | wxGridSizer( int rows, int cols, int vgap, int hgap ); | |
338 | wxGridSizer( int cols, int vgap = 0, int hgap = 0 ); | |
1e6feb95 | 339 | |
f6bcfd97 BP |
340 | void RecalcSizes(); |
341 | wxSize CalcMin(); | |
342 | ||
343 | void SetCols( int cols ) { m_cols = cols; } | |
344 | void SetRows( int rows ) { m_rows = rows; } | |
345 | void SetVGap( int gap ) { m_vgap = gap; } | |
346 | void SetHGap( int gap ) { m_hgap = gap; } | |
347 | int GetCols() { return m_cols; } | |
348 | int GetRows() { return m_rows; } | |
349 | int GetVGap() { return m_vgap; } | |
350 | int GetHGap() { return m_hgap; } | |
1e6feb95 | 351 | |
f6bcfd97 BP |
352 | protected: |
353 | int m_rows; | |
354 | int m_cols; | |
355 | int m_vgap; | |
356 | int m_hgap; | |
1e6feb95 | 357 | |
0ca5105b VZ |
358 | // return the number of total items and the number of columns and rows |
359 | int CalcRowsCols(int& rows, int& cols) const; | |
360 | ||
f6bcfd97 | 361 | void SetItemBounds( wxSizerItem *item, int x, int y, int w, int h ); |
1e6feb95 | 362 | |
12a3f227 | 363 | DECLARE_DYNAMIC_CLASS(wxGridSizer); |
f6bcfd97 | 364 | }; |
5279a24d | 365 | |
f6bcfd97 BP |
366 | //--------------------------------------------------------------------------- |
367 | // wxFlexGridSizer | |
368 | //--------------------------------------------------------------------------- | |
0c0d686f | 369 | |
f6bcfd97 BP |
370 | class WXDLLEXPORT wxFlexGridSizer: public wxGridSizer |
371 | { | |
372 | public: | |
373 | wxFlexGridSizer( int rows, int cols, int vgap, int hgap ); | |
374 | wxFlexGridSizer( int cols, int vgap = 0, int hgap = 0 ); | |
375 | ~wxFlexGridSizer(); | |
1e6feb95 | 376 | |
f6bcfd97 BP |
377 | void RecalcSizes(); |
378 | wxSize CalcMin(); | |
1e6feb95 | 379 | |
f6bcfd97 BP |
380 | void AddGrowableRow( size_t idx ); |
381 | void RemoveGrowableRow( size_t idx ); | |
382 | void AddGrowableCol( size_t idx ); | |
383 | void RemoveGrowableCol( size_t idx ); | |
0c0d686f | 384 | |
c62ac5b6 | 385 | protected: |
f6bcfd97 BP |
386 | int *m_rowHeights; |
387 | int *m_colWidths; | |
388 | wxArrayInt m_growableRows; | |
389 | wxArrayInt m_growableCols; | |
1e6feb95 | 390 | |
f6bcfd97 | 391 | void CreateArrays(); |
1e6feb95 | 392 | |
12a3f227 | 393 | DECLARE_DYNAMIC_CLASS(wxFlexGridSizer); |
22f3361e | 394 | DECLARE_NO_COPY_CLASS(wxFlexGridSizer) |
c62ac5b6 RR |
395 | }; |
396 | ||
397 | //--------------------------------------------------------------------------- | |
92afa2b1 | 398 | // wxBoxSizer |
c62ac5b6 RR |
399 | //--------------------------------------------------------------------------- |
400 | ||
92afa2b1 | 401 | class WXDLLEXPORT wxBoxSizer: public wxSizer |
61d514bb RR |
402 | { |
403 | public: | |
f6bcfd97 | 404 | wxBoxSizer( int orient ); |
0c0d686f | 405 | |
f6bcfd97 BP |
406 | void RecalcSizes(); |
407 | wxSize CalcMin(); | |
0c0d686f | 408 | |
f6bcfd97 BP |
409 | int GetOrientation() |
410 | { return m_orient; } | |
0c0d686f | 411 | |
b657b4c9 JS |
412 | void SetOrientation(int orient) |
413 | { m_orient = orient; } | |
414 | ||
61d514bb RR |
415 | protected: |
416 | int m_orient; | |
417 | int m_stretchable; | |
418 | int m_minWidth; | |
419 | int m_minHeight; | |
420 | int m_fixedWidth; | |
421 | int m_fixedHeight; | |
1e6feb95 | 422 | |
12a3f227 | 423 | DECLARE_DYNAMIC_CLASS(wxBoxSizer); |
61d514bb | 424 | }; |
0c0d686f | 425 | |
27ea1d8a RR |
426 | //--------------------------------------------------------------------------- |
427 | // wxStaticBoxSizer | |
428 | //--------------------------------------------------------------------------- | |
429 | ||
1e6feb95 VZ |
430 | #if wxUSE_STATBOX |
431 | ||
432 | class WXDLLEXPORT wxStaticBox; | |
433 | ||
27ea1d8a RR |
434 | class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer |
435 | { | |
436 | public: | |
f6bcfd97 | 437 | wxStaticBoxSizer( wxStaticBox *box, int orient ); |
0c0d686f | 438 | |
f6bcfd97 BP |
439 | void RecalcSizes(); |
440 | wxSize CalcMin(); | |
0c0d686f | 441 | |
f6bcfd97 BP |
442 | wxStaticBox *GetStaticBox() |
443 | { return m_staticBox; } | |
0c0d686f | 444 | |
27ea1d8a | 445 | protected: |
f6bcfd97 | 446 | wxStaticBox *m_staticBox; |
1e6feb95 | 447 | |
12a3f227 | 448 | DECLARE_DYNAMIC_CLASS(wxStaticBoxSizer); |
22f3361e | 449 | DECLARE_NO_COPY_CLASS(wxStaticBoxSizer) |
27ea1d8a RR |
450 | }; |
451 | ||
1e6feb95 VZ |
452 | #endif // wxUSE_STATBOX |
453 | ||
83edc0a5 RR |
454 | //--------------------------------------------------------------------------- |
455 | // wxNotebookSizer | |
456 | //--------------------------------------------------------------------------- | |
457 | ||
65e4f9b9 VS |
458 | #if wxUSE_NOTEBOOK |
459 | ||
1e6feb95 VZ |
460 | class WXDLLEXPORT wxNotebook; |
461 | ||
83edc0a5 RR |
462 | class WXDLLEXPORT wxNotebookSizer: public wxSizer |
463 | { | |
83edc0a5 | 464 | public: |
f6bcfd97 | 465 | wxNotebookSizer( wxNotebook *nb ); |
83edc0a5 | 466 | |
f6bcfd97 BP |
467 | void RecalcSizes(); |
468 | wxSize CalcMin(); | |
83edc0a5 | 469 | |
f6bcfd97 BP |
470 | wxNotebook *GetNotebook() |
471 | { return m_notebook; } | |
83edc0a5 RR |
472 | |
473 | protected: | |
f6bcfd97 | 474 | wxNotebook *m_notebook; |
1e6feb95 | 475 | |
12a3f227 | 476 | DECLARE_DYNAMIC_CLASS(wxNotebookSizer); |
22f3361e | 477 | DECLARE_NO_COPY_CLASS(wxNotebookSizer) |
83edc0a5 RR |
478 | }; |
479 | ||
1e6feb95 | 480 | #endif // wxUSE_NOTEBOOK |
65e4f9b9 VS |
481 | |
482 | ||
5279a24d RR |
483 | #endif |
484 | // __WXSIZER_H__ |