wxSize wxRibbonPanel::GetMinSize() const { if(m_expanded_panel != NULL) { // Minimum size depends upon children, who are currently in the // expanded panel return m_expanded_panel->GetMinSize(); } if(CanAutoMinimise()) { return m_minimised_size; } else { return GetMinNotMinimisedSize(); } }
wxSize wxRibbonPanel::DoGetNextSmallerSize(wxOrientation direction, wxSize relative_to) const { if(m_expanded_panel != NULL) { // Next size depends upon children, who are currently in the // expanded panel return m_expanded_panel->DoGetNextSmallerSize(direction, relative_to); } if(m_art != NULL) { wxClientDC dc((wxRibbonPanel*) this); wxSize child_relative = m_art->GetPanelClientSize(dc, this, relative_to, NULL); wxSize smaller(-1, -1); bool minimise = false; if(GetSizer()) { // Get smallest non minimised size smaller = GetMinSize(); // and adjust to child_relative for parent page if(m_art->GetFlags() & wxRIBBON_BAR_FLOW_VERTICAL) { minimise = (child_relative.y <= smaller.y); if(smaller.x < child_relative.x) smaller.x = child_relative.x; } else { minimise = (child_relative.x <= smaller.x); if(smaller.y < child_relative.y) smaller.y = child_relative.y; } } else if(GetChildren().GetCount() == 1) { // Simple (and common) case of single ribbon child or Sizer wxWindow* child = GetChildren().Item(0)->GetData(); wxRibbonControl* ribbon_child = wxDynamicCast(child, wxRibbonControl); if(ribbon_child != NULL) { smaller = ribbon_child->GetNextSmallerSize(direction, child_relative); minimise = (smaller == child_relative); } } if(minimise) { if(CanAutoMinimise()) { wxSize minimised = m_minimised_size; switch(direction) { case wxHORIZONTAL: minimised.SetHeight(relative_to.GetHeight()); break; case wxVERTICAL: minimised.SetWidth(relative_to.GetWidth()); break; default: break; } return minimised; } else { return relative_to; } } else if(smaller.IsFullySpecified()) // Use fallback if !(sizer/child = 1) { return m_art->GetPanelSize(dc, this, smaller, NULL); } } // Fallback: Decrease by 20% (or minimum size, whichever larger) wxSize current(relative_to); wxSize minimum(GetMinSize()); if(direction & wxHORIZONTAL) { current.x = (current.x * 4) / 5; if(current.x < minimum.x) { current.x = minimum.x; } } if(direction & wxVERTICAL) { current.y = (current.y * 4) / 5; if(current.y < minimum.y) { current.y = minimum.y; } } return current; }
wxSize wxRibbonPanel::DoGetNextSmallerSize(wxOrientation direction, wxSize relative_to) const { if(m_expanded_panel != NULL) { // Next size depends upon children, who are currently in the // expanded panel return m_expanded_panel->DoGetNextSmallerSize(direction, relative_to); } // TODO: Check for, and delegate to, a sizer // Simple (and common) case of single ribbon child if(GetChildren().GetCount() == 1) { wxWindow* child = GetChildren().Item(0)->GetData(); wxRibbonControl* ribbon_child = wxDynamicCast(child, wxRibbonControl); if(m_art != NULL && ribbon_child != NULL) { wxClientDC dc((wxRibbonPanel*) this); wxSize child_relative = m_art->GetPanelClientSize(dc, this, relative_to, NULL); wxSize smaller = ribbon_child->GetNextSmallerSize(direction, child_relative); if(smaller == child_relative) { if(CanAutoMinimise()) { wxSize minimised = m_minimised_size; switch(direction) { case wxHORIZONTAL: minimised.SetHeight(relative_to.GetHeight()); break; case wxVERTICAL: minimised.SetWidth(relative_to.GetWidth()); break; default: break; } return minimised; } else { return relative_to; } } else { return m_art->GetPanelSize(dc, this, smaller, NULL); } } } // Fallback: Decrease by 20% (or minimum size, whichever larger) wxSize current(relative_to); wxSize minimum(GetMinSize()); if(direction & wxHORIZONTAL) { current.x = (current.x * 4) / 5; if(current.x < minimum.x) { current.x = minimum.x; } } if(direction & wxVERTICAL) { current.y = (current.y * 4) / 5; if(current.y < minimum.y) { current.y = minimum.y; } } return current; }