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