]> git.saurik.com Git - wxWidgets.git/blame - include/wx/sizer.h
Added support for delayed deactivation of windows (for MDI)
[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
566d84a7 5// Modified by: Ron Lee
0c0d686f 6// Created:
5279a24d 7// RCS-ID: $Id$
a4ab8ed5 8// Copyright: (c) Robin Dunn, Robert Roebling
5279a24d
RR
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef __WXSIZER_H__
13#define __WXSIZER_H__
14
af49c4b8 15#if defined(__GNUG__) && !defined(__APPLE__)
5279a24d
RR
16#pragma interface "sizer.h"
17#endif
18
19#include "wx/defs.h"
20
21#include "wx/window.h"
22#include "wx/frame.h"
23#include "wx/dialog.h"
24
25//---------------------------------------------------------------------------
26// classes
27//---------------------------------------------------------------------------
28
3417c2cd
RR
29class wxSizerItem;
30class wxSizer;
92afa2b1 31class wxBoxSizer;
5279a24d
RR
32
33//---------------------------------------------------------------------------
3417c2cd 34// wxSizerItem
5279a24d
RR
35//---------------------------------------------------------------------------
36
3417c2cd 37class WXDLLEXPORT wxSizerItem: public wxObject
5279a24d
RR
38{
39public:
df5ddbca 40 // spacer
12a3f227
RL
41 wxSizerItem( int width,
42 int height,
43 int proportion,
44 int flag,
45 int border,
46 wxObject* userData);
df5ddbca
RR
47
48 // window
12a3f227
RL
49 wxSizerItem( wxWindow *window,
50 int proportion,
51 int flag,
52 int border,
53 wxObject* userData );
df5ddbca
RR
54
55 // subsizer
12a3f227
RL
56 wxSizerItem( wxSizer *sizer,
57 int proportion,
58 int flag,
59 int border,
60 wxObject* userData );
df5ddbca
RR
61
62 ~wxSizerItem();
dc259b79 63
84f7908b 64 virtual void DeleteWindows();
df5ddbca 65
96fdbb60
RL
66 // Enable deleting the SizerItem without destroying the contained sizer.
67 void DetachSizer()
68 { m_sizer = 0; }
69
9cbee2ce 70 virtual wxSize GetSize() const;
df5ddbca
RR
71 virtual wxSize CalcMin();
72 virtual void SetDimension( wxPoint pos, wxSize size );
73
9cbee2ce 74 wxSize GetMinSize() const
df5ddbca 75 { return m_minSize; }
12a3f227
RL
76 void SetInitSize( int x, int y )
77 { m_minSize.x = x; m_minSize.y = y; }
df5ddbca
RR
78
79 void SetRatio( int width, int height )
80 // if either of dimensions is zero, ratio is assumed to be 1
81 // to avoid "divide by zero" errors
82 { m_ratio = (width && height) ? ((float) width / (float) height) : 1; }
83 void SetRatio( wxSize size )
84 { m_ratio = (size.x && size.y) ? ((float) size.x / (float) size.y) : 1; }
2aab8f16 85 void SetRatio( float ratio )
df5ddbca 86 { m_ratio = ratio; }
2aab8f16 87 float GetRatio() const
df5ddbca
RR
88 { return m_ratio; }
89
9cbee2ce
RL
90 bool IsWindow() const;
91 bool IsSizer() const;
92 bool IsSpacer() const;
2aab8f16 93
12a3f227
RL
94 // Deprecated in 2.6, use {G,S}etProportion instead.
95 wxDEPRECATED( void SetOption( int option ) );
96 wxDEPRECATED( int GetOption() const );
97
98 void SetProportion( int proportion )
99 { m_proportion = proportion; }
100 int GetProportion() const
101 { return m_proportion; }
df5ddbca
RR
102 void SetFlag( int flag )
103 { m_flag = flag; }
12a3f227
RL
104 int GetFlag() const
105 { return m_flag; }
df5ddbca
RR
106 void SetBorder( int border )
107 { m_border = border; }
12a3f227
RL
108 int GetBorder() const
109 { return m_border; }
df5ddbca
RR
110
111 wxWindow *GetWindow() const
112 { return m_window; }
113 void SetWindow( wxWindow *window )
114 { m_window = window; }
115 wxSizer *GetSizer() const
116 { return m_sizer; }
117 void SetSizer( wxSizer *sizer )
118 { m_sizer = sizer; }
12a3f227
RL
119 const wxSize &GetSpacer() const
120 { return m_size; }
121 void SetSpacer( const wxSize &size )
122 { m_size = size; m_minSize = size; }
123
124 void Show ( bool show );
2b5f62a0
VZ
125 bool IsShown() const
126 { return m_show; }
12a3f227 127
9cbee2ce 128 wxObject* GetUserData() const
df5ddbca 129 { return m_userData; }
9cbee2ce 130 wxPoint GetPosition() const
df5ddbca 131 { return m_pos; }
0c0d686f 132
c62ac5b6 133protected:
df5ddbca
RR
134 wxWindow *m_window;
135 wxSizer *m_sizer;
136 wxSize m_size;
137 wxPoint m_pos;
138 wxSize m_minSize;
12a3f227 139 int m_proportion;
df5ddbca
RR
140 int m_border;
141 int m_flag;
2b5f62a0 142
e0d8fb45 143 // If true, then this item is considered in the layout
dc259b79 144 // calculation. Otherwise, it is skipped over.
2b5f62a0 145 bool m_show;
12a3f227
RL
146
147 // Aspect ratio can always be calculated from m_size,
148 // but this would cause precision loss when the window
149 // is shrunk. It is safer to preserve the initial value.
df5ddbca 150 float m_ratio;
2b5f62a0 151
df5ddbca 152 wxObject *m_userData;
2aab8f16 153
9cbee2ce
RL
154private:
155 DECLARE_CLASS(wxSizerItem);
22f3361e 156 DECLARE_NO_COPY_CLASS(wxSizerItem)
c62ac5b6 157};
5279a24d 158
12a3f227
RL
159WX_DECLARE_EXPORTED_LIST( wxSizerItem, wxSizerItemList );
160
161
5279a24d 162//---------------------------------------------------------------------------
3417c2cd 163// wxSizer
5279a24d
RR
164//---------------------------------------------------------------------------
165
2aab8f16 166class WXDLLEXPORT wxSizer: public wxObject, public wxClientDataContainer
5279a24d
RR
167{
168public:
f6bcfd97
BP
169 wxSizer();
170 ~wxSizer();
171
172 /* These should be called Append() really. */
12a3f227
RL
173 virtual void Add( wxWindow *window,
174 int proportion = 0,
175 int flag = 0,
176 int border = 0,
177 wxObject* userData = NULL );
178 virtual void Add( wxSizer *sizer,
179 int proportion = 0,
180 int flag = 0,
181 int border = 0,
182 wxObject* userData = NULL );
183 virtual void Add( int width,
184 int height,
185 int proportion = 0,
186 int flag = 0,
187 int border = 0,
188 wxObject* userData = NULL );
189 virtual void Add( wxSizerItem *item );
190
191 virtual void Insert( size_t index,
192 wxWindow *window,
193 int proportion = 0,
194 int flag = 0,
195 int border = 0,
196 wxObject* userData = NULL );
197 virtual void Insert( size_t index,
198 wxSizer *sizer,
199 int proportion = 0,
200 int flag = 0,
201 int border = 0,
202 wxObject* userData = NULL );
203 virtual void Insert( size_t index,
204 int width,
205 int height,
206 int proportion = 0,
207 int flag = 0,
208 int border = 0,
209 wxObject* userData = NULL );
210 virtual void Insert( size_t index,
211 wxSizerItem *item );
212
213 virtual void Prepend( wxWindow *window,
214 int proportion = 0,
215 int flag = 0,
216 int border = 0,
217 wxObject* userData = NULL );
218 virtual void Prepend( wxSizer *sizer,
219 int proportion = 0,
220 int flag = 0,
221 int border = 0,
222 wxObject* userData = NULL );
223 virtual void Prepend( int width,
224 int height,
225 int proportion = 0,
226 int flag = 0,
227 int border = 0,
228 wxObject* userData = NULL );
229 virtual void Prepend( wxSizerItem *item );
230
231 // Deprecated in 2.6 since historically it does not delete the window,
232 // use Detach instead.
233 wxDEPRECATED( virtual bool Remove( wxWindow *window ) );
f6bcfd97 234 virtual bool Remove( wxSizer *sizer );
e0d8fb45 235 virtual bool Remove( int index );
00976fe5 236
12a3f227 237 virtual bool Detach( wxWindow *window );
00976fe5 238 virtual bool Detach( wxSizer *sizer );
e0d8fb45 239 virtual bool Detach( int index );
00976fe5 240
e0d8fb45 241 virtual void Clear( bool delete_windows = false );
84f7908b 242 virtual void DeleteWindows();
f6bcfd97
BP
243
244 void SetMinSize( int width, int height )
245 { DoSetMinSize( width, height ); }
246 void SetMinSize( wxSize size )
247 { DoSetMinSize( size.x, size.y ); }
1e6feb95 248
f6bcfd97
BP
249 /* Searches recursively */
250 bool SetItemMinSize( wxWindow *window, int width, int height )
251 { return DoSetItemMinSize( window, width, height ); }
252 bool SetItemMinSize( wxWindow *window, wxSize size )
253 { return DoSetItemMinSize( window, size.x, size.y ); }
1e6feb95 254
f6bcfd97
BP
255 /* Searches recursively */
256 bool SetItemMinSize( wxSizer *sizer, int width, int height )
257 { return DoSetItemMinSize( sizer, width, height ); }
258 bool SetItemMinSize( wxSizer *sizer, wxSize size )
259 { return DoSetItemMinSize( sizer, size.x, size.y ); }
1e6feb95 260
12a3f227
RL
261 bool SetItemMinSize( size_t index, int width, int height )
262 { return DoSetItemMinSize( index, width, height ); }
263 bool SetItemMinSize( size_t index, wxSize size )
264 { return DoSetItemMinSize( index, size.x, size.y ); }
1e6feb95 265
9cbee2ce 266 wxSize GetSize() const
f6bcfd97 267 { return m_size; }
9cbee2ce 268 wxPoint GetPosition() const
f6bcfd97 269 { return m_position; }
1e6feb95 270
f6bcfd97
BP
271 /* Calculate the minimal size or return m_minSize if bigger. */
272 wxSize GetMinSize();
273
274 virtual void RecalcSizes() = 0;
275 virtual wxSize CalcMin() = 0;
276
277 virtual void Layout();
278
e5251d4f 279 wxSize Fit( wxWindow *window );
566d84a7 280 void FitInside( wxWindow *window );
f6bcfd97 281 void SetSizeHints( wxWindow *window );
566d84a7 282 void SetVirtualSizeHints( wxWindow *window );
f6bcfd97 283
12a3f227 284 wxSizerItemList& GetChildren()
f6bcfd97
BP
285 { return m_children; }
286
287 void SetDimension( int x, int y, int width, int height );
0c0d686f 288
12a3f227 289 // Manage whether individual scene items are considered
2b5f62a0 290 // in the layout calculations or not.
e0d8fb45
VZ
291 void Show( wxWindow *window, bool show = true );
292 void Show( wxSizer *sizer, bool show = true );
293 void Show( size_t index, bool show = true );
12a3f227 294
2b5f62a0 295 void Hide( wxSizer *sizer )
e0d8fb45 296 { Show( sizer, false ); }
12a3f227 297 void Hide( wxWindow *window )
e0d8fb45 298 { Show( window, false ); }
12a3f227 299 void Hide( size_t index )
e0d8fb45 300 { Show( index, false ); }
2b5f62a0 301
9cbee2ce
RL
302 bool IsShown( wxWindow *window ) const;
303 bool IsShown( wxSizer *sizer ) const;
304 bool IsShown( size_t index ) const;
dc259b79 305
2b5f62a0
VZ
306 // Recursively call wxWindow::Show () on all sizer items.
307 void ShowItems (bool show);
308
f6bcfd97 309protected:
12a3f227
RL
310 wxSize m_size;
311 wxSize m_minSize;
312 wxPoint m_position;
313 wxSizerItemList m_children;
f6bcfd97 314
9cbee2ce 315 wxSize GetMaxWindowSize( wxWindow *window ) const;
f6bcfd97 316 wxSize GetMinWindowSize( wxWindow *window );
9cbee2ce 317 wxSize GetMaxClientSize( wxWindow *window ) const;
566d84a7 318 wxSize GetMinClientSize( wxWindow *window );
65ba4113 319 wxSize FitSize( wxWindow *window );
566d84a7 320 wxSize VirtualFitSize( wxWindow *window );
65ba4113 321
f6bcfd97
BP
322 virtual void DoSetMinSize( int width, int height );
323 virtual bool DoSetItemMinSize( wxWindow *window, int width, int height );
324 virtual bool DoSetItemMinSize( wxSizer *sizer, int width, int height );
12a3f227 325 virtual bool DoSetItemMinSize( size_t index, int width, int height );
1e6feb95 326
9cbee2ce
RL
327private:
328 DECLARE_CLASS(wxSizer);
f6bcfd97 329};
c62ac5b6 330
f6bcfd97
BP
331//---------------------------------------------------------------------------
332// wxGridSizer
333//---------------------------------------------------------------------------
0c0d686f 334
f6bcfd97
BP
335class WXDLLEXPORT wxGridSizer: public wxSizer
336{
337public:
338 wxGridSizer( int rows, int cols, int vgap, int hgap );
339 wxGridSizer( int cols, int vgap = 0, int hgap = 0 );
1e6feb95 340
5d76f462
VZ
341 virtual void RecalcSizes();
342 virtual wxSize CalcMin();
f6bcfd97
BP
343
344 void SetCols( int cols ) { m_cols = cols; }
345 void SetRows( int rows ) { m_rows = rows; }
346 void SetVGap( int gap ) { m_vgap = gap; }
347 void SetHGap( int gap ) { m_hgap = gap; }
9cbee2ce
RL
348 int GetCols() const { return m_cols; }
349 int GetRows() const { return m_rows; }
350 int GetVGap() const { return m_vgap; }
351 int GetHGap() const { return m_hgap; }
1e6feb95 352
f6bcfd97
BP
353protected:
354 int m_rows;
355 int m_cols;
356 int m_vgap;
357 int m_hgap;
1e6feb95 358
0ca5105b
VZ
359 // return the number of total items and the number of columns and rows
360 int CalcRowsCols(int& rows, int& cols) const;
361
f6bcfd97 362 void SetItemBounds( wxSizerItem *item, int x, int y, int w, int h );
1e6feb95 363
9cbee2ce
RL
364private:
365 DECLARE_CLASS(wxGridSizer);
f6bcfd97 366};
5279a24d 367
f6bcfd97
BP
368//---------------------------------------------------------------------------
369// wxFlexGridSizer
370//---------------------------------------------------------------------------
0c0d686f 371
5d76f462
VZ
372// the bevaiour for resizing wxFlexGridSizer cells in the "non-flexible"
373// direction
374enum wxFlexSizerGrowMode
375{
376 // don't resize the cells in non-flexible direction at all
377 wxFLEX_GROWMODE_NONE,
378
379 // uniformly resize only the specified ones (default)
380 wxFLEX_GROWMODE_SPECIFIED,
381
382 // uniformly resize all cells
383 wxFLEX_GROWMODE_ALL
384};
385
f6bcfd97
BP
386class WXDLLEXPORT wxFlexGridSizer: public wxGridSizer
387{
388public:
5d76f462 389 // ctors/dtor
f6bcfd97
BP
390 wxFlexGridSizer( int rows, int cols, int vgap, int hgap );
391 wxFlexGridSizer( int cols, int vgap = 0, int hgap = 0 );
5d76f462 392 virtual ~wxFlexGridSizer();
1e6feb95 393
1e6feb95 394
5d76f462
VZ
395 // set the rows/columns which will grow (the others will remain of the
396 // constant initial size)
e8800dcf 397 void AddGrowableRow( size_t idx, int proportion = 0 );
f6bcfd97 398 void RemoveGrowableRow( size_t idx );
e8800dcf 399 void AddGrowableCol( size_t idx, int proportion = 0 );
f6bcfd97 400 void RemoveGrowableCol( size_t idx );
0c0d686f 401
1e6feb95 402
5d76f462
VZ
403 // the sizer cells may grow in both directions, not grow at all or only
404 // grow in one direction but not the other
405
406 // the direction may be wxVERTICAL, wxHORIZONTAL or wxBOTH (default)
407 void SetFlexibleDirection(int direction) { m_flexDirection = direction; }
408 int GetFlexibleDirection() const { return m_flexDirection; }
409
410 // note that the grow mode only applies to the direction which is not
411 // flexible
412 void SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode) { m_growMode = mode; }
413 wxFlexSizerGrowMode GetNonFlexibleGrowMode() const { return m_growMode; }
414
415
416 // implementation
417 virtual void RecalcSizes();
418 virtual wxSize CalcMin();
419
420protected:
421 // the heights/widths of all rows/columns
422 wxArrayInt m_rowHeights,
423 m_colWidths;
424
425 // indices of the growable columns and rows
426 wxArrayInt m_growableRows,
427 m_growableCols;
428
e8800dcf
VZ
429 // proportion values of the corresponding growable rows and columns
430 wxArrayInt m_growableRowsProportions,
431 m_growableColsProportions;
432
5d76f462
VZ
433 // parameters describing whether the growable cells should be resized in
434 // both directions or only one
435 int m_flexDirection;
436 wxFlexSizerGrowMode m_growMode;
1e6feb95 437
9cbee2ce
RL
438private:
439 DECLARE_CLASS(wxFlexGridSizer);
22f3361e 440 DECLARE_NO_COPY_CLASS(wxFlexGridSizer)
c62ac5b6
RR
441};
442
443//---------------------------------------------------------------------------
92afa2b1 444// wxBoxSizer
c62ac5b6
RR
445//---------------------------------------------------------------------------
446
92afa2b1 447class WXDLLEXPORT wxBoxSizer: public wxSizer
61d514bb
RR
448{
449public:
f6bcfd97 450 wxBoxSizer( int orient );
0c0d686f 451
f6bcfd97
BP
452 void RecalcSizes();
453 wxSize CalcMin();
0c0d686f 454
9cbee2ce 455 int GetOrientation() const
f6bcfd97 456 { return m_orient; }
0c0d686f 457
b657b4c9
JS
458 void SetOrientation(int orient)
459 { m_orient = orient; }
460
61d514bb
RR
461protected:
462 int m_orient;
463 int m_stretchable;
464 int m_minWidth;
465 int m_minHeight;
466 int m_fixedWidth;
467 int m_fixedHeight;
1e6feb95 468
9cbee2ce
RL
469private:
470 DECLARE_CLASS(wxBoxSizer);
61d514bb 471};
0c0d686f 472
27ea1d8a
RR
473//---------------------------------------------------------------------------
474// wxStaticBoxSizer
475//---------------------------------------------------------------------------
476
1e6feb95
VZ
477#if wxUSE_STATBOX
478
479class WXDLLEXPORT wxStaticBox;
480
27ea1d8a
RR
481class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer
482{
483public:
f6bcfd97 484 wxStaticBoxSizer( wxStaticBox *box, int orient );
0c0d686f 485
f6bcfd97
BP
486 void RecalcSizes();
487 wxSize CalcMin();
0c0d686f 488
9cbee2ce 489 wxStaticBox *GetStaticBox() const
f6bcfd97 490 { return m_staticBox; }
0c0d686f 491
27ea1d8a 492protected:
f6bcfd97 493 wxStaticBox *m_staticBox;
1e6feb95 494
9cbee2ce
RL
495private:
496 DECLARE_CLASS(wxStaticBoxSizer);
22f3361e 497 DECLARE_NO_COPY_CLASS(wxStaticBoxSizer)
27ea1d8a
RR
498};
499
1e6feb95
VZ
500#endif // wxUSE_STATBOX
501
83edc0a5
RR
502//---------------------------------------------------------------------------
503// wxNotebookSizer
504//---------------------------------------------------------------------------
505
65e4f9b9
VS
506#if wxUSE_NOTEBOOK
507
1e6feb95
VZ
508class WXDLLEXPORT wxNotebook;
509
83edc0a5
RR
510class WXDLLEXPORT wxNotebookSizer: public wxSizer
511{
83edc0a5 512public:
f6bcfd97 513 wxNotebookSizer( wxNotebook *nb );
83edc0a5 514
f6bcfd97
BP
515 void RecalcSizes();
516 wxSize CalcMin();
83edc0a5 517
9cbee2ce 518 wxNotebook *GetNotebook() const
f6bcfd97 519 { return m_notebook; }
83edc0a5
RR
520
521protected:
f6bcfd97 522 wxNotebook *m_notebook;
1e6feb95 523
9cbee2ce
RL
524private:
525 DECLARE_CLASS(wxNotebookSizer);
22f3361e 526 DECLARE_NO_COPY_CLASS(wxNotebookSizer)
83edc0a5
RR
527};
528
1e6feb95 529#endif // wxUSE_NOTEBOOK
65e4f9b9
VS
530
531
5279a24d
RR
532#endif
533 // __WXSIZER_H__