]> code.delx.au - gnu-emacs/blobdiff - src/w32select.c
(print): Generate a backslash in \2e10.
[gnu-emacs] / src / w32select.c
index b99e94a64729a2567555caadd45318b80a276462..23a0b5deaa0ce37ef500b97ea1960c475656fab4 100644 (file)
@@ -1,4 +1,4 @@
-/* Win32 Selection processing for emacs
+/* Selection processing for Emacs on the Microsoft W32 API.
    Copyright (C) 1993, 1994 Free Software Foundation.
    
 This file is part of GNU Emacs.
@@ -22,13 +22,15 @@ Boston, MA 02111-1307, USA.  */
 
 #include <config.h>
 #include "lisp.h"
-#include "w32term.h"   /* for all of the win32 includes */
+#include "w32term.h"   /* for all of the w32 includes */
 #include "dispextern.h"        /* frame.h seems to want this */
 #include "frame.h"     /* Need this to get the X window of selected_frame */
 #include "blockinput.h"
 
+Lisp_Object QCLIPBOARD;
+
 #if 0
-DEFUN ("win32-open-clipboard", Fwin32_open_clipboard, Swin32_open_clipboard, 0, 1, 0,
+DEFUN ("w32-open-clipboard", Fw32_open_clipboard, Sw32_open_clipboard, 0, 1, 0,
        "This opens the clipboard with the given frame pointer.")
      (frame)
      Lisp_Object frame;
@@ -40,14 +42,14 @@ DEFUN ("win32-open-clipboard", Fwin32_open_clipboard, Swin32_open_clipboard, 0,
   
   BLOCK_INPUT;
   
-  ok = OpenClipboard ((!NILP (frame) && FRAME_WIN32_P (XFRAME (frame))) ? FRAME_WIN32_WINDOW (XFRAME (frame)) : NULL);
+  ok = OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL);
   
   UNBLOCK_INPUT;
   
   return (ok ? frame : Qnil);
 }
 
-DEFUN ("win32-empty-clipboard", Fwin32_empty_clipboard, Swin32_empty_clipboard, 0, 0, 0,
+DEFUN ("w32-empty-clipboard", Fw32_empty_clipboard, Sw32_empty_clipboard, 0, 0, 0,
        "This empties the clipboard and assigns ownership to the window which opened the clipboard.")
      ()
 {
@@ -62,7 +64,7 @@ DEFUN ("win32-empty-clipboard", Fwin32_empty_clipboard, Swin32_empty_clipboard,
   return (ok ? Qt : Qnil);
 }
 
-DEFUN ("win32-close-clipboard", Fwin32_close_clipboard, Swin32_close_clipboard, 0, 0, 0,
+DEFUN ("w32-close-clipboard", Fw32_close_clipboard, Sw32_close_clipboard, 0, 0, 0,
        "This closes the clipboard.")
      ()
 {
@@ -79,7 +81,7 @@ DEFUN ("win32-close-clipboard", Fwin32_close_clipboard, Swin32_close_clipboard,
 
 #endif
 
-DEFUN ("win32-set-clipboard-data", Fwin32_set_clipboard_data, Swin32_set_clipboard_data, 1, 2, 0,
+DEFUN ("w32-set-clipboard-data", Fw32_set_clipboard_data, Sw32_set_clipboard_data, 1, 2, 0,
        "This sets the clipboard data to the given text.")
     (string, frame)
     Lisp_Object string, frame;
@@ -144,7 +146,7 @@ DEFUN ("win32-set-clipboard-data", Fwin32_set_clipboard_data, Swin32_set_clipboa
     
   GlobalUnlock (htext);
   
-  if (!OpenClipboard ((!NILP (frame) && FRAME_WIN32_P (XFRAME (frame))) ? FRAME_WIN32_WINDOW (XFRAME (frame)) : NULL))
+  if (!OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL))
     goto error;
   
   ok = EmptyClipboard () && SetClipboardData (CF_TEXT, htext);
@@ -164,7 +166,7 @@ DEFUN ("win32-set-clipboard-data", Fwin32_set_clipboard_data, Swin32_set_clipboa
   return (ok ? string : Qnil);
 }
 
-DEFUN ("win32-get-clipboard-data", Fwin32_get_clipboard_data, Swin32_get_clipboard_data, 0, 1, 0,
+DEFUN ("w32-get-clipboard-data", Fw32_get_clipboard_data, Sw32_get_clipboard_data, 0, 1, 0,
        "This gets the clipboard data in text format.")
      (frame)
      Lisp_Object frame;
@@ -177,7 +179,7 @@ DEFUN ("win32-get-clipboard-data", Fwin32_get_clipboard_data, Swin32_get_clipboa
   
   BLOCK_INPUT;
   
-  if (!OpenClipboard ((!NILP (frame) && FRAME_WIN32_P (XFRAME (frame))) ? FRAME_WIN32_WINDOW (XFRAME (frame)) : NULL))
+  if (!OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL))
     goto done;
   
   if ((htext = GetClipboardData (CF_TEXT)) == NULL)
@@ -243,14 +245,55 @@ DEFUN ("win32-get-clipboard-data", Fwin32_get_clipboard_data, Swin32_get_clipboa
   return (ret);
 }
 
+/* Support checking for a clipboard selection. */
+
+DEFUN ("x-selection-exists-p", Fx_selection_exists_p, Sx_selection_exists_p,
+  0, 1, 0,
+  "Whether there is an owner for the given X Selection.\n\
+The arg should be the name of the selection in question, typically one of\n\
+the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.\n\
+\(Those are literal upper-case symbol names, since that's what X expects.)\n\
+For convenience, the symbol nil is the same as `PRIMARY',\n\
+and t is the same as `SECONDARY'.")
+  (selection)
+     Lisp_Object selection;
+{
+  CHECK_SYMBOL (selection, 0);
+
+  /* Return nil for PRIMARY and SECONDARY selections; for CLIPBOARD, check
+     if the clipboard currently has valid text format contents. */
+
+  if (EQ (selection, QCLIPBOARD))
+    {
+      Lisp_Object val = Qnil;
+
+      if (OpenClipboard (NULL))
+       {
+         int format = 0;
+         while (format = EnumClipboardFormats (format))
+           if (format == CF_TEXT)
+             {
+               val = Qt;
+               break;
+             }
+         CloseClipboard ();
+       }
+      return val;
+    }
+  return Qnil;
+}
+
 void 
-syms_of_win32select ()
+syms_of_w32select ()
 {
 #if 0
-  defsubr (&Swin32_open_clipboard);
-  defsubr (&Swin32_empty_clipboard);
-  defsubr (&Swin32_close_clipboard);
+  defsubr (&Sw32_open_clipboard);
+  defsubr (&Sw32_empty_clipboard);
+  defsubr (&Sw32_close_clipboard);
 #endif
-  defsubr (&Swin32_set_clipboard_data);
-  defsubr (&Swin32_get_clipboard_data);
+  defsubr (&Sw32_set_clipboard_data);
+  defsubr (&Sw32_get_clipboard_data);
+  defsubr (&Sx_selection_exists_p);
+
+  QCLIPBOARD = intern ("CLIPBOARD");   staticpro (&QCLIPBOARD);
 }