Tk Library Source Code

Artifact [78b351b3ec]
Login

Artifact 78b351b3ec21b780642323daf43d53d8fe7b6ebe:

Attachment "tooltip.treeview.patch" to ticket [2895994fff] added by keithv 2009-11-11 22:19:17.
--- tooltip-1.4.4.tm	2009-01-01 14:23:55.373250000 -0500
+++ tooltip-1.4.4a.tm	2009-11-11 10:08:44.609375000 -0500
@@ -225,7 +225,7 @@
 		set args [lreplace $args 0 1]
 	    }
 	    -item - -items {
-                if {[winfo class $w] eq "Listbox"} {
+                if {[winfo class $w] eq "Listbox" || [winfo class $w] eq "Treeview"} {
                     set items [lindex $args 1]
                 } else {
                     set namedItem [lindex $args 1]
@@ -270,6 +270,8 @@
 		set tooltip($w,$item) $key
 		if {[winfo class $w] eq "Listbox"} {
 		    enableListbox $w $item
+		} elseif {[winfo class $w] eq "Treeview"} {
+		    enableTreeview $w $item
 		} else {
 		    enableCanvas $w $item
 		}
@@ -519,4 +521,43 @@
     $w tag bind $tag <Any-Button> +[namespace code hide]
 }
 
+proc ::tooltip::treeviewTip {w x y} {
+    variable tooltip
+    variable G
+
+    set G(LAST) -1
+    set item [$w identify row $x $y]
+    if {$G(enabled) && [info exists tooltip($w,$item)]} {
+	set G(AFTERID) [after $G(DELAY) \
+		[namespace code [list show $w $tooltip($w,$item) cursor]]]
+    }
+}
+
+# Handle the lack of <Enter>/<Leave> between treeview rows using <Motion>
+proc ::tooltip::treeviewMotion {w x y} {
+    variable tooltip
+    variable G
+    if {$G(enabled)} {
+	set item [$w identify row $x $y]
+        if {$item ne $G(LAST)} {
+            set G(LAST) $item
+            after cancel $G(AFTERID)
+            catch {wm withdraw $G(TOPLEVEL)}
+            if {[info exists tooltip($w,$item)]} {
+                set G(AFTERID) [after $G(DELAY) \
+                   [namespace code [list show $w $tooltip($w,$item) cursor]]]
+            }
+        }
+    }
+}
+# Initialize tooltip events for Treeview widgets
+proc ::tooltip::enableTreeview {w args} {
+    if {[string match *treeviewTip* [bind $w <Enter>]]} { return }
+    bind $w <Enter> +[namespace code [list treeviewTip %W %x %y]]
+    bind $w <Motion> +[namespace code [list treeviewMotion %W %x %y]]
+    bind $w <Leave> +[namespace code [list hide 1]] ; # fade ok
+    bind $w <Any-KeyPress> +[namespace code hide]
+    bind $w <Any-Button> +[namespace code hide]
+}
+
 package provide tooltip 1.4.4