Index: NSScroller.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/gui/Source/NSScroller.m,v
retrieving revision 1.67
diff -u -r1.67 NSScroller.m
--- NSScroller.m	30 Mar 2003 17:24:47 -0000	1.67
+++ NSScroller.m	2 Apr 2003 10:01:24 -0000
@@ -583,8 +583,7 @@
 - (void) trackKnob: (NSEvent*)theEvent
 {
   unsigned int eventMask = NSLeftMouseDownMask | NSLeftMouseUpMask
-			  | NSLeftMouseDraggedMask | NSMouseMovedMask
-			  | NSPeriodicMask;
+			  | NSPeriodicMask | NSFlagsChangedMask;
   NSPoint	point;
   NSPoint	apoint;
   float		lastPosition;
@@ -616,49 +615,58 @@
    * set periodic events rate to achieve max of ~30fps
    */
   [NSEvent startPeriodicEventsAfterDelay: 0.02 withPeriod: 0.03];
-  [[NSRunLoop currentRunLoop] limitDateForMode: NSEventTrackingRunLoopMode];
 
   while ((eventType = [theEvent type]) != NSLeftMouseUp)
     {
       CREATE_AUTORELEASE_POOL(arp);
-      if (eventType != NSPeriodic)
-	{
-	  apoint = [theEvent locationInWindow];
-	  flags = [theEvent modifierFlags];
-	}
-      else
-	{
-	  point = [self convertPoint: apoint fromView: nil];
-          if (_isHorizontal)
-	    newPosition = point.x + offset;
-          else
-	    newPosition = point.y + offset;
-
-          if (newPosition != lastPosition)
-            {
-              if (flags & NSAlternateKeyMask)
-	        {
-	          float	diff;
-
-	          diff = newPosition - lastPosition;
-	          diff = diff * 3 / 4;
-	          offset -= diff;
-	          newPosition -= diff;
-	        }
-
-              // only one coordinate (X or Y) is used to compute floatValue.
-              point = NSMakePoint(newPosition, newPosition);
-	      floatValue = [self _floatValueForMousePoint: point];
-
-	      if (floatValue != _floatValue)
-		{
-		  [self setFloatValue: floatValue];
-		  [self sendAction: _action to: _target];
-		}
+      switch (eventType)
+        {
+	  case NSLeftMouseDown:
+	    /* This our first event */
+	    break;
+	  case NSFlagsChanged:
+	    /* We get this event when the user makes use of a modifier key */
+	    flags = [theEvent modifierFlags];
+	    break;
+	  case NSPeriodic:
+	    {
+	      point = [self convertPoint: [_window mouseLocationOutsideOfEventStream] 
+			        fromView: nil];
+
+              if (_isHorizontal)
+	        newPosition = point.x + offset;
+              else
+	        newPosition = point.y + offset;
+
+              if (newPosition != lastPosition)
+                {
+                  if (flags & NSAlternateKeyMask)
+	            {
+	              float	diff;
+
+	              diff = newPosition - lastPosition;
+	              diff = diff * 3 / 4;
+	              offset -= diff;
+	              newPosition -= diff;
+	            }
+
+                  // only one coordinate (X or Y) is used to compute floatValue.
+                  point = NSMakePoint(newPosition, newPosition);
+	          floatValue = [self _floatValueForMousePoint: point];
+
+	          if (floatValue != _floatValue)
+		    {
+		      [self setFloatValue: floatValue];
+		      [self sendAction: _action to: _target];
+		    }
 	      
-	      lastPosition = newPosition;
-            }
-	}
+	          lastPosition = newPosition;
+                }
+	      break;
+	    }
+	  default:
+	    NSLog(@"unhandled event.");
+        }
 
       theEvent = [NSApp nextEventMatchingMask: eventMask
 				    untilDate: theDistantFuture
@@ -671,78 +679,70 @@
 
 - (void) trackScrollButtons: (NSEvent*)theEvent
 {
-  NSApplication	*theApp = [NSApplication sharedApplication];
-  unsigned int	eventMask = NSLeftMouseDownMask | NSLeftMouseUpMask |
-			  NSLeftMouseDraggedMask | NSMouseMovedMask;
-  BOOL		shouldReturn = NO;
   id		theCell = nil;
   NSRect	rect;
 
   [self lockFocus];
 
   NSDebugLog (@"trackScrollButtons");
-  do
-    {
-      _hitPart = [self testPart: [theEvent locationInWindow]];
-      rect = [self rectForPart: _hitPart];
 
-      /*
-       * A hit on a scroller button should be a page movement
-       * if the alt key is pressed.
-       */
-      switch (_hitPart)
-	{
-	  case NSScrollerIncrementLine:
-	    if ([theEvent modifierFlags] & NSAlternateKeyMask)
-	      {
-		_hitPart = NSScrollerIncrementPage;
-	      }
-	    /* Fall through to next case */
-	  case NSScrollerIncrementPage:
-	    theCell = (_isHorizontal ? rightCell : downCell);
-	    break;
+  _hitPart = [self testPart: [theEvent locationInWindow]];
+  rect = [self rectForPart: _hitPart];
 
-	  case NSScrollerDecrementLine:
-	    if ([theEvent modifierFlags] & NSAlternateKeyMask)
-	      {
-		_hitPart = NSScrollerDecrementPage;
-	      }
-	    /* Fall through to next case */
-	  case NSScrollerDecrementPage:
-	    theCell = (_isHorizontal ? leftCell : upCell);
-	    break;
-
-	  default:
-	    theCell = nil;
-	    break;
-	}
+  /*
+   * A hit on a scroller button should be a page movement
+   * if the alt key is pressed.
+   */
+  switch (_hitPart)
+    {
+      case NSScrollerIncrementLine:
+        if ([theEvent modifierFlags] & NSAlternateKeyMask)
+	  {
+	    _hitPart = NSScrollerIncrementPage;
+	  }
+	/* Fall through to next case */
+      case NSScrollerIncrementPage:
+	theCell = (_isHorizontal ? rightCell : downCell);
+	break;
 
-      if (theCell)
-	{
-	  [theCell highlight: YES withFrame: rect inView: self];
-	  [_window flushWindow];
+      case NSScrollerDecrementLine:
+	if ([theEvent modifierFlags] & NSAlternateKeyMask)
+	  {
+	    _hitPart = NSScrollerDecrementPage;
+	  }
+	/* Fall through to next case */
+      case NSScrollerDecrementPage:
+	theCell = (_isHorizontal ? leftCell : upCell);
+	break;
 
-	  NSDebugLog (@"tracking cell %x", theCell);
+      default:
+	theCell = nil;
+	break;
+    }
 
-	  shouldReturn = [theCell trackMouse: theEvent
-				      inRect: rect
-				      ofView: self
-				untilMouseUp: YES];
+  /*
+   * If we don't find a cell this has been all for naught, but we 
+   * shouldn't ever be in that situation.
+   */
+  if (theCell)
+    {
+      [theCell highlight: YES withFrame: rect inView: self];
+      [_window flushWindow];
 
-	  [theCell highlight: NO withFrame: rect inView: self];
-	  [_window flushWindow];
-	}
+      NSDebugLog (@"tracking cell %x", theCell);
 
-      if (shouldReturn)
-	break;
+      /*
+       * The "tracking" in this method actually takes place within 
+       * NSCell's trackMouse: method. 
+       */
+      [theCell trackMouse: theEvent
+		   inRect: rect
+		   ofView: self
+	     untilMouseUp: YES];
 
-      theEvent = [theApp nextEventMatchingMask: eventMask
-				     untilDate: [NSDate distantFuture]
-					inMode: NSEventTrackingRunLoopMode
-				       dequeue: YES];
+      [theCell highlight: NO withFrame: rect inView: self];
+      [_window flushWindow];
     }
-  while ([theEvent type] != NSLeftMouseUp);
-
   [self unlockFocus];
 
   NSDebugLog (@"return from trackScrollButtons");
