From ac795d6ade829b799bc7130320ac608612f5a2ee Mon Sep 17 00:00:00 2001 From: petasis Date: Tue, 5 Jun 2012 11:23:25 +0000 Subject: Linux drag support --- library/tkdnd_unix.tcl | 37 ++++++++++++++++++++++++------------- unix/TkDND_XDND.c | 10 ++++++++++ 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/library/tkdnd_unix.tcl b/library/tkdnd_unix.tcl index 397c58a..58ce39a 100644 --- a/library/tkdnd_unix.tcl +++ b/library/tkdnd_unix.tcl @@ -440,7 +440,8 @@ proc xdnd::_normalise_data { type data } { # ---------------------------------------------------------------------------- proc xdnd::_platform_specific_type { type } { switch $type { - DND_Text {return [list text/plain UTF8_STRING STRING]} + DND_Text {return [list text/plain\;charset=utf-8 UTF8_STRING \ + text/plain STRING]} DND_Files {return [list text/uri-list]} default {return [list $type]} } @@ -490,8 +491,8 @@ proc xdnd::_selection_ownership_lost {} { proc xdnd::_dodragdrop { source actions types data button } { variable _dragging - # puts "xdnd::_dodragdrop: source: $source, actions: $actions, types: $types,\ - # data: \"$data\", button: $button" + puts "xdnd::_dodragdrop: source: $source, actions: $actions, types: $types,\ + data: \"$data\", button: $button" if {$_dragging} { ## We are in the middle of another drag operation... error "another drag operation in progress" @@ -534,8 +535,8 @@ proc xdnd::_dodragdrop { source actions types data button } { ## Arrange selection handlers for our drag source, and all the supported types ## foreach t $types { - selection handle -selection XdndSelection -type $t $source \ - [list ::tkdnd::xdnd::_SendData $t] + selection handle -selection XdndSelection -type $t -format UTF8_STRING \ + $source [list ::tkdnd::xdnd::_SendData $t] } ## @@ -565,7 +566,10 @@ proc xdnd::_dodragdrop { source actions types data button } { _unregister_generic_event_handler catch {selection clear -selection XdndSelection} foreach t $types { - catch {selection handle -selection XdndSelection -type $t $source {}} + catch { + selection handle -selection XdndSelection -type $t -format UTF8_STRING \ + $source {} + } } };# xdnd::_dodragdrop @@ -631,10 +635,13 @@ proc xdnd::_process_drag_events {event} { KeyPress { } KeyRelease { - } - EnterNotify { - } - LeaveNotify { + set keysym [dict get $event keysym] + switch $keysym { + Escape { + ## The user has pressed escape. Abort... + if {$_dragging} {set _dragging 0} + } + } } default { return 0 @@ -747,7 +754,11 @@ proc xdnd::_SendXdndLeave {} { proc xdnd::_SendXdndDrop {} { variable _dodragdrop_drag_source variable _dodragdrop_drop_target - if {$_dodragdrop_drop_target < 1} return + if {$_dodragdrop_drop_target < 1} { + ## The mouse has been released over a widget that does not accept drops. + _HandleXdndFinished {} + return + } variable _dodragdrop_drop_occured if {$_dodragdrop_drop_occured} {return} variable _dodragdrop_drop_target_proxy @@ -777,9 +788,9 @@ proc xdnd::_SendXdndDrop {} { # Command xdnd::_SendData # ---------------------------------------------------------------------------- proc xdnd::_SendData {type s e args} { - #puts "SendData: $type $args" variable _dodragdrop_data - return $_dodragdrop_data + puts "SendData: $type $s $e $args ($_dodragdrop_data)" + return [string range $_dodragdrop_data $s $e] };# xdnd::_SendData # ---------------------------------------------------------------------------- diff --git a/unix/TkDND_XDND.c b/unix/TkDND_XDND.c index eba6c87..993a685 100644 --- a/unix/TkDND_XDND.c +++ b/unix/TkDND_XDND.c @@ -958,6 +958,8 @@ int TkDND_HandleGenericEvent(ClientData clientData, XEvent *eventPtr) { Tcl_Obj *dict, *key, *value; Tcl_Obj *objv[2], *result; int status, i; + KeySym sym; + Tk_Window main_window; if (interp == NULL) return 0; dict = Tcl_NewDictObj(); @@ -1001,6 +1003,10 @@ int TkDND_HandleGenericEvent(ClientData clientData, XEvent *eventPtr) { TkDND_Dict_PutLong(dict, "time", eventPtr->xkey.time); 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)); break; case KeyRelease: TkDND_Dict_Put(dict, "type", "KeyRelease"); @@ -1011,6 +1017,10 @@ int TkDND_HandleGenericEvent(ClientData clientData, XEvent *eventPtr) { TkDND_Dict_PutLong(dict, "time", eventPtr->xkey.time); 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)); break; case EnterNotify: return 0; -- cgit v0.12