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.

328 lines
9.4 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_ipConsole2(NULL),
  28. m_bTaskpadView(FALSE), m_bIsTaskpadPreferred(FALSE)
  29. {
  30. OBJECT_CREATED
  31. }
  32. CComponent::~CComponent()
  33. {
  34. OBJECT_DESTROYED
  35. }
  36. STDMETHODIMP CComponent::QueryInterface(REFIID riid, LPVOID *ppv)
  37. {
  38. if (!ppv)
  39. return E_FAIL;
  40. *ppv = NULL;
  41. if (IsEqualIID(riid, IID_IUnknown))
  42. *ppv = static_cast<IComponent *>(this);
  43. else if (IsEqualIID(riid, IID_IComponent))
  44. *ppv = static_cast<IComponent *>(this);
  45. else if (IsEqualIID(riid, IID_IExtendTaskPad))
  46. *ppv = static_cast<IExtendTaskPad *>(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_IConsole2,
  79. reinterpret_cast<void**>(&m_ipConsole2));
  80. _ASSERT( NULL != m_ipConsole2 );
  81. hr = m_ipConsole2->IsTaskpadViewPreferred();
  82. m_bIsTaskpadPreferred = (hr == S_OK) ? TRUE : FALSE;
  83. return hr;
  84. }
  85. STDMETHODIMP CComponent::Notify(
  86. /* [in] */ LPDATAOBJECT lpDataObject,
  87. /* [in] */ MMC_NOTIFY_TYPE event,
  88. /* [in] */ LPARAM arg,
  89. /* [in] */ LPARAM param)
  90. {
  91. MMCN_Crack(FALSE, lpDataObject, NULL, this, event, arg, param);
  92. HRESULT hr = S_FALSE;
  93. //Get our data object. If it is NULL, we return with S_FALSE.
  94. //See implementation of GetOurDataObject() to see how to
  95. //handle special data objects.
  96. CDataObject *pDataObject = GetOurDataObject(lpDataObject);
  97. if (NULL == pDataObject)
  98. return S_FALSE;
  99. CDelegationBase *base = pDataObject->GetBaseNodeObject();
  100. switch (event)
  101. {
  102. case MMCN_SHOW:
  103. hr = base->OnShow(m_ipConsole, (BOOL)arg, (HSCOPEITEM)param);
  104. break;
  105. case MMCN_ADD_IMAGES:
  106. hr = base->OnAddImages((IImageList *)arg, (HSCOPEITEM)param);
  107. break;
  108. case MMCN_SELECT:
  109. hr = base->OnSelect(m_ipConsole, (BOOL)LOWORD(arg), (BOOL)HIWORD(arg));
  110. break;
  111. case MMCN_RENAME:
  112. hr = base->OnRename((LPOLESTR)param);
  113. break;
  114. case MMCN_LISTPAD:
  115. hr = base->OnListpad(m_ipConsole, (BOOL)arg);
  116. break;
  117. }
  118. return hr;
  119. }
  120. STDMETHODIMP CComponent::Destroy(
  121. /* [in] */ MMC_COOKIE cookie)
  122. {
  123. if (m_ipConsole) {
  124. m_ipConsole->Release();
  125. m_ipConsole = NULL;
  126. }
  127. return S_OK;
  128. }
  129. STDMETHODIMP CComponent::QueryDataObject(
  130. /* [in] */ MMC_COOKIE cookie,
  131. /* [in] */ DATA_OBJECT_TYPES type,
  132. /* [out] */ LPDATAOBJECT __RPC_FAR *ppDataObject)
  133. {
  134. CDataObject *pObj = NULL;
  135. if (cookie == 0)
  136. pObj = new CDataObject((MMC_COOKIE)m_pComponentData->m_pStaticNode, type);
  137. else
  138. pObj = new CDataObject(cookie, 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 = (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. }
  179. return hr;
  180. }
  181. STDMETHODIMP CComponent::CompareObjects(
  182. /* [in] */ LPDATAOBJECT lpDataObjectA,
  183. /* [in] */ LPDATAOBJECT lpDataObjectB)
  184. {
  185. CDelegationBase *baseA = GetOurDataObject(lpDataObjectA)->GetBaseNodeObject();
  186. CDelegationBase *baseB = GetOurDataObject(lpDataObjectB)->GetBaseNodeObject();
  187. // compare the object pointers
  188. if (baseA->GetCookie() == baseB->GetCookie())
  189. return S_OK;
  190. return S_FALSE;
  191. }
  192. ///////////////////////////////
  193. // Interface IComponent
  194. ///////////////////////////////
  195. HRESULT CComponent::TaskNotify(
  196. /* [in] */ IDataObject __RPC_FAR *pdo,
  197. /* [in] */ VARIANT __RPC_FAR *arg,
  198. /* [in] */ VARIANT __RPC_FAR *param)
  199. {
  200. CDelegationBase *base = GetOurDataObject(pdo)->GetBaseNodeObject();
  201. return base->TaskNotify(m_ipConsole, arg, param);
  202. }
  203. HRESULT CComponent::EnumTasks(
  204. /* [in] */ IDataObject __RPC_FAR *pdo,
  205. /* [string][in] */ LPOLESTR szTaskGroup,
  206. /* [out] */ IEnumTASK __RPC_FAR *__RPC_FAR *ppEnumTASK)
  207. {
  208. CDelegationBase *base = GetOurDataObject(pdo)->GetBaseNodeObject();
  209. // GetTaskList will allocate the entire task structure, it's
  210. // up to the enumerator to free the list when destroyed
  211. LONG nCount;
  212. MMC_TASK *tasks = base->GetTaskList(szTaskGroup, &nCount);
  213. if (tasks != NULL) {
  214. CEnumTASK *pTask = new CEnumTASK(tasks, nCount);
  215. if (pTask) {
  216. reinterpret_cast<IUnknown *>(pTask)->AddRef();
  217. HRESULT hr = pTask->QueryInterface (IID_IEnumTASK, (void **)ppEnumTASK);
  218. reinterpret_cast<IUnknown *>(pTask)->Release();
  219. return hr;
  220. }
  221. }
  222. return S_OK;
  223. }
  224. HRESULT CComponent::GetTitle(
  225. /* [string][in] */ LPOLESTR pszGroup,
  226. /* [string][out] */ LPOLESTR __RPC_FAR *pszTitle)
  227. {
  228. CDelegationBase *base = (CDelegationBase *)wcstoul(pszGroup, NULL, 16);
  229. if (NULL == base)
  230. return S_FALSE;
  231. return base->GetTaskpadTitle(pszTitle);
  232. }
  233. HRESULT CComponent::GetDescriptiveText(
  234. /* [string][in] */ LPOLESTR pszGroup,
  235. /* [string][out] */ LPOLESTR __RPC_FAR *pszDescriptiveText)
  236. {
  237. CDelegationBase *base = (CDelegationBase *)wcstoul(pszGroup, NULL, 16);
  238. if (NULL == base)
  239. return S_FALSE;
  240. return base->GetTaskpadDescription(pszDescriptiveText);
  241. }
  242. HRESULT CComponent::GetBackground(
  243. /* [string][in] */ LPOLESTR pszGroup,
  244. /* [out] */ MMC_TASK_DISPLAY_OBJECT __RPC_FAR *pTDO)
  245. {
  246. CDelegationBase *base = (CDelegationBase *)wcstoul(pszGroup, NULL, 16);
  247. if (NULL == base)
  248. return S_FALSE;
  249. return base->GetTaskpadBackground(pTDO);
  250. }
  251. HRESULT CComponent::GetListPadInfo(
  252. /* [string][in] */ LPOLESTR pszGroup,
  253. /* [out] */ MMC_LISTPAD_INFO __RPC_FAR *lpListPadInfo)
  254. {
  255. CDelegationBase *base = (CDelegationBase *)wcstoul(pszGroup, NULL, 16);
  256. if (NULL == base)
  257. return S_FALSE;
  258. return base->GetListpadInfo(lpListPadInfo);
  259. }