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.

425 lines
12 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 "CompData.h"
  20. #include "Space.h"
  21. #include "DataObj.h"
  22. #include <commctrl.h> // Needed for button styles...
  23. #include <crtdbg.h>
  24. #include "globals.h"
  25. #include "resource.h"
  26. #include "DeleBase.h"
  27. #include "CompData.h"
  28. CComponent::CComponent(CComponentData *pParent)
  29. : m_pParent(pParent), m_cref(0), m_ipConsole(NULL), m_pLastNode(NULL)
  30. {
  31. OBJECT_CREATED
  32. }
  33. CComponent::~CComponent()
  34. {
  35. OBJECT_DESTROYED
  36. }
  37. STDMETHODIMP CComponent::QueryInterface(REFIID riid, LPVOID *ppv)
  38. {
  39. if (!ppv)
  40. return E_FAIL;
  41. *ppv = NULL;
  42. if (IsEqualIID(riid, IID_IUnknown))
  43. *ppv = static_cast<IComponent *>(this);
  44. else if (IsEqualIID(riid, IID_IComponent))
  45. *ppv = static_cast<IComponent *>(this);
  46. else if (IsEqualIID(riid, IID_IResultOwnerData))
  47. *ppv = static_cast<IResultOwnerData *>(this);
  48. if (*ppv)
  49. {
  50. reinterpret_cast<IUnknown *>(*ppv)->AddRef();
  51. return S_OK;
  52. }
  53. return E_NOINTERFACE;
  54. }
  55. STDMETHODIMP_(ULONG) CComponent::AddRef()
  56. {
  57. return InterlockedIncrement((LONG *)&m_cref);
  58. }
  59. STDMETHODIMP_(ULONG) CComponent::Release()
  60. {
  61. if (InterlockedDecrement((LONG *)&m_cref) == 0)
  62. {
  63. delete this;
  64. return 0;
  65. }
  66. return m_cref;
  67. }
  68. ///////////////////////////////
  69. // Interface IComponent
  70. ///////////////////////////////
  71. STDMETHODIMP CComponent::Initialize(
  72. /* [in] */ LPCONSOLE lpConsole)
  73. {
  74. HRESULT hr = S_OK;
  75. // Save away all the interfaces we'll need.
  76. // Fail if we can't QI the required interfaces.
  77. m_ipConsole = lpConsole;
  78. m_ipConsole->AddRef();
  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. //Return S_FALSE for any unhandled notifications. MMC then
  89. //performs a default operation for the particular notification
  90. HRESULT hr = S_FALSE;
  91. // MMCN_VIEW_CHANGE and MMCN_CUTORMOVE
  92. static CDelegationBase *pLastPasteQuery = NULL;
  93. if (MMCN_VIEW_CHANGE == event)
  94. {
  95. switch (param)
  96. {//arg holds the data. For a scope item, this is the
  97. //item's HSCOPEITEM. For a result item, this is
  98. //the item's nId value, but we don't use it
  99. //param holds the hint passed to IConsole::UpdateAllViews.
  100. //hint is a value of the UPDATE_VIEWS_HINT enumeration
  101. case UPDATE_SCOPEITEM:
  102. hr = m_ipConsole->SelectScopeItem( (HSCOPEITEM)arg );
  103. _ASSERT( S_OK == hr);
  104. break;
  105. case UPDATE_RESULTITEM:
  106. CDelegationBase *base = GetOurDataObject(lpDataObject)->GetBaseNodeObject();
  107. hr = base->OnUpdateItem(m_ipConsole, (long)arg, RESULT);
  108. break;
  109. }
  110. return S_OK;
  111. }
  112. if (MMCN_CUTORMOVE == event && pLastPasteQuery != NULL)
  113. {
  114. //arg contains the data object of the cut object
  115. //we get its CDelegationBase and then cast it
  116. //to its proper type.
  117. CDelegationBase *base = GetOurDataObject( (LPDATAOBJECT)arg )->GetBaseNodeObject();
  118. CRocket *pRocket = dynamic_cast<CRocket *>(base);
  119. if (NULL == pRocket)
  120. {// The cut item is a scope item. Delete it.
  121. CSpaceStation* pSpaceStn = dynamic_cast<CSpaceStation*>(base);
  122. if (NULL != pSpaceStn)
  123. {
  124. hr = pSpaceStn->OnDeleteScopeItem(m_pParent->GetConsoleNameSpace());
  125. return hr;
  126. }
  127. }
  128. //The cut item is a result item. Set its isDeleted member to TRUE.
  129. //This tells the source scope item that the object no longer
  130. //needs to be inserted in its result pane
  131. pRocket->setDeletedStatus(TRUE);
  132. //Update the source scope item in all views. We need
  133. //a dummy data object for UpdateAllViews.
  134. //pLastPasteQuery is the lpDataObject of the source scope item
  135. //See MMCN_SHOW below
  136. IDataObject *pDummy = NULL;
  137. hr = m_pParent->m_ipConsole->UpdateAllViews(pDummy, (long)(pLastPasteQuery->GetHandle()), UPDATE_SCOPEITEM);
  138. _ASSERT( S_OK == hr);
  139. return S_OK;
  140. }
  141. //Remaining notifications
  142. //Get our data object. If it is NULL, we return with S_FALSE.
  143. //See implementation of GetOurDataObject() to see how to
  144. //handle special data objects.
  145. CDataObject *pDataObject = GetOurDataObject(lpDataObject);
  146. if (NULL == pDataObject)
  147. return S_FALSE;
  148. CDelegationBase *base = pDataObject->GetBaseNodeObject();
  149. switch (event)
  150. {
  151. case MMCN_SHOW:
  152. if (arg)
  153. {//scope item selected
  154. OutputDebugString(_T("Changing selected scope node\n"));
  155. //We use this for drag-and-drop operations.
  156. pLastPasteQuery = base;
  157. }
  158. hr = base->OnShow(m_ipConsole, (BOOL)arg, (HSCOPEITEM)param);
  159. break;
  160. case MMCN_ADD_IMAGES:
  161. hr = base->OnAddImages((IImageList *)arg, (HSCOPEITEM)param);
  162. break;
  163. case MMCN_SELECT:
  164. hr = base->OnSelect(m_ipConsole, (BOOL)LOWORD(arg), (BOOL)HIWORD(arg));
  165. break;
  166. case MMCN_REFRESH:
  167. hr = base->OnRefresh(m_pParent->m_ipConsole);
  168. break;
  169. case MMCN_DELETE:
  170. //first delete the selected result item
  171. hr = base->OnDelete(m_ipConsole);
  172. //Now call IConsole::UpdateAllViews to redraw all views
  173. //owned by the parent scope item. OnRefresh already does
  174. //this for us, so use it.
  175. hr = base->OnRefresh(m_pParent->m_ipConsole);
  176. break;
  177. case MMCN_RENAME:
  178. hr = base->OnRename((LPOLESTR)param);
  179. //Now call IConsole::UpdateAllViews to redraw the item in all views.
  180. hr = m_pParent->m_ipConsole->UpdateAllViews(lpDataObject, 0, UPDATE_RESULTITEM);
  181. _ASSERT( S_OK == hr);
  182. break;
  183. case MMCN_QUERY_PASTE:
  184. {
  185. CDataObject *pPastedDO = GetOurDataObject((IDataObject *)arg);
  186. if (pPastedDO != NULL)
  187. {
  188. CDelegationBase *pasted = pPastedDO->GetBaseNodeObject();
  189. if (pasted != NULL)
  190. {
  191. hr = base->OnQueryPaste(pasted);
  192. }
  193. }
  194. }
  195. break;
  196. case MMCN_PASTE:
  197. {
  198. CDataObject *pPastedDO = GetOurDataObject((IDataObject *)arg);
  199. if (pPastedDO != NULL)
  200. {
  201. CDelegationBase *pasted = pPastedDO->GetBaseNodeObject();
  202. if (pasted != NULL)
  203. {
  204. hr = base->OnPaste(m_ipConsole, m_pParent, pasted);
  205. if (SUCCEEDED(hr))
  206. {
  207. // Determine if the item to be pasted is scope or result item.
  208. CRocket* pRocket = dynamic_cast<CRocket*>(pasted);
  209. BOOL bResult = pRocket ? TRUE : FALSE; // Rocket item is result item.
  210. CDataObject *pObj = new CDataObject((MMC_COOKIE)pasted, bResult ? CCT_RESULT : CCT_SCOPE);
  211. if (!pObj)
  212. return E_OUTOFMEMORY;
  213. pObj->QueryInterface(IID_IDataObject, (void **)param);
  214. //now update the destination scope item in all views.
  215. //But only do this if this is not a drag-and-drop
  216. //operation. That is, the destination scope item
  217. //is the currently selected one.
  218. if (pLastPasteQuery != NULL && pLastPasteQuery == base)
  219. {
  220. IDataObject *pDummy = NULL;
  221. hr = m_pParent->m_ipConsole->UpdateAllViews(pDummy,
  222. (long)(pLastPasteQuery->GetHandle()), UPDATE_SCOPEITEM);
  223. _ASSERT( S_OK == hr);
  224. }
  225. }
  226. }
  227. }
  228. }
  229. break;
  230. }
  231. return hr;
  232. }
  233. STDMETHODIMP CComponent::Destroy(
  234. /* [in] */ MMC_COOKIE cookie)
  235. {
  236. if (m_ipConsole)
  237. {
  238. m_ipConsole->Release();
  239. m_ipConsole = NULL;
  240. }
  241. return S_OK;
  242. }
  243. STDMETHODIMP CComponent::QueryDataObject(
  244. /* [in] */ MMC_COOKIE cookie,
  245. /* [in] */ DATA_OBJECT_TYPES type,
  246. /* [out] */ LPDATAOBJECT __RPC_FAR *ppDataObject)
  247. {
  248. CDataObject *pObj = NULL;
  249. CDelegationBase *pBase = NULL;
  250. if (IsBadReadPtr((void *)cookie, sizeof(CDelegationBase)))
  251. {
  252. if (NULL == m_pLastNode)
  253. return E_FAIL;
  254. pBase = m_pLastNode->GetChildPtr((int)cookie);
  255. }
  256. else
  257. {
  258. pBase = (cookie == 0) ? m_pParent->m_pStaticNode : (CDelegationBase *)cookie;
  259. }
  260. if (pBase == NULL)
  261. return E_FAIL;
  262. pObj = new CDataObject((MMC_COOKIE)pBase, type);
  263. if (!pObj)
  264. return E_OUTOFMEMORY;
  265. pObj->QueryInterface(IID_IDataObject, (void **)ppDataObject);
  266. return S_OK;
  267. }
  268. STDMETHODIMP CComponent::GetResultViewType(
  269. /* [in] */ MMC_COOKIE cookie,
  270. /* [out] */ LPOLESTR __RPC_FAR *ppViewType,
  271. /* [out] */ long __RPC_FAR *pViewOptions)
  272. {
  273. CDelegationBase *base = m_pLastNode = (CDelegationBase *)cookie;
  274. //
  275. // Ask for default listview.
  276. //
  277. if (base == NULL)
  278. {
  279. *pViewOptions = MMC_VIEW_OPTIONS_NONE;
  280. *ppViewType = NULL;
  281. }
  282. else
  283. return base->GetResultViewType(ppViewType, pViewOptions);
  284. return S_OK;
  285. }
  286. STDMETHODIMP CComponent::GetDisplayInfo(
  287. /* [out][in] */ RESULTDATAITEM __RPC_FAR *pResultDataItem)
  288. {
  289. HRESULT hr = S_OK;
  290. CDelegationBase *base = NULL;
  291. // if they are asking for the RDI_STR we have one of those to give
  292. if (pResultDataItem->lParam)
  293. {
  294. base = (CDelegationBase *)pResultDataItem->lParam;
  295. if (pResultDataItem->mask & RDI_STR)
  296. {
  297. LPCTSTR pszT = base->GetDisplayName(pResultDataItem->nCol);
  298. MAKE_WIDEPTR_FROMTSTR_ALLOC(pszW, pszT);
  299. pResultDataItem->str = pszW;
  300. }
  301. if (pResultDataItem->mask & RDI_IMAGE)
  302. {
  303. pResultDataItem->nImage = base->GetBitmapIndex();
  304. }
  305. }
  306. else
  307. {
  308. m_pLastNode->GetChildColumnInfo(pResultDataItem);
  309. }
  310. return hr;
  311. }
  312. STDMETHODIMP CComponent::CompareObjects(
  313. /* [in] */ LPDATAOBJECT lpDataObjectA,
  314. /* [in] */ LPDATAOBJECT lpDataObjectB)
  315. {
  316. CDelegationBase *baseA = GetOurDataObject(lpDataObjectA)->GetBaseNodeObject();
  317. CDelegationBase *baseB = GetOurDataObject(lpDataObjectB)->GetBaseNodeObject();
  318. // compare the object pointers
  319. if (baseA->GetCookie() == baseB->GetCookie())
  320. return S_OK;
  321. return S_FALSE;
  322. }
  323. ///////////////////////////////
  324. // Interface IComponent
  325. ///////////////////////////////
  326. STDMETHODIMP CComponent::FindItem(
  327. /* [in] */ LPRESULTFINDINFO pFindInfo,
  328. /* [out] */ int __RPC_FAR *pnFoundIndex)
  329. {
  330. return E_NOTIMPL;
  331. }
  332. STDMETHODIMP CComponent::CacheHint(
  333. /* [in] */ int nStartIndex,
  334. /* [in] */ int nEndIndex)
  335. {
  336. return E_NOTIMPL;
  337. }
  338. STDMETHODIMP CComponent::SortItems(
  339. /* [in] */ int nColumn,
  340. /* [in] */ DWORD dwSortOptions,
  341. /* [in] */ LPARAM lUserParam)
  342. {
  343. return E_NOTIMPL;
  344. }