annotate lisp/term/sun-mouse.el @ 444:576fb035e263 r21-2-37

Import from CVS: tag r21-2-37
author cvs
date Mon, 13 Aug 2007 11:36:19 +0200
parents 3ecd8885ac67
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 ;;; sun-mouse.el --- mouse handling for Sun windows
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 ;; Copyright (C) 1987, 1997 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 ;; Author: Jeff Peck
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 ;; Maintainer: FSF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 ;; Keywords: hardware
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 ;; under the terms of the GNU General Public License as published by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 ;; any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 ;; General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 ;; 02111-1307, USA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 ;;; Synched up with: Unknown
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 ;;; Commentary:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 ;; Jeff Peck, Sun Microsystems, Jan 1987.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 ;; Original idea by Stan Jefferson
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 ;; Modelled after the GNUEMACS keymap interface.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 ;; User Functions:
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
37 ;; make-mousemap, copy-mousemap,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 ;; define-mouse, global-set-mouse, local-set-mouse,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 ;; use-global-mousemap, use-local-mousemap,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 ;; mouse-lookup, describe-mouse-bindings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 ;; Options:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 ;; extra-click-wait, scrollbar-width
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 ;;; Code:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 (defvar extra-click-wait 150
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 "*Number of milliseconds to wait for an extra click.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 Set this to zero if you don't want chords or double clicks.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 (defvar scrollbar-width 5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 "*The character width of the scrollbar.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 The cursor is deemed to be in the right edge scrollbar if it is this near the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 right edge, and more than two chars past the end of the indicated line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 Setting to nil limits the scrollbar to the edge or vertical dividing bar.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 ;;; Mousemaps
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 (defun make-mousemap ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 "Returns a new mousemap."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 (cons 'mousemap nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 (defun copy-mousemap (mousemap)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 "Return a copy of mousemap."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 (copy-alist mousemap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 (defun define-mouse (mousemap mouse-list def)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 "Args MOUSEMAP, MOUSE-LIST, DEF. Define MOUSE-LIST in MOUSEMAP as DEF.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 MOUSE-LIST is a list of atoms specifying a mouse hit according to these rules:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 * One of these atoms specifies the active region of the definition.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 text, scrollbar, modeline, minibuffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 * One or two or these atoms specify the button or button combination.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 left, middle, right, double
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 * Any combination of these atoms specify the active shift keys.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 control, shift, meta
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 * With a single unshifted button, you can add
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 up
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 to indicate an up-click.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 The atom `double' is used with a button designator to denote a double click.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 Two button chords are denoted by listing the two buttons.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 See sun-mouse-handler for the treatment of the form DEF."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 (mousemap-set (mouse-list-to-mouse-code mouse-list) mousemap def))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 (defun global-set-mouse (mouse-list def)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 "Give MOUSE-EVENT-LIST a local definition of DEF.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 See define-mouse for a description of MOUSE-EVENT-LIST and DEF.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 Note that if MOUSE-EVENT-LIST has a local definition in the current buffer,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 that local definition will continue to shadow any global definition."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 (interactive "xMouse event: \nxDefinition: ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 (define-mouse current-global-mousemap mouse-list def))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 (defun local-set-mouse (mouse-list def)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 "Give MOUSE-EVENT-LIST a local definition of DEF.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 See define-mouse for a description of the arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 The definition goes in the current buffer's local mousemap.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 Normally buffers in the same major mode share a local mousemap."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 (interactive "xMouse event: \nxDefinition: ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 (if (null current-local-mousemap)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 (setq current-local-mousemap (make-mousemap)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 (define-mouse current-local-mousemap mouse-list def))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 (defun use-global-mousemap (mousemap)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 "Selects MOUSEMAP as the global mousemap."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 (setq current-global-mousemap mousemap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 (defun use-local-mousemap (mousemap)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 "Selects MOUSEMAP as the local mousemap.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 nil for MOUSEMAP means no local mousemap."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 (setq current-local-mousemap mousemap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 ;;; Interface to the Mouse encoding defined in Emacstool.c
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 ;;; Called when mouse-prefix is sent to emacs, additional
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 ;;; information is read in as a list (button x y time-delta)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 ;;; First, some generally useful functions:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 (defun logtest (x y)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 "True if any bits set in X are also set in Y.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 Just like the Common Lisp function of the same name."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 (not (zerop (logand x y))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 ;;; Hit accessors.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 (defconst sm::ButtonBits 7) ; Lowest 3 bits.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 (defconst sm::ShiftmaskBits 56) ; Second lowest 3 bits (56 = 63 - 7).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 (defconst sm::DoubleBits 64) ; Bit 7.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 (defconst sm::UpBits 128) ; Bit 8.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 ;;; All the useful code bits
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 (defmacro sm::hit-code (hit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 `(nth 0 ,hit))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 ;;; The button, or buttons if a chord.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 (defmacro sm::hit-button (hit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 `(logand sm::ButtonBits (nth 0 ,hit)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 ;;; The shift, control, and meta flags.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 (defmacro sm::hit-shiftmask (hit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 `(logand sm::ShiftmaskBits (nth 0 ,hit)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 ;;; Set if a double click (but not a chord).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 (defmacro sm::hit-double (hit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 `(logand sm::DoubleBits (nth 0 ,hit)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 ;;; Set on button release (as opposed to button press).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 (defmacro sm::hit-up (hit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 `(logand sm::UpBits (nth 0 ,hit)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 ;;; Screen x position.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 (defmacro sm::hit-x (hit) `(nth 1 ,hit))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 ;;; Screen y position.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 (defmacro sm::hit-y (hit) `(nth 2 ,hit))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 ;;; Milliseconds since last hit.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 (defmacro sm::hit-delta (hit) `(nth 3 ,hit))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 (defmacro sm::hit-up-p (hit) ; A predicate.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 `(not (zerop (sm::hit-up ,hit))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 ;;; Loc accessors. for sm::window-xy
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 (defmacro sm::loc-w (loc) `(nth 0 ,loc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 (defmacro sm::loc-x (loc) `(nth 1 ,loc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 (defmacro sm::loc-y (loc) `(nth 2 ,loc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 ;;; this is used extensively by sun-fns.el
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 (defmacro eval-in-window (window &rest forms)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 "Switch to WINDOW, evaluate FORMS, return to original window."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 `(let ((OriginallySelectedWindow (selected-window)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 (unwind-protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 (select-window ,window)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 ,@forms)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 (select-window OriginallySelectedWindow))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 (put 'eval-in-window 'lisp-indent-function 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 ;;; handy utility, generalizes window_loop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 ;;; It's a macro (and does not evaluate its arguments).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 (defmacro eval-in-windows (form &optional yesmini)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 "Switches to each window and evaluates FORM. Optional argument
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 YESMINI says to include the minibuffer as a window.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 This is a macro, and does not evaluate its arguments."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 `(let ((OriginallySelectedWindow (selected-window)))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
192 (unwind-protect
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 (while (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 ,form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 (not (eq OriginallySelectedWindow
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 (select-window
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 (next-window nil ,yesmini))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 (select-window OriginallySelectedWindow))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 (put 'eval-in-window 'lisp-indent-function 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 (defun move-to-loc (x y)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 "Move cursor to window location X, Y.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 Handles wrapped and horizontally scrolled lines correctly."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 (move-to-window-line y)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 ;; window-line-end expects this to return the window column it moved to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 (let ((cc (current-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 (nc (move-to-column
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 (if (zerop (window-hscroll))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 (+ (current-column)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 (min (- (window-width) 2) ; To stay on the line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 x))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 (+ (window-hscroll) -1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 (min (1- (window-width)) ; To stay on the line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 x))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 (- nc cc)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 (defun minibuffer-window-p (window)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
219 "Return t if this WINDOW is a minibuffer."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 (= (frame-height)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 (nth 3 (window-edges window)) ; The bottom edge.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 (defun sun-mouse-handler (&optional hit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 "Evaluates the function or list associated with a mouse hit.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
227 Expecting to read a hit, which is a list: (button x y delta).
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
228 A form bound to button by define-mouse is found by mouse-lookup.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
229 The variables: *mouse-window*, *mouse-x*, *mouse-y* are bound.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 If the form is a symbol (symbolp), it is funcall'ed with *mouse-window*,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 *mouse-x*, and *mouse-y* as arguments; if the form is a list (listp),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 the form is eval'ed; if the form is neither of these, it is an error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 Returns nil."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 (if (null hit) (setq hit (sm::combined-hits)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 (let ((loc (sm::window-xy (sm::hit-x hit) (sm::hit-y hit))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 (let ((*mouse-window* (sm::loc-w loc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 (*mouse-x* (sm::loc-x loc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 (*mouse-y* (sm::loc-y loc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 (mouse-code (mouse-event-code hit loc)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 (let ((form (with-current-buffer (window-buffer *mouse-window*)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 (mouse-lookup mouse-code))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 (cond ((null form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 (if (not (sm::hit-up-p hit)) ; undefined up hits are ok.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
245 (error "Undefined mouse event: %s"
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
246 (prin1-to-string
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 (mouse-code-to-mouse-list mouse-code)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 ((symbolp form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 (setq this-command form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 (funcall form *mouse-window* *mouse-x* *mouse-y*))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 ((listp form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 (setq this-command (car form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 (eval form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 (error "Mouse action must be symbol or list, but was: %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 form))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 ;; Don't let 'sun-mouse-handler get on last-command,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 ;; since this function should be transparent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 (if (eq this-command 'sun-mouse-handler)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 (setq this-command last-command))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 ;; (message (prin1-to-string this-command)) ; to see what your buttons did
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 (defun sm::combined-hits ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 "Read and return next mouse-hit, include possible double click"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 (let ((hit1 (mouse-hit-read)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 (if (not (sm::hit-up-p hit1)) ; Up hits dont start doubles or chords.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 (let ((hit2 (mouse-second-hit extra-click-wait)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 (if hit2 ; we cons'd it, we can smash it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 ; (setf (sm::hit-code hit1) (logior (sm::hit-code hit1) ...))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
271 (setcar hit1 (logior (sm::hit-code hit1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 (sm::hit-code hit2)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
273 (if (= (sm::hit-button hit1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 (sm::hit-button hit2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 sm::DoubleBits 0))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 hit1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 (defun mouse-hit-read ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 "Read mouse-hit list from keyboard. Like (read 'read-char),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 but that uses minibuffer, and mucks up last-command."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 (let ((char-list nil) (char nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 (while (not (equal 13 ; Carriage return.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
283 (prog1 (setq char (read-char))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 (setq char-list (cons char char-list))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 (read (mapconcat 'char-to-string (nreverse char-list) ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 ;;; Second Click Hackery....
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 ;;; if prefix is not mouse-prefix, need a way to unread the char...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 ;;; or else have mouse flush input queue, or else need a peek at next char.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 ;;; There is no peek, but since one character can be unread, we only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 ;;; have to flush the queue when the command after a mouse click
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 ;;; starts with mouse-prefix1 (see below).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 ;;; Something to do later: We could buffer the read commands and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 ;;; execute them ourselves after doing the mouse command (using
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 ;;; lookup-key ??).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 (defvar mouse-prefix1 24 ; C-x
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 "First char of mouse-prefix. Used to detect double clicks and chords.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 (defvar mouse-prefix2 0 ; C-@
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 "Second char of mouse-prefix. Used to detect double clicks and chords.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 (defun mouse-second-hit (hit-wait)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 "Returns the next mouse hit occurring within HIT-WAIT milliseconds."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 (if (sit-for-millisecs hit-wait) nil ; No input within hit-wait millisecs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 (let ((pc1 (read-char)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 (if (or (not (equal pc1 mouse-prefix1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 (sit-for-millisecs 3)) ; a mouse prefix will have second char
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 ;; Can get away with one unread.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 (progn (setq unread-command-events (list pc1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 nil) ; Next input not mouse event.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 (let ((pc2 (read-char)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 (if (not (equal pc2 mouse-prefix2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 (progn (setq unread-command-events (list pc1)) ; put back the ^X
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 ;;; Too bad can't do two: (setq unread-command-event (list pc1 pc2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 ;;; Well, now we can, but I don't understand this code well enough to fix it...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 (ding) ; user will have to retype that pc2.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 nil) ; This input is not a mouse event.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 ;; Next input has mouse prefix and is within time limit.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 (let ((new-hit (mouse-hit-read))) ; Read the new hit.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 (if (sm::hit-up-p new-hit) ; Ignore up events when timing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 (mouse-second-hit (- hit-wait (sm::hit-delta new-hit)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 new-hit ; New down hit within limit, return it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 ))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 (defun sm::window-xy (x y)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 "Find window containing screen coordinates X and Y.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 Returns list (window x y) where x and y are relative to window."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 (or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 (catch 'found
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
334 (eval-in-windows
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 (let ((we (window-edges (selected-window))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 (let ((le (nth 0 we))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 (te (nth 1 we))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 (re (nth 2 we))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 (be (nth 3 we)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 (if (= re (frame-width))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 ;; include the continuation column with this window
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 (setq re (1+ re)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 (if (= be (frame-height))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 ;; include partial line at bottom of frame with this window
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 ;; id est, if window is not multple of char size.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 (setq be (1+ be)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 (if (and (>= x le) (< x re)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 (>= y te) (< y be))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
350 (throw 'found
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 (list (selected-window) (- x le) (- y te))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 t)) ; include minibuffer in eval-in-windows
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 ;;If x,y from a real mouse click, we shouldn't get here.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 (list nil x y)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 (defun sm::window-region (loc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 "Parse LOC into a region symbol.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 Returns one of (text scrollbar modeline minibuffer)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 (let ((w (sm::loc-w loc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 (x (sm::loc-x loc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 (y (sm::loc-y loc)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 (let ((right (1- (window-width w)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 (bottom (1- (window-height w))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 (cond ((minibuffer-window-p w) 'minibuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 ((>= y bottom) 'modeline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 ((>= x right) 'scrollbar)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 ;; far right column (window separator) is always a scrollbar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 ((and scrollbar-width
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 ;; mouse within scrollbar-width of edge.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 (>= x (- right scrollbar-width))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 ;; mouse a few chars past the end of line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 (>= x (+ 2 (window-line-end w x y))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 'scrollbar)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 (t 'text)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 (defun window-line-end (w x y)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
378 "Return WINDOW column (ignore X) containing end of line Y."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 (eval-in-window w (save-excursion (move-to-loc (frame-width) y))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 ;;; The encoding of mouse events into a mousemap.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 ;;; These values must agree with coding in emacstool:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 ;;;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
385 (defconst sm::keyword-alist
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 '((left . 1) (middle . 2) (right . 4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 (shift . 8) (control . 16) (meta . 32) (double . 64) (up . 128)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 (text . 256) (scrollbar . 512) (modeline . 1024) (minibuffer . 2048)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 (defun mouse-event-code (hit loc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 "Maps MOUSE-HIT and LOC into a mouse-code."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 ;;;Region is a code for one of text, modeline, scrollbar, or minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 (logior (sm::hit-code hit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 (mouse-region-to-code (sm::window-region loc))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 (defun mouse-region-to-code (region)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 "Returns partial mouse-code for specified REGION."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 (cdr (assq region sm::keyword-alist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 (defun mouse-list-to-mouse-code (mouse-list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 "Map a MOUSE-LIST to a mouse-code."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 (apply 'logior
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 (mapcar (function (lambda (x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 (cdr (assq x sm::keyword-alist))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 mouse-list)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 (defun mouse-code-to-mouse-list (mouse-code)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 "Map a MOUSE-CODE to a mouse-list."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 (apply 'nconc (mapcar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 (function (lambda (x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 (if (logtest mouse-code (cdr x))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 (list (car x)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 sm::keyword-alist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 (defun mousemap-set (code mousemap value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 (let* ((alist (cdr mousemap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 (assq-result (assq code alist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 (if assq-result
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 (setcdr assq-result value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 (setcdr mousemap (cons (cons code value) alist)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 (defun mousemap-get (code mousemap)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 (cdr (assq code (cdr mousemap))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 (defun mouse-lookup (mouse-code)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 "Look up MOUSE-EVENT and return the definition. nil means undefined."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 (or (mousemap-get mouse-code current-local-mousemap)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 (mousemap-get mouse-code current-global-mousemap)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 ;;; I (jpeck) don't understand the utility of the next four functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 ;;; ask Steven Greenbaum <froud@kestrel>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 (defun mouse-mask-lookup (mask list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 "Args MASK (a bit mask) and LIST (a list of (code . form) pairs).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 Returns a list of elements of LIST whose code or'ed with MASK is non-zero."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 (let ((result nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 (while list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 (if (logtest mask (car (car list)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 (setq result (cons (car list) result)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 (setq list (cdr list)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 result))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 (defun mouse-union (l l-unique)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 "Return the union of list of mouse (code . form) pairs L and L-UNIQUE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 where L-UNIQUE is considered to be union'ized already."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 (let ((result l-unique))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 (while l
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 (let ((code-form-pair (car l)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 (if (not (assq (car code-form-pair) result))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 (setq result (cons code-form-pair result))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 (setq l (cdr l)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 result))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 (defun mouse-union-first-preferred (l1 l2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 "Return the union of lists of mouse (code . form) pairs L1 and L2,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 based on the code's, with preference going to elements in L1."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 (mouse-union l2 (mouse-union l1 nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 (defun mouse-code-function-pairs-of-region (region)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 "Return a list of (code . function) pairs, where each code is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 currently set in the REGION."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 (let ((mask (mouse-region-to-code region)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 (mouse-union-first-preferred
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 (mouse-mask-lookup mask (cdr current-local-mousemap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 (mouse-mask-lookup mask (cdr current-global-mousemap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 )))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 ;;; Functions for DESCRIBE-MOUSE-BINDINGS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 ;;; And other mouse documentation functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 ;;; Still need a good procedure to print out a help sheet in readable format.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 (defun one-line-doc-string (function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 "Returns first line of documentation string for FUNCTION.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 If there is no documentation string, then the string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 \"No documentation\" is returned."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 (while (consp function) (setq function (car function)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 (let ((doc (documentation function)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 (if (null doc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 "No documentation."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 (string-match "^.*$" doc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 (substring doc 0 (match-end 0)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 (defun print-mouse-format (binding)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 (princ (car binding))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 (princ ": ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 (mapcar (function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 (lambda (mouse-list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 (princ mouse-list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 (princ " ")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 (cdr binding))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 (terpri)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 (princ " ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 (princ (one-line-doc-string (car binding)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 (terpri)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 (defun print-mouse-bindings (region)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 "Prints mouse-event bindings for REGION."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 (mapcar 'print-mouse-format (sm::event-bindings region)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 (defun sm::event-bindings (region)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 "Returns an alist of (function . (mouse-list1 ... mouse-listN)) for REGION,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 where each mouse-list is bound to the function in REGION."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 (let ((mouse-bindings (mouse-code-function-pairs-of-region region))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 (result nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 (while mouse-bindings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 (let* ((code-function-pair (car mouse-bindings))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 (current-entry (assoc (cdr code-function-pair) result)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 (if current-entry
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 (setcdr current-entry
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 (cons (mouse-code-to-mouse-list (car code-function-pair))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 (cdr current-entry)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 (setq result (cons (cons (cdr code-function-pair)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 (list (mouse-code-to-mouse-list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 (car code-function-pair))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 result))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 (setq mouse-bindings (cdr mouse-bindings))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 result))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 (defun describe-mouse-bindings ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 "Lists all current mouse-event bindings."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 (with-output-to-temp-buffer "*Help*"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 (princ "Text Region") (terpri)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 (princ "---- ------") (terpri)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 (print-mouse-bindings 'text) (terpri)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 (princ "Modeline Region") (terpri)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 (princ "-------- ------") (terpri)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 (print-mouse-bindings 'modeline) (terpri)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 (princ "Scrollbar Region") (terpri)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 (princ "--------- ------") (terpri)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 (print-mouse-bindings 'scrollbar)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 (defun describe-mouse-briefly (mouse-list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 "Print a short description of the function bound to MOUSE-LIST."
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
541 (interactive "xDescribe mouse list briefly: ")
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 (let ((function (mouse-lookup (mouse-list-to-mouse-code mouse-list))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 (if function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 (message "%s runs the command %s" mouse-list function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 (message "%s is undefined" mouse-list))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 (defun mouse-help-menu (function-and-binding)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 (cons (prin1-to-string (car function-and-binding))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 (menu-create ; Two sub-menu items of form ("String" . nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 (list (list (one-line-doc-string (car function-and-binding)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 (list (prin1-to-string (cdr function-and-binding)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 (defun mouse-help-region (w x y &optional region)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 "Displays a menu of mouse functions callable in this region."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 (let* ((region (or region (sm::window-region (list w x y))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 (mlist (mapcar (function mouse-help-menu)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 (sm::event-bindings region)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 (menu (menu-create (cons (list (symbol-name region)) mlist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 (item (sun-menu-evaluate w 0 y menu))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 )))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 ;;; Menu interface functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 ;;; use defmenu, because this interface is subject to change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 ;;; really need a menu-p, but we use vectorp and the context...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 (defun menu-create (items)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 "Functional form for defmenu, given a list of ITEMS returns a menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 Each ITEM is a (STRING . VALUE) pair."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 (apply 'vector items)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 (defmacro defmenu (menu &rest itemlist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 "Defines MENU to be a menu, the ITEMS are (STRING . VALUE) pairs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 See sun-menu-evaluate for interpretation of ITEMS."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 (list 'defconst menu (funcall 'menu-create itemlist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 (defun sun-menu-evaluate (*menu-window* *menu-x* *menu-y* menu)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 "Display a pop-up menu in WINDOW at X Y and evaluate selected item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 of MENU. MENU (or its symbol-value) should be a menu defined by defmenu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 A menu ITEM is a (STRING . FORM) pair;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 the FORM associated with the selected STRING is evaluated,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 and the resulting value is returned. Generally these FORMs are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 evaluated for their side-effects rather than their values.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
587 If the selected form is a menu or a symbol whose value is a menu,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 then it is displayed and evaluated as a pullright menu item.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 If the FORM of the first ITEM is nil, the STRING of the item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 is used as a label for the menu, i.e. it's inverted and not selectable."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 (if (symbolp menu) (setq menu (symbol-value menu)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 (eval (sun-menu-internal *menu-window* *menu-x* *menu-y* 4 menu)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 (defun sun-get-frame-data (code)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 "Sends the tty-sub-window escape sequence CODE to terminal,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 and returns a cons of the two numbers in returned escape sequence.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
598 That is it returns (cons <car> <cdr>) from \"\\E[n;<car>;<cdr>t\".
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 CODE values: 13 = Tool-Position, 14 = Size-in-Pixels, 18 = Size-in-Chars."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 (send-string-to-terminal (concat "\033[" (int-to-string code) "t"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 (let (char str x y)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 (while (not (equal 116 (setq char (read-char)))) ; #\t = 116
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 (setq str (cons char str)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 (setq str (mapconcat 'char-to-string (nreverse str) ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 (string-match ";[0-9]*" str)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 (setq y (substring str (1+ (match-beginning 0)) (match-end 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 (setq str (substring str (match-end 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 (string-match ";[0-9]*" str)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 (setq x (substring str (1+ (match-beginning 0)) (match-end 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 (cons (string-to-int y) (string-to-int x))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 (defun sm::font-size ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 "Returns font size in pixels: (cons Ysize Xsize)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 (let ((pix (sun-get-frame-data 14)) ; returns size in pixels
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 (chr (sun-get-frame-data 18))) ; returns size in chars
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 (cons (/ (car pix) (car chr)) (/ (cdr pix) (cdr chr)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
618 (defvar sm::menu-kludge-x nil
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 "Cached frame-to-window X-Offset for sm::menu-kludge")
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
620 (defvar sm::menu-kludge-y nil
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 "Cached frame-to-window Y-Offset for sm::menu-kludge")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 (defun sm::menu-kludge ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 "If sunfns.c uses <Menu_Base_Kludge> this function must be here!"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 (or sm::menu-kludge-y
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 (let ((fs (sm::font-size)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 (setq sm::menu-kludge-y (+ 8 (car fs)) ; a title line and borders
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 sm::menu-kludge-x 4))) ; best values depend on .defaults/Menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 (let ((wl (sun-get-frame-data 13))) ; returns frame location
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 (cons (+ (car wl) sm::menu-kludge-y)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 (+ (cdr wl) sm::menu-kludge-x))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 ;;; Function interface to selection/region
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 ;;; primitive functions are defined in sunfns.c
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 (defun sun-yank-selection ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 "Set mark and yank the contents of the current sunwindows selection.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 Insert contents into the current buffer at point."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 (interactive "*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 (set-mark-command nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 (insert-string (sun-get-selection)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
644 (defun sun-select-region (start end)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 "Set the sunwindows selection to the region in the current buffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 (interactive "r")
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
647 (sun-set-selection (buffer-substring start end)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 ;;; Support for emacstool
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 ;;; This closes the window instead of stopping emacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 (defun suspend-emacstool (&optional stuffstring)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 "Suspend emacstool.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 If running under as a detached process emacstool,
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
656 you don't want to suspend (there is no way to resume),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 just close the window, and wait for reopening."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 (run-hooks 'suspend-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 (if stuffstring (send-string-to-terminal stuffstring))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 (send-string-to-terminal "\033[2t") ; To close EmacsTool window.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 (run-hooks 'suspend-resume-hook))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 ;;; initialize mouse maps
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 (make-variable-buffer-local 'current-local-mousemap)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 (setq-default current-local-mousemap nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 (defvar current-global-mousemap (make-mousemap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 (provide 'sun-mouse)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 ;;; sun-mouse.el ends here