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