annotate lisp/x11/x-mouse.el @ 78:c7528f8e288d r20-0b34

Import from CVS: tag r20-0b34
author cvs
date Mon, 13 Aug 2007 09:05:42 +0200
parents 131b0175ea99
children 25f70ba0133c
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 (setq mouse-yank-function 'x-yank-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 (defun x-mouse-kill (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 "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
31 to the cut buffer"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 (interactive "@e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (let ((old-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (mouse-set-point event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (let ((s (buffer-substring old-point (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (x-own-clipboard s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (x-store-cutbuffer s))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (kill-region old-point (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (defun x-yank-function ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 "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
42 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
43 (push-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (if (region-active-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (if (consp zmacs-region-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;; pirated code from insert-rectangle in rect.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;; perhaps that code should be modified to handle a list of extents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;; as the rectangle to be inserted?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (let ((lines zmacs-region-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (insertcolumn (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (first t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (push-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (while lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (or first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (or (bolp) (insert ?\n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (move-to-column insertcolumn t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (setq first nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (insert (extent-string (car lines)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (setq lines (cdr lines))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (insert (extent-string zmacs-region-extent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (x-insert-selection t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (defun x-insert-selection (&optional check-cutbuffer-p move-point-event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 "Insert the current selection into buffer at point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (let ((text (if check-cutbuffer-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (or (condition-case () (x-get-selection) (error ()))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (x-get-cutbuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (error "No selection or cut buffer available"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (x-get-selection))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (cond (move-point-event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (mouse-set-point move-point-event)
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 ((interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (push-mark (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (insert text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (make-obsolete 'x-set-point-and-insert-selection 'mouse-yank)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (defun x-set-point-and-insert-selection (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 "Set point where clicked and insert the primary selection or the cut buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (interactive "e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (let ((mouse-yank-at-point nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (mouse-yank event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (defun x-set-point-and-move-selection (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 "Set point where clicked and move the selected text to that location."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (interactive "e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;; 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
92 ;; to fail; just let the appropriate error message get issued. (We need
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;; to insert the selection and set point first, or the selection may
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;; get inserted at the wrong place.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (and (x-selection-owner-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 primary-selection-extent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (x-insert-selection t event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (x-kill-primary-selection))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (defun mouse-track-and-copy-to-cutbuffer (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 "Make a selection like `mouse-track', but also copy it to the cutbuffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (interactive "e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (mouse-track event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ((null primary-selection-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 ((consp primary-selection-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (set-buffer (extent-object (car primary-selection-extent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (x-store-cutbuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (mapconcat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 'identity
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (extract-rectangle
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (extent-start-position (car primary-selection-extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (extent-end-position (car (reverse primary-selection-extent))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 "\n"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (set-buffer (extent-object primary-selection-extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (x-store-cutbuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (buffer-substring (extent-start-position primary-selection-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (extent-end-position primary-selection-extent)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (defvar x-pointers-initialized nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (defun x-init-pointer-shape (device)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 "Initializes the mouse-pointers of the given device from the resource
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 database."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (if x-pointers-initialized ; only do it when the first device is created
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (set-glyph-image text-pointer-glyph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (or (x-get-resource "textPointer" "Cursor" 'string device)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 "xterm"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (set-glyph-image selection-pointer-glyph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (or (x-get-resource "selectionPointer" "Cursor" 'string device)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 "top_left_arrow"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (set-glyph-image nontext-pointer-glyph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (or (x-get-resource "spacePointer" "Cursor" 'string device)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 "xterm")) ; was "crosshair"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (set-glyph-image modeline-pointer-glyph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (or (x-get-resource "modeLinePointer" "Cursor" 'string device)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 "sb_v_double_arrow"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (set-glyph-image gc-pointer-glyph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (or (x-get-resource "gcPointer" "Cursor" 'string device)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 "watch"))
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
147 (when (featurep 'scrollbar)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
148 (set-glyph-image
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
149 scrollbar-pointer-glyph
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
150 (or (x-get-resource "scrollbarPointer" "Cursor" 'string device)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
151 "top_left_arrow")))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (set-glyph-image busy-pointer-glyph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (or (x-get-resource "busyPointer" "Cursor" 'string device)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 "watch"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (set-glyph-image toolbar-pointer-glyph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (or (x-get-resource "toolBarPointer" "Cursor" 'string device)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 "left_ptr"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (let ((fg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (x-get-resource "pointerColor" "Foreground" 'string device)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (and fg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (set-face-foreground 'pointer fg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (let ((bg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (x-get-resource "pointerBackground" "Background" 'string device)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (and bg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (set-face-background 'pointer bg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (setq x-pointers-initialized t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168