Found a compatibility problem of the method of the Autocomplete and events wxEVT_TEXT applicable for the same object wxTextCtrl. The idea is to implement auto-completion of a text field with constant changes in the text array when entering text into this field.
Please tell me how to solve this problem.
Below is the program code that reveals the essence of the problem. The first text box works correctly, as in the autocomplete method is added unchanged text array in the constructor. But with the second test field there was a problem.
Code: Select all
#include <wx/wx.h>
class Window : public wxFrame {
public:
const int ID_TC_CURRECT = 1;
const int ID_TC_UNCURRECT = 2;
wxPanel *panel = new wxPanel(this);
wxBoxSizer *box_vertical = new wxBoxSizer(wxVERTICAL);
wxTextCtrl *tc_currect = new wxTextCtrl(panel, ID_TC_CURRECT);
wxTextCtrl *tc_uncurrect = new wxTextCtrl(panel, ID_TC_UNCURRECT);
wxArrayString *arr = new wxArrayString();
Window (
wxWindow *parent,
wxWindowID id,
const wxString &title,
const wxPoint &pos=wxDefaultPosition,
const wxSize &size=wxDefaultSize,
long style=wxDEFAULT_FRAME_STYLE,
const wxString &name=wxFrameNameStr) :
wxFrame (
parent,
id,
title,
pos,
size,
style,
name
) {
box_vertical->Add(tc_currect);
box_vertical->Add(tc_uncurrect);
panel->SetSizer(box_vertical);
/*Complete for example*/
arr->Add(wxT("111222333"));
arr->Add(wxT("22334455"));
arr->Add(wxT("543"));
arr->Add(wxT("12"));
arr->Add(wxT("23"));
arr->Add(wxT("34422"));
arr->Add(wxT("154"));
tc_currect->AutoComplete(*arr);
Bind(wxEVT_TEXT, m_textprint, this, ID_TC_UNCURRECT);
}
void m_textprint(wxCommandEvent & event);
};
void Window::m_textprint(wxCommandEvent & event) {
/*Here, a string array is formed when the xml document is parsed,
* which is added as an argument for the text field autocomplete method.
* Each time you enter a new letter, the array changes.
* For simple autocomplete method is added to an immutable array.
* Going on the fact that autocomplete is not working properly -
* automatically fills the text box and does not gives you the opportunity to change it.*/
Window::tc_uncurrect->AutoComplete(*(Window::arr));
}
class MyApp : public wxApp
{
public:
virtual bool OnInit();
};
IMPLEMENT_APP(MyApp)
bool MyApp::OnInit()
{
Window *window = new Window(NULL, wxID_ANY, wxT("Simple Window"));
window->Show(true);
return true;
}