1
0

Jump.cpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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. static LRESULT WINAPI jumpDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam);
  10. static LRESULT WINAPI jumpFileDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam);
  11. HWND jump_hwnd, jump_hwnd2;
  12. int jump_dialog(HWND hwnd)
  13. {
  14. if (IsWindow(jump_hwnd)) { SetForegroundWindow(jump_hwnd); return -1; }
  15. LPCreateDialogW(IDD_JUMPDLG,DIALOG_PARENT(hwnd), jumpDlgProc);
  16. return 0;
  17. }
  18. int jump_file_dialog(HWND hwnd)
  19. {
  20. if (IsWindow(jump_hwnd2)) { SetForegroundWindow(jump_hwnd2); return -1; }
  21. LPCreateDialogW(IDD_JUMPFILEDLG,DIALOG_PARENT(hwnd),jumpFileDlgProc);
  22. return 0;
  23. }
  24. static LRESULT WINAPI jumpDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  25. {
  26. switch (uMsg)
  27. {
  28. case WM_INITDIALOG:
  29. ShowWindow(jump_hwnd=hwndDlg,SW_SHOW);
  30. {
  31. char text[128] = {0};
  32. int len=0;
  33. if (in_mod) len=in_mod->GetLength()/1000;
  34. StringCchPrintfA(text,128,"%d:%02d",len/60,len%60);
  35. if (in_mod) len = in_mod->GetOutputTime()/1000;
  36. else len=0;
  37. SetDlgItemTextA(hwndDlg,IDC_TRACKLEN,text);
  38. StringCchPrintfA(text,128,"%d:%02d",len/60,len%60);
  39. SetDlgItemTextA(hwndDlg,IDC_MINUTES,text);
  40. // show jump to time window and restore last position as applicable
  41. POINT pt = {time_rect.left, time_rect.top};
  42. if (!windowOffScreen(hwndDlg, pt))
  43. SetWindowPos(hwndDlg, HWND_TOP, time_rect.left, time_rect.top, 0, 0, SWP_NOSIZE | SWP_NOSENDCHANGING);
  44. }
  45. return TRUE;
  46. case WM_COMMAND:
  47. switch (LOWORD(wParam))
  48. {
  49. case IDOK:
  50. {
  51. char text[129] = {0};
  52. int m=0,s=0,bt=0;
  53. char *p=text;
  54. GetDlgItemTextA(hwndDlg,IDC_MINUTES,text,sizeof(text));
  55. while (p && *p == ' ') p++;
  56. while (p && *p >= '0' && *p <= '9') {bt=1;s=s*10+*p++-'0';}
  57. if (p && *p++ == ':')
  58. {
  59. m=s;s=0;
  60. while (p && *p >= '0' && *p <= '9') {bt=1;s=s*10+*p++-'0';}
  61. }
  62. if (bt)
  63. {
  64. int time=m*60000+s*1000;
  65. if (time >= 0 && !PlayList_ishidden(PlayList_getPosition()))
  66. {
  67. if (in_seek(time) < 0)
  68. SendMessageW(hMainWindow,WM_WA_MPEG_EOF,0,0);
  69. else
  70. {
  71. ui_drawtime(in_getouttime()/1000,0);
  72. }
  73. }
  74. Sleep(100);
  75. while (1)
  76. {
  77. MSG msg = {0};
  78. if (!PeekMessage(&msg,hMainWindow,WM_MOUSEFIRST,WM_MOUSELAST,PM_REMOVE))
  79. break;
  80. }
  81. }
  82. }
  83. case IDCANCEL:
  84. GetWindowRect(hwndDlg, &time_rect);
  85. DestroyWindow(hwndDlg);
  86. return FALSE;
  87. }
  88. return FALSE;
  89. case WM_DESTROY:
  90. jump_hwnd=0;
  91. return 0;
  92. }
  93. return 0;
  94. }
  95. static void parselist(char *out, const char *in)
  96. {
  97. int inquotes=0, neednull=0;
  98. while (in && *in)
  99. {
  100. char c=*in++;
  101. if (c >= 'A' && c <= 'Z') c+='a'-'A';
  102. if ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9'))
  103. {
  104. neednull=1;
  105. *out++=c;
  106. }
  107. else if (c == '\"')
  108. {
  109. inquotes=!inquotes;
  110. if (!inquotes)
  111. {
  112. *out++=0;
  113. neednull=0;
  114. }
  115. }
  116. else
  117. {
  118. if (inquotes) *out++=c;
  119. else if (neednull)
  120. {
  121. *out++=0;
  122. neednull=0;
  123. }
  124. }
  125. }
  126. *out++=0;
  127. *out++=0;
  128. }
  129. extern "C"
  130. {
  131. static int __cdecl substr_search(const char *bigtext, const char *littletext)
  132. {
  133. char littletext_list[128] = {0}, *plist = 0;
  134. char bigtext_list[MAX_PATH*8] = {0};
  135. parselist(littletext_list, littletext);
  136. StringCchCopyA(bigtext_list, MAX_PATH*8, bigtext);
  137. plist = bigtext_list;
  138. while (plist && *plist)
  139. {
  140. if (*plist >= 'A' && *plist <= 'Z') *plist += 'a'-'A';
  141. plist++;
  142. }
  143. plist = littletext_list;
  144. while (plist && *plist)
  145. {
  146. if (!strstr(bigtext_list, plist)) return 0;
  147. plist += lstrlenA(plist) + 1;
  148. }
  149. return 1;
  150. }
  151. static int (__cdecl *jtf_comparator)(const char *, const char *) = substr_search;
  152. static int (__cdecl *jtf_comparatorW)(const wchar_t *, const wchar_t *) = 0;
  153. }
  154. void SetJumpComparator(void *functionPtr)
  155. {
  156. if (functionPtr)
  157. jtf_comparator = (int (__cdecl *)(const char *, const char *))(functionPtr);
  158. else
  159. jtf_comparator = substr_search;
  160. }
  161. void SetJumpComparatorW(void *functionPtr)
  162. {
  163. if (functionPtr)
  164. jtf_comparatorW = (int (__cdecl *)(const wchar_t *, const wchar_t *))(functionPtr);
  165. else
  166. jtf_comparatorW = 0;
  167. }
  168. static WNDPROC oldWndProc;
  169. static LRESULT WINAPI newWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  170. {
  171. if ((uMsg == WM_KEYDOWN || uMsg == WM_KEYUP) &&
  172. (wParam == VK_UP || wParam == VK_DOWN || wParam == VK_PRIOR || wParam == VK_NEXT))
  173. {
  174. SendMessageW(GetDlgItem(GetParent(hwndDlg),IDC_SELBOX),uMsg,wParam,lParam);
  175. return 0;
  176. }
  177. return CallWindowProc(oldWndProc,hwndDlg,uMsg,wParam,lParam);
  178. }
  179. static LRESULT WINAPI jumpFileDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  180. {
  181. switch (uMsg)
  182. {
  183. case WM_INITDIALOG:
  184. ShowWindow(jump_hwnd2=hwndDlg,SW_SHOW);
  185. {
  186. int x = 0;
  187. HWND hw = GetDlgItem(hwndDlg,IDC_SELBOX);
  188. // prevents showing the full playlist contents on loading as needed
  189. if (!config_jtf_check)
  190. {
  191. int t = PlayList_getPosition();
  192. int v = PlayList_getlength();
  193. SendMessageW(hw,WM_SETREDRAW,FALSE,0);
  194. for (x = 0; x < v; x ++)
  195. {
  196. wchar_t ft[FILETITLE_SIZE] = {0};
  197. PlayList_getitem2W(x, 0, ft);
  198. SendMessageW(hw,LB_SETITEMDATA,SendMessageW(hw,LB_ADDSTRING,0,(LPARAM) ft),x);
  199. }
  200. for (x = 0; x < v; x ++)
  201. {
  202. if (SendMessageW(hw,LB_GETITEMDATA,x,0)==t)
  203. break;
  204. }
  205. SendMessageW(hw,WM_SETREDRAW,TRUE,0);
  206. }
  207. SendMessageW(hw, LB_SETCURSEL, x, 0);
  208. oldWndProc = (WNDPROC) SetWindowLongPtrW(GetDlgItem(hwndDlg, IDC_EDIT1), GWLP_WNDPROC, (LONG_PTR)newWndProc);
  209. }
  210. return TRUE;
  211. case WM_COMMAND:
  212. switch (LOWORD(wParam))
  213. {
  214. case IDOK:
  215. {
  216. LRESULT x=SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_GETITEMDATA,SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_GETCURSEL,0,0),0);
  217. if (x >= 0 && x != PlayList_getPosition())
  218. {
  219. PlayList_setposition(x);
  220. PlayList_getcurrent(FileName,FileTitle,FileTitleNum);
  221. StartPlaying();
  222. }
  223. Sleep(100);
  224. while (1)
  225. {
  226. MSG msg = {0};
  227. if (!PeekMessage(&msg,hMainWindow,WM_MOUSEFIRST,WM_MOUSELAST,PM_REMOVE))
  228. break;
  229. }
  230. }
  231. case IDCANCEL:
  232. DestroyWindow(hwndDlg);
  233. return FALSE;
  234. case IDC_SELBOX:
  235. if (HIWORD(wParam) == LBN_DBLCLK)
  236. {
  237. SendMessageW(hwndDlg,WM_COMMAND,IDOK,0);
  238. }
  239. return FALSE;
  240. case IDC_EDIT1:
  241. if (HIWORD(wParam) == EN_CHANGE)
  242. {
  243. wchar_t s[64] = {0};
  244. if(jtf_comparatorW) GetDlgItemTextW(hwndDlg,IDC_EDIT1,s,64);
  245. else GetDlgItemTextA(hwndDlg,IDC_EDIT1,(char*)s,64);
  246. int v = PlayList_getlength();
  247. HWND hw = GetDlgItem(hwndDlg,IDC_SELBOX);
  248. SendMessageW(hw,WM_SETREDRAW,FALSE,0);
  249. SendMessageW(hw,LB_RESETCONTENT,0,0);
  250. // prevents showing the full playlist contents on searching as needed
  251. if (!config_jtf_check || s[0] && config_jtf_check)
  252. {
  253. int x = 0;
  254. for (; x < v; x++)
  255. {
  256. int addtolist = 1;
  257. if (jtf_comparatorW)
  258. {
  259. wchar_t buf[FILENAME_SIZE+FILETITLE_SIZE+1] = {0};
  260. PlayList_getitem_jtfW(x, buf);
  261. addtolist = jtf_comparatorW(buf, s);
  262. }
  263. else
  264. {
  265. char buf[FILENAME_SIZE+FILETITLE_SIZE+1] = {0}, b2[FILETITLE_SIZE] = {0};
  266. PlayList_getitem2(x,buf,b2);
  267. StringCchCatA(buf,FILENAME_SIZE+FILETITLE_SIZE+1," ");
  268. StringCchCatA(buf,FILENAME_SIZE+FILETITLE_SIZE+1,b2);
  269. addtolist = jtf_comparator(buf,(char*)s);
  270. }
  271. if (!s[0] || addtolist)
  272. {
  273. wchar_t b2[FILETITLE_SIZE] = {0};
  274. PlayList_getitem2W(x, 0, b2);
  275. SendMessageW(hw,LB_SETITEMDATA,SendMessageW(hw,LB_ADDSTRING,0,(LPARAM) b2),x);
  276. }
  277. }
  278. SendMessageW(hw,LB_SETCURSEL,0,x);
  279. }
  280. SendMessageW(hw,WM_SETREDRAW,TRUE,0);
  281. }
  282. return FALSE;
  283. }
  284. return FALSE;
  285. case WM_DESTROY:
  286. jump_hwnd2=0;
  287. return 0;
  288. }
  289. return 0;
  290. }