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.

446 lines
12 KiB

  1. // cmponent.cpp : Implementation of CMyComputerComponent
  2. #include "stdafx.h"
  3. #include "macros.h"
  4. USE_HANDLE_MACROS("MYCOMPUT(cmponent.cpp)")
  5. #include "dataobj.h"
  6. #include "cmponent.h" // CMyComputerComponent
  7. #include "compdata.h" // CMyComputerComponentData
  8. #include "guidhelp.h" // ExtractData
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. #include "stdcmpnt.cpp" // CComponent
  15. UINT g_aColumns0[4] =
  16. {IDS_COLUMN_NAME,IDS_COLUMN_TYPE,IDS_COLUMN_DESCRIPTION,0}; // SYSTEMTOOLS, SERVERAPPS, STORAGE
  17. UINT g_aColumns1[2] =
  18. {IDS_COLUMN_NAME,0}; // MYCOMPUT_COMPUTER
  19. UINT* g_Columns[MYCOMPUT_NUMTYPES] =
  20. { g_aColumns1, // MYCOMPUT_COMPUTER
  21. g_aColumns0, // MYCOMPUT_SYSTEMTOOLS
  22. g_aColumns0, // MYCOMPUT_SERVERAPPS
  23. g_aColumns0 // MYCOMPUT_STORAGE
  24. };
  25. UINT** g_aColumns = g_Columns;
  26. //
  27. // CODEWORK this should be in a resource, for example code on loading data resources see
  28. // D:\nt\private\net\ui\common\src\applib\applib\lbcolw.cxx ReloadColumnWidths()
  29. // JonN 10/11/96
  30. //
  31. int g_aColumnWidths0[3] = {150,150,150};
  32. int g_aColumnWidths1[1] = {450};
  33. int* g_ColumnWidths[MYCOMPUT_NUMTYPES] =
  34. { g_aColumnWidths1, // MYCOMPUT_COMPUTER
  35. g_aColumnWidths0, // MYCOMPUT_SYSTEMTOOLS
  36. g_aColumnWidths0, // MYCOMPUT_SERVERAPPS
  37. g_aColumnWidths0 // MYCOMPUT_STORAGE
  38. };
  39. int** g_aColumnWidths = g_ColumnWidths;
  40. CMyComputerComponent::CMyComputerComponent()
  41. : m_pSvcMgmtToolbar( NULL ),
  42. m_pMyComputerToolbar( NULL ),
  43. m_pControlbar( NULL ),
  44. m_pViewedCookie( NULL ),
  45. m_dwFlagsPersist( 0 ),
  46. m_bForcingGetResultType (false)
  47. {
  48. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  49. }
  50. CMyComputerComponent::~CMyComputerComponent()
  51. {
  52. TRACE_METHOD(CMyComputerComponent,Destructor);
  53. VERIFY( SUCCEEDED(ReleaseAll()) );
  54. }
  55. HRESULT CMyComputerComponent::ReleaseAll()
  56. {
  57. MFC_TRY;
  58. TRACE_METHOD(CMyComputerComponent,ReleaseAll);
  59. SAFE_RELEASE(m_pSvcMgmtToolbar);
  60. SAFE_RELEASE(m_pMyComputerToolbar);
  61. SAFE_RELEASE(m_pControlbar);
  62. // ISSUE: not ready for release yet
  63. // m_pViewedCookie->Release(); // JonN 10/1/01 465507
  64. // m_pViewedCookie = NULL;
  65. return CComponent::ReleaseAll();
  66. MFC_CATCH;
  67. }
  68. /////////////////////////////////////////////////////////////////////////////
  69. // IComponent Implementation
  70. HRESULT CMyComputerComponent::LoadStrings()
  71. {
  72. return S_OK;
  73. }
  74. HRESULT CMyComputerComponent::LoadColumns( CMyComputerCookie* pcookie )
  75. {
  76. AFX_MANAGE_STATE(AfxGetStaticModuleState( )); // 2002/03/22-JonN 572859
  77. TEST_NONNULL_PTR_PARAM(pcookie);
  78. return LoadColumnsFromArrays( (INT)(pcookie->m_objecttype) );
  79. }
  80. HRESULT CMyComputerComponent::Show( CCookie* pcookie, LPARAM arg, HSCOPEITEM /*hScopeItem*/ )
  81. {
  82. TEST_NONNULL_PTR_PARAM(pcookie);
  83. // 662617-2002/07/24-JonN LoadString was failing
  84. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  85. if ( QueryComponentDataRef ().m_bMessageView )
  86. {
  87. CComPtr<IUnknown> spUnknown;
  88. CComPtr<IMessageView> spMessageView;
  89. HRESULT hr = m_pConsole->QueryResultView(&spUnknown);
  90. if (SUCCEEDED(hr))
  91. {
  92. hr = spUnknown->QueryInterface(IID_IMessageView, (PVOID*)&spMessageView);
  93. if (SUCCEEDED(hr))
  94. {
  95. CString title;
  96. VERIFY (title.LoadString (IDS_TASKPADTITLE_COMPUTER));
  97. spMessageView->SetTitleText(title);
  98. spMessageView->SetBodyText(QueryComponentDataRef ().m_strMessageViewMsg);
  99. spMessageView->SetIcon(Icon_Information);
  100. }
  101. if ( E_NOINTERFACE == hr )
  102. {
  103. // The interface "IMessageView" was not found so call
  104. // UpdateAllViews to force a call to GetResultType () which
  105. // will install it. Since UpdateAllViews call MMCN_SHOW before
  106. // calling GetResultType, this flag will prevent an endless
  107. // loop
  108. // Note: This call is made here because it OnViewChange with
  109. // this hint will call SelectScopeItem () which cannot be
  110. // called during MMCN_EXPAND
  111. if ( !m_bForcingGetResultType )
  112. {
  113. m_bForcingGetResultType = true;
  114. hr = m_pConsole->UpdateAllViews (0, 0, HINT_SELECT_ROOT_NODE);
  115. }
  116. }
  117. }
  118. return S_OK;
  119. }
  120. if ( 0 == arg )
  121. {
  122. if ( NULL == m_pResultData )
  123. {
  124. ASSERT( FALSE );
  125. return E_UNEXPECTED;
  126. }
  127. // not needed pcookie->ReleaseResultChildren();
  128. // ISSUE: not ready for release yet
  129. // m_pViewedCookie->Release(); // JonN 10/1/01 465507
  130. // m_pViewedCookie = NULL;
  131. return S_OK;
  132. }
  133. m_pViewedCookie = (CMyComputerCookie*)pcookie;
  134. // ISSUE: not ready for release yet
  135. // m_pViewedCookie->AddRef(); // JonN 10/1/01 465507
  136. if ( MYCOMPUT_COMPUTER == m_pViewedCookie->m_objecttype
  137. && !(m_pViewedCookie->m_fRootCookieExpanded) )
  138. {
  139. m_pViewedCookie->m_fRootCookieExpanded = true;
  140. CComQIPtr<IConsole2, &IID_IConsole2> pIConsole2 = m_pConsole;
  141. ASSERT( pIConsole2 );
  142. if ( pIConsole2 )
  143. {
  144. // JonN 5/27/99 Some dead code in this directory contains bad templates for
  145. // looping on scopecookies, this is a better template
  146. POSITION pos = pcookie->m_listScopeCookieBlocks.GetHeadPosition();
  147. while (NULL != pos)
  148. {
  149. CBaseCookieBlock* pcookieblock = pcookie->m_listScopeCookieBlocks.GetNext( pos );
  150. TEST_NONNULL_PTR_PARAM(pcookieblock); // JonN 2/25/02 Security Push
  151. CMyComputerCookie* pChildCookie = (CMyComputerCookie*)pcookieblock;
  152. // JonN 03/07/00: PREFIX 56323
  153. switch ((NULL == pChildCookie) ? MYCOMPUT_COMPUTER
  154. : pChildCookie->m_objecttype)
  155. {
  156. case MYCOMPUT_SYSTEMTOOLS:
  157. case MYCOMPUT_STORAGE:
  158. {
  159. HRESULT hr = pIConsole2->Expand(pChildCookie->m_hScopeItem, TRUE);
  160. ASSERT(SUCCEEDED(hr));
  161. }
  162. break;
  163. default:
  164. break;
  165. }
  166. }
  167. }
  168. }
  169. LoadColumns( m_pViewedCookie );
  170. return PopulateListbox( m_pViewedCookie );
  171. }
  172. HRESULT CMyComputerComponent::OnNotifyAddImages( LPDATAOBJECT /*lpDataObject*/,
  173. LPIMAGELIST lpImageList,
  174. HSCOPEITEM /*hSelectedItem*/ )
  175. {
  176. if ( QueryComponentDataRef ().m_bMessageView )
  177. return S_OK;
  178. else
  179. return QueryComponentDataRef().LoadIcons(lpImageList,TRUE);
  180. }
  181. HRESULT CMyComputerComponent::OnNotifySnapinHelp (LPDATAOBJECT pDataObject)
  182. {
  183. CCookie* pBaseParentCookie = NULL;
  184. HRESULT hr = ExtractData( pDataObject,
  185. CMyComputerDataObject::m_CFRawCookie,
  186. reinterpret_cast<PBYTE>(&pBaseParentCookie),
  187. sizeof(pBaseParentCookie) );
  188. if ( FAILED(hr) )
  189. {
  190. ASSERT(FALSE);
  191. return S_OK;
  192. }
  193. CMyComputerCookie* pCookie = QueryComponentDataRef().ActiveCookie(pBaseParentCookie);
  194. if (NULL == pCookie)
  195. {
  196. ASSERT(FALSE);
  197. return S_OK;
  198. }
  199. LPCTSTR lpcszHelpTopic = L"compmgmt_topnode.htm";
  200. switch (pCookie->m_objecttype)
  201. {
  202. case MYCOMPUT_SYSTEMTOOLS:
  203. lpcszHelpTopic = L"system_tools_overview.htm";
  204. break;
  205. case MYCOMPUT_SERVERAPPS:
  206. lpcszHelpTopic = L"server_services_applications_overview.htm";
  207. break;
  208. case MYCOMPUT_STORAGE:
  209. lpcszHelpTopic = L"storage_devices_overview.htm";
  210. break;
  211. default:
  212. ASSERT(FALSE); // fall through
  213. case MYCOMPUT_COMPUTER:
  214. break;
  215. }
  216. return ShowHelpTopic( lpcszHelpTopic );
  217. }
  218. HRESULT CMyComputerComponent::PopulateListbox(CMyComputerCookie* /*pcookie*/)
  219. {
  220. // not needed (void) pcookie->AddRefResultChildren();
  221. return S_OK; // no resultitems in this snapin
  222. }
  223. ///////////////////////////////////////////////////////////////////////////////
  224. /// IExtendContextMenu
  225. STDMETHODIMP CMyComputerComponent::AddMenuItems(
  226. IDataObject* piDataObject,
  227. IContextMenuCallback* piCallback,
  228. long* pInsertionAllowed)
  229. {
  230. MFC_TRY;
  231. TRACE_METHOD(CMyComputerComponent,AddMenuItems);
  232. TEST_NONNULL_PTR_PARAM(piDataObject);
  233. TEST_NONNULL_PTR_PARAM(piCallback);
  234. TEST_NONNULL_PTR_PARAM(pInsertionAllowed);
  235. TRACE( "CMyComputerComponent: extending menu\n" );
  236. if ( 0 == (CCM_INSERTIONALLOWED_VIEW & (*pInsertionAllowed)) )
  237. return S_OK; // no View menu
  238. //
  239. // CODEWORK This code will not work if My Computer becomes an extension,
  240. // since the RawCookie format will not be available.
  241. // WARNING cookie cast
  242. //
  243. CCookie* pBaseParentCookie = NULL;
  244. HRESULT hr = ExtractData( piDataObject,
  245. CMyComputerDataObject::m_CFRawCookie,
  246. reinterpret_cast<PBYTE>(&pBaseParentCookie),
  247. sizeof(pBaseParentCookie) );
  248. if ( FAILED(hr) )
  249. {
  250. ASSERT(FALSE);
  251. return S_OK;
  252. }
  253. CMyComputerCookie* pCookie = QueryComponentDataRef().ActiveCookie(pBaseParentCookie);
  254. if (NULL == pCookie)
  255. {
  256. ASSERT(FALSE);
  257. return S_OK;
  258. }
  259. switch (pCookie->m_objecttype)
  260. {
  261. case MYCOMPUT_COMPUTER:
  262. case MYCOMPUT_SYSTEMTOOLS:
  263. case MYCOMPUT_SERVERAPPS:
  264. break;
  265. default:
  266. ASSERT(FALSE); // fall through
  267. case MYCOMPUT_STORAGE:
  268. return S_OK;
  269. }
  270. return hr;
  271. MFC_CATCH;
  272. } // CMyComputerComponent::AddMenuItems()
  273. STDMETHODIMP CMyComputerComponent::Command(
  274. LONG lCommandID,
  275. IDataObject* piDataObject )
  276. {
  277. MFC_TRY;
  278. TRACE_METHOD(CMyComputerComponent,Command);
  279. TEST_NONNULL_PTR_PARAM(piDataObject);
  280. TRACE( "CMyComputerComponent::Command: command %ld selected\n", lCommandID );
  281. switch (lCommandID)
  282. {
  283. case -1:
  284. break;
  285. default:
  286. ASSERT(FALSE);
  287. break;
  288. }
  289. return S_OK;
  290. MFC_CATCH;
  291. } // CMyComputerComponent::Command()
  292. HRESULT CMyComputerComponent::OnNotifySelect( LPDATAOBJECT lpDataObject, BOOL /*fSelected*/ )
  293. {
  294. MFC_TRY;
  295. TRACE_METHOD(CMyComputerComponent,OnNotifySelect);
  296. TEST_NONNULL_PTR_PARAM(lpDataObject);
  297. CCookie* pBaseParentCookie = NULL;
  298. HRESULT hr = ExtractData( lpDataObject,
  299. CMyComputerDataObject::m_CFRawCookie,
  300. reinterpret_cast<PBYTE>(&pBaseParentCookie),
  301. sizeof(pBaseParentCookie) );
  302. if ( FAILED(hr) )
  303. {
  304. ASSERT(FALSE);
  305. return S_OK;
  306. }
  307. CMyComputerCookie* pCookie = QueryComponentDataRef().ActiveCookie(pBaseParentCookie);
  308. if (NULL == pCookie)
  309. {
  310. ASSERT(FALSE);
  311. return S_OK;
  312. }
  313. // Set the default verb to display the properties of the selected object
  314. // We do this so that extensions can add properties, we don't have any
  315. #ifdef FIX538345
  316. //
  317. // 538345-2002/06/18-JonN Only permit a property sheet if none are
  318. // currently displayed
  319. BOOL fAllowProperties = (MYCOMPUT_COMPUTER == pCookie->m_objecttype);
  320. if (fAllowProperties)
  321. {
  322. CComQIPtr<IPropertySheetProvider,
  323. &IID_IPropertySheetProvider> pISP = m_pConsole;
  324. ASSERT(!!pISP);
  325. if (pISP)
  326. {
  327. HRESULT hr2 = pISP->FindPropertySheet( 0L, // cookie
  328. this, // IComponent
  329. lpDataObject);
  330. if (S_OK == hr2)
  331. fAllowProperties = FALSE;
  332. }
  333. }
  334. #endif
  335. m_pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES,
  336. ENABLED,
  337. #ifdef FIX538345
  338. fAllowProperties );
  339. #else
  340. (MYCOMPUT_COMPUTER == pCookie->m_objecttype) );
  341. #endif
  342. m_pConsoleVerb->SetDefaultVerb(MMC_VERB_OPEN);
  343. return S_OK;
  344. MFC_CATCH;
  345. }
  346. STDMETHODIMP CMyComputerComponent::GetResultViewType(
  347. MMC_COOKIE cookie,
  348. LPOLESTR* ppViewType,
  349. long* pViewOptions)
  350. {
  351. MFC_TRY;
  352. TEST_NONNULL_PTR_PARAM(pViewOptions); // JonN 2/25/02 Security Push
  353. if ( QueryComponentDataRef ().m_bMessageView )
  354. {
  355. m_bForcingGetResultType = false;
  356. *pViewOptions = MMC_VIEW_OPTIONS_NOLISTVIEWS;
  357. LPOLESTR psz = NULL;
  358. StringFromCLSID(CLSID_MessageView, &psz);
  359. USES_CONVERSION;
  360. if (psz != NULL)
  361. {
  362. *ppViewType = psz;
  363. return S_OK;
  364. }
  365. else
  366. return S_FALSE;
  367. }
  368. else
  369. return CComponent::GetResultViewType( cookie, ppViewType, pViewOptions );
  370. MFC_CATCH;
  371. }
  372. HRESULT CMyComputerComponent::OnViewChange (LPDATAOBJECT /*pDataObject*/, LPARAM /*data*/, LPARAM hint)
  373. {
  374. HRESULT hr = S_OK;
  375. if ( (HINT_SELECT_ROOT_NODE & hint) )
  376. {
  377. hr = m_pConsole->SelectScopeItem (QueryComponentDataRef().QueryRootCookie().m_hScopeItem);
  378. }
  379. return hr;
  380. }