Added support for page tooltips to wxAuiNotebook.

Allow setting tooltips for the tabs of the individual pages of wxAuiNotebook.

Closes #14216.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71204 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2012-04-16 12:12:26 +00:00
parent 86f5e64bb1
commit 11527fc9f0
5 changed files with 69 additions and 0 deletions

View File

@ -499,6 +499,7 @@ All (GUI):
- Fix setting of the frame icon when using non-standard icon sizes (vid).
- Implement wxDV_ROW_LINES in generic wxDataViewCtrl (RedCAT).
- Added EVT_AUI_PANE_ACTIVATED event (Ronny Krüger).
- Added support for page tooltips to wxAuiNotebook (Armel Asselin).
- Added wxSplitterWindow::SetSashInvisible() (Armel Asselin).
- Enable/disable "Window" menu items in AUI MDI correctly (wsu).
- Added wxTimePickerCtrl::Get/SetTime().

View File

@ -95,6 +95,7 @@ class WXDLLIMPEXP_AUI wxAuiNotebookPage
public:
wxWindow* window; // page's associated window
wxString caption; // caption displayed on the tab
wxString tooltip; // tooltip displayed when hovering over tab title
wxBitmap bitmap; // tab's bitmap
wxRect rect; // tab's hit rectangle
bool active; // true if the page is currently active
@ -295,6 +296,9 @@ public:
bool SetPageText(size_t page, const wxString& text);
wxString GetPageText(size_t pageIdx) const;
bool SetPageToolTip(size_t page, const wxString& text);
wxString GetPageToolTip(size_t pageIdx) const;
bool SetPageBitmap(size_t page, const wxBitmap& bitmap);
wxBitmap GetPageBitmap(size_t pageIdx) const;

View File

@ -219,6 +219,13 @@ public:
*/
wxString GetPageText(size_t page) const;
/**
Returns the tooltip for the tab label of the page.
@since 2.9.4
*/
wxString GetPageToolTip(size_t pageIdx) const;
/**
Returns the currently selected page.
*/
@ -308,6 +315,17 @@ public:
*/
bool SetPageText(size_t page, const wxString& text);
/**
Sets the tooltip displayed when hovering over the tab label of the page.
@return
@true if tooltip was updated, @false if it failed, e.g. because the
page index is invalid.
@since 2.9.4
*/
bool SetPageToolTip(size_t page, const wxString& text);
/**
Sets the font for drawing selected tab labels.
*/

View File

@ -1644,6 +1644,7 @@ wxAuiNotebook* MyFrame::CreateNotebook()
wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
ctrl->AddPage(CreateHTMLCtrl(ctrl), wxT("Welcome to wxAUI") , false, page_bmp);
ctrl->SetPageToolTip(0, "Welcome to wxAUI (this is a page tooltip)");
wxPanel *panel = new wxPanel( ctrl, wxID_ANY );
wxFlexGridSizer *flex = new wxFlexGridSizer( 4, 2, 0, 0 );
@ -1682,6 +1683,8 @@ wxAuiNotebook* MyFrame::CreateNotebook()
ctrl->AddPage( new wxTextCtrl( ctrl, wxID_ANY, wxT("Some more text"),
wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxNO_BORDER) , wxT("wxTextCtrl 7 (longer title)") );
ctrl->SetPageToolTip(ctrl->GetPageCount()-1,
"wxTextCtrl 7: and the tooltip message can be even longer!");
ctrl->AddPage( new wxTextCtrl( ctrl, wxID_ANY, wxT("Some more text"),
wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxNO_BORDER) , wxT("wxTextCtrl 8") );

View File

@ -1237,6 +1237,18 @@ void wxAuiTabCtrl::OnMotion(wxMouseEvent& evt)
}
}
wxWindow* wnd = NULL;
if (evt.Moving() && TabHitTest(evt.m_x, evt.m_y, &wnd))
{
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);
}
else
UnsetToolTip();
if (!evt.LeftIsDown() || m_clickPt == wxDefaultPosition)
return;
@ -2126,6 +2138,37 @@ wxString wxAuiNotebook::GetPageText(size_t page_idx) const
return page_info.caption;
}
bool wxAuiNotebook::SetPageToolTip(size_t page_idx, const wxString& text)
{
if (page_idx >= m_tabs.GetPageCount())
return false;
// update our own tab catalog
wxAuiNotebookPage& page_info = m_tabs.GetPage(page_idx);
page_info.tooltip = text;
wxAuiTabCtrl* ctrl;
int ctrl_idx;
if (!FindTab(page_info.window, &ctrl, &ctrl_idx))
return false;
wxAuiNotebookPage& info = ctrl->GetPage(ctrl_idx);
info.tooltip = text;
// NB: we don't update the tooltip if it is already being displayed, it
// typically never happens, no need to code that
return true;
}
wxString wxAuiNotebook::GetPageToolTip(size_t page_idx) const
{
if (page_idx >= m_tabs.GetPageCount())
return wxString();
const wxAuiNotebookPage& page_info = m_tabs.GetPage(page_idx);
return page_info.tooltip;
}
bool wxAuiNotebook::SetPageBitmap(size_t page_idx, const wxBitmap& bitmap)
{
if (page_idx >= m_tabs.GetPageCount())