From 0187ddb4a81e1eea473b960f9d740b4f531f1ada Mon Sep 17 00:00:00 2001 From: David Elliott Date: Mon, 6 Oct 2003 15:36:11 +0000 Subject: [PATCH] Use an application delegate object git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24100 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/cocoa/app.h | 5 ++++ src/cocoa/app.mm | 66 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/include/wx/cocoa/app.h b/include/wx/cocoa/app.h index 7caed7e180..e8a604544a 100644 --- a/include/wx/cocoa/app.h +++ b/include/wx/cocoa/app.h @@ -35,8 +35,13 @@ public: inline WX_NSApplication GetNSApplication() { return m_cocoaApp; } void CocoaInstallRequestedIdleHandler() { if(m_isIdle) CocoaInstallIdleHandler(); } inline void CocoaRequestIdle() { m_isIdle = true; } + virtual void CocoaDelegate_applicationWillBecomeActive(); + virtual void CocoaDelegate_applicationDidBecomeActive(); + virtual void CocoaDelegate_applicationWillResignActive(); + virtual void CocoaDelegate_applicationDidResignActive(); protected: WX_NSApplication m_cocoaApp; + struct objc_object *m_cocoaAppDelegate; WX_NSThread m_cocoaMainThread; void CocoaInstallIdleHandler(); bool m_isIdle; diff --git a/src/cocoa/app.mm b/src/cocoa/app.mm index 4607c1428a..2ee2c6bab8 100644 --- a/src/cocoa/app.mm +++ b/src/cocoa/app.mm @@ -51,7 +51,6 @@ wxPoseAsInitializer *wxPoseAsInitializer::sm_first = NULL; - (void)doIdle: (id)data; - (void)sendEvent: (NSEvent*)anEvent; -- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication; @end // wxPoserNSApplication WX_IMPLEMENT_POSER(wxPoserNSApplication); @@ -98,6 +97,24 @@ WX_IMPLEMENT_POSER(wxPoserNSApplication); [super sendEvent: anEvent]; } +@end // wxPoserNSApplication + +// ======================================================================== +// wxNSApplicationDelegate +// ======================================================================== +@interface wxNSApplicationDelegate : NSObject +{ +} + +- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication; +- (void)applicationWillBecomeActive:(NSNotification *)notification; +- (void)applicationDidBecomeActive:(NSNotification *)notification; +- (void)applicationWillResignActive:(NSNotification *)notification; +- (void)applicationDidResignActive:(NSNotification *)notification; +@end // interface wxNSApplicationDelegate : NSObject + +@implementation wxNSApplicationDelegate : NSObject + // NOTE: Terminate means that the event loop does NOT return and thus // cleanup code doesn't properly execute. Furthermore, wxWindows has its // own exit on frame delete mechanism. @@ -106,7 +123,27 @@ WX_IMPLEMENT_POSER(wxPoserNSApplication); return NO; } -@end // wxPoserNSApplication +- (void)applicationWillBecomeActive:(NSNotification *)notification +{ + wxTheApp->CocoaDelegate_applicationWillBecomeActive(); +} + +- (void)applicationDidBecomeActive:(NSNotification *)notification +{ + wxTheApp->CocoaDelegate_applicationDidBecomeActive(); +} + +- (void)applicationWillResignActive:(NSNotification *)notification +{ + wxTheApp->CocoaDelegate_applicationWillResignActive(); +} + +- (void)applicationDidResignActive:(NSNotification *)notification +{ + wxTheApp->CocoaDelegate_applicationDidResignActive(); +} + +@end // implementation wxNSApplicationDelegate : NSObject // ======================================================================== // wxApp @@ -152,9 +189,15 @@ bool wxApp::Initialize(int& argc, wxChar **argv) void wxApp::CleanUp() { + wxAutoNSAutoreleasePool pool; + wxDC::CocoaShutdownTextSystem(); wxMenuBarManager::DestroyInstance(); + [m_cocoaApp setDelegate:nil]; + [m_cocoaAppDelegate release]; + m_cocoaAppDelegate = NULL; + wxAppBase::CleanUp(); } @@ -176,6 +219,7 @@ wxApp::wxApp() argc = 0; argv = NULL; m_cocoaApp = NULL; + m_cocoaAppDelegate = NULL; } void wxApp::CocoaInstallIdleHandler() @@ -196,6 +240,22 @@ void wxApp::CocoaInstallIdleHandler() [[ NSRunLoop currentRunLoop ] performSelector:@selector(doIdle:) target:m_cocoaApp argument:NULL order:0 modes:[NSArray arrayWithObjects:NSDefaultRunLoopMode, /* NSConnectionReplyRunLoopMode,*/ NSModalPanelRunLoopMode, /**/NSEventTrackingRunLoopMode,/**/ nil] ]; } +void wxApp::CocoaDelegate_applicationWillBecomeActive() +{ +} + +void wxApp::CocoaDelegate_applicationDidBecomeActive() +{ +} + +void wxApp::CocoaDelegate_applicationWillResignActive() +{ +} + +void wxApp::CocoaDelegate_applicationDidResignActive() +{ +} + bool wxApp::OnInitGui() { wxAutoNSAutoreleasePool pool; @@ -204,6 +264,8 @@ bool wxApp::OnInitGui() // Create the app using the sharedApplication method m_cocoaApp = [NSApplication sharedApplication]; + m_cocoaAppDelegate = [[wxNSApplicationDelegate alloc] init]; + [m_cocoaApp setDelegate:m_cocoaAppDelegate]; wxMenuBarManager::CreateInstance(); -- 2.45.2