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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(theming
);
33 typedef LRESULT (CALLBACK
* THEMING_SUBCLASSPROC
)(HWND
, UINT
, WPARAM
, LPARAM
,
36 static const struct ThemingSubclass
38 const WCHAR
* className
;
39 THEMING_SUBCLASSPROC subclassProc
;
41 /* Note: list must be sorted by class name */
44 #define NUM_SUBCLASSES (sizeof(subclasses)/sizeof(subclasses[0]))
46 static WNDPROC originalProcs
[NUM_SUBCLASSES
];
47 static ATOM atRefDataProp
;
48 static ATOM atSubclassProp
;
50 /***********************************************************************
51 * THEMING_SubclassProc
53 * The window proc registered to the subclasses. Fetches the subclass
54 * proc and ref data and call the proc.
56 static LRESULT CALLBACK
THEMING_SubclassProc (HWND wnd
, UINT msg
,
57 WPARAM wParam
, LPARAM lParam
)
59 int subclass
= (int)GetPropW (wnd
, MAKEINTATOMW (atSubclassProp
));
63 refData
= (ULONG_PTR
)GetPropW (wnd
, MAKEINTATOMW (atRefDataProp
));
65 TRACE ("%d; (%p, %x, %x, %lx, %lx)", subclass
, wnd
, msg
, wParam
, lParam
,
67 result
= subclasses
[subclass
].subclassProc (wnd
, msg
, wParam
, lParam
, refData
);
68 TRACE (" = %lx\n", result
);
72 /* Generate a number of subclass window procs.
73 * With a single proc alone, we can't really reliably find out the superclass,
74 * hence, the first time the subclass is called, these "stubs" are used which
75 * just save the internal ID of the subclass.
77 #define MAKE_SUBCLASS_STUB(N) \
78 static LRESULT CALLBACK subclass_stub ## N (HWND wnd, UINT msg, \
79 WPARAM wParam, LPARAM lParam) \
81 SetPropW (wnd, MAKEINTATOMW (atSubclassProp), (HANDLE)N); \
82 SetWindowLongPtrW (wnd, GWLP_WNDPROC, (LONG_PTR)THEMING_SubclassProc); \
83 return THEMING_SubclassProc (wnd, msg, wParam, lParam); \
86 const static WNDPROC subclassStubs
[NUM_SUBCLASSES
] = {
89 /***********************************************************************
92 * Register classes for standard controls that will shadow the system
95 void THEMING_Initialize (void)
98 static const WCHAR subclassPropName
[] =
99 { 'C','C','3','2','T','h','e','m','i','n','g','S','u','b','C','l',0 };
100 static const WCHAR refDataPropName
[] =
101 { 'C','C','3','2','T','h','e','m','i','n','g','D','a','t','a',0 };
103 atSubclassProp
= GlobalAddAtomW (subclassPropName
);
104 atRefDataProp
= GlobalAddAtomW (refDataPropName
);
106 for (i
= 0; i
< NUM_SUBCLASSES
; i
++)
110 class.cbSize
= sizeof(class);
111 class.style
|= CS_GLOBALCLASS
;
112 GetClassInfoExW (NULL
, subclasses
[i
].className
, &class);
113 originalProcs
[i
] = class.lpfnWndProc
;
114 class.lpfnWndProc
= subclassStubs
[i
];
116 if (!class.lpfnWndProc
)
118 ERR("Missing stub for class %s\n",
119 debugstr_w (subclasses
[i
].className
));
123 if (!RegisterClassExW (&class))
125 ERR("Could not re-register class %s: %lx\n",
126 debugstr_w (subclasses
[i
].className
), GetLastError ());
130 TRACE("Re-registered class %s\n",
131 debugstr_w (subclasses
[i
].className
));
136 /***********************************************************************
137 * THEMING_CallOriginalClass
139 * Determines the original window proc and calls it.
141 LRESULT
THEMING_CallOriginalClass (HWND wnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
143 int subclass
= (int)GetPropW (wnd
, MAKEINTATOMW (atSubclassProp
));
144 WNDPROC oldProc
= originalProcs
[subclass
];
145 return CallWindowProcW (oldProc
, wnd
, msg
, wParam
, lParam
);
148 /***********************************************************************
149 * THEMING_SetSubclassData
151 * Update the "refData" value of the subclassed window.
153 void THEMING_SetSubclassData (HWND wnd
, ULONG_PTR refData
)
155 SetPropW (wnd
, MAKEINTATOMW (atRefDataProp
), (HANDLE
)refData
);