Re: NSTableView and NSTextFieldCell redraw oddness when undo
Re: NSTableView and NSTextFieldCell redraw oddness when undo
- Subject: Re: NSTableView and NSTextFieldCell redraw oddness when undo
- From: "email@hidden" <email@hidden>
- Date: Fri, 13 Nov 2009 19:51:33 +0000
On 13 Nov 2009, at 17:02, Corbin Dunn wrote:
>
> On Nov 13, 2009, at 8:19 AM, email@hidden wrote:
>
>>
>> On 13 Nov 2009, at 15:15, Corbin Dunn wrote:
>>
>>>
>>> On Nov 13, 2009, at 6:35 AM, email@hidden wrote:
>>>
>>>> I have a subclassed NSTextFieldCell to create a cell that draws outside of it's frame.
>>>
>>> All the logic in tableview redraws things based on -frameOfCellAtColumn:row:. Things will frequently not get redrawn if you draw outside of those bounds.
>>>
>>> I recommend using a "full width" cell. See the AppKit release notes for 10.5
>> Unfortunately this won't work in this situation as my custom cell is only drawing over the last half of the table width.
>>
>> I looked -frameOfCellAtColumn:row: but overriding it seems impracticable.
>>
>> It seems very weird that the problem pops up following an undo (it is a coredata app though...).
>> Surely the NSTableColumn + NSCell won't know about the undo?
>>
>> I use the same cell subclass in an NSOutlineView of the same data and it works fine.
>
> It works fine purely by chance! Plus, there are probably some cases where it doesn't update properly (and you just haven't noticed yet). If the table needs to redraw cell X at column Y, it will mark the area dirty via -frameOfCellAtColumn:Y row:X.
>
>> Would this and the fact that NSOutlineView is an NSTableView subclass tend to indicate that I am screwing up somewhere?
>
> The error is having the cell draw outside of its given bounds. You need to change that (or else do the invalidation yourself, which will be difficult to get correct in all cases, unless you override frameOfCellAtColumn:row:. Simply adding a -setNeedsDisplay:YES to redraw everything is bad for performance).
>
Don't know what I was going on about before.
There is nothing impracticable about overriding -frameOfCellAtColumn:row:
In fact it's trivial.
And, more to the point, it works.
/*
frame of cell at column
*/
- (NSRect)frameOfCellAtColumn:(NSInteger)columnIndex row:(NSInteger)rowIndex
{
NSRect rect = [super frameOfCellAtColumn:columnIndex row:rowIndex];
if (columnIndex == EXTENDED_COLUMN_INDEX) {
NSCell *cell = [[[self tableColumns] objectAtIndex:columnIndex] dataCell];
if ([cell isKindOfClass:[MGSEntryTextCell class]] && [(MGSEntryTextCell *)cell extendCell]) {
rect.size.width = [self frame].size.width - rect.origin.x;
}
}
return rect;
}
Many thanks. I think that this would have eluded me without your input.
Jonathan
> --corbin
>
>
>
>
_______________________________________________
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