+ m_totalProportion = 0;
+ m_minSize = wxSize(0, 0);
+
+ // calculate the minimal sizes for all items and count sum of proportions
+ for ( wxSizerItemList::const_iterator i = m_children.begin();
+ i != m_children.end();
+ ++i )
+ {
+ wxSizerItem * const item = *i;
+
+ if ( !item->IsShown() )
+ continue;
+
+ const wxSize sizeMinThis = item->CalcMin();
+ SizeInMajorDir(m_minSize) += GetSizeInMajorDir(sizeMinThis);
+ if ( GetSizeInMinorDir(sizeMinThis) > GetSizeInMinorDir(m_minSize) )
+ SizeInMinorDir(m_minSize) = GetSizeInMinorDir(sizeMinThis);
+
+ m_totalProportion += item->GetProportion();
+ }
+
+ return m_minSize;
+}
+
+//---------------------------------------------------------------------------
+// wxWrapSizer
+//---------------------------------------------------------------------------
+
+#define wxDEFAULT_PROPORTION_LAST 1000000
+
+// User data to hold old proportion for last item on line
+// (which might be extended)
+struct wxPropHolder : public wxObject
+{
+ wxPropHolder( ) : m_item(0), m_propOld(0) { }
+ void Init( wxSizerItem *item, int propOld ) { m_item=item; m_propOld=propOld; }
+
+ wxSizerItem *m_item;
+ int m_propOld;
+};
+
+IMPLEMENT_DYNAMIC_CLASS(wxWrapSizer, wxBoxSizer);
+
+wxWrapSizer::wxWrapSizer( int orient, int flags )
+ : wxBoxSizer(orient),
+ m_prim_size_last( -1 ),
+ m_rows(orient^wxBOTH),
+ m_flags(flags)
+{
+}
+
+wxWrapSizer::~wxWrapSizer()
+{
+ // Have to clear grand child items so that they're not deleted twice
+ for( int ix=m_rows.GetChildren().GetCount()-1; ix>=0; ix-- )
+ {
+ wxSizer *psz = m_rows.GetItem((size_t)ix)->GetSizer();
+ wxSizerItemList &sl = psz->GetChildren();
+ while( sl.GetLast() )
+ sl.Erase( sl.GetLast() );
+ }
+}
+
+
+bool wxWrapSizer::InformFirstDirection( int direction, int size, int WXUNUSED(availableOtherDir) )
+{
+ if( !direction )
+ {
+ // Better to keep value, then CalcMin will work better
+ //m_prim_size_last = -1;
+ return false;
+ }
+ if( direction==m_orient )
+ {
+ // The direction is same as our primary, so we can make use of it
+ m_prim_size_last = size;
+ return true;
+ }
+ else
+ return false;
+}
+
+
+void wxWrapSizer::AdjustPropLastItem(wxSizer *psz, wxSizerItem *itemLast)
+{
+ wxSizerItem *psi = m_rows.GetItem(psz);
+ wxASSERT(psi);
+ wxPropHolder *pph = (wxPropHolder*)psi->GetUserData();
+ if ( !pph )
+ psi->SetUserData( pph=new wxPropHolder );
+
+ pph->Init( itemLast, itemLast->GetProportion() );
+ itemLast->SetProportion( wxDEFAULT_PROPORTION_LAST );
+}
+
+void wxWrapSizer::RecalcSizes()
+{
+ wxASSERT( m_orient&wxBOTH );