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.

276 lines
7.5 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  5. //
  6. // File: expst.hxx
  7. //
  8. // Contents: CExposedStream definition
  9. //
  10. // Classes: CExposedStream
  11. //
  12. // Notes:
  13. // The CExposedStream class is the implementation
  14. // of IStream. It also inherits from CMappedStream and provides
  15. // the neccessary virtual functions to handle property set
  16. // functions.
  17. //
  18. // Note that this interface is solely UNICODE, the ASCII layer
  19. // support which is present if _UNICODE is not defined, provides
  20. // the overloaded functions that handles the ASCII to Unicode
  21. // conversion.
  22. //
  23. //--------------------------------------------------------------------------
  24. #ifndef __EXPST_HXX__
  25. #define __EXPST_HXX__
  26. #include "h/dfmsp.hxx"
  27. #include "expdf.hxx"
  28. #include "h/sstream.hxx"
  29. #ifdef NEWPROPS
  30. #include "props/h/windef.h"
  31. #include "h/propstm.hxx"
  32. #endif // NEWPROPS
  33. interface ILockBytes;
  34. class CMappedStream;
  35. //+--------------------------------------------------------------
  36. //
  37. // Class: CExposedStream (est)
  38. //
  39. // Purpose: Exposed stream interface
  40. //
  41. // Interface: See below
  42. //
  43. // Note: PRevertable is a general virtual class base that
  44. // handles updates to the storage elements. E.g.
  45. // when an IStorage parent is deleted, the children
  46. // underneadth them will have the reverted state.
  47. //
  48. //---------------------------------------------------------------
  49. interface CExposedStream
  50. : public IStream,
  51. #ifdef NEWPROPS
  52. public CMappedStream,
  53. #endif
  54. public PRevertable
  55. {
  56. public:
  57. CExposedStream();
  58. SCODE Init(CDirectStream *pst,
  59. CExposedDocFile* pdfParent,
  60. const DFLAGS df,
  61. const CDfName *pdfn,
  62. const ULONG ulPos);
  63. inline ~CExposedStream(void);
  64. // From IUnknown
  65. STDMETHOD(QueryInterface)(REFIID iid, void **ppvObj);
  66. STDMETHOD_(ULONG,AddRef)(void);
  67. STDMETHOD_(ULONG,Release)(void);
  68. // IStream
  69. STDMETHOD(Read)(VOID HUGEP *pv,
  70. ULONG cb,
  71. ULONG *pcbRead);
  72. STDMETHOD(Write)(VOID const HUGEP *pv,
  73. ULONG cb,
  74. ULONG *pcbWritten);
  75. STDMETHOD(Seek)(LARGE_INTEGER dlibMove,
  76. DWORD dwOrigin,
  77. ULARGE_INTEGER *plibNewPosition);
  78. STDMETHOD(SetSize)(ULARGE_INTEGER cb);
  79. STDMETHOD(CopyTo)(IStream *pstm,
  80. ULARGE_INTEGER cb,
  81. ULARGE_INTEGER *pcbRead,
  82. ULARGE_INTEGER *pcbWritten);
  83. STDMETHOD(Commit)(DWORD grfCommitFlags);
  84. STDMETHOD(Revert)(void);
  85. STDMETHOD(LockRegion)(ULARGE_INTEGER libOffset,
  86. ULARGE_INTEGER cb,
  87. DWORD dwLockType);
  88. STDMETHOD(UnlockRegion)(ULARGE_INTEGER libOffset,
  89. ULARGE_INTEGER cb,
  90. DWORD dwLockType);
  91. #ifndef _UNICODE
  92. STDMETHOD(Stat)(STATSTG *pstatstg, DWORD grfStatFlag);
  93. #endif
  94. STDMETHOD_(SCODE,Stat)(STATSTGW *pstatstg, DWORD grfStatFlag);
  95. STDMETHOD(Clone)(IStream **ppstm);
  96. #ifdef NEWPROPS
  97. public:
  98. VOID Open(/*IN*/ VOID *powner, /*OUT*/ LONG *phr);
  99. VOID Close(/* OUT */ LONG *phr);
  100. VOID ReOpen(/*IN OUT*/ VOID **ppv, /*OUT*/ LONG *phr);
  101. VOID Quiesce(VOID);
  102. VOID Map(BOOLEAN fCreate, VOID **ppv);
  103. VOID Unmap(BOOLEAN fFlush, VOID **pv);
  104. VOID Flush(/*OUT*/ LONG *phr);
  105. ULONG GetSize( /*OUT*/ LONG *phr);
  106. VOID SetSize(ULONG cb, BOOLEAN fPersistent, VOID **ppv,
  107. /*OUT*/ LONG *phr);
  108. VOID QueryTimeStamps(STATPROPSETSTG *pspss, BOOLEAN fNonSimple) const;
  109. BOOLEAN QueryModifyTime(/*OUT*/ LONGLONG *pll) const;
  110. BOOLEAN QuerySecurity(/*OUT*/ ULONG *pul) const;
  111. BOOLEAN IsWriteable(VOID) const;
  112. BOOLEAN IsModified(VOID) const;
  113. VOID SetModified(VOID);
  114. HANDLE GetHandle(VOID) const;
  115. #if DBGPROP
  116. BOOLEAN SetChangePending(BOOLEAN fChangePending);
  117. BOOLEAN IsNtMappedStream(VOID) const;
  118. #endif // #if DBGPROP
  119. #if DBG
  120. inline ULONG BytesCommitted(VOID) { return _cbUsed; }
  121. VOID DfpdbgFillUnusedMemory(VOID);
  122. VOID DfpdbgCheckUnusedMemory(VOID);
  123. #else
  124. VOID DfpdbgFillUnusedMemory(VOID) {}
  125. VOID DfpdbgCheckUnusedMemory(VOID) {}
  126. #endif // DBG
  127. private:
  128. HRESULT Write(VOID);
  129. #endif // #ifdef NEWPROPS
  130. public:
  131. inline SCODE Validate(void) const;
  132. inline CDirectStream *GetDirectStream(void) const;
  133. inline SCODE GetSize(ULONG *pcb);
  134. SCODE SetSize(ULONG cb);
  135. inline void SetDirty(void)
  136. { _fDirty = TRUE; }
  137. // PRevertable
  138. virtual void RevertFromAbove(void);
  139. inline SCODE CheckReverted(void) const;
  140. #ifdef NEWPROPS
  141. virtual SCODE FlushBufferedData();
  142. #endif
  143. private:
  144. CDirectStream *_pst;
  145. CExposedDocFile *_pdfParent;
  146. ULONG _ulAccessLockBase;
  147. ULONG _sig;
  148. LONG _cReferences;
  149. ULONG _ulPos;
  150. BOOL _fDirty;
  151. #ifdef NEWPROPS
  152. private:
  153. BYTE *_pb;
  154. BYTE *_powner; // owner of this mapped stream
  155. ULONG _cbUsed;
  156. ULONG _cbOriginalStreamSize;
  157. BOOL _fChangePending;
  158. #endif
  159. };
  160. #define CEXPOSEDSTREAM_SIG LONGSIG('E', 'X', 'S', 'T')
  161. #define CEXPOSEDSTREAM_SIGDEL LONGSIG('E', 'x', 'S', 't')
  162. //+--------------------------------------------------------------
  163. //
  164. // Member: CExposedStream::Validate, public
  165. //
  166. // Synopsis: Validates the object signature
  167. //
  168. // Returns: Returns STG_E_INVALIDHANDLE for bad signatures
  169. //
  170. //---------------------------------------------------------------
  171. inline SCODE CExposedStream::Validate(void) const
  172. {
  173. return (this == NULL || _sig != CEXPOSEDSTREAM_SIG) ?
  174. STG_E_INVALIDHANDLE : S_OK;
  175. }
  176. //+--------------------------------------------------------------
  177. //
  178. // Member: CExposedStream::GetPub, public
  179. //
  180. // Synopsis: Returns the public
  181. //
  182. //---------------------------------------------------------------
  183. inline CDirectStream *CExposedStream::GetDirectStream(void) const
  184. {
  185. return _pst;
  186. }
  187. //+--------------------------------------------------------------
  188. //
  189. // Member: CExposedStream::GetSize, public
  190. //
  191. // Synopsis: Gets the size of the stream
  192. //
  193. // Arguments: [pcb] - Stream size return
  194. //
  195. // Returns: Appropriate status code
  196. //
  197. // Modifies: [pcb]
  198. //
  199. //---------------------------------------------------------------
  200. inline SCODE CExposedStream::GetSize(ULONG *pcb)
  201. {
  202. SCODE sc;
  203. if (SUCCEEDED(sc = CheckReverted()))
  204. _pst->GetSize(pcb);
  205. return sc;
  206. }
  207. //+--------------------------------------------------------------
  208. //
  209. // Member: CExposedStream::CheckReverted, public
  210. //
  211. // Synopsis: Returns revertedness
  212. //
  213. //---------------------------------------------------------------
  214. inline SCODE CExposedStream::CheckReverted(void) const
  215. {
  216. return P_REVERTED(_df) ? STG_E_REVERTED : S_OK;
  217. }
  218. //+--------------------------------------------------------------
  219. //
  220. // Member: CExposedStream::~CExposedStream, public
  221. //
  222. // Synopsis: Destructor
  223. //
  224. // Returns: Appropriate status code
  225. ////---------------------------------------------------------------
  226. inline CExposedStream::~CExposedStream(void)
  227. {
  228. olDebugOut((DEB_ITRACE, "In CExposedStream::~CExposedStream\n"));
  229. olAssert(_cReferences == 0);
  230. _sig = CEXPOSEDSTREAM_SIGDEL;
  231. if (SUCCEEDED(CheckReverted()))
  232. {
  233. if (_pdfParent) _pdfParent->ReleaseChild(this);
  234. if (_pst) _pst->Release();
  235. }
  236. #ifdef NEWPROPS
  237. delete[] _pb;
  238. _pb = NULL;
  239. _powner = NULL;
  240. #endif
  241. olDebugOut((DEB_ITRACE, "Out CExposedStream::~CExposedStream\n"));
  242. }
  243. #endif // #ifndef __EXPST_HXX__