+extern "C" {
+static gboolean wx_event_loop_timeout(void* data)
+{
+ bool* expired = static_cast<bool*>(data);
+ *expired = true;
+
+ // return FALSE to remove this timeout
+ return FALSE;
+}
+}
+
+int wxGUIEventLoop::DispatchTimeout(unsigned long timeout)
+{
+ bool expired = false;
+ const unsigned id = g_timeout_add(timeout, wx_event_loop_timeout, &expired);
+ bool quit = gtk_main_iteration() != 0;
+
+ if ( expired )
+ return -1;
+
+ g_source_remove(id);
+
+ return !quit;
+}
+
+//-----------------------------------------------------------------------------
+// YieldFor
+//-----------------------------------------------------------------------------
+
+extern "C" {
+static void wxgtk_main_do_event(GdkEvent* event, void* data)
+{
+ // categorize the GDK event according to wxEventCategory.
+ // See http://library.gnome.org/devel/gdk/unstable/gdk-Events.html#GdkEventType
+ // for more info.
+
+ // NOTE: GDK_* constants which were not present in the GDK2.0 can be tested for
+ // only at compile-time; when running the program (compiled with a recent GDK)
+ // on a system with an older GDK lib we can be sure there won't be problems
+ // because event->type will never assume those values corresponding to
+ // new event types (since new event types are always added in GDK with non
+ // conflicting values for ABI compatibility).
+
+ // Some events (currently only a single one) may be used for more than one
+ // category, so we need 2 variables. The second one will remain "unknown"
+ // in most cases.
+ wxEventCategory cat = wxEVT_CATEGORY_UNKNOWN,
+ cat2 = wxEVT_CATEGORY_UNKNOWN;
+ switch (event->type)
+ {
+ case GDK_SELECTION_REQUEST:
+ case GDK_SELECTION_NOTIFY:
+ case GDK_SELECTION_CLEAR:
+ case GDK_OWNER_CHANGE:
+ cat = wxEVT_CATEGORY_CLIPBOARD;
+ break;
+
+ case GDK_KEY_PRESS:
+ case GDK_KEY_RELEASE:
+ case GDK_BUTTON_PRESS:
+ case GDK_2BUTTON_PRESS:
+ case GDK_3BUTTON_PRESS:
+ case GDK_BUTTON_RELEASE:
+ case GDK_SCROLL: // generated from mouse buttons
+ case GDK_CLIENT_EVENT:
+ cat = wxEVT_CATEGORY_USER_INPUT;
+ break;
+
+ case GDK_PROPERTY_NOTIFY:
+ // This one is special: it can be used for UI purposes but also for
+ // clipboard operations, so allow it in both cases (we probably could
+ // examine the event itself to distinguish between the two cases but
+ // this would be unnecessarily complicated).
+ cat2 = wxEVT_CATEGORY_CLIPBOARD;
+ // Fall through.
+
+ case GDK_PROXIMITY_IN:
+ case GDK_PROXIMITY_OUT:
+
+ case GDK_MOTION_NOTIFY:
+ case GDK_ENTER_NOTIFY:
+ case GDK_LEAVE_NOTIFY:
+ case GDK_VISIBILITY_NOTIFY:
+
+ case GDK_FOCUS_CHANGE:
+ case GDK_CONFIGURE:
+ case GDK_WINDOW_STATE:
+ case GDK_SETTING:
+ case GDK_DELETE:
+ case GDK_DESTROY:
+
+ case GDK_EXPOSE:
+#ifndef __WXGTK3__
+ case GDK_NO_EXPOSE:
+#endif
+ case GDK_MAP:
+ case GDK_UNMAP:
+
+ case GDK_DRAG_ENTER:
+ case GDK_DRAG_LEAVE:
+ case GDK_DRAG_MOTION:
+ case GDK_DRAG_STATUS:
+ case GDK_DROP_START:
+ case GDK_DROP_FINISHED:
+#if GTK_CHECK_VERSION(2,8,0)
+ case GDK_GRAB_BROKEN:
+#endif
+#if GTK_CHECK_VERSION(2,14,0)
+ case GDK_DAMAGE:
+#endif
+ cat = wxEVT_CATEGORY_UI;
+ break;
+
+ default:
+ cat = wxEVT_CATEGORY_UNKNOWN;
+ break;
+ }
+
+ wxGUIEventLoop* evtloop = static_cast<wxGUIEventLoop*>(data);
+
+ // is this event allowed now?
+ if (evtloop->IsEventAllowedInsideYield(cat) ||
+ (cat2 != wxEVT_CATEGORY_UNKNOWN &&
+ evtloop->IsEventAllowedInsideYield(cat2)))
+ {
+ // process it now
+ gtk_main_do_event(event);
+ }
+ else if (event->type != GDK_NOTHING)
+ {
+ // process it later (but make a copy; the caller will free the event
+ // pointer)
+ evtloop->StoreGdkEventForLaterProcessing(gdk_event_copy(event));
+ }
+}