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.

1965 lines
60 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1999
  5. //
  6. // File: colwidth.cpp
  7. //
  8. // Contents: Column Persistence data structures and property pages
  9. // implementation.
  10. //
  11. // History: 16-Oct-98 AnandhaG Created
  12. //
  13. //--------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "colwidth.h"
  16. #include "macros.h"
  17. #include "comdbg.h"
  18. #include "columninfo.h"
  19. #define MAX_COLUMNS_PERSISTED 50
  20. //+-------------------------------------------------------------------
  21. //
  22. // Class: ViewToColSetDataMapPersistor (wrapper, helper)
  23. //
  24. // Purpose: wraps ViewToColSetDataMap implementing XML persistence
  25. // map is persisted as linear list
  26. //
  27. // see "Data structures used to persist column information" comment
  28. // int file colwidth.h for more information
  29. //--------------------------------------------------------------------
  30. class ViewToColSetDataMapPersistor : public XMLListCollectionBase
  31. {
  32. public:
  33. ViewToColSetDataMapPersistor(ViewToColSetDataMap &map, ColSetDataList &list)
  34. : m_map(map), m_list(list) {}
  35. DEFINE_XML_TYPE(XML_TAG_COLUMN_SET);
  36. virtual void Persist(CPersistor &persistor);
  37. virtual void OnNewElement(CPersistor& persistor);
  38. private:
  39. ViewToColSetDataMap &m_map; // wrapped map
  40. ColSetDataList &m_list; // value list to persist actual information
  41. };
  42. //+-------------------------------------------------------------------
  43. //
  44. // Class: ColSetIDToViewTableMapPersistor (wrapper, helper)
  45. //
  46. // Purpose: wraps ColSetIDToViewTableMap implementing XML persistence
  47. // map is persisted as linear list
  48. //
  49. // see "Data structures used to persist column information" comment
  50. // int file colwidth.h for more information
  51. //--------------------------------------------------------------------
  52. class ColSetIDToViewTableMapPersistor : public XMLListCollectionBase
  53. {
  54. public:
  55. ColSetIDToViewTableMapPersistor(ColSetIDToViewTableMap &map, ColSetDataList &list)
  56. : m_map(map), m_list(list) {}
  57. DEFINE_XML_TYPE(XML_TAG_COLUMN_PERIST_ENTRY);
  58. virtual void Persist(CPersistor &persistor);
  59. virtual void OnNewElement(CPersistor& persistor);
  60. private:
  61. ColSetIDToViewTableMap &m_map; // wrapped map
  62. ColSetDataList &m_list; // value list to persist actual information
  63. };
  64. //+-------------------------------------------------------------------
  65. //
  66. // Class: SnapinToColSetIDMapPersistor (wrapper, helper)
  67. //
  68. // Purpose: wraps SnapinToColSetIDMap implementing XML persistence
  69. // map is persisted as linear list
  70. //
  71. // see "Data structures used to persist column information" comment
  72. // int file colwidth.h for more information
  73. //--------------------------------------------------------------------
  74. class SnapinToColSetIDMapPersistor : public XMLListCollectionBase
  75. {
  76. public:
  77. SnapinToColSetIDMapPersistor(SnapinToColSetIDMap &map, ColSetDataList &list)
  78. : m_map(map), m_list(list) {}
  79. DEFINE_XML_TYPE(XML_TAG_COLUMN_PERIST_ENTRY);
  80. virtual void Persist(CPersistor &persistor);
  81. virtual void OnNewElement(CPersistor& persistor);
  82. // prior-to-save cleanup
  83. SC ScPurgeUnusedColumnData();
  84. private:
  85. SnapinToColSetIDMap &m_map; // wrapped map
  86. ColSetDataList &m_list; // value list to persist actual information
  87. };
  88. //+-------------------------------------------------------------------
  89. //
  90. // Member: ReadSerialObject
  91. //
  92. // Synopsis: Read the given version of CColumnSortInfo object from
  93. // the given stream.
  94. //
  95. // Arguments: [stm] - The input stream.
  96. // [nVersion] - version of CColumnSortInfo to be read.
  97. //
  98. // The format is :
  99. // INT column index
  100. // DWORD Sort options
  101. // ULONG_PTR Any user (snapin) param
  102. //
  103. //--------------------------------------------------------------------
  104. HRESULT CColumnSortInfo::ReadSerialObject(IStream &stm, UINT nVersion /*,LARGE_INTEGER nBytes*/)
  105. {
  106. HRESULT hr = S_FALSE; // assume bad version
  107. if (GetVersion() >= nVersion)
  108. {
  109. try
  110. {
  111. stm >> m_nCol;
  112. // In version we stored just ascending or descending flag
  113. if (1 == nVersion)
  114. {
  115. BYTE bAscend;
  116. stm >> bAscend;
  117. m_dwSortOptions |= (bAscend ? 0 : RSI_DESCENDING);
  118. }
  119. else if (nVersion > 1)
  120. {
  121. // Versions greater than 1 has these sort data which
  122. // includes ascend/descend flags and a user param.
  123. stm >> m_dwSortOptions;
  124. stm >> m_lpUserParam;
  125. }
  126. hr = S_OK;
  127. }
  128. catch (_com_error& err)
  129. {
  130. hr = err.Error();
  131. ASSERT (false && "Caught _com_error");
  132. }
  133. }
  134. return (hr);
  135. }
  136. //+-------------------------------------------------------------------
  137. //
  138. // Member: CColumnSortInfo::Persist
  139. //
  140. // Synopsis: Persists object data
  141. //
  142. // Arguments:
  143. //
  144. // History: 10-10-1999 AudriusZ Created
  145. //
  146. //--------------------------------------------------------------------
  147. void CColumnSortInfo::Persist(CPersistor &persistor)
  148. {
  149. persistor.PersistAttribute(XML_ATTR_COLUMN_SORT_INFO_COLMN, m_nCol) ;
  150. static const EnumLiteral sortOptions[] =
  151. {
  152. { RSI_DESCENDING, XML_BITFLAG_COL_SORT_DESCENDING },
  153. { RSI_NOSORTICON, XML_BITFLAG_COL_SORT_NOSORTICON },
  154. };
  155. CXMLBitFlags optionPersistor(m_dwSortOptions, sortOptions, countof(sortOptions));
  156. persistor.PersistAttribute(XML_ATTR_COLUMN_SORT_INFO_OPTNS, optionPersistor) ;
  157. }
  158. //+-------------------------------------------------------------------
  159. //
  160. // Member: ReadSerialObject
  161. //
  162. // Synopsis: Reads CColumnSortList data from stream.
  163. //
  164. // Format: number of columns : each CColumnSortInfo entry.
  165. //
  166. // Arguments: [stm] - The input stream.
  167. // [nVersion] - Version of CColumnSortList to be read.
  168. //
  169. //
  170. //--------------------------------------------------------------------
  171. HRESULT CColumnSortList::ReadSerialObject (IStream &stm, UINT nVersion /*,LARGE_INTEGER nBytes*/)
  172. {
  173. HRESULT hr = S_FALSE; // assume bad version
  174. if (GetVersion() == nVersion)
  175. {
  176. try
  177. {
  178. // Number of columns.
  179. DWORD dwCols;
  180. stm >> dwCols;
  181. clear();
  182. for (int i = 0; i < dwCols; i++)
  183. {
  184. CColumnSortInfo colSortEntry;
  185. // Read data into colSortEntry structure.
  186. if (colSortEntry.Read(stm) != S_OK)
  187. continue;
  188. push_back(colSortEntry);
  189. }
  190. hr = S_OK;
  191. }
  192. catch (_com_error& err)
  193. {
  194. hr = err.Error();
  195. ASSERT (false && "Caught _com_error");
  196. }
  197. }
  198. return (hr);
  199. }
  200. /***************************************************************************\
  201. *
  202. * METHOD: CColumnSortList::Persist
  203. *
  204. * PURPOSE: persists object to XML
  205. *
  206. * PARAMETERS:
  207. * CPersistor& persistor [in/out] persistor to persist under
  208. *
  209. * RETURNS:
  210. * void
  211. *
  212. \***************************************************************************/
  213. void CColumnSortList::PersistSortList(CPersistor& persistor)
  214. {
  215. DECLARE_SC(sc, TEXT("CColumnSortList::PersistSortList"));
  216. if (persistor.IsLoading())
  217. {
  218. clear();
  219. CColumnSortInfo sortInfo;
  220. if (persistor.HasElement(sortInfo.GetXMLType(), NULL))
  221. {
  222. persistor.Persist(sortInfo);
  223. insert(end(), sortInfo);
  224. }
  225. }
  226. else
  227. {
  228. if (size() > 1)
  229. sc.Throw(E_UNEXPECTED);
  230. else if (size())
  231. persistor.Persist(*begin());
  232. }
  233. }
  234. //+-------------------------------------------------------------------
  235. //
  236. // Member: ReadSerialObject
  237. //
  238. // Synopsis: Read CColumnSetData data from the stream.
  239. //
  240. // Arguments: [stm] - The input stream.
  241. // [nVersion] - Version of CColumnSetData structure.
  242. //
  243. // Format : CColumnInfoList : CColumnSortList
  244. //
  245. //
  246. //--------------------------------------------------------------------
  247. HRESULT CColumnSetData::ReadSerialObject (IStream &stm, UINT nVersion /*,LARGE_INTEGER nBytes*/)
  248. {
  249. HRESULT hr = S_FALSE; // assume bad version
  250. if (GetVersion() == nVersion)
  251. {
  252. try
  253. {
  254. do // not a loop
  255. {
  256. // Read the rank
  257. stm >> m_dwRank;
  258. // Read the CColumnInfoList
  259. hr = get_ColumnInfoList()->Read(stm);
  260. if (hr != S_OK)
  261. break;
  262. // Read the CColumnSortList
  263. hr = get_ColumnSortList()->Read(stm);
  264. if (hr != S_OK)
  265. break;
  266. ASSERT (hr == S_OK);
  267. } while (false);
  268. }
  269. catch (_com_error& err)
  270. {
  271. hr = err.Error();
  272. ASSERT (false && "Caught _com_error");
  273. }
  274. }
  275. return (hr);
  276. }
  277. //+-------------------------------------------------------------------
  278. //
  279. // Member: CColumnSetData::Persist
  280. //
  281. // Synopsis: Persists object data
  282. //
  283. // Arguments:
  284. //
  285. // History: 10-10-1999 AudriusZ Created
  286. //
  287. //--------------------------------------------------------------------
  288. void CColumnSetData::Persist(CPersistor &persistor)
  289. {
  290. DECLARE_SC(sc, TEXT("CColumnSetData::Persist"));
  291. sc = ScCheckPointers(get_ColumnInfoList(), get_ColumnSortList());
  292. if (sc)
  293. sc.Throw();
  294. persistor.PersistAttribute(XML_ATTR_COLUMN_SET_RANK, m_dwRank);
  295. // Write CColumnInfoList
  296. persistor.Persist(*get_ColumnInfoList());
  297. // Write CColumnSortList
  298. get_ColumnSortList()->PersistSortList(persistor);
  299. }
  300. //------------------------------------------------------------------
  301. // class CColumnPersistInfo
  302. //------------------------------------------------------------------
  303. CColumnPersistInfo::CColumnPersistInfo() :
  304. m_bInitialized(FALSE), m_dwMaxItems(MAX_COLUMNS_PERSISTED),
  305. m_bDirty(FALSE)
  306. {
  307. }
  308. CColumnPersistInfo::~CColumnPersistInfo()
  309. {
  310. }
  311. //+-------------------------------------------------------------------
  312. //
  313. // Member: RetrieveColumnData
  314. //
  315. // Synopsis: Copy and return the persisted column information
  316. // for given column id and view id.
  317. //
  318. // Arguments: [refSnapinCLSID] - Snapin Guid
  319. // [SColumnSetID] - Column Set Identifier.
  320. // [nViewID] - View ID.
  321. // [columnSetData] - CColumnSetData, used to return the
  322. // persisted column information.
  323. //
  324. // Returns: TRUE - Loaded successfully.
  325. //
  326. // History: 10-16-1998 AnandhaG Created
  327. //
  328. //--------------------------------------------------------------------
  329. BOOL CColumnPersistInfo::RetrieveColumnData( const CLSID& refSnapinCLSID,
  330. const SColumnSetID& colID,
  331. INT nViewID,
  332. CColumnSetData& columnSetData)
  333. {
  334. BOOL bFound = FALSE;
  335. // Make sure we are initialized.
  336. if (!m_bInitialized && !Init())
  337. {
  338. ASSERT(FALSE);
  339. return bFound;
  340. }
  341. // Construct CColumnSetID.
  342. CColumnSetID colSetID(colID);
  343. // Use the snapin clsid to get the ColSetIDToViewTableMap.
  344. SnapinToColSetIDMap::iterator itSnapins;
  345. itSnapins = m_spSnapinsMap->find(refSnapinCLSID);
  346. if (itSnapins == m_spSnapinsMap->end())
  347. return bFound;
  348. // The ColSetIDToViewTableMap is a simple map.
  349. ColSetIDToViewTableMap::iterator itColSetIDMap;
  350. ColSetIDToViewTableMap& colSetIDMap = itSnapins->second;
  351. // Get the data for colSetID.
  352. itColSetIDMap = colSetIDMap.find(colSetID);
  353. if (colSetIDMap.end() == itColSetIDMap)
  354. return bFound;
  355. ViewToColSetDataMap& viewData = itColSetIDMap->second;
  356. ViewToColSetDataMap::iterator itViews;
  357. // See if our view is present.
  358. itViews = viewData.find(nViewID);
  359. if (viewData.end() != itViews)
  360. {
  361. // Found the item.
  362. bFound = TRUE;
  363. ItColSetDataList itColSetData = itViews->second;
  364. // Copy the data.
  365. columnSetData = *itColSetData;
  366. // So move this item to the top of the queue.
  367. m_spColSetList->erase(itColSetData);
  368. itColSetData = m_spColSetList->insert(m_spColSetList->begin(), columnSetData);
  369. itViews->second = itColSetData;
  370. }
  371. return bFound;
  372. }
  373. //+-------------------------------------------------------------------
  374. //
  375. // Member: SaveColumnData
  376. //
  377. // Synopsis: Save/Modify the column information for persistence into
  378. // CColumnPersistInfo.
  379. //
  380. // Arguments:
  381. // [refSnapinCLSID] - Snapin Guid.
  382. // [SColumnSetID] - Column Set Identifier.
  383. // [nViewID] - View ID.
  384. // [columnSetData] - CColumnSetData, Column data.
  385. //
  386. // Returns: TRUE - Saved successfully.
  387. //
  388. // History: 10-16-1998 AnandhaG Created
  389. //
  390. //--------------------------------------------------------------------
  391. BOOL CColumnPersistInfo::SaveColumnData( const CLSID& refSnapinCLSID,
  392. const SColumnSetID& colID,
  393. INT nViewID,
  394. CColumnSetData& columnSetData)
  395. {
  396. // Make sure we are init
  397. if (!m_bInitialized && !Init())
  398. {
  399. ASSERT(FALSE);
  400. return FALSE;
  401. }
  402. // Construct the CColumnSetID.
  403. CColumnSetID colSetID(colID);
  404. // Garbage collect if the number of items in the list is 40% more then pre-set limit.
  405. if (m_spColSetList->size() >= (m_dwMaxItems * (1 + COLUMNS_MAXLIMIT)) )
  406. GarbageCollectItems();
  407. // Insert this item to the top of the queue.
  408. ItColSetDataList itColData;
  409. itColData = m_spColSetList->insert(m_spColSetList->begin(), columnSetData);
  410. SnapinToColSetIDMap::iterator itSnapins;
  411. itSnapins = m_spSnapinsMap->find(refSnapinCLSID);
  412. if (itSnapins != m_spSnapinsMap->end())
  413. {
  414. // Snapin is already in the map.
  415. // Look if the col-id is already inserted.
  416. ColSetIDToViewTableMap::iterator itColSetIDMap;
  417. ColSetIDToViewTableMap& colSetIDMap = itSnapins->second;
  418. // Get the data for the colSetID.
  419. itColSetIDMap = colSetIDMap.find(colSetID);
  420. if (colSetIDMap.end() == itColSetIDMap)
  421. {
  422. // The column-id not found.
  423. // So insert new one.
  424. // Construct the view-id to column-data map
  425. ViewToColSetDataMap viewIDMap;
  426. viewIDMap.insert( ViewToColSetDataVal(nViewID, itColData) );
  427. colSetIDMap.insert(ColSetIDToViewTableVal(colSetID, viewIDMap) );
  428. }
  429. else
  430. {
  431. // The data for Col-ID exists.
  432. // find if the given view exists in the map.
  433. ViewToColSetDataMap::iterator itViewIDMap;
  434. ViewToColSetDataMap& viewIDMap = itColSetIDMap->second;
  435. itViewIDMap = viewIDMap.find(nViewID);
  436. if (viewIDMap.end() != itViewIDMap)
  437. {
  438. // The map from ViewID to column list exists.
  439. // So delete the old data and insert new data
  440. // at the top of the queue.
  441. m_spColSetList->erase(itViewIDMap->second);
  442. itViewIDMap->second = itColData;
  443. }
  444. else
  445. {
  446. // This view is not found.
  447. // So insert new one.
  448. viewIDMap.insert( ViewToColSetDataVal(nViewID, itColData) );
  449. }
  450. }
  451. }
  452. else
  453. {
  454. // Insert the snapin into the map.
  455. // Construct the ViewID to column-data map.
  456. ViewToColSetDataMap viewIDMap;
  457. viewIDMap.insert( ViewToColSetDataVal(nViewID, itColData) );
  458. // Insert the above into the col-id map.
  459. ColSetIDToViewTableMap colIDMap;
  460. colIDMap.insert( ColSetIDToViewTableVal(colSetID, viewIDMap) );
  461. // Insert into the snapins map.
  462. m_spSnapinsMap->insert( SnapinToColSetIDVal(refSnapinCLSID, colIDMap) );
  463. }
  464. // Set dirty after modifying the column-data.
  465. m_bDirty = TRUE;
  466. return TRUE;
  467. }
  468. //+-------------------------------------------------------------------
  469. //
  470. // Member: DeleteColumnData
  471. //
  472. // Synopsis: Delete the persisted column information for the given
  473. // snapin, col-id and view id.
  474. //
  475. // Arguments:
  476. // [refSnapinCLSID] - Snapin Guid.
  477. // [SColumnSetID] - Column Set Identifier.
  478. // [nViewID] - View ID.
  479. //
  480. // Returns: None.
  481. //
  482. // History: 02-13-1999 AnandhaG Created
  483. //
  484. //--------------------------------------------------------------------
  485. VOID CColumnPersistInfo::DeleteColumnData( const CLSID& refSnapinCLSID,
  486. const SColumnSetID& colID,
  487. INT nViewID)
  488. {
  489. // Make sure we are initialized.
  490. if (!m_bInitialized && !Init())
  491. {
  492. ASSERT(FALSE);
  493. return;
  494. }
  495. // Construct CColumnSetID.
  496. CColumnSetID colSetID(colID);
  497. // Use the snapin clsid to get the ColSetIDToViewTableMap.
  498. SnapinToColSetIDMap::iterator itSnapins;
  499. itSnapins = m_spSnapinsMap->find(refSnapinCLSID);
  500. if (itSnapins == m_spSnapinsMap->end())
  501. return;
  502. // The ColSetIDToViewTableMap is a simple map.
  503. ColSetIDToViewTableMap::iterator itColSetIDMap;
  504. ColSetIDToViewTableMap& colSetIDMap = itSnapins->second;
  505. // Get the data for colSetID.
  506. itColSetIDMap = colSetIDMap.find(colSetID);
  507. if (colSetIDMap.end() == itColSetIDMap)
  508. return;
  509. ViewToColSetDataMap& viewData = itColSetIDMap->second;
  510. ViewToColSetDataMap::iterator itViews;
  511. // See if our view is present.
  512. itViews = viewData.find(nViewID);
  513. if (viewData.end() == itViews)
  514. return;
  515. ItColSetDataList itColSetData = itViews->second;
  516. itColSetData->m_bInvalid = TRUE;
  517. // Delete the invalid items.
  518. DeleteMarkedItems();
  519. return;
  520. }
  521. //+-------------------------------------------------------------------
  522. //
  523. // Member: DeleteColumnDataOfSnapin
  524. //
  525. // Synopsis: Delete the column data of given snapin.
  526. //
  527. // Arguments: [refSnapinCLSID] - Snapin Guid.
  528. //
  529. // Returns: TRUE - Data removed successfully.
  530. //
  531. // History: 02-11-1999 AnandhaG Created
  532. //
  533. //--------------------------------------------------------------------
  534. BOOL CColumnPersistInfo::DeleteColumnDataOfSnapin( const CLSID& refSnapinCLSID)
  535. {
  536. // Make sure we are init
  537. if (!m_bInitialized)
  538. {
  539. return FALSE;
  540. }
  541. SnapinToColSetIDMap::iterator itSnapinsMap;
  542. itSnapinsMap = m_spSnapinsMap->find(refSnapinCLSID);
  543. // Find the given snapin.
  544. // Iterate thro all the col-ids of this snapin and
  545. // all the views of those col-id and set the data
  546. // to be invalid.
  547. if (m_spSnapinsMap->end() != itSnapinsMap)
  548. {
  549. ColSetIDToViewTableMap& colSets = itSnapinsMap->second;
  550. // Iterate thro' all colset ids of this snapin.
  551. ColSetIDToViewTableMap::iterator itColumnSetIDMap;
  552. for (itColumnSetIDMap = colSets.begin();
  553. itColumnSetIDMap != colSets.end();
  554. ++itColumnSetIDMap)
  555. {
  556. // Get the view map
  557. ViewToColSetDataMap& viewIDMap = itColumnSetIDMap->second;
  558. ViewToColSetDataMap::iterator itViewIDMap;
  559. // Iterate thro' all views and set the data invalid.
  560. for (itViewIDMap = viewIDMap.begin();
  561. itViewIDMap != viewIDMap.end();
  562. ++itViewIDMap)
  563. {
  564. ItColSetDataList itColSetData = itViewIDMap->second;
  565. itColSetData->m_bInvalid = TRUE;
  566. }
  567. }
  568. }
  569. // Delete the invalid items.
  570. DeleteMarkedItems();
  571. return TRUE;
  572. }
  573. //+-------------------------------------------------------------------
  574. //
  575. // Member: DeleteColumnDataOfView
  576. //
  577. // Synopsis: Delete the column data of given view.
  578. //
  579. // Arguments: [nViewID] - View ID.
  580. //
  581. // Returns: TRUE - Data removed successfully.
  582. //
  583. // History: 02-11-1999 AnandhaG Created
  584. //
  585. //--------------------------------------------------------------------
  586. BOOL CColumnPersistInfo::DeleteColumnDataOfView( int nViewID)
  587. {
  588. // Make sure we are init
  589. if (!m_bInitialized)
  590. {
  591. return FALSE;
  592. }
  593. // Iterate thro all snapins, col-ids and find the matching
  594. // view and set data to be invalid.
  595. SnapinToColSetIDMap::iterator itSnapinsMap;
  596. // Iterate thro all snapins.
  597. for (itSnapinsMap = m_spSnapinsMap->begin();
  598. m_spSnapinsMap->end() != itSnapinsMap;
  599. ++itSnapinsMap)
  600. {
  601. ColSetIDToViewTableMap& colSets = itSnapinsMap->second;
  602. ColSetIDToViewTableMap::iterator itColumnSetIDMap;
  603. // Iterate thro' all colset ids of this snapin.
  604. for (itColumnSetIDMap = colSets.begin();
  605. itColumnSetIDMap != colSets.end();
  606. ++itColumnSetIDMap)
  607. {
  608. // Get the view map
  609. ViewToColSetDataMap& viewIDMap = itColumnSetIDMap->second;
  610. ViewToColSetDataMap::iterator itViewIDMap;
  611. // Find the matching views and mark them to be deleted.
  612. for (itViewIDMap = viewIDMap.begin();
  613. itViewIDMap != viewIDMap.end();
  614. ++itViewIDMap)
  615. {
  616. if (nViewID == itViewIDMap->first)
  617. {
  618. ItColSetDataList itColSetData = itViewIDMap->second;
  619. itColSetData->m_bInvalid = TRUE;
  620. }
  621. }
  622. }
  623. }
  624. // Delete the invalid items.
  625. DeleteMarkedItems();
  626. return TRUE;
  627. }
  628. //+-------------------------------------------------------------------
  629. //
  630. // Member: Init
  631. //
  632. // Synopsis: Create the Map and the list for CColumnSetData.
  633. //
  634. // Returns: TRUE - for success.
  635. //
  636. // History: 10-16-1998 AnandhaG Created
  637. //
  638. //--------------------------------------------------------------------
  639. BOOL CColumnPersistInfo::Init()
  640. {
  641. // Create the data structures to store column data.
  642. m_spSnapinsMap = auto_ptr<SnapinToColSetIDMap>(new SnapinToColSetIDMap);
  643. m_spColSetList = auto_ptr<ColSetDataList> (new ColSetDataList);
  644. // Now the objects are created, so now set initialized to true.
  645. m_bInitialized = TRUE;
  646. // Now read the registry to see if m_dwMaxItems is specified.
  647. // Check if the settings key exists.
  648. CRegKeyEx rSettingsKey;
  649. if (rSettingsKey.ScOpen (HKEY_LOCAL_MACHINE, SETTINGS_KEY, KEY_READ).IsError())
  650. return m_bInitialized;
  651. // Read the values for MaxColDataPersisted.
  652. if (rSettingsKey.IsValuePresent(g_szMaxColumnDataPersisted))
  653. {
  654. DWORD dwType = REG_DWORD;
  655. DWORD dwSize = sizeof(DWORD);
  656. SC sc = rSettingsKey.ScQueryValue (g_szMaxColumnDataPersisted, &dwType,
  657. &m_dwMaxItems, &dwSize);
  658. if (sc)
  659. sc.TraceAndClear();
  660. }
  661. return m_bInitialized;
  662. }
  663. //+-------------------------------------------------------------------
  664. //
  665. // Member: GarbageCollectItems
  666. //
  667. // Synopsis: Free least used column data.
  668. //
  669. // Arguments: None.
  670. //
  671. // History: 02-11-1999 AnandhaG Created
  672. //
  673. //--------------------------------------------------------------------
  674. VOID CColumnPersistInfo::GarbageCollectItems()
  675. {
  676. INT nItemsToBeRemoved = COLUMNS_MAXLIMIT * m_dwMaxItems;
  677. // Go thro' the list and set the nItemsToBeRemoved that was least recently
  678. // accessed to be invalid.
  679. INT nIndex = 0;
  680. ItColSetDataList itColList;
  681. // Skip first m_dwMaxItems.
  682. for (itColList = m_spColSetList->begin();
  683. ( (itColList != m_spColSetList->end()) && (nIndex <= m_dwMaxItems) );
  684. ++itColList, nIndex++)
  685. {
  686. nIndex++;
  687. }
  688. // Mark rest of the items to be garbage.
  689. while (itColList != m_spColSetList->end())
  690. {
  691. itColList->m_bInvalid = TRUE;
  692. ++itColList;
  693. }
  694. // Delete the invalid items.
  695. DeleteMarkedItems();
  696. return;
  697. }
  698. //+-------------------------------------------------------------------
  699. //
  700. // Member: DeleteMarkedItems
  701. //
  702. // Synopsis: Delete invalidated items. This involves iterating thro
  703. // the maps to find the invalid items. Then deleting the
  704. // items. If the map becomes empty then delete the map.
  705. //
  706. // History: 02-11-1999 AnandhaG Created
  707. //
  708. //--------------------------------------------------------------------
  709. VOID CColumnPersistInfo::DeleteMarkedItems()
  710. {
  711. SnapinToColSetIDMap::iterator itSnapinsMap, itSnapinsMapNew;
  712. // Now iterate thro the map and remove those elements.
  713. itSnapinsMap = m_spSnapinsMap->begin();
  714. while (itSnapinsMap != m_spSnapinsMap->end())
  715. {
  716. ColSetIDToViewTableMap& colSets = itSnapinsMap->second;
  717. ColSetIDToViewTableMap::iterator itColumnSetIDMap;
  718. // Iterate thro this snapins col-ids.
  719. itColumnSetIDMap = colSets.begin();
  720. while (itColumnSetIDMap != colSets.end())
  721. {
  722. // Get the view map
  723. ViewToColSetDataMap& viewIDMap = itColumnSetIDMap->second;
  724. ViewToColSetDataMap::iterator itViewIDMap;
  725. // Iterate thro all the views.
  726. itViewIDMap = viewIDMap.begin();
  727. while (itViewIDMap != viewIDMap.end())
  728. {
  729. ItColSetDataList itColSetData = itViewIDMap->second;
  730. if (itColSetData->m_bInvalid)
  731. {
  732. // Delete the item ref from the map.
  733. // Erase returns iterator to next item.
  734. itViewIDMap = viewIDMap.erase(itViewIDMap);
  735. // Delete the item from the list.
  736. m_spColSetList->erase(itColSetData);
  737. }
  738. else
  739. // Item is valid item.
  740. ++itViewIDMap;
  741. }
  742. // If the view has zero items we need to remove this
  743. // view map. (ColID to ViewMap).
  744. if (0 == viewIDMap.size())
  745. {
  746. // Delete the col-id map.
  747. // Erase returns iterator to next item.
  748. itColumnSetIDMap = colSets.erase(itColumnSetIDMap);
  749. }
  750. else
  751. ++itColumnSetIDMap;
  752. }
  753. // If there are no col-id's remove the
  754. // Snapin to this col-id map.
  755. if (0 == colSets.size())
  756. {
  757. // Delete this snapin map.
  758. // Erase returns iterator to next item.
  759. itSnapinsMap = m_spSnapinsMap->erase(itSnapinsMap);
  760. }
  761. else
  762. ++itSnapinsMap;
  763. }
  764. return;
  765. }
  766. //+-------------------------------------------------------------------
  767. //
  768. // Member: Load
  769. //
  770. // Synopsis: Load the persisted column information.
  771. //
  772. // Arguments: [pStream]- ISteam from which column widths to be loaded.
  773. //
  774. // Returns: S_OK - Loaded successfully.
  775. //
  776. // History: 10-16-1998 AnandhaG Created
  777. //
  778. //--------------------------------------------------------------------
  779. STDMETHODIMP CColumnPersistInfo::Load (IStream* pStream)
  780. {
  781. HRESULT hr = E_FAIL;
  782. if (!m_bInitialized && !Init())
  783. {
  784. ASSERT(FALSE);
  785. return hr;
  786. }
  787. // read the column width information.
  788. try
  789. {
  790. do
  791. {
  792. // Read the version. If it did not match return
  793. INT nVersion = 0;
  794. *pStream >> nVersion;
  795. if (COLPersistenceVersion != nVersion)
  796. return S_FALSE;
  797. // Read the # of Snapins
  798. DWORD dwSnapins = 0;
  799. *pStream >> dwSnapins;
  800. m_spColSetList->clear();
  801. m_spSnapinsMap->clear();
  802. // For each snapin...
  803. for (int nSnapIdx = 0; nSnapIdx < dwSnapins; nSnapIdx++)
  804. {
  805. // Read snapin CLSID.
  806. CLSID clsidSnapin;
  807. *pStream >> clsidSnapin;
  808. // Read the number of col-ids for this snapin.
  809. DWORD dwColIDs = 0;
  810. *pStream >> dwColIDs;
  811. ColSetIDToViewTableMap colSetsMap;
  812. // For each col-id...
  813. for (int nColIDIdx = 0; nColIDIdx < dwColIDs; nColIDIdx++)
  814. {
  815. // Read the col-id
  816. CColumnSetID colSetID;
  817. *pStream >> colSetID;
  818. // Read the number of views.
  819. DWORD dwNumViews = 0;
  820. *pStream >> dwNumViews;
  821. ViewToColSetDataMap ViewIDMap;
  822. // For each view...
  823. for (int nViewIdx = 0; nViewIdx < dwNumViews; nViewIdx++)
  824. {
  825. // Read view id.
  826. DWORD dwViewID;
  827. *pStream >> dwViewID;
  828. // Read the CColumnSetData.
  829. CColumnSetData ColData;
  830. ColData.Read(*pStream);
  831. // Insert the data into the global linked list.
  832. ItColSetDataList itColSetData;
  833. itColSetData = m_spColSetList->insert(m_spColSetList->begin(), ColData);
  834. // Insert the pointer to the data in to view map.
  835. ViewIDMap.insert(ViewToColSetDataVal(dwViewID, itColSetData));
  836. }
  837. // Insert the view map into the col-id map.
  838. colSetsMap.insert(ColSetIDToViewTableVal(colSetID, ViewIDMap));
  839. }
  840. // Insert the col-id map into the snapin map.
  841. m_spSnapinsMap->insert(SnapinToColSetIDVal(clsidSnapin, colSetsMap));
  842. }
  843. // Now sort the list.
  844. m_spColSetList->sort();
  845. } while (FALSE);
  846. }
  847. catch (_com_error& err)
  848. {
  849. hr = err.Error();
  850. }
  851. catch (...)
  852. {
  853. ASSERT (0 && "Unexpected exception");
  854. throw;
  855. }
  856. return S_OK;
  857. }
  858. //+-------------------------------------------------------------------
  859. //
  860. // Member: Save
  861. //
  862. // Synopsis: Persist the column information.
  863. //
  864. // Arguments: [pStream]- IStream in which column widths are to be saved.
  865. //
  866. // Returns: S_OK - Saved successfully.
  867. //
  868. // History: 10-16-1998 AnandhaG Created
  869. //
  870. //--------------------------------------------------------------------
  871. STDMETHODIMP CColumnPersistInfo::Save (IStream* pStream, BOOL bClearDirty)
  872. {
  873. // absolete method.
  874. // this method is left here since we use IPersistStream to export
  875. // persistence to CONUI side and need to implement it.
  876. // But this interface will never be called to save data
  877. // [we will use CPersistor-based XML saving instead]
  878. // so the method will always fail.
  879. ASSERT(FALSE && "Should never come here");
  880. return E_NOTIMPL;
  881. }
  882. //+-------------------------------------------------------------------
  883. //
  884. // Member: Persist
  885. //
  886. // Synopsis: Persists the column information.
  887. //
  888. // Arguments: [persistor]- CPersistor in/from which column widths are persisted.
  889. //
  890. // Returns: void.
  891. //
  892. // History: 10-08-1999 AudriusZ Created
  893. //
  894. //--------------------------------------------------------------------
  895. void CColumnPersistInfo::Persist(CPersistor &persistor)
  896. {
  897. DECLARE_SC(sc, TEXT("CColumnPersistInfo::Persist"));
  898. if (!m_bInitialized && !Init())
  899. sc.Throw(E_FAIL);
  900. sc = ScCheckPointers(m_spColSetList.get(), m_spSnapinsMap.get(), E_UNEXPECTED);
  901. if (sc)
  902. sc.Throw();
  903. if (persistor.IsStoring())
  904. {
  905. // Give ranking to each column data.
  906. ItColSetDataList itColList;
  907. DWORD dwRank = 0;
  908. for (itColList = m_spColSetList->begin();
  909. itColList != m_spColSetList->end();
  910. ++itColList)
  911. {
  912. itColList->m_dwRank = dwRank++;
  913. }
  914. }
  915. else // if (persistor.IsLoading())
  916. {
  917. m_spColSetList->clear();
  918. m_spSnapinsMap->clear();
  919. }
  920. SnapinToColSetIDMapPersistor childPersisot(*m_spSnapinsMap, *m_spColSetList);
  921. childPersisot.Persist(persistor);
  922. if (persistor.IsStoring())
  923. m_bDirty = FALSE;
  924. }
  925. //+-------------------------------------------------------------------
  926. //
  927. // Member: OnInitDialog
  928. //
  929. // Synopsis: Initialize the Columns dialog.
  930. //
  931. // Arguments:
  932. //
  933. // History: 11-16-1998 AnandhaG Created
  934. //
  935. //--------------------------------------------------------------------
  936. LRESULT CColumnsDlg::OnInitDialog (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  937. {
  938. m_btnAdd = ::GetDlgItem(m_hWnd, IDC_ADD_COLUMNS);
  939. m_btnRemove = ::GetDlgItem(m_hWnd, IDC_REMOVE_COLUMNS);
  940. m_btnRestoreDefaultColumns = ::GetDlgItem(m_hWnd, IDC_RESTORE_DEFAULT_COLUMNS);
  941. m_btnMoveUp = ::GetDlgItem(m_hWnd, IDC_MOVEUP_COLUMN);
  942. m_btnMoveDown = ::GetDlgItem(m_hWnd, IDC_MOVEDOWN_COLUMN);
  943. m_HiddenColList.Attach(::GetDlgItem(m_hWnd, IDC_HIDDEN_COLUMNS));
  944. m_DisplayedColList.Attach(::GetDlgItem(m_hWnd, IDC_DISPLAYED_COLUMNS));
  945. m_bUsingDefaultColumnSettings = (*m_pColumnInfoList == m_DefaultColumnInfoList);
  946. InitializeLists();
  947. EnableUIObjects();
  948. return 0;
  949. }
  950. //+-------------------------------------------------------------------
  951. //
  952. // Member: OnOK
  953. //
  954. // Synopsis: Get the hidden and visible columns.
  955. //
  956. // Arguments:
  957. //
  958. // History: 11-16-1998 AnandhaG Created
  959. //
  960. //--------------------------------------------------------------------
  961. LRESULT CColumnsDlg::OnOK (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  962. {
  963. if (! m_bDirty) // column settings are not modified
  964. {
  965. EndDialog (IDCANCEL);
  966. return 1;
  967. }
  968. if (m_bUsingDefaultColumnSettings)
  969. {
  970. EndDialog(IDC_RESTORE_DEFAULT_COLUMNS);
  971. return 1;
  972. }
  973. ASSERT(NULL != m_pColumnInfoList);
  974. if (NULL == m_pColumnInfoList)
  975. return 0;
  976. WTL::CString strColumnName;
  977. CColumnInfoList::iterator it;
  978. CColumnInfo colinfo;
  979. // Get the strings from Hidden_List_Box.
  980. // These cols are to be hidden. So put them first in the list.
  981. int cItems = m_HiddenColList.GetCount();
  982. for (int i = 0; i < cItems; i++)
  983. {
  984. // Get the text from list box
  985. int nRet = m_HiddenColList.GetText(i, strColumnName);
  986. if (LB_ERR == nRet)
  987. {
  988. ASSERT(FALSE);
  989. break;
  990. }
  991. // Use the string to get the actual index of the column.
  992. int nIndex = GetColIndex(strColumnName);
  993. if (0 > nIndex )
  994. {
  995. ASSERT(FALSE);
  996. break;
  997. }
  998. // With the index get the column and insert it at beginning.
  999. it = find_if(m_pColumnInfoList->begin(), m_pColumnInfoList->end(),
  1000. bind2nd(ColPosCompare(), nIndex));
  1001. if (it == m_pColumnInfoList->end())
  1002. {
  1003. ASSERT(FALSE);
  1004. break;
  1005. }
  1006. // Set the *it flag to be hidden. Insert it at beginning.
  1007. colinfo = *it;
  1008. colinfo.SetColHidden();
  1009. // Move the item to the head of the list
  1010. m_pColumnInfoList->erase(it);
  1011. m_pColumnInfoList->push_front(colinfo);
  1012. }
  1013. // Then get the strings from DisplayedColumns_List_Box.
  1014. cItems = m_DisplayedColList.GetCount();
  1015. for (i = 0; i < cItems; i++)
  1016. {
  1017. // Get the text from list box
  1018. int nRet = m_DisplayedColList.GetText(i, strColumnName);
  1019. if (LB_ERR == nRet)
  1020. {
  1021. ASSERT(FALSE);
  1022. break;
  1023. }
  1024. // Use the column name to get the column index.
  1025. int nIndex = GetColIndex(strColumnName);
  1026. if (0 > nIndex )
  1027. {
  1028. ASSERT(FALSE);
  1029. break;
  1030. }
  1031. // Get the CColumnInfo and insert at end.
  1032. it = find_if(m_pColumnInfoList->begin(), m_pColumnInfoList->end(),
  1033. bind2nd(ColPosCompare(), nIndex));
  1034. if (it == m_pColumnInfoList->end())
  1035. break;
  1036. colinfo = *it;
  1037. if (colinfo.IsColHidden())
  1038. {
  1039. // If hidden column is made visible
  1040. // reset the hidden flag and set the width
  1041. // to auto_width.
  1042. colinfo.SetColHidden(false);
  1043. if (colinfo.GetColWidth() <= 0)
  1044. colinfo.SetColWidth(AUTO_WIDTH);
  1045. }
  1046. // Move it to the end of the list.
  1047. m_pColumnInfoList->erase(it);
  1048. m_pColumnInfoList->push_back(colinfo);
  1049. }
  1050. EndDialog (IDOK);
  1051. return 1;
  1052. }
  1053. LRESULT CColumnsDlg::OnCancel (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  1054. {
  1055. EndDialog (IDCANCEL);
  1056. return 0;
  1057. }
  1058. LRESULT CColumnsDlg::OnMoveUp (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  1059. {
  1060. MoveItem(TRUE);
  1061. return 0;
  1062. }
  1063. LRESULT CColumnsDlg::OnMoveDown (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  1064. {
  1065. MoveItem(FALSE);
  1066. return 0;
  1067. }
  1068. //+-------------------------------------------------------------------
  1069. //
  1070. // Member: OnAdd
  1071. //
  1072. // Synopsis: Adds a column to displayed columns list by removing
  1073. // the currently selected column from hidden column list.
  1074. //
  1075. // Arguments:
  1076. //
  1077. //--------------------------------------------------------------------
  1078. LRESULT CColumnsDlg::OnAdd (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  1079. {
  1080. // First remove from hidden column list.
  1081. int nCurSel = m_HiddenColList.GetCurSel();
  1082. WTL::CString strColumnName;
  1083. int nRet = m_HiddenColList.GetText(nCurSel, strColumnName);
  1084. if (LB_ERR == nRet)
  1085. {
  1086. ASSERT(FALSE);
  1087. return 0;
  1088. }
  1089. m_HiddenColList.DeleteString(nCurSel);
  1090. // now add it to Displayed column list.
  1091. m_DisplayedColList.AddString(strColumnName);
  1092. SetDirty();
  1093. if (nCurSel > m_HiddenColList.GetCount()-1)
  1094. nCurSel = m_HiddenColList.GetCount()-1;
  1095. m_HiddenColList.SetCurSel(nCurSel);
  1096. m_DisplayedColList.SelectString(0, strColumnName);
  1097. SetListBoxHScrollSize();
  1098. EnableUIObjects();
  1099. return 0;
  1100. }
  1101. //+-------------------------------------------------------------------
  1102. //
  1103. // Member: OnRemove
  1104. //
  1105. // Synopsis: Removes the currently selected column from displayed
  1106. // columns list by removing and adds it to hidden column list.
  1107. //
  1108. // Arguments:
  1109. //
  1110. //--------------------------------------------------------------------
  1111. LRESULT CColumnsDlg::OnRemove (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  1112. {
  1113. // Get the currently selected item in Displayed Columns list.
  1114. int nCurSel = m_DisplayedColList.GetCurSel();
  1115. WTL::CString strColumnName;
  1116. int nRet = m_DisplayedColList.GetText(nCurSel, strColumnName);
  1117. if (LB_ERR == nRet)
  1118. {
  1119. ASSERT(FALSE);
  1120. return 0;
  1121. }
  1122. // If column zero do not hide it.
  1123. if (0 == GetColIndex(strColumnName))
  1124. return 0;
  1125. m_DisplayedColList.DeleteString(nCurSel);
  1126. // Add it to hidden column list.
  1127. m_HiddenColList.AddString(strColumnName);
  1128. SetDirty();
  1129. if (nCurSel > m_DisplayedColList.GetCount()-1)
  1130. nCurSel = m_DisplayedColList.GetCount()-1;
  1131. m_DisplayedColList.SetCurSel(nCurSel);
  1132. m_HiddenColList.SelectString(0, strColumnName);
  1133. EnableUIObjects();
  1134. SetListBoxHScrollSize();
  1135. return 0;
  1136. }
  1137. LRESULT CColumnsDlg::OnRestoreDefaultColumns (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  1138. {
  1139. DECLARE_SC(sc, TEXT("CColumnsDlg::OnRestoreDefaultColumns"));
  1140. // Get the default data and populate the columns dialog.
  1141. *m_pColumnInfoList = m_DefaultColumnInfoList;
  1142. SetUsingDefaultColumnSettings();
  1143. InitializeLists();
  1144. EnableUIObjects();
  1145. // Button is disabled so put the focus on the dialog.
  1146. SetFocus();
  1147. return 0;
  1148. }
  1149. LRESULT CColumnsDlg::OnSelChange (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  1150. {
  1151. EnableUIObjects();
  1152. return 0;
  1153. }
  1154. //+-------------------------------------------------------------------
  1155. //
  1156. // Member: MoveItem
  1157. //
  1158. // Synopsis: Moves an item in the displayed columns list up or down.
  1159. // The up down order is same as column visible order from
  1160. // left to right.
  1161. //
  1162. // Arguments: [BOOL] - up or down.
  1163. //
  1164. //--------------------------------------------------------------------
  1165. void CColumnsDlg::MoveItem (BOOL bMoveUp)
  1166. {
  1167. int nCurSel = m_DisplayedColList.GetCurSel();
  1168. WTL::CString strColumnName;
  1169. int nRet = m_DisplayedColList.GetText(nCurSel, strColumnName);
  1170. if (LB_ERR == nRet)
  1171. {
  1172. ASSERT(FALSE);
  1173. return;
  1174. }
  1175. m_DisplayedColList.DeleteString(nCurSel);
  1176. if (bMoveUp)
  1177. m_DisplayedColList.InsertString(nCurSel-1, strColumnName);
  1178. else
  1179. m_DisplayedColList.InsertString(nCurSel+1, strColumnName);
  1180. m_DisplayedColList.SelectString(0, strColumnName);
  1181. SetDirty();
  1182. EnableUIObjects();
  1183. return;
  1184. }
  1185. //+-------------------------------------------------------------------
  1186. //
  1187. // Member: EnableControl
  1188. //
  1189. // Synopsis: Enable or Disable a window. If this window has to be
  1190. // disabled and it has focus, shift the focus to next
  1191. // enabled item in the tab-sequence.
  1192. //
  1193. // Arguments: hwnd - window to be enabled or disabled.
  1194. // bEnable - enable or disable.
  1195. //
  1196. //--------------------------------------------------------------------
  1197. bool CColumnsDlg::EnableControl(HWND hwnd, bool bEnable)
  1198. {
  1199. // If disabling and this window has focus then
  1200. // put focus on next enabled window.
  1201. if ( (!bEnable) && (hwnd == ::GetFocus()) )
  1202. {
  1203. HWND hwndWindowToFocus = GetNextDlgTabItem(hwnd);
  1204. if (hwndWindowToFocus)
  1205. ::SetFocus(hwndWindowToFocus);
  1206. }
  1207. // Now enable or disable the control.
  1208. return ::EnableWindow(hwnd, bEnable);
  1209. }
  1210. //+-------------------------------------------------------------------
  1211. //
  1212. // Member: EnableUIObjects
  1213. //
  1214. // Synopsis: Enable/Disable the UI objects in the dialog.
  1215. //
  1216. // Arguments:
  1217. //
  1218. //--------------------------------------------------------------------
  1219. void CColumnsDlg::EnableUIObjects()
  1220. {
  1221. int curselAvailable = m_HiddenColList.GetCurSel();
  1222. int curselShow = m_DisplayedColList.GetCurSel();
  1223. int cItems = m_HiddenColList.GetCount();
  1224. BOOL bEnableAdd = ((curselAvailable != LB_ERR) && (curselAvailable || cItems)) ? TRUE: FALSE;
  1225. BOOL bEnableRemove = ((curselShow != LB_ERR)) ? TRUE: FALSE;
  1226. BOOL bEnableMoveUp = ((curselShow != LB_ERR) && curselShow) ? TRUE: FALSE;
  1227. cItems = m_DisplayedColList.GetCount();
  1228. BOOL bEnableMoveDown = cItems && (curselShow != LB_ERR) && (cItems!=curselShow+1);
  1229. BOOL bRet = FALSE;
  1230. HWND hHwnFocussed = ::GetFocus();
  1231. bRet = EnableControl(m_btnAdd, bEnableAdd);
  1232. bRet = EnableControl(m_btnRemove, bEnableRemove);
  1233. bRet = EnableControl(m_btnMoveUp, bEnableMoveUp);
  1234. bRet = EnableControl(m_btnMoveDown, bEnableMoveDown);
  1235. // Enable restore defaults only if columns are already customized before bringing the dialog
  1236. bRet = EnableControl(m_btnRestoreDefaultColumns, (!m_bUsingDefaultColumnSettings));
  1237. // Disable Remove/Move Up/Move Down buttons for Col zero.
  1238. int nCurSel = m_DisplayedColList.GetCurSel();
  1239. WTL::CString strColumnName;
  1240. int nRet = m_DisplayedColList.GetText(nCurSel, strColumnName);
  1241. if (LB_ERR == nRet)
  1242. {
  1243. ASSERT(FALSE);
  1244. return;
  1245. }
  1246. if (0 == GetColIndex(strColumnName)) // Column 0
  1247. EnableControl(m_btnRemove, FALSE);
  1248. }
  1249. int CColumnsDlg::GetColIndex(LPCTSTR lpszColName)
  1250. {
  1251. TStringVector::iterator itStrVec1;
  1252. USES_CONVERSION;
  1253. itStrVec1 = find(m_pStringVector->begin(), m_pStringVector->end(), lpszColName);
  1254. if (m_pStringVector->end() != itStrVec1)
  1255. return (itStrVec1 - m_pStringVector->begin());
  1256. else
  1257. // Unknown column
  1258. return -1;
  1259. }
  1260. //+-------------------------------------------------------------------
  1261. //
  1262. // Member: SetListBoxHorizontalScrollbar
  1263. //
  1264. // Synopsis: For the given list box enumerate the strings added and find
  1265. // the largest string. Calculate scrollbar size for this string
  1266. // and set it.
  1267. //
  1268. // Arguments: [listBox] - Given list box.
  1269. //
  1270. //--------------------------------------------------------------------
  1271. void CColumnsDlg::SetListBoxHorizontalScrollbar(WTL::CListBox& listBox)
  1272. {
  1273. int dx=0;
  1274. WTL::CDC dc(listBox.GetWindowDC());
  1275. if (dc.IsNull())
  1276. return;
  1277. // Find the longest string in the list box.
  1278. for (int i=0;i < listBox.GetCount();i++)
  1279. {
  1280. WTL::CString str;
  1281. int nRet = listBox.GetText( i, str );
  1282. if (nRet == LB_ERR)
  1283. return;
  1284. WTL::CSize sz;
  1285. if (! dc.GetTextExtent(str, str.GetLength(), &sz))
  1286. return;
  1287. if (sz.cx > dx)
  1288. dx = sz.cx;
  1289. }
  1290. // Set the horizontal extent so every character of all strings
  1291. // can be scrolled to.
  1292. listBox.SetHorizontalExtent(dx);
  1293. return;
  1294. }
  1295. /* CColumnsDlg::InitializeLists
  1296. *
  1297. * PURPOSE:
  1298. *
  1299. * PARAMETERS:
  1300. *
  1301. * RETURNS:
  1302. * void
  1303. */
  1304. void CColumnsDlg::InitializeLists()
  1305. {
  1306. CColumnInfoList::iterator it;
  1307. int j = 0;
  1308. if (!m_pColumnInfoList)
  1309. {
  1310. ASSERT(FALSE);
  1311. return;
  1312. }
  1313. m_HiddenColList.ResetContent();
  1314. m_DisplayedColList.ResetContent();
  1315. USES_CONVERSION;
  1316. for (it = m_pColumnInfoList->begin(); it != m_pColumnInfoList->end(); ++it)
  1317. {
  1318. if (it->IsColHidden())
  1319. {
  1320. m_HiddenColList.AddString(m_pStringVector->at(it->GetColIndex()).data());
  1321. }
  1322. else
  1323. {
  1324. m_DisplayedColList.InsertString(j++, m_pStringVector->at(it->GetColIndex()).data());
  1325. }
  1326. }
  1327. m_DisplayedColList.SetCurSel(m_DisplayedColList.GetCount()-1);
  1328. m_HiddenColList.SetCurSel(m_HiddenColList.GetCount()-1);
  1329. SetListBoxHScrollSize();
  1330. }
  1331. //+-------------------------------------------------------------------
  1332. //
  1333. // Member: CColumnSetID::Persist
  1334. //
  1335. // Synopsis: Persists object data
  1336. //
  1337. // Arguments:
  1338. //
  1339. // History: 10-10-1999 AudriusZ Created
  1340. //
  1341. //--------------------------------------------------------------------
  1342. void CColumnSetID::Persist(CPersistor &persistor)
  1343. {
  1344. DECLARE_SC(sc, TEXT("CColumnSetID::Persist"));
  1345. CXMLAutoBinary binary;
  1346. if (persistor.IsStoring() && m_vID.size()) // fill only if have data
  1347. {
  1348. sc = binary.ScAlloc(m_vID.size());
  1349. if (sc)
  1350. sc.Throw();
  1351. CXMLBinaryLock sLock(binary); // will unlock in destructor
  1352. LPBYTE pData = NULL;
  1353. sc = sLock.ScLock(&pData);
  1354. if (sc)
  1355. sc.Throw();
  1356. sc = ScCheckPointers(pData, E_UNEXPECTED);
  1357. if (sc)
  1358. sc.Throw();
  1359. std::copy(m_vID.begin(), m_vID.end(), pData);
  1360. }
  1361. persistor.PersistAttribute(XML_ATTR_COLUMN_SET_ID_PATH, binary);
  1362. if (persistor.IsLoading())
  1363. {
  1364. m_vID.clear();
  1365. if (binary.GetSize())
  1366. {
  1367. CXMLBinaryLock sLock(binary); // will unlock in destructor
  1368. LPBYTE pData = NULL;
  1369. sc = sLock.ScLock(&pData);
  1370. if (sc)
  1371. sc.Throw();
  1372. sc = ScCheckPointers(pData, E_UNEXPECTED);
  1373. if (sc)
  1374. sc.Throw();
  1375. m_vID.insert(m_vID.end(), pData, pData + binary.GetSize());
  1376. }
  1377. }
  1378. persistor.PersistAttribute(XML_ATTR_COLUMN_SET_ID_FLAGS, m_dwFlags);
  1379. }
  1380. /***************************************************************************\
  1381. *
  1382. * METHOD: ViewToColSetDataMapPersistor::Persist
  1383. *
  1384. * PURPOSE: called by the base class to create and persist the new element
  1385. *
  1386. * PARAMETERS:
  1387. * CPersistor& persistor - [in] persistor from which to persist new element
  1388. *
  1389. * RETURNS:
  1390. * void
  1391. *
  1392. * see "Data structures used to persist column information" comment
  1393. * int file colwidth.h for more information
  1394. \***************************************************************************/
  1395. void ViewToColSetDataMapPersistor::Persist(CPersistor &persistor)
  1396. {
  1397. if (persistor.IsStoring())
  1398. {
  1399. // iterate and save all elements as linear list
  1400. ViewToColSetDataMap::iterator it;
  1401. for (it = m_map.begin(); it != m_map.end(); ++it)
  1402. {
  1403. // we will sneak under child's element to persist the KEY value as an attribute
  1404. // of the child element. To do that we use tag got from _GetXMLType() of the child
  1405. CPersistor persistorChild(persistor, it->second->GetXMLType());
  1406. int view_id = it->first; // just to cast constness out (we do not have const Persist)
  1407. persistorChild.PersistAttribute(XML_ATTR_COLUMN_SET_ID_VIEW, view_id);
  1408. // note: we are asking the child to persist on the same level.
  1409. // thats to save on depth
  1410. it->second->Persist(persistorChild);
  1411. }
  1412. }
  1413. else
  1414. {
  1415. // use base class to read. it will call OnNewElement for each found
  1416. m_map.clear();
  1417. XMLListCollectionBase::Persist(persistor);
  1418. }
  1419. }
  1420. /***************************************************************************\
  1421. *
  1422. * METHOD: ViewToColSetDataMapPersistor::OnNewElement
  1423. *
  1424. * PURPOSE: called by the base class to create and persist the new element
  1425. *
  1426. * PARAMETERS:
  1427. * CPersistor& persistor - [in] persistor from which to persist new element
  1428. *
  1429. * RETURNS:
  1430. * void
  1431. *
  1432. * see "Data structures used to persist column information" comment
  1433. * int file colwidth.h for more information
  1434. \***************************************************************************/
  1435. void ViewToColSetDataMapPersistor::OnNewElement(CPersistor& persistor)
  1436. {
  1437. // we will sneak under child's element to persist the KEY value as an attribute
  1438. // of the child element. To do that we use tag got from GetXMLType() of the child
  1439. CColumnSetData setData;
  1440. CPersistor persistorChild(persistor, setData.GetXMLType());
  1441. // read the key value from the child element
  1442. int view_id = 0;
  1443. persistorChild.PersistAttribute(XML_ATTR_COLUMN_SET_ID_VIEW, view_id);
  1444. // insert value to the list
  1445. ColSetDataList::iterator it = m_list.insert(m_list.end(), setData);
  1446. // ad list iterator to the map
  1447. m_map[view_id] = it;
  1448. // persist contents of the list item
  1449. it->Persist(persistorChild);
  1450. }
  1451. /***************************************************************************\
  1452. *
  1453. * METHOD: ColSetIDToViewTableMapPersistor::Persist
  1454. *
  1455. * PURPOSE: called as a request for the object to persist it's data
  1456. *
  1457. * PARAMETERS:
  1458. * CPersistor &persistor [in] persistor to persist to/from
  1459. *
  1460. * RETURNS:
  1461. * void
  1462. *
  1463. * see "Data structures used to persist column information" comment
  1464. * int file colwidth.h for more information
  1465. \***************************************************************************/
  1466. void ColSetIDToViewTableMapPersistor::Persist(CPersistor &persistor)
  1467. {
  1468. if (persistor.IsStoring())
  1469. {
  1470. // iterate and save all elements as linear list
  1471. ColSetIDToViewTableMap::iterator it;
  1472. for (it = m_map.begin(); it != m_map.end(); ++it)
  1473. {
  1474. // we will sneak under child's element to persist the KEY value as an attribute
  1475. // of the child element. To do that we use tag got from _GetXMLType() of the child
  1476. CPersistor persistorChild(persistor, ViewToColSetDataMapPersistor::_GetXMLType());
  1477. CColumnSetID& rID = *const_cast<CColumnSetID *>(&it->first);
  1478. rID.Persist(persistorChild);
  1479. // note: we are asking the child to persist on the same level.
  1480. // thats to save on depth
  1481. ViewToColSetDataMapPersistor mapPersistor(it->second, m_list);
  1482. mapPersistor.Persist(persistorChild);
  1483. }
  1484. }
  1485. else
  1486. {
  1487. // use base class to read. it will call OnNewElement for each found
  1488. m_map.clear();
  1489. XMLListCollectionBase::Persist(persistor);
  1490. }
  1491. }
  1492. /***************************************************************************\
  1493. *
  1494. * METHOD: ColSetIDToViewTableMapPersistor::OnNewElement
  1495. *
  1496. * PURPOSE: called by the base class to create and persist the new element
  1497. *
  1498. * PARAMETERS:
  1499. * CPersistor& persistor - [in] persistor from which to persist new element
  1500. *
  1501. * RETURNS:
  1502. * void
  1503. *
  1504. * see "Data structures used to persist column information" comment
  1505. * int file colwidth.h for more information
  1506. \***************************************************************************/
  1507. void ColSetIDToViewTableMapPersistor::OnNewElement(CPersistor& persistor)
  1508. {
  1509. // we will sneak under child's element to persist the KEY value as an attribute
  1510. // of the child element. To do that we use tag got from _GetXMLType() of the child
  1511. CPersistor persistorChild(persistor, ViewToColSetDataMapPersistor::_GetXMLType());
  1512. // read the key value from the child element
  1513. // note that we are forcing CColumnSetID to share the same element,
  1514. // therefore we are not using persistor.Persist()
  1515. CColumnSetID ID;
  1516. ID.Persist(persistorChild);
  1517. // insert the new element into the map
  1518. ViewToColSetDataMap &rMap = m_map[ID];
  1519. // create the wrapper on inserted map value
  1520. // (pass a list to wrapper. we actually have it [list] for this only reason)
  1521. ViewToColSetDataMapPersistor mapPersistor(m_map[ID], m_list);
  1522. // ask wrapper to read the rest
  1523. mapPersistor.Persist(persistorChild);
  1524. }
  1525. /***************************************************************************\
  1526. *
  1527. * METHOD: SnapinToColSetIDMapPersistor::Persist
  1528. *
  1529. * PURPOSE:
  1530. *
  1531. * PARAMETERS:
  1532. * CPersistor &persistor
  1533. *
  1534. * RETURNS:
  1535. * void
  1536. *
  1537. * see "Data structures used to persist column information" comment
  1538. * int file colwidth.h for more information
  1539. \***************************************************************************/
  1540. void SnapinToColSetIDMapPersistor::Persist(CPersistor &persistor)
  1541. {
  1542. DECLARE_SC(sc, TEXT("SnapinToColSetIDMapPersistor::Persist"));
  1543. if (persistor.IsStoring())
  1544. {
  1545. // prior-to-save cleanup
  1546. sc = ScPurgeUnusedColumnData();
  1547. if (sc)
  1548. sc.Throw();
  1549. // iterate and save all elements as linear list
  1550. SnapinToColSetIDMap::iterator it;
  1551. for (it = m_map.begin(); it != m_map.end(); ++it)
  1552. {
  1553. // we will sneak under child's element to persist the KEY value as an attribute
  1554. // of the child element. To do that we use tag got from _GetXMLType() of the child
  1555. CPersistor persistorChild(persistor, ColSetIDToViewTableMapPersistor::_GetXMLType());
  1556. // write the key value.
  1557. // just to cast constness out (we do not have const Persist)
  1558. GUID& guid = *const_cast<GUID *>(&it->first);
  1559. persistorChild.PersistAttribute(XML_ATTR_COLUMN_INFO_SNAPIN, guid);
  1560. // create a wrapper on the value (which is also a map)
  1561. // (pass a list to wrapper. though it's not used for storing)
  1562. ColSetIDToViewTableMapPersistor mapPersistor(it->second, m_list);
  1563. // persist the wrapper
  1564. mapPersistor.Persist(persistorChild);
  1565. }
  1566. }
  1567. else
  1568. {
  1569. // use base class to read. it will call OnNewElement for each found
  1570. m_map.clear();
  1571. XMLListCollectionBase::Persist(persistor);
  1572. }
  1573. }
  1574. /***************************************************************************\
  1575. *
  1576. * METHOD: SnapinToColSetIDMapPersistor::OnNewElement
  1577. *
  1578. * PURPOSE: called by the base class to create and persist the new element
  1579. *
  1580. * PARAMETERS:
  1581. * CPersistor& persistor - [in] persistor from which to persist new element
  1582. *
  1583. * RETURNS:
  1584. * void
  1585. *
  1586. * see "Data structures used to persist column information" comment
  1587. * int file colwidth.h for more information
  1588. \***************************************************************************/
  1589. void SnapinToColSetIDMapPersistor::OnNewElement(CPersistor& persistor)
  1590. {
  1591. // we will sneak under child's element to persist the KEY value as an attribute
  1592. // of the child element. To do that we use tag got from _GetXMLType() of the child
  1593. CPersistor persistorChild(persistor, ColSetIDToViewTableMapPersistor::_GetXMLType());
  1594. GUID guid;
  1595. // read the key value
  1596. persistorChild.PersistAttribute(XML_ATTR_COLUMN_INFO_SNAPIN, guid);
  1597. // insert the new element into the map
  1598. ColSetIDToViewTableMap &rMap = m_map[guid];
  1599. // create the wrapper on inserted map value
  1600. // (pass a list to wrapper. we actually have it [list] for this only reason)
  1601. ColSetIDToViewTableMapPersistor mapPersistor(rMap, m_list);
  1602. // ask wrapper to read the rest
  1603. mapPersistor.Persist(persistorChild);
  1604. }
  1605. /***************************************************************************\
  1606. *
  1607. * METHOD: SnapinToColSetIDMapPersistor::ScPurgeUnusedColumnData
  1608. *
  1609. * PURPOSE: prior-to-save cleanup. removes unused snapin entries
  1610. *
  1611. * PARAMETERS:
  1612. *
  1613. * RETURNS:
  1614. * SC - result code
  1615. *
  1616. \***************************************************************************/
  1617. SC SnapinToColSetIDMapPersistor::ScPurgeUnusedColumnData()
  1618. {
  1619. DECLARE_SC(sc, TEXT("SnapinToColSetIDMapPersistor::ScPurgeUnusedColumnData"));
  1620. // get the scopetree pointer
  1621. CScopeTree *pScopeTree = CScopeTree::GetScopeTree();
  1622. // check it
  1623. sc = ScCheckPointers(pScopeTree, E_UNEXPECTED);
  1624. if (sc)
  1625. return sc;
  1626. // iterate and remove unused entries
  1627. SnapinToColSetIDMap::iterator it = m_map.begin();
  1628. while (it != m_map.end())
  1629. {
  1630. // ask the scope tree if snapin is in use
  1631. BOOL bInUse = FALSE;
  1632. sc = pScopeTree->IsSnapinInUse(it->first, &bInUse);
  1633. if (sc)
  1634. return sc;
  1635. // act depending on usage
  1636. if (bInUse)
  1637. {
  1638. ++it; // skip also the stuff currently in use
  1639. }
  1640. else
  1641. {
  1642. // to the trash can
  1643. ColSetIDToViewTableMap& colSets = it->second;
  1644. // Iterate thro' all colset ids of this snapin.
  1645. ColSetIDToViewTableMap::iterator itColumnSetIDMap = colSets.begin();
  1646. while(itColumnSetIDMap != colSets.end())
  1647. {
  1648. // Get the view map
  1649. ViewToColSetDataMap& viewIDMap = itColumnSetIDMap->second;
  1650. ViewToColSetDataMap::iterator itViewIDMap = viewIDMap.begin();
  1651. // Iterate thro' all views and remove entries
  1652. while (itViewIDMap != viewIDMap.end())
  1653. {
  1654. m_list.erase(/*(ItColSetDataList)*/itViewIDMap->second);
  1655. itViewIDMap = viewIDMap.erase(itViewIDMap);
  1656. }
  1657. itColumnSetIDMap = colSets.erase(itColumnSetIDMap);
  1658. }
  1659. it = m_map.erase(it);
  1660. }
  1661. }
  1662. return sc;
  1663. }