petasis / tkdnd

TkDND is an extension that adds native drag & drop capabilities to the Tk toolkit

Home Page:https://sourceforge.net/projects/tkdnd/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

document the %x and %y replacements, and the meaning of the returned actions

ralfixx opened this issue · comments

The documentation doc only documents %X and %Y replacements, but there are also %x and %y which eg. in a canvas make more sense.

These should be documented.

The Makefile mentions a tkdnd.xml, so before wasting time sending patches for tkdnd.htm: is there a "master"-document (there isn't one in "git clone" or the created .zip)?

In addition, it would be nice if the <<DropPosition>> and <<Drop>> bindings could also use %x and %y
(Note that this patch includes the diff from #33 (%W replacement).):

--- tkdnd-master/library/tkdnd_generic.tcl.orig	2019-04-16 21:11:59.000000000 +0200
+++ tkdnd-master/library/tkdnd_generic.tcl	2019-06-06 17:29:35.719940312 +0200
@@ -154,7 +154,9 @@
       # debug "\t<<DropLeave>> on $_drop_target"
       set cmd [bind $_drop_target <<DropLeave>>]
       if {[string length $cmd]} {
-        set cmd [string map [list %W $_drop_target %X $rootX %Y $rootY \
+        set x [expr {$rootX-[winfo rootx $_drop_target]}]
+        set y [expr {$rootY-[winfo rooty $_drop_target]}]
+        set cmd [string map [list %W [list $_drop_target] %X $rootX %Y $rootY %x $x %y $y \
           %CST \{$_common_drag_source_types\} \
           %CTT \{$_common_drop_target_types\} \
           %CPT \{[lindex [platform_independent_type [lindex $_common_drag_source_types 0]] 0]\} \
@@ -181,7 +183,9 @@
       set cmd [bind $drop_target <<DropEnter>>]
       if {[string length $cmd]} {
         focus $drop_target
-        set cmd [string map [list %W $drop_target %X $rootX %Y $rootY \
+        set x [expr {$rootX-[winfo rootx $drop_target]}]
+        set y [expr {$rootY-[winfo rooty $drop_target]}]
+        set cmd [string map [list %W [list $drop_target] %X $rootX %Y $rootY %x $x %y $y \
           %CST \{$_common_drag_source_types\} \
           %CTT \{$_common_drop_target_types\} \
           %CPT \{[lindex [platform_independent_type [lindex $_common_drag_source_types 0]] 0]\} \
@@ -210,7 +214,9 @@
     ## Drop target supports at least one type. Send a <<DropPosition>>.
     set cmd [bind $drop_target <<DropPosition>>]
     if {[string length $cmd]} {
-      set cmd [string map [list %W $drop_target %X $rootX %Y $rootY \
+      set x [expr {$rootX-[winfo rootx $drop_target]}]
+      set y [expr {$rootY-[winfo rooty $drop_target]}]
+      set cmd [string map [list %W [list $drop_target] %X $rootX %Y $rootY %x $x %y $y \
         %CST \{$_common_drag_source_types\} \
         %CTT \{$_common_drop_target_types\} \
         %CPT \{[lindex [platform_independent_type [lindex $_common_drag_source_types 0]] 0]\} \
@@ -255,7 +261,7 @@
   if {[info exists _drop_target] && [string length $_drop_target]} {
     set cmd [bind $_drop_target <<DropLeave>>]
     if {[string length $cmd]} {
-      set cmd [string map [list %W $_drop_target \
+      set cmd [string map [list %W [list $_drop_target] \
         %X $_last_mouse_root_x %Y $_last_mouse_root_y \
         %CST \{$_common_drag_source_types\} \
         %CTT \{$_common_drop_target_types\} \
@@ -310,12 +316,15 @@
   if {![llength $_common_drag_source_types]} {return refuse_drop}
   ## Get the dropped data.
   set data [GetDroppedData $time]
+  set x [expr {$rootX-[winfo rootx $_drop_target]}]
+  set y [expr {$rootY-[winfo rooty $_drop_target]}]    
+
   ## Try to select the most specific <<Drop>> event.
   foreach type [concat $_common_drag_source_types $_common_drop_target_types] {
     set type [platform_independent_type $type]
     set cmd [bind $_drop_target <<Drop:$type>>]
     if {[string length $cmd]} {
-      set cmd [string map [list %W $_drop_target %X $rootX %Y $rootY \
+      set cmd [string map [list %W [list $_drop_target] %X $rootX %Y $rootY %x $x %y $y \
         %CST \{$_common_drag_source_types\} \
         %CTT \{$_common_drop_target_types\} \
         %CPT \{[lindex [platform_independent_type [lindex $_common_drag_source_types 0]] 0]\} \
@@ -338,7 +347,7 @@
   }
   set cmd [bind $_drop_target <<Drop>>]
   if {[string length $cmd]} {
-    set cmd [string map [list %W $_drop_target %X $rootX %Y $rootY \
+    set cmd [string map [list %W [list $_drop_target] %X $rootX %Y $rootY %x $x %y $y \
       %CST \{$_common_drag_source_types\} \
       %CTT \{$_common_drop_target_types\} \
       %CPT \{[lindex [platform_independent_type [lindex $_common_drag_source_types 0]] 0]\} \

Diff finished.  Thu Jun  6 17:29:42 2019

The "master" document is doc/tkDND.n (the unix man page). The html file is generated from the .n file.

Committed.