From 1481968400c94128642815b6871724f118141cbc Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Sat, 26 Aug 2006 22:07:45 +0000 Subject: [PATCH] use "event" signal emission hook to install idle handler for many events git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40854 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/app.cpp | 17 +++++++++++++++++ src/gtk/dnd.cpp | 3 +-- src/gtk/fontdlg.cpp | 3 +-- src/gtk/glcanvas.cpp | 3 +-- src/gtk/listbox.cpp | 4 ++-- src/gtk/minifram.cpp | 12 +++++------- src/gtk/notebook.cpp | 3 +-- src/gtk/radiobox.cpp | 3 +-- src/gtk/scrolbar.cpp | 5 ++--- src/gtk/tbargtk.cpp | 2 +- src/gtk/toplevel.cpp | 12 ++++-------- src/gtk/window.cpp | 24 ++++++++---------------- 12 files changed, 44 insertions(+), 47 deletions(-) diff --git a/src/gtk/app.cpp b/src/gtk/app.cpp index b6e5363c01..7422385af0 100644 --- a/src/gtk/app.cpp +++ b/src/gtk/app.cpp @@ -184,6 +184,16 @@ void wxApp::WakeUpIdle() extern "C" { +// One-shot emission hook for "event" signal, to install idle handler. +// This will be called when the "event" signal is issued on any GtkWidget object. +static gboolean +event_emission_hook(GSignalInvocationHint*, guint, const GValue*, gpointer) +{ + wxapp_install_idle_handler(); + // remove hook + return false; +} + static gint wxapp_idle_callback( gpointer WXUNUSED(data) ) { if (!wxTheApp) @@ -222,6 +232,13 @@ static gint wxapp_idle_callback( gpointer WXUNUSED(data) ) // Release lock again gdk_threads_leave(); + if (!moreIdles) + { + // add emission hook for "event" signal, to re-install idle handler when needed + guint sig_id = g_signal_lookup("event", GTK_TYPE_WIDGET); + g_signal_add_emission_hook(sig_id, 0, event_emission_hook, NULL, NULL); + } + // Return FALSE if no more idle events are to be sent return moreIdles; } diff --git a/src/gtk/dnd.cpp b/src/gtk/dnd.cpp index 2d234e0f92..aadec6a638 100644 --- a/src/gtk/dnd.cpp +++ b/src/gtk/dnd.cpp @@ -706,8 +706,7 @@ extern "C" { static gint gtk_dnd_window_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *WXUNUSED(event), wxDropSource *source ) { - if (g_isIdle) - wxapp_install_idle_handler(); + // don't need to install idle handler, its done from "event" signal source->GiveFeedback( ConvertFromGTK(source->m_dragContext->action) ); diff --git a/src/gtk/fontdlg.cpp b/src/gtk/fontdlg.cpp index 61a204f1e1..8c6f452f53 100644 --- a/src/gtk/fontdlg.cpp +++ b/src/gtk/fontdlg.cpp @@ -32,8 +32,7 @@ extern "C" { static bool gtk_fontdialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxDialog *win ) { - if (g_isIdle) - wxapp_install_idle_handler(); + // don't need to install idle handler, its done from "event" signal /* printf( "OnDelete from " ); diff --git a/src/gtk/glcanvas.cpp b/src/gtk/glcanvas.cpp index 1a49e90d90..c0969bd6e0 100644 --- a/src/gtk/glcanvas.cpp +++ b/src/gtk/glcanvas.cpp @@ -235,8 +235,7 @@ extern "C" { static void gtk_glwindow_expose_callback( GtkWidget *WXUNUSED(widget), GdkEventExpose *gdk_event, wxGLCanvas *win ) { - if (g_isIdle) - wxapp_install_idle_handler(); + // don't need to install idle handler, its done from "event" signal win->m_exposed = true; diff --git a/src/gtk/listbox.cpp b/src/gtk/listbox.cpp index 5d46ab79ce..fae6eb8e79 100644 --- a/src/gtk/listbox.cpp +++ b/src/gtk/listbox.cpp @@ -157,7 +157,7 @@ gtk_listbox_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxListBox *listbox ) { - if (g_isIdle) wxapp_install_idle_handler(); + // don't need to install idle handler, its done from "event" signal if (g_blockEventsOnDrag) return FALSE; if (g_blockEventsOnScroll) return FALSE; @@ -203,7 +203,7 @@ gtk_listbox_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxListBox *listbox ) { - if (g_isIdle) wxapp_install_idle_handler(); + // don't need to install idle handler, its done from "event" signal if (g_blockEventsOnDrag) return FALSE; diff --git a/src/gtk/minifram.cpp b/src/gtk/minifram.cpp index e915efca95..b98eceb5e7 100644 --- a/src/gtk/minifram.cpp +++ b/src/gtk/minifram.cpp @@ -64,7 +64,7 @@ static wxColor LightContrastColour(const wxColour& c) extern "C" { static void gtk_window_own_expose_callback( GtkWidget *widget, GdkEventExpose *gdk_event, wxMiniFrame *win ) { - if (g_isIdle) wxapp_install_idle_handler(); + // don't need to install idle handler, its done from "event" signal if (!win->m_hasVMT) return; if (gdk_event->count > 0) return; @@ -121,7 +121,7 @@ static void gtk_window_own_expose_callback( GtkWidget *widget, GdkEventExpose *g extern "C" { static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxMiniFrame *win ) { - if (g_isIdle) wxapp_install_idle_handler(); + // don't need to install idle handler, its done from "event" signal if (!win->m_hasVMT) return FALSE; if (g_blockEventsOnDrag) return TRUE; @@ -207,7 +207,7 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton extern "C" { static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxMiniFrame *win ) { - if (g_isIdle) wxapp_install_idle_handler(); + // don't need to install idle handler, its done from "event" signal if (!win->m_hasVMT) return FALSE; if (g_blockEventsOnDrag) return TRUE; @@ -242,8 +242,7 @@ extern "C" { static gboolean gtk_window_leave_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxMiniFrame *win ) { - if (g_isIdle) - wxapp_install_idle_handler(); + // don't need to install idle handler, its done from "event" signal if (!win->m_hasVMT) return FALSE; if (g_blockEventsOnDrag) return FALSE; @@ -262,8 +261,7 @@ extern "C" { static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion *gdk_event, wxMiniFrame *win ) { - if (g_isIdle) - wxapp_install_idle_handler(); + // don't need to install idle handler, its done from "event" signal if (!win->m_hasVMT) return FALSE; if (g_blockEventsOnDrag) return TRUE; diff --git a/src/gtk/notebook.cpp b/src/gtk/notebook.cpp index 756cd7f21b..c82ea26a99 100644 --- a/src/gtk/notebook.cpp +++ b/src/gtk/notebook.cpp @@ -192,8 +192,7 @@ gtk_notebook_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxNotebook *notebook ) { - if (g_isIdle) - wxapp_install_idle_handler(); + // don't need to install idle handler, its done from "event" signal if (!notebook->m_hasVMT) return FALSE; if (g_blockEventsOnDrag) return FALSE; diff --git a/src/gtk/radiobox.cpp b/src/gtk/radiobox.cpp index 9117e587ac..8d399e33e4 100644 --- a/src/gtk/radiobox.cpp +++ b/src/gtk/radiobox.cpp @@ -82,8 +82,7 @@ static void gtk_radiobutton_clicked_callback( GtkToggleButton *button, wxRadioBo extern "C" { static gint gtk_radiobox_keypress_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxRadioBox *rb ) { - if (g_isIdle) - wxapp_install_idle_handler(); + // don't need to install idle handler, its done from "event" signal if (!rb->m_hasVMT) return FALSE; if (g_blockEventsOnDrag) return FALSE; diff --git a/src/gtk/scrolbar.cpp b/src/gtk/scrolbar.cpp index f1d1efc384..00ea880973 100644 --- a/src/gtk/scrolbar.cpp +++ b/src/gtk/scrolbar.cpp @@ -57,7 +57,7 @@ extern "C" { static gboolean gtk_button_press_event(GtkRange*, GdkEventButton*, wxScrollBar* win) { - if (g_isIdle) wxapp_install_idle_handler(); + // don't need to install idle handler, its done from "event" signal win->m_mouseButtonDown = true; return false; @@ -98,8 +98,7 @@ extern "C" { static gboolean gtk_button_release_event(GtkRange* range, GdkEventButton*, wxScrollBar* win) { - if (g_isIdle) - wxapp_install_idle_handler(); + // don't need to install idle handler, its done from "event" signal win->m_mouseButtonDown = false; // If thumb tracking diff --git a/src/gtk/tbargtk.cpp b/src/gtk/tbargtk.cpp index 2bb36714e9..cd573461e5 100644 --- a/src/gtk/tbargtk.cpp +++ b/src/gtk/tbargtk.cpp @@ -204,7 +204,7 @@ static gint gtk_toolbar_tool_callback( GtkWidget *WXUNUSED(widget), GdkEventCrossing *gdk_event, wxToolBarTool *tool ) { - if (g_isIdle) wxapp_install_idle_handler(); + // don't need to install idle handler, its done from "event" signal if (g_blockEventsOnDrag) return TRUE; diff --git a/src/gtk/toplevel.cpp b/src/gtk/toplevel.cpp index 2584ec6512..c6ef11f681 100644 --- a/src/gtk/toplevel.cpp +++ b/src/gtk/toplevel.cpp @@ -111,8 +111,7 @@ static gboolean gtk_frame_focus_in_callback( GtkWidget *widget, GdkEvent *WXUNUSED(event), wxTopLevelWindowGTK *win ) { - if (g_isIdle) - wxapp_install_idle_handler(); + // don't need to install idle handler, its done from "event" signal switch ( g_sendActivateEvent ) { @@ -173,8 +172,7 @@ static gboolean gtk_frame_focus_out_callback( GtkWidget *widget, GdkEventFocus *WXUNUSED(gdk_event), wxTopLevelWindowGTK *win ) { - if (g_isIdle) - wxapp_install_idle_handler(); + // don't need to install idle handler, its done from "event" signal // if the focus goes out of our app alltogether, OnIdle() will send // wxActivateEvent, otherwise gtk_window_focus_in_callback() will reset @@ -257,8 +255,7 @@ gtk_frame_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxTopLevelWindowGTK *win ) { - if (g_isIdle) - wxapp_install_idle_handler(); + // don't need to install idle handler, its done from "event" signal if (win->IsEnabled() && (g_openDialogs == 0 || (win->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) || @@ -280,8 +277,7 @@ gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *WXUNUSED(event), wxTopLevelWindowGTK *win ) { - if (g_isIdle) - wxapp_install_idle_handler(); + // don't need to install idle handler, its done from "event" signal if (!win->m_hasVMT || !win->IsShown()) return FALSE; diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index c52acc6241..00d1a6c617 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -480,8 +480,7 @@ gtk_window_expose_callback( GtkWidget *widget, { DEBUG_MAIN_THREAD - if (g_isIdle) - wxapp_install_idle_handler(); + // don't need to install idle handler, its done from "event" signal // This callback gets called in drawing-idle time under // GTK 2.0, so we don't need to defer anything to idle @@ -991,8 +990,7 @@ gtk_window_key_press_callback( GtkWidget *widget, { DEBUG_MAIN_THREAD - if (g_isIdle) - wxapp_install_idle_handler(); + // don't need to install idle handler, its done from "event" signal if (!win->m_hasVMT) return FALSE; @@ -1244,8 +1242,7 @@ gtk_window_key_release_callback( GtkWidget *widget, { DEBUG_MAIN_THREAD - if (g_isIdle) - wxapp_install_idle_handler(); + // don't need to install idle handler, its done from "event" signal if (!win->m_hasVMT) return FALSE; @@ -1414,8 +1411,7 @@ int wxWindowGTK::GTKCallbackCommonPrologue(GdkEventAny *event) const { DEBUG_MAIN_THREAD - if (g_isIdle) - wxapp_install_idle_handler(); + // don't need to install idle handler, its done from "event" signal if (!m_hasVMT) return FALSE; @@ -1778,8 +1774,7 @@ window_scroll_event(GtkWidget*, GdkEventScroll* gdk_event, wxWindow* win) { DEBUG_MAIN_THREAD - if (g_isIdle) - wxapp_install_idle_handler(); + // don't need to install idle handler, its done from "event" signal if (gdk_event->direction != GDK_SCROLL_UP && gdk_event->direction != GDK_SCROLL_DOWN) @@ -1837,8 +1832,7 @@ gtk_window_focus_in_callback( GtkWidget *widget, { DEBUG_MAIN_THREAD - if (g_isIdle) - wxapp_install_idle_handler(); + // don't need to install idle handler, its done from "event" signal if (win->m_imData) gtk_im_context_focus_in(win->m_imData->context); @@ -1895,8 +1889,7 @@ gtk_window_focus_out_callback( GtkWidget *widget, { DEBUG_MAIN_THREAD - if (g_isIdle) - wxapp_install_idle_handler(); + // don't need to install idle handler, its done from "event" signal if (win->m_imData) gtk_im_context_focus_out(win->m_imData->context); @@ -2074,8 +2067,7 @@ gtk_scrollbar_button_press_event(GtkRange*, GdkEventButton*, wxWindow* win) { DEBUG_MAIN_THREAD - if (g_isIdle) - wxapp_install_idle_handler(); + // don't need to install idle handler, its done from "event" signal g_blockEventsOnScroll = true; win->m_mouseButtonDown = true; -- 2.45.2