From ce9685190eecd78ce64b7bb5321fdde960800456 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Sat, 23 Sep 2006 09:04:25 +0000 Subject: [PATCH 1/1] [ 1560860 ] wxComboCtrl EVT_TEXT filtering. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41382 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/combo.h | 6 ++++++ src/common/combocmn.cpp | 34 +++++++++++++++++++++++++++++++++- src/generic/odcombo.cpp | 2 +- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/include/wx/combo.h b/include/wx/combo.h index 8d53347408..25dc298df4 100644 --- a/include/wx/combo.h +++ b/include/wx/combo.h @@ -199,6 +199,10 @@ public: // (ie. wxComboPopup::SetStringValue doesn't get called). void SetText(const wxString& value); + // This method sets value and also optionally sends EVT_TEXT + // (needed by combo popups) + void SetValueWithEvent(const wxString& value, bool withEvent = true); + // // Popup customization methods // @@ -522,6 +526,8 @@ protected: private: void Init(); + wxByte m_ignoreEvtText; // Number of next EVT_TEXTs to ignore + DECLARE_EVENT_TABLE() DECLARE_ABSTRACT_CLASS(wxComboCtrlBase) diff --git a/src/common/combocmn.cpp b/src/common/combocmn.cpp index 564ee3cc54..4f6128e776 100644 --- a/src/common/combocmn.cpp +++ b/src/common/combocmn.cpp @@ -638,6 +638,7 @@ void wxComboCtrlBase::Init() m_btnState = 0; m_btnWidDefault = 0; m_blankButtonBg = false; + m_ignoreEvtText = 0; m_btnWid = m_btnHei = -1; m_btnSide = wxRIGHT; m_btnSpacingX = 0; @@ -709,6 +710,14 @@ wxComboCtrlBase::CreateTextCtrl(int style, const wxValidator& validator) if ( HasFlag(wxTE_PROCESS_ENTER) ) style |= wxTE_PROCESS_ENTER; + // Ignore EVT_TEXT generated by the constructor (but only + // if the event redirector already exists) + // NB: This must be " = 1" instead of "++"; + if ( m_textEvtHandler ) + m_ignoreEvtText = 1; + else + m_ignoreEvtText = 0; + m_text = new wxTextCtrl(this, wxID_ANY, m_valueString, wxDefaultPosition, wxDefaultSize, style, validator); @@ -1248,6 +1257,15 @@ wxBitmap& wxComboCtrlBase::GetBufferBitmap( const wxSize& sz ) const void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent& event) { + if ( event.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED ) + { + if ( m_ignoreEvtText > 0 ) + { + m_ignoreEvtText--; + return; + } + } + // Change event id, object and string before relaying it forward event.SetId(GetId()); wxString s = event.GetString(); @@ -1924,10 +1942,13 @@ wxString wxComboCtrlBase::GetValue() const return m_valueString; } -void wxComboCtrlBase::SetValue(const wxString& value) +void wxComboCtrlBase::SetValueWithEvent(const wxString& value, bool withEvent) { if ( m_text ) { + if ( !withEvent ) + m_ignoreEvtText++; + m_text->SetValue(value); if ( !(m_iFlags & wxCC_NO_TEXT_AUTO_SELECT) ) m_text->SelectAll(); @@ -1945,6 +1966,11 @@ void wxComboCtrlBase::SetValue(const wxString& value) } } +void wxComboCtrlBase::SetValue(const wxString& value) +{ + SetValueWithEvent(value, false); +} + // In this SetValue variant wxComboPopup::SetStringValue is not called void wxComboCtrlBase::SetText(const wxString& value) { @@ -1954,6 +1980,12 @@ void wxComboCtrlBase::SetText(const wxString& value) m_valueString = value; + if ( m_text ) + { + m_ignoreEvtText++; + m_text->SetValue( value ); + } + Refresh(); } diff --git a/src/generic/odcombo.cpp b/src/generic/odcombo.cpp index 5f3f732a19..42e12d9e5f 100644 --- a/src/generic/odcombo.cpp +++ b/src/generic/odcombo.cpp @@ -210,7 +210,7 @@ void wxVListBoxComboPopup::DismissWithEvent() m_value = selection; if ( valStr != m_combo->GetValue() ) - m_combo->SetValue(valStr); + m_combo->SetValueWithEvent(valStr); SendComboBoxEvent(selection); } -- 2.45.2