Skip to content

Commit 8e3b6ba

Browse files
committed
Bug #25 fixed
1 parent b58f000 commit 8e3b6ba

File tree

4 files changed

+94
-51
lines changed

4 files changed

+94
-51
lines changed

Changelog

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
2019-02-03 Petasis George <[email protected]>
2+
* demos/dndSpy.tcl: Modified demo to also show data to be dropped
3+
during drag.
4+
25
* win/OleDND.h:
6+
* unix/TkDND_XDND.c
37
* library/tkdnd_generic.tcl:
48
* library/tkdnd_macosx.tcl:
59
* library/tkdnd_unix.tcl:
610
* library/tkdnd_windows.tcl: Provided a solution for bug #25.
7-
Under Windows, the dropped data is available for the <<DropEnter>> and
8-
<<DropPosition>> events.
11+
Under Windows and Unix, the dropped data is available for the
12+
<<DropEnter>> and <<DropPosition>> events (%D specifier).
913

1014
2018-12-23 Petasis George <[email protected]>
1115
* .travis.yml: make install & deployment to GitHub.

demos/dndSpy.tcl

+17-5
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,17 @@ if {[catch {package require tkdnd} version]} {
3232

3333
## Place a listbox. This will be our drop target, which will also display the
3434
## types supported by the drag source...
35-
pack [listbox .typeList -height 25 -width 50] -side left -padx 2 -pady 2 \
36-
-fill y -expand 0
35+
listbox .typeList -height 20 -width 50
3736
## A text widget to display the dropped data...
38-
pack [text .data -height 25 -width 80] -side left -padx 2 -pady 2 -fill both \
39-
-expand 1
37+
text .data -height 20 -width 60
4038
.data insert end $package_info
41-
pack [button .exit -text { Exit } -command exit] -side bottom -pady 5 -padx 5
39+
text .position -height 5 -width 50
40+
button .exit -text { Exit } -command exit
41+
42+
grid .typeList .data - -sticky snew -padx 2 -pady 2
43+
grid columnconfigure . 1 -weight 1
44+
grid columnconfigure . 2 -weight 1
45+
grid .position - .exit -sticky snew -padx 2 -pady 2
4246

4347
proc FillTypeListbox {listbox types type codes code actions action mods} {
4448
$listbox delete 0 end
@@ -65,6 +69,13 @@ proc FillTypeListbox {listbox types type codes code actions action mods} {
6569
$listbox insert end " * Modifiers: \"$mods\""
6670
$listbox itemconfigure end -foreground brown -background $::bg
6771
}
72+
proc FillPosition {text X Y data} {
73+
$text configure -state normal
74+
$text delete 1.0 end
75+
$text insert end "Position: (x=$X, y=$Y) Data Preview:\n"
76+
$text insert end \"$data\"
77+
$text configure -state disabled
78+
};# FillPosition
6879
proc FillData {text Data type code} {
6980
$text configure -state normal
7081
$text delete 1.0 end
@@ -102,6 +113,7 @@ set abg #8fbc8f
102113
set type *
103114
dnd bindtarget .typeList $type <DragEnter> ".typeList configure -bg $abg
104115
FillTypeListbox .typeList %t %T %c %C %a %A %m
116+
FillPosition .position %X %Y %D
105117
return \[lindex %a 0\]"
106118
dnd bindtarget .typeList $type <Drag> \
107119
[dnd bindtarget .typeList $type <DragEnter>]

library/tkdnd_unix.tcl

+26-8
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,14 @@ namespace eval xdnd {
6060
# ----------------------------------------------------------------------------
6161
# Command xdnd::HandleXdndEnter
6262
# ----------------------------------------------------------------------------
63-
proc xdnd::HandleXdndEnter { path drag_source typelist { data {} } } {
63+
proc xdnd::HandleXdndEnter { path drag_source typelist time { data {} } } {
6464
variable _pressedkeys
6565
variable _actionlist
66+
variable _typelist
6667
set _pressedkeys 1
6768
set _actionlist { copy move link ask private }
69+
set _typelist $typelist
70+
# puts "xdnd::HandleXdndEnter: $time"
6871
::tkdnd::generic::SetDroppedData $data
6972
::tkdnd::generic::HandleEnter $path $drag_source $typelist $typelist \
7073
$_actionlist $_pressedkeys
@@ -73,10 +76,16 @@ proc xdnd::HandleXdndEnter { path drag_source typelist { data {} } } {
7376
# ----------------------------------------------------------------------------
7477
# Command xdnd::HandleXdndPosition
7578
# ----------------------------------------------------------------------------
76-
proc xdnd::HandleXdndPosition { drop_target rootX rootY {drag_source {}} } {
79+
proc xdnd::HandleXdndPosition { drop_target rootX rootY time {drag_source {}} } {
7780
variable _pressedkeys
81+
variable _typelist
7882
variable _last_mouse_root_x; set _last_mouse_root_x $rootX
7983
variable _last_mouse_root_y; set _last_mouse_root_y $rootY
84+
# puts "xdnd::HandleXdndPosition: $time"
85+
## Get the dropped data...
86+
catch {
87+
::tkdnd::generic::SetDroppedData [GetPositionData $drop_target $_typelist $time]
88+
}
8089
::tkdnd::generic::HandlePosition $drop_target $drag_source \
8190
$_pressedkeys $rootX $rootY
8291
};# xdnd::HandleXdndPosition
@@ -96,18 +105,27 @@ proc xdnd::HandleXdndDrop { time } {
96105
variable _last_mouse_root_x
97106
variable _last_mouse_root_y
98107
## Get the dropped data...
99-
::tkdnd::generic::SetDroppedData [GetDroppedData $time]
108+
::tkdnd::generic::SetDroppedData [GetDroppedData \
109+
[::tkdnd::generic::GetDragSource] [::tkdnd::generic::GetDropTarget] \
110+
[::tkdnd::generic::GetDragSourceCommonTypes] $time]
100111
::tkdnd::generic::HandleDrop {} {} $_pressedkeys \
101112
$_last_mouse_root_x $_last_mouse_root_y $time
102113
};# xdnd::HandleXdndDrop
103114

104115
# ----------------------------------------------------------------------------
105-
# Command xdnd::_GetDroppedData
116+
# Command xdnd::GetPositionData
117+
# ----------------------------------------------------------------------------
118+
proc xdnd::GetPositionData { drop_target typelist time } {
119+
foreach {drop_target common_drag_source_types common_drop_target_types} \
120+
[::tkdnd::generic::FindWindowWithCommonTypes $drop_target $typelist] {break}
121+
GetDroppedData [::tkdnd::generic::GetDragSource] $drop_target \
122+
$common_drag_source_types $time
123+
};# xdnd::GetPositionData
124+
125+
# ----------------------------------------------------------------------------
126+
# Command xdnd::GetDroppedData
106127
# ----------------------------------------------------------------------------
107-
proc xdnd::GetDroppedData { time } {
108-
set _drag_source [::tkdnd::generic::GetDragSource]
109-
set _drop_target [::tkdnd::generic::GetDropTarget]
110-
set _common_drag_source_types [::tkdnd::generic::GetDragSourceCommonTypes]
128+
proc xdnd::GetDroppedData { _drag_source _drop_target _common_drag_source_types time } {
111129
if {![llength $_common_drag_source_types]} {
112130
error "no common data types between the drag source and drop target widgets"
113131
}

0 commit comments

Comments
 (0)