]> git.saurik.com Git - wxWidgets.git/blob - include/wx/sizer.h
Updated to version 1.40 of Scintilla
[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 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();
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; }
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; }
100
101 protected:
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
116 private:
117 DECLARE_CLASS(wxSizerItem);
118 };
119
120 //---------------------------------------------------------------------------
121 // wxSizer
122 //---------------------------------------------------------------------------
123
124 class WXDLLEXPORT wxSizer: public wxObject
125 {
126 public:
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 ); }
151
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 ); }
157
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 ); }
163
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 ); }
168
169 wxSize GetSize()
170 { return m_size; }
171 wxPoint GetPosition()
172 { return m_position; }
173
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 );
189
190 protected:
191 wxSize m_size;
192 wxSize m_minSize;
193 wxPoint m_position;
194 wxList m_children;
195
196 wxSize GetMaxWindowSize( wxWindow *window );
197 wxSize GetMinWindowSize( wxWindow *window );
198 wxSize FitSize( wxWindow *window );
199
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 );
204
205 private:
206 DECLARE_CLASS(wxSizer);
207 };
208
209 //---------------------------------------------------------------------------
210 // wxGridSizer
211 //---------------------------------------------------------------------------
212
213 class WXDLLEXPORT wxGridSizer: public wxSizer
214 {
215 public:
216 wxGridSizer( int rows, int cols, int vgap, int hgap );
217 wxGridSizer( int cols, int vgap = 0, int hgap = 0 );
218
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; }
230
231 protected:
232 int m_rows;
233 int m_cols;
234 int m_vgap;
235 int m_hgap;
236
237 void SetItemBounds( wxSizerItem *item, int x, int y, int w, int h );
238
239 private:
240 DECLARE_CLASS(wxGridSizer);
241 };
242
243 //---------------------------------------------------------------------------
244 // wxFlexGridSizer
245 //---------------------------------------------------------------------------
246
247 class WXDLLEXPORT wxFlexGridSizer: public wxGridSizer
248 {
249 public:
250 wxFlexGridSizer( int rows, int cols, int vgap, int hgap );
251 wxFlexGridSizer( int cols, int vgap = 0, int hgap = 0 );
252 ~wxFlexGridSizer();
253
254 void RecalcSizes();
255 wxSize CalcMin();
256
257 void AddGrowableRow( size_t idx );
258 void RemoveGrowableRow( size_t idx );
259 void AddGrowableCol( size_t idx );
260 void RemoveGrowableCol( size_t idx );
261
262 protected:
263 int *m_rowHeights;
264 int *m_colWidths;
265 wxArrayInt m_growableRows;
266 wxArrayInt m_growableCols;
267
268 void CreateArrays();
269
270 private:
271 DECLARE_CLASS(wxFlexGridSizer);
272 };
273
274 //---------------------------------------------------------------------------
275 // wxBoxSizer
276 //---------------------------------------------------------------------------
277
278 class WXDLLEXPORT wxBoxSizer: public wxSizer
279 {
280 public:
281 wxBoxSizer( int orient );
282
283 void RecalcSizes();
284 wxSize CalcMin();
285
286 int GetOrientation()
287 { return m_orient; }
288
289 protected:
290 int m_orient;
291 int m_stretchable;
292 int m_minWidth;
293 int m_minHeight;
294 int m_fixedWidth;
295 int m_fixedHeight;
296
297 private:
298 DECLARE_CLASS(wxBoxSizer);
299 };
300
301 //---------------------------------------------------------------------------
302 // wxStaticBoxSizer
303 //---------------------------------------------------------------------------
304
305 #if wxUSE_STATBOX
306
307 class WXDLLEXPORT wxStaticBox;
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 #endif // wxUSE_STATBOX
328
329 //---------------------------------------------------------------------------
330 // wxNotebookSizer
331 //---------------------------------------------------------------------------
332
333 #if wxUSE_NOTEBOOK
334
335 class WXDLLEXPORT wxNotebook;
336
337 class WXDLLEXPORT wxNotebookSizer: public wxSizer
338 {
339 public:
340 wxNotebookSizer( wxNotebook *nb );
341
342 void RecalcSizes();
343 wxSize CalcMin();
344
345 wxNotebook *GetNotebook()
346 { return m_notebook; }
347
348 protected:
349 wxNotebook *m_notebook;
350
351 private:
352 DECLARE_CLASS(wxNotebookSizer);
353 };
354
355 #endif // wxUSE_NOTEBOOK
356
357
358 #endif
359 // __WXSIZER_H__