1
0

prefs_font.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  1. #include "precomp__gen_ff.h"
  2. #include <commctrl.h>
  3. #include <windows.h>
  4. #include <windowsx.h>
  5. #include "resource.h"
  6. #include <api/font/font.h>
  7. #include <bfc/parse/paramparser.h>
  8. #include "../nu/ListView.h"
  9. #include "prefs.h"
  10. #include "gen.h"
  11. #include "wa2cfgitems.h"
  12. #include <api/font/win32/truetypefont_win32.h>
  13. #include "../Agave/Language/api_language.h"
  14. extern HWND subWnd;
  15. #define ComboBox_SetItemDataW(hwndCtl, index, data) ((int)(DWORD)SendMessageW((hwndCtl), CB_SETITEMDATA, (WPARAM)(int)(index), (LPARAM)(data)))
  16. #define ComboBox_GetLBTextLenW(hwndCtl, index) ((int)(DWORD)SendMessageW((hwndCtl), CB_GETLBTEXTLEN, (WPARAM)(int)(index), 0L))
  17. #define ComboBox_GetLBTextW(hwndCtl, index, lpszBuffer) ((int)(DWORD)SendMessageW((hwndCtl), CB_GETLBTEXT, (WPARAM)(int)(index), (LPARAM)(LPCWSTR)(lpszBuffer)))
  18. #define ComboBox_SelectStringW(hwndCtl, indexStart, lpszSelect) ((int)(DWORD)SendMessageW((hwndCtl), CB_SELECTSTRING, (WPARAM)(int)(indexStart), (LPARAM)(LPCWSTR)(lpszSelect)))
  19. static W_ListView mappingList;
  20. int fonts_loaded = 0;
  21. int ComboBox_AddStringW(HWND list, const wchar_t *string);
  22. class font_entry
  23. {
  24. public:
  25. StringW filename;
  26. StringW face;
  27. };
  28. class font_entry_comparator1
  29. {
  30. public:
  31. // comparator for sorting
  32. static int compareItem(font_entry *p1, font_entry* p2)
  33. {
  34. return wcscmp(p1->face, p2->face);
  35. }
  36. // comparator for searching
  37. static int compareAttrib(const wchar_t *attrib, font_entry *item)
  38. {
  39. return wcscmp(attrib, item->face);
  40. }
  41. };
  42. class font_entry_comparator2
  43. {
  44. public:
  45. // comparator for sorting
  46. static int compareItem(font_entry *p1, font_entry* p2)
  47. {
  48. return _wcsicmp(p1->filename, p2->filename);
  49. }
  50. // comparator for searching
  51. static int compareAttrib(const wchar_t *attrib, font_entry *item)
  52. {
  53. return _wcsicmp(attrib, item->filename);
  54. }
  55. };
  56. int ResizeComboBoxDropDown(HWND hwndDlg, UINT id, const wchar_t * str, int width);
  57. PtrListQuickSorted<font_entry, font_entry_comparator1> fontlist;
  58. PtrListQuickSorted<font_entry, font_entry_comparator2> fontlist_byfilename;
  59. PtrListQuickSorted<font_entry, font_entry_comparator1> skin_fontlist;
  60. PtrListQuickSorted<font_entry, font_entry_comparator2> skin_fontlist_byfilename;
  61. void fillFontLists(HWND list, HWND list2, int selectdefault = 1)
  62. {
  63. fontlist.deleteAll();
  64. fontlist_byfilename.removeAll();
  65. ComboBox_ResetContent(list);
  66. ComboBox_ResetContent(list2);
  67. SendMessageW(list, CB_INITSTORAGE, 400, 32);
  68. SendMessageW(list2, CB_INITSTORAGE, 400, 32);
  69. wchar_t *txt = WMALLOC(WA_MAX_PATH);
  70. Wasabi::Std::getFontPath(WA_MAX_PATH, txt);
  71. StringW path = txt;
  72. StringW deffont = cfg_options_ttfoverridefont.getValue();
  73. FREE(txt);
  74. StringPathCombine mask(path, L"*.ttf");
  75. WIN32_FIND_DATAW fd = {0};
  76. HANDLE fh;
  77. int width = 0, width2 = 0;
  78. if ((fh = FindFirstFileW(mask, &fd)) != INVALID_HANDLE_VALUE)
  79. {
  80. while (1)
  81. {
  82. StringW fullpath = fd.cFileName;
  83. if (_wcsicmp(fullpath, L".") && _wcsicmp(fullpath, L".."))
  84. {
  85. fullpath = StringPathCombine(path, fullpath);
  86. StringW fontname = TrueTypeFont_Win32::filenameToFontFace(fullpath);
  87. if (!fontname.isempty())
  88. {
  89. if (fontlist_byfilename.findItem(fd.cFileName)) continue;
  90. font_entry *fe = new font_entry;
  91. fe->face = fontname;
  92. fe->filename = fd.cFileName;
  93. fontlist.addItem(fe);
  94. fontlist_byfilename.addItem(fe);
  95. int idx = ComboBox_AddStringW(list, fontname);
  96. ComboBox_SetItemData(list, idx, fe);
  97. width = ResizeComboBoxDropDown(list, 0, fontname, width);
  98. idx = ComboBox_AddStringW(list2, fontname);
  99. ComboBox_SetItemData(list2, idx, fe);
  100. width2 = ResizeComboBoxDropDown(list2, 0, fontname, width2);
  101. }
  102. }
  103. if (!FindNextFileW(fh, &fd)) break;
  104. }
  105. }
  106. if (fh != INVALID_HANDLE_VALUE) FindClose(fh);
  107. int pos = -1;
  108. font_entry *fe = fontlist_byfilename.findItem(deffont.v(), NULL);
  109. if (fe)
  110. {
  111. fontlist.sort(1);
  112. pos = fontlist.searchItem(fe);
  113. }
  114. ComboBox_SetCurSel(list, pos);
  115. }
  116. int fm_validMapping(HWND wnd)
  117. {
  118. if (ComboBox_GetCurSel(GetDlgItem(wnd, IDC_COMBO_SKINFONTS)) == -1) return 0;
  119. if (ComboBox_GetCurSel(GetDlgItem(wnd, IDC_COMBO_FONTS)) == -1) return 0;
  120. return 1;
  121. }
  122. int fm_hasSelection(HWND wnd)
  123. {
  124. int n = mappingList.GetCount();
  125. for (int i = 0;i < n;i++)
  126. if (mappingList.GetSelected(i))
  127. return 1;
  128. return 0;
  129. }
  130. void fm_itemClicked(HWND wnd, int pos)
  131. {
  132. HWND combo1 = GetDlgItem(wnd, IDC_COMBO_SKINFONTS);
  133. HWND combo2 = GetDlgItem(wnd, IDC_COMBO_FONTS);
  134. int n = mappingList.GetCount();
  135. for (int i = 0;i < n;i++)
  136. {
  137. if (mappingList.GetSelected(i))
  138. {
  139. wchar_t txt[4096] = {0};
  140. mappingList.GetText(i, 0, txt, 4096);
  141. ComboBox_SetCurSel(combo1, -1);
  142. if (skin_fontlist.findItem(txt))
  143. ComboBox_SelectStringW(combo1, -1, StringPrintfW(L" %s", txt));
  144. else
  145. ComboBox_SelectStringW(combo1, -1, txt);
  146. mappingList.GetText(i, 1, txt, 4096);
  147. ComboBox_SetCurSel(combo2, -1);
  148. ComboBox_SelectStringW(combo2, -1, txt);
  149. wchar_t type[64] = {0};
  150. mappingList.GetText(i, 3, type, 64);
  151. CheckDlgButton(wnd, IDC_RADIO_THISSKIN, WCSCASEEQLSAFE(type, WASABI_API_LNGSTRINGW(IDS_THIS_SKIN)));
  152. CheckDlgButton(wnd, IDC_RADIO_ALLSKINS, !WCSCASEEQLSAFE(type, WASABI_API_LNGSTRINGW(IDS_THIS_SKIN)));
  153. wchar_t scale[64] = {0};
  154. mappingList.GetText(i, 2, scale, 64);
  155. int s = WTOI(scale);
  156. SendMessageW(GetDlgItem(wnd, IDC_SLIDER_SCALE), TBM_SETPOS, 1, s);
  157. SetDlgItemTextW(wnd, IDC_STATIC_SCALE, StringPrintfW(L"%d%%", s));
  158. break;
  159. }
  160. }
  161. EnableWindow(GetDlgItem(wnd, IDC_BUTTON_SET), fm_validMapping(wnd) && fm_hasSelection(wnd));
  162. EnableWindow(GetDlgItem(wnd, IDC_BUTTON_NEW), fm_validMapping(wnd));
  163. EnableWindow(GetDlgItem(wnd, IDC_BUTTON_DEL), fm_hasSelection(wnd));
  164. }
  165. void fm_invalidate()
  166. {
  167. Font::uninstallAll(1);
  168. WASABI_API_WNDMGR->wndTrackInvalidateAll();
  169. }
  170. void fm_scanMapping(HWND ctrl, const wchar_t *id)
  171. {
  172. int global = 0;
  173. wchar_t t[256] = L"";
  174. int scale;
  175. StringW tmp;
  176. tmp.printf(L"Skin:%s/Font Mapping/%s", WASABI_API_SKIN->getSkinName(), id);
  177. WASABI_API_CONFIG->getStringPrivate(tmp, t, 250, L"");
  178. tmp.printf(L"Skin:%s/Font Mapping/%s_scale", WASABI_API_SKIN->getSkinName(), id);
  179. scale = WASABI_API_CONFIG->getIntPrivate(tmp, -1);
  180. if (!*t)
  181. {
  182. global = 1;
  183. tmp.printf(L"Font Mapping/%s", id);
  184. WASABI_API_CONFIG->getStringPrivate(tmp, t, 250, L"");
  185. tmp.printf(L"Skin:%s/Font Mapping/%s_scale", WASABI_API_SKIN->getSkinName(), id);
  186. scale = WASABI_API_CONFIG->getIntPrivate(tmp, -1);
  187. }
  188. if (t && *t)
  189. {
  190. if (!WCSCASESTR(t, L".ttf")) wcscat(t, L".ttf");
  191. font_entry *fe = fontlist_byfilename.findItem(t);
  192. if (fe)
  193. {
  194. int pos = mappingList.InsertItem(0, id, 0);
  195. mappingList.SetItemText(pos, 1, fe->face.getValue());
  196. mappingList.SetItemText(pos, 2, StringPrintfW(L"%d%%", scale != -1 ? scale : 100).getValue());
  197. mappingList.SetItemText(pos, 3, WASABI_API_LNGSTRINGW(global ? IDS_ALL_SKINS : IDS_THIS_SKIN));
  198. }
  199. }
  200. }
  201. void fm_rescanList(HWND lv)
  202. {
  203. mappingList.Clear();
  204. wchar_t t[4096] = L"";
  205. WASABI_API_CONFIG->getStringPrivate(StringPrintfW(L"Skin:%s/Font Mapping/Mapped", WASABI_API_SKIN->getSkinName()), t, 4096, L"");
  206. ParamParser pp(t);
  207. for (int i = 0;i < pp.getNumItems();i++)
  208. {
  209. fm_scanMapping(lv, pp.enumItem(i));
  210. }
  211. WASABI_API_CONFIG->getStringPrivate(L"Font Mapping/Mapped", t, 4096, L"");
  212. ParamParser pp2(t);
  213. for (int i = 0;i < pp2.getNumItems();i++)
  214. {
  215. fm_scanMapping(lv, pp2.enumItem(i));
  216. }
  217. }
  218. void fm_saveMappingLists(HWND wnd)
  219. {
  220. PtrListQuickSorted<StringW, StringWComparator> global_list;
  221. PtrListQuickSorted<StringW, StringWComparator> skin_list;
  222. int n = mappingList.GetCount();
  223. for (int i = 0;i < n;i++)
  224. {
  225. wchar_t txt[4096] = {0};
  226. mappingList.GetText(i, 0, txt, 4096);
  227. wchar_t type[64] = {0};
  228. mappingList.GetText(i, 3, type, 64);
  229. if (!_wcsicmp(type, WASABI_API_LNGSTRINGW(IDS_THIS_SKIN)))
  230. {
  231. if (skin_list.findItem(txt) != NULL) continue;
  232. skin_list.addItem(new StringW(txt));
  233. }
  234. else
  235. {
  236. if (global_list.findItem(txt) != NULL) continue;
  237. global_list.addItem(new StringW(txt));
  238. }
  239. }
  240. StringW s = L"";
  241. foreach(global_list)
  242. if (!s.isempty())
  243. s += L";";
  244. s += global_list.getfor()->getValue();
  245. endfor;
  246. WASABI_API_CONFIG->setStringPrivate(L"Font Mapping/Mapped", s);
  247. s = L"";
  248. foreach(skin_list)
  249. if (!s.isempty()) s += L";";
  250. s += skin_list.getfor()->getValue();
  251. endfor;
  252. WASABI_API_CONFIG->setStringPrivate(StringPrintfW(L"Skin:%s/Font Mapping/Mapped", WASABI_API_SKIN->getSkinName()), s);
  253. global_list.deleteAll();
  254. skin_list.deleteAll();
  255. }
  256. void fm_delMapping(HWND wnd, int pos = -1)
  257. {
  258. HWND list = GetDlgItem(wnd, IDC_LIST_MAPPINGS);
  259. int n = mappingList.GetCount();
  260. int start = 0;
  261. if (pos != -1) { start = pos; n = pos + 1; }
  262. for (int i = start;i < n;i++)
  263. {
  264. if (pos != -1 || mappingList.GetSelected(i))
  265. {
  266. wchar_t txt[4096] = {0};
  267. mappingList.GetText(i, 0, txt, 4096);
  268. wchar_t m[64] = {0};
  269. mappingList.GetText(i, 3, m, 64);
  270. if (WCSCASEEQLSAFE(m, WASABI_API_LNGSTRINGW(IDS_THIS_SKIN)))
  271. {
  272. WASABI_API_CONFIG->setStringPrivate(StringPrintfW(L"Skin:%s/Font Mapping/%s", WASABI_API_SKIN->getSkinName(), txt), L"");
  273. WASABI_API_CONFIG->setStringPrivate(StringPrintfW(L"Skin:%s/Font Mapping/%s_scale", WASABI_API_SKIN->getSkinName(), txt), L"100");
  274. }
  275. else
  276. {
  277. WASABI_API_CONFIG->setStringPrivate(StringPrintfW(L"Font Mapping/%s", txt), L"");
  278. WASABI_API_CONFIG->setStringPrivate(StringPrintfW(L"Font Mapping/%s_scale", txt), L"100");
  279. }
  280. mappingList.DeleteItem(i);
  281. break;
  282. }
  283. }
  284. fm_saveMappingLists(wnd);
  285. fm_rescanList(list);
  286. fm_invalidate();
  287. if (pos == -1)
  288. {
  289. EnableWindow(GetDlgItem(wnd, IDC_BUTTON_DEL), 0);
  290. EnableWindow(GetDlgItem(wnd, IDC_BUTTON_SET), 0);
  291. }
  292. }
  293. void fm_newMapping(HWND wnd)
  294. {
  295. HWND combo1 = GetDlgItem(wnd, IDC_COMBO_SKINFONTS);
  296. HWND combo2 = GetDlgItem(wnd, IDC_COMBO_FONTS);
  297. int global = !IsDlgButtonChecked(wnd, IDC_RADIO_THISSKIN);
  298. int pos = ComboBox_GetCurSel(combo1);
  299. int l = ComboBox_GetLBTextLenW(combo1, pos);
  300. wchar_t *txt = WMALLOC(l + 1);
  301. ComboBox_GetLBTextW(combo1, pos, txt);
  302. if (!*txt)
  303. {
  304. FREE(txt);
  305. return ;
  306. }
  307. wchar_t *delme = txt;
  308. if (*txt == ' ') txt++;
  309. font_entry *fe = skin_fontlist.findItem(txt);
  310. if (!fe) fe = fontlist.findItem(txt);
  311. if (!fe) return ;
  312. FREE(delme);
  313. int n = mappingList.GetCount();
  314. int oldpos = -1;
  315. for (int i = 0;i < n;i++)
  316. {
  317. wchar_t txt[4096] = {0};
  318. mappingList.GetText(i, 0, txt, 4096);
  319. if (!_wcsicmp(fe->face, txt)) { oldpos = i; break; }
  320. }
  321. if (oldpos != -1) fm_delMapping(wnd, oldpos);
  322. pos = ComboBox_GetCurSel(combo2);
  323. l = ComboBox_GetLBTextLenW(combo2, pos);
  324. txt = WMALLOC(l + 1);
  325. ComboBox_GetLBTextW(combo2, pos, txt);
  326. if (!*txt)
  327. {
  328. FREE(txt);
  329. return ;
  330. }
  331. font_entry *femap = fontlist.findItem(txt);
  332. if (!femap) return ;
  333. FREE(txt);
  334. StringW file = femap->filename;
  335. int v = (int)SendMessageW(GetDlgItem(wnd, IDC_SLIDER_SCALE), TBM_GETPOS, 0, 0);
  336. if (!global)
  337. {
  338. WASABI_API_CONFIG->setStringPrivate(StringPrintfW(L"Skin:%s/Font Mapping/%s", WASABI_API_SKIN->getSkinName(), fe->face), file);
  339. WASABI_API_CONFIG->setIntPrivate(StringPrintfW(L"Skin:%s/Font Mapping/%s_scale", WASABI_API_SKIN->getSkinName(), fe->face), v);
  340. }
  341. else
  342. {
  343. WASABI_API_CONFIG->setStringPrivate(StringPrintfW(L"Font Mapping/%s", fe->face), file);
  344. WASABI_API_CONFIG->setIntPrivate(StringPrintfW(L"Font Mapping/%s_scale", fe->face), v);
  345. }
  346. fm_scanMapping(GetDlgItem(wnd, IDC_LIST_MAPPINGS), fe->face);
  347. fm_saveMappingLists(wnd);
  348. fm_invalidate();
  349. if (oldpos == -1)
  350. {
  351. int n = mappingList.GetCount();
  352. for (int i = 0;i < n;i++)
  353. {
  354. wchar_t txt[4096] = {0};
  355. mappingList.GetText(i, 0, txt, 4096);
  356. if (!_wcsicmp(fe->face, txt)) { oldpos = i; break; }
  357. }
  358. }
  359. if (oldpos != -1)
  360. {
  361. mappingList.SetSelected(oldpos);
  362. EnableWindow(GetDlgItem(wnd, IDC_BUTTON_DEL), 1);
  363. EnableWindow(GetDlgItem(wnd, IDC_BUTTON_SET), 1);
  364. }
  365. }
  366. void fm_modifyMapping(HWND wnd)
  367. {
  368. int n = mappingList.GetCount();
  369. int i;
  370. for (i = 0;i < n;i++)
  371. {
  372. if (mappingList.GetSelected(i))
  373. {
  374. wchar_t txt[4096] = {0};
  375. mappingList.GetText(i, 0, txt, 4096);
  376. wchar_t m[64] = {0};
  377. mappingList.GetText(i, 3, m, 64);
  378. if (WCSCASEEQLSAFE(m, WASABI_API_LNGSTRINGW(IDS_THIS_SKIN)))
  379. WASABI_API_CONFIG->setStringPrivate(StringPrintfW(L"Skin:%s/Font Mapping/%s", WASABI_API_SKIN->getSkinName(), txt), L"");
  380. else
  381. WASABI_API_CONFIG->setStringPrivate(StringPrintfW(L"Font Mapping/%s", txt), L"");
  382. mappingList.DeleteItem(i);
  383. break;
  384. }
  385. }
  386. if (i == n) return ;
  387. fm_newMapping(wnd);
  388. mappingList.SetSelected(i);
  389. }
  390. void fillFontList2(HWND list, int reset = 1)
  391. {
  392. if (reset)
  393. ComboBox_ResetContent(list);
  394. int width = 0;
  395. foreach(fontlist)
  396. const wchar_t *str;
  397. int idx = ComboBox_AddStringW(list, (str = fontlist.getfor()->face.v()));
  398. ComboBox_SetItemDataW(list, idx, fontlist.getfor());
  399. width = ResizeComboBoxDropDown(list, 0, str, width);
  400. endfor;
  401. }
  402. void fillSkinFontList(HWND list)
  403. {
  404. ComboBox_ResetContent(list);
  405. SendMessageW(list, CB_INITSTORAGE, 400, 32);
  406. skin_fontlist.deleteAll();
  407. skin_fontlist_byfilename.removeAll();
  408. int n = Font::getNumFontDefs();
  409. for (int i = 0;i < n;i++)
  410. {
  411. FontDef *fd = Font::enumFontDef(i);
  412. if (!fd) continue;
  413. if (!fd->allowmapping) continue;
  414. font_entry *fe = new font_entry;
  415. fe->filename = fd->filename;
  416. fe->face = fd->id;
  417. skin_fontlist.addItem(fe);
  418. skin_fontlist_byfilename.addItem(fe);
  419. int idx = ComboBox_AddStringW(list, StringPrintfW(L" %s", fe->face));
  420. ComboBox_SetItemDataW(list, idx, fe);
  421. }
  422. fillFontList2(list, 0);
  423. }
  424. VOID CALLBACK FontMappingLoader(HWND hwndDlg, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
  425. {
  426. KillTimer(hwndDlg, idEvent);
  427. HWND ctrl = GetDlgItem(hwndDlg, IDC_COMBO_FONTS);
  428. HWND ctrl2 = GetDlgItem(hwndDlg, IDC_COMBO_SKINFONTS);
  429. fillFontList2(ctrl, 1);
  430. fillSkinFontList(ctrl2);
  431. EnableWindow(ctrl, TRUE);
  432. EnableWindow(ctrl2, TRUE);
  433. }
  434. BOOL CALLBACK fontMapperProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  435. {
  436. switch (uMsg)
  437. {
  438. case WM_INITDIALOG:
  439. {
  440. HWND lv = GetDlgItem(hwndDlg, IDC_LIST_MAPPINGS);
  441. mappingList.setwnd(lv);
  442. mappingList.AddCol(WASABI_API_LNGSTRINGW(IDS_FONT), 140);
  443. mappingList.AddCol(WASABI_API_LNGSTRINGW(IDS_MAPPING), 139);
  444. mappingList.AddCol(WASABI_API_LNGSTRINGW(IDS_SCALE), 48);
  445. mappingList.AddCol(WASABI_API_LNGSTRINGW(IDS_TYPE), 64);
  446. HWND ctrl = GetDlgItem(hwndDlg, IDC_COMBO_FONTS);
  447. ComboBox_AddStringW(ctrl, WASABI_API_LNGSTRINGW(IDS_LOADING));
  448. ComboBox_SetCurSel(ctrl, 0);
  449. EnableWindow(ctrl, FALSE);
  450. ctrl = GetDlgItem(hwndDlg, IDC_COMBO_SKINFONTS);
  451. ComboBox_AddStringW(ctrl, WASABI_API_LNGSTRINGW(IDS_LOADING));
  452. ComboBox_SetCurSel(ctrl, 0);
  453. EnableWindow(ctrl, FALSE);
  454. SetTimer(hwndDlg, 0xC0DF, 1, FontMappingLoader);
  455. fm_rescanList(lv);
  456. CheckDlgButton(hwndDlg, IDC_RADIO_THISSKIN, 1);
  457. EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_DEL), 0);
  458. EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_NEW), 0);
  459. EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_SET), 0);
  460. SendMessageW(GetDlgItem(hwndDlg, IDC_SLIDER_SCALE), TBM_SETRANGEMAX, 0, 200);
  461. SendMessageW(GetDlgItem(hwndDlg, IDC_SLIDER_SCALE), TBM_SETRANGEMIN, 0, 25);
  462. SendMessageW(GetDlgItem(hwndDlg, IDC_SLIDER_SCALE), TBM_SETPOS, 1, 100);
  463. return 1;
  464. }
  465. case WM_COMMAND:
  466. switch (LOWORD(wParam))
  467. {
  468. case IDCANCEL:
  469. EndDialog(hwndDlg, 0);
  470. return 0;
  471. case IDOK:
  472. EndDialog(hwndDlg, 1);
  473. return 0;
  474. case IDC_BUTTON_NEW:
  475. fm_newMapping(hwndDlg);
  476. return 0;
  477. case IDC_BUTTON_DEL:
  478. fm_delMapping(hwndDlg);
  479. return 0;
  480. case IDC_BUTTON_SET:
  481. fm_modifyMapping(hwndDlg);
  482. return 0;
  483. case IDC_COMBO_FONTS:
  484. case IDC_COMBO_SKINFONTS:
  485. EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_SET), fm_validMapping(hwndDlg) && fm_hasSelection(hwndDlg));
  486. EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_NEW), fm_validMapping(hwndDlg));
  487. return 0;
  488. }
  489. case WM_HSCROLL:
  490. {
  491. if ((HWND) lParam == GetDlgItem(hwndDlg, IDC_SLIDER_SCALE))
  492. {
  493. int t = (int)SendMessageW(GetDlgItem(hwndDlg, IDC_SLIDER_SCALE), TBM_GETPOS, 0, 0);
  494. SetDlgItemTextA(hwndDlg, IDC_STATIC_SCALE, StringPrintf("%d%%", t));
  495. return 0;
  496. }
  497. break;
  498. }
  499. case WM_NOTIFY:
  500. {
  501. int ctrl = (int)wParam;
  502. NMHDR *pnmh = (NMHDR*)lParam;
  503. if (ctrl == IDC_LIST_MAPPINGS)
  504. {
  505. if (pnmh->code == NM_CLICK)
  506. {
  507. NMLISTVIEW *nml = (NMLISTVIEW*)lParam;
  508. fm_itemClicked(hwndDlg, nml->iItem);
  509. break;
  510. }
  511. }
  512. }
  513. }
  514. const int controls[] =
  515. {
  516. IDC_SLIDER_SCALE,
  517. };
  518. if (FALSE != WASABI_API_APP->DirectMouseWheel_ProcessDialogMessage(hwndDlg, uMsg, wParam, lParam, controls, ARRAYSIZE(controls)))
  519. return TRUE;
  520. return 0;
  521. }
  522. void updateBFReplacement(HWND hwndDlg)
  523. {
  524. int replace = !IsDlgButtonChecked(hwndDlg, IDC_CHECK_ALLOWBITMAPFONTS);
  525. EnableWindow(GetDlgItem(hwndDlg, IDC_COMBO_TTFOVERRIDE), (replace && fonts_loaded));
  526. EnableWindow(GetDlgItem(hwndDlg, IDC_SLIDER_SCALETTFOVERRIDE), replace);
  527. EnableWindow(GetDlgItem(hwndDlg, IDC_STATIC_DECREASESIZE), replace);
  528. EnableWindow(GetDlgItem(hwndDlg, IDC_STATIC_TTFSCALE), replace);
  529. EnableWindow(GetDlgItem(hwndDlg, IDC_STATIC_INCREASESIZE), replace);
  530. EnableWindow(GetDlgItem(hwndDlg, IDC_NO_7BIT_OVERRIDE), replace);
  531. }
  532. void updateFreetypeVisible(HWND hwndDlg)
  533. {
  534. if (!IsDlgButtonChecked(hwndDlg, IDC_CHECK_FREETYPETTF))
  535. {
  536. EnableWindow(GetDlgItem(hwndDlg, IDC_STATIC_CHARMAP), FALSE);
  537. EnableWindow(GetDlgItem(hwndDlg, IDC_COMBO_CHARMAP), FALSE);
  538. }
  539. else
  540. {
  541. EnableWindow(GetDlgItem(hwndDlg, IDC_STATIC_CHARMAP), TRUE);
  542. EnableWindow(GetDlgItem(hwndDlg, IDC_COMBO_CHARMAP), TRUE);
  543. }
  544. }
  545. void updateAltFontsVisible(HWND hwndDlg)
  546. {
  547. if (!IsDlgButtonChecked(hwndDlg, IDC_CHECK_ALTFONTS))
  548. {
  549. EnableWindow(GetDlgItem(hwndDlg, IDC_CHECK_NO_ALT_7BIT_OVERRIDE), FALSE);
  550. }
  551. else
  552. {
  553. EnableWindow(GetDlgItem(hwndDlg, IDC_CHECK_NO_ALT_7BIT_OVERRIDE), TRUE);
  554. }
  555. }
  556. // {504060F6-7D8C-4ebe-AE1D-A8BDF5EA1881}
  557. static const GUID freetypeFontRendererGUID =
  558. { 0x504060f6, 0x7d8c, 0x4ebe, { 0xae, 0x1d, 0xa8, 0xbd, 0xf5, 0xea, 0x18, 0x81 } };
  559. VOID CALLBACK FontLoader(HWND hwndDlg, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
  560. {
  561. KillTimer(hwndDlg, idEvent);
  562. HWND ctrl = GetDlgItem(hwndDlg, IDC_COMBO_TTFOVERRIDE);
  563. HWND ctrl2 = GetDlgItem(hwndDlg, IDC_COMBO_DEFAULTFONT);
  564. fillFontLists(ctrl, ctrl2);
  565. int pos = -1;
  566. font_entry *fe = fontlist_byfilename.findItem(cfg_options_ttfoverridefont.getValue(), NULL);
  567. if (fe)
  568. {
  569. fontlist.sort(1);
  570. pos = fontlist.searchItem(fe);
  571. }
  572. ComboBox_SetCurSel(ctrl, pos);
  573. pos = -1;
  574. fe = fontlist_byfilename.findItem(cfg_options_defaultfont.getValue(), NULL);
  575. if (fe)
  576. {
  577. fontlist.sort(1);
  578. pos = fontlist.searchItem(fe);
  579. }
  580. ComboBox_SetCurSel(ctrl2, pos);
  581. EnableWindow(ctrl, (!IsDlgButtonChecked(hwndDlg, IDC_CHECK_ALLOWBITMAPFONTS)));
  582. EnableWindow(ctrl2, TRUE);
  583. EnableWindow(ctrl2, TRUE);
  584. fonts_loaded = 1;
  585. }
  586. INT_PTR CALLBACK ffPrefsProc2(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  587. {
  588. switch (uMsg)
  589. {
  590. case WM_INITDIALOG:
  591. {
  592. fonts_loaded = 0;
  593. CheckDlgButton(hwndDlg, IDC_CHECK_ALLOWBITMAPFONTS, cfg_options_allowbitmapfonts.getValueAsInt());
  594. CheckDlgButton(hwndDlg, IDC_CHECK_ALTFONTS, cfg_options_altfonts.getValueAsInt());
  595. // delay the loading of the font lists until after the dialog has loaded to improve ui response
  596. HWND ctrl = GetDlgItem(hwndDlg, IDC_COMBO_TTFOVERRIDE);
  597. ComboBox_AddStringW(ctrl, WASABI_API_LNGSTRINGW(IDS_LOADING));
  598. ComboBox_SetCurSel(ctrl, 0);
  599. EnableWindow(ctrl, FALSE);
  600. ctrl = GetDlgItem(hwndDlg, IDC_COMBO_DEFAULTFONT);
  601. ComboBox_AddStringW(ctrl, WASABI_API_LNGSTRINGW(IDS_LOADING));
  602. ComboBox_SetCurSel(ctrl, 0);
  603. EnableWindow(ctrl, FALSE);
  604. SetTimer(hwndDlg, 0xC0DE, 1, FontLoader);
  605. SendMessageW(GetDlgItem(hwndDlg, IDC_SLIDER_SCALETTFOVERRIDE), TBM_SETRANGEMAX, 0, 200);
  606. SendMessageW(GetDlgItem(hwndDlg, IDC_SLIDER_SCALETTFOVERRIDE), TBM_SETRANGEMIN, 0, 25);
  607. SendMessageW(GetDlgItem(hwndDlg, IDC_SLIDER_SCALETTFOVERRIDE), TBM_SETPOS, 1, cfg_options_ttfoverridescale.getValueAsInt());
  608. SetDlgItemTextA(hwndDlg, IDC_STATIC_TTFSCALE, StringPrintf("%d%%", cfg_options_ttfoverridescale.getValueAsInt()));
  609. SendMessageW(GetDlgItem(hwndDlg, IDC_SLIDER_SCALEDEFAULTFONT), TBM_SETRANGEMAX, 0, 200);
  610. SendMessageW(GetDlgItem(hwndDlg, IDC_SLIDER_SCALEDEFAULTFONT), TBM_SETRANGEMIN, 0, 25);
  611. SendMessageW(GetDlgItem(hwndDlg, IDC_SLIDER_SCALEDEFAULTFONT), TBM_SETPOS, 1, cfg_options_defaultfontscale.getValueAsInt());
  612. SetDlgItemTextA(hwndDlg, IDC_STATIC_SCALEDEFAULTFONT, StringPrintf("%d%%", cfg_options_defaultfontscale.getValueAsInt()));
  613. HWND charmaps = GetDlgItem(hwndDlg, IDC_COMBO_CHARMAP);
  614. if (WASABI_API_SVC->service_getServiceByGuid(freetypeFontRendererGUID) == 0) // no freetype
  615. {
  616. EnableWindow(GetDlgItem(hwndDlg, IDC_STATIC_FREETYPE), FALSE);
  617. EnableWindow(GetDlgItem(hwndDlg, IDC_CHECK_FREETYPETTF), FALSE);
  618. EnableWindow(charmaps, FALSE);
  619. }
  620. else
  621. {
  622. const wchar_t *v = cfg_options_fontrenderer.getValue();
  623. CheckDlgButton(hwndDlg, IDC_CHECK_FREETYPETTF, WCSCASEEQLSAFE(v, L"FreeType"));
  624. ComboBox_AddStringW(charmaps, WASABI_API_LNGSTRINGW(IDS_AUTO_UNICODE_LATIN1_ASCII));
  625. ComboBox_AddStringW(charmaps, L"Unicode");
  626. ComboBox_AddStringW(charmaps, L"Apple Roman");
  627. ComboBox_AddStringW(charmaps, L"Adobe Latin-1");
  628. ComboBox_AddStringW(charmaps, L"Adobe Standard");
  629. ComboBox_AddStringW(charmaps, L"Adobe Custom");
  630. ComboBox_AddStringW(charmaps, L"Adobe Expert");
  631. ComboBox_AddStringW(charmaps, L"SJIS");
  632. ComboBox_AddStringW(charmaps, L"Big5");
  633. ComboBox_AddStringW(charmaps, L"Wansung");
  634. ComboBox_AddStringW(charmaps, L"Johab");
  635. ComboBox_SetCurSel(charmaps, cfg_options_freetypecharmap.getValueAsInt() + 1);
  636. }
  637. CheckDlgButton(hwndDlg, IDC_NO_7BIT_OVERRIDE, cfg_options_no7bitsttfoverride.getValueAsInt());
  638. CheckDlgButton(hwndDlg, IDC_CHECK_NO_ALT_7BIT_OVERRIDE, cfg_options_noalt7bitsttfoverride.getValueAsInt());
  639. updateBFReplacement(hwndDlg);
  640. updateFreetypeVisible(hwndDlg);
  641. updateAltFontsVisible(hwndDlg);
  642. EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_FONTMAPPER), cfg_options_usefontmapper.getValueAsInt());
  643. CheckDlgButton(hwndDlg, IDC_CHECK_USEFONTMAPPER, cfg_options_usefontmapper.getValueAsInt());
  644. return 1;
  645. }
  646. case WM_COMMAND:
  647. {
  648. int id = (int) LOWORD(wParam);
  649. int msg = (int)HIWORD(wParam);
  650. switch (id)
  651. {
  652. case IDC_CHECK_ALLOWBITMAPFONTS:
  653. updateBFReplacement(hwndDlg);
  654. cfg_options_allowbitmapfonts.setValueAsInt(IsDlgButtonChecked(hwndDlg, IDC_CHECK_ALLOWBITMAPFONTS));
  655. return 0;
  656. case IDC_CHECK_ALTFONTS:
  657. updateAltFontsVisible(hwndDlg);
  658. cfg_options_altfonts.setValueAsInt(IsDlgButtonChecked(hwndDlg, IDC_CHECK_ALTFONTS));
  659. return 0;
  660. case IDC_CHECK_FREETYPETTF:
  661. updateFreetypeVisible(hwndDlg);
  662. if (!IsDlgButtonChecked(hwndDlg, IDC_CHECK_FREETYPETTF))
  663. cfg_options_fontrenderer.setValue(L"Win32 TextOut");
  664. else
  665. cfg_options_fontrenderer.setValue(L"FreeType");
  666. return 0;
  667. case IDC_NO_7BIT_OVERRIDE:
  668. cfg_options_no7bitsttfoverride.setValueAsInt(IsDlgButtonChecked(hwndDlg, IDC_NO_7BIT_OVERRIDE));
  669. return 0;
  670. case IDC_CHECK_NO_ALT_7BIT_OVERRIDE:
  671. cfg_options_noalt7bitsttfoverride.setValueAsInt(IsDlgButtonChecked(hwndDlg, IDC_CHECK_NO_ALT_7BIT_OVERRIDE));
  672. return 0;
  673. case IDC_BUTTON_FONTMAPPER:
  674. WASABI_API_DIALOGBOXW(IDD_FONTMAPPER, hwndDlg, fontMapperProc);
  675. return 0;
  676. case IDC_CHECK_USEFONTMAPPER:
  677. cfg_options_usefontmapper.setValueAsInt(IsDlgButtonChecked(hwndDlg, IDC_CHECK_USEFONTMAPPER));
  678. EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_FONTMAPPER), cfg_options_usefontmapper.getValueAsInt());
  679. return 0;
  680. case IDC_COMBO_TTFOVERRIDE:
  681. {
  682. if (msg == CBN_SELCHANGE)
  683. {
  684. HWND list = GetDlgItem(hwndDlg, IDC_COMBO_TTFOVERRIDE);
  685. int idx = ComboBox_GetCurSel(list);
  686. if (idx != -1)
  687. {
  688. font_entry *fe = (font_entry *)ComboBox_GetItemData(list, idx);
  689. if (fe && fontlist.haveItem(fe))
  690. {
  691. cfg_options_ttfoverridefont.setValue(fe->filename);
  692. }
  693. }
  694. return 0;
  695. }
  696. }
  697. case IDC_COMBO_DEFAULTFONT:
  698. {
  699. if (msg == CBN_SELCHANGE)
  700. {
  701. HWND list = GetDlgItem(hwndDlg, IDC_COMBO_DEFAULTFONT);
  702. int idx = ComboBox_GetCurSel(list);
  703. if (idx != -1)
  704. {
  705. font_entry *fe = (font_entry *)ComboBox_GetItemData(list, idx);
  706. if (fe && fontlist.haveItem(fe))
  707. {
  708. cfg_options_defaultfont.setValue(fe->filename);
  709. }
  710. }
  711. return 0;
  712. }
  713. }
  714. case IDC_COMBO_CHARMAP:
  715. {
  716. if (msg == CBN_SELCHANGE)
  717. {
  718. int idx = ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_COMBO_CHARMAP));
  719. if (idx >= 0)
  720. {
  721. cfg_options_freetypecharmap.setValueAsInt(idx - 1);
  722. }
  723. return 0;
  724. }
  725. }
  726. }
  727. break;
  728. }
  729. case WM_HSCROLL:
  730. {
  731. if ((HWND) lParam == GetDlgItem(hwndDlg, IDC_SLIDER_SCALETTFOVERRIDE))
  732. {
  733. int t = (int)SendMessageW((HWND)lParam, TBM_GETPOS, 0, 0);
  734. SetDlgItemTextA(hwndDlg, IDC_STATIC_TTFSCALE, StringPrintf("%d%%", t));
  735. SetTimer(hwndDlg, 100, 100, NULL);
  736. return 0;
  737. }
  738. if ((HWND) lParam == GetDlgItem(hwndDlg, IDC_SLIDER_SCALEDEFAULTFONT))
  739. {
  740. int t = (int)SendMessageW((HWND)lParam, TBM_GETPOS, 0, 0);
  741. SetDlgItemTextA(hwndDlg, IDC_STATIC_SCALEDEFAULTFONT, StringPrintf("%d%%", t));
  742. SetTimer(hwndDlg, 101, 100, NULL);
  743. return 0;
  744. }
  745. break;
  746. }
  747. case WM_TIMER:
  748. {
  749. if (wParam == 100)
  750. {
  751. KillTimer(hwndDlg, 100);
  752. int t = (int)SendMessageW(GetDlgItem(hwndDlg, IDC_SLIDER_SCALETTFOVERRIDE), TBM_GETPOS, 0, 0);
  753. cfg_options_ttfoverridescale.setValueAsInt(t);
  754. }
  755. else if (wParam == 101)
  756. {
  757. KillTimer(hwndDlg, 101);
  758. int t = (int)SendMessageW(GetDlgItem(hwndDlg, IDC_SLIDER_SCALEDEFAULTFONT), TBM_GETPOS, 0, 0);
  759. cfg_options_defaultfontscale.setValueAsInt(t);
  760. }
  761. return 0;
  762. }
  763. case WM_DESTROY:
  764. subWnd = NULL;
  765. return 0;
  766. }
  767. const int controls[] =
  768. {
  769. IDC_SLIDER_SCALETTFOVERRIDE,
  770. IDC_SLIDER_SCALEDEFAULTFONT,
  771. };
  772. if (FALSE != WASABI_API_APP->DirectMouseWheel_ProcessDialogMessage(hwndDlg, uMsg, wParam, lParam, controls, ARRAYSIZE(controls)))
  773. return TRUE;
  774. return 0;
  775. }