]>
git.saurik.com Git - wxWidgets.git/blob - samples/uiaction/uiaction.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxUIActionSimulator sample
4 // Author: Kevin Ollivier
7 // Copyright: (c) Kevin Ollivier, Steven Lamerton
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx/wx.h".
20 #include "wx/wxprec.h"
26 // for all others, include the necessary headers (this file is usually all you
27 // need because it includes almost all "standard" wxWidgets headers)
32 #if wxUSE_UIACTIONSIMULATOR
33 #include "wx/uiaction.h"
36 // ----------------------------------------------------------------------------
38 // ----------------------------------------------------------------------------
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)
42 #ifndef wxHAS_IMAGES_IN_RESOURCES
43 #include "../sample.xpm"
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 // IDs for the controls and the menu commands
58 // ----------------------------------------------------------------------------
60 // ----------------------------------------------------------------------------
62 // Define a new application type, each program should derive a class from wxApp
63 class MyApp
: public wxApp
66 virtual bool OnInit();
69 #if wxUSE_UIACTIONSIMULATOR
71 // Define a new frame type: this is going to be our main frame
72 class MyFrame
: public wxFrame
76 MyFrame(const wxString
& title
);
78 void OnButtonPressed(wxCommandEvent
& event
);
79 void OnRunSimulation(wxCommandEvent
& event
);
80 void OnSimulateText(wxCommandEvent
& event
);
81 void OnExit(wxCommandEvent
& WXUNUSED(event
)) { Close(); }
90 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
91 EVT_BUTTON(wxID_ANY
, MyFrame::OnButtonPressed
)
92 EVT_MENU(RunSimulation
, MyFrame::OnRunSimulation
)
93 EVT_MENU(SimulateText
, MyFrame::OnSimulateText
)
94 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
97 #endif // wxUSE_UIACTIONSIMULATOR
99 // ============================================================================
101 // ============================================================================
103 // ----------------------------------------------------------------------------
104 // the application class
105 // ----------------------------------------------------------------------------
111 if ( !wxApp::OnInit() )
114 #if wxUSE_UIACTIONSIMULATOR
115 MyFrame
*frame
= new MyFrame("wxUIActionSimulator sample application");
119 #else // !wxUSE_UIACTIONSIMULATOR
120 wxLogError("wxUSE_UIACTIONSIMULATOR must be 1 for this sample");
122 #endif // wxUSE_UIACTIONSIMULATOR/!wxUSE_UIACTIONSIMULATOR
125 // ----------------------------------------------------------------------------
127 // ----------------------------------------------------------------------------
129 #if wxUSE_UIACTIONSIMULATOR
132 MyFrame::MyFrame(const wxString
& title
)
133 : wxFrame(NULL
, wxID_ANY
, title
)
135 SetIcon(wxICON(sample
));
139 wxMenu
*fileMenu
= new wxMenu
;
141 fileMenu
->Append(wxID_NEW
, "&New File...", "Open a new file");
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();
148 fileMenu
->Append(wxID_EXIT
, "E&xit\tAlt-X", "Quit this program");
150 wxMenuBar
*menuBar
= new wxMenuBar();
151 menuBar
->Append(fileMenu
, "&File");
154 #endif // wxUSE_MENUS
156 wxPanel
*panel
= new wxPanel(this);
158 wxBoxSizer
* sizer
= new wxBoxSizer(wxVERTICAL
);
159 panel
->SetSizer(sizer
);
161 m_button
= new wxButton(panel
, wxID_ANY
, "&Button");
162 sizer
->Add(m_button
, wxSizerFlags().Centre().Border());
164 m_text
= new wxTextCtrl(panel
, wxID_ANY
, "",
165 wxDefaultPosition
, wxDefaultSize
,
167 sizer
->Add(m_text
, wxSizerFlags(1).Expand().Border());
173 void MyFrame::OnRunSimulation(wxCommandEvent
& WXUNUSED(event
))
175 wxUIActionSimulator sim
;
177 // Add some extra distance to take account of window decorations
178 sim
.MouseMove(m_button
->GetScreenPosition() + wxPoint(10, 10));
179 sim
.MouseClick(wxMOUSE_BTN_LEFT
);
181 // Process the resulting button event
186 sim
.Char('A', wxMOD_SHIFT
);
187 sim
.Char(WXK_RETURN
);
189 sim
.Char('Z', wxMOD_SHIFT
);
190 sim
.Char(WXK_RETURN
);
192 sim
.Char(WXK_RETURN
);
193 sim
.Text("1 234.57e-8");
194 sim
.Char(WXK_RETURN
);
198 void MyFrame::OnSimulateText(wxCommandEvent
& WXUNUSED(event
))
200 static wxString s_text
;
201 const wxString text
= wxGetTextFromUser
203 "Enter text to simulate: ",
204 "wxUIActionSimulator wxWidgets Sample",
213 wxUIActionSimulator sim
;
215 sim
.Text(s_text
.c_str());
218 void MyFrame::OnButtonPressed(wxCommandEvent
& WXUNUSED(event
))
220 m_text
->AppendText("Button pressed.\n");
223 #endif // wxUSE_UIACTIONSIMULATOR