1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
#include "stdafx.h"
#include "m_xpTheme.h"
//statical
struct XPTObject : public MZeroedObject
{
~XPTObject()
{
CloseThemeData(hThemeHandle);
}
HANDLE hThemeHandle;
HWND hOwnerWindow;
LPCWSTR lpcwClassObject;
};
static OBJLIST<XPTObject> xptObjectList(1);
static mir_cs xptCS;
static void _sttXptReloadThemeData(XPTObject * xptObject)
{
CloseThemeData(xptObject->hThemeHandle);
xptObject->hThemeHandle = OpenThemeData(xptObject->hOwnerWindow, xptObject->lpcwClassObject);
}
void XPThemesUnloadModule()
{
xptObjectList.destroy();
}
BOOL xpt_IsThemed(XPTHANDLE xptHandle)
{
if (!xptHandle) return FALSE;
mir_cslock lck(xptCS);
return xpt_IsValidHandle(xptHandle) && ((XPTObject*)xptHandle)->hThemeHandle;
}
BOOL xpt_IsValidHandle(XPTHANDLE xptHandle)
{
if (!xptHandle) return FALSE;
mir_cslock lck(xptCS);
return xptObjectList.indexOf((XPTObject*)xptHandle) != -1;
}
XPTHANDLE xpt_AddThemeHandle(HWND hwnd, LPCWSTR className)
{
mir_cslock lck(xptCS);
XPTObject* xptObject = new XPTObject;
xptObject->lpcwClassObject = className;
xptObject->hOwnerWindow = hwnd;
_sttXptReloadThemeData(xptObject);
xptObjectList.insert(xptObject);
return (XPTHANDLE)xptObject;
}
void xpt_FreeThemeForWindow(HWND hwnd)
{
mir_cslock lck(xptCS);
for (auto &xptObject : xptObjectList.rev_iter())
if (xptObject->hOwnerWindow == hwnd)
xptObjectList.removeItem(&xptObject);
}
void xpt_OnWM_THEMECHANGED()
{
mir_cslock lck(xptCS);
for (auto &it : xptObjectList)
_sttXptReloadThemeData(it);
}
HRESULT xpt_DrawThemeBackground(XPTHANDLE xptHandle, HDC hdc, int type, int state, const RECT *sizeRect, const RECT *clipRect)
{
mir_cslock lck(xptCS);
if (xpt_IsThemed(xptHandle))
return DrawThemeBackground(((XPTObject*)xptHandle)->hThemeHandle, hdc, type, state, sizeRect, clipRect);
return S_FALSE;
}
BOOL xpt_IsThemeBackgroundPartiallyTransparent(XPTHANDLE xptHandle, int type, int state)
{
mir_cslock lck(xptCS);
if (xpt_IsThemed(xptHandle))
return IsThemeBackgroundPartiallyTransparent(((XPTObject*)xptHandle)->hThemeHandle, type, state);
return FALSE;
}
HRESULT xpt_DrawTheme(XPTHANDLE xptHandle, HWND hwnd, HDC hdc, int type, int state, const RECT *sizeRect, const RECT *clipRect)
{
mir_cslock lck(xptCS);
if (xpt_IsThemed(xptHandle)) {
if (IsThemeBackgroundPartiallyTransparent(((XPTObject*)xptHandle)->hThemeHandle, type, state)) {
DrawThemeParentBackground(hwnd, hdc, sizeRect);
return DrawThemeBackground(((XPTObject*)xptHandle)->hThemeHandle, hdc, type, state, sizeRect, clipRect);
}
}
return S_FALSE;
}
HRESULT xpt_DrawThemeText(XPTHANDLE xptHandle, HDC hdc, int type, int state, LPCTSTR lpStr, int len, uint32_t flag1, uint32_t flag2, const RECT *textRect)
{
mir_cslock lck(xptCS);
if (xpt_IsThemed(xptHandle))
DrawThemeText(((XPTObject*)xptHandle)->hThemeHandle, hdc, type, state, (LPCWSTR)lpStr, len, flag1, flag2, textRect);
else
ske_DrawText(hdc, lpStr, len, (RECT*)textRect, flag1);
return S_OK;
}
BOOL xpt_EnableThemeDialogTexture(HWND hwnd, DWORD flags)
{
mir_cslock lck(xptCS);
return SUCCEEDED(EnableThemeDialogTexture(hwnd, flags));
}
|