Mercurial > emacs
annotate lisp/scroll-bar.el @ 15462:6418750a8408 libc-1-92 libc-960621 libc-960622 libc-960623 libc-960624 libc-960625 libc-960626 libc-960627 libc-960628
Add support for PowerPC Linux
author | Michael Meissner <gnu@the-meissners.org> |
---|---|
date | Thu, 20 Jun 1996 16:20:05 +0000 |
parents | 0eb55cad57c6 |
children | dedaafd841c0 |
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 | 2 |
14169 | 3 ;; Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc. |
1772 | 4 |
5 ;; Maintainer: FSF | |
6 ;; Keywords: hardware | |
7 | |
14169 | 8 ;; This file is part of GNU Emacs. |
1772 | 9 |
14169 | 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. | |
1772 | 14 |
14169 | 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. | |
1772 | 19 |
14169 | 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 the | |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
2233
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
24 |
2315
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2233
diff
changeset
|
25 ;;; Commentary: |
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2233
diff
changeset
|
26 |
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2233
diff
changeset
|
27 ;; 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
|
28 ;; Presently emulates the scroll-bar behavior of xterm. |
14169 | 29 |
2315
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 | 34 |
35 ;;;; Utilities. | |
36 | |
7222
3dae5675cd3e
(scroll-bar-event-ratio): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4469
diff
changeset
|
37 (defun scroll-bar-event-ratio (event) |
3dae5675cd3e
(scroll-bar-event-ratio): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4469
diff
changeset
|
38 "Given a scroll bar event EVENT, return the scroll bar position as a ratio. |
3dae5675cd3e
(scroll-bar-event-ratio): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4469
diff
changeset
|
39 The value is a cons cell (PORTION . WHOLE) containing two integers |
3dae5675cd3e
(scroll-bar-event-ratio): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4469
diff
changeset
|
40 whose ratio gives the event's vertical position in the scroll bar, with 0 |
3dae5675cd3e
(scroll-bar-event-ratio): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4469
diff
changeset
|
41 referring to the top and 1 to the bottom." |
3dae5675cd3e
(scroll-bar-event-ratio): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4469
diff
changeset
|
42 (nth 2 event)) |
3dae5675cd3e
(scroll-bar-event-ratio): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4469
diff
changeset
|
43 |
1981
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
44 (defun scroll-bar-scale (num-denom whole) |
1772 | 45 "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
|
46 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
|
47 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
|
48 from a scroll bar event, then (scroll-bar-scale SCROLL-BAR-POS |
1772 | 49 \(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
|
50 that scroll bar position." |
1772 | 51 ;; We multiply before we divide to maintain precision. |
52 ;; 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
|
53 ;; with a large scroll bar portion can easily overflow a lisp int. |
1772 | 54 (truncate (/ (* (float (car num-denom)) whole) (cdr num-denom)))) |
55 | |
56 | |
1954
059d99d03aae
* term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
57 ;;;; Helpful functions for enabling and disabling scroll bars. |
059d99d03aae
* term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
58 |
059d99d03aae
* term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
59 (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
|
60 "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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 (interactive "P") |
4469
abb585cf9188
(scroll-bar-mode): If FLAG is non-nil, set it to its prefix-numeric-value.
Roland McGrath <roland@gnu.org>
parents:
3613
diff
changeset
|
66 (if flag (setq flag (prefix-numeric-value flag))) |
3613
f37a9c897699
* scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents:
3588
diff
changeset
|
67 |
f37a9c897699
* scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents:
3588
diff
changeset
|
68 ;; Obtain the current setting by looking at default-frame-alist. |
f37a9c897699
* scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents:
3588
diff
changeset
|
69 (let ((scroll-bar-mode |
f37a9c897699
* scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents:
3588
diff
changeset
|
70 (let ((assq (assq 'vertical-scroll-bars default-frame-alist))) |
f37a9c897699
* scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents:
3588
diff
changeset
|
71 (if assq (cdr assq) t)))) |
f37a9c897699
* scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents:
3588
diff
changeset
|
72 |
f37a9c897699
* scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents:
3588
diff
changeset
|
73 ;; Tweedle it according to the argument. |
f37a9c897699
* scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents:
3588
diff
changeset
|
74 (setq scroll-bar-mode (if (null flag) (not scroll-bar-mode) |
f37a9c897699
* scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents:
3588
diff
changeset
|
75 (or (not (numberp flag)) (>= flag 0)))) |
f37a9c897699
* scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents:
3588
diff
changeset
|
76 |
f37a9c897699
* scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents:
3588
diff
changeset
|
77 ;; Apply it to default-frame-alist. |
f37a9c897699
* scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents:
3588
diff
changeset
|
78 (mapcar |
f37a9c897699
* scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents:
3588
diff
changeset
|
79 (function |
f37a9c897699
* scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents:
3588
diff
changeset
|
80 (lambda (param-name) |
f37a9c897699
* scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents:
3588
diff
changeset
|
81 (let ((parameter (assq param-name default-frame-alist))) |
f37a9c897699
* scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents:
3588
diff
changeset
|
82 (if (consp parameter) |
f37a9c897699
* scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents:
3588
diff
changeset
|
83 (setcdr parameter scroll-bar-mode) |
f37a9c897699
* scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents:
3588
diff
changeset
|
84 (setq default-frame-alist |
f37a9c897699
* scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents:
3588
diff
changeset
|
85 (cons (cons param-name scroll-bar-mode) |
f37a9c897699
* scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents:
3588
diff
changeset
|
86 default-frame-alist)))))) |
f37a9c897699
* scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents:
3588
diff
changeset
|
87 '(vertical-scroll-bars horizontal-scroll-bars)) |
f37a9c897699
* scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents:
3588
diff
changeset
|
88 |
f37a9c897699
* scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents:
3588
diff
changeset
|
89 ;; Apply it to existing frames. |
f37a9c897699
* scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents:
3588
diff
changeset
|
90 (let ((frames (frame-list))) |
f37a9c897699
* scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents:
3588
diff
changeset
|
91 (while frames |
f37a9c897699
* scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents:
3588
diff
changeset
|
92 (modify-frame-parameters |
f37a9c897699
* scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents:
3588
diff
changeset
|
93 (car frames) |
f37a9c897699
* scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents:
3588
diff
changeset
|
94 (list (cons 'vertical-scroll-bars scroll-bar-mode) |
f37a9c897699
* scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents:
3588
diff
changeset
|
95 (cons 'horizontal-scroll-bars scroll-bar-mode))) |
f37a9c897699
* scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents:
3588
diff
changeset
|
96 (setq frames (cdr frames)))))) |
1954
059d99d03aae
* term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
97 |
1981
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
98 ;;;; Buffer navigation using the scroll bar. |
1772 | 99 |
2698
6940c6b5d988
(scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
2315
diff
changeset
|
100 ;;; 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
|
101 (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
|
102 "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
|
103 EVENT should be a scroll bar click or drag event." |
1772 | 104 (interactive "e") |
1821
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1772
diff
changeset
|
105 (let* ((end-position (event-end event)) |
1772 | 106 (window (nth 0 end-position)) |
107 (portion-whole (nth 2 end-position))) | |
108 (save-excursion | |
109 (set-buffer (window-buffer window)) | |
110 (save-excursion | |
3588
9685f1d5545b
* scroll-bar.el (scroll-bar-set-window-start): Remember that the
Jim Blandy <jimb@redhat.com>
parents:
3508
diff
changeset
|
111 (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
|
112 (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
|
113 (- (point-max) (point-min))))) |
1772 | 114 (beginning-of-line) |
115 (set-window-start window (point)))))) | |
116 | |
15215
681866822119
(scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
117 (defun scroll-bar-drag-position (portion-whole) |
681866822119
(scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
118 "Calculate new window start for drag event." |
681866822119
(scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
119 (save-excursion |
681866822119
(scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
120 (goto-char (+ (point-min) |
681866822119
(scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
121 (scroll-bar-scale portion-whole |
681866822119
(scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
122 (- (point-max) (point-min))))) |
681866822119
(scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
123 (beginning-of-line) |
681866822119
(scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
124 (point))) |
681866822119
(scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
125 |
681866822119
(scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
126 (defun scroll-bar-maybe-set-window-start (event) |
681866822119
(scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
127 "Set the window start according to where the scroll bar is dragged. |
681866822119
(scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
128 Only change window start if the new start is substantially different. |
681866822119
(scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
129 EVENT should be a scroll bar click or drag event." |
681866822119
(scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
130 (interactive "e") |
681866822119
(scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
131 (let* ((end-position (event-end event)) |
681866822119
(scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
132 (window (nth 0 end-position)) |
681866822119
(scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
133 (portion-whole (nth 2 end-position)) |
681866822119
(scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
134 (next-portion-whole (cons (1+ (car portion-whole)) |
681866822119
(scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
135 (cdr portion-whole))) |
681866822119
(scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
136 portion-start |
681866822119
(scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
137 next-portion-start |
681866822119
(scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
138 (current-start (window-start window))) |
681866822119
(scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
139 (save-excursion |
681866822119
(scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
140 (set-buffer (window-buffer window)) |
681866822119
(scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
141 (setq portion-start (scroll-bar-drag-position portion-whole)) |
681866822119
(scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
142 (setq next-portion-start (max |
681866822119
(scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
143 (scroll-bar-drag-position next-portion-whole) |
681866822119
(scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
144 (1+ portion-start))) |
681866822119
(scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
145 (if (or (> current-start next-portion-start) |
681866822119
(scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
146 (< current-start portion-start)) |
15264
0eb55cad57c6
(scroll-bar-maybe-set-window-start): Always set
Karl Heuer <kwzh@gnu.org>
parents:
15215
diff
changeset
|
147 (set-window-start window portion-start) |
0eb55cad57c6
(scroll-bar-maybe-set-window-start): Always set
Karl Heuer <kwzh@gnu.org>
parents:
15215
diff
changeset
|
148 ;; Always set window start, to ensure scroll bar position is updated. |
0eb55cad57c6
(scroll-bar-maybe-set-window-start): Always set
Karl Heuer <kwzh@gnu.org>
parents:
15215
diff
changeset
|
149 (set-window-start window current-start))))) |
15215
681866822119
(scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
150 |
2698
6940c6b5d988
(scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
2315
diff
changeset
|
151 ;; 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
|
152 (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
|
153 (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
|
154 (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
|
155 (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
|
156 (save-excursion |
6940c6b5d988
(scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
2315
diff
changeset
|
157 (set-buffer (window-buffer window)) |
3508 | 158 ;; Calculate position relative to the accessible part of the buffer. |
159 (goto-char (+ (point-min) | |
160 (scroll-bar-scale portion-whole | |
161 (- (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
|
162 (beginning-of-line) |
6940c6b5d988
(scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
2315
diff
changeset
|
163 (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
|
164 |
6940c6b5d988
(scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
2315
diff
changeset
|
165 (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
|
166 "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
|
167 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
|
168 (interactive "e") |
11145
fb77829412af
(scroll-bar-drag): Bind echo-keystrokes to 0.
Richard M. Stallman <rms@gnu.org>
parents:
10555
diff
changeset
|
169 (let* (done |
fb77829412af
(scroll-bar-drag): Bind echo-keystrokes to 0.
Richard M. Stallman <rms@gnu.org>
parents:
10555
diff
changeset
|
170 (echo-keystrokes 0)) |
10555
39e925f8beaa
(scroll-bar-drag-1): Set point-before-scroll properly.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
171 (or point-before-scroll |
39e925f8beaa
(scroll-bar-drag-1): Set point-before-scroll properly.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
172 (setq point-before-scroll (point))) |
12040
e293764039a5
(scroll-bar-drag): Call scroll-bar-drag-1
Karl Heuer <kwzh@gnu.org>
parents:
11235
diff
changeset
|
173 ;; Our scrolling can move point; don't let that clear point-before-scroll. |
10555
39e925f8beaa
(scroll-bar-drag-1): Set point-before-scroll properly.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
174 (let (point-before-scroll) |
12040
e293764039a5
(scroll-bar-drag): Call scroll-bar-drag-1
Karl Heuer <kwzh@gnu.org>
parents:
11235
diff
changeset
|
175 (scroll-bar-drag-1 event) |
10555
39e925f8beaa
(scroll-bar-drag-1): Set point-before-scroll properly.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
176 (track-mouse |
39e925f8beaa
(scroll-bar-drag-1): Set point-before-scroll properly.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
177 (while (not done) |
39e925f8beaa
(scroll-bar-drag-1): Set point-before-scroll properly.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
178 (setq event (read-event)) |
39e925f8beaa
(scroll-bar-drag-1): Set point-before-scroll properly.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
179 (if (eq (car-safe event) 'mouse-movement) |
39e925f8beaa
(scroll-bar-drag-1): Set point-before-scroll properly.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
180 (setq event (read-event))) |
39e925f8beaa
(scroll-bar-drag-1): Set point-before-scroll properly.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
181 (cond ((eq (car-safe event) 'scroll-bar-movement) |
39e925f8beaa
(scroll-bar-drag-1): Set point-before-scroll properly.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
182 (scroll-bar-drag-1 event)) |
39e925f8beaa
(scroll-bar-drag-1): Set point-before-scroll properly.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
183 (t |
39e925f8beaa
(scroll-bar-drag-1): Set point-before-scroll properly.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
184 ;; Exit when we get the drag event; ignore that event. |
12040
e293764039a5
(scroll-bar-drag): Call scroll-bar-drag-1
Karl Heuer <kwzh@gnu.org>
parents:
11235
diff
changeset
|
185 (setq done t))))) |
e293764039a5
(scroll-bar-drag): Call scroll-bar-drag-1
Karl Heuer <kwzh@gnu.org>
parents:
11235
diff
changeset
|
186 (sit-for 0)))) |
2698
6940c6b5d988
(scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
2315
diff
changeset
|
187 |
1981
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
188 (defun scroll-bar-scroll-down (event) |
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
189 "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
|
190 EVENT should be a scroll bar click." |
1772 | 191 (interactive "e") |
192 (let ((old-selected-window (selected-window))) | |
193 (unwind-protect | |
194 (progn | |
1821
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1772
diff
changeset
|
195 (let* ((end-position (event-end event)) |
1772 | 196 (window (nth 0 end-position)) |
197 (portion-whole (nth 2 end-position))) | |
10555
39e925f8beaa
(scroll-bar-drag-1): Set point-before-scroll properly.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
198 (let (point-before-scroll) |
39e925f8beaa
(scroll-bar-drag-1): Set point-before-scroll properly.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
199 (select-window window)) |
39e925f8beaa
(scroll-bar-drag-1): Set point-before-scroll properly.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
200 (or point-before-scroll |
39e925f8beaa
(scroll-bar-drag-1): Set point-before-scroll properly.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
201 (setq point-before-scroll (point))) |
39e925f8beaa
(scroll-bar-drag-1): Set point-before-scroll properly.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
202 (let (point-before-scroll) |
39e925f8beaa
(scroll-bar-drag-1): Set point-before-scroll properly.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
203 (scroll-down |
39e925f8beaa
(scroll-bar-drag-1): Set point-before-scroll properly.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
204 (scroll-bar-scale portion-whole (1- (window-height))))))) |
1772 | 205 (select-window old-selected-window)))) |
206 | |
1981
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
207 (defun scroll-bar-scroll-up (event) |
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
208 "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
|
209 EVENT should be a scroll bar click." |
1772 | 210 (interactive "e") |
211 (let ((old-selected-window (selected-window))) | |
212 (unwind-protect | |
213 (progn | |
1821
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1772
diff
changeset
|
214 (let* ((end-position (event-end event)) |
1772 | 215 (window (nth 0 end-position)) |
216 (portion-whole (nth 2 end-position))) | |
10555
39e925f8beaa
(scroll-bar-drag-1): Set point-before-scroll properly.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
217 (let (point-before-scroll) |
39e925f8beaa
(scroll-bar-drag-1): Set point-before-scroll properly.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
218 (select-window window)) |
39e925f8beaa
(scroll-bar-drag-1): Set point-before-scroll properly.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
219 (or point-before-scroll |
39e925f8beaa
(scroll-bar-drag-1): Set point-before-scroll properly.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
220 (setq point-before-scroll (point))) |
39e925f8beaa
(scroll-bar-drag-1): Set point-before-scroll properly.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
221 (let (point-before-scroll) |
39e925f8beaa
(scroll-bar-drag-1): Set point-before-scroll properly.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
222 (scroll-up |
39e925f8beaa
(scroll-bar-drag-1): Set point-before-scroll properly.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
223 (scroll-bar-scale portion-whole (1- (window-height))))))) |
1772 | 224 (select-window old-selected-window)))) |
225 | |
226 | |
227 ;;;; Bindings. | |
228 | |
229 ;;; 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
|
230 (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
|
231 (global-set-key [vertical-scroll-bar drag-mouse-1] 'scroll-bar-scroll-up) |
1772 | 232 |
2698
6940c6b5d988
(scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
2315
diff
changeset
|
233 (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
|
234 |
1981
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
235 (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
|
236 (global-set-key [vertical-scroll-bar drag-mouse-3] 'scroll-bar-scroll-down) |
1772 | 237 |
238 | |
1973
3a08dacd8bfb
These are in preparation for a more thorough renaming to occur soon.
Jim Blandy <jimb@redhat.com>
parents:
1954
diff
changeset
|
239 (provide 'scroll-bar) |
1772 | 240 |
1981
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
241 ;;; scroll-bar.el ends here |