main_mouse.cpp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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 "../Plugins/General/gen_ml/ml.h"
  11. extern "C" HMENU g_submenus_vis;
  12. #include "../Plugins/General/gen_ml/ml_ipc.h"
  13. extern librarySendToMenuStruct mainSendTo;
  14. #include "../Plugins/General/gen_ml/menufucker.h"
  15. void ScaleMouseButtons(int &x, int &y)
  16. {
  17. if (config_dsize)
  18. {
  19. x /= 2;
  20. y /= 2;
  21. }
  22. }
  23. // Pops up a menu on right click
  24. int Main_OnRButtonUp(HWND hwnd, int x, int y, UINT flags)
  25. {
  26. HMENU hmenu=main_menu;
  27. POINT p;
  28. if ((flags & MK_LBUTTON)) return 1;
  29. GetCursorPos(&p);
  30. ScaleMouseButtons(x,y);
  31. if (x < 266 && x > 105 && y < 35 && y > 24)
  32. {
  33. int rating = 0;
  34. static HMENU ratingmenu = NULL;
  35. hmenu = GetSubMenu(GetSubMenu(top_menu,3),0);
  36. CheckMenuItem(hmenu,WINAMP_TOGGLE_AUTOSCROLL,(config_autoscrollname&1)?MF_CHECKED:MF_UNCHECKED);
  37. rating = sendMlIpc(ML_IPC_GETRATING, 0);
  38. // deal with no ml being present and querying the rating of a file from the tag (if possible)
  39. // as well as getting a zero rating which could mean that it's not present in the library
  40. if (!rating && !got_ml)
  41. {
  42. wchar_t fn[FILENAME_SIZE] = {0};
  43. if (!PlayList_getitem2W(PlayList_getPosition(), fn, NULL))
  44. {
  45. wchar_t buf[64] = {0};
  46. in_get_extended_fileinfoW(fn, L"rating", buf, 64);
  47. rating = _wtoi(buf);
  48. }
  49. }
  50. if(!IsMenu(ratingmenu))
  51. {
  52. ratingmenu = GetSubMenu(hmenu, 5);
  53. }
  54. CheckMenuItem(ratingmenu, ID_RATING5, (rating == 5) ? MF_CHECKED : MF_UNCHECKED);
  55. CheckMenuItem(ratingmenu, ID_RATING4, (rating == 4) ? MF_CHECKED : MF_UNCHECKED);
  56. CheckMenuItem(ratingmenu, ID_RATING3, (rating == 3) ? MF_CHECKED : MF_UNCHECKED);
  57. CheckMenuItem(ratingmenu, ID_RATING2, (rating == 2) ? MF_CHECKED : MF_UNCHECKED);
  58. CheckMenuItem(ratingmenu, ID_RATING1, (rating == 1) ? MF_CHECKED : MF_UNCHECKED);
  59. CheckMenuItem(ratingmenu, ID_RATING0, (rating == 0) ? MF_CHECKED : MF_UNCHECKED);
  60. LRESULT IPC_LIBRARY_SENDTOMENU = wa_register_ipc((WPARAM)&"LibrarySendToMenu");
  61. HMENU menu = 0;
  62. memset(&mainSendTo, 0, sizeof(mainSendTo));
  63. if (IPC_LIBRARY_SENDTOMENU > 65536 && SendMessageW(hMainWindow, WM_WA_IPC, (WPARAM)0, IPC_LIBRARY_SENDTOMENU) == 0xffffffff)
  64. {
  65. MENUITEMINFOW mii = {sizeof(mii), MIIM_SUBMENU | MIIM_TYPE, MFT_STRING, };
  66. mii.hSubMenu = menu = CreatePopupMenu();
  67. mii.dwTypeData = getStringW(IDS_SENDTO_STR,NULL,0);
  68. mii.cch = (UINT)wcslen(mii.dwTypeData);
  69. InsertMenuItemW(hmenu, 4, TRUE, &mii);
  70. mainSendTo.mode = 1;
  71. mainSendTo.hwnd = hwnd;
  72. mainSendTo.data_type = ML_TYPE_FILENAMESW;
  73. mainSendTo.build_hMenu = menu;
  74. }
  75. menufucker_t mf = {sizeof(mf),MENU_SONGTICKER,hmenu,0x3000,0x4000,0};
  76. pluginMessage message_build = {(int)wa_register_ipc((WPARAM)&"menufucker_build"),(intptr_t)&mf,0};
  77. sendMlIpc(ML_IPC_SEND_PLUGIN_MESSAGE,(WPARAM)&message_build);
  78. int ret = DoTrackPopup(hmenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD, p.x, p.y, hwnd);
  79. pluginMessage message_result = {(int)wa_register_ipc((WPARAM)&"menufucker_result"),(intptr_t)&mf,ret,0};
  80. sendMlIpc(ML_IPC_SEND_PLUGIN_MESSAGE,(WPARAM)&message_result);
  81. if (menu)
  82. {
  83. if (mainSendTo.mode == 2)
  84. {
  85. mainSendTo.menu_id = ret;
  86. if (SendMessageW(hMainWindow, WM_WA_IPC, (WPARAM)&mainSendTo, IPC_LIBRARY_SENDTOMENU) == 0xffffffff)
  87. {
  88. wchar_t buf[1041] = {0};
  89. wchar_t *end=buf;
  90. size_t endSize;
  91. StringCchCopyExW(buf, 1040, FileName, &end, &endSize, 0);
  92. end[1]=0; // double null terminate (since we passed 1040 for a 1041 size buffer, this is always safe)
  93. mainSendTo.mode = 3;
  94. mainSendTo.data = buf;
  95. mainSendTo.data_type = ML_TYPE_FILENAMESW;
  96. SendMessageW(hMainWindow, WM_WA_IPC, (WPARAM)&mainSendTo, IPC_LIBRARY_SENDTOMENU);
  97. }
  98. }
  99. // remove sendto
  100. DeleteMenu(hmenu, 4, MF_BYPOSITION);
  101. }
  102. if (mainSendTo.mode)
  103. {
  104. mainSendTo.mode = 4;
  105. SendMessageW(hMainWindow, WM_WA_IPC, (WPARAM)&mainSendTo, IPC_LIBRARY_SENDTOMENU); // cleanup
  106. memset(&mainSendTo, 0, sizeof(mainSendTo));
  107. }
  108. if (ret) SendMessageW(hwnd, WM_COMMAND, ret, 0);
  109. return 1;
  110. }
  111. else if ((!config_windowshade && x >= 36 && y >= 26 && x < 96 && y < 39) ||
  112. (config_windowshade && x >= 129 && y >= 3 && x < 129+28 && y < 3+6))
  113. {
  114. hmenu = GetSubMenu(GetSubMenu(top_menu,3),1);
  115. CheckMenuItem(hmenu,WINAMP_OPTIONS_ELAPSED,config_timeleftmode?MF_UNCHECKED:MF_CHECKED);
  116. CheckMenuItem(hmenu,WINAMP_OPTIONS_REMAINING,config_timeleftmode?MF_CHECKED:MF_UNCHECKED);
  117. }
  118. else if ((x >= 27 && y >= 40 && x < 99 && y < 61) ||
  119. (config_windowshade && x >= 78 && y >= 4 && x < 116 && y < 11))
  120. {
  121. hmenu=g_submenus_vis;
  122. }
  123. else if ((x >= 16 && y >= 88 && x < 37 && y < 106) || /// button 1
  124. (config_windowshade && x >= 167 && y >= 3 && x < 176 && y < 12))
  125. {
  126. hmenu = GetSubMenu(GetSubMenu(top_menu,3),2);
  127. }
  128. else if ((x >= 37 && y >= 88 && x < 62 && y < 106) || /// button 2
  129. (config_windowshade && x >= 176 && y >= 3 && x < 186 && y < 12))
  130. {
  131. hmenu = GetSubMenu(GetSubMenu(top_menu,3),3);
  132. }
  133. else if ((x >= 62 && y >= 88 && x < 89 && y < 106) || /// button 3
  134. (config_windowshade && x >= 186 && y >= 3 && x < 196 && y < 12))
  135. {
  136. hmenu = GetSubMenu(GetSubMenu(top_menu,3),4);
  137. }
  138. else if ((x >= 89 && y >= 88 && x < 107 && y < 106) || /// button 4
  139. (config_windowshade && x >= 196 && y >= 3 && x < 206 && y < 12))
  140. {
  141. hmenu = GetSubMenu(GetSubMenu(top_menu,3),5);
  142. }
  143. else if ((x >= 107 && y >= 88 && x < 130 && y < 106) || /// button 5
  144. (config_windowshade && x >= 206 && y >= 3 && x < 216 && y < 12))
  145. {
  146. hmenu = GetSubMenu(GetSubMenu(top_menu,3),6);
  147. }
  148. else if ((x >= 136 && y >= 89 && x < 158 && y < 105) || /// eject
  149. (config_windowshade && x >= 215 && y >= 3 && x < 225 && y < 12))
  150. {
  151. hmenu = GetSubMenu(GetSubMenu(top_menu,3),7);
  152. UpdateAudioCDMenus(hmenu);
  153. }
  154. else if (playing && (in_mod && in_mod->is_seekable) && x >= 18 && y >= 73 && x < 263 && y < 81)
  155. {
  156. hmenu = GetSubMenu(GetSubMenu(top_menu,3),8);
  157. }
  158. else if (x >= 164 && y >= 89 && x < 211 && y < 104) /// shuffle
  159. {
  160. hmenu = GetSubMenu(GetSubMenu(top_menu,3),9);
  161. CheckMenuItem(hmenu,WINAMP_FILE_SHUFFLE,config_shuffle?MF_CHECKED:MF_UNCHECKED);
  162. }
  163. else if (x >= 211 && y >= 89 && x < 211+28 && y < 104) /// repeat
  164. {
  165. hmenu = GetSubMenu(GetSubMenu(top_menu,3),10);
  166. CheckMenuItem(hmenu,WINAMP_FILE_REPEAT,config_repeat?MF_CHECKED:MF_UNCHECKED);
  167. CheckMenuItem(hmenu,WINAMP_FILE_MANUALPLADVANCE,config_pladv?MF_UNCHECKED:MF_CHECKED);
  168. }
  169. else if (x >= 219 && y >= 58 && x < 219+(265-219)/2 && y < 70) /// eq
  170. {
  171. hmenu = GetSubMenu(GetSubMenu(top_menu,3),11);
  172. CheckMenuItem(hmenu,WINAMP_OPTIONS_EQ,config_eq_open?MF_CHECKED:MF_UNCHECKED);
  173. }
  174. else if (x >= 219+(265-219)/2 && y >= 58 && x < 265 && y < 70) /// pe
  175. {
  176. hmenu = GetSubMenu(GetSubMenu(top_menu,3),12);
  177. CheckMenuItem(hmenu,WINAMP_OPTIONS_PLEDIT,config_pe_open?MF_CHECKED:MF_UNCHECKED);
  178. }
  179. DoTrackPopup(hmenu, TPM_LEFTALIGN|TPM_RIGHTBUTTON, p.x, p.y, hwnd);
  180. return 1;
  181. }
  182. // Doubleclick handler. Checks for a few regions, and usually does nothing,
  183. // except pass on a WM_LBUTTONDOWN.
  184. int Main_OnLButtonDblClk(HWND hwnd, BOOL fDoubleClick, int x, int y, UINT keyFlags)
  185. {
  186. int nx=x, ny=y;
  187. ScaleMouseButtons(nx,ny);
  188. if (nx <= 16 && nx >= 6 && ny <= 12 && ny >= 4)
  189. {
  190. KillTimer(hwnd,666);
  191. SendMessageW(hwnd,WM_CLOSE,0xDEADBEEF,0xDEADF00D);
  192. }
  193. else if (config_windowshade && nx <= 158 && nx >= 129 &&
  194. ny <= 10 && ny >= 5)
  195. Main_OnLButtonDown(hwnd,0,x,y,keyFlags);
  196. else if (config_windowshade && nx <= 213 && nx >= 168 &&
  197. ny <= 11 && ny >= 2)
  198. Main_OnLButtonDown(hwnd,0,x,y,keyFlags);
  199. else if (nx < 266 && nx > 117 && ny < 35 && ny > 24)
  200. {
  201. SendMessageW(hwnd,WM_COMMAND,WINAMP_EDIT_ID3,0);
  202. }
  203. else if ((nx >= 24 && ny >= 43 && nx < 24+76 && ny < 43+16) ||
  204. (config_windowshade && nx >= 79 && ny >= 5 && nx < 79+38 && ny < 5+5))
  205. {
  206. if (config_windowshade) config_sa = !config_sa;
  207. else
  208. {
  209. config_sa+=2;
  210. config_sa %= 3;
  211. }
  212. sa_setthread(config_sa);
  213. if (vis_running()) vis_stop();
  214. else vis_start(hMainWindow,NULL);
  215. }
  216. else if (ny < 15 && nx < 244)
  217. {
  218. SendMessageW(hwnd,WM_COMMAND,WINAMP_OPTIONS_WINDOWSHADE,0);
  219. UpdateWindow(hwnd);
  220. Sleep(200);
  221. for (;;)
  222. {
  223. MSG msg;
  224. if (!PeekMessage(&msg,hMainWindow,WM_MOUSEFIRST,WM_MOUSELAST,PM_REMOVE))
  225. break;
  226. }
  227. }
  228. else Main_OnLButtonDown(hwnd,0,x,y,keyFlags);
  229. return 1;
  230. }
  231. int Main_OnCaptureChanged(HWND hwnd)
  232. {
  233. if (hwnd != hMainWindow)
  234. ui_handlemouseevent(0,0,-2,0);
  235. return 0;
  236. }
  237. // Mouseup handler. Just passes to routines in ui.c, scaling if in doublesize mode
  238. int Main_OnLButtonUp(HWND hwnd, int x, int y, UINT flags)
  239. {
  240. ScaleMouseButtons(x,y);
  241. ui_handlemouseevent(x,y,-1,flags);
  242. ReleaseCapture();
  243. return 1;
  244. }
  245. // Mousedown handler. Just passes to routines in ui.c, scaling if in doublesize mode
  246. int Main_OnLButtonDown(HWND hwnd, BOOL fDoubleClick, int x, int y, UINT keyFlags)
  247. {
  248. ScaleMouseButtons(x,y);
  249. SetCapture(hwnd);
  250. ui_handlemouseevent(x,y,1,keyFlags);
  251. return 1;
  252. }
  253. // Mousemove handler. Just passes to routines in ui.c, scaling if in doublesize mode
  254. int Main_OnMouseMove(HWND hwnd, int x, int y, UINT keyFlags)
  255. {
  256. ScaleMouseButtons(x,y);
  257. ui_handlemouseevent(x,y,0,keyFlags);
  258. return 1;
  259. }