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.

392 lines
12 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. if(m_spRouterInfo) {
  59. DWORD RouterInfoFlags = m_spRouterInfo->GetFlags();
  60. // if the machine is added not as local, then we use the machine name
  61. if (0 == (RouterInfoFlags & RouterInfo_AddedAsLocal)) // not added as local
  62. strId = m_spRouterInfo->GetMachineName() + strGuid;
  63. else
  64. strId = strGuid;
  65. }
  66. else {
  67. strId = strGuid;
  68. }
  69. return hrOK;
  70. }
  71. /*!--------------------------------------------------------------------------
  72. BaseRouterHandler::OnResultSelect
  73. -
  74. Author: KennT
  75. ---------------------------------------------------------------------------*/
  76. HRESULT BaseRouterHandler::OnResultSelect(ITFSComponent *pComponent,
  77. LPDATAOBJECT pDataObject,
  78. MMC_COOKIE cookie,
  79. LPARAM arg,
  80. LPARAM lParam)
  81. {
  82. SPIConsoleVerb spConsoleVerb;
  83. SPITFSNode spNode;
  84. HRESULT hr = hrOK;
  85. CORg( pComponent->GetConsoleVerb(&spConsoleVerb) );
  86. CORg( m_spNodeMgr->FindNode(cookie, &spNode) );
  87. // If you need to update the verb state, do it here
  88. EnableVerbs(spConsoleVerb);
  89. Error:
  90. return hr;
  91. }
  92. /*!--------------------------------------------------------------------------
  93. BaseRouterHandler::EnableVerbs
  94. -
  95. Author: KennT
  96. ---------------------------------------------------------------------------*/
  97. void BaseRouterHandler::EnableVerbs(IConsoleVerb *pConsoleVerb)
  98. {
  99. Assert(pConsoleVerb);
  100. Assert(DimensionOf(m_rgButtonState) == DimensionOf(m_bState));
  101. Assert(DimensionOf(m_rgButtonState) == MMC_VERB_COUNT);
  102. for (int i=0; i<DimensionOf(m_rgButtonState); i++)
  103. {
  104. if (m_rgButtonState[i] & HIDDEN)
  105. {
  106. pConsoleVerb->SetVerbState(INDEX_TO_VERB(i), HIDDEN, TRUE);
  107. }
  108. else
  109. {
  110. // unhide this button before enabling
  111. pConsoleVerb->SetVerbState(INDEX_TO_VERB(i), HIDDEN, FALSE);
  112. pConsoleVerb->SetVerbState(INDEX_TO_VERB(i), ENABLED, m_bState[i]);
  113. }
  114. }
  115. pConsoleVerb->SetDefaultVerb(m_verbDefault);
  116. }
  117. /*!--------------------------------------------------------------------------
  118. BaseRouterHandler::OnResultPropertyChange
  119. -
  120. Author: KennT
  121. ---------------------------------------------------------------------------*/
  122. HRESULT BaseRouterHandler::OnResultPropertyChange
  123. (
  124. ITFSComponent * pComponent,
  125. LPDATAOBJECT pDataObject,
  126. MMC_COOKIE cookie,
  127. LPARAM arg,
  128. LPARAM param
  129. )
  130. {
  131. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  132. SPITFSNode spNode;
  133. m_spNodeMgr->FindNode(cookie, &spNode);
  134. RtrPropertySheet * pPropSheet = reinterpret_cast<RtrPropertySheet *>(param);
  135. LONG_PTR changeMask = 0;
  136. // tell the property page to do whatever now that we are back on the
  137. // main thread
  138. pPropSheet->OnPropertyChange(TRUE, &changeMask);
  139. pPropSheet->AcknowledgeNotify();
  140. if (changeMask)
  141. spNode->ChangeNode(changeMask);
  142. return hrOK;
  143. }
  144. /*!--------------------------------------------------------------------------
  145. BaseRouterHandler::OnPropertyChange
  146. -
  147. Author: KennT
  148. ---------------------------------------------------------------------------*/
  149. HRESULT BaseRouterHandler::OnPropertyChange
  150. (
  151. ITFSNode *pNode,
  152. LPDATAOBJECT pDataObject,
  153. DWORD dwType,
  154. LPARAM arg,
  155. LPARAM param
  156. )
  157. {
  158. // This is running on the MAIN THREAD!
  159. // ----------------------------------------------------------------
  160. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  161. RtrPropertySheet * pPropSheet = reinterpret_cast<RtrPropertySheet *>(param);
  162. LONG_PTR changeMask = 0;
  163. // tell the property page to do whatever now that we are back on the
  164. // main thread
  165. pPropSheet->OnPropertyChange(TRUE, &changeMask);
  166. pPropSheet->AcknowledgeNotify();
  167. if (changeMask)
  168. pNode->ChangeNode(changeMask);
  169. return hrOK;
  170. }
  171. /*!--------------------------------------------------------------------------
  172. BaseRouterHandler::OnVerbRefresh
  173. -
  174. Author: KennT
  175. ---------------------------------------------------------------------------*/
  176. HRESULT BaseRouterHandler::OnVerbRefresh(ITFSNode *pNode, LPARAM arg, LPARAM lParam)
  177. {
  178. return ForceGlobalRefresh(m_spRouterInfo);
  179. }
  180. /*!--------------------------------------------------------------------------
  181. BaseRouterHandler::OnResultRefresh
  182. -
  183. Author: KennT
  184. ---------------------------------------------------------------------------*/
  185. HRESULT BaseRouterHandler::OnResultRefresh(ITFSComponent *pTFSComponent, LPDATAOBJECT lpDataObject, MMC_COOKIE cookie, LPARAM arg, LPARAM lParam)
  186. {
  187. return ForceGlobalRefresh(m_spRouterInfo);
  188. }
  189. HRESULT BaseRouterHandler::ForwardCommandToParent(ITFSNode *pNode,
  190. long nCommandId,
  191. DATA_OBJECT_TYPES type,
  192. LPDATAOBJECT pDataObject,
  193. DWORD dwType)
  194. {
  195. SPITFSNode spParent;
  196. SPITFSNodeHandler spHandler;
  197. HRESULT hr = hrOK;
  198. CORg( pNode->GetParent(&spParent) );
  199. if (!spParent)
  200. CORg( E_INVALIDARG );
  201. CORg( spParent->GetHandler(&spHandler) );
  202. if (!spHandler)
  203. CORg( E_INVALIDARG );
  204. hr = spHandler->OnCommand(spParent, nCommandId, type, pDataObject, dwType);
  205. Error:
  206. return hr;
  207. }
  208. /*!--------------------------------------------------------------------------
  209. BaseRouterHandler::EnumDynamicExtensions
  210. Author: KennT
  211. ---------------------------------------------------------------------------*/
  212. HRESULT BaseRouterHandler::EnumDynamicExtensions(ITFSNode * pNode)
  213. {
  214. HRESULT hr = hrOK;
  215. CORg (m_dynExtensions.SetNode(pNode->GetNodeType()));
  216. CORg (m_dynExtensions.Reset());
  217. CORg (m_dynExtensions.Load());
  218. Error:
  219. return hr;
  220. }
  221. /*!--------------------------------------------------------------------------
  222. BaseRouterHandler::EnumDynamicExtensions
  223. Author: KennT
  224. ---------------------------------------------------------------------------*/
  225. HRESULT BaseRouterHandler::AddDynamicNamespaceExtensions(ITFSNode * pNode)
  226. {
  227. HRESULT hr = hrOK;
  228. CGUIDArray aNamespace;
  229. SPIConsoleNameSpace spNS;
  230. int i;
  231. COM_PROTECT_TRY
  232. {
  233. // enumerate dynamic namespace extensions
  234. CORg (m_spNodeMgr->GetConsoleNameSpace(&spNS));
  235. m_dynExtensions.GetNamespaceExtensions(aNamespace);
  236. for (i = 0; i < aNamespace.GetSize(); i++)
  237. {
  238. HRESULT hrAdd = spNS->AddExtension(pNode->GetData(TFS_DATA_SCOPEID), &aNamespace[i]);
  239. if (FAILED(hrAdd))
  240. Trace1("BaseRouterHandler::AddDynamicNamespaceExtensions - AddExtension failed %x", hrAdd);
  241. }
  242. COM_PROTECT_ERROR_LABEL;
  243. }
  244. COM_PROTECT_CATCH
  245. return hr;
  246. }
  247. /*!--------------------------------------------------------------------------
  248. BaseRouterHandler::OnResultContextHelp
  249. -
  250. Author: MikeG (a-migall)
  251. ---------------------------------------------------------------------------*/
  252. HRESULT BaseRouterHandler::OnResultContextHelp(ITFSComponent * pComponent,
  253. LPDATAOBJECT pDataObject,
  254. MMC_COOKIE cookie,
  255. LPARAM arg,
  256. LPARAM lParam)
  257. {
  258. // Not used...
  259. UNREFERENCED_PARAMETER(pDataObject);
  260. UNREFERENCED_PARAMETER(cookie);
  261. UNREFERENCED_PARAMETER(arg);
  262. UNREFERENCED_PARAMETER(lParam);
  263. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  264. return HrDisplayHelp(pComponent, m_spTFSCompData->GetHTMLHelpFileName(), m_nHelpTopicId);
  265. }
  266. /*!--------------------------------------------------------------------------
  267. BaseRouterHandler::AddArrayOfMenuItems
  268. -
  269. Author: KennT
  270. ---------------------------------------------------------------------------*/
  271. HRESULT BaseRouterHandler::AddArrayOfMenuItems(ITFSNode *pNode,
  272. const SRouterNodeMenu *prgMenu,
  273. UINT crgMenu,
  274. LPCONTEXTMENUCALLBACK pCallback,
  275. long iInsertionAllowed,
  276. INT_PTR pUserData)
  277. {
  278. HRESULT hr = hrOK;
  279. ULONG ulFlags;
  280. UINT i;
  281. CString stMenu;
  282. // Now go through and add our menu items
  283. for (i=0; i<crgMenu; i++)
  284. {
  285. // If this type of insertion is not allowed, skip it
  286. if ( (iInsertionAllowed & (1L << (prgMenu[i].m_ulPosition & CCM_INSERTIONPOINTID_MASK_FLAGINDEX))) == 0 )
  287. continue;
  288. if (prgMenu[i].m_sidMenu == IDS_MENU_SEPARATOR)
  289. {
  290. ulFlags = MF_SEPARATOR;
  291. stMenu.Empty();
  292. }
  293. else
  294. {
  295. if (prgMenu[i].m_pfnGetMenuFlags)
  296. {
  297. ulFlags = (*prgMenu[i].m_pfnGetMenuFlags)(prgMenu+i,
  298. pUserData);
  299. }
  300. else
  301. ulFlags = 0;
  302. // Special case - if the menu flags returns 0xFFFFFFFF
  303. // then we interpret this to mean don't add the menu item
  304. if (ulFlags == 0xFFFFFFFF)
  305. continue;
  306. stMenu.Empty();
  307. if (prgMenu[i].m_sidMenu)
  308. stMenu.LoadString(prgMenu[i].m_sidMenu);
  309. }
  310. LoadAndAddMenuItem(pCallback,
  311. stMenu,
  312. prgMenu[i].m_sidMenu,
  313. prgMenu[i].m_ulPosition,
  314. ulFlags,
  315. prgMenu[i].m_pszLangIndStr);
  316. }
  317. return hr;
  318. }