1. made wxBase compile/link/run again under Unix
[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 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif //__BORLANDC__
25
26 #ifndef WX_PRECOMP
27 #include "wx/app.h"
28 #include "wx/debug.h"
29 #include "wx/module.h"
30 #endif
31
32 // ----------------------------------------------------------------------------
33 // global vars
34 // ----------------------------------------------------------------------------
35
36 wxApp * WXDLLEXPORT wxTheApp = NULL;
37
38 wxAppInitializerFunction
39 wxAppBase::m_appInitFn = (wxAppInitializerFunction)NULL;
40
41 // ----------------------------------------------------------------------------
42 // private classes
43 // ----------------------------------------------------------------------------
44
45 class /* no WXDLLEXPORT */ wxConsoleApp : public wxApp
46 {
47 public:
48 virtual int OnRun() { wxFAIL_MSG(wxT("unreachable")); return 0; }
49 };
50
51 // ----------------------------------------------------------------------------
52 // private vars
53 // ----------------------------------------------------------------------------
54
55 static size_t gs_nInitCount = 0;
56
57 // ============================================================================
58 // implementation
59 // ============================================================================
60
61 bool WXDLLEXPORT wxInitialize()
62 {
63 if ( gs_nInitCount )
64 {
65 // already initialized
66 return TRUE;
67 }
68
69 wxASSERT_MSG( !wxTheApp,
70 wxT("either call wxInitialize or create app, not both!") );
71
72 wxClassInfo::InitializeClasses();
73
74 wxModule::RegisterModules();
75 if ( !wxModule::InitializeModules() )
76 {
77 return FALSE;
78 }
79
80 wxTheApp = new wxConsoleApp;
81
82 if ( !wxTheApp )
83 {
84 return FALSE;
85 }
86
87 gs_nInitCount++;
88
89 return TRUE;
90 }
91
92 void WXDLLEXPORT wxUninitialize()
93 {
94 if ( !--gs_nInitCount )
95 {
96 wxModule::CleanUpModules();
97
98 wxClassInfo::CleanUpClasses();
99
100 // delete the application object
101 delete wxTheApp;
102 wxTheApp = (wxApp *)NULL;
103 }
104 }