16884
|
1 /* Selection processing for Emacs on the Microsoft W32 API.
|
13434
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
2 Copyright (C) 1993, 1994 Free Software Foundation.
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
3
|
14186
|
4 This file is part of GNU Emacs.
|
|
5
|
|
6 GNU Emacs is free software; you can redistribute it and/or modify
|
|
7 it under the terms of the GNU General Public License as published by
|
|
8 the Free Software Foundation; either version 2, or (at your option)
|
|
9 any later version.
|
|
10
|
|
11 GNU Emacs is distributed in the hope that it will be useful,
|
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 GNU General Public License for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with GNU Emacs; see the file COPYING. If not, write to
|
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 Boston, MA 02111-1307, USA. */
|
13434
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
20
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
21 /* Written by Kevin Gallo */
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
22
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
23 #include <config.h>
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
24 #include "lisp.h"
|
16588
|
25 #include "w32term.h" /* for all of the w32 includes */
|
13434
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
26 #include "dispextern.h" /* frame.h seems to want this */
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
27 #include "frame.h" /* Need this to get the X window of selected_frame */
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
28 #include "blockinput.h"
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
29
|
15235
|
30 Lisp_Object QCLIPBOARD;
|
|
31
|
13434
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
32 #if 0
|
16588
|
33 DEFUN ("w32-open-clipboard", Fw32_open_clipboard, Sw32_open_clipboard, 0, 1, 0,
|
13434
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
34 "This opens the clipboard with the given frame pointer.")
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
35 (frame)
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
36 Lisp_Object frame;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
37 {
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
38 BOOL ok = FALSE;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
39
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
40 if (!NILP (frame))
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
41 CHECK_LIVE_FRAME (frame, 0);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
42
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
43 BLOCK_INPUT;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
44
|
16588
|
45 ok = OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL);
|
13434
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
46
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
47 UNBLOCK_INPUT;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
48
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
49 return (ok ? frame : Qnil);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
50 }
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
51
|
16588
|
52 DEFUN ("w32-empty-clipboard", Fw32_empty_clipboard, Sw32_empty_clipboard, 0, 0, 0,
|
13434
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
53 "This empties the clipboard and assigns ownership to the window which opened the clipboard.")
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
54 ()
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
55 {
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
56 BOOL ok = FALSE;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
57
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
58 BLOCK_INPUT;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
59
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
60 ok = EmptyClipboard ();
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
61
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
62 UNBLOCK_INPUT;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
63
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
64 return (ok ? Qt : Qnil);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
65 }
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
66
|
16588
|
67 DEFUN ("w32-close-clipboard", Fw32_close_clipboard, Sw32_close_clipboard, 0, 0, 0,
|
13434
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
68 "This closes the clipboard.")
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
69 ()
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
70 {
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
71 BOOL ok = FALSE;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
72
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
73 BLOCK_INPUT;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
74
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
75 ok = CloseClipboard ();
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
76
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
77 UNBLOCK_INPUT;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
78
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
79 return (ok ? Qt : Qnil);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
80 }
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
81
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
82 #endif
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
83
|
16588
|
84 DEFUN ("w32-set-clipboard-data", Fw32_set_clipboard_data, Sw32_set_clipboard_data, 1, 2, 0,
|
13434
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
85 "This sets the clipboard data to the given text.")
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
86 (string, frame)
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
87 Lisp_Object string, frame;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
88 {
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
89 BOOL ok = TRUE;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
90 HANDLE htext;
|
15150
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
91 int nbytes;
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
92 int truelen;
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
93 unsigned char *src;
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
94 unsigned char *dst;
|
13434
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
95
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
96 CHECK_STRING (string, 0);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
97
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
98 if (!NILP (frame))
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
99 CHECK_LIVE_FRAME (frame, 0);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
100
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
101 BLOCK_INPUT;
|
15150
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
102
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
103 nbytes = XSTRING (string)->size + 1;
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
104 src = XSTRING (string)->data;
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
105
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
106 /* need to know final size after '\r' chars are inserted (the
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
107 standard CF_TEXT clipboard format uses CRLF line endings,
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
108 while Emacs uses just LF internally) */
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
109
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
110 truelen = nbytes;
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
111 dst = src;
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
112 /* avoid using strchr because it recomputes the length everytime */
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
113 while ((dst = memchr (dst, '\n', nbytes - (dst - src))) != NULL)
|
13434
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
114 {
|
15150
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
115 truelen++;
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
116 dst++;
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
117 }
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
118
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
119 if ((htext = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, truelen)) == NULL)
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
120 goto error;
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
121
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
122 if ((dst = (unsigned char *) GlobalLock (htext)) == NULL)
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
123 goto error;
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
124
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
125 /* convert to CRLF line endings expected by clipboard */
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
126 while (1)
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
127 {
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
128 unsigned char *next;
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
129 /* copy next line or remaining bytes including '\0' */
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
130 next = _memccpy (dst, src, '\n', nbytes);
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
131 if (next)
|
13434
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
132 {
|
15150
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
133 /* copied one line ending with '\n' */
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
134 int copied = next - dst;
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
135 nbytes -= copied;
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
136 src += copied;
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
137 /* insert '\r' before '\n' */
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
138 next[-1] = '\r';
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
139 next[0] = '\n';
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
140 dst = next + 1;
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
141 }
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
142 else
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
143 /* copied remaining partial line -> now finished */
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
144 break;
|
13434
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
145 }
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
146
|
15150
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
147 GlobalUnlock (htext);
|
13434
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
148
|
16588
|
149 if (!OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL))
|
13434
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
150 goto error;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
151
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
152 ok = EmptyClipboard () && SetClipboardData (CF_TEXT, htext);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
153
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
154 CloseClipboard ();
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
155
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
156 if (ok) goto done;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
157
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
158 error:
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
159
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
160 ok = FALSE;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
161 if (htext) GlobalFree (htext);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
162
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
163 done:
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
164 UNBLOCK_INPUT;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
165
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
166 return (ok ? string : Qnil);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
167 }
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
168
|
16588
|
169 DEFUN ("w32-get-clipboard-data", Fw32_get_clipboard_data, Sw32_get_clipboard_data, 0, 1, 0,
|
13434
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
170 "This gets the clipboard data in text format.")
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
171 (frame)
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
172 Lisp_Object frame;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
173 {
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
174 HANDLE htext;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
175 Lisp_Object ret = Qnil;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
176
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
177 if (!NILP (frame))
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
178 CHECK_LIVE_FRAME (frame, 0);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
179
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
180 BLOCK_INPUT;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
181
|
16588
|
182 if (!OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL))
|
13434
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
183 goto done;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
184
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
185 if ((htext = GetClipboardData (CF_TEXT)) == NULL)
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
186 goto closeclip;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
187
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
188 {
|
15150
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
189 unsigned char *src;
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
190 unsigned char *dst;
|
13434
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
191 int nbytes;
|
15150
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
192 int truelen;
|
13434
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
193
|
15150
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
194 if ((src = (unsigned char *) GlobalLock (htext)) == NULL)
|
13434
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
195 goto closeclip;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
196
|
15150
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
197 nbytes = strlen (src);
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
198
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
199 /* need to know final size after '\r' chars are removed because
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
200 we can't change the string size manually, and doing an extra
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
201 copy is silly */
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
202
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
203 truelen = nbytes;
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
204 dst = src;
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
205 /* avoid using strchr because it recomputes the length everytime */
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
206 while ((dst = memchr (dst, '\r', nbytes - (dst - src))) != NULL)
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
207 {
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
208 truelen--;
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
209 dst++;
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
210 }
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
211
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
212 ret = make_uninit_string (truelen);
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
213
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
214 /* convert CRLF line endings (the standard CF_TEXT clipboard
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
215 format) to LF endings as used internally by Emacs */
|
13434
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
216
|
15150
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
217 dst = XSTRING (ret)->data;
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
218 while (1)
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
219 {
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
220 unsigned char *next;
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
221 /* copy next line or remaining bytes excluding '\0' */
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
222 next = _memccpy (dst, src, '\r', nbytes);
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
223 if (next)
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
224 {
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
225 /* copied one line ending with '\r' */
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
226 int copied = next - dst;
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
227 nbytes -= copied;
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
228 dst += copied - 1; /* overwrite '\r' */
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
229 src += copied;
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
230 }
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
231 else
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
232 /* copied remaining partial line -> now finished */
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
233 break;
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
234 }
|
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
235
|
13434
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
236 GlobalUnlock (htext);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
237 }
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
238
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
239 closeclip:
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
240 CloseClipboard ();
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
241
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
242 done:
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
243 UNBLOCK_INPUT;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
244
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
245 return (ret);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
246 }
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
247
|
15235
|
248 /* Support checking for a clipboard selection. */
|
|
249
|
|
250 DEFUN ("x-selection-exists-p", Fx_selection_exists_p, Sx_selection_exists_p,
|
|
251 0, 1, 0,
|
|
252 "Whether there is an owner for the given X Selection.\n\
|
|
253 The arg should be the name of the selection in question, typically one of\n\
|
|
254 the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.\n\
|
|
255 \(Those are literal upper-case symbol names, since that's what X expects.)\n\
|
|
256 For convenience, the symbol nil is the same as `PRIMARY',\n\
|
|
257 and t is the same as `SECONDARY'.")
|
|
258 (selection)
|
|
259 Lisp_Object selection;
|
|
260 {
|
|
261 CHECK_SYMBOL (selection, 0);
|
|
262
|
|
263 /* Return nil for PRIMARY and SECONDARY selections; for CLIPBOARD, check
|
|
264 if the clipboard currently has valid text format contents. */
|
|
265
|
|
266 if (EQ (selection, QCLIPBOARD))
|
|
267 {
|
|
268 Lisp_Object val = Qnil;
|
|
269
|
|
270 if (OpenClipboard (NULL))
|
|
271 {
|
|
272 int format = 0;
|
|
273 while (format = EnumClipboardFormats (format))
|
|
274 if (format == CF_TEXT)
|
|
275 {
|
|
276 val = Qt;
|
|
277 break;
|
|
278 }
|
|
279 CloseClipboard ();
|
|
280 }
|
|
281 return val;
|
|
282 }
|
|
283 return Qnil;
|
|
284 }
|
|
285
|
13434
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
286 void
|
16588
|
287 syms_of_w32select ()
|
13434
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
288 {
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
289 #if 0
|
16588
|
290 defsubr (&Sw32_open_clipboard);
|
|
291 defsubr (&Sw32_empty_clipboard);
|
|
292 defsubr (&Sw32_close_clipboard);
|
13434
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
293 #endif
|
16588
|
294 defsubr (&Sw32_set_clipboard_data);
|
|
295 defsubr (&Sw32_get_clipboard_data);
|
15235
|
296 defsubr (&Sx_selection_exists_p);
|
|
297
|
|
298 QCLIPBOARD = intern ("CLIPBOARD"); staticpro (&QCLIPBOARD);
|
13434
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
299 }
|