mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 20:40:47 +00:00
Modifiefd color well to act more like NeXTstep one
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@9160 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
263723f59d
commit
a002d02682
2 changed files with 193 additions and 197 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
2001-02-18 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* Source/NSColorWell.m: Tidied a little, and made changes to conform
|
||||||
|
to macOS-X documentation and observed NeXTstep behavior. Of note -
|
||||||
|
1. colorwell should not deactivate when panel is closed.
|
||||||
|
2. setting color of an active well should set the color of the panel
|
||||||
|
(though it should not raise it).
|
||||||
|
|
||||||
Sun Feb 18 13:35:55 2001 Nicola Pero <n.pero@mi.flashnet.it>
|
Sun Feb 18 13:35:55 2001 Nicola Pero <n.pero@mi.flashnet.it>
|
||||||
|
|
||||||
* Source/NSClipView.m ([-setBoundsOrigin:]): Make rect to copy
|
* Source/NSClipView.m ([-setBoundsOrigin:]): Make rect to copy
|
||||||
|
|
|
@ -44,62 +44,115 @@ static NSString *GSColorWellDidBecomeExclusiveNotification =
|
||||||
|
|
||||||
@implementation NSColorWell
|
@implementation NSColorWell
|
||||||
|
|
||||||
//
|
/*
|
||||||
// Class methods
|
* Class methods
|
||||||
//
|
*/
|
||||||
+ (void)initialize
|
+ (void) initialize
|
||||||
{
|
{
|
||||||
if (self == [NSColorWell class])
|
if (self == [NSColorWell class])
|
||||||
[self setVersion: 1];
|
{
|
||||||
|
[self setVersion: 1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: This is a hack. An NSColorWell shouldn't need an associated
|
/*
|
||||||
// cell, but without one the setTarget: and setAction: methods get passed
|
* Instance methods
|
||||||
// to an NSCell object by the superclass (NSControl). NSCell raises an
|
*/
|
||||||
// exception on these methods, but NSActionCell actually implements them.
|
|
||||||
+ (Class)cellClass
|
- (BOOL) acceptsFirstMouse: (NSEvent *)event
|
||||||
{
|
{
|
||||||
return [NSActionCell class];
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
- (SEL) action
|
||||||
// Instance methods
|
|
||||||
//
|
|
||||||
- (id) initWithFrame: (NSRect)frameRect
|
|
||||||
{
|
{
|
||||||
[super initWithFrame: frameRect];
|
return _action;
|
||||||
|
}
|
||||||
|
|
||||||
_is_bordered = YES;
|
- (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];
|
||||||
|
|
||||||
|
_is_active = YES;
|
||||||
|
|
||||||
|
[colorPanel setColor: _the_color];
|
||||||
|
[colorPanel orderFront: self];
|
||||||
|
|
||||||
|
[self setNeedsDisplay: YES];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSColor *) color
|
||||||
|
{
|
||||||
|
return _the_color;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) deactivate
|
||||||
|
{
|
||||||
_is_active = NO;
|
_is_active = NO;
|
||||||
_the_color = RETAIN([NSColor blackColor]);
|
|
||||||
|
|
||||||
[self registerForDraggedTypes:
|
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
||||||
[NSArray arrayWithObjects: NSColorPboardType, nil]];
|
|
||||||
|
|
||||||
return self;
|
[self setNeedsDisplay: YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
if (_is_active)
|
if (_is_active == YES)
|
||||||
[self deactivate];
|
{
|
||||||
|
[self deactivate];
|
||||||
|
}
|
||||||
TEST_RELEASE(_the_color);
|
TEST_RELEASE(_the_color);
|
||||||
[self unregisterDraggedTypes];
|
[self unregisterDraggedTypes];
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
- (unsigned int) draggingEntered: (id <NSDraggingInfo>)sender
|
||||||
* Drawing
|
{
|
||||||
*/
|
NSPasteboard *pb;
|
||||||
|
NSDragOperation sourceDragMask;
|
||||||
|
|
||||||
|
NSDebugLLog(@"NSColorWell", @"%@: draggingEntered", self);
|
||||||
|
sourceDragMask = [sender draggingSourceOperationMask];
|
||||||
|
pb = [sender draggingPasteboard];
|
||||||
|
|
||||||
|
if ([[pb types] indexOfObject: NSColorPboardType] != NSNotFound)
|
||||||
|
{
|
||||||
|
if (sourceDragMask & NSDragOperationCopy)
|
||||||
|
{
|
||||||
|
return NSDragOperationCopy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NSDragOperationNone;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (unsigned int) draggingSourceOperationMaskForLocal: (BOOL)flag
|
||||||
|
{
|
||||||
|
return NSDragOperationCopy;
|
||||||
|
}
|
||||||
|
|
||||||
- (void) drawRect: (NSRect)clipRect
|
- (void) drawRect: (NSRect)clipRect
|
||||||
{
|
{
|
||||||
NSRect aRect = _bounds;
|
NSRect aRect = _bounds;
|
||||||
|
|
||||||
if (NSIntersectsRect(aRect, clipRect) == NO)
|
if (NSIntersectsRect(aRect, clipRect) == NO)
|
||||||
return;
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (_is_bordered)
|
if (_is_bordered == YES)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Draw border.
|
* Draw border.
|
||||||
|
@ -110,10 +163,14 @@ static NSString *GSColorWellDidBecomeExclusiveNotification =
|
||||||
* Fill in control color.
|
* Fill in control color.
|
||||||
*/
|
*/
|
||||||
aRect = NSInsetRect(aRect, 2.0, 2.0);
|
aRect = NSInsetRect(aRect, 2.0, 2.0);
|
||||||
if (_is_active)
|
if (_is_active == YES)
|
||||||
[[NSColor selectedControlColor] set];
|
{
|
||||||
|
[[NSColor selectedControlColor] set];
|
||||||
|
}
|
||||||
else
|
else
|
||||||
[[NSColor controlColor] set];
|
{
|
||||||
|
[[NSColor controlColor] set];
|
||||||
|
}
|
||||||
NSRectFill(NSIntersectionRect(aRect, clipRect));
|
NSRectFill(NSIntersectionRect(aRect, clipRect));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -122,7 +179,9 @@ static NSString *GSColorWellDidBecomeExclusiveNotification =
|
||||||
_wellRect = NSInsetRect(_bounds, 8.0, 8.0);
|
_wellRect = NSInsetRect(_bounds, 8.0, 8.0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
_wellRect = _bounds;
|
{
|
||||||
|
_wellRect = _bounds;
|
||||||
|
}
|
||||||
|
|
||||||
aRect = _wellRect;
|
aRect = _wellRect;
|
||||||
|
|
||||||
|
@ -151,11 +210,61 @@ static NSString *GSColorWellDidBecomeExclusiveNotification =
|
||||||
[_the_color drawSwatchInRect: insideRect];
|
[_the_color drawSwatchInRect: insideRect];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) acceptsFirstMouse: (NSEvent *)event
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||||
{
|
{
|
||||||
return YES;
|
[super encodeWithCoder: aCoder];
|
||||||
|
[aCoder encodeObject: _the_color];
|
||||||
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_is_active];
|
||||||
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_is_bordered];
|
||||||
|
[aCoder encodeConditionalObject: _target];
|
||||||
|
[aCoder encodeValueOfObjCType: @encode(SEL) at: &_action];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (id) initWithCoder: (NSCoder*)aDecoder
|
||||||
|
{
|
||||||
|
self = [super initWithCoder: aDecoder];
|
||||||
|
if (self != nil)
|
||||||
|
{
|
||||||
|
[aDecoder decodeValueOfObjCType: @encode(id) at: &_the_color];
|
||||||
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_is_active];
|
||||||
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_is_bordered];
|
||||||
|
[aDecoder decodeValueOfObjCType: @encode(id) at: &_target];
|
||||||
|
// Undo RETAIN by decoder
|
||||||
|
TEST_RELEASE(_target);
|
||||||
|
[aDecoder decodeValueOfObjCType: @encode(SEL) at: &_action];
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id) initWithFrame: (NSRect)frameRect
|
||||||
|
{
|
||||||
|
self = [super initWithFrame: frameRect];
|
||||||
|
if (self != nil)
|
||||||
|
{
|
||||||
|
_is_bordered = YES;
|
||||||
|
_is_active = NO;
|
||||||
|
_the_color = RETAIN([NSColor blackColor]);
|
||||||
|
|
||||||
|
[self registerForDraggedTypes:
|
||||||
|
[NSArray arrayWithObjects: NSColorPboardType, nil]];
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) isActive
|
||||||
|
{
|
||||||
|
return _is_active;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) isBordered
|
||||||
|
{
|
||||||
|
return _is_bordered;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) isOpaque
|
||||||
|
{
|
||||||
|
return _is_bordered;
|
||||||
|
}
|
||||||
|
|
||||||
- (void) mouseDown: (NSEvent *)theEvent
|
- (void) mouseDown: (NSEvent *)theEvent
|
||||||
{
|
{
|
||||||
|
@ -170,81 +279,64 @@ static NSString *GSColorWellDidBecomeExclusiveNotification =
|
||||||
}
|
}
|
||||||
else if (_is_active == NO)
|
else if (_is_active == NO)
|
||||||
{
|
{
|
||||||
NSColorPanel *colorPanel = [NSColorPanel sharedColorPanel];
|
|
||||||
|
|
||||||
[self activate: YES];
|
[self activate: YES];
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter]
|
|
||||||
addObserver: self
|
|
||||||
selector: @selector(deactivate)
|
|
||||||
name: NSWindowWillCloseNotification
|
|
||||||
object: colorPanel];
|
|
||||||
|
|
||||||
[colorPanel setColor: _the_color];
|
|
||||||
[colorPanel orderFront: self];
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
[self deactivate];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (BOOL) isOpaque
|
|
||||||
{
|
|
||||||
return _is_bordered;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// Activating
|
|
||||||
//
|
|
||||||
- (void)activate: (BOOL)exclusive
|
|
||||||
{
|
|
||||||
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
|
||||||
|
|
||||||
if (exclusive == YES)
|
|
||||||
{
|
{
|
||||||
[nc postNotificationName: GSColorWellDidBecomeExclusiveNotification
|
[self deactivate];
|
||||||
object: self];
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[nc addObserver: self
|
- (BOOL) performDragOperation: (id <NSDraggingInfo>)sender
|
||||||
selector: @selector(deactivate)
|
{
|
||||||
name: GSColorWellDidBecomeExclusiveNotification
|
NSPasteboard *pb = [sender draggingPasteboard];
|
||||||
object: nil];
|
|
||||||
|
NSDebugLLog(@"NSColorWell", @"%@: performDragOperation", self);
|
||||||
|
[self setColor: [NSColor colorFromPasteboard: pb]];
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) prepareForDragOperation: (id <NSDraggingInfo>)sender
|
||||||
|
{
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) setAction: (SEL)action
|
||||||
|
{
|
||||||
|
_action = action;
|
||||||
|
}
|
||||||
|
|
||||||
_is_active = YES;
|
- (void) setBordered: (BOOL)bordered
|
||||||
|
{
|
||||||
|
_is_bordered = bordered;
|
||||||
[self setNeedsDisplay: YES];
|
[self setNeedsDisplay: YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)deactivate
|
|
||||||
{
|
|
||||||
_is_active = NO;
|
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
|
||||||
|
|
||||||
[self setNeedsDisplay: YES];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (BOOL)isActive
|
|
||||||
{
|
|
||||||
return _is_active;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Managing Color
|
|
||||||
//
|
|
||||||
- (NSColor *) color
|
|
||||||
{
|
|
||||||
return _the_color;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) setColor: (NSColor *)color
|
- (void) setColor: (NSColor *)color
|
||||||
{
|
{
|
||||||
ASSIGN(_the_color, 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
|
// Notify our target of colour change
|
||||||
[self sendAction: _action to: _target];
|
[self sendAction: _action to: _target];
|
||||||
[self setNeedsDisplay: YES];
|
[self setNeedsDisplay: YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) setTarget: (id)target
|
||||||
|
{
|
||||||
|
_target = target;
|
||||||
|
}
|
||||||
|
|
||||||
- (void) takeColorFrom: (id)sender
|
- (void) takeColorFrom: (id)sender
|
||||||
{
|
{
|
||||||
if ([sender respondsToSelector: @selector(color)])
|
if ([sender respondsToSelector: @selector(color)])
|
||||||
|
@ -253,114 +345,10 @@ static NSString *GSColorWellDidBecomeExclusiveNotification =
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void) setAction: (SEL)action
|
|
||||||
{
|
|
||||||
_action = action;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (SEL) action
|
|
||||||
{
|
|
||||||
return _action;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) setTarget: (id)target
|
|
||||||
{
|
|
||||||
_target = target;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id) target
|
- (id) target
|
||||||
{
|
{
|
||||||
return _target;
|
return _target;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// Managing Borders
|
|
||||||
//
|
|
||||||
- (BOOL) isBordered
|
|
||||||
{
|
|
||||||
return _is_bordered;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) setBordered: (BOOL)bordered
|
|
||||||
{
|
|
||||||
_is_bordered = bordered;
|
|
||||||
[self setNeedsDisplay: YES];
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// NSDraggingSource
|
|
||||||
//
|
|
||||||
|
|
||||||
- (unsigned int) draggingSourceOperationMaskForLocal: (BOOL)flag
|
|
||||||
{
|
|
||||||
return NSDragOperationCopy;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// NSDraggingDestination
|
|
||||||
//
|
|
||||||
|
|
||||||
- (unsigned int) draggingEntered: (id <NSDraggingInfo>)sender
|
|
||||||
{
|
|
||||||
NSPasteboard *pb;
|
|
||||||
NSDragOperation sourceDragMask;
|
|
||||||
|
|
||||||
NSDebugLLog(@"NSColorWell", @"%@: draggingEntered", self);
|
|
||||||
sourceDragMask = [sender draggingSourceOperationMask];
|
|
||||||
pb = [sender draggingPasteboard];
|
|
||||||
|
|
||||||
if ([[pb types] indexOfObject: NSColorPboardType] != NSNotFound)
|
|
||||||
{
|
|
||||||
if (sourceDragMask & NSDragOperationCopy)
|
|
||||||
{
|
|
||||||
return NSDragOperationCopy;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NSDragOperationNone;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (BOOL) prepareForDragOperation: (id <NSDraggingInfo>)sender
|
|
||||||
{
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (BOOL) performDragOperation: (id <NSDraggingInfo>)sender
|
|
||||||
{
|
|
||||||
NSPasteboard *pb = [sender draggingPasteboard];
|
|
||||||
|
|
||||||
NSDebugLLog(@"NSColorWell", @"%@: performDragOperation", self);
|
|
||||||
[self setColor: [NSColor colorFromPasteboard: pb]];
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// NSCoding protocol
|
|
||||||
//
|
|
||||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
|
||||||
{
|
|
||||||
[super encodeWithCoder: aCoder];
|
|
||||||
[aCoder encodeObject: _the_color];
|
|
||||||
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_is_active];
|
|
||||||
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_is_bordered];
|
|
||||||
[aCoder encodeConditionalObject: _target];
|
|
||||||
[aCoder encodeValueOfObjCType: @encode(SEL) at: &_action];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id) initWithCoder: (NSCoder*)aDecoder
|
|
||||||
{
|
|
||||||
[super initWithCoder: aDecoder];
|
|
||||||
[aDecoder decodeValueOfObjCType: @encode(id) at: &_the_color];
|
|
||||||
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_is_active];
|
|
||||||
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_is_bordered];
|
|
||||||
[aDecoder decodeValueOfObjCType: @encode(id) at: &_target];
|
|
||||||
// Undo RETAIN by decoder
|
|
||||||
TEST_RELEASE(_target);
|
|
||||||
[aDecoder decodeValueOfObjCType: @encode(SEL) at: &_action];
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue