annotate lisp/x-mouse.el @ 293:403535bfea94

Added tag r21-0b44 for changeset 6cb5e14cd98e
author cvs
date Mon, 13 Aug 2007 10:37:16 +0200
parents 558f606b08ae
children 4b85ae5eabfb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1 ;;; x-mouse.el --- Mouse support for X window system.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985, 1992-4, 1997 Free Software Foundation, Inc.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4 ;; Copyright (C) 1995, 1996 Ben Wing.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
5
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
6 ;; Maintainer: XEmacs Development Team
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
7 ;; Keywords: mouse, dumped
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
8
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
10
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
12 ;; under the terms of the GNU General Public License as published by
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
14 ;; any later version.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
15
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
19 ;; General Public License for more details.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
20
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
24 ;; Boston, MA 02111-1307, USA.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
25
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
26 ;;; Synched up with: Not synched.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
27
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
28 ;;; Commentary:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
29
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
30 ;; This file is dumped with XEmacs (when X support is compiled in).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
31
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
32 ;;; Code:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
33
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
34 ;;(define-key global-map 'button2 'x-set-point-and-insert-selection)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
35 ;; This is reserved for use by Hyperbole.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
36 ;;(define-key global-map '(shift button2) 'x-mouse-kill)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
37 (define-key global-map '(control button2) 'x-set-point-and-move-selection)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
38
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
39 (defun x-mouse-kill (event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
40 "Kill the text between the point and mouse and copy it to the clipboard and
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
41 to the cut buffer"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
42 (interactive "@e")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
43 (let ((old-point (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
44 (mouse-set-point event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
45 (let ((s (buffer-substring old-point (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
46 (x-own-clipboard s)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
47 (x-store-cutbuffer s))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
48 (kill-region old-point (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
49
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
50 (defun x-yank-function ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
51 "Insert the current X selection or, if there is none, insert the X cutbuffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
52 A mark is pushed, so that the inserted text lies between point and mark."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
53 (push-mark)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
54 (if (region-active-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
55 (if (consp zmacs-region-extent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
56 ;; pirated code from insert-rectangle in rect.el
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
57 ;; perhaps that code should be modified to handle a list of extents
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
58 ;; as the rectangle to be inserted?
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
59 (let ((lines zmacs-region-extent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
60 (insertcolumn (current-column))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
61 (first t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
62 (push-mark)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
63 (while lines
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
64 (or first
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
65 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
66 (forward-line 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
67 (or (bolp) (insert ?\n))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
68 (move-to-column insertcolumn t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
69 (setq first nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
70 (insert (extent-string (car lines)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
71 (setq lines (cdr lines))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
72 (insert (extent-string zmacs-region-extent)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
73 (x-insert-selection t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
74
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
75 (defun x-insert-selection (&optional check-cutbuffer-p move-point-event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
76 "Insert the current selection into buffer at point."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
77 (interactive "P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
78 (let ((text (if check-cutbuffer-p
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
79 (or (condition-case () (x-get-selection) (error ()))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
80 (x-get-cutbuffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
81 (error "No selection or cut buffer available"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
82 (x-get-selection))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
83 (cond (move-point-event
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
84 (mouse-set-point move-point-event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
85 (push-mark (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
86 ((interactive-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
87 (push-mark (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
88 (insert text)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
89 ))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
90
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
91 (make-obsolete 'x-set-point-and-insert-selection 'mouse-yank)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
92 (defun x-set-point-and-insert-selection (event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
93 "Set point where clicked and insert the primary selection or the cut buffer."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
94 (interactive "e")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
95 (let ((mouse-yank-at-point nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
96 (mouse-yank event)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
97
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
98 (defun x-set-point-and-move-selection (event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
99 "Set point where clicked and move the selected text to that location."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
100 (interactive "e")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
101 ;; Don't try to move the selection if x-kill-primary-selection if going
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
102 ;; to fail; just let the appropriate error message get issued. (We need
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
103 ;; to insert the selection and set point first, or the selection may
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
104 ;; get inserted at the wrong place.)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
105 (and (x-selection-owner-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
106 primary-selection-extent
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
107 (x-insert-selection t event))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
108 (x-kill-primary-selection))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
109
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
110 (defun mouse-track-and-copy-to-cutbuffer (event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
111 "Make a selection like `mouse-track', but also copy it to the cutbuffer."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
112 (interactive "e")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
113 (mouse-track event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
114 (cond
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
115 ((null primary-selection-extent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
116 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
117 ((consp primary-selection-extent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
118 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
119 (set-buffer (extent-object (car primary-selection-extent)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
120 (x-store-cutbuffer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
121 (mapconcat
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
122 'identity
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
123 (extract-rectangle
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
124 (extent-start-position (car primary-selection-extent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
125 (extent-end-position (car (reverse primary-selection-extent))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
126 "\n"))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
127 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
128 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
129 (set-buffer (extent-object primary-selection-extent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
130 (x-store-cutbuffer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
131 (buffer-substring (extent-start-position primary-selection-extent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
132 (extent-end-position primary-selection-extent)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
133
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
134
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
135 (defvar x-pointers-initialized nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
136
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
137 (defun x-init-pointer-shape (device)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
138 "Initialize the mouse-pointers of DEVICE from the X resource database."
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
139 (if x-pointers-initialized ; only do it when the first device is created
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
140 nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
141 (set-glyph-image text-pointer-glyph
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
142 (or (x-get-resource "textPointer" "Cursor" 'string device)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
143 "xterm"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
144 (set-glyph-image selection-pointer-glyph
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
145 (or (x-get-resource "selectionPointer" "Cursor" 'string device)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
146 "top_left_arrow"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
147 (set-glyph-image nontext-pointer-glyph
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
148 (or (x-get-resource "spacePointer" "Cursor" 'string device)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
149 "xterm")) ; was "crosshair"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
150 (set-glyph-image modeline-pointer-glyph
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
151 (or (x-get-resource "modeLinePointer" "Cursor" 'string device)
265
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
152 ;; "fleur"))
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
153 "sb_v_double_arrow"))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
154 (set-glyph-image gc-pointer-glyph
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
155 (or (x-get-resource "gcPointer" "Cursor" 'string device)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
156 "watch"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
157 (when (featurep 'scrollbar)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
158 (set-glyph-image
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
159 scrollbar-pointer-glyph
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
160 (or (x-get-resource "scrollbarPointer" "Cursor" 'string device)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
161 "top_left_arrow")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
162 (set-glyph-image busy-pointer-glyph
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
163 (or (x-get-resource "busyPointer" "Cursor" 'string device)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
164 "watch"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
165 (set-glyph-image toolbar-pointer-glyph
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
166 (or (x-get-resource "toolBarPointer" "Cursor" 'string device)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
167 "left_ptr"))
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 272
diff changeset
168 (set-glyph-image divider-pointer-glyph
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 272
diff changeset
169 (or (x-get-resource "dividerPointer" "Cursor" 'string device)
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 272
diff changeset
170 "sb_h_double_arrow"))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
171 (let ((fg
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
172 (x-get-resource "pointerColor" "Foreground" 'string device)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
173 (and fg
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
174 (set-face-foreground 'pointer fg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
175 (let ((bg
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
176 (x-get-resource "pointerBackground" "Background" 'string device)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
177 (and bg
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
178 (set-face-background 'pointer bg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
179 (setq x-pointers-initialized t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
180 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
181
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
182 ;;; x-mouse.el ends here