Add support for digits and +/- sign to wxUIActionSimulator::Text().

Support the characters needed for number entry in wxUIActionSimulator::Text()
too.

Closes #13671.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69762 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2011-11-15 15:56:55 +00:00
parent a496a72d66
commit c0c9009c8d
4 changed files with 52 additions and 6 deletions

View File

@@ -58,8 +58,8 @@ public:
{ return Key(keycode, modifiers, false); } { return Key(keycode, modifiers, false); }
// Higher level methods for generating both the key press and release for a // Higher level methods for generating both the key press and release for a
// single key or for all characters in the ASCII string "text" which can // single key or for all characters in the ASCII string "text" which can currently
// currently contain letters only (no digits, no punctuation). // contain letters, digits and characters for the definition of numbers [+-., ].
bool Char(int keycode, int modifiers = wxMOD_NONE); bool Char(int keycode, int modifiers = wxMOD_NONE);
bool Text(const char *text); bool Text(const char *text);

View File

@@ -148,7 +148,8 @@ public:
/** /**
Emulate typing in the keys representing the given string. Emulate typing in the keys representing the given string.
Currently only the ASCII letters (i.e. characters @c a-z and @c A-Z) Currently only the ASCII letters, digits and characters for the definition
of numbers (i.e. characters @c a-z @c A-Z @c 0-9 @c + @c - @c . @c , @c 'space')
are supported. are supported.
@param text @param text

View File

@@ -184,6 +184,9 @@ void MyFrame::OnRunSimulation(wxCommandEvent& WXUNUSED(event))
sim.Char(WXK_RETURN); sim.Char(WXK_RETURN);
sim.Text("aAbBcC"); sim.Text("aAbBcC");
sim.Char(WXK_RETURN); sim.Char(WXK_RETURN);
sim.Text("1 234.57e-8");
sim.Char(WXK_RETURN);
} }
void MyFrame::OnButtonPressed(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnButtonPressed(wxCommandEvent& WXUNUSED(event))

View File

@@ -80,6 +80,51 @@ void wxUIActionSimulator::SimulateModifiers(int modifiers, bool isDown)
bool wxUIActionSimulator::Char(int keycode, int modifiers) bool wxUIActionSimulator::Char(int keycode, int modifiers)
{ {
switch(keycode)
{
case '0':
keycode = WXK_NUMPAD0;
break;
case '1':
keycode = WXK_NUMPAD1;
break;
case '2':
keycode = WXK_NUMPAD2;
break;
case '3':
keycode = WXK_NUMPAD3;
break;
case '4':
keycode = WXK_NUMPAD4;
break;
case '5':
keycode = WXK_NUMPAD5;
break;
case '6':
keycode = WXK_NUMPAD6;
break;
case '7':
keycode = WXK_NUMPAD7;
break;
case '8':
keycode = WXK_NUMPAD8;
break;
case '9':
keycode = WXK_NUMPAD9;
break;
case '+':
keycode = WXK_NUMPAD_ADD;
break;
case '-':
keycode = WXK_NUMPAD_SUBTRACT;
break;
case '.':
keycode = WXK_NUMPAD_DECIMAL;
break;
default:
break;
};
Key(keycode, modifiers, true); Key(keycode, modifiers, true);
Key(keycode, modifiers, false); Key(keycode, modifiers, false);
@@ -91,9 +136,6 @@ bool wxUIActionSimulator::Text(const char *s)
while ( *s != '\0' ) while ( *s != '\0' )
{ {
const char ch = *s++; const char ch = *s++;
wxASSERT_MSG( ch, "Only letters are allowed" );
if ( !Char(ch, isupper(ch) ? wxMOD_SHIFT : 0) ) if ( !Char(ch, isupper(ch) ? wxMOD_SHIFT : 0) )
return false; return false;
} }