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"
21 #include "wx/private/flagscheck.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/display.h"
35 #include "wx/listimpl.cpp"
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 // check for flags conflicts
92 static const int SIZER_FLAGS_MASK
=
94 wxADD_FLAG(wxHORIZONTAL
,
95 wxADD_FLAG(wxVERTICAL
,
100 wxADD_FLAG(wxALIGN_NOT
,
101 wxADD_FLAG(wxALIGN_CENTER_HORIZONTAL
,
102 wxADD_FLAG(wxALIGN_RIGHT
,
103 wxADD_FLAG(wxALIGN_BOTTOM
,
104 wxADD_FLAG(wxALIGN_CENTER_VERTICAL
,
105 wxADD_FLAG(wxFIXED_MINSIZE
,
106 wxADD_FLAG(wxRESERVE_SPACE_EVEN_IF_HIDDEN
,
107 wxADD_FLAG(wxSTRETCH_NOT
,
113 #define ASSERT_VALID_SIZER_FLAGS(f) wxASSERT_VALID_FLAGS(f, SIZER_FLAGS_MASK)
116 void wxSizerItem::Init(const wxSizerFlags
& flags
)
120 m_proportion
= flags
.GetProportion();
121 m_flag
= flags
.GetFlags();
122 m_border
= flags
.GetBorderInPixels();
124 ASSERT_VALID_SIZER_FLAGS( m_flag
);
127 wxSizerItem::wxSizerItem()
138 void wxSizerItem::DoSetWindow(wxWindow
*window
)
140 wxCHECK_RET( window
, _T("NULL window in wxSizerItem::SetWindow()") );
142 m_kind
= Item_Window
;
145 // window doesn't become smaller than its initial size, whatever happens
146 m_minSize
= window
->GetSize();
148 if ( m_flag
& wxFIXED_MINSIZE
)
149 window
->SetMinSize(m_minSize
);
151 // aspect ratio calculated from initial size
155 wxSizerItem::wxSizerItem(wxWindow
*window
,
161 m_proportion(proportion
),
167 ASSERT_VALID_SIZER_FLAGS( m_flag
);
173 void wxSizerItem::DoSetSizer(wxSizer
*sizer
)
179 wxSizerItem::wxSizerItem(wxSizer
*sizer
,
186 m_proportion(proportion
),
193 ASSERT_VALID_SIZER_FLAGS( m_flag
);
197 // m_minSize is set later
201 void wxSizerItem::DoSetSpacer(const wxSize
& size
)
203 m_kind
= Item_Spacer
;
204 m_spacer
= new wxSizerSpacer(size
);
209 wxSizerItem::wxSizerItem(int width
,
217 m_minSize(width
, height
), // minimal size is the initial size
218 m_proportion(proportion
),
224 ASSERT_VALID_SIZER_FLAGS( m_flag
);
226 DoSetSpacer(wxSize(width
, height
));
229 wxSizerItem::~wxSizerItem()
235 void wxSizerItem::Free()
243 m_window
->SetContainingSizer(NULL
);
256 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
262 wxSize
wxSizerItem::GetSpacer() const
265 if ( m_kind
== Item_Spacer
)
266 size
= m_spacer
->GetSize();
272 wxSize
wxSizerItem::GetSize() const
281 ret
= m_window
->GetSize();
285 ret
= m_sizer
->GetSize();
289 ret
= m_spacer
->GetSize();
294 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
301 if (m_flag
& wxNORTH
)
303 if (m_flag
& wxSOUTH
)
309 bool wxSizerItem::InformFirstDirection(int direction
, int size
, int availableOtherDir
)
311 // The size that come here will be including borders. Child items should get it
315 if( direction
==wxHORIZONTAL
)
322 else if( direction
==wxVERTICAL
)
324 if (m_flag
& wxNORTH
)
326 if (m_flag
& wxSOUTH
)
332 // Pass the information along to the held object
335 didUse
= GetSizer()->InformFirstDirection(direction
,size
,availableOtherDir
);
337 m_minSize
= GetSizer()->CalcMin();
341 didUse
= GetWindow()->InformFirstDirection(direction
,size
,availableOtherDir
);
343 m_minSize
= m_window
->GetEffectiveMinSize();
345 // This information is useful for items with wxSHAPED flag, since
346 // we can request an optimal min size for such an item. Even if
347 // we overwrite the m_minSize member here, we can read it back from
348 // the owned window (happens automatically).
349 if( (m_flag
& wxSHAPED
) && (m_flag
& wxEXPAND
) && direction
)
351 if( !wxIsNullDouble(m_ratio
) )
353 wxCHECK_MSG( (m_proportion
==0), false, _T("Shaped item, non-zero proportion in wxSizerItem::InformFirstDirection()") );
354 if( direction
==wxHORIZONTAL
&& !wxIsNullDouble(m_ratio
) )
356 // Clip size so that we don't take too much
357 if( availableOtherDir
>=0 && int(size
/m_ratio
)-m_minSize
.y
>availableOtherDir
)
358 size
= int((availableOtherDir
+m_minSize
.y
)*m_ratio
);
359 m_minSize
= wxSize(size
,int(size
/m_ratio
));
361 else if( direction
==wxVERTICAL
)
363 // Clip size so that we don't take too much
364 if( availableOtherDir
>=0 && int(size
*m_ratio
)-m_minSize
.x
>availableOtherDir
)
365 size
= int((availableOtherDir
+m_minSize
.x
)/m_ratio
);
366 m_minSize
= wxSize(int(size
*m_ratio
),size
);
376 wxSize
wxSizerItem::CalcMin()
380 m_minSize
= m_sizer
->GetMinSize();
382 // if we have to preserve aspect ratio _AND_ this is
383 // the first-time calculation, consider ret to be initial size
384 if ( (m_flag
& wxSHAPED
) && wxIsNullDouble(m_ratio
) )
387 else if ( IsWindow() )
389 // Since the size of the window may change during runtime, we
390 // should use the current minimal/best size.
391 m_minSize
= m_window
->GetEffectiveMinSize();
394 return GetMinSizeWithBorder();
397 wxSize
wxSizerItem::GetMinSizeWithBorder() const
399 wxSize ret
= m_minSize
;
405 if (m_flag
& wxNORTH
)
407 if (m_flag
& wxSOUTH
)
414 void wxSizerItem::SetDimension( const wxPoint
& pos_
, const wxSize
& size_
)
418 if (m_flag
& wxSHAPED
)
420 // adjust aspect ratio
421 int rwidth
= (int) (size
.y
* m_ratio
);
425 int rheight
= (int) (size
.x
/ m_ratio
);
426 // add vertical space
427 if (m_flag
& wxALIGN_CENTER_VERTICAL
)
428 pos
.y
+= (size
.y
- rheight
) / 2;
429 else if (m_flag
& wxALIGN_BOTTOM
)
430 pos
.y
+= (size
.y
- rheight
);
431 // use reduced dimensions
434 else if (rwidth
< size
.x
)
436 // add horizontal space
437 if (m_flag
& wxALIGN_CENTER_HORIZONTAL
)
438 pos
.x
+= (size
.x
- rwidth
) / 2;
439 else if (m_flag
& wxALIGN_RIGHT
)
440 pos
.x
+= (size
.x
- rwidth
);
445 // This is what GetPosition() returns. Since we calculate
446 // borders afterwards, GetPosition() will be the left/top
447 // corner of the surrounding border.
459 if (m_flag
& wxNORTH
)
464 if (m_flag
& wxSOUTH
)
474 m_rect
= wxRect(pos
, size
);
479 wxFAIL_MSG( _T("can't set size of uninitialized sizer item") );
484 // Use wxSIZE_FORCE_EVENT here since a sizer item might
485 // have changed alignment or some other property which would
486 // not change the size of the window. In such a case, no
487 // wxSizeEvent would normally be generated and thus the
488 // control wouldn't get layed out correctly here.
489 m_window
->SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
,
490 wxSIZE_ALLOW_MINUS_ONE
|wxSIZE_FORCE_EVENT
);
494 m_sizer
->SetDimension(pos
, size
);
498 m_spacer
->SetSize(size
);
503 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
507 void wxSizerItem::DeleteWindows()
516 //We are deleting the window from this sizer - normally
517 //the window destroys the sizer associated with it,
518 //which might destroy this, which we don't want
519 m_window
->SetContainingSizer(NULL
);
521 //Putting this after the switch will result in a spacer
522 //not being deleted properly on destruction
527 m_sizer
->DeleteWindows();
532 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
537 void wxSizerItem::Show( bool show
)
542 wxFAIL_MSG( _T("can't show uninitialized sizer item") );
546 m_window
->Show(show
);
554 m_spacer
->Show(show
);
559 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
563 bool wxSizerItem::IsShown() const
565 if ( m_flag
& wxRESERVE_SPACE_EVEN_IF_HIDDEN
)
571 // we may be called from CalcMin(), just return false so that we're
576 return m_window
->IsShown();
579 // arbitrarily decide that if at least one of our elements is
580 // shown, so are we (this arbitrariness is the reason for
581 // deprecating this function)
583 // Some apps (such as dialog editors) depend on an empty sizer still
584 // being laid out correctly and reporting the correct size and position.
585 if (m_sizer
->GetChildren().GetCount() == 0)
588 for ( wxSizerItemList::compatibility_iterator
589 node
= m_sizer
->GetChildren().GetFirst();
591 node
= node
->GetNext() )
593 if ( node
->GetData()->IsShown() )
600 return m_spacer
->IsShown();
604 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
610 #if WXWIN_COMPATIBILITY_2_6
611 void wxSizerItem::SetOption( int option
)
613 SetProportion( option
);
616 int wxSizerItem::GetOption() const
618 return GetProportion();
620 #endif // WXWIN_COMPATIBILITY_2_6
623 //---------------------------------------------------------------------------
625 //---------------------------------------------------------------------------
629 WX_CLEAR_LIST(wxSizerItemList
, m_children
);
632 wxSizerItem
* wxSizer::Insert( size_t index
, wxSizerItem
*item
)
634 m_children
.Insert( index
, item
);
636 if ( item
->GetWindow() )
637 item
->GetWindow()->SetContainingSizer( this );
639 if ( item
->GetSizer() )
640 item
->GetSizer()->SetContainingWindow( m_containingWindow
);
645 void wxSizer::SetContainingWindow(wxWindow
*win
)
647 if ( win
== m_containingWindow
)
650 m_containingWindow
= win
;
652 // set the same window for all nested sizers as well, they also are in the
654 for ( wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
656 node
= node
->GetNext() )
658 wxSizerItem
*const item
= node
->GetData();
659 wxSizer
*const sizer
= item
->GetSizer();
663 sizer
->SetContainingWindow(win
);
668 #if WXWIN_COMPATIBILITY_2_6
669 bool wxSizer::Remove( wxWindow
*window
)
671 return Detach( window
);
673 #endif // WXWIN_COMPATIBILITY_2_6
675 bool wxSizer::Remove( wxSizer
*sizer
)
677 wxASSERT_MSG( sizer
, _T("Removing NULL sizer") );
679 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
682 wxSizerItem
*item
= node
->GetData();
684 if (item
->GetSizer() == sizer
)
687 m_children
.Erase( node
);
691 node
= node
->GetNext();
697 bool wxSizer::Remove( int index
)
699 wxCHECK_MSG( index
>= 0 && (size_t)index
< m_children
.GetCount(),
701 _T("Remove index is out of range") );
703 wxSizerItemList::compatibility_iterator node
= m_children
.Item( index
);
705 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
707 delete node
->GetData();
708 m_children
.Erase( node
);
713 bool wxSizer::Detach( wxSizer
*sizer
)
715 wxASSERT_MSG( sizer
, _T("Detaching NULL sizer") );
717 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
720 wxSizerItem
*item
= node
->GetData();
722 if (item
->GetSizer() == sizer
)
726 m_children
.Erase( node
);
729 node
= node
->GetNext();
735 bool wxSizer::Detach( wxWindow
*window
)
737 wxASSERT_MSG( window
, _T("Detaching NULL window") );
739 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
742 wxSizerItem
*item
= node
->GetData();
744 if (item
->GetWindow() == window
)
747 m_children
.Erase( node
);
750 node
= node
->GetNext();
756 bool wxSizer::Detach( int index
)
758 wxCHECK_MSG( index
>= 0 && (size_t)index
< m_children
.GetCount(),
760 _T("Detach index is out of range") );
762 wxSizerItemList::compatibility_iterator node
= m_children
.Item( index
);
764 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
766 wxSizerItem
*item
= node
->GetData();
768 if ( item
->IsSizer() )
772 m_children
.Erase( node
);
776 bool wxSizer::Replace( wxWindow
*oldwin
, wxWindow
*newwin
, bool recursive
)
778 wxASSERT_MSG( oldwin
, _T("Replacing NULL window") );
779 wxASSERT_MSG( newwin
, _T("Replacing with NULL window") );
781 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
784 wxSizerItem
*item
= node
->GetData();
786 if (item
->GetWindow() == oldwin
)
788 item
->AssignWindow(newwin
);
789 newwin
->SetContainingSizer( this );
792 else if (recursive
&& item
->IsSizer())
794 if (item
->GetSizer()->Replace( oldwin
, newwin
, true ))
798 node
= node
->GetNext();
804 bool wxSizer::Replace( wxSizer
*oldsz
, wxSizer
*newsz
, bool recursive
)
806 wxASSERT_MSG( oldsz
, _T("Replacing NULL sizer") );
807 wxASSERT_MSG( newsz
, _T("Replacing with NULL sizer") );
809 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
812 wxSizerItem
*item
= node
->GetData();
814 if (item
->GetSizer() == oldsz
)
816 item
->AssignSizer(newsz
);
819 else if (recursive
&& item
->IsSizer())
821 if (item
->GetSizer()->Replace( oldsz
, newsz
, true ))
825 node
= node
->GetNext();
831 bool wxSizer::Replace( size_t old
, wxSizerItem
*newitem
)
833 wxCHECK_MSG( old
< m_children
.GetCount(), false, _T("Replace index is out of range") );
834 wxASSERT_MSG( newitem
, _T("Replacing with NULL item") );
836 wxSizerItemList::compatibility_iterator node
= m_children
.Item( old
);
838 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
840 wxSizerItem
*item
= node
->GetData();
841 node
->SetData(newitem
);
847 void wxSizer::Clear( bool delete_windows
)
849 // First clear the ContainingSizer pointers
850 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
853 wxSizerItem
*item
= node
->GetData();
855 if (item
->IsWindow())
856 item
->GetWindow()->SetContainingSizer( NULL
);
857 node
= node
->GetNext();
860 // Destroy the windows if needed
864 // Now empty the list
865 WX_CLEAR_LIST(wxSizerItemList
, m_children
);
868 void wxSizer::DeleteWindows()
870 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
873 wxSizerItem
*item
= node
->GetData();
875 item
->DeleteWindows();
876 node
= node
->GetNext();
880 wxSize
wxSizer::ComputeFittingClientSize(wxWindow
*window
)
882 wxCHECK_MSG( window
, wxDefaultSize
, "window can't be NULL" );
884 // take the min size by default and limit it by max size
885 wxSize size
= GetMinClientSize(window
);
888 wxTopLevelWindow
*tlw
= wxDynamicCast(window
, wxTopLevelWindow
);
891 // hack for small screen devices where TLWs are always full screen
892 if ( tlw
->IsAlwaysMaximized() )
894 return tlw
->GetClientSize();
897 // limit the window to the size of the display it is on
898 int disp
= wxDisplay::GetFromWindow(window
);
899 if ( disp
== wxNOT_FOUND
)
901 // or, if we don't know which one it is, of the main one
905 sizeMax
= wxDisplay(disp
).GetClientArea().GetSize();
907 // space for decorations and toolbars etc.
908 sizeMax
= tlw
->WindowToClientSize(sizeMax
);
912 sizeMax
= GetMaxClientSize(window
);
915 if ( sizeMax
.x
!= wxDefaultCoord
&& size
.x
> sizeMax
.x
)
917 if ( sizeMax
.y
!= wxDefaultCoord
&& size
.y
> sizeMax
.y
)
923 wxSize
wxSizer::ComputeFittingWindowSize(wxWindow
*window
)
925 wxCHECK_MSG( window
, wxDefaultSize
, "window can't be NULL" );
927 return window
->ClientToWindowSize(ComputeFittingClientSize(window
));
930 wxSize
wxSizer::Fit( wxWindow
*window
)
932 wxCHECK_MSG( window
, wxDefaultSize
, "window can't be NULL" );
935 window
->SetClientSize(ComputeFittingClientSize(window
));
937 // return entire size
938 return window
->GetSize();
941 void wxSizer::FitInside( wxWindow
*window
)
944 if (window
->IsTopLevel())
945 size
= VirtualFitSize( window
);
947 size
= GetMinClientSize( window
);
949 window
->SetVirtualSize( size
);
952 void wxSizer::Layout()
954 // (re)calculates minimums needed for each item and other preparations
958 // Applies the layout and repositions/resizes the items
962 void wxSizer::SetSizeHints( wxWindow
*window
)
964 // Preserve the window's max size hints, but set the
965 // lower bound according to the sizer calculations.
967 // This is equivalent to calling Fit(), except that we need to set
968 // the size hints _in between_ the two steps performed by Fit
969 // (1. ComputeFittingClientSize, 2. SetClientSize). That's because
970 // otherwise SetClientSize() could have no effect if there already are
971 // size hints in effect that forbid requested client size.
973 const wxSize clientSize
= ComputeFittingClientSize(window
);
975 window
->SetMinClientSize(clientSize
);
976 window
->SetClientSize(clientSize
);
979 #if WXWIN_COMPATIBILITY_2_8
980 void wxSizer::SetVirtualSizeHints( wxWindow
*window
)
984 #endif // WXWIN_COMPATIBILITY_2_8
986 // TODO on mac we need a function that determines how much free space this
987 // min size contains, in order to make sure that we have 20 pixels of free
988 // space around the controls
989 wxSize
wxSizer::GetMaxClientSize( wxWindow
*window
) const
991 return window
->WindowToClientSize(window
->GetMaxSize());
994 wxSize
wxSizer::GetMinClientSize( wxWindow
*WXUNUSED(window
) )
996 return GetMinSize(); // Already returns client size.
999 wxSize
wxSizer::VirtualFitSize( wxWindow
*window
)
1001 wxSize size
= GetMinClientSize( window
);
1002 wxSize sizeMax
= GetMaxClientSize( window
);
1004 // Limit the size if sizeMax != wxDefaultSize
1006 if ( size
.x
> sizeMax
.x
&& sizeMax
.x
!= wxDefaultCoord
)
1008 if ( size
.y
> sizeMax
.y
&& sizeMax
.y
!= wxDefaultCoord
)
1014 wxSize
wxSizer::GetMinSize()
1016 wxSize
ret( CalcMin() );
1017 if (ret
.x
< m_minSize
.x
) ret
.x
= m_minSize
.x
;
1018 if (ret
.y
< m_minSize
.y
) ret
.y
= m_minSize
.y
;
1022 void wxSizer::DoSetMinSize( int width
, int height
)
1024 m_minSize
.x
= width
;
1025 m_minSize
.y
= height
;
1028 bool wxSizer::DoSetItemMinSize( wxWindow
*window
, int width
, int height
)
1030 wxASSERT_MSG( window
, _T("SetMinSize for NULL window") );
1032 // Is it our immediate child?
1034 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1037 wxSizerItem
*item
= node
->GetData();
1039 if (item
->GetWindow() == window
)
1041 item
->SetMinSize( width
, height
);
1044 node
= node
->GetNext();
1047 // No? Search any subsizers we own then
1049 node
= m_children
.GetFirst();
1052 wxSizerItem
*item
= node
->GetData();
1054 if ( item
->GetSizer() &&
1055 item
->GetSizer()->DoSetItemMinSize( window
, width
, height
) )
1057 // A child sizer found the requested windw, exit.
1060 node
= node
->GetNext();
1066 bool wxSizer::DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
)
1068 wxASSERT_MSG( sizer
, _T("SetMinSize for NULL sizer") );
1070 // Is it our immediate child?
1072 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1075 wxSizerItem
*item
= node
->GetData();
1077 if (item
->GetSizer() == sizer
)
1079 item
->GetSizer()->DoSetMinSize( width
, height
);
1082 node
= node
->GetNext();
1085 // No? Search any subsizers we own then
1087 node
= m_children
.GetFirst();
1090 wxSizerItem
*item
= node
->GetData();
1092 if ( item
->GetSizer() &&
1093 item
->GetSizer()->DoSetItemMinSize( sizer
, width
, height
) )
1095 // A child found the requested sizer, exit.
1098 node
= node
->GetNext();
1104 bool wxSizer::DoSetItemMinSize( size_t index
, int width
, int height
)
1106 wxSizerItemList::compatibility_iterator node
= m_children
.Item( index
);
1108 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
1110 wxSizerItem
*item
= node
->GetData();
1112 if (item
->GetSizer())
1114 // Sizers contains the minimal size in them, if not calculated ...
1115 item
->GetSizer()->DoSetMinSize( width
, height
);
1119 // ... but the minimal size of spacers and windows is stored via the item
1120 item
->SetMinSize( width
, height
);
1126 wxSizerItem
* wxSizer::GetItem( wxWindow
*window
, bool recursive
)
1128 wxASSERT_MSG( window
, _T("GetItem for NULL window") );
1130 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1133 wxSizerItem
*item
= node
->GetData();
1135 if (item
->GetWindow() == window
)
1139 else if (recursive
&& item
->IsSizer())
1141 wxSizerItem
*subitem
= item
->GetSizer()->GetItem( window
, true );
1146 node
= node
->GetNext();
1152 wxSizerItem
* wxSizer::GetItem( wxSizer
*sizer
, bool recursive
)
1154 wxASSERT_MSG( sizer
, _T("GetItem for NULL sizer") );
1156 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1159 wxSizerItem
*item
= node
->GetData();
1161 if (item
->GetSizer() == sizer
)
1165 else if (recursive
&& item
->IsSizer())
1167 wxSizerItem
*subitem
= item
->GetSizer()->GetItem( sizer
, true );
1172 node
= node
->GetNext();
1178 wxSizerItem
* wxSizer::GetItem( size_t index
)
1180 wxCHECK_MSG( index
< m_children
.GetCount(),
1182 _T("GetItem index is out of range") );
1184 return m_children
.Item( index
)->GetData();
1187 wxSizerItem
* wxSizer::GetItemById( int id
, bool recursive
)
1189 // This gets a sizer item by the id of the sizer item
1190 // and NOT the id of a window if the item is a window.
1192 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1195 wxSizerItem
*item
= node
->GetData();
1197 if (item
->GetId() == id
)
1201 else if (recursive
&& item
->IsSizer())
1203 wxSizerItem
*subitem
= item
->GetSizer()->GetItemById( id
, true );
1208 node
= node
->GetNext();
1214 bool wxSizer::Show( wxWindow
*window
, bool show
, bool recursive
)
1216 wxSizerItem
*item
= GetItem( window
, recursive
);
1227 bool wxSizer::Show( wxSizer
*sizer
, bool show
, bool recursive
)
1229 wxSizerItem
*item
= GetItem( sizer
, recursive
);
1240 bool wxSizer::Show( size_t index
, bool show
)
1242 wxSizerItem
*item
= GetItem( index
);
1253 void wxSizer::ShowItems( bool show
)
1255 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1258 node
->GetData()->Show( show
);
1259 node
= node
->GetNext();
1263 bool wxSizer::IsShown( wxWindow
*window
) const
1265 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1268 wxSizerItem
*item
= node
->GetData();
1270 if (item
->GetWindow() == window
)
1272 return item
->IsShown();
1274 node
= node
->GetNext();
1277 wxFAIL_MSG( _T("IsShown failed to find sizer item") );
1282 bool wxSizer::IsShown( wxSizer
*sizer
) const
1284 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1287 wxSizerItem
*item
= node
->GetData();
1289 if (item
->GetSizer() == sizer
)
1291 return item
->IsShown();
1293 node
= node
->GetNext();
1296 wxFAIL_MSG( _T("IsShown failed to find sizer item") );
1301 bool wxSizer::IsShown( size_t index
) const
1303 wxCHECK_MSG( index
< m_children
.GetCount(),
1305 _T("IsShown index is out of range") );
1307 return m_children
.Item( index
)->GetData()->IsShown();
1311 //---------------------------------------------------------------------------
1313 //---------------------------------------------------------------------------
1315 wxGridSizer::wxGridSizer( int rows
, int cols
, int vgap
, int hgap
)
1316 : m_rows( ( cols
== 0 && rows
== 0 ) ? 1 : rows
)
1323 wxGridSizer::wxGridSizer( int cols
, int vgap
, int hgap
)
1324 : m_rows( cols
== 0 ? 1 : 0 )
1331 int wxGridSizer::CalcRowsCols(int& nrows
, int& ncols
) const
1333 const int nitems
= m_children
.GetCount();
1334 if ( m_cols
&& m_rows
)
1336 // if both rows and columns are specified by user, use the provided
1337 // values even if we don't have enough items but check that we don't
1338 // have too many of them as this is going to result in problems later
1342 wxASSERT_MSG( ncols
*nrows
>= nitems
, "too many items in grid sizer" );
1347 nrows
= (nitems
+ m_cols
- 1) / m_cols
;
1351 ncols
= (nitems
+ m_rows
- 1) / m_rows
;
1354 else // 0 columns, 0 rows?
1356 wxFAIL_MSG( _T("grid sizer must have either rows or columns fixed") );
1365 void wxGridSizer::RecalcSizes()
1367 int nitems
, nrows
, ncols
;
1368 if ( (nitems
= CalcRowsCols(nrows
, ncols
)) == 0 )
1371 wxSize
sz( GetSize() );
1372 wxPoint
pt( GetPosition() );
1374 int w
= (sz
.x
- (ncols
- 1) * m_hgap
) / ncols
;
1375 int h
= (sz
.y
- (nrows
- 1) * m_vgap
) / nrows
;
1378 for (int c
= 0; c
< ncols
; c
++)
1381 for (int r
= 0; r
< nrows
; r
++)
1383 int i
= r
* ncols
+ c
;
1386 wxSizerItemList::compatibility_iterator node
= m_children
.Item( i
);
1388 wxASSERT_MSG( node
, _T("Failed to find SizerItemList node") );
1390 SetItemBounds( node
->GetData(), x
, y
, w
, h
);
1398 wxSize
wxGridSizer::CalcMin()
1401 if ( CalcRowsCols(nrows
, ncols
) == 0 )
1404 // Find the max width and height for any component
1408 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1411 wxSizerItem
*item
= node
->GetData();
1412 wxSize
sz( item
->CalcMin() );
1414 w
= wxMax( w
, sz
.x
);
1415 h
= wxMax( h
, sz
.y
);
1417 node
= node
->GetNext();
1420 // In case we have a nested sizer with a two step algo , give it
1421 // a chance to adjust to that (we give it width component)
1422 node
= m_children
.GetFirst();
1423 bool didChangeMinSize
= false;
1426 wxSizerItem
*item
= node
->GetData();
1427 didChangeMinSize
|= item
->InformFirstDirection( wxHORIZONTAL
, w
, -1 );
1429 node
= node
->GetNext();
1432 // And redo iteration in case min size changed
1433 if( didChangeMinSize
)
1435 node
= m_children
.GetFirst();
1439 wxSizerItem
*item
= node
->GetData();
1440 wxSize
sz( item
->GetMinSizeWithBorder() );
1442 w
= wxMax( w
, sz
.x
);
1443 h
= wxMax( h
, sz
.y
);
1445 node
= node
->GetNext();
1449 return wxSize( ncols
* w
+ (ncols
-1) * m_hgap
,
1450 nrows
* h
+ (nrows
-1) * m_vgap
);
1453 void wxGridSizer::SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
)
1456 wxSize
sz( item
->GetMinSizeWithBorder() );
1457 int flag
= item
->GetFlag();
1459 if ((flag
& wxEXPAND
) || (flag
& wxSHAPED
))
1465 if (flag
& wxALIGN_CENTER_HORIZONTAL
)
1467 pt
.x
= x
+ (w
- sz
.x
) / 2;
1469 else if (flag
& wxALIGN_RIGHT
)
1471 pt
.x
= x
+ (w
- sz
.x
);
1474 if (flag
& wxALIGN_CENTER_VERTICAL
)
1476 pt
.y
= y
+ (h
- sz
.y
) / 2;
1478 else if (flag
& wxALIGN_BOTTOM
)
1480 pt
.y
= y
+ (h
- sz
.y
);
1484 item
->SetDimension(pt
, sz
);
1487 //---------------------------------------------------------------------------
1489 //---------------------------------------------------------------------------
1491 wxFlexGridSizer::wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
)
1492 : wxGridSizer( rows
, cols
, vgap
, hgap
),
1493 m_flexDirection(wxBOTH
),
1494 m_growMode(wxFLEX_GROWMODE_SPECIFIED
)
1498 wxFlexGridSizer::wxFlexGridSizer( int cols
, int vgap
, int hgap
)
1499 : wxGridSizer( cols
, vgap
, hgap
),
1500 m_flexDirection(wxBOTH
),
1501 m_growMode(wxFLEX_GROWMODE_SPECIFIED
)
1505 wxFlexGridSizer::~wxFlexGridSizer()
1509 void wxFlexGridSizer::RecalcSizes()
1512 if ( !CalcRowsCols(nrows
, ncols
) )
1515 const wxPoint
pt(GetPosition());
1516 const wxSize
sz(GetSize());
1518 AdjustForGrowables(sz
);
1520 wxSizerItemList::const_iterator i
= m_children
.begin();
1521 const wxSizerItemList::const_iterator end
= m_children
.end();
1524 for ( int r
= 0; r
< nrows
; r
++ )
1526 if ( m_rowHeights
[r
] == -1 )
1528 // this row is entirely hidden, skip it
1529 for ( int c
= 0; c
< ncols
; c
++ )
1540 const int hrow
= m_rowHeights
[r
];
1541 int h
= sz
.y
- y
; // max remaining height, don't overflow it
1546 for ( int c
= 0; c
< ncols
&& i
!= end
; c
++, ++i
)
1548 const int wcol
= m_colWidths
[c
];
1553 int w
= sz
.x
- x
; // max possible value, ensure we don't overflow
1557 SetItemBounds(*i
, pt
.x
+ x
, pt
.y
+ y
, w
, h
);
1569 // helper function used in CalcMin() to sum up the sizes of non-hidden items
1570 static int SumArraySizes(const wxArrayInt
& sizes
, int gap
)
1572 // Sum total minimum size, including gaps between rows/columns.
1573 // -1 is used as a magic number meaning empty row/column.
1576 const size_t count
= sizes
.size();
1577 for ( size_t n
= 0; n
< count
; n
++ )
1579 if ( sizes
[n
] != -1 )
1582 total
+= gap
; // separate from the previous column
1591 void wxFlexGridSizer::FindWidthsAndHeights(int nrows
, int ncols
)
1593 // We have to recalculate the sizes in case the item minimum size has
1594 // changed since the previous layout, or the item has been hidden using
1595 // wxSizer::Show(). If all the items in a row/column are hidden, the final
1596 // dimension of the row/column will be -1, indicating that the column
1597 // itself is hidden.
1598 m_rowHeights
.assign(nrows
, -1);
1599 m_colWidths
.assign(ncols
, -1);
1601 // n is the index of the item in left-to-right top-to-bottom order
1603 for ( wxSizerItemList::iterator i
= m_children
.begin();
1604 i
!= m_children
.end();
1607 wxSizerItem
* const item
= *i
;
1608 if ( item
->IsShown() )
1610 // NOTE: Not doing the calculation here, this is just
1611 // for finding max values.
1612 const wxSize
sz(item
->GetMinSizeWithBorder());
1614 const int row
= n
/ ncols
;
1615 const int col
= n
% ncols
;
1617 if ( sz
.y
> m_rowHeights
[row
] )
1618 m_rowHeights
[row
] = sz
.y
;
1619 if ( sz
.x
> m_colWidths
[col
] )
1620 m_colWidths
[col
] = sz
.x
;
1624 AdjustForFlexDirection();
1626 m_calculatedMinSize
= wxSize(SumArraySizes(m_colWidths
, m_hgap
),
1627 SumArraySizes(m_rowHeights
, m_vgap
));
1630 wxSize
wxFlexGridSizer::CalcMin()
1635 // Number of rows/columns can change as items are added or removed.
1636 if ( !CalcRowsCols(nrows
, ncols
) )
1640 // We have to recalculate the sizes in case the item minimum size has
1641 // changed since the previous layout, or the item has been hidden using
1642 // wxSizer::Show(). If all the items in a row/column are hidden, the final
1643 // dimension of the row/column will be -1, indicating that the column
1644 // itself is hidden.
1645 m_rowHeights
.assign(nrows
, -1);
1646 m_colWidths
.assign(ncols
, -1);
1648 for ( wxSizerItemList::iterator i
= m_children
.begin();
1649 i
!= m_children
.end();
1652 wxSizerItem
* const item
= *i
;
1653 if ( item
->IsShown() )
1659 // The stage of looking for max values in each row/column has been
1660 // made a separate function, since it's reused in AdjustForGrowables.
1661 FindWidthsAndHeights(nrows
,ncols
);
1663 return m_calculatedMinSize
;
1666 void wxFlexGridSizer::AdjustForFlexDirection()
1668 // the logic in CalcMin works when we resize flexibly in both directions
1669 // but maybe this is not the case
1670 if ( m_flexDirection
!= wxBOTH
)
1672 // select the array corresponding to the direction in which we do *not*
1674 wxArrayInt
& array
= m_flexDirection
== wxVERTICAL
? m_colWidths
1677 const size_t count
= array
.GetCount();
1679 // find the largest value in this array
1683 for ( n
= 0; n
< count
; ++n
)
1685 if ( array
[n
] > largest
)
1689 // and now fill it with the largest value
1690 for ( n
= 0; n
< count
; ++n
)
1692 // don't touch hidden rows
1693 if ( array
[n
] != -1 )
1699 // helper of AdjustForGrowables() which is called for rows/columns separately
1702 // delta: the extra space, we do nothing unless it's positive
1703 // growable: indices or growable rows/cols in sizes array
1704 // sizes: the height/widths of rows/cols to adjust
1705 // proportions: proportions of the growable rows/cols or NULL if they all
1706 // should be assumed to have proportion of 1
1708 DoAdjustForGrowables(int delta
,
1709 const wxArrayInt
& growable
,
1711 const wxArrayInt
*proportions
)
1716 // total sum of proportions of all non-hidden rows
1717 int sum_proportions
= 0;
1719 // number of currently shown growable rows
1722 const int max_idx
= sizes
.size();
1724 const size_t count
= growable
.size();
1726 for ( idx
= 0; idx
< count
; idx
++ )
1728 // Since the number of rows/columns can change as items are
1729 // inserted/deleted, we need to verify at runtime that the
1730 // requested growable rows/columns are still valid.
1731 if ( growable
[idx
] >= max_idx
)
1734 // If all items in a row/column are hidden, that row/column will
1735 // have a dimension of -1. This causes the row/column to be
1736 // hidden completely.
1737 if ( sizes
[growable
[idx
]] == -1 )
1741 sum_proportions
+= (*proportions
)[idx
];
1749 // the remaining extra free space, adjusted during each iteration
1750 for ( idx
= 0; idx
< count
; idx
++ )
1752 if ( growable
[idx
] >= max_idx
)
1755 if ( sizes
[ growable
[idx
] ] == -1 )
1759 if ( sum_proportions
== 0 )
1761 // no growable rows -- divide extra space evenly among all
1762 cur_delta
= delta
/num
;
1765 else // allocate extra space proportionally
1767 const int cur_prop
= (*proportions
)[idx
];
1768 cur_delta
= (delta
*cur_prop
)/sum_proportions
;
1769 sum_proportions
-= cur_prop
;
1772 sizes
[growable
[idx
]] += cur_delta
;
1777 void wxFlexGridSizer::AdjustForGrowables(const wxSize
& sz
)
1779 if ( (m_flexDirection
& wxHORIZONTAL
) || (m_growMode
!= wxFLEX_GROWMODE_NONE
) )
1781 DoAdjustForGrowables
1783 sz
.x
- m_calculatedMinSize
.x
,
1786 m_growMode
== wxFLEX_GROWMODE_SPECIFIED
? &m_growableColsProportions
1790 // This gives nested objects that benefit from knowing one size
1791 // component in advance the chance to use that.
1792 bool didAdjustMinSize
= false;
1794 CalcRowsCols(nrows
, ncols
);
1796 // Iterate over all items and inform about column width
1798 for ( wxSizerItemList::iterator i
= m_children
.begin();
1799 i
!= m_children
.end();
1802 const int col
= n
% ncols
;
1803 didAdjustMinSize
|= (*i
)->InformFirstDirection(wxHORIZONTAL
, m_colWidths
[col
], sz
.y
- m_calculatedMinSize
.y
);
1806 // Only redo if info was actually used
1807 if( didAdjustMinSize
)
1809 DoAdjustForGrowables
1811 sz
.x
- m_calculatedMinSize
.x
,
1814 m_growMode
== wxFLEX_GROWMODE_SPECIFIED
? &m_growableColsProportions
1820 if ( (m_flexDirection
& wxVERTICAL
) || (m_growMode
!= wxFLEX_GROWMODE_NONE
) )
1822 // pass NULL instead of proportions if the grow mode is ALL as we
1823 // should treat all rows as having proportion of 1 then
1824 DoAdjustForGrowables
1826 sz
.y
- m_calculatedMinSize
.y
,
1829 m_growMode
== wxFLEX_GROWMODE_SPECIFIED
? &m_growableRowsProportions
1835 bool wxFlexGridSizer::IsRowGrowable( size_t idx
)
1837 return m_growableRows
.Index( idx
) != wxNOT_FOUND
;
1840 bool wxFlexGridSizer::IsColGrowable( size_t idx
)
1842 return m_growableCols
.Index( idx
) != wxNOT_FOUND
;
1845 void wxFlexGridSizer::AddGrowableRow( size_t idx
, int proportion
)
1848 CalcRowsCols(nrows
, ncols
);
1849 wxCHECK_RET( idx
< (size_t)nrows
, "invalid row index" );
1851 wxASSERT_MSG( !IsRowGrowable( idx
),
1852 "AddGrowableRow() called for growable row" );
1853 m_growableRows
.Add( idx
);
1854 m_growableRowsProportions
.Add( proportion
);
1857 void wxFlexGridSizer::AddGrowableCol( size_t idx
, int proportion
)
1860 CalcRowsCols(nrows
, ncols
);
1861 wxCHECK_RET( idx
< (size_t)ncols
, "invalid column index" );
1863 wxASSERT_MSG( !IsColGrowable( idx
),
1864 "AddGrowableCol() called for growable column" );
1865 m_growableCols
.Add( idx
);
1866 m_growableColsProportions
.Add( proportion
);
1869 // helper function for RemoveGrowableCol/Row()
1871 DoRemoveFromArrays(size_t idx
, wxArrayInt
& items
, wxArrayInt
& proportions
)
1873 const size_t count
= items
.size();
1874 for ( size_t n
= 0; n
< count
; n
++ )
1876 if ( (size_t)items
[n
] == idx
)
1879 proportions
.RemoveAt(n
);
1884 wxFAIL_MSG( _T("column/row is already not growable") );
1887 void wxFlexGridSizer::RemoveGrowableCol( size_t idx
)
1889 DoRemoveFromArrays(idx
, m_growableCols
, m_growableColsProportions
);
1892 void wxFlexGridSizer::RemoveGrowableRow( size_t idx
)
1894 DoRemoveFromArrays(idx
, m_growableRows
, m_growableRowsProportions
);
1897 //---------------------------------------------------------------------------
1899 //---------------------------------------------------------------------------
1901 void wxBoxSizer::RecalcSizes()
1903 if ( m_children
.empty() )
1906 const wxCoord totalMinorSize
= GetSizeInMinorDir(m_size
);
1908 // the amount of free space which we should redistribute among the
1909 // stretchable items (i.e. those with non zero proportion)
1910 int delta
= GetSizeInMajorDir(m_size
) - GetSizeInMajorDir(m_minSize
);
1913 // Inform child items about the size in minor direction, that can
1914 // change how much free space we have in major dir and how to distribute it.
1915 int majorMinSum
= 0;
1916 wxSizerItemList::const_iterator i
;
1917 for ( i
= m_children
.begin();
1918 i
!= m_children
.end();
1921 wxSizerItem
* const item
= *i
;
1923 if ( !item
->IsShown() )
1926 wxSize szMinPrev
= item
->GetMinSizeWithBorder();
1927 item
->InformFirstDirection(m_orient
^wxBOTH
,totalMinorSize
,delta
);
1928 wxSize szMin
= item
->GetMinSizeWithBorder();
1929 int deltaChange
= GetSizeInMajorDir(szMin
-szMinPrev
);
1932 // Since we passed available space along to the item, it should not
1933 // take too much, so delta should not become negative.
1934 delta
-= deltaChange
;
1936 majorMinSum
+= GetSizeInMajorDir(item
->GetMinSizeWithBorder());
1938 // And update our min size
1939 SizeInMajorDir(m_minSize
) = majorMinSum
;
1942 // might have a new delta now
1943 delta
= GetSizeInMajorDir(m_size
) - GetSizeInMajorDir(m_minSize
);
1945 // the position at which we put the next child
1946 wxPoint
pt(m_position
);
1948 int totalProportion
= m_totalProportion
;
1949 for ( i
= m_children
.begin();
1950 i
!= m_children
.end();
1953 wxSizerItem
* const item
= *i
;
1955 if ( !item
->IsShown() )
1958 const wxSize
sizeThis(item
->GetMinSizeWithBorder());
1960 // adjust the size in the major direction using the proportion
1961 wxCoord majorSize
= GetSizeInMajorDir(sizeThis
);
1963 // if there is not enough space, don't try to distribute negative space
1964 // among the children, this would result in overlapping windows which
1968 const int propItem
= item
->GetProportion();
1971 const int deltaItem
= (delta
* propItem
) / totalProportion
;
1973 majorSize
+= deltaItem
;
1976 totalProportion
-= propItem
;
1981 // apply the alignment in the minor direction
1982 wxPoint
posChild(pt
);
1984 wxCoord minorSize
= GetSizeInMinorDir(sizeThis
);
1985 const int flag
= item
->GetFlag();
1986 if ( flag
& (wxEXPAND
| wxSHAPED
) )
1988 minorSize
= totalMinorSize
;
1990 else if ( flag
& (IsVertical() ? wxALIGN_RIGHT
: wxALIGN_BOTTOM
) )
1992 PosInMinorDir(posChild
) += totalMinorSize
- minorSize
;
1994 // NB: wxCENTRE is used here only for backwards compatibility,
1995 // wxALIGN_CENTRE should be used in new code
1996 else if ( flag
& (wxCENTER
| (IsVertical() ? wxALIGN_CENTRE_HORIZONTAL
: wxALIGN_CENTRE_VERTICAL
)))
1998 PosInMinorDir(posChild
) += (totalMinorSize
- minorSize
) / 2;
2002 // apply RTL adjustment for horizontal sizers:
2003 if ( !IsVertical() && m_containingWindow
)
2005 posChild
.x
= m_containingWindow
->AdjustForLayoutDirection
2013 // finally set size of this child and advance to the next one
2014 item
->SetDimension(posChild
, SizeFromMajorMinor(majorSize
, minorSize
));
2016 PosInMajorDir(pt
) += majorSize
;
2020 wxSize
wxBoxSizer::CalcMin()
2022 m_totalProportion
= 0;
2023 m_minSize
= wxSize(0, 0);
2025 // calculate the minimal sizes for all items and count sum of proportions
2026 for ( wxSizerItemList::const_iterator i
= m_children
.begin();
2027 i
!= m_children
.end();
2030 wxSizerItem
* const item
= *i
;
2032 if ( !item
->IsShown() )
2035 const wxSize sizeMinThis
= item
->CalcMin();
2036 SizeInMajorDir(m_minSize
) += GetSizeInMajorDir(sizeMinThis
);
2037 if ( GetSizeInMinorDir(sizeMinThis
) > GetSizeInMinorDir(m_minSize
) )
2038 SizeInMinorDir(m_minSize
) = GetSizeInMinorDir(sizeMinThis
);
2040 m_totalProportion
+= item
->GetProportion();
2046 //---------------------------------------------------------------------------
2048 //---------------------------------------------------------------------------
2052 wxStaticBoxSizer::wxStaticBoxSizer( wxStaticBox
*box
, int orient
)
2053 : wxBoxSizer( orient
),
2056 wxASSERT_MSG( box
, wxT("wxStaticBoxSizer needs a static box") );
2058 // do this so that our Detach() is called if the static box is destroyed
2060 m_staticBox
->SetContainingSizer(this);
2063 wxStaticBoxSizer::wxStaticBoxSizer(int orient
, wxWindow
*win
, const wxString
& s
)
2064 : wxBoxSizer(orient
),
2065 m_staticBox(new wxStaticBox(win
, wxID_ANY
, s
))
2068 m_staticBox
->SetContainingSizer(this);
2071 wxStaticBoxSizer::~wxStaticBoxSizer()
2076 static void GetStaticBoxBorders( wxStaticBox
*box
,
2080 // this has to be done platform by platform as there is no way to
2081 // guess the thickness of a wxStaticBox border
2082 box
->GetBordersForSizer(borderTop
, borderOther
);
2085 void wxStaticBoxSizer::RecalcSizes()
2087 int top_border
, other_border
;
2088 GetStaticBoxBorders(m_staticBox
, &top_border
, &other_border
);
2090 m_staticBox
->SetSize( m_position
.x
, m_position
.y
, m_size
.x
, m_size
.y
);
2092 wxPoint
old_pos( m_position
);
2093 m_position
.x
+= other_border
;
2094 m_position
.y
+= top_border
;
2095 wxSize
old_size( m_size
);
2096 m_size
.x
-= 2*other_border
;
2097 m_size
.y
-= top_border
+ other_border
;
2099 wxBoxSizer::RecalcSizes();
2101 m_position
= old_pos
;
2105 wxSize
wxStaticBoxSizer::CalcMin()
2107 int top_border
, other_border
;
2108 GetStaticBoxBorders(m_staticBox
, &top_border
, &other_border
);
2110 wxSize
ret( wxBoxSizer::CalcMin() );
2111 ret
.x
+= 2*other_border
;
2112 ret
.y
+= other_border
+ top_border
;
2117 void wxStaticBoxSizer::ShowItems( bool show
)
2119 m_staticBox
->Show( show
);
2120 wxBoxSizer::ShowItems( show
);
2123 bool wxStaticBoxSizer::Detach( wxWindow
*window
)
2125 // avoid deleting m_staticBox in our dtor if it's being detached from the
2126 // sizer (which can happen because it's being already destroyed for
2128 if ( window
== m_staticBox
)
2134 return wxSizer::Detach( window
);
2137 #endif // wxUSE_STATBOX
2141 wxStdDialogButtonSizer::wxStdDialogButtonSizer()
2142 : wxBoxSizer(wxHORIZONTAL
)
2144 // Vertical buttons with lots of space on either side
2145 // looks rubbish on WinCE, so let's not do this for now.
2146 // If we are going to use vertical buttons, we should
2147 // put the sizer to the right of other controls in the dialog,
2148 // and that's beyond the scope of this sizer.
2150 bool is_pda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
2151 // If we have a PDA screen, put yes/no button over
2152 // all other buttons, otherwise on the left side.
2154 m_orient
= wxVERTICAL
;
2157 m_buttonAffirmative
= NULL
;
2158 m_buttonApply
= NULL
;
2159 m_buttonNegative
= NULL
;
2160 m_buttonCancel
= NULL
;
2161 m_buttonHelp
= NULL
;
2164 void wxStdDialogButtonSizer::AddButton(wxButton
*mybutton
)
2166 switch (mybutton
->GetId())
2171 m_buttonAffirmative
= mybutton
;
2174 m_buttonApply
= mybutton
;
2177 m_buttonNegative
= mybutton
;
2181 m_buttonCancel
= mybutton
;
2184 case wxID_CONTEXT_HELP
:
2185 m_buttonHelp
= mybutton
;
2192 void wxStdDialogButtonSizer::SetAffirmativeButton( wxButton
*button
)
2194 m_buttonAffirmative
= button
;
2197 void wxStdDialogButtonSizer::SetNegativeButton( wxButton
*button
)
2199 m_buttonNegative
= button
;
2202 void wxStdDialogButtonSizer::SetCancelButton( wxButton
*button
)
2204 m_buttonCancel
= button
;
2207 void wxStdDialogButtonSizer::Realize()
2210 Add(0, 0, 0, wxLEFT
, 6);
2212 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 6);
2214 if (m_buttonNegative
){
2215 // HIG POLICE BULLETIN - destructive buttons need extra padding
2216 // 24 pixels on either side
2217 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 12);
2220 // extra whitespace between help/negative and cancel/ok buttons
2221 Add(0, 0, 1, wxEXPAND
, 0);
2223 if (m_buttonCancel
){
2224 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 6);
2225 // Cancel or help should be default
2226 // m_buttonCancel->SetDefaultButton();
2229 // Ugh, Mac doesn't really have apply dialogs, so I'll just
2230 // figure the best place is between Cancel and OK
2232 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 6);
2234 if (m_buttonAffirmative
){
2235 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
, 6);
2237 if (m_buttonAffirmative
->GetId() == wxID_SAVE
){
2238 // these buttons have set labels under Mac so we should use them
2239 m_buttonAffirmative
->SetLabel(_("Save"));
2240 if (m_buttonNegative
)
2241 m_buttonNegative
->SetLabel(_("Don't Save"));
2245 // Extra space around and at the right
2247 #elif defined(__WXGTK20__)
2248 Add(0, 0, 0, wxLEFT
, 9);
2250 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
2252 // extra whitespace between help and cancel/ok buttons
2253 Add(0, 0, 1, wxEXPAND
, 0);
2255 if (m_buttonNegative
){
2256 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
2259 // according to HIG, in explicit apply windows the order is:
2260 // [ Help Apply Cancel OK ]
2262 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
2264 if (m_buttonCancel
){
2265 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
2266 // Cancel or help should be default
2267 // m_buttonCancel->SetDefaultButton();
2270 if (m_buttonAffirmative
)
2271 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
, 6);
2272 #elif defined(__WXMSW__)
2275 // right-justify buttons
2276 Add(0, 0, 1, wxEXPAND
, 0);
2278 if (m_buttonAffirmative
){
2279 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonAffirmative
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2282 if (m_buttonNegative
){
2283 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonNegative
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2286 if (m_buttonCancel
){
2287 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonCancel
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2290 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonApply
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2293 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonHelp
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2295 // GTK+1 and any other platform
2297 // Add(0, 0, 0, wxLEFT, 5); // Not sure what this was for but it unbalances the dialog
2299 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonHelp
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2301 // extra whitespace between help and cancel/ok buttons
2302 Add(0, 0, 1, wxEXPAND
, 0);
2305 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonApply
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2307 if (m_buttonAffirmative
){
2308 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonAffirmative
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2311 if (m_buttonNegative
){
2312 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonNegative
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2315 if (m_buttonCancel
){
2316 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonCancel
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2317 // Cancel or help should be default
2318 // m_buttonCancel->SetDefaultButton();
2324 #endif // wxUSE_BUTTON