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.

405 lines
11 KiB

  1. #ifndef dxatlpb_h
  2. #define dxatlpb_h
  3. #include <atlctl.h>
  4. #ifndef DXTDbg_h
  5. #include <dxtdbg.h>
  6. #endif
  7. #define COM_INTERFACE_ENTRY_DXIMPL(x)\
  8. COM_INTERFACE_ENTRY_IID(IID_##x, x##DXImpl<_ComMapClass>)
  9. /*** IOleObjectDXImpl
  10. * This is a simplified version used to allow a transform
  11. * to be hosted by IE
  12. */
  13. template <class T>
  14. class ATL_NO_VTABLE IOleObjectDXImpl
  15. {
  16. public:
  17. // IUnknown
  18. //
  19. STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObject) = 0;
  20. STDMETHOD_(ULONG,AddRef)() = 0;
  21. STDMETHOD_(ULONG,Release)() = 0;
  22. // IOleObject
  23. //
  24. STDMETHOD(SetClientSite)(IOleClientSite *pClientSite)
  25. {
  26. DXTDBG_FUNC( "IOleObjectDXImpl::SetClientSite" );
  27. HRESULT hr = S_OK;
  28. if( pClientSite && DXIsBadInterfacePtr( pClientSite ) )
  29. {
  30. hr = E_INVALIDARG;
  31. }
  32. else
  33. {
  34. T* pT = static_cast<T*>(this);
  35. pT->m_cpOleClientSite = pClientSite;
  36. }
  37. return hr;
  38. }
  39. STDMETHOD(GetClientSite)(IOleClientSite **ppClientSite)
  40. {
  41. DXTDBG_FUNC( "IOleObjectDXImpl::GetClientSite" );
  42. HRESULT hr = S_OK;
  43. if( DXIsBadWritePtr( ppClientSite, sizeof( *ppClientSite )) )
  44. {
  45. hr = E_POINTER;
  46. }
  47. else
  48. {
  49. T* pT = static_cast<T*>(this);
  50. *ppClientSite = pT->m_cpOleClientSite;
  51. }
  52. return hr;
  53. }
  54. STDMETHOD(SetHostNames)(LPCOLESTR /* szContainerApp */, LPCOLESTR /* szContainerObj */)
  55. {
  56. DXTDBG_FUNC( "IOleObjectDXImpl::SetHostNames" );
  57. return S_OK;
  58. }
  59. STDMETHOD(Close)(DWORD dwSaveOption)
  60. {
  61. DXTDBG_FUNC( "IOleObjectDXImpl::Close" );
  62. return S_OK;
  63. }
  64. STDMETHOD(SetMoniker)(DWORD /* dwWhichMoniker */, IMoniker* /* pmk */)
  65. {
  66. DXTDBG_FUNC( "IOleObjectDXImpl::SetMoniker" );
  67. return E_NOTIMPL;
  68. }
  69. STDMETHOD(GetMoniker)(DWORD /* dwAssign */, DWORD /* dwWhichMoniker */, IMoniker** /* ppmk */)
  70. {
  71. DXTDBG_FUNC( "IOleObjectDXImpl::GetMoniker" );
  72. return E_NOTIMPL;
  73. }
  74. STDMETHOD(InitFromData)(IDataObject* /* pDataObject */, BOOL /* fCreation */, DWORD /* dwReserved */)
  75. {
  76. DXTDBG_FUNC( "IOleObjectDXImpl::InitFromData" );
  77. return E_NOTIMPL;
  78. }
  79. STDMETHOD(GetClipboardData)(DWORD /* dwReserved */, IDataObject** /* ppDataObject */)
  80. {
  81. DXTDBG_FUNC( "IOleObjectDXImpl::GetClipboardData" );
  82. return E_NOTIMPL;
  83. }
  84. STDMETHOD(DoVerb)(LONG iVerb, LPMSG /* lpmsg */, IOleClientSite* /* pActiveSite */, LONG /* lindex */,
  85. HWND hwndParent, LPCRECT lprcPosRect)
  86. {
  87. DXTDBG_FUNC( "IOleObjectDXImpl::DoVerb" );
  88. return S_OK;
  89. }
  90. STDMETHOD(EnumVerbs)(IEnumOLEVERB **ppEnumOleVerb)
  91. {
  92. DXTDBG_FUNC( "IOleObjectDXImpl::DoVerb" );
  93. return OLEOBJ_E_NOVERBS;
  94. }
  95. STDMETHOD(Update)(void)
  96. {
  97. DXTDBG_FUNC( "IOleObjectDXImpl::Update" );
  98. return S_OK;
  99. }
  100. STDMETHOD(IsUpToDate)(void)
  101. {
  102. DXTDBG_FUNC( "IOleObjectDXImpl::IsUpToDate" );
  103. return S_OK;
  104. }
  105. STDMETHOD(GetUserClassID)(CLSID *pClsid)
  106. {
  107. DXTDBG_FUNC( "IOleObjectDXImpl::GetUserClassID" );
  108. _ASSERTE(pClsid);
  109. if( DXIsBadWritePtr( pClsid, sizeof( *pClsid ) ) )
  110. {
  111. return E_POINTER;
  112. }
  113. else
  114. {
  115. *pClsid = T::GetObjectCLSID();
  116. return S_OK;
  117. }
  118. }
  119. STDMETHOD(GetUserType)(DWORD dwFormOfType, LPOLESTR *pszUserType)
  120. {
  121. DXTDBG_FUNC( "IOleObjectDXImpl::GetUserType" );
  122. return OLE_S_USEREG;
  123. }
  124. STDMETHOD(SetExtent)(DWORD dwDrawAspect, SIZEL *psizel)
  125. {
  126. DXTDBG_FUNC( "IOleObjectDXImpl::SetExtent" );
  127. return S_OK;
  128. }
  129. STDMETHOD(GetExtent)(DWORD dwDrawAspect, SIZEL *psizel)
  130. {
  131. DXTDBG_FUNC( "IOleObjectDXImpl::GetExtent" );
  132. HRESULT hr = S_OK;
  133. if( DXIsBadWritePtr( psizel, sizeof( *psizel ) ) )
  134. {
  135. hr = E_POINTER;
  136. }
  137. else
  138. {
  139. psizel->cx = 0;
  140. psizel->cy = 0;
  141. }
  142. return hr;
  143. }
  144. STDMETHOD(Advise)(IAdviseSink *pAdvSink, DWORD *pdwConnection)
  145. {
  146. DXTDBG_FUNC( "IOleObjectDXImpl::Advise" );
  147. return S_OK;
  148. }
  149. STDMETHOD(Unadvise)(DWORD dwConnection)
  150. {
  151. DXTDBG_FUNC( "IOleObjectDXImpl::Unadvise" );
  152. return S_OK;
  153. }
  154. STDMETHOD(EnumAdvise)(IEnumSTATDATA **ppenumAdvise)
  155. {
  156. DXTDBG_FUNC( "IOleObjectDXImpl::EnumAdvise" );
  157. return E_FAIL;
  158. }
  159. STDMETHOD(GetMiscStatus)(DWORD dwAspect, DWORD *pdwStatus)
  160. {
  161. DXTDBG_FUNC( "IOleObjectDXImpl::GetMiscStatus" );
  162. return OLE_S_USEREG;
  163. }
  164. STDMETHOD(SetColorScheme)(LOGPALETTE* /* pLogpal */)
  165. {
  166. DXTDBG_FUNC( "IOleObjectDXImpl::SetColorScheme" );
  167. return E_NOTIMPL;
  168. }
  169. };
  170. /*** CComPropBase
  171. *
  172. */
  173. class ATL_NO_VTABLE CComPropBase
  174. {
  175. public:
  176. HRESULT IPersistPropertyBag_Load(LPPROPERTYBAG pPropBag,
  177. LPERRORLOG pErrorLog, ATL_PROPMAP_ENTRY* pMap)
  178. {
  179. USES_CONVERSION;
  180. CComPtr<IDispatch> pDispatch;
  181. const IID* piidOld = NULL;
  182. for(int i = 0; pMap[i].pclsidPropPage != NULL; i++)
  183. {
  184. if (pMap[i].szDesc == NULL)
  185. continue;
  186. CComVariant var;
  187. if(pMap[i].piidDispatch != piidOld)
  188. {
  189. pDispatch.Release();
  190. if(FAILED(PropQueryInterface(*pMap[i].piidDispatch, (void**)&pDispatch)))
  191. {
  192. ATLTRACE(_T("Failed to get a dispatch pointer for property #%i\n"), i);
  193. return E_FAIL;
  194. }
  195. piidOld = pMap[i].piidDispatch;
  196. }
  197. if (FAILED(CComDispatchDriver::GetProperty(pDispatch, pMap[i].dispid, &var)))
  198. {
  199. ATLTRACE(_T("Invoked failed on DISPID %x\n"), pMap[i].dispid);
  200. return E_FAIL;
  201. }
  202. HRESULT hr = pPropBag->Read(pMap[i].szDesc, &var, pErrorLog);
  203. if (FAILED(hr))
  204. {
  205. if (hr == E_INVALIDARG)
  206. {
  207. ATLTRACE(_T("Property %s not in Bag\n"), OLE2CT(pMap[i].szDesc));
  208. }
  209. else
  210. {
  211. // Many containers return different ERROR values for Member not found
  212. ATLTRACE(_T("Error attempting to read Property %s from PropertyBag \n"), OLE2CT(pMap[i].szDesc));
  213. }
  214. continue;
  215. }
  216. if (FAILED(CComDispatchDriver::PutProperty(pDispatch, pMap[i].dispid, &var)))
  217. {
  218. ATLTRACE(_T("Invoked failed on DISPID %x\n"), pMap[i].dispid);
  219. return E_FAIL;
  220. }
  221. }
  222. return S_OK;
  223. }
  224. HRESULT IPersistPropertyBag_Save(LPPROPERTYBAG pPropBag,
  225. BOOL fClearDirty, BOOL /*fSaveAllProperties*/, ATL_PROPMAP_ENTRY* pMap)
  226. {
  227. if (pPropBag == NULL)
  228. {
  229. ATLTRACE(_T("PropBag pointer passed in was invalid\n"));
  230. return E_POINTER;
  231. }
  232. CComPtr<IDispatch> pDispatch;
  233. const IID* piidOld = NULL;
  234. for(int i = 0; pMap[i].pclsidPropPage != NULL; i++)
  235. {
  236. if (pMap[i].szDesc == NULL)
  237. continue;
  238. CComVariant var;
  239. if(pMap[i].piidDispatch != piidOld)
  240. {
  241. pDispatch.Release();
  242. if(FAILED(PropQueryInterface(*pMap[i].piidDispatch, (void**)&pDispatch)))
  243. {
  244. ATLTRACE(_T("Failed to get a dispatch pointer for property #%i\n"), i);
  245. return E_FAIL;
  246. }
  247. piidOld = pMap[i].piidDispatch;
  248. }
  249. if (FAILED(CComDispatchDriver::GetProperty(pDispatch, pMap[i].dispid, &var)))
  250. {
  251. ATLTRACE(_T("Invoked failed on DISPID %x\n"), pMap[i].dispid);
  252. return E_FAIL;
  253. }
  254. if (var.vt == VT_UNKNOWN || var.vt == VT_DISPATCH)
  255. {
  256. if (var.punkVal == NULL)
  257. {
  258. ATLTRACE(_T("Warning skipping empty IUnknown in Save\n"));
  259. continue;
  260. }
  261. }
  262. HRESULT hr = pPropBag->Write(pMap[i].szDesc, &var);
  263. if (FAILED(hr))
  264. return hr;
  265. }
  266. m_bRequiresSave = FALSE;
  267. return S_OK;
  268. }
  269. HRESULT ISpecifyPropertyPages_GetPages(CAUUID* pPages,
  270. ATL_PROPMAP_ENTRY* pMap)
  271. {
  272. _ASSERTE(pMap != NULL);
  273. int nCnt = 0;
  274. // Get count of unique pages
  275. for(int i = 0; pMap[i].pclsidPropPage != NULL; i++)
  276. {
  277. if (!InlineIsEqualGUID(*pMap[i].pclsidPropPage, CLSID_NULL))
  278. nCnt++;
  279. }
  280. pPages->pElems = NULL;
  281. pPages->pElems = (GUID*) CoTaskMemAlloc(sizeof(CLSID)*nCnt);
  282. if (pPages->pElems == NULL)
  283. return E_OUTOFMEMORY;
  284. nCnt = 0;
  285. for(i = 0; pMap[i].pclsidPropPage != NULL; i++)
  286. {
  287. if (!InlineIsEqualGUID(*pMap[i].pclsidPropPage, CLSID_NULL))
  288. {
  289. BOOL bMatch = FALSE;
  290. for (int j=0;j<nCnt;j++)
  291. {
  292. if (InlineIsEqualGUID(*(pMap[i].pclsidPropPage), pPages->pElems[j]))
  293. {
  294. bMatch = TRUE;
  295. break;
  296. }
  297. }
  298. if (!bMatch)
  299. pPages->pElems[nCnt++] = *pMap[i].pclsidPropPage;
  300. }
  301. }
  302. pPages->cElems = nCnt;
  303. return S_OK;
  304. }
  305. virtual HRESULT PropQueryInterface(const IID& iid, void** ppv) = 0;
  306. BOOL m_bRequiresSave;
  307. };
  308. template <class T>
  309. class ATL_NO_VTABLE CComPropertySupport : public CComPropBase
  310. {
  311. public:
  312. virtual HRESULT PropQueryInterface(const IID& iid, void** ppv)
  313. {
  314. T* pT = static_cast<T*>(this);
  315. return pT->_InternalQueryInterface(iid, ppv);
  316. }
  317. };
  318. //////////////////////////////////////////////////////////////////////////////
  319. // IObjectSafety
  320. //
  321. template <class T>
  322. class ATL_NO_VTABLE IObjectSafetyImpl2
  323. {
  324. public:
  325. DWORD m_dwSafety[4];
  326. const IID *m_pIID[4];
  327. IObjectSafetyImpl2()
  328. {
  329. m_pIID[0] = &IID_IDispatch;
  330. m_pIID[1] = &IID_IPersistPropertyBag;
  331. m_pIID[2] = &IID_IPersistStorage;
  332. m_pIID[3] = &IID_IPersistStream;
  333. for (int i = 0; i < 4; i++)
  334. {
  335. m_dwSafety[i] = 0;
  336. }
  337. }
  338. // IUnknown
  339. //
  340. STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObject) = 0;
  341. _ATL_DEBUG_ADDREF_RELEASE_IMPL(IObjectSafetyImpl2)
  342. // IObjectSafety
  343. //
  344. STDMETHOD(GetInterfaceSafetyOptions)(REFIID riid, DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
  345. {
  346. ATLTRACE(_T("IObjectSafetyImpl::GetInterfaceSafetyOptions\n"));
  347. if (pdwSupportedOptions == NULL || pdwEnabledOptions == NULL)
  348. return E_POINTER;
  349. for (int i = 0; i < 4 && m_pIID[i]; i++)
  350. {
  351. if (riid == *m_pIID[i]) {
  352. *pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER;
  353. *pdwEnabledOptions = m_dwSafety[i] & INTERFACESAFE_FOR_UNTRUSTED_CALLER;
  354. return S_OK;
  355. }
  356. }
  357. *pdwSupportedOptions = 0;
  358. *pdwEnabledOptions = 0;
  359. return E_NOINTERFACE;
  360. }
  361. STDMETHOD(SetInterfaceSafetyOptions)(REFIID riid, DWORD dwOptionSetMask, DWORD dwEnabledOptions)
  362. {
  363. ATLTRACE(_T("IObjectSafetyImpl::SetInterfaceSafetyOptions\n"));
  364. // If we're being asked to set our safe for scripting option then oblige
  365. for (int i = 0; i < 4 && m_pIID[i]; i++)
  366. {
  367. if (riid == *m_pIID[i]) {
  368. m_dwSafety[i] = dwEnabledOptions & dwOptionSetMask;
  369. return S_OK;
  370. }
  371. }
  372. return E_NOINTERFACE;
  373. }
  374. };
  375. #endif // This must be the last line in the file