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.

1754 lines
41 KiB

  1. // ScopePaneItem.cpp : implementation file
  2. //
  3. // Copyright (c) 2000 Microsoft Corporation
  4. //
  5. // 03/29/00 v-marfin 62478 : Set help topic based on type of object
  6. // 03/30/00 v-marfin 59644 : Modified prototype of InvokeContextMenu
  7. // to allow passing to selected item count. Only allow
  8. // third party menu item (for Troubleshooting) if only 1
  9. // item is selected.
  10. // 04/02/00 v-marfin 59643b On creation of new items, show details page first.
  11. // 04/05/00 v-marfin 62962 Show "details" page on a new creation unless it is
  12. // a new data group in which case show General first.
  13. //
  14. #include "stdafx.h"
  15. #include "snapin.h"
  16. #include "ScopePaneItem.h"
  17. #include "ScopePane.h"
  18. #include "RootScopeItem.h"
  19. #include "AllSystemsScopeItem.h"
  20. #include "SystemScopeItem.h"
  21. #include "ActionPolicyScopeItem.h"
  22. #include "DataGroupScopeItem.h"
  23. #include "DataElementScopeItem.h"
  24. #include "RuleScopeItem.h"
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CScopePaneItem
  32. IMPLEMENT_DYNCREATE(CScopePaneItem, CCmdTarget)
  33. /////////////////////////////////////////////////////////////////////////////
  34. // Construction/Destruction
  35. CScopePaneItem::CScopePaneItem()
  36. {
  37. EnableAutomation();
  38. m_pScopePane = NULL;
  39. m_pParent = NULL;
  40. m_pResultsPaneView = NULL;
  41. m_hItemHandle = NULL;
  42. m_lpguidItemType = NULL;
  43. m_iCurrentIconIndex = -1;
  44. m_iCurrentOpenIconIndex = -1;
  45. m_bVisible = true;
  46. // To keep the application running as long as an OLE automation
  47. // object is active, the constructor calls AfxOleLockApp.
  48. AfxOleLockApp();
  49. }
  50. CScopePaneItem::~CScopePaneItem()
  51. {
  52. Destroy();
  53. // To terminate the application when all objects created with
  54. // with OLE automation, the destructor calls AfxOleUnlockApp.
  55. AfxOleUnlockApp();
  56. }
  57. /////////////////////////////////////////////////////////////////////////////
  58. // Create/Destroy
  59. bool CScopePaneItem::Create(CScopePane* pScopePane, CScopePaneItem* pParentItem)
  60. {
  61. TRACEX(_T("CScopePaneItem::Create\n"));
  62. TRACEARGn(pScopePane);
  63. TRACEARGn(pParentItem);
  64. if( ! GfxCheckObjPtr(pScopePane,CScopePane) )
  65. {
  66. TRACE(_T("FAILED : pScopePane is not a valid pointer.\n"));
  67. return false;
  68. }
  69. if( pParentItem == NULL )
  70. {
  71. TRACE(_T("WARNING : pParentItem is a NULL pointer. This is acceptable for the root node only.\n"));
  72. }
  73. else if( ! GfxCheckObjPtr(pParentItem,CScopePaneItem) )
  74. {
  75. TRACE(_T("FAILED : pParentItem is not a valid pointer.\n"));
  76. return false;
  77. }
  78. SetScopePane(pScopePane);
  79. SetParent(pParentItem);
  80. // create the results view
  81. m_pResultsPaneView = CreateResultsPaneView();
  82. if( ! GfxCheckObjPtr(m_pResultsPaneView,CResultsPaneView) )
  83. {
  84. TRACE(_T("FAILED : CResultsPaneView::CreateResultsPane returned an invalid pointer.\n"));
  85. return false;
  86. }
  87. if( ! m_pResultsPaneView->Create(this) )
  88. {
  89. TRACE(_T("FAILED : CResultsPaneView::Create failed.\n"));
  90. return false;
  91. }
  92. m_bVisible = true;
  93. return true;
  94. }
  95. void CScopePaneItem::Destroy()
  96. {
  97. TRACEX(_T("CScopePaneItem::Destroy\n"));
  98. if( m_pScopePane == NULL && m_Children.GetSize() == 0 && m_pResultsPaneView == NULL )
  99. {
  100. TRACE(_T("INFO : Destroy has already been called for this item.\n"));
  101. return;
  102. }
  103. // remove all children from our data structure
  104. for( int i=0; i < m_Children.GetSize(); i++ )
  105. {
  106. m_Children[i]->Destroy();
  107. delete m_Children[i];
  108. }
  109. m_Children.RemoveAll();
  110. DeleteItem();
  111. if( m_pResultsPaneView )
  112. {
  113. delete m_pResultsPaneView;
  114. m_pResultsPaneView = NULL;
  115. }
  116. m_pScopePane = NULL;
  117. m_pParent = NULL;
  118. m_hItemHandle = NULL;
  119. m_lpguidItemType = NULL;
  120. m_iCurrentIconIndex = -1;
  121. m_iCurrentOpenIconIndex = -1;
  122. m_saDisplayNames.RemoveAll();
  123. m_IconResIds.RemoveAll();
  124. m_OpenIconResIds.RemoveAll();
  125. m_sHelpTopic.Empty();
  126. m_bVisible = true;
  127. }
  128. /////////////////////////////////////////////////////////////////////////////
  129. // Scope Pane Members
  130. // v-marfin 59237 :
  131. // Within this data elements scope, return a unique name if the current name is already used
  132. CString CScopePaneItem::GetUniqueDisplayName(CString sProposedName)
  133. {
  134. int nSize = GetChildCount();
  135. // if no entries, use proposed
  136. if (nSize < 1)
  137. {
  138. return sProposedName;
  139. }
  140. CString sName = sProposedName;
  141. CString sCompare;
  142. int nSuffix=0;
  143. BOOL bContinue=TRUE;
  144. while (bContinue)
  145. {
  146. BOOL bNameAlreadyInUse=FALSE;
  147. // scan existing display names
  148. for (int x=0; x<nSize; x++)
  149. {
  150. // Is name already in use?
  151. CScopePaneItem* pItem = GetChild(x);
  152. if (!pItem)
  153. continue;
  154. sCompare = pItem->GetDisplayName();
  155. if (sCompare.CompareNoCase(sName)==0)
  156. {
  157. sName.Format(_T("%s %d"),sProposedName,nSuffix++);
  158. bNameAlreadyInUse=TRUE;
  159. break;
  160. }
  161. }
  162. if (bNameAlreadyInUse)
  163. continue;
  164. else
  165. break;
  166. }
  167. return sName;
  168. }
  169. CScopePane* CScopePaneItem::GetScopePane() const
  170. {
  171. TRACEX(_T("CScopePaneItem::GetScopePane\n"));
  172. if( ! GfxCheckObjPtr(m_pScopePane,CScopePane) )
  173. {
  174. TRACE(_T("FAILED : m_pScopePane is not a valid pointer.\n"));
  175. return NULL;
  176. }
  177. return m_pScopePane;
  178. }
  179. void CScopePaneItem::SetScopePane(CScopePane* pScopePane)
  180. {
  181. TRACEX(_T("CScopePaneItem::SetScopePane\n"));
  182. TRACEARGn(pScopePane);
  183. if( ! GfxCheckObjPtr(pScopePane,CScopePane) )
  184. {
  185. TRACE(_T("FAILED : pScopePane is not a valid pointer.\n"));
  186. return;
  187. }
  188. m_pScopePane = pScopePane;
  189. }
  190. /////////////////////////////////////////////////////////////////////////////
  191. // Parent Scope Item Members
  192. CScopePaneItem* CScopePaneItem::GetParent() const
  193. {
  194. TRACEX(_T("CScopePaneItem::GetParent\n"));
  195. if( !m_pParent || ! GfxCheckObjPtr(m_pParent,CScopePaneItem) )
  196. {
  197. TRACE(_T("WARNING : m_pParent is not a valid pointer.\n"));
  198. return NULL;
  199. }
  200. return m_pParent;
  201. }
  202. void CScopePaneItem::SetParent(CScopePaneItem* pParentItem)
  203. {
  204. TRACEX(_T("CScopePaneItem::SetParent\n"));
  205. TRACEARGn(pParentItem);
  206. if( pParentItem == NULL )
  207. {
  208. TRACE(_T("WARNING : pParentItem is NULL. This should only happen for the root node, which has no parent.\n"));
  209. }
  210. else if( ! GfxCheckObjPtr(pParentItem,CScopePaneItem) )
  211. {
  212. TRACE(_T("FAILED : pParentItem is not a valid pointer.\n"));
  213. m_pParent = NULL;
  214. return;
  215. }
  216. m_pParent = pParentItem;
  217. }
  218. /////////////////////////////////////////////////////////////////////////////
  219. // Child Scope Item Members
  220. int CScopePaneItem::GetChildCount() const
  221. {
  222. TRACEX(_T("CScopePaneItem::GetChildCount\n"));
  223. return (int)m_Children.GetSize();
  224. }
  225. CScopePaneItem* CScopePaneItem::GetChild(int iIndex)
  226. {
  227. TRACEX(_T("CScopePaneItem::GetChild\n"));
  228. TRACEARGn(iIndex);
  229. if( iIndex >= m_Children.GetSize() || iIndex < 0 )
  230. {
  231. TRACE(_T("FAILED : iIndex is out of array bounds.\n"));
  232. return NULL;
  233. }
  234. return m_Children[iIndex];
  235. }
  236. int CScopePaneItem::AddChild(CScopePaneItem* pChildItem)
  237. {
  238. TRACEX(_T("CScopePaneItem::AddChild\n"));
  239. TRACEARGn(pChildItem);
  240. if( ! GfxCheckObjPtr(pChildItem,CScopePaneItem) )
  241. {
  242. TRACE(_T("FAILED : pChildItem is not a valid pointer.\n"));
  243. return -1;
  244. }
  245. for( int i = 0; i < m_Children.GetSize(); i++ )
  246. {
  247. if( pChildItem->GetDisplayName().CompareNoCase(m_Children[i]->GetDisplayName()) < 0 )
  248. {
  249. m_Children.InsertAt(i,pChildItem);
  250. return i;
  251. }
  252. }
  253. return (int)m_Children.Add(pChildItem);
  254. }
  255. void CScopePaneItem::RemoveChild(int iIndex)
  256. {
  257. TRACEX(_T("CScopePaneItem::RemoveChild\n"));
  258. TRACEARGn(iIndex);
  259. if( iIndex >= m_Children.GetSize() || iIndex < 0 )
  260. {
  261. TRACE(_T("FAILED : iIndex is out of array bounds.\n"));
  262. return;
  263. }
  264. m_Children.RemoveAt(iIndex);
  265. }
  266. void CScopePaneItem::RemoveChild(CScopePaneItem* pChildItem)
  267. {
  268. TRACEX(_T("CScopePaneItem::RemoveChild\n"));
  269. TRACEARGn(pChildItem);
  270. if( ! GfxCheckObjPtr(pChildItem,CScopePaneItem) )
  271. {
  272. TRACE(_T("FAILED : pChildItem is not a valid pointer.\n"));
  273. return;
  274. }
  275. for( int i = 0; i < m_Children.GetSize(); i++ )
  276. {
  277. if( m_Children[i] == pChildItem )
  278. {
  279. RemoveChild(i);
  280. return;
  281. }
  282. }
  283. }
  284. void CScopePaneItem::DestroyChild(CScopePaneItem* pChild)
  285. {
  286. TRACEX(_T("CScopePaneItem::DestroyChild\n"));
  287. TRACEARGn(pChild);
  288. if( ! GfxCheckObjPtr(pChild,CScopePaneItem) )
  289. {
  290. TRACE(_T("FAILED : pChild is not a valid pointer.\n"));
  291. return;
  292. }
  293. for( int i = 0; i < m_Children.GetSize(); i++ )
  294. {
  295. if( m_Children[i] == pChild )
  296. {
  297. RemoveChild(i);
  298. delete pChild;
  299. return;
  300. }
  301. }
  302. }
  303. int CScopePaneItem::FindChild(SPIFINDPROC pFindProc, LPARAM param)
  304. {
  305. TRACEX(_T("CScopePaneItem::FindChild\n"));
  306. TRACEARGn(pFindProc);
  307. if( ! GfxCheckPtr(pFindProc,SPIFINPROC) )
  308. {
  309. TRACE(_T("FAILED : pFindProc is not a valid function pointer.\n"));
  310. return -1;
  311. }
  312. return pFindProc(m_Children,param);
  313. }
  314. /////////////////////////////////////////////////////////////////////////////
  315. // Results Pane View Members
  316. CResultsPaneView* CScopePaneItem::CreateResultsPaneView()
  317. {
  318. TRACEX(_T("CScopePaneItem::CreateResultsPaneView\n"));
  319. return new CResultsPaneView;
  320. }
  321. CResultsPaneView* CScopePaneItem::GetResultsPaneView()const
  322. {
  323. TRACEX(_T("CScopePaneItem::GetResultsPaneView\n"));
  324. if( ! GfxCheckObjPtr(m_pResultsPaneView,CResultsPaneView) )
  325. {
  326. TRACE(_T("FAILED : m_pResultsPaneView is not a valid pointer.\n"));
  327. return NULL;
  328. }
  329. return m_pResultsPaneView;
  330. }
  331. /////////////////////////////////////////////////////////////////////////////
  332. // MMC-Related Item Members
  333. bool CScopePaneItem::InsertItem( int iIndex )
  334. {
  335. TRACEX(_T("CScopePaneItem::InsertItem\n"));
  336. if( ! GetScopePane() )
  337. {
  338. TRACE(_T("FAILED : m_pScopePane is not a valid pointer.\n"));
  339. return false;
  340. }
  341. if( ! GetParent() )
  342. {
  343. TRACE(_T("WARNING : m_pParent is not a valid pointer. This could be the root item.\n"));
  344. return false;
  345. }
  346. if( m_pParent->GetItemHandle() == NULL )
  347. {
  348. TRACE(_T("FAILED : Parent's item handle is NULL!\n"));
  349. return false;
  350. }
  351. if( GetItemHandle() != NULL )
  352. {
  353. TRACE(_T("WARNING : Item already inserted.\n"));
  354. return false;
  355. }
  356. SCOPEDATAITEM sdi;
  357. ZeroMemory(&sdi,sizeof(sdi));
  358. if( iIndex > 0 )
  359. {
  360. CScopePaneItem* pSiblingItem = m_pParent->GetChild(iIndex-1);
  361. sdi.mask = SDI_STR |
  362. SDI_PARAM |
  363. SDI_IMAGE |
  364. SDI_OPENIMAGE |
  365. SDI_PREVIOUS;
  366. sdi.relativeID = pSiblingItem->GetItemHandle();
  367. }
  368. else
  369. {
  370. sdi.mask = SDI_STR |
  371. SDI_PARAM |
  372. SDI_IMAGE |
  373. SDI_OPENIMAGE |
  374. SDI_PARENT;
  375. sdi.relativeID = m_pParent->GetItemHandle();
  376. }
  377. sdi.nImage = m_pScopePane->AddIcon(GetIconId());
  378. sdi.nOpenImage = m_pScopePane->AddIcon(GetOpenIconId());
  379. sdi.displayname = MMC_CALLBACK;
  380. sdi.lParam = (LPARAM)this; // The cookie is the this pointer
  381. LPCONSOLENAMESPACE2 lpNamespace = m_pScopePane->GetConsoleNamespacePtr();
  382. if( ! GfxCheckPtr(lpNamespace,IConsoleNameSpace2) )
  383. {
  384. TRACE(_T("FAILED : lpNamespace is not a valid pointer.\n"));
  385. return false;
  386. }
  387. HRESULT hr = lpNamespace->InsertItem( &sdi );
  388. if( hr != S_OK )
  389. {
  390. TRACE(_T("FAILED : IConsoleNameSpace2::InsertItem failed.\n"));
  391. TRACE(_T("FAILED : HRESULT=%X\n"),hr);
  392. }
  393. // save off the ID
  394. m_hItemHandle = sdi.ID;
  395. lpNamespace->Release();
  396. return true;
  397. }
  398. bool CScopePaneItem::DeleteItem()
  399. {
  400. TRACEX(_T("CScopePaneItem::DeleteItem\n"));
  401. // this function deletes the item and all its children from the mmc namespace ONLY
  402. // call Destroy to completely remove this item from MMC and the framework
  403. if( ! GetScopePane() )
  404. {
  405. TRACE(_T("FAILED : m_pScopePane is not a valid pointer.\n"));
  406. return false;
  407. }
  408. if( ! GetItemHandle() )
  409. {
  410. TRACE(_T("FAILED : GetItemHandle returns NULL.\n"));
  411. return false;
  412. }
  413. if( IsPropertySheetOpen() )
  414. {
  415. return false;
  416. }
  417. LPCONSOLENAMESPACE2 lpConsoleNamespace = m_pScopePane->GetConsoleNamespacePtr();
  418. if( ! GfxCheckPtr(lpConsoleNamespace,IConsoleNamespace2) )
  419. {
  420. TRACE(_T("WARNING : lpConsoleNamespace is not a valid pointer.\n"));
  421. return false;
  422. }
  423. lpConsoleNamespace->DeleteItem(GetItemHandle(),TRUE);
  424. lpConsoleNamespace->Release();
  425. m_hItemHandle = NULL;
  426. return true;
  427. }
  428. bool CScopePaneItem::SetItem()
  429. {
  430. TRACEX(_T("CScopePaneItem::SetItem\n"));
  431. if( GetItemHandle() == NULL )
  432. {
  433. TRACE(_T("FAILED : Item handle is NULL!\n"));
  434. return false;
  435. }
  436. if( GetScopePane() == NULL )
  437. {
  438. TRACE(_T("FAILED : m_pScopePane is not a valid pointer.\n"));
  439. return false;
  440. }
  441. LPCONSOLENAMESPACE2 lpNamespace = m_pScopePane->GetConsoleNamespacePtr();
  442. if( ! GfxCheckPtr(lpNamespace,IConsoleNameSpace2) )
  443. {
  444. TRACE(_T("FAILED : lpNamespace is not a valid pointer.\n"));
  445. return false;
  446. }
  447. SCOPEDATAITEM sdi;
  448. ZeroMemory(&sdi,sizeof(sdi));
  449. sdi.mask = SDI_PARAM | // lParam is valid
  450. SDI_IMAGE | // nImage is valid
  451. SDI_OPENIMAGE; // nOpenImage is valid
  452. sdi.nImage = m_pScopePane->GetIconIndex(GetIconId());
  453. sdi.nOpenImage = m_pScopePane->GetIconIndex(GetOpenIconId());
  454. sdi.lParam = (LPARAM)this; // The cookie is the this pointer
  455. sdi.ID = GetItemHandle();
  456. HRESULT hr = lpNamespace->SetItem( &sdi );
  457. if( ! CHECKHRESULT(hr) )
  458. {
  459. TRACE(_T("FAILED : IConsoleNameSpace2::SetItem failed.\n"));
  460. lpNamespace->Release();
  461. return false;
  462. }
  463. lpNamespace->Release();
  464. return true;
  465. }
  466. void CScopePaneItem::SelectItem()
  467. {
  468. TRACEX(_T("CScopePaneItem::SelectItem\n"));
  469. CScopePane* pPane = GetScopePane();
  470. LPCONSOLE2 lpConsole = pPane->GetConsolePtr();
  471. lpConsole->SelectScopeItem(GetItemHandle());
  472. lpConsole->Release();
  473. }
  474. void CScopePaneItem::ExpandItem(BOOL bExpand /* = TRUE*/)
  475. {
  476. TRACEX(_T("CScopePaneItem::ExpandItem\n"));
  477. CScopePane* pPane = GetScopePane();
  478. for( int i = 0; i < pPane->GetResultsPaneCount(); i++ )
  479. {
  480. LPCONSOLE2 lpConsole = pPane->GetResultsPane(i)->GetConsolePtr();
  481. HRESULT hr = lpConsole->Expand(GetItemHandle(),bExpand);
  482. CHECKHRESULT(hr);
  483. lpConsole->Release();
  484. }
  485. }
  486. void CScopePaneItem::SortItems()
  487. {
  488. if( m_Children.GetSize() == 1 )
  489. return;
  490. bool bSorted = false;
  491. bool bDirty = false;
  492. while( !bSorted )
  493. {
  494. bSorted = true;
  495. for( int i = 0; i < m_Children.GetSize()-1; i++ )
  496. {
  497. CScopePaneItem* pItem1 = m_Children[i];
  498. CScopePaneItem* pItem2 = m_Children[i+1];
  499. TRACE(_T("%s > %s\n"),pItem1->GetDisplayName(),pItem2->GetDisplayName());
  500. if( pItem1->GetDisplayName().CompareNoCase(pItem2->GetDisplayName()) > 0 )
  501. {
  502. TRACE(_T("Swapping %s with %s.\n"),pItem1->GetDisplayName(),pItem2->GetDisplayName());
  503. m_Children.SetAt(i,pItem2);
  504. m_Children.SetAt(i+1,pItem1);
  505. bSorted = false;
  506. bDirty = true;
  507. }
  508. }
  509. }
  510. /*
  511. if( bDirty )
  512. {
  513. LPCONSOLENAMESPACE2 lpNamespace = GetScopePane()->GetConsoleNamespacePtr();
  514. for( int i = 0; i < m_Children.GetSize(); i++ )
  515. {
  516. lpNamespace->DeleteItem(m_Children[i]->GetItemHandle(),1L);
  517. m_Children[i]->InsertItem(i);
  518. }
  519. lpNamespace->Release();
  520. }
  521. */
  522. }
  523. void CScopePaneItem::ShowItem()
  524. {
  525. TRACEX(_T("CScopePaneItem::ShowItem\n"));
  526. if( m_bVisible )
  527. {
  528. TRACE(_T("WARNING : Item is already visible.\n"));
  529. return;
  530. }
  531. if( ! InsertItem(0) )
  532. {
  533. TRACE(_T("FAILED : InsertItem failed.\n"));
  534. return;
  535. }
  536. m_bVisible = true;
  537. }
  538. void CScopePaneItem::HideItem()
  539. {
  540. TRACEX(_T("CScopePaneItem::HideItem\n"));
  541. if( !m_bVisible )
  542. {
  543. TRACE(_T("WARNING : Item is already hidden.\n"));
  544. return;
  545. }
  546. if( ! DeleteItem() )
  547. {
  548. TRACE(_T("FAILED : DeleteItem failed.\n"));
  549. }
  550. m_bVisible = false;
  551. }
  552. bool CScopePaneItem::IsItemVisible() const
  553. {
  554. TRACEX(_T("CScopePaneItem::IsItemVisible\n"));
  555. return m_bVisible;
  556. }
  557. HSCOPEITEM CScopePaneItem::GetItemHandle()
  558. {
  559. TRACEX(_T("CScopePaneItem::GetItemHandle\n"));
  560. return m_hItemHandle;
  561. }
  562. void CScopePaneItem::SetItemHandle(HSCOPEITEM hItem)
  563. {
  564. TRACEX(_T("CScopePaneItem::SetItemHandle\n"));
  565. TRACEARGn(hItem);
  566. m_hItemHandle = hItem;
  567. }
  568. LPGUID CScopePaneItem::GetItemType()
  569. {
  570. TRACEX(_T("CScopePaneItem::GetItemType\n"));
  571. if( ! GfxCheckPtr(m_lpguidItemType,GUID) )
  572. {
  573. TRACE(_T("FAILED : m_lpguidItemType is an invalid pointer.\n"));
  574. return NULL;
  575. }
  576. return m_lpguidItemType;
  577. }
  578. HRESULT CScopePaneItem::WriteExtensionData(LPSTREAM pStream)
  579. {
  580. TRACEX(_T("CScopePaneItem::WriteExtensionData\n"));
  581. TRACEARGn(pStream);
  582. return S_OK;
  583. }
  584. /////////////////////////////////////////////////////////////////////////////
  585. // Display Name Members
  586. CString CScopePaneItem::GetDisplayName(int nIndex /*= 0*/)
  587. {
  588. TRACEX(_T("CScopePaneItem::GetDisplayName\n"));
  589. TRACEARGn(nIndex);
  590. if( nIndex >= m_saDisplayNames.GetSize() || nIndex < 0 )
  591. {
  592. TRACE(_T("FAILED : nIndex is out of array bounds.\n"));
  593. return _T("");
  594. }
  595. return m_saDisplayNames[nIndex];
  596. }
  597. CStringArray& CScopePaneItem::GetDisplayNames()
  598. {
  599. TRACEX(_T("CScopePaneItem::GetDisplayNames\n"));
  600. return m_saDisplayNames;
  601. }
  602. void CScopePaneItem::SetDisplayName(int nIndex, const CString& sName)
  603. {
  604. TRACEX(_T("CScopePaneItem::SetDisplayName\n"));
  605. TRACEARGn(nIndex);
  606. if( nIndex >= m_saDisplayNames.GetSize() || nIndex < 0 )
  607. {
  608. TRACE(_T("WARNING : nIndex is out of array bounds. The string will be added to Display Names.\n"));
  609. m_saDisplayNames.InsertAt(nIndex,sName);
  610. return;
  611. }
  612. m_saDisplayNames.SetAt(nIndex,sName);
  613. }
  614. void CScopePaneItem::SetDisplayNames(const CStringArray& saNames)
  615. {
  616. TRACEX(_T("CScopePaneItem::SetDisplayNames\n"));
  617. TRACEARGn(saNames.GetSize());
  618. m_saDisplayNames.Copy(saNames);
  619. }
  620. /////////////////////////////////////////////////////////////////////////////
  621. // Icon Members
  622. void CScopePaneItem::SetIconIndex(int iIndex)
  623. {
  624. TRACEX(_T("CScopePaneItem::SetIconIndex\n"));
  625. TRACEARGn(iIndex);
  626. if( iIndex >= m_IconResIds.GetSize() || iIndex < 0 )
  627. {
  628. TRACE(_T("FAILED : iIndex is out of array bounds.\n"));
  629. return;
  630. }
  631. m_iCurrentIconIndex = iIndex;
  632. }
  633. int CScopePaneItem::GetIconIndex()
  634. {
  635. TRACEX(_T("CScopePaneItem::GetIconIndex\n"));
  636. if( m_iCurrentIconIndex >= m_IconResIds.GetSize() || m_iCurrentIconIndex < 0 )
  637. {
  638. TRACE(_T("WARNING : m_iCurrentIconIndex is out of array bounds.\n"));
  639. return -1;
  640. }
  641. return m_iCurrentIconIndex;
  642. }
  643. UINT CScopePaneItem::GetIconId()
  644. {
  645. TRACEX(_T("CScopePaneItem::GetIconId\n"));
  646. if( GetIconIndex() == -1 )
  647. {
  648. TRACE(_T("FAILED : m_iCurrentIconIndex is out of array bounds.\n"));
  649. return 0;
  650. }
  651. return m_IconResIds[GetIconIndex()];
  652. }
  653. CUIntArray& CScopePaneItem::GetIconIds()
  654. {
  655. TRACEX(_T("CScopePaneItem::GetIconId\n"));
  656. return m_IconResIds;
  657. }
  658. void CScopePaneItem::SetOpenIconIndex(int iIndex)
  659. {
  660. TRACEX(_T("CScopePaneItem::SetOpenIconIndex\n"));
  661. TRACEARGn(iIndex);
  662. if( iIndex >= m_OpenIconResIds.GetSize() || iIndex < 0 )
  663. {
  664. TRACE(_T("FAILED : iIndex is out of array bounds.\n"));
  665. return;
  666. }
  667. m_iCurrentOpenIconIndex = iIndex;
  668. }
  669. int CScopePaneItem::GetOpenIconIndex()
  670. {
  671. TRACEX(_T("CScopePaneItem::GetOpenIconIndex\n"));
  672. if( m_iCurrentOpenIconIndex >= m_OpenIconResIds.GetSize() || m_iCurrentOpenIconIndex < 0 )
  673. {
  674. TRACE(_T("WARNING : m_iCurrentOpenIconIndex is out of array bounds.\n"));
  675. return -1;
  676. }
  677. return m_iCurrentOpenIconIndex;
  678. }
  679. UINT CScopePaneItem::GetOpenIconId()
  680. {
  681. TRACEX(_T("CScopePaneItem::GetOpenIconId\n"));
  682. if( GetOpenIconIndex() == -1 )
  683. {
  684. TRACE(_T("FAILED : m_iCurrentOpenIconIndex is out of array bounds.\n"));
  685. return 0;
  686. }
  687. return m_OpenIconResIds[GetOpenIconIndex()];
  688. }
  689. /////////////////////////////////////////////////////////////////////////////
  690. // Property Sheet Members
  691. bool CScopePaneItem::IsPropertySheetOpen(bool bSearchChildren /*=false*/)
  692. {
  693. TRACEX(_T("CScopePaneItem::IsPropertySheetOpen\n"));
  694. // this function attempts to bring up an open property sheet for this scope item
  695. // if it succeeds, then the property sheet is brought to the foreground
  696. // if it fails, then there are no open property sheets for the scope item
  697. if( ! GetScopePane() )
  698. {
  699. TRACE(_T("FAILED : m_pScopePane is not a valid pointer.\n"));
  700. return false;
  701. }
  702. LPCONSOLE2 lpConsole = m_pScopePane->GetConsolePtr();
  703. if( ! GfxCheckPtr(lpConsole,IConsole2) )
  704. {
  705. TRACE(_T("FAILED : lpConsole is not a valid pointer.\n"));
  706. return false;
  707. }
  708. // get a reference to the IPropertySheetProvider interface
  709. LPPROPERTYSHEETPROVIDER lpProvider = NULL;
  710. HRESULT hr = lpConsole->QueryInterface(IID_IPropertySheetProvider,(LPVOID*)&lpProvider);
  711. if( ! CHECKHRESULT(hr) )
  712. {
  713. TRACE(_T("IConsole2::QueryInterface failed.\n"));
  714. lpConsole->Release();
  715. return FALSE;
  716. }
  717. ASSERT(lpProvider);
  718. // create an IDataObject for this scope item
  719. CSnapinDataObject* pdoNew = NULL;
  720. pdoNew = new CSnapinDataObject;
  721. if( ! GfxCheckObjPtr(pdoNew,CSnapinDataObject) )
  722. {
  723. TRACE(_T("FAILED : Out of memory.\n"));
  724. lpProvider->Release();
  725. lpConsole->Release();
  726. return false;
  727. }
  728. LPDATAOBJECT lpDataObject = (LPDATAOBJECT)pdoNew->GetInterface(&IID_IDataObject);
  729. ASSERT(lpDataObject);
  730. pdoNew->SetItem(this);
  731. for( int i = 0; i < m_pScopePane->GetResultsPaneCount(); i++ )
  732. {
  733. CResultsPane* pResultsPane = m_pScopePane->GetResultsPane(i);
  734. if( GfxCheckObjPtr(pResultsPane,CResultsPane) )
  735. {
  736. LPCOMPONENT pComponent = (LPCOMPONENT)pResultsPane->GetInterface(&IID_IComponent);
  737. hr = lpProvider->FindPropertySheet(MMC_COOKIE(this),pComponent,lpDataObject);
  738. if( hr == S_OK )
  739. break;
  740. }
  741. }
  742. lpProvider->Release();
  743. lpConsole->Release();
  744. delete pdoNew;
  745. if( hr == S_FALSE || ! CHECKHRESULT(hr) )
  746. {
  747. TRACE(_T("INFO : No property sheets were open for this node.\n"));
  748. if( bSearchChildren ) // search children for open sheets if requested
  749. {
  750. for( int k = 0; k < GetChildCount(); k++ )
  751. {
  752. if( GetChild(k) && GetChild(k)->IsPropertySheetOpen(true) )
  753. {
  754. return true;
  755. }
  756. }
  757. }
  758. return false;
  759. }
  760. else
  761. {
  762. return true;
  763. }
  764. return false;
  765. }
  766. bool CScopePaneItem::InvokePropertySheet()
  767. {
  768. TRACEX(_T("CScopePaneItem::InvokePropertySheet\n"));
  769. // this function programmatically invokes a property sheet for a scope pane item
  770. // see M. Maguire's doc on IAS snapin design for a detailed description on just what
  771. // is going on here. I cannot claim this as my own. :-)
  772. // first see if a property sheet for this item is open already
  773. // if( IsPropertySheetOpen() )
  774. // {
  775. // return true;
  776. // }
  777. if( ! GetScopePane() )
  778. {
  779. TRACE(_T("FAILED : m_pScopePane is not a valid pointer.\n"));
  780. return false;
  781. }
  782. LPCONSOLE2 lpConsole = m_pScopePane->GetConsolePtr();
  783. if( ! GfxCheckPtr(lpConsole,IConsole2) )
  784. {
  785. TRACE(_T("FAILED : lpConsole is not a valid pointer.\n"));
  786. return false;
  787. }
  788. // get a reference to the IPropertySheetProvider interface
  789. LPPROPERTYSHEETPROVIDER lpProvider = NULL;
  790. HRESULT hr = lpConsole->QueryInterface(IID_IPropertySheetProvider,(LPVOID*)&lpProvider);
  791. if( ! CHECKHRESULT(hr) )
  792. {
  793. TRACE(_T("IConsole2::QueryInterface failed.\n"));
  794. lpConsole->Release();
  795. return FALSE;
  796. }
  797. ASSERT(lpProvider);
  798. // create an IDataObject for this scope item
  799. CSnapinDataObject* pdoNew = NULL;
  800. pdoNew = new CSnapinDataObject;
  801. if( ! GfxCheckObjPtr(pdoNew,CSnapinDataObject) )
  802. {
  803. TRACE(_T("FAILED : Out of memory.\n"));
  804. lpProvider->Release();
  805. lpConsole->Release();
  806. return false;
  807. }
  808. LPDATAOBJECT lpDataObject = (LPDATAOBJECT)pdoNew->GetInterface(&IID_IDataObject);
  809. ASSERT(lpDataObject);
  810. pdoNew->SetItem(this);
  811. hr = lpProvider->CreatePropertySheet(GetDisplayName(),TRUE,MMC_COOKIE(this),lpDataObject,MMC_PSO_HASHELP);
  812. if( ! CHECKHRESULT(hr) )
  813. {
  814. TRACE(_T("FAILED : IPropertySheetProvider::CreatePropertySheet failed.\n"));
  815. lpProvider->Release();
  816. lpConsole->Release();
  817. delete pdoNew;
  818. return false;
  819. }
  820. HWND hWndNotification = NULL;
  821. HWND hWndMain = NULL;
  822. hr = lpConsole->GetMainWindow(&hWndMain);
  823. if( ! CHECKHRESULT(hr) )
  824. {
  825. // Release data allocated in CreatePropertySheet
  826. lpProvider->Show( -1, 0);
  827. lpProvider->Release();
  828. lpConsole->Release();
  829. delete pdoNew;
  830. return false;
  831. }
  832. // Try to get the correct window that notifications should be sent to.
  833. hWndNotification = FindWindowEx( hWndMain, NULL, _T("MDIClient"), NULL );
  834. hWndNotification = FindWindowEx( hWndNotification, NULL, _T("MMCChildFrm"), NULL );
  835. hWndNotification = FindWindowEx( hWndNotification, NULL, _T("MMCView"), NULL );
  836. if( hWndNotification == NULL )
  837. {
  838. // It was a nice try, but it failed, so we should be able to get by by using the main HWND.
  839. hWndNotification = hWndMain;
  840. }
  841. LPCOMPONENTDATA lpComponentData = (LPCOMPONENTDATA)m_pScopePane->GetInterface(&IID_IComponentData);
  842. hr = lpProvider->AddPrimaryPages(lpComponentData,TRUE,hWndNotification,TRUE);
  843. if( ! CHECKHRESULT(hr) )
  844. {
  845. // Release data allocated in CreatePropertySheet
  846. lpProvider->Show(-1,0);
  847. lpProvider->Release();
  848. lpConsole->Release();
  849. delete pdoNew;
  850. return false;
  851. }
  852. hr = lpProvider->AddExtensionPages();
  853. if( ! CHECKHRESULT(hr) )
  854. {
  855. // ISSUE: Should I care if this fails?
  856. TRACE(_T("WARNING : PROPERTYSHEETPROVIDER::AddExtensionPages failed.\n"));
  857. // Release data allocated in CreatePropertySheet
  858. // lpProvider->Show( -1, 0);
  859. // lpProvider->Release();
  860. // lpConsole->Release();
  861. // delete pdoNew;
  862. // return false;
  863. }
  864. // v-marfin : 62962 Show "details" page on a new creation
  865. BOOL bIsNewDataGroup = this->IsKindOf(RUNTIME_CLASS(CDataGroupScopeItem));
  866. int nShowPage = bIsNewDataGroup ? 0 : 1;
  867. #ifndef IA64
  868. hr = lpProvider->Show( (long) hWndMain, nShowPage); //59643b
  869. #endif // IA64
  870. if( ! CHECKHRESULT( hr ) )
  871. {
  872. // Release data allocated in CreatePropertySheet
  873. lpProvider->Show( -1, 0);
  874. lpProvider->Release();
  875. lpConsole->Release();
  876. delete pdoNew;
  877. return false;
  878. }
  879. lpProvider->Release();
  880. lpConsole->Release();
  881. lpDataObject->Release();
  882. // delete pdoNew;
  883. return true;
  884. }
  885. /////////////////////////////////////////////////////////////////////////////
  886. // Context Menu Members
  887. // v-marfin 59644 : Modified prototype to allow passing to selected item count.
  888. // Only allow 3rd party menu item if ony 1 item is selected.
  889. bool CScopePaneItem::InvokeContextMenu(const CPoint& pt, int iSelectedCount)
  890. {
  891. TRACEX(_T("CScopePaneItem::InvokeContextMenu\n"));
  892. TRACEARGn(pt.x);
  893. TRACEARGn(pt.y);
  894. if( ! GetScopePane() )
  895. {
  896. TRACE(_T("FAILED : m_pScopePane is not a valid pointer.\n"));
  897. return false;
  898. }
  899. LPCONSOLE2 lpConsole = m_pScopePane->GetConsolePtr();
  900. if( ! GfxCheckPtr(lpConsole,IConsole2) )
  901. {
  902. TRACE(_T("FAILED : lpConsole is not a valid pointer.\n"));
  903. return false;
  904. }
  905. // get a reference to the IContextMenuProvider interface
  906. LPCONTEXTMENUPROVIDER lpProvider = NULL;
  907. HRESULT hr = lpConsole->QueryInterface(IID_IContextMenuProvider,(LPVOID*)&lpProvider);
  908. if( ! CHECKHRESULT(hr) )
  909. {
  910. TRACE(_T("IConsole2::QueryInterface failed.\n"));
  911. lpConsole->Release();
  912. return FALSE;
  913. }
  914. ASSERT(lpProvider);
  915. // just in case
  916. hr = lpProvider->EmptyMenuList();
  917. // populate the menu
  918. CONTEXTMENUITEM cmi;
  919. CString sResString;
  920. CString sResString2;
  921. ZeroMemory(&cmi,sizeof(CONTEXTMENUITEM));
  922. // add the top insertion point
  923. cmi.lCommandID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  924. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_ROOT_MENU;
  925. cmi.fSpecialFlags = CCM_SPECIAL_INSERTION_POINT;
  926. hr = lpProvider->AddItem(&cmi);
  927. // add new menu and insertion point
  928. sResString.LoadString(IDS_STRING_NEW);
  929. cmi.strName = LPTSTR(LPCTSTR(sResString));
  930. sResString2.LoadString(IDS_STRING_NEW_DESCRIPTION);
  931. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  932. cmi.lCommandID = CCM_INSERTIONPOINTID_PRIMARY_NEW;
  933. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  934. cmi.fFlags = MF_POPUP;
  935. cmi.fSpecialFlags = CCM_SPECIAL_SUBMENU;
  936. hr = lpProvider->AddItem(&cmi);
  937. cmi.lCommandID = CCM_INSERTIONPOINTID_PRIMARY_NEW;
  938. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  939. cmi.fSpecialFlags = CCM_SPECIAL_INSERTION_POINT;
  940. hr = lpProvider->AddItem(&cmi);
  941. // add task menu and insertion point
  942. sResString.LoadString(IDS_STRING_TASK);
  943. cmi.strName = LPTSTR(LPCTSTR(sResString));
  944. sResString2.LoadString(IDS_STRING_TASK_DESCRIPTION);
  945. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  946. cmi.lCommandID = CCM_INSERTIONPOINTID_PRIMARY_TASK;
  947. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  948. cmi.fFlags = MF_POPUP;
  949. cmi.fSpecialFlags = CCM_SPECIAL_SUBMENU;
  950. hr = lpProvider->AddItem(&cmi);
  951. cmi.lCommandID = CCM_INSERTIONPOINTID_PRIMARY_TASK;
  952. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  953. cmi.fSpecialFlags = CCM_SPECIAL_INSERTION_POINT;
  954. hr = lpProvider->AddItem(&cmi);
  955. // create an IDataObject for this scope item
  956. CSnapinDataObject* pdoNew = NULL;
  957. pdoNew = new CSnapinDataObject;
  958. if( ! GfxCheckObjPtr(pdoNew,CSnapinDataObject) )
  959. {
  960. TRACE(_T("FAILED : Out of memory.\n"));
  961. lpProvider->Release();
  962. lpConsole->Release();
  963. return false;
  964. }
  965. LPDATAOBJECT lpDataObject = (LPDATAOBJECT)pdoNew->GetInterface(&IID_IDataObject);
  966. ASSERT(lpDataObject);
  967. pdoNew->SetItem(this);
  968. LPUNKNOWN lpUnknown = (LPUNKNOWN)GetScopePane()->GetInterface(&IID_IExtendContextMenu);
  969. hr = lpProvider->AddPrimaryExtensionItems(lpUnknown,lpDataObject);
  970. // v-marfin 59644 : Only allow 3rd party menu items if only 1 item is selected
  971. // in the results pane view.
  972. if (iSelectedCount == 1)
  973. {
  974. // add third party insertion points
  975. cmi.lCommandID = CCM_INSERTIONPOINTID_3RDPARTY_NEW;
  976. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_NEW;
  977. cmi.fSpecialFlags = CCM_SPECIAL_INSERTION_POINT;
  978. hr = lpProvider->AddItem(&cmi);
  979. cmi.lCommandID = CCM_INSERTIONPOINTID_3RDPARTY_TASK;
  980. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TASK;
  981. cmi.fSpecialFlags = CCM_SPECIAL_INSERTION_POINT;
  982. hr = lpProvider->AddItem(&cmi);
  983. hr = lpProvider->AddThirdPartyExtensionItems(lpDataObject);
  984. }
  985. HWND hWndMain = NULL;
  986. hr = lpConsole->GetMainWindow(&hWndMain);
  987. // Try to get the correct window that notifications should be sent to.
  988. HWND hWndNotification = FindWindowEx( hWndMain, NULL, _T("MDIClient"), NULL );
  989. hWndNotification = FindWindowEx( hWndNotification, NULL, _T("MMCChildFrm"), NULL );
  990. hWndNotification = FindWindowEx( hWndNotification, NULL, _T("AfxFrameOrView42u"), NULL );
  991. if( hWndNotification == NULL )
  992. {
  993. // It was a nice try, but it failed, so we should be able to get by by using the main HWND.
  994. hWndNotification = hWndMain;
  995. }
  996. long lSelected = 0L;
  997. hr = lpProvider->ShowContextMenu(hWndNotification,pt.x,pt.y,&lSelected);
  998. lpProvider->Release();
  999. lpConsole->Release();
  1000. lpDataObject->Release();
  1001. return true;
  1002. }
  1003. /////////////////////////////////////////////////////////////////////////////
  1004. // Help Topic
  1005. CString CScopePaneItem::GetHelpTopic() const
  1006. {
  1007. TRACEX(_T("CScopePaneItem::GetHelpTopic\n"));
  1008. return m_sHelpTopic;
  1009. }
  1010. void CScopePaneItem::SetHelpTopic(const CString& sTopic)
  1011. {
  1012. TRACEX(_T("CScopePaneItem::SetHelpTopic\n"));
  1013. TRACEARGs(sTopic);
  1014. if( sTopic.IsEmpty() )
  1015. {
  1016. TRACE(_T("WARNING : sTopic is an empty string.\n"));
  1017. }
  1018. m_sHelpTopic = sTopic;
  1019. }
  1020. /////////////////////////////////////////////////////////////////////////////
  1021. // Messaging Members
  1022. LRESULT CScopePaneItem::MsgProc(UINT msg, WPARAM wparam, LPARAM lparam)
  1023. {
  1024. TRACEX(_T("CScopePaneItem::MsgProc\n"));
  1025. TRACEARGn(msg);
  1026. TRACEARGn(wparam);
  1027. TRACEARGn(lparam);
  1028. // propagate to all children
  1029. for( int i=0; i < m_Children.GetSize(); i++ )
  1030. {
  1031. // stop if a return value of -1 is given
  1032. if( m_Children[i]->MsgProc(msg,wparam,lparam) == -1L )
  1033. {
  1034. return -1L;
  1035. }
  1036. }
  1037. return 0L;
  1038. }
  1039. /////////////////////////////////////////////////////////////////////////////
  1040. // MMC Notify Handlers
  1041. HRESULT CScopePaneItem::OnActivate(BOOL bActivated)
  1042. {
  1043. TRACEX(_T("CScopePaneItem::OnActivate\n"));
  1044. TRACEARGn(bActivated);
  1045. return S_OK;
  1046. }
  1047. HRESULT CScopePaneItem::OnAddImages(CResultsPane* pPane)
  1048. {
  1049. TRACEX(_T("CScopePaneItem::OnAddImages\n"));
  1050. TRACEARGn(pPane);
  1051. if( ! GfxCheckObjPtr(pPane,CResultsPane) )
  1052. {
  1053. TRACE(_T("FAILED : pPane is not a valid pointer to an object.\n"));
  1054. return E_FAIL;
  1055. }
  1056. pPane->AddIcon(GetIconId());
  1057. return S_OK;
  1058. }
  1059. HRESULT CScopePaneItem::OnAddMenuItems(LPCONTEXTMENUCALLBACK piCallback,long __RPC_FAR *pInsertionAllowed)
  1060. {
  1061. TRACEX(_T("CScopePaneItem::OnAddMenuItems\n"));
  1062. TRACEARGn(piCallback);
  1063. TRACEARGn(pInsertionAllowed);
  1064. return S_OK;
  1065. }
  1066. HRESULT CScopePaneItem::OnBtnClick(MMC_CONSOLE_VERB verb)
  1067. {
  1068. TRACEX(_T("CScopePaneItem::OnBtnClick\n"));
  1069. TRACEARGn(verb);
  1070. return S_OK;
  1071. }
  1072. HRESULT CScopePaneItem::OnCommand(long lCommandID)
  1073. {
  1074. TRACEX(_T("CScopePaneItem::OnCommand\n"));
  1075. TRACEARGn(lCommandID);
  1076. return S_OK;
  1077. }
  1078. HRESULT CScopePaneItem::OnContextHelp()
  1079. {
  1080. TRACEX(_T("CScopePaneItem::OnContextHelp\n"));
  1081. if( GetScopePane() == NULL )
  1082. {
  1083. TRACE(_T("FAILED : m_pScopePane is not a valid pointer.\n"));
  1084. return E_FAIL;
  1085. }
  1086. // v-marfin 62478 : Set help topic based on type of object
  1087. //--------------------------------------------------------
  1088. if (GfxCheckObjPtr(this,CRootScopeItem)) // HealthMonitor level, top level
  1089. {
  1090. m_sHelpTopic = _T("HMon21.chm::/oroot.htm");
  1091. }
  1092. else if (GfxCheckObjPtr(this,CAllSystemsScopeItem)) // All Monitored Computers
  1093. {
  1094. m_sHelpTopic = _T("HMon21.chm::/oallmon.htm");
  1095. }
  1096. else if (GfxCheckObjPtr(this,CSystemScopeItem)) // Monitored Computer
  1097. {
  1098. m_sHelpTopic = _T("HMon21.chm::/ocomp.htm");
  1099. }
  1100. else if (GfxCheckObjPtr(this,CActionPolicyScopeItem)) // Actions
  1101. {
  1102. m_sHelpTopic = _T("HMon21.chm::/oact.htm");
  1103. }
  1104. else if (GfxCheckObjPtr(this,CDataGroupScopeItem)) // Data Group
  1105. {
  1106. m_sHelpTopic = _T("HMon21.chm::/odatagrp.htm");
  1107. }
  1108. else if (GfxCheckObjPtr(this,CDataElementScopeItem)) // Data Collector
  1109. {
  1110. m_sHelpTopic = _T("HMon21.chm::/odatacol.htm");
  1111. }
  1112. else if (GfxCheckObjPtr(this,CRuleScopeItem)) // Threshold
  1113. {
  1114. m_sHelpTopic = _T("HMon21.chm::/othreshold.htm");
  1115. }
  1116. //--------------------------------------------------------
  1117. if( m_sHelpTopic.IsEmpty() )
  1118. {
  1119. return S_OK;
  1120. }
  1121. LPCONSOLE2 lpConsole = m_pScopePane->GetConsolePtr();
  1122. if( ! GfxCheckPtr(lpConsole,IConsole2) )
  1123. {
  1124. TRACE(_T("FAILED : lpConsole is not a valid pointer.\n"));
  1125. return E_FAIL;
  1126. }
  1127. IDisplayHelp* pidh = NULL;
  1128. HRESULT hr = lpConsole->QueryInterface(IID_IDisplayHelp,(LPVOID*)&pidh);
  1129. ASSERT(pidh);
  1130. if( pidh == NULL || ! CHECKHRESULT(hr) )
  1131. {
  1132. TRACE(_T("Failed on IConsole2::QI(IID_IDisplayHelp).\n"));
  1133. return hr;
  1134. }
  1135. LPOLESTR lpCompiledHelpFile = reinterpret_cast<LPOLESTR>(CoTaskMemAlloc((m_sHelpTopic.GetLength() + 1)* sizeof(TCHAR)));
  1136. if( lpCompiledHelpFile == NULL )
  1137. {
  1138. TRACE(_T("FAILED : Out of memory.\n"));
  1139. return E_OUTOFMEMORY;
  1140. }
  1141. _tcscpy(lpCompiledHelpFile, (LPCTSTR)m_sHelpTopic);
  1142. hr = pidh->ShowTopic(lpCompiledHelpFile);
  1143. pidh->Release();
  1144. lpConsole->Release();
  1145. return hr;
  1146. }
  1147. HRESULT CScopePaneItem::OnCreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider, INT_PTR handle)
  1148. {
  1149. TRACEX(_T("CScopePaneItem::OnCreatePropertyPages\n"));
  1150. TRACEARGn(lpProvider);
  1151. TRACEARGn(handle);
  1152. // return S_FALSE to indicate that no property pages will be created
  1153. return S_FALSE;
  1154. }
  1155. HRESULT CScopePaneItem::OnCutOrMove()
  1156. {
  1157. TRACEX(_T("CScopePaneItem::OnCutOrMove\n"));
  1158. return S_OK;
  1159. }
  1160. HRESULT CScopePaneItem::OnDelete(BOOL bConfirm) // v-marfin 60298
  1161. {
  1162. TRACEX(_T("CScopePaneItem::OnDelete\n"));
  1163. return S_OK;
  1164. }
  1165. HRESULT CScopePaneItem::OnExpand(BOOL bExpand)
  1166. {
  1167. TRACEX(_T("CScopePaneItem::OnExpand\n"));
  1168. TRACEARGn(bExpand);
  1169. if( bExpand )
  1170. {
  1171. // for each child call InsertItem to insert into namespace
  1172. for( int i=0; i < m_Children.GetSize(); i++ )
  1173. {
  1174. if( ! m_Children[i]->InsertItem(i) )
  1175. {
  1176. TRACE(_T("FAILED : CScopePaneItem::InsertItem failed.\n"));
  1177. }
  1178. }
  1179. }
  1180. return S_OK;
  1181. }
  1182. HRESULT CScopePaneItem::OnGetDisplayInfo(int nColumnIndex, LPTSTR* ppString)
  1183. {
  1184. TRACEX(_T("CScopePaneItem::OnGetDisplayInfo\n"));
  1185. TRACEARGn(nColumnIndex);
  1186. TRACEARGn(ppString);
  1187. if( nColumnIndex < 0 || nColumnIndex >= m_saDisplayNames.GetSize() )
  1188. {
  1189. TRACE(_T("FAILED : The column index is out of the display name array bounds"));
  1190. return E_FAIL;
  1191. }
  1192. *ppString = LPTSTR(LPCTSTR(GetDisplayName(nColumnIndex)));
  1193. return S_OK;
  1194. }
  1195. HRESULT CScopePaneItem::OnGetResultViewType(CString& sViewType,long& lViewOptions)
  1196. {
  1197. TRACEX(_T("CScopePaneItem::OnGetResultViewType\n"));
  1198. TRACEARGs(sViewType);
  1199. TRACEARGn(lViewOptions);
  1200. if( ! GetResultsPaneView() )
  1201. {
  1202. return E_FAIL;
  1203. }
  1204. return m_pResultsPaneView->OnGetResultViewType(sViewType,lViewOptions);
  1205. }
  1206. HRESULT CScopePaneItem::OnListpad(BOOL bAttachingListCtrl)
  1207. {
  1208. TRACEX(_T("CScopePaneItem::OnListpad\n"));
  1209. TRACEARGn(bAttachingListCtrl);
  1210. return S_OK;
  1211. }
  1212. HRESULT CScopePaneItem::OnMinimized(BOOL bMinimized)
  1213. {
  1214. TRACEX(_T("CScopePaneItem::OnMinimized\n"));
  1215. TRACEARGn(bMinimized);
  1216. return S_OK;
  1217. }
  1218. HRESULT CScopePaneItem::OnPaste(LPDATAOBJECT pSelectedItems, LPDATAOBJECT* ppCopiedItems)
  1219. {
  1220. TRACEX(_T("CScopePaneItem::OnPaste\n"));
  1221. TRACEARGn(pSelectedItems);
  1222. TRACEARGn(ppCopiedItems);
  1223. return S_OK;
  1224. }
  1225. HRESULT CScopePaneItem::OnPropertyChange(LPARAM lParam)
  1226. {
  1227. TRACEX(_T("CScopePaneItem::OnPropertyChange\n"));
  1228. TRACEARGn(lParam);
  1229. return S_OK;
  1230. }
  1231. HRESULT CScopePaneItem::OnQueryPagesFor()
  1232. {
  1233. TRACEX(_T("CScopePaneItem::OnQueryPagesFor\n"));
  1234. return S_OK;
  1235. }
  1236. HRESULT CScopePaneItem::OnQueryPaste(LPDATAOBJECT pDataObject)
  1237. {
  1238. TRACEX(_T("CScopePaneItem::OnQueryPaste\n"));
  1239. TRACEARGn(pDataObject);
  1240. return S_OK;
  1241. }
  1242. HRESULT CScopePaneItem::OnRefresh()
  1243. {
  1244. TRACEX(_T("CScopePaneItem::OnRefresh\n"));
  1245. return S_OK;
  1246. }
  1247. HRESULT CScopePaneItem::OnRemoveChildren()
  1248. {
  1249. TRACEX(_T("CScopePaneItem::OnRemoveChildren\n"));
  1250. for( int i = 0; i < GetChildCount(); i++ )
  1251. {
  1252. CScopePaneItem* pItem = GetChild(i);
  1253. if( pItem )
  1254. {
  1255. if( ! pItem->DeleteItem() )
  1256. {
  1257. TRACE(_T("WARNING : CScopePaneItem::DeleteItem returns false.\n"));
  1258. }
  1259. }
  1260. }
  1261. return S_OK;
  1262. }
  1263. HRESULT CScopePaneItem::OnRename(const CString& sNewName)
  1264. {
  1265. TRACEX(_T("CScopePaneItem::OnRename\n"));
  1266. SetDisplayName(0,sNewName);
  1267. return S_OK;
  1268. }
  1269. HRESULT CScopePaneItem::OnRestoreView(MMC_RESTORE_VIEW* pRestoreView, BOOL* pbHandled)
  1270. {
  1271. TRACEX(_T("CScopePaneItem::OnRestoreView\n"));
  1272. TRACEARGn(pRestoreView);
  1273. TRACEARGn(pbHandled);
  1274. return S_OK;
  1275. }
  1276. HRESULT CScopePaneItem::OnSelect(CResultsPane* pPane, BOOL bSelected)
  1277. {
  1278. TRACEX(_T("CScopePaneItem::OnSelect\n"));
  1279. TRACEARGn(pPane);
  1280. TRACEARGn(bSelected);
  1281. if( ! GfxCheckObjPtr(pPane,CResultsPane) )
  1282. {
  1283. return E_FAIL;
  1284. }
  1285. LPCONSOLEVERB lpConsoleVerb = pPane->GetConsoleVerbPtr();
  1286. HRESULT hr = lpConsoleVerb->SetVerbState( MMC_VERB_REFRESH, ENABLED, TRUE );
  1287. if( ! CHECKHRESULT(hr) )
  1288. {
  1289. TRACE(_T("FAILED : IConsoleVerb::SetVerbState failed.\n"));
  1290. lpConsoleVerb->Release();
  1291. return hr;
  1292. }
  1293. hr = lpConsoleVerb->SetDefaultVerb( MMC_VERB_OPEN );
  1294. if( ! CHECKHRESULT(hr) )
  1295. {
  1296. TRACE(_T("FAILED : IConsoleVerb::SetDefaultVerb failed.\n"));
  1297. lpConsoleVerb->Release();
  1298. return hr;
  1299. }
  1300. lpConsoleVerb->Release();
  1301. return hr;
  1302. }
  1303. HRESULT CScopePaneItem::OnShow(CResultsPane* pPane, BOOL bSelecting)
  1304. {
  1305. TRACEX(_T("CScopePaneItem::OnShow\n"));
  1306. TRACEARGn(pPane);
  1307. TRACEARGn(bSelecting);
  1308. // first we need to track scope item selected since MMC does not do this
  1309. CScopePane* pScopePane = GetScopePane();
  1310. if( ! pScopePane )
  1311. {
  1312. TRACE(_T("FAILED : CScopePaneItem::GetScopePane returns NULL pointer.\n"));
  1313. return E_FAIL;
  1314. }
  1315. if( ! bSelecting ) // we are being de-selected so tell the scope pane !
  1316. {
  1317. pScopePane->SetSelectedScopeItem(NULL);
  1318. }
  1319. else
  1320. {
  1321. pScopePane->SetSelectedScopeItem(this);
  1322. }
  1323. if( ! GetResultsPaneView() )
  1324. {
  1325. TRACE(_T("FAILED : m_pResultsPaneView is not a valid pointer.\n"));
  1326. return E_FAIL;
  1327. }
  1328. return m_pResultsPaneView->OnShow(pPane,bSelecting,GetItemHandle());
  1329. }
  1330. /////////////////////////////////////////////////////////////////////////////
  1331. // MFC Operations
  1332. void CScopePaneItem::OnFinalRelease()
  1333. {
  1334. // When the last reference for an automation object is released
  1335. // OnFinalRelease is called. The base class will automatically
  1336. // deletes the object. Add additional cleanup required for your
  1337. // object before calling the base class.
  1338. CCmdTarget::OnFinalRelease();
  1339. }
  1340. BEGIN_MESSAGE_MAP(CScopePaneItem, CCmdTarget)
  1341. //{{AFX_MSG_MAP(CScopePaneItem)
  1342. // NOTE - the ClassWizard will add and remove mapping macros here.
  1343. //}}AFX_MSG_MAP
  1344. END_MESSAGE_MAP()
  1345. BEGIN_DISPATCH_MAP(CScopePaneItem, CCmdTarget)
  1346. //{{AFX_DISPATCH_MAP(CScopePaneItem)
  1347. // NOTE - the ClassWizard will add and remove mapping macros here.
  1348. //}}AFX_DISPATCH_MAP
  1349. END_DISPATCH_MAP()
  1350. // Note: we add support for IID_IScopePaneItem to support typesafe binding
  1351. // from VBA. This IID must match the GUID that is attached to the
  1352. // dispinterface in the .ODL file.
  1353. // {7D4A6861-9056-11D2-BD45-0000F87A3912}
  1354. static const IID IID_IScopePaneItem =
  1355. { 0x7d4a6861, 0x9056, 0x11d2, { 0xbd, 0x45, 0x0, 0x0, 0xf8, 0x7a, 0x39, 0x12 } };
  1356. BEGIN_INTERFACE_MAP(CScopePaneItem, CCmdTarget)
  1357. INTERFACE_PART(CScopePaneItem, IID_IScopePaneItem, Dispatch)
  1358. END_INTERFACE_MAP()
  1359. // {7D4A6862-9056-11D2-BD45-0000F87A3912}
  1360. IMPLEMENT_OLECREATE_EX(CScopePaneItem, "SnapIn.ScopePaneItem", 0x7d4a6862, 0x9056, 0x11d2, 0xbd, 0x45, 0x0, 0x0, 0xf8, 0x7a, 0x39, 0x12)
  1361. BOOL CScopePaneItem::CScopePaneItemFactory::UpdateRegistry(BOOL bRegister)
  1362. {
  1363. if (bRegister)
  1364. return AfxOleRegisterServerClass(m_clsid, m_lpszProgID, m_lpszProgID, m_lpszProgID, OAT_DISPATCH_OBJECT);
  1365. else
  1366. return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
  1367. }
  1368. /////////////////////////////////////////////////////////////////////////////
  1369. // CScopePaneItem message handlers