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