[Mono-osx] Need a replacement for NSWindow.Close()

Maxi Combina maxi.combina at passwordbank.com
Wed Mar 30 04:11:53 EDT 2011


Hi Geoff,

2011/3/29 Geoff Norton <gnorton at novell.com>

> I think you're confused what .Close () does.  Since it specifically calls
> out it does not call WillClose either:
>
>
> http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindow_Class/Reference/Reference.html
>
> Indeed I am confused. The documentation for the close: method, which I have
read in detail, reads:
"The close method posts an
NSWindowWillCloseNotification<http://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindow_Class/Reference/Reference.html#//apple_ref/c/data/NSWindowWillCloseNotification>
notification
to the default notification center."

What I understood (beware: I am pretty new to cocoa/monomac) is that the
NSWindowWillCloseNotification maps to Window.WillClose() (and I'm probaly
wrong here!).
I tried invoking PerformClose() and OrderOut(): the first delivers
WillClose(), the second does not.

Also, I read about PerformClose(). AFAIK, It differs from Close() in that
the former (a) does not send a windowShouldClose: and (b) does not simulate
the user clicking the close button (and this is why PerformClose() does not
word in Borderless windows)


>
> <http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindow_Class/Reference/Reference.html>Anyways,
> the issue with .Close is it does a .Release under the hood, that we aren't
> aware of, leading to a double free.
>
> But PerformClose() is exposed in MonoMac. Is the issue from Close()
present? I am using PerformClose() and maybe was lucky enough, but will the
double free hit me any time?


Considering, my specific doubts are the following. I would really appreciate
any clarification:
1) Is NSWindowWillCloseNotification mapped to Window.WillClose()?
2) Close() has the doube-free issue, ok. But, what about PerformClose()? Can
I use it safely?
3) You mention that "the functionality is easily accomplished in better
ways". Which ways? Using OrderOut()? In that case, do I have to call
Release()? And what about the WillClose()?
4) What are the differences between OrderOut() and Close()?  Only the
invocation to Release()?


Thanks in advance,
Maxi

On 2011-03-29, at 10:58 AM, Maxi Combina wrote:
>
> .OrderOut() and .Close() don't seem to be equivallent:
> If I use Window.OrderOut() then the Window.WillClose() is not dispatched.
> I can not invoke PerformClose() since I use Borderless windows.
>
> I found 2 ideas, please advise me on those:
> 1) To have my own events: I use .OrderOut() and launch a custom event, to
> replace WillClose().
> 2) I code:
>    OrderOut();
>    StyleMask = Titled | Closable; // enable PerformClose()
>    PerformClose(this) // Close the already hidden window
>
> Or maybe I should refactor.
>
> Is it just me that finds the missing .Close() a little odd?
>
>  Bests,
> Maxi
>
> 2011/3/29 Geoff Norton <gnorton at novell.com>
>
>> Use .OrderOut ()
>>
>> -g
>>
>> On 2011-03-29, at 5:54 AM, Maxi Combina wrote:
>>
>> Hello,
>>
>> I have a Borderless window which can not be closed with PerformClose(),
>> since this method (as per Apple documentation) "simulates the user clicking
>> the close button" and "if the windows doesn't ahve a close button or can't
>> be closed [...], the system emits the alert sound".
>> For closing a window I used the "Close()" method. But in the current
>> src/appkit.cs the "Close()" is commented out:
>>
>> /* NSWindow.Close by default calls [window release]
>>                  * This will cause a double free in our code since we're
>> not aware of this
>>                  * and we end up GCing the proxy eventually and sending
>> our own release
>>                  * Removing this method for now
>>                 [Export ("close")]
>>                 void Close ();
>>                  */
>>
>> I am looking for a way of closing (and releasing) the window.
>> Any ideas?
>>
>> Thanks!
>> maxi
>>
>> --
>> *Maxi Combina*
>> Cell:+1 408 300 3614
>> Tel:  +1 408 524 1579
>> 440 N. Wolfe Road. Sunnyvale. CA. 94085. USA
>>
>> <http://www.passwordbank.com/>www.PasswordBank.com<http://www.passwordbank.com/>
>> This message and its attachments are sent from PasswordBank, Inc. and may
>> contain information that is
>> confidential. If you are not the intended recipient, you are prohibited
>> from printing, copying, forwarding or
>> saving them. Please delete the message and attachments without printing,
>> copying, forwarding or saving
>> them, and notify the sender immediately. Message transmission is not
>> guaranteed to be secure.
>>
>>  _______________________________________________
>> Mono-osx mailing list
>> Mono-osx at lists.ximian.com
>> http://lists.ximian.com/mailman/listinfo/mono-osx
>>
>>
>>
>
>
> --
> *Maxi Combina*
> Cell:+1 408 300 3614
> Tel:  +1 408 524 1579
> 440 N. Wolfe Road. Sunnyvale. CA. 94085. USA
>
> <http://www.passwordbank.com/>www.PasswordBank.com<http://www.passwordbank.com/>
> This message and its attachments are sent from PasswordBank, Inc. and may
> contain information that is
> confidential. If you are not the intended recipient, you are prohibited
> from printing, copying, forwarding or
> saving them. Please delete the message and attachments without printing,
> copying, forwarding or saving
> them, and notify the sender immediately. Message transmission is not
> guaranteed to be secure.
>
>
>


-- 
*Maxi Combina*
Cell:+1 408 300 3614
Tel:  +1 408 524 1579
440 N. Wolfe Road. Sunnyvale. CA. 94085. USA

<http://www.passwordbank.com/>www.PasswordBank.com<http://www.passwordbank.com/>
This message and its attachments are sent from PasswordBank, Inc. and may
contain information that is
confidential. If you are not the intended recipient, you are prohibited from
printing, copying, forwarding or
saving them. Please delete the message and attachments without printing,
copying, forwarding or saving
them, and notify the sender immediately. Message transmission is not
guaranteed to be secure.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-osx/attachments/20110330/68ef7b96/attachment-0001.html 


More information about the Mono-osx mailing list