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_ComboSubclassProc (HWND
, UINT
, WPARAM
, LPARAM
,
39 extern LRESULT CALLBACK
THEMING_DialogSubclassProc (HWND
, UINT
, WPARAM
, LPARAM
,
41 extern LRESULT CALLBACK
THEMING_EditSubclassProc (HWND
, UINT
, WPARAM
, LPARAM
,
43 extern LRESULT CALLBACK
THEMING_ListBoxSubclassProc (HWND
, UINT
, WPARAM
, LPARAM
,
46 static const WCHAR dialogClass
[] = {'#','3','2','7','7','0',0};
47 static const WCHAR comboLboxClass
[] = {'C','o','m','b','o','L','b','o','x',0};
49 static const struct ThemingSubclass
51 const WCHAR
* className
;
52 THEMING_SUBCLASSPROC subclassProc
;
54 /* Note: list must be sorted by class name */
55 {dialogClass
, THEMING_DialogSubclassProc
},
56 {WC_COMBOBOXW
, THEMING_ComboSubclassProc
},
57 {comboLboxClass
, THEMING_ListBoxSubclassProc
},
58 {WC_EDITW
, THEMING_EditSubclassProc
},
59 {WC_LISTBOXW
, THEMING_ListBoxSubclassProc
}
62 #define NUM_SUBCLASSES (sizeof(subclasses)/sizeof(subclasses[0]))
64 static WNDPROC originalProcs
[NUM_SUBCLASSES
];
65 static ATOM atRefDataProp
;
66 static ATOM atSubclassProp
;
68 /* Generate a number of subclass window procs.
69 * With a single proc alone, we can't really reliably find out the superclass,
70 * so have one for each subclass. The subclass number is also stored in a prop
71 * since it's needed by THEMING_CallOriginalClass(). Then, the the subclass
72 * proc and ref data are fetched and the proc called.
74 #define MAKE_SUBCLASS_PROC(N) \
75 static LRESULT CALLBACK subclass_proc ## N (HWND wnd, UINT msg, \
76 WPARAM wParam, LPARAM lParam) \
80 SetPropW (wnd, (LPCWSTR)MAKEINTATOM(atSubclassProp), (HANDLE)N); \
81 refData = (ULONG_PTR)GetPropW (wnd, (LPCWSTR)MAKEINTATOM(atRefDataProp)); \
82 TRACE ("%d; (%p, %x, %x, %lx, %lx)\n", N, wnd, msg, wParam, lParam, \
84 result = subclasses[N].subclassProc (wnd, msg, wParam, lParam, refData);\
85 TRACE ("result = %lx\n", result); \
95 static const WNDPROC subclassProcs
[NUM_SUBCLASSES
] = {
103 /***********************************************************************
106 * Register classes for standard controls that will shadow the system
109 void THEMING_Initialize (void)
112 static const WCHAR subclassPropName
[] =
113 { 'C','C','3','2','T','h','e','m','i','n','g','S','u','b','C','l',0 };
114 static const WCHAR refDataPropName
[] =
115 { 'C','C','3','2','T','h','e','m','i','n','g','D','a','t','a',0 };
117 /* CrossOver only HACK - Theming subclassing is disabled
118 * It confuses Delphi programs (such as the DVD Pro installer) and is
119 * generally bad because it removes the A/W duality of the builtin USER
120 * classes like edit controls and list boxes. These probably need to depend
121 * on a manifest resource being present in the executable or maybe need to
122 * use hooks into user32 instead.
125 if (1 || !IsThemeActive()) return;
127 atSubclassProp
= GlobalAddAtomW (subclassPropName
);
128 atRefDataProp
= GlobalAddAtomW (refDataPropName
);
130 for (i
= 0; i
< NUM_SUBCLASSES
; i
++)
134 class.cbSize
= sizeof(class);
135 class.style
|= CS_GLOBALCLASS
;
136 GetClassInfoExW (NULL
, subclasses
[i
].className
, &class);
137 originalProcs
[i
] = class.lpfnWndProc
;
138 class.lpfnWndProc
= subclassProcs
[i
];
140 if (!class.lpfnWndProc
)
142 ERR("Missing proc for class %s\n",
143 debugstr_w (subclasses
[i
].className
));
147 if (!RegisterClassExW (&class))
149 ERR("Could not re-register class %s: %x\n",
150 debugstr_w (subclasses
[i
].className
), GetLastError ());
154 TRACE("Re-registered class %s\n",
155 debugstr_w (subclasses
[i
].className
));
160 /***********************************************************************
161 * THEMING_Uninitialize
163 * Unregister shadow classes for standard controls.
165 void THEMING_Uninitialize (void)
169 if (!atSubclassProp
) return; /* not initialized */
171 for (i
= 0; i
< NUM_SUBCLASSES
; i
++)
173 UnregisterClassW (subclasses
[i
].className
, NULL
);
177 /***********************************************************************
178 * THEMING_CallOriginalClass
180 * Determines the original window proc and calls it.
182 LRESULT
THEMING_CallOriginalClass (HWND wnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
184 INT_PTR subclass
= (INT_PTR
)GetPropW (wnd
, (LPCWSTR
)MAKEINTATOM(atSubclassProp
));
185 WNDPROC oldProc
= originalProcs
[subclass
];
186 return CallWindowProcW (oldProc
, wnd
, msg
, wParam
, lParam
);
189 /***********************************************************************
190 * THEMING_SetSubclassData
192 * Update the "refData" value of the subclassed window.
194 void THEMING_SetSubclassData (HWND wnd
, ULONG_PTR refData
)
196 SetPropW (wnd
, (LPCWSTR
)MAKEINTATOM(atRefDataProp
), (HANDLE
)refData
);