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