Here's the new diff.

The one thing I'm not sure about is the best way to communicate to the
GSThemeDrawing method how the color well should be drawn. Potentially
a theme could want to draw the "currently-being-pressed" and "active
color well" states differently. Right now I use isHighlighted /
setHighlighted: on the NSColorWell's NSCell, but I don't think that's
right.

-Eric

On Wed, Dec 9, 2009 at 4:35 PM, Eric Wasylishen <[email protected]> wrote:
> Hi Fred,
>
> On 2009-12-09, at 3:24 PM, Fred Kiefer wrote:
>
>> Hans Baier schrieb:
>>> Author: hansfbaier
>>> Date: Tue Dec  8 08:55:39 2009
>>> New Revision: 29106
>>>
>>> URL: http://svn.gna.org/viewcvs/gnustep?rev=29106&view=rev
>>> Log:
>>> * Source/NSColorWell.m (-mouseDragged:, -mouseDown:): Applied patch from 
>>> Eric Wasylishen to activate it on click inside the colored rectangle (same 
>>> behavior as in OS X)
>>>
>>> Modified:
>>>    libs/gui/trunk/ChangeLog
>>>    libs/gui/trunk/Source/NSColorWell.m
>>
>> I like this patch in general, what I dislike is the global variable that
>> gets used for the last mouse down position. Looking at the code I am
>> very sure that this wont lead to any side effects, still it is the wrong
>> way to code this. I would prefer that we come up with a better
>> implementation for this feature.
>>
>
>
> I agree, the global variable is ugly. I did some more investigation
> yesterday, and decided it would be best to use a mouse-tracking loop
> in mouseDown and eliminate the global variable. OS X appears to
> do this as well.
>
> I'm working on a new patch which fixes a bunch of little interaction
> details related to NSColorWell and NSColorPanel:
>
>  - activation of the well should really happen on mouseUp, not mouseDown
>  - non-bordered NSColorWells shouldn't be able to be activated by clicking
>  - non-bordered NSColorWells should start a drag operation upon mouseDown
>  - disabled NSColorWells shouldn't accept colours being dropped on them
>  - dropping a colour on the well inside the NSColorPanel should
>   also update the active NSColorWell
>
> I just want to do a bit more testing, and I'll post the patch later tonight 
> :-)
>
> Regards,
> Eric
>
>
Index: Source/NSColorWell.m
===================================================================
--- Source/NSColorWell.m	(revision 29108)
+++ Source/NSColorWell.m	(working copy)
@@ -46,8 +46,6 @@
 static NSString *GSColorWellDidBecomeExclusiveNotification =
                     @"GSColorWellDidBecomeExclusiveNotification";
 
-static NSPoint _lastMouseDownPoint;
-
 @implementation NSColorWell
 
 /*
@@ -102,6 +100,7 @@
            object: nil];
 
   _is_active = YES;
+  [[self cell] setHighlighted: YES];
 
   [colorPanel setColor: _the_color];
   [colorPanel orderFront: self];
@@ -124,6 +123,7 @@
 - (void) deactivate
 {
   _is_active = NO;
+  [[self cell] setHighlighted: NO];
 
   [[NSNotificationCenter defaultCenter] removeObserver: self];
 
@@ -147,6 +147,10 @@
   NSDragOperation sourceDragMask;
        
   NSDebugLLog(@"NSColorWell", @"%@: draggingEntered", self);
+
+  if ([self isEnabled] == NO)
+    return NSDragOperationNone;
+ 
   sourceDragMask = [sender draggingSourceOperationMask];
   pb = [sender draggingPasteboard];
  
@@ -285,39 +289,89 @@
 
 - (void) mouseDown: (NSEvent *)theEvent
 {
+  BOOL done;
+  BOOL inside;
+  BOOL startedInWell;
+  NSPoint point;
+
   //
   // OPENSTEP 4.2 and OSX behavior indicates that the colorwell doesn't
   // work when the widget is marked as disabled.
   //
-  if ([self isEnabled])
+  if ([self isEnabled] == NO)
+    return;
+
+  //
+  // Unbordered color wells start a drag immediately upon mouse down
+  //
+  if ([self isBordered] == NO)
     {
-      _lastMouseDownPoint = 
-         [self convertPoint: [theEvent locationInWindow]
-                   fromView: nil];
+      [NSColorPanel dragColor: _the_color
+		    withEvent: theEvent
+		    fromView: self];
+      return;
+    }
 
-      if (_is_active == NO)
+  point = [self convertPoint: [theEvent locationInWindow]
+		    fromView: nil];
+  startedInWell = [self mouse: point inRect: _wellRect];
+
+  [[self cell] setHighlighted: ![self isActive]];
+  [self setNeedsDisplay: YES];
+
+  done = NO;
+  while (!done)
+    {
+      theEvent = [[self window] nextEventMatchingMask: 
+		NSLeftMouseUpMask | NSLeftMouseDraggedMask];
+      point = [self convertPoint: [theEvent locationInWindow]
+		        fromView: nil];
+      inside = [self mouse: point inRect: [self bounds]];
+
+      switch ([theEvent type])
 	{
-	  [self activate: YES];
+	case NSLeftMouseDragged:
+	  if (startedInWell)
+	    {
+	      [[self cell] setHighlighted: [self isActive]];
+	      [self setNeedsDisplay: YES];
+
+	      [NSColorPanel dragColor: _the_color
+			    withEvent: theEvent
+			     fromView: self];
+	      done = YES;
+	    } 
+	  else 
+	    {
+	      [[self cell] setHighlighted: inside ^ [self isActive]];
+	      [self setNeedsDisplay: YES];
+	    }
+	  break;
+	case NSLeftMouseUp:
+	  if (inside)
+	    {
+	      if (_is_active == NO)
+		{
+		  [self activate: YES];
+		}
+	      else
+		{
+		  [self deactivate];
+		}
+	    } 
+	  else 
+	    {
+	      [[self cell] setHighlighted: [self isActive]];
+	      [self setNeedsDisplay: YES];
+	    }
+	  done = YES;
+	  break;
+	default:
+	  break;
 	}
-      else
-	{
-	  [self deactivate];
-	}
     }
 }
 
-- (void) mouseDragged: (NSEvent *)theEvent
-{
-  if ([self isEnabled])
-    {
-      if ([self mouse: _lastMouseDownPoint inRect: _wellRect])
-        {
-          [NSColorPanel dragColor: _the_color
-			withEvent: theEvent
-			fromView: self];
-        }
-    }
-}
 
 - (BOOL) performDragOperation: (id <NSDraggingInfo>)sender
 {
Index: Source/GSThemeDrawing.m
===================================================================
--- Source/GSThemeDrawing.m	(revision 29108)
+++ Source/GSThemeDrawing.m	(working copy)
@@ -728,7 +728,7 @@
       /*
        * Fill in control color.
        */
-      if ([well isActive])
+      if ([[well cell] isHighlighted])
 	{
 	  [[NSColor selectedControlColor] set];
 	}
Index: Source/NSColorPanel.m
===================================================================
--- Source/NSColorPanel.m	(revision 29108)
+++ Source/NSColorPanel.m	(working copy)
@@ -356,7 +356,7 @@
 
 - (void) _updatePicker: (id) sender
 {
-  [_currentPicker setColor: [_colorWell color]];
+  [self setColor: [_colorWell color]];
 }
 
 - (void) _bottomWellAction: (id) sender
_______________________________________________
Gnustep-dev mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/gnustep-dev

Reply via email to