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.

195 lines
5.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. 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. return hr;
  76. }
  77. STDMETHODIMP CComponent::Notify(
  78. /* [in] */ LPDATAOBJECT lpDataObject,
  79. /* [in] */ MMC_NOTIFY_TYPE event,
  80. /* [in] */ LPARAM arg,
  81. /* [in] */ LPARAM param)
  82. {
  83. MMCN_Crack(FALSE, lpDataObject, NULL, this, event, arg, param);
  84. return S_FALSE;
  85. }
  86. STDMETHODIMP CComponent::Destroy(
  87. /* [in] */ MMC_COOKIE cookie)
  88. {
  89. if (m_ipConsole) {
  90. m_ipConsole->Release();
  91. m_ipConsole = NULL;
  92. }
  93. return S_OK;
  94. }
  95. STDMETHODIMP CComponent::QueryDataObject(
  96. /* [in] */ MMC_COOKIE cookie,
  97. /* [in] */ DATA_OBJECT_TYPES type,
  98. /* [out] */ LPDATAOBJECT __RPC_FAR *ppDataObject)
  99. {
  100. CDataObject *pObj = NULL;
  101. if (cookie == 0)
  102. pObj = new CDataObject((MMC_COOKIE)m_pComponentData->m_pStaticNode, type);
  103. else
  104. pObj = new CDataObject(cookie, type);
  105. if (!pObj)
  106. return E_OUTOFMEMORY;
  107. pObj->QueryInterface(IID_IDataObject, (void **)ppDataObject);
  108. return S_OK;
  109. }
  110. STDMETHODIMP CComponent::GetResultViewType(
  111. /* [in] */ MMC_COOKIE cookie,
  112. /* [out] */ LPOLESTR __RPC_FAR *ppViewType,
  113. /* [out] */ long __RPC_FAR *pViewOptions)
  114. {
  115. CDelegationBase *base = (CDelegationBase *)cookie;
  116. //
  117. // Ask for default listview.
  118. //
  119. if (base == NULL)
  120. {
  121. *pViewOptions = MMC_VIEW_OPTIONS_NONE;
  122. *ppViewType = NULL;
  123. }
  124. else
  125. return base->GetResultViewType(ppViewType, pViewOptions);
  126. return S_OK;
  127. }
  128. STDMETHODIMP CComponent::GetDisplayInfo(
  129. /* [out][in] */ RESULTDATAITEM __RPC_FAR *pResultDataItem)
  130. {
  131. HRESULT hr = S_OK;
  132. CDelegationBase *base = NULL;
  133. // if they are asking for the RDI_STR we have one of those to give
  134. if (pResultDataItem->lParam) {
  135. base = (CDelegationBase *)pResultDataItem->lParam;
  136. if (pResultDataItem->mask & RDI_STR) {
  137. LPCTSTR pszT = base->GetDisplayName(pResultDataItem->nCol);
  138. MAKE_WIDEPTR_FROMTSTR_ALLOC(pszW, pszT);
  139. pResultDataItem->str = pszW;
  140. }
  141. if (pResultDataItem->mask & RDI_IMAGE) {
  142. pResultDataItem->nImage = base->GetBitmapIndex();
  143. }
  144. }
  145. return hr;
  146. }
  147. STDMETHODIMP CComponent::CompareObjects(
  148. /* [in] */ LPDATAOBJECT lpDataObjectA,
  149. /* [in] */ LPDATAOBJECT lpDataObjectB)
  150. {
  151. CDelegationBase *baseA = GetOurDataObject(lpDataObjectA)->GetBaseNodeObject();
  152. CDelegationBase *baseB = GetOurDataObject(lpDataObjectB)->GetBaseNodeObject();
  153. // compare the object pointers
  154. if (baseA->GetCookie() == baseB->GetCookie())
  155. return S_OK;
  156. return S_FALSE;
  157. }