X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/bd3e8827dd468030e34df0bde66fc6c38c4fa9b4..6612393c0080efbe5b12457434b794dc1a2cc1d8:/src/cocoa/app.mm diff --git a/src/cocoa/app.mm b/src/cocoa/app.mm index d5c70c6f32..c4fe8f3181 100644 --- a/src/cocoa/app.mm +++ b/src/cocoa/app.mm @@ -9,14 +9,6 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -// ============================================================================ -// declarations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - #include "wx/wxprec.h" #ifndef WX_PRECOMP #include "wx/defs.h" @@ -32,6 +24,7 @@ #include "wx/cocoa/ObjcPose.h" #include "wx/cocoa/autorelease.h" +#include "wx/cocoa/mbarman.h" #if wxUSE_WX_RESOURCES # include "wx/resource.h" @@ -41,13 +34,17 @@ #import #import #import +#import +#import -// ---------------------------------------------------------------------------- -// globals -// ---------------------------------------------------------------------------- - +// ======================================================================== +// wxPoseAsInitializer +// ======================================================================== wxPoseAsInitializer *wxPoseAsInitializer::sm_first = NULL; +// ======================================================================== +// wxPoserNSApplication +// ======================================================================== @interface wxPoserNSApplication : NSApplication { } @@ -57,24 +54,37 @@ wxPoseAsInitializer *wxPoseAsInitializer::sm_first = NULL; - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication; @end // wxPoserNSApplication +WX_IMPLEMENT_POSER(wxPoserNSApplication); + @implementation wxPoserNSApplication : NSApplication - (void)doIdle: (id)data { wxASSERT(wxTheApp); + wxASSERT(wxMenuBarManager::GetInstance()); + wxMenuBarManager::GetInstance()->CocoaInternalIdle(); 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 @@ -96,43 +106,28 @@ wxPoseAsInitializer *wxPoseAsInitializer::sm_first = NULL; } @end // wxPoserNSApplication -WX_IMPLEMENT_POSER(wxPoserNSApplication); - -// ============================================================================ -// functions -// ============================================================================ - -void wxApp::Exit() -{ - wxApp::CleanUp(); - - wxAppConsole::Exit(); -} -// ============================================================================ -// wxApp implementation -// ============================================================================ +// ======================================================================== +// wxApp +// ======================================================================== // ---------------------------------------------------------------------------- // wxApp Static member initialization // ---------------------------------------------------------------------------- - -#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() -#endif // ---------------------------------------------------------------------------- // wxApp initialization/cleanup // ---------------------------------------------------------------------------- - 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 @@ -157,6 +152,7 @@ bool wxApp::Initialize(int& argc, wxChar **argv) void wxApp::CleanUp() { wxDC::CocoaShutdownTextSystem(); + wxMenuBarManager::DestroyInstance(); wxAppBase::CleanUp(); } @@ -164,16 +160,17 @@ void wxApp::CleanUp() // ---------------------------------------------------------------------------- // wxApp creation // ---------------------------------------------------------------------------- - 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; @@ -182,6 +179,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; @@ -200,6 +203,9 @@ bool wxApp::OnInitGui() // Create the app using the sharedApplication method m_cocoaApp = [NSApplication sharedApplication]; + + wxMenuBarManager::CreateInstance(); + wxDC::CocoaInitializeTextSystem(); // [ m_cocoaApp setDelegate:m_cocoaApp ]; #if 0 @@ -224,12 +230,11 @@ bool wxApp::OnInit() return TRUE; } -bool wxApp::Initialized() +void wxApp::Exit() { - if (GetTopWindow()) - return TRUE; - else - return FALSE; + wxApp::CleanUp(); + + wxAppConsole::Exit(); } int wxApp::MainLoop() @@ -260,12 +265,12 @@ bool wxApp::Pending() } // Dispatch a message. -void wxApp::Dispatch() +bool wxApp::Dispatch() { + return true; } // Yield to other processes - bool wxApp::Yield(bool onlyIfNeeded) { // MT-FIXME @@ -289,8 +294,15 @@ bool wxApp::Yield(bool onlyIfNeeded) s_inYield = true; - wxLogDebug("WARNING: SUPPOSED to have yielded!"); - // FIXME: Do something! + // Run the event loop until it is out of events + while(NSEvent *event = [GetNSApplication() + nextEventMatchingMask:NSAnyEventMask + untilDate:[NSDate distantPast] + inMode:NSDefaultRunLoopMode + dequeue: YES]) + { + [GetNSApplication() sendEvent: event]; + } #if wxUSE_LOG // let the logs be flashed again @@ -302,3 +314,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__ +