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