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.

702 lines
16 KiB

  1. /*++
  2. Module Name:
  3. ICompont.cpp
  4. Abstract:
  5. This module contains the IComponent Interface implementation for Dfs Admin snapin,
  6. Implementation for the CDfsSnapinResultManager class
  7. --*/
  8. #include "stdafx.h"
  9. #include "DfsGUI.h"
  10. #include "DfsCore.h" // For IDfsRoot
  11. #include "DfsScope.h" // For CDfsScopeManager
  12. #include "DfsReslt.h" // IComponent and other declarations
  13. #include "MMCAdmin.h" // For CMMCDfsAdmin
  14. #include "Utils.h"
  15. #include <htmlHelp.h>
  16. STDMETHODIMP
  17. CDfsSnapinResultManager::Initialize(
  18. IN LPCONSOLE i_lpConsole
  19. )
  20. /*++
  21. Routine Description:
  22. Initializes the Icomponent interface. Allows the interface to save pointers,
  23. interfaces that are required later.
  24. Arguments:
  25. i_lpConsole - Pointer to the IConsole object.
  26. --*/
  27. {
  28. RETURN_INVALIDARG_IF_NULL(i_lpConsole);
  29. HRESULT hr = i_lpConsole->QueryInterface(IID_IConsole2, reinterpret_cast<void**>(&m_pConsole));
  30. RETURN_IF_FAILED(hr);
  31. hr = i_lpConsole->QueryInterface(IID_IHeaderCtrl2, reinterpret_cast<void**>(&m_pHeader));
  32. RETURN_IF_FAILED(hr);
  33. hr = i_lpConsole -> QueryInterface (IID_IResultData, (void**)&m_pResultData);
  34. RETURN_IF_FAILED(hr);
  35. hr = i_lpConsole->QueryConsoleVerb(&m_pConsoleVerb);
  36. RETURN_IF_FAILED(hr);
  37. return(S_OK);
  38. }
  39. STDMETHODIMP
  40. CDfsSnapinResultManager::Notify(
  41. IN LPDATAOBJECT i_lpDataObject,
  42. IN MMC_NOTIFY_TYPE i_Event,
  43. IN LPARAM i_lArg,
  44. IN LPARAM i_lParam
  45. )
  46. /*++
  47. Routine Description:
  48. Handles different events in form of notify
  49. Arguments:
  50. i_lpDataObject - The data object for the node for which the event occured
  51. i_Event - The type of event for which notify has occurred
  52. i_lArg - Argument for the event
  53. i_lParam - Parameters for the event.
  54. Return value:
  55. S_OK, On success
  56. E_INVALIDARG, On incorrect input parameters
  57. HRESULT sent by methods called, if it is not S_OK.
  58. --*/
  59. {
  60. HRESULT hr = S_FALSE;
  61. switch(i_Event)
  62. {
  63. case MMCN_SHOW:
  64. { // Show Result items.
  65. hr = DoNotifyShow(i_lpDataObject, i_lArg, i_lParam);
  66. break;
  67. }
  68. case MMCN_ADD_IMAGES: // Called once for every change of view\focus
  69. {
  70. CMmcDisplay* pCMmcDisplayObj = NULL;
  71. hr = m_pScopeManager->GetDisplayObject(i_lpDataObject, &pCMmcDisplayObj);
  72. if (SUCCEEDED(hr))
  73. hr = pCMmcDisplayObj->OnAddImages((IImageList *)i_lArg, (HSCOPEITEM)i_lParam);
  74. break;
  75. }
  76. case MMCN_SELECT: // Called when a node has been selected
  77. {
  78. hr = DoNotifySelect(i_lpDataObject, i_lArg, i_lParam);
  79. break;
  80. }
  81. case MMCN_DBLCLICK: // Ask MMC to use the default verb. Non documented feature
  82. {
  83. hr = DoNotifyDblClick(i_lpDataObject);
  84. break;
  85. }
  86. case MMCN_DELETE: // Delete the node. Time to remove item
  87. {
  88. hr = DoNotifyDelete(i_lpDataObject);
  89. break;
  90. }
  91. case MMCN_SNAPINHELP:
  92. case MMCN_CONTEXTHELP:
  93. {
  94. hr = DfsHelp();
  95. break;
  96. }
  97. case MMCN_VIEW_CHANGE:
  98. {
  99. hr = DoNotifyViewChange(i_lpDataObject, (LONG_PTR)i_lArg, (LONG_PTR)i_lParam);
  100. break;
  101. }
  102. case MMCN_REFRESH:
  103. {
  104. hr = DoNotifyRefresh(i_lpDataObject);
  105. break;
  106. }
  107. default:
  108. break;
  109. }
  110. return hr;
  111. }
  112. STDMETHODIMP
  113. CDfsSnapinResultManager::DoNotifyShow(
  114. IN LPDATAOBJECT i_lpDataObject,
  115. IN BOOL i_bShow,
  116. IN HSCOPEITEM i_hParent
  117. )
  118. /*++
  119. Routine Description:
  120. Take action on Notify with the event MMCN_SHOW.
  121. Do add the column headers to result pane and add items to result pane.
  122. Arguments:
  123. i_lpDataObject - The IDataObject pointer which identifies the node for which
  124. the event is taking place
  125. i_bShow - TRUE, if the node is being showed. FALSE otherwise
  126. i_hParent - HSCOPEITEM of the node that received this event
  127. Return value:
  128. S_OK, if successful.
  129. E_INVALIDARG, if one of the arguments is null.
  130. HRESULT sent by methods called, if it is not S_OK.
  131. --*/
  132. {
  133. RETURN_INVALIDARG_IF_NULL(i_lpDataObject);
  134. HRESULT hr = S_FALSE;
  135. CMmcDisplay* pCMmcDisplayObj = NULL;
  136. hr = m_pScopeManager->GetDisplayObject(i_lpDataObject, &pCMmcDisplayObj);
  137. RETURN_IF_FAILED(hr);
  138. DISPLAY_OBJECT_TYPE DisplayObType = pCMmcDisplayObj->GetDisplayObjectType();
  139. if (i_bShow && DISPLAY_OBJECT_TYPE_ADMIN == DisplayObType)
  140. {
  141. CComPtr<IUnknown> spUnknown;
  142. CComPtr<IMessageView> spMessageView;
  143. hr = m_pConsole->QueryResultView(&spUnknown);
  144. _ASSERT(SUCCEEDED(hr));
  145. hr = spUnknown->QueryInterface(IID_IMessageView, (PVOID*)&spMessageView);
  146. if (SUCCEEDED(hr))
  147. {
  148. CComBSTR bstrTitleText;
  149. CComBSTR bstrBodyText;
  150. LoadStringFromResource(IDS_APPLICATION_NAME, &bstrTitleText);
  151. LoadStringFromResource(IDS_MSG_DFS_INTRO, &bstrBodyText);
  152. spMessageView->SetTitleText(bstrTitleText);
  153. spMessageView->SetBodyText(bstrBodyText);
  154. spMessageView->SetIcon(Icon_Information);
  155. }
  156. return hr;
  157. }
  158. if(FALSE == i_bShow) // If the item is being deselected.
  159. {
  160. // This node is being "un-shown".
  161. m_pSelectScopeDisplayObject = NULL;
  162. return S_OK;
  163. }
  164. // This node is being shown.
  165. m_pSelectScopeDisplayObject = pCMmcDisplayObj;
  166. CWaitCursor WaitCursor; // An object to set\reset the cursor to wait cursor
  167. hr = pCMmcDisplayObj->SetColumnHeader(m_pHeader); // Call the method SetColumnHeader in the Display callback
  168. RETURN_IF_FAILED(hr);
  169. hr = pCMmcDisplayObj->EnumerateResultPane (m_pResultData); // Add the items to the Result pane
  170. return S_OK;
  171. }
  172. STDMETHODIMP
  173. CDfsSnapinResultManager::Destroy(
  174. IN MMC_COOKIE i_lCookie
  175. )
  176. /*++
  177. Routine Description:
  178. The IComponent object is about to be destroyed. Explicitely release all interface pointers,
  179. otherwise, MMC may not call the destructor.
  180. Arguments:
  181. None.
  182. Return value:
  183. S_OK.
  184. --*/
  185. {
  186. m_pHeader.Release();
  187. m_pResultData.Release();
  188. m_pConsoleVerb.Release();
  189. m_pConsole.Release();
  190. m_pControlbar.Release();
  191. m_pMMCAdminToolBar.Release();
  192. m_pMMCRootToolBar.Release();
  193. m_pMMCJPToolBar.Release();
  194. m_pMMCReplicaToolBar.Release();
  195. return S_OK;
  196. }
  197. STDMETHODIMP
  198. CDfsSnapinResultManager::GetResultViewType(
  199. IN MMC_COOKIE i_lCookie,
  200. OUT LPOLESTR* o_ppViewType,
  201. OUT LPLONG o_lpViewOptions
  202. )
  203. /*++
  204. Routine Description:
  205. Used to describe to MMC the type of view the result pane has.
  206. Arguments:
  207. i_lCookie - This parameter is used identify the Scope Pane item. Not used
  208. o_ppViewType - Not used.
  209. o_lpViewOptions - Pointer to the MMC_VIEW_OPTIONS enumeration. Used to specify
  210. what view is being used
  211. Return value:
  212. S_FALSE to indicate that the default list view should be used.
  213. E_INVALIDARG, if one of the arguments is null.
  214. --*/
  215. {
  216. RETURN_INVALIDARG_IF_NULL(o_lpViewOptions);
  217. if (i_lCookie == 0) // the static node
  218. {
  219. *o_lpViewOptions = MMC_VIEW_OPTIONS_NOLISTVIEWS;
  220. LPOLESTR psz = NULL;
  221. StringFromCLSID(CLSID_MessageView, &psz);
  222. USES_CONVERSION;
  223. if (psz)
  224. {
  225. *o_ppViewType = psz;
  226. return S_OK;
  227. }
  228. }
  229. *o_lpViewOptions = MMC_VIEW_OPTIONS_NONE | MMC_VIEW_OPTIONS_EXCLUDE_SCOPE_ITEMS_FROM_LIST; // Use the default list view
  230. *o_ppViewType = NULL;
  231. return S_FALSE; // Use the list view. S_OK implies some other view
  232. }
  233. STDMETHODIMP
  234. CDfsSnapinResultManager::QueryDataObject(
  235. IN MMC_COOKIE i_lCookie,
  236. IN DATA_OBJECT_TYPES i_DataObjectType,
  237. OUT LPDATAOBJECT* o_ppDataObject
  238. )
  239. /*++
  240. Routine Description:
  241. Returns the IDataObject for the specified node.
  242. Arguments:
  243. i_lCookie - This parameter identifies the node for which IDataObject is
  244. being queried.
  245. i_DataObjectType - The context in which the IDataObject is being queried.
  246. Eg., Result or Scope or Snapin(Node) Manager.
  247. o_ppDataObject - The data object will be returned in this pointer.
  248. Return value:
  249. S_OK, On success
  250. E_INVALIDARG, On incorrect input parameters
  251. HRESULT sent by methods called, if it is not S_OK.
  252. --*/
  253. {
  254. RETURN_INVALIDARG_IF_NULL(o_ppDataObject);
  255. if (NULL == m_pScopeManager)
  256. {
  257. return(E_UNEXPECTED);
  258. }
  259. return m_pScopeManager->QueryDataObject(i_lCookie, i_DataObjectType, o_ppDataObject);
  260. }
  261. STDMETHODIMP
  262. CDfsSnapinResultManager::GetDisplayInfo(
  263. IN OUT RESULTDATAITEM* io_pResultDataItem
  264. )
  265. /*++
  266. Routine Description:
  267. Returns the display information being asked for by MMC.
  268. Arguments:
  269. io_pResultDataItem - Contains details about what information is being asked for.
  270. The information being asked in returned in this object itself.
  271. Return value:
  272. S_OK, On success
  273. E_INVALIDARG, On incorrect input parameters
  274. HRESULT sent by methods called, if it is not S_OK.
  275. --*/
  276. {
  277. RETURN_INVALIDARG_IF_NULL(io_pResultDataItem);
  278. RETURN_INVALIDARG_IF_NULL(io_pResultDataItem->lParam);
  279. HRESULT hr = E_FAIL;
  280. CMmcDisplay* pCMmcDisplayObj = NULL;
  281. pCMmcDisplayObj = reinterpret_cast<CMmcDisplay*>(io_pResultDataItem->lParam);
  282. _ASSERTE(NULL != pCMmcDisplayObj);
  283. hr = pCMmcDisplayObj->GetResultDisplayInfo(io_pResultDataItem);
  284. RETURN_IF_FAILED(hr);
  285. return S_OK;
  286. }
  287. STDMETHODIMP
  288. CDfsSnapinResultManager::CompareObjects(
  289. IN LPDATAOBJECT i_lpDataObjectA,
  290. IN LPDATAOBJECT i_lpDataObjectB
  291. )
  292. {
  293. return m_pScopeManager->CompareObjects(i_lpDataObjectA, i_lpDataObjectB);
  294. }
  295. STDMETHODIMP
  296. CDfsSnapinResultManager::DoNotifySelect(
  297. IN LPDATAOBJECT i_lpDataObject,
  298. IN BOOL i_bSelect,
  299. IN HSCOPEITEM i_hParent
  300. )
  301. /*++
  302. Routine Description:
  303. Take action on Notify with the event MMCN_SELECT.
  304. Calling the Display object method to set the console verbs like Copy\Paste\Properties, etc
  305. Arguments:
  306. i_lpDataObject - The IDataObject pointer which is used to get the DisplayObject.
  307. i_bSelect - Used to identify whether the item is in scope and if the item is
  308. being selected or deselected
  309. i_hParent - Not used.
  310. Return value:
  311. S_OK, if successful.
  312. E_INVALIDARG, if one of the arguments is null.
  313. --*/
  314. {
  315. RETURN_INVALIDARG_IF_NULL(i_lpDataObject);
  316. HRESULT hr = S_FALSE;
  317. BOOL bSelected = HIWORD(i_bSelect); // Indicator as to whether the item is being selected
  318. BOOL bItemInScope = LOWORD(i_bSelect); // Used to indicate whether the item is in the scope.
  319. if (DOBJ_CUSTOMOCX == i_lpDataObject)
  320. return S_OK;
  321. // Get the display object from the IDataObject
  322. CMmcDisplay* pCMmcDisplayObj = NULL; // The display object
  323. hr = m_pScopeManager->GetDisplayObject(i_lpDataObject, &pCMmcDisplayObj);
  324. RETURN_IF_FAILED(hr);
  325. if (TRUE == bSelected)
  326. {
  327. if ((m_pConsoleVerb != NULL))
  328. {
  329. // Set MMC Console verbs like Cut\Paste\Properties, etc
  330. hr = pCMmcDisplayObj->SetConsoleVerbs(m_pConsoleVerb);
  331. RETURN_IF_FAILED(hr);
  332. }
  333. // Set the text in the description bar above the result view
  334. hr = pCMmcDisplayObj->SetDescriptionBarText(m_pResultData);
  335. RETURN_IF_FAILED(hr);
  336. hr = pCMmcDisplayObj->SetStatusText(m_pConsole);
  337. RETURN_IF_FAILED(hr);
  338. }
  339. else // Clear previous text
  340. {
  341. hr = m_pResultData->SetDescBarText(NULL);
  342. RETURN_IF_FAILED(hr);
  343. hr = m_pConsole->SetStatusText(NULL);
  344. RETURN_IF_FAILED(hr);
  345. }
  346. return S_OK;
  347. }
  348. STDMETHODIMP
  349. CDfsSnapinResultManager::DoNotifyDblClick(
  350. IN LPDATAOBJECT i_lpDataObject
  351. )
  352. {
  353. RETURN_INVALIDARG_IF_NULL(i_lpDataObject);
  354. CMmcDisplay* pCMmcDisplayObj = NULL;
  355. HRESULT hr = m_pScopeManager->GetDisplayObject(i_lpDataObject, &pCMmcDisplayObj);
  356. if (SUCCEEDED(hr))
  357. hr = pCMmcDisplayObj->DoDblClick();
  358. return hr;
  359. }
  360. STDMETHODIMP
  361. CDfsSnapinResultManager::DoNotifyDelete(
  362. IN LPDATAOBJECT i_lpDataObject
  363. )
  364. /*++
  365. Routine Description:
  366. Take action on Notify with the event MMCN_DELETE.
  367. Arguments:
  368. i_lpDataObject - The IDataObject pointer which is used to get the DisplayObject.
  369. Return value:
  370. S_OK, if successful.
  371. E_INVALIDARG, if one of the arguments is null.
  372. HRESULT sent by methods called, if it is not S_OK.
  373. --*/
  374. {
  375. RETURN_INVALIDARG_IF_NULL(i_lpDataObject);
  376. HRESULT hr = S_FALSE;
  377. CMmcDisplay* pCMmcDisplayObj = NULL;
  378. hr = m_pScopeManager->GetDisplayObject(i_lpDataObject, &pCMmcDisplayObj);
  379. RETURN_IF_FAILED(hr);
  380. hr = pCMmcDisplayObj->DoDelete(); // Delete the the item.
  381. RETURN_IF_FAILED(hr);
  382. return S_OK;
  383. }
  384. //+--------------------------------------------------------------
  385. //
  386. // Function: CDfsSnapinResultManager::DfsHelp
  387. //
  388. // Synopsis: Display dfs help topic.
  389. //
  390. //---------------------------------------------------------------
  391. STDMETHODIMP
  392. CDfsSnapinResultManager::DfsHelp()
  393. {
  394. CComPtr<IDisplayHelp> sp;
  395. HRESULT hr = m_pConsole->QueryInterface(IID_IDisplayHelp, (void**)&sp);
  396. if (SUCCEEDED(hr))
  397. {
  398. CComBSTR bstrTopic;
  399. hr = LoadStringFromResource(IDS_MMC_HELP_FILE_TOPIC, &bstrTopic);
  400. if (SUCCEEDED(hr))
  401. {
  402. LPOLESTR pszHelpTopic = (LPOLESTR)CoTaskMemAlloc( sizeof(WCHAR) * (wcslen(bstrTopic) + 1) );
  403. if (pszHelpTopic)
  404. {
  405. USES_CONVERSION;
  406. wcscpy(pszHelpTopic, T2OLE(bstrTopic));
  407. hr = sp->ShowTopic(pszHelpTopic);
  408. } else
  409. hr = E_OUTOFMEMORY;
  410. }
  411. }
  412. return hr;
  413. }
  414. STDMETHODIMP CDfsSnapinResultManager::DoNotifyViewChange(
  415. IN LPDATAOBJECT i_lpDataObject,
  416. IN LONG_PTR i_lArg,
  417. IN LONG_PTR i_lParam
  418. )
  419. /*++
  420. Routine Description:
  421. Take action on Notify with the event MMCN_VIEW_CHANGE
  422. Arguments:
  423. i_lpDataObject - The IDataObject pointer which is used to get the DisplayObject.
  424. i_lArg - If this is present then the view change is for replica and this parameter
  425. contains the DisplayObject (CMmcDfsReplica*) pointer of the replica.
  426. i_lParam - This is the lHint used by Root and Link. 0 means clean up the result pane only.
  427. 1 means to enumerate the result items and redisplay.
  428. Return value:
  429. S_OK, if successful.
  430. E_INVALIDARG, if one of the arguments is null.
  431. HRESULT sent by methods called, if it is not S_OK.
  432. --*/
  433. {
  434. RETURN_INVALIDARG_IF_NULL(i_lpDataObject);
  435. HRESULT hr = S_FALSE;
  436. CMmcDisplay* pCMmcDisplayObj = NULL;
  437. hr = m_pScopeManager->GetDisplayObject(i_lpDataObject, &pCMmcDisplayObj);
  438. RETURN_IF_FAILED(hr);
  439. // Is the view change node the currently selected node?
  440. if (pCMmcDisplayObj == m_pSelectScopeDisplayObject)
  441. {
  442. if (NULL != i_lArg)
  443. { // The view change is for a replica result item.
  444. CMmcDisplay* pDfsReplicaObject = (CMmcDisplay*) i_lArg;
  445. pDfsReplicaObject->ViewChange(m_pResultData, i_lParam);
  446. }
  447. hr = pCMmcDisplayObj->ViewChange(m_pResultData, i_lParam); // Handle View Change event.
  448. RETURN_IF_FAILED(hr);
  449. IToolbar *piToolbar = NULL;
  450. switch (pCMmcDisplayObj->GetDisplayObjectType())
  451. {
  452. case DISPLAY_OBJECT_TYPE_ADMIN:
  453. piToolbar = m_pMMCAdminToolBar;
  454. break;
  455. case DISPLAY_OBJECT_TYPE_ROOT:
  456. piToolbar = m_pMMCRootToolBar;
  457. break;
  458. case DISPLAY_OBJECT_TYPE_JUNCTION:
  459. piToolbar = m_pMMCJPToolBar;
  460. break;
  461. case DISPLAY_OBJECT_TYPE_REPLICA:
  462. piToolbar = m_pMMCReplicaToolBar;
  463. break;
  464. default:
  465. break;
  466. }
  467. if (piToolbar)
  468. (void)pCMmcDisplayObj->ToolbarSelect(MAKELONG(0, 1), piToolbar);
  469. }
  470. return S_OK;
  471. }
  472. STDMETHODIMP CDfsSnapinResultManager::DoNotifyRefresh(
  473. IN LPDATAOBJECT i_lpDataObject
  474. )
  475. /*++
  476. Routine Description:
  477. Called on refresh. Call the OnRefresh() method of teh display object.
  478. Arguments:
  479. i_lpDataObject - The IDataObject pointer which is used to get the DisplayObject.
  480. --*/
  481. {
  482. RETURN_INVALIDARG_IF_NULL(i_lpDataObject);
  483. HRESULT hr = S_FALSE;
  484. CMmcDisplay* pCMmcDisplayObj = NULL;
  485. hr = m_pScopeManager->GetDisplayObject(i_lpDataObject, &pCMmcDisplayObj);
  486. RETURN_IF_FAILED(hr);
  487. pCMmcDisplayObj->OnRefresh();
  488. return(S_OK);
  489. }