include: Use the hard-float calling convention for Windows APIs on ARM
[wine.git] / dlls / comctl32 / theming.c
blob93d6fe61f41e7be824abeae99cd0961df085be74
1 /*
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
22 #include <stdarg.h>
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"
32 WINE_DEFAULT_DEBUG_CHANNEL(theming);
34 typedef LRESULT (CALLBACK* THEMING_SUBCLASSPROC)(HWND, UINT, WPARAM, LPARAM,
35 ULONG_PTR);
37 extern LRESULT CALLBACK THEMING_ButtonSubclassProc (HWND, UINT, WPARAM, LPARAM,
38 ULONG_PTR) DECLSPEC_HIDDEN;
39 extern LRESULT CALLBACK THEMING_ComboSubclassProc (HWND, UINT, WPARAM, LPARAM,
40 ULONG_PTR) DECLSPEC_HIDDEN;
41 extern LRESULT CALLBACK THEMING_DialogSubclassProc (HWND, UINT, WPARAM, LPARAM,
42 ULONG_PTR) DECLSPEC_HIDDEN;
43 extern LRESULT CALLBACK THEMING_EditSubclassProc (HWND, UINT, WPARAM, LPARAM,
44 ULONG_PTR) DECLSPEC_HIDDEN;
45 extern LRESULT CALLBACK THEMING_ListBoxSubclassProc (HWND, UINT, WPARAM, LPARAM,
46 ULONG_PTR) DECLSPEC_HIDDEN;
47 extern LRESULT CALLBACK THEMING_ScrollbarSubclassProc (HWND, UINT, WPARAM, LPARAM,
48 ULONG_PTR) DECLSPEC_HIDDEN;
50 static const WCHAR dialogClass[] = {'#','3','2','7','7','0',0};
51 static const WCHAR comboLboxClass[] = {'C','o','m','b','o','L','b','o','x',0};
53 static const struct ThemingSubclass
55 const WCHAR* className;
56 THEMING_SUBCLASSPROC subclassProc;
57 } subclasses[] = {
58 /* Note: list must be sorted by class name */
59 {dialogClass, THEMING_DialogSubclassProc},
60 {WC_BUTTONW, THEMING_ButtonSubclassProc},
61 {WC_COMBOBOXW, THEMING_ComboSubclassProc},
62 {comboLboxClass, THEMING_ListBoxSubclassProc},
63 {WC_EDITW, THEMING_EditSubclassProc},
64 {WC_LISTBOXW, THEMING_ListBoxSubclassProc},
65 {WC_SCROLLBARW, THEMING_ScrollbarSubclassProc}
68 #define NUM_SUBCLASSES (sizeof(subclasses)/sizeof(subclasses[0]))
70 static WNDPROC originalProcs[NUM_SUBCLASSES];
71 static ATOM atRefDataProp;
72 static ATOM atSubclassProp;
74 /* Generate a number of subclass window procs.
75 * With a single proc alone, we can't really reliably find out the superclass,
76 * so have one for each subclass. The subclass number is also stored in a prop
77 * since it's needed by THEMING_CallOriginalClass(). Then, the subclass
78 * proc and ref data are fetched and the proc called.
80 #define MAKE_SUBCLASS_PROC(N) \
81 static LRESULT CALLBACK subclass_proc ## N (HWND wnd, UINT msg, \
82 WPARAM wParam, LPARAM lParam) \
83 { \
84 LRESULT result; \
85 ULONG_PTR refData; \
86 SetPropW (wnd, (LPCWSTR)MAKEINTATOM(atSubclassProp), (HANDLE)N); \
87 refData = (ULONG_PTR)GetPropW (wnd, (LPCWSTR)MAKEINTATOM(atRefDataProp)); \
88 TRACE ("%d; (%p, %x, %lx, %lx, %lx)\n", N, wnd, msg, wParam, lParam, \
89 refData); \
90 result = subclasses[N].subclassProc (wnd, msg, wParam, lParam, refData);\
91 TRACE ("result = %lx\n", result); \
92 return result; \
95 MAKE_SUBCLASS_PROC(0)
96 MAKE_SUBCLASS_PROC(1)
97 MAKE_SUBCLASS_PROC(2)
98 MAKE_SUBCLASS_PROC(3)
99 MAKE_SUBCLASS_PROC(4)
100 MAKE_SUBCLASS_PROC(5)
101 MAKE_SUBCLASS_PROC(6)
103 static const WNDPROC subclassProcs[NUM_SUBCLASSES] = {
104 subclass_proc0,
105 subclass_proc1,
106 subclass_proc2,
107 subclass_proc3,
108 subclass_proc4,
109 subclass_proc5,
110 subclass_proc6
113 /***********************************************************************
114 * THEMING_Initialize
116 * Register classes for standard controls that will shadow the system
117 * classes.
119 void THEMING_Initialize (void)
121 unsigned int i;
122 static const WCHAR subclassPropName[] =
123 { 'C','C','3','2','T','h','e','m','i','n','g','S','u','b','C','l',0 };
124 static const WCHAR refDataPropName[] =
125 { 'C','C','3','2','T','h','e','m','i','n','g','D','a','t','a',0 };
127 if (!IsThemeActive()) return;
129 atSubclassProp = GlobalAddAtomW (subclassPropName);
130 atRefDataProp = GlobalAddAtomW (refDataPropName);
132 for (i = 0; i < NUM_SUBCLASSES; i++)
134 WNDCLASSEXW class;
136 class.cbSize = sizeof(class);
137 if (!GetClassInfoExW (NULL, subclasses[i].className, &class))
139 ERR("Could not retrieve information for class %s\n",
140 debugstr_w (subclasses[i].className));
141 continue;
143 originalProcs[i] = class.lpfnWndProc;
144 class.lpfnWndProc = subclassProcs[i];
146 if (!class.lpfnWndProc)
148 ERR("Missing proc for class %s\n",
149 debugstr_w (subclasses[i].className));
150 continue;
153 if (!RegisterClassExW (&class))
155 ERR("Could not re-register class %s: %x\n",
156 debugstr_w (subclasses[i].className), GetLastError ());
158 else
160 TRACE("Re-registered class %s\n",
161 debugstr_w (subclasses[i].className));
166 /***********************************************************************
167 * THEMING_Uninitialize
169 * Unregister shadow classes for standard controls.
171 void THEMING_Uninitialize (void)
173 unsigned int i;
175 if (!atSubclassProp) return; /* not initialized */
177 for (i = 0; i < NUM_SUBCLASSES; i++)
179 UnregisterClassW (subclasses[i].className, NULL);
183 /***********************************************************************
184 * THEMING_CallOriginalClass
186 * Determines the original window proc and calls it.
188 LRESULT THEMING_CallOriginalClass (HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam)
190 INT_PTR subclass = (INT_PTR)GetPropW (wnd, (LPCWSTR)MAKEINTATOM(atSubclassProp));
191 WNDPROC oldProc = originalProcs[subclass];
192 return CallWindowProcW (oldProc, wnd, msg, wParam, lParam);
195 /***********************************************************************
196 * THEMING_SetSubclassData
198 * Update the "refData" value of the subclassed window.
200 void THEMING_SetSubclassData (HWND wnd, ULONG_PTR refData)
202 SetPropW (wnd, (LPCWSTR)MAKEINTATOM(atRefDataProp), (HANDLE)refData);