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