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 )
|
|
45 MIME-TYPE should have the format as required by tm-view, but
|
|
46 is a string
|
|
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 /* Drag'n'Drop data types known by XEmacs */
|
|
56 Lisp_Object Qdragdrop_MIME;
|
|
57 Lisp_Object Qdragdrop_URL;
|
|
58
|
|
59 /* External defined functions to handle Drag'n'Drop */
|
|
60 Lisp_Object Qdragdrop_drop_dispatch;
|
|
61
|
|
62 /* from wget -- thanxx Hrvoje */
|
|
63 /* A list of unsafe characters for encoding, as per RFC1738. '@' and
|
|
64 ':' (not listed in RFC) were added because of user/password
|
|
65 encoding, and \033 for safe printing. */
|
|
66
|
|
67 #define URL_UNSAFE " <>\"#%{}|\\^~[]`@:\033"
|
|
68
|
|
69 /* HEX digit -> ASCII char */
|
|
70 #define HEXD2ASC(x) (((x) < 10) ? ((x) + '0') : ((x) - 10 + 'A'))
|
|
71
|
|
72 /* Encodes the unsafe characters (listed in URL_UNSAFE) in a given
|
|
73 string, returning a malloc-ed %XX encoded string.
|
|
74 if method is != NULL it is prepended to the string. */
|
|
75 char *
|
|
76 dnd_url_hexify_string (const char *s, const char *m)
|
|
77 {
|
|
78 const char *b;
|
|
79 char *p, *res;
|
|
80 int i;
|
|
81
|
|
82 b = s;
|
|
83 for (i = 0; *s; s++, i++)
|
|
84 if (strchr (URL_UNSAFE, *s))
|
|
85 i += 2; /* Two more characters (hex digits) */
|
|
86 if (m)
|
|
87 {
|
|
88 res = (char *)xmalloc (i + 1 + strlen (m));
|
|
89 strcpy (res, m);
|
|
90 p = res + strlen (m);
|
|
91 }
|
|
92 else
|
|
93 {
|
|
94 res = (char *)xmalloc (i + 1);
|
|
95 p = res;
|
|
96 }
|
|
97 for (s = b; *s; s++)
|
|
98 if (strchr (URL_UNSAFE, *s))
|
|
99 {
|
|
100 const unsigned char c = *s;
|
|
101 *p++ = '%';
|
|
102 *p++ = HEXD2ASC (c >> 4);
|
|
103 *p++ = HEXD2ASC (c & 0xf);
|
|
104 }
|
|
105 else
|
|
106 *p++ = *s;
|
|
107 *p = '\0';
|
|
108 return res;
|
|
109 }
|
|
110
|
|
111 void
|
|
112 syms_of_dragdrop (void)
|
|
113 {
|
|
114 defsymbol (&Qdragdrop_MIME, "dragdrop-MIME");
|
|
115 defsymbol (&Qdragdrop_URL, "dragdrop-URL");
|
|
116 defsymbol (&Qdragdrop_drop_dispatch, "dragdrop-drop-dispatch");
|
|
117 }
|