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
This commit is contained in:
Vadim Zeitlin
2012-09-18 22:45:15 +00:00
parent f45f43cad0
commit fcde720806
2 changed files with 24 additions and 5 deletions

View File

@@ -552,6 +552,7 @@ All (GUI):
- Add wxTextEntry::SelectNone() (troelsk). - Add wxTextEntry::SelectNone() (troelsk).
- Restore the original wxGrid col/row size when unhiding it (Michael Richards). - Restore the original wxGrid col/row size when unhiding it (Michael Richards).
- Fix text origin and extent computations in wxSVGFileDC (Neil Chittenden). - Fix text origin and extent computations in wxSVGFileDC (Neil Chittenden).
- Show tooltips for the too long items in generic wxTreeCtrl (Steven Houchins).
wxGTK: wxGTK:

View File

@@ -3534,9 +3534,14 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event )
wxTreeEvent wxTreeEvent
hevent(wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP, this, hoverItem); hevent(wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP, this, hoverItem);
if ( GetEventHandler()->ProcessEvent(hevent) && hevent.IsAllowed() ) if ( GetEventHandler()->ProcessEvent(hevent) )
{ {
// If the user permitted the tooltip change, update it, otherwise
// remove any old tooltip we might have.
if ( hevent.IsAllowed() )
SetToolTip(hevent.m_label); SetToolTip(hevent.m_label);
else
SetToolTip(NULL);
} }
} }
#endif #endif
@@ -4004,12 +4009,25 @@ bool wxGenericTreeCtrl::SetForegroundColour(const wxColour& colour)
return true; return true;
} }
// Process the tooltip event, to speed up event processing.
// Doesn't actually get a tooltip.
void wxGenericTreeCtrl::OnGetToolTip( wxTreeEvent &event ) void wxGenericTreeCtrl::OnGetToolTip( wxTreeEvent &event )
{ {
#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(); event.Veto();
} }
}
// NOTE: If using the wxListBox visual attributes works everywhere then this can // NOTE: If using the wxListBox visual attributes works everywhere then this can