annotate lisp/x11/x-mouse.el @ 0:376386a54a3c r19-14

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