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 #if WXWIN_COMPATIBILITY_2_6
510 bool wxSizer::Remove( wxWindow
*window
)
512 return Detach( window
);
514 #endif // WXWIN_COMPATIBILITY_2_6
516 bool wxSizer::Remove( wxSizer
*sizer
)
518 wxASSERT_MSG( sizer
, _T("Removing NULL sizer") );
520 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
523 wxSizerItem
*item
= node
->GetData();
525 if (item
->GetSizer() == sizer
)
528 m_children
.Erase( node
);
532 node
= node
->GetNext();
538 bool wxSizer::Remove( int index
)
540 wxCHECK_MSG( index
>= 0 && (size_t)index
< m_children
.GetCount(),
542 _T("Remove index is out of range") );
544 wxSizerItemList::compatibility_iterator node
= m_children
.Item( index
);
546 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
548 wxSizerItem
*item
= node
->GetData();
550 if ( item
->IsWindow() )
551 item
->GetWindow()->SetContainingSizer( NULL
);
554 m_children
.Erase( node
);
558 bool wxSizer::Detach( wxSizer
*sizer
)
560 wxASSERT_MSG( sizer
, _T("Detaching NULL sizer") );
562 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
565 wxSizerItem
*item
= node
->GetData();
567 if (item
->GetSizer() == sizer
)
571 m_children
.Erase( node
);
574 node
= node
->GetNext();
580 bool wxSizer::Detach( wxWindow
*window
)
582 wxASSERT_MSG( window
, _T("Detaching NULL window") );
584 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
587 wxSizerItem
*item
= node
->GetData();
589 if (item
->GetWindow() == window
)
591 item
->GetWindow()->SetContainingSizer( NULL
);
593 m_children
.Erase( node
);
596 node
= node
->GetNext();
602 bool wxSizer::Detach( int index
)
604 wxCHECK_MSG( index
>= 0 && (size_t)index
< m_children
.GetCount(),
606 _T("Detach index is out of range") );
608 wxSizerItemList::compatibility_iterator node
= m_children
.Item( index
);
610 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
612 wxSizerItem
*item
= node
->GetData();
614 if ( item
->IsSizer() )
616 else if ( item
->IsWindow() )
617 item
->GetWindow()->SetContainingSizer( NULL
);
620 m_children
.Erase( node
);
624 bool wxSizer::Replace( wxWindow
*oldwin
, wxWindow
*newwin
, bool recursive
)
626 wxASSERT_MSG( oldwin
, _T("Replacing NULL window") );
627 wxASSERT_MSG( newwin
, _T("Replacing with NULL window") );
629 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
632 wxSizerItem
*item
= node
->GetData();
634 if (item
->GetWindow() == oldwin
)
636 item
->GetWindow()->SetContainingSizer( NULL
);
637 item
->SetWindow(newwin
);
638 newwin
->SetContainingSizer( this );
641 else if (recursive
&& item
->IsSizer())
643 if (item
->GetSizer()->Replace( oldwin
, newwin
, true ))
647 node
= node
->GetNext();
653 bool wxSizer::Replace( wxSizer
*oldsz
, wxSizer
*newsz
, bool recursive
)
655 wxASSERT_MSG( oldsz
, _T("Replacing NULL sizer") );
656 wxASSERT_MSG( newsz
, _T("Replacing with NULL sizer") );
658 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
661 wxSizerItem
*item
= node
->GetData();
663 if (item
->GetSizer() == oldsz
)
665 wxSizer
*old
= item
->GetSizer();
666 item
->SetSizer(newsz
);
670 else if (recursive
&& item
->IsSizer())
672 if (item
->GetSizer()->Replace( oldsz
, newsz
, true ))
676 node
= node
->GetNext();
682 bool wxSizer::Replace( size_t old
, wxSizerItem
*newitem
)
684 wxCHECK_MSG( old
< m_children
.GetCount(), false, _T("Replace index is out of range") );
685 wxASSERT_MSG( newitem
, _T("Replacing with NULL item") );
687 wxSizerItemList::compatibility_iterator node
= m_children
.Item( old
);
689 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
691 wxSizerItem
*item
= node
->GetData();
692 node
->SetData(newitem
);
698 void wxSizer::Clear( bool delete_windows
)
700 // First clear the ContainingSizer pointers
701 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
704 wxSizerItem
*item
= node
->GetData();
706 if (item
->IsWindow())
707 item
->GetWindow()->SetContainingSizer( NULL
);
708 node
= node
->GetNext();
711 // Destroy the windows if needed
715 // Now empty the list
716 WX_CLEAR_LIST(wxSizerItemList
, m_children
);
719 void wxSizer::DeleteWindows()
721 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
724 wxSizerItem
*item
= node
->GetData();
726 item
->DeleteWindows();
727 node
= node
->GetNext();
731 wxSize
wxSizer::Fit( wxWindow
*window
)
733 wxSize
size(window
->IsTopLevel() ? FitSize(window
)
734 : GetMinWindowSize(window
));
736 window
->SetSize( size
);
741 void wxSizer::FitInside( wxWindow
*window
)
744 if (window
->IsTopLevel())
745 size
= VirtualFitSize( window
);
747 size
= GetMinClientSize( window
);
749 window
->SetVirtualSize( size
);
752 void wxSizer::Layout()
754 // (re)calculates minimums needed for each item and other preparations
758 // Applies the layout and repositions/resizes the items
762 void wxSizer::SetSizeHints( wxWindow
*window
)
764 // Preserve the window's max size hints, but set the
765 // lower bound according to the sizer calculations.
767 wxSize size
= Fit( window
);
769 window
->SetSizeHints( size
.x
,
771 window
->GetMaxWidth(),
772 window
->GetMaxHeight() );
775 void wxSizer::SetVirtualSizeHints( wxWindow
*window
)
777 // Preserve the window's max size hints, but set the
778 // lower bound according to the sizer calculations.
781 wxSize
size( window
->GetVirtualSize() );
782 window
->SetVirtualSizeHints( size
.x
,
784 window
->GetMaxWidth(),
785 window
->GetMaxHeight() );
788 wxSize
wxSizer::GetMaxWindowSize( wxWindow
*window
) const
790 return window
->GetMaxSize();
793 wxSize
wxSizer::GetMinWindowSize( wxWindow
*window
)
795 wxSize
minSize( GetMinSize() );
796 wxSize
size( window
->GetSize() );
797 wxSize
client_size( window
->GetClientSize() );
799 return wxSize( minSize
.x
+size
.x
-client_size
.x
,
800 minSize
.y
+size
.y
-client_size
.y
);
803 // TODO on mac we need a function that determines how much free space this
804 // min size contains, in order to make sure that we have 20 pixels of free
805 // space around the controls
807 // Return a window size that will fit within the screens dimensions
808 wxSize
wxSizer::FitSize( wxWindow
*window
)
810 if ( window
->IsTopLevel() )
812 wxTopLevelWindow
*tlw
= wxDynamicCast(window
, wxTopLevelWindow
);
813 if ( tlw
&& tlw
->IsAlwaysMaximized() )
815 return tlw
->GetClientSize();
819 wxSize size
= GetMinWindowSize( window
);
820 wxSize sizeMax
= GetMaxWindowSize( window
);
822 // Limit the size if sizeMax != wxDefaultSize
824 if ( size
.x
> sizeMax
.x
&& sizeMax
.x
!= wxDefaultCoord
)
826 if ( size
.y
> sizeMax
.y
&& sizeMax
.y
!= wxDefaultCoord
)
832 wxSize
wxSizer::GetMaxClientSize( wxWindow
*window
) const
834 wxSize
maxSize( window
->GetMaxSize() );
836 if ( maxSize
!= wxDefaultSize
)
838 wxSize
size( window
->GetSize() );
839 wxSize
client_size( window
->GetClientSize() );
841 return wxSize( maxSize
.x
+ client_size
.x
- size
.x
,
842 maxSize
.y
+ client_size
.y
- size
.y
);
845 return wxDefaultSize
;
848 wxSize
wxSizer::GetMinClientSize( wxWindow
*WXUNUSED(window
) )
850 return GetMinSize(); // Already returns client size.
853 wxSize
wxSizer::VirtualFitSize( wxWindow
*window
)
855 wxSize size
= GetMinClientSize( window
);
856 wxSize sizeMax
= GetMaxClientSize( window
);
858 // Limit the size if sizeMax != wxDefaultSize
860 if ( size
.x
> sizeMax
.x
&& sizeMax
.x
!= wxDefaultCoord
)
862 if ( size
.y
> sizeMax
.y
&& sizeMax
.y
!= wxDefaultCoord
)
868 void wxSizer::SetDimension( int x
, int y
, int width
, int height
)
877 wxSize
wxSizer::GetMinSize()
879 wxSize
ret( CalcMin() );
880 if (ret
.x
< m_minSize
.x
) ret
.x
= m_minSize
.x
;
881 if (ret
.y
< m_minSize
.y
) ret
.y
= m_minSize
.y
;
885 void wxSizer::DoSetMinSize( int width
, int height
)
888 m_minSize
.y
= height
;
891 bool wxSizer::DoSetItemMinSize( wxWindow
*window
, int width
, int height
)
893 wxASSERT_MSG( window
, _T("SetMinSize for NULL window") );
895 // Is it our immediate child?
897 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
900 wxSizerItem
*item
= node
->GetData();
902 if (item
->GetWindow() == window
)
904 item
->SetMinSize( width
, height
);
907 node
= node
->GetNext();
910 // No? Search any subsizers we own then
912 node
= m_children
.GetFirst();
915 wxSizerItem
*item
= node
->GetData();
917 if ( item
->GetSizer() &&
918 item
->GetSizer()->DoSetItemMinSize( window
, width
, height
) )
920 // A child sizer found the requested windw, exit.
923 node
= node
->GetNext();
929 bool wxSizer::DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
)
931 wxASSERT_MSG( sizer
, _T("SetMinSize for NULL sizer") );
933 // Is it our immediate child?
935 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
938 wxSizerItem
*item
= node
->GetData();
940 if (item
->GetSizer() == sizer
)
942 item
->GetSizer()->DoSetMinSize( width
, height
);
945 node
= node
->GetNext();
948 // No? Search any subsizers we own then
950 node
= m_children
.GetFirst();
953 wxSizerItem
*item
= node
->GetData();
955 if ( item
->GetSizer() &&
956 item
->GetSizer()->DoSetItemMinSize( sizer
, width
, height
) )
958 // A child found the requested sizer, exit.
961 node
= node
->GetNext();
967 bool wxSizer::DoSetItemMinSize( size_t index
, int width
, int height
)
969 wxSizerItemList::compatibility_iterator node
= m_children
.Item( index
);
971 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
973 wxSizerItem
*item
= node
->GetData();
975 if (item
->GetSizer())
977 // Sizers contains the minimal size in them, if not calculated ...
978 item
->GetSizer()->DoSetMinSize( width
, height
);
982 // ... but the minimal size of spacers and windows is stored via the item
983 item
->SetMinSize( width
, height
);
989 wxSizerItem
* wxSizer::GetItem( wxWindow
*window
, bool recursive
)
991 wxASSERT_MSG( window
, _T("GetItem for NULL window") );
993 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
996 wxSizerItem
*item
= node
->GetData();
998 if (item
->GetWindow() == window
)
1002 else if (recursive
&& item
->IsSizer())
1004 wxSizerItem
*subitem
= item
->GetSizer()->GetItem( window
, true );
1009 node
= node
->GetNext();
1015 wxSizerItem
* wxSizer::GetItem( wxSizer
*sizer
, bool recursive
)
1017 wxASSERT_MSG( sizer
, _T("GetItem for NULL sizer") );
1019 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1022 wxSizerItem
*item
= node
->GetData();
1024 if (item
->GetSizer() == sizer
)
1028 else if (recursive
&& item
->IsSizer())
1030 wxSizerItem
*subitem
= item
->GetSizer()->GetItem( sizer
, true );
1035 node
= node
->GetNext();
1041 wxSizerItem
* wxSizer::GetItem( size_t index
)
1043 wxCHECK_MSG( index
< m_children
.GetCount(),
1045 _T("GetItem index is out of range") );
1047 return m_children
.Item( index
)->GetData();
1050 bool wxSizer::Show( wxWindow
*window
, bool show
, bool recursive
)
1052 wxSizerItem
*item
= GetItem( window
, recursive
);
1063 bool wxSizer::Show( wxSizer
*sizer
, bool show
, bool recursive
)
1065 wxSizerItem
*item
= GetItem( sizer
, recursive
);
1076 bool wxSizer::Show( size_t index
, bool show
)
1078 wxSizerItem
*item
= GetItem( index
);
1089 void wxSizer::ShowItems( bool show
)
1091 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1094 node
->GetData()->Show( show
);
1095 node
= node
->GetNext();
1099 bool wxSizer::IsShown( wxWindow
*window
) const
1101 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1104 wxSizerItem
*item
= node
->GetData();
1106 if (item
->GetWindow() == window
)
1108 return item
->IsShown();
1110 node
= node
->GetNext();
1113 wxFAIL_MSG( _T("IsShown failed to find sizer item") );
1118 bool wxSizer::IsShown( wxSizer
*sizer
) const
1120 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1123 wxSizerItem
*item
= node
->GetData();
1125 if (item
->GetSizer() == sizer
)
1127 return item
->IsShown();
1129 node
= node
->GetNext();
1132 wxFAIL_MSG( _T("IsShown failed to find sizer item") );
1137 bool wxSizer::IsShown( size_t index
) const
1139 wxCHECK_MSG( index
< m_children
.GetCount(),
1141 _T("IsShown index is out of range") );
1143 return m_children
.Item( index
)->GetData()->IsShown();
1147 //---------------------------------------------------------------------------
1149 //---------------------------------------------------------------------------
1151 wxGridSizer::wxGridSizer( int rows
, int cols
, int vgap
, int hgap
)
1152 : m_rows( ( cols
== 0 && rows
== 0 ) ? 1 : rows
)
1159 wxGridSizer::wxGridSizer( int cols
, int vgap
, int hgap
)
1160 : m_rows( cols
== 0 ? 1 : 0 )
1167 int wxGridSizer::CalcRowsCols(int& nrows
, int& ncols
) const
1169 int nitems
= m_children
.GetCount();
1175 nrows
= (nitems
+ m_cols
- 1) / m_cols
;
1179 ncols
= (nitems
+ m_rows
- 1) / m_rows
;
1182 else // 0 columns, 0 rows?
1184 wxFAIL_MSG( _T("grid sizer must have either rows or columns fixed") );
1193 void wxGridSizer::RecalcSizes()
1195 int nitems
, nrows
, ncols
;
1196 if ( (nitems
= CalcRowsCols(nrows
, ncols
)) == 0 )
1199 wxSize
sz( GetSize() );
1200 wxPoint
pt( GetPosition() );
1202 int w
= (sz
.x
- (ncols
- 1) * m_hgap
) / ncols
;
1203 int h
= (sz
.y
- (nrows
- 1) * m_vgap
) / nrows
;
1206 for (int c
= 0; c
< ncols
; c
++)
1209 for (int r
= 0; r
< nrows
; r
++)
1211 int i
= r
* ncols
+ c
;
1214 wxSizerItemList::compatibility_iterator node
= m_children
.Item( i
);
1216 wxASSERT_MSG( node
, _T("Failed to find SizerItemList node") );
1218 SetItemBounds( node
->GetData(), x
, y
, w
, h
);
1226 wxSize
wxGridSizer::CalcMin()
1229 if ( CalcRowsCols(nrows
, ncols
) == 0 )
1232 // Find the max width and height for any component
1236 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1239 wxSizerItem
*item
= node
->GetData();
1240 wxSize
sz( item
->CalcMin() );
1242 w
= wxMax( w
, sz
.x
);
1243 h
= wxMax( h
, sz
.y
);
1245 node
= node
->GetNext();
1248 return wxSize( ncols
* w
+ (ncols
-1) * m_hgap
,
1249 nrows
* h
+ (nrows
-1) * m_vgap
);
1252 void wxGridSizer::SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
)
1255 wxSize
sz( item
->GetMinSizeWithBorder() );
1256 int flag
= item
->GetFlag();
1258 if ((flag
& wxEXPAND
) || (flag
& wxSHAPED
))
1264 if (flag
& wxALIGN_CENTER_HORIZONTAL
)
1266 pt
.x
= x
+ (w
- sz
.x
) / 2;
1268 else if (flag
& wxALIGN_RIGHT
)
1270 pt
.x
= x
+ (w
- sz
.x
);
1273 if (flag
& wxALIGN_CENTER_VERTICAL
)
1275 pt
.y
= y
+ (h
- sz
.y
) / 2;
1277 else if (flag
& wxALIGN_BOTTOM
)
1279 pt
.y
= y
+ (h
- sz
.y
);
1283 item
->SetDimension(pt
, sz
);
1286 //---------------------------------------------------------------------------
1288 //---------------------------------------------------------------------------
1290 wxFlexGridSizer::wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
)
1291 : wxGridSizer( rows
, cols
, vgap
, hgap
),
1292 m_flexDirection(wxBOTH
),
1293 m_growMode(wxFLEX_GROWMODE_SPECIFIED
)
1297 wxFlexGridSizer::wxFlexGridSizer( int cols
, int vgap
, int hgap
)
1298 : wxGridSizer( cols
, vgap
, hgap
),
1299 m_flexDirection(wxBOTH
),
1300 m_growMode(wxFLEX_GROWMODE_SPECIFIED
)
1304 wxFlexGridSizer::~wxFlexGridSizer()
1308 void wxFlexGridSizer::RecalcSizes()
1310 int nitems
, nrows
, ncols
;
1311 if ( (nitems
= CalcRowsCols(nrows
, ncols
)) == 0 )
1314 wxPoint
pt( GetPosition() );
1315 wxSize
sz( GetSize() );
1317 AdjustForGrowables(sz
, m_calculatedMinSize
, nrows
, ncols
);
1319 sz
= wxSize( pt
.x
+ sz
.x
, pt
.y
+ sz
.y
);
1322 for (int c
= 0; c
< ncols
; c
++)
1325 for (int r
= 0; r
< nrows
; r
++)
1327 int i
= r
* ncols
+ c
;
1330 wxSizerItemList::compatibility_iterator node
= m_children
.Item( i
);
1332 wxASSERT_MSG( node
, _T("Failed to find node") );
1334 int w
= wxMax( 0, wxMin( m_colWidths
[c
], sz
.x
- x
) );
1335 int h
= wxMax( 0, wxMin( m_rowHeights
[r
], sz
.y
- y
) );
1337 SetItemBounds( node
->GetData(), x
, y
, w
, h
);
1339 if (m_rowHeights
[r
] != -1)
1340 y
= y
+ m_rowHeights
[r
] + m_vgap
;
1342 if (m_colWidths
[c
] != -1)
1343 x
= x
+ m_colWidths
[c
] + m_hgap
;
1347 wxSize
wxFlexGridSizer::CalcMin()
1353 // Number of rows/columns can change as items are added or removed.
1354 if ( !CalcRowsCols(nrows
, ncols
) )
1357 m_rowHeights
.SetCount(nrows
);
1358 m_colWidths
.SetCount(ncols
);
1360 // We have to recalcuate the sizes in case the item minimum size has
1361 // changed since the previous layout, or the item has been hidden using
1362 // wxSizer::Show(). If all the items in a row/column are hidden, the final
1363 // dimension of the row/column will be -1, indicating that the column
1364 // itself is hidden.
1365 for( s
= m_rowHeights
.GetCount(), i
= 0; i
< s
; ++i
)
1366 m_rowHeights
[ i
] = -1;
1367 for( s
= m_colWidths
.GetCount(), i
= 0; i
< s
; ++i
)
1368 m_colWidths
[ i
] = -1;
1370 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1375 wxSizerItem
*item
= node
->GetData();
1376 if ( item
->IsShown() )
1378 wxSize
sz( item
->CalcMin() );
1379 int row
= i
/ ncols
;
1380 int col
= i
% ncols
;
1382 m_rowHeights
[ row
] = wxMax( wxMax( 0, sz
.y
), m_rowHeights
[ row
] );
1383 m_colWidths
[ col
] = wxMax( wxMax( 0, sz
.x
), m_colWidths
[ col
] );
1386 node
= node
->GetNext();
1390 AdjustForFlexDirection();
1392 // Sum total minimum size, including gaps between rows/columns.
1393 // -1 is used as a magic number meaning empty column.
1395 for (int col
= 0; col
< ncols
; col
++)
1396 if ( m_colWidths
[ col
] != -1 )
1397 width
+= m_colWidths
[ col
] + m_hgap
;
1402 for (int row
= 0; row
< nrows
; row
++)
1403 if ( m_rowHeights
[ row
] != -1 )
1404 height
+= m_rowHeights
[ row
] + m_vgap
;
1408 m_calculatedMinSize
= wxSize( width
, height
);
1409 return m_calculatedMinSize
;
1412 void wxFlexGridSizer::AdjustForFlexDirection()
1414 // the logic in CalcMin works when we resize flexibly in both directions
1415 // but maybe this is not the case
1416 if ( m_flexDirection
!= wxBOTH
)
1418 // select the array corresponding to the direction in which we do *not*
1420 wxArrayInt
& array
= m_flexDirection
== wxVERTICAL
? m_colWidths
1423 const size_t count
= array
.GetCount();
1425 // find the largest value in this array
1429 for ( n
= 0; n
< count
; ++n
)
1431 if ( array
[n
] > largest
)
1435 // and now fill it with the largest value
1436 for ( n
= 0; n
< count
; ++n
)
1444 void wxFlexGridSizer::AdjustForGrowables(const wxSize
& sz
, const wxSize
& minsz
,
1445 int nrows
, int ncols
)
1447 // what to do with the rows? by default, resize them proportionally
1448 if ( sz
.y
> minsz
.y
&& ( (m_flexDirection
& wxVERTICAL
) || (m_growMode
== wxFLEX_GROWMODE_SPECIFIED
) ) )
1450 int sum_proportions
= 0;
1451 int growable_space
= 0;
1454 for (idx
= 0; idx
< m_growableRows
.GetCount(); idx
++)
1456 // Since the number of rows/columns can change as items are
1457 // inserted/deleted, we need to verify at runtime that the
1458 // requested growable rows/columns are still valid.
1459 if (m_growableRows
[idx
] >= nrows
)
1462 // If all items in a row/column are hidden, that row/column will
1463 // have a dimension of -1. This causes the row/column to be
1464 // hidden completely.
1465 if (m_rowHeights
[ m_growableRows
[idx
] ] == -1)
1467 sum_proportions
+= m_growableRowsProportions
[idx
];
1468 growable_space
+= m_rowHeights
[ m_growableRows
[idx
] ];
1474 for (idx
= 0; idx
< m_growableRows
.GetCount(); idx
++)
1476 if (m_growableRows
[idx
] >= nrows
)
1478 if (m_rowHeights
[ m_growableRows
[idx
] ] == -1)
1479 m_rowHeights
[ m_growableRows
[idx
] ] = 0;
1482 int delta
= (sz
.y
- minsz
.y
);
1483 if (sum_proportions
== 0)
1484 delta
= (delta
/num
) + m_rowHeights
[ m_growableRows
[idx
] ];
1486 delta
= ((delta
+growable_space
)*m_growableRowsProportions
[idx
]) / sum_proportions
;
1487 m_rowHeights
[ m_growableRows
[idx
] ] = delta
;
1492 else if ( (m_growMode
== wxFLEX_GROWMODE_ALL
) && (sz
.y
> minsz
.y
) )
1494 // rounding problem?
1495 for ( int row
= 0; row
< nrows
; ++row
)
1496 m_rowHeights
[ row
] = sz
.y
/ nrows
;
1499 // the same logic as above but for the columns
1500 if ( sz
.x
> minsz
.x
&& ( (m_flexDirection
& wxHORIZONTAL
) || (m_growMode
== wxFLEX_GROWMODE_SPECIFIED
) ) )
1502 int sum_proportions
= 0;
1503 int growable_space
= 0;
1506 for (idx
= 0; idx
< m_growableCols
.GetCount(); idx
++)
1508 // Since the number of rows/columns can change as items are
1509 // inserted/deleted, we need to verify at runtime that the
1510 // requested growable rows/columns are still valid.
1511 if (m_growableCols
[idx
] >= ncols
)
1514 // If all items in a row/column are hidden, that row/column will
1515 // have a dimension of -1. This causes the column to be hidden
1517 if (m_colWidths
[ m_growableCols
[idx
] ] == -1)
1519 sum_proportions
+= m_growableColsProportions
[idx
];
1520 growable_space
+= m_colWidths
[ m_growableCols
[idx
] ];
1526 for (idx
= 0; idx
< m_growableCols
.GetCount(); idx
++)
1528 if (m_growableCols
[idx
] >= ncols
)
1530 if (m_colWidths
[ m_growableCols
[idx
] ] == -1)
1531 m_colWidths
[ m_growableCols
[idx
] ] = 0;
1534 int delta
= (sz
.x
- minsz
.x
);
1535 if (sum_proportions
== 0)
1536 delta
= (delta
/num
) + m_colWidths
[ m_growableCols
[idx
] ];
1538 delta
= ((delta
+growable_space
)*m_growableColsProportions
[idx
])/sum_proportions
;
1539 m_colWidths
[ m_growableCols
[idx
] ] = delta
;
1544 else if ( (m_growMode
== wxFLEX_GROWMODE_ALL
) && (sz
.x
> minsz
.x
) )
1546 for ( int col
=0; col
< ncols
; ++col
)
1547 m_colWidths
[ col
] = sz
.x
/ ncols
;
1552 void wxFlexGridSizer::AddGrowableRow( size_t idx
, int proportion
)
1554 m_growableRows
.Add( idx
);
1555 m_growableRowsProportions
.Add( proportion
);
1558 void wxFlexGridSizer::AddGrowableCol( size_t idx
, int proportion
)
1560 m_growableCols
.Add( idx
);
1561 m_growableColsProportions
.Add( proportion
);
1564 // helper function for RemoveGrowableCol/Row()
1566 DoRemoveFromArrays(size_t idx
, wxArrayInt
& items
, wxArrayInt
& proportions
)
1568 const size_t count
= items
.size();
1569 for ( size_t n
= 0; n
< count
; n
++ )
1571 if ( (size_t)items
[n
] == idx
)
1574 proportions
.RemoveAt(n
);
1579 wxFAIL_MSG( _T("column/row is already not growable") );
1582 void wxFlexGridSizer::RemoveGrowableCol( size_t idx
)
1584 DoRemoveFromArrays(idx
, m_growableCols
, m_growableColsProportions
);
1587 void wxFlexGridSizer::RemoveGrowableRow( size_t idx
)
1589 DoRemoveFromArrays(idx
, m_growableRows
, m_growableRowsProportions
);
1592 //---------------------------------------------------------------------------
1594 //---------------------------------------------------------------------------
1596 wxBoxSizer::wxBoxSizer( int orient
)
1597 : m_orient( orient
)
1601 void wxBoxSizer::RecalcSizes()
1603 if (m_children
.GetCount() == 0)
1609 if (m_orient
== wxHORIZONTAL
)
1610 delta
= m_size
.x
- m_fixedWidth
;
1612 delta
= m_size
.y
- m_fixedHeight
;
1615 wxPoint
pt( m_position
);
1617 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1620 wxSizerItem
*item
= node
->GetData();
1622 if (item
->IsShown())
1624 wxSize
size( item
->GetMinSizeWithBorder() );
1626 if (m_orient
== wxVERTICAL
)
1628 wxCoord height
= size
.y
;
1629 if (item
->GetProportion())
1631 // Because of at least one visible item has non-zero
1632 // proportion then m_stretchable is not zero
1633 height
= (delta
* item
->GetProportion()) / m_stretchable
;
1636 wxPoint
child_pos( pt
);
1637 wxSize
child_size( size
.x
, height
);
1639 if (item
->GetFlag() & (wxEXPAND
| wxSHAPED
))
1640 child_size
.x
= m_size
.x
;
1641 else if (item
->GetFlag() & wxALIGN_RIGHT
)
1642 child_pos
.x
+= m_size
.x
- size
.x
;
1643 else if (item
->GetFlag() & (wxCENTER
| wxALIGN_CENTER_HORIZONTAL
))
1644 // XXX wxCENTER is added for backward compatibility;
1645 // wxALIGN_CENTER should be used in new code
1646 child_pos
.x
+= (m_size
.x
- size
.x
) / 2;
1648 item
->SetDimension( child_pos
, child_size
);
1654 wxCoord width
= size
.x
;
1655 if (item
->GetProportion())
1657 // Because of at least one visible item has non-zero
1658 // proportion then m_stretchable is not zero
1659 width
= (delta
* item
->GetProportion()) / m_stretchable
;
1662 wxPoint
child_pos( pt
);
1663 wxSize
child_size( width
, size
.y
);
1665 if (item
->GetFlag() & (wxEXPAND
| wxSHAPED
))
1666 child_size
.y
= m_size
.y
;
1667 else if (item
->GetFlag() & wxALIGN_BOTTOM
)
1668 child_pos
.y
+= m_size
.y
- size
.y
;
1669 else if (item
->GetFlag() & (wxCENTER
| wxALIGN_CENTER_VERTICAL
))
1670 // XXX wxCENTER is added for backward compatibility;
1671 // wxALIGN_CENTER should be used in new code
1672 child_pos
.y
+= (m_size
.y
- size
.y
) / 2;
1674 item
->SetDimension( child_pos
, child_size
);
1680 node
= node
->GetNext();
1684 wxSize
wxBoxSizer::CalcMin()
1686 if (m_children
.GetCount() == 0)
1695 // precalc item minsizes and count proportions
1696 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1699 wxSizerItem
*item
= node
->GetData();
1701 if ( item
->IsShown() )
1703 item
->CalcMin(); // result is stored in the item
1705 m_stretchable
+= item
->GetProportion();
1708 node
= node
->GetNext();
1711 // Total minimum size (width or height) of sizer
1714 node
= m_children
.GetFirst();
1717 wxSizerItem
*item
= node
->GetData();
1719 if (item
->IsShown() && item
->GetProportion() != 0)
1721 int stretch
= item
->GetProportion();
1722 wxSize
size( item
->GetMinSizeWithBorder() );
1725 // Integer division rounded up is (a + b - 1) / b
1726 // Round up needed in order to guarantee that all
1727 // all items will have size not less then their min size
1728 if (m_orient
== wxHORIZONTAL
)
1729 minSize
= ( size
.x
*m_stretchable
+ stretch
- 1)/stretch
;
1731 minSize
= ( size
.y
*m_stretchable
+ stretch
- 1)/stretch
;
1733 if (minSize
> maxMinSize
)
1734 maxMinSize
= minSize
;
1736 node
= node
->GetNext();
1739 // Calculate overall minimum size
1740 node
= m_children
.GetFirst();
1743 wxSizerItem
*item
= node
->GetData();
1745 if (item
->IsShown())
1747 wxSize
size( item
->GetMinSizeWithBorder() );
1748 if (item
->GetProportion() != 0)
1750 if (m_orient
== wxHORIZONTAL
)
1751 size
.x
= (maxMinSize
*item
->GetProportion())/m_stretchable
;
1753 size
.y
= (maxMinSize
*item
->GetProportion())/m_stretchable
;
1757 if (m_orient
== wxVERTICAL
)
1759 m_fixedHeight
+= size
.y
;
1760 m_fixedWidth
= wxMax( m_fixedWidth
, size
.x
);
1764 m_fixedWidth
+= size
.x
;
1765 m_fixedHeight
= wxMax( m_fixedHeight
, size
.y
);
1769 if (m_orient
== wxHORIZONTAL
)
1771 m_minWidth
+= size
.x
;
1772 m_minHeight
= wxMax( m_minHeight
, size
.y
);
1776 m_minHeight
+= size
.y
;
1777 m_minWidth
= wxMax( m_minWidth
, size
.x
);
1780 node
= node
->GetNext();
1783 return wxSize( m_minWidth
, m_minHeight
);
1786 //---------------------------------------------------------------------------
1788 //---------------------------------------------------------------------------
1792 wxStaticBoxSizer::wxStaticBoxSizer( wxStaticBox
*box
, int orient
)
1793 : wxBoxSizer( orient
),
1796 wxASSERT_MSG( box
, wxT("wxStaticBoxSizer needs a static box") );
1798 // do this so that our Detach() is called if the static box is destroyed
1800 m_staticBox
->SetContainingSizer(this);
1803 wxStaticBoxSizer::wxStaticBoxSizer(int orient
, wxWindow
*win
, const wxString
& s
)
1804 : wxBoxSizer(orient
),
1805 m_staticBox(new wxStaticBox(win
, wxID_ANY
, s
))
1808 m_staticBox
->SetContainingSizer(this);
1811 wxStaticBoxSizer::~wxStaticBoxSizer()
1816 static void GetStaticBoxBorders( wxStaticBox
*box
,
1820 // this has to be done platform by platform as there is no way to
1821 // guess the thickness of a wxStaticBox border
1822 box
->GetBordersForSizer(borderTop
, borderOther
);
1825 void wxStaticBoxSizer::RecalcSizes()
1827 int top_border
, other_border
;
1828 GetStaticBoxBorders(m_staticBox
, &top_border
, &other_border
);
1830 m_staticBox
->SetSize( m_position
.x
, m_position
.y
, m_size
.x
, m_size
.y
);
1832 wxPoint
old_pos( m_position
);
1833 m_position
.x
+= other_border
;
1834 m_position
.y
+= top_border
;
1835 wxSize
old_size( m_size
);
1836 m_size
.x
-= 2*other_border
;
1837 m_size
.y
-= top_border
+ other_border
;
1839 wxBoxSizer::RecalcSizes();
1841 m_position
= old_pos
;
1845 wxSize
wxStaticBoxSizer::CalcMin()
1847 int top_border
, other_border
;
1848 GetStaticBoxBorders(m_staticBox
, &top_border
, &other_border
);
1850 wxSize
ret( wxBoxSizer::CalcMin() );
1851 ret
.x
+= 2*other_border
;
1852 ret
.y
+= other_border
+ top_border
;
1857 void wxStaticBoxSizer::ShowItems( bool show
)
1859 m_staticBox
->Show( show
);
1860 wxBoxSizer::ShowItems( show
);
1863 bool wxStaticBoxSizer::Detach( wxWindow
*window
)
1865 // avoid deleting m_staticBox in our dtor if it's being detached from the
1866 // sizer (which can happen because it's being already destroyed for
1868 if ( window
== m_staticBox
)
1874 return wxSizer::Detach( window
);
1877 #endif // wxUSE_STATBOX
1881 wxStdDialogButtonSizer::wxStdDialogButtonSizer()
1882 : wxBoxSizer(wxHORIZONTAL
)
1884 // Vertical buttons with lots of space on either side
1885 // looks rubbish on WinCE, so let's not do this for now.
1886 // If we are going to use vertical buttons, we should
1887 // put the sizer to the right of other controls in the dialog,
1888 // and that's beyond the scope of this sizer.
1890 bool is_pda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
1891 // If we have a PDA screen, put yes/no button over
1892 // all other buttons, otherwise on the left side.
1894 m_orient
= wxVERTICAL
;
1897 m_buttonAffirmative
= NULL
;
1898 m_buttonApply
= NULL
;
1899 m_buttonNegative
= NULL
;
1900 m_buttonCancel
= NULL
;
1901 m_buttonHelp
= NULL
;
1904 void wxStdDialogButtonSizer::AddButton(wxButton
*mybutton
)
1906 switch (mybutton
->GetId())
1911 m_buttonAffirmative
= mybutton
;
1914 m_buttonApply
= mybutton
;
1917 m_buttonNegative
= mybutton
;
1920 m_buttonCancel
= mybutton
;
1923 case wxID_CONTEXT_HELP
:
1924 m_buttonHelp
= mybutton
;
1931 void wxStdDialogButtonSizer::SetAffirmativeButton( wxButton
*button
)
1933 m_buttonAffirmative
= button
;
1936 void wxStdDialogButtonSizer::SetNegativeButton( wxButton
*button
)
1938 m_buttonNegative
= button
;
1941 void wxStdDialogButtonSizer::SetCancelButton( wxButton
*button
)
1943 m_buttonCancel
= button
;
1946 void wxStdDialogButtonSizer::Realize()
1949 Add(0, 0, 0, wxLEFT
, 6);
1951 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 6);
1953 if (m_buttonNegative
){
1954 // HIG POLICE BULLETIN - destructive buttons need extra padding
1955 // 24 pixels on either side
1956 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 12);
1959 // extra whitespace between help/negative and cancel/ok buttons
1960 Add(0, 0, 1, wxEXPAND
, 0);
1962 if (m_buttonCancel
){
1963 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 6);
1964 // Cancel or help should be default
1965 // m_buttonCancel->SetDefaultButton();
1968 // Ugh, Mac doesn't really have apply dialogs, so I'll just
1969 // figure the best place is between Cancel and OK
1971 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 6);
1973 if (m_buttonAffirmative
){
1974 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
, 6);
1976 if (m_buttonAffirmative
->GetId() == wxID_SAVE
){
1977 // these buttons have set labels under Mac so we should use them
1978 m_buttonAffirmative
->SetLabel(_("Save"));
1979 m_buttonNegative
->SetLabel(_("Don't Save"));
1983 // Extra space around and at the right
1985 #elif defined(__WXGTK20__)
1986 Add(0, 0, 0, wxLEFT
, 9);
1988 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
1990 // extra whitespace between help and cancel/ok buttons
1991 Add(0, 0, 1, wxEXPAND
, 0);
1993 if (m_buttonNegative
){
1994 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
1997 if (m_buttonCancel
){
1998 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
1999 // Cancel or help should be default
2000 // m_buttonCancel->SetDefaultButton();
2004 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
2006 if (m_buttonAffirmative
)
2007 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
, 6);
2008 #elif defined(__WXMSW__)
2011 // right-justify buttons
2012 Add(0, 0, 1, wxEXPAND
, 0);
2014 if (m_buttonAffirmative
){
2015 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonAffirmative
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2018 if (m_buttonNegative
){
2019 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonNegative
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2022 if (m_buttonCancel
){
2023 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonCancel
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2026 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonApply
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2029 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonHelp
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2031 // GTK+1 and any other platform
2033 // Add(0, 0, 0, wxLEFT, 5); // Not sure what this was for but it unbalances the dialog
2035 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonHelp
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2037 // extra whitespace between help and cancel/ok buttons
2038 Add(0, 0, 1, wxEXPAND
, 0);
2041 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonApply
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2043 if (m_buttonAffirmative
){
2044 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonAffirmative
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2047 if (m_buttonNegative
){
2048 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonNegative
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2051 if (m_buttonCancel
){
2052 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonCancel
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2053 // Cancel or help should be default
2054 // m_buttonCancel->SetDefaultButton();
2060 #endif // wxUSE_BUTTON
2062 #if WXWIN_COMPATIBILITY_2_4
2064 // ----------------------------------------------------------------------------
2066 // ----------------------------------------------------------------------------
2069 IMPLEMENT_CLASS(wxBookCtrlSizer
, wxSizer
)
2071 IMPLEMENT_CLASS(wxNotebookSizer
, wxBookCtrlSizer
)
2072 #endif // wxUSE_NOTEBOOK
2073 #endif // wxUSE_BOOKCTRL
2077 #if WXWIN_COMPATIBILITY_2_6
2079 wxBookCtrlSizer::wxBookCtrlSizer(wxBookCtrlBase
*bookctrl
)
2080 : m_bookctrl(bookctrl
)
2082 wxASSERT_MSG( bookctrl
, wxT("wxBookCtrlSizer needs a control") );
2085 #endif // WXWIN_COMPATIBILITY_2_6
2087 void wxBookCtrlSizer::RecalcSizes()
2089 m_bookctrl
->SetSize( m_position
.x
, m_position
.y
, m_size
.x
, m_size
.y
);
2092 wxSize
wxBookCtrlSizer::CalcMin()
2094 wxSize sizeBorder
= m_bookctrl
->CalcSizeFromPage(wxSize(0,0));
2099 if ( m_bookctrl
->GetPageCount() == 0 )
2101 return wxSize(sizeBorder
.x
+ 10, sizeBorder
.y
+ 10);
2107 wxWindowList::compatibility_iterator
2108 node
= m_bookctrl
->GetChildren().GetFirst();
2111 wxWindow
*item
= node
->GetData();
2112 wxSizer
*itemsizer
= item
->GetSizer();
2116 wxSize
subsize( itemsizer
->CalcMin() );
2118 if (subsize
.x
> maxX
)
2120 if (subsize
.y
> maxY
)
2124 node
= node
->GetNext();
2127 return wxSize( maxX
, maxY
) + sizeBorder
;
2132 #if WXWIN_COMPATIBILITY_2_6
2134 wxNotebookSizer::wxNotebookSizer(wxNotebook
*nb
)
2136 wxASSERT_MSG( nb
, wxT("wxNotebookSizer needs a control") );
2140 #endif // WXWIN_COMPATIBILITY_2_6
2142 #endif // wxUSE_NOTEBOOOK
2143 #endif // wxUSE_BOOKCTRL
2145 #endif // WXWIN_COMPATIBILITY_2_4