+// we need a dummy app object if the user doesn't want to create a real one
+class wxDummyConsoleApp : public wxAppConsole
+{
+public:
+ virtual int OnRun() { wxFAIL_MSG( _T("unreachable code") ); return 0; }
+};
+
+// we need a special kind of auto pointer to wxApp which not only deletes the
+// pointer it holds in its dtor but also resets wxTheApp
+wxDECLARE_SCOPED_PTR(wxApp, wxAppPtrBase);
+wxDEFINE_SCOPED_PTR(wxApp, wxAppPtrBase);
+
+class wxAppPtr : public wxAppPtrBase
+{
+public:
+ wxEXPLICIT wxAppPtr(wxApp *ptr = NULL) : wxAppPtrBase(ptr) { }
+ ~wxAppPtr()
+ {
+ if ( get() )
+ {
+ // the pointer is going to be deleted in the base class dtor, don't
+ // leave the dangling pointer!
+ wxTheApp = NULL;
+ }
+ }
+
+ void Set(wxApp *ptr)
+ {
+ reset(ptr);
+
+ wxTheApp = ptr;
+ }
+};
+
+// class to ensure that wxAppBase::CleanUp() is called if our Initialize()
+// fails
+class wxCallAppCleanup
+{
+public:
+ wxCallAppCleanup(wxApp *app) : m_app(app) { }
+ ~wxCallAppCleanup() { if ( m_app ) m_app->CleanUp(); }
+
+ void Dismiss() { m_app = NULL; }
+
+private:
+ wxApp *m_app;
+};
+
+// another tiny class which simply exists to ensure that wxEntryCleanup is
+// always called
+class wxCleanupOnExit