]> code.delx.au - gnu-emacs/blobdiff - lisp/x-dnd.el
Use __sparc__ rather than sparc.
[gnu-emacs] / lisp / x-dnd.el
index a5b6d409b8714d000af6683c1c912c902f3bfcc9..71398f106f274f004c652ea305751f660c767652 100644 (file)
@@ -1,6 +1,6 @@
 ;;; x-dnd.el --- drag and drop support for X.
 
 ;;; x-dnd.el --- drag and drop support for X.
 
-;; Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
+;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
 ;; Author: Jan Dj\e,Ad\e(Brv <jan.h.d@swipnet.se>
 ;; Maintainer: FSF
 
 ;; Author: Jan Dj\e,Ad\e(Brv <jan.h.d@swipnet.se>
 ;; Maintainer: FSF
@@ -10,7 +10,7 @@
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
@@ -70,7 +70,7 @@ The default value for this variable is `x-dnd-default-test-function'."
   "Which function to call to handle a drop of that type.
 If the type for the drop is not present, or the function is nil,
 the drop is rejected.  The function takes three arguments, WINDOW, ACTION
   "Which function to call to handle a drop of that type.
 If the type for the drop is not present, or the function is nil,
 the drop is rejected.  The function takes three arguments, WINDOW, ACTION
-and DATA.  WINDOW is where the drop occured, ACTION is the action for
+and DATA.  WINDOW is where the drop occurred, ACTION is the action for
 this drop (copy, move, link, private or ask) as determined by a previous
 call to `x-dnd-test-function'.  DATA is the drop data.
 The function shall return the action used (copy, move, link or private) if drop
 this drop (copy, move, link, private or ask) as determined by a previous
 call to `x-dnd-test-function'.  DATA is the drop data.
 The function shall return the action used (copy, move, link or private) if drop
@@ -121,6 +121,12 @@ any protocol specific data.")
 
 (defun x-dnd-init-frame (&optional frame)
   "Setup drag and drop for FRAME (i.e. create appropriate properties)."
 
 (defun x-dnd-init-frame (&optional frame)
   "Setup drag and drop for FRAME (i.e. create appropriate properties)."
+  (x-register-dnd-atom "DndProtocol" frame)
+  (x-register-dnd-atom "_MOTIF_DRAG_AND_DROP_MESSAGE" frame)
+  (x-register-dnd-atom "XdndEnter" frame)
+  (x-register-dnd-atom "XdndPosition" frame)
+  (x-register-dnd-atom "XdndLeave" frame)
+  (x-register-dnd-atom "XdndDrop" frame)
   (x-dnd-init-xdnd-for-frame frame)
   (x-dnd-init-motif-for-frame frame))
 
   (x-dnd-init-xdnd-for-frame frame)
   (x-dnd-init-motif-for-frame frame))
 
@@ -256,14 +262,20 @@ STRING is the uri-list as a string.  The URIs are separated by \r\n."
     retval))
 
 (defun x-dnd-handle-file-name (window action string)
     retval))
 
 (defun x-dnd-handle-file-name (window action string)
-  "Prepend file:// to file names and call `dnd-handle-one-url'.
+  "Convert file names to URLs and call `dnd-handle-one-url'.
 WINDOW is the window where the drop happened.
 STRING is the file names as a string, separated by nulls."
   (let ((uri-list (split-string string "[\0\r\n]" t))
 WINDOW is the window where the drop happened.
 STRING is the file names as a string, separated by nulls."
   (let ((uri-list (split-string string "[\0\r\n]" t))
+       (coding (and default-enable-multibyte-characters
+                    (or file-name-coding-system
+                        default-file-name-coding-system)))
        retval)
     (dolist (bf uri-list)
       ;; If one URL is handeled, treat as if the whole drop succeeded.
        retval)
     (dolist (bf uri-list)
       ;; If one URL is handeled, treat as if the whole drop succeeded.
-      (let* ((file-uri (concat "file://" bf))
+      (if coding (setq bf (encode-coding-string bf coding)))
+      (let* ((file-uri (concat "file://"
+                              (mapconcat 'url-hexify-string
+                                         (split-string bf "/") "/")))
             (did-action (dnd-handle-one-url window action file-uri)))
        (when did-action (setq retval did-action))))
     retval))
             (did-action (dnd-handle-one-url window action file-uri)))
        (when did-action (setq retval did-action))))
     retval))
@@ -313,7 +325,8 @@ nil if not."
          ;; If dropping in an ordinary window which we could use,
          ;; let dnd-open-file-other-window specify what to do.
          (progn
          ;; If dropping in an ordinary window which we could use,
          ;; let dnd-open-file-other-window specify what to do.
          (progn
-           (goto-char (posn-point (event-start event)))
+           (when (not mouse-yank-at-point)
+             (goto-char (posn-point (event-start event))))
            (funcall handler window action data))
        ;; If we can't display the file here,
        ;; make a new window for it.
            (funcall handler window action data))
        ;; If we can't display the file here,
        ;; make a new window for it.