]>
Commit | Line | Data |
---|---|---|
5279a24d RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: sizer.h | |
0c0d686f | 3 | // Purpose: provide wxSizer class for layouting |
5279a24d | 4 | // Author: Robert Roebling and Robin Dunn |
566d84a7 | 5 | // Modified by: Ron Lee |
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 | ||
3417c2cd RR |
29 | class wxSizerItem; |
30 | class wxSizer; | |
92afa2b1 | 31 | class wxBoxSizer; |
5279a24d RR |
32 | |
33 | //--------------------------------------------------------------------------- | |
3417c2cd | 34 | // wxSizerItem |
5279a24d RR |
35 | //--------------------------------------------------------------------------- |
36 | ||
3417c2cd | 37 | class WXDLLEXPORT wxSizerItem: public wxObject |
5279a24d RR |
38 | { |
39 | public: | |
df5ddbca RR |
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(); | |
84f7908b RR |
50 | |
51 | virtual void DeleteWindows(); | |
df5ddbca RR |
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; } | |
2aab8f16 | 66 | void SetRatio( float ratio ) |
df5ddbca | 67 | { m_ratio = ratio; } |
2aab8f16 | 68 | float GetRatio() const |
df5ddbca RR |
69 | { return m_ratio; } |
70 | ||
71 | bool IsWindow(); | |
72 | bool IsSizer(); | |
73 | bool IsSpacer(); | |
2aab8f16 | 74 | |
df5ddbca RR |
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; } | |
0c0d686f | 102 | |
c62ac5b6 | 103 | protected: |
df5ddbca RR |
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; | |
2aab8f16 | 117 | |
df5ddbca RR |
118 | private: |
119 | DECLARE_CLASS(wxSizerItem); | |
c62ac5b6 | 120 | }; |
5279a24d RR |
121 | |
122 | //--------------------------------------------------------------------------- | |
3417c2cd | 123 | // wxSizer |
5279a24d RR |
124 | //--------------------------------------------------------------------------- |
125 | ||
2aab8f16 | 126 | class WXDLLEXPORT wxSizer: public wxObject, public wxClientDataContainer |
5279a24d RR |
127 | { |
128 | public: | |
f6bcfd97 BP |
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 ); | |
84f7908b RR |
148 | |
149 | virtual void Clear( bool delete_windows=FALSE ); | |
150 | virtual void DeleteWindows(); | |
f6bcfd97 BP |
151 | |
152 | void SetMinSize( int width, int height ) | |
153 | { DoSetMinSize( width, height ); } | |
154 | void SetMinSize( wxSize size ) | |
155 | { DoSetMinSize( size.x, size.y ); } | |
1e6feb95 | 156 | |
f6bcfd97 BP |
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 ); } | |
1e6feb95 | 162 | |
f6bcfd97 BP |
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 ); } | |
1e6feb95 | 168 | |
f6bcfd97 BP |
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 ); } | |
1e6feb95 | 173 | |
f6bcfd97 BP |
174 | wxSize GetSize() |
175 | { return m_size; } | |
176 | wxPoint GetPosition() | |
177 | { return m_position; } | |
1e6feb95 | 178 | |
f6bcfd97 BP |
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 | ||
e5251d4f | 187 | wxSize Fit( wxWindow *window ); |
566d84a7 | 188 | void FitInside( wxWindow *window ); |
f6bcfd97 | 189 | void SetSizeHints( wxWindow *window ); |
566d84a7 | 190 | void SetVirtualSizeHints( wxWindow *window ); |
f6bcfd97 BP |
191 | |
192 | wxList& GetChildren() | |
193 | { return m_children; } | |
194 | ||
195 | void SetDimension( int x, int y, int width, int height ); | |
0c0d686f | 196 | |
f6bcfd97 BP |
197 | protected: |
198 | wxSize m_size; | |
199 | wxSize m_minSize; | |
200 | wxPoint m_position; | |
201 | wxList m_children; | |
202 | ||
65ba4113 | 203 | wxSize GetMaxWindowSize( wxWindow *window ); |
f6bcfd97 | 204 | wxSize GetMinWindowSize( wxWindow *window ); |
566d84a7 RL |
205 | wxSize GetMaxClientSize( wxWindow *window ); |
206 | wxSize GetMinClientSize( wxWindow *window ); | |
65ba4113 | 207 | wxSize FitSize( wxWindow *window ); |
566d84a7 | 208 | wxSize VirtualFitSize( wxWindow *window ); |
65ba4113 | 209 | |
f6bcfd97 BP |
210 | virtual void DoSetMinSize( int width, int height ); |
211 | virtual bool DoSetItemMinSize( wxWindow *window, int width, int height ); | |
212 | virtual bool DoSetItemMinSize( wxSizer *sizer, int width, int height ); | |
213 | virtual bool DoSetItemMinSize( int pos, int width, int height ); | |
1e6feb95 | 214 | |
f6bcfd97 BP |
215 | private: |
216 | DECLARE_CLASS(wxSizer); | |
217 | }; | |
c62ac5b6 | 218 | |
f6bcfd97 BP |
219 | //--------------------------------------------------------------------------- |
220 | // wxGridSizer | |
221 | //--------------------------------------------------------------------------- | |
0c0d686f | 222 | |
f6bcfd97 BP |
223 | class WXDLLEXPORT wxGridSizer: public wxSizer |
224 | { | |
225 | public: | |
226 | wxGridSizer( int rows, int cols, int vgap, int hgap ); | |
227 | wxGridSizer( int cols, int vgap = 0, int hgap = 0 ); | |
1e6feb95 | 228 | |
f6bcfd97 BP |
229 | void RecalcSizes(); |
230 | wxSize CalcMin(); | |
231 | ||
232 | void SetCols( int cols ) { m_cols = cols; } | |
233 | void SetRows( int rows ) { m_rows = rows; } | |
234 | void SetVGap( int gap ) { m_vgap = gap; } | |
235 | void SetHGap( int gap ) { m_hgap = gap; } | |
236 | int GetCols() { return m_cols; } | |
237 | int GetRows() { return m_rows; } | |
238 | int GetVGap() { return m_vgap; } | |
239 | int GetHGap() { return m_hgap; } | |
1e6feb95 | 240 | |
f6bcfd97 BP |
241 | protected: |
242 | int m_rows; | |
243 | int m_cols; | |
244 | int m_vgap; | |
245 | int m_hgap; | |
1e6feb95 | 246 | |
f6bcfd97 | 247 | void SetItemBounds( wxSizerItem *item, int x, int y, int w, int h ); |
1e6feb95 | 248 | |
f6bcfd97 BP |
249 | private: |
250 | DECLARE_CLASS(wxGridSizer); | |
251 | }; | |
5279a24d | 252 | |
f6bcfd97 BP |
253 | //--------------------------------------------------------------------------- |
254 | // wxFlexGridSizer | |
255 | //--------------------------------------------------------------------------- | |
0c0d686f | 256 | |
f6bcfd97 BP |
257 | class WXDLLEXPORT wxFlexGridSizer: public wxGridSizer |
258 | { | |
259 | public: | |
260 | wxFlexGridSizer( int rows, int cols, int vgap, int hgap ); | |
261 | wxFlexGridSizer( int cols, int vgap = 0, int hgap = 0 ); | |
262 | ~wxFlexGridSizer(); | |
1e6feb95 | 263 | |
f6bcfd97 BP |
264 | void RecalcSizes(); |
265 | wxSize CalcMin(); | |
1e6feb95 | 266 | |
f6bcfd97 BP |
267 | void AddGrowableRow( size_t idx ); |
268 | void RemoveGrowableRow( size_t idx ); | |
269 | void AddGrowableCol( size_t idx ); | |
270 | void RemoveGrowableCol( size_t idx ); | |
0c0d686f | 271 | |
c62ac5b6 | 272 | protected: |
f6bcfd97 BP |
273 | int *m_rowHeights; |
274 | int *m_colWidths; | |
275 | wxArrayInt m_growableRows; | |
276 | wxArrayInt m_growableCols; | |
1e6feb95 | 277 | |
f6bcfd97 | 278 | void CreateArrays(); |
1e6feb95 | 279 | |
f6bcfd97 BP |
280 | private: |
281 | DECLARE_CLASS(wxFlexGridSizer); | |
c62ac5b6 RR |
282 | }; |
283 | ||
284 | //--------------------------------------------------------------------------- | |
92afa2b1 | 285 | // wxBoxSizer |
c62ac5b6 RR |
286 | //--------------------------------------------------------------------------- |
287 | ||
92afa2b1 | 288 | class WXDLLEXPORT wxBoxSizer: public wxSizer |
61d514bb RR |
289 | { |
290 | public: | |
f6bcfd97 | 291 | wxBoxSizer( int orient ); |
0c0d686f | 292 | |
f6bcfd97 BP |
293 | void RecalcSizes(); |
294 | wxSize CalcMin(); | |
0c0d686f | 295 | |
f6bcfd97 BP |
296 | int GetOrientation() |
297 | { return m_orient; } | |
0c0d686f | 298 | |
61d514bb RR |
299 | protected: |
300 | int m_orient; | |
301 | int m_stretchable; | |
302 | int m_minWidth; | |
303 | int m_minHeight; | |
304 | int m_fixedWidth; | |
305 | int m_fixedHeight; | |
1e6feb95 | 306 | |
f6bcfd97 BP |
307 | private: |
308 | DECLARE_CLASS(wxBoxSizer); | |
61d514bb | 309 | }; |
0c0d686f | 310 | |
27ea1d8a RR |
311 | //--------------------------------------------------------------------------- |
312 | // wxStaticBoxSizer | |
313 | //--------------------------------------------------------------------------- | |
314 | ||
1e6feb95 VZ |
315 | #if wxUSE_STATBOX |
316 | ||
317 | class WXDLLEXPORT wxStaticBox; | |
318 | ||
27ea1d8a RR |
319 | class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer |
320 | { | |
321 | public: | |
f6bcfd97 | 322 | wxStaticBoxSizer( wxStaticBox *box, int orient ); |
0c0d686f | 323 | |
f6bcfd97 BP |
324 | void RecalcSizes(); |
325 | wxSize CalcMin(); | |
0c0d686f | 326 | |
f6bcfd97 BP |
327 | wxStaticBox *GetStaticBox() |
328 | { return m_staticBox; } | |
0c0d686f | 329 | |
27ea1d8a | 330 | protected: |
f6bcfd97 | 331 | wxStaticBox *m_staticBox; |
1e6feb95 | 332 | |
f6bcfd97 BP |
333 | private: |
334 | DECLARE_CLASS(wxStaticBoxSizer); | |
27ea1d8a RR |
335 | }; |
336 | ||
1e6feb95 VZ |
337 | #endif // wxUSE_STATBOX |
338 | ||
83edc0a5 RR |
339 | //--------------------------------------------------------------------------- |
340 | // wxNotebookSizer | |
341 | //--------------------------------------------------------------------------- | |
342 | ||
65e4f9b9 VS |
343 | #if wxUSE_NOTEBOOK |
344 | ||
1e6feb95 VZ |
345 | class WXDLLEXPORT wxNotebook; |
346 | ||
83edc0a5 RR |
347 | class WXDLLEXPORT wxNotebookSizer: public wxSizer |
348 | { | |
83edc0a5 | 349 | public: |
f6bcfd97 | 350 | wxNotebookSizer( wxNotebook *nb ); |
83edc0a5 | 351 | |
f6bcfd97 BP |
352 | void RecalcSizes(); |
353 | wxSize CalcMin(); | |
83edc0a5 | 354 | |
f6bcfd97 BP |
355 | wxNotebook *GetNotebook() |
356 | { return m_notebook; } | |
83edc0a5 RR |
357 | |
358 | protected: | |
f6bcfd97 | 359 | wxNotebook *m_notebook; |
1e6feb95 | 360 | |
f6bcfd97 BP |
361 | private: |
362 | DECLARE_CLASS(wxNotebookSizer); | |
83edc0a5 RR |
363 | }; |
364 | ||
1e6feb95 | 365 | #endif // wxUSE_NOTEBOOK |
65e4f9b9 VS |
366 | |
367 | ||
5279a24d RR |
368 | #endif |
369 | // __WXSIZER_H__ |