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.

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