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.

266 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_pLastNode(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_IResultOwnerData))
  45. *ppv = static_cast<IResultOwnerData *>(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. return hr;
  78. }
  79. STDMETHODIMP CComponent::Notify(
  80. /* [in] */ LPDATAOBJECT lpDataObject,
  81. /* [in] */ MMC_NOTIFY_TYPE event,
  82. /* [in] */ LPARAM arg,
  83. /* [in] */ LPARAM param)
  84. {
  85. MMCN_Crack(FALSE, lpDataObject, NULL, this, event, arg, param);
  86. HRESULT hr = S_FALSE;
  87. //Get our data object. If it is NULL, we return with S_FALSE.
  88. //See implementation of GetOurDataObject() to see how to
  89. //handle special data objects.
  90. CDataObject *pDataObject = GetOurDataObject(lpDataObject);
  91. if (NULL == pDataObject)
  92. return S_FALSE;
  93. CDelegationBase *base = pDataObject->GetBaseNodeObject();
  94. switch (event) {
  95. case MMCN_SHOW:
  96. hr = base->OnShow(m_ipConsole, (BOOL)arg, (HSCOPEITEM)param);
  97. break;
  98. case MMCN_ADD_IMAGES:
  99. hr = base->OnAddImages((IImageList *)arg, (HSCOPEITEM)param);
  100. break;
  101. case MMCN_SELECT:
  102. hr = base->OnSelect(m_ipConsole, (BOOL)LOWORD(arg), (BOOL)HIWORD(arg));
  103. break;
  104. case MMCN_RENAME:
  105. hr = base->OnRename((LPOLESTR)param);
  106. break;
  107. case MMCN_REFRESH:
  108. hr = base->OnRefresh();
  109. break;
  110. }
  111. return hr;
  112. }
  113. STDMETHODIMP CComponent::Destroy(
  114. /* [in] */ MMC_COOKIE cookie)
  115. {
  116. if (m_ipConsole) {
  117. m_ipConsole->Release();
  118. m_ipConsole = NULL;
  119. }
  120. return S_OK;
  121. }
  122. STDMETHODIMP CComponent::QueryDataObject(
  123. /* [in] */ MMC_COOKIE cookie,
  124. /* [in] */ DATA_OBJECT_TYPES type,
  125. /* [out] */ LPDATAOBJECT __RPC_FAR *ppDataObject)
  126. {
  127. CDataObject *pObj = NULL;
  128. CDelegationBase *pBase = NULL;
  129. if (IsBadReadPtr((void *)cookie, sizeof(CDelegationBase))) {
  130. if (NULL == m_pLastNode)
  131. return E_FAIL;
  132. pBase = m_pLastNode->GetChildPtr((int)cookie);
  133. } else {
  134. pBase = (cookie == 0) ? m_pComponentData->m_pStaticNode : (CDelegationBase *)cookie;
  135. }
  136. if (pBase == NULL)
  137. return E_FAIL;
  138. pObj = new CDataObject((MMC_COOKIE)pBase, type);
  139. if (!pObj)
  140. return E_OUTOFMEMORY;
  141. pObj->QueryInterface(IID_IDataObject, (void **)ppDataObject);
  142. return S_OK;
  143. }
  144. STDMETHODIMP CComponent::GetResultViewType(
  145. /* [in] */ MMC_COOKIE cookie,
  146. /* [out] */ LPOLESTR __RPC_FAR *ppViewType,
  147. /* [out] */ long __RPC_FAR *pViewOptions)
  148. {
  149. CDelegationBase *base = m_pLastNode = (CDelegationBase *)cookie;
  150. //
  151. // Ask for default listview.
  152. //
  153. if (base == NULL)
  154. {
  155. *pViewOptions = MMC_VIEW_OPTIONS_NONE;
  156. *ppViewType = NULL;
  157. }
  158. else
  159. return base->GetResultViewType(ppViewType, pViewOptions);
  160. return S_OK;
  161. }
  162. STDMETHODIMP CComponent::GetDisplayInfo(
  163. /* [out][in] */ RESULTDATAITEM __RPC_FAR *pResultDataItem)
  164. {
  165. HRESULT hr = S_OK;
  166. CDelegationBase *base = NULL;
  167. // if they are asking for the RDI_STR we have one of those to give
  168. if (pResultDataItem->lParam) {
  169. base = (CDelegationBase *)pResultDataItem->lParam;
  170. if (pResultDataItem->mask & RDI_STR) {
  171. LPCTSTR pszT = base->GetDisplayName(pResultDataItem->nCol);
  172. MAKE_WIDEPTR_FROMTSTR_ALLOC(pszW, pszT);
  173. pResultDataItem->str = pszW;
  174. }
  175. if (pResultDataItem->mask & RDI_IMAGE) {
  176. pResultDataItem->nImage = base->GetBitmapIndex();
  177. }
  178. } else {
  179. m_pLastNode->GetChildColumnInfo(pResultDataItem);
  180. }
  181. return hr;
  182. }
  183. STDMETHODIMP CComponent::CompareObjects(
  184. /* [in] */ LPDATAOBJECT lpDataObjectA,
  185. /* [in] */ LPDATAOBJECT lpDataObjectB)
  186. {
  187. CDelegationBase *baseA = GetOurDataObject(lpDataObjectA)->GetBaseNodeObject();
  188. CDelegationBase *baseB = GetOurDataObject(lpDataObjectB)->GetBaseNodeObject();
  189. // compare the object pointers
  190. if (baseA->GetCookie() == baseB->GetCookie())
  191. return S_OK;
  192. return S_FALSE;
  193. }
  194. ///////////////////////////////
  195. // Interface IComponent
  196. ///////////////////////////////
  197. STDMETHODIMP CComponent::FindItem(
  198. /* [in] */ LPRESULTFINDINFO pFindInfo,
  199. /* [out] */ int __RPC_FAR *pnFoundIndex)
  200. {
  201. return E_NOTIMPL;
  202. }
  203. STDMETHODIMP CComponent::CacheHint(
  204. /* [in] */ int nStartIndex,
  205. /* [in] */ int nEndIndex)
  206. {
  207. return E_NOTIMPL;
  208. }
  209. STDMETHODIMP CComponent::SortItems(
  210. /* [in] */ int nColumn,
  211. /* [in] */ DWORD dwSortOptions,
  212. /* [in] */ LPARAM lUserParam)
  213. {
  214. return E_NOTIMPL;
  215. }