221
|
1 ;;; msw-select.el --- Lisp interface to mswindows selections.
|
|
2
|
|
3 ;; Copyright (C) 1990, 1997 Free Software Foundation, Inc.
|
|
4 ;; Copyright (C) 1995 Sun Microsystems.
|
|
5
|
|
6 ;; Maintainer: XEmacs Development Team
|
|
7 ;; Keywords: extensions, dumped
|
|
8
|
|
9 ;; This file is part of XEmacs.
|
|
10
|
|
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)
|
|
14 ;; any later version.
|
|
15
|
|
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.
|
|
20
|
|
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.
|
|
25
|
|
26 ;;; Synched up with: Not in FSF
|
|
27
|
|
28 ;;; Commentary:
|
|
29
|
|
30 ;; This file is dumped with XEmacs (when mswindows support is compiled in).
|
|
31 ;; #### Only copes with copying/pasting text
|
|
32
|
|
33 ;;; Code:
|
|
34
|
|
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."
|
|
38 (interactive "*")
|
|
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"))
|
|
43 (if s
|
|
44 (if mouse-track-rectangle-p
|
|
45 (delete-rectangle s e)
|
|
46 (delete-region s e)))
|
|
47 (push-mark)
|
|
48 (if mouse-track-rectangle-p
|
|
49 (insert-rectangle clip)
|
|
50 (insert clip))))
|
|
51
|
284
|
52 (defun mswindows-clear-clipboard ()
|
|
53 "Delete the selection without copying it to the clipboard or the kill ring."
|
|
54 (interactive "*")
|
|
55 (mswindows-cut-copy-clear-clipboard 'clear))
|
|
56
|
221
|
57 (defun mswindows-copy-clipboard ()
|
|
58 "Copy the selection to the mswindows clipboard and to the kill ring."
|
|
59 (interactive)
|
284
|
60 (mswindows-cut-copy-clear-clipboard 'copy))
|
221
|
61
|
|
62 (defun mswindows-cut-clipboard ()
|
|
63 "Copy the selection to the mswindows clipboard and to the kill ring,
|
|
64 then delete it."
|
|
65 (interactive "*")
|
284
|
66 (mswindows-cut-copy-clear-clipboard 'cut))
|
221
|
67
|
284
|
68 (defun mswindows-cut-copy-clear-clipboard (mode)
|
221
|
69 "Don't use this function.
|
284
|
70 Use mswindows-cut-clipboard, mswindows-copy-clipboard or
|
|
71 mswindows-clear-clipboard instead."
|
|
72 (or (memq mode '(cut copy clear)) (error "unkown mode %S" mode))
|
221
|
73 (setq last-command nil)
|
|
74 (let ((s (mark-marker)) (e (point-marker)))
|
|
75 (if s
|
|
76 (progn
|
|
77 (if mouse-track-rectangle-p
|
|
78 (progn
|
|
79 (setq killed-rectangle (extract-rectangle s e))
|
|
80 (kill-new (mapconcat 'identity killed-rectangle "\n")))
|
|
81 (copy-region-as-kill s e))
|
284
|
82 (if (memq mode '(cut copy))
|
|
83 (mswindows-set-clipboard (car kill-ring)))
|
|
84 (if (memq mode '(cut clear))
|
221
|
85 (if mouse-track-rectangle-p
|
|
86 (delete-rectangle s e)
|
|
87 (delete-region s e))
|
|
88 ;; mswindows apps normally leave the selection active but that feels weird here
|
|
89 ;; (setq zmacs-region-stays t)
|
|
90 ))
|
|
91 (error "there is no selection to cut or copy"))))
|
280
|
92
|
|
93 (defvar mswindows-selection-owned-p nil
|
|
94 "Whether we have a selection or not.
|
|
95 MS-Windows has no concept of ownership; don't use this.")
|
|
96
|
|
97 (defun mswindows-own-selection (data &optional type)
|
|
98 "Make an MS Windows selection of type TYPE and value DATA.
|
|
99 The argument TYPE is ignored, and DATA specifies the contents.
|
|
100 DATA may be a string,
|
|
101 a symbol, an integer (or a cons of two integers or list of two integers).
|
|
102
|
|
103 The selection may also be a cons of two markers pointing to the same buffer,
|
|
104 or an overlay. In these cases, the selection is considered to be the text
|
|
105 between the markers *at whatever time the selection is examined*.
|
|
106 Thus, editing done in the buffer after you specify the selection
|
|
107 can alter the effective value of the selection.
|
|
108
|
|
109 The data may also be a vector of valid non-vector selection values.
|
|
110
|
|
111 Interactively, the text of the region is used as the selection value."
|
|
112 (interactive (if (not current-prefix-arg)
|
|
113 (list (read-string "Store text for pasting: "))
|
|
114 (list (substring (region-beginning) (region-end)))))
|
|
115 (or (valid-simple-selection-p data)
|
|
116 (and (vectorp data)
|
|
117 (let ((valid t)
|
|
118 (i (1- (length data))))
|
|
119 (while (>= i 0)
|
|
120 (or (valid-simple-selection-p (aref data i))
|
|
121 (setq valid nil))
|
|
122 (setq i (1- i)))
|
|
123 valid))
|
|
124 (signal 'error (list "invalid selection" data)))
|
|
125 (if data
|
|
126 (setq mswindows-selection-owned-p data)
|
|
127 (setq mswindows-selection-owned-p nil))
|
|
128 (setq primary-selection-extent
|
|
129 (select-make-extent-for-selection
|
|
130 data primary-selection-extent))
|
|
131 (setq zmacs-region-stays t)
|
|
132 data)
|
|
133
|
|
134 (defun mswindows-disown-selection (&optional secondary-p)
|
|
135 "Assuming we own the selection, disown it. With an argument, discard the
|
|
136 secondary selection instead of the primary selection."
|
|
137 (setq mswindows-selection-owned-p nil))
|
|
138
|
|
139 (defun mswindows-selection-owner-p (&optional selection)
|
|
140 "Return t if current emacs process owns the given Selection.
|
|
141 The arg is ignored."
|
|
142 (not (eq mswindows-selection-owned-p nil)))
|
|
143
|