home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / e20313sr.zip / emacs / 20.3.1 / src / pmselect.c < prev    next >
C/C++ Source or Header  |  1999-07-31  |  5KB  |  183 lines

  1. /* pmselect.c -- xselect.c for the OS/2 Presentation Manager
  2.    Copyright (C) 1993-1996 Eberhard Mattes.
  3.  
  4. This file is part of GNU Emacs.
  5.  
  6. GNU Emacs is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU Emacs is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU Emacs; see the file COPYING.  If not, write to
  18. the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. Boston, MA 02111-1307, USA.  */
  20.  
  21.  
  22. #include <stdio.h>
  23. #include "config.h"
  24. #include "lisp.h"
  25. #include "frame.h"
  26. #include "blockinput.h"
  27. #include "pmterm.h"
  28. #include "pmemacs.h"
  29. #include "charset.h"
  30. #include "coding.h"
  31.  
  32. Lisp_Object QCLIPBOARD;
  33.  
  34. /* Coding system for communicating with other Windows programs via the
  35.    clipboard.  */
  36. static Lisp_Object Vselection_coding_system;
  37.  
  38.  
  39. void
  40. x_clear_frame_selections (f)
  41.      FRAME_PTR f;
  42. {
  43. }
  44.  
  45.  
  46. DEFUN ("x-selection-owner-p", Fx_selection_owner_p, Sx_selection_owner_p,
  47.   0, 1, 0,
  48.   "Whether the current Emacs process owns the given X Selection.\n\
  49. The arg should be the name of the selection in question, typically one of\n\
  50. the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.\n\
  51. \(Those are literal upper-case symbol names, since that's what X expects.)\n\
  52. For convenience, the symbol nil is the same as `PRIMARY',\n\
  53. and t is the same as `SECONDARY'.)")
  54.   (selection)
  55.      Lisp_Object selection;
  56. {
  57.   return Qnil;
  58. }
  59.  
  60.  
  61. DEFUN ("x-selection-exists-p", Fx_selection_exists_p, Sx_selection_exists_p,
  62.   0, 1, 0,
  63.   "Whether there is an owner for the given X Selection.\n\
  64. The arg should be the name of the selection in question, typically one of\n\
  65. the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.\n\
  66. \(Those are literal upper-case symbol names, since that's what X expects.)\n\
  67. For convenience, the symbol nil is the same as `PRIMARY',\n\
  68. and t is the same as `SECONDARY'.)")
  69.   (selection)
  70.      Lisp_Object selection;
  71. {
  72.   return Qnil;
  73. }
  74.  
  75.  
  76. DEFUN ("pm-get-clipboard", Fpm_get_clipboard, Spm_get_clipboard,
  77.   0, 0, 0,
  78.   "Retrieve a text string from the clipboard.\n\
  79. Return the empty string if there is no text in the clipboard.")
  80.   ()
  81. {
  82.   pm_request pmr;
  83.   int size;
  84.   char *buf;
  85.   Lisp_Object result;
  86.  
  87.   BLOCK_INPUT;
  88.   pmr.paste.header.type = PMR_PASTE;
  89.   pmr.paste.header.frame = 0;
  90.   pmr.paste.serial = pm_serial++;
  91.   pmr.paste.get_text = 1;
  92.   pm_send (&pmr, sizeof (pmr));
  93.   buf = pm_receive (pmr.paste.serial, 0, &size, 0);
  94.   UNBLOCK_INPUT;
  95.   if (!buf)
  96.     result = make_string ("", 0);
  97.   else
  98.     {
  99.       _crlf (buf, size, &size);
  100.       result = make_string (buf, size);
  101.       xfree (buf);
  102.     }
  103.   return result;
  104. }
  105.  
  106.  
  107. DEFUN ("pm-clipboard-ready-p", Fpm_clipboard_ready_p, Spm_clipboard_ready_p,
  108.   0, 0, 0,
  109.   "Return t if a text is in the clipboard.")
  110.   ()
  111. {
  112.   pm_request pmr;
  113.   void *buf;
  114.   int size;
  115.  
  116.   BLOCK_INPUT;
  117.   pmr.paste.header.type = PMR_PASTE;
  118.   pmr.paste.header.frame = 0;
  119.   pmr.paste.serial = pm_serial++;
  120.   pmr.paste.get_text = 0;
  121.   pm_send (&pmr, sizeof (pmr));
  122.   buf = pm_receive (pmr.paste.serial, &size, 0, 0);
  123.   UNBLOCK_INPUT;
  124.   if (buf == NULL)
  125.     return Qnil;
  126.   return (size == 0 ? Qnil : Qt);
  127. }
  128.  
  129.  
  130. DEFUN ("pm-put-clipboard", Fpm_put_clipboard, Spm_put_clipboard,
  131.   1, 1, 0,
  132.   "Put a text string into the clipboard.")
  133.   (string)
  134.      Lisp_Object string;
  135. {
  136.   pm_request pmr;
  137.   unsigned long size, tmp;
  138.   char *p, *q, *buf;
  139.  
  140.   CHECK_STRING (string, 0);
  141.   p = XSTRING (string)->data;
  142.   size = XSTRING (string)->size;
  143.   for (tmp = size; tmp != 0; --tmp)
  144.     if (*p++ == '\n')
  145.       ++size;
  146.   buf = alloca (size);
  147.   p = XSTRING (string)->data;
  148.   q = buf;
  149.   for (tmp = XSTRING (string)->size; tmp != 0; --tmp)
  150.     {
  151.       if (*p == '\n')
  152.         *q++ = '\r';
  153.       *q++ = *p++;
  154.     }
  155.   pmr.cut.header.type = PMR_CUT;
  156.   pmr.cut.header.frame = 0;
  157.   pmr.cut.size = size;
  158.   pm_send (&pmr, sizeof (pmr));
  159.   pm_send (buf, size);
  160.   return Qnil;
  161. }
  162.  
  163.  
  164. void syms_of_xselect ()
  165. {
  166.   defsubr (&Sx_selection_owner_p);  
  167.   defsubr (&Sx_selection_exists_p);
  168.   defsubr (&Spm_get_clipboard);
  169.   defsubr (&Spm_put_clipboard);
  170.   defsubr (&Spm_clipboard_ready_p);
  171.  
  172.   DEFVAR_LISP ("selection-coding-system", &Vselection_coding_system,
  173.     "Coding system for communicating with other X clients.\n\
  174. When sending or receiving text via cut_buffer, selection, and clipboard,\n\
  175. the text is encoded or decoded by this coding system.\n\
  176. A default value is `compound-text'");
  177.   Vselection_coding_system=intern ("iso-latin-1-dos");
  178.  
  179.   QCLIPBOARD = intern ("CLIPBOARD");    staticpro (&QCLIPBOARD);
  180.  
  181.   
  182. }
  183.