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_ButtonSubclassProc (HWND
, UINT
, WPARAM
, LPARAM
,
39 extern LRESULT CALLBACK
THEMING_ComboSubclassProc (HWND
, UINT
, WPARAM
, LPARAM
,
41 extern LRESULT CALLBACK
THEMING_DialogSubclassProc (HWND
, UINT
, WPARAM
, LPARAM
,
43 extern LRESULT CALLBACK
THEMING_EditSubclassProc (HWND
, UINT
, WPARAM
, LPARAM
,
45 extern LRESULT CALLBACK
THEMING_ListBoxSubclassProc (HWND
, UINT
, WPARAM
, LPARAM
,
48 static const WCHAR dialogClass
[] = {'#','3','2','7','7','0',0};
49 static const WCHAR comboLboxClass
[] = {'C','o','m','b','o','L','b','o','x',0};
51 static const struct ThemingSubclass
53 const WCHAR
* className
;
54 THEMING_SUBCLASSPROC subclassProc
;
56 /* Note: list must be sorted by class name */
57 {dialogClass
, THEMING_DialogSubclassProc
},
58 {WC_BUTTONW
, THEMING_ButtonSubclassProc
},
59 {WC_COMBOBOXW
, THEMING_ComboSubclassProc
},
60 {comboLboxClass
, THEMING_ListBoxSubclassProc
},
61 {WC_EDITW
, THEMING_EditSubclassProc
},
62 {WC_LISTBOXW
, THEMING_ListBoxSubclassProc
}
65 #define NUM_SUBCLASSES (sizeof(subclasses)/sizeof(subclasses[0]))
67 static WNDPROC originalProcs
[NUM_SUBCLASSES
];
68 static ATOM atRefDataProp
;
69 static ATOM atSubclassProp
;
71 /* Generate a number of subclass window procs.
72 * With a single proc alone, we can't really reliably find out the superclass,
73 * so have one for each subclass. The subclass number is also stored in a prop
74 * since it's needed by THEMING_CallOriginalClass(). Then, the subclass
75 * proc and ref data are fetched and the proc called.
77 #define MAKE_SUBCLASS_PROC(N) \
78 static LRESULT CALLBACK subclass_proc ## N (HWND wnd, UINT msg, \
79 WPARAM wParam, LPARAM lParam) \
83 SetPropW (wnd, (LPCWSTR)MAKEINTATOM(atSubclassProp), (HANDLE)N); \
84 refData = (ULONG_PTR)GetPropW (wnd, (LPCWSTR)MAKEINTATOM(atRefDataProp)); \
85 TRACE ("%d; (%p, %x, %lx, %lx, %lx)\n", N, wnd, msg, wParam, lParam, \
87 result = subclasses[N].subclassProc (wnd, msg, wParam, lParam, refData);\
88 TRACE ("result = %lx\n", result); \
99 static const WNDPROC subclassProcs
[NUM_SUBCLASSES
] = {
108 /***********************************************************************
111 * Register classes for standard controls that will shadow the system
114 void THEMING_Initialize (void)
117 static const WCHAR subclassPropName
[] =
118 { 'C','C','3','2','T','h','e','m','i','n','g','S','u','b','C','l',0 };
119 static const WCHAR refDataPropName
[] =
120 { 'C','C','3','2','T','h','e','m','i','n','g','D','a','t','a',0 };
122 if (!IsThemeActive()) return;
124 atSubclassProp
= GlobalAddAtomW (subclassPropName
);
125 atRefDataProp
= GlobalAddAtomW (refDataPropName
);
127 for (i
= 0; i
< NUM_SUBCLASSES
; i
++)
131 class.cbSize
= sizeof(class);
132 class.style
|= CS_GLOBALCLASS
;
133 GetClassInfoExW (NULL
, subclasses
[i
].className
, &class);
134 originalProcs
[i
] = class.lpfnWndProc
;
135 class.lpfnWndProc
= subclassProcs
[i
];
137 if (!class.lpfnWndProc
)
139 ERR("Missing proc for class %s\n",
140 debugstr_w (subclasses
[i
].className
));
144 if (!RegisterClassExW (&class))
146 ERR("Could not re-register class %s: %x\n",
147 debugstr_w (subclasses
[i
].className
), GetLastError ());
151 TRACE("Re-registered class %s\n",
152 debugstr_w (subclasses
[i
].className
));
157 /***********************************************************************
158 * THEMING_Uninitialize
160 * Unregister shadow classes for standard controls.
162 void THEMING_Uninitialize (void)
166 if (!atSubclassProp
) return; /* not initialized */
168 for (i
= 0; i
< NUM_SUBCLASSES
; i
++)
170 UnregisterClassW (subclasses
[i
].className
, NULL
);
174 /***********************************************************************
175 * THEMING_CallOriginalClass
177 * Determines the original window proc and calls it.
179 LRESULT
THEMING_CallOriginalClass (HWND wnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
181 INT_PTR subclass
= (INT_PTR
)GetPropW (wnd
, (LPCWSTR
)MAKEINTATOM(atSubclassProp
));
182 WNDPROC oldProc
= originalProcs
[subclass
];
183 return CallWindowProcW (oldProc
, wnd
, msg
, wParam
, lParam
);
186 /***********************************************************************
187 * THEMING_SetSubclassData
189 * Update the "refData" value of the subclassed window.
191 void THEMING_SetSubclassData (HWND wnd
, ULONG_PTR refData
)
193 SetPropW (wnd
, (LPCWSTR
)MAKEINTATOM(atRefDataProp
), (HANDLE
)refData
);