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.
This commit is contained in:
Vadim Zeitlin
2019-07-08 15:58:12 +02:00
parent c75067f0b4
commit c024944d78
3 changed files with 20 additions and 7 deletions

View File

@@ -142,6 +142,8 @@ public:
static wxVisualAttributes static wxVisualAttributes
GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
void GTKOnTextChanged() wxOVERRIDE;
protected: protected:
// overridden wxWindow virtual methods // overridden wxWindow virtual methods
virtual wxSize DoGetBestSize() const wxOVERRIDE; virtual wxSize DoGetBestSize() const wxOVERRIDE;

View File

@@ -62,6 +62,12 @@ public:
bool GTKEntryOnInsertText(const char* text); bool GTKEntryOnInsertText(const char* text);
bool GTKIsUpperCase() const { return m_isUpperCase; } 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: protected:
// This method must be called from the derived class Create() to connect // This method must be called from the derived class Create() to connect
// the handlers for the clipboard (cut/copy/paste) events. // the handlers for the clipboard (cut/copy/paste) events.

View File

@@ -575,13 +575,7 @@ extern "C" {
static void static void
gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win ) gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win )
{ {
if ( win->IgnoreTextUpdate() ) win->GTKOnTextChanged();
return;
if ( win->MarkDirtyOnChange() )
win->MarkDirty();
win->SendTextUpdatedEvent();
} }
} }
@@ -1371,6 +1365,17 @@ void wxTextCtrl::DiscardEdits()
m_modified = false; m_modified = false;
} }
void wxTextCtrl::GTKOnTextChanged()
{
if ( IgnoreTextUpdate() )
return;
if ( MarkDirtyOnChange() )
MarkDirty();
SendTextUpdatedEvent();
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// event handling // event handling
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------