]> git.saurik.com Git - wxWidgets.git/commitdiff
Applied patch [ 827011 ] Event-based processing of item tooltips in wxTreeCtrl
authorJulian Smart <julian@anthemion.co.uk>
Thu, 11 Dec 2003 07:30:20 +0000 (07:30 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Thu, 11 Dec 2003 07:30:20 +0000 (07:30 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24732 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/cmdevent.tex
docs/latex/wx/treectrl.tex
docs/latex/wx/treeevt.tex
include/wx/treebase.h
src/common/treebase.cpp
src/msw/treectrl.cpp

index dfba91d860534c1e48c247db0d920a0a1c9e18de..8951c4cb19b45e691ad2fb283849e18dcc76c597 100644 (file)
@@ -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
index c5d51fdeb0d5818517cc00390c3e28d3cbccf4fa..7f5a1b3eb739a395ed936092c17e450bbd077462 100644 (file)
@@ -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}
index d696179a2994627e833a4f00519558bcf2ce2f65..eb4aadce57d35be2e199426f272cb96ffca3bda3 100644 (file)
@@ -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.
+
index 3181b225d2ebab7c0dd667ca8f5381f24045df56..42477df701ac84eac9a78416a6692aa626863f05 100644 (file)
@@ -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_
index e611c3a134d979e0ddc032357feef56fa6478364..4c07404f5a347d408a4bd7f0a748cd008cd4a5fe 100644 (file)
@@ -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
index eb177d058ec4980d00d4c447d66ca10c3b7678fb..a7c06e728e49e0f53c774d17d0d23ad730428a7c 100644 (file)
@@ -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