Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

930 lines
24 KiB

  1. #include "shellprv.h"
  2. #include "ids.h"
  3. #include "apprmdlg.h"
  4. #include "mtpt.h"
  5. #include "hwcmmn.h"
  6. #include "mixctnt.h"
  7. static DWORD s_rgdwHelpIDsArray[] =
  8. { // Context Help IDs
  9. IDC_AP_MXCT_TOPICON, NO_HELP,
  10. IDC_AP_MXCT_TOPTEXT, NO_HELP,
  11. IDC_AP_MXCT_TOPTEXT2, NO_HELP,
  12. IDC_AP_MXCT_LIST, NO_HELP,
  13. IDC_AP_MXCT_CHECKBOX, NO_HELP,
  14. 0, 0
  15. };
  16. CBaseContentDlg::CBaseContentDlg() : CBaseDlg((ULONG_PTR)s_rgdwHelpIDsArray),
  17. _pszDeviceID(NULL), _hiconInfo(NULL), _hiconTop(NULL)
  18. {}
  19. CBaseContentDlg::~CBaseContentDlg()
  20. {
  21. if (_pszDeviceID)
  22. {
  23. LocalFree((HLOCAL)_pszDeviceID);
  24. }
  25. if (_hiconInfo)
  26. {
  27. DestroyIcon(_hiconInfo);
  28. }
  29. if (_hiconTop)
  30. {
  31. DestroyIcon(_hiconTop);
  32. }
  33. }
  34. HRESULT CBaseContentDlg::_SetHandler()
  35. {
  36. CHandlerData* phandlerdata;
  37. HRESULT hr = _uilListView.GetSelectedItemData(&phandlerdata);
  38. if (SUCCEEDED(hr))
  39. {
  40. hr = StringCchCopy(_szHandler, ARRAYSIZE(_szHandler),
  41. phandlerdata->_pszHandler);
  42. phandlerdata->Release();
  43. }
  44. return hr;
  45. }
  46. HRESULT CBaseContentDlg::Init(LPCWSTR pszDeviceID, LPCWSTR pszDeviceIDAlt,
  47. DWORD dwContentType, BOOL fCheckAlwaysDoThis)
  48. {
  49. HRESULT hr = E_INVALIDARG;
  50. _fCheckAlwaysDoThis = fCheckAlwaysDoThis;
  51. if (pszDeviceID)
  52. {
  53. _pszDeviceID = StrDup(pszDeviceID);
  54. if (_pszDeviceID)
  55. {
  56. _szDeviceIDAlt[0] = 0;
  57. if (pszDeviceIDAlt)
  58. {
  59. if (InRange(*pszDeviceIDAlt, 'a', 'z') ||
  60. InRange(*pszDeviceIDAlt, 'A', 'Z'))
  61. {
  62. hr = StringCchCopy(_szDeviceIDAlt, ARRAYSIZE(_szDeviceIDAlt),
  63. pszDeviceIDAlt);
  64. if (SUCCEEDED(hr))
  65. {
  66. _dwContentType = dwContentType;
  67. hr = _GetContentTypeHandler(dwContentType, _szContentTypeHandler,
  68. ARRAYSIZE(_szContentTypeHandler));
  69. }
  70. }
  71. }
  72. hr = S_OK;
  73. }
  74. else
  75. {
  76. hr = E_OUTOFMEMORY;
  77. }
  78. }
  79. return hr;
  80. }
  81. #define COL_ACTION 0
  82. #define COL_PROVIDER 1
  83. const UINT c_auTileColumns[] = {COL_ACTION, COL_PROVIDER};
  84. const UINT c_auTileSubItems[] = {COL_PROVIDER};
  85. HRESULT CBaseContentDlg::_InitListView()
  86. {
  87. HWND hwndList = GetDlgItem(_hwnd, IDC_AP_MXCT_LIST);
  88. HRESULT hr = _uilListView.Init(hwndList);
  89. if (SUCCEEDED(hr))
  90. {
  91. hr = _uilListView.InitTileInfo(c_auTileSubItems, ARRAYSIZE(c_auTileSubItems));
  92. if (SUCCEEDED(hr))
  93. {
  94. RECT rc = {0};
  95. LVTILEVIEWINFO lvtvi = {0};
  96. HIMAGELIST himagelist;
  97. ListView_SetView(hwndList, LV_VIEW_TILE);
  98. for (int i = 0; i < ARRAYSIZE(c_auTileColumns); ++i)
  99. {
  100. LVCOLUMN lvcolumn = {0};
  101. lvcolumn.mask = LVCF_SUBITEM;
  102. lvcolumn.iSubItem = c_auTileColumns[i];
  103. ListView_InsertColumn(hwndList, i, &lvcolumn);
  104. }
  105. GetClientRect(hwndList, &rc);
  106. lvtvi.cbSize = sizeof(LVTILEVIEWINFO);
  107. lvtvi.dwMask = LVTVIM_TILESIZE | LVTVIM_COLUMNS;
  108. lvtvi.dwFlags = LVTVIF_FIXEDWIDTH;
  109. // Leave room for the scroll bar when setting tile sizes or listview gets screwed up.
  110. lvtvi.sizeTile.cx = ((rc.right - rc.left) - GetSystemMetrics(SM_CXVSCROLL));
  111. lvtvi.cLines = ARRAYSIZE(c_auTileSubItems);
  112. ListView_SetTileViewInfo(hwndList, &lvtvi);
  113. Shell_GetImageLists(&himagelist, NULL);
  114. if (himagelist)
  115. {
  116. ListView_SetImageList(hwndList, himagelist, LVSIL_NORMAL);
  117. hr = S_OK;
  118. }
  119. }
  120. }
  121. return hr;
  122. }
  123. LRESULT CBaseContentDlg::OnInitDialog(WPARAM wParam, LPARAM lParam)
  124. {
  125. HRESULT hr = _InitListView();
  126. if (SUCCEEDED(hr))
  127. {
  128. hr = _FillListView();
  129. if (SUCCEEDED(hr))
  130. {
  131. hr = _InitStaticsCommon();
  132. if (SUCCEEDED(hr))
  133. {
  134. hr = _InitStatics();
  135. if (SUCCEEDED(hr))
  136. {
  137. hr = _InitSelections();
  138. }
  139. }
  140. }
  141. }
  142. if (_szDeviceIDAlt[0])
  143. {
  144. _SetAutoplayPromptHWND(_szDeviceIDAlt, _hwnd);
  145. }
  146. return TRUE;
  147. }
  148. LRESULT CBaseContentDlg::OnNotify(WPARAM wParam, LPARAM lParam)
  149. {
  150. LRESULT lRes = FALSE;
  151. LPNMHDR pNMHDR = (NMHDR *)lParam;
  152. UINT_PTR idFrom = pNMHDR->idFrom;
  153. UINT uCode = pNMHDR->code;
  154. switch (idFrom)
  155. {
  156. case IDC_AP_MXCT_LIST:
  157. if (LVN_ITEMCHANGED == uCode)
  158. {
  159. NMLISTVIEW* pNMLV = (NMLISTVIEW*)pNMHDR;
  160. // Is a new item being selected/unselected?
  161. if (pNMLV->uChanged & LVIF_STATE)
  162. {
  163. // Yes
  164. _OnListSelChange();
  165. }
  166. }
  167. else if (NM_DBLCLK == uCode)
  168. {
  169. OnOK(0);
  170. }
  171. lRes = CBaseDlg::OnNotify(wParam, lParam);
  172. break;
  173. default:
  174. lRes = CBaseDlg::OnNotify(wParam, lParam);
  175. break;
  176. }
  177. return lRes;
  178. }
  179. LRESULT CBaseContentDlg::OnDestroy(WPARAM wParam, LPARAM lParam)
  180. {
  181. _uilListView.ResetContent();
  182. return CBaseDlg::OnDestroy(wParam, lParam);
  183. }
  184. LRESULT CBaseContentDlg::OnOK(WORD wNotif)
  185. {
  186. // Wait cursor...
  187. EndDialog(_hwnd, IDOK);
  188. return FALSE;
  189. }
  190. LRESULT CBaseContentDlg::OnCancel(WORD wNotif)
  191. {
  192. EndDialog(_hwnd, IDCANCEL);
  193. return FALSE;
  194. }
  195. HRESULT CBaseContentDlg::_InitStaticsCommon()
  196. {
  197. // Initialize _szDeviceName to something
  198. HRESULT hr = _InitDeviceName();
  199. if (SUCCEEDED(hr))
  200. {
  201. SetWindowText(_hwnd, _szDeviceName);
  202. }
  203. if (_fCheckAlwaysDoThis)
  204. {
  205. Button_SetCheck(GetDlgItem(_hwnd, IDC_AP_MXCT_CHECKBOX), _fCheckAlwaysDoThis);
  206. }
  207. if (_szDeviceIDAlt[0])
  208. {
  209. // Initialize _szDeviceName to something
  210. CMountPoint* pmtpt = CMountPoint::GetMountPoint(_szDeviceIDAlt);
  211. if (pmtpt)
  212. {
  213. WCHAR szIconLocation[MAX_PATH + 12];
  214. int iIcon = pmtpt->GetIcon(szIconLocation, ARRAYSIZE(szIconLocation));
  215. if (SUCCEEDED(hr))
  216. {
  217. if (!szIconLocation[0])
  218. {
  219. hr = StringCchCopy(szIconLocation, ARRAYSIZE(szIconLocation),
  220. TEXT("shell32.dll"));
  221. }
  222. if (SUCCEEDED(hr))
  223. {
  224. int iImage = Shell_GetCachedImageIndex(szIconLocation, iIcon, 0);
  225. HIMAGELIST himagelist;
  226. if ((-1 != iImage) && Shell_GetImageLists(&himagelist, NULL))
  227. {
  228. _hiconTop = ImageList_GetIcon(himagelist, iImage, ILD_TRANSPARENT);
  229. SendDlgItemMessage(_hwnd, IDC_AP_MXCT_TOPICON, STM_SETIMAGE,
  230. IMAGE_ICON, (LPARAM)_hiconTop);
  231. }
  232. }
  233. }
  234. pmtpt->Release();
  235. }
  236. }
  237. return hr;
  238. }
  239. HRESULT CBaseContentDlg::_InitDeviceName()
  240. {
  241. HRESULT hr = E_FAIL;
  242. if (_szDeviceIDAlt[0])
  243. {
  244. CMountPoint* pmtpt = CMountPoint::GetMountPoint(_szDeviceIDAlt);
  245. if (pmtpt)
  246. {
  247. hr = pmtpt->GetDisplayName(_szDeviceName, ARRAYSIZE(_szDeviceName));
  248. pmtpt->Release();
  249. }
  250. }
  251. if (FAILED(hr))
  252. {
  253. GetWindowText(_hwnd, _szDeviceName, ARRAYSIZE(_szDeviceName));
  254. hr = S_FALSE;
  255. }
  256. return hr;
  257. }
  258. ///////////////////////////////////////////////////////////////////////////////
  259. CHWContentPromptDlg::CHWContentPromptDlg() : CBaseContentDlg()
  260. {}
  261. CHWContentPromptDlg::~CHWContentPromptDlg()
  262. {}
  263. HRESULT CHWContentPromptDlg::_InitDataObjects()
  264. {
  265. HRESULT hr = _data.Init(_pszDeviceID, _dwContentType);
  266. if (SUCCEEDED(hr))
  267. {
  268. hr = _dlmanager.AddDataObject(&_data);
  269. }
  270. return hr;
  271. }
  272. HRESULT CHWContentPromptDlg::_FillListView()
  273. {
  274. HRESULT hr = _InitDataObjects();
  275. if (SUCCEEDED(hr))
  276. {
  277. int c = _data.GetHandlerCount();
  278. for (int i = 0; SUCCEEDED(hr) && (i < c); ++i)
  279. {
  280. CHandlerData* phandlerdata = _data.GetHandlerData(i);
  281. if (phandlerdata)
  282. {
  283. CHandlerLVItem* puidata = new CHandlerLVItem();
  284. if (puidata)
  285. {
  286. hr = puidata->InitData(phandlerdata);
  287. if (SUCCEEDED(hr))
  288. {
  289. hr = _uilListView.AddItem(puidata);
  290. }
  291. if (FAILED(hr))
  292. {
  293. delete puidata;
  294. }
  295. }
  296. else
  297. {
  298. hr = E_OUTOFMEMORY;
  299. }
  300. phandlerdata->Release();
  301. }
  302. }
  303. }
  304. return hr;
  305. }
  306. HRESULT CHWContentPromptDlg::_InitStatics()
  307. {
  308. // Set content icon
  309. if (_hiconTop)
  310. {
  311. DestroyIcon(_hiconTop);
  312. }
  313. _hiconTop = _GetIconFromIconLocation(_data._szIconLocation, FALSE);
  314. SendDlgItemMessage(_hwnd, IDC_AP_MXCT_CONTENTICON, STM_SETIMAGE,
  315. IMAGE_ICON, (LPARAM)_hiconTop);
  316. // Set content name
  317. SetDlgItemText(_hwnd, IDC_AP_MXCT_CONTENTTYPE, _data._szIconLabel);
  318. return S_OK;
  319. }
  320. HRESULT CHWContentPromptDlg::_InitSelections()
  321. {
  322. HRESULT hr;
  323. if (_data._pszHandlerDefaultOriginal && *(_data._pszHandlerDefaultOriginal))
  324. {
  325. hr = _uilListView.SelectItem(_data._pszHandlerDefaultOriginal);
  326. }
  327. else
  328. {
  329. hr = _uilListView.SelectFirstItem();
  330. }
  331. if (SUCCEEDED(hr))
  332. {
  333. CHandlerData* phandlerdata;
  334. hr = _uilListView.GetSelectedItemData(&phandlerdata);
  335. if (SUCCEEDED(hr))
  336. {
  337. hr = StringCchCopy(_szHandler, ARRAYSIZE(_szHandler),
  338. phandlerdata->_pszHandler);
  339. if (SUCCEEDED(hr))
  340. {
  341. _SetHandlerDefault(&(_data._pszHandlerDefault),
  342. phandlerdata->_pszHandler);
  343. }
  344. phandlerdata->Release();
  345. }
  346. }
  347. Button_SetCheck(GetDlgItem(_hwnd, IDC_AP_MXCT_CHECKBOX), _fCheckAlwaysDoThis);
  348. return hr;
  349. }
  350. HRESULT CHWContentPromptDlg::_UpdateHandlerSettings()
  351. {
  352. CHandlerData* phandlerdata;
  353. HRESULT hr = _uilListView.GetSelectedItemData(&phandlerdata);
  354. if (SUCCEEDED(hr))
  355. {
  356. _SetHandlerDefault(&(_data._pszHandlerDefault), phandlerdata->_pszHandler);
  357. phandlerdata->Release();
  358. }
  359. return hr;
  360. }
  361. HRESULT CHWContentPromptDlg::_OnListSelChange()
  362. {
  363. return _UpdateHandlerSettings();
  364. }
  365. LRESULT CHWContentPromptDlg::OnOK(WORD wNotif)
  366. {
  367. if (BST_CHECKED == Button_GetCheck(GetDlgItem(_hwnd, IDC_AP_MXCT_CHECKBOX)))
  368. {
  369. _SaveSettings(FALSE);
  370. // return value????
  371. }
  372. else
  373. {
  374. _SaveSettings(TRUE);
  375. }
  376. _SetHandler();
  377. // Do default processing
  378. return CBaseContentDlg::OnOK(wNotif);
  379. }
  380. HRESULT CHWContentPromptDlg::_SaveSettings(BOOL fSoftCommit)
  381. {
  382. _data._fSoftCommit = fSoftCommit;
  383. return _dlmanager.Commit();
  384. }
  385. CMixedContentDlg::CMixedContentDlg() : _dpaContentTypeData(NULL)
  386. {
  387. }
  388. CMixedContentDlg::~CMixedContentDlg()
  389. {
  390. if (_dpaContentTypeData)
  391. {
  392. int c = _dpaContentTypeData.GetPtrCount();
  393. for (int i = 0; i < c; ++i)
  394. {
  395. CContentTypeData* pdata = _dpaContentTypeData.GetPtr(i);
  396. pdata->Release();
  397. }
  398. _dpaContentTypeData.Destroy();
  399. }
  400. }
  401. const DWORD c_rgdwContentTypeAutoplay[] =
  402. {
  403. CT_AUTOPLAYMUSIC,
  404. CT_AUTOPLAYPIX,
  405. CT_AUTOPLAYMOVIE,
  406. };
  407. HRESULT CMixedContentDlg::_InitDataObjects()
  408. {
  409. HRESULT hr = _dpaContentTypeData.Create(4) ? S_OK : E_OUTOFMEMORY;
  410. if (SUCCEEDED(hr))
  411. {
  412. for (DWORD dw = 0; dw < ARRAYSIZE(c_rgdwContentTypeAutoplay); ++dw)
  413. {
  414. if (_dwContentType & c_rgdwContentTypeAutoplay[dw])
  415. {
  416. CContentTypeData* pdata = new CContentTypeData();
  417. if (pdata)
  418. {
  419. hr = pdata->Init(_pszDeviceID, _dwContentType & c_rgdwContentTypeAutoplay[dw]);
  420. if (SUCCEEDED(hr))
  421. {
  422. if (-1 == _dpaContentTypeData.AppendPtr(pdata))
  423. {
  424. hr = E_OUTOFMEMORY;
  425. }
  426. }
  427. if (FAILED(hr))
  428. {
  429. pdata->Release();
  430. }
  431. }
  432. else
  433. {
  434. hr = E_OUTOFMEMORY;
  435. }
  436. }
  437. }
  438. if (SUCCEEDED(hr))
  439. {
  440. // Eliminate the duplicates. Go thru all the content types
  441. // and then thru all their handlers and see if their would
  442. // not be two duplicate handlers that were brought by two diff
  443. // content type. E.g.: Open folder is registered for music,
  444. // pictures and video
  445. int cContentType = _dpaContentTypeData.GetPtrCount();
  446. for (int iContentType = 0; iContentType < cContentType; ++iContentType)
  447. {
  448. CContentTypeData* pdata = _dpaContentTypeData.GetPtr(iContentType);
  449. if (pdata)
  450. {
  451. int cHandler = pdata->GetHandlerCount();
  452. for (int iHandler = 0; iHandler < cHandler; ++iHandler)
  453. {
  454. CHandlerData* phandlerdata = pdata->GetHandlerData(iHandler);
  455. if (phandlerdata)
  456. {
  457. for (int iContentTypeInner = 0;
  458. iContentTypeInner < cContentType;
  459. ++iContentTypeInner)
  460. {
  461. BOOL fExitInnerLoop = FALSE;
  462. // Cannot have duplicate handler within same content type
  463. if (iContentTypeInner != iContentType)
  464. {
  465. CContentTypeData* pdataInner = _dpaContentTypeData.GetPtr(iContentTypeInner);
  466. if (pdataInner)
  467. {
  468. int cHandlerInner = pdataInner->GetHandlerCount();
  469. for (int iHandlerInner = 0;
  470. !fExitInnerLoop && (iHandlerInner < cHandlerInner);
  471. ++iHandlerInner)
  472. {
  473. CHandlerData* phandlerdataInner = pdataInner->GetHandlerData(iHandlerInner);
  474. if (phandlerdataInner)
  475. {
  476. if (!lstrcmp(phandlerdataInner->_pszHandler,
  477. phandlerdata->_pszHandler))
  478. {
  479. pdataInner->RemoveHandler(iHandlerInner);
  480. // Can be only one duplicate for a
  481. // handler within another content type
  482. fExitInnerLoop = TRUE;
  483. }
  484. phandlerdataInner->Release();
  485. }
  486. }
  487. }
  488. }
  489. }
  490. phandlerdata->Release();
  491. }
  492. }
  493. }
  494. }
  495. }
  496. }
  497. else
  498. {
  499. hr = E_OUTOFMEMORY;
  500. }
  501. return hr;
  502. }
  503. HRESULT CMixedContentDlg::_FillListView()
  504. {
  505. HRESULT hr = _InitDataObjects();
  506. if (SUCCEEDED(hr))
  507. {
  508. if (_dpaContentTypeData)
  509. {
  510. int c = _dpaContentTypeData.GetPtrCount();
  511. for (int i = 0; SUCCEEDED(hr) && (i < c); ++i)
  512. {
  513. CContentTypeData* pdata = _dpaContentTypeData.GetPtr(i);
  514. if (pdata)
  515. {
  516. pdata->AddRef();
  517. int cHandler = pdata->GetHandlerCount();
  518. for (int j = 0; SUCCEEDED(hr) && (j < cHandler); ++j)
  519. {
  520. CHandlerData* phandlerdata = pdata->GetHandlerData(j);
  521. if (phandlerdata)
  522. {
  523. CHandlerLVItem* puidata = new CHandlerLVItem();
  524. if (puidata)
  525. {
  526. hr = puidata->InitData(phandlerdata);
  527. if (SUCCEEDED(hr))
  528. {
  529. hr = _uilListView.AddItem(puidata);
  530. }
  531. if (FAILED(hr))
  532. {
  533. delete puidata;
  534. }
  535. }
  536. else
  537. {
  538. hr = E_OUTOFMEMORY;
  539. }
  540. phandlerdata->Release();
  541. }
  542. }
  543. pdata->Release();
  544. }
  545. }
  546. }
  547. }
  548. return hr;
  549. }
  550. HRESULT CMixedContentDlg::_InitStatics()
  551. {
  552. return S_OK;
  553. }
  554. HRESULT CMixedContentDlg::_InitSelections()
  555. {
  556. HRESULT hr = _uilListView.SelectFirstItem();
  557. if (SUCCEEDED(hr))
  558. {
  559. CHandlerData* phandlerdata;
  560. hr = _uilListView.GetSelectedItemData(&phandlerdata);
  561. if (SUCCEEDED(hr))
  562. {
  563. hr = StringCchCopy(_szHandler, ARRAYSIZE(_szHandler),
  564. phandlerdata->_pszHandler);
  565. phandlerdata->Release();
  566. }
  567. }
  568. return hr;
  569. }
  570. HRESULT CMixedContentDlg::_OnListSelChange()
  571. {
  572. return S_OK;
  573. }
  574. LRESULT CMixedContentDlg::OnOK(WORD wNotif)
  575. {
  576. _SetHandler();
  577. if (_dpaContentTypeData)
  578. {
  579. BOOL fFound = FALSE;
  580. int c = _dpaContentTypeData.GetPtrCount();
  581. for (int i = 0; !fFound && (i < c); ++i)
  582. {
  583. CContentTypeData* pdata = _dpaContentTypeData.GetPtr(i);
  584. if (pdata)
  585. {
  586. pdata->AddRef();
  587. int cHandler = pdata->GetHandlerCount();
  588. for (int j = 0; !fFound && (j < cHandler); ++j)
  589. {
  590. CHandlerData* phandlerdata = pdata->GetHandlerData(j);
  591. if (phandlerdata)
  592. {
  593. if (!lstrcmp(phandlerdata->_pszHandler,
  594. _szHandler))
  595. {
  596. StringCchCopy(_szContentTypeHandler,
  597. ARRAYSIZE(_szContentTypeHandler),
  598. pdata->_szContentTypeHandler);
  599. fFound = TRUE;
  600. }
  601. phandlerdata->Release();
  602. }
  603. }
  604. pdata->Release();
  605. }
  606. }
  607. }
  608. // Do default processing
  609. return CBaseContentDlg::OnOK(wNotif);
  610. }
  611. ///////////////////////////////////////////////////////////////////////////////
  612. ///////////////////////////////////////////////////////////////////////////////
  613. ///////////////////////////////////////////////////////////////////////////////
  614. CNoContentDlg::CNoContentDlg() : CBaseContentDlg()
  615. {}
  616. CNoContentDlg::~CNoContentDlg()
  617. {}
  618. HRESULT CNoContentDlg::_InitDataObjects()
  619. {
  620. HRESULT hr = _data.Init(_pszDeviceID);
  621. if (SUCCEEDED(hr))
  622. {
  623. hr = _dlmanager.AddDataObject(&_data);
  624. }
  625. _SetAutoplayPromptHWND(_pszDeviceID, _hwnd);
  626. return hr;
  627. }
  628. HRESULT CNoContentDlg::_FillListView()
  629. {
  630. HRESULT hr = _InitDataObjects();
  631. if (SUCCEEDED(hr))
  632. {
  633. int c = _data.GetHandlerCount();
  634. for (int i = 0; SUCCEEDED(hr) && (i < c); ++i)
  635. {
  636. CHandlerData* phandlerdata = _data.GetHandlerData(i);
  637. if (phandlerdata)
  638. {
  639. CHandlerLVItem* puidata = new CHandlerLVItem();
  640. if (puidata)
  641. {
  642. hr = puidata->InitData(phandlerdata);
  643. if (SUCCEEDED(hr))
  644. {
  645. hr = _uilListView.AddItem(puidata);
  646. }
  647. if (FAILED(hr))
  648. {
  649. delete puidata;
  650. }
  651. }
  652. else
  653. {
  654. hr = E_OUTOFMEMORY;
  655. }
  656. phandlerdata->Release();
  657. }
  658. }
  659. }
  660. return hr;
  661. }
  662. HRESULT CNoContentDlg::_InitStatics()
  663. {
  664. if (_hiconTop)
  665. {
  666. DestroyIcon(_hiconTop);
  667. }
  668. // Set device icon
  669. _hiconTop = _GetIconFromIconLocation(_data._pszIconLocation, TRUE);
  670. SendDlgItemMessage(_hwnd, IDC_AP_MXCT_TOPICON, STM_SETIMAGE,
  671. IMAGE_ICON, (LPARAM)_hiconTop);
  672. // Set device name
  673. SetWindowText(_hwnd, _data._pszIconLabel);
  674. return S_OK;
  675. }
  676. HRESULT CNoContentDlg::_InitSelections()
  677. {
  678. HRESULT hr;
  679. if (_data._pszHandlerDefaultOriginal && *(_data._pszHandlerDefaultOriginal))
  680. {
  681. hr = _uilListView.SelectItem(_data._pszHandlerDefaultOriginal);
  682. }
  683. else
  684. {
  685. hr = _uilListView.SelectFirstItem();
  686. }
  687. if (SUCCEEDED(hr))
  688. {
  689. CHandlerData* phandlerdata;
  690. hr = _uilListView.GetSelectedItemData(&phandlerdata);
  691. if (SUCCEEDED(hr))
  692. {
  693. hr = StringCchCopy(_szHandler, ARRAYSIZE(_szHandler),
  694. phandlerdata->_pszHandler);
  695. if (SUCCEEDED(hr))
  696. {
  697. _SetHandlerDefault(&(_data._pszHandlerDefault),
  698. phandlerdata->_pszHandler);
  699. }
  700. phandlerdata->Release();
  701. }
  702. }
  703. Button_SetCheck(GetDlgItem(_hwnd, IDC_AP_MXCT_CHECKBOX), _fCheckAlwaysDoThis);
  704. return hr;
  705. }
  706. HRESULT CNoContentDlg::_UpdateHandlerSettings()
  707. {
  708. CHandlerData* phandlerdata;
  709. HRESULT hr = _uilListView.GetSelectedItemData(&phandlerdata);
  710. if (SUCCEEDED(hr))
  711. {
  712. _SetHandlerDefault(&(_data._pszHandlerDefault), phandlerdata->_pszHandler);
  713. phandlerdata->Release();
  714. }
  715. return hr;
  716. }
  717. HRESULT CNoContentDlg::_OnListSelChange()
  718. {
  719. return _UpdateHandlerSettings();
  720. }
  721. LRESULT CNoContentDlg::OnOK(WORD wNotif)
  722. {
  723. if (BST_CHECKED == Button_GetCheck(GetDlgItem(_hwnd, IDC_AP_MXCT_CHECKBOX)))
  724. {
  725. _SaveSettings(FALSE);
  726. // return value????
  727. }
  728. else
  729. {
  730. _SaveSettings(TRUE);
  731. }
  732. _SetHandler();
  733. // Do default processing
  734. return CBaseContentDlg::OnOK(wNotif);
  735. }
  736. HRESULT CNoContentDlg::_SaveSettings(BOOL fSoftCommit)
  737. {
  738. _data._fSoftCommit = fSoftCommit;
  739. return _dlmanager.Commit();
  740. }