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.

528 lines
10 KiB

  1. // HMScopeItem.cpp: implementation of the CHMScopeItem class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. //
  5. // 04/07/00 v-marfin 62985 : do not allow paste into yourself
  6. //
  7. //
  8. //
  9. //
  10. //
  11. //
  12. #include "stdafx.h"
  13. #include "snapin.h"
  14. #include "HMScopeItem.h"
  15. #include "HMObject.h"
  16. #include "ScopePane.h"
  17. #include "SplitPaneResultsView.h"
  18. #include "HMResultsPaneItem.h"
  19. #ifdef _DEBUG
  20. #undef THIS_FILE
  21. static char THIS_FILE[]=__FILE__;
  22. #define new DEBUG_NEW
  23. #endif
  24. IMPLEMENT_DYNCREATE(CHMScopeItem,CScopePaneItem)
  25. //////////////////////////////////////////////////////////////////////
  26. // Construction/Destruction
  27. //////////////////////////////////////////////////////////////////////
  28. CHMScopeItem::CHMScopeItem()
  29. {
  30. m_pObject = NULL;
  31. m_sHelpTopic = _T("HMon21.chm::/ostart.htm");
  32. }
  33. CHMScopeItem::~CHMScopeItem()
  34. {
  35. CHMObject* pObject = GetObjectPtr();
  36. if( pObject )
  37. {
  38. for( int i = 0; i < pObject->GetScopeItemCount(); i++ )
  39. {
  40. if( pObject->GetScopeItem(i) == this )
  41. {
  42. pObject->RemoveScopeItem(i);
  43. break;
  44. }
  45. }
  46. }
  47. Destroy();
  48. }
  49. /////////////////////////////////////////////////////////////////////////////
  50. // State Management
  51. /////////////////////////////////////////////////////////////////////////////
  52. int CHMScopeItem::OnChangeChildState(int iNewState)
  53. {
  54. TRACEX(_T("CHMScopeItem::OnChangeChildState\n"));
  55. TRACEARGn(iNewState);
  56. // walk the list of children and determine the final state we should assume
  57. for( int i = 0; i < m_Children.GetSize(); i++ )
  58. {
  59. CHMScopeItem* pItem = (CHMScopeItem*)(m_Children[i]);
  60. int iItemState = pItem->GetIconIndex();
  61. if( iItemState > iNewState )
  62. {
  63. if( iItemState == GetIconIndex() )
  64. {
  65. return iItemState;
  66. }
  67. else
  68. {
  69. iNewState = iItemState;
  70. }
  71. }
  72. }
  73. SetIconIndex(iNewState);
  74. SetOpenIconIndex(iNewState);
  75. SetItem();
  76. // if the parent is an HMScopeItem, inform it of the state change
  77. CHMScopeItem* pParentItem = (CHMScopeItem*)GetParent();
  78. if( pParentItem && GfxCheckObjPtr(pParentItem,CHMScopeItem) )
  79. {
  80. pParentItem->OnChangeChildState(iNewState);
  81. }
  82. return iNewState;
  83. }
  84. /////////////////////////////////////////////////////////////////////////////
  85. // MMC-Related Item Members
  86. /////////////////////////////////////////////////////////////////////////////
  87. bool CHMScopeItem::InsertItem( int iIndex )
  88. {
  89. TRACEX(_T("CHMScopeItem::InsertItem\n"));
  90. bool bResult = CScopePaneItem::InsertItem(iIndex);
  91. // if the parent is the current selected scope item
  92. // and the parent's results view is of type CSplitPaneResultsView
  93. // and there is no results item for this scope item in the split pane
  94. // then add a new CHMResultsPaneItem to the results view for this scope item
  95. CScopePane* pPane = GetScopePane();
  96. if( pPane == NULL )
  97. {
  98. ASSERT(FALSE);
  99. return bResult;
  100. }
  101. if( !pPane->GetSelectedScopeItem() || !GetParent() || pPane->GetSelectedScopeItem() != GetParent() )
  102. {
  103. return bResult;
  104. }
  105. CResultsPaneView* pView = GetParent()->GetResultsPaneView();
  106. if( ! pView || ! pView->IsKindOf(RUNTIME_CLASS(CSplitPaneResultsView)) )
  107. {
  108. return bResult;
  109. }
  110. for( int i = 0; i < pView->GetItemCount(); i++ )
  111. {
  112. if( pView->GetItem(i)->GetDisplayName() == GetDisplayName() )
  113. {
  114. return bResult;
  115. }
  116. }
  117. CHMResultsPaneItem* pHMRPI = new CHMResultsPaneItem;
  118. CStringArray saNames;
  119. saNames.Copy(GetDisplayNames());
  120. CUIntArray iaIconIds;
  121. iaIconIds.Copy(GetIconIds());
  122. pHMRPI->Create(pView,saNames,iaIconIds,GetIconIndex());
  123. pHMRPI->SetToUpperPane();
  124. pView->AddItem(pHMRPI);
  125. return bResult;
  126. }
  127. bool CHMScopeItem::DeleteItem()
  128. {
  129. TRACEX(_T("CHMScopeItem::DeleteItem\n"));
  130. bool bResult = CScopePaneItem::DeleteItem();
  131. return bResult;
  132. }
  133. bool CHMScopeItem::SetItem()
  134. {
  135. TRACEX(_T("CHMScopeItem::SetItem\n"));
  136. bool bResult = CScopePaneItem::SetItem();
  137. CScopePane* pPane = GetScopePane();
  138. if( pPane == NULL )
  139. {
  140. ASSERT(FALSE);
  141. return bResult;
  142. }
  143. if( !pPane->GetSelectedScopeItem() || !GetParent() || pPane->GetSelectedScopeItem() != GetParent() )
  144. {
  145. return bResult;
  146. }
  147. CResultsPaneView* pView = GetParent()->GetResultsPaneView();
  148. if( ! pView || ! pView->IsKindOf(RUNTIME_CLASS(CSplitPaneResultsView)) )
  149. {
  150. return bResult;
  151. }
  152. for( int i = 0; i < pView->GetItemCount(); i++ )
  153. {
  154. if( pView->GetItem(i)->GetDisplayName() == GetDisplayName() )
  155. {
  156. CStringArray saNames;
  157. saNames.Copy(GetDisplayNames());
  158. CUIntArray iaIconIds;
  159. iaIconIds.Copy(GetIconIds());
  160. pView->GetItem(i)->SetDisplayNames(saNames);
  161. pView->GetItem(i)->SetIconIds(iaIconIds);
  162. pView->GetItem(i)->SetIconIndex(GetIconIndex());
  163. return pView->UpdateItem(pView->GetItem(i)) && bResult;
  164. }
  165. }
  166. return bResult;
  167. }
  168. HRESULT CHMScopeItem::WriteExtensionData(LPSTREAM pStream)
  169. {
  170. TRACEX(_T("CHMScopeItem::WriteExtensionData\n"));
  171. TRACEARGn(pStream);
  172. HRESULT hr = S_OK;
  173. ULONG ulSize = GetObjectPtr()->GetSystemName().GetLength() + 1;
  174. ulSize *= sizeof(TCHAR);
  175. if( ! CHECKHRESULT(hr = pStream->Write(GetObjectPtr()->GetSystemName(), ulSize, NULL)) )
  176. {
  177. return hr;
  178. }
  179. ulSize = GetObjectPtr()->GetObjectPath().GetLength() + 1;
  180. ulSize *= sizeof(TCHAR);
  181. if( ! CHECKHRESULT(hr = pStream->Write(GetObjectPtr()->GetObjectPath(), ulSize, NULL)) )
  182. {
  183. return hr;
  184. }
  185. ulSize = GetObjectPtr()->GetGuid().GetLength() + 1;
  186. ulSize *= sizeof(TCHAR);
  187. if( ! CHECKHRESULT(hr = pStream->Write(GetObjectPtr()->GetGuid(), ulSize, NULL)) )
  188. {
  189. return hr;
  190. }
  191. return S_OK;
  192. }
  193. //////////////////////////////////////////////////////////////////////
  194. // MMC Notify Handlers
  195. //////////////////////////////////////////////////////////////////////
  196. HRESULT CHMScopeItem::OnCutOrMove()
  197. {
  198. TRACEX(_T("CHMScopeItem::OnCutOrMove\n"));
  199. HRESULT hr = S_OK;
  200. /*if( ! CHECKHRESULT(hr = CHMScopeItem::OnCutOrMove()) )
  201. {
  202. return hr;
  203. }*/
  204. return hr;
  205. }
  206. HRESULT CHMScopeItem::OnCommand(long lCommandID)
  207. {
  208. TRACEX(_T("CHMScopeItem::OnCutOrMove\n"));
  209. HRESULT hr = S_OK;
  210. CHMObject* pObject = GetObjectPtr();
  211. if( ! pObject )
  212. {
  213. return E_FAIL;
  214. }
  215. switch( lCommandID )
  216. {
  217. case IDM_CLEAR_EVENTS:
  218. {
  219. if( AfxMessageBox(IDS_STRING_WARN_CLEAR_EVENTS,MB_YESNO) == IDYES )
  220. {
  221. pObject->ClearEvents();
  222. SelectItem();
  223. }
  224. }
  225. break;
  226. case IDM_RESET_STATUS:
  227. {
  228. pObject->ResetStatus();
  229. }
  230. break;
  231. case IDM_RESET_STATISTICS:
  232. {
  233. pObject->ResetStatistics();
  234. }
  235. break;
  236. case IDM_DISABLE_MONITORING:
  237. {
  238. if( pObject->IsEnabled() )
  239. {
  240. pObject->Disable();
  241. }
  242. else
  243. {
  244. pObject->Enable();
  245. }
  246. }
  247. break;
  248. case IDM_CHECK_NOW:
  249. {
  250. pObject->CheckNow();
  251. }
  252. break;
  253. case IDM_ICON_LEGEND:
  254. {
  255. CScopePane* pPane = GetScopePane();
  256. if( pPane )
  257. {
  258. hr = pPane->ShowTopic(_T("HMon21.chm::/cicons.htm"));
  259. }
  260. }
  261. break;
  262. default:
  263. {
  264. hr = CScopePaneItem::OnCommand(lCommandID);
  265. }
  266. }
  267. return hr;
  268. }
  269. HRESULT CHMScopeItem::OnDelete(BOOL bConfirm) // v-marfin 60298
  270. {
  271. TRACEX(_T("CHMScopeItem::OnDelete\n"));
  272. HRESULT hr = CScopePaneItem::OnDelete();
  273. if( ! CHECKHRESULT(hr) )
  274. {
  275. return hr;
  276. }
  277. CHMObject* pObject = GetObjectPtr();
  278. if( ! pObject )
  279. {
  280. return E_FAIL;
  281. }
  282. CString sMsg;
  283. sMsg.Format(IDS_STRING_WARN_DELETE,pObject->GetUITypeName(),pObject->GetUITypeName());
  284. if ((bConfirm) && ( AfxMessageBox(sMsg,MB_YESNO) != IDYES ))
  285. {
  286. return S_FALSE;
  287. }
  288. // first query all the scope items and see if any have open property sheets
  289. for( int i = 0; i < pObject->GetScopeItemCount(); i++ )
  290. {
  291. if( pObject->GetScopeItem(i)->IsPropertySheetOpen(true) )
  292. {
  293. AfxMessageBox(IDS_STRING_WARN_PROPPAGE_OPEN);
  294. return S_OK;
  295. }
  296. }
  297. for( i = pObject->GetScopeItemCount()-1; i >= 0 ; i-- )
  298. {
  299. CHMScopeItem* pParentItem = (CHMScopeItem*)pObject->GetScopeItem(i)->GetParent();
  300. if( pParentItem && GfxCheckObjPtr(pParentItem,CHMScopeItem) )
  301. {
  302. pParentItem->DestroyChild(pObject->GetScopeItem(i));
  303. pParentItem->OnChangeChildState(HMS_NORMAL);
  304. if( i == 0 )
  305. {
  306. CHMObject* pParentObject = pParentItem->GetObjectPtr();
  307. pParentObject->RemoveChild(pObject);
  308. }
  309. }
  310. }
  311. pObject->Destroy(true);
  312. delete pObject;
  313. return S_OK;
  314. }
  315. HRESULT CHMScopeItem::OnExpand(BOOL bExpand)
  316. {
  317. TRACEX(_T("CHMScopeItem::OnExpand\n"));
  318. TRACEARGn(bExpand);
  319. if( ! GetObjectPtr() )
  320. {
  321. return E_FAIL;
  322. }
  323. if( GetChildCount() == 0 )
  324. {
  325. m_pObject->EnumerateChildren();
  326. }
  327. return CScopePaneItem::OnExpand(bExpand);;
  328. }
  329. HRESULT CHMScopeItem::OnPaste(LPDATAOBJECT pSelectedItems, LPDATAOBJECT* ppCopiedItems)
  330. {
  331. TRACEX(_T("CHMScopeItem::OnPaste\n"));
  332. TRACEARGn(pSelectedItems);
  333. TRACEARGn(ppCopiedItems);
  334. HRESULT hr = S_OK;
  335. if( ! CHECKHRESULT(hr = CScopePaneItem::OnPaste(pSelectedItems, ppCopiedItems)) )
  336. {
  337. return hr;
  338. }
  339. CSnapinDataObject* psdo = CSnapinDataObject::GetSnapinDataObject(pSelectedItems);
  340. if( ! CHECKOBJPTR(psdo,RUNTIME_CLASS(CSnapinDataObject),sizeof(CSnapinDataObject)) )
  341. {
  342. return E_FAIL;
  343. }
  344. if( psdo->GetItemType() != CCT_SCOPE )
  345. {
  346. return E_FAIL;
  347. }
  348. CScopePaneItem* pItem = NULL;
  349. if( ! psdo->GetItem(pItem) )
  350. {
  351. return E_FAIL;
  352. }
  353. ASSERT(pItem);
  354. if( ! GetObjectPtr()->Paste(((CHMScopeItem*)pItem)->GetObjectPtr(),ppCopiedItems == NULL) )
  355. {
  356. return E_FAIL;
  357. }
  358. return hr;
  359. }
  360. HRESULT CHMScopeItem::OnQueryPaste(LPDATAOBJECT pDataObject)
  361. {
  362. TRACEX(_T("CHMScopeItem::OnQueryPaste\n"));
  363. TRACEARGn(pDataObject);
  364. HRESULT hr = S_OK;
  365. if( ! CHECKHRESULT(hr = CScopePaneItem::OnQueryPaste(pDataObject)) )
  366. {
  367. return hr;
  368. }
  369. CSnapinDataObject* psdo = CSnapinDataObject::GetSnapinDataObject(pDataObject);
  370. if( psdo == NULL || ! CHECKOBJPTR(psdo,RUNTIME_CLASS(CSnapinDataObject),sizeof(CSnapinDataObject)) )
  371. {
  372. return E_FAIL;
  373. }
  374. if( psdo->GetItemType() != CCT_SCOPE )
  375. {
  376. return E_FAIL;
  377. }
  378. CScopePaneItem* pItem = NULL;
  379. if( ! psdo->GetItem(pItem) )
  380. {
  381. return E_FAIL;
  382. }
  383. ASSERT(pItem);
  384. // 62985 : do not allow paste into yourself
  385. if (this == pItem)
  386. {
  387. return E_FAIL;
  388. }
  389. if( ! GetObjectPtr()->QueryPaste(((CHMScopeItem*)pItem)->GetObjectPtr()) )
  390. {
  391. return S_FALSE;
  392. }
  393. return hr;
  394. }
  395. HRESULT CHMScopeItem::OnRefresh()
  396. {
  397. TRACEX(_T("CHMScopeItem::OnRefresh\n"));
  398. CHMObject* pObject = GetObjectPtr();
  399. if( ! pObject )
  400. {
  401. return E_FAIL;
  402. }
  403. if( IsPropertySheetOpen(true) )
  404. {
  405. AfxMessageBox(IDS_STRING_WARN_PROPPAGE_OPEN);
  406. return S_FALSE;
  407. }
  408. if( ! pObject->Refresh() )
  409. {
  410. return E_FAIL;
  411. }
  412. SelectItem();
  413. return S_OK;
  414. }
  415. HRESULT CHMScopeItem::OnRename(const CString& sNewName)
  416. {
  417. TRACEX(_T("CHMScopeItem::OnRename\n"));
  418. if( ! m_pObject->Rename(sNewName) )
  419. {
  420. return S_FALSE;
  421. }
  422. return S_OK;
  423. }