Re: Window close notification
Re: Window close notification
- Subject: Re: Window close notification
- From: Tomas Zahradnicky <email@hidden>
- Date: Mon, 19 May 2003 09:52:40 +0200
Hello,
I have a carbon window in my cocoa app (using mCarbonWindow =
[[NSWindow alloc] initWithWindowRef:mWindowRef];) and I don't know how
to get the windowWillClose notification. I have try to set the delegate
of this window and to instal a carbon event handler, but when I click
the close button of the window, no event occurs (and windowWillClose is
not called). What am I doing wrong ?
Thanks in advance!
Jean Bovet
Hello Jean,
since the window is Carbon Cocoa events are not generated for it so
you have to install Carbon Event Handler so you can intercept window
closing in a Carbon way. The event you're looking for is
kEventWindowClose. For more information look at CarbonEvents.h. The
code should look like:
OSStatus CarbonWindowHandler(EventHandlerCallRef inHandlerCallRef,
EventRef inEvent, void *inYourData)
{
NSWindow* window = (NSWindow*)inYourData;
// do something here
// propagate event to standard handler
return eventNotHandledErr;
}
DEFINE_ONE_SHOT_HANDLER_GETTER( CarbonWindowHandler );
OSStatus InstallHandler( WindowRef inWindow, NSWindow* inNSWindow )
{
EventTypeSpec events[] = { {kEventClassWindow, kEventWindowClose} };
OSStatus err = noErr;
WindowAttributes windowAttr = 0;
// get window attributes
err = GetWindowAttributes( inWindow, &windowAttr );
// look if there's standard handler installed, if not, install it
if( (err == noErr) && ((windowAttr & kWindowStandardHandlerAttribute) == 0) )
err = InstallStandardEventHandler( GetWindowEventTarget(inWindow) );
// install our handler to intercept closing
err = InstallWindowEventHandler( inWindow,
GetCarbonWindowHandlerUPP(), GetEventTypeCount(events), events,
inNSWindow, NULL);
return err;
}
-Tomas
--
# Ing. Tomas Zahradnicky, Jr.
# The Czech Technical University
# Dept of Computer Science, FEE-CTU Prague
_______________________________________________
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.