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