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.

284 lines
7.7 KiB

  1. //------------------------------------------------------------------------------
  2. // ioleobj.cpp
  3. // Copyright (c)1997-1999 Microsoft Corporation, All Rights Reserved
  4. //
  5. // Author
  6. // bash
  7. //
  8. // History
  9. // 6-27-97 created (bash)
  10. //
  11. // Implementation of IOleObject.
  12. //
  13. // We mostly just delegate to Trident's IOleObject, except
  14. // for GetUserClassID and GetUserType. We also cache the
  15. // host's clientsite and uihandler interfaces in SetClientSite.
  16. //------------------------------------------------------------------------------
  17. #include "stdafx.h"
  18. #include "triedit.h"
  19. #include "document.h"
  20. STDMETHODIMP CTriEditDocument::SetClientSite(IOleClientSite *pClientSite)
  21. {
  22. ATLTRACE(_T("IOleObjectImpl::SetClientSite\n"));
  23. HRESULT hr;
  24. ICustomDoc *pCustomDoc = NULL;
  25. _ASSERTE(m_pOleObjTrident);
  26. SAFERELEASE(m_pClientSiteHost);
  27. SAFERELEASE(m_pUIHandlerHost);
  28. SAFERELEASE(m_pDragDropHandlerHost);
  29. m_pClientSiteHost = pClientSite;
  30. if (NULL != m_pClientSiteHost)
  31. {
  32. m_pClientSiteHost->AddRef();
  33. m_pClientSiteHost->QueryInterface(IID_IDocHostUIHandler, (void **) &m_pUIHandlerHost);
  34. m_pClientSiteHost->QueryInterface(IID_IDocHostDragDropHandler, (void **) &m_pDragDropHandlerHost);
  35. }
  36. hr = m_pOleObjTrident->SetClientSite(pClientSite);
  37. if (!m_fUIHandlerSet)
  38. {
  39. // Give Trident the pointer to our IDocHostUIHandler
  40. // This has to be done after the SetClientSite call due to a Trident bug
  41. hr = m_pUnkTrident->QueryInterface(IID_ICustomDoc, (void **) &pCustomDoc);
  42. if (SUCCEEDED(hr) && m_pUIHandler)
  43. {
  44. hr = pCustomDoc->SetUIHandler(static_cast<IDocHostUIHandler*>(m_pUIHandler));
  45. pCustomDoc->Release();
  46. }
  47. m_fUIHandlerSet = TRUE;
  48. // We can only call this after SetClientSite or else Trident will crash
  49. SetUpDefaults();
  50. }
  51. #ifdef IE5_SPACING
  52. // instantiate the sink
  53. if (NULL != m_pClientSiteHost)
  54. {
  55. CComPtr<IHTMLDocument2> pHTMLDocument2;
  56. m_pTridentEventSink = NULL;
  57. hr = m_pUnkTrident->QueryInterface(IID_IHTMLDocument2, (void**)&pHTMLDocument2);
  58. if (hr == S_OK && pHTMLDocument2 != NULL)
  59. {
  60. m_pTridentEventSink = new CComObject<CTridentEventSink>;
  61. if (m_pTridentEventSink != NULL)
  62. {
  63. m_pTridentEventSink->m_pHTMLDocument2 = pHTMLDocument2;
  64. m_pTridentEventSink->m_pTriEditDocument = this;
  65. hr = m_pTridentEventSink->AddRef();
  66. hr = m_pTridentEventSink->Advise(m_pTridentEventSink->m_pHTMLDocument2, DIID_HTMLDocumentEvents);
  67. }
  68. }
  69. }
  70. else
  71. {
  72. if (m_pTridentEventSink)
  73. {
  74. m_pTridentEventSink->Unadvise();
  75. hr = m_pTridentEventSink->Release();
  76. }
  77. }
  78. #endif //IE5_SPACING
  79. return hr;
  80. }
  81. STDMETHODIMP CTriEditDocument::GetClientSite(IOleClientSite **ppClientSite)
  82. {
  83. ATLTRACE(_T("IOleObjectImpl::GetClientSite\n"));
  84. _ASSERTE(m_pOleObjTrident);
  85. return m_pOleObjTrident->GetClientSite(ppClientSite);
  86. }
  87. STDMETHODIMP CTriEditDocument::SetHostNames(LPCOLESTR szContainerApp, LPCOLESTR szContainerObj)
  88. {
  89. ATLTRACE(_T("IOleObjectImpl::SetHostNames\n"));
  90. _ASSERTE(m_pOleObjTrident);
  91. return m_pOleObjTrident->SetHostNames(szContainerApp, szContainerObj);
  92. }
  93. STDMETHODIMP CTriEditDocument::Close(DWORD dwSaveOption)
  94. {
  95. ATLTRACE(_T("IOleObjectImpl::Close\n"));
  96. _ASSERTE(m_pOleObjTrident);
  97. ReleaseElement();
  98. return m_pOleObjTrident->Close(dwSaveOption);
  99. }
  100. STDMETHODIMP CTriEditDocument::SetMoniker(DWORD dwWhichMoniker, IMoniker* pmk)
  101. {
  102. ATLTRACE(_T("IOleObjectImpl::SetMoniker\n"));
  103. _ASSERTE(m_pOleObjTrident);
  104. return m_pOleObjTrident->SetMoniker(dwWhichMoniker, pmk);
  105. }
  106. STDMETHODIMP CTriEditDocument::GetMoniker(DWORD dwAssign, DWORD dwWhichMoniker, IMoniker** ppmk )
  107. {
  108. ATLTRACE(_T("IOleObjectImpl::GetMoniker\n"));
  109. _ASSERTE(m_pOleObjTrident);
  110. return m_pOleObjTrident->GetMoniker(dwAssign, dwWhichMoniker, ppmk);
  111. }
  112. STDMETHODIMP CTriEditDocument::InitFromData(IDataObject* pDataObject, BOOL fCreation, DWORD dwReserved)
  113. {
  114. ATLTRACE(_T("IOleObjectImpl::InitFromData\n"));
  115. _ASSERTE(m_pOleObjTrident);
  116. return m_pOleObjTrident->InitFromData(pDataObject, fCreation, dwReserved );
  117. }
  118. STDMETHODIMP CTriEditDocument::GetClipboardData(DWORD dwReserved, IDataObject** ppDataObject)
  119. {
  120. ATLTRACE(_T("IOleObjectImpl::GetClipboardData\n"));
  121. _ASSERTE(m_pOleObjTrident);
  122. return m_pOleObjTrident->GetClipboardData(dwReserved, ppDataObject);
  123. }
  124. STDMETHODIMP CTriEditDocument::DoVerb(LONG iVerb, LPMSG lpmsg, IOleClientSite* pActiveSite , LONG lindex ,
  125. HWND hwndParent, LPCRECT lprcPosRect)
  126. {
  127. ATLTRACE(_T("IOleObjectImpl::DoVerb\n"));
  128. _ASSERTE(m_pOleObjTrident);
  129. return m_pOleObjTrident->DoVerb(iVerb, lpmsg, pActiveSite, lindex, hwndParent, lprcPosRect);
  130. }
  131. STDMETHODIMP CTriEditDocument::EnumVerbs(IEnumOLEVERB **ppEnumOleVerb)
  132. {
  133. ATLTRACE(_T("IOleObjectImpl::EnumVerbs\n"));
  134. _ASSERTE(m_pOleObjTrident);
  135. return m_pOleObjTrident->EnumVerbs(ppEnumOleVerb);
  136. }
  137. STDMETHODIMP CTriEditDocument::Update(void)
  138. {
  139. ATLTRACE(_T("IOleObjectImpl::Update\n"));
  140. _ASSERTE(m_pOleObjTrident);
  141. return m_pOleObjTrident->Update();
  142. }
  143. STDMETHODIMP CTriEditDocument::IsUpToDate(void)
  144. {
  145. ATLTRACE(_T("IOleObjectImpl::IsUpToDate\n"));
  146. _ASSERTE(m_pOleObjTrident);
  147. return m_pOleObjTrident->IsUpToDate();
  148. }
  149. STDMETHODIMP CTriEditDocument::GetUserClassID(CLSID *pClsid)
  150. {
  151. ATLTRACE(_T("IOleObjectImpl::GetUserClassID\n"));
  152. _ASSERTE(m_pOleObjTrident);
  153. *pClsid = GetObjectCLSID();
  154. return S_OK;
  155. }
  156. STDMETHODIMP CTriEditDocument::GetUserType(DWORD dwFormOfType, LPOLESTR *pszUserType)
  157. {
  158. ATLTRACE(_T("IOleObjectImpl::GetUserType\n"));
  159. _ASSERTE(m_pOleObjTrident);
  160. return OleRegGetUserType(GetObjectCLSID(), dwFormOfType, pszUserType);
  161. }
  162. STDMETHODIMP CTriEditDocument::SetExtent(DWORD dwDrawAspect, SIZEL *psizel)
  163. {
  164. ATLTRACE(_T("IOleObjectImpl::SetExtent\n"));
  165. _ASSERTE(m_pOleObjTrident);
  166. return m_pOleObjTrident->SetExtent(dwDrawAspect, psizel);
  167. }
  168. STDMETHODIMP CTriEditDocument::GetExtent(DWORD dwDrawAspect, SIZEL *psizel)
  169. {
  170. ATLTRACE(_T("IOleObjectImpl::GetExtent\n"));
  171. _ASSERTE(m_pOleObjTrident);
  172. return m_pOleObjTrident->GetExtent(dwDrawAspect, psizel);
  173. }
  174. STDMETHODIMP CTriEditDocument::Advise(IAdviseSink *pAdvSink, DWORD *pdwConnection)
  175. {
  176. ATLTRACE(_T("IOleObjectImpl::Advise\n"));
  177. _ASSERTE(m_pOleObjTrident);
  178. return m_pOleObjTrident->Advise(pAdvSink, pdwConnection);
  179. }
  180. STDMETHODIMP CTriEditDocument::Unadvise(DWORD dwConnection)
  181. {
  182. ATLTRACE(_T("IOleObjectImpl::Unadvise\n"));
  183. _ASSERTE(m_pOleObjTrident);
  184. return m_pOleObjTrident->Unadvise(dwConnection);
  185. }
  186. STDMETHODIMP CTriEditDocument::EnumAdvise(IEnumSTATDATA **ppenumAdvise)
  187. {
  188. ATLTRACE(_T("IOleObjectImpl::EnumAdvise\n"));
  189. _ASSERTE(m_pOleObjTrident);
  190. return m_pOleObjTrident->EnumAdvise(ppenumAdvise);
  191. }
  192. STDMETHODIMP CTriEditDocument::GetMiscStatus(DWORD dwAspect, DWORD *pdwStatus)
  193. {
  194. ATLTRACE(_T("IOleObjectImpl::GetMiscStatus\n"));
  195. _ASSERTE(m_pOleObjTrident);
  196. return m_pOleObjTrident->GetMiscStatus(dwAspect, pdwStatus);
  197. }
  198. STDMETHODIMP CTriEditDocument::SetColorScheme(LOGPALETTE* pLogpal)
  199. {
  200. ATLTRACE(_T("IOleObjectImpl::SetColorScheme\n"));
  201. _ASSERTE(m_pOleObjTrident);
  202. return m_pOleObjTrident->SetColorScheme(pLogpal);
  203. }