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.

836 lines
26 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1999
  5. //
  6. // File: viewpers.cpp
  7. //
  8. // Contents: View Persistence data structures.
  9. //
  10. // History: 04-Apr-99 AnandhaG Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #include "stdafx.h"
  14. #include "viewpers.h"
  15. #include "macros.h"
  16. #include "comdbg.h"
  17. #define MAX_VIEWITEMS_PERSISTED 50
  18. //------------------------------------------------------------------
  19. // class CViewSettingsPersistor
  20. //------------------------------------------------------------------
  21. CViewSettingsPersistor::CViewSettingsPersistor() :
  22. m_dwMaxItems(MAX_VIEWITEMS_PERSISTED), m_bDirty(false)
  23. {
  24. // Now read the registry to see if m_dwMaxItems is specified.
  25. // Check if the settings key exists.
  26. CRegKeyEx rSettingsKey;
  27. if (rSettingsKey.ScOpen (HKEY_LOCAL_MACHINE, SETTINGS_KEY, KEY_READ).IsError())
  28. return;
  29. // Read the values for MaxColDataPersisted.
  30. if (rSettingsKey.IsValuePresent(g_szMaxViewItemsPersisted))
  31. {
  32. DWORD dwType = REG_DWORD;
  33. DWORD dwSize = sizeof(DWORD);
  34. SC sc = rSettingsKey.ScQueryValue (g_szMaxViewItemsPersisted, &dwType,
  35. &m_dwMaxItems, &dwSize);
  36. if (sc)
  37. sc.TraceAndClear();
  38. }
  39. }
  40. //+-------------------------------------------------------------------
  41. //
  42. // Member: ScGetViewSettings
  43. //
  44. // Synopsis: Given the CViewSettingsID return the CViewSettings object.
  45. //
  46. // Arguments: [viewSettingsID] - [in]
  47. // [viewSettings] - [out]
  48. //
  49. // Returns: SC, S_FALSE if none found.
  50. //
  51. //--------------------------------------------------------------------
  52. SC CViewSettingsPersistor::ScGetViewSettings(const CViewSettingsID& viewSettingsID,
  53. CViewSettings& viewSettings)
  54. {
  55. DECLARE_SC(sc, TEXT("CViewSettingsPersistor::ScGetViewSettings"));
  56. // 1. Look in the map if there is persisted data for given id.
  57. CViewSettingsIDToViewSettingsMap::iterator itViewSettingsDataMap;
  58. itViewSettingsDataMap = m_mapViewSettingsIDToViewSettings.find(viewSettingsID);
  59. if (itViewSettingsDataMap == m_mapViewSettingsIDToViewSettings.end())
  60. return (sc = S_FALSE);
  61. // Found the data.
  62. IteratorToViewSettingsList itViewSettings = itViewSettingsDataMap->second;
  63. // 2. Copy the data.
  64. viewSettings = *itViewSettings;
  65. // 3. Move this item to the front of the queue.
  66. m_listViewSettings.erase(itViewSettings);
  67. itViewSettings = m_listViewSettings.insert(m_listViewSettings.begin(), viewSettings);
  68. itViewSettingsDataMap->second = itViewSettings;
  69. return sc;
  70. }
  71. //+-------------------------------------------------------------------
  72. //
  73. // Member: ScSetViewSettings
  74. //
  75. // Synopsis: Modify the persisted view information
  76. // for given view and bookmark (node).
  77. //
  78. // Arguments: [nViewID] - Snapin Guid
  79. // [pBookmark] - Column Set Identifier.
  80. // [viewDataSet] - View ID.
  81. //
  82. // Returns: TRUE - Loaded successfully.
  83. //
  84. // History: 04-26-1999 AnandhaG Created
  85. //
  86. //--------------------------------------------------------------------
  87. SC CViewSettingsPersistor::ScSetViewSettings(const CViewSettingsID& viewSettingsID,
  88. const CViewSettings& viewSettings,
  89. bool bSetViewDirty)
  90. {
  91. DECLARE_SC(sc, TEXT("CViewSettingsPersistor::ScSetViewSettings"));
  92. // 1. Garbage collect if the number of items in the list are 40% more than pre-set limit.
  93. if (m_listViewSettings.size() >= (m_dwMaxItems * (1 + VIEWSETTINGS_MAXLIMIT)) )
  94. {
  95. sc = ScGarbageCollectItems();
  96. if (sc)
  97. sc.TraceAndClear();
  98. }
  99. // 2. Insert the item into the front of the queue.
  100. IteratorToViewSettingsList itViewSettings;
  101. itViewSettings = m_listViewSettings.insert(m_listViewSettings.begin(), viewSettings);
  102. // 3. See if there is data persisted for this id.
  103. CViewSettingsIDToViewSettingsMap::iterator itViewSettingsDataMap;
  104. itViewSettingsDataMap = m_mapViewSettingsIDToViewSettings.find(viewSettingsID);
  105. if (itViewSettingsDataMap == m_mapViewSettingsIDToViewSettings.end()) // not found so insert data.
  106. {
  107. m_mapViewSettingsIDToViewSettings.insert(
  108. CViewSettingsIDToViewSettingsMap::value_type(viewSettingsID, itViewSettings) );
  109. }
  110. else
  111. {
  112. // found, so replace old settings.
  113. m_listViewSettings.erase(itViewSettingsDataMap->second);
  114. itViewSettingsDataMap->second = itViewSettings;
  115. }
  116. // dirty flag accumulates.
  117. m_bDirty = (m_bDirty || bSetViewDirty);
  118. return sc;
  119. }
  120. //+-------------------------------------------------------------------
  121. //
  122. // Member: CViewSettingsPersistor::ScGetTaskpadID
  123. //
  124. // Synopsis: Given the nodetype & viewid get the taskpad id (this
  125. // is for taskpads persisted per nodetype).
  126. //
  127. // Arguments: [nViewID] - [in]
  128. // [guidNodeType] - [in]
  129. // [guidTaskpad] - [out]
  130. //
  131. // Returns: SC, S_FALSE if none found.
  132. //
  133. //--------------------------------------------------------------------
  134. SC CViewSettingsPersistor::ScGetTaskpadID (int nViewID, const GUID& guidNodeType ,GUID& guidTaskpad)
  135. {
  136. DECLARE_SC(sc, _T("CViewSettingsPersistor::ScGetTaskpadID"));
  137. // 1. Init out param.
  138. guidTaskpad = GUID_NULL;
  139. // 2. Construct a CViewSettingsID object with given nodetype & viewid.
  140. CViewSettingsID viewSettingsID(nViewID, guidNodeType);
  141. // 3. Get the viewsettings
  142. CViewSettings viewSettings;
  143. sc = ScGetViewSettings(viewSettingsID, viewSettings);
  144. // If none exists return
  145. if (sc != S_OK)
  146. return sc;
  147. // 4. CViewSettings exists, see if there is valid taskpad-id stored.
  148. sc = viewSettings.ScGetTaskpadID(guidTaskpad);
  149. if (sc) // taskpad-id is not valid.
  150. return (sc = S_FALSE);
  151. return (sc);
  152. }
  153. //+-------------------------------------------------------------------
  154. //
  155. // Member: CViewSettingsPersistor::ScSetTaskpadID
  156. //
  157. // Synopsis: Given the nodetype & viewid set the taskpad id (this
  158. // is for taskpads persisted per nodetype).
  159. //
  160. // NOTE: NUKE ANY NODE-SPECIFIC TASKPAD-ID THAT IS STORED.
  161. //
  162. // Arguments: [nViewID] - [in]
  163. // [guidNodeType] - [in]
  164. // [bookmark] - [in]
  165. // [guidTaskpad] - [in]
  166. // [bSetDirty] - [in] set the console file dirty
  167. //
  168. // Returns: SC
  169. //
  170. //--------------------------------------------------------------------
  171. SC CViewSettingsPersistor::ScSetTaskpadID (int nViewID, const GUID& guidNodeType,
  172. const CBookmark& bookmark, const GUID& guidTaskpad,
  173. bool bSetDirty)
  174. {
  175. DECLARE_SC(sc, _T("CViewSettingsPersistor::ScSetTaskpadID"));
  176. // 1. First nuke the the old node specific taskpad-id settings (if any).
  177. // 1.a) Construct a CViewSettingsID object with given nodetype & viewid.
  178. CViewSettingsID viewSettingsIDNodeSpecific(nViewID, bookmark);
  179. // 1.b) Get the viewsettings.
  180. CViewSettings viewSettingsNodeSpecific;
  181. sc = ScGetViewSettings(viewSettingsIDNodeSpecific, viewSettingsNodeSpecific);
  182. if (sc)
  183. return sc;
  184. // data available
  185. if ( (sc == S_OK) &&
  186. (viewSettingsNodeSpecific.IsTaskpadIDValid()) )
  187. {
  188. // 1.c) Set taskpad id invalid.
  189. viewSettingsNodeSpecific.SetTaskpadIDValid(false);
  190. if (sc)
  191. return sc;
  192. // 1.d) Save the data.
  193. sc = ScSetViewSettings(viewSettingsIDNodeSpecific, viewSettingsNodeSpecific, bSetDirty);
  194. }
  195. // 2. Now save the taskpad id for nodetype specific.
  196. // 2.a) Construct a CViewSettingsID object with given nodetype & viewid.
  197. CViewSettingsID viewSettingsID(nViewID, guidNodeType);
  198. // 2.b) The CResultViewType & view-mode data are not stored when CViewSettings is stored
  199. // per nodetype. So just set the taskpad id.
  200. CViewSettings viewSettings;
  201. sc = viewSettings.ScSetTaskpadID(guidTaskpad);
  202. if (sc)
  203. return sc;
  204. // 2.c) Save the viewsettings into the map.
  205. sc = ScSetViewSettings(viewSettingsID, viewSettings, bSetDirty);
  206. if (sc)
  207. return sc;
  208. return (sc);
  209. }
  210. //+-------------------------------------------------------------------
  211. //
  212. // Member: CViewSettingsPersistor::ScGetTaskpadID
  213. //
  214. // Synopsis: Given the bookmark & viewid get the taskpad id (this
  215. // is for taskpads persisted per node).
  216. //
  217. // Arguments: [nViewID] - [in]
  218. // [bookmark] - [in]
  219. // [guidTaskpad] - [out]
  220. //
  221. // Returns: SC, S_FALSE if none found.
  222. //
  223. //--------------------------------------------------------------------
  224. SC CViewSettingsPersistor::ScGetTaskpadID (int nViewID, const CBookmark& bookmark,GUID& guidTaskpad)
  225. {
  226. DECLARE_SC(sc, _T("CViewSettingsPersistor::ScGetTaskpadID"));
  227. // 1. Init out param.
  228. guidTaskpad = GUID_NULL;
  229. // 2. Construct a CViewSettingsID object with given bookmark & viewid.
  230. CViewSettingsID viewSettingsID(nViewID, bookmark);
  231. // 3. Get the viewsettings
  232. CViewSettings viewSettings;
  233. sc = ScGetViewSettings(viewSettingsID, viewSettings);
  234. // If none exists return
  235. if (sc != S_OK)
  236. return sc;
  237. // 4. CViewSettings exists, see if there is valid taskpad-id stored.
  238. sc = viewSettings.ScGetTaskpadID(guidTaskpad);
  239. if (sc) // taskpad-id is not valid.
  240. return (sc = S_FALSE);
  241. return (sc);
  242. }
  243. //+-------------------------------------------------------------------
  244. //
  245. // Member: CViewSettingsPersistor::ScSetTaskpadID
  246. //
  247. // Synopsis: Given the bookmark & viewid get the taskpad id (this
  248. // is for taskpads persisted per nodetype).
  249. //
  250. // Arguments: [nViewID] - [in]
  251. // [bookmark] - [in]
  252. // [guidTaskpad] - [in]
  253. // [bSetDirty] - [in] set the console file dirty
  254. //
  255. // Returns: SC
  256. //
  257. //--------------------------------------------------------------------
  258. SC CViewSettingsPersistor::ScSetTaskpadID (int nViewID, const CBookmark& bookmark,
  259. const GUID& guidTaskpad, bool bSetDirty)
  260. {
  261. DECLARE_SC(sc, _T("CViewSettingsPersistor::ScSetTaskpadID"));
  262. // 1. Construct a CViewSettingsID object with given bookmark & viewid.
  263. CViewSettingsID viewSettingsID(nViewID, bookmark);
  264. // 2. First get the old settings (if any) and just modify taskpad-id.
  265. CViewSettings viewSettings;
  266. sc = ScGetViewSettings(viewSettingsID, viewSettings);
  267. if (sc)
  268. return sc;
  269. // 3. If persisted data does not exist dont worry (as CResultViewType and
  270. // view mode are invalid), just set taskpad-id.
  271. sc = viewSettings.ScSetTaskpadID(guidTaskpad);
  272. if (sc)
  273. return sc;
  274. // 4. Save the viewsettings into the map.
  275. sc = ScSetViewSettings(viewSettingsID, viewSettings, bSetDirty);
  276. if (sc)
  277. return sc;
  278. return (sc);
  279. }
  280. //+-------------------------------------------------------------------
  281. //
  282. // Member: CViewSettingsPersistor::ScGetViewMode
  283. //
  284. // Synopsis: Given the viewid & bookmark (can identify a node), return
  285. // the view mode if any persisted.
  286. //
  287. // Arguments: [nViewID] - [in]
  288. // [bookmark] - [in]
  289. // [ulViewMode] - [out]
  290. //
  291. // Returns: SC, S_FALSE if none.
  292. //
  293. //--------------------------------------------------------------------
  294. SC CViewSettingsPersistor::ScGetViewMode (int nViewID, const CBookmark& bookmark, ULONG& ulViewMode)
  295. {
  296. DECLARE_SC(sc, _T("CViewSettingsPersistor::ScGetViewMode"));
  297. // 1. Construct the viewsettings-id.
  298. CViewSettingsID viewSettingsID(nViewID, bookmark);
  299. // 2. see if ViewSettings exist.
  300. CViewSettings viewSettings;
  301. sc = ScGetViewSettings(viewSettingsID, viewSettings);
  302. if (sc != S_OK)
  303. return sc;
  304. sc = viewSettings.ScGetViewMode(ulViewMode);
  305. if (sc)
  306. return (sc = S_FALSE);
  307. return (sc);
  308. }
  309. //+-------------------------------------------------------------------
  310. //
  311. // Member: CViewSettingsPersistor::ScSetViewMode
  312. //
  313. // Synopsis: Given view-id & bookmark, set the viewmode in a node
  314. // specific viewsettings.
  315. //
  316. // Arguments: [nViewID] - [in]
  317. // [bookmark] - [in]
  318. // [ulViewMode] - [in]
  319. //
  320. // Returns: SC
  321. //
  322. //--------------------------------------------------------------------
  323. SC CViewSettingsPersistor::ScSetViewMode (int nViewID, const CBookmark& bookmark, ULONG ulViewMode)
  324. {
  325. DECLARE_SC(sc, _T("CViewSettingsPersistor::ScSetViewMode"));
  326. // 1. Construct the viewsettings-id.
  327. CViewSettingsID viewSettingsID(nViewID, bookmark);
  328. // 2. First get the old settings (if any) and just modify viewmode.
  329. CViewSettings viewSettings;
  330. sc = ScGetViewSettings(viewSettingsID, viewSettings);
  331. if (sc)
  332. return sc;
  333. // 3. If persisted data does not exist dont worry (as CResultViewType and
  334. // taskpad-id are invalid), just set viewmode.
  335. sc = viewSettings.ScSetViewMode(ulViewMode);
  336. if (sc)
  337. return sc;
  338. // 4. Save the viewsettings into the map.
  339. sc = ScSetViewSettings(viewSettingsID, viewSettings, /*bSetDirty*/ true);
  340. if (sc)
  341. return sc;
  342. return (sc);
  343. }
  344. //+-------------------------------------------------------------------
  345. //
  346. // Member: CViewSettingsPersistor::ScGetResultViewType
  347. //
  348. // Synopsis: Given the viewid & bookmark (can identify a node), return
  349. // the CResultViewType if persisted.
  350. //
  351. // Arguments: [nViewID] - [in]
  352. // [bookmark] - [in]
  353. // [rvt] - [out]
  354. //
  355. // Returns: SC, S_FALSE if none.
  356. //
  357. //--------------------------------------------------------------------
  358. SC CViewSettingsPersistor::ScGetResultViewType (int nViewID, const CBookmark& bookmark, CResultViewType& rvt)
  359. {
  360. DECLARE_SC(sc, _T("CViewSettingsPersistor::ScGetResultViewType"));
  361. // 1. Construct the viewsettings-id.
  362. CViewSettingsID viewSettingsID(nViewID, bookmark);
  363. // 2. see if ViewSettings exist.
  364. CViewSettings viewSettings;
  365. sc = ScGetViewSettings(viewSettingsID, viewSettings);
  366. if (sc != S_OK)
  367. return sc;
  368. sc = viewSettings.ScGetResultViewType(rvt);
  369. if (sc)
  370. return (sc = S_FALSE);
  371. return (sc);
  372. }
  373. //+-------------------------------------------------------------------
  374. //
  375. // Member: CViewSettingsPersistor::ScSetResultViewType
  376. //
  377. // Synopsis: Given view-id & bookmark, set the resultviewtype in a node
  378. // specific viewsettings.
  379. //
  380. // Arguments: [nViewID] - [in]
  381. // [bookmark] - [in]
  382. // [nViewMode] - [in]
  383. //
  384. // Returns: SC
  385. //
  386. //--------------------------------------------------------------------
  387. SC CViewSettingsPersistor::ScSetResultViewType (int nViewID, const CBookmark& bookmark, const CResultViewType& rvt)
  388. {
  389. DECLARE_SC(sc, _T("CViewSettingsPersistor::ScSetResultViewType"));
  390. // 1. Construct the viewsettings-id.
  391. CViewSettingsID viewSettingsID(nViewID, bookmark);
  392. // 2. First get the old settings (if any) and just modify resultviewtype.
  393. CViewSettings viewSettings;
  394. sc = ScGetViewSettings(viewSettingsID, viewSettings);
  395. if (sc)
  396. return sc;
  397. // 3. If persisted data does not exist dont worry (as view-mode and
  398. // taskpad-id are invalid), just set resultviewtype.
  399. sc = viewSettings.ScSetResultViewType(rvt);
  400. if (sc)
  401. return sc;
  402. // 4. Save the viewsettings into the map.
  403. sc = ScSetViewSettings(viewSettingsID, viewSettings, /*bSetDirty*/ true);
  404. if (sc)
  405. return sc;
  406. return (sc);
  407. }
  408. //+-------------------------------------------------------------------
  409. //
  410. // Member: CViewSettingsPersistor::ScSetFavoriteViewSettings
  411. //
  412. // Synopsis: A favorite is selected and it sets viewsettings
  413. // before re-selecting the node so that after re-selection
  414. // the new settings are set for the view. So dont set the
  415. // console file dirty.
  416. //
  417. // Arguments: [nViewID] -
  418. // [bookmark] -
  419. // [viewSettings] -
  420. //
  421. // Returns: SC
  422. //
  423. //--------------------------------------------------------------------
  424. SC CViewSettingsPersistor::ScSetFavoriteViewSettings (int nViewID, const CBookmark& bookmark,
  425. const CViewSettings& viewSettings)
  426. {
  427. DECLARE_SC(sc, _T("CViewSettingsPersistor::ScSetFavoriteViewSettings"));
  428. // 1. Construct the viewsettings-id.
  429. CViewSettingsID viewSettingsID(nViewID, bookmark);
  430. // 2. Save the viewsettings into the map.
  431. sc = ScSetViewSettings(viewSettingsID, viewSettings, /*bSetDirty*/ false);
  432. if (sc)
  433. return sc;
  434. return (sc);
  435. }
  436. //+-------------------------------------------------------------------
  437. //
  438. // Member: ScDeleteDataOfView
  439. //
  440. // Synopsis: Delete the data of given view.
  441. //
  442. // Arguments: [nViewID] - View ID.
  443. //
  444. // Returns: SC
  445. //
  446. //--------------------------------------------------------------------
  447. SC CViewSettingsPersistor::ScDeleteDataOfView( int nViewID)
  448. {
  449. DECLARE_SC(sc, TEXT("CViewSettingsPersistor::ScDeleteDataOfView"));
  450. // Find the data for the view.
  451. CViewSettingsIDToViewSettingsMap::iterator itViewSettingsDataMap;
  452. for (itViewSettingsDataMap = m_mapViewSettingsIDToViewSettings.begin();
  453. itViewSettingsDataMap != m_mapViewSettingsIDToViewSettings.end();
  454. ++itViewSettingsDataMap)
  455. {
  456. const CViewSettingsID& viewSettingsID = itViewSettingsDataMap->first;
  457. if (viewSettingsID.get_ViewID() == nViewID)
  458. {
  459. // Delete the item;
  460. IteratorToViewSettingsList itViewSettings = itViewSettingsDataMap->second;
  461. itViewSettings->SetObjInvalid(TRUE);
  462. }
  463. }
  464. // Delete the invalid items.
  465. sc = ScDeleteMarkedItems();
  466. if (sc)
  467. return sc;
  468. return sc;
  469. }
  470. //+-------------------------------------------------------------------
  471. //
  472. // Member: ScGarbageCollectItems
  473. //
  474. // Synopsis: Free least used data.
  475. //
  476. // Arguments: None.
  477. //
  478. // History: 04-26-1999 AnandhaG Created
  479. //
  480. //--------------------------------------------------------------------
  481. SC CViewSettingsPersistor::ScGarbageCollectItems()
  482. {
  483. DECLARE_SC(sc, TEXT("CViewSettingsPersistor::ScGarbageCollectItems"));
  484. INT nItemsToBeRemoved = VIEWSETTINGS_MAXLIMIT * m_dwMaxItems;
  485. // Go thro' the list and set the nItemsToBeRemoved that was least recently
  486. // accessed to be invalid.
  487. INT nIndex = 0;
  488. IteratorToViewSettingsList itViewSettings;
  489. // Skip first m_dwMaxItems.
  490. for (itViewSettings = m_listViewSettings.begin();
  491. ( (itViewSettings != m_listViewSettings.end()) && (nIndex <= m_dwMaxItems) );
  492. ++itViewSettings, nIndex++)
  493. {
  494. nIndex++;
  495. }
  496. // Mark rest of the items to be garbage.
  497. while (itViewSettings != m_listViewSettings.end())
  498. {
  499. itViewSettings->SetObjInvalid(TRUE);
  500. ++itViewSettings;
  501. }
  502. // Delete the invalid items.
  503. sc = ScDeleteMarkedItems();
  504. if (sc)
  505. return sc;
  506. return sc;
  507. }
  508. //+-------------------------------------------------------------------
  509. //
  510. // Member: ScDeleteMarkedItems
  511. //
  512. // Synopsis: Delete invalidated items. This involves iterating thro
  513. // the maps to find the invalid items. Then deleting the
  514. // items. If the map becomes empty then delete the map.
  515. //
  516. // History: 04-26-1999 AnandhaG Created
  517. //
  518. //--------------------------------------------------------------------
  519. SC CViewSettingsPersistor::ScDeleteMarkedItems()
  520. {
  521. DECLARE_SC(sc, TEXT("CViewSettingsPersistor::ScDeleteMarkedItems"));
  522. CViewSettingsIDToViewSettingsMap::iterator itViewSettingsDataMap = m_mapViewSettingsIDToViewSettings.begin();
  523. // Iterate through the map to see if there are
  524. // invalidated items.
  525. while (m_mapViewSettingsIDToViewSettings.end() != itViewSettingsDataMap)
  526. {
  527. IteratorToViewSettingsList itViewSettings = itViewSettingsDataMap->second;
  528. if (itViewSettings->IsObjInvalid())
  529. {
  530. // Delete the item ref from the map.
  531. // Erase returns iterator to next item.
  532. itViewSettingsDataMap = m_mapViewSettingsIDToViewSettings.erase(itViewSettingsDataMap);
  533. // Delete the item from the list.
  534. m_listViewSettings.erase(itViewSettings);
  535. }
  536. else
  537. ++itViewSettingsDataMap; // Item is valid so get next item.
  538. }
  539. return sc;
  540. }
  541. //+-------------------------------------------------------------------
  542. //
  543. // Member: Load
  544. //
  545. // Synopsis: Load the persisted view information.
  546. //
  547. // Arguments: [pStream]- IStream from which view data will be loaded.
  548. //
  549. // Returns: S_OK - Loaded successfully.
  550. //
  551. // History: 04-26-1999 AnandhaG Created
  552. //
  553. //--------------------------------------------------------------------
  554. HRESULT CViewSettingsPersistor::Load (IStream* pStream)
  555. {
  556. HRESULT hr = E_FAIL;
  557. // read the column width information.
  558. try
  559. {
  560. do
  561. {
  562. // Read the version. If it did not match return
  563. INT nVersion = 0;
  564. *pStream >> nVersion;
  565. if (ViewSettingPersistenceVersion != nVersion)
  566. return S_FALSE;
  567. // Read the # of Snapins
  568. DWORD dwNumItems = 0;
  569. *pStream >> dwNumItems;
  570. m_listViewSettings.clear();
  571. m_mapViewSettingsIDToViewSettings.clear();
  572. for (int i = 0; i < dwNumItems; i++)
  573. {
  574. // Read the ID.
  575. CViewSettingsID viewSettingsID;
  576. *pStream >> viewSettingsID;
  577. // Read the data.
  578. CViewSettings viewSettings;
  579. viewSettings.Read(*pStream);
  580. // Insert the data into the list.
  581. IteratorToViewSettingsList itViewSettings;
  582. itViewSettings = m_listViewSettings.insert(m_listViewSettings.begin(),
  583. viewSettings);
  584. // Insert the data into the map.
  585. m_mapViewSettingsIDToViewSettings.insert(
  586. CViewSettingsIDToViewSettingsMap::value_type(viewSettingsID, itViewSettings) );
  587. }
  588. m_listViewSettings.sort();
  589. } while (FALSE);
  590. }
  591. catch (_com_error& err)
  592. {
  593. hr = err.Error();
  594. }
  595. catch (...)
  596. {
  597. ASSERT (0 && "Unexpected exception");
  598. throw;
  599. }
  600. return S_OK;
  601. }
  602. //+-------------------------------------------------------------------
  603. //
  604. // Member: Save
  605. //
  606. // Synopsis: Persist the view information.
  607. //
  608. // Arguments: [pStream]- IStream in which data is persisted.
  609. //
  610. // Returns: S_OK - Saved successfully.
  611. //
  612. // History: 04-26-1999 AnandhaG Created
  613. //
  614. //--------------------------------------------------------------------
  615. HRESULT CViewSettingsPersistor::Save (IStream* pStream, BOOL bClearDirty)
  616. {
  617. // absolete method.
  618. // this method is left here since we use IPersistStream to export
  619. // persistence to CONUI side and need to implement it.
  620. // But this interface will never be called to save data
  621. // [we will use CPersistor-based XML saving instead]
  622. // so the method will always fail.
  623. ASSERT(FALSE && "Should never come here");
  624. return E_NOTIMPL;
  625. }
  626. //+-------------------------------------------------------------------
  627. //
  628. // Member: Persist
  629. //
  630. // Synopsis: Persist the view information.
  631. //
  632. // Arguments: [CPersistor]- Persistor in/from which data is persisted.
  633. //
  634. // Returns: void
  635. //
  636. // History: 11-08-1999 AudriusZ Created
  637. //
  638. //--------------------------------------------------------------------
  639. void CViewSettingsPersistor::Persist(CPersistor &persistor)
  640. {
  641. DECLARE_SC(sc, TEXT("CViewSettingsPersistor::Persist"));
  642. if (persistor.IsStoring())
  643. {
  644. // Give ranking to each CViewSettings instance.
  645. IteratorToViewSettingsList itViewSettings;
  646. DWORD dwRank = 0;
  647. for (itViewSettings = m_listViewSettings.begin();
  648. itViewSettings != m_listViewSettings.end();
  649. ++itViewSettings)
  650. {
  651. dwRank++;
  652. itViewSettings->SetUsageRank(dwRank);
  653. }
  654. CViewSettingsIDToViewSettingsMap::iterator itViewSettingsDataMap;
  655. for (itViewSettingsDataMap = m_mapViewSettingsIDToViewSettings.begin();
  656. itViewSettingsDataMap != m_mapViewSettingsIDToViewSettings.end();
  657. ++itViewSettingsDataMap)
  658. {
  659. // Write the ID.
  660. persistor.Persist(*const_cast<CViewSettingsID *>(&itViewSettingsDataMap->first));
  661. // Write the data.
  662. persistor.Persist(*itViewSettingsDataMap->second);
  663. }
  664. }
  665. else
  666. {
  667. // let the base class do the job
  668. // it will call OnNewElement for every element found
  669. XMLMapCollectionBase::Persist(persistor);
  670. // some extra loading actions
  671. m_listViewSettings.sort();
  672. }
  673. // either way we are the same as the file copy
  674. m_bDirty = false;
  675. }
  676. //+-------------------------------------------------------------------
  677. //
  678. // Member: OnNewElement
  679. //
  680. // Synopsis: Called for each new data pair read.
  681. //
  682. // Arguments: [persistKey]- Persistor from which key is to be loaded
  683. // [persistVal]- Persistor from which value is to be loaded
  684. //
  685. // Returns: void
  686. //
  687. // History: 11-08-1999 AudriusZ Created
  688. //
  689. //--------------------------------------------------------------------
  690. void CViewSettingsPersistor::OnNewElement(CPersistor& persistKey,CPersistor& persistVal)
  691. {
  692. DECLARE_SC(sc, TEXT("CViewSettingsPersistor::OnNewElement"));
  693. // Read the ID.
  694. CViewSettingsID viewSettingsID;
  695. persistKey.Persist(viewSettingsID);
  696. // Read the data.
  697. CViewSettings viewSettings;
  698. persistVal.Persist(viewSettings);
  699. // Insert the data into the list.
  700. IteratorToViewSettingsList itViewSettings;
  701. itViewSettings = m_listViewSettings.insert(m_listViewSettings.begin(),
  702. viewSettings);
  703. // Insert the data into the map.
  704. m_mapViewSettingsIDToViewSettings.insert(
  705. CViewSettingsIDToViewSettingsMap::value_type(viewSettingsID, itViewSettings) );
  706. }