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.

330 lines
8.9 KiB

  1. //+============================================================================
  2. //
  3. // File: bag.hxx
  4. //
  5. // This provides the declaration for the CPropertyBagEx class.
  6. //
  7. // History:
  8. // 3/10/98 MikeHill - Change name of STATPROPS to STATPROPBAG.
  9. // - Added support for IUnknown.
  10. // 5/6/98 MikeHill
  11. // - CPropertyBagEx now derives from IPropertyBag too.
  12. // - New DeleteMultiple method.
  13. // - VT_UNKNOWN/VT_DISPATCH support.
  14. // 5/18/98 MikeHill
  15. // - Modifed CPropertyBagEx constructors and added Init method.
  16. // 6/11/98 MikeHill
  17. // - Added the new reserved parameter to DeleteMultiple.
  18. //
  19. //+============================================================================
  20. #ifndef _BAG_HXX_
  21. #define _BAG_HXX_
  22. #include <pbagex.h> // MIDL-generated IPropertyBagEx declarations
  23. //+----------------------------------------------------------------------------
  24. //
  25. // Class: CPropertyBagEx
  26. //
  27. // This class implements the IPropertyBagEx interface, and is used in
  28. // Docfile, NSS, and NFF.
  29. //
  30. //+----------------------------------------------------------------------------
  31. class CEnumSTATPROPBAG;
  32. class CPropertyBagEx : public IPropertyBagEx, public IPropertyBag
  33. {
  34. // --------------
  35. // Internal state
  36. // --------------
  37. private:
  38. BOOL _fLcidInitialized:1;
  39. LCID _lcid;
  40. // This IPropertySetStorage is the container for the property bag
  41. IPropertySetStorage *_ppropsetstgContainer;
  42. // This IPropertyStorage actually holds the property bag
  43. IPropertyStorage *_ppropstg;
  44. IBlockingLock *_pBlockingLock;
  45. DWORD _grfMode;
  46. // This reference count is only used if we have no _ppropsetstgParent.
  47. // Whether or not we have this parent depends on which constructor is called.
  48. // If we have one, we forward all IUnknown calls to it. Otherwise, we use
  49. // CPropertyBagEx's own implementation.
  50. LONG _cRefs;
  51. // ------------
  52. // Construction
  53. // ------------
  54. public:
  55. // Normal constructur
  56. CPropertyBagEx( DWORD grfMode );
  57. void Init( IPropertySetStorage *ppropsetstg, IBlockingLock *pBlockingLock ); // No Addrefs
  58. // Constructor for building an IPropertyBagEx on top of an IPropertyStorage
  59. CPropertyBagEx( DWORD grfMode,
  60. IPropertyStorage *ppropstg, // Addref-ed
  61. IBlockingLock *pBlockingLock ); // Addref-ed
  62. ~CPropertyBagEx();
  63. // --------
  64. // IUnknown
  65. // --------
  66. public:
  67. HRESULT STDMETHODCALLTYPE QueryInterface(
  68. /* [in] */ REFIID riid,
  69. /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject);
  70. ULONG STDMETHODCALLTYPE AddRef( void);
  71. ULONG STDMETHODCALLTYPE Release( void);
  72. // ------------
  73. // IPropertyBag
  74. // ------------
  75. HRESULT STDMETHODCALLTYPE Read(
  76. /* [in] */ LPCOLESTR pszPropName,
  77. /* [out][in] */ VARIANT __RPC_FAR *pVar,
  78. /* [in] */ IErrorLog __RPC_FAR *pErrorLog);
  79. HRESULT STDMETHODCALLTYPE Write(
  80. /* [in] */ LPCOLESTR pszPropName,
  81. /* [in] */ VARIANT __RPC_FAR *pVar);
  82. // --------------
  83. // IPropertyBagEx
  84. // --------------
  85. public:
  86. HRESULT STDMETHODCALLTYPE ReadMultiple(
  87. /* [in] */ ULONG cprops,
  88. /* [size_is][in] */ LPCOLESTR const __RPC_FAR rgoszPropNames[ ],
  89. /* [size_is][out][in] */ PROPVARIANT __RPC_FAR rgpropvar[ ],
  90. /* [in] */ IErrorLog __RPC_FAR *pErrorLog);
  91. HRESULT STDMETHODCALLTYPE WriteMultiple(
  92. /* [in] */ ULONG cprops,
  93. /* [size_is][in] */ LPCOLESTR const __RPC_FAR rgoszPropNames[ ],
  94. /* [size_is][in] */ const PROPVARIANT __RPC_FAR rgpropvar[ ]);
  95. HRESULT STDMETHODCALLTYPE DeleteMultiple(
  96. /*[in]*/ ULONG cprops,
  97. /*[in]*/ LPCOLESTR const rgoszPropNames[],
  98. /*[in]*/ DWORD dwReserved );
  99. HRESULT STDMETHODCALLTYPE Open(
  100. /* [in] */ IUnknown __RPC_FAR *pUnkOuter,
  101. /* [in] */ LPCOLESTR pwszPropName,
  102. /* [in] */ GUID guidPropertyType,
  103. /* [in] */ DWORD dwFlags,
  104. /* [in] */ REFIID riid,
  105. /* [out] */ IUnknown __RPC_FAR *__RPC_FAR *ppUnk);
  106. HRESULT STDMETHODCALLTYPE Enum(
  107. /* [in] */ LPCOLESTR poszPropNameMask,
  108. /* [in] */ DWORD dwFlags,
  109. /* [out] */ IEnumSTATPROPBAG __RPC_FAR *__RPC_FAR *ppenum);
  110. // ---------------------
  111. // Non-Interface Methods
  112. // ---------------------
  113. public:
  114. HRESULT Commit( DWORD grfCommitFlags );
  115. HRESULT ShutDown();
  116. // ----------------
  117. // Internal Methods
  118. // ----------------
  119. private:
  120. HRESULT OpenPropStg( DWORD dwDisposition ); // FILE_OPEN, FILE_OPEN_IF
  121. HRESULT GetLCID();
  122. BOOL IsReadable();
  123. BOOL IsWriteable();
  124. BOOL PropertyRequiresConversion( VARTYPE vt );
  125. HRESULT WriteObjects( IN ULONG cprops, IN const PROPSPEC rgpropspec[], IN const PROPVARIANT rgvar[] );
  126. HRESULT WriteOneObject( IN const PROPSPEC *ppropspec, IN const PROPVARIANT *pvar );
  127. HRESULT LoadObject( OUT PROPVARIANT *ppropvarOut, IN PROPVARIANT *ppropvarIn ) const;
  128. }; // class CPropertyBagEx
  129. inline BOOL
  130. CPropertyBagEx::IsWriteable()
  131. {
  132. return( ::GrfModeIsWriteable( _grfMode ));
  133. }
  134. inline BOOL
  135. CPropertyBagEx::IsReadable()
  136. {
  137. return( ::GrfModeIsReadable( _grfMode ));
  138. }
  139. // Does this interface type require conversion via IPersist?
  140. inline BOOL
  141. CPropertyBagEx::PropertyRequiresConversion( VARTYPE vt )
  142. {
  143. return( VT_UNKNOWN == (~VT_BYREF & vt)
  144. ||
  145. VT_DISPATCH == (~VT_BYREF & vt) );
  146. }
  147. //+----------------------------------------------------------------------------
  148. //
  149. // Class: CSTATPROPBAGArray
  150. //
  151. // This class is used by the CEnumSTATPROPBAG class. This array class
  152. // is responsible for enumeration of the properties, the CEnumSTATPROPBAG
  153. // class is responsible for maintaining the index. Thus, a single
  154. // CSTATPROPBAGArray object can be used by multiple enumerators
  155. // (e.g., when an enumerator is cloned).
  156. //
  157. //+----------------------------------------------------------------------------
  158. class CSTATPROPBAGArray
  159. {
  160. public:
  161. CSTATPROPBAGArray( IBlockingLock *pBlockingLock );
  162. ~CSTATPROPBAGArray();
  163. HRESULT Init( IPropertyStorage *ppropstg, const OLECHAR *poszPrefix, DWORD dwFlags );
  164. public:
  165. ULONG AddRef();
  166. ULONG Release();
  167. HRESULT NextAt( ULONG iNext, STATPROPBAG *prgSTATPROPBAG, ULONG *pcFetched );
  168. private:
  169. LONG _cReferences;
  170. IEnumSTATPROPSTG *_penum;
  171. IBlockingLock *_pBlockingLock;
  172. OLECHAR *_poszPrefix;
  173. DWORD _dwFlags; // ENUMPROPERTY_* enumeration
  174. }; // class CSTATPROPBAGArray
  175. inline
  176. CSTATPROPBAGArray::CSTATPROPBAGArray( IBlockingLock *pBlockingLock )
  177. {
  178. _cReferences = 1;
  179. _penum = NULL;
  180. _poszPrefix = NULL;
  181. _pBlockingLock = pBlockingLock;
  182. _pBlockingLock->AddRef();
  183. }
  184. inline
  185. CSTATPROPBAGArray::~CSTATPROPBAGArray()
  186. {
  187. if( NULL != _penum )
  188. _penum->Release();
  189. _penum = NULL;
  190. CoTaskMemFree( _poszPrefix );
  191. _poszPrefix = NULL;
  192. DfpAssert( NULL != _pBlockingLock );
  193. _pBlockingLock->Release();
  194. _pBlockingLock = NULL;
  195. }
  196. //+----------------------------------------------------------------------------
  197. //
  198. // Class: CEnumSTATPROPBAG
  199. //
  200. // This class implements the enumerator (IEnumSTATPROPBAG) for a property bag.
  201. // A CSTATPROPBAGArray object is used to contain the actual properties,
  202. // CEnumSTATPROPBAG is only responsible for maintaining an index.
  203. //
  204. //+----------------------------------------------------------------------------
  205. class CEnumSTATPROPBAG : public IEnumSTATPROPBAG
  206. {
  207. public:
  208. CEnumSTATPROPBAG( IBlockingLock *pBlockingLock );
  209. CEnumSTATPROPBAG( const CEnumSTATPROPBAG &Other );
  210. ~CEnumSTATPROPBAG();
  211. HRESULT Init( IPropertyStorage *ppropstg, LPCOLESTR poszPrefix, DWORD dwFlags );
  212. public:
  213. HRESULT STDMETHODCALLTYPE QueryInterface( REFIID riid, void **ppvObject );
  214. ULONG STDMETHODCALLTYPE AddRef();
  215. ULONG STDMETHODCALLTYPE Release();
  216. public:
  217. HRESULT STDMETHODCALLTYPE Next(
  218. /* [in] */ ULONG celt,
  219. /* [length_is][size_is][out] */ STATPROPBAG __RPC_FAR *rgelt,
  220. /* [out] */ ULONG __RPC_FAR *pceltFetched);
  221. HRESULT STDMETHODCALLTYPE Skip(
  222. /* [in] */ ULONG celt);
  223. HRESULT STDMETHODCALLTYPE Reset( void);
  224. HRESULT STDMETHODCALLTYPE Clone(
  225. /* [out] */ IEnumSTATPROPBAG __RPC_FAR *__RPC_FAR *ppenum);
  226. private:
  227. LONG _cRefs;
  228. IBlockingLock *_pBlockingLock;
  229. CSTATPROPBAGArray *_parray;
  230. ULONG _iarray;
  231. }; // class CEnumSTATPROPBAG
  232. inline
  233. CEnumSTATPROPBAG::CEnumSTATPROPBAG( IBlockingLock *pBlockingLock )
  234. {
  235. _cRefs = 1;
  236. _parray = NULL;
  237. _iarray = 0;
  238. _pBlockingLock = pBlockingLock;
  239. _pBlockingLock->AddRef();
  240. }
  241. #endif // #ifndef _BAG_HXX_