diff --git a/include/wx/ribbon/bar.h b/include/wx/ribbon/bar.h index c4904e9c64..954a8e6f76 100644 --- a/include/wx/ribbon/bar.h +++ b/include/wx/ribbon/bar.h @@ -140,9 +140,11 @@ public: void AddPageHighlight(size_t page, bool highlight = true); void RemovePageHighlight(size_t page) { AddPageHighlight(page, false); } + void ShowPanels(wxRibbonDisplayMode mode); void ShowPanels(bool show = true); - void HidePanels() { ShowPanels(false); } + void HidePanels() { ShowPanels(wxRIBBON_BAR_MINIMIZED); } bool ArePanelsShown() const { return m_arePanelsShown; } + wxRibbonDisplayMode GetDisplayMode() const { return m_ribbon_state; } virtual bool HasMultiplePages() const wxOVERRIDE { return true; } diff --git a/interface/wx/ribbon/bar.h b/interface/wx/ribbon/bar.h index c729347ab1..7b0926ef2c 100644 --- a/interface/wx/ribbon/bar.h +++ b/interface/wx/ribbon/bar.h @@ -348,6 +348,14 @@ public: */ void RemovePageHighlight(size_t page); + /** + Shows or hide the panel area of the ribbon bar according to the + given display mode. + + @since 3.1.0 + */ + void ShowPanels(wxRibbonDisplayMode mode); + /** Shows or hides the panel area of the ribbon bar. @@ -355,6 +363,10 @@ public: be shown. This is useful for giving the user more screen space to work with when he/she doesn't need to see the ribbon's options. + If the panel is currently shown, this method pins it, use the other + overload of this method to specify the exact panel display mode to + avoid it. + @since 2.9.2 */ void ShowPanels(bool show = true); @@ -362,7 +374,7 @@ public: /** Hides the panel area of the ribbon bar. - This method simply calls ShowPanels() with @false argument. + This method behaves like ShowPanels() with @false argument. @since 2.9.2 */ @@ -377,6 +389,16 @@ public: */ bool ArePanelsShown() const; + /** + Returns the current display mode of the panel area. + + @see ShowPanels() + + @since 3.1.0 + */ + wxRibbonDisplayMode GetDisplayMode() const; + + /** Perform initial layout and size calculations of the bar and its children. This must be called after all of the bar's children have been diff --git a/src/ribbon/bar.cpp b/src/ribbon/bar.cpp index 1bad16a18b..79f3966332 100644 --- a/src/ribbon/bar.cpp +++ b/src/ribbon/bar.cpp @@ -115,12 +115,32 @@ bool wxRibbonBar::DismissExpandedPanel() return m_pages.Item(m_current_page).page->DismissExpandedPanel(); } -void wxRibbonBar::ShowPanels(bool show) + +void wxRibbonBar::ShowPanels(wxRibbonDisplayMode mode) { - m_arePanelsShown = show; + switch ( mode ) + { + case wxRIBBON_BAR_PINNED: + case wxRIBBON_BAR_EXPANDED: + m_arePanelsShown = true; + break; + + case wxRIBBON_BAR_MINIMIZED: + m_arePanelsShown = false; + break; + } + SetMinSize(wxSize(GetSize().GetWidth(), DoGetBestSize().GetHeight())); Realise(); GetParent()->Layout(); + + m_ribbon_state = mode; +} + + +void wxRibbonBar::ShowPanels(bool show) +{ + ShowPanels( show ? wxRIBBON_BAR_PINNED : wxRIBBON_BAR_MINIMIZED ); } void wxRibbonBar::SetWindowStyleFlag(long style) @@ -974,13 +994,11 @@ void wxRibbonBar::OnMouseLeftDown(wxMouseEvent& evt) { if ( m_ribbon_state == wxRIBBON_BAR_MINIMIZED ) { - ShowPanels(); - m_ribbon_state = wxRIBBON_BAR_EXPANDED; + ShowPanels(wxRIBBON_BAR_EXPANDED); } else if ( (tab == &m_pages.Item(m_current_page)) && (m_ribbon_state == wxRIBBON_BAR_EXPANDED) ) { HidePanels(); - m_ribbon_state = wxRIBBON_BAR_MINIMIZED; } } else @@ -988,7 +1006,6 @@ void wxRibbonBar::OnMouseLeftDown(wxMouseEvent& evt) if ( m_ribbon_state == wxRIBBON_BAR_EXPANDED ) { HidePanels(); - m_ribbon_state = wxRIBBON_BAR_MINIMIZED; } } if(tab && tab != &m_pages.Item(m_current_page)) @@ -1028,12 +1045,7 @@ void wxRibbonBar::OnMouseLeftDown(wxMouseEvent& evt) { if(m_toggle_button_rect.Contains(position)) { - bool pshown = ArePanelsShown(); - ShowPanels(!pshown); - if ( pshown ) - m_ribbon_state = wxRIBBON_BAR_MINIMIZED; - else - m_ribbon_state = wxRIBBON_BAR_PINNED; + ShowPanels(ArePanelsShown() ? wxRIBBON_BAR_MINIMIZED : wxRIBBON_BAR_PINNED); wxRibbonBarEvent event(wxEVT_RIBBONBAR_TOGGLED, GetId()); event.SetEventObject(this); ProcessWindowEvent(event); @@ -1168,13 +1180,11 @@ void wxRibbonBar::OnMouseDoubleClick(wxMouseEvent& evt) { if ( m_ribbon_state == wxRIBBON_BAR_PINNED ) { - m_ribbon_state = wxRIBBON_BAR_MINIMIZED; HidePanels(); } else { - m_ribbon_state = wxRIBBON_BAR_PINNED; - ShowPanels(); + ShowPanels(wxRIBBON_BAR_PINNED); } } } @@ -1269,20 +1279,8 @@ void wxRibbonBar::HitTestRibbonButton(const wxRect& rect, const wxPoint& positio void wxRibbonBar::HideIfExpanded() { - switch ( m_ribbon_state ) - { - case wxRIBBON_BAR_EXPANDED: - m_ribbon_state = wxRIBBON_BAR_MINIMIZED; - // Fall through - - case wxRIBBON_BAR_MINIMIZED: - HidePanels(); - break; - - case wxRIBBON_BAR_PINNED: - ShowPanels(); - break; - } + if ( m_ribbon_state == wxRIBBON_BAR_EXPANDED) + HidePanels(); } void wxRibbonBar::OnKillFocus(wxFocusEvent& WXUNUSED(evt))