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.

275 lines
8.0 KiB

  1. //==============================================================;
  2. //
  3. // This source code is only intended as a supplement to existing Microsoft documentation.
  4. //
  5. //
  6. //
  7. //
  8. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  9. // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  10. // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  11. // PURPOSE.
  12. //
  13. // Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  14. //
  15. //
  16. //
  17. //==============================================================;
  18. #include "Comp.h"
  19. #include "DataObj.h"
  20. #include <commctrl.h> // Needed for button styles...
  21. #include <crtdbg.h>
  22. #include "globals.h"
  23. #include "resource.h"
  24. #include "DeleBase.h"
  25. #include "CompData.h"
  26. CComponent::CComponent(CComponentData *parent)
  27. : m_pComponentData(parent), m_cref(0), m_ipConsole(NULL)
  28. {
  29. OBJECT_CREATED
  30. }
  31. CComponent::~CComponent()
  32. {
  33. OBJECT_DESTROYED
  34. }
  35. STDMETHODIMP CComponent::QueryInterface(REFIID riid, LPVOID *ppv)
  36. {
  37. if (!ppv)
  38. return E_FAIL;
  39. *ppv = NULL;
  40. if (IsEqualIID(riid, IID_IUnknown))
  41. *ppv = static_cast<IComponent *>(this);
  42. else if (IsEqualIID(riid, IID_IComponent))
  43. *ppv = static_cast<IComponent *>(this);
  44. // first things first, make sure that when MMC
  45. // asks if we do property sheets, that we actually
  46. // say "yes"
  47. else if (IsEqualIID(riid, IID_IExtendPropertySheet))
  48. *ppv = static_cast<IExtendPropertySheet2 *>(this);
  49. else if (IsEqualIID(riid, IID_IExtendPropertySheet2))
  50. *ppv = static_cast<IExtendPropertySheet2 *>(this);
  51. if (*ppv)
  52. {
  53. reinterpret_cast<IUnknown *>(*ppv)->AddRef();
  54. return S_OK;
  55. }
  56. return E_NOINTERFACE;
  57. }
  58. STDMETHODIMP_(ULONG) CComponent::AddRef()
  59. {
  60. return InterlockedIncrement((LONG *)&m_cref);
  61. }
  62. STDMETHODIMP_(ULONG) CComponent::Release()
  63. {
  64. if (InterlockedDecrement((LONG *)&m_cref) == 0)
  65. {
  66. delete this;
  67. return 0;
  68. }
  69. return m_cref;
  70. }
  71. ///////////////////////////////
  72. // Interface IComponent
  73. ///////////////////////////////
  74. STDMETHODIMP CComponent::Initialize(
  75. /* [in] */ LPCONSOLE lpConsole)
  76. {
  77. HRESULT hr = S_OK;
  78. // Save away all the interfaces we'll need.
  79. // Fail if we can't QI the required interfaces.
  80. m_ipConsole = lpConsole;
  81. m_ipConsole->AddRef();
  82. return hr;
  83. }
  84. STDMETHODIMP CComponent::Notify(
  85. /* [in] */ LPDATAOBJECT lpDataObject,
  86. /* [in] */ MMC_NOTIFY_TYPE event,
  87. /* [in] */ LPARAM arg,
  88. /* [in] */ LPARAM param)
  89. {
  90. MMCN_Crack(FALSE, lpDataObject, NULL, this, event, arg, param);
  91. HRESULT hr = S_FALSE;
  92. CDelegationBase *base = NULL;
  93. // we need to watch for property change and delegate it
  94. // a little differently, we're actually going to send
  95. // the CDelegationBase object pointer in the property page
  96. // PSN_APPLY handler via MMCPropPageNotify()
  97. if (MMCN_PROPERTY_CHANGE != event) {
  98. if (NULL == lpDataObject)
  99. return S_FALSE;
  100. base = GetOurDataObject(lpDataObject)->GetBaseNodeObject();
  101. } else {
  102. base = (CDelegationBase *)param;
  103. }
  104. switch (event) {
  105. case MMCN_SHOW:
  106. hr = base->OnShow(m_ipConsole, (BOOL)arg, (HSCOPEITEM)param);
  107. break;
  108. case MMCN_ADD_IMAGES:
  109. hr = base->OnAddImages((IImageList *)arg, (HSCOPEITEM)param);
  110. break;
  111. case MMCN_SELECT:
  112. hr = base->OnSelect(m_ipConsole, (BOOL)LOWORD(arg), (BOOL)HIWORD(arg));
  113. break;
  114. case MMCN_RENAME:
  115. hr = base->OnRename((LPOLESTR)param);
  116. break;
  117. // handle the property change notification if we need to do anything
  118. // special with it
  119. case MMCN_PROPERTY_CHANGE:
  120. hr = base->OnPropertyChange(m_ipConsole);
  121. break;
  122. }
  123. return hr;
  124. }
  125. STDMETHODIMP CComponent::Destroy(
  126. /* [in] */ MMC_COOKIE cookie)
  127. {
  128. if (m_ipConsole) {
  129. m_ipConsole->Release();
  130. m_ipConsole = NULL;
  131. }
  132. return S_OK;
  133. }
  134. STDMETHODIMP CComponent::QueryDataObject(
  135. /* [in] */ MMC_COOKIE cookie,
  136. /* [in] */ DATA_OBJECT_TYPES type,
  137. /* [out] */ LPDATAOBJECT __RPC_FAR *ppDataObject)
  138. {
  139. CDataObject *pObj = NULL;
  140. if (cookie == 0)
  141. pObj = new CDataObject((MMC_COOKIE)m_pComponentData->m_pStaticNode, type);
  142. else
  143. pObj = new CDataObject(cookie, type);
  144. if (!pObj)
  145. return E_OUTOFMEMORY;
  146. pObj->QueryInterface(IID_IDataObject, (void **)ppDataObject);
  147. return S_OK;
  148. }
  149. STDMETHODIMP CComponent::GetResultViewType(
  150. /* [in] */ MMC_COOKIE cookie,
  151. /* [out] */ LPOLESTR __RPC_FAR *ppViewType,
  152. /* [out] */ long __RPC_FAR *pViewOptions)
  153. {
  154. CDelegationBase *base = (CDelegationBase *)cookie;
  155. //
  156. // Ask for default listview.
  157. //
  158. if (base == NULL)
  159. {
  160. *pViewOptions = MMC_VIEW_OPTIONS_NONE;
  161. *ppViewType = NULL;
  162. }
  163. else
  164. return base->GetResultViewType(ppViewType, pViewOptions);
  165. return S_OK;
  166. }
  167. STDMETHODIMP CComponent::GetDisplayInfo(
  168. /* [out][in] */ RESULTDATAITEM __RPC_FAR *pResultDataItem)
  169. {
  170. HRESULT hr = S_OK;
  171. CDelegationBase *base = NULL;
  172. // if they are asking for the RDI_STR we have one of those to give
  173. if (pResultDataItem->lParam) {
  174. base = (CDelegationBase *)pResultDataItem->lParam;
  175. if (pResultDataItem->mask & RDI_STR) {
  176. LPCTSTR pszT = base->GetDisplayName(pResultDataItem->nCol);
  177. MAKE_WIDEPTR_FROMTSTR_ALLOC(pszW, pszT);
  178. pResultDataItem->str = pszW;
  179. }
  180. if (pResultDataItem->mask & RDI_IMAGE) {
  181. pResultDataItem->nImage = base->GetBitmapIndex();
  182. }
  183. }
  184. return hr;
  185. }
  186. STDMETHODIMP CComponent::CompareObjects(
  187. /* [in] */ LPDATAOBJECT lpDataObjectA,
  188. /* [in] */ LPDATAOBJECT lpDataObjectB)
  189. {
  190. CDelegationBase *baseA = GetOurDataObject(lpDataObjectA)->GetBaseNodeObject();
  191. CDelegationBase *baseB = GetOurDataObject(lpDataObjectB)->GetBaseNodeObject();
  192. // compare the object pointers
  193. if (baseA->GetCookie() == baseB->GetCookie())
  194. return S_OK;
  195. return S_FALSE;
  196. }
  197. ///////////////////////////////////
  198. // Interface IExtendPropertySheet2
  199. ///////////////////////////////////
  200. HRESULT CComponent::CreatePropertyPages(
  201. /* [in] */ LPPROPERTYSHEETCALLBACK lpProvider,
  202. /* [in] */ LONG_PTR handle,
  203. /* [in] */ LPDATAOBJECT lpIDataObject)
  204. {
  205. CDelegationBase *base = GetOurDataObject(lpIDataObject)->GetBaseNodeObject();
  206. return base->CreatePropertyPages(lpProvider, handle);
  207. }
  208. HRESULT CComponent::QueryPagesFor(
  209. /* [in] */ LPDATAOBJECT lpDataObject)
  210. {
  211. CDelegationBase *base = GetOurDataObject(lpDataObject)->GetBaseNodeObject();
  212. return base->HasPropertySheets();
  213. }
  214. HRESULT CComponent::GetWatermarks(
  215. /* [in] */ LPDATAOBJECT lpIDataObject,
  216. /* [out] */ HBITMAP __RPC_FAR *lphWatermark,
  217. /* [out] */ HBITMAP __RPC_FAR *lphHeader,
  218. /* [out] */ HPALETTE __RPC_FAR *lphPalette,
  219. /* [out] */ BOOL __RPC_FAR *bStretch)
  220. {
  221. CDelegationBase *base = GetOurDataObject(lpIDataObject)->GetBaseNodeObject();
  222. return base->GetWatermarks(lphWatermark, lphHeader, lphPalette, bStretch);
  223. }