// global data
//-----------------------------------------------------------------------------
-bool g_mainThreadLocked = false;
-
-static GtkWidget *gs_RootWindow = (GtkWidget*) NULL;
+static GtkWidget *gs_RootWindow = NULL;
+static wxArrayPtrVoid g_arrGdkEvents;
//-----------------------------------------------------------------------------
// wxYield
//-----------------------------------------------------------------------------
-// not static because used by textctrl.cpp
-//
-// MT-FIXME
-bool wxIsInsideYield = false;
-
-bool wxApp::Yield(bool onlyIfNeeded)
+bool wxApp::DoYield(bool onlyIfNeeded, long eventsToProcess)
{
- if ( wxIsInsideYield )
+ if ( m_isInsideYield )
{
if ( !onlyIfNeeded )
{
}
#endif // wxUSE_THREADS
- wxIsInsideYield = true;
+ m_isInsideYield = true;
+ m_eventsToProcessInsideYield = eventsToProcess;
#if wxUSE_LOG
// disable log flushing from here because a call to wxYield() shouldn't
wxLog::Suspend();
#endif
- while (EventsPending())
- gtk_main_iteration();
+ // NOTE: gtk_main_iteration() doesn't allow us to filter events, so we
+ // rather use gtk_main_do_event() after filtering the events at
+ // GDK level
+
+ GdkDisplay* disp = gtk_widget_get_display(gs_RootWindow);
+
+ // gdk_display_get_event() will transform X11 events into GDK events
+ // and will queue all of them in the display (private) structure;
+ // finally it will "unqueue" the last one and return it to us
+ GdkEvent* event = gdk_display_get_event(disp);
+ while (event)
+ {
+ // categorize the GDK event according to wxEventCategory.
+ // See http://library.gnome.org/devel/gdk/unstable/gdk-Events.html#GdkEventType
+ // for more info.
+
+ wxEventCategory cat = 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_PROXIMITY_IN:
+ case GDK_PROXIMITY_OUT:
+
+ case GDK_MOTION_NOTIFY:
+ case GDK_ENTER_NOTIFY:
+ case GDK_LEAVE_NOTIFY:
+ case GDK_VISIBILITY_NOTIFY:
+ case GDK_PROPERTY_NOTIFY:
+
+ case GDK_FOCUS_CHANGE:
+ case GDK_CONFIGURE:
+ case GDK_WINDOW_STATE:
+ case GDK_SETTING:
+ case GDK_DELETE:
+ case GDK_DESTROY:
+
+ case GDK_EXPOSE:
+ case GDK_NO_EXPOSE:
+ case GDK_MAP:
+ case GDK_UNMAP:
+ //case GDK_DAMAGE:
+
+ case GDK_DRAG_ENTER:
+ case GDK_DRAG_LEAVE:
+ case GDK_DRAG_MOTION:
+ case GDK_DRAG_STATUS:
+ case GDK_DROP_START:
+ case GDK_DROP_FINISHED:
+ case GDK_GRAB_BROKEN:
+ cat = wxEVT_CATEGORY_UI;
+ break;
+
+ default:
+ cat = wxEVT_CATEGORY_UNKNOWN;
+ break;
+ }
+
+ if (eventsToProcess & cat)
+ gtk_main_do_event(event); // process it now
+ else
+ g_arrGdkEvents.Add(event); // process it later
- // 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();
+ // get next event
+ event = gdk_display_get_event(disp);
+ }
+
+ 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
+ for (size_t i=0; i<g_arrGdkEvents.GetCount(); i++)
+ {
+ GdkEvent* ev = (GdkEvent*)g_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);
+ }
+
+ g_arrGdkEvents.Clear();
#if wxUSE_LOG
// let the logs be flashed again
wxLog::Resume();
#endif
- wxIsInsideYield = false;
+ m_isInsideYield = false;
return true;
}
g_source_remove(m_idleSourceId);
m_idleSourceId = 0;
}
+
+ // Pending events can be added asynchronously,
+ // need to keep idle source if any have appeared
+ needMore = needMore || HasPendingEvents();
+
// if more idle processing requested
if (needMore)
{
return false;
}
-#if wxUSE_THREADS
-
-static GPollFunc wxgs_poll_func;
-
-extern "C" {
-static gint wxapp_poll_func( GPollFD *ufds, guint nfds, gint timeout )
-{
- g_mainThreadLocked = true;
-
- gint res = (*wxgs_poll_func)(ufds, nfds, timeout);
-
- g_mainThreadLocked = false;
-
- return res;
-}
-}
-
-#endif // wxUSE_THREADS
-
//-----------------------------------------------------------------------------
// Access to the root window global
//-----------------------------------------------------------------------------
{
}
+bool wxApp::SetNativeTheme(const wxString& theme)
+{
+ wxString path;
+ path = gtk_rc_get_theme_dir();
+ path += "/";
+ path += theme.utf8_str();
+ path += "/gtk-2.0/gtkrc";
+
+ if ( wxFileExists(path.utf8_str()) )
+ gtk_rc_add_default_file(path.utf8_str());
+ else if ( wxFileExists(theme.utf8_str()) )
+ gtk_rc_add_default_file(theme.utf8_str());
+ else
+ {
+ wxLogWarning("Theme \"%s\" not available.", theme);
+
+ return false;
+ }
+
+ gtk_rc_reparse_all_for_settings(gtk_settings_get_default(), TRUE);
+
+ return true;
+}
+
bool wxApp::OnInitGui()
{
if ( !wxAppBase::OnInitGui() )
g_thread_init(NULL);
gdk_threads_init();
}
-
- wxgs_poll_func = g_main_context_get_poll_func(NULL);
- g_main_context_set_poll_func(NULL, wxapp_poll_func);
#endif // wxUSE_THREADS
- // We should have the wxUSE_WCHAR_T test on the _outside_
-#if wxUSE_WCHAR_T
// gtk+ 2.0 supports Unicode through UTF-8 strings
wxConvCurrent = &wxConvUTF8;
-#else // !wxUSE_WCHAR_T
- if (!wxOKlibc())
- wxConvCurrent = (wxMBConv*) NULL;
-#endif // wxUSE_WCHAR_T/!wxUSE_WCHAR_T
// decide which conversion to use for the file names
}
argc_ = argcGTK;
+ argv_[argc_] = NULL;
}
//else: gtk_init() didn't modify our parameters