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.

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