comparison src/select-msw.c @ 430:a5df635868b2 r21-2-23

Import from CVS: tag r21-2-23
author cvs
date Mon, 13 Aug 2007 11:29:08 +0200
parents 3ecd8885ac67
children abe6d1db359e
comparison
equal deleted inserted replaced
429:8305706cbb93 430:a5df635868b2
27 */ 27 */
28 28
29 29
30 #include <config.h> 30 #include <config.h>
31 #include "lisp.h" 31 #include "lisp.h"
32 #include "frame.h"
32 #include "select.h" 33 #include "select.h"
33 34
34 #include "console-msw.h" 35 #include "console-msw.h"
35 36
36 DEFUN ("mswindows-set-clipboard", Fmswindows_set_clipboard, 1, 1, 0, /* 37 DEFUN ("mswindows-set-clipboard", Fmswindows_set_clipboard, 1, 1, 0, /*
39 (string)) 40 (string))
40 { 41 {
41 int rawsize, size, i; 42 int rawsize, size, i;
42 unsigned char *src, *dst, *next; 43 unsigned char *src, *dst, *next;
43 HGLOBAL h = NULL; 44 HGLOBAL h = NULL;
45 struct frame *f = NULL;
44 46
45 CHECK_STRING (string); 47 CHECK_STRING (string);
46 48
47 /* Calculate size with LFs converted to CRLFs because 49 /* Calculate size with LFs converted to CRLFs because
48 * CF_TEXT format uses CRLF delimited ASCIIZ */ 50 * CF_TEXT format uses CRLF delimited ASCIIZ */
50 size = rawsize = XSTRING_LENGTH (string) + 1; 52 size = rawsize = XSTRING_LENGTH (string) + 1;
51 for (i=0; i<rawsize; i++) 53 for (i=0; i<rawsize; i++)
52 if (src[i] == '\n') 54 if (src[i] == '\n')
53 size++; 55 size++;
54 56
55 if (!OpenClipboard (NULL)) 57 f = selected_frame ();
58 if (!OpenClipboard (FRAME_MSWINDOWS_HANDLE (f)))
56 return Qnil; 59 return Qnil;
57 60
58 if (!EmptyClipboard () || 61 if (!EmptyClipboard () ||
59 (h = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, size)) == NULL || 62 (h = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, size)) == NULL ||
60 (dst = (unsigned char *) GlobalLock (h)) == NULL) 63 (dst = (unsigned char *) GlobalLock (h)) == NULL)
86 GlobalUnlock (h); 89 GlobalUnlock (h);
87 90
88 i = (SetClipboardData (CF_TEXT, h) != NULL); 91 i = (SetClipboardData (CF_TEXT, h) != NULL);
89 92
90 CloseClipboard (); 93 CloseClipboard ();
91 GlobalFree (h);
92 94
93 return i ? Qt : Qnil; 95 return i ? Qt : Qnil;
94 } 96 }
95 97
96 /* Do protocol to assert ourself as a selection owner. Under mswindows 98 /* Do protocol to assert ourself as a selection owner. Under mswindows
182 DEFUN ("mswindows-delete-selection", Fmswindows_delete_selection, 0, 0, 0, /* 184 DEFUN ("mswindows-delete-selection", Fmswindows_delete_selection, 0, 0, 0, /*
183 Remove the current MS-Windows selection from the clipboard. 185 Remove the current MS-Windows selection from the clipboard.
184 */ 186 */
185 ()) 187 ())
186 { 188 {
187 return EmptyClipboard () ? Qt : Qnil; 189 BOOL success = OpenClipboard (NULL);
190 if (success)
191 {
192 success = EmptyClipboard ();
193 /* Close it regardless of whether empty worked. */
194 if (!CloseClipboard ())
195 success = FALSE;
196 }
197
198 return success ? Qt : Qnil;
188 } 199 }
189 200
190 static void 201 static void
191 mswindows_disown_selection (Lisp_Object selection, Lisp_Object timeval) 202 mswindows_disown_selection (Lisp_Object selection, Lisp_Object timeval)
192 { 203 {