wined3d: Default to using a non-forward-compatible core profile context.
[wine.git] / programs / winecfg / theme.c
blob1d915bcaade4221396ef37c7bf80a87d1d3630ea
1 /*
2 * Desktop Integration
3 * - Theme configuration code
4 * - User Shell Folder mapping
6 * Copyright (c) 2005 by Frank Richter
7 * Copyright (c) 2006 by Michael Jung
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "config.h"
26 #include "wine/port.h"
28 #include <stdarg.h>
29 #include <stdlib.h>
30 #include <stdio.h>
31 #ifdef HAVE_SYS_STAT_H
32 #include <sys/stat.h>
33 #endif
34 #ifdef HAVE_UNISTD_H
35 #include <unistd.h>
36 #endif
37 #ifdef HAVE_DIRECT_H
38 #include <direct.h>
39 #endif
41 #define COBJMACROS
43 #include <windows.h>
44 #include <commdlg.h>
45 #include <shellapi.h>
46 #include <uxtheme.h>
47 #include <tmschema.h>
48 #include <shlobj.h>
49 #include <shlwapi.h>
50 #include <wine/debug.h>
51 #include <wine/unicode.h>
53 #include "resource.h"
54 #include "winecfg.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,
70 LPCWSTR pszThemeName,
71 LPCWSTR pszToolTip, LPVOID lpReserved2,
72 LPVOID lpData);
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,
81 DWORD unknown);
82 HRESULT WINAPI CloseThemeFile (HTHEMEFILE hThemeFile);
83 HRESULT WINAPI EnumThemes (LPCWSTR pszThemePath, EnumThemeProc callback,
84 LPVOID lpData);
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 */
90 typedef struct
92 WCHAR* name;
93 WCHAR* fancyName;
94 } ThemeColorOrSize;
96 /* wrapper around DSA that also keeps an item count */
97 typedef struct
99 HDSA dsa;
100 int count;
101 } WrappedDsa;
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);
119 wdsa->count++;
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);
127 return 1;
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);
138 wdsa->count = 0;
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)
148 int i = 0;
149 for (; i < wdsa->count; i++)
151 ThemeColorOrSize* item = color_or_size_dsa_get (wdsa, i);
152 if (lstrcmpiW (item->name, name) == 0) break;
154 return i;
157 /* A theme file, contains file name, display name, color and size scheme names */
158 typedef struct
160 WCHAR* themeFileName;
161 WCHAR* fancyName;
162 WrappedDsa colors;
163 WrappedDsa sizes;
164 } ThemeFile;
166 static HDSA themeFiles = NULL;
167 static int themeFilesCount = 0;
169 static int CALLBACK theme_dsa_destroy_callback (LPVOID p, LPVOID pData)
171 ThemeFile* item = p;
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);
176 return 1;
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);
185 themeFiles = NULL;
186 themeFilesCount = 0;
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,
193 WrappedDsa* wdsa,
194 EnumTheme enumTheme)
196 DWORD index = 0;
197 THEMENAMES names;
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,
213 LPCWSTR pszToolTip,
214 LPVOID lpReserved2, LPVOID lpData)
216 ThemeFile newEntry;
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);
234 themeFilesCount++;
236 return TRUE;
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];
245 free_theme_files();
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,
258 HWND comboSize)
260 int i;
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
278 * scheme. */
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];
294 int themeIndex = 0;
295 BOOL ret = TRUE;
296 int i;
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,
303 sizeof(textNoTheme) / sizeof(WCHAR));
305 SendMessageW (comboTheme, CB_RESETCONTENT, 0, 0);
306 SendMessageW (comboTheme, CB_ADDSTRING, 0, (LPARAM)textNoTheme);
308 for (i = 0; i < themeFilesCount; i++)
310 ThemeFile* item = DSA_GetItemPtr (themeFiles, i);
311 SendMessageW (comboTheme, CB_ADDSTRING, 0,
312 (LPARAM)item->fancyName);
315 if (IsThemeActive () && SUCCEEDED (GetCurrentThemeName (currentTheme,
316 sizeof(currentTheme) / sizeof(WCHAR),
317 currentColor, sizeof(currentColor) / sizeof(WCHAR),
318 currentSize, sizeof(currentSize) / sizeof(WCHAR))))
320 /* Determine the index of the currently active theme. */
321 BOOL found = FALSE;
322 for (i = 0; i < themeFilesCount; i++)
324 theme = DSA_GetItemPtr (themeFiles, i);
325 if (lstrcmpiW (theme->themeFileName, currentTheme) == 0)
327 found = TRUE;
328 themeIndex = i+1;
329 break;
332 if (!found)
334 /* Current theme not found?... add to the list, then... */
335 WINE_TRACE("Theme %s not in list of enumerated themes\n",
336 wine_dbgstr_w (currentTheme));
337 myEnumThemeProc (NULL, currentTheme, currentTheme,
338 currentTheme, NULL, NULL);
339 themeIndex = themeFilesCount;
340 theme = DSA_GetItemPtr (themeFiles, themeFilesCount-1);
342 fill_color_size_combos (theme, comboColor, comboSize);
343 select_color_and_size (theme, currentColor, comboColor,
344 currentSize, comboSize);
346 else
348 /* No theme selected */
349 ret = FALSE;
352 SendMessageW (comboTheme, CB_SETCURSEL, themeIndex, 0);
353 return ret;
356 /* Update the color & size combo boxes when the selection of the theme
357 * combo changed. Selects the current color and size scheme if the theme
358 * is currently active, otherwise the first color and size. */
359 static BOOL update_color_and_size (int themeIndex, HWND comboColor,
360 HWND comboSize)
362 if (themeIndex == 0)
364 return FALSE;
366 else
368 WCHAR currentTheme[MAX_PATH];
369 WCHAR currentColor[MAX_PATH];
370 WCHAR currentSize[MAX_PATH];
371 ThemeFile* theme = DSA_GetItemPtr (themeFiles, themeIndex - 1);
373 fill_color_size_combos (theme, comboColor, comboSize);
375 if ((SUCCEEDED (GetCurrentThemeName (currentTheme,
376 sizeof(currentTheme) / sizeof(WCHAR),
377 currentColor, sizeof(currentColor) / sizeof(WCHAR),
378 currentSize, sizeof(currentSize) / sizeof(WCHAR))))
379 && (lstrcmpiW (currentTheme, theme->themeFileName) == 0))
381 select_color_and_size (theme, currentColor, comboColor,
382 currentSize, comboSize);
384 else
386 SendMessageW (comboColor, CB_SETCURSEL, 0, 0);
387 SendMessageW (comboSize, CB_SETCURSEL, 0, 0);
390 return TRUE;
393 /* Apply a theme from a given theme, color and size combo box item index. */
394 static void do_apply_theme (HWND dialog, int themeIndex, int colorIndex, int sizeIndex)
396 static char b[] = "\0";
398 if (themeIndex == 0)
400 /* no theme */
401 ApplyTheme (NULL, b, NULL);
403 else
405 ThemeFile* theme = DSA_GetItemPtr (themeFiles, themeIndex-1);
406 const WCHAR* themeFileName = theme->themeFileName;
407 const WCHAR* colorName = NULL;
408 const WCHAR* sizeName = NULL;
409 HTHEMEFILE hTheme;
410 ThemeColorOrSize* item;
412 item = color_or_size_dsa_get (&theme->colors, colorIndex);
413 colorName = item->name;
415 item = color_or_size_dsa_get (&theme->sizes, sizeIndex);
416 sizeName = item->name;
418 if (SUCCEEDED (OpenThemeFile (themeFileName, colorName, sizeName,
419 &hTheme, 0)))
421 ApplyTheme (hTheme, b, NULL);
422 CloseThemeFile (hTheme);
424 else
426 ApplyTheme (NULL, b, NULL);
430 refresh_sysparams(dialog);
433 static BOOL updating_ui;
434 static BOOL theme_dirty;
436 static void enable_size_and_color_controls (HWND dialog, BOOL enable)
438 EnableWindow (GetDlgItem (dialog, IDC_THEME_COLORCOMBO), enable);
439 EnableWindow (GetDlgItem (dialog, IDC_THEME_COLORTEXT), enable);
440 EnableWindow (GetDlgItem (dialog, IDC_THEME_SIZECOMBO), enable);
441 EnableWindow (GetDlgItem (dialog, IDC_THEME_SIZETEXT), enable);
444 static void init_dialog (HWND dialog)
446 updating_ui = TRUE;
448 scan_theme_files();
449 if (!fill_theme_list (GetDlgItem (dialog, IDC_THEME_THEMECOMBO),
450 GetDlgItem (dialog, IDC_THEME_COLORCOMBO),
451 GetDlgItem (dialog, IDC_THEME_SIZECOMBO)))
453 SendMessageW (GetDlgItem (dialog, IDC_THEME_COLORCOMBO), CB_SETCURSEL, (WPARAM)-1, 0);
454 SendMessageW (GetDlgItem (dialog, IDC_THEME_SIZECOMBO), CB_SETCURSEL, (WPARAM)-1, 0);
455 enable_size_and_color_controls (dialog, FALSE);
457 else
459 enable_size_and_color_controls (dialog, TRUE);
461 theme_dirty = FALSE;
463 SendDlgItemMessageW(dialog, IDC_SYSPARAM_SIZE_UD, UDM_SETBUDDY, (WPARAM)GetDlgItem(dialog, IDC_SYSPARAM_SIZE), 0);
464 SendDlgItemMessageW(dialog, IDC_SYSPARAM_SIZE_UD, UDM_SETRANGE, 0, MAKELONG(100, 8));
466 updating_ui = FALSE;
469 static void on_theme_changed(HWND dialog) {
470 int index = SendMessageW (GetDlgItem (dialog, IDC_THEME_THEMECOMBO),
471 CB_GETCURSEL, 0, 0);
472 if (!update_color_and_size (index, GetDlgItem (dialog, IDC_THEME_COLORCOMBO),
473 GetDlgItem (dialog, IDC_THEME_SIZECOMBO)))
475 SendMessageW (GetDlgItem (dialog, IDC_THEME_COLORCOMBO), CB_SETCURSEL, -1, 0);
476 SendMessageW (GetDlgItem (dialog, IDC_THEME_SIZECOMBO), CB_SETCURSEL, -1, 0);
477 enable_size_and_color_controls (dialog, FALSE);
479 else
481 enable_size_and_color_controls (dialog, TRUE);
483 theme_dirty = TRUE;
486 static void apply_theme(HWND dialog)
488 int themeIndex, colorIndex, sizeIndex;
490 if (!theme_dirty) return;
492 themeIndex = SendMessageW (GetDlgItem (dialog, IDC_THEME_THEMECOMBO),
493 CB_GETCURSEL, 0, 0);
494 colorIndex = SendMessageW (GetDlgItem (dialog, IDC_THEME_COLORCOMBO),
495 CB_GETCURSEL, 0, 0);
496 sizeIndex = SendMessageW (GetDlgItem (dialog, IDC_THEME_SIZECOMBO),
497 CB_GETCURSEL, 0, 0);
499 do_apply_theme (dialog, themeIndex, colorIndex, sizeIndex);
500 theme_dirty = FALSE;
503 static struct
505 int sm_idx, color_idx;
506 const char *color_reg;
507 int size;
508 COLORREF color;
509 LOGFONTW lf;
510 } metrics[] =
512 {-1, COLOR_BTNFACE, "ButtonFace" }, /* IDC_SYSPARAMS_BUTTON */
513 {-1, COLOR_BTNTEXT, "ButtonText" }, /* IDC_SYSPARAMS_BUTTON_TEXT */
514 {-1, COLOR_BACKGROUND, "Background" }, /* IDC_SYSPARAMS_DESKTOP */
515 {SM_CXMENUSIZE, COLOR_MENU, "Menu" }, /* IDC_SYSPARAMS_MENU */
516 {-1, COLOR_MENUTEXT, "MenuText" }, /* IDC_SYSPARAMS_MENU_TEXT */
517 {SM_CXVSCROLL, COLOR_SCROLLBAR, "Scrollbar" }, /* IDC_SYSPARAMS_SCROLLBAR */
518 {-1, COLOR_HIGHLIGHT, "Hilight" }, /* IDC_SYSPARAMS_SELECTION */
519 {-1, COLOR_HIGHLIGHTTEXT, "HilightText" }, /* IDC_SYSPARAMS_SELECTION_TEXT */
520 {-1, COLOR_INFOBK, "InfoWindow" }, /* IDC_SYSPARAMS_TOOLTIP */
521 {-1, COLOR_INFOTEXT, "InfoText" }, /* IDC_SYSPARAMS_TOOLTIP_TEXT */
522 {-1, COLOR_WINDOW, "Window" }, /* IDC_SYSPARAMS_WINDOW */
523 {-1, COLOR_WINDOWTEXT, "WindowText" }, /* IDC_SYSPARAMS_WINDOW_TEXT */
524 {SM_CXSIZE, COLOR_ACTIVECAPTION, "ActiveTitle" }, /* IDC_SYSPARAMS_ACTIVE_TITLE */
525 {-1, COLOR_CAPTIONTEXT, "TitleText" }, /* IDC_SYSPARAMS_ACTIVE_TITLE_TEXT */
526 {-1, COLOR_INACTIVECAPTION, "InactiveTitle" }, /* IDC_SYSPARAMS_INACTIVE_TITLE */
527 {-1, COLOR_INACTIVECAPTIONTEXT,"InactiveTitleText" }, /* IDC_SYSPARAMS_INACTIVE_TITLE_TEXT */
528 {-1, -1, "MsgBoxText" }, /* IDC_SYSPARAMS_MSGBOX_TEXT */
529 {-1, COLOR_APPWORKSPACE, "AppWorkSpace" }, /* IDC_SYSPARAMS_APPWORKSPACE */
530 {-1, COLOR_WINDOWFRAME, "WindowFrame" }, /* IDC_SYSPARAMS_WINDOW_FRAME */
531 {-1, COLOR_ACTIVEBORDER, "ActiveBorder" }, /* IDC_SYSPARAMS_ACTIVE_BORDER */
532 {-1, COLOR_INACTIVEBORDER, "InactiveBorder" }, /* IDC_SYSPARAMS_INACTIVE_BORDER */
533 {-1, COLOR_BTNSHADOW, "ButtonShadow" }, /* IDC_SYSPARAMS_BUTTON_SHADOW */
534 {-1, COLOR_GRAYTEXT, "GrayText" }, /* IDC_SYSPARAMS_GRAY_TEXT */
535 {-1, COLOR_BTNHIGHLIGHT, "ButtonHilight" }, /* IDC_SYSPARAMS_BUTTON_HIGHLIGHT */
536 {-1, COLOR_3DDKSHADOW, "ButtonDkShadow" }, /* IDC_SYSPARAMS_BUTTON_DARK_SHADOW */
537 {-1, COLOR_3DLIGHT, "ButtonLight" }, /* IDC_SYSPARAMS_BUTTON_LIGHT */
538 {-1, COLOR_ALTERNATEBTNFACE, "ButtonAlternateFace" }, /* IDC_SYSPARAMS_BUTTON_ALTERNATE */
539 {-1, COLOR_HOTLIGHT, "HotTrackingColor" }, /* IDC_SYSPARAMS_HOT_TRACKING */
540 {-1, COLOR_GRADIENTACTIVECAPTION, "GradientActiveTitle" }, /* IDC_SYSPARAMS_ACTIVE_TITLE_GRADIENT */
541 {-1, COLOR_GRADIENTINACTIVECAPTION, "GradientInactiveTitle" }, /* IDC_SYSPARAMS_INACTIVE_TITLE_GRADIENT */
542 {-1, COLOR_MENUHILIGHT, "MenuHilight" }, /* IDC_SYSPARAMS_MENU_HIGHLIGHT */
543 {-1, COLOR_MENUBAR, "MenuBar" }, /* IDC_SYSPARAMS_MENUBAR */
546 static void save_sys_color(int idx, COLORREF clr)
548 char buffer[13];
550 sprintf(buffer, "%d %d %d", GetRValue (clr), GetGValue (clr), GetBValue (clr));
551 set_reg_key(HKEY_CURRENT_USER, "Control Panel\\Colors", metrics[idx].color_reg, buffer);
554 static void set_color_from_theme(WCHAR *keyName, COLORREF color)
556 char *keyNameA = NULL;
557 int keyNameSize=0, i=0;
559 keyNameSize = WideCharToMultiByte(CP_ACP, 0, keyName, -1, keyNameA, 0, NULL, NULL);
560 keyNameA = HeapAlloc(GetProcessHeap(), 0, keyNameSize);
561 WideCharToMultiByte(CP_ACP, 0, keyName, -1, keyNameA, keyNameSize, NULL, NULL);
563 for (i=0; i<sizeof(metrics)/sizeof(metrics[0]); i++)
565 if (lstrcmpiA(metrics[i].color_reg, keyNameA)==0)
567 metrics[i].color = color;
568 save_sys_color(i, color);
569 break;
572 HeapFree(GetProcessHeap(), 0, keyNameA);
575 static void do_parse_theme(WCHAR *file)
577 static const WCHAR colorSect[] = {
578 'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\',
579 'C','o','l','o','r','s',0};
580 WCHAR keyName[MAX_PATH], keyNameValue[MAX_PATH];
581 WCHAR *keyNamePtr = NULL;
582 char *keyNameValueA = NULL;
583 int keyNameValueSize = 0;
584 int red = 0, green = 0, blue = 0;
585 COLORREF color;
587 WINE_TRACE("%s\n", wine_dbgstr_w(file));
589 GetPrivateProfileStringW(colorSect, NULL, NULL, keyName,
590 MAX_PATH, file);
592 keyNamePtr = keyName;
593 while (*keyNamePtr!=0) {
594 GetPrivateProfileStringW(colorSect, keyNamePtr, NULL, keyNameValue,
595 MAX_PATH, file);
597 keyNameValueSize = WideCharToMultiByte(CP_ACP, 0, keyNameValue, -1,
598 keyNameValueA, 0, NULL, NULL);
599 keyNameValueA = HeapAlloc(GetProcessHeap(), 0, keyNameValueSize);
600 WideCharToMultiByte(CP_ACP, 0, keyNameValue, -1, keyNameValueA, keyNameValueSize, NULL, NULL);
602 WINE_TRACE("parsing key: %s with value: %s\n",
603 wine_dbgstr_w(keyNamePtr), wine_dbgstr_w(keyNameValue));
605 sscanf(keyNameValueA, "%d %d %d", &red, &green, &blue);
607 color = RGB((BYTE)red, (BYTE)green, (BYTE)blue);
609 HeapFree(GetProcessHeap(), 0, keyNameValueA);
611 set_color_from_theme(keyNamePtr, color);
613 keyNamePtr+=lstrlenW(keyNamePtr);
614 keyNamePtr++;
618 static void on_theme_install(HWND dialog)
620 static const WCHAR filterMask[] = {0,'*','.','m','s','s','t','y','l','e','s',';',
621 '*','.','t','h','e','m','e',0,0};
622 static const WCHAR themeExt[] = {'.','T','h','e','m','e',0};
623 const int filterMaskLen = sizeof(filterMask)/sizeof(filterMask[0]);
624 OPENFILENAMEW ofn;
625 WCHAR filetitle[MAX_PATH];
626 WCHAR file[MAX_PATH];
627 WCHAR filter[100];
628 WCHAR title[100];
630 LoadStringW (GetModuleHandleW(NULL), IDS_THEMEFILE,
631 filter, sizeof (filter) / sizeof (filter[0]) - filterMaskLen);
632 memcpy (filter + lstrlenW (filter), filterMask,
633 filterMaskLen * sizeof (WCHAR));
634 LoadStringW (GetModuleHandleW(NULL), IDS_THEMEFILE_SELECT,
635 title, sizeof (title) / sizeof (title[0]));
637 ofn.lStructSize = sizeof(OPENFILENAMEW);
638 ofn.hwndOwner = dialog;
639 ofn.hInstance = 0;
640 ofn.lpstrFilter = filter;
641 ofn.lpstrCustomFilter = NULL;
642 ofn.nMaxCustFilter = 0;
643 ofn.nFilterIndex = 0;
644 ofn.lpstrFile = file;
645 ofn.lpstrFile[0] = '\0';
646 ofn.nMaxFile = sizeof(file)/sizeof(filetitle[0]);
647 ofn.lpstrFileTitle = filetitle;
648 ofn.lpstrFileTitle[0] = '\0';
649 ofn.nMaxFileTitle = sizeof(filetitle)/sizeof(filetitle[0]);
650 ofn.lpstrInitialDir = NULL;
651 ofn.lpstrTitle = title;
652 ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_ENABLESIZING;
653 ofn.nFileOffset = 0;
654 ofn.nFileExtension = 0;
655 ofn.lpstrDefExt = NULL;
656 ofn.lCustData = 0;
657 ofn.lpfnHook = NULL;
658 ofn.lpTemplateName = NULL;
660 if (GetOpenFileNameW(&ofn))
662 static const WCHAR themesSubdir[] = { '\\','T','h','e','m','e','s',0 };
663 static const WCHAR backslash[] = { '\\',0 };
664 WCHAR themeFilePath[MAX_PATH];
665 SHFILEOPSTRUCTW shfop;
667 if (FAILED (SHGetFolderPathW (NULL, CSIDL_RESOURCES|CSIDL_FLAG_CREATE, NULL,
668 SHGFP_TYPE_CURRENT, themeFilePath))) return;
670 if (lstrcmpiW(PathFindExtensionW(filetitle), themeExt)==0)
672 do_parse_theme(file);
673 SendMessageW(GetParent(dialog), PSM_CHANGED, 0, 0);
674 return;
677 PathRemoveExtensionW (filetitle);
679 /* Construct path into which the theme file goes */
680 lstrcatW (themeFilePath, themesSubdir);
681 lstrcatW (themeFilePath, backslash);
682 lstrcatW (themeFilePath, filetitle);
684 /* Create the directory */
685 SHCreateDirectoryExW (dialog, themeFilePath, NULL);
687 /* Append theme file name itself */
688 lstrcatW (themeFilePath, backslash);
689 lstrcatW (themeFilePath, PathFindFileNameW (file));
690 /* SHFileOperation() takes lists as input, so double-nullterminate */
691 themeFilePath[lstrlenW (themeFilePath)+1] = 0;
692 file[lstrlenW (file)+1] = 0;
694 /* Do the copying */
695 WINE_TRACE("copying: %s -> %s\n", wine_dbgstr_w (file),
696 wine_dbgstr_w (themeFilePath));
697 shfop.hwnd = dialog;
698 shfop.wFunc = FO_COPY;
699 shfop.pFrom = file;
700 shfop.pTo = themeFilePath;
701 shfop.fFlags = FOF_NOCONFIRMMKDIR;
702 if (SHFileOperationW (&shfop) == 0)
704 scan_theme_files();
705 if (!fill_theme_list (GetDlgItem (dialog, IDC_THEME_THEMECOMBO),
706 GetDlgItem (dialog, IDC_THEME_COLORCOMBO),
707 GetDlgItem (dialog, IDC_THEME_SIZECOMBO)))
709 SendMessageW (GetDlgItem (dialog, IDC_THEME_COLORCOMBO), CB_SETCURSEL, -1, 0);
710 SendMessageW (GetDlgItem (dialog, IDC_THEME_SIZECOMBO), CB_SETCURSEL, -1, 0);
711 enable_size_and_color_controls (dialog, FALSE);
713 else
715 enable_size_and_color_controls (dialog, TRUE);
718 else
719 WINE_TRACE("copy operation failed\n");
721 else WINE_TRACE("user cancelled\n");
724 /* Information about symbolic link targets of certain User Shell Folders. */
725 struct ShellFolderInfo {
726 int nFolder;
727 char szLinkTarget[FILENAME_MAX]; /* in unix locale */
730 static struct ShellFolderInfo asfiInfo[] = {
731 { CSIDL_DESKTOP, "" },
732 { CSIDL_PERSONAL, "" },
733 { CSIDL_MYPICTURES, "" },
734 { CSIDL_MYMUSIC, "" },
735 { CSIDL_MYVIDEO, "" }
738 static struct ShellFolderInfo *psfiSelected = NULL;
740 #define NUM_ELEMS(x) (sizeof(x)/sizeof(*(x)))
742 static void init_shell_folder_listview_headers(HWND dialog) {
743 LVCOLUMNW listColumn;
744 RECT viewRect;
745 WCHAR szShellFolder[64] = {'S','h','e','l','l',' ','F','o','l','d','e','r',0};
746 WCHAR szLinksTo[64] = {'L','i','n','k','s',' ','t','o',0};
747 int width;
749 LoadStringW(GetModuleHandleW(NULL), IDS_SHELL_FOLDER, szShellFolder, sizeof(szShellFolder)/sizeof(WCHAR));
750 LoadStringW(GetModuleHandleW(NULL), IDS_LINKS_TO, szLinksTo, sizeof(szLinksTo)/sizeof(WCHAR));
752 GetClientRect(GetDlgItem(dialog, IDC_LIST_SFPATHS), &viewRect);
753 width = (viewRect.right - viewRect.left) / 3;
755 listColumn.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
756 listColumn.pszText = szShellFolder;
757 listColumn.cchTextMax = strlenW(listColumn.pszText);
758 listColumn.cx = width;
760 SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_INSERTCOLUMNW, 0, (LPARAM) &listColumn);
762 listColumn.pszText = szLinksTo;
763 listColumn.cchTextMax = strlenW(listColumn.pszText);
764 listColumn.cx = viewRect.right - viewRect.left - width - 1;
766 SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_INSERTCOLUMNW, 1, (LPARAM) &listColumn);
769 /* Reads the currently set shell folder symbol link targets into asfiInfo. */
770 static void read_shell_folder_link_targets(void) {
771 WCHAR wszPath[MAX_PATH];
772 HRESULT hr;
773 int i;
775 for (i=0; i<NUM_ELEMS(asfiInfo); i++) {
776 asfiInfo[i].szLinkTarget[0] = '\0';
777 hr = SHGetFolderPathW(NULL, asfiInfo[i].nFolder|CSIDL_FLAG_DONT_VERIFY, NULL,
778 SHGFP_TYPE_CURRENT, wszPath);
779 if (SUCCEEDED(hr)) {
780 char *pszUnixPath = wine_get_unix_file_name(wszPath);
781 if (pszUnixPath) {
782 struct stat statPath;
783 if (!lstat(pszUnixPath, &statPath) && S_ISLNK(statPath.st_mode)) {
784 int cLen = readlink(pszUnixPath, asfiInfo[i].szLinkTarget, FILENAME_MAX-1);
785 if (cLen >= 0) asfiInfo[i].szLinkTarget[cLen] = '\0';
787 HeapFree(GetProcessHeap(), 0, pszUnixPath);
793 static void update_shell_folder_listview(HWND dialog) {
794 int i;
795 LVITEMW item;
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<NUM_ELEMS(asfiInfo); i++) {
802 WCHAR buffer[MAX_PATH];
803 HRESULT hr;
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);
808 if (SUCCEEDED(hr)) {
809 LPSHELLFOLDER psfParent;
810 LPCITEMIDLIST pidlLast;
811 hr = SHBindToParent(pidlCurrent, &IID_IShellFolder, (LPVOID*)&psfParent, &pidlLast);
812 if (SUCCEEDED(hr)) {
813 STRRET strRet;
814 hr = IShellFolder_GetDisplayNameOf(psfParent, pidlLast, SHGDN_FORADDRESSBAR, &strRet);
815 if (SUCCEEDED(hr)) {
816 hr = StrRetToBufW(&strRet, pidlLast, buffer, MAX_PATH);
818 IShellFolder_Release(psfParent);
820 ILFree(pidlCurrent);
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. */
825 if (FAILED(hr)) {
826 hr = SHGetFolderPathW(dialog, asfiInfo[i].nFolder|CSIDL_FLAG_DONT_VERIFY, NULL,
827 SHGFP_TYPE_CURRENT, buffer);
830 item.mask = LVIF_TEXT | LVIF_PARAM;
831 item.iItem = i;
832 item.iSubItem = 0;
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;
838 item.iItem = i;
839 item.iSubItem = 1;
840 item.pszText = strdupU2W(asfiInfo[i].szLinkTarget);
841 SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_SETITEMW, 0, (LPARAM)&item);
842 HeapFree(GetProcessHeap(), 0, item.pszText);
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 (strlen(psfiSelected->szLinkTarget)) {
859 WCHAR *link;
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);
865 HeapFree(GetProcessHeap(), 0, link);
866 } else {
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, "");
872 } else {
873 psfiSelected = NULL;
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) {
885 LVITEMW item;
886 WCHAR *text = get_textW(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) {
891 HeapFree(GetProcessHeap(), 0, text);
892 return;
895 WideCharToMultiByte(CP_UNIXCP, 0, text, -1,
896 psfiSelected->szLinkTarget, FILENAME_MAX, NULL, NULL);
898 item.mask = LVIF_TEXT;
899 item.iItem = iSel;
900 item.iSubItem = 1;
901 item.pszText = text;
902 SendDlgItemMessageW(hDlg, IDC_LIST_SFPATHS, LVM_SETITEMW, 0, (LPARAM)&item);
904 HeapFree(GetProcessHeap(), 0, text);
906 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
909 static void apply_shell_folder_changes(void) {
910 WCHAR wszPath[MAX_PATH];
911 char szBackupPath[FILENAME_MAX], szUnixPath[FILENAME_MAX], *pszUnixPath = NULL;
912 int i;
913 struct stat statPath;
914 HRESULT hr;
916 for (i=0; i<NUM_ELEMS(asfiInfo); i++) {
917 /* Ignore nonexistent link targets */
918 if (asfiInfo[i].szLinkTarget[0] && stat(asfiInfo[i].szLinkTarget, &statPath))
919 continue;
921 hr = SHGetFolderPathW(NULL, asfiInfo[i].nFolder|CSIDL_FLAG_CREATE, NULL,
922 SHGFP_TYPE_CURRENT, wszPath);
923 if (FAILED(hr)) continue;
925 /* Retrieve the corresponding unix path. */
926 pszUnixPath = wine_get_unix_file_name(wszPath);
927 if (!pszUnixPath) continue;
928 lstrcpyA(szUnixPath, pszUnixPath);
929 HeapFree(GetProcessHeap(), 0, pszUnixPath);
931 /* Derive name for folder backup. */
932 lstrcpyA(szBackupPath, szUnixPath);
933 lstrcatA(szBackupPath, ".winecfg");
935 if (lstat(szUnixPath, &statPath)) continue;
937 /* Move old folder/link out of the way. */
938 if (S_ISLNK(statPath.st_mode)) {
939 if (unlink(szUnixPath)) continue; /* Unable to remove link. */
940 } else {
941 if (!*asfiInfo[i].szLinkTarget) {
942 continue; /* We are done. Old was real folder, as new shall be. */
943 } else {
944 if (rename(szUnixPath, szBackupPath)) { /* Move folder out of the way. */
945 continue; /* Unable to move old folder. */
950 /* Create new link/folder. */
951 if (*asfiInfo[i].szLinkTarget) {
952 symlink(asfiInfo[i].szLinkTarget, szUnixPath);
953 } else {
954 /* If there's a backup folder, restore it. Else create new folder. */
955 if (!lstat(szBackupPath, &statPath) && S_ISDIR(statPath.st_mode)) {
956 rename(szBackupPath, szUnixPath);
957 } else {
958 mkdir(szUnixPath, 0777);
964 static void refresh_sysparams(HWND hDlg)
966 int i;
968 for (i = 0; i < sizeof(metrics) / sizeof(metrics[0]); i++)
970 if (metrics[i].sm_idx != -1)
971 metrics[i].size = GetSystemMetrics(metrics[i].sm_idx);
972 if (metrics[i].color_idx != -1)
973 metrics[i].color = GetSysColor(metrics[i].color_idx);
976 on_sysparam_change(hDlg);
979 static void read_sysparams(HWND hDlg)
981 WCHAR buffer[256];
982 HWND list = GetDlgItem(hDlg, IDC_SYSPARAM_COMBO);
983 NONCLIENTMETRICSW nonclient_metrics;
984 int i, idx;
986 for (i = 0; i < sizeof(metrics) / sizeof(metrics[0]); i++)
988 LoadStringW(GetModuleHandleW(NULL), i + IDC_SYSPARAMS_BUTTON, buffer,
989 sizeof(buffer) / sizeof(buffer[0]));
990 idx = SendMessageW(list, CB_ADDSTRING, 0, (LPARAM)buffer);
991 if (idx != CB_ERR) SendMessageW(list, CB_SETITEMDATA, idx, i);
993 if (metrics[i].sm_idx != -1)
994 metrics[i].size = GetSystemMetrics(metrics[i].sm_idx);
995 if (metrics[i].color_idx != -1)
996 metrics[i].color = GetSysColor(metrics[i].color_idx);
999 nonclient_metrics.cbSize = sizeof(NONCLIENTMETRICSW);
1000 SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSW), &nonclient_metrics, 0);
1002 memcpy(&(metrics[IDC_SYSPARAMS_MENU_TEXT - IDC_SYSPARAMS_BUTTON].lf),
1003 &(nonclient_metrics.lfMenuFont), sizeof(LOGFONTW));
1004 memcpy(&(metrics[IDC_SYSPARAMS_ACTIVE_TITLE_TEXT - IDC_SYSPARAMS_BUTTON].lf),
1005 &(nonclient_metrics.lfCaptionFont), sizeof(LOGFONTW));
1006 memcpy(&(metrics[IDC_SYSPARAMS_TOOLTIP_TEXT - IDC_SYSPARAMS_BUTTON].lf),
1007 &(nonclient_metrics.lfStatusFont), sizeof(LOGFONTW));
1008 memcpy(&(metrics[IDC_SYSPARAMS_MSGBOX_TEXT - IDC_SYSPARAMS_BUTTON].lf),
1009 &(nonclient_metrics.lfMessageFont), sizeof(LOGFONTW));
1012 static void apply_sysparams(void)
1014 NONCLIENTMETRICSW ncm;
1015 int i, cnt = 0;
1016 int colors_idx[sizeof(metrics) / sizeof(metrics[0])];
1017 COLORREF colors[sizeof(metrics) / sizeof(metrics[0])];
1018 HDC hdc;
1019 int dpi;
1021 hdc = GetDC( 0 );
1022 dpi = GetDeviceCaps( hdc, LOGPIXELSY );
1023 ReleaseDC( 0, hdc );
1025 ncm.cbSize = sizeof(ncm);
1026 SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0);
1028 /* convert metrics back to twips */
1029 ncm.iMenuWidth = ncm.iMenuHeight =
1030 MulDiv( metrics[IDC_SYSPARAMS_MENU - IDC_SYSPARAMS_BUTTON].size, -1440, dpi );
1031 ncm.iCaptionWidth = ncm.iCaptionHeight =
1032 MulDiv( metrics[IDC_SYSPARAMS_ACTIVE_TITLE - IDC_SYSPARAMS_BUTTON].size, -1440, dpi );
1033 ncm.iScrollWidth = ncm.iScrollHeight =
1034 MulDiv( metrics[IDC_SYSPARAMS_SCROLLBAR - IDC_SYSPARAMS_BUTTON].size, -1440, dpi );
1035 ncm.iSmCaptionWidth = MulDiv( ncm.iSmCaptionWidth, -1440, dpi );
1036 ncm.iSmCaptionHeight = MulDiv( ncm.iSmCaptionHeight, -1440, dpi );
1038 ncm.lfMenuFont = metrics[IDC_SYSPARAMS_MENU_TEXT - IDC_SYSPARAMS_BUTTON].lf;
1039 ncm.lfCaptionFont = metrics[IDC_SYSPARAMS_ACTIVE_TITLE_TEXT - IDC_SYSPARAMS_BUTTON].lf;
1040 ncm.lfStatusFont = metrics[IDC_SYSPARAMS_TOOLTIP_TEXT - IDC_SYSPARAMS_BUTTON].lf;
1041 ncm.lfMessageFont = metrics[IDC_SYSPARAMS_MSGBOX_TEXT - IDC_SYSPARAMS_BUTTON].lf;
1043 ncm.lfMenuFont.lfHeight = MulDiv( ncm.lfMenuFont.lfHeight, -72, dpi );
1044 ncm.lfCaptionFont.lfHeight = MulDiv( ncm.lfCaptionFont.lfHeight, -72, dpi );
1045 ncm.lfStatusFont.lfHeight = MulDiv( ncm.lfStatusFont.lfHeight, -72, dpi );
1046 ncm.lfMessageFont.lfHeight = MulDiv( ncm.lfMessageFont.lfHeight, -72, dpi );
1047 ncm.lfSmCaptionFont.lfHeight = MulDiv( ncm.lfSmCaptionFont.lfHeight, -72, dpi );
1049 SystemParametersInfoW(SPI_SETNONCLIENTMETRICS, sizeof(ncm), &ncm,
1050 SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
1052 for (i = 0; i < sizeof(metrics) / sizeof(metrics[0]); i++)
1053 if (metrics[i].color_idx != -1)
1055 colors_idx[cnt] = metrics[i].color_idx;
1056 colors[cnt++] = metrics[i].color;
1058 SetSysColors(cnt, colors_idx, colors);
1061 static void on_sysparam_change(HWND hDlg)
1063 int index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETCURSEL, 0, 0);
1065 index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETITEMDATA, index, 0);
1067 updating_ui = TRUE;
1069 EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_COLOR_TEXT), metrics[index].color_idx != -1);
1070 EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_COLOR), metrics[index].color_idx != -1);
1071 InvalidateRect(GetDlgItem(hDlg, IDC_SYSPARAM_COLOR), NULL, TRUE);
1073 EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_SIZE_TEXT), metrics[index].sm_idx != -1);
1074 EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_SIZE), metrics[index].sm_idx != -1);
1075 EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_SIZE_UD), metrics[index].sm_idx != -1);
1076 if (metrics[index].sm_idx != -1)
1077 SendDlgItemMessageW(hDlg, IDC_SYSPARAM_SIZE_UD, UDM_SETPOS, 0, MAKELONG(metrics[index].size, 0));
1078 else
1079 set_text(hDlg, IDC_SYSPARAM_SIZE, "");
1081 EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_FONT),
1082 index == IDC_SYSPARAMS_MENU_TEXT-IDC_SYSPARAMS_BUTTON ||
1083 index == IDC_SYSPARAMS_ACTIVE_TITLE_TEXT-IDC_SYSPARAMS_BUTTON ||
1084 index == IDC_SYSPARAMS_TOOLTIP_TEXT-IDC_SYSPARAMS_BUTTON ||
1085 index == IDC_SYSPARAMS_MSGBOX_TEXT-IDC_SYSPARAMS_BUTTON
1088 updating_ui = FALSE;
1091 static void on_draw_item(HWND hDlg, WPARAM wParam, LPARAM lParam)
1093 static HBRUSH black_brush = 0;
1094 LPDRAWITEMSTRUCT draw_info = (LPDRAWITEMSTRUCT)lParam;
1096 if (!black_brush) black_brush = CreateSolidBrush(0);
1098 if (draw_info->CtlID == IDC_SYSPARAM_COLOR)
1100 UINT state;
1101 HTHEME theme;
1102 RECT buttonrect;
1104 theme = OpenThemeData(NULL, WC_BUTTONW);
1106 if (theme) {
1107 MARGINS margins;
1109 if (draw_info->itemState & ODS_DISABLED)
1110 state = PBS_DISABLED;
1111 else if (draw_info->itemState & ODS_SELECTED)
1112 state = PBS_PRESSED;
1113 else
1114 state = PBS_NORMAL;
1116 if (IsThemeBackgroundPartiallyTransparent(theme, BP_PUSHBUTTON, state))
1117 DrawThemeParentBackground(draw_info->hwndItem, draw_info->hDC, NULL);
1119 DrawThemeBackground(theme, draw_info->hDC, BP_PUSHBUTTON, state, &draw_info->rcItem, NULL);
1121 buttonrect = draw_info->rcItem;
1123 GetThemeMargins(theme, draw_info->hDC, BP_PUSHBUTTON, state, TMT_CONTENTMARGINS, &draw_info->rcItem, &margins);
1125 buttonrect.left += margins.cxLeftWidth;
1126 buttonrect.top += margins.cyTopHeight;
1127 buttonrect.right -= margins.cxRightWidth;
1128 buttonrect.bottom -= margins.cyBottomHeight;
1130 if (draw_info->itemState & ODS_FOCUS)
1131 DrawFocusRect(draw_info->hDC, &buttonrect);
1133 CloseThemeData(theme);
1134 } else {
1135 state = DFCS_ADJUSTRECT | DFCS_BUTTONPUSH;
1137 if (draw_info->itemState & ODS_DISABLED)
1138 state |= DFCS_INACTIVE;
1139 else
1140 state |= draw_info->itemState & ODS_SELECTED ? DFCS_PUSHED : 0;
1142 DrawFrameControl(draw_info->hDC, &draw_info->rcItem, DFC_BUTTON, state);
1144 buttonrect = draw_info->rcItem;
1147 if (!(draw_info->itemState & ODS_DISABLED))
1149 HBRUSH brush;
1150 int index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETCURSEL, 0, 0);
1152 index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETITEMDATA, index, 0);
1153 brush = CreateSolidBrush(metrics[index].color);
1155 InflateRect(&buttonrect, -1, -1);
1156 FrameRect(draw_info->hDC, &buttonrect, black_brush);
1157 InflateRect(&buttonrect, -1, -1);
1158 FillRect(draw_info->hDC, &buttonrect, brush);
1159 DeleteObject(brush);
1164 static void on_select_font(HWND hDlg)
1166 CHOOSEFONTW cf;
1167 int index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETCURSEL, 0, 0);
1168 index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETITEMDATA, index, 0);
1170 ZeroMemory(&cf, sizeof(cf));
1171 cf.lStructSize = sizeof(CHOOSEFONTW);
1172 cf.hwndOwner = hDlg;
1173 cf.lpLogFont = &(metrics[index].lf);
1174 cf.Flags = CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT | CF_NOSCRIPTSEL | CF_NOVERTFONTS;
1176 if (ChooseFontW(&cf))
1177 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1180 INT_PTR CALLBACK
1181 ThemeDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1183 switch (uMsg) {
1184 case WM_INITDIALOG:
1185 read_shell_folder_link_targets();
1186 init_shell_folder_listview_headers(hDlg);
1187 update_shell_folder_listview(hDlg);
1188 read_sysparams(hDlg);
1189 break;
1191 case WM_DESTROY:
1192 free_theme_files();
1193 break;
1195 case WM_SHOWWINDOW:
1196 set_window_title(hDlg);
1197 break;
1199 case WM_COMMAND:
1200 switch(HIWORD(wParam)) {
1201 case CBN_SELCHANGE: {
1202 if (updating_ui) break;
1203 switch (LOWORD(wParam))
1205 case IDC_THEME_THEMECOMBO: on_theme_changed(hDlg); break;
1206 case IDC_THEME_COLORCOMBO: /* fall through */
1207 case IDC_THEME_SIZECOMBO: theme_dirty = TRUE; break;
1208 case IDC_SYSPARAM_COMBO: on_sysparam_change(hDlg); return FALSE;
1210 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1211 break;
1213 case EN_CHANGE: {
1214 if (updating_ui) break;
1215 switch (LOWORD(wParam))
1217 case IDC_EDIT_SFPATH: on_shell_folder_edit_changed(hDlg); break;
1218 case IDC_SYSPARAM_SIZE:
1220 char *text = get_text(hDlg, IDC_SYSPARAM_SIZE);
1221 int index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETCURSEL, 0, 0);
1223 index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETITEMDATA, index, 0);
1225 if (text)
1227 metrics[index].size = atoi(text);
1228 HeapFree(GetProcessHeap(), 0, text);
1230 else
1232 /* for empty string set to minimum value */
1233 SendDlgItemMessageW(hDlg, IDC_SYSPARAM_SIZE_UD, UDM_GETRANGE32, (WPARAM)&metrics[index].size, 0);
1236 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1237 break;
1240 break;
1242 case BN_CLICKED:
1243 switch (LOWORD(wParam))
1245 case IDC_THEME_INSTALL:
1246 on_theme_install (hDlg);
1247 break;
1249 case IDC_SYSPARAM_FONT:
1250 on_select_font(hDlg);
1251 break;
1253 case IDC_BROWSE_SFPATH:
1255 WCHAR link[FILENAME_MAX];
1256 if (browse_for_unix_folder(hDlg, link)) {
1257 WideCharToMultiByte(CP_UNIXCP, 0, link, -1,
1258 psfiSelected->szLinkTarget, FILENAME_MAX,
1259 NULL, NULL);
1260 update_shell_folder_listview(hDlg);
1261 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1263 break;
1266 case IDC_LINK_SFPATH:
1267 if (IsDlgButtonChecked(hDlg, IDC_LINK_SFPATH)) {
1268 WCHAR link[FILENAME_MAX];
1269 if (browse_for_unix_folder(hDlg, link)) {
1270 WideCharToMultiByte(CP_UNIXCP, 0, link, -1,
1271 psfiSelected->szLinkTarget, FILENAME_MAX,
1272 NULL, NULL);
1273 update_shell_folder_listview(hDlg);
1274 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1275 } else {
1276 CheckDlgButton(hDlg, IDC_LINK_SFPATH, BST_UNCHECKED);
1278 } else {
1279 psfiSelected->szLinkTarget[0] = '\0';
1280 update_shell_folder_listview(hDlg);
1281 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1283 break;
1285 case IDC_SYSPARAM_COLOR:
1287 static COLORREF user_colors[16];
1288 CHOOSECOLORW c_color;
1289 int index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETCURSEL, 0, 0);
1291 index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETITEMDATA, index, 0);
1293 memset(&c_color, 0, sizeof(c_color));
1294 c_color.lStructSize = sizeof(c_color);
1295 c_color.lpCustColors = user_colors;
1296 c_color.rgbResult = metrics[index].color;
1297 c_color.Flags = CC_ANYCOLOR | CC_RGBINIT;
1298 c_color.hwndOwner = hDlg;
1299 if (ChooseColorW(&c_color))
1301 metrics[index].color = c_color.rgbResult;
1302 save_sys_color(index, metrics[index].color);
1303 InvalidateRect(GetDlgItem(hDlg, IDC_SYSPARAM_COLOR), NULL, TRUE);
1304 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1306 break;
1309 break;
1311 break;
1313 case WM_NOTIFY:
1314 switch (((LPNMHDR)lParam)->code) {
1315 case PSN_KILLACTIVE: {
1316 SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, FALSE);
1317 break;
1319 case PSN_APPLY: {
1320 apply();
1321 apply_theme(hDlg);
1322 apply_shell_folder_changes();
1323 apply_sysparams();
1324 read_shell_folder_link_targets();
1325 update_shell_folder_listview(hDlg);
1326 SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
1327 break;
1329 case LVN_ITEMCHANGED: {
1330 if (wParam == IDC_LIST_SFPATHS)
1331 on_shell_folder_selection_changed(hDlg, (LPNMLISTVIEW)lParam);
1332 break;
1334 case PSN_SETACTIVE: {
1335 init_dialog (hDlg);
1336 break;
1339 break;
1341 case WM_DRAWITEM:
1342 on_draw_item(hDlg, wParam, lParam);
1343 break;
1345 default:
1346 break;
1348 return FALSE;