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, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* Written by Kevin Gallo */
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"
31 DEFUN ("win32-open-clipboard", Fwin32_open_clipboard
, Swin32_open_clipboard
, 0, 1, 0,
32 "This opens the clipboard with the given frame pointer.")
39 CHECK_LIVE_FRAME (frame
, 0);
43 ok
= OpenClipboard ((!NILP (frame
) && FRAME_WIN32_P (XFRAME (frame
))) ? FRAME_WIN32_WINDOW (XFRAME (frame
)) : NULL
);
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.")
58 ok
= EmptyClipboard ();
62 return (ok
? Qt
: Qnil
);
65 DEFUN ("win32-close-clipboard", Fwin32_close_clipboard
, Swin32_close_clipboard
, 0, 0, 0,
66 "This closes the clipboard.")
73 ok
= CloseClipboard ();
77 return (ok
? Qt
: Qnil
);
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.")
85 Lisp_Object string
, frame
;
90 CHECK_STRING (string
, 0);
93 CHECK_LIVE_FRAME (frame
, 0);
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
)
103 unsigned char *lptext
;
105 if ((lptext
= (unsigned char *)GlobalLock (htext
)) == NULL
)
109 int i
= XSTRING (string
)->size
;
110 int newsize
= XSTRING (string
)->size
;
111 register char *p1
= XSTRING (string
)->data
;
112 register char *p2
= lptext
;
128 GlobalUnlock (htext
);
131 if (!OpenClipboard ((!NILP (frame
) && FRAME_WIN32_P (XFRAME (frame
))) ? FRAME_WIN32_WINDOW (XFRAME (frame
)) : NULL
))
134 ok
= EmptyClipboard () && SetClipboardData (CF_TEXT
, htext
);
143 if (htext
) GlobalFree (htext
);
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.")
157 Lisp_Object ret
= Qnil
;
160 CHECK_LIVE_FRAME (frame
, 0);
164 if (!OpenClipboard ((!NILP (frame
) && FRAME_WIN32_P (XFRAME (frame
))) ? FRAME_WIN32_WINDOW (XFRAME (frame
)) : NULL
))
167 if ((htext
= GetClipboardData (CF_TEXT
)) == NULL
)
172 unsigned char *lptext
;
175 if ((lptext
= (unsigned char *)GlobalLock (htext
)) == NULL
)
178 nbytes
= strlen (lptext
);
181 char *buf
= (char *) xmalloc (nbytes
);
182 register char *p1
= lptext
;
183 register char *p2
= buf
;
186 if (buf
== NULL
) goto closeclip
;
190 if (p1
[0] == '\r' && i
&& p1
[1] == '\n')
200 ret
= make_string (buf
, nbytes
);
205 GlobalUnlock (htext
);
218 syms_of_win32select ()
221 defsubr (&Swin32_open_clipboard
);
222 defsubr (&Swin32_empty_clipboard
);
223 defsubr (&Swin32_close_clipboard
);
225 defsubr (&Swin32_set_clipboard_data
);
226 defsubr (&Swin32_get_clipboard_data
);