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
26 #include "wine/port.h"
31 #ifdef HAVE_SYS_STAT_H
50 #include <wine/debug.h>
51 #include <wine/unicode.h>
56 WINE_DEFAULT_DEBUG_CHANNEL(winecfg
);
58 /* UXTHEME functions not in the headers */
60 typedef struct tagTHEMENAMES
62 WCHAR szName
[MAX_PATH
+1];
63 WCHAR szDisplayName
[MAX_PATH
+1];
64 WCHAR szTooltip
[MAX_PATH
+1];
65 } THEMENAMES
, *PTHEMENAMES
;
67 typedef void* HTHEMEFILE
;
68 typedef BOOL (CALLBACK
*EnumThemeProc
)(LPVOID lpReserved
,
69 LPCWSTR pszThemeFileName
,
71 LPCWSTR pszToolTip
, LPVOID lpReserved2
,
74 HRESULT WINAPI
EnumThemeColors (LPCWSTR pszThemeFileName
, LPWSTR pszSizeName
,
75 DWORD dwColorNum
, PTHEMENAMES pszColorNames
);
76 HRESULT WINAPI
EnumThemeSizes (LPCWSTR pszThemeFileName
, LPWSTR pszColorName
,
77 DWORD dwSizeNum
, PTHEMENAMES pszSizeNames
);
78 HRESULT WINAPI
ApplyTheme (HTHEMEFILE hThemeFile
, char* unknown
, HWND hWnd
);
79 HRESULT WINAPI
OpenThemeFile (LPCWSTR pszThemeFileName
, LPCWSTR pszColorName
,
80 LPCWSTR pszSizeName
, HTHEMEFILE
* hThemeFile
,
82 HRESULT WINAPI
CloseThemeFile (HTHEMEFILE hThemeFile
);
83 HRESULT WINAPI
EnumThemes (LPCWSTR pszThemePath
, EnumThemeProc callback
,
86 static void refresh_sysparams(HWND hDlg
);
87 static void on_sysparam_change(HWND hDlg
);
89 /* A struct to keep both the internal and "fancy" name of a color or size */
96 /* wrapper around DSA that also keeps an item count */
103 /* Some helper functions to deal with ThemeColorOrSize structs in WrappedDSAs */
105 static void color_or_size_dsa_add (WrappedDsa
* wdsa
, const WCHAR
* name
,
106 const WCHAR
* fancyName
)
108 ThemeColorOrSize item
;
110 item
.name
= HeapAlloc (GetProcessHeap(), 0,
111 (lstrlenW (name
) + 1) * sizeof(WCHAR
));
112 lstrcpyW (item
.name
, name
);
114 item
.fancyName
= HeapAlloc (GetProcessHeap(), 0,
115 (lstrlenW (fancyName
) + 1) * sizeof(WCHAR
));
116 lstrcpyW (item
.fancyName
, fancyName
);
118 DSA_InsertItem (wdsa
->dsa
, wdsa
->count
, &item
);
122 static int CALLBACK
dsa_destroy_callback (LPVOID p
, LPVOID pData
)
124 ThemeColorOrSize
* item
= p
;
125 HeapFree (GetProcessHeap(), 0, item
->name
);
126 HeapFree (GetProcessHeap(), 0, item
->fancyName
);
130 static void free_color_or_size_dsa (WrappedDsa
* wdsa
)
132 DSA_DestroyCallback (wdsa
->dsa
, dsa_destroy_callback
, NULL
);
135 static void create_color_or_size_dsa (WrappedDsa
* wdsa
)
137 wdsa
->dsa
= DSA_Create (sizeof (ThemeColorOrSize
), 1);
141 static ThemeColorOrSize
* color_or_size_dsa_get (WrappedDsa
* wdsa
, int index
)
143 return DSA_GetItemPtr (wdsa
->dsa
, index
);
146 static int color_or_size_dsa_find (WrappedDsa
* wdsa
, const WCHAR
* name
)
149 for (; i
< wdsa
->count
; i
++)
151 ThemeColorOrSize
* item
= color_or_size_dsa_get (wdsa
, i
);
152 if (lstrcmpiW (item
->name
, name
) == 0) break;
157 /* A theme file, contains file name, display name, color and size scheme names */
160 WCHAR
* themeFileName
;
166 static HDSA themeFiles
= NULL
;
167 static int themeFilesCount
= 0;
169 static int CALLBACK
theme_dsa_destroy_callback (LPVOID p
, LPVOID pData
)
172 HeapFree (GetProcessHeap(), 0, item
->themeFileName
);
173 HeapFree (GetProcessHeap(), 0, item
->fancyName
);
174 free_color_or_size_dsa (&item
->colors
);
175 free_color_or_size_dsa (&item
->sizes
);
179 /* Free memory occupied by the theme list */
180 static void free_theme_files(void)
182 if (themeFiles
== NULL
) return;
184 DSA_DestroyCallback (themeFiles
, theme_dsa_destroy_callback
, NULL
);
189 typedef HRESULT (WINAPI
* EnumTheme
) (LPCWSTR
, LPWSTR
, DWORD
, PTHEMENAMES
);
191 /* fill a string list with either colors or sizes of a theme */
192 static void fill_theme_string_array (const WCHAR
* filename
,
199 WINE_TRACE ("%s %p %p\n", wine_dbgstr_w (filename
), wdsa
, enumTheme
);
201 while (SUCCEEDED (enumTheme (filename
, NULL
, index
++, &names
)))
203 WINE_TRACE ("%s: %s\n", wine_dbgstr_w (names
.szName
),
204 wine_dbgstr_w (names
.szDisplayName
));
205 color_or_size_dsa_add (wdsa
, names
.szName
, names
.szDisplayName
);
209 /* Theme enumeration callback, adds theme to theme list */
210 static BOOL CALLBACK
myEnumThemeProc (LPVOID lpReserved
,
211 LPCWSTR pszThemeFileName
,
212 LPCWSTR pszThemeName
,
214 LPVOID lpReserved2
, LPVOID lpData
)
218 /* fill size/color lists */
219 create_color_or_size_dsa (&newEntry
.colors
);
220 fill_theme_string_array (pszThemeFileName
, &newEntry
.colors
, EnumThemeColors
);
221 create_color_or_size_dsa (&newEntry
.sizes
);
222 fill_theme_string_array (pszThemeFileName
, &newEntry
.sizes
, EnumThemeSizes
);
224 newEntry
.themeFileName
= HeapAlloc (GetProcessHeap(), 0,
225 (lstrlenW (pszThemeFileName
) + 1) * sizeof(WCHAR
));
226 lstrcpyW (newEntry
.themeFileName
, pszThemeFileName
);
228 newEntry
.fancyName
= HeapAlloc (GetProcessHeap(), 0,
229 (lstrlenW (pszThemeName
) + 1) * sizeof(WCHAR
));
230 lstrcpyW (newEntry
.fancyName
, pszThemeName
);
232 /*list_add_tail (&themeFiles, &newEntry->entry);*/
233 DSA_InsertItem (themeFiles
, themeFilesCount
, &newEntry
);
239 /* Scan for themes */
240 static void scan_theme_files(void)
242 static const WCHAR themesSubdir
[] = { '\\','T','h','e','m','e','s',0 };
243 WCHAR themesPath
[MAX_PATH
];
247 if (FAILED (SHGetFolderPathW (NULL
, CSIDL_RESOURCES
, NULL
,
248 SHGFP_TYPE_CURRENT
, themesPath
))) return;
250 themeFiles
= DSA_Create (sizeof (ThemeFile
), 1);
251 lstrcatW (themesPath
, themesSubdir
);
253 EnumThemes (themesPath
, myEnumThemeProc
, 0);
256 /* fill the color & size combo boxes for a given theme */
257 static void fill_color_size_combos (ThemeFile
* theme
, HWND comboColor
,
262 SendMessageW (comboColor
, CB_RESETCONTENT
, 0, 0);
263 for (i
= 0; i
< theme
->colors
.count
; i
++)
265 ThemeColorOrSize
* item
= color_or_size_dsa_get (&theme
->colors
, i
);
266 SendMessageW (comboColor
, CB_ADDSTRING
, 0, (LPARAM
)item
->fancyName
);
269 SendMessageW (comboSize
, CB_RESETCONTENT
, 0, 0);
270 for (i
= 0; i
< theme
->sizes
.count
; i
++)
272 ThemeColorOrSize
* item
= color_or_size_dsa_get (&theme
->sizes
, i
);
273 SendMessageW (comboSize
, CB_ADDSTRING
, 0, (LPARAM
)item
->fancyName
);
277 /* Select the item of a combo box that matches a theme's color and size
279 static void select_color_and_size (ThemeFile
* theme
,
280 const WCHAR
* colorName
, HWND comboColor
,
281 const WCHAR
* sizeName
, HWND comboSize
)
283 SendMessageW (comboColor
, CB_SETCURSEL
,
284 color_or_size_dsa_find (&theme
->colors
, colorName
), 0);
285 SendMessageW (comboSize
, CB_SETCURSEL
,
286 color_or_size_dsa_find (&theme
->sizes
, sizeName
), 0);
289 /* Fill theme, color and sizes combo boxes with the know themes and select
290 * the entries matching the currently active theme. */
291 static BOOL
fill_theme_list (HWND comboTheme
, HWND comboColor
, HWND comboSize
)
293 WCHAR textNoTheme
[256];
297 WCHAR currentTheme
[MAX_PATH
];
298 WCHAR currentColor
[MAX_PATH
];
299 WCHAR currentSize
[MAX_PATH
];
300 ThemeFile
* theme
= NULL
;
302 LoadStringW(GetModuleHandleW(NULL
), IDS_NOTHEME
, textNoTheme
, ARRAY_SIZE(textNoTheme
));
304 SendMessageW (comboTheme
, CB_RESETCONTENT
, 0, 0);
305 SendMessageW (comboTheme
, CB_ADDSTRING
, 0, (LPARAM
)textNoTheme
);
307 for (i
= 0; i
< themeFilesCount
; i
++)
309 ThemeFile
* item
= DSA_GetItemPtr (themeFiles
, i
);
310 SendMessageW (comboTheme
, CB_ADDSTRING
, 0,
311 (LPARAM
)item
->fancyName
);
314 if (IsThemeActive() && SUCCEEDED(GetCurrentThemeName(currentTheme
, ARRAY_SIZE(currentTheme
),
315 currentColor
, ARRAY_SIZE(currentColor
), currentSize
, ARRAY_SIZE(currentSize
))))
317 /* Determine the index of the currently active theme. */
319 for (i
= 0; i
< themeFilesCount
; i
++)
321 theme
= DSA_GetItemPtr (themeFiles
, i
);
322 if (lstrcmpiW (theme
->themeFileName
, currentTheme
) == 0)
331 /* Current theme not found?... add to the list, then... */
332 WINE_TRACE("Theme %s not in list of enumerated themes\n",
333 wine_dbgstr_w (currentTheme
));
334 myEnumThemeProc (NULL
, currentTheme
, currentTheme
,
335 currentTheme
, NULL
, NULL
);
336 themeIndex
= themeFilesCount
;
337 theme
= DSA_GetItemPtr (themeFiles
, themeFilesCount
-1);
339 fill_color_size_combos (theme
, comboColor
, comboSize
);
340 select_color_and_size (theme
, currentColor
, comboColor
,
341 currentSize
, comboSize
);
345 /* No theme selected */
349 SendMessageW (comboTheme
, CB_SETCURSEL
, themeIndex
, 0);
353 /* Update the color & size combo boxes when the selection of the theme
354 * combo changed. Selects the current color and size scheme if the theme
355 * is currently active, otherwise the first color and size. */
356 static BOOL
update_color_and_size (int themeIndex
, HWND comboColor
,
365 WCHAR currentTheme
[MAX_PATH
];
366 WCHAR currentColor
[MAX_PATH
];
367 WCHAR currentSize
[MAX_PATH
];
368 ThemeFile
* theme
= DSA_GetItemPtr (themeFiles
, themeIndex
- 1);
370 fill_color_size_combos (theme
, comboColor
, comboSize
);
372 if ((SUCCEEDED(GetCurrentThemeName (currentTheme
, ARRAY_SIZE(currentTheme
),
373 currentColor
, ARRAY_SIZE(currentColor
), currentSize
, ARRAY_SIZE(currentSize
))))
374 && (lstrcmpiW (currentTheme
, theme
->themeFileName
) == 0))
376 select_color_and_size (theme
, currentColor
, comboColor
,
377 currentSize
, comboSize
);
381 SendMessageW (comboColor
, CB_SETCURSEL
, 0, 0);
382 SendMessageW (comboSize
, CB_SETCURSEL
, 0, 0);
388 /* Apply a theme from a given theme, color and size combo box item index. */
389 static void do_apply_theme (HWND dialog
, int themeIndex
, int colorIndex
, int sizeIndex
)
391 static char b
[] = "\0";
396 ApplyTheme (NULL
, b
, NULL
);
400 ThemeFile
* theme
= DSA_GetItemPtr (themeFiles
, themeIndex
-1);
401 const WCHAR
* themeFileName
= theme
->themeFileName
;
402 const WCHAR
* colorName
= NULL
;
403 const WCHAR
* sizeName
= NULL
;
405 ThemeColorOrSize
* item
;
407 item
= color_or_size_dsa_get (&theme
->colors
, colorIndex
);
408 colorName
= item
->name
;
410 item
= color_or_size_dsa_get (&theme
->sizes
, sizeIndex
);
411 sizeName
= item
->name
;
413 if (SUCCEEDED (OpenThemeFile (themeFileName
, colorName
, sizeName
,
416 ApplyTheme (hTheme
, b
, NULL
);
417 CloseThemeFile (hTheme
);
421 ApplyTheme (NULL
, b
, NULL
);
425 refresh_sysparams(dialog
);
428 static BOOL updating_ui
;
429 static BOOL theme_dirty
;
431 static void enable_size_and_color_controls (HWND dialog
, BOOL enable
)
433 EnableWindow (GetDlgItem (dialog
, IDC_THEME_COLORCOMBO
), enable
);
434 EnableWindow (GetDlgItem (dialog
, IDC_THEME_COLORTEXT
), enable
);
435 EnableWindow (GetDlgItem (dialog
, IDC_THEME_SIZECOMBO
), enable
);
436 EnableWindow (GetDlgItem (dialog
, IDC_THEME_SIZETEXT
), enable
);
439 static void init_dialog (HWND dialog
)
444 if (!fill_theme_list (GetDlgItem (dialog
, IDC_THEME_THEMECOMBO
),
445 GetDlgItem (dialog
, IDC_THEME_COLORCOMBO
),
446 GetDlgItem (dialog
, IDC_THEME_SIZECOMBO
)))
448 SendMessageW (GetDlgItem (dialog
, IDC_THEME_COLORCOMBO
), CB_SETCURSEL
, (WPARAM
)-1, 0);
449 SendMessageW (GetDlgItem (dialog
, IDC_THEME_SIZECOMBO
), CB_SETCURSEL
, (WPARAM
)-1, 0);
450 enable_size_and_color_controls (dialog
, FALSE
);
454 enable_size_and_color_controls (dialog
, TRUE
);
458 SendDlgItemMessageW(dialog
, IDC_SYSPARAM_SIZE_UD
, UDM_SETBUDDY
, (WPARAM
)GetDlgItem(dialog
, IDC_SYSPARAM_SIZE
), 0);
459 SendDlgItemMessageW(dialog
, IDC_SYSPARAM_SIZE_UD
, UDM_SETRANGE
, 0, MAKELONG(100, 8));
464 static void on_theme_changed(HWND dialog
) {
465 int index
= SendMessageW (GetDlgItem (dialog
, IDC_THEME_THEMECOMBO
),
467 if (!update_color_and_size (index
, GetDlgItem (dialog
, IDC_THEME_COLORCOMBO
),
468 GetDlgItem (dialog
, IDC_THEME_SIZECOMBO
)))
470 SendMessageW (GetDlgItem (dialog
, IDC_THEME_COLORCOMBO
), CB_SETCURSEL
, -1, 0);
471 SendMessageW (GetDlgItem (dialog
, IDC_THEME_SIZECOMBO
), CB_SETCURSEL
, -1, 0);
472 enable_size_and_color_controls (dialog
, FALSE
);
476 enable_size_and_color_controls (dialog
, TRUE
);
481 static void apply_theme(HWND dialog
)
483 int themeIndex
, colorIndex
, sizeIndex
;
485 if (!theme_dirty
) return;
487 themeIndex
= SendMessageW (GetDlgItem (dialog
, IDC_THEME_THEMECOMBO
),
489 colorIndex
= SendMessageW (GetDlgItem (dialog
, IDC_THEME_COLORCOMBO
),
491 sizeIndex
= SendMessageW (GetDlgItem (dialog
, IDC_THEME_SIZECOMBO
),
494 do_apply_theme (dialog
, themeIndex
, colorIndex
, sizeIndex
);
500 int sm_idx
, color_idx
;
501 const char *color_reg
;
507 {-1, COLOR_BTNFACE
, "ButtonFace" }, /* IDC_SYSPARAMS_BUTTON */
508 {-1, COLOR_BTNTEXT
, "ButtonText" }, /* IDC_SYSPARAMS_BUTTON_TEXT */
509 {-1, COLOR_BACKGROUND
, "Background" }, /* IDC_SYSPARAMS_DESKTOP */
510 {SM_CXMENUSIZE
, COLOR_MENU
, "Menu" }, /* IDC_SYSPARAMS_MENU */
511 {-1, COLOR_MENUTEXT
, "MenuText" }, /* IDC_SYSPARAMS_MENU_TEXT */
512 {SM_CXVSCROLL
, COLOR_SCROLLBAR
, "Scrollbar" }, /* IDC_SYSPARAMS_SCROLLBAR */
513 {-1, COLOR_HIGHLIGHT
, "Hilight" }, /* IDC_SYSPARAMS_SELECTION */
514 {-1, COLOR_HIGHLIGHTTEXT
, "HilightText" }, /* IDC_SYSPARAMS_SELECTION_TEXT */
515 {-1, COLOR_INFOBK
, "InfoWindow" }, /* IDC_SYSPARAMS_TOOLTIP */
516 {-1, COLOR_INFOTEXT
, "InfoText" }, /* IDC_SYSPARAMS_TOOLTIP_TEXT */
517 {-1, COLOR_WINDOW
, "Window" }, /* IDC_SYSPARAMS_WINDOW */
518 {-1, COLOR_WINDOWTEXT
, "WindowText" }, /* IDC_SYSPARAMS_WINDOW_TEXT */
519 {SM_CXSIZE
, COLOR_ACTIVECAPTION
, "ActiveTitle" }, /* IDC_SYSPARAMS_ACTIVE_TITLE */
520 {-1, COLOR_CAPTIONTEXT
, "TitleText" }, /* IDC_SYSPARAMS_ACTIVE_TITLE_TEXT */
521 {-1, COLOR_INACTIVECAPTION
, "InactiveTitle" }, /* IDC_SYSPARAMS_INACTIVE_TITLE */
522 {-1, COLOR_INACTIVECAPTIONTEXT
,"InactiveTitleText" }, /* IDC_SYSPARAMS_INACTIVE_TITLE_TEXT */
523 {-1, -1, "MsgBoxText" }, /* IDC_SYSPARAMS_MSGBOX_TEXT */
524 {-1, COLOR_APPWORKSPACE
, "AppWorkSpace" }, /* IDC_SYSPARAMS_APPWORKSPACE */
525 {-1, COLOR_WINDOWFRAME
, "WindowFrame" }, /* IDC_SYSPARAMS_WINDOW_FRAME */
526 {-1, COLOR_ACTIVEBORDER
, "ActiveBorder" }, /* IDC_SYSPARAMS_ACTIVE_BORDER */
527 {-1, COLOR_INACTIVEBORDER
, "InactiveBorder" }, /* IDC_SYSPARAMS_INACTIVE_BORDER */
528 {-1, COLOR_BTNSHADOW
, "ButtonShadow" }, /* IDC_SYSPARAMS_BUTTON_SHADOW */
529 {-1, COLOR_GRAYTEXT
, "GrayText" }, /* IDC_SYSPARAMS_GRAY_TEXT */
530 {-1, COLOR_BTNHIGHLIGHT
, "ButtonHilight" }, /* IDC_SYSPARAMS_BUTTON_HIGHLIGHT */
531 {-1, COLOR_3DDKSHADOW
, "ButtonDkShadow" }, /* IDC_SYSPARAMS_BUTTON_DARK_SHADOW */
532 {-1, COLOR_3DLIGHT
, "ButtonLight" }, /* IDC_SYSPARAMS_BUTTON_LIGHT */
533 {-1, COLOR_ALTERNATEBTNFACE
, "ButtonAlternateFace" }, /* IDC_SYSPARAMS_BUTTON_ALTERNATE */
534 {-1, COLOR_HOTLIGHT
, "HotTrackingColor" }, /* IDC_SYSPARAMS_HOT_TRACKING */
535 {-1, COLOR_GRADIENTACTIVECAPTION
, "GradientActiveTitle" }, /* IDC_SYSPARAMS_ACTIVE_TITLE_GRADIENT */
536 {-1, COLOR_GRADIENTINACTIVECAPTION
, "GradientInactiveTitle" }, /* IDC_SYSPARAMS_INACTIVE_TITLE_GRADIENT */
537 {-1, COLOR_MENUHILIGHT
, "MenuHilight" }, /* IDC_SYSPARAMS_MENU_HIGHLIGHT */
538 {-1, COLOR_MENUBAR
, "MenuBar" }, /* IDC_SYSPARAMS_MENUBAR */
541 static void save_sys_color(int idx
, COLORREF clr
)
545 sprintf(buffer
, "%d %d %d", GetRValue (clr
), GetGValue (clr
), GetBValue (clr
));
546 set_reg_key(HKEY_CURRENT_USER
, "Control Panel\\Colors", metrics
[idx
].color_reg
, buffer
);
549 static void set_color_from_theme(WCHAR
*keyName
, COLORREF color
)
551 char *keyNameA
= NULL
;
552 int keyNameSize
=0, i
=0;
554 keyNameSize
= WideCharToMultiByte(CP_ACP
, 0, keyName
, -1, keyNameA
, 0, NULL
, NULL
);
555 keyNameA
= HeapAlloc(GetProcessHeap(), 0, keyNameSize
);
556 WideCharToMultiByte(CP_ACP
, 0, keyName
, -1, keyNameA
, keyNameSize
, NULL
, NULL
);
558 for (i
=0; i
< ARRAY_SIZE(metrics
); i
++)
560 if (lstrcmpiA(metrics
[i
].color_reg
, keyNameA
)==0)
562 metrics
[i
].color
= color
;
563 save_sys_color(i
, color
);
567 HeapFree(GetProcessHeap(), 0, keyNameA
);
570 static void do_parse_theme(WCHAR
*file
)
572 static const WCHAR colorSect
[] = {
573 'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\',
574 'C','o','l','o','r','s',0};
575 WCHAR keyName
[MAX_PATH
], keyNameValue
[MAX_PATH
];
576 WCHAR
*keyNamePtr
= NULL
;
577 char *keyNameValueA
= NULL
;
578 int keyNameValueSize
= 0;
579 int red
= 0, green
= 0, blue
= 0;
582 WINE_TRACE("%s\n", wine_dbgstr_w(file
));
584 GetPrivateProfileStringW(colorSect
, NULL
, NULL
, keyName
,
587 keyNamePtr
= keyName
;
588 while (*keyNamePtr
!=0) {
589 GetPrivateProfileStringW(colorSect
, keyNamePtr
, NULL
, keyNameValue
,
592 keyNameValueSize
= WideCharToMultiByte(CP_ACP
, 0, keyNameValue
, -1,
593 keyNameValueA
, 0, NULL
, NULL
);
594 keyNameValueA
= HeapAlloc(GetProcessHeap(), 0, keyNameValueSize
);
595 WideCharToMultiByte(CP_ACP
, 0, keyNameValue
, -1, keyNameValueA
, keyNameValueSize
, NULL
, NULL
);
597 WINE_TRACE("parsing key: %s with value: %s\n",
598 wine_dbgstr_w(keyNamePtr
), wine_dbgstr_w(keyNameValue
));
600 sscanf(keyNameValueA
, "%d %d %d", &red
, &green
, &blue
);
602 color
= RGB((BYTE
)red
, (BYTE
)green
, (BYTE
)blue
);
604 HeapFree(GetProcessHeap(), 0, keyNameValueA
);
606 set_color_from_theme(keyNamePtr
, color
);
608 keyNamePtr
+=lstrlenW(keyNamePtr
);
613 static void on_theme_install(HWND dialog
)
615 static const WCHAR filterMask
[] = {0,'*','.','m','s','s','t','y','l','e','s',';',
616 '*','.','t','h','e','m','e',0,0};
617 static const WCHAR themeExt
[] = {'.','T','h','e','m','e',0};
618 const int filterMaskLen
= ARRAY_SIZE(filterMask
);
620 WCHAR filetitle
[MAX_PATH
];
621 WCHAR file
[MAX_PATH
];
625 LoadStringW(GetModuleHandleW(NULL
), IDS_THEMEFILE
, filter
, ARRAY_SIZE(filter
) - filterMaskLen
);
626 memcpy(filter
+ lstrlenW (filter
), filterMask
, filterMaskLen
* sizeof (WCHAR
));
627 LoadStringW(GetModuleHandleW(NULL
), IDS_THEMEFILE_SELECT
, title
, ARRAY_SIZE(title
));
629 ofn
.lStructSize
= sizeof(OPENFILENAMEW
);
630 ofn
.hwndOwner
= dialog
;
632 ofn
.lpstrFilter
= filter
;
633 ofn
.lpstrCustomFilter
= NULL
;
634 ofn
.nMaxCustFilter
= 0;
635 ofn
.nFilterIndex
= 0;
636 ofn
.lpstrFile
= file
;
637 ofn
.lpstrFile
[0] = '\0';
638 ofn
.nMaxFile
= ARRAY_SIZE(file
);
639 ofn
.lpstrFileTitle
= filetitle
;
640 ofn
.lpstrFileTitle
[0] = '\0';
641 ofn
.nMaxFileTitle
= ARRAY_SIZE(filetitle
);
642 ofn
.lpstrInitialDir
= NULL
;
643 ofn
.lpstrTitle
= title
;
644 ofn
.Flags
= OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST
| OFN_HIDEREADONLY
| OFN_ENABLESIZING
;
646 ofn
.nFileExtension
= 0;
647 ofn
.lpstrDefExt
= NULL
;
650 ofn
.lpTemplateName
= NULL
;
652 if (GetOpenFileNameW(&ofn
))
654 static const WCHAR themesSubdir
[] = { '\\','T','h','e','m','e','s',0 };
655 static const WCHAR backslash
[] = { '\\',0 };
656 WCHAR themeFilePath
[MAX_PATH
];
657 SHFILEOPSTRUCTW shfop
;
659 if (FAILED (SHGetFolderPathW (NULL
, CSIDL_RESOURCES
|CSIDL_FLAG_CREATE
, NULL
,
660 SHGFP_TYPE_CURRENT
, themeFilePath
))) return;
662 if (lstrcmpiW(PathFindExtensionW(filetitle
), themeExt
)==0)
664 do_parse_theme(file
);
665 SendMessageW(GetParent(dialog
), PSM_CHANGED
, 0, 0);
669 PathRemoveExtensionW (filetitle
);
671 /* Construct path into which the theme file goes */
672 lstrcatW (themeFilePath
, themesSubdir
);
673 lstrcatW (themeFilePath
, backslash
);
674 lstrcatW (themeFilePath
, filetitle
);
676 /* Create the directory */
677 SHCreateDirectoryExW (dialog
, themeFilePath
, NULL
);
679 /* Append theme file name itself */
680 lstrcatW (themeFilePath
, backslash
);
681 lstrcatW (themeFilePath
, PathFindFileNameW (file
));
682 /* SHFileOperation() takes lists as input, so double-nullterminate */
683 themeFilePath
[lstrlenW (themeFilePath
)+1] = 0;
684 file
[lstrlenW (file
)+1] = 0;
687 WINE_TRACE("copying: %s -> %s\n", wine_dbgstr_w (file
),
688 wine_dbgstr_w (themeFilePath
));
690 shfop
.wFunc
= FO_COPY
;
692 shfop
.pTo
= themeFilePath
;
693 shfop
.fFlags
= FOF_NOCONFIRMMKDIR
;
694 if (SHFileOperationW (&shfop
) == 0)
697 if (!fill_theme_list (GetDlgItem (dialog
, IDC_THEME_THEMECOMBO
),
698 GetDlgItem (dialog
, IDC_THEME_COLORCOMBO
),
699 GetDlgItem (dialog
, IDC_THEME_SIZECOMBO
)))
701 SendMessageW (GetDlgItem (dialog
, IDC_THEME_COLORCOMBO
), CB_SETCURSEL
, -1, 0);
702 SendMessageW (GetDlgItem (dialog
, IDC_THEME_SIZECOMBO
), CB_SETCURSEL
, -1, 0);
703 enable_size_and_color_controls (dialog
, FALSE
);
707 enable_size_and_color_controls (dialog
, TRUE
);
711 WINE_TRACE("copy operation failed\n");
713 else WINE_TRACE("user cancelled\n");
716 /* Information about symbolic link targets of certain User Shell Folders. */
717 struct ShellFolderInfo
{
719 char szLinkTarget
[FILENAME_MAX
]; /* in unix locale */
722 static struct ShellFolderInfo asfiInfo
[] = {
723 { CSIDL_DESKTOP
, "" },
724 { CSIDL_PERSONAL
, "" },
725 { CSIDL_MYPICTURES
, "" },
726 { CSIDL_MYMUSIC
, "" },
727 { CSIDL_MYVIDEO
, "" }
730 static struct ShellFolderInfo
*psfiSelected
= NULL
;
732 static void init_shell_folder_listview_headers(HWND dialog
) {
733 LVCOLUMNW listColumn
;
735 WCHAR szShellFolder
[64] = {'S','h','e','l','l',' ','F','o','l','d','e','r',0};
736 WCHAR szLinksTo
[64] = {'L','i','n','k','s',' ','t','o',0};
739 LoadStringW(GetModuleHandleW(NULL
), IDS_SHELL_FOLDER
, szShellFolder
, ARRAY_SIZE(szShellFolder
));
740 LoadStringW(GetModuleHandleW(NULL
), IDS_LINKS_TO
, szLinksTo
, ARRAY_SIZE(szLinksTo
));
742 GetClientRect(GetDlgItem(dialog
, IDC_LIST_SFPATHS
), &viewRect
);
743 width
= (viewRect
.right
- viewRect
.left
) / 3;
745 listColumn
.mask
= LVCF_TEXT
| LVCF_WIDTH
| LVCF_SUBITEM
;
746 listColumn
.pszText
= szShellFolder
;
747 listColumn
.cchTextMax
= strlenW(listColumn
.pszText
);
748 listColumn
.cx
= width
;
750 SendDlgItemMessageW(dialog
, IDC_LIST_SFPATHS
, LVM_INSERTCOLUMNW
, 0, (LPARAM
) &listColumn
);
752 listColumn
.pszText
= szLinksTo
;
753 listColumn
.cchTextMax
= strlenW(listColumn
.pszText
);
754 listColumn
.cx
= viewRect
.right
- viewRect
.left
- width
- 1;
756 SendDlgItemMessageW(dialog
, IDC_LIST_SFPATHS
, LVM_INSERTCOLUMNW
, 1, (LPARAM
) &listColumn
);
759 /* Reads the currently set shell folder symbol link targets into asfiInfo. */
760 static void read_shell_folder_link_targets(void) {
761 WCHAR wszPath
[MAX_PATH
];
765 for (i
=0; i
<ARRAY_SIZE(asfiInfo
); i
++) {
766 asfiInfo
[i
].szLinkTarget
[0] = '\0';
767 hr
= SHGetFolderPathW(NULL
, asfiInfo
[i
].nFolder
|CSIDL_FLAG_DONT_VERIFY
, NULL
,
768 SHGFP_TYPE_CURRENT
, wszPath
);
770 char *pszUnixPath
= wine_get_unix_file_name(wszPath
);
772 struct stat statPath
;
773 if (!lstat(pszUnixPath
, &statPath
) && S_ISLNK(statPath
.st_mode
)) {
774 int cLen
= readlink(pszUnixPath
, asfiInfo
[i
].szLinkTarget
, FILENAME_MAX
-1);
775 if (cLen
>= 0) asfiInfo
[i
].szLinkTarget
[cLen
] = '\0';
777 HeapFree(GetProcessHeap(), 0, pszUnixPath
);
783 static void update_shell_folder_listview(HWND dialog
) {
786 LONG lSelected
= SendDlgItemMessageW(dialog
, IDC_LIST_SFPATHS
, LVM_GETNEXTITEM
, -1,
787 MAKELPARAM(LVNI_SELECTED
,0));
789 SendDlgItemMessageW(dialog
, IDC_LIST_SFPATHS
, LVM_DELETEALLITEMS
, 0, 0);
791 for (i
=0; i
<ARRAY_SIZE(asfiInfo
); i
++) {
792 WCHAR buffer
[MAX_PATH
];
794 LPITEMIDLIST pidlCurrent
;
796 /* Some acrobatic to get the localized name of the shell folder */
797 hr
= SHGetFolderLocation(dialog
, asfiInfo
[i
].nFolder
, NULL
, 0, &pidlCurrent
);
799 LPSHELLFOLDER psfParent
;
800 LPCITEMIDLIST pidlLast
;
801 hr
= SHBindToParent(pidlCurrent
, &IID_IShellFolder
, (LPVOID
*)&psfParent
, &pidlLast
);
804 hr
= IShellFolder_GetDisplayNameOf(psfParent
, pidlLast
, SHGDN_FORADDRESSBAR
, &strRet
);
806 hr
= StrRetToBufW(&strRet
, pidlLast
, buffer
, MAX_PATH
);
808 IShellFolder_Release(psfParent
);
813 /* If there's a dangling symlink for the current shell folder, SHGetFolderLocation
814 * will fail above. We fall back to the (non-verified) path of the shell folder. */
816 hr
= SHGetFolderPathW(dialog
, asfiInfo
[i
].nFolder
|CSIDL_FLAG_DONT_VERIFY
, NULL
,
817 SHGFP_TYPE_CURRENT
, buffer
);
820 item
.mask
= LVIF_TEXT
| LVIF_PARAM
;
823 item
.pszText
= buffer
;
824 item
.lParam
= (LPARAM
)&asfiInfo
[i
];
825 SendDlgItemMessageW(dialog
, IDC_LIST_SFPATHS
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
827 item
.mask
= LVIF_TEXT
;
830 item
.pszText
= strdupU2W(asfiInfo
[i
].szLinkTarget
);
831 SendDlgItemMessageW(dialog
, IDC_LIST_SFPATHS
, LVM_SETITEMW
, 0, (LPARAM
)&item
);
832 HeapFree(GetProcessHeap(), 0, item
.pszText
);
835 /* Ensure that the previously selected item is selected again. */
836 if (lSelected
>= 0) {
837 item
.mask
= LVIF_STATE
;
838 item
.state
= LVIS_SELECTED
;
839 item
.stateMask
= LVIS_SELECTED
;
840 SendDlgItemMessageW(dialog
, IDC_LIST_SFPATHS
, LVM_SETITEMSTATE
, lSelected
, (LPARAM
)&item
);
844 static void on_shell_folder_selection_changed(HWND hDlg
, LPNMLISTVIEW lpnm
) {
845 if (lpnm
->uNewState
& LVIS_SELECTED
) {
846 psfiSelected
= (struct ShellFolderInfo
*)lpnm
->lParam
;
847 EnableWindow(GetDlgItem(hDlg
, IDC_LINK_SFPATH
), 1);
848 if (strlen(psfiSelected
->szLinkTarget
)) {
850 CheckDlgButton(hDlg
, IDC_LINK_SFPATH
, BST_CHECKED
);
851 EnableWindow(GetDlgItem(hDlg
, IDC_EDIT_SFPATH
), 1);
852 EnableWindow(GetDlgItem(hDlg
, IDC_BROWSE_SFPATH
), 1);
853 link
= strdupU2W(psfiSelected
->szLinkTarget
);
854 set_textW(hDlg
, IDC_EDIT_SFPATH
, link
);
855 HeapFree(GetProcessHeap(), 0, link
);
857 CheckDlgButton(hDlg
, IDC_LINK_SFPATH
, BST_UNCHECKED
);
858 EnableWindow(GetDlgItem(hDlg
, IDC_EDIT_SFPATH
), 0);
859 EnableWindow(GetDlgItem(hDlg
, IDC_BROWSE_SFPATH
), 0);
860 set_text(hDlg
, IDC_EDIT_SFPATH
, "");
864 CheckDlgButton(hDlg
, IDC_LINK_SFPATH
, BST_UNCHECKED
);
865 set_text(hDlg
, IDC_EDIT_SFPATH
, "");
866 EnableWindow(GetDlgItem(hDlg
, IDC_LINK_SFPATH
), 0);
867 EnableWindow(GetDlgItem(hDlg
, IDC_EDIT_SFPATH
), 0);
868 EnableWindow(GetDlgItem(hDlg
, IDC_BROWSE_SFPATH
), 0);
872 /* Keep the contents of the edit control, the listview control and the symlink
873 * information in sync. */
874 static void on_shell_folder_edit_changed(HWND hDlg
) {
876 WCHAR
*text
= get_textW(hDlg
, IDC_EDIT_SFPATH
);
877 LONG iSel
= SendDlgItemMessageW(hDlg
, IDC_LIST_SFPATHS
, LVM_GETNEXTITEM
, -1,
878 MAKELPARAM(LVNI_SELECTED
,0));
880 if (!text
|| !psfiSelected
|| iSel
< 0) {
881 HeapFree(GetProcessHeap(), 0, text
);
885 WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1,
886 psfiSelected
->szLinkTarget
, FILENAME_MAX
, NULL
, NULL
);
888 item
.mask
= LVIF_TEXT
;
892 SendDlgItemMessageW(hDlg
, IDC_LIST_SFPATHS
, LVM_SETITEMW
, 0, (LPARAM
)&item
);
894 HeapFree(GetProcessHeap(), 0, text
);
896 SendMessageW(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
899 static void apply_shell_folder_changes(void) {
900 WCHAR wszPath
[MAX_PATH
];
901 char szBackupPath
[FILENAME_MAX
], szUnixPath
[FILENAME_MAX
], *pszUnixPath
= NULL
;
903 struct stat statPath
;
906 for (i
=0; i
<ARRAY_SIZE(asfiInfo
); i
++) {
907 /* Ignore nonexistent link targets */
908 if (asfiInfo
[i
].szLinkTarget
[0] && stat(asfiInfo
[i
].szLinkTarget
, &statPath
))
911 hr
= SHGetFolderPathW(NULL
, asfiInfo
[i
].nFolder
|CSIDL_FLAG_CREATE
, NULL
,
912 SHGFP_TYPE_CURRENT
, wszPath
);
913 if (FAILED(hr
)) continue;
915 /* Retrieve the corresponding unix path. */
916 pszUnixPath
= wine_get_unix_file_name(wszPath
);
917 if (!pszUnixPath
) continue;
918 lstrcpyA(szUnixPath
, pszUnixPath
);
919 HeapFree(GetProcessHeap(), 0, pszUnixPath
);
921 /* Derive name for folder backup. */
922 lstrcpyA(szBackupPath
, szUnixPath
);
923 lstrcatA(szBackupPath
, ".winecfg");
925 if (lstat(szUnixPath
, &statPath
)) continue;
927 /* Move old folder/link out of the way. */
928 if (S_ISLNK(statPath
.st_mode
)) {
929 if (unlink(szUnixPath
)) continue; /* Unable to remove link. */
931 if (!*asfiInfo
[i
].szLinkTarget
) {
932 continue; /* We are done. Old was real folder, as new shall be. */
934 if (rename(szUnixPath
, szBackupPath
)) { /* Move folder out of the way. */
935 continue; /* Unable to move old folder. */
940 /* Create new link/folder. */
941 if (*asfiInfo
[i
].szLinkTarget
) {
942 symlink(asfiInfo
[i
].szLinkTarget
, szUnixPath
);
944 /* If there's a backup folder, restore it. Else create new folder. */
945 if (!lstat(szBackupPath
, &statPath
) && S_ISDIR(statPath
.st_mode
)) {
946 rename(szBackupPath
, szUnixPath
);
948 mkdir(szUnixPath
, 0777);
954 static void refresh_sysparams(HWND hDlg
)
958 for (i
= 0; i
< ARRAY_SIZE(metrics
); i
++)
960 if (metrics
[i
].sm_idx
!= -1)
961 metrics
[i
].size
= GetSystemMetrics(metrics
[i
].sm_idx
);
962 if (metrics
[i
].color_idx
!= -1)
963 metrics
[i
].color
= GetSysColor(metrics
[i
].color_idx
);
966 on_sysparam_change(hDlg
);
969 static void read_sysparams(HWND hDlg
)
972 HWND list
= GetDlgItem(hDlg
, IDC_SYSPARAM_COMBO
);
973 NONCLIENTMETRICSW nonclient_metrics
;
976 for (i
= 0; i
< ARRAY_SIZE(metrics
); i
++)
978 LoadStringW(GetModuleHandleW(NULL
), i
+ IDC_SYSPARAMS_BUTTON
, buffer
, ARRAY_SIZE(buffer
));
979 idx
= SendMessageW(list
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
980 if (idx
!= CB_ERR
) SendMessageW(list
, CB_SETITEMDATA
, idx
, i
);
982 if (metrics
[i
].sm_idx
!= -1)
983 metrics
[i
].size
= GetSystemMetrics(metrics
[i
].sm_idx
);
984 if (metrics
[i
].color_idx
!= -1)
985 metrics
[i
].color
= GetSysColor(metrics
[i
].color_idx
);
988 nonclient_metrics
.cbSize
= sizeof(NONCLIENTMETRICSW
);
989 SystemParametersInfoW(SPI_GETNONCLIENTMETRICS
, sizeof(NONCLIENTMETRICSW
), &nonclient_metrics
, 0);
991 memcpy(&(metrics
[IDC_SYSPARAMS_MENU_TEXT
- IDC_SYSPARAMS_BUTTON
].lf
),
992 &(nonclient_metrics
.lfMenuFont
), sizeof(LOGFONTW
));
993 memcpy(&(metrics
[IDC_SYSPARAMS_ACTIVE_TITLE_TEXT
- IDC_SYSPARAMS_BUTTON
].lf
),
994 &(nonclient_metrics
.lfCaptionFont
), sizeof(LOGFONTW
));
995 memcpy(&(metrics
[IDC_SYSPARAMS_TOOLTIP_TEXT
- IDC_SYSPARAMS_BUTTON
].lf
),
996 &(nonclient_metrics
.lfStatusFont
), sizeof(LOGFONTW
));
997 memcpy(&(metrics
[IDC_SYSPARAMS_MSGBOX_TEXT
- IDC_SYSPARAMS_BUTTON
].lf
),
998 &(nonclient_metrics
.lfMessageFont
), sizeof(LOGFONTW
));
1001 static void apply_sysparams(void)
1003 NONCLIENTMETRICSW ncm
;
1005 int colors_idx
[ARRAY_SIZE(metrics
)];
1006 COLORREF colors
[ARRAY_SIZE(metrics
)];
1011 dpi
= GetDeviceCaps( hdc
, LOGPIXELSY
);
1012 ReleaseDC( 0, hdc
);
1014 ncm
.cbSize
= sizeof(ncm
);
1015 SystemParametersInfoW(SPI_GETNONCLIENTMETRICS
, sizeof(ncm
), &ncm
, 0);
1017 /* convert metrics back to twips */
1018 ncm
.iMenuWidth
= ncm
.iMenuHeight
=
1019 MulDiv( metrics
[IDC_SYSPARAMS_MENU
- IDC_SYSPARAMS_BUTTON
].size
, -1440, dpi
);
1020 ncm
.iCaptionWidth
= ncm
.iCaptionHeight
=
1021 MulDiv( metrics
[IDC_SYSPARAMS_ACTIVE_TITLE
- IDC_SYSPARAMS_BUTTON
].size
, -1440, dpi
);
1022 ncm
.iScrollWidth
= ncm
.iScrollHeight
=
1023 MulDiv( metrics
[IDC_SYSPARAMS_SCROLLBAR
- IDC_SYSPARAMS_BUTTON
].size
, -1440, dpi
);
1024 ncm
.iSmCaptionWidth
= MulDiv( ncm
.iSmCaptionWidth
, -1440, dpi
);
1025 ncm
.iSmCaptionHeight
= MulDiv( ncm
.iSmCaptionHeight
, -1440, dpi
);
1027 ncm
.lfMenuFont
= metrics
[IDC_SYSPARAMS_MENU_TEXT
- IDC_SYSPARAMS_BUTTON
].lf
;
1028 ncm
.lfCaptionFont
= metrics
[IDC_SYSPARAMS_ACTIVE_TITLE_TEXT
- IDC_SYSPARAMS_BUTTON
].lf
;
1029 ncm
.lfStatusFont
= metrics
[IDC_SYSPARAMS_TOOLTIP_TEXT
- IDC_SYSPARAMS_BUTTON
].lf
;
1030 ncm
.lfMessageFont
= metrics
[IDC_SYSPARAMS_MSGBOX_TEXT
- IDC_SYSPARAMS_BUTTON
].lf
;
1032 ncm
.lfMenuFont
.lfHeight
= MulDiv( ncm
.lfMenuFont
.lfHeight
, -72, dpi
);
1033 ncm
.lfCaptionFont
.lfHeight
= MulDiv( ncm
.lfCaptionFont
.lfHeight
, -72, dpi
);
1034 ncm
.lfStatusFont
.lfHeight
= MulDiv( ncm
.lfStatusFont
.lfHeight
, -72, dpi
);
1035 ncm
.lfMessageFont
.lfHeight
= MulDiv( ncm
.lfMessageFont
.lfHeight
, -72, dpi
);
1036 ncm
.lfSmCaptionFont
.lfHeight
= MulDiv( ncm
.lfSmCaptionFont
.lfHeight
, -72, dpi
);
1038 SystemParametersInfoW(SPI_SETNONCLIENTMETRICS
, sizeof(ncm
), &ncm
,
1039 SPIF_UPDATEINIFILE
| SPIF_SENDCHANGE
);
1041 for (i
= 0; i
< ARRAY_SIZE(metrics
); i
++)
1042 if (metrics
[i
].color_idx
!= -1)
1044 colors_idx
[cnt
] = metrics
[i
].color_idx
;
1045 colors
[cnt
++] = metrics
[i
].color
;
1047 SetSysColors(cnt
, colors_idx
, colors
);
1050 static void on_sysparam_change(HWND hDlg
)
1052 int index
= SendDlgItemMessageW(hDlg
, IDC_SYSPARAM_COMBO
, CB_GETCURSEL
, 0, 0);
1054 index
= SendDlgItemMessageW(hDlg
, IDC_SYSPARAM_COMBO
, CB_GETITEMDATA
, index
, 0);
1058 EnableWindow(GetDlgItem(hDlg
, IDC_SYSPARAM_COLOR_TEXT
), metrics
[index
].color_idx
!= -1);
1059 EnableWindow(GetDlgItem(hDlg
, IDC_SYSPARAM_COLOR
), metrics
[index
].color_idx
!= -1);
1060 InvalidateRect(GetDlgItem(hDlg
, IDC_SYSPARAM_COLOR
), NULL
, TRUE
);
1062 EnableWindow(GetDlgItem(hDlg
, IDC_SYSPARAM_SIZE_TEXT
), metrics
[index
].sm_idx
!= -1);
1063 EnableWindow(GetDlgItem(hDlg
, IDC_SYSPARAM_SIZE
), metrics
[index
].sm_idx
!= -1);
1064 EnableWindow(GetDlgItem(hDlg
, IDC_SYSPARAM_SIZE_UD
), metrics
[index
].sm_idx
!= -1);
1065 if (metrics
[index
].sm_idx
!= -1)
1066 SendDlgItemMessageW(hDlg
, IDC_SYSPARAM_SIZE_UD
, UDM_SETPOS
, 0, MAKELONG(metrics
[index
].size
, 0));
1068 set_text(hDlg
, IDC_SYSPARAM_SIZE
, "");
1070 EnableWindow(GetDlgItem(hDlg
, IDC_SYSPARAM_FONT
),
1071 index
== IDC_SYSPARAMS_MENU_TEXT
-IDC_SYSPARAMS_BUTTON
||
1072 index
== IDC_SYSPARAMS_ACTIVE_TITLE_TEXT
-IDC_SYSPARAMS_BUTTON
||
1073 index
== IDC_SYSPARAMS_TOOLTIP_TEXT
-IDC_SYSPARAMS_BUTTON
||
1074 index
== IDC_SYSPARAMS_MSGBOX_TEXT
-IDC_SYSPARAMS_BUTTON
1077 updating_ui
= FALSE
;
1080 static void on_draw_item(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
1082 static HBRUSH black_brush
= 0;
1083 LPDRAWITEMSTRUCT draw_info
= (LPDRAWITEMSTRUCT
)lParam
;
1085 if (!black_brush
) black_brush
= CreateSolidBrush(0);
1087 if (draw_info
->CtlID
== IDC_SYSPARAM_COLOR
)
1093 theme
= OpenThemeData(NULL
, WC_BUTTONW
);
1098 if (draw_info
->itemState
& ODS_DISABLED
)
1099 state
= PBS_DISABLED
;
1100 else if (draw_info
->itemState
& ODS_SELECTED
)
1101 state
= PBS_PRESSED
;
1105 if (IsThemeBackgroundPartiallyTransparent(theme
, BP_PUSHBUTTON
, state
))
1106 DrawThemeParentBackground(draw_info
->hwndItem
, draw_info
->hDC
, NULL
);
1108 DrawThemeBackground(theme
, draw_info
->hDC
, BP_PUSHBUTTON
, state
, &draw_info
->rcItem
, NULL
);
1110 buttonrect
= draw_info
->rcItem
;
1112 GetThemeMargins(theme
, draw_info
->hDC
, BP_PUSHBUTTON
, state
, TMT_CONTENTMARGINS
, &draw_info
->rcItem
, &margins
);
1114 buttonrect
.left
+= margins
.cxLeftWidth
;
1115 buttonrect
.top
+= margins
.cyTopHeight
;
1116 buttonrect
.right
-= margins
.cxRightWidth
;
1117 buttonrect
.bottom
-= margins
.cyBottomHeight
;
1119 if (draw_info
->itemState
& ODS_FOCUS
)
1120 DrawFocusRect(draw_info
->hDC
, &buttonrect
);
1122 CloseThemeData(theme
);
1124 state
= DFCS_ADJUSTRECT
| DFCS_BUTTONPUSH
;
1126 if (draw_info
->itemState
& ODS_DISABLED
)
1127 state
|= DFCS_INACTIVE
;
1129 state
|= draw_info
->itemState
& ODS_SELECTED
? DFCS_PUSHED
: 0;
1131 DrawFrameControl(draw_info
->hDC
, &draw_info
->rcItem
, DFC_BUTTON
, state
);
1133 buttonrect
= draw_info
->rcItem
;
1136 if (!(draw_info
->itemState
& ODS_DISABLED
))
1139 int index
= SendDlgItemMessageW(hDlg
, IDC_SYSPARAM_COMBO
, CB_GETCURSEL
, 0, 0);
1141 index
= SendDlgItemMessageW(hDlg
, IDC_SYSPARAM_COMBO
, CB_GETITEMDATA
, index
, 0);
1142 brush
= CreateSolidBrush(metrics
[index
].color
);
1144 InflateRect(&buttonrect
, -1, -1);
1145 FrameRect(draw_info
->hDC
, &buttonrect
, black_brush
);
1146 InflateRect(&buttonrect
, -1, -1);
1147 FillRect(draw_info
->hDC
, &buttonrect
, brush
);
1148 DeleteObject(brush
);
1153 static void on_select_font(HWND hDlg
)
1156 int index
= SendDlgItemMessageW(hDlg
, IDC_SYSPARAM_COMBO
, CB_GETCURSEL
, 0, 0);
1157 index
= SendDlgItemMessageW(hDlg
, IDC_SYSPARAM_COMBO
, CB_GETITEMDATA
, index
, 0);
1159 ZeroMemory(&cf
, sizeof(cf
));
1160 cf
.lStructSize
= sizeof(CHOOSEFONTW
);
1161 cf
.hwndOwner
= hDlg
;
1162 cf
.lpLogFont
= &(metrics
[index
].lf
);
1163 cf
.Flags
= CF_SCREENFONTS
| CF_INITTOLOGFONTSTRUCT
| CF_NOSCRIPTSEL
| CF_NOVERTFONTS
;
1165 if (ChooseFontW(&cf
))
1166 SendMessageW(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
1169 static void init_mime_types(HWND hDlg
)
1171 char *buf
= get_reg_key(config_key
, keypath("FileOpenAssociations"), "Enable", "Y");
1172 int state
= IS_OPTION_TRUE(*buf
) ? BST_CHECKED
: BST_UNCHECKED
;
1174 CheckDlgButton(hDlg
, IDC_ENABLE_FILE_ASSOCIATIONS
, state
);
1176 HeapFree(GetProcessHeap(), 0, buf
);
1179 static void update_mime_types(HWND hDlg
)
1181 const char *state
= "Y";
1183 if (IsDlgButtonChecked(hDlg
, IDC_ENABLE_FILE_ASSOCIATIONS
) != BST_CHECKED
)
1186 set_reg_key(config_key
, keypath("FileOpenAssociations"), "Enable", state
);
1190 ThemeDlgProc (HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1194 read_shell_folder_link_targets();
1195 init_shell_folder_listview_headers(hDlg
);
1196 update_shell_folder_listview(hDlg
);
1197 read_sysparams(hDlg
);
1198 init_mime_types(hDlg
);
1206 set_window_title(hDlg
);
1210 switch(HIWORD(wParam
)) {
1211 case CBN_SELCHANGE
: {
1212 if (updating_ui
) break;
1213 switch (LOWORD(wParam
))
1215 case IDC_THEME_THEMECOMBO
: on_theme_changed(hDlg
); break;
1216 case IDC_THEME_COLORCOMBO
: /* fall through */
1217 case IDC_THEME_SIZECOMBO
: theme_dirty
= TRUE
; break;
1218 case IDC_SYSPARAM_COMBO
: on_sysparam_change(hDlg
); return FALSE
;
1220 SendMessageW(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
1224 if (updating_ui
) break;
1225 switch (LOWORD(wParam
))
1227 case IDC_EDIT_SFPATH
: on_shell_folder_edit_changed(hDlg
); break;
1228 case IDC_SYSPARAM_SIZE
:
1230 char *text
= get_text(hDlg
, IDC_SYSPARAM_SIZE
);
1231 int index
= SendDlgItemMessageW(hDlg
, IDC_SYSPARAM_COMBO
, CB_GETCURSEL
, 0, 0);
1233 index
= SendDlgItemMessageW(hDlg
, IDC_SYSPARAM_COMBO
, CB_GETITEMDATA
, index
, 0);
1237 metrics
[index
].size
= atoi(text
);
1238 HeapFree(GetProcessHeap(), 0, text
);
1242 /* for empty string set to minimum value */
1243 SendDlgItemMessageW(hDlg
, IDC_SYSPARAM_SIZE_UD
, UDM_GETRANGE32
, (WPARAM
)&metrics
[index
].size
, 0);
1246 SendMessageW(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
1253 switch (LOWORD(wParam
))
1255 case IDC_THEME_INSTALL
:
1256 on_theme_install (hDlg
);
1259 case IDC_SYSPARAM_FONT
:
1260 on_select_font(hDlg
);
1263 case IDC_BROWSE_SFPATH
:
1265 WCHAR link
[FILENAME_MAX
];
1266 if (browse_for_unix_folder(hDlg
, link
)) {
1267 WideCharToMultiByte(CP_UNIXCP
, 0, link
, -1,
1268 psfiSelected
->szLinkTarget
, FILENAME_MAX
,
1270 update_shell_folder_listview(hDlg
);
1271 SendMessageW(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
1276 case IDC_LINK_SFPATH
:
1277 if (IsDlgButtonChecked(hDlg
, IDC_LINK_SFPATH
)) {
1278 WCHAR link
[FILENAME_MAX
];
1279 if (browse_for_unix_folder(hDlg
, link
)) {
1280 WideCharToMultiByte(CP_UNIXCP
, 0, link
, -1,
1281 psfiSelected
->szLinkTarget
, FILENAME_MAX
,
1283 update_shell_folder_listview(hDlg
);
1284 SendMessageW(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
1286 CheckDlgButton(hDlg
, IDC_LINK_SFPATH
, BST_UNCHECKED
);
1289 psfiSelected
->szLinkTarget
[0] = '\0';
1290 update_shell_folder_listview(hDlg
);
1291 SendMessageW(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
1295 case IDC_SYSPARAM_COLOR
:
1297 static COLORREF user_colors
[16];
1298 CHOOSECOLORW c_color
;
1299 int index
= SendDlgItemMessageW(hDlg
, IDC_SYSPARAM_COMBO
, CB_GETCURSEL
, 0, 0);
1301 index
= SendDlgItemMessageW(hDlg
, IDC_SYSPARAM_COMBO
, CB_GETITEMDATA
, index
, 0);
1303 memset(&c_color
, 0, sizeof(c_color
));
1304 c_color
.lStructSize
= sizeof(c_color
);
1305 c_color
.lpCustColors
= user_colors
;
1306 c_color
.rgbResult
= metrics
[index
].color
;
1307 c_color
.Flags
= CC_ANYCOLOR
| CC_RGBINIT
;
1308 c_color
.hwndOwner
= hDlg
;
1309 if (ChooseColorW(&c_color
))
1311 metrics
[index
].color
= c_color
.rgbResult
;
1312 save_sys_color(index
, metrics
[index
].color
);
1313 InvalidateRect(GetDlgItem(hDlg
, IDC_SYSPARAM_COLOR
), NULL
, TRUE
);
1314 SendMessageW(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
1319 case IDC_ENABLE_FILE_ASSOCIATIONS
:
1320 update_mime_types(hDlg
);
1321 SendMessageW(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
1329 switch (((LPNMHDR
)lParam
)->code
) {
1330 case PSN_KILLACTIVE
: {
1331 SetWindowLongPtrW(hDlg
, DWLP_MSGRESULT
, FALSE
);
1337 apply_shell_folder_changes();
1339 read_shell_folder_link_targets();
1340 update_shell_folder_listview(hDlg
);
1341 update_mime_types(hDlg
);
1342 SetWindowLongPtrW(hDlg
, DWLP_MSGRESULT
, PSNRET_NOERROR
);
1345 case LVN_ITEMCHANGED
: {
1346 if (wParam
== IDC_LIST_SFPATHS
)
1347 on_shell_folder_selection_changed(hDlg
, (LPNMLISTVIEW
)lParam
);
1350 case PSN_SETACTIVE
: {
1358 on_draw_item(hDlg
, wParam
, lParam
);