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