[CALC] Add theming support, requires Windows XP or later. CORE-13343
[reactos.git] / base / applications / calc / theme.c
1 /*
2 * ReactOS Calc (Theming support)
3 *
4 * Copyright 2007-2017, Carlo Bramini
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include "calc.h"
22
23 #define GET_CB(name) \
24 calc_##name = (type_##name)GetProcAddress(hUxTheme, #name); \
25 if (calc_##name == NULL) calc_##name = dummy_##name;
26
27 static HTHEME WINAPI
28 dummy_OpenThemeData(HWND hwnd, const WCHAR *pszClassList);
29
30 static HRESULT WINAPI
31 dummy_CloseThemeData(HTHEME hTheme);
32
33 static HRESULT WINAPI
34 dummy_DrawThemeBackground(HTHEME hTheme, HDC hdc, int iPartId, int iStateId,
35 const RECT *prc, const RECT *prcClip);
36
37 static BOOL WINAPI
38 dummy_IsAppThemed(void);
39
40 static BOOL WINAPI
41 dummy_IsThemeActive(void);
42
43 static BOOL WINAPI
44 dummy_IsThemeBackgroundPartiallyTransparent(HTHEME hTheme, int iPartId, int iStateId);
45
46 static HRESULT WINAPI
47 dummy_DrawThemeParentBackground(HWND hWnd, HDC hdc, RECT *prc);
48
49
50 type_OpenThemeData calc_OpenThemeData = dummy_OpenThemeData;
51 type_CloseThemeData calc_CloseThemeData = dummy_CloseThemeData;
52 type_DrawThemeBackground calc_DrawThemeBackground = dummy_DrawThemeBackground;
53 type_IsAppThemed calc_IsAppThemed = dummy_IsAppThemed;
54 type_IsThemeActive calc_IsThemeActive = dummy_IsThemeActive;
55 type_IsThemeBackgroundPartiallyTransparent calc_IsThemeBackgroundPartiallyTransparent = \
56 dummy_IsThemeBackgroundPartiallyTransparent;
57 type_DrawThemeParentBackground calc_DrawThemeParentBackground = \
58 dummy_DrawThemeParentBackground;
59
60 static HMODULE hUxTheme;
61
62 static HTHEME WINAPI
63 dummy_OpenThemeData(HWND hwnd, const WCHAR* pszClassList)
64 {
65 return NULL;
66 }
67
68 static HRESULT WINAPI
69 dummy_CloseThemeData(HTHEME hTheme)
70 {
71 return E_NOTIMPL;
72 }
73
74 static HRESULT WINAPI
75 dummy_DrawThemeBackground(HTHEME hTheme, HDC hdc, int iPartId, int iStateId,
76 const RECT* prc, const RECT* prcClip)
77 {
78 return E_NOTIMPL;
79 }
80
81 static BOOL WINAPI
82 dummy_IsAppThemed(void)
83 {
84 return FALSE;
85 }
86
87 static BOOL WINAPI
88 dummy_IsThemeActive(void)
89 {
90 return FALSE;
91 }
92
93 static BOOL WINAPI
94 dummy_IsThemeBackgroundPartiallyTransparent(HTHEME hTheme, int iPartId, int iStateId)
95 {
96 return FALSE;
97 }
98
99 static HRESULT WINAPI
100 dummy_DrawThemeParentBackground(HWND hWnd, HDC hdc, RECT *prc)
101 {
102 return E_NOTIMPL;
103 }
104
105 void Theme_Start(HINSTANCE hInstance)
106 {
107 hUxTheme = LoadLibrary(_T("UXTHEME"));
108 if (hUxTheme == NULL)
109 return;
110
111 GET_CB(OpenThemeData)
112 GET_CB(CloseThemeData)
113 GET_CB(DrawThemeBackground)
114 GET_CB(IsAppThemed)
115 GET_CB(IsThemeActive)
116 GET_CB(IsThemeBackgroundPartiallyTransparent)
117 GET_CB(DrawThemeParentBackground)
118 }
119
120 void Theme_Stop(void)
121 {
122 if(hUxTheme == NULL)
123 return;
124
125 FreeLibrary(hUxTheme);
126 hUxTheme = NULL;
127 }