annotate lisp/scroll-bar.el @ 3588:9685f1d5545b

* scroll-bar.el (scroll-bar-set-window-start): Remember that the scroll bar numbers reflect the accessible region of the buffer, not the entire buffer.
author Jim Blandy <jimb@redhat.com>
date Wed, 09 Jun 1993 09:44:24 +0000
parents dea00c8a47a6
children f37a9c897699
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2232
4f9d60f7de9d Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1981
diff changeset
1 ;;; scroll-bar.el --- window system-independent scroll bar support.
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
2
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
3 ;;; Copyright (C) 1993 Free Software Foundation, Inc.
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
4
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
5 ;; Maintainer: FSF
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
6 ;; Keywords: hardware
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
7
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
8 ;;; This file is part of GNU Emacs.
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
9
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
10 ;;; GNU Emacs is free software; you can redistribute it and/or modify
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
11 ;;; it under the terms of the GNU General Public License as published by
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
12 ;;; the Free Software Foundation; either version 2, or (at your option)
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
13 ;;; any later version.
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
14
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
15 ;;; GNU Emacs is distributed in the hope that it will be useful,
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
16 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
18 ;;; GNU General Public License for more details.
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
19
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
20 ;;; You should have received a copy of the GNU General Public License
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
21 ;;; along with GNU Emacs; see the file COPYING. If not, write to
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
22 ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
23
2233
fb0ed5a1d0f3 Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2232
diff changeset
24 ;;; Code:
fb0ed5a1d0f3 Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2232
diff changeset
25
2315
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2233
diff changeset
26 ;;; Commentary:
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2233
diff changeset
27
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2233
diff changeset
28 ;; Window-system-independent bindings of mouse clicks on the scroll bar.
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2233
diff changeset
29 ;; Presently emulates the scroll-bar behavior of xterm.
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2233
diff changeset
30 ;;; Code:
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2233
diff changeset
31
1821
04fb1d3d6992 JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents: 1772
diff changeset
32 (require 'mouse)
04fb1d3d6992 JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents: 1772
diff changeset
33
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
34
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
35 ;;;; Utilities.
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
36
1981
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
37 (defun scroll-bar-scale (num-denom whole)
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
38 "Given a pair (NUM . DENOM) and WHOLE, return (/ (* NUM WHOLE) DENOM).
1981
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
39 This is handy for scaling a position on a scroll bar into real units,
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
40 like buffer positions. If SCROLL-BAR-POS is the (PORTION . WHOLE) pair
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
41 from a scroll bar event, then (scroll-bar-scale SCROLL-BAR-POS
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
42 \(buffer-size)) is the position in the current buffer corresponding to
1981
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
43 that scroll bar position."
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
44 ;; We multiply before we divide to maintain precision.
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
45 ;; We use floating point because the product of a large buffer size
1981
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
46 ;; with a large scroll bar portion can easily overflow a lisp int.
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
47 (truncate (/ (* (float (car num-denom)) whole) (cdr num-denom))))
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
48
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
49
1954
059d99d03aae * term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents: 1821
diff changeset
50 ;;;; Helpful functions for enabling and disabling scroll bars.
3129
1b51f5e18410 (scroll-bar-mode): Make default value t.
Richard M. Stallman <rms@gnu.org>
parents: 2698
diff changeset
51 ;;; This is not documented because you can't change the
1b51f5e18410 (scroll-bar-mode): Make default value t.
Richard M. Stallman <rms@gnu.org>
parents: 2698
diff changeset
52 ;;; mode properly by setting it.
1b51f5e18410 (scroll-bar-mode): Make default value t.
Richard M. Stallman <rms@gnu.org>
parents: 2698
diff changeset
53 (defvar scroll-bar-mode t)
1954
059d99d03aae * term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents: 1821
diff changeset
54
059d99d03aae * term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents: 1821
diff changeset
55 (defun scroll-bar-mode (flag)
059d99d03aae * term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents: 1821
diff changeset
56 "Toggle display of vertical scroll bars on each frame.
059d99d03aae * term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents: 1821
diff changeset
57 This command applies to all frames that exist and frames to be
059d99d03aae * term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents: 1821
diff changeset
58 created in the future.
059d99d03aae * term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents: 1821
diff changeset
59 With a numeric argument, if the argument is negative,
059d99d03aae * term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents: 1821
diff changeset
60 turn off scroll bars; otherwise, turn on scroll bars."
059d99d03aae * term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents: 1821
diff changeset
61 (interactive "P")
059d99d03aae * term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents: 1821
diff changeset
62 (setq scroll-bar-mode (if (null flag) (not scroll-bar-mode)
059d99d03aae * term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents: 1821
diff changeset
63 (or (not (numberp flag)) (>= flag 0))))
059d99d03aae * term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents: 1821
diff changeset
64 (mapcar
059d99d03aae * term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents: 1821
diff changeset
65 (function
059d99d03aae * term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents: 1821
diff changeset
66 (lambda (param-name)
059d99d03aae * term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents: 1821
diff changeset
67 (let ((parameter (assq param-name default-frame-alist)))
059d99d03aae * term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents: 1821
diff changeset
68 (if (consp parameter)
059d99d03aae * term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents: 1821
diff changeset
69 (setcdr parameter scroll-bar-mode)
059d99d03aae * term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents: 1821
diff changeset
70 (setq default-frame-alist
059d99d03aae * term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents: 1821
diff changeset
71 (cons (cons param-name scroll-bar-mode)
059d99d03aae * term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents: 1821
diff changeset
72 default-frame-alist))))))
1981
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
73 '(vertical-scroll-bars horizontal-scroll-bars))
1954
059d99d03aae * term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents: 1821
diff changeset
74 (let ((frames (frame-list)))
059d99d03aae * term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents: 1821
diff changeset
75 (while frames
059d99d03aae * term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents: 1821
diff changeset
76 (modify-frame-parameters
059d99d03aae * term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents: 1821
diff changeset
77 (car frames)
1981
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
78 (list (cons 'vertical-scroll-bars scroll-bar-mode)
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
79 (cons 'horizontal-scroll-bars scroll-bar-mode)))
1954
059d99d03aae * term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents: 1821
diff changeset
80 (setq frames (cdr frames)))))
059d99d03aae * term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents: 1821
diff changeset
81
1981
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
82 ;;;; Buffer navigation using the scroll bar.
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
83
2698
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
84 ;;; This was used for up-events on button 2, but no longer.
1981
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
85 (defun scroll-bar-set-window-start (event)
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
86 "Set the window start according to where the scroll bar is dragged.
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
87 EVENT should be a scroll bar click or drag event."
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
88 (interactive "e")
1821
04fb1d3d6992 JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents: 1772
diff changeset
89 (let* ((end-position (event-end event))
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
90 (window (nth 0 end-position))
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
91 (portion-whole (nth 2 end-position)))
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
92 (save-excursion
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
93 (set-buffer (window-buffer window))
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
94 (save-excursion
3588
9685f1d5545b * scroll-bar.el (scroll-bar-set-window-start): Remember that the
Jim Blandy <jimb@redhat.com>
parents: 3508
diff changeset
95 (goto-char (+ (point-min)
9685f1d5545b * scroll-bar.el (scroll-bar-set-window-start): Remember that the
Jim Blandy <jimb@redhat.com>
parents: 3508
diff changeset
96 (scroll-bar-scale portion-whole
9685f1d5545b * scroll-bar.el (scroll-bar-set-window-start): Remember that the
Jim Blandy <jimb@redhat.com>
parents: 3508
diff changeset
97 (- (point-max) (point-min)))))
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
98 (beginning-of-line)
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
99 (set-window-start window (point))))))
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
100
2698
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
101 ;; Scroll the window to the proper position for EVENT.
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
102 (defun scroll-bar-drag-1 (event)
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
103 (let* ((start-position (event-start event))
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
104 (window (nth 0 start-position))
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
105 (portion-whole (nth 2 start-position)))
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
106 (save-excursion
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
107 (set-buffer (window-buffer window))
3508
dea00c8a47a6 (scroll-bar-drag-1):
Richard M. Stallman <rms@gnu.org>
parents: 3129
diff changeset
108 ;; Calculate position relative to the accessible part of the buffer.
dea00c8a47a6 (scroll-bar-drag-1):
Richard M. Stallman <rms@gnu.org>
parents: 3129
diff changeset
109 (goto-char (+ (point-min)
dea00c8a47a6 (scroll-bar-drag-1):
Richard M. Stallman <rms@gnu.org>
parents: 3129
diff changeset
110 (scroll-bar-scale portion-whole
dea00c8a47a6 (scroll-bar-drag-1):
Richard M. Stallman <rms@gnu.org>
parents: 3129
diff changeset
111 (- (point-max) (point-min)))))
2698
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
112 (beginning-of-line)
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
113 (set-window-start window (point)))))
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
114
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
115 (defun scroll-bar-drag (event)
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
116 "Scroll the window by dragging the scroll bar slider.
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
117 If you click outside the slider, the window scrolls to bring the slider there."
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
118 (interactive "e")
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
119 (let* (done)
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
120 (scroll-bar-drag-1 event)
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
121 (track-mouse
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
122 (while (not done)
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
123 (setq event (read-event))
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
124 (if (eq (car-safe event) 'mouse-movement)
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
125 (setq event (read-event)))
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
126 (cond ((eq (car-safe event) 'scroll-bar-movement)
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
127 (scroll-bar-drag-1 event))
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
128 (t
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
129 ;; Exit when we get the drag event; ignore that event.
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
130 (setq done t)))))))
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
131
1981
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
132 (defun scroll-bar-scroll-down (event)
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
133 "Scroll the window's top line down to the location of the scroll bar click.
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
134 EVENT should be a scroll bar click."
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
135 (interactive "e")
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
136 (let ((old-selected-window (selected-window)))
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
137 (unwind-protect
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
138 (progn
1821
04fb1d3d6992 JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents: 1772
diff changeset
139 (let* ((end-position (event-end event))
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
140 (window (nth 0 end-position))
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
141 (portion-whole (nth 2 end-position)))
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
142 (select-window window)
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
143 (scroll-down
1981
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
144 (scroll-bar-scale portion-whole (1- (window-height))))))
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
145 (select-window old-selected-window))))
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
146
1981
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
147 (defun scroll-bar-scroll-up (event)
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
148 "Scroll the line next to the scroll bar click to the top of the window.
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
149 EVENT should be a scroll bar click."
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
150 (interactive "e")
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
151 (let ((old-selected-window (selected-window)))
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
152 (unwind-protect
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
153 (progn
1821
04fb1d3d6992 JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents: 1772
diff changeset
154 (let* ((end-position (event-end event))
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
155 (window (nth 0 end-position))
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
156 (portion-whole (nth 2 end-position)))
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
157 (select-window window)
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
158 (scroll-up
1981
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
159 (scroll-bar-scale portion-whole (1- (window-height))))))
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
160 (select-window old-selected-window))))
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
161
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
162
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
163 ;;;; Bindings.
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
164
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
165 ;;; For now, we'll set things up to work like xterm.
1981
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
166 (global-set-key [vertical-scroll-bar mouse-1] 'scroll-bar-scroll-up)
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
167 (global-set-key [vertical-scroll-bar drag-mouse-1] 'scroll-bar-scroll-up)
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
168
2698
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
169 (global-set-key [vertical-scroll-bar down-mouse-2] 'scroll-bar-drag)
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
170
1981
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
171 (global-set-key [vertical-scroll-bar mouse-3] 'scroll-bar-scroll-down)
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
172 (global-set-key [vertical-scroll-bar drag-mouse-3] 'scroll-bar-scroll-down)
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
173
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
174
1973
3a08dacd8bfb These are in preparation for a more thorough renaming to occur soon.
Jim Blandy <jimb@redhat.com>
parents: 1954
diff changeset
175 (provide 'scroll-bar)
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
176
1981
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
177 ;;; scroll-bar.el ends here