]>
Commit | Line | Data |
---|---|---|
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 wxStandardPathsBase; | |
29 | class WXDLLIMPEXP_FWD_BASE wxString; | |
30 | class WXDLLIMPEXP_FWD_BASE wxTimer; | |
31 | class WXDLLIMPEXP_FWD_BASE wxTimerImpl; | |
32 | ||
33 | class GSocketGUIFunctionsTable; | |
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 wxStandardPathsBase& GetStandardPaths(); | |
79 | ||
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 | ||
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; | |
117 | ||
118 | #if wxUSE_SOCKETS | |
119 | // return table of GUI callbacks for GSocket code or NULL in wxBase. This | |
120 | // is needed because networking classes are in their own library and so | |
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 | |
125 | virtual GSocketGUIFunctionsTable* GetSocketGUIFunctionsTable() = 0; | |
126 | #endif | |
127 | ||
128 | // create a new, port specific, instance of the event loop used by wxApp | |
129 | virtual wxEventLoopBase *CreateEventLoop() = 0; | |
130 | ||
131 | #if wxUSE_TIMER | |
132 | // return platform and toolkit dependent wxTimer implementation | |
133 | virtual wxTimerImpl *CreateTimerImpl(wxTimer *timer) = 0; | |
134 | #endif | |
135 | ||
136 | // functions returning port-specific information | |
137 | // ------------------------------------------------------------------------ | |
138 | ||
139 | // return information about the (native) toolkit currently used and its | |
140 | // runtime (not compile-time) version. | |
141 | // returns wxPORT_BASE for console applications and one of the remaining | |
142 | // wxPORT_* values for GUI applications. | |
143 | virtual wxPortId GetToolkitVersion(int *majVer, int *minVer) const = 0; | |
144 | ||
145 | // return true if the port is using wxUniversal for the GUI, false if not | |
146 | virtual bool IsUsingUniversalWidgets() const = 0; | |
147 | ||
148 | // return the name of the Desktop Environment such as | |
149 | // "KDE" or "GNOME". May return an empty string. | |
150 | virtual wxString GetDesktopEnvironment() const = 0; | |
151 | ||
152 | // returns a short string to identify the block of the standard command | |
153 | // line options parsed automatically by current port: if this string is | |
154 | // empty, there are no such options, otherwise the function also fills | |
155 | // passed arrays with the names and the descriptions of those options. | |
156 | virtual wxString GetStandardCmdLineOptions(wxArrayString& names, | |
157 | wxArrayString& desc) const | |
158 | { | |
159 | wxUnusedVar(names); | |
160 | wxUnusedVar(desc); | |
161 | ||
162 | return wxEmptyString; | |
163 | } | |
164 | ||
165 | ||
166 | protected: | |
167 | #if wxUSE_STACKWALKER && defined( __WXDEBUG__ ) | |
168 | // utility function: returns the stack frame as a plain wxString | |
169 | virtual wxString GetAssertStackTrace(); | |
170 | #endif | |
171 | }; | |
172 | ||
173 | // ---------------------------------------------------------------------------- | |
174 | // include the platform-specific version of the class | |
175 | // ---------------------------------------------------------------------------- | |
176 | ||
177 | // NB: test for __UNIX__ before __WXMAC__ as under Darwin we want to use the | |
178 | // Unix code (and otherwise __UNIX__ wouldn't be defined) | |
179 | // ABX: check __WIN32__ instead of __WXMSW__ for the same MSWBase in any Win32 port | |
180 | #if defined(__WXPALMOS__) | |
181 | #include "wx/palmos/apptbase.h" | |
182 | #elif defined(__WIN32__) | |
183 | #include "wx/msw/apptbase.h" | |
184 | #elif defined(__UNIX__) && !defined(__EMX__) | |
185 | #include "wx/unix/apptbase.h" | |
186 | #elif defined(__OS2__) | |
187 | #include "wx/os2/apptbase.h" | |
188 | #else // no platform-specific methods to add to wxAppTraits | |
189 | // wxAppTraits must be a class because it was forward declared as class | |
190 | class WXDLLIMPEXP_BASE wxAppTraits : public wxAppTraitsBase | |
191 | { | |
192 | }; | |
193 | #endif // platform | |
194 | ||
195 | // ============================================================================ | |
196 | // standard traits for console and GUI applications | |
197 | // ============================================================================ | |
198 | ||
199 | // ---------------------------------------------------------------------------- | |
200 | // wxConsoleAppTraitsBase: wxAppTraits implementation for the console apps | |
201 | // ---------------------------------------------------------------------------- | |
202 | ||
203 | class WXDLLIMPEXP_BASE wxConsoleAppTraitsBase : public wxAppTraits | |
204 | { | |
205 | public: | |
206 | #if !wxUSE_CONSOLE_EVENTLOOP | |
207 | virtual wxEventLoopBase *CreateEventLoop() { return NULL; } | |
208 | #endif // !wxUSE_CONSOLE_EVENTLOOP | |
209 | ||
210 | #if wxUSE_LOG | |
211 | virtual wxLog *CreateLogTarget(); | |
212 | #endif // wxUSE_LOG | |
213 | virtual wxMessageOutput *CreateMessageOutput(); | |
214 | #if wxUSE_FONTMAP | |
215 | virtual wxFontMapper *CreateFontMapper(); | |
216 | #endif // wxUSE_FONTMAP | |
217 | virtual wxRendererNative *CreateRenderer(); | |
218 | #if wxUSE_SOCKETS | |
219 | virtual GSocketGUIFunctionsTable* GetSocketGUIFunctionsTable(); | |
220 | #endif | |
221 | ||
222 | #ifdef __WXDEBUG__ | |
223 | virtual bool ShowAssertDialog(const wxString& msg); | |
224 | #endif // __WXDEBUG__ | |
225 | virtual bool HasStderr(); | |
226 | ||
227 | virtual void ScheduleForDestroy(wxObject *object); | |
228 | virtual void RemoveFromPendingDelete(wxObject *object); | |
229 | ||
230 | // the GetToolkitVersion for console application is always the same | |
231 | virtual wxPortId GetToolkitVersion(int *verMaj, int *verMin) const | |
232 | { | |
233 | // no toolkits (wxBase is for console applications without GUI support) | |
234 | // NB: zero means "no toolkit", -1 means "not initialized yet" | |
235 | // so we must use zero here! | |
236 | if (verMaj) *verMaj = 0; | |
237 | if (verMin) *verMin = 0; | |
238 | return wxPORT_BASE; | |
239 | } | |
240 | ||
241 | virtual bool IsUsingUniversalWidgets() const { return false; } | |
242 | virtual wxString GetDesktopEnvironment() const { return wxEmptyString; } | |
243 | }; | |
244 | ||
245 | // ---------------------------------------------------------------------------- | |
246 | // wxGUIAppTraitsBase: wxAppTraits implementation for the GUI apps | |
247 | // ---------------------------------------------------------------------------- | |
248 | ||
249 | #if wxUSE_GUI | |
250 | ||
251 | class WXDLLEXPORT wxGUIAppTraitsBase : public wxAppTraits | |
252 | { | |
253 | public: | |
254 | #if wxUSE_LOG | |
255 | virtual wxLog *CreateLogTarget(); | |
256 | #endif // wxUSE_LOG | |
257 | virtual wxMessageOutput *CreateMessageOutput(); | |
258 | #if wxUSE_FONTMAP | |
259 | virtual wxFontMapper *CreateFontMapper(); | |
260 | #endif // wxUSE_FONTMAP | |
261 | virtual wxRendererNative *CreateRenderer(); | |
262 | #if wxUSE_SOCKETS | |
263 | virtual GSocketGUIFunctionsTable* GetSocketGUIFunctionsTable(); | |
264 | #endif | |
265 | ||
266 | #ifdef __WXDEBUG__ | |
267 | virtual bool ShowAssertDialog(const wxString& msg); | |
268 | #endif // __WXDEBUG__ | |
269 | virtual bool HasStderr(); | |
270 | ||
271 | virtual void ScheduleForDestroy(wxObject *object); | |
272 | virtual void RemoveFromPendingDelete(wxObject *object); | |
273 | ||
274 | virtual bool IsUsingUniversalWidgets() const | |
275 | { | |
276 | #ifdef __WXUNIVERSAL__ | |
277 | return true; | |
278 | #else | |
279 | return false; | |
280 | #endif | |
281 | } | |
282 | ||
283 | virtual wxString GetDesktopEnvironment() const { return wxEmptyString; } | |
284 | }; | |
285 | ||
286 | #endif // wxUSE_GUI | |
287 | ||
288 | // ---------------------------------------------------------------------------- | |
289 | // include the platform-specific version of the classes above | |
290 | // ---------------------------------------------------------------------------- | |
291 | ||
292 | // ABX: check __WIN32__ instead of __WXMSW__ for the same MSWBase in any Win32 port | |
293 | #if defined(__WXPALMOS__) | |
294 | #include "wx/palmos/apptrait.h" | |
295 | #elif defined(__WIN32__) | |
296 | #include "wx/msw/apptrait.h" | |
297 | #elif defined(__OS2__) | |
298 | #include "wx/os2/apptrait.h" | |
299 | #elif defined(__UNIX__) | |
300 | #include "wx/unix/apptrait.h" | |
301 | #elif defined(__DOS__) | |
302 | #include "wx/msdos/apptrait.h" | |
303 | #else | |
304 | #if wxUSE_GUI | |
305 | class wxGUIAppTraits : public wxGUIAppTraitsBase | |
306 | { | |
307 | }; | |
308 | #endif // wxUSE_GUI | |
309 | class wxConsoleAppTraits: public wxConsoleAppTraitsBase | |
310 | { | |
311 | }; | |
312 | #endif // platform | |
313 | ||
314 | #endif // _WX_APPTRAIT_H_ | |
315 |