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