Re: NSCell interiorBackgroundStyle wrong?
Re: NSCell interiorBackgroundStyle wrong?
- Subject: Re: NSCell interiorBackgroundStyle wrong?
- From: Seth Willits <email@hidden>
- Date: Fri, 31 May 2013 15:18:09 -0700
On May 31, 2013, at 2:11 PM, Kyle Sluder wrote:
> On Fri, May 31, 2013, at 01:42 PM, Seth Willits wrote:
>> In my case, since the cell does not draw its own background, the
>> interiorBackgroundStyle should simply be whatever the backgroundStyle is,
>> right?
>
> backgroundStyle refers to the style of the _container_ relative to the
> _control_. That's why it has a setter.
>
> interiorBackgroundStyle refers to the style of _some of the cell's
> drawing_ related to _some of the cell's other drawing_. That's why it
> doesn't have a setter, because all the state that affects it is
> contained within the cell.
I'm very well aware of all of that. I'm not sure what gave the impression I don't.
My point is that if the cell itself has no background, then the cell's "interior background" has to reflect whatever the container's background is. Hence interiorBackgroundStyle would return the same value as backgroundStyle which is set from wherever.
(The problem is that interiorBackgroundStyle is doing dual duty so you have to handle the field editor as well…)
>> So the correct solution involves overriding the editing-related methods
>> and setting an internal flag to know when editing is happening, and
>> return NSBackgroundLight when editing, otherwise return
>> self.backgroundStyle. Ugh.
>
> Can you instead just override -setUpFieldEditorAttributes: to call super
> and then trump its decisions?
I could, but I consider that a bigger can of ugly. What if something else calls interiorBackgroundStyle and makes the same mistake? Considering NSCell/NSTextFieldCell itself tweaks the interiorBackgroundStyle rather than handling it in -setupFieldEditorAttributes:, I don't think it's a far fetched idea.
Overall, it's actually simple. It just took me hours to figure out how all the pieces fit together:
- (NSColor *)highlightColorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView;
{
return nil;
}
- (NSBackgroundStyle)interiorBackgroundStyle;
{
if (mIsEditing) {
return NSBackgroundStyleLight;
}
return self.backgroundStyle;
}
- (void)editWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject event:(NSEvent *)theEvent;
{
mIsEditing = YES;
[super editWithFrame:aRect inView:controlView editor:textObj delegate:anObject event:theEvent];
}
- (void)selectWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject start:(NSInteger)selStart length:(NSInteger)selLength;
{
mIsEditing = YES;
[super selectWithFrame:aRect inView:controlView editor:textObj delegate:anObject start:selStart length:selLength];
}
- (void)endEditing:(NSText *)textObj;
{
mIsEditing = NO;
[super endEditing:textObj];
}
With the above, the cell can be dumped into a standard or customized table view and its backgroundStyle set to either Light or Dark and it'll adapt correctly, unlike NSTextFieldCell right out of the box.
(Related: I haven't come across reasoning for why a cell draws the highlight color within its drawInterior…: method. Where does that ever get used? In a table view, for instance, the table view draws the selection highlight anyway.)
-- Seth
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden