Coalesce wxEVT_TEXT events in wxGTK wxTextCtrl and wxComboBox

For consistency with the other platforms, coalesce multiple wxEVT_TEXT
events resulting from a single user action into a single one in wxGTK
too. For example, when pressing a key in a control with some text
selected, wxGTK previously generated 2 wxEVT_TEXT events: one
corresponding to the removal of the selection and another one to the
addition of the new text. Now only a single event with the new text is
generated, as in the other ports.

Doing this requires delaying sending wxEVT_TEXT until GTK itself ends
handling the key press, however we delay it as little as possible, so
hopefully this shouldn't have any visible effects at wx API level.

Closes #10050.
This commit is contained in:
Vadim Zeitlin
2019-07-10 02:14:21 +02:00
parent 958df5fb74
commit 2c6dcc2e51
3 changed files with 141 additions and 2 deletions

View File

@@ -15,6 +15,7 @@ typedef struct _GtkEditable GtkEditable;
typedef struct _GtkEntry GtkEntry;
class wxTextAutoCompleteData; // private class used only by wxTextEntry itself
class wxTextCoalesceData; // another private class
// ----------------------------------------------------------------------------
// wxTextEntry: roughly corresponds to GtkEditable
@@ -62,12 +63,16 @@ public:
bool GTKEntryOnInsertText(const char* text);
bool GTKIsUpperCase() const { return m_isUpperCase; }
// Called from "changed" signal handler for GtkEntry.
// Called from "changed" signal handler (or, possibly, slightly later, when
// coalescing several "changed" signals into a single event) for GtkEntry.
//
// By default just generates a wxEVT_TEXT, but overridden to do more things
// in wxTextCtrl.
virtual void GTKOnTextChanged() { SendTextUpdatedEvent(); }
// Helper functions only used internally.
wxTextCoalesceData* GTKGetCoalesceData() const { return m_coalesceData; }
protected:
// This method must be called from the derived class Create() to connect
// the handlers for the clipboard (cut/copy/paste) events.
@@ -95,6 +100,12 @@ protected:
// GtkEntry IM context.
int GTKEntryIMFilterKeypress(GdkEventKey* event) const;
// If GTKEntryIMFilterKeypress() is not called (as multiline wxTextCtrl
// uses its own IM), call this method instead to still notify wxTextEntry
// about the key press events in the given widget.
void GTKEntryOnKeypress(GtkWidget* widget) const;
static int GTKGetEntryTextLength(GtkEntry* entry);
// Block/unblock the corresponding GTK signal.
@@ -124,6 +135,10 @@ private:
// It needs to call our GetEntry() method.
friend class wxTextAutoCompleteData;
// Data used for coalescing "changed" events resulting from a single user
// action.
mutable wxTextCoalesceData* m_coalesceData;
bool m_isUpperCase;
};