Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

727 lines
18 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved.
  3. Module Name:
  4. evntsnap.cpp
  5. Abstract:
  6. This module is responsible for handling the notification
  7. calls from MMC for CSakSnap.
  8. Author:
  9. Rohde Wakefield [rohde] 06-Mar-1997
  10. Revision History:
  11. --*/
  12. #include "stdafx.h"
  13. #include "CSakSnap.h"
  14. #include "CSakData.h"
  15. HRESULT
  16. CSakSnap::OnShow(
  17. IN IDataObject* pDataObject,
  18. IN LPARAM arg,
  19. IN LPARAM param
  20. )
  21. /*++
  22. Routine Description:
  23. The result view is just about to be shown.
  24. Set the headers for the result view.
  25. Param is the unique identifier (an HSCOPEITEM) of the
  26. selected or deselected item.
  27. Arguments:
  28. pDataObject - The node which is showing.
  29. arg -
  30. param -
  31. Return Value:
  32. S_OK - Created successfully.
  33. E_xxxxxxxxxxx - Failure occurred.
  34. --*/
  35. {
  36. WsbTraceIn( L"CSakSnap::OnShow", L"pDataObject = <0x%p>, arg = <%ld><0x%p>, param = <%ld><0x%p>", pDataObject, arg, arg, param, param );
  37. HRESULT hr = S_OK;
  38. try {
  39. CComPtr<ISakNode> pNode;
  40. //
  41. // We've got a regular data object (single select)
  42. //
  43. WsbAffirmHr( m_pSakData->GetBaseHsmFromDataObject( pDataObject, &pNode, NULL ) );
  44. //
  45. // Arg is TRUE when it is time to enumerate
  46. //
  47. if( arg ) {
  48. //
  49. // Initialize child node list prior to graphically enumerating them
  50. //
  51. WsbAffirmHr( m_pSakData->EnsureChildrenAreCreated( pNode ) );
  52. //
  53. // Show the the node's children column headers in the result view.
  54. //
  55. WsbAffirmHr( InitResultPaneHeaders( pNode ) );
  56. //
  57. // Enumerate both the scope and result views. "Param" contains the
  58. // HSCOPEITEM of the node being shown.
  59. //
  60. WsbAffirmHr( EnumResultPane( pNode ) );
  61. } else {
  62. //
  63. // The node is being contracted - save the result pane configuration
  64. //
  65. //
  66. // Save them in CSakSnap for this node
  67. //
  68. WsbAffirmHr( SaveColumnWidths( pNode ) );
  69. //
  70. // Free data associated with the result pane items, because
  71. // your node is no longer being displayed.
  72. // Note: The console will remove the items from the result pane
  73. //
  74. }
  75. } WsbCatch( hr );
  76. WsbTraceOut( L"CSakSnap::OnShow", L"hr = <%ls>", WsbHrAsString( hr ) );
  77. return( hr );
  78. }
  79. HRESULT
  80. CSakSnap::OnChange(
  81. IN IDataObject* pDataObject,
  82. IN LPARAM arg,
  83. IN LPARAM param
  84. )
  85. /*++
  86. Routine Description:
  87. Update the scope and result panes from the already existing objects.
  88. Arguments:
  89. pNode - The node which is showing.
  90. arg -
  91. param -
  92. Return Value:
  93. S_OK - Created successfully.
  94. E_xxxxxxxxxxx - Failure occurred.
  95. --*/
  96. {
  97. WsbTraceIn( L"CSakSnap::OnChange", L"pDataObject = <0x%p>, arg = <%ld><0x%p>, param = <%ld><0x%p>", pDataObject, arg, arg, param, param );
  98. HRESULT hr = S_OK;
  99. try {
  100. CComPtr<ISakNode> pNode;
  101. MMC_COOKIE cookie;
  102. //
  103. // We've got a regular data object (single select)
  104. //
  105. WsbAffirmHr( m_pSakData->GetBaseHsmFromDataObject( pDataObject, &pNode, NULL ) );
  106. WsbAffirmHr( m_pSakData->GetCookieFromBaseHsm( pNode, &cookie ) );
  107. //
  108. // Find out if object is still valid
  109. //
  110. if( S_OK == pNode->IsValid( ) ) {
  111. //
  112. // Refresh the object itself
  113. //
  114. pNode->RefreshObject( );
  115. //
  116. // If this node's children are currently enumerated in the result pane,
  117. // delete and recreate all children
  118. //
  119. if( pNode == m_pEnumeratedNode ) {
  120. //
  121. // Re-show the the node's children column headers in the result view.
  122. // We do this because some views may change the number of columns they show
  123. //
  124. //
  125. // Save the current configuration
  126. //
  127. WsbAffirmHr( SaveColumnWidths( pNode ) );
  128. //
  129. // Clear out the MMC Result Pane
  130. //
  131. WsbAffirmHr( ClearResultPane() );
  132. //
  133. // Recreate the headers
  134. //
  135. WsbAffirmHr( InitResultPaneHeaders( pNode ) );
  136. //
  137. // Refresh the children
  138. //
  139. MMC_COOKIE cookie;
  140. WsbAffirmHr( m_pSakData->GetCookieFromBaseHsm( pNode, &cookie ) );
  141. WsbAffirmHr( m_pSakData->InternalRefreshNode( cookie ) );
  142. //
  143. // Redisplay children in the result pane
  144. //
  145. WsbAffirmHr( EnumResultPane( pNode ) );
  146. } else {
  147. //
  148. // If this is the active node (but not displayed in the result pane,
  149. // destroy and recreate it's child nodes
  150. //
  151. if( cookie == m_ActiveNodeCookie) {
  152. //
  153. // This node's children are not currently in the result pane.
  154. // Refresh the children
  155. //
  156. WsbAffirmHr( m_pSakData->RefreshNode( pNode ) );
  157. }
  158. }
  159. //
  160. // Is this a leaf node?
  161. //
  162. if( pNode->IsContainer() != S_OK ) {
  163. //
  164. // Redisplay in the result pane
  165. // Tell MMC to update the item
  166. //
  167. // Get the cookie for the node
  168. //
  169. if( cookie > 0 ) {
  170. HRESULTITEM itemID;
  171. WsbAffirmHr( m_pResultData->FindItemByLParam( cookie, &itemID ) );
  172. //
  173. // Force the result pane to udpate this item
  174. // Note that we have to force an icon update ourselves
  175. //
  176. RESULTDATAITEM resultItem;
  177. memset( &resultItem, 0, sizeof(RESULTDATAITEM) );
  178. resultItem.itemID = itemID;
  179. WsbAffirmHr( pNode->GetResultIcon( m_pSakData->m_State, &resultItem.nImage ) );
  180. resultItem.mask |= RDI_IMAGE;
  181. WsbAffirmHr( m_pResultData->SetItem( &resultItem ) );
  182. WsbAffirmHr( m_pResultData->UpdateItem( itemID ) );
  183. }
  184. }
  185. } else {
  186. //
  187. // Not valid - have parent update
  188. //
  189. CComPtr<ISakNode> pParentNode;
  190. WsbAffirmHr( pNode->GetParent( &pParentNode ) );
  191. WsbAffirmHr( m_pSakData->UpdateAllViews( pParentNode ) );
  192. }
  193. } WsbCatch( hr );
  194. WsbTraceOut( L"CSakSnap::OnChange", L"hr = <%ls>", WsbHrAsString( hr ) );
  195. return( hr );
  196. }
  197. HRESULT
  198. CSakSnap::OnRefresh(
  199. IN IDataObject* pDataObject,
  200. IN LPARAM arg,
  201. IN LPARAM param
  202. )
  203. /*++
  204. Routine Description:
  205. Arguments:
  206. pNode - The node
  207. arg -
  208. param -
  209. Return Value:
  210. S_OK - Created successfully.
  211. E_xxxxxxxxxxx - Failure occurred.
  212. --*/
  213. {
  214. WsbTraceIn( L"CSakSnap::OnRefresh", L"pDataObject = <0x%p>, arg = <%ld><0x%p>, param = <%ld><0x%p>", pDataObject, arg, arg, param, param );
  215. HRESULT hr = S_OK;
  216. try {
  217. CComPtr<ISakNode> pNode;
  218. //
  219. // We've got a regular data object (single select)
  220. //
  221. WsbAffirmHr( m_pSakData->GetBaseHsmFromDataObject( pDataObject, &pNode, NULL ) );
  222. WsbAffirmHr( m_pSakData->UpdateAllViews( pNode ) );
  223. } WsbCatch( hr );
  224. WsbTraceOut( L"CSakSnap::OnRefresh", L"hr = <%ls>", WsbHrAsString( hr ) );
  225. return( hr );
  226. }
  227. HRESULT
  228. CSakSnap::OnDelete(
  229. IN IDataObject* pDataObject,
  230. IN LPARAM arg,
  231. IN LPARAM param
  232. )
  233. /*++
  234. Routine Description:
  235. Arguments:
  236. pDataObject - The node
  237. arg -
  238. param -
  239. Return Value:
  240. S_OK - Created successfully.
  241. E_xxxxxxxxxxx - Failure occurred.
  242. --*/
  243. {
  244. WsbTraceIn( L"CSakSnap::OnDelete", L"pDataObject = <0x%p>, arg = <%ld><0x%p>, param = <%ld><0x%p>", pDataObject, arg, arg, param, param );
  245. HRESULT hr = S_OK;
  246. CComPtr<ISakNode> pNode;
  247. try {
  248. //
  249. // We've got a regular data object (single select)
  250. //
  251. WsbAffirmHr( m_pSakData->GetBaseHsmFromDataObject( pDataObject, &pNode, NULL ) );
  252. WsbAffirmHr ( pNode->DeleteObject() );
  253. } WsbCatch( hr );
  254. WsbTraceOut( L"CSakSnap::OnDelete", L"hr = <%ls>", WsbHrAsString( hr ) );
  255. return( hr );
  256. }
  257. HRESULT
  258. CSakSnap::OnSelect(
  259. IN IDataObject* pDataObject,
  260. IN LPARAM arg,
  261. IN LPARAM param
  262. )
  263. /*++
  264. Routine Description:
  265. Called when a node is selected. If the node is in the scope pane,
  266. save it as the currently active node.
  267. Arguments:
  268. pNode - The
  269. arg -
  270. param -
  271. Return Value:
  272. S_OK - Created successfully.
  273. E_xxxxxxxxxxx - Failure occurred.
  274. --*/
  275. {
  276. WsbTraceIn( L"CSakSnap::OnSelect", L"pDataObject = <0x%p>, arg = <%ld><0x%p>, param = <%ld><0x%p>", pDataObject, arg, arg, param, param );
  277. BOOL bState;
  278. BOOL bMultiSelect;
  279. MMC_CONSOLE_VERB defaultVerb = MMC_VERB_NONE;
  280. HRESULT hr = S_OK;
  281. try {
  282. CComPtr<IEnumGUID> pEnumObjectId;
  283. CComPtr<ISakNode> pNode;
  284. WsbAffirmHr( m_pSakData->GetBaseHsmFromDataObject( pDataObject, &pNode, &pEnumObjectId ) );
  285. // If we got back an enumeration, we're doing multi-select
  286. bMultiSelect = pEnumObjectId ? TRUE : FALSE;
  287. bState = ( m_pSakData->GetState() == S_OK );
  288. //
  289. // Set the verb state for the node
  290. //
  291. if( pNode->SupportsProperties( bMultiSelect ) == S_OK ) {
  292. if( bState || ( pNode->SupportsPropertiesNoEngine() == S_OK) ) {
  293. //
  294. // Engine OK - enable
  295. //
  296. WsbAffirmHr( m_pConsoleVerb->SetVerbState( MMC_VERB_PROPERTIES, HIDDEN, FALSE ) );
  297. WsbAffirmHr( m_pConsoleVerb->SetVerbState( MMC_VERB_PROPERTIES, ENABLED, TRUE ) );
  298. defaultVerb = MMC_VERB_PROPERTIES;
  299. } else {
  300. //
  301. // Engine down - set to disabled
  302. //
  303. WsbAffirmHr( m_pConsoleVerb->SetVerbState( MMC_VERB_PROPERTIES, HIDDEN, FALSE ) );
  304. WsbAffirmHr( m_pConsoleVerb->SetVerbState( MMC_VERB_PROPERTIES, ENABLED, FALSE ) );
  305. }
  306. } else {
  307. WsbAffirmHr( m_pConsoleVerb->SetVerbState( MMC_VERB_PROPERTIES, HIDDEN, TRUE) );
  308. }
  309. if( pNode->SupportsRefresh( bMultiSelect ) == S_OK ) {
  310. if( bState || ( pNode->SupportsRefreshNoEngine() == S_OK ) ) {
  311. WsbAffirmHr( m_pConsoleVerb->SetVerbState( MMC_VERB_REFRESH, HIDDEN, FALSE ) );
  312. WsbAffirmHr( m_pConsoleVerb->SetVerbState( MMC_VERB_REFRESH, ENABLED, TRUE ) );
  313. } else {
  314. WsbAffirmHr( m_pConsoleVerb->SetVerbState( MMC_VERB_REFRESH, HIDDEN, TRUE ) );
  315. }
  316. } else {
  317. WsbAffirmHr( m_pConsoleVerb->SetVerbState( MMC_VERB_REFRESH, HIDDEN, TRUE ) );
  318. }
  319. if( pNode->SupportsDelete( bMultiSelect ) == S_OK ) {
  320. WsbAffirmHr( m_pConsoleVerb->SetVerbState( MMC_VERB_DELETE, HIDDEN, FALSE ) );
  321. WsbAffirmHr( m_pConsoleVerb->SetVerbState( MMC_VERB_DELETE, ENABLED, bState ) );
  322. } else {
  323. WsbAffirmHr( m_pConsoleVerb->SetVerbState( MMC_VERB_DELETE, HIDDEN, TRUE ) );
  324. }
  325. //
  326. // If container, default action should be to open, regardless
  327. // of any previous work
  328. //
  329. if( S_OK == pNode->IsContainer( ) ) {
  330. defaultVerb = MMC_VERB_OPEN;
  331. }
  332. WsbAffirmHr( m_pConsoleVerb->SetDefaultVerb( defaultVerb ) );
  333. // Standard functionality NOT support by all items
  334. WsbAffirmHr( m_pConsoleVerb->SetVerbState( MMC_VERB_RENAME, HIDDEN, TRUE ) );
  335. WsbAffirmHr( m_pConsoleVerb->SetVerbState( MMC_VERB_COPY, HIDDEN, TRUE ) );
  336. WsbAffirmHr( m_pConsoleVerb->SetVerbState( MMC_VERB_PASTE, HIDDEN, TRUE ) );
  337. WsbAffirmHr( m_pConsoleVerb->SetVerbState( MMC_VERB_PRINT, HIDDEN, TRUE ) );
  338. // Extract data from the arg
  339. BOOL bScope = (BOOL) LOWORD(arg);
  340. BOOL bSelect = (BOOL) HIWORD(arg);
  341. if( bScope && bSelect ) {
  342. WsbAffirmHr( m_pSakData->GetCookieFromBaseHsm( pNode, &m_ActiveNodeCookie ) );
  343. }
  344. } WsbCatch( hr );
  345. WsbTraceOut( L"CSakSnap::OnSelect", L"hr = <%ls>", WsbHrAsString( hr ) );
  346. return( hr );
  347. }
  348. HRESULT
  349. CSakSnap::OnMinimize(
  350. IN IDataObject* pDataObject,
  351. IN LPARAM arg,
  352. IN LPARAM param
  353. )
  354. /*++
  355. Routine Description:
  356. Arguments:
  357. pNode - The node
  358. arg -
  359. param -
  360. Return Value:
  361. S_OK - Created successfully.
  362. E_xxxxxxxxxxx - Failure occurred.
  363. --*/
  364. {
  365. WsbTraceIn( L"CSakSnap::OnMinimize", L"pDataObject = <0x%p>, arg = <%ld><0x%p>, param = <%ld><0x%p>", pDataObject, arg, arg, param, param );
  366. HRESULT hr = S_OK;
  367. WsbTraceOut( L"CSakSnap::OnMinimize", L"hr = <%ls>", WsbHrAsString( hr ) );
  368. return( hr );
  369. }
  370. HRESULT
  371. CSakSnap::EnumResultPane(
  372. IN ISakNode* pNode
  373. )
  374. /*++
  375. Routine Description:
  376. Insert the child items into the result pane.
  377. Arguments:
  378. pNode - The node which is expanding.
  379. arg -
  380. param -
  381. Return Value:
  382. S_OK - Created successfully.
  383. E_xxxxxxxxxxx - Failure occurred.
  384. --*/
  385. {
  386. WsbTraceIn( L"CSakSnap::EnumResultPane", L"pNode = <0x%p>", pNode );
  387. HRESULT hr = S_OK;
  388. try {
  389. WsbAffirmPointer( pNode );
  390. CComPtr<IResultData> pResult;
  391. WsbAffirmHr( m_pConsole->QueryInterface( IID_IResultData, (void**)&pResult ) );
  392. //
  393. // Clear the result pane
  394. //
  395. WsbAffirmHr( ClearResultPane() );
  396. //
  397. // allocate and initialize a result item.
  398. //
  399. RESULTDATAITEM resultItem;
  400. memset( &resultItem, 0, sizeof(RESULTDATAITEM) );
  401. //
  402. // Loop through this node's children (just one level deep).
  403. //
  404. if( pNode->IsContainer( ) == S_OK ) {
  405. CComPtr<IEnumUnknown> pEnum; // child enumerator
  406. CComPtr<ISakNode> pNodeChild; // ISakNode pointer for the child
  407. //
  408. // Force a fresh list to be used - this way list is updated
  409. // WRT added or deleted nodes
  410. //
  411. if( S_OK == pNode->HasDynamicChildren( ) ) {
  412. WsbAffirmHr( m_pSakData->FreeEnumChildren( pNode ) );
  413. WsbAffirmHr( pNode->InvalidateChildren() )
  414. WsbAffirmHr( pNode->RefreshObject( ) );
  415. }
  416. //
  417. // Enumerate and add in order
  418. //
  419. WsbAffirmHr( pNode->EnumChildren( &pEnum ) );
  420. CComPtr<IUnknown> pUnk;
  421. int virtIndex = 0;
  422. HRESULT hrEnum = S_OK;
  423. while( S_OK == hrEnum ) {
  424. //
  425. // Clear these from previous iterations
  426. //
  427. pUnk.Release( );
  428. pNodeChild.Release( );
  429. //
  430. // Get the next
  431. //
  432. hrEnum = pEnum->Next( 1, &pUnk, NULL );
  433. WsbAffirmHr( hrEnum );
  434. //
  435. // Did we just hit the end of the list?
  436. //
  437. if( S_FALSE == hrEnum ) {
  438. continue;
  439. }
  440. WsbAffirmHr( RsQueryInterface( pUnk, ISakNode, pNodeChild ) );
  441. //
  442. // MMC will automatically put in items from the scope
  443. // pane so do not put these up.
  444. //
  445. if( pNodeChild->IsContainer( ) == S_OK ) {
  446. continue;
  447. }
  448. //
  449. // Put the first column of info into the result view.
  450. //
  451. memset( &resultItem, 0, sizeof(RESULTDATAITEM) );
  452. resultItem.str = MMC_CALLBACK;
  453. resultItem.mask |= RDI_STR;
  454. //
  455. // stuff the child BaseHsm interface in the RESULTDATAITEM lParam.
  456. //
  457. WsbAffirmHr( m_pSakData->GetCookieFromBaseHsm( pNodeChild, (MMC_COOKIE*)( &resultItem.lParam ) ) );
  458. resultItem.mask |= RDI_PARAM;
  459. WsbAffirmHr( pNodeChild->GetResultIcon( m_pSakData->m_State, &resultItem.nImage ) );
  460. resultItem.mask |= RDI_IMAGE;
  461. pResult->InsertItem( &resultItem );
  462. }
  463. }
  464. // Record the fact that this node is showing in the result pane
  465. m_pEnumeratedNode = pNode;
  466. } WsbCatch( hr );
  467. WsbTraceOut( L"CSakSnap::EnumResultPane", L"hr = <%ls>", WsbHrAsString( hr ) );
  468. return( hr );
  469. }
  470. /*++
  471. Routine Description:
  472. Calls MMC to clear out the result pane.
  473. Arguments:
  474. Return Value:
  475. S_OK - OK
  476. E_xxxxxxxxxxx - Failure occurred.
  477. --*/
  478. HRESULT CSakSnap::ClearResultPane()
  479. {
  480. WsbTraceIn( L"CSakSnap::ClearResultPane", L"");
  481. HRESULT hr = S_OK;
  482. try {
  483. CComPtr<IResultData> pResult;
  484. WsbAffirmHr( m_pConsole->QueryInterface( IID_IResultData, (void**)&pResult ) );
  485. WsbAffirmHr( pResult->DeleteAllRsltItems( ) );
  486. m_pEnumeratedNode = NULL;
  487. } WsbCatch (hr);
  488. WsbTraceOut( L"CSakSnap::ClearResultPane", L"hr = <%ls>", WsbHrAsString( hr ) );
  489. return hr;
  490. }