Mercurial > emacs
annotate src/w32select.c @ 22677:a05b1e5f4389
(dos-printer): Obsolete variable deleted.
(dos-ps-printer): Likewise.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 03 Jul 1998 19:53:47 +0000 |
parents | 5d3f50b4c8d2 |
children | ef9607e709bc |
rev | line source |
---|---|
16884
36babc489b0c
Change all uses of win95, winnt, and win32
Geoff Voelker <voelker@cs.washington.edu>
parents:
16588
diff
changeset
|
1 /* Selection processing for Emacs on the Microsoft W32 API. |
13434 | 2 Copyright (C) 1993, 1994 Free Software Foundation. |
3 | |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13434
diff
changeset
|
4 This file is part of GNU Emacs. |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13434
diff
changeset
|
5 |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13434
diff
changeset
|
6 GNU Emacs is free software; you can redistribute it and/or modify |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13434
diff
changeset
|
7 it under the terms of the GNU General Public License as published by |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13434
diff
changeset
|
8 the Free Software Foundation; either version 2, or (at your option) |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13434
diff
changeset
|
9 any later version. |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13434
diff
changeset
|
10 |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13434
diff
changeset
|
11 GNU Emacs is distributed in the hope that it will be useful, |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13434
diff
changeset
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13434
diff
changeset
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13434
diff
changeset
|
14 GNU General Public License for more details. |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13434
diff
changeset
|
15 |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13434
diff
changeset
|
16 You should have received a copy of the GNU General Public License |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13434
diff
changeset
|
17 along with GNU Emacs; see the file COPYING. If not, write to |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13434
diff
changeset
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13434
diff
changeset
|
19 Boston, MA 02111-1307, USA. */ |
13434 | 20 |
21 /* Written by Kevin Gallo */ | |
22 | |
23 #include <config.h> | |
24 #include "lisp.h" | |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15235
diff
changeset
|
25 #include "w32term.h" /* for all of the w32 includes */ |
13434 | 26 #include "dispextern.h" /* frame.h seems to want this */ |
27 #include "frame.h" /* Need this to get the X window of selected_frame */ | |
28 #include "blockinput.h" | |
22545
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
29 #include "buffer.h" |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
30 #include "charset.h" |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
31 #include "coding.h" |
13434 | 32 |
15235 | 33 Lisp_Object QCLIPBOARD; |
34 | |
22545
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
35 /* Coding system for communicating with other Windows programs via the |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
36 clipboard. */ |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
37 static Lisp_Object Vclipboard_coding_system; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
38 |
13434 | 39 #if 0 |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15235
diff
changeset
|
40 DEFUN ("w32-open-clipboard", Fw32_open_clipboard, Sw32_open_clipboard, 0, 1, 0, |
13434 | 41 "This opens the clipboard with the given frame pointer.") |
42 (frame) | |
43 Lisp_Object frame; | |
44 { | |
45 BOOL ok = FALSE; | |
46 | |
47 if (!NILP (frame)) | |
48 CHECK_LIVE_FRAME (frame, 0); | |
49 | |
50 BLOCK_INPUT; | |
51 | |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15235
diff
changeset
|
52 ok = OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL); |
13434 | 53 |
54 UNBLOCK_INPUT; | |
55 | |
56 return (ok ? frame : Qnil); | |
57 } | |
58 | |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15235
diff
changeset
|
59 DEFUN ("w32-empty-clipboard", Fw32_empty_clipboard, Sw32_empty_clipboard, 0, 0, 0, |
13434 | 60 "This empties the clipboard and assigns ownership to the window which opened the clipboard.") |
61 () | |
62 { | |
63 BOOL ok = FALSE; | |
64 | |
65 BLOCK_INPUT; | |
66 | |
67 ok = EmptyClipboard (); | |
68 | |
69 UNBLOCK_INPUT; | |
70 | |
71 return (ok ? Qt : Qnil); | |
72 } | |
73 | |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15235
diff
changeset
|
74 DEFUN ("w32-close-clipboard", Fw32_close_clipboard, Sw32_close_clipboard, 0, 0, 0, |
13434 | 75 "This closes the clipboard.") |
76 () | |
77 { | |
78 BOOL ok = FALSE; | |
79 | |
80 BLOCK_INPUT; | |
81 | |
82 ok = CloseClipboard (); | |
83 | |
84 UNBLOCK_INPUT; | |
85 | |
86 return (ok ? Qt : Qnil); | |
87 } | |
88 | |
89 #endif | |
90 | |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15235
diff
changeset
|
91 DEFUN ("w32-set-clipboard-data", Fw32_set_clipboard_data, Sw32_set_clipboard_data, 1, 2, 0, |
13434 | 92 "This sets the clipboard data to the given text.") |
93 (string, frame) | |
94 Lisp_Object string, frame; | |
95 { | |
96 BOOL ok = TRUE; | |
97 HANDLE htext; | |
15150
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
98 int nbytes; |
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
99 int truelen; |
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
100 unsigned char *src; |
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
101 unsigned char *dst; |
13434 | 102 |
103 CHECK_STRING (string, 0); | |
104 | |
105 if (!NILP (frame)) | |
106 CHECK_LIVE_FRAME (frame, 0); | |
107 | |
108 BLOCK_INPUT; | |
15150
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
109 |
22545
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
110 nbytes = STRING_BYTES (XSTRING (string)) + 1; |
15150
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
111 src = XSTRING (string)->data; |
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
112 |
22545
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
113 { |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
114 /* Since we are now handling multilingual text, we must consider |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
115 encoding text for the clipboard. */ |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
116 int charsets[MAX_CHARSET + 1]; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
117 int num; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
118 |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
119 bzero (charsets, (MAX_CHARSET + 1) * sizeof (int)); |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
120 num = ((nbytes <= 2 /* Check the possibility of short cut. */ |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
121 || NILP (buffer_defaults.enable_multibyte_characters)) |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
122 ? 0 |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
123 : find_charset_in_str (src, nbytes, charsets, Qnil, 1)); |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
124 |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
125 if (!num || (num == 1 && charsets[CHARSET_ASCII])) |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
126 { |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
127 /* No multibyte character in OBJ. We need not encode it. */ |
15150
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
128 |
22545
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
129 /* need to know final size after '\r' chars are inserted (the |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
130 standard CF_TEXT clipboard format uses CRLF line endings, |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
131 while Emacs uses just LF internally) */ |
15150
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
132 |
22545
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
133 truelen = nbytes; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
134 dst = src; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
135 /* avoid using strchr because it recomputes the length everytime */ |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
136 while ((dst = memchr (dst, '\n', nbytes - (dst - src))) != NULL) |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
137 { |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
138 truelen++; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
139 dst++; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
140 } |
15150
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
141 |
22545
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
142 if ((htext = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, truelen)) == NULL) |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
143 goto error; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
144 |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
145 if ((dst = (unsigned char *) GlobalLock (htext)) == NULL) |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
146 goto error; |
15150
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
147 |
22545
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
148 /* convert to CRLF line endings expected by clipboard */ |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
149 while (1) |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
150 { |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
151 unsigned char *next; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
152 /* copy next line or remaining bytes including '\0' */ |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
153 next = _memccpy (dst, src, '\n', nbytes); |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
154 if (next) |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
155 { |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
156 /* copied one line ending with '\n' */ |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
157 int copied = next - dst; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
158 nbytes -= copied; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
159 src += copied; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
160 /* insert '\r' before '\n' */ |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
161 next[-1] = '\r'; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
162 next[0] = '\n'; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
163 dst = next + 1; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
164 } |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
165 else |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
166 /* copied remaining partial line -> now finished */ |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
167 break; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
168 } |
13434 | 169 |
22545
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
170 GlobalUnlock (htext); |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
171 } |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
172 else |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
173 { |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
174 /* We must encode contents of OBJ to compound text format. |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
175 The format is compatible with what the target `STRING' |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
176 expects if OBJ contains only ASCII and Latin-1 |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
177 characters. */ |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
178 int bufsize; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
179 struct coding_system coding; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
180 HANDLE htext2; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
181 |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
182 setup_coding_system |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
183 (Fcheck_coding_system (Vclipboard_coding_system), &coding); |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
184 coding.mode |= CODING_MODE_LAST_BLOCK; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
185 bufsize = encoding_buffer_size (&coding, nbytes); |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
186 if ((htext = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, bufsize)) == NULL) |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
187 goto error; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
188 if ((dst = (unsigned char *) GlobalLock (htext)) == NULL) |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
189 goto error; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
190 encode_coding (&coding, src, dst, nbytes, bufsize); |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
191 GlobalUnlock (htext); |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
192 /* Shrink data block to actual size. */ |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
193 htext2 = GlobalReAlloc (htext, coding.produced, GMEM_MOVEABLE | GMEM_DDESHARE); |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
194 if (htext2 != NULL) htext = htext2; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
195 } |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
196 } |
13434 | 197 |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15235
diff
changeset
|
198 if (!OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL)) |
13434 | 199 goto error; |
200 | |
201 ok = EmptyClipboard () && SetClipboardData (CF_TEXT, htext); | |
202 | |
203 CloseClipboard (); | |
204 | |
205 if (ok) goto done; | |
206 | |
207 error: | |
208 | |
209 ok = FALSE; | |
210 if (htext) GlobalFree (htext); | |
211 | |
212 done: | |
213 UNBLOCK_INPUT; | |
214 | |
215 return (ok ? string : Qnil); | |
216 } | |
217 | |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15235
diff
changeset
|
218 DEFUN ("w32-get-clipboard-data", Fw32_get_clipboard_data, Sw32_get_clipboard_data, 0, 1, 0, |
13434 | 219 "This gets the clipboard data in text format.") |
220 (frame) | |
221 Lisp_Object frame; | |
222 { | |
223 HANDLE htext; | |
224 Lisp_Object ret = Qnil; | |
225 | |
226 if (!NILP (frame)) | |
227 CHECK_LIVE_FRAME (frame, 0); | |
228 | |
229 BLOCK_INPUT; | |
230 | |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15235
diff
changeset
|
231 if (!OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL)) |
13434 | 232 goto done; |
233 | |
234 if ((htext = GetClipboardData (CF_TEXT)) == NULL) | |
235 goto closeclip; | |
236 | |
237 { | |
15150
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
238 unsigned char *src; |
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
239 unsigned char *dst; |
13434 | 240 int nbytes; |
15150
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
241 int truelen; |
13434 | 242 |
15150
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
243 if ((src = (unsigned char *) GlobalLock (htext)) == NULL) |
13434 | 244 goto closeclip; |
245 | |
15150
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
246 nbytes = strlen (src); |
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
247 |
22545
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
248 if (! NILP (buffer_defaults.enable_multibyte_characters)) |
15150
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
249 { |
22545
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
250 int bufsize; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
251 unsigned char *buf; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
252 struct coding_system coding; |
15150
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
253 |
22545
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
254 setup_coding_system |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
255 (Fcheck_coding_system(Vclipboard_coding_system), &coding); |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
256 coding.mode |= CODING_MODE_LAST_BLOCK; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
257 bufsize = decoding_buffer_size (&coding, nbytes); |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
258 buf = (unsigned char *) xmalloc (bufsize); |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
259 decode_coding (&coding, src, buf, nbytes, bufsize); |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
260 truelen = (coding.fake_multibyte |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
261 ? multibyte_chars_in_text (buf, coding.produced) |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
262 : coding.produced_char); |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
263 ret = make_string_from_bytes ((char *) buf, truelen, coding.produced); |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
264 xfree (buf); |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
265 } |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
266 else |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
267 { |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
268 /* need to know final size after '\r' chars are removed because |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
269 we can't change the string size manually, and doing an extra |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
270 copy is silly */ |
13434 | 271 |
22545
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
272 truelen = nbytes; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
273 dst = src; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
274 /* avoid using strchr because it recomputes the length everytime */ |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
275 while ((dst = memchr (dst, '\r', nbytes - (dst - src))) != NULL) |
15150
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
276 { |
22545
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
277 truelen--; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
278 dst++; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
279 } |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
280 |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
281 ret = make_uninit_string (truelen); |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
282 |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
283 /* convert CRLF line endings (the standard CF_TEXT clipboard |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
284 format) to LF endings as used internally by Emacs */ |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
285 |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
286 dst = XSTRING (ret)->data; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
287 while (1) |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
288 { |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
289 unsigned char *next; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
290 /* copy next line or remaining bytes excluding '\0' */ |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
291 next = _memccpy (dst, src, '\r', nbytes); |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
292 if (next) |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
293 { |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
294 /* copied one line ending with '\r' */ |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
295 int copied = next - dst; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
296 nbytes -= copied; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
297 dst += copied - 1; /* overwrite '\r' */ |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
298 src += copied; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
299 } |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
300 else |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
301 /* copied remaining partial line -> now finished */ |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
302 break; |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
303 } |
15150
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
304 } |
e37489592e27
(Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
305 |
13434 | 306 GlobalUnlock (htext); |
307 } | |
308 | |
309 closeclip: | |
310 CloseClipboard (); | |
311 | |
312 done: | |
313 UNBLOCK_INPUT; | |
314 | |
315 return (ret); | |
316 } | |
317 | |
15235 | 318 /* Support checking for a clipboard selection. */ |
319 | |
320 DEFUN ("x-selection-exists-p", Fx_selection_exists_p, Sx_selection_exists_p, | |
321 0, 1, 0, | |
322 "Whether there is an owner for the given X Selection.\n\ | |
323 The arg should be the name of the selection in question, typically one of\n\ | |
324 the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.\n\ | |
325 \(Those are literal upper-case symbol names, since that's what X expects.)\n\ | |
326 For convenience, the symbol nil is the same as `PRIMARY',\n\ | |
327 and t is the same as `SECONDARY'.") | |
328 (selection) | |
329 Lisp_Object selection; | |
330 { | |
331 CHECK_SYMBOL (selection, 0); | |
332 | |
333 /* Return nil for PRIMARY and SECONDARY selections; for CLIPBOARD, check | |
334 if the clipboard currently has valid text format contents. */ | |
335 | |
336 if (EQ (selection, QCLIPBOARD)) | |
337 { | |
338 Lisp_Object val = Qnil; | |
339 | |
340 if (OpenClipboard (NULL)) | |
341 { | |
342 int format = 0; | |
343 while (format = EnumClipboardFormats (format)) | |
344 if (format == CF_TEXT) | |
345 { | |
346 val = Qt; | |
347 break; | |
348 } | |
349 CloseClipboard (); | |
350 } | |
351 return val; | |
352 } | |
353 return Qnil; | |
354 } | |
355 | |
13434 | 356 void |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15235
diff
changeset
|
357 syms_of_w32select () |
13434 | 358 { |
359 #if 0 | |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15235
diff
changeset
|
360 defsubr (&Sw32_open_clipboard); |
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15235
diff
changeset
|
361 defsubr (&Sw32_empty_clipboard); |
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15235
diff
changeset
|
362 defsubr (&Sw32_close_clipboard); |
13434 | 363 #endif |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15235
diff
changeset
|
364 defsubr (&Sw32_set_clipboard_data); |
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15235
diff
changeset
|
365 defsubr (&Sw32_get_clipboard_data); |
15235 | 366 defsubr (&Sx_selection_exists_p); |
367 | |
22545
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
368 DEFVAR_LISP ("clipboard-coding-system", &Vclipboard_coding_system, |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
369 "Coding system for communicating with other X clients.\n\ |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
370 When sending or receiving text via cut_buffer, selection, and clipboard,\n\ |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
371 the text is encoded or decoded by this coding system.\n\ |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
372 A default value is `compound-text'"); |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
373 Vclipboard_coding_system=intern ("iso-latin-1-dos"); |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
374 staticpro(&Vclipboard_coding_system); |
5d3f50b4c8d2
Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents:
16884
diff
changeset
|
375 |
15235 | 376 QCLIPBOARD = intern ("CLIPBOARD"); staticpro (&QCLIPBOARD); |
13434 | 377 } |