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.

886 lines
24 KiB

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