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 m_window
->SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
,
485 wxSIZE_ALLOW_MINUS_ONE
|wxSIZE_FORCE_EVENT
);
489 m_sizer
->SetDimension(pos
, size
);
493 m_spacer
->SetSize(size
);
498 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
502 void wxSizerItem::DeleteWindows()
511 //We are deleting the window from this sizer - normally
512 //the window destroys the sizer associated with it,
513 //which might destroy this, which we don't want
514 m_window
->SetContainingSizer(NULL
);
516 //Putting this after the switch will result in a spacer
517 //not being deleted properly on destruction
522 m_sizer
->DeleteWindows();
527 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
532 void wxSizerItem::Show( bool show
)
537 wxFAIL_MSG( _T("can't show uninitialized sizer item") );
541 m_window
->Show(show
);
549 m_spacer
->Show(show
);
554 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
558 bool wxSizerItem::IsShown() const
560 if ( m_flag
& wxRESERVE_SPACE_EVEN_IF_HIDDEN
)
566 // we may be called from CalcMin(), just return false so that we're
571 return m_window
->IsShown();
574 // arbitrarily decide that if at least one of our elements is
575 // shown, so are we (this arbitrariness is the reason for
576 // deprecating this function)
578 // Some apps (such as dialog editors) depend on an empty sizer still
579 // being laid out correctly and reporting the correct size and position.
580 if (m_sizer
->GetChildren().GetCount() == 0)
583 for ( wxSizerItemList::compatibility_iterator
584 node
= m_sizer
->GetChildren().GetFirst();
586 node
= node
->GetNext() )
588 if ( node
->GetData()->IsShown() )
595 return m_spacer
->IsShown();
599 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
605 #if WXWIN_COMPATIBILITY_2_6
606 void wxSizerItem::SetOption( int option
)
608 SetProportion( option
);
611 int wxSizerItem::GetOption() const
613 return GetProportion();
615 #endif // WXWIN_COMPATIBILITY_2_6
618 //---------------------------------------------------------------------------
620 //---------------------------------------------------------------------------
624 WX_CLEAR_LIST(wxSizerItemList
, m_children
);
627 wxSizerItem
* wxSizer::Insert( size_t index
, wxSizerItem
*item
)
629 m_children
.Insert( index
, item
);
631 if ( item
->GetWindow() )
632 item
->GetWindow()->SetContainingSizer( this );
634 if ( item
->GetSizer() )
635 item
->GetSizer()->SetContainingWindow( m_containingWindow
);
640 void wxSizer::SetContainingWindow(wxWindow
*win
)
642 if ( win
== m_containingWindow
)
645 m_containingWindow
= win
;
647 // set the same window for all nested sizers as well, they also are in the
649 for ( wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
651 node
= node
->GetNext() )
653 wxSizerItem
*const item
= node
->GetData();
654 wxSizer
*const sizer
= item
->GetSizer();
658 sizer
->SetContainingWindow(win
);
663 #if WXWIN_COMPATIBILITY_2_6
664 bool wxSizer::Remove( wxWindow
*window
)
666 return Detach( window
);
668 #endif // WXWIN_COMPATIBILITY_2_6
670 bool wxSizer::Remove( wxSizer
*sizer
)
672 wxASSERT_MSG( sizer
, _T("Removing NULL sizer") );
674 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
677 wxSizerItem
*item
= node
->GetData();
679 if (item
->GetSizer() == sizer
)
682 m_children
.Erase( node
);
686 node
= node
->GetNext();
692 bool wxSizer::Remove( int index
)
694 wxCHECK_MSG( index
>= 0 && (size_t)index
< m_children
.GetCount(),
696 _T("Remove index is out of range") );
698 wxSizerItemList::compatibility_iterator node
= m_children
.Item( index
);
700 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
702 delete node
->GetData();
703 m_children
.Erase( node
);
708 bool wxSizer::Detach( wxSizer
*sizer
)
710 wxASSERT_MSG( sizer
, _T("Detaching NULL sizer") );
712 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
715 wxSizerItem
*item
= node
->GetData();
717 if (item
->GetSizer() == sizer
)
721 m_children
.Erase( node
);
724 node
= node
->GetNext();
730 bool wxSizer::Detach( wxWindow
*window
)
732 wxASSERT_MSG( window
, _T("Detaching NULL window") );
734 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
737 wxSizerItem
*item
= node
->GetData();
739 if (item
->GetWindow() == window
)
742 m_children
.Erase( node
);
745 node
= node
->GetNext();
751 bool wxSizer::Detach( int index
)
753 wxCHECK_MSG( index
>= 0 && (size_t)index
< m_children
.GetCount(),
755 _T("Detach index is out of range") );
757 wxSizerItemList::compatibility_iterator node
= m_children
.Item( index
);
759 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
761 wxSizerItem
*item
= node
->GetData();
763 if ( item
->IsSizer() )
767 m_children
.Erase( node
);
771 bool wxSizer::Replace( wxWindow
*oldwin
, wxWindow
*newwin
, bool recursive
)
773 wxASSERT_MSG( oldwin
, _T("Replacing NULL window") );
774 wxASSERT_MSG( newwin
, _T("Replacing with NULL window") );
776 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
779 wxSizerItem
*item
= node
->GetData();
781 if (item
->GetWindow() == oldwin
)
783 item
->AssignWindow(newwin
);
784 newwin
->SetContainingSizer( this );
787 else if (recursive
&& item
->IsSizer())
789 if (item
->GetSizer()->Replace( oldwin
, newwin
, true ))
793 node
= node
->GetNext();
799 bool wxSizer::Replace( wxSizer
*oldsz
, wxSizer
*newsz
, bool recursive
)
801 wxASSERT_MSG( oldsz
, _T("Replacing NULL sizer") );
802 wxASSERT_MSG( newsz
, _T("Replacing with NULL sizer") );
804 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
807 wxSizerItem
*item
= node
->GetData();
809 if (item
->GetSizer() == oldsz
)
811 item
->AssignSizer(newsz
);
814 else if (recursive
&& item
->IsSizer())
816 if (item
->GetSizer()->Replace( oldsz
, newsz
, true ))
820 node
= node
->GetNext();
826 bool wxSizer::Replace( size_t old
, wxSizerItem
*newitem
)
828 wxCHECK_MSG( old
< m_children
.GetCount(), false, _T("Replace index is out of range") );
829 wxASSERT_MSG( newitem
, _T("Replacing with NULL item") );
831 wxSizerItemList::compatibility_iterator node
= m_children
.Item( old
);
833 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
835 wxSizerItem
*item
= node
->GetData();
836 node
->SetData(newitem
);
842 void wxSizer::Clear( bool delete_windows
)
844 // First clear the ContainingSizer pointers
845 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
848 wxSizerItem
*item
= node
->GetData();
850 if (item
->IsWindow())
851 item
->GetWindow()->SetContainingSizer( NULL
);
852 node
= node
->GetNext();
855 // Destroy the windows if needed
859 // Now empty the list
860 WX_CLEAR_LIST(wxSizerItemList
, m_children
);
863 void wxSizer::DeleteWindows()
865 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
868 wxSizerItem
*item
= node
->GetData();
870 item
->DeleteWindows();
871 node
= node
->GetNext();
875 wxSize
wxSizer::ComputeFittingClientSize(wxWindow
*window
)
877 wxCHECK_MSG( window
, wxDefaultSize
, "window can't be NULL" );
879 // take the min size by default and limit it by max size
880 wxSize size
= GetMinClientSize(window
);
883 wxTopLevelWindow
*tlw
= wxDynamicCast(window
, wxTopLevelWindow
);
886 // hack for small screen devices where TLWs are always full screen
887 if ( tlw
->IsAlwaysMaximized() )
889 return tlw
->GetClientSize();
892 // limit the window to the size of the display it is on
893 int disp
= wxDisplay::GetFromWindow(window
);
894 if ( disp
== wxNOT_FOUND
)
896 // or, if we don't know which one it is, of the main one
900 sizeMax
= wxDisplay(disp
).GetClientArea().GetSize();
902 // space for decorations and toolbars etc.
903 sizeMax
= tlw
->WindowToClientSize(sizeMax
);
907 sizeMax
= GetMaxClientSize(window
);
910 if ( sizeMax
.x
!= wxDefaultCoord
&& size
.x
> sizeMax
.x
)
912 if ( sizeMax
.y
!= wxDefaultCoord
&& size
.y
> sizeMax
.y
)
918 wxSize
wxSizer::ComputeFittingWindowSize(wxWindow
*window
)
920 wxCHECK_MSG( window
, wxDefaultSize
, "window can't be NULL" );
922 return window
->ClientToWindowSize(ComputeFittingClientSize(window
));
925 wxSize
wxSizer::Fit( wxWindow
*window
)
927 wxCHECK_MSG( window
, wxDefaultSize
, "window can't be NULL" );
930 window
->SetClientSize(ComputeFittingClientSize(window
));
932 // return entire size
933 return window
->GetSize();
936 void wxSizer::FitInside( wxWindow
*window
)
939 if (window
->IsTopLevel())
940 size
= VirtualFitSize( window
);
942 size
= GetMinClientSize( window
);
944 window
->SetVirtualSize( size
);
947 void wxSizer::Layout()
949 // (re)calculates minimums needed for each item and other preparations
953 // Applies the layout and repositions/resizes the items
957 void wxSizer::SetSizeHints( wxWindow
*window
)
959 // Preserve the window's max size hints, but set the
960 // lower bound according to the sizer calculations.
962 // This is equivalent to calling Fit(), except that we need to set
963 // the size hints _in between_ the two steps performed by Fit
964 // (1. ComputeFittingClientSize, 2. SetClientSize). That's because
965 // otherwise SetClientSize() could have no effect if there already are
966 // size hints in effect that forbid requested client size.
968 const wxSize clientSize
= ComputeFittingClientSize(window
);
970 window
->SetMinClientSize(clientSize
);
971 window
->SetClientSize(clientSize
);
974 #if WXWIN_COMPATIBILITY_2_8
975 void wxSizer::SetVirtualSizeHints( wxWindow
*window
)
979 #endif // WXWIN_COMPATIBILITY_2_8
981 // TODO on mac we need a function that determines how much free space this
982 // min size contains, in order to make sure that we have 20 pixels of free
983 // space around the controls
984 wxSize
wxSizer::GetMaxClientSize( wxWindow
*window
) const
986 return window
->WindowToClientSize(window
->GetMaxSize());
989 wxSize
wxSizer::GetMinClientSize( wxWindow
*WXUNUSED(window
) )
991 return GetMinSize(); // Already returns client size.
994 wxSize
wxSizer::VirtualFitSize( wxWindow
*window
)
996 wxSize size
= GetMinClientSize( window
);
997 wxSize sizeMax
= GetMaxClientSize( window
);
999 // Limit the size if sizeMax != wxDefaultSize
1001 if ( size
.x
> sizeMax
.x
&& sizeMax
.x
!= wxDefaultCoord
)
1003 if ( size
.y
> sizeMax
.y
&& sizeMax
.y
!= wxDefaultCoord
)
1009 wxSize
wxSizer::GetMinSize()
1011 wxSize
ret( CalcMin() );
1012 if (ret
.x
< m_minSize
.x
) ret
.x
= m_minSize
.x
;
1013 if (ret
.y
< m_minSize
.y
) ret
.y
= m_minSize
.y
;
1017 void wxSizer::DoSetMinSize( int width
, int height
)
1019 m_minSize
.x
= width
;
1020 m_minSize
.y
= height
;
1023 bool wxSizer::DoSetItemMinSize( wxWindow
*window
, int width
, int height
)
1025 wxASSERT_MSG( window
, _T("SetMinSize for NULL window") );
1027 // Is it our immediate child?
1029 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1032 wxSizerItem
*item
= node
->GetData();
1034 if (item
->GetWindow() == window
)
1036 item
->SetMinSize( width
, height
);
1039 node
= node
->GetNext();
1042 // No? Search any subsizers we own then
1044 node
= m_children
.GetFirst();
1047 wxSizerItem
*item
= node
->GetData();
1049 if ( item
->GetSizer() &&
1050 item
->GetSizer()->DoSetItemMinSize( window
, width
, height
) )
1052 // A child sizer found the requested windw, exit.
1055 node
= node
->GetNext();
1061 bool wxSizer::DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
)
1063 wxASSERT_MSG( sizer
, _T("SetMinSize for NULL sizer") );
1065 // Is it our immediate child?
1067 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1070 wxSizerItem
*item
= node
->GetData();
1072 if (item
->GetSizer() == sizer
)
1074 item
->GetSizer()->DoSetMinSize( width
, height
);
1077 node
= node
->GetNext();
1080 // No? Search any subsizers we own then
1082 node
= m_children
.GetFirst();
1085 wxSizerItem
*item
= node
->GetData();
1087 if ( item
->GetSizer() &&
1088 item
->GetSizer()->DoSetItemMinSize( sizer
, width
, height
) )
1090 // A child found the requested sizer, exit.
1093 node
= node
->GetNext();
1099 bool wxSizer::DoSetItemMinSize( size_t index
, int width
, int height
)
1101 wxSizerItemList::compatibility_iterator node
= m_children
.Item( index
);
1103 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
1105 wxSizerItem
*item
= node
->GetData();
1107 if (item
->GetSizer())
1109 // Sizers contains the minimal size in them, if not calculated ...
1110 item
->GetSizer()->DoSetMinSize( width
, height
);
1114 // ... but the minimal size of spacers and windows is stored via the item
1115 item
->SetMinSize( width
, height
);
1121 wxSizerItem
* wxSizer::GetItem( wxWindow
*window
, bool recursive
)
1123 wxASSERT_MSG( window
, _T("GetItem for NULL window") );
1125 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1128 wxSizerItem
*item
= node
->GetData();
1130 if (item
->GetWindow() == window
)
1134 else if (recursive
&& item
->IsSizer())
1136 wxSizerItem
*subitem
= item
->GetSizer()->GetItem( window
, true );
1141 node
= node
->GetNext();
1147 wxSizerItem
* wxSizer::GetItem( wxSizer
*sizer
, bool recursive
)
1149 wxASSERT_MSG( sizer
, _T("GetItem for NULL sizer") );
1151 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1154 wxSizerItem
*item
= node
->GetData();
1156 if (item
->GetSizer() == sizer
)
1160 else if (recursive
&& item
->IsSizer())
1162 wxSizerItem
*subitem
= item
->GetSizer()->GetItem( sizer
, true );
1167 node
= node
->GetNext();
1173 wxSizerItem
* wxSizer::GetItem( size_t index
)
1175 wxCHECK_MSG( index
< m_children
.GetCount(),
1177 _T("GetItem index is out of range") );
1179 return m_children
.Item( index
)->GetData();
1182 wxSizerItem
* wxSizer::GetItemById( int id
, bool recursive
)
1184 // This gets a sizer item by the id of the sizer item
1185 // and NOT the id of a window if the item is a window.
1187 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1190 wxSizerItem
*item
= node
->GetData();
1192 if (item
->GetId() == id
)
1196 else if (recursive
&& item
->IsSizer())
1198 wxSizerItem
*subitem
= item
->GetSizer()->GetItemById( id
, true );
1203 node
= node
->GetNext();
1209 bool wxSizer::Show( wxWindow
*window
, bool show
, bool recursive
)
1211 wxSizerItem
*item
= GetItem( window
, recursive
);
1222 bool wxSizer::Show( wxSizer
*sizer
, bool show
, bool recursive
)
1224 wxSizerItem
*item
= GetItem( sizer
, recursive
);
1235 bool wxSizer::Show( size_t index
, bool show
)
1237 wxSizerItem
*item
= GetItem( index
);
1248 void wxSizer::ShowItems( bool show
)
1250 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1253 node
->GetData()->Show( show
);
1254 node
= node
->GetNext();
1258 bool wxSizer::IsShown( wxWindow
*window
) const
1260 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1263 wxSizerItem
*item
= node
->GetData();
1265 if (item
->GetWindow() == window
)
1267 return item
->IsShown();
1269 node
= node
->GetNext();
1272 wxFAIL_MSG( _T("IsShown failed to find sizer item") );
1277 bool wxSizer::IsShown( wxSizer
*sizer
) const
1279 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1282 wxSizerItem
*item
= node
->GetData();
1284 if (item
->GetSizer() == sizer
)
1286 return item
->IsShown();
1288 node
= node
->GetNext();
1291 wxFAIL_MSG( _T("IsShown failed to find sizer item") );
1296 bool wxSizer::IsShown( size_t index
) const
1298 wxCHECK_MSG( index
< m_children
.GetCount(),
1300 _T("IsShown index is out of range") );
1302 return m_children
.Item( index
)->GetData()->IsShown();
1306 //---------------------------------------------------------------------------
1308 //---------------------------------------------------------------------------
1310 wxGridSizer::wxGridSizer( int rows
, int cols
, int vgap
, int hgap
)
1311 : m_rows( ( cols
== 0 && rows
== 0 ) ? 1 : rows
)
1318 wxGridSizer::wxGridSizer( int cols
, int vgap
, int hgap
)
1319 : m_rows( cols
== 0 ? 1 : 0 )
1326 int wxGridSizer::CalcRowsCols(int& nrows
, int& ncols
) const
1328 const int nitems
= m_children
.GetCount();
1329 if ( m_cols
&& m_rows
)
1331 // if both rows and columns are specified by user, use the provided
1332 // values even if we don't have enough items but check that we don't
1333 // have too many of them as this is going to result in problems later
1337 wxASSERT_MSG( ncols
*nrows
>= nitems
, "too many items in grid sizer" );
1342 nrows
= (nitems
+ m_cols
- 1) / m_cols
;
1346 ncols
= (nitems
+ m_rows
- 1) / m_rows
;
1349 else // 0 columns, 0 rows?
1351 wxFAIL_MSG( _T("grid sizer must have either rows or columns fixed") );
1360 void wxGridSizer::RecalcSizes()
1362 int nitems
, nrows
, ncols
;
1363 if ( (nitems
= CalcRowsCols(nrows
, ncols
)) == 0 )
1366 wxSize
sz( GetSize() );
1367 wxPoint
pt( GetPosition() );
1369 int w
= (sz
.x
- (ncols
- 1) * m_hgap
) / ncols
;
1370 int h
= (sz
.y
- (nrows
- 1) * m_vgap
) / nrows
;
1373 for (int c
= 0; c
< ncols
; c
++)
1376 for (int r
= 0; r
< nrows
; r
++)
1378 int i
= r
* ncols
+ c
;
1381 wxSizerItemList::compatibility_iterator node
= m_children
.Item( i
);
1383 wxASSERT_MSG( node
, _T("Failed to find SizerItemList node") );
1385 SetItemBounds( node
->GetData(), x
, y
, w
, h
);
1393 wxSize
wxGridSizer::CalcMin()
1396 if ( CalcRowsCols(nrows
, ncols
) == 0 )
1399 // Find the max width and height for any component
1403 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1406 wxSizerItem
*item
= node
->GetData();
1407 wxSize
sz( item
->CalcMin() );
1409 w
= wxMax( w
, sz
.x
);
1410 h
= wxMax( h
, sz
.y
);
1412 node
= node
->GetNext();
1415 // In case we have a nested sizer with a two step algo , give it
1416 // a chance to adjust to that (we give it width component)
1417 node
= m_children
.GetFirst();
1418 bool didChangeMinSize
= false;
1421 wxSizerItem
*item
= node
->GetData();
1422 didChangeMinSize
|= item
->InformFirstDirection( wxHORIZONTAL
, w
, -1 );
1424 node
= node
->GetNext();
1427 // And redo iteration in case min size changed
1428 if( didChangeMinSize
)
1430 node
= m_children
.GetFirst();
1434 wxSizerItem
*item
= node
->GetData();
1435 wxSize
sz( item
->GetMinSizeWithBorder() );
1437 w
= wxMax( w
, sz
.x
);
1438 h
= wxMax( h
, sz
.y
);
1440 node
= node
->GetNext();
1444 return wxSize( ncols
* w
+ (ncols
-1) * m_hgap
,
1445 nrows
* h
+ (nrows
-1) * m_vgap
);
1448 void wxGridSizer::SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
)
1451 wxSize
sz( item
->GetMinSizeWithBorder() );
1452 int flag
= item
->GetFlag();
1454 if ((flag
& wxEXPAND
) || (flag
& wxSHAPED
))
1460 if (flag
& wxALIGN_CENTER_HORIZONTAL
)
1462 pt
.x
= x
+ (w
- sz
.x
) / 2;
1464 else if (flag
& wxALIGN_RIGHT
)
1466 pt
.x
= x
+ (w
- sz
.x
);
1469 if (flag
& wxALIGN_CENTER_VERTICAL
)
1471 pt
.y
= y
+ (h
- sz
.y
) / 2;
1473 else if (flag
& wxALIGN_BOTTOM
)
1475 pt
.y
= y
+ (h
- sz
.y
);
1479 item
->SetDimension(pt
, sz
);
1482 //---------------------------------------------------------------------------
1484 //---------------------------------------------------------------------------
1486 wxFlexGridSizer::wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
)
1487 : wxGridSizer( rows
, cols
, vgap
, hgap
),
1488 m_flexDirection(wxBOTH
),
1489 m_growMode(wxFLEX_GROWMODE_SPECIFIED
)
1493 wxFlexGridSizer::wxFlexGridSizer( int cols
, int vgap
, int hgap
)
1494 : wxGridSizer( cols
, vgap
, hgap
),
1495 m_flexDirection(wxBOTH
),
1496 m_growMode(wxFLEX_GROWMODE_SPECIFIED
)
1500 wxFlexGridSizer::~wxFlexGridSizer()
1504 void wxFlexGridSizer::RecalcSizes()
1507 if ( !CalcRowsCols(nrows
, ncols
) )
1510 const wxPoint
pt(GetPosition());
1511 const wxSize
sz(GetSize());
1513 AdjustForGrowables(sz
);
1515 wxSizerItemList::const_iterator i
= m_children
.begin();
1516 const wxSizerItemList::const_iterator end
= m_children
.end();
1519 for ( int r
= 0; r
< nrows
; r
++ )
1521 if ( m_rowHeights
[r
] == -1 )
1523 // this row is entirely hidden, skip it
1524 for ( int c
= 0; c
< ncols
; c
++ )
1535 const int hrow
= m_rowHeights
[r
];
1536 int h
= sz
.y
- y
; // max remaining height, don't overflow it
1541 for ( int c
= 0; c
< ncols
&& i
!= end
; c
++, ++i
)
1543 const int wcol
= m_colWidths
[c
];
1548 int w
= sz
.x
- x
; // max possible value, ensure we don't overflow
1552 SetItemBounds(*i
, pt
.x
+ x
, pt
.y
+ y
, w
, h
);
1564 // helper function used in CalcMin() to sum up the sizes of non-hidden items
1565 static int SumArraySizes(const wxArrayInt
& sizes
, int gap
)
1567 // Sum total minimum size, including gaps between rows/columns.
1568 // -1 is used as a magic number meaning empty row/column.
1571 const size_t count
= sizes
.size();
1572 for ( size_t n
= 0; n
< count
; n
++ )
1574 if ( sizes
[n
] != -1 )
1577 total
+= gap
; // separate from the previous column
1586 void wxFlexGridSizer::FindWidthsAndHeights(int nrows
, int ncols
)
1588 // We have to recalculate the sizes in case the item minimum size has
1589 // changed since the previous layout, or the item has been hidden using
1590 // wxSizer::Show(). If all the items in a row/column are hidden, the final
1591 // dimension of the row/column will be -1, indicating that the column
1592 // itself is hidden.
1593 m_rowHeights
.assign(nrows
, -1);
1594 m_colWidths
.assign(ncols
, -1);
1596 // n is the index of the item in left-to-right top-to-bottom order
1598 for ( wxSizerItemList::iterator i
= m_children
.begin();
1599 i
!= m_children
.end();
1602 wxSizerItem
* const item
= *i
;
1603 if ( item
->IsShown() )
1605 // NOTE: Not doing the calculation here, this is just
1606 // for finding max values.
1607 const wxSize
sz(item
->GetMinSizeWithBorder());
1609 const int row
= n
/ ncols
;
1610 const int col
= n
% ncols
;
1612 if ( sz
.y
> m_rowHeights
[row
] )
1613 m_rowHeights
[row
] = sz
.y
;
1614 if ( sz
.x
> m_colWidths
[col
] )
1615 m_colWidths
[col
] = sz
.x
;
1619 AdjustForFlexDirection();
1621 m_calculatedMinSize
= wxSize(SumArraySizes(m_colWidths
, m_hgap
),
1622 SumArraySizes(m_rowHeights
, m_vgap
));
1625 wxSize
wxFlexGridSizer::CalcMin()
1630 // Number of rows/columns can change as items are added or removed.
1631 if ( !CalcRowsCols(nrows
, ncols
) )
1635 // We have to recalculate the sizes in case the item minimum size has
1636 // changed since the previous layout, or the item has been hidden using
1637 // wxSizer::Show(). If all the items in a row/column are hidden, the final
1638 // dimension of the row/column will be -1, indicating that the column
1639 // itself is hidden.
1640 m_rowHeights
.assign(nrows
, -1);
1641 m_colWidths
.assign(ncols
, -1);
1643 for ( wxSizerItemList::iterator i
= m_children
.begin();
1644 i
!= m_children
.end();
1647 wxSizerItem
* const item
= *i
;
1648 if ( item
->IsShown() )
1654 // The stage of looking for max values in each row/column has been
1655 // made a separate function, since it's reused in AdjustForGrowables.
1656 FindWidthsAndHeights(nrows
,ncols
);
1658 return m_calculatedMinSize
;
1661 void wxFlexGridSizer::AdjustForFlexDirection()
1663 // the logic in CalcMin works when we resize flexibly in both directions
1664 // but maybe this is not the case
1665 if ( m_flexDirection
!= wxBOTH
)
1667 // select the array corresponding to the direction in which we do *not*
1669 wxArrayInt
& array
= m_flexDirection
== wxVERTICAL
? m_colWidths
1672 const size_t count
= array
.GetCount();
1674 // find the largest value in this array
1678 for ( n
= 0; n
< count
; ++n
)
1680 if ( array
[n
] > largest
)
1684 // and now fill it with the largest value
1685 for ( n
= 0; n
< count
; ++n
)
1687 // don't touch hidden rows
1688 if ( array
[n
] != -1 )
1694 // helper of AdjustForGrowables() which is called for rows/columns separately
1697 // delta: the extra space, we do nothing unless it's positive
1698 // growable: indices or growable rows/cols in sizes array
1699 // sizes: the height/widths of rows/cols to adjust
1700 // proportions: proportions of the growable rows/cols or NULL if they all
1701 // should be assumed to have proportion of 1
1703 DoAdjustForGrowables(int delta
,
1704 const wxArrayInt
& growable
,
1706 const wxArrayInt
*proportions
)
1711 // total sum of proportions of all non-hidden rows
1712 int sum_proportions
= 0;
1714 // number of currently shown growable rows
1717 const int max_idx
= sizes
.size();
1719 const size_t count
= growable
.size();
1721 for ( idx
= 0; idx
< count
; idx
++ )
1723 // Since the number of rows/columns can change as items are
1724 // inserted/deleted, we need to verify at runtime that the
1725 // requested growable rows/columns are still valid.
1726 if ( growable
[idx
] >= max_idx
)
1729 // If all items in a row/column are hidden, that row/column will
1730 // have a dimension of -1. This causes the row/column to be
1731 // hidden completely.
1732 if ( sizes
[growable
[idx
]] == -1 )
1736 sum_proportions
+= (*proportions
)[idx
];
1744 // the remaining extra free space, adjusted during each iteration
1745 for ( idx
= 0; idx
< count
; idx
++ )
1747 if ( growable
[idx
] >= max_idx
)
1750 if ( sizes
[ growable
[idx
] ] == -1 )
1754 if ( sum_proportions
== 0 )
1756 // no growable rows -- divide extra space evenly among all
1757 cur_delta
= delta
/num
;
1760 else // allocate extra space proportionally
1762 const int cur_prop
= (*proportions
)[idx
];
1763 cur_delta
= (delta
*cur_prop
)/sum_proportions
;
1764 sum_proportions
-= cur_prop
;
1767 sizes
[growable
[idx
]] += cur_delta
;
1772 void wxFlexGridSizer::AdjustForGrowables(const wxSize
& sz
)
1774 if ( (m_flexDirection
& wxHORIZONTAL
) || (m_growMode
!= wxFLEX_GROWMODE_NONE
) )
1776 DoAdjustForGrowables
1778 sz
.x
- m_calculatedMinSize
.x
,
1781 m_growMode
== wxFLEX_GROWMODE_SPECIFIED
? &m_growableColsProportions
1785 // This gives nested objects that benefit from knowing one size
1786 // component in advance the chance to use that.
1787 bool didAdjustMinSize
= false;
1789 CalcRowsCols(nrows
, ncols
);
1791 // Iterate over all items and inform about column width
1793 for ( wxSizerItemList::iterator i
= m_children
.begin();
1794 i
!= m_children
.end();
1797 const int col
= n
% ncols
;
1798 didAdjustMinSize
|= (*i
)->InformFirstDirection(wxHORIZONTAL
, m_colWidths
[col
], sz
.y
- m_calculatedMinSize
.y
);
1801 // Only redo if info was actually used
1802 if( didAdjustMinSize
)
1804 DoAdjustForGrowables
1806 sz
.x
- m_calculatedMinSize
.x
,
1809 m_growMode
== wxFLEX_GROWMODE_SPECIFIED
? &m_growableColsProportions
1815 if ( (m_flexDirection
& wxVERTICAL
) || (m_growMode
!= wxFLEX_GROWMODE_NONE
) )
1817 // pass NULL instead of proportions if the grow mode is ALL as we
1818 // should treat all rows as having proportion of 1 then
1819 DoAdjustForGrowables
1821 sz
.y
- m_calculatedMinSize
.y
,
1824 m_growMode
== wxFLEX_GROWMODE_SPECIFIED
? &m_growableRowsProportions
1830 bool wxFlexGridSizer::IsRowGrowable( size_t idx
)
1832 return m_growableRows
.Index( idx
) != wxNOT_FOUND
;
1835 bool wxFlexGridSizer::IsColGrowable( size_t idx
)
1837 return m_growableCols
.Index( idx
) != wxNOT_FOUND
;
1840 void wxFlexGridSizer::AddGrowableRow( size_t idx
, int proportion
)
1843 CalcRowsCols(nrows
, ncols
);
1844 wxCHECK_RET( idx
< (size_t)nrows
, "invalid row index" );
1846 wxASSERT_MSG( !IsRowGrowable( idx
),
1847 "AddGrowableRow() called for growable row" );
1848 m_growableRows
.Add( idx
);
1849 m_growableRowsProportions
.Add( proportion
);
1852 void wxFlexGridSizer::AddGrowableCol( size_t idx
, int proportion
)
1855 CalcRowsCols(nrows
, ncols
);
1856 wxCHECK_RET( idx
< (size_t)ncols
, "invalid column index" );
1858 wxASSERT_MSG( !IsColGrowable( idx
),
1859 "AddGrowableCol() called for growable column" );
1860 m_growableCols
.Add( idx
);
1861 m_growableColsProportions
.Add( proportion
);
1864 // helper function for RemoveGrowableCol/Row()
1866 DoRemoveFromArrays(size_t idx
, wxArrayInt
& items
, wxArrayInt
& proportions
)
1868 const size_t count
= items
.size();
1869 for ( size_t n
= 0; n
< count
; n
++ )
1871 if ( (size_t)items
[n
] == idx
)
1874 proportions
.RemoveAt(n
);
1879 wxFAIL_MSG( _T("column/row is already not growable") );
1882 void wxFlexGridSizer::RemoveGrowableCol( size_t idx
)
1884 DoRemoveFromArrays(idx
, m_growableCols
, m_growableColsProportions
);
1887 void wxFlexGridSizer::RemoveGrowableRow( size_t idx
)
1889 DoRemoveFromArrays(idx
, m_growableRows
, m_growableRowsProportions
);
1892 //---------------------------------------------------------------------------
1894 //---------------------------------------------------------------------------
1896 void wxBoxSizer::RecalcSizes()
1898 if ( m_children
.empty() )
1901 const wxCoord totalMinorSize
= GetSizeInMinorDir(m_size
);
1903 // the amount of free space which we should redistribute among the
1904 // stretchable items (i.e. those with non zero proportion)
1905 int delta
= GetSizeInMajorDir(m_size
) - GetSizeInMajorDir(m_minSize
);
1908 // Inform child items about the size in minor direction, that can
1909 // change how much free space we have in major dir and how to distribute it.
1910 int majorMinSum
= 0;
1911 wxSizerItemList::const_iterator i
;
1912 for ( i
= m_children
.begin();
1913 i
!= m_children
.end();
1916 wxSizerItem
* const item
= *i
;
1918 if ( !item
->IsShown() )
1921 wxSize szMinPrev
= item
->GetMinSizeWithBorder();
1922 item
->InformFirstDirection(m_orient
^wxBOTH
,totalMinorSize
,delta
);
1923 wxSize szMin
= item
->GetMinSizeWithBorder();
1924 int deltaChange
= GetSizeInMajorDir(szMin
-szMinPrev
);
1927 // Since we passed available space along to the item, it should not
1928 // take too much, so delta should not become negative.
1929 delta
-= deltaChange
;
1931 majorMinSum
+= GetSizeInMajorDir(item
->GetMinSizeWithBorder());
1933 // And update our min size
1934 SizeInMajorDir(m_minSize
) = majorMinSum
;
1937 // might have a new delta now
1938 delta
= GetSizeInMajorDir(m_size
) - GetSizeInMajorDir(m_minSize
);
1940 // the position at which we put the next child
1941 wxPoint
pt(m_position
);
1943 int totalProportion
= m_totalProportion
;
1944 for ( i
= m_children
.begin();
1945 i
!= m_children
.end();
1948 wxSizerItem
* const item
= *i
;
1950 if ( !item
->IsShown() )
1953 const wxSize
sizeThis(item
->GetMinSizeWithBorder());
1955 // adjust the size in the major direction using the proportion
1956 wxCoord majorSize
= GetSizeInMajorDir(sizeThis
);
1958 // if there is not enough space, don't try to distribute negative space
1959 // among the children, this would result in overlapping windows which
1963 const int propItem
= item
->GetProportion();
1966 const int deltaItem
= (delta
* propItem
) / totalProportion
;
1968 majorSize
+= deltaItem
;
1971 totalProportion
-= propItem
;
1976 // apply the alignment in the minor direction
1977 wxPoint
posChild(pt
);
1979 wxCoord minorSize
= GetSizeInMinorDir(sizeThis
);
1980 const int flag
= item
->GetFlag();
1981 if ( flag
& (wxEXPAND
| wxSHAPED
) )
1983 minorSize
= totalMinorSize
;
1985 else if ( flag
& (IsVertical() ? wxALIGN_RIGHT
: wxALIGN_BOTTOM
) )
1987 PosInMinorDir(posChild
) += totalMinorSize
- minorSize
;
1989 // NB: wxCENTRE is used here only for backwards compatibility,
1990 // wxALIGN_CENTRE should be used in new code
1991 else if ( flag
& (wxCENTER
| (IsVertical() ? wxALIGN_CENTRE_HORIZONTAL
: wxALIGN_CENTRE_VERTICAL
)))
1993 PosInMinorDir(posChild
) += (totalMinorSize
- minorSize
) / 2;
1997 // apply RTL adjustment for horizontal sizers:
1998 if ( !IsVertical() && m_containingWindow
)
2000 posChild
.x
= m_containingWindow
->AdjustForLayoutDirection
2008 // finally set size of this child and advance to the next one
2009 item
->SetDimension(posChild
, SizeFromMajorMinor(majorSize
, minorSize
));
2011 PosInMajorDir(pt
) += majorSize
;
2015 wxSize
wxBoxSizer::CalcMin()
2017 m_totalProportion
= 0;
2018 m_minSize
= wxSize(0, 0);
2020 // calculate the minimal sizes for all items and count sum of proportions
2021 for ( wxSizerItemList::const_iterator i
= m_children
.begin();
2022 i
!= m_children
.end();
2025 wxSizerItem
* const item
= *i
;
2027 if ( !item
->IsShown() )
2030 const wxSize sizeMinThis
= item
->CalcMin();
2031 SizeInMajorDir(m_minSize
) += GetSizeInMajorDir(sizeMinThis
);
2032 if ( GetSizeInMinorDir(sizeMinThis
) > GetSizeInMinorDir(m_minSize
) )
2033 SizeInMinorDir(m_minSize
) = GetSizeInMinorDir(sizeMinThis
);
2035 m_totalProportion
+= item
->GetProportion();
2041 //---------------------------------------------------------------------------
2043 //---------------------------------------------------------------------------
2047 wxStaticBoxSizer::wxStaticBoxSizer( wxStaticBox
*box
, int orient
)
2048 : wxBoxSizer( orient
),
2051 wxASSERT_MSG( box
, wxT("wxStaticBoxSizer needs a static box") );
2053 // do this so that our Detach() is called if the static box is destroyed
2055 m_staticBox
->SetContainingSizer(this);
2058 wxStaticBoxSizer::wxStaticBoxSizer(int orient
, wxWindow
*win
, const wxString
& s
)
2059 : wxBoxSizer(orient
),
2060 m_staticBox(new wxStaticBox(win
, wxID_ANY
, s
))
2063 m_staticBox
->SetContainingSizer(this);
2066 wxStaticBoxSizer::~wxStaticBoxSizer()
2071 static void GetStaticBoxBorders( wxStaticBox
*box
,
2075 // this has to be done platform by platform as there is no way to
2076 // guess the thickness of a wxStaticBox border
2077 box
->GetBordersForSizer(borderTop
, borderOther
);
2080 void wxStaticBoxSizer::RecalcSizes()
2082 int top_border
, other_border
;
2083 GetStaticBoxBorders(m_staticBox
, &top_border
, &other_border
);
2085 m_staticBox
->SetSize( m_position
.x
, m_position
.y
, m_size
.x
, m_size
.y
);
2087 wxPoint
old_pos( m_position
);
2088 m_position
.x
+= other_border
;
2089 m_position
.y
+= top_border
;
2090 wxSize
old_size( m_size
);
2091 m_size
.x
-= 2*other_border
;
2092 m_size
.y
-= top_border
+ other_border
;
2094 wxBoxSizer::RecalcSizes();
2096 m_position
= old_pos
;
2100 wxSize
wxStaticBoxSizer::CalcMin()
2102 int top_border
, other_border
;
2103 GetStaticBoxBorders(m_staticBox
, &top_border
, &other_border
);
2105 wxSize
ret( wxBoxSizer::CalcMin() );
2106 ret
.x
+= 2*other_border
;
2107 ret
.y
+= other_border
+ top_border
;
2112 void wxStaticBoxSizer::ShowItems( bool show
)
2114 m_staticBox
->Show( show
);
2115 wxBoxSizer::ShowItems( show
);
2118 bool wxStaticBoxSizer::Detach( wxWindow
*window
)
2120 // avoid deleting m_staticBox in our dtor if it's being detached from the
2121 // sizer (which can happen because it's being already destroyed for
2123 if ( window
== m_staticBox
)
2129 return wxSizer::Detach( window
);
2132 #endif // wxUSE_STATBOX
2136 wxStdDialogButtonSizer::wxStdDialogButtonSizer()
2137 : wxBoxSizer(wxHORIZONTAL
)
2139 // Vertical buttons with lots of space on either side
2140 // looks rubbish on WinCE, so let's not do this for now.
2141 // If we are going to use vertical buttons, we should
2142 // put the sizer to the right of other controls in the dialog,
2143 // and that's beyond the scope of this sizer.
2145 bool is_pda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
2146 // If we have a PDA screen, put yes/no button over
2147 // all other buttons, otherwise on the left side.
2149 m_orient
= wxVERTICAL
;
2152 m_buttonAffirmative
= NULL
;
2153 m_buttonApply
= NULL
;
2154 m_buttonNegative
= NULL
;
2155 m_buttonCancel
= NULL
;
2156 m_buttonHelp
= NULL
;
2159 void wxStdDialogButtonSizer::AddButton(wxButton
*mybutton
)
2161 switch (mybutton
->GetId())
2166 m_buttonAffirmative
= mybutton
;
2169 m_buttonApply
= mybutton
;
2172 m_buttonNegative
= mybutton
;
2176 m_buttonCancel
= mybutton
;
2179 case wxID_CONTEXT_HELP
:
2180 m_buttonHelp
= mybutton
;
2187 void wxStdDialogButtonSizer::SetAffirmativeButton( wxButton
*button
)
2189 m_buttonAffirmative
= button
;
2192 void wxStdDialogButtonSizer::SetNegativeButton( wxButton
*button
)
2194 m_buttonNegative
= button
;
2197 void wxStdDialogButtonSizer::SetCancelButton( wxButton
*button
)
2199 m_buttonCancel
= button
;
2202 void wxStdDialogButtonSizer::Realize()
2205 Add(0, 0, 0, wxLEFT
, 6);
2207 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 6);
2209 if (m_buttonNegative
){
2210 // HIG POLICE BULLETIN - destructive buttons need extra padding
2211 // 24 pixels on either side
2212 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 12);
2215 // extra whitespace between help/negative and cancel/ok buttons
2216 Add(0, 0, 1, wxEXPAND
, 0);
2218 if (m_buttonCancel
){
2219 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 6);
2220 // Cancel or help should be default
2221 // m_buttonCancel->SetDefaultButton();
2224 // Ugh, Mac doesn't really have apply dialogs, so I'll just
2225 // figure the best place is between Cancel and OK
2227 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 6);
2229 if (m_buttonAffirmative
){
2230 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
, 6);
2232 if (m_buttonAffirmative
->GetId() == wxID_SAVE
){
2233 // these buttons have set labels under Mac so we should use them
2234 m_buttonAffirmative
->SetLabel(_("Save"));
2235 if (m_buttonNegative
)
2236 m_buttonNegative
->SetLabel(_("Don't Save"));
2240 // Extra space around and at the right
2242 #elif defined(__WXGTK20__)
2243 Add(0, 0, 0, wxLEFT
, 9);
2245 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
2247 // extra whitespace between help and cancel/ok buttons
2248 Add(0, 0, 1, wxEXPAND
, 0);
2250 if (m_buttonNegative
){
2251 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
2254 // according to HIG, in explicit apply windows the order is:
2255 // [ Help Apply Cancel OK ]
2257 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
2259 if (m_buttonCancel
){
2260 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
2261 // Cancel or help should be default
2262 // m_buttonCancel->SetDefaultButton();
2265 if (m_buttonAffirmative
)
2266 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
, 6);
2267 #elif defined(__WXMSW__)
2270 // right-justify buttons
2271 Add(0, 0, 1, wxEXPAND
, 0);
2273 if (m_buttonAffirmative
){
2274 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonAffirmative
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2277 if (m_buttonNegative
){
2278 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonNegative
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2281 if (m_buttonCancel
){
2282 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonCancel
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2285 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonApply
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2288 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonHelp
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2290 // GTK+1 and any other platform
2292 // Add(0, 0, 0, wxLEFT, 5); // Not sure what this was for but it unbalances the dialog
2294 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonHelp
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2296 // extra whitespace between help and cancel/ok buttons
2297 Add(0, 0, 1, wxEXPAND
, 0);
2300 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonApply
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2302 if (m_buttonAffirmative
){
2303 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonAffirmative
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2306 if (m_buttonNegative
){
2307 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonNegative
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2310 if (m_buttonCancel
){
2311 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonCancel
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2312 // Cancel or help should be default
2313 // m_buttonCancel->SetDefaultButton();
2319 #endif // wxUSE_BUTTON