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