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.

484 lines
13 KiB

  1. #include "stdafx.h"
  2. #include "DomMigSI.h"
  3. #include "DomMigr.h"
  4. #include "Globals.h"
  5. #include "MultiSel.h"
  6. UINT CMultiSelectItemDataObject::s_cfMsObjTypes = 0; // MultiSelect clipformat
  7. UINT CMultiSelectItemDataObject::s_cfMsDataObjs = 0; // MultiSelect clipformat
  8. CMultiSelectItemDataObject::CMultiSelectItemDataObject()
  9. {
  10. m_objectDataArray.RemoveAll();
  11. m_ddStatusArray.RemoveAll();
  12. m_pParentItem = NULL;
  13. s_cfMsObjTypes = RegisterClipboardFormat(CCF_OBJECT_TYPES_IN_MULTI_SELECT);
  14. s_cfMsDataObjs = RegisterClipboardFormat(CCF_MULTI_SELECT_SNAPINS);
  15. m_bHasGroup = false;
  16. }
  17. CMultiSelectItemDataObject::~CMultiSelectItemDataObject()
  18. {
  19. for ( int i = 0; i < m_objectDataArray.GetSize(); i++ )
  20. {
  21. delete (CObjectData *)(m_objectDataArray[i]);
  22. }
  23. }
  24. DWORD CMultiSelectItemDataObject::GetItemCount()
  25. {
  26. return (DWORD)m_objectDataArray.GetSize();
  27. }
  28. HRESULT CMultiSelectItemDataObject::AddMultiSelectItem( CObjectData *pDataObject )
  29. {
  30. m_objectDataArray.Add(pDataObject);
  31. m_ddStatusArray.Add(DD_NONE);
  32. return S_OK;
  33. }
  34. void CMultiSelectItemDataObject::SetParentItem( CSnapInItem *pParentItem )
  35. {
  36. m_pParentItem = pParentItem;
  37. }
  38. CSnapInItem *CMultiSelectItemDataObject::GetParentItem()
  39. {
  40. return m_pParentItem;
  41. }
  42. void CMultiSelectItemDataObject::GetParentGuid(GUID *guid)
  43. {
  44. memcpy( guid, &m_parentGuid, sizeof( GUID ) );
  45. }
  46. void CMultiSelectItemDataObject::SetParentGuid(GUID *guid)
  47. {
  48. memcpy( &m_parentGuid, guid, sizeof( GUID ) );
  49. }
  50. CSnapInItem *CMultiSelectItemDataObject::GetSnapInItem(DWORD index)
  51. {
  52. if ( GetItemCount() <= index )
  53. return NULL;
  54. return ((CObjectData *)m_objectDataArray[index])->m_pItem;
  55. }
  56. BYTE CMultiSelectItemDataObject::GetDDStatus(DWORD index)
  57. {
  58. if ( GetItemCount() <= index )
  59. return DD_NONE;
  60. return m_ddStatusArray[index];
  61. }
  62. void CMultiSelectItemDataObject::SetDDStatus(DWORD index, BYTE status)
  63. {
  64. if ( GetItemCount() <= index )
  65. return;
  66. m_ddStatusArray[index] = status;
  67. }
  68. STDMETHODIMP CMultiSelectItemDataObject::GetDataHere(FORMATETC *pformatetc, STGMEDIUM *pmedium)
  69. {
  70. if (( pmedium == NULL ) || ( pformatetc == NULL ))
  71. return E_POINTER;
  72. pmedium->pUnkForRelease = NULL; // by OLE spec
  73. HRESULT hr = DV_E_TYMED;
  74. // Make sure the type medium is HGLOBAL
  75. if (pmedium->tymed == TYMED_HGLOBAL )
  76. {
  77. if ( s_cfMsObjTypes == pformatetc->cfFormat )
  78. {
  79. // Create the stream on the hGlobal passed in
  80. CComPtr<IStream> spStream;
  81. hr = CreateStreamOnHGlobal(pmedium->hGlobal, FALSE, &spStream);
  82. if (SUCCEEDED(hr))
  83. {
  84. hr = DV_E_CLIPFORMAT;
  85. if (pformatetc->cfFormat == s_cfMsObjTypes)
  86. {
  87. DWORD objCount = (DWORD)m_objectDataArray.GetSize();
  88. spStream->Write( &objCount, sizeof(DWORD), NULL );
  89. for ( DWORD i = 0; i < objCount; i++ )
  90. {
  91. CSnapInItem* pItem;
  92. pItem = (CSnapInItem*)((CObjectData*)m_objectDataArray[i])->m_pItem;
  93. pItem->FillData( pItem->m_CCF_NODETYPE, spStream);
  94. }
  95. }
  96. }
  97. }
  98. }
  99. return hr;
  100. }
  101. STDMETHODIMP CMultiSelectItemDataObject::GetData
  102. (
  103. FORMATETC *pformatetc, // [in] Pointer to the FORMATETC structure
  104. STGMEDIUM *pmedium // [out] Pointer to the STGMEDIUM structure
  105. )
  106. {
  107. HRESULT hr = DATA_E_FORMATETC;
  108. if (( pmedium == NULL ) || ( pformatetc == NULL ))
  109. return E_POINTER;
  110. if( s_cfMsObjTypes == pformatetc->cfFormat )
  111. {
  112. HGLOBAL hMem = NULL;
  113. DWORD objCount = GetItemCount();
  114. ATLTRACE( L"CMultiSelectItemDataObject::GetData - asked for MultiSelect Object \n" );
  115. hMem = ::GlobalAlloc(GMEM_SHARE | GMEM_MOVEABLE, sizeof(GUID)*objCount + sizeof(DWORD));
  116. if( NULL == hMem )
  117. hr = STG_E_MEDIUMFULL;
  118. else
  119. {
  120. CComPtr<IStream> spStream;
  121. hr = CreateStreamOnHGlobal(hMem, FALSE, &spStream);
  122. if (SUCCEEDED(hr))
  123. {
  124. spStream->Write( &objCount, sizeof(DWORD), NULL );
  125. for ( DWORD i = 0; i < objCount; i++ )
  126. {
  127. CSnapInItem* pItem;
  128. pItem = (CSnapInItem*)((CObjectData*)m_objectDataArray[i])->m_pItem;
  129. pItem->FillData( pItem->m_CCF_NODETYPE, spStream);
  130. }
  131. pmedium->hGlobal = hMem; // StgMedium variables
  132. pmedium->tymed = TYMED_HGLOBAL;
  133. pmedium->pUnkForRelease = NULL;
  134. }
  135. }
  136. }
  137. ATLTRACE( L"CMultiSelectItemDataObject::GetData returned 0x%X \n", hr );
  138. return hr;
  139. } // end GetData()
  140. STDMETHODIMP CMultiSelectItemDataObject::QueryGetData(FORMATETC *pformatetc)
  141. {
  142. HRESULT hr = S_FALSE;
  143. if ( pformatetc == NULL )
  144. return E_POINTER;
  145. if( (0 != s_cfMsObjTypes) && (s_cfMsObjTypes == pformatetc->cfFormat) )
  146. {
  147. hr = S_OK;
  148. }
  149. ATLTRACE( L"CMultiSelectItemDataObject::QueryGetData() called with ClipFormat 0x%X \n", pformatetc->cfFormat );
  150. return hr;
  151. }
  152. HRESULT CMultiSelectItemDataObject::OnNotify(CDomMigratorComponent *pComponent, MMC_NOTIFY_TYPE event, long arg, long param )
  153. {
  154. HRESULT hr = E_NOTIMPL;
  155. DWORD objCount = (DWORD)m_objectDataArray.GetSize();
  156. CComPtr<IConsole> spConsole;
  157. if ( 0 == objCount )
  158. return hr;
  159. if ( pComponent == NULL )
  160. return E_POINTER;
  161. spConsole = ((CDomMigratorComponent*)pComponent)->m_spConsole;
  162. switch (event)
  163. {
  164. case MMCN_SELECT:
  165. {
  166. bool bSelect = (HIWORD(arg) != 0 );
  167. if ( bSelect )
  168. {
  169. hr = OnSelect(spConsole);
  170. }
  171. break;
  172. }
  173. case MMCN_DELETE:
  174. //hr = OnDelete(spConsole);
  175. break;
  176. case MMCN_CUTORMOVE:
  177. hr = OnCutOrMove(spConsole);
  178. break;
  179. default:
  180. break;
  181. }
  182. return hr;
  183. }
  184. HRESULT CMultiSelectItemDataObject::OnCutOrMove( IConsole* pConsole )
  185. {
  186. HRESULT hr = S_OK;//E_NOTIMPL;
  187. DWORD objCount = (DWORD)m_objectDataArray.GetSize();
  188. if ( 0 == objCount )
  189. goto ret_exit;
  190. if ( pConsole == NULL )
  191. return E_POINTER;
  192. GUID itemParentGuid;
  193. GetParentGuid( &itemParentGuid );
  194. ret_exit:
  195. return hr;
  196. }
  197. HRESULT CMultiSelectItemDataObject::OnSelect(IConsole *pConsole)
  198. {
  199. HRESULT hr = S_OK;//E_NOTIMPL;
  200. DWORD objCount = (DWORD)m_objectDataArray.GetSize();
  201. if ( 0 == objCount )
  202. goto ret_exit;
  203. if ( pConsole == NULL )
  204. return E_POINTER;
  205. GUID itemParentGuid;
  206. GetParentGuid( &itemParentGuid );
  207. hr = OnSelectAllowDragDrop( pConsole );
  208. ret_exit:
  209. return hr;
  210. }
  211. HRESULT CMultiSelectItemDataObject::OnSelectAllowDragDrop(IConsole *pConsole)
  212. {
  213. HRESULT hr = S_OK;
  214. CComPtr<IConsoleVerb> pConsoleVerb;
  215. if ( pConsole == NULL )
  216. return E_POINTER;
  217. hr = pConsole->QueryConsoleVerb( &pConsoleVerb );
  218. if ( FAILED( hr ) )
  219. goto ret_exit;
  220. //
  221. // Enable the delete verb.
  222. //
  223. hr = pConsoleVerb->SetVerbState( MMC_VERB_DELETE, ENABLED, TRUE );
  224. if ( FAILED( hr ) )
  225. goto ret_exit;
  226. hr = pConsoleVerb->SetVerbState( MMC_VERB_DELETE, HIDDEN, TRUE );
  227. if ( FAILED( hr ) )
  228. goto ret_exit;
  229. //
  230. // Enable the copy verb.
  231. //
  232. hr = pConsoleVerb->SetVerbState( MMC_VERB_COPY, ENABLED, TRUE );
  233. if ( FAILED( hr ) )
  234. goto ret_exit;
  235. hr = pConsoleVerb->SetVerbState( MMC_VERB_COPY, HIDDEN, TRUE );
  236. if ( FAILED( hr ) )
  237. goto ret_exit;
  238. ret_exit:
  239. return hr;
  240. }
  241. SMMCDataObjects *CMultiSelectItemDataObject::ExtractMSDataObjects( LPDATAOBJECT lpDataObject )
  242. {
  243. HRESULT hr = S_OK;
  244. SMMCDataObjects *p = NULL;
  245. STGMEDIUM stgmedium = { TYMED_HGLOBAL, NULL };
  246. FORMATETC formatetc = { (CLIPFORMAT)s_cfMsDataObjs, NULL,
  247. DVASPECT_CONTENT, -1, TYMED_HGLOBAL
  248. };
  249. hr = lpDataObject->GetData(&formatetc, &stgmedium);
  250. if (FAILED(hr))
  251. goto ret_exit;
  252. p = reinterpret_cast<SMMCDataObjects*>(stgmedium.hGlobal);
  253. //ReleaseStgMedium(&stgmedium);
  254. ret_exit:
  255. return p;
  256. }
  257. HRESULT CMultiSelectItemDataObject::Command(long lCommandID,
  258. CSnapInObjectRootBase* pObj,
  259. DATA_OBJECT_TYPES type)
  260. {
  261. bool bHandled = false;
  262. return ProcessCommand(lCommandID, bHandled, pObj, type);
  263. }
  264. HRESULT CMultiSelectItemDataObject::AddMenuItems(LPCONTEXTMENUCALLBACK piCallback,
  265. long *pInsertionAllowed,
  266. DATA_OBJECT_TYPES type)
  267. {
  268. if ( m_bHasGroup )
  269. return S_OK;
  270. if ( piCallback == NULL )
  271. return E_POINTER;
  272. //ATLTRACE2(atlTraceSnapin, 0, _T("CSnapInItemImpl::AddMenuItems\n"));
  273. //T* pT = static_cast<T*>(this);
  274. bool bIsExtension = false;
  275. if (!bIsExtension)
  276. /*pT->*/SetMenuInsertionFlags(true, pInsertionAllowed);
  277. UINT menuID = /*pT->*/GetMenuID();
  278. if (menuID == 0)
  279. return S_OK;
  280. HMENU hMenu = LoadMenu(_Module.GetResourceInstance(), MAKEINTRESOURCE(menuID));
  281. long insertionID;
  282. if (hMenu)
  283. {
  284. for (int i = 0; 1; i++)
  285. {
  286. HMENU hSubMenu = GetSubMenu(hMenu, i);
  287. if (hSubMenu == NULL)
  288. break;
  289. MENUITEMINFO menuItemInfo;
  290. memset(&menuItemInfo, 0, sizeof(menuItemInfo));
  291. menuItemInfo.cbSize = sizeof(menuItemInfo);
  292. switch (i)
  293. {
  294. case 0:
  295. if (! (*pInsertionAllowed & CCM_INSERTIONALLOWED_TOP) )
  296. continue;
  297. insertionID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  298. break;
  299. case 1:
  300. if (! (*pInsertionAllowed & CCM_INSERTIONALLOWED_NEW) )
  301. continue;
  302. if (bIsExtension)
  303. insertionID = CCM_INSERTIONPOINTID_3RDPARTY_NEW;
  304. else
  305. insertionID = CCM_INSERTIONPOINTID_PRIMARY_NEW;
  306. break;
  307. case 2:;
  308. if (! (*pInsertionAllowed & CCM_INSERTIONALLOWED_TASK) )
  309. continue;
  310. if (bIsExtension)
  311. insertionID = CCM_INSERTIONPOINTID_3RDPARTY_TASK;
  312. else
  313. insertionID = CCM_INSERTIONPOINTID_PRIMARY_TASK;
  314. break;
  315. case 3:;
  316. if (! (*pInsertionAllowed & CCM_INSERTIONALLOWED_VIEW) )
  317. continue;
  318. insertionID = CCM_INSERTIONPOINTID_PRIMARY_VIEW;
  319. break;
  320. default:
  321. {
  322. insertionID = 0;
  323. continue;
  324. }
  325. break;
  326. }
  327. menuItemInfo.fMask = MIIM_TYPE | MIIM_STATE | MIIM_ID;
  328. menuItemInfo.fType = MFT_STRING;
  329. TCHAR szMenuText[128];
  330. for (int j = 0; 1; j++)
  331. {
  332. menuItemInfo.fMask = MIIM_TYPE | MIIM_STATE | MIIM_ID;
  333. menuItemInfo.fType = MFT_STRING;
  334. menuItemInfo.cch = 128;
  335. menuItemInfo.dwTypeData = szMenuText;
  336. TCHAR szStatusBar[256];
  337. if (!GetMenuItemInfo(hSubMenu, j, TRUE, &menuItemInfo))
  338. break;
  339. if (menuItemInfo.fType != MFT_STRING)
  340. continue;
  341. /*pT->*/UpdateMenuState(menuItemInfo.wID, szMenuText, &menuItemInfo.fState);
  342. LoadString(_Module.GetResourceInstance(), menuItemInfo.wID, szStatusBar, 256);
  343. OLECHAR wszStatusBar[256];
  344. OLECHAR wszMenuText[128];
  345. USES_CONVERSION;
  346. ocscpy(wszMenuText, T2OLE(szMenuText));
  347. ocscpy(wszStatusBar, T2OLE(szStatusBar));
  348. CONTEXTMENUITEM contextMenuItem;
  349. contextMenuItem.strName = wszMenuText;
  350. contextMenuItem.strStatusBarText = wszStatusBar;
  351. contextMenuItem.lCommandID = menuItemInfo.wID;
  352. contextMenuItem.lInsertionPointID = insertionID;
  353. contextMenuItem.fFlags = menuItemInfo.fState;
  354. contextMenuItem.fSpecialFlags = 0;
  355. HRESULT hr = piCallback->AddItem(&contextMenuItem);
  356. ATLASSERT(SUCCEEDED(hr));
  357. }
  358. }
  359. DestroyMenu(hMenu);
  360. }
  361. if (!bIsExtension)
  362. /*pT->*/SetMenuInsertionFlags(true, pInsertionAllowed);
  363. return S_OK;
  364. }
  365. HRESULT CMultiSelectItemDataObject::OnVersionInfo(bool &bHandled, CSnapInObjectRootBase* pObj)
  366. {
  367. HRESULT hr=S_OK;
  368. /* CVersionInfoDlg dlg;
  369. dlg.DoModal();
  370. */ hr = S_OK;
  371. return hr;
  372. }
  373. HRESULT CMultiSelectItemDataObject::OnMoveMultipleObjs(bool &bHandled, CSnapInObjectRootBase* pObj)
  374. {
  375. HRESULT hr = S_OK;
  376. CComPtr<IConsole> pConsole;
  377. hr = GetConsoleFromCSnapInObjectRootBase(pObj, &pConsole);
  378. if (FAILED(hr))
  379. return hr;
  380. return hr;
  381. }