Correct the test for the ODS_SELECTED bit in the WM_DRAWITEM message
[wine] / dlls / uxtheme / system.c
1 /*
2  * Win32 5.1 Theme system
3  *
4  * Copyright (C) 2003 Kevin Koltzau
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22
23 #include <stdarg.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "wingdi.h"
29 #include "uxtheme.h"
30
31 #include "uxthemedll.h"
32
33 #include "wine/debug.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(uxtheme);
36
37 /***********************************************************************
38  * Defines and global variables
39  */
40
41 DWORD dwThemeAppProperties = STAP_ALLOW_NONCLIENT | STAP_ALLOW_CONTROLS;
42 ATOM atWindowTheme;
43 ATOM atSubAppName;
44 ATOM atSubIdList;
45
46 /***********************************************************************/
47
48 /***********************************************************************
49  *      UXTHEME_InitSystem
50  */
51 void UXTHEME_InitSystem()
52 {
53     const WCHAR szWindowTheme[] = {
54         'u','x','_','t','h','e','m','e','\0'
55     };
56     const WCHAR szSubAppName[] = {
57         'u','x','_','s','u','b','a','p','p','\0'
58     };
59     const WCHAR szSubIdList[] = {
60         'u','x','_','s','u','b','i','d','l','s','t','\0'
61     };
62
63     atWindowTheme = GlobalAddAtomW(szWindowTheme);
64     atSubAppName  = GlobalAddAtomW(szSubAppName);
65     atSubIdList   = GlobalAddAtomW(szSubIdList);
66 }
67
68 /***********************************************************************
69  *      IsAppThemed                                         (UXTHEME.@)
70  */
71 BOOL WINAPI IsAppThemed(void)
72 {
73     FIXME("stub\n");
74     return FALSE;
75 }
76
77 /***********************************************************************
78  *      IsThemeActive                                       (UXTHEME.@)
79  */
80 BOOL WINAPI IsThemeActive(void)
81 {
82     FIXME("stub\n");
83     return FALSE;
84 }
85
86 /***********************************************************************
87  *      EnableTheming                                       (UXTHEME.@)
88  *
89  * NOTES
90  * This is a global and persistant change
91  */
92 HRESULT WINAPI EnableTheming(BOOL fEnable)
93 {
94     FIXME("%d: stub\n", fEnable);
95     return ERROR_CALL_NOT_IMPLEMENTED;
96  }
97
98 /***********************************************************************
99  *      OpenThemeData                                       (UXTHEME.@)
100  */
101 HTHEME WINAPI OpenThemeData(HWND hwnd, LPCWSTR pszClassList)
102 {
103     FIXME("%p %s: stub\n", hwnd, debugstr_w(pszClassList));
104     return NULL;
105 }
106
107 /***********************************************************************
108  *      GetWindowTheme                                      (UXTHEME.@)
109  *
110  * Retrieve the last theme opened for a window
111  */
112 HTHEME WINAPI GetWindowTheme(HWND hwnd)
113 {
114     TRACE("(%p)\n", hwnd);
115     return GetPropW(hwnd, MAKEINTATOMW(atWindowTheme));
116 }
117
118 /***********************************************************************
119  *      UXTHEME_SetWindowProperty
120  *
121  * I'm using atoms as there may be large numbers of duplicated strings
122  * and they do the work of keeping memory down as a cause of that quite nicely
123  */
124 HRESULT UXTHEME_SetWindowProperty(HWND hwnd, ATOM aProp, LPCWSTR pszValue)
125 {
126     ATOM oldValue = (ATOM)(size_t)RemovePropW(hwnd, MAKEINTATOMW(aProp));
127     if(oldValue)
128         DeleteAtom(oldValue);
129     if(pszValue) {
130         ATOM atValue = AddAtomW(pszValue);
131         if(!atValue
132            || !SetPropW(hwnd, MAKEINTATOMW(aProp), (LPWSTR)MAKEINTATOMW(atValue))) {
133             HRESULT hr = HRESULT_FROM_WIN32(GetLastError());
134             if(atValue) DeleteAtom(atValue);
135             return hr;
136         }
137     }
138     return S_OK;
139 }
140
141 /***********************************************************************
142  *      SetWindowTheme                                      (UXTHEME.@)
143  *
144  * Persistant through the life of the window, even after themes change
145  */
146 HRESULT WINAPI SetWindowTheme(HWND hwnd, LPCWSTR pszSubAppName,
147                               LPCWSTR pszSubIdList)
148 {
149     HRESULT hr;
150     TRACE("(%p,%s,%s)\n", hwnd, debugstr_w(pszSubAppName),
151           debugstr_w(pszSubIdList));
152     hr = UXTHEME_SetWindowProperty(hwnd, atSubAppName, pszSubAppName);
153     if(SUCCEEDED(hr))
154       hr = UXTHEME_SetWindowProperty(hwnd, atSubIdList, pszSubIdList);
155     return hr;
156 }
157
158 /***********************************************************************
159  *      GetCurrentThemeName                                 (UXTHEME.@)
160  */
161 HRESULT WINAPI GetCurrentThemeName(LPWSTR pszThemeFileName, int dwMaxNameChars,
162                                    LPWSTR pszColorBuff, int cchMaxColorChars,
163                                    LPWSTR pszSizeBuff, int cchMaxSizeChars)
164 {
165     FIXME("stub\n");
166     return ERROR_CALL_NOT_IMPLEMENTED;
167 }
168
169 /***********************************************************************
170  *      GetThemeAppProperties                               (UXTHEME.@)
171  */
172 DWORD WINAPI GetThemeAppProperties(void)
173 {
174     return dwThemeAppProperties;
175 }
176
177 /***********************************************************************
178  *      SetThemeAppProperties                               (UXTHEME.@)
179  */
180 void WINAPI SetThemeAppProperties(DWORD dwFlags)
181 {
182     TRACE("(0x%08lx)\n", dwFlags);
183     dwThemeAppProperties = dwFlags;
184 }
185
186 /***********************************************************************
187  *      CloseThemeData                                      (UXTHEME.@)
188  */
189 HRESULT WINAPI CloseThemeData(HTHEME hTheme)
190 {
191     FIXME("stub\n");
192     if(!hTheme)
193         return E_HANDLE;
194     return S_OK;
195 }
196
197 /***********************************************************************
198  *      HitTestThemeBackground                              (UXTHEME.@)
199  */
200 HRESULT WINAPI HitTestThemeBackground(HTHEME hTheme, HDC hdc, int iPartId,
201                                      int iStateId, DWORD dwOptions,
202                                      const RECT *pRect, HRGN hrgn,
203                                      POINT ptTest, WORD *pwHitTestCode)
204 {
205     FIXME("%d %d 0x%08lx: stub\n", iPartId, iStateId, dwOptions);
206     if(!hTheme)
207         return E_HANDLE;
208     return ERROR_CALL_NOT_IMPLEMENTED;
209 }
210
211 /***********************************************************************
212  *      IsThemePartDefined                                  (UXTHEME.@)
213  */
214 BOOL WINAPI IsThemePartDefined(HTHEME hTheme, int iPartId, int iStateId)
215 {
216     FIXME("%d %d: stub\n", iPartId, iStateId);
217     return FALSE;
218 }
219
220 /**********************************************************************
221  *      Undocumented functions
222  */
223
224 /**********************************************************************
225  *      QueryThemeServices                                 (UXTHEME.1)
226  *
227  * RETURNS
228  *     some kind of status flag
229  */
230 DWORD WINAPI QueryThemeServices()
231 {
232     FIXME("stub\n");
233     return 3; /* This is what is returned under XP in most cases */
234 }
235
236
237 /**********************************************************************
238  *      OpenThemeFile                                      (UXTHEME.2)
239  *
240  * Opens a theme file, which can be used to change the current theme, etc
241  *
242  * PARAMS
243  *     pszThemeFileName    Path to a msstyles theme file
244  *     pszColorName        Color defined in the theme, eg. NormalColor
245  *     pszSizeName         Size defined in the theme, eg. NormalSize
246  *     hThemeFile          Handle to theme file
247  */
248 HRESULT WINAPI OpenThemeFile(LPCWSTR pszThemeFileName, LPCWSTR pszColorName,
249                              LPCWSTR pszSizeName, HTHEMEFILE *hThemeFile,
250                              DWORD unknown)
251 {
252     FIXME("%s,%s,%s,%ld: stub\n", debugstr_w(pszThemeFileName),
253           debugstr_w(pszColorName),
254           debugstr_w(pszSizeName), unknown);
255     return ERROR_CALL_NOT_IMPLEMENTED;
256 }
257
258 /**********************************************************************
259  *      CloseThemeFile                                     (UXTHEME.3)
260  *
261  * Releases theme file handle returned by OpenThemeFile
262  *
263  * PARAMS
264  *     hThemeFile           Handle to theme file
265  */
266 HRESULT WINAPI CloseThemeFile(HTHEMEFILE hThemeFile)
267 {
268     FIXME("stub\n");
269     return S_OK;
270 }
271
272 /**********************************************************************
273  *      ApplyTheme                                         (UXTHEME.4)
274  *
275  * Set a theme file to be the currently active theme
276  *
277  * PARAMS
278  *     hThemeFile           Handle to theme file
279  *     unknown              See notes
280  *     hWnd                 Window requesting the theme change
281  *
282  * NOTES
283  * I'm not sure what the second parameter is (the datatype is likely wrong), other then this:
284  * Under XP if I pass
285  * char b[] = "";
286  *   the theme is applied with the screen redrawing really badly (flickers)
287  * char b[] = "\0"; where \0 can be one or more of any character, makes no difference
288  *   the theme is applied smoothly (screen does not flicker)
289  * char *b = "\0" or NULL; where \0 can be zero or more of any character, makes no difference
290  *   the function fails returning invalid parameter...very strange
291  */
292 HRESULT WINAPI ApplyTheme(HTHEMEFILE hThemeFile, char *unknown, HWND hWnd)
293 {
294     FIXME("%s: stub\n", unknown);
295     return ERROR_CALL_NOT_IMPLEMENTED;
296 }
297
298 /**********************************************************************
299  *      GetThemeDefaults                                   (UXTHEME.7)
300  *
301  * Get the default color & size for a theme
302  *
303  * PARAMS
304  *     pszThemeFileName    Path to a msstyles theme file
305  *     pszColorName        Buffer to recieve the default color name
306  *     dwColorNameLen      Length, in characters, of color name buffer
307  *     pszSizeName         Buffer to recieve the default size name
308  *     dwSizeNameLen       Length, in characters, of size name buffer
309  */
310 HRESULT WINAPI GetThemeDefaults(LPCWSTR pszThemeFileName, LPWSTR pszColorName,
311                                 DWORD dwColorNameLen, LPWSTR pszSizeName,
312                                 DWORD dwSizeNameLen)
313 {
314     FIXME("%s: stub\n", debugstr_w(pszThemeFileName));
315     return ERROR_CALL_NOT_IMPLEMENTED;
316 }
317
318 /**********************************************************************
319  *      EnumThemes                                         (UXTHEME.8)
320  *
321  * Enumerate available themes, calls specified EnumThemeProc for each
322  * theme found. Passes lpData through to callback function.
323  *
324  * PARAMS
325  *     pszThemePath        Path containing themes
326  *     callback            Called for each theme found in path
327  *     lpData              Passed through to callback
328  */
329 HRESULT WINAPI EnumThemes(LPCWSTR pszThemePath, EnumThemeProc callback,
330                           LPVOID lpData)
331 {
332     FIXME("%s: stub\n", debugstr_w(pszThemePath));
333     return ERROR_CALL_NOT_IMPLEMENTED;
334 }
335
336
337 /**********************************************************************
338  *      EnumThemeColors                                    (UXTHEME.9)
339  *
340  * Enumerate theme colors available with a particular size
341  *
342  * PARAMS
343  *     pszThemeFileName    Path to a msstyles theme file
344  *     pszSizeName         Theme size to enumerate available colors
345  *                         If NULL the default theme size is used
346  *     dwColorNum          Color index to retrieve, increment from 0
347  *     pszColorName        Output color name
348  *
349  * RETURNS
350  *     S_OK on success
351  *     E_PROP_ID_UNSUPPORTED when dwColorName does not refer to a color
352  *          or when pszSizeName does not refer to a valid size
353  *
354  * NOTES
355  * XP fails with E_POINTER when pszColorName points to a buffer smaller then 605
356  * characters
357  */
358 HRESULT WINAPI EnumThemeColors(LPWSTR pszThemeFileName, LPWSTR pszSizeName,
359                                DWORD dwColorNum, LPWSTR pszColorName)
360 {
361     FIXME("%s %s %ld: stub\n", debugstr_w(pszThemeFileName),
362           debugstr_w(pszSizeName), dwColorNum);
363     return ERROR_CALL_NOT_IMPLEMENTED;
364 }
365
366 /**********************************************************************
367  *      EnumThemeSizes                                     (UXTHEME.10)
368  *
369  * Enumerate theme colors available with a particular size
370  *
371  * PARAMS
372  *     pszThemeFileName    Path to a msstyles theme file
373  *     pszColorName        Theme color to enumerate available sizes
374  *                         If NULL the default theme color is used
375  *     dwSizeNum           Size index to retrieve, increment from 0
376  *     pszSizeName         Output size name
377  *
378  * RETURNS
379  *     S_OK on success
380  *     E_PROP_ID_UNSUPPORTED when dwSizeName does not refer to a size
381  *          or when pszColorName does not refer to a valid color
382  *
383  * NOTES
384  * XP fails with E_POINTER when pszSizeName points to a buffer smaller then 605
385  * characters
386  */
387 HRESULT WINAPI EnumThemeSizes(LPWSTR pszThemeFileName, LPWSTR pszColorName,
388                               DWORD dwSizeNum, LPWSTR pszSizeName)
389 {
390     FIXME("%s %s %ld: stub\n", debugstr_w(pszThemeFileName), debugstr_w(pszColorName), dwSizeNum);
391     return ERROR_CALL_NOT_IMPLEMENTED;
392 }
393
394 /**********************************************************************
395  *      ParseThemeIniFile                                  (UXTHEME.11)
396  *
397  * Enumerate data in a theme INI file.
398  *
399  * PARAMS
400  *     pszIniFileName      Path to a theme ini file
401  *     pszUnknown          Cannot be NULL, L"" is valid
402  *     callback            Called for each found entry
403  *     lpData              Passed through to callback
404  *
405  * RETURNS
406  *     S_OK on success
407  *     0x800706488 (Unknown property) when enumeration is canceled from callback
408  *
409  * NOTES
410  * When pszUnknown is NULL the callback is never called, the value does not seem to surve
411  * any other purpose
412  */
413 HRESULT WINAPI ParseThemeIniFile(LPCWSTR pszIniFileName, LPWSTR pszUnknown,
414                                  ParseThemeIniFileProc callback, LPVOID lpData)
415 {
416     FIXME("%s %s: stub\n", debugstr_w(pszIniFileName), debugstr_w(pszUnknown));
417     return ERROR_CALL_NOT_IMPLEMENTED;
418 }