Re: NSTextField, NSTextFieldCell, NSTextView... this is a mess, I need help
Re: NSTextField, NSTextFieldCell, NSTextView... this is a mess, I need help
- Subject: Re: NSTextField, NSTextFieldCell, NSTextView... this is a mess, I need help
- From: Daryn <email@hidden>
- Date: Thu, 10 Jul 2003 23:06:45 -0500
On Thursday, July 10, 2003, at 09:05 PM, Sailor Quasar wrote:
On Thursday, July 10, 2003, at 05:22 PM, Alastair J.Houghton wrote:
The process of intercepting keystrokes that go to a single text
field without subclassing the application or window is proving far
more complex than it ought.
Just out of curiosity, why are you trying to intercept keystrokes? I
only ask because on Windows this is often the way people go about
limiting the types of data that can be entered into edit controls
(and often they miss the fact that they have to deal with cut, copy,
paste etcetera when they do this ;->). If you are trying to do that,
then I think you should be looking at the NSFormatter class instead.
I need to intercept two keystrokes (option-up and option-down), as
well as the sending of the field's action, to implement a history for
a command input area. I've successfully implemented it using a
subclass of NSWindow and of NSTextField, but I'm very unhappy with the
violation of enscapulation principles that comes with that. I'd much
rather have just the field responding to the keys, but the text input
architecture means I either have to trap sendEvent in the field's
window (not its delegate, the window itself!) or replace the field's
field editor (again, not the delegate). I've had zero success with the
latter, due mostly to poor documention on what's really going on
inside those things. NSFormatter is a good idea, but unfortunately is
never asked about keystrokes involving the arrow keys so can not
handle what I need. (I've run tests to verify this).
If you find yourself fighting the text system, then it's almost assured
that you are taking the wrong approach. Once you conquer the learning
curve to figure out how it works, it's actually quite elegant.
Here's a few approches:
For simple bindings, implement the NSTextField's delegate
control:textView:doCommandBySelector:. If I recall correctly, opt-up &
opt-down are translated into the responder selectors
moveToBeginningOfLine: and moveToEndOfLine:.
For more complicated keystrokes, use NSWindow's delegate
windowWillReturnFieldEditor:toObject: to replace the field editor for
your cell with a subclass of NSText or NSTextView. In your custom
field editor, override keyDown: to catch and process your special
keystrokes. The delegate of your custom field editor will be set to
the control, so you can then use the control's delegate to get to your
external controller object.
If you can directly use a NSTextView, then try the delegate's
textView:doCommandBySelector: to trap the responder selectors, or
implement implement keyDown: in a subclass.
Hopefully one of these approaches will work for you.
Daryn
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.