Use an application delegate object
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24100 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -35,8 +35,13 @@ public:
|
|||||||
inline WX_NSApplication GetNSApplication() { return m_cocoaApp; }
|
inline WX_NSApplication GetNSApplication() { return m_cocoaApp; }
|
||||||
void CocoaInstallRequestedIdleHandler() { if(m_isIdle) CocoaInstallIdleHandler(); }
|
void CocoaInstallRequestedIdleHandler() { if(m_isIdle) CocoaInstallIdleHandler(); }
|
||||||
inline void CocoaRequestIdle() { m_isIdle = true; }
|
inline void CocoaRequestIdle() { m_isIdle = true; }
|
||||||
|
virtual void CocoaDelegate_applicationWillBecomeActive();
|
||||||
|
virtual void CocoaDelegate_applicationDidBecomeActive();
|
||||||
|
virtual void CocoaDelegate_applicationWillResignActive();
|
||||||
|
virtual void CocoaDelegate_applicationDidResignActive();
|
||||||
protected:
|
protected:
|
||||||
WX_NSApplication m_cocoaApp;
|
WX_NSApplication m_cocoaApp;
|
||||||
|
struct objc_object *m_cocoaAppDelegate;
|
||||||
WX_NSThread m_cocoaMainThread;
|
WX_NSThread m_cocoaMainThread;
|
||||||
void CocoaInstallIdleHandler();
|
void CocoaInstallIdleHandler();
|
||||||
bool m_isIdle;
|
bool m_isIdle;
|
||||||
|
@@ -51,7 +51,6 @@ wxPoseAsInitializer *wxPoseAsInitializer::sm_first = NULL;
|
|||||||
|
|
||||||
- (void)doIdle: (id)data;
|
- (void)doIdle: (id)data;
|
||||||
- (void)sendEvent: (NSEvent*)anEvent;
|
- (void)sendEvent: (NSEvent*)anEvent;
|
||||||
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication;
|
|
||||||
@end // wxPoserNSApplication
|
@end // wxPoserNSApplication
|
||||||
|
|
||||||
WX_IMPLEMENT_POSER(wxPoserNSApplication);
|
WX_IMPLEMENT_POSER(wxPoserNSApplication);
|
||||||
@@ -98,6 +97,24 @@ WX_IMPLEMENT_POSER(wxPoserNSApplication);
|
|||||||
[super sendEvent: anEvent];
|
[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
|
// NOTE: Terminate means that the event loop does NOT return and thus
|
||||||
// cleanup code doesn't properly execute. Furthermore, wxWindows has its
|
// cleanup code doesn't properly execute. Furthermore, wxWindows has its
|
||||||
// own exit on frame delete mechanism.
|
// own exit on frame delete mechanism.
|
||||||
@@ -106,7 +123,27 @@ WX_IMPLEMENT_POSER(wxPoserNSApplication);
|
|||||||
return NO;
|
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
|
// wxApp
|
||||||
@@ -152,9 +189,15 @@ bool wxApp::Initialize(int& argc, wxChar **argv)
|
|||||||
|
|
||||||
void wxApp::CleanUp()
|
void wxApp::CleanUp()
|
||||||
{
|
{
|
||||||
|
wxAutoNSAutoreleasePool pool;
|
||||||
|
|
||||||
wxDC::CocoaShutdownTextSystem();
|
wxDC::CocoaShutdownTextSystem();
|
||||||
wxMenuBarManager::DestroyInstance();
|
wxMenuBarManager::DestroyInstance();
|
||||||
|
|
||||||
|
[m_cocoaApp setDelegate:nil];
|
||||||
|
[m_cocoaAppDelegate release];
|
||||||
|
m_cocoaAppDelegate = NULL;
|
||||||
|
|
||||||
wxAppBase::CleanUp();
|
wxAppBase::CleanUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,6 +219,7 @@ wxApp::wxApp()
|
|||||||
argc = 0;
|
argc = 0;
|
||||||
argv = NULL;
|
argv = NULL;
|
||||||
m_cocoaApp = NULL;
|
m_cocoaApp = NULL;
|
||||||
|
m_cocoaAppDelegate = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxApp::CocoaInstallIdleHandler()
|
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] ];
|
[[ 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()
|
bool wxApp::OnInitGui()
|
||||||
{
|
{
|
||||||
wxAutoNSAutoreleasePool pool;
|
wxAutoNSAutoreleasePool pool;
|
||||||
@@ -204,6 +264,8 @@ bool wxApp::OnInitGui()
|
|||||||
|
|
||||||
// Create the app using the sharedApplication method
|
// Create the app using the sharedApplication method
|
||||||
m_cocoaApp = [NSApplication sharedApplication];
|
m_cocoaApp = [NSApplication sharedApplication];
|
||||||
|
m_cocoaAppDelegate = [[wxNSApplicationDelegate alloc] init];
|
||||||
|
[m_cocoaApp setDelegate:m_cocoaAppDelegate];
|
||||||
|
|
||||||
wxMenuBarManager::CreateInstance();
|
wxMenuBarManager::CreateInstance();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user