]> git.saurik.com Git - wxWidgets.git/blob - src/palmos/app.cpp
implement wxGTK wxBitmapButton in terms of wxButton
[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/crt.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 #include "wx/evtloop.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 // 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
103 void wxGUIAppTraits::AfterChildWaitLoop(void *dataOrig)
104 {
105 }
106
107 bool wxGUIAppTraits::DoMessageFromThreadWait()
108 {
109 return false;
110 }
111
112 wxPortId wxGUIAppTraits::GetToolkitVersion(int *majVer, int *minVer) const
113 {
114 // TODO: how to get PalmOS GUI system version ?
115 return wxPORT_PALMOS;
116 }
117
118 #if wxUSE_TIMER
119 wxTimerImpl* wxGUIAppTraits::CreateTimerImpl(wxTimer *timer)
120 {
121 return new wxPalmOSTimerImpl(timer);
122 };
123 #endif // wxUSE_TIMER
124
125 wxEventLoopBase* wxGUIAppTraits::CreateEventLoop()
126 {
127 return new wxEventLoop;
128 }
129 // ===========================================================================
130 // wxApp implementation
131 // ===========================================================================
132
133 int wxApp::m_nCmdShow = 0;
134
135 // ---------------------------------------------------------------------------
136 // wxWin macros
137 // ---------------------------------------------------------------------------
138
139 IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
140
141 BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
142 EVT_END_SESSION(wxApp::OnEndSession)
143 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession)
144 END_EVENT_TABLE()
145
146 // class to ensure that wxAppBase::CleanUp() is called if our Initialize()
147 // fails
148 class wxCallBaseCleanup
149 {
150 public:
151 wxCallBaseCleanup(wxApp *app) : m_app(app) { }
152 ~wxCallBaseCleanup() { if ( m_app ) m_app->wxAppBase::CleanUp(); }
153
154 void Dismiss() { m_app = NULL; }
155
156 private:
157 wxApp *m_app;
158 };
159
160 //// Initialize
161 bool wxApp::Initialize(int& argc, wxChar **argv)
162 {
163 if ( !wxAppBase::Initialize(argc, argv) )
164 return false;
165
166 // ensure that base cleanup is done if we return too early
167 wxCallBaseCleanup callBaseCleanup(this);
168
169 wxWinHandleHash = new wxWinHashTable(wxKEY_INTEGER, 100);
170
171 callBaseCleanup.Dismiss();
172
173 return true;
174 }
175
176 // ---------------------------------------------------------------------------
177 // RegisterWindowClasses
178 // ---------------------------------------------------------------------------
179
180 // TODO we should only register classes really used by the app. For this it
181 // would be enough to just delay the class registration until an attempt
182 // to create a window of this class is made.
183 bool wxApp::RegisterWindowClasses()
184 {
185 return true;
186 }
187
188 // ---------------------------------------------------------------------------
189 // UnregisterWindowClasses
190 // ---------------------------------------------------------------------------
191
192 bool wxApp::UnregisterWindowClasses()
193 {
194 bool retval = true;
195 return retval;
196 }
197
198 void wxApp::CleanUp()
199 {
200 // all objects pending for deletion must be deleted first, otherwise we
201 // would crash when they use wxWinHandleHash (and UnregisterWindowClasses()
202 // call wouldn't succeed as long as any windows still exist), so call the
203 // base class method first and only then do our clean up
204 wxAppBase::CleanUp();
205
206 // for an EXE the classes are unregistered when it terminates but DLL may
207 // be loaded several times (load/unload/load) into the same process in
208 // which case the registration will fail after the first time if we don't
209 // unregister the classes now
210 UnregisterWindowClasses();
211
212 delete wxWinHandleHash;
213 wxWinHandleHash = NULL;
214 }
215
216 // ----------------------------------------------------------------------------
217 // wxApp ctor/dtor
218 // ----------------------------------------------------------------------------
219
220 wxApp::wxApp()
221 {
222 m_printMode = wxPRINT_WINDOWS;
223 }
224
225 wxApp::~wxApp()
226 {
227 wxChar **argv_tmp;
228 argv_tmp = argv;
229 // src/palmos/main.cpp
230 // our cmd line arguments are allocated inside wxEntry(HINSTANCE), they
231 // don't come from main(), so we have to free them
232 while ( argc )
233 {
234 // m_argv elements were allocated by wxStrdup()
235 if (argv_tmp[--argc]) {
236 free((void *)(argv_tmp[--argc]));
237 }
238 }
239 // but m_argv itself -- using new[]
240 delete [] argv_tmp;
241 //argv = NULL;
242 }
243
244 // ----------------------------------------------------------------------------
245 // wxApp idle handling
246 // ----------------------------------------------------------------------------
247
248 void wxApp::WakeUpIdle()
249 {
250 }
251
252 // ----------------------------------------------------------------------------
253 // other wxApp event hanlders
254 // ----------------------------------------------------------------------------
255
256 void wxApp::OnEndSession(wxCloseEvent& WXUNUSED(event))
257 {
258 if (GetTopWindow())
259 GetTopWindow()->Close(true);
260 }
261
262 // Default behaviour: close the application with prompts. The
263 // user can veto the close, and therefore the end session.
264 void wxApp::OnQueryEndSession(wxCloseEvent& event)
265 {
266 if (GetTopWindow())
267 {
268 if (!GetTopWindow()->Close(!event.CanVeto()))
269 event.Veto(true);
270 }
271 }
272
273 // ----------------------------------------------------------------------------
274 // miscellaneous
275 // ----------------------------------------------------------------------------
276
277 /* static */
278 int wxApp::GetComCtl32Version()
279 {
280 return 0;
281 }
282
283 #if wxUSE_EXCEPTIONS
284
285 // ----------------------------------------------------------------------------
286 // exception handling
287 // ----------------------------------------------------------------------------
288
289 bool wxApp::OnExceptionInMainLoop()
290 {
291 return true;
292 }
293
294 #endif // wxUSE_EXCEPTIONS