]> git.saurik.com Git - wxWidgets.git/blob - src/palmos/app.cpp
preparation for allowing to use wxTimer in wxBase (heavily modified patch 1113088):
[wxWidgets.git] / src / palmos / app.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/palmos/app.cpp
3 // Purpose: wxApp
4 // Author: William Osborne - minimal working wxPalmOS port
5 // Modified by:
6 // Created: 10/08/04
7 // RCS-ID: $Id$
8 // Copyright: (c) William Osborne
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ===========================================================================
13 // declarations
14 // ===========================================================================
15
16 // ---------------------------------------------------------------------------
17 // headers
18 // ---------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #if defined(__BORLANDC__)
24 #pragma hdrstop
25 #endif
26
27 #ifndef WX_PRECOMP
28 #include "wx/dynarray.h"
29 #include "wx/frame.h"
30 #include "wx/app.h"
31 #include "wx/utils.h"
32 #include "wx/gdicmn.h"
33 #include "wx/pen.h"
34 #include "wx/brush.h"
35 #include "wx/cursor.h"
36 #include "wx/icon.h"
37 #include "wx/palette.h"
38 #include "wx/dc.h"
39 #include "wx/dialog.h"
40 #include "wx/msgdlg.h"
41 #include "wx/intl.h"
42 #include "wx/wxchar.h"
43 #include "wx/log.h"
44 #include "wx/module.h"
45 #endif
46
47 #include "wx/apptrait.h"
48 #include "wx/filename.h"
49 #include "wx/dynlib.h"
50
51 #if wxUSE_TOOLTIPS
52 #include "wx/tooltip.h"
53 #endif // wxUSE_TOOLTIPS
54
55 // We don't support OLE
56 #undef wxUSE_OLE
57 #define wxUSE_OLE 0
58
59 #include <string.h>
60 #include <ctype.h>
61
62 // ---------------------------------------------------------------------------
63 // global variables
64 // ---------------------------------------------------------------------------
65
66 // NB: all "NoRedraw" classes must have the same names as the "normal" classes
67 // with NR suffix - wxWindow::MSWCreate() supposes this
68 const wxChar *wxCanvasClassName = wxT("wxWindowClass");
69 const wxChar *wxCanvasClassNameNR = wxT("wxWindowClassNR");
70 const wxChar *wxMDIFrameClassName = wxT("wxMDIFrameClass");
71 const wxChar *wxMDIFrameClassNameNoRedraw = wxT("wxMDIFrameClassNR");
72 const wxChar *wxMDIChildFrameClassName = wxT("wxMDIChildFrameClass");
73 const wxChar *wxMDIChildFrameClassNameNoRedraw = wxT("wxMDIChildFrameClassNR");
74
75 // ----------------------------------------------------------------------------
76 // private functions
77 // ----------------------------------------------------------------------------
78
79 // ===========================================================================
80 // wxGUIAppTraits implementation
81 // ===========================================================================
82
83 // private class which we use to pass parameters from BeforeChildWaitLoop() to
84 // AfterChildWaitLoop()
85 struct ChildWaitLoopData
86 {
87 ChildWaitLoopData(wxWindowDisabler *wd_, wxWindow *winActive_)
88 {
89 wd = wd_;
90 winActive = winActive_;
91 }
92
93 wxWindowDisabler *wd;
94 wxWindow *winActive;
95 };
96
97 void *wxGUIAppTraits::BeforeChildWaitLoop()
98 {
99 return NULL;
100 }
101
102 void wxGUIAppTraits::AlwaysYield()
103 {
104 wxYield();
105 }
106
107 void wxGUIAppTraits::AfterChildWaitLoop(void *dataOrig)
108 {
109 }
110
111 bool wxGUIAppTraits::DoMessageFromThreadWait()
112 {
113 return false;
114 }
115
116 wxPortId wxGUIAppTraits::GetToolkitVersion(int *majVer, int *minVer) const
117 {
118 // TODO: how to get PalmOS GUI system version ?
119 return wxPORT_PALMOS;
120 }
121
122 wxTimerImpl* wxGUIAppTraits::CreateTimerImpl(wxTimer *timer)
123 {
124 return new wxPalmOSTimerImpl(timer);
125 };
126 // ===========================================================================
127 // wxApp implementation
128 // ===========================================================================
129
130 int wxApp::m_nCmdShow = 0;
131
132 // ---------------------------------------------------------------------------
133 // wxWin macros
134 // ---------------------------------------------------------------------------
135
136 IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
137
138 BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
139 EVT_IDLE(wxApp::OnIdle)
140 EVT_END_SESSION(wxApp::OnEndSession)
141 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession)
142 END_EVENT_TABLE()
143
144 // class to ensure that wxAppBase::CleanUp() is called if our Initialize()
145 // fails
146 class wxCallBaseCleanup
147 {
148 public:
149 wxCallBaseCleanup(wxApp *app) : m_app(app) { }
150 ~wxCallBaseCleanup() { if ( m_app ) m_app->wxAppBase::CleanUp(); }
151
152 void Dismiss() { m_app = NULL; }
153
154 private:
155 wxApp *m_app;
156 };
157
158 //// Initialize
159 bool wxApp::Initialize(int& argc, wxChar **argv)
160 {
161 if ( !wxAppBase::Initialize(argc, argv) )
162 return false;
163
164 // ensure that base cleanup is done if we return too early
165 wxCallBaseCleanup callBaseCleanup(this);
166
167 wxWinHandleHash = new wxWinHashTable(wxKEY_INTEGER, 100);
168
169 callBaseCleanup.Dismiss();
170
171 return true;
172 }
173
174 // ---------------------------------------------------------------------------
175 // RegisterWindowClasses
176 // ---------------------------------------------------------------------------
177
178 // TODO we should only register classes really used by the app. For this it
179 // would be enough to just delay the class registration until an attempt
180 // to create a window of this class is made.
181 bool wxApp::RegisterWindowClasses()
182 {
183 return true;
184 }
185
186 // ---------------------------------------------------------------------------
187 // UnregisterWindowClasses
188 // ---------------------------------------------------------------------------
189
190 bool wxApp::UnregisterWindowClasses()
191 {
192 bool retval = true;
193 return retval;
194 }
195
196 void wxApp::CleanUp()
197 {
198 // all objects pending for deletion must be deleted first, otherwise we
199 // would crash when they use wxWinHandleHash (and UnregisterWindowClasses()
200 // call wouldn't succeed as long as any windows still exist), so call the
201 // base class method first and only then do our clean up
202 wxAppBase::CleanUp();
203
204 // for an EXE the classes are unregistered when it terminates but DLL may
205 // be loaded several times (load/unload/load) into the same process in
206 // which case the registration will fail after the first time if we don't
207 // unregister the classes now
208 UnregisterWindowClasses();
209
210 delete wxWinHandleHash;
211 wxWinHandleHash = NULL;
212 }
213
214 // ----------------------------------------------------------------------------
215 // wxApp ctor/dtor
216 // ----------------------------------------------------------------------------
217
218 wxApp::wxApp()
219 {
220 m_printMode = wxPRINT_WINDOWS;
221 }
222
223 wxApp::~wxApp()
224 {
225 // our cmd line arguments are allocated inside wxEntry(HINSTANCE), they
226 // don't come from main(), so we have to free them
227
228 while ( argc )
229 {
230 // m_argv elements were allocated by wxStrdup()
231 free(argv[--argc]);
232 }
233
234 // but m_argv itself -- using new[]
235 delete [] argv;
236 }
237
238 // ----------------------------------------------------------------------------
239 // wxApp idle handling
240 // ----------------------------------------------------------------------------
241
242 void wxApp::OnIdle(wxIdleEvent& event)
243 {
244 wxAppBase::OnIdle(event);
245 }
246
247 void wxApp::WakeUpIdle()
248 {
249 }
250
251 // ----------------------------------------------------------------------------
252 // other wxApp event hanlders
253 // ----------------------------------------------------------------------------
254
255 void wxApp::OnEndSession(wxCloseEvent& WXUNUSED(event))
256 {
257 if (GetTopWindow())
258 GetTopWindow()->Close(true);
259 }
260
261 // Default behaviour: close the application with prompts. The
262 // user can veto the close, and therefore the end session.
263 void wxApp::OnQueryEndSession(wxCloseEvent& event)
264 {
265 if (GetTopWindow())
266 {
267 if (!GetTopWindow()->Close(!event.CanVeto()))
268 event.Veto(true);
269 }
270 }
271
272 // ----------------------------------------------------------------------------
273 // miscellaneous
274 // ----------------------------------------------------------------------------
275
276 /* static */
277 int wxApp::GetComCtl32Version()
278 {
279 return 0;
280 }
281
282 // Yield to incoming messages
283
284 bool wxApp::Yield(bool onlyIfNeeded)
285 {
286 return true;
287 }
288
289 #if wxUSE_EXCEPTIONS
290
291 // ----------------------------------------------------------------------------
292 // exception handling
293 // ----------------------------------------------------------------------------
294
295 bool wxApp::OnExceptionInMainLoop()
296 {
297 return true;
298 }
299
300 #endif // wxUSE_EXCEPTIONS