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"
23 #include "wx/string.h"
27 #include "wx/settings.h"
28 #include "wx/statbox.h"
31 #include "wx/listimpl.cpp"
33 #if WXWIN_COMPATIBILITY_2_4
34 #include "wx/notebook.h"
37 //---------------------------------------------------------------------------
39 IMPLEMENT_CLASS(wxSizerItem
, wxObject
)
40 IMPLEMENT_CLASS(wxSizer
, wxObject
)
41 IMPLEMENT_CLASS(wxGridSizer
, wxSizer
)
42 IMPLEMENT_CLASS(wxFlexGridSizer
, wxGridSizer
)
43 IMPLEMENT_CLASS(wxBoxSizer
, wxSizer
)
45 IMPLEMENT_CLASS(wxStaticBoxSizer
, wxBoxSizer
)
48 IMPLEMENT_CLASS(wxStdDialogButtonSizer
, wxBoxSizer
)
51 WX_DEFINE_EXPORTED_LIST( wxSizerItemList
)
86 // ----------------------------------------------------------------------------
88 // ----------------------------------------------------------------------------
90 void wxSizerItem::Init(const wxSizerFlags
& flags
)
94 m_proportion
= flags
.GetProportion();
95 m_flag
= flags
.GetFlags();
96 m_border
= flags
.GetBorderInPixels();
99 wxSizerItem::wxSizerItem()
111 void wxSizerItem::SetWindow(wxWindow
*window
)
113 wxCHECK_RET( window
, _T("NULL window in wxSizerItem::SetWindow()") );
115 m_kind
= Item_Window
;
118 // window doesn't become smaller than its initial size, whatever happens
119 m_minSize
= window
->GetSize();
121 if ( m_flag
& wxFIXED_MINSIZE
)
122 window
->SetMinSize(m_minSize
);
124 // aspect ratio calculated from initial size
128 wxSizerItem::wxSizerItem(wxWindow
*window
,
133 : m_proportion(proportion
),
142 void wxSizerItem::SetSizer(wxSizer
*sizer
)
148 wxSizerItem::wxSizerItem(wxSizer
*sizer
,
153 : m_proportion(proportion
),
161 // m_minSize is set later
165 void wxSizerItem::SetSpacer(const wxSize
& size
)
167 m_kind
= Item_Spacer
;
168 m_spacer
= new wxSizerSpacer(size
);
173 wxSizerItem::wxSizerItem(int width
,
179 : m_minSize(width
, height
), // minimal size is the initial size
180 m_proportion(proportion
),
185 SetSpacer(width
, height
);
188 wxSizerItem::~wxSizerItem()
198 m_window
->SetContainingSizer(NULL
);
211 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
215 wxSize
wxSizerItem::GetSpacer() const
218 if ( m_kind
== Item_Spacer
)
219 size
= m_spacer
->GetSize();
225 wxSize
wxSizerItem::GetSize() const
234 ret
= m_window
->GetSize();
238 ret
= m_sizer
->GetSize();
242 ret
= m_spacer
->GetSize();
247 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
254 if (m_flag
& wxNORTH
)
256 if (m_flag
& wxSOUTH
)
262 wxSize
wxSizerItem::CalcMin()
266 m_minSize
= m_sizer
->GetMinSize();
268 // if we have to preserve aspect ratio _AND_ this is
269 // the first-time calculation, consider ret to be initial size
270 if ( (m_flag
& wxSHAPED
) && wxIsNullDouble(m_ratio
) )
273 else if ( IsWindow() )
275 // Since the size of the window may change during runtime, we
276 // should use the current minimal/best size.
277 m_minSize
= m_window
->GetBestFittingSize();
280 return GetMinSizeWithBorder();
283 wxSize
wxSizerItem::GetMinSizeWithBorder() const
285 wxSize ret
= m_minSize
;
291 if (m_flag
& wxNORTH
)
293 if (m_flag
& wxSOUTH
)
300 void wxSizerItem::SetDimension( const wxPoint
& pos_
, const wxSize
& size_
)
304 if (m_flag
& wxSHAPED
)
306 // adjust aspect ratio
307 int rwidth
= (int) (size
.y
* m_ratio
);
311 int rheight
= (int) (size
.x
/ m_ratio
);
312 // add vertical space
313 if (m_flag
& wxALIGN_CENTER_VERTICAL
)
314 pos
.y
+= (size
.y
- rheight
) / 2;
315 else if (m_flag
& wxALIGN_BOTTOM
)
316 pos
.y
+= (size
.y
- rheight
);
317 // use reduced dimensions
320 else if (rwidth
< size
.x
)
322 // add horizontal space
323 if (m_flag
& wxALIGN_CENTER_HORIZONTAL
)
324 pos
.x
+= (size
.x
- rwidth
) / 2;
325 else if (m_flag
& wxALIGN_RIGHT
)
326 pos
.x
+= (size
.x
- rwidth
);
331 // This is what GetPosition() returns. Since we calculate
332 // borders afterwards, GetPosition() will be the left/top
333 // corner of the surrounding border.
345 if (m_flag
& wxNORTH
)
350 if (m_flag
& wxSOUTH
)
355 m_rect
= wxRect(pos
, size
);
360 wxFAIL_MSG( _T("can't set size of uninitialized sizer item") );
364 m_window
->SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
,
365 wxSIZE_ALLOW_MINUS_ONE
);
369 m_sizer
->SetDimension(pos
.x
, pos
.y
, size
.x
, size
.y
);
373 m_spacer
->SetSize(size
);
378 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
382 void wxSizerItem::DeleteWindows()
391 //We are deleting the window from this sizer - normally
392 //the window destroys the sizer associated with it,
393 //which might destroy this, which we don't want
394 m_window
->SetContainingSizer(NULL
);
396 //Putting this after the switch will result in a spacer
397 //not being deleted properly on destruction
402 m_sizer
->DeleteWindows();
407 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
412 void wxSizerItem::Show( bool show
)
417 wxFAIL_MSG( _T("can't show uninitialized sizer item") );
421 m_window
->Show(show
);
429 m_spacer
->Show(show
);
434 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
438 bool wxSizerItem::IsShown() const
443 // we may be called from CalcMin(), just return false so that we're
448 return m_window
->IsShown();
451 // arbitrarily decide that if at least one of our elements is
452 // shown, so are we (this arbitrariness is the reason for
453 // deprecating this function)
455 for ( wxSizerItemList::compatibility_iterator
456 node
= m_sizer
->GetChildren().GetFirst();
458 node
= node
->GetNext() )
460 if ( node
->GetData()->IsShown() )
467 return m_spacer
->IsShown();
471 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
477 #if WXWIN_COMPATIBILITY_2_6
478 void wxSizerItem::SetOption( int option
)
480 SetProportion( option
);
483 int wxSizerItem::GetOption() const
485 return GetProportion();
487 #endif // WXWIN_COMPATIBILITY_2_6
490 //---------------------------------------------------------------------------
492 //---------------------------------------------------------------------------
496 WX_CLEAR_LIST(wxSizerItemList
, m_children
);
499 wxSizerItem
* wxSizer::Insert( size_t index
, wxSizerItem
*item
)
501 m_children
.Insert( index
, item
);
503 if ( item
->GetWindow() )
504 item
->GetWindow()->SetContainingSizer( this );
509 void wxSizer::SetContainingWindow(wxWindow
*win
)
511 if ( win
== m_containingWindow
)
514 m_containingWindow
= win
;
516 // set the same window for all nested sizers as well, they also are in the
518 for ( wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
520 node
= node
->GetNext() )
522 wxSizerItem
*const item
= node
->GetData();
523 wxSizer
*const sizer
= item
->GetSizer();
527 sizer
->SetContainingWindow(win
);
532 #if WXWIN_COMPATIBILITY_2_6
533 bool wxSizer::Remove( wxWindow
*window
)
535 return Detach( window
);
537 #endif // WXWIN_COMPATIBILITY_2_6
539 bool wxSizer::Remove( wxSizer
*sizer
)
541 wxASSERT_MSG( sizer
, _T("Removing NULL sizer") );
543 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
546 wxSizerItem
*item
= node
->GetData();
548 if (item
->GetSizer() == sizer
)
551 m_children
.Erase( node
);
555 node
= node
->GetNext();
561 bool wxSizer::Remove( int index
)
563 wxCHECK_MSG( index
>= 0 && (size_t)index
< m_children
.GetCount(),
565 _T("Remove index is out of range") );
567 wxSizerItemList::compatibility_iterator node
= m_children
.Item( index
);
569 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
571 wxSizerItem
*item
= node
->GetData();
573 if ( item
->IsWindow() )
574 item
->GetWindow()->SetContainingSizer( NULL
);
577 m_children
.Erase( node
);
581 bool wxSizer::Detach( wxSizer
*sizer
)
583 wxASSERT_MSG( sizer
, _T("Detaching NULL sizer") );
585 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
588 wxSizerItem
*item
= node
->GetData();
590 if (item
->GetSizer() == sizer
)
594 m_children
.Erase( node
);
597 node
= node
->GetNext();
603 bool wxSizer::Detach( wxWindow
*window
)
605 wxASSERT_MSG( window
, _T("Detaching NULL window") );
607 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
610 wxSizerItem
*item
= node
->GetData();
612 if (item
->GetWindow() == window
)
614 item
->GetWindow()->SetContainingSizer( NULL
);
616 m_children
.Erase( node
);
619 node
= node
->GetNext();
625 bool wxSizer::Detach( int index
)
627 wxCHECK_MSG( index
>= 0 && (size_t)index
< m_children
.GetCount(),
629 _T("Detach index is out of range") );
631 wxSizerItemList::compatibility_iterator node
= m_children
.Item( index
);
633 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
635 wxSizerItem
*item
= node
->GetData();
637 if ( item
->IsSizer() )
639 else if ( item
->IsWindow() )
640 item
->GetWindow()->SetContainingSizer( NULL
);
643 m_children
.Erase( node
);
647 bool wxSizer::Replace( wxWindow
*oldwin
, wxWindow
*newwin
, bool recursive
)
649 wxASSERT_MSG( oldwin
, _T("Replacing NULL window") );
650 wxASSERT_MSG( newwin
, _T("Replacing with NULL window") );
652 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
655 wxSizerItem
*item
= node
->GetData();
657 if (item
->GetWindow() == oldwin
)
659 item
->GetWindow()->SetContainingSizer( NULL
);
660 item
->SetWindow(newwin
);
661 newwin
->SetContainingSizer( this );
664 else if (recursive
&& item
->IsSizer())
666 if (item
->GetSizer()->Replace( oldwin
, newwin
, true ))
670 node
= node
->GetNext();
676 bool wxSizer::Replace( wxSizer
*oldsz
, wxSizer
*newsz
, bool recursive
)
678 wxASSERT_MSG( oldsz
, _T("Replacing NULL sizer") );
679 wxASSERT_MSG( newsz
, _T("Replacing with NULL sizer") );
681 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
684 wxSizerItem
*item
= node
->GetData();
686 if (item
->GetSizer() == oldsz
)
688 wxSizer
*old
= item
->GetSizer();
689 item
->SetSizer(newsz
);
693 else if (recursive
&& item
->IsSizer())
695 if (item
->GetSizer()->Replace( oldsz
, newsz
, true ))
699 node
= node
->GetNext();
705 bool wxSizer::Replace( size_t old
, wxSizerItem
*newitem
)
707 wxCHECK_MSG( old
< m_children
.GetCount(), false, _T("Replace index is out of range") );
708 wxASSERT_MSG( newitem
, _T("Replacing with NULL item") );
710 wxSizerItemList::compatibility_iterator node
= m_children
.Item( old
);
712 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
714 wxSizerItem
*item
= node
->GetData();
715 node
->SetData(newitem
);
721 void wxSizer::Clear( bool delete_windows
)
723 // First clear the ContainingSizer pointers
724 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
727 wxSizerItem
*item
= node
->GetData();
729 if (item
->IsWindow())
730 item
->GetWindow()->SetContainingSizer( NULL
);
731 node
= node
->GetNext();
734 // Destroy the windows if needed
738 // Now empty the list
739 WX_CLEAR_LIST(wxSizerItemList
, m_children
);
742 void wxSizer::DeleteWindows()
744 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
747 wxSizerItem
*item
= node
->GetData();
749 item
->DeleteWindows();
750 node
= node
->GetNext();
754 wxSize
wxSizer::Fit( wxWindow
*window
)
756 wxSize
size(window
->IsTopLevel() ? FitSize(window
)
757 : GetMinWindowSize(window
));
759 window
->SetSize( size
);
764 void wxSizer::FitInside( wxWindow
*window
)
767 if (window
->IsTopLevel())
768 size
= VirtualFitSize( window
);
770 size
= GetMinClientSize( window
);
772 window
->SetVirtualSize( size
);
775 void wxSizer::Layout()
777 // (re)calculates minimums needed for each item and other preparations
781 // Applies the layout and repositions/resizes the items
785 void wxSizer::SetSizeHints( wxWindow
*window
)
787 // Preserve the window's max size hints, but set the
788 // lower bound according to the sizer calculations.
790 wxSize size
= Fit( window
);
792 window
->SetSizeHints( size
.x
,
794 window
->GetMaxWidth(),
795 window
->GetMaxHeight() );
798 void wxSizer::SetVirtualSizeHints( wxWindow
*window
)
800 // Preserve the window's max size hints, but set the
801 // lower bound according to the sizer calculations.
804 wxSize
size( window
->GetVirtualSize() );
805 window
->SetVirtualSizeHints( size
.x
,
807 window
->GetMaxWidth(),
808 window
->GetMaxHeight() );
811 wxSize
wxSizer::GetMaxWindowSize( wxWindow
*window
) const
813 return window
->GetMaxSize();
816 wxSize
wxSizer::GetMinWindowSize( wxWindow
*window
)
818 wxSize
minSize( GetMinSize() );
819 wxSize
size( window
->GetSize() );
820 wxSize
client_size( window
->GetClientSize() );
822 return wxSize( minSize
.x
+size
.x
-client_size
.x
,
823 minSize
.y
+size
.y
-client_size
.y
);
826 // TODO on mac we need a function that determines how much free space this
827 // min size contains, in order to make sure that we have 20 pixels of free
828 // space around the controls
830 // Return a window size that will fit within the screens dimensions
831 wxSize
wxSizer::FitSize( wxWindow
*window
)
833 if ( window
->IsTopLevel() )
835 wxTopLevelWindow
*tlw
= wxDynamicCast(window
, wxTopLevelWindow
);
836 if ( tlw
&& tlw
->IsAlwaysMaximized() )
838 return tlw
->GetClientSize();
842 wxSize size
= GetMinWindowSize( window
);
843 wxSize sizeMax
= GetMaxWindowSize( window
);
845 // Limit the size if sizeMax != wxDefaultSize
847 if ( size
.x
> sizeMax
.x
&& sizeMax
.x
!= wxDefaultCoord
)
849 if ( size
.y
> sizeMax
.y
&& sizeMax
.y
!= wxDefaultCoord
)
855 wxSize
wxSizer::GetMaxClientSize( wxWindow
*window
) const
857 wxSize
maxSize( window
->GetMaxSize() );
859 if ( maxSize
!= wxDefaultSize
)
861 wxSize
size( window
->GetSize() );
862 wxSize
client_size( window
->GetClientSize() );
864 return wxSize( maxSize
.x
+ client_size
.x
- size
.x
,
865 maxSize
.y
+ client_size
.y
- size
.y
);
868 return wxDefaultSize
;
871 wxSize
wxSizer::GetMinClientSize( wxWindow
*WXUNUSED(window
) )
873 return GetMinSize(); // Already returns client size.
876 wxSize
wxSizer::VirtualFitSize( wxWindow
*window
)
878 wxSize size
= GetMinClientSize( window
);
879 wxSize sizeMax
= GetMaxClientSize( window
);
881 // Limit the size if sizeMax != wxDefaultSize
883 if ( size
.x
> sizeMax
.x
&& sizeMax
.x
!= wxDefaultCoord
)
885 if ( size
.y
> sizeMax
.y
&& sizeMax
.y
!= wxDefaultCoord
)
891 void wxSizer::SetDimension( int x
, int y
, int width
, int height
)
900 wxSize
wxSizer::GetMinSize()
902 wxSize
ret( CalcMin() );
903 if (ret
.x
< m_minSize
.x
) ret
.x
= m_minSize
.x
;
904 if (ret
.y
< m_minSize
.y
) ret
.y
= m_minSize
.y
;
908 void wxSizer::DoSetMinSize( int width
, int height
)
911 m_minSize
.y
= height
;
914 bool wxSizer::DoSetItemMinSize( wxWindow
*window
, int width
, int height
)
916 wxASSERT_MSG( window
, _T("SetMinSize for NULL window") );
918 // Is it our immediate child?
920 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
923 wxSizerItem
*item
= node
->GetData();
925 if (item
->GetWindow() == window
)
927 item
->SetMinSize( width
, height
);
930 node
= node
->GetNext();
933 // No? Search any subsizers we own then
935 node
= m_children
.GetFirst();
938 wxSizerItem
*item
= node
->GetData();
940 if ( item
->GetSizer() &&
941 item
->GetSizer()->DoSetItemMinSize( window
, width
, height
) )
943 // A child sizer found the requested windw, exit.
946 node
= node
->GetNext();
952 bool wxSizer::DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
)
954 wxASSERT_MSG( sizer
, _T("SetMinSize for NULL sizer") );
956 // Is it our immediate child?
958 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
961 wxSizerItem
*item
= node
->GetData();
963 if (item
->GetSizer() == sizer
)
965 item
->GetSizer()->DoSetMinSize( width
, height
);
968 node
= node
->GetNext();
971 // No? Search any subsizers we own then
973 node
= m_children
.GetFirst();
976 wxSizerItem
*item
= node
->GetData();
978 if ( item
->GetSizer() &&
979 item
->GetSizer()->DoSetItemMinSize( sizer
, width
, height
) )
981 // A child found the requested sizer, exit.
984 node
= node
->GetNext();
990 bool wxSizer::DoSetItemMinSize( size_t index
, int width
, int height
)
992 wxSizerItemList::compatibility_iterator node
= m_children
.Item( index
);
994 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
996 wxSizerItem
*item
= node
->GetData();
998 if (item
->GetSizer())
1000 // Sizers contains the minimal size in them, if not calculated ...
1001 item
->GetSizer()->DoSetMinSize( width
, height
);
1005 // ... but the minimal size of spacers and windows is stored via the item
1006 item
->SetMinSize( width
, height
);
1012 wxSizerItem
* wxSizer::GetItem( wxWindow
*window
, bool recursive
)
1014 wxASSERT_MSG( window
, _T("GetItem for NULL window") );
1016 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1019 wxSizerItem
*item
= node
->GetData();
1021 if (item
->GetWindow() == window
)
1025 else if (recursive
&& item
->IsSizer())
1027 wxSizerItem
*subitem
= item
->GetSizer()->GetItem( window
, true );
1032 node
= node
->GetNext();
1038 wxSizerItem
* wxSizer::GetItem( wxSizer
*sizer
, bool recursive
)
1040 wxASSERT_MSG( sizer
, _T("GetItem for NULL sizer") );
1042 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1045 wxSizerItem
*item
= node
->GetData();
1047 if (item
->GetSizer() == sizer
)
1051 else if (recursive
&& item
->IsSizer())
1053 wxSizerItem
*subitem
= item
->GetSizer()->GetItem( sizer
, true );
1058 node
= node
->GetNext();
1064 wxSizerItem
* wxSizer::GetItem( size_t index
)
1066 wxCHECK_MSG( index
< m_children
.GetCount(),
1068 _T("GetItem index is out of range") );
1070 return m_children
.Item( index
)->GetData();
1073 bool wxSizer::Show( wxWindow
*window
, bool show
, bool recursive
)
1075 wxSizerItem
*item
= GetItem( window
, recursive
);
1086 bool wxSizer::Show( wxSizer
*sizer
, bool show
, bool recursive
)
1088 wxSizerItem
*item
= GetItem( sizer
, recursive
);
1099 bool wxSizer::Show( size_t index
, bool show
)
1101 wxSizerItem
*item
= GetItem( index
);
1112 void wxSizer::ShowItems( bool show
)
1114 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1117 node
->GetData()->Show( show
);
1118 node
= node
->GetNext();
1122 bool wxSizer::IsShown( wxWindow
*window
) const
1124 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1127 wxSizerItem
*item
= node
->GetData();
1129 if (item
->GetWindow() == window
)
1131 return item
->IsShown();
1133 node
= node
->GetNext();
1136 wxFAIL_MSG( _T("IsShown failed to find sizer item") );
1141 bool wxSizer::IsShown( wxSizer
*sizer
) const
1143 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1146 wxSizerItem
*item
= node
->GetData();
1148 if (item
->GetSizer() == sizer
)
1150 return item
->IsShown();
1152 node
= node
->GetNext();
1155 wxFAIL_MSG( _T("IsShown failed to find sizer item") );
1160 bool wxSizer::IsShown( size_t index
) const
1162 wxCHECK_MSG( index
< m_children
.GetCount(),
1164 _T("IsShown index is out of range") );
1166 return m_children
.Item( index
)->GetData()->IsShown();
1170 //---------------------------------------------------------------------------
1172 //---------------------------------------------------------------------------
1174 wxGridSizer::wxGridSizer( int rows
, int cols
, int vgap
, int hgap
)
1175 : m_rows( ( cols
== 0 && rows
== 0 ) ? 1 : rows
)
1182 wxGridSizer::wxGridSizer( int cols
, int vgap
, int hgap
)
1183 : m_rows( cols
== 0 ? 1 : 0 )
1190 int wxGridSizer::CalcRowsCols(int& nrows
, int& ncols
) const
1192 int nitems
= m_children
.GetCount();
1198 nrows
= (nitems
+ m_cols
- 1) / m_cols
;
1202 ncols
= (nitems
+ m_rows
- 1) / m_rows
;
1205 else // 0 columns, 0 rows?
1207 wxFAIL_MSG( _T("grid sizer must have either rows or columns fixed") );
1216 void wxGridSizer::RecalcSizes()
1218 int nitems
, nrows
, ncols
;
1219 if ( (nitems
= CalcRowsCols(nrows
, ncols
)) == 0 )
1222 wxSize
sz( GetSize() );
1223 wxPoint
pt( GetPosition() );
1225 int w
= (sz
.x
- (ncols
- 1) * m_hgap
) / ncols
;
1226 int h
= (sz
.y
- (nrows
- 1) * m_vgap
) / nrows
;
1229 for (int c
= 0; c
< ncols
; c
++)
1232 for (int r
= 0; r
< nrows
; r
++)
1234 int i
= r
* ncols
+ c
;
1237 wxSizerItemList::compatibility_iterator node
= m_children
.Item( i
);
1239 wxASSERT_MSG( node
, _T("Failed to find SizerItemList node") );
1241 SetItemBounds( node
->GetData(), x
, y
, w
, h
);
1249 wxSize
wxGridSizer::CalcMin()
1252 if ( CalcRowsCols(nrows
, ncols
) == 0 )
1255 // Find the max width and height for any component
1259 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1262 wxSizerItem
*item
= node
->GetData();
1263 wxSize
sz( item
->CalcMin() );
1265 w
= wxMax( w
, sz
.x
);
1266 h
= wxMax( h
, sz
.y
);
1268 node
= node
->GetNext();
1271 return wxSize( ncols
* w
+ (ncols
-1) * m_hgap
,
1272 nrows
* h
+ (nrows
-1) * m_vgap
);
1275 void wxGridSizer::SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
)
1278 wxSize
sz( item
->GetMinSizeWithBorder() );
1279 int flag
= item
->GetFlag();
1281 if ((flag
& wxEXPAND
) || (flag
& wxSHAPED
))
1287 if (flag
& wxALIGN_CENTER_HORIZONTAL
)
1289 pt
.x
= x
+ (w
- sz
.x
) / 2;
1291 else if (flag
& wxALIGN_RIGHT
)
1293 pt
.x
= x
+ (w
- sz
.x
);
1296 if (flag
& wxALIGN_CENTER_VERTICAL
)
1298 pt
.y
= y
+ (h
- sz
.y
) / 2;
1300 else if (flag
& wxALIGN_BOTTOM
)
1302 pt
.y
= y
+ (h
- sz
.y
);
1306 item
->SetDimension(pt
, sz
);
1309 //---------------------------------------------------------------------------
1311 //---------------------------------------------------------------------------
1313 wxFlexGridSizer::wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
)
1314 : wxGridSizer( rows
, cols
, vgap
, hgap
),
1315 m_flexDirection(wxBOTH
),
1316 m_growMode(wxFLEX_GROWMODE_SPECIFIED
)
1320 wxFlexGridSizer::wxFlexGridSizer( int cols
, int vgap
, int hgap
)
1321 : wxGridSizer( cols
, vgap
, hgap
),
1322 m_flexDirection(wxBOTH
),
1323 m_growMode(wxFLEX_GROWMODE_SPECIFIED
)
1327 wxFlexGridSizer::~wxFlexGridSizer()
1331 void wxFlexGridSizer::RecalcSizes()
1333 int nitems
, nrows
, ncols
;
1334 if ( (nitems
= CalcRowsCols(nrows
, ncols
)) == 0 )
1337 wxPoint
pt( GetPosition() );
1338 wxSize
sz( GetSize() );
1340 AdjustForGrowables(sz
, m_calculatedMinSize
, nrows
, ncols
);
1342 sz
= wxSize( pt
.x
+ sz
.x
, pt
.y
+ sz
.y
);
1345 for (int c
= 0; c
< ncols
; c
++)
1348 for (int r
= 0; r
< nrows
; r
++)
1350 int i
= r
* ncols
+ c
;
1353 wxSizerItemList::compatibility_iterator node
= m_children
.Item( i
);
1355 wxASSERT_MSG( node
, _T("Failed to find node") );
1357 int w
= wxMax( 0, wxMin( m_colWidths
[c
], sz
.x
- x
) );
1358 int h
= wxMax( 0, wxMin( m_rowHeights
[r
], sz
.y
- y
) );
1360 SetItemBounds( node
->GetData(), x
, y
, w
, h
);
1362 if (m_rowHeights
[r
] != -1)
1363 y
= y
+ m_rowHeights
[r
] + m_vgap
;
1365 if (m_colWidths
[c
] != -1)
1366 x
= x
+ m_colWidths
[c
] + m_hgap
;
1370 wxSize
wxFlexGridSizer::CalcMin()
1376 // Number of rows/columns can change as items are added or removed.
1377 if ( !CalcRowsCols(nrows
, ncols
) )
1380 m_rowHeights
.SetCount(nrows
);
1381 m_colWidths
.SetCount(ncols
);
1383 // We have to recalcuate the sizes in case the item minimum size has
1384 // changed since the previous layout, or the item has been hidden using
1385 // wxSizer::Show(). If all the items in a row/column are hidden, the final
1386 // dimension of the row/column will be -1, indicating that the column
1387 // itself is hidden.
1388 for( s
= m_rowHeights
.GetCount(), i
= 0; i
< s
; ++i
)
1389 m_rowHeights
[ i
] = -1;
1390 for( s
= m_colWidths
.GetCount(), i
= 0; i
< s
; ++i
)
1391 m_colWidths
[ i
] = -1;
1393 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1398 wxSizerItem
*item
= node
->GetData();
1399 if ( item
->IsShown() )
1401 wxSize
sz( item
->CalcMin() );
1402 int row
= i
/ ncols
;
1403 int col
= i
% ncols
;
1405 m_rowHeights
[ row
] = wxMax( wxMax( 0, sz
.y
), m_rowHeights
[ row
] );
1406 m_colWidths
[ col
] = wxMax( wxMax( 0, sz
.x
), m_colWidths
[ col
] );
1409 node
= node
->GetNext();
1413 AdjustForFlexDirection();
1415 // Sum total minimum size, including gaps between rows/columns.
1416 // -1 is used as a magic number meaning empty column.
1418 for (int col
= 0; col
< ncols
; col
++)
1419 if ( m_colWidths
[ col
] != -1 )
1420 width
+= m_colWidths
[ col
] + m_hgap
;
1425 for (int row
= 0; row
< nrows
; row
++)
1426 if ( m_rowHeights
[ row
] != -1 )
1427 height
+= m_rowHeights
[ row
] + m_vgap
;
1431 m_calculatedMinSize
= wxSize( width
, height
);
1432 return m_calculatedMinSize
;
1435 void wxFlexGridSizer::AdjustForFlexDirection()
1437 // the logic in CalcMin works when we resize flexibly in both directions
1438 // but maybe this is not the case
1439 if ( m_flexDirection
!= wxBOTH
)
1441 // select the array corresponding to the direction in which we do *not*
1443 wxArrayInt
& array
= m_flexDirection
== wxVERTICAL
? m_colWidths
1446 const size_t count
= array
.GetCount();
1448 // find the largest value in this array
1452 for ( n
= 0; n
< count
; ++n
)
1454 if ( array
[n
] > largest
)
1458 // and now fill it with the largest value
1459 for ( n
= 0; n
< count
; ++n
)
1467 void wxFlexGridSizer::AdjustForGrowables(const wxSize
& sz
, const wxSize
& minsz
,
1468 int nrows
, int ncols
)
1470 // what to do with the rows? by default, resize them proportionally
1471 if ( sz
.y
> minsz
.y
&& ( (m_flexDirection
& wxVERTICAL
) || (m_growMode
== wxFLEX_GROWMODE_SPECIFIED
) ) )
1473 int sum_proportions
= 0;
1474 int growable_space
= 0;
1477 for (idx
= 0; idx
< m_growableRows
.GetCount(); idx
++)
1479 // Since the number of rows/columns can change as items are
1480 // inserted/deleted, we need to verify at runtime that the
1481 // requested growable rows/columns are still valid.
1482 if (m_growableRows
[idx
] >= nrows
)
1485 // If all items in a row/column are hidden, that row/column will
1486 // have a dimension of -1. This causes the row/column to be
1487 // hidden completely.
1488 if (m_rowHeights
[ m_growableRows
[idx
] ] == -1)
1490 sum_proportions
+= m_growableRowsProportions
[idx
];
1491 growable_space
+= m_rowHeights
[ m_growableRows
[idx
] ];
1497 for (idx
= 0; idx
< m_growableRows
.GetCount(); idx
++)
1499 if (m_growableRows
[idx
] >= nrows
)
1501 if (m_rowHeights
[ m_growableRows
[idx
] ] == -1)
1502 m_rowHeights
[ m_growableRows
[idx
] ] = 0;
1505 int delta
= (sz
.y
- minsz
.y
);
1506 if (sum_proportions
== 0)
1507 delta
= (delta
/num
) + m_rowHeights
[ m_growableRows
[idx
] ];
1509 delta
= ((delta
+growable_space
)*m_growableRowsProportions
[idx
]) / sum_proportions
;
1510 m_rowHeights
[ m_growableRows
[idx
] ] = delta
;
1515 else if ( (m_growMode
== wxFLEX_GROWMODE_ALL
) && (sz
.y
> minsz
.y
) )
1517 // rounding problem?
1518 for ( int row
= 0; row
< nrows
; ++row
)
1519 m_rowHeights
[ row
] = sz
.y
/ nrows
;
1522 // the same logic as above but for the columns
1523 if ( sz
.x
> minsz
.x
&& ( (m_flexDirection
& wxHORIZONTAL
) || (m_growMode
== wxFLEX_GROWMODE_SPECIFIED
) ) )
1525 int sum_proportions
= 0;
1526 int growable_space
= 0;
1529 for (idx
= 0; idx
< m_growableCols
.GetCount(); idx
++)
1531 // Since the number of rows/columns can change as items are
1532 // inserted/deleted, we need to verify at runtime that the
1533 // requested growable rows/columns are still valid.
1534 if (m_growableCols
[idx
] >= ncols
)
1537 // If all items in a row/column are hidden, that row/column will
1538 // have a dimension of -1. This causes the column to be hidden
1540 if (m_colWidths
[ m_growableCols
[idx
] ] == -1)
1542 sum_proportions
+= m_growableColsProportions
[idx
];
1543 growable_space
+= m_colWidths
[ m_growableCols
[idx
] ];
1549 for (idx
= 0; idx
< m_growableCols
.GetCount(); idx
++)
1551 if (m_growableCols
[idx
] >= ncols
)
1553 if (m_colWidths
[ m_growableCols
[idx
] ] == -1)
1554 m_colWidths
[ m_growableCols
[idx
] ] = 0;
1557 int delta
= (sz
.x
- minsz
.x
);
1558 if (sum_proportions
== 0)
1559 delta
= (delta
/num
) + m_colWidths
[ m_growableCols
[idx
] ];
1561 delta
= ((delta
+growable_space
)*m_growableColsProportions
[idx
])/sum_proportions
;
1562 m_colWidths
[ m_growableCols
[idx
] ] = delta
;
1567 else if ( (m_growMode
== wxFLEX_GROWMODE_ALL
) && (sz
.x
> minsz
.x
) )
1569 for ( int col
=0; col
< ncols
; ++col
)
1570 m_colWidths
[ col
] = sz
.x
/ ncols
;
1575 void wxFlexGridSizer::AddGrowableRow( size_t idx
, int proportion
)
1577 m_growableRows
.Add( idx
);
1578 m_growableRowsProportions
.Add( proportion
);
1581 void wxFlexGridSizer::AddGrowableCol( size_t idx
, int proportion
)
1583 m_growableCols
.Add( idx
);
1584 m_growableColsProportions
.Add( proportion
);
1587 // helper function for RemoveGrowableCol/Row()
1589 DoRemoveFromArrays(size_t idx
, wxArrayInt
& items
, wxArrayInt
& proportions
)
1591 const size_t count
= items
.size();
1592 for ( size_t n
= 0; n
< count
; n
++ )
1594 if ( (size_t)items
[n
] == idx
)
1597 proportions
.RemoveAt(n
);
1602 wxFAIL_MSG( _T("column/row is already not growable") );
1605 void wxFlexGridSizer::RemoveGrowableCol( size_t idx
)
1607 DoRemoveFromArrays(idx
, m_growableCols
, m_growableColsProportions
);
1610 void wxFlexGridSizer::RemoveGrowableRow( size_t idx
)
1612 DoRemoveFromArrays(idx
, m_growableRows
, m_growableRowsProportions
);
1615 //---------------------------------------------------------------------------
1617 //---------------------------------------------------------------------------
1619 wxBoxSizer::wxBoxSizer( int orient
)
1620 : m_orient( orient
)
1624 void wxBoxSizer::RecalcSizes()
1626 if (m_children
.GetCount() == 0)
1632 if (m_orient
== wxHORIZONTAL
)
1633 delta
= m_size
.x
- m_fixedWidth
;
1635 delta
= m_size
.y
- m_fixedHeight
;
1638 wxPoint
pt( m_position
);
1640 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1643 wxSizerItem
*item
= node
->GetData();
1645 if (item
->IsShown())
1647 wxSize
size( item
->GetMinSizeWithBorder() );
1649 if (m_orient
== wxVERTICAL
)
1651 wxCoord height
= size
.y
;
1652 if (item
->GetProportion())
1654 // Because of at least one visible item has non-zero
1655 // proportion then m_stretchable is not zero
1656 height
= (delta
* item
->GetProportion()) / m_stretchable
;
1659 wxPoint
child_pos( pt
);
1660 wxSize
child_size( size
.x
, height
);
1662 if (item
->GetFlag() & (wxEXPAND
| wxSHAPED
))
1663 child_size
.x
= m_size
.x
;
1664 else if (item
->GetFlag() & wxALIGN_RIGHT
)
1665 child_pos
.x
+= m_size
.x
- size
.x
;
1666 else if (item
->GetFlag() & (wxCENTER
| wxALIGN_CENTER_HORIZONTAL
))
1667 // XXX wxCENTER is added for backward compatibility;
1668 // wxALIGN_CENTER should be used in new code
1669 child_pos
.x
+= (m_size
.x
- size
.x
) / 2;
1671 item
->SetDimension( child_pos
, child_size
);
1677 wxCoord width
= size
.x
;
1678 if (item
->GetProportion())
1680 // Because of at least one visible item has non-zero
1681 // proportion then m_stretchable is not zero
1682 width
= (delta
* item
->GetProportion()) / m_stretchable
;
1685 wxPoint
child_pos( pt
);
1686 wxSize
child_size( width
, size
.y
);
1688 if (item
->GetFlag() & (wxEXPAND
| wxSHAPED
))
1689 child_size
.y
= m_size
.y
;
1690 else if (item
->GetFlag() & wxALIGN_BOTTOM
)
1691 child_pos
.y
+= m_size
.y
- size
.y
;
1692 else if (item
->GetFlag() & (wxCENTER
| wxALIGN_CENTER_VERTICAL
))
1693 // XXX wxCENTER is added for backward compatibility;
1694 // wxALIGN_CENTER should be used in new code
1695 child_pos
.y
+= (m_size
.y
- size
.y
) / 2;
1697 item
->SetDimension( child_pos
, child_size
);
1703 node
= node
->GetNext();
1707 wxSize
wxBoxSizer::CalcMin()
1709 if (m_children
.GetCount() == 0)
1718 // precalc item minsizes and count proportions
1719 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1722 wxSizerItem
*item
= node
->GetData();
1724 if ( item
->IsShown() )
1726 item
->CalcMin(); // result is stored in the item
1728 m_stretchable
+= item
->GetProportion();
1731 node
= node
->GetNext();
1734 // Total minimum size (width or height) of sizer
1737 node
= m_children
.GetFirst();
1740 wxSizerItem
*item
= node
->GetData();
1742 if (item
->IsShown() && item
->GetProportion() != 0)
1744 int stretch
= item
->GetProportion();
1745 wxSize
size( item
->GetMinSizeWithBorder() );
1748 // Integer division rounded up is (a + b - 1) / b
1749 // Round up needed in order to guarantee that all
1750 // all items will have size not less then their min size
1751 if (m_orient
== wxHORIZONTAL
)
1752 minSize
= ( size
.x
*m_stretchable
+ stretch
- 1)/stretch
;
1754 minSize
= ( size
.y
*m_stretchable
+ stretch
- 1)/stretch
;
1756 if (minSize
> maxMinSize
)
1757 maxMinSize
= minSize
;
1759 node
= node
->GetNext();
1762 // Calculate overall minimum size
1763 node
= m_children
.GetFirst();
1766 wxSizerItem
*item
= node
->GetData();
1768 if (item
->IsShown())
1770 wxSize
size( item
->GetMinSizeWithBorder() );
1771 if (item
->GetProportion() != 0)
1773 if (m_orient
== wxHORIZONTAL
)
1774 size
.x
= (maxMinSize
*item
->GetProportion())/m_stretchable
;
1776 size
.y
= (maxMinSize
*item
->GetProportion())/m_stretchable
;
1780 if (m_orient
== wxVERTICAL
)
1782 m_fixedHeight
+= size
.y
;
1783 m_fixedWidth
= wxMax( m_fixedWidth
, size
.x
);
1787 m_fixedWidth
+= size
.x
;
1788 m_fixedHeight
= wxMax( m_fixedHeight
, size
.y
);
1792 if (m_orient
== wxHORIZONTAL
)
1794 m_minWidth
+= size
.x
;
1795 m_minHeight
= wxMax( m_minHeight
, size
.y
);
1799 m_minHeight
+= size
.y
;
1800 m_minWidth
= wxMax( m_minWidth
, size
.x
);
1803 node
= node
->GetNext();
1806 return wxSize( m_minWidth
, m_minHeight
);
1809 //---------------------------------------------------------------------------
1811 //---------------------------------------------------------------------------
1815 wxStaticBoxSizer::wxStaticBoxSizer( wxStaticBox
*box
, int orient
)
1816 : wxBoxSizer( orient
),
1819 wxASSERT_MSG( box
, wxT("wxStaticBoxSizer needs a static box") );
1821 // do this so that our Detach() is called if the static box is destroyed
1823 m_staticBox
->SetContainingSizer(this);
1826 wxStaticBoxSizer::wxStaticBoxSizer(int orient
, wxWindow
*win
, const wxString
& s
)
1827 : wxBoxSizer(orient
),
1828 m_staticBox(new wxStaticBox(win
, wxID_ANY
, s
))
1831 m_staticBox
->SetContainingSizer(this);
1834 wxStaticBoxSizer::~wxStaticBoxSizer()
1839 static void GetStaticBoxBorders( wxStaticBox
*box
,
1843 // this has to be done platform by platform as there is no way to
1844 // guess the thickness of a wxStaticBox border
1845 box
->GetBordersForSizer(borderTop
, borderOther
);
1848 void wxStaticBoxSizer::RecalcSizes()
1850 int top_border
, other_border
;
1851 GetStaticBoxBorders(m_staticBox
, &top_border
, &other_border
);
1853 m_staticBox
->SetSize( m_position
.x
, m_position
.y
, m_size
.x
, m_size
.y
);
1855 wxPoint
old_pos( m_position
);
1856 m_position
.x
+= other_border
;
1857 m_position
.y
+= top_border
;
1858 wxSize
old_size( m_size
);
1859 m_size
.x
-= 2*other_border
;
1860 m_size
.y
-= top_border
+ other_border
;
1862 wxBoxSizer::RecalcSizes();
1864 m_position
= old_pos
;
1868 wxSize
wxStaticBoxSizer::CalcMin()
1870 int top_border
, other_border
;
1871 GetStaticBoxBorders(m_staticBox
, &top_border
, &other_border
);
1873 wxSize
ret( wxBoxSizer::CalcMin() );
1874 ret
.x
+= 2*other_border
;
1875 ret
.y
+= other_border
+ top_border
;
1880 void wxStaticBoxSizer::ShowItems( bool show
)
1882 m_staticBox
->Show( show
);
1883 wxBoxSizer::ShowItems( show
);
1886 bool wxStaticBoxSizer::Detach( wxWindow
*window
)
1888 // avoid deleting m_staticBox in our dtor if it's being detached from the
1889 // sizer (which can happen because it's being already destroyed for
1891 if ( window
== m_staticBox
)
1897 return wxSizer::Detach( window
);
1900 #endif // wxUSE_STATBOX
1904 wxStdDialogButtonSizer::wxStdDialogButtonSizer()
1905 : wxBoxSizer(wxHORIZONTAL
)
1907 // Vertical buttons with lots of space on either side
1908 // looks rubbish on WinCE, so let's not do this for now.
1909 // If we are going to use vertical buttons, we should
1910 // put the sizer to the right of other controls in the dialog,
1911 // and that's beyond the scope of this sizer.
1913 bool is_pda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
1914 // If we have a PDA screen, put yes/no button over
1915 // all other buttons, otherwise on the left side.
1917 m_orient
= wxVERTICAL
;
1920 m_buttonAffirmative
= NULL
;
1921 m_buttonApply
= NULL
;
1922 m_buttonNegative
= NULL
;
1923 m_buttonCancel
= NULL
;
1924 m_buttonHelp
= NULL
;
1927 void wxStdDialogButtonSizer::AddButton(wxButton
*mybutton
)
1929 switch (mybutton
->GetId())
1934 m_buttonAffirmative
= mybutton
;
1937 m_buttonApply
= mybutton
;
1940 m_buttonNegative
= mybutton
;
1943 m_buttonCancel
= mybutton
;
1946 case wxID_CONTEXT_HELP
:
1947 m_buttonHelp
= mybutton
;
1954 void wxStdDialogButtonSizer::SetAffirmativeButton( wxButton
*button
)
1956 m_buttonAffirmative
= button
;
1959 void wxStdDialogButtonSizer::SetNegativeButton( wxButton
*button
)
1961 m_buttonNegative
= button
;
1964 void wxStdDialogButtonSizer::SetCancelButton( wxButton
*button
)
1966 m_buttonCancel
= button
;
1969 void wxStdDialogButtonSizer::Realize()
1972 Add(0, 0, 0, wxLEFT
, 6);
1974 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 6);
1976 if (m_buttonNegative
){
1977 // HIG POLICE BULLETIN - destructive buttons need extra padding
1978 // 24 pixels on either side
1979 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 12);
1982 // extra whitespace between help/negative and cancel/ok buttons
1983 Add(0, 0, 1, wxEXPAND
, 0);
1985 if (m_buttonCancel
){
1986 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 6);
1987 // Cancel or help should be default
1988 // m_buttonCancel->SetDefaultButton();
1991 // Ugh, Mac doesn't really have apply dialogs, so I'll just
1992 // figure the best place is between Cancel and OK
1994 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 6);
1996 if (m_buttonAffirmative
){
1997 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
, 6);
1999 if (m_buttonAffirmative
->GetId() == wxID_SAVE
){
2000 // these buttons have set labels under Mac so we should use them
2001 m_buttonAffirmative
->SetLabel(_("Save"));
2002 m_buttonNegative
->SetLabel(_("Don't Save"));
2006 // Extra space around and at the right
2008 #elif defined(__WXGTK20__)
2009 Add(0, 0, 0, wxLEFT
, 9);
2011 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
2013 // extra whitespace between help and cancel/ok buttons
2014 Add(0, 0, 1, wxEXPAND
, 0);
2016 if (m_buttonNegative
){
2017 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
2020 if (m_buttonCancel
){
2021 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
2022 // Cancel or help should be default
2023 // m_buttonCancel->SetDefaultButton();
2027 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
2029 if (m_buttonAffirmative
)
2030 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
, 6);
2031 #elif defined(__WXMSW__)
2034 // right-justify buttons
2035 Add(0, 0, 1, wxEXPAND
, 0);
2037 if (m_buttonAffirmative
){
2038 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonAffirmative
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2041 if (m_buttonNegative
){
2042 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonNegative
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2045 if (m_buttonCancel
){
2046 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonCancel
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2049 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonApply
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2052 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonHelp
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2054 // GTK+1 and any other platform
2056 // Add(0, 0, 0, wxLEFT, 5); // Not sure what this was for but it unbalances the dialog
2058 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonHelp
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2060 // extra whitespace between help and cancel/ok buttons
2061 Add(0, 0, 1, wxEXPAND
, 0);
2064 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonApply
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2066 if (m_buttonAffirmative
){
2067 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonAffirmative
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2070 if (m_buttonNegative
){
2071 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonNegative
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2074 if (m_buttonCancel
){
2075 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonCancel
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2076 // Cancel or help should be default
2077 // m_buttonCancel->SetDefaultButton();
2083 #endif // wxUSE_BUTTON
2085 #if WXWIN_COMPATIBILITY_2_4
2087 // ----------------------------------------------------------------------------
2089 // ----------------------------------------------------------------------------
2092 IMPLEMENT_CLASS(wxBookCtrlSizer
, wxSizer
)
2094 IMPLEMENT_CLASS(wxNotebookSizer
, wxBookCtrlSizer
)
2095 #endif // wxUSE_NOTEBOOK
2096 #endif // wxUSE_BOOKCTRL
2100 #if WXWIN_COMPATIBILITY_2_6
2102 wxBookCtrlSizer::wxBookCtrlSizer(wxBookCtrlBase
*bookctrl
)
2103 : m_bookctrl(bookctrl
)
2105 wxASSERT_MSG( bookctrl
, wxT("wxBookCtrlSizer needs a control") );
2108 #endif // WXWIN_COMPATIBILITY_2_6
2110 void wxBookCtrlSizer::RecalcSizes()
2112 m_bookctrl
->SetSize( m_position
.x
, m_position
.y
, m_size
.x
, m_size
.y
);
2115 wxSize
wxBookCtrlSizer::CalcMin()
2117 wxSize sizeBorder
= m_bookctrl
->CalcSizeFromPage(wxSize(0,0));
2122 if ( m_bookctrl
->GetPageCount() == 0 )
2124 return wxSize(sizeBorder
.x
+ 10, sizeBorder
.y
+ 10);
2130 wxWindowList::compatibility_iterator
2131 node
= m_bookctrl
->GetChildren().GetFirst();
2134 wxWindow
*item
= node
->GetData();
2135 wxSizer
*itemsizer
= item
->GetSizer();
2139 wxSize
subsize( itemsizer
->CalcMin() );
2141 if (subsize
.x
> maxX
)
2143 if (subsize
.y
> maxY
)
2147 node
= node
->GetNext();
2150 return wxSize( maxX
, maxY
) + sizeBorder
;
2155 #if WXWIN_COMPATIBILITY_2_6
2157 wxNotebookSizer::wxNotebookSizer(wxNotebook
*nb
)
2159 wxASSERT_MSG( nb
, wxT("wxNotebookSizer needs a control") );
2163 #endif // WXWIN_COMPATIBILITY_2_6
2165 #endif // wxUSE_NOTEBOOOK
2166 #endif // wxUSE_BOOKCTRL
2168 #endif // WXWIN_COMPATIBILITY_2_4