+ bool has_idle = (wxTheApp->m_idleTag != 0);
+
+ if (has_idle)
+ {
+ /* We need to temporarily remove idle callbacks or the loop will
+ never finish. */
+ gtk_idle_remove( wxTheApp->m_idleTag );
+ wxTheApp->m_idleTag = 0;
+ }
+
+ while (gtk_events_pending())
+ gtk_main_iteration();
+
+ /* 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) */
+ while (wxTheApp->ProcessIdle()) { }
+
+ if (has_idle)
+ {
+ /* re-add idle handler */
+ wxTheApp->m_idleTag = gtk_idle_add( wxapp_idle_callback, (gpointer) NULL );
+ }
+
+ return TRUE;
+}
+
+//-----------------------------------------------------------------------------
+// wxWakeUpIdle
+//-----------------------------------------------------------------------------
+
+void wxWakeUpIdle()
+{
+ if (g_isIdle)
+ wxapp_install_idle_handler();
+}
+
+//-----------------------------------------------------------------------------
+// local functions
+//-----------------------------------------------------------------------------
+
+gint wxapp_idle_callback( gpointer WXUNUSED(data) )
+{
+ if (!wxTheApp) return TRUE;
+
+#if (GTK_MINOR_VERSION > 0)
+ /* when getting called from GDK's idle handler we
+ are no longer within GDK's grab on the GUI
+ thread so we must lock it here ourselves */
+ GDK_THREADS_ENTER ();
+#endif
+
+ /* sent idle event to all who request them */
+ while (wxTheApp->ProcessIdle()) { }
+
+ /* we don't want any more idle events until the next event is
+ sent to wxGTK */
+ gtk_idle_remove( wxTheApp->m_idleTag );
+ wxTheApp->m_idleTag = 0;
+
+ /* indicate that we are now in idle mode - even so deeply
+ in idle mode that we don't get any idle events anymore.
+ this is like wxMSW where an idle event is sent only
+ once each time after the event queue has been completely
+ emptied */
+ g_isIdle = TRUE;
+
+#if (GTK_MINOR_VERSION > 0)
+ /* release lock again */
+ GDK_THREADS_LEAVE ();
+#endif
+
+ return TRUE;
+}
+
+void wxapp_install_idle_handler()
+{
+ wxASSERT_MSG( wxTheApp->m_idleTag == 0, wxT("attempt to install idle handler twice") );
+
+ /* this routine gets called by all event handlers
+ indicating that the idle is over. */
+
+ wxTheApp->m_idleTag = gtk_idle_add( wxapp_idle_callback, (gpointer) NULL );
+
+ g_isIdle = FALSE;
+}
+
+#if wxUSE_THREADS
+
+void wxapp_install_thread_wakeup()
+{
+ if (wxTheApp->m_wakeUpTimerTag) return;
+
+ wxTheApp->m_wakeUpTimerTag = gtk_timeout_add( 100, wxapp_wakeup_timerout_callback, (gpointer) NULL );
+}
+
+void wxapp_uninstall_thread_wakeup()
+{
+ if (!wxTheApp->m_wakeUpTimerTag) return;
+
+ gtk_timeout_remove( wxTheApp->m_wakeUpTimerTag );
+ wxTheApp->m_wakeUpTimerTag = 0;
+}
+
+gint wxapp_wakeup_timerout_callback( gpointer WXUNUSED(data) )
+{
+ wxapp_uninstall_thread_wakeup();
+
+#if (GTK_MINOR_VERSION > 0)
+ // when getting called from GDK's time-out handler
+ // we are no longer within GDK's grab on the GUI
+ // thread so we must lock it here ourselves
+ GDK_THREADS_ENTER ();
+#endif
+
+ // unblock other threads wishing to do some GUI things
+ wxMutexGuiLeave();
+
+ // wake up other threads
+ wxUsleep( 1 );
+
+ // block other thread again
+ wxMutexGuiEnter();
+
+#if (GTK_MINOR_VERSION > 0)
+ // release lock again
+ GDK_THREADS_LEAVE ();
+#endif
+
+ wxapp_install_thread_wakeup();
+
+ return TRUE;
+}
+
+#endif // wxUSE_THREADS