1
0

Peui.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  1. #include "Main.h"
  2. #define inreg(x,y,x2,y2) \
  3. ((mouse_x <= ( x2 ) && mouse_x >= ( x ) && \
  4. mouse_y <= ( y2 ) && mouse_y >= ( y )))
  5. static int mouse_x, mouse_y, mouse_type, mouse_stats;
  6. static int which_cap=0;
  7. enum { NO_CAP,TITLE_CAP,TB_CAP, SZ_CAP, VS_CAP, LB_CAP, VSB_CAP, ADD_CAP, REM_CAP, SEL_CAP, MISC_CAP, FILE_CAP, TD_CAP, MB_CAP };
  8. static void do_titlebar(HWND hwnd);
  9. static void do_titlebuttons();
  10. static void do_size(HWND hwnd);
  11. static void do_vscroll(HWND hwnd);
  12. static void do_lb(HWND hwnd);
  13. static void do_vsb(HWND hwnd);
  14. static void do_addbut(HWND hwnd);
  15. static void do_rembut(HWND hwnd);
  16. static void do_selbut(HWND hwnd);
  17. static void do_miscbut(HWND hwnd);
  18. static void do_filebut(HWND hwnd);
  19. static void do_timedisplay();
  20. static void do_mb();
  21. int peui_isrbuttoncaptured()
  22. {
  23. if (which_cap >= ADD_CAP && which_cap <= FILE_CAP) return 1;
  24. return 0;
  25. }
  26. void peui_reset(HWND hwnd)
  27. {
  28. if (which_cap>=ADD_CAP && which_cap <= FILE_CAP)
  29. InvalidateRect(hwnd,NULL,0);
  30. which_cap=0;
  31. }
  32. //#include "../gen_ml/ml_ipc_0313.h"
  33. void peui_handlemouseevent(HWND hwnd, int x, int y, int type, int stats)
  34. {
  35. mouse_x = x;
  36. mouse_y = y;
  37. mouse_type = type;
  38. mouse_stats = stats;
  39. if (!which_cap)
  40. {
  41. if (playing && mouse_type == 1 && config_pe_height != 14 && config_pe_width >= 350 &&
  42. inreg(config_pe_width-150-75,config_pe_height-26,config_pe_width-150,config_pe_height-8))
  43. {
  44. config_sa++;
  45. if (config_sa > 2) config_sa = 0;
  46. set_visopts();
  47. sa_setthread(config_sa);
  48. return;
  49. }
  50. }
  51. switch (which_cap)
  52. {
  53. case MB_CAP: do_mb(); return;
  54. case TD_CAP: do_timedisplay(); return;
  55. case MISC_CAP: do_miscbut(hwnd); return;
  56. case FILE_CAP: do_filebut(hwnd); return;
  57. case SEL_CAP: do_selbut(hwnd); return;
  58. case ADD_CAP: do_addbut(hwnd); return;
  59. case REM_CAP: do_rembut(hwnd); return;
  60. case VSB_CAP:do_vsb(hwnd);return;
  61. case LB_CAP: do_lb(hwnd);return;
  62. case TITLE_CAP: do_titlebar(hwnd);return;
  63. case TB_CAP: do_titlebuttons();return;
  64. case SZ_CAP: do_size(hwnd); return;
  65. case VS_CAP: do_vscroll(hwnd); return;
  66. default: break;
  67. }
  68. if (config_pe_height != 14)
  69. {
  70. do_mb();
  71. do_timedisplay();
  72. do_filebut(hwnd);
  73. do_miscbut(hwnd);
  74. do_selbut(hwnd);
  75. do_addbut(hwnd);
  76. do_rembut(hwnd);
  77. do_vsb(hwnd);
  78. do_lb(hwnd);
  79. do_vscroll(hwnd);
  80. }
  81. do_titlebuttons();
  82. do_size(hwnd);
  83. do_titlebar(hwnd);
  84. // TODO make this not go weird / cause WM_MOUSEWHEEL to fail, etc
  85. #if 0
  86. if(!mouse_type)
  87. {
  88. int t = (mouse_y - 22) / pe_fontheight;
  89. if (t < 0) t = 0;
  90. else if (t > (config_pe_height - 38 - 22) / pe_fontheight) t = PlayList_getlength();
  91. //else t += pledit_disp_offs;
  92. // TODO alignment isn't 100% correct at times
  93. RECT rs = {0};
  94. rs.left = 12;
  95. rs.right = config_pe_width - 20;
  96. rs.top = 22+(pe_fontheight*t);
  97. rs.bottom = rs.top + pe_fontheight;
  98. if(rs.bottom <= config_pe_height - 38)
  99. {
  100. TOOLINFOW ti = {0};
  101. RECT r_main;
  102. EstPLWindowRect(&r_main);
  103. ti.cbSize = sizeof(ti);
  104. ti.uFlags = TTF_SUBCLASS|TTF_TRANSPARENT;
  105. ti.hwnd = hPLWindow;
  106. ti.uId = (UINT_PTR)hPL2TooltipWindow;
  107. ti.lpszText = (wchar_t*)LPSTR_TEXTCALLBACK;
  108. ti.uId = 17;
  109. ti.rect = rs;
  110. // TODO need to get this to show the actual playlist item
  111. t = (mouse_y - 22) / pe_fontheight;
  112. if (t < 0) t = 0;
  113. else if (t > (config_pe_height - 38 - 22) / pe_fontheight) t = PlayList_getlength();
  114. else t += pledit_disp_offs;
  115. wchar_t ft[FILETITLE_SIZE], *ftp = ft;
  116. PlayList_getitem_pl(t,ft);
  117. while(ftp && *ftp)
  118. {
  119. if(*ftp != ' ') break;
  120. ftp = CharNextW(ftp);
  121. }
  122. ti.lpszText=ftp;
  123. ///*if (c)*/
  124. SendMessageW(hPLTooltipWindow,TTM_DELTOOLW,0,(LPARAM) &ti);
  125. //if (config_ttips)
  126. SendMessageW(hPL2TooltipWindow,TTM_ADDTOOLW,0,(LPARAM) &ti);
  127. // TODO need to get the skinning code from gen_ml into winamp.exe or split it out...
  128. static bool skinned;
  129. if(!skinned)
  130. {
  131. typedef BOOL (__cdecl *MLSKINWINDOWEX)(HWND /*hwnd*/, INT /*type*/, UINT /*style*/);
  132. MLSKINWINDOWEX mlSkinWindowEx = (MLSKINWINDOWEX)GetProcAddress(GetModuleHandle("gen_ml.dll"), "MlSkinWindowEx");
  133. unsigned int skinStyle = SWS_USESKINCOLORS;
  134. skinStyle |= ((SWS_USESKINFONT | SWS_USESKINCURSORS)/* & style*/);
  135. mlSkinWindowEx(hPL2TooltipWindow, SKINNEDWND_TYPE_TOOLTIP, skinStyle);
  136. skinned = true;
  137. }
  138. }
  139. }
  140. #endif
  141. }
  142. static void __do_buttons(int which)
  143. {
  144. int m = WINAMP_BUTTON1 + which;
  145. if (which == 5)
  146. {
  147. if (mouse_stats & MK_CONTROL) SendMessageW(hMainWindow,WM_COMMAND,WINAMP_FILE_LOC,0);
  148. else if (mouse_stats & MK_SHIFT) SendMessageW(hMainWindow,WM_COMMAND,WINAMP_FILE_DIR,0);
  149. else SendMessageW(hMainWindow,WM_COMMAND,WINAMP_FILE_PLAY,0);
  150. }
  151. else
  152. {
  153. if (mouse_stats & MK_SHIFT) m += 100;
  154. else if (mouse_stats & MK_CONTROL) m += 110;
  155. SendMessageW(hMainWindow,WM_COMMAND,m,0);
  156. }
  157. }
  158. static void do_mb()
  159. {
  160. if (!which_cap && mouse_type == 1 && inreg(config_pe_width-144,config_pe_height-15,config_pe_width-91,config_pe_height-8))
  161. {
  162. int t=config_pe_width-144;
  163. int which = 5 - (mouse_x < 45+t) - (mouse_x < 36+t) - (mouse_x < 27+t) - (mouse_x < 17+t) - (mouse_x < 7+t);
  164. which_cap = MB_CAP;
  165. __do_buttons(which);
  166. }
  167. if (which_cap == MB_CAP && mouse_type == -1)
  168. which_cap=0;
  169. }
  170. static void do_timedisplay()
  171. {
  172. if (!which_cap && mouse_type == 1 && inreg(config_pe_width-87,config_pe_height-18,config_pe_width-53,config_pe_height-9))
  173. {
  174. which_cap = TD_CAP;
  175. config_timeleftmode = !config_timeleftmode;
  176. if (!config_timeleftmode)
  177. {
  178. CheckMenuItem(main_menu,WINAMP_OPTIONS_ELAPSED,MF_CHECKED);
  179. CheckMenuItem(main_menu,WINAMP_OPTIONS_REMAINING,MF_UNCHECKED);
  180. }
  181. else
  182. {
  183. CheckMenuItem(main_menu,WINAMP_OPTIONS_ELAPSED,MF_UNCHECKED);
  184. CheckMenuItem(main_menu,WINAMP_OPTIONS_REMAINING,MF_CHECKED);
  185. }
  186. SendMessageW(hMainWindow,WM_TIMER,UPDATE_DISPLAY_TIMER+4,0);
  187. }
  188. if (which_cap == TD_CAP && mouse_type == -1)
  189. which_cap=0;
  190. }
  191. static void do_filebut(HWND hwnd)
  192. {
  193. int lwc=which_cap;
  194. if (!which_cap && mouse_type == 1 && inreg(config_pe_width-44,config_pe_height-30,config_pe_width-44+22,config_pe_height-12))
  195. {
  196. which_cap = FILE_CAP;
  197. }
  198. if (which_cap == FILE_CAP)
  199. {
  200. int doit=-1;
  201. if (inreg(config_pe_width-44,config_pe_height-30,config_pe_width-44+22,config_pe_height-12)) doit=0;
  202. else if (inreg(config_pe_width-44,config_pe_height-30-18,config_pe_width-44+22,config_pe_height-12-18)) doit=1;
  203. else if (inreg(config_pe_width-44,config_pe_height-30-18*2,config_pe_width-44+22,config_pe_height-12-18*2)) doit=2;
  204. draw_pe_iobut(doit);
  205. if ((config_ospb&&mouse_type==-1) || (mouse_type == 1 && lwc==FILE_CAP))
  206. {
  207. RECT r={config_pe_width-44-5,config_pe_height-12-18*3,config_pe_width-44+22,config_pe_height-12};
  208. InvalidateRect(hwnd,&r,FALSE);
  209. which_cap=0;
  210. switch (doit)
  211. {
  212. case 0: SendMessageW(hwnd,WM_COMMAND,ID_PE_OPEN,0); break;
  213. case 1: SendMessageW(hwnd,WM_COMMAND,ID_PE_SAVEAS,0); break;
  214. case 2: SendMessageW(hwnd,WM_COMMAND,ID_PE_CLEAR,0); break;
  215. }
  216. }
  217. }
  218. }
  219. static void do_miscbut(HWND hwnd)
  220. {
  221. int lwc=which_cap;
  222. if (!which_cap && mouse_type == 1 && inreg(101,config_pe_height-30,122,config_pe_height-12))
  223. {
  224. which_cap = MISC_CAP;
  225. }
  226. if (which_cap == MISC_CAP)
  227. {
  228. int doit=-1;
  229. if (inreg(101,config_pe_height-30,122,config_pe_height-12)) doit=0;
  230. else if (inreg(101,config_pe_height-30-18,122,config_pe_height-12-18)) doit=1;
  231. else if (inreg(101,config_pe_height-30-18*2,122,config_pe_height-12-18*2)) doit=2;
  232. draw_pe_miscbut(doit);
  233. if ((config_ospb&&mouse_type==-1) || (mouse_type == 1 && lwc==MISC_CAP))
  234. {
  235. RECT r={97,config_pe_height-12-18*3,123,config_pe_height-12};
  236. which_cap=0;
  237. switch (doit)
  238. {
  239. case 1:
  240. {
  241. POINT p={122,config_pe_height-30-18};
  242. ClientToScreen(hwnd,&p);
  243. DoTrackPopup(GetSubMenu(GetSubMenu(GetSubMenu(top_menu,2),0),0),TPM_LEFTALIGN,p.x,p.y,hwnd);
  244. }
  245. break;
  246. case 2:
  247. {
  248. POINT p={122,config_pe_height-30-18*2};
  249. ClientToScreen(hwnd,&p);
  250. DoTrackPopup(GetSubMenu(GetSubMenu(GetSubMenu(top_menu,2),0),1),TPM_LEFTALIGN,p.x,p.y,hwnd);
  251. }
  252. break;
  253. case 0:
  254. {
  255. POINT p={122,config_pe_height-30};
  256. ClientToScreen(hwnd,&p);
  257. DoTrackPopup(GetSubMenu(GetSubMenu(GetSubMenu(top_menu,2),0),2),TPM_LEFTALIGN,p.x,p.y,hwnd);
  258. }
  259. break;
  260. }
  261. InvalidateRect(hwnd,&r,FALSE);
  262. }
  263. }
  264. }
  265. static void do_selbut(HWND hwnd)
  266. {
  267. int lwc=which_cap;
  268. if (!which_cap && mouse_type == 1 && inreg(72,config_pe_height-30,93,config_pe_height-12))
  269. {
  270. which_cap = SEL_CAP;
  271. }
  272. if (which_cap == SEL_CAP)
  273. {
  274. int doit=-1;
  275. if (inreg(72,config_pe_height-30,93,config_pe_height-12)) doit=0;
  276. else if (inreg(72,config_pe_height-30-18,93,config_pe_height-12-18)) doit=1;
  277. else if (inreg(72,config_pe_height-30-18*2,93,config_pe_height-12-18*2)) doit=2;
  278. draw_pe_selbut(doit);
  279. if ((config_ospb&&mouse_type==-1) || (mouse_type == 1 && lwc==SEL_CAP))
  280. {
  281. RECT r={68,config_pe_height-12-18*3,95,config_pe_height-12};
  282. InvalidateRect(hwnd,&r,FALSE);
  283. which_cap=0;
  284. switch (doit)
  285. {
  286. case 0: SendMessageW(hwnd,WM_COMMAND,ID_PE_SELECTALL,0); break;
  287. case 1: SendMessageW(hwnd,WM_COMMAND,ID_PE_NONE,0); break;
  288. case 2: SendMessageW(hwnd,WM_COMMAND,IDC_SELECTINV,0); break;
  289. }
  290. }
  291. }
  292. }
  293. static void do_rembut(HWND hwnd)
  294. {
  295. int lwc=which_cap;
  296. if (!which_cap && mouse_type == 1 && inreg(43,config_pe_height-30,64,config_pe_height-12))
  297. {
  298. which_cap = REM_CAP;
  299. }
  300. if (which_cap == REM_CAP)
  301. {
  302. int doit=-1;
  303. if (inreg(43,config_pe_height-30,64,config_pe_height-12)) doit=0;
  304. else if (inreg(43,config_pe_height-30-18,64,config_pe_height-12-18)) doit=1;
  305. else if (inreg(43,config_pe_height-30-18*2,64,config_pe_height-12-18*2)) doit=2;
  306. else if (inreg(43,config_pe_height-30-18*3,64,config_pe_height-12-18*3)) doit=3;
  307. draw_pe_rembut(doit);
  308. if ((config_ospb&&mouse_type==-1) || (mouse_type == 1 && lwc==REM_CAP))
  309. {
  310. RECT r={39,config_pe_height-12-18*4,65,config_pe_height-12};
  311. which_cap=0;
  312. switch (doit)
  313. {
  314. case 0: SendMessageW(hwnd,WM_COMMAND,IDC_PLAYLIST_REMOVEMP3,0); break;
  315. case 1: SendMessageW(hwnd,WM_COMMAND,IDC_PLAYLIST_CROP,0); break;
  316. case 2: SendMessageW(hwnd,WM_COMMAND,ID_PE_CLEAR,0); break;
  317. case 3:
  318. {
  319. POINT p={64,config_pe_height-30-18*3};
  320. ClientToScreen(hwnd,&p);
  321. DoTrackPopup(GetSubMenu(GetSubMenu(GetSubMenu(top_menu,2),2),3),TPM_LEFTALIGN,p.x,p.y,hwnd);
  322. }
  323. break;
  324. }
  325. InvalidateRect(hwnd,&r,FALSE);
  326. }
  327. }
  328. }
  329. static void do_addbut(HWND hwnd)
  330. {
  331. int lwc=which_cap;
  332. if (!which_cap && mouse_type == 1 && inreg(14,config_pe_height-30,35,config_pe_height-12))
  333. {
  334. which_cap = ADD_CAP;
  335. }
  336. if (which_cap == ADD_CAP)
  337. {
  338. int doit=-1;
  339. if (inreg(14,config_pe_height-30,35,config_pe_height-12)) doit=0;
  340. else if (inreg(14,config_pe_height-30-18,35,config_pe_height-12-18)) doit=1;
  341. else if (inreg(14,config_pe_height-30-18*2,35,config_pe_height-12-18*2)) doit=2;
  342. draw_pe_addbut(doit);
  343. if ((config_ospb&&mouse_type==-1) || (mouse_type == 1 && lwc==ADD_CAP))
  344. {
  345. RECT r={11,config_pe_height-12-18*3,36,config_pe_height-12};
  346. InvalidateRect(hwnd,&r,FALSE);
  347. which_cap=0;
  348. switch (doit)
  349. {
  350. case 0: SendMessageW(hwnd,WM_COMMAND,IDC_PLAYLIST_ADDMP3,0); break;
  351. case 1: SendMessageW(hwnd,WM_COMMAND,IDC_PLAYLIST_ADDDIR,0); break;
  352. case 2: SendMessageW(hwnd,WM_COMMAND,IDC_PLAYLIST_ADDLOC,0); break;
  353. }
  354. }
  355. }
  356. }
  357. static void do_vsb(HWND hwnd)
  358. {
  359. if (!which_cap && mouse_type == 1 && inreg(config_pe_width-15,config_pe_height-36,config_pe_width-7,config_pe_height-32))
  360. {
  361. SendMessageW(hwnd,WM_COMMAND,ID_PE_SCROLLUP,0);
  362. which_cap = VSB_CAP;
  363. }
  364. if (!which_cap && mouse_type == 1 && inreg(config_pe_width-15,config_pe_height-31,config_pe_width-7,config_pe_height-27))
  365. {
  366. SendMessageW(hwnd,WM_COMMAND,ID_PE_SCROLLDOWN,0);
  367. which_cap = VSB_CAP;
  368. }
  369. if (which_cap == VSB_CAP && mouse_type == -1) which_cap=0;
  370. }
  371. int shiftsel_1=-1;
  372. static void do_lb(HWND hwnd)
  373. {
  374. static int move_mpos,stt;
  375. if (!which_cap && mouse_type == 1 && inreg(12,20,config_pe_width-20,config_pe_height-38))
  376. {
  377. int wh=(mouse_y-22)/pe_fontheight + pledit_disp_offs;
  378. if (!(mouse_stats & MK_CONTROL) && !PlayList_getselect(wh))
  379. {
  380. int x,t=PlayList_getlength();
  381. for (x = 0; x < t; x ++)
  382. PlayList_setselect(x,0);
  383. }
  384. if (mouse_stats & MK_SHIFT)
  385. {
  386. if (shiftsel_1 != -1)
  387. {
  388. int x,t=max(min(PlayList_getlength(),shiftsel_1),min(PlayList_getlength(),wh));
  389. if (!(mouse_stats & MK_CONTROL) && PlayList_getselect(wh))
  390. {
  391. int x,t=PlayList_getlength();
  392. for (x = 0; x < t; x ++)
  393. PlayList_setselect(x,0);
  394. }
  395. for (x = min(shiftsel_1,wh); x <=t; x ++)
  396. {
  397. PlayList_setselect(x,1);
  398. }
  399. stt=1;
  400. }
  401. }
  402. else
  403. {
  404. if (PlayList_getselect(wh) && mouse_stats & MK_CONTROL) PlayList_setselect(wh,0);
  405. else
  406. {
  407. int y = wh-pledit_disp_offs;
  408. if (y < PlayList_getlength()-pledit_disp_offs && y < (config_pe_height-38-20-2)/pe_fontheight)
  409. {
  410. PlayList_setselect(wh,1);
  411. }
  412. }
  413. shiftsel_1=wh;
  414. }
  415. {
  416. RECT r1={12,22,config_pe_width-20,config_pe_height-38};
  417. RECT r2={12,20+(wh-pledit_disp_offs)*pe_fontheight,config_pe_width-20,20+(wh+1-pledit_disp_offs)*pe_fontheight};
  418. if (!(mouse_stats & MK_CONTROL) || (mouse_stats & MK_SHIFT))
  419. InvalidateRect(hwnd,&r1,FALSE);
  420. else
  421. InvalidateRect(hwnd,&r2,FALSE);
  422. }
  423. move_mpos=(mouse_y-22)/pe_fontheight+pledit_disp_offs;
  424. which_cap=LB_CAP;
  425. }
  426. if (which_cap == LB_CAP)
  427. {
  428. extern int g_has_deleted_current;
  429. int m=(mouse_y-22)/pe_fontheight+pledit_disp_offs;
  430. if (m!=move_mpos)
  431. {
  432. int v,x;
  433. v = PlayList_getlength();
  434. x=1;
  435. while (m>move_mpos)
  436. {
  437. if (!PlayList_getselect(v-1)) for (x = v-2; x >= 0; x --)
  438. {
  439. if (!PlayList_getselect(x))
  440. {
  441. continue;
  442. }
  443. if (shiftsel_1 == x) shiftsel_1=x+1;
  444. PlayList_swap(x,x+1);
  445. if (x == PlayList_getPosition())
  446. PlayList_advance(1);
  447. else if (x+1 == PlayList_getPosition())
  448. PlayList_advance(-1);
  449. }
  450. move_mpos++;
  451. }
  452. while (m<move_mpos)
  453. {
  454. if (!PlayList_getselect(0)) for (x = 1; x < v; x ++)
  455. {
  456. if (!PlayList_getselect(x)) continue;
  457. if (shiftsel_1 == x) shiftsel_1=x-1;
  458. PlayList_swap(x,x-1);
  459. if (x == PlayList_getPosition())
  460. PlayList_advance(-1);
  461. else if (x-1 == PlayList_getPosition())
  462. PlayList_advance(1);
  463. }
  464. move_mpos--;
  465. }
  466. if (mouse_y < 10)
  467. {
  468. RECT r={0,0,config_pe_width,config_pe_height-37};
  469. // move_mpos++;
  470. pledit_disp_offs --;
  471. if (pledit_disp_offs < 0) { pledit_disp_offs=0; move_mpos=0;}
  472. InvalidateRect(hwnd,&r,FALSE);
  473. }
  474. else if (mouse_y > config_pe_height-28)
  475. {
  476. RECT r={0,0,config_pe_width,config_pe_height-37};
  477. int num_songs=(config_pe_height-38-20-2)/pe_fontheight;
  478. int t=PlayList_getlength()-num_songs;
  479. // move_mpos--;
  480. pledit_disp_offs ++;
  481. if (pledit_disp_offs > t) { pledit_disp_offs=max(t,0); move_mpos=PlayList_getlength(); }
  482. InvalidateRect(hwnd,&r,FALSE);
  483. }
  484. else {
  485. RECT r1={12,22,config_pe_width-20,config_pe_height-38};
  486. InvalidateRect(hwnd,&r1,FALSE);
  487. }
  488. if (!g_has_deleted_current)
  489. {
  490. PlayList_getcurrent(FileName,FileTitle,FileTitleNum);
  491. draw_songname(FileTitle,&ui_songposition,playing?in_getlength():PlayList_getcurrentlength());
  492. }
  493. }
  494. if (mouse_type == -1)
  495. {
  496. if (!stt)
  497. {
  498. int wh=(mouse_y-22)/pe_fontheight + pledit_disp_offs;
  499. if (!(mouse_stats & MK_CONTROL) && PlayList_getselect(wh))
  500. {
  501. int x,t=PlayList_getlength();
  502. for (x = 0; x < t; x ++)
  503. PlayList_setselect(x,0);
  504. PlayList_setselect(wh,1);
  505. {
  506. RECT r1={12,22,config_pe_width-20,config_pe_height-38};
  507. InvalidateRect(hwnd,&r1,FALSE);
  508. }
  509. }
  510. }
  511. stt=0;
  512. which_cap=0;
  513. }
  514. }
  515. }
  516. static void do_titlebar(HWND hwnd)
  517. {
  518. #ifdef FFSKIN
  519. if ((GetParent(hwnd) == NULL) && (which_cap == TITLE_CAP || (!which_cap && (config_easymove || mouse_y < 14))))
  520. #else
  521. if (which_cap == TITLE_CAP || (!which_cap && (config_easymove || mouse_y < 14)))
  522. #endif
  523. {
  524. static int clickx, clicky;
  525. switch (mouse_type)
  526. {
  527. case 1:
  528. which_cap=TITLE_CAP;
  529. clickx=mouse_x;
  530. clicky=mouse_y;
  531. break;
  532. case -1:
  533. which_cap=0;
  534. break;
  535. case 0:
  536. if (which_cap == TITLE_CAP && mouse_stats & MK_LBUTTON)
  537. {
  538. POINT p = { mouse_x,mouse_y};
  539. ClientToScreen(hwnd,&p);
  540. config_pe_wx = p.x-clickx;
  541. config_pe_wy = p.y-clicky;
  542. if ((!!config_snap) ^ (!!(mouse_stats & MK_SHIFT)))
  543. {
  544. RECT outrc;
  545. EstPLWindowRect(&outrc);
  546. SnapWindowToAllWindows(&outrc,hwnd);
  547. SetPLWindowRect(&outrc);
  548. }
  549. SetWindowPos(hwnd,0,config_pe_wx,config_pe_wy,0,0,SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);
  550. }
  551. break;
  552. }
  553. }
  554. }
  555. static void do_titlebuttons()
  556. {
  557. int w=0;
  558. w=inreg(config_pe_width-10,3,config_pe_width-1,3+9)?1:w;
  559. w=inreg(config_pe_width-20,3,config_pe_width-11,3+9)?2:w;
  560. if (w) // kill button
  561. {
  562. if (mouse_type == -1 && which_cap == TB_CAP)
  563. {
  564. which_cap=0;
  565. draw_pe_tbutton(0,0,0);
  566. SendMessageW(hMainWindow,WM_COMMAND,w==1?WINAMP_OPTIONS_PLEDIT:WINAMP_OPTIONS_WINDOWSHADE_PL,0);
  567. }
  568. else if (mouse_stats & MK_LBUTTON)
  569. {
  570. which_cap=TB_CAP;
  571. draw_pe_tbutton(w==2?1:0,w==1?1:0,config_pe_height==14?1:0);
  572. }
  573. }
  574. else if (which_cap == TB_CAP)
  575. {
  576. which_cap=0;
  577. draw_pe_tbutton(0,0,config_pe_height==14?1:0);
  578. }
  579. }
  580. static void do_size(HWND hwnd)
  581. {
  582. if (which_cap == SZ_CAP || (config_pe_height != 14 && !which_cap &&
  583. mouse_x > config_pe_width-20 && mouse_y > config_pe_height-20 &&
  584. ((config_pe_width-mouse_x + config_pe_height-mouse_y) <= 30))
  585. ||
  586. (config_pe_height == 14 && !which_cap && mouse_x > config_pe_width-29 && mouse_x < config_pe_width-20)
  587. )
  588. {
  589. static int dx,dy;
  590. if (!which_cap && mouse_type == 1)
  591. {
  592. dx=config_pe_width-mouse_x;
  593. dy=config_pe_height-mouse_y;
  594. which_cap=SZ_CAP;
  595. }
  596. if (which_cap == SZ_CAP)
  597. {
  598. int x,y;
  599. if (mouse_type == -1)
  600. {
  601. which_cap=0;
  602. }
  603. x=mouse_x + dx;
  604. y=mouse_y + dy;
  605. // if (x >= GetSystemMetrics(SM_CXSCREEN)) x = GetSystemMetrics(SM_CXSCREEN)-24;
  606. // if (y >= GetSystemMetrics(SM_CYSCREEN)) y = GetSystemMetrics(SM_CYSCREEN)-28;
  607. if (!config_embedwnd_freesize)
  608. {
  609. x += 24;
  610. x -= x%25;
  611. y += 28;
  612. y -= y%29;
  613. }
  614. if (x < 275) x = 275;
  615. if (y < 20+38+29+29) y = 20+38+29+29;
  616. config_pe_width = x;
  617. if (config_pe_height != 14) config_pe_height= y;
  618. SetWindowPos(hwnd,0,0,0,config_pe_width,config_pe_height,SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE);
  619. if (hPLVisWindow)
  620. {
  621. int x,y,w,h;
  622. x=config_pe_width-150-75+2;
  623. y=config_pe_height-26;
  624. w=(config_pe_width >= 350 && config_pe_height != 14 ? 72 : 0);
  625. h=16;
  626. SetWindowPos(hPLVisWindow,0,x,y,w,h,SWP_NOZORDER|SWP_NOACTIVATE);
  627. }
  628. }
  629. }
  630. }
  631. static void do_vscroll(HWND hwnd)
  632. {
  633. int top=20,bottom=config_pe_height-38;
  634. int num_songs=(config_pe_height-38-20-2)/pe_fontheight;
  635. int xoffs=config_pe_width-15,w=8;
  636. if (inreg(xoffs,top,xoffs+w,bottom) || which_cap == VS_CAP)
  637. {
  638. if ((!which_cap && mouse_type == 1) || which_cap == VS_CAP)
  639. {
  640. int d;
  641. int p;
  642. static int click_yoffs=9;
  643. int a=PlayList_getlength()-num_songs;
  644. {
  645. if (a < 1) p = top;
  646. else
  647. {
  648. p = top + ((config_pe_height-38-20-18)*pledit_disp_offs) / a;
  649. }
  650. }
  651. if (mouse_type == 1 && mouse_y >= p && mouse_y < p + 20)
  652. {
  653. click_yoffs=mouse_y - p -1;
  654. } else if (mouse_type == 1) click_yoffs=9;
  655. d=((mouse_y-click_yoffs-top)*a)/(config_pe_height-38-20-18);
  656. pledit_disp_offs = d;
  657. if (pledit_disp_offs > a) pledit_disp_offs = a;
  658. draw_pe_vslide(hwnd, NULL, 1,pledit_disp_offs);
  659. {
  660. RECT r={12,22,config_pe_width-19,config_pe_height-37};
  661. InvalidateRect(hwnd,&r,FALSE);
  662. }
  663. if (mouse_type == -1)
  664. {
  665. draw_pe_vslide(hwnd, NULL, 0,pledit_disp_offs);
  666. which_cap=0;
  667. } else
  668. {
  669. which_cap = VS_CAP;
  670. }
  671. }
  672. }
  673. }
  674. static const RECT b_normal[] =
  675. {
  676. {-(275-254),3,-(275-262),12},//wshade
  677. {-(275-264),3,-(275-272),12},//close
  678. {0,0,-1,13},// titelbar
  679. {-15,20,-7,-38},
  680. {-20,-20,-1,-1},
  681. },
  682. b_windowshade[] =
  683. {
  684. {-(275-254),3,-(275-262),12},//wshade
  685. {-(275-264),3,-(275-272),12},//close
  686. {-29,3,-20,12},//size
  687. };
  688. void pe_ui_handlecursor(HWND hwnd)
  689. {
  690. int mouse_x, mouse_y;
  691. POINT p;
  692. const RECT *b;
  693. int b_len;
  694. int x;
  695. if (!config_usecursors || disable_skin_cursors) return;
  696. GetCursorPos(&p);
  697. ScreenToClient(hwnd,&p);
  698. mouse_x=p.x;
  699. mouse_y=p.y;
  700. if (config_pe_height == 14)
  701. {
  702. b=b_windowshade;
  703. b_len = sizeof(b_windowshade)/sizeof(b_windowshade[0]);
  704. }
  705. else
  706. {
  707. b=b_normal;
  708. b_len = sizeof(b_normal)/sizeof(b_normal[0]);
  709. }
  710. for (x = 0; x < b_len; x ++)
  711. {
  712. int l,r,t,bo;
  713. l=b[x].left;r=b[x].right;t=b[x].top;bo=b[x].bottom;
  714. if (l < 0) l += config_pe_width;
  715. if (r < 0) r += config_pe_width;
  716. if (t < 0) t += config_pe_height;
  717. if (bo < 0) bo += config_pe_height;
  718. if (inreg(l,t,r,bo)) break;
  719. }
  720. if (config_pe_height == 14) x+=21;
  721. else x+=15;
  722. if (Skin_Cursors[x]) SetCursor(Skin_Cursors[x]);
  723. else SetCursor(LoadCursor(NULL,IDC_ARROW));
  724. }