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