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