annotate lisp/msw-select.el @ 412:697ef44129c6 r21-2-14

Import from CVS: tag r21-2-14
author cvs
date Mon, 13 Aug 2007 11:20:41 +0200
parents de805c49cfc1
children da8ed4261e83
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.
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
41 (let ((clip (mswindows-get-clipboard)) (s (mark-marker)) (e (point-marker)))
221
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
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
52 (defun mswindows-own-clipboard (string)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
53 "Paste the given string to the mswindows clipboard."
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
54 (mswindows-set-clipboard string))
221
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents:
diff changeset
55
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
56 (defvar mswindows-selection-owned-p nil
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
57 "Whether we have a selection or not.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
58 MS-Windows has no concept of ownership; don't use this.")
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
59
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
60 (defun mswindows-own-selection (data &optional type)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
61 "Make an MS-Windows selection of type TYPE and value DATA.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
62 The argument TYPE is ignored, and DATA specifies the contents.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
63 DATA may be a string,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
64 a symbol, an integer (or a cons of two integers or list of two integers).
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
65
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
66 The selection may also be a cons of two markers pointing to the same buffer,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
67 or an overlay. In these cases, the selection is considered to be the text
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
68 between the markers *at whatever time the selection is examined*.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
69 Thus, editing done in the buffer after you specify the selection
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
70 can alter the effective value of the selection.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
71
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
72 The data may also be a vector of valid non-vector selection values.
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
73
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
74 Interactively, the text of the region is used as the selection value."
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
75 (interactive (if (not current-prefix-arg)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
76 (list (read-string "Store text for pasting: "))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
77 (list (substring (region-beginning) (region-end)))))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
78 (or (valid-simple-selection-p data)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
79 (and (vectorp data)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
80 (let ((valid t)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
81 (i (1- (length data))))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
82 (while (>= i 0)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
83 (or (valid-simple-selection-p (aref data i))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
84 (setq valid nil))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
85 (setq i (1- i)))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
86 valid))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
87 (signal 'error (list "invalid selection" data)))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
88 (if data
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
89 (progn
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
90 ; (mswindows-set-clipboard data)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
91 (setq mswindows-selection-owned-p data))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
92 (setq mswindows-selection-owned-p nil))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
93 (setq primary-selection-extent
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
94 (select-make-extent-for-selection
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
95 data primary-selection-extent))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
96 (setq zmacs-region-stays t)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
97 data)
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 249
diff changeset
98
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
99 (defun mswindows-disown-selection (&optional secondary-p)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
100 "Assuming we own the selection, disown it. With an argument, discard the
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
101 secondary selection instead of the primary selection."
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
102 (setq mswindows-selection-owned-p nil)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
103 (mswindows-delete-selection))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
104
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
105 (defun mswindows-selection-owner-p (&optional selection)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
106 "Return t if current emacs process owns the given Selection.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
107 The arg is ignored."
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
108 (not (eq mswindows-selection-owned-p nil)))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
109