msgsm32.acm: Use standard dlopen() instead of the libwine wrappers.
[wine/zf.git] / programs / winecfg / theme.c
blobb38b2ff26d64bc7217b80acf0f39040bf97a8791
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
38 #define COBJMACROS
40 #include <windows.h>
41 #include <commdlg.h>
42 #include <shellapi.h>
43 #include <uxtheme.h>
44 #include <tmschema.h>
45 #include <shlobj.h>
46 #include <shlwapi.h>
47 #include <wine/debug.h>
48 #include <wine/unicode.h>
50 #include "resource.h"
51 #include "winecfg.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
55 /* UXTHEME functions not in the headers */
57 typedef struct tagTHEMENAMES
59 WCHAR szName[MAX_PATH+1];
60 WCHAR szDisplayName[MAX_PATH+1];
61 WCHAR szTooltip[MAX_PATH+1];
62 } THEMENAMES, *PTHEMENAMES;
64 typedef void* HTHEMEFILE;
65 typedef BOOL (CALLBACK *EnumThemeProc)(LPVOID lpReserved,
66 LPCWSTR pszThemeFileName,
67 LPCWSTR pszThemeName,
68 LPCWSTR pszToolTip, LPVOID lpReserved2,
69 LPVOID lpData);
71 HRESULT WINAPI EnumThemeColors (LPCWSTR pszThemeFileName, LPWSTR pszSizeName,
72 DWORD dwColorNum, PTHEMENAMES pszColorNames);
73 HRESULT WINAPI EnumThemeSizes (LPCWSTR pszThemeFileName, LPWSTR pszColorName,
74 DWORD dwSizeNum, PTHEMENAMES pszSizeNames);
75 HRESULT WINAPI ApplyTheme (HTHEMEFILE hThemeFile, char* unknown, HWND hWnd);
76 HRESULT WINAPI OpenThemeFile (LPCWSTR pszThemeFileName, LPCWSTR pszColorName,
77 LPCWSTR pszSizeName, HTHEMEFILE* hThemeFile,
78 DWORD unknown);
79 HRESULT WINAPI CloseThemeFile (HTHEMEFILE hThemeFile);
80 HRESULT WINAPI EnumThemes (LPCWSTR pszThemePath, EnumThemeProc callback,
81 LPVOID lpData);
83 static void refresh_sysparams(HWND hDlg);
84 static void on_sysparam_change(HWND hDlg);
86 /* A struct to keep both the internal and "fancy" name of a color or size */
87 typedef struct
89 WCHAR* name;
90 WCHAR* fancyName;
91 } ThemeColorOrSize;
93 /* wrapper around DSA that also keeps an item count */
94 typedef struct
96 HDSA dsa;
97 int count;
98 } WrappedDsa;
100 /* Some helper functions to deal with ThemeColorOrSize structs in WrappedDSAs */
102 static void color_or_size_dsa_add (WrappedDsa* wdsa, const WCHAR* name,
103 const WCHAR* fancyName)
105 ThemeColorOrSize item;
107 item.name = HeapAlloc (GetProcessHeap(), 0,
108 (lstrlenW (name) + 1) * sizeof(WCHAR));
109 lstrcpyW (item.name, name);
111 item.fancyName = HeapAlloc (GetProcessHeap(), 0,
112 (lstrlenW (fancyName) + 1) * sizeof(WCHAR));
113 lstrcpyW (item.fancyName, fancyName);
115 DSA_InsertItem (wdsa->dsa, wdsa->count, &item);
116 wdsa->count++;
119 static int CALLBACK dsa_destroy_callback (LPVOID p, LPVOID pData)
121 ThemeColorOrSize* item = p;
122 HeapFree (GetProcessHeap(), 0, item->name);
123 HeapFree (GetProcessHeap(), 0, item->fancyName);
124 return 1;
127 static void free_color_or_size_dsa (WrappedDsa* wdsa)
129 DSA_DestroyCallback (wdsa->dsa, dsa_destroy_callback, NULL);
132 static void create_color_or_size_dsa (WrappedDsa* wdsa)
134 wdsa->dsa = DSA_Create (sizeof (ThemeColorOrSize), 1);
135 wdsa->count = 0;
138 static ThemeColorOrSize* color_or_size_dsa_get (WrappedDsa* wdsa, int index)
140 return DSA_GetItemPtr (wdsa->dsa, index);
143 static int color_or_size_dsa_find (WrappedDsa* wdsa, const WCHAR* name)
145 int i = 0;
146 for (; i < wdsa->count; i++)
148 ThemeColorOrSize* item = color_or_size_dsa_get (wdsa, i);
149 if (lstrcmpiW (item->name, name) == 0) break;
151 return i;
154 /* A theme file, contains file name, display name, color and size scheme names */
155 typedef struct
157 WCHAR* themeFileName;
158 WCHAR* fancyName;
159 WrappedDsa colors;
160 WrappedDsa sizes;
161 } ThemeFile;
163 static HDSA themeFiles = NULL;
164 static int themeFilesCount = 0;
166 static int CALLBACK theme_dsa_destroy_callback (LPVOID p, LPVOID pData)
168 ThemeFile* item = p;
169 HeapFree (GetProcessHeap(), 0, item->themeFileName);
170 HeapFree (GetProcessHeap(), 0, item->fancyName);
171 free_color_or_size_dsa (&item->colors);
172 free_color_or_size_dsa (&item->sizes);
173 return 1;
176 /* Free memory occupied by the theme list */
177 static void free_theme_files(void)
179 if (themeFiles == NULL) return;
181 DSA_DestroyCallback (themeFiles , theme_dsa_destroy_callback, NULL);
182 themeFiles = NULL;
183 themeFilesCount = 0;
186 typedef HRESULT (WINAPI * EnumTheme) (LPCWSTR, LPWSTR, DWORD, PTHEMENAMES);
188 /* fill a string list with either colors or sizes of a theme */
189 static void fill_theme_string_array (const WCHAR* filename,
190 WrappedDsa* wdsa,
191 EnumTheme enumTheme)
193 DWORD index = 0;
194 THEMENAMES names;
196 WINE_TRACE ("%s %p %p\n", wine_dbgstr_w (filename), wdsa, enumTheme);
198 while (SUCCEEDED (enumTheme (filename, NULL, index++, &names)))
200 WINE_TRACE ("%s: %s\n", wine_dbgstr_w (names.szName),
201 wine_dbgstr_w (names.szDisplayName));
202 color_or_size_dsa_add (wdsa, names.szName, names.szDisplayName);
206 /* Theme enumeration callback, adds theme to theme list */
207 static BOOL CALLBACK myEnumThemeProc (LPVOID lpReserved,
208 LPCWSTR pszThemeFileName,
209 LPCWSTR pszThemeName,
210 LPCWSTR pszToolTip,
211 LPVOID lpReserved2, LPVOID lpData)
213 ThemeFile newEntry;
215 /* fill size/color lists */
216 create_color_or_size_dsa (&newEntry.colors);
217 fill_theme_string_array (pszThemeFileName, &newEntry.colors, EnumThemeColors);
218 create_color_or_size_dsa (&newEntry.sizes);
219 fill_theme_string_array (pszThemeFileName, &newEntry.sizes, EnumThemeSizes);
221 newEntry.themeFileName = HeapAlloc (GetProcessHeap(), 0,
222 (lstrlenW (pszThemeFileName) + 1) * sizeof(WCHAR));
223 lstrcpyW (newEntry.themeFileName, pszThemeFileName);
225 newEntry.fancyName = HeapAlloc (GetProcessHeap(), 0,
226 (lstrlenW (pszThemeName) + 1) * sizeof(WCHAR));
227 lstrcpyW (newEntry.fancyName, pszThemeName);
229 /*list_add_tail (&themeFiles, &newEntry->entry);*/
230 DSA_InsertItem (themeFiles, themeFilesCount, &newEntry);
231 themeFilesCount++;
233 return TRUE;
236 /* Scan for themes */
237 static void scan_theme_files(void)
239 static const WCHAR themesSubdir[] = { '\\','T','h','e','m','e','s',0 };
240 WCHAR themesPath[MAX_PATH];
242 free_theme_files();
244 if (FAILED (SHGetFolderPathW (NULL, CSIDL_RESOURCES, NULL,
245 SHGFP_TYPE_CURRENT, themesPath))) return;
247 themeFiles = DSA_Create (sizeof (ThemeFile), 1);
248 lstrcatW (themesPath, themesSubdir);
250 EnumThemes (themesPath, myEnumThemeProc, 0);
253 /* fill the color & size combo boxes for a given theme */
254 static void fill_color_size_combos (ThemeFile* theme, HWND comboColor,
255 HWND comboSize)
257 int i;
259 SendMessageW (comboColor, CB_RESETCONTENT, 0, 0);
260 for (i = 0; i < theme->colors.count; i++)
262 ThemeColorOrSize* item = color_or_size_dsa_get (&theme->colors, i);
263 SendMessageW (comboColor, CB_ADDSTRING, 0, (LPARAM)item->fancyName);
266 SendMessageW (comboSize, CB_RESETCONTENT, 0, 0);
267 for (i = 0; i < theme->sizes.count; i++)
269 ThemeColorOrSize* item = color_or_size_dsa_get (&theme->sizes, i);
270 SendMessageW (comboSize, CB_ADDSTRING, 0, (LPARAM)item->fancyName);
274 /* Select the item of a combo box that matches a theme's color and size
275 * scheme. */
276 static void select_color_and_size (ThemeFile* theme,
277 const WCHAR* colorName, HWND comboColor,
278 const WCHAR* sizeName, HWND comboSize)
280 SendMessageW (comboColor, CB_SETCURSEL,
281 color_or_size_dsa_find (&theme->colors, colorName), 0);
282 SendMessageW (comboSize, CB_SETCURSEL,
283 color_or_size_dsa_find (&theme->sizes, sizeName), 0);
286 /* Fill theme, color and sizes combo boxes with the know themes and select
287 * the entries matching the currently active theme. */
288 static BOOL fill_theme_list (HWND comboTheme, HWND comboColor, HWND comboSize)
290 WCHAR textNoTheme[256];
291 int themeIndex = 0;
292 BOOL ret = TRUE;
293 int i;
294 WCHAR currentTheme[MAX_PATH];
295 WCHAR currentColor[MAX_PATH];
296 WCHAR currentSize[MAX_PATH];
297 ThemeFile* theme = NULL;
299 LoadStringW(GetModuleHandleW(NULL), IDS_NOTHEME, textNoTheme, ARRAY_SIZE(textNoTheme));
301 SendMessageW (comboTheme, CB_RESETCONTENT, 0, 0);
302 SendMessageW (comboTheme, CB_ADDSTRING, 0, (LPARAM)textNoTheme);
304 for (i = 0; i < themeFilesCount; i++)
306 ThemeFile* item = DSA_GetItemPtr (themeFiles, i);
307 SendMessageW (comboTheme, CB_ADDSTRING, 0,
308 (LPARAM)item->fancyName);
311 if (IsThemeActive() && SUCCEEDED(GetCurrentThemeName(currentTheme, ARRAY_SIZE(currentTheme),
312 currentColor, ARRAY_SIZE(currentColor), currentSize, ARRAY_SIZE(currentSize))))
314 /* Determine the index of the currently active theme. */
315 BOOL found = FALSE;
316 for (i = 0; i < themeFilesCount; i++)
318 theme = DSA_GetItemPtr (themeFiles, i);
319 if (lstrcmpiW (theme->themeFileName, currentTheme) == 0)
321 found = TRUE;
322 themeIndex = i+1;
323 break;
326 if (!found)
328 /* Current theme not found?... add to the list, then... */
329 WINE_TRACE("Theme %s not in list of enumerated themes\n",
330 wine_dbgstr_w (currentTheme));
331 myEnumThemeProc (NULL, currentTheme, currentTheme,
332 currentTheme, NULL, NULL);
333 themeIndex = themeFilesCount;
334 theme = DSA_GetItemPtr (themeFiles, themeFilesCount-1);
336 fill_color_size_combos (theme, comboColor, comboSize);
337 select_color_and_size (theme, currentColor, comboColor,
338 currentSize, comboSize);
340 else
342 /* No theme selected */
343 ret = FALSE;
346 SendMessageW (comboTheme, CB_SETCURSEL, themeIndex, 0);
347 return ret;
350 /* Update the color & size combo boxes when the selection of the theme
351 * combo changed. Selects the current color and size scheme if the theme
352 * is currently active, otherwise the first color and size. */
353 static BOOL update_color_and_size (int themeIndex, HWND comboColor,
354 HWND comboSize)
356 if (themeIndex == 0)
358 return FALSE;
360 else
362 WCHAR currentTheme[MAX_PATH];
363 WCHAR currentColor[MAX_PATH];
364 WCHAR currentSize[MAX_PATH];
365 ThemeFile* theme = DSA_GetItemPtr (themeFiles, themeIndex - 1);
367 fill_color_size_combos (theme, comboColor, comboSize);
369 if ((SUCCEEDED(GetCurrentThemeName (currentTheme, ARRAY_SIZE(currentTheme),
370 currentColor, ARRAY_SIZE(currentColor), currentSize, ARRAY_SIZE(currentSize))))
371 && (lstrcmpiW (currentTheme, theme->themeFileName) == 0))
373 select_color_and_size (theme, currentColor, comboColor,
374 currentSize, comboSize);
376 else
378 SendMessageW (comboColor, CB_SETCURSEL, 0, 0);
379 SendMessageW (comboSize, CB_SETCURSEL, 0, 0);
382 return TRUE;
385 /* Apply a theme from a given theme, color and size combo box item index. */
386 static void do_apply_theme (HWND dialog, int themeIndex, int colorIndex, int sizeIndex)
388 static char b[] = "\0";
390 if (themeIndex == 0)
392 /* no theme */
393 ApplyTheme (NULL, b, NULL);
395 else
397 ThemeFile* theme = DSA_GetItemPtr (themeFiles, themeIndex-1);
398 const WCHAR* themeFileName = theme->themeFileName;
399 const WCHAR* colorName = NULL;
400 const WCHAR* sizeName = NULL;
401 HTHEMEFILE hTheme;
402 ThemeColorOrSize* item;
404 item = color_or_size_dsa_get (&theme->colors, colorIndex);
405 colorName = item->name;
407 item = color_or_size_dsa_get (&theme->sizes, sizeIndex);
408 sizeName = item->name;
410 if (SUCCEEDED (OpenThemeFile (themeFileName, colorName, sizeName,
411 &hTheme, 0)))
413 ApplyTheme (hTheme, b, NULL);
414 CloseThemeFile (hTheme);
416 else
418 ApplyTheme (NULL, b, NULL);
422 refresh_sysparams(dialog);
425 static BOOL updating_ui;
426 static BOOL theme_dirty;
428 static void enable_size_and_color_controls (HWND dialog, BOOL enable)
430 EnableWindow (GetDlgItem (dialog, IDC_THEME_COLORCOMBO), enable);
431 EnableWindow (GetDlgItem (dialog, IDC_THEME_COLORTEXT), enable);
432 EnableWindow (GetDlgItem (dialog, IDC_THEME_SIZECOMBO), enable);
433 EnableWindow (GetDlgItem (dialog, IDC_THEME_SIZETEXT), enable);
436 static void init_dialog (HWND dialog)
438 updating_ui = TRUE;
440 scan_theme_files();
441 if (!fill_theme_list (GetDlgItem (dialog, IDC_THEME_THEMECOMBO),
442 GetDlgItem (dialog, IDC_THEME_COLORCOMBO),
443 GetDlgItem (dialog, IDC_THEME_SIZECOMBO)))
445 SendMessageW (GetDlgItem (dialog, IDC_THEME_COLORCOMBO), CB_SETCURSEL, (WPARAM)-1, 0);
446 SendMessageW (GetDlgItem (dialog, IDC_THEME_SIZECOMBO), CB_SETCURSEL, (WPARAM)-1, 0);
447 enable_size_and_color_controls (dialog, FALSE);
449 else
451 enable_size_and_color_controls (dialog, TRUE);
453 theme_dirty = FALSE;
455 SendDlgItemMessageW(dialog, IDC_SYSPARAM_SIZE_UD, UDM_SETBUDDY, (WPARAM)GetDlgItem(dialog, IDC_SYSPARAM_SIZE), 0);
456 SendDlgItemMessageW(dialog, IDC_SYSPARAM_SIZE_UD, UDM_SETRANGE, 0, MAKELONG(100, 8));
458 updating_ui = FALSE;
461 static void on_theme_changed(HWND dialog) {
462 int index = SendMessageW (GetDlgItem (dialog, IDC_THEME_THEMECOMBO),
463 CB_GETCURSEL, 0, 0);
464 if (!update_color_and_size (index, GetDlgItem (dialog, IDC_THEME_COLORCOMBO),
465 GetDlgItem (dialog, IDC_THEME_SIZECOMBO)))
467 SendMessageW (GetDlgItem (dialog, IDC_THEME_COLORCOMBO), CB_SETCURSEL, -1, 0);
468 SendMessageW (GetDlgItem (dialog, IDC_THEME_SIZECOMBO), CB_SETCURSEL, -1, 0);
469 enable_size_and_color_controls (dialog, FALSE);
471 else
473 enable_size_and_color_controls (dialog, TRUE);
475 theme_dirty = TRUE;
478 static void apply_theme(HWND dialog)
480 int themeIndex, colorIndex, sizeIndex;
482 if (!theme_dirty) return;
484 themeIndex = SendMessageW (GetDlgItem (dialog, IDC_THEME_THEMECOMBO),
485 CB_GETCURSEL, 0, 0);
486 colorIndex = SendMessageW (GetDlgItem (dialog, IDC_THEME_COLORCOMBO),
487 CB_GETCURSEL, 0, 0);
488 sizeIndex = SendMessageW (GetDlgItem (dialog, IDC_THEME_SIZECOMBO),
489 CB_GETCURSEL, 0, 0);
491 do_apply_theme (dialog, themeIndex, colorIndex, sizeIndex);
492 theme_dirty = FALSE;
495 static struct
497 int sm_idx, color_idx;
498 const char *color_reg;
499 int size;
500 COLORREF color;
501 LOGFONTW lf;
502 } metrics[] =
504 {-1, COLOR_BTNFACE, "ButtonFace" }, /* IDC_SYSPARAMS_BUTTON */
505 {-1, COLOR_BTNTEXT, "ButtonText" }, /* IDC_SYSPARAMS_BUTTON_TEXT */
506 {-1, COLOR_BACKGROUND, "Background" }, /* IDC_SYSPARAMS_DESKTOP */
507 {SM_CXMENUSIZE, COLOR_MENU, "Menu" }, /* IDC_SYSPARAMS_MENU */
508 {-1, COLOR_MENUTEXT, "MenuText" }, /* IDC_SYSPARAMS_MENU_TEXT */
509 {SM_CXVSCROLL, COLOR_SCROLLBAR, "Scrollbar" }, /* IDC_SYSPARAMS_SCROLLBAR */
510 {-1, COLOR_HIGHLIGHT, "Hilight" }, /* IDC_SYSPARAMS_SELECTION */
511 {-1, COLOR_HIGHLIGHTTEXT, "HilightText" }, /* IDC_SYSPARAMS_SELECTION_TEXT */
512 {-1, COLOR_INFOBK, "InfoWindow" }, /* IDC_SYSPARAMS_TOOLTIP */
513 {-1, COLOR_INFOTEXT, "InfoText" }, /* IDC_SYSPARAMS_TOOLTIP_TEXT */
514 {-1, COLOR_WINDOW, "Window" }, /* IDC_SYSPARAMS_WINDOW */
515 {-1, COLOR_WINDOWTEXT, "WindowText" }, /* IDC_SYSPARAMS_WINDOW_TEXT */
516 {SM_CXSIZE, COLOR_ACTIVECAPTION, "ActiveTitle" }, /* IDC_SYSPARAMS_ACTIVE_TITLE */
517 {-1, COLOR_CAPTIONTEXT, "TitleText" }, /* IDC_SYSPARAMS_ACTIVE_TITLE_TEXT */
518 {-1, COLOR_INACTIVECAPTION, "InactiveTitle" }, /* IDC_SYSPARAMS_INACTIVE_TITLE */
519 {-1, COLOR_INACTIVECAPTIONTEXT,"InactiveTitleText" }, /* IDC_SYSPARAMS_INACTIVE_TITLE_TEXT */
520 {-1, -1, "MsgBoxText" }, /* IDC_SYSPARAMS_MSGBOX_TEXT */
521 {-1, COLOR_APPWORKSPACE, "AppWorkSpace" }, /* IDC_SYSPARAMS_APPWORKSPACE */
522 {-1, COLOR_WINDOWFRAME, "WindowFrame" }, /* IDC_SYSPARAMS_WINDOW_FRAME */
523 {-1, COLOR_ACTIVEBORDER, "ActiveBorder" }, /* IDC_SYSPARAMS_ACTIVE_BORDER */
524 {-1, COLOR_INACTIVEBORDER, "InactiveBorder" }, /* IDC_SYSPARAMS_INACTIVE_BORDER */
525 {-1, COLOR_BTNSHADOW, "ButtonShadow" }, /* IDC_SYSPARAMS_BUTTON_SHADOW */
526 {-1, COLOR_GRAYTEXT, "GrayText" }, /* IDC_SYSPARAMS_GRAY_TEXT */
527 {-1, COLOR_BTNHIGHLIGHT, "ButtonHilight" }, /* IDC_SYSPARAMS_BUTTON_HIGHLIGHT */
528 {-1, COLOR_3DDKSHADOW, "ButtonDkShadow" }, /* IDC_SYSPARAMS_BUTTON_DARK_SHADOW */
529 {-1, COLOR_3DLIGHT, "ButtonLight" }, /* IDC_SYSPARAMS_BUTTON_LIGHT */
530 {-1, COLOR_ALTERNATEBTNFACE, "ButtonAlternateFace" }, /* IDC_SYSPARAMS_BUTTON_ALTERNATE */
531 {-1, COLOR_HOTLIGHT, "HotTrackingColor" }, /* IDC_SYSPARAMS_HOT_TRACKING */
532 {-1, COLOR_GRADIENTACTIVECAPTION, "GradientActiveTitle" }, /* IDC_SYSPARAMS_ACTIVE_TITLE_GRADIENT */
533 {-1, COLOR_GRADIENTINACTIVECAPTION, "GradientInactiveTitle" }, /* IDC_SYSPARAMS_INACTIVE_TITLE_GRADIENT */
534 {-1, COLOR_MENUHILIGHT, "MenuHilight" }, /* IDC_SYSPARAMS_MENU_HIGHLIGHT */
535 {-1, COLOR_MENUBAR, "MenuBar" }, /* IDC_SYSPARAMS_MENUBAR */
538 static void save_sys_color(int idx, COLORREF clr)
540 char buffer[13];
542 sprintf(buffer, "%d %d %d", GetRValue (clr), GetGValue (clr), GetBValue (clr));
543 set_reg_key(HKEY_CURRENT_USER, "Control Panel\\Colors", metrics[idx].color_reg, buffer);
546 static void set_color_from_theme(WCHAR *keyName, COLORREF color)
548 char *keyNameA = NULL;
549 int keyNameSize=0, i=0;
551 keyNameSize = WideCharToMultiByte(CP_ACP, 0, keyName, -1, keyNameA, 0, NULL, NULL);
552 keyNameA = HeapAlloc(GetProcessHeap(), 0, keyNameSize);
553 WideCharToMultiByte(CP_ACP, 0, keyName, -1, keyNameA, keyNameSize, NULL, NULL);
555 for (i=0; i < ARRAY_SIZE(metrics); i++)
557 if (lstrcmpiA(metrics[i].color_reg, keyNameA)==0)
559 metrics[i].color = color;
560 save_sys_color(i, color);
561 break;
564 HeapFree(GetProcessHeap(), 0, keyNameA);
567 static void do_parse_theme(WCHAR *file)
569 static const WCHAR colorSect[] = {
570 'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\',
571 'C','o','l','o','r','s',0};
572 WCHAR keyName[MAX_PATH], keyNameValue[MAX_PATH];
573 WCHAR *keyNamePtr = NULL;
574 char *keyNameValueA = NULL;
575 int keyNameValueSize = 0;
576 int red = 0, green = 0, blue = 0;
577 COLORREF color;
579 WINE_TRACE("%s\n", wine_dbgstr_w(file));
581 GetPrivateProfileStringW(colorSect, NULL, NULL, keyName,
582 MAX_PATH, file);
584 keyNamePtr = keyName;
585 while (*keyNamePtr!=0) {
586 GetPrivateProfileStringW(colorSect, keyNamePtr, NULL, keyNameValue,
587 MAX_PATH, file);
589 keyNameValueSize = WideCharToMultiByte(CP_ACP, 0, keyNameValue, -1,
590 keyNameValueA, 0, NULL, NULL);
591 keyNameValueA = HeapAlloc(GetProcessHeap(), 0, keyNameValueSize);
592 WideCharToMultiByte(CP_ACP, 0, keyNameValue, -1, keyNameValueA, keyNameValueSize, NULL, NULL);
594 WINE_TRACE("parsing key: %s with value: %s\n",
595 wine_dbgstr_w(keyNamePtr), wine_dbgstr_w(keyNameValue));
597 sscanf(keyNameValueA, "%d %d %d", &red, &green, &blue);
599 color = RGB((BYTE)red, (BYTE)green, (BYTE)blue);
601 HeapFree(GetProcessHeap(), 0, keyNameValueA);
603 set_color_from_theme(keyNamePtr, color);
605 keyNamePtr+=lstrlenW(keyNamePtr);
606 keyNamePtr++;
610 static void on_theme_install(HWND dialog)
612 static const WCHAR filterMask[] = {0,'*','.','m','s','s','t','y','l','e','s',';',
613 '*','.','t','h','e','m','e',0,0};
614 static const WCHAR themeExt[] = {'.','T','h','e','m','e',0};
615 const int filterMaskLen = ARRAY_SIZE(filterMask);
616 OPENFILENAMEW ofn;
617 WCHAR filetitle[MAX_PATH];
618 WCHAR file[MAX_PATH];
619 WCHAR filter[100];
620 WCHAR title[100];
622 LoadStringW(GetModuleHandleW(NULL), IDS_THEMEFILE, filter, ARRAY_SIZE(filter) - filterMaskLen);
623 memcpy(filter + lstrlenW (filter), filterMask, filterMaskLen * sizeof (WCHAR));
624 LoadStringW(GetModuleHandleW(NULL), IDS_THEMEFILE_SELECT, title, ARRAY_SIZE(title));
626 ofn.lStructSize = sizeof(OPENFILENAMEW);
627 ofn.hwndOwner = dialog;
628 ofn.hInstance = 0;
629 ofn.lpstrFilter = filter;
630 ofn.lpstrCustomFilter = NULL;
631 ofn.nMaxCustFilter = 0;
632 ofn.nFilterIndex = 0;
633 ofn.lpstrFile = file;
634 ofn.lpstrFile[0] = '\0';
635 ofn.nMaxFile = ARRAY_SIZE(file);
636 ofn.lpstrFileTitle = filetitle;
637 ofn.lpstrFileTitle[0] = '\0';
638 ofn.nMaxFileTitle = ARRAY_SIZE(filetitle);
639 ofn.lpstrInitialDir = NULL;
640 ofn.lpstrTitle = title;
641 ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_ENABLESIZING;
642 ofn.nFileOffset = 0;
643 ofn.nFileExtension = 0;
644 ofn.lpstrDefExt = NULL;
645 ofn.lCustData = 0;
646 ofn.lpfnHook = NULL;
647 ofn.lpTemplateName = NULL;
649 if (GetOpenFileNameW(&ofn))
651 static const WCHAR themesSubdir[] = { '\\','T','h','e','m','e','s',0 };
652 static const WCHAR backslash[] = { '\\',0 };
653 WCHAR themeFilePath[MAX_PATH];
654 SHFILEOPSTRUCTW shfop;
656 if (FAILED (SHGetFolderPathW (NULL, CSIDL_RESOURCES|CSIDL_FLAG_CREATE, NULL,
657 SHGFP_TYPE_CURRENT, themeFilePath))) return;
659 if (lstrcmpiW(PathFindExtensionW(filetitle), themeExt)==0)
661 do_parse_theme(file);
662 SendMessageW(GetParent(dialog), PSM_CHANGED, 0, 0);
663 return;
666 PathRemoveExtensionW (filetitle);
668 /* Construct path into which the theme file goes */
669 lstrcatW (themeFilePath, themesSubdir);
670 lstrcatW (themeFilePath, backslash);
671 lstrcatW (themeFilePath, filetitle);
673 /* Create the directory */
674 SHCreateDirectoryExW (dialog, themeFilePath, NULL);
676 /* Append theme file name itself */
677 lstrcatW (themeFilePath, backslash);
678 lstrcatW (themeFilePath, PathFindFileNameW (file));
679 /* SHFileOperation() takes lists as input, so double-nullterminate */
680 themeFilePath[lstrlenW (themeFilePath)+1] = 0;
681 file[lstrlenW (file)+1] = 0;
683 /* Do the copying */
684 WINE_TRACE("copying: %s -> %s\n", wine_dbgstr_w (file),
685 wine_dbgstr_w (themeFilePath));
686 shfop.hwnd = dialog;
687 shfop.wFunc = FO_COPY;
688 shfop.pFrom = file;
689 shfop.pTo = themeFilePath;
690 shfop.fFlags = FOF_NOCONFIRMMKDIR;
691 if (SHFileOperationW (&shfop) == 0)
693 scan_theme_files();
694 if (!fill_theme_list (GetDlgItem (dialog, IDC_THEME_THEMECOMBO),
695 GetDlgItem (dialog, IDC_THEME_COLORCOMBO),
696 GetDlgItem (dialog, IDC_THEME_SIZECOMBO)))
698 SendMessageW (GetDlgItem (dialog, IDC_THEME_COLORCOMBO), CB_SETCURSEL, -1, 0);
699 SendMessageW (GetDlgItem (dialog, IDC_THEME_SIZECOMBO), CB_SETCURSEL, -1, 0);
700 enable_size_and_color_controls (dialog, FALSE);
702 else
704 enable_size_and_color_controls (dialog, TRUE);
707 else
708 WINE_TRACE("copy operation failed\n");
710 else WINE_TRACE("user cancelled\n");
713 /* Information about symbolic link targets of certain User Shell Folders. */
714 struct ShellFolderInfo {
715 int nFolder;
716 char szLinkTarget[FILENAME_MAX]; /* in unix locale */
719 #define CSIDL_DOWNLOADS 0x0047
721 static struct ShellFolderInfo asfiInfo[] = {
722 { CSIDL_DESKTOP, "" },
723 { CSIDL_PERSONAL, "" },
724 { CSIDL_MYPICTURES, "" },
725 { CSIDL_MYMUSIC, "" },
726 { CSIDL_MYVIDEO, "" },
727 { CSIDL_DOWNLOADS, "" },
728 { CSIDL_TEMPLATES, "" }
731 static struct ShellFolderInfo *psfiSelected = NULL;
733 static void init_shell_folder_listview_headers(HWND dialog) {
734 LVCOLUMNW listColumn;
735 RECT viewRect;
736 WCHAR szShellFolder[64] = {'S','h','e','l','l',' ','F','o','l','d','e','r',0};
737 WCHAR szLinksTo[64] = {'L','i','n','k','s',' ','t','o',0};
738 int width;
740 LoadStringW(GetModuleHandleW(NULL), IDS_SHELL_FOLDER, szShellFolder, ARRAY_SIZE(szShellFolder));
741 LoadStringW(GetModuleHandleW(NULL), IDS_LINKS_TO, szLinksTo, ARRAY_SIZE(szLinksTo));
743 GetClientRect(GetDlgItem(dialog, IDC_LIST_SFPATHS), &viewRect);
744 width = (viewRect.right - viewRect.left) / 3;
746 listColumn.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
747 listColumn.pszText = szShellFolder;
748 listColumn.cchTextMax = strlenW(listColumn.pszText);
749 listColumn.cx = width;
751 SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_INSERTCOLUMNW, 0, (LPARAM) &listColumn);
753 listColumn.pszText = szLinksTo;
754 listColumn.cchTextMax = strlenW(listColumn.pszText);
755 listColumn.cx = viewRect.right - viewRect.left - width - 1;
757 SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_INSERTCOLUMNW, 1, (LPARAM) &listColumn);
760 /* Reads the currently set shell folder symbol link targets into asfiInfo. */
761 static void read_shell_folder_link_targets(void) {
762 WCHAR wszPath[MAX_PATH];
763 HRESULT hr;
764 int i;
766 for (i=0; i<ARRAY_SIZE(asfiInfo); i++) {
767 asfiInfo[i].szLinkTarget[0] = '\0';
768 hr = SHGetFolderPathW(NULL, asfiInfo[i].nFolder|CSIDL_FLAG_DONT_VERIFY, NULL,
769 SHGFP_TYPE_CURRENT, wszPath);
770 if (SUCCEEDED(hr)) {
771 char *pszUnixPath = wine_get_unix_file_name(wszPath);
772 if (pszUnixPath) {
773 struct stat statPath;
774 if (!lstat(pszUnixPath, &statPath) && S_ISLNK(statPath.st_mode)) {
775 int cLen = readlink(pszUnixPath, asfiInfo[i].szLinkTarget, FILENAME_MAX-1);
776 if (cLen >= 0) asfiInfo[i].szLinkTarget[cLen] = '\0';
778 HeapFree(GetProcessHeap(), 0, pszUnixPath);
784 static void update_shell_folder_listview(HWND dialog) {
785 int i;
786 LVITEMW item;
787 LONG lSelected = SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_GETNEXTITEM, -1,
788 MAKELPARAM(LVNI_SELECTED,0));
790 SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_DELETEALLITEMS, 0, 0);
792 for (i=0; i<ARRAY_SIZE(asfiInfo); i++) {
793 WCHAR buffer[MAX_PATH];
794 HRESULT hr;
795 LPITEMIDLIST pidlCurrent;
797 /* Some acrobatic to get the localized name of the shell folder */
798 hr = SHGetFolderLocation(dialog, asfiInfo[i].nFolder, NULL, 0, &pidlCurrent);
799 if (SUCCEEDED(hr)) {
800 LPSHELLFOLDER psfParent;
801 LPCITEMIDLIST pidlLast;
802 hr = SHBindToParent(pidlCurrent, &IID_IShellFolder, (LPVOID*)&psfParent, &pidlLast);
803 if (SUCCEEDED(hr)) {
804 STRRET strRet;
805 hr = IShellFolder_GetDisplayNameOf(psfParent, pidlLast, SHGDN_FORADDRESSBAR, &strRet);
806 if (SUCCEEDED(hr)) {
807 hr = StrRetToBufW(&strRet, pidlLast, buffer, MAX_PATH);
809 IShellFolder_Release(psfParent);
811 ILFree(pidlCurrent);
814 /* If there's a dangling symlink for the current shell folder, SHGetFolderLocation
815 * will fail above. We fall back to the (non-verified) path of the shell folder. */
816 if (FAILED(hr)) {
817 hr = SHGetFolderPathW(dialog, asfiInfo[i].nFolder|CSIDL_FLAG_DONT_VERIFY, NULL,
818 SHGFP_TYPE_CURRENT, buffer);
821 item.mask = LVIF_TEXT | LVIF_PARAM;
822 item.iItem = i;
823 item.iSubItem = 0;
824 item.pszText = buffer;
825 item.lParam = (LPARAM)&asfiInfo[i];
826 SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_INSERTITEMW, 0, (LPARAM)&item);
828 item.mask = LVIF_TEXT;
829 item.iItem = i;
830 item.iSubItem = 1;
831 item.pszText = strdupU2W(asfiInfo[i].szLinkTarget);
832 SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_SETITEMW, 0, (LPARAM)&item);
833 HeapFree(GetProcessHeap(), 0, item.pszText);
836 /* Ensure that the previously selected item is selected again. */
837 if (lSelected >= 0) {
838 item.mask = LVIF_STATE;
839 item.state = LVIS_SELECTED;
840 item.stateMask = LVIS_SELECTED;
841 SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_SETITEMSTATE, lSelected, (LPARAM)&item);
845 static void on_shell_folder_selection_changed(HWND hDlg, LPNMLISTVIEW lpnm) {
846 if (lpnm->uNewState & LVIS_SELECTED) {
847 psfiSelected = (struct ShellFolderInfo *)lpnm->lParam;
848 EnableWindow(GetDlgItem(hDlg, IDC_LINK_SFPATH), 1);
849 if (*psfiSelected->szLinkTarget) {
850 WCHAR *link;
851 CheckDlgButton(hDlg, IDC_LINK_SFPATH, BST_CHECKED);
852 EnableWindow(GetDlgItem(hDlg, IDC_EDIT_SFPATH), 1);
853 EnableWindow(GetDlgItem(hDlg, IDC_BROWSE_SFPATH), 1);
854 link = strdupU2W(psfiSelected->szLinkTarget);
855 set_textW(hDlg, IDC_EDIT_SFPATH, link);
856 HeapFree(GetProcessHeap(), 0, link);
857 } else {
858 CheckDlgButton(hDlg, IDC_LINK_SFPATH, BST_UNCHECKED);
859 EnableWindow(GetDlgItem(hDlg, IDC_EDIT_SFPATH), 0);
860 EnableWindow(GetDlgItem(hDlg, IDC_BROWSE_SFPATH), 0);
861 set_text(hDlg, IDC_EDIT_SFPATH, "");
863 } else {
864 psfiSelected = NULL;
865 CheckDlgButton(hDlg, IDC_LINK_SFPATH, BST_UNCHECKED);
866 set_text(hDlg, IDC_EDIT_SFPATH, "");
867 EnableWindow(GetDlgItem(hDlg, IDC_LINK_SFPATH), 0);
868 EnableWindow(GetDlgItem(hDlg, IDC_EDIT_SFPATH), 0);
869 EnableWindow(GetDlgItem(hDlg, IDC_BROWSE_SFPATH), 0);
873 /* Keep the contents of the edit control, the listview control and the symlink
874 * information in sync. */
875 static void on_shell_folder_edit_changed(HWND hDlg) {
876 LVITEMW item;
877 WCHAR *text = get_textW(hDlg, IDC_EDIT_SFPATH);
878 LONG iSel = SendDlgItemMessageW(hDlg, IDC_LIST_SFPATHS, LVM_GETNEXTITEM, -1,
879 MAKELPARAM(LVNI_SELECTED,0));
881 if (!text || !psfiSelected || iSel < 0) {
882 HeapFree(GetProcessHeap(), 0, text);
883 return;
886 WideCharToMultiByte(CP_UNIXCP, 0, text, -1,
887 psfiSelected->szLinkTarget, FILENAME_MAX, NULL, NULL);
889 item.mask = LVIF_TEXT;
890 item.iItem = iSel;
891 item.iSubItem = 1;
892 item.pszText = text;
893 SendDlgItemMessageW(hDlg, IDC_LIST_SFPATHS, LVM_SETITEMW, 0, (LPARAM)&item);
895 HeapFree(GetProcessHeap(), 0, text);
897 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
900 static void apply_shell_folder_changes(void) {
901 WCHAR wszPath[MAX_PATH];
902 char szBackupPath[FILENAME_MAX], szUnixPath[FILENAME_MAX], *pszUnixPath = NULL;
903 int i;
904 struct stat statPath;
905 HRESULT hr;
907 for (i=0; i<ARRAY_SIZE(asfiInfo); i++) {
908 /* Ignore nonexistent link targets */
909 if (asfiInfo[i].szLinkTarget[0] && stat(asfiInfo[i].szLinkTarget, &statPath))
910 continue;
912 hr = SHGetFolderPathW(NULL, asfiInfo[i].nFolder|CSIDL_FLAG_CREATE, NULL,
913 SHGFP_TYPE_CURRENT, wszPath);
914 if (FAILED(hr)) continue;
916 /* Retrieve the corresponding unix path. */
917 pszUnixPath = wine_get_unix_file_name(wszPath);
918 if (!pszUnixPath) continue;
919 lstrcpyA(szUnixPath, pszUnixPath);
920 HeapFree(GetProcessHeap(), 0, pszUnixPath);
922 /* Derive name for folder backup. */
923 lstrcpyA(szBackupPath, szUnixPath);
924 lstrcatA(szBackupPath, ".winecfg");
926 if (lstat(szUnixPath, &statPath)) continue;
928 /* Move old folder/link out of the way. */
929 if (S_ISLNK(statPath.st_mode)) {
930 if (unlink(szUnixPath)) continue; /* Unable to remove link. */
931 } else {
932 if (!*asfiInfo[i].szLinkTarget) {
933 continue; /* We are done. Old was real folder, as new shall be. */
934 } else {
935 if (rename(szUnixPath, szBackupPath)) { /* Move folder out of the way. */
936 continue; /* Unable to move old folder. */
941 /* Create new link/folder. */
942 if (*asfiInfo[i].szLinkTarget) {
943 symlink(asfiInfo[i].szLinkTarget, szUnixPath);
944 } else {
945 /* If there's a backup folder, restore it. Else create new folder. */
946 if (!lstat(szBackupPath, &statPath) && S_ISDIR(statPath.st_mode)) {
947 rename(szBackupPath, szUnixPath);
948 } else {
949 mkdir(szUnixPath, 0777);
955 static void refresh_sysparams(HWND hDlg)
957 int i;
959 for (i = 0; i < ARRAY_SIZE(metrics); i++)
961 if (metrics[i].sm_idx != -1)
962 metrics[i].size = GetSystemMetrics(metrics[i].sm_idx);
963 if (metrics[i].color_idx != -1)
964 metrics[i].color = GetSysColor(metrics[i].color_idx);
967 on_sysparam_change(hDlg);
970 static void read_sysparams(HWND hDlg)
972 WCHAR buffer[256];
973 HWND list = GetDlgItem(hDlg, IDC_SYSPARAM_COMBO);
974 NONCLIENTMETRICSW nonclient_metrics;
975 int i, idx;
977 for (i = 0; i < ARRAY_SIZE(metrics); i++)
979 LoadStringW(GetModuleHandleW(NULL), i + IDC_SYSPARAMS_BUTTON, buffer, ARRAY_SIZE(buffer));
980 idx = SendMessageW(list, CB_ADDSTRING, 0, (LPARAM)buffer);
981 if (idx != CB_ERR) SendMessageW(list, CB_SETITEMDATA, idx, i);
983 if (metrics[i].sm_idx != -1)
984 metrics[i].size = GetSystemMetrics(metrics[i].sm_idx);
985 if (metrics[i].color_idx != -1)
986 metrics[i].color = GetSysColor(metrics[i].color_idx);
989 nonclient_metrics.cbSize = sizeof(NONCLIENTMETRICSW);
990 SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSW), &nonclient_metrics, 0);
992 memcpy(&(metrics[IDC_SYSPARAMS_MENU_TEXT - IDC_SYSPARAMS_BUTTON].lf),
993 &(nonclient_metrics.lfMenuFont), sizeof(LOGFONTW));
994 memcpy(&(metrics[IDC_SYSPARAMS_ACTIVE_TITLE_TEXT - IDC_SYSPARAMS_BUTTON].lf),
995 &(nonclient_metrics.lfCaptionFont), sizeof(LOGFONTW));
996 memcpy(&(metrics[IDC_SYSPARAMS_TOOLTIP_TEXT - IDC_SYSPARAMS_BUTTON].lf),
997 &(nonclient_metrics.lfStatusFont), sizeof(LOGFONTW));
998 memcpy(&(metrics[IDC_SYSPARAMS_MSGBOX_TEXT - IDC_SYSPARAMS_BUTTON].lf),
999 &(nonclient_metrics.lfMessageFont), sizeof(LOGFONTW));
1002 static void apply_sysparams(void)
1004 NONCLIENTMETRICSW ncm;
1005 int i, cnt = 0;
1006 int colors_idx[ARRAY_SIZE(metrics)];
1007 COLORREF colors[ARRAY_SIZE(metrics)];
1008 HDC hdc;
1009 int dpi;
1011 hdc = GetDC( 0 );
1012 dpi = GetDeviceCaps( hdc, LOGPIXELSY );
1013 ReleaseDC( 0, hdc );
1015 ncm.cbSize = sizeof(ncm);
1016 SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0);
1018 /* convert metrics back to twips */
1019 ncm.iMenuWidth = ncm.iMenuHeight =
1020 MulDiv( metrics[IDC_SYSPARAMS_MENU - IDC_SYSPARAMS_BUTTON].size, -1440, dpi );
1021 ncm.iCaptionWidth = ncm.iCaptionHeight =
1022 MulDiv( metrics[IDC_SYSPARAMS_ACTIVE_TITLE - IDC_SYSPARAMS_BUTTON].size, -1440, dpi );
1023 ncm.iScrollWidth = ncm.iScrollHeight =
1024 MulDiv( metrics[IDC_SYSPARAMS_SCROLLBAR - IDC_SYSPARAMS_BUTTON].size, -1440, dpi );
1025 ncm.iSmCaptionWidth = MulDiv( ncm.iSmCaptionWidth, -1440, dpi );
1026 ncm.iSmCaptionHeight = MulDiv( ncm.iSmCaptionHeight, -1440, dpi );
1028 ncm.lfMenuFont = metrics[IDC_SYSPARAMS_MENU_TEXT - IDC_SYSPARAMS_BUTTON].lf;
1029 ncm.lfCaptionFont = metrics[IDC_SYSPARAMS_ACTIVE_TITLE_TEXT - IDC_SYSPARAMS_BUTTON].lf;
1030 ncm.lfStatusFont = metrics[IDC_SYSPARAMS_TOOLTIP_TEXT - IDC_SYSPARAMS_BUTTON].lf;
1031 ncm.lfMessageFont = metrics[IDC_SYSPARAMS_MSGBOX_TEXT - IDC_SYSPARAMS_BUTTON].lf;
1033 ncm.lfMenuFont.lfHeight = MulDiv( ncm.lfMenuFont.lfHeight, -72, dpi );
1034 ncm.lfCaptionFont.lfHeight = MulDiv( ncm.lfCaptionFont.lfHeight, -72, dpi );
1035 ncm.lfStatusFont.lfHeight = MulDiv( ncm.lfStatusFont.lfHeight, -72, dpi );
1036 ncm.lfMessageFont.lfHeight = MulDiv( ncm.lfMessageFont.lfHeight, -72, dpi );
1037 ncm.lfSmCaptionFont.lfHeight = MulDiv( ncm.lfSmCaptionFont.lfHeight, -72, dpi );
1039 SystemParametersInfoW(SPI_SETNONCLIENTMETRICS, sizeof(ncm), &ncm,
1040 SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
1042 for (i = 0; i < ARRAY_SIZE(metrics); i++)
1043 if (metrics[i].color_idx != -1)
1045 colors_idx[cnt] = metrics[i].color_idx;
1046 colors[cnt++] = metrics[i].color;
1048 SetSysColors(cnt, colors_idx, colors);
1051 static void on_sysparam_change(HWND hDlg)
1053 int index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETCURSEL, 0, 0);
1055 index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETITEMDATA, index, 0);
1057 updating_ui = TRUE;
1059 EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_COLOR_TEXT), metrics[index].color_idx != -1);
1060 EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_COLOR), metrics[index].color_idx != -1);
1061 InvalidateRect(GetDlgItem(hDlg, IDC_SYSPARAM_COLOR), NULL, TRUE);
1063 EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_SIZE_TEXT), metrics[index].sm_idx != -1);
1064 EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_SIZE), metrics[index].sm_idx != -1);
1065 EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_SIZE_UD), metrics[index].sm_idx != -1);
1066 if (metrics[index].sm_idx != -1)
1067 SendDlgItemMessageW(hDlg, IDC_SYSPARAM_SIZE_UD, UDM_SETPOS, 0, MAKELONG(metrics[index].size, 0));
1068 else
1069 set_text(hDlg, IDC_SYSPARAM_SIZE, "");
1071 EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_FONT),
1072 index == IDC_SYSPARAMS_MENU_TEXT-IDC_SYSPARAMS_BUTTON ||
1073 index == IDC_SYSPARAMS_ACTIVE_TITLE_TEXT-IDC_SYSPARAMS_BUTTON ||
1074 index == IDC_SYSPARAMS_TOOLTIP_TEXT-IDC_SYSPARAMS_BUTTON ||
1075 index == IDC_SYSPARAMS_MSGBOX_TEXT-IDC_SYSPARAMS_BUTTON
1078 updating_ui = FALSE;
1081 static void on_draw_item(HWND hDlg, WPARAM wParam, LPARAM lParam)
1083 static HBRUSH black_brush = 0;
1084 LPDRAWITEMSTRUCT draw_info = (LPDRAWITEMSTRUCT)lParam;
1086 if (!black_brush) black_brush = CreateSolidBrush(0);
1088 if (draw_info->CtlID == IDC_SYSPARAM_COLOR)
1090 UINT state;
1091 HTHEME theme;
1092 RECT buttonrect;
1094 theme = OpenThemeData(NULL, WC_BUTTONW);
1096 if (theme) {
1097 MARGINS margins;
1099 if (draw_info->itemState & ODS_DISABLED)
1100 state = PBS_DISABLED;
1101 else if (draw_info->itemState & ODS_SELECTED)
1102 state = PBS_PRESSED;
1103 else
1104 state = PBS_NORMAL;
1106 if (IsThemeBackgroundPartiallyTransparent(theme, BP_PUSHBUTTON, state))
1107 DrawThemeParentBackground(draw_info->hwndItem, draw_info->hDC, NULL);
1109 DrawThemeBackground(theme, draw_info->hDC, BP_PUSHBUTTON, state, &draw_info->rcItem, NULL);
1111 buttonrect = draw_info->rcItem;
1113 GetThemeMargins(theme, draw_info->hDC, BP_PUSHBUTTON, state, TMT_CONTENTMARGINS, &draw_info->rcItem, &margins);
1115 buttonrect.left += margins.cxLeftWidth;
1116 buttonrect.top += margins.cyTopHeight;
1117 buttonrect.right -= margins.cxRightWidth;
1118 buttonrect.bottom -= margins.cyBottomHeight;
1120 if (draw_info->itemState & ODS_FOCUS)
1121 DrawFocusRect(draw_info->hDC, &buttonrect);
1123 CloseThemeData(theme);
1124 } else {
1125 state = DFCS_ADJUSTRECT | DFCS_BUTTONPUSH;
1127 if (draw_info->itemState & ODS_DISABLED)
1128 state |= DFCS_INACTIVE;
1129 else
1130 state |= draw_info->itemState & ODS_SELECTED ? DFCS_PUSHED : 0;
1132 DrawFrameControl(draw_info->hDC, &draw_info->rcItem, DFC_BUTTON, state);
1134 buttonrect = draw_info->rcItem;
1137 if (!(draw_info->itemState & ODS_DISABLED))
1139 HBRUSH brush;
1140 int index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETCURSEL, 0, 0);
1142 index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETITEMDATA, index, 0);
1143 brush = CreateSolidBrush(metrics[index].color);
1145 InflateRect(&buttonrect, -1, -1);
1146 FrameRect(draw_info->hDC, &buttonrect, black_brush);
1147 InflateRect(&buttonrect, -1, -1);
1148 FillRect(draw_info->hDC, &buttonrect, brush);
1149 DeleteObject(brush);
1154 static void on_select_font(HWND hDlg)
1156 CHOOSEFONTW cf;
1157 int index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETCURSEL, 0, 0);
1158 index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETITEMDATA, index, 0);
1160 ZeroMemory(&cf, sizeof(cf));
1161 cf.lStructSize = sizeof(CHOOSEFONTW);
1162 cf.hwndOwner = hDlg;
1163 cf.lpLogFont = &(metrics[index].lf);
1164 cf.Flags = CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT | CF_NOSCRIPTSEL | CF_NOVERTFONTS;
1166 if (ChooseFontW(&cf))
1167 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1170 static void init_mime_types(HWND hDlg)
1172 char *buf = get_reg_key(config_key, keypath("FileOpenAssociations"), "Enable", "Y");
1173 int state = IS_OPTION_TRUE(*buf) ? BST_CHECKED : BST_UNCHECKED;
1175 CheckDlgButton(hDlg, IDC_ENABLE_FILE_ASSOCIATIONS, state);
1177 HeapFree(GetProcessHeap(), 0, buf);
1180 static void update_mime_types(HWND hDlg)
1182 const char *state = "Y";
1184 if (IsDlgButtonChecked(hDlg, IDC_ENABLE_FILE_ASSOCIATIONS) != BST_CHECKED)
1185 state = "N";
1187 set_reg_key(config_key, keypath("FileOpenAssociations"), "Enable", state);
1190 INT_PTR CALLBACK
1191 ThemeDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1193 switch (uMsg) {
1194 case WM_INITDIALOG:
1195 read_shell_folder_link_targets();
1196 init_shell_folder_listview_headers(hDlg);
1197 update_shell_folder_listview(hDlg);
1198 read_sysparams(hDlg);
1199 init_mime_types(hDlg);
1200 break;
1202 case WM_DESTROY:
1203 free_theme_files();
1204 break;
1206 case WM_SHOWWINDOW:
1207 set_window_title(hDlg);
1208 break;
1210 case WM_COMMAND:
1211 switch(HIWORD(wParam)) {
1212 case CBN_SELCHANGE: {
1213 if (updating_ui) break;
1214 switch (LOWORD(wParam))
1216 case IDC_THEME_THEMECOMBO: on_theme_changed(hDlg); break;
1217 case IDC_THEME_COLORCOMBO: /* fall through */
1218 case IDC_THEME_SIZECOMBO: theme_dirty = TRUE; break;
1219 case IDC_SYSPARAM_COMBO: on_sysparam_change(hDlg); return FALSE;
1221 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1222 break;
1224 case EN_CHANGE: {
1225 if (updating_ui) break;
1226 switch (LOWORD(wParam))
1228 case IDC_EDIT_SFPATH: on_shell_folder_edit_changed(hDlg); break;
1229 case IDC_SYSPARAM_SIZE:
1231 char *text = get_text(hDlg, IDC_SYSPARAM_SIZE);
1232 int index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETCURSEL, 0, 0);
1234 index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETITEMDATA, index, 0);
1236 if (text)
1238 metrics[index].size = atoi(text);
1239 HeapFree(GetProcessHeap(), 0, text);
1241 else
1243 /* for empty string set to minimum value */
1244 SendDlgItemMessageW(hDlg, IDC_SYSPARAM_SIZE_UD, UDM_GETRANGE32, (WPARAM)&metrics[index].size, 0);
1247 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1248 break;
1251 break;
1253 case BN_CLICKED:
1254 switch (LOWORD(wParam))
1256 case IDC_THEME_INSTALL:
1257 on_theme_install (hDlg);
1258 break;
1260 case IDC_SYSPARAM_FONT:
1261 on_select_font(hDlg);
1262 break;
1264 case IDC_BROWSE_SFPATH:
1266 WCHAR link[FILENAME_MAX];
1267 if (browse_for_unix_folder(hDlg, link)) {
1268 WideCharToMultiByte(CP_UNIXCP, 0, link, -1,
1269 psfiSelected->szLinkTarget, FILENAME_MAX,
1270 NULL, NULL);
1271 update_shell_folder_listview(hDlg);
1272 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1274 break;
1277 case IDC_LINK_SFPATH:
1278 if (IsDlgButtonChecked(hDlg, IDC_LINK_SFPATH)) {
1279 WCHAR link[FILENAME_MAX];
1280 if (browse_for_unix_folder(hDlg, link)) {
1281 WideCharToMultiByte(CP_UNIXCP, 0, link, -1,
1282 psfiSelected->szLinkTarget, FILENAME_MAX,
1283 NULL, NULL);
1284 update_shell_folder_listview(hDlg);
1285 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1286 } else {
1287 CheckDlgButton(hDlg, IDC_LINK_SFPATH, BST_UNCHECKED);
1289 } else {
1290 psfiSelected->szLinkTarget[0] = '\0';
1291 update_shell_folder_listview(hDlg);
1292 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1294 break;
1296 case IDC_SYSPARAM_COLOR:
1298 static COLORREF user_colors[16];
1299 CHOOSECOLORW c_color;
1300 int index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETCURSEL, 0, 0);
1302 index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETITEMDATA, index, 0);
1304 memset(&c_color, 0, sizeof(c_color));
1305 c_color.lStructSize = sizeof(c_color);
1306 c_color.lpCustColors = user_colors;
1307 c_color.rgbResult = metrics[index].color;
1308 c_color.Flags = CC_ANYCOLOR | CC_RGBINIT;
1309 c_color.hwndOwner = hDlg;
1310 if (ChooseColorW(&c_color))
1312 metrics[index].color = c_color.rgbResult;
1313 save_sys_color(index, metrics[index].color);
1314 InvalidateRect(GetDlgItem(hDlg, IDC_SYSPARAM_COLOR), NULL, TRUE);
1315 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1317 break;
1320 case IDC_ENABLE_FILE_ASSOCIATIONS:
1321 update_mime_types(hDlg);
1322 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
1323 break;
1325 break;
1327 break;
1329 case WM_NOTIFY:
1330 switch (((LPNMHDR)lParam)->code) {
1331 case PSN_KILLACTIVE: {
1332 SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, FALSE);
1333 break;
1335 case PSN_APPLY: {
1336 apply();
1337 apply_theme(hDlg);
1338 apply_shell_folder_changes();
1339 apply_sysparams();
1340 read_shell_folder_link_targets();
1341 update_shell_folder_listview(hDlg);
1342 update_mime_types(hDlg);
1343 SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
1344 break;
1346 case LVN_ITEMCHANGED: {
1347 if (wParam == IDC_LIST_SFPATHS)
1348 on_shell_folder_selection_changed(hDlg, (LPNMLISTVIEW)lParam);
1349 break;
1351 case PSN_SETACTIVE: {
1352 init_dialog (hDlg);
1353 break;
1356 break;
1358 case WM_DRAWITEM:
1359 on_draw_item(hDlg, wParam, lParam);
1360 break;
1362 default:
1363 break;
1365 return FALSE;