Re: Repositioning the Field Editor
Re: Repositioning the Field Editor
- Subject: Re: Repositioning the Field Editor
- From: "K. Darcy Otto" <email@hidden>
- Date: Tue, 28 Apr 2009 12:47:00 -0700
Continuing on with the mystery, I have tried the following code in my
NSTableView subclass (below, not yet solved though). I have got it so
that the rect returned by [fieldEditor frame] is not empty, but gives
exactly the frame it should. Still though, modifying the frame to
something different makes no difference. Is there a way to prompt the
field editor to redraw itself in accordance with the new frame?
In the documentation for -editColumn:row:withEvent:select:, I noticed
that it "sends -selectWithFrame:inView:editor:delegate:start:length:
and -editWithFrame:inView:editor:delegate:event: to the field editor’s
NSCell object with the NSTableView as the text delegate. So my call
to super is doing that. Could it be that I need to intervene somehow
in these NSCell methods?
-(void)editColumn:(NSInteger)columnIndex row:(NSInteger)rowIndex
withEvent:(NSEvent *)theEvent select:(BOOL)flag
{
[super editColumn:columnIndex row:rowIndex withEvent:theEvent
select:flag];
NSTextView *fieldEditor = (NSTextView *)[[self window]
fieldEditor:YES forObject:nil];
// Change the text colour to red, just to confirm I've got ahold of
the actual field editor that is being used (I do)
[fieldEditor setTextColor:[NSColor redColor]];
// Get the field editor frame (it is the correct frame)
NSRect cellRect = [fieldEditor frame];
NSLog(@"1. fieldEditor x origin: %f",cellRect.origin.x); // output: 127
// Change cellRect x origin, but don't extend the field width
cellRect.origin.x += 20;
cellRect.size.width -= 20;
// Set fieldEditor frame to new cellRect
[fieldEditor setFrame:cellRect];
[fieldEditor setNeedsDisplay:YES];
cellRect = [fieldEditor frame];
NSLog(@"2. fieldEditor x origin: %f",cellRect.origin.x); // output: 147
}
On 27-Apr-09, at 7:19 PM, K. Darcy Otto wrote:
I have a field editor which I need to reposition in my tableView –
specifically, I need to move it a few pixels to the right. The
following post:
http://www.cocoabuilder.com/archive/message/cocoa/2009/3/16/232513
makes two suggestions: (i) implement the move in -viewWillDraw in
the field editor subclass, and (ii) reposition the field editor
after calling super in -editColumn:row:withEvent:select: in the
tableView subclass. Neither of these seem to make any difference to
where the field editor is drawn. Here is my code with respect to
(i), contained in the field editor subclass:
-(void)viewWillDraw
{
NSRect frame = [self frame];
NSLog(@"Old: %f",frame.origin.x);
frame.origin.x += 50.0;
[self setFrame:frame];
frame = [self frame];
NSLog(@"New: %f",frame.origin.x);
[super viewWillDraw];
}
Now, I can confirm this method is being called, and by means of the
NSLog statements, the frame is being changed prior to the call to
super. Unfortunately, the field editor is drawn where is usually is
drawn, with no shift in place.
With respect to (ii), contained in the tableView subclass:
-(void)editColumn:(NSInteger)columnIndex row:(NSInteger)rowIndex
withEvent:(NSEvent *)theEvent select:(BOOL)flag
{
[super editColumn:columnIndex row:rowIndex withEvent:theEvent
select:flag];
NSText *fieldEditor = [[self window] fieldEditor:YES forObject:self];
NSRect fieldEditorFrame = [fieldEditor frame];
fieldEditorFrame.origin.x += 50.0;
[fieldEditor setFrame:fieldEditorFrame];
}
Here, it turns out that even though fieldEditor points to the custom
field editor object, fieldEditorFrame turns out to be empty. And
again, the field editor is drawn where it is usually drawn, with no
shift in place.
Any help would be greatly appreciated.
_______________________________________________
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