| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| namespace eval generic { |
| variable _types {} |
| variable _typelist {} |
| variable _codelist {} |
| variable _actionlist {} |
| variable _pressedkeys {} |
| variable _action {} |
| variable _common_drag_source_types {} |
| variable _common_drop_target_types {} |
| variable _drag_source {} |
| variable _drop_target {} |
|
|
| variable _last_mouse_root_x 0 |
| variable _last_mouse_root_y 0 |
|
|
| variable _tkdnd2platform |
| variable _platform2tkdnd |
|
|
| proc debug {msg} { |
| puts $msg |
| } |
|
|
| proc initialise { } { |
| } |
|
|
| proc initialise_platform_to_tkdnd_types { types } { |
| variable _platform2tkdnd |
| variable _tkdnd2platform |
| set _platform2tkdnd [dict create {*}$types] |
| set _tkdnd2platform [dict create] |
| foreach type [dict keys $_platform2tkdnd] { |
| dict lappend _tkdnd2platform [dict get $_platform2tkdnd $type] $type |
| } |
| } |
|
|
| proc initialise_tkdnd_to_platform_types { types } { |
| variable _tkdnd2platform |
| set _tkdnd2platform [dict create {*}$types] |
| } |
|
|
| } |
|
|
| |
| |
| |
| proc generic::HandleEnter { drop_target drag_source typelist codelist |
| actionlist pressedkeys } { |
| variable _typelist; set _typelist $typelist |
| variable _pressedkeys; set _pressedkeys $pressedkeys |
| variable _action; set _action refuse_drop |
| variable _common_drag_source_types; set _common_drag_source_types {} |
| variable _common_drop_target_types; set _common_drop_target_types {} |
| variable _actionlist |
| variable _drag_source; set _drag_source $drag_source |
| variable _drop_target; set _drop_target {} |
| variable _actionlist; set _actionlist $actionlist |
| variable _codelist set _codelist $codelist |
|
|
| variable _last_mouse_root_x; set _last_mouse_root_x 0 |
| variable _last_mouse_root_y; set _last_mouse_root_y 0 |
| |
| |
| |
| |
| |
| return default |
| } |
|
|
| |
| |
| |
| proc generic::HandlePosition { drop_target drag_source pressedkeys |
| rootX rootY { time 0 } } { |
| variable _types |
| variable _typelist |
| variable _codelist |
| variable _actionlist |
| variable _pressedkeys |
| variable _action |
| variable _common_drag_source_types |
| variable _common_drop_target_types |
| variable _drag_source |
| variable _drop_target |
|
|
| variable _last_mouse_root_x; set _last_mouse_root_x $rootX |
| variable _last_mouse_root_y; set _last_mouse_root_y $rootY |
|
|
| |
| |
|
|
| if {![info exists _drag_source] && ![string length $_drag_source]} { |
| |
| |
| return refuse_drop |
| } |
|
|
| if {$drag_source ne "" && $drag_source ne $_drag_source} { |
| debug "generic position event from unexpected source: $_drag_source\ |
| != $drag_source" |
| return refuse_drop |
| } |
|
|
| set _pressedkeys $pressedkeys |
|
|
| |
| |
| |
| foreach {drop_target common_drag_source_types common_drop_target_types} \ |
| [FindWindowWithCommonTypes $drop_target $_typelist] {break} |
| set data [GetDroppedData $time] |
|
|
| |
| if {$drop_target != $_drop_target} { |
| if {[string length $_drop_target]} { |
| |
| |
| set cmd [bind $_drop_target <<DropLeave>>] |
| if {[string length $cmd]} { |
| set cmd [string map [list %W $_drop_target %X $rootX %Y $rootY \ |
| %CST \{$_common_drag_source_types\} \ |
| %CTT \{$_common_drop_target_types\} \ |
| %CPT \{[lindex [platform_independent_type [lindex $_common_drag_source_types 0]] 0]\} \ |
| %ST \{$_typelist\} %TT \{$_types\} \ |
| %A \{$_action\} %a \{$_actionlist\} \ |
| %b \{$_pressedkeys\} %m \{$_pressedkeys\} \ |
| %D \{\} %e <<DropLeave>> \ |
| %L \{$_typelist\} %% % \ |
| %t \{$_typelist\} %T \{[lindex $_common_drag_source_types 0]\} \ |
| %c \{$_codelist\} %C \{[lindex $_codelist 0]\} \ |
| ] $cmd] |
| uplevel \#0 $cmd |
| } |
| } |
| set _drop_target $drop_target |
| set _action refuse_drop |
|
|
| if {[llength $common_drag_source_types]} { |
| set _action [lindex $_actionlist 0] |
| set _common_drag_source_types $common_drag_source_types |
| set _common_drop_target_types $common_drop_target_types |
| |
| |
| 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 \ |
| %CST \{$_common_drag_source_types\} \ |
| %CTT \{$_common_drop_target_types\} \ |
| %CPT \{[lindex [platform_independent_type [lindex $_common_drag_source_types 0]] 0]\} \ |
| %ST \{$_typelist\} %TT \{$_types\} \ |
| %A $_action %a \{$_actionlist\} \ |
| %b \{$_pressedkeys\} %m \{$_pressedkeys\} \ |
| %D [list $data] %e <<DropEnter>> \ |
| %L \{$_typelist\} %% % \ |
| %t \{$_typelist\} %T \{[lindex $_common_drag_source_types 0]\} \ |
| %c \{$_codelist\} %C \{[lindex $_codelist 0]\} \ |
| ] $cmd] |
| set _action [uplevel \#0 $cmd] |
| switch -exact -- $_action { |
| copy - move - link - ask - private - refuse_drop - default {} |
| default {set _action copy} |
| } |
| } |
| } |
| } |
|
|
| set _drop_target {} |
| if {[llength $common_drag_source_types]} { |
| set _common_drag_source_types $common_drag_source_types |
| set _common_drop_target_types $common_drop_target_types |
| set _drop_target $drop_target |
| |
| set cmd [bind $drop_target <<DropPosition>>] |
| if {[string length $cmd]} { |
| set cmd [string map [list %W $drop_target %X $rootX %Y $rootY \ |
| %CST \{$_common_drag_source_types\} \ |
| %CTT \{$_common_drop_target_types\} \ |
| %CPT \{[lindex [platform_independent_type [lindex $_common_drag_source_types 0]] 0]\} \ |
| %ST \{$_typelist\} %TT \{$_types\} \ |
| %A $_action %a \{$_actionlist\} \ |
| %b \{$_pressedkeys\} %m \{$_pressedkeys\} \ |
| %D [list $data] %e <<DropPosition>> \ |
| %L \{$_typelist\} %% % \ |
| %t \{$_typelist\} %T \{[lindex $_common_drag_source_types 0]\} \ |
| %c \{$_codelist\} %C \{[lindex $_codelist 0]\} \ |
| ] $cmd] |
| set _action [uplevel \#0 $cmd] |
| } |
| } |
| |
| |
| switch -exact -- $_action { |
| copy - move - link - ask - private - refuse_drop - default {} |
| default {set _action copy} |
| } |
| return $_action |
| } |
|
|
| |
| |
| |
| proc generic::HandleLeave { } { |
| variable _types |
| variable _typelist |
| variable _codelist |
| variable _actionlist |
| variable _pressedkeys |
| variable _action |
| variable _common_drag_source_types |
| variable _common_drop_target_types |
| variable _drag_source |
| variable _drop_target |
| variable _last_mouse_root_x |
| variable _last_mouse_root_y |
| if {![info exists _drop_target]} {set _drop_target {}} |
| |
| 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 \ |
| %X $_last_mouse_root_x %Y $_last_mouse_root_y \ |
| %CST \{$_common_drag_source_types\} \ |
| %CTT \{$_common_drop_target_types\} \ |
| %CPT \{[lindex [platform_independent_type [lindex $_common_drag_source_types 0]] 0]\} \ |
| %ST \{$_typelist\} %TT \{$_types\} \ |
| %A \{$_action\} %a \{$_actionlist\} \ |
| %b \{$_pressedkeys\} %m \{$_pressedkeys\} \ |
| %D \{\} %e <<DropLeave>> \ |
| %L \{$_typelist\} %% % \ |
| %t \{$_typelist\} %T \{[lindex $_common_drag_source_types 0]\} \ |
| %c \{$_codelist\} %C \{[lindex $_codelist 0]\} \ |
| ] $cmd] |
| set _action [uplevel \#0 $cmd] |
| } |
| } |
| foreach var {_types _typelist _actionlist _pressedkeys _action |
| _common_drag_source_types _common_drop_target_types |
| _drag_source _drop_target} { |
| set $var {} |
| } |
| } |
|
|
| |
| |
| |
| proc generic::HandleDrop {drop_target drag_source pressedkeys rootX rootY time } { |
| variable _types |
| variable _typelist |
| variable _codelist |
| variable _actionlist |
| variable _pressedkeys |
| variable _action |
| variable _common_drag_source_types |
| variable _common_drop_target_types |
| variable _drag_source |
| variable _drop_target |
| variable _last_mouse_root_x |
| variable _last_mouse_root_y |
| variable _last_mouse_root_x; set _last_mouse_root_x $rootX |
| variable _last_mouse_root_y; set _last_mouse_root_y $rootY |
|
|
| set _pressedkeys $pressedkeys |
|
|
| |
|
|
| if {![info exists _drag_source] && ![string length $_drag_source]} { |
| return refuse_drop |
| } |
| if {![info exists _drop_target] && ![string length $_drop_target]} { |
| return refuse_drop |
| } |
| if {![llength $_common_drag_source_types]} {return refuse_drop} |
| |
| set data [GetDroppedData $time] |
| |
| 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 \ |
| %CST \{$_common_drag_source_types\} \ |
| %CTT \{$_common_drop_target_types\} \ |
| %CPT \{[lindex [platform_independent_type [lindex $_common_drag_source_types 0]] 0]\} \ |
| %ST \{$_typelist\} %TT \{$_types\} \ |
| %A $_action %a \{$_actionlist\} \ |
| %b \{$_pressedkeys\} %m \{$_pressedkeys\} \ |
| %D [list $data] %e <<Drop:$type>> \ |
| %L \{$_typelist\} %% % \ |
| %t \{$_typelist\} %T \{[lindex $_common_drag_source_types 0]\} \ |
| %c \{$_codelist\} %C \{[lindex $_codelist 0]\} \ |
| ] $cmd] |
| set _action [uplevel \#0 $cmd] |
| |
| switch -exact -- $_action { |
| copy - move - link - ask - private - refuse_drop - default {} |
| default {set _action copy} |
| } |
| return $_action |
| } |
| } |
| set cmd [bind $_drop_target <<Drop>>] |
| if {[string length $cmd]} { |
| set cmd [string map [list %W $_drop_target %X $rootX %Y $rootY \ |
| %CST \{$_common_drag_source_types\} \ |
| %CTT \{$_common_drop_target_types\} \ |
| %CPT \{[lindex [platform_independent_type [lindex $_common_drag_source_types 0]] 0]\} \ |
| %ST \{$_typelist\} %TT \{$_types\} \ |
| %A $_action %a \{$_actionlist\} \ |
| %b \{$_pressedkeys\} %m \{$_pressedkeys\} \ |
| %D [list $data] %e <<Drop>> \ |
| %L \{$_typelist\} %% % \ |
| %t \{$_typelist\} %T \{[lindex $_common_drag_source_types 0]\} \ |
| %c \{$_codelist\} %C \{[lindex $_codelist 0]\} \ |
| ] $cmd] |
| set _action [uplevel \#0 $cmd] |
| } |
| |
| switch -exact -- $_action { |
| copy - move - link - ask - private - refuse_drop - default {} |
| default {set _action copy} |
| } |
| return $_action |
| } |
|
|
| |
| |
| |
| proc generic::GetWindowCommonTypes { win typelist } { |
| set types [bind $win <<DropTargetTypes>>] |
| |
| set common_drag_source_types {} |
| set common_drop_target_types {} |
| if {[llength $types]} { |
| |
| |
| set supported_types [supported_types $typelist] |
| foreach type $types { |
| foreach matched [lsearch -glob -all -inline $supported_types $type] { |
| |
| lappend common_drag_source_types $matched |
| lappend common_drop_target_types $type |
| } |
| } |
| } |
| list $common_drag_source_types $common_drop_target_types |
| } |
|
|
| |
| |
| |
| proc generic::FindWindowWithCommonTypes { win typelist } { |
| set toplevel [winfo toplevel $win] |
| while {![string equal $win $toplevel]} { |
| foreach {common_drag_source_types common_drop_target_types} \ |
| [GetWindowCommonTypes $win $typelist] {break} |
| if {[llength $common_drag_source_types]} { |
| return [list $win $common_drag_source_types $common_drop_target_types] |
| } |
| set win [winfo parent $win] |
| } |
| |
| foreach {common_drag_source_types common_drop_target_types} \ |
| [GetWindowCommonTypes $win $typelist] {break} |
| if {[llength $common_drag_source_types]} { |
| return [list $win $common_drag_source_types $common_drop_target_types] |
| } |
| return { {} {} {} } |
| } |
|
|
| |
| |
| |
| proc generic::GetDroppedData { time } { |
| variable _dropped_data |
| return $_dropped_data |
| } |
|
|
| |
| |
| |
| proc generic::SetDroppedData { data } { |
| variable _dropped_data |
| set _dropped_data $data |
| } |
|
|
| |
| |
| |
| proc generic::GetDragSource { } { |
| variable _drag_source |
| return $_drag_source |
| } |
|
|
| |
| |
| |
| proc generic::GetDropTarget { } { |
| variable _drop_target |
| return $_drop_target |
| } |
|
|
| |
| |
| |
| proc generic::GetDragSourceCommonTypes { } { |
| variable _common_drag_source_types |
| return $_common_drag_source_types |
| } |
|
|
| |
| |
| |
| proc generic::GetDropTargetCommonTypes { } { |
| variable _common_drag_source_types |
| return $_common_drag_source_types |
| } |
|
|
| |
| |
| |
| proc generic::platform_specific_types { types } { |
| set new_types {} |
| foreach type $types { |
| set new_types [concat $new_types [platform_specific_type $type]] |
| } |
| return $new_types |
| } |
|
|
| |
| |
| |
| proc generic::platform_specific_type { type } { |
| variable _tkdnd2platform |
| if {[dict exists $_tkdnd2platform $type]} { |
| return [dict get $_tkdnd2platform $type] |
| } |
| list $type |
| } |
|
|
| |
| |
| |
| proc ::tkdnd::platform_independent_types { types } { |
| set new_types {} |
| foreach type $types { |
| set new_types [concat $new_types [platform_independent_type $type]] |
| } |
| return $new_types |
| } |
|
|
| |
| |
| |
| proc generic::platform_independent_type { type } { |
| variable _platform2tkdnd |
| if {[dict exists $_platform2tkdnd $type]} { |
| return [dict get $_platform2tkdnd $type] |
| } |
| return $type |
| } |
|
|
| |
| |
| |
| proc generic::supported_types { types } { |
| set new_types {} |
| foreach type $types { |
| if {[supported_type $type]} {lappend new_types $type} |
| } |
| return $new_types |
| } |
|
|
| |
| |
| |
| proc generic::supported_type { type } { |
| variable _platform2tkdnd |
| if {[dict exists $_platform2tkdnd $type]} { |
| return 1 |
| } |
| return 0 |
| } |
|
|