]> git.saurik.com Git - wxWidgets.git/blob - include/wx/sizer.h
Added a couple more numeric character references
[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 wxStaticBox;
30 class wxNotebook;
31
32 class wxSizerItem;
33 class wxSizer;
34 class wxBoxSizer;
35 class wxStaticBoxSizer;
36
37 //---------------------------------------------------------------------------
38 // wxSizerItem
39 //---------------------------------------------------------------------------
40
41 class WXDLLEXPORT wxSizerItem: public wxObject
42 {
43 public:
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();
76
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; }
104
105 protected:
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
120 private:
121 DECLARE_CLASS(wxSizerItem);
122 };
123
124 //---------------------------------------------------------------------------
125 // wxSizer
126 //---------------------------------------------------------------------------
127
128 class WXDLLEXPORT wxSizer: public wxObject
129 {
130 public:
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 );
193
194 protected:
195 wxSize m_size;
196 wxSize m_minSize;
197 wxPoint m_position;
198 wxList m_children;
199
200 wxSize GetMaxWindowSize( wxWindow *window );
201 wxSize GetMinWindowSize( wxWindow *window );
202 wxSize FitSize( wxWindow *window );
203
204 virtual void DoSetMinSize( int width, int height );
205 virtual bool DoSetItemMinSize( wxWindow *window, int width, int height );
206 virtual bool DoSetItemMinSize( wxSizer *sizer, int width, int height );
207 virtual bool DoSetItemMinSize( int pos, int width, int height );
208
209 private:
210 DECLARE_CLASS(wxSizer);
211 };
212
213 //---------------------------------------------------------------------------
214 // wxGridSizer
215 //---------------------------------------------------------------------------
216
217 class WXDLLEXPORT wxGridSizer: public wxSizer
218 {
219 public:
220 wxGridSizer( int rows, int cols, int vgap, int hgap );
221 wxGridSizer( int cols, int vgap = 0, int hgap = 0 );
222
223 void RecalcSizes();
224 wxSize CalcMin();
225
226 void SetCols( int cols ) { m_cols = cols; }
227 void SetRows( int rows ) { m_rows = rows; }
228 void SetVGap( int gap ) { m_vgap = gap; }
229 void SetHGap( int gap ) { m_hgap = gap; }
230 int GetCols() { return m_cols; }
231 int GetRows() { return m_rows; }
232 int GetVGap() { return m_vgap; }
233 int GetHGap() { return m_hgap; }
234
235 protected:
236 int m_rows;
237 int m_cols;
238 int m_vgap;
239 int m_hgap;
240
241 void SetItemBounds( wxSizerItem *item, int x, int y, int w, int h );
242
243 private:
244 DECLARE_CLASS(wxGridSizer);
245 };
246
247 //---------------------------------------------------------------------------
248 // wxFlexGridSizer
249 //---------------------------------------------------------------------------
250
251 class WXDLLEXPORT wxFlexGridSizer: public wxGridSizer
252 {
253 public:
254 wxFlexGridSizer( int rows, int cols, int vgap, int hgap );
255 wxFlexGridSizer( int cols, int vgap = 0, int hgap = 0 );
256 ~wxFlexGridSizer();
257
258 void RecalcSizes();
259 wxSize CalcMin();
260
261 void AddGrowableRow( size_t idx );
262 void RemoveGrowableRow( size_t idx );
263 void AddGrowableCol( size_t idx );
264 void RemoveGrowableCol( size_t idx );
265
266 protected:
267 int *m_rowHeights;
268 int *m_colWidths;
269 wxArrayInt m_growableRows;
270 wxArrayInt m_growableCols;
271
272 void CreateArrays();
273
274 private:
275 DECLARE_CLASS(wxFlexGridSizer);
276 };
277
278 //---------------------------------------------------------------------------
279 // wxBoxSizer
280 //---------------------------------------------------------------------------
281
282 class WXDLLEXPORT wxBoxSizer: public wxSizer
283 {
284 public:
285 wxBoxSizer( int orient );
286
287 void RecalcSizes();
288 wxSize CalcMin();
289
290 int GetOrientation()
291 { return m_orient; }
292
293 protected:
294 int m_orient;
295 int m_stretchable;
296 int m_minWidth;
297 int m_minHeight;
298 int m_fixedWidth;
299 int m_fixedHeight;
300
301 private:
302 DECLARE_CLASS(wxBoxSizer);
303 };
304
305 //---------------------------------------------------------------------------
306 // wxStaticBoxSizer
307 //---------------------------------------------------------------------------
308
309 class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer
310 {
311 public:
312 wxStaticBoxSizer( wxStaticBox *box, int orient );
313
314 void RecalcSizes();
315 wxSize CalcMin();
316
317 wxStaticBox *GetStaticBox()
318 { return m_staticBox; }
319
320 protected:
321 wxStaticBox *m_staticBox;
322
323 private:
324 DECLARE_CLASS(wxStaticBoxSizer);
325 };
326
327 //---------------------------------------------------------------------------
328 // wxNotebookSizer
329 //---------------------------------------------------------------------------
330
331 #if wxUSE_NOTEBOOK
332
333 class WXDLLEXPORT wxNotebookSizer: public wxSizer
334 {
335 public:
336 wxNotebookSizer( wxNotebook *nb );
337
338 void RecalcSizes();
339 wxSize CalcMin();
340
341 wxNotebook *GetNotebook()
342 { return m_notebook; }
343
344 protected:
345 wxNotebook *m_notebook;
346
347 private:
348 DECLARE_CLASS(wxNotebookSizer);
349 };
350
351 #endif
352
353
354 #endif
355 // __WXSIZER_H__