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 working with 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
73 // called during wxApp initialization to set the locale to correspond to
74 // the user default (i.e. system locale under Windows, LC_ALL under Unix)
75 virtual void SetLocale();
79 // functions abstracting differences between GUI and console modes
80 // ------------------------------------------------------------------------
83 // show the assert dialog with the specified message in GUI or just print
84 // the string to stderr in console mode
86 // base class version has an implementation (in spite of being pure
87 // virtual) in base/appbase.cpp which can be called as last resort.
89 // return true to suppress subsequent asserts, false to continue as before
90 virtual bool ShowAssertDialog(const wxString
& msg
) = 0;
93 // return true if fprintf(stderr) goes somewhere, false otherwise
94 virtual bool HasStderr() = 0;
96 // managing "pending delete" list: in GUI mode we can't immediately delete
97 // some objects because there may be unprocessed events for them and so we
98 // only do it during the next idle loop iteration while this is, of course,
99 // unnecessary in wxBase, so we have a few functions to abstract these
102 // add the object to the pending delete list in GUI, delete it immediately
104 virtual void ScheduleForDestroy(wxObject
*object
) = 0;
106 // remove this object from the pending delete list in GUI, do nothing in
108 virtual void RemoveFromPendingDelete(wxObject
*object
) = 0;
111 // return table of GUI callbacks for GSocket code or NULL in wxBase. This
112 // is needed because networking classes are in their own library and so
113 // they can't directly call GUI functions (the same net library can be
114 // used in both GUI and base apps). To complicate it further, GUI library
115 // ("wxCore") doesn't depend on networking library and so only a functions
116 // table can be passed around
117 virtual GSocketGUIFunctionsTable
* GetSocketGUIFunctionsTable() = 0;
121 // functions returning port-specific information
122 // ------------------------------------------------------------------------
124 // return information about the (native) toolkit currently used and its
125 // runtime (not compile-time) version.
126 // returns wxPORT_BASE for console applications and one of the remaining
127 // wxPORT_* values for GUI applications.
128 virtual wxPortId
GetToolkitVersion(int *majVer
, int *minVer
) const = 0;
130 // return true if the port is using wxUniversal for the GUI, false if not
131 virtual bool IsUsingUniversalWidgets() const = 0;
133 // return the name of the Desktop Environment such as
134 // "KDE" or "GNOME". May return an empty string.
135 virtual wxString
GetDesktopEnvironment() const { return wxEmptyString
; }
138 #if wxUSE_STACKWALKER && defined( __WXDEBUG__ )
139 // utility function: returns the stack frame as a plain wxString
140 virtual wxString
GetAssertStackTrace();
144 // ----------------------------------------------------------------------------
145 // include the platform-specific version of the class
146 // ----------------------------------------------------------------------------
148 // NB: test for __UNIX__ before __WXMAC__ as under Darwin we want to use the
149 // Unix code (and otherwise __UNIX__ wouldn't be defined)
150 // ABX: check __WIN32__ instead of __WXMSW__ for the same MSWBase in any Win32 port
151 #if defined(__WXPALMOS__)
152 #include "wx/palmos/apptbase.h"
153 #elif defined(__WIN32__)
154 #include "wx/msw/apptbase.h"
155 #elif defined(__UNIX__) && !defined(__EMX__)
156 #include "wx/unix/apptbase.h"
157 #elif defined(__WXMAC__)
158 #include "wx/mac/apptbase.h"
159 #elif defined(__OS2__)
160 #include "wx/os2/apptbase.h"
161 #else // no platform-specific methods to add to wxAppTraits
162 // wxAppTraits must be a class because it was forward declared as class
163 class WXDLLIMPEXP_BASE wxAppTraits
: public wxAppTraitsBase
168 // ============================================================================
169 // standard traits for console and GUI applications
170 // ============================================================================
172 // ----------------------------------------------------------------------------
173 // wxConsoleAppTraitsBase: wxAppTraits implementation for the console apps
174 // ----------------------------------------------------------------------------
176 class WXDLLIMPEXP_BASE wxConsoleAppTraitsBase
: public wxAppTraits
180 virtual wxLog
*CreateLogTarget();
182 virtual wxMessageOutput
*CreateMessageOutput();
184 virtual wxFontMapper
*CreateFontMapper();
185 #endif // wxUSE_FONTMAP
186 virtual wxRendererNative
*CreateRenderer();
188 virtual GSocketGUIFunctionsTable
* GetSocketGUIFunctionsTable();
192 virtual bool ShowAssertDialog(const wxString
& msg
);
193 #endif // __WXDEBUG__
194 virtual bool HasStderr();
196 virtual void ScheduleForDestroy(wxObject
*object
);
197 virtual void RemoveFromPendingDelete(wxObject
*object
);
199 // the GetToolkitVersion for console application is always the same
200 virtual wxPortId
GetToolkitVersion(int *verMaj
, int *verMin
) const
202 // no toolkits (wxBase is for console applications without GUI support)
203 // NB: zero means "no toolkit", -1 means "not initialized yet"
204 // so we must use zero here!
205 if (verMaj
) *verMaj
= 0;
206 if (verMin
) *verMin
= 0;
210 virtual bool IsUsingUniversalWidgets() const { return false; }
213 // ----------------------------------------------------------------------------
214 // wxGUIAppTraitsBase: wxAppTraits implementation for the GUI apps
215 // ----------------------------------------------------------------------------
219 class WXDLLEXPORT wxGUIAppTraitsBase
: public wxAppTraits
223 virtual wxLog
*CreateLogTarget();
225 virtual wxMessageOutput
*CreateMessageOutput();
227 virtual wxFontMapper
*CreateFontMapper();
228 #endif // wxUSE_FONTMAP
229 virtual wxRendererNative
*CreateRenderer();
231 virtual GSocketGUIFunctionsTable
* GetSocketGUIFunctionsTable();
235 virtual bool ShowAssertDialog(const wxString
& msg
);
236 #endif // __WXDEBUG__
237 virtual bool HasStderr();
239 virtual void ScheduleForDestroy(wxObject
*object
);
240 virtual void RemoveFromPendingDelete(wxObject
*object
);
242 virtual bool IsUsingUniversalWidgets() const
244 #ifdef __WXUNIVERSAL__
254 // ----------------------------------------------------------------------------
255 // include the platform-specific version of the classes above
256 // ----------------------------------------------------------------------------
258 // ABX: check __WIN32__ instead of __WXMSW__ for the same MSWBase in any Win32 port
259 #if defined(__WXPALMOS__)
260 #include "wx/palmos/apptrait.h"
261 #elif defined(__WIN32__)
262 #include "wx/msw/apptrait.h"
263 #elif defined(__OS2__)
264 #include "wx/os2/apptrait.h"
265 #elif defined(__UNIX__)
266 #include "wx/unix/apptrait.h"
267 #elif defined(__WXMAC__)
268 #include "wx/mac/apptrait.h"
269 #elif defined(__DOS__)
270 #include "wx/msdos/apptrait.h"
273 class wxGUIAppTraits
: public wxGUIAppTraitsBase
277 class wxConsoleAppTraits
: public wxConsoleAppTraitsBase
282 #endif // _WX_APPTRAIT_H_