]>
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 #ifndef wxHAS_IMAGES_IN_RESOURCES
44 #include "../sample.xpm"
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 // IDs for the controls and the menu commands
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
63 // Define a new application type, each program should derive a class from wxApp
64 class MyApp
: public wxApp
67 virtual bool OnInit();
70 #if wxUSE_UIACTIONSIMULATOR
72 // Define a new frame type: this is going to be our main frame
73 class MyFrame
: public wxFrame
77 MyFrame(const wxString
& title
);
79 void OnButtonPressed(wxCommandEvent
& event
);
80 void OnRunSimulation(wxCommandEvent
& event
);
81 void OnSimulateText(wxCommandEvent
& event
);
82 void OnExit(wxCommandEvent
& WXUNUSED(event
)) { Close(); }
91 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
92 EVT_BUTTON(wxID_ANY
, MyFrame::OnButtonPressed
)
93 EVT_MENU(RunSimulation
, MyFrame::OnRunSimulation
)
94 EVT_MENU(SimulateText
, MyFrame::OnSimulateText
)
95 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
98 #endif // wxUSE_UIACTIONSIMULATOR
100 // ============================================================================
102 // ============================================================================
104 // ----------------------------------------------------------------------------
105 // the application class
106 // ----------------------------------------------------------------------------
112 if ( !wxApp::OnInit() )
115 #if wxUSE_UIACTIONSIMULATOR
116 MyFrame
*frame
= new MyFrame("wxUIActionSimulator sample application");
120 #else // !wxUSE_UIACTIONSIMULATOR
121 wxLogError("wxUSE_UIACTIONSIMULATOR must be 1 for this sample");
123 #endif // wxUSE_UIACTIONSIMULATOR/!wxUSE_UIACTIONSIMULATOR
126 // ----------------------------------------------------------------------------
128 // ----------------------------------------------------------------------------
130 #if wxUSE_UIACTIONSIMULATOR
133 MyFrame::MyFrame(const wxString
& title
)
134 : wxFrame(NULL
, wxID_ANY
, title
)
136 SetIcon(wxICON(sample
));
140 wxMenu
*fileMenu
= new wxMenu
;
142 fileMenu
->Append(wxID_NEW
, "&New File...", "Open a new file");
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();
149 fileMenu
->Append(wxID_EXIT
, "E&xit\tAlt-X", "Quit this program");
151 wxMenuBar
*menuBar
= new wxMenuBar();
152 menuBar
->Append(fileMenu
, "&File");
155 #endif // wxUSE_MENUS
157 wxPanel
*panel
= new wxPanel(this);
159 wxBoxSizer
* sizer
= new wxBoxSizer(wxVERTICAL
);
160 panel
->SetSizer(sizer
);
162 m_button
= new wxButton(panel
, wxID_ANY
, "&Button");
163 sizer
->Add(m_button
, wxSizerFlags().Centre().Border());
165 m_text
= new wxTextCtrl(panel
, wxID_ANY
, "",
166 wxDefaultPosition
, wxDefaultSize
,
168 sizer
->Add(m_text
, wxSizerFlags(1).Expand().Border());
174 void MyFrame::OnRunSimulation(wxCommandEvent
& WXUNUSED(event
))
176 wxUIActionSimulator sim
;
178 // Add some extra distance to take account of window decorations
179 sim
.MouseMove(m_button
->GetScreenPosition() + wxPoint(10, 10));
180 sim
.MouseClick(wxMOUSE_BTN_LEFT
);
182 // Process the resulting button event
187 sim
.Char('A', wxMOD_SHIFT
);
188 sim
.Char(WXK_RETURN
);
190 sim
.Char('Z', wxMOD_SHIFT
);
191 sim
.Char(WXK_RETURN
);
193 sim
.Char(WXK_RETURN
);
194 sim
.Text("1 234.57e-8");
195 sim
.Char(WXK_RETURN
);
199 void MyFrame::OnSimulateText(wxCommandEvent
& WXUNUSED(event
))
201 static wxString s_text
;
202 const wxString text
= wxGetTextFromUser
204 "Enter text to simulate: ",
205 "wxUIActionSimulator wxWidgets Sample",
214 wxUIActionSimulator sim
;
216 sim
.Text(s_text
.c_str());
219 void MyFrame::OnButtonPressed(wxCommandEvent
& WXUNUSED(event
))
221 m_text
->AppendText("Button pressed.\n");
224 #endif // wxUSE_UIACTIONSIMULATOR