]> git.saurik.com Git - wxWidgets.git/blob - src/common/init.cpp
fopen -> wxFopen and such
[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 #endif
30
31 #include "wx/module.h"
32
33
34 // ----------------------------------------------------------------------------
35 // global vars
36 // ----------------------------------------------------------------------------
37
38 wxApp * WXDLLEXPORT wxTheApp = NULL;
39
40 wxAppInitializerFunction
41 wxAppBase::m_appInitFn = (wxAppInitializerFunction)NULL;
42
43 // ----------------------------------------------------------------------------
44 // private classes
45 // ----------------------------------------------------------------------------
46
47 class /* no WXDLLEXPORT */ wxConsoleApp : public wxApp
48 {
49 public:
50 virtual int OnRun() { wxFAIL_MSG(wxT("unreachable")); return 0; }
51 };
52
53 // ----------------------------------------------------------------------------
54 // private vars
55 // ----------------------------------------------------------------------------
56
57 static size_t gs_nInitCount = 0;
58
59 // ============================================================================
60 // implementation
61 // ============================================================================
62
63 bool WXDLLEXPORT wxInitialize()
64 {
65 if ( gs_nInitCount )
66 {
67 // already initialized
68 return TRUE;
69 }
70
71 wxASSERT_MSG( !wxTheApp,
72 wxT("either call wxInitialize or create app, not both!") );
73
74 wxClassInfo::InitializeClasses();
75
76 wxModule::RegisterModules();
77 if ( !wxModule::InitializeModules() )
78 {
79 return FALSE;
80 }
81
82 wxTheApp = new wxConsoleApp;
83
84 if ( !wxTheApp )
85 {
86 return FALSE;
87 }
88
89 gs_nInitCount++;
90
91 return TRUE;
92 }
93
94 void WXDLLEXPORT wxUninitialize()
95 {
96 if ( !--gs_nInitCount )
97 {
98 wxModule::CleanUpModules();
99
100 wxClassInfo::CleanUpClasses();
101
102 // delete the application object
103 delete wxTheApp;
104 wxTheApp = (wxApp *)NULL;
105 }
106 }