replaced wxAppTraits::GetOSVersion with GetToolkitInfo with richer information that...
[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@wxwindows.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_APPTRAIT_H_
13 #define _WX_APPTRAIT_H_
14
15 #include "wx/string.h"
16
17 class WXDLLIMPEXP_BASE wxObject;
18 class WXDLLEXPORT wxAppTraits;
19 #if wxUSE_FONTMAP
20 class WXDLLEXPORT wxFontMapper;
21 #endif // wxUSE_FONTMAP
22 class WXDLLIMPEXP_BASE wxLog;
23 class WXDLLIMPEXP_BASE wxMessageOutput;
24 class WXDLLEXPORT wxRendererNative;
25 class WXDLLIMPEXP_BASE wxString;
26 struct WXDLLIMPEXP_BASE wxToolkitInfo;
27
28 // ----------------------------------------------------------------------------
29 // toolkit information
30 // ----------------------------------------------------------------------------
31
32 // Information about the toolkit that the app is running under (e.g. wxMSW):
33 struct WXDLLIMPEXP_BASE wxToolkitInfo
34 {
35 // Short name of the toolkit (e.g. "msw" or "mswuniv"); empty for console:
36 wxString shortName;
37 // Descriptive name of the toolkit, human readable (e.g. "wxMSW" or
38 // "wxMSW/Universal"); "wxBase" for console apps:
39 wxString name;
40 // Version of the underlying toolkit or of the OS for console apps:
41 int versionMajor, versionMinor;
42 // OS mnenomics, e.g. wxGTK or wxMSW:
43 int os;
44 };
45
46
47 // ----------------------------------------------------------------------------
48 // wxAppTraits: this class defines various configurable aspects of wxApp
49 // ----------------------------------------------------------------------------
50
51 class WXDLLIMPEXP_BASE wxAppTraitsBase
52 {
53 public:
54 // hooks for creating the global objects, may be overridden by the user
55 // ------------------------------------------------------------------------
56
57 #if wxUSE_LOG
58 // create the default log target
59 virtual wxLog *CreateLogTarget() = 0;
60 #endif // wxUSE_LOG
61
62 // create the global object used for printing out messages
63 virtual wxMessageOutput *CreateMessageOutput() = 0;
64
65 #if wxUSE_FONTMAP
66 // create the global font mapper object used for encodings/charset mapping
67 virtual wxFontMapper *CreateFontMapper() = 0;
68 #endif // wxUSE_FONTMAP
69
70 // get the renderer to use for drawing the generic controls (return value
71 // may be NULL in which case the default renderer for the current platform
72 // is used); this is used in GUI only and always returns NULL in console
73 //
74 // NB: returned pointer will be deleted by the caller
75 virtual wxRendererNative *CreateRenderer() = 0;
76
77
78 // functions abstracting differences between GUI and console modes
79 // ------------------------------------------------------------------------
80
81 #ifdef __WXDEBUG__
82 // show the assert dialog with the specified message in GUI or just print
83 // the string to stderr in console mode
84 //
85 // base class version has an implementation (in spite of being pure
86 // virtual) in base/appbase.cpp which can be called as last resort.
87 //
88 // return true to suppress subsequent asserts, false to continue as before
89 virtual bool ShowAssertDialog(const wxString& msg) = 0;
90 #endif // __WXDEBUG__
91
92 // return true if fprintf(stderr) goes somewhere, false otherwise
93 virtual bool HasStderr() = 0;
94
95 // managing "pending delete" list: in GUI mode we can't immediately delete
96 // some objects because there may be unprocessed events for them and so we
97 // only do it during the next idle loop iteration while this is, of course,
98 // unnecessary in wxBase, so we have a few functions to abstract these
99 // operations
100
101 // add the object to the pending delete list in GUI, delete it immediately
102 // in wxBase
103 virtual void ScheduleForDestroy(wxObject *object) = 0;
104
105 // remove this object from the pending delete list in GUI, do nothing in
106 // wxBase
107 virtual void RemoveFromPendingDelete(wxObject *object) = 0;
108
109
110 // return information about what toolkit is running; we need for two things
111 // that are both contained in wxBase:
112 // - wxGetOsVersion() behaves differently in GUI and non-GUI builds under
113 // Unix: in the former case it returns the information about the toolkit
114 // and in the latter -- about the OS, so we need to virtualize it
115 // - wxDynamicLibrary::CanonicalizePluginName() must embed toolkit
116 // signature in DLL name
117 virtual wxToolkitInfo *GetToolkitInfo() = 0;
118 };
119
120 // ----------------------------------------------------------------------------
121 // include the platform-specific version of the class
122 // ----------------------------------------------------------------------------
123
124 // NB: test for __UNIX__ before __WXMAC__ as under Darwin we want to use the
125 // Unix code (and otherwise __UNIX__ wouldn't be defined)
126 #if defined(__WXMSW__)
127 #include "wx/msw/apptbase.h"
128 #elif defined(__UNIX__)
129 #include "wx/unix/apptbase.h"
130 #elif defined(__WXMAC__)
131 #include "wx/mac/apptbase.h"
132 #else // no platform-specific methods to add to wxAppTraits
133 // wxAppTraits must be a class because it was forward declared as class
134 class WXDLLIMPEXP_BASE wxAppTraits : public wxAppTraitsBase
135 {
136 };
137 #endif // platform
138
139 // ============================================================================
140 // standard traits for console and GUI applications
141 // ============================================================================
142
143 // ----------------------------------------------------------------------------
144 // wxConsoleAppTraitsBase: wxAppTraits implementation for the console apps
145 // ----------------------------------------------------------------------------
146
147 class WXDLLIMPEXP_BASE wxConsoleAppTraitsBase : public wxAppTraits
148 {
149 public:
150 #if wxUSE_LOG
151 virtual wxLog *CreateLogTarget();
152 #endif // wxUSE_LOG
153 virtual wxMessageOutput *CreateMessageOutput();
154 #if wxUSE_FONTMAP
155 virtual wxFontMapper *CreateFontMapper();
156 #endif // wxUSE_FONTMAP
157 virtual wxRendererNative *CreateRenderer();
158
159 #ifdef __WXDEBUG__
160 virtual bool ShowAssertDialog(const wxString& msg);
161 #endif // __WXDEBUG__
162 virtual bool HasStderr();
163
164 virtual void ScheduleForDestroy(wxObject *object);
165 virtual void RemoveFromPendingDelete(wxObject *object);
166 };
167
168 // ----------------------------------------------------------------------------
169 // wxGUIAppTraitsBase: wxAppTraits implementation for the GUI apps
170 // ----------------------------------------------------------------------------
171
172 #if wxUSE_GUI
173
174 class WXDLLEXPORT wxGUIAppTraitsBase : public wxAppTraits
175 {
176 public:
177 #if wxUSE_LOG
178 virtual wxLog *CreateLogTarget();
179 #endif // wxUSE_LOG
180 virtual wxMessageOutput *CreateMessageOutput();
181 #if wxUSE_FONTMAP
182 virtual wxFontMapper *CreateFontMapper();
183 #endif // wxUSE_FONTMAP
184 virtual wxRendererNative *CreateRenderer();
185
186 #ifdef __WXDEBUG__
187 virtual bool ShowAssertDialog(const wxString& msg);
188 #endif // __WXDEBUG__
189 virtual bool HasStderr();
190
191 virtual void ScheduleForDestroy(wxObject *object);
192 virtual void RemoveFromPendingDelete(wxObject *object);
193 };
194
195 #endif // wxUSE_GUI
196
197 // ----------------------------------------------------------------------------
198 // include the platform-specific version of the classes above
199 // ----------------------------------------------------------------------------
200
201 #if defined(__WXMSW__)
202 #include "wx/msw/apptrait.h"
203 #elif defined(__UNIX__)
204 #include "wx/unix/apptrait.h"
205 #elif defined(__WXMAC__)
206 #include "wx/mac/apptrait.h"
207 #else // no platform-specific methods to add to wxAppTraits
208 #if wxUSE_GUI
209 typedef wxGUIAppTraitsBase wxGUIAppTraits;
210 #endif // wxUSE_GUI
211 typedef wxConsoleAppTraitsBase wxConsoleAppTraits;
212 #endif // platform
213
214 #endif // _WX_APPTRAIT_H_
215