FROM : Jerry Krinock
DATE : Tue Apr 03 17:17:34 2007
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
DATE : Tue Apr 03 17:17:34 2007
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
| Related mails | Author | Date |
|---|---|---|
| Jerry Krinock | Apr 1, 07:14 | |
| Jerry Krinock | Apr 3, 17:17 | |
| Sean McBride | Apr 3, 20:49 | |
| Jerry Krinock | Apr 4, 01:13 | |
| Jerry Krinock | Apr 6, 18:10 |






Cocoa mail archive

