X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/bc34fa2617f49d6e4c34db243ec0cdf62dd246c6..e8f60bac1ab18be00b4e433f5db7b0261c5f17da:/src/cocoa/app.mm?ds=sidebyside diff --git a/src/cocoa/app.mm b/src/cocoa/app.mm index baf11a8636..fe12b0f00e 100644 --- a/src/cocoa/app.mm +++ b/src/cocoa/app.mm @@ -31,6 +31,7 @@ #include "wx/module.h" #include "wx/cocoa/ObjcPose.h" +#include "wx/cocoa/autorelease.h" #if wxUSE_WX_RESOURCES # include "wx/resource.h" @@ -40,6 +41,7 @@ #import #import #import +#import // ---------------------------------------------------------------------------- // globals @@ -62,18 +64,27 @@ wxPoseAsInitializer *wxPoseAsInitializer::sm_first = NULL; { wxASSERT(wxTheApp); wxLogDebug("doIdle called"); - NSRunLoop *rl = [NSRunLoop currentRunLoop]; - // runMode: beforeDate returns YES if something was done - while(wxTheApp->ProcessIdle()) // FIXME: AND NO EVENTS ARE PENDING +#ifdef __WXDEBUG__ + if(wxTheApp->IsInAssert()) { - wxLogDebug("Looping for idle events"); - #if 1 - if( [rl runMode:[rl currentMode] beforeDate:[NSDate distantPast]]) + wxLogDebug("Idle events ignored durring assertion dialog"); + } + else +#endif + { + NSRunLoop *rl = [NSRunLoop currentRunLoop]; + // runMode: beforeDate returns YES if something was done + while(wxTheApp->ProcessIdle()) // FIXME: AND NO EVENTS ARE PENDING { - wxLogDebug("Found actual work to do"); - break; + wxLogDebug("Looping for idle events"); + #if 1 + if( [rl runMode:[rl currentMode] beforeDate:[NSDate distantPast]]) + { + wxLogDebug("Found actual work to do"); + break; + } + #endif } - #endif } wxLogDebug("Idle processing complete, requesting next idle event"); // Add ourself back into the run loop (on next event) if necessary @@ -97,21 +108,6 @@ wxPoseAsInitializer *wxPoseAsInitializer::sm_first = NULL; @end // wxPoserNSApplication WX_IMPLEMENT_POSER(wxPoserNSApplication); -class wxAutoNSAutoreleasePool -{ -public: - wxAutoNSAutoreleasePool() - { - m_pool = [[NSAutoreleasePool alloc] init]; - } - ~wxAutoNSAutoreleasePool() - { - [m_pool release]; - } -protected: - NSAutoreleasePool *m_pool; -}; - // ============================================================================ // functions // ============================================================================ @@ -134,6 +130,7 @@ void wxApp::Exit() #if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler) BEGIN_EVENT_TABLE(wxApp, wxEvtHandler) + EVT_IDLE(wxAppBase::OnIdle) // EVT_END_SESSION(wxApp::OnEndSession) // EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession) END_EVENT_TABLE() @@ -146,6 +143,7 @@ END_EVENT_TABLE() bool wxApp::Initialize(int& argc, wxChar **argv) { wxAutoNSAutoreleasePool pool; + m_cocoaMainThread = [NSThread currentThread]; // Mac OS X passes a process serial number command line argument when // the application is launched from the Finder. This argument must be // removed from the command line arguments before being handled by the @@ -181,12 +179,15 @@ void wxApp::CleanUp() wxApp::wxApp() { m_topWindow = NULL; - wxTheApp = this; m_isIdle = true; #if WXWIN_COMPATIBILITY_2_2 m_wantDebugOutput = TRUE; #endif +#ifdef __WXDEBUG__ + m_isInAssert = FALSE; +#endif // __WXDEBUG__ + argc = 0; argv = NULL; @@ -195,6 +196,12 @@ wxApp::wxApp() void wxApp::CocoaInstallIdleHandler() { + // If we're not the main thread, don't install the idle handler + if(m_cocoaMainThread != [NSThread currentThread]) + { + wxLogDebug("Attempt to install idle handler from secondary thread"); + return; + } // If we're supposed to be stopping, don't add more idle events if(![m_cocoaApp isRunning]) return; @@ -225,7 +232,7 @@ bool wxApp::OnInitGui() bool wxApp::CallOnInit() { - wxAutoNSAutoreleasePool pool; +// wxAutoNSAutoreleasePool pool; return OnInit(); } @@ -315,3 +322,12 @@ bool wxApp::Yield(bool onlyIfNeeded) return true; } +#ifdef __WXDEBUG__ +void wxApp::OnAssert(const wxChar *file, int line, const wxChar* cond, const wxChar *msg) +{ + m_isInAssert = TRUE; + wxAppBase::OnAssert(file, line, cond, msg); + m_isInAssert = FALSE; +} +#endif // __WXDEBUG__ +