diff options
author | wolfsuit <wolfsuit> | 2005-06-03 17:06:21 (GMT) |
---|---|---|
committer | wolfsuit <wolfsuit> | 2005-06-03 17:06:21 (GMT) |
commit | b47015e039bd872d4575c1493788ba4d5d675f83 (patch) | |
tree | 1d6fbed221951f5587d3c247754323e1816694a0 /macosx | |
parent | 4b070c479d73498774dd20d8c7723b9cee72133b (diff) | |
download | tk-b47015e039bd872d4575c1493788ba4d5d675f83.zip tk-b47015e039bd872d4575c1493788ba4d5d675f83.tar.gz tk-b47015e039bd872d4575c1493788ba4d5d675f83.tar.bz2 |
2005-06-02 Jim Ingham <jingham@apple.com>
Another patch from M. Kirkham.
* macosx/tkMacOSXScrlbr.c (ThumbActionProc, ScrollBarBindProc):
Record the first mouse down point, and compute differences from
that, rather than getting the mouse down each time through the
loop. The old method would get fooled if you moved the mouse less
than a text line height in the text widget.
[Bug 1083728]
Diffstat (limited to 'macosx')
-rw-r--r-- | macosx/tkMacOSXScrlbr.c | 59 |
1 files changed, 40 insertions, 19 deletions
diff --git a/macosx/tkMacOSXScrlbr.c b/macosx/tkMacOSXScrlbr.c index c6a8e29..0a5876d 100644 --- a/macosx/tkMacOSXScrlbr.c +++ b/macosx/tkMacOSXScrlbr.c @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXScrlbr.c,v 1.12 2005/05/15 21:09:34 wolfsuit Exp $ + * RCS: @(#) $Id: tkMacOSXScrlbr.c,v 1.13 2005/06/03 17:06:22 wolfsuit Exp $ */ #include "tkScrollbar.h" @@ -98,9 +98,11 @@ static ControlActionUPP scrollActionProc = NULL; /* Pointer to func. */ static ThumbActionUPP thumbActionProc = NULL; /* Pointer to func. */ static TkScrollbar *activeScrollPtr = NULL; /* Non-null when in thumb */ /* proc. */ -static Point activePoint; /* Used when - * activeScrollPtr is - * non-NULL */ +static Point mouseDownPoint; /* Used when activeScrollPtr is non-NULL */ + /* to store the coordinates where the */ + /* mouse was first pressed to begin */ + /* dragging the thumb, because */ + /* ThumbActionProc can't take any args. */ /* * Forward declarations for procedures defined later in this file: @@ -584,7 +586,7 @@ ThumbActionProc() register MacScrollbar *macScrollPtr = (MacScrollbar *) activeScrollPtr; Tcl_DString cmdString; int origValue; - double thumbWidth, newFirstFraction, trackBarSize; + double thumbWidth, oldFirstFraction, newFirstFraction, trackBarSize; char valueString[40]; Point currentPoint = { 0, 0 }; Rect trackRect; @@ -627,9 +629,16 @@ ThumbActionProc() /* * Track the mouse while the button is held down. If the mouse is moved, * we calculate the value that should be passed to the "command" part of - * the scrollbar. + * the scrollbar. Since the mouse may move a distance too small to + * cause a change to the first fraction, each calculation must be done + * versus what the first fraction was when the mouse button was + * initially pressed. Otherwise, moving the mouse too slowly will + * cause the calculated fraction delta to be zero and the scrollbar + * won't respond. */ + oldFirstFraction = scrollPtr->firstFraction; + do { err = TrackMouseLocationWithOptions(NULL, kTrackMouseLocationOptionDontConsumeMouseUp, @@ -641,18 +650,25 @@ ThumbActionProc() if ((err == noErr) && ((trackingResult == kMouseTrackingMouseDragged) || (trackingResult == kMouseTrackingMouseMoved))) { - /* - * Calculate where the scrollbar should move to, and reset the - * activePoint to where we are now. - */ - newFirstFraction = scrollPtr->firstFraction; + + /* + * Calculate where the scrollbar should move to, based on + * where the mouse button was pressed and where the scrollbar + * initially was at that time. Note that PtInRect() will + * return false if currentPoint or trackRect are not in + * is not in current graphics port, which may happen if any + * of the waiting idle events change the port (e.g. with + * SetPort()) but fail to restore it before returning and the + * scrollbar will lock in place. + */ + newFirstFraction = oldFirstFraction; if (PtInRect(currentPoint, &trackRect)) { double pixDiff; double fracDelta; if (scrollPtr->vertical == true) { - pixDiff = (double)(currentPoint.v - activePoint.v); + pixDiff = (double)(currentPoint.v - mouseDownPoint.v); } else { - pixDiff = (double)(currentPoint.h - activePoint.h); + pixDiff = (double)(currentPoint.h - mouseDownPoint.h); } fracDelta = pixDiff/(trackBarSize); newFirstFraction += fracDelta; @@ -663,8 +679,13 @@ ThumbActionProc() } } - activePoint = currentPoint; - + /* + * Move the scrollbar thumb to the new first fraction given + * its position when initially pressed and how far the mouse + * has moved. Process waiting idle tasks afterward to allow + * for the display to update. + */ + sprintf(valueString, "%g", newFirstFraction); Tcl_DStringSetLength(&cmdString, 0); Tcl_DStringAppend(&cmdString, scrollPtr->command, @@ -674,9 +695,9 @@ ThumbActionProc() interp = scrollPtr->interp; Tcl_Preserve((ClientData) interp); Tcl_GlobalEval(interp, cmdString.string); - Tcl_Release ((ClientData) interp); + Tcl_Release((ClientData) interp); - TclServiceIdle(); + TclServiceIdle(); } } while ((err == noErr) && trackingResult != kMouseTrackingMouseReleased); @@ -799,8 +820,8 @@ ScrollbarBindProc( * so the callback may have access to it. */ activeScrollPtr = scrollPtr; - activePoint.h = where.h; - activePoint.v = where.v; + mouseDownPoint.h = where.h; + mouseDownPoint.v = where.v; part = TrackControl(macScrollPtr->sbHandle, where, (ControlActionUPP) thumbActionProc); activeScrollPtr = NULL; |