1. wxBase compiles/links again
[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 // ----------------------------------------------------------------------------
64 // stubs for some GUI functions
65 // ----------------------------------------------------------------------------
66
67 void WXDLLEXPORT wxExit()
68 {
69 abort();
70 }
71
72 // Yield to other apps/messages
73 bool WXDLLEXPORT wxYield()
74 {
75 // do nothing
76 return TRUE;
77 }
78
79 // Yield to other apps/messages
80 void WXDLLEXPORT wxWakeUpIdle()
81 {
82 // do nothing
83 }
84
85 // ----------------------------------------------------------------------------
86 // wxBase-specific functions
87 // ----------------------------------------------------------------------------
88
89 bool WXDLLEXPORT wxInitialize()
90 {
91 if ( gs_nInitCount )
92 {
93 // already initialized
94 return TRUE;
95 }
96
97 wxASSERT_MSG( !wxTheApp,
98 wxT("either call wxInitialize or create app, not both!") );
99
100 wxClassInfo::InitializeClasses();
101
102 wxModule::RegisterModules();
103 if ( !wxModule::InitializeModules() )
104 {
105 return FALSE;
106 }
107
108 wxTheApp = new wxConsoleApp;
109
110 if ( !wxTheApp )
111 {
112 return FALSE;
113 }
114
115 gs_nInitCount++;
116
117 return TRUE;
118 }
119
120 void WXDLLEXPORT wxUninitialize()
121 {
122 if ( !--gs_nInitCount )
123 {
124 wxModule::CleanUpModules();
125
126 wxClassInfo::CleanUpClasses();
127
128 // delete the application object
129 delete wxTheApp;
130 wxTheApp = (wxApp *)NULL;
131 }
132 }