From c024944d78e0818b85d45c98b9d5c6f2476c9a57 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 8 Jul 2019 15:58:12 +0200 Subject: [PATCH] Move logic from GTK callback to GTKOnTextChanged() virtual method Check whether we should ignore the event and mark the control as being dirty if necessary in a virtual method, which can be defined in wxTextEntry and overridden by wxTextCtrl, instead of doing it in GTK callback itself. This will allow to reuse wxTextEntry callback for wxTextCtrl too in the upcoming commits. No real changes so far. --- include/wx/gtk/textctrl.h | 2 ++ include/wx/gtk/textentry.h | 6 ++++++ src/gtk/textctrl.cpp | 19 ++++++++++++------- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/include/wx/gtk/textctrl.h b/include/wx/gtk/textctrl.h index d1e4e5ee71..bf7f2e42a1 100644 --- a/include/wx/gtk/textctrl.h +++ b/include/wx/gtk/textctrl.h @@ -142,6 +142,8 @@ public: static wxVisualAttributes GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + void GTKOnTextChanged() wxOVERRIDE; + protected: // overridden wxWindow virtual methods virtual wxSize DoGetBestSize() const wxOVERRIDE; diff --git a/include/wx/gtk/textentry.h b/include/wx/gtk/textentry.h index aaf777a515..810a4659e0 100644 --- a/include/wx/gtk/textentry.h +++ b/include/wx/gtk/textentry.h @@ -62,6 +62,12 @@ public: bool GTKEntryOnInsertText(const char* text); bool GTKIsUpperCase() const { return m_isUpperCase; } + // Called from "changed" signal handler for GtkEntry. + // + // By default just generates a wxEVT_TEXT, but overridden to do more things + // in wxTextCtrl. + virtual void GTKOnTextChanged() { SendTextUpdatedEvent(); } + protected: // This method must be called from the derived class Create() to connect // the handlers for the clipboard (cut/copy/paste) events. diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 54af9c1def..1406919174 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -575,13 +575,7 @@ extern "C" { static void gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win ) { - if ( win->IgnoreTextUpdate() ) - return; - - if ( win->MarkDirtyOnChange() ) - win->MarkDirty(); - - win->SendTextUpdatedEvent(); + win->GTKOnTextChanged(); } } @@ -1371,6 +1365,17 @@ void wxTextCtrl::DiscardEdits() m_modified = false; } +void wxTextCtrl::GTKOnTextChanged() +{ + if ( IgnoreTextUpdate() ) + return; + + if ( MarkDirtyOnChange() ) + MarkDirty(); + + SendTextUpdatedEvent(); +} + // ---------------------------------------------------------------------------- // event handling // ----------------------------------------------------------------------------