1 /////////////////////////////////////////////////////////////////////////////
2 // Name: common/init.cpp
3 // Purpose: initialisation for the library
4 // Author: Vadim Zeitlin
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
29 #include "wx/filefn.h"
32 #include "wx/module.h"
34 // ----------------------------------------------------------------------------
36 // ----------------------------------------------------------------------------
38 wxApp
* WXDLLEXPORT wxTheApp
= NULL
;
40 wxAppInitializerFunction
41 wxAppBase::m_appInitFn
= (wxAppInitializerFunction
)NULL
;
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 class /* no WXDLLEXPORT */ wxConsoleApp
: public wxApp
50 virtual int OnRun() { wxFAIL_MSG(wxT("unreachable")); return 0; }
53 // ----------------------------------------------------------------------------
55 // ----------------------------------------------------------------------------
58 static void DoCleanUp();
60 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
64 static size_t gs_nInitCount
= 0;
66 // ============================================================================
68 // ============================================================================
70 // ----------------------------------------------------------------------------
71 // stubs for some GUI functions
72 // ----------------------------------------------------------------------------
74 void WXDLLEXPORT
wxExit()
79 // Yield to other apps/messages
80 bool WXDLLEXPORT
wxYield()
86 // Yield to other apps/messages
87 void WXDLLEXPORT
wxWakeUpIdle()
92 // ----------------------------------------------------------------------------
93 // wxBase-specific functions
94 // ----------------------------------------------------------------------------
96 bool WXDLLEXPORT
wxInitialize()
100 // already initialized
104 wxASSERT_MSG( !wxTheApp
,
105 wxT("either call wxInitialize or create app, not both!") );
112 wxTheApp
= new wxConsoleApp
;
124 void WXDLLEXPORT
wxUninitialize()
126 if ( !--gs_nInitCount
)
132 int wxEntry(int argc
, char **argv
)
134 // library initialization
143 wxCHECK_MSG( wxApp::GetInitializerFunction(), -1,
144 wxT("No application object: use IMPLEMENT_APP macro.") );
146 wxAppInitializerFunction fnCreate
= wxApp::GetInitializerFunction();
148 wxTheApp
= (wxApp
*)fnCreate();
151 wxCHECK_MSG( wxTheApp
, -1, wxT("wxWindows error: no application object") );
153 // app preinitialization
154 wxTheApp
->argc
= argc
;
157 wxTheApp
->argv
= new wxChar
*[argc
+1];
159 while (mb_argc
< argc
)
161 wxTheApp
->argv
[mb_argc
] = wxStrdup(wxConvLibc
.cMB2WX(argv
[mb_argc
]));
164 wxTheApp
->argv
[mb_argc
] = (wxChar
*)NULL
;
166 wxTheApp
->argv
= argv
;
169 wxString name
= wxFileNameFromPath(argv
[0]);
170 wxStripExtension(name
);
171 wxTheApp
->SetAppName(name
);
175 // app initialization
176 if ( !wxTheApp
->OnInit() )
182 retValue
= wxTheApp
->OnRun();
194 // ----------------------------------------------------------------------------
196 // ----------------------------------------------------------------------------
200 wxClassInfo::InitializeClasses();
202 wxModule::RegisterModules();
203 if ( !wxModule::InitializeModules() )
211 static void DoCleanUp()
214 // flush the logged messages if any
215 wxLog
*log
= wxLog::GetActiveTarget();
216 if (log
!= NULL
&& log
->HasPendingMessages())
219 // continuing to use user defined log target is unsafe from now on because
220 // some resources may be already unavailable, so replace it by something
222 wxLog
*oldlog
= wxLog::SetActiveTarget(new wxLogStderr
);
227 wxModule::CleanUpModules();
229 wxClassInfo::CleanUpClasses();
231 // delete the application object
233 wxTheApp
= (wxApp
*)NULL
;