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