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)
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, 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* Written by Kevin Gallo */
24 #include "w32term.h" /* for all of the win32 includes */
25 #include "dispextern.h" /* frame.h seems to want this */
26 #include "frame.h" /* Need this to get the X window of selected_frame */
27 #include "blockinput.h"
30 DEFUN ("win32-open-clipboard", Fwin32_open_clipboard
, Swin32_open_clipboard
, 0, 1, 0,
31 "This opens the clipboard with the given frame pointer.")
38 CHECK_LIVE_FRAME (frame
, 0);
42 ok
= OpenClipboard ((!NILP (frame
) && FRAME_WIN32_P (XFRAME (frame
))) ? FRAME_WIN32_WINDOW (XFRAME (frame
)) : NULL
);
46 return (ok
? frame
: Qnil
);
49 DEFUN ("win32-empty-clipboard", Fwin32_empty_clipboard
, Swin32_empty_clipboard
, 0, 0, 0,
50 "This empties the clipboard and assigns ownership to the window which opened the clipboard.")
57 ok
= EmptyClipboard ();
61 return (ok
? Qt
: Qnil
);
64 DEFUN ("win32-close-clipboard", Fwin32_close_clipboard
, Swin32_close_clipboard
, 0, 0, 0,
65 "This closes the clipboard.")
72 ok
= CloseClipboard ();
76 return (ok
? Qt
: Qnil
);
81 DEFUN ("win32-set-clipboard-data", Fwin32_set_clipboard_data
, Swin32_set_clipboard_data
, 1, 2, 0,
82 "This sets the clipboard data to the given text.")
84 Lisp_Object string
, frame
;
89 CHECK_STRING (string
, 0);
92 CHECK_LIVE_FRAME (frame
, 0);
96 /* Allocate twice the amount so we can convert lf to cr-lf */
98 if ((htext
= GlobalAlloc (GMEM_MOVEABLE
| GMEM_DDESHARE
, (2 * XSTRING (string
)->size
) + 1)) == NULL
)
102 unsigned char *lptext
;
104 if ((lptext
= (unsigned char *)GlobalLock (htext
)) == NULL
)
108 int i
= XSTRING (string
)->size
;
109 int newsize
= XSTRING (string
)->size
;
110 register char *p1
= XSTRING (string
)->data
;
111 register char *p2
= lptext
;
127 GlobalUnlock (htext
);
130 if (!OpenClipboard ((!NILP (frame
) && FRAME_WIN32_P (XFRAME (frame
))) ? FRAME_WIN32_WINDOW (XFRAME (frame
)) : NULL
))
133 ok
= EmptyClipboard () && SetClipboardData (CF_TEXT
, htext
);
142 if (htext
) GlobalFree (htext
);
147 return (ok
? string
: Qnil
);
150 DEFUN ("win32-get-clipboard-data", Fwin32_get_clipboard_data
, Swin32_get_clipboard_data
, 0, 1, 0,
151 "This gets the clipboard data in text format.")
156 Lisp_Object ret
= Qnil
;
159 CHECK_LIVE_FRAME (frame
, 0);
163 if (!OpenClipboard ((!NILP (frame
) && FRAME_WIN32_P (XFRAME (frame
))) ? FRAME_WIN32_WINDOW (XFRAME (frame
)) : NULL
))
166 if ((htext
= GetClipboardData (CF_TEXT
)) == NULL
)
171 unsigned char *lptext
;
174 if ((lptext
= (unsigned char *)GlobalLock (htext
)) == NULL
)
177 nbytes
= strlen (lptext
);
180 char *buf
= (char *) xmalloc (nbytes
);
181 register char *p1
= lptext
;
182 register char *p2
= buf
;
185 if (buf
== NULL
) goto closeclip
;
189 if (p1
[0] == '\r' && i
&& p1
[1] == '\n')
199 ret
= make_string (buf
, nbytes
);
204 GlobalUnlock (htext
);
217 syms_of_win32select ()
220 defsubr (&Swin32_open_clipboard
);
221 defsubr (&Swin32_empty_clipboard
);
222 defsubr (&Swin32_close_clipboard
);
224 defsubr (&Swin32_set_clipboard_data
);
225 defsubr (&Swin32_get_clipboard_data
);