include/mscvpdb.h: Use flexible array members for the rest of structures.
[wine.git] / programs / winecfg / theme.c
blobcc1a3c668203eb9c59eaa18594a835a3748aa752
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>
29 #define COBJMACROS
31 #include <windows.h>
32 #include <commdlg.h>
33 #include <shellapi.h>
34 #include <uxtheme.h>
35 #include <tmschema.h>
36 #include <shlobj.h>
37 #include <shlwapi.h>
38 #include <wine/debug.h>
40 #include "resource.h"
41 #include "winecfg.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
45 /* UXTHEME functions not in the headers */
47 typedef struct tagTHEMENAMES
49 WCHAR szName[MAX_PATH+1];
50 WCHAR szDisplayName[MAX_PATH+1];
51 WCHAR szTooltip[MAX_PATH+1];
52 } THEMENAMES, *PTHEMENAMES;
54 typedef void* HTHEMEFILE;
55 typedef BOOL (CALLBACK *EnumThemeProc)(LPVOID lpReserved,
56 LPCWSTR pszThemeFileName,
57 LPCWSTR pszThemeName,
58 LPCWSTR pszToolTip, LPVOID lpReserved2,
59 LPVOID lpData);
61 HRESULT WINAPI EnumThemeColors (LPCWSTR pszThemeFileName, LPWSTR pszSizeName,
62 DWORD dwColorNum, PTHEMENAMES pszColorNames);
63 HRESULT WINAPI EnumThemeSizes (LPCWSTR pszThemeFileName, LPWSTR pszColorName,
64 DWORD dwSizeNum, PTHEMENAMES pszSizeNames);
65 HRESULT WINAPI ApplyTheme (HTHEMEFILE hThemeFile, char* unknown, HWND hWnd);
66 HRESULT WINAPI OpenThemeFile (LPCWSTR pszThemeFileName, LPCWSTR pszColorName,
67 LPCWSTR pszSizeName, HTHEMEFILE* hThemeFile,
68 DWORD unknown);
69 HRESULT WINAPI CloseThemeFile (HTHEMEFILE hThemeFile);
70 HRESULT WINAPI EnumThemes (LPCWSTR pszThemePath, EnumThemeProc callback,
71 LPVOID lpData);
73 static void refresh_sysparams(HWND hDlg);
74 static void on_sysparam_change(HWND hDlg);
76 /* A struct to keep both the internal and "fancy" name of a color or size */
77 typedef struct
79 WCHAR* name;
80 WCHAR* fancyName;
81 } ThemeColorOrSize;
83 /* wrapper around DSA that also keeps an item count */
84 typedef struct
86 HDSA dsa;
87 int count;
88 } WrappedDsa;
90 /* Some helper functions to deal with ThemeColorOrSize structs in WrappedDSAs */
92 static void color_or_size_dsa_add (WrappedDsa* wdsa, const WCHAR* name,
93 const WCHAR* fancyName)
95 ThemeColorOrSize item;
97 item.name = malloc ((wcslen (name) + 1) * sizeof(WCHAR));
98 lstrcpyW (item.name, name);
100 item.fancyName = malloc ((wcslen (fancyName) + 1) * sizeof(WCHAR));
101 lstrcpyW (item.fancyName, fancyName);
103 DSA_InsertItem (wdsa->dsa, wdsa->count, &item);
104 wdsa->count++;
107 static int CALLBACK dsa_destroy_callback (LPVOID p, LPVOID pData)
109 ThemeColorOrSize* item = p;
110 free (item->name);
111 free (item->fancyName);
112 return 1;
115 static void free_color_or_size_dsa (WrappedDsa* wdsa)
117 DSA_DestroyCallback (wdsa->dsa, dsa_destroy_callback, NULL);
120 static void create_color_or_size_dsa (WrappedDsa* wdsa)
122 wdsa->dsa = DSA_Create (sizeof (ThemeColorOrSize), 1);
123 wdsa->count = 0;
126 static ThemeColorOrSize* color_or_size_dsa_get (WrappedDsa* wdsa, int index)
128 return DSA_GetItemPtr (wdsa->dsa, index);
131 static int color_or_size_dsa_find (WrappedDsa* wdsa, const WCHAR* name)
133 int i = 0;
134 for (; i < wdsa->count; i++)
136 ThemeColorOrSize* item = color_or_size_dsa_get (wdsa, i);
137 if (lstrcmpiW (item->name, name) == 0) break;
139 return i;
142 /* A theme file, contains file name, display name, color and size scheme names */
143 typedef struct
145 WCHAR* themeFileName;
146 WCHAR* fancyName;
147 WrappedDsa colors;
148 WrappedDsa sizes;
149 } ThemeFile;
151 static HDSA themeFiles = NULL;
152 static int themeFilesCount = 0;
154 static int CALLBACK theme_dsa_destroy_callback (LPVOID p, LPVOID pData)
156 ThemeFile* item = p;
157 free (item->themeFileName);
158 free (item->fancyName);
159 free_color_or_size_dsa (&item->colors);
160 free_color_or_size_dsa (&item->sizes);
161 return 1;
164 /* Free memory occupied by the theme list */
165 static void free_theme_files(void)
167 if (themeFiles == NULL) return;
169 DSA_DestroyCallback (themeFiles , theme_dsa_destroy_callback, NULL);
170 themeFiles = NULL;
171 themeFilesCount = 0;
174 typedef HRESULT (WINAPI * EnumTheme) (LPCWSTR, LPWSTR, DWORD, PTHEMENAMES);
176 /* fill a string list with either colors or sizes of a theme */
177 static void fill_theme_string_array (const WCHAR* filename,
178 WrappedDsa* wdsa,
179 EnumTheme enumTheme)
181 DWORD index = 0;
182 THEMENAMES names;
184 WINE_TRACE ("%s %p %p\n", wine_dbgstr_w (filename), wdsa, enumTheme);
186 while (SUCCEEDED (enumTheme (filename, NULL, index++, &names)))
188 WINE_TRACE ("%s: %s\n", wine_dbgstr_w (names.szName),
189 wine_dbgstr_w (names.szDisplayName));
190 color_or_size_dsa_add (wdsa, names.szName, names.szDisplayName);
194 /* Theme enumeration callback, adds theme to theme list */
195 static BOOL CALLBACK myEnumThemeProc (LPVOID lpReserved,
196 LPCWSTR pszThemeFileName,
197 LPCWSTR pszThemeName,
198 LPCWSTR pszToolTip,
199 LPVOID lpReserved2, LPVOID lpData)
201 ThemeFile newEntry;
203 /* fill size/color lists */
204 create_color_or_size_dsa (&newEntry.colors);
205 fill_theme_string_array (pszThemeFileName, &newEntry.colors, EnumThemeColors);
206 create_color_or_size_dsa (&newEntry.sizes);
207 fill_theme_string_array (pszThemeFileName, &newEntry.sizes, EnumThemeSizes);
209 newEntry.themeFileName = malloc ((wcslen (pszThemeFileName) + 1) * sizeof(WCHAR));
210 lstrcpyW (newEntry.themeFileName, pszThemeFileName);
212 newEntry.fancyName = malloc ((wcslen (pszThemeName) + 1) * sizeof(WCHAR));
213 lstrcpyW (newEntry.fancyName, pszThemeName);
215 /*list_add_tail (&themeFiles, &newEntry->entry);*/
216 DSA_InsertItem (themeFiles, themeFilesCount, &newEntry);
217 themeFilesCount++;
219 return TRUE;
222 /* Scan for themes */
223 static void scan_theme_files(void)
225 WCHAR themesPath[MAX_PATH];
227 free_theme_files();
229 if (FAILED (SHGetFolderPathW (NULL, CSIDL_RESOURCES, NULL,
230 SHGFP_TYPE_CURRENT, themesPath))) return;
232 themeFiles = DSA_Create (sizeof (ThemeFile), 1);
233 lstrcatW (themesPath, L"\\Themes");
235 EnumThemes (themesPath, myEnumThemeProc, 0);
238 /* fill the color & size combo boxes for a given theme */
239 static void fill_color_size_combos (ThemeFile* theme, HWND comboColor,
240 HWND comboSize)
242 int i;
244 SendMessageW (comboColor, CB_RESETCONTENT, 0, 0);
245 for (i = 0; i < theme->colors.count; i++)
247 ThemeColorOrSize* item = color_or_size_dsa_get (&theme->colors, i);
248 SendMessageW (comboColor, CB_ADDSTRING, 0, (LPARAM)item->fancyName);
251 SendMessageW (comboSize, CB_RESETCONTENT, 0, 0);
252 for (i = 0; i < theme->sizes.count; i++)
254 ThemeColorOrSize* item = color_or_size_dsa_get (&theme->sizes, i);
255 SendMessageW (comboSize, CB_ADDSTRING, 0, (LPARAM)item->fancyName);
259 /* Select the item of a combo box that matches a theme's color and size
260 * scheme. */
261 static void select_color_and_size (ThemeFile* theme,
262 const WCHAR* colorName, HWND comboColor,
263 const WCHAR* sizeName, HWND comboSize)
265 SendMessageW (comboColor, CB_SETCURSEL,
266 color_or_size_dsa_find (&theme->colors, colorName), 0);
267 SendMessageW (comboSize, CB_SETCURSEL,
268 color_or_size_dsa_find (&theme->sizes, sizeName), 0);
271 /* Fill theme, color and sizes combo boxes with the know themes and select
272 * the entries matching the currently active theme. */
273 static BOOL fill_theme_list (HWND comboTheme, HWND comboColor, HWND comboSize)
275 WCHAR textNoTheme[256];
276 int themeIndex = 0;
277 BOOL ret = TRUE;
278 int i;
279 WCHAR currentTheme[MAX_PATH];
280 WCHAR currentColor[MAX_PATH];
281 WCHAR currentSize[MAX_PATH];
282 ThemeFile* theme = NULL;
284 LoadStringW(GetModuleHandleW(NULL), IDS_NOTHEME, textNoTheme, ARRAY_SIZE(textNoTheme));
286 SendMessageW (comboTheme, CB_RESETCONTENT, 0, 0);
287 SendMessageW (comboTheme, CB_ADDSTRING, 0, (LPARAM)textNoTheme);
289 for (i = 0; i < themeFilesCount; i++)
291 ThemeFile* item = DSA_GetItemPtr (themeFiles, i);
292 SendMessageW (comboTheme, CB_ADDSTRING, 0,
293 (LPARAM)item->fancyName);
296 if (IsThemeActive() && SUCCEEDED(GetCurrentThemeName(currentTheme, ARRAY_SIZE(currentTheme),
297 currentColor, ARRAY_SIZE(currentColor), currentSize, ARRAY_SIZE(currentSize))))
299 /* Determine the index of the currently active theme. */
300 BOOL found = FALSE;
301 for (i = 0; i < themeFilesCount; i++)
303 theme = DSA_GetItemPtr (themeFiles, i);
304 if (lstrcmpiW (theme->themeFileName, currentTheme) == 0)
306 found = TRUE;
307 themeIndex = i+1;
308 break;
311 if (!found)
313 /* Current theme not found?... add to the list, then... */
314 WINE_TRACE("Theme %s not in list of enumerated themes\n",
315 wine_dbgstr_w (currentTheme));
316 myEnumThemeProc (NULL, currentTheme, currentTheme,
317 currentTheme, NULL, NULL);
318 themeIndex = themeFilesCount;
319 theme = DSA_GetItemPtr (themeFiles, themeFilesCount-1);
321 fill_color_size_combos (theme, comboColor, comboSize);
322 select_color_and_size (theme, currentColor, comboColor,
323 currentSize, comboSize);
325 else
327 /* No theme selected */
328 ret = FALSE;
331 SendMessageW (comboTheme, CB_SETCURSEL, themeIndex, 0);
332 return ret;
335 /* Update the color & size combo boxes when the selection of the theme
336 * combo changed. Selects the current color and size scheme if the theme
337 * is currently active, otherwise the first color and size. */
338 static BOOL update_color_and_size (int themeIndex, HWND comboColor,
339 HWND comboSize)
341 if (themeIndex == 0)
343 return FALSE;
345 else
347 WCHAR currentTheme[MAX_PATH];
348 WCHAR currentColor[MAX_PATH];
349 WCHAR currentSize[MAX_PATH];
350 ThemeFile* theme = DSA_GetItemPtr (themeFiles, themeIndex - 1);
352 fill_color_size_combos (theme, comboColor, comboSize);
354 if ((SUCCEEDED(GetCurrentThemeName (currentTheme, ARRAY_SIZE(currentTheme),
355 currentColor, ARRAY_SIZE(currentColor), currentSize, ARRAY_SIZE(currentSize))))
356 && (lstrcmpiW (currentTheme, theme->themeFileName) == 0))
358 select_color_and_size (theme, currentColor, comboColor,
359 currentSize, comboSize);
361 else
363 SendMessageW (comboColor, CB_SETCURSEL, 0, 0);
364 SendMessageW (comboSize, CB_SETCURSEL, 0, 0);
367 return TRUE;
370 /* Apply a theme from a given theme, color and size combo box item index. */
371 static void do_apply_theme (HWND dialog, int themeIndex, int colorIndex, int sizeIndex)
373 static char b[] = "\0";
375 if (themeIndex == 0)
377 /* no theme */
378 ApplyTheme (NULL, b, NULL);
380 else
382 ThemeFile* theme = DSA_GetItemPtr (themeFiles, themeIndex-1);
383 const WCHAR* themeFileName = theme->themeFileName;
384 const WCHAR* colorName = NULL;
385 const WCHAR* sizeName = NULL;
386 HTHEMEFILE hTheme;
387 ThemeColorOrSize* item;
389 item = color_or_size_dsa_get (&theme->colors, colorIndex);
390 colorName = item->name;
392 item = color_or_size_dsa_get (&theme->sizes, sizeIndex);
393 sizeName = item->name;
395 if (SUCCEEDED (OpenThemeFile (themeFileName, colorName, sizeName,
396 &hTheme, 0)))
398 ApplyTheme (hTheme, b, NULL);
399 CloseThemeFile (hTheme);
401 else
403 ApplyTheme (NULL, b, NULL);
407 refresh_sysparams(dialog);
410 static BOOL updating_ui;
411 static BOOL theme_dirty;
413 static void enable_size_and_color_controls (HWND dialog, BOOL enable)
415 EnableWindow (GetDlgItem (dialog, IDC_THEME_COLORCOMBO), enable);
416 EnableWindow (GetDlgItem (dialog, IDC_THEME_COLORTEXT), enable);
417 EnableWindow (GetDlgItem (dialog, IDC_THEME_SIZECOMBO), enable);
418 EnableWindow (GetDlgItem (dialog, IDC_THEME_SIZETEXT), enable);
421 static DWORD get_app_theme(void)
423 DWORD ret = 0, len = sizeof(ret), type;
424 HKEY hkey;
426 if (RegOpenKeyExW( HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", 0, KEY_QUERY_VALUE, &hkey ))
427 return 1;
428 if (RegQueryValueExW( hkey, L"AppsUseLightTheme", NULL, &type, (BYTE *)&ret, &len ) || type != REG_DWORD)
429 ret = 1;
431 RegCloseKey( hkey );
432 return ret;
435 static void init_dialog (HWND dialog)
437 DWORD apps_use_light_theme;
438 WCHAR apps_theme_str[256];
440 static const struct
442 int id;
443 DWORD value;
445 app_themes[] =
447 { IDC_THEME_APPCOMBO_LIGHT, 1 },
448 { IDC_THEME_APPCOMBO_DARK, 0 },
451 SendDlgItemMessageW( dialog, IDC_THEME_APPCOMBO, CB_RESETCONTENT, 0, 0 );
453 LoadStringW( GetModuleHandleW(NULL), app_themes[0].id, apps_theme_str, ARRAY_SIZE(apps_theme_str) );
454 SendDlgItemMessageW( dialog, IDC_THEME_APPCOMBO, CB_ADDSTRING, 0, (LPARAM)apps_theme_str );
455 LoadStringW( GetModuleHandleW(NULL), app_themes[1].id, apps_theme_str, ARRAY_SIZE(apps_theme_str) );
456 SendDlgItemMessageW( dialog, IDC_THEME_APPCOMBO, CB_ADDSTRING, 0, (LPARAM)apps_theme_str );
458 apps_use_light_theme = get_app_theme();
459 SendDlgItemMessageW( dialog, IDC_THEME_APPCOMBO, CB_SETCURSEL, app_themes[apps_use_light_theme].value, 0 );
461 SendDlgItemMessageW( dialog, IDC_SYSPARAM_SIZE_UD, UDM_SETBUDDY, (WPARAM)GetDlgItem(dialog, IDC_SYSPARAM_SIZE), 0 );
464 static void update_dialog (HWND dialog)
466 updating_ui = TRUE;
468 scan_theme_files();
469 if (!fill_theme_list (GetDlgItem (dialog, IDC_THEME_THEMECOMBO),
470 GetDlgItem (dialog, IDC_THEME_COLORCOMBO),
471 GetDlgItem (dialog, IDC_THEME_SIZECOMBO)))
473 SendMessageW (GetDlgItem (dialog, IDC_THEME_COLORCOMBO), CB_SETCURSEL, (WPARAM)-1, 0);
474 SendMessageW (GetDlgItem (dialog, IDC_THEME_SIZECOMBO), CB_SETCURSEL, (WPARAM)-1, 0);
475 enable_size_and_color_controls (dialog, FALSE);
477 else
479 enable_size_and_color_controls (dialog, TRUE);
481 theme_dirty = FALSE;
483 SendDlgItemMessageW(dialog, IDC_SYSPARAM_SIZE_UD, UDM_SETRANGE, 0, MAKELONG(100, 8));
485 updating_ui = FALSE;
488 static void on_theme_changed(HWND dialog) {
489 int index;
491 index = SendMessageW (GetDlgItem (dialog, IDC_THEME_THEMECOMBO), CB_GETCURSEL, 0, 0);
492 if (!update_color_and_size (index, GetDlgItem (dialog, IDC_THEME_COLORCOMBO),
493 GetDlgItem (dialog, IDC_THEME_SIZECOMBO)))
495 SendMessageW (GetDlgItem (dialog, IDC_THEME_COLORCOMBO), CB_SETCURSEL, -1, 0);
496 SendMessageW (GetDlgItem (dialog, IDC_THEME_SIZECOMBO), CB_SETCURSEL, -1, 0);
497 enable_size_and_color_controls (dialog, FALSE);
499 else
501 enable_size_and_color_controls (dialog, TRUE);
504 index = SendMessageW (GetDlgItem (dialog, IDC_THEME_APPCOMBO), CB_GETCURSEL, 0, 0);
505 set_reg_key_dword(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
506 L"AppsUseLightTheme", !index);
507 set_reg_key_dword(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
508 L"SystemUsesLightTheme", !index);
510 theme_dirty = TRUE;
513 static void apply_theme(HWND dialog)
515 int themeIndex, colorIndex, sizeIndex;
517 if (!theme_dirty) return;
519 themeIndex = SendMessageW (GetDlgItem (dialog, IDC_THEME_THEMECOMBO),
520 CB_GETCURSEL, 0, 0);
521 colorIndex = SendMessageW (GetDlgItem (dialog, IDC_THEME_COLORCOMBO),
522 CB_GETCURSEL, 0, 0);
523 sizeIndex = SendMessageW (GetDlgItem (dialog, IDC_THEME_SIZECOMBO),
524 CB_GETCURSEL, 0, 0);
526 do_apply_theme (dialog, themeIndex, colorIndex, sizeIndex);
527 theme_dirty = FALSE;
530 static struct
532 int sm_idx, color_idx;
533 const WCHAR *color_reg;
534 int size;
535 COLORREF color;
536 LOGFONTW lf;
537 } metrics[] =
539 {-1, COLOR_BTNFACE, L"ButtonFace" }, /* IDC_SYSPARAMS_BUTTON */
540 {-1, COLOR_BTNTEXT, L"ButtonText" }, /* IDC_SYSPARAMS_BUTTON_TEXT */
541 {-1, COLOR_BACKGROUND, L"Background" }, /* IDC_SYSPARAMS_DESKTOP */
542 {SM_CXMENUSIZE, COLOR_MENU, L"Menu" }, /* IDC_SYSPARAMS_MENU */
543 {-1, COLOR_MENUTEXT, L"MenuText" }, /* IDC_SYSPARAMS_MENU_TEXT */
544 {SM_CXVSCROLL, COLOR_SCROLLBAR, L"Scrollbar" }, /* IDC_SYSPARAMS_SCROLLBAR */
545 {-1, COLOR_HIGHLIGHT, L"Hilight" }, /* IDC_SYSPARAMS_SELECTION */
546 {-1, COLOR_HIGHLIGHTTEXT, L"HilightText" }, /* IDC_SYSPARAMS_SELECTION_TEXT */
547 {-1, COLOR_INFOBK, L"InfoWindow" }, /* IDC_SYSPARAMS_TOOLTIP */
548 {-1, COLOR_INFOTEXT, L"InfoText" }, /* IDC_SYSPARAMS_TOOLTIP_TEXT */
549 {-1, COLOR_WINDOW, L"Window" }, /* IDC_SYSPARAMS_WINDOW */
550 {-1, COLOR_WINDOWTEXT, L"WindowText" }, /* IDC_SYSPARAMS_WINDOW_TEXT */
551 {SM_CYSIZE, COLOR_ACTIVECAPTION, L"ActiveTitle" }, /* IDC_SYSPARAMS_ACTIVE_TITLE */
552 {-1, COLOR_CAPTIONTEXT, L"TitleText" }, /* IDC_SYSPARAMS_ACTIVE_TITLE_TEXT */
553 {-1, COLOR_INACTIVECAPTION, L"InactiveTitle" }, /* IDC_SYSPARAMS_INACTIVE_TITLE */
554 {-1, COLOR_INACTIVECAPTIONTEXT,L"InactiveTitleText" }, /* IDC_SYSPARAMS_INACTIVE_TITLE_TEXT */
555 {-1, -1, L"MsgBoxText" }, /* IDC_SYSPARAMS_MSGBOX_TEXT */
556 {-1, COLOR_APPWORKSPACE, L"AppWorkSpace" }, /* IDC_SYSPARAMS_APPWORKSPACE */
557 {-1, COLOR_WINDOWFRAME, L"WindowFrame" }, /* IDC_SYSPARAMS_WINDOW_FRAME */
558 {-1, COLOR_ACTIVEBORDER, L"ActiveBorder" }, /* IDC_SYSPARAMS_ACTIVE_BORDER */
559 {-1, COLOR_INACTIVEBORDER, L"InactiveBorder" }, /* IDC_SYSPARAMS_INACTIVE_BORDER */
560 {-1, COLOR_BTNSHADOW, L"ButtonShadow" }, /* IDC_SYSPARAMS_BUTTON_SHADOW */
561 {-1, COLOR_GRAYTEXT, L"GrayText" }, /* IDC_SYSPARAMS_GRAY_TEXT */
562 {-1, COLOR_BTNHIGHLIGHT, L"ButtonHilight" }, /* IDC_SYSPARAMS_BUTTON_HIGHLIGHT */
563 {-1, COLOR_3DDKSHADOW, L"ButtonDkShadow" }, /* IDC_SYSPARAMS_BUTTON_DARK_SHADOW */
564 {-1, COLOR_3DLIGHT, L"ButtonLight" }, /* IDC_SYSPARAMS_BUTTON_LIGHT */
565 {-1, COLOR_ALTERNATEBTNFACE, L"ButtonAlternateFace" }, /* IDC_SYSPARAMS_BUTTON_ALTERNATE */
566 {-1, COLOR_HOTLIGHT, L"HotTrackingColor" }, /* IDC_SYSPARAMS_HOT_TRACKING */
567 {-1, COLOR_GRADIENTACTIVECAPTION, L"GradientActiveTitle" }, /* IDC_SYSPARAMS_ACTIVE_TITLE_GRADIENT */
568 {-1, COLOR_GRADIENTINACTIVECAPTION, L"GradientInactiveTitle" }, /* IDC_SYSPARAMS_INACTIVE_TITLE_GRADIENT */
569 {-1, COLOR_MENUHILIGHT, L"MenuHilight" }, /* IDC_SYSPARAMS_MENU_HIGHLIGHT */
570 {-1, COLOR_MENUBAR, L"MenuBar" }, /* IDC_SYSPARAMS_MENUBAR */
573 static void save_sys_color(int idx, COLORREF clr)
575 WCHAR buffer[13];
577 swprintf(buffer, ARRAY_SIZE(buffer), L"%d %d %d", GetRValue (clr), GetGValue (clr), GetBValue (clr));
578 set_reg_key(HKEY_CURRENT_USER, L"Control Panel\\Colors", metrics[idx].color_reg, buffer);
581 static void set_color_from_theme(const WCHAR *keyName, COLORREF color)
583 int i;
585 for (i=0; i < ARRAY_SIZE(metrics); i++)
587 if (wcsicmp(metrics[i].color_reg, keyName)==0)
589 metrics[i].color = color;
590 save_sys_color(i, color);
591 break;
596 static void do_parse_theme(WCHAR *file)
598 WCHAR *keyName, keyNameValue[MAX_PATH];
599 DWORD len, allocLen = 512;
600 WCHAR *keyNamePtr = NULL;
601 int red = 0, green = 0, blue = 0;
602 COLORREF color;
604 WINE_TRACE("%s\n", wine_dbgstr_w(file));
605 keyName = malloc(sizeof(*keyName) * allocLen);
606 for (;;)
608 assert(keyName);
609 len = GetPrivateProfileStringW(L"Control Panel\\Colors", NULL, NULL, keyName,
610 allocLen, file);
611 if (len < allocLen - 2)
612 break;
614 allocLen *= 2;
615 keyName = realloc(keyName, sizeof(*keyName) * allocLen);
618 keyNamePtr = keyName;
619 while (*keyNamePtr!=0) {
620 GetPrivateProfileStringW(L"Control Panel\\Colors", keyNamePtr, NULL, keyNameValue,
621 MAX_PATH, file);
623 WINE_TRACE("parsing key: %s with value: %s\n",
624 wine_dbgstr_w(keyNamePtr), wine_dbgstr_w(keyNameValue));
626 swscanf(keyNameValue, L"%d %d %d", &red, &green, &blue);
628 color = RGB((BYTE)red, (BYTE)green, (BYTE)blue);
629 set_color_from_theme(keyNamePtr, color);
631 keyNamePtr+=lstrlenW(keyNamePtr);
632 keyNamePtr++;
634 free(keyName);
637 static void on_theme_install(HWND dialog)
639 static const WCHAR filterMask[] = L"\0*.msstyles;*.theme\0";
640 OPENFILENAMEW ofn;
641 WCHAR filetitle[MAX_PATH];
642 WCHAR file[MAX_PATH];
643 WCHAR filter[100];
644 WCHAR title[100];
646 LoadStringW(GetModuleHandleW(NULL), IDS_THEMEFILE, filter, ARRAY_SIZE(filter) - ARRAY_SIZE(filterMask));
647 memcpy(filter + lstrlenW (filter), filterMask, sizeof(filterMask));
648 LoadStringW(GetModuleHandleW(NULL), IDS_THEMEFILE_SELECT, title, ARRAY_SIZE(title));
650 ofn.lStructSize = sizeof(OPENFILENAMEW);
651 ofn.hwndOwner = dialog;
652 ofn.hInstance = 0;
653 ofn.lpstrFilter = filter;
654 ofn.lpstrCustomFilter = NULL;
655 ofn.nMaxCustFilter = 0;
656 ofn.nFilterIndex = 0;
657 ofn.lpstrFile = file;
658 ofn.lpstrFile[0] = '\0';
659 ofn.nMaxFile = ARRAY_SIZE(file);
660 ofn.lpstrFileTitle = filetitle;
661 ofn.lpstrFileTitle[0] = '\0';
662 ofn.nMaxFileTitle = ARRAY_SIZE(filetitle);
663 ofn.lpstrInitialDir = NULL;
664 ofn.lpstrTitle = title;
665 ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_ENABLESIZING;
666 ofn.nFileOffset = 0;
667 ofn.nFileExtension = 0;
668 ofn.lpstrDefExt = NULL;
669 ofn.lCustData = 0;
670 ofn.lpfnHook = NULL;
671 ofn.lpTemplateName = NULL;
673 if (GetOpenFileNameW(&ofn))
675 WCHAR themeFilePath[MAX_PATH];
676 SHFILEOPSTRUCTW shfop;
678 if (FAILED (SHGetFolderPathW (NULL, CSIDL_RESOURCES|CSIDL_FLAG_CREATE, NULL,
679 SHGFP_TYPE_CURRENT, themeFilePath))) return;
681 if (lstrcmpiW(PathFindExtensionW(filetitle), L".theme")==0)
683 do_parse_theme(file);
684 SendMessageW(GetParent(dialog), PSM_CHANGED, 0, 0);
685 return;
688 PathRemoveExtensionW (filetitle);
690 /* Construct path into which the theme file goes */
691 lstrcatW (themeFilePath, L"\\themes\\");
692 lstrcatW (themeFilePath, filetitle);
694 /* Create the directory */
695 SHCreateDirectoryExW (dialog, themeFilePath, NULL);
697 /* Append theme file name itself */
698 lstrcatW (themeFilePath, L"\\");
699 lstrcatW (themeFilePath, PathFindFileNameW (file));
700 /* SHFileOperation() takes lists as input, so double-nullterminate */
701 themeFilePath[lstrlenW (themeFilePath)+1] = 0;
702 file[lstrlenW (file)+1] = 0;
704 /* Do the copying */
705 WINE_TRACE("copying: %s -> %s\n", wine_dbgstr_w (file),
706 wine_dbgstr_w (themeFilePath));
707 shfop.hwnd = dialog;
708 shfop.wFunc = FO_COPY;
709 shfop.pFrom = file;
710 shfop.pTo = themeFilePath;
711 shfop.fFlags = FOF_NOCONFIRMMKDIR;
712 if (SHFileOperationW (&shfop) == 0)
714 scan_theme_files();
715 if (!fill_theme_list (GetDlgItem (dialog, IDC_THEME_THEMECOMBO),
716 GetDlgItem (dialog, IDC_THEME_COLORCOMBO),
717 GetDlgItem (dialog, IDC_THEME_SIZECOMBO)))
719 SendMessageW (GetDlgItem (dialog, IDC_THEME_COLORCOMBO), CB_SETCURSEL, -1, 0);
720 SendMessageW (GetDlgItem (dialog, IDC_THEME_SIZECOMBO), CB_SETCURSEL, -1, 0);
721 enable_size_and_color_controls (dialog, FALSE);
723 else
725 enable_size_and_color_controls (dialog, TRUE);
728 else
729 WINE_TRACE("copy operation failed\n");
731 else WINE_TRACE("user cancelled\n");
734 /* Information about symbolic link targets of certain User Shell Folders. */
735 struct ShellFolderInfo {
736 int nFolder;
737 char szLinkTarget[FILENAME_MAX]; /* in unix locale */
740 #define CSIDL_DOWNLOADS 0x0047
742 static struct ShellFolderInfo asfiInfo[] = {
743 { CSIDL_DESKTOP, "" },
744 { CSIDL_PERSONAL, "" },
745 { CSIDL_MYPICTURES, "" },
746 { CSIDL_MYMUSIC, "" },
747 { CSIDL_MYVIDEO, "" },
748 { CSIDL_DOWNLOADS, "" },
749 { CSIDL_TEMPLATES, "" }
752 static struct ShellFolderInfo *psfiSelected = NULL;
754 static void init_shell_folder_listview_headers(HWND dialog) {
755 LVCOLUMNW listColumn;
756 RECT viewRect;
757 WCHAR szShellFolder[64] = L"Shell Folder";
758 WCHAR szLinksTo[64] = L"Links to";
759 int width;
761 LoadStringW(GetModuleHandleW(NULL), IDS_SHELL_FOLDER, szShellFolder, ARRAY_SIZE(szShellFolder));
762 LoadStringW(GetModuleHandleW(NULL), IDS_LINKS_TO, szLinksTo, ARRAY_SIZE(szLinksTo));
764 GetClientRect(GetDlgItem(dialog, IDC_LIST_SFPATHS), &viewRect);
765 width = (viewRect.right - viewRect.left) / 3;
767 listColumn.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
768 listColumn.pszText = szShellFolder;
769 listColumn.cchTextMax = lstrlenW(listColumn.pszText);
770 listColumn.cx = width;
772 SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_INSERTCOLUMNW, 0, (LPARAM) &listColumn);
774 listColumn.pszText = szLinksTo;
775 listColumn.cchTextMax = lstrlenW(listColumn.pszText);
776 listColumn.cx = viewRect.right - viewRect.left - width - 1;
778 SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_INSERTCOLUMNW, 1, (LPARAM) &listColumn);
781 /* Reads the currently set shell folder symbol link targets into asfiInfo. */
782 static void read_shell_folder_link_targets(void) {
783 WCHAR wszPath[MAX_PATH];
784 int i;
786 for (i=0; i<ARRAY_SIZE(asfiInfo); i++) {
787 asfiInfo[i].szLinkTarget[0] = '\0';
788 if (SUCCEEDED( SHGetFolderPathW( NULL, asfiInfo[i].nFolder | CSIDL_FLAG_DONT_VERIFY, NULL,
789 SHGFP_TYPE_CURRENT, wszPath )))
790 query_shell_folder( wszPath, asfiInfo[i].szLinkTarget, FILENAME_MAX );
794 static void update_shell_folder_listview(HWND dialog) {
795 int i;
796 LVITEMW item;
797 LONG lSelected = SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_GETNEXTITEM, -1,
798 MAKELPARAM(LVNI_SELECTED,0));
800 SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_DELETEALLITEMS, 0, 0);
802 for (i=0; i<ARRAY_SIZE(asfiInfo); i++) {
803 WCHAR buffer[MAX_PATH];
804 HRESULT hr;
805 LPITEMIDLIST pidlCurrent;
807 /* Some acrobatic to get the localized name of the shell folder */
808 hr = SHGetFolderLocation(dialog, asfiInfo[i].nFolder, NULL, 0, &pidlCurrent);
809 if (SUCCEEDED(hr)) {
810 LPSHELLFOLDER psfParent;
811 LPCITEMIDLIST pidlLast;
812 hr = SHBindToParent(pidlCurrent, &IID_IShellFolder, (LPVOID*)&psfParent, &pidlLast);
813 if (SUCCEEDED(hr)) {
814 STRRET strRet;
815 hr = IShellFolder_GetDisplayNameOf(psfParent, pidlLast, SHGDN_FORADDRESSBAR, &strRet);
816 if (SUCCEEDED(hr)) {
817 hr = StrRetToBufW(&strRet, pidlLast, buffer, MAX_PATH);
819 IShellFolder_Release(psfParent);
821 ILFree(pidlCurrent);
824 /* If there's a dangling symlink for the current shell folder, SHGetFolderLocation
825 * will fail above. We fall back to the (non-verified) path of the shell folder. */
826 if (FAILED(hr)) {
827 hr = SHGetFolderPathW(dialog, asfiInfo[i].nFolder|CSIDL_FLAG_DONT_VERIFY, NULL,
828 SHGFP_TYPE_CURRENT, buffer);
831 item.mask = LVIF_TEXT | LVIF_PARAM;
832 item.iItem = i;
833 item.iSubItem = 0;
834 item.pszText = buffer;
835 item.lParam = (LPARAM)&asfiInfo[i];
836 SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_INSERTITEMW, 0, (LPARAM)&item);
838 item.mask = LVIF_TEXT;
839 item.iItem = i;
840 item.iSubItem = 1;
841 item.pszText = strdupU2W(asfiInfo[i].szLinkTarget);
842 SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_SETITEMW, 0, (LPARAM)&item);
843 free(item.pszText);
846 /* Ensure that the previously selected item is selected again. */
847 if (lSelected >= 0) {
848 item.mask = LVIF_STATE;
849 item.state = LVIS_SELECTED;
850 item.stateMask = LVIS_SELECTED;
851 SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_SETITEMSTATE, lSelected, (LPARAM)&item);
855 static void on_shell_folder_selection_changed(HWND hDlg, LPNMLISTVIEW lpnm) {
856 if (lpnm->uNewState & LVIS_SELECTED) {
857 psfiSelected = (struct ShellFolderInfo *)lpnm->lParam;
858 EnableWindow(GetDlgItem(hDlg, IDC_LINK_SFPATH), 1);
859 if (*psfiSelected->szLinkTarget) {
860 WCHAR *link;
861 CheckDlgButton(hDlg, IDC_LINK_SFPATH, BST_CHECKED);
862 EnableWindow(GetDlgItem(hDlg, IDC_EDIT_SFPATH), 1);
863 EnableWindow(GetDlgItem(hDlg, IDC_BROWSE_SFPATH), 1);
864 link = strdupU2W(psfiSelected->szLinkTarget);
865 set_textW(hDlg, IDC_EDIT_SFPATH, link);
866 free(link);
867 } else {
868 CheckDlgButton(hDlg, IDC_LINK_SFPATH, BST_UNCHECKED);
869 EnableWindow(GetDlgItem(hDlg, IDC_EDIT_SFPATH), 0);
870 EnableWindow(GetDlgItem(hDlg, IDC_BROWSE_SFPATH), 0);
871 set_text(hDlg, IDC_EDIT_SFPATH, "");
873 } else {
874 psfiSelected = NULL;
875 CheckDlgButton(hDlg, IDC_LINK_SFPATH, BST_UNCHECKED);
876 set_text(hDlg, IDC_EDIT_SFPATH, "");
877 EnableWindow(GetDlgItem(hDlg, IDC_LINK_SFPATH), 0);
878 EnableWindow(GetDlgItem(hDlg, IDC_EDIT_SFPATH), 0);
879 EnableWindow(GetDlgItem(hDlg, IDC_BROWSE_SFPATH), 0);
883 /* Keep the contents of the edit control, the listview control and the symlink
884 * information in sync. */
885 static void on_shell_folder_edit_changed(HWND hDlg) {
886 LVITEMW item;
887 WCHAR *text = get_text(hDlg, IDC_EDIT_SFPATH);
888 LONG iSel = SendDlgItemMessageW(hDlg, IDC_LIST_SFPATHS, LVM_GETNEXTITEM, -1,
889 MAKELPARAM(LVNI_SELECTED,0));
891 if (!text || !psfiSelected || iSel < 0) {
892 free(text);
893 return;
896 WideCharToMultiByte(CP_UNIXCP, 0, text, -1,
897 psfiSelected->szLinkTarget, FILENAME_MAX, NULL, NULL);
899 item.mask = LVIF_TEXT;
900 item.iItem = iSel;
901 item.iSubItem = 1;
902 item.pszText = text;
903 SendDlgItemMessageW(hDlg, IDC_LIST_SFPATHS, LVM_SETITEMW, 0, (LPARAM)&item);
905 free(text);
907 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
910 static void apply_shell_folder_changes(void) {
911 WCHAR wszPath[MAX_PATH];
912 int i;
914 for (i=0; i<ARRAY_SIZE(asfiInfo); i++) {
915 if (SUCCEEDED( SHGetFolderPathW( NULL, asfiInfo[i].nFolder | CSIDL_FLAG_CREATE, NULL,
916 SHGFP_TYPE_CURRENT, wszPath )))
917 set_shell_folder( wszPath, asfiInfo[i].szLinkTarget );
921 static void refresh_sysparams(HWND hDlg)
923 int i;
925 for (i = 0; i < ARRAY_SIZE(metrics); i++)
927 if (metrics[i].sm_idx != -1)
928 metrics[i].size = GetSystemMetrics(metrics[i].sm_idx);
929 if (metrics[i].color_idx != -1)
930 metrics[i].color = GetSysColor(metrics[i].color_idx);
933 on_sysparam_change(hDlg);
936 static void read_sysparams(HWND hDlg)
938 WCHAR buffer[256];
939 HWND list = GetDlgItem(hDlg, IDC_SYSPARAM_COMBO);
940 NONCLIENTMETRICSW nonclient_metrics;
941 int i, idx;
943 for (i = 0; i < ARRAY_SIZE(metrics); i++)
945 LoadStringW(GetModuleHandleW(NULL), i + IDC_SYSPARAMS_BUTTON, buffer, ARRAY_SIZE(buffer));
946 idx = SendMessageW(list, CB_ADDSTRING, 0, (LPARAM)buffer);
947 if (idx != CB_ERR) SendMessageW(list, CB_SETITEMDATA, idx, i);
949 if (metrics[i].sm_idx != -1)
950 metrics[i].size = GetSystemMetrics(metrics[i].sm_idx);
951 if (metrics[i].color_idx != -1)
952 metrics[i].color = GetSysColor(metrics[i].color_idx);
955 nonclient_metrics.cbSize = sizeof(NONCLIENTMETRICSW);
956 SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSW), &nonclient_metrics, 0);
958 memcpy(&(metrics[IDC_SYSPARAMS_MENU_TEXT - IDC_SYSPARAMS_BUTTON].lf),
959 &(nonclient_metrics.lfMenuFont), sizeof(LOGFONTW));
960 memcpy(&(metrics[IDC_SYSPARAMS_ACTIVE_TITLE_TEXT - IDC_SYSPARAMS_BUTTON].lf),
961 &(nonclient_metrics.lfCaptionFont), sizeof(LOGFONTW));
962 memcpy(&(metrics[IDC_SYSPARAMS_TOOLTIP_TEXT - IDC_SYSPARAMS_BUTTON].lf),
963 &(nonclient_metrics.lfStatusFont), sizeof(LOGFONTW));
964 memcpy(&(metrics[IDC_SYSPARAMS_MSGBOX_TEXT - IDC_SYSPARAMS_BUTTON].lf),
965 &(nonclient_metrics.lfMessageFont), sizeof(LOGFONTW));
968 static void apply_sysparams(void)
970 NONCLIENTMETRICSW ncm;
971 int i, cnt = 0;
972 int colors_idx[ARRAY_SIZE(metrics)];
973 COLORREF colors[ARRAY_SIZE(metrics)];
974 HDC hdc;
975 int dpi;
977 hdc = GetDC( 0 );
978 dpi = GetDeviceCaps( hdc, LOGPIXELSY );
979 ReleaseDC( 0, hdc );
981 ncm.cbSize = sizeof(ncm);
982 SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0);
984 /* convert metrics back to twips */
985 ncm.iMenuWidth = ncm.iMenuHeight =
986 MulDiv( metrics[IDC_SYSPARAMS_MENU - IDC_SYSPARAMS_BUTTON].size, -1440, dpi );
987 ncm.iCaptionWidth = ncm.iCaptionHeight =
988 MulDiv( metrics[IDC_SYSPARAMS_ACTIVE_TITLE - IDC_SYSPARAMS_BUTTON].size, -1440, dpi );
989 ncm.iScrollWidth = ncm.iScrollHeight =
990 MulDiv( metrics[IDC_SYSPARAMS_SCROLLBAR - IDC_SYSPARAMS_BUTTON].size, -1440, dpi );
991 ncm.iSmCaptionWidth = MulDiv( ncm.iSmCaptionWidth, -1440, dpi );
992 ncm.iSmCaptionHeight = MulDiv( ncm.iSmCaptionHeight, -1440, dpi );
994 ncm.lfMenuFont = metrics[IDC_SYSPARAMS_MENU_TEXT - IDC_SYSPARAMS_BUTTON].lf;
995 ncm.lfCaptionFont = metrics[IDC_SYSPARAMS_ACTIVE_TITLE_TEXT - IDC_SYSPARAMS_BUTTON].lf;
996 ncm.lfStatusFont = metrics[IDC_SYSPARAMS_TOOLTIP_TEXT - IDC_SYSPARAMS_BUTTON].lf;
997 ncm.lfMessageFont = metrics[IDC_SYSPARAMS_MSGBOX_TEXT - IDC_SYSPARAMS_BUTTON].lf;
999 SystemParametersInfoW(SPI_SETNONCLIENTMETRICS, sizeof(ncm), &ncm,
1000 SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
1002 for (i = 0; i < ARRAY_SIZE(metrics); i++)
1003 if (metrics[i].color_idx != -1)
1005 colors_idx[cnt] = metrics[i].color_idx;
1006 colors[cnt++] = metrics[i].color;
1008 SetSysColors(cnt, colors_idx, colors);
1011 static void on_sysparam_change(HWND hDlg)
1013 int index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETCURSEL, 0, 0);
1015 index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETITEMDATA, index, 0);
1017 updating_ui = TRUE;
1019 EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_COLOR_TEXT), metrics[index].color_idx != -1);
1020 EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_COLOR), metrics[index].color_idx != -1);
1021 InvalidateRect(GetDlgItem(hDlg, IDC_SYSPARAM_COLOR), NULL, TRUE);
1023 EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_SIZE_TEXT), metrics[index].sm_idx != -1);
1024 EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_SIZE), metrics[index].sm_idx != -1);
1025 EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_SIZE_UD), metrics[index].sm_idx != -1);
1026 if (metrics[index].sm_idx != -1)
1027 SendDlgItemMessageW(hDlg, IDC_SYSPARAM_SIZE_UD, UDM_SETPOS, 0, MAKELONG(metrics[index].size, 0));
1028 else
1029 set_text(hDlg, IDC_SYSPARAM_SIZE, "");
1031 EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_FONT),
1032 index == IDC_SYSPARAMS_MENU_TEXT-IDC_SYSPARAMS_BUTTON ||
1033 index == IDC_SYSPARAMS_ACTIVE_TITLE_TEXT-IDC_SYSPARAMS_BUTTON ||
1034 index == IDC_SYSPARAMS_TOOLTIP_TEXT-IDC_SYSPARAMS_BUTTON ||
1035 index == IDC_SYSPARAMS_MSGBOX_TEXT-IDC_SYSPARAMS_BUTTON
1038 updating_ui = FALSE;
1041 static void on_draw_item(HWND hDlg, WPARAM wParam, LPARAM lParam)
1043 static HBRUSH black_brush = 0;
1044 LPDRAWITEMSTRUCT draw_info = (LPDRAWITEMSTRUCT)lParam;
1046 if (!black_brush) black_brush = CreateSolidBrush(0);
1048 if (draw_info->CtlID == IDC_SYSPARAM_COLOR)
1050 UINT state;
1051 HTHEME theme;
1052 RECT buttonrect;
1054 theme = OpenThemeDataForDpi(NULL, WC_BUTTONW, GetDpiForWindow(hDlg));
1056 if (theme) {
1057 MARGINS margins;
1059 if (draw_info->itemState & ODS_DISABLED)
1060 state = PBS_DISABLED;
1061 else if (draw_info->itemState & ODS_SELECTED)
1062 state = PBS_PRESSED;
1063 else
1064 state = PBS_NORMAL;
1066 if (IsThemeBackgroundPartiallyTransparent(theme, BP_PUSHBUTTON, state))
1067 DrawThemeParentBackground(draw_info->hwndItem, draw_info->hDC, NULL);
1069 DrawThemeBackground(theme, draw_info->hDC, BP_PUSHBUTTON, state, &draw_info->rcItem, NULL);
1071 buttonrect = draw_info->rcItem;
1073 GetThemeMargins(theme, draw_info->hDC, BP_PUSHBUTTON, state, TMT_CONTENTMARGINS, &draw_info->rcItem, &margins);
1075 buttonrect.left += margins.cxLeftWidth;
1076 buttonrect.top += margins.cyTopHeight;
1077 buttonrect.right -= margins.cxRightWidth;
1078 buttonrect.bottom -= margins.cyBottomHeight;
1080 if (draw_info->itemState & ODS_FOCUS)
1081 DrawFocusRect(draw_info->hDC, &buttonrect);
1083 CloseThemeData(theme);
1084 } else {
1085 state = DFCS_ADJUSTRECT | DFCS_BUTTONPUSH;
1087 if (draw_info->itemState & ODS_DISABLED)
1088 state |= DFCS_INACTIVE;
1089 else
1090 state |= draw_info->itemState & ODS_SELECTED ? DFCS_PUSHED : 0;
1092 DrawFrameControl(draw_info->hDC, &draw_info->rcItem, DFC_BUTTON, state);
1094 buttonrect = draw_info->rcItem;
1097 if (!(draw_info->itemState & ODS_DISABLED))
1099 HBRUSH brush;
1100 int index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETCURSEL, 0, 0);
1102 index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETITEMDATA, index, 0);
1103 brush = CreateSolidBrush(metrics[index].color);
1105 InflateRect(&buttonrect, -1, -1);
1106 FrameRect(draw_info->hDC, &buttonrect, black_brush);
1107 InflateRect(&buttonrect, -1, -1);
1108 FillRect(draw_info->hDC, &buttonrect, brush);
1109 DeleteObject(brush);
1114 static void on_select_font(HWND hDlg)
1116 CHOOSEFONTW cf;
1117 int index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETCURSEL, 0, 0);
1118 index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETITEMDATA, index, 0);
1120 ZeroMemory(&cf, sizeof(cf));
1121 cf.lStructSize = sizeof(CHOOSEFONTW);
1122 cf.hwndOwner = hDlg;
1123 cf.lpLogFont = &(metrics[index].lf);
1124 cf.Flags = CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT | CF_NOSCRIPTSEL | CF_NOVERTFONTS;
1126 if (ChooseFontW(&cf))
1127 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1130 static void init_mime_types(HWND hDlg)
1132 WCHAR *buf = get_reg_key(config_key, keypath(L"FileOpenAssociations"), L"Enable", L"Y");
1133 int state = IS_OPTION_TRUE(*buf) ? BST_CHECKED : BST_UNCHECKED;
1135 CheckDlgButton(hDlg, IDC_ENABLE_FILE_ASSOCIATIONS, state);
1137 free(buf);
1140 static void update_mime_types(HWND hDlg)
1142 const WCHAR *state = L"Y";
1144 if (IsDlgButtonChecked(hDlg, IDC_ENABLE_FILE_ASSOCIATIONS) != BST_CHECKED)
1145 state = L"N";
1147 set_reg_key(config_key, keypath(L"FileOpenAssociations"), L"Enable", state);
1150 static BOOL CALLBACK update_window_pos_proc(HWND hwnd, LPARAM lp)
1152 RECT rect;
1154 GetClientRect(hwnd, &rect);
1155 AdjustWindowRectEx(&rect, GetWindowLongW(hwnd, GWL_STYLE), !!GetMenu(hwnd),
1156 GetWindowLongW(hwnd, GWL_EXSTYLE));
1157 SetWindowPos(hwnd, 0, 0, 0, rect.right - rect.left, rect.bottom - rect.top,
1158 SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
1159 return TRUE;
1162 /* Adjust the rectangle for top-level windows because the new non-client metrics may be different */
1163 static void update_window_pos(void)
1165 EnumWindows(update_window_pos_proc, 0);
1168 INT_PTR CALLBACK
1169 ThemeDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1171 switch (uMsg) {
1172 case WM_INITDIALOG:
1173 read_shell_folder_link_targets();
1174 init_shell_folder_listview_headers(hDlg);
1175 update_shell_folder_listview(hDlg);
1176 read_sysparams(hDlg);
1177 init_mime_types(hDlg);
1178 init_dialog(hDlg);
1179 break;
1181 case WM_DESTROY:
1182 free_theme_files();
1183 break;
1185 case WM_SHOWWINDOW:
1186 set_window_title(hDlg);
1187 break;
1189 case WM_COMMAND:
1190 switch(HIWORD(wParam)) {
1191 case CBN_SELCHANGE: {
1192 if (updating_ui) break;
1193 switch (LOWORD(wParam))
1195 case IDC_THEME_APPCOMBO: /* fall through */
1196 case IDC_THEME_THEMECOMBO: on_theme_changed(hDlg); break;
1197 case IDC_THEME_COLORCOMBO: /* fall through */
1198 case IDC_THEME_SIZECOMBO: theme_dirty = TRUE; break;
1199 case IDC_SYSPARAM_COMBO: on_sysparam_change(hDlg); return FALSE;
1201 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1202 break;
1204 case EN_CHANGE: {
1205 if (updating_ui) break;
1206 switch (LOWORD(wParam))
1208 case IDC_EDIT_SFPATH: on_shell_folder_edit_changed(hDlg); break;
1209 case IDC_SYSPARAM_SIZE:
1211 WCHAR *text = get_text(hDlg, IDC_SYSPARAM_SIZE);
1212 int index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETCURSEL, 0, 0);
1214 index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETITEMDATA, index, 0);
1216 if (text)
1218 metrics[index].size = wcstol(text, NULL, 10);
1219 free(text);
1221 else
1223 /* for empty string set to minimum value */
1224 SendDlgItemMessageW(hDlg, IDC_SYSPARAM_SIZE_UD, UDM_GETRANGE32, (WPARAM)&metrics[index].size, 0);
1227 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1228 break;
1231 break;
1233 case BN_CLICKED:
1234 switch (LOWORD(wParam))
1236 case IDC_THEME_INSTALL:
1237 on_theme_install (hDlg);
1238 break;
1240 case IDC_SYSPARAM_FONT:
1241 on_select_font(hDlg);
1242 break;
1244 case IDC_BROWSE_SFPATH:
1246 WCHAR link[FILENAME_MAX];
1247 if (browse_for_unix_folder(hDlg, link)) {
1248 WideCharToMultiByte(CP_UNIXCP, 0, link, -1,
1249 psfiSelected->szLinkTarget, FILENAME_MAX,
1250 NULL, NULL);
1251 update_shell_folder_listview(hDlg);
1252 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1254 break;
1257 case IDC_LINK_SFPATH:
1258 if (IsDlgButtonChecked(hDlg, IDC_LINK_SFPATH)) {
1259 WCHAR link[FILENAME_MAX];
1260 if (browse_for_unix_folder(hDlg, link)) {
1261 WideCharToMultiByte(CP_UNIXCP, 0, link, -1,
1262 psfiSelected->szLinkTarget, FILENAME_MAX,
1263 NULL, NULL);
1264 update_shell_folder_listview(hDlg);
1265 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1266 } else {
1267 CheckDlgButton(hDlg, IDC_LINK_SFPATH, BST_UNCHECKED);
1269 } else {
1270 psfiSelected->szLinkTarget[0] = '\0';
1271 update_shell_folder_listview(hDlg);
1272 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1274 break;
1276 case IDC_SYSPARAM_COLOR:
1278 static COLORREF user_colors[16];
1279 CHOOSECOLORW c_color;
1280 int index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETCURSEL, 0, 0);
1282 index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETITEMDATA, index, 0);
1284 memset(&c_color, 0, sizeof(c_color));
1285 c_color.lStructSize = sizeof(c_color);
1286 c_color.lpCustColors = user_colors;
1287 c_color.rgbResult = metrics[index].color;
1288 c_color.Flags = CC_ANYCOLOR | CC_RGBINIT;
1289 c_color.hwndOwner = hDlg;
1290 if (ChooseColorW(&c_color))
1292 metrics[index].color = c_color.rgbResult;
1293 save_sys_color(index, metrics[index].color);
1294 InvalidateRect(GetDlgItem(hDlg, IDC_SYSPARAM_COLOR), NULL, TRUE);
1295 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1297 break;
1300 case IDC_ENABLE_FILE_ASSOCIATIONS:
1301 update_mime_types(hDlg);
1302 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1303 break;
1305 break;
1307 break;
1309 case WM_NOTIFY:
1310 switch (((LPNMHDR)lParam)->code) {
1311 case PSN_KILLACTIVE: {
1312 SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, FALSE);
1313 break;
1315 case PSN_APPLY: {
1316 apply();
1317 apply_theme(hDlg);
1318 apply_shell_folder_changes();
1319 apply_sysparams();
1320 read_shell_folder_link_targets();
1321 update_shell_folder_listview(hDlg);
1322 update_mime_types(hDlg);
1323 update_window_pos();
1324 SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
1325 break;
1327 case LVN_ITEMCHANGED: {
1328 if (wParam == IDC_LIST_SFPATHS)
1329 on_shell_folder_selection_changed(hDlg, (LPNMLISTVIEW)lParam);
1330 break;
1332 case PSN_SETACTIVE: {
1333 update_dialog(hDlg);
1334 break;
1337 break;
1339 case WM_DRAWITEM:
1340 on_draw_item(hDlg, wParam, lParam);
1341 break;
1343 default:
1344 break;
1346 return FALSE;