winealsa: Use dedicated macros to call interface functions.
[wine.git] / programs / winecfg / theme.c
blob84337b4fcb13774b984b10877cf36542a4b46a39
1 /*
2 * Desktop Integration
3 * - Theme configuration code
4 * - User Shell Folder mapping
6 * Copyright (c) 2005 by Frank Richter
7 * Copyright (c) 2006 by Michael Jung
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include <assert.h>
26 #include <stdarg.h>
27 #include <stdlib.h>
28 #include <stdio.h>
30 #define COBJMACROS
32 #include <windows.h>
33 #include <commdlg.h>
34 #include <shellapi.h>
35 #include <uxtheme.h>
36 #include <tmschema.h>
37 #include <shlobj.h>
38 #include <shlwapi.h>
39 #include <wine/debug.h>
41 #include "resource.h"
42 #include "winecfg.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
46 /* UXTHEME functions not in the headers */
48 typedef struct tagTHEMENAMES
50 WCHAR szName[MAX_PATH+1];
51 WCHAR szDisplayName[MAX_PATH+1];
52 WCHAR szTooltip[MAX_PATH+1];
53 } THEMENAMES, *PTHEMENAMES;
55 typedef void* HTHEMEFILE;
56 typedef BOOL (CALLBACK *EnumThemeProc)(LPVOID lpReserved,
57 LPCWSTR pszThemeFileName,
58 LPCWSTR pszThemeName,
59 LPCWSTR pszToolTip, LPVOID lpReserved2,
60 LPVOID lpData);
62 HRESULT WINAPI EnumThemeColors (LPCWSTR pszThemeFileName, LPWSTR pszSizeName,
63 DWORD dwColorNum, PTHEMENAMES pszColorNames);
64 HRESULT WINAPI EnumThemeSizes (LPCWSTR pszThemeFileName, LPWSTR pszColorName,
65 DWORD dwSizeNum, PTHEMENAMES pszSizeNames);
66 HRESULT WINAPI ApplyTheme (HTHEMEFILE hThemeFile, char* unknown, HWND hWnd);
67 HRESULT WINAPI OpenThemeFile (LPCWSTR pszThemeFileName, LPCWSTR pszColorName,
68 LPCWSTR pszSizeName, HTHEMEFILE* hThemeFile,
69 DWORD unknown);
70 HRESULT WINAPI CloseThemeFile (HTHEMEFILE hThemeFile);
71 HRESULT WINAPI EnumThemes (LPCWSTR pszThemePath, EnumThemeProc callback,
72 LPVOID lpData);
74 static void refresh_sysparams(HWND hDlg);
75 static void on_sysparam_change(HWND hDlg);
77 /* A struct to keep both the internal and "fancy" name of a color or size */
78 typedef struct
80 WCHAR* name;
81 WCHAR* fancyName;
82 } ThemeColorOrSize;
84 /* wrapper around DSA that also keeps an item count */
85 typedef struct
87 HDSA dsa;
88 int count;
89 } WrappedDsa;
91 /* Some helper functions to deal with ThemeColorOrSize structs in WrappedDSAs */
93 static void color_or_size_dsa_add (WrappedDsa* wdsa, const WCHAR* name,
94 const WCHAR* fancyName)
96 ThemeColorOrSize item;
98 item.name = malloc ((wcslen (name) + 1) * sizeof(WCHAR));
99 lstrcpyW (item.name, name);
101 item.fancyName = malloc ((wcslen (fancyName) + 1) * sizeof(WCHAR));
102 lstrcpyW (item.fancyName, fancyName);
104 DSA_InsertItem (wdsa->dsa, wdsa->count, &item);
105 wdsa->count++;
108 static int CALLBACK dsa_destroy_callback (LPVOID p, LPVOID pData)
110 ThemeColorOrSize* item = p;
111 free (item->name);
112 free (item->fancyName);
113 return 1;
116 static void free_color_or_size_dsa (WrappedDsa* wdsa)
118 DSA_DestroyCallback (wdsa->dsa, dsa_destroy_callback, NULL);
121 static void create_color_or_size_dsa (WrappedDsa* wdsa)
123 wdsa->dsa = DSA_Create (sizeof (ThemeColorOrSize), 1);
124 wdsa->count = 0;
127 static ThemeColorOrSize* color_or_size_dsa_get (WrappedDsa* wdsa, int index)
129 return DSA_GetItemPtr (wdsa->dsa, index);
132 static int color_or_size_dsa_find (WrappedDsa* wdsa, const WCHAR* name)
134 int i = 0;
135 for (; i < wdsa->count; i++)
137 ThemeColorOrSize* item = color_or_size_dsa_get (wdsa, i);
138 if (lstrcmpiW (item->name, name) == 0) break;
140 return i;
143 /* A theme file, contains file name, display name, color and size scheme names */
144 typedef struct
146 WCHAR* themeFileName;
147 WCHAR* fancyName;
148 WrappedDsa colors;
149 WrappedDsa sizes;
150 } ThemeFile;
152 static HDSA themeFiles = NULL;
153 static int themeFilesCount = 0;
155 static int CALLBACK theme_dsa_destroy_callback (LPVOID p, LPVOID pData)
157 ThemeFile* item = p;
158 free (item->themeFileName);
159 free (item->fancyName);
160 free_color_or_size_dsa (&item->colors);
161 free_color_or_size_dsa (&item->sizes);
162 return 1;
165 /* Free memory occupied by the theme list */
166 static void free_theme_files(void)
168 if (themeFiles == NULL) return;
170 DSA_DestroyCallback (themeFiles , theme_dsa_destroy_callback, NULL);
171 themeFiles = NULL;
172 themeFilesCount = 0;
175 typedef HRESULT (WINAPI * EnumTheme) (LPCWSTR, LPWSTR, DWORD, PTHEMENAMES);
177 /* fill a string list with either colors or sizes of a theme */
178 static void fill_theme_string_array (const WCHAR* filename,
179 WrappedDsa* wdsa,
180 EnumTheme enumTheme)
182 DWORD index = 0;
183 THEMENAMES names;
185 WINE_TRACE ("%s %p %p\n", wine_dbgstr_w (filename), wdsa, enumTheme);
187 while (SUCCEEDED (enumTheme (filename, NULL, index++, &names)))
189 WINE_TRACE ("%s: %s\n", wine_dbgstr_w (names.szName),
190 wine_dbgstr_w (names.szDisplayName));
191 color_or_size_dsa_add (wdsa, names.szName, names.szDisplayName);
195 /* Theme enumeration callback, adds theme to theme list */
196 static BOOL CALLBACK myEnumThemeProc (LPVOID lpReserved,
197 LPCWSTR pszThemeFileName,
198 LPCWSTR pszThemeName,
199 LPCWSTR pszToolTip,
200 LPVOID lpReserved2, LPVOID lpData)
202 ThemeFile newEntry;
204 /* fill size/color lists */
205 create_color_or_size_dsa (&newEntry.colors);
206 fill_theme_string_array (pszThemeFileName, &newEntry.colors, EnumThemeColors);
207 create_color_or_size_dsa (&newEntry.sizes);
208 fill_theme_string_array (pszThemeFileName, &newEntry.sizes, EnumThemeSizes);
210 newEntry.themeFileName = malloc ((wcslen (pszThemeFileName) + 1) * sizeof(WCHAR));
211 lstrcpyW (newEntry.themeFileName, pszThemeFileName);
213 newEntry.fancyName = malloc ((wcslen (pszThemeName) + 1) * sizeof(WCHAR));
214 lstrcpyW (newEntry.fancyName, pszThemeName);
216 /*list_add_tail (&themeFiles, &newEntry->entry);*/
217 DSA_InsertItem (themeFiles, themeFilesCount, &newEntry);
218 themeFilesCount++;
220 return TRUE;
223 /* Scan for themes */
224 static void scan_theme_files(void)
226 WCHAR themesPath[MAX_PATH];
228 free_theme_files();
230 if (FAILED (SHGetFolderPathW (NULL, CSIDL_RESOURCES, NULL,
231 SHGFP_TYPE_CURRENT, themesPath))) return;
233 themeFiles = DSA_Create (sizeof (ThemeFile), 1);
234 lstrcatW (themesPath, L"\\Themes");
236 EnumThemes (themesPath, myEnumThemeProc, 0);
239 /* fill the color & size combo boxes for a given theme */
240 static void fill_color_size_combos (ThemeFile* theme, HWND comboColor,
241 HWND comboSize)
243 int i;
245 SendMessageW (comboColor, CB_RESETCONTENT, 0, 0);
246 for (i = 0; i < theme->colors.count; i++)
248 ThemeColorOrSize* item = color_or_size_dsa_get (&theme->colors, i);
249 SendMessageW (comboColor, CB_ADDSTRING, 0, (LPARAM)item->fancyName);
252 SendMessageW (comboSize, CB_RESETCONTENT, 0, 0);
253 for (i = 0; i < theme->sizes.count; i++)
255 ThemeColorOrSize* item = color_or_size_dsa_get (&theme->sizes, i);
256 SendMessageW (comboSize, CB_ADDSTRING, 0, (LPARAM)item->fancyName);
260 /* Select the item of a combo box that matches a theme's color and size
261 * scheme. */
262 static void select_color_and_size (ThemeFile* theme,
263 const WCHAR* colorName, HWND comboColor,
264 const WCHAR* sizeName, HWND comboSize)
266 SendMessageW (comboColor, CB_SETCURSEL,
267 color_or_size_dsa_find (&theme->colors, colorName), 0);
268 SendMessageW (comboSize, CB_SETCURSEL,
269 color_or_size_dsa_find (&theme->sizes, sizeName), 0);
272 /* Fill theme, color and sizes combo boxes with the know themes and select
273 * the entries matching the currently active theme. */
274 static BOOL fill_theme_list (HWND comboTheme, HWND comboColor, HWND comboSize)
276 WCHAR textNoTheme[256];
277 int themeIndex = 0;
278 BOOL ret = TRUE;
279 int i;
280 WCHAR currentTheme[MAX_PATH];
281 WCHAR currentColor[MAX_PATH];
282 WCHAR currentSize[MAX_PATH];
283 ThemeFile* theme = NULL;
285 LoadStringW(GetModuleHandleW(NULL), IDS_NOTHEME, textNoTheme, ARRAY_SIZE(textNoTheme));
287 SendMessageW (comboTheme, CB_RESETCONTENT, 0, 0);
288 SendMessageW (comboTheme, CB_ADDSTRING, 0, (LPARAM)textNoTheme);
290 for (i = 0; i < themeFilesCount; i++)
292 ThemeFile* item = DSA_GetItemPtr (themeFiles, i);
293 SendMessageW (comboTheme, CB_ADDSTRING, 0,
294 (LPARAM)item->fancyName);
297 if (IsThemeActive() && SUCCEEDED(GetCurrentThemeName(currentTheme, ARRAY_SIZE(currentTheme),
298 currentColor, ARRAY_SIZE(currentColor), currentSize, ARRAY_SIZE(currentSize))))
300 /* Determine the index of the currently active theme. */
301 BOOL found = FALSE;
302 for (i = 0; i < themeFilesCount; i++)
304 theme = DSA_GetItemPtr (themeFiles, i);
305 if (lstrcmpiW (theme->themeFileName, currentTheme) == 0)
307 found = TRUE;
308 themeIndex = i+1;
309 break;
312 if (!found)
314 /* Current theme not found?... add to the list, then... */
315 WINE_TRACE("Theme %s not in list of enumerated themes\n",
316 wine_dbgstr_w (currentTheme));
317 myEnumThemeProc (NULL, currentTheme, currentTheme,
318 currentTheme, NULL, NULL);
319 themeIndex = themeFilesCount;
320 theme = DSA_GetItemPtr (themeFiles, themeFilesCount-1);
322 fill_color_size_combos (theme, comboColor, comboSize);
323 select_color_and_size (theme, currentColor, comboColor,
324 currentSize, comboSize);
326 else
328 /* No theme selected */
329 ret = FALSE;
332 SendMessageW (comboTheme, CB_SETCURSEL, themeIndex, 0);
333 return ret;
336 /* Update the color & size combo boxes when the selection of the theme
337 * combo changed. Selects the current color and size scheme if the theme
338 * is currently active, otherwise the first color and size. */
339 static BOOL update_color_and_size (int themeIndex, HWND comboColor,
340 HWND comboSize)
342 if (themeIndex == 0)
344 return FALSE;
346 else
348 WCHAR currentTheme[MAX_PATH];
349 WCHAR currentColor[MAX_PATH];
350 WCHAR currentSize[MAX_PATH];
351 ThemeFile* theme = DSA_GetItemPtr (themeFiles, themeIndex - 1);
353 fill_color_size_combos (theme, comboColor, comboSize);
355 if ((SUCCEEDED(GetCurrentThemeName (currentTheme, ARRAY_SIZE(currentTheme),
356 currentColor, ARRAY_SIZE(currentColor), currentSize, ARRAY_SIZE(currentSize))))
357 && (lstrcmpiW (currentTheme, theme->themeFileName) == 0))
359 select_color_and_size (theme, currentColor, comboColor,
360 currentSize, comboSize);
362 else
364 SendMessageW (comboColor, CB_SETCURSEL, 0, 0);
365 SendMessageW (comboSize, CB_SETCURSEL, 0, 0);
368 return TRUE;
371 /* Apply a theme from a given theme, color and size combo box item index. */
372 static void do_apply_theme (HWND dialog, int themeIndex, int colorIndex, int sizeIndex)
374 static char b[] = "\0";
376 if (themeIndex == 0)
378 /* no theme */
379 ApplyTheme (NULL, b, NULL);
381 else
383 ThemeFile* theme = DSA_GetItemPtr (themeFiles, themeIndex-1);
384 const WCHAR* themeFileName = theme->themeFileName;
385 const WCHAR* colorName = NULL;
386 const WCHAR* sizeName = NULL;
387 HTHEMEFILE hTheme;
388 ThemeColorOrSize* item;
390 item = color_or_size_dsa_get (&theme->colors, colorIndex);
391 colorName = item->name;
393 item = color_or_size_dsa_get (&theme->sizes, sizeIndex);
394 sizeName = item->name;
396 if (SUCCEEDED (OpenThemeFile (themeFileName, colorName, sizeName,
397 &hTheme, 0)))
399 ApplyTheme (hTheme, b, NULL);
400 CloseThemeFile (hTheme);
402 else
404 ApplyTheme (NULL, b, NULL);
408 refresh_sysparams(dialog);
411 static BOOL updating_ui;
412 static BOOL theme_dirty;
414 static void enable_size_and_color_controls (HWND dialog, BOOL enable)
416 EnableWindow (GetDlgItem (dialog, IDC_THEME_COLORCOMBO), enable);
417 EnableWindow (GetDlgItem (dialog, IDC_THEME_COLORTEXT), enable);
418 EnableWindow (GetDlgItem (dialog, IDC_THEME_SIZECOMBO), enable);
419 EnableWindow (GetDlgItem (dialog, IDC_THEME_SIZETEXT), enable);
422 static DWORD get_app_theme(void)
424 DWORD ret = 0, len = sizeof(ret), type;
425 HKEY hkey;
427 if (RegOpenKeyExW( HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", 0, KEY_QUERY_VALUE, &hkey ))
428 return 1;
429 if (RegQueryValueExW( hkey, L"AppsUseLightTheme", NULL, &type, (BYTE *)&ret, &len ) || type != REG_DWORD)
430 ret = 1;
432 RegCloseKey( hkey );
433 return ret;
436 static void init_dialog (HWND dialog)
438 DWORD apps_use_light_theme;
439 WCHAR apps_theme_str[256];
441 static const struct
443 int id;
444 DWORD value;
446 app_themes[] =
448 { IDC_THEME_APPCOMBO_LIGHT, 1 },
449 { IDC_THEME_APPCOMBO_DARK, 0 },
452 SendDlgItemMessageW( dialog, IDC_THEME_APPCOMBO, CB_RESETCONTENT, 0, 0 );
454 LoadStringW( GetModuleHandleW(NULL), app_themes[0].id, apps_theme_str, ARRAY_SIZE(apps_theme_str) );
455 SendDlgItemMessageW( dialog, IDC_THEME_APPCOMBO, CB_ADDSTRING, 0, (LPARAM)apps_theme_str );
456 LoadStringW( GetModuleHandleW(NULL), app_themes[1].id, apps_theme_str, ARRAY_SIZE(apps_theme_str) );
457 SendDlgItemMessageW( dialog, IDC_THEME_APPCOMBO, CB_ADDSTRING, 0, (LPARAM)apps_theme_str );
459 apps_use_light_theme = get_app_theme();
460 SendDlgItemMessageW( dialog, IDC_THEME_APPCOMBO, CB_SETCURSEL, app_themes[apps_use_light_theme].value, 0 );
462 SendDlgItemMessageW( dialog, IDC_SYSPARAM_SIZE_UD, UDM_SETBUDDY, (WPARAM)GetDlgItem(dialog, IDC_SYSPARAM_SIZE), 0 );
465 static void update_dialog (HWND dialog)
467 updating_ui = TRUE;
469 scan_theme_files();
470 if (!fill_theme_list (GetDlgItem (dialog, IDC_THEME_THEMECOMBO),
471 GetDlgItem (dialog, IDC_THEME_COLORCOMBO),
472 GetDlgItem (dialog, IDC_THEME_SIZECOMBO)))
474 SendMessageW (GetDlgItem (dialog, IDC_THEME_COLORCOMBO), CB_SETCURSEL, (WPARAM)-1, 0);
475 SendMessageW (GetDlgItem (dialog, IDC_THEME_SIZECOMBO), CB_SETCURSEL, (WPARAM)-1, 0);
476 enable_size_and_color_controls (dialog, FALSE);
478 else
480 enable_size_and_color_controls (dialog, TRUE);
482 theme_dirty = FALSE;
484 SendDlgItemMessageW(dialog, IDC_SYSPARAM_SIZE_UD, UDM_SETRANGE, 0, MAKELONG(100, 8));
486 updating_ui = FALSE;
489 static void on_theme_changed(HWND dialog) {
490 int index;
492 index = SendMessageW (GetDlgItem (dialog, IDC_THEME_THEMECOMBO), CB_GETCURSEL, 0, 0);
493 if (!update_color_and_size (index, GetDlgItem (dialog, IDC_THEME_COLORCOMBO),
494 GetDlgItem (dialog, IDC_THEME_SIZECOMBO)))
496 SendMessageW (GetDlgItem (dialog, IDC_THEME_COLORCOMBO), CB_SETCURSEL, -1, 0);
497 SendMessageW (GetDlgItem (dialog, IDC_THEME_SIZECOMBO), CB_SETCURSEL, -1, 0);
498 enable_size_and_color_controls (dialog, FALSE);
500 else
502 enable_size_and_color_controls (dialog, TRUE);
505 index = SendMessageW (GetDlgItem (dialog, IDC_THEME_APPCOMBO), CB_GETCURSEL, 0, 0);
506 set_reg_key_dword(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
507 L"AppsUseLightTheme", !index);
509 theme_dirty = TRUE;
512 static void apply_theme(HWND dialog)
514 int themeIndex, colorIndex, sizeIndex;
516 if (!theme_dirty) return;
518 themeIndex = SendMessageW (GetDlgItem (dialog, IDC_THEME_THEMECOMBO),
519 CB_GETCURSEL, 0, 0);
520 colorIndex = SendMessageW (GetDlgItem (dialog, IDC_THEME_COLORCOMBO),
521 CB_GETCURSEL, 0, 0);
522 sizeIndex = SendMessageW (GetDlgItem (dialog, IDC_THEME_SIZECOMBO),
523 CB_GETCURSEL, 0, 0);
525 do_apply_theme (dialog, themeIndex, colorIndex, sizeIndex);
526 theme_dirty = FALSE;
529 static struct
531 int sm_idx, color_idx;
532 const WCHAR *color_reg;
533 int size;
534 COLORREF color;
535 LOGFONTW lf;
536 } metrics[] =
538 {-1, COLOR_BTNFACE, L"ButtonFace" }, /* IDC_SYSPARAMS_BUTTON */
539 {-1, COLOR_BTNTEXT, L"ButtonText" }, /* IDC_SYSPARAMS_BUTTON_TEXT */
540 {-1, COLOR_BACKGROUND, L"Background" }, /* IDC_SYSPARAMS_DESKTOP */
541 {SM_CXMENUSIZE, COLOR_MENU, L"Menu" }, /* IDC_SYSPARAMS_MENU */
542 {-1, COLOR_MENUTEXT, L"MenuText" }, /* IDC_SYSPARAMS_MENU_TEXT */
543 {SM_CXVSCROLL, COLOR_SCROLLBAR, L"Scrollbar" }, /* IDC_SYSPARAMS_SCROLLBAR */
544 {-1, COLOR_HIGHLIGHT, L"Hilight" }, /* IDC_SYSPARAMS_SELECTION */
545 {-1, COLOR_HIGHLIGHTTEXT, L"HilightText" }, /* IDC_SYSPARAMS_SELECTION_TEXT */
546 {-1, COLOR_INFOBK, L"InfoWindow" }, /* IDC_SYSPARAMS_TOOLTIP */
547 {-1, COLOR_INFOTEXT, L"InfoText" }, /* IDC_SYSPARAMS_TOOLTIP_TEXT */
548 {-1, COLOR_WINDOW, L"Window" }, /* IDC_SYSPARAMS_WINDOW */
549 {-1, COLOR_WINDOWTEXT, L"WindowText" }, /* IDC_SYSPARAMS_WINDOW_TEXT */
550 {SM_CYSIZE, COLOR_ACTIVECAPTION, L"ActiveTitle" }, /* IDC_SYSPARAMS_ACTIVE_TITLE */
551 {-1, COLOR_CAPTIONTEXT, L"TitleText" }, /* IDC_SYSPARAMS_ACTIVE_TITLE_TEXT */
552 {-1, COLOR_INACTIVECAPTION, L"InactiveTitle" }, /* IDC_SYSPARAMS_INACTIVE_TITLE */
553 {-1, COLOR_INACTIVECAPTIONTEXT,L"InactiveTitleText" }, /* IDC_SYSPARAMS_INACTIVE_TITLE_TEXT */
554 {-1, -1, L"MsgBoxText" }, /* IDC_SYSPARAMS_MSGBOX_TEXT */
555 {-1, COLOR_APPWORKSPACE, L"AppWorkSpace" }, /* IDC_SYSPARAMS_APPWORKSPACE */
556 {-1, COLOR_WINDOWFRAME, L"WindowFrame" }, /* IDC_SYSPARAMS_WINDOW_FRAME */
557 {-1, COLOR_ACTIVEBORDER, L"ActiveBorder" }, /* IDC_SYSPARAMS_ACTIVE_BORDER */
558 {-1, COLOR_INACTIVEBORDER, L"InactiveBorder" }, /* IDC_SYSPARAMS_INACTIVE_BORDER */
559 {-1, COLOR_BTNSHADOW, L"ButtonShadow" }, /* IDC_SYSPARAMS_BUTTON_SHADOW */
560 {-1, COLOR_GRAYTEXT, L"GrayText" }, /* IDC_SYSPARAMS_GRAY_TEXT */
561 {-1, COLOR_BTNHIGHLIGHT, L"ButtonHilight" }, /* IDC_SYSPARAMS_BUTTON_HIGHLIGHT */
562 {-1, COLOR_3DDKSHADOW, L"ButtonDkShadow" }, /* IDC_SYSPARAMS_BUTTON_DARK_SHADOW */
563 {-1, COLOR_3DLIGHT, L"ButtonLight" }, /* IDC_SYSPARAMS_BUTTON_LIGHT */
564 {-1, COLOR_ALTERNATEBTNFACE, L"ButtonAlternateFace" }, /* IDC_SYSPARAMS_BUTTON_ALTERNATE */
565 {-1, COLOR_HOTLIGHT, L"HotTrackingColor" }, /* IDC_SYSPARAMS_HOT_TRACKING */
566 {-1, COLOR_GRADIENTACTIVECAPTION, L"GradientActiveTitle" }, /* IDC_SYSPARAMS_ACTIVE_TITLE_GRADIENT */
567 {-1, COLOR_GRADIENTINACTIVECAPTION, L"GradientInactiveTitle" }, /* IDC_SYSPARAMS_INACTIVE_TITLE_GRADIENT */
568 {-1, COLOR_MENUHILIGHT, L"MenuHilight" }, /* IDC_SYSPARAMS_MENU_HIGHLIGHT */
569 {-1, COLOR_MENUBAR, L"MenuBar" }, /* IDC_SYSPARAMS_MENUBAR */
572 static void save_sys_color(int idx, COLORREF clr)
574 WCHAR buffer[13];
576 swprintf(buffer, ARRAY_SIZE(buffer), L"%d %d %d", GetRValue (clr), GetGValue (clr), GetBValue (clr));
577 set_reg_key(HKEY_CURRENT_USER, L"Control Panel\\Colors", metrics[idx].color_reg, buffer);
580 static void set_color_from_theme(const WCHAR *keyName, COLORREF color)
582 int i;
584 for (i=0; i < ARRAY_SIZE(metrics); i++)
586 if (wcsicmp(metrics[i].color_reg, keyName)==0)
588 metrics[i].color = color;
589 save_sys_color(i, color);
590 break;
595 static void do_parse_theme(WCHAR *file)
597 WCHAR *keyName, keyNameValue[MAX_PATH];
598 DWORD len, allocLen = 512;
599 WCHAR *keyNamePtr = NULL;
600 int red = 0, green = 0, blue = 0;
601 COLORREF color;
603 WINE_TRACE("%s\n", wine_dbgstr_w(file));
604 keyName = malloc(sizeof(*keyName) * allocLen);
605 for (;;)
607 assert(keyName);
608 len = GetPrivateProfileStringW(L"Control Panel\\Colors", NULL, NULL, keyName,
609 allocLen, file);
610 if (len < allocLen - 2)
611 break;
613 allocLen *= 2;
614 keyName = realloc(keyName, sizeof(*keyName) * allocLen);
617 keyNamePtr = keyName;
618 while (*keyNamePtr!=0) {
619 GetPrivateProfileStringW(L"Control Panel\\Colors", keyNamePtr, NULL, keyNameValue,
620 MAX_PATH, file);
622 WINE_TRACE("parsing key: %s with value: %s\n",
623 wine_dbgstr_w(keyNamePtr), wine_dbgstr_w(keyNameValue));
625 swscanf(keyNameValue, L"%d %d %d", &red, &green, &blue);
627 color = RGB((BYTE)red, (BYTE)green, (BYTE)blue);
628 set_color_from_theme(keyNamePtr, color);
630 keyNamePtr+=lstrlenW(keyNamePtr);
631 keyNamePtr++;
633 free(keyName);
636 static void on_theme_install(HWND dialog)
638 static const WCHAR filterMask[] = L"\0*.msstyles;*.theme\0";
639 OPENFILENAMEW ofn;
640 WCHAR filetitle[MAX_PATH];
641 WCHAR file[MAX_PATH];
642 WCHAR filter[100];
643 WCHAR title[100];
645 LoadStringW(GetModuleHandleW(NULL), IDS_THEMEFILE, filter, ARRAY_SIZE(filter) - ARRAY_SIZE(filterMask));
646 memcpy(filter + lstrlenW (filter), filterMask, sizeof(filterMask));
647 LoadStringW(GetModuleHandleW(NULL), IDS_THEMEFILE_SELECT, title, ARRAY_SIZE(title));
649 ofn.lStructSize = sizeof(OPENFILENAMEW);
650 ofn.hwndOwner = dialog;
651 ofn.hInstance = 0;
652 ofn.lpstrFilter = filter;
653 ofn.lpstrCustomFilter = NULL;
654 ofn.nMaxCustFilter = 0;
655 ofn.nFilterIndex = 0;
656 ofn.lpstrFile = file;
657 ofn.lpstrFile[0] = '\0';
658 ofn.nMaxFile = ARRAY_SIZE(file);
659 ofn.lpstrFileTitle = filetitle;
660 ofn.lpstrFileTitle[0] = '\0';
661 ofn.nMaxFileTitle = ARRAY_SIZE(filetitle);
662 ofn.lpstrInitialDir = NULL;
663 ofn.lpstrTitle = title;
664 ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_ENABLESIZING;
665 ofn.nFileOffset = 0;
666 ofn.nFileExtension = 0;
667 ofn.lpstrDefExt = NULL;
668 ofn.lCustData = 0;
669 ofn.lpfnHook = NULL;
670 ofn.lpTemplateName = NULL;
672 if (GetOpenFileNameW(&ofn))
674 WCHAR themeFilePath[MAX_PATH];
675 SHFILEOPSTRUCTW shfop;
677 if (FAILED (SHGetFolderPathW (NULL, CSIDL_RESOURCES|CSIDL_FLAG_CREATE, NULL,
678 SHGFP_TYPE_CURRENT, themeFilePath))) return;
680 if (lstrcmpiW(PathFindExtensionW(filetitle), L".theme")==0)
682 do_parse_theme(file);
683 SendMessageW(GetParent(dialog), PSM_CHANGED, 0, 0);
684 return;
687 PathRemoveExtensionW (filetitle);
689 /* Construct path into which the theme file goes */
690 lstrcatW (themeFilePath, L"\\themes\\");
691 lstrcatW (themeFilePath, filetitle);
693 /* Create the directory */
694 SHCreateDirectoryExW (dialog, themeFilePath, NULL);
696 /* Append theme file name itself */
697 lstrcatW (themeFilePath, L"\\");
698 lstrcatW (themeFilePath, PathFindFileNameW (file));
699 /* SHFileOperation() takes lists as input, so double-nullterminate */
700 themeFilePath[lstrlenW (themeFilePath)+1] = 0;
701 file[lstrlenW (file)+1] = 0;
703 /* Do the copying */
704 WINE_TRACE("copying: %s -> %s\n", wine_dbgstr_w (file),
705 wine_dbgstr_w (themeFilePath));
706 shfop.hwnd = dialog;
707 shfop.wFunc = FO_COPY;
708 shfop.pFrom = file;
709 shfop.pTo = themeFilePath;
710 shfop.fFlags = FOF_NOCONFIRMMKDIR;
711 if (SHFileOperationW (&shfop) == 0)
713 scan_theme_files();
714 if (!fill_theme_list (GetDlgItem (dialog, IDC_THEME_THEMECOMBO),
715 GetDlgItem (dialog, IDC_THEME_COLORCOMBO),
716 GetDlgItem (dialog, IDC_THEME_SIZECOMBO)))
718 SendMessageW (GetDlgItem (dialog, IDC_THEME_COLORCOMBO), CB_SETCURSEL, -1, 0);
719 SendMessageW (GetDlgItem (dialog, IDC_THEME_SIZECOMBO), CB_SETCURSEL, -1, 0);
720 enable_size_and_color_controls (dialog, FALSE);
722 else
724 enable_size_and_color_controls (dialog, TRUE);
727 else
728 WINE_TRACE("copy operation failed\n");
730 else WINE_TRACE("user cancelled\n");
733 /* Information about symbolic link targets of certain User Shell Folders. */
734 struct ShellFolderInfo {
735 int nFolder;
736 char szLinkTarget[FILENAME_MAX]; /* in unix locale */
739 #define CSIDL_DOWNLOADS 0x0047
741 static struct ShellFolderInfo asfiInfo[] = {
742 { CSIDL_DESKTOP, "" },
743 { CSIDL_PERSONAL, "" },
744 { CSIDL_MYPICTURES, "" },
745 { CSIDL_MYMUSIC, "" },
746 { CSIDL_MYVIDEO, "" },
747 { CSIDL_DOWNLOADS, "" },
748 { CSIDL_TEMPLATES, "" }
751 static struct ShellFolderInfo *psfiSelected = NULL;
753 static void init_shell_folder_listview_headers(HWND dialog) {
754 LVCOLUMNW listColumn;
755 RECT viewRect;
756 WCHAR szShellFolder[64] = L"Shell Folder";
757 WCHAR szLinksTo[64] = L"Links to";
758 int width;
760 LoadStringW(GetModuleHandleW(NULL), IDS_SHELL_FOLDER, szShellFolder, ARRAY_SIZE(szShellFolder));
761 LoadStringW(GetModuleHandleW(NULL), IDS_LINKS_TO, szLinksTo, ARRAY_SIZE(szLinksTo));
763 GetClientRect(GetDlgItem(dialog, IDC_LIST_SFPATHS), &viewRect);
764 width = (viewRect.right - viewRect.left) / 3;
766 listColumn.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
767 listColumn.pszText = szShellFolder;
768 listColumn.cchTextMax = lstrlenW(listColumn.pszText);
769 listColumn.cx = width;
771 SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_INSERTCOLUMNW, 0, (LPARAM) &listColumn);
773 listColumn.pszText = szLinksTo;
774 listColumn.cchTextMax = lstrlenW(listColumn.pszText);
775 listColumn.cx = viewRect.right - viewRect.left - width - 1;
777 SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_INSERTCOLUMNW, 1, (LPARAM) &listColumn);
780 /* Reads the currently set shell folder symbol link targets into asfiInfo. */
781 static void read_shell_folder_link_targets(void) {
782 WCHAR wszPath[MAX_PATH];
783 int i;
785 for (i=0; i<ARRAY_SIZE(asfiInfo); i++) {
786 asfiInfo[i].szLinkTarget[0] = '\0';
787 if (SUCCEEDED( SHGetFolderPathW( NULL, asfiInfo[i].nFolder | CSIDL_FLAG_DONT_VERIFY, NULL,
788 SHGFP_TYPE_CURRENT, wszPath )))
789 query_shell_folder( wszPath, asfiInfo[i].szLinkTarget, FILENAME_MAX );
793 static void update_shell_folder_listview(HWND dialog) {
794 int i;
795 LVITEMW item;
796 LONG lSelected = SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_GETNEXTITEM, -1,
797 MAKELPARAM(LVNI_SELECTED,0));
799 SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_DELETEALLITEMS, 0, 0);
801 for (i=0; i<ARRAY_SIZE(asfiInfo); i++) {
802 WCHAR buffer[MAX_PATH];
803 HRESULT hr;
804 LPITEMIDLIST pidlCurrent;
806 /* Some acrobatic to get the localized name of the shell folder */
807 hr = SHGetFolderLocation(dialog, asfiInfo[i].nFolder, NULL, 0, &pidlCurrent);
808 if (SUCCEEDED(hr)) {
809 LPSHELLFOLDER psfParent;
810 LPCITEMIDLIST pidlLast;
811 hr = SHBindToParent(pidlCurrent, &IID_IShellFolder, (LPVOID*)&psfParent, &pidlLast);
812 if (SUCCEEDED(hr)) {
813 STRRET strRet;
814 hr = IShellFolder_GetDisplayNameOf(psfParent, pidlLast, SHGDN_FORADDRESSBAR, &strRet);
815 if (SUCCEEDED(hr)) {
816 hr = StrRetToBufW(&strRet, pidlLast, buffer, MAX_PATH);
818 IShellFolder_Release(psfParent);
820 ILFree(pidlCurrent);
823 /* If there's a dangling symlink for the current shell folder, SHGetFolderLocation
824 * will fail above. We fall back to the (non-verified) path of the shell folder. */
825 if (FAILED(hr)) {
826 hr = SHGetFolderPathW(dialog, asfiInfo[i].nFolder|CSIDL_FLAG_DONT_VERIFY, NULL,
827 SHGFP_TYPE_CURRENT, buffer);
830 item.mask = LVIF_TEXT | LVIF_PARAM;
831 item.iItem = i;
832 item.iSubItem = 0;
833 item.pszText = buffer;
834 item.lParam = (LPARAM)&asfiInfo[i];
835 SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_INSERTITEMW, 0, (LPARAM)&item);
837 item.mask = LVIF_TEXT;
838 item.iItem = i;
839 item.iSubItem = 1;
840 item.pszText = strdupU2W(asfiInfo[i].szLinkTarget);
841 SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_SETITEMW, 0, (LPARAM)&item);
842 free(item.pszText);
845 /* Ensure that the previously selected item is selected again. */
846 if (lSelected >= 0) {
847 item.mask = LVIF_STATE;
848 item.state = LVIS_SELECTED;
849 item.stateMask = LVIS_SELECTED;
850 SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_SETITEMSTATE, lSelected, (LPARAM)&item);
854 static void on_shell_folder_selection_changed(HWND hDlg, LPNMLISTVIEW lpnm) {
855 if (lpnm->uNewState & LVIS_SELECTED) {
856 psfiSelected = (struct ShellFolderInfo *)lpnm->lParam;
857 EnableWindow(GetDlgItem(hDlg, IDC_LINK_SFPATH), 1);
858 if (*psfiSelected->szLinkTarget) {
859 WCHAR *link;
860 CheckDlgButton(hDlg, IDC_LINK_SFPATH, BST_CHECKED);
861 EnableWindow(GetDlgItem(hDlg, IDC_EDIT_SFPATH), 1);
862 EnableWindow(GetDlgItem(hDlg, IDC_BROWSE_SFPATH), 1);
863 link = strdupU2W(psfiSelected->szLinkTarget);
864 set_textW(hDlg, IDC_EDIT_SFPATH, link);
865 free(link);
866 } else {
867 CheckDlgButton(hDlg, IDC_LINK_SFPATH, BST_UNCHECKED);
868 EnableWindow(GetDlgItem(hDlg, IDC_EDIT_SFPATH), 0);
869 EnableWindow(GetDlgItem(hDlg, IDC_BROWSE_SFPATH), 0);
870 set_text(hDlg, IDC_EDIT_SFPATH, "");
872 } else {
873 psfiSelected = NULL;
874 CheckDlgButton(hDlg, IDC_LINK_SFPATH, BST_UNCHECKED);
875 set_text(hDlg, IDC_EDIT_SFPATH, "");
876 EnableWindow(GetDlgItem(hDlg, IDC_LINK_SFPATH), 0);
877 EnableWindow(GetDlgItem(hDlg, IDC_EDIT_SFPATH), 0);
878 EnableWindow(GetDlgItem(hDlg, IDC_BROWSE_SFPATH), 0);
882 /* Keep the contents of the edit control, the listview control and the symlink
883 * information in sync. */
884 static void on_shell_folder_edit_changed(HWND hDlg) {
885 LVITEMW item;
886 WCHAR *text = get_text(hDlg, IDC_EDIT_SFPATH);
887 LONG iSel = SendDlgItemMessageW(hDlg, IDC_LIST_SFPATHS, LVM_GETNEXTITEM, -1,
888 MAKELPARAM(LVNI_SELECTED,0));
890 if (!text || !psfiSelected || iSel < 0) {
891 free(text);
892 return;
895 WideCharToMultiByte(CP_UNIXCP, 0, text, -1,
896 psfiSelected->szLinkTarget, FILENAME_MAX, NULL, NULL);
898 item.mask = LVIF_TEXT;
899 item.iItem = iSel;
900 item.iSubItem = 1;
901 item.pszText = text;
902 SendDlgItemMessageW(hDlg, IDC_LIST_SFPATHS, LVM_SETITEMW, 0, (LPARAM)&item);
904 free(text);
906 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
909 static void apply_shell_folder_changes(void) {
910 WCHAR wszPath[MAX_PATH];
911 int i;
913 for (i=0; i<ARRAY_SIZE(asfiInfo); i++) {
914 if (SUCCEEDED( SHGetFolderPathW( NULL, asfiInfo[i].nFolder | CSIDL_FLAG_CREATE, NULL,
915 SHGFP_TYPE_CURRENT, wszPath )))
916 set_shell_folder( wszPath, asfiInfo[i].szLinkTarget );
920 static void refresh_sysparams(HWND hDlg)
922 int i;
924 for (i = 0; i < ARRAY_SIZE(metrics); i++)
926 if (metrics[i].sm_idx != -1)
927 metrics[i].size = GetSystemMetrics(metrics[i].sm_idx);
928 if (metrics[i].color_idx != -1)
929 metrics[i].color = GetSysColor(metrics[i].color_idx);
932 on_sysparam_change(hDlg);
935 static void read_sysparams(HWND hDlg)
937 WCHAR buffer[256];
938 HWND list = GetDlgItem(hDlg, IDC_SYSPARAM_COMBO);
939 NONCLIENTMETRICSW nonclient_metrics;
940 int i, idx;
942 for (i = 0; i < ARRAY_SIZE(metrics); i++)
944 LoadStringW(GetModuleHandleW(NULL), i + IDC_SYSPARAMS_BUTTON, buffer, ARRAY_SIZE(buffer));
945 idx = SendMessageW(list, CB_ADDSTRING, 0, (LPARAM)buffer);
946 if (idx != CB_ERR) SendMessageW(list, CB_SETITEMDATA, idx, i);
948 if (metrics[i].sm_idx != -1)
949 metrics[i].size = GetSystemMetrics(metrics[i].sm_idx);
950 if (metrics[i].color_idx != -1)
951 metrics[i].color = GetSysColor(metrics[i].color_idx);
954 nonclient_metrics.cbSize = sizeof(NONCLIENTMETRICSW);
955 SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSW), &nonclient_metrics, 0);
957 memcpy(&(metrics[IDC_SYSPARAMS_MENU_TEXT - IDC_SYSPARAMS_BUTTON].lf),
958 &(nonclient_metrics.lfMenuFont), sizeof(LOGFONTW));
959 memcpy(&(metrics[IDC_SYSPARAMS_ACTIVE_TITLE_TEXT - IDC_SYSPARAMS_BUTTON].lf),
960 &(nonclient_metrics.lfCaptionFont), sizeof(LOGFONTW));
961 memcpy(&(metrics[IDC_SYSPARAMS_TOOLTIP_TEXT - IDC_SYSPARAMS_BUTTON].lf),
962 &(nonclient_metrics.lfStatusFont), sizeof(LOGFONTW));
963 memcpy(&(metrics[IDC_SYSPARAMS_MSGBOX_TEXT - IDC_SYSPARAMS_BUTTON].lf),
964 &(nonclient_metrics.lfMessageFont), sizeof(LOGFONTW));
967 static void apply_sysparams(void)
969 NONCLIENTMETRICSW ncm;
970 int i, cnt = 0;
971 int colors_idx[ARRAY_SIZE(metrics)];
972 COLORREF colors[ARRAY_SIZE(metrics)];
973 HDC hdc;
974 int dpi;
976 hdc = GetDC( 0 );
977 dpi = GetDeviceCaps( hdc, LOGPIXELSY );
978 ReleaseDC( 0, hdc );
980 ncm.cbSize = sizeof(ncm);
981 SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0);
983 /* convert metrics back to twips */
984 ncm.iMenuWidth = ncm.iMenuHeight =
985 MulDiv( metrics[IDC_SYSPARAMS_MENU - IDC_SYSPARAMS_BUTTON].size, -1440, dpi );
986 ncm.iCaptionWidth = ncm.iCaptionHeight =
987 MulDiv( metrics[IDC_SYSPARAMS_ACTIVE_TITLE - IDC_SYSPARAMS_BUTTON].size, -1440, dpi );
988 ncm.iScrollWidth = ncm.iScrollHeight =
989 MulDiv( metrics[IDC_SYSPARAMS_SCROLLBAR - IDC_SYSPARAMS_BUTTON].size, -1440, dpi );
990 ncm.iSmCaptionWidth = MulDiv( ncm.iSmCaptionWidth, -1440, dpi );
991 ncm.iSmCaptionHeight = MulDiv( ncm.iSmCaptionHeight, -1440, dpi );
993 ncm.lfMenuFont = metrics[IDC_SYSPARAMS_MENU_TEXT - IDC_SYSPARAMS_BUTTON].lf;
994 ncm.lfCaptionFont = metrics[IDC_SYSPARAMS_ACTIVE_TITLE_TEXT - IDC_SYSPARAMS_BUTTON].lf;
995 ncm.lfStatusFont = metrics[IDC_SYSPARAMS_TOOLTIP_TEXT - IDC_SYSPARAMS_BUTTON].lf;
996 ncm.lfMessageFont = metrics[IDC_SYSPARAMS_MSGBOX_TEXT - IDC_SYSPARAMS_BUTTON].lf;
998 SystemParametersInfoW(SPI_SETNONCLIENTMETRICS, sizeof(ncm), &ncm,
999 SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
1001 for (i = 0; i < ARRAY_SIZE(metrics); i++)
1002 if (metrics[i].color_idx != -1)
1004 colors_idx[cnt] = metrics[i].color_idx;
1005 colors[cnt++] = metrics[i].color;
1007 SetSysColors(cnt, colors_idx, colors);
1010 static void on_sysparam_change(HWND hDlg)
1012 int index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETCURSEL, 0, 0);
1014 index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETITEMDATA, index, 0);
1016 updating_ui = TRUE;
1018 EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_COLOR_TEXT), metrics[index].color_idx != -1);
1019 EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_COLOR), metrics[index].color_idx != -1);
1020 InvalidateRect(GetDlgItem(hDlg, IDC_SYSPARAM_COLOR), NULL, TRUE);
1022 EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_SIZE_TEXT), metrics[index].sm_idx != -1);
1023 EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_SIZE), metrics[index].sm_idx != -1);
1024 EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_SIZE_UD), metrics[index].sm_idx != -1);
1025 if (metrics[index].sm_idx != -1)
1026 SendDlgItemMessageW(hDlg, IDC_SYSPARAM_SIZE_UD, UDM_SETPOS, 0, MAKELONG(metrics[index].size, 0));
1027 else
1028 set_text(hDlg, IDC_SYSPARAM_SIZE, "");
1030 EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_FONT),
1031 index == IDC_SYSPARAMS_MENU_TEXT-IDC_SYSPARAMS_BUTTON ||
1032 index == IDC_SYSPARAMS_ACTIVE_TITLE_TEXT-IDC_SYSPARAMS_BUTTON ||
1033 index == IDC_SYSPARAMS_TOOLTIP_TEXT-IDC_SYSPARAMS_BUTTON ||
1034 index == IDC_SYSPARAMS_MSGBOX_TEXT-IDC_SYSPARAMS_BUTTON
1037 updating_ui = FALSE;
1040 static void on_draw_item(HWND hDlg, WPARAM wParam, LPARAM lParam)
1042 static HBRUSH black_brush = 0;
1043 LPDRAWITEMSTRUCT draw_info = (LPDRAWITEMSTRUCT)lParam;
1045 if (!black_brush) black_brush = CreateSolidBrush(0);
1047 if (draw_info->CtlID == IDC_SYSPARAM_COLOR)
1049 UINT state;
1050 HTHEME theme;
1051 RECT buttonrect;
1053 theme = OpenThemeDataForDpi(NULL, WC_BUTTONW, GetDpiForWindow(hDlg));
1055 if (theme) {
1056 MARGINS margins;
1058 if (draw_info->itemState & ODS_DISABLED)
1059 state = PBS_DISABLED;
1060 else if (draw_info->itemState & ODS_SELECTED)
1061 state = PBS_PRESSED;
1062 else
1063 state = PBS_NORMAL;
1065 if (IsThemeBackgroundPartiallyTransparent(theme, BP_PUSHBUTTON, state))
1066 DrawThemeParentBackground(draw_info->hwndItem, draw_info->hDC, NULL);
1068 DrawThemeBackground(theme, draw_info->hDC, BP_PUSHBUTTON, state, &draw_info->rcItem, NULL);
1070 buttonrect = draw_info->rcItem;
1072 GetThemeMargins(theme, draw_info->hDC, BP_PUSHBUTTON, state, TMT_CONTENTMARGINS, &draw_info->rcItem, &margins);
1074 buttonrect.left += margins.cxLeftWidth;
1075 buttonrect.top += margins.cyTopHeight;
1076 buttonrect.right -= margins.cxRightWidth;
1077 buttonrect.bottom -= margins.cyBottomHeight;
1079 if (draw_info->itemState & ODS_FOCUS)
1080 DrawFocusRect(draw_info->hDC, &buttonrect);
1082 CloseThemeData(theme);
1083 } else {
1084 state = DFCS_ADJUSTRECT | DFCS_BUTTONPUSH;
1086 if (draw_info->itemState & ODS_DISABLED)
1087 state |= DFCS_INACTIVE;
1088 else
1089 state |= draw_info->itemState & ODS_SELECTED ? DFCS_PUSHED : 0;
1091 DrawFrameControl(draw_info->hDC, &draw_info->rcItem, DFC_BUTTON, state);
1093 buttonrect = draw_info->rcItem;
1096 if (!(draw_info->itemState & ODS_DISABLED))
1098 HBRUSH brush;
1099 int index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETCURSEL, 0, 0);
1101 index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETITEMDATA, index, 0);
1102 brush = CreateSolidBrush(metrics[index].color);
1104 InflateRect(&buttonrect, -1, -1);
1105 FrameRect(draw_info->hDC, &buttonrect, black_brush);
1106 InflateRect(&buttonrect, -1, -1);
1107 FillRect(draw_info->hDC, &buttonrect, brush);
1108 DeleteObject(brush);
1113 static void on_select_font(HWND hDlg)
1115 CHOOSEFONTW cf;
1116 int index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETCURSEL, 0, 0);
1117 index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETITEMDATA, index, 0);
1119 ZeroMemory(&cf, sizeof(cf));
1120 cf.lStructSize = sizeof(CHOOSEFONTW);
1121 cf.hwndOwner = hDlg;
1122 cf.lpLogFont = &(metrics[index].lf);
1123 cf.Flags = CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT | CF_NOSCRIPTSEL | CF_NOVERTFONTS;
1125 if (ChooseFontW(&cf))
1126 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1129 static void init_mime_types(HWND hDlg)
1131 WCHAR *buf = get_reg_key(config_key, keypath(L"FileOpenAssociations"), L"Enable", L"Y");
1132 int state = IS_OPTION_TRUE(*buf) ? BST_CHECKED : BST_UNCHECKED;
1134 CheckDlgButton(hDlg, IDC_ENABLE_FILE_ASSOCIATIONS, state);
1136 free(buf);
1139 static void update_mime_types(HWND hDlg)
1141 const WCHAR *state = L"Y";
1143 if (IsDlgButtonChecked(hDlg, IDC_ENABLE_FILE_ASSOCIATIONS) != BST_CHECKED)
1144 state = L"N";
1146 set_reg_key(config_key, keypath(L"FileOpenAssociations"), L"Enable", state);
1149 static BOOL CALLBACK update_window_pos_proc(HWND hwnd, LPARAM lp)
1151 RECT rect;
1153 GetClientRect(hwnd, &rect);
1154 AdjustWindowRectEx(&rect, GetWindowLongW(hwnd, GWL_STYLE), !!GetMenu(hwnd),
1155 GetWindowLongW(hwnd, GWL_EXSTYLE));
1156 SetWindowPos(hwnd, 0, 0, 0, rect.right - rect.left, rect.bottom - rect.top,
1157 SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
1158 return TRUE;
1161 /* Adjust the rectangle for top-level windows because the new non-client metrics may be different */
1162 static void update_window_pos(void)
1164 EnumWindows(update_window_pos_proc, 0);
1167 INT_PTR CALLBACK
1168 ThemeDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1170 switch (uMsg) {
1171 case WM_INITDIALOG:
1172 read_shell_folder_link_targets();
1173 init_shell_folder_listview_headers(hDlg);
1174 update_shell_folder_listview(hDlg);
1175 read_sysparams(hDlg);
1176 init_mime_types(hDlg);
1177 init_dialog(hDlg);
1178 break;
1180 case WM_DESTROY:
1181 free_theme_files();
1182 break;
1184 case WM_SHOWWINDOW:
1185 set_window_title(hDlg);
1186 break;
1188 case WM_COMMAND:
1189 switch(HIWORD(wParam)) {
1190 case CBN_SELCHANGE: {
1191 if (updating_ui) break;
1192 switch (LOWORD(wParam))
1194 case IDC_THEME_APPCOMBO: /* fall through */
1195 case IDC_THEME_THEMECOMBO: on_theme_changed(hDlg); break;
1196 case IDC_THEME_COLORCOMBO: /* fall through */
1197 case IDC_THEME_SIZECOMBO: theme_dirty = TRUE; break;
1198 case IDC_SYSPARAM_COMBO: on_sysparam_change(hDlg); return FALSE;
1200 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1201 break;
1203 case EN_CHANGE: {
1204 if (updating_ui) break;
1205 switch (LOWORD(wParam))
1207 case IDC_EDIT_SFPATH: on_shell_folder_edit_changed(hDlg); break;
1208 case IDC_SYSPARAM_SIZE:
1210 WCHAR *text = get_text(hDlg, IDC_SYSPARAM_SIZE);
1211 int index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETCURSEL, 0, 0);
1213 index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETITEMDATA, index, 0);
1215 if (text)
1217 metrics[index].size = wcstol(text, NULL, 10);
1218 free(text);
1220 else
1222 /* for empty string set to minimum value */
1223 SendDlgItemMessageW(hDlg, IDC_SYSPARAM_SIZE_UD, UDM_GETRANGE32, (WPARAM)&metrics[index].size, 0);
1226 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1227 break;
1230 break;
1232 case BN_CLICKED:
1233 switch (LOWORD(wParam))
1235 case IDC_THEME_INSTALL:
1236 on_theme_install (hDlg);
1237 break;
1239 case IDC_SYSPARAM_FONT:
1240 on_select_font(hDlg);
1241 break;
1243 case IDC_BROWSE_SFPATH:
1245 WCHAR link[FILENAME_MAX];
1246 if (browse_for_unix_folder(hDlg, link)) {
1247 WideCharToMultiByte(CP_UNIXCP, 0, link, -1,
1248 psfiSelected->szLinkTarget, FILENAME_MAX,
1249 NULL, NULL);
1250 update_shell_folder_listview(hDlg);
1251 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1253 break;
1256 case IDC_LINK_SFPATH:
1257 if (IsDlgButtonChecked(hDlg, IDC_LINK_SFPATH)) {
1258 WCHAR link[FILENAME_MAX];
1259 if (browse_for_unix_folder(hDlg, link)) {
1260 WideCharToMultiByte(CP_UNIXCP, 0, link, -1,
1261 psfiSelected->szLinkTarget, FILENAME_MAX,
1262 NULL, NULL);
1263 update_shell_folder_listview(hDlg);
1264 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1265 } else {
1266 CheckDlgButton(hDlg, IDC_LINK_SFPATH, BST_UNCHECKED);
1268 } else {
1269 psfiSelected->szLinkTarget[0] = '\0';
1270 update_shell_folder_listview(hDlg);
1271 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1273 break;
1275 case IDC_SYSPARAM_COLOR:
1277 static COLORREF user_colors[16];
1278 CHOOSECOLORW c_color;
1279 int index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETCURSEL, 0, 0);
1281 index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETITEMDATA, index, 0);
1283 memset(&c_color, 0, sizeof(c_color));
1284 c_color.lStructSize = sizeof(c_color);
1285 c_color.lpCustColors = user_colors;
1286 c_color.rgbResult = metrics[index].color;
1287 c_color.Flags = CC_ANYCOLOR | CC_RGBINIT;
1288 c_color.hwndOwner = hDlg;
1289 if (ChooseColorW(&c_color))
1291 metrics[index].color = c_color.rgbResult;
1292 save_sys_color(index, metrics[index].color);
1293 InvalidateRect(GetDlgItem(hDlg, IDC_SYSPARAM_COLOR), NULL, TRUE);
1294 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1296 break;
1299 case IDC_ENABLE_FILE_ASSOCIATIONS:
1300 update_mime_types(hDlg);
1301 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1302 break;
1304 break;
1306 break;
1308 case WM_NOTIFY:
1309 switch (((LPNMHDR)lParam)->code) {
1310 case PSN_KILLACTIVE: {
1311 SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, FALSE);
1312 break;
1314 case PSN_APPLY: {
1315 apply();
1316 apply_theme(hDlg);
1317 apply_shell_folder_changes();
1318 apply_sysparams();
1319 read_shell_folder_link_targets();
1320 update_shell_folder_listview(hDlg);
1321 update_mime_types(hDlg);
1322 update_window_pos();
1323 SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
1324 break;
1326 case LVN_ITEMCHANGED: {
1327 if (wParam == IDC_LIST_SFPATHS)
1328 on_shell_folder_selection_changed(hDlg, (LPNMLISTVIEW)lParam);
1329 break;
1331 case PSN_SETACTIVE: {
1332 update_dialog(hDlg);
1333 break;
1336 break;
1338 case WM_DRAWITEM:
1339 on_draw_item(hDlg, wParam, lParam);
1340 break;
1342 default:
1343 break;
1345 return FALSE;