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 wxSize
wxSizer::Fit( wxWindow
*window
)
406 if (window
->IsTopLevel())
407 size
= FitSize( window
);
409 size
= GetMinWindowSize( window
);
411 window
->SetSize( size
);
416 void wxSizer::FitInside( wxWindow
*window
)
419 if (window
->IsTopLevel())
420 size
= VirtualFitSize( window
);
422 size
= GetMinClientSize( window
);
424 window
->SetVirtualSize( size
);
427 void wxSizer::Layout()
433 void wxSizer::SetSizeHints( wxWindow
*window
)
435 // Preserve the window's max size hints, but set the
436 // lower bound according to the sizer calculations.
438 wxSize size
= Fit( window
);
440 window
->SetSizeHints( size
.x
,
442 window
->GetMaxWidth(),
443 window
->GetMaxHeight() );
446 void wxSizer::SetVirtualSizeHints( wxWindow
*window
)
448 // Preserve the window's max size hints, but set the
449 // lower bound according to the sizer calculations.
452 wxSize
size( window
->GetVirtualSize() );
453 window
->SetVirtualSizeHints( size
.x
,
455 window
->GetMaxWidth(),
456 window
->GetMaxHeight() );
459 wxSize
wxSizer::GetMaxWindowSize( wxWindow
*window
)
461 return window
->GetMaxSize();
464 wxSize
wxSizer::GetMinWindowSize( wxWindow
*window
)
466 wxSize
minSize( GetMinSize() );
467 wxSize
size( window
->GetSize() );
468 wxSize
client_size( window
->GetClientSize() );
469 return wxSize( minSize
.x
+size
.x
-client_size
.x
,
470 minSize
.y
+size
.y
-client_size
.y
);
473 // Return a window size that will fit within the screens dimensions
474 wxSize
wxSizer::FitSize( wxWindow
*window
)
476 wxSize size
= GetMinWindowSize( window
);
477 wxSize sizeMax
= GetMaxWindowSize( window
);
479 // Limit the size if sizeMax != wxDefaultSize
481 if ( size
.x
> sizeMax
.x
&& sizeMax
.x
!= -1 )
483 if ( size
.y
> sizeMax
.y
&& sizeMax
.y
!= -1 )
489 wxSize
wxSizer::GetMaxClientSize( wxWindow
*window
)
491 wxSize
maxSize( window
->GetMaxSize() );
493 if( maxSize
!= wxDefaultSize
)
495 wxSize
size( window
->GetSize() );
496 wxSize
client_size( window
->GetClientSize() );
498 return wxSize( maxSize
.x
+ client_size
.x
- size
.x
,
499 maxSize
.y
+ client_size
.y
- size
.y
);
502 return wxDefaultSize
;
505 wxSize
wxSizer::GetMinClientSize( wxWindow
*WXUNUSED(window
) )
507 return GetMinSize(); // Already returns client size.
510 wxSize
wxSizer::VirtualFitSize( wxWindow
*window
)
512 wxSize size
= GetMinClientSize( window
);
513 wxSize sizeMax
= GetMaxClientSize( window
);
515 // Limit the size if sizeMax != wxDefaultSize
517 if ( size
.x
> sizeMax
.x
&& sizeMax
.x
!= -1 )
519 if ( size
.y
> sizeMax
.y
&& sizeMax
.y
!= -1 )
525 void wxSizer::SetDimension( int x
, int y
, int width
, int height
)
535 wxSize
wxSizer::GetMinSize()
537 wxSize
ret( CalcMin() );
538 if (ret
.x
< m_minSize
.x
) ret
.x
= m_minSize
.x
;
539 if (ret
.y
< m_minSize
.y
) ret
.y
= m_minSize
.y
;
543 void wxSizer::DoSetMinSize( int width
, int height
)
546 m_minSize
.y
= height
;
549 bool wxSizer::DoSetItemMinSize( wxWindow
*window
, int width
, int height
)
553 wxNode
*node
= m_children
.First();
556 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
557 if (item
->GetWindow() == window
)
559 item
->SetInitSize( width
, height
);
565 node
= m_children
.First();
568 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
569 if (item
->GetSizer())
571 /* It's a sizer, so lets search recursively. */
572 if (item
->GetSizer()->DoSetItemMinSize( window
, width
, height
))
574 /* A child sizer found the requested windw, exit. */
584 bool wxSizer::DoSetItemMinSize( wxSizer
*sizer
, int width
, int height
)
588 wxNode
*node
= m_children
.First();
591 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
592 if (item
->GetSizer() == sizer
)
594 item
->GetSizer()->DoSetMinSize( width
, height
);
600 node
= m_children
.First();
603 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
604 if (item
->GetSizer())
606 /* It's a sizer, so lets search recursively. */
607 if (item
->GetSizer()->DoSetItemMinSize( sizer
, width
, height
))
609 /* A child sizer found the requested windw, exit. */
619 bool wxSizer::DoSetItemMinSize( int pos
, int width
, int height
)
621 wxNode
*node
= m_children
.Nth( pos
);
622 if (!node
) return FALSE
;
624 wxSizerItem
*item
= (wxSizerItem
*) node
->Data();
625 if (item
->GetSizer())
627 /* Sizers contains the minimal size in them, if not calculated ... */
628 item
->GetSizer()->DoSetMinSize( width
, height
);
632 /* ... whereas the minimal size of spacers and windows in stored
634 item
->SetInitSize( width
, height
);
640 //---------------------------------------------------------------------------
642 //---------------------------------------------------------------------------
644 wxGridSizer::wxGridSizer( int rows
, int cols
, int vgap
, int hgap
)
652 wxGridSizer::wxGridSizer( int cols
, int vgap
, int hgap
)
660 void wxGridSizer::RecalcSizes()
662 if (m_children
.GetCount() == 0)
665 int nitems
= m_children
.GetCount();
670 nrows
= (nitems
+ ncols
-1) / ncols
;
672 ncols
= (nitems
+ nrows
-1) / nrows
;
674 wxSize
sz( GetSize() );
675 wxPoint
pt( GetPosition() );
677 int w
= (sz
.x
- (ncols
- 1) * m_hgap
) / ncols
;
678 int h
= (sz
.y
- (nrows
- 1) * m_vgap
) / nrows
;
681 for (int c
= 0; c
< ncols
; c
++)
684 for (int r
= 0; r
< nrows
; r
++)
686 int i
= r
* ncols
+ c
;
689 wxNode
*node
= m_children
.Nth( i
);
692 SetItemBounds( (wxSizerItem
*) node
->Data(), x
, y
, w
, h
);
700 wxSize
wxGridSizer::CalcMin()
702 if (m_children
.GetCount() == 0)
703 return wxSize(10,10);
705 int nitems
= m_children
.GetCount();
710 nrows
= (nitems
+ ncols
-1) / ncols
;
712 ncols
= (nitems
+ nrows
-1) / nrows
;
714 /* Find the max width and height for any component */
718 wxNode
*node
= m_children
.First();
721 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
722 wxSize
sz( item
->CalcMin() );
723 w
= wxMax( w
, sz
.x
);
724 h
= wxMax( h
, sz
.y
);
729 return wxSize(ncols
* w
+ (ncols
-1) * m_hgap
,
730 nrows
* h
+ (nrows
-1) * m_vgap
);
733 void wxGridSizer::SetItemBounds( wxSizerItem
*item
, int x
, int y
, int w
, int h
)
736 wxSize
sz( item
->CalcMin() );
737 int flag
= item
->GetFlag();
739 if ((flag
& wxEXPAND
) || (flag
& wxSHAPED
))
745 if (flag
& wxALIGN_CENTER_HORIZONTAL
)
747 pt
.x
= x
+ (w
- sz
.x
) / 2;
749 else if (flag
& wxALIGN_RIGHT
)
751 pt
.x
= x
+ (w
- sz
.x
);
754 if (flag
& wxALIGN_CENTER_VERTICAL
)
756 pt
.y
= y
+ (h
- sz
.y
) / 2;
758 else if (flag
& wxALIGN_BOTTOM
)
760 pt
.y
= y
+ (h
- sz
.y
);
764 item
->SetDimension(pt
, sz
);
767 //---------------------------------------------------------------------------
769 //---------------------------------------------------------------------------
771 wxFlexGridSizer::wxFlexGridSizer( int rows
, int cols
, int vgap
, int hgap
)
772 : wxGridSizer( rows
, cols
, vgap
, hgap
)
774 m_rowHeights
= (int*) NULL
;
775 m_colWidths
= (int*) NULL
;
778 wxFlexGridSizer::wxFlexGridSizer( int cols
, int vgap
, int hgap
)
779 : wxGridSizer( cols
, vgap
, hgap
)
781 m_rowHeights
= (int*) NULL
;
782 m_colWidths
= (int*) NULL
;
785 wxFlexGridSizer::~wxFlexGridSizer()
788 delete[] m_rowHeights
;
790 delete[] m_colWidths
;
793 void wxFlexGridSizer::CreateArrays()
796 delete[] m_rowHeights
;
798 delete[] m_colWidths
;
800 if (m_children
.GetCount() == 0)
803 int nitems
= m_children
.GetCount();
808 nrows
= (nitems
+ ncols
-1) / ncols
;
810 ncols
= (nitems
+ nrows
-1) / nrows
;
812 m_rowHeights
= new int[nrows
];
813 m_colWidths
= new int[ncols
];
815 for (int col
= 0; col
< ncols
; col
++)
816 m_colWidths
[ col
] = 0;
817 for (int row
= 0; row
< nrows
; row
++)
818 m_rowHeights
[ row
] = 0;
821 void wxFlexGridSizer::RecalcSizes()
823 if (m_children
.GetCount() == 0)
826 int nitems
= m_children
.GetCount();
831 nrows
= (nitems
+ ncols
-1) / ncols
;
833 ncols
= (nitems
+ nrows
-1) / nrows
;
835 wxSize
sz( GetSize() );
836 wxSize
minsz( CalcMin() );
837 wxPoint
pt( GetPosition() );
841 if ((m_growableRows
.GetCount() > 0) && (sz
.y
> minsz
.y
))
843 delta
= (sz
.y
- minsz
.y
) / m_growableRows
.GetCount();
844 for (idx
= 0; idx
< m_growableRows
.GetCount(); idx
++)
845 m_rowHeights
[ m_growableRows
[idx
] ] += delta
;
848 if ((m_growableCols
.GetCount() > 0) && (sz
.x
> minsz
.x
))
850 delta
= (sz
.x
- minsz
.x
) / m_growableCols
.GetCount();
851 for (idx
= 0; idx
< m_growableCols
.GetCount(); idx
++)
852 m_colWidths
[ m_growableCols
[idx
] ] += delta
;
855 sz
= wxSize( pt
.x
+ sz
.x
, pt
.y
+ sz
.y
);
858 for (int c
= 0; c
< ncols
; c
++)
861 for (int r
= 0; r
< nrows
; r
++)
863 int i
= r
* ncols
+ c
;
866 wxNode
*node
= m_children
.Nth( i
);
869 int w
= wxMax( 0, wxMin( m_colWidths
[c
], sz
.x
- x
) );
870 int h
= wxMax( 0, wxMin( m_rowHeights
[r
], sz
.y
- y
) );
872 SetItemBounds( (wxSizerItem
*) node
->Data(), x
, y
, w
, h
);
874 y
= y
+ m_rowHeights
[r
] + m_vgap
;
876 x
= x
+ m_colWidths
[c
] + m_hgap
;
880 wxSize
wxFlexGridSizer::CalcMin()
882 if (m_children
.GetCount() == 0)
883 return wxSize(10,10);
885 int nitems
= m_children
.GetCount();
890 nrows
= (nitems
+ ncols
-1) / ncols
;
892 ncols
= (nitems
+ nrows
-1) / nrows
;
900 wxNode
*node
= m_children
.First();
903 wxSizerItem
*item
= (wxSizerItem
*)node
->Data();
904 wxSize
sz( item
->CalcMin() );
907 m_rowHeights
[ row
] = wxMax( sz
.y
, m_rowHeights
[ row
] );
908 m_colWidths
[ col
] = wxMax( sz
.x
, m_colWidths
[ col
] );
915 for (col
= 0; col
< ncols
; col
++)
916 width
+= m_colWidths
[ col
];
919 for (row
= 0; row
< nrows
; row
++)
920 height
+= m_rowHeights
[ row
];
922 return wxSize( width
+ (ncols
-1) * m_hgap
,
923 height
+ (nrows
-1) * m_vgap
);
926 void wxFlexGridSizer::AddGrowableRow( size_t idx
)
928 m_growableRows
.Add( idx
);
931 void wxFlexGridSizer::RemoveGrowableRow( size_t WXUNUSED(idx
) )
935 void wxFlexGridSizer::AddGrowableCol( size_t idx
)
937 m_growableCols
.Add( idx
);
940 void wxFlexGridSizer::RemoveGrowableCol( size_t WXUNUSED(idx
) )
944 //---------------------------------------------------------------------------
946 //---------------------------------------------------------------------------
948 wxBoxSizer::wxBoxSizer( int orient
)
953 void wxBoxSizer::RecalcSizes()
955 if (m_children
.GetCount() == 0)
962 if (m_orient
== wxHORIZONTAL
)
964 delta
= (m_size
.x
- m_fixedWidth
) / m_stretchable
;
965 extra
= (m_size
.x
- m_fixedWidth
) % m_stretchable
;
969 delta
= (m_size
.y
- m_fixedHeight
) / m_stretchable
;
970 extra
= (m_size
.y
- m_fixedHeight
) % m_stretchable
;
974 wxPoint
pt( m_position
);
976 wxNode
*node
= m_children
.GetFirst();
979 wxSizerItem
*item
= (wxSizerItem
*) node
->Data();
982 if (item
->GetOption())
983 weight
= item
->GetOption();
985 wxSize
size( item
->CalcMin() );
987 if (m_orient
== wxVERTICAL
)
989 wxCoord height
= size
.y
;
990 if (item
->GetOption())
992 height
= (delta
* weight
) + extra
;
993 extra
= 0; // only the first item will get the remainder as extra size
996 wxPoint
child_pos( pt
);
997 wxSize
child_size( wxSize( size
.x
, height
) );
999 if (item
->GetFlag() & (wxEXPAND
| wxSHAPED
))
1000 child_size
.x
= m_size
.x
;
1001 else if (item
->GetFlag() & wxALIGN_RIGHT
)
1002 child_pos
.x
+= m_size
.x
- size
.x
;
1003 else if (item
->GetFlag() & (wxCENTER
| wxALIGN_CENTER_HORIZONTAL
))
1004 // XXX wxCENTER is added for backward compatibility;
1005 // wxALIGN_CENTER should be used in new code
1006 child_pos
.x
+= (m_size
.x
- size
.x
) / 2;
1008 item
->SetDimension( child_pos
, child_size
);
1014 wxCoord width
= size
.x
;
1015 if (item
->GetOption())
1017 width
= (delta
* weight
) + extra
;
1018 extra
= 0; // only the first item will get the remainder as extra size
1021 wxPoint
child_pos( pt
);
1022 wxSize
child_size( wxSize(width
, size
.y
) );
1024 if (item
->GetFlag() & (wxEXPAND
| wxSHAPED
))
1025 child_size
.y
= m_size
.y
;
1026 else if (item
->GetFlag() & wxALIGN_BOTTOM
)
1027 child_pos
.y
+= m_size
.y
- size
.y
;
1028 else if (item
->GetFlag() & (wxCENTER
| wxALIGN_CENTER_VERTICAL
))
1029 // XXX wxCENTER is added for backward compatibility;
1030 // wxALIGN_CENTER should be used in new code
1031 child_pos
.y
+= (m_size
.y
- size
.y
) / 2;
1033 item
->SetDimension( child_pos
, child_size
);
1038 node
= node
->Next();
1042 wxSize
wxBoxSizer::CalcMin()
1044 if (m_children
.GetCount() == 0)
1045 return wxSize(10,10);
1053 // Find how long each stretch unit needs to be
1054 int stretchSize
= 1;
1055 wxNode
*node
= m_children
.GetFirst();
1058 wxSizerItem
*item
= (wxSizerItem
*) node
->Data();
1059 if (item
->GetOption() != 0)
1061 int stretch
= item
->GetOption();
1062 wxSize
size( item
->CalcMin() );
1064 // Integer division rounded up is (a + b - 1) / b
1065 if (m_orient
== wxHORIZONTAL
)
1066 sizePerStretch
= ( size
.x
+ stretch
- 1 ) / stretch
;
1068 sizePerStretch
= ( size
.y
+ stretch
- 1 ) / stretch
;
1069 if (sizePerStretch
> stretchSize
)
1070 stretchSize
= sizePerStretch
;
1072 node
= node
->Next();
1074 // Calculate overall minimum size
1075 node
= m_children
.GetFirst();
1078 wxSizerItem
*item
= (wxSizerItem
*) node
->Data();
1080 m_stretchable
+= item
->GetOption();
1082 wxSize
size( item
->CalcMin() );
1083 if (item
->GetOption() != 0)
1085 if (m_orient
== wxHORIZONTAL
)
1086 size
.x
= stretchSize
* item
->GetOption();
1088 size
.y
= stretchSize
* item
->GetOption();
1091 if (m_orient
== wxHORIZONTAL
)
1093 m_minWidth
+= size
.x
;
1094 m_minHeight
= wxMax( m_minHeight
, size
.y
);
1098 m_minHeight
+= size
.y
;
1099 m_minWidth
= wxMax( m_minWidth
, size
.x
);
1102 if (item
->GetOption() == 0)
1104 if (m_orient
== wxVERTICAL
)
1106 m_fixedHeight
+= size
.y
;
1107 m_fixedWidth
= wxMax( m_fixedWidth
, size
.x
);
1111 m_fixedWidth
+= size
.x
;
1112 m_fixedHeight
= wxMax( m_fixedHeight
, size
.y
);
1116 node
= node
->Next();
1119 return wxSize( m_minWidth
, m_minHeight
);
1122 //---------------------------------------------------------------------------
1124 //---------------------------------------------------------------------------
1128 wxStaticBoxSizer::wxStaticBoxSizer( wxStaticBox
*box
, int orient
)
1129 : wxBoxSizer( orient
)
1131 wxASSERT_MSG( box
, wxT("wxStaticBoxSizer needs a static box") );
1136 static void GetStaticBoxBorders(wxStaticBox
*box
,
1137 int *borderTop
, int *borderOther
)
1139 // this has to be done platform by platform as there is no way to
1140 // guess the thickness of a wxStaticBox border
1142 if ( box
->GetLabel().IsEmpty() )
1151 void wxStaticBoxSizer::RecalcSizes()
1153 int top_border
, other_border
;
1154 GetStaticBoxBorders(m_staticBox
, &top_border
, &other_border
);
1156 m_staticBox
->SetSize( m_position
.x
, m_position
.y
, m_size
.x
, m_size
.y
);
1158 wxPoint
old_pos( m_position
);
1159 m_position
.x
+= other_border
;
1160 m_position
.y
+= top_border
;
1161 wxSize
old_size( m_size
);
1162 m_size
.x
-= 2*other_border
;
1163 m_size
.y
-= top_border
+ other_border
;
1165 wxBoxSizer::RecalcSizes();
1167 m_position
= old_pos
;
1171 wxSize
wxStaticBoxSizer::CalcMin()
1173 int top_border
, other_border
;
1174 GetStaticBoxBorders(m_staticBox
, &top_border
, &other_border
);
1176 wxSize
ret( wxBoxSizer::CalcMin() );
1177 ret
.x
+= 2*other_border
;
1178 ret
.y
+= other_border
+ top_border
;
1183 #endif // wxUSE_STATBOX
1185 //---------------------------------------------------------------------------
1187 //---------------------------------------------------------------------------
1191 wxNotebookSizer::wxNotebookSizer( wxNotebook
*nb
)
1193 wxASSERT_MSG( nb
, wxT("wxNotebookSizer needs a notebook") );
1198 void wxNotebookSizer::RecalcSizes()
1200 m_notebook
->SetSize( m_position
.x
, m_position
.y
, m_size
.x
, m_size
.y
);
1203 wxSize
wxNotebookSizer::CalcMin()
1205 wxSize sizeBorder
= m_notebook
->CalcSizeFromPage(wxSize(0, 0));
1210 if (m_notebook
->GetChildren().GetCount() == 0)
1212 return wxSize(sizeBorder
.x
+ 10, sizeBorder
.y
+ 10);
1218 wxWindowList::Node
*node
= m_notebook
->GetChildren().GetFirst();
1221 wxWindow
*item
= node
->GetData();
1222 wxSizer
*itemsizer
= item
->GetSizer();
1226 wxSize
subsize( itemsizer
->CalcMin() );
1228 if (subsize
.x
> maxX
)
1230 if (subsize
.y
> maxY
)
1234 node
= node
->GetNext();
1237 return wxSize( maxX
, maxY
) + sizeBorder
;
1240 #endif // wxUSE_NOTEBOOK