From 813a15c8932edd551dd074a26ca224ae34835452 Mon Sep 17 00:00:00 2001 From: ali kettab Date: Wed, 18 Mar 2026 15:04:59 +0100 Subject: [PATCH] wxQt: Fix memory leak of wxTextAutoCompleteData Delete wxTextEntry member pointer which was forgotten in 602f4f3 (2025-02-08, wxQt: Add auto-completion support to wxTextEntry). Note that some code had to be moved to make full declaration of wxTextAutoCompleteData available to wxTextEntry destructor, this commit is best viewed using Git --color-moved option. Closes #26283. Closes #26310. --- include/wx/qt/textentry.h | 1 + src/qt/textentry.cpp | 236 ++++++++++++++++++++------------------ 2 files changed, 124 insertions(+), 113 deletions(-) diff --git a/include/wx/qt/textentry.h b/include/wx/qt/textentry.h index 23b8a54e92..35856ff7a8 100644 --- a/include/wx/qt/textentry.h +++ b/include/wx/qt/textentry.h @@ -14,6 +14,7 @@ class WXDLLIMPEXP_CORE wxTextEntry : public wxTextEntryBase { public: wxTextEntry(); + ~wxTextEntry(); virtual void WriteText(const wxString& text) override; diff --git a/src/qt/textentry.cpp b/src/qt/textentry.cpp index 32d9c5e449..9574b456b4 100644 --- a/src/qt/textentry.cpp +++ b/src/qt/textentry.cpp @@ -21,119 +21,6 @@ #include #include -wxTextEntry::wxTextEntry() -{ -} - -void wxTextEntry::WriteText(const wxString& WXUNUSED(text)) -{ -} - -void wxTextEntry::Remove(long from, long to) -{ - const long insertionPoint = GetInsertionPoint(); - wxString string = GetValue(); - string.erase(from, to - from); - SetValue(string); - SetInsertionPoint( std::min(insertionPoint, static_cast(string.length())) ); -} - -void wxTextEntry::Copy() -{ -} - -void wxTextEntry::Cut() -{ -} - -void wxTextEntry::Paste() -{ -} - -void wxTextEntry::Undo() -{ -} - -void wxTextEntry::Redo() -{ -} - -bool wxTextEntry::CanUndo() const -{ - return false; -} - -bool wxTextEntry::CanRedo() const -{ - return false; -} - -void wxTextEntry::SetInsertionPoint(long WXUNUSED(pos)) -{ -} - -long wxTextEntry::GetInsertionPoint() const -{ - return 0; -} - -long wxTextEntry::GetLastPosition() const -{ - return GetValue().length(); -} - -void wxTextEntry::SetSelection(long WXUNUSED(from), long WXUNUSED(to)) -{ - wxFAIL_MSG("wxTextEntry::SetSelection should be overridden"); -} - -void wxTextEntry::GetSelection(long *from, long *to) const -{ - // no unified get selection method in Qt (overridden in textctrl & combobox) - // only called if no selection - // If the return values from and to are the same, there is no - // selection. - { - *from = - *to = GetInsertionPoint(); - } -} - -bool wxTextEntry::IsEditable() const -{ - return false; -} - -void wxTextEntry::SetEditable(bool WXUNUSED(editable)) -{ -} - -wxString wxTextEntry::DoGetValue() const -{ - return wxString(); -} - -void wxTextEntry::DoSetValue(const wxString& value, int flags) -{ - wxTextEntryBase::DoSetValue(value, flags); -} - -wxWindow *wxTextEntry::GetEditableWindow() -{ - return nullptr; -} - -void wxTextEntry::EnableTextChangedEvents(bool enable) -{ - wxWindow* const win = GetEditableWindow(); - - if ( win ) - win->GetHandle()->blockSignals(!enable); -} - -// ---------------------------------------------------------------------------- -// auto-completion -// ---------------------------------------------------------------------------- namespace { // This class is taken from Qt documentation "as is" to see "C:\Program Files" @@ -327,6 +214,129 @@ private: wxDECLARE_NO_COPY_CLASS(wxTextAutoCompleteData); }; +// ============================================================================ +// wxTextEntry implementation +// ============================================================================ + +wxTextEntry::wxTextEntry() +{ +} + +wxTextEntry::~wxTextEntry() +{ + delete m_autoCompleteData; +} + +void wxTextEntry::WriteText(const wxString& WXUNUSED(text)) +{ +} + +void wxTextEntry::Remove(long from, long to) +{ + const long insertionPoint = GetInsertionPoint(); + wxString string = GetValue(); + string.erase(from, to - from); + SetValue(string); + SetInsertionPoint( std::min(insertionPoint, static_cast(string.length())) ); +} + +void wxTextEntry::Copy() +{ +} + +void wxTextEntry::Cut() +{ +} + +void wxTextEntry::Paste() +{ +} + +void wxTextEntry::Undo() +{ +} + +void wxTextEntry::Redo() +{ +} + +bool wxTextEntry::CanUndo() const +{ + return false; +} + +bool wxTextEntry::CanRedo() const +{ + return false; +} + +void wxTextEntry::SetInsertionPoint(long WXUNUSED(pos)) +{ +} + +long wxTextEntry::GetInsertionPoint() const +{ + return 0; +} + +long wxTextEntry::GetLastPosition() const +{ + return GetValue().length(); +} + +void wxTextEntry::SetSelection(long WXUNUSED(from), long WXUNUSED(to)) +{ + wxFAIL_MSG("wxTextEntry::SetSelection should be overridden"); +} + +void wxTextEntry::GetSelection(long *from, long *to) const +{ + // no unified get selection method in Qt (overridden in textctrl & combobox) + // only called if no selection + // If the return values from and to are the same, there is no + // selection. + { + *from = + *to = GetInsertionPoint(); + } +} + +bool wxTextEntry::IsEditable() const +{ + return false; +} + +void wxTextEntry::SetEditable(bool WXUNUSED(editable)) +{ +} + +wxString wxTextEntry::DoGetValue() const +{ + return wxString(); +} + +void wxTextEntry::DoSetValue(const wxString& value, int flags) +{ + wxTextEntryBase::DoSetValue(value, flags); +} + +wxWindow *wxTextEntry::GetEditableWindow() +{ + return nullptr; +} + +void wxTextEntry::EnableTextChangedEvents(bool enable) +{ + wxWindow* const win = GetEditableWindow(); + + if ( win ) + win->GetHandle()->blockSignals(!enable); +} + +// ---------------------------------------------------------------------------- +// auto-completion +// ---------------------------------------------------------------------------- + bool wxTextEntry::DoAutoCompleteFileNames(int WXUNUSED(flags)) { if ( m_autoCompleteData )