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.

312 lines
8.9 KiB

  1. // PPPBag.h : Declaration of the CPropertyPagePropertyBag
  2. #ifndef __PROPERTYPAGEPROPERTYBAG_H_
  3. #define __PROPERTYPAGEPROPERTYBAG_H_
  4. #include "resource.h" // main symbols
  5. #include <map>
  6. #include <assert.h>
  7. class CBSTR_Less
  8. {
  9. public:
  10. bool operator()( BSTR p, BSTR q ) const
  11. {
  12. return (_wcsicmp( (WCHAR*)p, (WCHAR*)q ) < 0);
  13. }
  14. };
  15. class CBagEntry
  16. {
  17. private:
  18. VARIANT m_var;
  19. PPPBAG_TYPE m_dwFlags;
  20. DWORD m_dwOwner;
  21. public:
  22. CBagEntry( VARIANT * v, PPPBAG_TYPE dwFlags, DWORD dwOwner )
  23. {
  24. VariantInit( &m_var );
  25. HRESULT hr = VariantCopy( &m_var, v );
  26. assert( SUCCEEDED(hr) );
  27. m_dwFlags = dwFlags;
  28. m_dwOwner = dwOwner;
  29. }
  30. ~CBagEntry( )
  31. {
  32. VariantClear( &m_var );
  33. }
  34. VARIANT * GetVariant( ) { return &m_var; }
  35. PPPBAG_TYPE GetFlags ( ) { return m_dwFlags; }
  36. DWORD GetOwner ( ) { return m_dwOwner; }
  37. };
  38. #define PPPBAG_SYSTEM_OWNER (-1)
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CPropertyPagePropertyBag
  41. class ATL_NO_VTABLE CPropertyPagePropertyBag :
  42. public CComObjectRootEx<CComSingleThreadModel>,
  43. public CComCoClass<CPropertyPagePropertyBag, &CLSID_PropertyPagePropertyBag>,
  44. public IDispatchImpl<IPropertyCollection, &IID_IPropertyCollection, &LIBID_WIZCHAINLib>
  45. {
  46. private:
  47. BOOL m_bReadOnly;
  48. DWORD m_dwOwner; // component id
  49. std::map<BSTR, CBagEntry*, CBSTR_Less> m_map;
  50. public:
  51. CPropertyPagePropertyBag()
  52. {
  53. m_bReadOnly = FALSE;
  54. m_dwOwner = PPPBAG_SYSTEM_OWNER; // initially owned by wizard, not any component
  55. }
  56. ~CPropertyPagePropertyBag()
  57. {
  58. // free map entries
  59. std::map<BSTR, CBagEntry *, CBSTR_Less>::iterator mapiter = m_map.begin();
  60. while( mapiter != m_map.end() )
  61. {
  62. SysFreeString( mapiter->first );
  63. delete mapiter->second;
  64. mapiter++;
  65. }
  66. }
  67. DECLARE_REGISTRY_RESOURCEID(IDR_PROPERTYPAGEPROPERTYBAG)
  68. DECLARE_NOT_AGGREGATABLE(CPropertyPagePropertyBag)
  69. DECLARE_PROTECT_FINAL_CONSTRUCT()
  70. BEGIN_COM_MAP(CPropertyPagePropertyBag)
  71. COM_INTERFACE_ENTRY(IPropertyPagePropertyBag)
  72. COM_INTERFACE_ENTRY(IPropertyCollection)
  73. COM_INTERFACE_ENTRY(IDispatch)
  74. END_COM_MAP()
  75. public:
  76. // IPropertyPagePropertyBag
  77. STDMETHOD(SetProperty)( /*[in]*/ BSTR szGUID, /*[in]*/ VARIANT * pvar, /*[in]*/ PPPBAG_TYPE dwFlags );
  78. STDMETHOD(GetProperty)( /*[in]*/ BSTR szGUID, /*[out]*/ VARIANT * pvar, /*[out]*/ PPPBAG_TYPE * dwFlags, /*[out]*/ BOOL * pbIsOwner );
  79. STDMETHOD(Enumerate )( /*[in]*/ long index, /*[out]*/ BSTR * pbstr, /*[out]*/ VARIANT * pvar, /*[out]*/PPPBAG_TYPE* pdwFlags, /*[out]*/ BOOL* pbIsOwner, /*[out,retval]*/ BOOL* pbInRange );
  80. // IPropertyCollection
  81. STDMETHOD(Remove )( /*[in]*/ BSTR bstrGuid);
  82. STDMETHOD(Add )( /*[in]*/ BSTR bstrGuid, /*[in]*/ VARIANT *varValue, /*[in, optional, defaultvalue(0)]*/ long iFlags, /*[out, retval]*/ IPropertyItem **ppItem);
  83. STDMETHOD(get_Count )( /*[out, retval]*/ long *pVal);
  84. STDMETHOD(get_Item )( /*[in]*/ VARIANT * pVar, /*[out, retval]*/ IDispatch* *pVal);
  85. STDMETHOD(get__NewEnum)( /*[out, retval]*/ IUnknown* *pVal);
  86. public:
  87. void SetReadOnly( BOOL b ) { m_bReadOnly = b; }
  88. void SetOwner ( DWORD dwOwner) { m_dwOwner = dwOwner; }
  89. };
  90. class COwnerPPPBag: public IPropertyCollection
  91. {
  92. private:
  93. CPropertyPagePropertyBag * m_pPPPBag;
  94. ULONG m_refs;
  95. DWORD m_dwOwner; // component id
  96. COwnerPPPBag( CPropertyPagePropertyBag * pPPPBag, DWORD dwOwner )
  97. {
  98. assert (pPPPBag != NULL);
  99. assert (dwOwner != 0);
  100. m_pPPPBag = pPPPBag;
  101. m_dwOwner = dwOwner;
  102. m_refs = 0;
  103. }
  104. ~COwnerPPPBag( ) {}
  105. public:
  106. static IPropertyPagePropertyBag* Create( CPropertyPagePropertyBag* pCPPPBag, DWORD dwOwner )
  107. {
  108. IPropertyPagePropertyBag * pPPPBag = NULL;
  109. COwnerPPPBag * pOPPPBag = new COwnerPPPBag (pCPPPBag, dwOwner);
  110. if( pOPPPBag )
  111. {
  112. pOPPPBag->AddRef();
  113. pOPPPBag->QueryInterface (IID_IPropertyPagePropertyBag, (void**)&pPPPBag);
  114. pOPPPBag->Release();
  115. }
  116. return pPPPBag;
  117. }
  118. virtual HRESULT STDMETHODCALLTYPE QueryInterface( REFIID riid, void** ppvObject )
  119. {
  120. HRESULT hr = S_OK;
  121. if ((riid == IID_IUnknown) ||
  122. (riid == IID_IDispatch) ||
  123. (riid == IID_IPropertyCollection) ||
  124. (riid == IID_IPropertyPagePropertyBag) )
  125. {
  126. AddRef();
  127. *ppvObject = (void *)this;
  128. }
  129. else
  130. {
  131. hr = E_NOINTERFACE;
  132. }
  133. return hr;
  134. }
  135. virtual ULONG STDMETHODCALLTYPE AddRef( )
  136. {
  137. InterlockedIncrement( (PLONG)&m_refs );
  138. return m_refs;
  139. }
  140. virtual ULONG STDMETHODCALLTYPE Release( )
  141. {
  142. InterlockedDecrement( (PLONG)&m_refs );
  143. ULONG l = m_refs;
  144. if( m_refs == 0 )
  145. {
  146. delete this;
  147. }
  148. return l;
  149. }
  150. // IDispatch
  151. virtual HRESULT STDMETHODCALLTYPE GetTypeInfoCount( UINT* pctinfo )
  152. {
  153. m_pPPPBag->SetOwner( m_dwOwner );
  154. HRESULT hr = m_pPPPBag->GetTypeInfoCount( pctinfo );
  155. m_pPPPBag->SetOwner( NULL );
  156. return hr;
  157. }
  158. virtual HRESULT STDMETHODCALLTYPE GetTypeInfo( UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
  159. {
  160. m_pPPPBag->SetOwner( m_dwOwner );
  161. HRESULT hr = m_pPPPBag->GetTypeInfo( iTInfo, lcid, ppTInfo );
  162. m_pPPPBag->SetOwner( NULL );
  163. return hr;
  164. }
  165. virtual HRESULT STDMETHODCALLTYPE GetIDsOfNames( REFIID riid, LPOLESTR * rgszNames, UINT cNames, LCID lcid, DISPID * rgDispId )
  166. {
  167. m_pPPPBag->SetOwner( m_dwOwner );
  168. HRESULT hr = m_pPPPBag->GetIDsOfNames( riid, rgszNames, cNames, lcid, rgDispId );
  169. m_pPPPBag->SetOwner( NULL );
  170. return hr;
  171. }
  172. virtual HRESULT STDMETHODCALLTYPE Invoke( DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr )
  173. {
  174. m_pPPPBag->SetOwner( m_dwOwner );
  175. HRESULT hr = m_pPPPBag->Invoke( dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr );
  176. m_pPPPBag->SetOwner( NULL );
  177. return hr;
  178. }
  179. // IPropertyPagePropertyBag
  180. virtual HRESULT STDMETHODCALLTYPE SetProperty( BSTR szGUID, VARIANT* pvar, PPPBAG_TYPE dwFlags )
  181. {
  182. m_pPPPBag->SetOwner( m_dwOwner );
  183. HRESULT hr = m_pPPPBag->SetProperty( szGUID, pvar, dwFlags );
  184. m_pPPPBag->SetOwner( NULL );
  185. return hr;
  186. }
  187. virtual HRESULT STDMETHODCALLTYPE GetProperty( BSTR szGUID, VARIANT* pvar, PPPBAG_TYPE* dwFlags, BOOL* pbIsOwner )
  188. {
  189. m_pPPPBag->SetOwner( m_dwOwner );
  190. HRESULT hr = m_pPPPBag->GetProperty( szGUID, pvar, dwFlags, pbIsOwner );
  191. m_pPPPBag->SetOwner( NULL );
  192. return hr;
  193. }
  194. virtual HRESULT STDMETHODCALLTYPE Enumerate( long index, BSTR* pbstr, VARIANT* pvar, PPPBAG_TYPE* pdwFlags, BOOL* pbIsOwner, BOOL* pbInRange )
  195. {
  196. m_pPPPBag->SetOwner( m_dwOwner );
  197. HRESULT hr = m_pPPPBag->Enumerate( index, pbstr, pvar, pdwFlags, pbIsOwner, pbInRange );
  198. m_pPPPBag->SetOwner( NULL );
  199. return hr;
  200. }
  201. STDMETHOD(Remove)( /*[in]*/ BSTR bstrGuid )
  202. {
  203. m_pPPPBag->SetOwner( m_dwOwner );
  204. HRESULT hr = m_pPPPBag->Remove( bstrGuid );
  205. m_pPPPBag->SetOwner( NULL );
  206. return hr;
  207. }
  208. STDMETHOD(Add)( /*[in]*/ BSTR bstrGuid, /*[in]*/ VARIANT* varValue, /*[in, optional, defaultvalue(0)]*/ long iFlags, /*[out, retval]*/ IPropertyItem** ppItem )
  209. {
  210. m_pPPPBag->SetOwner( m_dwOwner );
  211. HRESULT hr = m_pPPPBag->Add( bstrGuid, varValue, iFlags, ppItem );
  212. m_pPPPBag->SetOwner( NULL );
  213. return hr;
  214. }
  215. STDMETHOD(get_Count)( /*[out, retval]*/ long* pVal )
  216. {
  217. m_pPPPBag->SetOwner( m_dwOwner );
  218. HRESULT hr = m_pPPPBag->get_Count( pVal );
  219. m_pPPPBag->SetOwner( NULL );
  220. return hr;
  221. }
  222. STDMETHOD(get_Item)( /*[in]*/ VARIANT* pVar, /*[out, retval]*/ IDispatch** pVal )
  223. {
  224. m_pPPPBag->SetOwner( m_dwOwner );
  225. HRESULT hr = m_pPPPBag->get_Item( pVar, pVal );
  226. m_pPPPBag->SetOwner( NULL );
  227. return hr;
  228. }
  229. STDMETHOD(get__NewEnum)( /*[out, retval]*/ IUnknown** pVal )
  230. {
  231. m_pPPPBag->SetOwner( m_dwOwner );
  232. HRESULT hr = m_pPPPBag->get__NewEnum( pVal );
  233. m_pPPPBag->SetOwner( NULL );
  234. return hr;
  235. }
  236. };
  237. #endif //__PROPERTYPAGEPROPERTYBAG_H_