Skip to content

Commit

Permalink
Merge pull request #70 from apnadkarni/tcl9-port
Browse files Browse the repository at this point in the history
Adds support for Tcl 9
  • Loading branch information
petasis authored Jan 2, 2025
2 parents 45e6167 + 201da68 commit c87c08b
Show file tree
Hide file tree
Showing 8 changed files with 480 additions and 327 deletions.
2 changes: 1 addition & 1 deletion demos/dndSpy.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
## This file implements a drop target that is able to accept any type dropped.
##
## Check Tk version:
package require Tk 8.3
package require Tk 8.3-

if {$::tcl_version == "8.3" && ![package vsatisfies $::tcl_patchLevel 8.3.3]} {
tk_messageBox -type ok -icon error \
Expand Down
18 changes: 17 additions & 1 deletion library/tkdnd.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -534,5 +534,21 @@ proc ::tkdnd::urn_unquote {url} {
set start [incr last]
}
append result [string range $url $start end]
return [encoding convertfrom utf-8 $result]
return [from_encoding utf-8 $result]
};# tkdnd::urn_unquote

if {[package vsatisfies [package require Tcl] 9]} {
proc ::tkdnd::to_encoding {enc str} {
encoding convertto -profile replace $enc $str
}
proc ::tkdnd::from_encoding {enc data} {
encoding convertfrom -profile replace $enc $data
}
} else {
proc ::tkdnd::to_encoding {enc str} {
encoding convertto $enc $str
}
proc ::tkdnd::from_encoding {enc data} {
encoding convertfrom $enc $data
}
}
12 changes: 6 additions & 6 deletions library/tkdnd_unix.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ proc xdnd::normalise_data { type data } {
STRING - UTF8_STRING - TEXT - COMPOUND_TEXT {return $data}
text/html {
if {[catch {
encoding convertfrom unicode $data
::tkdnd::from_encoding unicode $data
} string]} {
set string $data
}
Expand All @@ -241,15 +241,15 @@ proc xdnd::normalise_data { type data } {
text/plain\;charset=utf-8 -
text/plain {
if {[catch {
encoding convertfrom utf-8 [tkdnd::bytes_to_string $data]
::tkdnd::from_encoding utf-8 [tkdnd::bytes_to_string $data]
} string]} {
set string $data
}
return [string map {\r\n \n} $string]
}
text/uri-list* {
if {[catch {
encoding convertfrom utf-8 [tkdnd::bytes_to_string $data]
::tkdnd::from_encoding utf-8 [tkdnd::bytes_to_string $data]
} string]} {
set string $data
}
Expand Down Expand Up @@ -800,7 +800,7 @@ proc xdnd::_SendData {type offset bytes args} {
## Prepare the data to be transferred...
switch -glob $type {
text/plain* - UTF8_STRING - STRING - TEXT - COMPOUND_TEXT {
binary scan [encoding convertto utf-8 $typed_data] \
binary scan [::tkdnd::to_encoding utf-8 $typed_data] \
c* _dodragdrop_transfer_data
set _dodragdrop_transfer_data \
[_convert_to_unsigned $_dodragdrop_transfer_data $format]
Expand All @@ -813,7 +813,7 @@ proc xdnd::_SendData {type offset bytes args} {
default {lappend files file://$file}
}
}
binary scan [encoding convertto utf-8 "[join $files \r\n]\r\n"] \
binary scan [::tkdnd::to_encoding utf-8 "[join $files \r\n]\r\n"] \
c* _dodragdrop_transfer_data
set _dodragdrop_transfer_data \
[_convert_to_unsigned $_dodragdrop_transfer_data $format]
Expand Down Expand Up @@ -849,7 +849,7 @@ proc xdnd::_SendData {type offset bytes args} {
set data [lrange $_dodragdrop_transfer_data $offset [expr {$offset+$bytes-1}]]
switch $format {
8 {
set data [encoding convertfrom utf-8 [binary format c* $data]]
set data [::tkdnd::from_encoding utf-8 [binary format c* $data]]
}
16 {
variable _dodragdrop_selection_requestor
Expand Down
2 changes: 1 addition & 1 deletion library/tkdnd_windows.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ proc olednd::normalise_data { type data } {
switch [lindex [::tkdnd::generic::platform_independent_type $type] 0] {
DND_Text {return $data}
DND_Files {return $data}
DND_HTML {return [encoding convertfrom utf-8 $data]}
DND_HTML {return [::tkdnd::from_encoding utf-8 $data]}
default {return $data}
}
}; # olednd::normalise_data
Loading

0 comments on commit c87c08b

Please sign in to comment.