From 1472b2f8efbb7a948459db5d37ac5e495cf1a841 Mon Sep 17 00:00:00 2001 From: Graham Dawes Date: Mon, 4 Feb 2019 09:23:08 +0000 Subject: [PATCH 1/2] Fix crashes with readonly combobox under wxQT --- src/qt/combobox.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/qt/combobox.cpp b/src/qt/combobox.cpp index 73a44dd770..f8d63ca915 100644 --- a/src/qt/combobox.cpp +++ b/src/qt/combobox.cpp @@ -185,7 +185,9 @@ void wxComboBox::SetActualValue(const wxString &value) void wxComboBox::SetValue(const wxString& value) { SetActualValue( value ); - SetInsertionPoint( 0 ); + + if ( !HasFlag(wxCB_READONLY) ) + SetInsertionPoint( 0 ); } void wxComboBox::ChangeValue(const wxString &value) @@ -249,7 +251,9 @@ void wxComboBox::Dismiss() void wxComboBox::Clear() { - wxTextEntry::Clear(); + if ( !HasFlag(wxCB_READONLY) ) + wxTextEntry::Clear(); + wxItemContainer::Clear(); } From a60c2470b5d4706fbb4584d6abd917d89ea599fb Mon Sep 17 00:00:00 2001 From: Graham Dawes Date: Mon, 4 Feb 2019 09:25:55 +0000 Subject: [PATCH 2/2] Dedupe wxCB_READONLY check --- include/wx/qt/combobox.h | 1 + src/qt/combobox.cpp | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/include/wx/qt/combobox.h b/include/wx/qt/combobox.h index bc0222d5cb..c5bce191de 100644 --- a/include/wx/qt/combobox.h +++ b/include/wx/qt/combobox.h @@ -87,6 +87,7 @@ protected: private: void SetActualValue(const wxString& value); + bool IsReadOnly() const; // From wxTextEntry: virtual wxWindow *GetEditableWindow() wxOVERRIDE { return this; } diff --git a/src/qt/combobox.cpp b/src/qt/combobox.cpp index f8d63ca915..9189d068fa 100644 --- a/src/qt/combobox.cpp +++ b/src/qt/combobox.cpp @@ -171,7 +171,7 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, void wxComboBox::SetActualValue(const wxString &value) { - if ( HasFlag(wxCB_READONLY) ) + if ( IsReadOnly() ) { SetStringSelection( value ); } @@ -182,11 +182,16 @@ void wxComboBox::SetActualValue(const wxString &value) } } +bool wxComboBox::IsReadOnly() const +{ + return HasFlag( wxCB_READONLY ); +} + void wxComboBox::SetValue(const wxString& value) { SetActualValue( value ); - if ( !HasFlag(wxCB_READONLY) ) + if ( !IsReadOnly() ) SetInsertionPoint( 0 ); } @@ -251,7 +256,7 @@ void wxComboBox::Dismiss() void wxComboBox::Clear() { - if ( !HasFlag(wxCB_READONLY) ) + if ( !IsReadOnly() ) wxTextEntry::Clear(); wxItemContainer::Clear();