ReactOS  0.4.13-dev-651-g5dbc677
theming.c
Go to the documentation of this file.
1 /*
2  * Theming - Initialization
3  *
4  * Copyright (c) 2005 by Frank Richter
5  *
6  * This library 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.1 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 St, Fifth Floor, Boston, MA 02110-1301, USA
19  *
20  */
21 
22 #include <stdarg.h>
23 
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "comctl32.h"
29 #include "uxtheme.h"
30 #include "wine/debug.h"
31 
33 
35  ULONG_PTR);
36 
37 #ifndef __REACTOS__ /* r73803 */
40 #endif
43 
44 #ifndef __REACTOS__
45 static const WCHAR dialogClass[] = {'#','3','2','7','7','0',0};
46 #endif
47 
48 static const struct ThemingSubclass
49 {
50  const WCHAR* className;
52 } subclasses[] = {
53  /* Note: list must be sorted by class name */
54 #ifndef __REACTOS__ /* r73803 & r73871 */
55  {dialogClass, THEMING_DialogSubclassProc},
56 #endif
58 };
59 
60 #define NUM_SUBCLASSES (ARRAY_SIZE(subclasses))
61 
65 
66 /* Generate a number of subclass window procs.
67  * With a single proc alone, we can't really reliably find out the superclass,
68  * so have one for each subclass. The subclass number is also stored in a prop
69  * since it's needed by THEMING_CallOriginalClass(). Then, the subclass
70  * proc and ref data are fetched and the proc called.
71  */
72 #define MAKE_SUBCLASS_PROC(N) \
73 static LRESULT CALLBACK subclass_proc ## N (HWND wnd, UINT msg, \
74  WPARAM wParam, LPARAM lParam) \
75 { \
76  LRESULT result; \
77  ULONG_PTR refData; \
78  SetPropW (wnd, (LPCWSTR)MAKEINTATOM(atSubclassProp), (HANDLE)N); \
79  refData = (ULONG_PTR)GetPropW (wnd, (LPCWSTR)MAKEINTATOM(atRefDataProp)); \
80  TRACE ("%d; (%p, %x, %lx, %lx, %lx)\n", N, wnd, msg, wParam, lParam, \
81  refData); \
82  result = subclasses[N].subclassProc (wnd, msg, wParam, lParam, refData);\
83  TRACE ("result = %lx\n", result); \
84  return result; \
85 }
86 
88 #ifndef __REACTOS__
90 #endif
91 
93  subclass_proc0,
94 #ifndef __REACTOS__
95  subclass_proc1,
96 #endif
97 };
98 
99 /***********************************************************************
100  * THEMING_Initialize
101  *
102  * Register classes for standard controls that will shadow the system
103  * classes.
104  */
105 #ifdef __REACTOS__ /* r73803 */
106 void THEMING_Initialize(HANDLE hActCtx5, HANDLE hActCtx6)
107 #else
109 #endif
110 {
111  unsigned int i;
112  static const WCHAR subclassPropName[] =
113  { 'C','C','3','2','T','h','e','m','i','n','g','S','u','b','C','l',0 };
114  static const WCHAR refDataPropName[] =
115  { 'C','C','3','2','T','h','e','m','i','n','g','D','a','t','a',0 };
116 #ifdef __REACTOS__ /* r73803 */
117  ULONG_PTR ulCookie;
118  BOOL ret, bActivated;
119 #else
120  if (!IsThemeActive()) return;
121 #endif
122 
123  atSubclassProp = GlobalAddAtomW (subclassPropName);
124  atRefDataProp = GlobalAddAtomW (refDataPropName);
125 
126  for (i = 0; i < NUM_SUBCLASSES; i++)
127  {
128  WNDCLASSEXW class;
129 
130  class.cbSize = sizeof(class);
131 
132 #ifdef __REACTOS__ /* r73803 */
133  bActivated = ActivateActCtx(hActCtx5, &ulCookie);
134  ret = GetClassInfoExW (NULL, subclasses[i].className, &class);
135  if (bActivated)
136  DeactivateActCtx(0, ulCookie);
137 
138  if (!ret)
139 #else
140  if (!GetClassInfoExW (NULL, subclasses[i].className, &class))
141 #endif
142  {
143  ERR("Could not retrieve information for class %s\n",
144  debugstr_w (subclasses[i].className));
145  continue;
146  }
147  originalProcs[i] = class.lpfnWndProc;
148  class.lpfnWndProc = subclassProcs[i];
149 #ifdef __REACTOS__ /* r73803 */
150  class.style |= CS_GLOBALCLASS;
151  class.hInstance = COMCTL32_hModule;
152 #endif
153 
154  if (!class.lpfnWndProc)
155  {
156  ERR("Missing proc for class %s\n",
157  debugstr_w (subclasses[i].className));
158  continue;
159  }
160 
161 #ifdef __REACTOS__ /* r73803 */
162  bActivated = ActivateActCtx(hActCtx6, &ulCookie);
163 #endif
164  if (!RegisterClassExW (&class))
165  {
166 #ifdef __REACTOS__ /* r73803 */
167  WARN("Could not re-register class %s: %x\n",
168 #else
169  ERR("Could not re-register class %s: %x\n",
170 #endif
171  debugstr_w (subclasses[i].className), GetLastError ());
172  }
173  else
174  {
175  TRACE("Re-registered class %s\n",
176  debugstr_w (subclasses[i].className));
177  }
178 
179 #ifdef __REACTOS__ /* r73803 */
180  if (bActivated)
181  DeactivateActCtx(0, ulCookie);
182 #endif
183  }
184 }
185 
186 /***********************************************************************
187  * THEMING_Uninitialize
188  *
189  * Unregister shadow classes for standard controls.
190  */
192 {
193  unsigned int i;
194 
195  if (!atSubclassProp) return; /* not initialized */
196 
197  for (i = 0; i < NUM_SUBCLASSES; i++)
198  {
199  UnregisterClassW (subclasses[i].className, NULL);
200  }
201 }
202 
203 /***********************************************************************
204  * THEMING_CallOriginalClass
205  *
206  * Determines the original window proc and calls it.
207  */
209 {
211  WNDPROC oldProc = originalProcs[subclass];
212  return CallWindowProcW (oldProc, wnd, msg, wParam, lParam);
213 }
214 
215 /***********************************************************************
216  * THEMING_SetSubclassData
217  *
218  * Update the "refData" value of the subclassed window.
219  */
221 {
222  SetPropW (wnd, (LPCWSTR)MAKEINTATOM(atRefDataProp), (HANDLE)refData);
223 }
BOOL WINAPI ActivateActCtx(IN HANDLE hActCtx, OUT PULONG_PTR ulCookie)
Definition: actctx.c:237
BOOL WINAPI GetClassInfoExW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _Out_ LPWNDCLASSEXW)
void THEMING_Initialize(void)
Definition: theming.c:108
BOOL WINAPI UnregisterClassW(_In_ LPCWSTR, HINSTANCE)
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
void THEMING_SetSubclassData(HWND wnd, ULONG_PTR refData)
Definition: theming.c:220
WORD ATOM
Definition: dimm.idl:113
LRESULT(CALLBACK * THEMING_SUBCLASSPROC)(HWND, UINT, WPARAM, LPARAM, ULONG_PTR)
Definition: theming.c:34
LRESULT CALLBACK THEMING_DialogSubclassProc(extern LRESULT CALLBACK THEMING_ScrollbarSubclassProc(HWND, extern LRESULT CALLBACK THEMING_ScrollbarSubclassProc(UINT, extern LRESULT CALLBACK THEMING_ScrollbarSubclassProc(WPARAM, extern LRESULT CALLBACK THEMING_ScrollbarSubclassProc(LPARAM, ULONG_PTR)
Definition: theming.c:38
void THEMING_Uninitialize(void)
Definition: theming.c:191
#define WARN(fmt,...)
Definition: debug.h:111
#define CALLBACK
Definition: compat.h:27
HANDLE HWND
Definition: compat.h:13
WINE_DEFAULT_DEBUG_CHANNEL(theming)
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
UINT_PTR WPARAM
Definition: windef.h:207
LRESULT CALLBACK THEMING_ScrollbarSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, ULONG_PTR dwRefData)
int32_t INT_PTR
Definition: typedefs.h:62
WPARAM wParam
Definition: combotst.c:138
uint32_t ULONG_PTR
Definition: typedefs.h:63
ATOM WINAPI RegisterClassExW(_In_ CONST WNDCLASSEXW *)
BOOL WINAPI DeactivateActCtx(IN DWORD dwFlags, IN ULONG_PTR ulCookie)
Definition: actctx.c:268
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
const WCHAR * className
Definition: theming.c:50
unsigned int BOOL
Definition: ntddk_ex.h:94
#define debugstr_w
Definition: kernel32.h:32
smooth NULL
Definition: ftsmooth.c:416
THEMING_SUBCLASSPROC subclassProc
Definition: theming.c:51
LONG_PTR LPARAM
Definition: windef.h:208
#define MAKE_SUBCLASS_PROC(N)
Definition: theming.c:72
static const struct ThemingSubclass subclasses[]
static ATOM atRefDataProp
Definition: theming.c:63
#define NUM_SUBCLASSES
Definition: theming.c:60
static const WNDPROC subclassProcs[NUM_SUBCLASSES]
Definition: theming.c:92
#define TRACE(s)
Definition: solgame.cpp:4
BOOL WINAPI SetPropW(_In_ HWND, _In_ LPCWSTR, _In_opt_ HANDLE)
__wchar_t WCHAR
Definition: xmlstorage.h:180
UINT cbSize
Definition: winuser.h:3190
static ATOM atSubclassProp
Definition: theming.c:64
#define CS_GLOBALCLASS
Definition: winuser.h:647
int ret
static WNDPROC originalProcs[NUM_SUBCLASSES]
Definition: theming.c:62
LRESULT THEMING_CallOriginalClass(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: theming.c:208
#define LRESULT
Definition: ole.h:14
LRESULT(CALLBACK * WNDPROC)(HWND, UINT, WPARAM, LPARAM)
Definition: winuser.h:2880
#define ERR(fmt,...)
Definition: debug.h:109
#define DECLSPEC_HIDDEN
Definition: precomp.h:8
HMODULE COMCTL32_hModule
Definition: commctrl.c:79
unsigned int UINT
Definition: ndis.h:50
HANDLE WINAPI GetPropW(_In_ HWND, _In_ LPCWSTR)
#define WC_SCROLLBARW
Definition: commctrl.h:4700
ATOM WINAPI GlobalAddAtomW(LPCWSTR lpString)
Definition: atom.c:444
#define msg(x)
Definition: auth_time.c:54
LRESULT WINAPI CallWindowProcW(_In_ WNDPROC, _In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
BOOL WINAPI IsThemeActive(void)
Definition: system.c:606
#define ULONG_PTR
Definition: config.h:101
LONG_PTR LRESULT
Definition: windef.h:209
LPARAM lParam
Definition: combotst.c:139
#define MAKEINTATOM(i)
Definition: winbase.h:1416