/**
Activates the NSColorWell and displays the NSColorPanel with the current NSColorWell's color. The NSColorWell can take color from the NSColorPanel. If exclusive is YES other NSColorWells are desacivated (through notifications)
See Also: -deactivate
*/ - (void) activate: (BOOL)exclusive { NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; NSColorPanel *colorPanel = [NSColorPanel sharedColorPanel]; if (exclusive == YES) { [nc postNotificationName: GSColorWellDidBecomeExclusiveNotification object: self]; } [nc addObserver: self selector: @selector(deactivate) name: GSColorWellDidBecomeExclusiveNotification object: nil]; [nc addObserver: self selector: @selector(_takeColorFromPanel:) name: NSColorPanelColorChangedNotification object: nil]; _is_active = YES; [colorPanel setColor: _the_color]; [colorPanel orderFront: self]; [self setNeedsDisplay: YES]; } /**Returns the current NSColor of the NSColorWell.
See Also: -setColor:
*/ - (NSColor *) color { return _the_color; } /**Desactivates the NSColorWell and marks self for display. It is usally call from an observer, when another NSColorWell is activate.
See Also: -activate:
*/ - (void) deactivate { _is_active = NO; [[NSNotificationCenter defaultCenter] removeObserver: self]; [self setNeedsDisplay: YES]; } - (void) dealloc { if (_is_active == YES) { [self deactivate]; } TEST_RELEASE(_the_color); [self unregisterDraggedTypes]; [super dealloc]; } - (unsigned int) draggingEntered: (idReturns whether the NSColorWell is active. By default a NSColorWell is not active.
See Also: -activate: -deactivate
*/ - (BOOL) isActive { return _is_active; } /**Returns whether the NSColorWell has border. By default a NSColorWell has border.
See Also: -setBordered:
*/ - (BOOL) isBordered { return _is_bordered; } - (BOOL) isOpaque { return _is_bordered; } - (void) mouseDown: (NSEvent *)theEvent { // // OPENSTEP 4.2 and OSX behavior indicates that the colorwell doesn't // work when the widget is marked as disabled. // if ([self isEnabled]) { NSPoint point = [self convertPoint: [theEvent locationInWindow] fromView: nil]; if ([self mouse: point inRect: _wellRect]) { [NSColorPanel dragColor: _the_color withEvent: theEvent fromView: self]; } else if (_is_active == NO) { [self activate: YES]; } else { [self deactivate]; } } } - (BOOL) performDragOperation: (idSets whether the NSColorWell has border and marks self for display. By default a NSColorWell has border.
See Also: -isBordered
*/ - (void) setBordered: (BOOL)bordered { _is_bordered = bordered; [self setNeedsDisplay: YES]; } /**Sets the NSColorWell to color. Sets the NSColorPanel if active, notify the target of color change and marks self to display
See Also: -color
*/ - (void) setColor: (NSColor *)color { ASSIGN(_the_color, color); /* * Experimentation with NeXTstep shows that when the color of an active * colorwell is set, the color of the shared color panel is set too, * though this does not raise the color panel, only the event of * activation does that. */ if ([self isActive]) { NSColorPanel *colorPanel = [NSColorPanel sharedColorPanel]; [colorPanel setColor: _the_color]; } // Notify our target of colour change [self sendAction: _action to: _target]; [self setNeedsDisplay: YES]; } - (void) setTarget: (id)target { _target = target; } /**Sets the NSColorWell's color to the sender color
*/ - (void) takeColorFrom: (id)sender { if ([sender respondsToSelector: @selector(color)]) { [self setColor: [sender color]]; } } - (void) _takeColorFromPanel: (NSNotification *) notification { id sender = [notification object]; if ([sender respondsToSelector: @selector(color)]) { ASSIGN(_the_color, [(id)sender color]); [self sendAction: _action to: _target]; [self setNeedsDisplay: YES]; } } - (id) target { return _target; } @end