]>
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, Steven Lamerton
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
58 // ----------------------------------------------------------------------------
60 // ----------------------------------------------------------------------------
62 // Define a new application type, each program should derive a class from wxApp
63 class MyApp
: public wxApp
66 virtual bool OnInit();
69 #if wxUSE_UIACTIONSIMULATOR
71 // Define a new frame type: this is going to be our main frame
72 class MyFrame
: public wxFrame
76 MyFrame(const wxString
& title
);
78 void OnButtonPressed(wxCommandEvent
& event
);
79 void OnRunSimulation(wxCommandEvent
& event
);
80 void OnExit(wxCommandEvent
& WXUNUSED(event
)) { Close(); }
89 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
90 EVT_BUTTON(wxID_ANY
, MyFrame::OnButtonPressed
)
91 EVT_MENU(RunSimulation
, MyFrame::OnRunSimulation
)
92 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
95 #endif // wxUSE_UIACTIONSIMULATOR
97 // ============================================================================
99 // ============================================================================
101 // ----------------------------------------------------------------------------
102 // the application class
103 // ----------------------------------------------------------------------------
109 if ( !wxApp::OnInit() )
112 #if wxUSE_UIACTIONSIMULATOR
113 MyFrame
*frame
= new MyFrame("wxUIActionSimulator sample application");
117 #else // !wxUSE_UIACTIONSIMULATOR
118 wxLogError("wxUSE_UIACTIONSIMULATOR must be 1 for this sample");
120 #endif // wxUSE_UIACTIONSIMULATOR/!wxUSE_UIACTIONSIMULATOR
123 // ----------------------------------------------------------------------------
125 // ----------------------------------------------------------------------------
127 #if wxUSE_UIACTIONSIMULATOR
130 MyFrame::MyFrame(const wxString
& title
)
131 : wxFrame(NULL
, wxID_ANY
, title
)
133 SetIcon(wxICON(sample
));
137 wxMenu
*fileMenu
= new wxMenu
;
139 fileMenu
->Append(wxID_NEW
, "&New File...", "Open a new file");
140 fileMenu
->Append(RunSimulation
, "&Run Simulation...", "Run the UI action simulation");
142 fileMenu
->Append(wxID_EXIT
, "E&xit\tAlt-X", "Quit this program");
144 wxMenuBar
*menuBar
= new wxMenuBar();
145 menuBar
->Append(fileMenu
, "&File");
148 #endif // wxUSE_MENUS
150 wxPanel
*panel
= new wxPanel(this);
152 wxBoxSizer
* sizer
= new wxBoxSizer(wxVERTICAL
);
153 panel
->SetSizer(sizer
);
155 m_button
= new wxButton(panel
, wxID_ANY
, "&Button");
156 sizer
->Add(m_button
, wxSizerFlags().Centre().Border());
158 m_text
= new wxTextCtrl(panel
, wxID_ANY
, "",
159 wxDefaultPosition
, wxDefaultSize
,
161 sizer
->Add(m_text
, wxSizerFlags(1).Expand().Border());
167 void MyFrame::OnRunSimulation(wxCommandEvent
& WXUNUSED(event
))
169 wxUIActionSimulator sim
;
171 // Add some extra distance to take account of window decorations
172 sim
.MouseMove(m_button
->GetScreenPosition() + wxPoint(10, 10));
173 sim
.MouseClick(wxMOUSE_BTN_LEFT
);
175 // Process the resulting button event
180 sim
.Char('A', wxMOD_SHIFT
);
181 sim
.Char(WXK_RETURN
);
183 sim
.Char('Z', wxMOD_SHIFT
);
184 sim
.Char(WXK_RETURN
);
186 sim
.Char(WXK_RETURN
);
189 void MyFrame::OnButtonPressed(wxCommandEvent
& WXUNUSED(event
))
191 m_text
->AppendText("Button pressed.\n");
194 #endif // wxUSE_UIACTIONSIMULATOR