]> git.saurik.com Git - wxWidgets.git/commitdiff
Use an application delegate object
authorDavid Elliott <dfe@tgwbd.org>
Mon, 6 Oct 2003 15:36:11 +0000 (15:36 +0000)
committerDavid Elliott <dfe@tgwbd.org>
Mon, 6 Oct 2003 15:36:11 +0000 (15:36 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24100 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/cocoa/app.h
src/cocoa/app.mm

index 7caed7e180a9dd1bb30412c0bd8d044347f69848..e8a604544afecd80180ea6bc002f4ea5391c1083 100644 (file)
@@ -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;
index 4607c1428aa49e6af66675f3842525972ad46f06..2ee2c6bab8f69abeca77e7b9fa5738fdbb90e60b 100644 (file)
@@ -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();