Source code of Windows XP (NT5)
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.

387 lines
11 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. basertr.cpp
  7. Base Router handler implementation.
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "util.h"
  12. #include "basertr.h"
  13. #include "basecon.h"
  14. #include "tfschar.h"
  15. #include "strmap.h" // XXXtoCString functions
  16. #include "service.h" // TFS service APIs
  17. #include "rtrstr.h" // const strings used
  18. #include "rtrsheet.h" // RtrPropertySheet
  19. #include "rtrutil.h"
  20. /*---------------------------------------------------------------------------
  21. BaseRouterHandler implementation
  22. ---------------------------------------------------------------------------*/
  23. BaseRouterHandler::BaseRouterHandler(ITFSComponentData *pCompData)
  24. : CHandler(pCompData),
  25. m_nHelpTopicId(IDS_DEFAULT_HELP_TOPIC)
  26. {
  27. // Initialize all of the buttons to be hidden by default
  28. for (int i=0; i<MMC_VERB_COUNT; i++)
  29. {
  30. m_rgButtonState[i] = HIDDEN;
  31. m_bState[i] = FALSE;
  32. }
  33. // Make sure that these constants don't change on us
  34. Assert((0x8000+MMC_VERB_OPEN_INDEX) == MMC_VERB_OPEN);
  35. Assert((0x8000+MMC_VERB_COPY_INDEX) == MMC_VERB_COPY);
  36. Assert((0x8000+MMC_VERB_PASTE_INDEX) == MMC_VERB_PASTE);
  37. Assert((0x8000+MMC_VERB_DELETE_INDEX) == MMC_VERB_DELETE);
  38. Assert((0x8000+MMC_VERB_PROPERTIES_INDEX) == MMC_VERB_PROPERTIES);
  39. Assert((0x8000+MMC_VERB_RENAME_INDEX) == MMC_VERB_RENAME);
  40. Assert((0x8000+MMC_VERB_REFRESH_INDEX) == MMC_VERB_REFRESH);
  41. Assert((0x8000+MMC_VERB_PRINT_INDEX) == MMC_VERB_PRINT);
  42. m_verbDefault = MMC_VERB_OPEN;
  43. }
  44. /*---------------------------------------------------------------------------
  45. BaseRouterHandler::OnCreateNodeId2
  46. Returns a unique string for this node
  47. Author: WeiJiang
  48. ---------------------------------------------------------------------------*/
  49. HRESULT BaseRouterHandler::OnCreateNodeId2(ITFSNode * pNode, CString & strId,
  50. DWORD * dwFlags)
  51. {
  52. const GUID * pGuid = pNode->GetNodeType();
  53. CString strProviderId, strGuid;
  54. StringFromGUID2(*pGuid, strGuid.GetBuffer(256), 256);
  55. strGuid.ReleaseBuffer();
  56. // RouterInfo should be available now
  57. Assert(m_spRouterInfo);
  58. DWORD RouterInfoFlags = m_spRouterInfo->GetFlags();
  59. // if the machine is added not as local, then we use the machine name
  60. if (0 == (RouterInfoFlags & RouterInfo_AddedAsLocal)) // not added as local
  61. strId = m_spRouterInfo->GetMachineName() + strGuid;
  62. else
  63. strId = strGuid;
  64. return hrOK;
  65. }
  66. /*!--------------------------------------------------------------------------
  67. BaseRouterHandler::OnResultSelect
  68. -
  69. Author: KennT
  70. ---------------------------------------------------------------------------*/
  71. HRESULT BaseRouterHandler::OnResultSelect(ITFSComponent *pComponent,
  72. LPDATAOBJECT pDataObject,
  73. MMC_COOKIE cookie,
  74. LPARAM arg,
  75. LPARAM lParam)
  76. {
  77. SPIConsoleVerb spConsoleVerb;
  78. SPITFSNode spNode;
  79. HRESULT hr = hrOK;
  80. CORg( pComponent->GetConsoleVerb(&spConsoleVerb) );
  81. CORg( m_spNodeMgr->FindNode(cookie, &spNode) );
  82. // If you need to update the verb state, do it here
  83. EnableVerbs(spConsoleVerb);
  84. Error:
  85. return hr;
  86. }
  87. /*!--------------------------------------------------------------------------
  88. BaseRouterHandler::EnableVerbs
  89. -
  90. Author: KennT
  91. ---------------------------------------------------------------------------*/
  92. void BaseRouterHandler::EnableVerbs(IConsoleVerb *pConsoleVerb)
  93. {
  94. Assert(pConsoleVerb);
  95. Assert(DimensionOf(m_rgButtonState) == DimensionOf(m_bState));
  96. Assert(DimensionOf(m_rgButtonState) == MMC_VERB_COUNT);
  97. for (int i=0; i<DimensionOf(m_rgButtonState); i++)
  98. {
  99. if (m_rgButtonState[i] & HIDDEN)
  100. {
  101. pConsoleVerb->SetVerbState(INDEX_TO_VERB(i), HIDDEN, TRUE);
  102. }
  103. else
  104. {
  105. // unhide this button before enabling
  106. pConsoleVerb->SetVerbState(INDEX_TO_VERB(i), HIDDEN, FALSE);
  107. pConsoleVerb->SetVerbState(INDEX_TO_VERB(i), ENABLED, m_bState[i]);
  108. }
  109. }
  110. pConsoleVerb->SetDefaultVerb(m_verbDefault);
  111. }
  112. /*!--------------------------------------------------------------------------
  113. BaseRouterHandler::OnResultPropertyChange
  114. -
  115. Author: KennT
  116. ---------------------------------------------------------------------------*/
  117. HRESULT BaseRouterHandler::OnResultPropertyChange
  118. (
  119. ITFSComponent * pComponent,
  120. LPDATAOBJECT pDataObject,
  121. MMC_COOKIE cookie,
  122. LPARAM arg,
  123. LPARAM param
  124. )
  125. {
  126. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  127. SPITFSNode spNode;
  128. m_spNodeMgr->FindNode(cookie, &spNode);
  129. RtrPropertySheet * pPropSheet = reinterpret_cast<RtrPropertySheet *>(param);
  130. LONG_PTR changeMask = 0;
  131. // tell the property page to do whatever now that we are back on the
  132. // main thread
  133. pPropSheet->OnPropertyChange(TRUE, &changeMask);
  134. pPropSheet->AcknowledgeNotify();
  135. if (changeMask)
  136. spNode->ChangeNode(changeMask);
  137. return hrOK;
  138. }
  139. /*!--------------------------------------------------------------------------
  140. BaseRouterHandler::OnPropertyChange
  141. -
  142. Author: KennT
  143. ---------------------------------------------------------------------------*/
  144. HRESULT BaseRouterHandler::OnPropertyChange
  145. (
  146. ITFSNode *pNode,
  147. LPDATAOBJECT pDataObject,
  148. DWORD dwType,
  149. LPARAM arg,
  150. LPARAM param
  151. )
  152. {
  153. // This is running on the MAIN THREAD!
  154. // ----------------------------------------------------------------
  155. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  156. RtrPropertySheet * pPropSheet = reinterpret_cast<RtrPropertySheet *>(param);
  157. LONG_PTR changeMask = 0;
  158. // tell the property page to do whatever now that we are back on the
  159. // main thread
  160. pPropSheet->OnPropertyChange(TRUE, &changeMask);
  161. pPropSheet->AcknowledgeNotify();
  162. if (changeMask)
  163. pNode->ChangeNode(changeMask);
  164. return hrOK;
  165. }
  166. /*!--------------------------------------------------------------------------
  167. BaseRouterHandler::OnVerbRefresh
  168. -
  169. Author: KennT
  170. ---------------------------------------------------------------------------*/
  171. HRESULT BaseRouterHandler::OnVerbRefresh(ITFSNode *pNode, LPARAM arg, LPARAM lParam)
  172. {
  173. return ForceGlobalRefresh(m_spRouterInfo);
  174. }
  175. /*!--------------------------------------------------------------------------
  176. BaseRouterHandler::OnResultRefresh
  177. -
  178. Author: KennT
  179. ---------------------------------------------------------------------------*/
  180. HRESULT BaseRouterHandler::OnResultRefresh(ITFSComponent *pTFSComponent, LPDATAOBJECT lpDataObject, MMC_COOKIE cookie, LPARAM arg, LPARAM lParam)
  181. {
  182. return ForceGlobalRefresh(m_spRouterInfo);
  183. }
  184. HRESULT BaseRouterHandler::ForwardCommandToParent(ITFSNode *pNode,
  185. long nCommandId,
  186. DATA_OBJECT_TYPES type,
  187. LPDATAOBJECT pDataObject,
  188. DWORD dwType)
  189. {
  190. SPITFSNode spParent;
  191. SPITFSNodeHandler spHandler;
  192. HRESULT hr = hrOK;
  193. CORg( pNode->GetParent(&spParent) );
  194. if (!spParent)
  195. CORg( E_INVALIDARG );
  196. CORg( spParent->GetHandler(&spHandler) );
  197. if (!spHandler)
  198. CORg( E_INVALIDARG );
  199. hr = spHandler->OnCommand(spParent, nCommandId, type, pDataObject, dwType);
  200. Error:
  201. return hr;
  202. }
  203. /*!--------------------------------------------------------------------------
  204. BaseRouterHandler::EnumDynamicExtensions
  205. Author: KennT
  206. ---------------------------------------------------------------------------*/
  207. HRESULT BaseRouterHandler::EnumDynamicExtensions(ITFSNode * pNode)
  208. {
  209. HRESULT hr = hrOK;
  210. CORg (m_dynExtensions.SetNode(pNode->GetNodeType()));
  211. CORg (m_dynExtensions.Reset());
  212. CORg (m_dynExtensions.Load());
  213. Error:
  214. return hr;
  215. }
  216. /*!--------------------------------------------------------------------------
  217. BaseRouterHandler::EnumDynamicExtensions
  218. Author: KennT
  219. ---------------------------------------------------------------------------*/
  220. HRESULT BaseRouterHandler::AddDynamicNamespaceExtensions(ITFSNode * pNode)
  221. {
  222. HRESULT hr = hrOK;
  223. CGUIDArray aNamespace;
  224. SPIConsoleNameSpace spNS;
  225. int i;
  226. COM_PROTECT_TRY
  227. {
  228. // enumerate dynamic namespace extensions
  229. CORg (m_spNodeMgr->GetConsoleNameSpace(&spNS));
  230. m_dynExtensions.GetNamespaceExtensions(aNamespace);
  231. for (i = 0; i < aNamespace.GetSize(); i++)
  232. {
  233. HRESULT hrAdd = spNS->AddExtension(pNode->GetData(TFS_DATA_SCOPEID), &aNamespace[i]);
  234. if (FAILED(hrAdd))
  235. Trace1("BaseRouterHandler::AddDynamicNamespaceExtensions - AddExtension failed %x", hrAdd);
  236. }
  237. COM_PROTECT_ERROR_LABEL;
  238. }
  239. COM_PROTECT_CATCH
  240. return hr;
  241. }
  242. /*!--------------------------------------------------------------------------
  243. BaseRouterHandler::OnResultContextHelp
  244. -
  245. Author: MikeG (a-migall)
  246. ---------------------------------------------------------------------------*/
  247. HRESULT BaseRouterHandler::OnResultContextHelp(ITFSComponent * pComponent,
  248. LPDATAOBJECT pDataObject,
  249. MMC_COOKIE cookie,
  250. LPARAM arg,
  251. LPARAM lParam)
  252. {
  253. // Not used...
  254. UNREFERENCED_PARAMETER(pDataObject);
  255. UNREFERENCED_PARAMETER(cookie);
  256. UNREFERENCED_PARAMETER(arg);
  257. UNREFERENCED_PARAMETER(lParam);
  258. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  259. return HrDisplayHelp(pComponent, m_spTFSCompData->GetHTMLHelpFileName(), m_nHelpTopicId);
  260. }
  261. /*!--------------------------------------------------------------------------
  262. BaseRouterHandler::AddArrayOfMenuItems
  263. -
  264. Author: KennT
  265. ---------------------------------------------------------------------------*/
  266. HRESULT BaseRouterHandler::AddArrayOfMenuItems(ITFSNode *pNode,
  267. const SRouterNodeMenu *prgMenu,
  268. UINT crgMenu,
  269. LPCONTEXTMENUCALLBACK pCallback,
  270. long iInsertionAllowed,
  271. INT_PTR pUserData)
  272. {
  273. HRESULT hr = hrOK;
  274. ULONG ulFlags;
  275. UINT i;
  276. CString stMenu;
  277. // Now go through and add our menu items
  278. for (i=0; i<crgMenu; i++)
  279. {
  280. // If this type of insertion is not allowed, skip it
  281. if ( (iInsertionAllowed & (1L << (prgMenu[i].m_ulPosition & CCM_INSERTIONPOINTID_MASK_FLAGINDEX))) == 0 )
  282. continue;
  283. if (prgMenu[i].m_sidMenu == IDS_MENU_SEPARATOR)
  284. {
  285. ulFlags = MF_SEPARATOR;
  286. stMenu.Empty();
  287. }
  288. else
  289. {
  290. if (prgMenu[i].m_pfnGetMenuFlags)
  291. {
  292. ulFlags = (*prgMenu[i].m_pfnGetMenuFlags)(prgMenu+i,
  293. pUserData);
  294. }
  295. else
  296. ulFlags = 0;
  297. // Special case - if the menu flags returns 0xFFFFFFFF
  298. // then we interpret this to mean don't add the menu item
  299. if (ulFlags == 0xFFFFFFFF)
  300. continue;
  301. stMenu.Empty();
  302. if (prgMenu[i].m_sidMenu)
  303. stMenu.LoadString(prgMenu[i].m_sidMenu);
  304. }
  305. LoadAndAddMenuItem(pCallback,
  306. stMenu,
  307. prgMenu[i].m_sidMenu,
  308. prgMenu[i].m_ulPosition,
  309. ulFlags,
  310. prgMenu[i].m_pszLangIndStr);
  311. }
  312. return hr;
  313. }