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.

415 lines
10 KiB

  1. /*--------------------------------------------------------------------------*
  2. *
  3. * Microsoft Windows
  4. * Copyright (C) Microsoft Corporation, 1999 - 1999
  5. *
  6. * File: viewset.cpp
  7. *
  8. * Contents: Implements CViewSettings.
  9. *
  10. * History: 21-April-99 vivekj Created
  11. *
  12. *--------------------------------------------------------------------------*/
  13. #include "stgio.h"
  14. #include "stddbg.h"
  15. #include "macros.h"
  16. #include <comdef.h>
  17. #include "serial.h"
  18. #include "mmcdebug.h"
  19. #include "mmcerror.h"
  20. #include "ndmgr.h"
  21. #include <string>
  22. #include "atlbase.h"
  23. #include "cstr.h"
  24. #include "xmlbase.h"
  25. #include "resultview.h"
  26. #include "viewset.h"
  27. #include "countof.h"
  28. CViewSettings::CViewSettings()
  29. : m_ulViewMode(0), m_guidTaskpad(GUID_NULL),
  30. m_dwRank(-1), m_bInvalid(FALSE), m_dwMask(0)
  31. {
  32. }
  33. bool
  34. CViewSettings::IsViewModeValid() const
  35. {
  36. return ( (m_RVType.HasList()) &&
  37. (m_dwMask & VIEWSET_MASK_VIEWMODE) );
  38. }
  39. bool
  40. CViewSettings::operator == (const CViewSettings& viewSettings)
  41. {
  42. if (m_dwMask != viewSettings.m_dwMask)
  43. {
  44. return false;
  45. }
  46. if (IsViewModeValid() &&
  47. (m_ulViewMode != viewSettings.m_ulViewMode) )
  48. {
  49. return false;
  50. }
  51. if (IsTaskpadIDValid() &&
  52. (m_guidTaskpad != viewSettings.m_guidTaskpad))
  53. {
  54. return false;
  55. }
  56. if (IsResultViewTypeValid() &&
  57. (m_RVType != viewSettings.m_RVType))
  58. {
  59. return false;
  60. }
  61. return true;
  62. }
  63. //+-------------------------------------------------------------------
  64. //
  65. // Member: CViewSettings::ScInitialize
  66. //
  67. // Synopsis: Private member to read 1.2 console files and init
  68. // the object.
  69. //
  70. // Arguments:
  71. //
  72. // Returns: SC
  73. //
  74. //--------------------------------------------------------------------
  75. SC CViewSettings::ScInitialize(bool bViewTypeValid, const VIEW_TYPE& viewType, const long lViewOptions, const wstring& wstrViewName)
  76. {
  77. DECLARE_SC(sc, _T("CViewSettings::ScInitialize"));
  78. LPOLESTR pViewName = NULL;
  79. if (wstrViewName.length() > 0)
  80. {
  81. pViewName = (LPOLESTR) CoTaskMemAlloc( (wstrViewName.length() + 1) * sizeof(OLECHAR) );
  82. wcscpy(pViewName, wstrViewName.data());
  83. }
  84. sc = m_RVType.ScInitialize(pViewName, lViewOptions);
  85. if (sc)
  86. return sc;
  87. SetResultViewTypeValid( bViewTypeValid );
  88. if ( bViewTypeValid )
  89. {
  90. // Now put these data in CViewSettings.
  91. switch(viewType)
  92. {
  93. case VIEW_TYPE_OCX:
  94. case VIEW_TYPE_WEB:
  95. break;
  96. case VIEW_TYPE_DEFAULT:
  97. // What is this?
  98. ASSERT(FALSE);
  99. break;
  100. case VIEW_TYPE_LARGE_ICON:
  101. m_ulViewMode = MMCLV_VIEWSTYLE_ICON;
  102. SetViewModeValid();
  103. break;
  104. case VIEW_TYPE_SMALL_ICON:
  105. m_ulViewMode = MMCLV_VIEWSTYLE_SMALLICON;
  106. SetViewModeValid();
  107. break;
  108. case VIEW_TYPE_REPORT:
  109. m_ulViewMode = MMCLV_VIEWSTYLE_REPORT;
  110. SetViewModeValid();
  111. break;
  112. case VIEW_TYPE_LIST:
  113. m_ulViewMode = MMCLV_VIEWSTYLE_LIST;
  114. SetViewModeValid();
  115. break;
  116. case VIEW_TYPE_FILTERED:
  117. m_ulViewMode = MMCLV_VIEWSTYLE_FILTERED;
  118. SetViewModeValid();
  119. break;
  120. default:
  121. // Should never come here.
  122. ASSERT(FALSE);
  123. break;
  124. }
  125. }
  126. return (sc);
  127. }
  128. //+-------------------------------------------------------------------
  129. //
  130. // Member: ReadSerialObject
  131. //
  132. // Synopsis: Reads the given version of CViewSettings from stream.
  133. //
  134. // Arguments: [stm] - The input stream.
  135. // [nVersion] - version of CColumnSortInfo to be read.
  136. //
  137. // The format is :
  138. // VIEW_TYPE
  139. // View Options
  140. // String (If VIEW_TYPE is OCX or Web).
  141. //
  142. //--------------------------------------------------------------------
  143. HRESULT CViewSettings::ReadSerialObject(IStream &stm, UINT nVersion)
  144. {
  145. HRESULT hr = S_FALSE; // assume unknown version
  146. if ( (4 <= nVersion))
  147. {
  148. try
  149. {
  150. VIEW_TYPE viewType;
  151. long lViewOptions;
  152. // ugly hackery required to extract directly into an enum
  153. stm >> *((int *) &viewType);
  154. stm >> lViewOptions;
  155. wstring wstrViewName;
  156. if( (VIEW_TYPE_OCX==viewType) || (VIEW_TYPE_WEB==viewType) )
  157. stm >> wstrViewName;
  158. if(2<=nVersion) // taskpads were added in version 2 of this object.
  159. {
  160. stm >> m_guidTaskpad;
  161. SetTaskpadIDValid(GUID_NULL != m_guidTaskpad);
  162. }
  163. if (3<=nVersion)
  164. stm >> m_dwRank;
  165. DWORD dwMask = 0;
  166. bool bViewTypeValid = true;
  167. if (4 <= nVersion)
  168. {
  169. stm >> dwMask;
  170. const DWORD MMC12_VIEWSET_MASK_TYPE = 0x0001;
  171. bViewTypeValid = ( dwMask & MMC12_VIEWSET_MASK_TYPE );
  172. }
  173. hr = ScInitialize(bViewTypeValid, viewType, lViewOptions, wstrViewName).ToHr();
  174. }
  175. catch (_com_error& err)
  176. {
  177. hr = err.Error();
  178. ASSERT (false && "Caught _com_error");
  179. }
  180. }
  181. return (hr);
  182. }
  183. //+-------------------------------------------------------------------
  184. //
  185. // Member: CViewSettings::Persist
  186. //
  187. // Synopsis: persist to / from XML document.
  188. //
  189. // Arguments: [persistor] - target or source.
  190. //
  191. //--------------------------------------------------------------------
  192. void CViewSettings::Persist(CPersistor& persistor)
  193. {
  194. // First Load or Save the mask. (Mask tells which members are valid).
  195. // define the table to map enumeration values to strings
  196. static const EnumLiteral mappedMasks[] =
  197. {
  198. { VIEWSET_MASK_VIEWMODE, XML_BITFLAG_VIEWSET_MASK_VIEWMODE },
  199. { VIEWSET_MASK_RVTYPE, XML_BITFLAG_VIEWSET_MASK_RVTYPE },
  200. { VIEWSET_MASK_TASKPADID, XML_BITFLAG_VIEWSET_MASK_TASKPADID },
  201. };
  202. // create wrapper to persist flag values as strings
  203. CXMLBitFlags maskPersistor(m_dwMask, mappedMasks, countof(mappedMasks));
  204. // persist the wrapper
  205. persistor.PersistAttribute(XML_ATTR_VIEW_SETTINGS_MASK, maskPersistor);
  206. if (IsTaskpadIDValid())
  207. persistor.Persist(m_guidTaskpad);
  208. if (IsViewModeValid())
  209. {
  210. // define the table to map enumeration values to strings
  211. static const EnumLiteral mappedModes[] =
  212. {
  213. { MMCLV_VIEWSTYLE_ICON, XML_ENUM_LV_STYLE_ICON },
  214. { MMCLV_VIEWSTYLE_SMALLICON, XML_ENUM_LV_STYLE_SMALLICON },
  215. { MMCLV_VIEWSTYLE_LIST, XML_ENUM_LV_STYLE_LIST },
  216. { MMCLV_VIEWSTYLE_REPORT, XML_ENUM_LV_STYLE_REPORT },
  217. { MMCLV_VIEWSTYLE_FILTERED, XML_ENUM_LV_STYLE_FILTERED },
  218. };
  219. // create wrapper to persist flag values as strings
  220. CXMLEnumeration modePersistor(m_ulViewMode, mappedModes, countof(mappedModes));
  221. // persist the wrapper
  222. persistor.PersistAttribute(XML_ATTR_VIEW_SETNGS_VIEW_MODE, modePersistor);
  223. }
  224. if (IsResultViewTypeValid())
  225. // Call CResultViewType to persist itself.
  226. persistor.Persist(m_RVType);
  227. bool bPeristRank = true;
  228. if (persistor.IsLoading())
  229. m_dwRank = (DWORD)-1; // make sure it's initialized if fails to load
  230. else
  231. bPeristRank = (m_dwRank != (DWORD)-1); // persist only if is used
  232. if (bPeristRank)
  233. persistor.PersistAttribute(XML_ATTR_VIEW_SETTINGS_RANK, m_dwRank, attr_optional);
  234. }
  235. //+-------------------------------------------------------------------
  236. //
  237. // Member: CViewSettings::ScGetViewMode
  238. //
  239. // Synopsis: Gets the view mode in list view.
  240. //
  241. // Arguments: [ulViewMode] - New view mode.
  242. //
  243. // Returns: SC
  244. //
  245. //--------------------------------------------------------------------
  246. SC CViewSettings::ScGetViewMode (ULONG& ulViewMode)
  247. {
  248. SC sc;
  249. if (!IsViewModeValid())
  250. return (sc = E_FAIL);
  251. ulViewMode = m_ulViewMode;
  252. return (sc);
  253. }
  254. //+-------------------------------------------------------------------
  255. //
  256. // Member: CViewSettings::ScSetViewMode
  257. //
  258. // Synopsis:
  259. //
  260. // Arguments:
  261. //
  262. // Returns: SC
  263. //
  264. //--------------------------------------------------------------------
  265. SC CViewSettings::ScSetViewMode (const ULONG ulViewMode)
  266. {
  267. SC sc;
  268. m_ulViewMode = ulViewMode;
  269. SetViewModeValid();
  270. return (sc);
  271. }
  272. //+-------------------------------------------------------------------
  273. //
  274. // Member: CViewSettings::ScGetTaskpadID
  275. //
  276. // Synopsis:
  277. //
  278. // Arguments:
  279. //
  280. // Returns: SC
  281. //
  282. //--------------------------------------------------------------------
  283. SC CViewSettings::ScGetTaskpadID (GUID& guidTaskpad)
  284. {
  285. SC sc;
  286. if (! IsTaskpadIDValid())
  287. return (sc = E_FAIL);
  288. guidTaskpad = m_guidTaskpad;
  289. return (sc);
  290. }
  291. //+-------------------------------------------------------------------
  292. //
  293. // Member: CViewSettings::ScSetTaskpadID
  294. //
  295. // Synopsis:
  296. //
  297. // Arguments:
  298. //
  299. // Returns: SC
  300. //
  301. //--------------------------------------------------------------------
  302. SC CViewSettings::ScSetTaskpadID (const GUID& guidTaskpad)
  303. {
  304. DECLARE_SC(sc, _T("CViewSettings::ScSetTaskpadID"));
  305. m_guidTaskpad = guidTaskpad;
  306. SetTaskpadIDValid(true);
  307. return (sc);
  308. }
  309. //+-------------------------------------------------------------------
  310. //
  311. // Member: CViewSettings::ScGetResultViewType
  312. //
  313. // Synopsis:
  314. //
  315. // Arguments:
  316. //
  317. // Returns: SC
  318. //
  319. //--------------------------------------------------------------------
  320. SC CViewSettings::ScGetResultViewType (CResultViewType& rvt)
  321. {
  322. SC sc;
  323. if (! IsResultViewTypeValid())
  324. return (sc = E_FAIL);
  325. rvt = m_RVType;
  326. return (sc);
  327. }
  328. //+-------------------------------------------------------------------
  329. //
  330. // Member: CViewSettings::ScSetResultViewType
  331. //
  332. // Synopsis:
  333. //
  334. // Arguments:
  335. //
  336. // Returns: SC
  337. //
  338. //--------------------------------------------------------------------
  339. SC CViewSettings::ScSetResultViewType (const CResultViewType& rvt)
  340. {
  341. DECLARE_SC(sc, _T("CViewSettings::ScSetResultViewType"));
  342. m_RVType = rvt;
  343. SetResultViewTypeValid();
  344. // ResultViewType changes, if new result-pane contains list use
  345. // current view mode if one exists else invalidate view mode data.
  346. if (!rvt.HasList())
  347. SetViewModeValid(false);
  348. return (sc);
  349. }