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.

283 lines
7.2 KiB

  1. /*++
  2. Module Name:
  3. DfsScope.cpp
  4. Abstract:
  5. This module contains the implementation for CDfsSnapinScopeManager.
  6. Most of the method of the class CDfsSnapinScopeManager are in other files.
  7. Only the constructor is here
  8. --*/
  9. #include "stdafx.h"
  10. #include "DfsGUI.h"
  11. #include "DfsScope.h"
  12. #include "MmcAdmin.h"
  13. #include "utils.h"
  14. #include <ntverp.h>
  15. CDfsSnapinScopeManager::CDfsSnapinScopeManager()
  16. {
  17. m_hLargeBitmap = NULL;
  18. m_hSmallBitmap = NULL;
  19. m_hSmallBitmapOpen = NULL;
  20. m_hSnapinIcon = NULL;
  21. m_hWatermark = NULL;
  22. m_hHeader = NULL;
  23. m_pMmcDfsAdmin = new CMmcDfsAdmin( this );
  24. }
  25. CDfsSnapinScopeManager::~CDfsSnapinScopeManager()
  26. {
  27. m_pMmcDfsAdmin->Release();
  28. if (m_hLargeBitmap)
  29. {
  30. DeleteObject(m_hLargeBitmap);
  31. m_hLargeBitmap = NULL;
  32. }
  33. if (m_hSmallBitmap)
  34. {
  35. DeleteObject(m_hSmallBitmap);
  36. m_hSmallBitmap = NULL;
  37. }
  38. if (m_hSmallBitmapOpen)
  39. {
  40. DeleteObject(m_hSmallBitmapOpen);
  41. m_hSmallBitmapOpen = NULL;
  42. }
  43. if (m_hSnapinIcon)
  44. {
  45. DestroyIcon(m_hSnapinIcon);
  46. m_hSnapinIcon = NULL;
  47. }
  48. if (m_hWatermark)
  49. {
  50. DeleteObject(m_hWatermark);
  51. m_hWatermark = NULL;
  52. }
  53. if (m_hHeader)
  54. {
  55. DeleteObject(m_hHeader);
  56. m_hHeader = NULL;
  57. }
  58. }
  59. #ifndef ARRAYSIZE
  60. #define ARRAYSIZE(x) sizeof(x)/sizeof(x[0])
  61. #endif
  62. typedef struct _RGSMAP {
  63. LPCTSTR szKey;
  64. UINT idString;
  65. } RGSMAP;
  66. RGSMAP g_aRgsSnapinRegs[] = {
  67. OLESTR("DfsAppName"), IDS_APPLICATION_NAME
  68. };
  69. HRESULT
  70. CDfsSnapinScopeManager::UpdateRegistry(BOOL bRegister)
  71. {
  72. USES_CONVERSION;
  73. HRESULT hr = S_OK;
  74. struct _ATL_REGMAP_ENTRY *pMapEntries = NULL;
  75. int n = ARRAYSIZE(g_aRgsSnapinRegs);
  76. int i = 0;
  77. // allocate 1 extra entry that is set to {NULL, NULL}
  78. pMapEntries = (struct _ATL_REGMAP_ENTRY *)calloc(n+2+1, sizeof(struct _ATL_REGMAP_ENTRY));
  79. if (!pMapEntries)
  80. return E_OUTOFMEMORY;
  81. if (n > 0)
  82. {
  83. CComBSTR bstrString;
  84. for (i=0; i<n; i++)
  85. {
  86. pMapEntries[i].szKey = g_aRgsSnapinRegs[i].szKey;
  87. hr = LoadStringFromResource(g_aRgsSnapinRegs[i].idString, &bstrString);
  88. if (FAILED(hr))
  89. break;
  90. pMapEntries[i].szData = T2OLE(bstrString.Detach());
  91. }
  92. }
  93. pMapEntries[n].szKey = OLESTR("DfsAppProvider");
  94. pMapEntries[n+1].szKey = OLESTR("DfsAppVersion");
  95. try {
  96. pMapEntries[n].szData = A2OLE(VER_COMPANYNAME_STR); //allocated on stack, will be freed automatically
  97. pMapEntries[n+1].szData = A2OLE(VER_PRODUCTVERSION_STR); // allocated on stack, will be freed automatically
  98. } catch (...) // (EXCEPTION_EXECUTE_HANDLER)
  99. {
  100. hr = E_OUTOFMEMORY; // stack over-flow
  101. }
  102. if (SUCCEEDED(hr))
  103. hr = _Module.UpdateRegistryFromResource(IDR_DFSSNAPINSCOPEMANAGER, bRegister, pMapEntries);
  104. // free resource strings
  105. if (n > 0)
  106. {
  107. for (i=0; i<n; i++)
  108. {
  109. if (pMapEntries[i].szData)
  110. SysFreeString( const_cast<LPTSTR>(OLE2CT(pMapEntries[i].szData)) );
  111. }
  112. free(pMapEntries);
  113. }
  114. return hr;
  115. }
  116. STDMETHODIMP CDfsSnapinScopeManager::CreatePropertyPages(
  117. IN LPPROPERTYSHEETCALLBACK i_lpPropSheetCallback,
  118. IN LONG_PTR i_lhandle,
  119. IN LPDATAOBJECT i_lpDataObject
  120. )
  121. /*++
  122. Routine Description:
  123. Called to create PropertyPages for the given node.
  124. The fact that this has been called implies the display object has a
  125. page to display.
  126. Arguments:
  127. i_lpPropSheetCallback - The callback used to add pages.
  128. i_lhandle - The handle used for notification
  129. i_lpDataObject - The IDataObject pointer which is used to get
  130. the DisplayObject.
  131. --*/
  132. {
  133. RETURN_INVALIDARG_IF_NULL(i_lpPropSheetCallback);
  134. // Assume we have page to display in case of NULL pDataObject,
  135. // this allows us to invoke wizard without specifing the pDataObject
  136. // in IPropertySheetProvider::CreatePropertySheet
  137. if (!i_lpDataObject)
  138. return S_OK;
  139. CMmcDisplay* pCMmcDisplayObj = NULL;
  140. HRESULT hr = GetDisplayObject(i_lpDataObject, &pCMmcDisplayObj);
  141. if (SUCCEEDED(hr))
  142. hr = pCMmcDisplayObj->CreatePropertyPages(i_lpPropSheetCallback, i_lhandle);
  143. return hr;
  144. }
  145. STDMETHODIMP CDfsSnapinScopeManager::QueryPagesFor(
  146. IN LPDATAOBJECT i_lpDataObject
  147. )
  148. /*++
  149. Routine Description:
  150. Called by the console to decide whether there are PropertyPages
  151. for the given node that should be displayed.
  152. We check, if the context is for scope or result(thereby skipping
  153. node manager) and if it is pass on the call to the Display object
  154. Arguments:
  155. i_lpDataObject - The IDataObject pointer which is used to get
  156. the DisplayObject.
  157. Return value:
  158. S_OK, if we want pages to be displayed. This is decided by the display object
  159. S_FALSE, if we don't want pages to be display.
  160. --*/
  161. {
  162. // Assume we have page to display in case of NULL pDataObject,
  163. // this allows us to invoke wizard without specifing the pDataObject
  164. // in IPropertySheetProvider::CreatePropertySheet
  165. if (!i_lpDataObject)
  166. return S_OK;
  167. CMmcDisplay* pCMmcDisplayObj = NULL;
  168. HRESULT hr = GetDisplayObject(i_lpDataObject, &pCMmcDisplayObj);
  169. if (SUCCEEDED(hr))
  170. hr = pCMmcDisplayObj->QueryPagesFor();
  171. return hr;
  172. }
  173. STDMETHODIMP
  174. CDfsSnapinScopeManager::GetWatermarks(
  175. IN LPDATAOBJECT pDataObject,
  176. IN HBITMAP* lphWatermark,
  177. IN HBITMAP* lphHeader,
  178. IN HPALETTE* lphPalette,
  179. IN BOOL* bStretch
  180. )
  181. {
  182. /*++
  183. Routine Description:
  184. Gives the water mark bitmaps to mmc to display for 97-style wizard pages.
  185. The snap-in is responsible for freeing the watermark and header resource.
  186. Arguments:
  187. lphWatermark - Bitmap mark for body
  188. lphHeader - Bitmap for header
  189. lphPalette - Pallete
  190. bStretch - Strech / not?
  191. --*/
  192. HRESULT hr = S_OK;
  193. do {
  194. if (!m_hWatermark)
  195. {
  196. m_hWatermark = (HBITMAP)LoadImage(_Module.GetModuleInstance(), MAKEINTRESOURCE(IDB_CREATE_DFSROOT_WATERMARK),
  197. IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
  198. if(!m_hWatermark)
  199. {
  200. hr = HRESULT_FROM_WIN32(GetLastError());
  201. break;
  202. }
  203. }
  204. if (!m_hHeader)
  205. {
  206. m_hHeader = (HBITMAP)LoadImage(_Module.GetModuleInstance(), MAKEINTRESOURCE(IDB_CREATE_DFSROOT_HEADER),
  207. IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
  208. if(!m_hHeader)
  209. {
  210. hr = HRESULT_FROM_WIN32(GetLastError());
  211. break;
  212. }
  213. }
  214. *lphWatermark = m_hWatermark;
  215. *lphHeader = m_hHeader;
  216. *bStretch = FALSE;
  217. *lphPalette = NULL;
  218. } while (0);
  219. return hr;
  220. }