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