comparison src/select-msw.c @ 398:74fd4e045ea6 r21-2-29

Import from CVS: tag r21-2-29
author cvs
date Mon, 13 Aug 2007 11:13:30 +0200
parents e11d67e05968
children a86b2b5e0111
comparison
equal deleted inserted replaced
397:f4aeb21a5bad 398:74fd4e045ea6
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"
33 #include "select.h"
32 34
33 #include "console-msw.h" 35 #include "console-msw.h"
34 36
35 DEFUN ("mswindows-set-clipboard", Fmswindows_set_clipboard, 1, 1, 0, /* 37 DEFUN ("mswindows-set-clipboard", Fmswindows_set_clipboard, 1, 1, 0, /*
36 Copy STRING to the mswindows clipboard. 38 Copy STRING to the mswindows clipboard.
38 (string)) 40 (string))
39 { 41 {
40 int rawsize, size, i; 42 int rawsize, size, i;
41 unsigned char *src, *dst, *next; 43 unsigned char *src, *dst, *next;
42 HGLOBAL h = NULL; 44 HGLOBAL h = NULL;
45 struct frame *f = NULL;
43 46
44 CHECK_STRING (string); 47 CHECK_STRING (string);
45 48
46 /* Calculate size with LFs converted to CRLFs because 49 /* Calculate size with LFs converted to CRLFs because
47 * CF_TEXT format uses CRLF delimited ASCIIZ */ 50 * CF_TEXT format uses CRLF delimited ASCIIZ */
49 size = rawsize = XSTRING_LENGTH (string) + 1; 52 size = rawsize = XSTRING_LENGTH (string) + 1;
50 for (i=0; i<rawsize; i++) 53 for (i=0; i<rawsize; i++)
51 if (src[i] == '\n') 54 if (src[i] == '\n')
52 size++; 55 size++;
53 56
54 if (!OpenClipboard (NULL)) 57 f = selected_frame ();
58 if (!OpenClipboard (FRAME_MSWINDOWS_HANDLE (f)))
55 return Qnil; 59 return Qnil;
56 60
57 if (!EmptyClipboard () || 61 if (!EmptyClipboard () ||
58 (h = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, size)) == NULL || 62 (h = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, size)) == NULL ||
59 (dst = (unsigned char *) GlobalLock (h)) == NULL) 63 (dst = (unsigned char *) GlobalLock (h)) == NULL)
85 GlobalUnlock (h); 89 GlobalUnlock (h);
86 90
87 i = (SetClipboardData (CF_TEXT, h) != NULL); 91 i = (SetClipboardData (CF_TEXT, h) != NULL);
88 92
89 CloseClipboard (); 93 CloseClipboard ();
90 GlobalFree (h);
91 94
92 return i ? Qt : Qnil; 95 return i ? Qt : Qnil;
96 }
97
98 /* Do protocol to assert ourself as a selection owner. Under mswindows
99 this is easy, we just set the clipboard. */
100 static Lisp_Object
101 mswindows_own_selection (Lisp_Object selection_name, Lisp_Object selection_value)
102 {
103 Lisp_Object converted_value = get_local_selection (selection_name, QSTRING);
104 if (!NILP (converted_value) &&
105 CONSP (converted_value) &&
106 EQ (XCAR (converted_value), QSTRING) &&
107 /* pure mswindows behaviour only says we can own the selection
108 if it is the clipboard */
109 EQ (selection_name, QCLIPBOARD))
110 Fmswindows_set_clipboard (XCDR (converted_value));
111
112 return Qnil;
93 } 113 }
94 114
95 DEFUN ("mswindows-get-clipboard", Fmswindows_get_clipboard, 0, 0, 0, /* 115 DEFUN ("mswindows-get-clipboard", Fmswindows_get_clipboard, 0, 0, 0, /*
96 Return the contents of the mswindows clipboard. 116 Return the contents of the mswindows clipboard.
97 */ 117 */
142 CloseClipboard (); 162 CloseClipboard ();
143 163
144 return ret; 164 return ret;
145 } 165 }
146 166
167 static Lisp_Object
168 mswindows_get_foreign_selection (Lisp_Object selection_symbol, Lisp_Object target_type)
169 {
170 if (EQ (selection_symbol, QCLIPBOARD))
171 return Fmswindows_get_clipboard ();
172 else
173 return Qnil;
174 }
175
147 DEFUN ("mswindows-selection-exists-p", Fmswindows_selection_exists_p, 0, 0, 0, /* 176 DEFUN ("mswindows-selection-exists-p", Fmswindows_selection_exists_p, 0, 0, 0, /*
148 Whether there is an MS-Windows selection. 177 Whether there is an MS-Windows selection.
149 */ 178 */
150 ()) 179 ())
151 { 180 {
155 DEFUN ("mswindows-delete-selection", Fmswindows_delete_selection, 0, 0, 0, /* 184 DEFUN ("mswindows-delete-selection", Fmswindows_delete_selection, 0, 0, 0, /*
156 Remove the current MS-Windows selection from the clipboard. 185 Remove the current MS-Windows selection from the clipboard.
157 */ 186 */
158 ()) 187 ())
159 { 188 {
160 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;
199 }
200
201 static void
202 mswindows_disown_selection (Lisp_Object selection, Lisp_Object timeval)
203 {
204 if (EQ (selection, QCLIPBOARD))
205 Fmswindows_delete_selection ();
161 } 206 }
162 207
163 208
164 /************************************************************************/ 209 /************************************************************************/
165 /* initialization */ 210 /* initialization */
166 /************************************************************************/ 211 /************************************************************************/
167 212
168 void 213 void
214 console_type_create_select_mswindows (void)
215 {
216 CONSOLE_HAS_METHOD (mswindows, own_selection);
217 CONSOLE_HAS_METHOD (mswindows, disown_selection);
218 CONSOLE_HAS_METHOD (mswindows, get_foreign_selection);
219 }
220
221 void
169 syms_of_select_mswindows (void) 222 syms_of_select_mswindows (void)
170 { 223 {
171 DEFSUBR (Fmswindows_set_clipboard); 224 DEFSUBR (Fmswindows_set_clipboard);
172 DEFSUBR (Fmswindows_get_clipboard); 225 DEFSUBR (Fmswindows_get_clipboard);
173 DEFSUBR (Fmswindows_selection_exists_p); 226 DEFSUBR (Fmswindows_selection_exists_p);