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.

146 lines
4.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1999
  5. //
  6. // File: columninfo.cpp
  7. //
  8. // Contents: Classes related to column persistence.
  9. //
  10. //
  11. // Note: The classes in this file (CColumnInfo, CColumnInfoList)
  12. // were in nodemgr/colwidth.h. They are moved here so that
  13. // if columns change conui can ask nodemgr to persist data
  14. // or conui can set headers by asking nodemgr for data.
  15. //
  16. // History: 04-Apr-00 AnandhaG Created
  17. //
  18. //--------------------------------------------------------------------------
  19. #include "stgio.h"
  20. #include "serial.h"
  21. #include "mmcdebug.h"
  22. #include "mmcerror.h"
  23. #include <string>
  24. #include "cstr.h"
  25. #include "xmlbase.h"
  26. #include "countof.h"
  27. #include "columninfo.h"
  28. //+-------------------------------------------------------------------
  29. //
  30. // Member: ReadSerialObject
  31. //
  32. // Synopsis: Read the CColumnInfo object from the stream.
  33. //
  34. // Arguments: [stm] - The input stream.
  35. // [nVersion] - The version of the object being read.
  36. //
  37. // The format is :
  38. // INT column index
  39. // INT column width
  40. // INT column format
  41. //
  42. //--------------------------------------------------------------------
  43. HRESULT CColumnInfo::ReadSerialObject (IStream &stm, UINT nVersion /*,LARGE_INTEGER nBytes*/)
  44. {
  45. HRESULT hr = S_FALSE; // assume bad version
  46. if (GetVersion() == nVersion)
  47. {
  48. try
  49. {
  50. stm >> m_nCol;
  51. stm >> m_nWidth;
  52. stm >> m_nFormat;
  53. hr = S_OK;
  54. }
  55. catch (_com_error& err)
  56. {
  57. hr = err.Error();
  58. ASSERT (false && "Caught _com_error");
  59. }
  60. }
  61. return (hr);
  62. }
  63. //+-------------------------------------------------------------------
  64. //
  65. // Member: CColumnInfo::Persist
  66. //
  67. // Synopsis: Persists object data
  68. //
  69. // Arguments:
  70. //
  71. // History: 10-10-1999 AudriusZ Created
  72. //
  73. //--------------------------------------------------------------------
  74. void CColumnInfo::Persist(CPersistor &persistor)
  75. {
  76. persistor.PersistAttribute(XML_ATTR_COLUMN_INFO_COLUMN, m_nCol) ;
  77. persistor.PersistAttribute(XML_ATTR_COLUMN_INFO_WIDTH, m_nWidth) ;
  78. static const EnumLiteral mappedFormats[] =
  79. {
  80. { LVCFMT_LEFT, XML_ENUM_COL_INFO_LVCFMT_LEFT },
  81. { LVCFMT_RIGHT, XML_ENUM_COL_INFO_LVCFMT_RIGHT },
  82. { LVCFMT_CENTER, XML_ENUM_COL_INFO_LVCFMT_CENTER },
  83. };
  84. CXMLEnumeration formatPersistor(m_nFormat, mappedFormats, countof(mappedFormats) );
  85. persistor.PersistAttribute(XML_ATTR_COLUMN_INFO_FORMAT, formatPersistor) ;
  86. }
  87. //+-------------------------------------------------------------------
  88. //
  89. // Member: ReadSerialObject
  90. //
  91. // Synopsis: Reads CColumnInfoList data from stream for the given version.
  92. //
  93. // Format: number of columns : each CColumnInfo entry.
  94. //
  95. // Arguments: [stm] - The input stream.
  96. // [nVersion] - Version of CColumnInfoList to be read.
  97. //
  98. //
  99. //--------------------------------------------------------------------
  100. HRESULT CColumnInfoList::ReadSerialObject (IStream &stm, UINT nVersion /*,LARGE_INTEGER nBytes*/)
  101. {
  102. HRESULT hr = S_FALSE; // assume bad version
  103. if (GetVersion() == nVersion)
  104. {
  105. try
  106. {
  107. // Number of columns.
  108. DWORD dwCols;
  109. stm >> dwCols;
  110. clear();
  111. for (int i = 0; i < dwCols; i++)
  112. {
  113. CColumnInfo colEntry;
  114. // Read the colEntry data.
  115. if (colEntry.Read(stm) != S_OK)
  116. continue;
  117. push_back(colEntry);
  118. }
  119. hr = S_OK;
  120. }
  121. catch (_com_error& err)
  122. {
  123. hr = err.Error();
  124. ASSERT (false && "Caught _com_error");
  125. }
  126. }
  127. return (hr);
  128. }