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