Skip to content

Commit

Permalink
Bug #25 fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
petasis committed Feb 3, 2019
1 parent b58f000 commit 8e3b6ba
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 51 deletions.
8 changes: 6 additions & 2 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
2019-02-03 Petasis George <petasis@iit.demokritos.gr>
* demos/dndSpy.tcl: Modified demo to also show data to be dropped
during drag.

* win/OleDND.h:
* unix/TkDND_XDND.c
* library/tkdnd_generic.tcl:
* library/tkdnd_macosx.tcl:
* library/tkdnd_unix.tcl:
* library/tkdnd_windows.tcl: Provided a solution for bug #25.
Under Windows, the dropped data is available for the <<DropEnter>> and
<<DropPosition>> events.
Under Windows and Unix, the dropped data is available for the
<<DropEnter>> and <<DropPosition>> events (%D specifier).

2018-12-23 Petasis George <petasis@iit.demokritos.gr>
* .travis.yml: make install & deployment to GitHub.
Expand Down
22 changes: 17 additions & 5 deletions demos/dndSpy.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ if {[catch {package require tkdnd} version]} {

## Place a listbox. This will be our drop target, which will also display the
## types supported by the drag source...
pack [listbox .typeList -height 25 -width 50] -side left -padx 2 -pady 2 \
-fill y -expand 0
listbox .typeList -height 20 -width 50
## A text widget to display the dropped data...
pack [text .data -height 25 -width 80] -side left -padx 2 -pady 2 -fill both \
-expand 1
text .data -height 20 -width 60
.data insert end $package_info
pack [button .exit -text { Exit } -command exit] -side bottom -pady 5 -padx 5
text .position -height 5 -width 50
button .exit -text { Exit } -command exit

grid .typeList .data - -sticky snew -padx 2 -pady 2
grid columnconfigure . 1 -weight 1
grid columnconfigure . 2 -weight 1
grid .position - .exit -sticky snew -padx 2 -pady 2

proc FillTypeListbox {listbox types type codes code actions action mods} {
$listbox delete 0 end
Expand All @@ -65,6 +69,13 @@ proc FillTypeListbox {listbox types type codes code actions action mods} {
$listbox insert end " * Modifiers: \"$mods\""
$listbox itemconfigure end -foreground brown -background $::bg
}
proc FillPosition {text X Y data} {
$text configure -state normal
$text delete 1.0 end
$text insert end "Position: (x=$X, y=$Y) Data Preview:\n"
$text insert end \"$data\"
$text configure -state disabled
};# FillPosition
proc FillData {text Data type code} {
$text configure -state normal
$text delete 1.0 end
Expand Down Expand Up @@ -102,6 +113,7 @@ set abg #8fbc8f
set type *
dnd bindtarget .typeList $type <DragEnter> ".typeList configure -bg $abg
FillTypeListbox .typeList %t %T %c %C %a %A %m
FillPosition .position %X %Y %D
return \[lindex %a 0\]"
dnd bindtarget .typeList $type <Drag> \
[dnd bindtarget .typeList $type <DragEnter>]
Expand Down
34 changes: 26 additions & 8 deletions library/tkdnd_unix.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@ namespace eval xdnd {
# ----------------------------------------------------------------------------
# Command xdnd::HandleXdndEnter
# ----------------------------------------------------------------------------
proc xdnd::HandleXdndEnter { path drag_source typelist { data {} } } {
proc xdnd::HandleXdndEnter { path drag_source typelist time { data {} } } {
variable _pressedkeys
variable _actionlist
variable _typelist
set _pressedkeys 1
set _actionlist { copy move link ask private }
set _typelist $typelist
# puts "xdnd::HandleXdndEnter: $time"
::tkdnd::generic::SetDroppedData $data
::tkdnd::generic::HandleEnter $path $drag_source $typelist $typelist \
$_actionlist $_pressedkeys
Expand All @@ -73,10 +76,16 @@ proc xdnd::HandleXdndEnter { path drag_source typelist { data {} } } {
# ----------------------------------------------------------------------------
# Command xdnd::HandleXdndPosition
# ----------------------------------------------------------------------------
proc xdnd::HandleXdndPosition { drop_target rootX rootY {drag_source {}} } {
proc xdnd::HandleXdndPosition { drop_target rootX rootY time {drag_source {}} } {
variable _pressedkeys
variable _typelist
variable _last_mouse_root_x; set _last_mouse_root_x $rootX
variable _last_mouse_root_y; set _last_mouse_root_y $rootY
# puts "xdnd::HandleXdndPosition: $time"
## Get the dropped data...
catch {
::tkdnd::generic::SetDroppedData [GetPositionData $drop_target $_typelist $time]
}
::tkdnd::generic::HandlePosition $drop_target $drag_source \
$_pressedkeys $rootX $rootY
};# xdnd::HandleXdndPosition
Expand All @@ -96,18 +105,27 @@ proc xdnd::HandleXdndDrop { time } {
variable _last_mouse_root_x
variable _last_mouse_root_y
## Get the dropped data...
::tkdnd::generic::SetDroppedData [GetDroppedData $time]
::tkdnd::generic::SetDroppedData [GetDroppedData \
[::tkdnd::generic::GetDragSource] [::tkdnd::generic::GetDropTarget] \
[::tkdnd::generic::GetDragSourceCommonTypes] $time]
::tkdnd::generic::HandleDrop {} {} $_pressedkeys \
$_last_mouse_root_x $_last_mouse_root_y $time
};# xdnd::HandleXdndDrop

# ----------------------------------------------------------------------------
# Command xdnd::_GetDroppedData
# Command xdnd::GetPositionData
# ----------------------------------------------------------------------------
proc xdnd::GetPositionData { drop_target typelist time } {
foreach {drop_target common_drag_source_types common_drop_target_types} \
[::tkdnd::generic::FindWindowWithCommonTypes $drop_target $typelist] {break}
GetDroppedData [::tkdnd::generic::GetDragSource] $drop_target \
$common_drag_source_types $time
};# xdnd::GetPositionData

# ----------------------------------------------------------------------------
# Command xdnd::GetDroppedData
# ----------------------------------------------------------------------------
proc xdnd::GetDroppedData { time } {
set _drag_source [::tkdnd::generic::GetDragSource]
set _drop_target [::tkdnd::generic::GetDropTarget]
set _common_drag_source_types [::tkdnd::generic::GetDragSourceCommonTypes]
proc xdnd::GetDroppedData { _drag_source _drop_target _common_drag_source_types time } {
if {![llength $_common_drag_source_types]} {
error "no common data types between the drag source and drop target widgets"
}
Expand Down
Loading

0 comments on commit 8e3b6ba

Please sign in to comment.