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
24 WINE_DEFAULT_DEBUG_CHANNEL(theming
);
26 typedef LRESULT (CALLBACK
* THEMING_SUBCLASSPROC
)(HWND
, UINT
, WPARAM
, LPARAM
,
29 #ifndef __REACTOS__ /* r73871 */
30 extern LRESULT CALLBACK
THEMING_ButtonSubclassProc (HWND
, UINT
, WPARAM
, LPARAM
,
31 ULONG_PTR
) DECLSPEC_HIDDEN
;
33 extern LRESULT CALLBACK
THEMING_ComboSubclassProc (HWND
, UINT
, WPARAM
, LPARAM
,
34 ULONG_PTR
) DECLSPEC_HIDDEN
;
35 #ifndef __REACTOS__ /* r73803 */
36 extern LRESULT CALLBACK
THEMING_DialogSubclassProc (HWND
, UINT
, WPARAM
, LPARAM
,
37 ULONG_PTR
) DECLSPEC_HIDDEN
;
39 extern LRESULT CALLBACK
THEMING_EditSubclassProc (HWND
, UINT
, WPARAM
, LPARAM
,
40 ULONG_PTR
) DECLSPEC_HIDDEN
;
41 extern LRESULT CALLBACK
THEMING_ListBoxSubclassProc (HWND
, UINT
, WPARAM
, LPARAM
,
42 ULONG_PTR
) DECLSPEC_HIDDEN
;
43 extern LRESULT CALLBACK
THEMING_ScrollbarSubclassProc (HWND
, UINT
, WPARAM
, LPARAM
,
44 ULONG_PTR
) DECLSPEC_HIDDEN
;
46 static const WCHAR dialogClass
[] = {'#','3','2','7','7','0',0};
47 static const WCHAR comboLboxClass
[] = {'C','o','m','b','o','L','b','o','x',0};
49 static const struct ThemingSubclass
51 const WCHAR
* className
;
52 THEMING_SUBCLASSPROC subclassProc
;
54 /* Note: list must be sorted by class name */
55 #ifndef __REACTOS__ /* r73803 & r73871 */
56 {dialogClass
, THEMING_DialogSubclassProc
},
57 {WC_BUTTONW
, THEMING_ButtonSubclassProc
},
59 {WC_COMBOBOXW
, THEMING_ComboSubclassProc
},
60 {comboLboxClass
, THEMING_ListBoxSubclassProc
},
61 {WC_EDITW
, THEMING_EditSubclassProc
},
62 {WC_LISTBOXW
, THEMING_ListBoxSubclassProc
},
63 {WC_SCROLLBARW
, THEMING_ScrollbarSubclassProc
}
66 #define NUM_SUBCLASSES (sizeof(subclasses)/sizeof(subclasses[0]))
68 static WNDPROC originalProcs
[NUM_SUBCLASSES
];
69 static ATOM atRefDataProp
;
70 static ATOM atSubclassProp
;
72 /* Generate a number of subclass window procs.
73 * With a single proc alone, we can't really reliably find out the superclass,
74 * so have one for each subclass. The subclass number is also stored in a prop
75 * since it's needed by THEMING_CallOriginalClass(). Then, the subclass
76 * proc and ref data are fetched and the proc called.
78 #define MAKE_SUBCLASS_PROC(N) \
79 static LRESULT CALLBACK subclass_proc ## N (HWND wnd, UINT msg, \
80 WPARAM wParam, LPARAM lParam) \
84 SetPropW (wnd, (LPCWSTR)MAKEINTATOM(atSubclassProp), (HANDLE)N); \
85 refData = (ULONG_PTR)GetPropW (wnd, (LPCWSTR)MAKEINTATOM(atRefDataProp)); \
86 TRACE ("%d; (%p, %x, %lx, %lx, %lx)\n", N, wnd, msg, wParam, lParam, \
88 result = subclasses[N].subclassProc (wnd, msg, wParam, lParam, refData);\
89 TRACE ("result = %lx\n", result); \
98 #ifndef __REACTOS__ /* r73803 & r73871 */
100 MAKE_SUBCLASS_PROC(6)
103 static const WNDPROC subclassProcs
[NUM_SUBCLASSES
] = {
108 #ifdef __REACTOS__ /* r73871 */
117 /***********************************************************************
120 * Register classes for standard controls that will shadow the system
123 #ifdef __REACTOS__ /* r73803 */
124 void THEMING_Initialize(HANDLE hActCtx5
, HANDLE hActCtx6
)
126 void THEMING_Initialize (void)
130 static const WCHAR subclassPropName
[] =
131 { 'C','C','3','2','T','h','e','m','i','n','g','S','u','b','C','l',0 };
132 static const WCHAR refDataPropName
[] =
133 { 'C','C','3','2','T','h','e','m','i','n','g','D','a','t','a',0 };
134 #ifdef __REACTOS__ /* r73803 */
136 BOOL ret
, bActivated
;
138 if (!IsThemeActive()) return;
141 atSubclassProp
= GlobalAddAtomW (subclassPropName
);
142 atRefDataProp
= GlobalAddAtomW (refDataPropName
);
144 for (i
= 0; i
< NUM_SUBCLASSES
; i
++)
148 class.cbSize
= sizeof(class);
150 #ifdef __REACTOS__ /* r73803 */
151 bActivated
= ActivateActCtx(hActCtx5
, &ulCookie
);
152 ret
= GetClassInfoExW (NULL
, subclasses
[i
].className
, &class);
154 DeactivateActCtx(0, ulCookie
);
158 if (!GetClassInfoExW (NULL
, subclasses
[i
].className
, &class))
161 ERR("Could not retrieve information for class %s\n",
162 debugstr_w (subclasses
[i
].className
));
165 originalProcs
[i
] = class.lpfnWndProc
;
166 class.lpfnWndProc
= subclassProcs
[i
];
167 #ifdef __REACTOS__ /* r73803 */
168 class.style
|= CS_GLOBALCLASS
;
169 class.hInstance
= COMCTL32_hModule
;
172 if (!class.lpfnWndProc
)
174 ERR("Missing proc for class %s\n",
175 debugstr_w (subclasses
[i
].className
));
179 #ifdef __REACTOS__ /* r73803 */
180 bActivated
= ActivateActCtx(hActCtx6
, &ulCookie
);
182 if (!RegisterClassExW (&class))
184 #ifdef __REACTOS__ /* r73803 */
185 WARN("Could not re-register class %s: %x\n",
187 ERR("Could not re-register class %s: %x\n",
189 debugstr_w (subclasses
[i
].className
), GetLastError ());
193 TRACE("Re-registered class %s\n",
194 debugstr_w (subclasses
[i
].className
));
197 #ifdef __REACTOS__ /* r73803 */
199 DeactivateActCtx(0, ulCookie
);
204 /***********************************************************************
205 * THEMING_Uninitialize
207 * Unregister shadow classes for standard controls.
209 void THEMING_Uninitialize (void)
213 if (!atSubclassProp
) return; /* not initialized */
215 for (i
= 0; i
< NUM_SUBCLASSES
; i
++)
217 UnregisterClassW (subclasses
[i
].className
, NULL
);
221 /***********************************************************************
222 * THEMING_CallOriginalClass
224 * Determines the original window proc and calls it.
226 LRESULT
THEMING_CallOriginalClass (HWND wnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
228 INT_PTR subclass
= (INT_PTR
)GetPropW (wnd
, (LPCWSTR
)MAKEINTATOM(atSubclassProp
));
229 WNDPROC oldProc
= originalProcs
[subclass
];
230 return CallWindowProcW (oldProc
, wnd
, msg
, wParam
, lParam
);
233 /***********************************************************************
234 * THEMING_SetSubclassData
236 * Update the "refData" value of the subclassed window.
238 void THEMING_SetSubclassData (HWND wnd
, ULONG_PTR refData
)
240 SetPropW (wnd
, (LPCWSTR
)MAKEINTATOM(atRefDataProp
), (HANDLE
)refData
);