include: Make sure __int64 is correctly defined on PPC64.
[wine.git] / dlls / comctl32 / theming.c
blobed7bb0a5b33a1ecab69b865f5f4e9ec65f15384b
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[] = L"#32770";
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 (ARRAY_SIZE(subclasses))
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;
99 if (!IsThemeActive()) return;
101 atSubclassProp = GlobalAddAtomW (L"CC32ThemingSubCl");
102 atRefDataProp = GlobalAddAtomW (L"CC32ThemingData");
104 for (i = 0; i < NUM_SUBCLASSES; i++)
106 WNDCLASSEXW class;
108 class.cbSize = sizeof(class);
109 if (!GetClassInfoExW (NULL, subclasses[i].className, &class))
111 ERR("Could not retrieve information for class %s\n",
112 debugstr_w (subclasses[i].className));
113 continue;
115 originalProcs[i] = class.lpfnWndProc;
116 class.lpfnWndProc = subclassProcs[i];
118 if (!class.lpfnWndProc)
120 ERR("Missing proc for class %s\n",
121 debugstr_w (subclasses[i].className));
122 continue;
125 if (!RegisterClassExW (&class))
127 ERR("Could not re-register class %s: %x\n",
128 debugstr_w (subclasses[i].className), GetLastError ());
130 else
132 TRACE("Re-registered class %s\n",
133 debugstr_w (subclasses[i].className));
138 /***********************************************************************
139 * THEMING_Uninitialize
141 * Unregister shadow classes for standard controls.
143 void THEMING_Uninitialize (void)
145 unsigned int i;
147 if (!atSubclassProp) return; /* not initialized */
149 for (i = 0; i < NUM_SUBCLASSES; i++)
151 UnregisterClassW (subclasses[i].className, NULL);
155 /***********************************************************************
156 * THEMING_CallOriginalClass
158 * Determines the original window proc and calls it.
160 LRESULT THEMING_CallOriginalClass (HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam)
162 INT_PTR subclass = (INT_PTR)GetPropW (wnd, (LPCWSTR)MAKEINTATOM(atSubclassProp));
163 WNDPROC oldProc = originalProcs[subclass];
164 return CallWindowProcW (oldProc, wnd, msg, wParam, lParam);