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.

439 lines
12 KiB

  1. /*++
  2. Module Name:
  3. IComData.cpp
  4. Abstract:
  5. This module contains the implementation for CDfsSnapinScopeManager.
  6. This class implements IComponentData and other related interfaces
  7. --*/
  8. #include "stdafx.h"
  9. #include "DfsGUI.h"
  10. #include "DfsScope.h"
  11. #include "MmcDispl.h"
  12. #include "DfsReslt.h"
  13. #include "Utils.h"
  14. #include "DfsNodes.h"
  15. STDMETHODIMP
  16. CDfsSnapinScopeManager::Initialize(
  17. IN LPUNKNOWN i_pUnknown
  18. )
  19. /*++
  20. Routine Description:
  21. Initialize the IComponentData interface.
  22. The variables needed later are QI'ed now
  23. Arguments:
  24. i_pUnknown - Pointer to the unknown object of IConsole2.
  25. --*/
  26. {
  27. RETURN_INVALIDARG_IF_NULL(i_pUnknown);
  28. HRESULT hr = i_pUnknown->QueryInterface(IID_IConsole2, reinterpret_cast<void**>(&m_pConsole));
  29. RETURN_IF_FAILED(hr);
  30. hr = m_pMmcDfsAdmin->PutConsolePtr(m_pConsole);
  31. RETURN_IF_FAILED(hr);
  32. hr = i_pUnknown->QueryInterface(IID_IConsoleNameSpace, reinterpret_cast<void**>(&m_pScope));
  33. RETURN_IF_FAILED(hr);
  34. // The snap-in should also call IConsole2::QueryScopeImageList
  35. // to get the image list for the scope pane and add images
  36. // to be displayed on the scope pane side.
  37. CComPtr<IImageList> pScopeImageList;
  38. hr = m_pConsole->QueryScopeImageList(&pScopeImageList);
  39. RETURN_IF_FAILED(hr);
  40. HBITMAP pBMapSm = NULL;
  41. HBITMAP pBMapLg = NULL;
  42. if (!(pBMapSm = LoadBitmap(_Module.GetModuleInstance(),
  43. MAKEINTRESOURCE(IDB_SCOPE_IMAGES_16x16))) ||
  44. !(pBMapLg = LoadBitmap(_Module.GetModuleInstance(),
  45. MAKEINTRESOURCE(IDB_SCOPE_IMAGES_32x32))))
  46. {
  47. hr = HRESULT_FROM_WIN32(GetLastError());
  48. } else
  49. {
  50. hr = pScopeImageList->ImageListSetStrip(
  51. (LONG_PTR *)pBMapSm,
  52. (LONG_PTR *)pBMapLg,
  53. 0,
  54. RGB(255, 0, 255)
  55. );
  56. }
  57. if (pBMapSm)
  58. DeleteObject(pBMapSm);
  59. if (pBMapLg)
  60. DeleteObject(pBMapLg);
  61. return hr;
  62. }
  63. STDMETHODIMP
  64. CDfsSnapinScopeManager::CreateComponent(
  65. OUT LPCOMPONENT* o_ppComponent
  66. )
  67. /*++
  68. Routine Description:
  69. Creates the IComponent object
  70. Arguments:
  71. o_ppComponent - Pointer to the object in which the pointer to IComponent object
  72. is stored.
  73. --*/
  74. {
  75. RETURN_INVALIDARG_IF_NULL(o_ppComponent);
  76. CComObject<CDfsSnapinResultManager>* pResultManager;
  77. CComObject<CDfsSnapinResultManager>::CreateInstance(&pResultManager);
  78. if (NULL == pResultManager)
  79. {
  80. return(E_FAIL);
  81. }
  82. pResultManager->m_pScopeManager = this;
  83. HRESULT hr = pResultManager->QueryInterface(IID_IComponent, (void**) o_ppComponent);
  84. _ASSERT(NULL != *o_ppComponent);
  85. return hr;
  86. }
  87. STDMETHODIMP
  88. CDfsSnapinScopeManager::Notify(
  89. IN LPDATAOBJECT i_lpDataObject,
  90. IN MMC_NOTIFY_TYPE i_Event,
  91. IN LPARAM i_lArg,
  92. IN LPARAM i_lParam
  93. )
  94. /*++
  95. Routine Description:
  96. Handles different events in form of notify
  97. Arguments:
  98. i_lpDataObject - The data object for the node for which the event occured
  99. i_Event - The type of event for which notify has occurred
  100. i_lArg - Argument for the event
  101. i_lParam - Parameters for the event.
  102. --*/
  103. {
  104. // The snap-in should return S_FALSE for any notification it does not handle.
  105. // MMC then performs a default operation for the notification.
  106. HRESULT hr = S_FALSE;
  107. switch(i_Event)
  108. {
  109. case MMCN_EXPAND:
  110. {
  111. // MMC sends the MMCN_EXPAND notification the first time it needs to display a
  112. // scope item's children in either the scope or result pane. The notification
  113. // is not sent each time the item is visually expanded or collapsed.
  114. // On receipt of this notification the snap-in should enumerate the children
  115. // (subcontainers only) of the specified scope item, if any, using
  116. // IConsoleNameSpace2 methods. Subsequently, if a new item is added to or deleted
  117. // from this scope object through some external means, that item should also be
  118. // added to or deleted from the console's namespace using IConsoleNameSpace2 methods.
  119. // lpDataObject: [in] Pointer to the data object of the scope item that needs
  120. // to be expanded or collapsed.
  121. // arg: [in] TRUE if the folder is being expanded; FALSE if the folder is being collapsed.
  122. // param: [in] The HSCOPEITEM of the item that needs to be expanded or collapsed.
  123. hr = DoNotifyExpand(i_lpDataObject, (BOOL)i_lArg, (HSCOPEITEM)i_lParam);
  124. break;
  125. }
  126. case MMCN_DELETE:
  127. {
  128. // This message is generated when the user presses the delete key or uses the
  129. // mouse to click the toolbar's delete button.
  130. // The snap-in should delete the items specified in the data object.
  131. // lpDataObject: [in] Pointer to the data object of the currently selected scope
  132. // or result item, provided by the snap-in.
  133. // arg: Not used.
  134. // param: Not used.
  135. CMmcDisplay* pCMmcDisplayObj = NULL;
  136. hr = GetDisplayObject(i_lpDataObject, &pCMmcDisplayObj);
  137. if (SUCCEEDED(hr))
  138. hr = pCMmcDisplayObj->DoDelete(); // Delete the the item.
  139. break;
  140. }
  141. case MMCN_PROPERTY_CHANGE: // Handle the property change
  142. {
  143. // i_lpDataObject is NULL because a data object is not required.
  144. // i_lArg is TRUE if the property change is for a scope item.
  145. // i_lParam is the param passed to MMCPropertyChangeNotify, this is the display object.
  146. hr = ((CMmcDisplay*)i_lParam)->PropertyChanged();
  147. break;
  148. }
  149. default:
  150. break;
  151. }
  152. return hr;
  153. }
  154. STDMETHODIMP
  155. CDfsSnapinScopeManager::DoNotifyExpand(
  156. IN LPDATAOBJECT i_lpDataObject,
  157. IN BOOL i_bExpanding,
  158. IN HSCOPEITEM i_hParent
  159. )
  160. /*++
  161. Routine Description:
  162. Take action on Notify with the event MMCN_EXPAND.
  163. Arguments:
  164. i_lpDataObject - The IDataObject pointer which is used to get the DisplayObject.
  165. i_bExpanding - TRUE, if the node is expanding. FALSE otherwise
  166. i_hParent - HSCOPEITEM of the node that received this event
  167. --*/
  168. {
  169. RETURN_INVALIDARG_IF_NULL(i_lpDataObject);
  170. if (!i_bExpanding)
  171. return S_OK;
  172. CWaitCursor WaitCursor;
  173. CMmcDisplay* pCMmcDisplayObj = NULL;
  174. HRESULT hr = GetDisplayObject(i_lpDataObject, &pCMmcDisplayObj);
  175. if (SUCCEEDED(hr))
  176. hr = pCMmcDisplayObj->EnumerateScopePane(m_pScope, i_hParent);
  177. return hr;
  178. }
  179. STDMETHODIMP
  180. CDfsSnapinScopeManager::Destroy()
  181. /*++
  182. Routine Description:
  183. The IComponentData object is about to be destroyed. Explicitely release all interface pointers,
  184. otherwise, MMC may not call the destructor.
  185. Arguments:
  186. None.
  187. --*/
  188. {
  189. // The snap-in is in the process of being unloaded. Release all references to the console.
  190. m_pScope.Release();
  191. m_pConsole.Release();
  192. return S_OK;
  193. }
  194. STDMETHODIMP
  195. CDfsSnapinScopeManager::QueryDataObject(
  196. IN MMC_COOKIE i_lCookie,
  197. IN DATA_OBJECT_TYPES i_DataObjectType,
  198. OUT LPDATAOBJECT* o_ppDataObject
  199. )
  200. /*++
  201. Routine Description:
  202. Returns the IDataObject for the specified node.
  203. Arguments:
  204. i_lCookie - This parameter identifies the node for which IDataObject is
  205. being queried.
  206. i_DataObjectType - The context in which the IDataObject is being queried.
  207. Eg., Result or Scope or Snapin(Node) Manager.
  208. o_ppDataObject - The data object will be returned in this pointer.
  209. --*/
  210. {
  211. RETURN_INVALIDARG_IF_NULL(o_ppDataObject);
  212. // We get back the cookie we stored in lparam of the scopeitem.
  213. // The cookie is the MmcDisplay pointer.
  214. // For the static(root) node, Use m_pMmcDfsAdmin as no lparam is stored.
  215. CMmcDisplay* pMmcDisplay = ((0 == i_lCookie)? (CMmcDisplay *)m_pMmcDfsAdmin : (CMmcDisplay *)i_lCookie);
  216. pMmcDisplay->put_CoClassCLSID(CLSID_DfsSnapinScopeManager);
  217. return pMmcDisplay->QueryInterface(IID_IDataObject, (void **)o_ppDataObject);
  218. }
  219. STDMETHODIMP
  220. CDfsSnapinScopeManager::GetDisplayInfo(
  221. IN OUT SCOPEDATAITEM* io_pScopeDataItem
  222. )
  223. /*++
  224. Routine Description:
  225. Retrieves display information for a scope item.
  226. Arguments:
  227. io_pScopeDataItem - Contains details about what information is being asked for.
  228. The information being asked is returned in this object itself.
  229. --*/
  230. {
  231. RETURN_INVALIDARG_IF_NULL(io_pScopeDataItem);
  232. // This (cookie) is null for static node.
  233. // Static node display name is returned through IDataObject Clipboard.
  234. if (NULL == io_pScopeDataItem->lParam)
  235. return(S_OK);
  236. return ((CMmcDisplay*)(io_pScopeDataItem->lParam))->GetScopeDisplayInfo(io_pScopeDataItem);
  237. }
  238. STDMETHODIMP
  239. CDfsSnapinScopeManager::CompareObjects(
  240. IN LPDATAOBJECT lpDataObjectA,
  241. IN LPDATAOBJECT lpDataObjectB
  242. )
  243. /*++
  244. Routine Description:
  245. The method enables a snap-in to compare two data objects acquired through QueryDataObject.
  246. Return Values:
  247. S_OK: The data objects represented by lpDataObjectA and lpDataObjectB are the same.
  248. S_FALSE: The data objects represented by lpDataObjectA and lpDataObjectB are not the same.
  249. --*/
  250. {
  251. if (lpDataObjectA == lpDataObjectB)
  252. return S_OK;
  253. if (!lpDataObjectA || !lpDataObjectB)
  254. return S_FALSE;
  255. FORMATETC fmte = {CMmcDisplay::mMMC_CF_Dfs_Snapin_Internal, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
  256. STGMEDIUM medium = {TYMED_HGLOBAL, NULL, NULL};
  257. medium.hGlobal = ::GlobalAlloc(GMEM_SHARE | GMEM_MOVEABLE | GMEM_NODISCARD, (sizeof(ULONG_PTR)));
  258. if (medium.hGlobal == NULL)
  259. return STG_E_MEDIUMFULL;
  260. HRESULT hr = lpDataObjectA->GetDataHere(&fmte, &medium);
  261. RETURN_IF_FAILED(hr);
  262. ULONG_PTR* pulVal = (ULONG_PTR*)(GlobalLock(medium.hGlobal));
  263. CMmcDisplay* pMmcDisplayA = reinterpret_cast<CMmcDisplay *>(*pulVal);
  264. GlobalUnlock(medium.hGlobal);
  265. hr = lpDataObjectB->GetDataHere(&fmte, &medium);
  266. RETURN_IF_FAILED(hr);
  267. pulVal = (ULONG_PTR*)(GlobalLock(medium.hGlobal));
  268. CMmcDisplay* pMmcDisplayB = reinterpret_cast<CMmcDisplay *>(*pulVal);
  269. GlobalUnlock(medium.hGlobal);
  270. GlobalFree(medium.hGlobal);
  271. return ((pMmcDisplayA == pMmcDisplayB) ? S_OK : S_FALSE);
  272. }
  273. STDMETHODIMP
  274. CDfsSnapinScopeManager::GetDisplayObject(
  275. IN LPDATAOBJECT i_lpDataObject,
  276. OUT CMmcDisplay** o_ppMmcDisplay
  277. )
  278. /*++
  279. Routine Description:
  280. Get the Display Object from the IDataObject. This is a derived object that is used for a
  281. lot of purposes
  282. Arguments:
  283. i_lpDataObject - The IDataObject pointer which is used to get the DisplayObject.
  284. o_ppMmcDisplay - The MmcDisplayObject written by us. Used as a callback for Mmc
  285. related display operations.
  286. --*/
  287. {
  288. RETURN_INVALIDARG_IF_NULL(i_lpDataObject);
  289. RETURN_INVALIDARG_IF_NULL(o_ppMmcDisplay);
  290. FORMATETC fmte = {CMmcDisplay::mMMC_CF_Dfs_Snapin_Internal, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
  291. STGMEDIUM medium = {TYMED_HGLOBAL, NULL, NULL};
  292. medium.hGlobal = ::GlobalAlloc(GMEM_SHARE | GMEM_MOVEABLE | GMEM_NODISCARD, (sizeof(ULONG_PTR)));
  293. if (medium.hGlobal == NULL)
  294. return STG_E_MEDIUMFULL;
  295. HRESULT hr = i_lpDataObject->GetDataHere(&fmte, &medium);
  296. if (SUCCEEDED(hr))
  297. {
  298. ULONG_PTR* pulVal = (ULONG_PTR*)(GlobalLock(medium.hGlobal));
  299. *o_ppMmcDisplay = reinterpret_cast<CMmcDisplay *>(*pulVal);
  300. GlobalUnlock(medium.hGlobal);
  301. }
  302. GlobalFree(medium.hGlobal);
  303. return hr;
  304. }