1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxUIActionSimulator sample
4 // Author: Kevin Ollivier
8 // Copyright: (c) Kevin Ollivier
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
27 // for all others, include the necessary headers (this file is usually all you
28 // need because it includes almost all "standard" wxWidgets headers)
33 #include "wx/uiaction.h"
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 // the application icon (under Windows and OS/2 it is in resources and even
40 // though we could still include the XPM here it would be unused)
41 #if !defined(__WXMSW__) && !defined(__WXPM__)
42 #include "../sample.xpm"
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 // Define a new application type, each program should derive a class from wxApp
50 class MyApp
: public wxApp
53 virtual bool OnInit();
56 // Define a new frame type: this is going to be our main frame
57 class MyFrame
: public wxFrame
61 MyFrame(const wxString
& title
);
63 void OnButtonPressed(wxCommandEvent
&);
64 void OnRunSimulation(wxCommandEvent
&);
66 bool ButtonPressed() const { return m_buttonPressed
; }
67 bool MenuSelected() const { return m_menuSelected
; }
74 // ----------------------------------------------------------------------------
76 // ----------------------------------------------------------------------------
78 // IDs for the controls and the menu commands
83 RunSimulation
= wxID_ANY
88 // ============================================================================
90 // ============================================================================
92 // ----------------------------------------------------------------------------
93 // the application class
94 // ----------------------------------------------------------------------------
98 if ( !wxApp::OnInit() )
101 MyFrame
*frame
= new MyFrame("wxUIActionSimulator sample application");
107 // ----------------------------------------------------------------------------
109 // ----------------------------------------------------------------------------
112 MyFrame::MyFrame(const wxString
& title
)
113 : wxFrame(NULL
, wxID_ANY
, title
)
115 SetIcon(wxICON(sample
));
117 m_buttonPressed
= false;
118 m_menuSelected
= false;
122 wxMenu
*fileMenu
= new wxMenu
;
124 fileMenu
->Append(wxID_NEW
, "&New File...", "Open a new file");
125 fileMenu
->Append(RunSimulation
, "&Run Simulation...", "Run the UI action simulation");
127 fileMenu
->Append(wxID_EXIT
, "E&xit\tAlt-X", "Quit this program");
129 wxMenuBar
*menuBar
= new wxMenuBar();
130 menuBar
->Append(fileMenu
, "&File");
133 #endif // wxUSE_MENUS
135 wxButton
* button
= new wxButton(this, TheButton
, "Button");
136 button
->SetName("TheButton");
137 Bind(wxEVT_COMMAND_BUTTON_CLICKED
, &MyFrame::OnButtonPressed
, this, button
->GetId());
138 Bind(wxEVT_COMMAND_MENU_SELECTED
, &MyFrame::OnRunSimulation
, this, RunSimulation
);
144 void MyFrame::OnRunSimulation(wxCommandEvent
&)
146 wxUIActionSimulator sim
;
147 wxWindow
* button
= FindWindow(wxString("TheButton"));
148 wxPoint globalPoint
= button
->ClientToScreen(wxPoint(20, 10));
149 sim
.MouseMove(globalPoint
.x
, globalPoint
.y
);
150 sim
.MouseClick(wxMOUSE_BTN_LEFT
);
155 wxMessageBox("Button automagically pressed!");
158 void MyFrame::OnButtonPressed(wxCommandEvent
&)
160 m_buttonPressed
= true;