]>
Commit | Line | Data |
---|---|---|
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 | |
7 | // RCS-ID: $Id$ | |
77ffb593 | 8 | // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org> |
65571936 | 9 | // Licence: wxWindows licence |
e2478fde VZ |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_APPTRAIT_H_ | |
13 | #define _WX_APPTRAIT_H_ | |
14 | ||
a8eaaeb2 | 15 | #include "wx/string.h" |
8bb6b2c0 | 16 | #include "wx/platinfo.h" |
a8eaaeb2 | 17 | |
b5dbe15d VS |
18 | class WXDLLIMPEXP_FWD_BASE wxArrayString; |
19 | class WXDLLIMPEXP_FWD_BASE wxConfigBase; | |
20 | class WXDLLIMPEXP_FWD_BASE wxEventLoopBase; | |
e2478fde | 21 | #if wxUSE_FONTMAP |
b5dbe15d | 22 | class WXDLLIMPEXP_FWD_CORE wxFontMapper; |
e2478fde | 23 | #endif // wxUSE_FONTMAP |
b5dbe15d VS |
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 wxStandardPathsBase; | |
29 | class WXDLLIMPEXP_FWD_BASE wxString; | |
30 | class WXDLLIMPEXP_FWD_BASE wxTimer; | |
31 | class WXDLLIMPEXP_FWD_BASE wxTimerImpl; | |
a8eaaeb2 | 32 | |
3e1400ac | 33 | class GSocketGUIFunctionsTable; |
38bb138f | 34 | |
e2478fde VZ |
35 | |
36 | // ---------------------------------------------------------------------------- | |
37 | // wxAppTraits: this class defines various configurable aspects of wxApp | |
38 | // ---------------------------------------------------------------------------- | |
39 | ||
7af1b539 | 40 | class WXDLLIMPEXP_BASE wxAppTraitsBase |
e2478fde VZ |
41 | { |
42 | public: | |
ed62f740 VZ |
43 | // needed since this class declares virtual members |
44 | virtual ~wxAppTraitsBase() { } | |
45 | ||
d774f916 | 46 | // hooks for working with the global objects, may be overridden by the user |
e2478fde VZ |
47 | // ------------------------------------------------------------------------ |
48 | ||
84281b92 VZ |
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 | ||
e2478fde VZ |
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 | ||
f0244295 VZ |
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 | ||
fc480dc1 DE |
76 | // wxStandardPaths object is normally the same for wxBase and wxGUI |
77 | // except in the case of wxMac and wxCocoa | |
78 | virtual wxStandardPathsBase& GetStandardPaths(); | |
e2478fde | 79 | |
d774f916 VZ |
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 | ||
e2478fde VZ |
87 | // functions abstracting differences between GUI and console modes |
88 | // ------------------------------------------------------------------------ | |
89 | ||
90 | #ifdef __WXDEBUG__ | |
91 | // show the assert dialog with the specified message in GUI or just print | |
92 | // the string to stderr in console mode | |
93 | // | |
94 | // base class version has an implementation (in spite of being pure | |
95 | // virtual) in base/appbase.cpp which can be called as last resort. | |
96 | // | |
97 | // return true to suppress subsequent asserts, false to continue as before | |
98 | virtual bool ShowAssertDialog(const wxString& msg) = 0; | |
99 | #endif // __WXDEBUG__ | |
100 | ||
101 | // return true if fprintf(stderr) goes somewhere, false otherwise | |
102 | virtual bool HasStderr() = 0; | |
103 | ||
104 | // managing "pending delete" list: in GUI mode we can't immediately delete | |
105 | // some objects because there may be unprocessed events for them and so we | |
106 | // only do it during the next idle loop iteration while this is, of course, | |
107 | // unnecessary in wxBase, so we have a few functions to abstract these | |
108 | // operations | |
109 | ||
110 | // add the object to the pending delete list in GUI, delete it immediately | |
111 | // in wxBase | |
112 | virtual void ScheduleForDestroy(wxObject *object) = 0; | |
113 | ||
114 | // remove this object from the pending delete list in GUI, do nothing in | |
115 | // wxBase | |
116 | virtual void RemoveFromPendingDelete(wxObject *object) = 0; | |
2739d4f0 | 117 | |
38bb138f | 118 | #if wxUSE_SOCKETS |
321b8029 | 119 | // return table of GUI callbacks for GSocket code or NULL in wxBase. This |
4629016d | 120 | // is needed because networking classes are in their own library and so |
321b8029 VS |
121 | // they can't directly call GUI functions (the same net library can be |
122 | // used in both GUI and base apps). To complicate it further, GUI library | |
123 | // ("wxCore") doesn't depend on networking library and so only a functions | |
124 | // table can be passed around | |
38bb138f VS |
125 | virtual GSocketGUIFunctionsTable* GetSocketGUIFunctionsTable() = 0; |
126 | #endif | |
127 | ||
b46b1d59 | 128 | // create a new, port specific, instance of the event loop used by wxApp |
2ddff00c | 129 | virtual wxEventLoopBase *CreateEventLoop() = 0; |
b46b1d59 | 130 | |
c2ca375c VZ |
131 | #if wxUSE_TIMER |
132 | // return platform and toolkit dependent wxTimer implementation | |
133 | virtual wxTimerImpl *CreateTimerImpl(wxTimer *timer) = 0; | |
134 | #endif | |
d774f916 | 135 | |
d254213e PC |
136 | #if wxUSE_THREADS |
137 | virtual void MutexGuiEnter(); | |
138 | virtual void MutexGuiLeave(); | |
139 | #endif | |
140 | ||
d774f916 VZ |
141 | // functions returning port-specific information |
142 | // ------------------------------------------------------------------------ | |
143 | ||
449090b5 VZ |
144 | // return information about the (native) toolkit currently used and its |
145 | // runtime (not compile-time) version. | |
8bb6b2c0 VZ |
146 | // returns wxPORT_BASE for console applications and one of the remaining |
147 | // wxPORT_* values for GUI applications. | |
148 | virtual wxPortId GetToolkitVersion(int *majVer, int *minVer) const = 0; | |
b98bd6af VS |
149 | |
150 | // return true if the port is using wxUniversal for the GUI, false if not | |
151 | virtual bool IsUsingUniversalWidgets() const = 0; | |
db9febdf RR |
152 | |
153 | // return the name of the Desktop Environment such as | |
88bbc332 | 154 | // "KDE" or "GNOME". May return an empty string. |
d3a0a0ee VZ |
155 | virtual wxString GetDesktopEnvironment() const = 0; |
156 | ||
157 | // returns a short string to identify the block of the standard command | |
158 | // line options parsed automatically by current port: if this string is | |
159 | // empty, there are no such options, otherwise the function also fills | |
160 | // passed arrays with the names and the descriptions of those options. | |
161 | virtual wxString GetStandardCmdLineOptions(wxArrayString& names, | |
162 | wxArrayString& desc) const | |
163 | { | |
164 | wxUnusedVar(names); | |
165 | wxUnusedVar(desc); | |
166 | ||
167 | return wxEmptyString; | |
168 | } | |
169 | ||
db9febdf RR |
170 | |
171 | protected: | |
172 | #if wxUSE_STACKWALKER && defined( __WXDEBUG__ ) | |
173 | // utility function: returns the stack frame as a plain wxString | |
174 | virtual wxString GetAssertStackTrace(); | |
175 | #endif | |
e2478fde VZ |
176 | }; |
177 | ||
178 | // ---------------------------------------------------------------------------- | |
179 | // include the platform-specific version of the class | |
180 | // ---------------------------------------------------------------------------- | |
181 | ||
532d575b WS |
182 | // NB: test for __UNIX__ before __WXMAC__ as under Darwin we want to use the |
183 | // Unix code (and otherwise __UNIX__ wouldn't be defined) | |
184 | // ABX: check __WIN32__ instead of __WXMSW__ for the same MSWBase in any Win32 port | |
4055ed82 | 185 | #if defined(__WXPALMOS__) |
ffecfa5a | 186 | #include "wx/palmos/apptbase.h" |
532d575b | 187 | #elif defined(__WIN32__) |
e2478fde | 188 | #include "wx/msw/apptbase.h" |
621ccd8a | 189 | #elif defined(__UNIX__) && !defined(__EMX__) |
2d2d4fc7 | 190 | #include "wx/unix/apptbase.h" |
9fc852b7 SN |
191 | #elif defined(__OS2__) |
192 | #include "wx/os2/apptbase.h" | |
46446cc2 | 193 | #else // no platform-specific methods to add to wxAppTraits |
e2478fde | 194 | // wxAppTraits must be a class because it was forward declared as class |
bb24c68f | 195 | class WXDLLIMPEXP_BASE wxAppTraits : public wxAppTraitsBase |
e2478fde VZ |
196 | { |
197 | }; | |
198 | #endif // platform | |
199 | ||
200 | // ============================================================================ | |
201 | // standard traits for console and GUI applications | |
202 | // ============================================================================ | |
203 | ||
204 | // ---------------------------------------------------------------------------- | |
205 | // wxConsoleAppTraitsBase: wxAppTraits implementation for the console apps | |
206 | // ---------------------------------------------------------------------------- | |
207 | ||
7af1b539 | 208 | class WXDLLIMPEXP_BASE wxConsoleAppTraitsBase : public wxAppTraits |
e2478fde VZ |
209 | { |
210 | public: | |
a1873279 VZ |
211 | #if !wxUSE_CONSOLE_EVENTLOOP |
212 | virtual wxEventLoopBase *CreateEventLoop() { return NULL; } | |
213 | #endif // !wxUSE_CONSOLE_EVENTLOOP | |
214 | ||
e2478fde VZ |
215 | #if wxUSE_LOG |
216 | virtual wxLog *CreateLogTarget(); | |
217 | #endif // wxUSE_LOG | |
218 | virtual wxMessageOutput *CreateMessageOutput(); | |
219 | #if wxUSE_FONTMAP | |
220 | virtual wxFontMapper *CreateFontMapper(); | |
221 | #endif // wxUSE_FONTMAP | |
f0244295 | 222 | virtual wxRendererNative *CreateRenderer(); |
38bb138f VS |
223 | #if wxUSE_SOCKETS |
224 | virtual GSocketGUIFunctionsTable* GetSocketGUIFunctionsTable(); | |
225 | #endif | |
e2478fde VZ |
226 | |
227 | #ifdef __WXDEBUG__ | |
228 | virtual bool ShowAssertDialog(const wxString& msg); | |
229 | #endif // __WXDEBUG__ | |
230 | virtual bool HasStderr(); | |
231 | ||
232 | virtual void ScheduleForDestroy(wxObject *object); | |
233 | virtual void RemoveFromPendingDelete(wxObject *object); | |
8bb6b2c0 VZ |
234 | |
235 | // the GetToolkitVersion for console application is always the same | |
b98bd6af | 236 | virtual wxPortId GetToolkitVersion(int *verMaj, int *verMin) const |
8bb6b2c0 VZ |
237 | { |
238 | // no toolkits (wxBase is for console applications without GUI support) | |
239 | // NB: zero means "no toolkit", -1 means "not initialized yet" | |
240 | // so we must use zero here! | |
241 | if (verMaj) *verMaj = 0; | |
242 | if (verMin) *verMin = 0; | |
243 | return wxPORT_BASE; | |
244 | } | |
b98bd6af VS |
245 | |
246 | virtual bool IsUsingUniversalWidgets() const { return false; } | |
d3a0a0ee | 247 | virtual wxString GetDesktopEnvironment() const { return wxEmptyString; } |
e2478fde VZ |
248 | }; |
249 | ||
250 | // ---------------------------------------------------------------------------- | |
251 | // wxGUIAppTraitsBase: wxAppTraits implementation for the GUI apps | |
252 | // ---------------------------------------------------------------------------- | |
253 | ||
254 | #if wxUSE_GUI | |
255 | ||
94826170 | 256 | class WXDLLEXPORT wxGUIAppTraitsBase : public wxAppTraits |
e2478fde VZ |
257 | { |
258 | public: | |
259 | #if wxUSE_LOG | |
260 | virtual wxLog *CreateLogTarget(); | |
261 | #endif // wxUSE_LOG | |
262 | virtual wxMessageOutput *CreateMessageOutput(); | |
263 | #if wxUSE_FONTMAP | |
264 | virtual wxFontMapper *CreateFontMapper(); | |
265 | #endif // wxUSE_FONTMAP | |
f0244295 | 266 | virtual wxRendererNative *CreateRenderer(); |
38bb138f VS |
267 | #if wxUSE_SOCKETS |
268 | virtual GSocketGUIFunctionsTable* GetSocketGUIFunctionsTable(); | |
269 | #endif | |
e2478fde VZ |
270 | |
271 | #ifdef __WXDEBUG__ | |
272 | virtual bool ShowAssertDialog(const wxString& msg); | |
273 | #endif // __WXDEBUG__ | |
274 | virtual bool HasStderr(); | |
275 | ||
276 | virtual void ScheduleForDestroy(wxObject *object); | |
277 | virtual void RemoveFromPendingDelete(wxObject *object); | |
b98bd6af VS |
278 | |
279 | virtual bool IsUsingUniversalWidgets() const | |
280 | { | |
281 | #ifdef __WXUNIVERSAL__ | |
282 | return true; | |
283 | #else | |
284 | return false; | |
285 | #endif | |
286 | } | |
d3a0a0ee VZ |
287 | |
288 | virtual wxString GetDesktopEnvironment() const { return wxEmptyString; } | |
e2478fde VZ |
289 | }; |
290 | ||
291 | #endif // wxUSE_GUI | |
292 | ||
293 | // ---------------------------------------------------------------------------- | |
294 | // include the platform-specific version of the classes above | |
295 | // ---------------------------------------------------------------------------- | |
296 | ||
532d575b | 297 | // ABX: check __WIN32__ instead of __WXMSW__ for the same MSWBase in any Win32 port |
4055ed82 | 298 | #if defined(__WXPALMOS__) |
ffecfa5a | 299 | #include "wx/palmos/apptrait.h" |
532d575b | 300 | #elif defined(__WIN32__) |
e2478fde | 301 | #include "wx/msw/apptrait.h" |
21d3d342 SN |
302 | #elif defined(__OS2__) |
303 | #include "wx/os2/apptrait.h" | |
304 | #elif defined(__UNIX__) | |
2d2d4fc7 | 305 | #include "wx/unix/apptrait.h" |
9aecec9a MW |
306 | #elif defined(__DOS__) |
307 | #include "wx/msdos/apptrait.h" | |
4629016d | 308 | #else |
e2478fde | 309 | #if wxUSE_GUI |
621ccd8a SN |
310 | class wxGUIAppTraits : public wxGUIAppTraitsBase |
311 | { | |
621ccd8a | 312 | }; |
e2478fde | 313 | #endif // wxUSE_GUI |
4629016d | 314 | class wxConsoleAppTraits: public wxConsoleAppTraitsBase |
621ccd8a | 315 | { |
621ccd8a | 316 | }; |
e2478fde VZ |
317 | #endif // platform |
318 | ||
319 | #endif // _WX_APPTRAIT_H_ | |
320 |