(-mouseDown:): Rewrite the mouse tracking loop.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@16391 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Alexander Malmberg 2003-04-08 13:36:15 +00:00
parent 3061f81c4e
commit 15ab06811c
2 changed files with 43 additions and 33 deletions

View file

@ -1,3 +1,7 @@
2003-04-08 15:33 Alexander Malmberg <alexander@malmberg.org>
* Source/NSTextView.m (-mouseDown:): Rewrite mouse tracking loop.
2003-04-08 02:12 Alexander Malmberg <alexander@malmberg.org> 2003-04-08 02:12 Alexander Malmberg <alexander@malmberg.org>
* Source/NSApplication.m: Note which thread is the -gui thread. * Source/NSApplication.m: Note which thread is the -gui thread.

View file

@ -1,6 +1,6 @@
/** <title>NSTextView</title> /** <title>NSTextView</title>
Copyright (C) 1996, 1998, 2000, 2001, 2002 Free Software Foundation, Inc. Copyright (C) 1996, 1998, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
Much code of this class was originally derived from code which was Much code of this class was originally derived from code which was
in NSText.m. in NSText.m.
@ -2884,10 +2884,12 @@ Figure out how the additional layout stuff is supposed to work.
/* TODO: Only do relayout if needed */ /* TODO: Only do relayout if needed */
NSRange drawnRange; NSRange drawnRange;
NSRect containerRect = rect; NSRect containerRect = rect;
containerRect.origin.x -= _textContainerOrigin.x; containerRect.origin.x -= _textContainerOrigin.x;
containerRect.origin.y -= _textContainerOrigin.y; containerRect.origin.y -= _textContainerOrigin.y;
drawnRange = [_layoutManager glyphRangeForBoundingRect: containerRect drawnRange = [_layoutManager glyphRangeForBoundingRect: containerRect
inTextContainer: _textContainer]; inTextContainer: _textContainer];
if (_tf.draws_background) if (_tf.draws_background)
{ {
/* First paint the background with the color. This is necessary /* First paint the background with the color. This is necessary
@ -3884,9 +3886,7 @@ other than copy/paste or dragging. */
NSSelectionGranularity granularity = NSSelectByCharacter; NSSelectionGranularity granularity = NSSelectByCharacter;
NSRange chosenRange, proposedRange; NSRange chosenRange, proposedRange;
NSPoint point, startPoint; NSPoint point, startPoint;
NSEvent *currentEvent;
unsigned startIndex; unsigned startIndex;
unsigned mask;
/* If non selectable then ignore the mouse down. */ /* If non selectable then ignore the mouse down. */
if (_tf.is_selectable == NO) if (_tf.is_selectable == NO)
@ -4040,37 +4040,46 @@ other than copy/paste or dragging. */
[self setSelectedRange: chosenRange affinity: affinity [self setSelectedRange: chosenRange affinity: affinity
stillSelecting: YES]; stillSelecting: YES];
/* Do an immediate redisplay for visual feedback */
[self displayIfNeeded];
/* Enter modal loop tracking the mouse */ /* Enter modal loop tracking the mouse */
{
mask = NSLeftMouseDraggedMask | NSLeftMouseUpMask; unsigned int mask = NSLeftMouseDraggedMask | NSLeftMouseUpMask;
NSEvent *currentEvent, *lastEvent = nil;
for (currentEvent = [_window nextEventMatchingMask: mask]; NSDate *distantPast = [NSDate distantPast];
[currentEvent type] != NSLeftMouseUp;
currentEvent = [_window nextEventMatchingMask: mask])
{
BOOL didScroll = [self autoscroll: currentEvent];
point = [self convertPoint: [currentEvent locationInWindow] currentEvent = [_window nextEventMatchingMask: mask
fromView: nil]; untilDate: nil
proposedRange = MakeRangeFromAbs ([self characterIndexForPoint: point], inMode: NSEventTrackingRunLoopMode
startIndex); dequeue: YES];
chosenRange = [self selectionRangeForProposedRange: proposedRange do
granularity: granularity]; {
[self setSelectedRange: chosenRange affinity: affinity while (currentEvent && [currentEvent type] != NSLeftMouseUp)
stillSelecting: YES]; {
lastEvent = currentEvent;
currentEvent = [_window nextEventMatchingMask: mask
untilDate: distantPast
inMode: NSEventTrackingRunLoopMode
dequeue: YES];
}
if (currentEvent && [currentEvent type] == NSLeftMouseUp)
break;
if (didScroll) [self autoscroll: lastEvent];
{ point = [self convertPoint: [lastEvent locationInWindow]
/* TODO: Only redisplay where needed, and avoid relayout */ fromView: nil];
[self setNeedsDisplay: YES]; proposedRange = MakeRangeFromAbs([self characterIndexForPoint: point],
} startIndex);
chosenRange = [self selectionRangeForProposedRange: proposedRange
/* Do an immediate redisplay for visual feedback */ granularity: granularity];
[self displayIfNeeded]; [self setSelectedRange: chosenRange affinity: affinity
} stillSelecting: YES];
currentEvent = [_window nextEventMatchingMask: mask
untilDate: nil
inMode: NSEventTrackingRunLoopMode
dequeue: YES];
} while ([currentEvent type] != NSLeftMouseUp);
}
NSDebugLog(@"chosenRange. location = %d, length = %d\n", NSDebugLog(@"chosenRange. location = %d, length = %d\n",
(int)chosenRange.location, (int)chosenRange.length); (int)chosenRange.location, (int)chosenRange.length);
@ -4078,9 +4087,6 @@ other than copy/paste or dragging. */
[self setSelectedRange: chosenRange affinity: affinity [self setSelectedRange: chosenRange affinity: affinity
stillSelecting: NO]; stillSelecting: NO];
/* Ahm - this shouldn't really be needed but... */
[self displayIfNeeded];
/* Remember granularity till a new selection destroys the memory */ /* Remember granularity till a new selection destroys the memory */
[self setSelectionGranularity: granularity]; [self setSelectionGranularity: granularity];
} }