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/button.h"
29 #include "wx/statbox.h"
32 #include "wx/listimpl.cpp"
34 #if WXWIN_COMPATIBILITY_2_4
35 #include "wx/notebook.h"
38 //---------------------------------------------------------------------------
40 IMPLEMENT_CLASS(wxSizerItem
, wxObject
)
41 IMPLEMENT_CLASS(wxSizer
, wxObject
)
42 IMPLEMENT_CLASS(wxGridSizer
, wxSizer
)
43 IMPLEMENT_CLASS(wxFlexGridSizer
, wxGridSizer
)
44 IMPLEMENT_CLASS(wxBoxSizer
, wxSizer
)
46 IMPLEMENT_CLASS(wxStaticBoxSizer
, wxBoxSizer
)
49 IMPLEMENT_CLASS(wxStdDialogButtonSizer
, wxBoxSizer
)
52 WX_DEFINE_EXPORTED_LIST( wxSizerItemList
)
87 // ----------------------------------------------------------------------------
89 // ----------------------------------------------------------------------------
91 void wxSizerItem::Init(const wxSizerFlags
& flags
)
95 m_proportion
= flags
.GetProportion();
96 m_flag
= flags
.GetFlags();
97 m_border
= flags
.GetBorderInPixels();
100 wxSizerItem::wxSizerItem()
112 void wxSizerItem::SetWindow(wxWindow
*window
)
114 wxCHECK_RET( window
, _T("NULL window in wxSizerItem::SetWindow()") );
116 m_kind
= Item_Window
;
119 // window doesn't become smaller than its initial size, whatever happens
120 m_minSize
= window
->GetSize();
122 if ( m_flag
& wxFIXED_MINSIZE
)
123 window
->SetMinSize(m_minSize
);
125 // aspect ratio calculated from initial size
129 wxSizerItem::wxSizerItem(wxWindow
*window
,
134 : m_proportion(proportion
),
143 void wxSizerItem::SetSizer(wxSizer
*sizer
)
149 wxSizerItem::wxSizerItem(wxSizer
*sizer
,
154 : m_proportion(proportion
),
162 // m_minSize is set later
166 void wxSizerItem::SetSpacer(const wxSize
& size
)
168 m_kind
= Item_Spacer
;
169 m_spacer
= new wxSizerSpacer(size
);
174 wxSizerItem::wxSizerItem(int width
,
180 : m_minSize(width
, height
), // minimal size is the initial size
181 m_proportion(proportion
),
186 SetSpacer(width
, height
);
189 wxSizerItem::~wxSizerItem()
199 m_window
->SetContainingSizer(NULL
);
212 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
216 wxSize
wxSizerItem::GetSpacer() const
219 if ( m_kind
== Item_Spacer
)
220 size
= m_spacer
->GetSize();
226 wxSize
wxSizerItem::GetSize() const
235 ret
= m_window
->GetSize();
239 ret
= m_sizer
->GetSize();
243 ret
= m_spacer
->GetSize();
248 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
255 if (m_flag
& wxNORTH
)
257 if (m_flag
& wxSOUTH
)
263 wxSize
wxSizerItem::CalcMin()
267 m_minSize
= m_sizer
->GetMinSize();
269 // if we have to preserve aspect ratio _AND_ this is
270 // the first-time calculation, consider ret to be initial size
271 if ( (m_flag
& wxSHAPED
) && wxIsNullDouble(m_ratio
) )
274 else if ( IsWindow() )
276 // Since the size of the window may change during runtime, we
277 // should use the current minimal/best size.
278 m_minSize
= m_window
->GetBestFittingSize();
281 return GetMinSizeWithBorder();
284 wxSize
wxSizerItem::GetMinSizeWithBorder() const
286 wxSize ret
= m_minSize
;
292 if (m_flag
& wxNORTH
)
294 if (m_flag
& wxSOUTH
)
301 void wxSizerItem::SetDimension( const wxPoint
& pos_
, const wxSize
& size_
)
305 if (m_flag
& wxSHAPED
)
307 // adjust aspect ratio
308 int rwidth
= (int) (size
.y
* m_ratio
);
312 int rheight
= (int) (size
.x
/ m_ratio
);
313 // add vertical space
314 if (m_flag
& wxALIGN_CENTER_VERTICAL
)
315 pos
.y
+= (size
.y
- rheight
) / 2;
316 else if (m_flag
& wxALIGN_BOTTOM
)
317 pos
.y
+= (size
.y
- rheight
);
318 // use reduced dimensions
321 else if (rwidth
< size
.x
)
323 // add horizontal space
324 if (m_flag
& wxALIGN_CENTER_HORIZONTAL
)
325 pos
.x
+= (size
.x
- rwidth
) / 2;
326 else if (m_flag
& wxALIGN_RIGHT
)
327 pos
.x
+= (size
.x
- rwidth
);
332 // This is what GetPosition() returns. Since we calculate
333 // borders afterwards, GetPosition() will be the left/top
334 // corner of the surrounding border.
346 if (m_flag
& wxNORTH
)
351 if (m_flag
& wxSOUTH
)
356 m_rect
= wxRect(pos
, size
);
361 wxFAIL_MSG( _T("can't set size of uninitialized sizer item") );
365 m_window
->SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
,
366 wxSIZE_ALLOW_MINUS_ONE
);
370 m_sizer
->SetDimension(pos
.x
, pos
.y
, size
.x
, size
.y
);
374 m_spacer
->SetSize(size
);
379 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
383 void wxSizerItem::DeleteWindows()
392 //We are deleting the window from this sizer - normally
393 //the window destroys the sizer associated with it,
394 //which might destroy this, which we don't want
395 m_window
->SetContainingSizer(NULL
);
397 //Putting this after the switch will result in a spacer
398 //not being deleted properly on destruction
403 m_sizer
->DeleteWindows();
408 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
413 void wxSizerItem::Show( bool show
)
418 wxFAIL_MSG( _T("can't show uninitialized sizer item") );
422 m_window
->Show(show
);
430 m_spacer
->Show(show
);
435 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
439 bool wxSizerItem::IsShown() const
444 // we may be called from CalcMin(), just return false so that we're
449 return m_window
->IsShown();
452 // arbitrarily decide that if at least one of our elements is
453 // shown, so are we (this arbitrariness is the reason for
454 // deprecating this function)
456 for ( wxSizerItemList::compatibility_iterator
457 node
= m_sizer
->GetChildren().GetFirst();
459 node
= node
->GetNext() )
461 if ( node
->GetData()->IsShown() )
468 return m_spacer
->IsShown();
472 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
478 #if WXWIN_COMPATIBILITY_2_6
479 void wxSizerItem::SetOption( int option
)
481 SetProportion( option
);
484 int wxSizerItem::GetOption() const
486 return GetProportion();
488 #endif // WXWIN_COMPATIBILITY_2_6
491 //---------------------------------------------------------------------------
493 //---------------------------------------------------------------------------
497 WX_CLEAR_LIST(wxSizerItemList
, m_children
);
500 wxSizerItem
* wxSizer::Insert( size_t index
, wxSizerItem
*item
)
502 m_children
.Insert( index
, item
);
504 if ( item
->GetWindow() )
505 item
->GetWindow()->SetContainingSizer( this );
510 void wxSizer::SetContainingWindow(wxWindow
*win
)
512 if ( win
== m_containingWindow
)
515 m_containingWindow
= win
;
517 // set the same window for all nested sizers as well, they also are in the
519 for ( wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
521 node
= node
->GetNext() )
523 wxSizerItem
*const item
= node
->GetData();
524 wxSizer
*const sizer
= item
->GetSizer();
528 sizer
->SetContainingWindow(win
);
533 #if WXWIN_COMPATIBILITY_2_6
534 bool wxSizer::Remove( wxWindow
*window
)
536 return Detach( window
);
538 #endif // WXWIN_COMPATIBILITY_2_6
540 bool wxSizer::Remove( wxSizer
*sizer
)
542 wxASSERT_MSG( sizer
, _T("Removing NULL sizer") );
544 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
547 wxSizerItem
*item
= node
->GetData();
549 if (item
->GetSizer() == sizer
)
552 m_children
.Erase( node
);
556 node
= node
->GetNext();
562 bool wxSizer::Remove( int index
)
564 wxCHECK_MSG( index
>= 0 && (size_t)index
< m_children
.GetCount(),
566 _T("Remove index is out of range") );
568 wxSizerItemList::compatibility_iterator node
= m_children
.Item( index
);
570 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
572 wxSizerItem
*item
= node
->GetData();
574 if ( item
->IsWindow() )
575 item
->GetWindow()->SetContainingSizer( NULL
);
578 m_children
.Erase( node
);
582 bool wxSizer::Detach( wxSizer
*sizer
)
584 wxASSERT_MSG( sizer
, _T("Detaching NULL sizer") );
586 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
589 wxSizerItem
*item
= node
->GetData();
591 if (item
->GetSizer() == sizer
)
595 m_children
.Erase( node
);
598 node
= node
->GetNext();
604 bool wxSizer::Detach( wxWindow
*window
)
606 wxASSERT_MSG( window
, _T("Detaching NULL window") );
608 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
611 wxSizerItem
*item
= node
->GetData();
613 if (item
->GetWindow() == window
)
615 item
->GetWindow()->SetContainingSizer( NULL
);
617 m_children
.Erase( node
);
620 node
= node
->GetNext();
626 bool wxSizer::Detach( int index
)
628 wxCHECK_MSG( index
>= 0 && (size_t)index
< m_children
.GetCount(),
630 _T("Detach index is out of range") );
632 wxSizerItemList::compatibility_iterator node
= m_children
.Item( index
);
634 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
636 wxSizerItem
*item
= node
->GetData();
638 if ( item
->IsSizer() )
640 else if ( item
->IsWindow() )
641 item
->GetWindow()->SetContainingSizer( NULL
);
644 m_children
.Erase( node
);
648 bool wxSizer::Replace( wxWindow
*oldwin
, wxWindow
*newwin
, bool recursive
)
650 wxASSERT_MSG( oldwin
, _T("Replacing NULL window") );
651 wxASSERT_MSG( newwin
, _T("Replacing with NULL window") );
653 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
656 wxSizerItem
*item
= node
->GetData();
658 if (item
->GetWindow() == oldwin
)
660 item
->GetWindow()->SetContainingSizer( NULL
);
661 item
->SetWindow(newwin
);
662 newwin
->SetContainingSizer( this );
665 else if (recursive
&& item
->IsSizer())
667 if (item
->GetSizer()->Replace( oldwin
, newwin
, true ))
671 node
= node
->GetNext();
677 bool wxSizer::Replace( wxSizer
*oldsz
, wxSizer
*newsz
, bool recursive
)
679 wxASSERT_MSG( oldsz
, _T("Replacing NULL sizer") );
680 wxASSERT_MSG( newsz
, _T("Replacing with NULL sizer") );
682 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
685 wxSizerItem
*item
= node
->GetData();
687 if (item
->GetSizer() == oldsz
)
689 wxSizer
*old
= item
->GetSizer();
690 item
->SetSizer(newsz
);
694 else if (recursive
&& item
->IsSizer())
696 if (item
->GetSizer()->Replace( oldsz
, newsz
, true ))
700 node
= node
->GetNext();
706 bool wxSizer::Replace( size_t old
, wxSizerItem
*newitem
)
708 wxCHECK_MSG( old
< m_children
.GetCount(), false, _T("Replace index is out of range") );
709 wxASSERT_MSG( newitem
, _T("Replacing with NULL item") );
711 wxSizerItemList::compatibility_iterator node
= m_children
.Item( old
);
713 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
715 wxSizerItem
*item
= node
->GetData();
716 node
->SetData(newitem
);
722 void wxSizer::Clear( bool delete_windows
)
724 // First clear the ContainingSizer pointers
725 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
728 wxSizerItem
*item
= node
->GetData();
730 if (item
->IsWindow())
731 item
->GetWindow()->SetContainingSizer( NULL
);
732 node
= node
->GetNext();
735 // Destroy the windows if needed
739 // Now empty the list
740 WX_CLEAR_LIST(wxSizerItemList
, m_children
);
743 void wxSizer::DeleteWindows()
745 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
748 wxSizerItem
*item
= node
->GetData();
750 item
->DeleteWindows();
751 node
= node
->GetNext();
755 wxSize
wxSizer::Fit( wxWindow
*window
)
757 wxSize
size(window
->IsTopLevel() ? FitSize(window
)
758 : GetMinWindowSize(window
));
760 window
->SetSize( size
);
765 void wxSizer::FitInside( wxWindow
*window
)
768 if (window
->IsTopLevel())
769 size
= VirtualFitSize( window
);
771 size
= GetMinClientSize( window
);
773 window
->SetVirtualSize( size
);
776 void wxSizer::Layout()
778 // (re)calculates minimums needed for each item and other preparations
782 // Applies the layout and repositions/resizes the items
786 void wxSizer::SetSizeHints( wxWindow
*window
)
788 // Preserve the window's max size hints, but set the
789 // lower bound according to the sizer calculations.
791 wxSize size
= Fit( window
);
793 window
->SetSizeHints( size
.x
,
795 window
->GetMaxWidth(),
796 window
->GetMaxHeight() );
799 void wxSizer::SetVirtualSizeHints( wxWindow
*window
)
801 // Preserve the window's max size hints, but set the
802 // lower bound according to the sizer calculations.
805 wxSize
size( window
->GetVirtualSize() );
806 window
->SetVirtualSizeHints( size
.x
,
808 window
->GetMaxWidth(),
809 window
->GetMaxHeight() );
812 wxSize
wxSizer::GetMaxWindowSize( wxWindow
*window
) const
814 return window
->GetMaxSize();
817 wxSize
wxSizer::GetMinWindowSize( wxWindow
*window
)
819 wxSize
minSize( GetMinSize() );
820 wxSize
size( window
->GetSize() );
821 wxSize
client_size( window
->GetClientSize() );
823 return wxSize( minSize
.x
+size
.x
-client_size
.x
,
824 minSize
.y
+size
.y
-client_size
.y
);
827 // TODO on mac we need a function that determines how much free space this
828 // min size contains, in order to make sure that we have 20 pixels of free
829 // space around the controls
831 // Return a window size that will fit within the screens dimensions
832 wxSize
wxSizer::FitSize( wxWindow
*window
)
834 if ( window
->IsTopLevel() )
836 wxTopLevelWindow
*tlw
= wxDynamicCast(window
, wxTopLevelWindow
);
837 if ( tlw
&& tlw
->IsAlwaysMaximized() )
839 return tlw
->GetClientSize();
843 wxSize size
= GetMinWindowSize( window
);
844 wxSize sizeMax
= GetMaxWindowSize( window
);
846 // Limit the size if sizeMax != wxDefaultSize
848 if ( size
.x
> sizeMax
.x
&& sizeMax
.x
!= wxDefaultCoord
)
850 if ( size
.y
> sizeMax
.y
&& sizeMax
.y
!= wxDefaultCoord
)
856 wxSize
wxSizer::GetMaxClientSize( wxWindow
*window
) const
858 wxSize
maxSize( window
->GetMaxSize() );
860 if ( maxSize
!= wxDefaultSize
)
862 wxSize
size( window
->GetSize() );
863 wxSize
client_size( window
->GetClientSize() );
865 return wxSize( maxSize
.x
+ client_size
.x
- size
.x
,
866 maxSize
.y
+ client_size
.y
- size
.y
);
869 return wxDefaultSize
;
872 wxSize
wxSizer::GetMinClientSize( wxWindow
*WXUNUSED(window
) )
874 return GetMinSize(); // Already returns client size.
877 wxSize
wxSizer::VirtualFitSize( wxWindow
*window
)
879 wxSize size
= GetMinClientSize( window
);
880 wxSize sizeMax
= GetMaxClientSize( window
);
882 // Limit the size if sizeMax != wxDefaultSize
884 if ( size
.x
> sizeMax
.x
&& sizeMax
.x
!= wxDefaultCoord
)
886 if ( size
.y
> sizeMax
.y
&& sizeMax
.y
!= wxDefaultCoord
)
892 void wxSizer::SetDimension( int x
, int y
, int width
, int height
)
901 wxSize
wxSizer::GetMinSize()
903 wxSize
ret( CalcMin() );
904 if (ret
.x
< m_minSize
.x
) ret
.x
= m_minSize
.x
;
905 if (ret
.y
< m_minSize
.y
) ret
.y
= m_minSize
.y
;
909 void wxSizer::DoSetMinSize( int width
, int height
)
912 m_minSize
.y
= height
;
915 bool wxSizer::DoSetItemMinSize( wxWindow
*window
, int width
, int height
)
917 wxASSERT_MSG( window
, _T("SetMinSize for NULL window") );
919 // Is it our immediate child?
921 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
924 wxSizerItem
*item
= node
->GetData();
926 if (item
->GetWindow() == window
)
928 item
->SetMinSize( width
, height
);
931 node
= node
->GetNext();
934 // No? Search any subsizers we own then
936 node
= m_children
.GetFirst();
939 wxSizerItem
*item
= node
->GetData();
941 if ( item
->GetSizer() &&
942 item
->GetSizer()->DoSetItemMinSize( window
, width
, height
) )
944 // A child sizer found the requested windw, exit.
947 node
= node
->GetNext();
953 bool wxSizer::DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
)
955 wxASSERT_MSG( sizer
, _T("SetMinSize for NULL sizer") );
957 // Is it our immediate child?
959 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
962 wxSizerItem
*item
= node
->GetData();
964 if (item
->GetSizer() == sizer
)
966 item
->GetSizer()->DoSetMinSize( width
, height
);
969 node
= node
->GetNext();
972 // No? Search any subsizers we own then
974 node
= m_children
.GetFirst();
977 wxSizerItem
*item
= node
->GetData();
979 if ( item
->GetSizer() &&
980 item
->GetSizer()->DoSetItemMinSize( sizer
, width
, height
) )
982 // A child found the requested sizer, exit.
985 node
= node
->GetNext();
991 bool wxSizer::DoSetItemMinSize( size_t index
, int width
, int height
)
993 wxSizerItemList::compatibility_iterator node
= m_children
.Item( index
);
995 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
997 wxSizerItem
*item
= node
->GetData();
999 if (item
->GetSizer())
1001 // Sizers contains the minimal size in them, if not calculated ...
1002 item
->GetSizer()->DoSetMinSize( width
, height
);
1006 // ... but the minimal size of spacers and windows is stored via the item
1007 item
->SetMinSize( width
, height
);
1013 wxSizerItem
* wxSizer::GetItem( wxWindow
*window
, bool recursive
)
1015 wxASSERT_MSG( window
, _T("GetItem for NULL window") );
1017 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1020 wxSizerItem
*item
= node
->GetData();
1022 if (item
->GetWindow() == window
)
1026 else if (recursive
&& item
->IsSizer())
1028 wxSizerItem
*subitem
= item
->GetSizer()->GetItem( window
, true );
1033 node
= node
->GetNext();
1039 wxSizerItem
* wxSizer::GetItem( wxSizer
*sizer
, bool recursive
)
1041 wxASSERT_MSG( sizer
, _T("GetItem for NULL sizer") );
1043 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1046 wxSizerItem
*item
= node
->GetData();
1048 if (item
->GetSizer() == sizer
)
1052 else if (recursive
&& item
->IsSizer())
1054 wxSizerItem
*subitem
= item
->GetSizer()->GetItem( sizer
, true );
1059 node
= node
->GetNext();
1065 wxSizerItem
* wxSizer::GetItem( size_t index
)
1067 wxCHECK_MSG( index
< m_children
.GetCount(),
1069 _T("GetItem index is out of range") );
1071 return m_children
.Item( index
)->GetData();
1074 bool wxSizer::Show( wxWindow
*window
, bool show
, bool recursive
)
1076 wxSizerItem
*item
= GetItem( window
, recursive
);
1087 bool wxSizer::Show( wxSizer
*sizer
, bool show
, bool recursive
)
1089 wxSizerItem
*item
= GetItem( sizer
, recursive
);
1100 bool wxSizer::Show( size_t index
, bool show
)
1102 wxSizerItem
*item
= GetItem( index
);
1113 void wxSizer::ShowItems( bool show
)
1115 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1118 node
->GetData()->Show( show
);
1119 node
= node
->GetNext();
1123 bool wxSizer::IsShown( wxWindow
*window
) const
1125 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1128 wxSizerItem
*item
= node
->GetData();
1130 if (item
->GetWindow() == window
)
1132 return item
->IsShown();
1134 node
= node
->GetNext();
1137 wxFAIL_MSG( _T("IsShown failed to find sizer item") );
1142 bool wxSizer::IsShown( wxSizer
*sizer
) const
1144 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1147 wxSizerItem
*item
= node
->GetData();
1149 if (item
->GetSizer() == sizer
)
1151 return item
->IsShown();
1153 node
= node
->GetNext();
1156 wxFAIL_MSG( _T("IsShown failed to find sizer item") );
1161 bool wxSizer::IsShown( size_t index
) const
1163 wxCHECK_MSG( index
< m_children
.GetCount(),
1165 _T("IsShown index is out of range") );
1167 return m_children
.Item( index
)->GetData()->IsShown();
1171 //---------------------------------------------------------------------------
1173 //---------------------------------------------------------------------------
1175 wxGridSizer::wxGridSizer( int rows
, int cols
, int vgap
, int hgap
)
1176 : m_rows( ( cols
== 0 && rows
== 0 ) ? 1 : rows
)
1183 wxGridSizer::wxGridSizer( int cols
, int vgap
, int hgap
)
1184 : m_rows( cols
== 0 ? 1 : 0 )
1191 int wxGridSizer::CalcRowsCols(int& nrows
, int& ncols
) const
1193 int nitems
= m_children
.GetCount();
1199 nrows
= (nitems
+ m_cols
- 1) / m_cols
;
1203 ncols
= (nitems
+ m_rows
- 1) / m_rows
;
1206 else // 0 columns, 0 rows?
1208 wxFAIL_MSG( _T("grid sizer must have either rows or columns fixed") );
1217 void wxGridSizer::RecalcSizes()
1219 int nitems
, nrows
, ncols
;
1220 if ( (nitems
= CalcRowsCols(nrows
, ncols
)) == 0 )
1223 wxSize
sz( GetSize() );
1224 wxPoint
pt( GetPosition() );
1226 int w
= (sz
.x
- (ncols
- 1) * m_hgap
) / ncols
;
1227 int h
= (sz
.y
- (nrows
- 1) * m_vgap
) / nrows
;
1230 for (int c
= 0; c
< ncols
; c
++)
1233 for (int r
= 0; r
< nrows
; r
++)
1235 int i
= r
* ncols
+ c
;
1238 wxSizerItemList::compatibility_iterator node
= m_children
.Item( i
);
1240 wxASSERT_MSG( node
, _T("Failed to find SizerItemList node") );
1242 SetItemBounds( node
->GetData(), x
, y
, w
, h
);
1250 wxSize
wxGridSizer::CalcMin()
1253 if ( CalcRowsCols(nrows
, ncols
) == 0 )
1256 // Find the max width and height for any component
1260 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1263 wxSizerItem
*item
= node
->GetData();
1264 wxSize
sz( item
->CalcMin() );
1266 w
= wxMax( w
, sz
.x
);
1267 h
= wxMax( h
, sz
.y
);
1269 node
= node
->GetNext();
1272 return wxSize( ncols
* w
+ (ncols
-1) * m_hgap
,
1273 nrows
* h
+ (nrows
-1) * m_vgap
);
1276 void wxGridSizer::SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
)
1279 wxSize
sz( item
->GetMinSizeWithBorder() );
1280 int flag
= item
->GetFlag();
1282 if ((flag
& wxEXPAND
) || (flag
& wxSHAPED
))
1288 if (flag
& wxALIGN_CENTER_HORIZONTAL
)
1290 pt
.x
= x
+ (w
- sz
.x
) / 2;
1292 else if (flag
& wxALIGN_RIGHT
)
1294 pt
.x
= x
+ (w
- sz
.x
);
1297 if (flag
& wxALIGN_CENTER_VERTICAL
)
1299 pt
.y
= y
+ (h
- sz
.y
) / 2;
1301 else if (flag
& wxALIGN_BOTTOM
)
1303 pt
.y
= y
+ (h
- sz
.y
);
1307 item
->SetDimension(pt
, sz
);
1310 //---------------------------------------------------------------------------
1312 //---------------------------------------------------------------------------
1314 wxFlexGridSizer::wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
)
1315 : wxGridSizer( rows
, cols
, vgap
, hgap
),
1316 m_flexDirection(wxBOTH
),
1317 m_growMode(wxFLEX_GROWMODE_SPECIFIED
)
1321 wxFlexGridSizer::wxFlexGridSizer( int cols
, int vgap
, int hgap
)
1322 : wxGridSizer( cols
, vgap
, hgap
),
1323 m_flexDirection(wxBOTH
),
1324 m_growMode(wxFLEX_GROWMODE_SPECIFIED
)
1328 wxFlexGridSizer::~wxFlexGridSizer()
1332 void wxFlexGridSizer::RecalcSizes()
1334 int nitems
, nrows
, ncols
;
1335 if ( (nitems
= CalcRowsCols(nrows
, ncols
)) == 0 )
1338 wxPoint
pt( GetPosition() );
1339 wxSize
sz( GetSize() );
1341 AdjustForGrowables(sz
, m_calculatedMinSize
, nrows
, ncols
);
1343 sz
= wxSize( pt
.x
+ sz
.x
, pt
.y
+ sz
.y
);
1346 for (int c
= 0; c
< ncols
; c
++)
1349 for (int r
= 0; r
< nrows
; r
++)
1351 int i
= r
* ncols
+ c
;
1354 wxSizerItemList::compatibility_iterator node
= m_children
.Item( i
);
1356 wxASSERT_MSG( node
, _T("Failed to find node") );
1358 int w
= wxMax( 0, wxMin( m_colWidths
[c
], sz
.x
- x
) );
1359 int h
= wxMax( 0, wxMin( m_rowHeights
[r
], sz
.y
- y
) );
1361 SetItemBounds( node
->GetData(), x
, y
, w
, h
);
1363 if (m_rowHeights
[r
] != -1)
1364 y
= y
+ m_rowHeights
[r
] + m_vgap
;
1366 if (m_colWidths
[c
] != -1)
1367 x
= x
+ m_colWidths
[c
] + m_hgap
;
1371 wxSize
wxFlexGridSizer::CalcMin()
1377 // Number of rows/columns can change as items are added or removed.
1378 if ( !CalcRowsCols(nrows
, ncols
) )
1381 m_rowHeights
.SetCount(nrows
);
1382 m_colWidths
.SetCount(ncols
);
1384 // We have to recalcuate the sizes in case the item minimum size has
1385 // changed since the previous layout, or the item has been hidden using
1386 // wxSizer::Show(). If all the items in a row/column are hidden, the final
1387 // dimension of the row/column will be -1, indicating that the column
1388 // itself is hidden.
1389 for( s
= m_rowHeights
.GetCount(), i
= 0; i
< s
; ++i
)
1390 m_rowHeights
[ i
] = -1;
1391 for( s
= m_colWidths
.GetCount(), i
= 0; i
< s
; ++i
)
1392 m_colWidths
[ i
] = -1;
1394 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1399 wxSizerItem
*item
= node
->GetData();
1400 if ( item
->IsShown() )
1402 wxSize
sz( item
->CalcMin() );
1403 int row
= i
/ ncols
;
1404 int col
= i
% ncols
;
1406 m_rowHeights
[ row
] = wxMax( wxMax( 0, sz
.y
), m_rowHeights
[ row
] );
1407 m_colWidths
[ col
] = wxMax( wxMax( 0, sz
.x
), m_colWidths
[ col
] );
1410 node
= node
->GetNext();
1414 AdjustForFlexDirection();
1416 // Sum total minimum size, including gaps between rows/columns.
1417 // -1 is used as a magic number meaning empty column.
1419 for (int col
= 0; col
< ncols
; col
++)
1420 if ( m_colWidths
[ col
] != -1 )
1421 width
+= m_colWidths
[ col
] + m_hgap
;
1426 for (int row
= 0; row
< nrows
; row
++)
1427 if ( m_rowHeights
[ row
] != -1 )
1428 height
+= m_rowHeights
[ row
] + m_vgap
;
1432 m_calculatedMinSize
= wxSize( width
, height
);
1433 return m_calculatedMinSize
;
1436 void wxFlexGridSizer::AdjustForFlexDirection()
1438 // the logic in CalcMin works when we resize flexibly in both directions
1439 // but maybe this is not the case
1440 if ( m_flexDirection
!= wxBOTH
)
1442 // select the array corresponding to the direction in which we do *not*
1444 wxArrayInt
& array
= m_flexDirection
== wxVERTICAL
? m_colWidths
1447 const size_t count
= array
.GetCount();
1449 // find the largest value in this array
1453 for ( n
= 0; n
< count
; ++n
)
1455 if ( array
[n
] > largest
)
1459 // and now fill it with the largest value
1460 for ( n
= 0; n
< count
; ++n
)
1468 void wxFlexGridSizer::AdjustForGrowables(const wxSize
& sz
, const wxSize
& minsz
,
1469 int nrows
, int ncols
)
1471 // what to do with the rows? by default, resize them proportionally
1472 if ( sz
.y
> minsz
.y
&& ( (m_flexDirection
& wxVERTICAL
) || (m_growMode
== wxFLEX_GROWMODE_SPECIFIED
) ) )
1474 int sum_proportions
= 0;
1475 int growable_space
= 0;
1478 for (idx
= 0; idx
< m_growableRows
.GetCount(); idx
++)
1480 // Since the number of rows/columns can change as items are
1481 // inserted/deleted, we need to verify at runtime that the
1482 // requested growable rows/columns are still valid.
1483 if (m_growableRows
[idx
] >= nrows
)
1486 // If all items in a row/column are hidden, that row/column will
1487 // have a dimension of -1. This causes the row/column to be
1488 // hidden completely.
1489 if (m_rowHeights
[ m_growableRows
[idx
] ] == -1)
1491 sum_proportions
+= m_growableRowsProportions
[idx
];
1492 growable_space
+= m_rowHeights
[ m_growableRows
[idx
] ];
1498 for (idx
= 0; idx
< m_growableRows
.GetCount(); idx
++)
1500 if (m_growableRows
[idx
] >= nrows
)
1502 if (m_rowHeights
[ m_growableRows
[idx
] ] == -1)
1503 m_rowHeights
[ m_growableRows
[idx
] ] = 0;
1506 int delta
= (sz
.y
- minsz
.y
);
1507 if (sum_proportions
== 0)
1508 delta
= (delta
/num
) + m_rowHeights
[ m_growableRows
[idx
] ];
1510 delta
= ((delta
+growable_space
)*m_growableRowsProportions
[idx
]) / sum_proportions
;
1511 m_rowHeights
[ m_growableRows
[idx
] ] = delta
;
1516 else if ( (m_growMode
== wxFLEX_GROWMODE_ALL
) && (sz
.y
> minsz
.y
) )
1518 // rounding problem?
1519 for ( int row
= 0; row
< nrows
; ++row
)
1520 m_rowHeights
[ row
] = sz
.y
/ nrows
;
1523 // the same logic as above but for the columns
1524 if ( sz
.x
> minsz
.x
&& ( (m_flexDirection
& wxHORIZONTAL
) || (m_growMode
== wxFLEX_GROWMODE_SPECIFIED
) ) )
1526 int sum_proportions
= 0;
1527 int growable_space
= 0;
1530 for (idx
= 0; idx
< m_growableCols
.GetCount(); idx
++)
1532 // Since the number of rows/columns can change as items are
1533 // inserted/deleted, we need to verify at runtime that the
1534 // requested growable rows/columns are still valid.
1535 if (m_growableCols
[idx
] >= ncols
)
1538 // If all items in a row/column are hidden, that row/column will
1539 // have a dimension of -1. This causes the column to be hidden
1541 if (m_colWidths
[ m_growableCols
[idx
] ] == -1)
1543 sum_proportions
+= m_growableColsProportions
[idx
];
1544 growable_space
+= m_colWidths
[ m_growableCols
[idx
] ];
1550 for (idx
= 0; idx
< m_growableCols
.GetCount(); idx
++)
1552 if (m_growableCols
[idx
] >= ncols
)
1554 if (m_colWidths
[ m_growableCols
[idx
] ] == -1)
1555 m_colWidths
[ m_growableCols
[idx
] ] = 0;
1558 int delta
= (sz
.x
- minsz
.x
);
1559 if (sum_proportions
== 0)
1560 delta
= (delta
/num
) + m_colWidths
[ m_growableCols
[idx
] ];
1562 delta
= ((delta
+growable_space
)*m_growableColsProportions
[idx
])/sum_proportions
;
1563 m_colWidths
[ m_growableCols
[idx
] ] = delta
;
1568 else if ( (m_growMode
== wxFLEX_GROWMODE_ALL
) && (sz
.x
> minsz
.x
) )
1570 for ( int col
=0; col
< ncols
; ++col
)
1571 m_colWidths
[ col
] = sz
.x
/ ncols
;
1576 void wxFlexGridSizer::AddGrowableRow( size_t idx
, int proportion
)
1578 m_growableRows
.Add( idx
);
1579 m_growableRowsProportions
.Add( proportion
);
1582 void wxFlexGridSizer::AddGrowableCol( size_t idx
, int proportion
)
1584 m_growableCols
.Add( idx
);
1585 m_growableColsProportions
.Add( proportion
);
1588 // helper function for RemoveGrowableCol/Row()
1590 DoRemoveFromArrays(size_t idx
, wxArrayInt
& items
, wxArrayInt
& proportions
)
1592 const size_t count
= items
.size();
1593 for ( size_t n
= 0; n
< count
; n
++ )
1595 if ( (size_t)items
[n
] == idx
)
1598 proportions
.RemoveAt(n
);
1603 wxFAIL_MSG( _T("column/row is already not growable") );
1606 void wxFlexGridSizer::RemoveGrowableCol( size_t idx
)
1608 DoRemoveFromArrays(idx
, m_growableCols
, m_growableColsProportions
);
1611 void wxFlexGridSizer::RemoveGrowableRow( size_t idx
)
1613 DoRemoveFromArrays(idx
, m_growableRows
, m_growableRowsProportions
);
1616 //---------------------------------------------------------------------------
1618 //---------------------------------------------------------------------------
1620 wxBoxSizer::wxBoxSizer( int orient
)
1621 : m_orient( orient
)
1625 void wxBoxSizer::RecalcSizes()
1627 if (m_children
.GetCount() == 0)
1633 if (m_orient
== wxHORIZONTAL
)
1634 delta
= m_size
.x
- m_fixedWidth
;
1636 delta
= m_size
.y
- m_fixedHeight
;
1639 wxPoint
pt( m_position
);
1641 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1644 wxSizerItem
*item
= node
->GetData();
1646 if (item
->IsShown())
1648 wxSize
size( item
->GetMinSizeWithBorder() );
1650 if (m_orient
== wxVERTICAL
)
1652 wxCoord height
= size
.y
;
1653 if (item
->GetProportion())
1655 // Because of at least one visible item has non-zero
1656 // proportion then m_stretchable is not zero
1657 height
= (delta
* item
->GetProportion()) / m_stretchable
;
1660 wxPoint
child_pos( pt
);
1661 wxSize
child_size( size
.x
, height
);
1663 if (item
->GetFlag() & (wxEXPAND
| wxSHAPED
))
1664 child_size
.x
= m_size
.x
;
1665 else if (item
->GetFlag() & wxALIGN_RIGHT
)
1666 child_pos
.x
+= m_size
.x
- size
.x
;
1667 else if (item
->GetFlag() & (wxCENTER
| wxALIGN_CENTER_HORIZONTAL
))
1668 // XXX wxCENTER is added for backward compatibility;
1669 // wxALIGN_CENTER should be used in new code
1670 child_pos
.x
+= (m_size
.x
- size
.x
) / 2;
1672 item
->SetDimension( child_pos
, child_size
);
1678 wxCoord width
= size
.x
;
1679 if (item
->GetProportion())
1681 // Because of at least one visible item has non-zero
1682 // proportion then m_stretchable is not zero
1683 width
= (delta
* item
->GetProportion()) / m_stretchable
;
1686 wxPoint
child_pos( pt
);
1687 wxSize
child_size( width
, size
.y
);
1689 if (item
->GetFlag() & (wxEXPAND
| wxSHAPED
))
1690 child_size
.y
= m_size
.y
;
1691 else if (item
->GetFlag() & wxALIGN_BOTTOM
)
1692 child_pos
.y
+= m_size
.y
- size
.y
;
1693 else if (item
->GetFlag() & (wxCENTER
| wxALIGN_CENTER_VERTICAL
))
1694 // XXX wxCENTER is added for backward compatibility;
1695 // wxALIGN_CENTER should be used in new code
1696 child_pos
.y
+= (m_size
.y
- size
.y
) / 2;
1698 if ( m_containingWindow
)
1700 child_pos
.x
= m_containingWindow
->AdjustForLayoutDirection
1708 item
->SetDimension( child_pos
, child_size
);
1714 node
= node
->GetNext();
1718 wxSize
wxBoxSizer::CalcMin()
1720 if (m_children
.GetCount() == 0)
1729 // precalc item minsizes and count proportions
1730 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1733 wxSizerItem
*item
= node
->GetData();
1735 if ( item
->IsShown() )
1737 item
->CalcMin(); // result is stored in the item
1739 m_stretchable
+= item
->GetProportion();
1742 node
= node
->GetNext();
1745 // Total minimum size (width or height) of sizer
1748 node
= m_children
.GetFirst();
1751 wxSizerItem
*item
= node
->GetData();
1753 if (item
->IsShown() && item
->GetProportion() != 0)
1755 int stretch
= item
->GetProportion();
1756 wxSize
size( item
->GetMinSizeWithBorder() );
1759 // Integer division rounded up is (a + b - 1) / b
1760 // Round up needed in order to guarantee that all
1761 // all items will have size not less then their min size
1762 if (m_orient
== wxHORIZONTAL
)
1763 minSize
= ( size
.x
*m_stretchable
+ stretch
- 1)/stretch
;
1765 minSize
= ( size
.y
*m_stretchable
+ stretch
- 1)/stretch
;
1767 if (minSize
> maxMinSize
)
1768 maxMinSize
= minSize
;
1770 node
= node
->GetNext();
1773 // Calculate overall minimum size
1774 node
= m_children
.GetFirst();
1777 wxSizerItem
*item
= node
->GetData();
1779 if (item
->IsShown())
1781 wxSize
size( item
->GetMinSizeWithBorder() );
1782 if (item
->GetProportion() != 0)
1784 if (m_orient
== wxHORIZONTAL
)
1785 size
.x
= (maxMinSize
*item
->GetProportion())/m_stretchable
;
1787 size
.y
= (maxMinSize
*item
->GetProportion())/m_stretchable
;
1791 if (m_orient
== wxVERTICAL
)
1793 m_fixedHeight
+= size
.y
;
1794 m_fixedWidth
= wxMax( m_fixedWidth
, size
.x
);
1798 m_fixedWidth
+= size
.x
;
1799 m_fixedHeight
= wxMax( m_fixedHeight
, size
.y
);
1803 if (m_orient
== wxHORIZONTAL
)
1805 m_minWidth
+= size
.x
;
1806 m_minHeight
= wxMax( m_minHeight
, size
.y
);
1810 m_minHeight
+= size
.y
;
1811 m_minWidth
= wxMax( m_minWidth
, size
.x
);
1814 node
= node
->GetNext();
1817 return wxSize( m_minWidth
, m_minHeight
);
1820 //---------------------------------------------------------------------------
1822 //---------------------------------------------------------------------------
1826 wxStaticBoxSizer::wxStaticBoxSizer( wxStaticBox
*box
, int orient
)
1827 : wxBoxSizer( orient
),
1830 wxASSERT_MSG( box
, wxT("wxStaticBoxSizer needs a static box") );
1832 // do this so that our Detach() is called if the static box is destroyed
1834 m_staticBox
->SetContainingSizer(this);
1837 wxStaticBoxSizer::wxStaticBoxSizer(int orient
, wxWindow
*win
, const wxString
& s
)
1838 : wxBoxSizer(orient
),
1839 m_staticBox(new wxStaticBox(win
, wxID_ANY
, s
))
1842 m_staticBox
->SetContainingSizer(this);
1845 wxStaticBoxSizer::~wxStaticBoxSizer()
1850 static void GetStaticBoxBorders( wxStaticBox
*box
,
1854 // this has to be done platform by platform as there is no way to
1855 // guess the thickness of a wxStaticBox border
1856 box
->GetBordersForSizer(borderTop
, borderOther
);
1859 void wxStaticBoxSizer::RecalcSizes()
1861 int top_border
, other_border
;
1862 GetStaticBoxBorders(m_staticBox
, &top_border
, &other_border
);
1864 m_staticBox
->SetSize( m_position
.x
, m_position
.y
, m_size
.x
, m_size
.y
);
1866 wxPoint
old_pos( m_position
);
1867 m_position
.x
+= other_border
;
1868 m_position
.y
+= top_border
;
1869 wxSize
old_size( m_size
);
1870 m_size
.x
-= 2*other_border
;
1871 m_size
.y
-= top_border
+ other_border
;
1873 wxBoxSizer::RecalcSizes();
1875 m_position
= old_pos
;
1879 wxSize
wxStaticBoxSizer::CalcMin()
1881 int top_border
, other_border
;
1882 GetStaticBoxBorders(m_staticBox
, &top_border
, &other_border
);
1884 wxSize
ret( wxBoxSizer::CalcMin() );
1885 ret
.x
+= 2*other_border
;
1886 ret
.y
+= other_border
+ top_border
;
1891 void wxStaticBoxSizer::ShowItems( bool show
)
1893 m_staticBox
->Show( show
);
1894 wxBoxSizer::ShowItems( show
);
1897 bool wxStaticBoxSizer::Detach( wxWindow
*window
)
1899 // avoid deleting m_staticBox in our dtor if it's being detached from the
1900 // sizer (which can happen because it's being already destroyed for
1902 if ( window
== m_staticBox
)
1908 return wxSizer::Detach( window
);
1911 #endif // wxUSE_STATBOX
1915 wxStdDialogButtonSizer::wxStdDialogButtonSizer()
1916 : wxBoxSizer(wxHORIZONTAL
)
1918 // Vertical buttons with lots of space on either side
1919 // looks rubbish on WinCE, so let's not do this for now.
1920 // If we are going to use vertical buttons, we should
1921 // put the sizer to the right of other controls in the dialog,
1922 // and that's beyond the scope of this sizer.
1924 bool is_pda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
1925 // If we have a PDA screen, put yes/no button over
1926 // all other buttons, otherwise on the left side.
1928 m_orient
= wxVERTICAL
;
1931 m_buttonAffirmative
= NULL
;
1932 m_buttonApply
= NULL
;
1933 m_buttonNegative
= NULL
;
1934 m_buttonCancel
= NULL
;
1935 m_buttonHelp
= NULL
;
1938 void wxStdDialogButtonSizer::AddButton(wxButton
*mybutton
)
1940 switch (mybutton
->GetId())
1945 m_buttonAffirmative
= mybutton
;
1948 m_buttonApply
= mybutton
;
1951 m_buttonNegative
= mybutton
;
1954 m_buttonCancel
= mybutton
;
1957 case wxID_CONTEXT_HELP
:
1958 m_buttonHelp
= mybutton
;
1965 void wxStdDialogButtonSizer::SetAffirmativeButton( wxButton
*button
)
1967 m_buttonAffirmative
= button
;
1970 void wxStdDialogButtonSizer::SetNegativeButton( wxButton
*button
)
1972 m_buttonNegative
= button
;
1975 void wxStdDialogButtonSizer::SetCancelButton( wxButton
*button
)
1977 m_buttonCancel
= button
;
1980 void wxStdDialogButtonSizer::Realize()
1983 Add(0, 0, 0, wxLEFT
, 6);
1985 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 6);
1987 if (m_buttonNegative
){
1988 // HIG POLICE BULLETIN - destructive buttons need extra padding
1989 // 24 pixels on either side
1990 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 12);
1993 // extra whitespace between help/negative and cancel/ok buttons
1994 Add(0, 0, 1, wxEXPAND
, 0);
1996 if (m_buttonCancel
){
1997 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 6);
1998 // Cancel or help should be default
1999 // m_buttonCancel->SetDefaultButton();
2002 // Ugh, Mac doesn't really have apply dialogs, so I'll just
2003 // figure the best place is between Cancel and OK
2005 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 6);
2007 if (m_buttonAffirmative
){
2008 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
, 6);
2010 if (m_buttonAffirmative
->GetId() == wxID_SAVE
){
2011 // these buttons have set labels under Mac so we should use them
2012 m_buttonAffirmative
->SetLabel(_("Save"));
2013 m_buttonNegative
->SetLabel(_("Don't Save"));
2017 // Extra space around and at the right
2019 #elif defined(__WXGTK20__)
2020 Add(0, 0, 0, wxLEFT
, 9);
2022 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
2024 // extra whitespace between help and cancel/ok buttons
2025 Add(0, 0, 1, wxEXPAND
, 0);
2027 if (m_buttonNegative
){
2028 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
2031 if (m_buttonCancel
){
2032 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
2033 // Cancel or help should be default
2034 // m_buttonCancel->SetDefaultButton();
2038 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
2040 if (m_buttonAffirmative
)
2041 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
, 6);
2042 #elif defined(__WXMSW__)
2045 // right-justify buttons
2046 Add(0, 0, 1, wxEXPAND
, 0);
2048 if (m_buttonAffirmative
){
2049 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonAffirmative
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2052 if (m_buttonNegative
){
2053 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonNegative
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2056 if (m_buttonCancel
){
2057 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonCancel
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2060 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonApply
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2063 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonHelp
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2065 // GTK+1 and any other platform
2067 // Add(0, 0, 0, wxLEFT, 5); // Not sure what this was for but it unbalances the dialog
2069 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonHelp
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2071 // extra whitespace between help and cancel/ok buttons
2072 Add(0, 0, 1, wxEXPAND
, 0);
2075 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonApply
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2077 if (m_buttonAffirmative
){
2078 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonAffirmative
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2081 if (m_buttonNegative
){
2082 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonNegative
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2085 if (m_buttonCancel
){
2086 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonCancel
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2087 // Cancel or help should be default
2088 // m_buttonCancel->SetDefaultButton();
2094 #endif // wxUSE_BUTTON
2096 #if WXWIN_COMPATIBILITY_2_4
2098 // ----------------------------------------------------------------------------
2100 // ----------------------------------------------------------------------------
2103 IMPLEMENT_CLASS(wxBookCtrlSizer
, wxSizer
)
2105 IMPLEMENT_CLASS(wxNotebookSizer
, wxBookCtrlSizer
)
2106 #endif // wxUSE_NOTEBOOK
2107 #endif // wxUSE_BOOKCTRL
2111 #if WXWIN_COMPATIBILITY_2_6
2113 wxBookCtrlSizer::wxBookCtrlSizer(wxBookCtrlBase
*bookctrl
)
2114 : m_bookctrl(bookctrl
)
2116 wxASSERT_MSG( bookctrl
, wxT("wxBookCtrlSizer needs a control") );
2119 #endif // WXWIN_COMPATIBILITY_2_6
2121 void wxBookCtrlSizer::RecalcSizes()
2123 m_bookctrl
->SetSize( m_position
.x
, m_position
.y
, m_size
.x
, m_size
.y
);
2126 wxSize
wxBookCtrlSizer::CalcMin()
2128 wxSize sizeBorder
= m_bookctrl
->CalcSizeFromPage(wxSize(0,0));
2133 if ( m_bookctrl
->GetPageCount() == 0 )
2135 return wxSize(sizeBorder
.x
+ 10, sizeBorder
.y
+ 10);
2141 wxWindowList::compatibility_iterator
2142 node
= m_bookctrl
->GetChildren().GetFirst();
2145 wxWindow
*item
= node
->GetData();
2146 wxSizer
*itemsizer
= item
->GetSizer();
2150 wxSize
subsize( itemsizer
->CalcMin() );
2152 if (subsize
.x
> maxX
)
2154 if (subsize
.y
> maxY
)
2158 node
= node
->GetNext();
2161 return wxSize( maxX
, maxY
) + sizeBorder
;
2166 #if WXWIN_COMPATIBILITY_2_6
2168 wxNotebookSizer::wxNotebookSizer(wxNotebook
*nb
)
2170 wxASSERT_MSG( nb
, wxT("wxNotebookSizer needs a control") );
2174 #endif // WXWIN_COMPATIBILITY_2_6
2176 #endif // wxUSE_NOTEBOOOK
2177 #endif // wxUSE_BOOKCTRL
2179 #endif // WXWIN_COMPATIBILITY_2_4