]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: sizer.h | |
3 | // Purpose: provide wxSizer class for layout | |
4 | // Author: Robert Roebling and Robin Dunn | |
5 | // Modified by: Ron Lee, Vadim Zeitlin (wxSizerFlags) | |
6 | // Created: | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Robin Dunn, Robert Roebling | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef __WXSIZER_H__ | |
13 | #define __WXSIZER_H__ | |
14 | ||
15 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) | |
16 | #pragma interface "sizer.h" | |
17 | #endif | |
18 | ||
19 | #include "wx/defs.h" | |
20 | ||
21 | #include "wx/button.h" | |
22 | #include "wx/window.h" | |
23 | #include "wx/frame.h" | |
24 | #include "wx/dialog.h" | |
25 | #include "wx/bookctrl.h" | |
26 | ||
27 | //--------------------------------------------------------------------------- | |
28 | // classes | |
29 | //--------------------------------------------------------------------------- | |
30 | ||
31 | class WXDLLEXPORT wxSizerItem; | |
32 | class WXDLLEXPORT wxSizer; | |
33 | class WXDLLEXPORT wxBoxSizer; | |
34 | ||
35 | ||
36 | // ---------------------------------------------------------------------------- | |
37 | // wxSizerFlags: flags used for an item in the sizer | |
38 | // ---------------------------------------------------------------------------- | |
39 | ||
40 | class WXDLLEXPORT wxSizerFlags | |
41 | { | |
42 | public: | |
43 | // construct the flags object initialized with the given proportion (0 by | |
44 | // default) | |
45 | wxSizerFlags(int proportion = 0) : m_proportion(proportion) | |
46 | { | |
47 | m_flags = 0; | |
48 | m_borderInPixels = 0; | |
49 | } | |
50 | ||
51 | // setters for all sizer flags, they all return the object itself so that | |
52 | // calls to them can be chained | |
53 | ||
54 | wxSizerFlags& Proportion(int proportion) | |
55 | { | |
56 | m_proportion = proportion; | |
57 | return *this; | |
58 | } | |
59 | ||
60 | wxSizerFlags& Align(int alignment) // combination of wxAlignment values | |
61 | { | |
62 | m_flags &= wxALL; | |
63 | m_flags |= alignment; | |
64 | ||
65 | return *this; | |
66 | } | |
67 | ||
68 | // some shortcuts for Align() | |
69 | wxSizerFlags& Expand() { return Align(wxEXPAND); } | |
70 | wxSizerFlags& Centre() { return Align(wxCENTRE); } | |
71 | wxSizerFlags& Center() { return Centre(); } | |
72 | ||
73 | ||
74 | wxSizerFlags& Border(int direction, int borderInPixels) | |
75 | { | |
76 | m_flags &= ~wxALL; | |
77 | m_flags |= direction; | |
78 | ||
79 | m_borderInPixels = borderInPixels; | |
80 | ||
81 | return *this; | |
82 | } | |
83 | ||
84 | wxSizerFlags& Border(int direction = wxALL) | |
85 | { | |
86 | // FIXME: default border size shouldn't be hardcoded | |
87 | return Border(direction, 5); | |
88 | } | |
89 | ||
90 | ||
91 | // accessors for wxSizer only | |
92 | int GetProportion() const { return m_proportion; } | |
93 | int GetFlags() const { return m_flags; } | |
94 | int GetBorderInPixels() const { return m_borderInPixels; } | |
95 | ||
96 | private: | |
97 | int m_proportion; | |
98 | int m_flags; | |
99 | int m_borderInPixels; | |
100 | }; | |
101 | ||
102 | ||
103 | //--------------------------------------------------------------------------- | |
104 | // wxSizerItem | |
105 | //--------------------------------------------------------------------------- | |
106 | ||
107 | class WXDLLEXPORT wxSizerItem: public wxObject | |
108 | { | |
109 | public: | |
110 | // window with flags | |
111 | wxSizerItem(wxWindow *window, const wxSizerFlags& flags) | |
112 | { | |
113 | Init(flags); | |
114 | ||
115 | m_window = window; | |
116 | } | |
117 | ||
118 | // sizer with flags | |
119 | wxSizerItem(wxSizer *sizer, const wxSizerFlags& flags) | |
120 | { | |
121 | Init(flags); | |
122 | ||
123 | m_sizer = sizer; | |
124 | } | |
125 | ||
126 | // window | |
127 | wxSizerItem( wxWindow *window, | |
128 | int proportion, | |
129 | int flag, | |
130 | int border, | |
131 | wxObject* userData ); | |
132 | ||
133 | // subsizer | |
134 | wxSizerItem( wxSizer *sizer, | |
135 | int proportion, | |
136 | int flag, | |
137 | int border, | |
138 | wxObject* userData ); | |
139 | ||
140 | // spacer | |
141 | wxSizerItem( int width, | |
142 | int height, | |
143 | int proportion, | |
144 | int flag, | |
145 | int border, | |
146 | wxObject* userData); | |
147 | ||
148 | wxSizerItem(); | |
149 | virtual ~wxSizerItem(); | |
150 | ||
151 | virtual void DeleteWindows(); | |
152 | ||
153 | // Enable deleting the SizerItem without destroying the contained sizer. | |
154 | void DetachSizer() | |
155 | { m_sizer = 0; } | |
156 | ||
157 | virtual wxSize GetSize() const; | |
158 | virtual wxSize CalcMin(); | |
159 | virtual void SetDimension( wxPoint pos, wxSize size ); | |
160 | ||
161 | wxSize GetMinSize() const | |
162 | { return m_minSize; } | |
163 | wxSize GetMinSizeWithBorder() const; | |
164 | ||
165 | void SetMinSize(const wxSize& size) | |
166 | { | |
167 | if (IsWindow()) m_window->SetMinSize(size); | |
168 | m_minSize = size; | |
169 | } | |
170 | void SetMinSize( int x, int y ) | |
171 | { SetMinSize(wxSize(x, y)); } | |
172 | void SetInitSize( int x, int y ) | |
173 | { SetMinSize(wxSize(x, y)); } | |
174 | ||
175 | void SetRatio( int width, int height ) | |
176 | // if either of dimensions is zero, ratio is assumed to be 1 | |
177 | // to avoid "divide by zero" errors | |
178 | { m_ratio = (width && height) ? ((float) width / (float) height) : 1; } | |
179 | void SetRatio( wxSize size ) | |
180 | { m_ratio = (size.x && size.y) ? ((float) size.x / (float) size.y) : 1; } | |
181 | void SetRatio( float ratio ) | |
182 | { m_ratio = ratio; } | |
183 | float GetRatio() const | |
184 | { return m_ratio; } | |
185 | ||
186 | virtual wxRect GetRect() { return m_zoneRect; } | |
187 | ||
188 | bool IsWindow() const; | |
189 | bool IsSizer() const; | |
190 | bool IsSpacer() const; | |
191 | ||
192 | // Deprecated in 2.6, use {G,S}etProportion instead. | |
193 | wxDEPRECATED( void SetOption( int option ) ); | |
194 | wxDEPRECATED( int GetOption() const ); | |
195 | ||
196 | void SetProportion( int proportion ) | |
197 | { m_proportion = proportion; } | |
198 | int GetProportion() const | |
199 | { return m_proportion; } | |
200 | void SetFlag( int flag ) | |
201 | { m_flag = flag; } | |
202 | int GetFlag() const | |
203 | { return m_flag; } | |
204 | void SetBorder( int border ) | |
205 | { m_border = border; } | |
206 | int GetBorder() const | |
207 | { return m_border; } | |
208 | ||
209 | wxWindow *GetWindow() const | |
210 | { return m_window; } | |
211 | void SetWindow( wxWindow *window ) | |
212 | { m_window = window; m_minSize = window->GetSize(); } | |
213 | wxSizer *GetSizer() const | |
214 | { return m_sizer; } | |
215 | void SetSizer( wxSizer *sizer ) | |
216 | { m_sizer = sizer; } | |
217 | const wxSize &GetSpacer() const | |
218 | { return m_size; } | |
219 | void SetSpacer( const wxSize &size ) | |
220 | { m_size = size; m_minSize = size; } | |
221 | ||
222 | void Show ( bool show ); | |
223 | bool IsShown() const | |
224 | { return m_show; } | |
225 | ||
226 | wxObject* GetUserData() const | |
227 | { return m_userData; } | |
228 | wxPoint GetPosition() const | |
229 | { return m_pos; } | |
230 | ||
231 | protected: | |
232 | // common part of several ctors | |
233 | void Init(); | |
234 | ||
235 | // common part of ctors taking wxSizerFlags | |
236 | void Init(const wxSizerFlags& flags); | |
237 | ||
238 | ||
239 | wxWindow *m_window; | |
240 | wxSizer *m_sizer; | |
241 | wxSize m_size; | |
242 | wxPoint m_pos; | |
243 | wxSize m_minSize; | |
244 | int m_proportion; | |
245 | int m_border; | |
246 | int m_flag; | |
247 | wxRect m_zoneRect; // Rectangle for window or item (not including borders) | |
248 | ||
249 | // If true, then this item is considered in the layout | |
250 | // calculation. Otherwise, it is skipped over. | |
251 | bool m_show; | |
252 | ||
253 | // Aspect ratio can always be calculated from m_size, | |
254 | // but this would cause precision loss when the window | |
255 | // is shrunk. It is safer to preserve the initial value. | |
256 | float m_ratio; | |
257 | ||
258 | wxObject *m_userData; | |
259 | ||
260 | private: | |
261 | DECLARE_CLASS(wxSizerItem) | |
262 | DECLARE_NO_COPY_CLASS(wxSizerItem) | |
263 | }; | |
264 | ||
265 | WX_DECLARE_EXPORTED_LIST( wxSizerItem, wxSizerItemList ); | |
266 | ||
267 | ||
268 | //--------------------------------------------------------------------------- | |
269 | // wxSizer | |
270 | //--------------------------------------------------------------------------- | |
271 | ||
272 | class WXDLLEXPORT wxSizer: public wxObject, public wxClientDataContainer | |
273 | { | |
274 | public: | |
275 | wxSizer(); | |
276 | ~wxSizer(); | |
277 | ||
278 | // methods for adding elements to the sizer: there are Add/Insert/Prepend | |
279 | // overloads for each of window/sizer/spacer/wxSizerItem | |
280 | inline wxSizerItem* Add( wxWindow *window, | |
281 | int proportion = 0, | |
282 | int flag = 0, | |
283 | int border = 0, | |
284 | wxObject* userData = NULL ); | |
285 | inline wxSizerItem* Add( wxSizer *sizer, | |
286 | int proportion = 0, | |
287 | int flag = 0, | |
288 | int border = 0, | |
289 | wxObject* userData = NULL ); | |
290 | inline wxSizerItem* Add( int width, | |
291 | int height, | |
292 | int proportion = 0, | |
293 | int flag = 0, | |
294 | int border = 0, | |
295 | wxObject* userData = NULL ); | |
296 | inline wxSizerItem* Add( wxWindow *window, const wxSizerFlags& flags ); | |
297 | inline wxSizerItem* Add( wxSizer *sizer, const wxSizerFlags& flags ); | |
298 | inline wxSizerItem* Add( wxSizerItem *item ); | |
299 | ||
300 | inline wxSizerItem* AddSpacer(int size); | |
301 | inline wxSizerItem* AddStretchSpacer(int prop = 1); | |
302 | ||
303 | inline wxSizerItem* Insert( size_t index, | |
304 | wxWindow *window, | |
305 | int proportion = 0, | |
306 | int flag = 0, | |
307 | int border = 0, | |
308 | wxObject* userData = NULL ); | |
309 | inline wxSizerItem* Insert( size_t index, | |
310 | wxSizer *sizer, | |
311 | int proportion = 0, | |
312 | int flag = 0, | |
313 | int border = 0, | |
314 | wxObject* userData = NULL ); | |
315 | inline wxSizerItem* Insert( size_t index, | |
316 | int width, | |
317 | int height, | |
318 | int proportion = 0, | |
319 | int flag = 0, | |
320 | int border = 0, | |
321 | wxObject* userData = NULL ); | |
322 | inline wxSizerItem* Insert( size_t index, | |
323 | wxWindow *window, | |
324 | const wxSizerFlags& flags ); | |
325 | inline wxSizerItem* Insert( size_t index, | |
326 | wxSizer *sizer, | |
327 | const wxSizerFlags& flags ); | |
328 | virtual wxSizerItem* Insert( size_t index, wxSizerItem *item ); | |
329 | ||
330 | inline wxSizerItem* InsertSpacer(size_t index, int size); | |
331 | inline wxSizerItem* InsertStretchSpacer(size_t index, int prop = 1); | |
332 | ||
333 | inline wxSizerItem* Prepend( wxWindow *window, | |
334 | int proportion = 0, | |
335 | int flag = 0, | |
336 | int border = 0, | |
337 | wxObject* userData = NULL ); | |
338 | inline wxSizerItem* Prepend( wxSizer *sizer, | |
339 | int proportion = 0, | |
340 | int flag = 0, | |
341 | int border = 0, | |
342 | wxObject* userData = NULL ); | |
343 | inline wxSizerItem* Prepend( int width, | |
344 | int height, | |
345 | int proportion = 0, | |
346 | int flag = 0, | |
347 | int border = 0, | |
348 | wxObject* userData = NULL ); | |
349 | inline wxSizerItem* Prepend( wxWindow *window, const wxSizerFlags& flags ); | |
350 | inline wxSizerItem* Prepend( wxSizer *sizer, const wxSizerFlags& flags ); | |
351 | inline wxSizerItem* Prepend( wxSizerItem *item ); | |
352 | ||
353 | inline wxSizerItem* PrependSpacer(int size); | |
354 | inline wxSizerItem* PrependStretchSpacer(int prop = 1); | |
355 | ||
356 | ||
357 | // Deprecated in 2.6 since historically it does not delete the window, | |
358 | // use Detach instead. | |
359 | wxDEPRECATED( virtual bool Remove( wxWindow *window ) ); | |
360 | virtual bool Remove( wxSizer *sizer ); | |
361 | virtual bool Remove( int index ); | |
362 | ||
363 | virtual bool Detach( wxWindow *window ); | |
364 | virtual bool Detach( wxSizer *sizer ); | |
365 | virtual bool Detach( int index ); | |
366 | ||
367 | virtual void Clear( bool delete_windows = false ); | |
368 | virtual void DeleteWindows(); | |
369 | ||
370 | void SetMinSize( int width, int height ) | |
371 | { DoSetMinSize( width, height ); } | |
372 | void SetMinSize( wxSize size ) | |
373 | { DoSetMinSize( size.x, size.y ); } | |
374 | ||
375 | /* Searches recursively */ | |
376 | bool SetItemMinSize( wxWindow *window, int width, int height ) | |
377 | { return DoSetItemMinSize( window, width, height ); } | |
378 | bool SetItemMinSize( wxWindow *window, wxSize size ) | |
379 | { return DoSetItemMinSize( window, size.x, size.y ); } | |
380 | ||
381 | /* Searches recursively */ | |
382 | bool SetItemMinSize( wxSizer *sizer, int width, int height ) | |
383 | { return DoSetItemMinSize( sizer, width, height ); } | |
384 | bool SetItemMinSize( wxSizer *sizer, wxSize size ) | |
385 | { return DoSetItemMinSize( sizer, size.x, size.y ); } | |
386 | ||
387 | bool SetItemMinSize( size_t index, int width, int height ) | |
388 | { return DoSetItemMinSize( index, width, height ); } | |
389 | bool SetItemMinSize( size_t index, wxSize size ) | |
390 | { return DoSetItemMinSize( index, size.x, size.y ); } | |
391 | ||
392 | wxSize GetSize() const | |
393 | { return m_size; } | |
394 | wxPoint GetPosition() const | |
395 | { return m_position; } | |
396 | ||
397 | /* Calculate the minimal size or return m_minSize if bigger. */ | |
398 | wxSize GetMinSize(); | |
399 | ||
400 | virtual void RecalcSizes() = 0; | |
401 | virtual wxSize CalcMin() = 0; | |
402 | ||
403 | virtual void Layout(); | |
404 | ||
405 | wxSize Fit( wxWindow *window ); | |
406 | void FitInside( wxWindow *window ); | |
407 | void SetSizeHints( wxWindow *window ); | |
408 | void SetVirtualSizeHints( wxWindow *window ); | |
409 | ||
410 | wxSizerItemList& GetChildren() | |
411 | { return m_children; } | |
412 | ||
413 | void SetDimension( int x, int y, int width, int height ); | |
414 | ||
415 | wxSizerItem* GetItem( wxWindow *window, bool recursive = false ); | |
416 | wxSizerItem* GetItem( wxSizer *sizer, bool recursive = false ); | |
417 | wxSizerItem* GetItem( size_t index ); | |
418 | ||
419 | // Manage whether individual scene items are considered | |
420 | // in the layout calculations or not. | |
421 | bool Show( wxWindow *window, bool show = true, bool recursive = false ); | |
422 | bool Show( wxSizer *sizer, bool show = true, bool recursive = false ); | |
423 | bool Show( size_t index, bool show = true ); | |
424 | ||
425 | bool Hide( wxSizer *sizer, bool recursive = false ) | |
426 | { return Show( sizer, false, recursive ); } | |
427 | bool Hide( wxWindow *window, bool recursive = false ) | |
428 | { return Show( window, false, recursive ); } | |
429 | bool Hide( size_t index ) | |
430 | { return Show( index, false ); } | |
431 | ||
432 | bool IsShown( wxWindow *window ) const; | |
433 | bool IsShown( wxSizer *sizer ) const; | |
434 | bool IsShown( size_t index ) const; | |
435 | ||
436 | // Recursively call wxWindow::Show () on all sizer items. | |
437 | virtual void ShowItems (bool show); | |
438 | ||
439 | protected: | |
440 | wxSize m_size; | |
441 | wxSize m_minSize; | |
442 | wxPoint m_position; | |
443 | wxSizerItemList m_children; | |
444 | ||
445 | wxSize GetMaxWindowSize( wxWindow *window ) const; | |
446 | wxSize GetMinWindowSize( wxWindow *window ); | |
447 | wxSize GetMaxClientSize( wxWindow *window ) const; | |
448 | wxSize GetMinClientSize( wxWindow *window ); | |
449 | wxSize FitSize( wxWindow *window ); | |
450 | wxSize VirtualFitSize( wxWindow *window ); | |
451 | ||
452 | virtual void DoSetMinSize( int width, int height ); | |
453 | virtual bool DoSetItemMinSize( wxWindow *window, int width, int height ); | |
454 | virtual bool DoSetItemMinSize( wxSizer *sizer, int width, int height ); | |
455 | virtual bool DoSetItemMinSize( size_t index, int width, int height ); | |
456 | ||
457 | private: | |
458 | DECLARE_CLASS(wxSizer) | |
459 | }; | |
460 | ||
461 | //--------------------------------------------------------------------------- | |
462 | // wxGridSizer | |
463 | //--------------------------------------------------------------------------- | |
464 | ||
465 | class WXDLLEXPORT wxGridSizer: public wxSizer | |
466 | { | |
467 | public: | |
468 | wxGridSizer( int rows, int cols, int vgap, int hgap ); | |
469 | wxGridSizer( int cols, int vgap = 0, int hgap = 0 ); | |
470 | ||
471 | virtual void RecalcSizes(); | |
472 | virtual wxSize CalcMin(); | |
473 | ||
474 | void SetCols( int cols ) { m_cols = cols; } | |
475 | void SetRows( int rows ) { m_rows = rows; } | |
476 | void SetVGap( int gap ) { m_vgap = gap; } | |
477 | void SetHGap( int gap ) { m_hgap = gap; } | |
478 | int GetCols() const { return m_cols; } | |
479 | int GetRows() const { return m_rows; } | |
480 | int GetVGap() const { return m_vgap; } | |
481 | int GetHGap() const { return m_hgap; } | |
482 | ||
483 | protected: | |
484 | int m_rows; | |
485 | int m_cols; | |
486 | int m_vgap; | |
487 | int m_hgap; | |
488 | ||
489 | // return the number of total items and the number of columns and rows | |
490 | int CalcRowsCols(int& rows, int& cols) const; | |
491 | ||
492 | void SetItemBounds( wxSizerItem *item, int x, int y, int w, int h ); | |
493 | ||
494 | private: | |
495 | DECLARE_CLASS(wxGridSizer) | |
496 | }; | |
497 | ||
498 | //--------------------------------------------------------------------------- | |
499 | // wxFlexGridSizer | |
500 | //--------------------------------------------------------------------------- | |
501 | ||
502 | // the bevaiour for resizing wxFlexGridSizer cells in the "non-flexible" | |
503 | // direction | |
504 | enum wxFlexSizerGrowMode | |
505 | { | |
506 | // don't resize the cells in non-flexible direction at all | |
507 | wxFLEX_GROWMODE_NONE, | |
508 | ||
509 | // uniformly resize only the specified ones (default) | |
510 | wxFLEX_GROWMODE_SPECIFIED, | |
511 | ||
512 | // uniformly resize all cells | |
513 | wxFLEX_GROWMODE_ALL | |
514 | }; | |
515 | ||
516 | class WXDLLEXPORT wxFlexGridSizer: public wxGridSizer | |
517 | { | |
518 | public: | |
519 | // ctors/dtor | |
520 | wxFlexGridSizer( int rows, int cols, int vgap, int hgap ); | |
521 | wxFlexGridSizer( int cols, int vgap = 0, int hgap = 0 ); | |
522 | virtual ~wxFlexGridSizer(); | |
523 | ||
524 | ||
525 | // set the rows/columns which will grow (the others will remain of the | |
526 | // constant initial size) | |
527 | void AddGrowableRow( size_t idx, int proportion = 0 ); | |
528 | void RemoveGrowableRow( size_t idx ); | |
529 | void AddGrowableCol( size_t idx, int proportion = 0 ); | |
530 | void RemoveGrowableCol( size_t idx ); | |
531 | ||
532 | ||
533 | // the sizer cells may grow in both directions, not grow at all or only | |
534 | // grow in one direction but not the other | |
535 | ||
536 | // the direction may be wxVERTICAL, wxHORIZONTAL or wxBOTH (default) | |
537 | void SetFlexibleDirection(int direction) { m_flexDirection = direction; } | |
538 | int GetFlexibleDirection() const { return m_flexDirection; } | |
539 | ||
540 | // note that the grow mode only applies to the direction which is not | |
541 | // flexible | |
542 | void SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode) { m_growMode = mode; } | |
543 | wxFlexSizerGrowMode GetNonFlexibleGrowMode() const { return m_growMode; } | |
544 | ||
545 | // Read-only access to the row heights and col widths arrays | |
546 | const wxArrayInt& GetRowHeights() const { return m_rowHeights; } | |
547 | const wxArrayInt& GetColWidths() const { return m_colWidths; } | |
548 | ||
549 | // implementation | |
550 | virtual void RecalcSizes(); | |
551 | virtual wxSize CalcMin(); | |
552 | ||
553 | protected: | |
554 | void AdjustForFlexDirection(); | |
555 | void AdjustForGrowables(const wxSize& sz, const wxSize& minsz, | |
556 | int nrows, int ncols); | |
557 | ||
558 | // the heights/widths of all rows/columns | |
559 | wxArrayInt m_rowHeights, | |
560 | m_colWidths; | |
561 | ||
562 | // indices of the growable columns and rows | |
563 | wxArrayInt m_growableRows, | |
564 | m_growableCols; | |
565 | ||
566 | // proportion values of the corresponding growable rows and columns | |
567 | wxArrayInt m_growableRowsProportions, | |
568 | m_growableColsProportions; | |
569 | ||
570 | // parameters describing whether the growable cells should be resized in | |
571 | // both directions or only one | |
572 | int m_flexDirection; | |
573 | wxFlexSizerGrowMode m_growMode; | |
574 | ||
575 | // saves CalcMin result to optimize RecalcSizes | |
576 | wxSize m_calculatedMinSize; | |
577 | ||
578 | private: | |
579 | DECLARE_CLASS(wxFlexGridSizer) | |
580 | DECLARE_NO_COPY_CLASS(wxFlexGridSizer) | |
581 | }; | |
582 | ||
583 | //--------------------------------------------------------------------------- | |
584 | // wxBoxSizer | |
585 | //--------------------------------------------------------------------------- | |
586 | ||
587 | class WXDLLEXPORT wxBoxSizer: public wxSizer | |
588 | { | |
589 | public: | |
590 | wxBoxSizer( int orient ); | |
591 | ||
592 | void RecalcSizes(); | |
593 | wxSize CalcMin(); | |
594 | ||
595 | int GetOrientation() const | |
596 | { return m_orient; } | |
597 | ||
598 | void SetOrientation(int orient) | |
599 | { m_orient = orient; } | |
600 | ||
601 | protected: | |
602 | int m_orient; | |
603 | int m_stretchable; | |
604 | int m_minWidth; | |
605 | int m_minHeight; | |
606 | int m_fixedWidth; | |
607 | int m_fixedHeight; | |
608 | ||
609 | private: | |
610 | DECLARE_CLASS(wxBoxSizer) | |
611 | }; | |
612 | ||
613 | //--------------------------------------------------------------------------- | |
614 | // wxStaticBoxSizer | |
615 | //--------------------------------------------------------------------------- | |
616 | ||
617 | #if wxUSE_STATBOX | |
618 | ||
619 | class WXDLLEXPORT wxStaticBox; | |
620 | ||
621 | class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer | |
622 | { | |
623 | public: | |
624 | wxStaticBoxSizer( wxStaticBox *box, int orient ); | |
625 | ||
626 | void RecalcSizes(); | |
627 | wxSize CalcMin(); | |
628 | ||
629 | wxStaticBox *GetStaticBox() const | |
630 | { return m_staticBox; } | |
631 | ||
632 | // override to hide/show the static box as well | |
633 | virtual void ShowItems (bool show); | |
634 | ||
635 | protected: | |
636 | wxStaticBox *m_staticBox; | |
637 | ||
638 | private: | |
639 | DECLARE_CLASS(wxStaticBoxSizer) | |
640 | DECLARE_NO_COPY_CLASS(wxStaticBoxSizer) | |
641 | }; | |
642 | ||
643 | #endif // wxUSE_STATBOX | |
644 | ||
645 | #if wxUSE_BUTTON | |
646 | ||
647 | class WXDLLEXPORT wxStdDialogButtonSizer: public wxBoxSizer | |
648 | { | |
649 | public: | |
650 | // Constructor just creates a new wxBoxSizer, not much else. | |
651 | // Box sizer orientation is automatically determined here: | |
652 | // vertical for PDAs, horizontal for everything else? | |
653 | wxStdDialogButtonSizer(); | |
654 | ||
655 | // Checks button ID against system IDs and sets one of the pointers below | |
656 | // to this button. Does not do any sizer-related things here. | |
657 | void AddButton(wxButton *button); | |
658 | ||
659 | // Use these if no standard ID can/should be used | |
660 | void SetAffirmativeButton( wxButton *button ); | |
661 | void SetNegativeButton( wxButton *button ); | |
662 | void SetCancelButton( wxButton *button ); | |
663 | ||
664 | // All platform-specific code here, checks which buttons exist and add | |
665 | // them to the sizer accordingly. | |
666 | // Note - one potential hack on Mac we could use here, | |
667 | // if m_buttonAffirmative is wxID_SAVE then ensure wxID_SAVE | |
668 | // is set to _("Save") and m_buttonNegative is set to _("Don't Save") | |
669 | // I wouldn't add any other hacks like that into here, | |
670 | // but this one I can see being useful. | |
671 | void Finalise(); | |
672 | ||
673 | wxButton *GetAffirmativeButton() const { return m_buttonAffirmative; } | |
674 | wxButton *GetApplyButton() const { return m_buttonApply; } | |
675 | wxButton *GetNegativeButton() const { return m_buttonNegative; } | |
676 | wxButton *GetCancelButton() const { return m_buttonCancel; } | |
677 | wxButton *GetHelpButton() const { return m_buttonHelp; } | |
678 | ||
679 | protected: | |
680 | wxButton *m_buttonAffirmative; // wxID_OK, wxID_YES, wxID_SAVE go here | |
681 | wxButton *m_buttonApply; | |
682 | wxButton *m_buttonNegative; // wxID_NO | |
683 | wxButton *m_buttonCancel; | |
684 | wxButton *m_buttonHelp; | |
685 | ||
686 | private: | |
687 | DECLARE_CLASS(wxStdDialogButtonSizer) | |
688 | DECLARE_NO_COPY_CLASS(wxStdDialogButtonSizer) | |
689 | }; | |
690 | ||
691 | #endif // wxUSE_BUTTON | |
692 | ||
693 | #if WXWIN_COMPATIBILITY_2_4 | |
694 | // NB: wxBookCtrlSizer and wxNotebookSizer are deprecated, they | |
695 | // don't do anything. wxBookCtrlBase::DoGetBestSize does the job now. | |
696 | ||
697 | // ---------------------------------------------------------------------------- | |
698 | // wxBookCtrlSizer | |
699 | // ---------------------------------------------------------------------------- | |
700 | ||
701 | #if wxUSE_BOOKCTRL | |
702 | ||
703 | // this sizer works with wxNotebook/wxListbook/... and sizes the control to | |
704 | // fit its pages | |
705 | class WXDLLEXPORT wxBookCtrlBase; | |
706 | ||
707 | class WXDLLEXPORT wxBookCtrlSizer : public wxSizer | |
708 | { | |
709 | public: | |
710 | wxDEPRECATED( wxBookCtrlSizer(wxBookCtrlBase *bookctrl) ); | |
711 | ||
712 | wxBookCtrlBase *GetControl() const { return m_bookctrl; } | |
713 | ||
714 | virtual void RecalcSizes(); | |
715 | virtual wxSize CalcMin(); | |
716 | ||
717 | protected: | |
718 | // this protected ctor lets us mark the real one above as deprecated | |
719 | // and still have warning-free build of the library itself: | |
720 | wxBookCtrlSizer() {} | |
721 | ||
722 | wxBookCtrlBase *m_bookctrl; | |
723 | ||
724 | private: | |
725 | DECLARE_CLASS(wxBookCtrlSizer) | |
726 | DECLARE_NO_COPY_CLASS(wxBookCtrlSizer) | |
727 | }; | |
728 | ||
729 | ||
730 | #if wxUSE_NOTEBOOK | |
731 | ||
732 | // before wxBookCtrlBase we only had wxNotebookSizer, keep it for backwards | |
733 | // compatibility | |
734 | class WXDLLEXPORT wxNotebook; | |
735 | ||
736 | class WXDLLEXPORT wxNotebookSizer : public wxBookCtrlSizer | |
737 | { | |
738 | public: | |
739 | wxDEPRECATED( wxNotebookSizer(wxNotebook *nb) ); | |
740 | ||
741 | wxNotebook *GetNotebook() const { return (wxNotebook *)m_bookctrl; } | |
742 | ||
743 | private: | |
744 | DECLARE_CLASS(wxNotebookSizer) | |
745 | DECLARE_NO_COPY_CLASS(wxNotebookSizer) | |
746 | }; | |
747 | ||
748 | #endif // wxUSE_NOTEBOOK | |
749 | ||
750 | #endif // wxUSE_BOOKCTRL | |
751 | ||
752 | #endif // WXWIN_COMPATIBILITY_2_4 | |
753 | ||
754 | // ---------------------------------------------------------------------------- | |
755 | // inline functions implementation | |
756 | // ---------------------------------------------------------------------------- | |
757 | ||
758 | inline wxSizerItem* | |
759 | wxSizer::Add( wxWindow *window, int proportion, int flag, int border, wxObject* userData ) | |
760 | { | |
761 | return Add( new wxSizerItem( window, proportion, flag, border, userData ) ); | |
762 | } | |
763 | ||
764 | inline wxSizerItem* | |
765 | wxSizer::Add( wxSizer *sizer, int proportion, int flag, int border, wxObject* userData ) | |
766 | { | |
767 | return Add( new wxSizerItem( sizer, proportion, flag, border, userData ) ); | |
768 | } | |
769 | ||
770 | inline wxSizerItem* | |
771 | wxSizer::Add( int width, int height, int proportion, int flag, int border, wxObject* userData ) | |
772 | { | |
773 | return Add( new wxSizerItem( width, height, proportion, flag, border, userData ) ); | |
774 | } | |
775 | ||
776 | inline wxSizerItem* | |
777 | wxSizer::Add( wxWindow *window, const wxSizerFlags& flags ) | |
778 | { | |
779 | return Add( new wxSizerItem(window, flags) ); | |
780 | } | |
781 | ||
782 | inline wxSizerItem* | |
783 | wxSizer::Add( wxSizer *sizer, const wxSizerFlags& flags ) | |
784 | { | |
785 | return Add( new wxSizerItem(sizer, flags) ); | |
786 | } | |
787 | ||
788 | inline wxSizerItem* | |
789 | wxSizer::Add( wxSizerItem *item ) | |
790 | { | |
791 | return Insert( m_children.GetCount(), item ); | |
792 | } | |
793 | ||
794 | inline wxSizerItem* | |
795 | wxSizer::AddSpacer(int size) | |
796 | { | |
797 | return Add(size, size); | |
798 | } | |
799 | ||
800 | inline wxSizerItem* | |
801 | wxSizer::AddStretchSpacer(int prop) | |
802 | { | |
803 | return Add(0, 0, prop); | |
804 | } | |
805 | ||
806 | inline wxSizerItem* | |
807 | wxSizer::Prepend( wxWindow *window, int proportion, int flag, int border, wxObject* userData ) | |
808 | { | |
809 | return Prepend( new wxSizerItem( window, proportion, flag, border, userData ) ); | |
810 | } | |
811 | ||
812 | inline wxSizerItem* | |
813 | wxSizer::Prepend( wxSizer *sizer, int proportion, int flag, int border, wxObject* userData ) | |
814 | { | |
815 | return Prepend( new wxSizerItem( sizer, proportion, flag, border, userData ) ); | |
816 | } | |
817 | ||
818 | inline wxSizerItem* | |
819 | wxSizer::Prepend( int width, int height, int proportion, int flag, int border, wxObject* userData ) | |
820 | { | |
821 | return Prepend( new wxSizerItem( width, height, proportion, flag, border, userData ) ); | |
822 | } | |
823 | ||
824 | inline wxSizerItem* | |
825 | wxSizer::Prepend( wxSizerItem *item ) | |
826 | { | |
827 | return Insert( 0, item ); | |
828 | } | |
829 | ||
830 | inline wxSizerItem* | |
831 | wxSizer::PrependSpacer(int size) | |
832 | { | |
833 | return Prepend(size, size); | |
834 | } | |
835 | ||
836 | inline wxSizerItem* | |
837 | wxSizer::PrependStretchSpacer(int prop) | |
838 | { | |
839 | return Prepend(0, 0, prop); | |
840 | } | |
841 | ||
842 | inline wxSizerItem* | |
843 | wxSizer::Prepend( wxWindow *window, const wxSizerFlags& flags ) | |
844 | { | |
845 | return Prepend( new wxSizerItem(window, flags) ); | |
846 | } | |
847 | ||
848 | inline wxSizerItem* | |
849 | wxSizer::Prepend( wxSizer *sizer, const wxSizerFlags& flags ) | |
850 | { | |
851 | return Prepend( new wxSizerItem(sizer, flags) ); | |
852 | } | |
853 | ||
854 | inline wxSizerItem* | |
855 | wxSizer::Insert( size_t index, | |
856 | wxWindow *window, | |
857 | int proportion, | |
858 | int flag, | |
859 | int border, | |
860 | wxObject* userData ) | |
861 | { | |
862 | return Insert( index, new wxSizerItem( window, proportion, flag, border, userData ) ); | |
863 | } | |
864 | ||
865 | inline wxSizerItem* | |
866 | wxSizer::Insert( size_t index, | |
867 | wxSizer *sizer, | |
868 | int proportion, | |
869 | int flag, | |
870 | int border, | |
871 | wxObject* userData ) | |
872 | { | |
873 | return Insert( index, new wxSizerItem( sizer, proportion, flag, border, userData ) ); | |
874 | } | |
875 | ||
876 | inline wxSizerItem* | |
877 | wxSizer::Insert( size_t index, | |
878 | int width, | |
879 | int height, | |
880 | int proportion, | |
881 | int flag, | |
882 | int border, | |
883 | wxObject* userData ) | |
884 | { | |
885 | return Insert( index, new wxSizerItem( width, height, proportion, flag, border, userData ) ); | |
886 | } | |
887 | ||
888 | inline wxSizerItem* | |
889 | wxSizer::Insert( size_t index, wxWindow *window, const wxSizerFlags& flags ) | |
890 | { | |
891 | return Insert( index, new wxSizerItem(window, flags) ); | |
892 | } | |
893 | ||
894 | inline wxSizerItem* | |
895 | wxSizer::Insert( size_t index, wxSizer *sizer, const wxSizerFlags& flags ) | |
896 | { | |
897 | return Insert( index, new wxSizerItem(sizer, flags) ); | |
898 | } | |
899 | ||
900 | inline wxSizerItem* | |
901 | wxSizer::InsertSpacer(size_t index, int size) | |
902 | { | |
903 | return Insert(index, size, size); | |
904 | } | |
905 | ||
906 | inline wxSizerItem* | |
907 | wxSizer::InsertStretchSpacer(size_t index, int prop) | |
908 | { | |
909 | return Insert(index, 0, 0, prop); | |
910 | } | |
911 | ||
912 | ||
913 | #endif // __WXSIZER_H__ | |
914 |