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