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:
committed by
Vadim Zeitlin
parent
e0a175e0b8
commit
1a8bcd4d88
@@ -99,6 +99,7 @@ public:
|
|||||||
wxBitmap bitmap; // tab's bitmap
|
wxBitmap bitmap; // tab's bitmap
|
||||||
wxRect rect; // tab's hit rectangle
|
wxRect rect; // tab's hit rectangle
|
||||||
bool active; // true if the page is currently active
|
bool active; // true if the page is currently active
|
||||||
|
bool hover; // true if mouse hovering over tab
|
||||||
};
|
};
|
||||||
|
|
||||||
class WXDLLIMPEXP_AUI wxAuiTabContainerButton
|
class WXDLLIMPEXP_AUI wxAuiTabContainerButton
|
||||||
@@ -234,6 +235,8 @@ protected:
|
|||||||
wxAuiTabContainerButton* m_hoverButton;
|
wxAuiTabContainerButton* m_hoverButton;
|
||||||
wxAuiTabContainerButton* m_pressedButton;
|
wxAuiTabContainerButton* m_pressedButton;
|
||||||
|
|
||||||
|
void SetHoverTab(wxWindow* wnd);
|
||||||
|
|
||||||
#ifndef SWIG
|
#ifndef SWIG
|
||||||
wxDECLARE_CLASS(wxAuiTabCtrl);
|
wxDECLARE_CLASS(wxAuiTabCtrl);
|
||||||
wxDECLARE_EVENT_TABLE();
|
wxDECLARE_EVENT_TABLE();
|
||||||
|
@@ -186,6 +186,7 @@ bool wxAuiTabContainer::AddPage(wxWindow* page,
|
|||||||
wxAuiNotebookPage page_info;
|
wxAuiNotebookPage page_info;
|
||||||
page_info = info;
|
page_info = info;
|
||||||
page_info.window = page;
|
page_info.window = page;
|
||||||
|
page_info.hover = false;
|
||||||
|
|
||||||
m_pages.Add(page_info);
|
m_pages.Add(page_info);
|
||||||
|
|
||||||
@@ -205,6 +206,7 @@ bool wxAuiTabContainer::InsertPage(wxWindow* page,
|
|||||||
wxAuiNotebookPage page_info;
|
wxAuiNotebookPage page_info;
|
||||||
page_info = info;
|
page_info = info;
|
||||||
page_info.window = page;
|
page_info.window = page;
|
||||||
|
page_info.hover = false;
|
||||||
|
|
||||||
if (idx >= m_pages.GetCount())
|
if (idx >= m_pages.GetCount())
|
||||||
m_pages.Add(page_info);
|
m_pages.Add(page_info);
|
||||||
@@ -1233,20 +1235,28 @@ void wxAuiTabCtrl::OnMotion(wxMouseEvent& evt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if wxUSE_TOOLTIPS
|
|
||||||
wxWindow* wnd = NULL;
|
wxWindow* wnd = NULL;
|
||||||
if (evt.Moving() && TabHitTest(evt.m_x, evt.m_y, &wnd))
|
if (evt.Moving() && TabHitTest(evt.m_x, evt.m_y, &wnd))
|
||||||
{
|
{
|
||||||
|
SetHoverTab(wnd);
|
||||||
|
|
||||||
|
#if wxUSE_TOOLTIPS
|
||||||
wxString tooltip(m_pages[GetIdxFromWindow(wnd)].tooltip);
|
wxString tooltip(m_pages[GetIdxFromWindow(wnd)].tooltip);
|
||||||
|
|
||||||
// If the text changes, set it else, keep old, to avoid
|
// If the text changes, set it else, keep old, to avoid
|
||||||
// 'moving tooltip' effect
|
// 'moving tooltip' effect
|
||||||
if (GetToolTipText() != tooltip)
|
if (GetToolTipText() != tooltip)
|
||||||
SetToolTip(tooltip);
|
SetToolTip(tooltip);
|
||||||
|
#endif // wxUSE_TOOLTIPS
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
SetHoverTab(NULL);
|
||||||
|
|
||||||
|
#if wxUSE_TOOLTIPS
|
||||||
UnsetToolTip();
|
UnsetToolTip();
|
||||||
#endif // wxUSE_TOOLTIPS
|
#endif // wxUSE_TOOLTIPS
|
||||||
|
}
|
||||||
|
|
||||||
if (!evt.LeftIsDown() || m_clickPt == wxDefaultPosition)
|
if (!evt.LeftIsDown() || m_clickPt == wxDefaultPosition)
|
||||||
return;
|
return;
|
||||||
@@ -1287,6 +1297,8 @@ void wxAuiTabCtrl::OnLeaveWindow(wxMouseEvent& WXUNUSED(event))
|
|||||||
Refresh();
|
Refresh();
|
||||||
Update();
|
Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SetHoverTab(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxAuiTabCtrl::OnButton(wxAuiNotebookEvent& event)
|
void wxAuiTabCtrl::OnButton(wxAuiNotebookEvent& event)
|
||||||
@@ -3450,5 +3462,26 @@ int wxAuiNotebook::DoModifySelection(size_t n, bool events)
|
|||||||
return m_curPage;
|
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
|
#endif // wxUSE_AUI
|
||||||
|
Reference in New Issue
Block a user