]> git.saurik.com Git - wxWidgets.git/blob - include/wx/app.h
Updated testconf
[wxWidgets.git] / include / wx / app.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 and Markus Holzem
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
12
13 #ifndef _WX_APP_H_BASE_
14 #define _WX_APP_H_BASE_
15
16 #ifdef __GNUG__
17 #pragma interface "appbase.h"
18 #endif
19
20 // ----------------------------------------------------------------------------
21 // typedefs
22 // ----------------------------------------------------------------------------
23
24 #ifdef __WXMSW__
25 class WXDLLEXPORT wxApp;
26 typedef wxApp* (*wxAppInitializerFunction)();
27 #else
28 // returning wxApp* won't work with gcc
29 #include "wx/object.h"
30
31 typedef wxObject* (*wxAppInitializerFunction)();
32 #endif
33
34 // ----------------------------------------------------------------------------
35 // headers we have to include here
36 // ----------------------------------------------------------------------------
37
38 #include "wx/event.h" // for the base class
39
40 #include "wx/window.h" // for wxTopLevelWindows
41
42 #if wxUSE_LOG
43 #include "wx/log.h"
44 #endif
45
46 // ----------------------------------------------------------------------------
47 // constants
48 // ----------------------------------------------------------------------------
49
50 static const int wxPRINT_WINDOWS = 1;
51 static const int wxPRINT_POSTSCRIPT = 2;
52
53 // ----------------------------------------------------------------------------
54 // the common part of wxApp implementations for all platforms
55 // ----------------------------------------------------------------------------
56
57 class WXDLLEXPORT wxAppBase : public wxEvtHandler
58 {
59 public:
60 // the virtual functions which may/must be overridden in the derived class
61 // -----------------------------------------------------------------------
62
63 // called during the program initialization, returning FALSE from here
64 // prevents the program from continuing - it's a good place to create
65 // the top level program window and return TRUE.
66 //
67 // Override: always.
68 virtual bool OnInit() { return FALSE; };
69
70 // a platform-dependent version of OnInit(): the code here is likely to
71 // depend on the toolkit. default version does nothing.
72 //
73 // Override: rarely.
74 virtual bool OnInitGui() { return TRUE; }
75
76 // called to start program execution - the default version just enters
77 // the main GUI loop in which events are received and processed until
78 // the last window is not deleted (if GetExitOnFrameDelete) or
79 // ExitMainLoop() is called.
80 //
81 // Override: rarely.
82 virtual int OnRun() { return MainLoop(); };
83
84 // called after the main loop termination. This is a good place for
85 // cleaning up (it may be too late in dtor) and is also useful if you
86 // want to return some non-default exit code - this is just the return
87 // value of this method.
88 //
89 // Override: often.
90 virtual int OnExit() { return 0; }
91
92 // called when a fatal exception occurs, this function should take care
93 // not to do anything which might provoke a nested exception! It may be
94 // overridden if you wish to react somehow in non-default way (core
95 // dump under Unix, application crash under Windows) to fatal program
96 // errors, however extreme care should be taken if you don't want this
97 // function to crash.
98 //
99 // Override: rarely.
100 virtual void OnFatalException() { }
101
102 // the worker functions - usually not used directly by the user code
103 // -----------------------------------------------------------------
104
105 // execute the main GUI loop, the function returns when the loop ends
106 virtual int MainLoop() = 0;
107
108 // exit the main GUI loop during the next iteration (i.e. it does not
109 // stop the program immediately!)
110 virtual void ExitMainLoop() = 0;
111
112 // returns TRUE if the program is initialized
113 virtual bool Initialized() = 0;
114
115 // returns TRUE if there are unprocessed events in the event queue
116 virtual bool Pending() = 0;
117
118 // process the first event in the event queue (blocks until an event
119 // apperas if there are none currently)
120 virtual void Dispatch() = 0;
121
122 // application info: name, description, vendor
123 // -------------------------------------------
124
125 // NB: all these should be set by the application itself, there are no
126 // reasonable default except for the application name which is taken to
127 // be argv[0]
128
129 // set/get the application name
130 wxString GetAppName() const
131 {
132 if ( !m_appName )
133 return m_className;
134 else
135 return m_appName;
136 }
137 void SetAppName(const wxString& name) { m_appName = name; }
138
139 // set/get the app class name
140 wxString GetClassName() const { return m_className; }
141 void SetClassName(const wxString& name) { m_className = name; }
142
143 // set/get the vendor name
144 const wxString& GetVendorName() const { return m_vendorName; }
145 void SetVendorName(const wxString& name) { m_vendorName = name; }
146
147 // top level window functions
148 // --------------------------
149
150 // set the "main" top level window
151 void SetTopWindow(wxWindow *win) { m_topWindow = win; }
152
153 // return the "main" top level window (if it hadn't been set previously
154 // with SetTopWindow(), will return just some top level window and, if
155 // there are none, will return NULL)
156 wxWindow *GetTopWindow() const
157 {
158 if (m_topWindow)
159 return m_topWindow;
160 else if (wxTopLevelWindows.GetCount() > 0)
161 return wxTopLevelWindows.GetFirst()->GetData();
162 else
163 return (wxWindow *)NULL;
164 }
165
166 // control the exit behaviour: by default, the program will exit the
167 // main loop (and so, usually, terminate) when the last top-level
168 // program window is deleted. Beware that if you disabel this (with
169 // SetExitOnFrameDelete(FALSE)), you'll have to call ExitMainLoop()
170 // explicitly from somewhere.
171 void SetExitOnFrameDelete(bool flag) { m_exitOnFrameDelete = flag; }
172 bool GetExitOnFrameDelete() const { return m_exitOnFrameDelete; }
173
174 // miscellaneous customization functions
175 // -------------------------------------
176
177 #if wxUSE_LOG
178 // override this function to create default log target of arbitrary
179 // user-defined class (default implementation creates a wxLogGui
180 // object) - this log object is used by default by all wxLogXXX()
181 // functions.
182 virtual wxLog *CreateLogTarget() { return new wxLogGui; }
183 #endif // wxUSE_LOG
184
185
186 // get the standard icon used by wxWin dialogs - this allows the user
187 // to customize the standard dialogs. The 'which' parameter is one of
188 // wxICON_XXX values
189 virtual wxIcon GetStdIcon(int which) const = 0;
190
191 // VZ: what does this do exactly?
192 void SetWantDebugOutput( bool flag ) { m_wantDebugOutput = flag; }
193 bool GetWantDebugOutput() const { return m_wantDebugOutput; }
194
195 // set/get printing mode: see wxPRINT_XXX constants.
196 //
197 // default behaviour is the normal one for Unix: always use PostScript
198 // printing.
199 virtual void SetPrintMode(int WXUNUSED(mode)) { }
200 int GetPrintMode() const { return wxPRINT_POSTSCRIPT; }
201
202 // implementation only from now on
203 // -------------------------------
204
205 // helpers for dynamic wxApp construction
206 static void SetInitializerFunction(wxAppInitializerFunction fn)
207 { m_appInitFn = fn; }
208 static wxAppInitializerFunction GetInitializerFunction()
209 { return m_appInitFn; }
210
211 // access to the command line arguments
212 int argc;
213 char **argv;
214
215 //private:
216 protected:
217 // function used for dynamic wxApp creation
218 static wxAppInitializerFunction m_appInitFn;
219
220 // application info (must be set from the user code)
221 wxString m_vendorName, // vendor name (ACME Inc)
222 m_appName, // app name
223 m_className; // class name
224
225 // if TRUE, exit the main loop when the last top level window is deleted
226 bool m_exitOnFrameDelete;
227
228 // TRUE if the application wants to get debug output
229 bool m_wantDebugOutput;
230
231 // the main top level window - may be NULL
232 wxWindow *m_topWindow;
233 };
234
235 // ----------------------------------------------------------------------------
236 // now include the declaration of the real class
237 // ----------------------------------------------------------------------------
238
239 #if defined(__WXMSW__)
240 #include "wx/msw/app.h"
241 #elif defined(__WXMOTIF__)
242 #include "wx/motif/app.h"
243 #elif defined(__WXQT__)
244 #include "wx/qt/app.h"
245 #elif defined(__WXGTK__)
246 #include "wx/gtk/app.h"
247 #elif defined(__WXMAC__)
248 #include "wx/mac/app.h"
249 #elif defined(__WXSTUBS__)
250 #include "wx/stubs/app.h"
251 #endif
252
253 // ----------------------------------------------------------------------------
254 // macros for dynamic creation of the application object
255 // ----------------------------------------------------------------------------
256
257 // Having a global instance of this class allows wxApp to be aware of the app
258 // creator function. wxApp can then call this function to create a new app
259 // object. Convoluted, but necessary.
260
261 class WXDLLEXPORT wxAppInitializer
262 {
263 public:
264 wxAppInitializer(wxAppInitializerFunction fn)
265 { wxApp::SetInitializerFunction(fn); }
266 };
267
268 // Here's a macro you can use if your compiler really, really wants main() to
269 // be in your main program (e.g. hello.cpp). Now IMPLEMENT_APP should add this
270 // code if required.
271
272 #if defined(__AIX__) || defined(__HPUX__)
273 #define IMPLEMENT_WXWIN_MAIN \
274 extern int wxEntry( int argc, char *argv[] ); \
275 int main(int argc, char *argv[]) { return wxEntry(argc, argv); }
276 #elif defined(__WXMSW__) && defined(WXUSINGDLL)
277 // NT defines APIENTRY, 3.x not
278 #if !defined(WXAPIENTRY)
279 #ifdef __WATCOMC__
280 #define WXAPIENTRY PASCAL
281 #else
282 #define WXAPIENTRY FAR PASCAL
283 #endif
284 #endif
285
286 #define IMPLEMENT_WXWIN_MAIN \
287 int WXAPIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,\
288 LPSTR m_lpCmdLine, int nCmdShow )\
289 {\
290 return wxEntry((WXHINSTANCE) hInstance, \
291 (WXHINSTANCE) hPrevInstance,\
292 m_lpCmdLine, nCmdShow);\
293 }
294
295 #else
296 #define IMPLEMENT_WXWIN_MAIN
297 #endif
298
299 // use this macro exactly once, the argument is the name of the wxApp-derived
300 // class which is the class of your application
301 #define IMPLEMENT_APP(appname) \
302 wxApp *wxCreateApp() { return new appname; } \
303 wxAppInitializer wxTheAppInitializer((wxAppInitializerFunction) wxCreateApp); \
304 appname& wxGetApp() { return *(appname *)wxTheApp; } \
305 IMPLEMENT_WXWIN_MAIN
306
307 #define DECLARE_APP(appname) extern appname& wxGetApp();
308
309 #endif
310 // _WX_APP_H_BASE_