]>
Commit | Line | Data |
---|---|---|
5279a24d RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: sizer.h | |
a4ab8ed5 | 3 | // Purpose: provide wxSizer class for layout |
5279a24d | 4 | // Author: Robert Roebling and Robin Dunn |
5f813ad6 | 5 | // Modified by: Ron Lee, Vadim Zeitlin (wxSizerFlags) |
0c0d686f | 6 | // Created: |
5279a24d | 7 | // RCS-ID: $Id$ |
a4ab8ed5 | 8 | // Copyright: (c) Robin Dunn, Robert Roebling |
65571936 | 9 | // Licence: wxWindows licence |
5279a24d RR |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef __WXSIZER_H__ | |
13 | #define __WXSIZER_H__ | |
14 | ||
5279a24d RR |
15 | #include "wx/defs.h" |
16 | ||
acf2ac37 | 17 | #include "wx/button.h" |
5279a24d RR |
18 | #include "wx/window.h" |
19 | #include "wx/frame.h" | |
20 | #include "wx/dialog.h" | |
21 | ||
22 | //--------------------------------------------------------------------------- | |
23 | // classes | |
24 | //--------------------------------------------------------------------------- | |
25 | ||
446e5259 VS |
26 | class WXDLLEXPORT wxSizerItem; |
27 | class WXDLLEXPORT wxSizer; | |
28 | class WXDLLEXPORT wxBoxSizer; | |
5279a24d | 29 | |
5f813ad6 VZ |
30 | |
31 | // ---------------------------------------------------------------------------- | |
32 | // wxSizerFlags: flags used for an item in the sizer | |
33 | // ---------------------------------------------------------------------------- | |
34 | ||
35 | class WXDLLEXPORT wxSizerFlags | |
36 | { | |
37 | public: | |
38 | // construct the flags object initialized with the given proportion (0 by | |
39 | // default) | |
40 | wxSizerFlags(int proportion = 0) : m_proportion(proportion) | |
41 | { | |
42 | m_flags = 0; | |
43 | m_borderInPixels = 0; | |
44 | } | |
45 | ||
46 | // setters for all sizer flags, they all return the object itself so that | |
47 | // calls to them can be chained | |
48 | ||
49 | wxSizerFlags& Proportion(int proportion) | |
50 | { | |
51 | m_proportion = proportion; | |
52 | return *this; | |
53 | } | |
54 | ||
55 | wxSizerFlags& Align(int alignment) // combination of wxAlignment values | |
56 | { | |
57 | m_flags &= wxALL; | |
58 | m_flags |= alignment; | |
59 | ||
60 | return *this; | |
61 | } | |
62 | ||
63 | // some shortcuts for Align() | |
64 | wxSizerFlags& Expand() { return Align(wxEXPAND); } | |
65 | wxSizerFlags& Centre() { return Align(wxCENTRE); } | |
66 | wxSizerFlags& Center() { return Centre(); } | |
e72ac082 VZ |
67 | wxSizerFlags& Left() { return Align(wxALIGN_LEFT); } |
68 | wxSizerFlags& Right() { return Align(wxALIGN_RIGHT); } | |
5f813ad6 VZ |
69 | |
70 | ||
71 | wxSizerFlags& Border(int direction, int borderInPixels) | |
72 | { | |
73 | m_flags &= ~wxALL; | |
74 | m_flags |= direction; | |
75 | ||
76 | m_borderInPixels = borderInPixels; | |
77 | ||
78 | return *this; | |
79 | } | |
80 | ||
81 | wxSizerFlags& Border(int direction = wxALL) | |
82 | { | |
83 | // FIXME: default border size shouldn't be hardcoded | |
92b0cd9e VZ |
84 | #ifdef __SMARTPHONE__ |
85 | // no borders by default on limited size screen | |
86 | wxUnusedVar(direction); | |
87 | ||
88 | return *this; | |
89 | #else | |
5f813ad6 | 90 | return Border(direction, 5); |
92b0cd9e | 91 | #endif |
5f813ad6 VZ |
92 | } |
93 | ||
94 | ||
95 | // accessors for wxSizer only | |
96 | int GetProportion() const { return m_proportion; } | |
97 | int GetFlags() const { return m_flags; } | |
98 | int GetBorderInPixels() const { return m_borderInPixels; } | |
99 | ||
100 | private: | |
101 | int m_proportion; | |
102 | int m_flags; | |
103 | int m_borderInPixels; | |
104 | }; | |
105 | ||
106 | ||
50c06297 VZ |
107 | // ---------------------------------------------------------------------------- |
108 | // wxSizerSpacer: used by wxSizerItem to represent a spacer | |
109 | // ---------------------------------------------------------------------------- | |
5279a24d | 110 | |
50c06297 | 111 | class WXDLLEXPORT wxSizerSpacer |
5279a24d RR |
112 | { |
113 | public: | |
50c06297 | 114 | wxSizerSpacer(const wxSize& size) : m_size(size), m_isShown(true) { } |
5f813ad6 | 115 | |
50c06297 VZ |
116 | void SetSize(const wxSize& size) { m_size = size; } |
117 | const wxSize& GetSize() const { return m_size; } | |
5f813ad6 | 118 | |
50c06297 VZ |
119 | void Show(bool show) { m_isShown = show; } |
120 | bool IsShown() const { return m_isShown; } | |
5f813ad6 | 121 | |
50c06297 VZ |
122 | private: |
123 | // the size, in pixel | |
124 | wxSize m_size; | |
df5ddbca | 125 | |
50c06297 VZ |
126 | // is the spacer currently shown? |
127 | bool m_isShown; | |
128 | }; | |
129 | ||
130 | // ---------------------------------------------------------------------------- | |
131 | // wxSizerItem | |
132 | // ---------------------------------------------------------------------------- | |
133 | ||
134 | class WXDLLEXPORT wxSizerItem : public wxObject | |
135 | { | |
136 | public: | |
df5ddbca | 137 | // window |
12a3f227 RL |
138 | wxSizerItem( wxWindow *window, |
139 | int proportion, | |
140 | int flag, | |
141 | int border, | |
142 | wxObject* userData ); | |
df5ddbca | 143 | |
50c06297 VZ |
144 | // window with flags |
145 | wxSizerItem(wxWindow *window, const wxSizerFlags& flags) | |
146 | { | |
147 | Init(flags); | |
148 | ||
149 | SetWindow(window); | |
150 | } | |
151 | ||
df5ddbca | 152 | // subsizer |
12a3f227 RL |
153 | wxSizerItem( wxSizer *sizer, |
154 | int proportion, | |
155 | int flag, | |
156 | int border, | |
157 | wxObject* userData ); | |
df5ddbca | 158 | |
50c06297 VZ |
159 | // sizer with flags |
160 | wxSizerItem(wxSizer *sizer, const wxSizerFlags& flags) | |
161 | { | |
162 | Init(flags); | |
163 | ||
164 | SetSizer(sizer); | |
165 | } | |
166 | ||
5f813ad6 VZ |
167 | // spacer |
168 | wxSizerItem( int width, | |
169 | int height, | |
170 | int proportion, | |
171 | int flag, | |
172 | int border, | |
173 | wxObject* userData); | |
174 | ||
50c06297 VZ |
175 | // spacer with flags |
176 | wxSizerItem(int width, int height, const wxSizerFlags& flags) | |
177 | { | |
178 | Init(flags); | |
179 | ||
180 | SetSpacer(width, height); | |
181 | } | |
182 | ||
20b35a69 RD |
183 | wxSizerItem(); |
184 | virtual ~wxSizerItem(); | |
dc259b79 | 185 | |
84f7908b | 186 | virtual void DeleteWindows(); |
df5ddbca | 187 | |
96fdbb60 | 188 | // Enable deleting the SizerItem without destroying the contained sizer. |
50c06297 | 189 | void DetachSizer() { m_sizer = NULL; } |
96fdbb60 | 190 | |
9cbee2ce | 191 | virtual wxSize GetSize() const; |
df5ddbca | 192 | virtual wxSize CalcMin(); |
fbfb8bcc | 193 | virtual void SetDimension( const wxPoint& pos, const wxSize& size ); |
df5ddbca | 194 | |
9cbee2ce | 195 | wxSize GetMinSize() const |
df5ddbca | 196 | { return m_minSize; } |
ba763a45 RD |
197 | wxSize GetMinSizeWithBorder() const; |
198 | ||
1eba2193 | 199 | void SetMinSize(const wxSize& size) |
50c06297 VZ |
200 | { |
201 | if ( IsWindow() ) | |
202 | m_window->SetMinSize(size); | |
203 | m_minSize = size; | |
204 | } | |
1eba2193 | 205 | void SetMinSize( int x, int y ) |
8b2bac62 | 206 | { SetMinSize(wxSize(x, y)); } |
12a3f227 | 207 | void SetInitSize( int x, int y ) |
1eba2193 | 208 | { SetMinSize(wxSize(x, y)); } |
df5ddbca | 209 | |
50c06297 VZ |
210 | // if either of dimensions is zero, ratio is assumed to be 1 |
211 | // to avoid "divide by zero" errors | |
212 | void SetRatio(int width, int height) | |
df5ddbca | 213 | { m_ratio = (width && height) ? ((float) width / (float) height) : 1; } |
50c06297 VZ |
214 | void SetRatio(const wxSize& size) |
215 | { SetRatio(size.x, size.y); } | |
216 | void SetRatio(float ratio) | |
df5ddbca | 217 | { m_ratio = ratio; } |
2aab8f16 | 218 | float GetRatio() const |
df5ddbca RR |
219 | { return m_ratio; } |
220 | ||
50c06297 | 221 | virtual wxRect GetRect() { return m_rect; } |
56eee37f | 222 | |
50c06297 VZ |
223 | bool IsWindow() const { return m_kind == Item_Window; } |
224 | bool IsSizer() const { return m_kind == Item_Sizer; } | |
225 | bool IsSpacer() const { return m_kind == Item_Spacer; } | |
2aab8f16 | 226 | |
12a3f227 RL |
227 | // Deprecated in 2.6, use {G,S}etProportion instead. |
228 | wxDEPRECATED( void SetOption( int option ) ); | |
229 | wxDEPRECATED( int GetOption() const ); | |
230 | ||
231 | void SetProportion( int proportion ) | |
232 | { m_proportion = proportion; } | |
233 | int GetProportion() const | |
234 | { return m_proportion; } | |
df5ddbca RR |
235 | void SetFlag( int flag ) |
236 | { m_flag = flag; } | |
12a3f227 RL |
237 | int GetFlag() const |
238 | { return m_flag; } | |
df5ddbca RR |
239 | void SetBorder( int border ) |
240 | { m_border = border; } | |
12a3f227 RL |
241 | int GetBorder() const |
242 | { return m_border; } | |
df5ddbca RR |
243 | |
244 | wxWindow *GetWindow() const | |
50c06297 | 245 | { return m_kind == Item_Window ? m_window : NULL; } |
df5ddbca | 246 | wxSizer *GetSizer() const |
50c06297 VZ |
247 | { return m_kind == Item_Sizer ? m_sizer : NULL; } |
248 | wxSize GetSpacer() const; | |
12a3f227 | 249 | |
50c06297 VZ |
250 | void Show(bool show); |
251 | bool IsShown() const; | |
12a3f227 | 252 | |
9cbee2ce | 253 | wxObject* GetUserData() const |
df5ddbca | 254 | { return m_userData; } |
9cbee2ce | 255 | wxPoint GetPosition() const |
df5ddbca | 256 | { return m_pos; } |
0c0d686f | 257 | |
50c06297 VZ |
258 | |
259 | // these functions do not free old sizer/spacer | |
260 | void SetWindow(wxWindow *window); | |
261 | void SetSizer(wxSizer *sizer); | |
262 | void SetSpacer(const wxSize& size); | |
263 | void SetSpacer(int width, int height) { SetSpacer(wxSize(width, height)); } | |
264 | ||
c62ac5b6 | 265 | protected: |
5f813ad6 | 266 | // common part of several ctors |
50c06297 | 267 | void Init() { m_userData = NULL; } |
5f813ad6 VZ |
268 | |
269 | // common part of ctors taking wxSizerFlags | |
270 | void Init(const wxSizerFlags& flags); | |
271 | ||
50c06297 VZ |
272 | enum |
273 | { | |
274 | Item_None, | |
275 | Item_Window, | |
276 | Item_Sizer, | |
277 | Item_Spacer, | |
278 | Item_Max | |
279 | } m_kind; | |
280 | union | |
281 | { | |
282 | wxWindow *m_window; | |
283 | wxSizer *m_sizer; | |
284 | wxSizerSpacer *m_spacer; | |
285 | }; | |
5f813ad6 | 286 | |
df5ddbca RR |
287 | wxPoint m_pos; |
288 | wxSize m_minSize; | |
12a3f227 | 289 | int m_proportion; |
df5ddbca RR |
290 | int m_border; |
291 | int m_flag; | |
2b5f62a0 | 292 | |
50c06297 VZ |
293 | // on screen rectangle of this item (not including borders) |
294 | wxRect m_rect; | |
12a3f227 RL |
295 | |
296 | // Aspect ratio can always be calculated from m_size, | |
297 | // but this would cause precision loss when the window | |
298 | // is shrunk. It is safer to preserve the initial value. | |
df5ddbca | 299 | float m_ratio; |
2b5f62a0 | 300 | |
df5ddbca | 301 | wxObject *m_userData; |
2aab8f16 | 302 | |
9cbee2ce | 303 | private: |
4393b50c | 304 | DECLARE_CLASS(wxSizerItem) |
22f3361e | 305 | DECLARE_NO_COPY_CLASS(wxSizerItem) |
c62ac5b6 | 306 | }; |
5279a24d | 307 | |
12a3f227 RL |
308 | WX_DECLARE_EXPORTED_LIST( wxSizerItem, wxSizerItemList ); |
309 | ||
5f813ad6 | 310 | |
5279a24d | 311 | //--------------------------------------------------------------------------- |
3417c2cd | 312 | // wxSizer |
5279a24d RR |
313 | //--------------------------------------------------------------------------- |
314 | ||
2aab8f16 | 315 | class WXDLLEXPORT wxSizer: public wxObject, public wxClientDataContainer |
5279a24d RR |
316 | { |
317 | public: | |
f6bcfd97 BP |
318 | wxSizer(); |
319 | ~wxSizer(); | |
320 | ||
436ae7cf VZ |
321 | // methods for adding elements to the sizer: there are Add/Insert/Prepend |
322 | // overloads for each of window/sizer/spacer/wxSizerItem | |
56eee37f WS |
323 | inline wxSizerItem* Add( wxWindow *window, |
324 | int proportion = 0, | |
325 | int flag = 0, | |
326 | int border = 0, | |
327 | wxObject* userData = NULL ); | |
328 | inline wxSizerItem* Add( wxSizer *sizer, | |
329 | int proportion = 0, | |
330 | int flag = 0, | |
331 | int border = 0, | |
332 | wxObject* userData = NULL ); | |
333 | inline wxSizerItem* Add( int width, | |
334 | int height, | |
335 | int proportion = 0, | |
336 | int flag = 0, | |
337 | int border = 0, | |
338 | wxObject* userData = NULL ); | |
339 | inline wxSizerItem* Add( wxWindow *window, const wxSizerFlags& flags ); | |
340 | inline wxSizerItem* Add( wxSizer *sizer, const wxSizerFlags& flags ); | |
341 | inline wxSizerItem* Add( wxSizerItem *item ); | |
342 | ||
343 | inline wxSizerItem* AddSpacer(int size); | |
344 | inline wxSizerItem* AddStretchSpacer(int prop = 1); | |
345 | ||
346 | inline wxSizerItem* Insert( size_t index, | |
347 | wxWindow *window, | |
348 | int proportion = 0, | |
349 | int flag = 0, | |
350 | int border = 0, | |
351 | wxObject* userData = NULL ); | |
352 | inline wxSizerItem* Insert( size_t index, | |
353 | wxSizer *sizer, | |
354 | int proportion = 0, | |
355 | int flag = 0, | |
356 | int border = 0, | |
357 | wxObject* userData = NULL ); | |
358 | inline wxSizerItem* Insert( size_t index, | |
359 | int width, | |
360 | int height, | |
361 | int proportion = 0, | |
362 | int flag = 0, | |
363 | int border = 0, | |
364 | wxObject* userData = NULL ); | |
365 | inline wxSizerItem* Insert( size_t index, | |
366 | wxWindow *window, | |
367 | const wxSizerFlags& flags ); | |
368 | inline wxSizerItem* Insert( size_t index, | |
369 | wxSizer *sizer, | |
370 | const wxSizerFlags& flags ); | |
371 | virtual wxSizerItem* Insert( size_t index, wxSizerItem *item ); | |
372 | ||
373 | inline wxSizerItem* InsertSpacer(size_t index, int size); | |
374 | inline wxSizerItem* InsertStretchSpacer(size_t index, int prop = 1); | |
375 | ||
376 | inline wxSizerItem* Prepend( wxWindow *window, | |
377 | int proportion = 0, | |
378 | int flag = 0, | |
379 | int border = 0, | |
380 | wxObject* userData = NULL ); | |
381 | inline wxSizerItem* Prepend( wxSizer *sizer, | |
382 | int proportion = 0, | |
383 | int flag = 0, | |
384 | int border = 0, | |
385 | wxObject* userData = NULL ); | |
386 | inline wxSizerItem* Prepend( int width, | |
387 | int height, | |
388 | int proportion = 0, | |
389 | int flag = 0, | |
390 | int border = 0, | |
391 | wxObject* userData = NULL ); | |
392 | inline wxSizerItem* Prepend( wxWindow *window, const wxSizerFlags& flags ); | |
393 | inline wxSizerItem* Prepend( wxSizer *sizer, const wxSizerFlags& flags ); | |
394 | inline wxSizerItem* Prepend( wxSizerItem *item ); | |
395 | ||
396 | inline wxSizerItem* PrependSpacer(int size); | |
397 | inline wxSizerItem* PrependStretchSpacer(int prop = 1); | |
8e32ea1c | 398 | |
749bb9f1 | 399 | |
12a3f227 RL |
400 | // Deprecated in 2.6 since historically it does not delete the window, |
401 | // use Detach instead. | |
402 | wxDEPRECATED( virtual bool Remove( wxWindow *window ) ); | |
f6bcfd97 | 403 | virtual bool Remove( wxSizer *sizer ); |
e0d8fb45 | 404 | virtual bool Remove( int index ); |
00976fe5 | 405 | |
12a3f227 | 406 | virtual bool Detach( wxWindow *window ); |
00976fe5 | 407 | virtual bool Detach( wxSizer *sizer ); |
e0d8fb45 | 408 | virtual bool Detach( int index ); |
00976fe5 | 409 | |
e0d8fb45 | 410 | virtual void Clear( bool delete_windows = false ); |
84f7908b | 411 | virtual void DeleteWindows(); |
f6bcfd97 BP |
412 | |
413 | void SetMinSize( int width, int height ) | |
414 | { DoSetMinSize( width, height ); } | |
fbfb8bcc | 415 | void SetMinSize( const wxSize& size ) |
f6bcfd97 | 416 | { DoSetMinSize( size.x, size.y ); } |
1e6feb95 | 417 | |
50c06297 | 418 | // Searches recursively |
f6bcfd97 BP |
419 | bool SetItemMinSize( wxWindow *window, int width, int height ) |
420 | { return DoSetItemMinSize( window, width, height ); } | |
fbfb8bcc | 421 | bool SetItemMinSize( wxWindow *window, const wxSize& size ) |
f6bcfd97 | 422 | { return DoSetItemMinSize( window, size.x, size.y ); } |
1e6feb95 | 423 | |
50c06297 | 424 | // Searches recursively |
f6bcfd97 BP |
425 | bool SetItemMinSize( wxSizer *sizer, int width, int height ) |
426 | { return DoSetItemMinSize( sizer, width, height ); } | |
fbfb8bcc | 427 | bool SetItemMinSize( wxSizer *sizer, const wxSize& size ) |
f6bcfd97 | 428 | { return DoSetItemMinSize( sizer, size.x, size.y ); } |
1e6feb95 | 429 | |
12a3f227 RL |
430 | bool SetItemMinSize( size_t index, int width, int height ) |
431 | { return DoSetItemMinSize( index, width, height ); } | |
fbfb8bcc | 432 | bool SetItemMinSize( size_t index, const wxSize& size ) |
12a3f227 | 433 | { return DoSetItemMinSize( index, size.x, size.y ); } |
1e6feb95 | 434 | |
9cbee2ce | 435 | wxSize GetSize() const |
f6bcfd97 | 436 | { return m_size; } |
9cbee2ce | 437 | wxPoint GetPosition() const |
f6bcfd97 | 438 | { return m_position; } |
1e6feb95 | 439 | |
50c06297 | 440 | // Calculate the minimal size or return m_minSize if bigger. |
f6bcfd97 BP |
441 | wxSize GetMinSize(); |
442 | ||
443 | virtual void RecalcSizes() = 0; | |
444 | virtual wxSize CalcMin() = 0; | |
445 | ||
446 | virtual void Layout(); | |
447 | ||
e5251d4f | 448 | wxSize Fit( wxWindow *window ); |
566d84a7 | 449 | void FitInside( wxWindow *window ); |
f6bcfd97 | 450 | void SetSizeHints( wxWindow *window ); |
566d84a7 | 451 | void SetVirtualSizeHints( wxWindow *window ); |
f6bcfd97 | 452 | |
12a3f227 | 453 | wxSizerItemList& GetChildren() |
f6bcfd97 BP |
454 | { return m_children; } |
455 | ||
456 | void SetDimension( int x, int y, int width, int height ); | |
0c0d686f | 457 | |
9f13661f WS |
458 | wxSizerItem* GetItem( wxWindow *window, bool recursive = false ); |
459 | wxSizerItem* GetItem( wxSizer *sizer, bool recursive = false ); | |
460 | wxSizerItem* GetItem( size_t index ); | |
461 | ||
12a3f227 | 462 | // Manage whether individual scene items are considered |
2b5f62a0 | 463 | // in the layout calculations or not. |
8b2bac62 WS |
464 | bool Show( wxWindow *window, bool show = true, bool recursive = false ); |
465 | bool Show( wxSizer *sizer, bool show = true, bool recursive = false ); | |
466 | bool Show( size_t index, bool show = true ); | |
12a3f227 | 467 | |
8b2bac62 WS |
468 | bool Hide( wxSizer *sizer, bool recursive = false ) |
469 | { return Show( sizer, false, recursive ); } | |
470 | bool Hide( wxWindow *window, bool recursive = false ) | |
471 | { return Show( window, false, recursive ); } | |
472 | bool Hide( size_t index ) | |
473 | { return Show( index, false ); } | |
2b5f62a0 | 474 | |
9cbee2ce RL |
475 | bool IsShown( wxWindow *window ) const; |
476 | bool IsShown( wxSizer *sizer ) const; | |
477 | bool IsShown( size_t index ) const; | |
dc259b79 | 478 | |
2b5f62a0 | 479 | // Recursively call wxWindow::Show () on all sizer items. |
eb2a7883 | 480 | virtual void ShowItems (bool show); |
2b5f62a0 | 481 | |
3a5910cb DE |
482 | void Show(bool show) |
483 | { m_isShown = show; | |
484 | ShowItems(show); | |
485 | } | |
50c06297 VZ |
486 | bool IsShown() const { return m_isShown; } |
487 | ||
f6bcfd97 | 488 | protected: |
12a3f227 RL |
489 | wxSize m_size; |
490 | wxSize m_minSize; | |
491 | wxPoint m_position; | |
492 | wxSizerItemList m_children; | |
50c06297 | 493 | bool m_isShown; |
f6bcfd97 | 494 | |
9cbee2ce | 495 | wxSize GetMaxWindowSize( wxWindow *window ) const; |
f6bcfd97 | 496 | wxSize GetMinWindowSize( wxWindow *window ); |
9cbee2ce | 497 | wxSize GetMaxClientSize( wxWindow *window ) const; |
566d84a7 | 498 | wxSize GetMinClientSize( wxWindow *window ); |
65ba4113 | 499 | wxSize FitSize( wxWindow *window ); |
566d84a7 | 500 | wxSize VirtualFitSize( wxWindow *window ); |
65ba4113 | 501 | |
f6bcfd97 BP |
502 | virtual void DoSetMinSize( int width, int height ); |
503 | virtual bool DoSetItemMinSize( wxWindow *window, int width, int height ); | |
504 | virtual bool DoSetItemMinSize( wxSizer *sizer, int width, int height ); | |
12a3f227 | 505 | virtual bool DoSetItemMinSize( size_t index, int width, int height ); |
1e6feb95 | 506 | |
9cbee2ce | 507 | private: |
4393b50c | 508 | DECLARE_CLASS(wxSizer) |
f6bcfd97 | 509 | }; |
c62ac5b6 | 510 | |
f6bcfd97 BP |
511 | //--------------------------------------------------------------------------- |
512 | // wxGridSizer | |
513 | //--------------------------------------------------------------------------- | |
0c0d686f | 514 | |
f6bcfd97 BP |
515 | class WXDLLEXPORT wxGridSizer: public wxSizer |
516 | { | |
517 | public: | |
518 | wxGridSizer( int rows, int cols, int vgap, int hgap ); | |
519 | wxGridSizer( int cols, int vgap = 0, int hgap = 0 ); | |
1e6feb95 | 520 | |
5d76f462 VZ |
521 | virtual void RecalcSizes(); |
522 | virtual wxSize CalcMin(); | |
f6bcfd97 BP |
523 | |
524 | void SetCols( int cols ) { m_cols = cols; } | |
525 | void SetRows( int rows ) { m_rows = rows; } | |
526 | void SetVGap( int gap ) { m_vgap = gap; } | |
527 | void SetHGap( int gap ) { m_hgap = gap; } | |
9cbee2ce RL |
528 | int GetCols() const { return m_cols; } |
529 | int GetRows() const { return m_rows; } | |
530 | int GetVGap() const { return m_vgap; } | |
531 | int GetHGap() const { return m_hgap; } | |
1e6feb95 | 532 | |
f6bcfd97 BP |
533 | protected: |
534 | int m_rows; | |
535 | int m_cols; | |
536 | int m_vgap; | |
537 | int m_hgap; | |
1e6feb95 | 538 | |
0ca5105b VZ |
539 | // return the number of total items and the number of columns and rows |
540 | int CalcRowsCols(int& rows, int& cols) const; | |
541 | ||
f6bcfd97 | 542 | void SetItemBounds( wxSizerItem *item, int x, int y, int w, int h ); |
1e6feb95 | 543 | |
9cbee2ce | 544 | private: |
4393b50c | 545 | DECLARE_CLASS(wxGridSizer) |
f6bcfd97 | 546 | }; |
5279a24d | 547 | |
f6bcfd97 BP |
548 | //--------------------------------------------------------------------------- |
549 | // wxFlexGridSizer | |
550 | //--------------------------------------------------------------------------- | |
0c0d686f | 551 | |
5d76f462 VZ |
552 | // the bevaiour for resizing wxFlexGridSizer cells in the "non-flexible" |
553 | // direction | |
554 | enum wxFlexSizerGrowMode | |
555 | { | |
556 | // don't resize the cells in non-flexible direction at all | |
557 | wxFLEX_GROWMODE_NONE, | |
558 | ||
559 | // uniformly resize only the specified ones (default) | |
560 | wxFLEX_GROWMODE_SPECIFIED, | |
561 | ||
562 | // uniformly resize all cells | |
563 | wxFLEX_GROWMODE_ALL | |
564 | }; | |
565 | ||
f6bcfd97 BP |
566 | class WXDLLEXPORT wxFlexGridSizer: public wxGridSizer |
567 | { | |
568 | public: | |
5d76f462 | 569 | // ctors/dtor |
f6bcfd97 BP |
570 | wxFlexGridSizer( int rows, int cols, int vgap, int hgap ); |
571 | wxFlexGridSizer( int cols, int vgap = 0, int hgap = 0 ); | |
5d76f462 | 572 | virtual ~wxFlexGridSizer(); |
1e6feb95 | 573 | |
1e6feb95 | 574 | |
5d76f462 VZ |
575 | // set the rows/columns which will grow (the others will remain of the |
576 | // constant initial size) | |
e8800dcf | 577 | void AddGrowableRow( size_t idx, int proportion = 0 ); |
f6bcfd97 | 578 | void RemoveGrowableRow( size_t idx ); |
e8800dcf | 579 | void AddGrowableCol( size_t idx, int proportion = 0 ); |
f6bcfd97 | 580 | void RemoveGrowableCol( size_t idx ); |
0c0d686f | 581 | |
1e6feb95 | 582 | |
5d76f462 VZ |
583 | // the sizer cells may grow in both directions, not grow at all or only |
584 | // grow in one direction but not the other | |
585 | ||
586 | // the direction may be wxVERTICAL, wxHORIZONTAL or wxBOTH (default) | |
587 | void SetFlexibleDirection(int direction) { m_flexDirection = direction; } | |
588 | int GetFlexibleDirection() const { return m_flexDirection; } | |
589 | ||
590 | // note that the grow mode only applies to the direction which is not | |
591 | // flexible | |
592 | void SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode) { m_growMode = mode; } | |
593 | wxFlexSizerGrowMode GetNonFlexibleGrowMode() const { return m_growMode; } | |
594 | ||
fc1fcd0e RD |
595 | // Read-only access to the row heights and col widths arrays |
596 | const wxArrayInt& GetRowHeights() const { return m_rowHeights; } | |
597 | const wxArrayInt& GetColWidths() const { return m_colWidths; } | |
8b2bac62 | 598 | |
5d76f462 VZ |
599 | // implementation |
600 | virtual void RecalcSizes(); | |
601 | virtual wxSize CalcMin(); | |
602 | ||
603 | protected: | |
20b35a69 RD |
604 | void AdjustForFlexDirection(); |
605 | void AdjustForGrowables(const wxSize& sz, const wxSize& minsz, | |
606 | int nrows, int ncols); | |
8b2bac62 | 607 | |
5d76f462 VZ |
608 | // the heights/widths of all rows/columns |
609 | wxArrayInt m_rowHeights, | |
610 | m_colWidths; | |
611 | ||
612 | // indices of the growable columns and rows | |
613 | wxArrayInt m_growableRows, | |
614 | m_growableCols; | |
615 | ||
e8800dcf VZ |
616 | // proportion values of the corresponding growable rows and columns |
617 | wxArrayInt m_growableRowsProportions, | |
618 | m_growableColsProportions; | |
619 | ||
5d76f462 VZ |
620 | // parameters describing whether the growable cells should be resized in |
621 | // both directions or only one | |
622 | int m_flexDirection; | |
623 | wxFlexSizerGrowMode m_growMode; | |
1e6feb95 | 624 | |
ba763a45 RD |
625 | // saves CalcMin result to optimize RecalcSizes |
626 | wxSize m_calculatedMinSize; | |
627 | ||
9cbee2ce | 628 | private: |
4393b50c | 629 | DECLARE_CLASS(wxFlexGridSizer) |
22f3361e | 630 | DECLARE_NO_COPY_CLASS(wxFlexGridSizer) |
c62ac5b6 RR |
631 | }; |
632 | ||
633 | //--------------------------------------------------------------------------- | |
92afa2b1 | 634 | // wxBoxSizer |
c62ac5b6 RR |
635 | //--------------------------------------------------------------------------- |
636 | ||
92afa2b1 | 637 | class WXDLLEXPORT wxBoxSizer: public wxSizer |
61d514bb RR |
638 | { |
639 | public: | |
f6bcfd97 | 640 | wxBoxSizer( int orient ); |
0c0d686f | 641 | |
f6bcfd97 BP |
642 | void RecalcSizes(); |
643 | wxSize CalcMin(); | |
0c0d686f | 644 | |
9cbee2ce | 645 | int GetOrientation() const |
f6bcfd97 | 646 | { return m_orient; } |
0c0d686f | 647 | |
b657b4c9 JS |
648 | void SetOrientation(int orient) |
649 | { m_orient = orient; } | |
650 | ||
61d514bb RR |
651 | protected: |
652 | int m_orient; | |
653 | int m_stretchable; | |
654 | int m_minWidth; | |
655 | int m_minHeight; | |
656 | int m_fixedWidth; | |
657 | int m_fixedHeight; | |
1e6feb95 | 658 | |
9cbee2ce | 659 | private: |
4393b50c | 660 | DECLARE_CLASS(wxBoxSizer) |
61d514bb | 661 | }; |
0c0d686f | 662 | |
27ea1d8a RR |
663 | //--------------------------------------------------------------------------- |
664 | // wxStaticBoxSizer | |
665 | //--------------------------------------------------------------------------- | |
666 | ||
1e6feb95 VZ |
667 | #if wxUSE_STATBOX |
668 | ||
669 | class WXDLLEXPORT wxStaticBox; | |
670 | ||
27ea1d8a RR |
671 | class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer |
672 | { | |
673 | public: | |
6c1635b5 | 674 | wxStaticBoxSizer(wxStaticBox *box, int orient); |
450a1593 | 675 | wxStaticBoxSizer(int orient, wxWindow *win, const wxString& label = wxEmptyString); |
0c0d686f | 676 | |
f6bcfd97 BP |
677 | void RecalcSizes(); |
678 | wxSize CalcMin(); | |
0c0d686f | 679 | |
9cbee2ce | 680 | wxStaticBox *GetStaticBox() const |
f6bcfd97 | 681 | { return m_staticBox; } |
0c0d686f | 682 | |
eb2a7883 VZ |
683 | // override to hide/show the static box as well |
684 | virtual void ShowItems (bool show); | |
685 | ||
27ea1d8a | 686 | protected: |
f6bcfd97 | 687 | wxStaticBox *m_staticBox; |
1e6feb95 | 688 | |
9cbee2ce | 689 | private: |
4393b50c | 690 | DECLARE_CLASS(wxStaticBoxSizer) |
22f3361e | 691 | DECLARE_NO_COPY_CLASS(wxStaticBoxSizer) |
27ea1d8a RR |
692 | }; |
693 | ||
1e6feb95 VZ |
694 | #endif // wxUSE_STATBOX |
695 | ||
974c2a59 WS |
696 | #if wxUSE_BUTTON |
697 | ||
acf2ac37 RR |
698 | class WXDLLEXPORT wxStdDialogButtonSizer: public wxBoxSizer |
699 | { | |
700 | public: | |
acf2ac37 RR |
701 | // Constructor just creates a new wxBoxSizer, not much else. |
702 | // Box sizer orientation is automatically determined here: | |
703 | // vertical for PDAs, horizontal for everything else? | |
b181a505 | 704 | wxStdDialogButtonSizer(); |
acf2ac37 | 705 | |
acf2ac37 | 706 | // Checks button ID against system IDs and sets one of the pointers below |
b181a505 RR |
707 | // to this button. Does not do any sizer-related things here. |
708 | void AddButton(wxButton *button); | |
acf2ac37 | 709 | |
b181a505 RR |
710 | // Use these if no standard ID can/should be used |
711 | void SetAffirmativeButton( wxButton *button ); | |
712 | void SetNegativeButton( wxButton *button ); | |
713 | void SetCancelButton( wxButton *button ); | |
acf2ac37 | 714 | |
acf2ac37 RR |
715 | // All platform-specific code here, checks which buttons exist and add |
716 | // them to the sizer accordingly. | |
717 | // Note - one potential hack on Mac we could use here, | |
718 | // if m_buttonAffirmative is wxID_SAVE then ensure wxID_SAVE | |
719 | // is set to _("Save") and m_buttonNegative is set to _("Don't Save") | |
720 | // I wouldn't add any other hacks like that into here, | |
721 | // but this one I can see being useful. | |
718903fe | 722 | void Realize(); |
974c2a59 | 723 | |
acf2ac37 RR |
724 | wxButton *GetAffirmativeButton() const { return m_buttonAffirmative; } |
725 | wxButton *GetApplyButton() const { return m_buttonApply; } | |
726 | wxButton *GetNegativeButton() const { return m_buttonNegative; } | |
727 | wxButton *GetCancelButton() const { return m_buttonCancel; } | |
728 | wxButton *GetHelpButton() const { return m_buttonHelp; } | |
729 | ||
730 | protected: | |
b181a505 | 731 | wxButton *m_buttonAffirmative; // wxID_OK, wxID_YES, wxID_SAVE go here |
acf2ac37 | 732 | wxButton *m_buttonApply; |
b181a505 | 733 | wxButton *m_buttonNegative; // wxID_NO |
acf2ac37 RR |
734 | wxButton *m_buttonCancel; |
735 | wxButton *m_buttonHelp; | |
974c2a59 | 736 | |
acf2ac37 RR |
737 | private: |
738 | DECLARE_CLASS(wxStdDialogButtonSizer) | |
b181a505 | 739 | DECLARE_NO_COPY_CLASS(wxStdDialogButtonSizer) |
acf2ac37 | 740 | }; |
adbf2d73 | 741 | |
6b5c4761 | 742 | #endif // wxUSE_BUTTON |
974c2a59 | 743 | |
adbf2d73 VS |
744 | #if WXWIN_COMPATIBILITY_2_4 |
745 | // NB: wxBookCtrlSizer and wxNotebookSizer are deprecated, they | |
61c083e7 | 746 | // don't do anything. wxBookCtrlBase::DoGetBestSize does the job now. |
adbf2d73 | 747 | |
ade4eb65 VZ |
748 | // ---------------------------------------------------------------------------- |
749 | // wxBookCtrlSizer | |
750 | // ---------------------------------------------------------------------------- | |
83edc0a5 | 751 | |
ade4eb65 | 752 | #if wxUSE_BOOKCTRL |
65e4f9b9 | 753 | |
8e32ea1c | 754 | // this sizer works with wxNotebook/wxListbook/... and sizes the control to |
ade4eb65 | 755 | // fit its pages |
61c083e7 | 756 | class WXDLLEXPORT wxBookCtrlBase; |
1e6feb95 | 757 | |
ade4eb65 | 758 | class WXDLLEXPORT wxBookCtrlSizer : public wxSizer |
83edc0a5 | 759 | { |
83edc0a5 | 760 | public: |
61c083e7 | 761 | wxDEPRECATED( wxBookCtrlSizer(wxBookCtrlBase *bookctrl) ); |
83edc0a5 | 762 | |
61c083e7 | 763 | wxBookCtrlBase *GetControl() const { return m_bookctrl; } |
8b2bac62 | 764 | |
ade4eb65 VZ |
765 | virtual void RecalcSizes(); |
766 | virtual wxSize CalcMin(); | |
83edc0a5 | 767 | |
83edc0a5 | 768 | protected: |
adbf2d73 | 769 | // this protected ctor lets us mark the real one above as deprecated |
749bb9f1 | 770 | // and still have warning-free build of the library itself: |
adbf2d73 | 771 | wxBookCtrlSizer() {} |
8b2bac62 | 772 | |
61c083e7 | 773 | wxBookCtrlBase *m_bookctrl; |
ade4eb65 VZ |
774 | |
775 | private: | |
776 | DECLARE_CLASS(wxBookCtrlSizer) | |
777 | DECLARE_NO_COPY_CLASS(wxBookCtrlSizer) | |
778 | }; | |
779 | ||
780 | ||
781 | #if wxUSE_NOTEBOOK | |
782 | ||
61c083e7 | 783 | // before wxBookCtrlBase we only had wxNotebookSizer, keep it for backwards |
ade4eb65 VZ |
784 | // compatibility |
785 | class WXDLLEXPORT wxNotebook; | |
786 | ||
787 | class WXDLLEXPORT wxNotebookSizer : public wxBookCtrlSizer | |
788 | { | |
789 | public: | |
adbf2d73 | 790 | wxDEPRECATED( wxNotebookSizer(wxNotebook *nb) ); |
ade4eb65 VZ |
791 | |
792 | wxNotebook *GetNotebook() const { return (wxNotebook *)m_bookctrl; } | |
1e6feb95 | 793 | |
9cbee2ce | 794 | private: |
4393b50c | 795 | DECLARE_CLASS(wxNotebookSizer) |
22f3361e | 796 | DECLARE_NO_COPY_CLASS(wxNotebookSizer) |
83edc0a5 RR |
797 | }; |
798 | ||
1e6feb95 | 799 | #endif // wxUSE_NOTEBOOK |
65e4f9b9 | 800 | |
ade4eb65 VZ |
801 | #endif // wxUSE_BOOKCTRL |
802 | ||
adbf2d73 VS |
803 | #endif // WXWIN_COMPATIBILITY_2_4 |
804 | ||
8e32ea1c VZ |
805 | // ---------------------------------------------------------------------------- |
806 | // inline functions implementation | |
807 | // ---------------------------------------------------------------------------- | |
808 | ||
56eee37f | 809 | inline wxSizerItem* |
8e32ea1c VZ |
810 | wxSizer::Add( wxWindow *window, int proportion, int flag, int border, wxObject* userData ) |
811 | { | |
56eee37f | 812 | return Add( new wxSizerItem( window, proportion, flag, border, userData ) ); |
8e32ea1c VZ |
813 | } |
814 | ||
56eee37f | 815 | inline wxSizerItem* |
8e32ea1c VZ |
816 | wxSizer::Add( wxSizer *sizer, int proportion, int flag, int border, wxObject* userData ) |
817 | { | |
56eee37f | 818 | return Add( new wxSizerItem( sizer, proportion, flag, border, userData ) ); |
8e32ea1c VZ |
819 | } |
820 | ||
56eee37f | 821 | inline wxSizerItem* |
8e32ea1c VZ |
822 | wxSizer::Add( int width, int height, int proportion, int flag, int border, wxObject* userData ) |
823 | { | |
56eee37f | 824 | return Add( new wxSizerItem( width, height, proportion, flag, border, userData ) ); |
8e32ea1c VZ |
825 | } |
826 | ||
56eee37f | 827 | inline wxSizerItem* |
5f813ad6 VZ |
828 | wxSizer::Add( wxWindow *window, const wxSizerFlags& flags ) |
829 | { | |
56eee37f | 830 | return Add( new wxSizerItem(window, flags) ); |
5f813ad6 VZ |
831 | } |
832 | ||
56eee37f | 833 | inline wxSizerItem* |
5f813ad6 VZ |
834 | wxSizer::Add( wxSizer *sizer, const wxSizerFlags& flags ) |
835 | { | |
56eee37f | 836 | return Add( new wxSizerItem(sizer, flags) ); |
5f813ad6 VZ |
837 | } |
838 | ||
56eee37f | 839 | inline wxSizerItem* |
8e32ea1c VZ |
840 | wxSizer::Add( wxSizerItem *item ) |
841 | { | |
56eee37f | 842 | return Insert( m_children.GetCount(), item ); |
8e32ea1c VZ |
843 | } |
844 | ||
56eee37f | 845 | inline wxSizerItem* |
8e32ea1c VZ |
846 | wxSizer::AddSpacer(int size) |
847 | { | |
56eee37f | 848 | return Add(size, size); |
8e32ea1c VZ |
849 | } |
850 | ||
56eee37f | 851 | inline wxSizerItem* |
8e32ea1c VZ |
852 | wxSizer::AddStretchSpacer(int prop) |
853 | { | |
56eee37f | 854 | return Add(0, 0, prop); |
8e32ea1c VZ |
855 | } |
856 | ||
56eee37f | 857 | inline wxSizerItem* |
8e32ea1c VZ |
858 | wxSizer::Prepend( wxWindow *window, int proportion, int flag, int border, wxObject* userData ) |
859 | { | |
56eee37f | 860 | return Prepend( new wxSizerItem( window, proportion, flag, border, userData ) ); |
8e32ea1c VZ |
861 | } |
862 | ||
56eee37f | 863 | inline wxSizerItem* |
8e32ea1c VZ |
864 | wxSizer::Prepend( wxSizer *sizer, int proportion, int flag, int border, wxObject* userData ) |
865 | { | |
56eee37f | 866 | return Prepend( new wxSizerItem( sizer, proportion, flag, border, userData ) ); |
8e32ea1c VZ |
867 | } |
868 | ||
56eee37f | 869 | inline wxSizerItem* |
8e32ea1c VZ |
870 | wxSizer::Prepend( int width, int height, int proportion, int flag, int border, wxObject* userData ) |
871 | { | |
56eee37f | 872 | return Prepend( new wxSizerItem( width, height, proportion, flag, border, userData ) ); |
8e32ea1c VZ |
873 | } |
874 | ||
56eee37f | 875 | inline wxSizerItem* |
8e32ea1c VZ |
876 | wxSizer::Prepend( wxSizerItem *item ) |
877 | { | |
56eee37f | 878 | return Insert( 0, item ); |
8e32ea1c VZ |
879 | } |
880 | ||
56eee37f | 881 | inline wxSizerItem* |
8e32ea1c VZ |
882 | wxSizer::PrependSpacer(int size) |
883 | { | |
56eee37f | 884 | return Prepend(size, size); |
8e32ea1c VZ |
885 | } |
886 | ||
56eee37f | 887 | inline wxSizerItem* |
8e32ea1c VZ |
888 | wxSizer::PrependStretchSpacer(int prop) |
889 | { | |
56eee37f | 890 | return Prepend(0, 0, prop); |
8e32ea1c VZ |
891 | } |
892 | ||
56eee37f | 893 | inline wxSizerItem* |
5f813ad6 VZ |
894 | wxSizer::Prepend( wxWindow *window, const wxSizerFlags& flags ) |
895 | { | |
56eee37f | 896 | return Prepend( new wxSizerItem(window, flags) ); |
5f813ad6 VZ |
897 | } |
898 | ||
56eee37f | 899 | inline wxSizerItem* |
5f813ad6 VZ |
900 | wxSizer::Prepend( wxSizer *sizer, const wxSizerFlags& flags ) |
901 | { | |
56eee37f | 902 | return Prepend( new wxSizerItem(sizer, flags) ); |
5f813ad6 VZ |
903 | } |
904 | ||
56eee37f | 905 | inline wxSizerItem* |
8e32ea1c | 906 | wxSizer::Insert( size_t index, |
5f813ad6 VZ |
907 | wxWindow *window, |
908 | int proportion, | |
909 | int flag, | |
910 | int border, | |
911 | wxObject* userData ) | |
8e32ea1c | 912 | { |
56eee37f | 913 | return Insert( index, new wxSizerItem( window, proportion, flag, border, userData ) ); |
8e32ea1c VZ |
914 | } |
915 | ||
56eee37f | 916 | inline wxSizerItem* |
8e32ea1c | 917 | wxSizer::Insert( size_t index, |
5f813ad6 VZ |
918 | wxSizer *sizer, |
919 | int proportion, | |
920 | int flag, | |
921 | int border, | |
922 | wxObject* userData ) | |
8e32ea1c | 923 | { |
56eee37f | 924 | return Insert( index, new wxSizerItem( sizer, proportion, flag, border, userData ) ); |
8e32ea1c VZ |
925 | } |
926 | ||
56eee37f | 927 | inline wxSizerItem* |
8e32ea1c | 928 | wxSizer::Insert( size_t index, |
5f813ad6 VZ |
929 | int width, |
930 | int height, | |
931 | int proportion, | |
932 | int flag, | |
933 | int border, | |
934 | wxObject* userData ) | |
8e32ea1c | 935 | { |
56eee37f | 936 | return Insert( index, new wxSizerItem( width, height, proportion, flag, border, userData ) ); |
8e32ea1c VZ |
937 | } |
938 | ||
56eee37f | 939 | inline wxSizerItem* |
5f813ad6 VZ |
940 | wxSizer::Insert( size_t index, wxWindow *window, const wxSizerFlags& flags ) |
941 | { | |
56eee37f | 942 | return Insert( index, new wxSizerItem(window, flags) ); |
5f813ad6 VZ |
943 | } |
944 | ||
56eee37f | 945 | inline wxSizerItem* |
5f813ad6 VZ |
946 | wxSizer::Insert( size_t index, wxSizer *sizer, const wxSizerFlags& flags ) |
947 | { | |
56eee37f | 948 | return Insert( index, new wxSizerItem(sizer, flags) ); |
5f813ad6 VZ |
949 | } |
950 | ||
56eee37f | 951 | inline wxSizerItem* |
8e32ea1c VZ |
952 | wxSizer::InsertSpacer(size_t index, int size) |
953 | { | |
56eee37f | 954 | return Insert(index, size, size); |
8e32ea1c VZ |
955 | } |
956 | ||
56eee37f | 957 | inline wxSizerItem* |
8e32ea1c VZ |
958 | wxSizer::InsertStretchSpacer(size_t index, int prop) |
959 | { | |
56eee37f | 960 | return Insert(index, 0, 0, prop); |
8e32ea1c VZ |
961 | } |
962 | ||
adbf2d73 | 963 | |
ade4eb65 | 964 | #endif // __WXSIZER_H__ |
65e4f9b9 | 965 |