1 /* mswindows selection processing for XEmacs
2 Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
4 This file is part of XEmacs.
6 XEmacs is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with XEmacs; 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 /* Synched up with: Not synched with FSF. */
25 Written by Kevin Gallo for FSF Emacs.
26 Rewritten for mswindows by Jonathan Harris, December 1997 for 21.0.
33 #include "console-msw.h"
35 DEFUN ("mswindows-set-clipboard", Fmswindows_set_clipboard, 1, 1, 0, /*
36 Copy STRING to the mswindows clipboard.
41 unsigned char *src, *dst, *next;
44 CHECK_STRING (string);
46 /* Calculate size with LFs converted to CRLFs because
47 * CF_TEXT format uses CRLF delimited ASCIIZ */
48 src = XSTRING_DATA (string);
49 size = rawsize = XSTRING_LENGTH (string) + 1;
50 for (i=0; i<rawsize; i++)
54 if (!OpenClipboard (NULL))
57 if (!EmptyClipboard () ||
58 (h = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, size)) == NULL ||
59 (dst = (unsigned char *) GlobalLock (h)) == NULL)
61 if (h != NULL) GlobalFree (h);
66 /* Convert LFs to CRLFs */
69 /* copy next line or remaining bytes including '\0' */
70 next = memccpy (dst, src, '\n', rawsize);
73 /* copied one line ending with '\n' */
74 int copied = next - dst;
77 /* insert '\r' before '\n' */
87 i = (SetClipboardData (CF_TEXT, h) != NULL);
95 DEFUN ("mswindows-get-clipboard", Fmswindows_get_clipboard, 0, 0, 0, /*
96 Return the contents of the mswindows clipboard.
101 unsigned char *src, *dst, *next;
102 Lisp_Object ret = Qnil;
104 if (!OpenClipboard (NULL))
107 if ((h = GetClipboardData (CF_TEXT)) != NULL &&
108 (src = (unsigned char *) GlobalLock (h)) != NULL)
112 size = rawsize = strlen (src);
114 for (i=0; i<rawsize; i++)
115 if (src[i] == '\r' && src[i+1] == '\n')
118 /* Convert CRLFs to LFs */
119 ret = make_uninit_string (size);
120 dst = XSTRING_DATA (ret);
123 /* copy next line or remaining bytes excluding '\0' */
124 next = memccpy (dst, src, '\r', rawsize);
127 /* copied one line ending with '\r' */
128 int copied = next - dst;
132 dst += copied - 1; /* overwrite '\r' */
147 DEFUN ("mswindows-selection-exists-p", Fmswindows_selection_exists_p, 0, 0, 0, /*
148 Whether there is an MS-Windows selection.
152 return IsClipboardFormatAvailable (CF_TEXT) ? Qt : Qnil;
155 DEFUN ("mswindows-delete-selection", Fmswindows_delete_selection, 0, 0, 0, /*
156 Remove the current MS-Windows selection from the clipboard.
160 return EmptyClipboard () ? Qt : Qnil;
164 /************************************************************************/
166 /************************************************************************/
169 syms_of_select_mswindows (void)
171 DEFSUBR (Fmswindows_set_clipboard);
172 DEFSUBR (Fmswindows_get_clipboard);
173 DEFSUBR (Fmswindows_selection_exists_p);
174 DEFSUBR (Fmswindows_delete_selection);
178 vars_of_select_mswindows (void)