theme.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275
  1. /*
  2. * Desktop Integration
  3. * - Theme configuration code
  4. * - User Shell Folder mapping
  5. *
  6. * Copyright (c) 2005 by Frank Richter
  7. * Copyright (c) 2006 by Michael Jung
  8. *
  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.
  13. *
  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.
  18. *
  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
  22. *
  23. */
  24. #include <stdarg.h>
  25. #include <stdlib.h>
  26. #include <stdio.h>
  27. #define COBJMACROS
  28. #include <windows.h>
  29. #include <commdlg.h>
  30. #include <shellapi.h>
  31. #include <uxtheme.h>
  32. #include <tmschema.h>
  33. #include <shlobj.h>
  34. #include <shlwapi.h>
  35. #include <wine/debug.h>
  36. #include "resource.h"
  37. #include "winecfg.h"
  38. WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
  39. /* UXTHEME functions not in the headers */
  40. typedef struct tagTHEMENAMES
  41. {
  42. WCHAR szName[MAX_PATH+1];
  43. WCHAR szDisplayName[MAX_PATH+1];
  44. WCHAR szTooltip[MAX_PATH+1];
  45. } THEMENAMES, *PTHEMENAMES;
  46. typedef void* HTHEMEFILE;
  47. typedef BOOL (CALLBACK *EnumThemeProc)(LPVOID lpReserved,
  48. LPCWSTR pszThemeFileName,
  49. LPCWSTR pszThemeName,
  50. LPCWSTR pszToolTip, LPVOID lpReserved2,
  51. LPVOID lpData);
  52. HRESULT WINAPI EnumThemeColors (LPCWSTR pszThemeFileName, LPWSTR pszSizeName,
  53. DWORD dwColorNum, PTHEMENAMES pszColorNames);
  54. HRESULT WINAPI EnumThemeSizes (LPCWSTR pszThemeFileName, LPWSTR pszColorName,
  55. DWORD dwSizeNum, PTHEMENAMES pszSizeNames);
  56. HRESULT WINAPI ApplyTheme (HTHEMEFILE hThemeFile, char* unknown, HWND hWnd);
  57. HRESULT WINAPI OpenThemeFile (LPCWSTR pszThemeFileName, LPCWSTR pszColorName,
  58. LPCWSTR pszSizeName, HTHEMEFILE* hThemeFile,
  59. DWORD unknown);
  60. HRESULT WINAPI CloseThemeFile (HTHEMEFILE hThemeFile);
  61. HRESULT WINAPI EnumThemes (LPCWSTR pszThemePath, EnumThemeProc callback,
  62. LPVOID lpData);
  63. static void refresh_sysparams(HWND hDlg);
  64. static void on_sysparam_change(HWND hDlg);
  65. /* A struct to keep both the internal and "fancy" name of a color or size */
  66. typedef struct
  67. {
  68. WCHAR* name;
  69. WCHAR* fancyName;
  70. } ThemeColorOrSize;
  71. /* wrapper around DSA that also keeps an item count */
  72. typedef struct
  73. {
  74. HDSA dsa;
  75. int count;
  76. } WrappedDsa;
  77. /* Some helper functions to deal with ThemeColorOrSize structs in WrappedDSAs */
  78. static void color_or_size_dsa_add (WrappedDsa* wdsa, const WCHAR* name,
  79. const WCHAR* fancyName)
  80. {
  81. ThemeColorOrSize item;
  82. item.name = HeapAlloc (GetProcessHeap(), 0,
  83. (lstrlenW (name) + 1) * sizeof(WCHAR));
  84. lstrcpyW (item.name, name);
  85. item.fancyName = HeapAlloc (GetProcessHeap(), 0,
  86. (lstrlenW (fancyName) + 1) * sizeof(WCHAR));
  87. lstrcpyW (item.fancyName, fancyName);
  88. DSA_InsertItem (wdsa->dsa, wdsa->count, &item);
  89. wdsa->count++;
  90. }
  91. static int CALLBACK dsa_destroy_callback (LPVOID p, LPVOID pData)
  92. {
  93. ThemeColorOrSize* item = p;
  94. HeapFree (GetProcessHeap(), 0, item->name);
  95. HeapFree (GetProcessHeap(), 0, item->fancyName);
  96. return 1;
  97. }
  98. static void free_color_or_size_dsa (WrappedDsa* wdsa)
  99. {
  100. DSA_DestroyCallback (wdsa->dsa, dsa_destroy_callback, NULL);
  101. }
  102. static void create_color_or_size_dsa (WrappedDsa* wdsa)
  103. {
  104. wdsa->dsa = DSA_Create (sizeof (ThemeColorOrSize), 1);
  105. wdsa->count = 0;
  106. }
  107. static ThemeColorOrSize* color_or_size_dsa_get (WrappedDsa* wdsa, int index)
  108. {
  109. return DSA_GetItemPtr (wdsa->dsa, index);
  110. }
  111. static int color_or_size_dsa_find (WrappedDsa* wdsa, const WCHAR* name)
  112. {
  113. int i = 0;
  114. for (; i < wdsa->count; i++)
  115. {
  116. ThemeColorOrSize* item = color_or_size_dsa_get (wdsa, i);
  117. if (lstrcmpiW (item->name, name) == 0) break;
  118. }
  119. return i;
  120. }
  121. /* A theme file, contains file name, display name, color and size scheme names */
  122. typedef struct
  123. {
  124. WCHAR* themeFileName;
  125. WCHAR* fancyName;
  126. WrappedDsa colors;
  127. WrappedDsa sizes;
  128. } ThemeFile;
  129. static HDSA themeFiles = NULL;
  130. static int themeFilesCount = 0;
  131. static int CALLBACK theme_dsa_destroy_callback (LPVOID p, LPVOID pData)
  132. {
  133. ThemeFile* item = p;
  134. HeapFree (GetProcessHeap(), 0, item->themeFileName);
  135. HeapFree (GetProcessHeap(), 0, item->fancyName);
  136. free_color_or_size_dsa (&item->colors);
  137. free_color_or_size_dsa (&item->sizes);
  138. return 1;
  139. }
  140. /* Free memory occupied by the theme list */
  141. static void free_theme_files(void)
  142. {
  143. if (themeFiles == NULL) return;
  144. DSA_DestroyCallback (themeFiles , theme_dsa_destroy_callback, NULL);
  145. themeFiles = NULL;
  146. themeFilesCount = 0;
  147. }
  148. typedef HRESULT (WINAPI * EnumTheme) (LPCWSTR, LPWSTR, DWORD, PTHEMENAMES);
  149. /* fill a string list with either colors or sizes of a theme */
  150. static void fill_theme_string_array (const WCHAR* filename,
  151. WrappedDsa* wdsa,
  152. EnumTheme enumTheme)
  153. {
  154. DWORD index = 0;
  155. THEMENAMES names;
  156. WINE_TRACE ("%s %p %p\n", wine_dbgstr_w (filename), wdsa, enumTheme);
  157. while (SUCCEEDED (enumTheme (filename, NULL, index++, &names)))
  158. {
  159. WINE_TRACE ("%s: %s\n", wine_dbgstr_w (names.szName),
  160. wine_dbgstr_w (names.szDisplayName));
  161. color_or_size_dsa_add (wdsa, names.szName, names.szDisplayName);
  162. }
  163. }
  164. /* Theme enumeration callback, adds theme to theme list */
  165. static BOOL CALLBACK myEnumThemeProc (LPVOID lpReserved,
  166. LPCWSTR pszThemeFileName,
  167. LPCWSTR pszThemeName,
  168. LPCWSTR pszToolTip,
  169. LPVOID lpReserved2, LPVOID lpData)
  170. {
  171. ThemeFile newEntry;
  172. /* fill size/color lists */
  173. create_color_or_size_dsa (&newEntry.colors);
  174. fill_theme_string_array (pszThemeFileName, &newEntry.colors, EnumThemeColors);
  175. create_color_or_size_dsa (&newEntry.sizes);
  176. fill_theme_string_array (pszThemeFileName, &newEntry.sizes, EnumThemeSizes);
  177. newEntry.themeFileName = HeapAlloc (GetProcessHeap(), 0,
  178. (lstrlenW (pszThemeFileName) + 1) * sizeof(WCHAR));
  179. lstrcpyW (newEntry.themeFileName, pszThemeFileName);
  180. newEntry.fancyName = HeapAlloc (GetProcessHeap(), 0,
  181. (lstrlenW (pszThemeName) + 1) * sizeof(WCHAR));
  182. lstrcpyW (newEntry.fancyName, pszThemeName);
  183. /*list_add_tail (&themeFiles, &newEntry->entry);*/
  184. DSA_InsertItem (themeFiles, themeFilesCount, &newEntry);
  185. themeFilesCount++;
  186. return TRUE;
  187. }
  188. /* Scan for themes */
  189. static void scan_theme_files(void)
  190. {
  191. WCHAR themesPath[MAX_PATH];
  192. free_theme_files();
  193. if (FAILED (SHGetFolderPathW (NULL, CSIDL_RESOURCES, NULL,
  194. SHGFP_TYPE_CURRENT, themesPath))) return;
  195. themeFiles = DSA_Create (sizeof (ThemeFile), 1);
  196. lstrcatW (themesPath, L"\\Themes");
  197. EnumThemes (themesPath, myEnumThemeProc, 0);
  198. }
  199. /* fill the color & size combo boxes for a given theme */
  200. static void fill_color_size_combos (ThemeFile* theme, HWND comboColor,
  201. HWND comboSize)
  202. {
  203. int i;
  204. SendMessageW (comboColor, CB_RESETCONTENT, 0, 0);
  205. for (i = 0; i < theme->colors.count; i++)
  206. {
  207. ThemeColorOrSize* item = color_or_size_dsa_get (&theme->colors, i);
  208. SendMessageW (comboColor, CB_ADDSTRING, 0, (LPARAM)item->fancyName);
  209. }
  210. SendMessageW (comboSize, CB_RESETCONTENT, 0, 0);
  211. for (i = 0; i < theme->sizes.count; i++)
  212. {
  213. ThemeColorOrSize* item = color_or_size_dsa_get (&theme->sizes, i);
  214. SendMessageW (comboSize, CB_ADDSTRING, 0, (LPARAM)item->fancyName);
  215. }
  216. }
  217. /* Select the item of a combo box that matches a theme's color and size
  218. * scheme. */
  219. static void select_color_and_size (ThemeFile* theme,
  220. const WCHAR* colorName, HWND comboColor,
  221. const WCHAR* sizeName, HWND comboSize)
  222. {
  223. SendMessageW (comboColor, CB_SETCURSEL,
  224. color_or_size_dsa_find (&theme->colors, colorName), 0);
  225. SendMessageW (comboSize, CB_SETCURSEL,
  226. color_or_size_dsa_find (&theme->sizes, sizeName), 0);
  227. }
  228. /* Fill theme, color and sizes combo boxes with the know themes and select
  229. * the entries matching the currently active theme. */
  230. static BOOL fill_theme_list (HWND comboTheme, HWND comboColor, HWND comboSize)
  231. {
  232. WCHAR textNoTheme[256];
  233. int themeIndex = 0;
  234. BOOL ret = TRUE;
  235. int i;
  236. WCHAR currentTheme[MAX_PATH];
  237. WCHAR currentColor[MAX_PATH];
  238. WCHAR currentSize[MAX_PATH];
  239. ThemeFile* theme = NULL;
  240. LoadStringW(GetModuleHandleW(NULL), IDS_NOTHEME, textNoTheme, ARRAY_SIZE(textNoTheme));
  241. SendMessageW (comboTheme, CB_RESETCONTENT, 0, 0);
  242. SendMessageW (comboTheme, CB_ADDSTRING, 0, (LPARAM)textNoTheme);
  243. for (i = 0; i < themeFilesCount; i++)
  244. {
  245. ThemeFile* item = DSA_GetItemPtr (themeFiles, i);
  246. SendMessageW (comboTheme, CB_ADDSTRING, 0,
  247. (LPARAM)item->fancyName);
  248. }
  249. if (IsThemeActive() && SUCCEEDED(GetCurrentThemeName(currentTheme, ARRAY_SIZE(currentTheme),
  250. currentColor, ARRAY_SIZE(currentColor), currentSize, ARRAY_SIZE(currentSize))))
  251. {
  252. /* Determine the index of the currently active theme. */
  253. BOOL found = FALSE;
  254. for (i = 0; i < themeFilesCount; i++)
  255. {
  256. theme = DSA_GetItemPtr (themeFiles, i);
  257. if (lstrcmpiW (theme->themeFileName, currentTheme) == 0)
  258. {
  259. found = TRUE;
  260. themeIndex = i+1;
  261. break;
  262. }
  263. }
  264. if (!found)
  265. {
  266. /* Current theme not found?... add to the list, then... */
  267. WINE_TRACE("Theme %s not in list of enumerated themes\n",
  268. wine_dbgstr_w (currentTheme));
  269. myEnumThemeProc (NULL, currentTheme, currentTheme,
  270. currentTheme, NULL, NULL);
  271. themeIndex = themeFilesCount;
  272. theme = DSA_GetItemPtr (themeFiles, themeFilesCount-1);
  273. }
  274. fill_color_size_combos (theme, comboColor, comboSize);
  275. select_color_and_size (theme, currentColor, comboColor,
  276. currentSize, comboSize);
  277. }
  278. else
  279. {
  280. /* No theme selected */
  281. ret = FALSE;
  282. }
  283. SendMessageW (comboTheme, CB_SETCURSEL, themeIndex, 0);
  284. return ret;
  285. }
  286. /* Update the color & size combo boxes when the selection of the theme
  287. * combo changed. Selects the current color and size scheme if the theme
  288. * is currently active, otherwise the first color and size. */
  289. static BOOL update_color_and_size (int themeIndex, HWND comboColor,
  290. HWND comboSize)
  291. {
  292. if (themeIndex == 0)
  293. {
  294. return FALSE;
  295. }
  296. else
  297. {
  298. WCHAR currentTheme[MAX_PATH];
  299. WCHAR currentColor[MAX_PATH];
  300. WCHAR currentSize[MAX_PATH];
  301. ThemeFile* theme = DSA_GetItemPtr (themeFiles, themeIndex - 1);
  302. fill_color_size_combos (theme, comboColor, comboSize);
  303. if ((SUCCEEDED(GetCurrentThemeName (currentTheme, ARRAY_SIZE(currentTheme),
  304. currentColor, ARRAY_SIZE(currentColor), currentSize, ARRAY_SIZE(currentSize))))
  305. && (lstrcmpiW (currentTheme, theme->themeFileName) == 0))
  306. {
  307. select_color_and_size (theme, currentColor, comboColor,
  308. currentSize, comboSize);
  309. }
  310. else
  311. {
  312. SendMessageW (comboColor, CB_SETCURSEL, 0, 0);
  313. SendMessageW (comboSize, CB_SETCURSEL, 0, 0);
  314. }
  315. }
  316. return TRUE;
  317. }
  318. /* Apply a theme from a given theme, color and size combo box item index. */
  319. static void do_apply_theme (HWND dialog, int themeIndex, int colorIndex, int sizeIndex)
  320. {
  321. static char b[] = "\0";
  322. if (themeIndex == 0)
  323. {
  324. /* no theme */
  325. ApplyTheme (NULL, b, NULL);
  326. }
  327. else
  328. {
  329. ThemeFile* theme = DSA_GetItemPtr (themeFiles, themeIndex-1);
  330. const WCHAR* themeFileName = theme->themeFileName;
  331. const WCHAR* colorName = NULL;
  332. const WCHAR* sizeName = NULL;
  333. HTHEMEFILE hTheme;
  334. ThemeColorOrSize* item;
  335. item = color_or_size_dsa_get (&theme->colors, colorIndex);
  336. colorName = item->name;
  337. item = color_or_size_dsa_get (&theme->sizes, sizeIndex);
  338. sizeName = item->name;
  339. if (SUCCEEDED (OpenThemeFile (themeFileName, colorName, sizeName,
  340. &hTheme, 0)))
  341. {
  342. ApplyTheme (hTheme, b, NULL);
  343. CloseThemeFile (hTheme);
  344. }
  345. else
  346. {
  347. ApplyTheme (NULL, b, NULL);
  348. }
  349. }
  350. refresh_sysparams(dialog);
  351. }
  352. static BOOL updating_ui;
  353. static BOOL theme_dirty;
  354. static void enable_size_and_color_controls (HWND dialog, BOOL enable)
  355. {
  356. EnableWindow (GetDlgItem (dialog, IDC_THEME_COLORCOMBO), enable);
  357. EnableWindow (GetDlgItem (dialog, IDC_THEME_COLORTEXT), enable);
  358. EnableWindow (GetDlgItem (dialog, IDC_THEME_SIZECOMBO), enable);
  359. EnableWindow (GetDlgItem (dialog, IDC_THEME_SIZETEXT), enable);
  360. }
  361. static void init_dialog (HWND dialog)
  362. {
  363. SendDlgItemMessageW(dialog, IDC_SYSPARAM_SIZE_UD, UDM_SETBUDDY,
  364. (WPARAM)GetDlgItem(dialog, IDC_SYSPARAM_SIZE), 0);
  365. }
  366. static void update_dialog (HWND dialog)
  367. {
  368. updating_ui = TRUE;
  369. scan_theme_files();
  370. if (!fill_theme_list (GetDlgItem (dialog, IDC_THEME_THEMECOMBO),
  371. GetDlgItem (dialog, IDC_THEME_COLORCOMBO),
  372. GetDlgItem (dialog, IDC_THEME_SIZECOMBO)))
  373. {
  374. SendMessageW (GetDlgItem (dialog, IDC_THEME_COLORCOMBO), CB_SETCURSEL, (WPARAM)-1, 0);
  375. SendMessageW (GetDlgItem (dialog, IDC_THEME_SIZECOMBO), CB_SETCURSEL, (WPARAM)-1, 0);
  376. enable_size_and_color_controls (dialog, FALSE);
  377. }
  378. else
  379. {
  380. enable_size_and_color_controls (dialog, TRUE);
  381. }
  382. theme_dirty = FALSE;
  383. SendDlgItemMessageW(dialog, IDC_SYSPARAM_SIZE_UD, UDM_SETRANGE, 0, MAKELONG(100, 8));
  384. updating_ui = FALSE;
  385. }
  386. static void on_theme_changed(HWND dialog) {
  387. int index = SendMessageW (GetDlgItem (dialog, IDC_THEME_THEMECOMBO),
  388. CB_GETCURSEL, 0, 0);
  389. if (!update_color_and_size (index, GetDlgItem (dialog, IDC_THEME_COLORCOMBO),
  390. GetDlgItem (dialog, IDC_THEME_SIZECOMBO)))
  391. {
  392. SendMessageW (GetDlgItem (dialog, IDC_THEME_COLORCOMBO), CB_SETCURSEL, -1, 0);
  393. SendMessageW (GetDlgItem (dialog, IDC_THEME_SIZECOMBO), CB_SETCURSEL, -1, 0);
  394. enable_size_and_color_controls (dialog, FALSE);
  395. }
  396. else
  397. {
  398. enable_size_and_color_controls (dialog, TRUE);
  399. }
  400. theme_dirty = TRUE;
  401. }
  402. static void apply_theme(HWND dialog)
  403. {
  404. int themeIndex, colorIndex, sizeIndex;
  405. if (!theme_dirty) return;
  406. themeIndex = SendMessageW (GetDlgItem (dialog, IDC_THEME_THEMECOMBO),
  407. CB_GETCURSEL, 0, 0);
  408. colorIndex = SendMessageW (GetDlgItem (dialog, IDC_THEME_COLORCOMBO),
  409. CB_GETCURSEL, 0, 0);
  410. sizeIndex = SendMessageW (GetDlgItem (dialog, IDC_THEME_SIZECOMBO),
  411. CB_GETCURSEL, 0, 0);
  412. do_apply_theme (dialog, themeIndex, colorIndex, sizeIndex);
  413. theme_dirty = FALSE;
  414. }
  415. static struct
  416. {
  417. int sm_idx, color_idx;
  418. const WCHAR *color_reg;
  419. int size;
  420. COLORREF color;
  421. LOGFONTW lf;
  422. } metrics[] =
  423. {
  424. {-1, COLOR_BTNFACE, L"ButtonFace" }, /* IDC_SYSPARAMS_BUTTON */
  425. {-1, COLOR_BTNTEXT, L"ButtonText" }, /* IDC_SYSPARAMS_BUTTON_TEXT */
  426. {-1, COLOR_BACKGROUND, L"Background" }, /* IDC_SYSPARAMS_DESKTOP */
  427. {SM_CXMENUSIZE, COLOR_MENU, L"Menu" }, /* IDC_SYSPARAMS_MENU */
  428. {-1, COLOR_MENUTEXT, L"MenuText" }, /* IDC_SYSPARAMS_MENU_TEXT */
  429. {SM_CXVSCROLL, COLOR_SCROLLBAR, L"Scrollbar" }, /* IDC_SYSPARAMS_SCROLLBAR */
  430. {-1, COLOR_HIGHLIGHT, L"Hilight" }, /* IDC_SYSPARAMS_SELECTION */
  431. {-1, COLOR_HIGHLIGHTTEXT, L"HilightText" }, /* IDC_SYSPARAMS_SELECTION_TEXT */
  432. {-1, COLOR_INFOBK, L"InfoWindow" }, /* IDC_SYSPARAMS_TOOLTIP */
  433. {-1, COLOR_INFOTEXT, L"InfoText" }, /* IDC_SYSPARAMS_TOOLTIP_TEXT */
  434. {-1, COLOR_WINDOW, L"Window" }, /* IDC_SYSPARAMS_WINDOW */
  435. {-1, COLOR_WINDOWTEXT, L"WindowText" }, /* IDC_SYSPARAMS_WINDOW_TEXT */
  436. {SM_CXSIZE, COLOR_ACTIVECAPTION, L"ActiveTitle" }, /* IDC_SYSPARAMS_ACTIVE_TITLE */
  437. {-1, COLOR_CAPTIONTEXT, L"TitleText" }, /* IDC_SYSPARAMS_ACTIVE_TITLE_TEXT */
  438. {-1, COLOR_INACTIVECAPTION, L"InactiveTitle" }, /* IDC_SYSPARAMS_INACTIVE_TITLE */
  439. {-1, COLOR_INACTIVECAPTIONTEXT,L"InactiveTitleText" }, /* IDC_SYSPARAMS_INACTIVE_TITLE_TEXT */
  440. {-1, -1, L"MsgBoxText" }, /* IDC_SYSPARAMS_MSGBOX_TEXT */
  441. {-1, COLOR_APPWORKSPACE, L"AppWorkSpace" }, /* IDC_SYSPARAMS_APPWORKSPACE */
  442. {-1, COLOR_WINDOWFRAME, L"WindowFrame" }, /* IDC_SYSPARAMS_WINDOW_FRAME */
  443. {-1, COLOR_ACTIVEBORDER, L"ActiveBorder" }, /* IDC_SYSPARAMS_ACTIVE_BORDER */
  444. {-1, COLOR_INACTIVEBORDER, L"InactiveBorder" }, /* IDC_SYSPARAMS_INACTIVE_BORDER */
  445. {-1, COLOR_BTNSHADOW, L"ButtonShadow" }, /* IDC_SYSPARAMS_BUTTON_SHADOW */
  446. {-1, COLOR_GRAYTEXT, L"GrayText" }, /* IDC_SYSPARAMS_GRAY_TEXT */
  447. {-1, COLOR_BTNHIGHLIGHT, L"ButtonHilight" }, /* IDC_SYSPARAMS_BUTTON_HIGHLIGHT */
  448. {-1, COLOR_3DDKSHADOW, L"ButtonDkShadow" }, /* IDC_SYSPARAMS_BUTTON_DARK_SHADOW */
  449. {-1, COLOR_3DLIGHT, L"ButtonLight" }, /* IDC_SYSPARAMS_BUTTON_LIGHT */
  450. {-1, COLOR_ALTERNATEBTNFACE, L"ButtonAlternateFace" }, /* IDC_SYSPARAMS_BUTTON_ALTERNATE */
  451. {-1, COLOR_HOTLIGHT, L"HotTrackingColor" }, /* IDC_SYSPARAMS_HOT_TRACKING */
  452. {-1, COLOR_GRADIENTACTIVECAPTION, L"GradientActiveTitle" }, /* IDC_SYSPARAMS_ACTIVE_TITLE_GRADIENT */
  453. {-1, COLOR_GRADIENTINACTIVECAPTION, L"GradientInactiveTitle" }, /* IDC_SYSPARAMS_INACTIVE_TITLE_GRADIENT */
  454. {-1, COLOR_MENUHILIGHT, L"MenuHilight" }, /* IDC_SYSPARAMS_MENU_HIGHLIGHT */
  455. {-1, COLOR_MENUBAR, L"MenuBar" }, /* IDC_SYSPARAMS_MENUBAR */
  456. };
  457. static void save_sys_color(int idx, COLORREF clr)
  458. {
  459. WCHAR buffer[13];
  460. swprintf(buffer, ARRAY_SIZE(buffer), L"%d %d %d", GetRValue (clr), GetGValue (clr), GetBValue (clr));
  461. set_reg_key(HKEY_CURRENT_USER, L"Control Panel\\Colors", metrics[idx].color_reg, buffer);
  462. }
  463. static void set_color_from_theme(const WCHAR *keyName, COLORREF color)
  464. {
  465. int i;
  466. for (i=0; i < ARRAY_SIZE(metrics); i++)
  467. {
  468. if (wcsicmp(metrics[i].color_reg, keyName)==0)
  469. {
  470. metrics[i].color = color;
  471. save_sys_color(i, color);
  472. break;
  473. }
  474. }
  475. }
  476. static void do_parse_theme(WCHAR *file)
  477. {
  478. WCHAR keyName[MAX_PATH], keyNameValue[MAX_PATH];
  479. WCHAR *keyNamePtr = NULL;
  480. int red = 0, green = 0, blue = 0;
  481. COLORREF color;
  482. WINE_TRACE("%s\n", wine_dbgstr_w(file));
  483. GetPrivateProfileStringW(L"Control Panel\\Colors", NULL, NULL, keyName,
  484. MAX_PATH, file);
  485. keyNamePtr = keyName;
  486. while (*keyNamePtr!=0) {
  487. GetPrivateProfileStringW(L"Control Panel\\Colors", keyNamePtr, NULL, keyNameValue,
  488. MAX_PATH, file);
  489. WINE_TRACE("parsing key: %s with value: %s\n",
  490. wine_dbgstr_w(keyNamePtr), wine_dbgstr_w(keyNameValue));
  491. swscanf(keyNameValue, L"%d %d %d", &red, &green, &blue);
  492. color = RGB((BYTE)red, (BYTE)green, (BYTE)blue);
  493. set_color_from_theme(keyNamePtr, color);
  494. keyNamePtr+=lstrlenW(keyNamePtr);
  495. keyNamePtr++;
  496. }
  497. }
  498. static void on_theme_install(HWND dialog)
  499. {
  500. static const WCHAR filterMask[] = L"\0*.msstyles;*.theme\0";
  501. OPENFILENAMEW ofn;
  502. WCHAR filetitle[MAX_PATH];
  503. WCHAR file[MAX_PATH];
  504. WCHAR filter[100];
  505. WCHAR title[100];
  506. LoadStringW(GetModuleHandleW(NULL), IDS_THEMEFILE, filter, ARRAY_SIZE(filter) - ARRAY_SIZE(filterMask));
  507. memcpy(filter + lstrlenW (filter), filterMask, sizeof(filterMask));
  508. LoadStringW(GetModuleHandleW(NULL), IDS_THEMEFILE_SELECT, title, ARRAY_SIZE(title));
  509. ofn.lStructSize = sizeof(OPENFILENAMEW);
  510. ofn.hwndOwner = dialog;
  511. ofn.hInstance = 0;
  512. ofn.lpstrFilter = filter;
  513. ofn.lpstrCustomFilter = NULL;
  514. ofn.nMaxCustFilter = 0;
  515. ofn.nFilterIndex = 0;
  516. ofn.lpstrFile = file;
  517. ofn.lpstrFile[0] = '\0';
  518. ofn.nMaxFile = ARRAY_SIZE(file);
  519. ofn.lpstrFileTitle = filetitle;
  520. ofn.lpstrFileTitle[0] = '\0';
  521. ofn.nMaxFileTitle = ARRAY_SIZE(filetitle);
  522. ofn.lpstrInitialDir = NULL;
  523. ofn.lpstrTitle = title;
  524. ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_ENABLESIZING;
  525. ofn.nFileOffset = 0;
  526. ofn.nFileExtension = 0;
  527. ofn.lpstrDefExt = NULL;
  528. ofn.lCustData = 0;
  529. ofn.lpfnHook = NULL;
  530. ofn.lpTemplateName = NULL;
  531. if (GetOpenFileNameW(&ofn))
  532. {
  533. WCHAR themeFilePath[MAX_PATH];
  534. SHFILEOPSTRUCTW shfop;
  535. if (FAILED (SHGetFolderPathW (NULL, CSIDL_RESOURCES|CSIDL_FLAG_CREATE, NULL,
  536. SHGFP_TYPE_CURRENT, themeFilePath))) return;
  537. if (lstrcmpiW(PathFindExtensionW(filetitle), L".theme")==0)
  538. {
  539. do_parse_theme(file);
  540. SendMessageW(GetParent(dialog), PSM_CHANGED, 0, 0);
  541. return;
  542. }
  543. PathRemoveExtensionW (filetitle);
  544. /* Construct path into which the theme file goes */
  545. lstrcatW (themeFilePath, L"\\themes\\");
  546. lstrcatW (themeFilePath, filetitle);
  547. /* Create the directory */
  548. SHCreateDirectoryExW (dialog, themeFilePath, NULL);
  549. /* Append theme file name itself */
  550. lstrcatW (themeFilePath, L"\\");
  551. lstrcatW (themeFilePath, PathFindFileNameW (file));
  552. /* SHFileOperation() takes lists as input, so double-nullterminate */
  553. themeFilePath[lstrlenW (themeFilePath)+1] = 0;
  554. file[lstrlenW (file)+1] = 0;
  555. /* Do the copying */
  556. WINE_TRACE("copying: %s -> %s\n", wine_dbgstr_w (file),
  557. wine_dbgstr_w (themeFilePath));
  558. shfop.hwnd = dialog;
  559. shfop.wFunc = FO_COPY;
  560. shfop.pFrom = file;
  561. shfop.pTo = themeFilePath;
  562. shfop.fFlags = FOF_NOCONFIRMMKDIR;
  563. if (SHFileOperationW (&shfop) == 0)
  564. {
  565. scan_theme_files();
  566. if (!fill_theme_list (GetDlgItem (dialog, IDC_THEME_THEMECOMBO),
  567. GetDlgItem (dialog, IDC_THEME_COLORCOMBO),
  568. GetDlgItem (dialog, IDC_THEME_SIZECOMBO)))
  569. {
  570. SendMessageW (GetDlgItem (dialog, IDC_THEME_COLORCOMBO), CB_SETCURSEL, -1, 0);
  571. SendMessageW (GetDlgItem (dialog, IDC_THEME_SIZECOMBO), CB_SETCURSEL, -1, 0);
  572. enable_size_and_color_controls (dialog, FALSE);
  573. }
  574. else
  575. {
  576. enable_size_and_color_controls (dialog, TRUE);
  577. }
  578. }
  579. else
  580. WINE_TRACE("copy operation failed\n");
  581. }
  582. else WINE_TRACE("user cancelled\n");
  583. }
  584. /* Information about symbolic link targets of certain User Shell Folders. */
  585. struct ShellFolderInfo {
  586. int nFolder;
  587. char szLinkTarget[FILENAME_MAX]; /* in unix locale */
  588. };
  589. #define CSIDL_DOWNLOADS 0x0047
  590. static struct ShellFolderInfo asfiInfo[] = {
  591. { CSIDL_DESKTOP, "" },
  592. { CSIDL_PERSONAL, "" },
  593. { CSIDL_MYPICTURES, "" },
  594. { CSIDL_MYMUSIC, "" },
  595. { CSIDL_MYVIDEO, "" },
  596. { CSIDL_DOWNLOADS, "" },
  597. { CSIDL_TEMPLATES, "" }
  598. };
  599. static struct ShellFolderInfo *psfiSelected = NULL;
  600. static void init_shell_folder_listview_headers(HWND dialog) {
  601. LVCOLUMNW listColumn;
  602. RECT viewRect;
  603. WCHAR szShellFolder[64] = L"Shell Folder";
  604. WCHAR szLinksTo[64] = L"Links to";
  605. int width;
  606. LoadStringW(GetModuleHandleW(NULL), IDS_SHELL_FOLDER, szShellFolder, ARRAY_SIZE(szShellFolder));
  607. LoadStringW(GetModuleHandleW(NULL), IDS_LINKS_TO, szLinksTo, ARRAY_SIZE(szLinksTo));
  608. GetClientRect(GetDlgItem(dialog, IDC_LIST_SFPATHS), &viewRect);
  609. width = (viewRect.right - viewRect.left) / 3;
  610. listColumn.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
  611. listColumn.pszText = szShellFolder;
  612. listColumn.cchTextMax = lstrlenW(listColumn.pszText);
  613. listColumn.cx = width;
  614. SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_INSERTCOLUMNW, 0, (LPARAM) &listColumn);
  615. listColumn.pszText = szLinksTo;
  616. listColumn.cchTextMax = lstrlenW(listColumn.pszText);
  617. listColumn.cx = viewRect.right - viewRect.left - width - 1;
  618. SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_INSERTCOLUMNW, 1, (LPARAM) &listColumn);
  619. }
  620. /* Reads the currently set shell folder symbol link targets into asfiInfo. */
  621. static void read_shell_folder_link_targets(void) {
  622. WCHAR wszPath[MAX_PATH];
  623. int i;
  624. for (i=0; i<ARRAY_SIZE(asfiInfo); i++) {
  625. asfiInfo[i].szLinkTarget[0] = '\0';
  626. if (SUCCEEDED( SHGetFolderPathW( NULL, asfiInfo[i].nFolder | CSIDL_FLAG_DONT_VERIFY, NULL,
  627. SHGFP_TYPE_CURRENT, wszPath )))
  628. query_shell_folder( wszPath, asfiInfo[i].szLinkTarget, FILENAME_MAX );
  629. }
  630. }
  631. static void update_shell_folder_listview(HWND dialog) {
  632. int i;
  633. LVITEMW item;
  634. LONG lSelected = SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_GETNEXTITEM, -1,
  635. MAKELPARAM(LVNI_SELECTED,0));
  636. SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_DELETEALLITEMS, 0, 0);
  637. for (i=0; i<ARRAY_SIZE(asfiInfo); i++) {
  638. WCHAR buffer[MAX_PATH];
  639. HRESULT hr;
  640. LPITEMIDLIST pidlCurrent;
  641. /* Some acrobatic to get the localized name of the shell folder */
  642. hr = SHGetFolderLocation(dialog, asfiInfo[i].nFolder, NULL, 0, &pidlCurrent);
  643. if (SUCCEEDED(hr)) {
  644. LPSHELLFOLDER psfParent;
  645. LPCITEMIDLIST pidlLast;
  646. hr = SHBindToParent(pidlCurrent, &IID_IShellFolder, (LPVOID*)&psfParent, &pidlLast);
  647. if (SUCCEEDED(hr)) {
  648. STRRET strRet;
  649. hr = IShellFolder_GetDisplayNameOf(psfParent, pidlLast, SHGDN_FORADDRESSBAR, &strRet);
  650. if (SUCCEEDED(hr)) {
  651. hr = StrRetToBufW(&strRet, pidlLast, buffer, MAX_PATH);
  652. }
  653. IShellFolder_Release(psfParent);
  654. }
  655. ILFree(pidlCurrent);
  656. }
  657. /* If there's a dangling symlink for the current shell folder, SHGetFolderLocation
  658. * will fail above. We fall back to the (non-verified) path of the shell folder. */
  659. if (FAILED(hr)) {
  660. hr = SHGetFolderPathW(dialog, asfiInfo[i].nFolder|CSIDL_FLAG_DONT_VERIFY, NULL,
  661. SHGFP_TYPE_CURRENT, buffer);
  662. }
  663. item.mask = LVIF_TEXT | LVIF_PARAM;
  664. item.iItem = i;
  665. item.iSubItem = 0;
  666. item.pszText = buffer;
  667. item.lParam = (LPARAM)&asfiInfo[i];
  668. SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_INSERTITEMW, 0, (LPARAM)&item);
  669. item.mask = LVIF_TEXT;
  670. item.iItem = i;
  671. item.iSubItem = 1;
  672. item.pszText = strdupU2W(asfiInfo[i].szLinkTarget);
  673. SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_SETITEMW, 0, (LPARAM)&item);
  674. HeapFree(GetProcessHeap(), 0, item.pszText);
  675. }
  676. /* Ensure that the previously selected item is selected again. */
  677. if (lSelected >= 0) {
  678. item.mask = LVIF_STATE;
  679. item.state = LVIS_SELECTED;
  680. item.stateMask = LVIS_SELECTED;
  681. SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_SETITEMSTATE, lSelected, (LPARAM)&item);
  682. }
  683. }
  684. static void on_shell_folder_selection_changed(HWND hDlg, LPNMLISTVIEW lpnm) {
  685. if (lpnm->uNewState & LVIS_SELECTED) {
  686. psfiSelected = (struct ShellFolderInfo *)lpnm->lParam;
  687. EnableWindow(GetDlgItem(hDlg, IDC_LINK_SFPATH), 1);
  688. if (*psfiSelected->szLinkTarget) {
  689. WCHAR *link;
  690. CheckDlgButton(hDlg, IDC_LINK_SFPATH, BST_CHECKED);
  691. EnableWindow(GetDlgItem(hDlg, IDC_EDIT_SFPATH), 1);
  692. EnableWindow(GetDlgItem(hDlg, IDC_BROWSE_SFPATH), 1);
  693. link = strdupU2W(psfiSelected->szLinkTarget);
  694. set_textW(hDlg, IDC_EDIT_SFPATH, link);
  695. HeapFree(GetProcessHeap(), 0, link);
  696. } else {
  697. CheckDlgButton(hDlg, IDC_LINK_SFPATH, BST_UNCHECKED);
  698. EnableWindow(GetDlgItem(hDlg, IDC_EDIT_SFPATH), 0);
  699. EnableWindow(GetDlgItem(hDlg, IDC_BROWSE_SFPATH), 0);
  700. set_text(hDlg, IDC_EDIT_SFPATH, "");
  701. }
  702. } else {
  703. psfiSelected = NULL;
  704. CheckDlgButton(hDlg, IDC_LINK_SFPATH, BST_UNCHECKED);
  705. set_text(hDlg, IDC_EDIT_SFPATH, "");
  706. EnableWindow(GetDlgItem(hDlg, IDC_LINK_SFPATH), 0);
  707. EnableWindow(GetDlgItem(hDlg, IDC_EDIT_SFPATH), 0);
  708. EnableWindow(GetDlgItem(hDlg, IDC_BROWSE_SFPATH), 0);
  709. }
  710. }
  711. /* Keep the contents of the edit control, the listview control and the symlink
  712. * information in sync. */
  713. static void on_shell_folder_edit_changed(HWND hDlg) {
  714. LVITEMW item;
  715. WCHAR *text = get_text(hDlg, IDC_EDIT_SFPATH);
  716. LONG iSel = SendDlgItemMessageW(hDlg, IDC_LIST_SFPATHS, LVM_GETNEXTITEM, -1,
  717. MAKELPARAM(LVNI_SELECTED,0));
  718. if (!text || !psfiSelected || iSel < 0) {
  719. HeapFree(GetProcessHeap(), 0, text);
  720. return;
  721. }
  722. WideCharToMultiByte(CP_UNIXCP, 0, text, -1,
  723. psfiSelected->szLinkTarget, FILENAME_MAX, NULL, NULL);
  724. item.mask = LVIF_TEXT;
  725. item.iItem = iSel;
  726. item.iSubItem = 1;
  727. item.pszText = text;
  728. SendDlgItemMessageW(hDlg, IDC_LIST_SFPATHS, LVM_SETITEMW, 0, (LPARAM)&item);
  729. HeapFree(GetProcessHeap(), 0, text);
  730. SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
  731. }
  732. static void apply_shell_folder_changes(void) {
  733. WCHAR wszPath[MAX_PATH];
  734. int i;
  735. for (i=0; i<ARRAY_SIZE(asfiInfo); i++) {
  736. if (SUCCEEDED( SHGetFolderPathW( NULL, asfiInfo[i].nFolder | CSIDL_FLAG_CREATE, NULL,
  737. SHGFP_TYPE_CURRENT, wszPath )))
  738. set_shell_folder( wszPath, asfiInfo[i].szLinkTarget );
  739. }
  740. }
  741. static void refresh_sysparams(HWND hDlg)
  742. {
  743. int i;
  744. for (i = 0; i < ARRAY_SIZE(metrics); i++)
  745. {
  746. if (metrics[i].sm_idx != -1)
  747. metrics[i].size = GetSystemMetrics(metrics[i].sm_idx);
  748. if (metrics[i].color_idx != -1)
  749. metrics[i].color = GetSysColor(metrics[i].color_idx);
  750. }
  751. on_sysparam_change(hDlg);
  752. }
  753. static void read_sysparams(HWND hDlg)
  754. {
  755. WCHAR buffer[256];
  756. HWND list = GetDlgItem(hDlg, IDC_SYSPARAM_COMBO);
  757. NONCLIENTMETRICSW nonclient_metrics;
  758. int i, idx;
  759. for (i = 0; i < ARRAY_SIZE(metrics); i++)
  760. {
  761. LoadStringW(GetModuleHandleW(NULL), i + IDC_SYSPARAMS_BUTTON, buffer, ARRAY_SIZE(buffer));
  762. idx = SendMessageW(list, CB_ADDSTRING, 0, (LPARAM)buffer);
  763. if (idx != CB_ERR) SendMessageW(list, CB_SETITEMDATA, idx, i);
  764. if (metrics[i].sm_idx != -1)
  765. metrics[i].size = GetSystemMetrics(metrics[i].sm_idx);
  766. if (metrics[i].color_idx != -1)
  767. metrics[i].color = GetSysColor(metrics[i].color_idx);
  768. }
  769. nonclient_metrics.cbSize = sizeof(NONCLIENTMETRICSW);
  770. SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSW), &nonclient_metrics, 0);
  771. memcpy(&(metrics[IDC_SYSPARAMS_MENU_TEXT - IDC_SYSPARAMS_BUTTON].lf),
  772. &(nonclient_metrics.lfMenuFont), sizeof(LOGFONTW));
  773. memcpy(&(metrics[IDC_SYSPARAMS_ACTIVE_TITLE_TEXT - IDC_SYSPARAMS_BUTTON].lf),
  774. &(nonclient_metrics.lfCaptionFont), sizeof(LOGFONTW));
  775. memcpy(&(metrics[IDC_SYSPARAMS_TOOLTIP_TEXT - IDC_SYSPARAMS_BUTTON].lf),
  776. &(nonclient_metrics.lfStatusFont), sizeof(LOGFONTW));
  777. memcpy(&(metrics[IDC_SYSPARAMS_MSGBOX_TEXT - IDC_SYSPARAMS_BUTTON].lf),
  778. &(nonclient_metrics.lfMessageFont), sizeof(LOGFONTW));
  779. }
  780. static void apply_sysparams(void)
  781. {
  782. NONCLIENTMETRICSW ncm;
  783. int i, cnt = 0;
  784. int colors_idx[ARRAY_SIZE(metrics)];
  785. COLORREF colors[ARRAY_SIZE(metrics)];
  786. HDC hdc;
  787. int dpi;
  788. hdc = GetDC( 0 );
  789. dpi = GetDeviceCaps( hdc, LOGPIXELSY );
  790. ReleaseDC( 0, hdc );
  791. ncm.cbSize = sizeof(ncm);
  792. SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0);
  793. /* convert metrics back to twips */
  794. ncm.iMenuWidth = ncm.iMenuHeight =
  795. MulDiv( metrics[IDC_SYSPARAMS_MENU - IDC_SYSPARAMS_BUTTON].size, -1440, dpi );
  796. ncm.iCaptionWidth = ncm.iCaptionHeight =
  797. MulDiv( metrics[IDC_SYSPARAMS_ACTIVE_TITLE - IDC_SYSPARAMS_BUTTON].size, -1440, dpi );
  798. ncm.iScrollWidth = ncm.iScrollHeight =
  799. MulDiv( metrics[IDC_SYSPARAMS_SCROLLBAR - IDC_SYSPARAMS_BUTTON].size, -1440, dpi );
  800. ncm.iSmCaptionWidth = MulDiv( ncm.iSmCaptionWidth, -1440, dpi );
  801. ncm.iSmCaptionHeight = MulDiv( ncm.iSmCaptionHeight, -1440, dpi );
  802. ncm.lfMenuFont = metrics[IDC_SYSPARAMS_MENU_TEXT - IDC_SYSPARAMS_BUTTON].lf;
  803. ncm.lfCaptionFont = metrics[IDC_SYSPARAMS_ACTIVE_TITLE_TEXT - IDC_SYSPARAMS_BUTTON].lf;
  804. ncm.lfStatusFont = metrics[IDC_SYSPARAMS_TOOLTIP_TEXT - IDC_SYSPARAMS_BUTTON].lf;
  805. ncm.lfMessageFont = metrics[IDC_SYSPARAMS_MSGBOX_TEXT - IDC_SYSPARAMS_BUTTON].lf;
  806. SystemParametersInfoW(SPI_SETNONCLIENTMETRICS, sizeof(ncm), &ncm,
  807. SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
  808. for (i = 0; i < ARRAY_SIZE(metrics); i++)
  809. if (metrics[i].color_idx != -1)
  810. {
  811. colors_idx[cnt] = metrics[i].color_idx;
  812. colors[cnt++] = metrics[i].color;
  813. }
  814. SetSysColors(cnt, colors_idx, colors);
  815. }
  816. static void on_sysparam_change(HWND hDlg)
  817. {
  818. int index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETCURSEL, 0, 0);
  819. index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETITEMDATA, index, 0);
  820. updating_ui = TRUE;
  821. EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_COLOR_TEXT), metrics[index].color_idx != -1);
  822. EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_COLOR), metrics[index].color_idx != -1);
  823. InvalidateRect(GetDlgItem(hDlg, IDC_SYSPARAM_COLOR), NULL, TRUE);
  824. EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_SIZE_TEXT), metrics[index].sm_idx != -1);
  825. EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_SIZE), metrics[index].sm_idx != -1);
  826. EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_SIZE_UD), metrics[index].sm_idx != -1);
  827. if (metrics[index].sm_idx != -1)
  828. SendDlgItemMessageW(hDlg, IDC_SYSPARAM_SIZE_UD, UDM_SETPOS, 0, MAKELONG(metrics[index].size, 0));
  829. else
  830. set_text(hDlg, IDC_SYSPARAM_SIZE, "");
  831. EnableWindow(GetDlgItem(hDlg, IDC_SYSPARAM_FONT),
  832. index == IDC_SYSPARAMS_MENU_TEXT-IDC_SYSPARAMS_BUTTON ||
  833. index == IDC_SYSPARAMS_ACTIVE_TITLE_TEXT-IDC_SYSPARAMS_BUTTON ||
  834. index == IDC_SYSPARAMS_TOOLTIP_TEXT-IDC_SYSPARAMS_BUTTON ||
  835. index == IDC_SYSPARAMS_MSGBOX_TEXT-IDC_SYSPARAMS_BUTTON
  836. );
  837. updating_ui = FALSE;
  838. }
  839. static void on_draw_item(HWND hDlg, WPARAM wParam, LPARAM lParam)
  840. {
  841. static HBRUSH black_brush = 0;
  842. LPDRAWITEMSTRUCT draw_info = (LPDRAWITEMSTRUCT)lParam;
  843. if (!black_brush) black_brush = CreateSolidBrush(0);
  844. if (draw_info->CtlID == IDC_SYSPARAM_COLOR)
  845. {
  846. UINT state;
  847. HTHEME theme;
  848. RECT buttonrect;
  849. theme = OpenThemeDataForDpi(NULL, WC_BUTTONW, GetDpiForWindow(hDlg));
  850. if (theme) {
  851. MARGINS margins;
  852. if (draw_info->itemState & ODS_DISABLED)
  853. state = PBS_DISABLED;
  854. else if (draw_info->itemState & ODS_SELECTED)
  855. state = PBS_PRESSED;
  856. else
  857. state = PBS_NORMAL;
  858. if (IsThemeBackgroundPartiallyTransparent(theme, BP_PUSHBUTTON, state))
  859. DrawThemeParentBackground(draw_info->hwndItem, draw_info->hDC, NULL);
  860. DrawThemeBackground(theme, draw_info->hDC, BP_PUSHBUTTON, state, &draw_info->rcItem, NULL);
  861. buttonrect = draw_info->rcItem;
  862. GetThemeMargins(theme, draw_info->hDC, BP_PUSHBUTTON, state, TMT_CONTENTMARGINS, &draw_info->rcItem, &margins);
  863. buttonrect.left += margins.cxLeftWidth;
  864. buttonrect.top += margins.cyTopHeight;
  865. buttonrect.right -= margins.cxRightWidth;
  866. buttonrect.bottom -= margins.cyBottomHeight;
  867. if (draw_info->itemState & ODS_FOCUS)
  868. DrawFocusRect(draw_info->hDC, &buttonrect);
  869. CloseThemeData(theme);
  870. } else {
  871. state = DFCS_ADJUSTRECT | DFCS_BUTTONPUSH;
  872. if (draw_info->itemState & ODS_DISABLED)
  873. state |= DFCS_INACTIVE;
  874. else
  875. state |= draw_info->itemState & ODS_SELECTED ? DFCS_PUSHED : 0;
  876. DrawFrameControl(draw_info->hDC, &draw_info->rcItem, DFC_BUTTON, state);
  877. buttonrect = draw_info->rcItem;
  878. }
  879. if (!(draw_info->itemState & ODS_DISABLED))
  880. {
  881. HBRUSH brush;
  882. int index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETCURSEL, 0, 0);
  883. index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETITEMDATA, index, 0);
  884. brush = CreateSolidBrush(metrics[index].color);
  885. InflateRect(&buttonrect, -1, -1);
  886. FrameRect(draw_info->hDC, &buttonrect, black_brush);
  887. InflateRect(&buttonrect, -1, -1);
  888. FillRect(draw_info->hDC, &buttonrect, brush);
  889. DeleteObject(brush);
  890. }
  891. }
  892. }
  893. static void on_select_font(HWND hDlg)
  894. {
  895. CHOOSEFONTW cf;
  896. int index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETCURSEL, 0, 0);
  897. index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETITEMDATA, index, 0);
  898. ZeroMemory(&cf, sizeof(cf));
  899. cf.lStructSize = sizeof(CHOOSEFONTW);
  900. cf.hwndOwner = hDlg;
  901. cf.lpLogFont = &(metrics[index].lf);
  902. cf.Flags = CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT | CF_NOSCRIPTSEL | CF_NOVERTFONTS;
  903. if (ChooseFontW(&cf))
  904. SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
  905. }
  906. static void init_mime_types(HWND hDlg)
  907. {
  908. WCHAR *buf = get_reg_key(config_key, keypath(L"FileOpenAssociations"), L"Enable", L"Y");
  909. int state = IS_OPTION_TRUE(*buf) ? BST_CHECKED : BST_UNCHECKED;
  910. CheckDlgButton(hDlg, IDC_ENABLE_FILE_ASSOCIATIONS, state);
  911. HeapFree(GetProcessHeap(), 0, buf);
  912. }
  913. static void update_mime_types(HWND hDlg)
  914. {
  915. const WCHAR *state = L"Y";
  916. if (IsDlgButtonChecked(hDlg, IDC_ENABLE_FILE_ASSOCIATIONS) != BST_CHECKED)
  917. state = L"N";
  918. set_reg_key(config_key, keypath(L"FileOpenAssociations"), L"Enable", state);
  919. }
  920. INT_PTR CALLBACK
  921. ThemeDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  922. {
  923. switch (uMsg) {
  924. case WM_INITDIALOG:
  925. read_shell_folder_link_targets();
  926. init_shell_folder_listview_headers(hDlg);
  927. update_shell_folder_listview(hDlg);
  928. read_sysparams(hDlg);
  929. init_mime_types(hDlg);
  930. init_dialog(hDlg);
  931. break;
  932. case WM_DESTROY:
  933. free_theme_files();
  934. break;
  935. case WM_SHOWWINDOW:
  936. set_window_title(hDlg);
  937. break;
  938. case WM_COMMAND:
  939. switch(HIWORD(wParam)) {
  940. case CBN_SELCHANGE: {
  941. if (updating_ui) break;
  942. switch (LOWORD(wParam))
  943. {
  944. case IDC_THEME_THEMECOMBO: on_theme_changed(hDlg); break;
  945. case IDC_THEME_COLORCOMBO: /* fall through */
  946. case IDC_THEME_SIZECOMBO: theme_dirty = TRUE; break;
  947. case IDC_SYSPARAM_COMBO: on_sysparam_change(hDlg); return FALSE;
  948. }
  949. SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
  950. break;
  951. }
  952. case EN_CHANGE: {
  953. if (updating_ui) break;
  954. switch (LOWORD(wParam))
  955. {
  956. case IDC_EDIT_SFPATH: on_shell_folder_edit_changed(hDlg); break;
  957. case IDC_SYSPARAM_SIZE:
  958. {
  959. WCHAR *text = get_text(hDlg, IDC_SYSPARAM_SIZE);
  960. int index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETCURSEL, 0, 0);
  961. index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETITEMDATA, index, 0);
  962. if (text)
  963. {
  964. metrics[index].size = wcstol(text, NULL, 10);
  965. HeapFree(GetProcessHeap(), 0, text);
  966. }
  967. else
  968. {
  969. /* for empty string set to minimum value */
  970. SendDlgItemMessageW(hDlg, IDC_SYSPARAM_SIZE_UD, UDM_GETRANGE32, (WPARAM)&metrics[index].size, 0);
  971. }
  972. SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
  973. break;
  974. }
  975. }
  976. break;
  977. }
  978. case BN_CLICKED:
  979. switch (LOWORD(wParam))
  980. {
  981. case IDC_THEME_INSTALL:
  982. on_theme_install (hDlg);
  983. break;
  984. case IDC_SYSPARAM_FONT:
  985. on_select_font(hDlg);
  986. break;
  987. case IDC_BROWSE_SFPATH:
  988. {
  989. WCHAR link[FILENAME_MAX];
  990. if (browse_for_unix_folder(hDlg, link)) {
  991. WideCharToMultiByte(CP_UNIXCP, 0, link, -1,
  992. psfiSelected->szLinkTarget, FILENAME_MAX,
  993. NULL, NULL);
  994. update_shell_folder_listview(hDlg);
  995. SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
  996. }
  997. break;
  998. }
  999. case IDC_LINK_SFPATH:
  1000. if (IsDlgButtonChecked(hDlg, IDC_LINK_SFPATH)) {
  1001. WCHAR link[FILENAME_MAX];
  1002. if (browse_for_unix_folder(hDlg, link)) {
  1003. WideCharToMultiByte(CP_UNIXCP, 0, link, -1,
  1004. psfiSelected->szLinkTarget, FILENAME_MAX,
  1005. NULL, NULL);
  1006. update_shell_folder_listview(hDlg);
  1007. SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
  1008. } else {
  1009. CheckDlgButton(hDlg, IDC_LINK_SFPATH, BST_UNCHECKED);
  1010. }
  1011. } else {
  1012. psfiSelected->szLinkTarget[0] = '\0';
  1013. update_shell_folder_listview(hDlg);
  1014. SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
  1015. }
  1016. break;
  1017. case IDC_SYSPARAM_COLOR:
  1018. {
  1019. static COLORREF user_colors[16];
  1020. CHOOSECOLORW c_color;
  1021. int index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETCURSEL, 0, 0);
  1022. index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETITEMDATA, index, 0);
  1023. memset(&c_color, 0, sizeof(c_color));
  1024. c_color.lStructSize = sizeof(c_color);
  1025. c_color.lpCustColors = user_colors;
  1026. c_color.rgbResult = metrics[index].color;
  1027. c_color.Flags = CC_ANYCOLOR | CC_RGBINIT;
  1028. c_color.hwndOwner = hDlg;
  1029. if (ChooseColorW(&c_color))
  1030. {
  1031. metrics[index].color = c_color.rgbResult;
  1032. save_sys_color(index, metrics[index].color);
  1033. InvalidateRect(GetDlgItem(hDlg, IDC_SYSPARAM_COLOR), NULL, TRUE);
  1034. SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
  1035. }
  1036. break;
  1037. }
  1038. case IDC_ENABLE_FILE_ASSOCIATIONS:
  1039. update_mime_types(hDlg);
  1040. SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
  1041. break;
  1042. }
  1043. break;
  1044. }
  1045. break;
  1046. case WM_NOTIFY:
  1047. switch (((LPNMHDR)lParam)->code) {
  1048. case PSN_KILLACTIVE: {
  1049. SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, FALSE);
  1050. break;
  1051. }
  1052. case PSN_APPLY: {
  1053. apply();
  1054. apply_theme(hDlg);
  1055. apply_shell_folder_changes();
  1056. apply_sysparams();
  1057. read_shell_folder_link_targets();
  1058. update_shell_folder_listview(hDlg);
  1059. update_mime_types(hDlg);
  1060. SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
  1061. break;
  1062. }
  1063. case LVN_ITEMCHANGED: {
  1064. if (wParam == IDC_LIST_SFPATHS)
  1065. on_shell_folder_selection_changed(hDlg, (LPNMLISTVIEW)lParam);
  1066. break;
  1067. }
  1068. case PSN_SETACTIVE: {
  1069. update_dialog(hDlg);
  1070. break;
  1071. }
  1072. }
  1073. break;
  1074. case WM_DRAWITEM:
  1075. on_draw_item(hDlg, wParam, lParam);
  1076. break;
  1077. default:
  1078. break;
  1079. }
  1080. return FALSE;
  1081. }