apptrait.h 10 KB

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