X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0187ddb4a81e1eea473b960f9d740b4f531f1ada..243f5c2d917b77474b6d159fc338ec669d70cc91:/src/cocoa/app.mm diff --git a/src/cocoa/app.mm b/src/cocoa/app.mm index 2ee2c6bab8..d1676de387 100644 --- a/src/cocoa/app.mm +++ b/src/cocoa/app.mm @@ -49,7 +49,6 @@ wxPoseAsInitializer *wxPoseAsInitializer::sm_first = NULL; { } -- (void)doIdle: (id)data; - (void)sendEvent: (NSEvent*)anEvent; @end // wxPoserNSApplication @@ -57,11 +56,37 @@ WX_IMPLEMENT_POSER(wxPoserNSApplication); @implementation wxPoserNSApplication : NSApplication +- (void)sendEvent: (NSEvent*)anEvent +{ + wxLogDebug("SendEvent"); + wxTheApp->CocoaInstallRequestedIdleHandler(); + [super sendEvent: anEvent]; +} + +@end // wxPoserNSApplication + +// ======================================================================== +// wxNSApplicationDelegate +// ======================================================================== +@interface wxNSApplicationDelegate : NSObject +{ +} + +- (void)doIdle: (id)data; +// Delegate methods +- (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 + - (void)doIdle: (id)data { wxASSERT(wxTheApp); wxASSERT(wxMenuBarManager::GetInstance()); - wxMenuBarManager::GetInstance()->CocoaInternalIdle(); wxLogDebug("doIdle called"); #ifdef __WXDEBUG__ if(wxTheApp->IsInAssert()) @@ -90,31 +115,6 @@ WX_IMPLEMENT_POSER(wxPoserNSApplication); wxTheApp->CocoaRequestIdle(); } -- (void)sendEvent: (NSEvent*)anEvent -{ - wxLogDebug("SendEvent"); - wxTheApp->CocoaInstallRequestedIdleHandler(); - [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. @@ -173,10 +173,11 @@ bool wxApp::Initialize(int& argc, wxChar **argv) if ( argc > 1 ) { static const wxChar *ARG_PSN = _T("-psn_"); - if ( wxStrncmp(argv[1], ARG_PSN, sizeof(ARG_PSN) - 1) == 0 ) + if ( wxStrncmp(argv[1], ARG_PSN, strlen(ARG_PSN)) == 0 ) { // remove this argument - memmove(argv, argv + 1, argc--); + --argc; + memmove(argv + 1, argv + 2, argc * sizeof(char *)); } } @@ -237,7 +238,17 @@ void wxApp::CocoaInstallIdleHandler() m_isIdle = false; // Call doIdle for EVERYTHING dammit // We'd need Foundation/NSConnection.h for this next constant, do we need it? - [[ 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_cocoaAppDelegate argument:NULL order:0 modes:[NSArray arrayWithObjects:NSDefaultRunLoopMode, /* NSConnectionReplyRunLoopMode,*/ NSModalPanelRunLoopMode, /**/NSEventTrackingRunLoopMode,/**/ nil] ]; + /* Notes: + In the Mac OS X implementation of Cocoa, the above method schedules + doIdle: to be called from *within* [NSApplication + -nextEventMatchingMask:untilDate:inMode:dequeue:]. That is, no + NSEvent object is generated and control does not return from that + method. In fact, control will only return from that method for the + usual reasons (e.g. a real event is received or the untilDate is reached). + This has implications when trying to stop the event loop and return to + its caller. See wxEventLoop::Exit + */ } void wxApp::CocoaDelegate_applicationWillBecomeActive() @@ -273,7 +284,7 @@ bool wxApp::OnInitGui() // [ m_cocoaApp setDelegate:m_cocoaApp ]; #if 0 wxLogDebug("Just for kicks"); - [ m_cocoaApp performSelector:@selector(doIdle:) withObject:NULL ]; + [ m_cocoaAppDelegate performSelector:@selector(doIdle:) withObject:NULL ]; wxLogDebug("okay.. done now"); #endif return TRUE;