From 1a8bcd4d88a7c5c89590afc9b272401d4424e6c4 Mon Sep 17 00:00:00 2001 From: Tobias Taschner Date: Mon, 28 Sep 2015 19:29:51 +0200 Subject: [PATCH] Add support for mouse hover state to wxAuiTabArt This allows wxAuiNotebook to support drawing its tabs differently depending on whether the mouse is hovering above them or not. See https://github.com/wxWidgets/wxWidgets/pull/105 --- include/wx/aui/auibook.h | 3 +++ src/aui/auibook.cpp | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/include/wx/aui/auibook.h b/include/wx/aui/auibook.h index d96e88fe1e..c6d232e48d 100644 --- a/include/wx/aui/auibook.h +++ b/include/wx/aui/auibook.h @@ -99,6 +99,7 @@ public: wxBitmap bitmap; // tab's bitmap wxRect rect; // tab's hit rectangle bool active; // true if the page is currently active + bool hover; // true if mouse hovering over tab }; class WXDLLIMPEXP_AUI wxAuiTabContainerButton @@ -234,6 +235,8 @@ protected: wxAuiTabContainerButton* m_hoverButton; wxAuiTabContainerButton* m_pressedButton; + void SetHoverTab(wxWindow* wnd); + #ifndef SWIG wxDECLARE_CLASS(wxAuiTabCtrl); wxDECLARE_EVENT_TABLE(); diff --git a/src/aui/auibook.cpp b/src/aui/auibook.cpp index c5391e2d87..92f7fb33d5 100644 --- a/src/aui/auibook.cpp +++ b/src/aui/auibook.cpp @@ -186,6 +186,7 @@ bool wxAuiTabContainer::AddPage(wxWindow* page, wxAuiNotebookPage page_info; page_info = info; page_info.window = page; + page_info.hover = false; m_pages.Add(page_info); @@ -205,6 +206,7 @@ bool wxAuiTabContainer::InsertPage(wxWindow* page, wxAuiNotebookPage page_info; page_info = info; page_info.window = page; + page_info.hover = false; if (idx >= m_pages.GetCount()) m_pages.Add(page_info); @@ -1233,20 +1235,28 @@ void wxAuiTabCtrl::OnMotion(wxMouseEvent& evt) } } -#if wxUSE_TOOLTIPS wxWindow* wnd = NULL; if (evt.Moving() && TabHitTest(evt.m_x, evt.m_y, &wnd)) { + SetHoverTab(wnd); + +#if wxUSE_TOOLTIPS wxString tooltip(m_pages[GetIdxFromWindow(wnd)].tooltip); // If the text changes, set it else, keep old, to avoid // 'moving tooltip' effect if (GetToolTipText() != tooltip) SetToolTip(tooltip); +#endif // wxUSE_TOOLTIPS } else + { + SetHoverTab(NULL); + +#if wxUSE_TOOLTIPS UnsetToolTip(); #endif // wxUSE_TOOLTIPS + } if (!evt.LeftIsDown() || m_clickPt == wxDefaultPosition) return; @@ -1287,6 +1297,8 @@ void wxAuiTabCtrl::OnLeaveWindow(wxMouseEvent& WXUNUSED(event)) Refresh(); Update(); } + + SetHoverTab(NULL); } void wxAuiTabCtrl::OnButton(wxAuiNotebookEvent& event) @@ -3450,5 +3462,26 @@ int wxAuiNotebook::DoModifySelection(size_t n, bool events) return m_curPage; } +void wxAuiTabCtrl::SetHoverTab(wxWindow* wnd) +{ + bool hoverChanged = false; + + const size_t page_count = m_pages.GetCount(); + for ( size_t i = 0; i < page_count; ++i ) + { + wxAuiNotebookPage& page = m_pages.Item(i); + bool oldHover = page.hover; + page.hover = (page.window == wnd); + if ( oldHover != page.hover ) + hoverChanged = true; + } + + if ( hoverChanged ) + { + Refresh(); + Update(); + } +} + #endif // wxUSE_AUI