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
24 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  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. //Tthe help file
  15. const TCHAR g_szDefaultHelpTopic[] = _T("\\help\\infrared.chm::/sag_IrDAtopnode.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 * pGuid;
  144. spCurNode = listSelectedNodes.RemoveHead();
  145. pGuid = spCurNode->GetNodeType();
  146. rgGuids.AddUnique(*pGuid);
  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 CMTIpsmHandler::OnResultContextHelp(ITFSComponent * pComponent,
  277. LPDATAOBJECT pDataObject,
  278. MMC_COOKIE cookie,
  279. LPARAM arg,
  280. LPARAM lParam)
  281. {
  282. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  283. HRESULT hr = hrOK;
  284. SPIDisplayHelp spDisplayHelp;
  285. SPIConsole spConsole;
  286. UINT nLen = 0;
  287. LPCTSTR pszHelpFile = NULL;
  288. CString szHelpFilePath;
  289. pComponent->GetConsole(&spConsole);
  290. hr = spConsole->QueryInterface(IID_IDisplayHelp,
  291. (LPVOID*) &spDisplayHelp);
  292. ASSERT(SUCCEEDED(hr));
  293. if (SUCCEEDED(hr))
  294. {
  295. pszHelpFile = m_spTFSCompData->GetHTMLHelpFileName();
  296. if (NULL == pszHelpFile)
  297. goto Error;
  298. nLen = ::GetWindowsDirectory(szHelpFilePath.GetBufferSetLength(2 * MAX_PATH), 2 * MAX_PATH);
  299. if (0 == nLen)
  300. {
  301. hr = E_FAIL;
  302. goto Error;
  303. }
  304. szHelpFilePath.ReleaseBuffer();
  305. szHelpFilePath += g_szDefaultHelpTopic;
  306. hr = spDisplayHelp->ShowTopic(T2OLE((LPTSTR)(LPCTSTR) szHelpFilePath));
  307. ASSERT (SUCCEEDED(hr));
  308. }
  309. Error:
  310. return hr;
  311. }
  312. /*!--------------------------------------------------------------------------
  313. CMTIpsmHandler::UpdateStandardVerbs
  314. Updates the standard verbs depending upon the state of the node
  315. Author: NSun
  316. ---------------------------------------------------------------------------*/
  317. void
  318. CMTIpsmHandler::UpdateConsoleVerbs
  319. (
  320. IConsoleVerb * pConsoleVerb,
  321. LONG_PTR dwNodeType,
  322. BOOL bMultiSelect
  323. )
  324. {
  325. BOOL bStates[ARRAYLEN(g_ConsoleVerbs)];
  326. MMC_BUTTON_STATE * ButtonState;
  327. int i;
  328. if (bMultiSelect)
  329. {
  330. ButtonState = g_ConsoleVerbStatesMultiSel[dwNodeType];
  331. for (i = 0; i < ARRAYLEN(g_ConsoleVerbs); bStates[i++] = TRUE);
  332. }
  333. else
  334. {
  335. ButtonState = g_ConsoleVerbStates[dwNodeType];
  336. switch (m_nState)
  337. {
  338. case loaded:
  339. for (i = 0; i < ARRAYLEN(g_ConsoleVerbs); bStates[i++] = TRUE);
  340. break;
  341. case notLoaded:
  342. case loading:
  343. for (i = 0; i < ARRAYLEN(g_ConsoleVerbs); bStates[i++] = FALSE);
  344. break;
  345. case unableToLoad:
  346. for (i = 0; i < ARRAYLEN(g_ConsoleVerbs); bStates[i++] = FALSE);
  347. bStates[MMC_VERB_REFRESH & 0x000F] = TRUE;
  348. bStates[MMC_VERB_DELETE & 0x000F] = TRUE;
  349. break;
  350. }
  351. }
  352. EnableVerbs(pConsoleVerb, ButtonState, bStates);
  353. }
  354. /*!--------------------------------------------------------------------------
  355. CMTIpsmHandler::EnableVerbs
  356. Enables the verb buttons
  357. Author: NSun
  358. ---------------------------------------------------------------------------*/
  359. void
  360. CMTIpsmHandler::EnableVerbs
  361. (
  362. IConsoleVerb * pConsoleVerb,
  363. MMC_BUTTON_STATE ButtonState[],
  364. BOOL bState[]
  365. )
  366. {
  367. if (pConsoleVerb == NULL)
  368. {
  369. Assert(FALSE);
  370. return;
  371. }
  372. for (int i=0; i < ARRAYLEN(g_ConsoleVerbs); ++i)
  373. {
  374. if (ButtonState[i] == ENABLED)
  375. {
  376. // unhide this button before enabling
  377. pConsoleVerb->SetVerbState(g_ConsoleVerbs[i],
  378. HIDDEN,
  379. FALSE);
  380. pConsoleVerb->SetVerbState(g_ConsoleVerbs[i],
  381. ButtonState[i],
  382. bState[i]);
  383. }
  384. else
  385. {
  386. // hide this button
  387. pConsoleVerb->SetVerbState(g_ConsoleVerbs[i],
  388. HIDDEN,
  389. TRUE);
  390. }
  391. }
  392. pConsoleVerb->SetDefaultVerb(m_verbDefault);
  393. }
  394. /*!--------------------------------------------------------------------------
  395. CMTIpsmHandler::OnResultRefresh
  396. Call into the MTHandler to do a refresh
  397. Author: NSun
  398. ---------------------------------------------------------------------------*/
  399. HRESULT
  400. CMTIpsmHandler::OnResultRefresh
  401. (
  402. ITFSComponent * pComponent,
  403. LPDATAOBJECT pDataObject,
  404. MMC_COOKIE cookie,
  405. LPARAM arg,
  406. LPARAM lParam
  407. )
  408. {
  409. HRESULT hr = hrOK;
  410. SPITFSNode spNode;
  411. CORg (m_spNodeMgr->FindNode(cookie, &spNode));
  412. OnRefresh(spNode, pDataObject, 0, arg, lParam);
  413. Error:
  414. return hr;
  415. }
  416. /*!--------------------------------------------------------------------------
  417. CMTIpsmHandler::ExpandNode
  418. Expands/compresses this node
  419. Author: NSun
  420. ---------------------------------------------------------------------------*/
  421. void
  422. CMTIpsmHandler::ExpandNode
  423. (
  424. ITFSNode * pNode,
  425. BOOL fExpand
  426. )
  427. {
  428. SPIComponentData spCompData;
  429. SPIDataObject spDataObject;
  430. LPDATAOBJECT pDataObject;
  431. SPIConsole spConsole;
  432. HRESULT hr = hrOK;
  433. m_spNodeMgr->GetComponentData(&spCompData);
  434. CORg ( spCompData->QueryDataObject((MMC_COOKIE) pNode, CCT_SCOPE, &pDataObject) );
  435. spDataObject = pDataObject;
  436. CORg ( m_spNodeMgr->GetConsole(&spConsole) );
  437. CORg ( spConsole->UpdateAllViews(pDataObject, TRUE, RESULT_PANE_EXPAND) );
  438. Error:
  439. return;
  440. }
  441. /*---------------------------------------------------------------------------
  442. Class: CIpsmHandler
  443. ---------------------------------------------------------------------------*/
  444. /*!--------------------------------------------------------------------------
  445. CIpsmHandler::SaveColumns
  446. -
  447. Author: NSun
  448. ---------------------------------------------------------------------------*/
  449. HRESULT
  450. CIpsmHandler::SaveColumns
  451. (
  452. ITFSComponent * pComponent,
  453. MMC_COOKIE cookie,
  454. LPARAM arg,
  455. LPARAM lParam
  456. )
  457. {
  458. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  459. HRESULT hr = hrOK;
  460. LONG_PTR dwNodeType;
  461. int nCol = 0;
  462. int nColWidth = 0;
  463. SPITFSNode spNode, spRootNode;
  464. SPIHeaderCtrl spHeaderCtrl;
  465. BOOL bDirty = FALSE;
  466. CORg (m_spNodeMgr->FindNode(cookie, &spNode));
  467. CORg (pComponent->GetHeaderCtrl(&spHeaderCtrl));
  468. dwNodeType = spNode->GetData(TFS_DATA_TYPE);
  469. while (aColumns[dwNodeType][nCol] != 0)
  470. {
  471. if ( (SUCCEEDED(spHeaderCtrl->GetColumnWidth(nCol, &nColWidth))) &&
  472. (aColumnWidths[dwNodeType][nCol] != nColWidth) )
  473. {
  474. aColumnWidths[dwNodeType][nCol] = nColWidth;
  475. bDirty = TRUE;
  476. }
  477. nCol++;
  478. }
  479. if (bDirty)
  480. {
  481. CORg (m_spNodeMgr->GetRootNode(&spRootNode));
  482. spRootNode->SetData(TFS_DATA_DIRTY, TRUE);
  483. }
  484. Error:
  485. return hr;
  486. }
  487. /*!--------------------------------------------------------------------------
  488. CIpsmHandler::OnCreateDataObject
  489. -
  490. Author: NSun
  491. ---------------------------------------------------------------------------*/
  492. STDMETHODIMP
  493. CIpsmHandler::OnCreateDataObject
  494. (
  495. ITFSComponent * pComponent,
  496. MMC_COOKIE cookie,
  497. DATA_OBJECT_TYPES type,
  498. IDataObject ** ppDataObject
  499. )
  500. {
  501. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  502. Assert(ppDataObject != NULL);
  503. CDataObject * pObject = NULL;
  504. SPIDataObject spDataObject;
  505. pObject = new CDataObject;
  506. spDataObject = pObject; // do this so that it gets released correctly
  507. Assert(pObject != NULL);
  508. if (cookie == MMC_MULTI_SELECT_COOKIE)
  509. {
  510. CreateMultiSelectData(pComponent, pObject);
  511. }
  512. // Save cookie and type for delayed rendering
  513. pObject->SetType(type);
  514. pObject->SetCookie(cookie);
  515. // Store the coclass with the data object
  516. pObject->SetClsid(*(m_spTFSComponentData->GetCoClassID()));
  517. pObject->SetTFSComponentData(m_spTFSComponentData);
  518. return pObject->QueryInterface(IID_IDataObject,
  519. reinterpret_cast<void**>(ppDataObject));
  520. }
  521. HRESULT
  522. CIpsmHandler::CreateMultiSelectData(ITFSComponent * pComponent, CDataObject * pObject)
  523. {
  524. HRESULT hr = hrOK;
  525. // build the list of selected nodes
  526. CTFSNodeList listSelectedNodes;
  527. CGUIDArray rgGuids;
  528. UINT cb;
  529. GUID* pGuid;
  530. COM_PROTECT_TRY
  531. {
  532. CORg (BuildSelectedItemList(pComponent, &listSelectedNodes));
  533. // collect all of the unique guids
  534. while (listSelectedNodes.GetCount() > 0)
  535. {
  536. SPITFSNode spCurNode;
  537. const GUID * pGuid;
  538. spCurNode = listSelectedNodes.RemoveHead();
  539. pGuid = spCurNode->GetNodeType();
  540. rgGuids.AddUnique(*pGuid);
  541. }
  542. // now put the information in the data object
  543. pObject->SetMultiSelDobj();
  544. cb = (UINT)rgGuids.GetSize() * sizeof(GUID);
  545. pGuid = new GUID[(size_t)rgGuids.GetSize()];
  546. CopyMemory(pGuid, rgGuids.GetData(), cb);
  547. pObject->SetMultiSelData((BYTE*)pGuid, cb);
  548. COM_PROTECT_ERROR_LABEL;
  549. }
  550. COM_PROTECT_CATCH
  551. return hr;
  552. }
  553. /*---------------------------------------------------------------------------
  554. CIpsmHandler::OnResultDelete
  555. Description
  556. Author: NSun
  557. ---------------------------------------------------------------------------*/
  558. HRESULT
  559. CIpsmHandler::OnResultDelete
  560. (
  561. ITFSComponent * pComponent,
  562. LPDATAOBJECT pDataObject,
  563. MMC_COOKIE cookie,
  564. LPARAM arg,
  565. LPARAM lParam
  566. )
  567. {
  568. HRESULT hr = hrOK;
  569. Trace0("CIpsmHandler::OnResultDelete received\n");
  570. // translate this call to the parent and let it handle deletion
  571. // of result pane items
  572. SPITFSNode spNode, spParent;
  573. SPITFSResultHandler spParentRH;
  574. CORg (m_spNodeMgr->FindNode(cookie, &spNode));
  575. CORg (spNode->GetParent(&spParent));
  576. if (spParent == NULL)
  577. return hr;
  578. CORg (spParent->GetResultHandler(&spParentRH));
  579. CORg (spParentRH->Notify(pComponent, spParent->GetData(TFS_DATA_COOKIE), pDataObject, MMCN_DELETE, arg, lParam));
  580. Error:
  581. return hr;
  582. }
  583. /*!--------------------------------------------------------------------------
  584. CMTIpsmHandler::OnResultRefresh
  585. Call into the MTHandler to do a refresh
  586. Author: NSun
  587. ---------------------------------------------------------------------------*/
  588. HRESULT
  589. CIpsmHandler::OnResultRefresh
  590. (
  591. ITFSComponent * pComponent,
  592. LPDATAOBJECT pDataObject,
  593. MMC_COOKIE cookie,
  594. LPARAM arg,
  595. LPARAM lParam
  596. )
  597. {
  598. HRESULT hr = hrOK;
  599. SPITFSNode spNode;
  600. CORg (m_spNodeMgr->FindNode(cookie, &spNode));
  601. OnRefresh(spNode, pDataObject, 0, arg, lParam);
  602. Error:
  603. return hr;
  604. }
  605. /*!--------------------------------------------------------------------------
  606. CIpsmHandler::OnResultContextHelp
  607. Implementation of ITFSResultHandler::OnResultContextHelp
  608. Author: NSun
  609. ---------------------------------------------------------------------------*/
  610. HRESULT
  611. CIpsmHandler::OnResultContextHelp
  612. (
  613. ITFSComponent * pComponent,
  614. LPDATAOBJECT pDataObject,
  615. MMC_COOKIE cookie,
  616. LPARAM arg,
  617. LPARAM lParam
  618. )
  619. {
  620. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  621. HRESULT hr = hrOK;
  622. SPIDisplayHelp spDisplayHelp;
  623. SPIConsole spConsole;
  624. pComponent->GetConsole(&spConsole);
  625. hr = spConsole->QueryInterface (IID_IDisplayHelp, (LPVOID*) &spDisplayHelp);
  626. ASSERT (SUCCEEDED (hr));
  627. if ( SUCCEEDED (hr) )
  628. {
  629. LPCTSTR pszHelpFile = m_spTFSCompData->GetHTMLHelpFileName();
  630. if (pszHelpFile == NULL)
  631. goto Error;
  632. CString szHelpFilePath;
  633. UINT nLen = ::GetWindowsDirectory (szHelpFilePath.GetBufferSetLength(2 * MAX_PATH), 2 * MAX_PATH);
  634. if (nLen == 0)
  635. {
  636. hr = E_FAIL;
  637. goto Error;
  638. }
  639. szHelpFilePath.ReleaseBuffer();
  640. szHelpFilePath += g_szDefaultHelpTopic;
  641. hr = spDisplayHelp->ShowTopic (T2OLE ((LPTSTR)(LPCTSTR) szHelpFilePath));
  642. ASSERT (SUCCEEDED (hr));
  643. }
  644. Error:
  645. return hr;
  646. }
  647. /*!--------------------------------------------------------------------------
  648. CIpsmHandler::OnResultSelect
  649. Handles the MMCN_SELECT notifcation
  650. Author: NSun
  651. ---------------------------------------------------------------------------*/
  652. HRESULT
  653. CIpsmHandler::OnResultSelect
  654. (
  655. ITFSComponent * pComponent,
  656. LPDATAOBJECT pDataObject,
  657. MMC_COOKIE cookie,
  658. LPARAM arg,
  659. LPARAM lParam
  660. )
  661. {
  662. SPIConsoleVerb spConsoleVerb;
  663. SPITFSNode spNode;
  664. HRESULT hr = hrOK;
  665. BOOL bStates[ARRAYLEN(g_ConsoleVerbs)];
  666. int i;
  667. BOOL bScope = (BOOL) LOWORD(arg);
  668. BOOL bSelect = (BOOL) HIWORD(arg);
  669. Trace1("CIpsmHandler::OnResultSelect select = %d\n", bSelect);
  670. //m_bSelected = bSelect;
  671. CORg (pComponent->GetConsoleVerb(&spConsoleVerb));
  672. CORg (m_spNodeMgr->FindNode(cookie, &spNode));
  673. for (i = 0; i < ARRAYLEN(g_ConsoleVerbs); bStates[i++] = TRUE);
  674. EnableVerbs(spConsoleVerb, g_ConsoleVerbStates[spNode->GetData(TFS_DATA_TYPE)], bStates);
  675. Error:
  676. return hr;
  677. }
  678. /*!--------------------------------------------------------------------------
  679. CMTIpsmHandler::EnableVerbs
  680. Enables the verb buttons
  681. Author: NSun
  682. ---------------------------------------------------------------------------*/
  683. void
  684. CIpsmHandler::EnableVerbs
  685. (
  686. IConsoleVerb * pConsoleVerb,
  687. MMC_BUTTON_STATE ButtonState[],
  688. BOOL bState[]
  689. )
  690. {
  691. if (pConsoleVerb == NULL)
  692. {
  693. Assert(FALSE);
  694. return;
  695. }
  696. for (int i=0; i < ARRAYLEN(g_ConsoleVerbs); ++i)
  697. {
  698. if (ButtonState[i] == ENABLED)
  699. {
  700. // unhide this button before enabling
  701. pConsoleVerb->SetVerbState(g_ConsoleVerbs[i],
  702. HIDDEN,
  703. FALSE);
  704. pConsoleVerb->SetVerbState(g_ConsoleVerbs[i],
  705. ButtonState[i],
  706. bState[i]);
  707. }
  708. else
  709. {
  710. // hide this button
  711. pConsoleVerb->SetVerbState(g_ConsoleVerbs[i],
  712. HIDDEN,
  713. TRUE);
  714. }
  715. }
  716. pConsoleVerb->SetDefaultVerb(m_verbDefault);
  717. }