1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: declaration of wxAppTraits and derived classes
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_APPTRAIT_H_
13 #define _WX_APPTRAIT_H_
15 #include "wx/string.h"
16 #include "wx/platinfo.h"
18 class WXDLLIMPEXP_BASE wxArrayString
;
19 class WXDLLIMPEXP_BASE wxObject
;
20 class WXDLLEXPORT wxAppTraits
;
22 class WXDLLEXPORT wxFontMapper
;
23 #endif // wxUSE_FONTMAP
24 class WXDLLIMPEXP_BASE wxLog
;
25 class WXDLLIMPEXP_BASE wxMessageOutput
;
26 class WXDLLEXPORT wxRendererNative
;
27 class WXDLLIMPEXP_BASE wxString
;
28 class WXDLLIMPEXP_BASE wxTimer
;
29 class WXDLLIMPEXP_BASE wxTimerImpl
;
31 class GSocketGUIFunctionsTable
;
34 // ----------------------------------------------------------------------------
35 // wxAppTraits: this class defines various configurable aspects of wxApp
36 // ----------------------------------------------------------------------------
38 class WXDLLIMPEXP_BASE wxStandardPathsBase
;
40 class WXDLLIMPEXP_BASE wxAppTraitsBase
43 // needed since this class declares virtual members
44 virtual ~wxAppTraitsBase() { }
46 // hooks for working with the global objects, may be overridden by the user
47 // ------------------------------------------------------------------------
50 // create the default log target
51 virtual wxLog
*CreateLogTarget() = 0;
54 // create the global object used for printing out messages
55 virtual wxMessageOutput
*CreateMessageOutput() = 0;
58 // create the global font mapper object used for encodings/charset mapping
59 virtual wxFontMapper
*CreateFontMapper() = 0;
60 #endif // wxUSE_FONTMAP
62 // get the renderer to use for drawing the generic controls (return value
63 // may be NULL in which case the default renderer for the current platform
64 // is used); this is used in GUI only and always returns NULL in console
66 // NB: returned pointer will be deleted by the caller
67 virtual wxRendererNative
*CreateRenderer() = 0;
70 // wxStandardPaths object is normally the same for wxBase and wxGUI
71 // except in the case of wxMac and wxCocoa
72 virtual wxStandardPathsBase
& GetStandardPaths();
73 #endif // wxUSE_STDPATHS
76 // called during wxApp initialization to set the locale to correspond to
77 // the user default (i.e. system locale under Windows, LC_ALL under Unix)
78 virtual void SetLocale();
82 // functions abstracting differences between GUI and console modes
83 // ------------------------------------------------------------------------
86 // show the assert dialog with the specified message in GUI or just print
87 // the string to stderr in console mode
89 // base class version has an implementation (in spite of being pure
90 // virtual) in base/appbase.cpp which can be called as last resort.
92 // return true to suppress subsequent asserts, false to continue as before
93 virtual bool ShowAssertDialog(const wxString
& msg
) = 0;
96 // return true if fprintf(stderr) goes somewhere, false otherwise
97 virtual bool HasStderr() = 0;
99 // managing "pending delete" list: in GUI mode we can't immediately delete
100 // some objects because there may be unprocessed events for them and so we
101 // only do it during the next idle loop iteration while this is, of course,
102 // unnecessary in wxBase, so we have a few functions to abstract these
105 // add the object to the pending delete list in GUI, delete it immediately
107 virtual void ScheduleForDestroy(wxObject
*object
) = 0;
109 // remove this object from the pending delete list in GUI, do nothing in
111 virtual void RemoveFromPendingDelete(wxObject
*object
) = 0;
114 // return table of GUI callbacks for GSocket code or NULL in wxBase. This
115 // is needed because networking classes are in their own library and so
116 // they can't directly call GUI functions (the same net library can be
117 // used in both GUI and base apps). To complicate it further, GUI library
118 // ("wxCore") doesn't depend on networking library and so only a functions
119 // table can be passed around
120 virtual GSocketGUIFunctionsTable
* GetSocketGUIFunctionsTable() = 0;
124 // return platform and toolkit dependent wxTimer implementation
125 virtual wxTimerImpl
*CreateTimerImpl(wxTimer
*timer
) = 0;
128 // functions returning port-specific information
129 // ------------------------------------------------------------------------
131 // return information about the (native) toolkit currently used and its
132 // runtime (not compile-time) version.
133 // returns wxPORT_BASE for console applications and one of the remaining
134 // wxPORT_* values for GUI applications.
135 virtual wxPortId
GetToolkitVersion(int *majVer
, int *minVer
) const = 0;
137 // return true if the port is using wxUniversal for the GUI, false if not
138 virtual bool IsUsingUniversalWidgets() const = 0;
140 // return the name of the Desktop Environment such as
141 // "KDE" or "GNOME". May return an empty string.
142 virtual wxString
GetDesktopEnvironment() const = 0;
144 // returns a short string to identify the block of the standard command
145 // line options parsed automatically by current port: if this string is
146 // empty, there are no such options, otherwise the function also fills
147 // passed arrays with the names and the descriptions of those options.
148 virtual wxString
GetStandardCmdLineOptions(wxArrayString
& names
,
149 wxArrayString
& desc
) const
154 return wxEmptyString
;
159 #if wxUSE_STACKWALKER && defined( __WXDEBUG__ )
160 // utility function: returns the stack frame as a plain wxString
161 virtual wxString
GetAssertStackTrace();
165 // ----------------------------------------------------------------------------
166 // include the platform-specific version of the class
167 // ----------------------------------------------------------------------------
169 // NB: test for __UNIX__ before __WXMAC__ as under Darwin we want to use the
170 // Unix code (and otherwise __UNIX__ wouldn't be defined)
171 // ABX: check __WIN32__ instead of __WXMSW__ for the same MSWBase in any Win32 port
172 #if defined(__WXPALMOS__)
173 #include "wx/palmos/apptbase.h"
174 #elif defined(__WIN32__)
175 #include "wx/msw/apptbase.h"
176 #elif defined(__UNIX__) && !defined(__EMX__)
177 #include "wx/unix/apptbase.h"
178 #elif defined(__WXMAC__)
179 #include "wx/mac/apptbase.h"
180 #elif defined(__OS2__)
181 #include "wx/os2/apptbase.h"
182 #else // no platform-specific methods to add to wxAppTraits
183 // wxAppTraits must be a class because it was forward declared as class
184 class WXDLLIMPEXP_BASE wxAppTraits
: public wxAppTraitsBase
189 // ============================================================================
190 // standard traits for console and GUI applications
191 // ============================================================================
193 // ----------------------------------------------------------------------------
194 // wxConsoleAppTraitsBase: wxAppTraits implementation for the console apps
195 // ----------------------------------------------------------------------------
197 class WXDLLIMPEXP_BASE wxConsoleAppTraitsBase
: public wxAppTraits
201 virtual wxLog
*CreateLogTarget();
203 virtual wxMessageOutput
*CreateMessageOutput();
205 virtual wxFontMapper
*CreateFontMapper();
206 #endif // wxUSE_FONTMAP
207 virtual wxRendererNative
*CreateRenderer();
209 virtual GSocketGUIFunctionsTable
* GetSocketGUIFunctionsTable();
213 virtual bool ShowAssertDialog(const wxString
& msg
);
214 #endif // __WXDEBUG__
215 virtual bool HasStderr();
217 virtual void ScheduleForDestroy(wxObject
*object
);
218 virtual void RemoveFromPendingDelete(wxObject
*object
);
220 // the GetToolkitVersion for console application is always the same
221 virtual wxPortId
GetToolkitVersion(int *verMaj
, int *verMin
) const
223 // no toolkits (wxBase is for console applications without GUI support)
224 // NB: zero means "no toolkit", -1 means "not initialized yet"
225 // so we must use zero here!
226 if (verMaj
) *verMaj
= 0;
227 if (verMin
) *verMin
= 0;
231 virtual bool IsUsingUniversalWidgets() const { return false; }
232 virtual wxString
GetDesktopEnvironment() const { return wxEmptyString
; }
235 // ----------------------------------------------------------------------------
236 // wxGUIAppTraitsBase: wxAppTraits implementation for the GUI apps
237 // ----------------------------------------------------------------------------
241 class WXDLLEXPORT wxGUIAppTraitsBase
: public wxAppTraits
245 virtual wxLog
*CreateLogTarget();
247 virtual wxMessageOutput
*CreateMessageOutput();
249 virtual wxFontMapper
*CreateFontMapper();
250 #endif // wxUSE_FONTMAP
251 virtual wxRendererNative
*CreateRenderer();
253 virtual GSocketGUIFunctionsTable
* GetSocketGUIFunctionsTable();
257 virtual bool ShowAssertDialog(const wxString
& msg
);
258 #endif // __WXDEBUG__
259 virtual bool HasStderr();
261 virtual void ScheduleForDestroy(wxObject
*object
);
262 virtual void RemoveFromPendingDelete(wxObject
*object
);
264 virtual bool IsUsingUniversalWidgets() const
266 #ifdef __WXUNIVERSAL__
273 virtual wxString
GetDesktopEnvironment() const { return wxEmptyString
; }
278 // ----------------------------------------------------------------------------
279 // include the platform-specific version of the classes above
280 // ----------------------------------------------------------------------------
282 // ABX: check __WIN32__ instead of __WXMSW__ for the same MSWBase in any Win32 port
283 #if defined(__WXPALMOS__)
284 #include "wx/palmos/apptrait.h"
285 #elif defined(__WIN32__)
286 #include "wx/msw/apptrait.h"
287 #elif defined(__OS2__)
288 #include "wx/os2/apptrait.h"
289 #elif defined(__UNIX__)
290 #include "wx/unix/apptrait.h"
291 #elif defined(__WXMAC__)
292 #include "wx/mac/apptrait.h"
293 #elif defined(__DOS__)
294 #include "wx/msdos/apptrait.h"
297 class wxGUIAppTraits
: public wxGUIAppTraitsBase
301 class wxConsoleAppTraits
: public wxConsoleAppTraitsBase
306 #endif // _WX_APPTRAIT_H_