annotate lisp/x11/x-mouse.el @ 172:a38aed19690b

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