1
0

view_ripburn.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. #include "main.h"
  2. #include "resource.h"
  3. #include "../nu/DialogSkinner.h"
  4. #include "../nu/ChildSizer.h"
  5. #include "config.h"
  6. #include ".\driveListBox.h"
  7. #include ".\infoBox.h"
  8. #include ".\primosdk_helper.h"
  9. #include <strsafe.h>
  10. static ChildWndResizeItem ripburn_rlist[]=
  11. {
  12. {IDC_LBL_DRIVES, 0x0000},
  13. {IDC_LIST_DRIVES, 0x0001},
  14. {IDC_LBL_INFO_DRIVE, 0x0010},
  15. {IDC_LBL_INFO_MEDIUM, 0x0011},
  16. {IDC_LBL_DRIVE_LETTER_VAL, 0x0010},
  17. {IDC_LBL_DRIVE_DESCRIPTION_VAL,0x0010},
  18. {IDC_LBL_DRIVE_BUS_VAL, 0x0010},
  19. {IDC_LBL_DRIVE_TYPES_VAL, 0x0010},
  20. {IDC_LBL_MEDIUM_UPDATE, 0x0010},
  21. {IDC_LBL_MEDIUM_CAPACITY_VAL, 0x0010},
  22. {IDC_LBL_MEDIUM_TRACKN_VAL, 0x0010},
  23. {IDC_LBL_MEDIUM_ERASEABLE_VAL, 0x0010},
  24. {IDC_LBL_MEDIUM_RECORDABLE_VAL,0x0010},
  25. {IDC_LBL_MEDIUM_FORMAT_VAL, 0x0010},
  26. {IDC_LBL_MEDIUM_ADDINFO_VAL, 0x0010},
  27. {IDC_LBL_MEDIUM_DISC_VAL, 0x0010},
  28. {IDC_BTN_REFRESH, 0x0101},
  29. };
  30. static DriveListBox *driveListBox = NULL;
  31. static MLInfoBox *driveInfo = NULL;
  32. static MLInfoBox *mediumInfo = NULL;
  33. static HBRUSH lblHeaderBrush = NULL;
  34. static HBRUSH lblValueBrush = NULL;
  35. static UINT msgNotify = 0;
  36. static CHAR activeDrive = 0x00;
  37. static void CALLBACK FreeAsyncParam(DM_NOTIFY_PARAM *phdr)
  38. {
  39. DM_UNITINFO_PARAM *pui = NULL;
  40. DM_UNITINFO2_PARAM *pui2 = NULL;
  41. if(!phdr) return;
  42. switch(phdr->opCode)
  43. {
  44. case DMOP_UNITINFO:
  45. pui = (DM_UNITINFO_PARAM*)phdr;
  46. if (pui->pszDesc) free(pui->pszDesc);
  47. break;
  48. case DMOP_UNITINFO2:
  49. pui2 = (DM_UNITINFO2_PARAM*)phdr;
  50. if (pui2->pdwTypes) free(pui2->pdwTypes);
  51. break;
  52. }
  53. free(phdr);
  54. }
  55. static void UpdateDriveInfo(HWND hwndDlg, CHAR cLetter)
  56. {
  57. DM_NOTIFY_PARAM header = {0};
  58. DM_UNITINFO_PARAM *pui = NULL;
  59. DM_UNITINFO2_PARAM *pui2 = NULL;
  60. DM_DISCINFOEX_PARAM *pdi = NULL;
  61. DM_DISCINFO2_PARAM *pdi2 = NULL;
  62. wchar_t message[128] = {0};
  63. activeDrive = cLetter;
  64. if(!PrimoSDKHelper_IsLoaded())
  65. {
  66. WASABI_API_LNGSTRINGW_BUF(IDS_NO_INFO_AVAILABLE,message,128);
  67. }
  68. SetDlgItemTextA(hwndDlg, IDC_LBL_DRIVE_LETTER_VAL, &cLetter);
  69. SetDlgItemText(hwndDlg, IDC_LBL_DRIVE_DESCRIPTION_VAL, message);
  70. SetDlgItemText(hwndDlg, IDC_LBL_DRIVE_BUS_VAL, message);
  71. SetDlgItemText(hwndDlg, IDC_LBL_DRIVE_TYPES_VAL, message);
  72. SetDlgItemTextA(hwndDlg, IDC_LBL_MEDIUM_DISC_VAL, NULL);
  73. SetDlgItemTextA(hwndDlg, IDC_LBL_MEDIUM_CAPACITY_VAL, NULL);
  74. SetDlgItemTextA(hwndDlg, IDC_LBL_MEDIUM_FORMAT_VAL, NULL);
  75. SetDlgItemTextA(hwndDlg, IDC_LBL_MEDIUM_ERASEABLE_VAL, NULL);
  76. SetDlgItemTextA(hwndDlg, IDC_LBL_MEDIUM_RECORDABLE_VAL, NULL);
  77. SetDlgItemTextA(hwndDlg, IDC_LBL_MEDIUM_TRACKN_VAL, NULL);
  78. SetDlgItemTextA(hwndDlg, IDC_LBL_MEDIUM_ADDINFO_VAL, NULL);
  79. if (0 == activeDrive) return;
  80. ZeroMemory(&header, sizeof(DM_NOTIFY_PARAM));
  81. header.callback = (INT_PTR)hwndDlg;
  82. header.uMsg = msgNotify;
  83. header.cLetter = cLetter;
  84. header.fnFree = FreeAsyncParam;
  85. // request unitinfo
  86. pui = (DM_UNITINFO_PARAM*)calloc(1, sizeof(DM_UNITINFO_PARAM));
  87. if (pui)
  88. {
  89. CopyMemory(&pui->header, &header, sizeof(DM_NOTIFY_PARAM));
  90. pui->header.fFlags = DMF_DESCRIPTION;
  91. pui->cchDesc = 128;
  92. pui->pszDesc = (CHAR*)calloc(pui->cchDesc, sizeof(CHAR));
  93. DriveManager_GetUnitInfo(pui);
  94. }
  95. // request unitinfo2
  96. pui2 = (DM_UNITINFO2_PARAM*)calloc(1, sizeof(DM_UNITINFO2_PARAM));
  97. if (pui2)
  98. {
  99. CopyMemory(&pui2->header, &header, sizeof(DM_NOTIFY_PARAM));
  100. pui2->header.fFlags = DMF_TYPES;
  101. pui2->nTypes = 32;
  102. pui2->pdwTypes = (DWORD*)calloc(pui2->nTypes, sizeof(DWORD));
  103. DriveManager_GetUnitInfo2(pui2);
  104. }
  105. // request discinfoex
  106. pdi = (DM_DISCINFOEX_PARAM*)calloc(1, sizeof(DM_DISCINFOEX_PARAM));
  107. if (pdi)
  108. {
  109. CopyMemory(&pdi->header, &header, sizeof(DM_NOTIFY_PARAM));
  110. pdi->header.fFlags = DMF_DRIVEMODE_DAO | DMF_MEDIUMTYPE | DMF_MEDIUMFORMAT | DMF_TRACKS | DMF_USED | DMF_FREE;
  111. DriveManager_GetDiscInfoEx(pdi);
  112. }
  113. // request discinfo2
  114. pdi2 = (DM_DISCINFO2_PARAM*)calloc(1, sizeof(DM_DISCINFO2_PARAM));
  115. if (pdi2)
  116. {
  117. CopyMemory(&pdi2->header, &header, sizeof(DM_NOTIFY_PARAM));
  118. pdi2->header.fFlags = DMF_MEDIUM | DMF_MEDIUMEX;
  119. DriveManager_GetDiscInfo2(pdi2);
  120. }
  121. }
  122. static BOOL CALLBACK EnumerateNavItemsCB(HNAVITEM hItem, DRIVE *pDrive, LPARAM param)
  123. {
  124. if (!param) return FALSE;
  125. if (pDrive) PostMessageW((HWND)param, msgNotify, (WPARAM)DMW_DRIVEADDED, (LPARAM)pDrive->cLetter);
  126. return TRUE;
  127. }
  128. static void SwitchControlVisible(HWND hwndDlg, INT ctrlId, RECT *prcParent, BOOL hide, BOOL bInvalidate = FALSE)
  129. {
  130. HWND hwndCtrl = GetDlgItem(hwndDlg, ctrlId);
  131. if (hwndCtrl)
  132. {
  133. if (hide) ShowWindow(hwndCtrl, SW_HIDE);
  134. else
  135. {
  136. RECT rc;
  137. GetWindowRect(hwndCtrl, &rc);
  138. BOOL bVisible = ((prcParent->right > rc.right) && (prcParent->bottom > rc.bottom));
  139. if (bVisible != IsWindowVisible(hwndCtrl)) ShowWindow(hwndCtrl, (bVisible) ? SW_SHOWNORMAL : SW_HIDE);
  140. if (bVisible && bInvalidate) InvalidateRect(hwndCtrl, NULL, TRUE);
  141. }
  142. }
  143. }
  144. static void ripburn_OnDisplayChanges(HWND hwndDlg)
  145. {
  146. driveListBox->SetColors(dialogSkinner.Color(WADLG_ITEMBG),
  147. dialogSkinner.Color(WADLG_ITEMBG),
  148. dialogSkinner.Color(WADLG_ITEMFG),
  149. dialogSkinner.Color(WADLG_ITEMFG),
  150. dialogSkinner.Color(WADLG_WNDFG));
  151. driveInfo->SetColors( dialogSkinner.Color(WADLG_ITEMBG),
  152. dialogSkinner.Color(WADLG_LISTHEADER_FONTCOLOR),
  153. dialogSkinner.Color(WADLG_LISTHEADER_BGCOLOR));
  154. mediumInfo->SetColors( dialogSkinner.Color(WADLG_ITEMBG),
  155. dialogSkinner.Color(WADLG_LISTHEADER_FONTCOLOR),
  156. dialogSkinner.Color(WADLG_LISTHEADER_BGCOLOR));
  157. if (lblHeaderBrush) DeleteObject(lblHeaderBrush);
  158. lblHeaderBrush = NULL;
  159. if (lblValueBrush) DeleteObject(lblValueBrush);
  160. lblValueBrush = NULL;
  161. // fixes the view not updating correctly on colour theme changes, etc
  162. // NOTE: ideal would be using a LayoutWindows(..) method which would
  163. // help to resolve this as things can be offloaded to gen_ml...
  164. RECT rc;
  165. GetClientRect(hwndDlg, &rc);
  166. RedrawWindow(hwndDlg, &rc, NULL, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN | RDW_ERASENOW | RDW_UPDATENOW);
  167. }
  168. static void ripburn_OnInitDialog(HWND hwndDlg)
  169. {
  170. HWND hwndList = GetDlgItem(hwndDlg, IDC_LIST_DRIVES);
  171. driveListBox = new DriveListBox(IDC_LIST_DRIVES);
  172. driveListBox->SetImages(plugin.hDllInstance, IDB_LISTBOX_BACK, IDB_LISTITEM_CDDRIVE);
  173. driveListBox->Init(hwndList);
  174. driveInfo = new MLInfoBox();
  175. driveInfo->Init(GetDlgItem(hwndDlg, IDC_LBL_INFO_DRIVE));
  176. mediumInfo = new MLInfoBox();
  177. mediumInfo->Init(GetDlgItem(hwndDlg, IDC_LBL_INFO_MEDIUM));
  178. UpdateDriveInfo(hwndDlg, 0);
  179. childSizer.Init(hwndDlg,ripburn_rlist,sizeof(ripburn_rlist)/sizeof(ripburn_rlist[0]));
  180. ripburn_OnDisplayChanges(hwndDlg);
  181. if (!msgNotify) msgNotify = RegisterWindowMessageW(L"ripburn_notify_msg");
  182. Plugin_EnumerateNavItems(EnumerateNavItemsCB, (LPARAM)hwndDlg);
  183. Plugin_RegisterListener(hwndDlg, msgNotify, 0);
  184. }
  185. static void ripburn_OnDestroy(HWND hwndDlg)
  186. {
  187. Plugin_UnregisterListener(hwndDlg);
  188. HWND hwndLB = GetDlgItem(hwndDlg, IDC_LIST_DRIVES);
  189. if (hwndLB)
  190. {
  191. INT index = (int)(INT_PTR)SendMessageW(hwndLB, LB_GETCURSEL, 0,0);
  192. DWORD data = (LB_ERR != index) ? (DWORD)SendMessageW(hwndLB, LB_GETITEMDATA, index, 0) : 0;
  193. if (data) g_config->WriteInt(L"last_drive", (CHAR)(0xFF & data));
  194. }
  195. if (lblHeaderBrush) DeleteObject(lblHeaderBrush);
  196. lblHeaderBrush = NULL;
  197. if (lblValueBrush) DeleteObject(lblValueBrush);
  198. lblValueBrush = NULL;
  199. if (driveListBox) delete(driveListBox);
  200. driveListBox = NULL;
  201. if (driveInfo) delete(driveInfo);
  202. driveInfo = NULL;
  203. if (mediumInfo) delete(mediumInfo);
  204. mediumInfo = NULL;
  205. }
  206. static void ripburn_OnSize(HWND hwndDlg, int cx, int cy)
  207. {
  208. RECT box;
  209. GetWindowRect(GetDlgItem(hwndDlg, IDC_LBL_INFO_DRIVE), &box);
  210. BOOL hide = FALSE;
  211. SwitchControlVisible(hwndDlg, IDC_LBL_DRIVE_LETTER, &box, FALSE);
  212. SwitchControlVisible(hwndDlg, IDC_LBL_DRIVE_DESCRIPTION, &box, FALSE);
  213. SwitchControlVisible(hwndDlg, IDC_LBL_DRIVE_BUS, &box, FALSE);
  214. SwitchControlVisible(hwndDlg, IDC_LBL_DRIVE_TYPES,&box, FALSE);
  215. SwitchControlVisible(hwndDlg, IDC_LBL_DRIVE_LETTER_VAL, &box, hide, TRUE);
  216. SwitchControlVisible(hwndDlg, IDC_LBL_DRIVE_DESCRIPTION_VAL, &box, hide, TRUE);
  217. SwitchControlVisible(hwndDlg, IDC_LBL_DRIVE_BUS_VAL, &box, hide, TRUE);
  218. SwitchControlVisible(hwndDlg, IDC_LBL_DRIVE_TYPES_VAL, &box, hide, TRUE);
  219. GetWindowRect(GetDlgItem(hwndDlg, IDC_LBL_INFO_MEDIUM), &box);
  220. hide = IsWindowVisible(GetDlgItem(hwndDlg, IDC_LBL_MEDIUM_UPDATE));
  221. if (hide) InvalidateRect(GetDlgItem(hwndDlg, IDC_LBL_MEDIUM_UPDATE), NULL, TRUE);
  222. if(PrimoSDKHelper_IsLoaded())
  223. /*{
  224. ShowWindow(GetDlgItem(hwndDlg, IDC_LBL_MEDIUM_UPDATE), SW_SHOW);
  225. }
  226. else*/
  227. {
  228. ShowWindow(GetDlgItem(hwndDlg, IDC_LBL_MEDIUM_UPDATE), SW_HIDE);
  229. SwitchControlVisible(hwndDlg, IDC_LBL_MEDIUM_CAPACITY_VAL, &box, hide, TRUE);
  230. SwitchControlVisible(hwndDlg, IDC_LBL_MEDIUM_FORMAT_VAL, &box, hide, TRUE);
  231. SwitchControlVisible(hwndDlg, IDC_LBL_MEDIUM_ERASEABLE_VAL, &box, hide, TRUE);
  232. SwitchControlVisible(hwndDlg, IDC_LBL_MEDIUM_RECORDABLE_VAL,&box, hide, TRUE);
  233. SwitchControlVisible(hwndDlg, IDC_LBL_MEDIUM_TRACKN_VAL, &box, hide, TRUE);
  234. SwitchControlVisible(hwndDlg, IDC_LBL_MEDIUM_DISC_VAL, &box, hide, TRUE);
  235. SwitchControlVisible(hwndDlg, IDC_LBL_MEDIUM_ADDINFO_VAL, &box, hide, TRUE);
  236. SwitchControlVisible(hwndDlg, IDC_LBL_MEDIUM_TYPE, &box, hide);
  237. SwitchControlVisible(hwndDlg, IDC_LBL_MEDIUM_CAPACITY, &box, hide);
  238. SwitchControlVisible(hwndDlg, IDC_LBL_MEDIUM_FORMAT, &box, hide);
  239. SwitchControlVisible(hwndDlg, IDC_LBL_MEDIUM_ERASEABLE, &box, hide);
  240. SwitchControlVisible(hwndDlg, IDC_LBL_MEDIUM_RECORDABLE, &box, hide);
  241. SwitchControlVisible(hwndDlg, IDC_LBL_MEDIUM_TRACKN, &box, hide);
  242. SwitchControlVisible(hwndDlg, IDC_LBL_MEDIUM_ADDINFO, &box, hide);
  243. }
  244. }
  245. static int LabelColoring(HDC hdc, HWND hwndCtrl)
  246. {
  247. switch(GetDlgCtrlID(hwndCtrl))
  248. {
  249. case IDC_LBL_DRIVES:
  250. if(!lblHeaderBrush) lblHeaderBrush = CreateSolidBrush(dialogSkinner.Color(WADLG_LISTHEADER_BGCOLOR));
  251. SetBkMode(hdc, TRANSPARENT);
  252. SetTextColor(hdc, dialogSkinner.Color(WADLG_LISTHEADER_FONTCOLOR));
  253. return (BOOL)(INT_PTR)lblHeaderBrush;
  254. case IDC_LBL_MEDIUM_NOINFO:
  255. case IDC_LBL_MEDIUM_CAPACITY_VAL:
  256. case IDC_LBL_MEDIUM_TRACKN_VAL:
  257. case IDC_LBL_MEDIUM_ERASEABLE_VAL:
  258. case IDC_LBL_MEDIUM_RECORDABLE_VAL:
  259. case IDC_LBL_MEDIUM_FORMAT_VAL:
  260. case IDC_LBL_MEDIUM_DISC_VAL:
  261. case IDC_LBL_MEDIUM_ADDINFO_VAL:
  262. case IDC_LBL_DRIVE_LETTER_VAL:
  263. case IDC_LBL_DRIVE_DESCRIPTION_VAL:
  264. case IDC_LBL_DRIVE_BUS_VAL:
  265. case IDC_LBL_DRIVE_TYPES_VAL:
  266. case IDC_LBL_MEDIUM_UPDATE:
  267. if(!lblValueBrush) lblValueBrush = CreateSolidBrush(dialogSkinner.Color(WADLG_ITEMBG));
  268. SetBkColor(hdc, dialogSkinner.Color(WADLG_ITEMBG));
  269. SetTextColor(hdc, dialogSkinner.Color(WADLG_ITEMFG));
  270. return (BOOL)(INT_PTR)lblValueBrush;
  271. case IDC_LBL_MEDIUM_CAPACITY:
  272. case IDC_LBL_MEDIUM_TRACKN:
  273. case IDC_LBL_MEDIUM_ERASEABLE:
  274. case IDC_LBL_MEDIUM_RECORDABLE:
  275. case IDC_LBL_MEDIUM_FORMAT:
  276. case IDC_LBL_MEDIUM_ADDINFO:
  277. case IDC_LBL_DRIVE_LETTER:
  278. case IDC_LBL_DRIVE_DESCRIPTION:
  279. case IDC_LBL_DRIVE_BUS:
  280. case IDC_LBL_DRIVE_TYPES:
  281. case IDC_LBL_MEDIUM_TYPE:
  282. if(!lblValueBrush) lblValueBrush = CreateSolidBrush(dialogSkinner.Color(WADLG_ITEMBG));
  283. SetBkMode(hdc, TRANSPARENT);
  284. // SetBkColor(hdc, dialogSkinner.Color(WADLG_ITEMBG));
  285. SetTextColor(hdc, dialogSkinner.Color(WADLG_ITEMFG));
  286. return (BOOL)(INT_PTR)lblValueBrush;
  287. }
  288. return FALSE;
  289. }
  290. static void Drive_OnAdded(HWND hwndDlg, CHAR cLetter)
  291. {
  292. HWND hwndLB = GetDlgItem(hwndDlg, IDC_LIST_DRIVES);
  293. if (IsWindow(hwndLB))
  294. {
  295. wchar_t str[] = {cLetter, 0x00};
  296. INT index = (INT)SendMessageW(hwndLB, LB_ADDSTRING, 0, (LPARAM)str);
  297. if (LB_ERR != index)
  298. {
  299. SendMessageW(hwndLB, LB_SETITEMDATA, index, (LPARAM)cLetter);
  300. INT idxSelection = (int)(INT_PTR)SendMessageW(hwndLB, LB_GETCURSEL, 0,0);
  301. if (LB_ERR == idxSelection && cLetter == g_config->ReadInt(L"last_drive", cLetter))
  302. {
  303. if (LB_ERR != SendMessageW(hwndLB, LB_SETCURSEL, index, 0L))
  304. {
  305. UpdateDriveInfo(hwndDlg, cLetter);
  306. }
  307. }
  308. // request unitinfo
  309. DM_UNITINFO_PARAM *pui = (DM_UNITINFO_PARAM*)calloc(1, sizeof(DM_UNITINFO_PARAM));
  310. if (pui)
  311. {
  312. pui->header.callback = (INT_PTR)hwndDlg;
  313. pui->header.uMsg = msgNotify;
  314. pui->header.cLetter = cLetter;
  315. pui->header.fnFree = FreeAsyncParam;
  316. DriveManager_GetUnitInfo(pui);
  317. }
  318. }
  319. }
  320. }
  321. static INT GetListBoxIndex(HWND hwndLB, CHAR cLetter)
  322. {
  323. wchar_t str[] = {cLetter, 0x00};
  324. return (cLetter && hwndLB) ? (INT)SendMessageW(hwndLB, LB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)str) : LB_ERR;
  325. }
  326. static void Drive_OnRemoved(HWND hwndDlg, CHAR cLetter)
  327. {
  328. HWND hwndLB = GetDlgItem(hwndDlg, IDC_LIST_DRIVES);
  329. if (IsWindow(hwndLB))
  330. {
  331. INT index = GetListBoxIndex(hwndLB, cLetter);
  332. if (LB_ERR != index) SendMessageW(hwndLB, LB_DELETESTRING, (WPARAM)index, 0L);
  333. }
  334. }
  335. static void GetInfo_Completed(HWND hwndDlg, DM_NOTIFY_PARAM *phdr)
  336. {
  337. wchar_t szBuffer[256] = {0};
  338. DM_UNITINFO_PARAM *pui = NULL;
  339. DM_UNITINFO2_PARAM *pui2 = NULL;
  340. DM_DISCINFOEX_PARAM *pdi = NULL;
  341. DM_DISCINFO2_PARAM *pdi2 = NULL;
  342. switch(phdr->opCode)
  343. {
  344. case DMOP_UNITINFO:
  345. pui = (DM_UNITINFO_PARAM*)phdr;
  346. if (0 == phdr->result)
  347. {
  348. HWND hwndLB = GetDlgItem(hwndDlg, IDC_LIST_DRIVES);
  349. if (hwndLB)
  350. {
  351. INT idxLB = GetListBoxIndex(hwndLB, phdr->cLetter);
  352. if (LB_ERR != idxLB)
  353. {
  354. DWORD data = MAKELONG(phdr->cLetter, pui->dwType);
  355. if (data != (DWORD)SendMessage(hwndLB ,LB_GETITEMDATA, idxLB, 0))
  356. {
  357. if (LB_ERR != SendMessageW(hwndLB, LB_SETITEMDATA, idxLB, (LPARAM)data))
  358. {
  359. RECT rc;
  360. SendMessageW(hwndLB, LB_GETITEMRECT, idxLB, (LPARAM)&rc);
  361. InvalidateRect(hwndLB, &rc, FALSE);
  362. UpdateWindow(hwndLB);
  363. }
  364. }
  365. }
  366. }
  367. if (activeDrive == phdr->cLetter && pui->pszDesc) SetDlgItemTextA(hwndDlg, IDC_LBL_DRIVE_DESCRIPTION_VAL, (pui->cchDesc > 0) ? pui->pszDesc : "");
  368. }
  369. break;
  370. case DMOP_UNITINFO2:
  371. pui2 = (DM_UNITINFO2_PARAM*)phdr;
  372. if (0 == phdr->result && activeDrive == phdr->cLetter)
  373. {
  374. SetDlgItemTextW(hwndDlg, IDC_LBL_DRIVE_BUS_VAL, Drive_GetBusTypeString(pui2->dwBusType));
  375. szBuffer[0] = 0x00;
  376. for (int i = 0; i < pui2->nTypes; i++)
  377. {
  378. if (0 != i) StringCchCatW(szBuffer, sizeof(szBuffer)/sizeof(wchar_t), L", ");
  379. StringCchCatW(szBuffer, sizeof(szBuffer)/sizeof(wchar_t), Drive_GetTypeString(pui2->pdwTypes[i]));
  380. }
  381. SetDlgItemTextW(hwndDlg, IDC_LBL_DRIVE_TYPES_VAL, szBuffer);
  382. }
  383. break;
  384. case DMOP_DISCINFO:
  385. pdi = (DM_DISCINFOEX_PARAM*)phdr;
  386. if (0 == phdr->result && activeDrive == phdr->cLetter)
  387. {
  388. StringCchPrintfW(szBuffer, sizeof(szBuffer)/sizeof(wchar_t),
  389. WASABI_API_LNGSTRINGW(IDS_X_OF_X_SECTORS_FREE),
  390. pdi->dwFree, pdi->dwUsed + pdi->dwFree);
  391. SetDlgItemTextW(hwndDlg, IDC_LBL_MEDIUM_CAPACITY_VAL, szBuffer);
  392. SetDlgItemInt(hwndDlg, IDC_LBL_MEDIUM_TRACKN_VAL, pdi->dwTracks, FALSE);
  393. SetDlgItemText(hwndDlg, IDC_LBL_MEDIUM_ERASEABLE_VAL, WASABI_API_LNGSTRINGW((pdi->bErasable) ? IDS_YES : IDS_NO));
  394. SetDlgItemText(hwndDlg, IDC_LBL_MEDIUM_RECORDABLE_VAL, WASABI_API_LNGSTRINGW((Medium_IsRecordableType(pdi->dwMediumType)) ? IDS_YES : IDS_NO));
  395. SetDlgItemText(hwndDlg, IDC_LBL_MEDIUM_ADDINFO_VAL, Medium_GetTypeString(pdi->dwMediumType));
  396. SetDlgItemText(hwndDlg, IDC_LBL_MEDIUM_FORMAT_VAL, Medium_GetFormatString(pdi->dwMediumFormat));
  397. }
  398. break;
  399. case DMOP_DISCINFO2:
  400. pdi2 = (DM_DISCINFO2_PARAM*)phdr;
  401. if (0 == phdr->result && activeDrive == phdr->cLetter)
  402. {
  403. SetDlgItemTextW(hwndDlg, IDC_LBL_MEDIUM_DISC_VAL, Medium_GetPhysicalTypeString(pdi2->dwMediumEx));
  404. }
  405. break;
  406. }
  407. }
  408. static void View_OnPluginNotify(HWND hwndDlg, WORD wCode, INT_PTR param)
  409. {
  410. switch(wCode)
  411. {
  412. case DMW_DRIVEADDED: Drive_OnAdded(hwndDlg, (CHAR)param); break;
  413. case DMW_DRIVEREMOVED: Drive_OnRemoved(hwndDlg, (CHAR)param); break;
  414. case DMW_MEDIUMARRIVED:
  415. case DMW_MEDIUMREMOVED: if ((CHAR)param == activeDrive) UpdateDriveInfo(hwndDlg, activeDrive); break;
  416. case DMW_OPCOMPLETED:
  417. SendMessage(hwndDlg, WM_SIZE, 0, 0);
  418. GetInfo_Completed(hwndDlg, (DM_NOTIFY_PARAM*)param);
  419. break;
  420. }
  421. }
  422. static INT_PTR ListBox_OnKeyPressed(HWND hwndDlg, HWND hwndLB, WORD wKey, INT iCurret)
  423. {
  424. switch(wKey)
  425. {
  426. case VK_F5: DriveManager_Update(TRUE); return -2;
  427. case VK_SPACE:
  428. PostMessageW(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_LIST_DRIVES,LBN_DBLCLK), (LPARAM)hwndLB);
  429. return -2;
  430. }
  431. if (wKey >= 'A' && wKey <= 'Z')
  432. {
  433. INT index = GetListBoxIndex(hwndLB, (CHAR)wKey);
  434. return (LB_ERR != index) ? index : -2;
  435. }
  436. return -1; // do default
  437. }
  438. INT_PTR CALLBACK view_ripburnDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  439. {
  440. INT_PTR a;
  441. if (uMsg == WM_CTLCOLORSTATIC )
  442. {
  443. a = LabelColoring((HDC)wParam, (HWND) lParam);
  444. if (a) return a;
  445. }
  446. a = driveListBox->HandleMsgProc(uMsg,wParam,lParam); if (a) return a;
  447. a = dialogSkinner.Handle(hwndDlg,uMsg,wParam,lParam); if (a) return a;
  448. switch(uMsg)
  449. {
  450. case WM_INITDIALOG:
  451. ripburn_OnInitDialog(hwndDlg);
  452. break;
  453. case WM_DISPLAYCHANGE:
  454. ripburn_OnDisplayChanges(hwndDlg);
  455. break;
  456. case WM_SIZE:
  457. if (wParam != SIZE_MINIMIZED)
  458. {
  459. childSizer.Resize(hwndDlg,ripburn_rlist,sizeof(ripburn_rlist)/sizeof(ripburn_rlist[0]));
  460. ripburn_OnSize(hwndDlg, LOWORD(lParam), HIWORD(lParam));
  461. }
  462. break;
  463. case WM_COMMAND:
  464. switch (LOWORD(wParam))
  465. {
  466. case IDC_LIST_DRIVES:
  467. if (HIWORD(wParam) == LBN_SELCHANGE)
  468. {
  469. INT index = (int)(INT_PTR)SendMessage((HWND)lParam, LB_GETCURSEL, 0,0);
  470. DWORD data = (LB_ERR != index) ? (DWORD)SendMessage((HWND)lParam ,LB_GETITEMDATA, index, 0) : 0;
  471. if (data) UpdateDriveInfo(hwndDlg, (CHAR)(0xFF & data));
  472. }
  473. else if (HIWORD(wParam) == LBN_DBLCLK)
  474. {
  475. INT index = (int)(INT_PTR)SendMessage((HWND)lParam, LB_GETCURSEL, 0,0);
  476. DWORD data = (LB_ERR != index) ? (DWORD)SendMessage((HWND)lParam ,LB_GETITEMDATA, index, 0) : 0;
  477. HNAVITEM hItem = (data) ? Plugin_GetNavItemFromLetter((CHAR)(0xFF & data)) : NULL;
  478. if (hItem) MLNavItem_Select(plugin.hwndLibraryParent, hItem);
  479. }
  480. break;
  481. case IDC_BTN_REFRESH:
  482. if (HIWORD(wParam) == BN_CLICKED) DriveManager_Update(TRUE);
  483. break;
  484. }
  485. break;
  486. case WM_PAINT:
  487. {
  488. int tab[] = { IDC_LIST_DRIVES | DCW_SUNKENBORDER,
  489. IDC_LBL_DRIVES | DCW_SUNKENBORDER,
  490. IDC_LBL_INFO_DRIVE | DCW_SUNKENBORDER,
  491. IDC_LBL_INFO_MEDIUM | DCW_SUNKENBORDER};
  492. dialogSkinner.Draw(hwndDlg, tab, 4);
  493. }
  494. return 0;
  495. case WM_DESTROY:
  496. ripburn_OnDestroy(hwndDlg);
  497. break;
  498. case WM_ERASEBKGND:
  499. return 0;
  500. case WM_VKEYTOITEM:
  501. return ListBox_OnKeyPressed(hwndDlg, (HWND)lParam, LOWORD(wParam), HIWORD(wParam));
  502. }
  503. if (msgNotify == uMsg)
  504. View_OnPluginNotify(hwndDlg, (WORD)wParam, (INT_PTR)lParam);
  505. return FALSE;
  506. }