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.

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