]>
Commit | Line | Data |
---|---|---|
a02a5cfc KO |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: uiaction.cpp | |
3 | // Purpose: wxUIActionSimulator sample | |
4 | // Author: Kevin Ollivier | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
571d991b | 7 | // Copyright: (c) Kevin Ollivier, Steven Lamerton |
a02a5cfc KO |
8 | // Licence: wxWindows licence |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | // ============================================================================ | |
12 | // declarations | |
13 | // ============================================================================ | |
14 | ||
15 | // ---------------------------------------------------------------------------- | |
16 | // headers | |
17 | // ---------------------------------------------------------------------------- | |
571d991b | 18 | |
a02a5cfc KO |
19 | // For compilers that support precompilation, includes "wx/wx.h". |
20 | #include "wx/wxprec.h" | |
571d991b | 21 | |
a02a5cfc KO |
22 | #ifdef __BORLANDC__ |
23 | #pragma hdrstop | |
24 | #endif | |
25 | ||
26 | // for all others, include the necessary headers (this file is usually all you | |
27 | // need because it includes almost all "standard" wxWidgets headers) | |
28 | #ifndef WX_PRECOMP | |
29 | #include "wx/wx.h" | |
30 | #endif | |
31 | ||
14480540 VZ |
32 | #if wxUSE_UIACTIONSIMULATOR |
33 | #include "wx/uiaction.h" | |
34 | #endif | |
a02a5cfc KO |
35 | |
36 | // ---------------------------------------------------------------------------- | |
37 | // resources | |
38 | // ---------------------------------------------------------------------------- | |
39 | ||
40 | // the application icon (under Windows and OS/2 it is in resources and even | |
41 | // though we could still include the XPM here it would be unused) | |
e7092398 | 42 | #ifndef wxHAS_IMAGES_IN_RESOURCES |
a02a5cfc KO |
43 | #include "../sample.xpm" |
44 | #endif | |
45 | ||
d9ffb9fd VZ |
46 | // ---------------------------------------------------------------------------- |
47 | // constants | |
48 | // ---------------------------------------------------------------------------- | |
49 | ||
50 | // IDs for the controls and the menu commands | |
51 | enum | |
52 | { | |
53 | // menu items | |
1863484b VZ |
54 | RunSimulation = 1, |
55 | SimulateText | |
d9ffb9fd VZ |
56 | }; |
57 | ||
a02a5cfc KO |
58 | // ---------------------------------------------------------------------------- |
59 | // private classes | |
60 | // ---------------------------------------------------------------------------- | |
61 | ||
62 | // Define a new application type, each program should derive a class from wxApp | |
63 | class MyApp : public wxApp | |
64 | { | |
65 | public: | |
66 | virtual bool OnInit(); | |
67 | }; | |
68 | ||
14480540 VZ |
69 | #if wxUSE_UIACTIONSIMULATOR |
70 | ||
a02a5cfc KO |
71 | // Define a new frame type: this is going to be our main frame |
72 | class MyFrame : public wxFrame | |
73 | { | |
74 | public: | |
75 | // ctor(s) | |
76 | MyFrame(const wxString& title); | |
77 | ||
571d991b VZ |
78 | void OnButtonPressed(wxCommandEvent& event); |
79 | void OnRunSimulation(wxCommandEvent& event); | |
1863484b | 80 | void OnSimulateText(wxCommandEvent& event); |
571d991b VZ |
81 | void OnExit(wxCommandEvent& WXUNUSED(event)) { Close(); } |
82 | ||
a02a5cfc | 83 | private: |
571d991b VZ |
84 | wxButton* m_button; |
85 | wxTextCtrl* m_text; | |
a02a5cfc | 86 | |
d9ffb9fd | 87 | DECLARE_EVENT_TABLE() |
a02a5cfc KO |
88 | }; |
89 | ||
d9ffb9fd | 90 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) |
571d991b | 91 | EVT_BUTTON(wxID_ANY, MyFrame::OnButtonPressed) |
d9ffb9fd | 92 | EVT_MENU(RunSimulation, MyFrame::OnRunSimulation) |
1863484b | 93 | EVT_MENU(SimulateText, MyFrame::OnSimulateText) |
571d991b | 94 | EVT_MENU(wxID_EXIT, MyFrame::OnExit) |
d9ffb9fd | 95 | END_EVENT_TABLE() |
a02a5cfc | 96 | |
14480540 VZ |
97 | #endif // wxUSE_UIACTIONSIMULATOR |
98 | ||
a02a5cfc KO |
99 | // ============================================================================ |
100 | // implementation | |
101 | // ============================================================================ | |
102 | ||
103 | // ---------------------------------------------------------------------------- | |
104 | // the application class | |
105 | // ---------------------------------------------------------------------------- | |
106 | ||
d9ffb9fd VZ |
107 | IMPLEMENT_APP(MyApp) |
108 | ||
a02a5cfc KO |
109 | bool MyApp::OnInit() |
110 | { | |
111 | if ( !wxApp::OnInit() ) | |
112 | return false; | |
113 | ||
14480540 | 114 | #if wxUSE_UIACTIONSIMULATOR |
a02a5cfc KO |
115 | MyFrame *frame = new MyFrame("wxUIActionSimulator sample application"); |
116 | frame->Show(true); | |
571d991b | 117 | |
a02a5cfc | 118 | return true; |
14480540 VZ |
119 | #else // !wxUSE_UIACTIONSIMULATOR |
120 | wxLogError("wxUSE_UIACTIONSIMULATOR must be 1 for this sample"); | |
121 | return false; | |
122 | #endif // wxUSE_UIACTIONSIMULATOR/!wxUSE_UIACTIONSIMULATOR | |
a02a5cfc KO |
123 | } |
124 | ||
125 | // ---------------------------------------------------------------------------- | |
126 | // main frame | |
127 | // ---------------------------------------------------------------------------- | |
128 | ||
14480540 VZ |
129 | #if wxUSE_UIACTIONSIMULATOR |
130 | ||
a02a5cfc KO |
131 | // frame constructor |
132 | MyFrame::MyFrame(const wxString& title) | |
133 | : wxFrame(NULL, wxID_ANY, title) | |
134 | { | |
135 | SetIcon(wxICON(sample)); | |
136 | ||
a02a5cfc KO |
137 | #if wxUSE_MENUS |
138 | // create a menu bar | |
139 | wxMenu *fileMenu = new wxMenu; | |
140 | ||
141 | fileMenu->Append(wxID_NEW, "&New File...", "Open a new file"); | |
1863484b VZ |
142 | fileMenu->Append(RunSimulation, "&Run Simulation", |
143 | "Run predefined UI action simulation"); | |
144 | fileMenu->Append(SimulateText, "Simulate &text input...", | |
145 | "Enter text to simulate"); | |
146 | fileMenu->AppendSeparator(); | |
a02a5cfc KO |
147 | |
148 | fileMenu->Append(wxID_EXIT, "E&xit\tAlt-X", "Quit this program"); | |
149 | ||
150 | wxMenuBar *menuBar = new wxMenuBar(); | |
151 | menuBar->Append(fileMenu, "&File"); | |
152 | ||
153 | SetMenuBar(menuBar); | |
154 | #endif // wxUSE_MENUS | |
155 | ||
571d991b VZ |
156 | wxPanel *panel = new wxPanel(this); |
157 | ||
158 | wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL); | |
159 | panel->SetSizer(sizer); | |
160 | ||
161 | m_button = new wxButton(panel, wxID_ANY, "&Button"); | |
162 | sizer->Add(m_button, wxSizerFlags().Centre().Border()); | |
163 | ||
164 | m_text = new wxTextCtrl(panel, wxID_ANY, "", | |
165 | wxDefaultPosition, wxDefaultSize, | |
166 | wxTE_MULTILINE); | |
167 | sizer->Add(m_text, wxSizerFlags(1).Expand().Border()); | |
a02a5cfc KO |
168 | } |
169 | ||
170 | ||
171 | // event handlers | |
172 | ||
571d991b | 173 | void MyFrame::OnRunSimulation(wxCommandEvent& WXUNUSED(event)) |
a02a5cfc KO |
174 | { |
175 | wxUIActionSimulator sim; | |
571d991b VZ |
176 | |
177 | // Add some extra distance to take account of window decorations | |
178 | sim.MouseMove(m_button->GetScreenPosition() + wxPoint(10, 10)); | |
a02a5cfc | 179 | sim.MouseClick(wxMOUSE_BTN_LEFT); |
571d991b VZ |
180 | |
181 | // Process the resulting button event | |
a02a5cfc | 182 | wxYield(); |
571d991b VZ |
183 | |
184 | m_text->SetFocus(); | |
185 | sim.Char('A'); | |
186 | sim.Char('A', wxMOD_SHIFT); | |
187 | sim.Char(WXK_RETURN); | |
188 | sim.Char('Z'); | |
189 | sim.Char('Z', wxMOD_SHIFT); | |
190 | sim.Char(WXK_RETURN); | |
191 | sim.Text("aAbBcC"); | |
192 | sim.Char(WXK_RETURN); | |
c0c9009c VZ |
193 | sim.Text("1 234.57e-8"); |
194 | sim.Char(WXK_RETURN); | |
195 | ||
a02a5cfc KO |
196 | } |
197 | ||
1863484b VZ |
198 | void MyFrame::OnSimulateText(wxCommandEvent& WXUNUSED(event)) |
199 | { | |
200 | static wxString s_text; | |
201 | const wxString text = wxGetTextFromUser | |
202 | ( | |
203 | "Enter text to simulate: ", | |
204 | "wxUIActionSimulator wxWidgets Sample", | |
205 | s_text, | |
206 | this | |
207 | ); | |
208 | if ( text.empty() ) | |
209 | return; | |
210 | ||
211 | s_text = text; | |
212 | ||
213 | wxUIActionSimulator sim; | |
214 | m_text->SetFocus(); | |
7e3ea54f | 215 | sim.Text(s_text.c_str()); |
1863484b VZ |
216 | } |
217 | ||
571d991b | 218 | void MyFrame::OnButtonPressed(wxCommandEvent& WXUNUSED(event)) |
a02a5cfc | 219 | { |
571d991b | 220 | m_text->AppendText("Button pressed.\n"); |
a02a5cfc | 221 | } |
9b7e0226 VZ |
222 | |
223 | #endif // wxUSE_UIACTIONSIMULATOR |