field editor oddness
field editor oddness
- Subject: field editor oddness
- From: Tom Waters <email@hidden>
- Date: Mon, 25 Jun 2001 18:59:48 -0700
I am re-attempting to use the built-in field editor in NSWindow.
In an earlier attempt, I subclassed NSTextView and did it myself,
because I was frustrated with attempts to make the standard one work
right. But I would prefer to do things the "correct" way, as opposed to
simply making it work.
Here's a simple example of what I am seeing that seems odd/wrong.
I have a custom view, full of custom cells.
when I get a double-click in my view I do the following:
- (void)mouseDown:(NSEvent *)theEvent
if ([theEvent clickCount] > 1) {
id editor = [[self window] fieldEditor: YES forObject: cell];
[editor setFont: [cell font]];
[editor setString: [cell title]];
[editor setFrame: [cell textRect]];
[editor setDelegate: self];
[editor setMaxSize: NSMakeSize(128, 10000)];
[editor setHorizontallyResizable: YES];
[editor setBackgroundColor: [NSColor redColor]];
[editor setDrawsBackground: YES];
[editor setFieldEditor: YES];
[self addSubview: editor];
[[self window] makeFirstResponder: editor];
}
My cell's textRect method returns the exact bounding box of the text to
be edited, computed via NSStringAdditions sizeWithAttributes:
Given this setup, I would expect that the editor would be in the exact
right place, and then resize accordingly up to the max width, then wrap
to a second line, etc. This was my intent by setting
setHorizontallyResizable to YES.
The problem I'm seeing is that the text editor ALWAYS wraps the last
character of my title to a second line, even if I use the editor to
delete the last few characters, it insists on keeping things on two
lines...
"Mac OS X" looks like this, as you hit backspace from the end.
Mac OS
X
Mac O
S
Mac
Ma
c
Attempts to use sizeToFit have made things worse!
Anyone see what I'm doing wrong?
Also, whose responsibility is it to paint the border that one sees
around most edited text? ala TableView and OutlineView... the method
I'm using above has no border at all...