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