diff --git a/include/wx/gtk/textentry.h b/include/wx/gtk/textentry.h index cc69686650..8b47b758e1 100644 --- a/include/wx/gtk/textentry.h +++ b/include/wx/gtk/textentry.h @@ -52,6 +52,7 @@ public: void SendMaxLenEvent(); protected: + virtual void DoSetValue(const wxString& value, int flags); virtual wxString DoGetValue() const; // margins functions diff --git a/src/gtk/textentry.cpp b/src/gtk/textentry.cpp index 70e5e591cf..c1badd3203 100644 --- a/src/gtk/textentry.cpp +++ b/src/gtk/textentry.cpp @@ -110,6 +110,26 @@ void wxTextEntry::WriteText(const wxString& value) gtk_editable_set_position(edit, len); } +void wxTextEntry::DoSetValue(const wxString& value, int flags) +{ + if (value != GetValue()) + { + // use Remove() rather than SelectAll() to avoid unnecessary clipboard + // operations, and prevent triggering an apparent bug in GTK which + // causes the the subsequent WriteText() to append rather than overwrite + { + EventsSuppressor noevents(this); + Remove(0, -1); + } + EventsSuppressor noeventsIf(this, !(flags & SetValue_SendEvent)); + WriteText(value); + } + else if (flags & SetValue_SendEvent) + SendTextUpdatedEvent(GetEditableWindow()); + + SetInsertionPoint(0); +} + wxString wxTextEntry::DoGetValue() const { const wxGtkString value(gtk_editable_get_chars(GetEditable(), 0, -1));