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 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
;
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) \
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, \
76 result = subclasses[N].subclassProc (wnd, msg, wParam, lParam, refData);\
77 TRACE ("result = %lx\n", result); \
84 static const WNDPROC subclassProcs
[NUM_SUBCLASSES
] = {
89 /***********************************************************************
92 * Register classes for standard controls that will shadow the system
95 void THEMING_Initialize (void)
99 if (!IsThemeActive()) return;
101 atSubclassProp
= GlobalAddAtomW (L
"CC32ThemingSubCl");
102 atRefDataProp
= GlobalAddAtomW (L
"CC32ThemingData");
104 for (i
= 0; i
< NUM_SUBCLASSES
; i
++)
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
));
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
));
125 if (!RegisterClassExW (&class))
127 ERR("Could not re-register class %s: %x\n",
128 debugstr_w (subclasses
[i
].className
), GetLastError ());
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)
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
);