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.

256 lines
7.2 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. else if (IsEqualIID(riid, IID_IExtendPropertySheet))
  45. *ppv = static_cast<IExtendPropertySheet2 *>(this);
  46. if (*ppv)
  47. {
  48. reinterpret_cast<IUnknown *>(*ppv)->AddRef();
  49. return S_OK;
  50. }
  51. return E_NOINTERFACE;
  52. }
  53. STDMETHODIMP_(ULONG) CComponent::AddRef()
  54. {
  55. return InterlockedIncrement((LONG *)&m_cref);
  56. }
  57. STDMETHODIMP_(ULONG) CComponent::Release()
  58. {
  59. if (InterlockedDecrement((LONG *)&m_cref) == 0)
  60. {
  61. delete this;
  62. return 0;
  63. }
  64. return m_cref;
  65. }
  66. ///////////////////////////////
  67. // Interface IComponent
  68. ///////////////////////////////
  69. STDMETHODIMP CComponent::Initialize(
  70. /* [in] */ LPCONSOLE lpConsole)
  71. {
  72. HRESULT hr = S_OK;
  73. // Save away all the interfaces we'll need.
  74. // Fail if we can't QI the required interfaces.
  75. m_ipConsole = lpConsole;
  76. m_ipConsole->AddRef();
  77. return hr;
  78. }
  79. STDMETHODIMP CComponent::Notify(
  80. /* [in] */ LPDATAOBJECT lpDataObject,
  81. /* [in] */ MMC_NOTIFY_TYPE event,
  82. /* [in] */ LPARAM arg,
  83. /* [in] */ LPARAM param)
  84. {
  85. MMCN_Crack(FALSE, lpDataObject, NULL, this, event, arg, param);
  86. HRESULT hr = S_FALSE;
  87. //Get our data object. If it is NULL, we return with S_FALSE.
  88. //See implementation of GetOurDataObject() to see how to
  89. //handle special data objects.
  90. CDataObject *pDataObject = GetOurDataObject(lpDataObject);
  91. if (NULL == pDataObject)
  92. return S_FALSE;
  93. CDelegationBase *base = pDataObject->GetBaseNodeObject();
  94. switch (event) {
  95. case MMCN_SHOW:
  96. hr = base->OnShow(m_ipConsole, (BOOL)arg, (HSCOPEITEM)param);
  97. break;
  98. case MMCN_ADD_IMAGES:
  99. hr = base->OnAddImages((IImageList *)arg, (HSCOPEITEM)param);
  100. break;
  101. case MMCN_SELECT:
  102. hr = base->OnSelect(m_ipConsole, (BOOL)LOWORD(arg), (BOOL)HIWORD(arg));
  103. break;
  104. case MMCN_RENAME:
  105. hr = base->OnRename((LPOLESTR)param);
  106. break;
  107. }
  108. return hr;
  109. }
  110. STDMETHODIMP CComponent::Destroy(
  111. /* [in] */ MMC_COOKIE cookie)
  112. {
  113. if (m_ipConsole) {
  114. m_ipConsole->Release();
  115. m_ipConsole = NULL;
  116. }
  117. return S_OK;
  118. }
  119. STDMETHODIMP CComponent::QueryDataObject(
  120. /* [in] */ MMC_COOKIE cookie,
  121. /* [in] */ DATA_OBJECT_TYPES type,
  122. /* [out] */ LPDATAOBJECT __RPC_FAR *ppDataObject)
  123. {
  124. CDataObject *pObj = NULL;
  125. if (cookie == 0)
  126. pObj = new CDataObject((MMC_COOKIE)m_pComponentData->m_pStaticNode, type);
  127. else
  128. pObj = new CDataObject(cookie, type);
  129. if (!pObj)
  130. return E_OUTOFMEMORY;
  131. pObj->QueryInterface(IID_IDataObject, (void **)ppDataObject);
  132. return S_OK;
  133. }
  134. STDMETHODIMP CComponent::GetResultViewType(
  135. /* [in] */ MMC_COOKIE cookie,
  136. /* [out] */ LPOLESTR __RPC_FAR *ppViewType,
  137. /* [out] */ long __RPC_FAR *pViewOptions)
  138. {
  139. CDelegationBase *base = (CDelegationBase *)cookie;
  140. //
  141. // Ask for default listview.
  142. //
  143. if (base == NULL)
  144. {
  145. *pViewOptions = MMC_VIEW_OPTIONS_NONE;
  146. *ppViewType = NULL;
  147. }
  148. else
  149. return base->GetResultViewType(ppViewType, pViewOptions);
  150. return S_OK;
  151. }
  152. STDMETHODIMP CComponent::GetDisplayInfo(
  153. /* [out][in] */ RESULTDATAITEM __RPC_FAR *pResultDataItem)
  154. {
  155. HRESULT hr = S_OK;
  156. CDelegationBase *base = NULL;
  157. // if they are asking for the RDI_STR we have one of those to give
  158. if (pResultDataItem->lParam) {
  159. base = (CDelegationBase *)pResultDataItem->lParam;
  160. if (pResultDataItem->mask & RDI_STR) {
  161. LPCTSTR pszT = base->GetDisplayName(pResultDataItem->nCol);
  162. MAKE_WIDEPTR_FROMTSTR_ALLOC(pszW, pszT);
  163. pResultDataItem->str = pszW;
  164. }
  165. if (pResultDataItem->mask & RDI_IMAGE) {
  166. pResultDataItem->nImage = base->GetBitmapIndex();
  167. }
  168. }
  169. return hr;
  170. }
  171. STDMETHODIMP CComponent::CompareObjects(
  172. /* [in] */ LPDATAOBJECT lpDataObjectA,
  173. /* [in] */ LPDATAOBJECT lpDataObjectB)
  174. {
  175. CDelegationBase *baseA = GetOurDataObject(lpDataObjectA)->GetBaseNodeObject();
  176. CDelegationBase *baseB = GetOurDataObject(lpDataObjectB)->GetBaseNodeObject();
  177. // compare the object pointers
  178. if (baseA->GetCookie() == baseB->GetCookie())
  179. return S_OK;
  180. return S_FALSE;
  181. }
  182. ///////////////////////////////////
  183. // Interface IExtendPropertySheet2
  184. ///////////////////////////////////
  185. //We need to implement IExtendPropertySheet2 methods and
  186. //return S_OK to allow extension snap-ins to extend result item
  187. //by adding their own property pages
  188. HRESULT CComponent::CreatePropertyPages(
  189. /* [in] */ LPPROPERTYSHEETCALLBACK lpProvider,
  190. /* [in] */ LONG_PTR handle,
  191. /* [in] */ LPDATAOBJECT lpIDataObject)
  192. {
  193. return S_OK;
  194. }
  195. HRESULT CComponent::QueryPagesFor(
  196. /* [in] */ LPDATAOBJECT lpDataObject)
  197. {
  198. return S_OK;
  199. }
  200. HRESULT CComponent::GetWatermarks(
  201. /* [in] */ LPDATAOBJECT lpIDataObject,
  202. /* [out] */ HBITMAP __RPC_FAR *lphWatermark,
  203. /* [out] */ HBITMAP __RPC_FAR *lphHeader,
  204. /* [out] */ HPALETTE __RPC_FAR *lphPalette,
  205. /* [out] */ BOOL __RPC_FAR *bStretch)
  206. {
  207. return S_OK;
  208. }