extracted common initialization/cleanup functions in common/init.cpp; standardized...
[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 class WXDLLEXPORT wxAppTraits;
16 #if wxUSE_FONTMAP
17 class WXDLLEXPORT wxFontMapper;
18 #endif // wxUSE_FONTMAP
19 class WXDLLEXPORT wxLog;
20 class WXDLLEXPORT wxMessageOutput;
21
22 // ----------------------------------------------------------------------------
23 // wxAppTraits: this class defines various configurable aspects of wxApp
24 // ----------------------------------------------------------------------------
25
26 class WXDLLEXPORT wxAppTraitsBase
27 {
28 public:
29 // wxAppTraits is an ABC, but we also provide 2 standard implementations of
30 // it, one for the console apps and the other for the GUI ones
31 static wxAppTraits *CreateConsole();
32 #if wxUSE_GUI
33 static wxAppTraits *CreateGUI();
34 #endif // wxUSE_GUI
35
36
37 // hooks for creating the global objects, may be overridden by the user
38 // ------------------------------------------------------------------------
39
40 #if wxUSE_LOG
41 // create the default log target
42 virtual wxLog *CreateLogTarget() = 0;
43 #endif // wxUSE_LOG
44
45 // create the global object used for printing out messages
46 virtual wxMessageOutput *CreateMessageOutput() = 0;
47
48 #if wxUSE_FONTMAP
49 // create the global font mapper object used for encodings/charset mapping
50 virtual wxFontMapper *CreateFontMapper() = 0;
51 #endif // wxUSE_FONTMAP
52
53
54 // functions abstracting differences between GUI and console modes
55 // ------------------------------------------------------------------------
56
57 #ifdef __WXDEBUG__
58 // show the assert dialog with the specified message in GUI or just print
59 // the string to stderr in console mode
60 //
61 // base class version has an implementation (in spite of being pure
62 // virtual) in base/appbase.cpp which can be called as last resort.
63 //
64 // return true to suppress subsequent asserts, false to continue as before
65 virtual bool ShowAssertDialog(const wxString& msg) = 0;
66 #endif // __WXDEBUG__
67
68 // return true if fprintf(stderr) goes somewhere, false otherwise
69 virtual bool HasStderr() = 0;
70
71 // managing "pending delete" list: in GUI mode we can't immediately delete
72 // some objects because there may be unprocessed events for them and so we
73 // only do it during the next idle loop iteration while this is, of course,
74 // unnecessary in wxBase, so we have a few functions to abstract these
75 // operations
76
77 // add the object to the pending delete list in GUI, delete it immediately
78 // in wxBase
79 virtual void ScheduleForDestroy(wxObject *object) = 0;
80
81 // remove this object from the pending delete list in GUI, do nothing in
82 // wxBase
83 virtual void RemoveFromPendingDelete(wxObject *object) = 0;
84
85
86 // other miscellaneous helpers
87 // ---------------------------
88
89 // wxGetOsVersion() behaves differently in GUI and non-GUI builds under
90 // Unix: in the former case it returns the information about the toolkit
91 // and in the latter -- about the OS, so we need to virtualize it
92 virtual int GetOSVersion(int *verMaj, int *verMin) = 0;
93 };
94
95 // ----------------------------------------------------------------------------
96 // include the platform-specific version of the class
97 // ----------------------------------------------------------------------------
98
99 #if defined(__WXMSW__)
100 #include "wx/msw/apptbase.h"
101 #elif defined(__UNIX__)
102 #include "wx/unix/apptbase.h"
103 #else // no platform-specific methods to add to wxAppTraits
104 typedef
105 // wxAppTraits must be a class because it was forward declared as class
106 class WXDLLEXPORT wxAppTraits : public wxAppTraitsBase
107 {
108 };
109 #endif // platform
110
111 // ============================================================================
112 // standard traits for console and GUI applications
113 // ============================================================================
114
115 // ----------------------------------------------------------------------------
116 // wxConsoleAppTraitsBase: wxAppTraits implementation for the console apps
117 // ----------------------------------------------------------------------------
118
119 class WXDLLEXPORT wxConsoleAppTraitsBase : public wxAppTraits
120 {
121 public:
122 #if wxUSE_LOG
123 virtual wxLog *CreateLogTarget();
124 #endif // wxUSE_LOG
125 virtual wxMessageOutput *CreateMessageOutput();
126 #if wxUSE_FONTMAP
127 virtual wxFontMapper *CreateFontMapper();
128 #endif // wxUSE_FONTMAP
129
130 #ifdef __WXDEBUG__
131 virtual bool ShowAssertDialog(const wxString& msg);
132 #endif // __WXDEBUG__
133 virtual bool HasStderr();
134
135 virtual void ScheduleForDestroy(wxObject *object);
136 virtual void RemoveFromPendingDelete(wxObject *object);
137 };
138
139 // ----------------------------------------------------------------------------
140 // wxGUIAppTraitsBase: wxAppTraits implementation for the GUI apps
141 // ----------------------------------------------------------------------------
142
143 #if wxUSE_GUI
144
145 class WXDLLEXPORT wxGUIAppTraitsBase : public wxAppTraits
146 {
147 public:
148 #if wxUSE_LOG
149 virtual wxLog *CreateLogTarget();
150 #endif // wxUSE_LOG
151 virtual wxMessageOutput *CreateMessageOutput();
152 #if wxUSE_FONTMAP
153 virtual wxFontMapper *CreateFontMapper();
154 #endif // wxUSE_FONTMAP
155
156 #ifdef __WXDEBUG__
157 virtual bool ShowAssertDialog(const wxString& msg);
158 #endif // __WXDEBUG__
159 virtual bool HasStderr();
160
161 virtual void ScheduleForDestroy(wxObject *object);
162 virtual void RemoveFromPendingDelete(wxObject *object);
163 };
164
165 #endif // wxUSE_GUI
166
167 // ----------------------------------------------------------------------------
168 // include the platform-specific version of the classes above
169 // ----------------------------------------------------------------------------
170
171 #if defined(__WXMSW__)
172 #include "wx/msw/apptrait.h"
173 #elif defined(__UNIX__)
174 #include "wx/unix/apptrait.h"
175 #else // no platform-specific methods to add to wxAppTraits
176 #if wxUSE_GUI
177 typedef wxGUIAppTraitsBase wxGUIAppTraits;
178 #endif // wxUSE_GUI
179 typedef wxConsoleAppTraitsBase wxConsoleAppTraits;
180 #endif // platform
181
182 #endif // _WX_APPTRAIT_H_
183