diff options
author | petasisg@gmail.com <petasisg@gmail.com@f3661a36-4baa-549a-d6c7-40e0ffef350e> | 2014-08-06 17:17:21 (GMT) |
---|---|---|
committer | petasisg@gmail.com <petasisg@gmail.com@f3661a36-4baa-549a-d6c7-40e0ffef350e> | 2014-08-06 17:17:21 (GMT) |
commit | 1e4792f41e87188683ff68c6321ffd97e9947632 (patch) | |
tree | 7761f557e80df47a48b326194206b940831e9931 | |
parent | 98884afec896ed55aa2c61cae8e824fe73bec17c (diff) | |
download | tkdnd-1e4792f41e87188683ff68c6321ffd97e9947632.zip tkdnd-1e4792f41e87188683ff68c6321ffd97e9947632.tar.gz tkdnd-1e4792f41e87188683ff68c6321ffd97e9947632.tar.bz2 |
Multiple drag source types also under Unix
-rw-r--r-- | Changelog | 8 | ||||
-rw-r--r-- | library/tkdnd_unix.tcl | 34 | ||||
-rw-r--r-- | unix/TkDND_XDND.c | 35 |
3 files changed, 61 insertions, 16 deletions
@@ -1,3 +1,11 @@ +2014-08-06 Petasis George <petasis@iit.demokritos.gr> + * library/tkdnd_unix.tcl: Added support for sources with multiple + and (incompatible) types under Unix. Completed implementation started + on 2014-01-05 for Windows. OS X support is still pending. + + * unix/TkDND_XDND.c: Replaced calls to (deprecated) + XKeycodeToKeysym(), with calls to XGetKeyboardMapping(). + 2014-08-04 Petasis George <petasis@iit.demokritos.gr> * library/tkdnd_unix.tcl: Fixed a bug where successive drags may be canceled, by a delayed XDNDFinished event, which is scheduled by diff --git a/library/tkdnd_unix.tcl b/library/tkdnd_unix.tcl index f5d0f25..4d70eb0 100644 --- a/library/tkdnd_unix.tcl +++ b/library/tkdnd_unix.tcl @@ -141,6 +141,7 @@ proc xdnd::_HandleXdndPosition { drop_target rootX rootY {drag_source {}} } { 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\} \ @@ -168,6 +169,7 @@ proc xdnd::_HandleXdndPosition { drop_target rootX rootY {drag_source {}} } { 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\} \ @@ -196,6 +198,7 @@ proc xdnd::_HandleXdndPosition { drop_target rootX rootY {drag_source {}} } { 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\} \ @@ -237,6 +240,7 @@ proc xdnd::_HandleXdndLeave { } { %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\} \ @@ -293,6 +297,7 @@ proc xdnd::_HandleXdndDrop { time } { 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\} \ @@ -310,6 +315,7 @@ proc xdnd::_HandleXdndDrop { time } { 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\} \ @@ -945,21 +951,31 @@ proc xdnd::_convert_to_unsigned {data format} { # ---------------------------------------------------------------------------- proc xdnd::_SendData {type offset bytes args} { variable _dodragdrop_drag_source + variable _dodragdrop_types variable _dodragdrop_data variable _dodragdrop_transfer_data + + ## The variable _dodragdrop_data contains a list of data, one for each + ## type in the _dodragdrop_types variable. We have to search types, and find + ## the corresponding entry in the _dodragdrop_data list. + set index [lsearch $_dodragdrop_types $type] + if {$index < 0} { + error "unable to locate data suitable for type \"$type\"" + } + set typed_data [lindex $_dodragdrop_data $index] set format 8 if {$offset == 0} { ## Prepare the data to be transfered... switch -glob $type { text/plain* - UTF8_STRING - STRING - TEXT - COMPOUND_TEXT { - binary scan [encoding convertto utf-8 $_dodragdrop_data] \ + binary scan [encoding convertto utf-8 $typed_data] \ c* _dodragdrop_transfer_data set _dodragdrop_transfer_data \ [_convert_to_unsigned $_dodragdrop_transfer_data $format] } text/uri-list* { set files [list] - foreach file $_dodragdrop_data { + foreach file $typed_data { switch -glob $file { *://* {lappend files $file} default {lappend files file://$file} @@ -975,12 +991,12 @@ proc xdnd::_SendData {type offset bytes args} { ## Try to understand the provided data: we accept a standard Tk colour, ## or a list of 3 values (red green blue) or a list of 4 values ## (red green blue opacity). - switch [llength $_dodragdrop_data] { - 1 { set color [winfo rgb $_dodragdrop_drag_source $_dodragdrop_data] + switch [llength $typed_data] { + 1 { set color [winfo rgb $_dodragdrop_drag_source $typed_data] lappend color 65535 } - 3 { set color $_dodragdrop_data; lappend color 65535 } - 4 { set color $_dodragdrop_data } - default {error "unknown color data: \"$_dodragdrop_data\""} + 3 { set color $typed_data; lappend color 65535 } + 4 { set color $typed_data } + default {error "unknown color data: \"$typed_data\""} } ## Convert the 4 elements into 16 bit values... set _dodragdrop_transfer_data [list] @@ -990,7 +1006,7 @@ proc xdnd::_SendData {type offset bytes args} { } default { set format 32 - binary scan $_dodragdrop_data c* _dodragdrop_transfer_data + binary scan $typed_data c* _dodragdrop_transfer_data } } } @@ -1029,7 +1045,7 @@ proc xdnd::_SendData {type offset bytes args} { error "unsupported format $format" } } - # puts "SendData: $type $offset $bytes $args ($_dodragdrop_data)" + # puts "SendData: $type $offset $bytes $args ($typed_data)" # puts " $data" return $data };# xdnd::_SendData diff --git a/unix/TkDND_XDND.c b/unix/TkDND_XDND.c index bc12901..95c3387 100644 --- a/unix/TkDND_XDND.c +++ b/unix/TkDND_XDND.c @@ -963,7 +963,12 @@ int TkDND_HandleGenericEvent(ClientData clientData, XEvent *eventPtr) { Tcl_Obj *dict, *key, *value; Tcl_Obj *objv[2], *result; int status, i; - KeySym sym; +#ifdef TKDND_USE_XKEYCODETOKEYSYM + KeySym keysym; +#else + KeySym *keysym; + int keysyms_per_keycode_return; +#endif /* TKDND_USE_XKEYCODETOKEYSYM */ Tk_Window main_window; if (interp == NULL) return 0; @@ -1009,9 +1014,17 @@ int TkDND_HandleGenericEvent(ClientData clientData, XEvent *eventPtr) { TkDND_AddStateInformation(interp, dict, eventPtr->xkey.state); TkDND_Dict_PutInt(dict, "keycode", eventPtr->xkey.keycode); main_window = Tk_MainWindow(interp); - sym = XKeycodeToKeysym(Tk_Display(main_window), - eventPtr->xkey.keycode, 0); - TkDND_Dict_Put(dict, "keysym", XKeysymToString(sym)); +#ifdef TKDND_USE_XKEYCODETOKEYSYM + keysym = XKeycodeToKeysym(Tk_Display(main_window), + eventPtr->xkey.keycode, 0); + TkDND_Dict_Put(dict, "keysym", XKeysymToString(keysym)); +#else /* TKDND_USE_XKEYCODETOKEYSYM */ + keysym = XGetKeyboardMapping(Tk_Display(main_window), + eventPtr->xkey.keycode, 1, + &keysyms_per_keycode_return); + TkDND_Dict_Put(dict, "keysym", XKeysymToString(keysym[0])); + XFree(keysym); +#endif /* TKDND_USE_XKEYCODETOKEYSYM */ break; case KeyRelease: TkDND_Dict_Put(dict, "type", "KeyRelease"); @@ -1023,9 +1036,17 @@ int TkDND_HandleGenericEvent(ClientData clientData, XEvent *eventPtr) { TkDND_AddStateInformation(interp, dict, eventPtr->xkey.state); TkDND_Dict_PutInt(dict, "keycode", eventPtr->xkey.keycode); main_window = Tk_MainWindow(interp); - sym = XKeycodeToKeysym(Tk_Display(main_window), - eventPtr->xkey.keycode, 0); - TkDND_Dict_Put(dict, "keysym", XKeysymToString(sym)); +#ifdef TKDND_USE_XKEYCODETOKEYSYM + keysym = XKeycodeToKeysym(Tk_Display(main_window), + eventPtr->xkey.keycode, 0); + TkDND_Dict_Put(dict, "keysym", XKeysymToString(keysym)); +#else /* TKDND_USE_XKEYCODETOKEYSYM */ + keysym = XGetKeyboardMapping(Tk_Display(main_window), + eventPtr->xkey.keycode, 1, + &keysyms_per_keycode_return); + TkDND_Dict_Put(dict, "keysym", XKeysymToString(keysym[0])); + XFree(keysym); +#endif /* TKDND_USE_XKEYCODETOKEYSYM */ break; case EnterNotify: return 0; |