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.

885 lines
25 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: A C L I S T . C P P
  7. //
  8. // Contents: Functions related to listview control in adavnced
  9. // configuration dialog.
  10. //
  11. // Notes:
  12. //
  13. // Author: danielwe 3 Dec 1997
  14. //
  15. //----------------------------------------------------------------------------
  16. #include "pch.h"
  17. #pragma hdrstop
  18. #include "acbind.h"
  19. #include "acsheet.h"
  20. #include "lancmn.h"
  21. #include "ncnetcfg.h"
  22. #include "ncnetcon.h"
  23. #include "ncsetup.h"
  24. #include "foldinc.h"
  25. extern const WCHAR c_szInfId_MS_TCPIP[];
  26. HRESULT CBindingsDlg::HrGetAdapters(INetCfgComponent *pncc,
  27. NCC_LIST *plistNcc)
  28. {
  29. Assert(pncc);
  30. HRESULT hr = S_OK;
  31. CIterNetCfgBindingPath ncbpIter(pncc);
  32. INetCfgBindingPath * pncbp;
  33. NCC_LIST listncc;
  34. INetCfgComponent * pnccLast;
  35. while (SUCCEEDED(hr) && S_OK == (hr = ncbpIter.HrNext(&pncbp)))
  36. {
  37. hr = HrGetLastComponentAndInterface(pncbp, &pnccLast, NULL);
  38. if (SUCCEEDED(hr))
  39. {
  40. hr = HrIsConnection(pnccLast);
  41. if (S_OK == hr)
  42. {
  43. plistNcc->push_back(pnccLast);
  44. }
  45. else
  46. {
  47. // Don't need it anymore so release it
  48. ReleaseObj(pnccLast);
  49. }
  50. }
  51. ReleaseObj(pncbp);
  52. }
  53. if (SUCCEEDED(hr))
  54. {
  55. if (plistNcc->empty())
  56. {
  57. hr = S_FALSE;
  58. }
  59. else
  60. {
  61. plistNcc->unique();
  62. hr = S_OK;
  63. }
  64. }
  65. TraceError("CBindingsDlg::HrGetAdapters", hr);
  66. return hr;
  67. }
  68. //+---------------------------------------------------------------------------
  69. //
  70. // Member: CBindingsDlg::HrBuildAdapterList
  71. //
  72. // Purpose: Builds the list of adapters displayed in the listview control
  73. //
  74. // Arguments:
  75. // (none)
  76. //
  77. // Returns: S_OK if succeeded, OLE or Win32 error otherwise
  78. //
  79. // Author: danielwe 19 Nov 1997
  80. //
  81. // Notes:
  82. //
  83. HRESULT CBindingsDlg::HrBuildAdapterList()
  84. {
  85. HRESULT hr = S_OK;
  86. INetCfgComponent * pncc = NULL;
  87. SP_CLASSIMAGELIST_DATA cid;
  88. INT nIndexWan;
  89. INT ipos = 0;
  90. NCC_LIST listncc;
  91. Assert(m_pnc);
  92. // Get the class image list structure
  93. hr = HrSetupDiGetClassImageList(&cid);
  94. if (SUCCEEDED(hr))
  95. {
  96. // Get the modem class image list index
  97. hr = HrSetupDiGetClassImageIndex(&cid,
  98. const_cast<LPGUID>(&GUID_DEVCLASS_MODEM),
  99. &nIndexWan);
  100. }
  101. if (SUCCEEDED(hr))
  102. {
  103. hr = m_pnc->FindComponent(c_szInfId_MS_TCPIP, &pncc);
  104. if (S_FALSE == hr)
  105. {
  106. // Hmm, TCP/IP is not installed. Better look for a protocol that
  107. // has bindings to an adapter.
  108. //
  109. CIterNetCfgComponent nccIter(m_pnc, &GUID_DEVCLASS_NETTRANS);
  110. while (SUCCEEDED(hr) && S_OK == (hr = nccIter.HrNext(&pncc)))
  111. {
  112. hr = HrGetAdapters(pncc, &listncc);
  113. ReleaseObj(pncc);
  114. if (S_OK == hr)
  115. {
  116. // We found one! Yay.
  117. break;
  118. }
  119. }
  120. }
  121. else if (S_OK == hr)
  122. {
  123. hr = HrGetAdapters(pncc, &listncc);
  124. ReleaseObj(pncc);
  125. }
  126. }
  127. if (S_OK == hr)
  128. {
  129. // Iterate all LAN connections
  130. //
  131. INetConnectionManager * pconMan;
  132. HRESULT hr = HrCreateInstance(
  133. CLSID_LanConnectionManager,
  134. CLSCTX_SERVER | CLSCTX_NO_CODE_DOWNLOAD,
  135. &pconMan);
  136. TraceHr(ttidError, FAL, hr, FALSE, "HrCreateInstance");
  137. if (SUCCEEDED(hr))
  138. {
  139. NCC_LIST::iterator iterlist;
  140. INetCfgComponent * pnccToAdd;
  141. for (iterlist = listncc.begin();
  142. iterlist != listncc.end();
  143. iterlist++)
  144. {
  145. CIterNetCon ncIter(pconMan, NCME_DEFAULT);
  146. INetConnection * pconn;
  147. GUID guidAdd;
  148. BOOL fAdded = FALSE;
  149. pnccToAdd = *iterlist;
  150. (VOID) pnccToAdd->GetInstanceGuid(&guidAdd);
  151. while (SUCCEEDED(hr) && !fAdded &&
  152. (S_OK == (ncIter.HrNext(&pconn))))
  153. {
  154. // Compare guid of connection's adapter to this
  155. // one. If we have a match, add it to the listview
  156. if (FPconnEqualGuid(pconn, guidAdd))
  157. {
  158. NETCON_PROPERTIES* pProps;
  159. hr = pconn->GetProperties(&pProps);
  160. if (SUCCEEDED(hr))
  161. {
  162. AddListViewItem(pnccToAdd, ipos, m_nIndexLan,
  163. pProps->pszwName);
  164. fAdded = TRUE;
  165. ipos++;
  166. FreeNetconProperties(pProps);
  167. }
  168. }
  169. ReleaseObj(pconn);
  170. }
  171. #if DBG
  172. if (!fAdded)
  173. {
  174. WCHAR szwGuid[64];
  175. StringFromGUID2(guidAdd, szwGuid, sizeof(szwGuid));
  176. TraceTag(ttidAdvCfg, "Never added item %S for this "
  177. "connection!", szwGuid);
  178. }
  179. #endif
  180. // Balance AddRef from HrGetLastComponentAndInterface()
  181. ReleaseObj(pnccToAdd);
  182. }
  183. ReleaseObj(pconMan);
  184. }
  185. listncc.erase(listncc.begin(), listncc.end());
  186. }
  187. // Display WAN Adapter Bindings
  188. if (SUCCEEDED(hr))
  189. {
  190. GetWanOrdering();
  191. AddListViewItem(NULL, m_fWanBindingsFirst ? 0 : ipos, nIndexWan,
  192. SzLoadIds(IDS_ADVCFG_WAN_ADAPTERS));
  193. }
  194. (void) HrSetupDiDestroyClassImageList(&cid);
  195. if (SUCCEEDED(hr))
  196. {
  197. SetAdapterButtons();
  198. ListView_SetColumnWidth(m_hwndLV, 0, LVSCW_AUTOSIZE);
  199. hr = S_OK;
  200. }
  201. // Select first item
  202. ListView_SetItemState(m_hwndLV, 0, LVIS_FOCUSED | LVIS_SELECTED,
  203. LVIS_FOCUSED | LVIS_SELECTED);
  204. TraceError("CBindingsDlg::HrBuildAdapterList", hr);
  205. return hr;
  206. }
  207. VOID CBindingsDlg::GetWanOrdering()
  208. {
  209. INetCfgSpecialCase * pncsc = NULL;
  210. if (SUCCEEDED(m_pnc->QueryInterface(IID_INetCfgSpecialCase,
  211. reinterpret_cast<LPVOID*>(&pncsc))))
  212. {
  213. (VOID) pncsc->GetWanAdaptersFirst(&m_fWanBindingsFirst);
  214. ReleaseObj(pncsc);
  215. }
  216. }
  217. VOID CBindingsDlg::SetWanOrdering()
  218. {
  219. INetCfgSpecialCase * pncsc = NULL;
  220. if (SUCCEEDED(m_pnc->QueryInterface(IID_INetCfgSpecialCase,
  221. reinterpret_cast<LPVOID*>(&pncsc))))
  222. {
  223. (VOID) pncsc->SetWanAdaptersFirst(m_fWanBindingsFirst);
  224. ReleaseObj(pncsc);
  225. }
  226. }
  227. //+---------------------------------------------------------------------------
  228. //
  229. // Member: CBindingsDlg::AddListViewItem
  230. //
  231. // Purpose: Adds the given component to the listview
  232. //
  233. // Arguments:
  234. // pncc [in] Component to be added. If NULL, then this is the
  235. // special WAN adapter component.
  236. // ipos [in] Position at which to add
  237. // nIndex [in] Index of icon into system image list
  238. // pszConnName [in] Connection name
  239. //
  240. // Returns: Nothing
  241. //
  242. // Author: danielwe 3 Dec 1997
  243. //
  244. // Notes:
  245. //
  246. VOID CBindingsDlg::AddListViewItem(INetCfgComponent *pncc, INT ipos,
  247. INT nIndex, PCWSTR pszConnName)
  248. {
  249. LV_ITEM lvi = {0};
  250. lvi.mask = LVIF_TEXT | LVIF_IMAGE |
  251. LVIF_STATE | LVIF_PARAM;
  252. lvi.iImage = nIndex;
  253. lvi.iItem = ipos;
  254. AddRefObj(pncc);
  255. lvi.lParam = reinterpret_cast<LPARAM>(pncc);
  256. lvi.pszText = const_cast<PWSTR>(pszConnName);
  257. ListView_InsertItem(m_hwndLV, &lvi);
  258. }
  259. //+---------------------------------------------------------------------------
  260. //
  261. // Member: CBindingsDlg::OnListItemChanged
  262. //
  263. // Purpose: Called when the LVN_ITEMCHANGED message is received
  264. //
  265. // Arguments:
  266. // idCtrl []
  267. // pnmh []
  268. // bHandled []
  269. //
  270. // Returns:
  271. //
  272. // Author: danielwe 19 Nov 1997
  273. //
  274. // Notes:
  275. //
  276. LRESULT CBindingsDlg::OnListItemChanged(int idCtrl, LPNMHDR pnmh,
  277. BOOL& bHandled)
  278. {
  279. NM_LISTVIEW * pnmlv = reinterpret_cast<NM_LISTVIEW *>(pnmh);
  280. Assert(pnmlv);
  281. // Check if selection changed
  282. if ((pnmlv->uNewState & LVIS_SELECTED) &&
  283. (!(pnmlv->uOldState & LVIS_SELECTED)))
  284. {
  285. if (pnmlv->iItem != m_iItemSel)
  286. {
  287. // Selection changed to different item
  288. OnAdapterChange(pnmlv->iItem);
  289. m_iItemSel = pnmlv->iItem;
  290. }
  291. }
  292. return 0;
  293. }
  294. //+---------------------------------------------------------------------------
  295. //
  296. // Member: CBindingsDlg::OnListDeleteItem
  297. //
  298. // Purpose: Called when the LVN_DELETEITEM message is received.
  299. //
  300. // Arguments:
  301. // idCtrl []
  302. // pnmh []
  303. // bHandled []
  304. //
  305. // Returns:
  306. //
  307. // Author: danielwe 4 Dec 1997
  308. //
  309. // Notes:
  310. //
  311. LRESULT CBindingsDlg::OnListDeleteItem(int idCtrl, LPNMHDR pnmh,
  312. BOOL& bHandled)
  313. {
  314. LV_ITEM lvi = {0};
  315. INetCfgComponent * pncc;
  316. NM_LISTVIEW * pnmlv = reinterpret_cast<NM_LISTVIEW *>(pnmh);
  317. Assert(pnmlv);
  318. lvi.mask = LVIF_PARAM;
  319. lvi.iItem = pnmlv->iItem;
  320. ListView_GetItem(m_hwndLV, &lvi);
  321. pncc = reinterpret_cast<INetCfgComponent *>(lvi.lParam);
  322. ReleaseObj(pncc);
  323. return 0;
  324. }
  325. //+---------------------------------------------------------------------------
  326. //
  327. // Member: CBindingsDlg::OnAdapterChange
  328. //
  329. // Purpose: Handles the selection of a different adapter from the listview
  330. //
  331. // Arguments:
  332. // iItem [in] Item in list that was selected
  333. //
  334. // Returns: S_OK if success, OLE or Win32 error otherwise
  335. //
  336. // Author: danielwe 19 Nov 1997
  337. //
  338. // Notes:
  339. //
  340. VOID CBindingsDlg::OnAdapterChange(INT iItem)
  341. {
  342. LV_ITEM lvi = {0};
  343. INetCfgComponent * pncc;
  344. PWSTR szwText;
  345. WCHAR szBuffer[256];
  346. lvi.mask = LVIF_TEXT | LVIF_PARAM;
  347. lvi.pszText = szBuffer;
  348. lvi.cchTextMax = celems(szBuffer);
  349. lvi.iItem = iItem;
  350. ListView_GetItem(m_hwndLV, &lvi);
  351. TreeView_DeleteAllItems(m_hwndTV);
  352. pncc = reinterpret_cast<INetCfgComponent *>(lvi.lParam);
  353. if (pncc)
  354. {
  355. BuildBindingsList(pncc);
  356. SetCheckboxStates();
  357. }
  358. SetAdapterButtons();
  359. DwFormatStringWithLocalAlloc(SzLoadIds(IDS_BINDINGS_FOR), &szwText,
  360. lvi.pszText);
  361. BOOL bShouldEnable = TRUE;
  362. if (!pncc)
  363. {
  364. // If the WAN bindings item is selected, hide and disable the treeview
  365. bShouldEnable = FALSE;
  366. }
  367. else
  368. {
  369. // if a LAN item is selected, make sure the treeview is enabled
  370. GUID guid;
  371. HRESULT hr = pncc->GetInstanceGuid(&guid);
  372. if (SUCCEEDED(hr))
  373. {
  374. ConnListEntry cle;
  375. hr = g_ccl.HrFindConnectionByGuid(&guid, cle);
  376. if (S_FALSE == hr)
  377. {
  378. hr = g_ccl.HrRefreshConManEntries();
  379. if (SUCCEEDED(hr))
  380. {
  381. hr = g_ccl.HrFindConnectionByGuid(&guid, cle);
  382. }
  383. }
  384. if (S_OK == hr)
  385. {
  386. if ( (NCM_LAN == cle.ccfe.GetNetConMediaType()) &&
  387. (cle.ccfe.GetCharacteristics() & NCCF_BRIDGED) )
  388. {
  389. bShouldEnable = FALSE;
  390. }
  391. }
  392. }
  393. }
  394. if (bShouldEnable)
  395. {
  396. ::ShowWindow(GetDlgItem(IDH_TXT_ADVGFG_BINDINGS), SW_SHOW);
  397. ::EnableWindow(GetDlgItem(IDH_TXT_ADVGFG_BINDINGS), TRUE);
  398. ::EnableWindow(GetDlgItem(TVW_Bindings), TRUE);
  399. }
  400. else
  401. {
  402. ::ShowWindow(GetDlgItem(IDH_TXT_ADVGFG_BINDINGS), SW_HIDE);
  403. ::EnableWindow(GetDlgItem(IDH_TXT_ADVGFG_BINDINGS), FALSE);
  404. ::EnableWindow(GetDlgItem(TVW_Bindings), FALSE);
  405. }
  406. SetDlgItemText(IDH_TXT_ADVGFG_BINDINGS, szwText);
  407. LocalFree(szwText);
  408. }
  409. //+---------------------------------------------------------------------------
  410. //
  411. // Member: CBindingsDlg::OnAdapterUpDown
  412. //
  413. // Purpose: Helper function that performs most of the work to move
  414. // adapter bindings
  415. //
  416. // Arguments:
  417. // fUp [in] TRUE if moving up, FALSE if down
  418. //
  419. // Returns: Nothing
  420. //
  421. // Author: danielwe 2 Dec 1997
  422. //
  423. // Notes:
  424. //
  425. VOID CBindingsDlg::OnAdapterUpDown(BOOL fUp)
  426. {
  427. INetCfgComponent * pnccSrc;
  428. INetCfgComponent * pnccDst;
  429. INT iSel;
  430. INT iDst;
  431. LV_ITEM lvi = {0};
  432. WCHAR szBuffer[256];
  433. iSel = ListView_GetNextItem(m_hwndLV, -1, LVNI_SELECTED);
  434. AssertSz(iSel != -1, "No Selection?!?!?");
  435. lvi.mask = LVIF_PARAM | LVIF_TEXT | LVIF_IMAGE | LVIF_STATE;
  436. lvi.pszText = szBuffer;
  437. lvi.cchTextMax = celems(szBuffer);
  438. lvi.iItem = iSel;
  439. ListView_GetItem(m_hwndLV, &lvi);
  440. pnccSrc = reinterpret_cast<INetCfgComponent *>(lvi.lParam);
  441. if (pnccSrc)
  442. {
  443. // Normal LAN adapter
  444. iDst = ListView_GetNextItem(m_hwndLV, iSel,
  445. fUp ? LVNI_ABOVE : LVNI_BELOW);
  446. AssertSz(iDst != -1, "No item above or below!");
  447. }
  448. else
  449. {
  450. m_fWanBindingsFirst = fUp;
  451. // WAN binding item
  452. iDst = fUp ? 0 : ListView_GetItemCount(m_hwndLV) - 1;
  453. }
  454. lvi.iItem = iDst;
  455. ListView_GetItem(m_hwndLV, &lvi);
  456. pnccDst = reinterpret_cast<INetCfgComponent *>(lvi.lParam);
  457. AssertSz(pnccDst, "Dest Component is NULL!?!?");
  458. if (pnccSrc)
  459. {
  460. MoveAdapterBindings(pnccSrc, pnccDst, fUp ? MAB_UP : MAB_DOWN);
  461. }
  462. else
  463. {
  464. SetWanOrdering();
  465. }
  466. // Delete source item and move to where dest item is
  467. // Note: (danielwe) 2 Dec 1997: For LVN_DELETEITEM handler, make sure
  468. // refcount remains the same
  469. // Get item we are moving
  470. lvi.iItem = iSel;
  471. ListView_GetItem(m_hwndLV, &lvi);
  472. // Make the lParam of the item NULL so we don't release it
  473. ChangeListItemParam(m_hwndLV, iSel, NULL);
  474. ListView_DeleteItem(m_hwndLV, iSel);
  475. // Change its index
  476. lvi.iItem = iDst;
  477. lvi.state = lvi.stateMask = 0;
  478. // And insert in new location
  479. int iItem = ListView_InsertItem(m_hwndLV, &lvi);
  480. if (-1 != iItem)
  481. {
  482. ListView_SetItemState(m_hwndLV, iItem, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  483. }
  484. // Reset cached selection
  485. m_iItemSel = iDst;
  486. SetAdapterButtons();
  487. ::SetFocus(m_hwndLV);
  488. }
  489. //+---------------------------------------------------------------------------
  490. //
  491. // Member: CBindingsDlg::OnAdapterUp
  492. //
  493. // Purpose: Called when the adapter UP arrow button is pressed
  494. //
  495. // Arguments:
  496. // wNotifyCode []
  497. // wID []
  498. // hWndCtl []
  499. // bHandled []
  500. //
  501. // Returns:
  502. //
  503. // Author: danielwe 2 Dec 1997
  504. //
  505. // Notes:
  506. //
  507. LRESULT CBindingsDlg::OnAdapterUp(WORD wNotifyCode, WORD wID, HWND hWndCtl,
  508. BOOL& bHandled)
  509. {
  510. OnAdapterUpDown(TRUE);
  511. return 0;
  512. }
  513. //+---------------------------------------------------------------------------
  514. //
  515. // Member: CBindingsDlg::OnAdapterDown
  516. //
  517. // Purpose: Called when the adapter DOWN button is pressed
  518. //
  519. // Arguments:
  520. // wNotifyCode []
  521. // wID []
  522. // hWndCtl []
  523. // bHandled []
  524. //
  525. // Returns:
  526. //
  527. // Author: danielwe 2 Dec 1997
  528. //
  529. // Notes:
  530. //
  531. LRESULT CBindingsDlg::OnAdapterDown(WORD wNotifyCode, WORD wID, HWND hWndCtl,
  532. BOOL& bHandled)
  533. {
  534. OnAdapterUpDown(FALSE);
  535. return 0;
  536. }
  537. //+---------------------------------------------------------------------------
  538. //
  539. // Member: CBindingsDlg::FIsWanBinding
  540. //
  541. // Purpose: Determines if the given list view item is the special WAN
  542. // adapter ordering item.
  543. //
  544. // Arguments:
  545. // iItem [in] List view item to test
  546. //
  547. // Returns: TRUE if this is the WAN adapter ordering item or FALSE if not
  548. //
  549. // Author: danielwe 21 Jul 1998
  550. //
  551. // Notes:
  552. //
  553. BOOL CBindingsDlg::FIsWanBinding(INT iItem)
  554. {
  555. if (iItem != -1)
  556. {
  557. LV_ITEM lvi = {0};
  558. lvi.mask = LVIF_PARAM;
  559. lvi.iItem = iItem;
  560. ListView_GetItem(m_hwndLV, &lvi);
  561. return !lvi.lParam;
  562. }
  563. else
  564. {
  565. // Invalid item can't be the WAN binding
  566. return FALSE;
  567. }
  568. }
  569. //+---------------------------------------------------------------------------
  570. //
  571. // Member: CBindingsDlg::SetAdapterButtons
  572. //
  573. // Purpose: Sets the state of the up and down arrow buttons for the
  574. // adapters listview
  575. //
  576. // Arguments:
  577. // (none)
  578. //
  579. // Returns: Nothing
  580. //
  581. // Author: danielwe 19 Nov 1997
  582. //
  583. // Notes:
  584. //
  585. VOID CBindingsDlg::SetAdapterButtons()
  586. {
  587. INT iItemAbove = -1;
  588. INT iItemBelow = -1;
  589. INT iItem;
  590. iItem = ListView_GetNextItem(m_hwndLV, -1, LVNI_SELECTED);
  591. if (ListView_GetItemCount(m_hwndLV) > 1)
  592. {
  593. iItemAbove = ListView_GetNextItem(m_hwndLV, iItem, LVNI_ABOVE);
  594. iItemBelow = ListView_GetNextItem(m_hwndLV, iItem, LVNI_BELOW);
  595. if (FIsWanBinding(iItemAbove))
  596. {
  597. iItemAbove = -1;
  598. AssertSz(ListView_GetNextItem(m_hwndLV, iItemAbove, LVNI_ABOVE) == -1,
  599. "Item above the WAN binding??");
  600. }
  601. else if (FIsWanBinding(iItemBelow))
  602. {
  603. iItemBelow = -1;
  604. AssertSz(ListView_GetNextItem(m_hwndLV, iItemBelow, LVNI_BELOW) == -1,
  605. "Item below the WAN binding??");
  606. }
  607. }
  608. ::EnableWindow(GetDlgItem(PSB_Adapter_Up), (iItemAbove != -1));
  609. ::EnableWindow(GetDlgItem(PSB_Adapter_Down), (iItemBelow != -1));
  610. }
  611. static const GUID * c_aguidClass[] =
  612. {
  613. &GUID_DEVCLASS_NETTRANS,
  614. &GUID_DEVCLASS_NETSERVICE,
  615. &GUID_DEVCLASS_NETCLIENT,
  616. };
  617. static const DWORD c_cguidClass = celems(c_aguidClass);
  618. //+---------------------------------------------------------------------------
  619. //
  620. // Member: CBindingsDlg::MoveAdapterBindings
  621. //
  622. // Purpose: Moves all bindings for the given source and destination
  623. // adapters in the given direction
  624. //
  625. // Arguments:
  626. // pnccSrc [in] Adapter for which bindings are being moved
  627. // pnccDst [in] Adapter to which bindings are being moved before or
  628. // after
  629. // mabDir [in] Direction to move. Either MAB_UP or MAB_DOWN
  630. //
  631. // Returns: Nothing
  632. //
  633. // Author: danielwe 2 Dec 1997
  634. //
  635. // Notes:
  636. //
  637. VOID CBindingsDlg::MoveAdapterBindings(INetCfgComponent *pnccSrc,
  638. INetCfgComponent *pnccDst,
  639. MAB_DIRECTION mabDir)
  640. {
  641. HRESULT hr = S_OK;
  642. DWORD iguid;
  643. AssertSz(pnccDst, "Destination component cannot be NULL!");
  644. for (iguid = 0; iguid < c_cguidClass; iguid++)
  645. {
  646. CIterNetCfgComponent nccIter(m_pnc, c_aguidClass[iguid]);
  647. INetCfgComponent * pncc;
  648. while (SUCCEEDED(hr) && S_OK == (hr = nccIter.HrNext(&pncc)))
  649. {
  650. CIterNetCfgBindingPath ncbpIter(pncc);
  651. INetCfgBindingPath * pncbp;
  652. INetCfgBindingPath * pncbpTarget = NULL;
  653. BOOL fAssign = TRUE;
  654. NCBP_LIST listbp;
  655. INetCfgComponent * pnccLast;
  656. while (SUCCEEDED(hr) && S_OK == (hr = ncbpIter.HrNext(&pncbp)))
  657. {
  658. hr = HrGetLastComponentAndInterface(pncbp, &pnccLast, NULL);
  659. if (SUCCEEDED(hr))
  660. {
  661. if (pnccLast == pnccDst)
  662. {
  663. if ((mabDir == MAB_UP) && fAssign)
  664. {
  665. AddRefObj(pncbpTarget = pncbp);
  666. fAssign = FALSE;
  667. }
  668. else if (mabDir == MAB_DOWN)
  669. {
  670. ReleaseObj(pncbpTarget);
  671. AddRefObj(pncbpTarget = pncbp);
  672. }
  673. }
  674. else if (pnccLast == pnccSrc)
  675. {
  676. AddRefObj(pncbp);
  677. listbp.push_back(pncbp);
  678. }
  679. ReleaseObj(pnccLast);
  680. }
  681. ReleaseObj(pncbp);
  682. }
  683. if (SUCCEEDED(hr))
  684. {
  685. NCBP_LIST::iterator iterbp;
  686. INetCfgComponentBindings * pnccb;
  687. hr = pncc->QueryInterface(IID_INetCfgComponentBindings,
  688. reinterpret_cast<LPVOID *>(&pnccb));
  689. if (SUCCEEDED(hr))
  690. {
  691. for (iterbp = listbp.begin();
  692. (iterbp != listbp.end()) && SUCCEEDED(hr);
  693. iterbp++)
  694. {
  695. if (mabDir == MAB_UP)
  696. {
  697. TraceTag(ttidAdvCfg, "Moving...");
  698. DbgDumpBindPath(*iterbp);
  699. // Move this binding path before the tagret
  700. hr = pnccb->MoveBefore(*iterbp, pncbpTarget);
  701. TraceTag(ttidAdvCfg, "before...");
  702. DbgDumpBindPath(pncbpTarget);
  703. }
  704. else
  705. {
  706. TraceTag(ttidAdvCfg, "Moving...");
  707. DbgDumpBindPath(*iterbp);
  708. // Move this binding path after the tagret
  709. hr = pnccb->MoveAfter(*iterbp, pncbpTarget);
  710. TraceTag(ttidAdvCfg, "after...");
  711. DbgDumpBindPath(pncbpTarget);
  712. }
  713. if (mabDir == MAB_DOWN)
  714. {
  715. // In the down direction ONLY, from now on, the
  716. // target becomes the last binding we moved. This
  717. // keeps the binding order intact because moving
  718. // several bindings after the same target
  719. // effectively reverses their order.
  720. //
  721. // Release old target
  722. ReleaseObj(pncbpTarget);
  723. // AddRef new target
  724. AddRefObj(pncbpTarget = *iterbp);
  725. }
  726. ReleaseObj(*iterbp);
  727. }
  728. ReleaseObj(pnccb);
  729. }
  730. listbp.erase(listbp.begin(), listbp.end());
  731. }
  732. ReleaseObj(pncbpTarget);
  733. ReleaseObj(pncc);
  734. }
  735. }
  736. if (SUCCEEDED(hr))
  737. {
  738. hr = S_OK;
  739. }
  740. TraceError("CBindingsDlg::MoveAdapterBindings", hr);
  741. }
  742. //+---------------------------------------------------------------------------
  743. //
  744. // Function: ChangeListItemParam
  745. //
  746. // Purpose: Changes the lParam member of the given item to the given
  747. // value.
  748. //
  749. // Arguments:
  750. // hwndLV [in] HWND of list view
  751. // iItem [in] Item to modify
  752. // lParam [in] New lParam for item
  753. //
  754. // Returns: Nothing
  755. //
  756. // Author: danielwe 4 Dec 1997
  757. //
  758. // Notes:
  759. //
  760. VOID ChangeListItemParam(HWND hwndLV, INT iItem, LPARAM lParam)
  761. {
  762. LV_ITEM lvi = {0};
  763. lvi.mask = LVIF_PARAM;
  764. lvi.iItem = iItem;
  765. lvi.lParam = lParam;
  766. ListView_SetItem(hwndLV, &lvi);
  767. }