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