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