fixed wxBase and GUI separation for sockets code
[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 extern "C" struct 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 wxAppTraitsBase
53 {
54 public:
55 // hooks for creating the global objects, may be overridden by the user
56 // ------------------------------------------------------------------------
57
58 #if wxUSE_LOG
59 // create the default log target
60 virtual wxLog *CreateLogTarget() = 0;
61 #endif // wxUSE_LOG
62
63 // create the global object used for printing out messages
64 virtual wxMessageOutput *CreateMessageOutput() = 0;
65
66 #if wxUSE_FONTMAP
67 // create the global font mapper object used for encodings/charset mapping
68 virtual wxFontMapper *CreateFontMapper() = 0;
69 #endif // wxUSE_FONTMAP
70
71 // get the renderer to use for drawing the generic controls (return value
72 // may be NULL in which case the default renderer for the current platform
73 // is used); this is used in GUI only and always returns NULL in console
74 //
75 // NB: returned pointer will be deleted by the caller
76 virtual wxRendererNative *CreateRenderer() = 0;
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
112 virtual GSocketGUIFunctionsTable* GetSocketGUIFunctionsTable() = 0;
113 #endif
114
115
116 // return information about what toolkit is running; we need for two things
117 // that are both contained in wxBase:
118 // - wxGetOsVersion() behaves differently in GUI and non-GUI builds under
119 // Unix: in the former case it returns the information about the toolkit
120 // and in the latter -- about the OS, so we need to virtualize it
121 // - wxDynamicLibrary::CanonicalizePluginName() must embed toolkit
122 // signature in DLL name
123 virtual wxToolkitInfo& GetToolkitInfo() = 0;
124 };
125
126 // ----------------------------------------------------------------------------
127 // include the platform-specific version of the class
128 // ----------------------------------------------------------------------------
129
130 // NB: test for __UNIX__ before __WXMAC__ as under Darwin we want to use the
131 // Unix code (and otherwise __UNIX__ wouldn't be defined)
132 #if defined(__WXMSW__)
133 #include "wx/msw/apptbase.h"
134 #elif defined(__UNIX__)
135 #include "wx/unix/apptbase.h"
136 #elif defined(__WXMAC__)
137 #include "wx/mac/apptbase.h"
138 #else // no platform-specific methods to add to wxAppTraits
139 // wxAppTraits must be a class because it was forward declared as class
140 class WXDLLIMPEXP_BASE wxAppTraits : public wxAppTraitsBase
141 {
142 };
143 #endif // platform
144
145 // ============================================================================
146 // standard traits for console and GUI applications
147 // ============================================================================
148
149 // ----------------------------------------------------------------------------
150 // wxConsoleAppTraitsBase: wxAppTraits implementation for the console apps
151 // ----------------------------------------------------------------------------
152
153 class WXDLLIMPEXP_BASE wxConsoleAppTraitsBase : public wxAppTraits
154 {
155 public:
156 #if wxUSE_LOG
157 virtual wxLog *CreateLogTarget();
158 #endif // wxUSE_LOG
159 virtual wxMessageOutput *CreateMessageOutput();
160 #if wxUSE_FONTMAP
161 virtual wxFontMapper *CreateFontMapper();
162 #endif // wxUSE_FONTMAP
163 virtual wxRendererNative *CreateRenderer();
164 #if wxUSE_SOCKETS
165 virtual GSocketGUIFunctionsTable* GetSocketGUIFunctionsTable();
166 #endif
167
168 #ifdef __WXDEBUG__
169 virtual bool ShowAssertDialog(const wxString& msg);
170 #endif // __WXDEBUG__
171 virtual bool HasStderr();
172
173 virtual void ScheduleForDestroy(wxObject *object);
174 virtual void RemoveFromPendingDelete(wxObject *object);
175 };
176
177 // ----------------------------------------------------------------------------
178 // wxGUIAppTraitsBase: wxAppTraits implementation for the GUI apps
179 // ----------------------------------------------------------------------------
180
181 #if wxUSE_GUI
182
183 class WXDLLEXPORT wxGUIAppTraitsBase : public wxAppTraits
184 {
185 public:
186 #if wxUSE_LOG
187 virtual wxLog *CreateLogTarget();
188 #endif // wxUSE_LOG
189 virtual wxMessageOutput *CreateMessageOutput();
190 #if wxUSE_FONTMAP
191 virtual wxFontMapper *CreateFontMapper();
192 #endif // wxUSE_FONTMAP
193 virtual wxRendererNative *CreateRenderer();
194 #if wxUSE_SOCKETS
195 virtual GSocketGUIFunctionsTable* GetSocketGUIFunctionsTable();
196 #endif
197
198 #ifdef __WXDEBUG__
199 virtual bool ShowAssertDialog(const wxString& msg);
200 #endif // __WXDEBUG__
201 virtual bool HasStderr();
202
203 virtual void ScheduleForDestroy(wxObject *object);
204 virtual void RemoveFromPendingDelete(wxObject *object);
205 };
206
207 #endif // wxUSE_GUI
208
209 // ----------------------------------------------------------------------------
210 // include the platform-specific version of the classes above
211 // ----------------------------------------------------------------------------
212
213 #if defined(__WXMSW__)
214 #include "wx/msw/apptrait.h"
215 #elif defined(__UNIX__)
216 #include "wx/unix/apptrait.h"
217 #elif defined(__WXMAC__)
218 #include "wx/mac/apptrait.h"
219 #else // no platform-specific methods to add to wxAppTraits
220 #if wxUSE_GUI
221 typedef wxGUIAppTraitsBase wxGUIAppTraits;
222 #endif // wxUSE_GUI
223 typedef wxConsoleAppTraitsBase wxConsoleAppTraits;
224 #endif // platform
225
226 #endif // _WX_APPTRAIT_H_
227