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: Sailor Quasar <email@hidden>
- Date: Fri, 11 Jul 2003 03:07:06 -0400
On Friday, July 11, 2003, at 12:06 AM, Daryn wrote:
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).
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:.
This might work, but it neither addresses the control's action (which I
do with the subclass of NSTextField anyway), nor the fact that those
selectors are in no way guarnateed to be bound to those keys in the
current or any future version of the OS; my understanding is that the
key bindings are read from a dictionary file of such on disk that the
user can modify at will and that the programmer has no control over.
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.
That requires that I know how to create an NSTextView subclass
correctly. I already tried this approach, only to have the field never
appear in the running program at all. I'm also not satisfied with it
since it requires working with the window, even though it's the
window's delegate. The ideal here is to have the text field be a
self-contained subclass that only reacts when it gets events relevant
to itself.
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.
Again, I've tried overriding keyDown in subclasses, see my last
response. I can only guess that I must be missing something. There's no
way to substitute a field editor without an NSWindow delegate, since a
subclass of NSTextFieldCell yields the same nothing-appears results.
-- Sailor Quasar, guardian of Leraz's memory
"A face of stone may hide a soul with the deepest Love of all"
Email: email@hidden
_______________________________________________
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.