]> git.saurik.com Git - wxWidgets.git/blob - include/wx/apptrait.h
remove virtual override that just calls base
[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_FWD_BASE wxArrayString;
19 class WXDLLIMPEXP_FWD_BASE wxConfigBase;
20 class WXDLLIMPEXP_FWD_BASE wxEventLoopBase;
21 #if wxUSE_FONTMAP
22 class WXDLLIMPEXP_FWD_CORE wxFontMapper;
23 #endif // wxUSE_FONTMAP
24 class WXDLLIMPEXP_FWD_BASE wxLog;
25 class WXDLLIMPEXP_FWD_BASE wxMessageOutput;
26 class WXDLLIMPEXP_FWD_BASE wxObject;
27 class WXDLLIMPEXP_FWD_CORE wxRendererNative;
28 class WXDLLIMPEXP_FWD_BASE wxStandardPaths;
29 class WXDLLIMPEXP_FWD_BASE wxString;
30 class WXDLLIMPEXP_FWD_BASE wxTimer;
31 class WXDLLIMPEXP_FWD_BASE wxTimerImpl;
32
33 class wxSocketManager;
34
35
36 // ----------------------------------------------------------------------------
37 // wxAppTraits: this class defines various configurable aspects of wxApp
38 // ----------------------------------------------------------------------------
39
40 class WXDLLIMPEXP_BASE wxAppTraitsBase
41 {
42 public:
43 // needed since this class declares virtual members
44 virtual ~wxAppTraitsBase() { }
45
46 // hooks for working with the global objects, may be overridden by the user
47 // ------------------------------------------------------------------------
48
49 #if wxUSE_CONFIG
50 // create the default configuration object (base class version is
51 // implemented in config.cpp and creates wxRegConfig for wxMSW and
52 // wxFileConfig for all the other platforms)
53 virtual wxConfigBase *CreateConfig();
54 #endif // wxUSE_CONFIG
55
56 #if wxUSE_LOG
57 // create the default log target
58 virtual wxLog *CreateLogTarget() = 0;
59 #endif // wxUSE_LOG
60
61 // create the global object used for printing out messages
62 virtual wxMessageOutput *CreateMessageOutput() = 0;
63
64 #if wxUSE_FONTMAP
65 // create the global font mapper object used for encodings/charset mapping
66 virtual wxFontMapper *CreateFontMapper() = 0;
67 #endif // wxUSE_FONTMAP
68
69 // get the renderer to use for drawing the generic controls (return value
70 // may be NULL in which case the default renderer for the current platform
71 // is used); this is used in GUI only and always returns NULL in console
72 //
73 // NB: returned pointer will be deleted by the caller
74 virtual wxRendererNative *CreateRenderer() = 0;
75
76 // wxStandardPaths object is normally the same for wxBase and wxGUI
77 // except in the case of wxMac and wxCocoa
78 virtual wxStandardPaths& GetStandardPaths();
79
80 #if wxUSE_INTL
81 // called during wxApp initialization to set the locale to correspond to
82 // the user default (i.e. system locale under Windows, LC_ALL under Unix)
83 virtual void SetLocale();
84 #endif // wxUSE_INTL
85
86
87 // functions abstracting differences between GUI and console modes
88 // ------------------------------------------------------------------------
89
90 // show the assert dialog with the specified message in GUI or just print
91 // the string to stderr in console mode
92 //
93 // base class version has an implementation (in spite of being pure
94 // virtual) in base/appbase.cpp which can be called as last resort.
95 //
96 // return true to suppress subsequent asserts, false to continue as before
97 virtual bool ShowAssertDialog(const wxString& msg) = 0;
98
99 // return true if fprintf(stderr) goes somewhere, false otherwise
100 virtual bool HasStderr() = 0;
101
102 #if wxUSE_SOCKETS
103 // this function is used by wxNet library to set the default socket manager
104 // to use: doing it like this allows us to keep all socket-related code in
105 // wxNet instead of having to pull it in wxBase itself as we'd have to do
106 // if we really implemented wxSocketManager here
107 //
108 // we don't take ownership of this pointer, it should have a lifetime
109 // greater than that of any socket (e.g. be a pointer to a static object)
110 static void SetDefaultSocketManager(wxSocketManager *manager)
111 {
112 ms_manager = manager;
113 }
114
115 // return socket manager: this is usually different for console and GUI
116 // applications (although some ports use the same implementation for both)
117 virtual wxSocketManager *GetSocketManager() { return ms_manager; }
118 #endif
119
120 // create a new, port specific, instance of the event loop used by wxApp
121 virtual wxEventLoopBase *CreateEventLoop() = 0;
122
123 #if wxUSE_TIMER
124 // return platform and toolkit dependent wxTimer implementation
125 virtual wxTimerImpl *CreateTimerImpl(wxTimer *timer) = 0;
126 #endif
127
128 #if wxUSE_THREADS
129 virtual void MutexGuiEnter();
130 virtual void MutexGuiLeave();
131 #endif
132
133 // functions returning port-specific information
134 // ------------------------------------------------------------------------
135
136 // return information about the (native) toolkit currently used and its
137 // runtime (not compile-time) version.
138 // returns wxPORT_BASE for console applications and one of the remaining
139 // wxPORT_* values for GUI applications.
140 virtual wxPortId GetToolkitVersion(int *majVer = NULL, int *minVer = NULL) const = 0;
141
142 // return true if the port is using wxUniversal for the GUI, false if not
143 virtual bool IsUsingUniversalWidgets() const = 0;
144
145 // return the name of the Desktop Environment such as
146 // "KDE" or "GNOME". May return an empty string.
147 virtual wxString GetDesktopEnvironment() const = 0;
148
149 // returns a short string to identify the block of the standard command
150 // line options parsed automatically by current port: if this string is
151 // empty, there are no such options, otherwise the function also fills
152 // passed arrays with the names and the descriptions of those options.
153 virtual wxString GetStandardCmdLineOptions(wxArrayString& names,
154 wxArrayString& desc) const
155 {
156 wxUnusedVar(names);
157 wxUnusedVar(desc);
158
159 return wxEmptyString;
160 }
161
162
163 protected:
164 #if wxUSE_STACKWALKER
165 // utility function: returns the stack frame as a plain wxString
166 virtual wxString GetAssertStackTrace();
167 #endif
168
169 private:
170 static wxSocketManager *ms_manager;
171 };
172
173 // ----------------------------------------------------------------------------
174 // include the platform-specific version of the class
175 // ----------------------------------------------------------------------------
176
177 // NB: test for __UNIX__ before __WXMAC__ as under Darwin we want to use the
178 // Unix code (and otherwise __UNIX__ wouldn't be defined)
179 // ABX: check __WIN32__ instead of __WXMSW__ for the same MSWBase in any Win32 port
180 #if defined(__WIN32__)
181 #include "wx/msw/apptbase.h"
182 #elif defined(__UNIX__) && !defined(__EMX__)
183 #include "wx/unix/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_CONSOLE_EVENTLOOP
205 virtual wxEventLoopBase *CreateEventLoop() { return NULL; }
206 #endif // !wxUSE_CONSOLE_EVENTLOOP
207
208 #if wxUSE_LOG
209 virtual wxLog *CreateLogTarget();
210 #endif // wxUSE_LOG
211 virtual wxMessageOutput *CreateMessageOutput();
212 #if wxUSE_FONTMAP
213 virtual wxFontMapper *CreateFontMapper();
214 #endif // wxUSE_FONTMAP
215 virtual wxRendererNative *CreateRenderer();
216
217 virtual bool ShowAssertDialog(const wxString& msg);
218 virtual bool HasStderr();
219
220 // the GetToolkitVersion for console application is always the same
221 virtual wxPortId GetToolkitVersion(int *verMaj = NULL, int *verMin = NULL) const
222 {
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;
228 return wxPORT_BASE;
229 }
230
231 virtual bool IsUsingUniversalWidgets() const { return false; }
232 virtual wxString GetDesktopEnvironment() const { return wxEmptyString; }
233 };
234
235 // ----------------------------------------------------------------------------
236 // wxGUIAppTraitsBase: wxAppTraits implementation for the GUI apps
237 // ----------------------------------------------------------------------------
238
239 #if wxUSE_GUI
240
241 class WXDLLIMPEXP_CORE wxGUIAppTraitsBase : public wxAppTraits
242 {
243 public:
244 #if wxUSE_LOG
245 virtual wxLog *CreateLogTarget();
246 #endif // wxUSE_LOG
247 virtual wxMessageOutput *CreateMessageOutput();
248 #if wxUSE_FONTMAP
249 virtual wxFontMapper *CreateFontMapper();
250 #endif // wxUSE_FONTMAP
251 virtual wxRendererNative *CreateRenderer();
252
253 virtual bool ShowAssertDialog(const wxString& msg);
254 virtual bool HasStderr();
255
256 virtual bool IsUsingUniversalWidgets() const
257 {
258 #ifdef __WXUNIVERSAL__
259 return true;
260 #else
261 return false;
262 #endif
263 }
264
265 virtual wxString GetDesktopEnvironment() const { return wxEmptyString; }
266 };
267
268 #endif // wxUSE_GUI
269
270 // ----------------------------------------------------------------------------
271 // include the platform-specific version of the classes above
272 // ----------------------------------------------------------------------------
273
274 // ABX: check __WIN32__ instead of __WXMSW__ for the same MSWBase in any Win32 port
275 #if defined(__WIN32__)
276 #include "wx/msw/apptrait.h"
277 #elif defined(__OS2__)
278 #include "wx/os2/apptrait.h"
279 #elif defined(__UNIX__)
280 #include "wx/unix/apptrait.h"
281 #elif defined(__DOS__)
282 #include "wx/msdos/apptrait.h"
283 #else
284 #if wxUSE_GUI
285 class wxGUIAppTraits : public wxGUIAppTraitsBase
286 {
287 };
288 #endif // wxUSE_GUI
289 class wxConsoleAppTraits: public wxConsoleAppTraitsBase
290 {
291 };
292 #endif // platform
293
294 #endif // _WX_APPTRAIT_H_
295