]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: sizer.h | |
3 | // Purpose: provide wxSizer class for layouting | |
4 | // Author: Robert Roebling and Robin Dunn | |
5 | // Modified by: Ron Lee | |
6 | // Created: | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Robin Dunn, Dirk Holtwick and Robert Roebling | |
9 | // (c) 2003, Ron Lee | |
10 | // Licence: wxWindows licence | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | #ifndef __WXSIZER_H__ | |
14 | #define __WXSIZER_H__ | |
15 | ||
16 | #if defined(__GNUG__) && !defined(__APPLE__) | |
17 | #pragma interface "sizer.h" | |
18 | #endif | |
19 | ||
20 | #include "wx/defs.h" | |
21 | ||
22 | #include "wx/window.h" | |
23 | #include "wx/frame.h" | |
24 | #include "wx/dialog.h" | |
25 | ||
26 | //--------------------------------------------------------------------------- | |
27 | // classes | |
28 | //--------------------------------------------------------------------------- | |
29 | ||
30 | class wxSizerItem; | |
31 | class wxSizer; | |
32 | class wxBoxSizer; | |
33 | ||
34 | //--------------------------------------------------------------------------- | |
35 | // wxSizerItem | |
36 | //--------------------------------------------------------------------------- | |
37 | ||
38 | class WXDLLEXPORT wxSizerItem: public wxObject | |
39 | { | |
40 | public: | |
41 | // spacer | |
42 | wxSizerItem( int width, | |
43 | int height, | |
44 | int proportion, | |
45 | int flag, | |
46 | int border, | |
47 | wxObject* userData); | |
48 | ||
49 | // window | |
50 | wxSizerItem( wxWindow *window, | |
51 | int proportion, | |
52 | int flag, | |
53 | int border, | |
54 | wxObject* userData ); | |
55 | ||
56 | // subsizer | |
57 | wxSizerItem( wxSizer *sizer, | |
58 | int proportion, | |
59 | int flag, | |
60 | int border, | |
61 | wxObject* userData ); | |
62 | ||
63 | ~wxSizerItem(); | |
64 | ||
65 | virtual void DeleteWindows(); | |
66 | ||
67 | // Enable deleting the SizerItem without destroying the contained sizer. | |
68 | void DetachSizer() | |
69 | { m_sizer = 0; } | |
70 | ||
71 | virtual wxSize GetSize(); | |
72 | virtual wxSize CalcMin(); | |
73 | virtual void SetDimension( wxPoint pos, wxSize size ); | |
74 | ||
75 | wxSize GetMinSize() | |
76 | { return m_minSize; } | |
77 | void SetInitSize( int x, int y ) | |
78 | { m_minSize.x = x; m_minSize.y = y; } | |
79 | ||
80 | void SetRatio( int width, int height ) | |
81 | // if either of dimensions is zero, ratio is assumed to be 1 | |
82 | // to avoid "divide by zero" errors | |
83 | { m_ratio = (width && height) ? ((float) width / (float) height) : 1; } | |
84 | void SetRatio( wxSize size ) | |
85 | { m_ratio = (size.x && size.y) ? ((float) size.x / (float) size.y) : 1; } | |
86 | void SetRatio( float ratio ) | |
87 | { m_ratio = ratio; } | |
88 | float GetRatio() const | |
89 | { return m_ratio; } | |
90 | ||
91 | bool IsWindow(); | |
92 | bool IsSizer(); | |
93 | bool IsSpacer(); | |
94 | ||
95 | // Deprecated in 2.6, use {G,S}etProportion instead. | |
96 | wxDEPRECATED( void SetOption( int option ) ); | |
97 | wxDEPRECATED( int GetOption() const ); | |
98 | ||
99 | void SetProportion( int proportion ) | |
100 | { m_proportion = proportion; } | |
101 | int GetProportion() const | |
102 | { return m_proportion; } | |
103 | void SetFlag( int flag ) | |
104 | { m_flag = flag; } | |
105 | int GetFlag() const | |
106 | { return m_flag; } | |
107 | void SetBorder( int border ) | |
108 | { m_border = border; } | |
109 | int GetBorder() const | |
110 | { return m_border; } | |
111 | ||
112 | wxWindow *GetWindow() const | |
113 | { return m_window; } | |
114 | void SetWindow( wxWindow *window ) | |
115 | { m_window = window; } | |
116 | wxSizer *GetSizer() const | |
117 | { return m_sizer; } | |
118 | void SetSizer( wxSizer *sizer ) | |
119 | { m_sizer = sizer; } | |
120 | const wxSize &GetSpacer() const | |
121 | { return m_size; } | |
122 | void SetSpacer( const wxSize &size ) | |
123 | { m_size = size; m_minSize = size; } | |
124 | ||
125 | void Show ( bool show ); | |
126 | bool IsShown() const | |
127 | { return m_show; } | |
128 | ||
129 | wxObject* GetUserData() | |
130 | { return m_userData; } | |
131 | wxPoint GetPosition() | |
132 | { return m_pos; } | |
133 | ||
134 | protected: | |
135 | wxWindow *m_window; | |
136 | wxSizer *m_sizer; | |
137 | wxSize m_size; | |
138 | wxPoint m_pos; | |
139 | wxSize m_minSize; | |
140 | int m_proportion; | |
141 | int m_border; | |
142 | int m_flag; | |
143 | ||
144 | // If true, then this item is considered in the layout | |
145 | // calculation. Otherwise, it is skipped over. | |
146 | bool m_show; | |
147 | ||
148 | // Aspect ratio can always be calculated from m_size, | |
149 | // but this would cause precision loss when the window | |
150 | // is shrunk. It is safer to preserve the initial value. | |
151 | float m_ratio; | |
152 | ||
153 | wxObject *m_userData; | |
154 | ||
155 | DECLARE_DYNAMIC_CLASS(wxSizerItem); | |
156 | DECLARE_NO_COPY_CLASS(wxSizerItem) | |
157 | }; | |
158 | ||
159 | WX_DECLARE_EXPORTED_LIST( wxSizerItem, wxSizerItemList ); | |
160 | ||
161 | ||
162 | //--------------------------------------------------------------------------- | |
163 | // wxSizer | |
164 | //--------------------------------------------------------------------------- | |
165 | ||
166 | class WXDLLEXPORT wxSizer: public wxObject, public wxClientDataContainer | |
167 | { | |
168 | public: | |
169 | wxSizer(); | |
170 | ~wxSizer(); | |
171 | ||
172 | /* These should be called Append() really. */ | |
173 | virtual void Add( wxWindow *window, | |
174 | int proportion = 0, | |
175 | int flag = 0, | |
176 | int border = 0, | |
177 | wxObject* userData = NULL ); | |
178 | virtual void Add( wxSizer *sizer, | |
179 | int proportion = 0, | |
180 | int flag = 0, | |
181 | int border = 0, | |
182 | wxObject* userData = NULL ); | |
183 | virtual void Add( int width, | |
184 | int height, | |
185 | int proportion = 0, | |
186 | int flag = 0, | |
187 | int border = 0, | |
188 | wxObject* userData = NULL ); | |
189 | virtual void Add( wxSizerItem *item ); | |
190 | ||
191 | virtual void Insert( size_t index, | |
192 | wxWindow *window, | |
193 | int proportion = 0, | |
194 | int flag = 0, | |
195 | int border = 0, | |
196 | wxObject* userData = NULL ); | |
197 | virtual void Insert( size_t index, | |
198 | wxSizer *sizer, | |
199 | int proportion = 0, | |
200 | int flag = 0, | |
201 | int border = 0, | |
202 | wxObject* userData = NULL ); | |
203 | virtual void Insert( size_t index, | |
204 | int width, | |
205 | int height, | |
206 | int proportion = 0, | |
207 | int flag = 0, | |
208 | int border = 0, | |
209 | wxObject* userData = NULL ); | |
210 | virtual void Insert( size_t index, | |
211 | wxSizerItem *item ); | |
212 | ||
213 | virtual void Prepend( wxWindow *window, | |
214 | int proportion = 0, | |
215 | int flag = 0, | |
216 | int border = 0, | |
217 | wxObject* userData = NULL ); | |
218 | virtual void Prepend( wxSizer *sizer, | |
219 | int proportion = 0, | |
220 | int flag = 0, | |
221 | int border = 0, | |
222 | wxObject* userData = NULL ); | |
223 | virtual void Prepend( int width, | |
224 | int height, | |
225 | int proportion = 0, | |
226 | int flag = 0, | |
227 | int border = 0, | |
228 | wxObject* userData = NULL ); | |
229 | virtual void Prepend( wxSizerItem *item ); | |
230 | ||
231 | // Deprecated in 2.6 since historically it does not delete the window, | |
232 | // use Detach instead. | |
233 | wxDEPRECATED( virtual bool Remove( wxWindow *window ) ); | |
234 | virtual bool Remove( wxSizer *sizer ); | |
235 | virtual bool Remove( size_t index ); | |
236 | ||
237 | virtual bool Detach( wxWindow *window ); | |
238 | virtual bool Detach( wxSizer *sizer ); | |
239 | virtual bool Detach( size_t index ); | |
240 | ||
241 | virtual void Clear( bool delete_windows=false ); | |
242 | virtual void DeleteWindows(); | |
243 | ||
244 | void SetMinSize( int width, int height ) | |
245 | { DoSetMinSize( width, height ); } | |
246 | void SetMinSize( wxSize size ) | |
247 | { DoSetMinSize( size.x, size.y ); } | |
248 | ||
249 | /* Searches recursively */ | |
250 | bool SetItemMinSize( wxWindow *window, int width, int height ) | |
251 | { return DoSetItemMinSize( window, width, height ); } | |
252 | bool SetItemMinSize( wxWindow *window, wxSize size ) | |
253 | { return DoSetItemMinSize( window, size.x, size.y ); } | |
254 | ||
255 | /* Searches recursively */ | |
256 | bool SetItemMinSize( wxSizer *sizer, int width, int height ) | |
257 | { return DoSetItemMinSize( sizer, width, height ); } | |
258 | bool SetItemMinSize( wxSizer *sizer, wxSize size ) | |
259 | { return DoSetItemMinSize( sizer, size.x, size.y ); } | |
260 | ||
261 | bool SetItemMinSize( size_t index, int width, int height ) | |
262 | { return DoSetItemMinSize( index, width, height ); } | |
263 | bool SetItemMinSize( size_t index, wxSize size ) | |
264 | { return DoSetItemMinSize( index, size.x, size.y ); } | |
265 | ||
266 | wxSize GetSize() | |
267 | { return m_size; } | |
268 | wxPoint GetPosition() | |
269 | { return m_position; } | |
270 | ||
271 | /* Calculate the minimal size or return m_minSize if bigger. */ | |
272 | wxSize GetMinSize(); | |
273 | ||
274 | virtual void RecalcSizes() = 0; | |
275 | virtual wxSize CalcMin() = 0; | |
276 | ||
277 | virtual void Layout(); | |
278 | ||
279 | wxSize Fit( wxWindow *window ); | |
280 | void FitInside( wxWindow *window ); | |
281 | void SetSizeHints( wxWindow *window ); | |
282 | void SetVirtualSizeHints( wxWindow *window ); | |
283 | ||
284 | wxSizerItemList& GetChildren() | |
285 | { return m_children; } | |
286 | ||
287 | void SetDimension( int x, int y, int width, int height ); | |
288 | ||
289 | // Manage whether individual scene items are considered | |
290 | // in the layout calculations or not. | |
291 | void Show( wxWindow *window, bool show = true ); | |
292 | void Show( wxSizer *sizer, bool show = true ); | |
293 | void Show( size_t index, bool show = true ); | |
294 | ||
295 | void Hide( wxSizer *sizer ) | |
296 | { Show( sizer, false ); } | |
297 | void Hide( wxWindow *window ) | |
298 | { Show( window, false ); } | |
299 | void Hide( size_t index ) | |
300 | { Show( index, false ); } | |
301 | ||
302 | bool IsShown( wxWindow *window ); | |
303 | bool IsShown( wxSizer *sizer ); | |
304 | bool IsShown( size_t index ); | |
305 | ||
306 | // Recursively call wxWindow::Show () on all sizer items. | |
307 | void ShowItems (bool show); | |
308 | ||
309 | protected: | |
310 | wxSize m_size; | |
311 | wxSize m_minSize; | |
312 | wxPoint m_position; | |
313 | wxSizerItemList m_children; | |
314 | ||
315 | wxSize GetMaxWindowSize( wxWindow *window ); | |
316 | wxSize GetMinWindowSize( wxWindow *window ); | |
317 | wxSize GetMaxClientSize( wxWindow *window ); | |
318 | wxSize GetMinClientSize( wxWindow *window ); | |
319 | wxSize FitSize( wxWindow *window ); | |
320 | wxSize VirtualFitSize( wxWindow *window ); | |
321 | ||
322 | virtual void DoSetMinSize( int width, int height ); | |
323 | virtual bool DoSetItemMinSize( wxWindow *window, int width, int height ); | |
324 | virtual bool DoSetItemMinSize( wxSizer *sizer, int width, int height ); | |
325 | virtual bool DoSetItemMinSize( size_t index, int width, int height ); | |
326 | ||
327 | DECLARE_DYNAMIC_CLASS(wxSizer); | |
328 | }; | |
329 | ||
330 | //--------------------------------------------------------------------------- | |
331 | // wxGridSizer | |
332 | //--------------------------------------------------------------------------- | |
333 | ||
334 | class WXDLLEXPORT wxGridSizer: public wxSizer | |
335 | { | |
336 | public: | |
337 | wxGridSizer( int rows, int cols, int vgap, int hgap ); | |
338 | wxGridSizer( int cols, int vgap = 0, int hgap = 0 ); | |
339 | ||
340 | void RecalcSizes(); | |
341 | wxSize CalcMin(); | |
342 | ||
343 | void SetCols( int cols ) { m_cols = cols; } | |
344 | void SetRows( int rows ) { m_rows = rows; } | |
345 | void SetVGap( int gap ) { m_vgap = gap; } | |
346 | void SetHGap( int gap ) { m_hgap = gap; } | |
347 | int GetCols() { return m_cols; } | |
348 | int GetRows() { return m_rows; } | |
349 | int GetVGap() { return m_vgap; } | |
350 | int GetHGap() { return m_hgap; } | |
351 | ||
352 | protected: | |
353 | int m_rows; | |
354 | int m_cols; | |
355 | int m_vgap; | |
356 | int m_hgap; | |
357 | ||
358 | // return the number of total items and the number of columns and rows | |
359 | int CalcRowsCols(int& rows, int& cols) const; | |
360 | ||
361 | void SetItemBounds( wxSizerItem *item, int x, int y, int w, int h ); | |
362 | ||
363 | DECLARE_DYNAMIC_CLASS(wxGridSizer); | |
364 | }; | |
365 | ||
366 | //--------------------------------------------------------------------------- | |
367 | // wxFlexGridSizer | |
368 | //--------------------------------------------------------------------------- | |
369 | ||
370 | class WXDLLEXPORT wxFlexGridSizer: public wxGridSizer | |
371 | { | |
372 | public: | |
373 | wxFlexGridSizer( int rows, int cols, int vgap, int hgap ); | |
374 | wxFlexGridSizer( int cols, int vgap = 0, int hgap = 0 ); | |
375 | ~wxFlexGridSizer(); | |
376 | ||
377 | void RecalcSizes(); | |
378 | wxSize CalcMin(); | |
379 | ||
380 | void AddGrowableRow( size_t idx ); | |
381 | void RemoveGrowableRow( size_t idx ); | |
382 | void AddGrowableCol( size_t idx ); | |
383 | void RemoveGrowableCol( size_t idx ); | |
384 | ||
385 | protected: | |
386 | int *m_rowHeights; | |
387 | int *m_colWidths; | |
388 | wxArrayInt m_growableRows; | |
389 | wxArrayInt m_growableCols; | |
390 | ||
391 | void CreateArrays(); | |
392 | ||
393 | DECLARE_DYNAMIC_CLASS(wxFlexGridSizer); | |
394 | DECLARE_NO_COPY_CLASS(wxFlexGridSizer) | |
395 | }; | |
396 | ||
397 | //--------------------------------------------------------------------------- | |
398 | // wxBoxSizer | |
399 | //--------------------------------------------------------------------------- | |
400 | ||
401 | class WXDLLEXPORT wxBoxSizer: public wxSizer | |
402 | { | |
403 | public: | |
404 | wxBoxSizer( int orient ); | |
405 | ||
406 | void RecalcSizes(); | |
407 | wxSize CalcMin(); | |
408 | ||
409 | int GetOrientation() | |
410 | { return m_orient; } | |
411 | ||
412 | void SetOrientation(int orient) | |
413 | { m_orient = orient; } | |
414 | ||
415 | protected: | |
416 | int m_orient; | |
417 | int m_stretchable; | |
418 | int m_minWidth; | |
419 | int m_minHeight; | |
420 | int m_fixedWidth; | |
421 | int m_fixedHeight; | |
422 | ||
423 | DECLARE_DYNAMIC_CLASS(wxBoxSizer); | |
424 | }; | |
425 | ||
426 | //--------------------------------------------------------------------------- | |
427 | // wxStaticBoxSizer | |
428 | //--------------------------------------------------------------------------- | |
429 | ||
430 | #if wxUSE_STATBOX | |
431 | ||
432 | class WXDLLEXPORT wxStaticBox; | |
433 | ||
434 | class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer | |
435 | { | |
436 | public: | |
437 | wxStaticBoxSizer( wxStaticBox *box, int orient ); | |
438 | ||
439 | void RecalcSizes(); | |
440 | wxSize CalcMin(); | |
441 | ||
442 | wxStaticBox *GetStaticBox() | |
443 | { return m_staticBox; } | |
444 | ||
445 | protected: | |
446 | wxStaticBox *m_staticBox; | |
447 | ||
448 | DECLARE_DYNAMIC_CLASS(wxStaticBoxSizer); | |
449 | DECLARE_NO_COPY_CLASS(wxStaticBoxSizer) | |
450 | }; | |
451 | ||
452 | #endif // wxUSE_STATBOX | |
453 | ||
454 | //--------------------------------------------------------------------------- | |
455 | // wxNotebookSizer | |
456 | //--------------------------------------------------------------------------- | |
457 | ||
458 | #if wxUSE_NOTEBOOK | |
459 | ||
460 | class WXDLLEXPORT wxNotebook; | |
461 | ||
462 | class WXDLLEXPORT wxNotebookSizer: public wxSizer | |
463 | { | |
464 | public: | |
465 | wxNotebookSizer( wxNotebook *nb ); | |
466 | ||
467 | void RecalcSizes(); | |
468 | wxSize CalcMin(); | |
469 | ||
470 | wxNotebook *GetNotebook() | |
471 | { return m_notebook; } | |
472 | ||
473 | protected: | |
474 | wxNotebook *m_notebook; | |
475 | ||
476 | DECLARE_DYNAMIC_CLASS(wxNotebookSizer); | |
477 | DECLARE_NO_COPY_CLASS(wxNotebookSizer) | |
478 | }; | |
479 | ||
480 | #endif // wxUSE_NOTEBOOK | |
481 | ||
482 | ||
483 | #endif | |
484 | // __WXSIZER_H__ |