]> git.saurik.com Git - wxWidgets.git/blame - include/wx/sizer.h
Added wxTreeCtrl::GetItemParent to deprecate GetParent.
[wxWidgets.git] / include / wx / sizer.h
CommitLineData
5279a24d
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: sizer.h
0c0d686f 3// Purpose: provide wxSizer class for layouting
5279a24d 4// Author: Robert Roebling and Robin Dunn
566d84a7 5// Modified by: Ron Lee
0c0d686f 6// Created:
5279a24d
RR
7// RCS-ID: $Id$
8// Copyright: (c) Robin Dunn, Dirk Holtwick and Robert Roebling
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
RR
40 // spacer
41 wxSizerItem( int width, int height, int option, int flag, int border, wxObject* userData);
42
43 // window
44 wxSizerItem( wxWindow *window, int option, int flag, int border, wxObject* userData );
45
46 // subsizer
47 wxSizerItem( wxSizer *sizer, int option, int flag, int border, wxObject* userData );
48
49 ~wxSizerItem();
84f7908b
RR
50
51 virtual void DeleteWindows();
df5ddbca
RR
52
53 virtual wxSize GetSize();
54 virtual wxSize CalcMin();
55 virtual void SetDimension( wxPoint pos, wxSize size );
56
57 wxSize GetMinSize()
58 { return m_minSize; }
59
60 void SetRatio( int width, int height )
61 // if either of dimensions is zero, ratio is assumed to be 1
62 // to avoid "divide by zero" errors
63 { m_ratio = (width && height) ? ((float) width / (float) height) : 1; }
64 void SetRatio( wxSize size )
65 { m_ratio = (size.x && size.y) ? ((float) size.x / (float) size.y) : 1; }
2aab8f16 66 void SetRatio( float ratio )
df5ddbca 67 { m_ratio = ratio; }
2aab8f16 68 float GetRatio() const
df5ddbca
RR
69 { return m_ratio; }
70
71 bool IsWindow();
72 bool IsSizer();
73 bool IsSpacer();
2aab8f16 74
df5ddbca
RR
75 void SetInitSize( int x, int y )
76 { m_minSize.x = x; m_minSize.y = y; }
77 void SetOption( int option )
78 { m_option = option; }
79 void SetFlag( int flag )
80 { m_flag = flag; }
81 void SetBorder( int border )
82 { m_border = border; }
2b5f62a0
VZ
83 void Show ( bool show )
84 { m_show = show; }
df5ddbca
RR
85
86 wxWindow *GetWindow() const
87 { return m_window; }
88 void SetWindow( wxWindow *window )
89 { m_window = window; }
90 wxSizer *GetSizer() const
91 { return m_sizer; }
92 void SetSizer( wxSizer *sizer )
93 { m_sizer = sizer; }
94 int GetOption() const
95 { return m_option; }
96 int GetFlag() const
97 { return m_flag; }
98 int GetBorder() const
99 { return m_border; }
2b5f62a0
VZ
100 bool IsShown() const
101 { return m_show; }
df5ddbca
RR
102 wxObject* GetUserData()
103 { return m_userData; }
104 wxPoint GetPosition()
105 { return m_pos; }
0c0d686f 106
c62ac5b6 107protected:
df5ddbca
RR
108 wxWindow *m_window;
109 wxSizer *m_sizer;
110 wxSize m_size;
111 wxPoint m_pos;
112 wxSize m_minSize;
113 int m_option;
114 int m_border;
115 int m_flag;
2b5f62a0
VZ
116
117 // If TRUE, then this item is considered in the layout
118 // calculation. Otherwise, it is skipped over.
119 bool m_show;
df5ddbca
RR
120 // als: aspect ratio can always be calculated from m_size,
121 // but this would cause precision loss when the window
122 // is shrinked. it is safer to preserve initial value.
123 float m_ratio;
2b5f62a0 124
df5ddbca 125 wxObject *m_userData;
2aab8f16 126
df5ddbca
RR
127private:
128 DECLARE_CLASS(wxSizerItem);
c62ac5b6 129};
5279a24d
RR
130
131//---------------------------------------------------------------------------
3417c2cd 132// wxSizer
5279a24d
RR
133//---------------------------------------------------------------------------
134
2aab8f16 135class WXDLLEXPORT wxSizer: public wxObject, public wxClientDataContainer
5279a24d
RR
136{
137public:
f6bcfd97
BP
138 wxSizer();
139 ~wxSizer();
140
141 /* These should be called Append() really. */
142 virtual void Add( wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
143 virtual void Add( wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
144 virtual void Add( int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
145
146 virtual void Insert( int before, wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
147 virtual void Insert( int before, wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
148 virtual void Insert( int before, int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
149
150 virtual void Prepend( wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
151 virtual void Prepend( wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
152 virtual void Prepend( int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
153
154 virtual bool Remove( wxWindow *window );
155 virtual bool Remove( wxSizer *sizer );
156 virtual bool Remove( int pos );
84f7908b
RR
157
158 virtual void Clear( bool delete_windows=FALSE );
159 virtual void DeleteWindows();
f6bcfd97
BP
160
161 void SetMinSize( int width, int height )
162 { DoSetMinSize( width, height ); }
163 void SetMinSize( wxSize size )
164 { DoSetMinSize( size.x, size.y ); }
1e6feb95 165
f6bcfd97
BP
166 /* Searches recursively */
167 bool SetItemMinSize( wxWindow *window, int width, int height )
168 { return DoSetItemMinSize( window, width, height ); }
169 bool SetItemMinSize( wxWindow *window, wxSize size )
170 { return DoSetItemMinSize( window, size.x, size.y ); }
1e6feb95 171
f6bcfd97
BP
172 /* Searches recursively */
173 bool SetItemMinSize( wxSizer *sizer, int width, int height )
174 { return DoSetItemMinSize( sizer, width, height ); }
175 bool SetItemMinSize( wxSizer *sizer, wxSize size )
176 { return DoSetItemMinSize( sizer, size.x, size.y ); }
1e6feb95 177
f6bcfd97
BP
178 bool SetItemMinSize( int pos, int width, int height )
179 { return DoSetItemMinSize( pos, width, height ); }
180 bool SetItemMinSize( int pos, wxSize size )
181 { return DoSetItemMinSize( pos, size.x, size.y ); }
1e6feb95 182
f6bcfd97
BP
183 wxSize GetSize()
184 { return m_size; }
185 wxPoint GetPosition()
186 { return m_position; }
1e6feb95 187
f6bcfd97
BP
188 /* Calculate the minimal size or return m_minSize if bigger. */
189 wxSize GetMinSize();
190
191 virtual void RecalcSizes() = 0;
192 virtual wxSize CalcMin() = 0;
193
194 virtual void Layout();
195
e5251d4f 196 wxSize Fit( wxWindow *window );
566d84a7 197 void FitInside( wxWindow *window );
f6bcfd97 198 void SetSizeHints( wxWindow *window );
566d84a7 199 void SetVirtualSizeHints( wxWindow *window );
f6bcfd97
BP
200
201 wxList& GetChildren()
202 { return m_children; }
203
204 void SetDimension( int x, int y, int width, int height );
0c0d686f 205
2b5f62a0
VZ
206 // Manage whether individual windows or sub-sizers are considered
207 // in the layout calculations or not.
208 void Show( wxWindow *window, bool show = TRUE );
209 void Hide( wxWindow *window )
210 { Show (window, FALSE); }
211 void Show( wxSizer *sizer, bool show = TRUE );
212 void Hide( wxSizer *sizer )
213 { Show (sizer, FALSE); }
214
215 bool IsShown( wxWindow *window );
216 bool IsShown( wxSizer *sizer );
217
218 // Recursively call wxWindow::Show () on all sizer items.
219 void ShowItems (bool show);
220
f6bcfd97
BP
221protected:
222 wxSize m_size;
223 wxSize m_minSize;
224 wxPoint m_position;
225 wxList m_children;
226
65ba4113 227 wxSize GetMaxWindowSize( wxWindow *window );
f6bcfd97 228 wxSize GetMinWindowSize( wxWindow *window );
566d84a7
RL
229 wxSize GetMaxClientSize( wxWindow *window );
230 wxSize GetMinClientSize( wxWindow *window );
65ba4113 231 wxSize FitSize( wxWindow *window );
566d84a7 232 wxSize VirtualFitSize( wxWindow *window );
65ba4113 233
f6bcfd97
BP
234 virtual void DoSetMinSize( int width, int height );
235 virtual bool DoSetItemMinSize( wxWindow *window, int width, int height );
236 virtual bool DoSetItemMinSize( wxSizer *sizer, int width, int height );
237 virtual bool DoSetItemMinSize( int pos, int width, int height );
1e6feb95 238
f6bcfd97
BP
239private:
240 DECLARE_CLASS(wxSizer);
241};
c62ac5b6 242
f6bcfd97
BP
243//---------------------------------------------------------------------------
244// wxGridSizer
245//---------------------------------------------------------------------------
0c0d686f 246
f6bcfd97
BP
247class WXDLLEXPORT wxGridSizer: public wxSizer
248{
249public:
250 wxGridSizer( int rows, int cols, int vgap, int hgap );
251 wxGridSizer( int cols, int vgap = 0, int hgap = 0 );
1e6feb95 252
f6bcfd97
BP
253 void RecalcSizes();
254 wxSize CalcMin();
255
256 void SetCols( int cols ) { m_cols = cols; }
257 void SetRows( int rows ) { m_rows = rows; }
258 void SetVGap( int gap ) { m_vgap = gap; }
259 void SetHGap( int gap ) { m_hgap = gap; }
260 int GetCols() { return m_cols; }
261 int GetRows() { return m_rows; }
262 int GetVGap() { return m_vgap; }
263 int GetHGap() { return m_hgap; }
1e6feb95 264
f6bcfd97
BP
265protected:
266 int m_rows;
267 int m_cols;
268 int m_vgap;
269 int m_hgap;
1e6feb95 270
0ca5105b
VZ
271 // return the number of total items and the number of columns and rows
272 int CalcRowsCols(int& rows, int& cols) const;
273
f6bcfd97 274 void SetItemBounds( wxSizerItem *item, int x, int y, int w, int h );
1e6feb95 275
f6bcfd97
BP
276private:
277 DECLARE_CLASS(wxGridSizer);
278};
5279a24d 279
f6bcfd97
BP
280//---------------------------------------------------------------------------
281// wxFlexGridSizer
282//---------------------------------------------------------------------------
0c0d686f 283
f6bcfd97
BP
284class WXDLLEXPORT wxFlexGridSizer: public wxGridSizer
285{
286public:
287 wxFlexGridSizer( int rows, int cols, int vgap, int hgap );
288 wxFlexGridSizer( int cols, int vgap = 0, int hgap = 0 );
289 ~wxFlexGridSizer();
1e6feb95 290
f6bcfd97
BP
291 void RecalcSizes();
292 wxSize CalcMin();
1e6feb95 293
f6bcfd97
BP
294 void AddGrowableRow( size_t idx );
295 void RemoveGrowableRow( size_t idx );
296 void AddGrowableCol( size_t idx );
297 void RemoveGrowableCol( size_t idx );
0c0d686f 298
c62ac5b6 299protected:
f6bcfd97
BP
300 int *m_rowHeights;
301 int *m_colWidths;
302 wxArrayInt m_growableRows;
303 wxArrayInt m_growableCols;
1e6feb95 304
f6bcfd97 305 void CreateArrays();
1e6feb95 306
f6bcfd97
BP
307private:
308 DECLARE_CLASS(wxFlexGridSizer);
c62ac5b6
RR
309};
310
311//---------------------------------------------------------------------------
92afa2b1 312// wxBoxSizer
c62ac5b6
RR
313//---------------------------------------------------------------------------
314
92afa2b1 315class WXDLLEXPORT wxBoxSizer: public wxSizer
61d514bb
RR
316{
317public:
f6bcfd97 318 wxBoxSizer( int orient );
0c0d686f 319
f6bcfd97
BP
320 void RecalcSizes();
321 wxSize CalcMin();
0c0d686f 322
f6bcfd97
BP
323 int GetOrientation()
324 { return m_orient; }
0c0d686f 325
b657b4c9
JS
326 void SetOrientation(int orient)
327 { m_orient = orient; }
328
61d514bb
RR
329protected:
330 int m_orient;
331 int m_stretchable;
332 int m_minWidth;
333 int m_minHeight;
334 int m_fixedWidth;
335 int m_fixedHeight;
1e6feb95 336
f6bcfd97
BP
337private:
338 DECLARE_CLASS(wxBoxSizer);
61d514bb 339};
0c0d686f 340
27ea1d8a
RR
341//---------------------------------------------------------------------------
342// wxStaticBoxSizer
343//---------------------------------------------------------------------------
344
1e6feb95
VZ
345#if wxUSE_STATBOX
346
347class WXDLLEXPORT wxStaticBox;
348
27ea1d8a
RR
349class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer
350{
351public:
f6bcfd97 352 wxStaticBoxSizer( wxStaticBox *box, int orient );
0c0d686f 353
f6bcfd97
BP
354 void RecalcSizes();
355 wxSize CalcMin();
0c0d686f 356
f6bcfd97
BP
357 wxStaticBox *GetStaticBox()
358 { return m_staticBox; }
0c0d686f 359
27ea1d8a 360protected:
f6bcfd97 361 wxStaticBox *m_staticBox;
1e6feb95 362
f6bcfd97
BP
363private:
364 DECLARE_CLASS(wxStaticBoxSizer);
27ea1d8a
RR
365};
366
1e6feb95
VZ
367#endif // wxUSE_STATBOX
368
83edc0a5
RR
369//---------------------------------------------------------------------------
370// wxNotebookSizer
371//---------------------------------------------------------------------------
372
65e4f9b9
VS
373#if wxUSE_NOTEBOOK
374
1e6feb95
VZ
375class WXDLLEXPORT wxNotebook;
376
83edc0a5
RR
377class WXDLLEXPORT wxNotebookSizer: public wxSizer
378{
83edc0a5 379public:
f6bcfd97 380 wxNotebookSizer( wxNotebook *nb );
83edc0a5 381
f6bcfd97
BP
382 void RecalcSizes();
383 wxSize CalcMin();
83edc0a5 384
f6bcfd97
BP
385 wxNotebook *GetNotebook()
386 { return m_notebook; }
83edc0a5
RR
387
388protected:
f6bcfd97 389 wxNotebook *m_notebook;
1e6feb95 390
f6bcfd97
BP
391private:
392 DECLARE_CLASS(wxNotebookSizer);
83edc0a5
RR
393};
394
1e6feb95 395#endif // wxUSE_NOTEBOOK
65e4f9b9
VS
396
397
5279a24d
RR
398#endif
399 // __WXSIZER_H__