Source code of Windows XP (NT5)
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.

1180 lines
28 KiB

  1. // ResultsPaneView.cpp : implementation file
  2. //
  3. // Copyright (c) 2000 Microsoft Corporation
  4. //
  5. // 03/30/00 v-marfin 59644 : GetUpperPaneSelectedCount(). Created to get the number of selected items so we can pass it
  6. // to the context menu so it knows whether to add the
  7. // third party menu item "TroubleShooting" which it should
  8. // only add if there is only 1 item selected.
  9. // 04/02/00 v-marfin 59643b On creation of new objects, show details page first.
  10. //
  11. //
  12. //
  13. #include "stdafx.h"
  14. #include "snapin.h"
  15. #include "ResultsPaneView.h"
  16. #include "ScopePane.h"
  17. #include "ResultsPane.h"
  18. #include "HealthmonResultsPane.h"
  19. #include "HMListView.h"
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CResultsPaneView
  27. IMPLEMENT_DYNCREATE(CResultsPaneView, CCmdTarget)
  28. CResultsPaneView::CResultsPaneView()
  29. {
  30. EnableAutomation();
  31. m_pOwnerScopeItem = NULL;
  32. }
  33. CResultsPaneView::~CResultsPaneView()
  34. {
  35. Destroy();
  36. }
  37. /////////////////////////////////////////////////////////////////////////////
  38. // Create/Destroy
  39. bool CResultsPaneView::Create(CScopePaneItem* pOwnerItem)
  40. {
  41. TRACEX(_T("CResultsPaneView::Create\n"));
  42. TRACEARGn(pOwnerItem);
  43. if( ! GfxCheckObjPtr(pOwnerItem,CScopePaneItem) )
  44. {
  45. TRACE(_T("FAILED : pOwnerItem is not a valid pointer.\n"));
  46. return false;
  47. }
  48. SetOwnerScopeItem(pOwnerItem);
  49. return true;
  50. }
  51. void CResultsPaneView::Destroy()
  52. {
  53. TRACEX(_T("CResultsPaneView::Destroy\n"));
  54. RemoveAllItems();
  55. m_pOwnerScopeItem = NULL;
  56. for( int i=0; i < m_Columns.GetSize(); i++ )
  57. {
  58. delete m_Columns[i];
  59. }
  60. m_Columns.RemoveAll();
  61. m_ResultsPanes.RemoveAll();
  62. }
  63. /////////////////////////////////////////////////////////////////////////////
  64. // Owner ScopeItem Members
  65. CScopePaneItem* CResultsPaneView::GetOwnerScopeItem()
  66. {
  67. TRACEX(_T("CResultsPaneView::GetOwnerScopeItem\n"));
  68. if( ! GfxCheckObjPtr(m_pOwnerScopeItem,CScopePaneItem) )
  69. {
  70. TRACE(_T("FAILED : m_pOwnerScopeItem is not a valid pointer.\n"));
  71. return NULL;
  72. }
  73. return m_pOwnerScopeItem;
  74. }
  75. void CResultsPaneView::SetOwnerScopeItem(CScopePaneItem* pOwnerItem)
  76. {
  77. TRACEX(_T("CResultsPaneView::SetOwnerScopeItem\n"));
  78. TRACEARGn(pOwnerItem);
  79. if( ! GfxCheckObjPtr(pOwnerItem,CScopePaneItem) )
  80. {
  81. TRACE(_T("FAILED : pOwnerItem is not a valid pointer.\n"));
  82. return;
  83. }
  84. m_pOwnerScopeItem = pOwnerItem;
  85. }
  86. /////////////////////////////////////////////////////////////////////////////
  87. // ListView Column Members
  88. int CResultsPaneView::GetColumnCount() const
  89. {
  90. TRACEX(_T("CResultsPaneView::GetColumnCount\n"));
  91. return (int)m_Columns.GetSize();
  92. }
  93. CListViewColumn* CResultsPaneView::GetColumn(int iIndex)
  94. {
  95. TRACEX(_T("CResultsPaneView::GetColumn\n"));
  96. TRACEARGn(iIndex);
  97. if( iIndex >= m_Columns.GetSize() || iIndex < 0 )
  98. {
  99. TRACE(_T("FAILED : iIndex is out of array bounds.\n"));
  100. return NULL;
  101. }
  102. return m_Columns[iIndex];
  103. }
  104. void CResultsPaneView::SetColumn(int iIndex, CListViewColumn* pColumn)
  105. {
  106. TRACEX(_T("CResultsPaneView::SetColumn\n"));
  107. TRACEARGn(iIndex);
  108. TRACEARGn(pColumn);
  109. if( iIndex >= m_Columns.GetSize() || iIndex < 0 )
  110. {
  111. TRACE(_T("FAILED : iIndex is out of array bounds.\n"));
  112. return;
  113. }
  114. if( ! GfxCheckObjPtr(pColumn,CListViewColumn) )
  115. {
  116. TRACE(_T("FAILED : pColumn is not a valid pointer.\n"));
  117. return;
  118. }
  119. m_Columns.SetAt(iIndex,pColumn);
  120. }
  121. int CResultsPaneView::AddColumn(CListViewColumn* pColumn)
  122. {
  123. TRACEX(_T("CResultsPaneView::AddColumn\n"));
  124. TRACEARGn(pColumn);
  125. if( ! GfxCheckObjPtr(pColumn,CListViewColumn) )
  126. {
  127. TRACE(_T("FAILED : pColumn is not a valid pointer.\n"));
  128. return -1;
  129. }
  130. return (int)m_Columns.Add(pColumn);
  131. }
  132. void CResultsPaneView::RemoveColumn(int iIndex)
  133. {
  134. TRACEX(_T("CResultsPaneView::RemoveColumn\n"));
  135. TRACEARGn(iIndex);
  136. if( iIndex >= m_Columns.GetSize() || iIndex < 0 )
  137. {
  138. TRACE(_T("FAILED : iIndex is out of array bounds.\n"));
  139. return;
  140. }
  141. delete m_Columns[iIndex];
  142. m_Columns.RemoveAt(iIndex);
  143. }
  144. /////////////////////////////////////////////////////////////////////////////
  145. // Results Pane Item Members
  146. int CResultsPaneView::GetItemCount() const
  147. {
  148. TRACEX(_T("CResultsPaneView::GetItemCount\n"));
  149. return (int)m_ResultItems.GetSize();
  150. }
  151. CResultsPaneItem* CResultsPaneView::GetItem(int iIndex)
  152. {
  153. TRACEX(_T("CResultsPaneView::GetItem\n"));
  154. TRACEARGn(iIndex);
  155. if( iIndex >= m_ResultItems.GetSize() || iIndex < 0 )
  156. {
  157. TRACE(_T("FAILED : iIndex is out of array bounds.\n"));
  158. return NULL;
  159. }
  160. if( ! GfxCheckObjPtr(m_ResultItems[iIndex],CResultsPaneItem) )
  161. {
  162. TRACE(_T("FAILED : item pointer at iIndex is invalid.\n"));
  163. return NULL;
  164. }
  165. return m_ResultItems[iIndex];
  166. }
  167. int CResultsPaneView::AddItem(CResultsPaneItem* pItem, bool bResizeColumn /*= false*/)
  168. {
  169. TRACEX(_T("CResultsPaneView::AddItem\n"));
  170. TRACEARGn(pItem);
  171. if( ! GfxCheckObjPtr(pItem,CResultsPaneItem) )
  172. {
  173. TRACE(_T("FAILED : pItem is not a valid pointer.\n"));
  174. return -1;
  175. }
  176. int iNewItemIndex = (int)m_ResultItems.Add(pItem);
  177. ASSERT(iNewItemIndex != -1);
  178. // for all result panes on this view, add the item into each pane
  179. for( int i = 0; i < m_ResultsPanes.GetSize(); i++ )
  180. {
  181. if( ! pItem->InsertItem(m_ResultsPanes[i],0, bResizeColumn) )
  182. {
  183. TRACE(_T("FAILED : CResultsPaneItem::InsertItem failed.\n"));
  184. ASSERT(FALSE);
  185. }
  186. }
  187. return iNewItemIndex;
  188. }
  189. void CResultsPaneView::RemoveItem(int iIndex)
  190. {
  191. TRACEX(_T("CResultsPaneView::RemoveItem\n"));
  192. TRACEARGn(iIndex);
  193. if( iIndex >= m_ResultItems.GetSize() || iIndex < 0 )
  194. {
  195. TRACE(_T("FAILED : iIndex is out of array bounds.\n"));
  196. return;
  197. }
  198. CResultsPaneItem* pItem = m_ResultItems[iIndex];
  199. if( ! GfxCheckObjPtr(pItem,CResultsPaneItem) )
  200. {
  201. TRACE(_T("FAILED : pItem is not a valid results pane item pointer.\n"));
  202. return;
  203. }
  204. // for each pane showing this results view, delete the item from it
  205. // this gets a little ugly...sorry
  206. for( int i=0; i < m_ResultsPanes.GetSize(); i++ )
  207. {
  208. if( GfxCheckObjPtr(m_ResultsPanes[i],CResultsPane) )
  209. {
  210. LPRESULTDATA lpResultData = m_ResultsPanes[i]->GetResultDataPtr();
  211. if( lpResultData )
  212. {
  213. HRESULTITEM hri = NULL;
  214. if( lpResultData->FindItemByLParam((LPARAM)pItem,&hri) == S_OK )
  215. {
  216. HRESULT hr = lpResultData->DeleteItem(hri,0);
  217. if( ! CHECKHRESULT(hr) )
  218. {
  219. TRACE(_T("FAILED : IResultData::DeleteItem failed.\n"));
  220. }
  221. }
  222. lpResultData->Release();
  223. }
  224. }
  225. }
  226. delete pItem;
  227. m_ResultItems.RemoveAt(iIndex);
  228. }
  229. void CResultsPaneView::RemoveItem(CResultsPaneItem* pItem)
  230. {
  231. TRACEX(_T("CResultsPaneView::RemoveItem\n"));
  232. TRACEARGn(pItem);
  233. if( ! GfxCheckObjPtr(pItem,CResultsPaneItem) )
  234. {
  235. TRACE(_T("FAILED : pItem is not a valid pointer.\n"));
  236. return;
  237. }
  238. for( int i = 0; i < m_ResultItems.GetSize(); i++ )
  239. {
  240. if( pItem == m_ResultItems[i] )
  241. {
  242. RemoveItem(i);
  243. return;
  244. }
  245. }
  246. }
  247. void CResultsPaneView::RemoveItem(const CString& sName)
  248. {
  249. TRACEX(_T("CResultsPaneView::RemoveItem\n"));
  250. if( sName.IsEmpty() )
  251. {
  252. TRACE(_T("FAILED : sName is empty.\n"));
  253. return;
  254. }
  255. for( int i = 0; i < m_ResultItems.GetSize(); i++ )
  256. {
  257. if( GfxCheckObjPtr(m_ResultItems[i],CResultsPaneItem) )
  258. {
  259. if( sName == m_ResultItems[i]->GetDisplayName() )
  260. {
  261. RemoveItem(i);
  262. return;
  263. }
  264. }
  265. }
  266. }
  267. int CResultsPaneView::FindItem(RPIFINDPROC pFindProc, LPARAM param)
  268. {
  269. TRACEX(_T("CResultsPaneView::FindItem\n"));
  270. TRACEARGn(pFindProc);
  271. TRACEARGn(param);
  272. if( ! GfxCheckPtr(pFindProc,RPIFINDPROC) )
  273. {
  274. TRACE(_T("FAILED : pFindProc is not a valid function pointer.\n"));
  275. return -1;
  276. }
  277. return pFindProc(m_ResultItems,param);
  278. }
  279. bool CResultsPaneView::UpdateItem(CResultsPaneItem* pItem)
  280. {
  281. TRACEX(_T("CResultsPaneView::UpdateItem\n"));
  282. TRACEARGn(pItem);
  283. if( ! GfxCheckObjPtr(pItem,CResultsPaneItem) )
  284. {
  285. TRACE(_T("FAILED : pItem is not a valid pointer.\n"));
  286. return false;
  287. }
  288. HRESULT hr = S_OK;
  289. for( int i=0; i < m_ResultsPanes.GetSize(); i++ )
  290. {
  291. hr = pItem->SetItem(m_ResultsPanes[i]);
  292. if( hr == S_FALSE || ! CHECKHRESULT(hr) )
  293. {
  294. TRACE(_T("FAILED : CResultsPaneItem::SetItem failed.\n"));
  295. }
  296. }
  297. return true;
  298. }
  299. void CResultsPaneView::UpdateAllItems()
  300. {
  301. TRACEX(_T("CResultsPaneView::UpdateAllItems\n"));
  302. for( int i = 0; i < m_ResultItems.GetSize(); i++ )
  303. {
  304. if( ! UpdateItem(m_ResultItems[i]) )
  305. {
  306. TRACE(_T("FAILED : CResultsPaneView::UpdateItem failed.\n"));
  307. }
  308. }
  309. }
  310. void CResultsPaneView::RemoveAllItems()
  311. {
  312. TRACEX(_T("CResultsPaneView::RemoveAllItems\n"));
  313. for( int i = (int)m_ResultItems.GetSize()-1; i >=0 ; i-- )
  314. {
  315. RemoveItem(i);
  316. }
  317. }
  318. bool CResultsPaneView::GetSelectedItems(ResultsPaneItemArray& rpiaSelectedItems)
  319. {
  320. TRACEX(_T("CResultsPaneView::GetSelectedItems\n"));
  321. TRACEARGn(rpiaSelectedItems.GetSize());
  322. return true;
  323. }
  324. int CResultsPaneView::GetUpperPaneSelectedCount()
  325. {
  326. TRACEX(_T("CResultsPaneView::GetUpperPaneSelectedCount\n"));
  327. // v-marfin 59644 : Get the number of selected items so we can pass it
  328. // to the context menu so it knows whether to add the
  329. // third party menu item "TroubleShooting" which it should
  330. // only add if there is only 1 item selected.
  331. if (m_ResultsPanes.GetSize() < 1)
  332. {
  333. TRACE(_T("ERROR: CResultsPaneView::GetUpperPaneSelectedCount(): no results panes defined.\n"));
  334. return 0;
  335. }
  336. CHealthmonResultsPane* pPane = (CHealthmonResultsPane*)m_ResultsPanes[0];
  337. if (!pPane)
  338. {
  339. TRACE(_T("ERROR: CResultsPaneView::GetUpperPaneSelectedCount() : Could not fetch CHealthmonResultsPane\n"));
  340. return 0;
  341. }
  342. _DHMListView* pList = pPane->GetUpperListCtrl();
  343. if (!pList)
  344. {
  345. TRACE(_T("ERROR: CResultsPaneView::GetUpperPaneSelectedCount() : Could not fetch upper list control\n"));
  346. return 0;
  347. }
  348. int nSelectedCount = pList->GetSelectedCount();
  349. return nSelectedCount;
  350. }
  351. /////////////////////////////////////////////////////////////////////////////
  352. // Property Page Members
  353. bool CResultsPaneView::IsPropertySheetOpen()
  354. {
  355. TRACEX(_T("CResultsPaneView::IsPropertySheetOpen\n"));
  356. // this function attempts to bring up an open property sheet for each result item
  357. // if it succeeds, then the property sheet is brought to the foreground
  358. // if it fails, then there are no open property sheets for the results view
  359. if( ! GetOwnerScopeItem() || ! GetOwnerScopeItem()->GetScopePane() )
  360. {
  361. TRACE(_T("FAILED : Owner scope item is not a valid object.\n"));
  362. return false;
  363. }
  364. LPCONSOLE2 lpConsole = GetOwnerScopeItem()->GetScopePane()->GetConsolePtr();
  365. if( ! GfxCheckPtr(lpConsole,IConsole2) )
  366. {
  367. TRACE(_T("FAILED : lpConsole is not a valid pointer.\n"));
  368. return false;
  369. }
  370. // get a reference to the IPropertySheetProvider interface
  371. LPPROPERTYSHEETPROVIDER lpProvider = NULL;
  372. HRESULT hr = lpConsole->QueryInterface(IID_IPropertySheetProvider,(LPVOID*)&lpProvider);
  373. if( ! CHECKHRESULT(hr) )
  374. {
  375. TRACE(_T("IConsole2::QueryInterface failed.\n"));
  376. lpConsole->Release();
  377. return FALSE;
  378. }
  379. ASSERT(lpProvider);
  380. bool bIsOpenSheet = false;
  381. for( int i = 0; i < m_ResultItems.GetSize(); i++ )
  382. {
  383. // create an IDataObject for this result item
  384. CSnapinDataObject* pdoNew = NULL;
  385. pdoNew = new CSnapinDataObject;
  386. if( ! GfxCheckObjPtr(pdoNew,CSnapinDataObject) )
  387. {
  388. TRACE(_T("FAILED : Out of memory.\n"));
  389. lpProvider->Release();
  390. lpConsole->Release();
  391. return false;
  392. }
  393. LPDATAOBJECT lpDataObject = (LPDATAOBJECT)pdoNew->GetInterface(&IID_IDataObject);
  394. ASSERT(lpDataObject);
  395. pdoNew->SetItem(m_ResultItems[i]);
  396. for( int i = 0; i < GetOwnerScopeItem()->GetScopePane()->GetResultsPaneCount(); i++ )
  397. {
  398. CResultsPane* pResultsPane = GetOwnerScopeItem()->GetScopePane()->GetResultsPane(i);
  399. if( GfxCheckObjPtr(pResultsPane,CResultsPane) )
  400. {
  401. LPCOMPONENT lpComponent = (LPCOMPONENT)pResultsPane->GetInterface(&IID_IComponent);
  402. hr = lpProvider->FindPropertySheet(MMC_COOKIE(this),lpComponent,lpDataObject);
  403. if( hr == S_OK )
  404. {
  405. bIsOpenSheet = true;
  406. }
  407. }
  408. }
  409. delete pdoNew;
  410. }
  411. lpProvider->Release();
  412. lpConsole->Release();
  413. return bIsOpenSheet;
  414. }
  415. bool CResultsPaneView::InvokePropertySheet(CResultsPaneItem* pItem)
  416. {
  417. TRACEX(_T("CResultsPaneView::InvokePropertySheet\n"));
  418. TRACEARGn(pItem);
  419. // first see if a property sheet for this item is open already
  420. if( IsPropertySheetOpen() )
  421. {
  422. return true;
  423. }
  424. if( ! GetOwnerScopeItem() || ! GetOwnerScopeItem()->GetScopePane() )
  425. {
  426. TRACE(_T("FAILED : Owner scope item is not a valid object.\n"));
  427. return false;
  428. }
  429. LPCONSOLE2 lpConsole = GetOwnerScopeItem()->GetScopePane()->GetConsolePtr();
  430. if( ! GfxCheckPtr(lpConsole,IConsole2) )
  431. {
  432. TRACE(_T("FAILED : lpConsole is not a valid pointer.\n"));
  433. return false;
  434. }
  435. // get a reference to the IPropertySheetProvider interface
  436. LPPROPERTYSHEETPROVIDER lpProvider = NULL;
  437. HRESULT hr = lpConsole->QueryInterface(IID_IPropertySheetProvider,(LPVOID*)&lpProvider);
  438. if( ! CHECKHRESULT(hr) )
  439. {
  440. TRACE(_T("IConsole2::QueryInterface failed.\n"));
  441. lpConsole->Release();
  442. return FALSE;
  443. }
  444. ASSERT(lpProvider);
  445. // create an IDataObject for this result item
  446. CSnapinDataObject* pdoNew = NULL;
  447. pdoNew = new CSnapinDataObject;
  448. if( ! GfxCheckObjPtr(pdoNew,CSnapinDataObject) )
  449. {
  450. TRACE(_T("FAILED : Out of memory.\n"));
  451. lpProvider->Release();
  452. lpConsole->Release();
  453. return false;
  454. }
  455. LPDATAOBJECT lpDataObject = (LPDATAOBJECT)pdoNew->GetInterface(&IID_IDataObject);
  456. ASSERT(lpDataObject);
  457. pdoNew->SetItem(pItem);
  458. hr = lpProvider->CreatePropertySheet(pItem->GetDisplayName(),TRUE,MMC_COOKIE(pItem),lpDataObject,MMC_PSO_HASHELP);
  459. if( ! CHECKHRESULT(hr) )
  460. {
  461. TRACE(_T("FAILED : IPropertySheetProvider::CreatePropertySheet failed.\n"));
  462. lpProvider->Release();
  463. lpConsole->Release();
  464. delete pdoNew;
  465. return false;
  466. }
  467. HWND hWndNotification = NULL;
  468. HWND hWndMain = NULL;
  469. hr = lpConsole->GetMainWindow(&hWndMain);
  470. if( ! CHECKHRESULT(hr) )
  471. {
  472. // Release data allocated in CreatePropertySheet
  473. lpProvider->Show( -1, 0);
  474. lpProvider->Release();
  475. lpConsole->Release();
  476. delete pdoNew;
  477. return false;
  478. }
  479. // Try to get the correct window that notifications should be sent to.
  480. hWndNotification = FindWindowEx( hWndMain, NULL, _T("MDIClient"), NULL );
  481. hWndNotification = FindWindowEx( hWndNotification, NULL, _T("MMCChildFrm"), NULL );
  482. hWndNotification = FindWindowEx( hWndNotification, NULL, _T("MMCView"), NULL );
  483. if( hWndNotification == NULL )
  484. {
  485. // It was a nice try, but it failed, so we should be able to get by by using the main HWND.
  486. hWndNotification = hWndMain;
  487. }
  488. LPCOMPONENTDATA lpComponentData = (LPCOMPONENTDATA)GetOwnerScopeItem()->GetScopePane()->GetInterface(&IID_IComponentData);
  489. hr = lpProvider->AddPrimaryPages(lpComponentData,TRUE,hWndNotification,TRUE);
  490. if( ! CHECKHRESULT(hr) )
  491. {
  492. // Release data allocated in CreatePropertySheet
  493. lpProvider->Show(-1,0);
  494. lpProvider->Release();
  495. lpConsole->Release();
  496. delete pdoNew;
  497. return false;
  498. }
  499. hr = lpProvider->AddExtensionPages();
  500. if( ! CHECKHRESULT(hr) )
  501. {
  502. // ISSUE: Should I care if this fails?
  503. // Release data allocated in CreatePropertySheet
  504. lpProvider->Show( -1, 0);
  505. lpProvider->Release();
  506. lpConsole->Release();
  507. delete pdoNew;
  508. return false;
  509. }
  510. // v-marfin : Show "details" page on creation of a new obejct
  511. #ifndef IA64
  512. hr = lpProvider->Show( (long) hWndMain, 1); // 59643b
  513. #endif // IA64
  514. if( ! CHECKHRESULT( hr ) )
  515. {
  516. // Release data allocated in CreatePropertySheet
  517. lpProvider->Show( -1, 0);
  518. lpProvider->Release();
  519. lpConsole->Release();
  520. delete pdoNew;
  521. return false;
  522. }
  523. lpProvider->Release();
  524. lpConsole->Release();
  525. delete pdoNew;
  526. return true;
  527. }
  528. /////////////////////////////////////////////////////////////////////////////
  529. // Context Menu Members
  530. bool CResultsPaneView::InvokeContextMenu(const CPoint& pt, CResultsPaneItem* pItem, int iSelectedCount)
  531. {
  532. TRACEX(_T("CResultsPaneView::InvokeContextMenu\n"));
  533. TRACEARGn(pt.x);
  534. TRACEARGn(pt.y);
  535. TRACEARGn(pItem);
  536. ASSERT(m_ResultsPanes.GetSize());
  537. CResultsPane* pPane = m_ResultsPanes[0];
  538. if( !pPane || ! GfxCheckObjPtr(pPane,CResultsPane) )
  539. {
  540. return false;
  541. }
  542. LPCONSOLE2 lpConsole = pPane->GetConsolePtr();
  543. // get a reference to the IContextMenuProvider interface
  544. LPCONTEXTMENUPROVIDER lpProvider = NULL;
  545. HRESULT hr = lpConsole->QueryInterface(IID_IContextMenuProvider,(LPVOID*)&lpProvider);
  546. if( ! CHECKHRESULT(hr) )
  547. {
  548. TRACE(_T("IConsole2::QueryInterface failed.\n"));
  549. lpConsole->Release();
  550. return FALSE;
  551. }
  552. ASSERT(lpProvider);
  553. // just as a precaution
  554. hr = lpProvider->EmptyMenuList();
  555. // populate the menu
  556. CONTEXTMENUITEM cmi;
  557. CString sResString;
  558. CString sResString2;
  559. ZeroMemory(&cmi,sizeof(CONTEXTMENUITEM));
  560. // add the top insertion point
  561. cmi.lCommandID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  562. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_ROOT_MENU;
  563. cmi.fSpecialFlags = CCM_SPECIAL_INSERTION_POINT;
  564. hr = lpProvider->AddItem(&cmi);
  565. // add new menu and insertion point
  566. sResString.LoadString(IDS_STRING_NEW);
  567. cmi.strName = LPTSTR(LPCTSTR(sResString));
  568. sResString2.LoadString(IDS_STRING_NEW_DESCRIPTION);
  569. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  570. cmi.lCommandID = CCM_INSERTIONPOINTID_PRIMARY_NEW;
  571. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  572. cmi.fFlags = MF_POPUP;
  573. cmi.fSpecialFlags = CCM_SPECIAL_SUBMENU;
  574. hr = lpProvider->AddItem(&cmi);
  575. cmi.lCommandID = CCM_INSERTIONPOINTID_PRIMARY_NEW;
  576. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  577. cmi.fSpecialFlags = CCM_SPECIAL_INSERTION_POINT;
  578. hr = lpProvider->AddItem(&cmi);
  579. // add task menu and insertion point
  580. sResString.LoadString(IDS_STRING_TASK);
  581. cmi.strName = LPTSTR(LPCTSTR(sResString));
  582. sResString2.LoadString(IDS_STRING_TASK_DESCRIPTION);
  583. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  584. cmi.lCommandID = CCM_INSERTIONPOINTID_PRIMARY_TASK;
  585. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  586. cmi.fFlags = MF_POPUP;
  587. cmi.fSpecialFlags = CCM_SPECIAL_SUBMENU;
  588. hr = lpProvider->AddItem(&cmi);
  589. cmi.lCommandID = CCM_INSERTIONPOINTID_PRIMARY_TASK;
  590. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  591. cmi.fSpecialFlags = CCM_SPECIAL_INSERTION_POINT;
  592. hr = lpProvider->AddItem(&cmi);
  593. // create an IDataObject for this results item
  594. CSnapinDataObject* pdoNew = NULL;
  595. pdoNew = new CSnapinDataObject;
  596. if( ! GfxCheckObjPtr(pdoNew,CSnapinDataObject) )
  597. {
  598. TRACE(_T("FAILED : Out of memory.\n"));
  599. lpProvider->Release();
  600. lpConsole->Release();
  601. return false;
  602. }
  603. LPDATAOBJECT lpDataObject = (LPDATAOBJECT)pdoNew->GetInterface(&IID_IDataObject);
  604. ASSERT(lpDataObject);
  605. pdoNew->SetItem(pItem);
  606. LPUNKNOWN lpUnknown = (LPUNKNOWN)pPane->GetInterface(&IID_IExtendContextMenu);
  607. hr = lpProvider->AddPrimaryExtensionItems(lpUnknown,lpDataObject);
  608. // add third party insertion points only if there is 1 item selected
  609. if( iSelectedCount == 1 )
  610. {
  611. cmi.lCommandID = CCM_INSERTIONPOINTID_3RDPARTY_NEW;
  612. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_NEW;
  613. cmi.fSpecialFlags = CCM_SPECIAL_INSERTION_POINT;
  614. hr = lpProvider->AddItem(&cmi);
  615. cmi.lCommandID = CCM_INSERTIONPOINTID_3RDPARTY_TASK;
  616. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TASK;
  617. cmi.fSpecialFlags = CCM_SPECIAL_INSERTION_POINT;
  618. hr = lpProvider->AddItem(&cmi);
  619. hr = lpProvider->AddThirdPartyExtensionItems(lpDataObject);
  620. }
  621. HWND hWndMain = NULL;
  622. hr = lpConsole->GetMainWindow(&hWndMain);
  623. // Try to get the correct window that notifications should be sent to.
  624. HWND hWndNotification = FindWindowEx( hWndMain, NULL, _T("MDIClient"), NULL );
  625. hWndNotification = FindWindowEx( hWndNotification, NULL, _T("MMCChildFrm"), NULL );
  626. hWndNotification = FindWindowEx( hWndNotification, NULL, _T("AfxFrameOrView42u"), NULL );
  627. if( hWndNotification == NULL )
  628. {
  629. // It was a nice try, but it failed, so we should be able to get by by using the main HWND.
  630. hWndNotification = hWndMain;
  631. }
  632. long lSelected = 0L;
  633. hr = lpProvider->ShowContextMenu(hWndNotification,pt.x,pt.y,&lSelected);
  634. lpProvider->Release();
  635. lpConsole->Release();
  636. lpDataObject->Release();
  637. return true;
  638. }
  639. /////////////////////////////////////////////////////////////////////////////
  640. // Results Pane Members - tracks each results pane open on a particular results view
  641. void CResultsPaneView::AddResultsPane(CResultsPane* pPane)
  642. {
  643. TRACEX(_T("CResultsPaneView::AddResultsPane\n"));
  644. TRACEARGn(pPane);
  645. if( ! GfxCheckObjPtr(pPane,CResultsPane) )
  646. {
  647. TRACE(_T("FAILED : pPane is not a valid pointer.\n"));
  648. return;
  649. }
  650. m_ResultsPanes.Add(pPane);
  651. }
  652. void CResultsPaneView::RemoveResultsPane(CResultsPane* pPane)
  653. {
  654. TRACEX(_T("CResultsPaneView::RemoveResultsPane\n"));
  655. TRACEARGn(pPane);
  656. if( ! GfxCheckObjPtr(pPane,CResultsPane) )
  657. {
  658. TRACE(_T("FAILED : pPane is not a valid pointer.\n"));
  659. return;
  660. }
  661. for( int i = 0; i < m_ResultsPanes.GetSize(); i++ )
  662. {
  663. if( m_ResultsPanes[i] == pPane )
  664. {
  665. m_ResultsPanes.RemoveAt(i);
  666. return;
  667. }
  668. }
  669. }
  670. CResultsPane* CResultsPaneView::GetResultsPane(int iIndex)
  671. {
  672. TRACEX(_T("CResultsPaneView::GetResultsPane\n"));
  673. TRACEARGn(iIndex);
  674. if( iIndex < 0 )
  675. {
  676. TRACE(_T("FAILED : index is out of bounds.\n"));
  677. return NULL;
  678. }
  679. if( iIndex > m_ResultsPanes.GetUpperBound() )
  680. {
  681. TRACE(_T("FAILED : index is out of bounds.\n"));
  682. return NULL;
  683. }
  684. return m_ResultsPanes[iIndex];
  685. }
  686. int CResultsPaneView::GetResultsPanesCount()
  687. {
  688. TRACEX(_T("CResultsPaneView::GetResultsPanesCount\n"));
  689. return (int)m_ResultsPanes.GetSize();
  690. }
  691. /////////////////////////////////////////////////////////////////////////////
  692. // MMC Notify Handlers
  693. HRESULT CResultsPaneView::OnActivate(BOOL bActivate)
  694. {
  695. TRACEX(_T("CResultsPaneView::OnActivate\n"));
  696. TRACEARGn(bActivate);
  697. return S_OK;
  698. }
  699. HRESULT CResultsPaneView::OnAddMenuItems(CResultsPaneItem* pItem, LPCONTEXTMENUCALLBACK piCallback,long __RPC_FAR *pInsertionAllowed)
  700. {
  701. TRACEX(_T("CResultsPaneView::OnAddMenuItems\n"));
  702. TRACEARGn(pItem);
  703. TRACEARGn(piCallback);
  704. TRACEARGn(pInsertionAllowed);
  705. // Add New Menu Items
  706. if( CCM_INSERTIONALLOWED_NEW & *pInsertionAllowed )
  707. {
  708. // TODO: Add any context menu items for the New Menu here
  709. }
  710. // Add Task Menu Items
  711. if( CCM_INSERTIONALLOWED_TASK & *pInsertionAllowed )
  712. {
  713. // TODO: Add any context menu items for the Task Menu here
  714. }
  715. return pItem->OnAddMenuItems(piCallback,pInsertionAllowed);
  716. }
  717. HRESULT CResultsPaneView::OnBtnClick(CResultsPaneItem* pItem, MMC_CONSOLE_VERB mcvVerb)
  718. {
  719. TRACEX(_T("CResultsPaneView::OnBtnClick\n"));
  720. TRACEARGn(pItem);
  721. TRACEARGn(mcvVerb);
  722. return S_OK;
  723. }
  724. HRESULT CResultsPaneView::OnCommand(CResultsPane* pPane, CResultsPaneItem* pItem, long lCommandID)
  725. {
  726. TRACEX(_T("CResultsPaneView::OnCommand\n"));
  727. TRACEARGn(pPane);
  728. TRACEARGn(pItem);
  729. TRACEARGn(lCommandID);
  730. return pItem->OnCommand(pPane,lCommandID);
  731. }
  732. HRESULT CResultsPaneView::OnContextHelp(CResultsPaneItem* pItem)
  733. {
  734. TRACEX(_T("CResultsPaneView::OnContextHelp\n"));
  735. TRACEARGn(pItem);
  736. if( ! GetOwnerScopeItem() )
  737. {
  738. return E_FAIL;
  739. }
  740. return GetOwnerScopeItem()->OnContextHelp();
  741. }
  742. HRESULT CResultsPaneView::OnCreatePropertyPages(CResultsPaneItem* pItem, LPPROPERTYSHEETCALLBACK lpProvider, INT_PTR handle)
  743. {
  744. TRACEX(_T("CResultsPaneView::OnCreatePropertyPages\n"));
  745. TRACEARGn(lpProvider);
  746. TRACEARGn(handle);
  747. TRACEARGn(pItem);
  748. return S_FALSE;
  749. }
  750. HRESULT CResultsPaneView::OnDblClick(CResultsPaneItem* pItem)
  751. {
  752. TRACEX(_T("CResultsPaneView::OnDblClick\n"));
  753. TRACEARGn(pItem);
  754. return S_FALSE;
  755. }
  756. HRESULT CResultsPaneView::OnDelete(CResultsPaneItem* pItem)
  757. {
  758. TRACEX(_T("CResultsPaneView::OnDelete\n"));
  759. TRACEARGn(pItem);
  760. RemoveItem(pItem);
  761. return S_OK;
  762. }
  763. HRESULT CResultsPaneView::OnGetResultViewType(CString& sViewType,long& lViewOptions)
  764. {
  765. TRACEX(_T("CResultsPaneView::OnGetResultViewType\n"));
  766. TRACEARGs(sViewType);
  767. TRACEARGn(lViewOptions);
  768. return S_OK;
  769. }
  770. HRESULT CResultsPaneView::OnMinimized(BOOL bMinimized)
  771. {
  772. TRACEX(_T("CResultsPaneView::OnMinimized\n"));
  773. TRACEARGn(bMinimized);
  774. return S_OK;
  775. }
  776. HRESULT CResultsPaneView::OnPropertyChange(LPARAM lParam)
  777. {
  778. TRACEX(_T("CResultsPaneView::OnPropertyChange\n"));
  779. TRACEARGn(lParam);
  780. return S_OK;
  781. }
  782. HRESULT CResultsPaneView::OnQueryPagesFor(CResultsPaneItem* pItem)
  783. {
  784. TRACEX(_T("CResultsPaneView::OnQueryPagesFor\n"));
  785. TRACEARGn(pItem);
  786. return S_OK;
  787. }
  788. HRESULT CResultsPaneView::OnRefresh()
  789. {
  790. TRACEX(_T("CResultsPaneView::OnRefresh\n"));
  791. return S_OK;
  792. }
  793. HRESULT CResultsPaneView::OnRename(CResultsPaneItem* pItem, const CString& sNewName)
  794. {
  795. TRACEX(_T("CResultsPaneView::OnRename\n"));
  796. TRACEARGn(pItem);
  797. return S_OK;
  798. }
  799. HRESULT CResultsPaneView::OnRestoreView(MMC_RESTORE_VIEW* pRestoreView, BOOL* pbHandled)
  800. {
  801. TRACEX(_T("CResultsPaneView::OnRestoreView\n"));
  802. TRACEARGn(pRestoreView);
  803. TRACEARGn(pbHandled);
  804. return S_OK;
  805. }
  806. HRESULT CResultsPaneView::OnSelect(CResultsPane* pPane, CResultsPaneItem* pItem, BOOL bSelected)
  807. {
  808. TRACEX(_T("CResultsPaneView::OnSelect\n"));
  809. TRACEARGn(pPane);
  810. TRACEARGn(pItem);
  811. TRACEARGn(bSelected);
  812. return S_OK;
  813. }
  814. HRESULT CResultsPaneView::OnShow(CResultsPane* pPane, BOOL bSelecting, HSCOPEITEM hScopeItem)
  815. {
  816. TRACEX(_T("CResultsPaneView::OnShow\n"));
  817. TRACEARGn(pPane);
  818. TRACEARGn(bSelecting);
  819. TRACEARGn(hScopeItem);
  820. if( ! GfxCheckObjPtr(pPane,CResultsPane) )
  821. {
  822. TRACE(_T("FAILED : pPane is not a valid pointer.\n"));
  823. return E_FAIL;
  824. }
  825. HRESULT hr = S_OK;
  826. if( bSelecting )
  827. {
  828. // add all the columns to the header control
  829. for( int i=0; i < GetColumnCount(); i++ )
  830. {
  831. CListViewColumn* pColumn = GetColumn(i);
  832. if( pColumn )
  833. {
  834. if( ! pColumn->InsertColumn(pPane,i) )
  835. {
  836. TRACE(_T("FAILED : CListViewColumn::InsertColumn failed.\n"));
  837. }
  838. }
  839. }
  840. // insert all the results pane items
  841. for( i=0; i < GetItemCount(); i++ )
  842. {
  843. CResultsPaneItem* pItem = GetItem(i);
  844. if( pItem )
  845. {
  846. if( ! pItem->InsertItem(pPane,i,true) )
  847. {
  848. TRACE(_T("FAILED : CResultsPaneItem::InsertItem failed.\n"));
  849. }
  850. }
  851. }
  852. }
  853. else
  854. {
  855. /* // remember all the column sizes
  856. for( int i=0; i < GetColumnCount(); i++ )
  857. {
  858. CListViewColumn* pColumn = GetColumn(i);
  859. if( pColumn )
  860. {
  861. pColumn->SaveWidth(pPane,i);
  862. }
  863. }
  864. LPRESULTDATA lpResultData = pPane->GetResultDataPtr();
  865. if( ! GfxCheckPtr(lpResultData,IResultData) )
  866. {
  867. return E_FAIL;
  868. }
  869. // remember all the positions of the items
  870. for( i = 0; i < GetItemCount(); i++ )
  871. {
  872. CResultsPaneItem* pItem = NULL;
  873. RESULTDATAITEM rdi;
  874. ZeroMemory(&rdi,sizeof(rdi));
  875. rdi.mask = RDI_INDEX | RDI_PARAM;
  876. rdi.nIndex = i;
  877. hr = lpResultData->GetItem(&rdi);
  878. pItem = (CResultsPaneItem*)rdi.lParam;
  879. m_ResultItems.SetAt(i,pItem);
  880. }
  881. lpResultData->Release();
  882. */ }
  883. return hr;
  884. }
  885. HRESULT CResultsPaneView::OnViewChange(CResultsPaneItem* pItem, LONG lArg, LONG lHintParam)
  886. {
  887. TRACEX(_T("CResultsPaneView::OnViewChange\n"));
  888. TRACEARGn(pItem);
  889. TRACEARGn(lArg);
  890. TRACEARGn(lHintParam);
  891. return S_OK;
  892. }
  893. void CResultsPaneView::OnFinalRelease()
  894. {
  895. // When the last reference for an automation object is released
  896. // OnFinalRelease is called. The base class will automatically
  897. // deletes the object. Add additional cleanup required for your
  898. // object before calling the base class.
  899. CCmdTarget::OnFinalRelease();
  900. }
  901. BEGIN_MESSAGE_MAP(CResultsPaneView, CCmdTarget)
  902. //{{AFX_MSG_MAP(CResultsPaneView)
  903. // NOTE - the ClassWizard will add and remove mapping macros here.
  904. //}}AFX_MSG_MAP
  905. END_MESSAGE_MAP()
  906. BEGIN_DISPATCH_MAP(CResultsPaneView, CCmdTarget)
  907. //{{AFX_DISPATCH_MAP(CResultsPaneView)
  908. // NOTE - the ClassWizard will add and remove mapping macros here.
  909. //}}AFX_DISPATCH_MAP
  910. END_DISPATCH_MAP()
  911. // Note: we add support for IID_IResultsPaneView to support typesafe binding
  912. // from VBA. This IID must match the GUID that is attached to the
  913. // dispinterface in the .ODL file.
  914. // {7D4A6864-9056-11D2-BD45-0000F87A3912}
  915. static const IID IID_IResultsPaneView =
  916. { 0x7d4a6864, 0x9056, 0x11d2, { 0xbd, 0x45, 0x0, 0x0, 0xf8, 0x7a, 0x39, 0x12 } };
  917. BEGIN_INTERFACE_MAP(CResultsPaneView, CCmdTarget)
  918. INTERFACE_PART(CResultsPaneView, IID_IResultsPaneView, Dispatch)
  919. END_INTERFACE_MAP()
  920. /////////////////////////////////////////////////////////////////////////////
  921. // CResultsPaneView message handlers