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.

320 lines
11 KiB

  1. //+-------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1999
  5. //
  6. // File: viewpers.h
  7. //
  8. // Contents: Classes related to view setting persistence.
  9. //
  10. // Classes: CViewSettingsID and CViewSettingPersistor.
  11. //
  12. // History: 04-Apr-99 AnandhaG Created
  13. //
  14. //--------------------------------------------------------------------
  15. #ifndef __VIEWPERS_H__
  16. #define __VIEWPERS_H__
  17. #pragma once
  18. #include "bookmark.h"
  19. #pragma warning(disable: 4503) // Disable long name limit warnings
  20. using namespace std;
  21. class CViewSettings;
  22. class CBookmark;
  23. /*************************************************************************
  24. *
  25. * How CViewSettingsPersistor is used:
  26. * There is only one CViewSettingsPersistor object per document.
  27. *
  28. * The object stored as static variable inside CNode as CNode needs
  29. * to access this object frequently.
  30. *
  31. * The Document needs to initialize/save the object by loading/savind
  32. * from/to console file. It calls below ScQueryViewSettingsPersistor.
  33. *
  34. * The object is created with first call to ScQueryViewSettingsPersistor.
  35. * The object is destroyed when DocumentClosed event is received.
  36. *
  37. *************************************************************************/
  38. //+-------------------------------------------------------------------
  39. // View Setting Persistence Versioning
  40. // This version info is used for MMC1.2 IPersist* interfaces.
  41. // In MMC2.0, XML maintains versioning using the tags, so this
  42. // constant is not used. Look at CViewPersistInfo members Load/Save
  43. // to see how this version information is used.
  44. static const INT ViewSettingPersistenceVersion = 2;
  45. // We allow the list to grow VIEWSETTINGS_MAXLIMIT times more,
  46. // then we do garbage collection.
  47. #define VIEWSETTINGS_MAXLIMIT 0.4
  48. //+-------------------------------------------------------------------
  49. //
  50. // Class: CViewSettingsID
  51. //
  52. // Purpose: To identify the result-view-setting-data. The identifier
  53. // consists of the triplet [ViewID, NodeTypeGUID, Node-Bookmark]
  54. //
  55. // We need to persist some result-view-setting-data per node and
  56. // some per node-type basis.
  57. //
  58. // The [ViewID + Node-Bookmark] identifies a node. In this case
  59. // NodeTypeGUID will be GUID_NULL.
  60. //
  61. // The [ViewID + NodeTypeGUID] identifies a nodetype. In this case
  62. // Node-Bookmark will be invalid object (see CBookmark for invalid obj).
  63. //
  64. // History: 06-22-2000 AnandhaG Created
  65. //
  66. //--------------------------------------------------------------------
  67. class CViewSettingsID : public CXMLObject
  68. {
  69. public:
  70. friend class CViewPersistInfo;
  71. friend IStream& operator>> (IStream& stm, CViewSettingsID& viewSettingsID);
  72. public:
  73. CViewSettingsID() : m_dwViewID(-1), m_nodeTypeGUID(GUID_NULL)
  74. {
  75. // m_bookmark is initialized as not valid by default constructor
  76. }
  77. // Synopsis: Given the view-id & bookmark (not nodetypeguid) construct
  78. // a CViewSettingsID object (with GUID_NULL as nodetypeguid).
  79. CViewSettingsID(INT nViewID, const CBookmark& bookmark)
  80. {
  81. m_dwViewID = nViewID;
  82. m_bookmark = bookmark;
  83. m_nodeTypeGUID = GUID_NULL;
  84. }
  85. // Synopsis: Given the view-id & nodetype guid (not bookmark) construct
  86. // a CViewSettingsID object (with invalid bookmark).
  87. CViewSettingsID(INT nViewID, const GUID& guidNodeType)
  88. {
  89. m_dwViewID = nViewID;
  90. m_nodeTypeGUID = guidNodeType;
  91. // m_bookmark is initialized as not valid by default constructor
  92. }
  93. /*
  94. CViewSettingsID(const CViewSettingsID& viewSettingsID)
  95. {
  96. m_dwViewID = viewSettingsID.m_dwViewID;
  97. m_bookmark = viewSettingsID.m_bookmark;
  98. m_nodeTypeGUID = viewSettingsID.m_nodeTypeGUID;
  99. }
  100. CViewSettingsID& operator=(const CViewSettingsID& viewSettingsID)
  101. {
  102. if (this != &viewSettingsID)
  103. {
  104. m_dwViewID = viewSettingsID.m_dwViewID;
  105. m_bookmark = viewSettingsID.m_bookmark;
  106. m_nodeTypeGUID = viewSettingsID.m_nodeTypeGUID;
  107. }
  108. return (*this);
  109. }
  110. bool operator==(const CViewSettingsID& viewSettingsID) const
  111. {
  112. return ((m_dwViewID == viewSettingsID.m_dwViewID) &&
  113. (m_bookmark == viewSettingsID.m_bookmark) &&
  114. (m_nodeTypeGUID == viewSettingsID.m_nodeTypeGUID) );
  115. }
  116. */
  117. /*
  118. Compare view id first, then guid and then bookmark.
  119. */
  120. bool operator<(const CViewSettingsID& viewSettingsID) const
  121. {
  122. // First compare view-ids (low cost).
  123. if (m_dwViewID < viewSettingsID.m_dwViewID)
  124. return true;
  125. if (m_dwViewID > viewSettingsID.m_dwViewID)
  126. return false;
  127. // The view-ids match so now compare GUIDs.
  128. if (m_nodeTypeGUID < viewSettingsID.m_nodeTypeGUID)
  129. return true;
  130. if (m_nodeTypeGUID > viewSettingsID.m_nodeTypeGUID)
  131. return false;
  132. // The view-ids as well as guids match so compare bookmarks.
  133. if (m_bookmark < viewSettingsID.m_bookmark)
  134. return true;
  135. return false;
  136. }
  137. DWORD get_ViewID() const { return m_dwViewID;}
  138. virtual void Persist(CPersistor &persistor)
  139. {
  140. persistor.PersistAttribute(XML_ATTR_VIEW_SETTINGS_ID_VIEW, m_dwViewID);
  141. persistor.PersistAttribute(XML_ATTR_NODETYPE_GUID, m_nodeTypeGUID, attr_optional); // optional
  142. /*
  143. * Storing: save book mark only if it is valid.
  144. * Loading: See if bookmark is present for this element before reading.
  145. */
  146. if ( ( persistor.IsStoring() && m_bookmark.IsValid() ) ||
  147. ( persistor.IsLoading() && persistor.HasElement(m_bookmark.GetXMLType(), NULL) ))
  148. persistor.Persist(m_bookmark);
  149. }
  150. DEFINE_XML_TYPE(XML_TAG_VIEW_SETTINGS_ID);
  151. protected:
  152. CBookmark m_bookmark;
  153. GUID m_nodeTypeGUID;
  154. DWORD m_dwViewID;
  155. };
  156. //+-------------------------------------------------------------------
  157. //
  158. // Member: operator>>
  159. //
  160. // Synopsis: Reads CViewSettingsID data from the stream.
  161. //
  162. // Arguments: [stm] - The input stream.
  163. // [viewSettingsID] - CViewSettingsID object.
  164. //
  165. // The format is :
  166. // DWORD viewID
  167. // CBookmark*
  168. //
  169. //--------------------------------------------------------------------
  170. inline IStream& operator>> (IStream& stm, CViewSettingsID& rvsd)
  171. {
  172. ASSERT(rvsd.m_nodeTypeGUID == GUID_NULL);
  173. rvsd.m_nodeTypeGUID = GUID_NULL;
  174. return (stm >> rvsd.m_dwViewID >> rvsd.m_bookmark);
  175. }
  176. //+-------------------------------------------------------------------
  177. //
  178. // Data structures used to persist view information:
  179. //
  180. // View information is persisted as follows:
  181. // Internally, the following data structure is used. View information
  182. // is recorded per view.
  183. // map
  184. // [View ID, NodeTypeGUID, Bookmark]------> iterator to a list containing CViewSettings.
  185. //
  186. // The list contains CViewSettings to all the views, and is ordered
  187. // in with most recently used data in the front of the list.
  188. // This is useful for garbage collection.
  189. //
  190. // Persistence: The information is serialized as follows:
  191. //
  192. // 1) Stream version
  193. // 2) Number of viewSettings
  194. // 3) For each viewSettings
  195. // i) CViewSettingsID (the identifier).
  196. // ii) CViewSettings(the data).
  197. //
  198. //--------------------------------------------------------------------
  199. typedef list<CViewSettings> CViewSettingsList;
  200. typedef CViewSettingsList::iterator IteratorToViewSettingsList;
  201. // A one to one map from CViewSettings to pointer to CViewSettings.
  202. typedef map<CViewSettingsID, IteratorToViewSettingsList> CViewSettingsIDToViewSettingsMap;
  203. //+-------------------------------------------------------------------
  204. //
  205. // Class: CViewSettingsPersistor
  206. //
  207. // Purpose: This class has persisted settings information for nodes & nodetypes
  208. // in all views (therefore one per instance of mmc).
  209. // It knows to load/save the info from streams.
  210. //
  211. // History: 04-23-1999 AnandhaG Created
  212. //
  213. // Data structures used to persist view information:
  214. // A map from the CViewSettingsID to pointer to CViewSettings class.
  215. //
  216. //--------------------------------------------------------------------
  217. class CViewSettingsPersistor : public IPersistStream,
  218. public CComObjectRoot,
  219. public XMLMapCollectionBase
  220. {
  221. private:
  222. CViewSettingsList m_listViewSettings;
  223. CViewSettingsIDToViewSettingsMap m_mapViewSettingsIDToViewSettings;
  224. bool m_bDirty;
  225. // This is the max number of items specified by user???
  226. // We go 40% more so that we dont do garbage collection often.
  227. DWORD m_dwMaxItems;
  228. public:
  229. /*
  230. * ATL COM map
  231. */
  232. BEGIN_COM_MAP (CViewSettingsPersistor)
  233. COM_INTERFACE_ENTRY (IPersistStream)
  234. END_COM_MAP ()
  235. CViewSettingsPersistor();
  236. SC ScDeleteDataOfView( int nViewID);
  237. // IPersistStream methods
  238. STDMETHOD(IsDirty)(void) { return ( m_bDirty ? S_OK : S_FALSE); }
  239. STDMETHOD(GetSizeMax)(ULARGE_INTEGER *pcbSize) { ASSERT(FALSE); return E_NOTIMPL;}
  240. STDMETHOD(GetClassID)(LPCLSID lpClsid) { ASSERT(FALSE); return E_NOTIMPL; }
  241. STDMETHOD(Load)(IStream *pStm);
  242. STDMETHOD(Save)(IStream *pStm, BOOL fClearDirty);
  243. // XML persistence helpers
  244. virtual void Persist(CPersistor &persistor);
  245. virtual void OnNewElement(CPersistor& persistKey,CPersistor& persistVal);
  246. DEFINE_XML_TYPE(XML_TAG_VIEW_PERSIST_INFO)
  247. // Members to access viewsettings data.
  248. // 1. Taskpad IDs.
  249. // 1.a) Per NodeTypeGUID
  250. SC ScGetTaskpadID(int nViewID, const GUID& guidNodeType ,GUID& guidTaskpad);
  251. SC ScSetTaskpadID(int nViewID, const GUID& guidNodeType ,const CBookmark& bookmark,
  252. const GUID& guidTaskpad, bool bSetDirty);
  253. // 1.b) Per node
  254. SC ScGetTaskpadID(int nViewID, const CBookmark& bookmark,GUID& guidTaskpad);
  255. SC ScSetTaskpadID(int nViewID, const CBookmark& bookmark,const GUID& guidTaskpad, bool bSetDirty);
  256. // 2. View mode.
  257. SC ScGetViewMode (int nViewID, const CBookmark& bookmark, ULONG& ulViewMode);
  258. SC ScSetViewMode (int nViewID, const CBookmark& bookmark, ULONG ulViewMode);
  259. // 3. ResultViewTypeInfo.
  260. SC ScGetResultViewType (int nViewID, const CBookmark& bookmark, CResultViewType& rvt);
  261. SC ScSetResultViewType (int nViewID, const CBookmark& bookmark, const CResultViewType& rvt);
  262. SC ScSetFavoriteViewSettings (int nViewID, const CBookmark& bookmark, const CViewSettings& viewSettings);
  263. private:
  264. SC ScGetViewSettings( const CViewSettingsID& viewSettingsID, CViewSettings& viewSettings);
  265. SC ScSetViewSettings( const CViewSettingsID& viewSettingsID, const CViewSettings& viewSettings, bool bSetViewDirty);
  266. SC ScGarbageCollectItems();
  267. SC ScDeleteMarkedItems();
  268. };
  269. #endif /* __VIEWPERS_H__ */