+void wxApp::WakeUpIdle()
+{
+ [m_cocoaApp postEvent:[NSEvent otherEventWithType:NSApplicationDefined
+ location:NSZeroPoint modifierFlags:NSAnyEventMask
+ timestamp:0 windowNumber:0 context:nil
+ subtype:0 data1:0 data2:0] atStart:NO];
+}
+
+extern "C" static void ObserveMainRunLoopBeforeWaiting(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info);
+extern "C" static void ObserveMainRunLoopBeforeWaiting(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info)
+{
+ static_cast<wxApp*>(info)->CF_ObserveMainRunLoopBeforeWaiting(observer, activity);
+}
+
+#if 0
+static int sg_cApplicationWillUpdate = 0;
+#endif
+
+void wxApp::CocoaDelegate_applicationWillUpdate()
+{
+ wxLogTrace(wxTRACE_COCOA,wxT("applicationWillUpdate"));
+
+// CFRunLoopRef cfRunLoop = [[NSRunLoop currentRunLoop] getCFRunLoop];
+ CFRunLoopRef cfRunLoop = CFRunLoopGetCurrent();
+ wxCFRef<CFStringRef> cfRunLoopMode(CFRunLoopCopyCurrentMode(cfRunLoop));
+
+ if(m_cfRunLoopIdleObserver != NULL && m_cfObservedRunLoopMode != cfRunLoopMode)
+ {
+ CFRunLoopObserverInvalidate(m_cfRunLoopIdleObserver);
+ m_cfRunLoopIdleObserver.reset();
+ }
+#if 0
+ ++sg_cApplicationWillUpdate;
+#endif
+ if(m_cfRunLoopIdleObserver == NULL)
+ {
+ // Enable idle event handling
+ CFRunLoopObserverContext observerContext =
+ { 0
+ , this
+ , NULL
+ , NULL
+ , NULL
+ };
+ m_cfRunLoopIdleObserver.reset(CFRunLoopObserverCreate(kCFAllocatorDefault, kCFRunLoopBeforeWaiting, /*repeats*/FALSE, /*priority*/0, ObserveMainRunLoopBeforeWaiting, &observerContext));
+ m_cfObservedRunLoopMode = cfRunLoopMode;
+ CFRunLoopAddObserver(cfRunLoop, m_cfRunLoopIdleObserver, m_cfObservedRunLoopMode);
+ }
+}
+
+static inline bool FakeNeedMoreIdle()
+{
+#if 0
+// Return true on every 10th call.
+ static int idleCount = 0;
+ return ++idleCount % 10;
+#else
+ return false;
+#endif
+}
+
+void wxApp::CF_ObserveMainRunLoopBeforeWaiting(CFRunLoopObserverRef observer, int activity)
+{
+ // Ensure that the app knows we've been invalidated
+ m_cfRunLoopIdleObserver.reset();
+#if 0
+ wxLogTrace(wxTRACE_COCOA,wxT("Idle BEGIN (%d)"), sg_cApplicationWillUpdate);
+ sg_cApplicationWillUpdate = 0;
+#else
+ wxLogTrace(wxTRACE_COCOA,wxT("Idle BEGIN"));
+#endif
+ if( ProcessIdle() || FakeNeedMoreIdle() )
+ {
+ wxLogTrace(wxTRACE_COCOA, wxT("Idle REQUEST MORE"));
+ [NSApp setWindowsNeedUpdate:YES];
+ }
+ else
+ {
+ wxLogTrace(wxTRACE_COCOA, wxT("Idle END"));
+ }
+}
+
+#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__