+// Finds the best width and height given the parents' width and height
+wxSize wxRibbonToolBar::GetBestSizeForParentSize(const wxSize& parentSize) const
+{
+ if (!m_sizes)
+ return GetMinSize();
+
+ // Choose row count with largest possible area
+ wxSize size = parentSize;
+ int row_count = m_nrows_max;
+ wxOrientation major_axis = m_art->GetFlags() & wxRIBBON_BAR_FLOW_VERTICAL ?
+ wxVERTICAL : wxHORIZONTAL;
+
+ // A toolbar should maximize its width whether vertical or horizontal, so
+ // force the major axis to be horizontal. Without this, there will be
+ // redundant horizontal space.
+ major_axis = wxHORIZONTAL;
+ wxSize bestSize = m_sizes[0];
+
+ if(m_nrows_max != m_nrows_min)
+ {
+ int area = 0;
+ for(int i = 0; i <= m_nrows_max - m_nrows_min; ++i)
+ {
+ if(m_sizes[i].x <= size.x && m_sizes[i].y <= size.y &&
+ GetSizeInOrientation(m_sizes[i], major_axis) > area)
+ {
+ area = GetSizeInOrientation(m_sizes[i], major_axis);
+ row_count = m_nrows_min + i;
+ bestSize = m_sizes[i];
+ }
+ }
+ }
+ return bestSize;
+}
+