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.

253 lines
7.4 KiB

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