X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0274a7973da59746c55bc91ebceac64f622b6a34..26022721e88892446ebcfc34bc34384492952fa9:/src/common/sizer.cpp?ds=sidebyside diff --git a/src/common/sizer.cpp b/src/common/sizer.cpp index 01180b5374..ad0abd60ed 100644 --- a/src/common/sizer.cpp +++ b/src/common/sizer.cpp @@ -634,7 +634,7 @@ wxSizer::~wxSizer() WX_CLEAR_LIST(wxSizerItemList, m_children); } -wxSizerItem* wxSizer::Insert( size_t index, wxSizerItem *item ) +wxSizerItem* wxSizer::DoInsert( size_t index, wxSizerItem *item ) { m_children.Insert( index, item ); @@ -1349,7 +1349,7 @@ wxGridSizer::wxGridSizer( int rows, int cols, const wxSize& gap ) { } -wxSizerItem *wxGridSizer::Insert(size_t index, wxSizerItem *item) +wxSizerItem *wxGridSizer::DoInsert(size_t index, wxSizerItem *item) { // if only the number of columns or the number of rows is specified for a // sizer, arbitrarily many items can be added to it but if both of them are @@ -1379,7 +1379,7 @@ wxSizerItem *wxGridSizer::Insert(size_t index, wxSizerItem *item) } } - return wxSizer::Insert(index, item); + return wxSizer::DoInsert(index, item); } int wxGridSizer::CalcRowsCols(int& nrows, int& ncols) const @@ -1982,16 +1982,22 @@ void wxFlexGridSizer::RemoveGrowableRow( size_t idx ) // wxBoxSizer //--------------------------------------------------------------------------- +wxSizerItem *wxBoxSizer::AddSpacer(int size) +{ + return IsVertical() ? Add(0, size) : Add(size, 0); +} + void wxBoxSizer::RecalcSizes() { if ( m_children.empty() ) return; const wxCoord totalMinorSize = GetSizeInMinorDir(m_size); + const wxCoord totalMajorSize = GetSizeInMajorDir(m_size); // the amount of free space which we should redistribute among the // stretchable items (i.e. those with non zero proportion) - int delta = GetSizeInMajorDir(m_size) - GetSizeInMajorDir(m_minSize); + int delta = totalMajorSize - GetSizeInMajorDir(m_minSize); // Inform child items about the size in minor direction, that can @@ -2024,11 +2030,14 @@ void wxBoxSizer::RecalcSizes() // might have a new delta now - delta = GetSizeInMajorDir(m_size) - GetSizeInMajorDir(m_minSize); + delta = totalMajorSize - GetSizeInMajorDir(m_minSize); // the position at which we put the next child wxPoint pt(m_position); + // space remaining for the items + wxCoord majorRemaining = totalMajorSize; + int totalProportion = m_totalProportion; for ( i = m_children.begin(); i != m_children.end(); @@ -2044,11 +2053,10 @@ void wxBoxSizer::RecalcSizes() // adjust the size in the major direction using the proportion wxCoord majorSize = GetSizeInMajorDir(sizeThis); - // if there is not enough space, don't try to distribute negative space - // among the children, this would result in overlapping windows which - // we don't want if ( delta > 0 ) { + // distribute extra space among the items respecting their + // proportions const int propItem = item->GetProportion(); if ( propItem ) { @@ -2060,6 +2068,18 @@ void wxBoxSizer::RecalcSizes() totalProportion -= propItem; } } + else // delta < 0 + { + // we're not going to have enough space for making all items even + // of their minimal size, check if this item still fits at all and + // truncate it if it doesn't -- even if it means giving it 0 size + // and thus making it invisible because we just can't do anything + // else + if ( majorSize > majorRemaining ) + majorSize = majorRemaining; + + majorRemaining -= majorSize; + } // apply the alignment in the minor direction