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
9 // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
10 // Licence: wxWindows licence
11 ///////////////////////////////////////////////////////////////////////////////
13 #ifndef _WX_UNIV_THEME_H_
14 #define _WX_UNIV_THEME_H_
16 #include "wx/string.h"
18 // ----------------------------------------------------------------------------
20 // ----------------------------------------------------------------------------
22 class WXDLLIMPEXP_FWD_CORE wxArtProvider
;
23 class WXDLLIMPEXP_FWD_CORE wxColourScheme
;
24 class WXDLLIMPEXP_FWD_CORE wxInputConsumer
;
25 class WXDLLIMPEXP_FWD_CORE wxInputHandler
;
26 class WXDLLIMPEXP_FWD_CORE wxRenderer
;
27 struct WXDLLIMPEXP_FWD_CORE wxThemeInfo
;
29 class WXDLLIMPEXP_CORE wxTheme
35 // create the default theme
36 static bool CreateDefault();
38 // create the theme by name (will return NULL if not found)
39 static wxTheme
*Create(const wxString
& name
);
41 // change the current scheme
42 static wxTheme
*Set(wxTheme
*theme
);
44 // get the current theme (never NULL)
45 static wxTheme
*Get() { return ms_theme
; }
50 // get the renderer implementing all the control-drawing operations in
52 virtual wxRenderer
*GetRenderer() = 0;
54 // get the art provider to be used together with this theme
55 virtual wxArtProvider
*GetArtProvider() = 0;
57 // get the input handler of the given type, forward to the standard one
58 virtual wxInputHandler
*GetInputHandler(const wxString
& handlerType
,
59 wxInputConsumer
*consumer
) = 0;
61 // get the colour scheme for the control with this name
62 virtual wxColourScheme
*GetColourScheme() = 0;
64 // implementation only from now on
65 // -------------------------------
70 // the list of descriptions of all known themes
71 static wxThemeInfo
*ms_allThemes
;
74 static wxTheme
*ms_theme
;
75 friend struct wxThemeInfo
;
78 // ----------------------------------------------------------------------------
79 // wxDelegateTheme: it is impossible to inherit from any of standard
80 // themes as their declarations are in private code, but you can use this
81 // class to override only some of their functions - all the other ones
82 // will be left to the original theme
83 // ----------------------------------------------------------------------------
85 class WXDLLIMPEXP_CORE wxDelegateTheme
: public wxTheme
88 wxDelegateTheme(const wxString
& theme
);
89 virtual ~wxDelegateTheme();
91 virtual wxRenderer
*GetRenderer();
92 virtual wxArtProvider
*GetArtProvider();
93 virtual wxInputHandler
*GetInputHandler(const wxString
& control
,
94 wxInputConsumer
*consumer
);
95 virtual wxColourScheme
*GetColourScheme();
98 // gets or creates theme and sets m_theme to point to it,
99 // returns true on success
100 bool GetOrCreateTheme();
102 wxString m_themeName
;
106 // ----------------------------------------------------------------------------
107 // dynamic theme creation helpers
108 // ----------------------------------------------------------------------------
110 struct WXDLLIMPEXP_CORE wxThemeInfo
112 typedef wxTheme
*(*Constructor
)();
114 // theme name and (user readable) description
117 // the function to create a theme object
120 // next node in the linked list or NULL
123 // constructor for the struct itself
124 wxThemeInfo(Constructor ctor
, const wxString
& name
, const wxString
& desc
);
127 // ----------------------------------------------------------------------------
129 // ----------------------------------------------------------------------------
131 // to use a standard theme insert this macro into one of the application files:
132 // without it, an over optimizing linker may discard the object module
133 // containing the theme implementation entirely
134 #define WX_USE_THEME(themename) \
135 /* this indirection makes it possible to pass macro as the argument */ \
136 WX_USE_THEME_IMPL(themename)
138 #define WX_USE_THEME_IMPL(themename) \
139 extern WXDLLIMPEXP_DATA_CORE(bool) wxThemeUse##themename; \
140 static struct wxThemeUserFor##themename \
142 wxThemeUserFor##themename() { wxThemeUse##themename = true; } \
143 } wxThemeDoUse##themename
145 // to declare a new theme, this macro must be used in the class declaration
146 #define WX_DECLARE_THEME(themename) \
148 static wxThemeInfo ms_info##themename; \
150 const wxThemeInfo *GetThemeInfo() const \
151 { return &ms_info##themename; }
153 // and this one must be inserted in the source file
154 #define WX_IMPLEMENT_THEME(classname, themename, themedesc) \
155 WXDLLIMPEXP_DATA_CORE(bool) wxThemeUse##themename = true; \
156 wxTheme *wxCtorFor##themename() { return new classname; } \
157 wxThemeInfo classname::ms_info##themename(wxCtorFor##themename, \
158 wxT( #themename ), themedesc)
160 // ----------------------------------------------------------------------------
161 // determine default theme
162 // ----------------------------------------------------------------------------
165 #undef wxUSE_THEME_WIN32
166 #define wxUSE_THEME_WIN32 1
167 #undef wxUSE_THEME_GTK
168 #define wxUSE_THEME_GTK 1
169 #undef wxUSE_THEME_MONO
170 #define wxUSE_THEME_MONO 1
171 #undef wxUSE_THEME_METAL
172 #define wxUSE_THEME_METAL 1
173 #endif // wxUSE_ALL_THEMES
175 // determine the default theme to use:
176 #if defined(__WXGTK__) && wxUSE_THEME_GTK
177 #define wxUNIV_DEFAULT_THEME gtk
178 #elif defined(__WXDFB__) && wxUSE_THEME_MONO
179 // use mono theme for DirectFB port because it cannot correctly
180 // render neither win32 nor gtk themes yet:
181 #define wxUNIV_DEFAULT_THEME mono
184 // if no theme was picked, get any theme compiled in (sorted by
185 // quality/completeness of the theme):
186 #ifndef wxUNIV_DEFAULT_THEME
187 #if wxUSE_THEME_WIN32
188 #define wxUNIV_DEFAULT_THEME win32
189 #elif wxUSE_THEME_GTK
190 #define wxUNIV_DEFAULT_THEME gtk
191 #elif wxUSE_THEME_MONO
192 #define wxUNIV_DEFAULT_THEME mono
194 // If nothing matches, no themes are compiled and the app must provide
196 // (note that wxUSE_THEME_METAL depends on win32 theme, so we don't have to
199 #endif // !wxUNIV_DEFAULT_THEME
201 #endif // _WX_UNIV_THEME_H_