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.

409 lines
11 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_dwFlagsPersist( 0 ),
  45. m_bForcingGetResultType (false)
  46. {
  47. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  48. m_pViewedCookie = NULL;
  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. return CComponent::ReleaseAll();
  63. MFC_CATCH;
  64. }
  65. /////////////////////////////////////////////////////////////////////////////
  66. // IComponent Implementation
  67. HRESULT CMyComputerComponent::LoadStrings()
  68. {
  69. return S_OK;
  70. }
  71. HRESULT CMyComputerComponent::LoadColumns( CMyComputerCookie* pcookie )
  72. {
  73. TEST_NONNULL_PTR_PARAM(pcookie);
  74. return LoadColumnsFromArrays( (INT)(pcookie->m_objecttype) );
  75. }
  76. HRESULT CMyComputerComponent::Show( CCookie* pcookie, LPARAM arg, HSCOPEITEM /*hScopeItem*/ )
  77. {
  78. TEST_NONNULL_PTR_PARAM(pcookie);
  79. if ( QueryComponentDataRef ().m_bMessageView )
  80. {
  81. CComPtr<IUnknown> spUnknown;
  82. CComPtr<IMessageView> spMessageView;
  83. HRESULT hr = m_pConsole->QueryResultView(&spUnknown);
  84. if (SUCCEEDED(hr))
  85. {
  86. hr = spUnknown->QueryInterface(IID_IMessageView, (PVOID*)&spMessageView);
  87. if (SUCCEEDED(hr))
  88. {
  89. CString title;
  90. VERIFY (title.LoadString (IDS_TASKPADTITLE_COMPUTER));
  91. spMessageView->SetTitleText(title);
  92. spMessageView->SetBodyText(QueryComponentDataRef ().m_strMessageViewMsg);
  93. spMessageView->SetIcon(Icon_Information);
  94. }
  95. if ( E_NOINTERFACE == hr )
  96. {
  97. // The interface "IMessageView" was not found so call
  98. // UpdateAllViews to force a call to GetResultType () which
  99. // will install it. Since UpdateAllViews call MMCN_SHOW before
  100. // calling GetResultType, this flag will prevent an endless
  101. // loop
  102. // Note: This call is made here because it OnViewChange with
  103. // this hint will call SelectScopeItem () which cannot be
  104. // called during MMCN_EXPAND
  105. if ( !m_bForcingGetResultType )
  106. {
  107. m_bForcingGetResultType = true;
  108. hr = m_pConsole->UpdateAllViews (0, 0, HINT_SELECT_ROOT_NODE);
  109. }
  110. }
  111. }
  112. return S_OK;
  113. }
  114. if ( 0 == arg )
  115. {
  116. if ( NULL == m_pResultData )
  117. {
  118. ASSERT( FALSE );
  119. return E_UNEXPECTED;
  120. }
  121. // not needed pcookie->ReleaseResultChildren();
  122. m_pViewedCookie = NULL;
  123. return S_OK;
  124. }
  125. m_pViewedCookie = (CMyComputerCookie*)pcookie;
  126. if ( MYCOMPUT_COMPUTER == m_pViewedCookie->m_objecttype
  127. && !(m_pViewedCookie->m_fRootCookieExpanded) )
  128. {
  129. m_pViewedCookie->m_fRootCookieExpanded = true;
  130. CComQIPtr<IConsole2, &IID_IConsole2> pIConsole2 = m_pConsole;
  131. ASSERT( pIConsole2 );
  132. if ( pIConsole2 )
  133. {
  134. // JonN 5/27/99 Some dead code in this directory contains bad templates for
  135. // looping on scopecookies, this is a better template
  136. POSITION pos = pcookie->m_listScopeCookieBlocks.GetHeadPosition();
  137. while (NULL != pos)
  138. {
  139. CBaseCookieBlock* pcookieblock = pcookie->m_listScopeCookieBlocks.GetNext( pos );
  140. ASSERT( NULL != pcookieblock );
  141. CMyComputerCookie* pChildCookie = (CMyComputerCookie*)pcookieblock;
  142. // JonN 03/07/00: PREFIX 56323
  143. switch ((NULL == pChildCookie) ? MYCOMPUT_COMPUTER
  144. : pChildCookie->m_objecttype)
  145. {
  146. case MYCOMPUT_SYSTEMTOOLS:
  147. case MYCOMPUT_STORAGE:
  148. {
  149. HRESULT hr = pIConsole2->Expand(pChildCookie->m_hScopeItem, TRUE);
  150. ASSERT(SUCCEEDED(hr));
  151. }
  152. break;
  153. default:
  154. break;
  155. }
  156. }
  157. }
  158. }
  159. LoadColumns( m_pViewedCookie );
  160. return PopulateListbox( m_pViewedCookie );
  161. }
  162. HRESULT CMyComputerComponent::OnNotifyAddImages( LPDATAOBJECT /*lpDataObject*/,
  163. LPIMAGELIST lpImageList,
  164. HSCOPEITEM /*hSelectedItem*/ )
  165. {
  166. if ( QueryComponentDataRef ().m_bMessageView )
  167. return S_OK;
  168. else
  169. return QueryComponentDataRef().LoadIcons(lpImageList,TRUE);
  170. }
  171. HRESULT CMyComputerComponent::OnNotifySnapinHelp (LPDATAOBJECT pDataObject)
  172. {
  173. CCookie* pBaseParentCookie = NULL;
  174. HRESULT hr = ExtractData( pDataObject,
  175. CMyComputerDataObject::m_CFRawCookie,
  176. reinterpret_cast<PBYTE>(&pBaseParentCookie),
  177. sizeof(pBaseParentCookie) );
  178. if ( FAILED(hr) )
  179. {
  180. ASSERT(FALSE);
  181. return S_OK;
  182. }
  183. CMyComputerCookie* pCookie = QueryComponentDataRef().ActiveCookie(pBaseParentCookie);
  184. if (NULL == pCookie)
  185. {
  186. ASSERT(FALSE);
  187. return S_OK;
  188. }
  189. LPCTSTR lpcszHelpTopic = L"compmgmt_topnode.htm";
  190. switch (pCookie->m_objecttype)
  191. {
  192. case MYCOMPUT_SYSTEMTOOLS:
  193. lpcszHelpTopic = L"system_tools_overview.htm";
  194. break;
  195. case MYCOMPUT_SERVERAPPS:
  196. lpcszHelpTopic = L"server_services_applications_overview.htm";
  197. break;
  198. case MYCOMPUT_STORAGE:
  199. lpcszHelpTopic = L"storage_devices_overview.htm";
  200. break;
  201. default:
  202. ASSERT(FALSE); // fall through
  203. case MYCOMPUT_COMPUTER:
  204. break;
  205. }
  206. return ShowHelpTopic( lpcszHelpTopic );
  207. }
  208. HRESULT CMyComputerComponent::PopulateListbox(CMyComputerCookie* /*pcookie*/)
  209. {
  210. // not needed (void) pcookie->AddRefResultChildren();
  211. return S_OK; // no resultitems in this snapin
  212. }
  213. ///////////////////////////////////////////////////////////////////////////////
  214. /// IExtendContextMenu
  215. STDMETHODIMP CMyComputerComponent::AddMenuItems(
  216. IDataObject* piDataObject,
  217. IContextMenuCallback* piCallback,
  218. long* pInsertionAllowed)
  219. {
  220. MFC_TRY;
  221. TRACE_METHOD(CMyComputerComponent,AddMenuItems);
  222. TEST_NONNULL_PTR_PARAM(piDataObject);
  223. TEST_NONNULL_PTR_PARAM(piCallback);
  224. TEST_NONNULL_PTR_PARAM(pInsertionAllowed);
  225. TRACE( "CMyComputerComponent: extending menu\n" );
  226. if ( 0 == (CCM_INSERTIONALLOWED_VIEW & (*pInsertionAllowed)) )
  227. return S_OK; // no View menu
  228. //
  229. // CODEWORK This code will not work if My Computer becomes an extension,
  230. // since the RawCookie format will not be available.
  231. // WARNING cookie cast
  232. //
  233. CCookie* pBaseParentCookie = NULL;
  234. HRESULT hr = ExtractData( piDataObject,
  235. CMyComputerDataObject::m_CFRawCookie,
  236. reinterpret_cast<PBYTE>(&pBaseParentCookie),
  237. sizeof(pBaseParentCookie) );
  238. if ( FAILED(hr) )
  239. {
  240. ASSERT(FALSE);
  241. return S_OK;
  242. }
  243. CMyComputerCookie* pCookie = QueryComponentDataRef().ActiveCookie(pBaseParentCookie);
  244. if (NULL == pCookie)
  245. {
  246. ASSERT(FALSE);
  247. return S_OK;
  248. }
  249. switch (pCookie->m_objecttype)
  250. {
  251. case MYCOMPUT_COMPUTER:
  252. case MYCOMPUT_SYSTEMTOOLS:
  253. case MYCOMPUT_SERVERAPPS:
  254. break;
  255. default:
  256. ASSERT(FALSE); // fall through
  257. case MYCOMPUT_STORAGE:
  258. return S_OK;
  259. }
  260. return hr;
  261. MFC_CATCH;
  262. } // CMyComputerComponent::AddMenuItems()
  263. STDMETHODIMP CMyComputerComponent::Command(
  264. LONG lCommandID,
  265. IDataObject* piDataObject )
  266. {
  267. MFC_TRY;
  268. TRACE_METHOD(CMyComputerComponent,Command);
  269. TEST_NONNULL_PTR_PARAM(piDataObject);
  270. TRACE( "CMyComputerComponent::Command: command %ld selected\n", lCommandID );
  271. switch (lCommandID)
  272. {
  273. case -1:
  274. break;
  275. default:
  276. ASSERT(FALSE);
  277. break;
  278. }
  279. return S_OK;
  280. MFC_CATCH;
  281. } // CMyComputerComponent::Command()
  282. HRESULT CMyComputerComponent::OnNotifySelect( LPDATAOBJECT lpDataObject, BOOL /*fSelected*/ )
  283. {
  284. MFC_TRY;
  285. TRACE_METHOD(CMyComputerComponent,OnNotifySelect);
  286. TEST_NONNULL_PTR_PARAM(lpDataObject);
  287. CCookie* pBaseParentCookie = NULL;
  288. HRESULT hr = ExtractData( lpDataObject,
  289. CMyComputerDataObject::m_CFRawCookie,
  290. reinterpret_cast<PBYTE>(&pBaseParentCookie),
  291. sizeof(pBaseParentCookie) );
  292. if ( FAILED(hr) )
  293. {
  294. ASSERT(FALSE);
  295. return S_OK;
  296. }
  297. CMyComputerCookie* pCookie = QueryComponentDataRef().ActiveCookie(pBaseParentCookie);
  298. if (NULL == pCookie)
  299. {
  300. ASSERT(FALSE);
  301. return S_OK;
  302. }
  303. // Set the default verb to display the properties of the selected object
  304. // We do this so that extensions can add properties, we don't have any
  305. m_pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES,
  306. ENABLED,
  307. (MYCOMPUT_COMPUTER == pCookie->m_objecttype) );
  308. m_pConsoleVerb->SetDefaultVerb(MMC_VERB_OPEN);
  309. return S_OK;
  310. MFC_CATCH;
  311. }
  312. STDMETHODIMP CMyComputerComponent::GetResultViewType(
  313. MMC_COOKIE cookie,
  314. LPOLESTR* ppViewType,
  315. long* pViewOptions)
  316. {
  317. MFC_TRY;
  318. if ( QueryComponentDataRef ().m_bMessageView )
  319. {
  320. m_bForcingGetResultType = false;
  321. *pViewOptions = MMC_VIEW_OPTIONS_NOLISTVIEWS;
  322. LPOLESTR psz = NULL;
  323. StringFromCLSID(CLSID_MessageView, &psz);
  324. USES_CONVERSION;
  325. if (psz != NULL)
  326. {
  327. *ppViewType = psz;
  328. return S_OK;
  329. }
  330. else
  331. return S_FALSE;
  332. }
  333. else
  334. return CComponent::GetResultViewType( cookie, ppViewType, pViewOptions );
  335. MFC_CATCH;
  336. }
  337. HRESULT CMyComputerComponent::OnViewChange (LPDATAOBJECT /*pDataObject*/, LPARAM /*data*/, LPARAM hint)
  338. {
  339. HRESULT hr = S_OK;
  340. if ( (HINT_SELECT_ROOT_NODE & hint) )
  341. {
  342. hr = m_pConsole->SelectScopeItem (QueryComponentDataRef().QueryRootCookie().m_hScopeItem);
  343. }
  344. return hr;
  345. }