From: Julian Smart Date: Thu, 11 Dec 2003 07:30:20 +0000 (+0000) Subject: Applied patch [ 827011 ] Event-based processing of item tooltips in wxTreeCtrl X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/156194e1d525407e90c21552f8f7aa05756e0ddc Applied patch [ 827011 ] Event-based processing of item tooltips in wxTreeCtrl git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24732 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/latex/wx/cmdevent.tex b/docs/latex/wx/cmdevent.tex index dfba91d860..8951c4cb19 100644 --- a/docs/latex/wx/cmdevent.tex +++ b/docs/latex/wx/cmdevent.tex @@ -64,7 +64,7 @@ which is generated by a wxComboBox control.} \twocolitem{{\bf EVT\_TOOL(id, func)}}{Process a wxEVT\_COMMAND\_TOOL\_CLICKED event (a synonym for wxEVT\_COMMAND\_MENU\_SELECTED). Pass the id of the tool.} \twocolitem{{\bf EVT\_TOOL\_RANGE(id1, id2, func)}}{Process a wxEVT\_COMMAND\_TOOL\_CLICKED event -for a range id identifiers. Pass the ids of the tools.} +for a range of identifiers. Pass the ids of the tools.} \twocolitem{{\bf EVT\_TOOL\_RCLICKED(id, func)}}{Process a wxEVT\_COMMAND\_TOOL\_RCLICKED event. Pass the id of the tool.} \twocolitem{{\bf EVT\_TOOL\_RCLICKED\_RANGE(id1, id2, func)}}{Process a wxEVT\_COMMAND\_TOOL\_RCLICKED event diff --git a/docs/latex/wx/treectrl.tex b/docs/latex/wx/treectrl.tex index c5d51fdeb0..7f5a1b3eb7 100644 --- a/docs/latex/wx/treectrl.tex +++ b/docs/latex/wx/treectrl.tex @@ -88,6 +88,8 @@ functions that take a \helpref{wxTreeEvent}{wxtreeevent} argument. \twocolitem{{\bf EVT\_TREE\_SEL\_CHANGED(id, func)}}{Selection has changed.} \twocolitem{{\bf EVT\_TREE\_SEL\_CHANGING(id, func)}}{Selection is changing. This can be prevented by calling \helpref{Veto()}{wxnotifyeventveto}.} \twocolitem{{\bf EVT\_TREE\_KEY\_DOWN(id, func)}}{A key has been pressed.} +\twocolitem{{\bf EVT\_TREE\_ITEM\_GETTOOLTIP(id, func)}}{The opportunity to set the item tooltip +is being given to the application (call wxTreeEvent::SetToolTip). Windows only.} \end{twocollist} \wxheading{See also} diff --git a/docs/latex/wx/treeevt.tex b/docs/latex/wx/treeevt.tex index d696179a29..eb4aadce57 100644 --- a/docs/latex/wx/treeevt.tex +++ b/docs/latex/wx/treeevt.tex @@ -39,6 +39,9 @@ functions that take a wxTreeEvent argument. \twocolitem{{\bf EVT\_TREE\_KEY\_DOWN(id, func)}}{A key has been pressed.} \twocolitem{{\bf EVT\_TREE\_SEL\_CHANGED(id, func)}}{Selection has changed.} \twocolitem{{\bf EVT\_TREE\_SEL\_CHANGING(id, func)}}{Selection is changing. This can be prevented by calling \helpref{Veto()}{wxnotifyeventveto}.} +\twocolitem{{\bf EVT\_TREE\_KEY\_DOWN(id, func)}}{A key has been pressed.} +\twocolitem{{\bf EVT\_TREE\_ITEM\_GETTOOLTIP(id, func)}}{The opportunity to set the item tooltip +is being given to the application (call wxTreeEvent::SetToolTip). Windows only.} \end{twocollist}% \wxheading{See also} @@ -98,3 +101,10 @@ Returns the position of the mouse pointer if the event is a drag event. Returns true if the label edit was cancelled. This should be called from within an EVT\_TREE\_END\_LABEL\_EDIT handler. +\membersection{wxTreeEvent::SetToolTip} + +\func{void}{SetToolTip}{\param{const wxString\&}{ tooltip}} + +Set the tooltip for the item (valid for EVT\_TREE\_ITEM\_GETTOOLTIP events). +Windows only. + diff --git a/include/wx/treebase.h b/include/wx/treebase.h index 3181b225d2..42477df701 100644 --- a/include/wx/treebase.h +++ b/include/wx/treebase.h @@ -274,6 +274,9 @@ public: bool IsEditCancelled() const { return m_editCancelled; } void SetEditCanceled(bool editCancelled) { m_editCancelled = editCancelled; } + // Set the tooltip for the item (for EVT\_TREE\_ITEM\_GETTOOLTIP events) + void SetToolTip(const wxString& toolTip) { m_label = toolTip; } + #if WXWIN_COMPATIBILITY_2_2 // for compatibility only, don't use int GetCode() const { return m_evtKey.GetKeyCode(); } @@ -320,6 +323,7 @@ BEGIN_DECLARE_EVENT_TYPES() DECLARE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, 616) DECLARE_EVENT_TYPE(wxEVT_COMMAND_TREE_END_DRAG, 617) DECLARE_EVENT_TYPE(wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK, 618) + DECLARE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP, 619) END_DECLARE_EVENT_TYPES() // GetItem() returns the item being dragged, GetPoint() the mouse coords @@ -375,6 +379,9 @@ END_DECLARE_EVENT_TYPES() // GetItem() returns the item whose state image was clicked on #define EVT_TREE_STATE_IMAGE_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL ), +// GetItem() is the item for which the tooltip is being requested +#define EVT_TREE_ITEM_GETTOOLTIP(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL ), + #endif // wxUSE_TREECTRL #endif // _WX_TREEBASE_H_ diff --git a/src/common/treebase.cpp b/src/common/treebase.cpp index e611c3a134..4c07404f5a 100644 --- a/src/common/treebase.cpp +++ b/src/common/treebase.cpp @@ -62,6 +62,7 @@ DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK) DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK) DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_END_DRAG) DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK) +DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP) // ---------------------------------------------------------------------------- // Tree event diff --git a/src/msw/treectrl.cpp b/src/msw/treectrl.cpp index eb177d058e..a7c06e728e 100644 --- a/src/msw/treectrl.cpp +++ b/src/msw/treectrl.cpp @@ -674,6 +674,9 @@ bool wxTreeCtrl::Create(wxWindow *parent, wstyle |= TVS_CHECKBOXES; #endif // wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE + // Need so that TVN_GETINFOTIP messages will be sent + wstyle |= TVS_INFOTIP; + // Create the tree control. if ( !MSWCreateControl(WC_TREEVIEW, wstyle) ) return false; @@ -2459,6 +2462,29 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) break; } + + // These *must* not be removed or TVN_GETINFOTIP will + // not be processed each time the mouse is moved + // and the tooltip will only ever update once. + case TTN_NEEDTEXTA: + case TTN_NEEDTEXTW: + { + *result = 0; + + break; + } + + case TVN_GETINFOTIP: + { + eventType = wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP; + NMTVGETINFOTIP *info = (NMTVGETINFOTIP*)lParam; + + // Which item are we trying to get a tooltip for? + event.m_item = (WXHTREEITEM) info->hItem; + + break; + } + case TVN_GETDISPINFO: eventType = wxEVT_COMMAND_TREE_GET_INFO; // fall through @@ -2805,6 +2831,16 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) DeleteTextCtrl(); break; + case TVN_GETINFOTIP: + { + // If the user permitted a tooltip change, change it + if (event.IsAllowed()) + { + SetToolTip(event.m_label); + } + } + break; + case TVN_SELCHANGING: case TVN_ITEMEXPANDING: // return true to prevent the action from happening