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 
13 #ifndef _WX_UNIV_THEME_H_
14 #define _WX_UNIV_THEME_H_
15 
16 #include "wx/string.h"
17 
18 // ----------------------------------------------------------------------------
19 // wxTheme
20 // ----------------------------------------------------------------------------
21 
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;
28 
29 class WXDLLIMPEXP_CORE wxTheme
30 {
31 public:
32     // static methods
33     // --------------
34 
35     // create the default theme
36     static bool CreateDefault();
37 
38     // create the theme by name (will return NULL if not found)
39     static wxTheme *Create(const wxString& name);
40 
41     // change the current scheme
42     static wxTheme *Set(wxTheme *theme);
43 
44     // get the current theme (never NULL)
Get()45     static wxTheme *Get() { return ms_theme; }
46 
47     // the theme methods
48     // -----------------
49 
50     // get the renderer implementing all the control-drawing operations in
51     // this theme
52     virtual wxRenderer *GetRenderer() = 0;
53 
54     // get the art provider to be used together with this theme
55     virtual wxArtProvider *GetArtProvider() = 0;
56 
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;
60 
61     // get the colour scheme for the control with this name
62     virtual wxColourScheme *GetColourScheme() = 0;
63 
64     // implementation only from now on
65     // -------------------------------
66 
67     virtual ~wxTheme();
68 
69 private:
70     // the list of descriptions of all known themes
71     static wxThemeInfo *ms_allThemes;
72 
73     // the current theme
74     static wxTheme *ms_theme;
75     friend struct wxThemeInfo;
76 };
77 
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 // ----------------------------------------------------------------------------
84 
85 class WXDLLIMPEXP_CORE wxDelegateTheme : public wxTheme
86 {
87 public:
88     wxDelegateTheme(const wxString& theme);
89     virtual ~wxDelegateTheme();
90 
91     virtual wxRenderer *GetRenderer();
92     virtual wxArtProvider *GetArtProvider();
93     virtual wxInputHandler *GetInputHandler(const wxString& control,
94                                             wxInputConsumer *consumer);
95     virtual wxColourScheme *GetColourScheme();
96 
97 protected:
98     // gets or creates theme and sets m_theme to point to it,
99     // returns true on success
100     bool GetOrCreateTheme();
101 
102     wxString    m_themeName;
103     wxTheme    *m_theme;
104 };
105 
106 // ----------------------------------------------------------------------------
107 // dynamic theme creation helpers
108 // ----------------------------------------------------------------------------
109 
110 struct WXDLLIMPEXP_CORE wxThemeInfo
111 {
112     typedef wxTheme *(*Constructor)();
113 
114     // theme name and (user readable) description
115     wxString name, desc;
116 
117     // the function to create a theme object
118     Constructor ctor;
119 
120     // next node in the linked list or NULL
121     wxThemeInfo *next;
122 
123     // constructor for the struct itself
124     wxThemeInfo(Constructor ctor, const wxString& name, const wxString& desc);
125 };
126 
127 // ----------------------------------------------------------------------------
128 // macros
129 // ----------------------------------------------------------------------------
130 
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)
137 
138 #define WX_USE_THEME_IMPL(themename)                                        \
139     extern WXDLLIMPEXP_DATA_CORE(bool) wxThemeUse##themename;                    \
140     static struct wxThemeUserFor##themename                                 \
141     {                                                                       \
142         wxThemeUserFor##themename() { wxThemeUse##themename = true; }       \
143     } wxThemeDoUse##themename
144 
145 // to declare a new theme, this macro must be used in the class declaration
146 #define WX_DECLARE_THEME(themename)                                         \
147     private:                                                                \
148         static wxThemeInfo ms_info##themename;                              \
149     public:                                                                 \
150         const wxThemeInfo *GetThemeInfo() const                             \
151             { return &ms_info##themename; }
152 
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)
159 
160 // ----------------------------------------------------------------------------
161 // determine default theme
162 // ----------------------------------------------------------------------------
163 
164 #if wxUSE_ALL_THEMES
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
174 
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
182 #endif
183 
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
193     #endif
194     // If nothing matches, no themes are compiled and the app must provide
195     // some theme itself
196     // (note that wxUSE_THEME_METAL depends on win32 theme, so we don't have to
197     // try it)
198     //
199 #endif // !wxUNIV_DEFAULT_THEME
200 
201 #endif // _WX_UNIV_THEME_H_
202