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.

267 lines
6.6 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: rootnode.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // RootNode.cpp: implementation of the CRootNode class.
  11. //
  12. //////////////////////////////////////////////////////////////////////
  13. #include "stdafx.h"
  14. #include "resource.h"
  15. #include "RootNode.h"
  16. #include "BenNodes.h"
  17. #include "Dialogs.h"
  18. //////////////////////////////////////////////////////////////////////
  19. // Construction/Destruction
  20. //////////////////////////////////////////////////////////////////////
  21. static const GUID CBenefitsGUID_NODETYPE =
  22. { 0xe0573e71, 0xd325, 0x11d1, { 0x84, 0x6c, 0x0, 0x10, 0x4b, 0x21, 0x1b, 0xe5 } };
  23. const GUID* CRootNode::m_NODETYPE = &CBenefitsGUID_NODETYPE;
  24. const TCHAR* CRootNode::m_SZNODETYPE = _T("E0573E71-D325-11D1-846C-00104B211BE5");
  25. const TCHAR* CRootNode::m_SZDISPLAY_NAME = _T("Benefits");
  26. const CLSID* CRootNode::m_SNAPIN_CLASSID = &CLSID_Benefits;
  27. //
  28. // Pass NULL in as the employee since this contains the valid
  29. // employee. The pointer to the employee is leftover baggage
  30. // from using the CBenefitsData() template.
  31. //
  32. CRootNode::CRootNode() : CChildrenBenefitsData< CRootNode >()
  33. {
  34. m_scopeDataItem.nOpenImage = 5;
  35. m_scopeDataItem.nImage = 4;
  36. //
  37. // Always clear our dirty flag.
  38. //
  39. m_fDirty = false;
  40. }
  41. //
  42. // Creates the benefits subnodes for the scope pane.
  43. //
  44. BOOL CRootNode::InitializeSubNodes()
  45. {
  46. CSnapInItem* pNode;
  47. //
  48. // Allocate sub nodes and add them to our internal list.
  49. //
  50. pNode = new CHealthNode( &m_Employee );
  51. if ( pNode == NULL || m_Nodes.Add( pNode ) == FALSE )
  52. return( FALSE );
  53. pNode = new CRetirementNode( &m_Employee );
  54. if ( pNode == NULL || m_Nodes.Add( pNode ) == FALSE )
  55. return( FALSE );
  56. pNode = new CKeyNode( &m_Employee );
  57. if ( pNode == NULL || m_Nodes.Add( pNode ) == FALSE )
  58. return( FALSE );
  59. return( TRUE );
  60. }
  61. //
  62. // Overridden to provide employee name for root node.
  63. //
  64. STDMETHODIMP CRootNode::FillData( CLIPFORMAT cf, LPSTREAM pStream )
  65. {
  66. HRESULT hr = DV_E_CLIPFORMAT;
  67. ULONG uWritten;
  68. //
  69. // We need to write out our own member since GetDisplayName() does
  70. // not give us an opportunity override its static implementation by
  71. // ATL.
  72. //
  73. if (cf == m_CCF_NODETYPE)
  74. {
  75. hr = pStream->Write( GetNodeType(), sizeof(GUID), &uWritten);
  76. return hr;
  77. }
  78. if (cf == m_CCF_SZNODETYPE)
  79. {
  80. hr = pStream->Write( GetSZNodeType(), (lstrlen((LPCTSTR) GetSZNodeType()) + 1 )* sizeof(TCHAR), &uWritten);
  81. return hr;
  82. }
  83. if (cf == m_CCF_DISPLAY_NAME)
  84. {
  85. USES_CONVERSION;
  86. TCHAR szDisplayName[ 256 ];
  87. LPWSTR pwszName;
  88. // Create a full display name.
  89. CreateDisplayName( szDisplayName );
  90. pwszName = T2W( szDisplayName );
  91. hr = pStream->Write( pwszName, wcslen( pwszName ) * sizeof( WCHAR ), &uWritten);
  92. return hr;
  93. }
  94. if (cf == m_CCF_SNAPIN_CLASSID)
  95. {
  96. hr = pStream->Write( GetSnapInCLSID(), sizeof(GUID), &uWritten);
  97. return hr;
  98. }
  99. return hr;
  100. }
  101. //
  102. // Overridden to add new columns to the results
  103. // display.
  104. //
  105. STDMETHODIMP CRootNode::OnShowColumn( IHeaderCtrl* pHeader )
  106. {
  107. USES_CONVERSION;
  108. HRESULT hr = E_FAIL;
  109. CComPtr<IHeaderCtrl> spHeader( pHeader );
  110. //
  111. // Add two columns: one with the name of the object and one with
  112. // the description of the node. Use the value of 200 pixels as the size.
  113. //
  114. hr = spHeader->InsertColumn( 0, T2OLE( _T( "Benefit" ) ), LVCFMT_LEFT, 200 );
  115. _ASSERTE( SUCCEEDED( hr ) );
  116. //
  117. // Add the second column. Use the value of 350 pixels as the size.
  118. //
  119. hr = spHeader->InsertColumn( 1, T2OLE( _T( "Description" ) ), LVCFMT_LEFT, 350 );
  120. _ASSERTE( SUCCEEDED( hr ) );
  121. return( hr );
  122. }
  123. STDMETHODIMP CRootNode::CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider,
  124. long handle,
  125. IUnknown* pUnk,
  126. DATA_OBJECT_TYPES type)
  127. {
  128. UNUSED_ALWAYS( pUnk );
  129. HRESULT hr = E_UNEXPECTED;
  130. if ( type == CCT_SCOPE || type == CCT_RESULT || type == CCT_SNAPIN_MANAGER )
  131. {
  132. bool fStartup;
  133. //
  134. // Set the start-up flag based on the type of pages to be
  135. // created.
  136. //
  137. fStartup = type == CCT_SNAPIN_MANAGER ? true : false;
  138. //
  139. // Allocate the new page. The second parameter of the constructor
  140. // indicates whether or not this is the start-up wizard. The dialog
  141. // handler will update the UI appropriately.
  142. //
  143. CEmployeeNamePage* pNamePage = new CEmployeeNamePage( handle, fStartup, false, _T( "Employee Name" ) );
  144. CEmployeeAddressPage* pAddressPage = new CEmployeeAddressPage( handle, fStartup, false, _T( "Employee Address" ) );
  145. //
  146. // Set the page's employee.
  147. //
  148. pNamePage->m_pEmployee = &m_Employee;
  149. pAddressPage->m_pEmployee = &m_Employee;
  150. lpProvider->AddPage( pNamePage->Create() );
  151. lpProvider->AddPage( pAddressPage->Create() );
  152. //
  153. // The second parameter to the property page class constructor
  154. // should be true for only one page.
  155. //
  156. hr = S_OK;
  157. }
  158. return( hr );
  159. }
  160. //
  161. // Ensures that the appropriate verbs are displayed.
  162. //
  163. STDMETHODIMP CRootNode::OnSelect( IConsole* pConsole )
  164. {
  165. //
  166. // Since we display property pages, make sure that the property page
  167. // verb is enabled.
  168. //
  169. CComPtr<IConsoleVerb> spConsoleVerb;
  170. HRESULT hr = pConsole->QueryConsoleVerb( &spConsoleVerb );
  171. //
  172. // Enable the properties verb.
  173. //
  174. hr = spConsoleVerb->SetVerbState( MMC_VERB_PROPERTIES, ENABLED, TRUE );
  175. _ASSERTE( SUCCEEDED( hr ) );
  176. return( hr );
  177. }
  178. //
  179. // Received when a property has changed. This function
  180. // modifies the employee's display text. At a later date,
  181. // it may post this message to its sub-nodes.
  182. //
  183. STDMETHODIMP CRootNode::OnPropertyChange( IConsole* pConsole )
  184. {
  185. HRESULT hr;
  186. SCOPEDATAITEM* pScopeData;
  187. CComQIPtr<IConsoleNameSpace,&IID_IConsoleNameSpace> spNamespace( pConsole );
  188. TCHAR szNameBuf[ 256 ];
  189. //
  190. // For demonstration purposes, always set the modified flag. This
  191. // could be done more intelligently for real purposes.
  192. //
  193. SetModified();
  194. //
  195. // Always assume that the name changed. Recreate the display name
  196. // since this will be called for after SetItem() is called.
  197. //
  198. CreateDisplayName( szNameBuf );
  199. m_bstrDisplayName = szNameBuf;
  200. //
  201. // Fill out the scope item structure and set the item.
  202. // This will cause MMC to call us for the new display
  203. // text.
  204. //
  205. hr = GetScopeData( &pScopeData );
  206. //
  207. // Make sure that callback is specified.
  208. //
  209. hr = spNamespace->SetItem( pScopeData );
  210. return( hr );
  211. }
  212. //
  213. // Simply function to create the display name from the
  214. // employee data.
  215. //
  216. int CRootNode::CreateDisplayName( TCHAR* szBuf )
  217. {
  218. USES_CONVERSION;
  219. //
  220. // Create a full display name.
  221. //
  222. _tcscpy( szBuf, W2T( m_Employee.m_szLastName ) );
  223. _tcscat( szBuf, _T( ", " ) );
  224. _tcscat( szBuf, W2T( m_Employee.m_szFirstName ) );
  225. return( _tcslen( szBuf ) );
  226. }