• 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: Keyboard Loop in Programmatically Created Window
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Keyboard Loop in Programmatically Created Window


  • Subject: Re: Keyboard Loop in Programmatically Created Window
  • From: Jerry Krinock <email@hidden>
  • Date: Tue, 3 Apr 2007 08:17:34 -0700

After re-reading Justin Bur's recent post on this topic [1], I resigned myself to the fact that there's probably some "implementation compromise" [2] which prevents the keyboard loop from working in a programatically-created window. So, I bit the bullet and subclassed NSWindow to re-implement the keyboard loop in - sendEvent: [3], and it looks like the problem is solved.

An interesting fact is that, in my re-implementation, if I ask for - nextValidKeyView or -previousValidKeyView instead of -nextKeyView and -previousKeyView, it breaks again. Nevertheless, at any time I can ask any of my buttons if they -acceptFirstResponder, and they smile and say YES.

So, my conclusion is that Cocoa somehow gets a bad first impression, or maybe no impression, of my programmatically-created subviews if they are not loaded from a nib. After a bad impression, Cocoa forever thinks that they are not valid firstResponders. Can anyone explain this more rigorously ???

Jerry Krinock


[1] http://www.cocoabuilder.com/archive/message/cocoa/2007/1/31/177975

[2] Non-Apple people may read this as "bug".

[3] Subclass of NSWindow to fix the problem...

@interface SSAlertWindow : NSWindow
@end

@implementation SSAlertWindow

- (void)sendEvent:(NSEvent *)event {
    int tab = 0 ;
    if ([event type] == NSKeyDown) {
        unichar character = [[event characters] characterAtIndex:0] ;
        if (character == 9) {
            tab = 1 ;
        }
        else if (character == 25) {
            tab = -1 ;
        }
    }

    if (!tab) {
        [super sendEvent:event] ;
    }
    else {
        NSView* firstResponder = (NSView*)[self firstResponder] ;
        NSView* nextResponder = (tab > 0)
            ? [firstResponder nextKeyView]
            : [firstResponder previousKeyView] ;
        [self makeFirstResponder:nextResponder] ;
    }
}

@end

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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


  • Follow-Ups:
    • Re: Keyboard Loop in Programmatically Created Window
      • From: "Sean McBride" <email@hidden>
  • Prev by Date: Re: Sharing a single menu among multiple nibs?
  • Next by Date: Re: NSOutlineView space next to disclosure triangle
  • Previous by thread: Re: Sharing a single menu among multiple nibs?
  • Next by thread: Re: Keyboard Loop in Programmatically Created Window
  • Index(es):
    • Date
    • Thread