• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTextField, NSTextFieldCell, NSTextView... this is a mess, I need help
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: NSTextField, NSTextFieldCell, NSTextView... this is a mess, I need help
      • From: Sailor Quasar <email@hidden>
References: 
 >Re: NSTextField, NSTextFieldCell, NSTextView... this is a mess, I need help (From: Sailor Quasar <email@hidden>)

  • Prev by Date: Re: /Library/Preferences
  • Next by Date: MathML and Cocoa
  • Previous by thread: Re: NSTextField, NSTextFieldCell, NSTextView... this is a mess, I need help
  • Next by thread: Re: NSTextField, NSTextFieldCell, NSTextView... this is a mess, I need help
  • Index(es):
    • Date
    • Thread