/src/wxwidgets/include/wx/init.h
Line | Count | Source |
1 | | /////////////////////////////////////////////////////////////////////////////// |
2 | | // Name: wx/init.h |
3 | | // Purpose: wxWidgets initialization and finalization functions |
4 | | // Author: Vadim Zeitlin |
5 | | // Created: 29.06.2003 |
6 | | // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org> |
7 | | // Licence: wxWindows licence |
8 | | /////////////////////////////////////////////////////////////////////////////// |
9 | | |
10 | | #ifndef _WX_INIT_H_ |
11 | | #define _WX_INIT_H_ |
12 | | |
13 | | #include "wx/defs.h" |
14 | | #include "wx/chartype.h" |
15 | | |
16 | | // ---------------------------------------------------------------------------- |
17 | | // wxEntry helper functions which allow to have more fine grained control |
18 | | // ---------------------------------------------------------------------------- |
19 | | |
20 | | // do common initialization, return true if ok (in this case wxEntryCleanup |
21 | | // must be called later), otherwise the program can't use wxWidgets at all |
22 | | // |
23 | | // this function also creates wxTheApp as a side effect, if wxIMPLEMENT_APP |
24 | | // hadn't been used a dummy default application object is created |
25 | | // |
26 | | // note that the parameters may be modified, this is why we pass them by |
27 | | // reference! |
28 | | extern bool WXDLLIMPEXP_BASE wxEntryStart(int& argc, wxChar **argv); |
29 | | |
30 | | // free the resources allocated by the library in wxEntryStart() and shut it |
31 | | // down (wxEntryStart() may be called again afterwards if necessary) |
32 | | extern void WXDLLIMPEXP_BASE wxEntryCleanup(); |
33 | | |
34 | | |
35 | | // ---------------------------------------------------------------------------- |
36 | | // wxEntry: this function initializes the library, runs the main event loop |
37 | | // and cleans it up |
38 | | // ---------------------------------------------------------------------------- |
39 | | |
40 | | // note that other, platform-specific, overloads of wxEntry may exist as well |
41 | | // but this one always exists under all platforms |
42 | | // |
43 | | // returns the program exit code |
44 | | extern int WXDLLIMPEXP_BASE wxEntry(int& argc, wxChar **argv); |
45 | | |
46 | | // we overload wxEntry[Start]() to take "char **" pointers too |
47 | | extern bool WXDLLIMPEXP_BASE wxEntryStart(int& argc, char **argv); |
48 | | extern int WXDLLIMPEXP_BASE wxEntry(int& argc, char **argv); |
49 | | |
50 | | // Under Windows we define additional wxEntry() overloads with signature |
51 | | // compatible with WinMain() and not the traditional main(). |
52 | | #ifdef __WINDOWS__ |
53 | | #include "wx/msw/init.h" |
54 | | #endif |
55 | | |
56 | | // ---------------------------------------------------------------------------- |
57 | | // Using the library without (explicit) application object: you may avoid using |
58 | | // wxDECLARE_APP and wxIMPLEMENT_APP macros and call the functions below instead at |
59 | | // the program startup and termination |
60 | | // ---------------------------------------------------------------------------- |
61 | | |
62 | | // initialize the library (may be called as many times as needed, but each |
63 | | // call to wxInitialize() must be matched by wxUninitialize()) |
64 | | extern bool WXDLLIMPEXP_BASE wxInitialize(); |
65 | | extern bool WXDLLIMPEXP_BASE wxInitialize(int& argc, wxChar **argv); |
66 | | extern bool WXDLLIMPEXP_BASE wxInitialize(int& argc, char **argv); |
67 | | |
68 | | // clean up -- the library can't be used any more after the last call to |
69 | | // wxUninitialize() |
70 | | extern void WXDLLIMPEXP_BASE wxUninitialize(); |
71 | | |
72 | | // create an object of this class on stack to initialize/cleanup the library |
73 | | // automatically |
74 | | class WXDLLIMPEXP_BASE wxInitializer |
75 | | { |
76 | | public: |
77 | | // initialize the library |
78 | | wxInitializer() |
79 | 0 | { |
80 | 0 | m_ok = wxInitialize(); |
81 | 0 | } |
82 | | |
83 | | wxInitializer(int& argc, wxChar **argv) |
84 | 0 | { |
85 | 0 | m_ok = wxInitialize(argc, argv); |
86 | 0 | } |
87 | | |
88 | | wxInitializer(int& argc, char **argv) |
89 | 0 | { |
90 | 0 | m_ok = wxInitialize(argc, argv); |
91 | 0 | } |
92 | | |
93 | | // has the initialization been successful? (explicit test) |
94 | 0 | bool IsOk() const { return m_ok; } |
95 | | |
96 | | // has the initialization been successful? (implicit test) |
97 | 0 | operator bool() const { return m_ok; } |
98 | | |
99 | | // dtor only does clean up if we initialized the library properly |
100 | 0 | ~wxInitializer() { if ( m_ok ) wxUninitialize(); } |
101 | | |
102 | | private: |
103 | | bool m_ok; |
104 | | }; |
105 | | |
106 | | #endif // _WX_INIT_H_ |
107 | | |