From 70f86dedfd91afeb6bd1f941802063941431d13b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 15 Aug 2012 23:34:36 +0000 Subject: [PATCH] Add page highlighting to wxRibbonBar. Allow visually highlighting a page to make it more noticeable to the user. Closes #14527. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72347 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + include/wx/ribbon/bar.h | 5 +++++ interface/wx/ribbon/bar.h | 29 +++++++++++++++++++++++++++ samples/ribbon/ribbondemo.cpp | 2 ++ src/ribbon/art_aui.cpp | 22 ++++++++++++++++++--- src/ribbon/art_msw.cpp | 37 ++++++++++++++++++++++++++++++++++- src/ribbon/bar.cpp | 15 ++++++++++++++ 7 files changed, 107 insertions(+), 4 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 70ae91854f..c86448a104 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -536,6 +536,7 @@ All (GUI): - Respect window max size in wxBoxSizer (Nathan Ridge). - Add possibility to hide and show again wxRibbonBar pages (wxBen). +- Add wxRibbonBar pages highlighting (wxBen). - Add expand/collapse button to wxRibbonBar (rakeshthp). - Fix item data access in wxDataViewListCtrl (Kry). - Fix problem with floating maximized AUI panes (Laurent Poujoulat). diff --git a/include/wx/ribbon/bar.h b/include/wx/ribbon/bar.h index 4836578ccc..755358d15b 100644 --- a/include/wx/ribbon/bar.h +++ b/include/wx/ribbon/bar.h @@ -82,6 +82,7 @@ public: int minimum_width; bool active; bool hovered; + bool highlight; bool shown; }; @@ -127,6 +128,10 @@ public: void ShowPage(size_t page, bool show = true); void HidePage(size_t page) { ShowPage(page, false); } + bool IsPageHighlighted(size_t page) const; + void AddPageHighlight(size_t page, bool highlight = true); + void RemovePageHighlight(size_t page) { AddPageHighlight(page, false); } + void ShowPanels(bool show = true); void HidePanels() { ShowPanels(false); } bool ArePanelsShown() const { return m_arePanelsShown; } diff --git a/interface/wx/ribbon/bar.h b/interface/wx/ribbon/bar.h index 32eb4da06b..cfc9af0a6f 100644 --- a/interface/wx/ribbon/bar.h +++ b/interface/wx/ribbon/bar.h @@ -284,6 +284,35 @@ public: */ void HidePage(size_t page); + /** + Indicates whether a tab is currently highlighted. + + @see AddPageHighlight() + + @since 2.9.5 + */ + bool IsPageHighlighted(size_t page) const; + + /** + Highlight the specified tab. + + Highlighted tabs have a colour between that of the active tab + and a tab over which the mouse is hovering. This can be used + to make a tab (usually temporarily) more noticeable to the user. + + @since 2.9.5 + */ + void AddPageHighlight(size_t page, bool highlight = true); + + /** + Changes a tab to not be highlighted. + + @see AddPageHighlight() + + @since 2.9.5 + */ + void RemovePageHighlight(size_t page); + /** Shows or hides the panel area of the ribbon bar. diff --git a/samples/ribbon/ribbondemo.cpp b/samples/ribbon/ribbondemo.cpp index cd6077a34b..3fbffc2747 100644 --- a/samples/ribbon/ribbondemo.cpp +++ b/samples/ribbon/ribbondemo.cpp @@ -401,6 +401,8 @@ MyFrame::MyFrame() bar->AddButton(ID_HIDE_PAGES, wxT("Hide Pages"), ribbon_xpm); bar->AddButton(ID_SHOW_PAGES, wxT("Show Pages"), ribbon_xpm); } + new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Highlight Page"), empty_xpm); + m_ribbon->AddPageHighlight(m_ribbon->GetPageCount()-1); m_ribbon->Realize(); diff --git a/src/ribbon/art_aui.cpp b/src/ribbon/art_aui.cpp index a8fd9c2b34..7249af03ee 100644 --- a/src/ribbon/art_aui.cpp +++ b/src/ribbon/art_aui.cpp @@ -326,7 +326,7 @@ void wxRibbonAUIArtProvider::DrawTab(wxDC& dc, dc.SetFont(m_tab_label_font); dc.SetPen(*wxTRANSPARENT_PEN); - if(tab.active || tab.hovered) + if(tab.active || tab.hovered || tab.highlight) { if(tab.active) { @@ -343,8 +343,24 @@ void wxRibbonAUIArtProvider::DrawTab(wxDC& dc, dc.SetBrush(m_tab_active_top_background_brush); dc.DrawRectangle(tab.rect.x, tab.rect.y + 3, tab.rect.width - 1, grad_rect.y - tab.rect.y - 3); - dc.GradientFillLinear(grad_rect, m_tab_active_background_colour, - m_tab_active_background_gradient_colour, wxSOUTH); + if(tab.highlight) + { + wxColour top_colour((m_tab_active_background_colour.Red() + m_tab_hover_background_top_colour.Red())/2, + (m_tab_active_background_colour.Green() + m_tab_hover_background_top_colour.Green())/2, + (m_tab_active_background_colour.Blue() + m_tab_hover_background_top_colour.Blue())/2); + + wxColour bottom_colour((m_tab_active_background_gradient_colour.Red() + m_tab_hover_background_top_gradient_colour.Red())/2, + (m_tab_active_background_gradient_colour.Green() + m_tab_hover_background_top_gradient_colour.Green())/2, + (m_tab_active_background_gradient_colour.Blue() + m_tab_hover_background_top_gradient_colour.Blue())/2); + + dc.GradientFillLinear(grad_rect, top_colour, + bottom_colour, wxSOUTH); + } + else + { + dc.GradientFillLinear(grad_rect, m_tab_active_background_colour, + m_tab_active_background_gradient_colour, wxSOUTH); + } } else { diff --git a/src/ribbon/art_msw.cpp b/src/ribbon/art_msw.cpp index eb530dcef3..0484c51b98 100644 --- a/src/ribbon/art_msw.cpp +++ b/src/ribbon/art_msw.cpp @@ -1063,7 +1063,7 @@ void wxRibbonMSWArtProvider::DrawTab( if(tab.rect.height <= 2) return; - if(tab.active || tab.hovered) + if(tab.active || tab.hovered || tab.highlight) { if(tab.active) { @@ -1098,6 +1098,41 @@ void wxRibbonMSWArtProvider::DrawTab( dc.GradientFillLinear(background, m_tab_hover_background_colour, m_tab_hover_background_gradient_colour, wxSOUTH); } + else if(tab.highlight) + { + wxRect background(tab.rect); + + background.x += 2; + background.y += 2; + background.width -= 4; + background.height -= 3; + int h = background.height; + background.height /= 2; + + //For highlight pages we show a colour between the active page and for a hovered page: + wxColour top_colour1((m_tab_active_background_colour.Red() + m_tab_hover_background_top_colour.Red())/2, + (m_tab_active_background_colour.Green() + m_tab_hover_background_top_colour.Green())/2, + (m_tab_active_background_colour.Blue() + m_tab_hover_background_top_colour.Blue())/2); + + wxColour bottom_colour1((m_tab_active_background_gradient_colour.Red() + m_tab_hover_background_top_gradient_colour.Red())/2, + (m_tab_active_background_gradient_colour.Green() + m_tab_hover_background_top_gradient_colour.Green())/2, + (m_tab_active_background_gradient_colour.Blue() + m_tab_hover_background_top_gradient_colour.Blue())/2); + + dc.GradientFillLinear(background, top_colour1, bottom_colour1, wxSOUTH); + + background.y += background.height; + background.height = h - background.height; + + wxColour top_colour2((m_tab_active_background_colour.Red() + m_tab_hover_background_colour.Red())/2, + (m_tab_active_background_colour.Green() + m_tab_hover_background_colour.Green())/2, + (m_tab_active_background_colour.Blue() + m_tab_hover_background_colour.Blue())/2); + + wxColour bottom_colour2((m_tab_active_background_gradient_colour.Red() + m_tab_hover_background_gradient_colour.Red())/2, + (m_tab_active_background_gradient_colour.Green() + m_tab_hover_background_gradient_colour.Green())/2, + (m_tab_active_background_gradient_colour.Blue() + m_tab_hover_background_gradient_colour.Blue())/2); + + dc.GradientFillLinear(background, top_colour2, bottom_colour2, wxSOUTH); + } wxPoint border_points[6]; border_points[0] = wxPoint(1, tab.rect.height - 2); diff --git a/src/ribbon/bar.cpp b/src/ribbon/bar.cpp index 57d8cda87d..e64b381778 100644 --- a/src/ribbon/bar.cpp +++ b/src/ribbon/bar.cpp @@ -67,6 +67,7 @@ void wxRibbonBar::AddPage(wxRibbonPage *page) info.page = page; info.active = false; info.hovered = false; + info.highlight = false; info.shown = true; // info.rect not set (intentional) @@ -306,6 +307,20 @@ void wxRibbonBar::ShowPage(size_t page, bool show) m_pages.Item(page).shown = show; } +bool wxRibbonBar::IsPageHighlighted(size_t page) const +{ + if (page >= m_pages.GetCount()) + return false; + return m_pages.Item(page).highlight; +} + +void wxRibbonBar::AddPageHighlight(size_t page, bool highlight) +{ + if(page >= m_pages.GetCount()) + return; + m_pages.Item(page).highlight = highlight; +} + void wxRibbonBar::DeletePage(size_t n) { if(n < m_pages.GetCount()) -- 2.47.2