diff --git a/ChangeLog b/ChangeLog index 4569c7ef3..6a814308d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2209-12-20 Eric Wasylishen + + * Source/NSColorWell.m + * Source/GSThemeDrawing.m + * Source/NSColorPanel.m + * Headers/AppKit/NSColorWell.h: + Finish NSColorWell interaction tweaks: + - activation of the now happens on mouseUp, not mouseDown + - non-bordered NSColorWells can't be activated by clicking + - non-bordered NSColorWells start a drag operation upon mouseDown + - disabled NSColorWells don't accept colours being dropped on them + - dropping a colour on the well inside the NSColorPanel now + also updates the active NSColorWell + Also moved the static variable for keeping track of where the mouseDown + occurred to an instance variable. + 2009-12-21 Fred Kiefer * Source/NSTableColumn.m (-initWithCoder:, -encodeWithCoder:): Add diff --git a/Headers/AppKit/NSColorWell.h b/Headers/AppKit/NSColorWell.h index 62cf03613..d38ffbe33 100644 --- a/Headers/AppKit/NSColorWell.h +++ b/Headers/AppKit/NSColorWell.h @@ -45,6 +45,8 @@ NSRect _wellRect; id _target; SEL _action; + // Mouse tracking + NSPoint _mouseDownPoint; } // diff --git a/Source/GSThemeDrawing.m b/Source/GSThemeDrawing.m index ceeaa9935..9c85dea81 100644 --- a/Source/GSThemeDrawing.m +++ b/Source/GSThemeDrawing.m @@ -728,7 +728,7 @@ /* * Fill in control color. */ - if ([well isActive]) + if ([[well cell] isHighlighted] || [well isActive]) { [[NSColor selectedControlColor] set]; } diff --git a/Source/NSColorPanel.m b/Source/NSColorPanel.m index be7e6c045..f88a8000c 100644 --- a/Source/NSColorPanel.m +++ b/Source/NSColorPanel.m @@ -356,7 +356,7 @@ static int _gs_gui_color_picker_mode = NSRGBModeColorPanel; - (void) _updatePicker: (id) sender { - [_currentPicker setColor: [_colorWell color]]; + [self setColor: [_colorWell color]]; } - (void) _bottomWellAction: (id) sender diff --git a/Source/NSColorWell.m b/Source/NSColorWell.m index e98051597..4b5fb3636 100644 --- a/Source/NSColorWell.m +++ b/Source/NSColorWell.m @@ -46,8 +46,6 @@ static NSString *GSColorWellDidBecomeExclusiveNotification = @"GSColorWellDidBecomeExclusiveNotification"; -static NSPoint _lastMouseDownPoint; - @implementation NSColorWell /* @@ -147,6 +145,10 @@ static NSPoint _lastMouseDownPoint; NSDragOperation sourceDragMask; NSDebugLLog(@"NSColorWell", @"%@: draggingEntered", self); + + if ([self isEnabled] == NO) + return NSDragOperationNone; + sourceDragMask = [sender draggingSourceOperationMask]; pb = [sender draggingPasteboard]; @@ -289,12 +291,65 @@ static NSPoint _lastMouseDownPoint; // OPENSTEP 4.2 and OSX behavior indicates that the colorwell doesn't // work when the widget is marked as disabled. // - if ([self isEnabled]) - { - _lastMouseDownPoint = - [self convertPoint: [theEvent locationInWindow] - fromView: nil]; + if ([self isEnabled] == NO) + return; + // Unbordered color wells start a drag immediately upon mouse down + if ([self isBordered] == NO) + { + [NSColorPanel dragColor: _the_color + withEvent: theEvent + fromView: self]; + return; + } + + _mouseDownPoint = [self convertPoint: [theEvent locationInWindow] + fromView: nil]; + [[self cell] setHighlighted: YES]; + [self setNeedsDisplay: YES]; +} + +- (void) mouseDragged: (NSEvent *)theEvent +{ + NSPoint point = [self convertPoint: [theEvent locationInWindow] + fromView: nil]; + BOOL inside = [self mouse: point inRect: [self bounds]]; + BOOL startedInWell = [self mouse: _mouseDownPoint inRect: _wellRect]; + + if ([self isEnabled] == NO) + return; + + if (startedInWell) + { + [[self cell] setHighlighted: NO]; + [self setNeedsDisplay: YES]; + + [NSColorPanel dragColor: _the_color + withEvent: theEvent + fromView: self]; + return; + } + else + { + [[self cell] setHighlighted: inside]; + [self setNeedsDisplay: YES]; + } +} + +- (void) mouseUp: (NSEvent *)theEvent +{ + NSPoint point = [self convertPoint: [theEvent locationInWindow] + fromView: nil]; + BOOL inside = [self mouse: point inRect: [self bounds]]; + + if ([self isEnabled] == NO) + return; + + [[self cell] setHighlighted: NO]; + [self setNeedsDisplay: YES]; + + if (inside) + { if (_is_active == NO) { [self activate: YES]; @@ -306,19 +361,6 @@ static NSPoint _lastMouseDownPoint; } } -- (void) mouseDragged: (NSEvent *)theEvent -{ - if ([self isEnabled]) - { - if ([self mouse: _lastMouseDownPoint inRect: _wellRect]) - { - [NSColorPanel dragColor: _the_color - withEvent: theEvent - fromView: self]; - } - } -} - - (BOOL) performDragOperation: (id )sender { NSPasteboard *pb = [sender draggingPasteboard];