428
|
1 /* Drag'n'Drop definitions
|
|
2 created 03-may-98 by Oliver Graf <ograf@fga.de>
|
|
3 Copyright (C) 1998 Oliver Graf <ograf@fga.de>
|
2367
|
4 Copyright (C) 2004 Ben Wing.
|
428
|
5
|
|
6 This file is part of XEmacs.
|
|
7
|
|
8 XEmacs is free software; you can redistribute it and/or modify it
|
|
9 under the terms of the GNU General Public License as published by the
|
|
10 Free Software Foundation; either version 2, or (at your option) any
|
|
11 later version.
|
|
12
|
|
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
16 for more details.
|
|
17
|
|
18 You should have received a copy of the GNU General Public License
|
|
19 along with XEmacs; see the file COPYING. If not, write to
|
|
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
21 Boston, MA 02111-1307, USA. */
|
|
22
|
|
23 /* Synched up with: Not in FSF. */
|
|
24
|
|
25 /* This file should be Mule-ized. */
|
|
26
|
|
27 /* A short introduction to the new Drag'n'Drop Model:
|
|
28
|
|
29 Currently only drops from OffiX are implemented.
|
|
30
|
|
31 A drop generates a extended misc-user-event, as defined in events.[ch].
|
|
32 This event contains the same as a eval and a button event.
|
|
33 The function of a drop is set to 'dragdrop-drop-dispatch' which will be
|
|
34 defined in ../lisp/dragdrop.el.
|
|
35 The object of the misc-user-event has the following format:
|
|
36 ( TYPE . DATA )
|
|
37 TYPE is one of 'dragdrop-MIME and 'dragdrop-URL
|
|
38 DATA - if TYPE is 'dragdrop-URL, DATA is a list of valid URL strings. It
|
|
39 is always a list, also if only one URL string is within it.
|
|
40 - if TYPE is 'dragdrop-MIME, DATA is a list of MIME elements.
|
|
41 Each can be a string or a list.
|
|
42 if it is a string it is the pure MIME data complete with header
|
|
43 and body.
|
|
44 if it is a list it should look like
|
|
45 ( MIME-TYPE MIME-ENCODING MIME-DATA )
|
|
46 MIME-TYPE list of type and key.value conses. Same as in tm-view
|
|
47 MIME-ENC the same (a string in this case)
|
|
48 MIME-DATA is a string
|
|
49 */
|
|
50
|
|
51 #include <config.h>
|
|
52 #include "lisp.h"
|
|
53 #include "dragdrop.h"
|
|
54
|
|
55 /* The supported protocol list */
|
|
56 Lisp_Object Vdragdrop_protocols;
|
|
57
|
|
58 /* Drag'n'Drop data types known by XEmacs */
|
|
59 Lisp_Object Qdragdrop_MIME;
|
|
60 Lisp_Object Qdragdrop_URL;
|
|
61
|
|
62 /* External defined functions to handle Drag'n'Drop */
|
|
63 Lisp_Object Qdragdrop_drop_dispatch;
|
|
64
|
|
65 /* from wget -- thanxx Hrvoje */
|
|
66 /* A list of unsafe characters for encoding, as per RFC1738. '@' and
|
|
67 ':' (not listed in RFC) were added because of user/password
|
|
68 encoding, and \033 for safe printing. */
|
|
69
|
|
70 #define URL_UNSAFE " <>\"#%{}|\\^~[]`@:\033"
|
|
71
|
|
72 /* HEX digit -> ASCII char */
|
|
73 #define HEXD2ASC(x) (((x) < 10) ? ((x) + '0') : ((x) - 10 + 'A'))
|
|
74
|
|
75 /* Encodes the unsafe characters (listed in URL_UNSAFE) in a given
|
|
76 string, returning a malloc-ed %XX encoded string.
|
|
77 if method is != NULL it is prepended to the string. */
|
2367
|
78 Ibyte *
|
|
79 dnd_url_hexify_string (const Ibyte *s, const Ibyte *m)
|
428
|
80 {
|
2367
|
81 const Ibyte *b;
|
|
82 Ibyte *p, *res;
|
|
83 Bytecount i;
|
428
|
84
|
|
85 b = s;
|
|
86 for (i = 0; *s; s++, i++)
|
|
87 if (strchr (URL_UNSAFE, *s))
|
|
88 i += 2; /* Two more characters (hex digits) */
|
|
89 if (m)
|
|
90 {
|
2367
|
91 res = xnew_ibytes (i + ITEXT_ZTERM_SIZE + qxestrlen (m));
|
|
92 qxestrcpy (res, m);
|
|
93 p = res + qxestrlen (m);
|
428
|
94 }
|
|
95 else
|
|
96 {
|
2367
|
97 res = xnew_ibytes (i + ITEXT_ZTERM_SIZE);
|
428
|
98 p = res;
|
|
99 }
|
|
100 for (s = b; *s; s++)
|
|
101 if (strchr (URL_UNSAFE, *s))
|
|
102 {
|
2367
|
103 const Ibyte c = *s;
|
428
|
104 *p++ = '%';
|
|
105 *p++ = HEXD2ASC (c >> 4);
|
|
106 *p++ = HEXD2ASC (c & 0xf);
|
|
107 }
|
|
108 else
|
|
109 *p++ = *s;
|
|
110 *p = '\0';
|
|
111 return res;
|
|
112 }
|
|
113
|
|
114 void
|
|
115 syms_of_dragdrop (void)
|
|
116 {
|
563
|
117 DEFSYMBOL (Qdragdrop_MIME);
|
|
118 DEFSYMBOL (Qdragdrop_URL);
|
|
119 DEFSYMBOL (Qdragdrop_drop_dispatch);
|
428
|
120 }
|
|
121
|
|
122 void
|
|
123 vars_of_dragdrop (void)
|
|
124 {
|
|
125 Fprovide (intern ("dragdrop-api"));
|
|
126
|
|
127 DEFVAR_CONST_LISP ("dragdrop-protocols", &Vdragdrop_protocols /*
|
|
128 A list of supported Drag'n'drop protocols.
|
|
129 Each element is the feature symbol of the protocol.
|
|
130 */ );
|
|
131
|
|
132 Vdragdrop_protocols = Qnil;
|
|
133
|
|
134 #ifdef HAVE_MS_WINDOWS
|
2367
|
135 Vdragdrop_protocols = Fcons (Qmswindows, Vdragdrop_protocols);
|
428
|
136 #endif
|
|
137 #ifdef HAVE_CDE
|
2367
|
138 Vdragdrop_protocols = Fcons (intern ("cde"), Vdragdrop_protocols);
|
428
|
139 #endif
|
|
140 #ifdef HAVE_OFFIX_DND
|
2367
|
141 Vdragdrop_protocols = Fcons (intern ("offix"), Vdragdrop_protocols);
|
428
|
142 #endif
|
462
|
143 #ifdef HAVE_GTK
|
2367
|
144 Vdragdrop_protocols = Fcons (Qgtk, Vdragdrop_protocols);
|
462
|
145 #endif
|
428
|
146 }
|