]> git.saurik.com Git - wxWidgets.git/blob - include/wx/apptrait.h
only define globals when wxUSE_BASE to avoid duplicate definitions in wxBase and...
[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
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 class GSocketGUIFunctionsTable;
28
29 // ----------------------------------------------------------------------------
30 // toolkit information
31 // ----------------------------------------------------------------------------
32
33 // Information about the toolkit that the app is running under (e.g. wxMSW):
34 struct WXDLLIMPEXP_BASE wxToolkitInfo
35 {
36 // Short name of the toolkit (e.g. "msw" or "mswuniv"); empty for console:
37 wxString shortName;
38 // Descriptive name of the toolkit, human readable (e.g. "wxMSW" or
39 // "wxMSW/Universal"); "wxBase" for console apps:
40 wxString name;
41 // Version of the underlying toolkit or of the OS for console apps:
42 int versionMajor, versionMinor;
43 // OS mnenomics, e.g. wxGTK or wxMSW:
44 int os;
45 };
46
47
48 // ----------------------------------------------------------------------------
49 // wxAppTraits: this class defines various configurable aspects of wxApp
50 // ----------------------------------------------------------------------------
51
52 class WXDLLIMPEXP_BASE wxStandardPathsBase;
53
54 class WXDLLIMPEXP_BASE wxAppTraitsBase
55 {
56 public:
57 // hooks for creating the global objects, may be overridden by the user
58 // ------------------------------------------------------------------------
59
60 #if wxUSE_LOG
61 // create the default log target
62 virtual wxLog *CreateLogTarget() = 0;
63 #endif // wxUSE_LOG
64
65 // create the global object used for printing out messages
66 virtual wxMessageOutput *CreateMessageOutput() = 0;
67
68 #if wxUSE_FONTMAP
69 // create the global font mapper object used for encodings/charset mapping
70 virtual wxFontMapper *CreateFontMapper() = 0;
71 #endif // wxUSE_FONTMAP
72
73 // get the renderer to use for drawing the generic controls (return value
74 // may be NULL in which case the default renderer for the current platform
75 // is used); this is used in GUI only and always returns NULL in console
76 //
77 // NB: returned pointer will be deleted by the caller
78 virtual wxRendererNative *CreateRenderer() = 0;
79
80 // wxStandardPaths object is normally the same for wxBase and wxGUI
81 // except in the case of wxMac and wxCocoa
82 #ifndef __WXPALMOS__
83 virtual wxStandardPathsBase& GetStandardPaths();
84 #endif
85
86 // functions abstracting differences between GUI and console modes
87 // ------------------------------------------------------------------------
88
89 #ifdef __WXDEBUG__
90 // show the assert dialog with the specified message in GUI or just print
91 // the string to stderr in console mode
92 //
93 // base class version has an implementation (in spite of being pure
94 // virtual) in base/appbase.cpp which can be called as last resort.
95 //
96 // return true to suppress subsequent asserts, false to continue as before
97 virtual bool ShowAssertDialog(const wxString& msg) = 0;
98 #endif // __WXDEBUG__
99
100 // return true if fprintf(stderr) goes somewhere, false otherwise
101 virtual bool HasStderr() = 0;
102
103 // managing "pending delete" list: in GUI mode we can't immediately delete
104 // some objects because there may be unprocessed events for them and so we
105 // only do it during the next idle loop iteration while this is, of course,
106 // unnecessary in wxBase, so we have a few functions to abstract these
107 // operations
108
109 // add the object to the pending delete list in GUI, delete it immediately
110 // in wxBase
111 virtual void ScheduleForDestroy(wxObject *object) = 0;
112
113 // remove this object from the pending delete list in GUI, do nothing in
114 // wxBase
115 virtual void RemoveFromPendingDelete(wxObject *object) = 0;
116
117 #if wxUSE_SOCKETS
118 // return table of GUI callbacks for GSocket code or NULL in wxBase. This
119 // is needed because networking classes are in their own library and so
120 // they can't directly call GUI functions (the same net library can be
121 // used in both GUI and base apps). To complicate it further, GUI library
122 // ("wxCore") doesn't depend on networking library and so only a functions
123 // table can be passed around
124 virtual GSocketGUIFunctionsTable* GetSocketGUIFunctionsTable() = 0;
125 #endif
126
127
128 // return information about what toolkit is running; we need for two things
129 // that are both contained in wxBase:
130 // - wxGetOsVersion() behaves differently in GUI and non-GUI builds under
131 // Unix: in the former case it returns the information about the toolkit
132 // and in the latter -- about the OS, so we need to virtualize it
133 // - wxDynamicLibrary::CanonicalizePluginName() must embed toolkit
134 // signature in DLL name
135 virtual wxToolkitInfo& GetToolkitInfo() = 0;
136 };
137
138 // ----------------------------------------------------------------------------
139 // include the platform-specific version of the class
140 // ----------------------------------------------------------------------------
141
142 // NB: test for __UNIX__ before __WXMAC__ as under Darwin we want to use the
143 // Unix code (and otherwise __UNIX__ wouldn't be defined)
144 #if defined(__WXPALMOS__)
145 #include "wx/palmos/apptbase.h"
146 #elif defined(__WXMSW__)
147 #include "wx/msw/apptbase.h"
148 #elif defined(__UNIX__) && !defined(__EMX__)
149 #include "wx/unix/apptbase.h"
150 #elif defined(__WXMAC__)
151 #include "wx/mac/apptbase.h"
152 #elif defined(__OS2__)
153 #include "wx/os2/apptbase.h"
154 #else // no platform-specific methods to add to wxAppTraits
155 // wxAppTraits must be a class because it was forward declared as class
156 class WXDLLIMPEXP_BASE wxAppTraits : public wxAppTraitsBase
157 {
158 };
159 #endif // platform
160
161 // ============================================================================
162 // standard traits for console and GUI applications
163 // ============================================================================
164
165 // ----------------------------------------------------------------------------
166 // wxConsoleAppTraitsBase: wxAppTraits implementation for the console apps
167 // ----------------------------------------------------------------------------
168
169 class WXDLLIMPEXP_BASE wxConsoleAppTraitsBase : public wxAppTraits
170 {
171 public:
172 #if wxUSE_LOG
173 virtual wxLog *CreateLogTarget();
174 #endif // wxUSE_LOG
175 virtual wxMessageOutput *CreateMessageOutput();
176 #if wxUSE_FONTMAP
177 virtual wxFontMapper *CreateFontMapper();
178 #endif // wxUSE_FONTMAP
179 virtual wxRendererNative *CreateRenderer();
180 #if wxUSE_SOCKETS
181 virtual GSocketGUIFunctionsTable* GetSocketGUIFunctionsTable();
182 #endif
183
184 #ifdef __WXDEBUG__
185 virtual bool ShowAssertDialog(const wxString& msg);
186 #endif // __WXDEBUG__
187 virtual bool HasStderr();
188
189 virtual void ScheduleForDestroy(wxObject *object);
190 virtual void RemoveFromPendingDelete(wxObject *object);
191 };
192
193 // ----------------------------------------------------------------------------
194 // wxGUIAppTraitsBase: wxAppTraits implementation for the GUI apps
195 // ----------------------------------------------------------------------------
196
197 #if wxUSE_GUI
198
199 class WXDLLEXPORT wxGUIAppTraitsBase : public wxAppTraits
200 {
201 public:
202 #if wxUSE_LOG
203 virtual wxLog *CreateLogTarget();
204 #endif // wxUSE_LOG
205 virtual wxMessageOutput *CreateMessageOutput();
206 #if wxUSE_FONTMAP
207 virtual wxFontMapper *CreateFontMapper();
208 #endif // wxUSE_FONTMAP
209 virtual wxRendererNative *CreateRenderer();
210 #if wxUSE_SOCKETS
211 virtual GSocketGUIFunctionsTable* GetSocketGUIFunctionsTable();
212 #endif
213
214 #ifdef __WXDEBUG__
215 virtual bool ShowAssertDialog(const wxString& msg);
216 #endif // __WXDEBUG__
217 virtual bool HasStderr();
218
219 virtual void ScheduleForDestroy(wxObject *object);
220 virtual void RemoveFromPendingDelete(wxObject *object);
221 };
222
223 #endif // wxUSE_GUI
224
225 // ----------------------------------------------------------------------------
226 // include the platform-specific version of the classes above
227 // ----------------------------------------------------------------------------
228
229 #if defined(__WXPALMOS__)
230 #include "wx/palmos/apptrait.h"
231 #elif defined(__WXMSW__)
232 #include "wx/msw/apptrait.h"
233 #elif defined(__UNIX__) && !defined(__EMX__)
234 #include "wx/unix/apptrait.h"
235 #elif defined(__WXMAC__)
236 #include "wx/mac/apptrait.h"
237 #elif defined(__WXPM__)
238 #include "wx/os2/apptrait.h"
239 #else
240 // at least, we need an implementation of GetToolkitInfo !
241 #if wxUSE_GUI
242 class wxGUIAppTraits : public wxGUIAppTraitsBase
243 {
244 virtual wxToolkitInfo& GetToolkitInfo();
245 };
246 #endif // wxUSE_GUI
247 class wxConsoleAppTraits: public wxConsoleAppTraitsBase
248 {
249 virtual wxToolkitInfo& GetToolkitInfo();
250 };
251 #endif // platform
252
253 #endif // _WX_APPTRAIT_H_
254