diff --git a/include/wx/gtk/combobox.h b/include/wx/gtk/combobox.h index 880ec67c8e..06da278b1b 100644 --- a/include/wx/gtk/combobox.h +++ b/include/wx/gtk/combobox.h @@ -151,7 +151,6 @@ private: // From wxTextEntry: virtual wxWindow *GetEditableWindow() wxOVERRIDE { return this; } virtual GtkEditable *GetEditable() const wxOVERRIDE; - virtual void EnableTextChangedEvents(bool enable) wxOVERRIDE; void Init(); diff --git a/include/wx/gtk/textctrl.h b/include/wx/gtk/textctrl.h index bf7f2e42a1..b343fc9b1a 100644 --- a/include/wx/gtk/textctrl.h +++ b/include/wx/gtk/textctrl.h @@ -184,7 +184,6 @@ private: // overridden wxTextEntry virtual methods virtual GtkEditable *GetEditable() const wxOVERRIDE; virtual GtkEntry *GetEntry() const wxOVERRIDE; - virtual void EnableTextChangedEvents(bool enable) wxOVERRIDE; // change the font for everything in this control void ChangeFontGlobally(); @@ -198,7 +197,7 @@ private: // returns either m_text or m_buffer depending on whether the control is // single- or multi-line; convenient for the GTK+ functions which work with // both - void *GetTextObject() const + void *GetTextObject() const wxOVERRIDE { return IsMultiLine() ? static_cast(m_buffer) : static_cast(m_text); diff --git a/include/wx/gtk/textentry.h b/include/wx/gtk/textentry.h index 810a4659e0..aad2982d80 100644 --- a/include/wx/gtk/textentry.h +++ b/include/wx/gtk/textentry.h @@ -76,6 +76,10 @@ protected: // And this one to connect "insert-text" signal. void GTKConnectInsertTextSignal(GtkEntry* entry); + // Finally this one connects to the "changed" signal on the object returned + // by GetTextObject(). + void GTKConnectChangedSignal(); + virtual void DoSetValue(const wxString& value, int flags) wxOVERRIDE; virtual wxString DoGetValue() const wxOVERRIDE; @@ -92,6 +96,12 @@ protected: static int GTKGetEntryTextLength(GtkEntry* entry); + // Block/unblock the corresponding GTK signal. + // + // Note that we make it protected in wxGTK as it is called from wxComboBox + // currently. + virtual void EnableTextChangedEvents(bool enable) wxOVERRIDE; + private: // implement this to return the associated GtkEntry or another widget // implementing GtkEditable @@ -100,6 +110,12 @@ private: // implement this to return the associated GtkEntry virtual GtkEntry *GetEntry() const = 0; + // This one exists in order to be overridden by wxTextCtrl which uses + // either GtkEditable or GtkTextBuffer depending on whether it is single- + // or multi-line. + virtual void *GetTextObject() const { return GetEntry(); } + + // Various auto-completion-related stuff, only used if any of AutoComplete() // methods are called. wxTextAutoCompleteData *m_autoCompleteData; diff --git a/src/gtk/combobox.cpp b/src/gtk/combobox.cpp index d0d6ad23c8..47352b8626 100644 --- a/src/gtk/combobox.cpp +++ b/src/gtk/combobox.cpp @@ -27,14 +27,6 @@ // ---------------------------------------------------------------------------- extern "C" { -static void -gtkcombobox_text_changed_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo ) -{ - wxCommandEvent event( wxEVT_TEXT, combo->GetId() ); - event.SetString( combo->GetValue() ); - event.SetEventObject( combo ); - combo->HandleWindowEvent( event ); -} static void gtkcombobox_changed_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo ) @@ -185,9 +177,7 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value, gtk_entry_set_text( entry, wxGTK_CONV(value) ); } - g_signal_connect_after (entry, "changed", - G_CALLBACK (gtkcombobox_text_changed_callback), this); - + GTKConnectChangedSignal(); GTKConnectInsertTextSignal(entry); GTKConnectClipboardSignals(GTK_WIDGET(entry)); } @@ -248,23 +238,6 @@ void wxComboBox::OnChar( wxKeyEvent &event ) event.Skip(); } -void wxComboBox::EnableTextChangedEvents(bool enable) -{ - if ( !GetEntry() ) - return; - - if ( enable ) - { - g_signal_handlers_unblock_by_func(gtk_bin_get_child(GTK_BIN(m_widget)), - (gpointer)gtkcombobox_text_changed_callback, this); - } - else // disable - { - g_signal_handlers_block_by_func(gtk_bin_get_child(GTK_BIN(m_widget)), - (gpointer)gtkcombobox_text_changed_callback, this); - } -} - void wxComboBox::GTKDisableEvents() { EnableTextChangedEvents(false); diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 1406919174..c30726362b 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -567,18 +567,6 @@ gtk_textctrl_populate_popup( GtkEntry *WXUNUSED(entry), GtkMenu *menu, wxTextCtr } } -//----------------------------------------------------------------------------- -// "changed" -//----------------------------------------------------------------------------- - -extern "C" { -static void -gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win ) -{ - win->GTKOnTextChanged(); -} -} - //----------------------------------------------------------------------------- // "mark_set" //----------------------------------------------------------------------------- @@ -768,16 +756,7 @@ bool wxTextCtrl::Create( wxWindow *parent, } // We want to be notified about text changes. - if (multi_line) - { - g_signal_connect (m_buffer, "changed", - G_CALLBACK (gtk_text_changed_callback), this); - } - else - { - g_signal_connect (m_text, "changed", - G_CALLBACK (gtk_text_changed_callback), this); - } + GTKConnectChangedSignal(); // Catch to disable focus out handling g_signal_connect (m_text, "populate_popup", @@ -1380,20 +1359,6 @@ void wxTextCtrl::GTKOnTextChanged() // event handling // ---------------------------------------------------------------------------- -void wxTextCtrl::EnableTextChangedEvents(bool enable) -{ - if ( enable ) - { - g_signal_handlers_unblock_by_func(GetTextObject(), - (gpointer)gtk_text_changed_callback, this); - } - else // disable events - { - g_signal_handlers_block_by_func(GetTextObject(), - (gpointer)gtk_text_changed_callback, this); - } -} - bool wxTextCtrl::IgnoreTextUpdate() { if ( m_countUpdatesToIgnore > 0 ) diff --git a/src/gtk/textentry.cpp b/src/gtk/textentry.cpp index 598d7593a0..850082ec41 100644 --- a/src/gtk/textentry.cpp +++ b/src/gtk/textentry.cpp @@ -57,8 +57,16 @@ static int GetEntryTextLength(GtkEntry* entry) // signal handlers implementation // ============================================================================ -// "insert_text" handler for GtkEntry extern "C" { + +// "changed" handler for GtkEntry +static void +wx_gtk_text_changed_callback(GtkWidget* WXUNUSED(widget), wxTextEntry* entry) +{ + entry->GTKOnTextChanged(); +} + +// "insert_text" handler for GtkEntry static void wx_gtk_insert_text_callback(GtkEditable *editable, const gchar * new_text, @@ -869,6 +877,31 @@ int wxTextEntry::GTKIMFilterKeypress(GdkEventKey* event) const return result; } +// ---------------------------------------------------------------------------- +// signals and events +// ---------------------------------------------------------------------------- + +void wxTextEntry::EnableTextChangedEvents(bool enable) +{ + if ( enable ) + { + g_signal_handlers_unblock_by_func(GetTextObject(), + (gpointer)wx_gtk_text_changed_callback, this); + } + else // disable events + { + g_signal_handlers_block_by_func(GetTextObject(), + (gpointer)wx_gtk_text_changed_callback, this); + } +} + +void wxTextEntry::GTKConnectChangedSignal() +{ + g_signal_connect(GetTextObject(), "changed", + G_CALLBACK(wx_gtk_text_changed_callback), this); + +} + void wxTextEntry::GTKConnectInsertTextSignal(GtkEntry* entry) { g_signal_connect(entry, "insert_text",