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