1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/palmos/app.cpp
4 // Author: William Osborne - minimal working wxPalmOS port
8 // Copyright: (c) William Osborne
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
23 #if defined(__BORLANDC__)
28 #include "wx/dynarray.h"
32 #include "wx/gdicmn.h"
35 #include "wx/cursor.h"
37 #include "wx/palette.h"
39 #include "wx/dialog.h"
40 #include "wx/msgdlg.h"
42 #include "wx/wxchar.h"
44 #include "wx/module.h"
47 #include "wx/apptrait.h"
48 #include "wx/filename.h"
49 #include "wx/dynlib.h"
50 #include "wx/evtloop.h"
53 #include "wx/tooltip.h"
54 #endif // wxUSE_TOOLTIPS
56 // We don't support OLE
63 // ---------------------------------------------------------------------------
65 // ---------------------------------------------------------------------------
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");
76 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
80 // ===========================================================================
81 // wxGUIAppTraits implementation
82 // ===========================================================================
84 // private class which we use to pass parameters from BeforeChildWaitLoop() to
85 // AfterChildWaitLoop()
86 struct ChildWaitLoopData
88 ChildWaitLoopData(wxWindowDisabler
*wd_
, wxWindow
*winActive_
)
91 winActive
= winActive_
;
98 void *wxGUIAppTraits::BeforeChildWaitLoop()
103 void wxGUIAppTraits::AlwaysYield()
108 void wxGUIAppTraits::AfterChildWaitLoop(void *dataOrig
)
112 bool wxGUIAppTraits::DoMessageFromThreadWait()
117 wxPortId
wxGUIAppTraits::GetToolkitVersion(int *majVer
, int *minVer
) const
119 // TODO: how to get PalmOS GUI system version ?
120 return wxPORT_PALMOS
;
123 wxTimerImpl
* wxGUIAppTraits::CreateTimerImpl(wxTimer
*timer
)
125 return new wxPalmOSTimerImpl(timer
);
128 wxEventLoopBase
* wxGUIAppTraits::CreateEventLoop()
130 return new wxEventLoop
;
132 // ===========================================================================
133 // wxApp implementation
134 // ===========================================================================
136 int wxApp::m_nCmdShow
= 0;
138 // ---------------------------------------------------------------------------
140 // ---------------------------------------------------------------------------
142 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
144 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
145 EVT_IDLE(wxApp::OnIdle
)
146 EVT_END_SESSION(wxApp::OnEndSession
)
147 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
150 // class to ensure that wxAppBase::CleanUp() is called if our Initialize()
152 class wxCallBaseCleanup
155 wxCallBaseCleanup(wxApp
*app
) : m_app(app
) { }
156 ~wxCallBaseCleanup() { if ( m_app
) m_app
->wxAppBase::CleanUp(); }
158 void Dismiss() { m_app
= NULL
; }
165 bool wxApp::Initialize(int& argc
, wxChar
**argv
)
167 if ( !wxAppBase::Initialize(argc
, argv
) )
170 // ensure that base cleanup is done if we return too early
171 wxCallBaseCleanup
callBaseCleanup(this);
173 wxWinHandleHash
= new wxWinHashTable(wxKEY_INTEGER
, 100);
175 callBaseCleanup
.Dismiss();
180 // ---------------------------------------------------------------------------
181 // RegisterWindowClasses
182 // ---------------------------------------------------------------------------
184 // TODO we should only register classes really used by the app. For this it
185 // would be enough to just delay the class registration until an attempt
186 // to create a window of this class is made.
187 bool wxApp::RegisterWindowClasses()
192 // ---------------------------------------------------------------------------
193 // UnregisterWindowClasses
194 // ---------------------------------------------------------------------------
196 bool wxApp::UnregisterWindowClasses()
202 void wxApp::CleanUp()
204 // all objects pending for deletion must be deleted first, otherwise we
205 // would crash when they use wxWinHandleHash (and UnregisterWindowClasses()
206 // call wouldn't succeed as long as any windows still exist), so call the
207 // base class method first and only then do our clean up
208 wxAppBase::CleanUp();
210 // for an EXE the classes are unregistered when it terminates but DLL may
211 // be loaded several times (load/unload/load) into the same process in
212 // which case the registration will fail after the first time if we don't
213 // unregister the classes now
214 UnregisterWindowClasses();
216 delete wxWinHandleHash
;
217 wxWinHandleHash
= NULL
;
220 // ----------------------------------------------------------------------------
222 // ----------------------------------------------------------------------------
226 m_printMode
= wxPRINT_WINDOWS
;
231 // our cmd line arguments are allocated inside wxEntry(HINSTANCE), they
232 // don't come from main(), so we have to free them
236 // m_argv elements were allocated by wxStrdup()
240 // but m_argv itself -- using new[]
244 // ----------------------------------------------------------------------------
245 // wxApp idle handling
246 // ----------------------------------------------------------------------------
248 void wxApp::OnIdle(wxIdleEvent
& event
)
250 wxAppBase::OnIdle(event
);
253 void wxApp::WakeUpIdle()
257 // ----------------------------------------------------------------------------
258 // other wxApp event hanlders
259 // ----------------------------------------------------------------------------
261 void wxApp::OnEndSession(wxCloseEvent
& WXUNUSED(event
))
264 GetTopWindow()->Close(true);
267 // Default behaviour: close the application with prompts. The
268 // user can veto the close, and therefore the end session.
269 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
273 if (!GetTopWindow()->Close(!event
.CanVeto()))
278 // ----------------------------------------------------------------------------
280 // ----------------------------------------------------------------------------
283 int wxApp::GetComCtl32Version()
288 // Yield to incoming messages
290 bool wxApp::Yield(bool onlyIfNeeded
)
297 // ----------------------------------------------------------------------------
298 // exception handling
299 // ----------------------------------------------------------------------------
301 bool wxApp::OnExceptionInMainLoop()
306 #endif // wxUSE_EXCEPTIONS