• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
ColorCell, NSActionCell subclass
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ColorCell, NSActionCell subclass


  • Subject: ColorCell, NSActionCell subclass
  • From: Carl Gieringer <email@hidden>
  • Date: Sun, 17 Apr 2005 21:53:52 -0800

Hello,

I have not found this question definitively answered in the archives or via google, but I apologize if I missed something.

I am trying to create a subclass of NSActionCell that displays a color. Clicking on the cell presents the color panel, which allows the user to change the color of the cell. I am having a problem propagating the selection of a color back to the object which is "represented" by the cell. In particular, I do not understand how to get an NSTableView to call -tableView:setObjectValue:forTableColumn:row: on its dataSource when I am using this custom cell in one of the NSTableView's columns. I thought that calling -setObjectValue on my cell would suffice, but it doesn't.

My implementation follows; thanks!

- (id) init
{
	if ( self = [super init] ) {

		[self setEditable:YES];
		[self setTarget:self];
		[self setAction:@selector(changeColor:)];

	}
	return self;
}

- (IBAction) changeColor: (id) sender
{
	NSColorPanel* colorPanel = [NSColorPanel sharedColorPanel];

	// don't send the panel nil
	[colorPanel setColor:
		( [self objectValue] ? [self objectValue] : [NSColor whiteColor] )];

	[colorPanel setTarget:self];
	[colorPanel setAction: @selector(commitColor:)];
	[colorPanel setContinuous:YES];

	[colorPanel makeKeyAndOrderFront:self];
}

- (IBAction) commitColor:(id) sender
{
	[self setObjectValue:[sender color]];
}

- (void) drawWithFrame:(NSRect) cellFrame inView:(NSView *) controlView
{
NSRect borderRect = NSInsetRect (cellFrame, 0.5, 0.5);

// use the smallest size to sqare off the box & center the box
if (borderRect.size.height < borderRect.size.width) {

borderRect.size.width = borderRect.size.height;
borderRect.origin.x = borderRect.origin.x + (cellFrame.size.width - borderRect.size.width) / 2.0;

} else {

borderRect.size.height = borderRect.size.width;
borderRect.origin.y = borderRect.origin.y + (cellFrame.size.height - borderRect.size.height) / 2.0;

}

[[NSColor grayColor] set];
[NSBezierPath strokeRect: borderRect];


[(NSColor *)[self objectValue] drawSwatchInRect:NSInsetRect (borderRect, 2.0, 2.0)];
}


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: ColorCell, NSActionCell subclass
      • From: Carl Gieringer <email@hidden>
  • Prev by Date: Re: Permissions problem after NSTask application launch
  • Next by Date: Re: Custom view, selection consistency with NSTableView
  • Previous by thread: Re: Permissions problem after NSTask application launch
  • Next by thread: Re: ColorCell, NSActionCell subclass
  • Index(es):
    • Date
    • Thread