options_vis.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. /** (c) Nullsoft, Inc. C O N F I D E N T I A L
  2. ** Filename:
  3. ** Project:
  4. ** Description:
  5. ** Author:
  6. ** Created:
  7. **/
  8. #include "Main.h"
  9. #include "resource.h"
  10. #include "Options.h"
  11. #include "vis.h"
  12. #include "main.hpp"
  13. #include "../nu/AutoChar.h"
  14. #include "../nu/AutoWide.h"
  15. static void VisUpdateSel(HWND hwndDlg, HWND listWindow, INT iItem)
  16. {
  17. if (ListView_GetNextItem(listWindow, -1, LVIS_SELECTED) != -1)
  18. {
  19. wchar_t fn[FILENAME_SIZE] = {0}, b[1024] = {0}, namestr[MAX_PATH] = {0};
  20. ListView_GetItemTextW(listWindow, iItem, 1, fn, ARRAYSIZE(fn));
  21. if (wcscmp(config_visplugin_name, fn))
  22. config_visplugin_num = 0;
  23. StringCchCopyW(config_visplugin_name, MAX_PATH, fn);
  24. SendDlgItemMessageA(hwndDlg,IDC_VISMOD,CB_RESETCONTENT,0,0);
  25. PathCombineW(b, VISDIR, fn);
  26. HINSTANCE hLib = LoadLibraryW(b);
  27. if (hLib)
  28. {
  29. winampVisGetHeaderType pr = (winampVisGetHeaderType) GetProcAddress(hLib,"winampVisGetHeader");
  30. if (pr)
  31. {
  32. for(int i = 0;;)
  33. {
  34. winampVisModule *l_module = pr(hMainWindow)->getModule(i++);
  35. if (!l_module )
  36. break;
  37. SendDlgItemMessageA(hwndDlg, IDC_VISMOD, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)l_module->description);
  38. }
  39. ListView_DeleteItem(listWindow, iItem);
  40. StringCchCopyW(namestr, MAX_PATH, AutoWide(pr(hMainWindow)->description));
  41. LVITEMW lvi = {LVIF_TEXT, 0, 0};
  42. lvi.pszText = namestr;
  43. lvi.iItem = ListView_InsertItemW(listWindow, &lvi);
  44. lvi.mask = LVIF_TEXT;
  45. lvi.iSubItem = 1;
  46. lvi.pszText = fn;
  47. ListView_SetItemW(listWindow, &lvi);
  48. ListView_SetItemState(listWindow, lvi.iItem, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  49. }
  50. FreeModule(hLib);
  51. }
  52. }
  53. int count = SendDlgItemMessageA(hwndDlg, IDC_VISMOD, CB_GETCOUNT, 0, 0);
  54. SendDlgItemMessageA(hwndDlg, IDC_VISMOD, CB_SETCURSEL, (config_visplugin_num < count ? config_visplugin_num : (config_visplugin_num = 0)), 0);
  55. }
  56. // vis tab procedure
  57. static bool pluginsLoaded;
  58. INT_PTR CALLBACK VisProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  59. {
  60. hi helpinfo[]={
  61. {IDC_VISLIB,IDS_P_VIS_LIB},
  62. {IDC_VISMOD,IDS_P_VIS_MOD},
  63. {IDC_VISCONF,IDS_P_VIS_CONF},
  64. {IDC_VISSTOP,IDS_P_VIS_STOP},
  65. {IDC_VISTEST,IDS_P_VIS_START},
  66. {IDC_UNINSTVIS,IDS_P_VIS_UNINST},
  67. };
  68. DO_HELP();
  69. if (uMsg == WM_INITDIALOG)
  70. {
  71. pluginsLoaded = false;
  72. link_startsubclass(hwndDlg, IDC_PLUGINVERS);
  73. HWND listWindow = GetDlgItem(hwndDlg, IDC_VISLIB);
  74. if (IsWindow(listWindow))
  75. {
  76. RECT r = {0}, rc = {0};
  77. GetWindowRect(listWindow, &r);
  78. GetClientRect(listWindow, &r);
  79. MapWindowPoints(listWindow, hwndDlg, (LPPOINT)&r, 2);
  80. InflateRect(&r, 2, 2);
  81. DestroyWindow(listWindow);
  82. listWindow = CreateWindowExW(WS_EX_NOPARENTNOTIFY | WS_EX_CLIENTEDGE, WC_LISTVIEWW, L"",
  83. WS_CHILD | WS_VISIBLE | WS_TABSTOP | LVS_REPORT | LVS_SINGLESEL |
  84. LVS_SHOWSELALWAYS | LVS_SORTASCENDING | LVS_NOCOLUMNHEADER | LVS_NOSORTHEADER,
  85. r.left, r.top, r.right - r.left, r.bottom - r.top,
  86. hwndDlg, (HMENU)IDC_VISLIB, NULL, NULL);
  87. SetWindowPos(listWindow, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  88. ListView_SetExtendedListViewStyleEx(listWindow, LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP, LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP);
  89. SendMessageW(listWindow, WM_SETFONT, SendMessageW(hwndDlg, WM_GETFONT, 0, 0), FALSE);
  90. LVCOLUMNW lvc = {0};
  91. ListView_InsertColumnW(listWindow, 0, &lvc);
  92. ListView_InsertColumnW(listWindow, 1, &lvc);
  93. WIN32_FIND_DATAW d = {0};
  94. wchar_t dirstr[MAX_PATH+128] = {0};
  95. PathCombineW(dirstr,VISDIR,L"*.DLL");
  96. HANDLE h = FindFirstFileW(dirstr,&d);
  97. if (h != INVALID_HANDLE_VALUE)
  98. {
  99. do
  100. {
  101. if (_wcsnicmp(d.cFileName,L"dsp_",4)
  102. && _wcsnicmp(d.cFileName,L"in_",3)
  103. && _wcsnicmp(d.cFileName,L"gen_",4)
  104. && _wcsnicmp(d.cFileName,L"ml_",3)
  105. && _wcsnicmp(d.cFileName,L"enc_",4)
  106. && _wcsnicmp(d.cFileName,L"CDDB",4)
  107. && _wcsnicmp(d.cFileName,L"out_",4)
  108. && _wcsnicmp(d.cFileName, L"pmp_", 4))
  109. {
  110. wchar_t b[1024] = {0}, namestr[MAX_PATH] = {0};
  111. PathCombineW(b, VISDIR, d.cFileName);
  112. HINSTANCE hLib = LoadLibrary(b);
  113. if (hLib)
  114. {
  115. winampVisGetHeaderType pr = (winampVisGetHeaderType) GetProcAddress(hLib,"winampVisGetHeader");
  116. if (pr)
  117. {
  118. if (!g_safeMode)
  119. {
  120. winampVisHeader* pv = pr(hMainWindow);
  121. if (pv)
  122. {
  123. StringCchCopyW(namestr,MAX_PATH+256,AutoWide(pv->description));
  124. }
  125. else
  126. {
  127. StringCchCopyW(namestr,MAX_PATH+256,L"!");
  128. }
  129. }
  130. }
  131. else
  132. {
  133. StringCchCopyW(namestr,MAX_PATH+256,L"!");
  134. }
  135. FreeModule(hLib);
  136. }
  137. else
  138. {
  139. StringCchCopyW(namestr,MAX_PATH+256,L"!");
  140. }
  141. if (wcscmp(namestr,L"!"))
  142. {
  143. LVITEMW lvi = {LVIF_TEXT, 0, 0};
  144. lvi.pszText = namestr;
  145. lvi.iItem = ListView_InsertItemW(listWindow, &lvi);
  146. lvi.mask = LVIF_TEXT;
  147. lvi.iSubItem = 1;
  148. lvi.pszText = d.cFileName;
  149. ListView_SetItemW(listWindow, &lvi);
  150. if (!_wcsicmp(d.cFileName, config_visplugin_name))
  151. {
  152. ListView_SetItemState(listWindow, lvi.iItem, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  153. VisUpdateSel(hwndDlg, listWindow, lvi.iItem);
  154. }
  155. }
  156. }
  157. } while (FindNextFileW(h,&d));
  158. FindClose(h);
  159. }
  160. // [5.55+] only send this to correct the page state if we have no valid vis plugins available and loaded
  161. if(!ListView_GetItemCount(listWindow) ||
  162. (ListView_GetNextItem(listWindow, -1, LVIS_SELECTED) == -1) ||
  163. g_safeMode || !config_visplugin_name[0])
  164. {
  165. VisUpdateSel(hwndDlg, listWindow, -1);
  166. int enable = (ListView_GetSelectionMark(listWindow) != -1);
  167. EnableWindow(GetDlgItem(hwndDlg,IDC_VISTEST),enable);
  168. EnableWindow(GetDlgItem(hwndDlg,IDC_VISSTOP),enable);
  169. EnableWindow(GetDlgItem(hwndDlg,IDC_VISCONF),enable);
  170. EnableWindow(GetDlgItem(hwndDlg,IDC_UNINSTVIS),enable);
  171. EnableWindow(GetDlgItem(hwndDlg,IDC_VISMOD),enable);
  172. }
  173. GetClientRect(listWindow, &r);
  174. ListView_SetColumnWidth(listWindow, 1, LVSCW_AUTOSIZE);
  175. ListView_SetColumnWidth(listWindow, 0, (r.right - r.left) - ListView_GetColumnWidth(listWindow, 1));
  176. DirectMouseWheel_EnableConvertToMouseWheel(listWindow, TRUE);
  177. pluginsLoaded = true;
  178. }
  179. }
  180. else if (uMsg == WM_DESTROY)
  181. {
  182. HWND listWindow = GetDlgItem(hwndDlg, IDC_VISLIB);
  183. if (IsWindow(listWindow))
  184. DirectMouseWheel_EnableConvertToMouseWheel(listWindow, FALSE);
  185. }
  186. else if (uMsg == WM_NOTIFY)
  187. {
  188. static int own_update;
  189. LPNMHDR p = (LPNMHDR)lParam;
  190. if (p->idFrom == IDC_VISLIB)
  191. {
  192. if (p->code == LVN_ITEMCHANGED && pluginsLoaded && !own_update)
  193. {
  194. if (!g_safeMode)
  195. {
  196. LPNMLISTVIEW pnmv = (LPNMLISTVIEW)lParam;
  197. LVITEM lvi = {LVIF_PARAM, pnmv->iItem};
  198. if (ListView_GetItem(p->hwndFrom, &lvi) && (pnmv->uNewState & LVIS_SELECTED))
  199. {
  200. own_update = 1;
  201. VisUpdateSel(hwndDlg, p->hwndFrom, pnmv->iItem);
  202. own_update = 0;
  203. }
  204. }
  205. int enable = (ListView_GetSelectionMark(p->hwndFrom) != -1);
  206. EnableWindow(GetDlgItem(hwndDlg,IDC_VISTEST),enable);
  207. EnableWindow(GetDlgItem(hwndDlg,IDC_VISSTOP),enable);
  208. EnableWindow(GetDlgItem(hwndDlg,IDC_VISCONF),enable);
  209. EnableWindow(GetDlgItem(hwndDlg,IDC_UNINSTVIS),enable);
  210. EnableWindow(GetDlgItem(hwndDlg,IDC_VISMOD),enable);
  211. }
  212. else if (p->code == NM_DBLCLK || p->code == NM_CLICK)
  213. {
  214. // helps to keep the selection on things...
  215. LPNMITEMACTIVATE lpnmitem = (LPNMITEMACTIVATE)lParam;
  216. if (lpnmitem->iItem == -1)
  217. {
  218. int which = ListView_GetNextItem(p->hwndFrom, -1, LVIS_SELECTED);
  219. if (which == -1)
  220. {
  221. for (int i = 0; i < ListView_GetItemCount(p->hwndFrom); i++)
  222. {
  223. wchar_t fn[MAX_PATH*2] = {0};
  224. ListView_GetItemTextW(p->hwndFrom, i, 1, fn, ARRAYSIZE(fn));
  225. if (!_wcsicmp(fn, config_visplugin_name))
  226. {
  227. ListView_SetItemState(p->hwndFrom, i, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  228. break;
  229. }
  230. }
  231. }
  232. else ListView_SetItemState(p->hwndFrom, which, LVIS_SELECTED, LVIS_SELECTED);
  233. }
  234. if (p->code == NM_DBLCLK)
  235. {
  236. PostMessageW(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_VISTEST, 0), (LPARAM)GetDlgItem(hwndDlg, IDC_VISTEST));
  237. }
  238. }
  239. }
  240. else if (p->code == HDN_ITEMCHANGINGW)
  241. {
  242. if (pluginsLoaded)
  243. {
  244. #ifdef WIN64
  245. SetWindowLongPtrW(hwndDlg, DWLP_MSGRESULT, TRUE);
  246. #else
  247. SetWindowLong(hwndDlg, DWL_MSGRESULT, TRUE);
  248. #endif
  249. return TRUE;
  250. }
  251. }
  252. }
  253. else if (uMsg == WM_COMMAND)
  254. {
  255. switch (LOWORD(wParam))
  256. {
  257. case IDC_VISMOD:
  258. if (HIWORD(wParam) == CBN_SELCHANGE)
  259. {
  260. config_visplugin_num = (unsigned char) SendDlgItemMessageA(hwndDlg,IDC_VISMOD,CB_GETCURSEL,0,0);
  261. if (config_visplugin_num == CB_ERR)
  262. config_visplugin_num = 0;
  263. }
  264. return FALSE;
  265. case IDC_VISCONF:
  266. {
  267. if (IsWindowEnabled(GetDlgItem(hwndDlg, IDC_VISCONF)))
  268. {
  269. HWND listWindow = GetDlgItem(hwndDlg, IDC_VISLIB);
  270. int which = ListView_GetNextItem(listWindow, -1, LVIS_SELECTED);
  271. if (which >= 0 && which < ListView_GetItemCount(listWindow))
  272. {
  273. wchar_t b[MAX_PATH] = {0}, fn[MAX_PATH*2] = {0};
  274. ListView_GetItemTextW(listWindow, which, 1, fn, ARRAYSIZE(fn));
  275. PathCombineW(b, VISDIR, fn);
  276. HINSTANCE hLib = LoadLibraryW(b);
  277. if (hLib)
  278. {
  279. winampVisGetHeaderType pr = (winampVisGetHeaderType) GetProcAddress(hLib,"winampVisGetHeader");
  280. winampVisModule *module = pr(hMainWindow)->getModule(SendDlgItemMessageA(hwndDlg,IDC_VISMOD,CB_GETCURSEL,0,0));
  281. if (module)
  282. {
  283. module->hDllInstance = hLib;
  284. module->hwndParent = hMainWindow;
  285. if (!(config_no_visseh&1))
  286. {
  287. try {
  288. module->Config(module);
  289. }
  290. catch(...)
  291. {
  292. LPMessageBox(hwndDlg, IDS_PLUGINERROR, IDS_ERROR, MB_OK|MB_ICONEXCLAMATION);
  293. }
  294. }
  295. else
  296. {
  297. module->Config(module);
  298. }
  299. }
  300. else
  301. {
  302. LPMessageBox(hwndDlg, IDS_ERRORLOADINGPLUGIN, IDS_ERROR, MB_OK);
  303. }
  304. FreeLibrary(hLib);
  305. }
  306. else
  307. {
  308. LPMessageBox(hwndDlg, IDS_ERRORLOADINGPLUGIN, IDS_ERROR, MB_OK);
  309. }
  310. }
  311. }
  312. }
  313. return FALSE;
  314. case IDC_VISSTOP:
  315. {
  316. vis_stop();
  317. }
  318. return FALSE;
  319. case IDC_VISTEST:
  320. {
  321. if (IsWindowEnabled(GetDlgItem(hwndDlg, IDC_VISTEST)))
  322. {
  323. HWND listWindow = GetDlgItem(hwndDlg, IDC_VISLIB);
  324. int which = ListView_GetNextItem(listWindow, -1, LVIS_SELECTED);
  325. if (which >= 0 && which < ListView_GetItemCount(listWindow))
  326. {
  327. wchar_t fn[MAX_PATH] = {0};
  328. ListView_GetItemTextW(listWindow, which, 1, fn, ARRAYSIZE(fn));
  329. StringCchCopyW(config_visplugin_name, MAX_PATH, fn);
  330. config_visplugin_num = (unsigned char)SendDlgItemMessageA(hwndDlg, IDC_VISMOD, CB_GETCURSEL, 0, 0);
  331. }
  332. }
  333. vis_start(hMainWindow,NULL);
  334. }
  335. return FALSE;
  336. case IDC_UNINSTVIS:
  337. vis_stop();
  338. {
  339. if (IsWindowEnabled(GetDlgItem(hwndDlg, IDC_UNINSTVIS)))
  340. {
  341. HWND listWindow = GetDlgItem(hwndDlg, IDC_VISLIB);
  342. int which = ListView_GetNextItem(listWindow, -1, LVIS_SELECTED);
  343. wchar_t b[MAX_PATH] = {0}, fn[FILENAME_SIZE] = {0};
  344. ListView_GetItemTextW(listWindow, which, 1, fn, ARRAYSIZE(fn));
  345. PathCombineW(b, VISDIR, fn);
  346. HINSTANCE hLib = LoadLibraryW(b);
  347. if (hLib)
  348. {
  349. wchar_t buf[MAX_PATH] = {0};
  350. GetModuleFileNameW(hLib, buf, MAX_PATH);
  351. int ret=0;
  352. int (*pr)
  353. (HINSTANCE hDllInst, HWND hwndDlg, int param);
  354. *(void**)&pr = (void*)GetProcAddress(hLib,"winampUninstallPlugin");
  355. if (pr)
  356. ret=pr(hLib,hwndDlg,0);
  357. FreeLibrary(hLib);
  358. if (!ret)
  359. {
  360. IFileTypeRegistrar *registrar=0;
  361. if (GetRegistrar(&registrar, true) == 0 && registrar)
  362. {
  363. if (registrar->DeleteItem(buf) != S_OK)
  364. {
  365. _w_sW("remove_genplug", buf);
  366. _w_i("show_prefs", 33);
  367. PostMessageW(hMainWindow, WM_USER, 0, IPC_RESTARTWINAMP);
  368. }
  369. else
  370. ListView_DeleteItem(listWindow, which);
  371. registrar->Release();
  372. }
  373. SendDlgItemMessageA(hwndDlg,IDC_VISMOD,CB_RESETCONTENT,0,0);
  374. }
  375. }
  376. }
  377. }
  378. return FALSE;
  379. case IDC_PLUGINVERS:
  380. myOpenURLWithFallback(hwndDlg, L"http://www.google.com/search?q=Winamp+Visualization+Plugins", L"http://www.google.com/search?q=Winamp+Visualization+Plugins");
  381. return TRUE;
  382. }
  383. }
  384. link_handledraw(hwndDlg,uMsg,wParam,lParam);
  385. return FALSE;
  386. } //vis