mfplat: Only convert MEDIASUBTYPE for the formats which need it.
[wine.git] / programs / winecfg / theme.c
blobd52c127db0b46e2c7842ed7604c8a03af2b57951
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);
508 set_reg_key_dword(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
509 L"SystemUsesLightTheme", !index);
511 theme_dirty = TRUE;
514 static void apply_theme(HWND dialog)
516 int themeIndex, colorIndex, sizeIndex;
518 if (!theme_dirty) return;
520 themeIndex = SendMessageW (GetDlgItem (dialog, IDC_THEME_THEMECOMBO),
521 CB_GETCURSEL, 0, 0);
522 colorIndex = SendMessageW (GetDlgItem (dialog, IDC_THEME_COLORCOMBO),
523 CB_GETCURSEL, 0, 0);
524 sizeIndex = SendMessageW (GetDlgItem (dialog, IDC_THEME_SIZECOMBO),
525 CB_GETCURSEL, 0, 0);
527 do_apply_theme (dialog, themeIndex, colorIndex, sizeIndex);
528 theme_dirty = FALSE;
531 static struct
533 int sm_idx, color_idx;
534 const WCHAR *color_reg;
535 int size;
536 COLORREF color;
537 LOGFONTW lf;
538 } metrics[] =
540 {-1, COLOR_BTNFACE, L"ButtonFace" }, /* IDC_SYSPARAMS_BUTTON */
541 {-1, COLOR_BTNTEXT, L"ButtonText" }, /* IDC_SYSPARAMS_BUTTON_TEXT */
542 {-1, COLOR_BACKGROUND, L"Background" }, /* IDC_SYSPARAMS_DESKTOP */
543 {SM_CXMENUSIZE, COLOR_MENU, L"Menu" }, /* IDC_SYSPARAMS_MENU */
544 {-1, COLOR_MENUTEXT, L"MenuText" }, /* IDC_SYSPARAMS_MENU_TEXT */
545 {SM_CXVSCROLL, COLOR_SCROLLBAR, L"Scrollbar" }, /* IDC_SYSPARAMS_SCROLLBAR */
546 {-1, COLOR_HIGHLIGHT, L"Hilight" }, /* IDC_SYSPARAMS_SELECTION */
547 {-1, COLOR_HIGHLIGHTTEXT, L"HilightText" }, /* IDC_SYSPARAMS_SELECTION_TEXT */
548 {-1, COLOR_INFOBK, L"InfoWindow" }, /* IDC_SYSPARAMS_TOOLTIP */
549 {-1, COLOR_INFOTEXT, L"InfoText" }, /* IDC_SYSPARAMS_TOOLTIP_TEXT */
550 {-1, COLOR_WINDOW, L"Window" }, /* IDC_SYSPARAMS_WINDOW */
551 {-1, COLOR_WINDOWTEXT, L"WindowText" }, /* IDC_SYSPARAMS_WINDOW_TEXT */
552 {SM_CYSIZE, COLOR_ACTIVECAPTION, L"ActiveTitle" }, /* IDC_SYSPARAMS_ACTIVE_TITLE */
553 {-1, COLOR_CAPTIONTEXT, L"TitleText" }, /* IDC_SYSPARAMS_ACTIVE_TITLE_TEXT */
554 {-1, COLOR_INACTIVECAPTION, L"InactiveTitle" }, /* IDC_SYSPARAMS_INACTIVE_TITLE */
555 {-1, COLOR_INACTIVECAPTIONTEXT,L"InactiveTitleText" }, /* IDC_SYSPARAMS_INACTIVE_TITLE_TEXT */
556 {-1, -1, L"MsgBoxText" }, /* IDC_SYSPARAMS_MSGBOX_TEXT */
557 {-1, COLOR_APPWORKSPACE, L"AppWorkSpace" }, /* IDC_SYSPARAMS_APPWORKSPACE */
558 {-1, COLOR_WINDOWFRAME, L"WindowFrame" }, /* IDC_SYSPARAMS_WINDOW_FRAME */
559 {-1, COLOR_ACTIVEBORDER, L"ActiveBorder" }, /* IDC_SYSPARAMS_ACTIVE_BORDER */
560 {-1, COLOR_INACTIVEBORDER, L"InactiveBorder" }, /* IDC_SYSPARAMS_INACTIVE_BORDER */
561 {-1, COLOR_BTNSHADOW, L"ButtonShadow" }, /* IDC_SYSPARAMS_BUTTON_SHADOW */
562 {-1, COLOR_GRAYTEXT, L"GrayText" }, /* IDC_SYSPARAMS_GRAY_TEXT */
563 {-1, COLOR_BTNHIGHLIGHT, L"ButtonHilight" }, /* IDC_SYSPARAMS_BUTTON_HIGHLIGHT */
564 {-1, COLOR_3DDKSHADOW, L"ButtonDkShadow" }, /* IDC_SYSPARAMS_BUTTON_DARK_SHADOW */
565 {-1, COLOR_3DLIGHT, L"ButtonLight" }, /* IDC_SYSPARAMS_BUTTON_LIGHT */
566 {-1, COLOR_ALTERNATEBTNFACE, L"ButtonAlternateFace" }, /* IDC_SYSPARAMS_BUTTON_ALTERNATE */
567 {-1, COLOR_HOTLIGHT, L"HotTrackingColor" }, /* IDC_SYSPARAMS_HOT_TRACKING */
568 {-1, COLOR_GRADIENTACTIVECAPTION, L"GradientActiveTitle" }, /* IDC_SYSPARAMS_ACTIVE_TITLE_GRADIENT */
569 {-1, COLOR_GRADIENTINACTIVECAPTION, L"GradientInactiveTitle" }, /* IDC_SYSPARAMS_INACTIVE_TITLE_GRADIENT */
570 {-1, COLOR_MENUHILIGHT, L"MenuHilight" }, /* IDC_SYSPARAMS_MENU_HIGHLIGHT */
571 {-1, COLOR_MENUBAR, L"MenuBar" }, /* IDC_SYSPARAMS_MENUBAR */
574 static void save_sys_color(int idx, COLORREF clr)
576 WCHAR buffer[13];
578 swprintf(buffer, ARRAY_SIZE(buffer), L"%d %d %d", GetRValue (clr), GetGValue (clr), GetBValue (clr));
579 set_reg_key(HKEY_CURRENT_USER, L"Control Panel\\Colors", metrics[idx].color_reg, buffer);
582 static void set_color_from_theme(const WCHAR *keyName, COLORREF color)
584 int i;
586 for (i=0; i < ARRAY_SIZE(metrics); i++)
588 if (wcsicmp(metrics[i].color_reg, keyName)==0)
590 metrics[i].color = color;
591 save_sys_color(i, color);
592 break;
597 static void do_parse_theme(WCHAR *file)
599 WCHAR *keyName, keyNameValue[MAX_PATH];
600 DWORD len, allocLen = 512;
601 WCHAR *keyNamePtr = NULL;
602 int red = 0, green = 0, blue = 0;
603 COLORREF color;
605 WINE_TRACE("%s\n", wine_dbgstr_w(file));
606 keyName = malloc(sizeof(*keyName) * allocLen);
607 for (;;)
609 assert(keyName);
610 len = GetPrivateProfileStringW(L"Control Panel\\Colors", NULL, NULL, keyName,
611 allocLen, file);
612 if (len < allocLen - 2)
613 break;
615 allocLen *= 2;
616 keyName = realloc(keyName, sizeof(*keyName) * allocLen);
619 keyNamePtr = keyName;
620 while (*keyNamePtr!=0) {
621 GetPrivateProfileStringW(L"Control Panel\\Colors", keyNamePtr, NULL, keyNameValue,
622 MAX_PATH, file);
624 WINE_TRACE("parsing key: %s with value: %s\n",
625 wine_dbgstr_w(keyNamePtr), wine_dbgstr_w(keyNameValue));
627 swscanf(keyNameValue, L"%d %d %d", &red, &green, &blue);
629 color = RGB((BYTE)red, (BYTE)green, (BYTE)blue);
630 set_color_from_theme(keyNamePtr, color);
632 keyNamePtr+=lstrlenW(keyNamePtr);
633 keyNamePtr++;
635 free(keyName);
638 static void on_theme_install(HWND dialog)
640 static const WCHAR filterMask[] = L"\0*.msstyles;*.theme\0";
641 OPENFILENAMEW ofn;
642 WCHAR filetitle[MAX_PATH];
643 WCHAR file[MAX_PATH];
644 WCHAR filter[100];
645 WCHAR title[100];
647 LoadStringW(GetModuleHandleW(NULL), IDS_THEMEFILE, filter, ARRAY_SIZE(filter) - ARRAY_SIZE(filterMask));
648 memcpy(filter + lstrlenW (filter), filterMask, sizeof(filterMask));
649 LoadStringW(GetModuleHandleW(NULL), IDS_THEMEFILE_SELECT, title, ARRAY_SIZE(title));
651 ofn.lStructSize = sizeof(OPENFILENAMEW);
652 ofn.hwndOwner = dialog;
653 ofn.hInstance = 0;
654 ofn.lpstrFilter = filter;
655 ofn.lpstrCustomFilter = NULL;
656 ofn.nMaxCustFilter = 0;
657 ofn.nFilterIndex = 0;
658 ofn.lpstrFile = file;
659 ofn.lpstrFile[0] = '\0';
660 ofn.nMaxFile = ARRAY_SIZE(file);
661 ofn.lpstrFileTitle = filetitle;
662 ofn.lpstrFileTitle[0] = '\0';
663 ofn.nMaxFileTitle = ARRAY_SIZE(filetitle);
664 ofn.lpstrInitialDir = NULL;
665 ofn.lpstrTitle = title;
666 ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_ENABLESIZING;
667 ofn.nFileOffset = 0;
668 ofn.nFileExtension = 0;
669 ofn.lpstrDefExt = NULL;
670 ofn.lCustData = 0;
671 ofn.lpfnHook = NULL;
672 ofn.lpTemplateName = NULL;
674 if (GetOpenFileNameW(&ofn))
676 WCHAR themeFilePath[MAX_PATH];
677 SHFILEOPSTRUCTW shfop;
679 if (FAILED (SHGetFolderPathW (NULL, CSIDL_RESOURCES|CSIDL_FLAG_CREATE, NULL,
680 SHGFP_TYPE_CURRENT, themeFilePath))) return;
682 if (lstrcmpiW(PathFindExtensionW(filetitle), L".theme")==0)
684 do_parse_theme(file);
685 SendMessageW(GetParent(dialog), PSM_CHANGED, 0, 0);
686 return;
689 PathRemoveExtensionW (filetitle);
691 /* Construct path into which the theme file goes */
692 lstrcatW (themeFilePath, L"\\themes\\");
693 lstrcatW (themeFilePath, filetitle);
695 /* Create the directory */
696 SHCreateDirectoryExW (dialog, themeFilePath, NULL);
698 /* Append theme file name itself */
699 lstrcatW (themeFilePath, L"\\");
700 lstrcatW (themeFilePath, PathFindFileNameW (file));
701 /* SHFileOperation() takes lists as input, so double-nullterminate */
702 themeFilePath[lstrlenW (themeFilePath)+1] = 0;
703 file[lstrlenW (file)+1] = 0;
705 /* Do the copying */
706 WINE_TRACE("copying: %s -> %s\n", wine_dbgstr_w (file),
707 wine_dbgstr_w (themeFilePath));
708 shfop.hwnd = dialog;
709 shfop.wFunc = FO_COPY;
710 shfop.pFrom = file;
711 shfop.pTo = themeFilePath;
712 shfop.fFlags = FOF_NOCONFIRMMKDIR;
713 if (SHFileOperationW (&shfop) == 0)
715 scan_theme_files();
716 if (!fill_theme_list (GetDlgItem (dialog, IDC_THEME_THEMECOMBO),
717 GetDlgItem (dialog, IDC_THEME_COLORCOMBO),
718 GetDlgItem (dialog, IDC_THEME_SIZECOMBO)))
720 SendMessageW (GetDlgItem (dialog, IDC_THEME_COLORCOMBO), CB_SETCURSEL, -1, 0);
721 SendMessageW (GetDlgItem (dialog, IDC_THEME_SIZECOMBO), CB_SETCURSEL, -1, 0);
722 enable_size_and_color_controls (dialog, FALSE);
724 else
726 enable_size_and_color_controls (dialog, TRUE);
729 else
730 WINE_TRACE("copy operation failed\n");
732 else WINE_TRACE("user cancelled\n");
735 /* Information about symbolic link targets of certain User Shell Folders. */
736 struct ShellFolderInfo {
737 int nFolder;
738 char szLinkTarget[FILENAME_MAX]; /* in unix locale */
741 #define CSIDL_DOWNLOADS 0x0047
743 static struct ShellFolderInfo asfiInfo[] = {
744 { CSIDL_DESKTOP, "" },
745 { CSIDL_PERSONAL, "" },
746 { CSIDL_MYPICTURES, "" },
747 { CSIDL_MYMUSIC, "" },
748 { CSIDL_MYVIDEO, "" },
749 { CSIDL_DOWNLOADS, "" },
750 { CSIDL_TEMPLATES, "" }
753 static struct ShellFolderInfo *psfiSelected = NULL;
755 static void init_shell_folder_listview_headers(HWND dialog) {
756 LVCOLUMNW listColumn;
757 RECT viewRect;
758 WCHAR szShellFolder[64] = L"Shell Folder";
759 WCHAR szLinksTo[64] = L"Links to";
760 int width;
762 LoadStringW(GetModuleHandleW(NULL), IDS_SHELL_FOLDER, szShellFolder, ARRAY_SIZE(szShellFolder));
763 LoadStringW(GetModuleHandleW(NULL), IDS_LINKS_TO, szLinksTo, ARRAY_SIZE(szLinksTo));
765 GetClientRect(GetDlgItem(dialog, IDC_LIST_SFPATHS), &viewRect);
766 width = (viewRect.right - viewRect.left) / 3;
768 listColumn.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
769 listColumn.pszText = szShellFolder;
770 listColumn.cchTextMax = lstrlenW(listColumn.pszText);
771 listColumn.cx = width;
773 SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_INSERTCOLUMNW, 0, (LPARAM) &listColumn);
775 listColumn.pszText = szLinksTo;
776 listColumn.cchTextMax = lstrlenW(listColumn.pszText);
777 listColumn.cx = viewRect.right - viewRect.left - width - 1;
779 SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_INSERTCOLUMNW, 1, (LPARAM) &listColumn);
782 /* Reads the currently set shell folder symbol link targets into asfiInfo. */
783 static void read_shell_folder_link_targets(void) {
784 WCHAR wszPath[MAX_PATH];
785 int i;
787 for (i=0; i<ARRAY_SIZE(asfiInfo); i++) {
788 asfiInfo[i].szLinkTarget[0] = '\0';
789 if (SUCCEEDED( SHGetFolderPathW( NULL, asfiInfo[i].nFolder | CSIDL_FLAG_DONT_VERIFY, NULL,
790 SHGFP_TYPE_CURRENT, wszPath )))
791 query_shell_folder( wszPath, asfiInfo[i].szLinkTarget, FILENAME_MAX );
795 static void update_shell_folder_listview(HWND dialog) {
796 int i;
797 LVITEMW item;
798 LONG lSelected = SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_GETNEXTITEM, -1,
799 MAKELPARAM(LVNI_SELECTED,0));
801 SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_DELETEALLITEMS, 0, 0);
803 for (i=0; i<ARRAY_SIZE(asfiInfo); i++) {
804 WCHAR buffer[MAX_PATH];
805 HRESULT hr;
806 LPITEMIDLIST pidlCurrent;
808 /* Some acrobatic to get the localized name of the shell folder */
809 hr = SHGetFolderLocation(dialog, asfiInfo[i].nFolder, NULL, 0, &pidlCurrent);
810 if (SUCCEEDED(hr)) {
811 LPSHELLFOLDER psfParent;
812 LPCITEMIDLIST pidlLast;
813 hr = SHBindToParent(pidlCurrent, &IID_IShellFolder, (LPVOID*)&psfParent, &pidlLast);
814 if (SUCCEEDED(hr)) {
815 STRRET strRet;
816 hr = IShellFolder_GetDisplayNameOf(psfParent, pidlLast, SHGDN_FORADDRESSBAR, &strRet);
817 if (SUCCEEDED(hr)) {
818 hr = StrRetToBufW(&strRet, pidlLast, buffer, MAX_PATH);
820 IShellFolder_Release(psfParent);
822 ILFree(pidlCurrent);
825 /* If there's a dangling symlink for the current shell folder, SHGetFolderLocation
826 * will fail above. We fall back to the (non-verified) path of the shell folder. */
827 if (FAILED(hr)) {
828 hr = SHGetFolderPathW(dialog, asfiInfo[i].nFolder|CSIDL_FLAG_DONT_VERIFY, NULL,
829 SHGFP_TYPE_CURRENT, buffer);
832 item.mask = LVIF_TEXT | LVIF_PARAM;
833 item.iItem = i;
834 item.iSubItem = 0;
835 item.pszText = buffer;
836 item.lParam = (LPARAM)&asfiInfo[i];
837 SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_INSERTITEMW, 0, (LPARAM)&item);
839 item.mask = LVIF_TEXT;
840 item.iItem = i;
841 item.iSubItem = 1;
842 item.pszText = strdupU2W(asfiInfo[i].szLinkTarget);
843 SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_SETITEMW, 0, (LPARAM)&item);
844 free(item.pszText);
847 /* Ensure that the previously selected item is selected again. */
848 if (lSelected >= 0) {
849 item.mask = LVIF_STATE;
850 item.state = LVIS_SELECTED;
851 item.stateMask = LVIS_SELECTED;
852 SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_SETITEMSTATE, lSelected, (LPARAM)&item);
856 static void on_shell_folder_selection_changed(HWND hDlg, LPNMLISTVIEW lpnm) {
857 if (lpnm->uNewState & LVIS_SELECTED) {
858 psfiSelected = (struct ShellFolderInfo *)lpnm->lParam;
859 EnableWindow(GetDlgItem(hDlg, IDC_LINK_SFPATH), 1);
860 if (*psfiSelected->szLinkTarget) {
861 WCHAR *link;
862 CheckDlgButton(hDlg, IDC_LINK_SFPATH, BST_CHECKED);
863 EnableWindow(GetDlgItem(hDlg, IDC_EDIT_SFPATH), 1);
864 EnableWindow(GetDlgItem(hDlg, IDC_BROWSE_SFPATH), 1);
865 link = strdupU2W(psfiSelected->szLinkTarget);
866 set_textW(hDlg, IDC_EDIT_SFPATH, link);
867 free(link);
868 } else {
869 CheckDlgButton(hDlg, IDC_LINK_SFPATH, BST_UNCHECKED);
870 EnableWindow(GetDlgItem(hDlg, IDC_EDIT_SFPATH), 0);
871 EnableWindow(GetDlgItem(hDlg, IDC_BROWSE_SFPATH), 0);
872 set_text(hDlg, IDC_EDIT_SFPATH, "");
874 } else {
875 psfiSelected = NULL;
876 CheckDlgButton(hDlg, IDC_LINK_SFPATH, BST_UNCHECKED);
877 set_text(hDlg, IDC_EDIT_SFPATH, "");
878 EnableWindow(GetDlgItem(hDlg, IDC_LINK_SFPATH), 0);
879 EnableWindow(GetDlgItem(hDlg, IDC_EDIT_SFPATH), 0);
880 EnableWindow(GetDlgItem(hDlg, IDC_BROWSE_SFPATH), 0);
884 /* Keep the contents of the edit control, the listview control and the symlink
885 * information in sync. */
886 static void on_shell_folder_edit_changed(HWND hDlg) {
887 LVITEMW item;
888 WCHAR *text = get_text(hDlg, IDC_EDIT_SFPATH);
889 LONG iSel = SendDlgItemMessageW(hDlg, IDC_LIST_SFPATHS, LVM_GETNEXTITEM, -1,
890 MAKELPARAM(LVNI_SELECTED,0));
892 if (!text || !psfiSelected || iSel < 0) {
893 free(text);
894 return;
897 WideCharToMultiByte(CP_UNIXCP, 0, text, -1,
898 psfiSelected->szLinkTarget, FILENAME_MAX, NULL, NULL);
900 item.mask = LVIF_TEXT;
901 item.iItem = iSel;
902 item.iSubItem = 1;
903 item.pszText = text;
904 SendDlgItemMessageW(hDlg, IDC_LIST_SFPATHS, LVM_SETITEMW, 0, (LPARAM)&item);
906 free(text);
908 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
911 static void apply_shell_folder_changes(void) {
912 WCHAR wszPath[MAX_PATH];
913 int i;
915 for (i=0; i<ARRAY_SIZE(asfiInfo); i++) {
916 if (SUCCEEDED( SHGetFolderPathW( NULL, asfiInfo[i].nFolder | CSIDL_FLAG_CREATE, NULL,
917 SHGFP_TYPE_CURRENT, wszPath )))
918 set_shell_folder( wszPath, asfiInfo[i].szLinkTarget );
922 static void refresh_sysparams(HWND hDlg)
924 int i;
926 for (i = 0; i < ARRAY_SIZE(metrics); i++)
928 if (metrics[i].sm_idx != -1)
929 metrics[i].size = GetSystemMetrics(metrics[i].sm_idx);
930 if (metrics[i].color_idx != -1)
931 metrics[i].color = GetSysColor(metrics[i].color_idx);
934 on_sysparam_change(hDlg);
937 static void read_sysparams(HWND hDlg)
939 WCHAR buffer[256];
940 HWND list = GetDlgItem(hDlg, IDC_SYSPARAM_COMBO);
941 NONCLIENTMETRICSW nonclient_metrics;
942 int i, idx;
944 for (i = 0; i < ARRAY_SIZE(metrics); i++)
946 LoadStringW(GetModuleHandleW(NULL), i + IDC_SYSPARAMS_BUTTON, buffer, ARRAY_SIZE(buffer));
947 idx = SendMessageW(list, CB_ADDSTRING, 0, (LPARAM)buffer);
948 if (idx != CB_ERR) SendMessageW(list, CB_SETITEMDATA, idx, i);
950 if (metrics[i].sm_idx != -1)
951 metrics[i].size = GetSystemMetrics(metrics[i].sm_idx);
952 if (metrics[i].color_idx != -1)
953 metrics[i].color = GetSysColor(metrics[i].color_idx);
956 nonclient_metrics.cbSize = sizeof(NONCLIENTMETRICSW);
957 SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSW), &nonclient_metrics, 0);
959 memcpy(&(metrics[IDC_SYSPARAMS_MENU_TEXT - IDC_SYSPARAMS_BUTTON].lf),
960 &(nonclient_metrics.lfMenuFont), sizeof(LOGFONTW));
961 memcpy(&(metrics[IDC_SYSPARAMS_ACTIVE_TITLE_TEXT - IDC_SYSPARAMS_BUTTON].lf),
962 &(nonclient_metrics.lfCaptionFont), sizeof(LOGFONTW));
963 memcpy(&(metrics[IDC_SYSPARAMS_TOOLTIP_TEXT - IDC_SYSPARAMS_BUTTON].lf),
964 &(nonclient_metrics.lfStatusFont), sizeof(LOGFONTW));
965 memcpy(&(metrics[IDC_SYSPARAMS_MSGBOX_TEXT - IDC_SYSPARAMS_BUTTON].lf),
966 &(nonclient_metrics.lfMessageFont), sizeof(LOGFONTW));
969 static void apply_sysparams(void)
971 NONCLIENTMETRICSW ncm;
972 int i, cnt = 0;
973 int colors_idx[ARRAY_SIZE(metrics)];
974 COLORREF colors[ARRAY_SIZE(metrics)];
975 HDC hdc;
976 int dpi;
978 hdc = GetDC( 0 );
979 dpi = GetDeviceCaps( hdc, LOGPIXELSY );
980 ReleaseDC( 0, hdc );
982 ncm.cbSize = sizeof(ncm);
983 SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0);
985 /* convert metrics back to twips */
986 ncm.iMenuWidth = ncm.iMenuHeight =
987 MulDiv( metrics[IDC_SYSPARAMS_MENU - IDC_SYSPARAMS_BUTTON].size, -1440, dpi );
988 ncm.iCaptionWidth = ncm.iCaptionHeight =
989 MulDiv( metrics[IDC_SYSPARAMS_ACTIVE_TITLE - IDC_SYSPARAMS_BUTTON].size, -1440, dpi );
990 ncm.iScrollWidth = ncm.iScrollHeight =
991 MulDiv( metrics[IDC_SYSPARAMS_SCROLLBAR - IDC_SYSPARAMS_BUTTON].size, -1440, dpi );
992 ncm.iSmCaptionWidth = MulDiv( ncm.iSmCaptionWidth, -1440, dpi );
993 ncm.iSmCaptionHeight = MulDiv( ncm.iSmCaptionHeight, -1440, dpi );
995 ncm.lfMenuFont = metrics[IDC_SYSPARAMS_MENU_TEXT - IDC_SYSPARAMS_BUTTON].lf;
996 ncm.lfCaptionFont = metrics[IDC_SYSPARAMS_ACTIVE_TITLE_TEXT - IDC_SYSPARAMS_BUTTON].lf;
997 ncm.lfStatusFont = metrics[IDC_SYSPARAMS_TOOLTIP_TEXT - IDC_SYSPARAMS_BUTTON].lf;
998 ncm.lfMessageFont = metrics[IDC_SYSPARAMS_MSGBOX_TEXT - IDC_SYSPARAMS_BUTTON].lf;
1000 SystemParametersInfoW(SPI_SETNONCLIENTMETRICS, sizeof(ncm), &ncm,
1001 SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
1003 for (i = 0; i < ARRAY_SIZE(metrics); i++)
1004 if (metrics[i].color_idx != -1)
1006 colors_idx[cnt] = metrics[i].color_idx;
1007 colors[cnt++] = metrics[i].color;
1009 SetSysColors(cnt, colors_idx, colors);
1012 static void on_sysparam_change(HWND hDlg)
1014 int index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETCURSEL, 0, 0);
1016 index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETITEMDATA, index, 0);
1018 updating_ui = TRUE;
1020 EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_COLOR_TEXT), metrics[index].color_idx != -1);
1021 EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_COLOR), metrics[index].color_idx != -1);
1022 InvalidateRect(GetDlgItem(hDlg, IDC_SYSPARAM_COLOR), NULL, TRUE);
1024 EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_SIZE_TEXT), metrics[index].sm_idx != -1);
1025 EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_SIZE), metrics[index].sm_idx != -1);
1026 EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_SIZE_UD), metrics[index].sm_idx != -1);
1027 if (metrics[index].sm_idx != -1)
1028 SendDlgItemMessageW(hDlg, IDC_SYSPARAM_SIZE_UD, UDM_SETPOS, 0, MAKELONG(metrics[index].size, 0));
1029 else
1030 set_text(hDlg, IDC_SYSPARAM_SIZE, "");
1032 EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_FONT),
1033 index == IDC_SYSPARAMS_MENU_TEXT-IDC_SYSPARAMS_BUTTON ||
1034 index == IDC_SYSPARAMS_ACTIVE_TITLE_TEXT-IDC_SYSPARAMS_BUTTON ||
1035 index == IDC_SYSPARAMS_TOOLTIP_TEXT-IDC_SYSPARAMS_BUTTON ||
1036 index == IDC_SYSPARAMS_MSGBOX_TEXT-IDC_SYSPARAMS_BUTTON
1039 updating_ui = FALSE;
1042 static void on_draw_item(HWND hDlg, WPARAM wParam, LPARAM lParam)
1044 static HBRUSH black_brush = 0;
1045 LPDRAWITEMSTRUCT draw_info = (LPDRAWITEMSTRUCT)lParam;
1047 if (!black_brush) black_brush = CreateSolidBrush(0);
1049 if (draw_info->CtlID == IDC_SYSPARAM_COLOR)
1051 UINT state;
1052 HTHEME theme;
1053 RECT buttonrect;
1055 theme = OpenThemeDataForDpi(NULL, WC_BUTTONW, GetDpiForWindow(hDlg));
1057 if (theme) {
1058 MARGINS margins;
1060 if (draw_info->itemState & ODS_DISABLED)
1061 state = PBS_DISABLED;
1062 else if (draw_info->itemState & ODS_SELECTED)
1063 state = PBS_PRESSED;
1064 else
1065 state = PBS_NORMAL;
1067 if (IsThemeBackgroundPartiallyTransparent(theme, BP_PUSHBUTTON, state))
1068 DrawThemeParentBackground(draw_info->hwndItem, draw_info->hDC, NULL);
1070 DrawThemeBackground(theme, draw_info->hDC, BP_PUSHBUTTON, state, &draw_info->rcItem, NULL);
1072 buttonrect = draw_info->rcItem;
1074 GetThemeMargins(theme, draw_info->hDC, BP_PUSHBUTTON, state, TMT_CONTENTMARGINS, &draw_info->rcItem, &margins);
1076 buttonrect.left += margins.cxLeftWidth;
1077 buttonrect.top += margins.cyTopHeight;
1078 buttonrect.right -= margins.cxRightWidth;
1079 buttonrect.bottom -= margins.cyBottomHeight;
1081 if (draw_info->itemState & ODS_FOCUS)
1082 DrawFocusRect(draw_info->hDC, &buttonrect);
1084 CloseThemeData(theme);
1085 } else {
1086 state = DFCS_ADJUSTRECT | DFCS_BUTTONPUSH;
1088 if (draw_info->itemState & ODS_DISABLED)
1089 state |= DFCS_INACTIVE;
1090 else
1091 state |= draw_info->itemState & ODS_SELECTED ? DFCS_PUSHED : 0;
1093 DrawFrameControl(draw_info->hDC, &draw_info->rcItem, DFC_BUTTON, state);
1095 buttonrect = draw_info->rcItem;
1098 if (!(draw_info->itemState & ODS_DISABLED))
1100 HBRUSH brush;
1101 int index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETCURSEL, 0, 0);
1103 index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETITEMDATA, index, 0);
1104 brush = CreateSolidBrush(metrics[index].color);
1106 InflateRect(&buttonrect, -1, -1);
1107 FrameRect(draw_info->hDC, &buttonrect, black_brush);
1108 InflateRect(&buttonrect, -1, -1);
1109 FillRect(draw_info->hDC, &buttonrect, brush);
1110 DeleteObject(brush);
1115 static void on_select_font(HWND hDlg)
1117 CHOOSEFONTW cf;
1118 int index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETCURSEL, 0, 0);
1119 index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETITEMDATA, index, 0);
1121 ZeroMemory(&cf, sizeof(cf));
1122 cf.lStructSize = sizeof(CHOOSEFONTW);
1123 cf.hwndOwner = hDlg;
1124 cf.lpLogFont = &(metrics[index].lf);
1125 cf.Flags = CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT | CF_NOSCRIPTSEL | CF_NOVERTFONTS;
1127 if (ChooseFontW(&cf))
1128 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1131 static void init_mime_types(HWND hDlg)
1133 WCHAR *buf = get_reg_key(config_key, keypath(L"FileOpenAssociations"), L"Enable", L"Y");
1134 int state = IS_OPTION_TRUE(*buf) ? BST_CHECKED : BST_UNCHECKED;
1136 CheckDlgButton(hDlg, IDC_ENABLE_FILE_ASSOCIATIONS, state);
1138 free(buf);
1141 static void update_mime_types(HWND hDlg)
1143 const WCHAR *state = L"Y";
1145 if (IsDlgButtonChecked(hDlg, IDC_ENABLE_FILE_ASSOCIATIONS) != BST_CHECKED)
1146 state = L"N";
1148 set_reg_key(config_key, keypath(L"FileOpenAssociations"), L"Enable", state);
1151 static BOOL CALLBACK update_window_pos_proc(HWND hwnd, LPARAM lp)
1153 RECT rect;
1155 GetClientRect(hwnd, &rect);
1156 AdjustWindowRectEx(&rect, GetWindowLongW(hwnd, GWL_STYLE), !!GetMenu(hwnd),
1157 GetWindowLongW(hwnd, GWL_EXSTYLE));
1158 SetWindowPos(hwnd, 0, 0, 0, rect.right - rect.left, rect.bottom - rect.top,
1159 SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
1160 return TRUE;
1163 /* Adjust the rectangle for top-level windows because the new non-client metrics may be different */
1164 static void update_window_pos(void)
1166 EnumWindows(update_window_pos_proc, 0);
1169 INT_PTR CALLBACK
1170 ThemeDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1172 switch (uMsg) {
1173 case WM_INITDIALOG:
1174 read_shell_folder_link_targets();
1175 init_shell_folder_listview_headers(hDlg);
1176 update_shell_folder_listview(hDlg);
1177 read_sysparams(hDlg);
1178 init_mime_types(hDlg);
1179 init_dialog(hDlg);
1180 break;
1182 case WM_DESTROY:
1183 free_theme_files();
1184 break;
1186 case WM_SHOWWINDOW:
1187 set_window_title(hDlg);
1188 break;
1190 case WM_COMMAND:
1191 switch(HIWORD(wParam)) {
1192 case CBN_SELCHANGE: {
1193 if (updating_ui) break;
1194 switch (LOWORD(wParam))
1196 case IDC_THEME_APPCOMBO: /* fall through */
1197 case IDC_THEME_THEMECOMBO: on_theme_changed(hDlg); break;
1198 case IDC_THEME_COLORCOMBO: /* fall through */
1199 case IDC_THEME_SIZECOMBO: theme_dirty = TRUE; break;
1200 case IDC_SYSPARAM_COMBO: on_sysparam_change(hDlg); return FALSE;
1202 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1203 break;
1205 case EN_CHANGE: {
1206 if (updating_ui) break;
1207 switch (LOWORD(wParam))
1209 case IDC_EDIT_SFPATH: on_shell_folder_edit_changed(hDlg); break;
1210 case IDC_SYSPARAM_SIZE:
1212 WCHAR *text = get_text(hDlg, IDC_SYSPARAM_SIZE);
1213 int index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETCURSEL, 0, 0);
1215 index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETITEMDATA, index, 0);
1217 if (text)
1219 metrics[index].size = wcstol(text, NULL, 10);
1220 free(text);
1222 else
1224 /* for empty string set to minimum value */
1225 SendDlgItemMessageW(hDlg, IDC_SYSPARAM_SIZE_UD, UDM_GETRANGE32, (WPARAM)&metrics[index].size, 0);
1228 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1229 break;
1232 break;
1234 case BN_CLICKED:
1235 switch (LOWORD(wParam))
1237 case IDC_THEME_INSTALL:
1238 on_theme_install (hDlg);
1239 break;
1241 case IDC_SYSPARAM_FONT:
1242 on_select_font(hDlg);
1243 break;
1245 case IDC_BROWSE_SFPATH:
1247 WCHAR link[FILENAME_MAX];
1248 if (browse_for_unix_folder(hDlg, link)) {
1249 WideCharToMultiByte(CP_UNIXCP, 0, link, -1,
1250 psfiSelected->szLinkTarget, FILENAME_MAX,
1251 NULL, NULL);
1252 update_shell_folder_listview(hDlg);
1253 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1255 break;
1258 case IDC_LINK_SFPATH:
1259 if (IsDlgButtonChecked(hDlg, IDC_LINK_SFPATH)) {
1260 WCHAR link[FILENAME_MAX];
1261 if (browse_for_unix_folder(hDlg, link)) {
1262 WideCharToMultiByte(CP_UNIXCP, 0, link, -1,
1263 psfiSelected->szLinkTarget, FILENAME_MAX,
1264 NULL, NULL);
1265 update_shell_folder_listview(hDlg);
1266 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1267 } else {
1268 CheckDlgButton(hDlg, IDC_LINK_SFPATH, BST_UNCHECKED);
1270 } else {
1271 psfiSelected->szLinkTarget[0] = '\0';
1272 update_shell_folder_listview(hDlg);
1273 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1275 break;
1277 case IDC_SYSPARAM_COLOR:
1279 static COLORREF user_colors[16];
1280 CHOOSECOLORW c_color;
1281 int index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETCURSEL, 0, 0);
1283 index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETITEMDATA, index, 0);
1285 memset(&c_color, 0, sizeof(c_color));
1286 c_color.lStructSize = sizeof(c_color);
1287 c_color.lpCustColors = user_colors;
1288 c_color.rgbResult = metrics[index].color;
1289 c_color.Flags = CC_ANYCOLOR | CC_RGBINIT;
1290 c_color.hwndOwner = hDlg;
1291 if (ChooseColorW(&c_color))
1293 metrics[index].color = c_color.rgbResult;
1294 save_sys_color(index, metrics[index].color);
1295 InvalidateRect(GetDlgItem(hDlg, IDC_SYSPARAM_COLOR), NULL, TRUE);
1296 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1298 break;
1301 case IDC_ENABLE_FILE_ASSOCIATIONS:
1302 update_mime_types(hDlg);
1303 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1304 break;
1306 break;
1308 break;
1310 case WM_NOTIFY:
1311 switch (((LPNMHDR)lParam)->code) {
1312 case PSN_KILLACTIVE: {
1313 SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, FALSE);
1314 break;
1316 case PSN_APPLY: {
1317 apply();
1318 apply_theme(hDlg);
1319 apply_shell_folder_changes();
1320 apply_sysparams();
1321 read_shell_folder_link_targets();
1322 update_shell_folder_listview(hDlg);
1323 update_mime_types(hDlg);
1324 update_window_pos();
1325 SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
1326 break;
1328 case LVN_ITEMCHANGED: {
1329 if (wParam == IDC_LIST_SFPATHS)
1330 on_shell_folder_selection_changed(hDlg, (LPNMLISTVIEW)lParam);
1331 break;
1333 case PSN_SETACTIVE: {
1334 update_dialog(hDlg);
1335 break;
1338 break;
1340 case WM_DRAWITEM:
1341 on_draw_item(hDlg, wParam, lParam);
1342 break;
1344 default:
1345 break;
1347 return FALSE;