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