On Mar 3, 2010, at 10:20 AM, Eric Gorr wrote: > > On Mar 2, 2010, at 6:42 PM, Jens Alfke wrote: > >> >> On Mar 2, 2010, at 3:32 PM, Eric Gorr wrote: >> >>> Is there any way to determine how a window was closed? >>> I need to base what I do on whether or not a window will be closed by the >>> user pressing the close (red) button or some other way. >> >> If you have an NSWindow subclass, you can override -performClose:, which is >> called when the user takes action to close the window. > > I tried this, but performClose: was not called after I pressed the close > (red) button. The intent of this method seems to be to simulate the click, > not respond to it. > >> Otherwise, you can make your class implement the NSWindow delegate method >> -windowShouldClose:, which will also be called when the user tries to close >> the window. > > This method is called after I press the close (red) button. My only concern > here is that the method does not necessarily lend itself to be exclusively > called at this time and it would be a problem if it was ever called if the > window was being closed for any other reason. So, how certain is it that it > will _only_ be called if the user presses the close (red) button? > > With the old toolbox, one would receive a mouse down event and be able to > determine what window and what part of the window it belonged to. One of > these parts was "inGoAway". I just need the same information with the same > reliability. > > Now, I suppose I could attach a carbon event handler to my window and ask for > kEventClassWindow / kEventWindowClickCloseRgn events, but I was hoping to > avoid this and am surprised that there isn't something as clear in Cocoa.
Looks like I spoke to soon and should have tried the carbon event handler first. This does not work - the event is not generated. _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com