+bool wxGUIEventLoop::YieldFor(long eventsToProcess)
+{
+#if wxUSE_THREADS
+ if ( !wxThread::IsMain() )
+ {
+ // can't call gtk_main_iteration() from other threads like this
+ return true;
+ }
+#endif // wxUSE_THREADS
+
+ m_isInsideYield = true;
+ m_eventsToProcessInsideYield = eventsToProcess;
+
+#if wxUSE_LOG
+ // disable log flushing from here because a call to wxYield() shouldn't
+ // normally result in message boxes popping up &c
+ wxLog::Suspend();
+#endif
+
+ // temporarily replace the global GDK event handler with our function, which
+ // categorizes the events and using m_eventsToProcessInsideYield decides
+ // if an event should be processed immediately or not
+ // NOTE: this approach is better than using gdk_display_get_event() because
+ // gtk_main_iteration() does more than just calling gdk_display_get_event()
+ // and then call gtk_main_do_event()!
+ // In particular in this way we also process input from sources like
+ // GIOChannels (this is needed for e.g. wxGUIAppTraits::WaitForChild).
+ gdk_event_handler_set ((GdkEventFunc)wxgtk_main_do_event, this, NULL);
+ while (Pending()) // avoid false positives from our idle source
+ gtk_main_iteration();
+ gdk_event_handler_set ((GdkEventFunc)gtk_main_do_event, NULL, NULL);
+
+ if (eventsToProcess != wxEVT_CATEGORY_CLIPBOARD)
+ {
+ // It's necessary to call ProcessIdle() to update the frames sizes which
+ // might have been changed (it also will update other things set from
+ // OnUpdateUI() which is a nice (and desired) side effect). But we
+ // call ProcessIdle() only once since this is not meant for longish
+ // background jobs (controlled by wxIdleEvent::RequestMore() and the
+ // return value of Processidle().
+ ProcessIdle(); // ProcessIdle() also calls ProcessPendingEvents()
+ }
+ //else: if we are inside ~wxClipboardSync() and we call ProcessIdle() and
+ // the user app contains an UI update handler which calls wxClipboard::IsSupported,
+ // then we fall into a never-ending loop...
+
+ // put all unprocessed GDK events back in the queue
+ GdkDisplay* disp = gtk_widget_get_display(wxGetRootWindow());
+ for (size_t i=0; i<m_arrGdkEvents.GetCount(); i++)
+ {
+ GdkEvent* ev = (GdkEvent*)m_arrGdkEvents[i];
+
+ // NOTE: gdk_display_put_event makes a copy of the event passed to it
+ gdk_display_put_event(disp, ev);
+ gdk_event_free(ev);
+ }
+
+ m_arrGdkEvents.Clear();
+
+#if wxUSE_LOG
+ // let the logs be flashed again
+ wxLog::Resume();
+#endif
+
+ m_isInsideYield = false;
+
+ return true;
+}