[ 1560860 ] wxComboCtrl EVT_TEXT filtering.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41382 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling 2006-09-23 09:04:25 +00:00
parent 25dff19c97
commit ce9685190e
3 changed files with 40 additions and 2 deletions

View File

@ -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)

View File

@ -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();
}

View File

@ -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);
}