many changes; major ones:
[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 // ----------------------------------------------------------------------------
37 // private classes
38 // ----------------------------------------------------------------------------
39
40 class /* no WXDLLEXPORT */ wxConsoleApp : public wxApp
41 {
42 public:
43 virtual int OnRun() { wxFAIL_MSG(T("unreachable")); return 0; }
44 };
45
46 // ----------------------------------------------------------------------------
47 // private vars
48 // ----------------------------------------------------------------------------
49
50 static size_t gs_nInitCount = 0;
51
52 // ============================================================================
53 // implementation
54 // ============================================================================
55
56 bool WXDLLEXPORT wxInitialize()
57 {
58 if ( gs_nInitCount++ )
59 {
60 // already initialized
61 return TRUE;
62 }
63
64 wxASSERT_MSG( !wxTheApp,
65 T("either call wxInitialize or create app, not both!") );
66
67 wxTheApp = new wxConsoleApp;
68
69 return wxTheApp != NULL;
70 }
71
72 void WXDLLEXPORT wxUninitialize()
73 {
74 if ( !--gs_nInitCount )
75 {
76 // delete the application object
77 delete wxTheApp;
78 wxTheApp = (wxApp *)NULL;
79 }
80 }