annotate src/select-msw.c @ 221:6c0ae1f9357f r20-4b9

Import from CVS: tag r20-4b9
author cvs
date Mon, 13 Aug 2007 10:10:02 +0200
parents
children 557eaa0339bf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
221
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
1 /* mswindows selection processing for XEmacs
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
2 Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
3
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
4 This file is part of XEmacs.
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
5
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
9 later version.
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
10
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
14 for more details.
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
15
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
20
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
21 /* Synched up with: Not synched with FSF. */
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
22
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
23 /* Authorship:
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
24
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
25 Written by Kevin Gallo for FSF Emacs.
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
26 Rewritten for mswindows by Jonathan Harris, December 1997 for 20.4.
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
27 */
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
28
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
29
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
30 #include <config.h>
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
31 #include "lisp.h"
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
32
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
33 #include "console-msw.h"
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
34
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
35 DEFUN ("mswindows-set-clipboard", Fmswindows_set_clipboard, 1, 1, 0, /*
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
36 Copy STRING to the mswindows clipboard.
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
37 */
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
38 (string))
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
39 {
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
40 int rawsize, size, i;
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
41 unsigned char *src, *dst, *next;
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
42 HGLOBAL h = NULL;
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
43
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
44 CHECK_STRING (string, 0);
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
45
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
46 /* Calculate size with LFs converted to CRLFs because
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
47 * CF_TEXT format uses CRLF delimited ASCIIZ */
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
48 src = XSTRING_DATA (string);
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
49 size = rawsize = XSTRING_LENGTH (string) + 1;
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
50 for (i=0; i<rawsize; i++)
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
51 if (src[i] == '\n')
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
52 size++;
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
53
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
54 if (!OpenClipboard (NULL))
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
55 return Qnil;
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
56
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
57 if (!EmptyClipboard () ||
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
58 (h = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, size)) == NULL ||
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
59 (dst = (unsigned char *) GlobalLock (h)) == NULL)
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
60 {
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
61 if (h != NULL) GlobalFree (h);
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
62 CloseClipboard ();
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
63 return Qnil;
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
64 }
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
65
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
66 /* Convert LFs to CRLFs */
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
67 do
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
68 {
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
69 /* copy next line or remaining bytes including '\0' */
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
70 next = memccpy (dst, src, '\n', rawsize);
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
71 if (next)
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
72 {
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
73 /* copied one line ending with '\n' */
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
74 int copied = next - dst;
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
75 rawsize -= copied;
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
76 src += copied;
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
77 /* insert '\r' before '\n' */
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
78 next[-1] = '\r';
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
79 next[0] = '\n';
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
80 dst = next+1;
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
81 }
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
82 }
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
83 while (next);
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
84
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
85 GlobalUnlock (h);
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
86
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
87 i = SetClipboardData (CF_TEXT, h);
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
88
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
89 CloseClipboard ();
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
90 GlobalFree (h);
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
91
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
92 return i ? Qt : Qnil;
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
93 }
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
94
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
95 DEFUN ("mswindows-get-clipboard", Fmswindows_get_clipboard, 0, 0, 0, /*
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
96 Return the contents of the mswindows clipboard.
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
97 */
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
98 ())
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
99 {
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
100 HANDLE h;
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
101 unsigned char *src, *dst, *next;
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
102 Lisp_Object ret = Qnil;
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
103
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
104 if (!OpenClipboard (NULL))
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
105 return Qnil;
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
106
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
107 if ((h = GetClipboardData (CF_TEXT)) != NULL &&
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
108 (src = (unsigned char *) GlobalLock (h)) != NULL)
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
109 {
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
110 int i;
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
111 int size, rawsize;
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
112 size = rawsize = strlen (src);
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
113
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
114 for (i=0; i<rawsize; i++)
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
115 if (src[i] == '\r' && src[i+1] == '\n')
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
116 size--;
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
117
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
118 /* Convert CRLFs to LFs */
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
119 ret = make_uninit_string (size);
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
120 dst = XSTRING_DATA (ret);
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
121 do
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
122 {
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
123 /* copy next line or remaining bytes excluding '\0' */
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
124 next = _memccpy (dst, src, '\r', rawsize);
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
125 if (next)
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
126 {
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
127 /* copied one line ending with '\r' */
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
128 int copied = next - dst;
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
129 rawsize -= copied;
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
130 src += copied;
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
131 if (*src == '\n')
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
132 dst += copied - 1; /* overwrite '\r' */
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
133 else
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
134 dst += copied;
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
135 }
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
136 }
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
137 while (next);
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
138
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
139 GlobalUnlock (h);
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
140 }
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
141
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
142 CloseClipboard ();
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
143
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
144 return ret;
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
145 }
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
146
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
147
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
148 /************************************************************************/
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
149 /* initialization */
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
150 /************************************************************************/
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
151
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
152 void
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
153 syms_of_select_mswindows (void)
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
154 {
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
155 DEFSUBR (Fmswindows_set_clipboard);
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
156 DEFSUBR (Fmswindows_get_clipboard);
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
157 }
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
158
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
159 void
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
160 vars_of_select_mswindows (void)
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
161 {
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
162 }