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 wxObject
;
19 class WXDLLEXPORT wxAppTraits
;
21 class WXDLLEXPORT wxFontMapper
;
22 #endif // wxUSE_FONTMAP
23 class WXDLLIMPEXP_BASE wxLog
;
24 class WXDLLIMPEXP_BASE wxMessageOutput
;
25 class WXDLLEXPORT wxRendererNative
;
26 class WXDLLIMPEXP_BASE wxString
;
28 class GSocketGUIFunctionsTable
;
31 // ----------------------------------------------------------------------------
32 // wxAppTraits: this class defines various configurable aspects of wxApp
33 // ----------------------------------------------------------------------------
35 class WXDLLIMPEXP_BASE wxStandardPathsBase
;
37 class WXDLLIMPEXP_BASE wxAppTraitsBase
40 // needed since this class declares virtual members
41 virtual ~wxAppTraitsBase() { }
43 // hooks for creating the global objects, may be overridden by the user
44 // ------------------------------------------------------------------------
47 // create the default log target
48 virtual wxLog
*CreateLogTarget() = 0;
51 // create the global object used for printing out messages
52 virtual wxMessageOutput
*CreateMessageOutput() = 0;
55 // create the global font mapper object used for encodings/charset mapping
56 virtual wxFontMapper
*CreateFontMapper() = 0;
57 #endif // wxUSE_FONTMAP
59 // get the renderer to use for drawing the generic controls (return value
60 // may be NULL in which case the default renderer for the current platform
61 // is used); this is used in GUI only and always returns NULL in console
63 // NB: returned pointer will be deleted by the caller
64 virtual wxRendererNative
*CreateRenderer() = 0;
67 // wxStandardPaths object is normally the same for wxBase and wxGUI
68 // except in the case of wxMac and wxCocoa
69 virtual wxStandardPathsBase
& GetStandardPaths();
70 #endif // wxUSE_STDPATHS
72 // functions abstracting differences between GUI and console modes
73 // ------------------------------------------------------------------------
76 // show the assert dialog with the specified message in GUI or just print
77 // the string to stderr in console mode
79 // base class version has an implementation (in spite of being pure
80 // virtual) in base/appbase.cpp which can be called as last resort.
82 // return true to suppress subsequent asserts, false to continue as before
83 virtual bool ShowAssertDialog(const wxString
& msg
) = 0;
86 // return true if fprintf(stderr) goes somewhere, false otherwise
87 virtual bool HasStderr() = 0;
89 // managing "pending delete" list: in GUI mode we can't immediately delete
90 // some objects because there may be unprocessed events for them and so we
91 // only do it during the next idle loop iteration while this is, of course,
92 // unnecessary in wxBase, so we have a few functions to abstract these
95 // add the object to the pending delete list in GUI, delete it immediately
97 virtual void ScheduleForDestroy(wxObject
*object
) = 0;
99 // remove this object from the pending delete list in GUI, do nothing in
101 virtual void RemoveFromPendingDelete(wxObject
*object
) = 0;
104 // return table of GUI callbacks for GSocket code or NULL in wxBase. This
105 // is needed because networking classes are in their own library and so
106 // they can't directly call GUI functions (the same net library can be
107 // used in both GUI and base apps). To complicate it further, GUI library
108 // ("wxCore") doesn't depend on networking library and so only a functions
109 // table can be passed around
110 virtual GSocketGUIFunctionsTable
* GetSocketGUIFunctionsTable() = 0;
113 // return information about the (native) toolkit currently used and its
114 // runtime (not compile-time) version.
115 // returns wxPORT_BASE for console applications and one of the remaining
116 // wxPORT_* values for GUI applications.
117 virtual wxPortId
GetToolkitVersion(int *majVer
, int *minVer
) const = 0;
119 // return true if the port is using wxUniversal for the GUI, false if not
120 virtual bool IsUsingUniversalWidgets() const = 0;
122 // return the name of the Desktop Environment such as
123 // "KDE" or "GNOME". May return an empty string.
124 virtual wxString
GetDesktopEnvironment() const { return wxEmptyString
; }
127 #if wxUSE_STACKWALKER && defined( __WXDEBUG__ )
128 // utility function: returns the stack frame as a plain wxString
129 virtual wxString
GetAssertStackTrace();
133 // ----------------------------------------------------------------------------
134 // include the platform-specific version of the class
135 // ----------------------------------------------------------------------------
137 // NB: test for __UNIX__ before __WXMAC__ as under Darwin we want to use the
138 // Unix code (and otherwise __UNIX__ wouldn't be defined)
139 // ABX: check __WIN32__ instead of __WXMSW__ for the same MSWBase in any Win32 port
140 #if defined(__WXPALMOS__)
141 #include "wx/palmos/apptbase.h"
142 #elif defined(__WIN32__)
143 #include "wx/msw/apptbase.h"
144 #elif defined(__UNIX__) && !defined(__EMX__)
145 #include "wx/unix/apptbase.h"
146 #elif defined(__WXMAC__)
147 #include "wx/mac/apptbase.h"
148 #elif defined(__OS2__)
149 #include "wx/os2/apptbase.h"
150 #else // no platform-specific methods to add to wxAppTraits
151 // wxAppTraits must be a class because it was forward declared as class
152 class WXDLLIMPEXP_BASE wxAppTraits
: public wxAppTraitsBase
157 // ============================================================================
158 // standard traits for console and GUI applications
159 // ============================================================================
161 // ----------------------------------------------------------------------------
162 // wxConsoleAppTraitsBase: wxAppTraits implementation for the console apps
163 // ----------------------------------------------------------------------------
165 class WXDLLIMPEXP_BASE wxConsoleAppTraitsBase
: public wxAppTraits
169 virtual wxLog
*CreateLogTarget();
171 virtual wxMessageOutput
*CreateMessageOutput();
173 virtual wxFontMapper
*CreateFontMapper();
174 #endif // wxUSE_FONTMAP
175 virtual wxRendererNative
*CreateRenderer();
177 virtual GSocketGUIFunctionsTable
* GetSocketGUIFunctionsTable();
181 virtual bool ShowAssertDialog(const wxString
& msg
);
182 #endif // __WXDEBUG__
183 virtual bool HasStderr();
185 virtual void ScheduleForDestroy(wxObject
*object
);
186 virtual void RemoveFromPendingDelete(wxObject
*object
);
188 // the GetToolkitVersion for console application is always the same
189 virtual wxPortId
GetToolkitVersion(int *verMaj
, int *verMin
) const
191 // no toolkits (wxBase is for console applications without GUI support)
192 // NB: zero means "no toolkit", -1 means "not initialized yet"
193 // so we must use zero here!
194 if (verMaj
) *verMaj
= 0;
195 if (verMin
) *verMin
= 0;
199 virtual bool IsUsingUniversalWidgets() const { return false; }
202 // ----------------------------------------------------------------------------
203 // wxGUIAppTraitsBase: wxAppTraits implementation for the GUI apps
204 // ----------------------------------------------------------------------------
208 class WXDLLEXPORT wxGUIAppTraitsBase
: public wxAppTraits
212 virtual wxLog
*CreateLogTarget();
214 virtual wxMessageOutput
*CreateMessageOutput();
216 virtual wxFontMapper
*CreateFontMapper();
217 #endif // wxUSE_FONTMAP
218 virtual wxRendererNative
*CreateRenderer();
220 virtual GSocketGUIFunctionsTable
* GetSocketGUIFunctionsTable();
224 virtual bool ShowAssertDialog(const wxString
& msg
);
225 #endif // __WXDEBUG__
226 virtual bool HasStderr();
228 virtual void ScheduleForDestroy(wxObject
*object
);
229 virtual void RemoveFromPendingDelete(wxObject
*object
);
231 virtual bool IsUsingUniversalWidgets() const
233 #ifdef __WXUNIVERSAL__
243 // ----------------------------------------------------------------------------
244 // include the platform-specific version of the classes above
245 // ----------------------------------------------------------------------------
247 // ABX: check __WIN32__ instead of __WXMSW__ for the same MSWBase in any Win32 port
248 #if defined(__WXPALMOS__)
249 #include "wx/palmos/apptrait.h"
250 #elif defined(__WIN32__)
251 #include "wx/msw/apptrait.h"
252 #elif defined(__OS2__)
253 #include "wx/os2/apptrait.h"
254 #elif defined(__UNIX__)
255 #include "wx/unix/apptrait.h"
256 #elif defined(__WXMAC__)
257 #include "wx/mac/apptrait.h"
258 #elif defined(__DOS__)
259 #include "wx/msdos/apptrait.h"
262 class wxGUIAppTraits
: public wxGUIAppTraitsBase
266 class wxConsoleAppTraits
: public wxConsoleAppTraitsBase
271 #endif // _WX_APPTRAIT_H_