home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / activedocument / framer / iipsite.cpp < prev    next >
C/C++ Source or Header  |  1997-08-12  |  10KB  |  411 lines

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