Discussion:
[wxOSX-Cocoa] How to handle Quit events sent from the Dock
(too old to reply)
Деян Хаджиев
2014-10-02 18:09:41 UTC
Permalink
Hi,

I have a heavy application on OSX, that runs in several threads and it is
essential it cleans up properly. I am already handling the OnClose events
from the possible frames and I'm also handling the wxID_EXIT event. I have
been trying to capture the events (or signals) sent when a user clicks the
"Quit" from the Dock, but have been unsuccessful so far. I have even tried
to capture all wxEVT_COMMAND_MENU_SELECTED events in range wxID_LOWEST,
wxID_HIGHTEST, but still no effect. Afterwards I also tried to filter all
events but I found no unique events whatsoever. Then I tried to capture
signals, but hit a stone there as well. Do you know what kind of event (or
signal) is generated on Dock Quit (or at least some way to intercept the
kill)? TIA

Best Regards,
Deyan Hadzhiev
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Stefan Csomor
2014-10-02 19:52:39 UTC
Permalink
Hi

I have a heavy application on OSX, that runs in several threads and it is essential it cleans up properly. I am already handling the OnClose events from the possible frames and I'm also handling the wxID_EXIT event.

are you sure you are really handling the Close Event ?

Internally there are two methods that get called


// OS asks to terminate app, return no to stay running

virtual bool OSXOnShouldTerminate();

// before application terminates

virtual void OSXOnWillTerminate();

and their implementation is quite simple


void wxApp::OSXOnWillTerminate()

{

wxCloseEvent event;

event.SetCanVeto(false);

wxTheApp->OnEndSession(event);

}


bool wxApp::OSXOnShouldTerminate()

{

wxCloseEvent event;

wxTheApp->OnQueryEndSession(event);

return !event.GetVeto();

}

(these are two virtual methods and - if everything else is not working - could be overridden ..)

these in turn call


void wxApp::OnEndSession(wxCloseEvent& WXUNUSED(event))

{

if (GetTopWindow())

GetTopWindow()->Close(true);

}


// Default behaviour: close the application with prompts. The

// user can veto the close, and therefore the end session.

void wxApp::OnQueryEndSession(wxCloseEvent& event)

{

if ( !wxDialog::OSXHasModalDialogsOpen() )

{

if (GetTopWindow())

{

if (!GetTopWindow()->Close(!event.CanVeto()))

event.Veto(true);

}

}

else

{

event.Veto(true);

}

}

so the top window gets the close event and I just checked with the minimal sample

if you add a close handler


BEGIN_EVENT_TABLE(MyFrame, wxFrame)

...

EVT_CLOSE(MyFrame::OnClose)

..

END_EVENT_TABLE()


then this gets called


Best,


Stefan
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Деян Хаджиев
2014-10-02 20:32:25 UTC
Permalink
Yes, I actually have forgotten to handle the wxEVT_CLOSE_WINDOW for the
TopLevelWindow. Thanks for the tips, this should solve my problems.

Best Regards
Deyan
Post by Деян Хаджиев
Hi
I have a heavy application on OSX, that runs in several threads and it
is essential it cleans up properly. I am already handling the OnClose
events from the possible frames and I'm also handling the wxID_EXIT event.
are you sure you are really handling the Close Event ?
Internally there are two methods that get called
// OS asks to terminate app, return no to stay running
virtual bool OSXOnShouldTerminate();
// before application terminates
virtual void OSXOnWillTerminate();
and their implementation is quite simple
void wxApp::OSXOnWillTerminate()
{
wxCloseEvent event;
event.SetCanVeto(false);
wxTheApp->OnEndSession(event);
}
bool wxApp::OSXOnShouldTerminate()
{
wxCloseEvent event;
wxTheApp->OnQueryEndSession(event);
return !event.GetVeto();
}
(these are two virtual methods and – if everything else is not working –
could be overridden ..)
these in turn call
void wxApp::OnEndSession(wxCloseEvent& WXUNUSED(event))
{
if (GetTopWindow())
GetTopWindow()->Close(true);
}
// Default behaviour: close the application with prompts. The
// user can veto the close, and therefore the end session.
void wxApp::OnQueryEndSession(wxCloseEvent& event)
{
if ( !wxDialog::OSXHasModalDialogsOpen() )
{
if (GetTopWindow())
{
if (!GetTopWindow()->Close(!event.CanVeto()))
event.Veto(true);
}
}
else
{
event.Veto(true);
}
}
so the top window gets the close event and I just checked with the minimal sample
if you add a close handler
BEGIN_EVENT_TABLE(MyFrame, wxFrame)


EVT_CLOSE(MyFrame::OnClose)
..
END_EVENT_TABLE()
then this gets called
Best,
Stefan
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Loading...