1
0

sendto.cpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. #include "main.h"
  2. #include <windowsx.h>
  3. #include "resource.h"
  4. #include "config.h"
  5. #include "sendto.h"
  6. #include "api__gen_ml.h"
  7. #include "../nu/AutoWideFn.h"
  8. #include "../Winamp/strutil.h"
  9. SendToMenu::SendToMenu()
  10. {
  11. activePlaylist=0;
  12. m_addtolibrary=0;
  13. _hm=0;
  14. branch=0;
  15. branch_pos=0;
  16. _pos=0;
  17. _len=0;
  18. _start=0;
  19. m_start=0;
  20. m_len=0;
  21. plugin_start=0;
  22. plugin_len=0;
  23. }
  24. SendToMenu::~SendToMenu()
  25. {
  26. }
  27. void SendToMenu::onAddItem(mlAddToSendToStruct *ptr)
  28. {
  29. if (--_len < 0)
  30. return;
  31. MENUITEMINFOA mii= {sizeof(MENUITEMINFOA),};
  32. if (ptr->desc && *ptr->desc == '-')
  33. {
  34. // cannot insert a seperator at the top
  35. if (_pos <= 2) return;
  36. mii.fMask = MIIM_TYPE;
  37. mii.fType = MFT_SEPARATOR;
  38. }
  39. else
  40. {
  41. mii.fMask = MIIM_TYPE | MIIM_ID | MIIM_DATA | MIIM_STATE;
  42. mii.fType = MFT_STRING;
  43. if (ptr->desc && *ptr->desc == '#')
  44. {
  45. mii.fState = MFS_GRAYED;
  46. mii.dwTypeData = ptr->desc+1;
  47. }
  48. else
  49. {
  50. mii.fState = MFS_ENABLED;
  51. mii.dwTypeData = ptr->desc;
  52. }
  53. mii.wID = _start++;
  54. mii.dwItemData = ptr->user32;
  55. mii.cch = (UINT)strlen(mii.dwTypeData);
  56. }
  57. InsertMenuItemA(_hm,_pos++,TRUE,&mii);
  58. }
  59. void SendToMenu::onAddItem(mlAddToSendToStructW *ptr)
  60. {
  61. if (--_len < 0)
  62. return;
  63. MENUITEMINFOW mii= {sizeof(MENUITEMINFOW),};
  64. if (ptr->desc && *ptr->desc == L'-')
  65. {
  66. // cannot insert a seperator at the top
  67. if (_pos <= 2) return;
  68. mii.fMask = MIIM_TYPE;
  69. mii.fType = MFT_SEPARATOR;
  70. }
  71. else
  72. {
  73. mii.fMask = MIIM_TYPE | MIIM_ID | MIIM_DATA | MIIM_STATE;
  74. mii.fType = MFT_STRING;
  75. if (ptr->desc && *ptr->desc == L'#')
  76. {
  77. mii.fState = MFS_GRAYED;
  78. mii.dwTypeData = ptr->desc+1;
  79. }
  80. else
  81. {
  82. mii.fState = MFS_ENABLED;
  83. mii.dwTypeData = ptr->desc;
  84. }
  85. mii.wID = _start++;
  86. mii.dwItemData = ptr->user32;
  87. mii.cch = (UINT)wcslen(mii.dwTypeData);
  88. }
  89. InsertMenuItemW(_hm,_pos++,TRUE,&mii);
  90. }
  91. void SendToMenu::addItemToBranch(mlAddToSendToStructW *ptr)
  92. {
  93. if (!branch)
  94. return;
  95. if (--_len < 0)
  96. return;
  97. MENUITEMINFOW mii= {sizeof(MENUITEMINFOW),};
  98. if (ptr->desc && *ptr->desc == L'-')
  99. {
  100. // cannot insert a seperator at the top
  101. if (_pos <= 2) return;
  102. mii.fMask = MIIM_TYPE;
  103. mii.fType = MFT_SEPARATOR;
  104. }
  105. else
  106. {
  107. mii.fMask = MIIM_TYPE | MIIM_ID | MIIM_DATA | MIIM_STATE;
  108. mii.fType = MFT_STRING;
  109. if (ptr->desc && *ptr->desc == L'#')
  110. {
  111. mii.fState = MFS_GRAYED;
  112. mii.dwTypeData = ptr->desc+1;
  113. }
  114. else
  115. {
  116. mii.fState = MFS_ENABLED;
  117. mii.dwTypeData = ptr->desc;
  118. }
  119. mii.wID = _start++;
  120. mii.dwItemData = ptr->user32;
  121. mii.cch = (UINT)wcslen(mii.dwTypeData);
  122. }
  123. InsertMenuItemW(branch,branch_pos++,TRUE,&mii);
  124. }
  125. void SendToMenu::startBranch()
  126. {
  127. branch=CreateMenu();
  128. branch_pos=0;
  129. }
  130. void SendToMenu::endBranch(const wchar_t *name)
  131. {
  132. MENUITEMINFOW mii=
  133. {
  134. sizeof(MENUITEMINFOW),
  135. MIIM_TYPE|MIIM_DATA|MIIM_SUBMENU,
  136. MFT_STRING,
  137. MFS_ENABLED,
  138. 0,
  139. branch,
  140. NULL,
  141. NULL,
  142. 0,
  143. (LPWSTR)name,
  144. };
  145. mii.cch= (UINT)wcslen(mii.dwTypeData);
  146. InsertMenuItemW(_hm,_pos++,TRUE,&mii);
  147. branch=0;
  148. }
  149. void SendToMenu::buildmenu(HMENU hMenu, int type, int simple, int true_type, int start, int len)
  150. {
  151. _start=start;
  152. _len=len;
  153. _hm=hMenu;
  154. _pos=0;
  155. m_start=_start;
  156. plugin_start=0;
  157. while (DeleteMenu(hMenu,0,MF_BYPOSITION));
  158. if (type == ML_TYPE_ITEMRECORDLIST || type == ML_TYPE_FILENAMES ||
  159. type == ML_TYPE_ITEMRECORDLISTW || type == ML_TYPE_FILENAMESW ||
  160. type == ML_TYPE_STREAMNAMES || type == ML_TYPE_CDTRACKS)
  161. {
  162. activePlaylist=_start++; _len--;
  163. // hardcode playlists :)
  164. MENUITEMINFOW mii=
  165. {
  166. sizeof(MENUITEMINFO),
  167. MIIM_TYPE|MIIM_ID,
  168. MFT_STRING,
  169. MFS_ENABLED,
  170. (UINT)activePlaylist,
  171. NULL,
  172. NULL,
  173. NULL,
  174. 0,
  175. };
  176. if(simple == FALSE)
  177. {
  178. mii.dwTypeData = WASABI_API_LNGSTRINGW(IDS_ENQUEUE_IN_WINAMP);
  179. mii.cch = (UINT)wcslen(mii.dwTypeData);
  180. InsertMenuItemW(hMenu,_pos++,TRUE,&mii);
  181. mii.fType = MFT_SEPARATOR;
  182. mii.wID=0;
  183. InsertMenuItemW(hMenu,_pos++,TRUE,&mii);
  184. }
  185. }
  186. plugin_start=_start;
  187. plugin_SendMessage(ML_MSG_ONSENDTOBUILD,type,reinterpret_cast<INT_PTR>(this),(true_type-1));
  188. plugin_len=_start - plugin_start;
  189. m_len=_start-m_start;
  190. }
  191. int SendToMenu::isourcmd(int id)
  192. {
  193. return id >= m_start && id < m_start+m_len;
  194. }
  195. void TAG_FMT_EXT(const wchar_t *filename, void *f, void *ff, void *p, wchar_t *out, int out_len, int extended);
  196. wchar_t *itemrecordTagFunc(wchar_t *tag, void * p);
  197. wchar_t *itemrecordWTagFunc(wchar_t *tag, void * p);
  198. void fieldTagFuncFree(wchar_t * tag, void * p);
  199. int SendToMenu::handlecmd(HWND hwndParent, int id, int type, void *data)
  200. {
  201. if (!isourcmd(id))
  202. return 0;
  203. if (plugin_start && id >= plugin_start && id < plugin_start+plugin_len)
  204. {
  205. MENUITEMINFO i={sizeof(i),MIIM_DATA,};
  206. GetMenuItemInfo(_hm,id,FALSE,&i);
  207. return (INT)plugin_SendMessage(ML_MSG_ONSENDTOSELECT,type,reinterpret_cast<INT_PTR>(data),i.dwItemData);
  208. }
  209. else if (activePlaylist && id == activePlaylist)
  210. {
  211. if (type == ML_TYPE_FILENAMES || type == ML_TYPE_STREAMNAMES)
  212. {
  213. char *ptr=(char*)data;
  214. while (ptr && *ptr)
  215. {
  216. COPYDATASTRUCT cds;
  217. cds.dwData = IPC_PLAYFILE;
  218. cds.lpData = (void *) ptr;
  219. cds.cbData = (DWORD)strlen((char *)cds.lpData)+1; // include space for null char
  220. SendMessage(plugin.hwndParent,WM_COPYDATA,(WPARAM)NULL,(LPARAM)&cds);
  221. ptr+=strlen(ptr)+1;
  222. }
  223. return 1;
  224. }
  225. else if (type == ML_TYPE_FILENAMESW || type == ML_TYPE_STREAMNAMESW)
  226. {
  227. wchar_t *ptr=(wchar_t*)data;
  228. while (ptr && *ptr)
  229. {
  230. COPYDATASTRUCT cds;
  231. cds.dwData = IPC_PLAYFILEW;
  232. cds.lpData = (void *) ptr;
  233. cds.cbData = (DWORD)sizeof(wchar_t) * wcslen((wchar_t *)cds.lpData) + sizeof(wchar_t); // include space for null char
  234. SendMessage(plugin.hwndParent,WM_COPYDATA,(WPARAM)NULL,(LPARAM)&cds);
  235. ptr+=wcslen(ptr)+1;
  236. }
  237. return 1;
  238. }
  239. else if (type == ML_TYPE_ITEMRECORDLIST)
  240. {
  241. wchar_t title[FILETITLE_SIZE] = {0};
  242. itemRecordList *obj = (itemRecordList *)data;
  243. for (int i=0;i < obj->Size;i++)
  244. {
  245. AutoWideFn wfn( obj->Items[ i ].filename );
  246. TAG_FMT_EXT(wfn, itemrecordTagFunc, fieldTagFuncFree, (void*)&obj->Items[i], title, FILETITLE_SIZE, 1);
  247. enqueueFileWithMetaStructW enqueueFile;
  248. enqueueFile.filename = wfn;
  249. enqueueFile.title = title;
  250. enqueueFile.ext = NULL;
  251. enqueueFile.length = obj->Items[i].length;
  252. SendMessage(plugin.hwndParent, WM_WA_IPC, (WPARAM)&enqueueFile, IPC_PLAYFILEW);
  253. }
  254. return 1;
  255. }
  256. else if (type == ML_TYPE_ITEMRECORDLISTW)
  257. {
  258. wchar_t title[FILETITLE_SIZE] = {0};
  259. itemRecordListW *obj = (itemRecordListW *)data;
  260. for (int i=0;i < obj->Size;i++)
  261. {
  262. TAG_FMT_EXT(obj->Items[i].filename, itemrecordWTagFunc, fieldTagFuncFree, (void*)&obj->Items[i], title, FILETITLE_SIZE, 1);
  263. enqueueFileWithMetaStructW enqueueFile;
  264. enqueueFile.filename = obj->Items[i].filename;
  265. enqueueFile.title = title;
  266. enqueueFile.ext = NULL;
  267. enqueueFile.length = obj->Items[i].length;
  268. SendMessage(plugin.hwndParent, WM_WA_IPC, (WPARAM)&enqueueFile, IPC_PLAYFILEW);
  269. }
  270. return 1;
  271. }
  272. }
  273. return 0;
  274. }