annotate src/select-msw.c @ 288:e11d67e05968 r21-0b42

Import from CVS: tag r21-0b42
author cvs
date Mon, 13 Aug 2007 10:35:54 +0200
parents 57709be46d1b
children 74fd4e045ea6
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.
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 249
diff changeset
26 Rewritten for mswindows by Jonathan Harris, December 1997 for 21.0.
221
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
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 221
diff changeset
44 CHECK_STRING (string);
221
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
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 231
diff changeset
87 i = (SetClipboardData (CF_TEXT, h) != NULL);
221
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' */
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
124 next = memccpy (dst, src, '\r', rawsize);
221
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
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 278
diff changeset
147 DEFUN ("mswindows-selection-exists-p", Fmswindows_selection_exists_p, 0, 0, 0, /*
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
148 Whether there is an MS-Windows selection.
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 278
diff changeset
149 */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 278
diff changeset
150 ())
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 278
diff changeset
151 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 278
diff changeset
152 return IsClipboardFormatAvailable (CF_TEXT) ? Qt : Qnil;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 278
diff changeset
153 }
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 278
diff changeset
154
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 278
diff changeset
155 DEFUN ("mswindows-delete-selection", Fmswindows_delete_selection, 0, 0, 0, /*
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
156 Remove the current MS-Windows selection from the clipboard.
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 278
diff changeset
157 */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 278
diff changeset
158 ())
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 278
diff changeset
159 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 278
diff changeset
160 return EmptyClipboard () ? Qt : Qnil;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 278
diff changeset
161 }
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 278
diff changeset
162
221
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
163
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
164 /************************************************************************/
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
165 /* initialization */
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
166 /************************************************************************/
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
167
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
168 void
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
169 syms_of_select_mswindows (void)
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
170 {
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
171 DEFSUBR (Fmswindows_set_clipboard);
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
172 DEFSUBR (Fmswindows_get_clipboard);
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 278
diff changeset
173 DEFSUBR (Fmswindows_selection_exists_p);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 278
diff changeset
174 DEFSUBR (Fmswindows_delete_selection);
221
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
175 }
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
176
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
177 void
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
178 vars_of_select_mswindows (void)
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
179 {
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
180 }