From 7c70331e28be93b833dfa4f2594a25841fcb6e20 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 30 Jul 2012 17:53:36 +0000 Subject: [PATCH] Add expand/collapse button to wxRibbonBar. This allows the user to toggle the ribbon bar visibility. Closes #14530. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72261 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + include/wx/ribbon/art.h | 31 ++++++++++++ include/wx/ribbon/bar.h | 16 +++++- interface/wx/ribbon/bar.h | 9 +++- samples/ribbon/ribbondemo.cpp | 15 ++++-- src/ribbon/art_msw.cpp | 93 +++++++++++++++++++++++++++++++++++ src/ribbon/bar.cpp | 58 ++++++++++++++++++++++ 7 files changed, 217 insertions(+), 6 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 3c52f5d3fb..8d14d1b268 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -534,6 +534,7 @@ All: All (GUI): - Add possibility to hide and show again wxRibbonBar pages (wxBen). +- Add expand/collapse button to wxRibbonBar (rakeshthp). - Fix item data access in wxDataViewListCtrl (Kry). wxGTK: diff --git a/include/wx/ribbon/art.h b/include/wx/ribbon/art.h index e2f9177b98..5d40437594 100644 --- a/include/wx/ribbon/art.h +++ b/include/wx/ribbon/art.h @@ -103,6 +103,10 @@ enum wxRibbonArtSetting wxRIBBON_ART_PANEL_ACTIVE_BACKGROUND_GRADIENT_COLOUR, wxRIBBON_ART_PANEL_BUTTON_FACE_COLOUR, wxRIBBON_ART_PANEL_BUTTON_HOVER_FACE_COLOUR, + + wxRIBBON_ART_PAGE_TOGGLE_FACE_COLOUR, + wxRIBBON_ART_PAGE_TOGGLE_HOVER_FACE_COLOUR, + wxRIBBON_ART_PAGE_BORDER_COLOUR, wxRIBBON_ART_PAGE_BACKGROUND_TOP_COLOUR, wxRIBBON_ART_PAGE_BACKGROUND_TOP_GRADIENT_COLOUR, @@ -185,6 +189,7 @@ enum wxRibbonGalleryButtonState wxRIBBON_GALLERY_BUTTON_DISABLED }; +class wxRibbonBar; class wxRibbonPage; class wxRibbonPanel; class wxRibbonGallery; @@ -297,6 +302,12 @@ public: wxRibbonButtonKind kind, long state) = 0; + virtual void DrawToggleButton( + wxDC& dc, + wxRibbonBar* wnd, + const wxRect& rect, + bool upBitmap) = 0; + virtual void GetBarTabWidth( wxDC& dc, wxWindow* wnd, @@ -380,6 +391,10 @@ public: bool is_first, bool is_last, wxRect* dropdown_region) = 0; + + virtual wxRect GetBarToggleButtonArea(wxDC& dc, + const wxRibbonBar* wnd, + wxRect rect)= 0; }; class WXDLLIMPEXP_RIBBON wxRibbonMSWArtProvider : public wxRibbonArtProvider @@ -491,6 +506,12 @@ public: wxRibbonButtonKind kind, long state); + void DrawToggleButton( + wxDC& dc, + wxRibbonBar* wnd, + const wxRect& rect, + bool upBitmap); + void GetBarTabWidth( wxDC& dc, wxWindow* wnd, @@ -570,6 +591,10 @@ public: bool is_last, wxRect* dropdown_region); + wxRect GetBarToggleButtonArea(wxDC& dc, + const wxRibbonBar* wnd, + wxRect rect); + protected: void ReallyDrawTabSeparator(wxWindow* wnd, const wxRect& rect, double visibility); void DrawPartialPageBackground(wxDC& dc, wxWindow* wnd, const wxRect& rect, @@ -605,6 +630,8 @@ protected: wxBitmap m_gallery_extension_bitmap[4]; wxBitmap m_toolbar_drop_bitmap; wxBitmap m_panel_extension_bitmap[2]; + wxBitmap m_ribbon_toggle_up_bitmap[2]; + wxBitmap m_ribbon_toggle_down_bitmap[2]; wxColour m_primary_scheme_colour; wxColour m_secondary_scheme_colour; @@ -629,6 +656,8 @@ protected: wxColour m_panel_active_background_top_gradient_colour; wxColour m_panel_button_face_colour; wxColour m_panel_button_hover_face_colour; + wxColour m_page_toggle_face_colour; + wxColour m_page_toggle_hover_face_colour; wxColour m_page_background_colour; wxColour m_page_background_gradient_colour; wxColour m_page_background_top_colour; @@ -681,6 +710,7 @@ protected: wxBrush m_gallery_button_hover_background_top_brush; wxBrush m_gallery_button_active_background_top_brush; wxBrush m_gallery_button_disabled_background_top_brush; + wxBrush m_ribbon_toggle_brush; wxFont m_tab_label_font; wxFont m_panel_label_font; @@ -698,6 +728,7 @@ protected: wxPen m_gallery_border_pen; wxPen m_gallery_item_border_pen; wxPen m_toolbar_border_pen; + wxPen m_ribbon_toggle_pen; double m_cached_tab_separator_visibility; long m_flags; diff --git a/include/wx/ribbon/bar.h b/include/wx/ribbon/bar.h index d5a97cbe26..4836578ccc 100644 --- a/include/wx/ribbon/bar.h +++ b/include/wx/ribbon/bar.h @@ -28,10 +28,12 @@ enum wxRibbonBarOption wxRIBBON_BAR_SHOW_PANEL_EXT_BUTTONS = 1 << 3, wxRIBBON_BAR_SHOW_PANEL_MINIMISE_BUTTONS = 1 << 4, wxRIBBON_BAR_ALWAYS_SHOW_TABS = 1 << 5, + wxRIBBON_BAR_SHOW_TOGGLE_BUTTON = 1 << 6, wxRIBBON_BAR_DEFAULT_STYLE = wxRIBBON_BAR_FLOW_HORIZONTAL | wxRIBBON_BAR_SHOW_PAGE_LABELS - | wxRIBBON_BAR_SHOW_PANEL_EXT_BUTTONS, + | wxRIBBON_BAR_SHOW_PANEL_EXT_BUTTONS + | wxRIBBON_BAR_SHOW_TOGGLE_BUTTON, wxRIBBON_BAR_FOLDBAR_STYLE = wxRIBBON_BAR_FLOW_VERTICAL | wxRIBBON_BAR_SHOW_PAGE_ICONS @@ -135,12 +137,16 @@ public: long GetWindowStyleFlag() const; virtual bool Realize(); + // Implementation only. + bool IsToggleButtonHovered() const { return m_toggle_button_hovered; } + protected: friend class wxRibbonPage; virtual wxSize DoGetBestSize() const; wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } wxRibbonPageTabInfo* HitTestTabs(wxPoint position, int* index = NULL); + void HitTestToggleButton(wxPoint position); void CommonInit(long style); void AddPage(wxRibbonPage *page); @@ -168,6 +174,7 @@ protected: wxRibbonPageTabInfoArray m_pages; wxRect m_tab_scroll_left_button_rect; wxRect m_tab_scroll_right_button_rect; + wxRect m_toggle_button_rect; long m_flags; int m_tabs_total_width_ideal; int m_tabs_total_width_minimum; @@ -181,6 +188,8 @@ protected: int m_tab_scroll_right_button_state; bool m_tab_scroll_buttons_shown; bool m_arePanelsShown; + bool m_bar_hovered; + bool m_toggle_button_hovered; #ifndef SWIG DECLARE_CLASS(wxRibbonBar) @@ -197,6 +206,7 @@ wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON, wxEVT_COMMAND_RIBBONBAR_TAB_MIDDLE_ wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON, wxEVT_COMMAND_RIBBONBAR_TAB_RIGHT_DOWN, wxRibbonBarEvent); wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON, wxEVT_COMMAND_RIBBONBAR_TAB_RIGHT_UP, wxRibbonBarEvent); wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON, wxEVT_COMMAND_RIBBONBAR_TAB_LEFT_DCLICK, wxRibbonBarEvent); +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON, wxEVT_COMMAND_RIBBONBAR_TOGGLED, wxRibbonBarEvent); typedef void (wxEvtHandler::*wxRibbonBarEventFunction)(wxRibbonBarEvent&); @@ -217,6 +227,8 @@ typedef void (wxEvtHandler::*wxRibbonBarEventFunction)(wxRibbonBarEvent&); wx__DECLARE_EVT1(wxEVT_COMMAND_RIBBONBAR_TAB_RIGHT_UP, winid, wxRibbonBarEventHandler(fn)) #define EVT_RIBBONBAR_TAB_LEFT_DCLICK(winid, fn) \ wx__DECLARE_EVT1(wxEVT_COMMAND_RIBBONBAR_TAB_LEFT_DCLICK, winid, wxRibbonBarEventHandler(fn)) +#define EVT_RIBBONBAR_TOGGLED(winid, fn) \ + wx__DECLARE_EVT1(wxEVT_COMMAND_RIBBONBAR_TOGGLED, winid, wxRibbonBarEventHandler(fn)) #else // wxpython/swig event work @@ -227,6 +239,7 @@ typedef void (wxEvtHandler::*wxRibbonBarEventFunction)(wxRibbonBarEvent&); %constant wxEventType wxEVT_COMMAND_RIBBONBAR_TAB_RIGHT_DOWN; %constant wxEventType wxEVT_COMMAND_RIBBONBAR_TAB_RIGHT_UP; %constant wxEventType wxEVT_COMMAND_RIBBONBAR_TAB_LEFT_DCLICK; +%constant wxEventType wxEVT_COMMAND_RIBBONBAR_TOGGLED; %pythoncode { EVT_RIBBONBAR_PAGE_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_RIBBONBAR_PAGE_CHANGED, 1 ) @@ -236,6 +249,7 @@ typedef void (wxEvtHandler::*wxRibbonBarEventFunction)(wxRibbonBarEvent&); EVT_RIBBONBAR_TAB_RIGHT_DOWN = wx.PyEventBinder( wxEVT_COMMAND_RIBBONBAR_TAB_RIGHT_DOWN, 1 ) EVT_RIBBONBAR_TAB_RIGHT_UP = wx.PyEventBinder( wxEVT_COMMAND_RIBBONBAR_TAB_RIGHT_UP, 1 ) EVT_RIBBONBAR_TAB_LEFT_DCLICK = wx.PyEventBinder( wxEVT_COMMAND_RIBBONBAR_TAB_LEFT_DCLICK, 1 ) + EVT_RIBBONBAR_TOGGLED = wx.PyEventBinder( wxEVT_COMMAND_RIBBONBAR_TOGGLED, 1 ) } #endif diff --git a/interface/wx/ribbon/bar.h b/interface/wx/ribbon/bar.h index 93274decc2..32eb4da06b 100644 --- a/interface/wx/ribbon/bar.h +++ b/interface/wx/ribbon/bar.h @@ -64,7 +64,8 @@ public: @beginStyleTable @style{wxRIBBON_BAR_DEFAULT_STYLE} Defined as wxRIBBON_BAR_FLOW_HORIZONTAL | - wxRIBBON_BAR_SHOW_PAGE_LABELS | wxRIBBON_BAR_SHOW_PANEL_EXT_BUTTONS + wxRIBBON_BAR_SHOW_PAGE_LABELS | wxRIBBON_BAR_SHOW_PANEL_EXT_BUTTONS | + wxRIBBON_BAR_SHOW_TOGGLE_BUTTON. @style{wxRIBBON_BAR_FOLDBAR_STYLE} Defined as wxRIBBON_BAR_FLOW_VERTICAL | wxRIBBON_BAR_SHOW_PAGE_ICONS | wxRIBBON_BAR_SHOW_PANEL_EXT_BUTTONS | @@ -83,6 +84,9 @@ public: @style{wxRIBBON_BAR_SHOW_PANEL_MINIMISE_BUTTONS} Causes minimise buttons to be shown on panels (where the panel has such a button). + @style{wxRIBBON_BAR_SHOW_TOGGLE_BUTTON} + Causes a toggle button to appear on the ribbon bar at top-right corner. + This style is new since wxWidgets 2.9.5. @endStyleTable @@ -103,6 +107,9 @@ public: Triggered when the right mouse button is released on a tab. @event{EVT_RIBBONBAR_TAB_LEFT_DCLICK(id, func)} Triggered when the left mouse button is double clicked on a tab. + @event{EVT_RIBBONBAR_TOGGLE_BUTTON_CLICK(id, func)} + Triggered when the button triggering the ribbon bar is clicked. This + event is new since wxWidgets 2.9.5. @endEventTable @library{wxribbon} diff --git a/samples/ribbon/ribbondemo.cpp b/samples/ribbon/ribbondemo.cpp index 4473602d2f..cd6077a34b 100644 --- a/samples/ribbon/ribbondemo.cpp +++ b/samples/ribbon/ribbondemo.cpp @@ -134,6 +134,7 @@ public: void OnHidePages(wxRibbonButtonBarEvent& evt); void OnShowPages(wxRibbonButtonBarEvent& evt); void OnTogglePanels(wxCommandEvent& evt); + void OnRibbonBarToggled(wxRibbonBarEvent& evt); void OnExtButton(wxRibbonPanelEvent& evt); @@ -234,6 +235,7 @@ EVT_RIBBONPANEL_EXTBUTTON_ACTIVATED(wxID_ANY, MyFrame::OnExtButton) EVT_RIBBONBUTTONBAR_CLICKED(ID_REMOVE_PAGE, MyFrame::OnRemovePage) EVT_RIBBONBUTTONBAR_CLICKED(ID_HIDE_PAGES, MyFrame::OnHidePages) EVT_RIBBONBUTTONBAR_CLICKED(ID_SHOW_PAGES, MyFrame::OnShowPages) +EVT_RIBBONBAR_TOGGLED(wxID_ANY, MyFrame::OnRibbonBarToggled) END_EVENT_TABLE() #include "align_center.xpm" @@ -262,10 +264,7 @@ END_EVENT_TABLE() MyFrame::MyFrame() : wxFrame(NULL, wxID_ANY, wxT("wxRibbon Sample Application"), wxDefaultPosition, wxSize(800, 600), wxDEFAULT_FRAME_STYLE) { - m_ribbon = new wxRibbonBar(this, wxID_ANY, - wxDefaultPosition, wxDefaultSize, - wxRIBBON_BAR_DEFAULT_STYLE | - wxRIBBON_BAR_SHOW_PANEL_EXT_BUTTONS); + m_ribbon = new wxRibbonBar(this); { wxRibbonPage* home = new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Examples"), ribbon_xpm); @@ -1008,3 +1007,11 @@ void MyFrame::OnShowPages(wxRibbonButtonBarEvent& WXUNUSED(evt)) m_ribbon->ShowPage(3); m_ribbon->Realize(); } + +void MyFrame::OnRibbonBarToggled(wxRibbonBarEvent& WXUNUSED(evt)) +{ + AddText(wxString::Format("Ribbon bar %s.", + m_ribbon->ArePanelsShown() + ? "expanded" + : "collapsed")); +} diff --git a/src/ribbon/art_msw.cpp b/src/ribbon/art_msw.cpp index 2785dc9d3d..eb530dcef3 100644 --- a/src/ribbon/art_msw.cpp +++ b/src/ribbon/art_msw.cpp @@ -94,6 +94,34 @@ static const char* const panel_extension_xpm[] = { "x xxx", " xxxx"}; +static const char* const panel_toggle_down_xpm[] = { + "7 9 2 1", + " c None", + "x c #FF00FF", + " ", + "x x", + "xx xx", + " xx xx ", + "x xxx x", + "xx x xx", + " xx xx ", + " xxx ", + " x ",}; + +static const char* const panel_toggle_up_xpm[] = { + "7 9 2 1", + " c None", + "x c #FF00FF", + " x ", + " xxx ", + " xx xx ", + "xx x xx", + "x xxx x", + " xx xx ", + "xx xx", + "x x", + " ",}; + wxRibbonMSWArtProvider::wxRibbonMSWArtProvider(bool set_colour_scheme) { m_flags = 0; @@ -233,6 +261,11 @@ void wxRibbonMSWArtProvider::SetColourScheme( SetColour(wxRIBBON_ART_PANEL_BUTTON_FACE_COLOUR, LikePrimary(1.4, -0.21, -0.23)); SetColour(wxRIBBON_ART_PANEL_BUTTON_HOVER_FACE_COLOUR, LikePrimary(1.5, -0.24, -0.29)); + m_ribbon_toggle_brush = LikeSecondary(-0.9, 0.16, -0.07); + m_ribbon_toggle_pen = LikeSecondary(-3.9, -0.16, -0.14); + SetColour(wxRIBBON_ART_PAGE_TOGGLE_FACE_COLOUR, LikePrimary(1.7, -0.20, -0.15)); + SetColour(wxRIBBON_ART_PAGE_TOGGLE_HOVER_FACE_COLOUR, LikePrimary(1.8, -0.23, -0.21)); + m_gallery_button_disabled_background_colour = LikePrimary(-2.8, -0.46, 0.09); m_gallery_button_disabled_background_top_brush = LikePrimary(-2.8, -0.36, 0.15); m_gallery_hover_background_brush = LikePrimary(-0.8, 0.05, 0.15); @@ -308,6 +341,8 @@ void wxRibbonMSWArtProvider::CloneTo(wxRibbonMSWArtProvider* copy) const for(i = 0; i < 2; ++i) { copy->m_panel_extension_bitmap[i] = m_panel_extension_bitmap[i]; + copy->m_ribbon_toggle_up_bitmap[i] = m_ribbon_toggle_up_bitmap[i]; + copy->m_ribbon_toggle_down_bitmap[i] = m_ribbon_toggle_down_bitmap[i]; } copy->m_toolbar_drop_bitmap = m_toolbar_drop_bitmap; @@ -315,6 +350,9 @@ void wxRibbonMSWArtProvider::CloneTo(wxRibbonMSWArtProvider* copy) const copy->m_secondary_scheme_colour = m_secondary_scheme_colour; copy->m_tertiary_scheme_colour = m_tertiary_scheme_colour; + copy->m_page_toggle_face_colour = m_page_toggle_face_colour; + copy->m_page_toggle_hover_face_colour = m_page_toggle_hover_face_colour; + copy->m_button_bar_label_colour = m_button_bar_label_colour; copy->m_tab_label_colour = m_tab_label_colour; copy->m_tab_separator_colour = m_tab_separator_colour; @@ -372,6 +410,7 @@ void wxRibbonMSWArtProvider::CloneTo(wxRibbonMSWArtProvider* copy) const copy->m_gallery_button_hover_background_top_brush = m_gallery_button_hover_background_top_brush; copy->m_gallery_button_active_background_top_brush = m_gallery_button_active_background_top_brush; copy->m_gallery_button_disabled_background_top_brush = m_gallery_button_disabled_background_top_brush; + copy->m_ribbon_toggle_brush = m_ribbon_toggle_brush; copy->m_tab_label_font = m_tab_label_font; copy->m_button_bar_label_font = m_button_bar_label_font; @@ -389,6 +428,7 @@ void wxRibbonMSWArtProvider::CloneTo(wxRibbonMSWArtProvider* copy) const copy->m_button_bar_active_border_pen = m_button_bar_active_border_pen; copy->m_gallery_item_border_pen = m_gallery_item_border_pen; copy->m_toolbar_border_pen = m_toolbar_border_pen; + copy->m_ribbon_toggle_pen = m_ribbon_toggle_pen; copy->m_flags = m_flags; copy->m_tab_separation_size = m_tab_separation_size; @@ -705,6 +745,10 @@ wxColour wxRibbonMSWArtProvider::GetColour(int id) const return m_toolbar_border_pen.GetColour(); case wxRIBBON_ART_TOOLBAR_FACE_COLOUR: return m_tool_face_colour; + case wxRIBBON_ART_PAGE_TOGGLE_FACE_COLOUR: + return m_page_toggle_face_colour; + case wxRIBBON_ART_PAGE_TOGGLE_HOVER_FACE_COLOUR: + return m_page_toggle_hover_face_colour; default: wxFAIL_MSG(wxT("Invalid Metric Ordinal")); break; @@ -975,6 +1019,16 @@ void wxRibbonMSWArtProvider::SetColour(int id, const wxColor& colour) m_tool_face_colour = colour; m_toolbar_drop_bitmap = wxRibbonLoadPixmap(gallery_down_xpm, colour); break; + case wxRIBBON_ART_PAGE_TOGGLE_FACE_COLOUR: + m_page_toggle_face_colour = colour; + m_ribbon_toggle_down_bitmap[0] = wxRibbonLoadPixmap(panel_toggle_down_xpm, colour); + m_ribbon_toggle_up_bitmap[0] = wxRibbonLoadPixmap(panel_toggle_up_xpm, colour); + break; + case wxRIBBON_ART_PAGE_TOGGLE_HOVER_FACE_COLOUR: + m_page_toggle_hover_face_colour = colour; + m_ribbon_toggle_down_bitmap[1] = wxRibbonLoadPixmap(panel_toggle_down_xpm, colour); + m_ribbon_toggle_up_bitmap[1] = wxRibbonLoadPixmap(panel_toggle_up_xpm, colour); + break; default: wxFAIL_MSG(wxT("Invalid Metric Ordinal")); break; @@ -2424,6 +2478,36 @@ void wxRibbonMSWArtProvider::DrawTool( bg_rect.y + (bg_rect.height - bitmap.GetHeight()) / 2, true); } +void +wxRibbonMSWArtProvider::DrawToggleButton(wxDC& dc, + wxRibbonBar* wnd, + const wxRect& rect, + bool upBitmap) +{ + DrawPartialPageBackground(dc, wnd, rect, false); + + dc.DestroyClippingRegion(); + dc.SetClippingRegion(rect); + + if(wnd->IsToggleButtonHovered()) + { + dc.SetPen(m_ribbon_toggle_pen); + dc.SetBrush(m_ribbon_toggle_brush); + dc.DrawRoundedRectangle(rect.GetX(), rect.GetY(), 12, 12, 1.0); + if(upBitmap) + dc.DrawBitmap(m_ribbon_toggle_up_bitmap[1], rect.GetX()+2, rect.GetY()+2, true); + else + dc.DrawBitmap(m_ribbon_toggle_down_bitmap[1], rect.GetX()+2, rect.GetY()+2, true); + } + else + { + if(upBitmap) + dc.DrawBitmap(m_ribbon_toggle_up_bitmap[0], rect.GetX()+2, rect.GetY()+2, true); + else + dc.DrawBitmap(m_ribbon_toggle_down_bitmap[0], rect.GetX()+2, rect.GetY()+2, true); + } +} + void wxRibbonMSWArtProvider::GetBarTabWidth( wxDC& dc, wxWindow* WXUNUSED(wnd), @@ -2878,4 +2962,13 @@ wxSize wxRibbonMSWArtProvider::GetToolSize( return size; } +wxRect +wxRibbonMSWArtProvider::GetBarToggleButtonArea(wxDC& WXUNUSED(dc), + const wxRibbonBar* WXUNUSED(wnd), + wxRect rect) +{ + rect = wxRect(rect.GetWidth()-30, 6, 12, 12); + return rect; +} + #endif // wxUSE_RIBBON diff --git a/src/ribbon/bar.cpp b/src/ribbon/bar.cpp index 1e2acc9e2d..57d8cda87d 100644 --- a/src/ribbon/bar.cpp +++ b/src/ribbon/bar.cpp @@ -40,6 +40,7 @@ wxDEFINE_EVENT(wxEVT_COMMAND_RIBBONBAR_TAB_MIDDLE_UP, wxRibbonBarEvent); wxDEFINE_EVENT(wxEVT_COMMAND_RIBBONBAR_TAB_RIGHT_DOWN, wxRibbonBarEvent); wxDEFINE_EVENT(wxEVT_COMMAND_RIBBONBAR_TAB_RIGHT_UP, wxRibbonBarEvent); wxDEFINE_EVENT(wxEVT_COMMAND_RIBBONBAR_TAB_LEFT_DCLICK, wxRibbonBarEvent); +wxDEFINE_EVENT(wxEVT_COMMAND_RIBBONBAR_TOGGLED, wxRibbonBarEvent); IMPLEMENT_CLASS(wxRibbonBar, wxRibbonControl) IMPLEMENT_DYNAMIC_CLASS(wxRibbonBarEvent, wxNotifyEvent) @@ -243,6 +244,7 @@ void wxRibbonBar::OnMouseMove(wxMouseEvent& evt) { RefreshTabBar(); } + HitTestToggleButton(evt.GetPosition()); } void wxRibbonBar::OnMouseLeave(wxMouseEvent& WXUNUSED(evt)) @@ -270,6 +272,12 @@ void wxRibbonBar::OnMouseLeave(wxMouseEvent& WXUNUSED(evt)) { RefreshTabBar(); } + if(m_toggle_button_hovered) + { + m_bar_hovered = false; + m_toggle_button_hovered = false; + Refresh(false); + } } wxRibbonPage* wxRibbonBar::GetPage(int n) @@ -720,6 +728,9 @@ void wxRibbonBar::CommonInit(long style) SetArtProvider(new wxRibbonDefaultArtProvider); } SetBackgroundStyle(wxBG_STYLE_CUSTOM); + + m_toggle_button_hovered = false; + m_bar_hovered = false; } void wxRibbonBar::SetArtProvider(wxRibbonArtProvider* art) @@ -757,6 +768,8 @@ void wxRibbonBar::OnPaint(wxPaintEvent& WXUNUSED(evt)) DoEraseBackground(dc); + m_toggle_button_rect = m_art->GetBarToggleButtonArea(dc, this, GetSize()); + size_t numtabs = m_pages.GetCount(); double sep_visibility = 0.0; bool draw_sep = false; @@ -830,6 +843,9 @@ void wxRibbonBar::OnPaint(wxPaintEvent& WXUNUSED(evt)) m_art->DrawScrollButton(dc, this, m_tab_scroll_right_button_rect, wxRIBBON_SCROLL_BTN_RIGHT | m_tab_scroll_right_button_state | wxRIBBON_SCROLL_BTN_FOR_TABS); } } + wxRect rect(GetClientSize().GetWidth() - 30, 6, 12, 12); + if ( m_flags & wxRIBBON_BAR_SHOW_TOGGLE_BUTTON ) + m_art->DrawToggleButton(dc, this, rect, ArePanelsShown()); } void wxRibbonBar::OnEraseBackground(wxEraseEvent& WXUNUSED(evt)) @@ -927,6 +943,23 @@ void wxRibbonBar::OnMouseLeftDown(wxMouseEvent& evt) RefreshTabBar(); } } + + wxPoint position = evt.GetPosition(); + + if(position.x >= 0 && position.y >= 0) + { + wxSize size = GetSize(); + if(position.x < size.GetWidth() && position.y < size.GetHeight()) + { + if(m_toggle_button_rect.Contains(position)) + { + ShowPanels(!ArePanelsShown()); + wxRibbonBarEvent event(wxEVT_COMMAND_RIBBONBAR_TOGGLED, GetId()); + event.SetEventObject(this); + ProcessWindowEvent(event); + } + } + } } void wxRibbonBar::OnMouseLeftUp(wxMouseEvent& WXUNUSED(evt)) @@ -1110,4 +1143,29 @@ wxSize wxRibbonBar::DoGetBestSize() const return best; } +void wxRibbonBar::HitTestToggleButton(wxPoint position) +{ + bool hovered = false, toggle_button_hovered = false; + if(position.x >= 0 && position.y >= 0) + { + wxSize size = GetSize(); + if(position.x < size.GetWidth() && position.y < size.GetHeight()) + { + hovered = true; + } + } + if(hovered) + { + toggle_button_hovered = (m_flags & wxRIBBON_BAR_SHOW_TOGGLE_BUTTON) && + m_toggle_button_rect.Contains(position); + + if(hovered != m_bar_hovered || toggle_button_hovered != m_toggle_button_hovered) + { + m_bar_hovered = hovered; + m_toggle_button_hovered = toggle_button_hovered; + Refresh(false); + } + } +} + #endif // wxUSE_RIBBON