]>
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) | |
43 | #if !defined(__WXMSW__) && !defined(__WXPM__) | |
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 | |
571d991b | 55 | RunSimulation = 1 |
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); | |
80 | void OnExit(wxCommandEvent& WXUNUSED(event)) { Close(); } | |
81 | ||
a02a5cfc | 82 | private: |
571d991b VZ |
83 | wxButton* m_button; |
84 | wxTextCtrl* m_text; | |
a02a5cfc | 85 | |
d9ffb9fd | 86 | DECLARE_EVENT_TABLE() |
a02a5cfc KO |
87 | }; |
88 | ||
d9ffb9fd | 89 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) |
571d991b | 90 | EVT_BUTTON(wxID_ANY, MyFrame::OnButtonPressed) |
d9ffb9fd | 91 | EVT_MENU(RunSimulation, MyFrame::OnRunSimulation) |
571d991b | 92 | EVT_MENU(wxID_EXIT, MyFrame::OnExit) |
d9ffb9fd | 93 | END_EVENT_TABLE() |
a02a5cfc | 94 | |
14480540 VZ |
95 | #endif // wxUSE_UIACTIONSIMULATOR |
96 | ||
a02a5cfc KO |
97 | // ============================================================================ |
98 | // implementation | |
99 | // ============================================================================ | |
100 | ||
101 | // ---------------------------------------------------------------------------- | |
102 | // the application class | |
103 | // ---------------------------------------------------------------------------- | |
104 | ||
d9ffb9fd VZ |
105 | IMPLEMENT_APP(MyApp) |
106 | ||
a02a5cfc KO |
107 | bool MyApp::OnInit() |
108 | { | |
109 | if ( !wxApp::OnInit() ) | |
110 | return false; | |
111 | ||
14480540 | 112 | #if wxUSE_UIACTIONSIMULATOR |
a02a5cfc KO |
113 | MyFrame *frame = new MyFrame("wxUIActionSimulator sample application"); |
114 | frame->Show(true); | |
571d991b | 115 | |
a02a5cfc | 116 | return true; |
14480540 VZ |
117 | #else // !wxUSE_UIACTIONSIMULATOR |
118 | wxLogError("wxUSE_UIACTIONSIMULATOR must be 1 for this sample"); | |
119 | return false; | |
120 | #endif // wxUSE_UIACTIONSIMULATOR/!wxUSE_UIACTIONSIMULATOR | |
a02a5cfc KO |
121 | } |
122 | ||
123 | // ---------------------------------------------------------------------------- | |
124 | // main frame | |
125 | // ---------------------------------------------------------------------------- | |
126 | ||
14480540 VZ |
127 | #if wxUSE_UIACTIONSIMULATOR |
128 | ||
a02a5cfc KO |
129 | // frame constructor |
130 | MyFrame::MyFrame(const wxString& title) | |
131 | : wxFrame(NULL, wxID_ANY, title) | |
132 | { | |
133 | SetIcon(wxICON(sample)); | |
134 | ||
a02a5cfc KO |
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 | ||
571d991b VZ |
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()); | |
a02a5cfc KO |
162 | } |
163 | ||
164 | ||
165 | // event handlers | |
166 | ||
571d991b | 167 | void MyFrame::OnRunSimulation(wxCommandEvent& WXUNUSED(event)) |
a02a5cfc KO |
168 | { |
169 | wxUIActionSimulator sim; | |
571d991b VZ |
170 | |
171 | // Add some extra distance to take account of window decorations | |
172 | sim.MouseMove(m_button->GetScreenPosition() + wxPoint(10, 10)); | |
a02a5cfc | 173 | sim.MouseClick(wxMOUSE_BTN_LEFT); |
571d991b VZ |
174 | |
175 | // Process the resulting button event | |
a02a5cfc | 176 | wxYield(); |
571d991b VZ |
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); | |
a02a5cfc KO |
187 | } |
188 | ||
571d991b | 189 | void MyFrame::OnButtonPressed(wxCommandEvent& WXUNUSED(event)) |
a02a5cfc | 190 | { |
571d991b | 191 | m_text->AppendText("Button pressed.\n"); |
a02a5cfc | 192 | } |
9b7e0226 VZ |
193 | |
194 | #endif // wxUSE_UIACTIONSIMULATOR |