1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: declaration of wxAppTraits and derived classes
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_APPTRAIT_H_
13 #define _WX_APPTRAIT_H_
15 #include "wx/string.h"
17 class WXDLLIMPEXP_BASE wxObject
;
18 class WXDLLEXPORT wxAppTraits
;
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
;
27 class GSocketGUIFunctionsTable
;
29 // ----------------------------------------------------------------------------
30 // toolkit information
31 // ----------------------------------------------------------------------------
33 // Information about the toolkit that the app is running under (e.g. wxMSW):
34 struct WXDLLIMPEXP_BASE wxToolkitInfo
36 // Short name of the toolkit (e.g. "msw" or "mswuniv"); empty for console:
38 // Descriptive name of the toolkit, human readable (e.g. "wxMSW" or
39 // "wxMSW/Universal"); "wxBase" for console apps:
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:
48 // ----------------------------------------------------------------------------
49 // wxAppTraits: this class defines various configurable aspects of wxApp
50 // ----------------------------------------------------------------------------
52 class WXDLLIMPEXP_BASE wxAppTraitsBase
55 // hooks for creating the global objects, may be overridden by the user
56 // ------------------------------------------------------------------------
59 // create the default log target
60 virtual wxLog
*CreateLogTarget() = 0;
63 // create the global object used for printing out messages
64 virtual wxMessageOutput
*CreateMessageOutput() = 0;
67 // create the global font mapper object used for encodings/charset mapping
68 virtual wxFontMapper
*CreateFontMapper() = 0;
69 #endif // wxUSE_FONTMAP
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
75 // NB: returned pointer will be deleted by the caller
76 virtual wxRendererNative
*CreateRenderer() = 0;
79 // functions abstracting differences between GUI and console modes
80 // ------------------------------------------------------------------------
83 // show the assert dialog with the specified message in GUI or just print
84 // the string to stderr in console mode
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.
89 // return true to suppress subsequent asserts, false to continue as before
90 virtual bool ShowAssertDialog(const wxString
& msg
) = 0;
93 // return true if fprintf(stderr) goes somewhere, false otherwise
94 virtual bool HasStderr() = 0;
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
102 // add the object to the pending delete list in GUI, delete it immediately
104 virtual void ScheduleForDestroy(wxObject
*object
) = 0;
106 // remove this object from the pending delete list in GUI, do nothing in
108 virtual void RemoveFromPendingDelete(wxObject
*object
) = 0;
111 // return table of GUI callbacks for GSocket code or NULL in wxBase. This
112 // is needed because networking classes are in their own library and so
113 // they can't directly call GUI functions (the same net library can be
114 // used in both GUI and base apps). To complicate it further, GUI library
115 // ("wxCore") doesn't depend on networking library and so only a functions
116 // table can be passed around
117 virtual GSocketGUIFunctionsTable
* GetSocketGUIFunctionsTable() = 0;
121 // return information about what toolkit is running; we need for two things
122 // that are both contained in wxBase:
123 // - wxGetOsVersion() behaves differently in GUI and non-GUI builds under
124 // Unix: in the former case it returns the information about the toolkit
125 // and in the latter -- about the OS, so we need to virtualize it
126 // - wxDynamicLibrary::CanonicalizePluginName() must embed toolkit
127 // signature in DLL name
128 virtual wxToolkitInfo
& GetToolkitInfo() = 0;
131 // ----------------------------------------------------------------------------
132 // include the platform-specific version of the class
133 // ----------------------------------------------------------------------------
135 // NB: test for __UNIX__ before __WXMAC__ as under Darwin we want to use the
136 // Unix code (and otherwise __UNIX__ wouldn't be defined)
137 #if defined(__WXMSW__)
138 #include "wx/msw/apptbase.h"
139 #elif defined(__UNIX__) && !defined(__EMX__)
140 #include "wx/unix/apptbase.h"
141 #elif defined(__WXMAC__)
142 #include "wx/mac/apptbase.h"
143 #elif defined(__OS2__)
144 #include "wx/os2/apptbase.h"
145 #else // no platform-specific methods to add to wxAppTraits
146 // wxAppTraits must be a class because it was forward declared as class
147 class WXDLLIMPEXP_BASE wxAppTraits
: public wxAppTraitsBase
152 // ============================================================================
153 // standard traits for console and GUI applications
154 // ============================================================================
156 // ----------------------------------------------------------------------------
157 // wxConsoleAppTraitsBase: wxAppTraits implementation for the console apps
158 // ----------------------------------------------------------------------------
160 class WXDLLIMPEXP_BASE wxConsoleAppTraitsBase
: public wxAppTraits
164 virtual wxLog
*CreateLogTarget();
166 virtual wxMessageOutput
*CreateMessageOutput();
168 virtual wxFontMapper
*CreateFontMapper();
169 #endif // wxUSE_FONTMAP
170 virtual wxRendererNative
*CreateRenderer();
172 virtual GSocketGUIFunctionsTable
* GetSocketGUIFunctionsTable();
176 virtual bool ShowAssertDialog(const wxString
& msg
);
177 #endif // __WXDEBUG__
178 virtual bool HasStderr();
180 virtual void ScheduleForDestroy(wxObject
*object
);
181 virtual void RemoveFromPendingDelete(wxObject
*object
);
184 // ----------------------------------------------------------------------------
185 // wxGUIAppTraitsBase: wxAppTraits implementation for the GUI apps
186 // ----------------------------------------------------------------------------
190 class WXDLLEXPORT wxGUIAppTraitsBase
: public wxAppTraits
194 virtual wxLog
*CreateLogTarget();
196 virtual wxMessageOutput
*CreateMessageOutput();
198 virtual wxFontMapper
*CreateFontMapper();
199 #endif // wxUSE_FONTMAP
200 virtual wxRendererNative
*CreateRenderer();
202 virtual GSocketGUIFunctionsTable
* GetSocketGUIFunctionsTable();
206 virtual bool ShowAssertDialog(const wxString
& msg
);
207 #endif // __WXDEBUG__
208 virtual bool HasStderr();
210 virtual void ScheduleForDestroy(wxObject
*object
);
211 virtual void RemoveFromPendingDelete(wxObject
*object
);
216 // ----------------------------------------------------------------------------
217 // include the platform-specific version of the classes above
218 // ----------------------------------------------------------------------------
220 #if defined(__WXMSW__)
221 #include "wx/msw/apptrait.h"
222 #elif defined(__UNIX__) && !defined(__EMX__)
223 #include "wx/unix/apptrait.h"
224 #elif defined(__WXMAC__)
225 #include "wx/mac/apptrait.h"
226 #elif defined(__WXPM__)
227 #include "wx/os2/apptrait.h"
229 // at least, we need an implementation of GetToolkitInfo !
231 class wxGUIAppTraits
: public wxGUIAppTraitsBase
233 virtual wxToolkitInfo
& GetToolkitInfo();
236 class wxConsoleAppTraits
: public wxConsoleAppTraitsBase
238 virtual wxToolkitInfo
& GetToolkitInfo();
242 #endif // _WX_APPTRAIT_H_