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.

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