don't define wxEventLoop class differently in GUI and base, this breaks the
[wxWidgets.git] / include / wx / apptrait.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/apptrait.h
3 // Purpose: declaration of wxAppTraits and derived classes
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 19.06.2003
7 // RCS-ID: $Id$
8 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_APPTRAIT_H_
13 #define _WX_APPTRAIT_H_
14
15 #include "wx/string.h"
16 #include "wx/platinfo.h"
17
18 class WXDLLIMPEXP_BASE wxArrayString;
19 class WXDLLIMPEXP_BASE wxObject;
20 class WXDLLEXPORT wxAppTraits;
21 class WXDLLIMPEXP_BASE wxEventLoopBase;
22 #if wxUSE_FONTMAP
23 class WXDLLEXPORT wxFontMapper;
24 #endif // wxUSE_FONTMAP
25 class WXDLLIMPEXP_BASE wxLog;
26 class WXDLLIMPEXP_BASE wxMessageOutput;
27 class WXDLLEXPORT wxRendererNative;
28 class WXDLLIMPEXP_BASE wxString;
29 class WXDLLIMPEXP_BASE wxTimer;
30 class WXDLLIMPEXP_BASE wxTimerImpl;
31
32 class GSocketGUIFunctionsTable;
33
34
35 // ----------------------------------------------------------------------------
36 // wxAppTraits: this class defines various configurable aspects of wxApp
37 // ----------------------------------------------------------------------------
38
39 class WXDLLIMPEXP_BASE wxStandardPathsBase;
40
41 class WXDLLIMPEXP_BASE wxAppTraitsBase
42 {
43 public:
44 // needed since this class declares virtual members
45 virtual ~wxAppTraitsBase() { }
46
47 // hooks for working with the global objects, may be overridden by the user
48 // ------------------------------------------------------------------------
49
50 #if wxUSE_LOG
51 // create the default log target
52 virtual wxLog *CreateLogTarget() = 0;
53 #endif // wxUSE_LOG
54
55 // create the global object used for printing out messages
56 virtual wxMessageOutput *CreateMessageOutput() = 0;
57
58 #if wxUSE_FONTMAP
59 // create the global font mapper object used for encodings/charset mapping
60 virtual wxFontMapper *CreateFontMapper() = 0;
61 #endif // wxUSE_FONTMAP
62
63 // get the renderer to use for drawing the generic controls (return value
64 // may be NULL in which case the default renderer for the current platform
65 // is used); this is used in GUI only and always returns NULL in console
66 //
67 // NB: returned pointer will be deleted by the caller
68 virtual wxRendererNative *CreateRenderer() = 0;
69
70 #if wxUSE_STDPATHS
71 // wxStandardPaths object is normally the same for wxBase and wxGUI
72 // except in the case of wxMac and wxCocoa
73 virtual wxStandardPathsBase& GetStandardPaths();
74 #endif // wxUSE_STDPATHS
75
76 #if wxUSE_INTL
77 // called during wxApp initialization to set the locale to correspond to
78 // the user default (i.e. system locale under Windows, LC_ALL under Unix)
79 virtual void SetLocale();
80 #endif // wxUSE_INTL
81
82
83 // functions abstracting differences between GUI and console modes
84 // ------------------------------------------------------------------------
85
86 #ifdef __WXDEBUG__
87 // show the assert dialog with the specified message in GUI or just print
88 // the string to stderr in console mode
89 //
90 // base class version has an implementation (in spite of being pure
91 // virtual) in base/appbase.cpp which can be called as last resort.
92 //
93 // return true to suppress subsequent asserts, false to continue as before
94 virtual bool ShowAssertDialog(const wxString& msg) = 0;
95 #endif // __WXDEBUG__
96
97 // return true if fprintf(stderr) goes somewhere, false otherwise
98 virtual bool HasStderr() = 0;
99
100 // managing "pending delete" list: in GUI mode we can't immediately delete
101 // some objects because there may be unprocessed events for them and so we
102 // only do it during the next idle loop iteration while this is, of course,
103 // unnecessary in wxBase, so we have a few functions to abstract these
104 // operations
105
106 // add the object to the pending delete list in GUI, delete it immediately
107 // in wxBase
108 virtual void ScheduleForDestroy(wxObject *object) = 0;
109
110 // remove this object from the pending delete list in GUI, do nothing in
111 // wxBase
112 virtual void RemoveFromPendingDelete(wxObject *object) = 0;
113
114 #if wxUSE_SOCKETS
115 // return table of GUI callbacks for GSocket code or NULL in wxBase. This
116 // is needed because networking classes are in their own library and so
117 // they can't directly call GUI functions (the same net library can be
118 // used in both GUI and base apps). To complicate it further, GUI library
119 // ("wxCore") doesn't depend on networking library and so only a functions
120 // table can be passed around
121 virtual GSocketGUIFunctionsTable* GetSocketGUIFunctionsTable() = 0;
122 #endif
123
124 // create a new, port specific, instance of the event loop used by wxApp
125 virtual wxEventLoopBase *CreateEventLoop() = 0;
126
127 #if wxUSE_TIMER
128 // return platform and toolkit dependent wxTimer implementation
129 virtual wxTimerImpl *CreateTimerImpl(wxTimer *timer) = 0;
130 #endif
131
132 // functions returning port-specific information
133 // ------------------------------------------------------------------------
134
135 // return information about the (native) toolkit currently used and its
136 // runtime (not compile-time) version.
137 // returns wxPORT_BASE for console applications and one of the remaining
138 // wxPORT_* values for GUI applications.
139 virtual wxPortId GetToolkitVersion(int *majVer, int *minVer) const = 0;
140
141 // return true if the port is using wxUniversal for the GUI, false if not
142 virtual bool IsUsingUniversalWidgets() const = 0;
143
144 // return the name of the Desktop Environment such as
145 // "KDE" or "GNOME". May return an empty string.
146 virtual wxString GetDesktopEnvironment() const = 0;
147
148 // returns a short string to identify the block of the standard command
149 // line options parsed automatically by current port: if this string is
150 // empty, there are no such options, otherwise the function also fills
151 // passed arrays with the names and the descriptions of those options.
152 virtual wxString GetStandardCmdLineOptions(wxArrayString& names,
153 wxArrayString& desc) const
154 {
155 wxUnusedVar(names);
156 wxUnusedVar(desc);
157
158 return wxEmptyString;
159 }
160
161
162 protected:
163 #if wxUSE_STACKWALKER && defined( __WXDEBUG__ )
164 // utility function: returns the stack frame as a plain wxString
165 virtual wxString GetAssertStackTrace();
166 #endif
167 };
168
169 // ----------------------------------------------------------------------------
170 // include the platform-specific version of the class
171 // ----------------------------------------------------------------------------
172
173 // NB: test for __UNIX__ before __WXMAC__ as under Darwin we want to use the
174 // Unix code (and otherwise __UNIX__ wouldn't be defined)
175 // ABX: check __WIN32__ instead of __WXMSW__ for the same MSWBase in any Win32 port
176 #if defined(__WXPALMOS__)
177 #include "wx/palmos/apptbase.h"
178 #elif defined(__WIN32__)
179 #include "wx/msw/apptbase.h"
180 #elif defined(__UNIX__) && !defined(__EMX__)
181 #include "wx/unix/apptbase.h"
182 #elif defined(__WXMAC__)
183 #include "wx/mac/apptbase.h"
184 #elif defined(__OS2__)
185 #include "wx/os2/apptbase.h"
186 #else // no platform-specific methods to add to wxAppTraits
187 // wxAppTraits must be a class because it was forward declared as class
188 class WXDLLIMPEXP_BASE wxAppTraits : public wxAppTraitsBase
189 {
190 };
191 #endif // platform
192
193 // ============================================================================
194 // standard traits for console and GUI applications
195 // ============================================================================
196
197 // ----------------------------------------------------------------------------
198 // wxConsoleAppTraitsBase: wxAppTraits implementation for the console apps
199 // ----------------------------------------------------------------------------
200
201 class WXDLLIMPEXP_BASE wxConsoleAppTraitsBase : public wxAppTraits
202 {
203 public:
204 #if wxUSE_LOG
205 virtual wxLog *CreateLogTarget();
206 #endif // wxUSE_LOG
207 virtual wxMessageOutput *CreateMessageOutput();
208 #if wxUSE_FONTMAP
209 virtual wxFontMapper *CreateFontMapper();
210 #endif // wxUSE_FONTMAP
211 virtual wxRendererNative *CreateRenderer();
212 #if wxUSE_SOCKETS
213 virtual GSocketGUIFunctionsTable* GetSocketGUIFunctionsTable();
214 #endif
215
216 #ifdef __WXDEBUG__
217 virtual bool ShowAssertDialog(const wxString& msg);
218 #endif // __WXDEBUG__
219 virtual bool HasStderr();
220
221 virtual void ScheduleForDestroy(wxObject *object);
222 virtual void RemoveFromPendingDelete(wxObject *object);
223
224 // the GetToolkitVersion for console application is always the same
225 virtual wxPortId GetToolkitVersion(int *verMaj, int *verMin) const
226 {
227 // no toolkits (wxBase is for console applications without GUI support)
228 // NB: zero means "no toolkit", -1 means "not initialized yet"
229 // so we must use zero here!
230 if (verMaj) *verMaj = 0;
231 if (verMin) *verMin = 0;
232 return wxPORT_BASE;
233 }
234
235 virtual bool IsUsingUniversalWidgets() const { return false; }
236 virtual wxString GetDesktopEnvironment() const { return wxEmptyString; }
237 };
238
239 // ----------------------------------------------------------------------------
240 // wxGUIAppTraitsBase: wxAppTraits implementation for the GUI apps
241 // ----------------------------------------------------------------------------
242
243 #if wxUSE_GUI
244
245 class WXDLLEXPORT wxGUIAppTraitsBase : public wxAppTraits
246 {
247 public:
248 #if wxUSE_LOG
249 virtual wxLog *CreateLogTarget();
250 #endif // wxUSE_LOG
251 virtual wxMessageOutput *CreateMessageOutput();
252 #if wxUSE_FONTMAP
253 virtual wxFontMapper *CreateFontMapper();
254 #endif // wxUSE_FONTMAP
255 virtual wxRendererNative *CreateRenderer();
256 #if wxUSE_SOCKETS
257 virtual GSocketGUIFunctionsTable* GetSocketGUIFunctionsTable();
258 #endif
259
260 #ifdef __WXDEBUG__
261 virtual bool ShowAssertDialog(const wxString& msg);
262 #endif // __WXDEBUG__
263 virtual bool HasStderr();
264
265 virtual void ScheduleForDestroy(wxObject *object);
266 virtual void RemoveFromPendingDelete(wxObject *object);
267
268 virtual bool IsUsingUniversalWidgets() const
269 {
270 #ifdef __WXUNIVERSAL__
271 return true;
272 #else
273 return false;
274 #endif
275 }
276
277 virtual wxString GetDesktopEnvironment() const { return wxEmptyString; }
278 };
279
280 #endif // wxUSE_GUI
281
282 // ----------------------------------------------------------------------------
283 // include the platform-specific version of the classes above
284 // ----------------------------------------------------------------------------
285
286 // ABX: check __WIN32__ instead of __WXMSW__ for the same MSWBase in any Win32 port
287 #if defined(__WXPALMOS__)
288 #include "wx/palmos/apptrait.h"
289 #elif defined(__WIN32__)
290 #include "wx/msw/apptrait.h"
291 #elif defined(__OS2__)
292 #include "wx/os2/apptrait.h"
293 #elif defined(__UNIX__)
294 #include "wx/unix/apptrait.h"
295 #elif defined(__WXMAC__)
296 #include "wx/mac/apptrait.h"
297 #elif defined(__DOS__)
298 #include "wx/msdos/apptrait.h"
299 #else
300 #if wxUSE_GUI
301 class wxGUIAppTraits : public wxGUIAppTraitsBase
302 {
303 };
304 #endif // wxUSE_GUI
305 class wxConsoleAppTraits: public wxConsoleAppTraitsBase
306 {
307 };
308 #endif // platform
309
310 #endif // _WX_APPTRAIT_H_
311