1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/sizer.cpp
3 // Purpose: provide new wxSizer class for layout
4 // Author: Robert Roebling and Robin Dunn, contributions by
5 // Dirk Holtwick, Ron Lee
6 // Modified by: Ron Lee
9 // Copyright: (c) Robin Dunn, Robert Roebling
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
13 // For compilers that support precompilation, includes "wx.h".
14 #include "wx/wxprec.h"
20 #include "wx/display.h"
24 #include "wx/string.h"
28 #include "wx/settings.h"
29 #include "wx/button.h"
30 #include "wx/statbox.h"
31 #include "wx/toplevel.h"
34 #include "wx/listimpl.cpp"
36 #if WXWIN_COMPATIBILITY_2_4
37 #include "wx/notebook.h"
40 //---------------------------------------------------------------------------
42 IMPLEMENT_CLASS(wxSizerItem
, wxObject
)
43 IMPLEMENT_CLASS(wxSizer
, wxObject
)
44 IMPLEMENT_CLASS(wxGridSizer
, wxSizer
)
45 IMPLEMENT_CLASS(wxFlexGridSizer
, wxGridSizer
)
46 IMPLEMENT_CLASS(wxBoxSizer
, wxSizer
)
48 IMPLEMENT_CLASS(wxStaticBoxSizer
, wxBoxSizer
)
51 IMPLEMENT_CLASS(wxStdDialogButtonSizer
, wxBoxSizer
)
54 WX_DEFINE_EXPORTED_LIST( wxSizerItemList
)
89 // ----------------------------------------------------------------------------
91 // ----------------------------------------------------------------------------
93 void wxSizerItem::Init(const wxSizerFlags
& flags
)
97 m_proportion
= flags
.GetProportion();
98 m_flag
= flags
.GetFlags();
99 m_border
= flags
.GetBorderInPixels();
102 wxSizerItem::wxSizerItem()
114 void wxSizerItem::SetWindow(wxWindow
*window
)
116 wxCHECK_RET( window
, _T("NULL window in wxSizerItem::SetWindow()") );
118 m_kind
= Item_Window
;
121 // window doesn't become smaller than its initial size, whatever happens
122 m_minSize
= window
->GetSize();
124 if ( m_flag
& wxFIXED_MINSIZE
)
125 window
->SetMinSize(m_minSize
);
127 // aspect ratio calculated from initial size
131 wxSizerItem::wxSizerItem(wxWindow
*window
,
136 : m_proportion(proportion
),
145 void wxSizerItem::SetSizer(wxSizer
*sizer
)
151 wxSizerItem::wxSizerItem(wxSizer
*sizer
,
156 : m_proportion(proportion
),
164 // m_minSize is set later
168 void wxSizerItem::SetSpacer(const wxSize
& size
)
170 m_kind
= Item_Spacer
;
171 m_spacer
= new wxSizerSpacer(size
);
176 wxSizerItem::wxSizerItem(int width
,
182 : m_minSize(width
, height
), // minimal size is the initial size
183 m_proportion(proportion
),
188 SetSpacer(width
, height
);
191 wxSizerItem::~wxSizerItem()
201 m_window
->SetContainingSizer(NULL
);
214 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
218 wxSize
wxSizerItem::GetSpacer() const
221 if ( m_kind
== Item_Spacer
)
222 size
= m_spacer
->GetSize();
228 wxSize
wxSizerItem::GetSize() const
237 ret
= m_window
->GetSize();
241 ret
= m_sizer
->GetSize();
245 ret
= m_spacer
->GetSize();
250 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
257 if (m_flag
& wxNORTH
)
259 if (m_flag
& wxSOUTH
)
265 wxSize
wxSizerItem::CalcMin()
269 m_minSize
= m_sizer
->GetMinSize();
271 // if we have to preserve aspect ratio _AND_ this is
272 // the first-time calculation, consider ret to be initial size
273 if ( (m_flag
& wxSHAPED
) && wxIsNullDouble(m_ratio
) )
276 else if ( IsWindow() )
278 // Since the size of the window may change during runtime, we
279 // should use the current minimal/best size.
280 m_minSize
= m_window
->GetEffectiveMinSize();
283 return GetMinSizeWithBorder();
286 wxSize
wxSizerItem::GetMinSizeWithBorder() const
288 wxSize ret
= m_minSize
;
294 if (m_flag
& wxNORTH
)
296 if (m_flag
& wxSOUTH
)
303 void wxSizerItem::SetDimension( const wxPoint
& pos_
, const wxSize
& size_
)
307 if (m_flag
& wxSHAPED
)
309 // adjust aspect ratio
310 int rwidth
= (int) (size
.y
* m_ratio
);
314 int rheight
= (int) (size
.x
/ m_ratio
);
315 // add vertical space
316 if (m_flag
& wxALIGN_CENTER_VERTICAL
)
317 pos
.y
+= (size
.y
- rheight
) / 2;
318 else if (m_flag
& wxALIGN_BOTTOM
)
319 pos
.y
+= (size
.y
- rheight
);
320 // use reduced dimensions
323 else if (rwidth
< size
.x
)
325 // add horizontal space
326 if (m_flag
& wxALIGN_CENTER_HORIZONTAL
)
327 pos
.x
+= (size
.x
- rwidth
) / 2;
328 else if (m_flag
& wxALIGN_RIGHT
)
329 pos
.x
+= (size
.x
- rwidth
);
334 // This is what GetPosition() returns. Since we calculate
335 // borders afterwards, GetPosition() will be the left/top
336 // corner of the surrounding border.
348 if (m_flag
& wxNORTH
)
353 if (m_flag
& wxSOUTH
)
363 m_rect
= wxRect(pos
, size
);
368 wxFAIL_MSG( _T("can't set size of uninitialized sizer item") );
372 m_window
->SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
,
373 wxSIZE_ALLOW_MINUS_ONE
);
377 m_sizer
->SetDimension(pos
.x
, pos
.y
, size
.x
, size
.y
);
381 m_spacer
->SetSize(size
);
386 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
390 void wxSizerItem::DeleteWindows()
399 //We are deleting the window from this sizer - normally
400 //the window destroys the sizer associated with it,
401 //which might destroy this, which we don't want
402 m_window
->SetContainingSizer(NULL
);
404 //Putting this after the switch will result in a spacer
405 //not being deleted properly on destruction
410 m_sizer
->DeleteWindows();
415 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
420 void wxSizerItem::Show( bool show
)
425 wxFAIL_MSG( _T("can't show uninitialized sizer item") );
429 m_window
->Show(show
);
437 m_spacer
->Show(show
);
442 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
446 bool wxSizerItem::IsShown() const
451 // we may be called from CalcMin(), just return false so that we're
456 return m_window
->IsShown();
459 // arbitrarily decide that if at least one of our elements is
460 // shown, so are we (this arbitrariness is the reason for
461 // deprecating this function)
463 for ( wxSizerItemList::compatibility_iterator
464 node
= m_sizer
->GetChildren().GetFirst();
466 node
= node
->GetNext() )
468 if ( node
->GetData()->IsShown() )
475 return m_spacer
->IsShown();
479 wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
485 #if WXWIN_COMPATIBILITY_2_6
486 void wxSizerItem::SetOption( int option
)
488 SetProportion( option
);
491 int wxSizerItem::GetOption() const
493 return GetProportion();
495 #endif // WXWIN_COMPATIBILITY_2_6
498 //---------------------------------------------------------------------------
500 //---------------------------------------------------------------------------
504 WX_CLEAR_LIST(wxSizerItemList
, m_children
);
507 wxSizerItem
* wxSizer::Insert( size_t index
, wxSizerItem
*item
)
509 m_children
.Insert( index
, item
);
511 if ( item
->GetWindow() )
512 item
->GetWindow()->SetContainingSizer( this );
517 void wxSizer::SetContainingWindow(wxWindow
*win
)
519 if ( win
== m_containingWindow
)
522 m_containingWindow
= win
;
524 // set the same window for all nested sizers as well, they also are in the
526 for ( wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
528 node
= node
->GetNext() )
530 wxSizerItem
*const item
= node
->GetData();
531 wxSizer
*const sizer
= item
->GetSizer();
535 sizer
->SetContainingWindow(win
);
540 #if WXWIN_COMPATIBILITY_2_6
541 bool wxSizer::Remove( wxWindow
*window
)
543 return Detach( window
);
545 #endif // WXWIN_COMPATIBILITY_2_6
547 bool wxSizer::Remove( wxSizer
*sizer
)
549 wxASSERT_MSG( sizer
, _T("Removing NULL sizer") );
551 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
554 wxSizerItem
*item
= node
->GetData();
556 if (item
->GetSizer() == sizer
)
559 m_children
.Erase( node
);
563 node
= node
->GetNext();
569 bool wxSizer::Remove( int index
)
571 wxCHECK_MSG( index
>= 0 && (size_t)index
< m_children
.GetCount(),
573 _T("Remove index is out of range") );
575 wxSizerItemList::compatibility_iterator node
= m_children
.Item( index
);
577 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
579 wxSizerItem
*item
= node
->GetData();
581 if ( item
->IsWindow() )
582 item
->GetWindow()->SetContainingSizer( NULL
);
585 m_children
.Erase( node
);
589 bool wxSizer::Detach( wxSizer
*sizer
)
591 wxASSERT_MSG( sizer
, _T("Detaching NULL sizer") );
593 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
596 wxSizerItem
*item
= node
->GetData();
598 if (item
->GetSizer() == sizer
)
602 m_children
.Erase( node
);
605 node
= node
->GetNext();
611 bool wxSizer::Detach( wxWindow
*window
)
613 wxASSERT_MSG( window
, _T("Detaching NULL window") );
615 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
618 wxSizerItem
*item
= node
->GetData();
620 if (item
->GetWindow() == window
)
622 item
->GetWindow()->SetContainingSizer( NULL
);
624 m_children
.Erase( node
);
627 node
= node
->GetNext();
633 bool wxSizer::Detach( int index
)
635 wxCHECK_MSG( index
>= 0 && (size_t)index
< m_children
.GetCount(),
637 _T("Detach index is out of range") );
639 wxSizerItemList::compatibility_iterator node
= m_children
.Item( index
);
641 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
643 wxSizerItem
*item
= node
->GetData();
645 if ( item
->IsSizer() )
647 else if ( item
->IsWindow() )
648 item
->GetWindow()->SetContainingSizer( NULL
);
651 m_children
.Erase( node
);
655 bool wxSizer::Replace( wxWindow
*oldwin
, wxWindow
*newwin
, bool recursive
)
657 wxASSERT_MSG( oldwin
, _T("Replacing NULL window") );
658 wxASSERT_MSG( newwin
, _T("Replacing with NULL window") );
660 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
663 wxSizerItem
*item
= node
->GetData();
665 if (item
->GetWindow() == oldwin
)
667 item
->GetWindow()->SetContainingSizer( NULL
);
668 item
->SetWindow(newwin
);
669 newwin
->SetContainingSizer( this );
672 else if (recursive
&& item
->IsSizer())
674 if (item
->GetSizer()->Replace( oldwin
, newwin
, true ))
678 node
= node
->GetNext();
684 bool wxSizer::Replace( wxSizer
*oldsz
, wxSizer
*newsz
, bool recursive
)
686 wxASSERT_MSG( oldsz
, _T("Replacing NULL sizer") );
687 wxASSERT_MSG( newsz
, _T("Replacing with NULL sizer") );
689 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
692 wxSizerItem
*item
= node
->GetData();
694 if (item
->GetSizer() == oldsz
)
696 wxSizer
*old
= item
->GetSizer();
697 item
->SetSizer(newsz
);
701 else if (recursive
&& item
->IsSizer())
703 if (item
->GetSizer()->Replace( oldsz
, newsz
, true ))
707 node
= node
->GetNext();
713 bool wxSizer::Replace( size_t old
, wxSizerItem
*newitem
)
715 wxCHECK_MSG( old
< m_children
.GetCount(), false, _T("Replace index is out of range") );
716 wxASSERT_MSG( newitem
, _T("Replacing with NULL item") );
718 wxSizerItemList::compatibility_iterator node
= m_children
.Item( old
);
720 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
722 wxSizerItem
*item
= node
->GetData();
723 node
->SetData(newitem
);
729 void wxSizer::Clear( bool delete_windows
)
731 // First clear the ContainingSizer pointers
732 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
735 wxSizerItem
*item
= node
->GetData();
737 if (item
->IsWindow())
738 item
->GetWindow()->SetContainingSizer( NULL
);
739 node
= node
->GetNext();
742 // Destroy the windows if needed
746 // Now empty the list
747 WX_CLEAR_LIST(wxSizerItemList
, m_children
);
750 void wxSizer::DeleteWindows()
752 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
755 wxSizerItem
*item
= node
->GetData();
757 item
->DeleteWindows();
758 node
= node
->GetNext();
762 wxSize
wxSizer::Fit( wxWindow
*window
)
764 // take the min size by default and limit it by max size
765 wxSize size
= GetMinWindowSize(window
);
766 wxSize sizeMax
= GetMaxWindowSize(window
);
768 wxTopLevelWindow
*tlw
= wxDynamicCast(window
, wxTopLevelWindow
);
771 // hack for small screen devices where TLWs are always full screen
772 if ( tlw
->IsAlwaysMaximized() )
774 size
= tlw
->GetSize();
776 else // normal situation
778 // limit the window to the size of the display it is on
779 int disp
= wxDisplay::GetFromWindow(window
);
780 if ( disp
== wxNOT_FOUND
)
782 // or, if we don't know which one it is, of the main one
786 sizeMax
= wxDisplay(disp
).GetClientArea().GetSize();
790 if ( sizeMax
.x
!= wxDefaultCoord
&& size
.x
> sizeMax
.x
)
792 if ( sizeMax
.y
!= wxDefaultCoord
&& size
.y
> sizeMax
.y
)
796 window
->SetSize( size
);
801 void wxSizer::FitInside( wxWindow
*window
)
804 if (window
->IsTopLevel())
805 size
= VirtualFitSize( window
);
807 size
= GetMinClientSize( window
);
809 window
->SetVirtualSize( size
);
812 void wxSizer::Layout()
814 // (re)calculates minimums needed for each item and other preparations
818 // Applies the layout and repositions/resizes the items
822 void wxSizer::SetSizeHints( wxWindow
*window
)
824 // Preserve the window's max size hints, but set the
825 // lower bound according to the sizer calculations.
827 wxSize size
= Fit( window
);
829 window
->SetSizeHints( size
.x
,
831 window
->GetMaxWidth(),
832 window
->GetMaxHeight() );
835 void wxSizer::SetVirtualSizeHints( wxWindow
*window
)
837 // Preserve the window's max size hints, but set the
838 // lower bound according to the sizer calculations.
841 wxSize
size( window
->GetVirtualSize() );
842 window
->SetVirtualSizeHints( size
.x
,
844 window
->GetMaxWidth(),
845 window
->GetMaxHeight() );
848 wxSize
wxSizer::GetMaxWindowSize( wxWindow
*window
) const
850 return window
->GetMaxSize();
853 wxSize
wxSizer::GetMinWindowSize( wxWindow
*window
)
855 wxSize
minSize( GetMinSize() );
856 wxSize
size( window
->GetSize() );
857 wxSize
client_size( window
->GetClientSize() );
859 return wxSize( minSize
.x
+size
.x
-client_size
.x
,
860 minSize
.y
+size
.y
-client_size
.y
);
863 // TODO on mac we need a function that determines how much free space this
864 // min size contains, in order to make sure that we have 20 pixels of free
865 // space around the controls
866 wxSize
wxSizer::GetMaxClientSize( wxWindow
*window
) const
868 wxSize
maxSize( window
->GetMaxSize() );
870 if ( maxSize
!= wxDefaultSize
)
872 wxSize
size( window
->GetSize() );
873 wxSize
client_size( window
->GetClientSize() );
875 return wxSize( maxSize
.x
+ client_size
.x
- size
.x
,
876 maxSize
.y
+ client_size
.y
- size
.y
);
879 return wxDefaultSize
;
882 wxSize
wxSizer::GetMinClientSize( wxWindow
*WXUNUSED(window
) )
884 return GetMinSize(); // Already returns client size.
887 wxSize
wxSizer::VirtualFitSize( wxWindow
*window
)
889 wxSize size
= GetMinClientSize( window
);
890 wxSize sizeMax
= GetMaxClientSize( window
);
892 // Limit the size if sizeMax != wxDefaultSize
894 if ( size
.x
> sizeMax
.x
&& sizeMax
.x
!= wxDefaultCoord
)
896 if ( size
.y
> sizeMax
.y
&& sizeMax
.y
!= wxDefaultCoord
)
902 void wxSizer::SetDimension( int x
, int y
, int width
, int height
)
911 wxSize
wxSizer::GetMinSize()
913 wxSize
ret( CalcMin() );
914 if (ret
.x
< m_minSize
.x
) ret
.x
= m_minSize
.x
;
915 if (ret
.y
< m_minSize
.y
) ret
.y
= m_minSize
.y
;
919 void wxSizer::DoSetMinSize( int width
, int height
)
922 m_minSize
.y
= height
;
925 bool wxSizer::DoSetItemMinSize( wxWindow
*window
, int width
, int height
)
927 wxASSERT_MSG( window
, _T("SetMinSize for NULL window") );
929 // Is it our immediate child?
931 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
934 wxSizerItem
*item
= node
->GetData();
936 if (item
->GetWindow() == window
)
938 item
->SetMinSize( width
, height
);
941 node
= node
->GetNext();
944 // No? Search any subsizers we own then
946 node
= m_children
.GetFirst();
949 wxSizerItem
*item
= node
->GetData();
951 if ( item
->GetSizer() &&
952 item
->GetSizer()->DoSetItemMinSize( window
, width
, height
) )
954 // A child sizer found the requested windw, exit.
957 node
= node
->GetNext();
963 bool wxSizer::DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
)
965 wxASSERT_MSG( sizer
, _T("SetMinSize for NULL sizer") );
967 // Is it our immediate child?
969 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
972 wxSizerItem
*item
= node
->GetData();
974 if (item
->GetSizer() == sizer
)
976 item
->GetSizer()->DoSetMinSize( width
, height
);
979 node
= node
->GetNext();
982 // No? Search any subsizers we own then
984 node
= m_children
.GetFirst();
987 wxSizerItem
*item
= node
->GetData();
989 if ( item
->GetSizer() &&
990 item
->GetSizer()->DoSetItemMinSize( sizer
, width
, height
) )
992 // A child found the requested sizer, exit.
995 node
= node
->GetNext();
1001 bool wxSizer::DoSetItemMinSize( size_t index
, int width
, int height
)
1003 wxSizerItemList::compatibility_iterator node
= m_children
.Item( index
);
1005 wxCHECK_MSG( node
, false, _T("Failed to find child node") );
1007 wxSizerItem
*item
= node
->GetData();
1009 if (item
->GetSizer())
1011 // Sizers contains the minimal size in them, if not calculated ...
1012 item
->GetSizer()->DoSetMinSize( width
, height
);
1016 // ... but the minimal size of spacers and windows is stored via the item
1017 item
->SetMinSize( width
, height
);
1023 wxSizerItem
* wxSizer::GetItem( wxWindow
*window
, bool recursive
)
1025 wxASSERT_MSG( window
, _T("GetItem for NULL window") );
1027 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1030 wxSizerItem
*item
= node
->GetData();
1032 if (item
->GetWindow() == window
)
1036 else if (recursive
&& item
->IsSizer())
1038 wxSizerItem
*subitem
= item
->GetSizer()->GetItem( window
, true );
1043 node
= node
->GetNext();
1049 wxSizerItem
* wxSizer::GetItem( wxSizer
*sizer
, bool recursive
)
1051 wxASSERT_MSG( sizer
, _T("GetItem for NULL sizer") );
1053 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1056 wxSizerItem
*item
= node
->GetData();
1058 if (item
->GetSizer() == sizer
)
1062 else if (recursive
&& item
->IsSizer())
1064 wxSizerItem
*subitem
= item
->GetSizer()->GetItem( sizer
, true );
1069 node
= node
->GetNext();
1075 wxSizerItem
* wxSizer::GetItem( size_t index
)
1077 wxCHECK_MSG( index
< m_children
.GetCount(),
1079 _T("GetItem index is out of range") );
1081 return m_children
.Item( index
)->GetData();
1084 bool wxSizer::Show( wxWindow
*window
, bool show
, bool recursive
)
1086 wxSizerItem
*item
= GetItem( window
, recursive
);
1097 bool wxSizer::Show( wxSizer
*sizer
, bool show
, bool recursive
)
1099 wxSizerItem
*item
= GetItem( sizer
, recursive
);
1110 bool wxSizer::Show( size_t index
, bool show
)
1112 wxSizerItem
*item
= GetItem( index
);
1123 void wxSizer::ShowItems( bool show
)
1125 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1128 node
->GetData()->Show( show
);
1129 node
= node
->GetNext();
1133 bool wxSizer::IsShown( wxWindow
*window
) const
1135 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1138 wxSizerItem
*item
= node
->GetData();
1140 if (item
->GetWindow() == window
)
1142 return item
->IsShown();
1144 node
= node
->GetNext();
1147 wxFAIL_MSG( _T("IsShown failed to find sizer item") );
1152 bool wxSizer::IsShown( wxSizer
*sizer
) const
1154 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1157 wxSizerItem
*item
= node
->GetData();
1159 if (item
->GetSizer() == sizer
)
1161 return item
->IsShown();
1163 node
= node
->GetNext();
1166 wxFAIL_MSG( _T("IsShown failed to find sizer item") );
1171 bool wxSizer::IsShown( size_t index
) const
1173 wxCHECK_MSG( index
< m_children
.GetCount(),
1175 _T("IsShown index is out of range") );
1177 return m_children
.Item( index
)->GetData()->IsShown();
1181 //---------------------------------------------------------------------------
1183 //---------------------------------------------------------------------------
1185 wxGridSizer::wxGridSizer( int rows
, int cols
, int vgap
, int hgap
)
1186 : m_rows( ( cols
== 0 && rows
== 0 ) ? 1 : rows
)
1193 wxGridSizer::wxGridSizer( int cols
, int vgap
, int hgap
)
1194 : m_rows( cols
== 0 ? 1 : 0 )
1201 int wxGridSizer::CalcRowsCols(int& nrows
, int& ncols
) const
1203 int nitems
= m_children
.GetCount();
1209 nrows
= (nitems
+ m_cols
- 1) / m_cols
;
1213 ncols
= (nitems
+ m_rows
- 1) / m_rows
;
1216 else // 0 columns, 0 rows?
1218 wxFAIL_MSG( _T("grid sizer must have either rows or columns fixed") );
1227 void wxGridSizer::RecalcSizes()
1229 int nitems
, nrows
, ncols
;
1230 if ( (nitems
= CalcRowsCols(nrows
, ncols
)) == 0 )
1233 wxSize
sz( GetSize() );
1234 wxPoint
pt( GetPosition() );
1236 int w
= (sz
.x
- (ncols
- 1) * m_hgap
) / ncols
;
1237 int h
= (sz
.y
- (nrows
- 1) * m_vgap
) / nrows
;
1240 for (int c
= 0; c
< ncols
; c
++)
1243 for (int r
= 0; r
< nrows
; r
++)
1245 int i
= r
* ncols
+ c
;
1248 wxSizerItemList::compatibility_iterator node
= m_children
.Item( i
);
1250 wxASSERT_MSG( node
, _T("Failed to find SizerItemList node") );
1252 SetItemBounds( node
->GetData(), x
, y
, w
, h
);
1260 wxSize
wxGridSizer::CalcMin()
1263 if ( CalcRowsCols(nrows
, ncols
) == 0 )
1266 // Find the max width and height for any component
1270 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1273 wxSizerItem
*item
= node
->GetData();
1274 wxSize
sz( item
->CalcMin() );
1276 w
= wxMax( w
, sz
.x
);
1277 h
= wxMax( h
, sz
.y
);
1279 node
= node
->GetNext();
1282 return wxSize( ncols
* w
+ (ncols
-1) * m_hgap
,
1283 nrows
* h
+ (nrows
-1) * m_vgap
);
1286 void wxGridSizer::SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
)
1289 wxSize
sz( item
->GetMinSizeWithBorder() );
1290 int flag
= item
->GetFlag();
1292 if ((flag
& wxEXPAND
) || (flag
& wxSHAPED
))
1298 if (flag
& wxALIGN_CENTER_HORIZONTAL
)
1300 pt
.x
= x
+ (w
- sz
.x
) / 2;
1302 else if (flag
& wxALIGN_RIGHT
)
1304 pt
.x
= x
+ (w
- sz
.x
);
1307 if (flag
& wxALIGN_CENTER_VERTICAL
)
1309 pt
.y
= y
+ (h
- sz
.y
) / 2;
1311 else if (flag
& wxALIGN_BOTTOM
)
1313 pt
.y
= y
+ (h
- sz
.y
);
1317 item
->SetDimension(pt
, sz
);
1320 //---------------------------------------------------------------------------
1322 //---------------------------------------------------------------------------
1324 wxFlexGridSizer::wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
)
1325 : wxGridSizer( rows
, cols
, vgap
, hgap
),
1326 m_flexDirection(wxBOTH
),
1327 m_growMode(wxFLEX_GROWMODE_SPECIFIED
)
1331 wxFlexGridSizer::wxFlexGridSizer( int cols
, int vgap
, int hgap
)
1332 : wxGridSizer( cols
, vgap
, hgap
),
1333 m_flexDirection(wxBOTH
),
1334 m_growMode(wxFLEX_GROWMODE_SPECIFIED
)
1338 wxFlexGridSizer::~wxFlexGridSizer()
1342 void wxFlexGridSizer::RecalcSizes()
1344 int nitems
, nrows
, ncols
;
1345 if ( (nitems
= CalcRowsCols(nrows
, ncols
)) == 0 )
1348 wxPoint
pt( GetPosition() );
1349 wxSize
sz( GetSize() );
1351 AdjustForGrowables(sz
, m_calculatedMinSize
, nrows
, ncols
);
1353 sz
= wxSize( pt
.x
+ sz
.x
, pt
.y
+ sz
.y
);
1356 for (int c
= 0; c
< ncols
; c
++)
1359 for (int r
= 0; r
< nrows
; r
++)
1361 int i
= r
* ncols
+ c
;
1364 wxSizerItemList::compatibility_iterator node
= m_children
.Item( i
);
1366 wxASSERT_MSG( node
, _T("Failed to find node") );
1368 int w
= wxMax( 0, wxMin( m_colWidths
[c
], sz
.x
- x
) );
1369 int h
= wxMax( 0, wxMin( m_rowHeights
[r
], sz
.y
- y
) );
1371 SetItemBounds( node
->GetData(), x
, y
, w
, h
);
1373 if (m_rowHeights
[r
] != -1)
1374 y
= y
+ m_rowHeights
[r
] + m_vgap
;
1376 if (m_colWidths
[c
] != -1)
1377 x
= x
+ m_colWidths
[c
] + m_hgap
;
1381 wxSize
wxFlexGridSizer::CalcMin()
1387 // Number of rows/columns can change as items are added or removed.
1388 if ( !CalcRowsCols(nrows
, ncols
) )
1391 m_rowHeights
.SetCount(nrows
);
1392 m_colWidths
.SetCount(ncols
);
1394 // We have to recalcuate the sizes in case the item minimum size has
1395 // changed since the previous layout, or the item has been hidden using
1396 // wxSizer::Show(). If all the items in a row/column are hidden, the final
1397 // dimension of the row/column will be -1, indicating that the column
1398 // itself is hidden.
1399 for( s
= m_rowHeights
.GetCount(), i
= 0; i
< s
; ++i
)
1400 m_rowHeights
[ i
] = -1;
1401 for( s
= m_colWidths
.GetCount(), i
= 0; i
< s
; ++i
)
1402 m_colWidths
[ i
] = -1;
1404 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1409 wxSizerItem
*item
= node
->GetData();
1410 if ( item
->IsShown() )
1412 wxSize
sz( item
->CalcMin() );
1413 int row
= i
/ ncols
;
1414 int col
= i
% ncols
;
1416 m_rowHeights
[ row
] = wxMax( wxMax( 0, sz
.y
), m_rowHeights
[ row
] );
1417 m_colWidths
[ col
] = wxMax( wxMax( 0, sz
.x
), m_colWidths
[ col
] );
1420 node
= node
->GetNext();
1424 AdjustForFlexDirection();
1426 // Sum total minimum size, including gaps between rows/columns.
1427 // -1 is used as a magic number meaning empty column.
1429 for (int col
= 0; col
< ncols
; col
++)
1430 if ( m_colWidths
[ col
] != -1 )
1431 width
+= m_colWidths
[ col
] + m_hgap
;
1436 for (int row
= 0; row
< nrows
; row
++)
1437 if ( m_rowHeights
[ row
] != -1 )
1438 height
+= m_rowHeights
[ row
] + m_vgap
;
1442 m_calculatedMinSize
= wxSize( width
, height
);
1443 return m_calculatedMinSize
;
1446 void wxFlexGridSizer::AdjustForFlexDirection()
1448 // the logic in CalcMin works when we resize flexibly in both directions
1449 // but maybe this is not the case
1450 if ( m_flexDirection
!= wxBOTH
)
1452 // select the array corresponding to the direction in which we do *not*
1454 wxArrayInt
& array
= m_flexDirection
== wxVERTICAL
? m_colWidths
1457 const size_t count
= array
.GetCount();
1459 // find the largest value in this array
1463 for ( n
= 0; n
< count
; ++n
)
1465 if ( array
[n
] > largest
)
1469 // and now fill it with the largest value
1470 for ( n
= 0; n
< count
; ++n
)
1478 void wxFlexGridSizer::AdjustForGrowables(const wxSize
& sz
, const wxSize
& minsz
,
1479 int nrows
, int ncols
)
1481 // what to do with the rows? by default, resize them proportionally
1482 if ( sz
.y
> minsz
.y
&& ( (m_flexDirection
& wxVERTICAL
) || (m_growMode
== wxFLEX_GROWMODE_SPECIFIED
) ) )
1484 int sum_proportions
= 0;
1485 int growable_space
= 0;
1488 for (idx
= 0; idx
< m_growableRows
.GetCount(); idx
++)
1490 // Since the number of rows/columns can change as items are
1491 // inserted/deleted, we need to verify at runtime that the
1492 // requested growable rows/columns are still valid.
1493 if (m_growableRows
[idx
] >= nrows
)
1496 // If all items in a row/column are hidden, that row/column will
1497 // have a dimension of -1. This causes the row/column to be
1498 // hidden completely.
1499 if (m_rowHeights
[ m_growableRows
[idx
] ] == -1)
1501 sum_proportions
+= m_growableRowsProportions
[idx
];
1502 growable_space
+= m_rowHeights
[ m_growableRows
[idx
] ];
1508 for (idx
= 0; idx
< m_growableRows
.GetCount(); idx
++)
1510 if (m_growableRows
[idx
] >= nrows
)
1512 if (m_rowHeights
[ m_growableRows
[idx
] ] == -1)
1513 m_rowHeights
[ m_growableRows
[idx
] ] = 0;
1516 int delta
= (sz
.y
- minsz
.y
);
1517 if (sum_proportions
== 0)
1518 delta
= (delta
/num
) + m_rowHeights
[ m_growableRows
[idx
] ];
1520 delta
= ((delta
+growable_space
)*m_growableRowsProportions
[idx
]) / sum_proportions
;
1521 m_rowHeights
[ m_growableRows
[idx
] ] = delta
;
1526 else if ( (m_growMode
== wxFLEX_GROWMODE_ALL
) && (sz
.y
> minsz
.y
) )
1528 // rounding problem?
1529 for ( int row
= 0; row
< nrows
; ++row
)
1530 m_rowHeights
[ row
] = sz
.y
/ nrows
;
1533 // the same logic as above but for the columns
1534 if ( sz
.x
> minsz
.x
&& ( (m_flexDirection
& wxHORIZONTAL
) || (m_growMode
== wxFLEX_GROWMODE_SPECIFIED
) ) )
1536 int sum_proportions
= 0;
1537 int growable_space
= 0;
1540 for (idx
= 0; idx
< m_growableCols
.GetCount(); idx
++)
1542 // Since the number of rows/columns can change as items are
1543 // inserted/deleted, we need to verify at runtime that the
1544 // requested growable rows/columns are still valid.
1545 if (m_growableCols
[idx
] >= ncols
)
1548 // If all items in a row/column are hidden, that row/column will
1549 // have a dimension of -1. This causes the column to be hidden
1551 if (m_colWidths
[ m_growableCols
[idx
] ] == -1)
1553 sum_proportions
+= m_growableColsProportions
[idx
];
1554 growable_space
+= m_colWidths
[ m_growableCols
[idx
] ];
1560 for (idx
= 0; idx
< m_growableCols
.GetCount(); idx
++)
1562 if (m_growableCols
[idx
] >= ncols
)
1564 if (m_colWidths
[ m_growableCols
[idx
] ] == -1)
1565 m_colWidths
[ m_growableCols
[idx
] ] = 0;
1568 int delta
= (sz
.x
- minsz
.x
);
1569 if (sum_proportions
== 0)
1570 delta
= (delta
/num
) + m_colWidths
[ m_growableCols
[idx
] ];
1572 delta
= ((delta
+growable_space
)*m_growableColsProportions
[idx
])/sum_proportions
;
1573 m_colWidths
[ m_growableCols
[idx
] ] = delta
;
1578 else if ( (m_growMode
== wxFLEX_GROWMODE_ALL
) && (sz
.x
> minsz
.x
) )
1580 for ( int col
=0; col
< ncols
; ++col
)
1581 m_colWidths
[ col
] = sz
.x
/ ncols
;
1586 void wxFlexGridSizer::AddGrowableRow( size_t idx
, int proportion
)
1588 m_growableRows
.Add( idx
);
1589 m_growableRowsProportions
.Add( proportion
);
1592 void wxFlexGridSizer::AddGrowableCol( size_t idx
, int proportion
)
1594 m_growableCols
.Add( idx
);
1595 m_growableColsProportions
.Add( proportion
);
1598 // helper function for RemoveGrowableCol/Row()
1600 DoRemoveFromArrays(size_t idx
, wxArrayInt
& items
, wxArrayInt
& proportions
)
1602 const size_t count
= items
.size();
1603 for ( size_t n
= 0; n
< count
; n
++ )
1605 if ( (size_t)items
[n
] == idx
)
1608 proportions
.RemoveAt(n
);
1613 wxFAIL_MSG( _T("column/row is already not growable") );
1616 void wxFlexGridSizer::RemoveGrowableCol( size_t idx
)
1618 DoRemoveFromArrays(idx
, m_growableCols
, m_growableColsProportions
);
1621 void wxFlexGridSizer::RemoveGrowableRow( size_t idx
)
1623 DoRemoveFromArrays(idx
, m_growableRows
, m_growableRowsProportions
);
1626 //---------------------------------------------------------------------------
1628 //---------------------------------------------------------------------------
1630 wxBoxSizer::wxBoxSizer( int orient
)
1631 : m_orient( orient
)
1635 void wxBoxSizer::RecalcSizes()
1637 if (m_children
.GetCount() == 0)
1643 if (m_orient
== wxHORIZONTAL
)
1644 delta
= m_size
.x
- m_fixedWidth
;
1646 delta
= m_size
.y
- m_fixedHeight
;
1649 wxPoint
pt( m_position
);
1651 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1654 wxSizerItem
*item
= node
->GetData();
1656 if (item
->IsShown())
1658 wxSize
size( item
->GetMinSizeWithBorder() );
1660 if (m_orient
== wxVERTICAL
)
1662 wxCoord height
= size
.y
;
1663 if (item
->GetProportion())
1665 // Because of at least one visible item has non-zero
1666 // proportion then m_stretchable is not zero
1667 height
= (delta
* item
->GetProportion()) / m_stretchable
;
1670 wxPoint
child_pos( pt
);
1671 wxSize
child_size( size
.x
, height
);
1673 if (item
->GetFlag() & (wxEXPAND
| wxSHAPED
))
1674 child_size
.x
= m_size
.x
;
1675 else if (item
->GetFlag() & wxALIGN_RIGHT
)
1676 child_pos
.x
+= m_size
.x
- size
.x
;
1677 else if (item
->GetFlag() & (wxCENTER
| wxALIGN_CENTER_HORIZONTAL
))
1678 // XXX wxCENTER is added for backward compatibility;
1679 // wxALIGN_CENTER should be used in new code
1680 child_pos
.x
+= (m_size
.x
- size
.x
) / 2;
1682 item
->SetDimension( child_pos
, child_size
);
1688 wxCoord width
= size
.x
;
1689 if (item
->GetProportion())
1691 // Because of at least one visible item has non-zero
1692 // proportion then m_stretchable is not zero
1693 width
= (delta
* item
->GetProportion()) / m_stretchable
;
1696 wxPoint
child_pos( pt
);
1697 wxSize
child_size( width
, size
.y
);
1699 if (item
->GetFlag() & (wxEXPAND
| wxSHAPED
))
1700 child_size
.y
= m_size
.y
;
1701 else if (item
->GetFlag() & wxALIGN_BOTTOM
)
1702 child_pos
.y
+= m_size
.y
- size
.y
;
1703 else if (item
->GetFlag() & (wxCENTER
| wxALIGN_CENTER_VERTICAL
))
1704 // XXX wxCENTER is added for backward compatibility;
1705 // wxALIGN_CENTER should be used in new code
1706 child_pos
.y
+= (m_size
.y
- size
.y
) / 2;
1708 if ( m_containingWindow
)
1710 child_pos
.x
= m_containingWindow
->AdjustForLayoutDirection
1718 item
->SetDimension( child_pos
, child_size
);
1724 node
= node
->GetNext();
1728 wxSize
wxBoxSizer::CalcMin()
1730 if (m_children
.GetCount() == 0)
1739 // precalc item minsizes and count proportions
1740 wxSizerItemList::compatibility_iterator node
= m_children
.GetFirst();
1743 wxSizerItem
*item
= node
->GetData();
1745 if ( item
->IsShown() )
1747 item
->CalcMin(); // result is stored in the item
1749 m_stretchable
+= item
->GetProportion();
1752 node
= node
->GetNext();
1755 // Total minimum size (width or height) of sizer
1758 node
= m_children
.GetFirst();
1761 wxSizerItem
*item
= node
->GetData();
1763 if (item
->IsShown() && item
->GetProportion() != 0)
1765 int stretch
= item
->GetProportion();
1766 wxSize
size( item
->GetMinSizeWithBorder() );
1769 // Integer division rounded up is (a + b - 1) / b
1770 // Round up needed in order to guarantee that all
1771 // all items will have size not less then their min size
1772 if (m_orient
== wxHORIZONTAL
)
1773 minSize
= ( size
.x
*m_stretchable
+ stretch
- 1)/stretch
;
1775 minSize
= ( size
.y
*m_stretchable
+ stretch
- 1)/stretch
;
1777 if (minSize
> maxMinSize
)
1778 maxMinSize
= minSize
;
1780 node
= node
->GetNext();
1783 // Calculate overall minimum size
1784 node
= m_children
.GetFirst();
1787 wxSizerItem
*item
= node
->GetData();
1789 if (item
->IsShown())
1791 wxSize
size( item
->GetMinSizeWithBorder() );
1792 if (item
->GetProportion() != 0)
1794 if (m_orient
== wxHORIZONTAL
)
1795 size
.x
= (maxMinSize
*item
->GetProportion())/m_stretchable
;
1797 size
.y
= (maxMinSize
*item
->GetProportion())/m_stretchable
;
1801 if (m_orient
== wxVERTICAL
)
1803 m_fixedHeight
+= size
.y
;
1804 m_fixedWidth
= wxMax( m_fixedWidth
, size
.x
);
1808 m_fixedWidth
+= size
.x
;
1809 m_fixedHeight
= wxMax( m_fixedHeight
, size
.y
);
1813 if (m_orient
== wxHORIZONTAL
)
1815 m_minWidth
+= size
.x
;
1816 m_minHeight
= wxMax( m_minHeight
, size
.y
);
1820 m_minHeight
+= size
.y
;
1821 m_minWidth
= wxMax( m_minWidth
, size
.x
);
1824 node
= node
->GetNext();
1827 return wxSize( m_minWidth
, m_minHeight
);
1830 //---------------------------------------------------------------------------
1832 //---------------------------------------------------------------------------
1836 wxStaticBoxSizer::wxStaticBoxSizer( wxStaticBox
*box
, int orient
)
1837 : wxBoxSizer( orient
),
1840 wxASSERT_MSG( box
, wxT("wxStaticBoxSizer needs a static box") );
1842 // do this so that our Detach() is called if the static box is destroyed
1844 m_staticBox
->SetContainingSizer(this);
1847 wxStaticBoxSizer::wxStaticBoxSizer(int orient
, wxWindow
*win
, const wxString
& s
)
1848 : wxBoxSizer(orient
),
1849 m_staticBox(new wxStaticBox(win
, wxID_ANY
, s
))
1852 m_staticBox
->SetContainingSizer(this);
1855 wxStaticBoxSizer::~wxStaticBoxSizer()
1860 static void GetStaticBoxBorders( wxStaticBox
*box
,
1864 // this has to be done platform by platform as there is no way to
1865 // guess the thickness of a wxStaticBox border
1866 box
->GetBordersForSizer(borderTop
, borderOther
);
1869 void wxStaticBoxSizer::RecalcSizes()
1871 int top_border
, other_border
;
1872 GetStaticBoxBorders(m_staticBox
, &top_border
, &other_border
);
1874 m_staticBox
->SetSize( m_position
.x
, m_position
.y
, m_size
.x
, m_size
.y
);
1876 wxPoint
old_pos( m_position
);
1877 m_position
.x
+= other_border
;
1878 m_position
.y
+= top_border
;
1879 wxSize
old_size( m_size
);
1880 m_size
.x
-= 2*other_border
;
1881 m_size
.y
-= top_border
+ other_border
;
1883 wxBoxSizer::RecalcSizes();
1885 m_position
= old_pos
;
1889 wxSize
wxStaticBoxSizer::CalcMin()
1891 int top_border
, other_border
;
1892 GetStaticBoxBorders(m_staticBox
, &top_border
, &other_border
);
1894 wxSize
ret( wxBoxSizer::CalcMin() );
1895 ret
.x
+= 2*other_border
;
1896 ret
.y
+= other_border
+ top_border
;
1901 void wxStaticBoxSizer::ShowItems( bool show
)
1903 m_staticBox
->Show( show
);
1904 wxBoxSizer::ShowItems( show
);
1907 bool wxStaticBoxSizer::Detach( wxWindow
*window
)
1909 // avoid deleting m_staticBox in our dtor if it's being detached from the
1910 // sizer (which can happen because it's being already destroyed for
1912 if ( window
== m_staticBox
)
1918 return wxSizer::Detach( window
);
1921 #endif // wxUSE_STATBOX
1925 wxStdDialogButtonSizer::wxStdDialogButtonSizer()
1926 : wxBoxSizer(wxHORIZONTAL
)
1928 // Vertical buttons with lots of space on either side
1929 // looks rubbish on WinCE, so let's not do this for now.
1930 // If we are going to use vertical buttons, we should
1931 // put the sizer to the right of other controls in the dialog,
1932 // and that's beyond the scope of this sizer.
1934 bool is_pda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
1935 // If we have a PDA screen, put yes/no button over
1936 // all other buttons, otherwise on the left side.
1938 m_orient
= wxVERTICAL
;
1941 m_buttonAffirmative
= NULL
;
1942 m_buttonApply
= NULL
;
1943 m_buttonNegative
= NULL
;
1944 m_buttonCancel
= NULL
;
1945 m_buttonHelp
= NULL
;
1948 void wxStdDialogButtonSizer::AddButton(wxButton
*mybutton
)
1950 switch (mybutton
->GetId())
1955 m_buttonAffirmative
= mybutton
;
1958 m_buttonApply
= mybutton
;
1961 m_buttonNegative
= mybutton
;
1964 m_buttonCancel
= mybutton
;
1967 case wxID_CONTEXT_HELP
:
1968 m_buttonHelp
= mybutton
;
1975 void wxStdDialogButtonSizer::SetAffirmativeButton( wxButton
*button
)
1977 m_buttonAffirmative
= button
;
1980 void wxStdDialogButtonSizer::SetNegativeButton( wxButton
*button
)
1982 m_buttonNegative
= button
;
1985 void wxStdDialogButtonSizer::SetCancelButton( wxButton
*button
)
1987 m_buttonCancel
= button
;
1990 void wxStdDialogButtonSizer::Realize()
1993 Add(0, 0, 0, wxLEFT
, 6);
1995 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 6);
1997 if (m_buttonNegative
){
1998 // HIG POLICE BULLETIN - destructive buttons need extra padding
1999 // 24 pixels on either side
2000 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 12);
2003 // extra whitespace between help/negative and cancel/ok buttons
2004 Add(0, 0, 1, wxEXPAND
, 0);
2006 if (m_buttonCancel
){
2007 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 6);
2008 // Cancel or help should be default
2009 // m_buttonCancel->SetDefaultButton();
2012 // Ugh, Mac doesn't really have apply dialogs, so I'll just
2013 // figure the best place is between Cancel and OK
2015 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 6);
2017 if (m_buttonAffirmative
){
2018 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
, 6);
2020 if (m_buttonAffirmative
->GetId() == wxID_SAVE
){
2021 // these buttons have set labels under Mac so we should use them
2022 m_buttonAffirmative
->SetLabel(_("Save"));
2023 m_buttonNegative
->SetLabel(_("Don't Save"));
2027 // Extra space around and at the right
2029 #elif defined(__WXGTK20__)
2030 Add(0, 0, 0, wxLEFT
, 9);
2032 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
2034 // extra whitespace between help and cancel/ok buttons
2035 Add(0, 0, 1, wxEXPAND
, 0);
2037 if (m_buttonNegative
){
2038 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
2041 if (m_buttonCancel
){
2042 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
2043 // Cancel or help should be default
2044 // m_buttonCancel->SetDefaultButton();
2048 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, 3);
2050 if (m_buttonAffirmative
)
2051 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
, 6);
2052 #elif defined(__WXMSW__)
2055 // right-justify buttons
2056 Add(0, 0, 1, wxEXPAND
, 0);
2058 if (m_buttonAffirmative
){
2059 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonAffirmative
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2062 if (m_buttonNegative
){
2063 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonNegative
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2066 if (m_buttonCancel
){
2067 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonCancel
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2070 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonApply
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2073 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonHelp
->ConvertDialogToPixels(wxSize(2, 0)).x
);
2075 // GTK+1 and any other platform
2077 // Add(0, 0, 0, wxLEFT, 5); // Not sure what this was for but it unbalances the dialog
2079 Add((wxWindow
*)m_buttonHelp
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonHelp
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2081 // extra whitespace between help and cancel/ok buttons
2082 Add(0, 0, 1, wxEXPAND
, 0);
2085 Add((wxWindow
*)m_buttonApply
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonApply
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2087 if (m_buttonAffirmative
){
2088 Add((wxWindow
*)m_buttonAffirmative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonAffirmative
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2091 if (m_buttonNegative
){
2092 Add((wxWindow
*)m_buttonNegative
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonNegative
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2095 if (m_buttonCancel
){
2096 Add((wxWindow
*)m_buttonCancel
, 0, wxALIGN_CENTRE
| wxLEFT
| wxRIGHT
, m_buttonCancel
->ConvertDialogToPixels(wxSize(4, 0)).x
);
2097 // Cancel or help should be default
2098 // m_buttonCancel->SetDefaultButton();
2104 #endif // wxUSE_BUTTON
2106 #if WXWIN_COMPATIBILITY_2_4
2108 // ----------------------------------------------------------------------------
2110 // ----------------------------------------------------------------------------
2113 IMPLEMENT_CLASS(wxBookCtrlSizer
, wxSizer
)
2115 IMPLEMENT_CLASS(wxNotebookSizer
, wxBookCtrlSizer
)
2116 #endif // wxUSE_NOTEBOOK
2117 #endif // wxUSE_BOOKCTRL
2121 #if WXWIN_COMPATIBILITY_2_6
2123 wxBookCtrlSizer::wxBookCtrlSizer(wxBookCtrlBase
*bookctrl
)
2124 : m_bookctrl(bookctrl
)
2126 wxASSERT_MSG( bookctrl
, wxT("wxBookCtrlSizer needs a control") );
2129 #endif // WXWIN_COMPATIBILITY_2_6
2131 void wxBookCtrlSizer::RecalcSizes()
2133 m_bookctrl
->SetSize( m_position
.x
, m_position
.y
, m_size
.x
, m_size
.y
);
2136 wxSize
wxBookCtrlSizer::CalcMin()
2138 wxSize sizeBorder
= m_bookctrl
->CalcSizeFromPage(wxSize(0,0));
2143 if ( m_bookctrl
->GetPageCount() == 0 )
2145 return wxSize(sizeBorder
.x
+ 10, sizeBorder
.y
+ 10);
2151 wxWindowList::compatibility_iterator
2152 node
= m_bookctrl
->GetChildren().GetFirst();
2155 wxWindow
*item
= node
->GetData();
2156 wxSizer
*itemsizer
= item
->GetSizer();
2160 wxSize
subsize( itemsizer
->CalcMin() );
2162 if (subsize
.x
> maxX
)
2164 if (subsize
.y
> maxY
)
2168 node
= node
->GetNext();
2171 return wxSize( maxX
, maxY
) + sizeBorder
;
2176 #if WXWIN_COMPATIBILITY_2_6
2178 wxNotebookSizer::wxNotebookSizer(wxNotebook
*nb
)
2180 wxASSERT_MSG( nb
, wxT("wxNotebookSizer needs a control") );
2184 #endif // WXWIN_COMPATIBILITY_2_6
2186 #endif // wxUSE_NOTEBOOOK
2187 #endif // wxUSE_BOOKCTRL
2189 #endif // WXWIN_COMPATIBILITY_2_4