NSWindow keyWindow problem
NSWindow keyWindow problem
- Subject: NSWindow keyWindow problem
- From: Thierry Passeron <email@hidden>
- Date: Thu, 12 Jan 2006 22:15:08 +0100
Happy new year to all the people from the list !
I'm having problems trying to make a keyWindow from a borderless
subclassed NSWindow programmatically (without IB).
Can anyone tell me what's wrong ?
Here is an example of code I wrote to test the problem:
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
@interface MyWindow: NSWindow
{
}
- (BOOL) canBecomeKeyWindow; /* We need this to be able to get
keyboard events ... */
@end
@implementation MyWindow
- (BOOL) canBecomeKeyWindow
{
NSLog(@"MyView::-canBecomeKeyWindow");
return YES;
}
@end
@interface MyView: NSView
{
}
- (BOOL)acceptsFirstResponder;
- (BOOL)becomeFirstResponder;
@end
@implementation MyView
- (id) initWithFrame:(NSRect) rect
{
NSLog(@"MyView::-initWithFrame:");
return [super initWithFrame:rect];
}
- (BOOL)acceptsFirstResponder
{
NSLog(@"MyView::-acceptsFirstResponder");
return YES;
}
- (BOOL)becomeFirstResponder
{
NSLog(@"MyView::-becomeFirstResponder");
return YES;
}
@end
@interface MyController: NSResponder
{
}
- (id) init;
- (void) keyDown:(NSEvent *)event;
@end
@implementation MyController
- (id) init
{
NSLog(@"MyController::-init");
return [super init];
}
- (void) keyDown:(NSEvent *)event
{
NSLog(@"MyController::-keyDown: %@", [event characters]);
}
@end
int main(int argc, char **argv)
{
NSAutoreleasePool * pool = [[ NSAutoreleasePool alloc ] init ];
[[ NSApplication sharedApplication ] autorelease ];
/*******************/
/* Window creation */
/*******************/
// First let's define the shape of the window (origin and size):
NSRect windowShape;
windowShape.origin=NSMakePoint(0,0);
windowShape.size=NSMakeSize(200,200);
// Let's instanciate the window now:
MyWindow * w = [[MyWindow alloc ] initWithContentRect: windowShape
styleMask: NSBorderlessWindowMask
backing: NSBackingStoreBuffered defer: YES];
// Let's instanciate the view
MyView * v = [[[MyView alloc] initWithFrame: windowShape] autorelease];
// Attach the view to the window
[w setContentView:v];
// Give keyborad focus to the window
[w setInitialFirstResponder:v];
// Set the responder chain to include the controller
[v setNextResponder: [[[MyController alloc]init]autorelease]];
// Display the window centered in front of all the others
[w center];
[ w makeKeyAndOrderFront: nil ];
[ NSApp run ];
[ NSApp terminate:nil ];
[ pool release ];
exit(0);
}
This code works on my PC with the GNUStep framework installed.
The window becomes keyWindow without any problem.
But on my mac , the window doesn't become keyWindow.
So how should I do it to make it work on both system (Mac/Linux) ?
Best regards,
Thierry Passeron
France.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden