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
;
21 class WXDLLIMPEXP_BASE wxEventLoop
;
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
;
32 class GSocketGUIFunctionsTable
;
35 // ----------------------------------------------------------------------------
36 // wxAppTraits: this class defines various configurable aspects of wxApp
37 // ----------------------------------------------------------------------------
39 class WXDLLIMPEXP_BASE wxStandardPathsBase
;
41 class WXDLLIMPEXP_BASE wxAppTraitsBase
44 // needed since this class declares virtual members
45 virtual ~wxAppTraitsBase() { }
47 // hooks for working with the global objects, may be overridden by the user
48 // ------------------------------------------------------------------------
51 // create the default log target
52 virtual wxLog
*CreateLogTarget() = 0;
55 // create the global object used for printing out messages
56 virtual wxMessageOutput
*CreateMessageOutput() = 0;
59 // create the global font mapper object used for encodings/charset mapping
60 virtual wxFontMapper
*CreateFontMapper() = 0;
61 #endif // wxUSE_FONTMAP
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
67 // NB: returned pointer will be deleted by the caller
68 virtual wxRendererNative
*CreateRenderer() = 0;
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
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();
83 // functions abstracting differences between GUI and console modes
84 // ------------------------------------------------------------------------
87 // show the assert dialog with the specified message in GUI or just print
88 // the string to stderr in console mode
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.
93 // return true to suppress subsequent asserts, false to continue as before
94 virtual bool ShowAssertDialog(const wxString
& msg
) = 0;
97 // return true if fprintf(stderr) goes somewhere, false otherwise
98 virtual bool HasStderr() = 0;
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
106 // add the object to the pending delete list in GUI, delete it immediately
108 virtual void ScheduleForDestroy(wxObject
*object
) = 0;
110 // remove this object from the pending delete list in GUI, do nothing in
112 virtual void RemoveFromPendingDelete(wxObject
*object
) = 0;
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;
124 // create a new, port specific, instance of the event loop used by wxApp
125 virtual wxEventLoop
*CreateEventLoop() = 0;
128 // return platform and toolkit dependent wxTimer implementation
129 virtual wxTimerImpl
*CreateTimerImpl(wxTimer
*timer
) = 0;
132 // functions returning port-specific information
133 // ------------------------------------------------------------------------
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;
141 // return true if the port is using wxUniversal for the GUI, false if not
142 virtual bool IsUsingUniversalWidgets() const = 0;
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;
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
158 return wxEmptyString
;
163 #if wxUSE_STACKWALKER && defined( __WXDEBUG__ )
164 // utility function: returns the stack frame as a plain wxString
165 virtual wxString
GetAssertStackTrace();
169 // ----------------------------------------------------------------------------
170 // include the platform-specific version of the class
171 // ----------------------------------------------------------------------------
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
193 // ============================================================================
194 // standard traits for console and GUI applications
195 // ============================================================================
197 // ----------------------------------------------------------------------------
198 // wxConsoleAppTraitsBase: wxAppTraits implementation for the console apps
199 // ----------------------------------------------------------------------------
201 class WXDLLIMPEXP_BASE wxConsoleAppTraitsBase
: public wxAppTraits
205 virtual wxLog
*CreateLogTarget();
207 virtual wxMessageOutput
*CreateMessageOutput();
209 virtual wxFontMapper
*CreateFontMapper();
210 #endif // wxUSE_FONTMAP
211 virtual wxRendererNative
*CreateRenderer();
213 virtual GSocketGUIFunctionsTable
* GetSocketGUIFunctionsTable();
217 virtual bool ShowAssertDialog(const wxString
& msg
);
218 #endif // __WXDEBUG__
219 virtual bool HasStderr();
221 virtual void ScheduleForDestroy(wxObject
*object
);
222 virtual void RemoveFromPendingDelete(wxObject
*object
);
224 // the GetToolkitVersion for console application is always the same
225 virtual wxPortId
GetToolkitVersion(int *verMaj
, int *verMin
) const
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;
235 virtual bool IsUsingUniversalWidgets() const { return false; }
236 virtual wxString
GetDesktopEnvironment() const { return wxEmptyString
; }
239 // ----------------------------------------------------------------------------
240 // wxGUIAppTraitsBase: wxAppTraits implementation for the GUI apps
241 // ----------------------------------------------------------------------------
245 class WXDLLEXPORT wxGUIAppTraitsBase
: public wxAppTraits
249 virtual wxLog
*CreateLogTarget();
251 virtual wxMessageOutput
*CreateMessageOutput();
253 virtual wxFontMapper
*CreateFontMapper();
254 #endif // wxUSE_FONTMAP
255 virtual wxRendererNative
*CreateRenderer();
257 virtual GSocketGUIFunctionsTable
* GetSocketGUIFunctionsTable();
261 virtual bool ShowAssertDialog(const wxString
& msg
);
262 #endif // __WXDEBUG__
263 virtual bool HasStderr();
265 virtual void ScheduleForDestroy(wxObject
*object
);
266 virtual void RemoveFromPendingDelete(wxObject
*object
);
268 virtual bool IsUsingUniversalWidgets() const
270 #ifdef __WXUNIVERSAL__
277 virtual wxString
GetDesktopEnvironment() const { return wxEmptyString
; }
282 // ----------------------------------------------------------------------------
283 // include the platform-specific version of the classes above
284 // ----------------------------------------------------------------------------
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"
301 class wxGUIAppTraits
: public wxGUIAppTraitsBase
305 class wxConsoleAppTraits
: public wxConsoleAppTraitsBase
310 #endif // _WX_APPTRAIT_H_