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 A drop generates a extended misc-user-event, as defined in events.[ch].
+ − 30 This event contains the same as a eval and a button event.
+ − 31 The function of a drop is set to 'dragdrop-drop-dispatch' which will be
+ − 32 defined in ../lisp/dragdrop.el.
+ − 33 The object of the misc-user-event has the following format:
+ − 34 ( TYPE . DATA )
3025
+ − 35 TYPE is one of `dragdrop-MIME' and `dragdrop-URL'
+ − 36 DATA - if TYPE is `dragdrop-URL', DATA is a list of valid URL strings. It
428
+ − 37 is always a list, also if only one URL string is within it.
3025
+ − 38 - if TYPE is `dragdrop-MIME', DATA is a list of MIME elements.
428
+ − 39 Each can be a string or a list.
+ − 40 if it is a string it is the pure MIME data complete with header
+ − 41 and body.
+ − 42 if it is a list it should look like
+ − 43 ( MIME-TYPE MIME-ENCODING MIME-DATA )
+ − 44 MIME-TYPE list of type and key.value conses. Same as in tm-view
+ − 45 MIME-ENC the same (a string in this case)
+ − 46 MIME-DATA is a string
+ − 47 */
+ − 48
+ − 49 #include <config.h>
+ − 50 #include "lisp.h"
+ − 51 #include "dragdrop.h"
+ − 52
+ − 53 /* The supported protocol list */
+ − 54 Lisp_Object Vdragdrop_protocols;
+ − 55
+ − 56 /* Drag'n'Drop data types known by XEmacs */
+ − 57 Lisp_Object Qdragdrop_MIME;
+ − 58 Lisp_Object Qdragdrop_URL;
+ − 59
+ − 60 /* External defined functions to handle Drag'n'Drop */
+ − 61 Lisp_Object Qdragdrop_drop_dispatch;
+ − 62
+ − 63 /* from wget -- thanxx Hrvoje */
+ − 64 /* A list of unsafe characters for encoding, as per RFC1738. '@' and
+ − 65 ':' (not listed in RFC) were added because of user/password
+ − 66 encoding, and \033 for safe printing. */
+ − 67
+ − 68 #define URL_UNSAFE " <>\"#%{}|\\^~[]`@:\033"
+ − 69
+ − 70 /* HEX digit -> ASCII char */
+ − 71 #define HEXD2ASC(x) (((x) < 10) ? ((x) + '0') : ((x) - 10 + 'A'))
+ − 72
+ − 73 /* Encodes the unsafe characters (listed in URL_UNSAFE) in a given
+ − 74 string, returning a malloc-ed %XX encoded string.
+ − 75 if method is != NULL it is prepended to the string. */
2367
+ − 76 Ibyte *
+ − 77 dnd_url_hexify_string (const Ibyte *s, const Ibyte *m)
428
+ − 78 {
2367
+ − 79 const Ibyte *b;
+ − 80 Ibyte *p, *res;
+ − 81 Bytecount i;
428
+ − 82
+ − 83 b = s;
+ − 84 for (i = 0; *s; s++, i++)
+ − 85 if (strchr (URL_UNSAFE, *s))
+ − 86 i += 2; /* Two more characters (hex digits) */
+ − 87 if (m)
+ − 88 {
2367
+ − 89 res = xnew_ibytes (i + ITEXT_ZTERM_SIZE + qxestrlen (m));
+ − 90 qxestrcpy (res, m);
+ − 91 p = res + qxestrlen (m);
428
+ − 92 }
+ − 93 else
+ − 94 {
2367
+ − 95 res = xnew_ibytes (i + ITEXT_ZTERM_SIZE);
428
+ − 96 p = res;
+ − 97 }
+ − 98 for (s = b; *s; s++)
+ − 99 if (strchr (URL_UNSAFE, *s))
+ − 100 {
2367
+ − 101 const Ibyte c = *s;
428
+ − 102 *p++ = '%';
+ − 103 *p++ = HEXD2ASC (c >> 4);
+ − 104 *p++ = HEXD2ASC (c & 0xf);
+ − 105 }
+ − 106 else
+ − 107 *p++ = *s;
+ − 108 *p = '\0';
+ − 109 return res;
+ − 110 }
+ − 111
+ − 112 void
+ − 113 syms_of_dragdrop (void)
+ − 114 {
563
+ − 115 DEFSYMBOL (Qdragdrop_MIME);
+ − 116 DEFSYMBOL (Qdragdrop_URL);
+ − 117 DEFSYMBOL (Qdragdrop_drop_dispatch);
428
+ − 118 }
+ − 119
+ − 120 void
+ − 121 vars_of_dragdrop (void)
+ − 122 {
+ − 123 Fprovide (intern ("dragdrop-api"));
+ − 124
+ − 125 DEFVAR_CONST_LISP ("dragdrop-protocols", &Vdragdrop_protocols /*
+ − 126 A list of supported Drag'n'drop protocols.
+ − 127 Each element is the feature symbol of the protocol.
+ − 128 */ );
+ − 129
+ − 130 Vdragdrop_protocols = Qnil;
+ − 131
+ − 132 #ifdef HAVE_MS_WINDOWS
2367
+ − 133 Vdragdrop_protocols = Fcons (Qmswindows, Vdragdrop_protocols);
428
+ − 134 #endif
+ − 135 #ifdef HAVE_CDE
2367
+ − 136 Vdragdrop_protocols = Fcons (intern ("cde"), Vdragdrop_protocols);
428
+ − 137 #endif
462
+ − 138 #ifdef HAVE_GTK
2367
+ − 139 Vdragdrop_protocols = Fcons (Qgtk, Vdragdrop_protocols);
462
+ − 140 #endif
428
+ − 141 }