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" 
  52     #include "wx/tooltip.h" 
  53 #endif // wxUSE_TOOLTIPS 
  55 // We don't support OLE 
  62 // --------------------------------------------------------------------------- 
  64 // --------------------------------------------------------------------------- 
  66 // NB: all "NoRedraw" classes must have the same names as the "normal" classes 
  67 //     with NR suffix - wxWindow::MSWCreate() supposes this 
  68 const wxChar 
*wxCanvasClassName        
= wxT("wxWindowClass"); 
  69 const wxChar 
*wxCanvasClassNameNR      
= wxT("wxWindowClassNR"); 
  70 const wxChar 
*wxMDIFrameClassName      
= wxT("wxMDIFrameClass"); 
  71 const wxChar 
*wxMDIFrameClassNameNoRedraw 
= wxT("wxMDIFrameClassNR"); 
  72 const wxChar 
*wxMDIChildFrameClassName 
= wxT("wxMDIChildFrameClass"); 
  73 const wxChar 
*wxMDIChildFrameClassNameNoRedraw 
= wxT("wxMDIChildFrameClassNR"); 
  75 // ---------------------------------------------------------------------------- 
  77 // ---------------------------------------------------------------------------- 
  79 // =========================================================================== 
  80 // wxGUIAppTraits implementation 
  81 // =========================================================================== 
  83 // private class which we use to pass parameters from BeforeChildWaitLoop() to 
  84 // AfterChildWaitLoop() 
  85 struct ChildWaitLoopData
 
  87     ChildWaitLoopData(wxWindowDisabler 
*wd_
, wxWindow 
*winActive_
) 
  90         winActive 
= winActive_
; 
  97 void *wxGUIAppTraits::BeforeChildWaitLoop() 
 102 void wxGUIAppTraits::AlwaysYield() 
 107 void wxGUIAppTraits::AfterChildWaitLoop(void *dataOrig
) 
 111 bool wxGUIAppTraits::DoMessageFromThreadWait() 
 116 wxPortId 
wxGUIAppTraits::GetToolkitVersion(int *majVer
, int *minVer
) const 
 118     // TODO: how to get PalmOS GUI system version ? 
 119     return wxPORT_PALMOS
; 
 122 // =========================================================================== 
 123 // wxApp implementation 
 124 // =========================================================================== 
 126 int wxApp::m_nCmdShow 
= 0; 
 128 // --------------------------------------------------------------------------- 
 130 // --------------------------------------------------------------------------- 
 132 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
) 
 134 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
) 
 135     EVT_IDLE(wxApp::OnIdle
) 
 136     EVT_END_SESSION(wxApp::OnEndSession
) 
 137     EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
) 
 140 // class to ensure that wxAppBase::CleanUp() is called if our Initialize() 
 142 class wxCallBaseCleanup
 
 145     wxCallBaseCleanup(wxApp 
*app
) : m_app(app
) { } 
 146     ~wxCallBaseCleanup() { if ( m_app 
) m_app
->wxAppBase::CleanUp(); } 
 148     void Dismiss() { m_app 
= NULL
; } 
 155 bool wxApp::Initialize(int& argc
, wxChar 
**argv
) 
 157     if ( !wxAppBase::Initialize(argc
, argv
) ) 
 160     // ensure that base cleanup is done if we return too early 
 161     wxCallBaseCleanup 
callBaseCleanup(this); 
 163     wxWinHandleHash 
= new wxWinHashTable(wxKEY_INTEGER
, 100); 
 165     callBaseCleanup
.Dismiss(); 
 170 // --------------------------------------------------------------------------- 
 171 // RegisterWindowClasses 
 172 // --------------------------------------------------------------------------- 
 174 // TODO we should only register classes really used by the app. For this it 
 175 //      would be enough to just delay the class registration until an attempt 
 176 //      to create a window of this class is made. 
 177 bool wxApp::RegisterWindowClasses() 
 182 // --------------------------------------------------------------------------- 
 183 // UnregisterWindowClasses 
 184 // --------------------------------------------------------------------------- 
 186 bool wxApp::UnregisterWindowClasses() 
 192 void wxApp::CleanUp() 
 194     // all objects pending for deletion must be deleted first, otherwise we 
 195     // would crash when they use wxWinHandleHash (and UnregisterWindowClasses() 
 196     // call wouldn't succeed as long as any windows still exist), so call the 
 197     // base class method first and only then do our clean up 
 198     wxAppBase::CleanUp(); 
 200     // for an EXE the classes are unregistered when it terminates but DLL may 
 201     // be loaded several times (load/unload/load) into the same process in 
 202     // which case the registration will fail after the first time if we don't 
 203     // unregister the classes now 
 204     UnregisterWindowClasses(); 
 206     delete wxWinHandleHash
; 
 207     wxWinHandleHash 
= NULL
; 
 210 // ---------------------------------------------------------------------------- 
 212 // ---------------------------------------------------------------------------- 
 216     m_printMode 
= wxPRINT_WINDOWS
; 
 221     // our cmd line arguments are allocated inside wxEntry(HINSTANCE), they 
 222     // don't come from main(), so we have to free them 
 226         // m_argv elements were allocated by wxStrdup() 
 230     // but m_argv itself -- using new[] 
 234 // ---------------------------------------------------------------------------- 
 235 // wxApp idle handling 
 236 // ---------------------------------------------------------------------------- 
 238 void wxApp::OnIdle(wxIdleEvent
& event
) 
 240     wxAppBase::OnIdle(event
); 
 243 void wxApp::WakeUpIdle() 
 247 // ---------------------------------------------------------------------------- 
 248 // other wxApp event hanlders 
 249 // ---------------------------------------------------------------------------- 
 251 void wxApp::OnEndSession(wxCloseEvent
& WXUNUSED(event
)) 
 254         GetTopWindow()->Close(true); 
 257 // Default behaviour: close the application with prompts. The 
 258 // user can veto the close, and therefore the end session. 
 259 void wxApp::OnQueryEndSession(wxCloseEvent
& event
) 
 263         if (!GetTopWindow()->Close(!event
.CanVeto())) 
 268 // ---------------------------------------------------------------------------- 
 270 // ---------------------------------------------------------------------------- 
 273 int wxApp::GetComCtl32Version() 
 278 // Yield to incoming messages 
 280 bool wxApp::Yield(bool onlyIfNeeded
) 
 287 // ---------------------------------------------------------------------------- 
 288 // exception handling 
 289 // ---------------------------------------------------------------------------- 
 291 bool wxApp::OnExceptionInMainLoop() 
 296 #endif // wxUSE_EXCEPTIONS