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.

168 lines
4.9 KiB

  1. #ifndef _DVViewState_h
  2. #define _DVViewState_h
  3. // Forwards
  4. class CDefView;
  5. typedef struct
  6. {
  7. POINT pt;
  8. ITEMIDLIST idl;
  9. } VIEWSTATE_POSITION;
  10. typedef struct
  11. {
  12. // NOTE: Not a typo! This is a persisted structure so we cannot use LPARAM
  13. LONG lParamSort;
  14. int iDirection;
  15. int iLastColumnClick;
  16. } WIN95SAVESTATE;
  17. typedef struct
  18. {
  19. WORD cbSize;
  20. WORD wUnused; // junk on stack at this location has been saved in the registry since Win95... bummer
  21. DWORD ViewMode;
  22. POINTS ptScroll;
  23. WORD cbColOffset;
  24. WORD cbPosOffset;
  25. WIN95SAVESTATE dvState;
  26. } WIN95HEADER;
  27. // Even though we don't currently store anything we care
  28. // about in this structure relating to the view state,
  29. // the cbStreamSize value fixes a bug in Win95 where we
  30. // read to the end of the stream instead of just reading
  31. // in the same number of bytes we wrote out.
  32. //
  33. typedef struct
  34. {
  35. DWORD dwSignature; // DVSAVEHEADEREX_SIGNATURE
  36. WORD cbSize; // size of this structure, in bytes
  37. WORD wVersion; // DVSAVEHEADEREX_VERSION
  38. DWORD cbStreamSize; // size of all info saved, in bytes
  39. DWORD dwUnused; // used to be SIZE szExtended (ie4 beta1)
  40. WORD cbColOffset; // overrides DVSAVEHEADER.cbColOffset
  41. WORD wAlign;
  42. } IE4HEADER;
  43. typedef struct
  44. {
  45. WIN95HEADER dvSaveHeader;
  46. IE4HEADER dvSaveHeaderEx;
  47. } DVSAVEHEADER_COMBO;
  48. #define IE4HEADER_SIGNATURE 0xf0f0f0f0 // don't conflict with CCOLSHEADER_SIGNATURE
  49. #define IE4HEADER_VERSION 3 // for easy versioning
  50. #define VIEWSTATEHEADER_SIGNATURE 0xfddfdffd
  51. #define VIEWSTATEHEADER_VERSION_1 0x0C
  52. #define VIEWSTATEHEADER_VERSION_2 0x0E
  53. #define VIEWSTATEHEADER_VERSION_3 0x0f
  54. #define VIEWSTATEHEADER_VERSION_CURRENT VIEWSTATEHEADER_VERSION_3
  55. typedef struct
  56. {
  57. GUID guidGroupID;
  58. SHCOLUMNID scidDetails;
  59. } GROUP_PERSIST;
  60. typedef struct
  61. {
  62. struct
  63. {
  64. DWORD dwSignature;
  65. USHORT uVersion; // 0x0c == IE4, 0x0e == IE5
  66. USHORT uCols;
  67. USHORT uOffsetWidths;
  68. USHORT uOffsetColOrder;
  69. } Version1;
  70. struct
  71. {
  72. USHORT uOffsetColStates;
  73. } Version2;
  74. struct
  75. {
  76. USHORT uOffsetGroup;
  77. } Version3;
  78. } VIEWSTATEHEADER;
  79. class CViewState
  80. {
  81. void InitFromHeader(DVSAVEHEADER_COMBO* pdv);
  82. void LoadPositionBlob(CDefView* pdv, DWORD cbSizeofStream, IStream* pstm);
  83. HRESULT SavePositionBlob(CDefView* pdv, IStream* pstm);
  84. BOOL SyncColumnWidths(CDefView* pdv, BOOL fSetListViewState);
  85. BOOL SyncColumnStates(CDefView* pdv, BOOL fSetListViewstate);
  86. BOOL SyncPositions(CDefView* pdv);
  87. static int CALLBACK _SavedItemCompare(void *p1, void *p2, LPARAM lParam);
  88. DWORD _GetStreamSize(IStream* pstm);
  89. public:
  90. // Save State
  91. LPARAM _lParamSort;
  92. int _iDirection;
  93. int _iLastColumnClick;
  94. DWORD _ViewMode;
  95. POINTS _ptScroll;
  96. HDSA _hdsaColumnOrder;
  97. HDSA _hdsaColumnWidths;
  98. HDSA _hdsaColumnStates;
  99. HDSA _hdsaColumns;
  100. HDPA _hdpaItemPos;
  101. BYTE* _pbPositionData;
  102. GUID _guidGroupID;
  103. SHCOLUMNID _scidDetails;
  104. BOOL _fFirstViewed;
  105. CViewState();
  106. ~CViewState();
  107. // When initializing a new DefView, see if we can
  108. // propogate information from the previous one.
  109. void InitFromPreviousView(IUnknown* pPrevView);
  110. void InitWithDefaults(CDefView* pdv);
  111. void GetDefaults(CDefView* pdv, LPARAM* plParamSort, int* piDirection, int* piLastColumnClick);
  112. HRESULT InitializeColumns(CDefView* pdv);
  113. BOOL AppendColumn(UINT uCol, USHORT uWidth, INT uOrder);
  114. BOOL RemoveColumn(UINT uCol);
  115. UINT GetColumnWidth(UINT uCol, UINT uDefaultWidth);
  116. UINT GetColumnCount();
  117. // Column Helpers.
  118. DWORD GetColumnState(UINT uCol);
  119. DWORD GetTransientColumnState(UINT uCol);
  120. void SetColumnState(UINT uCol, DWORD dwMask, DWORD dwState);
  121. void SetTransientColumnState(UINT uCol, DWORD dwMask, DWORD dwState);
  122. LPTSTR GetColumnName(UINT uCol);
  123. int GetColumnFormat(UINT uCol);
  124. UINT GetColumnCharCount(UINT uCol);
  125. // When Loading or Saving from the View State Stream
  126. HRESULT SaveToStream(CDefView* pdv, IStream* pstm);
  127. HRESULT LoadFromStream(CDefView* pdv, IStream* pstm);
  128. HRESULT SaveToPropertyBag(CDefView* pdv, IPropertyBag* ppb);
  129. HRESULT LoadFromPropertyBag(CDefView* pdv, IPropertyBag* ppb);
  130. // When Loading from a View Callback provided stream.
  131. HRESULT LoadColumns(CDefView* pdv, IStream* pstm);
  132. HRESULT SaveColumns(CDefView* pdv, IStream* pstm);
  133. // Syncronizes ListView with the current View State.
  134. // TRUE means take the view state object and set it into the listview.
  135. HRESULT Sync(CDefView* pdv, BOOL fSetListViewState);
  136. void ClearPositionData();
  137. // Needs to be called at the time of CDefView::AddColumns
  138. BOOL SyncColumnOrder(CDefView* pdv, BOOL fSetListViewState);
  139. };
  140. #endif