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.

457 lines
13 KiB

  1. // stdcmpnt.cpp : Implementation of CComponent
  2. #include "guidhelp.h" // ExtractData
  3. // Note that m_pComponentData is still NULL during construction
  4. CComponent::CComponent()
  5. : m_pConsole( NULL ),
  6. m_pConsoleVerb( NULL ),
  7. m_pHeader( NULL ),
  8. m_pResultData( NULL ),
  9. m_pConsoleNameSpace( NULL ),
  10. m_pRsltImageList( NULL ),
  11. m_pComponentData( NULL )
  12. {
  13. }
  14. CComponent::~CComponent()
  15. {
  16. VERIFY( SUCCEEDED(ReleaseAll()) );
  17. }
  18. /////////////////////////////////////////////////////////////////////
  19. // CComponent::SetComponentDataPtr()
  20. void CComponent::SetComponentDataPtr(
  21. CComponentData* pComponentData)
  22. {
  23. ASSERT(NULL != pComponentData && NULL == m_pComponentData);
  24. (void) ((IComponentData*)pComponentData)->AddRef();
  25. m_pComponentData = pComponentData;
  26. }
  27. /////////////////////////////////////////////////////////////////////
  28. // CComponent::IComponent::QueryDataObject()
  29. STDMETHODIMP CComponent::QueryDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type, LPDATAOBJECT* ppDataObject)
  30. {
  31. HRESULT hr = S_OK;
  32. MFC_TRY;
  33. // Delegate it to the IComponentData
  34. hr = QueryBaseComponentDataRef().QueryDataObject(cookie, type, ppDataObject);
  35. MFC_CATCH;
  36. return hr;
  37. }
  38. /////////////////////////////////////////////////////////////////////
  39. // CComponent::IComponent::CompareObjects()
  40. STDMETHODIMP CComponent::CompareObjects(
  41. LPDATAOBJECT lpDataObjectA,
  42. LPDATAOBJECT lpDataObjectB)
  43. {
  44. return QueryBaseComponentDataRef().CompareObjects( lpDataObjectA, lpDataObjectB );
  45. }
  46. /////////////////////////////////////////////////////////////////////
  47. // Virtual function called by CComponent::IComponent::Notify(MMCN_PROPERTY_CHANGE)
  48. // OnPropertyChange() is generated by MMCPropertyChangeNotify( param )
  49. HRESULT CComponent::OnPropertyChange( LPARAM /*param*/)
  50. {
  51. return S_OK;
  52. }
  53. /////////////////////////////////////////////////////////////////////
  54. // Virtual function called by CComponent::IComponent::Notify(MMCN_SELECT)
  55. HRESULT CComponent::OnNotifySelect( LPDATAOBJECT /*lpDataObject*/, BOOL /*fSelected*/ )
  56. {
  57. return S_OK;
  58. }
  59. /////////////////////////////////////////////////////////////////////
  60. // Virtual function called by CComponent::IComponent::Notify(MMCN_ACTIVATE)
  61. HRESULT CComponent::OnNotifyActivate( LPDATAOBJECT /*lpDataObject*/, BOOL /*fActivated*/ )
  62. {
  63. return S_OK;
  64. }
  65. /////////////////////////////////////////////////////////////////////
  66. // Virtual function called by CComponent::IComponent::Notify(MMCN_CLICK)
  67. HRESULT CComponent::OnNotifyClick( LPDATAOBJECT /*lpDataObject*/ )
  68. {
  69. TRACE0("CComponent::OnNotifyClick().\n");
  70. return S_OK;
  71. }
  72. /////////////////////////////////////////////////////////////////////
  73. // Virtual function called by CComponent::IComponent::Notify(MMCN_DBLCLICK)
  74. HRESULT CComponent::OnNotifyDblClick( LPDATAOBJECT /*lpDataObject*/ )
  75. {
  76. // Returning S_FALSE allows MMC to do the default verb.
  77. return S_FALSE;
  78. }
  79. /////////////////////////////////////////////////////////////////////
  80. // Virtual function called by CComponent::IComponent::Notify(MMCN_ADD_IMAGES)
  81. HRESULT CComponent::OnNotifyAddImages( LPDATAOBJECT /*lpDataObject*/,
  82. LPIMAGELIST /*lpImageList*/,
  83. HSCOPEITEM /*hSelectedItem*/ )
  84. {
  85. ASSERT(FALSE); // this should be redefined by all snapins
  86. return S_OK;
  87. }
  88. /////////////////////////////////////////////////////////////////////
  89. // Virtual function called by CComponent::IComponent::Notify(MMCN_VIEW_CHANGE)
  90. // OnViewChange is generated by UpdateAllViews( lpDataObject, data, hint )
  91. HRESULT CComponent::OnViewChange( LPDATAOBJECT /*lpDataObject*/, LPARAM /*data*/, LPARAM /*hint*/ )
  92. {
  93. return S_OK;
  94. }
  95. /////////////////////////////////////////////////////////////////////
  96. // Virtual function called by CComponent::IComponent::Notify(MMCN_REFRESH)
  97. // OnNotifyRefresh is generated by enabling the verb MMC_VERB_REFRESH.
  98. // Typically this routine will be overriden.
  99. HRESULT CComponent::OnNotifyRefresh( LPDATAOBJECT /*lpDataObject*/ )
  100. {
  101. TRACE0("CComponent::OnNotifyRefresh() - You must implement your own refresh routine.\n");
  102. return S_OK;
  103. }
  104. /////////////////////////////////////////////////////////////////////
  105. // Virtual function called by CComponent::IComponent::Notify(MMCN_DELETE)
  106. HRESULT CComponent::OnNotifyDelete( LPDATAOBJECT /*lpDataObject*/ )
  107. {
  108. return S_OK;
  109. }
  110. /////////////////////////////////////////////////////////////////////
  111. // Virtual function called by CComponent::IComponent::Notify(MMCN_COLUMN_CLICK)
  112. HRESULT CComponent::OnNotifyColumnClick( LPDATAOBJECT /*lpDataObject*/, LPARAM /*iColumn*/, LPARAM /*uFlags*/ )
  113. {
  114. return S_OK;
  115. }
  116. /////////////////////////////////////////////////////////////////////
  117. // CComponent::ReleaseAll()
  118. HRESULT CComponent::ReleaseAll()
  119. {
  120. MFC_TRY;
  121. TRACE_METHOD(CComponent,Destructor);
  122. if (NULL != m_pHeader)
  123. m_pConsole->SetHeader(NULL);
  124. SAFE_RELEASE(m_pHeader);
  125. SAFE_RELEASE(m_pResultData);
  126. SAFE_RELEASE(m_pConsoleNameSpace);
  127. SAFE_RELEASE(m_pRsltImageList);
  128. SAFE_RELEASE(m_pConsole);
  129. SAFE_RELEASE(m_pConsoleVerb);
  130. if ( NULL != m_pComponentData )
  131. {
  132. ((IComponentData*)m_pComponentData)->Release();
  133. m_pComponentData = NULL;
  134. }
  135. MFC_CATCH;
  136. return S_OK;
  137. }
  138. /////////////////////////////////////////////////////////////////////////////
  139. // CComponent::IComponent::Initialize()
  140. STDMETHODIMP CComponent::Initialize(LPCONSOLE lpConsole)
  141. {
  142. MFC_TRY;
  143. TRACE_METHOD(CComponent,Create);
  144. TEST_NONNULL_PTR_PARAM(lpConsole);
  145. if (NULL == lpConsole)
  146. {
  147. ASSERT(FALSE);
  148. return E_POINTER;
  149. }
  150. ASSERT( NULL == m_pConsole );
  151. SAFE_RELEASE( m_pConsole ); // just in case
  152. lpConsole->AddRef();
  153. m_pConsole = lpConsole;
  154. HRESULT hr = m_pConsole->QueryInterface(IID_IHeaderCtrl, (void**)&m_pHeader);
  155. ASSERT(hr == S_OK);
  156. if (FAILED(hr))
  157. return E_FAIL;
  158. m_pConsole->SetHeader(m_pHeader);
  159. hr = m_pConsole->QueryConsoleVerb(OUT &m_pConsoleVerb);
  160. ASSERT(hr == S_OK);
  161. if (FAILED(hr))
  162. return hr;
  163. ASSERT(NULL != m_pConsoleVerb);
  164. hr = m_pConsole->QueryInterface(IID_IResultData, (void**)&m_pResultData);
  165. if (FAILED(hr))
  166. return hr;
  167. hr = m_pConsole->QueryInterface(IID_IConsoleNameSpace, (void**)&m_pConsoleNameSpace);
  168. if (FAILED(hr))
  169. return hr;
  170. hr = m_pConsole->QueryInterface(IID_IImageList, (void**)&m_pRsltImageList);
  171. if (FAILED(hr))
  172. return hr;
  173. // Load icons for the scope pane
  174. LPIMAGELIST pImageList;
  175. hr = m_pConsole->QueryScopeImageList(&pImageList);
  176. ASSERT(SUCCEEDED(hr));
  177. // LoadIconsIntoImageList(pImageList, FALSE);
  178. pImageList->Release();
  179. MFC_CATCH;
  180. return S_OK;
  181. } // CComponent::Initialize()
  182. /////////////////////////////////////////////////////////////////////////////
  183. // CComponent::IComponent::Notify()
  184. // Entry point for all the MMCN_ notification messages.
  185. // The routine will then call virtual functions of the CComponent object.
  186. STDMETHODIMP CComponent::Notify(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param)
  187. {
  188. HRESULT hr = S_OK;
  189. // MFC_TRY;
  190. TRACE_METHOD(CComponent,Notify);
  191. switch (event)
  192. {
  193. case MMCN_SHOW:
  194. // CODEWORK this is hacked together quickly
  195. {
  196. CCookie* pcookie = NULL;
  197. hr = ExtractData( lpDataObject,
  198. CDataObject::m_CFRawCookie,
  199. (PBYTE)&pcookie,
  200. sizeof(pcookie) );
  201. ASSERT( SUCCEEDED(hr) );
  202. CCookie* pActiveCookie = ActiveBaseCookie (pcookie);
  203. // Save the scope item handle in the cookie
  204. pActiveCookie->m_hScopeItem = (HSCOPEITEM) param;
  205. hr = Show (pActiveCookie, arg, (HSCOPEITEM) param);
  206. }
  207. break;
  208. case MMCN_MINIMIZED:
  209. break;
  210. case MMCN_SELECT:
  211. hr = OnNotifySelect( lpDataObject, (BOOL)(HIWORD(arg)) );
  212. break;
  213. case MMCN_ACTIVATE:
  214. hr = OnNotifyActivate( lpDataObject, (BOOL)arg );
  215. break;
  216. case MMCN_ADD_IMAGES:
  217. hr = OnNotifyAddImages( lpDataObject,
  218. reinterpret_cast<IImageList*>(arg),
  219. (HSCOPEITEM)param );
  220. break;
  221. case MMCN_CLICK:
  222. hr = OnNotifyClick( lpDataObject );
  223. break;
  224. case MMCN_DBLCLICK:
  225. hr = OnNotifyDblClick( lpDataObject );
  226. break;
  227. case MMCN_PROPERTY_CHANGE:
  228. // CODEWORK arg is "fScopePane", should this be passed on?
  229. hr = OnPropertyChange( param );
  230. break;
  231. case MMCN_VIEW_CHANGE:
  232. hr = OnViewChange( lpDataObject, arg, param );
  233. break;
  234. case MMCN_REFRESH:
  235. hr = OnNotifyRefresh( lpDataObject );
  236. break;
  237. case MMCN_DELETE:
  238. hr = OnNotifyDelete( lpDataObject );
  239. break;
  240. case MMCN_COLUMN_CLICK:
  241. hr = OnNotifyColumnClick( lpDataObject, arg, param );
  242. break;
  243. case MMCN_CONTEXTHELP:
  244. hr = OnNotifyContextHelp( lpDataObject );
  245. break;
  246. case MMCN_SNAPINHELP:
  247. hr = OnNotifySnapinHelp( lpDataObject );
  248. break;
  249. default:
  250. TRACE1("INFO: CComponent::Notify() - Unknown Event %d.\n", event);
  251. break;
  252. }
  253. // MFC_CATCH;
  254. return hr;
  255. } // CComponent::Notify()
  256. // parameter "MMC_COOKIE cookie" is reserved per MSDN
  257. STDMETHODIMP CComponent::Destroy(MMC_COOKIE /*cookie*/)
  258. {
  259. MFC_TRY;
  260. TRACE_METHOD(CComponent,Destroy);
  261. VERIFY( SUCCEEDED( ReleaseAll() ) );
  262. MFC_CATCH;
  263. return S_OK;
  264. }
  265. HRESULT CComponent::InsertResultCookies( CCookie& refparentcookie )
  266. {
  267. ASSERT( NULL != m_pResultData );
  268. RESULTDATAITEM tRDItem;
  269. ::ZeroMemory( &tRDItem, sizeof(tRDItem) );
  270. tRDItem.nCol = 0;
  271. tRDItem.mask = RDI_STR | RDI_IMAGE | RDI_PARAM;
  272. tRDItem.str = MMC_CALLBACK;
  273. // CODEWORK should use MMC_ICON_CALLBACK here
  274. HRESULT hr = S_OK;
  275. POSITION pos = refparentcookie.m_listResultCookieBlocks.GetHeadPosition();
  276. while (NULL != pos)
  277. {
  278. CBaseCookieBlock* pblock = refparentcookie.m_listResultCookieBlocks.GetNext( pos );
  279. ASSERT( NULL != pblock );
  280. for (INT i = 0; i < pblock->QueryNumCookies(); i++)
  281. {
  282. CCookie* pbasecookie = pblock->QueryBaseCookie(i);
  283. tRDItem.nImage = QueryBaseComponentDataRef().QueryImage( *pbasecookie, FALSE );
  284. // WARNING cookie cast
  285. tRDItem.lParam = reinterpret_cast<LPARAM>(pbasecookie);
  286. hr = m_pResultData->InsertItem(&tRDItem);
  287. if ( FAILED(hr) )
  288. {
  289. ASSERT(FALSE);
  290. break;
  291. }
  292. }
  293. }
  294. return hr;
  295. }
  296. STDMETHODIMP CComponent::GetResultViewType(MMC_COOKIE /*cookie*/,
  297. BSTR* ppViewType,
  298. long* pViewOptions)
  299. {
  300. // ISSUE-2002/03/28-JonN check for NULL
  301. *ppViewType = NULL;
  302. *pViewOptions = MMC_VIEW_OPTIONS_NONE;
  303. return S_FALSE;
  304. }
  305. STDMETHODIMP CComponent::GetDisplayInfo(RESULTDATAITEM* pResultDataItem)
  306. {
  307. MFC_TRY;
  308. CCookie* pcookie = ActiveBaseCookie(
  309. reinterpret_cast<CCookie*>(pResultDataItem->lParam));
  310. // ISSUE-2002/03/28-JonN handle NULL parameter
  311. ASSERT( NULL != pResultDataItem ); // result items never have NULL cookie
  312. if (RDI_STR & pResultDataItem->mask)
  313. {
  314. pResultDataItem->str = QueryBaseComponentDataRef().QueryResultColumnText(
  315. *pcookie,
  316. pResultDataItem->nCol );
  317. if ( NULL == pResultDataItem->str )
  318. pResultDataItem->str = L""; // just in case
  319. }
  320. if ( RDI_IMAGE & pResultDataItem->mask )
  321. {
  322. pResultDataItem->nImage = QueryBaseComponentDataRef().QueryImage(
  323. *pcookie, FALSE );
  324. }
  325. MFC_CATCH;
  326. return S_OK;
  327. }
  328. // CODEWORK These should be parameters rather than globals
  329. // CODEWORK figure out correct const'ing
  330. extern UINT** g_aColumns;
  331. extern int** g_aColumnWidths;
  332. HRESULT CComponent::LoadColumnsFromArrays(
  333. INT objecttype )
  334. {
  335. ASSERT( NULL != m_pHeader );
  336. CString str;
  337. // ISSUE-2002/03/28-JonN check objecttype parameter
  338. // ISSUE-2002/03/28-JonN should invoke AFX_MANAGE_STATE
  339. const UINT* pColumns = g_aColumns[objecttype];
  340. const int* pColumnWidths = g_aColumnWidths[objecttype];
  341. ASSERT( NULL != pColumns && NULL != pColumnWidths );
  342. for ( INT i = 0; 0 != pColumns[i]; i++)
  343. {
  344. VERIFY( str.LoadString( pColumns[i] ) );
  345. m_pHeader->InsertColumn(i, const_cast<LPTSTR>((LPCTSTR)str), LVCFMT_LEFT,
  346. pColumnWidths[i]);
  347. }
  348. return S_OK;
  349. }
  350. HRESULT CComponent::OnNotifySnapinHelp (LPDATAOBJECT /*pDataObject*/)
  351. {
  352. return ShowHelpTopic( NULL ); // snapins should redefine this
  353. }
  354. HRESULT CComponent::OnNotifyContextHelp (LPDATAOBJECT pDataObject)
  355. {
  356. return OnNotifySnapinHelp( pDataObject ); // snapins should redefine this
  357. }
  358. HRESULT CComponent::ShowHelpTopic( LPCWSTR lpcwszHelpTopic )
  359. {
  360. HRESULT hr = S_OK;
  361. MFC_TRY;
  362. CComQIPtr<IDisplayHelp,&IID_IDisplayHelp> spDisplayHelp = m_pConsole;
  363. if ( !spDisplayHelp )
  364. {
  365. ASSERT(FALSE);
  366. return E_UNEXPECTED;
  367. }
  368. CString strHelpTopic;
  369. hr = QueryBaseComponentDataRef().GetHtmlHelpFilePath( strHelpTopic );
  370. if ( FAILED(hr) )
  371. return hr;
  372. if (NULL != lpcwszHelpTopic && L'\0' != *lpcwszHelpTopic)
  373. {
  374. strHelpTopic += L"::/";
  375. strHelpTopic += lpcwszHelpTopic;
  376. }
  377. hr = spDisplayHelp->ShowTopic (T2OLE ((LPWSTR)(LPCWSTR) strHelpTopic));
  378. ASSERT (SUCCEEDED (hr));
  379. MFC_CATCH;
  380. return hr;
  381. }