1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/sizer.cpp
3 // Purpose: provide new wxSizer class for layout
4 // Author: Robert Roebling and Robin Dunn, contributions by
5 // Dirk Holtwick, Ron Lee
6 // Modified by: Ron Lee
9 // Copyright: (c) Robin Dunn, Robert Roebling
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
13 // For compilers that support precompilation, includes "wx.h".
14 #include "wx/wxprec.h"
20 #include "wx/display.h"
24 #include "wx/string.h"
28 #include "wx/settings.h"
29 #include "wx/button.h"
30 #include "wx/statbox.h"
31 #include "wx/toplevel.h"
34 #include "wx/listimpl.cpp"
36 #if WXWIN_COMPATIBILITY_2_4
37 #include "wx/notebook.h"
40 //---------------------------------------------------------------------------
42 IMPLEMENT_CLASS(wxSizerItem
, wxObject
)
43 IMPLEMENT_CLASS(wxSizer
, wxObject
)
44 IMPLEMENT_CLASS(wxGridSizer
, wxSizer
)
45 IMPLEMENT_CLASS(wxFlexGridSizer
, wxGridSizer
)
46 IMPLEMENT_CLASS(wxBoxSizer
, wxSizer
)
48 IMPLEMENT_CLASS(wxStaticBoxSizer
, wxBoxSizer
)
51 IMPLEMENT_CLASS(wxStdDialogButtonSizer
, wxBoxSizer
)
54 WX_DEFINE_EXPORTED_LIST( wxSizerItemList
)
89 // ----------------------------------------------------------------------------
91 // ----------------------------------------------------------------------------
93 void wxSizerItem::Init(const wxSizerFlags
& flags
)
97 m_proportion
= flags
.GetProportion();
98 m_flag
= flags
.GetFlags();
99 m_border
= flags
.GetBorderInPixels();
102 wxSizerItem::wxSizerItem()
114 void wxSizerItem::SetWindow(wxWindow
*window
)
116 wxCHECK_RET( window
, _T("NULL window in wxSizerItem::SetWindow()") );
118 m_kind
= Item_Window
;
121 // window doesn't become smaller than its initial size, whatever happens
122 m_minSize
= window
->GetSize();
124 if ( m_flag
& wxFIXED_MINSIZE
)
125 window
->SetMinSize(m_minSize
);
127 // aspect ratio calculated from initial size
131 wxSizerItem::wxSizerItem(wxWindow
*window
,
136 : m_proportion(proportion
),
145 void wxSizerItem::SetSizer(wxSizer
*sizer
)
151 wxSizerItem::wxSizerItem(wxSizer
*sizer
,
156 : m_proportion(proportion
),
164 // m_minSize is set later
168 void wxSizerItem::SetSpacer(const wxSize
& size
)
170 m_kind
= Item_Spacer
;
171 m_spacer
= new wxSizerSpacer(size
);
176 wxSizerItem::wxSizerItem(int width
,
182 : m_minSize(width
, height
), // minimal size is the initial size
183 m_proportion(proportion
),
188 SetSpacer(width
, height
);
191 wxSizerItem::~wxSizerItem()
201 m_window
->SetContainingSizer(NULL
);
214 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
218 wxSize
wxSizerItem::GetSpacer() const
221 if ( m_kind
== Item_Spacer
)
222 size
= m_spacer
->GetSize();
228 wxSize
wxSizerItem::GetSize() const
237 ret
= m_window
->GetSize();
241 ret
= m_sizer
->GetSize();
245 ret
= m_spacer
->GetSize();
250 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
257 if (m_flag
& wxNORTH
)
259 if (m_flag
& wxSOUTH
)
265 wxSize
wxSizerItem::CalcMin()
269 m_minSize
= m_sizer
->GetMinSize();
271 // if we have to preserve aspect ratio _AND_ this is
272 // the first-time calculation, consider ret to be initial size
273 if ( (m_flag
& wxSHAPED
) && wxIsNullDouble(m_ratio
) )
276 else if ( IsWindow() )
278 // Since the size of the window may change during runtime, we
279 // should use the current minimal/best size.
280 m_minSize
= m_window
->GetEffectiveMinSize();
283 return GetMinSizeWithBorder();
286 wxSize
wxSizerItem::GetMinSizeWithBorder() const
288 wxSize ret
= m_minSize
;
294 if (m_flag
& wxNORTH
)
296 if (m_flag
& wxSOUTH
)
303 void wxSizerItem::SetDimension( const wxPoint
& pos_
, const wxSize
& size_
)
307 if (m_flag
& wxSHAPED
)
309 // adjust aspect ratio
310 int rwidth
= (int) (size
.y
* m_ratio
);
314 int rheight
= (int) (size
.x
/ m_ratio
);
315 // add vertical space
316 if (m_flag
& wxALIGN_CENTER_VERTICAL
)
317 pos
.y
+= (size
.y
- rheight
) / 2;
318 else if (m_flag
& wxALIGN_BOTTOM
)
319 pos
.y
+= (size
.y
- rheight
);
320 // use reduced dimensions
323 else if (rwidth
< size
.x
)
325 // add horizontal space
326 if (m_flag
& wxALIGN_CENTER_HORIZONTAL
)
327 pos
.x
+= (size
.x
- rwidth
) / 2;
328 else if (m_flag
& wxALIGN_RIGHT
)
329 pos
.x
+= (size
.x
- rwidth
);
334 // This is what GetPosition() returns. Since we calculate
335 // borders afterwards, GetPosition() will be the left/top
336 // corner of the surrounding border.
348 if (m_flag
& wxNORTH
)
353 if (m_flag
& wxSOUTH
)
363 m_rect
= wxRect(pos
, size
);
368 wxFAIL_MSG( _T("can't set size of uninitialized sizer item") );
372 m_window
->SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
,
373 wxSIZE_ALLOW_MINUS_ONE
);
377 m_sizer
->SetDimension(pos
.x
, pos
.y
, size
.x
, size
.y
);
381 m_spacer
->SetSize(size
);
386 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
390 void wxSizerItem::DeleteWindows()
399 //We are deleting the window from this sizer - normally
400 //the window destroys the sizer associated with it,
401 //which might destroy this, which we don't want
402 m_window
->SetContainingSizer(NULL
);
404 //Putting this after the switch will result in a spacer
405 //not being deleted properly on destruction
410 m_sizer
->DeleteWindows();
415 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
420 void wxSizerItem::Show( bool show
)
425 wxFAIL_MSG( _T("can't show uninitialized sizer item") );
429 m_window
->Show(show
);
437 m_spacer
->Show(show
);
442 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
446 bool wxSizerItem::IsShown() const
451 // we may be called from CalcMin(), just return false so that we're
456 return m_window
->IsShown();
459 // arbitrarily decide that if at least one of our elements is
460 // shown, so are we (this arbitrariness is the reason for
461 // deprecating this function)
463 // Some apps (such as dialog editors) depend on an empty sizer still
464 // being laid out correctly and reporting the correct size and position.
465 if (m_sizer
->GetChildren().GetCount() == 0)
468 for ( wxSizerItemList::compatibility_iterator
469 node
= m_sizer
->GetChildren().GetFirst();
471 node
= node
->GetNext() )
473 if ( node
->GetData()->IsShown() )
480 return m_spacer
->IsShown();
484 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
490 #if WXWIN_COMPATIBILITY_2_6
491 void wxSizerItem::SetOption( int option
)
493 SetProportion( option
);
496 int wxSizerItem::GetOption() const
498 return GetProportion();
500 #endif // WXWIN_COMPATIBILITY_2_6
503 //---------------------------------------------------------------------------
505 //---------------------------------------------------------------------------
509 WX_CLEAR_LIST(wxSizerItemList
, m_children
);
512 wxSizerItem
* wxSizer::Insert( size_t index
, wxSizerItem
*item
)
514 m_children
.Insert( index
, item
);
516 if ( item
->GetWindow() )
517 item
->GetWindow()->SetContainingSizer( this );
522 void wxSizer::SetContainingWindow(wxWindow
*win
)
524 if ( win
== m_containingWindow
)
527 m_containingWindow
= win
;
529 // set the same window for all nested sizers as well, they also are in the
531 for ( wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
533 node
= node
->GetNext() )
535 wxSizerItem
*const item
= node
->GetData();
536 wxSizer
*const sizer
= item
->GetSizer();
540 sizer
->SetContainingWindow(win
);
545 #if WXWIN_COMPATIBILITY_2_6
546 bool wxSizer::Remove( wxWindow
*window
)
548 return Detach( window
);
550 #endif // WXWIN_COMPATIBILITY_2_6
552 bool wxSizer::Remove( wxSizer
*sizer
)
554 wxASSERT_MSG( sizer
, _T("Removing NULL sizer") );
556 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
559 wxSizerItem
*item
= node
->GetData();
561 if (item
->GetSizer() == sizer
)
564 m_children
.Erase( node
);
568 node
= node
->GetNext();
574 bool wxSizer::Remove( int index
)
576 wxCHECK_MSG( index
>= 0 && (size_t)index
< m_children
.GetCount(),
578 _T("Remove index is out of range") );
580 wxSizerItemList::compatibility_iterator node
= m_children
.Item( index
);
582 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
584 wxSizerItem
*item
= node
->GetData();
586 if ( item
->IsWindow() )
587 item
->GetWindow()->SetContainingSizer( NULL
);
590 m_children
.Erase( node
);
594 bool wxSizer::Detach( wxSizer
*sizer
)
596 wxASSERT_MSG( sizer
, _T("Detaching NULL sizer") );
598 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
601 wxSizerItem
*item
= node
->GetData();
603 if (item
->GetSizer() == sizer
)
607 m_children
.Erase( node
);
610 node
= node
->GetNext();
616 bool wxSizer::Detach( wxWindow
*window
)
618 wxASSERT_MSG( window
, _T("Detaching NULL window") );
620 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
623 wxSizerItem
*item
= node
->GetData();
625 if (item
->GetWindow() == window
)
627 item
->GetWindow()->SetContainingSizer( NULL
);
629 m_children
.Erase( node
);
632 node
= node
->GetNext();
638 bool wxSizer::Detach( int index
)
640 wxCHECK_MSG( index
>= 0 && (size_t)index
< m_children
.GetCount(),
642 _T("Detach index is out of range") );
644 wxSizerItemList::compatibility_iterator node
= m_children
.Item( index
);
646 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
648 wxSizerItem
*item
= node
->GetData();
650 if ( item
->IsSizer() )
652 else if ( item
->IsWindow() )
653 item
->GetWindow()->SetContainingSizer( NULL
);
656 m_children
.Erase( node
);
660 bool wxSizer::Replace( wxWindow
*oldwin
, wxWindow
*newwin
, bool recursive
)
662 wxASSERT_MSG( oldwin
, _T("Replacing NULL window") );
663 wxASSERT_MSG( newwin
, _T("Replacing with NULL window") );
665 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
668 wxSizerItem
*item
= node
->GetData();
670 if (item
->GetWindow() == oldwin
)
672 item
->GetWindow()->SetContainingSizer( NULL
);
673 item
->SetWindow(newwin
);
674 newwin
->SetContainingSizer( this );
677 else if (recursive
&& item
->IsSizer())
679 if (item
->GetSizer()->Replace( oldwin
, newwin
, true ))
683 node
= node
->GetNext();
689 bool wxSizer::Replace( wxSizer
*oldsz
, wxSizer
*newsz
, bool recursive
)
691 wxASSERT_MSG( oldsz
, _T("Replacing NULL sizer") );
692 wxASSERT_MSG( newsz
, _T("Replacing with NULL sizer") );
694 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
697 wxSizerItem
*item
= node
->GetData();
699 if (item
->GetSizer() == oldsz
)
701 wxSizer
*old
= item
->GetSizer();
702 item
->SetSizer(newsz
);
706 else if (recursive
&& item
->IsSizer())
708 if (item
->GetSizer()->Replace( oldsz
, newsz
, true ))
712 node
= node
->GetNext();
718 bool wxSizer::Replace( size_t old
, wxSizerItem
*newitem
)
720 wxCHECK_MSG( old
< m_children
.GetCount(), false, _T("Replace index is out of range") );
721 wxASSERT_MSG( newitem
, _T("Replacing with NULL item") );
723 wxSizerItemList::compatibility_iterator node
= m_children
.Item( old
);
725 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
727 wxSizerItem
*item
= node
->GetData();
728 node
->SetData(newitem
);
734 void wxSizer::Clear( bool delete_windows
)
736 // First clear the ContainingSizer pointers
737 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
740 wxSizerItem
*item
= node
->GetData();
742 if (item
->IsWindow())
743 item
->GetWindow()->SetContainingSizer( NULL
);
744 node
= node
->GetNext();
747 // Destroy the windows if needed
751 // Now empty the list
752 WX_CLEAR_LIST(wxSizerItemList
, m_children
);
755 void wxSizer::DeleteWindows()
757 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
760 wxSizerItem
*item
= node
->GetData();
762 item
->DeleteWindows();
763 node
= node
->GetNext();
767 wxSize
wxSizer::Fit( wxWindow
*window
)
769 // take the min size by default and limit it by max size
770 wxSize size
= GetMinWindowSize(window
);
771 wxSize sizeMax
= GetMaxWindowSize(window
);
773 wxTopLevelWindow
*tlw
= wxDynamicCast(window
, wxTopLevelWindow
);
776 // hack for small screen devices where TLWs are always full screen
777 if ( tlw
->IsAlwaysMaximized() )
779 size
= tlw
->GetSize();
781 else // normal situation
783 // limit the window to the size of the display it is on
784 int disp
= wxDisplay::GetFromWindow(window
);
785 if ( disp
== wxNOT_FOUND
)
787 // or, if we don't know which one it is, of the main one
791 sizeMax
= wxDisplay(disp
).GetClientArea().GetSize();
795 if ( sizeMax
.x
!= wxDefaultCoord
&& size
.x
> sizeMax
.x
)
797 if ( sizeMax
.y
!= wxDefaultCoord
&& size
.y
> sizeMax
.y
)
801 window
->SetSize( size
);
806 void wxSizer::FitInside( wxWindow
*window
)
809 if (window
->IsTopLevel())
810 size
= VirtualFitSize( window
);
812 size
= GetMinClientSize( window
);
814 window
->SetVirtualSize( size
);
817 void wxSizer::Layout()
819 // (re)calculates minimums needed for each item and other preparations
823 // Applies the layout and repositions/resizes the items
827 void wxSizer::SetSizeHints( wxWindow
*window
)
829 // Preserve the window's max size hints, but set the
830 // lower bound according to the sizer calculations.
832 wxSize size
= Fit( window
);
834 window
->SetSizeHints( size
.x
,
836 window
->GetMaxWidth(),
837 window
->GetMaxHeight() );
840 void wxSizer::SetVirtualSizeHints( wxWindow
*window
)
842 // Preserve the window's max size hints, but set the
843 // lower bound according to the sizer calculations.
846 wxSize
size( window
->GetVirtualSize() );
847 window
->SetVirtualSizeHints( size
.x
,
849 window
->GetMaxWidth(),
850 window
->GetMaxHeight() );
853 wxSize
wxSizer::GetMaxWindowSize( wxWindow
*window
) const
855 return window
->GetMaxSize();
858 wxSize
wxSizer::GetMinWindowSize( wxWindow
*window
)
860 wxSize
minSize( GetMinSize() );
861 wxSize
size( window
->GetSize() );
862 wxSize
client_size( window
->GetClientSize() );
864 return wxSize( minSize
.x
+size
.x
-client_size
.x
,
865 minSize
.y
+size
.y
-client_size
.y
);
868 // TODO on mac we need a function that determines how much free space this
869 // min size contains, in order to make sure that we have 20 pixels of free
870 // space around the controls
871 wxSize
wxSizer::GetMaxClientSize( wxWindow
*window
) const
873 wxSize
maxSize( window
->GetMaxSize() );
875 if ( maxSize
!= wxDefaultSize
)
877 wxSize
size( window
->GetSize() );
878 wxSize
client_size( window
->GetClientSize() );
880 return wxSize( maxSize
.x
+ client_size
.x
- size
.x
,
881 maxSize
.y
+ client_size
.y
- size
.y
);
884 return wxDefaultSize
;
887 wxSize
wxSizer::GetMinClientSize( wxWindow
*WXUNUSED(window
) )
889 return GetMinSize(); // Already returns client size.
892 wxSize
wxSizer::VirtualFitSize( wxWindow
*window
)
894 wxSize size
= GetMinClientSize( window
);
895 wxSize sizeMax
= GetMaxClientSize( window
);
897 // Limit the size if sizeMax != wxDefaultSize
899 if ( size
.x
> sizeMax
.x
&& sizeMax
.x
!= wxDefaultCoord
)
901 if ( size
.y
> sizeMax
.y
&& sizeMax
.y
!= wxDefaultCoord
)
907 void wxSizer::SetDimension( int x
, int y
, int width
, int height
)
916 wxSize
wxSizer::GetMinSize()
918 wxSize
ret( CalcMin() );
919 if (ret
.x
< m_minSize
.x
) ret
.x
= m_minSize
.x
;
920 if (ret
.y
< m_minSize
.y
) ret
.y
= m_minSize
.y
;
924 void wxSizer::DoSetMinSize( int width
, int height
)
927 m_minSize
.y
= height
;
930 bool wxSizer::DoSetItemMinSize( wxWindow
*window
, int width
, int height
)
932 wxASSERT_MSG( window
, _T("SetMinSize for NULL window") );
934 // Is it our immediate child?
936 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
939 wxSizerItem
*item
= node
->GetData();
941 if (item
->GetWindow() == window
)
943 item
->SetMinSize( width
, height
);
946 node
= node
->GetNext();
949 // No? Search any subsizers we own then
951 node
= m_children
.GetFirst();
954 wxSizerItem
*item
= node
->GetData();
956 if ( item
->GetSizer() &&
957 item
->GetSizer()->DoSetItemMinSize( window
, width
, height
) )
959 // A child sizer found the requested windw, exit.
962 node
= node
->GetNext();
968 bool wxSizer::DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
)
970 wxASSERT_MSG( sizer
, _T("SetMinSize for NULL sizer") );
972 // Is it our immediate child?
974 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
977 wxSizerItem
*item
= node
->GetData();
979 if (item
->GetSizer() == sizer
)
981 item
->GetSizer()->DoSetMinSize( width
, height
);
984 node
= node
->GetNext();
987 // No? Search any subsizers we own then
989 node
= m_children
.GetFirst();
992 wxSizerItem
*item
= node
->GetData();
994 if ( item
->GetSizer() &&
995 item
->GetSizer()->DoSetItemMinSize( sizer
, width
, height
) )
997 // A child found the requested sizer, exit.
1000 node
= node
->GetNext();
1006 bool wxSizer::DoSetItemMinSize( size_t index
, int width
, int height
)
1008 wxSizerItemList::compatibility_iterator node
= m_children
.Item( index
);
1010 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
1012 wxSizerItem
*item
= node
->GetData();
1014 if (item
->GetSizer())
1016 // Sizers contains the minimal size in them, if not calculated ...
1017 item
->GetSizer()->DoSetMinSize( width
, height
);
1021 // ... but the minimal size of spacers and windows is stored via the item
1022 item
->SetMinSize( width
, height
);
1028 wxSizerItem
* wxSizer::GetItem( wxWindow
*window
, bool recursive
)
1030 wxASSERT_MSG( window
, _T("GetItem for NULL window") );
1032 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1035 wxSizerItem
*item
= node
->GetData();
1037 if (item
->GetWindow() == window
)
1041 else if (recursive
&& item
->IsSizer())
1043 wxSizerItem
*subitem
= item
->GetSizer()->GetItem( window
, true );
1048 node
= node
->GetNext();
1054 wxSizerItem
* wxSizer::GetItem( wxSizer
*sizer
, bool recursive
)
1056 wxASSERT_MSG( sizer
, _T("GetItem for NULL sizer") );
1058 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1061 wxSizerItem
*item
= node
->GetData();
1063 if (item
->GetSizer() == sizer
)
1067 else if (recursive
&& item
->IsSizer())
1069 wxSizerItem
*subitem
= item
->GetSizer()->GetItem( sizer
, true );
1074 node
= node
->GetNext();
1080 wxSizerItem
* wxSizer::GetItem( size_t index
)
1082 wxCHECK_MSG( index
< m_children
.GetCount(),
1084 _T("GetItem index is out of range") );
1086 return m_children
.Item( index
)->GetData();
1089 bool wxSizer::Show( wxWindow
*window
, bool show
, bool recursive
)
1091 wxSizerItem
*item
= GetItem( window
, recursive
);
1102 bool wxSizer::Show( wxSizer
*sizer
, bool show
, bool recursive
)
1104 wxSizerItem
*item
= GetItem( sizer
, recursive
);
1115 bool wxSizer::Show( size_t index
, bool show
)
1117 wxSizerItem
*item
= GetItem( index
);
1128 void wxSizer::ShowItems( bool show
)
1130 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1133 node
->GetData()->Show( show
);
1134 node
= node
->GetNext();
1138 bool wxSizer::IsShown( wxWindow
*window
) const
1140 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1143 wxSizerItem
*item
= node
->GetData();
1145 if (item
->GetWindow() == window
)
1147 return item
->IsShown();
1149 node
= node
->GetNext();
1152 wxFAIL_MSG( _T("IsShown failed to find sizer item") );
1157 bool wxSizer::IsShown( wxSizer
*sizer
) const
1159 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1162 wxSizerItem
*item
= node
->GetData();
1164 if (item
->GetSizer() == sizer
)
1166 return item
->IsShown();
1168 node
= node
->GetNext();
1171 wxFAIL_MSG( _T("IsShown failed to find sizer item") );
1176 bool wxSizer::IsShown( size_t index
) const
1178 wxCHECK_MSG( index
< m_children
.GetCount(),
1180 _T("IsShown index is out of range") );
1182 return m_children
.Item( index
)->GetData()->IsShown();
1186 //---------------------------------------------------------------------------
1188 //---------------------------------------------------------------------------
1190 wxGridSizer::wxGridSizer( int rows
, int cols
, int vgap
, int hgap
)
1191 : m_rows( ( cols
== 0 && rows
== 0 ) ? 1 : rows
)
1198 wxGridSizer::wxGridSizer( int cols
, int vgap
, int hgap
)
1199 : m_rows( cols
== 0 ? 1 : 0 )
1206 int wxGridSizer::CalcRowsCols(int& nrows
, int& ncols
) const
1208 int nitems
= m_children
.GetCount();
1214 nrows
= (nitems
+ m_cols
- 1) / m_cols
;
1218 ncols
= (nitems
+ m_rows
- 1) / m_rows
;
1221 else // 0 columns, 0 rows?
1223 wxFAIL_MSG( _T("grid sizer must have either rows or columns fixed") );
1232 void wxGridSizer::RecalcSizes()
1234 int nitems
, nrows
, ncols
;
1235 if ( (nitems
= CalcRowsCols(nrows
, ncols
)) == 0 )
1238 wxSize
sz( GetSize() );
1239 wxPoint
pt( GetPosition() );
1241 int w
= (sz
.x
- (ncols
- 1) * m_hgap
) / ncols
;
1242 int h
= (sz
.y
- (nrows
- 1) * m_vgap
) / nrows
;
1245 for (int c
= 0; c
< ncols
; c
++)
1248 for (int r
= 0; r
< nrows
; r
++)
1250 int i
= r
* ncols
+ c
;
1253 wxSizerItemList::compatibility_iterator node
= m_children
.Item( i
);
1255 wxASSERT_MSG( node
, _T("Failed to find SizerItemList node") );
1257 SetItemBounds( node
->GetData(), x
, y
, w
, h
);
1265 wxSize
wxGridSizer::CalcMin()
1268 if ( CalcRowsCols(nrows
, ncols
) == 0 )
1271 // Find the max width and height for any component
1275 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1278 wxSizerItem
*item
= node
->GetData();
1279 wxSize
sz( item
->CalcMin() );
1281 w
= wxMax( w
, sz
.x
);
1282 h
= wxMax( h
, sz
.y
);
1284 node
= node
->GetNext();
1287 return wxSize( ncols
* w
+ (ncols
-1) * m_hgap
,
1288 nrows
* h
+ (nrows
-1) * m_vgap
);
1291 void wxGridSizer::SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
)
1294 wxSize
sz( item
->GetMinSizeWithBorder() );
1295 int flag
= item
->GetFlag();
1297 if ((flag
& wxEXPAND
) || (flag
& wxSHAPED
))
1303 if (flag
& wxALIGN_CENTER_HORIZONTAL
)
1305 pt
.x
= x
+ (w
- sz
.x
) / 2;
1307 else if (flag
& wxALIGN_RIGHT
)
1309 pt
.x
= x
+ (w
- sz
.x
);
1312 if (flag
& wxALIGN_CENTER_VERTICAL
)
1314 pt
.y
= y
+ (h
- sz
.y
) / 2;
1316 else if (flag
& wxALIGN_BOTTOM
)
1318 pt
.y
= y
+ (h
- sz
.y
);
1322 item
->SetDimension(pt
, sz
);
1325 //---------------------------------------------------------------------------
1327 //---------------------------------------------------------------------------
1329 wxFlexGridSizer::wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
)
1330 : wxGridSizer( rows
, cols
, vgap
, hgap
),
1331 m_flexDirection(wxBOTH
),
1332 m_growMode(wxFLEX_GROWMODE_SPECIFIED
)
1336 wxFlexGridSizer::wxFlexGridSizer( int cols
, int vgap
, int hgap
)
1337 : wxGridSizer( cols
, vgap
, hgap
),
1338 m_flexDirection(wxBOTH
),
1339 m_growMode(wxFLEX_GROWMODE_SPECIFIED
)
1343 wxFlexGridSizer::~wxFlexGridSizer()
1347 void wxFlexGridSizer::RecalcSizes()
1349 int nitems
, nrows
, ncols
;
1350 if ( (nitems
= CalcRowsCols(nrows
, ncols
)) == 0 )
1353 wxPoint
pt( GetPosition() );
1354 wxSize
sz( GetSize() );
1356 AdjustForGrowables(sz
, m_calculatedMinSize
, nrows
, ncols
);
1358 sz
= wxSize( pt
.x
+ sz
.x
, pt
.y
+ sz
.y
);
1361 for (int c
= 0; c
< ncols
; c
++)
1364 for (int r
= 0; r
< nrows
; r
++)
1366 int i
= r
* ncols
+ c
;
1369 wxSizerItemList::compatibility_iterator node
= m_children
.Item( i
);
1371 wxASSERT_MSG( node
, _T("Failed to find node") );
1373 int w
= wxMax( 0, wxMin( m_colWidths
[c
], sz
.x
- x
) );
1374 int h
= wxMax( 0, wxMin( m_rowHeights
[r
], sz
.y
- y
) );
1376 SetItemBounds( node
->GetData(), x
, y
, w
, h
);
1378 if (m_rowHeights
[r
] != -1)
1379 y
= y
+ m_rowHeights
[r
] + m_vgap
;
1381 if (m_colWidths
[c
] != -1)
1382 x
= x
+ m_colWidths
[c
] + m_hgap
;
1386 wxSize
wxFlexGridSizer::CalcMin()
1392 // Number of rows/columns can change as items are added or removed.
1393 if ( !CalcRowsCols(nrows
, ncols
) )
1396 m_rowHeights
.SetCount(nrows
);
1397 m_colWidths
.SetCount(ncols
);
1399 // We have to recalcuate the sizes in case the item minimum size has
1400 // changed since the previous layout, or the item has been hidden using
1401 // wxSizer::Show(). If all the items in a row/column are hidden, the final
1402 // dimension of the row/column will be -1, indicating that the column
1403 // itself is hidden.
1404 for( s
= m_rowHeights
.GetCount(), i
= 0; i
< s
; ++i
)
1405 m_rowHeights
[ i
] = -1;
1406 for( s
= m_colWidths
.GetCount(), i
= 0; i
< s
; ++i
)
1407 m_colWidths
[ i
] = -1;
1409 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1414 wxSizerItem
*item
= node
->GetData();
1415 if ( item
->IsShown() )
1417 wxSize
sz( item
->CalcMin() );
1418 int row
= i
/ ncols
;
1419 int col
= i
% ncols
;
1421 m_rowHeights
[ row
] = wxMax( wxMax( 0, sz
.y
), m_rowHeights
[ row
] );
1422 m_colWidths
[ col
] = wxMax( wxMax( 0, sz
.x
), m_colWidths
[ col
] );
1425 node
= node
->GetNext();
1429 AdjustForFlexDirection();
1431 // Sum total minimum size, including gaps between rows/columns.
1432 // -1 is used as a magic number meaning empty column.
1434 for (int col
= 0; col
< ncols
; col
++)
1435 if ( m_colWidths
[ col
] != -1 )
1436 width
+= m_colWidths
[ col
] + m_hgap
;
1441 for (int row
= 0; row
< nrows
; row
++)
1442 if ( m_rowHeights
[ row
] != -1 )
1443 height
+= m_rowHeights
[ row
] + m_vgap
;
1447 m_calculatedMinSize
= wxSize( width
, height
);
1448 return m_calculatedMinSize
;
1451 void wxFlexGridSizer::AdjustForFlexDirection()
1453 // the logic in CalcMin works when we resize flexibly in both directions
1454 // but maybe this is not the case
1455 if ( m_flexDirection
!= wxBOTH
)
1457 // select the array corresponding to the direction in which we do *not*
1459 wxArrayInt
& array
= m_flexDirection
== wxVERTICAL
? m_colWidths
1462 const size_t count
= array
.GetCount();
1464 // find the largest value in this array
1468 for ( n
= 0; n
< count
; ++n
)
1470 if ( array
[n
] > largest
)
1474 // and now fill it with the largest value
1475 for ( n
= 0; n
< count
; ++n
)
1483 void wxFlexGridSizer::AdjustForGrowables(const wxSize
& sz
, const wxSize
& minsz
,
1484 int nrows
, int ncols
)
1486 // what to do with the rows? by default, resize them proportionally
1487 if ( sz
.y
> minsz
.y
&& ( (m_flexDirection
& wxVERTICAL
) || (m_growMode
== wxFLEX_GROWMODE_SPECIFIED
) ) )
1489 int sum_proportions
= 0;
1490 int growable_space
= 0;
1493 for (idx
= 0; idx
< m_growableRows
.GetCount(); idx
++)
1495 // Since the number of rows/columns can change as items are
1496 // inserted/deleted, we need to verify at runtime that the
1497 // requested growable rows/columns are still valid.
1498 if (m_growableRows
[idx
] >= nrows
)
1501 // If all items in a row/column are hidden, that row/column will
1502 // have a dimension of -1. This causes the row/column to be
1503 // hidden completely.
1504 if (m_rowHeights
[ m_growableRows
[idx
] ] == -1)
1506 sum_proportions
+= m_growableRowsProportions
[idx
];
1507 growable_space
+= m_rowHeights
[ m_growableRows
[idx
] ];
1513 for (idx
= 0; idx
< m_growableRows
.GetCount(); idx
++)
1515 if (m_growableRows
[idx
] >= nrows
)
1517 if (m_rowHeights
[ m_growableRows
[idx
] ] == -1)
1518 m_rowHeights
[ m_growableRows
[idx
] ] = 0;
1521 int delta
= (sz
.y
- minsz
.y
);
1522 if (sum_proportions
== 0)
1523 delta
= (delta
/num
) + m_rowHeights
[ m_growableRows
[idx
] ];
1525 delta
= ((delta
+growable_space
)*m_growableRowsProportions
[idx
]) / sum_proportions
;
1526 m_rowHeights
[ m_growableRows
[idx
] ] = delta
;
1531 else if ( (m_growMode
== wxFLEX_GROWMODE_ALL
) && (sz
.y
> minsz
.y
) )
1533 // rounding problem?
1534 for ( int row
= 0; row
< nrows
; ++row
)
1535 m_rowHeights
[ row
] = sz
.y
/ nrows
;
1538 // the same logic as above but for the columns
1539 if ( sz
.x
> minsz
.x
&& ( (m_flexDirection
& wxHORIZONTAL
) || (m_growMode
== wxFLEX_GROWMODE_SPECIFIED
) ) )
1541 int sum_proportions
= 0;
1542 int growable_space
= 0;
1545 for (idx
= 0; idx
< m_growableCols
.GetCount(); idx
++)
1547 // Since the number of rows/columns can change as items are
1548 // inserted/deleted, we need to verify at runtime that the
1549 // requested growable rows/columns are still valid.
1550 if (m_growableCols
[idx
] >= ncols
)
1553 // If all items in a row/column are hidden, that row/column will
1554 // have a dimension of -1. This causes the column to be hidden
1556 if (m_colWidths
[ m_growableCols
[idx
] ] == -1)
1558 sum_proportions
+= m_growableColsProportions
[idx
];
1559 growable_space
+= m_colWidths
[ m_growableCols
[idx
] ];
1565 for (idx
= 0; idx
< m_growableCols
.GetCount(); idx
++)
1567 if (m_growableCols
[idx
] >= ncols
)
1569 if (m_colWidths
[ m_growableCols
[idx
] ] == -1)
1570 m_colWidths
[ m_growableCols
[idx
] ] = 0;
1573 int delta
= (sz
.x
- minsz
.x
);
1574 if (sum_proportions
== 0)
1575 delta
= (delta
/num
) + m_colWidths
[ m_growableCols
[idx
] ];
1577 delta
= ((delta
+growable_space
)*m_growableColsProportions
[idx
])/sum_proportions
;
1578 m_colWidths
[ m_growableCols
[idx
] ] = delta
;
1583 else if ( (m_growMode
== wxFLEX_GROWMODE_ALL
) && (sz
.x
> minsz
.x
) )
1585 for ( int col
=0; col
< ncols
; ++col
)
1586 m_colWidths
[ col
] = sz
.x
/ ncols
;
1591 void wxFlexGridSizer::AddGrowableRow( size_t idx
, int proportion
)
1593 m_growableRows
.Add( idx
);
1594 m_growableRowsProportions
.Add( proportion
);
1597 void wxFlexGridSizer::AddGrowableCol( size_t idx
, int proportion
)
1599 m_growableCols
.Add( idx
);
1600 m_growableColsProportions
.Add( proportion
);
1603 // helper function for RemoveGrowableCol/Row()
1605 DoRemoveFromArrays(size_t idx
, wxArrayInt
& items
, wxArrayInt
& proportions
)
1607 const size_t count
= items
.size();
1608 for ( size_t n
= 0; n
< count
; n
++ )
1610 if ( (size_t)items
[n
] == idx
)
1613 proportions
.RemoveAt(n
);
1618 wxFAIL_MSG( _T("column/row is already not growable") );
1621 void wxFlexGridSizer::RemoveGrowableCol( size_t idx
)
1623 DoRemoveFromArrays(idx
, m_growableCols
, m_growableColsProportions
);
1626 void wxFlexGridSizer::RemoveGrowableRow( size_t idx
)
1628 DoRemoveFromArrays(idx
, m_growableRows
, m_growableRowsProportions
);
1631 //---------------------------------------------------------------------------
1633 //---------------------------------------------------------------------------
1635 wxBoxSizer::wxBoxSizer( int orient
)
1636 : m_orient( orient
)
1640 void wxBoxSizer::RecalcSizes()
1642 if (m_children
.GetCount() == 0)
1648 if (m_orient
== wxHORIZONTAL
)
1649 delta
= m_size
.x
- m_fixedWidth
;
1651 delta
= m_size
.y
- m_fixedHeight
;
1654 wxPoint
pt( m_position
);
1656 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1659 wxSizerItem
*item
= node
->GetData();
1661 if (item
->IsShown())
1663 wxSize
size( item
->GetMinSizeWithBorder() );
1665 if (m_orient
== wxVERTICAL
)
1667 wxCoord height
= size
.y
;
1668 if (item
->GetProportion())
1670 // Because of at least one visible item has non-zero
1671 // proportion then m_stretchable is not zero
1672 height
= (delta
* item
->GetProportion()) / m_stretchable
;
1675 wxPoint
child_pos( pt
);
1676 wxSize
child_size( size
.x
, height
);
1678 if (item
->GetFlag() & (wxEXPAND
| wxSHAPED
))
1679 child_size
.x
= m_size
.x
;
1680 else if (item
->GetFlag() & wxALIGN_RIGHT
)
1681 child_pos
.x
+= m_size
.x
- size
.x
;
1682 else if (item
->GetFlag() & (wxCENTER
| wxALIGN_CENTER_HORIZONTAL
))
1683 // XXX wxCENTER is added for backward compatibility;
1684 // wxALIGN_CENTER should be used in new code
1685 child_pos
.x
+= (m_size
.x
- size
.x
) / 2;
1687 item
->SetDimension( child_pos
, child_size
);
1693 wxCoord width
= size
.x
;
1694 if (item
->GetProportion())
1696 // Because of at least one visible item has non-zero
1697 // proportion then m_stretchable is not zero
1698 width
= (delta
* item
->GetProportion()) / m_stretchable
;
1701 wxPoint
child_pos( pt
);
1702 wxSize
child_size( width
, size
.y
);
1704 if (item
->GetFlag() & (wxEXPAND
| wxSHAPED
))
1705 child_size
.y
= m_size
.y
;
1706 else if (item
->GetFlag() & wxALIGN_BOTTOM
)
1707 child_pos
.y
+= m_size
.y
- size
.y
;
1708 else if (item
->GetFlag() & (wxCENTER
| wxALIGN_CENTER_VERTICAL
))
1709 // XXX wxCENTER is added for backward compatibility;
1710 // wxALIGN_CENTER should be used in new code
1711 child_pos
.y
+= (m_size
.y
- size
.y
) / 2;
1713 if ( m_containingWindow
)
1715 child_pos
.x
= m_containingWindow
->AdjustForLayoutDirection
1723 item
->SetDimension( child_pos
, child_size
);
1729 node
= node
->GetNext();
1733 wxSize
wxBoxSizer::CalcMin()
1735 if (m_children
.GetCount() == 0)
1744 // precalc item minsizes and count proportions
1745 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1748 wxSizerItem
*item
= node
->GetData();
1750 if ( item
->IsShown() )
1752 item
->CalcMin(); // result is stored in the item
1754 m_stretchable
+= item
->GetProportion();
1757 node
= node
->GetNext();
1760 // Total minimum size (width or height) of sizer
1763 node
= m_children
.GetFirst();
1766 wxSizerItem
*item
= node
->GetData();
1768 if (item
->IsShown() && item
->GetProportion() != 0)
1770 int stretch
= item
->GetProportion();
1771 wxSize
size( item
->GetMinSizeWithBorder() );
1774 // Integer division rounded up is (a + b - 1) / b
1775 // Round up needed in order to guarantee that all
1776 // all items will have size not less then their min size
1777 if (m_orient
== wxHORIZONTAL
)
1778 minSize
= ( size
.x
*m_stretchable
+ stretch
- 1)/stretch
;
1780 minSize
= ( size
.y
*m_stretchable
+ stretch
- 1)/stretch
;
1782 if (minSize
> maxMinSize
)
1783 maxMinSize
= minSize
;
1785 node
= node
->GetNext();
1788 // Calculate overall minimum size
1789 node
= m_children
.GetFirst();
1792 wxSizerItem
*item
= node
->GetData();
1794 if (item
->IsShown())
1796 wxSize
size( item
->GetMinSizeWithBorder() );
1797 if (item
->GetProportion() != 0)
1799 if (m_orient
== wxHORIZONTAL
)
1800 size
.x
= (maxMinSize
*item
->GetProportion())/m_stretchable
;
1802 size
.y
= (maxMinSize
*item
->GetProportion())/m_stretchable
;
1806 if (m_orient
== wxVERTICAL
)
1808 m_fixedHeight
+= size
.y
;
1809 m_fixedWidth
= wxMax( m_fixedWidth
, size
.x
);
1813 m_fixedWidth
+= size
.x
;
1814 m_fixedHeight
= wxMax( m_fixedHeight
, size
.y
);
1818 if (m_orient
== wxHORIZONTAL
)
1820 m_minWidth
+= size
.x
;
1821 m_minHeight
= wxMax( m_minHeight
, size
.y
);
1825 m_minHeight
+= size
.y
;
1826 m_minWidth
= wxMax( m_minWidth
, size
.x
);
1829 node
= node
->GetNext();
1832 return wxSize( m_minWidth
, m_minHeight
);
1835 //---------------------------------------------------------------------------
1837 //---------------------------------------------------------------------------
1841 wxStaticBoxSizer::wxStaticBoxSizer( wxStaticBox
*box
, int orient
)
1842 : wxBoxSizer( orient
),
1845 wxASSERT_MSG( box
, wxT("wxStaticBoxSizer needs a static box") );
1847 // do this so that our Detach() is called if the static box is destroyed
1849 m_staticBox
->SetContainingSizer(this);
1852 wxStaticBoxSizer::wxStaticBoxSizer(int orient
, wxWindow
*win
, const wxString
& s
)
1853 : wxBoxSizer(orient
),
1854 m_staticBox(new wxStaticBox(win
, wxID_ANY
, s
))
1857 m_staticBox
->SetContainingSizer(this);
1860 wxStaticBoxSizer::~wxStaticBoxSizer()
1865 static void GetStaticBoxBorders( wxStaticBox
*box
,
1869 // this has to be done platform by platform as there is no way to
1870 // guess the thickness of a wxStaticBox border
1871 box
->GetBordersForSizer(borderTop
, borderOther
);
1874 void wxStaticBoxSizer::RecalcSizes()
1876 int top_border
, other_border
;
1877 GetStaticBoxBorders(m_staticBox
, &top_border
, &other_border
);
1879 m_staticBox
->SetSize( m_position
.x
, m_position
.y
, m_size
.x
, m_size
.y
);
1881 wxPoint
old_pos( m_position
);
1882 m_position
.x
+= other_border
;
1883 m_position
.y
+= top_border
;
1884 wxSize
old_size( m_size
);
1885 m_size
.x
-= 2*other_border
;
1886 m_size
.y
-= top_border
+ other_border
;
1888 wxBoxSizer::RecalcSizes();
1890 m_position
= old_pos
;
1894 wxSize
wxStaticBoxSizer::CalcMin()
1896 int top_border
, other_border
;
1897 GetStaticBoxBorders(m_staticBox
, &top_border
, &other_border
);
1899 wxSize
ret( wxBoxSizer::CalcMin() );
1900 ret
.x
+= 2*other_border
;
1901 ret
.y
+= other_border
+ top_border
;
1906 void wxStaticBoxSizer::ShowItems( bool show
)
1908 m_staticBox
->Show( show
);
1909 wxBoxSizer::ShowItems( show
);
1912 bool wxStaticBoxSizer::Detach( wxWindow
*window
)
1914 // avoid deleting m_staticBox in our dtor if it's being detached from the
1915 // sizer (which can happen because it's being already destroyed for
1917 if ( window
== m_staticBox
)
1923 return wxSizer::Detach( window
);
1926 #endif // wxUSE_STATBOX
1930 wxStdDialogButtonSizer::wxStdDialogButtonSizer()
1931 : wxBoxSizer(wxHORIZONTAL
)
1933 // Vertical buttons with lots of space on either side
1934 // looks rubbish on WinCE, so let's not do this for now.
1935 // If we are going to use vertical buttons, we should
1936 // put the sizer to the right of other controls in the dialog,
1937 // and that's beyond the scope of this sizer.
1939 bool is_pda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
1940 // If we have a PDA screen, put yes/no button over
1941 // all other buttons, otherwise on the left side.
1943 m_orient
= wxVERTICAL
;
1946 m_buttonAffirmative
= NULL
;
1947 m_buttonApply
= NULL
;
1948 m_buttonNegative
= NULL
;
1949 m_buttonCancel
= NULL
;
1950 m_buttonHelp
= NULL
;
1953 void wxStdDialogButtonSizer::AddButton(wxButton
*mybutton
)
1955 switch (mybutton
->GetId())
1960 m_buttonAffirmative
= mybutton
;
1963 m_buttonApply
= mybutton
;
1966 m_buttonNegative
= mybutton
;
1969 m_buttonCancel
= mybutton
;
1972 case wxID_CONTEXT_HELP
:
1973 m_buttonHelp
= mybutton
;
1980 void wxStdDialogButtonSizer::SetAffirmativeButton( wxButton
*button
)
1982 m_buttonAffirmative
= button
;
1985 void wxStdDialogButtonSizer::SetNegativeButton( wxButton
*button
)
1987 m_buttonNegative
= button
;
1990 void wxStdDialogButtonSizer::SetCancelButton( wxButton
*button
)
1992 m_buttonCancel
= button
;
1995 void wxStdDialogButtonSizer::Realize()
1998 Add(0, 0, 0, wxLEFT
, 6);
2000 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 6);
2002 if (m_buttonNegative
){
2003 // HIG POLICE BULLETIN - destructive buttons need extra padding
2004 // 24 pixels on either side
2005 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 12);
2008 // extra whitespace between help/negative and cancel/ok buttons
2009 Add(0, 0, 1, wxEXPAND
, 0);
2011 if (m_buttonCancel
){
2012 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 6);
2013 // Cancel or help should be default
2014 // m_buttonCancel->SetDefaultButton();
2017 // Ugh, Mac doesn't really have apply dialogs, so I'll just
2018 // figure the best place is between Cancel and OK
2020 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 6);
2022 if (m_buttonAffirmative
){
2023 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
, 6);
2025 if (m_buttonAffirmative
->GetId() == wxID_SAVE
){
2026 // these buttons have set labels under Mac so we should use them
2027 m_buttonAffirmative
->SetLabel(_("Save"));
2028 m_buttonNegative
->SetLabel(_("Don't Save"));
2032 // Extra space around and at the right
2034 #elif defined(__WXGTK20__)
2035 Add(0, 0, 0, wxLEFT
, 9);
2037 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
2039 // extra whitespace between help and cancel/ok buttons
2040 Add(0, 0, 1, wxEXPAND
, 0);
2042 if (m_buttonNegative
){
2043 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
2046 if (m_buttonCancel
){
2047 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
2048 // Cancel or help should be default
2049 // m_buttonCancel->SetDefaultButton();
2053 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
2055 if (m_buttonAffirmative
)
2056 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
, 6);
2057 #elif defined(__WXMSW__)
2060 // right-justify buttons
2061 Add(0, 0, 1, wxEXPAND
, 0);
2063 if (m_buttonAffirmative
){
2064 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonAffirmative
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2067 if (m_buttonNegative
){
2068 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonNegative
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2071 if (m_buttonCancel
){
2072 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonCancel
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2075 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonApply
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2078 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonHelp
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2080 // GTK+1 and any other platform
2082 // Add(0, 0, 0, wxLEFT, 5); // Not sure what this was for but it unbalances the dialog
2084 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonHelp
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2086 // extra whitespace between help and cancel/ok buttons
2087 Add(0, 0, 1, wxEXPAND
, 0);
2090 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonApply
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2092 if (m_buttonAffirmative
){
2093 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonAffirmative
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2096 if (m_buttonNegative
){
2097 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonNegative
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2100 if (m_buttonCancel
){
2101 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonCancel
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2102 // Cancel or help should be default
2103 // m_buttonCancel->SetDefaultButton();
2109 #endif // wxUSE_BUTTON
2111 #if WXWIN_COMPATIBILITY_2_4
2113 // ----------------------------------------------------------------------------
2115 // ----------------------------------------------------------------------------
2118 IMPLEMENT_CLASS(wxBookCtrlSizer
, wxSizer
)
2120 IMPLEMENT_CLASS(wxNotebookSizer
, wxBookCtrlSizer
)
2121 #endif // wxUSE_NOTEBOOK
2122 #endif // wxUSE_BOOKCTRL
2126 #if WXWIN_COMPATIBILITY_2_6
2128 wxBookCtrlSizer::wxBookCtrlSizer(wxBookCtrlBase
*bookctrl
)
2129 : m_bookctrl(bookctrl
)
2131 wxASSERT_MSG( bookctrl
, wxT("wxBookCtrlSizer needs a control") );
2134 #endif // WXWIN_COMPATIBILITY_2_6
2136 void wxBookCtrlSizer::RecalcSizes()
2138 m_bookctrl
->SetSize( m_position
.x
, m_position
.y
, m_size
.x
, m_size
.y
);
2141 wxSize
wxBookCtrlSizer::CalcMin()
2143 wxSize sizeBorder
= m_bookctrl
->CalcSizeFromPage(wxSize(0,0));
2148 if ( m_bookctrl
->GetPageCount() == 0 )
2150 return wxSize(sizeBorder
.x
+ 10, sizeBorder
.y
+ 10);
2156 wxWindowList::compatibility_iterator
2157 node
= m_bookctrl
->GetChildren().GetFirst();
2160 wxWindow
*item
= node
->GetData();
2161 wxSizer
*itemsizer
= item
->GetSizer();
2165 wxSize
subsize( itemsizer
->CalcMin() );
2167 if (subsize
.x
> maxX
)
2169 if (subsize
.y
> maxY
)
2173 node
= node
->GetNext();
2176 return wxSize( maxX
, maxY
) + sizeBorder
;
2181 #if WXWIN_COMPATIBILITY_2_6
2183 wxNotebookSizer::wxNotebookSizer(wxNotebook
*nb
)
2185 wxASSERT_MSG( nb
, wxT("wxNotebookSizer needs a control") );
2189 #endif // WXWIN_COMPATIBILITY_2_6
2191 #endif // wxUSE_NOTEBOOOK
2192 #endif // wxUSE_BOOKCTRL
2194 #endif // WXWIN_COMPATIBILITY_2_4