SetRatio(size);
}
+wxSize wxSizerItem::AddBorderToSize(const wxSize& size) const
+{
+ if (size == wxDefaultSize)
+ return size;
+
+ wxSize result = size;
+ if (m_flag & wxWEST)
+ result.x += m_border;
+ if (m_flag & wxEAST)
+ result.x += m_border;
+ if (m_flag & wxNORTH)
+ result.y += m_border;
+ if (m_flag & wxSOUTH)
+ result.y += m_border;
+ return result;
+}
+
wxSizerItem::wxSizerItem(int width,
int height,
int proportion,
wxSize wxSizerItem::GetMinSizeWithBorder() const
{
- wxSize ret = m_minSize;
-
- if (m_flag & wxWEST)
- ret.x += m_border;
- if (m_flag & wxEAST)
- ret.x += m_border;
- if (m_flag & wxNORTH)
- ret.y += m_border;
- if (m_flag & wxSOUTH)
- ret.y += m_border;
-
- return ret;
+ return AddBorderToSize(m_minSize);
}
+wxSize wxSizerItem::GetMaxSizeWithBorder() const
+{
+ return AddBorderToSize(GetMaxSize());
+}
void wxSizerItem::SetDimension( const wxPoint& pos_, const wxSize& size_ )
{
nonFixedSpaceChanged = true;
}
+ // Similar to the previous loop, but dealing with items whose max size
+ // is less than what we would allocate to them taking their proportion
+ // into account.
+ nonFixedSpaceChanged = false;
+ for ( i = m_children.begin(), n = 0; ; ++i, ++n )
+ {
+ if ( nonFixedSpaceChanged )
+ {
+ i = m_children.begin();
+ n = 0;
+ nonFixedSpaceChanged = false;
+ }
+
+ // check for the end of the loop only after the check above as
+ // otherwise we wouldn't do another pass if the last child resulted
+ // in non fixed space reduction
+ if ( i == m_children.end() )
+ break;
+
+ wxSizerItem * const item = *i;
+
+ if ( !item->IsShown() )
+ continue;
+
+ // don't check the item which we had already dealt with during a
+ // previous pass (this is more than an optimization, the code
+ // wouldn't work correctly if we kept adjusting for the same item
+ // over and over again)
+ if ( majorSizes[n] != wxDefaultCoord )
+ continue;
+
+ wxCoord maxMajor = GetSizeInMajorDir(item->GetMaxSizeWithBorder());
+
+ // must be nonzero, fixed-size items were dealt with in previous loop
+ const int propItem = item->GetProportion();
+
+ // is the desired size of this item small enough?
+ if ( maxMajor < 0 ||
+ (remaining*propItem)/totalProportion <= maxMajor )
+ {
+ // yes, it is, we'll determine the real size of this
+ // item later, for now just leave it as wxDefaultCoord
+ continue;
+ }
+
+ // the proportion of this item won't count, it has
+ // effectively become fixed
+ totalProportion -= propItem;
+
+ // we can already allocate space for this item
+ majorSizes[n] = maxMajor;
+
+ // change the amount of the space remaining to the other items,
+ // as this can result in not being able to satisfy their
+ // proportions any more we will need to redo another loop
+ // iteration
+ remaining -= maxMajor;
+
+ nonFixedSpaceChanged = true;
+ }
// Last by one pass: distribute the remaining space among the non-fixed
// items whose size weren't fixed yet according to their proportions.
// its minimal size which is bad but better than not showing parts
// of the window at all
minorSize = totalMinorSize;
+
+ // do not allow the size in the minor direction to grow beyond the max
+ // size of the item in the minor direction
+ const wxCoord maxMinorSize = GetSizeInMinorDir(item->GetMaxSizeWithBorder());
+ if ( maxMinorSize >= 0 && minorSize > maxMinorSize )
+ minorSize = maxMinorSize;
}
- else if ( flag & (IsVertical() ? wxALIGN_RIGHT : wxALIGN_BOTTOM) )
+
+ if ( flag & (IsVertical() ? wxALIGN_RIGHT : wxALIGN_BOTTOM) )
{
PosInMinorDir(posChild) += totalMinorSize - minorSize;
}