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
39 #include <wine/debug.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
,
59 LPCWSTR pszToolTip
, LPVOID lpReserved2
,
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
,
70 HRESULT WINAPI
CloseThemeFile (HTHEMEFILE hThemeFile
);
71 HRESULT WINAPI
EnumThemes (LPCWSTR pszThemePath
, EnumThemeProc callback
,
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 */
84 /* wrapper around DSA that also keeps an item count */
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
);
108 static int CALLBACK
dsa_destroy_callback (LPVOID p
, LPVOID pData
)
110 ThemeColorOrSize
* item
= p
;
112 free (item
->fancyName
);
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);
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
)
135 for (; i
< wdsa
->count
; i
++)
137 ThemeColorOrSize
* item
= color_or_size_dsa_get (wdsa
, i
);
138 if (lstrcmpiW (item
->name
, name
) == 0) break;
143 /* A theme file, contains file name, display name, color and size scheme names */
146 WCHAR
* themeFileName
;
152 static HDSA themeFiles
= NULL
;
153 static int themeFilesCount
= 0;
155 static int CALLBACK
theme_dsa_destroy_callback (LPVOID p
, LPVOID pData
)
158 free (item
->themeFileName
);
159 free (item
->fancyName
);
160 free_color_or_size_dsa (&item
->colors
);
161 free_color_or_size_dsa (&item
->sizes
);
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
);
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
,
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
,
200 LPVOID lpReserved2
, LPVOID lpData
)
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
);
223 /* Scan for themes */
224 static void scan_theme_files(void)
226 WCHAR themesPath
[MAX_PATH
];
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
,
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
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];
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. */
302 for (i
= 0; i
< themeFilesCount
; i
++)
304 theme
= DSA_GetItemPtr (themeFiles
, i
);
305 if (lstrcmpiW (theme
->themeFileName
, currentTheme
) == 0)
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
);
328 /* No theme selected */
332 SendMessageW (comboTheme
, CB_SETCURSEL
, themeIndex
, 0);
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
,
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
);
364 SendMessageW (comboColor
, CB_SETCURSEL
, 0, 0);
365 SendMessageW (comboSize
, CB_SETCURSEL
, 0, 0);
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";
379 ApplyTheme (NULL
, b
, NULL
);
383 ThemeFile
* theme
= DSA_GetItemPtr (themeFiles
, themeIndex
-1);
384 const WCHAR
* themeFileName
= theme
->themeFileName
;
385 const WCHAR
* colorName
= NULL
;
386 const WCHAR
* sizeName
= NULL
;
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
,
399 ApplyTheme (hTheme
, b
, NULL
);
400 CloseThemeFile (hTheme
);
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
;
427 if (RegOpenKeyExW( HKEY_CURRENT_USER
, L
"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", 0, KEY_QUERY_VALUE
, &hkey
))
429 if (RegQueryValueExW( hkey
, L
"AppsUseLightTheme", NULL
, &type
, (BYTE
*)&ret
, &len
) || type
!= REG_DWORD
)
436 static void init_dialog (HWND dialog
)
438 DWORD apps_use_light_theme
;
439 WCHAR apps_theme_str
[256];
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
)
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
);
480 enable_size_and_color_controls (dialog
, TRUE
);
484 SendDlgItemMessageW(dialog
, IDC_SYSPARAM_SIZE_UD
, UDM_SETRANGE
, 0, MAKELONG(100, 8));
489 static void on_theme_changed(HWND dialog
) {
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
);
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
);
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
),
520 colorIndex
= SendMessageW (GetDlgItem (dialog
, IDC_THEME_COLORCOMBO
),
522 sizeIndex
= SendMessageW (GetDlgItem (dialog
, IDC_THEME_SIZECOMBO
),
525 do_apply_theme (dialog
, themeIndex
, colorIndex
, sizeIndex
);
531 int sm_idx
, color_idx
;
532 const WCHAR
*color_reg
;
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
)
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
)
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
);
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;
603 WINE_TRACE("%s\n", wine_dbgstr_w(file
));
604 keyName
= malloc(sizeof(*keyName
) * allocLen
);
608 len
= GetPrivateProfileStringW(L
"Control Panel\\Colors", NULL
, NULL
, keyName
,
610 if (len
< 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
,
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
);
636 static void on_theme_install(HWND dialog
)
638 static const WCHAR filterMask
[] = L
"\0*.msstyles;*.theme\0";
640 WCHAR filetitle
[MAX_PATH
];
641 WCHAR file
[MAX_PATH
];
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
;
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
;
666 ofn
.nFileExtension
= 0;
667 ofn
.lpstrDefExt
= 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);
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;
704 WINE_TRACE("copying: %s -> %s\n", wine_dbgstr_w (file
),
705 wine_dbgstr_w (themeFilePath
));
707 shfop
.wFunc
= FO_COPY
;
709 shfop
.pTo
= themeFilePath
;
710 shfop
.fFlags
= FOF_NOCONFIRMMKDIR
;
711 if (SHFileOperationW (&shfop
) == 0)
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
);
724 enable_size_and_color_controls (dialog
, TRUE
);
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
{
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
;
756 WCHAR szShellFolder
[64] = L
"Shell Folder";
757 WCHAR szLinksTo
[64] = L
"Links to";
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
];
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
) {
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
];
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
);
809 LPSHELLFOLDER psfParent
;
810 LPCITEMIDLIST pidlLast
;
811 hr
= SHBindToParent(pidlCurrent
, &IID_IShellFolder
, (LPVOID
*)&psfParent
, &pidlLast
);
814 hr
= IShellFolder_GetDisplayNameOf(psfParent
, pidlLast
, SHGDN_FORADDRESSBAR
, &strRet
);
816 hr
= StrRetToBufW(&strRet
, pidlLast
, buffer
, MAX_PATH
);
818 IShellFolder_Release(psfParent
);
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. */
826 hr
= SHGetFolderPathW(dialog
, asfiInfo
[i
].nFolder
|CSIDL_FLAG_DONT_VERIFY
, NULL
,
827 SHGFP_TYPE_CURRENT
, buffer
);
830 item
.mask
= LVIF_TEXT
| LVIF_PARAM
;
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
;
840 item
.pszText
= strdupU2W(asfiInfo
[i
].szLinkTarget
);
841 SendDlgItemMessageW(dialog
, IDC_LIST_SFPATHS
, LVM_SETITEMW
, 0, (LPARAM
)&item
);
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
) {
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
);
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
, "");
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
) {
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) {
895 WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1,
896 psfiSelected
->szLinkTarget
, FILENAME_MAX
, NULL
, NULL
);
898 item
.mask
= LVIF_TEXT
;
902 SendDlgItemMessageW(hDlg
, IDC_LIST_SFPATHS
, LVM_SETITEMW
, 0, (LPARAM
)&item
);
906 SendMessageW(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
909 static void apply_shell_folder_changes(void) {
910 WCHAR wszPath
[MAX_PATH
];
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
)
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
)
938 HWND list
= GetDlgItem(hDlg
, IDC_SYSPARAM_COMBO
);
939 NONCLIENTMETRICSW nonclient_metrics
;
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
;
971 int colors_idx
[ARRAY_SIZE(metrics
)];
972 COLORREF colors
[ARRAY_SIZE(metrics
)];
977 dpi
= GetDeviceCaps( hdc
, LOGPIXELSY
);
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);
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));
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
)
1053 theme
= OpenThemeDataForDpi(NULL
, WC_BUTTONW
, GetDpiForWindow(hDlg
));
1058 if (draw_info
->itemState
& ODS_DISABLED
)
1059 state
= PBS_DISABLED
;
1060 else if (draw_info
->itemState
& ODS_SELECTED
)
1061 state
= PBS_PRESSED
;
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
);
1084 state
= DFCS_ADJUSTRECT
| DFCS_BUTTONPUSH
;
1086 if (draw_info
->itemState
& ODS_DISABLED
)
1087 state
|= DFCS_INACTIVE
;
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
))
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
)
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
);
1139 static void update_mime_types(HWND hDlg
)
1141 const WCHAR
*state
= L
"Y";
1143 if (IsDlgButtonChecked(hDlg
, IDC_ENABLE_FILE_ASSOCIATIONS
) != BST_CHECKED
)
1146 set_reg_key(config_key
, keypath(L
"FileOpenAssociations"), L
"Enable", state
);
1149 static BOOL CALLBACK
update_window_pos_proc(HWND hwnd
, LPARAM lp
)
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
);
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);
1168 ThemeDlgProc (HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
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
);
1185 set_window_title(hDlg
);
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);
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);
1217 metrics
[index
].size
= wcstol(text
, NULL
, 10);
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);
1233 switch (LOWORD(wParam
))
1235 case IDC_THEME_INSTALL
:
1236 on_theme_install (hDlg
);
1239 case IDC_SYSPARAM_FONT
:
1240 on_select_font(hDlg
);
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
,
1250 update_shell_folder_listview(hDlg
);
1251 SendMessageW(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
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
,
1263 update_shell_folder_listview(hDlg
);
1264 SendMessageW(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
1266 CheckDlgButton(hDlg
, IDC_LINK_SFPATH
, BST_UNCHECKED
);
1269 psfiSelected
->szLinkTarget
[0] = '\0';
1270 update_shell_folder_listview(hDlg
);
1271 SendMessageW(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
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);
1299 case IDC_ENABLE_FILE_ASSOCIATIONS
:
1300 update_mime_types(hDlg
);
1301 SendMessageW(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
1309 switch (((LPNMHDR
)lParam
)->code
) {
1310 case PSN_KILLACTIVE
: {
1311 SetWindowLongPtrW(hDlg
, DWLP_MSGRESULT
, FALSE
);
1317 apply_shell_folder_changes();
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
);
1326 case LVN_ITEMCHANGED
: {
1327 if (wParam
== IDC_LIST_SFPATHS
)
1328 on_shell_folder_selection_changed(hDlg
, (LPNMLISTVIEW
)lParam
);
1331 case PSN_SETACTIVE
: {
1332 update_dialog(hDlg
);
1339 on_draw_item(hDlg
, wParam
, lParam
);