From acfd422afac254f4356904275656c0c15685fa1e Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Tue, 27 Apr 1999 19:32:19 +0000 Subject: [PATCH] New idle handling. Only that. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2295 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/app.cpp | 87 +++++++++++++++++++++++++++++-------------- src/gtk/bmpbuttn.cpp | 9 +++++ src/gtk/button.cpp | 21 ++++++++--- src/gtk/checkbox.cpp | 9 +++++ src/gtk/choice.cpp | 25 ++++++++----- src/gtk/combobox.cpp | 17 +++++++-- src/gtk/data.cpp | 4 ++ src/gtk/dialog.cpp | 17 +++++++++ src/gtk/filedlg.cpp | 13 +++++++ src/gtk/frame.cpp | 23 ++++++++++++ src/gtk/listbox.cpp | 13 +++++++ src/gtk/mdi.cpp | 9 +++++ src/gtk/menu.cpp | 13 +++++++ src/gtk/minifram.cpp | 19 ++++++++++ src/gtk/notebook.cpp | 13 +++++++ src/gtk/radiobox.cpp | 9 +++++ src/gtk/radiobut.cpp | 9 +++++ src/gtk/scrolbar.cpp | 17 ++++++++- src/gtk/slider.cpp | 9 +++++ src/gtk/spinbutt.cpp | 9 +++++ src/gtk/tbargtk.cpp | 11 ++++++ src/gtk/textctrl.cpp | 11 ++++++ src/gtk/window.cpp | 43 +++++++++++++++++++++ src/gtk1/app.cpp | 87 +++++++++++++++++++++++++++++-------------- src/gtk1/bmpbuttn.cpp | 9 +++++ src/gtk1/button.cpp | 21 ++++++++--- src/gtk1/checkbox.cpp | 9 +++++ src/gtk1/choice.cpp | 25 ++++++++----- src/gtk1/combobox.cpp | 17 +++++++-- src/gtk1/data.cpp | 4 ++ src/gtk1/dialog.cpp | 17 +++++++++ src/gtk1/filedlg.cpp | 13 +++++++ src/gtk1/frame.cpp | 23 ++++++++++++ src/gtk1/listbox.cpp | 13 +++++++ src/gtk1/mdi.cpp | 9 +++++ src/gtk1/menu.cpp | 13 +++++++ src/gtk1/minifram.cpp | 19 ++++++++++ src/gtk1/notebook.cpp | 13 +++++++ src/gtk1/radiobox.cpp | 9 +++++ src/gtk1/radiobut.cpp | 9 +++++ src/gtk1/scrolbar.cpp | 17 ++++++++- src/gtk1/slider.cpp | 9 +++++ src/gtk1/spinbutt.cpp | 9 +++++ src/gtk1/tbargtk.cpp | 11 ++++++ src/gtk1/textctrl.cpp | 11 ++++++ src/gtk1/window.cpp | 43 +++++++++++++++++++++ 46 files changed, 722 insertions(+), 98 deletions(-) diff --git a/src/gtk/app.cpp b/src/gtk/app.cpp index e3bb20d00d..315d37194c 100644 --- a/src/gtk/app.cpp +++ b/src/gtk/app.cpp @@ -51,6 +51,7 @@ extern wxList *wxPendingEvents; extern wxCriticalSection *wxPendingEventsLocker; #endif extern wxResourceCache *wxTheResourceCache; +extern bool g_isIdle; unsigned char g_palette[64*3] = { @@ -135,7 +136,7 @@ void wxExit() gtk_main_quit(); } -// forward decl +/* forward declaration */ gint wxapp_idle_callback( gpointer WXUNUSED(data) ); bool wxYield() @@ -151,15 +152,62 @@ bool wxYield() win->OnInternalIdle(); } - // We need to temporarily remove idle callbacks or the loop will - // never finish. + if (wxTheApp->m_idleTag) + { + /* 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(); + + /* re-add idle handler */ + wxTheApp->m_idleTag = gtk_idle_add( wxapp_idle_callback, (gpointer) NULL ); + } + else + { + while (gtk_events_pending()) + gtk_main_iteration(); + } + + return TRUE; +} + +gint wxapp_idle_callback( gpointer WXUNUSED(data) ) +{ + if (!wxTheApp) return TRUE; + + /* 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; + +/* wxMutexGuiLeave(); + wxUsleep(10); + wxMutexGuiEnter(); */ - while (gtk_events_pending()) - gtk_main_iteration(); + return TRUE; +} + +void wxapp_install_idle_handler() +{ + /* 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 ); - return TRUE; + + g_isIdle = FALSE; } //----------------------------------------------------------------------------- @@ -172,22 +220,6 @@ BEGIN_EVENT_TABLE(wxApp, wxEvtHandler) EVT_IDLE(wxApp::OnIdle) END_EVENT_TABLE() -gint wxapp_idle_callback( gpointer WXUNUSED(data) ) -{ - if (wxTheApp) - { - while (wxTheApp->ProcessIdle()) - { - } - } - - wxMutexGuiLeave(); - wxUsleep(10); - wxMutexGuiEnter(); - - return TRUE; -} - wxApp::wxApp() { wxTheApp = this; @@ -202,7 +234,7 @@ wxApp::wxApp() wxApp::~wxApp() { - gtk_idle_remove( m_idleTag ); + if (m_idleTag) gtk_idle_remove( m_idleTag ); if (m_colorCube) free(m_colorCube); } @@ -255,14 +287,14 @@ bool wxApp::OnInitGui() int bb = (b << 3) | (b >> 2); GdkColor *colors = cmap->colors; - int max = 3 * (65536); + int max = 3 * 65536; int index = -1; for (int i = 0; i < cmap->size; i++) { int rdiff = ((rr << 8) - colors[i].red); - int gdiff = ((gg << 8)- colors[i].green); - int bdiff = ((bb << 8)- colors[i].blue); + int gdiff = ((gg << 8) - colors[i].green); + int bdiff = ((bb << 8) - colors[i].blue); int sum = ABS (rdiff) + ABS (gdiff) + ABS (bdiff); if (sum < max) { index = i; max = sum; } } @@ -272,7 +304,6 @@ bool wxApp::OnInitGui() } } - return TRUE; } @@ -378,7 +409,7 @@ bool wxApp::Initialized() bool wxApp::Pending() { - return gtk_events_pending(); + return (gtk_events_pending() > 0); } void wxApp::Dispatch() diff --git a/src/gtk/bmpbuttn.cpp b/src/gtk/bmpbuttn.cpp index c6d4499cef..dc24fa7301 100644 --- a/src/gtk/bmpbuttn.cpp +++ b/src/gtk/bmpbuttn.cpp @@ -22,6 +22,13 @@ class wxBitmapButton; +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -34,6 +41,8 @@ extern bool g_blockEventsOnDrag; static void gtk_bmpbutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!button->HasVMT()) return; if (g_blockEventsOnDrag) return; diff --git a/src/gtk/button.cpp b/src/gtk/button.cpp index 07a3dac108..1347e6ddae 100644 --- a/src/gtk/button.cpp +++ b/src/gtk/button.cpp @@ -22,6 +22,13 @@ class wxButton; +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -34,12 +41,14 @@ extern bool g_blockEventsOnDrag; static void gtk_button_clicked_callback( GtkWidget *WXUNUSED(widget), wxButton *button ) { - if (!button->HasVMT()) return; - if (g_blockEventsOnDrag) return; + if (g_isIdle) wxapp_install_idle_handler(); + + if (!button->HasVMT()) return; + if (g_blockEventsOnDrag) return; - wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, button->GetId()); - event.SetEventObject(button); - button->GetEventHandler()->ProcessEvent(event); + wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, button->GetId()); + event.SetEventObject(button); + button->GetEventHandler()->ProcessEvent(event); } //----------------------------------------------------------------------------- @@ -54,7 +63,7 @@ wxButton::wxButton() wxButton::~wxButton() { - if (m_clientData) delete m_clientData; + if (m_clientData) delete m_clientData; } bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label, diff --git a/src/gtk/checkbox.cpp b/src/gtk/checkbox.cpp index 8cda3d112b..1811807ab0 100644 --- a/src/gtk/checkbox.cpp +++ b/src/gtk/checkbox.cpp @@ -17,6 +17,13 @@ #include "gdk/gdk.h" #include "gtk/gtk.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -29,6 +36,8 @@ extern bool g_blockEventsOnDrag; static void gtk_checkbox_clicked_callback( GtkWidget *WXUNUSED(widget), wxCheckBox *cb ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!cb->HasVMT()) return; if (cb->m_blockFirstEvent) diff --git a/src/gtk/choice.cpp b/src/gtk/choice.cpp index ba049f6447..41ef1aba6f 100644 --- a/src/gtk/choice.cpp +++ b/src/gtk/choice.cpp @@ -17,6 +17,13 @@ #include "gdk/gdk.h" #include "gtk/gtk.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -29,17 +36,17 @@ extern bool g_blockEventsOnDrag; static void gtk_choice_clicked_callback( GtkWidget *WXUNUSED(widget), wxChoice *choice ) { - if (!choice->HasVMT()) - return; + if (g_isIdle) wxapp_install_idle_handler(); + + if (!choice->HasVMT()) return; - if (g_blockEventsOnDrag) - return; + if (g_blockEventsOnDrag) return; - wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, choice->GetId() ); - event.SetInt( choice->GetSelection() ); - event.SetString( choice->GetStringSelection() ); - event.SetEventObject(choice); - choice->GetEventHandler()->ProcessEvent(event); + wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, choice->GetId() ); + event.SetInt( choice->GetSelection() ); + event.SetString( choice->GetStringSelection() ); + event.SetEventObject(choice); + choice->GetEventHandler()->ProcessEvent(event); } //----------------------------------------------------------------------------- diff --git a/src/gtk/combobox.cpp b/src/gtk/combobox.cpp index 63162e8ed0..cb5a74135a 100644 --- a/src/gtk/combobox.cpp +++ b/src/gtk/combobox.cpp @@ -18,6 +18,13 @@ #include "gdk/gdk.h" #include "gtk/gtk.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -31,11 +38,11 @@ extern bool g_blockEventsOnDrag; static void gtk_combo_clicked_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo ) { - if (!combo->HasVMT()) - return; + if (g_isIdle) wxapp_install_idle_handler(); - if (g_blockEventsOnDrag) - return; + if (!combo->HasVMT()) return; + + if (g_blockEventsOnDrag) return; if (combo->m_alreadySent) { @@ -60,6 +67,8 @@ gtk_combo_clicked_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo ) static void gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo ) { + if (g_isIdle) wxapp_install_idle_handler(); + wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() ); event.SetString( combo->GetValue() ); event.SetEventObject( combo ); diff --git a/src/gtk/data.cpp b/src/gtk/data.cpp index 37f4f0006c..b2fdae961c 100644 --- a/src/gtk/data.cpp +++ b/src/gtk/data.cpp @@ -54,6 +54,10 @@ bool g_blockEventsOnDrag = FALSE; /* Don't allow mouse event propagation during scroll */ bool g_blockEventsOnScroll = FALSE; +/* TRUE when the message queue is empty. this gets set to + FALSE by all event callbacks before anything else is done */ +bool g_isIdle = FALSE; + /* Message Strings for Internationalization */ char **wx_msg_str = (char**)NULL; diff --git a/src/gtk/dialog.cpp b/src/gtk/dialog.cpp index dde6539b16..b8adf30bda 100644 --- a/src/gtk/dialog.cpp +++ b/src/gtk/dialog.cpp @@ -19,6 +19,15 @@ #include "gtk/gtk.h" #include "wx/gtk/win_gtk.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + +//----------------------------------------------------------------------------- +// data //----------------------------------------------------------------------------- extern wxList wxPendingDelete; @@ -29,6 +38,8 @@ extern wxList wxPendingDelete; bool gtk_dialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxDialog *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + /* printf( "OnDelete from " ); if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) @@ -47,6 +58,8 @@ bool gtk_dialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED static void gtk_dialog_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxDialog *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return; /* @@ -70,6 +83,8 @@ static void gtk_dialog_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation static gint gtk_dialog_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *event, wxDialog *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; win->m_x = event->x; @@ -92,6 +107,8 @@ static gint gtk_dialog_configure_callback( GtkWidget *WXUNUSED(widget), GdkEvent static gint gtk_dialog_realized_callback( GtkWidget *widget, wxDialog *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + /* all this is for Motif Window Manager "hints" and is supposed to be recognized by other WM as well. not tested. */ long decor = (long) GDK_DECOR_ALL; diff --git a/src/gtk/filedlg.cpp b/src/gtk/filedlg.cpp index fa6d087c99..bd7d405395 100644 --- a/src/gtk/filedlg.cpp +++ b/src/gtk/filedlg.cpp @@ -18,6 +18,13 @@ #include "gtk/gtk.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // "delete_event" //----------------------------------------------------------------------------- @@ -25,6 +32,8 @@ static bool gtk_filedialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxDialog *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + /* printf( "OnDelete from " ); if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) @@ -44,6 +53,8 @@ bool gtk_filedialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUN static void gtk_filedialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFileDialog *dialog ) { + if (g_isIdle) wxapp_install_idle_handler(); + int style = dialog->GetStyle(); GtkFileSelection *filedlg = GTK_FILE_SELECTION(dialog->m_widget); @@ -85,6 +96,8 @@ void gtk_filedialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFileDialog *dial static void gtk_filedialog_cancel_callback( GtkWidget *WXUNUSED(w), wxFileDialog *dialog ) { + if (g_isIdle) wxapp_install_idle_handler(); + wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); event.SetEventObject( dialog ); dialog->GetEventHandler()->ProcessEvent( event ); diff --git a/src/gtk/frame.cpp b/src/gtk/frame.cpp index 38b56e56d9..f402313c36 100644 --- a/src/gtk/frame.cpp +++ b/src/gtk/frame.cpp @@ -33,6 +33,13 @@ const int wxMENU_HEIGHT = 27; const int wxSTATUS_HEIGHT = 25; const int wxPLACE_HOLDER = 0; +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -45,6 +52,8 @@ extern wxList wxPendingDelete; static void gtk_frame_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxFrame *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return; /* @@ -68,6 +77,8 @@ static void gtk_frame_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* static gint gtk_frame_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxFrame *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + /* printf( "OnDelete from " ); if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) @@ -86,6 +97,8 @@ static gint gtk_frame_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WX static void gtk_menu_attached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return; win->m_menuBarDetached = FALSE; @@ -98,6 +111,8 @@ static void gtk_menu_attached_callback( GtkWidget *WXUNUSED(widget), GtkWidget * static void gtk_menu_detached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return; win->m_menuBarDetached = TRUE; @@ -110,6 +125,8 @@ static void gtk_menu_detached_callback( GtkWidget *WXUNUSED(widget), GtkWidget * static void gtk_toolbar_attached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return; win->m_toolBarDetached = FALSE; @@ -122,6 +139,8 @@ static void gtk_toolbar_attached_callback( GtkWidget *WXUNUSED(widget), GtkWidge static void gtk_toolbar_detached_callback( GtkWidget *widget, GtkWidget *WXUNUSED(child), wxFrame *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return; win->m_toolBarDetached = TRUE; @@ -134,6 +153,8 @@ static void gtk_toolbar_detached_callback( GtkWidget *widget, GtkWidget *WXUNUSE static gint gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *event, wxFrame *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; win->m_x = event->x; @@ -156,6 +177,8 @@ static gint gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventC static gint gtk_frame_realized_callback( GtkWidget *widget, wxFrame *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + /* all this is for Motif Window Manager "hints" and is supposed to be recognized by other WM as well. not tested. */ long decor = (long) GDK_DECOR_ALL; diff --git a/src/gtk/listbox.cpp b/src/gtk/listbox.cpp index 138fc38d96..e0fa8aca7e 100644 --- a/src/gtk/listbox.cpp +++ b/src/gtk/listbox.cpp @@ -29,6 +29,13 @@ #include "gdk/gdk.h" #include "gtk/gtk.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //------------------------------------------------------------------------- // conditional compilation //------------------------------------------------------------------------- @@ -63,6 +70,8 @@ extern bool g_blockEventsOnScroll; static gint gtk_listbox_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxListBox *listbox ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (g_blockEventsOnDrag) return FALSE; if (g_blockEventsOnScroll) return FALSE; @@ -116,6 +125,8 @@ gtk_listbox_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, static gint gtk_listbox_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxListBox *listbox ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (g_blockEventsOnDrag) return FALSE; if (!listbox->HasVMT()) return FALSE; @@ -142,6 +153,8 @@ gtk_listbox_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxLis static void gtk_listitem_select_callback( GtkWidget *WXUNUSED(widget), wxListBox *listbox ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!listbox->HasVMT()) return; if (g_blockEventsOnDrag) return; diff --git a/src/gtk/mdi.cpp b/src/gtk/mdi.cpp index 85eb0270c7..064376b54c 100644 --- a/src/gtk/mdi.cpp +++ b/src/gtk/mdi.cpp @@ -27,6 +27,13 @@ const int wxMENU_HEIGHT = 27; +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // globals //----------------------------------------------------------------------------- @@ -314,6 +321,8 @@ void wxMDIChildFrame::OnActivate( wxActivateEvent &WXUNUSED(event) ) static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if ((win->m_x == alloc->x) && (win->m_y == alloc->y) && (win->m_width == alloc->width) && diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index dd3d6850bf..5e6b4c8b03 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -20,6 +20,13 @@ #include "gdk/gdk.h" #include "gtk/gtk.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // wxMenuBar //----------------------------------------------------------------------------- @@ -343,6 +350,8 @@ wxString wxMenuBar::GetHelpString( int id ) const static void gtk_menu_clicked_callback( GtkWidget *widget, wxMenu *menu ) { + if (g_isIdle) wxapp_install_idle_handler(); + int id = menu->FindMenuIdByMenuItem(widget); /* should find it for normal (not popup) menu */ @@ -392,6 +401,8 @@ static void gtk_menu_clicked_callback( GtkWidget *widget, wxMenu *menu ) static void gtk_menu_hilight_callback( GtkWidget *widget, wxMenu *menu ) { + if (g_isIdle) wxapp_install_idle_handler(); + int id = menu->FindMenuIdByMenuItem(widget); wxASSERT( id != -1 ); // should find it! @@ -424,6 +435,8 @@ static void gtk_menu_hilight_callback( GtkWidget *widget, wxMenu *menu ) static void gtk_menu_nolight_callback( GtkWidget *widget, wxMenu *menu ) { + if (g_isIdle) wxapp_install_idle_handler(); + int id = menu->FindMenuIdByMenuItem(widget); wxASSERT( id != -1 ); // should find it! diff --git a/src/gtk/minifram.cpp b/src/gtk/minifram.cpp index ea6f98fe1a..9b0c1f0309 100644 --- a/src/gtk/minifram.cpp +++ b/src/gtk/minifram.cpp @@ -21,6 +21,13 @@ #include "gdk/gdkprivate.h" #include "gdk/gdkx.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -56,6 +63,8 @@ static void DrawFrame( GtkWidget *widget, int x, int y, int w, int h ) static void gtk_window_own_expose_callback( GtkWidget *widget, GdkEventExpose *gdk_event, wxFrame *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return; if (gdk_event->count > 0) return; @@ -73,6 +82,8 @@ static void gtk_window_own_expose_callback( GtkWidget *widget, GdkEventExpose *g static void gtk_window_own_draw_callback( GtkWidget *widget, GdkRectangle *WXUNUSED(rect), wxFrame *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return; gtk_draw_shadow( widget->style, @@ -89,6 +100,8 @@ static void gtk_window_own_draw_callback( GtkWidget *widget, GdkRectangle *WXUNU static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxMiniFrame *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return TRUE; if (g_blockEventsOnScroll) return TRUE; @@ -124,6 +137,8 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxMiniFrame *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return TRUE; if (g_blockEventsOnScroll) return TRUE; @@ -155,6 +170,8 @@ static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButto static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion *gdk_event, wxMiniFrame *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return TRUE; if (g_blockEventsOnScroll) return TRUE; @@ -186,6 +203,8 @@ static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion static void gtk_button_clicked_callback( GtkWidget *WXUNUSED(widget), wxMiniFrame *mf ) { + if (g_isIdle) wxapp_install_idle_handler(); + mf->Close(); } diff --git a/src/gtk/notebook.cpp b/src/gtk/notebook.cpp index a7b6bd091d..a690de0dea 100644 --- a/src/gtk/notebook.cpp +++ b/src/gtk/notebook.cpp @@ -23,6 +23,13 @@ #include "wx/gtk/win_gtk.h" #include "gdk/gdkkeysyms.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -86,6 +93,8 @@ static void gtk_notebook_page_change_callback(GtkNotebook *WXUNUSED(widget), gint nPage, gpointer data) { + if (g_isIdle) wxapp_install_idle_handler(); + wxNotebook *notebook = (wxNotebook *)data; int old = notebook->GetSelection(); @@ -104,6 +113,8 @@ static void gtk_notebook_page_change_callback(GtkNotebook *WXUNUSED(widget), static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if ((win->m_x == alloc->x) && (win->m_y == alloc->y) && (win->m_width == alloc->width) && @@ -124,6 +135,8 @@ static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* static gint gtk_notebook_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxNotebook *notebook ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (g_blockEventsOnDrag) return FALSE; if (!notebook->HasVMT()) return FALSE; diff --git a/src/gtk/radiobox.cpp b/src/gtk/radiobox.cpp index 1f60b251b0..e9ba1e8c5e 100644 --- a/src/gtk/radiobox.cpp +++ b/src/gtk/radiobox.cpp @@ -19,6 +19,13 @@ #include "gtk/gtk.h" #include "wx/gtk/win_gtk.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -31,6 +38,8 @@ extern bool g_blockEventsOnDrag; static void gtk_radiobutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxRadioBox *rb ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!rb->HasVMT()) return; if (g_blockEventsOnDrag) return; diff --git a/src/gtk/radiobut.cpp b/src/gtk/radiobut.cpp index 8b93df7380..9ab2906909 100644 --- a/src/gtk/radiobut.cpp +++ b/src/gtk/radiobut.cpp @@ -16,6 +16,13 @@ #include "gdk/gdk.h" #include "gtk/gtk.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -29,6 +36,8 @@ extern bool g_blockEventsOnDrag; static void gtk_radiobutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxRadioButton *rb ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!rb->HasVMT()) return; if (rb->m_blockFirstEvent) diff --git a/src/gtk/scrolbar.cpp b/src/gtk/scrolbar.cpp index 39aba4ce46..5c9ddc9eb5 100644 --- a/src/gtk/scrolbar.cpp +++ b/src/gtk/scrolbar.cpp @@ -19,6 +19,13 @@ #include "gdk/gdk.h" #include "gtk/gtk.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -32,6 +39,8 @@ extern bool g_blockEventsOnScroll; static void gtk_scrollbar_callback( GtkWidget *WXUNUSED(widget), wxScrollBar *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return; if (g_blockEventsOnDrag) return; @@ -83,10 +92,12 @@ static gint gtk_scrollbar_button_press_callback( GtkRange *WXUNUSED(widget), GdkEventButton *WXUNUSED(gdk_event), wxScrollBar *win ) { - win->m_isScrolling = TRUE; + if (g_isIdle) wxapp_install_idle_handler(); + + win->m_isScrolling = TRUE; // g_blockEventsOnScroll = TRUE; doesn't work in DialogEd - return FALSE; + return FALSE; } //----------------------------------------------------------------------------- @@ -97,6 +108,8 @@ static gint gtk_scrollbar_button_release_callback( GtkRange *WXUNUSED(widget), GdkEventButton *WXUNUSED(gdk_event), wxScrollBar *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + win->m_isScrolling = FALSE; // g_blockEventsOnScroll = FALSE; diff --git a/src/gtk/slider.cpp b/src/gtk/slider.cpp index a9a4e9a7d3..3c7c1ade23 100644 --- a/src/gtk/slider.cpp +++ b/src/gtk/slider.cpp @@ -18,6 +18,13 @@ #include "gdk/gdk.h" #include "gtk/gtk.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -30,6 +37,8 @@ extern bool g_blockEventsOnDrag; static void gtk_slider_callback( GtkWidget *WXUNUSED(widget), wxSlider *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return; if (g_blockEventsOnDrag) return; diff --git a/src/gtk/spinbutt.cpp b/src/gtk/spinbutt.cpp index afbd61ee1e..73f6493e81 100644 --- a/src/gtk/spinbutt.cpp +++ b/src/gtk/spinbutt.cpp @@ -19,6 +19,13 @@ #include "gdk/gdk.h" #include "gtk/gtk.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -33,6 +40,8 @@ static const float sensitivity = 0.2; static void gtk_spinbutt_callback( GtkWidget *WXUNUSED(widget), wxSpinButton *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return; if (g_blockEventsOnDrag) return; diff --git a/src/gtk/tbargtk.cpp b/src/gtk/tbargtk.cpp index dfc1d7b631..46ca5bad1f 100644 --- a/src/gtk/tbargtk.cpp +++ b/src/gtk/tbargtk.cpp @@ -18,6 +18,13 @@ #include "gdk/gdk.h" #include "gtk/gtk.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -30,6 +37,8 @@ extern bool g_blockEventsOnDrag; static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget), wxToolBarTool *tool ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (g_blockEventsOnDrag) return; if (!tool->m_enabled) return; @@ -45,6 +54,8 @@ static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget), wxToolBarTool *to static gint gtk_toolbar_enter_callback( GtkWidget *WXUNUSED(widget), GdkEventCrossing *WXUNUSED(gdk_event), wxToolBarTool *tool ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (g_blockEventsOnDrag) return TRUE; /* we grey-out the tip text of disabled tool */ diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index bdbc8e279f..eab7ee1db8 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -24,6 +24,13 @@ #include "gtk/gtk.h" #include "gdk/gdkkeysyms.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -37,6 +44,8 @@ extern bool g_blockEventsOnDrag; static void gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->m_hasVMT) return; win->SetModified(); @@ -54,6 +63,8 @@ gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win ) static void gtk_scrollbar_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->m_hasVMT) return; win->CalculateScrollbar(); diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 6310487a74..c1a81398db 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -128,6 +128,7 @@ extern wxList wxPendingDelete; extern bool g_blockEventsOnDrag; extern bool g_blockEventsOnScroll; +extern bool g_isIdle; static bool g_capturing = FALSE; static wxWindow *g_focusWindow = (wxWindow*) NULL; @@ -135,6 +136,13 @@ static wxWindow *g_focusWindow = (wxWindow*) NULL; the last click here */ static guint32 gs_timeLastClick = 0; +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + #if (GTK_MINOR_VERSION > 0) //----------------------------------------------------------------------------- @@ -231,6 +239,8 @@ static void gtk_window_own_draw_callback( GtkWidget *widget, GdkRectangle *WXUNU static void gtk_window_expose_callback( GtkWidget *WXUNUSED(widget), GdkEventExpose *gdk_event, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return; win->m_updateRegion.Union( gdk_event->area.x, @@ -260,6 +270,8 @@ static void gtk_window_expose_callback( GtkWidget *WXUNUSED(widget), GdkEventExp static void gtk_window_draw_callback( GtkWidget *WXUNUSED(widget), GdkRectangle *rect, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return; win->m_updateRegion.Union( rect->x, rect->y, rect->width, rect->height ); @@ -277,6 +289,8 @@ static void gtk_window_draw_callback( GtkWidget *WXUNUSED(widget), GdkRectangle static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return FALSE; @@ -456,6 +470,8 @@ static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_e static gint gtk_window_key_release_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return FALSE; @@ -572,6 +588,8 @@ static gint gtk_window_key_release_callback( GtkWidget *widget, GdkEventKey *gdk static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + /* wxPrintf( _T("1) OnButtonPress from ") ); if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) @@ -734,6 +752,8 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return FALSE; if (g_blockEventsOnScroll) return FALSE; @@ -838,6 +858,8 @@ static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButto static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion *gdk_event, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return FALSE; if (g_blockEventsOnScroll) return FALSE; @@ -945,6 +967,8 @@ static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion static gint gtk_window_focus_in_callback( GtkWidget *widget, GdkEvent *WXUNUSED(event), wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return FALSE; @@ -992,6 +1016,8 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget, GdkEvent *WXUNUSED( static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED(event), wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return FALSE; @@ -1028,6 +1054,8 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return FALSE; @@ -1078,6 +1106,8 @@ static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_ static gint gtk_window_leave_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return FALSE; @@ -1128,6 +1158,8 @@ static gint gtk_window_leave_callback( GtkWidget *widget, GdkEventCrossing *gdk_ static void gtk_window_vscroll_callback( GtkWidget *WXUNUSED(widget), wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (g_blockEventsOnDrag) return; /* @@ -1176,6 +1208,8 @@ static void gtk_window_vscroll_callback( GtkWidget *WXUNUSED(widget), wxWindow * static void gtk_window_hscroll_callback( GtkWidget *WXUNUSED(widget), wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (g_blockEventsOnDrag) return; /* @@ -1224,6 +1258,8 @@ static void gtk_window_hscroll_callback( GtkWidget *WXUNUSED(widget), wxWindow * static void gtk_window_vscroll_change_callback( GtkWidget *WXUNUSED(widget), wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (g_blockEventsOnDrag) return; /* @@ -1249,6 +1285,8 @@ static void gtk_window_vscroll_change_callback( GtkWidget *WXUNUSED(widget), wxW static void gtk_window_hscroll_change_callback( GtkWidget *WXUNUSED(widget), wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (g_blockEventsOnDrag) return; /* @@ -1276,6 +1314,8 @@ static gint gtk_scrollbar_button_press_callback( GtkRange *WXUNUSED(widget), GdkEventButton *WXUNUSED(gdk_event), wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + // don't test here as we can release the mouse while being over // a different window then the slider // @@ -1295,6 +1335,7 @@ static gint gtk_scrollbar_button_release_callback( GtkRange *widget, GdkEventButton *WXUNUSED(gdk_event), wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); // don't test here as we can release the mouse while being over // a different window then the slider @@ -1324,6 +1365,8 @@ static gint gtk_scrollbar_button_release_callback( GtkRange *widget, static gint gtk_window_realized_callback( GtkWidget *widget, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (win->m_font != *wxSWISS_FONT) { wxFont font( win->m_font ); diff --git a/src/gtk1/app.cpp b/src/gtk1/app.cpp index e3bb20d00d..315d37194c 100644 --- a/src/gtk1/app.cpp +++ b/src/gtk1/app.cpp @@ -51,6 +51,7 @@ extern wxList *wxPendingEvents; extern wxCriticalSection *wxPendingEventsLocker; #endif extern wxResourceCache *wxTheResourceCache; +extern bool g_isIdle; unsigned char g_palette[64*3] = { @@ -135,7 +136,7 @@ void wxExit() gtk_main_quit(); } -// forward decl +/* forward declaration */ gint wxapp_idle_callback( gpointer WXUNUSED(data) ); bool wxYield() @@ -151,15 +152,62 @@ bool wxYield() win->OnInternalIdle(); } - // We need to temporarily remove idle callbacks or the loop will - // never finish. + if (wxTheApp->m_idleTag) + { + /* 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(); + + /* re-add idle handler */ + wxTheApp->m_idleTag = gtk_idle_add( wxapp_idle_callback, (gpointer) NULL ); + } + else + { + while (gtk_events_pending()) + gtk_main_iteration(); + } + + return TRUE; +} + +gint wxapp_idle_callback( gpointer WXUNUSED(data) ) +{ + if (!wxTheApp) return TRUE; + + /* 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; + +/* wxMutexGuiLeave(); + wxUsleep(10); + wxMutexGuiEnter(); */ - while (gtk_events_pending()) - gtk_main_iteration(); + return TRUE; +} + +void wxapp_install_idle_handler() +{ + /* 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 ); - return TRUE; + + g_isIdle = FALSE; } //----------------------------------------------------------------------------- @@ -172,22 +220,6 @@ BEGIN_EVENT_TABLE(wxApp, wxEvtHandler) EVT_IDLE(wxApp::OnIdle) END_EVENT_TABLE() -gint wxapp_idle_callback( gpointer WXUNUSED(data) ) -{ - if (wxTheApp) - { - while (wxTheApp->ProcessIdle()) - { - } - } - - wxMutexGuiLeave(); - wxUsleep(10); - wxMutexGuiEnter(); - - return TRUE; -} - wxApp::wxApp() { wxTheApp = this; @@ -202,7 +234,7 @@ wxApp::wxApp() wxApp::~wxApp() { - gtk_idle_remove( m_idleTag ); + if (m_idleTag) gtk_idle_remove( m_idleTag ); if (m_colorCube) free(m_colorCube); } @@ -255,14 +287,14 @@ bool wxApp::OnInitGui() int bb = (b << 3) | (b >> 2); GdkColor *colors = cmap->colors; - int max = 3 * (65536); + int max = 3 * 65536; int index = -1; for (int i = 0; i < cmap->size; i++) { int rdiff = ((rr << 8) - colors[i].red); - int gdiff = ((gg << 8)- colors[i].green); - int bdiff = ((bb << 8)- colors[i].blue); + int gdiff = ((gg << 8) - colors[i].green); + int bdiff = ((bb << 8) - colors[i].blue); int sum = ABS (rdiff) + ABS (gdiff) + ABS (bdiff); if (sum < max) { index = i; max = sum; } } @@ -272,7 +304,6 @@ bool wxApp::OnInitGui() } } - return TRUE; } @@ -378,7 +409,7 @@ bool wxApp::Initialized() bool wxApp::Pending() { - return gtk_events_pending(); + return (gtk_events_pending() > 0); } void wxApp::Dispatch() diff --git a/src/gtk1/bmpbuttn.cpp b/src/gtk1/bmpbuttn.cpp index c6d4499cef..dc24fa7301 100644 --- a/src/gtk1/bmpbuttn.cpp +++ b/src/gtk1/bmpbuttn.cpp @@ -22,6 +22,13 @@ class wxBitmapButton; +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -34,6 +41,8 @@ extern bool g_blockEventsOnDrag; static void gtk_bmpbutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!button->HasVMT()) return; if (g_blockEventsOnDrag) return; diff --git a/src/gtk1/button.cpp b/src/gtk1/button.cpp index 07a3dac108..1347e6ddae 100644 --- a/src/gtk1/button.cpp +++ b/src/gtk1/button.cpp @@ -22,6 +22,13 @@ class wxButton; +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -34,12 +41,14 @@ extern bool g_blockEventsOnDrag; static void gtk_button_clicked_callback( GtkWidget *WXUNUSED(widget), wxButton *button ) { - if (!button->HasVMT()) return; - if (g_blockEventsOnDrag) return; + if (g_isIdle) wxapp_install_idle_handler(); + + if (!button->HasVMT()) return; + if (g_blockEventsOnDrag) return; - wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, button->GetId()); - event.SetEventObject(button); - button->GetEventHandler()->ProcessEvent(event); + wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, button->GetId()); + event.SetEventObject(button); + button->GetEventHandler()->ProcessEvent(event); } //----------------------------------------------------------------------------- @@ -54,7 +63,7 @@ wxButton::wxButton() wxButton::~wxButton() { - if (m_clientData) delete m_clientData; + if (m_clientData) delete m_clientData; } bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label, diff --git a/src/gtk1/checkbox.cpp b/src/gtk1/checkbox.cpp index 8cda3d112b..1811807ab0 100644 --- a/src/gtk1/checkbox.cpp +++ b/src/gtk1/checkbox.cpp @@ -17,6 +17,13 @@ #include "gdk/gdk.h" #include "gtk/gtk.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -29,6 +36,8 @@ extern bool g_blockEventsOnDrag; static void gtk_checkbox_clicked_callback( GtkWidget *WXUNUSED(widget), wxCheckBox *cb ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!cb->HasVMT()) return; if (cb->m_blockFirstEvent) diff --git a/src/gtk1/choice.cpp b/src/gtk1/choice.cpp index ba049f6447..41ef1aba6f 100644 --- a/src/gtk1/choice.cpp +++ b/src/gtk1/choice.cpp @@ -17,6 +17,13 @@ #include "gdk/gdk.h" #include "gtk/gtk.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -29,17 +36,17 @@ extern bool g_blockEventsOnDrag; static void gtk_choice_clicked_callback( GtkWidget *WXUNUSED(widget), wxChoice *choice ) { - if (!choice->HasVMT()) - return; + if (g_isIdle) wxapp_install_idle_handler(); + + if (!choice->HasVMT()) return; - if (g_blockEventsOnDrag) - return; + if (g_blockEventsOnDrag) return; - wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, choice->GetId() ); - event.SetInt( choice->GetSelection() ); - event.SetString( choice->GetStringSelection() ); - event.SetEventObject(choice); - choice->GetEventHandler()->ProcessEvent(event); + wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, choice->GetId() ); + event.SetInt( choice->GetSelection() ); + event.SetString( choice->GetStringSelection() ); + event.SetEventObject(choice); + choice->GetEventHandler()->ProcessEvent(event); } //----------------------------------------------------------------------------- diff --git a/src/gtk1/combobox.cpp b/src/gtk1/combobox.cpp index 63162e8ed0..cb5a74135a 100644 --- a/src/gtk1/combobox.cpp +++ b/src/gtk1/combobox.cpp @@ -18,6 +18,13 @@ #include "gdk/gdk.h" #include "gtk/gtk.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -31,11 +38,11 @@ extern bool g_blockEventsOnDrag; static void gtk_combo_clicked_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo ) { - if (!combo->HasVMT()) - return; + if (g_isIdle) wxapp_install_idle_handler(); - if (g_blockEventsOnDrag) - return; + if (!combo->HasVMT()) return; + + if (g_blockEventsOnDrag) return; if (combo->m_alreadySent) { @@ -60,6 +67,8 @@ gtk_combo_clicked_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo ) static void gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo ) { + if (g_isIdle) wxapp_install_idle_handler(); + wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() ); event.SetString( combo->GetValue() ); event.SetEventObject( combo ); diff --git a/src/gtk1/data.cpp b/src/gtk1/data.cpp index 37f4f0006c..b2fdae961c 100644 --- a/src/gtk1/data.cpp +++ b/src/gtk1/data.cpp @@ -54,6 +54,10 @@ bool g_blockEventsOnDrag = FALSE; /* Don't allow mouse event propagation during scroll */ bool g_blockEventsOnScroll = FALSE; +/* TRUE when the message queue is empty. this gets set to + FALSE by all event callbacks before anything else is done */ +bool g_isIdle = FALSE; + /* Message Strings for Internationalization */ char **wx_msg_str = (char**)NULL; diff --git a/src/gtk1/dialog.cpp b/src/gtk1/dialog.cpp index dde6539b16..b8adf30bda 100644 --- a/src/gtk1/dialog.cpp +++ b/src/gtk1/dialog.cpp @@ -19,6 +19,15 @@ #include "gtk/gtk.h" #include "wx/gtk/win_gtk.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + +//----------------------------------------------------------------------------- +// data //----------------------------------------------------------------------------- extern wxList wxPendingDelete; @@ -29,6 +38,8 @@ extern wxList wxPendingDelete; bool gtk_dialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxDialog *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + /* printf( "OnDelete from " ); if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) @@ -47,6 +58,8 @@ bool gtk_dialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED static void gtk_dialog_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxDialog *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return; /* @@ -70,6 +83,8 @@ static void gtk_dialog_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation static gint gtk_dialog_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *event, wxDialog *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; win->m_x = event->x; @@ -92,6 +107,8 @@ static gint gtk_dialog_configure_callback( GtkWidget *WXUNUSED(widget), GdkEvent static gint gtk_dialog_realized_callback( GtkWidget *widget, wxDialog *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + /* all this is for Motif Window Manager "hints" and is supposed to be recognized by other WM as well. not tested. */ long decor = (long) GDK_DECOR_ALL; diff --git a/src/gtk1/filedlg.cpp b/src/gtk1/filedlg.cpp index fa6d087c99..bd7d405395 100644 --- a/src/gtk1/filedlg.cpp +++ b/src/gtk1/filedlg.cpp @@ -18,6 +18,13 @@ #include "gtk/gtk.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // "delete_event" //----------------------------------------------------------------------------- @@ -25,6 +32,8 @@ static bool gtk_filedialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxDialog *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + /* printf( "OnDelete from " ); if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) @@ -44,6 +53,8 @@ bool gtk_filedialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUN static void gtk_filedialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFileDialog *dialog ) { + if (g_isIdle) wxapp_install_idle_handler(); + int style = dialog->GetStyle(); GtkFileSelection *filedlg = GTK_FILE_SELECTION(dialog->m_widget); @@ -85,6 +96,8 @@ void gtk_filedialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFileDialog *dial static void gtk_filedialog_cancel_callback( GtkWidget *WXUNUSED(w), wxFileDialog *dialog ) { + if (g_isIdle) wxapp_install_idle_handler(); + wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); event.SetEventObject( dialog ); dialog->GetEventHandler()->ProcessEvent( event ); diff --git a/src/gtk1/frame.cpp b/src/gtk1/frame.cpp index 38b56e56d9..f402313c36 100644 --- a/src/gtk1/frame.cpp +++ b/src/gtk1/frame.cpp @@ -33,6 +33,13 @@ const int wxMENU_HEIGHT = 27; const int wxSTATUS_HEIGHT = 25; const int wxPLACE_HOLDER = 0; +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -45,6 +52,8 @@ extern wxList wxPendingDelete; static void gtk_frame_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxFrame *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return; /* @@ -68,6 +77,8 @@ static void gtk_frame_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* static gint gtk_frame_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxFrame *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + /* printf( "OnDelete from " ); if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) @@ -86,6 +97,8 @@ static gint gtk_frame_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WX static void gtk_menu_attached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return; win->m_menuBarDetached = FALSE; @@ -98,6 +111,8 @@ static void gtk_menu_attached_callback( GtkWidget *WXUNUSED(widget), GtkWidget * static void gtk_menu_detached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return; win->m_menuBarDetached = TRUE; @@ -110,6 +125,8 @@ static void gtk_menu_detached_callback( GtkWidget *WXUNUSED(widget), GtkWidget * static void gtk_toolbar_attached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return; win->m_toolBarDetached = FALSE; @@ -122,6 +139,8 @@ static void gtk_toolbar_attached_callback( GtkWidget *WXUNUSED(widget), GtkWidge static void gtk_toolbar_detached_callback( GtkWidget *widget, GtkWidget *WXUNUSED(child), wxFrame *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return; win->m_toolBarDetached = TRUE; @@ -134,6 +153,8 @@ static void gtk_toolbar_detached_callback( GtkWidget *widget, GtkWidget *WXUNUSE static gint gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *event, wxFrame *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; win->m_x = event->x; @@ -156,6 +177,8 @@ static gint gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventC static gint gtk_frame_realized_callback( GtkWidget *widget, wxFrame *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + /* all this is for Motif Window Manager "hints" and is supposed to be recognized by other WM as well. not tested. */ long decor = (long) GDK_DECOR_ALL; diff --git a/src/gtk1/listbox.cpp b/src/gtk1/listbox.cpp index 138fc38d96..e0fa8aca7e 100644 --- a/src/gtk1/listbox.cpp +++ b/src/gtk1/listbox.cpp @@ -29,6 +29,13 @@ #include "gdk/gdk.h" #include "gtk/gtk.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //------------------------------------------------------------------------- // conditional compilation //------------------------------------------------------------------------- @@ -63,6 +70,8 @@ extern bool g_blockEventsOnScroll; static gint gtk_listbox_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxListBox *listbox ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (g_blockEventsOnDrag) return FALSE; if (g_blockEventsOnScroll) return FALSE; @@ -116,6 +125,8 @@ gtk_listbox_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, static gint gtk_listbox_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxListBox *listbox ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (g_blockEventsOnDrag) return FALSE; if (!listbox->HasVMT()) return FALSE; @@ -142,6 +153,8 @@ gtk_listbox_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxLis static void gtk_listitem_select_callback( GtkWidget *WXUNUSED(widget), wxListBox *listbox ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!listbox->HasVMT()) return; if (g_blockEventsOnDrag) return; diff --git a/src/gtk1/mdi.cpp b/src/gtk1/mdi.cpp index 85eb0270c7..064376b54c 100644 --- a/src/gtk1/mdi.cpp +++ b/src/gtk1/mdi.cpp @@ -27,6 +27,13 @@ const int wxMENU_HEIGHT = 27; +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // globals //----------------------------------------------------------------------------- @@ -314,6 +321,8 @@ void wxMDIChildFrame::OnActivate( wxActivateEvent &WXUNUSED(event) ) static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if ((win->m_x == alloc->x) && (win->m_y == alloc->y) && (win->m_width == alloc->width) && diff --git a/src/gtk1/menu.cpp b/src/gtk1/menu.cpp index dd3d6850bf..5e6b4c8b03 100644 --- a/src/gtk1/menu.cpp +++ b/src/gtk1/menu.cpp @@ -20,6 +20,13 @@ #include "gdk/gdk.h" #include "gtk/gtk.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // wxMenuBar //----------------------------------------------------------------------------- @@ -343,6 +350,8 @@ wxString wxMenuBar::GetHelpString( int id ) const static void gtk_menu_clicked_callback( GtkWidget *widget, wxMenu *menu ) { + if (g_isIdle) wxapp_install_idle_handler(); + int id = menu->FindMenuIdByMenuItem(widget); /* should find it for normal (not popup) menu */ @@ -392,6 +401,8 @@ static void gtk_menu_clicked_callback( GtkWidget *widget, wxMenu *menu ) static void gtk_menu_hilight_callback( GtkWidget *widget, wxMenu *menu ) { + if (g_isIdle) wxapp_install_idle_handler(); + int id = menu->FindMenuIdByMenuItem(widget); wxASSERT( id != -1 ); // should find it! @@ -424,6 +435,8 @@ static void gtk_menu_hilight_callback( GtkWidget *widget, wxMenu *menu ) static void gtk_menu_nolight_callback( GtkWidget *widget, wxMenu *menu ) { + if (g_isIdle) wxapp_install_idle_handler(); + int id = menu->FindMenuIdByMenuItem(widget); wxASSERT( id != -1 ); // should find it! diff --git a/src/gtk1/minifram.cpp b/src/gtk1/minifram.cpp index ea6f98fe1a..9b0c1f0309 100644 --- a/src/gtk1/minifram.cpp +++ b/src/gtk1/minifram.cpp @@ -21,6 +21,13 @@ #include "gdk/gdkprivate.h" #include "gdk/gdkx.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -56,6 +63,8 @@ static void DrawFrame( GtkWidget *widget, int x, int y, int w, int h ) static void gtk_window_own_expose_callback( GtkWidget *widget, GdkEventExpose *gdk_event, wxFrame *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return; if (gdk_event->count > 0) return; @@ -73,6 +82,8 @@ static void gtk_window_own_expose_callback( GtkWidget *widget, GdkEventExpose *g static void gtk_window_own_draw_callback( GtkWidget *widget, GdkRectangle *WXUNUSED(rect), wxFrame *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return; gtk_draw_shadow( widget->style, @@ -89,6 +100,8 @@ static void gtk_window_own_draw_callback( GtkWidget *widget, GdkRectangle *WXUNU static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxMiniFrame *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return TRUE; if (g_blockEventsOnScroll) return TRUE; @@ -124,6 +137,8 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxMiniFrame *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return TRUE; if (g_blockEventsOnScroll) return TRUE; @@ -155,6 +170,8 @@ static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButto static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion *gdk_event, wxMiniFrame *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return TRUE; if (g_blockEventsOnScroll) return TRUE; @@ -186,6 +203,8 @@ static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion static void gtk_button_clicked_callback( GtkWidget *WXUNUSED(widget), wxMiniFrame *mf ) { + if (g_isIdle) wxapp_install_idle_handler(); + mf->Close(); } diff --git a/src/gtk1/notebook.cpp b/src/gtk1/notebook.cpp index a7b6bd091d..a690de0dea 100644 --- a/src/gtk1/notebook.cpp +++ b/src/gtk1/notebook.cpp @@ -23,6 +23,13 @@ #include "wx/gtk/win_gtk.h" #include "gdk/gdkkeysyms.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -86,6 +93,8 @@ static void gtk_notebook_page_change_callback(GtkNotebook *WXUNUSED(widget), gint nPage, gpointer data) { + if (g_isIdle) wxapp_install_idle_handler(); + wxNotebook *notebook = (wxNotebook *)data; int old = notebook->GetSelection(); @@ -104,6 +113,8 @@ static void gtk_notebook_page_change_callback(GtkNotebook *WXUNUSED(widget), static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if ((win->m_x == alloc->x) && (win->m_y == alloc->y) && (win->m_width == alloc->width) && @@ -124,6 +135,8 @@ static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* static gint gtk_notebook_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxNotebook *notebook ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (g_blockEventsOnDrag) return FALSE; if (!notebook->HasVMT()) return FALSE; diff --git a/src/gtk1/radiobox.cpp b/src/gtk1/radiobox.cpp index 1f60b251b0..e9ba1e8c5e 100644 --- a/src/gtk1/radiobox.cpp +++ b/src/gtk1/radiobox.cpp @@ -19,6 +19,13 @@ #include "gtk/gtk.h" #include "wx/gtk/win_gtk.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -31,6 +38,8 @@ extern bool g_blockEventsOnDrag; static void gtk_radiobutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxRadioBox *rb ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!rb->HasVMT()) return; if (g_blockEventsOnDrag) return; diff --git a/src/gtk1/radiobut.cpp b/src/gtk1/radiobut.cpp index 8b93df7380..9ab2906909 100644 --- a/src/gtk1/radiobut.cpp +++ b/src/gtk1/radiobut.cpp @@ -16,6 +16,13 @@ #include "gdk/gdk.h" #include "gtk/gtk.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -29,6 +36,8 @@ extern bool g_blockEventsOnDrag; static void gtk_radiobutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxRadioButton *rb ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!rb->HasVMT()) return; if (rb->m_blockFirstEvent) diff --git a/src/gtk1/scrolbar.cpp b/src/gtk1/scrolbar.cpp index 39aba4ce46..5c9ddc9eb5 100644 --- a/src/gtk1/scrolbar.cpp +++ b/src/gtk1/scrolbar.cpp @@ -19,6 +19,13 @@ #include "gdk/gdk.h" #include "gtk/gtk.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -32,6 +39,8 @@ extern bool g_blockEventsOnScroll; static void gtk_scrollbar_callback( GtkWidget *WXUNUSED(widget), wxScrollBar *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return; if (g_blockEventsOnDrag) return; @@ -83,10 +92,12 @@ static gint gtk_scrollbar_button_press_callback( GtkRange *WXUNUSED(widget), GdkEventButton *WXUNUSED(gdk_event), wxScrollBar *win ) { - win->m_isScrolling = TRUE; + if (g_isIdle) wxapp_install_idle_handler(); + + win->m_isScrolling = TRUE; // g_blockEventsOnScroll = TRUE; doesn't work in DialogEd - return FALSE; + return FALSE; } //----------------------------------------------------------------------------- @@ -97,6 +108,8 @@ static gint gtk_scrollbar_button_release_callback( GtkRange *WXUNUSED(widget), GdkEventButton *WXUNUSED(gdk_event), wxScrollBar *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + win->m_isScrolling = FALSE; // g_blockEventsOnScroll = FALSE; diff --git a/src/gtk1/slider.cpp b/src/gtk1/slider.cpp index a9a4e9a7d3..3c7c1ade23 100644 --- a/src/gtk1/slider.cpp +++ b/src/gtk1/slider.cpp @@ -18,6 +18,13 @@ #include "gdk/gdk.h" #include "gtk/gtk.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -30,6 +37,8 @@ extern bool g_blockEventsOnDrag; static void gtk_slider_callback( GtkWidget *WXUNUSED(widget), wxSlider *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return; if (g_blockEventsOnDrag) return; diff --git a/src/gtk1/spinbutt.cpp b/src/gtk1/spinbutt.cpp index afbd61ee1e..73f6493e81 100644 --- a/src/gtk1/spinbutt.cpp +++ b/src/gtk1/spinbutt.cpp @@ -19,6 +19,13 @@ #include "gdk/gdk.h" #include "gtk/gtk.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -33,6 +40,8 @@ static const float sensitivity = 0.2; static void gtk_spinbutt_callback( GtkWidget *WXUNUSED(widget), wxSpinButton *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return; if (g_blockEventsOnDrag) return; diff --git a/src/gtk1/tbargtk.cpp b/src/gtk1/tbargtk.cpp index dfc1d7b631..46ca5bad1f 100644 --- a/src/gtk1/tbargtk.cpp +++ b/src/gtk1/tbargtk.cpp @@ -18,6 +18,13 @@ #include "gdk/gdk.h" #include "gtk/gtk.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -30,6 +37,8 @@ extern bool g_blockEventsOnDrag; static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget), wxToolBarTool *tool ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (g_blockEventsOnDrag) return; if (!tool->m_enabled) return; @@ -45,6 +54,8 @@ static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget), wxToolBarTool *to static gint gtk_toolbar_enter_callback( GtkWidget *WXUNUSED(widget), GdkEventCrossing *WXUNUSED(gdk_event), wxToolBarTool *tool ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (g_blockEventsOnDrag) return TRUE; /* we grey-out the tip text of disabled tool */ diff --git a/src/gtk1/textctrl.cpp b/src/gtk1/textctrl.cpp index bdbc8e279f..eab7ee1db8 100644 --- a/src/gtk1/textctrl.cpp +++ b/src/gtk1/textctrl.cpp @@ -24,6 +24,13 @@ #include "gtk/gtk.h" #include "gdk/gdkkeysyms.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -37,6 +44,8 @@ extern bool g_blockEventsOnDrag; static void gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->m_hasVMT) return; win->SetModified(); @@ -54,6 +63,8 @@ gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win ) static void gtk_scrollbar_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->m_hasVMT) return; win->CalculateScrollbar(); diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index 6310487a74..c1a81398db 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -128,6 +128,7 @@ extern wxList wxPendingDelete; extern bool g_blockEventsOnDrag; extern bool g_blockEventsOnScroll; +extern bool g_isIdle; static bool g_capturing = FALSE; static wxWindow *g_focusWindow = (wxWindow*) NULL; @@ -135,6 +136,13 @@ static wxWindow *g_focusWindow = (wxWindow*) NULL; the last click here */ static guint32 gs_timeLastClick = 0; +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + #if (GTK_MINOR_VERSION > 0) //----------------------------------------------------------------------------- @@ -231,6 +239,8 @@ static void gtk_window_own_draw_callback( GtkWidget *widget, GdkRectangle *WXUNU static void gtk_window_expose_callback( GtkWidget *WXUNUSED(widget), GdkEventExpose *gdk_event, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return; win->m_updateRegion.Union( gdk_event->area.x, @@ -260,6 +270,8 @@ static void gtk_window_expose_callback( GtkWidget *WXUNUSED(widget), GdkEventExp static void gtk_window_draw_callback( GtkWidget *WXUNUSED(widget), GdkRectangle *rect, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return; win->m_updateRegion.Union( rect->x, rect->y, rect->width, rect->height ); @@ -277,6 +289,8 @@ static void gtk_window_draw_callback( GtkWidget *WXUNUSED(widget), GdkRectangle static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return FALSE; @@ -456,6 +470,8 @@ static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_e static gint gtk_window_key_release_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return FALSE; @@ -572,6 +588,8 @@ static gint gtk_window_key_release_callback( GtkWidget *widget, GdkEventKey *gdk static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + /* wxPrintf( _T("1) OnButtonPress from ") ); if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) @@ -734,6 +752,8 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return FALSE; if (g_blockEventsOnScroll) return FALSE; @@ -838,6 +858,8 @@ static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButto static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion *gdk_event, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return FALSE; if (g_blockEventsOnScroll) return FALSE; @@ -945,6 +967,8 @@ static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion static gint gtk_window_focus_in_callback( GtkWidget *widget, GdkEvent *WXUNUSED(event), wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return FALSE; @@ -992,6 +1016,8 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget, GdkEvent *WXUNUSED( static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED(event), wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return FALSE; @@ -1028,6 +1054,8 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return FALSE; @@ -1078,6 +1106,8 @@ static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_ static gint gtk_window_leave_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return FALSE; @@ -1128,6 +1158,8 @@ static gint gtk_window_leave_callback( GtkWidget *widget, GdkEventCrossing *gdk_ static void gtk_window_vscroll_callback( GtkWidget *WXUNUSED(widget), wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (g_blockEventsOnDrag) return; /* @@ -1176,6 +1208,8 @@ static void gtk_window_vscroll_callback( GtkWidget *WXUNUSED(widget), wxWindow * static void gtk_window_hscroll_callback( GtkWidget *WXUNUSED(widget), wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (g_blockEventsOnDrag) return; /* @@ -1224,6 +1258,8 @@ static void gtk_window_hscroll_callback( GtkWidget *WXUNUSED(widget), wxWindow * static void gtk_window_vscroll_change_callback( GtkWidget *WXUNUSED(widget), wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (g_blockEventsOnDrag) return; /* @@ -1249,6 +1285,8 @@ static void gtk_window_vscroll_change_callback( GtkWidget *WXUNUSED(widget), wxW static void gtk_window_hscroll_change_callback( GtkWidget *WXUNUSED(widget), wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (g_blockEventsOnDrag) return; /* @@ -1276,6 +1314,8 @@ static gint gtk_scrollbar_button_press_callback( GtkRange *WXUNUSED(widget), GdkEventButton *WXUNUSED(gdk_event), wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + // don't test here as we can release the mouse while being over // a different window then the slider // @@ -1295,6 +1335,7 @@ static gint gtk_scrollbar_button_release_callback( GtkRange *widget, GdkEventButton *WXUNUSED(gdk_event), wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); // don't test here as we can release the mouse while being over // a different window then the slider @@ -1324,6 +1365,8 @@ static gint gtk_scrollbar_button_release_callback( GtkRange *widget, static gint gtk_window_realized_callback( GtkWidget *widget, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (win->m_font != *wxSWISS_FONT) { wxFont font( win->m_font ); -- 2.45.2