annotate lisp/mouse-drag.el @ 17915:3c572d848dab

(pc-selection-mode): Swap meanings of f16 and f18; they were backwards.
author Richard M. Stallman <rms@gnu.org>
date Thu, 22 May 1997 02:06:07 +0000
parents 8f952e921136
children e3b0e7dc5efd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17517
8f952e921136 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 16322
diff changeset
1 ;;; mouse-drag.el --- use mouse-2 to do a new style of scrolling
8f952e921136 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 16322
diff changeset
2
16322
f4be70df6bb6 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 16320
diff changeset
3 ;; Copyright (C) 1996 Free Software Foundation, Inc.
16319
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
16322
f4be70df6bb6 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 16320
diff changeset
5 ;; Author: John Heidemann <johnh@ISI.EDU>
f4be70df6bb6 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 16320
diff changeset
6 ;; Keywords: mouse
16319
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; any later version.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;;; Commentary:
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;;; What is ``mouse-drag.el''?
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;;; Doesn't that scroll bar seem far away when you want to scroll?
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;;; This module overloads mouse-2 to do ``throw'' scrolling. You
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;;; click and drag. The distance you move from your original click
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;;; turns into a scroll amount. The scroll amount is scaled
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;;; exponentially to make both large moves and short adjustments easy.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;;; What this boils down to is that you can easily scroll around the
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;;; buffer without much mouse movement. Finally, clicks which aren't
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;;; drags are passed off to the old mouse-2 binding, so old mouse-2
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;;; operations (find-file in dired-mode, yanking in most other modes)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;;; still work.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;;; There is an alternative way to scroll, ``drag'' scrolling. You
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;;; can click on a character and then drag it around, scrolling the
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;;; buffer with you. The character always stays under the mouse.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;;; Compared to throw-scrolling, this approach provides direct
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;;; manipulation (nice) but requires more mouse movement
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;;; (unfortunate). It is offered as an alternative for those who
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;;; prefer it.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;;; If you like mouse-drag, you should also check out mouse-copy
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;;; for ``one-click text copy and move''.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;;; To use mouse-drag, place the following in your .emacs file:
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;;; (require 'mouse-drag)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;;; -and either-
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;;; (global-set-key [down-mouse-2] 'mouse-drag-throw)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;;; -or-
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;;; (global-set-key [down-mouse-2] 'mouse-drag-drag)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;;; Options:
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;;; - reverse the throw-scroll direction with \\[mouse-throw-with-scroll-bar]
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;;; - work around a bug with \\[mouse-extras-work-around-drag-bug]
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 ;;; History and related work:
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 ;;; One-click copying and moving was inspired by lemacs-19.8.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 ;;; Throw-scrolling was inspired by MacPaint's ``hand'' and by Tk's
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 ;;; mouse-2 scrolling. The package mouse-scroll.el by Tom Wurgler
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 ;;; <twurgler@goodyear.com> is similar to mouse-drag-throw, but
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 ;;; doesn't pass clicks through.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 ;;; These functions have been tested in emacs version 19.30,
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 ;;; and this package has run in the past on 19.25-19.29.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ;;; Originally mouse-drag was part of a larger package.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 ;;; As of 11 July 96 the scrolling functions were split out
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 ;;; in preparation for incorporation into (the future) emacs-19.32.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 ;;; Thanks:
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 ;;; Thanks to Kai Grossjohann
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 ;;; <grossjoh@dusty.informatik.uni-dortmund.de> for reporting bugs, to
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 ;;; Tom Wurgler <twurgler@goodyear.com> for reporting bugs and
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 ;;; suggesting fixes, and to Joel Graber <jgraber@ti.com> for
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 ;;; prompting me to do drag-scrolling and for an initial
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 ;;; implementation of horizontal drag-scrolling.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 ;;; -johnh@isi.edu, 11-Jul-96
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 ;;; Old changes, for reference:
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 ;;; What's new with mouse-extras 2.21?
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 ;;; - support for emacs-19.{29,30}
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 ;;; - point now stays on the visible screen during horizontal scrolling
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 ;;; (bug identified and fix suggested by Tom Wurgler <twurgler@goodyear.com>)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 ;;; - better work-around for lost-mouse-events bug (supports double/triple
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 ;;; clicks), see \\[mouse-extras-work-around-drag-bug] for details.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 ;;; - work-around for lost-mouse-events bug now is OFF by default;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 ;;; enable it if you have problems
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 ;;; Code:
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 ;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 ;; scrolling code
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 ;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (defun mouse-drag-safe-scroll (row-delta &optional col-delta)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 "* Scroll down ROW-DELTA lines and right COL-DELTA, ignoring buffer edge errors.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 Keep the cursor on the screen as needed."
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 (if (and row-delta
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 (/= 0 row-delta))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 (condition-case nil ;; catch and ignore movement errors
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 (scroll-down row-delta)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (beginning-of-buffer (message "Beginning of buffer"))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 (end-of-buffer (message "End of buffer"))))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 (if (and col-delta
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 (/= 0 col-delta))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 (progn
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 (scroll-right col-delta)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 ;; Make sure that the point stays on the visible screen
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 ;; (if truncation-lines in set).
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 ;; This code mimics the behavior we automatically get
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 ;; when doing vertical scrolling.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 ;; Problem identified and a fix suggested by Tom Wurgler.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 (cond
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 ((< (current-column) (window-hscroll))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (move-to-column (window-hscroll))) ; make on left column
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 ((> (- (current-column) (window-hscroll) (window-width) -2) 0)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 (move-to-column (+ (window-width) (window-hscroll) -3)))))))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (defun mouse-drag-repeatedly-safe-scroll (row-delta &optional col-delta)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 "* Scroll ROW-DELTA rows and COL-DELTA cols until an event happens."
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (while (sit-for mouse-scroll-delay)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 (mouse-drag-safe-scroll row-delta col-delta)))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 (defun mouse-drag-events-are-point-events-p (start-posn end-posn)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 "* Determine if START-POSN and END-POSN are \"close\"."
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 (let*
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 ((start-col-row (posn-col-row start-posn))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (end-col-row (posn-col-row end-posn)))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 (and
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 ;; We no longer exclude things by time.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 ;; (< (- (posn-timestamp end-posn) (posn-timestamp start-posn))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 ;; (if (numberp double-click-time)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 ;; (* 2 double-click-time) ;; stretch it a little
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 ;; 999999)) ;; non-numeric => check by position alone
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 (= (car start-col-row) (car end-col-row))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 (= (cdr start-col-row) (cdr end-col-row)))))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 (defun mouse-drag-should-do-col-scrolling ()
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 "* Determine if it's wise to enable col-scrolling for the current window."
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 (or truncate-lines
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 (> (window-hscroll (selected-window)) 0)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 (< (window-width) (screen-width))))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 (defvar mouse-throw-with-scroll-bar nil
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 "* Set direction of mouse-throwing.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 If nil, the text moves in the direction the mouse moves.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 If t, the scroll bar moves in the direction the mouse moves.")
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 (defconst mouse-throw-magnifier-with-scroll-bar
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 [-16 -8 -4 -2 -1 0 0 0 1 2 4 8 16])
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (defconst mouse-throw-magnifier-with-mouse-movement
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 [ 16 8 4 2 1 0 0 0 -1 -2 -4 -8 -16])
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 (defconst mouse-throw-magnifier-min -6)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 (defconst mouse-throw-magnifier-max 6)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 (defun mouse-drag-throw (start-event)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 "\"Throw\" the page according to a mouse drag.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 A \"throw\" is scrolling the page at a speed relative to the distance
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 from the original mouse click to the current mouse location. Try it;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 you'll like it. It's easier to observe than to explain.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 If the mouse is clicked and released in the same place of time we
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 assume that the user didn't want to scdebugroll but wanted to whatever
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 mouse-2 used to do, so we pass it through.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 Throw scrolling was inspired (but is not identical to) the \"hand\"
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 option in MacPaint, or the middle button in Tk text widgets.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 If `mouse-throw-with-scroll-bar' is non-nil, then this command scrolls
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 in the opposite direction. (Different people have different ideas
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 about which direction is natural. Perhaps it has to do with which
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 hemisphere you're in.)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 To test this function, evaluate:
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (global-set-key [down-mouse-2] 'mouse-drag-throw)"
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (interactive "e")
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 ;; we want to do save-selected-window, but that requires 19.29
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (let* ((start-posn (event-start start-event))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (start-window (posn-window start-posn))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (start-row (cdr (posn-col-row start-posn)))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (start-col (car (posn-col-row start-posn)))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (old-selected-window (selected-window))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 event end row mouse-delta scroll-delta
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 have-scrolled point-event-p old-binding
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 window-last-row
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 col mouse-col-delta window-last-col
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (scroll-col-delta 0)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 adjusted-mouse-col-delta
16320
56f494ed6b13 (mouse-drag-throw): Bind adjusted-mouse-delta.
Richard M. Stallman <rms@gnu.org>
parents: 16319
diff changeset
209 adjusted-mouse-delta
16319
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 ;; be conservative about allowing horizontal scrolling
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (col-scrolling-p (mouse-drag-should-do-col-scrolling)))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (select-window start-window)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (track-mouse
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (while (progn
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (setq event (read-event)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 end (event-end event)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 row (cdr (posn-col-row end))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 col (car (posn-col-row end)))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (or (mouse-movement-p event)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 (eq (car-safe event) 'switch-frame)))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (if (eq start-window (posn-window end))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 (progn
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 (setq mouse-delta (- start-row row)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 adjusted-mouse-delta
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (- (cond
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 ((<= mouse-delta mouse-throw-magnifier-min)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 mouse-throw-magnifier-min)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 ((>= mouse-delta mouse-throw-magnifier-max)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 mouse-throw-magnifier-max)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 (t mouse-delta))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 mouse-throw-magnifier-min)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 scroll-delta (aref (if mouse-throw-with-scroll-bar
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 mouse-throw-magnifier-with-scroll-bar
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 mouse-throw-magnifier-with-mouse-movement)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 adjusted-mouse-delta))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 (if col-scrolling-p
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 (setq mouse-col-delta (- start-col col)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 adjusted-mouse-col-delta
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 (- (cond
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 ((<= mouse-col-delta mouse-throw-magnifier-min)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 mouse-throw-magnifier-min)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 ((>= mouse-col-delta mouse-throw-magnifier-max)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 mouse-throw-magnifier-max)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 (t mouse-col-delta))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 mouse-throw-magnifier-min)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 scroll-col-delta (aref (if mouse-throw-with-scroll-bar
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 mouse-throw-magnifier-with-scroll-bar
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 mouse-throw-magnifier-with-mouse-movement)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 adjusted-mouse-col-delta)))))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 (if (or (/= 0 scroll-delta)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (/= 0 scroll-col-delta))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 (progn
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (setq have-scrolled t)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (mouse-drag-safe-scroll scroll-delta scroll-col-delta)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 (mouse-drag-repeatedly-safe-scroll scroll-delta scroll-col-delta))))) ;xxx
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 ;; If it was a click and not a drag, prepare to pass the event on.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 ;; Note: We must determine the pass-through event before restoring
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 ;; the window, but invoke it after. Sigh.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 (if (and (not have-scrolled)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 (mouse-drag-events-are-point-events-p start-posn end))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 (setq point-event-p t
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 old-binding (key-binding
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 (vector (event-basic-type start-event)))))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 ;; Now restore the old window.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (select-window old-selected-window)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 ;; For clicks, call the old function.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 (if point-event-p
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 (call-interactively old-binding))))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 (defun mouse-drag-drag (start-event)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 "\"Drag\" the page according to a mouse drag.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 Drag scrolling moves the page according to the movement of the mouse.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 You \"grab\" the character under the mouse and move it around.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 If the mouse is clicked and released in the same place of time we
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 assume that the user didn't want to scroll but wanted to whatever
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 mouse-2 used to do, so we pass it through.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 Drag scrolling is identical to the \"hand\" option in MacPaint, or the
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 middle button in Tk text widgets.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 To test this function, evaluate:
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 (global-set-key [down-mouse-2] 'mouse-drag-drag)"
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 (interactive "e")
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 ;; we want to do save-selected-window, but that requires 19.29
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 (let* ((start-posn (event-start start-event))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 (start-window (posn-window start-posn))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 (start-row (cdr (posn-col-row start-posn)))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 (start-col (car (posn-col-row start-posn)))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 (old-selected-window (selected-window))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 event end row mouse-delta scroll-delta
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 have-scrolled point-event-p old-binding
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 window-last-row
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 col mouse-col-delta window-last-col
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 (scroll-col-delta 0)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 ;; be conservative about allowing horizontal scrolling
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 (col-scrolling-p (mouse-drag-should-do-col-scrolling)))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 (select-window start-window)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 (setq window-last-row (- (window-height) 2)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 window-last-col (- (window-width) 2))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 (track-mouse
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 (while (progn
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 (setq event (read-event)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 end (event-end event)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 row (cdr (posn-col-row end))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 col (car (posn-col-row end)))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 (or (mouse-movement-p event)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 (eq (car-safe event) 'switch-frame)))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 ;; Scroll if see if we're on the edge.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 ;; NEEDSWORK: should handle mouse-in-other window.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 (cond
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 ((not (eq start-window (posn-window end)))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 t) ; wait for return to original window
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 ((<= row 0) (mouse-drag-repeatedly-safe-scroll -1 0))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 ((>= row window-last-row) (mouse-drag-repeatedly-safe-scroll 1 0))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 ((and col-scrolling-p (<= col 1)) (mouse-drag-repeatedly-safe-scroll 0 -1))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 ((and col-scrolling-p (>= col window-last-col)) (mouse-drag-repeatedly-safe-scroll 0 1))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 (t
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 (setq scroll-delta (- row start-row)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 start-row row)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 (if col-scrolling-p
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 (setq scroll-col-delta (- col start-col)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 start-col col))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 (if (or (/= 0 scroll-delta)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 (/= 0 scroll-col-delta))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 (progn
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 (setq have-scrolled t)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 (mouse-drag-safe-scroll scroll-delta scroll-col-delta)))))))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 ;; If it was a click and not a drag, prepare to pass the event on.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 ;; Note: We must determine the pass-through event before restoring
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 ;; the window, but invoke it after. Sigh.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 (if (and (not have-scrolled)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 (mouse-drag-events-are-point-events-p start-posn end))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 (setq point-event-p t
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 old-binding (key-binding
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 (vector (event-basic-type start-event)))))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 ;; Now restore the old window.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 (select-window old-selected-window)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 ;; For clicks, call the old function.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 (if point-event-p
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 (call-interactively old-binding))))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 (provide 'mouse-drag)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 ;;; mouse-drag.el ends here