non-retained Windows, NSWindowExposedEventType - with source code
non-retained Windows, NSWindowExposedEventType - with source code
- Subject: non-retained Windows, NSWindowExposedEventType - with source code
- From: "Thomas Martin" <email@hidden>
- Date: Sat, 21 Sep 2002 17:38:31 -0600
I would like to be able to intercept and process the
NSAppKitDefined NSEvents of the subtype NSWindowExposedEventType,
when the non-retained NSWindow of my application becomes exposed.
The following code illustrates the situation - InterfaceBuilder is not used:
//--------------------------------------------------------------------------
---------------
int main(int argc, const char *argv[])
{
NSAutoreleasePool * Pool = [[NSAutoreleasePool alloc] init];
[[MyApplication sharedApplication] setDelegate: NSApp]; // create an
instance of MyApplication,
which is derived from NSApplication
[NSApp run]; // will return, because "applicationDidFinishLaunching" will
stop NSApp
[NSApp loop]; // call proprietary event loop procedure
return 0;
}
//--------------------------------------------------------------------------
---------------
@implementation MyApplication // my subclass of NSApplication
- (void)applicationDidFinishLaunching:(NSNotification *)Notification
{
// create a non-retained window e.g. with a button as the window's
contentview
NSRect ContentsFrame = {{20, 20}, {200, 30}};
NSButton * MyButton = [[NSButton alloc] initWithFrame : ContentsFrame];
NSWindow * MyWindow = [NSWindow alloc];
if(MyWindow){
NSString * AquaTitle = [NSString stringWithCString : "Expose Event
Test"];
NSRect ContentsFrame = {{200, 300}, {500, 400}};
[MyWindow initWithContentRect : ContentsFrame
styleMask : NSTitledWindowMask
backing : NSBackingStoreNonretained
defer : NO];
[MyWindow setTitle : AquaTitle];
[AquaTitle release];
[MyButton setTitle : [NSString stringWithCString : "Button"]];
[MyWindow setContentView : MyButton];
[MyWindow setBackgroundColor : [NSColor blackColor]];
[MyWindow makeKeyAndOrderFront : self]; // put the window on the screen
and activate it
}
[[Notification object] stop : self]; // stop the main event loop
return; // return to main()
}
//--------------------------------------------------------------------------
---------------
- (void)loop
{
NSEvent * CocoaEvent = NULL;
while((CocoaEvent = [NSApp nextEventMatchingMask : NSAnyEventMask
untilDate : [NSDate
distantFuture]
inMode :
NSDefaultRunLoopMode
dequeue : YES])){
if ([CocoaEvent type] == NSAppKitDefined){
// how are data1 and data2 used by the different event subtypes e.g.
NSWindowExposedEventType?
int data1 = [CocoaEvent data1];
int data2 = [CocoaEvent data2];
if ([CocoaEvent subtype] == NSWindowExposedEventType){
fprintf(stderr, "\nNSWindowExposedEventType\n"); // this never happens
!!??
}
}
[self sendEvent : CocoaEvent];
}// loop forever
return;
}
@end
Any sugguestion is greatly appreciated!
Sincerely,
Thomas
PS: On a second note - I could not find any documentation on the
details of NSEvent's -(int)data1 and -(int)data2 functions. I
would like to find out, how the returned integer values need to
be interpreted according to the designated event types (i.e.
NSAppKitDefined, etc.)
_______________________________________________
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.