Use the same "changed" GTK callback for wxComboBox and wxTextCtrl
And reuse EnableTextChangedEvents() between these classes as well. No real changes so far, this is just a refactoring to centralize the code in a single place before modifying it.
This commit is contained in:
@@ -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();
|
||||
|
||||
|
@@ -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<void *>(m_buffer)
|
||||
: static_cast<void *>(m_text);
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
|
@@ -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 )
|
||||
|
@@ -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",
|
||||
|
Reference in New Issue
Block a user