diff options
| author | Jim Blandy | 1993-01-14 14:52:32 +0000 |
|---|---|---|
| committer | Jim Blandy | 1993-01-14 14:52:32 +0000 |
| commit | 6d62a90e1f9662c515f1c026d550b93cb2b718e0 (patch) | |
| tree | bc231a975cc740fe43af60d5d666b3b107832b76 /lisp | |
| parent | d5ab20330ab7b35cf8e2eb5ff916649dad7a65d8 (diff) | |
| download | emacs-6d62a90e1f9662c515f1c026d550b93cb2b718e0.tar.gz emacs-6d62a90e1f9662c515f1c026d550b93cb2b718e0.zip | |
* scrollbar.el: New file.
* term/x-win.el: Require 'scrollbar.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/scroll-bar.el | 102 | ||||
| -rw-r--r-- | lisp/term/x-win.el | 1 |
2 files changed, 103 insertions, 0 deletions
diff --git a/lisp/scroll-bar.el b/lisp/scroll-bar.el index e69de29bb2d..fbbc91a870d 100644 --- a/lisp/scroll-bar.el +++ b/lisp/scroll-bar.el | |||
| @@ -0,0 +1,102 @@ | |||
| 1 | ;;; scrollbar.el -- window system-independent scrollbar support. | ||
| 2 | |||
| 3 | ;;; Copyright (C) 1993 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Maintainer: FSF | ||
| 6 | ;; Keywords: hardware | ||
| 7 | |||
| 8 | ;;; This file is part of GNU Emacs. | ||
| 9 | |||
| 10 | ;;; GNU Emacs is free software; you can redistribute it and/or modify | ||
| 11 | ;;; it under the terms of the GNU General Public License as published by | ||
| 12 | ;;; the Free Software Foundation; either version 2, or (at your option) | ||
| 13 | ;;; any later version. | ||
| 14 | |||
| 15 | ;;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 16 | ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 18 | ;;; GNU General Public License for more details. | ||
| 19 | |||
| 20 | ;;; You should have received a copy of the GNU General Public License | ||
| 21 | ;;; along with GNU Emacs; see the file COPYING. If not, write to | ||
| 22 | ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 23 | |||
| 24 | |||
| 25 | ;;;; Utilities. | ||
| 26 | |||
| 27 | (defun scrollbar-scale (num-denom whole) | ||
| 28 | "Given a pair (NUM . DENOM) and WHOLE, return (/ (* NUM WHOLE) DENOM). | ||
| 29 | This is handy for scaling a position on a scrollbar into real units, | ||
| 30 | like buffer positions. If SCROLLBAR-POS is the (PORTION . WHOLE) pair | ||
| 31 | from a scrollbar event, then (scrollbar-scale SCROLLBAR-POS | ||
| 32 | \(buffer-size)) is the position in the current buffer corresponding to | ||
| 33 | that scrollbar position." | ||
| 34 | ;; We multiply before we divide to maintain precision. | ||
| 35 | ;; We use floating point because the product of a large buffer size | ||
| 36 | ;; with a large scrollbar portion can easily overflow a lisp int. | ||
| 37 | (truncate (/ (* (float (car num-denom)) whole) (cdr num-denom)))) | ||
| 38 | |||
| 39 | |||
| 40 | ;;;; Buffer navigation using the scrollbar. | ||
| 41 | |||
| 42 | (defun scrollbar-set-window-start (event) | ||
| 43 | "Set the window start according to where the scrollbar is dragged. | ||
| 44 | EVENT should be a scrollbar click or drag event." | ||
| 45 | (interactive "e") | ||
| 46 | (let* ((end-position (nth (1- (length event)) event)) | ||
| 47 | (window (nth 0 end-position)) | ||
| 48 | (portion-whole (nth 2 end-position))) | ||
| 49 | (save-excursion | ||
| 50 | (set-buffer (window-buffer window)) | ||
| 51 | (save-excursion | ||
| 52 | (goto-char (scrollbar-scale portion-whole (buffer-size))) | ||
| 53 | (beginning-of-line) | ||
| 54 | (set-window-start window (point)))))) | ||
| 55 | |||
| 56 | (defun scrollbar-scroll-down (event) | ||
| 57 | "Scroll the window's top line down to the location of the scrollbar click. | ||
| 58 | EVENT should be a scrollbar click." | ||
| 59 | (interactive "e") | ||
| 60 | (let ((old-selected-window (selected-window))) | ||
| 61 | (unwind-protect | ||
| 62 | (progn | ||
| 63 | (let* ((end-position (nth (1- (length event)) event)) | ||
| 64 | (window (nth 0 end-position)) | ||
| 65 | (portion-whole (nth 2 end-position))) | ||
| 66 | (select-window window) | ||
| 67 | (scroll-down | ||
| 68 | (scrollbar-scale portion-whole (1- (window-height)))))) | ||
| 69 | (select-window old-selected-window)))) | ||
| 70 | |||
| 71 | (defun scrollbar-scroll-up (event) | ||
| 72 | "Scroll the line next to the scrollbar click to the top of the window. | ||
| 73 | EVENT should be a scrollbar click." | ||
| 74 | (interactive "e") | ||
| 75 | (let ((old-selected-window (selected-window))) | ||
| 76 | (unwind-protect | ||
| 77 | (progn | ||
| 78 | (let* ((end-position (nth (1- (length event)) event)) | ||
| 79 | (window (nth 0 end-position)) | ||
| 80 | (portion-whole (nth 2 end-position))) | ||
| 81 | (select-window window) | ||
| 82 | (scroll-up | ||
| 83 | (scrollbar-scale portion-whole (1- (window-height)))))) | ||
| 84 | (select-window old-selected-window)))) | ||
| 85 | |||
| 86 | |||
| 87 | ;;;; Bindings. | ||
| 88 | |||
| 89 | ;;; For now, we'll set things up to work like xterm. | ||
| 90 | (global-set-key [vertical-scrollbar mouse-1] 'scrollbar-scroll-up) | ||
| 91 | (global-set-key [vertical-scrollbar drag-mouse-1] 'scrollbar-scroll-up) | ||
| 92 | |||
| 93 | (global-set-key [vertical-scrollbar mouse-2] 'scrollbar-set-window-start) | ||
| 94 | (global-set-key [vertical-scrollbar drag-mouse-2] 'scrollbar-set-window-start) | ||
| 95 | |||
| 96 | (global-set-key [vertical-scrollbar mouse-3] 'scrollbar-scroll-down) | ||
| 97 | (global-set-key [vertical-scrollbar drag-mouse-3] 'scrollbar-scroll-down) | ||
| 98 | |||
| 99 | |||
| 100 | (provide 'scrollbar) | ||
| 101 | |||
| 102 | ;;; scrollbar.el ends here | ||
diff --git a/lisp/term/x-win.el b/lisp/term/x-win.el index aafaa529363..2c774cb2a7e 100644 --- a/lisp/term/x-win.el +++ b/lisp/term/x-win.el | |||
| @@ -63,6 +63,7 @@ | |||
| 63 | 63 | ||
| 64 | (require 'frame) | 64 | (require 'frame) |
| 65 | (require 'mouse) | 65 | (require 'mouse) |
| 66 | (require 'scrollbar) | ||
| 66 | 67 | ||
| 67 | (setq command-switch-alist | 68 | (setq command-switch-alist |
| 68 | (append '(("-bw" . x-handle-numeric-switch) | 69 | (append '(("-bw" . x-handle-numeric-switch) |