Suppress a wxWidgets event at specific point to prevent mutual handling
I have a WxWidget Panel with two TextControls for user input. One TextControl input changes the value of the other input field. I used an EVT_COMMAND_TEXT_UPDATE event and bound it to a function like "OnValueChanged" ...
mTextCtrl1->Connect(wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler(MyClass::OnTextCtrlChanged1), NULL, this);
mTextCtrl2->Connect(wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler(MyClass::OnTextCtrlChanged2), NULL,开发者_高级运维 this);
void MyClass::OnTextCtrlChanged1(wxCommandEvent &event) {
// ...
mTextCtrl2->SetValue(...); // Set a Hex value of entered Value in text ctrl 1
}
void MyClass::OnTextCtrlChanged2(wxCommandEvent &event) {
// ...
mTextCtrl1->SetValue(...); // Set a Integer value of entered Value in text ctrl 2
// at this point, MyClass::OnTextCtrl1 is handled,
// but should not, only if user himself enters something
}
Problem is, when Text in one TextControl is changed, it changes the value of the other correctly. But, as soon as text is changed in other input, it rises its own TEXT_UPDATE event and updates the current users inputs, resulting in funny curser jumping etc.
Is it possible to provide the execution of these events while changing the value of the other TextControl, so that it does not rise its TEXT_UPDATE event? If the user makes some input for himself to this text control, it should work as usual.
Maybe you can use wxTextCtrl::ChangeValue
virtual void ChangeValue(const wxString& value)
Sets the text value and marks the control as not-modified (which means that
IsModified
would return false immediately after the call toSetValue
).Note that this function will not generate the
wxEVT_COMMAND_TEXT_UPDATED
event. This is the only difference withSetValue
. See this topic for more information.
精彩评论