1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/sizer.cpp
3 // Purpose: provide new wxSizer class for layout
4 // Author: Robert Roebling and Robin Dunn, contributions by
5 // Dirk Holtwick, Ron Lee
6 // Modified by: Ron Lee
9 // Copyright: (c) Robin Dunn, Robert Roebling
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
13 // For compilers that support precompilation, includes "wx.h".
14 #include "wx/wxprec.h"
20 #include "wx/display.h"
24 #include "wx/string.h"
28 #include "wx/settings.h"
29 #include "wx/button.h"
30 #include "wx/statbox.h"
31 #include "wx/toplevel.h"
34 #include "wx/listimpl.cpp"
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
->GetEffectiveMinSize();
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
)
360 m_rect
= wxRect(pos
, size
);
365 wxFAIL_MSG( _T("can't set size of uninitialized sizer item") );
369 m_window
->SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
,
370 wxSIZE_ALLOW_MINUS_ONE
);
374 m_sizer
->SetDimension(pos
.x
, pos
.y
, size
.x
, size
.y
);
378 m_spacer
->SetSize(size
);
383 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
387 void wxSizerItem::DeleteWindows()
396 //We are deleting the window from this sizer - normally
397 //the window destroys the sizer associated with it,
398 //which might destroy this, which we don't want
399 m_window
->SetContainingSizer(NULL
);
401 //Putting this after the switch will result in a spacer
402 //not being deleted properly on destruction
407 m_sizer
->DeleteWindows();
412 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
417 void wxSizerItem::Show( bool show
)
422 wxFAIL_MSG( _T("can't show uninitialized sizer item") );
426 m_window
->Show(show
);
434 m_spacer
->Show(show
);
439 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
443 bool wxSizerItem::IsShown() const
448 // we may be called from CalcMin(), just return false so that we're
453 return m_window
->IsShown();
456 // arbitrarily decide that if at least one of our elements is
457 // shown, so are we (this arbitrariness is the reason for
458 // deprecating this function)
460 // Some apps (such as dialog editors) depend on an empty sizer still
461 // being laid out correctly and reporting the correct size and position.
462 if (m_sizer
->GetChildren().GetCount() == 0)
465 for ( wxSizerItemList::compatibility_iterator
466 node
= m_sizer
->GetChildren().GetFirst();
468 node
= node
->GetNext() )
470 if ( node
->GetData()->IsShown() )
477 return m_spacer
->IsShown();
481 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
487 #if WXWIN_COMPATIBILITY_2_6
488 void wxSizerItem::SetOption( int option
)
490 SetProportion( option
);
493 int wxSizerItem::GetOption() const
495 return GetProportion();
497 #endif // WXWIN_COMPATIBILITY_2_6
500 //---------------------------------------------------------------------------
502 //---------------------------------------------------------------------------
506 WX_CLEAR_LIST(wxSizerItemList
, m_children
);
509 wxSizerItem
* wxSizer::Insert( size_t index
, wxSizerItem
*item
)
511 m_children
.Insert( index
, item
);
513 if ( item
->GetWindow() )
514 item
->GetWindow()->SetContainingSizer( this );
519 void wxSizer::SetContainingWindow(wxWindow
*win
)
521 if ( win
== m_containingWindow
)
524 m_containingWindow
= win
;
526 // set the same window for all nested sizers as well, they also are in the
528 for ( wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
530 node
= node
->GetNext() )
532 wxSizerItem
*const item
= node
->GetData();
533 wxSizer
*const sizer
= item
->GetSizer();
537 sizer
->SetContainingWindow(win
);
542 #if WXWIN_COMPATIBILITY_2_6
543 bool wxSizer::Remove( wxWindow
*window
)
545 return Detach( window
);
547 #endif // WXWIN_COMPATIBILITY_2_6
549 bool wxSizer::Remove( wxSizer
*sizer
)
551 wxASSERT_MSG( sizer
, _T("Removing NULL sizer") );
553 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
556 wxSizerItem
*item
= node
->GetData();
558 if (item
->GetSizer() == sizer
)
561 m_children
.Erase( node
);
565 node
= node
->GetNext();
571 bool wxSizer::Remove( int index
)
573 wxCHECK_MSG( index
>= 0 && (size_t)index
< m_children
.GetCount(),
575 _T("Remove index is out of range") );
577 wxSizerItemList::compatibility_iterator node
= m_children
.Item( index
);
579 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
581 wxSizerItem
*item
= node
->GetData();
583 if ( item
->IsWindow() )
584 item
->GetWindow()->SetContainingSizer( NULL
);
587 m_children
.Erase( node
);
591 bool wxSizer::Detach( wxSizer
*sizer
)
593 wxASSERT_MSG( sizer
, _T("Detaching NULL sizer") );
595 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
598 wxSizerItem
*item
= node
->GetData();
600 if (item
->GetSizer() == sizer
)
604 m_children
.Erase( node
);
607 node
= node
->GetNext();
613 bool wxSizer::Detach( wxWindow
*window
)
615 wxASSERT_MSG( window
, _T("Detaching NULL window") );
617 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
620 wxSizerItem
*item
= node
->GetData();
622 if (item
->GetWindow() == window
)
624 item
->GetWindow()->SetContainingSizer( NULL
);
626 m_children
.Erase( node
);
629 node
= node
->GetNext();
635 bool wxSizer::Detach( int index
)
637 wxCHECK_MSG( index
>= 0 && (size_t)index
< m_children
.GetCount(),
639 _T("Detach index is out of range") );
641 wxSizerItemList::compatibility_iterator node
= m_children
.Item( index
);
643 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
645 wxSizerItem
*item
= node
->GetData();
647 if ( item
->IsSizer() )
649 else if ( item
->IsWindow() )
650 item
->GetWindow()->SetContainingSizer( NULL
);
653 m_children
.Erase( node
);
657 bool wxSizer::Replace( wxWindow
*oldwin
, wxWindow
*newwin
, bool recursive
)
659 wxASSERT_MSG( oldwin
, _T("Replacing NULL window") );
660 wxASSERT_MSG( newwin
, _T("Replacing with NULL window") );
662 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
665 wxSizerItem
*item
= node
->GetData();
667 if (item
->GetWindow() == oldwin
)
669 item
->GetWindow()->SetContainingSizer( NULL
);
670 item
->SetWindow(newwin
);
671 newwin
->SetContainingSizer( this );
674 else if (recursive
&& item
->IsSizer())
676 if (item
->GetSizer()->Replace( oldwin
, newwin
, true ))
680 node
= node
->GetNext();
686 bool wxSizer::Replace( wxSizer
*oldsz
, wxSizer
*newsz
, bool recursive
)
688 wxASSERT_MSG( oldsz
, _T("Replacing NULL sizer") );
689 wxASSERT_MSG( newsz
, _T("Replacing with NULL sizer") );
691 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
694 wxSizerItem
*item
= node
->GetData();
696 if (item
->GetSizer() == oldsz
)
698 wxSizer
*old
= item
->GetSizer();
699 item
->SetSizer(newsz
);
703 else if (recursive
&& item
->IsSizer())
705 if (item
->GetSizer()->Replace( oldsz
, newsz
, true ))
709 node
= node
->GetNext();
715 bool wxSizer::Replace( size_t old
, wxSizerItem
*newitem
)
717 wxCHECK_MSG( old
< m_children
.GetCount(), false, _T("Replace index is out of range") );
718 wxASSERT_MSG( newitem
, _T("Replacing with NULL item") );
720 wxSizerItemList::compatibility_iterator node
= m_children
.Item( old
);
722 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
724 wxSizerItem
*item
= node
->GetData();
725 node
->SetData(newitem
);
731 void wxSizer::Clear( bool delete_windows
)
733 // First clear the ContainingSizer pointers
734 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
737 wxSizerItem
*item
= node
->GetData();
739 if (item
->IsWindow())
740 item
->GetWindow()->SetContainingSizer( NULL
);
741 node
= node
->GetNext();
744 // Destroy the windows if needed
748 // Now empty the list
749 WX_CLEAR_LIST(wxSizerItemList
, m_children
);
752 void wxSizer::DeleteWindows()
754 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
757 wxSizerItem
*item
= node
->GetData();
759 item
->DeleteWindows();
760 node
= node
->GetNext();
764 wxSize
wxSizer::Fit( wxWindow
*window
)
766 // take the min size by default and limit it by max size
767 wxSize size
= GetMinWindowSize(window
);
768 wxSize sizeMax
= GetMaxWindowSize(window
);
770 wxTopLevelWindow
*tlw
= wxDynamicCast(window
, wxTopLevelWindow
);
773 // hack for small screen devices where TLWs are always full screen
774 if ( tlw
->IsAlwaysMaximized() )
776 size
= tlw
->GetSize();
778 else // normal situation
780 // limit the window to the size of the display it is on
781 int disp
= wxDisplay::GetFromWindow(window
);
782 if ( disp
== wxNOT_FOUND
)
784 // or, if we don't know which one it is, of the main one
788 sizeMax
= wxDisplay(disp
).GetClientArea().GetSize();
792 if ( sizeMax
.x
!= wxDefaultCoord
&& size
.x
> sizeMax
.x
)
794 if ( sizeMax
.y
!= wxDefaultCoord
&& size
.y
> sizeMax
.y
)
798 window
->SetSize( size
);
803 void wxSizer::FitInside( wxWindow
*window
)
806 if (window
->IsTopLevel())
807 size
= VirtualFitSize( window
);
809 size
= GetMinClientSize( window
);
811 window
->SetVirtualSize( size
);
814 void wxSizer::Layout()
816 // (re)calculates minimums needed for each item and other preparations
820 // Applies the layout and repositions/resizes the items
824 void wxSizer::SetSizeHints( wxWindow
*window
)
826 // Preserve the window's max size hints, but set the
827 // lower bound according to the sizer calculations.
829 wxSize size
= Fit( window
);
831 window
->SetSizeHints( size
.x
,
833 window
->GetMaxWidth(),
834 window
->GetMaxHeight() );
837 void wxSizer::SetVirtualSizeHints( wxWindow
*window
)
839 // Preserve the window's max size hints, but set the
840 // lower bound according to the sizer calculations.
843 wxSize
size( window
->GetVirtualSize() );
844 window
->SetVirtualSizeHints( size
.x
,
846 window
->GetMaxWidth(),
847 window
->GetMaxHeight() );
850 wxSize
wxSizer::GetMaxWindowSize( wxWindow
*window
) const
852 return window
->GetMaxSize();
855 wxSize
wxSizer::GetMinWindowSize( wxWindow
*window
)
857 wxSize
minSize( GetMinSize() );
858 wxSize
size( window
->GetSize() );
859 wxSize
client_size( window
->GetClientSize() );
861 return wxSize( minSize
.x
+size
.x
-client_size
.x
,
862 minSize
.y
+size
.y
-client_size
.y
);
865 // TODO on mac we need a function that determines how much free space this
866 // min size contains, in order to make sure that we have 20 pixels of free
867 // space around the controls
868 wxSize
wxSizer::GetMaxClientSize( wxWindow
*window
) const
870 wxSize
maxSize( window
->GetMaxSize() );
872 if ( maxSize
!= wxDefaultSize
)
874 wxSize
size( window
->GetSize() );
875 wxSize
client_size( window
->GetClientSize() );
877 return wxSize( maxSize
.x
+ client_size
.x
- size
.x
,
878 maxSize
.y
+ client_size
.y
- size
.y
);
881 return wxDefaultSize
;
884 wxSize
wxSizer::GetMinClientSize( wxWindow
*WXUNUSED(window
) )
886 return GetMinSize(); // Already returns client size.
889 wxSize
wxSizer::VirtualFitSize( wxWindow
*window
)
891 wxSize size
= GetMinClientSize( window
);
892 wxSize sizeMax
= GetMaxClientSize( window
);
894 // Limit the size if sizeMax != wxDefaultSize
896 if ( size
.x
> sizeMax
.x
&& sizeMax
.x
!= wxDefaultCoord
)
898 if ( size
.y
> sizeMax
.y
&& sizeMax
.y
!= wxDefaultCoord
)
904 void wxSizer::SetDimension( int x
, int y
, int width
, int height
)
913 wxSize
wxSizer::GetMinSize()
915 wxSize
ret( CalcMin() );
916 if (ret
.x
< m_minSize
.x
) ret
.x
= m_minSize
.x
;
917 if (ret
.y
< m_minSize
.y
) ret
.y
= m_minSize
.y
;
921 void wxSizer::DoSetMinSize( int width
, int height
)
924 m_minSize
.y
= height
;
927 bool wxSizer::DoSetItemMinSize( wxWindow
*window
, int width
, int height
)
929 wxASSERT_MSG( window
, _T("SetMinSize for NULL window") );
931 // Is it our immediate child?
933 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
936 wxSizerItem
*item
= node
->GetData();
938 if (item
->GetWindow() == window
)
940 item
->SetMinSize( width
, height
);
943 node
= node
->GetNext();
946 // No? Search any subsizers we own then
948 node
= m_children
.GetFirst();
951 wxSizerItem
*item
= node
->GetData();
953 if ( item
->GetSizer() &&
954 item
->GetSizer()->DoSetItemMinSize( window
, width
, height
) )
956 // A child sizer found the requested windw, exit.
959 node
= node
->GetNext();
965 bool wxSizer::DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
)
967 wxASSERT_MSG( sizer
, _T("SetMinSize for NULL sizer") );
969 // Is it our immediate child?
971 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
974 wxSizerItem
*item
= node
->GetData();
976 if (item
->GetSizer() == sizer
)
978 item
->GetSizer()->DoSetMinSize( width
, height
);
981 node
= node
->GetNext();
984 // No? Search any subsizers we own then
986 node
= m_children
.GetFirst();
989 wxSizerItem
*item
= node
->GetData();
991 if ( item
->GetSizer() &&
992 item
->GetSizer()->DoSetItemMinSize( sizer
, width
, height
) )
994 // A child found the requested sizer, exit.
997 node
= node
->GetNext();
1003 bool wxSizer::DoSetItemMinSize( size_t index
, int width
, int height
)
1005 wxSizerItemList::compatibility_iterator node
= m_children
.Item( index
);
1007 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
1009 wxSizerItem
*item
= node
->GetData();
1011 if (item
->GetSizer())
1013 // Sizers contains the minimal size in them, if not calculated ...
1014 item
->GetSizer()->DoSetMinSize( width
, height
);
1018 // ... but the minimal size of spacers and windows is stored via the item
1019 item
->SetMinSize( width
, height
);
1025 wxSizerItem
* wxSizer::GetItem( wxWindow
*window
, bool recursive
)
1027 wxASSERT_MSG( window
, _T("GetItem for NULL window") );
1029 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1032 wxSizerItem
*item
= node
->GetData();
1034 if (item
->GetWindow() == window
)
1038 else if (recursive
&& item
->IsSizer())
1040 wxSizerItem
*subitem
= item
->GetSizer()->GetItem( window
, true );
1045 node
= node
->GetNext();
1051 wxSizerItem
* wxSizer::GetItem( wxSizer
*sizer
, bool recursive
)
1053 wxASSERT_MSG( sizer
, _T("GetItem for NULL sizer") );
1055 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1058 wxSizerItem
*item
= node
->GetData();
1060 if (item
->GetSizer() == sizer
)
1064 else if (recursive
&& item
->IsSizer())
1066 wxSizerItem
*subitem
= item
->GetSizer()->GetItem( sizer
, true );
1071 node
= node
->GetNext();
1077 wxSizerItem
* wxSizer::GetItem( size_t index
)
1079 wxCHECK_MSG( index
< m_children
.GetCount(),
1081 _T("GetItem index is out of range") );
1083 return m_children
.Item( index
)->GetData();
1086 bool wxSizer::Show( wxWindow
*window
, bool show
, bool recursive
)
1088 wxSizerItem
*item
= GetItem( window
, recursive
);
1099 bool wxSizer::Show( wxSizer
*sizer
, bool show
, bool recursive
)
1101 wxSizerItem
*item
= GetItem( sizer
, recursive
);
1112 bool wxSizer::Show( size_t index
, bool show
)
1114 wxSizerItem
*item
= GetItem( index
);
1125 void wxSizer::ShowItems( bool show
)
1127 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1130 node
->GetData()->Show( show
);
1131 node
= node
->GetNext();
1135 bool wxSizer::IsShown( wxWindow
*window
) const
1137 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1140 wxSizerItem
*item
= node
->GetData();
1142 if (item
->GetWindow() == window
)
1144 return item
->IsShown();
1146 node
= node
->GetNext();
1149 wxFAIL_MSG( _T("IsShown failed to find sizer item") );
1154 bool wxSizer::IsShown( wxSizer
*sizer
) const
1156 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1159 wxSizerItem
*item
= node
->GetData();
1161 if (item
->GetSizer() == sizer
)
1163 return item
->IsShown();
1165 node
= node
->GetNext();
1168 wxFAIL_MSG( _T("IsShown failed to find sizer item") );
1173 bool wxSizer::IsShown( size_t index
) const
1175 wxCHECK_MSG( index
< m_children
.GetCount(),
1177 _T("IsShown index is out of range") );
1179 return m_children
.Item( index
)->GetData()->IsShown();
1183 //---------------------------------------------------------------------------
1185 //---------------------------------------------------------------------------
1187 wxGridSizer::wxGridSizer( int rows
, int cols
, int vgap
, int hgap
)
1188 : m_rows( ( cols
== 0 && rows
== 0 ) ? 1 : rows
)
1195 wxGridSizer::wxGridSizer( int cols
, int vgap
, int hgap
)
1196 : m_rows( cols
== 0 ? 1 : 0 )
1203 int wxGridSizer::CalcRowsCols(int& nrows
, int& ncols
) const
1205 int nitems
= m_children
.GetCount();
1211 nrows
= (nitems
+ m_cols
- 1) / m_cols
;
1215 ncols
= (nitems
+ m_rows
- 1) / m_rows
;
1218 else // 0 columns, 0 rows?
1220 wxFAIL_MSG( _T("grid sizer must have either rows or columns fixed") );
1229 void wxGridSizer::RecalcSizes()
1231 int nitems
, nrows
, ncols
;
1232 if ( (nitems
= CalcRowsCols(nrows
, ncols
)) == 0 )
1235 wxSize
sz( GetSize() );
1236 wxPoint
pt( GetPosition() );
1238 int w
= (sz
.x
- (ncols
- 1) * m_hgap
) / ncols
;
1239 int h
= (sz
.y
- (nrows
- 1) * m_vgap
) / nrows
;
1242 for (int c
= 0; c
< ncols
; c
++)
1245 for (int r
= 0; r
< nrows
; r
++)
1247 int i
= r
* ncols
+ c
;
1250 wxSizerItemList::compatibility_iterator node
= m_children
.Item( i
);
1252 wxASSERT_MSG( node
, _T("Failed to find SizerItemList node") );
1254 SetItemBounds( node
->GetData(), x
, y
, w
, h
);
1262 wxSize
wxGridSizer::CalcMin()
1265 if ( CalcRowsCols(nrows
, ncols
) == 0 )
1268 // Find the max width and height for any component
1272 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1275 wxSizerItem
*item
= node
->GetData();
1276 wxSize
sz( item
->CalcMin() );
1278 w
= wxMax( w
, sz
.x
);
1279 h
= wxMax( h
, sz
.y
);
1281 node
= node
->GetNext();
1284 return wxSize( ncols
* w
+ (ncols
-1) * m_hgap
,
1285 nrows
* h
+ (nrows
-1) * m_vgap
);
1288 void wxGridSizer::SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
)
1291 wxSize
sz( item
->GetMinSizeWithBorder() );
1292 int flag
= item
->GetFlag();
1294 if ((flag
& wxEXPAND
) || (flag
& wxSHAPED
))
1300 if (flag
& wxALIGN_CENTER_HORIZONTAL
)
1302 pt
.x
= x
+ (w
- sz
.x
) / 2;
1304 else if (flag
& wxALIGN_RIGHT
)
1306 pt
.x
= x
+ (w
- sz
.x
);
1309 if (flag
& wxALIGN_CENTER_VERTICAL
)
1311 pt
.y
= y
+ (h
- sz
.y
) / 2;
1313 else if (flag
& wxALIGN_BOTTOM
)
1315 pt
.y
= y
+ (h
- sz
.y
);
1319 item
->SetDimension(pt
, sz
);
1322 //---------------------------------------------------------------------------
1324 //---------------------------------------------------------------------------
1326 wxFlexGridSizer::wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
)
1327 : wxGridSizer( rows
, cols
, vgap
, hgap
),
1328 m_flexDirection(wxBOTH
),
1329 m_growMode(wxFLEX_GROWMODE_SPECIFIED
)
1333 wxFlexGridSizer::wxFlexGridSizer( int cols
, int vgap
, int hgap
)
1334 : wxGridSizer( cols
, vgap
, hgap
),
1335 m_flexDirection(wxBOTH
),
1336 m_growMode(wxFLEX_GROWMODE_SPECIFIED
)
1340 wxFlexGridSizer::~wxFlexGridSizer()
1344 void wxFlexGridSizer::RecalcSizes()
1346 int nitems
, nrows
, ncols
;
1347 if ( (nitems
= CalcRowsCols(nrows
, ncols
)) == 0 )
1350 wxPoint
pt( GetPosition() );
1351 wxSize
sz( GetSize() );
1353 AdjustForGrowables(sz
, m_calculatedMinSize
, nrows
, ncols
);
1355 sz
= wxSize( pt
.x
+ sz
.x
, pt
.y
+ sz
.y
);
1358 for (int c
= 0; c
< ncols
; c
++)
1361 for (int r
= 0; r
< nrows
; r
++)
1363 int i
= r
* ncols
+ c
;
1366 wxSizerItemList::compatibility_iterator node
= m_children
.Item( i
);
1368 wxASSERT_MSG( node
, _T("Failed to find node") );
1370 int w
= wxMax( 0, wxMin( m_colWidths
[c
], sz
.x
- x
) );
1371 int h
= wxMax( 0, wxMin( m_rowHeights
[r
], sz
.y
- y
) );
1373 SetItemBounds( node
->GetData(), x
, y
, w
, h
);
1375 if (m_rowHeights
[r
] != -1)
1376 y
= y
+ m_rowHeights
[r
] + m_vgap
;
1378 if (m_colWidths
[c
] != -1)
1379 x
= x
+ m_colWidths
[c
] + m_hgap
;
1383 wxSize
wxFlexGridSizer::CalcMin()
1389 // Number of rows/columns can change as items are added or removed.
1390 if ( !CalcRowsCols(nrows
, ncols
) )
1393 m_rowHeights
.SetCount(nrows
);
1394 m_colWidths
.SetCount(ncols
);
1396 // We have to recalcuate the sizes in case the item minimum size has
1397 // changed since the previous layout, or the item has been hidden using
1398 // wxSizer::Show(). If all the items in a row/column are hidden, the final
1399 // dimension of the row/column will be -1, indicating that the column
1400 // itself is hidden.
1401 for( s
= m_rowHeights
.GetCount(), i
= 0; i
< s
; ++i
)
1402 m_rowHeights
[ i
] = -1;
1403 for( s
= m_colWidths
.GetCount(), i
= 0; i
< s
; ++i
)
1404 m_colWidths
[ i
] = -1;
1406 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1411 wxSizerItem
*item
= node
->GetData();
1412 if ( item
->IsShown() )
1414 wxSize
sz( item
->CalcMin() );
1415 int row
= i
/ ncols
;
1416 int col
= i
% ncols
;
1418 m_rowHeights
[ row
] = wxMax( wxMax( 0, sz
.y
), m_rowHeights
[ row
] );
1419 m_colWidths
[ col
] = wxMax( wxMax( 0, sz
.x
), m_colWidths
[ col
] );
1422 node
= node
->GetNext();
1426 AdjustForFlexDirection();
1428 // Sum total minimum size, including gaps between rows/columns.
1429 // -1 is used as a magic number meaning empty column.
1431 for (int col
= 0; col
< ncols
; col
++)
1432 if ( m_colWidths
[ col
] != -1 )
1433 width
+= m_colWidths
[ col
] + m_hgap
;
1438 for (int row
= 0; row
< nrows
; row
++)
1439 if ( m_rowHeights
[ row
] != -1 )
1440 height
+= m_rowHeights
[ row
] + m_vgap
;
1444 m_calculatedMinSize
= wxSize( width
, height
);
1445 return m_calculatedMinSize
;
1448 void wxFlexGridSizer::AdjustForFlexDirection()
1450 // the logic in CalcMin works when we resize flexibly in both directions
1451 // but maybe this is not the case
1452 if ( m_flexDirection
!= wxBOTH
)
1454 // select the array corresponding to the direction in which we do *not*
1456 wxArrayInt
& array
= m_flexDirection
== wxVERTICAL
? m_colWidths
1459 const size_t count
= array
.GetCount();
1461 // find the largest value in this array
1465 for ( n
= 0; n
< count
; ++n
)
1467 if ( array
[n
] > largest
)
1471 // and now fill it with the largest value
1472 for ( n
= 0; n
< count
; ++n
)
1480 void wxFlexGridSizer::AdjustForGrowables(const wxSize
& sz
, const wxSize
& minsz
,
1481 int nrows
, int ncols
)
1483 // what to do with the rows? by default, resize them proportionally
1484 if ( sz
.y
> minsz
.y
&& ( (m_flexDirection
& wxVERTICAL
) || (m_growMode
== wxFLEX_GROWMODE_SPECIFIED
) ) )
1486 int sum_proportions
= 0;
1487 int growable_space
= 0;
1490 for (idx
= 0; idx
< m_growableRows
.GetCount(); idx
++)
1492 // Since the number of rows/columns can change as items are
1493 // inserted/deleted, we need to verify at runtime that the
1494 // requested growable rows/columns are still valid.
1495 if (m_growableRows
[idx
] >= nrows
)
1498 // If all items in a row/column are hidden, that row/column will
1499 // have a dimension of -1. This causes the row/column to be
1500 // hidden completely.
1501 if (m_rowHeights
[ m_growableRows
[idx
] ] == -1)
1503 sum_proportions
+= m_growableRowsProportions
[idx
];
1504 growable_space
+= m_rowHeights
[ m_growableRows
[idx
] ];
1510 for (idx
= 0; idx
< m_growableRows
.GetCount(); idx
++)
1512 if (m_growableRows
[idx
] >= nrows
)
1514 if (m_rowHeights
[ m_growableRows
[idx
] ] == -1)
1515 m_rowHeights
[ m_growableRows
[idx
] ] = 0;
1518 int delta
= (sz
.y
- minsz
.y
);
1519 if (sum_proportions
== 0)
1520 delta
= (delta
/num
) + m_rowHeights
[ m_growableRows
[idx
] ];
1522 delta
= ((delta
+growable_space
)*m_growableRowsProportions
[idx
]) / sum_proportions
;
1523 m_rowHeights
[ m_growableRows
[idx
] ] = delta
;
1528 else if ( (m_growMode
== wxFLEX_GROWMODE_ALL
) && (sz
.y
> minsz
.y
) )
1530 // rounding problem?
1531 for ( int row
= 0; row
< nrows
; ++row
)
1532 m_rowHeights
[ row
] = sz
.y
/ nrows
;
1535 // the same logic as above but for the columns
1536 if ( sz
.x
> minsz
.x
&& ( (m_flexDirection
& wxHORIZONTAL
) || (m_growMode
== wxFLEX_GROWMODE_SPECIFIED
) ) )
1538 int sum_proportions
= 0;
1539 int growable_space
= 0;
1542 for (idx
= 0; idx
< m_growableCols
.GetCount(); idx
++)
1544 // Since the number of rows/columns can change as items are
1545 // inserted/deleted, we need to verify at runtime that the
1546 // requested growable rows/columns are still valid.
1547 if (m_growableCols
[idx
] >= ncols
)
1550 // If all items in a row/column are hidden, that row/column will
1551 // have a dimension of -1. This causes the column to be hidden
1553 if (m_colWidths
[ m_growableCols
[idx
] ] == -1)
1555 sum_proportions
+= m_growableColsProportions
[idx
];
1556 growable_space
+= m_colWidths
[ m_growableCols
[idx
] ];
1562 for (idx
= 0; idx
< m_growableCols
.GetCount(); idx
++)
1564 if (m_growableCols
[idx
] >= ncols
)
1566 if (m_colWidths
[ m_growableCols
[idx
] ] == -1)
1567 m_colWidths
[ m_growableCols
[idx
] ] = 0;
1570 int delta
= (sz
.x
- minsz
.x
);
1571 if (sum_proportions
== 0)
1572 delta
= (delta
/num
) + m_colWidths
[ m_growableCols
[idx
] ];
1574 delta
= ((delta
+growable_space
)*m_growableColsProportions
[idx
])/sum_proportions
;
1575 m_colWidths
[ m_growableCols
[idx
] ] = delta
;
1580 else if ( (m_growMode
== wxFLEX_GROWMODE_ALL
) && (sz
.x
> minsz
.x
) )
1582 for ( int col
=0; col
< ncols
; ++col
)
1583 m_colWidths
[ col
] = sz
.x
/ ncols
;
1588 void wxFlexGridSizer::AddGrowableRow( size_t idx
, int proportion
)
1590 m_growableRows
.Add( idx
);
1591 m_growableRowsProportions
.Add( proportion
);
1594 void wxFlexGridSizer::AddGrowableCol( size_t idx
, int proportion
)
1596 m_growableCols
.Add( idx
);
1597 m_growableColsProportions
.Add( proportion
);
1600 // helper function for RemoveGrowableCol/Row()
1602 DoRemoveFromArrays(size_t idx
, wxArrayInt
& items
, wxArrayInt
& proportions
)
1604 const size_t count
= items
.size();
1605 for ( size_t n
= 0; n
< count
; n
++ )
1607 if ( (size_t)items
[n
] == idx
)
1610 proportions
.RemoveAt(n
);
1615 wxFAIL_MSG( _T("column/row is already not growable") );
1618 void wxFlexGridSizer::RemoveGrowableCol( size_t idx
)
1620 DoRemoveFromArrays(idx
, m_growableCols
, m_growableColsProportions
);
1623 void wxFlexGridSizer::RemoveGrowableRow( size_t idx
)
1625 DoRemoveFromArrays(idx
, m_growableRows
, m_growableRowsProportions
);
1628 //---------------------------------------------------------------------------
1630 //---------------------------------------------------------------------------
1632 wxBoxSizer::wxBoxSizer( int orient
)
1633 : m_orient( orient
)
1637 void wxBoxSizer::RecalcSizes()
1639 if (m_children
.GetCount() == 0)
1645 if (m_orient
== wxHORIZONTAL
)
1646 delta
= m_size
.x
- m_fixedWidth
;
1648 delta
= m_size
.y
- m_fixedHeight
;
1651 wxPoint
pt( m_position
);
1653 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1656 wxSizerItem
*item
= node
->GetData();
1658 if (item
->IsShown())
1660 wxSize
size( item
->GetMinSizeWithBorder() );
1662 if (m_orient
== wxVERTICAL
)
1664 wxCoord height
= size
.y
;
1665 if (item
->GetProportion())
1667 // Because of at least one visible item has non-zero
1668 // proportion then m_stretchable is not zero
1669 height
= (delta
* item
->GetProportion()) / m_stretchable
;
1672 wxPoint
child_pos( pt
);
1673 wxSize
child_size( size
.x
, height
);
1675 if (item
->GetFlag() & (wxEXPAND
| wxSHAPED
))
1676 child_size
.x
= m_size
.x
;
1677 else if (item
->GetFlag() & wxALIGN_RIGHT
)
1678 child_pos
.x
+= m_size
.x
- size
.x
;
1679 else if (item
->GetFlag() & (wxCENTER
| wxALIGN_CENTER_HORIZONTAL
))
1680 // XXX wxCENTER is added for backward compatibility;
1681 // wxALIGN_CENTER should be used in new code
1682 child_pos
.x
+= (m_size
.x
- size
.x
) / 2;
1684 item
->SetDimension( child_pos
, child_size
);
1690 wxCoord width
= size
.x
;
1691 if (item
->GetProportion())
1693 // Because of at least one visible item has non-zero
1694 // proportion then m_stretchable is not zero
1695 width
= (delta
* item
->GetProportion()) / m_stretchable
;
1698 wxPoint
child_pos( pt
);
1699 wxSize
child_size( width
, size
.y
);
1701 if (item
->GetFlag() & (wxEXPAND
| wxSHAPED
))
1702 child_size
.y
= m_size
.y
;
1703 else if (item
->GetFlag() & wxALIGN_BOTTOM
)
1704 child_pos
.y
+= m_size
.y
- size
.y
;
1705 else if (item
->GetFlag() & (wxCENTER
| wxALIGN_CENTER_VERTICAL
))
1706 // XXX wxCENTER is added for backward compatibility;
1707 // wxALIGN_CENTER should be used in new code
1708 child_pos
.y
+= (m_size
.y
- size
.y
) / 2;
1710 if ( m_containingWindow
)
1712 child_pos
.x
= m_containingWindow
->AdjustForLayoutDirection
1720 item
->SetDimension( child_pos
, child_size
);
1726 node
= node
->GetNext();
1730 wxSize
wxBoxSizer::CalcMin()
1732 if (m_children
.GetCount() == 0)
1741 // precalc item minsizes and count proportions
1742 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1745 wxSizerItem
*item
= node
->GetData();
1747 if ( item
->IsShown() )
1749 item
->CalcMin(); // result is stored in the item
1751 m_stretchable
+= item
->GetProportion();
1754 node
= node
->GetNext();
1757 // Total minimum size (width or height) of sizer
1760 node
= m_children
.GetFirst();
1763 wxSizerItem
*item
= node
->GetData();
1765 if (item
->IsShown() && item
->GetProportion() != 0)
1767 int stretch
= item
->GetProportion();
1768 wxSize
size( item
->GetMinSizeWithBorder() );
1771 // Integer division rounded up is (a + b - 1) / b
1772 // Round up needed in order to guarantee that all
1773 // all items will have size not less then their min size
1774 if (m_orient
== wxHORIZONTAL
)
1775 minSize
= ( size
.x
*m_stretchable
+ stretch
- 1)/stretch
;
1777 minSize
= ( size
.y
*m_stretchable
+ stretch
- 1)/stretch
;
1779 if (minSize
> maxMinSize
)
1780 maxMinSize
= minSize
;
1782 node
= node
->GetNext();
1785 // Calculate overall minimum size
1786 node
= m_children
.GetFirst();
1789 wxSizerItem
*item
= node
->GetData();
1791 if (item
->IsShown())
1793 wxSize
size( item
->GetMinSizeWithBorder() );
1794 if (item
->GetProportion() != 0)
1796 if (m_orient
== wxHORIZONTAL
)
1797 size
.x
= (maxMinSize
*item
->GetProportion())/m_stretchable
;
1799 size
.y
= (maxMinSize
*item
->GetProportion())/m_stretchable
;
1803 if (m_orient
== wxVERTICAL
)
1805 m_fixedHeight
+= size
.y
;
1806 m_fixedWidth
= wxMax( m_fixedWidth
, size
.x
);
1810 m_fixedWidth
+= size
.x
;
1811 m_fixedHeight
= wxMax( m_fixedHeight
, size
.y
);
1815 if (m_orient
== wxHORIZONTAL
)
1817 m_minWidth
+= size
.x
;
1818 m_minHeight
= wxMax( m_minHeight
, size
.y
);
1822 m_minHeight
+= size
.y
;
1823 m_minWidth
= wxMax( m_minWidth
, size
.x
);
1826 node
= node
->GetNext();
1829 return wxSize( m_minWidth
, m_minHeight
);
1832 //---------------------------------------------------------------------------
1834 //---------------------------------------------------------------------------
1838 wxStaticBoxSizer::wxStaticBoxSizer( wxStaticBox
*box
, int orient
)
1839 : wxBoxSizer( orient
),
1842 wxASSERT_MSG( box
, wxT("wxStaticBoxSizer needs a static box") );
1844 // do this so that our Detach() is called if the static box is destroyed
1846 m_staticBox
->SetContainingSizer(this);
1849 wxStaticBoxSizer::wxStaticBoxSizer(int orient
, wxWindow
*win
, const wxString
& s
)
1850 : wxBoxSizer(orient
),
1851 m_staticBox(new wxStaticBox(win
, wxID_ANY
, s
))
1854 m_staticBox
->SetContainingSizer(this);
1857 wxStaticBoxSizer::~wxStaticBoxSizer()
1862 static void GetStaticBoxBorders( wxStaticBox
*box
,
1866 // this has to be done platform by platform as there is no way to
1867 // guess the thickness of a wxStaticBox border
1868 box
->GetBordersForSizer(borderTop
, borderOther
);
1871 void wxStaticBoxSizer::RecalcSizes()
1873 int top_border
, other_border
;
1874 GetStaticBoxBorders(m_staticBox
, &top_border
, &other_border
);
1876 m_staticBox
->SetSize( m_position
.x
, m_position
.y
, m_size
.x
, m_size
.y
);
1878 wxPoint
old_pos( m_position
);
1879 m_position
.x
+= other_border
;
1880 m_position
.y
+= top_border
;
1881 wxSize
old_size( m_size
);
1882 m_size
.x
-= 2*other_border
;
1883 m_size
.y
-= top_border
+ other_border
;
1885 wxBoxSizer::RecalcSizes();
1887 m_position
= old_pos
;
1891 wxSize
wxStaticBoxSizer::CalcMin()
1893 int top_border
, other_border
;
1894 GetStaticBoxBorders(m_staticBox
, &top_border
, &other_border
);
1896 wxSize
ret( wxBoxSizer::CalcMin() );
1897 ret
.x
+= 2*other_border
;
1898 ret
.y
+= other_border
+ top_border
;
1903 void wxStaticBoxSizer::ShowItems( bool show
)
1905 m_staticBox
->Show( show
);
1906 wxBoxSizer::ShowItems( show
);
1909 bool wxStaticBoxSizer::Detach( wxWindow
*window
)
1911 // avoid deleting m_staticBox in our dtor if it's being detached from the
1912 // sizer (which can happen because it's being already destroyed for
1914 if ( window
== m_staticBox
)
1920 return wxSizer::Detach( window
);
1923 #endif // wxUSE_STATBOX
1927 wxStdDialogButtonSizer::wxStdDialogButtonSizer()
1928 : wxBoxSizer(wxHORIZONTAL
)
1930 // Vertical buttons with lots of space on either side
1931 // looks rubbish on WinCE, so let's not do this for now.
1932 // If we are going to use vertical buttons, we should
1933 // put the sizer to the right of other controls in the dialog,
1934 // and that's beyond the scope of this sizer.
1936 bool is_pda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
1937 // If we have a PDA screen, put yes/no button over
1938 // all other buttons, otherwise on the left side.
1940 m_orient
= wxVERTICAL
;
1943 m_buttonAffirmative
= NULL
;
1944 m_buttonApply
= NULL
;
1945 m_buttonNegative
= NULL
;
1946 m_buttonCancel
= NULL
;
1947 m_buttonHelp
= NULL
;
1950 void wxStdDialogButtonSizer::AddButton(wxButton
*mybutton
)
1952 switch (mybutton
->GetId())
1957 m_buttonAffirmative
= mybutton
;
1960 m_buttonApply
= mybutton
;
1963 m_buttonNegative
= mybutton
;
1966 m_buttonCancel
= mybutton
;
1969 case wxID_CONTEXT_HELP
:
1970 m_buttonHelp
= mybutton
;
1977 void wxStdDialogButtonSizer::SetAffirmativeButton( wxButton
*button
)
1979 m_buttonAffirmative
= button
;
1982 void wxStdDialogButtonSizer::SetNegativeButton( wxButton
*button
)
1984 m_buttonNegative
= button
;
1987 void wxStdDialogButtonSizer::SetCancelButton( wxButton
*button
)
1989 m_buttonCancel
= button
;
1992 void wxStdDialogButtonSizer::Realize()
1995 Add(0, 0, 0, wxLEFT
, 6);
1997 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 6);
1999 if (m_buttonNegative
){
2000 // HIG POLICE BULLETIN - destructive buttons need extra padding
2001 // 24 pixels on either side
2002 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 12);
2005 // extra whitespace between help/negative and cancel/ok buttons
2006 Add(0, 0, 1, wxEXPAND
, 0);
2008 if (m_buttonCancel
){
2009 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 6);
2010 // Cancel or help should be default
2011 // m_buttonCancel->SetDefaultButton();
2014 // Ugh, Mac doesn't really have apply dialogs, so I'll just
2015 // figure the best place is between Cancel and OK
2017 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 6);
2019 if (m_buttonAffirmative
){
2020 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
, 6);
2022 if (m_buttonAffirmative
->GetId() == wxID_SAVE
){
2023 // these buttons have set labels under Mac so we should use them
2024 m_buttonAffirmative
->SetLabel(_("Save"));
2025 m_buttonNegative
->SetLabel(_("Don't Save"));
2029 // Extra space around and at the right
2031 #elif defined(__WXGTK20__)
2032 Add(0, 0, 0, wxLEFT
, 9);
2034 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
2036 // extra whitespace between help and cancel/ok buttons
2037 Add(0, 0, 1, wxEXPAND
, 0);
2039 if (m_buttonNegative
){
2040 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
2043 if (m_buttonCancel
){
2044 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
2045 // Cancel or help should be default
2046 // m_buttonCancel->SetDefaultButton();
2050 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
2052 if (m_buttonAffirmative
)
2053 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
, 6);
2054 #elif defined(__WXMSW__)
2057 // right-justify buttons
2058 Add(0, 0, 1, wxEXPAND
, 0);
2060 if (m_buttonAffirmative
){
2061 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonAffirmative
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2064 if (m_buttonNegative
){
2065 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonNegative
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2068 if (m_buttonCancel
){
2069 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonCancel
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2072 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonApply
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2075 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonHelp
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2077 // GTK+1 and any other platform
2079 // Add(0, 0, 0, wxLEFT, 5); // Not sure what this was for but it unbalances the dialog
2081 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonHelp
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2083 // extra whitespace between help and cancel/ok buttons
2084 Add(0, 0, 1, wxEXPAND
, 0);
2087 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonApply
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2089 if (m_buttonAffirmative
){
2090 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonAffirmative
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2093 if (m_buttonNegative
){
2094 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonNegative
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2097 if (m_buttonCancel
){
2098 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonCancel
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2099 // Cancel or help should be default
2100 // m_buttonCancel->SetDefaultButton();
2106 #endif // wxUSE_BUTTON