]>
git.saurik.com Git - wxWidgets.git/blob - samples/access/accesstest.cpp
9c21331683e360619b14216d418f315d884e4546
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: accesstest.cpp
3 // Purpose: wxWindows accessibility sample
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
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" wxWindows headers)
33 #include "wx/access.h"
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 // the application icon (under Windows and OS/2 it is in resources)
40 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
41 #include "mondrian.xpm"
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 // Define a new application type, each program should derive a class from wxApp
49 class MyApp
: public wxApp
52 // override base class virtuals
53 // ----------------------------
55 // this one is called on application startup and is a good place for the app
56 // initialization (doing it here and not in the ctor allows to have an error
57 // return: if OnInit() returns false, the application terminates)
58 virtual bool OnInit();
61 // Define a new frame type: this is going to be our main frame
62 class MyFrame
: public wxFrame
66 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
,
67 long style
= wxDEFAULT_FRAME_STYLE
);
69 // event handlers (these functions should _not_ be virtual)
70 void OnQuit(wxCommandEvent
& event
);
71 void OnAbout(wxCommandEvent
& event
);
74 // any class wishing to process wxWindows events must use this macro
78 // ----------------------------------------------------------------------------
80 // ----------------------------------------------------------------------------
82 // IDs for the controls and the menu commands
88 // it is important for the id corresponding to the "About" command to have
89 // this standard value as otherwise it won't be handled properly under Mac
90 // (where it is special and put into the "Apple" menu)
91 AccessTest_About
= wxID_ABOUT
94 // ----------------------------------------------------------------------------
95 // event tables and other macros for wxWindows
96 // ----------------------------------------------------------------------------
98 // the event tables connect the wxWindows events with the functions (event
99 // handlers) which process them. It can be also done at run-time, but for the
100 // simple menu events like this the static method is much simpler.
101 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
102 EVT_MENU(AccessTest_Quit
, MyFrame::OnQuit
)
103 EVT_MENU(AccessTest_About
, MyFrame::OnAbout
)
106 // Create a new application object: this macro will allow wxWindows to create
107 // the application object during program execution (it's better than using a
108 // static object for many reasons) and also declares the accessor function
109 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
113 // ============================================================================
115 // ============================================================================
117 // ----------------------------------------------------------------------------
118 // the application class
119 // ----------------------------------------------------------------------------
121 // 'Main program' equivalent: the program execution "starts" here
124 // create the main application window
125 MyFrame
*frame
= new MyFrame(_T("AccessTest wxWindows App"),
126 wxPoint(50, 50), wxSize(450, 340));
128 // and show it (the frames, unlike simple controls, are not shown when
129 // created initially)
132 // success: wxApp::OnRun() will be called which will enter the main message
133 // loop and the application will run. If we returned FALSE here, the
134 // application would exit immediately.
138 class FrameAccessible
: public wxWindowAccessible
141 FrameAccessible(wxWindow
* win
): wxWindowAccessible(win
) {}
143 // Gets the name of the specified object.
144 virtual wxAccStatus
GetName(int childId
, wxString
* name
)
147 if (childId
== wxACC_SELF
)
149 * name
= wxT("Julian's Frame");
154 return wxACC_NOT_IMPLEMENTED
;
158 class ScrolledWindowAccessible
: public wxWindowAccessible
161 ScrolledWindowAccessible(wxWindow
* win
): wxWindowAccessible(win
) {}
163 // Gets the name of the specified object.
164 virtual wxAccStatus
GetName(int childId
, wxString
* name
)
166 if (childId
== wxACC_SELF
)
168 * name
= wxT("My scrolled window");
172 return wxACC_NOT_IMPLEMENTED
;
176 // ----------------------------------------------------------------------------
178 // ----------------------------------------------------------------------------
181 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
, long style
)
182 : wxFrame(NULL
, -1, title
, pos
, size
, style
)
184 SetAccessible(new FrameAccessible(this));
186 // set the frame icon
187 SetIcon(wxICON(mondrian
));
191 wxMenu
*menuFile
= new wxMenu
;
193 // the "About" item should be in the help menu
194 wxMenu
*helpMenu
= new wxMenu
;
195 helpMenu
->Append(AccessTest_About
, _T("&About...\tF1"), _T("Show about dialog"));
197 menuFile
->Append(AccessTest_Quit
, _T("E&xit\tAlt-X"), _T("Quit this program"));
199 // now append the freshly created menu to the menu bar...
200 wxMenuBar
*menuBar
= new wxMenuBar();
201 menuBar
->Append(menuFile
, _T("&File"));
202 menuBar
->Append(helpMenu
, _T("&Help"));
204 // ... and attach this menu bar to the frame
206 #endif // wxUSE_MENUS
209 // create a status bar just for fun (by default with 1 pane only)
211 SetStatusText(_T("Welcome to wxWindows!"));
212 #endif // wxUSE_STATUSBAR
215 wxListBox
* listBox
= new wxListBox(this, -1);
216 listBox
->SetAccessible(new ScrolledWindowAccessible(listBox
));
218 wxScrolledWindow
* scrolledWindow
= new wxScrolledWindow(this, -1);
219 scrolledWindow
->SetAccessible(new ScrolledWindowAccessible(scrolledWindow
));
226 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
228 // TRUE is to force the frame to close
232 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
235 msg
.Printf( _T("This is the About dialog of the AccessTest sample.\n")
236 _T("Welcome to %s"), wxVERSION_STRING
);
238 wxMessageBox(msg
, _T("About AccessTest"), wxOK
| wxICON_INFORMATION
, this);