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
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(theming
);
33 typedef LRESULT (CALLBACK
* THEMING_SUBCLASSPROC
)(HWND
, UINT
, WPARAM
, LPARAM
,
36 extern LRESULT CALLBACK
THEMING_DialogSubclassProc (HWND
, UINT
, WPARAM
, LPARAM
,
37 ULONG_PTR
) DECLSPEC_HIDDEN
;
38 extern LRESULT CALLBACK
THEMING_ScrollbarSubclassProc (HWND
, UINT
, WPARAM
, LPARAM
,
39 ULONG_PTR
) DECLSPEC_HIDDEN
;
41 static const WCHAR dialogClass
[] = L
"#32770";
43 static const struct ThemingSubclass
45 const WCHAR
* className
;
46 THEMING_SUBCLASSPROC subclassProc
;
48 /* Note: list must be sorted by class name */
49 {dialogClass
, THEMING_DialogSubclassProc
},
50 {WC_SCROLLBARW
, THEMING_ScrollbarSubclassProc
}
53 #define NUM_SUBCLASSES (ARRAY_SIZE(subclasses))
55 static WNDPROC originalProcs
[NUM_SUBCLASSES
];
56 static ATOM atRefDataProp
;
57 static ATOM atSubclassProp
;
59 /* Generate a number of subclass window procs.
60 * With a single proc alone, we can't really reliably find out the superclass,
61 * so have one for each subclass. The subclass number is also stored in a prop
62 * since it's needed by THEMING_CallOriginalClass(). Then, the subclass
63 * proc and ref data are fetched and the proc called.
65 #define MAKE_SUBCLASS_PROC(N) \
66 static LRESULT CALLBACK subclass_proc ## N (HWND wnd, UINT msg, \
67 WPARAM wParam, LPARAM lParam) \
71 SetPropW (wnd, (LPCWSTR)MAKEINTATOM(atSubclassProp), (HANDLE)N); \
72 refData = (ULONG_PTR)GetPropW (wnd, (LPCWSTR)MAKEINTATOM(atRefDataProp)); \
73 TRACE ("%d; (%p, %x, %lx, %lx, %lx)\n", N, wnd, msg, wParam, lParam, \
75 result = subclasses[N].subclassProc (wnd, msg, wParam, lParam, refData);\
76 TRACE ("result = %lx\n", result); \
83 static const WNDPROC subclassProcs
[NUM_SUBCLASSES
] = {
88 /***********************************************************************
91 * Register classes for standard controls that will shadow the system
94 void THEMING_Initialize (void)
98 atSubclassProp
= GlobalAddAtomW (L
"CC32ThemingSubCl");
99 atRefDataProp
= GlobalAddAtomW (L
"CC32ThemingData");
101 for (i
= 0; i
< NUM_SUBCLASSES
; i
++)
105 class.cbSize
= sizeof(class);
106 if (!GetClassInfoExW (NULL
, subclasses
[i
].className
, &class))
108 ERR("Could not retrieve information for class %s\n",
109 debugstr_w (subclasses
[i
].className
));
112 originalProcs
[i
] = class.lpfnWndProc
;
113 class.lpfnWndProc
= subclassProcs
[i
];
115 if (!class.lpfnWndProc
)
117 ERR("Missing proc for class %s\n",
118 debugstr_w (subclasses
[i
].className
));
122 if (!RegisterClassExW (&class))
124 ERR("Could not re-register class %s: %x\n",
125 debugstr_w (subclasses
[i
].className
), GetLastError ());
129 TRACE("Re-registered class %s\n",
130 debugstr_w (subclasses
[i
].className
));
135 /***********************************************************************
136 * THEMING_Uninitialize
138 * Unregister shadow classes for standard controls.
140 void THEMING_Uninitialize (void)
144 if (!atSubclassProp
) return; /* not initialized */
146 for (i
= 0; i
< NUM_SUBCLASSES
; i
++)
148 UnregisterClassW (subclasses
[i
].className
, NULL
);
152 /***********************************************************************
153 * THEMING_CallOriginalClass
155 * Determines the original window proc and calls it.
157 LRESULT
THEMING_CallOriginalClass (HWND wnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
159 INT_PTR subclass
= (INT_PTR
)GetPropW (wnd
, (LPCWSTR
)MAKEINTATOM(atSubclassProp
));
160 WNDPROC oldProc
= originalProcs
[subclass
];
161 return CallWindowProcW (oldProc
, wnd
, msg
, wParam
, lParam
);