Use '1'..'9' to simulate digits instead of WXK_NUMPADn.

Using WXK_NUMPADn with wxUIActionSimulator doesn't work under Unix, the
resulting GDK events have wrong keyval for some reason.

It would, of course, be nice to fix this but in the meanwhile use ASCII codes
to simulate the digits to at least allow doing this at all.

Also extend uiaction sample to allow testing text simulation.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69960 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2011-12-08 15:55:40 +00:00
parent 64c502e828
commit 1863484b08
2 changed files with 42 additions and 15 deletions

View File

@ -52,7 +52,8 @@
enum
{
// menu items
RunSimulation = 1
RunSimulation = 1,
SimulateText
};
// ----------------------------------------------------------------------------
@ -77,6 +78,7 @@ public:
void OnButtonPressed(wxCommandEvent& event);
void OnRunSimulation(wxCommandEvent& event);
void OnSimulateText(wxCommandEvent& event);
void OnExit(wxCommandEvent& WXUNUSED(event)) { Close(); }
private:
@ -89,6 +91,7 @@ private:
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_BUTTON(wxID_ANY, MyFrame::OnButtonPressed)
EVT_MENU(RunSimulation, MyFrame::OnRunSimulation)
EVT_MENU(SimulateText, MyFrame::OnSimulateText)
EVT_MENU(wxID_EXIT, MyFrame::OnExit)
END_EVENT_TABLE()
@ -137,7 +140,11 @@ MyFrame::MyFrame(const wxString& title)
wxMenu *fileMenu = new wxMenu;
fileMenu->Append(wxID_NEW, "&New File...", "Open a new file");
fileMenu->Append(RunSimulation, "&Run Simulation...", "Run the UI action simulation");
fileMenu->Append(RunSimulation, "&Run Simulation",
"Run predefined UI action simulation");
fileMenu->Append(SimulateText, "Simulate &text input...",
"Enter text to simulate");
fileMenu->AppendSeparator();
fileMenu->Append(wxID_EXIT, "E&xit\tAlt-X", "Quit this program");
@ -189,6 +196,26 @@ void MyFrame::OnRunSimulation(wxCommandEvent& WXUNUSED(event))
}
void MyFrame::OnSimulateText(wxCommandEvent& WXUNUSED(event))
{
static wxString s_text;
const wxString text = wxGetTextFromUser
(
"Enter text to simulate: ",
"wxUIActionSimulator wxWidgets Sample",
s_text,
this
);
if ( text.empty() )
return;
s_text = text;
wxUIActionSimulator sim;
m_text->SetFocus();
sim.Text(s_text);
}
void MyFrame::OnButtonPressed(wxCommandEvent& WXUNUSED(event))
{
m_text->AppendText("Button pressed.\n");

View File

@ -83,43 +83,43 @@ bool wxUIActionSimulator::Char(int keycode, int modifiers)
switch(keycode)
{
case '0':
keycode = WXK_NUMPAD0;
keycode = '0';
break;
case '1':
keycode = WXK_NUMPAD1;
keycode = '1';
break;
case '2':
keycode = WXK_NUMPAD2;
keycode = '2';
break;
case '3':
keycode = WXK_NUMPAD3;
keycode = '3';
break;
case '4':
keycode = WXK_NUMPAD4;
keycode = '4';
break;
case '5':
keycode = WXK_NUMPAD5;
keycode = '5';
break;
case '6':
keycode = WXK_NUMPAD6;
keycode = '6';
break;
case '7':
keycode = WXK_NUMPAD7;
keycode = '7';
break;
case '8':
keycode = WXK_NUMPAD8;
keycode = '8';
break;
case '9':
keycode = WXK_NUMPAD9;
keycode = '9';
break;
case '+':
keycode = WXK_NUMPAD_ADD;
keycode = '+';
break;
case '-':
keycode = WXK_NUMPAD_SUBTRACT;
keycode = '-';
break;
case '.':
keycode = WXK_NUMPAD_DECIMAL;
keycode = '.';
break;
default:
break;