]> git.saurik.com Git - wxWidgets.git/blob - include/wx/apptrait.h
support SDK < 10.6, fixes #14902
[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
81 // functions abstracting differences between GUI and console modes
82 // ------------------------------------------------------------------------
83
84 // show the assert dialog with the specified message in GUI or just print
85 // the string to stderr in console mode
86 //
87 // base class version has an implementation (in spite of being pure
88 // virtual) in base/appbase.cpp which can be called as last resort.
89 //
90 // return true to suppress subsequent asserts, false to continue as before
91 virtual bool ShowAssertDialog(const wxString& msg) = 0;
92
93 // return true if fprintf(stderr) goes somewhere, false otherwise
94 virtual bool HasStderr() = 0;
95
96 #if wxUSE_SOCKETS
97 // this function is used by wxNet library to set the default socket manager
98 // to use: doing it like this allows us to keep all socket-related code in
99 // wxNet instead of having to pull it in wxBase itself as we'd have to do
100 // if we really implemented wxSocketManager here
101 //
102 // we don't take ownership of this pointer, it should have a lifetime
103 // greater than that of any socket (e.g. be a pointer to a static object)
104 static void SetDefaultSocketManager(wxSocketManager *manager)
105 {
106 ms_manager = manager;
107 }
108
109 // return socket manager: this is usually different for console and GUI
110 // applications (although some ports use the same implementation for both)
111 virtual wxSocketManager *GetSocketManager() { return ms_manager; }
112 #endif
113
114 // create a new, port specific, instance of the event loop used by wxApp
115 virtual wxEventLoopBase *CreateEventLoop() = 0;
116
117 #if wxUSE_TIMER
118 // return platform and toolkit dependent wxTimer implementation
119 virtual wxTimerImpl *CreateTimerImpl(wxTimer *timer) = 0;
120 #endif
121
122 #if wxUSE_THREADS
123 virtual void MutexGuiEnter();
124 virtual void MutexGuiLeave();
125 #endif
126
127 // functions returning port-specific information
128 // ------------------------------------------------------------------------
129
130 // return information about the (native) toolkit currently used and its
131 // runtime (not compile-time) version.
132 // returns wxPORT_BASE for console applications and one of the remaining
133 // wxPORT_* values for GUI applications.
134 virtual wxPortId GetToolkitVersion(int *majVer = NULL, int *minVer = NULL) const = 0;
135
136 // return true if the port is using wxUniversal for the GUI, false if not
137 virtual bool IsUsingUniversalWidgets() const = 0;
138
139 // return the name of the Desktop Environment such as
140 // "KDE" or "GNOME". May return an empty string.
141 virtual wxString GetDesktopEnvironment() const = 0;
142
143 // returns a short string to identify the block of the standard command
144 // line options parsed automatically by current port: if this string is
145 // empty, there are no such options, otherwise the function also fills
146 // passed arrays with the names and the descriptions of those options.
147 virtual wxString GetStandardCmdLineOptions(wxArrayString& names,
148 wxArrayString& desc) const
149 {
150 wxUnusedVar(names);
151 wxUnusedVar(desc);
152
153 return wxEmptyString;
154 }
155
156
157 protected:
158 #if wxUSE_STACKWALKER
159 // utility function: returns the stack frame as a plain wxString
160 virtual wxString GetAssertStackTrace();
161 #endif
162
163 private:
164 static wxSocketManager *ms_manager;
165 };
166
167 // ----------------------------------------------------------------------------
168 // include the platform-specific version of the class
169 // ----------------------------------------------------------------------------
170
171 // NB: test for __UNIX__ before __WXMAC__ as under Darwin we want to use the
172 // Unix code (and otherwise __UNIX__ wouldn't be defined)
173 // ABX: check __WIN32__ instead of __WXMSW__ for the same MSWBase in any Win32 port
174 #if defined(__WIN32__)
175 #include "wx/msw/apptbase.h"
176 #elif defined(__UNIX__) && !defined(__EMX__)
177 #include "wx/unix/apptbase.h"
178 #elif defined(__OS2__)
179 #include "wx/os2/apptbase.h"
180 #else // no platform-specific methods to add to wxAppTraits
181 // wxAppTraits must be a class because it was forward declared as class
182 class WXDLLIMPEXP_BASE wxAppTraits : public wxAppTraitsBase
183 {
184 };
185 #endif // platform
186
187 // ============================================================================
188 // standard traits for console and GUI applications
189 // ============================================================================
190
191 // ----------------------------------------------------------------------------
192 // wxConsoleAppTraitsBase: wxAppTraits implementation for the console apps
193 // ----------------------------------------------------------------------------
194
195 class WXDLLIMPEXP_BASE wxConsoleAppTraitsBase : public wxAppTraits
196 {
197 public:
198 #if !wxUSE_CONSOLE_EVENTLOOP
199 virtual wxEventLoopBase *CreateEventLoop() { return NULL; }
200 #endif // !wxUSE_CONSOLE_EVENTLOOP
201
202 #if wxUSE_LOG
203 virtual wxLog *CreateLogTarget();
204 #endif // wxUSE_LOG
205 virtual wxMessageOutput *CreateMessageOutput();
206 #if wxUSE_FONTMAP
207 virtual wxFontMapper *CreateFontMapper();
208 #endif // wxUSE_FONTMAP
209 virtual wxRendererNative *CreateRenderer();
210
211 virtual bool ShowAssertDialog(const wxString& msg);
212 virtual bool HasStderr();
213
214 // the GetToolkitVersion for console application is always the same
215 virtual wxPortId GetToolkitVersion(int *verMaj = NULL, int *verMin = NULL) const
216 {
217 // no toolkits (wxBase is for console applications without GUI support)
218 // NB: zero means "no toolkit", -1 means "not initialized yet"
219 // so we must use zero here!
220 if (verMaj) *verMaj = 0;
221 if (verMin) *verMin = 0;
222 return wxPORT_BASE;
223 }
224
225 virtual bool IsUsingUniversalWidgets() const { return false; }
226 virtual wxString GetDesktopEnvironment() const { return wxEmptyString; }
227 };
228
229 // ----------------------------------------------------------------------------
230 // wxGUIAppTraitsBase: wxAppTraits implementation for the GUI apps
231 // ----------------------------------------------------------------------------
232
233 #if wxUSE_GUI
234
235 class WXDLLIMPEXP_CORE wxGUIAppTraitsBase : public wxAppTraits
236 {
237 public:
238 #if wxUSE_LOG
239 virtual wxLog *CreateLogTarget();
240 #endif // wxUSE_LOG
241 virtual wxMessageOutput *CreateMessageOutput();
242 #if wxUSE_FONTMAP
243 virtual wxFontMapper *CreateFontMapper();
244 #endif // wxUSE_FONTMAP
245 virtual wxRendererNative *CreateRenderer();
246
247 virtual bool ShowAssertDialog(const wxString& msg);
248 virtual bool HasStderr();
249
250 virtual bool IsUsingUniversalWidgets() const
251 {
252 #ifdef __WXUNIVERSAL__
253 return true;
254 #else
255 return false;
256 #endif
257 }
258
259 virtual wxString GetDesktopEnvironment() const { return wxEmptyString; }
260 };
261
262 #endif // wxUSE_GUI
263
264 // ----------------------------------------------------------------------------
265 // include the platform-specific version of the classes above
266 // ----------------------------------------------------------------------------
267
268 // ABX: check __WIN32__ instead of __WXMSW__ for the same MSWBase in any Win32 port
269 #if defined(__WIN32__)
270 #include "wx/msw/apptrait.h"
271 #elif defined(__OS2__)
272 #include "wx/os2/apptrait.h"
273 #elif defined(__UNIX__)
274 #include "wx/unix/apptrait.h"
275 #elif defined(__DOS__)
276 #include "wx/msdos/apptrait.h"
277 #else
278 #if wxUSE_GUI
279 class wxGUIAppTraits : public wxGUIAppTraitsBase
280 {
281 };
282 #endif // wxUSE_GUI
283 class wxConsoleAppTraits: public wxConsoleAppTraitsBase
284 {
285 };
286 #endif // platform
287
288 #endif // _WX_APPTRAIT_H_
289