]> git.saurik.com Git - wxWidgets.git/blame - samples/uiaction/uiaction.cpp
Suppress warnings about double to int truncation in wxHTML code.
[wxWidgets.git] / samples / uiaction / uiaction.cpp
CommitLineData
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$
8// Copyright: (c) Kevin Ollivier
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
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
52enum
53{
54 // menu items
55 TheButton = 100,
56 RunSimulation
57};
58
a02a5cfc
KO
59// ----------------------------------------------------------------------------
60// private classes
61// ----------------------------------------------------------------------------
62
63// Define a new application type, each program should derive a class from wxApp
64class MyApp : public wxApp
65{
66public:
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
73class MyFrame : public wxFrame
74{
75public:
76 // ctor(s)
77 MyFrame(const wxString& title);
78
79 void OnButtonPressed(wxCommandEvent&);
80 void OnRunSimulation(wxCommandEvent&);
81
82 bool ButtonPressed() const { return m_buttonPressed; }
83 bool MenuSelected() const { return m_menuSelected; }
84
85private:
86 bool m_buttonPressed;
87 bool m_menuSelected;
a02a5cfc 88
d9ffb9fd 89 DECLARE_EVENT_TABLE()
a02a5cfc
KO
90};
91
d9ffb9fd
VZ
92BEGIN_EVENT_TABLE(MyFrame, wxFrame)
93 EVT_BUTTON(TheButton, MyFrame::OnButtonPressed)
94 EVT_MENU(RunSimulation, MyFrame::OnRunSimulation)
95END_EVENT_TABLE()
a02a5cfc 96
14480540
VZ
97#endif // wxUSE_UIACTIONSIMULATOR
98
a02a5cfc
KO
99// ============================================================================
100// implementation
101// ============================================================================
102
103// ----------------------------------------------------------------------------
104// the application class
105// ----------------------------------------------------------------------------
106
d9ffb9fd
VZ
107IMPLEMENT_APP(MyApp)
108
a02a5cfc
KO
109bool MyApp::OnInit()
110{
111 if ( !wxApp::OnInit() )
112 return false;
113
14480540 114#if wxUSE_UIACTIONSIMULATOR
a02a5cfc
KO
115 MyFrame *frame = new MyFrame("wxUIActionSimulator sample application");
116 frame->Show(true);
117
118 return true;
14480540
VZ
119#else // !wxUSE_UIACTIONSIMULATOR
120 wxLogError("wxUSE_UIACTIONSIMULATOR must be 1 for this sample");
121 return false;
122#endif // wxUSE_UIACTIONSIMULATOR/!wxUSE_UIACTIONSIMULATOR
a02a5cfc
KO
123}
124
125// ----------------------------------------------------------------------------
126// main frame
127// ----------------------------------------------------------------------------
128
14480540
VZ
129#if wxUSE_UIACTIONSIMULATOR
130
a02a5cfc
KO
131// frame constructor
132MyFrame::MyFrame(const wxString& title)
133 : wxFrame(NULL, wxID_ANY, title)
134{
135 SetIcon(wxICON(sample));
136
137 m_buttonPressed = false;
138 m_menuSelected = false;
139
140#if wxUSE_MENUS
141 // create a menu bar
142 wxMenu *fileMenu = new wxMenu;
143
144 fileMenu->Append(wxID_NEW, "&New File...", "Open a new file");
145 fileMenu->Append(RunSimulation, "&Run Simulation...", "Run the UI action simulation");
146
147 fileMenu->Append(wxID_EXIT, "E&xit\tAlt-X", "Quit this program");
148
149 wxMenuBar *menuBar = new wxMenuBar();
150 menuBar->Append(fileMenu, "&File");
151
152 SetMenuBar(menuBar);
153#endif // wxUSE_MENUS
154
155 wxButton* button = new wxButton(this, TheButton, "Button");
156 button->SetName("TheButton");
a02a5cfc
KO
157}
158
159
160// event handlers
161
162void MyFrame::OnRunSimulation(wxCommandEvent&)
163{
164 wxUIActionSimulator sim;
165 wxWindow* button = FindWindow(wxString("TheButton"));
166 wxPoint globalPoint = button->ClientToScreen(wxPoint(20, 10));
167 sim.MouseMove(globalPoint.x, globalPoint.y);
168 sim.MouseClick(wxMOUSE_BTN_LEFT);
169
170 wxYield();
171
172 if (ButtonPressed())
173 wxMessageBox("Button automagically pressed!");
174}
175
176void MyFrame::OnButtonPressed(wxCommandEvent&)
177{
178 m_buttonPressed = true;
179}
9b7e0226
VZ
180
181#endif // wxUSE_UIACTIONSIMULATOR