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.

592 lines
16 KiB

  1. //____________________________________________________________________________
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997 - 1999
  5. //
  6. // File: ViewData.cpp
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 5/18/1997 RaviR Created
  15. //____________________________________________________________________________
  16. //
  17. #include "stdafx.h"
  18. #pragma hdrstop
  19. #ifdef _DEBUG
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. #include "menubtn.h"
  24. #include "viewdata.h"
  25. #include "multisel.h"
  26. #include "colwidth.h"
  27. #include "conview.h" // for CConsoleView
  28. #include "conframe.h"
  29. void CViewData::CreateControlbarsCache()
  30. {
  31. ASSERT(m_spControlbarsCache == NULL);
  32. CComObject<CControlbarsCache>* pObj;
  33. HRESULT hr = CComObject<CControlbarsCache>::CreateInstance(&pObj);
  34. ASSERT(SUCCEEDED(hr));
  35. pObj->SetViewData(this);
  36. if (SUCCEEDED(hr))
  37. m_spControlbarsCache = pObj;
  38. }
  39. STDMETHODIMP CNodeInitObject::InitViewData(LONG_PTR lViewData)
  40. {
  41. MMC_TRY
  42. if (lViewData == NULL)
  43. return E_INVALIDARG;
  44. SViewData* pVD = reinterpret_cast<SViewData*>(lViewData);
  45. ASSERT(pVD != NULL);
  46. ASSERT(pVD->m_spVerbSet == NULL);
  47. CViewData* pCVD = reinterpret_cast<CViewData*>(lViewData);
  48. ASSERT(pCVD != NULL);
  49. if (pVD->m_spVerbSet == NULL)
  50. {
  51. CComObject<CVerbSet>* pVerb;
  52. HRESULT hr = CComObject<CVerbSet>::CreateInstance(&pVerb);
  53. if (FAILED(hr))
  54. return hr;
  55. ASSERT(pVerb != NULL);
  56. pVD->m_spVerbSet = pVerb;
  57. ASSERT(pVD->m_spVerbSet != NULL);
  58. if (pVD->m_spVerbSet == NULL)
  59. return E_NOINTERFACE;
  60. }
  61. // See if the Column Persistence Object was created,
  62. // else create one.
  63. if ( pCVD && (pCVD->IsColumnPersistObjectInitialized() == false) )
  64. {
  65. // Create the column persistence object
  66. CComObject<CColumnPersistInfo>* pColData;
  67. HRESULT hr = CComObject<CColumnPersistInfo>::CreateInstance (&pColData);
  68. ASSERT(SUCCEEDED(hr) && pColData != NULL);
  69. if (FAILED(hr))
  70. {
  71. CStr strMsg;
  72. strMsg.LoadString(GetStringModule(), IDS_ColumnsCouldNotBePersisted);
  73. ::MessageBox(NULL, strMsg, NULL, MB_OK|MB_SYSTEMMODAL);
  74. }
  75. // Save a pointer to Column persistence object in CViewData.
  76. pCVD->InitializeColumnPersistObject(pColData, pColData);
  77. }
  78. return S_OK;
  79. MMC_CATCH
  80. }
  81. STDMETHODIMP CNodeInitObject::CleanupViewData(LONG_PTR lViewData)
  82. {
  83. SViewData* pVD = reinterpret_cast<SViewData*>(lViewData);
  84. if (pVD->m_pMultiSelection != NULL)
  85. {
  86. pVD->m_pMultiSelection->Release();
  87. pVD->m_pMultiSelection = NULL;
  88. }
  89. return S_OK;
  90. }
  91. // Buttons
  92. //
  93. void CViewData::ShowStdButtons(bool bShow)
  94. {
  95. DECLARE_SC(sc, _T("CViewData::ShowStdButtons"));
  96. CStdVerbButtons* pStdToolbar = GetStdVerbButtons();
  97. if (NULL == pStdToolbar)
  98. {
  99. sc = E_UNEXPECTED;
  100. return;
  101. }
  102. sc = pStdToolbar->ScShow(bShow);
  103. }
  104. void CViewData::ShowSnapinButtons(bool bShow)
  105. {
  106. DECLARE_SC(sc, _T("CViewData::ShowSnapinButtons"));
  107. IControlbarsCache* pICBC = GetControlbarsCache();
  108. if (pICBC == NULL)
  109. {
  110. sc = E_UNEXPECTED;
  111. return;
  112. }
  113. CControlbarsCache* pCBC = dynamic_cast<CControlbarsCache*>(pICBC);
  114. if (pCBC == NULL)
  115. {
  116. sc = E_UNEXPECTED;
  117. return;
  118. }
  119. sc = pCBC->ScShowToolbars(bShow);
  120. }
  121. bool IsFlagEnabled(DWORD cache, DWORD flag)
  122. {
  123. return ((cache & flag) == flag) ? true : false;
  124. }
  125. void CViewData::UpdateToolbars(DWORD dwTBNew)
  126. {
  127. ShowStdButtons(IsFlagEnabled(dwTBNew, STD_BUTTONS));
  128. ShowSnapinButtons(IsFlagEnabled(dwTBNew, SNAPIN_BUTTONS));
  129. SetToolbarsDisplayed(dwTBNew);
  130. }
  131. void CViewData::ToggleToolbar(long lMenuID)
  132. {
  133. DWORD dwTBOld = GetToolbarsDisplayed();
  134. DWORD dwTBNew = 0;
  135. DECLARE_SC(sc, _T("CViewData::ToggleToolbar"));
  136. switch (lMenuID)
  137. {
  138. case MID_STD_MENUS:
  139. {
  140. dwTBNew = dwTBOld ^ STD_MENUS;
  141. SetToolbarsDisplayed(dwTBNew);
  142. CConsoleFrame* pFrame = GetConsoleFrame();
  143. sc = ScCheckPointers(pFrame, E_UNEXPECTED);
  144. if (sc)
  145. return;
  146. sc = pFrame->ScShowMMCMenus(IsStandardMenusAllowed());
  147. if (sc)
  148. return;
  149. }
  150. break;
  151. case MID_STD_BUTTONS:
  152. dwTBNew = dwTBOld ^ STD_BUTTONS;
  153. ShowStdButtons(bool(dwTBNew & STD_BUTTONS));
  154. break;
  155. case MID_SNAPIN_MENUS:
  156. {
  157. dwTBNew = dwTBOld ^ SNAPIN_MENUS;
  158. SetToolbarsDisplayed(dwTBNew);
  159. CMenuButtonsMgr* pMenuButtonsMgr = GetMenuButtonsMgr();
  160. if (NULL != pMenuButtonsMgr)
  161. {
  162. sc = pMenuButtonsMgr->ScToggleMenuButton(IsSnapinMenusAllowed());
  163. }
  164. }
  165. break;
  166. case MID_SNAPIN_BUTTONS:
  167. dwTBNew = dwTBOld ^ SNAPIN_BUTTONS;
  168. ShowSnapinButtons(bool(dwTBNew & SNAPIN_BUTTONS));
  169. break;
  170. default:
  171. ASSERT(0 && "Unexpected");
  172. return;
  173. }
  174. SetToolbarsDisplayed(dwTBNew);
  175. }
  176. BOOL CViewData::RetrieveColumnData( const CLSID& refSnapinCLSID,
  177. const SColumnSetID& colID,
  178. CColumnSetData& columnSetData)
  179. {
  180. CColumnPersistInfo* pColPersInfo = NULL;
  181. if ( (NULL != m_pConsoleData) && (NULL != m_pConsoleData->m_spPersistStreamColumnData) )
  182. {
  183. pColPersInfo = dynamic_cast<CColumnPersistInfo*>(
  184. static_cast<IPersistStream*>(m_pConsoleData->m_spPersistStreamColumnData));
  185. if (pColPersInfo)
  186. return pColPersInfo->RetrieveColumnData( refSnapinCLSID, colID,
  187. GetViewID(), columnSetData);
  188. }
  189. return FALSE;
  190. }
  191. BOOL CViewData::SaveColumnData( const CLSID& refSnapinCLSID,
  192. const SColumnSetID& colID,
  193. CColumnSetData& columnSetData)
  194. {
  195. CColumnPersistInfo* pColPersInfo = NULL;
  196. if ( (NULL != m_pConsoleData) && (NULL != m_pConsoleData->m_spPersistStreamColumnData) )
  197. {
  198. pColPersInfo = dynamic_cast<CColumnPersistInfo*>(
  199. static_cast<IPersistStream*>(m_pConsoleData->m_spPersistStreamColumnData));
  200. if (pColPersInfo)
  201. return pColPersInfo->SaveColumnData( refSnapinCLSID, colID,
  202. GetViewID(), columnSetData);
  203. }
  204. return FALSE;
  205. }
  206. //+-------------------------------------------------------------------
  207. //
  208. // Member: CViewData::ScSaveColumnInfoList
  209. //
  210. // Synopsis: Save the CColumnInfoList for given snapin/col-id.
  211. //
  212. // Arguments: [refSnapinCLSID] - snapin GUID
  213. // [colID] - column-set-id
  214. // [colInfoList] - data for columns in a view.
  215. //
  216. // Returns: SC
  217. //
  218. //--------------------------------------------------------------------
  219. SC CViewData::ScSaveColumnInfoList(const CLSID& refSnapinCLSID, const SColumnSetID& colID,
  220. const CColumnInfoList& colInfoList)
  221. {
  222. DECLARE_SC(sc, _T("CViewData::ScSaveColumnInfoList"));
  223. sc = ScCheckPointers(m_pConsoleData, E_UNEXPECTED);
  224. if (sc)
  225. return sc;
  226. sc = ScCheckPointers(m_pConsoleData->m_spPersistStreamColumnData, E_UNEXPECTED);
  227. if (sc)
  228. return sc;
  229. CColumnPersistInfo* pColPersInfo = dynamic_cast<CColumnPersistInfo*>(
  230. static_cast<IPersistStream*>(m_pConsoleData->m_spPersistStreamColumnData));
  231. sc = ScCheckPointers(pColPersInfo, E_UNEXPECTED);
  232. if (sc)
  233. return sc;
  234. CColumnSetData colSetData;
  235. // Dont care if below succeeds or not, just merge sort & column data.
  236. pColPersInfo->RetrieveColumnData(refSnapinCLSID, colID, GetViewID(), colSetData);
  237. colSetData.set_ColumnInfoList(colInfoList);
  238. sc = pColPersInfo->SaveColumnData(refSnapinCLSID, colID, GetViewID(), colSetData) ? S_OK : E_FAIL;
  239. if (sc)
  240. return sc;
  241. return (sc);
  242. }
  243. //+-------------------------------------------------------------------
  244. //
  245. // Member: CViewData::ScSaveColumnSortData
  246. //
  247. // Synopsis: Save the given sort data for persistence into CColumnSetData.
  248. //
  249. // Arguments: [refSnapinCLSID] - snapin GUID
  250. // [colID] - column-set-id
  251. // [colSortInfo] - sort-data.
  252. //
  253. // Returns: SC
  254. //
  255. //--------------------------------------------------------------------
  256. SC CViewData::ScSaveColumnSortData(const CLSID& refSnapinCLSID, const SColumnSetID& colID,
  257. const CColumnSortInfo& colSortInfo)
  258. {
  259. DECLARE_SC(sc, _T("CViewData::ScSaveColumnSortData"));
  260. sc = ScCheckPointers(m_pConsoleData, E_UNEXPECTED);
  261. if (sc)
  262. return sc;
  263. sc = ScCheckPointers(m_pConsoleData->m_spPersistStreamColumnData, E_UNEXPECTED);
  264. if (sc)
  265. return sc;
  266. CColumnPersistInfo* pColPersInfo = dynamic_cast<CColumnPersistInfo*>(
  267. static_cast<IPersistStream*>(m_pConsoleData->m_spPersistStreamColumnData));
  268. sc = ScCheckPointers(pColPersInfo, E_UNEXPECTED);
  269. if (sc)
  270. return sc;
  271. CColumnSetData colSetData;
  272. // Dont care if below succeeds or not, just merge sort & column data.
  273. pColPersInfo->RetrieveColumnData(refSnapinCLSID, colID, GetViewID(), colSetData);
  274. CColumnSortList *pColSortList = colSetData.get_ColumnSortList();
  275. sc = ScCheckPointers(pColSortList, E_UNEXPECTED);
  276. if (sc)
  277. return sc;
  278. pColSortList->clear();
  279. pColSortList->push_back(colSortInfo);
  280. sc = pColPersInfo->SaveColumnData(refSnapinCLSID, colID, GetViewID(), colSetData) ? S_OK : E_FAIL;
  281. if (sc)
  282. return sc;
  283. return (sc);
  284. }
  285. VOID CViewData::DeleteColumnData( const CLSID& refSnapinCLSID,
  286. const SColumnSetID& colID)
  287. {
  288. CColumnPersistInfo* pColPersInfo = NULL;
  289. if ( (NULL != m_pConsoleData) && (NULL != m_pConsoleData->m_spPersistStreamColumnData) )
  290. {
  291. pColPersInfo = dynamic_cast<CColumnPersistInfo*>(
  292. static_cast<IPersistStream*>(m_pConsoleData->m_spPersistStreamColumnData));
  293. if (pColPersInfo)
  294. pColPersInfo->DeleteColumnData( refSnapinCLSID, colID, GetViewID());
  295. }
  296. return;
  297. }
  298. /*+-------------------------------------------------------------------------*
  299. * CViewSettings::GetSelectedNode
  300. *
  301. * Returns a pointer to the selected node in the view.
  302. *--------------------------------------------------------------------------*/
  303. CNode* CViewData::GetSelectedNode () const
  304. {
  305. CConsoleView* pConsoleView = GetConsoleView();
  306. if (pConsoleView == NULL)
  307. return (NULL);
  308. HNODE hNode = pConsoleView->GetSelectedNode();
  309. return (CNode::FromHandle(hNode));
  310. }
  311. //+-------------------------------------------------------------------
  312. //
  313. // Member: ScUpdateStdbarVerbs
  314. //
  315. // Synopsis: Update all the std-toolbar buttons with
  316. // current verb state, this is just a wrapper
  317. // around CStdVerbButtons::ScUpdateStdbarVerbs.
  318. //
  319. // Arguments: None
  320. //
  321. // Returns: SC
  322. //
  323. //--------------------------------------------------------------------
  324. SC CViewData::ScUpdateStdbarVerbs()
  325. {
  326. DECLARE_SC (sc, _T("CViewData::ScUpdateStdbarVerbs"));
  327. CStdVerbButtons* pStdVerbButtons = GetStdVerbButtons();
  328. if (NULL == pStdVerbButtons)
  329. {
  330. sc = E_UNEXPECTED;
  331. return sc;
  332. }
  333. // Update the std-verb tool-buttons.
  334. sc = pStdVerbButtons->ScUpdateStdbarVerbs(GetVerbSet());
  335. return sc;
  336. }
  337. //+-------------------------------------------------------------------
  338. //
  339. // Member: ScUpdateStdbarVerb
  340. //
  341. // Synopsis: Update given verb's tool-button, this is just
  342. // a wrapper around CStdVerbButtons::ScUpdateStdbarVerb.
  343. //
  344. // Arguments: [cVerb] - the verb whose button to be updated.
  345. //
  346. // Returns: SC
  347. //
  348. //--------------------------------------------------------------------
  349. SC CViewData::ScUpdateStdbarVerb (MMC_CONSOLE_VERB cVerb)
  350. {
  351. DECLARE_SC (sc, _T("CViewData::ScUpdateStdbarVerb"));
  352. CStdVerbButtons* pStdVerbButtons = GetStdVerbButtons();
  353. if (NULL == pStdVerbButtons)
  354. {
  355. sc = E_UNEXPECTED;
  356. return sc;
  357. }
  358. // Update the std-verb tool-buttons.
  359. sc = pStdVerbButtons->ScUpdateStdbarVerb(cVerb, GetVerbSet());
  360. return sc;
  361. }
  362. //+-------------------------------------------------------------------
  363. //
  364. // Member: ScUpdateStdbarVerb
  365. //
  366. // Synopsis: Update given verb's tool-button, this is just
  367. // a wrapper around CStdVerbButtons::ScUpdateStdbarVerb.
  368. //
  369. // Arguments: [cVerb] - the verb whose button to be updated.
  370. // [byState] - State of the button to be updated.
  371. // [bFlag] - State.
  372. //
  373. // Returns: SC
  374. //
  375. //--------------------------------------------------------------------
  376. SC CViewData::ScUpdateStdbarVerb (MMC_CONSOLE_VERB cVerb, BYTE byState, BOOL bFlag)
  377. {
  378. DECLARE_SC (sc, _T("CViewData::ScUpdateStdbarVerb"));
  379. CStdVerbButtons* pStdVerbButtons = GetStdVerbButtons();
  380. if (NULL == pStdVerbButtons)
  381. {
  382. sc = E_UNEXPECTED;
  383. return sc;
  384. }
  385. // Update the std-verb tool-buttons.
  386. sc = pStdVerbButtons->ScUpdateStdbarVerb(cVerb, byState, bFlag);
  387. return sc;
  388. }
  389. //+-------------------------------------------------------------------
  390. //
  391. // Member: CViewData::ScIsVerbSetContextForMultiSelect
  392. //
  393. // Synopsis: Get the selection context data stored in verb-set.
  394. //
  395. // Arguments: [bMultiSelection] - [out] Is the verb context for multiseleciton?
  396. //
  397. // Returns: SC,
  398. //
  399. //--------------------------------------------------------------------
  400. SC CViewData::ScIsVerbSetContextForMultiSelect(bool& bMultiSelection)
  401. {
  402. DECLARE_SC(sc, _T("CNode::ScIsVerbSetContextForMultiSelect"));
  403. bMultiSelection = false;
  404. // 1. Get the verb set.
  405. CVerbSet* pVerbSet = dynamic_cast<CVerbSet*>(GetVerbSet() );
  406. sc = ScCheckPointers( pVerbSet, E_UNEXPECTED );
  407. if (sc)
  408. return sc;
  409. // 2. Get context information from permanent verb-set.
  410. CNode *pNode = NULL;
  411. LPARAM lCookie = NULL;
  412. bool bScopePane;
  413. bool bSelected;
  414. SC scNoTrace = pVerbSet->ScGetVerbSetContext(pNode, bScopePane, lCookie, bSelected);
  415. if (scNoTrace)
  416. return sc; // ignore the error.
  417. if (LVDATA_MULTISELECT == lCookie)
  418. {
  419. bMultiSelection = true;
  420. return sc;
  421. }
  422. return sc;
  423. }
  424. //+-------------------------------------------------------------------
  425. //
  426. // Member: CViewData::ScGetVerbSetData
  427. //
  428. // Synopsis: Get the selection context data stored in verb-set.
  429. //
  430. // Arguments: [ppDataObject] - [out] dataobject of item in the verb-set context.
  431. // This is the item for which last non-temporary MMCN_SELECT
  432. // was sent last time.
  433. // [ppComponent] - [out] the above item's component
  434. // [bScope] - [out] Is the above item scope or result?
  435. // [bSelected] - [out] Is the above item selected or not?
  436. // [ppszNodeName] - [out] If bScope is true the node name else the name of the node
  437. // that owns result pane. This is for debug purposes only.
  438. //
  439. // Returns: SC
  440. //
  441. //--------------------------------------------------------------------
  442. SC CViewData::ScGetVerbSetData(IDataObject **ppDataObject, CComponent **ppComponent,
  443. bool& bScopeItem, bool& bSelected
  444. #ifdef DBG
  445. , LPCTSTR *ppszNodeName
  446. #endif
  447. )
  448. {
  449. DECLARE_SC(sc, _T("CNode::ScGetVerbSetData"));
  450. sc = ScCheckPointers(ppDataObject, ppComponent);
  451. if (sc)
  452. return sc;
  453. *ppDataObject = NULL;
  454. *ppComponent = NULL;
  455. // 1. Get the verb set.
  456. CVerbSet* pVerbSet = dynamic_cast<CVerbSet*>(GetVerbSet() );
  457. sc = ScCheckPointers( pVerbSet, E_UNEXPECTED );
  458. if (sc)
  459. return sc;
  460. // 2. Get context information from permanent verb-set.
  461. CNode *pNode = NULL;
  462. LPARAM lCookie = NULL;
  463. bool bScopePane;
  464. SC scNoTrace = pVerbSet->ScGetVerbSetContext(pNode, bScopePane, lCookie, bSelected);
  465. if (scNoTrace)
  466. return scNoTrace;
  467. sc = ScCheckPointers(pNode, E_UNEXPECTED);
  468. if (sc)
  469. return sc;
  470. // 3. Get the dataobject from context information.
  471. sc = pNode->ScGetDataObject(bScopePane, lCookie, bScopeItem, ppDataObject, ppComponent);
  472. if (sc)
  473. return sc;
  474. #ifdef DBG
  475. if (! ppszNodeName)
  476. return (sc = E_INVALIDARG);
  477. *ppszNodeName = pNode->GetDisplayName().data();
  478. #endif
  479. return (sc);
  480. }