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.

250 lines
7.0 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. else if (IsEqualIID(riid, IID_IExtendContextMenu))
  45. *ppv = static_cast<IExtendContextMenu *>(this);
  46. if (*ppv)
  47. {
  48. reinterpret_cast<IUnknown *>(*ppv)->AddRef();
  49. return S_OK;
  50. }
  51. return E_NOINTERFACE;
  52. }
  53. STDMETHODIMP_(ULONG) CComponent::AddRef()
  54. {
  55. return InterlockedIncrement((LONG *)&m_cref);
  56. }
  57. STDMETHODIMP_(ULONG) CComponent::Release()
  58. {
  59. if (InterlockedDecrement((LONG *)&m_cref) == 0)
  60. {
  61. delete this;
  62. return 0;
  63. }
  64. return m_cref;
  65. }
  66. ///////////////////////////////
  67. // Interface IComponent
  68. ///////////////////////////////
  69. STDMETHODIMP CComponent::Initialize(
  70. /* [in] */ LPCONSOLE lpConsole)
  71. {
  72. HRESULT hr = S_OK;
  73. // Save away all the interfaces we'll need.
  74. // Fail if we can't QI the required interfaces.
  75. m_ipConsole = lpConsole;
  76. m_ipConsole->AddRef();
  77. hr = m_ipConsole->QueryInterface(IID_IDisplayHelp, (void **)&m_ipDisplayHelp);
  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_ADD_IMAGES:
  97. hr = base->OnAddImages((IImageList *)arg, (HSCOPEITEM)param);
  98. break;
  99. case MMCN_SHOW:
  100. hr = base->OnShow(m_ipConsole, (BOOL)arg, (HSCOPEITEM)param);
  101. break;
  102. case MMCN_CONTEXTHELP:
  103. hr = base->OnShowContextHelp(m_ipDisplayHelp, m_pComponentData->m_HelpFile);
  104. break;
  105. }
  106. return hr;
  107. }
  108. STDMETHODIMP CComponent::Destroy(
  109. /* [in] */ MMC_COOKIE cookie)
  110. {
  111. if (m_ipConsole) {
  112. m_ipConsole->Release();
  113. m_ipConsole = NULL;
  114. }
  115. if (m_ipDisplayHelp) {
  116. m_ipDisplayHelp->Release();
  117. m_ipDisplayHelp = NULL;
  118. }
  119. return S_OK;
  120. }
  121. STDMETHODIMP CComponent::QueryDataObject(
  122. /* [in] */ MMC_COOKIE cookie,
  123. /* [in] */ DATA_OBJECT_TYPES type,
  124. /* [out] */ LPDATAOBJECT __RPC_FAR *ppDataObject)
  125. {
  126. CDataObject *pObj = NULL;
  127. if (cookie == 0)
  128. pObj = new CDataObject((MMC_COOKIE)m_pComponentData->m_pStaticNode, type);
  129. else
  130. pObj = new CDataObject(cookie, type);
  131. if (!pObj)
  132. return E_OUTOFMEMORY;
  133. pObj->QueryInterface(IID_IDataObject, (void **)ppDataObject);
  134. return S_OK;
  135. }
  136. STDMETHODIMP CComponent::GetResultViewType(
  137. /* [in] */ MMC_COOKIE cookie,
  138. /* [out] */ LPOLESTR __RPC_FAR *ppViewType,
  139. /* [out] */ long __RPC_FAR *pViewOptions)
  140. {
  141. CDelegationBase *base = (CDelegationBase *)cookie;
  142. //
  143. // Ask for default listview.
  144. //
  145. if (base == NULL)
  146. {
  147. *pViewOptions = MMC_VIEW_OPTIONS_NONE;
  148. *ppViewType = NULL;
  149. }
  150. else
  151. return base->GetResultViewType(ppViewType, pViewOptions);
  152. return S_OK;
  153. }
  154. STDMETHODIMP CComponent::GetDisplayInfo(
  155. /* [out][in] */ RESULTDATAITEM __RPC_FAR *pResultDataItem)
  156. {
  157. HRESULT hr = S_OK;
  158. CDelegationBase *base = NULL;
  159. // if they are asking for the RDI_STR we have one of those to give
  160. if (pResultDataItem->lParam) {
  161. base = (CDelegationBase *)pResultDataItem->lParam;
  162. if (pResultDataItem->mask & RDI_STR) {
  163. LPCTSTR pszT = base->GetDisplayName(pResultDataItem->nCol);
  164. MAKE_WIDEPTR_FROMTSTR_ALLOC(pszW, pszT);
  165. pResultDataItem->str = pszW;
  166. }
  167. if (pResultDataItem->mask & RDI_IMAGE) {
  168. pResultDataItem->nImage = base->GetBitmapIndex();
  169. }
  170. }
  171. return hr;
  172. }
  173. STDMETHODIMP CComponent::CompareObjects(
  174. /* [in] */ LPDATAOBJECT lpDataObjectA,
  175. /* [in] */ LPDATAOBJECT lpDataObjectB)
  176. {
  177. CDelegationBase *baseA = GetOurDataObject(lpDataObjectA)->GetBaseNodeObject();
  178. CDelegationBase *baseB = GetOurDataObject(lpDataObjectB)->GetBaseNodeObject();
  179. // compare the object pointers
  180. if (baseA->GetCookie() == baseB->GetCookie())
  181. return S_OK;
  182. return S_FALSE;
  183. }
  184. ///////////////////////////////
  185. // Interface IExtendContextMenu
  186. ///////////////////////////////
  187. HRESULT CComponent::AddMenuItems(
  188. /* [in] */ LPDATAOBJECT piDataObject,
  189. /* [in] */ LPCONTEXTMENUCALLBACK piCallback,
  190. /* [out][in] */ long __RPC_FAR *pInsertionAllowed)
  191. {
  192. CDelegationBase *base = GetOurDataObject(piDataObject)->GetBaseNodeObject();
  193. return base->OnAddMenuItems(piCallback, pInsertionAllowed);
  194. }
  195. HRESULT CComponent::Command(
  196. /* [in] */ long lCommandID,
  197. /* [in] */ LPDATAOBJECT piDataObject)
  198. {
  199. CDelegationBase *base = GetOurDataObject(piDataObject)->GetBaseNodeObject();
  200. return base->OnMenuCommand(m_ipConsole, lCommandID);
  201. }