theme.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/univ/theme.h
  3. // Purpose: wxTheme class manages all configurable aspects of the
  4. // application including the look (wxRenderer), feel
  5. // (wxInputHandler) and the colours (wxColourScheme)
  6. // Author: Vadim Zeitlin
  7. // Modified by:
  8. // Created: 06.08.00
  9. // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
  10. // Licence: wxWindows licence
  11. ///////////////////////////////////////////////////////////////////////////////
  12. #ifndef _WX_UNIV_THEME_H_
  13. #define _WX_UNIV_THEME_H_
  14. #include "wx/string.h"
  15. // ----------------------------------------------------------------------------
  16. // wxTheme
  17. // ----------------------------------------------------------------------------
  18. class WXDLLIMPEXP_FWD_CORE wxArtProvider;
  19. class WXDLLIMPEXP_FWD_CORE wxColourScheme;
  20. class WXDLLIMPEXP_FWD_CORE wxInputConsumer;
  21. class WXDLLIMPEXP_FWD_CORE wxInputHandler;
  22. class WXDLLIMPEXP_FWD_CORE wxRenderer;
  23. struct WXDLLIMPEXP_FWD_CORE wxThemeInfo;
  24. class WXDLLIMPEXP_CORE wxTheme
  25. {
  26. public:
  27. // static methods
  28. // --------------
  29. // create the default theme
  30. static bool CreateDefault();
  31. // create the theme by name (will return NULL if not found)
  32. static wxTheme *Create(const wxString& name);
  33. // change the current scheme
  34. static wxTheme *Set(wxTheme *theme);
  35. // get the current theme (never NULL)
  36. static wxTheme *Get() { return ms_theme; }
  37. // the theme methods
  38. // -----------------
  39. // get the renderer implementing all the control-drawing operations in
  40. // this theme
  41. virtual wxRenderer *GetRenderer() = 0;
  42. // get the art provider to be used together with this theme
  43. virtual wxArtProvider *GetArtProvider() = 0;
  44. // get the input handler of the given type, forward to the standard one
  45. virtual wxInputHandler *GetInputHandler(const wxString& handlerType,
  46. wxInputConsumer *consumer) = 0;
  47. // get the colour scheme for the control with this name
  48. virtual wxColourScheme *GetColourScheme() = 0;
  49. // implementation only from now on
  50. // -------------------------------
  51. virtual ~wxTheme();
  52. private:
  53. // the list of descriptions of all known themes
  54. static wxThemeInfo *ms_allThemes;
  55. // the current theme
  56. static wxTheme *ms_theme;
  57. friend struct wxThemeInfo;
  58. };
  59. // ----------------------------------------------------------------------------
  60. // wxDelegateTheme: it is impossible to inherit from any of standard
  61. // themes as their declarations are in private code, but you can use this
  62. // class to override only some of their functions - all the other ones
  63. // will be left to the original theme
  64. // ----------------------------------------------------------------------------
  65. class WXDLLIMPEXP_CORE wxDelegateTheme : public wxTheme
  66. {
  67. public:
  68. wxDelegateTheme(const wxString& theme);
  69. virtual ~wxDelegateTheme();
  70. virtual wxRenderer *GetRenderer();
  71. virtual wxArtProvider *GetArtProvider();
  72. virtual wxInputHandler *GetInputHandler(const wxString& control,
  73. wxInputConsumer *consumer);
  74. virtual wxColourScheme *GetColourScheme();
  75. protected:
  76. // gets or creates theme and sets m_theme to point to it,
  77. // returns true on success
  78. bool GetOrCreateTheme();
  79. wxString m_themeName;
  80. wxTheme *m_theme;
  81. };
  82. // ----------------------------------------------------------------------------
  83. // dynamic theme creation helpers
  84. // ----------------------------------------------------------------------------
  85. struct WXDLLIMPEXP_CORE wxThemeInfo
  86. {
  87. typedef wxTheme *(*Constructor)();
  88. // theme name and (user readable) description
  89. wxString name, desc;
  90. // the function to create a theme object
  91. Constructor ctor;
  92. // next node in the linked list or NULL
  93. wxThemeInfo *next;
  94. // constructor for the struct itself
  95. wxThemeInfo(Constructor ctor, const wxString& name, const wxString& desc);
  96. };
  97. // ----------------------------------------------------------------------------
  98. // macros
  99. // ----------------------------------------------------------------------------
  100. // to use a standard theme insert this macro into one of the application files:
  101. // without it, an over optimizing linker may discard the object module
  102. // containing the theme implementation entirely
  103. #define WX_USE_THEME(themename) \
  104. /* this indirection makes it possible to pass macro as the argument */ \
  105. WX_USE_THEME_IMPL(themename)
  106. #define WX_USE_THEME_IMPL(themename) \
  107. extern WXDLLIMPEXP_DATA_CORE(bool) wxThemeUse##themename; \
  108. static struct wxThemeUserFor##themename \
  109. { \
  110. wxThemeUserFor##themename() { wxThemeUse##themename = true; } \
  111. } wxThemeDoUse##themename
  112. // to declare a new theme, this macro must be used in the class declaration
  113. #define WX_DECLARE_THEME(themename) \
  114. private: \
  115. static wxThemeInfo ms_info##themename; \
  116. public: \
  117. const wxThemeInfo *GetThemeInfo() const \
  118. { return &ms_info##themename; }
  119. // and this one must be inserted in the source file
  120. #define WX_IMPLEMENT_THEME(classname, themename, themedesc) \
  121. WXDLLIMPEXP_DATA_CORE(bool) wxThemeUse##themename = true; \
  122. wxTheme *wxCtorFor##themename() { return new classname; } \
  123. wxThemeInfo classname::ms_info##themename(wxCtorFor##themename, \
  124. wxT( #themename ), themedesc)
  125. // ----------------------------------------------------------------------------
  126. // determine default theme
  127. // ----------------------------------------------------------------------------
  128. #if wxUSE_ALL_THEMES
  129. #undef wxUSE_THEME_WIN32
  130. #define wxUSE_THEME_WIN32 1
  131. #undef wxUSE_THEME_GTK
  132. #define wxUSE_THEME_GTK 1
  133. #undef wxUSE_THEME_MONO
  134. #define wxUSE_THEME_MONO 1
  135. #undef wxUSE_THEME_METAL
  136. #define wxUSE_THEME_METAL 1
  137. #endif // wxUSE_ALL_THEMES
  138. // determine the default theme to use:
  139. #if defined(__WXGTK__) && wxUSE_THEME_GTK
  140. #define wxUNIV_DEFAULT_THEME gtk
  141. #elif defined(__WXDFB__) && wxUSE_THEME_MONO
  142. // use mono theme for DirectFB port because it cannot correctly
  143. // render neither win32 nor gtk themes yet:
  144. #define wxUNIV_DEFAULT_THEME mono
  145. #endif
  146. // if no theme was picked, get any theme compiled in (sorted by
  147. // quality/completeness of the theme):
  148. #ifndef wxUNIV_DEFAULT_THEME
  149. #if wxUSE_THEME_WIN32
  150. #define wxUNIV_DEFAULT_THEME win32
  151. #elif wxUSE_THEME_GTK
  152. #define wxUNIV_DEFAULT_THEME gtk
  153. #elif wxUSE_THEME_MONO
  154. #define wxUNIV_DEFAULT_THEME mono
  155. #endif
  156. // If nothing matches, no themes are compiled and the app must provide
  157. // some theme itself
  158. // (note that wxUSE_THEME_METAL depends on win32 theme, so we don't have to
  159. // try it)
  160. //
  161. #endif // !wxUNIV_DEFAULT_THEME
  162. #endif // _WX_UNIV_THEME_H_