On Mar 3, 2010, at 7: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. 

Well, if you're trying to determine whether your window was closed by the user 
and when it was closed by your code, you could simply set a flag in your window 
delegate when you close the window by code.

If you're trying to determine the difference between closing the window using 
the close box and when using the menu item, choose the option that gives you 
the most "control" (e.g. set the menu item's target) and set a flag there.

In reality, it probably shouldn't really matter *why* the window is being 
closed, only that it's being closed.  If there's supposed to be a difference 
when your code closes the window, then your code is going to have to do the 
extra work to notify the receiver.

-- 
Glenn L. Austin, Computer Wizard and Race Car Driver         <><
<http://www.austin-soft.com>
_______________________________________________

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

Reply via email to