]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/uxtheme.h
avoiding crash for pure modifier events
[wxWidgets.git] / include / wx / msw / uxtheme.h
CommitLineData
2d9c0e97
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: include/wx/msw/uxtheme.h
3// Purpose: wxUxThemeEngine class: support for XP themes
0ea1cce3 4// Author: John Platts, Vadim Zeitlin
2d9c0e97
VZ
5// Modified by:
6// Created: 2003
7// RCS-ID: $Id$
0ea1cce3 8// Copyright: (c) 2003 John Platts, Vadim Zeitlin
65571936 9// License: wxWindows licence
2d9c0e97 10///////////////////////////////////////////////////////////////////////////////
0d1cb8cb
JS
11
12#ifndef _WX_UXTHEME_H_
13#define _WX_UXTHEME_H_
14
2d9c0e97 15#include "wx/defs.h"
0d1cb8cb 16
e6efee00 17#include "wx/msw/private.h" // we use GetHwndOf()
92199f4c
JS
18#include "wx/msw/uxthemep.h"
19
20typedef HTHEME (__stdcall *PFNWXUOPENTHEMEDATA)(HWND, const wchar_t *);
21typedef HRESULT (__stdcall *PFNWXUCLOSETHEMEDATA)(HTHEME);
22typedef HRESULT (__stdcall *PFNWXUDRAWTHEMEBACKGROUND)(HTHEME, HDC, int, int, const RECT *, const RECT *);
23typedef HRESULT (__stdcall *PFNWXUDRAWTHEMETEXT)(HTHEME, HDC, int, int, const wchar_t *, int, DWORD, DWORD, const RECT *);
24typedef HRESULT (__stdcall *PFNWXUGETTHEMEBACKGROUNDCONTENTRECT)(HTHEME, HDC, int, int, const RECT *, RECT *);
25typedef HRESULT (__stdcall *PFNWXUGETTHEMEBACKGROUNDEXTENT)(HTHEME, HDC, int, int, const RECT *, RECT *);
26typedef HRESULT (__stdcall *PFNWXUGETTHEMEPARTSIZE)(HTHEME, HDC, int, int, const RECT *, /* enum */ THEMESIZE, SIZE *);
27typedef HRESULT (__stdcall *PFNWXUGETTHEMETEXTEXTENT)(HTHEME, HDC, int, int, const wchar_t *, int, DWORD, const RECT *, RECT *);
28typedef HRESULT (__stdcall *PFNWXUGETTHEMETEXTMETRICS)(HTHEME, HDC, int, int, TEXTMETRIC*);
29typedef HRESULT (__stdcall *PFNWXUGETTHEMEBACKGROUNDREGION)(HTHEME, HDC, int, int, const RECT *, HRGN *);
30typedef HRESULT (__stdcall *PFNWXUHITTESTTHEMEBACKGROUND)(HTHEME, HDC, int, int, DWORD, const RECT *, HRGN, POINT, unsigned short *);
31typedef HRESULT (__stdcall *PFNWXUDRAWTHEMEEDGE)(HTHEME, HDC, int, int, const RECT *, unsigned int, unsigned int, RECT *);
32typedef HRESULT (__stdcall *PFNWXUDRAWTHEMEICON)(HTHEME, HDC, int, int, const RECT *, HIMAGELIST, int);
33typedef BOOL (__stdcall *PFNWXUISTHEMEPARTDEFINED)(HTHEME, int, int);
34typedef BOOL (__stdcall *PFNWXUISTHEMEBACKGROUNDPARTIALLYTRANSPARENT)(HTHEME, int, int);
35typedef HRESULT (__stdcall *PFNWXUGETTHEMECOLOR)(HTHEME, int, int, int, COLORREF*);
36typedef HRESULT (__stdcall *PFNWXUGETTHEMEMETRIC)(HTHEME, HDC, int, int, int, int *);
37typedef HRESULT (__stdcall *PFNWXUGETTHEMESTRING)(HTHEME, int, int, int, wchar_t *, int);
38typedef HRESULT (__stdcall *PFNWXUGETTHEMEBOOL)(HTHEME, int, int, int, BOOL *);
39typedef HRESULT (__stdcall *PFNWXUGETTHEMEINT)(HTHEME, int, int, int, int *);
40typedef HRESULT (__stdcall *PFNWXUGETTHEMEENUMVALUE)(HTHEME, int, int, int, int *);
41typedef HRESULT (__stdcall *PFNWXUGETTHEMEPOSITION)(HTHEME, int, int, int, POINT *);
42typedef HRESULT (__stdcall *PFNWXUGETTHEMEFONT)(HTHEME, HDC, int, int, int, LOGFONT *);
43typedef HRESULT (__stdcall *PFNWXUGETTHEMERECT)(HTHEME, int, int, int, RECT *);
44typedef HRESULT (__stdcall *PFNWXUGETTHEMEMARGINS)(HTHEME, HDC, int, int, int, RECT *, MARGINS *);
45typedef HRESULT (__stdcall *PFNWXUGETTHEMEINTLIST)(HTHEME, int, int, int, INTLIST*);
46typedef HRESULT (__stdcall *PFNWXUGETTHEMEPROPERTYORIGIN)(HTHEME, int, int, int, /* enum */ PROPERTYORIGIN *);
47typedef HRESULT (__stdcall *PFNWXUSETWINDOWTHEME)(HWND, const wchar_t*, const wchar_t *);
48typedef HRESULT (__stdcall *PFNWXUGETTHEMEFILENAME)(HTHEME, int, int, int, wchar_t *, int);
49typedef COLORREF(__stdcall *PFNWXUGETTHEMESYSCOLOR)(HTHEME, int);
50typedef HBRUSH (__stdcall *PFNWXUGETTHEMESYSCOLORBRUSH)(HTHEME, int);
51typedef BOOL (__stdcall *PFNWXUGETTHEMESYSBOOL)(HTHEME, int);
52typedef int (__stdcall *PFNWXUGETTHEMESYSSIZE)(HTHEME, int);
53typedef HRESULT (__stdcall *PFNWXUGETTHEMESYSFONT)(HTHEME, int, LOGFONT *);
54typedef HRESULT (__stdcall *PFNWXUGETTHEMESYSSTRING)(HTHEME, int, wchar_t *, int);
55typedef HRESULT (__stdcall *PFNWXUGETTHEMESYSINT)(HTHEME, int, int *);
56typedef BOOL (__stdcall *PFNWXUISTHEMEACTIVE)();
57typedef BOOL (__stdcall *PFNWXUISAPPTHEMED)();
58typedef HTHEME (__stdcall *PFNWXUGETWINDOWTHEME)(HWND);
59typedef HRESULT (__stdcall *PFNWXUENABLETHEMEDIALOGTEXTURE)(HWND, DWORD);
60typedef BOOL (__stdcall *PFNWXUISTHEMEDIALOGTEXTUREENABLED)(HWND);
61typedef DWORD (__stdcall *PFNWXUGETTHEMEAPPPROPERTIES)();
62typedef void (__stdcall *PFNWXUSETTHEMEAPPPROPERTIES)(DWORD);
63typedef HRESULT (__stdcall *PFNWXUGETCURRENTTHEMENAME)(wchar_t *, int, wchar_t *, int, wchar_t *, int);
64typedef HRESULT (__stdcall *PFNWXUGETTHEMEDOCUMENTATIONPROPERTY)(const wchar_t *, const wchar_t *, wchar_t *, int);
65typedef HRESULT (__stdcall *PFNWXUDRAWTHEMEPARENTBACKGROUND)(HWND, HDC, RECT *);
66typedef HRESULT (__stdcall *PFNWXUENABLETHEMING)(BOOL);
2d9c0e97
VZ
67
68// ----------------------------------------------------------------------------
69// wxUxThemeEngine: provides all theme functions from uxtheme.dll
70// ----------------------------------------------------------------------------
71
72// we always define this class, even if wxUSE_UXTHEME == 0, but we just make it
73// empty in this case -- this allows to use it elsewhere without any #ifdefs
74#if wxUSE_UXTHEME
dedba2a1 75 #include "wx/dynlib.h"
2d9c0e97
VZ
76
77 #define wxUX_THEME_DECLARE(type, func) type func;
78#else
79 #define wxUX_THEME_DECLARE(type, func) type func(...) { return 0; }
80#endif
0d1cb8cb 81
53a2db12 82class WXDLLIMPEXP_CORE wxUxThemeEngine
0d1cb8cb 83{
0d1cb8cb 84public:
2d9c0e97
VZ
85 // get the theme engine or NULL if themes are not available
86 static wxUxThemeEngine *Get();
87
8a462d4e
VZ
88 // get the theme enging or NULL if themes are not available or not used for
89 // this application
90 static wxUxThemeEngine *GetIfActive();
91
2d9c0e97
VZ
92 // all uxtheme.dll functions
93 wxUX_THEME_DECLARE(PFNWXUOPENTHEMEDATA, OpenThemeData)
94 wxUX_THEME_DECLARE(PFNWXUCLOSETHEMEDATA, CloseThemeData)
95 wxUX_THEME_DECLARE(PFNWXUDRAWTHEMEBACKGROUND, DrawThemeBackground)
96 wxUX_THEME_DECLARE(PFNWXUDRAWTHEMETEXT, DrawThemeText)
97 wxUX_THEME_DECLARE(PFNWXUGETTHEMEBACKGROUNDCONTENTRECT, GetThemeBackgroundContentRect)
98 wxUX_THEME_DECLARE(PFNWXUGETTHEMEBACKGROUNDEXTENT, GetThemeBackgroundExtent)
99 wxUX_THEME_DECLARE(PFNWXUGETTHEMEPARTSIZE, GetThemePartSize)
100 wxUX_THEME_DECLARE(PFNWXUGETTHEMETEXTEXTENT, GetThemeTextExtent)
101 wxUX_THEME_DECLARE(PFNWXUGETTHEMETEXTMETRICS, GetThemeTextMetrics)
102 wxUX_THEME_DECLARE(PFNWXUGETTHEMEBACKGROUNDREGION, GetThemeBackgroundRegion)
103 wxUX_THEME_DECLARE(PFNWXUHITTESTTHEMEBACKGROUND, HitTestThemeBackground)
104 wxUX_THEME_DECLARE(PFNWXUDRAWTHEMEEDGE, DrawThemeEdge)
105 wxUX_THEME_DECLARE(PFNWXUDRAWTHEMEICON, DrawThemeIcon)
106 wxUX_THEME_DECLARE(PFNWXUISTHEMEPARTDEFINED, IsThemePartDefined)
107 wxUX_THEME_DECLARE(PFNWXUISTHEMEBACKGROUNDPARTIALLYTRANSPARENT, IsThemeBackgroundPartiallyTransparent)
108 wxUX_THEME_DECLARE(PFNWXUGETTHEMECOLOR, GetThemeColor)
109 wxUX_THEME_DECLARE(PFNWXUGETTHEMEMETRIC, GetThemeMetric)
110 wxUX_THEME_DECLARE(PFNWXUGETTHEMESTRING, GetThemeString)
111 wxUX_THEME_DECLARE(PFNWXUGETTHEMEBOOL, GetThemeBool)
112 wxUX_THEME_DECLARE(PFNWXUGETTHEMEINT, GetThemeInt)
113 wxUX_THEME_DECLARE(PFNWXUGETTHEMEENUMVALUE, GetThemeEnumValue)
114 wxUX_THEME_DECLARE(PFNWXUGETTHEMEPOSITION, GetThemePosition)
115 wxUX_THEME_DECLARE(PFNWXUGETTHEMEFONT, GetThemeFont)
116 wxUX_THEME_DECLARE(PFNWXUGETTHEMERECT, GetThemeRect)
117 wxUX_THEME_DECLARE(PFNWXUGETTHEMEMARGINS, GetThemeMargins)
118 wxUX_THEME_DECLARE(PFNWXUGETTHEMEINTLIST, GetThemeIntList)
119 wxUX_THEME_DECLARE(PFNWXUGETTHEMEPROPERTYORIGIN, GetThemePropertyOrigin)
120 wxUX_THEME_DECLARE(PFNWXUSETWINDOWTHEME, SetWindowTheme)
121 wxUX_THEME_DECLARE(PFNWXUGETTHEMEFILENAME, GetThemeFilename)
122 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSCOLOR, GetThemeSysColor)
123 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSCOLORBRUSH, GetThemeSysColorBrush)
124 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSBOOL, GetThemeSysBool)
125 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSSIZE, GetThemeSysSize)
126 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSFONT, GetThemeSysFont)
127 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSSTRING, GetThemeSysString)
128 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSINT, GetThemeSysInt)
129 wxUX_THEME_DECLARE(PFNWXUISTHEMEACTIVE, IsThemeActive)
130 wxUX_THEME_DECLARE(PFNWXUISAPPTHEMED, IsAppThemed)
131 wxUX_THEME_DECLARE(PFNWXUGETWINDOWTHEME, GetWindowTheme)
132 wxUX_THEME_DECLARE(PFNWXUENABLETHEMEDIALOGTEXTURE, EnableThemeDialogTexture)
133 wxUX_THEME_DECLARE(PFNWXUISTHEMEDIALOGTEXTUREENABLED, IsThemeDialogTextureEnabled)
134 wxUX_THEME_DECLARE(PFNWXUGETTHEMEAPPPROPERTIES, GetThemeAppProperties)
135 wxUX_THEME_DECLARE(PFNWXUSETTHEMEAPPPROPERTIES, SetThemeAppProperties)
136 wxUX_THEME_DECLARE(PFNWXUGETCURRENTTHEMENAME, GetCurrentThemeName)
137 wxUX_THEME_DECLARE(PFNWXUGETTHEMEDOCUMENTATIONPROPERTY, GetThemeDocumentationProperty)
138 wxUX_THEME_DECLARE(PFNWXUDRAWTHEMEPARENTBACKGROUND, DrawThemeParentBackground)
139 wxUX_THEME_DECLARE(PFNWXUENABLETHEMING, EnableTheming)
0d1cb8cb
JS
140
141private:
2d9c0e97
VZ
142 // construcor is private as only Get() can create us and is also trivial as
143 // everything really happens in Initialize()
144 wxUxThemeEngine() { }
0d1cb8cb 145
2d9c0e97
VZ
146 // destructor is private as only Get() and wxUxThemeModule delete us, it is
147 // not virtual as we're not supposed to be derived from
148 ~wxUxThemeEngine() { }
149
150#if wxUSE_UXTHEME
151 // initialize the theme engine: load the DLL, resolve the functions
152 //
153 // return true if we can be used, false if themes are not available
154 bool Initialize();
155
156
157 // uxtheme.dll
158 wxDynamicLibrary m_dllUxTheme;
159
27d2dbbc 160
2d9c0e97
VZ
161 // the one and only theme engine, initially NULL
162 static wxUxThemeEngine *ms_themeEngine;
163
164 // this is a bool which initially has the value -1 meaning "unknown"
165 static int ms_isThemeEngineAvailable;
166
167 // it must be able to delete us
168 friend class wxUxThemeModule;
169#endif // wxUSE_UXTHEME
170
b3062afd 171 DECLARE_NO_COPY_CLASS(wxUxThemeEngine)
0d1cb8cb
JS
172};
173
1a38c220
VZ
174#if wxUSE_UXTHEME
175
8a462d4e
VZ
176/* static */ inline wxUxThemeEngine *wxUxThemeEngine::GetIfActive()
177{
178 wxUxThemeEngine *engine = Get();
179 return engine && engine->IsAppThemed() && engine->IsThemeActive()
180 ? engine
181 : NULL;
182}
183
1a38c220 184#else // !wxUSE_UXTHEME
0d1cb8cb 185
2d9c0e97
VZ
186/* static */ inline wxUxThemeEngine *wxUxThemeEngine::Get()
187{
188 return NULL;
189}
0d1cb8cb 190
8a462d4e
VZ
191/* static */ inline wxUxThemeEngine *wxUxThemeEngine::GetIfActive()
192{
193 return NULL;
194}
195
1a38c220 196#endif // wxUSE_UXTHEME/!wxUSE_UXTHEME
0d1cb8cb 197
ca5ccd7e
VZ
198// ----------------------------------------------------------------------------
199// wxUxThemeHandle: encapsulates ::Open/CloseThemeData()
200// ----------------------------------------------------------------------------
201
202class wxUxThemeHandle
203{
204public:
317121ea 205 wxUxThemeHandle(const wxWindow *win, const wchar_t *classes)
ca5ccd7e
VZ
206 {
207 wxUxThemeEngine *engine = wxUxThemeEngine::Get();
208
317121ea
VZ
209 m_hTheme = engine ? (HTHEME)engine->OpenThemeData(GetHwndOf(win), classes)
210 : NULL;
ca5ccd7e
VZ
211 }
212
92199f4c 213 operator HTHEME() const { return m_hTheme; }
ca5ccd7e
VZ
214
215 ~wxUxThemeHandle()
216 {
217 if ( m_hTheme )
218 {
219 wxUxThemeEngine::Get()->CloseThemeData(m_hTheme);
220 }
221 }
222
223private:
92199f4c 224 HTHEME m_hTheme;
ca5ccd7e
VZ
225
226 DECLARE_NO_COPY_CLASS(wxUxThemeHandle)
227};
228
2d9c0e97 229#endif // _WX_UXTHEME_H_
0d1cb8cb 230