XEmacs 21.2.28 "Hermes".
[chise/xemacs-chise.git.1] / src / select-msw.c
index 2e4a127..a760eb0 100644 (file)
@@ -29,6 +29,7 @@ Boston, MA 02111-1307, USA.  */
 
 #include <config.h>
 #include "lisp.h"
+#include "frame.h"
 #include "select.h"
 
 #include "console-msw.h"
@@ -41,6 +42,7 @@ Copy STRING to the mswindows clipboard.
   int rawsize, size, i;
   unsigned char *src, *dst, *next;
   HGLOBAL h = NULL;
+  struct frame *f = NULL;
 
   CHECK_STRING (string);
 
@@ -52,7 +54,8 @@ Copy STRING to the mswindows clipboard.
     if (src[i] == '\n')
       size++;
 
-  if (!OpenClipboard (NULL))
+  f = selected_frame ();
+  if (!OpenClipboard (FRAME_MSWINDOWS_HANDLE (f)))
     return Qnil;
 
   if (!EmptyClipboard () ||
@@ -88,7 +91,6 @@ Copy STRING to the mswindows clipboard.
   i = (SetClipboardData (CF_TEXT, h) != NULL);
   
   CloseClipboard ();
-  GlobalFree (h);
   
   return i ? Qt : Qnil;
 }
@@ -101,7 +103,10 @@ mswindows_own_selection (Lisp_Object selection_name, Lisp_Object selection_value
   Lisp_Object converted_value = get_local_selection (selection_name, QSTRING);
   if (!NILP (converted_value) &&
       CONSP (converted_value) &&
-      EQ (XCAR (converted_value), QSTRING))
+      EQ (XCAR (converted_value), QSTRING) &&
+      /* pure mswindows behaviour only says we can own the selection 
+        if it is the clipboard */
+      EQ (selection_name, QCLIPBOARD))
     Fmswindows_set_clipboard (XCDR (converted_value));
 
   return Qnil;
@@ -162,7 +167,10 @@ Return the contents of the mswindows clipboard.
 static Lisp_Object
 mswindows_get_foreign_selection (Lisp_Object selection_symbol, Lisp_Object target_type)
 {
-  return Fmswindows_get_clipboard ();
+  if (EQ (selection_symbol, QCLIPBOARD))
+    return Fmswindows_get_clipboard ();
+  else
+    return Qnil;
 }
 
 DEFUN ("mswindows-selection-exists-p", Fmswindows_selection_exists_p, 0, 0, 0, /*
@@ -178,13 +186,23 @@ Remove the current MS-Windows selection from the clipboard.
 */
        ())
 {
-  return EmptyClipboard () ? Qt : Qnil;
+  BOOL success = OpenClipboard (NULL);
+  if (success)
+    {
+      success = EmptyClipboard ();
+      /* Close it regardless of whether empty worked. */
+      if (!CloseClipboard ())
+       success = FALSE;
+    }
+
+  return success ? Qt : Qnil;
 }
 
 static void
 mswindows_disown_selection (Lisp_Object selection, Lisp_Object timeval)
 {
-  Fmswindows_delete_selection ();
+  if (EQ (selection, QCLIPBOARD))
+    Fmswindows_delete_selection ();
 }
 
 \f