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.

407 lines
10 KiB

  1. /*
  2. * IIPSITE.CPP
  3. * IOleInPlaceSite for Document Objects CSite class
  4. *
  5. * Copyright (c)1995-1999 Microsoft Corporation, All Rights Reserved
  6. */
  7. #include "stdafx.h"
  8. #include <docobj.h>
  9. #include "DHTMLEd.h"
  10. #include "DHTMLEdit.h"
  11. #include "site.h"
  12. #include "proxyframe.h"
  13. /**
  14. Note: the m_cRef count is provided for debugging purposes only.
  15. CSite controls the destruction of the object through delete,
  16. not reference counting
  17. */
  18. /*
  19. * CImpIOleInPlaceSite::CImpIOleInPlaceSite
  20. * CImpIOleInPlaceSite::~CImpIOleInPlaceSite
  21. *
  22. * Parameters (Constructor):
  23. * pSite PCSite of the site we're in.
  24. * pUnkOuter LPUNKNOWN to which we delegate.
  25. */
  26. CImpIOleInPlaceSite::CImpIOleInPlaceSite( PCSite pSite, LPUNKNOWN pUnkOuter)
  27. {
  28. m_cRef = 0;
  29. m_pSite = pSite;
  30. m_pUnkOuter = pUnkOuter;
  31. }
  32. CImpIOleInPlaceSite::~CImpIOleInPlaceSite( void )
  33. {
  34. }
  35. /*
  36. * CImpIOleInPlaceSite::QueryInterface
  37. * CImpIOleInPlaceSite::AddRef
  38. * CImpIOleInPlaceSite::Release
  39. *
  40. * Purpose:
  41. * IUnknown members for CImpIOleInPlaceSite object.
  42. */
  43. STDMETHODIMP CImpIOleInPlaceSite::QueryInterface( REFIID riid, void **ppv )
  44. {
  45. return m_pUnkOuter->QueryInterface( riid, ppv );
  46. }
  47. STDMETHODIMP_(ULONG) CImpIOleInPlaceSite::AddRef(void)
  48. {
  49. ++m_cRef;
  50. return m_pUnkOuter->AddRef();
  51. }
  52. STDMETHODIMP_(ULONG) CImpIOleInPlaceSite::Release(void)
  53. {
  54. --m_cRef;
  55. return m_pUnkOuter->Release();
  56. }
  57. /*
  58. * CImpIOleInPlaceActiveObject::GetWindow
  59. *
  60. * Purpose:
  61. * Retrieves the handle of the window associated with the object
  62. * on which this interface is implemented.
  63. *
  64. * Parameters:
  65. * phWnd HWND * in which to store the window handle.
  66. *
  67. * Return Value:
  68. * HRESULT S_OK if successful, E_FAIL if there is no
  69. * window.
  70. */
  71. STDMETHODIMP CImpIOleInPlaceSite::GetWindow( HWND *phWnd )
  72. {
  73. //This is the client-area window in the frame
  74. *phWnd = m_pSite->GetWindow();
  75. return S_OK;
  76. }
  77. /*
  78. * CImpIOleInPlaceActiveObject::ContextSensitiveHelp
  79. *
  80. * Purpose:
  81. * Instructs the object on which this interface is implemented to
  82. * enter or leave a context-sensitive help mode.
  83. *
  84. * Parameters:
  85. * fEnterMode BOOL TRUE to enter the mode, FALSE otherwise.
  86. *
  87. * Return Value:
  88. * HRESULT S_OK
  89. */
  90. STDMETHODIMP CImpIOleInPlaceSite::ContextSensitiveHelp(
  91. BOOL /*fEnterMode*/ )
  92. {
  93. return S_OK;
  94. }
  95. /*
  96. * CImpIOleInPlaceSite::CanInPlaceActivate
  97. *
  98. * Purpose:
  99. * Answers the server whether or not we can currently in-place
  100. * activate its object. By implementing this interface we say
  101. * that we support in-place activation, but through this function
  102. * we indicate whether the object can currently be activated
  103. * in-place. Iconic aspects, for example, cannot, meaning we
  104. * return S_FALSE.
  105. *
  106. * Parameters:
  107. * None
  108. *
  109. * Return Value:
  110. * HRESULT S_OK if we can in-place activate the object
  111. * in this site, S_FALSE if not.
  112. */
  113. STDMETHODIMP CImpIOleInPlaceSite::CanInPlaceActivate( void )
  114. {
  115. /*
  116. * We can always in-place activate--no restrictions for DocObjects.
  117. * We don't worry about other cases since CSite only ever creates
  118. * embedded files.
  119. */
  120. return S_OK;
  121. }
  122. /*
  123. * CImpIOleInPlaceSite::OnInPlaceActivate
  124. *
  125. * Purpose:
  126. * Informs the container that an object is being activated in-place
  127. * such that the container can prepare appropriately. The
  128. * container does not, however, make any user interface changes at
  129. * this point. See OnUIActivate.
  130. *
  131. * Parameters:
  132. * None
  133. *
  134. * Return Value:
  135. * HRESULT NOERROR or an appropriate error code.
  136. */
  137. STDMETHODIMP CImpIOleInPlaceSite::OnInPlaceActivate( void )
  138. {
  139. LPOLEINPLACEOBJECT pIOleIPObject;
  140. HRESULT hr = m_pSite->GetObjectUnknown()->QueryInterface(
  141. IID_IOleInPlaceObject, (void**) &pIOleIPObject );
  142. m_pSite->SetIPObject( pIOleIPObject );
  143. return hr;
  144. }
  145. /*
  146. * CImpIOleInPlaceSite::OnInPlaceDeactivate
  147. *
  148. * Purpose:
  149. * Notifies the container that the object has deactivated itself
  150. * from an in-place state. Opposite of OnInPlaceActivate. The
  151. * container does not change any UI at this point.
  152. *
  153. * Parameters:
  154. * None
  155. *
  156. * Return Value:
  157. * HRESULT NOERROR or an appropriate error code.
  158. */
  159. STDMETHODIMP CImpIOleInPlaceSite::OnInPlaceDeactivate( void )
  160. {
  161. /*
  162. * Since we don't have an Undo command, we can tell the object
  163. * right away to discard its Undo state.
  164. */
  165. m_pSite->Activate(OLEIVERB_DISCARDUNDOSTATE);
  166. m_pSite->GetIPObject()->Release();
  167. return NOERROR;
  168. }
  169. /*
  170. * CImpIOleInPlaceSite::OnUIActivate
  171. *
  172. * Purpose:
  173. * Informs the container that the object is going to start munging
  174. * around with user interface, like replacing the menu. The
  175. * container should remove any relevant UI in preparation.
  176. *
  177. * Parameters:
  178. * None
  179. *
  180. * Return Value:
  181. * HRESULT NOERROR or an appropriate error code.
  182. */
  183. STDMETHODIMP CImpIOleInPlaceSite::OnUIActivate( void )
  184. {
  185. m_pSite->GetFrame()->GetControl()->DoVerbUIActivate ( NULL, NULL );
  186. // Bug 107500 returns an error from OnUIActivate.
  187. // If we return that error here, the control gets into an inconsistant state.
  188. // All is well if we return OK.
  189. return S_OK;
  190. }
  191. /*
  192. * CImpIOleInPlaceSite::OnUIDeactivate
  193. *
  194. * Purpose:
  195. * Informs the container that the object is deactivating its
  196. * in-place user interface at which time the container may
  197. * reinstate its own. Opposite of OnUIActivate.
  198. *
  199. * Parameters:
  200. * fUndoable BOOL indicating if the object will actually
  201. * perform an Undo if the container calls
  202. * ReactivateAndUndo.
  203. *
  204. * Return Value:
  205. * HRESULT NOERROR or an appropriate error code.
  206. */
  207. STDMETHODIMP CImpIOleInPlaceSite::OnUIDeactivate( BOOL /*fUndoable*/ )
  208. {
  209. // Normally we'd tidy up here, but since MSHTML.DLL is the only thing we host
  210. // the Frame will go away on deactivation so there's no point in restoring
  211. // the Frame's empty state
  212. return NOERROR;
  213. }
  214. /*
  215. * CImpIOleInPlaceSite::DeactivateAndUndo
  216. *
  217. * Purpose:
  218. * If immediately after activation the object does an Undo, the
  219. * action being undone is the activation itself, and this call
  220. * informs the container that this is, in fact, what happened.
  221. * The container should call IOleInPlaceObject::UIDeactivate.
  222. *
  223. * Parameters:
  224. * None
  225. *
  226. * Return Value:
  227. * HRESULT NOERROR or an appropriate error code.
  228. */
  229. STDMETHODIMP CImpIOleInPlaceSite::DeactivateAndUndo( void )
  230. {
  231. // Tell the object we are deactivating
  232. m_pSite->GetIPObject()->InPlaceDeactivate();
  233. return NOERROR;
  234. }
  235. /*
  236. * CImpIOleInPlaceSite::DiscardUndoState
  237. *
  238. * Purpose:
  239. * Informs the container that something happened in the object
  240. * that means the container should discard any undo information
  241. * it currently maintains for the object.
  242. *
  243. * Parameters:
  244. * None
  245. *
  246. * Return Value:
  247. * HRESULT NOERROR or an appropriate error code.
  248. */
  249. STDMETHODIMP CImpIOleInPlaceSite::DiscardUndoState( void )
  250. {
  251. return E_NOTIMPL;
  252. }
  253. /*
  254. * CImpIOleInPlaceSite::GetWindowContext
  255. *
  256. * Purpose:
  257. * Provides an in-place object with pointers to the frame and
  258. * document level in-place interfaces (IOleInPlaceFrame and
  259. * IOleInPlaceUIWindow) such that the object can do border
  260. * negotiation and so forth. Also requests the position and
  261. * clipping rectangles of the object in the container and a
  262. * pointer to an OLEINPLACEFRAME info structure which contains
  263. * accelerator information.
  264. *
  265. * Note that the two interfaces this call returns are not
  266. * available through QueryInterface on IOleInPlaceSite since they
  267. * live with the frame and document, but not the site.
  268. *
  269. * Parameters:
  270. * ppIIPFrame LPOLEINPLACEFRAME * in which to return the
  271. * AddRef'd pointer to the container's
  272. * IOleInPlaceFrame.
  273. * ppIIPUIWindow LPOLEINPLACEUIWINDOW * in which to return
  274. * the AddRef'd pointer to the container document's
  275. * IOleInPlaceUIWindow.
  276. * prcPos LPRECT in which to store the object's position.
  277. * prcClip LPRECT in which to store the object's visible
  278. * region.
  279. * pFI LPOLEINPLACEFRAMEINFO to fill with accelerator
  280. * stuff.
  281. *
  282. * Return Value:
  283. * HRESULT NOERROR
  284. */
  285. STDMETHODIMP CImpIOleInPlaceSite::GetWindowContext(
  286. LPOLEINPLACEFRAME* ppIIPFrame,
  287. LPOLEINPLACEUIWINDOW* ppIIPUIWindow,
  288. LPRECT prcPos,
  289. LPRECT prcClip,
  290. LPOLEINPLACEFRAMEINFO pFI )
  291. {
  292. *ppIIPUIWindow = NULL;
  293. m_pSite->QueryInterface(
  294. IID_IOleInPlaceFrame, (void **)ppIIPFrame);
  295. if (NULL != prcPos)
  296. {
  297. GetClientRect( m_pSite->GetWindow(), prcPos );
  298. }
  299. *prcClip = *prcPos;
  300. pFI->cb = sizeof(OLEINPLACEFRAMEINFO);
  301. pFI->fMDIApp = FALSE;
  302. m_pSite->GetFrame()->GetWindow(&pFI->hwndFrame);
  303. SetWindowLong ( pFI->hwndFrame, GWL_STYLE,
  304. GetWindowLong ( pFI->hwndFrame, GWL_STYLE ) |
  305. WS_CLIPSIBLINGS | WS_CLIPCHILDREN );
  306. pFI->haccel = NULL;
  307. pFI->cAccelEntries = 0;
  308. return NOERROR;
  309. }
  310. /*
  311. * CImpIOleInPlaceSite::Scroll
  312. *
  313. * Purpose:
  314. * Asks the container to scroll the document, and thus the object,
  315. * by the given amounts in the sz parameter.
  316. *
  317. * Parameters:
  318. * sz SIZE containing signed horizontal and vertical
  319. * extents by which the container should scroll.
  320. * These are in device units.
  321. *
  322. * Return Value:
  323. * HRESULT NOERROR
  324. */
  325. STDMETHODIMP CImpIOleInPlaceSite::Scroll( SIZE /*sz*/ )
  326. {
  327. //Not needed for DocObjects
  328. return E_NOTIMPL;
  329. }
  330. /*
  331. * CImpIOleInPlaceSite::OnPosRectChange
  332. *
  333. * Purpose:
  334. * Informs the container that the in-place object was resized.
  335. * The container must call IOleInPlaceObject::SetObjectRects.
  336. * This does not change the site's rectangle in any case.
  337. *
  338. * Parameters:
  339. * prcPos LPCRECT containing the new size of the object.
  340. *
  341. * Return Value:
  342. * HRESULT NOERROR
  343. */
  344. STDMETHODIMP CImpIOleInPlaceSite::OnPosRectChange( LPCRECT /*prcPos*/ )
  345. {
  346. //Not needed for DocObjects
  347. return E_NOTIMPL;
  348. }