1 ;;; msw-select.el --- Lisp interface to mswindows selections.
3 ;; Copyright (C) 1990, 1997 Free Software Foundation, Inc.
4 ;; Copyright (C) 1995 Sun Microsystems.
6 ;; Maintainer: XEmacs Development Team
7 ;; Keywords: extensions, dumped
9 ;; This file is part of XEmacs.
11 ;; XEmacs is free software; you can redistribute it and/or modify it
12 ;; under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; XEmacs is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
26 ;;; Synched up with: Not in FSF
30 ;; This file is dumped with XEmacs (when mswindows support is compiled in).
31 ;; #### Only copes with copying/pasting text
35 (defun mswindows-paste-clipboard ()
36 "Insert the current contents of the mswindows clipboard at point,
37 replacing the active selection if there is one."
39 (setq last-command nil)
40 (setq this-command 'yank) ; so that yank-pop works.
41 (let ((clip (mswindows-get-clipboard)) (s (mark-marker)) (e (point-marker)))
42 (or clip (error "there is no text on the clipboard"))
44 (if mouse-track-rectangle-p
45 (delete-rectangle s e)
48 (if mouse-track-rectangle-p
49 (insert-rectangle clip)
52 (defun mswindows-own-clipboard (string)
53 "Paste the given string to the mswindows clipboard."
54 (mswindows-set-clipboard string))
56 (defvar mswindows-selection-owned-p nil
57 "Whether we have a selection or not.
58 MS-Windows has no concept of ownership; don't use this.")
60 (defun mswindows-own-selection (data &optional type)
61 "Make an MS-Windows selection of type TYPE and value DATA.
62 The argument TYPE is ignored, and DATA specifies the contents.
64 a symbol, an integer (or a cons of two integers or list of two integers).
66 The selection may also be a cons of two markers pointing to the same buffer,
67 or an overlay. In these cases, the selection is considered to be the text
68 between the markers *at whatever time the selection is examined*.
69 Thus, editing done in the buffer after you specify the selection
70 can alter the effective value of the selection.
72 The data may also be a vector of valid non-vector selection values.
74 Interactively, the text of the region is used as the selection value."
75 (interactive (if (not current-prefix-arg)
76 (list (read-string "Store text for pasting: "))
77 (list (substring (region-beginning) (region-end)))))
78 (or (valid-simple-selection-p data)
81 (i (1- (length data))))
83 (or (valid-simple-selection-p (aref data i))
87 (signal 'error (list "invalid selection" data)))
89 (setq mswindows-selection-owned-p data)
90 (setq mswindows-selection-owned-p nil))
91 (setq primary-selection-extent
92 (select-make-extent-for-selection
93 data primary-selection-extent))
94 (setq zmacs-region-stays t)
97 (defun mswindows-disown-selection (&optional secondary-p)
98 "Assuming we own the selection, disown it. With an argument, discard the
99 secondary selection instead of the primary selection."
100 (setq mswindows-selection-owned-p nil)
101 (mswindows-delete-selection))
103 (defun mswindows-selection-owner-p (&optional selection)
104 "Return t if current emacs process owns the given Selection.
106 (not (eq mswindows-selection-owned-p nil)))