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