Mercurial > hg > xemacs-beta
diff src/select-msw.c @ 771:943eaba38521
[xemacs-hg @ 2002-03-13 08:51:24 by ben]
The big ben-mule-21-5 check-in!
Various files were added and deleted. See CHANGES-ben-mule.
There are still some test suite failures. No crashes, though.
Many of the failures have to do with problems in the test suite itself
rather than in the actual code. I'll be addressing these in the next
day or so -- none of the test suite failures are at all critical.
Meanwhile I'll be trying to address the biggest issues -- i.e. build
or run failures, which will almost certainly happen on various platforms.
All comments should be sent to ben@xemacs.org -- use a Cc: if necessary
when sending to mailing lists. There will be pre- and post- tags,
something like
pre-ben-mule-21-5-merge-in, and
post-ben-mule-21-5-merge-in.
author | ben |
---|---|
date | Wed, 13 Mar 2002 08:54:06 +0000 |
parents | 5fd7ba8b56e7 |
children | a5954632b187 |
line wrap: on
line diff
--- a/src/select-msw.c Fri Mar 08 13:33:14 2002 +0000 +++ b/src/select-msw.c Wed Mar 13 08:54:06 2002 +0000 @@ -1,5 +1,6 @@ /* mswindows selection processing for XEmacs Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc. + Copyright (C) 2000, 2001 Ben Wing. This file is part of XEmacs. @@ -20,26 +21,61 @@ /* Synched up with: Not synched with FSF. */ +/* This file Mule-ized 7-00?? Needs some Unicode review. --ben */ + /* Authorship: Written by Kevin Gallo for FSF Emacs. Rewritten for mswindows by Jonathan Harris, December 1997 for 21.0. + Rewritten April 2000 by Ben Wing -- support device methods, Mule-ize. Hacked by Alastair Houghton, July 2000 for enhanced clipboard support. */ #include <config.h> #include "lisp.h" +#include "buffer.h" #include "frame.h" #include "select.h" #include "opaque.h" #include "file-coding.h" -#include "buffer.h" #include "console-msw.h" +static int in_own_selection; + /* A list of handles that we must release. Not accessible from Lisp. */ static Lisp_Object Vhandle_alist; +void +mswindows_handle_destroyclipboard (void) +{ + /* We also receive a destroy message when we call EmptyClipboard() and + we already own it. In this case we don't want to call + handle_selection_clear() because it will remove what we're trying + to add! */ + if (!in_own_selection) + { + /* We own the clipboard and someone else wants it. Delete our + cached copy of the clipboard contents so we'll ask for it from + Windows again when someone does a paste, and destroy any memory + objects we hold on the clipboard that are not in the list of types + that Windows will delete itself. */ + mswindows_destroy_selection (QCLIPBOARD); + handle_selection_clear (QCLIPBOARD); + } +} + +static int +mswindows_empty_clipboard (void) +{ + int retval; + + in_own_selection = 1; + retval = EmptyClipboard (); + in_own_selection = 0; + return retval; +} + /* Test if this is an X symbol that we understand */ static int x_sym_p (Lisp_Object value) @@ -71,8 +107,11 @@ /* If it's a string, register the format(!) */ if (STRINGP (value)) - /* !!#### more mule bogosity */ - return RegisterClipboardFormat ((Extbyte *) XSTRING_DATA (value)); + { + Extbyte *valext; + LISP_STRING_TO_TSTR (value, valext); + return qxeRegisterClipboardFormat (valext); + } /* Check for Windows clipboard format symbols */ if (EQ (value, QCF_TEXT)) return CF_TEXT; @@ -209,8 +248,16 @@ if (NILP (selection_type) || x_sym_p (selection_type)) { /* Should COMPOUND_TEXT map to CF_UNICODETEXT? */ - cfType = CF_TEXT; - cfObject = QCF_TEXT; + if (XEUNICODE_P) + { + cfType = CF_UNICODETEXT; + cfObject = QCF_UNICODETEXT; + } + else + { + cfType = CF_TEXT; + cfObject = QCF_TEXT; + } is_X_type = TRUE; } else @@ -244,17 +291,13 @@ } /* We support opaque or string values, but we only mention string - values for now... */ + values for now... + #### where do the opaque objects come from? currently they're not + allowed to be exported to the lisp level! */ if (!OPAQUEP (data) && !STRINGP (data)) return Qnil; - /* Compute the data length */ - if (OPAQUEP (data)) - size = XOPAQUE_SIZE (data); - else - size = XSTRING_LENGTH (data) + 1; - /* Find the frame */ f = selected_frame (); @@ -262,6 +305,18 @@ if (!OpenClipboard (FRAME_MSWINDOWS_HANDLE (f))) return Qnil; + /* Obtain the data */ + if (OPAQUEP (data)) + { + src = XOPAQUE_DATA (data); + size = XOPAQUE_SIZE (data); + } + else + /* we do NOT append a zero byte. we don't know whether we're dealing + with regular text, unicode text, binary data, etc. */ + TO_EXTERNAL_FORMAT (LISP_STRING, data, ALLOCA, (src, size), + Qbinary); + /* Allocate memory */ hValue = GlobalAlloc (GMEM_DDESHARE | GMEM_MOVEABLE, size); @@ -272,12 +327,6 @@ return Qnil; } - /* Copy the data */ - if (OPAQUEP (data)) - src = XOPAQUE_DATA (data); - else - src = XSTRING_DATA (data); - dst = GlobalLock (hValue); if (!dst) @@ -295,7 +344,7 @@ /* Empty the clipboard if we're replacing everything */ if (NILP (how_to_add) || EQ (how_to_add, Qreplace_all)) { - if (!EmptyClipboard ()) + if (!mswindows_empty_clipboard ()) { CloseClipboard (); GlobalFree (hValue); @@ -327,8 +376,9 @@ /* Free the original handle */ GlobalFree ((HGLOBAL) get_opaque_ptr (XCDR (alist_elt))); - /* Remove the original one (adding first makes life easier, because - we don't have to special case this being the first element) */ + /* Remove the original one (adding first makes life easier, + because we don't have to special case this being the + first element) */ for (rest = Vhandle_alist; !NILP (rest); rest = Fcdr (rest)) if (EQ (cfType_int, Fcar (XCDR (rest)))) { @@ -362,9 +412,12 @@ if (!OpenClipboard (FRAME_MSWINDOWS_HANDLE (f))) return Qnil; - /* #### ajh - Should there be an unwind-protect handler around this? - It could (well it probably won't, but it's always better to - be safe) run out of memory and leave the clipboard open... */ + /* [[ ajh - Should there be an unwind-protect handler around this? + It could (well it probably won't, but it's always better to + be safe) run out of memory and leave the clipboard open... ]] + -- xemacs in general makes no provisions for out-of-memory errors; + we will probably just crash. fixing this is a huge amount of work, + so don't bother protecting in this case. --ben */ while ((format = EnumClipboardFormats (format))) types = Fcons (ms_cf_to_symbol (format), types); @@ -379,11 +432,11 @@ mswindows_register_selection_data_type (Lisp_Object type_name) { /* Type already checked in select.c */ - /* !!#### more mule bogosity */ - const char *name = (char *) XSTRING_DATA (type_name); - UINT format; + Extbyte *nameext; + UINT format; - format = RegisterClipboardFormat (name); + LISP_STRING_TO_TSTR (type_name, nameext); + format = qxeRegisterClipboardFormat (nameext); if (format) return make_int ((int) format); @@ -394,9 +447,9 @@ static Lisp_Object mswindows_selection_data_type_name (Lisp_Object type_id) { - UINT format; - int numchars; - char name_buf[128]; + UINT format; + Extbyte *namebuf; + int numchars; /* If it's an integer, convert to a symbol if appropriate */ if (INTP (type_id)) @@ -413,19 +466,20 @@ return Qnil; /* Microsoft, stupid Microsoft */ - numchars = GetClipboardFormatName (format, name_buf, 128); + { + int size, new_size = 128; + do + { + size = new_size; + new_size *= 2; + namebuf = alloca_extbytes (size * XETCHAR_SIZE); + numchars = qxeGetClipboardFormatName (format, namebuf, size); + } + while (numchars >= size - 1); + } if (numchars) - { - Lisp_Object name; - - /* Do this properly - though we could support UNICODE (UCS-2) if - MULE could hack it. */ - name = make_ext_string (name_buf, numchars, - Fget_coding_system (Qraw_text)); - - return name; - } + return build_tstr_string (namebuf); return Qnil; } @@ -453,8 +507,16 @@ if (NILP (target_type) || x_sym_p (target_type)) { /* Should COMPOUND_TEXT map to CF_UNICODETEXT? */ - cfType = CF_TEXT; - cfObject = QCF_TEXT; + if (XEUNICODE_P) + { + cfType = CF_UNICODETEXT; + cfObject = QCF_UNICODETEXT; + } + else + { + cfType = CF_TEXT; + cfObject = QCF_TEXT; + } is_X_type = TRUE; } else @@ -497,9 +559,7 @@ } /* Place it in a Lisp string */ - TO_INTERNAL_FORMAT (DATA, (data, size), - LISP_STRING, ret, - Qbinary); + ret = make_ext_string ((Extbyte *) data, size, Qbinary); GlobalUnlock (data); CloseClipboard (); @@ -529,7 +589,8 @@ BOOL success = OpenClipboard (NULL); if (success) { - success = EmptyClipboard (); + /* the caller calls handle_selection_clear(). */ + success = mswindows_empty_clipboard (); /* Close it regardless of whether empty worked. */ if (!CloseClipboard ()) success = FALSE; @@ -601,3 +662,11 @@ Vhandle_alist = Qnil; staticpro (&Vhandle_alist); } + +void +init_select_mswindows (void) +{ + /* Reinitialise Vhandle_alist */ + /* #### Why do we need to do this? Somehow I added this. --ben */ + Vhandle_alist = Qnil; +}