On Mar 3, 2010, at 10:41 AM, Glenn L. Austin wrote:

> 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.

Yes, a global variable could be used to track this as well, but was hoping to 
avoid that as it would be difficult to catch every possible location in the 
code which might close the window.

> 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.


Ok. I am still hoping this isn't true, but have now filed a bug report - 
rdar://7711380

Oh, the reason why I cannot use kEventClassWindow / kEventWindowClickCloseRgn 
is because according to the documentation,

Note that this event is
not sent for composited windows; the window close button view
handles the mouse-down event directly. To intercept a close
region click in a composited window, install a kEventControlClick
handler on the window’s close button view

So, now the question becomes how / if I can get a view from a NSButton onto 
which I could install this carbon event.

I suppose what might work is simply installing a generic click event on the 
window and then determining whether or not it was in the close button...






_______________________________________________

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