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
This commit is contained in:
Tobias Taschner
2015-09-28 19:29:51 +02:00
committed by Vadim Zeitlin
parent e0a175e0b8
commit 1a8bcd4d88
2 changed files with 37 additions and 1 deletions

View File

@@ -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();

View File

@@ -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