diff options
| author | Eli Zaretskii | 2001-11-12 11:39:45 +0000 |
|---|---|---|
| committer | Eli Zaretskii | 2001-11-12 11:39:45 +0000 |
| commit | 1d937026aabac8a10496bfa25e0857a62c978a9d (patch) | |
| tree | 5bafca6480a1b724e5e82bcf844bb88e02b7878a | |
| parent | 3d3f602a1b6bb0ca34cfb2fa0737d5786d48a08f (diff) | |
| download | emacs-1d937026aabac8a10496bfa25e0857a62c978a9d.tar.gz emacs-1d937026aabac8a10496bfa25e0857a62c978a9d.zip | |
(toplevel): Bind mouse buttons.
(calc-do-keypad): Don't attempt to use nonexistent global
mouse-map, use calc-keypad-map.
(calc-keypad-x-left-click): Renamed to calc-keypad-left-click.
(calc-keypad-left-click): Don't use mouse-map; update to new event
interface.
(calc-keypad-x-middle-click, calc-keypad-x-right-click): Ditto.
(calc-keypad-press): Use `unread-command-events' instead of
`unread-command-char'.
| -rw-r--r-- | lisp/calc/calc-keypd.el | 139 |
1 files changed, 46 insertions, 93 deletions
diff --git a/lisp/calc/calc-keypd.el b/lisp/calc/calc-keypd.el index 3c087abb072..0d84309a856 100644 --- a/lisp/calc/calc-keypd.el +++ b/lisp/calc/calc-keypd.el | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | ;; Calculator for GNU Emacs, part II [calc-keypd.el] | 1 | ;; Calculator for GNU Emacs, part II [calc-keypd.el] |
| 2 | ;; Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc. | 2 | ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. |
| 3 | ;; Written by Dave Gillespie, daveg@synaptics.com. | 3 | ;; Written by Dave Gillespie, daveg@synaptics.com. |
| 4 | 4 | ||
| 5 | ;; This file is part of GNU Emacs. | 5 | ;; This file is part of GNU Emacs. |
| @@ -30,45 +30,42 @@ | |||
| 30 | 30 | ||
| 31 | 31 | ||
| 32 | 32 | ||
| 33 | ;;; Pictorial interface to Calc using the X window system mouse. | 33 | ;;; Pictorial interface to Calc using a mouse. |
| 34 | 34 | ||
| 35 | (defvar calc-keypad-buffer nil) | 35 | (defvar calc-keypad-buffer nil) |
| 36 | (defvar calc-keypad-menu 0) | 36 | (defvar calc-keypad-menu 0) |
| 37 | (defvar calc-keypad-full-layout nil) | 37 | (defvar calc-keypad-full-layout nil) |
| 38 | (defvar calc-keypad-input nil) | 38 | (defvar calc-keypad-input nil) |
| 39 | (defvar calc-keypad-prev-input nil) | 39 | (defvar calc-keypad-prev-input nil) |
| 40 | (defvar calc-keypad-prev-x-left-click nil) | ||
| 41 | (defvar calc-keypad-prev-x-middle-click nil) | ||
| 42 | (defvar calc-keypad-prev-x-right-click nil) | ||
| 43 | (defvar calc-keypad-said-hello nil) | 40 | (defvar calc-keypad-said-hello nil) |
| 44 | 41 | ||
| 45 | (defvar calc-keypad-map nil) | 42 | (defvar calc-keypad-map nil) |
| 46 | (if calc-keypad-map | 43 | (unless calc-keypad-map |
| 47 | () | 44 | (let ((map (make-sparse-keymap))) |
| 48 | (setq calc-keypad-map (make-sparse-keymap)) | 45 | (define-key map " " 'calc-keypad-press) |
| 49 | (define-key calc-keypad-map " " 'calc-keypad-press) | 46 | (define-key map (kbd "RET") 'calc-keypad-press) |
| 50 | (define-key calc-keypad-map "\r" 'calc-keypad-press) | 47 | (define-key map (kbd "TAB") 'calc-keypad-menu) |
| 51 | (define-key calc-keypad-map "\t" 'calc-keypad-menu) | 48 | (define-key map "q" 'calc-keypad-off) |
| 52 | (define-key calc-keypad-map "q" 'calc-keypad-off)) | 49 | (define-key map [(mouse-3)] 'calc-keypad-right-click) |
| 50 | (define-key map [(mouse-2)] 'calc-keypad-middle-click) | ||
| 51 | (define-key map [(mouse-1)] 'calc-keypad-left-click) | ||
| 52 | (setq calc-keypad-map map))) | ||
| 53 | 53 | ||
| 54 | (defun calc-do-keypad (&optional full-display interactive) | 54 | (defun calc-do-keypad (&optional full-display interactive) |
| 55 | (if (string-match "^19" emacs-version) | ||
| 56 | (error "Sorry, calc-keypad not yet implemented for Emacs 19")) | ||
| 57 | (calc-create-buffer) | 55 | (calc-create-buffer) |
| 58 | (let ((calcbuf (current-buffer))) | 56 | (let ((calcbuf (current-buffer))) |
| 59 | (or (and calc-keypad-buffer | 57 | (unless (and calc-keypad-buffer |
| 60 | (buffer-name calc-keypad-buffer)) | 58 | (buffer-name calc-keypad-buffer)) |
| 61 | (progn | 59 | (setq calc-keypad-buffer (get-buffer-create "*Calc Keypad*")) |
| 62 | (setq calc-keypad-buffer (get-buffer-create "*Calc Keypad*")) | 60 | (set-buffer calc-keypad-buffer) |
| 63 | (set-buffer calc-keypad-buffer) | 61 | (use-local-map calc-keypad-map) |
| 64 | (use-local-map calc-keypad-map) | 62 | (setq major-mode 'calc-keypad) |
| 65 | (setq major-mode 'calc-keypad) | 63 | (setq mode-name "Calculator") |
| 66 | (setq mode-name "Calculator") | 64 | (put 'calc-keypad 'mode-class 'special) |
| 67 | (put 'calc-keypad 'mode-class 'special) | 65 | (make-local-variable 'calc-main-buffer) |
| 68 | (make-local-variable 'calc-main-buffer) | 66 | (setq calc-main-buffer calcbuf) |
| 69 | (setq calc-main-buffer calcbuf) | 67 | (calc-keypad-redraw) |
| 70 | (calc-keypad-redraw) | 68 | (calc-trail-buffer)) |
| 71 | (calc-trail-buffer))) | ||
| 72 | (let ((width 29) | 69 | (let ((width 29) |
| 73 | (height 17) | 70 | (height 17) |
| 74 | win old-win) | 71 | win old-win) |
| @@ -85,16 +82,7 @@ | |||
| 85 | (bury-buffer calc-keypad-buffer) | 82 | (bury-buffer calc-keypad-buffer) |
| 86 | (if (one-window-p) | 83 | (if (one-window-p) |
| 87 | (switch-to-buffer (other-buffer)) | 84 | (switch-to-buffer (other-buffer)) |
| 88 | (delete-window win)) | 85 | (delete-window win))) |
| 89 | (if (and calc-keypad-prev-x-left-click | ||
| 90 | (eq (aref mouse-map 0) 'calc-keypad-x-right-click) | ||
| 91 | (eq (aref mouse-map 1) 'calc-keypad-x-middle-click) | ||
| 92 | (eq (aref mouse-map 2) 'calc-keypad-x-left-click)) | ||
| 93 | (progn | ||
| 94 | (aset mouse-map 0 calc-keypad-prev-x-right-click) | ||
| 95 | (aset mouse-map 1 calc-keypad-prev-x-middle-click) | ||
| 96 | (aset mouse-map 2 calc-keypad-prev-x-left-click) | ||
| 97 | (setq calc-keypad-prev-x-left-click nil)))) | ||
| 98 | (setq calc-was-keypad-mode t | 86 | (setq calc-was-keypad-mode t |
| 99 | old-win (get-largest-window)) | 87 | old-win (get-largest-window)) |
| 100 | (if (or (< (window-height old-win) (+ height 6)) | 88 | (if (or (< (window-height old-win) (+ height 6)) |
| @@ -126,24 +114,14 @@ | |||
| 126 | (split-window win (- (window-height win) height 1)) | 114 | (split-window win (- (window-height win) height 1)) |
| 127 | (set-window-buffer win calcbuf)) | 115 | (set-window-buffer win calcbuf)) |
| 128 | (select-window old-win) | 116 | (select-window old-win) |
| 129 | (if (and (eq window-system 'x) | ||
| 130 | (not calc-keypad-prev-x-left-click)) | ||
| 131 | (progn | ||
| 132 | (setq calc-keypad-prev-x-right-click (aref mouse-map 0) | ||
| 133 | calc-keypad-prev-x-middle-click (aref mouse-map 1) | ||
| 134 | calc-keypad-prev-x-left-click (aref mouse-map 2)) | ||
| 135 | (aset mouse-map 0 'calc-keypad-x-right-click) | ||
| 136 | (aset mouse-map 1 'calc-keypad-x-middle-click) | ||
| 137 | (aset mouse-map 2 'calc-keypad-x-left-click))) | ||
| 138 | (message "Welcome to GNU Emacs Calc! Use the left and right mouse buttons.") | 117 | (message "Welcome to GNU Emacs Calc! Use the left and right mouse buttons.") |
| 139 | (run-hooks 'calc-keypad-start-hook) | 118 | (run-hooks 'calc-keypad-start-hook) |
| 140 | (and calc-keypad-said-hello interactive | 119 | (and calc-keypad-said-hello interactive |
| 141 | (progn | 120 | (progn |
| 142 | (sit-for 2) | 121 | (sit-for 2) |
| 143 | (message ""))) | 122 | (message ""))) |
| 144 | (setq calc-keypad-said-hello t)))) | 123 | (setq calc-keypad-said-hello t))) |
| 145 | (setq calc-keypad-input nil) | 124 | (setq calc-keypad-input nil))) |
| 146 | ) | ||
| 147 | 125 | ||
| 148 | (defun calc-keypad-off () | 126 | (defun calc-keypad-off () |
| 149 | (interactive) | 127 | (interactive) |
| @@ -252,13 +230,13 @@ | |||
| 252 | (beep)) | 230 | (beep)) |
| 253 | ((and (> (minibuffer-depth) 0)) | 231 | ((and (> (minibuffer-depth) 0)) |
| 254 | (cond (isstring | 232 | (cond (isstring |
| 255 | (setq unread-command-char (aref (car cmd) 0))) | 233 | (push (aref (car cmd) 0) unread-command-events)) |
| 256 | ((eq cmd 'calc-pop) | 234 | ((eq cmd 'calc-pop) |
| 257 | (setq unread-command-char ?\177)) | 235 | (push ?\177 unread-command-events)) |
| 258 | ((eq cmd 'calc-enter) | 236 | ((eq cmd 'calc-enter) |
| 259 | (setq unread-command-char 13)) | 237 | (push 13 unread-command-events)) |
| 260 | ((eq cmd 'calc-undo) | 238 | ((eq cmd 'calc-undo) |
| 261 | (setq unread-command-char 7)) | 239 | (push 7 unread-command-events)) |
| 262 | (t | 240 | (t |
| 263 | (beep)))) | 241 | (beep)))) |
| 264 | ((and input (string-match "STO\\|RCL" input)) | 242 | ((and input (string-match "STO\\|RCL" input)) |
| @@ -368,54 +346,29 @@ | |||
| 368 | (calc-keypad-show-input))) | 346 | (calc-keypad-show-input))) |
| 369 | ) | 347 | ) |
| 370 | 348 | ||
| 371 | (defun calc-keypad-x-left-click (arg) | 349 | (defun calc-keypad-left-click (event) |
| 372 | "Handle a left-button mouse click in Calc Keypad window." | 350 | "Handle a left-button mouse click in Calc Keypad window." |
| 373 | (let (coords) | 351 | (interactive "e") |
| 374 | (if (and calc-keypad-buffer | 352 | (goto-char (posn-point (event-start event))) |
| 375 | (buffer-name calc-keypad-buffer) | 353 | (calc-keypad-press)) |
| 376 | (get-buffer-window calc-keypad-buffer) | ||
| 377 | (setq coords (coordinates-in-window-p | ||
| 378 | arg (get-buffer-window calc-keypad-buffer)))) | ||
| 379 | (let ((win (selected-window))) | ||
| 380 | (unwind-protect | ||
| 381 | (progn | ||
| 382 | (x-mouse-set-point arg) | ||
| 383 | (calc-keypad-press)) | ||
| 384 | (and (window-point win) | ||
| 385 | (select-window win)))) | ||
| 386 | (funcall calc-keypad-prev-x-left-click arg))) | ||
| 387 | ) | ||
| 388 | 354 | ||
| 389 | (defun calc-keypad-x-right-click (arg) | 355 | (defun calc-keypad-right-click (event) |
| 390 | "Handle a right-button mouse click in Calc Keypad window." | 356 | "Handle a right-button mouse click in Calc Keypad window." |
| 391 | (if (and calc-keypad-buffer | 357 | (interactive "e") |
| 392 | (buffer-name calc-keypad-buffer) | 358 | (save-excursion |
| 393 | (get-buffer-window calc-keypad-buffer) | 359 | (set-buffer calc-keypad-buffer) |
| 394 | (coordinates-in-window-p | 360 | (calc-keypad-menu))) |
| 395 | arg (get-buffer-window calc-keypad-buffer))) | ||
| 396 | (save-excursion | ||
| 397 | (set-buffer calc-keypad-buffer) | ||
| 398 | (calc-keypad-menu)) | ||
| 399 | (funcall calc-keypad-prev-x-right-click arg)) | ||
| 400 | ) | ||
| 401 | 361 | ||
| 402 | (defun calc-keypad-x-middle-click (arg) | 362 | (defun calc-keypad-middle-click (event) |
| 403 | "Handle a middle-button mouse click in Calc Keypad window." | 363 | "Handle a middle-button mouse click in Calc Keypad window." |
| 404 | (if (and calc-keypad-buffer | 364 | (interactive "e") |
| 405 | (buffer-name calc-keypad-buffer) | 365 | (with-current-buffer calc-keypad-buffer |
| 406 | (get-buffer-window calc-keypad-buffer) | 366 | (calc-keypad-menu-back))) |
| 407 | (coordinates-in-window-p | ||
| 408 | arg (get-buffer-window calc-keypad-buffer))) | ||
| 409 | (save-excursion | ||
| 410 | (set-buffer calc-keypad-buffer) | ||
| 411 | (calc-keypad-menu-back)) | ||
| 412 | (funcall calc-keypad-prev-x-middle-click arg)) | ||
| 413 | ) | ||
| 414 | 367 | ||
| 415 | (defun calc-keypad-menu () | 368 | (defun calc-keypad-menu () |
| 416 | (interactive) | 369 | (interactive) |
| 417 | (or (eq major-mode 'calc-keypad) | 370 | (unless (eq major-mode 'calc-keypad) |
| 418 | (error "Must be in *Calc Keypad* buffer for this command")) | 371 | (error "Must be in *Calc Keypad* buffer for this command")) |
| 419 | (while (progn (setq calc-keypad-menu (% (1+ calc-keypad-menu) | 372 | (while (progn (setq calc-keypad-menu (% (1+ calc-keypad-menu) |
| 420 | (length calc-keypad-menus))) | 373 | (length calc-keypad-menus))) |
| 421 | (not (symbol-value (nth calc-keypad-menu calc-keypad-menus))))) | 374 | (not (symbol-value (nth calc-keypad-menu calc-keypad-menus))))) |