annotate lisp/x-dnd.el @ 57459:dc60b5774fad

(files-in-below-directory): remove unneeded `or' expression that looks at both . and .. since argument to `substring' specifies just one character.
author Robert J. Chassell <bob@rattlesnake.com>
date Tue, 12 Oct 2004 17:15:06 +0000
parents 4504840779eb
children 61662d4f85c7 cc29203a9a04 3219f94257bc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
1 ;;; x-dnd.el --- drag and drop support for X.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
2
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
3 ;; Copyright (C) 2004
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
4 ;; Free Software Foundation, Inc.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
5
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
6 ;; Author: Jan Dj,Ad(Brv <jan.h.d@swipnet.se>
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
7 ;; Maintainer: FSF
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
8 ;; Keywords: window, drag, drop
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
9
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
11
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
15 ;; any later version.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
16
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
20 ;; GNU General Public License for more details.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
21
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
25 ;; Boston, MA 02111-1307, USA.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
26
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
27 ;;; Commentary:
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
28
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
29 ;; This file provides the drop part only. Currently supported protocols
53949
7edbce1dd20a * x-dnd.el: Mention support for Motif in commentary.
Jan Djärv <jan.h.d@swipnet.se>
parents: 53913
diff changeset
30 ;; are XDND, Motif and the old KDE 1.x protocol.
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
31
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
32 ;;; Code:
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
33
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
34 ;;; Customizable variables
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
35
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
36
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
37 (defcustom x-dnd-test-function 'x-dnd-default-test-function
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
38 "The function drag and drop uses to determine if to accept or reject a drop.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
39 The function takes three arguments, WINDOW ACTION and TYPES.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
40 WINDOW is where the mouse is when the function is called. WINDOW may be a
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
41 frame if the mouse isn't over a real window (i.e. menu bar, tool bar or
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
42 scroll bar). ACTION is the suggested action from the drag and drop source,
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
43 one of the symbols move, copy link or ask. TYPES is a list of available types
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
44 for the drop.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
45
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
46 The function shall return nil to reject the drop or a cons with two values,
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
47 the wanted action as car and the wanted type as cdr. The wanted action
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
48 can be copy, move, link, ask or private.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
49 The default value for this variable is `x-dnd-default-test-function'."
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
50 :type 'symbol
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
51 :group 'x)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
52
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
53 (defcustom x-dnd-protocol-alist
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
54 '(
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
55 ("^file:///" . x-dnd-open-local-file) ; XDND format.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
56 ("^file://" . x-dnd-open-file) ; URL with host
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
57 ("^file:" . x-dnd-open-local-file) ; Old KDE, Motif, Sun
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
58 )
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
59
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
60 "The functions to call for different protocols when a drop is made.
56852
4504840779eb * x-dnd.el (x-dnd-protocol-alist): Document update.
Jan Djärv <jan.h.d@swipnet.se>
parents: 54986
diff changeset
61 This variable is used by `x-dnd-handle-uri-list', `x-dnd-handle-file-name'
4504840779eb * x-dnd.el (x-dnd-protocol-alist): Document update.
Jan Djärv <jan.h.d@swipnet.se>
parents: 54986
diff changeset
62 and `x-dnd-handle-moz-url'. The list contains of (REGEXP . FUNCTION) pairs.
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
63 The functions shall take two arguments, URL, which is the URL dropped and
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
64 ACTION which is the action to be performed for the drop (move, copy, link,
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
65 private or ask).
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
66 If no match is found here, and the value of `browse-url-browser-function'
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
67 is a pair of (REGEXP . FUNCTION), those regexps are tried for a match.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
68 Insertion of text is not handeled by these functions, see `x-dnd-types-alist'
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
69 for that.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
70 The function shall return the action done (move, copy, link or private)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
71 if some action was made, or nil if the URL is ignored."
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
72 :type 'alist
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
73 :group 'x)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
74
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
75
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
76 (defcustom x-dnd-types-alist
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
77 '(
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
78 ("text/uri-list" . x-dnd-handle-uri-list)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
79 ("text/x-moz-url" . x-dnd-handle-moz-url)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
80 ("_NETSCAPE_URL" . x-dnd-handle-uri-list)
53913
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
81 ("FILE_NAME" . x-dnd-handle-file-name)
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
82 ("UTF8_STRING" . x-dnd-insert-utf8-text)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
83 ("text/plain;charset=UTF-8" . x-dnd-insert-utf8-text)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
84 ("text/plain;charset=utf-8" . x-dnd-insert-utf8-text)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
85 ("text/unicode" . x-dnd-insert-utf16-text)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
86 ("text/plain" . x-dnd-insert-text)
53913
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
87 ("COMPOUND_TEXT" . x-dnd-insert-ctext)
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
88 ("STRING" . x-dnd-insert-text)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
89 ("TEXT" . x-dnd-insert-text)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
90 )
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
91 "Which function to call to handle a drop of that type.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
92 If the type for the drop is not present, or the function is nil,
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
93 the drop is rejected. The function takes three arguments, WINDOW, ACTION
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
94 and DATA. WINDOW is where the drop occured, ACTION is the action for
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
95 this drop (copy, move, link, private or ask) as determined by a previous
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
96 call to `x-dnd-test-function'. DATA is the drop data.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
97 The function shall return the action used (copy, move, link or private) if drop
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
98 is successful, nil if not."
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
99 :type 'alist
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
100 :group 'x)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
101
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
102 (defcustom x-dnd-open-file-other-window nil
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
103 "If non-nil, always use find-file-other-window to open dropped files."
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
104 :type 'boolean
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
105 :group 'x)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
106
56852
4504840779eb * x-dnd.el (x-dnd-protocol-alist): Document update.
Jan Djärv <jan.h.d@swipnet.se>
parents: 54986
diff changeset
107 (defcustom x-dnd-known-types
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
108 '("text/uri-list"
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
109 "text/x-moz-url"
53913
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
110 "_NETSCAPE_URL"
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
111 "FILE_NAME"
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
112 "UTF8_STRING"
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
113 "text/plain;charset=UTF-8"
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
114 "text/plain;charset=utf-8"
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
115 "text/unicode"
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
116 "text/plain"
53913
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
117 "COMPOUND_TEXT"
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
118 "STRING"
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
119 "TEXT"
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
120 )
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
121 "The types accepted by default for dropped data.
56852
4504840779eb * x-dnd.el (x-dnd-protocol-alist): Document update.
Jan Djärv <jan.h.d@swipnet.se>
parents: 54986
diff changeset
122 The types are chosen in the order they appear in the list."
4504840779eb * x-dnd.el (x-dnd-protocol-alist): Document update.
Jan Djärv <jan.h.d@swipnet.se>
parents: 54986
diff changeset
123 :type '(repeat string)
4504840779eb * x-dnd.el (x-dnd-protocol-alist): Document update.
Jan Djärv <jan.h.d@swipnet.se>
parents: 54986
diff changeset
124 :group 'x
4504840779eb * x-dnd.el (x-dnd-protocol-alist): Document update.
Jan Djärv <jan.h.d@swipnet.se>
parents: 54986
diff changeset
125 )
4504840779eb * x-dnd.el (x-dnd-protocol-alist): Document update.
Jan Djärv <jan.h.d@swipnet.se>
parents: 54986
diff changeset
126
4504840779eb * x-dnd.el (x-dnd-protocol-alist): Document update.
Jan Djärv <jan.h.d@swipnet.se>
parents: 54986
diff changeset
127 ;; Internal variables
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
128
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
129 (defvar x-dnd-current-state nil
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
130 "The current state for a drop.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
131 This is an alist with one entry for each display. The value for each display
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
132 is a vector that contains the state for drag and drop for that display.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
133 Elements in the vector are:
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
134 Last buffer drag was in,
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
135 last window drag was in,
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
136 types available for drop,
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
137 the action suggested by the source,
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
138 the type we want for the drop,
53913
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
139 the action we want for the drop,
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
140 any protocol specific data.")
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
141
53913
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
142 (defvar x-dnd-empty-state [nil nil nil nil nil nil nil])
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
143
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
144
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
145
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
146 (defun x-dnd-init-frame (&optional frame)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
147 "Setup drag and drop for FRAME (i.e. create appropriate properties)."
53913
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
148 (x-dnd-init-xdnd-for-frame frame)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
149 (x-dnd-init-motif-for-frame frame))
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
150
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
151 (defun x-dnd-get-state-cons-for-frame (frame-or-window)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
152 "Return the entry in x-dnd-current-state for a frame or window."
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
153 (let* ((frame (if (framep frame-or-window) frame-or-window
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
154 (window-frame frame-or-window)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
155 (display (frame-parameter frame 'display)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
156 (if (not (assoc display x-dnd-current-state))
53913
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
157 (push (cons display (copy-sequence x-dnd-empty-state))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
158 x-dnd-current-state))
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
159 (assoc display x-dnd-current-state)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
160
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
161 (defun x-dnd-get-state-for-frame (frame-or-window)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
162 "Return the state in x-dnd-current-state for a frame or window."
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
163 (cdr (x-dnd-get-state-cons-for-frame frame-or-window)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
164
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
165 (defun x-dnd-default-test-function (window action types)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
166 "The default test function for drag and drop.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
167 WINDOW is where the mouse is when this function is called. It may be a frame
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
168 if the mouse is over the menu bar, scroll bar or tool bar.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
169 ACTION is the suggested action from the source, and TYPES are the
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
170 types the drop data can have. This function only accepts drops with
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
171 types in `x-dnd-known-types'. It always returns the action private."
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
172 (let ((type (x-dnd-choose-type types)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
173 (when type (cons 'private type))))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
174
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
175
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
176 (defun x-dnd-current-type (frame-or-window)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
177 "Return the type we want the DND data to be in for the current drop.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
178 FRAME-OR-WINDOW is the frame or window that the mouse is over."
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
179 (aref (x-dnd-get-state-for-frame frame-or-window) 4))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
180
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
181 (defun x-dnd-forget-drop (frame-or-window)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
182 "Remove all state for the last drop.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
183 FRAME-OR-WINDOW is the frame or window that the mouse is over."
53913
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
184 (setcdr (x-dnd-get-state-cons-for-frame frame-or-window)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
185 (copy-sequence x-dnd-empty-state)))
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
186
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
187 (defun x-dnd-maybe-call-test-function (window action)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
188 "Call `x-dnd-test-function' if something has changed.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
189 WINDOW is the window the mouse is over. ACTION is the suggested
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
190 action from the source. If nothing has changed, return the last
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
191 action and type we got from `x-dnd-test-function'."
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
192 (let ((buffer (when (and (windowp window) (window-live-p window))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
193 (window-buffer window)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
194 (current-state (x-dnd-get-state-for-frame window)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
195 (when (or (not (equal buffer (aref current-state 0)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
196 (not (equal window (aref current-state 1)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
197 (not (equal action (aref current-state 3))))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
198 (save-excursion
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
199 (when buffer (set-buffer buffer))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
200 (let* ((action-type (funcall x-dnd-test-function
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
201 window
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
202 action
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
203 (aref current-state 2)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
204 (handler (cdr (assoc (cdr action-type) x-dnd-types-alist))))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
205 ;; Ignore action-type if we have no handler.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
206 (setq current-state
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
207 (x-dnd-save-state window
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
208 action
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
209 (when handler action-type)))))))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
210 (let ((current-state (x-dnd-get-state-for-frame window)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
211 (cons (aref current-state 5)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
212 (aref current-state 4))))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
213
53913
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
214 (defun x-dnd-save-state (window action action-type &optional types extra-data)
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
215 "Save the state of the current drag and drop.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
216 WINDOW is the window the mouse is over. ACTION is the action suggested
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
217 by the source. ACTION-TYPE is the result of calling `x-dnd-test-function'.
53913
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
218 If given, TYPES are the types for the drop data that the source supports.
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
219 EXTRA-DATA is data needed for a specific protocol."
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
220 (let ((current-state (x-dnd-get-state-for-frame window)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
221 (aset current-state 5 (car action-type))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
222 (aset current-state 4 (cdr action-type))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
223 (aset current-state 3 action)
53913
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
224 (when types (aset current-state 2 types))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
225 (when extra-data (aset current-state 6 extra-data))
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
226 (aset current-state 1 window)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
227 (aset current-state 0 (if (and (windowp window)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
228 (window-live-p window))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
229 (window-buffer window) nil))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
230 (setcdr (x-dnd-get-state-cons-for-frame window) current-state)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
231
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
232
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
233 (defun x-dnd-handle-one-url (window action arg)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
234 "Handle one dropped url by calling the appropriate handler.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
235 The handler is first localted by looking at `x-dnd-protocol-alist'.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
236 If no match is found here, and the value of `browse-url-browser-function'
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
237 is a pair of (REGEXP . FUNCTION), those regexps are tried for a match.
53790
5046818534df Fix typo.
Jan Djärv <jan.h.d@swipnet.se>
parents: 53789
diff changeset
238 If no match is found, just call `x-dnd-insert-text'.
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
239 WINDOW is where the drop happend, ACTION is the action for the drop,
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
240 ARG is the URL that has been dropped.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
241 Returns ACTION."
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
242 (require 'browse-url)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
243 (let* ((uri (replace-regexp-in-string
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
244 "%[A-Z0-9][A-Z0-9]"
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
245 (lambda (arg)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
246 (format "%c" (string-to-number (substring arg 1) 16)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
247 arg))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
248 ret)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
249 (or
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
250 (catch 'done
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
251 (dolist (bf x-dnd-protocol-alist)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
252 (when (string-match (car bf) uri)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
253 (setq ret (funcall (cdr bf) uri action))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
254 (throw 'done t)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
255 nil)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
256 (when (not (functionp browse-url-browser-function))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
257 (catch 'done
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
258 (dolist (bf browse-url-browser-function)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
259 (when (string-match (car bf) uri)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
260 (setq ret 'private)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
261 (funcall (cdr bf) uri action)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
262 (throw 'done t)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
263 nil))
53913
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
264 (progn
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
265 (x-dnd-insert-text window action uri)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
266 (setq ret 'private)))
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
267 ret))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
268
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
269
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
270 (defun x-dnd-get-local-file-uri (uri)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
271 "Return an uri converted to file:/// syntax if uri is a local file.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
272 Return nil if URI is not a local file."
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
273
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
274 ;; The hostname may be our hostname, in that case, convert to a local
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
275 ;; file. Otherwise return nil. TODO: How about an IP-address as hostname?
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
276 (let ((hostname (when (string-match "^file://\\([^/]*\\)" uri)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
277 (downcase (match-string 1 uri))))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
278 (system-name-no-dot
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
279 (downcase (if (string-match "^[^\\.]+" system-name)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
280 (match-string 0 system-name)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
281 system-name))))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
282 (when (and hostname
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
283 (or (string-equal "localhost" hostname)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
284 (string-equal (downcase system-name) hostname)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
285 (string-equal system-name-no-dot hostname)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
286 (concat "file://" (substring uri (+ 7 (length hostname)))))))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
287
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
288 (defun x-dnd-get-local-file-name (uri &optional must-exist)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
289 "Return file name converted from file:/// or file: syntax.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
290 URI is the uri for the file. If MUST-EXIST is given and non-nil,
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
291 only return non-nil if the file exists.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
292 Return nil if URI is not a local file."
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
293 (let ((f (cond ((string-match "^file:///" uri) ; XDND format.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
294 (substring uri (1- (match-end 0))))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
295 ((string-match "^file:" uri) ; Old KDE, Motif, Sun
53823
cc4faf95fea2 * x-dnd.el (x-dnd-get-local-file-name): Fix byte compiler warning
Jan Djärv <jan.h.d@swipnet.se>
parents: 53797
diff changeset
296 (substring uri (match-end 0))))))
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
297 (when (and f must-exist)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
298 (let* ((decoded-f (decode-coding-string
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
299 f
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
300 (or file-name-coding-system
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
301 default-file-name-coding-system)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
302 (try-f (if (file-readable-p decoded-f) decoded-f f)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
303 (when (file-readable-p try-f) try-f)))))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
304
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
305
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
306 (defun x-dnd-open-local-file (uri action)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
307 "Open a local file.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
308 The file is opened in the current window, or a new window if
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
309 `x-dnd-open-file-other-window' is set. URI is the url for the file,
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
310 and must have the format file:file-name or file:///file-name.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
311 The last / in file:/// is part of the file name. ACTION is ignored."
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
312
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
313 (let* ((f (x-dnd-get-local-file-name uri t)))
54986
82f3f56ffbf1 * x-dnd.el (x-dnd-open-local-file, x-dnd-open-file): Improved error
Jan Djärv <jan.h.d@swipnet.se>
parents: 54682
diff changeset
314 (if (and f (file-readable-p f))
82f3f56ffbf1 * x-dnd.el (x-dnd-open-local-file, x-dnd-open-file): Improved error
Jan Djärv <jan.h.d@swipnet.se>
parents: 54682
diff changeset
315 (progn
82f3f56ffbf1 * x-dnd.el (x-dnd-open-local-file, x-dnd-open-file): Improved error
Jan Djärv <jan.h.d@swipnet.se>
parents: 54682
diff changeset
316 (if x-dnd-open-file-other-window
82f3f56ffbf1 * x-dnd.el (x-dnd-open-local-file, x-dnd-open-file): Improved error
Jan Djärv <jan.h.d@swipnet.se>
parents: 54682
diff changeset
317 (find-file-other-window f)
82f3f56ffbf1 * x-dnd.el (x-dnd-open-local-file, x-dnd-open-file): Improved error
Jan Djärv <jan.h.d@swipnet.se>
parents: 54682
diff changeset
318 (find-file f))
82f3f56ffbf1 * x-dnd.el (x-dnd-open-local-file, x-dnd-open-file): Improved error
Jan Djärv <jan.h.d@swipnet.se>
parents: 54682
diff changeset
319 'private)
82f3f56ffbf1 * x-dnd.el (x-dnd-open-local-file, x-dnd-open-file): Improved error
Jan Djärv <jan.h.d@swipnet.se>
parents: 54682
diff changeset
320 (error "Can not read %s" uri))))
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
321
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
322 (defun x-dnd-open-file (uri action)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
323 "Open a local or remote file.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
324 The file is opened in the current window, or a new window if
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
325 `x-dnd-open-file-other-window' is set. URI is the url for the file,
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
326 and must have the format file://hostname/file-name. ACTION is ignored.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
327 The last / in file://hostname/ is part of the file name."
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
328
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
329 ;; The hostname may be our hostname, in that case, convert to a local
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
330 ;; file. Otherwise return nil.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
331 (let ((local-file (x-dnd-get-local-file-uri uri)))
54986
82f3f56ffbf1 * x-dnd.el (x-dnd-open-local-file, x-dnd-open-file): Improved error
Jan Djärv <jan.h.d@swipnet.se>
parents: 54682
diff changeset
332 (if local-file (x-dnd-open-local-file local-file action)
82f3f56ffbf1 * x-dnd.el (x-dnd-open-local-file, x-dnd-open-file): Improved error
Jan Djärv <jan.h.d@swipnet.se>
parents: 54682
diff changeset
333 (error "Remote files not supported"))))
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
334
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
335
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
336 (defun x-dnd-handle-moz-url (window action data)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
337 "Handle one item of type text/x-moz-url.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
338 WINDOW is the window where the drop happened. ACTION is ignored.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
339 DATA is the moz-url, which is formatted as two strings separated by \r\n.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
340 The first string is the URL, the second string is the title of that URL.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
341 DATA is encoded in utf-16. Decode the URL and call `x-dnd-handle-uri-list'."
54682
bd0296e87c16 * x-dnd.el (x-dnd-handle-moz-url, x-dnd-insert-utf16-text): Use
Jan Djärv <jan.h.d@swipnet.se>
parents: 53949
diff changeset
342 ;; Mozilla and applications based on it (Galeon for example) uses
bd0296e87c16 * x-dnd.el (x-dnd-handle-moz-url, x-dnd-insert-utf16-text): Use
Jan Djärv <jan.h.d@swipnet.se>
parents: 53949
diff changeset
343 ;; text/unicode, but it is impossible to tell if it is le or be. Use what
bd0296e87c16 * x-dnd.el (x-dnd-handle-moz-url, x-dnd-insert-utf16-text): Use
Jan Djärv <jan.h.d@swipnet.se>
parents: 53949
diff changeset
344 ;; the machine Emacs runs on use. This looses if dropping between machines
bd0296e87c16 * x-dnd.el (x-dnd-handle-moz-url, x-dnd-insert-utf16-text): Use
Jan Djärv <jan.h.d@swipnet.se>
parents: 53949
diff changeset
345 ;; with different endian, but it is the best we can do.
bd0296e87c16 * x-dnd.el (x-dnd-handle-moz-url, x-dnd-insert-utf16-text): Use
Jan Djärv <jan.h.d@swipnet.se>
parents: 53949
diff changeset
346 (let* ((coding (if (eq (byteorder) ?B) 'utf-16be 'utf-16le))
bd0296e87c16 * x-dnd.el (x-dnd-handle-moz-url, x-dnd-insert-utf16-text): Use
Jan Djärv <jan.h.d@swipnet.se>
parents: 53949
diff changeset
347 (string (decode-coding-string data coding))
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
348 (strings (split-string string "[\r\n]" t))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
349 ;; Can one drop more than one moz-url ?? Assume not.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
350 (url (car strings))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
351 (title (car (cdr strings))))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
352 (x-dnd-handle-uri-list window action url)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
353
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
354 (defun x-dnd-insert-utf8-text (window action text)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
355 "Decode the UTF-8 text and insert it at point.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
356 TEXT is the text as a string, WINDOW is the window where the drop happened."
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
357 (x-dnd-insert-text window action (decode-coding-string text 'utf-8)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
358
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
359 (defun x-dnd-insert-utf16-text (window action text)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
360 "Decode the UTF-16 text and insert it at point.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
361 TEXT is the text as a string, WINDOW is the window where the drop happened."
54682
bd0296e87c16 * x-dnd.el (x-dnd-handle-moz-url, x-dnd-insert-utf16-text): Use
Jan Djärv <jan.h.d@swipnet.se>
parents: 53949
diff changeset
362 ;; See comment in x-dnd-handle-moz-url about coding.
bd0296e87c16 * x-dnd.el (x-dnd-handle-moz-url, x-dnd-insert-utf16-text): Use
Jan Djärv <jan.h.d@swipnet.se>
parents: 53949
diff changeset
363 (let ((coding (if (eq (byteorder) ?B) 'utf-16be 'utf-16le)))
bd0296e87c16 * x-dnd.el (x-dnd-handle-moz-url, x-dnd-insert-utf16-text): Use
Jan Djärv <jan.h.d@swipnet.se>
parents: 53949
diff changeset
364 (x-dnd-insert-text window action (decode-coding-string text coding))))
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
365
53913
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
366 (defun x-dnd-insert-ctext (window action text)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
367 "Decode the compound text and insert it at point.
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
368 TEXT is the text as a string, WINDOW is the window where the drop happened."
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
369 (x-dnd-insert-text window action
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
370 (decode-coding-string text
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
371 'compound-text-with-extensions)))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
372
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
373 (defun x-dnd-insert-text (window action text)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
374 "Insert text at point or push to the kill ring if buffer is read only.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
375 TEXT is the text as a string, WINDOW is the window where the drop happened."
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
376 (if (or buffer-read-only
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
377 (not (windowp window)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
378 (progn
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
379 (kill-new text)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
380 (message
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
381 (substitute-command-keys
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
382 "The dropped text can be accessed with \\[yank]")))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
383 (insert text))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
384 action)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
385
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
386 (defun x-dnd-handle-uri-list (window action string)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
387 "Split an uri-list into separate URIs and call `x-dnd-handle-one-url'.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
388 WINDOW is the window where the drop happened.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
389 STRING is the uri-list as a string. The URIs are separated by \r\n."
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
390 (let ((uri-list (split-string string "[\0\r\n]" t))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
391 retval)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
392 (dolist (bf uri-list)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
393 ;; If one URL is handeled, treat as if the whole drop succeeded.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
394 (let ((did-action (x-dnd-handle-one-url window action bf)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
395 (when did-action (setq retval did-action))))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
396 retval))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
397
53913
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
398 (defun x-dnd-handle-file-name (window action string)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
399 "Prepend file:// to file names and call `x-dnd-handle-one-url'.
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
400 WINDOW is the window where the drop happened.
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
401 STRING is the file names as a string, separated by nulls."
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
402 (let ((uri-list (split-string string "[\0\r\n]" t))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
403 retval)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
404 (dolist (bf uri-list)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
405 ;; If one URL is handeled, treat as if the whole drop succeeded.
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
406 (let* ((file-uri (concat "file://" bf))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
407 (did-action (x-dnd-handle-one-url window action file-uri)))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
408 (when did-action (setq retval did-action))))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
409 retval))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
410
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
411
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
412 (defun x-dnd-choose-type (types &optional known-types)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
413 "Choose which type we want to receive for the drop.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
414 TYPES are the types the source of the drop offers, a vector of type names
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
415 as strings or symbols. Select among the types in `x-dnd-known-types' or
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
416 KNOWN-TYPES if given, and return that type name.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
417 If no suitable type is found, return nil."
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
418 (let* ((known-list (or known-types x-dnd-known-types))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
419 (first-known-type (car known-list))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
420 (types-array types)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
421 (found (when first-known-type
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
422 (catch 'done
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
423 (dotimes (i (length types-array))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
424 (let* ((type (aref types-array i))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
425 (typename (if (symbolp type)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
426 (symbol-name type) type)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
427 (when (equal first-known-type typename)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
428 (throw 'done first-known-type))))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
429 nil))))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
430
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
431 (if (and (not found) (cdr known-list))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
432 (x-dnd-choose-type types (cdr known-list))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
433 found)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
434
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
435 (defun x-dnd-drop-data (event frame window data type)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
436 "Drop one data item onto a frame.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
437 EVENT is the client message for the drop, FRAME is the frame the drop occurred
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
438 on. WINDOW is the window of FRAME where the drop happened. DATA is the data
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
439 received from the source, and type is the type for DATA, see
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
440 `x-dnd-types-alist').
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
441
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
442 Returns the action used (move, copy, link, private) if drop was successful,
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
443 nil if not."
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
444 (let* ((type-info (assoc type x-dnd-types-alist))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
445 (handler (cdr type-info))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
446 (state (x-dnd-get-state-for-frame frame))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
447 (action (aref state 5))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
448 (w (posn-window (event-start event))))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
449 (when handler
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
450 (if (and (windowp w) (window-live-p w))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
451 ;; If dropping in a window, open files in that window rather
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
452 ;; than in a new widow.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
453 (let ((x-dnd-open-file-other-window nil))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
454 (goto-char (posn-point (event-start event)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
455 (funcall handler window action data))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
456 (let ((x-dnd-open-file-other-window t)) ;; Dropping on non-window.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
457 (select-frame frame)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
458 (funcall handler window action data))))))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
459
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
460 (defun x-dnd-handle-drag-n-drop-event (event)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
461 "Receive drag and drop events (X client messages).
53949
7edbce1dd20a * x-dnd.el: Mention support for Motif in commentary.
Jan Djärv <jan.h.d@swipnet.se>
parents: 53913
diff changeset
462 Currently XDND, Motif and old KDE 1.x protocols are recognized."
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
463 (interactive "e")
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
464 (let* ((client-message (car (cdr (cdr event))))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
465 (window (posn-window (event-start event)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
466 (message-atom (aref client-message 0))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
467 (frame (aref client-message 1))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
468 (format (aref client-message 2))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
469 (data (aref client-message 3)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
470
53913
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
471 (cond ((equal "DndProtocol" message-atom) ; Old KDE 1.x.
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
472 (x-dnd-handle-old-kde event frame window message-atom format data))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
473
53913
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
474 ((equal "_MOTIF_DRAG_AND_DROP_MESSAGE" message-atom) ; Motif
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
475 (x-dnd-handle-motif event frame window message-atom format data))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
476
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
477 ((and (> (length message-atom) 4) ; XDND protocol.
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
478 (equal "Xdnd" (substring message-atom 0 4)))
53913
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
479 (x-dnd-handle-xdnd event frame window message-atom format data)))))
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
480
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
481
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
482 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
483 ;;; Old KDE protocol. Only dropping of files.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
484
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
485 (defun x-dnd-handle-old-kde (event frame window message format data)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
486 "Open the files in a KDE 1.x drop."
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
487 (let ((values (x-window-property "DndSelection" frame nil 0 t)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
488 (x-dnd-handle-uri-list window 'private
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
489 (replace-regexp-in-string "\0$" "" values))))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
490 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
491
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
492
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
493
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
494 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
495 ;;; XDND protocol.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
496
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
497 (defvar x-dnd-xdnd-to-action
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
498 '(("XdndActionPrivate" . private)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
499 ("XdndActionCopy" . copy)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
500 ("XdndActionMove" . move)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
501 ("XdndActionLink" . link)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
502 ("XdndActionAsk" . ask))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
503 "Mapping from XDND action types to lisp symbols.")
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
504
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
505 (defun x-dnd-init-xdnd-for-frame (frame)
53913
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
506 "Set the XdndAware property for FRAME to indicate that we do XDND."
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
507 (x-change-window-property "XdndAware"
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
508 '(5) ;; The version of XDND we support.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
509 frame "ATOM" 32 t))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
510
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
511 (defun x-dnd-get-drop-width-height (frame w accept)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
512 "Return the widht/height to be sent in a XDndStatus message.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
513 FRAME is the frame and W is the window where the drop happened.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
514 If ACCEPT is nil return 0 (empty rectangle),
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
515 otherwise if W is a window, return its widht/height,
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
516 otherwise return the frame width/height."
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
517 (if accept
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
518 (if (windowp w) ;; w is not a window if dropping on the menu bar,
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
519 ;; scroll bar or tool bar.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
520 (let ((edges (window-inside-pixel-edges w)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
521 (cons
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
522 (- (nth 2 edges) (nth 0 edges)) ;; right - left
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
523 (- (nth 3 edges) (nth 1 edges)))) ;; bottom - top
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
524 (cons (frame-pixel-width frame)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
525 (frame-pixel-height frame)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
526 0))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
527
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
528 (defun x-dnd-get-drop-x-y (frame w)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
529 "Return the x/y coordinates to be sent in a XDndStatus message.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
530 Coordinates are required to be absolute.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
531 FRAME is the frame and W is the window where the drop happened.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
532 If W is a window, return its absolute corrdinates,
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
533 otherwise return the frame coordinates."
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
534 (let* ((frame-left (frame-parameter frame 'left))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
535 ;; If the frame is outside the display, frame-left looks like
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
536 ;; '(0 -16). Extract the -16.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
537 (frame-real-left (if (consp frame-left) (car (cdr frame-left))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
538 frame-left))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
539 (frame-top (frame-parameter frame 'top))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
540 (frame-real-top (if (consp frame-top) (car (cdr frame-top))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
541 frame-top)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
542 (if (windowp w)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
543 (let ((edges (window-inside-pixel-edges w)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
544 (cons
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
545 (+ frame-real-left (nth 0 edges))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
546 (+ frame-real-top (nth 1 edges))))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
547 (cons frame-real-left frame-real-top))))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
548
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
549 (defun x-dnd-handle-xdnd (event frame window message format data)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
550 "Receive one XDND event (client message) and send the appropriate reply.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
551 EVENT is the client message. FRAME is where the mouse is now.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
552 WINDOW is the window within FRAME where the mouse is now.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
553 FORMAT is 32 (not used). MESSAGE is the data part of an XClientMessageEvent."
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
554 (cond ((equal "XdndEnter" message)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
555 (let ((version (ash (car (aref data 1)) -8))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
556 (more-than-3 (cdr (aref data 1)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
557 (dnd-source (aref data 0)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
558 (x-dnd-save-state
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
559 window nil nil
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
560 (if (> more-than-3 0)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
561 (x-window-property "XdndTypeList"
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
562 frame "AnyPropertyType"
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
563 dnd-source nil t)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
564 (vector (x-get-atom-name (aref data 2))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
565 (x-get-atom-name (aref data 3))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
566 (x-get-atom-name (aref data 4)))))))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
567
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
568 ((equal "XdndPosition" message)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
569 (let* ((x (car (aref data 2)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
570 (y (cdr (aref data 2)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
571 (action (x-get-atom-name (aref data 4)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
572 (dnd-source (aref data 0))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
573 (dnd-time (aref data 3))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
574 (action-type (x-dnd-maybe-call-test-function
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
575 window
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
576 (cdr (assoc action x-dnd-xdnd-to-action))))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
577 (reply-action (car (rassoc (car action-type)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
578 x-dnd-xdnd-to-action)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
579 (accept ;; 1 = accept, 0 = reject
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
580 (if (and reply-action action-type) 1 0))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
581 (list-to-send
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
582 (list (string-to-number
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
583 (frame-parameter frame 'outer-window-id))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
584 accept ;; 1 = Accept, 0 = reject.
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
585 (x-dnd-get-drop-x-y frame window)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
586 (x-dnd-get-drop-width-height
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
587 frame window (eq accept 1))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
588 (or reply-action 0)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
589 )))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
590 (x-send-client-message
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
591 frame dnd-source frame "XdndStatus" 32 list-to-send)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
592 ))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
593
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
594 ((equal "XdndLeave" message)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
595 (x-dnd-forget-drop window))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
596
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
597 ((equal "XdndDrop" message)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
598 (if (windowp window) (select-window window))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
599 (let* ((dnd-source (aref data 0))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
600 (value (and (x-dnd-current-type window)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
601 (x-get-selection-internal
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
602 'XdndSelection
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
603 (intern (x-dnd-current-type window)))))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
604 success action ret-action)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
605
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
606 (setq action (if value
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
607 (condition-case info
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
608 (x-dnd-drop-data event frame window value
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
609 (x-dnd-current-type window))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
610 (error
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
611 (message "Error: %s" info)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
612 nil))))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
613
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
614 (setq success (if action 1 0))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
615 (setq ret-action
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
616 (if (eq success 1)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
617 (or (car (rassoc action x-dnd-xdnd-to-action))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
618 "XdndActionPrivate")
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
619 0))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
620
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
621 (x-send-client-message
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
622 frame dnd-source frame "XdndFinished" 32
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
623 (list (string-to-number (frame-parameter frame 'outer-window-id))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
624 success ;; 1 = Success, 0 = Error
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
625 (if success "XdndActionPrivate" 0)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
626 ))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
627 (x-dnd-forget-drop window)))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
628
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
629 (t (error "Unknown XDND message %s %s" message data))))
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
630
53913
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
631 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
632 ;;; Motif protocol.
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
633
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
634 (defun x-dnd-init-motif-for-frame (frame)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
635 "Set _MOTIF_DRAG_RECEIVER_INFO for FRAME to indicate that we do Motif DND."
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
636 (x-change-window-property "_MOTIF_DRAG_RECEIVER_INFO"
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
637 (list
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
638 (byteorder)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
639 0 ; The Motif DND version.
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
640 5 ; We want drag dynamic.
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
641 0 0 0 0 0 0 0
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
642 0 0 0 0 0 0) ; Property must be 16 bytes.
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
643 frame "_MOTIF_DRAG_RECEIVER_INFO" 8 t))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
644
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
645 (defun x-dnd-get-motif-value (data offset size byteorder)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
646 (cond ((eq size 2)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
647 (if (eq byteorder ?l)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
648 (+ (ash (aref data (1+ offset)) 8)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
649 (aref data offset))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
650 (+ (ash (aref data offset) 8)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
651 (aref data (1+ offset)))))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
652
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
653 ((eq size 4)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
654 (if (eq byteorder ?l)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
655 (cons (+ (ash (aref data (+ 3 offset)) 8)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
656 (aref data (+ 2 offset)))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
657 (+ (ash (aref data (1+ offset)) 8)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
658 (aref data offset)))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
659 (cons (+ (ash (aref data offset) 8)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
660 (aref data (1+ offset)))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
661 (+ (ash (aref data (+ 2 offset)) 8)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
662 (aref data (+ 3 offset))))))))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
663
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
664 (defun x-dnd-motif-value-to-list (value size byteorder)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
665 (let ((bytes (cond ((eq size 2)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
666 (list (logand (lsh value -8) ?\xff)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
667 (logand value ?\xff)))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
668
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
669 ((eq size 4)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
670 (if (consp value)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
671 (list (logand (lsh (car value) -8) ?\xff)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
672 (logand (car value) ?\xff)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
673 (logand (lsh (cdr value) -8) ?\xff)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
674 (logand (cdr value) ?\xff))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
675 (list (logand (lsh value -24) ?\xff)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
676 (logand (lsh value -16) ?\xff)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
677 (logand (lsh value -8) ?\xff)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
678 (logand value ?\xff)))))))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
679 (if (eq byteorder ?l)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
680 (reverse bytes)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
681 bytes)))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
682
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
683
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
684 (defvar x-dnd-motif-message-types
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
685 '((0 . XmTOP_LEVEL_ENTER)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
686 (1 . XmTOP_LEVEL_LEAVE)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
687 (2 . XmDRAG_MOTION)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
688 (3 . XmDROP_SITE_ENTER)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
689 (4 . XmDROP_SITE_LEAVE)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
690 (5 . XmDROP_START)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
691 (6 . XmDROP_FINISH)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
692 (7 . XmDRAG_DROP_FINISH)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
693 (8 . XmOPERATION_CHANGED))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
694 "Mapping from numbers to Motif DND message types.")
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
695
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
696 (defvar x-dnd-motif-to-action
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
697 '((1 . move)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
698 (2 . copy)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
699 (3 . link) ; Both 3 and 4 has been seen as link.
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
700 (4 . link)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
701 (2 . private)) ; Motif does not have private, so use copy for private.
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
702 "Mapping from number to operation for Motif DND.")
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
703
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
704 (defun x-dnd-handle-motif (event frame window message-atom format data)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
705 (let* ((message-type (cdr (assoc (aref data 0) x-dnd-motif-message-types)))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
706 (source-byteorder (aref data 1))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
707 (my-byteorder (byteorder))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
708 (source-flags (x-dnd-get-motif-value data 2 2 source-byteorder))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
709 (source-action (cdr (assoc (logand ?\xF source-flags)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
710 x-dnd-motif-to-action))))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
711
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
712 (cond ((eq message-type 'XmTOP_LEVEL_ENTER)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
713 (let* ((dnd-source (x-dnd-get-motif-value
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
714 data 8 4 source-byteorder))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
715 (selection-atom (x-dnd-get-motif-value
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
716 data 12 4 source-byteorder))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
717 (atom-name (x-get-atom-name selection-atom))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
718 (types (when atom-name
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
719 (x-get-selection-internal (intern atom-name)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
720 'TARGETS))))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
721 (x-dnd-forget-drop frame)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
722 (when types (x-dnd-save-state window nil nil
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
723 types
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
724 dnd-source))))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
725
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
726 ;; Can not forget drop here, LEAVE comes before DROP_START and
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
727 ;; we need the state in DROP_START.
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
728 ((eq message-type 'XmTOP_LEVEL_LEAVE)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
729 nil)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
730
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
731 ((eq message-type 'XmDRAG_MOTION)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
732 (let* ((state (x-dnd-get-state-for-frame frame))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
733 (timestamp (x-dnd-motif-value-to-list
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
734 (x-dnd-get-motif-value data 4 4
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
735 source-byteorder)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
736 4 my-byteorder))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
737 (x (x-dnd-motif-value-to-list
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
738 (x-dnd-get-motif-value data 8 2 source-byteorder)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
739 2 my-byteorder))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
740 (y (x-dnd-motif-value-to-list
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
741 (x-dnd-get-motif-value data 10 2 source-byteorder)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
742 2 my-byteorder))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
743 (dnd-source (aref state 6))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
744 (first-move (not (aref state 3)))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
745 (action-type (x-dnd-maybe-call-test-function
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
746 window
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
747 source-action))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
748 (reply-action (car (rassoc (car action-type)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
749 x-dnd-motif-to-action)))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
750 (reply-flags
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
751 (x-dnd-motif-value-to-list
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
752 (if reply-action
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
753 (+ reply-action
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
754 ?\x30 ; 30: valid drop site
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
755 ?\x700) ; 700: can do copy, move or link
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
756 ?\x30) ; 30: drop site, but noop.
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
757 2 my-byteorder))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
758 (reply (append
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
759 (list
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
760 (+ ?\x80 ; 0x80 indicates a reply.
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
761 (if first-move
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
762 3 ; First time, reply is SITE_ENTER.
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
763 2)) ; Not first time, reply is DRAG_MOTION.
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
764 my-byteorder)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
765 reply-flags
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
766 timestamp
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
767 x
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
768 y)))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
769 (x-send-client-message frame
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
770 dnd-source
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
771 frame
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
772 "_MOTIF_DRAG_AND_DROP_MESSAGE"
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
773 8
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
774 reply)))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
775
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
776 ((eq message-type 'XmOPERATION_CHANGED)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
777 (let* ((state (x-dnd-get-state-for-frame frame))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
778 (timestamp (x-dnd-motif-value-to-list
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
779 (x-dnd-get-motif-value data 4 4 source-byteorder)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
780 4 my-byteorder))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
781 (dnd-source (aref state 6))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
782 (action-type (x-dnd-maybe-call-test-function
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
783 window
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
784 source-action))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
785 (reply-action (car (rassoc (car action-type)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
786 x-dnd-motif-to-action)))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
787 (reply-flags
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
788 (x-dnd-motif-value-to-list
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
789 (if reply-action
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
790 (+ reply-action
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
791 ?\x30 ; 30: valid drop site
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
792 ?\x700) ; 700: can do copy, move or link
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
793 ?\x30) ; 30: drop site, but noop
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
794 2 my-byteorder))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
795 (reply (append
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
796 (list
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
797 (+ ?\x80 ; 0x80 indicates a reply.
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
798 8) ; 8 is OPERATION_CHANGED
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
799 my-byteorder)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
800 reply-flags
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
801 timestamp)))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
802 (x-send-client-message frame
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
803 dnd-source
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
804 frame
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
805 "_MOTIF_DRAG_AND_DROP_MESSAGE"
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
806 8
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
807 reply)))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
808
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
809 ((eq message-type 'XmDROP_START)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
810 (let* ((x (x-dnd-motif-value-to-list
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
811 (x-dnd-get-motif-value data 8 2 source-byteorder)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
812 2 my-byteorder))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
813 (y (x-dnd-motif-value-to-list
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
814 (x-dnd-get-motif-value data 10 2 source-byteorder)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
815 2 my-byteorder))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
816 (selection-atom (x-dnd-get-motif-value
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
817 data 12 4 source-byteorder))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
818 (atom-name (x-get-atom-name selection-atom))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
819 (dnd-source (x-dnd-get-motif-value
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
820 data 16 4 source-byteorder))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
821 (action-type (x-dnd-maybe-call-test-function
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
822 window
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
823 source-action))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
824 (reply-action (car (rassoc (car action-type)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
825 x-dnd-motif-to-action)))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
826 (reply-flags
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
827 (x-dnd-motif-value-to-list
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
828 (if reply-action
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
829 (+ reply-action
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
830 ?\x30 ; 30: valid drop site
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
831 ?\x700) ; 700: can do copy, move or link
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
832 (+ ?\x30 ; 30: drop site, but noop.
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
833 ?\x200)) ; 200: drop cancel.
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
834 2 my-byteorder))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
835 (reply (append
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
836 (list
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
837 (+ ?\x80 ; 0x80 indicates a reply.
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
838 5) ; DROP_START.
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
839 my-byteorder)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
840 reply-flags
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
841 x
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
842 y))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
843 (timestamp (x-dnd-get-motif-value
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
844 data 4 4 source-byteorder))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
845 action)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
846
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
847 (x-send-client-message frame
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
848 dnd-source
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
849 frame
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
850 "_MOTIF_DRAG_AND_DROP_MESSAGE"
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
851 8
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
852 reply)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
853 (setq action
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
854 (when (and reply-action atom-name)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
855 (let* ((value (x-get-selection-internal
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
856 (intern atom-name)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
857 (intern (x-dnd-current-type window)))))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
858 (when value
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
859 (condition-case info
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
860 (x-dnd-drop-data event frame window value
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
861 (x-dnd-current-type window))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
862 (error
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
863 (message "Error: %s" info)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
864 nil))))))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
865 (x-get-selection-internal
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
866 (intern atom-name)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
867 (if action 'XmTRANSFER_SUCCESS 'XmTRANSFER_FAILURE)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
868 timestamp)
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
869 (x-dnd-forget-drop frame)))
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
870
56852
4504840779eb * x-dnd.el (x-dnd-protocol-alist): Document update.
Jan Djärv <jan.h.d@swipnet.se>
parents: 54986
diff changeset
871 (t (error "Unknown Motif DND message %s %s" message-atom data)))))
53913
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
872
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
873
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
874 ;;;
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
875
e83b3b3941cf x-dnd.el: Add COMPOUND_TEXT, handle FILE_NAME correctly, add Motif (CDE)
Jan Djärv <jan.h.d@swipnet.se>
parents: 53823
diff changeset
876
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
877 (provide 'x-dnd)
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
878
53797
1f2fa74fb0aa Resolve CVS conflicts
Miles Bader <miles@gnu.org>
parents: 53796
diff changeset
879 ;;; arch-tag: b621fb7e-50da-4323-850b-5fc71ae64621
53789
7efe8089eadf * x-dnd.el: New file for drag and drop.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
880 ;;; x-dnd.el ends here