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.

244 lines
6.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. #define ARRAYLEN(x) (sizeof(x) / sizeof((x)[0]))
  27. CComponent::CComponent(CComponentData *parent)
  28. : m_pComponentData(parent), m_cref(0), m_ipConsole(NULL)
  29. {
  30. OBJECT_CREATED
  31. m_ipDisplayHelp = NULL;
  32. m_ipControlBar = NULL;
  33. }
  34. CComponent::~CComponent()
  35. {
  36. OBJECT_DESTROYED
  37. }
  38. STDMETHODIMP CComponent::QueryInterface(REFIID riid, LPVOID *ppv)
  39. {
  40. if (!ppv)
  41. return E_FAIL;
  42. *ppv = NULL;
  43. if (IsEqualIID(riid, IID_IUnknown))
  44. *ppv = static_cast<IComponent *>(this);
  45. else if (IsEqualIID(riid, IID_IComponent))
  46. *ppv = static_cast<IComponent *>(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. hr = m_ipConsole->QueryInterface(IID_IDisplayHelp, (void **)&m_ipDisplayHelp);
  79. return hr;
  80. }
  81. STDMETHODIMP CComponent::Notify(
  82. /* [in] */ LPDATAOBJECT lpDataObject,
  83. /* [in] */ MMC_NOTIFY_TYPE event,
  84. /* [in] */ LPARAM arg,
  85. /* [in] */ LPARAM param)
  86. {
  87. MMCN_Crack(FALSE, lpDataObject, NULL, this, event, arg, param);
  88. HRESULT hr = S_FALSE;
  89. //Get our data object. If it is NULL, we return with S_FALSE.
  90. //See implementation of GetOurDataObject() to see how to
  91. //handle special data objects.
  92. CDataObject *pDataObject = GetOurDataObject(lpDataObject);
  93. if (NULL == pDataObject)
  94. return S_FALSE;
  95. CDelegationBase *base = pDataObject->GetBaseNodeObject();
  96. switch (event) {
  97. case MMCN_ADD_IMAGES:
  98. hr = base->AddImages((IImageList *)arg, (HSCOPEITEM)param);
  99. break;
  100. case MMCN_SELECT:
  101. hr = base->Select(m_ipConsole, (BOOL) LOWORD(arg), (BOOL) HIWORD(arg));
  102. break;
  103. case MMCN_SHOW:
  104. hr = base->Show(m_ipConsole, (BOOL)arg, (HSCOPEITEM)param);
  105. break;
  106. case MMCN_INITOCX:
  107. hr = base->InitOCX(reinterpret_cast<IUnknown *>(param));
  108. break;
  109. case MMCN_CONTEXTHELP:
  110. hr = base->ShowContextHelp(m_ipConsole, m_ipDisplayHelp, m_pComponentData->m_HelpFile);
  111. break;
  112. }
  113. return hr;
  114. }
  115. STDMETHODIMP CComponent::Destroy(
  116. /* [in] */ MMC_COOKIE cookie)
  117. {
  118. if (m_ipConsole) {
  119. m_ipConsole->Release();
  120. m_ipConsole = NULL;
  121. }
  122. if (m_ipDisplayHelp) {
  123. m_ipDisplayHelp->Release();
  124. m_ipDisplayHelp = NULL;
  125. }
  126. if (m_ipControlBar) {
  127. m_ipControlBar->Release();
  128. m_ipControlBar = NULL;
  129. }
  130. return S_OK;
  131. }
  132. STDMETHODIMP CComponent::QueryDataObject(
  133. /* [in] */ MMC_COOKIE cookie,
  134. /* [in] */ DATA_OBJECT_TYPES type,
  135. /* [out] */ LPDATAOBJECT __RPC_FAR *ppDataObject)
  136. {
  137. CDataObject *pObj = NULL;
  138. if (cookie == 0)
  139. pObj = new CDataObject((MMC_COOKIE)m_pComponentData->m_pStaticNode, type);
  140. else
  141. pObj = new CDataObject(cookie, type);
  142. if (!pObj)
  143. return E_OUTOFMEMORY;
  144. pObj->QueryInterface(IID_IDataObject, (void **)ppDataObject);
  145. return S_OK;
  146. }
  147. STDMETHODIMP CComponent::GetResultViewType(
  148. /* [in] */ MMC_COOKIE cookie,
  149. /* [out] */ LPOLESTR __RPC_FAR *ppViewType,
  150. /* [out] */ long __RPC_FAR *pViewOptions)
  151. {
  152. CDelegationBase *base = (CDelegationBase *)cookie;
  153. //
  154. // Ask for default listview.
  155. //
  156. if (base == NULL)
  157. {
  158. *pViewOptions = MMC_VIEW_OPTIONS_NONE;
  159. *ppViewType = NULL;
  160. }
  161. else
  162. return base->GetResultViewType(ppViewType, pViewOptions);
  163. return S_OK;
  164. }
  165. STDMETHODIMP CComponent::GetDisplayInfo(
  166. /* [out][in] */ RESULTDATAITEM __RPC_FAR *pResultDataItem)
  167. {
  168. HRESULT hr = S_OK;
  169. CDelegationBase *base = NULL;
  170. // if they are asking for the RDI_STR we have one of those to give
  171. if (pResultDataItem->lParam) {
  172. base = (CDelegationBase *)pResultDataItem->lParam;
  173. if (pResultDataItem->mask & RDI_STR) {
  174. LPCTSTR pszT = base->GetDisplayName(pResultDataItem->nCol);
  175. MAKE_WIDEPTR_FROMTSTR_ALLOC(pszW, pszT);
  176. pResultDataItem->str = pszW;
  177. }
  178. if (pResultDataItem->mask & RDI_IMAGE) {
  179. pResultDataItem->nImage = base->GetBitmapIndex();
  180. }
  181. }
  182. return hr;
  183. }
  184. STDMETHODIMP CComponent::CompareObjects(
  185. /* [in] */ LPDATAOBJECT lpDataObjectA,
  186. /* [in] */ LPDATAOBJECT lpDataObjectB)
  187. {
  188. CDelegationBase *baseA = GetOurDataObject(lpDataObjectA)->GetBaseNodeObject();
  189. CDelegationBase *baseB = GetOurDataObject(lpDataObjectB)->GetBaseNodeObject();
  190. // compare the object pointers
  191. if (baseA->GetCookie() == baseB->GetCookie())
  192. return S_OK;
  193. return S_FALSE;
  194. }