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:
|
// From wxTextEntry:
|
||||||
virtual wxWindow *GetEditableWindow() wxOVERRIDE { return this; }
|
virtual wxWindow *GetEditableWindow() wxOVERRIDE { return this; }
|
||||||
virtual GtkEditable *GetEditable() const wxOVERRIDE;
|
virtual GtkEditable *GetEditable() const wxOVERRIDE;
|
||||||
virtual void EnableTextChangedEvents(bool enable) wxOVERRIDE;
|
|
||||||
|
|
||||||
void Init();
|
void Init();
|
||||||
|
|
||||||
|
@@ -184,7 +184,6 @@ private:
|
|||||||
// overridden wxTextEntry virtual methods
|
// overridden wxTextEntry virtual methods
|
||||||
virtual GtkEditable *GetEditable() const wxOVERRIDE;
|
virtual GtkEditable *GetEditable() const wxOVERRIDE;
|
||||||
virtual GtkEntry *GetEntry() const wxOVERRIDE;
|
virtual GtkEntry *GetEntry() const wxOVERRIDE;
|
||||||
virtual void EnableTextChangedEvents(bool enable) wxOVERRIDE;
|
|
||||||
|
|
||||||
// change the font for everything in this control
|
// change the font for everything in this control
|
||||||
void ChangeFontGlobally();
|
void ChangeFontGlobally();
|
||||||
@@ -198,7 +197,7 @@ private:
|
|||||||
// returns either m_text or m_buffer depending on whether the control is
|
// 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
|
// single- or multi-line; convenient for the GTK+ functions which work with
|
||||||
// both
|
// both
|
||||||
void *GetTextObject() const
|
void *GetTextObject() const wxOVERRIDE
|
||||||
{
|
{
|
||||||
return IsMultiLine() ? static_cast<void *>(m_buffer)
|
return IsMultiLine() ? static_cast<void *>(m_buffer)
|
||||||
: static_cast<void *>(m_text);
|
: static_cast<void *>(m_text);
|
||||||
|
@@ -76,6 +76,10 @@ protected:
|
|||||||
// And this one to connect "insert-text" signal.
|
// And this one to connect "insert-text" signal.
|
||||||
void GTKConnectInsertTextSignal(GtkEntry* entry);
|
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 void DoSetValue(const wxString& value, int flags) wxOVERRIDE;
|
||||||
virtual wxString DoGetValue() const wxOVERRIDE;
|
virtual wxString DoGetValue() const wxOVERRIDE;
|
||||||
@@ -92,6 +96,12 @@ protected:
|
|||||||
|
|
||||||
static int GTKGetEntryTextLength(GtkEntry* entry);
|
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:
|
private:
|
||||||
// implement this to return the associated GtkEntry or another widget
|
// implement this to return the associated GtkEntry or another widget
|
||||||
// implementing GtkEditable
|
// implementing GtkEditable
|
||||||
@@ -100,6 +110,12 @@ private:
|
|||||||
// implement this to return the associated GtkEntry
|
// implement this to return the associated GtkEntry
|
||||||
virtual GtkEntry *GetEntry() const = 0;
|
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()
|
// Various auto-completion-related stuff, only used if any of AutoComplete()
|
||||||
// methods are called.
|
// methods are called.
|
||||||
wxTextAutoCompleteData *m_autoCompleteData;
|
wxTextAutoCompleteData *m_autoCompleteData;
|
||||||
|
@@ -27,14 +27,6 @@
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
extern "C" {
|
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
|
static void
|
||||||
gtkcombobox_changed_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo )
|
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) );
|
gtk_entry_set_text( entry, wxGTK_CONV(value) );
|
||||||
}
|
}
|
||||||
|
|
||||||
g_signal_connect_after (entry, "changed",
|
GTKConnectChangedSignal();
|
||||||
G_CALLBACK (gtkcombobox_text_changed_callback), this);
|
|
||||||
|
|
||||||
GTKConnectInsertTextSignal(entry);
|
GTKConnectInsertTextSignal(entry);
|
||||||
GTKConnectClipboardSignals(GTK_WIDGET(entry));
|
GTKConnectClipboardSignals(GTK_WIDGET(entry));
|
||||||
}
|
}
|
||||||
@@ -248,23 +238,6 @@ void wxComboBox::OnChar( wxKeyEvent &event )
|
|||||||
event.Skip();
|
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()
|
void wxComboBox::GTKDisableEvents()
|
||||||
{
|
{
|
||||||
EnableTextChangedEvents(false);
|
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"
|
// "mark_set"
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -768,16 +756,7 @@ bool wxTextCtrl::Create( wxWindow *parent,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We want to be notified about text changes.
|
// We want to be notified about text changes.
|
||||||
if (multi_line)
|
GTKConnectChangedSignal();
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Catch to disable focus out handling
|
// Catch to disable focus out handling
|
||||||
g_signal_connect (m_text, "populate_popup",
|
g_signal_connect (m_text, "populate_popup",
|
||||||
@@ -1380,20 +1359,6 @@ void wxTextCtrl::GTKOnTextChanged()
|
|||||||
// event handling
|
// 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()
|
bool wxTextCtrl::IgnoreTextUpdate()
|
||||||
{
|
{
|
||||||
if ( m_countUpdatesToIgnore > 0 )
|
if ( m_countUpdatesToIgnore > 0 )
|
||||||
|
@@ -57,8 +57,16 @@ static int GetEntryTextLength(GtkEntry* entry)
|
|||||||
// signal handlers implementation
|
// signal handlers implementation
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
// "insert_text" handler for GtkEntry
|
|
||||||
extern "C" {
|
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
|
static void
|
||||||
wx_gtk_insert_text_callback(GtkEditable *editable,
|
wx_gtk_insert_text_callback(GtkEditable *editable,
|
||||||
const gchar * new_text,
|
const gchar * new_text,
|
||||||
@@ -869,6 +877,31 @@ int wxTextEntry::GTKIMFilterKeypress(GdkEventKey* event) const
|
|||||||
return result;
|
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)
|
void wxTextEntry::GTKConnectInsertTextSignal(GtkEntry* entry)
|
||||||
{
|
{
|
||||||
g_signal_connect(entry, "insert_text",
|
g_signal_connect(entry, "insert_text",
|
||||||
|
Reference in New Issue
Block a user