]> git.saurik.com Git - wxWidgets.git/blame - include/wx/apptrait.h
using Run of base class
[wxWidgets.git] / include / wx / apptrait.h
CommitLineData
e2478fde
VZ
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
77ffb593 7// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
65571936 8// Licence: wxWindows licence
e2478fde
VZ
9///////////////////////////////////////////////////////////////////////////////
10
11#ifndef _WX_APPTRAIT_H_
12#define _WX_APPTRAIT_H_
13
a8eaaeb2 14#include "wx/string.h"
8bb6b2c0 15#include "wx/platinfo.h"
a8eaaeb2 16
b5dbe15d
VS
17class WXDLLIMPEXP_FWD_BASE wxArrayString;
18class WXDLLIMPEXP_FWD_BASE wxConfigBase;
19class WXDLLIMPEXP_FWD_BASE wxEventLoopBase;
e2478fde 20#if wxUSE_FONTMAP
b5dbe15d 21 class WXDLLIMPEXP_FWD_CORE wxFontMapper;
e2478fde 22#endif // wxUSE_FONTMAP
b5dbe15d
VS
23class WXDLLIMPEXP_FWD_BASE wxLog;
24class WXDLLIMPEXP_FWD_BASE wxMessageOutput;
25class WXDLLIMPEXP_FWD_BASE wxObject;
26class WXDLLIMPEXP_FWD_CORE wxRendererNative;
25f49256 27class WXDLLIMPEXP_FWD_BASE wxStandardPaths;
b5dbe15d
VS
28class WXDLLIMPEXP_FWD_BASE wxString;
29class WXDLLIMPEXP_FWD_BASE wxTimer;
30class WXDLLIMPEXP_FWD_BASE wxTimerImpl;
a8eaaeb2 31
51fe4b60 32class wxSocketManager;
38bb138f 33
e2478fde
VZ
34
35// ----------------------------------------------------------------------------
36// wxAppTraits: this class defines various configurable aspects of wxApp
37// ----------------------------------------------------------------------------
38
7af1b539 39class WXDLLIMPEXP_BASE wxAppTraitsBase
e2478fde
VZ
40{
41public:
ed62f740
VZ
42 // needed since this class declares virtual members
43 virtual ~wxAppTraitsBase() { }
44
d774f916 45 // hooks for working with the global objects, may be overridden by the user
e2478fde
VZ
46 // ------------------------------------------------------------------------
47
84281b92
VZ
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
e2478fde
VZ
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
f0244295
VZ
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
fc480dc1
DE
75 // wxStandardPaths object is normally the same for wxBase and wxGUI
76 // except in the case of wxMac and wxCocoa
25f49256 77 virtual wxStandardPaths& GetStandardPaths();
e2478fde 78
d774f916 79
e2478fde
VZ
80 // functions abstracting differences between GUI and console modes
81 // ------------------------------------------------------------------------
82
e2478fde
VZ
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;
e2478fde
VZ
91
92 // return true if fprintf(stderr) goes somewhere, false otherwise
93 virtual bool HasStderr() = 0;
94
38bb138f 95#if wxUSE_SOCKETS
51fe4b60
VZ
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
2804f77d
VZ
108 // return socket manager: this is usually different for console and GUI
109 // applications (although some ports use the same implementation for both)
51fe4b60 110 virtual wxSocketManager *GetSocketManager() { return ms_manager; }
38bb138f
VS
111#endif
112
b46b1d59 113 // create a new, port specific, instance of the event loop used by wxApp
2ddff00c 114 virtual wxEventLoopBase *CreateEventLoop() = 0;
b46b1d59 115
c2ca375c
VZ
116#if wxUSE_TIMER
117 // return platform and toolkit dependent wxTimer implementation
118 virtual wxTimerImpl *CreateTimerImpl(wxTimer *timer) = 0;
119#endif
d774f916 120
d254213e
PC
121#if wxUSE_THREADS
122 virtual void MutexGuiEnter();
123 virtual void MutexGuiLeave();
124#endif
125
d774f916
VZ
126 // functions returning port-specific information
127 // ------------------------------------------------------------------------
128
449090b5
VZ
129 // return information about the (native) toolkit currently used and its
130 // runtime (not compile-time) version.
8bb6b2c0
VZ
131 // returns wxPORT_BASE for console applications and one of the remaining
132 // wxPORT_* values for GUI applications.
1f5c6629 133 virtual wxPortId GetToolkitVersion(int *majVer = NULL, int *minVer = NULL) const = 0;
b98bd6af
VS
134
135 // return true if the port is using wxUniversal for the GUI, false if not
136 virtual bool IsUsingUniversalWidgets() const = 0;
db9febdf
RR
137
138 // return the name of the Desktop Environment such as
88bbc332 139 // "KDE" or "GNOME". May return an empty string.
d3a0a0ee
VZ
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
db9febdf
RR
155
156protected:
657a8a35 157#if wxUSE_STACKWALKER
db9febdf
RR
158 // utility function: returns the stack frame as a plain wxString
159 virtual wxString GetAssertStackTrace();
160#endif
51fe4b60
VZ
161
162private:
163 static wxSocketManager *ms_manager;
e2478fde
VZ
164};
165
166// ----------------------------------------------------------------------------
167// include the platform-specific version of the class
168// ----------------------------------------------------------------------------
169
532d575b
WS
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
bd362275 173#if defined(__WIN32__)
e2478fde 174 #include "wx/msw/apptbase.h"
621ccd8a 175#elif defined(__UNIX__) && !defined(__EMX__)
2d2d4fc7 176 #include "wx/unix/apptbase.h"
9fc852b7
SN
177#elif defined(__OS2__)
178 #include "wx/os2/apptbase.h"
46446cc2 179#else // no platform-specific methods to add to wxAppTraits
e2478fde 180 // wxAppTraits must be a class because it was forward declared as class
bb24c68f 181 class WXDLLIMPEXP_BASE wxAppTraits : public wxAppTraitsBase
e2478fde
VZ
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
7af1b539 194class WXDLLIMPEXP_BASE wxConsoleAppTraitsBase : public wxAppTraits
e2478fde
VZ
195{
196public:
a1873279
VZ
197#if !wxUSE_CONSOLE_EVENTLOOP
198 virtual wxEventLoopBase *CreateEventLoop() { return NULL; }
199#endif // !wxUSE_CONSOLE_EVENTLOOP
200
e2478fde
VZ
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
f0244295 208 virtual wxRendererNative *CreateRenderer();
e2478fde 209
e2478fde 210 virtual bool ShowAssertDialog(const wxString& msg);
e2478fde
VZ
211 virtual bool HasStderr();
212
8bb6b2c0 213 // the GetToolkitVersion for console application is always the same
1f5c6629 214 virtual wxPortId GetToolkitVersion(int *verMaj = NULL, int *verMin = NULL) const
8bb6b2c0
VZ
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 }
b98bd6af
VS
223
224 virtual bool IsUsingUniversalWidgets() const { return false; }
d3a0a0ee 225 virtual wxString GetDesktopEnvironment() const { return wxEmptyString; }
e2478fde
VZ
226};
227
228// ----------------------------------------------------------------------------
229// wxGUIAppTraitsBase: wxAppTraits implementation for the GUI apps
230// ----------------------------------------------------------------------------
231
232#if wxUSE_GUI
233
53a2db12 234class WXDLLIMPEXP_CORE wxGUIAppTraitsBase : public wxAppTraits
e2478fde
VZ
235{
236public:
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
f0244295 244 virtual wxRendererNative *CreateRenderer();
e2478fde 245
e2478fde 246 virtual bool ShowAssertDialog(const wxString& msg);
e2478fde
VZ
247 virtual bool HasStderr();
248
b98bd6af
VS
249 virtual bool IsUsingUniversalWidgets() const
250 {
251 #ifdef __WXUNIVERSAL__
252 return true;
253 #else
254 return false;
255 #endif
256 }
d3a0a0ee
VZ
257
258 virtual wxString GetDesktopEnvironment() const { return wxEmptyString; }
e2478fde
VZ
259};
260
261#endif // wxUSE_GUI
262
263// ----------------------------------------------------------------------------
264// include the platform-specific version of the classes above
265// ----------------------------------------------------------------------------
266
532d575b 267// ABX: check __WIN32__ instead of __WXMSW__ for the same MSWBase in any Win32 port
bd362275 268#if defined(__WIN32__)
e2478fde 269 #include "wx/msw/apptrait.h"
21d3d342
SN
270#elif defined(__OS2__)
271 #include "wx/os2/apptrait.h"
272#elif defined(__UNIX__)
2d2d4fc7 273 #include "wx/unix/apptrait.h"
9aecec9a
MW
274#elif defined(__DOS__)
275 #include "wx/msdos/apptrait.h"
4629016d 276#else
e2478fde 277 #if wxUSE_GUI
621ccd8a
SN
278 class wxGUIAppTraits : public wxGUIAppTraitsBase
279 {
621ccd8a 280 };
e2478fde 281 #endif // wxUSE_GUI
4629016d 282 class wxConsoleAppTraits: public wxConsoleAppTraitsBase
621ccd8a 283 {
621ccd8a 284 };
e2478fde
VZ
285#endif // platform
286
287#endif // _WX_APPTRAIT_H_
288