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