From 15160da216c5e4048a905acfdd5574b3c1323073 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Mon, 22 Jul 2013 18:33:01 +0000 Subject: [PATCH] further routing into wxApp git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74580 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/osx/app.h | 6 +++++- src/osx/carbon/app.cpp | 15 +++++++++++++++ src/osx/cocoa/utils.mm | 8 ++------ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/include/wx/osx/app.h b/include/wx/osx/app.h index 0efd8c05a7..c940c0bb18 100644 --- a/include/wx/osx/app.h +++ b/include/wx/osx/app.h @@ -146,7 +146,11 @@ public: virtual void OSXOnWillFinishLaunching(); // immediately when the native event loop starts, no events have been served yet virtual void OSXOnDidFinishLaunching(); - + // OS asks to terminate app, return no to stay running + virtual bool OSXOnShouldTerminate(); + // before application terminates + virtual void OSXOnWillTerminate(); + // Hide the application windows the same as the system hide command would do it. void MacHideApp(); diff --git a/src/osx/carbon/app.cpp b/src/osx/carbon/app.cpp index f24210f1ca..aee21c66f6 100644 --- a/src/osx/carbon/app.cpp +++ b/src/osx/carbon/app.cpp @@ -407,6 +407,21 @@ void wxApp::OSXOnWillFinishLaunching() void wxApp::OSXOnDidFinishLaunching() { + +} + +void wxApp::OSXOnWillTerminate() +{ + wxCloseEvent event; + event.SetCanVeto(false); + wxTheApp->OnEndSession(event); +} + +bool wxApp::OSXOnShouldTerminate() +{ + wxCloseEvent event; + wxTheApp->OnQueryEndSession(event); + return !event.GetVeto(); } //---------------------------------------------------------------------- diff --git a/src/osx/cocoa/utils.mm b/src/osx/cocoa/utils.mm index 94716dd31e..77289eb913 100644 --- a/src/osx/cocoa/utils.mm +++ b/src/osx/cocoa/utils.mm @@ -126,9 +126,7 @@ void wxBell() - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender { wxUnusedVar(sender); - wxCloseEvent event; - wxTheApp->OnQueryEndSession(event); - if ( event.GetVeto() ) + if ( !wxTheApp->OSXOnShouldTerminate() ) return NSTerminateCancel; return NSTerminateNow; @@ -136,9 +134,7 @@ void wxBell() - (void)applicationWillTerminate:(NSNotification *)application { wxUnusedVar(application); - wxCloseEvent event; - event.SetCanVeto(false); - wxTheApp->OnEndSession(event); + wxTheApp->OSXOnWillTerminate(); } - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender -- 2.45.2