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.

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