2010-03-06 15:09:23 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: uiaction.cpp
|
|
|
|
// Purpose: wxUIActionSimulator sample
|
|
|
|
// Author: Kevin Ollivier
|
|
|
|
// Modified by:
|
|
|
|
// Created: 04/01/98
|
|
|
|
// RCS-ID: $Id$
|
2010-08-22 18:15:42 -04:00
|
|
|
// Copyright: (c) Kevin Ollivier, Steven Lamerton
|
2010-03-06 15:09:23 -05:00
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// declarations
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
2010-08-22 18:15:42 -04:00
|
|
|
|
2010-03-06 15:09:23 -05:00
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
2010-08-22 18:15:42 -04:00
|
|
|
|
2010-03-06 15:09:23 -05:00
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// for all others, include the necessary headers (this file is usually all you
|
|
|
|
// need because it includes almost all "standard" wxWidgets headers)
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
2010-03-22 18:56:22 -04:00
|
|
|
#if wxUSE_UIACTIONSIMULATOR
|
|
|
|
#include "wx/uiaction.h"
|
|
|
|
#endif
|
2010-03-06 15:09:23 -05:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// resources
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// the application icon (under Windows and OS/2 it is in resources and even
|
|
|
|
// though we could still include the XPM here it would be unused)
|
|
|
|
#if !defined(__WXMSW__) && !defined(__WXPM__)
|
|
|
|
#include "../sample.xpm"
|
|
|
|
#endif
|
|
|
|
|
2010-03-13 16:58:04 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// IDs for the controls and the menu commands
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
// menu items
|
2010-08-22 18:15:42 -04:00
|
|
|
RunSimulation = 1
|
2010-03-13 16:58:04 -05:00
|
|
|
};
|
|
|
|
|
2010-03-06 15:09:23 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// private classes
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Define a new application type, each program should derive a class from wxApp
|
|
|
|
class MyApp : public wxApp
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual bool OnInit();
|
|
|
|
};
|
|
|
|
|
2010-03-22 18:56:22 -04:00
|
|
|
#if wxUSE_UIACTIONSIMULATOR
|
|
|
|
|
2010-03-06 15:09:23 -05:00
|
|
|
// Define a new frame type: this is going to be our main frame
|
|
|
|
class MyFrame : public wxFrame
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// ctor(s)
|
|
|
|
MyFrame(const wxString& title);
|
|
|
|
|
2010-08-22 18:15:42 -04:00
|
|
|
void OnButtonPressed(wxCommandEvent& event);
|
|
|
|
void OnRunSimulation(wxCommandEvent& event);
|
|
|
|
void OnExit(wxCommandEvent& WXUNUSED(event)) { Close(); }
|
|
|
|
|
2010-03-06 15:09:23 -05:00
|
|
|
private:
|
2010-08-22 18:15:42 -04:00
|
|
|
wxButton* m_button;
|
|
|
|
wxTextCtrl* m_text;
|
2010-03-06 15:09:23 -05:00
|
|
|
|
2010-03-13 16:58:04 -05:00
|
|
|
DECLARE_EVENT_TABLE()
|
2010-03-06 15:09:23 -05:00
|
|
|
};
|
|
|
|
|
2010-03-13 16:58:04 -05:00
|
|
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
2010-08-22 18:15:42 -04:00
|
|
|
EVT_BUTTON(wxID_ANY, MyFrame::OnButtonPressed)
|
2010-03-13 16:58:04 -05:00
|
|
|
EVT_MENU(RunSimulation, MyFrame::OnRunSimulation)
|
2010-08-22 18:15:42 -04:00
|
|
|
EVT_MENU(wxID_EXIT, MyFrame::OnExit)
|
2010-03-13 16:58:04 -05:00
|
|
|
END_EVENT_TABLE()
|
2010-03-06 15:09:23 -05:00
|
|
|
|
2010-03-22 18:56:22 -04:00
|
|
|
#endif // wxUSE_UIACTIONSIMULATOR
|
|
|
|
|
2010-03-06 15:09:23 -05:00
|
|
|
// ============================================================================
|
|
|
|
// implementation
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// the application class
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2010-03-13 16:58:04 -05:00
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
2010-03-06 15:09:23 -05:00
|
|
|
bool MyApp::OnInit()
|
|
|
|
{
|
|
|
|
if ( !wxApp::OnInit() )
|
|
|
|
return false;
|
|
|
|
|
2010-03-22 18:56:22 -04:00
|
|
|
#if wxUSE_UIACTIONSIMULATOR
|
2010-03-06 15:09:23 -05:00
|
|
|
MyFrame *frame = new MyFrame("wxUIActionSimulator sample application");
|
|
|
|
frame->Show(true);
|
2010-08-22 18:15:42 -04:00
|
|
|
|
2010-03-06 15:09:23 -05:00
|
|
|
return true;
|
2010-03-22 18:56:22 -04:00
|
|
|
#else // !wxUSE_UIACTIONSIMULATOR
|
|
|
|
wxLogError("wxUSE_UIACTIONSIMULATOR must be 1 for this sample");
|
|
|
|
return false;
|
|
|
|
#endif // wxUSE_UIACTIONSIMULATOR/!wxUSE_UIACTIONSIMULATOR
|
2010-03-06 15:09:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// main frame
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2010-03-22 18:56:22 -04:00
|
|
|
#if wxUSE_UIACTIONSIMULATOR
|
|
|
|
|
2010-03-06 15:09:23 -05:00
|
|
|
// frame constructor
|
|
|
|
MyFrame::MyFrame(const wxString& title)
|
|
|
|
: wxFrame(NULL, wxID_ANY, title)
|
|
|
|
{
|
|
|
|
SetIcon(wxICON(sample));
|
|
|
|
|
|
|
|
#if wxUSE_MENUS
|
|
|
|
// create a menu bar
|
|
|
|
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(wxID_EXIT, "E&xit\tAlt-X", "Quit this program");
|
|
|
|
|
|
|
|
wxMenuBar *menuBar = new wxMenuBar();
|
|
|
|
menuBar->Append(fileMenu, "&File");
|
|
|
|
|
|
|
|
SetMenuBar(menuBar);
|
|
|
|
#endif // wxUSE_MENUS
|
|
|
|
|
2010-08-22 18:15:42 -04:00
|
|
|
wxPanel *panel = new wxPanel(this);
|
|
|
|
|
|
|
|
wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
panel->SetSizer(sizer);
|
|
|
|
|
|
|
|
m_button = new wxButton(panel, wxID_ANY, "&Button");
|
|
|
|
sizer->Add(m_button, wxSizerFlags().Centre().Border());
|
|
|
|
|
|
|
|
m_text = new wxTextCtrl(panel, wxID_ANY, "",
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxTE_MULTILINE);
|
|
|
|
sizer->Add(m_text, wxSizerFlags(1).Expand().Border());
|
2010-03-06 15:09:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// event handlers
|
|
|
|
|
2010-08-22 18:15:42 -04:00
|
|
|
void MyFrame::OnRunSimulation(wxCommandEvent& WXUNUSED(event))
|
2010-03-06 15:09:23 -05:00
|
|
|
{
|
|
|
|
wxUIActionSimulator sim;
|
2010-08-22 18:15:42 -04:00
|
|
|
|
|
|
|
// Add some extra distance to take account of window decorations
|
|
|
|
sim.MouseMove(m_button->GetScreenPosition() + wxPoint(10, 10));
|
2010-03-06 15:09:23 -05:00
|
|
|
sim.MouseClick(wxMOUSE_BTN_LEFT);
|
2010-08-22 18:15:42 -04:00
|
|
|
|
|
|
|
// Process the resulting button event
|
2010-03-06 15:09:23 -05:00
|
|
|
wxYield();
|
2010-08-22 18:15:42 -04:00
|
|
|
|
|
|
|
m_text->SetFocus();
|
|
|
|
sim.Char('A');
|
|
|
|
sim.Char('A', wxMOD_SHIFT);
|
|
|
|
sim.Char(WXK_RETURN);
|
|
|
|
sim.Char('Z');
|
|
|
|
sim.Char('Z', wxMOD_SHIFT);
|
|
|
|
sim.Char(WXK_RETURN);
|
|
|
|
sim.Text("aAbBcC");
|
|
|
|
sim.Char(WXK_RETURN);
|
2010-03-06 15:09:23 -05:00
|
|
|
}
|
|
|
|
|
2010-08-22 18:15:42 -04:00
|
|
|
void MyFrame::OnButtonPressed(wxCommandEvent& WXUNUSED(event))
|
2010-03-06 15:09:23 -05:00
|
|
|
{
|
2010-08-22 18:15:42 -04:00
|
|
|
m_text->AppendText("Button pressed.\n");
|
2010-03-06 15:09:23 -05:00
|
|
|
}
|
2010-03-22 07:40:35 -04:00
|
|
|
|
|
|
|
#endif // wxUSE_UIACTIONSIMULATOR
|