annotate lisp/msw-select.el @ 284:558f606b08ae r21-0b40

Import from CVS: tag r21-0b40
author cvs
date Mon, 13 Aug 2007 10:34:13 +0200
parents 7df0dd720c89
children 57709be46d1b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
221
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
1 ;;; msw-select.el --- Lisp interface to mswindows selections.
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
2
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
3 ;; Copyright (C) 1990, 1997 Free Software Foundation, Inc.
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
4 ;; Copyright (C) 1995 Sun Microsystems.
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
5
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
6 ;; Maintainer: XEmacs Development Team
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
7 ;; Keywords: extensions, dumped
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
8
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
10
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
12 ;; under the terms of the GNU General Public License as published by
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
14 ;; any later version.
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
15
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
19 ;; General Public License for more details.
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
20
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
24 ;; Boston, MA 02111-1307, USA.
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
25
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
26 ;;; Synched up with: Not in FSF
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
27
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
28 ;;; Commentary:
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
29
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
30 ;; This file is dumped with XEmacs (when mswindows support is compiled in).
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
31 ;; #### Only copes with copying/pasting text
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
32
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
33 ;;; Code:
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
34
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
35 (defun mswindows-paste-clipboard ()
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
36 "Insert the current contents of the mswindows clipboard at point,
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
37 replacing the active selection if there is one."
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
38 (interactive "*")
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
39 (setq last-command nil)
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
40 (setq this-command 'yank) ; so that yank-pop works.
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
41 (let ((clip (mswindows-get-clipboard)) (s (mark-marker)) (e (point-marker)))
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
42 (or clip (error "there is no text on the clipboard"))
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
43 (if s
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
44 (if mouse-track-rectangle-p
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
45 (delete-rectangle s e)
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
46 (delete-region s e)))
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
47 (push-mark)
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
48 (if mouse-track-rectangle-p
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
49 (insert-rectangle clip)
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
50 (insert clip))))
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
51
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 280
diff changeset
52 (defun mswindows-clear-clipboard ()
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 280
diff changeset
53 "Delete the selection without copying it to the clipboard or the kill ring."
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 280
diff changeset
54 (interactive "*")
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 280
diff changeset
55 (mswindows-cut-copy-clear-clipboard 'clear))
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 280
diff changeset
56
221
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
57 (defun mswindows-copy-clipboard ()
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
58 "Copy the selection to the mswindows clipboard and to the kill ring."
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
59 (interactive)
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 280
diff changeset
60 (mswindows-cut-copy-clear-clipboard 'copy))
221
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
61
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
62 (defun mswindows-cut-clipboard ()
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
63 "Copy the selection to the mswindows clipboard and to the kill ring,
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
64 then delete it."
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
65 (interactive "*")
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 280
diff changeset
66 (mswindows-cut-copy-clear-clipboard 'cut))
221
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
67
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 280
diff changeset
68 (defun mswindows-cut-copy-clear-clipboard (mode)
221
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
69 "Don't use this function.
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 280
diff changeset
70 Use mswindows-cut-clipboard, mswindows-copy-clipboard or
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 280
diff changeset
71 mswindows-clear-clipboard instead."
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 280
diff changeset
72 (or (memq mode '(cut copy clear)) (error "unkown mode %S" mode))
221
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
73 (setq last-command nil)
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
74 (let ((s (mark-marker)) (e (point-marker)))
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
75 (if s
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
76 (progn
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
77 (if mouse-track-rectangle-p
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
78 (progn
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
79 (setq killed-rectangle (extract-rectangle s e))
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
80 (kill-new (mapconcat 'identity killed-rectangle "\n")))
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
81 (copy-region-as-kill s e))
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 280
diff changeset
82 (if (memq mode '(cut copy))
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 280
diff changeset
83 (mswindows-set-clipboard (car kill-ring)))
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 280
diff changeset
84 (if (memq mode '(cut clear))
221
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
85 (if mouse-track-rectangle-p
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
86 (delete-rectangle s e)
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
87 (delete-region s e))
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
88 ;; mswindows apps normally leave the selection active but that feels weird here
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
89 ;; (setq zmacs-region-stays t)
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
90 ))
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
91 (error "there is no selection to cut or copy"))))
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
92
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
93 (defvar mswindows-selection-owned-p nil
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
94 "Whether we have a selection or not.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
95 MS-Windows has no concept of ownership; don't use this.")
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
96
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
97 (defun mswindows-own-selection (data &optional type)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
98 "Make an MS Windows selection of type TYPE and value DATA.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
99 The argument TYPE is ignored, and DATA specifies the contents.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
100 DATA may be a string,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
101 a symbol, an integer (or a cons of two integers or list of two integers).
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
102
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
103 The selection may also be a cons of two markers pointing to the same buffer,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
104 or an overlay. In these cases, the selection is considered to be the text
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
105 between the markers *at whatever time the selection is examined*.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
106 Thus, editing done in the buffer after you specify the selection
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
107 can alter the effective value of the selection.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
108
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
109 The data may also be a vector of valid non-vector selection values.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
110
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
111 Interactively, the text of the region is used as the selection value."
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
112 (interactive (if (not current-prefix-arg)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
113 (list (read-string "Store text for pasting: "))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
114 (list (substring (region-beginning) (region-end)))))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
115 (or (valid-simple-selection-p data)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
116 (and (vectorp data)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
117 (let ((valid t)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
118 (i (1- (length data))))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
119 (while (>= i 0)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
120 (or (valid-simple-selection-p (aref data i))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
121 (setq valid nil))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
122 (setq i (1- i)))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
123 valid))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
124 (signal 'error (list "invalid selection" data)))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
125 (if data
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
126 (setq mswindows-selection-owned-p data)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
127 (setq mswindows-selection-owned-p nil))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
128 (setq primary-selection-extent
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
129 (select-make-extent-for-selection
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
130 data primary-selection-extent))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
131 (setq zmacs-region-stays t)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
132 data)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
133
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
134 (defun mswindows-disown-selection (&optional secondary-p)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
135 "Assuming we own the selection, disown it. With an argument, discard the
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
136 secondary selection instead of the primary selection."
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
137 (setq mswindows-selection-owned-p nil))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
138
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
139 (defun mswindows-selection-owner-p (&optional selection)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
140 "Return t if current emacs process owns the given Selection.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
141 The arg is ignored."
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
142 (not (eq mswindows-selection-owned-p nil)))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
143