]>
git.saurik.com Git - wxWidgets.git/blob - samples/uiaction/uiaction.cpp
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 #if wxUSE_UIACTIONSIMULATOR
34 #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 #if wxUSE_UIACTIONSIMULATOR
72 // Define a new frame type: this is going to be our main frame
73 class MyFrame
: public wxFrame
77 MyFrame(const wxString
& title
);
79 void OnButtonPressed(wxCommandEvent
&);
80 void OnRunSimulation(wxCommandEvent
&);
82 bool ButtonPressed() const { return m_buttonPressed
; }
83 bool MenuSelected() const { return m_menuSelected
; }
92 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
93 EVT_BUTTON(TheButton
, MyFrame::OnButtonPressed
)
94 EVT_MENU(RunSimulation
, MyFrame::OnRunSimulation
)
97 #endif // wxUSE_UIACTIONSIMULATOR
99 // ============================================================================
101 // ============================================================================
103 // ----------------------------------------------------------------------------
104 // the application class
105 // ----------------------------------------------------------------------------
111 if ( !wxApp::OnInit() )
114 #if wxUSE_UIACTIONSIMULATOR
115 MyFrame
*frame
= new MyFrame("wxUIActionSimulator sample application");
119 #else // !wxUSE_UIACTIONSIMULATOR
120 wxLogError("wxUSE_UIACTIONSIMULATOR must be 1 for this sample");
122 #endif // wxUSE_UIACTIONSIMULATOR/!wxUSE_UIACTIONSIMULATOR
125 // ----------------------------------------------------------------------------
127 // ----------------------------------------------------------------------------
129 #if wxUSE_UIACTIONSIMULATOR
132 MyFrame::MyFrame(const wxString
& title
)
133 : wxFrame(NULL
, wxID_ANY
, title
)
135 SetIcon(wxICON(sample
));
137 m_buttonPressed
= false;
138 m_menuSelected
= false;
142 wxMenu
*fileMenu
= new wxMenu
;
144 fileMenu
->Append(wxID_NEW
, "&New File...", "Open a new file");
145 fileMenu
->Append(RunSimulation
, "&Run Simulation...", "Run the UI action simulation");
147 fileMenu
->Append(wxID_EXIT
, "E&xit\tAlt-X", "Quit this program");
149 wxMenuBar
*menuBar
= new wxMenuBar();
150 menuBar
->Append(fileMenu
, "&File");
153 #endif // wxUSE_MENUS
155 wxButton
* button
= new wxButton(this, TheButton
, "Button");
156 button
->SetName("TheButton");
162 void MyFrame::OnRunSimulation(wxCommandEvent
&)
164 wxUIActionSimulator sim
;
165 wxWindow
* button
= FindWindow(wxString("TheButton"));
166 wxPoint globalPoint
= button
->ClientToScreen(wxPoint(20, 10));
167 sim
.MouseMove(globalPoint
.x
, globalPoint
.y
);
168 sim
.MouseClick(wxMOUSE_BTN_LEFT
);
173 wxMessageBox("Button automagically pressed!");
176 void MyFrame::OnButtonPressed(wxCommandEvent
&)
178 m_buttonPressed
= true;
181 #endif // wxUSE_UIACTIONSIMULATOR