From: Vadim Zeitlin Date: Tue, 18 Sep 2012 22:45:15 +0000 (+0000) Subject: Show tooltips for the too long items in generic wxTreeCtrl. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/fcde7208062ce955a124c1e1d074720bf646dff6 Show tooltips for the too long items in generic wxTreeCtrl. Show the full item text in a tooltip if the entire text can't be shown on screen. Closes #14667. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72505 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index 20aa862f3c..c848a76727 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -552,6 +552,7 @@ All (GUI): - Add wxTextEntry::SelectNone() (troelsk). - Restore the original wxGrid col/row size when unhiding it (Michael Richards). - Fix text origin and extent computations in wxSVGFileDC (Neil Chittenden). +- Show tooltips for the too long items in generic wxTreeCtrl (Steven Houchins). wxGTK: diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index b11fd4b449..51347f51e5 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -3534,9 +3534,14 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event ) wxTreeEvent hevent(wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP, this, hoverItem); - if ( GetEventHandler()->ProcessEvent(hevent) && hevent.IsAllowed() ) + if ( GetEventHandler()->ProcessEvent(hevent) ) { - SetToolTip(hevent.m_label); + // If the user permitted the tooltip change, update it, otherwise + // remove any old tooltip we might have. + if ( hevent.IsAllowed() ) + SetToolTip(hevent.m_label); + else + SetToolTip(NULL); } } #endif @@ -4004,11 +4009,24 @@ bool wxGenericTreeCtrl::SetForegroundColour(const wxColour& colour) return true; } -// Process the tooltip event, to speed up event processing. -// Doesn't actually get a tooltip. void wxGenericTreeCtrl::OnGetToolTip( wxTreeEvent &event ) { - event.Veto(); +#if wxUSE_TOOLTIPS + wxTreeItemId itemId = event.GetItem(); + const wxGenericTreeItem* const pItem = (wxGenericTreeItem*)itemId.m_pItem; + + // Check if the item fits into the client area: + if ( pItem->GetX() + pItem->GetWidth() > GetClientSize().x ) + { + // If it doesn't, show its full text in the tooltip. + event.SetLabel(pItem->GetText()); + } + else +#endif // wxUSE_TOOLTIPS + { + // veto processing the event, nixing any tooltip + event.Veto(); + } }