]>
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 #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 // IDs for the controls and the menu commands
57 // ----------------------------------------------------------------------------
59 // ----------------------------------------------------------------------------
61 // Define a new application type, each program should derive a class from wxApp
62 class MyApp
: public wxApp
65 virtual bool OnInit();
68 // Define a new frame type: this is going to be our main frame
69 class MyFrame
: public wxFrame
73 MyFrame(const wxString
& title
);
75 void OnButtonPressed(wxCommandEvent
&);
76 void OnRunSimulation(wxCommandEvent
&);
78 bool ButtonPressed() const { return m_buttonPressed
; }
79 bool MenuSelected() const { return m_menuSelected
; }
88 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
89 EVT_BUTTON(TheButton
, MyFrame::OnButtonPressed
)
90 EVT_MENU(RunSimulation
, MyFrame::OnRunSimulation
)
93 // ============================================================================
95 // ============================================================================
97 // ----------------------------------------------------------------------------
98 // the application class
99 // ----------------------------------------------------------------------------
105 if ( !wxApp::OnInit() )
108 MyFrame
*frame
= new MyFrame("wxUIActionSimulator sample application");
114 // ----------------------------------------------------------------------------
116 // ----------------------------------------------------------------------------
119 MyFrame::MyFrame(const wxString
& title
)
120 : wxFrame(NULL
, wxID_ANY
, title
)
122 SetIcon(wxICON(sample
));
124 m_buttonPressed
= false;
125 m_menuSelected
= false;
129 wxMenu
*fileMenu
= new wxMenu
;
131 fileMenu
->Append(wxID_NEW
, "&New File...", "Open a new file");
132 fileMenu
->Append(RunSimulation
, "&Run Simulation...", "Run the UI action simulation");
134 fileMenu
->Append(wxID_EXIT
, "E&xit\tAlt-X", "Quit this program");
136 wxMenuBar
*menuBar
= new wxMenuBar();
137 menuBar
->Append(fileMenu
, "&File");
140 #endif // wxUSE_MENUS
142 wxButton
* button
= new wxButton(this, TheButton
, "Button");
143 button
->SetName("TheButton");
149 void MyFrame::OnRunSimulation(wxCommandEvent
&)
151 wxUIActionSimulator sim
;
152 wxWindow
* button
= FindWindow(wxString("TheButton"));
153 wxPoint globalPoint
= button
->ClientToScreen(wxPoint(20, 10));
154 sim
.MouseMove(globalPoint
.x
, globalPoint
.y
);
155 sim
.MouseClick(wxMOUSE_BTN_LEFT
);
160 wxMessageBox("Button automagically pressed!");
163 void MyFrame::OnButtonPressed(wxCommandEvent
&)
165 m_buttonPressed
= true;