Sending a message to super's super (tab keyDown in NSTextView)
Sending a message to super's super (tab keyDown in NSTextView)
- Subject: Sending a message to super's super (tab keyDown in NSTextView)
- From: Jerry Krinock <email@hidden>
- Date: Thu, 21 Aug 2008 01:22:23 -0700
When the 'tab' or 'backTab' key is pressed, NSTextView accepts it as a
character to be typewritten. But sometimes I want NSTextView to
behave like an NSTextField, with 'tab' or 'backTab' selecting the next
or previous key view. So, in my NSTextView subclass, I over-ride -
keyDown: and re-implement the next/previous view selection.
It works, but, besides being redundant code, this re-implementation
seems like an evil assumption of some other class' behavior by my
subclass. What I really want to say is: "Behave like your
'grandfather' class, NSView". But there is no supersuper keyword.
Is there any way to improve this?.....
- (void)keyDown:(NSEvent*)event {
NSString *s = [event charactersIgnoringModifiers] ;
unichar keyChar = 0 ;
if ([s length] == 1) {
keyChar = [s characterAtIndex:0] ;
// Our superclass NSTextView accepts tabs and backtabs as text.
// If we want _tabToNextKeyView, we re-implement the NSView
behavior
// of selecting the next or previous key view
if ((keyChar == NSTabCharacter)&& _tabToNextKeyView) {
[[self window] selectNextKeyView:self] ;
}
else if ((keyChar == NSBackTabCharacter) &&
_tabToNextKeyView) {
[[self window] selectPreviousKeyView:self] ;
}
else {
// Handle using super's (i.e. NSTextView) -
interpretKeyEvents:,
// which will typewrite the key-downed character
NSArray* events = [NSArray arrayWithObject:event] ;
[self interpretKeyEvents:events] ;
}
}
}
_______________________________________________
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