ipsite.cpp
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 9k
Category:

Windows Kernel

Development Platform:

Visual C++

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