]>
git.saurik.com Git - wxWidgets.git/blob - samples/uiaction/uiaction.cpp
b08767fdd3bba581ad859ea661f3e59a06d00f90
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 #if wxUSE_UIACTIONSIMULATOR
29 // for all others, include the necessary headers (this file is usually all you
30 // need because it includes almost all "standard" wxWidgets headers)
35 #include "wx/uiaction.h"
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 // the application icon (under Windows and OS/2 it is in resources and even
42 // though we could still include the XPM here it would be unused)
43 #if !defined(__WXMSW__) && !defined(__WXPM__)
44 #include "../sample.xpm"
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 // IDs for the controls and the menu commands
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
63 // Define a new application type, each program should derive a class from wxApp
64 class MyApp
: public wxApp
67 virtual bool OnInit();
70 // Define a new frame type: this is going to be our main frame
71 class MyFrame
: public wxFrame
75 MyFrame(const wxString
& title
);
77 void OnButtonPressed(wxCommandEvent
&);
78 void OnRunSimulation(wxCommandEvent
&);
80 bool ButtonPressed() const { return m_buttonPressed
; }
81 bool MenuSelected() const { return m_menuSelected
; }
90 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
91 EVT_BUTTON(TheButton
, MyFrame::OnButtonPressed
)
92 EVT_MENU(RunSimulation
, MyFrame::OnRunSimulation
)
95 // ============================================================================
97 // ============================================================================
99 // ----------------------------------------------------------------------------
100 // the application class
101 // ----------------------------------------------------------------------------
107 if ( !wxApp::OnInit() )
110 MyFrame
*frame
= new MyFrame("wxUIActionSimulator sample application");
116 // ----------------------------------------------------------------------------
118 // ----------------------------------------------------------------------------
121 MyFrame::MyFrame(const wxString
& title
)
122 : wxFrame(NULL
, wxID_ANY
, title
)
124 SetIcon(wxICON(sample
));
126 m_buttonPressed
= false;
127 m_menuSelected
= false;
131 wxMenu
*fileMenu
= new wxMenu
;
133 fileMenu
->Append(wxID_NEW
, "&New File...", "Open a new file");
134 fileMenu
->Append(RunSimulation
, "&Run Simulation...", "Run the UI action simulation");
136 fileMenu
->Append(wxID_EXIT
, "E&xit\tAlt-X", "Quit this program");
138 wxMenuBar
*menuBar
= new wxMenuBar();
139 menuBar
->Append(fileMenu
, "&File");
142 #endif // wxUSE_MENUS
144 wxButton
* button
= new wxButton(this, TheButton
, "Button");
145 button
->SetName("TheButton");
151 void MyFrame::OnRunSimulation(wxCommandEvent
&)
153 wxUIActionSimulator sim
;
154 wxWindow
* button
= FindWindow(wxString("TheButton"));
155 wxPoint globalPoint
= button
->ClientToScreen(wxPoint(20, 10));
156 sim
.MouseMove(globalPoint
.x
, globalPoint
.y
);
157 sim
.MouseClick(wxMOUSE_BTN_LEFT
);
162 wxMessageBox("Button automagically pressed!");
165 void MyFrame::OnButtonPressed(wxCommandEvent
&)
167 m_buttonPressed
= true;
170 #endif // wxUSE_UIACTIONSIMULATOR