1
0

options_output.cpp 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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 "../nu/AutoWide.h"
  12. // output tab procedure
  13. static int last_sel = -1;
  14. static bool pluginsLoaded;
  15. INT_PTR CALLBACK OutputProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  16. {
  17. hi helpinfo[]=
  18. {
  19. {IDC_OUTPUTS,IDS_P_OUT_OUTPUTS},
  20. {IDC_CONF2,IDS_P_OUT_CONF},
  21. {IDC_ABOUT2,IDS_P_OUT_ABOUT},
  22. {IDC_UNINSTOUT,IDS_P_OUT_UNINST},
  23. };
  24. DO_HELP();
  25. if (uMsg == WM_INITDIALOG)
  26. {
  27. pluginsLoaded = false;
  28. WIN32_FIND_DATAW d = {0};
  29. link_startsubclass(hwndDlg, IDC_PLUGINVERS);
  30. HWND listWindow = GetDlgItem(hwndDlg, IDC_OUTPUTS);
  31. if (IsWindow(listWindow))
  32. {
  33. size_t x;
  34. RECT r = {0};
  35. GetWindowRect(listWindow, &r);
  36. GetClientRect(listWindow, &r);
  37. MapWindowPoints(listWindow, hwndDlg, (LPPOINT)&r, 2);
  38. InflateRect(&r, 2, 2);
  39. DestroyWindow(listWindow);
  40. listWindow = CreateWindowExW(WS_EX_NOPARENTNOTIFY | WS_EX_CLIENTEDGE, WC_LISTVIEWW, L"",
  41. WS_CHILD | WS_VISIBLE | WS_TABSTOP | LVS_REPORT | LVS_SINGLESEL |
  42. LVS_SHOWSELALWAYS | LVS_SORTASCENDING | LVS_NOCOLUMNHEADER | LVS_NOSORTHEADER,
  43. r.left, r.top, r.right - r.left, r.bottom - r.top,
  44. hwndDlg, (HMENU)IDC_OUTPUTS, NULL, NULL);
  45. SetWindowPos(listWindow, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  46. ListView_SetExtendedListViewStyleEx(listWindow, LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP, LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP);
  47. SendMessageW(listWindow, WM_SETFONT, SendMessageW(hwndDlg, WM_GETFONT, 0, 0), FALSE);
  48. LVCOLUMNW lvc = {0};
  49. ListView_InsertColumnW(listWindow, 0, &lvc);
  50. ListView_InsertColumnW(listWindow, 1, &lvc);
  51. for (x = 0; out_modules[x]; x ++)
  52. {
  53. wchar_t fn[MAX_PATH] = {0}, buf[512] = {0};
  54. GetModuleFileNameW(out_modules[x]->hDllInstance, fn, MAX_PATH);
  55. PathStripPathW(fn);
  56. LVITEMW lvi = {LVIF_TEXT | LVIF_PARAM, (int)x, 0};
  57. lstrcpynW(buf, ((out_modules[x]->version == OUT_VER_U) ? (wchar_t*)out_modules[x]->description : AutoWide(out_modules[x]->description)), 512);
  58. lvi.pszText = buf;
  59. lvi.lParam = x;
  60. lvi.iItem = ListView_InsertItemW(listWindow, &lvi);
  61. lvi.mask = LVIF_TEXT;
  62. lvi.iSubItem = 1;
  63. lvi.pszText = fn;
  64. ListView_SetItemW(listWindow, &lvi);
  65. if (!_stricmp(config_outname, (char*)out_modules[x]->id))
  66. {
  67. last_sel = lvi.iItem;
  68. ListView_SetItemState(listWindow, lvi.iItem, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  69. }
  70. }
  71. wchar_t dirstr[MAX_PATH] = {0};
  72. PathCombineW(dirstr, PLUGINDIR, L"OUT*.DLL");
  73. HANDLE h = FindFirstFileW(dirstr, &d);
  74. if (h != INVALID_HANDLE_VALUE)
  75. {
  76. do
  77. {
  78. PathCombineW(dirstr, PLUGINDIR, d.cFileName);
  79. HMODULE b = LoadLibraryExW(dirstr, NULL, LOAD_LIBRARY_AS_DATAFILE);
  80. bool found = false;
  81. for (x = 0; b && out_modules[x]; x ++)
  82. {
  83. if (out_modules[x]->hDllInstance == b)
  84. {
  85. found = true;
  86. break;
  87. }
  88. }
  89. if (!found)
  90. {
  91. LVITEMW lvi = {LVIF_TEXT | LVIF_PARAM, (int)x, 0};
  92. lvi.pszText = d.cFileName;
  93. lvi.lParam = -2;
  94. lvi.iItem = ListView_InsertItemW(listWindow, &lvi);
  95. lvi.mask = LVIF_TEXT;
  96. lvi.iSubItem = 1;
  97. lvi.pszText = getStringW(IDS_NOT_LOADED, NULL, 0);
  98. ListView_SetItemW(listWindow, &lvi);
  99. }
  100. FreeLibrary(b);
  101. }
  102. while (FindNextFileW(h, &d));
  103. FindClose(h);
  104. }
  105. GetClientRect(listWindow, &r);
  106. ListView_SetColumnWidth(listWindow, 1, LVSCW_AUTOSIZE);
  107. ListView_SetColumnWidth(listWindow, 0, (r.right - r.left) - ListView_GetColumnWidth(listWindow, 1));
  108. DirectMouseWheel_EnableConvertToMouseWheel(listWindow, TRUE);
  109. pluginsLoaded = true;
  110. }
  111. }
  112. else if (uMsg == WM_DESTROY)
  113. {
  114. HWND listWindow = GetDlgItem(hwndDlg, IDC_OUTPUTS);
  115. if (IsWindow(listWindow))
  116. DirectMouseWheel_EnableConvertToMouseWheel(listWindow, FALSE);
  117. }
  118. else if (uMsg == WM_NOTIFY)
  119. {
  120. LPNMHDR p = (LPNMHDR)lParam;
  121. if (p->idFrom == IDC_OUTPUTS)
  122. {
  123. if (p->code == LVN_ITEMCHANGED)
  124. {
  125. LPNMLISTVIEW pnmv = (LPNMLISTVIEW)lParam;
  126. LVITEM lvi = {LVIF_PARAM, pnmv->iItem};
  127. if (ListView_GetItem(p->hwndFrom, &lvi) && (pnmv->uNewState & LVIS_SELECTED))
  128. {
  129. int loaded = (lvi.lParam != -2);
  130. EnableWindow(GetDlgItem(hwndDlg, IDC_CONF2), loaded);
  131. EnableWindow(GetDlgItem(hwndDlg, IDC_ABOUT2), loaded);
  132. EnableWindow(GetDlgItem(hwndDlg, IDC_UNINSTOUT), 1);
  133. if (loaded && out_modules[lvi.lParam])
  134. {
  135. StringCbCopyA(config_outname, sizeof(config_outname), (char *)out_modules[lvi.lParam]->id);
  136. if (last_sel != -1 && out_modules[last_sel]) out_changed(out_modules[last_sel]->hDllInstance, OUT_UNSET);
  137. out_changed(out_modules[lvi.lParam]->hDllInstance, OUT_SET);
  138. PostMessageW(hMainWindow, WM_WA_IPC, (WPARAM)config_outname, IPC_CB_OUTPUTCHANGED);
  139. }
  140. }
  141. else
  142. {
  143. EnableWindow(GetDlgItem(hwndDlg, IDC_CONF2), 0);
  144. EnableWindow(GetDlgItem(hwndDlg, IDC_ABOUT2), 0);
  145. EnableWindow(GetDlgItem(hwndDlg, IDC_UNINSTOUT), 0);
  146. }
  147. }
  148. else if (p->code == NM_DBLCLK || p->code == NM_CLICK)
  149. {
  150. if (p->code == NM_DBLCLK)
  151. {
  152. PostMessageW(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_CONF2, 0), (LPARAM)GetDlgItem(hwndDlg, IDC_CONF2));
  153. }
  154. // helps to keep the selection on things...
  155. LPNMITEMACTIVATE lpnmitem = (LPNMITEMACTIVATE)lParam;
  156. if (lpnmitem->iItem == -1)
  157. {
  158. ListView_SetItemState(p->hwndFrom, ListView_GetSelectionMark(p->hwndFrom), LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  159. }
  160. }
  161. }
  162. else if (p->code == HDN_ITEMCHANGINGW)
  163. {
  164. if (pluginsLoaded)
  165. {
  166. #ifdef WIN64
  167. SetWindowLongPtrW(hwndDlg, DWLP_MSGRESULT, TRUE);
  168. #else
  169. SetWindowLong(hwndDlg, DWL_MSGRESULT, TRUE);
  170. #endif
  171. return TRUE;
  172. }
  173. }
  174. }
  175. else if (uMsg == WM_COMMAND)
  176. {
  177. switch (LOWORD(wParam))
  178. {
  179. case IDC_ABOUT2:
  180. {
  181. if (IsWindowEnabled(GetDlgItem(hwndDlg, IDC_ABOUT2)))
  182. {
  183. HWND listWindow = GetDlgItem(hwndDlg, IDC_OUTPUTS);
  184. LVITEM lvi = {LVIF_PARAM, ListView_GetSelectionMark(listWindow)};
  185. if (ListView_GetItem(listWindow, &lvi))
  186. {
  187. if (lvi.lParam >= 0 && lvi.lParam < 32 && out_modules[lvi.lParam]) out_modules[lvi.lParam]->About(hwndDlg);
  188. }
  189. }
  190. }
  191. return FALSE;
  192. case IDC_CONF2:
  193. {
  194. if (IsWindowEnabled(GetDlgItem(hwndDlg, IDC_CONF2)))
  195. {
  196. HWND listWindow = GetDlgItem(hwndDlg, IDC_OUTPUTS);
  197. LVITEM lvi = {LVIF_PARAM, ListView_GetSelectionMark(listWindow)};
  198. if (ListView_GetItem(listWindow, &lvi))
  199. {
  200. if (lvi.lParam >= 0 && lvi.lParam < 32 && out_modules[lvi.lParam]) out_modules[lvi.lParam]->Config(hwndDlg);
  201. }
  202. }
  203. }
  204. return FALSE;
  205. case IDC_UNINSTOUT:
  206. {
  207. HWND listWindow = GetDlgItem(hwndDlg, IDC_OUTPUTS);
  208. int which_sel = ListView_GetSelectionMark(listWindow);
  209. LVITEM lvi = {LVIF_PARAM, which_sel};
  210. if (ListView_GetItem(listWindow, &lvi))
  211. {
  212. if (LPMessageBox(hwndDlg, IDS_P_PLUGIN_UNINSTALL,IDS_P_PLUGIN_UNINSTALL_CONFIRM,MB_YESNO|MB_ICONEXCLAMATION) == IDYES)
  213. {
  214. if (lvi.lParam >= 0 && lvi.lParam < 32 && out_modules[lvi.lParam])
  215. {
  216. int ret=0;
  217. int (*pr)(HINSTANCE hDllInst, HWND hwndDlg, int param);
  218. *(void**)&pr = (void*)GetProcAddress(out_modules[lvi.lParam]->hDllInstance,"winampUninstallPlugin");
  219. // changed 28/11/2010 so that even if non-zero is returned then the plug-in will uninstall
  220. if (pr)/*ret=*/pr(out_modules[lvi.lParam]->hDllInstance,hwndDlg,0);
  221. if (!ret)
  222. {
  223. char buf[1024] = {0};
  224. int w=-1;
  225. char *p=buf;
  226. int y;
  227. GetModuleFileNameA(out_modules[lvi.lParam]->hDllInstance,buf,sizeof(buf));
  228. _w_s("remove_genplug",buf);
  229. _w_i("show_prefs",32);
  230. buf[0]=0;
  231. for (y = 0; out_modules[y]; y ++)
  232. {
  233. if (lvi.lParam != y)
  234. {
  235. GetModuleFileNameA(out_modules[y]->hDllInstance,buf,sizeof(buf));
  236. p = PathFindFileNameA(buf);
  237. if (!_stricmp(p,"out_wave.dll") && w < 1) w=1;
  238. if (!_stricmp(p,"out_ds.dll") && w < 0) w=0;
  239. if (w>0) break;
  240. }
  241. }
  242. if (w==1) StringCbCopyA(config_outname, sizeof(config_outname), "out_wave.dll");
  243. else if (w==0) StringCbCopyA(config_outname,sizeof(config_outname), "out_ds.dll");
  244. else StringCbCopyA(config_outname,sizeof(config_outname),p);
  245. PostMessageW(hMainWindow,WM_USER,0,IPC_RESTARTWINAMP);
  246. }
  247. }
  248. // will cope with not loaded plug-ins so we can still remove them, etc
  249. else if (lvi.lParam == -2)
  250. {
  251. wchar_t buf[1024] = {0}, base[1024] = {0};
  252. StringCchCopyW(base, 1024, PLUGINDIR);
  253. PathAddBackslashW(base);
  254. LVITEMW lvi = {LVIF_TEXT, which_sel};
  255. lvi.pszText = buf;
  256. lvi.cchTextMax = ARRAYSIZE(buf);
  257. ListView_GetItemW(listWindow, &lvi);
  258. wchar_t *p = wcschr(buf, L'.');
  259. if (p && *p == L'.')
  260. {
  261. p += 4;
  262. *p = 0;
  263. PathRemoveFileSpecW(base);
  264. PathAppendW(base, buf);
  265. }
  266. IFileTypeRegistrar *registrar=0;
  267. if (GetRegistrar(&registrar, true) == 0 && registrar)
  268. {
  269. if (registrar->DeleteItem(base) != S_OK)
  270. {
  271. _w_sW("remove_genplug", base);
  272. _w_i("show_prefs", 32);
  273. PostMessageW(hMainWindow, WM_USER, 0, IPC_RESTARTWINAMP);
  274. }
  275. else
  276. ListView_DeleteItem(listWindow, which_sel);
  277. registrar->Release();
  278. }
  279. }
  280. // resets the focus to the listbox so it'll keep ui response working
  281. SetFocus(GetDlgItem(hwndDlg,IDC_INPUTS));
  282. }
  283. }
  284. }
  285. break;
  286. case IDC_PLUGINVERS:
  287. myOpenURLWithFallback(hwndDlg,L"http://www.google.com/search?q=Winamp+Output+Plugins", L"http://www.google.com/search?q=Winamp+Output+Plugins");
  288. break;
  289. }
  290. }
  291. else
  292. {
  293. link_handledraw(hwndDlg,uMsg,wParam,lParam);
  294. }
  295. return FALSE;
  296. } //output