2 * Theming - Initialization
4 * Copyright (c) 2005 by Frank Richter
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.
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.
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
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(theming
);
34 typedef LRESULT (CALLBACK
* THEMING_SUBCLASSPROC
)(HWND
, UINT
, WPARAM
, LPARAM
,
37 #ifndef __REACTOS__ /* r73803 */
38 extern LRESULT CALLBACK
THEMING_DialogSubclassProc (HWND
, UINT
, WPARAM
, LPARAM
,
39 ULONG_PTR
) DECLSPEC_HIDDEN
;
41 extern LRESULT CALLBACK
THEMING_ScrollbarSubclassProc (HWND
, UINT
, WPARAM
, LPARAM
,
42 ULONG_PTR
) DECLSPEC_HIDDEN
;
45 static const WCHAR dialogClass
[] = {'#','3','2','7','7','0',0};
48 static const struct ThemingSubclass
50 const WCHAR
* className
;
51 THEMING_SUBCLASSPROC subclassProc
;
53 /* Note: list must be sorted by class name */
54 #ifndef __REACTOS__ /* r73803 & r73871 */
55 {dialogClass
, THEMING_DialogSubclassProc
},
57 {WC_SCROLLBARW
, THEMING_ScrollbarSubclassProc
}
60 #define NUM_SUBCLASSES (ARRAY_SIZE(subclasses))
62 static WNDPROC originalProcs
[NUM_SUBCLASSES
];
63 static ATOM atRefDataProp
;
64 static ATOM atSubclassProp
;
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.
72 #define MAKE_SUBCLASS_PROC(N) \
73 static LRESULT CALLBACK subclass_proc ## N (HWND wnd, UINT msg, \
74 WPARAM wParam, LPARAM lParam) \
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, \
82 result = subclasses[N].subclassProc (wnd, msg, wParam, lParam, refData);\
83 TRACE ("result = %lx\n", result); \
92 static const WNDPROC subclassProcs
[NUM_SUBCLASSES
] = {
99 /***********************************************************************
102 * Register classes for standard controls that will shadow the system
105 #ifdef __REACTOS__ /* r73803 */
106 void THEMING_Initialize(HANDLE hActCtx5
, HANDLE hActCtx6
)
108 void THEMING_Initialize (void)
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 */
118 BOOL ret
, bActivated
;
120 if (!IsThemeActive()) return;
123 atSubclassProp
= GlobalAddAtomW (subclassPropName
);
124 atRefDataProp
= GlobalAddAtomW (refDataPropName
);
126 for (i
= 0; i
< NUM_SUBCLASSES
; i
++)
130 class.cbSize
= sizeof(class);
132 #ifdef __REACTOS__ /* r73803 */
133 bActivated
= ActivateActCtx(hActCtx5
, &ulCookie
);
134 ret
= GetClassInfoExW (NULL
, subclasses
[i
].className
, &class);
136 DeactivateActCtx(0, ulCookie
);
140 if (!GetClassInfoExW (NULL
, subclasses
[i
].className
, &class))
143 ERR("Could not retrieve information for class %s\n",
144 debugstr_w (subclasses
[i
].className
));
147 originalProcs
[i
] = class.lpfnWndProc
;
148 class.lpfnWndProc
= subclassProcs
[i
];
149 #ifdef __REACTOS__ /* r73803 */
150 class.style
|= CS_GLOBALCLASS
;
151 class.hInstance
= COMCTL32_hModule
;
154 if (!class.lpfnWndProc
)
156 ERR("Missing proc for class %s\n",
157 debugstr_w (subclasses
[i
].className
));
161 #ifdef __REACTOS__ /* r73803 */
162 bActivated
= ActivateActCtx(hActCtx6
, &ulCookie
);
164 if (!RegisterClassExW (&class))
166 #ifdef __REACTOS__ /* r73803 */
167 WARN("Could not re-register class %s: %x\n",
169 ERR("Could not re-register class %s: %x\n",
171 debugstr_w (subclasses
[i
].className
), GetLastError ());
175 TRACE("Re-registered class %s\n",
176 debugstr_w (subclasses
[i
].className
));
179 #ifdef __REACTOS__ /* r73803 */
181 DeactivateActCtx(0, ulCookie
);
186 /***********************************************************************
187 * THEMING_Uninitialize
189 * Unregister shadow classes for standard controls.
191 void THEMING_Uninitialize (void)
195 if (!atSubclassProp
) return; /* not initialized */
197 for (i
= 0; i
< NUM_SUBCLASSES
; i
++)
199 UnregisterClassW (subclasses
[i
].className
, NULL
);
203 /***********************************************************************
204 * THEMING_CallOriginalClass
206 * Determines the original window proc and calls it.
208 LRESULT
THEMING_CallOriginalClass (HWND wnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
210 INT_PTR subclass
= (INT_PTR
)GetPropW (wnd
, (LPCWSTR
)MAKEINTATOM(atSubclassProp
));
211 WNDPROC oldProc
= originalProcs
[subclass
];
212 return CallWindowProcW (oldProc
, wnd
, msg
, wParam
, lParam
);
215 /***********************************************************************
216 * THEMING_SetSubclassData
218 * Update the "refData" value of the subclassed window.
220 void THEMING_SetSubclassData (HWND wnd
, ULONG_PTR refData
)
222 SetPropW (wnd
, (LPCWSTR
)MAKEINTATOM(atRefDataProp
), (HANDLE
)refData
);