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
48 #include <wine/debug.h>
49 #include <wine/unicode.h>
54 WINE_DEFAULT_DEBUG_CHANNEL(winecfg
);
56 /* UXTHEME functions not in the headers */
58 typedef struct tagTHEMENAMES
60 WCHAR szName
[MAX_PATH
+1];
61 WCHAR szDisplayName
[MAX_PATH
+1];
62 WCHAR szTooltip
[MAX_PATH
+1];
63 } THEMENAMES
, *PTHEMENAMES
;
65 typedef void* HTHEMEFILE
;
66 typedef BOOL (CALLBACK
*EnumThemeProc
)(LPVOID lpReserved
,
67 LPCWSTR pszThemeFileName
,
69 LPCWSTR pszToolTip
, LPVOID lpReserved2
,
72 HRESULT WINAPI
EnumThemeColors (LPCWSTR pszThemeFileName
, LPWSTR pszSizeName
,
73 DWORD dwColorNum
, PTHEMENAMES pszColorNames
);
74 HRESULT WINAPI
EnumThemeSizes (LPCWSTR pszThemeFileName
, LPWSTR pszColorName
,
75 DWORD dwSizeNum
, PTHEMENAMES pszSizeNames
);
76 HRESULT WINAPI
ApplyTheme (HTHEMEFILE hThemeFile
, char* unknown
, HWND hWnd
);
77 HRESULT WINAPI
OpenThemeFile (LPCWSTR pszThemeFileName
, LPCWSTR pszColorName
,
78 LPCWSTR pszSizeName
, HTHEMEFILE
* hThemeFile
,
80 HRESULT WINAPI
CloseThemeFile (HTHEMEFILE hThemeFile
);
81 HRESULT WINAPI
EnumThemes (LPCWSTR pszThemePath
, EnumThemeProc callback
,
84 /* A struct to keep both the internal and "fancy" name of a color or size */
91 /* wrapper around DSA that also keeps an item count */
98 /* Some helper functions to deal with ThemeColorOrSize structs in WrappedDSAs */
100 static void color_or_size_dsa_add (WrappedDsa
* wdsa
, const WCHAR
* name
,
101 const WCHAR
* fancyName
)
103 ThemeColorOrSize item
;
105 item
.name
= HeapAlloc (GetProcessHeap(), 0,
106 (lstrlenW (name
) + 1) * sizeof(WCHAR
));
107 lstrcpyW (item
.name
, name
);
109 item
.fancyName
= HeapAlloc (GetProcessHeap(), 0,
110 (lstrlenW (fancyName
) + 1) * sizeof(WCHAR
));
111 lstrcpyW (item
.fancyName
, fancyName
);
113 DSA_InsertItem (wdsa
->dsa
, wdsa
->count
, &item
);
117 static int CALLBACK
dsa_destroy_callback (LPVOID p
, LPVOID pData
)
119 ThemeColorOrSize
* item
= (ThemeColorOrSize
*)p
;
120 HeapFree (GetProcessHeap(), 0, item
->name
);
121 HeapFree (GetProcessHeap(), 0, item
->fancyName
);
125 static void free_color_or_size_dsa (WrappedDsa
* wdsa
)
127 DSA_DestroyCallback (wdsa
->dsa
, dsa_destroy_callback
, NULL
);
130 static void create_color_or_size_dsa (WrappedDsa
* wdsa
)
132 wdsa
->dsa
= DSA_Create (sizeof (ThemeColorOrSize
), 1);
136 static ThemeColorOrSize
* color_or_size_dsa_get (WrappedDsa
* wdsa
, int index
)
138 return (ThemeColorOrSize
*)DSA_GetItemPtr (wdsa
->dsa
, index
);
141 static int color_or_size_dsa_find (WrappedDsa
* wdsa
, const WCHAR
* name
)
144 for (; i
< wdsa
->count
; i
++)
146 ThemeColorOrSize
* item
= color_or_size_dsa_get (wdsa
, i
);
147 if (lstrcmpiW (item
->name
, name
) == 0) break;
152 /* A theme file, contains file name, display name, color and size scheme names */
155 WCHAR
* themeFileName
;
161 static HDSA themeFiles
= NULL
;
162 static int themeFilesCount
= 0;
164 static int CALLBACK
theme_dsa_destroy_callback (LPVOID p
, LPVOID pData
)
166 ThemeFile
* item
= (ThemeFile
*)p
;
167 HeapFree (GetProcessHeap(), 0, item
->themeFileName
);
168 HeapFree (GetProcessHeap(), 0, item
->fancyName
);
169 free_color_or_size_dsa (&item
->colors
);
170 free_color_or_size_dsa (&item
->sizes
);
174 /* Free memory occupied by the theme list */
175 static void free_theme_files(void)
177 if (themeFiles
== NULL
) return;
179 DSA_DestroyCallback (themeFiles
, theme_dsa_destroy_callback
, NULL
);
184 typedef HRESULT (WINAPI
* EnumTheme
) (LPCWSTR
, LPWSTR
, DWORD
, PTHEMENAMES
);
186 /* fill a string list with either colors or sizes of a theme */
187 static void fill_theme_string_array (const WCHAR
* filename
,
194 WINE_TRACE ("%s %p %p\n", wine_dbgstr_w (filename
), wdsa
, enumTheme
);
196 while (SUCCEEDED (enumTheme (filename
, NULL
, index
++, &names
)))
198 WINE_TRACE ("%s: %s\n", wine_dbgstr_w (names
.szName
),
199 wine_dbgstr_w (names
.szDisplayName
));
200 color_or_size_dsa_add (wdsa
, names
.szName
, names
.szDisplayName
);
204 /* Theme enumeration callback, adds theme to theme list */
205 static BOOL CALLBACK
myEnumThemeProc (LPVOID lpReserved
,
206 LPCWSTR pszThemeFileName
,
207 LPCWSTR pszThemeName
,
209 LPVOID lpReserved2
, LPVOID lpData
)
213 /* fill size/color lists */
214 create_color_or_size_dsa (&newEntry
.colors
);
215 fill_theme_string_array (pszThemeFileName
, &newEntry
.colors
, EnumThemeColors
);
216 create_color_or_size_dsa (&newEntry
.sizes
);
217 fill_theme_string_array (pszThemeFileName
, &newEntry
.sizes
, EnumThemeSizes
);
219 newEntry
.themeFileName
= HeapAlloc (GetProcessHeap(), 0,
220 (lstrlenW (pszThemeFileName
) + 1) * sizeof(WCHAR
));
221 lstrcpyW (newEntry
.themeFileName
, pszThemeFileName
);
223 newEntry
.fancyName
= HeapAlloc (GetProcessHeap(), 0,
224 (lstrlenW (pszThemeName
) + 1) * sizeof(WCHAR
));
225 lstrcpyW (newEntry
.fancyName
, pszThemeName
);
227 /*list_add_tail (&themeFiles, &newEntry->entry);*/
228 DSA_InsertItem (themeFiles
, themeFilesCount
, &newEntry
);
234 /* Scan for themes */
235 static void scan_theme_files(void)
237 static const WCHAR themesSubdir
[] = { '\\','T','h','e','m','e','s',0 };
238 WCHAR themesPath
[MAX_PATH
];
242 if (FAILED (SHGetFolderPathW (NULL
, CSIDL_RESOURCES
, NULL
,
243 SHGFP_TYPE_CURRENT
, themesPath
))) return;
245 themeFiles
= DSA_Create (sizeof (ThemeFile
), 1);
246 lstrcatW (themesPath
, themesSubdir
);
248 EnumThemes (themesPath
, myEnumThemeProc
, 0);
251 /* fill the color & size combo boxes for a given theme */
252 static void fill_color_size_combos (ThemeFile
* theme
, HWND comboColor
,
257 SendMessageW (comboColor
, CB_RESETCONTENT
, 0, 0);
258 for (i
= 0; i
< theme
->colors
.count
; i
++)
260 ThemeColorOrSize
* item
= color_or_size_dsa_get (&theme
->colors
, i
);
261 SendMessageW (comboColor
, CB_ADDSTRING
, 0, (LPARAM
)item
->fancyName
);
264 SendMessageW (comboSize
, CB_RESETCONTENT
, 0, 0);
265 for (i
= 0; i
< theme
->sizes
.count
; i
++)
267 ThemeColorOrSize
* item
= color_or_size_dsa_get (&theme
->sizes
, i
);
268 SendMessageW (comboSize
, CB_ADDSTRING
, 0, (LPARAM
)item
->fancyName
);
272 /* Select the item of a combo box that matches a theme's color and size
274 static void select_color_and_size (ThemeFile
* theme
,
275 const WCHAR
* colorName
, HWND comboColor
,
276 const WCHAR
* sizeName
, HWND comboSize
)
278 SendMessageW (comboColor
, CB_SETCURSEL
,
279 color_or_size_dsa_find (&theme
->colors
, colorName
), 0);
280 SendMessageW (comboSize
, CB_SETCURSEL
,
281 color_or_size_dsa_find (&theme
->sizes
, sizeName
), 0);
284 /* Fill theme, color and sizes combo boxes with the know themes and select
285 * the entries matching the currently active theme. */
286 static BOOL
fill_theme_list (HWND comboTheme
, HWND comboColor
, HWND comboSize
)
288 WCHAR textNoTheme
[256];
292 WCHAR currentTheme
[MAX_PATH
];
293 WCHAR currentColor
[MAX_PATH
];
294 WCHAR currentSize
[MAX_PATH
];
295 ThemeFile
* theme
= NULL
;
297 LoadStringW (GetModuleHandle (NULL
), IDS_NOTHEME
, textNoTheme
,
298 sizeof(textNoTheme
) / sizeof(WCHAR
));
300 SendMessageW (comboTheme
, CB_RESETCONTENT
, 0, 0);
301 SendMessageW (comboTheme
, CB_ADDSTRING
, 0, (LPARAM
)textNoTheme
);
303 for (i
= 0; i
< themeFilesCount
; i
++)
305 ThemeFile
* item
= DSA_GetItemPtr (themeFiles
, i
);
306 SendMessageW (comboTheme
, CB_ADDSTRING
, 0,
307 (LPARAM
)item
->fancyName
);
310 if (IsThemeActive () && SUCCEEDED (GetCurrentThemeName (currentTheme
,
311 sizeof(currentTheme
) / sizeof(WCHAR
),
312 currentColor
, sizeof(currentColor
) / sizeof(WCHAR
),
313 currentSize
, sizeof(currentSize
) / sizeof(WCHAR
))))
315 /* Determine the index of the currently active theme. */
317 for (i
= 0; i
< themeFilesCount
; i
++)
319 theme
= DSA_GetItemPtr (themeFiles
, i
);
320 if (lstrcmpiW (theme
->themeFileName
, currentTheme
) == 0)
329 /* Current theme not found?... add to the list, then... */
330 WINE_TRACE("Theme %s not in list of enumerated themes\n",
331 wine_dbgstr_w (currentTheme
));
332 myEnumThemeProc (NULL
, currentTheme
, currentTheme
,
333 currentTheme
, NULL
, NULL
);
334 themeIndex
= themeFilesCount
;
335 theme
= DSA_GetItemPtr (themeFiles
, themeFilesCount
-1);
337 fill_color_size_combos (theme
, comboColor
, comboSize
);
338 select_color_and_size (theme
, currentColor
, comboColor
,
339 currentSize
, comboSize
);
343 /* No theme selected */
347 SendMessageW (comboTheme
, CB_SETCURSEL
, themeIndex
, 0);
351 /* Update the color & size combo boxes when the selection of the theme
352 * combo changed. Selects the current color and size scheme if the theme
353 * is currently active, otherwise the first color and size. */
354 static BOOL
update_color_and_size (int themeIndex
, HWND comboColor
,
363 WCHAR currentTheme
[MAX_PATH
];
364 WCHAR currentColor
[MAX_PATH
];
365 WCHAR currentSize
[MAX_PATH
];
366 ThemeFile
* theme
= DSA_GetItemPtr (themeFiles
, themeIndex
- 1);
368 fill_color_size_combos (theme
, comboColor
, comboSize
);
370 if ((SUCCEEDED (GetCurrentThemeName (currentTheme
,
371 sizeof(currentTheme
) / sizeof(WCHAR
),
372 currentColor
, sizeof(currentColor
) / sizeof(WCHAR
),
373 currentSize
, sizeof(currentSize
) / sizeof(WCHAR
))))
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 (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
);
429 static void enable_size_and_color_controls (HWND dialog
, BOOL enable
)
431 EnableWindow (GetDlgItem (dialog
, IDC_THEME_COLORCOMBO
), enable
);
432 EnableWindow (GetDlgItem (dialog
, IDC_THEME_COLORTEXT
), enable
);
433 EnableWindow (GetDlgItem (dialog
, IDC_THEME_SIZECOMBO
), enable
);
434 EnableWindow (GetDlgItem (dialog
, IDC_THEME_SIZETEXT
), enable
);
437 static void init_dialog (HWND dialog
)
442 if (!fill_theme_list (GetDlgItem (dialog
, IDC_THEME_THEMECOMBO
),
443 GetDlgItem (dialog
, IDC_THEME_COLORCOMBO
),
444 GetDlgItem (dialog
, IDC_THEME_SIZECOMBO
)))
446 SendMessageW (GetDlgItem (dialog
, IDC_THEME_COLORCOMBO
), CB_SETCURSEL
, (WPARAM
)-1, 0);
447 SendMessageW (GetDlgItem (dialog
, IDC_THEME_SIZECOMBO
), CB_SETCURSEL
, (WPARAM
)-1, 0);
448 enable_size_and_color_controls (dialog
, FALSE
);
452 enable_size_and_color_controls (dialog
, TRUE
);
456 SendDlgItemMessageW(dialog
, IDC_SYSPARAM_SIZE_UD
, UDM_SETBUDDY
, (WPARAM
)GetDlgItem(dialog
, IDC_SYSPARAM_SIZE
), 0);
457 SendDlgItemMessageW(dialog
, IDC_SYSPARAM_SIZE_UD
, UDM_SETRANGE
, 0, MAKELONG(100, 8));
462 static void on_theme_changed(HWND dialog
) {
463 int index
= SendMessageW (GetDlgItem (dialog
, IDC_THEME_THEMECOMBO
),
465 if (!update_color_and_size (index
, GetDlgItem (dialog
, IDC_THEME_COLORCOMBO
),
466 GetDlgItem (dialog
, IDC_THEME_SIZECOMBO
)))
468 SendMessageW (GetDlgItem (dialog
, IDC_THEME_COLORCOMBO
), CB_SETCURSEL
, (WPARAM
)-1, 0);
469 SendMessageW (GetDlgItem (dialog
, IDC_THEME_SIZECOMBO
), CB_SETCURSEL
, (WPARAM
)-1, 0);
470 enable_size_and_color_controls (dialog
, FALSE
);
474 enable_size_and_color_controls (dialog
, TRUE
);
479 static void apply_theme(HWND dialog
)
481 int themeIndex
, colorIndex
, sizeIndex
;
483 if (!theme_dirty
) return;
485 themeIndex
= SendMessageW (GetDlgItem (dialog
, IDC_THEME_THEMECOMBO
),
487 colorIndex
= SendMessageW (GetDlgItem (dialog
, IDC_THEME_COLORCOMBO
),
489 sizeIndex
= SendMessageW (GetDlgItem (dialog
, IDC_THEME_SIZECOMBO
),
492 do_apply_theme (themeIndex
, colorIndex
, sizeIndex
);
498 int sm_idx
, color_idx
;
499 const char *color_reg
;
505 {-1, COLOR_BTNFACE
, "ButtonFace" }, /* IDC_SYSPARAMS_BUTTON */
506 {-1, COLOR_BTNTEXT
, "ButtonText" }, /* IDC_SYSPARAMS_BUTTON_TEXT */
507 {-1, COLOR_BACKGROUND
, "Background" }, /* IDC_SYSPARAMS_DESKTOP */
508 {SM_CXMENUSIZE
, COLOR_MENU
, "Menu" }, /* IDC_SYSPARAMS_MENU */
509 {-1, COLOR_MENUTEXT
, "MenuText" }, /* IDC_SYSPARAMS_MENU_TEXT */
510 {SM_CXVSCROLL
, COLOR_SCROLLBAR
, "Scrollbar" }, /* IDC_SYSPARAMS_SCROLLBAR */
511 {-1, COLOR_HIGHLIGHT
, "Hilight" }, /* IDC_SYSPARAMS_SELECTION */
512 {-1, COLOR_HIGHLIGHTTEXT
, "HilightText" }, /* IDC_SYSPARAMS_SELECTION_TEXT */
513 {-1, COLOR_INFOBK
, "InfoWindow" }, /* IDC_SYSPARAMS_TOOLTIP */
514 {-1, COLOR_INFOTEXT
, "InfoText" }, /* IDC_SYSPARAMS_TOOLTIP_TEXT */
515 {-1, COLOR_WINDOW
, "Window" }, /* IDC_SYSPARAMS_WINDOW */
516 {-1, COLOR_WINDOWTEXT
, "WindowText" }, /* IDC_SYSPARAMS_WINDOW_TEXT */
517 {SM_CXSIZE
, COLOR_ACTIVECAPTION
, "ActiveTitle" }, /* IDC_SYSPARAMS_ACTIVE_TITLE */
518 {-1, COLOR_CAPTIONTEXT
, "TitleText" }, /* IDC_SYSPARAMS_ACTIVE_TITLE_TEXT */
519 {-1, COLOR_INACTIVECAPTION
, "InactiveTitle" }, /* IDC_SYSPARAMS_INACTIVE_TITLE */
520 {-1, COLOR_INACTIVECAPTIONTEXT
,"InactiveTitleText" }, /* IDC_SYSPARAMS_INACTIVE_TITLE_TEXT */
521 {-1, -1, "MsgBoxText" }, /* IDC_SYSPARAMS_MSGBOX_TEXT */
522 {-1, COLOR_APPWORKSPACE
, "AppWorkSpace" }, /* IDC_SYSPARAMS_APPWORKSPACE */
523 {-1, COLOR_WINDOWFRAME
, "WindowFrame" }, /* IDC_SYSPARAMS_WINDOW_FRAME */
524 {-1, COLOR_ACTIVEBORDER
, "ActiveBorder" }, /* IDC_SYSPARAMS_ACTIVE_BORDER */
525 {-1, COLOR_INACTIVEBORDER
, "InactiveBorder" }, /* IDC_SYSPARAMS_INACTIVE_BORDER */
526 {-1, COLOR_BTNSHADOW
, "ButtonShadow" }, /* IDC_SYSPARAMS_BUTTON_SHADOW */
527 {-1, COLOR_GRAYTEXT
, "GrayText" }, /* IDC_SYSPARAMS_GRAY_TEXT */
528 {-1, COLOR_BTNHILIGHT
, "ButtonHilight" }, /* IDC_SYSPARAMS_BUTTON_HILIGHT */
529 {-1, COLOR_3DDKSHADOW
, "ButtonDkShadow" }, /* IDC_SYSPARAMS_BUTTON_DARK_SHADOW */
530 {-1, COLOR_3DLIGHT
, "ButtonLight" }, /* IDC_SYSPARAMS_BUTTON_LIGHT */
531 {-1, COLOR_ALTERNATEBTNFACE
, "ButtonAlternateFace" }, /* IDC_SYSPARAMS_BUTTON_ALTERNATE */
532 {-1, COLOR_HOTLIGHT
, "HotTrackingColor" }, /* IDC_SYSPARAMS_HOT_TRACKING */
533 {-1, COLOR_GRADIENTACTIVECAPTION
, "GradientActiveTitle" }, /* IDC_SYSPARAMS_ACTIVE_TITLE_GRADIENT */
534 {-1, COLOR_GRADIENTINACTIVECAPTION
, "GradientInactiveTitle" }, /* IDC_SYSPARAMS_INACTIVE_TITLE_GRADIENT */
535 {-1, COLOR_MENUHILIGHT
, "MenuHilight" }, /* IDC_SYSPARAMS_MENU_HILIGHT */
536 {-1, COLOR_MENUBAR
, "MenuBar" }, /* IDC_SYSPARAMS_MENUBAR */
539 static void save_sys_color(int idx
, COLORREF clr
)
543 sprintf(buffer
, "%d %d %d", GetRValue (clr
), GetGValue (clr
), GetBValue (clr
));
544 set_reg_key(HKEY_CURRENT_USER
, "Control Panel\\Colors", metrics
[idx
].color_reg
, buffer
);
547 static void set_color_from_theme(WCHAR
*keyName
, COLORREF color
)
549 char *keyNameA
= NULL
;
550 int keyNameSize
=0, i
=0;
552 keyNameSize
= WideCharToMultiByte(CP_ACP
, 0, keyName
, -1, keyNameA
, 0, NULL
, NULL
);
553 keyNameA
= HeapAlloc(GetProcessHeap(), 0, keyNameSize
);
554 WideCharToMultiByte(CP_ACP
, 0, keyName
, -1, keyNameA
, keyNameSize
, NULL
, NULL
);
556 for (i
=0; i
<sizeof(metrics
)/sizeof(metrics
[0]); i
++)
558 if (lstrcmpiA(metrics
[i
].color_reg
, keyNameA
)==0)
560 metrics
[i
].color
= color
;
561 save_sys_color(i
, color
);
565 HeapFree(GetProcessHeap(), 0, keyNameA
);
568 static void do_parse_theme(WCHAR
*file
)
570 static const WCHAR colorSect
[] = {
571 'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\',
572 'C','o','l','o','r','s',0};
573 WCHAR keyName
[MAX_PATH
], keyNameValue
[MAX_PATH
];
574 WCHAR
*keyNamePtr
= NULL
;
575 char *keyNameValueA
= NULL
;
576 int keyNameValueSize
= 0;
577 int red
= 0, green
= 0, blue
= 0;
580 WINE_TRACE("%s\n", wine_dbgstr_w(file
));
582 GetPrivateProfileStringW(colorSect
, NULL
, NULL
, keyName
,
585 keyNamePtr
= keyName
;
586 while (*keyNamePtr
!=0) {
587 GetPrivateProfileStringW(colorSect
, keyNamePtr
, NULL
, keyNameValue
,
590 keyNameValueSize
= WideCharToMultiByte(CP_ACP
, 0, keyNameValue
, -1,
591 keyNameValueA
, 0, NULL
, NULL
);
592 keyNameValueA
= HeapAlloc(GetProcessHeap(), 0, keyNameValueSize
);
593 WideCharToMultiByte(CP_ACP
, 0, keyNameValue
, -1, keyNameValueA
, keyNameValueSize
, NULL
, NULL
);
595 WINE_TRACE("parsing key: %s with value: %s\n",
596 wine_dbgstr_w(keyNamePtr
), wine_dbgstr_w(keyNameValue
));
598 sscanf(keyNameValueA
, "%d %d %d", &red
, &green
, &blue
);
600 color
= RGB((BYTE
)red
, (BYTE
)green
, (BYTE
)blue
);
602 HeapFree(GetProcessHeap(), 0, keyNameValueA
);
604 set_color_from_theme(keyNamePtr
, color
);
606 keyNamePtr
+=lstrlenW(keyNamePtr
);
611 static void on_theme_install(HWND dialog
)
613 static const WCHAR filterMask
[] = {0,'*','.','m','s','s','t','y','l','e','s',';',
614 '*','.','t','h','e','m','e',0,0};
615 static const WCHAR themeExt
[] = {'.','T','h','e','m','e',0};
616 const int filterMaskLen
= sizeof(filterMask
)/sizeof(filterMask
[0]);
618 WCHAR filetitle
[MAX_PATH
];
619 WCHAR file
[MAX_PATH
];
623 LoadStringW (GetModuleHandle (NULL
), IDS_THEMEFILE
,
624 filter
, sizeof (filter
) / sizeof (filter
[0]) - filterMaskLen
);
625 memcpy (filter
+ lstrlenW (filter
), filterMask
,
626 filterMaskLen
* sizeof (WCHAR
));
627 LoadStringW (GetModuleHandle (NULL
), IDS_THEMEFILE_SELECT
,
628 title
, sizeof (title
) / sizeof (title
[0]));
630 ofn
.lStructSize
= sizeof(OPENFILENAMEW
);
633 ofn
.lpstrFilter
= filter
;
634 ofn
.lpstrCustomFilter
= NULL
;
635 ofn
.nMaxCustFilter
= 0;
636 ofn
.nFilterIndex
= 0;
637 ofn
.lpstrFile
= file
;
638 ofn
.lpstrFile
[0] = '\0';
639 ofn
.nMaxFile
= sizeof(file
)/sizeof(filetitle
[0]);
640 ofn
.lpstrFileTitle
= filetitle
;
641 ofn
.lpstrFileTitle
[0] = '\0';
642 ofn
.nMaxFileTitle
= sizeof(filetitle
)/sizeof(filetitle
[0]);
643 ofn
.lpstrInitialDir
= NULL
;
644 ofn
.lpstrTitle
= title
;
645 ofn
.Flags
= OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST
| OFN_HIDEREADONLY
;
647 ofn
.nFileExtension
= 0;
648 ofn
.lpstrDefExt
= NULL
;
651 ofn
.lpTemplateName
= NULL
;
653 if (GetOpenFileNameW(&ofn
))
655 static const WCHAR themesSubdir
[] = { '\\','T','h','e','m','e','s',0 };
656 static const WCHAR backslash
[] = { '\\',0 };
657 WCHAR themeFilePath
[MAX_PATH
];
658 SHFILEOPSTRUCTW shfop
;
660 if (FAILED (SHGetFolderPathW (NULL
, CSIDL_RESOURCES
|CSIDL_FLAG_CREATE
, NULL
,
661 SHGFP_TYPE_CURRENT
, themeFilePath
))) return;
663 if (lstrcmpiW(PathFindExtensionW(filetitle
), themeExt
)==0)
665 do_parse_theme(file
);
666 SendMessage(GetParent(dialog
), PSM_CHANGED
, 0, 0);
670 PathRemoveExtensionW (filetitle
);
672 /* Construct path into which the theme file goes */
673 lstrcatW (themeFilePath
, themesSubdir
);
674 lstrcatW (themeFilePath
, backslash
);
675 lstrcatW (themeFilePath
, filetitle
);
677 /* Create the directory */
678 SHCreateDirectoryExW (dialog
, themeFilePath
, NULL
);
680 /* Append theme file name itself */
681 lstrcatW (themeFilePath
, backslash
);
682 lstrcatW (themeFilePath
, PathFindFileNameW (file
));
683 /* SHFileOperation() takes lists as input, so double-nullterminate */
684 themeFilePath
[lstrlenW (themeFilePath
)+1] = 0;
685 file
[lstrlenW (file
)+1] = 0;
688 WINE_TRACE("copying: %s -> %s\n", wine_dbgstr_w (file
),
689 wine_dbgstr_w (themeFilePath
));
691 shfop
.wFunc
= FO_COPY
;
693 shfop
.pTo
= themeFilePath
;
694 shfop
.fFlags
= FOF_NOCONFIRMMKDIR
;
695 if (SHFileOperationW (&shfop
) == 0)
698 if (!fill_theme_list (GetDlgItem (dialog
, IDC_THEME_THEMECOMBO
),
699 GetDlgItem (dialog
, IDC_THEME_COLORCOMBO
),
700 GetDlgItem (dialog
, IDC_THEME_SIZECOMBO
)))
702 SendMessageW (GetDlgItem (dialog
, IDC_THEME_COLORCOMBO
), CB_SETCURSEL
, (WPARAM
)-1, 0);
703 SendMessageW (GetDlgItem (dialog
, IDC_THEME_SIZECOMBO
), CB_SETCURSEL
, (WPARAM
)-1, 0);
704 enable_size_and_color_controls (dialog
, FALSE
);
708 enable_size_and_color_controls (dialog
, TRUE
);
712 WINE_TRACE("copy operation failed\n");
714 else WINE_TRACE("user cancelled\n");
717 /* Information about symbolic link targets of certain User Shell Folders. */
718 struct ShellFolderInfo
{
720 char szLinkTarget
[FILENAME_MAX
]; /* in unix locale */
723 static struct ShellFolderInfo asfiInfo
[] = {
724 { CSIDL_DESKTOP
, "" },
725 { CSIDL_PERSONAL
, "" },
726 { CSIDL_MYPICTURES
, "" },
727 { CSIDL_MYMUSIC
, "" },
728 { CSIDL_MYVIDEO
, "" }
731 static struct ShellFolderInfo
*psfiSelected
= NULL
;
733 #define NUM_ELEMS(x) (sizeof(x)/sizeof(*(x)))
735 /* create a unicode string from a string in Unix locale */
736 static WCHAR
*strdupU2W(const char *unix_str
)
741 lenW
= MultiByteToWideChar(CP_UNIXCP
, 0, unix_str
, -1, NULL
, 0);
742 unicode_str
= HeapAlloc(GetProcessHeap(), 0, lenW
* sizeof(WCHAR
));
744 MultiByteToWideChar(CP_UNIXCP
, 0, unix_str
, -1, unicode_str
, lenW
);
748 static void init_shell_folder_listview_headers(HWND dialog
) {
751 char szShellFolder
[64] = "Shell Folder";
752 char szLinksTo
[64] = "Links to";
755 LoadString(GetModuleHandle(NULL
), IDS_SHELL_FOLDER
, szShellFolder
, sizeof(szShellFolder
));
756 LoadString(GetModuleHandle(NULL
), IDS_LINKS_TO
, szLinksTo
, sizeof(szLinksTo
));
758 GetClientRect(GetDlgItem(dialog
, IDC_LIST_SFPATHS
), &viewRect
);
759 width
= (viewRect
.right
- viewRect
.left
) / 4;
761 listColumn
.mask
= LVCF_TEXT
| LVCF_WIDTH
| LVCF_SUBITEM
;
762 listColumn
.pszText
= szShellFolder
;
763 listColumn
.cchTextMax
= lstrlen(listColumn
.pszText
);
764 listColumn
.cx
= width
;
766 SendDlgItemMessage(dialog
, IDC_LIST_SFPATHS
, LVM_INSERTCOLUMN
, 0, (LPARAM
) &listColumn
);
768 listColumn
.pszText
= szLinksTo
;
769 listColumn
.cchTextMax
= lstrlen(listColumn
.pszText
);
770 listColumn
.cx
= viewRect
.right
- viewRect
.left
- width
- 1;
772 SendDlgItemMessage(dialog
, IDC_LIST_SFPATHS
, LVM_INSERTCOLUMN
, 1, (LPARAM
) &listColumn
);
775 /* Reads the currently set shell folder symbol link targets into asfiInfo. */
776 static void read_shell_folder_link_targets(void) {
777 WCHAR wszPath
[MAX_PATH
];
781 for (i
=0; i
<NUM_ELEMS(asfiInfo
); i
++) {
782 asfiInfo
[i
].szLinkTarget
[0] = '\0';
783 hr
= SHGetFolderPathW(NULL
, asfiInfo
[i
].nFolder
|CSIDL_FLAG_DONT_VERIFY
, NULL
,
784 SHGFP_TYPE_CURRENT
, wszPath
);
786 char *pszUnixPath
= wine_get_unix_file_name(wszPath
);
788 struct stat statPath
;
789 if (!lstat(pszUnixPath
, &statPath
) && S_ISLNK(statPath
.st_mode
)) {
790 int cLen
= readlink(pszUnixPath
, asfiInfo
[i
].szLinkTarget
, FILENAME_MAX
-1);
791 if (cLen
>= 0) asfiInfo
[i
].szLinkTarget
[cLen
] = '\0';
793 HeapFree(GetProcessHeap(), 0, pszUnixPath
);
799 static void update_shell_folder_listview(HWND dialog
) {
802 LONG lSelected
= SendDlgItemMessage(dialog
, IDC_LIST_SFPATHS
, LVM_GETNEXTITEM
, (WPARAM
)-1,
803 MAKELPARAM(LVNI_SELECTED
,0));
805 SendDlgItemMessage(dialog
, IDC_LIST_SFPATHS
, LVM_DELETEALLITEMS
, 0, 0);
807 for (i
=0; i
<NUM_ELEMS(asfiInfo
); i
++) {
808 WCHAR buffer
[MAX_PATH
];
810 LPITEMIDLIST pidlCurrent
;
812 /* Some acrobatic to get the localized name of the shell folder */
813 hr
= SHGetFolderLocation(dialog
, asfiInfo
[i
].nFolder
, NULL
, 0, &pidlCurrent
);
815 LPSHELLFOLDER psfParent
;
816 LPCITEMIDLIST pidlLast
;
817 hr
= SHBindToParent(pidlCurrent
, &IID_IShellFolder
, (LPVOID
*)&psfParent
, &pidlLast
);
820 hr
= IShellFolder_GetDisplayNameOf(psfParent
, pidlLast
, SHGDN_FORADDRESSBAR
, &strRet
);
822 hr
= StrRetToBufW(&strRet
, pidlLast
, buffer
, MAX_PATH
);
824 IShellFolder_Release(psfParent
);
829 /* If there's a dangling symlink for the current shell folder, SHGetFolderLocation
830 * will fail above. We fall back to the (non-verified) path of the shell folder. */
832 hr
= SHGetFolderPathW(dialog
, asfiInfo
[i
].nFolder
|CSIDL_FLAG_DONT_VERIFY
, NULL
,
833 SHGFP_TYPE_CURRENT
, buffer
);
836 item
.mask
= LVIF_TEXT
| LVIF_PARAM
;
839 item
.pszText
= buffer
;
840 item
.lParam
= (LPARAM
)&asfiInfo
[i
];
841 SendDlgItemMessage(dialog
, IDC_LIST_SFPATHS
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
843 item
.mask
= LVIF_TEXT
;
846 item
.pszText
= strdupU2W(asfiInfo
[i
].szLinkTarget
);
847 SendDlgItemMessage(dialog
, IDC_LIST_SFPATHS
, LVM_SETITEMW
, 0, (LPARAM
)&item
);
848 HeapFree(GetProcessHeap(), 0, item
.pszText
);
851 /* Ensure that the previously selected item is selected again. */
852 if (lSelected
>= 0) {
853 item
.mask
= LVIF_STATE
;
854 item
.state
= LVIS_SELECTED
;
855 item
.stateMask
= LVIS_SELECTED
;
856 SendDlgItemMessage(dialog
, IDC_LIST_SFPATHS
, LVM_SETITEMSTATE
, (WPARAM
)lSelected
,
861 static void on_shell_folder_selection_changed(HWND hDlg
, LPNMLISTVIEW lpnm
) {
862 if (lpnm
->uNewState
& LVIS_SELECTED
) {
863 psfiSelected
= (struct ShellFolderInfo
*)lpnm
->lParam
;
864 EnableWindow(GetDlgItem(hDlg
, IDC_LINK_SFPATH
), 1);
865 if (strlen(psfiSelected
->szLinkTarget
)) {
867 CheckDlgButton(hDlg
, IDC_LINK_SFPATH
, BST_CHECKED
);
868 EnableWindow(GetDlgItem(hDlg
, IDC_EDIT_SFPATH
), 1);
869 EnableWindow(GetDlgItem(hDlg
, IDC_BROWSE_SFPATH
), 1);
870 link
= strdupU2W(psfiSelected
->szLinkTarget
);
871 set_textW(hDlg
, IDC_EDIT_SFPATH
, link
);
872 HeapFree(GetProcessHeap(), 0, link
);
874 CheckDlgButton(hDlg
, IDC_LINK_SFPATH
, BST_UNCHECKED
);
875 EnableWindow(GetDlgItem(hDlg
, IDC_EDIT_SFPATH
), 0);
876 EnableWindow(GetDlgItem(hDlg
, IDC_BROWSE_SFPATH
), 0);
877 set_text(hDlg
, IDC_EDIT_SFPATH
, "");
881 CheckDlgButton(hDlg
, IDC_LINK_SFPATH
, BST_UNCHECKED
);
882 set_text(hDlg
, IDC_EDIT_SFPATH
, "");
883 EnableWindow(GetDlgItem(hDlg
, IDC_LINK_SFPATH
), 0);
884 EnableWindow(GetDlgItem(hDlg
, IDC_EDIT_SFPATH
), 0);
885 EnableWindow(GetDlgItem(hDlg
, IDC_BROWSE_SFPATH
), 0);
889 /* Keep the contents of the edit control, the listview control and the symlink
890 * information in sync. */
891 static void on_shell_folder_edit_changed(HWND hDlg
) {
893 WCHAR
*text
= get_textW(hDlg
, IDC_EDIT_SFPATH
);
894 LONG iSel
= SendDlgItemMessage(hDlg
, IDC_LIST_SFPATHS
, LVM_GETNEXTITEM
, -1,
895 MAKELPARAM(LVNI_SELECTED
,0));
897 if (!text
|| !psfiSelected
|| iSel
< 0) {
898 HeapFree(GetProcessHeap(), 0, text
);
902 WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1,
903 psfiSelected
->szLinkTarget
, FILENAME_MAX
, NULL
, NULL
);
905 item
.mask
= LVIF_TEXT
;
909 SendDlgItemMessage(hDlg
, IDC_LIST_SFPATHS
, LVM_SETITEMW
, 0, (LPARAM
)&item
);
911 HeapFree(GetProcessHeap(), 0, text
);
913 SendMessage(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
916 static void apply_shell_folder_changes(void) {
917 WCHAR wszPath
[MAX_PATH
];
918 char szBackupPath
[FILENAME_MAX
], szUnixPath
[FILENAME_MAX
], *pszUnixPath
= NULL
;
920 struct stat statPath
;
923 for (i
=0; i
<NUM_ELEMS(asfiInfo
); i
++) {
924 /* Ignore nonexistent link targets */
925 if (asfiInfo
[i
].szLinkTarget
[0] && stat(asfiInfo
[i
].szLinkTarget
, &statPath
))
928 hr
= SHGetFolderPathW(NULL
, asfiInfo
[i
].nFolder
|CSIDL_FLAG_CREATE
, NULL
,
929 SHGFP_TYPE_CURRENT
, wszPath
);
930 if (FAILED(hr
)) continue;
932 /* Retrieve the corresponding unix path. */
933 pszUnixPath
= wine_get_unix_file_name(wszPath
);
934 if (!pszUnixPath
) continue;
935 lstrcpyA(szUnixPath
, pszUnixPath
);
936 HeapFree(GetProcessHeap(), 0, pszUnixPath
);
938 /* Derive name for folder backup. */
939 cUnixPathLen
= lstrlenA(szUnixPath
);
940 lstrcpyA(szBackupPath
, szUnixPath
);
941 lstrcatA(szBackupPath
, ".winecfg");
943 if (lstat(szUnixPath
, &statPath
)) continue;
945 /* Move old folder/link out of the way. */
946 if (S_ISLNK(statPath
.st_mode
)) {
947 if (unlink(szUnixPath
)) continue; /* Unable to remove link. */
949 if (!*asfiInfo
[i
].szLinkTarget
) {
950 continue; /* We are done. Old was real folder, as new shall be. */
952 if (rename(szUnixPath
, szBackupPath
)) { /* Move folder out of the way. */
953 continue; /* Unable to move old folder. */
958 /* Create new link/folder. */
959 if (*asfiInfo
[i
].szLinkTarget
) {
960 symlink(asfiInfo
[i
].szLinkTarget
, szUnixPath
);
962 /* If there's a backup folder, restore it. Else create new folder. */
963 if (!lstat(szBackupPath
, &statPath
) && S_ISDIR(statPath
.st_mode
)) {
964 rename(szBackupPath
, szUnixPath
);
966 mkdir(szUnixPath
, 0777);
972 static void read_sysparams(HWND hDlg
)
975 HWND list
= GetDlgItem(hDlg
, IDC_SYSPARAM_COMBO
);
976 NONCLIENTMETRICSW nonclient_metrics
;
979 for (i
= 0; i
< sizeof(metrics
) / sizeof(metrics
[0]); i
++)
981 LoadStringW(GetModuleHandle(NULL
), i
+ IDC_SYSPARAMS_BUTTON
, buffer
,
982 sizeof(buffer
) / sizeof(buffer
[0]));
983 idx
= SendMessageW(list
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
984 if (idx
!= CB_ERR
) SendMessageW(list
, CB_SETITEMDATA
, idx
, i
);
986 if (metrics
[i
].sm_idx
!= -1)
987 metrics
[i
].size
= GetSystemMetrics(metrics
[i
].sm_idx
);
988 if (metrics
[i
].color_idx
!= -1)
989 metrics
[i
].color
= GetSysColor(metrics
[i
].color_idx
);
992 nonclient_metrics
.cbSize
= sizeof(NONCLIENTMETRICSW
);
993 SystemParametersInfoW(SPI_GETNONCLIENTMETRICS
, sizeof(NONCLIENTMETRICSW
), &nonclient_metrics
, 0);
995 memcpy(&(metrics
[IDC_SYSPARAMS_MENU_TEXT
- IDC_SYSPARAMS_BUTTON
].lf
),
996 &(nonclient_metrics
.lfMenuFont
), sizeof(LOGFONTW
));
997 memcpy(&(metrics
[IDC_SYSPARAMS_ACTIVE_TITLE_TEXT
- IDC_SYSPARAMS_BUTTON
].lf
),
998 &(nonclient_metrics
.lfCaptionFont
), sizeof(LOGFONTW
));
999 memcpy(&(metrics
[IDC_SYSPARAMS_TOOLTIP_TEXT
- IDC_SYSPARAMS_BUTTON
].lf
),
1000 &(nonclient_metrics
.lfStatusFont
), sizeof(LOGFONTW
));
1001 memcpy(&(metrics
[IDC_SYSPARAMS_MSGBOX_TEXT
- IDC_SYSPARAMS_BUTTON
].lf
),
1002 &(nonclient_metrics
.lfMessageFont
), sizeof(LOGFONTW
));
1005 static void apply_sysparams(void)
1007 NONCLIENTMETRICSW nonclient_metrics
;
1009 int colors_idx
[sizeof(metrics
) / sizeof(metrics
[0])];
1010 COLORREF colors
[sizeof(metrics
) / sizeof(metrics
[0])];
1012 nonclient_metrics
.cbSize
= sizeof(nonclient_metrics
);
1013 SystemParametersInfoW(SPI_GETNONCLIENTMETRICS
, sizeof(nonclient_metrics
), &nonclient_metrics
, 0);
1015 nonclient_metrics
.iMenuWidth
= nonclient_metrics
.iMenuHeight
=
1016 metrics
[IDC_SYSPARAMS_MENU
- IDC_SYSPARAMS_BUTTON
].size
;
1017 nonclient_metrics
.iCaptionWidth
= nonclient_metrics
.iCaptionHeight
=
1018 metrics
[IDC_SYSPARAMS_ACTIVE_TITLE
- IDC_SYSPARAMS_BUTTON
].size
;
1019 nonclient_metrics
.iScrollWidth
= nonclient_metrics
.iScrollHeight
=
1020 metrics
[IDC_SYSPARAMS_SCROLLBAR
- IDC_SYSPARAMS_BUTTON
].size
;
1022 memcpy(&(nonclient_metrics
.lfMenuFont
),
1023 &(metrics
[IDC_SYSPARAMS_MENU_TEXT
- IDC_SYSPARAMS_BUTTON
].lf
),
1025 memcpy(&(nonclient_metrics
.lfCaptionFont
),
1026 &(metrics
[IDC_SYSPARAMS_ACTIVE_TITLE_TEXT
- IDC_SYSPARAMS_BUTTON
].lf
),
1028 memcpy(&(nonclient_metrics
.lfStatusFont
),
1029 &(metrics
[IDC_SYSPARAMS_TOOLTIP_TEXT
- IDC_SYSPARAMS_BUTTON
].lf
),
1031 memcpy(&(nonclient_metrics
.lfMessageFont
),
1032 &(metrics
[IDC_SYSPARAMS_MSGBOX_TEXT
- IDC_SYSPARAMS_BUTTON
].lf
),
1035 SystemParametersInfoW(SPI_SETNONCLIENTMETRICS
, sizeof(nonclient_metrics
), &nonclient_metrics
,
1036 SPIF_UPDATEINIFILE
| SPIF_SENDCHANGE
);
1038 for (i
= 0; i
< sizeof(metrics
) / sizeof(metrics
[0]); i
++)
1039 if (metrics
[i
].color_idx
!= -1)
1041 colors_idx
[cnt
] = metrics
[i
].color_idx
;
1042 colors
[cnt
++] = metrics
[i
].color
;
1044 SetSysColors(cnt
, colors_idx
, colors
);
1047 static void on_sysparam_change(HWND hDlg
)
1049 int index
= SendDlgItemMessageW(hDlg
, IDC_SYSPARAM_COMBO
, CB_GETCURSEL
, 0, 0);
1051 index
= SendDlgItemMessageW(hDlg
, IDC_SYSPARAM_COMBO
, CB_GETITEMDATA
, index
, 0);
1055 EnableWindow(GetDlgItem(hDlg
, IDC_SYSPARAM_COLOR_TEXT
), metrics
[index
].color_idx
!= -1);
1056 EnableWindow(GetDlgItem(hDlg
, IDC_SYSPARAM_COLOR
), metrics
[index
].color_idx
!= -1);
1057 InvalidateRect(GetDlgItem(hDlg
, IDC_SYSPARAM_COLOR
), NULL
, TRUE
);
1059 EnableWindow(GetDlgItem(hDlg
, IDC_SYSPARAM_SIZE_TEXT
), metrics
[index
].sm_idx
!= -1);
1060 EnableWindow(GetDlgItem(hDlg
, IDC_SYSPARAM_SIZE
), metrics
[index
].sm_idx
!= -1);
1061 EnableWindow(GetDlgItem(hDlg
, IDC_SYSPARAM_SIZE_UD
), metrics
[index
].sm_idx
!= -1);
1062 if (metrics
[index
].sm_idx
!= -1)
1063 SendDlgItemMessageW(hDlg
, IDC_SYSPARAM_SIZE_UD
, UDM_SETPOS
, 0, MAKELONG(metrics
[index
].size
, 0));
1065 set_text(hDlg
, IDC_SYSPARAM_SIZE
, "");
1067 EnableWindow(GetDlgItem(hDlg
, IDC_SYSPARAM_FONT
),
1068 index
== IDC_SYSPARAMS_MENU_TEXT
-IDC_SYSPARAMS_BUTTON
||
1069 index
== IDC_SYSPARAMS_ACTIVE_TITLE_TEXT
-IDC_SYSPARAMS_BUTTON
||
1070 index
== IDC_SYSPARAMS_TOOLTIP_TEXT
-IDC_SYSPARAMS_BUTTON
||
1071 index
== IDC_SYSPARAMS_MSGBOX_TEXT
-IDC_SYSPARAMS_BUTTON
1074 updating_ui
= FALSE
;
1077 static void on_draw_item(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
1079 static HBRUSH black_brush
= 0;
1080 LPDRAWITEMSTRUCT draw_info
= (LPDRAWITEMSTRUCT
)lParam
;
1082 if (!black_brush
) black_brush
= CreateSolidBrush(0);
1084 if (draw_info
->CtlID
== IDC_SYSPARAM_COLOR
)
1086 UINT state
= DFCS_ADJUSTRECT
| DFCS_BUTTONPUSH
;
1088 if (draw_info
->itemState
& ODS_DISABLED
)
1089 state
|= DFCS_INACTIVE
;
1091 state
|= draw_info
->itemState
& ODS_SELECTED
? DFCS_PUSHED
: 0;
1093 DrawFrameControl(draw_info
->hDC
, &draw_info
->rcItem
, DFC_BUTTON
, state
);
1095 if (!(draw_info
->itemState
& ODS_DISABLED
))
1098 int index
= SendDlgItemMessageW(hDlg
, IDC_SYSPARAM_COMBO
, CB_GETCURSEL
, 0, 0);
1100 index
= SendDlgItemMessageW(hDlg
, IDC_SYSPARAM_COMBO
, CB_GETITEMDATA
, index
, 0);
1101 brush
= CreateSolidBrush(metrics
[index
].color
);
1103 InflateRect(&draw_info
->rcItem
, -1, -1);
1104 FrameRect(draw_info
->hDC
, &draw_info
->rcItem
, black_brush
);
1105 InflateRect(&draw_info
->rcItem
, -1, -1);
1106 FillRect(draw_info
->hDC
, &draw_info
->rcItem
, brush
);
1107 DeleteObject(brush
);
1112 static void on_select_font(HWND hDlg
)
1115 int index
= SendDlgItemMessageW(hDlg
, IDC_SYSPARAM_COMBO
, CB_GETCURSEL
, 0, 0);
1116 index
= SendDlgItemMessageW(hDlg
, IDC_SYSPARAM_COMBO
, CB_GETITEMDATA
, index
, 0);
1118 ZeroMemory(&cf
, sizeof(cf
));
1119 cf
.lStructSize
= sizeof(CHOOSEFONTW
);
1120 cf
.hwndOwner
= hDlg
;
1121 cf
.lpLogFont
= &(metrics
[index
].lf
);
1122 cf
.Flags
= CF_SCREENFONTS
| CF_INITTOLOGFONTSTRUCT
| CF_NOSCRIPTSEL
;
1128 ThemeDlgProc (HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1132 read_shell_folder_link_targets();
1133 init_shell_folder_listview_headers(hDlg
);
1134 update_shell_folder_listview(hDlg
);
1135 read_sysparams(hDlg
);
1143 set_window_title(hDlg
);
1147 switch(HIWORD(wParam
)) {
1148 case CBN_SELCHANGE
: {
1149 if (updating_ui
) break;
1150 switch (LOWORD(wParam
))
1152 case IDC_THEME_THEMECOMBO
: on_theme_changed(hDlg
); break;
1153 case IDC_THEME_COLORCOMBO
: /* fall through */
1154 case IDC_THEME_SIZECOMBO
: theme_dirty
= TRUE
; break;
1155 case IDC_SYSPARAM_COMBO
: on_sysparam_change(hDlg
); return FALSE
;
1157 SendMessage(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
1161 if (updating_ui
) break;
1162 switch (LOWORD(wParam
))
1164 case IDC_EDIT_SFPATH
: on_shell_folder_edit_changed(hDlg
); break;
1165 case IDC_SYSPARAM_SIZE
:
1167 char *text
= get_text(hDlg
, IDC_SYSPARAM_SIZE
);
1168 int index
= SendDlgItemMessageW(hDlg
, IDC_SYSPARAM_COMBO
, CB_GETCURSEL
, 0, 0);
1170 index
= SendDlgItemMessageW(hDlg
, IDC_SYSPARAM_COMBO
, CB_GETITEMDATA
, index
, 0);
1171 metrics
[index
].size
= atoi(text
);
1172 HeapFree(GetProcessHeap(), 0, text
);
1174 SendMessage(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
1181 switch (LOWORD(wParam
))
1183 case IDC_THEME_INSTALL
:
1184 on_theme_install (hDlg
);
1187 case IDC_SYSPARAM_FONT
:
1188 on_select_font(hDlg
);
1191 case IDC_BROWSE_SFPATH
:
1193 WCHAR link
[FILENAME_MAX
];
1194 if (browse_for_unix_folder(hDlg
, link
)) {
1195 WideCharToMultiByte(CP_UNIXCP
, 0, link
, -1,
1196 psfiSelected
->szLinkTarget
, FILENAME_MAX
,
1198 update_shell_folder_listview(hDlg
);
1199 SendMessage(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
1204 case IDC_LINK_SFPATH
:
1205 if (IsDlgButtonChecked(hDlg
, IDC_LINK_SFPATH
)) {
1206 WCHAR link
[FILENAME_MAX
];
1207 if (browse_for_unix_folder(hDlg
, link
)) {
1208 WideCharToMultiByte(CP_UNIXCP
, 0, link
, -1,
1209 psfiSelected
->szLinkTarget
, FILENAME_MAX
,
1211 update_shell_folder_listview(hDlg
);
1212 SendMessage(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
1214 CheckDlgButton(hDlg
, IDC_LINK_SFPATH
, BST_UNCHECKED
);
1217 psfiSelected
->szLinkTarget
[0] = '\0';
1218 update_shell_folder_listview(hDlg
);
1219 SendMessage(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
1223 case IDC_SYSPARAM_COLOR
:
1225 static COLORREF user_colors
[16];
1226 CHOOSECOLORW c_color
;
1227 int index
= SendDlgItemMessageW(hDlg
, IDC_SYSPARAM_COMBO
, CB_GETCURSEL
, 0, 0);
1229 index
= SendDlgItemMessageW(hDlg
, IDC_SYSPARAM_COMBO
, CB_GETITEMDATA
, index
, 0);
1231 memset(&c_color
, 0, sizeof(c_color
));
1232 c_color
.lStructSize
= sizeof(c_color
);
1233 c_color
.lpCustColors
= user_colors
;
1234 c_color
.rgbResult
= metrics
[index
].color
;
1235 c_color
.Flags
= CC_ANYCOLOR
| CC_RGBINIT
;
1236 c_color
.hwndOwner
= hDlg
;
1237 if (ChooseColorW(&c_color
))
1239 metrics
[index
].color
= c_color
.rgbResult
;
1240 save_sys_color(index
, metrics
[index
].color
);
1241 InvalidateRect(GetDlgItem(hDlg
, IDC_SYSPARAM_COLOR
), NULL
, TRUE
);
1242 SendMessage(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
1252 switch (((LPNMHDR
)lParam
)->code
) {
1253 case PSN_KILLACTIVE
: {
1254 SetWindowLongPtr(hDlg
, DWLP_MSGRESULT
, FALSE
);
1260 apply_shell_folder_changes();
1262 read_shell_folder_link_targets();
1263 update_shell_folder_listview(hDlg
);
1264 SetWindowLongPtr(hDlg
, DWLP_MSGRESULT
, PSNRET_NOERROR
);
1267 case LVN_ITEMCHANGED
: {
1268 if (wParam
== IDC_LIST_SFPATHS
)
1269 on_shell_folder_selection_changed(hDlg
, (LPNMLISTVIEW
)lParam
);
1272 case PSN_SETACTIVE
: {
1280 on_draw_item(hDlg
, wParam
, lParam
);