(iso-transl-dead-key-alist): Fix syntax for ?^.
[emacs.git] / src / w32select.c
blobe7bb0c940073ce22be3912ede09376195d3176a4
1 /* Win32 Selection processing for emacs
2 Copyright (C) 1993, 1994 Free Software Foundation.
4 This file is part of GNU Emacs.
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.
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.
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. */
21 /* Written by Kevin Gallo */
23 #include <config.h>
24 #include "lisp.h"
25 #include "w32term.h" /* for all of the win32 includes */
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"
30 #if 0
31 DEFUN ("win32-open-clipboard", Fwin32_open_clipboard, Swin32_open_clipboard, 0, 1, 0,
32 "This opens the clipboard with the given frame pointer.")
33 (frame)
34 Lisp_Object frame;
36 BOOL ok = FALSE;
38 if (!NILP (frame))
39 CHECK_LIVE_FRAME (frame, 0);
41 BLOCK_INPUT;
43 ok = OpenClipboard ((!NILP (frame) && FRAME_WIN32_P (XFRAME (frame))) ? FRAME_WIN32_WINDOW (XFRAME (frame)) : NULL);
45 UNBLOCK_INPUT;
47 return (ok ? frame : Qnil);
50 DEFUN ("win32-empty-clipboard", Fwin32_empty_clipboard, Swin32_empty_clipboard, 0, 0, 0,
51 "This empties the clipboard and assigns ownership to the window which opened the clipboard.")
54 BOOL ok = FALSE;
56 BLOCK_INPUT;
58 ok = EmptyClipboard ();
60 UNBLOCK_INPUT;
62 return (ok ? Qt : Qnil);
65 DEFUN ("win32-close-clipboard", Fwin32_close_clipboard, Swin32_close_clipboard, 0, 0, 0,
66 "This closes the clipboard.")
69 BOOL ok = FALSE;
71 BLOCK_INPUT;
73 ok = CloseClipboard ();
75 UNBLOCK_INPUT;
77 return (ok ? Qt : Qnil);
80 #endif
82 DEFUN ("win32-set-clipboard-data", Fwin32_set_clipboard_data, Swin32_set_clipboard_data, 1, 2, 0,
83 "This sets the clipboard data to the given text.")
84 (string, frame)
85 Lisp_Object string, frame;
87 BOOL ok = TRUE;
88 HANDLE htext;
90 CHECK_STRING (string, 0);
92 if (!NILP (frame))
93 CHECK_LIVE_FRAME (frame, 0);
95 BLOCK_INPUT;
97 /* Allocate twice the amount so we can convert lf to cr-lf */
99 if ((htext = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, (2 * XSTRING (string)->size) + 1)) == NULL)
100 goto error;
103 unsigned char *lptext;
105 if ((lptext = (unsigned char *)GlobalLock (htext)) == NULL)
106 goto error;
109 int i = XSTRING (string)->size;
110 int newsize = XSTRING (string)->size;
111 register char *p1 = XSTRING (string)->data;
112 register char *p2 = lptext;
114 while (i--)
116 if (*p1 == '\n')
118 newsize++;
119 *p2++ = '\r';
122 *p2++ = *p1++;
125 *p2 = 0;
128 GlobalUnlock (htext);
131 if (!OpenClipboard ((!NILP (frame) && FRAME_WIN32_P (XFRAME (frame))) ? FRAME_WIN32_WINDOW (XFRAME (frame)) : NULL))
132 goto error;
134 ok = EmptyClipboard () && SetClipboardData (CF_TEXT, htext);
136 CloseClipboard ();
138 if (ok) goto done;
140 error:
142 ok = FALSE;
143 if (htext) GlobalFree (htext);
145 done:
146 UNBLOCK_INPUT;
148 return (ok ? string : Qnil);
151 DEFUN ("win32-get-clipboard-data", Fwin32_get_clipboard_data, Swin32_get_clipboard_data, 0, 1, 0,
152 "This gets the clipboard data in text format.")
153 (frame)
154 Lisp_Object frame;
156 HANDLE htext;
157 Lisp_Object ret = Qnil;
159 if (!NILP (frame))
160 CHECK_LIVE_FRAME (frame, 0);
162 BLOCK_INPUT;
164 if (!OpenClipboard ((!NILP (frame) && FRAME_WIN32_P (XFRAME (frame))) ? FRAME_WIN32_WINDOW (XFRAME (frame)) : NULL))
165 goto done;
167 if ((htext = GetClipboardData (CF_TEXT)) == NULL)
168 goto closeclip;
172 unsigned char *lptext;
173 int nbytes;
175 if ((lptext = (unsigned char *)GlobalLock (htext)) == NULL)
176 goto closeclip;
178 nbytes = strlen (lptext);
181 char *buf = (char *) xmalloc (nbytes);
182 register char *p1 = lptext;
183 register char *p2 = buf;
184 int i = nbytes;
186 if (buf == NULL) goto closeclip;
188 while (i--)
190 if (p1[0] == '\r' && i && p1[1] == '\n')
192 p1++;
193 i--;
194 nbytes--;
197 *p2++ = *p1++;
200 ret = make_string (buf, nbytes);
202 xfree (buf);
205 GlobalUnlock (htext);
208 closeclip:
209 CloseClipboard ();
211 done:
212 UNBLOCK_INPUT;
214 return (ret);
217 void
218 syms_of_win32select ()
220 #if 0
221 defsubr (&Swin32_open_clipboard);
222 defsubr (&Swin32_empty_clipboard);
223 defsubr (&Swin32_close_clipboard);
224 #endif
225 defsubr (&Swin32_set_clipboard_data);
226 defsubr (&Swin32_get_clipboard_data);