~ubuntu-branches/ubuntu/karmic/emacs-snapshot/karmic

« back to all changes in this revision

Viewing changes to lisp/x-dnd.el

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2009-04-05 09:14:30 UTC
  • mto: This revision was merged to the branch mainline in revision 34.
  • Revision ID: james.westby@ubuntu.com-20090405091430-nw07lynn2arotjbe
Tags: upstream-20090320
ImportĀ upstreamĀ versionĀ 20090320

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
;;; x-dnd.el --- drag and drop support for X.
2
2
 
3
 
;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
3
;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
4
4
 
5
5
;; Author: Jan Dj,Ad(Brv <jan.h.d@swipnet.se>
6
6
;; Maintainer: FSF
33
33
;;; Customizable variables
34
34
(defcustom x-dnd-test-function 'x-dnd-default-test-function
35
35
  "The function drag and drop uses to determine if to accept or reject a drop.
36
 
The function takes three arguments, WINDOW ACTION and TYPES.
 
36
The function takes three arguments, WINDOW, ACTION and TYPES.
37
37
WINDOW is where the mouse is when the function is called.  WINDOW may be a
38
38
frame if the mouse isn't over a real window (i.e. menu bar, tool bar or
39
39
scroll bar).  ACTION is the suggested action from the drag and drop source,
40
 
one of the symbols move, copy link or ask.  TYPES is a list of available types
41
 
for the drop.
 
40
one of the symbols move, copy, link or ask.  TYPES is a list of available
 
41
types for the drop.
42
42
 
43
43
The function shall return nil to reject the drop or a cons with two values,
44
44
the wanted action as car and the wanted type as cdr.  The wanted action
71
71
and DATA.  WINDOW is where the drop occurred, ACTION is the action for
72
72
this drop (copy, move, link, private or ask) as determined by a previous
73
73
call to `x-dnd-test-function'.  DATA is the drop data.
74
 
The function shall return the action used (copy, move, link or private) if drop
75
 
is successful, nil if not."
 
74
The function shall return the action used (copy, move, link or private)
 
75
if drop is successful, nil if not."
76
76
  :version "22.1"
77
77
  :type 'alist
78
78
  :group 'x)
130
130
    (x-dnd-init-motif-for-frame frame)))
131
131
 
132
132
(defun x-dnd-get-state-cons-for-frame (frame-or-window)
133
 
  "Return the entry in x-dnd-current-state for a frame or window."
 
133
  "Return the entry in `x-dnd-current-state' for a frame or window."
134
134
  (let* ((frame (if (framep frame-or-window) frame-or-window
135
135
                  (window-frame frame-or-window)))
136
136
         (display (frame-parameter frame 'display)))
140
140
    (assoc display x-dnd-current-state)))
141
141
 
142
142
(defun x-dnd-get-state-for-frame (frame-or-window)
143
 
  "Return the state in x-dnd-current-state for a frame or window."
 
143
  "Return the state in `x-dnd-current-state' for a frame or window."
144
144
  (cdr (x-dnd-get-state-cons-for-frame frame-or-window)))
145
145
 
146
146
(defun x-dnd-default-test-function (window action types)
147
147
  "The default test function for drag and drop.
148
 
WINDOW is where the mouse is when this function is called.  It may be a frame
149
 
if the mouse is over the menu bar, scroll bar or tool bar.
 
148
WINDOW is where the mouse is when this function is called.  It may be
 
149
a frame if the mouse is over the menu bar, scroll bar or tool bar.
150
150
ACTION is the suggested action from the source, and TYPES are the
151
151
types the drop data can have.  This function only accepts drops with
152
152
types in `x-dnd-known-types'.  It always returns the action private."
212
212
(defun x-dnd-handle-moz-url (window action data)
213
213
  "Handle one item of type text/x-moz-url.
214
214
WINDOW is the window where the drop happened.  ACTION is ignored.
215
 
DATA is the moz-url, which is formatted as two strings separated by \r\n.
 
215
DATA is the moz-url, which is formatted as two strings separated by \\r\\n.
216
216
The first string is the URL, the second string is the title of that URL.
217
217
DATA is encoded in utf-16.  Decode the URL and call `x-dnd-handle-uri-list'."
218
218
  ;; Mozilla and applications based on it (Galeon for example) uses
249
249
(defun x-dnd-handle-uri-list (window action string)
250
250
  "Split an uri-list into separate URIs and call `dnd-handle-one-url'.
251
251
WINDOW is the window where the drop happened.
252
 
STRING is the uri-list as a string.  The URIs are separated by \r\n."
 
252
STRING is the uri-list as a string.  The URIs are separated by \\r\\n."
253
253
  (let ((uri-list (split-string string "[\0\r\n]" t))
254
254
        retval)
255
255
    (dolist (bf uri-list)
256
 
      ;; If one URL is handeled, treat as if the whole drop succeeded.
 
256
      ;; If one URL is handled, treat as if the whole drop succeeded.
257
257
      (let ((did-action (dnd-handle-one-url window action bf)))
258
258
        (when did-action (setq retval did-action))))
259
259
    retval))
268
268
                         default-file-name-coding-system)))
269
269
        retval)
270
270
    (dolist (bf uri-list)
271
 
      ;; If one URL is handeled, treat as if the whole drop succeeded.
 
271
      ;; If one URL is handled, treat as if the whole drop succeeded.
272
272
      (if coding (setq bf (encode-coding-string bf coding)))
273
273
      (let* ((file-uri (concat "file://"
274
274
                               (mapconcat 'url-hexify-string
282
282
  "Choose which type we want to receive for the drop.
283
283
TYPES are the types the source of the drop offers, a vector of type names
284
284
as strings or symbols.  Select among the types in `x-dnd-known-types' or
285
 
KNOWN-TYPES if given,  and return that type name.
 
285
KNOWN-TYPES if given, and return that type name.
286
286
If no suitable type is found, return nil."
287
287
  (let* ((known-list (or known-types x-dnd-known-types))
288
288
         (first-known-type (car known-list))
303
303
 
304
304
(defun x-dnd-drop-data (event frame window data type)
305
305
  "Drop one data item onto a frame.
306
 
EVENT is the client message for the drop, FRAME is the frame the drop occurred
307
 
on.  WINDOW is the window of FRAME where the drop happened.  DATA is the data
308
 
received from the source, and type is the type for DATA, see
309
 
`x-dnd-types-alist').
 
306
EVENT is the client message for the drop, FRAME is the frame the drop
 
307
occurred on.  WINDOW is the window of FRAME where the drop happened.
 
308
DATA is the data received from the source, and type is the type for DATA,
 
309
see `x-dnd-types-alist').
310
310
 
311
311
Returns the action used (move, copy, link, private) if drop was successful,
312
312
nil if not."
389
389
                            frame "ATOM" 32 t))
390
390
 
391
391
(defun x-dnd-get-drop-width-height (frame w accept)
392
 
  "Return the widht/height to be sent in a XDndStatus message.
 
392
  "Return the width/height to be sent in a XDndStatus message.
393
393
FRAME is the frame and W is the window where the drop happened.
394
394
If ACCEPT is nil return 0 (empty rectangle),
395
 
otherwise if W is a window, return its widht/height,
 
395
otherwise if W is a window, return its width/height,
396
396
otherwise return the frame width/height."
397
397
  (if accept
398
398
      (if (windowp w)   ;; w is not a window if dropping on the menu bar,
520
520
;;;  Motif protocol.
521
521
 
522
522
(defun x-dnd-init-motif-for-frame (frame)
523
 
  "Set _MOTIF_DRAG_RECEIVER_INFO  for FRAME to indicate that we do Motif DND."
 
523
  "Set _MOTIF_DRAG_RECEIVER_INFO for FRAME to indicate that we do Motif DND."
524
524
  (x-change-window-property "_MOTIF_DRAG_RECEIVER_INFO"
525
525
                            (list
526
526
                             (byteorder)