]>
Commit | Line | Data |
---|---|---|
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$ | |
8 | // Copyright: (c) Kevin Ollivier, Steven Lamerton | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | // For compilers that support precompilation, includes "wx/wx.h". | |
21 | #include "wx/wxprec.h" | |
22 | ||
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 | ||
33 | #if wxUSE_UIACTIONSIMULATOR | |
34 | #include "wx/uiaction.h" | |
35 | #endif | |
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) | |
43 | #if !defined(__WXMSW__) && !defined(__WXPM__) | |
44 | #include "../sample.xpm" | |
45 | #endif | |
46 | ||
47 | // ---------------------------------------------------------------------------- | |
48 | // constants | |
49 | // ---------------------------------------------------------------------------- | |
50 | ||
51 | // IDs for the controls and the menu commands | |
52 | enum | |
53 | { | |
54 | // menu items | |
55 | RunSimulation = 1 | |
56 | }; | |
57 | ||
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 | ||
69 | #if wxUSE_UIACTIONSIMULATOR | |
70 | ||
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 | ||
78 | void OnButtonPressed(wxCommandEvent& event); | |
79 | void OnRunSimulation(wxCommandEvent& event); | |
80 | void OnExit(wxCommandEvent& WXUNUSED(event)) { Close(); } | |
81 | ||
82 | private: | |
83 | wxButton* m_button; | |
84 | wxTextCtrl* m_text; | |
85 | ||
86 | DECLARE_EVENT_TABLE() | |
87 | }; | |
88 | ||
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) | |
93 | END_EVENT_TABLE() | |
94 | ||
95 | #endif // wxUSE_UIACTIONSIMULATOR | |
96 | ||
97 | // ============================================================================ | |
98 | // implementation | |
99 | // ============================================================================ | |
100 | ||
101 | // ---------------------------------------------------------------------------- | |
102 | // the application class | |
103 | // ---------------------------------------------------------------------------- | |
104 | ||
105 | IMPLEMENT_APP(MyApp) | |
106 | ||
107 | bool MyApp::OnInit() | |
108 | { | |
109 | if ( !wxApp::OnInit() ) | |
110 | return false; | |
111 | ||
112 | #if wxUSE_UIACTIONSIMULATOR | |
113 | MyFrame *frame = new MyFrame("wxUIActionSimulator sample application"); | |
114 | frame->Show(true); | |
115 | ||
116 | return true; | |
117 | #else // !wxUSE_UIACTIONSIMULATOR | |
118 | wxLogError("wxUSE_UIACTIONSIMULATOR must be 1 for this sample"); | |
119 | return false; | |
120 | #endif // wxUSE_UIACTIONSIMULATOR/!wxUSE_UIACTIONSIMULATOR | |
121 | } | |
122 | ||
123 | // ---------------------------------------------------------------------------- | |
124 | // main frame | |
125 | // ---------------------------------------------------------------------------- | |
126 | ||
127 | #if wxUSE_UIACTIONSIMULATOR | |
128 | ||
129 | // frame constructor | |
130 | MyFrame::MyFrame(const wxString& title) | |
131 | : wxFrame(NULL, wxID_ANY, title) | |
132 | { | |
133 | SetIcon(wxICON(sample)); | |
134 | ||
135 | #if wxUSE_MENUS | |
136 | // create a menu bar | |
137 | wxMenu *fileMenu = new wxMenu; | |
138 | ||
139 | fileMenu->Append(wxID_NEW, "&New File...", "Open a new file"); | |
140 | fileMenu->Append(RunSimulation, "&Run Simulation...", "Run the UI action simulation"); | |
141 | ||
142 | fileMenu->Append(wxID_EXIT, "E&xit\tAlt-X", "Quit this program"); | |
143 | ||
144 | wxMenuBar *menuBar = new wxMenuBar(); | |
145 | menuBar->Append(fileMenu, "&File"); | |
146 | ||
147 | SetMenuBar(menuBar); | |
148 | #endif // wxUSE_MENUS | |
149 | ||
150 | wxPanel *panel = new wxPanel(this); | |
151 | ||
152 | wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL); | |
153 | panel->SetSizer(sizer); | |
154 | ||
155 | m_button = new wxButton(panel, wxID_ANY, "&Button"); | |
156 | sizer->Add(m_button, wxSizerFlags().Centre().Border()); | |
157 | ||
158 | m_text = new wxTextCtrl(panel, wxID_ANY, "", | |
159 | wxDefaultPosition, wxDefaultSize, | |
160 | wxTE_MULTILINE); | |
161 | sizer->Add(m_text, wxSizerFlags(1).Expand().Border()); | |
162 | } | |
163 | ||
164 | ||
165 | // event handlers | |
166 | ||
167 | void MyFrame::OnRunSimulation(wxCommandEvent& WXUNUSED(event)) | |
168 | { | |
169 | wxUIActionSimulator sim; | |
170 | ||
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); | |
174 | ||
175 | // Process the resulting button event | |
176 | wxYield(); | |
177 | ||
178 | m_text->SetFocus(); | |
179 | sim.Char('A'); | |
180 | sim.Char('A', wxMOD_SHIFT); | |
181 | sim.Char(WXK_RETURN); | |
182 | sim.Char('Z'); | |
183 | sim.Char('Z', wxMOD_SHIFT); | |
184 | sim.Char(WXK_RETURN); | |
185 | sim.Text("aAbBcC"); | |
186 | sim.Char(WXK_RETURN); | |
187 | } | |
188 | ||
189 | void MyFrame::OnButtonPressed(wxCommandEvent& WXUNUSED(event)) | |
190 | { | |
191 | m_text->AppendText("Button pressed.\n"); | |
192 | } | |
193 | ||
194 | #endif // wxUSE_UIACTIONSIMULATOR |