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 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org> 8 // Licence: wxWindows licence 9 /////////////////////////////////////////////////////////////////////////////// 10 11 #ifndef _WX_APPTRAIT_H_ 12 #define _WX_APPTRAIT_H_ 13 14 #include "wx/string.h" 15 #include "wx/platinfo.h" 16 17 class WXDLLIMPEXP_FWD_BASE wxArrayString; 18 class WXDLLIMPEXP_FWD_BASE wxConfigBase; 19 class WXDLLIMPEXP_FWD_BASE wxEventLoopBase; 20 #if wxUSE_FONTMAP 21 class WXDLLIMPEXP_FWD_CORE wxFontMapper; 22 #endif // wxUSE_FONTMAP 23 class WXDLLIMPEXP_FWD_BASE wxLog; 24 class WXDLLIMPEXP_FWD_BASE wxMessageOutput; 25 class WXDLLIMPEXP_FWD_BASE wxObject; 26 class WXDLLIMPEXP_FWD_CORE wxRendererNative; 27 class WXDLLIMPEXP_FWD_BASE wxStandardPaths; 28 class WXDLLIMPEXP_FWD_BASE wxString; 29 class WXDLLIMPEXP_FWD_BASE wxTimer; 30 class WXDLLIMPEXP_FWD_BASE wxTimerImpl; 31 32 class wxSocketManager; 33 34 35 // ---------------------------------------------------------------------------- 36 // wxAppTraits: this class defines various configurable aspects of wxApp 37 // ---------------------------------------------------------------------------- 38 39 class WXDLLIMPEXP_BASE wxAppTraitsBase 40 { 41 public: 42 // needed since this class declares virtual members ~wxAppTraitsBase()43 virtual ~wxAppTraitsBase() { } 44 45 // hooks for working with the global objects, may be overridden by the user 46 // ------------------------------------------------------------------------ 47 48 #if wxUSE_CONFIG 49 // create the default configuration object (base class version is 50 // implemented in config.cpp and creates wxRegConfig for wxMSW and 51 // wxFileConfig for all the other platforms) 52 virtual wxConfigBase *CreateConfig(); 53 #endif // wxUSE_CONFIG 54 55 #if wxUSE_LOG 56 // create the default log target 57 virtual wxLog *CreateLogTarget() = 0; 58 #endif // wxUSE_LOG 59 60 // create the global object used for printing out messages 61 virtual wxMessageOutput *CreateMessageOutput() = 0; 62 63 #if wxUSE_FONTMAP 64 // create the global font mapper object used for encodings/charset mapping 65 virtual wxFontMapper *CreateFontMapper() = 0; 66 #endif // wxUSE_FONTMAP 67 68 // get the renderer to use for drawing the generic controls (return value 69 // may be NULL in which case the default renderer for the current platform 70 // is used); this is used in GUI only and always returns NULL in console 71 // 72 // NB: returned pointer will be deleted by the caller 73 virtual wxRendererNative *CreateRenderer() = 0; 74 75 // wxStandardPaths object is normally the same for wxBase and wxGUI 76 virtual wxStandardPaths& GetStandardPaths(); 77 78 79 // functions abstracting differences between GUI and console modes 80 // ------------------------------------------------------------------------ 81 82 // show the assert dialog with the specified message in GUI or just print 83 // the string to stderr in console mode 84 // 85 // base class version has an implementation (in spite of being pure 86 // virtual) in base/appbase.cpp which can be called as last resort. 87 // 88 // return true to suppress subsequent asserts, false to continue as before 89 virtual bool ShowAssertDialog(const wxString& msg) = 0; 90 91 // show the message safely to the user, i.e. show it in a message box if 92 // possible (even in a console application!) or return false if we can't do 93 // it (e.g. GUI is not initialized at all) 94 // 95 // note that this function can be called even when wxApp doesn't exist, as 96 // it's supposed to be always safe to call -- hence the name 97 // 98 // return true if the message box was shown, false if nothing was done 99 virtual bool SafeMessageBox(const wxString& text, const wxString& title) = 0; 100 101 // return true if fprintf(stderr) goes somewhere, false otherwise 102 virtual bool HasStderr() = 0; 103 104 #if wxUSE_SOCKETS 105 // this function is used by wxNet library to set the default socket manager 106 // to use: doing it like this allows us to keep all socket-related code in 107 // wxNet instead of having to pull it in wxBase itself as we'd have to do 108 // if we really implemented wxSocketManager here 109 // 110 // we don't take ownership of this pointer, it should have a lifetime 111 // greater than that of any socket (e.g. be a pointer to a static object) SetDefaultSocketManager(wxSocketManager * manager)112 static void SetDefaultSocketManager(wxSocketManager *manager) 113 { 114 ms_manager = manager; 115 } 116 117 // return socket manager: this is usually different for console and GUI 118 // applications (although some ports use the same implementation for both) GetSocketManager()119 virtual wxSocketManager *GetSocketManager() { return ms_manager; } 120 #endif 121 122 // create a new, port specific, instance of the event loop used by wxApp 123 virtual wxEventLoopBase *CreateEventLoop() = 0; 124 125 #if wxUSE_TIMER 126 // return platform and toolkit dependent wxTimer implementation 127 virtual wxTimerImpl *CreateTimerImpl(wxTimer *timer) = 0; 128 #endif 129 130 #if wxUSE_THREADS 131 virtual void MutexGuiEnter(); 132 virtual void MutexGuiLeave(); 133 #endif 134 135 // functions returning port-specific information 136 // ------------------------------------------------------------------------ 137 138 // return information about the (native) toolkit currently used and its 139 // runtime (not compile-time) version. 140 // returns wxPORT_BASE for console applications and one of the remaining 141 // wxPORT_* values for GUI applications. 142 virtual wxPortId GetToolkitVersion(int *majVer = NULL, 143 int *minVer = NULL, 144 int *microVer = NULL) const = 0; 145 146 // return true if the port is using wxUniversal for the GUI, false if not 147 virtual bool IsUsingUniversalWidgets() const = 0; 148 149 // return the name of the Desktop Environment such as 150 // "KDE" or "GNOME". May return an empty string. 151 virtual wxString GetDesktopEnvironment() const = 0; 152 153 // returns a short string to identify the block of the standard command 154 // line options parsed automatically by current port: if this string is 155 // empty, there are no such options, otherwise the function also fills 156 // passed arrays with the names and the descriptions of those options. GetStandardCmdLineOptions(wxArrayString & names,wxArrayString & desc)157 virtual wxString GetStandardCmdLineOptions(wxArrayString& names, 158 wxArrayString& desc) const 159 { 160 wxUnusedVar(names); 161 wxUnusedVar(desc); 162 163 return wxEmptyString; 164 } 165 166 167 #if wxUSE_STACKWALKER 168 // Helper function mostly useful for derived classes ShowAssertDialog() 169 // implementation. 170 // 171 // Returns the stack frame as a plain (and possibly empty) wxString. 172 virtual wxString GetAssertStackTrace(); 173 #endif // wxUSE_STACKWALKER 174 175 private: 176 static wxSocketManager *ms_manager; 177 }; 178 179 // ---------------------------------------------------------------------------- 180 // include the platform-specific version of the class 181 // ---------------------------------------------------------------------------- 182 183 // NB: test for __UNIX__ before __WXMAC__ as under Darwin we want to use the 184 // Unix code (and otherwise __UNIX__ wouldn't be defined) 185 // ABX: check __WIN32__ instead of __WXMSW__ for the same MSWBase in any Win32 port 186 #if defined(__WIN32__) 187 #include "wx/msw/apptbase.h" 188 #elif defined(__UNIX__) 189 #include "wx/unix/apptbase.h" 190 #else // no platform-specific methods to add to wxAppTraits 191 // wxAppTraits must be a class because it was forward declared as class 192 class WXDLLIMPEXP_BASE wxAppTraits : public wxAppTraitsBase 193 { 194 }; 195 #endif // platform 196 197 // ============================================================================ 198 // standard traits for console and GUI applications 199 // ============================================================================ 200 201 // ---------------------------------------------------------------------------- 202 // wxConsoleAppTraitsBase: wxAppTraits implementation for the console apps 203 // ---------------------------------------------------------------------------- 204 205 class WXDLLIMPEXP_BASE wxConsoleAppTraitsBase : public wxAppTraits 206 { 207 public: 208 #if !wxUSE_CONSOLE_EVENTLOOP CreateEventLoop()209 virtual wxEventLoopBase *CreateEventLoop() wxOVERRIDE { return NULL; } 210 #endif // !wxUSE_CONSOLE_EVENTLOOP 211 212 #if wxUSE_LOG 213 virtual wxLog *CreateLogTarget() wxOVERRIDE; 214 #endif // wxUSE_LOG 215 virtual wxMessageOutput *CreateMessageOutput() wxOVERRIDE; 216 #if wxUSE_FONTMAP 217 virtual wxFontMapper *CreateFontMapper() wxOVERRIDE; 218 #endif // wxUSE_FONTMAP 219 virtual wxRendererNative *CreateRenderer() wxOVERRIDE; 220 221 virtual bool ShowAssertDialog(const wxString& msg) wxOVERRIDE; 222 virtual bool HasStderr() wxOVERRIDE; 223 virtual bool SafeMessageBox(const wxString& text, 224 const wxString& title) wxOVERRIDE; 225 226 // the GetToolkitVersion for console application is always the same 227 wxPortId GetToolkitVersion(int *verMaj = NULL, 228 int *verMin = NULL, 229 int *verMicro = NULL) const wxOVERRIDE 230 { 231 // no toolkits (wxBase is for console applications without GUI support) 232 // NB: zero means "no toolkit", -1 means "not initialized yet" 233 // so we must use zero here! 234 if (verMaj) *verMaj = 0; 235 if (verMin) *verMin = 0; 236 if (verMicro) *verMicro = 0; 237 return wxPORT_BASE; 238 } 239 IsUsingUniversalWidgets()240 virtual bool IsUsingUniversalWidgets() const wxOVERRIDE { return false; } GetDesktopEnvironment()241 virtual wxString GetDesktopEnvironment() const wxOVERRIDE { return wxEmptyString; } 242 }; 243 244 // ---------------------------------------------------------------------------- 245 // wxGUIAppTraitsBase: wxAppTraits implementation for the GUI apps 246 // ---------------------------------------------------------------------------- 247 248 #if wxUSE_GUI 249 250 class WXDLLIMPEXP_CORE wxGUIAppTraitsBase : public wxAppTraits 251 { 252 public: 253 #if wxUSE_LOG 254 virtual wxLog *CreateLogTarget() wxOVERRIDE; 255 #endif // wxUSE_LOG 256 virtual wxMessageOutput *CreateMessageOutput() wxOVERRIDE; 257 #if wxUSE_FONTMAP 258 virtual wxFontMapper *CreateFontMapper() wxOVERRIDE; 259 #endif // wxUSE_FONTMAP 260 virtual wxRendererNative *CreateRenderer() wxOVERRIDE; 261 262 virtual bool ShowAssertDialog(const wxString& msg) wxOVERRIDE; 263 virtual bool HasStderr() wxOVERRIDE; 264 265 // Win32 has its own implementation using native message box directly in 266 // the base class, don't override it. 267 #ifndef __WIN32__ 268 virtual bool SafeMessageBox(const wxString& text, 269 const wxString& title) wxOVERRIDE; 270 #endif // !__WIN32__ 271 IsUsingUniversalWidgets()272 virtual bool IsUsingUniversalWidgets() const wxOVERRIDE 273 { 274 #ifdef __WXUNIVERSAL__ 275 return true; 276 #else 277 return false; 278 #endif 279 } 280 GetDesktopEnvironment()281 virtual wxString GetDesktopEnvironment() const wxOVERRIDE { return wxEmptyString; } 282 }; 283 284 #endif // wxUSE_GUI 285 286 // ---------------------------------------------------------------------------- 287 // include the platform-specific version of the classes above 288 // ---------------------------------------------------------------------------- 289 290 // ABX: check __WIN32__ instead of __WXMSW__ for the same MSWBase in any Win32 port 291 #if defined(__WIN32__) 292 #include "wx/msw/apptrait.h" 293 #elif defined(__UNIX__) 294 #include "wx/unix/apptrait.h" 295 #else 296 #if wxUSE_GUI 297 class wxGUIAppTraits : public wxGUIAppTraitsBase 298 { 299 }; 300 #endif // wxUSE_GUI 301 class wxConsoleAppTraits: public wxConsoleAppTraitsBase 302 { 303 }; 304 #endif // platform 305 306 #endif // _WX_APPTRAIT_H_ 307 308