]>
Commit | Line | Data |
---|---|---|
e90c1d2a VZ |
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 | ||
f4c890fd JS |
20 | #include "wx/wxprec.h" |
21 | ||
22 | #ifdef __BORLANDC__ | |
23 | #pragma hdrstop | |
24 | #endif //__BORLANDC__ | |
25 | ||
e87271f3 VZ |
26 | #ifndef WX_PRECOMP |
27 | #include "wx/app.h" | |
28 | #include "wx/debug.h" | |
e87271f3 | 29 | #endif |
e90c1d2a | 30 | |
51abe921 SC |
31 | #include "wx/module.h" |
32 | ||
33 | ||
e90c1d2a VZ |
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: | |
223d09f6 | 50 | virtual int OnRun() { wxFAIL_MSG(wxT("unreachable")); return 0; } |
e90c1d2a VZ |
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 | { | |
bbfa0322 | 65 | if ( gs_nInitCount ) |
e90c1d2a VZ |
66 | { |
67 | // already initialized | |
68 | return TRUE; | |
69 | } | |
70 | ||
71 | wxASSERT_MSG( !wxTheApp, | |
223d09f6 | 72 | wxT("either call wxInitialize or create app, not both!") ); |
e90c1d2a | 73 | |
bbfa0322 VZ |
74 | wxClassInfo::InitializeClasses(); |
75 | ||
76 | wxModule::RegisterModules(); | |
77 | if ( !wxModule::InitializeModules() ) | |
78 | { | |
79 | return FALSE; | |
80 | } | |
81 | ||
e90c1d2a VZ |
82 | wxTheApp = new wxConsoleApp; |
83 | ||
bbfa0322 VZ |
84 | if ( !wxTheApp ) |
85 | { | |
86 | return FALSE; | |
87 | } | |
88 | ||
89 | gs_nInitCount++; | |
90 | ||
91 | return TRUE; | |
e90c1d2a VZ |
92 | } |
93 | ||
94 | void WXDLLEXPORT wxUninitialize() | |
95 | { | |
96 | if ( !--gs_nInitCount ) | |
97 | { | |
bbfa0322 VZ |
98 | wxModule::CleanUpModules(); |
99 | ||
100 | wxClassInfo::CleanUpClasses(); | |
101 | ||
e90c1d2a VZ |
102 | // delete the application object |
103 | delete wxTheApp; | |
104 | wxTheApp = (wxApp *)NULL; | |
105 | } | |
106 | } |