1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
|
;;; hmouse-key.el --- Load "hmouse-sh.el" or "hmouse-reg.el" for Smart Key bindings.
;; Copyright (C) 1994-1995, 2006 Free Software Foundation, Inc.
;; Developed with support from Motorola Inc.
;; Author: Bob Weiner, Brown U.
;; Maintainer: Mats Lidell <matsl@contactor.se>
;; Keywords: hypermedia, mouse
;; This file is part of GNU Hyperbole.
;; GNU Hyperbole is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2, or (at
;; your option) any later version.
;; GNU Hyperbole is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;;
;; Supports Epoch, Lucid Emacs, X, Sunview, NEXTSTEP, and Apollo DM
;; window systems.
;;
;; 'hmouse-shift-buttons' globally binds the Action and Assist Mouse Keys
;; to either shifted or unshifted mouse buttons.
;;
;; 'hmouse-toggle-bindings' may be bound to a key. It switches between
;; the Hyperbole mouse bindings and previous mouse key bindings any time
;; after 'hmouse-shift-buttons' has been called.
;;
;;; Code:
;;;
;;; Other required Elisp libraries
;;;
(require 'hversion)
(require 'hmouse-drv)
(require 'h-skip-bytec "h-skip-bytec.lsp")
;;;
;;; Public variables
;;;
(eval (cdr (assoc hyperb:window-system
'(
;; XEmacs and Emacs 19 pre-load their mouse libraries, so
;; we shouldn't have to require them here.
;;
("xterm" . (require 'x-mouse)) ; X
("epoch" . (require 'mouse)) ; UofI Epoch
("next" . (load "eterm-fns" t)) ; NeXTstep
("sun" . (require 'sun-fns)) ; SunView
("apollo" . (require 'apollo)) ; Display Manager
))))
;;;
;;; Public functions
;;;
(defun hmouse-set-bindings (key-binding-list)
"Sets mouse keys used as Smart Keys to bindings in KEY-BINDING-LIST.
KEY-BINDING-LIST is the value returned by 'hmouse-get-bindings' prior to
Smart Key setup."
(cond
;;
;; GNU Emacs 19, Lucid Emacs, XEmacs or InfoDock
((or (if (not noninteractive) (or hyperb:xemacs-p hyperb:emacs19-p))
(equal hyperb:window-system "xemacs"))
(mapcar
(function
(lambda (key-and-binding)
(global-set-key (car key-and-binding) (cdr key-and-binding))))
key-binding-list))
;;
;; X
((equal hyperb:window-system "xterm")
(mapcar
(function
(lambda (key-and-binding)
(define-key mouse-map (car key-and-binding) (cdr key-and-binding))))
key-binding-list))
;;
;; Epoch
((equal hyperb:window-system "epoch")
(mapcar
(function
(lambda (key-and-binding)
(aset mouse::global-map (car key-and-binding)
(cdr key-and-binding))))
key-binding-list))
;;
;; SunView or NeXT
((or (equal hyperb:window-system "next")
(equal hyperb:window-system "sun"))
(mapcar
(function
(lambda (key-and-binding)
(global-set-mouse (car key-and-binding) (cdr key-and-binding))))
key-binding-list))
;;
;; Apollo Display Manager
((equal hyperb:window-system "apollo")
(if (string< emacs-version "18.58")
(mapcar
(function
(lambda (key-and-binding)
(global-set-key (car key-and-binding) (cdr key-and-binding))))
key-binding-list)
(mapcar
(function
(lambda (key-and-binding)
(define-key 'apollo-prefix (car key-and-binding)
(cdr key-and-binding))))
key-binding-list)))))
(defun hmouse-shift-buttons (&optional arg)
"Selects between shifted and unshifted Action and Assist mouse buttons.
With optional prefix ARG, use shifted buttons if ARG is positive or use
unshifted buttons otherwise. If ARG is nil, shifted buttons are used and
under InfoDock the middle button also acts as an Action Key."
(interactive "P")
(setq hmouse-shift-flag (if arg
(> (prefix-numeric-value arg) 0)
(not (and (boundp 'infodock-version)
infodock-version))))
(if hmouse-shift-flag
;; Action Key = shift-middle mouse key. Assist Key = shift-right mouse
;; key. Standard Hyperbole configuration.
(load "hmouse-sh")
;; Action Key = middle mouse key; Assist Key = right mouse key
;; InfoDock actually moves the Assist Key to the shift-right mouse key so
;; that the right key can be used for popup menus.
(load "hmouse-reg"))
;; Replace any original mouse bindings before moving Hyperbole bindings and
;; then force reinitialization of hmouse-previous-bindings.
(if (and hmouse-bindings-flag hmouse-previous-bindings)
(hmouse-set-bindings hmouse-previous-bindings))
(setq hmouse-bindings-flag nil
hmouse-previous-bindings nil)
;; Initialize Hyperbole mouse bindings.
(hmouse-setup)
(if (interactive-p)
(message "%s Action and Assist mouse buttons in use."
(if hmouse-shift-flag "Shifted" "Unshifted"))))
(defun hmouse-toggle-bindings ()
"Toggles between Smart Key mouse settings and their prior bindings."
(interactive)
(let ((key-binding-list (if hmouse-bindings-flag
hmouse-previous-bindings
hmouse-bindings))
(other-list-var (if hmouse-bindings-flag
'hmouse-bindings
'hmouse-previous-bindings)))
(if key-binding-list
(progn
(set other-list-var (hmouse-get-bindings))
(hmouse-set-bindings key-binding-list)
(message "%s mouse bindings in use."
(if (setq hmouse-bindings-flag (not hmouse-bindings-flag))
"Smart Key" "Personal")))
(error "(hmouse-toggle-bindings): Null %s." other-list-var))))
(defun hmouse-set-point-at (set-point-arg-list)
"Sets point to cursor position using SET-POINT-ARG-LIST and returns t.
If 'hmouse-set-point-command' is not bound to a function, this does nothing
and returns nil."
(if (fboundp hmouse-set-point-command)
(progn
(if (and (boundp 'drag-zone) drag-zone)
(progn (delete-zone drag-zone)
(setq drag-zone nil))
(and (boundp 'drag-button) drag-button
(progn (delete-button drag-button)
(setq drag-button nil))))
(or (if set-point-arg-list
(funcall hmouse-set-point-command set-point-arg-list)
(funcall hmouse-set-point-command))
t))))
;;;
;;; Private functions
;;;
(if (fboundp 'bind-apollo-mouse-button)
(progn
(if (string< emacs-version "18.58")
(defun apollo-mouse-key-and-binding (mouse-button)
"Returns binding for an Apollo MOUSE-BUTTON (a string) or nil if none."
(interactive "sMouse Button: ")
(let ((numeric-code (cdr (assoc mouse-button *apollo-mouse-buttons*))))
(if (null numeric-code)
(error "(hmouse-key): %s is not a valid Apollo mouse key name."
mouse-button))
(if (stringp numeric-code)
(setq numeric-code
(cdr (assoc numeric-code *apollo-mouse-buttons*))))
(let ((key-sequence (concat "\M-*" (char-to-string numeric-code))))
(cons key-sequence (global-key-binding key-sequence)))))
(defun apollo-mouse-key-and-binding (mouse-button)
"Returns binding for an Apollo MOUSE-BUTTON (a string) or nil if none."
(interactive "sMouse Button: ")
(let ((numeric-code (cdr (assoc mouse-button *apollo-mouse-buttons*))))
(if (null numeric-code)
(error "(hmouse-key): %s is not a valid Apollo mouse key name."
mouse-button))
(if (stringp numeric-code)
(setq numeric-code
(cdr (assoc numeric-code *apollo-mouse-buttons*))))
(let ((key-sequence (char-to-string numeric-code)))
(cons key-sequence (lookup-key 'apollo-prefix key-sequence)))))
)
(defun apollo-mouse-move-point (&optional no-mark)
"Used so that pressing the left mouse button, moving the cursor, and
releasing the left mouse button leaves the mark set to the initial position
and the point set to the final position. Useful for easily marking regions
of text. If the left mouse button is pressed and released at the same place,
the mark is left at the original position of the character cursor.
Returns (x y) frame coordinates of point in columns and lines."
(interactive)
(let* ((opoint (point))
(owindow (selected-window))
(x (- (read-char) 8))
(y (- (read-char) 8))
(edges (window-edges))
(window nil))
(while (and (not (eq window (selected-window)))
(or (< y (nth 1 edges))
(>= y (nth 3 edges))
(< x (nth 0 edges))
(>= x (nth 2 edges))))
(setq window (next-window window))
(setq edges (window-edges window)))
(if (and window (not (eq window (selected-window))))
(progn
(if (and (not *apollo-mouse-move-point-allow-minibuffer-exit*)
(eq (selected-window) (minibuffer-window)))
(error "Cannot use mouse to leave minibuffer!"))
(if (eq window (minibuffer-window))
(error "Cannot use mouse to enter minibuffer!"))))
(if window (select-window window))
(move-to-window-line (- y (nth 1 edges)))
(let* ((width-1 (1- (window-width window)))
(wraps (/ (current-column) width-1))
(prompt-length (if (eq (selected-window) (minibuffer-window))
(minibuffer-prompt-length)
0)))
(move-to-column (+ (- x (nth 0 edges) prompt-length)
(* wraps width-1))))
(if no-mark
(progn (setq window (selected-window))
(if (eq owindow window)
(if (equal opoint (point))
(pop-mark))
(select-window owindow)
(pop-mark)
(select-window window)))
(set-mark-command nil))
;; Return (x y) coords of point in column and frame line numbers.
(list x y)))
))
(defun action-key-depress (&rest args)
(interactive)
(require 'hsite)
(setq action-key-depress-prev-point (point-marker)
action-key-depressed-flag t
action-key-depress-args (hmouse-set-point args)
action-key-depress-window (selected-window)
action-key-release-args nil
action-key-release-window nil
action-key-release-prev-point nil)
(if assist-key-depressed-flag
(or action-key-help-flag
(setq assist-key-help-flag t))))
(defun assist-key-depress (&rest args)
(interactive)
(require 'hsite)
(setq assist-key-depress-prev-point (point-marker)
assist-key-depressed-flag t
assist-key-depress-args (hmouse-set-point args)
assist-key-depress-window (selected-window)
assist-key-release-args nil
assist-key-release-window nil
assist-key-release-prev-point nil)
(if action-key-depressed-flag
(or assist-key-help-flag
(setq action-key-help-flag t)))
)
(defun action-key-depress-emacs19 (event)
(interactive "e")
(require 'hsite)
(action-key-depress event))
(defun assist-key-depress-emacs19 (event)
(interactive "e")
(require 'hsite)
(assist-key-depress event))
(defun action-mouse-key-emacs19 (event)
"Set point to the current mouse cursor position and execute 'action-key'.
EVENT will be passed to 'hmouse-function'."
(interactive "e")
(action-mouse-key (hmouse-key-release-args-emacs19 event)))
(defun assist-mouse-key-emacs19 (event)
"Set point to the current mouse cursor position and execute 'action-key'.
EVENT will be passed to 'hmouse-function'."
(interactive "e")
(assist-mouse-key (hmouse-key-release-args-emacs19 event)))
(defun hmouse-key-release-args-emacs19 (event)
(let ((ev-type-str (and (listp event) (symbol-name (car event)))))
(if (or (and ev-type-str
(string-match "\\(double\\|triple\\)-mouse" ev-type-str))
(not (= (length event) 3)))
event
;; Remove depress coordinates and send only release coordinates.
(list (car event) (nth 2 event)))))
(defun hmouse-move-point-xemacs ()
(condition-case ()
(mouse-set-point current-mouse-event)
;; Catch "not in a window" errors, e.g. on modeline
(error nil)))
(defun hmouse-move-point-eterm (arg-list)
(apply 'mouse-move-point arg-list))
;;;
;;; Private variables
;;;
(defvar hmouse-bindings nil
"List of (key . binding) pairs for Smart Mouse Keys.")
(defvar hmouse-bindings-flag nil
"True if Smart Key mouse bindings are in use, else nil.")
(defvar hmouse-previous-bindings nil
"List of previous (key . binding) pairs for mouse keys used as Smart Keys.")
(provide 'hmouse-key)
;;; hmouse-key.el ends here
|