view_pmp_devices.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  1. #include "main.h"
  2. #include <windows.h>
  3. #include <windowsx.h>
  4. #include <stdio.h>
  5. #include <shlobj.h>
  6. #include "..\..\General\gen_ml/ml.h"
  7. #include "..\..\General\gen_ml/itemlist.h"
  8. #include "../nu/listview.h"
  9. #include "..\..\General\gen_ml/childwnd.h"
  10. #include "../winamp/wa_ipc.h"
  11. #include "../winamp/wa_dlg.h"
  12. #include "resource1.h"
  13. #include "SkinnedListView.h"
  14. #include "DeviceView.h"
  15. #include "api__ml_pmp.h"
  16. #include "metadata_utils.h"
  17. static int (*wad_handleDialogMsgs)(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  18. static void (*wad_DrawChildWindowBorders)(HWND hwndDlg, int *tab, int tabsize);
  19. static void (*cr_init)(HWND hwndDlg, ChildWndResizeItem *list, int num);
  20. static void (*cr_resize)(HWND hwndDlg, ChildWndResizeItem *list, int num);
  21. static HWND m_hwnd;
  22. static ChildWndResizeItem resize_rlist[]=
  23. {
  24. {IDC_LIST_DEVICES, 0x0010},
  25. {IDC_LIST_TRANSFERS, 0x0011},
  26. {IDC_TQ_STATIC, 0x0000},
  27. {IDC_HDELIM, 0x0010},
  28. {IDC_BUTTON_PAUSETRANSFERS, 0x0101},
  29. {IDC_BUTTON_CLEARFINISHED, 0x0101},
  30. {IDC_BUTTON_REMOVESELECTED, 0x0101},
  31. {IDC_STATUS,0x0111},
  32. };
  33. static int m_nodrawtopborders=0,adiv_clickoffs,adivpos=-1;
  34. SkinnedListView * listDevices=NULL;
  35. static SkinnedListView * listTransfers=NULL;
  36. //CRITICAL_SECTION listTransfersLock;
  37. static INT_PTR CALLBACK adiv_newWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam);
  38. static void adiv_UpdPos(int xp);
  39. static WNDPROC adiv_oldWndProc;
  40. class DeviceContents : public ListContents
  41. {
  42. public:
  43. virtual int GetNumColumns()
  44. {
  45. return 2;
  46. }
  47. virtual int GetNumRows()
  48. {
  49. return devices.GetSize();
  50. }
  51. virtual wchar_t * GetColumnTitle(int num)
  52. {
  53. switch (num)
  54. {
  55. case 0: return WASABI_API_LNGSTRINGW(IDS_NAME);
  56. case 1: return WASABI_API_LNGSTRINGW(IDS_CAPACITY_FREE);
  57. }
  58. return L"";
  59. }
  60. virtual int GetColumnWidth(int num)
  61. {
  62. switch (num)
  63. {
  64. case 0: return global_config->ReadInt(L"devices_col0_width",150);
  65. case 1: return global_config->ReadInt(L"devices_col1_width",100);
  66. default: return 0;
  67. }
  68. }
  69. virtual void ColumnResize(int col, int newWidth)
  70. {
  71. if (col==0) global_config->WriteInt(L"devices_col0_width",newWidth);
  72. else if (col==1) global_config->WriteInt(L"devices_col1_width",newWidth);
  73. }
  74. virtual void GetCellText(int row, int col, wchar_t * buf, int buflen)
  75. {
  76. switch (col)
  77. {
  78. case 0:
  79. ((DeviceView *)devices.Get(row))->dev->getPlaylistName(0,buf,buflen);
  80. return;
  81. case 1:
  82. {
  83. wchar_t capacity[20]=L"";
  84. Device * dev = ((DeviceView *)devices.Get(row))->dev;
  85. WASABI_API_LNG->FormattedSizeString(capacity, ARRAYSIZE(capacity), dev->getDeviceCapacityTotal());
  86. __int64 cap = dev->getDeviceCapacityTotal();
  87. int pc;
  88. if (cap) pc = (int)((((__int64)100)*dev->getDeviceCapacityAvailable()) / cap);
  89. else pc = 0;
  90. wsprintf(buf,L"%s (%d%%)",capacity,pc);
  91. }
  92. return;
  93. }
  94. }
  95. virtual songid_t GetTrack(int pos) { return 0; }
  96. };
  97. static DeviceContents deviceListContents;
  98. class TransferItemShadow
  99. {
  100. public:
  101. CopyInst * c;
  102. wchar_t * status, * type, * track;
  103. wchar_t device[128];
  104. bool changed;
  105. TransferItemShadow(CopyInst * c)
  106. {
  107. changed = false;
  108. this->c = c;
  109. status = _wcsdup(c->statusCaption);
  110. type = _wcsdup(c->typeCaption);
  111. track = _wcsdup(c->trackCaption);
  112. device[0] = 0;
  113. c->dev->dev->getPlaylistName(0,device,128);
  114. }
  115. ~TransferItemShadow()
  116. {
  117. free(status);
  118. free(type);
  119. free(track);
  120. }
  121. bool Equals(TransferItemShadow * a)
  122. {
  123. if (!a) return false;
  124. return (c == a->c) && !wcscmp(track,a->track) && !wcscmp(status,a->status) && !wcscmp(device,a->device) && !wcscmp(type,a->type);
  125. }
  126. };
  127. static C_ItemList *getTransferListShadow()
  128. {
  129. C_ItemList * list = new C_ItemList;
  130. for (int i=0; i < devices.GetSize(); i++)
  131. {
  132. DeviceView *device = (DeviceView*)devices.Get(i);
  133. LinkedQueue * txQueue = getTransferQueue(device);
  134. LinkedQueue * finishedTX = getFinishedTransferQueue(device);
  135. if (txQueue)
  136. {
  137. txQueue->lock();
  138. int l = txQueue->GetSize();
  139. for (int j=0; j<l; j++)
  140. list->Add(new TransferItemShadow((CopyInst*)txQueue->Get(j)));
  141. txQueue->unlock();
  142. }
  143. if (finishedTX)
  144. {
  145. finishedTX->lock();
  146. int l = finishedTX->GetSize();
  147. for (int j=0; j<l; j++)
  148. list->Add(new TransferItemShadow((CopyInst*)finishedTX->Get(j)));
  149. finishedTX->unlock();
  150. }
  151. }
  152. return list;
  153. }
  154. class TransferContents2 : public ListContents
  155. {
  156. public:
  157. CRITICAL_SECTION cs;
  158. C_ItemList * listShadow;
  159. TransferContents2() : listShadow(0)
  160. {
  161. oldSize = 0;
  162. listShadow = getTransferListShadow();
  163. InitializeCriticalSection(&cs);
  164. }
  165. virtual ~TransferContents2()
  166. {
  167. DeleteCriticalSection(&cs); delete listShadow;
  168. }
  169. virtual int GetNumColumns()
  170. {
  171. return 4;
  172. }
  173. virtual int GetNumRows()
  174. {
  175. return (listShadow ? listShadow->GetSize() : 0);
  176. }
  177. virtual wchar_t * GetColumnTitle(int num)
  178. {
  179. switch (num)
  180. {
  181. case 0: return WASABI_API_LNGSTRINGW(IDS_TYPE);
  182. case 1: return WASABI_API_LNGSTRINGW(IDS_TRACK);
  183. case 2: return WASABI_API_LNGSTRINGW(IDS_STATUS);
  184. case 3: return WASABI_API_LNGSTRINGW(IDS_DEVICE);
  185. }
  186. return L"";
  187. }
  188. virtual int GetColumnWidth(int num)
  189. {
  190. switch (num)
  191. {
  192. case 0: return global_config->ReadInt(L"transfers_col0_width",100);
  193. case 1: return global_config->ReadInt(L"transfers_col1_width",300);
  194. case 2: return global_config->ReadInt(L"transfers_col2_width",150);
  195. case 3: return global_config->ReadInt(L"transfers_col3_width",150);
  196. default: return 0;
  197. }
  198. }
  199. virtual void ColumnResize(int col, int newWidth)
  200. {
  201. if (col==0) global_config->WriteInt(L"transfers_col0_width",newWidth);
  202. else if (col==1) global_config->WriteInt(L"transfers_col1_width",newWidth);
  203. else if (col==2) global_config->WriteInt(L"transfers_col2_width",newWidth);
  204. else if (col==3) global_config->WriteInt(L"transfers_col3_width",newWidth);
  205. }
  206. void lock()
  207. {
  208. EnterCriticalSection(&cs);
  209. }
  210. void unlock()
  211. {
  212. LeaveCriticalSection(&cs);
  213. }
  214. virtual void GetCellText(int row, int col, wchar_t * buf, int buflen)
  215. {
  216. lock();
  217. if (row >= listShadow->GetSize())
  218. {
  219. unlock(); return;
  220. }
  221. TransferItemShadow * t = (TransferItemShadow *)listShadow->Get(row);
  222. switch (col)
  223. {
  224. case 0: lstrcpyn(buf,t->type,buflen); break;
  225. case 1: lstrcpyn(buf,t->track,buflen); break;
  226. case 2: lstrcpyn(buf,t->status,buflen); break;
  227. case 3: lstrcpyn(buf,t->device,buflen); break;
  228. }
  229. unlock();
  230. }
  231. void PushPopItem(CopyInst *c)
  232. {
  233. lock();
  234. int size = listShadow->GetSize();
  235. for (int i=0; i<size; i++)
  236. {
  237. TransferItemShadow * t = (TransferItemShadow *)listShadow->Get(i);
  238. if (c == t->c)
  239. {
  240. t->changed=true;
  241. listShadow->Del(i);
  242. listShadow->Add(t);
  243. if (listTransfers)
  244. {
  245. HWND hwnd = listTransfers->listview.getwnd();
  246. PostMessage(hwnd,LVM_DELETEITEM,i,0);
  247. PostMessage(hwnd,LVM_SETITEMCOUNT,size,LVSICF_NOINVALIDATEALL | LVSICF_NOSCROLL);
  248. }
  249. unlock();
  250. return;
  251. }
  252. }
  253. unlock();
  254. }
  255. void ItemUpdate(CopyInst * c)
  256. {
  257. lock();
  258. int size = listShadow->GetSize();
  259. for (int i=0; i<size; i++)
  260. {
  261. TransferItemShadow * t = (TransferItemShadow *)listShadow->Get(i);
  262. if (c == t->c)
  263. {
  264. TransferItemShadow * n = new TransferItemShadow(c);
  265. n->changed=true;
  266. listShadow->Set(i,n);
  267. delete t;
  268. if (listTransfers)
  269. {
  270. HWND hwnd = listTransfers->listview.getwnd();
  271. PostMessage(hwnd,LVM_REDRAWITEMS,i,i);
  272. }
  273. unlock();
  274. return;
  275. }
  276. }
  277. unlock();
  278. }
  279. int oldSize;
  280. void FullUpdate()
  281. {
  282. C_ItemList * newListShadow = getTransferListShadow();
  283. int newSize = newListShadow->GetSize();
  284. lock();
  285. oldSize = listShadow->GetSize();
  286. for (int i=0; i<newSize; i++)
  287. {
  288. TransferItemShadow * newt = (TransferItemShadow *)newListShadow->Get(i);
  289. TransferItemShadow * oldt = i<oldSize?(TransferItemShadow *)listShadow->Get(i):NULL;
  290. newt->changed = !newt->Equals(oldt);
  291. }
  292. C_ItemList * oldListShadow = listShadow;
  293. listShadow = newListShadow;
  294. for (int i=0; i<oldListShadow->GetSize(); i++) delete(TransferItemShadow *)oldListShadow->Get(i);
  295. delete oldListShadow;
  296. if (listTransfers)
  297. {
  298. HWND hwnd = listTransfers->listview.getwnd();
  299. if (newSize != oldSize) PostMessage(hwnd,LVM_SETITEMCOUNT,newSize, 0);
  300. for (int i=0; i<newSize; i++)
  301. {
  302. TransferItemShadow * t = (TransferItemShadow *)listShadow->Get(i);
  303. if (t->changed) PostMessage(hwnd,LVM_REDRAWITEMS,i,i);
  304. }
  305. }
  306. unlock();
  307. }
  308. virtual songid_t GetTrack(int pos) { return 0; }
  309. };
  310. static void updateStatus()
  311. {
  312. int pcnum=0,num=0,time=0,total=0;
  313. for (int i=0; i<devices.GetSize(); i++)
  314. {
  315. DeviceView* device = (DeviceView*)devices.Get(i);
  316. LinkedQueue * txQueue = getTransferQueue(device);
  317. LinkedQueue * finishedTX = getFinishedTransferQueue(device);
  318. int txProgress = getTransferProgress(device);
  319. int s = (txQueue ? txQueue->GetSize() : 0);
  320. int n = (s * 100) - txProgress;
  321. total += s * 100;
  322. total += 100 * (finishedTX ? finishedTX->GetSize() : 0);
  323. pcnum += n;
  324. num += s;
  325. int t = (int)(device->transferRate * (((double)n) / 100.0));
  326. if (time < t) time = t;
  327. }
  328. if (total)
  329. {
  330. wchar_t caption[256] = {0};
  331. int pc = ((total-pcnum)*100)/total;
  332. wsprintf(caption,WASABI_API_LNGSTRINGW((time > 0 ? IDS_TRANFERS_PERCENT_REMAINING : IDS_TRANFERS_PERCENT_REMAINING_NOT_TIME)),num,pc,time/60,time%60);
  333. SetDlgItemText(m_hwnd,IDC_STATUS,caption);
  334. }
  335. else SetDlgItemText(m_hwnd,IDC_STATUS,L"");
  336. }
  337. static TransferContents2 transferListContents;
  338. void TransfersListUpdateItem(CopyInst * item)
  339. {
  340. transferListContents.ItemUpdate(item);
  341. }
  342. void TransfersListPushPopItem(CopyInst * item)
  343. {
  344. transferListContents.PushPopItem(item);
  345. }
  346. void UpdateDevicesListView(bool softUpdate)
  347. {
  348. if (listDevices) listDevices->UpdateList(softUpdate);
  349. }
  350. static bool AddSelectedItems(C_ItemList *items, W_ListView *listview, LinkedQueue *transfer_queue, int &row, DeviceView *&dev)
  351. {
  352. transfer_queue->lock();
  353. int l = transfer_queue->GetSize();
  354. for (int j=0; j<l; j++)
  355. {
  356. if (listview->GetSelected(row++))
  357. {
  358. CopyInst * c = (CopyInst *)transfer_queue->Get(j);
  359. if (c->songid)
  360. {
  361. if (!dev && c->dev) dev = c->dev;
  362. if (dev)
  363. {
  364. if (c->dev != dev)
  365. {
  366. transfer_queue->unlock();
  367. return false;
  368. }
  369. else
  370. items->Add((void*)c->songid);
  371. }
  372. }
  373. }
  374. }
  375. transfer_queue->unlock();
  376. return true;
  377. }
  378. static void RemoveSelectedItems(DeviceView *device, W_ListView *listview, LinkedQueue *transfer_queue, int &row, bool finished_queue)
  379. {
  380. transfer_queue->lock();
  381. int j = transfer_queue->GetSize();
  382. while (j-- > 0)
  383. {
  384. if (listview->GetSelected(--row))
  385. {
  386. if (j == 0 && !finished_queue)
  387. {
  388. CopyInst * d = (CopyInst *)transfer_queue->Get(j);
  389. if (d && d->status == STATUS_WAITING && device->transferContext.IsPaused())
  390. {
  391. transfer_queue->Del(j);
  392. d->Cancelled();
  393. delete d;
  394. } // otherwise don't bother
  395. }
  396. else
  397. {
  398. CopyInst * d = (CopyInst*)transfer_queue->Del(j);
  399. if (d)
  400. {
  401. if (d->status == STATUS_WAITING && !finished_queue)
  402. d->Cancelled();
  403. delete d;
  404. }
  405. }
  406. }
  407. }
  408. transfer_queue->unlock();
  409. }
  410. extern void handleContextMenuResult(int r, C_ItemList * items=NULL, DeviceView * dev=NULL);
  411. extern int showContextMenu(int context,HWND hwndDlg, Device * dev, POINT pt);
  412. extern int (*wad_getColor)(int idx);
  413. INT_PTR CALLBACK pmp_devices_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  414. {
  415. if (wad_handleDialogMsgs)
  416. {
  417. BOOL a=wad_handleDialogMsgs(hwndDlg,uMsg,wParam,lParam); if (a) return a;
  418. }
  419. if (listDevices)
  420. {
  421. BOOL a=listDevices->DialogProc(hwndDlg,uMsg,wParam,lParam); if (a) return a;
  422. }
  423. if (listTransfers)
  424. {
  425. BOOL a=listTransfers->DialogProc(hwndDlg,uMsg,wParam,lParam); if (a) return a;
  426. }
  427. switch (uMsg)
  428. {
  429. case WM_INITDIALOG:
  430. m_hwnd=hwndDlg;
  431. *(void **)&wad_handleDialogMsgs=(void*)SendMessage(plugin.hwndLibraryParent,WM_ML_IPC,2,ML_IPC_SKIN_WADLG_GETFUNC);
  432. *(void **)&wad_DrawChildWindowBorders=(void*)SendMessage(plugin.hwndLibraryParent,WM_ML_IPC,3,ML_IPC_SKIN_WADLG_GETFUNC);
  433. *(void **)&cr_init=(void*)SendMessage(plugin.hwndLibraryParent,WM_ML_IPC,32,ML_IPC_SKIN_WADLG_GETFUNC);
  434. *(void **)&cr_resize=(void*)SendMessage(plugin.hwndLibraryParent,WM_ML_IPC,33,ML_IPC_SKIN_WADLG_GETFUNC);
  435. if (cr_init) cr_init(hwndDlg,resize_rlist,sizeof(resize_rlist)/sizeof(resize_rlist[0]));
  436. listDevices = new SkinnedListView(&deviceListContents,IDC_LIST_DEVICES,plugin.hwndLibraryParent, hwndDlg);
  437. listDevices->DialogProc(hwndDlg,uMsg,0,0);
  438. transferListContents.lock();
  439. listTransfers = new SkinnedListView(&transferListContents,IDC_LIST_TRANSFERS,plugin.hwndLibraryParent, hwndDlg);
  440. listTransfers->DialogProc(hwndDlg,uMsg,0,0);
  441. transferListContents.unlock();
  442. adiv_oldWndProc=(WNDPROC)SetWindowLongPtr(GetDlgItem(hwndDlg,IDC_HDELIM),GWLP_WNDPROC,(LONG_PTR)adiv_newWndProc);
  443. SetDlgItemText(hwndDlg,IDC_BUTTON_PAUSETRANSFERS,WASABI_API_LNGSTRINGW((TransferContext::IsAllPaused()?IDS_RESUME:IDS_PAUSE)));
  444. SetTimer(hwndDlg,1,250,NULL);
  445. updateStatus();
  446. break;
  447. case WM_TIMER:
  448. if (wParam == 1)
  449. {
  450. updateStatus();
  451. if (device_update_map[0])
  452. {
  453. device_update_map[0]=0;
  454. transferListContents.FullUpdate();
  455. }
  456. }
  457. break;
  458. case WM_DISPLAYCHANGE:
  459. break;
  460. case WM_SETCURSOR: // set cursor when near the dividers
  461. {
  462. RECT r;
  463. POINT p;
  464. GetCursorPos(&p);
  465. GetWindowRect(GetDlgItem(hwndDlg,IDC_HDELIM),&r);
  466. r.top-=3;
  467. r.bottom+=3;
  468. if (PtInRect(&r,p))
  469. {
  470. SetCursor(LoadCursor(NULL,IDC_SIZENS));
  471. return uMsg == WM_SETCURSOR;
  472. }
  473. break;
  474. }
  475. case WM_LBUTTONDOWN:
  476. {
  477. // forward dialog clicks to the dividers if they get near them
  478. POINT p;
  479. RECT r3;
  480. GetWindowRect(GetDlgItem(hwndDlg,IDC_VDELIM),&r3);
  481. GetCursorPos(&p);
  482. GetWindowRect(GetDlgItem(hwndDlg,IDC_HDELIM),&r3);
  483. if (p.x >= r3.left && p.x <= r3.right)
  484. {
  485. int d=p.y-r3.bottom;
  486. int d2=p.y-r3.top;
  487. if (d<0)d=-d;
  488. if (d2<0)d2=-d2;
  489. if (d < 6 || d2 < 6) SendDlgItemMessage(hwndDlg,IDC_HDELIM,uMsg,0,0);
  490. }
  491. }
  492. break;
  493. case WM_SIZE:
  494. if (wParam != SIZE_MINIMIZED)
  495. {
  496. if (cr_resize) cr_resize(hwndDlg,resize_rlist,sizeof(resize_rlist)/sizeof(resize_rlist[0]));
  497. }
  498. break;
  499. case WM_PAINT:
  500. {
  501. if (wad_DrawChildWindowBorders)
  502. {
  503. int tab[] = {m_nodrawtopborders==1?0:(IDC_LIST_DEVICES|DCW_SUNKENBORDER),
  504. m_nodrawtopborders==2?0:(IDC_LIST_TRANSFERS|DCW_SUNKENBORDER),
  505. IDC_HDELIM|DCW_DIVIDER
  506. };
  507. wad_DrawChildWindowBorders(hwndDlg,tab,3);
  508. }
  509. }
  510. break;
  511. case WM_DESTROY:
  512. {
  513. KillTimer(hwndDlg, 1);
  514. m_hwnd=NULL;
  515. SkinnedListView * ld = listDevices; listDevices=NULL; delete ld;
  516. SkinnedListView * lt = listTransfers;
  517. transferListContents.lock();
  518. listTransfers=NULL;
  519. transferListContents.unlock();
  520. delete lt;
  521. }
  522. break;
  523. case WM_NOTIFY:
  524. {
  525. LPNMHDR l=(LPNMHDR)lParam;
  526. if (l->idFrom==IDC_LIST_TRANSFERS)
  527. switch (l->code)
  528. {
  529. case NM_RETURN: // enter!
  530. case NM_RCLICK: // right click!
  531. case LVN_KEYDOWN:
  532. {
  533. DeviceView * dev = NULL;
  534. C_ItemList items;
  535. int row = 0;
  536. for (int i=0; i<devices.GetSize(); i++)
  537. {
  538. DeviceView *device = (DeviceView*)devices.Get(i);
  539. if (!AddSelectedItems(&items, &listTransfers->listview, getTransferQueue(device), row, dev))
  540. return 0;
  541. if (!AddSelectedItems(&items, &listTransfers->listview, getFinishedTransferQueue(device), row, dev))
  542. return 0;
  543. }
  544. bool foundDev=false;
  545. for (int k=0; k<devices.GetSize(); k++) if (dev == (DeviceView*)devices.Get(k)) foundDev=true;
  546. if (dev && foundDev && items.GetSize())
  547. {
  548. if (l->code == NM_RCLICK)
  549. {
  550. LPNMITEMACTIVATE lva=(LPNMITEMACTIVATE)lParam;
  551. handleContextMenuResult(showContextMenu(7,l->hwndFrom,dev->dev,lva->ptAction),&items,dev);
  552. }
  553. else if (l->code == NM_RETURN)
  554. {
  555. handleContextMenuResult((!GetAsyncKeyState(VK_SHIFT)?ID_TRACKSLIST_PLAYSELECTION:ID_TRACKSLIST_ENQUEUESELECTION),&items,dev);
  556. }
  557. else if (l->code == LVN_KEYDOWN)
  558. {
  559. switch (((LPNMLVKEYDOWN)lParam)->wVKey)
  560. {
  561. case VK_DELETE:
  562. {
  563. if (!(GetAsyncKeyState(VK_CONTROL)&0x8000) && !(GetAsyncKeyState(VK_SHIFT)&0x8000))
  564. {
  565. handleContextMenuResult(ID_TRACKSLIST_DELETE,&items,dev);
  566. }
  567. }
  568. break;
  569. case 0x45: //E
  570. if ((GetAsyncKeyState(VK_CONTROL)&0x8000) && !(GetAsyncKeyState(VK_SHIFT)&0x8000))
  571. {
  572. handleContextMenuResult(ID_TRACKSLIST_EDITSELECTEDITEMS,&items,dev);
  573. }
  574. break;
  575. }
  576. }
  577. }
  578. break;
  579. }
  580. }
  581. }
  582. break;
  583. case WM_COMMAND:
  584. switch (LOWORD(wParam))
  585. {
  586. case IDC_BUTTON_CLEARFINISHED:
  587. {
  588. for (int i=0; i<devices.GetSize(); i++)
  589. {
  590. DeviceView *device = (DeviceView*)devices.Get(i);
  591. LinkedQueue * finishedTX = getFinishedTransferQueue(device);
  592. if (finishedTX)
  593. {
  594. finishedTX->lock();
  595. int j=finishedTX->GetSize();
  596. while (j-- > 0) delete(CopyInst*)finishedTX->Del(j);
  597. finishedTX->unlock();
  598. }
  599. }
  600. transferListContents.FullUpdate();
  601. }
  602. break;
  603. case IDC_BUTTON_REMOVESELECTED:
  604. {
  605. int row = transferListContents.GetNumRows();
  606. int i = devices.GetSize();
  607. while (i-- > 0)
  608. {
  609. DeviceView *device = (DeviceView *)devices.Get(i);
  610. RemoveSelectedItems(device, &listTransfers->listview, getTransferQueue(device), row, false);
  611. RemoveSelectedItems(device, &listTransfers->listview, getFinishedTransferQueue(device), row, true);
  612. }
  613. transferListContents.FullUpdate();
  614. }
  615. break;
  616. case IDC_BUTTON_PAUSETRANSFERS:
  617. if (false != TransferContext::IsAllPaused())
  618. TransferContext::ResumeAll();
  619. else
  620. TransferContext::PauseAll();
  621. for (int i=0;i<devices.GetSize();i++)
  622. {
  623. DeviceView *device_view = (DeviceView*)devices.Get(i);
  624. SetEvent(device_view->transferContext.notifier);
  625. }
  626. SetDlgItemText(hwndDlg,IDC_BUTTON_PAUSETRANSFERS,WASABI_API_LNGSTRINGW((TransferContext::IsAllPaused()?IDS_RESUME:IDS_PAUSE)));
  627. break;
  628. }
  629. break;
  630. case WM_MOUSEMOVE:
  631. if (wParam==MK_LBUTTON)
  632. {
  633. if (GetCapture() == hwndDlg) ReleaseCapture();
  634. }
  635. break;
  636. }
  637. return 0;
  638. }
  639. // deals with the horizontal (IDC_HDELIM) divider
  640. static void adiv_UpdPos(int yp)
  641. {
  642. RECT r,old_divider_rect;
  643. GetClientRect(m_hwnd,&r);
  644. GetWindowRect(GetDlgItem(m_hwnd,IDC_HDELIM),&old_divider_rect);
  645. ScreenToClient(m_hwnd,(LPPOINT)&old_divider_rect);
  646. ScreenToClient(m_hwnd,((LPPOINT)&old_divider_rect)+1);
  647. if (yp < 50)
  648. {
  649. m_nodrawtopborders=1;
  650. yp=20;
  651. }
  652. else m_nodrawtopborders=0;
  653. if (yp > r.bottom-42-30)
  654. {
  655. yp=r.bottom-42;
  656. m_nodrawtopborders=2;
  657. }
  658. int x;
  659. for (x = 0; x < 4; x ++)
  660. {
  661. RECT myoldr;
  662. GetWindowRect(GetDlgItem(m_hwnd,resize_rlist[x].id),&myoldr);
  663. ScreenToClient(m_hwnd,(LPPOINT)&myoldr);
  664. ScreenToClient(m_hwnd,((LPPOINT)&myoldr)+1);
  665. switch (x)
  666. {
  667. case 0:
  668. resize_rlist[x].rinfo.bottom=yp - old_divider_rect.top + myoldr.bottom;
  669. break;
  670. case 1:
  671. resize_rlist[x].rinfo.top=yp - old_divider_rect.top + myoldr.top;
  672. break;
  673. case 2:
  674. case 3:
  675. {
  676. int h=resize_rlist[x].rinfo.bottom - resize_rlist[x].rinfo.top;
  677. resize_rlist[x].rinfo.top = yp - old_divider_rect.top + resize_rlist[x].rinfo.top;
  678. resize_rlist[x].rinfo.bottom = resize_rlist[x].rinfo.top + h;
  679. }
  680. break;
  681. }
  682. }
  683. cr_resize(m_hwnd,resize_rlist,4);
  684. }
  685. static INT_PTR CALLBACK adiv_newWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  686. {
  687. if (uMsg == WM_LBUTTONDOWN)
  688. {
  689. SetForegroundWindow(hwndDlg);
  690. SetCapture(hwndDlg);
  691. SetCursor(LoadCursor(NULL,IDC_SIZENS));
  692. POINT p;
  693. GetCursorPos(&p);
  694. ScreenToClient(hwndDlg,&p);
  695. adiv_clickoffs=p.y;
  696. }
  697. else if (uMsg == WM_SETCURSOR)
  698. {
  699. SetCursor(LoadCursor(NULL,IDC_SIZENS));
  700. return TRUE;
  701. }
  702. else if (uMsg == WM_MOUSEMOVE && GetCapture()==hwndDlg)
  703. {
  704. POINT p;
  705. GetCursorPos(&p);
  706. ScreenToClient(GetParent(hwndDlg),&p);
  707. adiv_UpdPos(p.y-adiv_clickoffs);
  708. RECT r;
  709. GetClientRect(GetParent(hwndDlg),&r);
  710. if (r.bottom > r.top)
  711. {
  712. int percent = ((p.y-adiv_clickoffs) * 100000) / (r.bottom-r.top);
  713. adivpos = percent;
  714. }
  715. }
  716. else if (uMsg == WM_MOUSEMOVE)
  717. {
  718. SetCursor(LoadCursor(NULL,IDC_SIZENS));
  719. }
  720. else if (uMsg == WM_LBUTTONUP)
  721. {
  722. ReleaseCapture();
  723. }
  724. return CallWindowProc(adiv_oldWndProc,hwndDlg,uMsg,wParam,lParam);
  725. }