]>
Commit | Line | Data |
---|---|---|
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 creating 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 | // functions abstracting differences between GUI and console modes | |
73 | // ------------------------------------------------------------------------ | |
74 | ||
75 | #ifdef __WXDEBUG__ | |
76 | // show the assert dialog with the specified message in GUI or just print | |
77 | // the string to stderr in console mode | |
78 | // | |
79 | // base class version has an implementation (in spite of being pure | |
80 | // virtual) in base/appbase.cpp which can be called as last resort. | |
81 | // | |
82 | // return true to suppress subsequent asserts, false to continue as before | |
83 | virtual bool ShowAssertDialog(const wxString& msg) = 0; | |
84 | #endif // __WXDEBUG__ | |
85 | ||
86 | // return true if fprintf(stderr) goes somewhere, false otherwise | |
87 | virtual bool HasStderr() = 0; | |
88 | ||
89 | // managing "pending delete" list: in GUI mode we can't immediately delete | |
90 | // some objects because there may be unprocessed events for them and so we | |
91 | // only do it during the next idle loop iteration while this is, of course, | |
92 | // unnecessary in wxBase, so we have a few functions to abstract these | |
93 | // operations | |
94 | ||
95 | // add the object to the pending delete list in GUI, delete it immediately | |
96 | // in wxBase | |
97 | virtual void ScheduleForDestroy(wxObject *object) = 0; | |
98 | ||
99 | // remove this object from the pending delete list in GUI, do nothing in | |
100 | // wxBase | |
101 | virtual void RemoveFromPendingDelete(wxObject *object) = 0; | |
102 | ||
103 | #if wxUSE_SOCKETS | |
104 | // return table of GUI callbacks for GSocket code or NULL in wxBase. This | |
105 | // is needed because networking classes are in their own library and so | |
106 | // they can't directly call GUI functions (the same net library can be | |
107 | // used in both GUI and base apps). To complicate it further, GUI library | |
108 | // ("wxCore") doesn't depend on networking library and so only a functions | |
109 | // table can be passed around | |
110 | virtual GSocketGUIFunctionsTable* GetSocketGUIFunctionsTable() = 0; | |
111 | #endif | |
112 | ||
113 | // return information about the (native) toolkit currently used; | |
114 | // returns wxPORT_BASE for console applications and one of the remaining | |
115 | // wxPORT_* values for GUI applications. | |
116 | virtual wxPortId GetToolkitVersion(int *majVer, int *minVer) const = 0; | |
117 | ||
118 | // return true if the port is using wxUniversal for the GUI, false if not | |
119 | virtual bool IsUsingUniversalWidgets() const = 0; | |
120 | }; | |
121 | ||
122 | // ---------------------------------------------------------------------------- | |
123 | // include the platform-specific version of the class | |
124 | // ---------------------------------------------------------------------------- | |
125 | ||
126 | // NB: test for __UNIX__ before __WXMAC__ as under Darwin we want to use the | |
127 | // Unix code (and otherwise __UNIX__ wouldn't be defined) | |
128 | // ABX: check __WIN32__ instead of __WXMSW__ for the same MSWBase in any Win32 port | |
129 | #if defined(__WXPALMOS__) | |
130 | #include "wx/palmos/apptbase.h" | |
131 | #elif defined(__WIN32__) | |
132 | #include "wx/msw/apptbase.h" | |
133 | #elif defined(__UNIX__) && !defined(__EMX__) | |
134 | #include "wx/unix/apptbase.h" | |
135 | #elif defined(__WXMAC__) | |
136 | #include "wx/mac/apptbase.h" | |
137 | #elif defined(__OS2__) | |
138 | #include "wx/os2/apptbase.h" | |
139 | #else // no platform-specific methods to add to wxAppTraits | |
140 | // wxAppTraits must be a class because it was forward declared as class | |
141 | class WXDLLIMPEXP_BASE wxAppTraits : public wxAppTraitsBase | |
142 | { | |
143 | }; | |
144 | #endif // platform | |
145 | ||
146 | // ============================================================================ | |
147 | // standard traits for console and GUI applications | |
148 | // ============================================================================ | |
149 | ||
150 | // ---------------------------------------------------------------------------- | |
151 | // wxConsoleAppTraitsBase: wxAppTraits implementation for the console apps | |
152 | // ---------------------------------------------------------------------------- | |
153 | ||
154 | class WXDLLIMPEXP_BASE wxConsoleAppTraitsBase : public wxAppTraits | |
155 | { | |
156 | public: | |
157 | #if wxUSE_LOG | |
158 | virtual wxLog *CreateLogTarget(); | |
159 | #endif // wxUSE_LOG | |
160 | virtual wxMessageOutput *CreateMessageOutput(); | |
161 | #if wxUSE_FONTMAP | |
162 | virtual wxFontMapper *CreateFontMapper(); | |
163 | #endif // wxUSE_FONTMAP | |
164 | virtual wxRendererNative *CreateRenderer(); | |
165 | #if wxUSE_SOCKETS | |
166 | virtual GSocketGUIFunctionsTable* GetSocketGUIFunctionsTable(); | |
167 | #endif | |
168 | ||
169 | #ifdef __WXDEBUG__ | |
170 | virtual bool ShowAssertDialog(const wxString& msg); | |
171 | #endif // __WXDEBUG__ | |
172 | virtual bool HasStderr(); | |
173 | ||
174 | virtual void ScheduleForDestroy(wxObject *object); | |
175 | virtual void RemoveFromPendingDelete(wxObject *object); | |
176 | ||
177 | // the GetToolkitVersion for console application is always the same | |
178 | virtual wxPortId GetToolkitVersion(int *verMaj, int *verMin) const | |
179 | { | |
180 | // no toolkits (wxBase is for console applications without GUI support) | |
181 | // NB: zero means "no toolkit", -1 means "not initialized yet" | |
182 | // so we must use zero here! | |
183 | if (verMaj) *verMaj = 0; | |
184 | if (verMin) *verMin = 0; | |
185 | return wxPORT_BASE; | |
186 | } | |
187 | ||
188 | virtual bool IsUsingUniversalWidgets() const { return false; } | |
189 | }; | |
190 | ||
191 | // ---------------------------------------------------------------------------- | |
192 | // wxGUIAppTraitsBase: wxAppTraits implementation for the GUI apps | |
193 | // ---------------------------------------------------------------------------- | |
194 | ||
195 | #if wxUSE_GUI | |
196 | ||
197 | class WXDLLEXPORT wxGUIAppTraitsBase : 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 | virtual bool IsUsingUniversalWidgets() const | |
221 | { | |
222 | #ifdef __WXUNIVERSAL__ | |
223 | return true; | |
224 | #else | |
225 | return false; | |
226 | #endif | |
227 | } | |
228 | }; | |
229 | ||
230 | #endif // wxUSE_GUI | |
231 | ||
232 | // ---------------------------------------------------------------------------- | |
233 | // include the platform-specific version of the classes above | |
234 | // ---------------------------------------------------------------------------- | |
235 | ||
236 | // ABX: check __WIN32__ instead of __WXMSW__ for the same MSWBase in any Win32 port | |
237 | #if defined(__WXPALMOS__) | |
238 | #include "wx/palmos/apptrait.h" | |
239 | #elif defined(__WIN32__) | |
240 | #include "wx/msw/apptrait.h" | |
241 | #elif defined(__UNIX__) && !defined(__EMX__) | |
242 | #include "wx/unix/apptrait.h" | |
243 | #elif defined(__WXMAC__) | |
244 | #include "wx/mac/apptrait.h" | |
245 | #elif defined(__WXPM__) | |
246 | #include "wx/os2/apptrait.h" | |
247 | #elif defined(__DOS__) | |
248 | #include "wx/msdos/apptrait.h" | |
249 | #else | |
250 | #if wxUSE_GUI | |
251 | class wxGUIAppTraits : public wxGUIAppTraitsBase | |
252 | { | |
253 | }; | |
254 | #endif // wxUSE_GUI | |
255 | class wxConsoleAppTraits: public wxConsoleAppTraitsBase | |
256 | { | |
257 | }; | |
258 | #endif // platform | |
259 | ||
260 | #endif // _WX_APPTRAIT_H_ | |
261 |