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