Merge branch 'uisim-xtest'

Make wxUIActionSimulator work with GTK+3, including when using DPI scaling.
This commit is contained in:
Vadim Zeitlin
2016-06-04 22:44:25 +02:00
15 changed files with 705 additions and 100 deletions

View File

@@ -2,9 +2,9 @@
// Name: uiaction.cpp
// Purpose: wxUIActionSimulator sample
// Author: Kevin Ollivier
// Modified by:
// Created: 04/01/98
// Copyright: (c) Kevin Ollivier, Steven Lamerton
// Copyright: (c) 2010 Kevin Ollivier, Steven Lamerton
// (c) 2016 Vadim Zeitlin
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
@@ -33,6 +33,8 @@
#include "wx/uiaction.h"
#endif
#include "wx/stopwatch.h"
// ----------------------------------------------------------------------------
// resources
// ----------------------------------------------------------------------------
@@ -76,6 +78,7 @@ public:
MyFrame(const wxString& title);
void OnButtonPressed(wxCommandEvent& event);
void OnNew(wxCommandEvent& event);
void OnRunSimulation(wxCommandEvent& event);
void OnSimulateText(wxCommandEvent& event);
void OnExit(wxCommandEvent& WXUNUSED(event)) { Close(); }
@@ -89,6 +92,7 @@ private:
wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_BUTTON(wxID_ANY, MyFrame::OnButtonPressed)
EVT_MENU(wxID_NEW, MyFrame::OnNew)
EVT_MENU(RunSimulation, MyFrame::OnRunSimulation)
EVT_MENU(SimulateText, MyFrame::OnSimulateText)
EVT_MENU(wxID_EXIT, MyFrame::OnExit)
@@ -139,9 +143,9 @@ MyFrame::MyFrame(const wxString& title)
wxMenu *fileMenu = new wxMenu;
fileMenu->Append(wxID_NEW, "&New File...", "Open a new file");
fileMenu->Append(RunSimulation, "&Run Simulation",
fileMenu->Append(RunSimulation, "&Run Simulation\tCtrl-R",
"Run predefined UI action simulation");
fileMenu->Append(SimulateText, "Simulate &text input...",
fileMenu->Append(SimulateText, "Simulate &text input...\tCtrl-T",
"Enter text to simulate");
fileMenu->AppendSeparator();
@@ -170,8 +174,25 @@ MyFrame::MyFrame(const wxString& title)
// event handlers
void MyFrame::OnNew(wxCommandEvent& WXUNUSED(event))
{
m_text->AppendText("\"New\" menu item was selected\n");
}
void MyFrame::OnRunSimulation(wxCommandEvent& WXUNUSED(event))
{
m_text->SetValue("=== Starting the simulation "
"(release any pressed keys) ===\n");
// This sleep is needed to give the time for the currently pressed modifier
// keys, if any, to be released. Notice that Control modifier could well be
// pressed if this command was activated from the menu using accelerator
// and keeping it pressed would totally derail the test below, e.g. "A" key
// press would actually become "Ctrl+A" selecting the entire text and so on.
wxMilliSleep(500);
wxStopWatch sw;
wxUIActionSimulator sim;
// Add some extra distance to take account of window decorations
@@ -193,6 +214,15 @@ void MyFrame::OnRunSimulation(wxCommandEvent& WXUNUSED(event))
sim.Text("1 234.57e-8");
sim.Char(WXK_RETURN);
// Process the resulting text events
wxYield();
// Emulate opening a menu from keyboard.
sim.Char('F', wxMOD_ALT);
sim.Char('N');
wxYield();
m_text->AppendText(wxString::Format("\n=== Done in %ldms ===\n", sw.Time()));
}
void MyFrame::OnSimulateText(wxCommandEvent& WXUNUSED(event))