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.

871 lines
23 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 2002 **/
  4. /**********************************************************************/
  5. /*
  6. ipsmhand.cpp
  7. IPSecMon specifc handler base classes
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "ipsmhand.h"
  12. #include "snaputil.h" // For CGUIDArray
  13. #include "extract.h" // For ExtractInternalFormat
  14. //TODO the help file
  15. const TCHAR g_szDefaultHelpTopic[] = _T("\\help\\ipsecconcepts.chm::/sag_IPSECtopnode.htm");
  16. /*---------------------------------------------------------------------------
  17. CMTIpsmHandler::OnChangeState
  18. Description
  19. Author: NSun
  20. ---------------------------------------------------------------------------*/
  21. void CMTIpsmHandler::OnChangeState
  22. (
  23. ITFSNode * pNode
  24. )
  25. {
  26. // Increment the state to the next position
  27. switch (m_nState)
  28. {
  29. case notLoaded:
  30. case loaded:
  31. case unableToLoad:
  32. {
  33. m_nState = loading;
  34. m_dwErr = 0;
  35. }
  36. break;
  37. case loading:
  38. {
  39. m_nState = (m_dwErr != 0) ? unableToLoad : loaded;
  40. if (m_dwErr)
  41. {
  42. CString strPrefix;
  43. GetErrorPrefix(pNode, &strPrefix);
  44. if (!strPrefix.IsEmpty())
  45. ::IpsmMessageBoxEx(m_dwErr, strPrefix);
  46. }
  47. }
  48. break;
  49. default:
  50. ASSERT(FALSE);
  51. }
  52. // check to make sure we are still the visible node in the UI
  53. if (m_bSelected)
  54. {
  55. UpdateStandardVerbs(pNode, pNode->GetData(TFS_DATA_TYPE));
  56. }
  57. // Now check and see if there is a new image for this state for this handler
  58. int nImage, nOpenImage;
  59. nImage = GetImageIndex(FALSE);
  60. nOpenImage = GetImageIndex(TRUE);
  61. if (nImage >= 0)
  62. pNode->SetData(TFS_DATA_IMAGEINDEX, nImage);
  63. if (nOpenImage >= 0)
  64. pNode->SetData(TFS_DATA_OPENIMAGEINDEX, nOpenImage);
  65. VERIFY(SUCCEEDED(pNode->ChangeNode(SCOPE_PANE_CHANGE_ITEM_ICON)));
  66. }
  67. /*!--------------------------------------------------------------------------
  68. CMTIpsmHandler::UpdateStandardVerbs
  69. Tells the IComponent to update the verbs for this node
  70. Author: NSun
  71. ---------------------------------------------------------------------------*/
  72. void
  73. CMTIpsmHandler::UpdateStandardVerbs
  74. (
  75. ITFSNode * pNode,
  76. LONG_PTR dwNodeType
  77. )
  78. {
  79. HRESULT hr = hrOK;
  80. SPIComponentData spCompData;
  81. SPIConsole spConsole;
  82. IDataObject* pDataObject;
  83. m_spNodeMgr->GetComponentData(&spCompData);
  84. CORg ( spCompData->QueryDataObject(NULL, CCT_RESULT, &pDataObject) );
  85. CORg ( m_spNodeMgr->GetConsole(&spConsole) );
  86. CORg ( spConsole->UpdateAllViews(pDataObject,
  87. reinterpret_cast<MMC_COOKIE>(pNode),
  88. RESULT_PANE_UPDATE_VERBS) );
  89. pDataObject->Release();
  90. Error:
  91. return;
  92. }
  93. /*!--------------------------------------------------------------------------
  94. CMTIpsmHandler::OnCreateDataObject
  95. -
  96. Author: NSun
  97. ---------------------------------------------------------------------------*/
  98. STDMETHODIMP
  99. CMTIpsmHandler::OnCreateDataObject
  100. (
  101. ITFSComponent * pComponent,
  102. MMC_COOKIE cookie,
  103. DATA_OBJECT_TYPES type,
  104. IDataObject ** ppDataObject
  105. )
  106. {
  107. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  108. Assert(ppDataObject != NULL);
  109. CDataObject * pObject = NULL;
  110. SPIDataObject spDataObject;
  111. pObject = new CDataObject;
  112. spDataObject = pObject; // do this so that it gets released correctly
  113. Assert(pObject != NULL);
  114. if (cookie == MMC_MULTI_SELECT_COOKIE)
  115. {
  116. CreateMultiSelectData(pComponent, pObject);
  117. }
  118. // Save cookie and type for delayed rendering
  119. pObject->SetType(type);
  120. pObject->SetCookie(cookie);
  121. // Store the coclass with the data object
  122. pObject->SetClsid(*(m_spTFSComponentData->GetCoClassID()));
  123. pObject->SetTFSComponentData(m_spTFSComponentData);
  124. return pObject->QueryInterface(IID_IDataObject,
  125. reinterpret_cast<void**>(ppDataObject));
  126. }
  127. HRESULT
  128. CMTIpsmHandler::CreateMultiSelectData(ITFSComponent * pComponent, CDataObject * pObject)
  129. {
  130. HRESULT hr = hrOK;
  131. // build the list of selected nodes
  132. CTFSNodeList listSelectedNodes;
  133. CGUIDArray rgGuids;
  134. UINT cb;
  135. GUID* pGuid;
  136. COM_PROTECT_TRY
  137. {
  138. CORg (BuildSelectedItemList(pComponent, &listSelectedNodes));
  139. // collect all of the unique guids
  140. while (listSelectedNodes.GetCount() > 0)
  141. {
  142. SPITFSNode spCurNode;
  143. const GUID * pConstGuid;
  144. spCurNode = listSelectedNodes.RemoveHead();
  145. pConstGuid = spCurNode->GetNodeType();
  146. rgGuids.AddUnique(*pConstGuid);
  147. }
  148. // now put the information in the data object
  149. pObject->SetMultiSelDobj();
  150. cb = (UINT)rgGuids.GetSize() * sizeof(GUID);
  151. pGuid = new GUID[(size_t)rgGuids.GetSize()];
  152. CopyMemory(pGuid, rgGuids.GetData(), cb);
  153. pObject->SetMultiSelData((BYTE*)pGuid, cb);
  154. COM_PROTECT_ERROR_LABEL;
  155. }
  156. COM_PROTECT_CATCH
  157. return hr;
  158. }
  159. /*!--------------------------------------------------------------------------
  160. CMTIpsmHandler::SaveColumns
  161. -
  162. Author: NSun
  163. ---------------------------------------------------------------------------*/
  164. HRESULT
  165. CMTIpsmHandler::SaveColumns
  166. (
  167. ITFSComponent * pComponent,
  168. MMC_COOKIE cookie,
  169. LPARAM arg,
  170. LPARAM lParam
  171. )
  172. {
  173. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  174. HRESULT hr = hrOK;
  175. LONG_PTR dwNodeType;
  176. int nCol = 0;
  177. int nColWidth;
  178. SPITFSNode spNode, spRootNode;
  179. SPIHeaderCtrl spHeaderCtrl;
  180. BOOL bDirty = FALSE;
  181. CORg (m_spNodeMgr->FindNode(cookie, &spNode));
  182. CORg (pComponent->GetHeaderCtrl(&spHeaderCtrl));
  183. dwNodeType = spNode->GetData(TFS_DATA_TYPE);
  184. while (aColumns[dwNodeType][nCol] != 0)
  185. {
  186. if ( (SUCCEEDED(spHeaderCtrl->GetColumnWidth(nCol, &nColWidth))) &&
  187. (aColumnWidths[dwNodeType][nCol] != nColWidth) )
  188. {
  189. aColumnWidths[dwNodeType][nCol] = nColWidth;
  190. bDirty = TRUE;
  191. }
  192. nCol++;
  193. }
  194. if (bDirty)
  195. {
  196. CORg (m_spNodeMgr->GetRootNode(&spRootNode));
  197. spRootNode->SetData(TFS_DATA_DIRTY, TRUE);
  198. }
  199. Error:
  200. return hr;
  201. }
  202. /*!--------------------------------------------------------------------------
  203. CMTIpsmHandler::OnResultSelect
  204. Handles the MMCN_SELECT notifcation
  205. Author: NSun
  206. ---------------------------------------------------------------------------*/
  207. HRESULT
  208. CMTIpsmHandler::OnResultSelect
  209. (
  210. ITFSComponent * pComponent,
  211. LPDATAOBJECT pDataObject,
  212. MMC_COOKIE cookie,
  213. LPARAM arg,
  214. LPARAM lParam
  215. )
  216. {
  217. SPIConsoleVerb spConsoleVerb;
  218. SPITFSNode spNode;
  219. HRESULT hr = hrOK;
  220. SPINTERNAL spInternal;
  221. BOOL bMultiSelect = FALSE;
  222. BOOL bScope = (BOOL) LOWORD(arg);
  223. BOOL bSelect = (BOOL) HIWORD(arg);
  224. m_bSelected = bSelect;
  225. Trace1("CMTIpsmHandler::OnResultSelect select = %d\n", bSelect);
  226. CORg (pComponent->GetConsoleVerb(&spConsoleVerb));
  227. spInternal = ::ExtractInternalFormat(pDataObject);
  228. if (spInternal &&
  229. spInternal->m_cookie == MMC_MULTI_SELECT_COOKIE)
  230. {
  231. CORg (pComponent->GetSelectedNode(&spNode));
  232. bMultiSelect = TRUE;
  233. }
  234. else
  235. {
  236. CORg (m_spNodeMgr->FindNode(cookie, &spNode));
  237. }
  238. UpdateConsoleVerbs(spConsoleVerb, spNode->GetData(TFS_DATA_TYPE), bMultiSelect);
  239. Error:
  240. return hr;
  241. }
  242. /*!--------------------------------------------------------------------------
  243. CMTIpsmHandler::OnResultUpdateView
  244. Implementation of ITFSResultHandler::OnResultUpdateView
  245. Author: NSun
  246. ---------------------------------------------------------------------------*/
  247. HRESULT CMTIpsmHandler::OnResultUpdateView
  248. (
  249. ITFSComponent *pComponent,
  250. LPDATAOBJECT pDataObject,
  251. LPARAM data,
  252. LPARAM hint
  253. )
  254. {
  255. HRESULT hr = hrOK;
  256. if (hint == RESULT_PANE_UPDATE_VERBS)
  257. {
  258. SPIConsoleVerb spConsoleVerb;
  259. SPITFSNode spNode;
  260. CORg (pComponent->GetConsoleVerb(&spConsoleVerb));
  261. spNode.Set(reinterpret_cast<ITFSNode *>(data));
  262. UpdateConsoleVerbs(spConsoleVerb, spNode->GetData(TFS_DATA_TYPE));
  263. }
  264. else
  265. {
  266. return CBaseResultHandler::OnResultUpdateView(pComponent, pDataObject, data, hint);
  267. }
  268. Error:
  269. return hr;
  270. }
  271. /*!--------------------------------------------------------------------------
  272. CMTIpsmHandler::OnResultContextHelp
  273. Implementation of ITFSResultHandler::OnResultContextHelp
  274. Author: NSun
  275. ---------------------------------------------------------------------------*/
  276. HRESULT
  277. CMTIpsmHandler::OnResultContextHelp
  278. (
  279. ITFSComponent * pComponent,
  280. LPDATAOBJECT pDataObject,
  281. MMC_COOKIE cookie,
  282. LPARAM arg,
  283. LPARAM lParam
  284. )
  285. {
  286. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  287. HRESULT hr = hrOK;
  288. SPIDisplayHelp spDisplayHelp;
  289. SPIConsole spConsole;
  290. pComponent->GetConsole(&spConsole);
  291. hr = spConsole->QueryInterface (IID_IDisplayHelp, (LPVOID*) &spDisplayHelp);
  292. ASSERT (SUCCEEDED (hr));
  293. if ( SUCCEEDED (hr) )
  294. {
  295. LPCTSTR pszHelpFile = m_spTFSCompData->GetHTMLHelpFileName();
  296. if (pszHelpFile == NULL)
  297. goto Error;
  298. CString szHelpFilePath;
  299. UINT nLen = ::GetWindowsDirectory (szHelpFilePath.GetBufferSetLength(2 * MAX_PATH), 2 * MAX_PATH);
  300. if (nLen == 0)
  301. {
  302. hr = E_FAIL;
  303. goto Error;
  304. }
  305. szHelpFilePath.ReleaseBuffer();
  306. szHelpFilePath += g_szDefaultHelpTopic;
  307. hr = spDisplayHelp->ShowTopic (T2OLE ((LPTSTR)(LPCTSTR) szHelpFilePath));
  308. ASSERT (SUCCEEDED (hr));
  309. }
  310. Error:
  311. return hr;
  312. }
  313. /*!--------------------------------------------------------------------------
  314. CMTIpsmHandler::UpdateStandardVerbs
  315. Updates the standard verbs depending upon the state of the node
  316. Author: NSun
  317. ---------------------------------------------------------------------------*/
  318. void
  319. CMTIpsmHandler::UpdateConsoleVerbs
  320. (
  321. IConsoleVerb * pConsoleVerb,
  322. LONG_PTR dwNodeType,
  323. BOOL bMultiSelect
  324. )
  325. {
  326. BOOL bStates[ARRAYLEN(g_ConsoleVerbs)];
  327. MMC_BUTTON_STATE * ButtonState;
  328. int i;
  329. if (bMultiSelect)
  330. {
  331. ButtonState = g_ConsoleVerbStatesMultiSel[dwNodeType];
  332. for (i = 0; i < ARRAYLEN(g_ConsoleVerbs); bStates[i++] = TRUE);
  333. }
  334. else
  335. {
  336. ButtonState = g_ConsoleVerbStates[dwNodeType];
  337. switch (m_nState)
  338. {
  339. case loaded:
  340. for (i = 0; i < ARRAYLEN(g_ConsoleVerbs); bStates[i++] = TRUE);
  341. break;
  342. case notLoaded:
  343. case loading:
  344. for (i = 0; i < ARRAYLEN(g_ConsoleVerbs); bStates[i++] = FALSE);
  345. break;
  346. case unableToLoad:
  347. for (i = 0; i < ARRAYLEN(g_ConsoleVerbs); bStates[i++] = FALSE);
  348. bStates[MMC_VERB_REFRESH & 0x000F] = TRUE;
  349. bStates[MMC_VERB_DELETE & 0x000F] = TRUE;
  350. break;
  351. }
  352. }
  353. EnableVerbs(pConsoleVerb, ButtonState, bStates);
  354. }
  355. /*!--------------------------------------------------------------------------
  356. CMTIpsmHandler::EnableVerbs
  357. Enables the verb buttons
  358. Author: NSun
  359. ---------------------------------------------------------------------------*/
  360. void
  361. CMTIpsmHandler::EnableVerbs
  362. (
  363. IConsoleVerb * pConsoleVerb,
  364. MMC_BUTTON_STATE ButtonState[],
  365. BOOL bState[]
  366. )
  367. {
  368. if (pConsoleVerb == NULL)
  369. {
  370. Assert(FALSE);
  371. return;
  372. }
  373. for (int i=0; i < ARRAYLEN(g_ConsoleVerbs); ++i)
  374. {
  375. if (ButtonState[i] == ENABLED)
  376. {
  377. // unhide this button before enabling
  378. pConsoleVerb->SetVerbState(g_ConsoleVerbs[i],
  379. HIDDEN,
  380. FALSE);
  381. pConsoleVerb->SetVerbState(g_ConsoleVerbs[i],
  382. ButtonState[i],
  383. bState[i]);
  384. }
  385. else
  386. {
  387. // hide this button
  388. pConsoleVerb->SetVerbState(g_ConsoleVerbs[i],
  389. HIDDEN,
  390. TRUE);
  391. }
  392. }
  393. pConsoleVerb->SetDefaultVerb(m_verbDefault);
  394. }
  395. /*!--------------------------------------------------------------------------
  396. CMTIpsmHandler::OnResultRefresh
  397. Call into the MTHandler to do a refresh
  398. Author: NSun
  399. ---------------------------------------------------------------------------*/
  400. HRESULT
  401. CMTIpsmHandler::OnResultRefresh
  402. (
  403. ITFSComponent * pComponent,
  404. LPDATAOBJECT pDataObject,
  405. MMC_COOKIE cookie,
  406. LPARAM arg,
  407. LPARAM lParam
  408. )
  409. {
  410. HRESULT hr = hrOK;
  411. SPITFSNode spNode;
  412. CORg (m_spNodeMgr->FindNode(cookie, &spNode));
  413. OnRefresh(spNode, pDataObject, 0, arg, lParam);
  414. Error:
  415. return hr;
  416. }
  417. /*!--------------------------------------------------------------------------
  418. CMTIpsmHandler::ExpandNode
  419. Expands/compresses this node
  420. Author: NSun
  421. ---------------------------------------------------------------------------*/
  422. void
  423. CMTIpsmHandler::ExpandNode
  424. (
  425. ITFSNode * pNode,
  426. BOOL fExpand
  427. )
  428. {
  429. SPIComponentData spCompData;
  430. SPIDataObject spDataObject;
  431. LPDATAOBJECT pDataObject;
  432. SPIConsole spConsole;
  433. HRESULT hr = hrOK;
  434. m_spNodeMgr->GetComponentData(&spCompData);
  435. CORg ( spCompData->QueryDataObject((MMC_COOKIE) pNode, CCT_SCOPE, &pDataObject) );
  436. spDataObject = pDataObject;
  437. CORg ( m_spNodeMgr->GetConsole(&spConsole) );
  438. CORg ( spConsole->UpdateAllViews(pDataObject, TRUE, RESULT_PANE_EXPAND) );
  439. Error:
  440. return;
  441. }
  442. /*---------------------------------------------------------------------------
  443. Class: CIpsmHandler
  444. ---------------------------------------------------------------------------*/
  445. /*!--------------------------------------------------------------------------
  446. CIpsmHandler::SaveColumns
  447. -
  448. Author: NSun
  449. ---------------------------------------------------------------------------*/
  450. HRESULT
  451. CIpsmHandler::SaveColumns
  452. (
  453. ITFSComponent * pComponent,
  454. MMC_COOKIE cookie,
  455. LPARAM arg,
  456. LPARAM lParam
  457. )
  458. {
  459. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  460. HRESULT hr = hrOK;
  461. LONG_PTR dwNodeType;
  462. int nCol = 0;
  463. int nColWidth = 0;
  464. SPITFSNode spNode, spRootNode;
  465. SPIHeaderCtrl spHeaderCtrl;
  466. BOOL bDirty = FALSE;
  467. CORg (m_spNodeMgr->FindNode(cookie, &spNode));
  468. CORg (pComponent->GetHeaderCtrl(&spHeaderCtrl));
  469. dwNodeType = spNode->GetData(TFS_DATA_TYPE);
  470. while (aColumns[dwNodeType][nCol] != 0)
  471. {
  472. if ( (SUCCEEDED(spHeaderCtrl->GetColumnWidth(nCol, &nColWidth))) &&
  473. (aColumnWidths[dwNodeType][nCol] != nColWidth) )
  474. {
  475. aColumnWidths[dwNodeType][nCol] = nColWidth;
  476. bDirty = TRUE;
  477. }
  478. nCol++;
  479. }
  480. if (bDirty)
  481. {
  482. CORg (m_spNodeMgr->GetRootNode(&spRootNode));
  483. spRootNode->SetData(TFS_DATA_DIRTY, TRUE);
  484. }
  485. Error:
  486. return hr;
  487. }
  488. /*!--------------------------------------------------------------------------
  489. CIpsmHandler::OnCreateDataObject
  490. -
  491. Author: NSun
  492. ---------------------------------------------------------------------------*/
  493. STDMETHODIMP
  494. CIpsmHandler::OnCreateDataObject
  495. (
  496. ITFSComponent * pComponent,
  497. MMC_COOKIE cookie,
  498. DATA_OBJECT_TYPES type,
  499. IDataObject ** ppDataObject
  500. )
  501. {
  502. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  503. Assert(ppDataObject != NULL);
  504. CDataObject * pObject = NULL;
  505. SPIDataObject spDataObject;
  506. pObject = new CDataObject;
  507. spDataObject = pObject; // do this so that it gets released correctly
  508. Assert(pObject != NULL);
  509. if (cookie == MMC_MULTI_SELECT_COOKIE)
  510. {
  511. CreateMultiSelectData(pComponent, pObject);
  512. }
  513. // Save cookie and type for delayed rendering
  514. pObject->SetType(type);
  515. pObject->SetCookie(cookie);
  516. // Store the coclass with the data object
  517. pObject->SetClsid(*(m_spTFSComponentData->GetCoClassID()));
  518. pObject->SetTFSComponentData(m_spTFSComponentData);
  519. return pObject->QueryInterface(IID_IDataObject,
  520. reinterpret_cast<void**>(ppDataObject));
  521. }
  522. HRESULT
  523. CIpsmHandler::CreateMultiSelectData(ITFSComponent * pComponent, CDataObject * pObject)
  524. {
  525. HRESULT hr = hrOK;
  526. // build the list of selected nodes
  527. CTFSNodeList listSelectedNodes;
  528. CGUIDArray rgGuids;
  529. UINT cb;
  530. GUID* pGuid;
  531. COM_PROTECT_TRY
  532. {
  533. CORg (BuildSelectedItemList(pComponent, &listSelectedNodes));
  534. // collect all of the unique guids
  535. while (listSelectedNodes.GetCount() > 0)
  536. {
  537. SPITFSNode spCurNode;
  538. const GUID * pConstGuid;
  539. spCurNode = listSelectedNodes.RemoveHead();
  540. pConstGuid = spCurNode->GetNodeType();
  541. rgGuids.AddUnique(*pConstGuid);
  542. }
  543. // now put the information in the data object
  544. pObject->SetMultiSelDobj();
  545. cb = (UINT)rgGuids.GetSize() * sizeof(GUID);
  546. pGuid = new GUID[(size_t)rgGuids.GetSize()];
  547. CopyMemory(pGuid, rgGuids.GetData(), cb);
  548. pObject->SetMultiSelData((BYTE*)pGuid, cb);
  549. COM_PROTECT_ERROR_LABEL;
  550. }
  551. COM_PROTECT_CATCH
  552. return hr;
  553. }
  554. /*---------------------------------------------------------------------------
  555. CIpsmHandler::OnResultDelete
  556. Description
  557. Author: NSun
  558. ---------------------------------------------------------------------------*/
  559. HRESULT
  560. CIpsmHandler::OnResultDelete
  561. (
  562. ITFSComponent * pComponent,
  563. LPDATAOBJECT pDataObject,
  564. MMC_COOKIE cookie,
  565. LPARAM arg,
  566. LPARAM lParam
  567. )
  568. {
  569. HRESULT hr = hrOK;
  570. Trace0("CIpsmHandler::OnResultDelete received\n");
  571. // translate this call to the parent and let it handle deletion
  572. // of result pane items
  573. SPITFSNode spNode, spParent;
  574. SPITFSResultHandler spParentRH;
  575. CORg (m_spNodeMgr->FindNode(cookie, &spNode));
  576. CORg (spNode->GetParent(&spParent));
  577. if (spParent == NULL)
  578. return hr;
  579. CORg (spParent->GetResultHandler(&spParentRH));
  580. CORg (spParentRH->Notify(pComponent, spParent->GetData(TFS_DATA_COOKIE), pDataObject, MMCN_DELETE, arg, lParam));
  581. Error:
  582. return hr;
  583. }
  584. /*!--------------------------------------------------------------------------
  585. CMTIpsmHandler::OnResultRefresh
  586. Call into the MTHandler to do a refresh
  587. Author: NSun
  588. ---------------------------------------------------------------------------*/
  589. HRESULT
  590. CIpsmHandler::OnResultRefresh
  591. (
  592. ITFSComponent * pComponent,
  593. LPDATAOBJECT pDataObject,
  594. MMC_COOKIE cookie,
  595. LPARAM arg,
  596. LPARAM lParam
  597. )
  598. {
  599. HRESULT hr = hrOK;
  600. SPITFSNode spNode;
  601. CORg (m_spNodeMgr->FindNode(cookie, &spNode));
  602. OnRefresh(spNode, pDataObject, 0, arg, lParam);
  603. Error:
  604. return hr;
  605. }
  606. /*!--------------------------------------------------------------------------
  607. CIpsmHandler::OnResultContextHelp
  608. Implementation of ITFSResultHandler::OnResultContextHelp
  609. Author: NSun
  610. ---------------------------------------------------------------------------*/
  611. HRESULT
  612. CIpsmHandler::OnResultContextHelp
  613. (
  614. ITFSComponent * pComponent,
  615. LPDATAOBJECT pDataObject,
  616. MMC_COOKIE cookie,
  617. LPARAM arg,
  618. LPARAM lParam
  619. )
  620. {
  621. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  622. HRESULT hr = hrOK;
  623. SPIDisplayHelp spDisplayHelp;
  624. SPIConsole spConsole;
  625. pComponent->GetConsole(&spConsole);
  626. hr = spConsole->QueryInterface (IID_IDisplayHelp, (LPVOID*) &spDisplayHelp);
  627. ASSERT (SUCCEEDED (hr));
  628. if ( SUCCEEDED (hr) )
  629. {
  630. LPCTSTR pszHelpFile = m_spTFSCompData->GetHTMLHelpFileName();
  631. if (pszHelpFile == NULL)
  632. goto Error;
  633. CString szHelpFilePath;
  634. UINT nLen = ::GetWindowsDirectory (szHelpFilePath.GetBufferSetLength(2 * MAX_PATH), 2 * MAX_PATH);
  635. if (nLen == 0)
  636. {
  637. hr = E_FAIL;
  638. goto Error;
  639. }
  640. szHelpFilePath.ReleaseBuffer();
  641. szHelpFilePath += g_szDefaultHelpTopic;
  642. hr = spDisplayHelp->ShowTopic (T2OLE ((LPTSTR)(LPCTSTR) szHelpFilePath));
  643. ASSERT (SUCCEEDED (hr));
  644. }
  645. Error:
  646. return hr;
  647. }
  648. /*!--------------------------------------------------------------------------
  649. CIpsmHandler::OnResultSelect
  650. Handles the MMCN_SELECT notifcation
  651. Author: NSun
  652. ---------------------------------------------------------------------------*/
  653. HRESULT
  654. CIpsmHandler::OnResultSelect
  655. (
  656. ITFSComponent * pComponent,
  657. LPDATAOBJECT pDataObject,
  658. MMC_COOKIE cookie,
  659. LPARAM arg,
  660. LPARAM lParam
  661. )
  662. {
  663. SPIConsoleVerb spConsoleVerb;
  664. SPITFSNode spNode;
  665. HRESULT hr = hrOK;
  666. BOOL bStates[ARRAYLEN(g_ConsoleVerbs)];
  667. int i;
  668. BOOL bScope = (BOOL) LOWORD(arg);
  669. BOOL bSelect = (BOOL) HIWORD(arg);
  670. Trace1("CIpsmHandler::OnResultSelect select = %d\n", bSelect);
  671. //m_bSelected = bSelect;
  672. CORg (pComponent->GetConsoleVerb(&spConsoleVerb));
  673. CORg (m_spNodeMgr->FindNode(cookie, &spNode));
  674. for (i = 0; i < ARRAYLEN(g_ConsoleVerbs); bStates[i++] = TRUE);
  675. EnableVerbs(spConsoleVerb, g_ConsoleVerbStates[spNode->GetData(TFS_DATA_TYPE)], bStates);
  676. Error:
  677. return hr;
  678. }
  679. /*!--------------------------------------------------------------------------
  680. CMTIpsmHandler::EnableVerbs
  681. Enables the verb buttons
  682. Author: NSun
  683. ---------------------------------------------------------------------------*/
  684. void
  685. CIpsmHandler::EnableVerbs
  686. (
  687. IConsoleVerb * pConsoleVerb,
  688. MMC_BUTTON_STATE ButtonState[],
  689. BOOL bState[]
  690. )
  691. {
  692. if (pConsoleVerb == NULL)
  693. {
  694. Assert(FALSE);
  695. return;
  696. }
  697. for (int i=0; i < ARRAYLEN(g_ConsoleVerbs); ++i)
  698. {
  699. if (ButtonState[i] == ENABLED)
  700. {
  701. // unhide this button before enabling
  702. pConsoleVerb->SetVerbState(g_ConsoleVerbs[i],
  703. HIDDEN,
  704. FALSE);
  705. pConsoleVerb->SetVerbState(g_ConsoleVerbs[i],
  706. ButtonState[i],
  707. bState[i]);
  708. }
  709. else
  710. {
  711. // hide this button
  712. pConsoleVerb->SetVerbState(g_ConsoleVerbs[i],
  713. HIDDEN,
  714. TRUE);
  715. }
  716. }
  717. pConsoleVerb->SetDefaultVerb(m_verbDefault);
  718. }