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