d3d9/tests: Add a test for cube texture mipmap autogeneration.
[wine.git] / dlls / comctl32 / theming.c
blobe9305cc3b73320f121fd6f6949e8f57036a105ba
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_DialogSubclassProc (HWND, UINT, WPARAM, LPARAM,
38 ULONG_PTR) DECLSPEC_HIDDEN;
39 extern LRESULT CALLBACK THEMING_ScrollbarSubclassProc (HWND, UINT, WPARAM, LPARAM,
40 ULONG_PTR) DECLSPEC_HIDDEN;
42 static const WCHAR dialogClass[] = {'#','3','2','7','7','0',0};
44 static const struct ThemingSubclass
46 const WCHAR* className;
47 THEMING_SUBCLASSPROC subclassProc;
48 } subclasses[] = {
49 /* Note: list must be sorted by class name */
50 {dialogClass, THEMING_DialogSubclassProc},
51 {WC_SCROLLBARW, THEMING_ScrollbarSubclassProc}
54 #define NUM_SUBCLASSES (sizeof(subclasses)/sizeof(subclasses[0]))
56 static WNDPROC originalProcs[NUM_SUBCLASSES];
57 static ATOM atRefDataProp;
58 static ATOM atSubclassProp;
60 /* Generate a number of subclass window procs.
61 * With a single proc alone, we can't really reliably find out the superclass,
62 * so have one for each subclass. The subclass number is also stored in a prop
63 * since it's needed by THEMING_CallOriginalClass(). Then, the subclass
64 * proc and ref data are fetched and the proc called.
66 #define MAKE_SUBCLASS_PROC(N) \
67 static LRESULT CALLBACK subclass_proc ## N (HWND wnd, UINT msg, \
68 WPARAM wParam, LPARAM lParam) \
69 { \
70 LRESULT result; \
71 ULONG_PTR refData; \
72 SetPropW (wnd, (LPCWSTR)MAKEINTATOM(atSubclassProp), (HANDLE)N); \
73 refData = (ULONG_PTR)GetPropW (wnd, (LPCWSTR)MAKEINTATOM(atRefDataProp)); \
74 TRACE ("%d; (%p, %x, %lx, %lx, %lx)\n", N, wnd, msg, wParam, lParam, \
75 refData); \
76 result = subclasses[N].subclassProc (wnd, msg, wParam, lParam, refData);\
77 TRACE ("result = %lx\n", result); \
78 return result; \
81 MAKE_SUBCLASS_PROC(0)
82 MAKE_SUBCLASS_PROC(1)
84 static const WNDPROC subclassProcs[NUM_SUBCLASSES] = {
85 subclass_proc0,
86 subclass_proc1,
89 /***********************************************************************
90 * THEMING_Initialize
92 * Register classes for standard controls that will shadow the system
93 * classes.
95 void THEMING_Initialize (void)
97 unsigned int i;
98 static const WCHAR subclassPropName[] =
99 { 'C','C','3','2','T','h','e','m','i','n','g','S','u','b','C','l',0 };
100 static const WCHAR refDataPropName[] =
101 { 'C','C','3','2','T','h','e','m','i','n','g','D','a','t','a',0 };
103 if (!IsThemeActive()) return;
105 atSubclassProp = GlobalAddAtomW (subclassPropName);
106 atRefDataProp = GlobalAddAtomW (refDataPropName);
108 for (i = 0; i < NUM_SUBCLASSES; i++)
110 WNDCLASSEXW class;
112 class.cbSize = sizeof(class);
113 if (!GetClassInfoExW (NULL, subclasses[i].className, &class))
115 ERR("Could not retrieve information for class %s\n",
116 debugstr_w (subclasses[i].className));
117 continue;
119 originalProcs[i] = class.lpfnWndProc;
120 class.lpfnWndProc = subclassProcs[i];
122 if (!class.lpfnWndProc)
124 ERR("Missing proc for class %s\n",
125 debugstr_w (subclasses[i].className));
126 continue;
129 if (!RegisterClassExW (&class))
131 ERR("Could not re-register class %s: %x\n",
132 debugstr_w (subclasses[i].className), GetLastError ());
134 else
136 TRACE("Re-registered class %s\n",
137 debugstr_w (subclasses[i].className));
142 /***********************************************************************
143 * THEMING_Uninitialize
145 * Unregister shadow classes for standard controls.
147 void THEMING_Uninitialize (void)
149 unsigned int i;
151 if (!atSubclassProp) return; /* not initialized */
153 for (i = 0; i < NUM_SUBCLASSES; i++)
155 UnregisterClassW (subclasses[i].className, NULL);
159 /***********************************************************************
160 * THEMING_CallOriginalClass
162 * Determines the original window proc and calls it.
164 LRESULT THEMING_CallOriginalClass (HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam)
166 INT_PTR subclass = (INT_PTR)GetPropW (wnd, (LPCWSTR)MAKEINTATOM(atSubclassProp));
167 WNDPROC oldProc = originalProcs[subclass];
168 return CallWindowProcW (oldProc, wnd, msg, wParam, lParam);
171 /***********************************************************************
172 * THEMING_SetSubclassData
174 * Update the "refData" value of the subclassed window.
176 void THEMING_SetSubclassData (HWND wnd, ULONG_PTR refData)
178 SetPropW (wnd, (LPCWSTR)MAKEINTATOM(atRefDataProp), (HANDLE)refData);