1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: provide new wxSizer class for layout
4 // Author: Robert Roebling and Robin Dunn
5 // Modified by: Ron Lee
8 // Copyright: (c) Robin Dunn, Dirk Holtwick and Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "sizer.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
25 #include "wx/statbox.h"
26 #include "wx/notebook.h"
28 //---------------------------------------------------------------------------
30 IMPLEMENT_ABSTRACT_CLASS(wxSizerItem
, wxObject
)
31 IMPLEMENT_ABSTRACT_CLASS(wxSizer
, wxObject
)
32 IMPLEMENT_ABSTRACT_CLASS(wxGridSizer
, wxSizer
)
33 IMPLEMENT_ABSTRACT_CLASS(wxFlexGridSizer
, wxGridSizer
)
34 IMPLEMENT_ABSTRACT_CLASS(wxBoxSizer
, wxSizer
)
36 IMPLEMENT_ABSTRACT_CLASS(wxStaticBoxSizer
, wxBoxSizer
)
39 IMPLEMENT_ABSTRACT_CLASS(wxNotebookSizer
, wxSizer
)
42 //---------------------------------------------------------------------------
44 //---------------------------------------------------------------------------
46 wxSizerItem::wxSizerItem( int width
, int height
, int option
, int flag
, int border
, wxObject
* userData
)
48 m_window
= (wxWindow
*) NULL
;
49 m_sizer
= (wxSizer
*) NULL
;
53 m_userData
= userData
;
55 // minimal size is the initial size
59 SetRatio(width
, height
);
61 // size is set directly
65 wxSizerItem::wxSizerItem( wxWindow
*window
, int option
, int flag
, int border
, wxObject
* userData
)
68 m_sizer
= (wxSizer
*) NULL
;
72 m_userData
= userData
;
74 // minimal size is the initial size
75 m_minSize
= window
->GetSize();
77 // aspect ratio calculated from initial size
80 // size is calculated later
84 wxSizerItem::wxSizerItem( wxSizer
*sizer
, int option
, int flag
, int border
, wxObject
* userData
)
86 m_window
= (wxWindow
*) NULL
;
91 m_userData
= userData
;
93 // minimal size is calculated later
97 // size is calculated later
101 wxSizerItem::~wxSizerItem()
110 wxSize
wxSizerItem::GetSize()
114 ret
= m_sizer
->GetSize();
117 ret
= m_window
->GetSize();
124 if (m_flag
& wxNORTH
)
126 if (m_flag
& wxSOUTH
)
132 wxSize
wxSizerItem::CalcMin()
137 ret
= m_sizer
->GetMinSize();
139 // if we have to preserve aspect ratio _AND_ this is
140 // the first-time calculation, consider ret to be initial size
141 if ((m_flag
& wxSHAPED
) && !m_ratio
)
146 if ( IsWindow() && (m_flag
& wxADJUST_MINSIZE
) )
148 // check if the best (minimal, in fact) window size hadn't changed
149 // by chance: this may happen for, e.g. static text if its label
151 wxSize size
= m_window
->GetBestSize();
152 if ( size
.x
> m_minSize
.x
)
153 m_minSize
.x
= size
.x
;
154 if ( size
.y
> m_minSize
.y
)
155 m_minSize
.y
= size
.y
;
165 if (m_flag
& wxNORTH
)
167 if (m_flag
& wxSOUTH
)
173 void wxSizerItem::SetDimension( wxPoint pos
, wxSize size
)
175 if (m_flag
& wxSHAPED
)
177 // adjust aspect ratio
178 int rwidth
= (int) (size
.y
* m_ratio
);
182 int rheight
= (int) (size
.x
/ m_ratio
);
183 // add vertical space
184 if (m_flag
& wxALIGN_CENTER_VERTICAL
)
185 pos
.y
+= (size
.y
- rheight
) / 2;
186 else if (m_flag
& wxALIGN_BOTTOM
)
187 pos
.y
+= (size
.y
- rheight
);
188 // use reduced dimensions
191 else if (rwidth
< size
.x
)
193 // add horizontal space
194 if (m_flag
& wxALIGN_CENTER_HORIZONTAL
)
195 pos
.x
+= (size
.x
- rwidth
) / 2;
196 else if (m_flag
& wxALIGN_RIGHT
)
197 pos
.x
+= (size
.x
- rwidth
);
202 // This is what GetPosition() returns. Since we calculate
203 // borders afterwards, GetPosition() will be the left/top
204 // corner of the surrounding border.
216 if (m_flag
& wxNORTH
)
221 if (m_flag
& wxSOUTH
)
227 m_sizer
->SetDimension( pos
.x
, pos
.y
, size
.x
, size
.y
);
230 m_window
->SetSize( pos
.x
, pos
.y
, size
.x
, size
.y
, wxSIZE_ALLOW_MINUS_ONE
);
235 void wxSizerItem::DeleteWindows()
241 m_sizer
->DeleteWindows();
244 bool wxSizerItem::IsWindow()
246 return (m_window
!= NULL
);
249 bool wxSizerItem::IsSizer()
251 return (m_sizer
!= NULL
);
254 bool wxSizerItem::IsSpacer()
256 return (m_window
== NULL
) && (m_sizer
== NULL
);
259 //---------------------------------------------------------------------------
261 //---------------------------------------------------------------------------
265 m_children
.DeleteContents( TRUE
);
275 void wxSizer::Add( wxWindow
*window
, int option
, int flag
, int border
, wxObject
* userData
)
277 m_children
.Append( new wxSizerItem( window
, option
, flag
, border
, userData
) );
278 window
->SetContainingSizer(this);
281 void wxSizer::Add( wxSizer
*sizer
, int option
, int flag
, int border
, wxObject
* userData
)
283 m_children
.Append( new wxSizerItem( sizer
, option
, flag
, border
, userData
) );
286 void wxSizer::Add( int width
, int height
, int option
, int flag
, int border
, wxObject
* userData
)
288 m_children
.Append( new wxSizerItem( width
, height
, option
, flag
, border
, userData
) );
291 void wxSizer::Prepend( wxWindow
*window
, int option
, int flag
, int border
, wxObject
* userData
)
293 m_children
.Insert( new wxSizerItem( window
, option
, flag
, border
, userData
) );
294 window
->SetContainingSizer(this);
297 void wxSizer::Prepend( wxSizer
*sizer
, int option
, int flag
, int border
, wxObject
* userData
)
299 m_children
.Insert( new wxSizerItem( sizer
, option
, flag
, border
, userData
) );
302 void wxSizer::Prepend( int width
, int height
, int option
, int flag
, int border
, wxObject
* userData
)
304 m_children
.Insert( new wxSizerItem( width
, height
, option
, flag
, border
, userData
) );
307 void wxSizer::Insert( int before
, wxWindow
*window
, int option
, int flag
, int border
, wxObject
* userData
)
309 m_children
.Insert( before
, new wxSizerItem( window
, option
, flag
, border
, userData
) );
310 window
->SetContainingSizer(this);
313 void wxSizer::Insert( int before
, wxSizer
*sizer
, int option
, int flag
, int border
, wxObject
* userData
)
315 m_children
.Insert( before
, new wxSizerItem( sizer
, option
, flag
, border
, userData
) );
318 void wxSizer::Insert( int before
, int width
, int height
, int option
, int flag
, int border
, wxObject
* userData
)
320 m_children
.Insert( before
, new wxSizerItem( width
, height
, option
, flag
, border
, userData
) );
323 bool wxSizer::Remove( wxWindow
*window
)
327 wxNode
*node
= m_children
.First();
330 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
331 if (item
->GetWindow() == window
)
333 item
->GetWindow()->SetContainingSizer(NULL
);
334 m_children
.DeleteNode( node
);
343 bool wxSizer::Remove( wxSizer
*sizer
)
347 wxNode
*node
= m_children
.First();
350 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
351 if (item
->GetSizer() == sizer
)
353 m_children
.DeleteNode( node
);
362 bool wxSizer::Remove( int pos
)
364 wxNode
*node
= m_children
.Nth( pos
);
365 if (!node
) return FALSE
;
367 m_children
.DeleteNode( node
);
372 void wxSizer::Clear( bool delete_windows
)
374 // First clear the ContainingSizer pointers
375 wxNode
*node
= m_children
.First();
378 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
379 if (item
->IsWindow())
380 item
->GetWindow()->SetContainingSizer(NULL
);
384 // Destroy the windows if needed
388 // Now empty the list
392 void wxSizer::DeleteWindows()
394 wxNode
*node
= m_children
.First();
397 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
398 item
->DeleteWindows();
403 void wxSizer::Fit( wxWindow
*window
)
406 if (window
->IsTopLevel())
407 size
= FitSize( window
);
409 size
= GetMinWindowSize( window
);
411 //window->SetClientSize( size );
412 window
->SetSize( size
);
415 void wxSizer::FitInside( wxWindow
*window
)
418 if (window
->IsTopLevel())
419 size
= VirtualFitSize( window
);
421 size
= GetMinClientSize( window
);
423 window
->SetVirtualSize( size
);
426 void wxSizer::Layout()
432 void wxSizer::SetSizeHints( wxWindow
*window
)
434 // Preserve the window's max size hints, but set the
435 // lower bound according to the sizer calculations.
438 wxSize
size( window
->GetSize() );
439 window
->SetSizeHints( size
.x
,
441 window
->GetMaxWidth(),
442 window
->GetMaxHeight() );
445 void wxSizer::SetVirtualSizeHints( wxWindow
*window
)
447 // Preserve the window's max size hints, but set the
448 // lower bound according to the sizer calculations.
451 wxSize
size( window
->GetVirtualSize() );
452 window
->SetVirtualSizeHints( size
.x
,
454 window
->GetMaxWidth(),
455 window
->GetMaxHeight() );
458 wxSize
wxSizer::GetMaxWindowSize( wxWindow
*window
)
460 return window
->GetMaxSize();
463 wxSize
wxSizer::GetMinWindowSize( wxWindow
*window
)
465 wxSize
minSize( GetMinSize() );
466 wxSize
size( window
->GetSize() );
467 wxSize
client_size( window
->GetClientSize() );
468 return wxSize( minSize
.x
+size
.x
-client_size
.x
,
469 minSize
.y
+size
.y
-client_size
.y
);
472 // Return a window size that will fit within the screens dimensions
473 wxSize
wxSizer::FitSize( wxWindow
*window
)
475 wxSize size
= GetMinWindowSize( window
);
476 wxSize sizeMax
= GetMaxWindowSize( window
);
478 // Limit the size if sizeMax != wxDefaultSize
480 if ( size
.x
> sizeMax
.x
&& sizeMax
.x
!= -1 )
482 if ( size
.y
> sizeMax
.y
&& sizeMax
.y
!= -1 )
488 wxSize
wxSizer::GetMaxClientSize( wxWindow
*window
)
490 wxSize
maxSize( window
->GetMaxSize() );
492 if( maxSize
!= wxDefaultSize
)
494 wxSize
size( window
->GetSize() );
495 wxSize
client_size( window
->GetClientSize() );
497 return wxSize( maxSize
.x
+ client_size
.x
- size
.x
,
498 maxSize
.y
+ client_size
.y
- size
.y
);
501 return wxDefaultSize
;
504 wxSize
wxSizer::GetMinClientSize( wxWindow
*window
)
506 return GetMinSize(); // Already returns client size.
509 wxSize
wxSizer::VirtualFitSize( wxWindow
*window
)
511 wxSize size
= GetMinClientSize( window
);
512 wxSize sizeMax
= GetMaxClientSize( window
);
514 // Limit the size if sizeMax != wxDefaultSize
516 if ( size
.x
> sizeMax
.x
&& sizeMax
.x
!= -1 )
518 if ( size
.y
> sizeMax
.y
&& sizeMax
.y
!= -1 )
524 void wxSizer::SetDimension( int x
, int y
, int width
, int height
)
534 wxSize
wxSizer::GetMinSize()
536 wxSize
ret( CalcMin() );
537 if (ret
.x
< m_minSize
.x
) ret
.x
= m_minSize
.x
;
538 if (ret
.y
< m_minSize
.y
) ret
.y
= m_minSize
.y
;
542 void wxSizer::DoSetMinSize( int width
, int height
)
545 m_minSize
.y
= height
;
548 bool wxSizer::DoSetItemMinSize( wxWindow
*window
, int width
, int height
)
552 wxNode
*node
= m_children
.First();
555 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
556 if (item
->GetWindow() == window
)
558 item
->SetInitSize( width
, height
);
564 node
= m_children
.First();
567 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
568 if (item
->GetSizer())
570 /* It's a sizer, so lets search recursively. */
571 if (item
->GetSizer()->DoSetItemMinSize( window
, width
, height
))
573 /* A child sizer found the requested windw, exit. */
583 bool wxSizer::DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
)
587 wxNode
*node
= m_children
.First();
590 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
591 if (item
->GetSizer() == sizer
)
593 item
->GetSizer()->DoSetMinSize( width
, height
);
599 node
= m_children
.First();
602 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
603 if (item
->GetSizer())
605 /* It's a sizer, so lets search recursively. */
606 if (item
->GetSizer()->DoSetItemMinSize( sizer
, width
, height
))
608 /* A child sizer found the requested windw, exit. */
618 bool wxSizer::DoSetItemMinSize( int pos
, int width
, int height
)
620 wxNode
*node
= m_children
.Nth( pos
);
621 if (!node
) return FALSE
;
623 wxSizerItem
*item
= (wxSizerItem
*) node
->Data();
624 if (item
->GetSizer())
626 /* Sizers contains the minimal size in them, if not calculated ... */
627 item
->GetSizer()->DoSetMinSize( width
, height
);
631 /* ... whereas the minimal size of spacers and windows in stored
633 item
->SetInitSize( width
, height
);
639 //---------------------------------------------------------------------------
641 //---------------------------------------------------------------------------
643 wxGridSizer::wxGridSizer( int rows
, int cols
, int vgap
, int hgap
)
651 wxGridSizer::wxGridSizer( int cols
, int vgap
, int hgap
)
659 void wxGridSizer::RecalcSizes()
661 if (m_children
.GetCount() == 0)
664 int nitems
= m_children
.GetCount();
669 nrows
= (nitems
+ ncols
-1) / ncols
;
671 ncols
= (nitems
+ nrows
-1) / nrows
;
673 wxSize
sz( GetSize() );
674 wxPoint
pt( GetPosition() );
676 int w
= (sz
.x
- (ncols
- 1) * m_hgap
) / ncols
;
677 int h
= (sz
.y
- (nrows
- 1) * m_vgap
) / nrows
;
680 for (int c
= 0; c
< ncols
; c
++)
683 for (int r
= 0; r
< nrows
; r
++)
685 int i
= r
* ncols
+ c
;
688 wxNode
*node
= m_children
.Nth( i
);
691 SetItemBounds( (wxSizerItem
*) node
->Data(), x
, y
, w
, h
);
699 wxSize
wxGridSizer::CalcMin()
701 if (m_children
.GetCount() == 0)
702 return wxSize(10,10);
704 int nitems
= m_children
.GetCount();
709 nrows
= (nitems
+ ncols
-1) / ncols
;
711 ncols
= (nitems
+ nrows
-1) / nrows
;
713 /* Find the max width and height for any component */
717 wxNode
*node
= m_children
.First();
720 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
721 wxSize
sz( item
->CalcMin() );
722 w
= wxMax( w
, sz
.x
);
723 h
= wxMax( h
, sz
.y
);
728 return wxSize(ncols
* w
+ (ncols
-1) * m_hgap
,
729 nrows
* h
+ (nrows
-1) * m_vgap
);
732 void wxGridSizer::SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
)
735 wxSize
sz( item
->CalcMin() );
736 int flag
= item
->GetFlag();
738 if ((flag
& wxEXPAND
) || (flag
& wxSHAPED
))
744 if (flag
& wxALIGN_CENTER_HORIZONTAL
)
746 pt
.x
= x
+ (w
- sz
.x
) / 2;
748 else if (flag
& wxALIGN_RIGHT
)
750 pt
.x
= x
+ (w
- sz
.x
);
753 if (flag
& wxALIGN_CENTER_VERTICAL
)
755 pt
.y
= y
+ (h
- sz
.y
) / 2;
757 else if (flag
& wxALIGN_BOTTOM
)
759 pt
.y
= y
+ (h
- sz
.y
);
763 item
->SetDimension(pt
, sz
);
766 //---------------------------------------------------------------------------
768 //---------------------------------------------------------------------------
770 wxFlexGridSizer::wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
)
771 : wxGridSizer( rows
, cols
, vgap
, hgap
)
773 m_rowHeights
= (int*) NULL
;
774 m_colWidths
= (int*) NULL
;
777 wxFlexGridSizer::wxFlexGridSizer( int cols
, int vgap
, int hgap
)
778 : wxGridSizer( cols
, vgap
, hgap
)
780 m_rowHeights
= (int*) NULL
;
781 m_colWidths
= (int*) NULL
;
784 wxFlexGridSizer::~wxFlexGridSizer()
787 delete[] m_rowHeights
;
789 delete[] m_colWidths
;
792 void wxFlexGridSizer::CreateArrays()
795 delete[] m_rowHeights
;
797 delete[] m_colWidths
;
799 if (m_children
.GetCount() == 0)
802 int nitems
= m_children
.GetCount();
807 nrows
= (nitems
+ ncols
-1) / ncols
;
809 ncols
= (nitems
+ nrows
-1) / nrows
;
811 m_rowHeights
= new int[nrows
];
812 m_colWidths
= new int[ncols
];
814 for (int col
= 0; col
< ncols
; col
++)
815 m_colWidths
[ col
] = 0;
816 for (int row
= 0; row
< nrows
; row
++)
817 m_rowHeights
[ row
] = 0;
820 void wxFlexGridSizer::RecalcSizes()
822 if (m_children
.GetCount() == 0)
825 int nitems
= m_children
.GetCount();
830 nrows
= (nitems
+ ncols
-1) / ncols
;
832 ncols
= (nitems
+ nrows
-1) / nrows
;
834 wxSize
sz( GetSize() );
835 wxSize
minsz( CalcMin() );
836 wxPoint
pt( GetPosition() );
840 if ((m_growableRows
.GetCount() > 0) && (sz
.y
> minsz
.y
))
842 delta
= (sz
.y
- minsz
.y
) / m_growableRows
.GetCount();
843 for (idx
= 0; idx
< m_growableRows
.GetCount(); idx
++)
844 m_rowHeights
[ m_growableRows
[idx
] ] += delta
;
847 if ((m_growableCols
.GetCount() > 0) && (sz
.x
> minsz
.x
))
849 delta
= (sz
.x
- minsz
.x
) / m_growableCols
.GetCount();
850 for (idx
= 0; idx
< m_growableCols
.GetCount(); idx
++)
851 m_colWidths
[ m_growableCols
[idx
] ] += delta
;
854 sz
= wxSize( pt
.x
+ sz
.x
, pt
.y
+ sz
.y
);
857 for (int c
= 0; c
< ncols
; c
++)
860 for (int r
= 0; r
< nrows
; r
++)
862 int i
= r
* ncols
+ c
;
865 wxNode
*node
= m_children
.Nth( i
);
868 int w
= wxMax( 0, wxMin( m_colWidths
[c
], sz
.x
- x
) );
869 int h
= wxMax( 0, wxMin( m_rowHeights
[r
], sz
.y
- y
) );
871 SetItemBounds( (wxSizerItem
*) node
->Data(), x
, y
, w
, h
);
873 y
= y
+ m_rowHeights
[r
] + m_vgap
;
875 x
= x
+ m_colWidths
[c
] + m_hgap
;
879 wxSize
wxFlexGridSizer::CalcMin()
881 if (m_children
.GetCount() == 0)
882 return wxSize(10,10);
884 int nitems
= m_children
.GetCount();
889 nrows
= (nitems
+ ncols
-1) / ncols
;
891 ncols
= (nitems
+ nrows
-1) / nrows
;
899 wxNode
*node
= m_children
.First();
902 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
903 wxSize
sz( item
->CalcMin() );
906 m_rowHeights
[ row
] = wxMax( sz
.y
, m_rowHeights
[ row
] );
907 m_colWidths
[ col
] = wxMax( sz
.x
, m_colWidths
[ col
] );
914 for (col
= 0; col
< ncols
; col
++)
915 width
+= m_colWidths
[ col
];
918 for (row
= 0; row
< nrows
; row
++)
919 height
+= m_rowHeights
[ row
];
921 return wxSize( width
+ (ncols
-1) * m_hgap
,
922 height
+ (nrows
-1) * m_vgap
);
925 void wxFlexGridSizer::AddGrowableRow( size_t idx
)
927 m_growableRows
.Add( idx
);
930 void wxFlexGridSizer::RemoveGrowableRow( size_t WXUNUSED(idx
) )
934 void wxFlexGridSizer::AddGrowableCol( size_t idx
)
936 m_growableCols
.Add( idx
);
939 void wxFlexGridSizer::RemoveGrowableCol( size_t WXUNUSED(idx
) )
943 //---------------------------------------------------------------------------
945 //---------------------------------------------------------------------------
947 wxBoxSizer::wxBoxSizer( int orient
)
952 void wxBoxSizer::RecalcSizes()
954 if (m_children
.GetCount() == 0)
961 if (m_orient
== wxHORIZONTAL
)
963 delta
= (m_size
.x
- m_fixedWidth
) / m_stretchable
;
964 extra
= (m_size
.x
- m_fixedWidth
) % m_stretchable
;
968 delta
= (m_size
.y
- m_fixedHeight
) / m_stretchable
;
969 extra
= (m_size
.y
- m_fixedHeight
) % m_stretchable
;
973 wxPoint
pt( m_position
);
975 wxNode
*node
= m_children
.GetFirst();
978 wxSizerItem
*item
= (wxSizerItem
*) node
->Data();
981 if (item
->GetOption())
982 weight
= item
->GetOption();
984 wxSize
size( item
->CalcMin() );
986 if (m_orient
== wxVERTICAL
)
988 wxCoord height
= size
.y
;
989 if (item
->GetOption())
991 height
= (delta
* weight
) + extra
;
992 extra
= 0; // only the first item will get the remainder as extra size
995 wxPoint
child_pos( pt
);
996 wxSize
child_size( wxSize( size
.x
, height
) );
998 if (item
->GetFlag() & (wxEXPAND
| wxSHAPED
))
999 child_size
.x
= m_size
.x
;
1000 else if (item
->GetFlag() & wxALIGN_RIGHT
)
1001 child_pos
.x
+= m_size
.x
- size
.x
;
1002 else if (item
->GetFlag() & (wxCENTER
| wxALIGN_CENTER_HORIZONTAL
))
1003 // XXX wxCENTER is added for backward compatibility;
1004 // wxALIGN_CENTER should be used in new code
1005 child_pos
.x
+= (m_size
.x
- size
.x
) / 2;
1007 item
->SetDimension( child_pos
, child_size
);
1013 wxCoord width
= size
.x
;
1014 if (item
->GetOption())
1016 width
= (delta
* weight
) + extra
;
1017 extra
= 0; // only the first item will get the remainder as extra size
1020 wxPoint
child_pos( pt
);
1021 wxSize
child_size( wxSize(width
, size
.y
) );
1023 if (item
->GetFlag() & (wxEXPAND
| wxSHAPED
))
1024 child_size
.y
= m_size
.y
;
1025 else if (item
->GetFlag() & wxALIGN_BOTTOM
)
1026 child_pos
.y
+= m_size
.y
- size
.y
;
1027 else if (item
->GetFlag() & (wxCENTER
| wxALIGN_CENTER_VERTICAL
))
1028 // XXX wxCENTER is added for backward compatibility;
1029 // wxALIGN_CENTER should be used in new code
1030 child_pos
.y
+= (m_size
.y
- size
.y
) / 2;
1032 item
->SetDimension( child_pos
, child_size
);
1037 node
= node
->Next();
1041 wxSize
wxBoxSizer::CalcMin()
1043 if (m_children
.GetCount() == 0)
1044 return wxSize(10,10);
1052 // Find how long each stretch unit needs to be
1053 int stretchSize
= 1;
1054 wxNode
*node
= m_children
.GetFirst();
1057 wxSizerItem
*item
= (wxSizerItem
*) node
->Data();
1058 if (item
->GetOption() != 0)
1060 int stretch
= item
->GetOption();
1061 wxSize
size( item
->CalcMin() );
1063 // Integer division rounded up is (a + b - 1) / b
1064 if (m_orient
== wxHORIZONTAL
)
1065 sizePerStretch
= ( size
.x
+ stretch
- 1 ) / stretch
;
1067 sizePerStretch
= ( size
.y
+ stretch
- 1 ) / stretch
;
1068 if (sizePerStretch
> stretchSize
)
1069 stretchSize
= sizePerStretch
;
1071 node
= node
->Next();
1073 // Calculate overall minimum size
1074 node
= m_children
.GetFirst();
1077 wxSizerItem
*item
= (wxSizerItem
*) node
->Data();
1079 m_stretchable
+= item
->GetOption();
1081 wxSize
size( item
->CalcMin() );
1082 if (item
->GetOption() != 0)
1084 if (m_orient
== wxHORIZONTAL
)
1085 size
.x
= stretchSize
* item
->GetOption();
1087 size
.y
= stretchSize
* item
->GetOption();
1090 if (m_orient
== wxHORIZONTAL
)
1092 m_minWidth
+= size
.x
;
1093 m_minHeight
= wxMax( m_minHeight
, size
.y
);
1097 m_minHeight
+= size
.y
;
1098 m_minWidth
= wxMax( m_minWidth
, size
.x
);
1101 if (item
->GetOption() == 0)
1103 if (m_orient
== wxVERTICAL
)
1105 m_fixedHeight
+= size
.y
;
1106 m_fixedWidth
= wxMax( m_fixedWidth
, size
.x
);
1110 m_fixedWidth
+= size
.x
;
1111 m_fixedHeight
= wxMax( m_fixedHeight
, size
.y
);
1115 node
= node
->Next();
1118 return wxSize( m_minWidth
, m_minHeight
);
1121 //---------------------------------------------------------------------------
1123 //---------------------------------------------------------------------------
1127 wxStaticBoxSizer::wxStaticBoxSizer( wxStaticBox
*box
, int orient
)
1128 : wxBoxSizer( orient
)
1130 wxASSERT_MSG( box
, wxT("wxStaticBoxSizer needs a static box") );
1135 static void GetStaticBoxBorders(wxStaticBox
*box
,
1136 int *borderTop
, int *borderOther
)
1138 // this has to be done platform by platform as there is no way to
1139 // guess the thickness of a wxStaticBox border
1141 if ( box
->GetLabel().IsEmpty() )
1150 void wxStaticBoxSizer::RecalcSizes()
1152 int top_border
, other_border
;
1153 GetStaticBoxBorders(m_staticBox
, &top_border
, &other_border
);
1155 m_staticBox
->SetSize( m_position
.x
, m_position
.y
, m_size
.x
, m_size
.y
);
1157 wxPoint
old_pos( m_position
);
1158 m_position
.x
+= other_border
;
1159 m_position
.y
+= top_border
;
1160 wxSize
old_size( m_size
);
1161 m_size
.x
-= 2*other_border
;
1162 m_size
.y
-= top_border
+ other_border
;
1164 wxBoxSizer::RecalcSizes();
1166 m_position
= old_pos
;
1170 wxSize
wxStaticBoxSizer::CalcMin()
1172 int top_border
, other_border
;
1173 GetStaticBoxBorders(m_staticBox
, &top_border
, &other_border
);
1175 wxSize
ret( wxBoxSizer::CalcMin() );
1176 ret
.x
+= 2*other_border
;
1177 ret
.y
+= other_border
+ top_border
;
1182 #endif // wxUSE_STATBOX
1184 //---------------------------------------------------------------------------
1186 //---------------------------------------------------------------------------
1190 wxNotebookSizer::wxNotebookSizer( wxNotebook
*nb
)
1192 wxASSERT_MSG( nb
, wxT("wxNotebookSizer needs a notebook") );
1197 void wxNotebookSizer::RecalcSizes()
1199 m_notebook
->SetSize( m_position
.x
, m_position
.y
, m_size
.x
, m_size
.y
);
1202 wxSize
wxNotebookSizer::CalcMin()
1204 wxSize sizeBorder
= m_notebook
->CalcSizeFromPage(wxSize(0, 0));
1209 if (m_notebook
->GetChildren().GetCount() == 0)
1211 return wxSize(sizeBorder
.x
+ 10, sizeBorder
.y
+ 10);
1217 wxWindowList::Node
*node
= m_notebook
->GetChildren().GetFirst();
1220 wxWindow
*item
= node
->GetData();
1221 wxSizer
*itemsizer
= item
->GetSizer();
1225 wxSize
subsize( itemsizer
->CalcMin() );
1227 if (subsize
.x
> maxX
)
1229 if (subsize
.y
> maxY
)
1233 node
= node
->GetNext();
1236 return wxSize( maxX
, maxY
) + sizeBorder
;
1239 #endif // wxUSE_NOTEBOOK