diff --git a/docs/changes.txt b/docs/changes.txt index ddfc91898c..a145245ed7 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -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(). diff --git a/include/wx/aui/auibook.h b/include/wx/aui/auibook.h index edec2ce078..36536e0b87 100644 --- a/include/wx/aui/auibook.h +++ b/include/wx/aui/auibook.h @@ -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; diff --git a/interface/wx/aui/auibook.h b/interface/wx/aui/auibook.h index 9f58a60a0b..b95461b9ae 100644 --- a/interface/wx/aui/auibook.h +++ b/interface/wx/aui/auibook.h @@ -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. */ diff --git a/samples/aui/auidemo.cpp b/samples/aui/auidemo.cpp index 08d5d136d9..9654e9ae49 100644 --- a/samples/aui/auidemo.cpp +++ b/samples/aui/auidemo.cpp @@ -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") ); diff --git a/src/aui/auibook.cpp b/src/aui/auibook.cpp index f9ab942b9a..6471c076c4 100644 --- a/src/aui/auibook.cpp +++ b/src/aui/auibook.cpp @@ -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())