replaced T() makro with wxT() due to namespace probs, _T() exists, too
[wxWidgets.git] / src / common / init.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: common/init.cpp
3 // Purpose: initialisation for the library
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 04.10.99
7 // RCS-ID: $Id$
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "appbase.h"
22 #endif
23
24 #include "wx/app.h"
25 #include "wx/debug.h"
26
27 // ----------------------------------------------------------------------------
28 // global vars
29 // ----------------------------------------------------------------------------
30
31 wxApp * WXDLLEXPORT wxTheApp = NULL;
32
33 wxAppInitializerFunction
34 wxAppBase::m_appInitFn = (wxAppInitializerFunction)NULL;
35
36 #if wxUSE_THREADS
37 // List of events pending processing
38 wxList *wxPendingEvents = NULL;
39 wxCriticalSection *wxPendingEventsLocker = NULL;
40 #endif // wxUSE_THREADS
41
42 // ----------------------------------------------------------------------------
43 // private classes
44 // ----------------------------------------------------------------------------
45
46 class /* no WXDLLEXPORT */ wxConsoleApp : public wxApp
47 {
48 public:
49 virtual int OnRun() { wxFAIL_MSG(wxT("unreachable")); return 0; }
50 };
51
52 // ----------------------------------------------------------------------------
53 // private vars
54 // ----------------------------------------------------------------------------
55
56 static size_t gs_nInitCount = 0;
57
58 // ============================================================================
59 // implementation
60 // ============================================================================
61
62 bool WXDLLEXPORT wxInitialize()
63 {
64 if ( gs_nInitCount )
65 {
66 // already initialized
67 return TRUE;
68 }
69
70 wxASSERT_MSG( !wxTheApp,
71 wxT("either call wxInitialize or create app, not both!") );
72
73 wxClassInfo::InitializeClasses();
74
75 wxModule::RegisterModules();
76 if ( !wxModule::InitializeModules() )
77 {
78 return FALSE;
79 }
80
81 wxTheApp = new wxConsoleApp;
82
83 if ( !wxTheApp )
84 {
85 return FALSE;
86 }
87
88 gs_nInitCount++;
89
90 return TRUE;
91 }
92
93 void WXDLLEXPORT wxUninitialize()
94 {
95 if ( !--gs_nInitCount )
96 {
97 wxModule::CleanUpModules();
98
99 wxClassInfo::CleanUpClasses();
100
101 // delete the application object
102 delete wxTheApp;
103 wxTheApp = (wxApp *)NULL;
104 }
105 }