]> git.saurik.com Git - wxWidgets.git/blobdiff - src/cocoa/app.mm
Applied [ 792543 ] sample of animate contrib corrected
[wxWidgets.git] / src / cocoa / app.mm
index fc253712dbf0e9c4f0573b91ea2037ac18c87a55..ec398d67248cfbd68b04041db30edec2a51b1790 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "wx/cocoa/ObjcPose.h"
 #include "wx/cocoa/autorelease.h"
+#include "wx/cocoa/mbarman.h"
 
 #if wxUSE_WX_RESOURCES
 #  include "wx/resource.h"
@@ -42,6 +43,7 @@
 #import <Foundation/NSArray.h>
 #import <Foundation/NSAutoreleasePool.h>
 #import <Foundation/NSThread.h>
+#import <AppKit/NSEvent.h>
 
 // ----------------------------------------------------------------------------
 // globals
@@ -63,19 +65,30 @@ wxPoseAsInitializer *wxPoseAsInitializer::sm_first = NULL;
 - (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
@@ -159,6 +172,7 @@ bool wxApp::Initialize(int& argc, wxChar **argv)
 void wxApp::CleanUp()
 {
     wxDC::CocoaShutdownTextSystem();
+    wxMenuBarManager::DestroyInstance();
 
     wxAppBase::CleanUp();
 }
@@ -175,6 +189,9 @@ wxApp::wxApp()
 #if WXWIN_COMPATIBILITY_2_2
     m_wantDebugOutput = TRUE;
 #endif
+#ifdef __WXDEBUG__
+    m_isInAssert = FALSE;
+#endif // __WXDEBUG__
 
     argc = 0;
     argv = NULL;
@@ -207,6 +224,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
@@ -296,8 +316,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
@@ -309,3 +336,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__
+