]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: wx/app.h | |
3 | // Purpose: wxAppBase class and macros used for declaration of wxApp | |
4 | // derived class in the user code | |
5 | // Author: Julian Smart | |
6 | // Modified by: | |
7 | // Created: 01/02/97 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) Julian Smart | |
10 | // Licence: wxWindows licence | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | #ifndef _WX_APP_H_BASE_ | |
14 | #define _WX_APP_H_BASE_ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers we have to include here | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | #include "wx/event.h" // for the base class | |
21 | ||
22 | #if wxUSE_GUI | |
23 | #include "wx/window.h" // for wxTopLevelWindows | |
24 | ||
25 | #include "wx/vidmode.h" | |
26 | #endif // wxUSE_GUI | |
27 | ||
28 | #include "wx/build.h" | |
29 | #include "wx/init.h" // we must declare wxEntry() | |
30 | ||
31 | class WXDLLIMPEXP_BASE wxAppConsole; | |
32 | class WXDLLIMPEXP_BASE wxAppTraits; | |
33 | class WXDLLIMPEXP_BASE wxCmdLineParser; | |
34 | class WXDLLIMPEXP_BASE wxLog; | |
35 | class WXDLLIMPEXP_BASE wxMessageOutput; | |
36 | ||
37 | // wxUSE_EVTLOOP_IN_APP is a temporary hack needed until all ports are updated | |
38 | // to use wxEventLoop, otherwise we get linking errors on wxMac, it's going to | |
39 | // disappear a.s.a.p. | |
40 | #ifdef __WXMAC__ | |
41 | #define wxUSE_EVTLOOP_IN_APP 0 | |
42 | #else | |
43 | #define wxUSE_EVTLOOP_IN_APP 1 | |
44 | class WXDLLEXPORT wxEventLoop; | |
45 | #endif | |
46 | ||
47 | // ---------------------------------------------------------------------------- | |
48 | // typedefs | |
49 | // ---------------------------------------------------------------------------- | |
50 | ||
51 | // the type of the function used to create a wxApp object on program start up | |
52 | typedef wxAppConsole* (*wxAppInitializerFunction)(); | |
53 | ||
54 | // ---------------------------------------------------------------------------- | |
55 | // constants | |
56 | // ---------------------------------------------------------------------------- | |
57 | ||
58 | enum | |
59 | { | |
60 | wxPRINT_WINDOWS = 1, | |
61 | wxPRINT_POSTSCRIPT = 2 | |
62 | }; | |
63 | ||
64 | // ---------------------------------------------------------------------------- | |
65 | // wxAppConsole: wxApp for non-GUI applications | |
66 | // ---------------------------------------------------------------------------- | |
67 | ||
68 | class WXDLLIMPEXP_BASE wxAppConsole : public wxEvtHandler | |
69 | { | |
70 | public: | |
71 | // ctor and dtor | |
72 | wxAppConsole(); | |
73 | virtual ~wxAppConsole(); | |
74 | ||
75 | ||
76 | // the virtual functions which may/must be overridden in the derived class | |
77 | // ----------------------------------------------------------------------- | |
78 | ||
79 | // This is the very first function called for a newly created wxApp object, | |
80 | // it is used by the library to do the global initialization. If, for some | |
81 | // reason, you must override it (instead of just overriding OnInit(), as | |
82 | // usual, for app-specific initializations), do not forget to call the base | |
83 | // class version! | |
84 | virtual bool Initialize(int& argc, wxChar **argv); | |
85 | ||
86 | // This gives wxCocoa a chance to call OnInit() with a memory pool in place | |
87 | virtual bool CallOnInit() { return OnInit(); } | |
88 | ||
89 | // Called before OnRun(), this is a good place to do initialization -- if | |
90 | // anything fails, return false from here to prevent the program from | |
91 | // continuing. The command line is normally parsed here, call the base | |
92 | // class OnInit() to do it. | |
93 | virtual bool OnInit(); | |
94 | ||
95 | // this is here only temproary hopefully (FIXME) | |
96 | virtual bool OnInitGui() { return true; } | |
97 | ||
98 | // This is the replacement for the normal main(): all program work should | |
99 | // be done here. When OnRun() returns, the programs starts shutting down. | |
100 | virtual int OnRun() = 0; | |
101 | ||
102 | // This is only called if OnInit() returned true so it's a good place to do | |
103 | // any cleanup matching the initializations done there. | |
104 | virtual int OnExit(); | |
105 | ||
106 | // This is the very last function called on wxApp object before it is | |
107 | // destroyed. If you override it (instead of overriding OnExit() as usual) | |
108 | // do not forget to call the base class version! | |
109 | virtual void CleanUp(); | |
110 | ||
111 | // Called when a fatal exception occurs, this function should take care not | |
112 | // to do anything which might provoke a nested exception! It may be | |
113 | // overridden if you wish to react somehow in non-default way (core dump | |
114 | // under Unix, application crash under Windows) to fatal program errors, | |
115 | // however extreme care should be taken if you don't want this function to | |
116 | // crash. | |
117 | virtual void OnFatalException() { } | |
118 | ||
119 | #if wxUSE_EXCEPTIONS | |
120 | // function called if an uncaught exception is caught inside the main | |
121 | // event loop: it may return true to continue running the event loop or | |
122 | // false to stop it (in the latter case it may rethrow the exception as | |
123 | // well) | |
124 | virtual bool OnExceptionInMainLoop() { | |
125 | throw; | |
126 | #if defined(__DMC__) || (defined(_MSC_VER) && _MSC_VER < 1200) | |
127 | return false; | |
128 | #endif | |
129 | } | |
130 | ||
131 | // Called when an unhandled C++ exception occurs inside OnRun(): note that | |
132 | // the exception type is lost by now, so if you really want to handle the | |
133 | // exception you should override OnRun() and put a try/catch around | |
134 | // MainLoop() call there | |
135 | virtual void OnUnhandledException() { } | |
136 | #endif // wxUSE_EXCEPTIONS | |
137 | ||
138 | // Called from wxExit() function, should terminate the application a.s.a.p. | |
139 | virtual void Exit(); | |
140 | ||
141 | ||
142 | // application info: name, description, vendor | |
143 | // ------------------------------------------- | |
144 | ||
145 | // NB: all these should be set by the application itself, there are no | |
146 | // reasonable default except for the application name which is taken to | |
147 | // be argv[0] | |
148 | ||
149 | // set/get the application name | |
150 | wxString GetAppName() const | |
151 | { | |
152 | return m_appName.empty() ? m_className : m_appName; | |
153 | } | |
154 | void SetAppName(const wxString& name) { m_appName = name; } | |
155 | ||
156 | // set/get the app class name | |
157 | wxString GetClassName() const { return m_className; } | |
158 | void SetClassName(const wxString& name) { m_className = name; } | |
159 | ||
160 | // set/get the vendor name | |
161 | const wxString& GetVendorName() const { return m_vendorName; } | |
162 | void SetVendorName(const wxString& name) { m_vendorName = name; } | |
163 | ||
164 | ||
165 | // cmd line parsing stuff | |
166 | // ---------------------- | |
167 | ||
168 | // all of these methods may be overridden in the derived class to | |
169 | // customize the command line parsing (by default only a few standard | |
170 | // options are handled) | |
171 | // | |
172 | // you also need to call wxApp::OnInit() from YourApp::OnInit() for all | |
173 | // this to work | |
174 | ||
175 | #if wxUSE_CMDLINE_PARSER | |
176 | // this one is called from OnInit() to add all supported options | |
177 | // to the given parser (don't forget to call the base class version if you | |
178 | // override it!) | |
179 | virtual void OnInitCmdLine(wxCmdLineParser& parser); | |
180 | ||
181 | // called after successfully parsing the command line, return TRUE | |
182 | // to continue and FALSE to exit (don't forget to call the base class | |
183 | // version if you override it!) | |
184 | virtual bool OnCmdLineParsed(wxCmdLineParser& parser); | |
185 | ||
186 | // called if "--help" option was specified, return TRUE to continue | |
187 | // and FALSE to exit | |
188 | virtual bool OnCmdLineHelp(wxCmdLineParser& parser); | |
189 | ||
190 | // called if incorrect command line options were given, return | |
191 | // FALSE to abort and TRUE to continue | |
192 | virtual bool OnCmdLineError(wxCmdLineParser& parser); | |
193 | #endif // wxUSE_CMDLINE_PARSER | |
194 | ||
195 | ||
196 | // miscellaneous customization functions | |
197 | // ------------------------------------- | |
198 | ||
199 | // create the app traits object to which we delegate for everything which | |
200 | // either should be configurable by the user (then he can change the | |
201 | // default behaviour simply by overriding CreateTraits() and returning his | |
202 | // own traits object) or which is GUI/console dependent as then wxAppTraits | |
203 | Content-type: text/html ]>