]>
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 | ||
af49c4b8 | 15 | #if defined(__GNUG__) && !defined(__APPLE__) |
5279a24d RR |
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 | 52 | |
96fdbb60 RL |
53 | // Enable deleting the SizerItem without destroying the contained sizer. |
54 | void DetachSizer() | |
55 | { m_sizer = 0; } | |
56 | ||
df5ddbca RR |
57 | virtual wxSize GetSize(); |
58 | virtual wxSize CalcMin(); | |
59 | virtual void SetDimension( wxPoint pos, wxSize size ); | |
60 | ||
61 | wxSize GetMinSize() | |
62 | { return m_minSize; } | |
63 | ||
64 | void SetRatio( int width, int height ) | |
65 | // if either of dimensions is zero, ratio is assumed to be 1 | |
66 | // to avoid "divide by zero" errors | |
67 | { m_ratio = (width && height) ? ((float) width / (float) height) : 1; } | |
68 | void SetRatio( wxSize size ) | |
69 | { m_ratio = (size.x && size.y) ? ((float) size.x / (float) size.y) : 1; } | |
2aab8f16 | 70 | void SetRatio( float ratio ) |
df5ddbca | 71 | { m_ratio = ratio; } |
2aab8f16 | 72 | float GetRatio() const |
df5ddbca RR |
73 | { return m_ratio; } |
74 | ||
75 | bool IsWindow(); | |
76 | bool IsSizer(); | |
77 | bool IsSpacer(); | |
2aab8f16 | 78 | |
df5ddbca RR |
79 | void SetInitSize( int x, int y ) |
80 | { m_minSize.x = x; m_minSize.y = y; } | |
81 | void SetOption( int option ) | |
82 | { m_option = option; } | |
83 | void SetFlag( int flag ) | |
84 | { m_flag = flag; } | |
85 | void SetBorder( int border ) | |
86 | { m_border = border; } | |
2b5f62a0 VZ |
87 | void Show ( bool show ) |
88 | { m_show = show; } | |
df5ddbca RR |
89 | |
90 | wxWindow *GetWindow() const | |
91 | { return m_window; } | |
92 | void SetWindow( wxWindow *window ) | |
93 | { m_window = window; } | |
94 | wxSizer *GetSizer() const | |
95 | { return m_sizer; } | |
96 | void SetSizer( wxSizer *sizer ) | |
97 | { m_sizer = sizer; } | |
98 | int GetOption() const | |
99 | { return m_option; } | |
100 | int GetFlag() const | |
101 | { return m_flag; } | |
102 | int GetBorder() const | |
103 | { return m_border; } | |
2b5f62a0 VZ |
104 | bool IsShown() const |
105 | { return m_show; } | |
df5ddbca RR |
106 | wxObject* GetUserData() |
107 | { return m_userData; } | |
108 | wxPoint GetPosition() | |
109 | { return m_pos; } | |
0c0d686f | 110 | |
c62ac5b6 | 111 | protected: |
df5ddbca RR |
112 | wxWindow *m_window; |
113 | wxSizer *m_sizer; | |
114 | wxSize m_size; | |
115 | wxPoint m_pos; | |
116 | wxSize m_minSize; | |
117 | int m_option; | |
118 | int m_border; | |
119 | int m_flag; | |
2b5f62a0 VZ |
120 | |
121 | // If TRUE, then this item is considered in the layout | |
122 | // calculation. Otherwise, it is skipped over. | |
123 | bool m_show; | |
df5ddbca RR |
124 | // als: aspect ratio can always be calculated from m_size, |
125 | // but this would cause precision loss when the window | |
126 | // is shrinked. it is safer to preserve initial value. | |
127 | float m_ratio; | |
2b5f62a0 | 128 | |
df5ddbca | 129 | wxObject *m_userData; |
2aab8f16 | 130 | |
df5ddbca RR |
131 | private: |
132 | DECLARE_CLASS(wxSizerItem); | |
22f3361e | 133 | DECLARE_NO_COPY_CLASS(wxSizerItem) |
c62ac5b6 | 134 | }; |
5279a24d RR |
135 | |
136 | //--------------------------------------------------------------------------- | |
3417c2cd | 137 | // wxSizer |
5279a24d RR |
138 | //--------------------------------------------------------------------------- |
139 | ||
2aab8f16 | 140 | class WXDLLEXPORT wxSizer: public wxObject, public wxClientDataContainer |
5279a24d RR |
141 | { |
142 | public: | |
f6bcfd97 BP |
143 | wxSizer(); |
144 | ~wxSizer(); | |
145 | ||
146 | /* These should be called Append() really. */ | |
147 | virtual void Add( wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); | |
148 | virtual void Add( wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); | |
149 | virtual void Add( int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); | |
150 | ||
151 | virtual void Insert( int before, wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); | |
152 | virtual void Insert( int before, wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); | |
153 | virtual void Insert( int before, int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); | |
154 | ||
155 | virtual void Prepend( wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); | |
156 | virtual void Prepend( wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); | |
157 | virtual void Prepend( int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); | |
158 | ||
00976fe5 | 159 | // Remove will delete a sizer, but not a window. |
f6bcfd97 BP |
160 | virtual bool Remove( wxWindow *window ); |
161 | virtual bool Remove( wxSizer *sizer ); | |
162 | virtual bool Remove( int pos ); | |
00976fe5 RL |
163 | |
164 | // Detach will never destroy a sizer or window. | |
165 | virtual bool Detach( wxWindow *window ) | |
166 | { return Remove( window ); } | |
167 | virtual bool Detach( wxSizer *sizer ); | |
168 | virtual bool Detach( int pos ); | |
169 | ||
84f7908b RR |
170 | virtual void Clear( bool delete_windows=FALSE ); |
171 | virtual void DeleteWindows(); | |
f6bcfd97 BP |
172 | |
173 | void SetMinSize( int width, int height ) | |
174 | { DoSetMinSize( width, height ); } | |
175 | void SetMinSize( wxSize size ) | |
176 | { DoSetMinSize( size.x, size.y ); } | |
1e6feb95 | 177 | |
f6bcfd97 BP |
178 | /* Searches recursively */ |
179 | bool SetItemMinSize( wxWindow *window, int width, int height ) | |
180 | { return DoSetItemMinSize( window, width, height ); } | |
181 | bool SetItemMinSize( wxWindow *window, wxSize size ) | |
182 | { return DoSetItemMinSize( window, size.x, size.y ); } | |
1e6feb95 | 183 | |
f6bcfd97 BP |
184 | /* Searches recursively */ |
185 | bool SetItemMinSize( wxSizer *sizer, int width, int height ) | |
186 | { return DoSetItemMinSize( sizer, width, height ); } | |
187 | bool SetItemMinSize( wxSizer *sizer, wxSize size ) | |
188 | { return DoSetItemMinSize( sizer, size.x, size.y ); } | |
1e6feb95 | 189 | |
f6bcfd97 BP |
190 | bool SetItemMinSize( int pos, int width, int height ) |
191 | { return DoSetItemMinSize( pos, width, height ); } | |
192 | bool SetItemMinSize( int pos, wxSize size ) | |
193 | { return DoSetItemMinSize( pos, size.x, size.y ); } | |
1e6feb95 | 194 | |
f6bcfd97 BP |
195 | wxSize GetSize() |
196 | { return m_size; } | |
197 | wxPoint GetPosition() | |
198 | { return m_position; } | |
1e6feb95 | 199 | |
f6bcfd97 BP |
200 | /* Calculate the minimal size or return m_minSize if bigger. */ |
201 | wxSize GetMinSize(); | |
202 | ||
203 | virtual void RecalcSizes() = 0; | |
204 | virtual wxSize CalcMin() = 0; | |
205 | ||
206 | virtual void Layout(); | |
207 | ||
e5251d4f | 208 | wxSize Fit( wxWindow *window ); |
566d84a7 | 209 | void FitInside( wxWindow *window ); |
f6bcfd97 | 210 | void SetSizeHints( wxWindow *window ); |
566d84a7 | 211 | void SetVirtualSizeHints( wxWindow *window ); |
f6bcfd97 BP |
212 | |
213 | wxList& GetChildren() | |
214 | { return m_children; } | |
215 | ||
216 | void SetDimension( int x, int y, int width, int height ); | |
0c0d686f | 217 | |
2b5f62a0 VZ |
218 | // Manage whether individual windows or sub-sizers are considered |
219 | // in the layout calculations or not. | |
220 | void Show( wxWindow *window, bool show = TRUE ); | |
221 | void Hide( wxWindow *window ) | |
222 | { Show (window, FALSE); } | |
223 | void Show( wxSizer *sizer, bool show = TRUE ); | |
224 | void Hide( wxSizer *sizer ) | |
225 | { Show (sizer, FALSE); } | |
226 | ||
227 | bool IsShown( wxWindow *window ); | |
228 | bool IsShown( wxSizer *sizer ); | |
229 | ||
230 | // Recursively call wxWindow::Show () on all sizer items. | |
231 | void ShowItems (bool show); | |
232 | ||
f6bcfd97 BP |
233 | protected: |
234 | wxSize m_size; | |
235 | wxSize m_minSize; | |
236 | wxPoint m_position; | |
237 | wxList m_children; | |
238 | ||
65ba4113 | 239 | wxSize GetMaxWindowSize( wxWindow *window ); |
f6bcfd97 | 240 | wxSize GetMinWindowSize( wxWindow *window ); |
566d84a7 RL |
241 | wxSize GetMaxClientSize( wxWindow *window ); |
242 | wxSize GetMinClientSize( wxWindow *window ); | |
65ba4113 | 243 | wxSize FitSize( wxWindow *window ); |
566d84a7 | 244 | wxSize VirtualFitSize( wxWindow *window ); |
65ba4113 | 245 | |
f6bcfd97 BP |
246 | virtual void DoSetMinSize( int width, int height ); |
247 | virtual bool DoSetItemMinSize( wxWindow *window, int width, int height ); | |
248 | virtual bool DoSetItemMinSize( wxSizer *sizer, int width, int height ); | |
249 | virtual bool DoSetItemMinSize( int pos, int width, int height ); | |
1e6feb95 | 250 | |
f6bcfd97 BP |
251 | private: |
252 | DECLARE_CLASS(wxSizer); | |
253 | }; | |
c62ac5b6 | 254 | |
f6bcfd97 BP |
255 | //--------------------------------------------------------------------------- |
256 | // wxGridSizer | |
257 | //--------------------------------------------------------------------------- | |
0c0d686f | 258 | |
f6bcfd97 BP |
259 | class WXDLLEXPORT wxGridSizer: public wxSizer |
260 | { | |
261 | public: | |
262 | wxGridSizer( int rows, int cols, int vgap, int hgap ); | |
263 | wxGridSizer( int cols, int vgap = 0, int hgap = 0 ); | |
1e6feb95 | 264 | |
f6bcfd97 BP |
265 | void RecalcSizes(); |
266 | wxSize CalcMin(); | |
267 | ||
268 | void SetCols( int cols ) { m_cols = cols; } | |
269 | void SetRows( int rows ) { m_rows = rows; } | |
270 | void SetVGap( int gap ) { m_vgap = gap; } | |
271 | void SetHGap( int gap ) { m_hgap = gap; } | |
272 | int GetCols() { return m_cols; } | |
273 | int GetRows() { return m_rows; } | |
274 | int GetVGap() { return m_vgap; } | |
275 | int GetHGap() { return m_hgap; } | |
1e6feb95 | 276 | |
f6bcfd97 BP |
277 | protected: |
278 | int m_rows; | |
279 | int m_cols; | |
280 | int m_vgap; | |
281 | int m_hgap; | |
1e6feb95 | 282 | |
0ca5105b VZ |
283 | // return the number of total items and the number of columns and rows |
284 | int CalcRowsCols(int& rows, int& cols) const; | |
285 | ||
f6bcfd97 | 286 | void SetItemBounds( wxSizerItem *item, int x, int y, int w, int h ); |
1e6feb95 | 287 | |
f6bcfd97 BP |
288 | private: |
289 | DECLARE_CLASS(wxGridSizer); | |
290 | }; | |
5279a24d | 291 | |
f6bcfd97 BP |
292 | //--------------------------------------------------------------------------- |
293 | // wxFlexGridSizer | |
294 | //--------------------------------------------------------------------------- | |
0c0d686f | 295 | |
f6bcfd97 BP |
296 | class WXDLLEXPORT wxFlexGridSizer: public wxGridSizer |
297 | { | |
298 | public: | |
299 | wxFlexGridSizer( int rows, int cols, int vgap, int hgap ); | |
300 | wxFlexGridSizer( int cols, int vgap = 0, int hgap = 0 ); | |
301 | ~wxFlexGridSizer(); | |
1e6feb95 | 302 | |
f6bcfd97 BP |
303 | void RecalcSizes(); |
304 | wxSize CalcMin(); | |
1e6feb95 | 305 | |
f6bcfd97 BP |
306 | void AddGrowableRow( size_t idx ); |
307 | void RemoveGrowableRow( size_t idx ); | |
308 | void AddGrowableCol( size_t idx ); | |
309 | void RemoveGrowableCol( size_t idx ); | |
0c0d686f | 310 | |
c62ac5b6 | 311 | protected: |
f6bcfd97 BP |
312 | int *m_rowHeights; |
313 | int *m_colWidths; | |
314 | wxArrayInt m_growableRows; | |
315 | wxArrayInt m_growableCols; | |
1e6feb95 | 316 | |
f6bcfd97 | 317 | void CreateArrays(); |
1e6feb95 | 318 | |
f6bcfd97 BP |
319 | private: |
320 | DECLARE_CLASS(wxFlexGridSizer); | |
22f3361e | 321 | DECLARE_NO_COPY_CLASS(wxFlexGridSizer) |
c62ac5b6 RR |
322 | }; |
323 | ||
324 | //--------------------------------------------------------------------------- | |
92afa2b1 | 325 | // wxBoxSizer |
c62ac5b6 RR |
326 | //--------------------------------------------------------------------------- |
327 | ||
92afa2b1 | 328 | class WXDLLEXPORT wxBoxSizer: public wxSizer |
61d514bb RR |
329 | { |
330 | public: | |
f6bcfd97 | 331 | wxBoxSizer( int orient ); |
0c0d686f | 332 | |
f6bcfd97 BP |
333 | void RecalcSizes(); |
334 | wxSize CalcMin(); | |
0c0d686f | 335 | |
f6bcfd97 BP |
336 | int GetOrientation() |
337 | { return m_orient; } | |
0c0d686f | 338 | |
b657b4c9 JS |
339 | void SetOrientation(int orient) |
340 | { m_orient = orient; } | |
341 | ||
61d514bb RR |
342 | protected: |
343 | int m_orient; | |
344 | int m_stretchable; | |
345 | int m_minWidth; | |
346 | int m_minHeight; | |
347 | int m_fixedWidth; | |
348 | int m_fixedHeight; | |
1e6feb95 | 349 | |
f6bcfd97 BP |
350 | private: |
351 | DECLARE_CLASS(wxBoxSizer); | |
61d514bb | 352 | }; |
0c0d686f | 353 | |
27ea1d8a RR |
354 | //--------------------------------------------------------------------------- |
355 | // wxStaticBoxSizer | |
356 | //--------------------------------------------------------------------------- | |
357 | ||
1e6feb95 VZ |
358 | #if wxUSE_STATBOX |
359 | ||
360 | class WXDLLEXPORT wxStaticBox; | |
361 | ||
27ea1d8a RR |
362 | class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer |
363 | { | |
364 | public: | |
f6bcfd97 | 365 | wxStaticBoxSizer( wxStaticBox *box, int orient ); |
0c0d686f | 366 | |
f6bcfd97 BP |
367 | void RecalcSizes(); |
368 | wxSize CalcMin(); | |
0c0d686f | 369 | |
f6bcfd97 BP |
370 | wxStaticBox *GetStaticBox() |
371 | { return m_staticBox; } | |
0c0d686f | 372 | |
27ea1d8a | 373 | protected: |
f6bcfd97 | 374 | wxStaticBox *m_staticBox; |
1e6feb95 | 375 | |
f6bcfd97 BP |
376 | private: |
377 | DECLARE_CLASS(wxStaticBoxSizer); | |
22f3361e | 378 | DECLARE_NO_COPY_CLASS(wxStaticBoxSizer) |
27ea1d8a RR |
379 | }; |
380 | ||
1e6feb95 VZ |
381 | #endif // wxUSE_STATBOX |
382 | ||
83edc0a5 RR |
383 | //--------------------------------------------------------------------------- |
384 | // wxNotebookSizer | |
385 | //--------------------------------------------------------------------------- | |
386 | ||
65e4f9b9 VS |
387 | #if wxUSE_NOTEBOOK |
388 | ||
1e6feb95 VZ |
389 | class WXDLLEXPORT wxNotebook; |
390 | ||
83edc0a5 RR |
391 | class WXDLLEXPORT wxNotebookSizer: public wxSizer |
392 | { | |
83edc0a5 | 393 | public: |
f6bcfd97 | 394 | wxNotebookSizer( wxNotebook *nb ); |
83edc0a5 | 395 | |
f6bcfd97 BP |
396 | void RecalcSizes(); |
397 | wxSize CalcMin(); | |
83edc0a5 | 398 | |
f6bcfd97 BP |
399 | wxNotebook *GetNotebook() |
400 | { return m_notebook; } | |
83edc0a5 RR |
401 | |
402 | protected: | |
f6bcfd97 | 403 | wxNotebook *m_notebook; |
1e6feb95 | 404 | |
f6bcfd97 BP |
405 | private: |
406 | DECLARE_CLASS(wxNotebookSizer); | |
22f3361e | 407 | DECLARE_NO_COPY_CLASS(wxNotebookSizer) |
83edc0a5 RR |
408 | }; |
409 | ||
1e6feb95 | 410 | #endif // wxUSE_NOTEBOOK |
65e4f9b9 VS |
411 | |
412 | ||
5279a24d RR |
413 | #endif |
414 | // __WXSIZER_H__ |