home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / inole2 / chap20 / patron / iclisite.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  5.3 KB  |  258 lines

  1. /*
  2.  * ICLISITE.CPP
  3.  * Patron Chapter 20
  4.  *
  5.  * Implementation of the IOleClientSite interface for
  6.  * Patron's tenants.
  7.  *
  8.  * Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  9.  *
  10.  * Kraig Brockschmidt, Microsoft
  11.  * Internet  :  kraigb@microsoft.com
  12.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  13.  */
  14.  
  15.  
  16. #include "patron.h"
  17.  
  18.  
  19. /*
  20.  * CImpIOleClientSite::CImpIOleClientSite
  21.  * CImpIOleClientSite::~CImpIOleClientSite
  22.  *
  23.  * Parameters (Constructor):
  24.  *  pTenant         PCTenant of the tenant we're in.
  25.  *  pUnkOuter       LPUNKNOWN to which we delegate.
  26.  */
  27.  
  28. CImpIOleClientSite::CImpIOleClientSite(PCTenant pTenant
  29.     , LPUNKNOWN pUnkOuter)
  30.     {
  31.     m_cRef=0;
  32.     m_pTen=pTenant;
  33.     m_pUnkOuter=pUnkOuter;
  34.     return;
  35.     }
  36.  
  37. CImpIOleClientSite::~CImpIOleClientSite(void)
  38.     {
  39.     return;
  40.     }
  41.  
  42.  
  43.  
  44.  
  45. /*
  46.  * CImpIOleClientSite::QueryInterface
  47.  * CImpIOleClientSite::AddRef
  48.  * CImpIOleClientSite::Release
  49.  *
  50.  * Purpose:
  51.  *  IUnknown members for CImpIOleClientSite object.
  52.  */
  53.  
  54. STDMETHODIMP CImpIOleClientSite::QueryInterface(REFIID riid
  55.     , PPVOID ppv)
  56.     {
  57.     return m_pUnkOuter->QueryInterface(riid, ppv);
  58.     }
  59.  
  60.  
  61. STDMETHODIMP_(ULONG) CImpIOleClientSite::AddRef(void)
  62.     {
  63.     ++m_cRef;
  64.     return m_pUnkOuter->AddRef();
  65.     }
  66.  
  67. STDMETHODIMP_(ULONG) CImpIOleClientSite::Release(void)
  68.     {
  69.     --m_cRef;
  70.     return m_pUnkOuter->Release();
  71.     }
  72.  
  73.  
  74.  
  75.  
  76. /*
  77.  * CImpIOleClientSite::SaveObject
  78.  *
  79.  * Purpose:
  80.  *  Requests that the container call OleSave for the object that
  81.  *  lives here.  Typically this happens on server shutdown.
  82.  *
  83.  * Parameters:
  84.  *  None
  85.  *
  86.  * Return Value:
  87.  *  HRESULT         Standard.
  88.  */
  89.  
  90. STDMETHODIMP CImpIOleClientSite::SaveObject(void)
  91.     {
  92.     //We're already set up with the tenant to save; this is trivial.
  93.     m_pTen->Update();
  94.     return NOERROR;
  95.     }
  96.  
  97.  
  98.  
  99.  
  100.  
  101. /*
  102.  * CImpIOleClientSite::GetMoniker
  103.  *
  104.  * Purpose:
  105.  *  Retrieves the moniker for the site in which this object lives,
  106.  *  either the moniker relative to the container or the full
  107.  *  moniker.
  108.  *
  109.  * Parameters:
  110.  *  dwAssign        DWORD specifying that the object wants moniker
  111.  *                  assignment.  Yeah.  Right.  Got any bridges to
  112.  *                  sell?
  113.  *  dwWhich         DWORD identifying which moniker the object
  114.  *                  wants, either the container's moniker, the
  115.  *                  moniker relative to this client site, or the
  116.  *                  full moniker.
  117.  *
  118.  * Return Value:
  119.  *  HRESULT         Standard.
  120.  */
  121.  
  122. STDMETHODIMP CImpIOleClientSite::GetMoniker(DWORD dwAssign
  123.     , DWORD dwWhich, LPMONIKER *ppmk)
  124.     {
  125.     *ppmk=NULL;
  126.  
  127.     //CHAPTER20MOD
  128.     /*
  129.      * To support linking as a container we at least have to
  130.      * implement this for OLEWHICKMK_CONTAINER but not for any
  131.      * others.  This allows OLE to update absolute monikers when
  132.      * it has to use the relative moniker to locate a link source.
  133.      */
  134.  
  135.     switch (dwWhich)
  136.         {
  137.         case OLEWHICHMK_CONTAINER:
  138.             //This is just the file we're living in.
  139.             if (NULL!=m_pTen->m_pmkFile)
  140.                 *ppmk=m_pTen->m_pmkFile;
  141.  
  142.             break;
  143.         }
  144.  
  145.     if (NULL==*ppmk)
  146.         return ResultFromScode(E_FAIL);
  147.  
  148.     (*ppmk)->AddRef();
  149.     return NOERROR;
  150.     //End CHAPTER20MOD
  151.     }
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158. /*
  159.  * CImpIOleClientSite::GetContainer
  160.  *
  161.  * Purpose:
  162.  *  Returns a pointer to the document's IOleContainer interface.
  163.  *
  164.  * Parameters:
  165.  *  ppContainer     LPOLECONTAINER * in which to return the
  166.  *                  interface.
  167.  *
  168.  * Return Value:
  169.  *  HRESULT         Standard.
  170.  */
  171.  
  172. STDMETHODIMP CImpIOleClientSite::GetContainer(LPOLECONTAINER
  173.     * ppContainer)
  174.     {
  175.     //Only necessary if you allow linking to embeddings
  176.     *ppContainer=NULL;
  177.     return ResultFromScode(E_NOTIMPL);
  178.     }
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185. /*
  186.  * CImpIOleClientSite::ShowObject
  187.  *
  188.  * Purpose:
  189.  *  Tells the container to bring the object fully into view as much
  190.  *  as possible, that is, scroll the document.
  191.  *
  192.  * Parameters:
  193.  *  None
  194.  *
  195.  * Return Value:
  196.  *  HRESULT         Standard.
  197.  */
  198.  
  199. STDMETHODIMP CImpIOleClientSite::ShowObject(void)
  200.     {
  201.     /*
  202.      * We let the tenant do this, since it can access the current
  203.      * scroll position as a friend of CPages whereas we cannot.
  204.      */
  205.     m_pTen->ShowYourself();
  206.     return NOERROR;
  207.     }
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214. /*
  215.  * CImpIOleClientSite::OnShowWindow
  216.  *
  217.  * Purpose:
  218.  *  Informs the container if the object is showing itself or
  219.  *  hiding itself.  This is done only in the opening mode and allows
  220.  *  the container to know when to shade or unshade the object.
  221.  *
  222.  * Parameters:
  223.  *  fShow           BOOL indiciating that the object is being shown
  224.  *                  (TRUE) or hidden (FALSE).
  225.  * Return Value:
  226.  *  HRESULT         Standard.
  227.  */
  228.  
  229. STDMETHODIMP CImpIOleClientSite::OnShowWindow(BOOL fShow)
  230.     {
  231.     //All we have to do is tell the tenant of the open state change.
  232.     m_pTen->ShowAsOpen(fShow);
  233.     return NOERROR;
  234.     }
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241. /*
  242.  * CImpIOleClientSite::RequestNewObjectLayout
  243.  *
  244.  * Purpose:
  245.  *  Called when the object needs more room in the container.
  246.  *
  247.  * Parameters:
  248.  *  None
  249.  *
  250.  * Return Value:
  251.  *  HRESULT         Standard.
  252.  */
  253.  
  254. STDMETHODIMP CImpIOleClientSite::RequestNewObjectLayout(void)
  255.     {
  256.     return ResultFromScode(E_NOTIMPL);
  257.     }
  258.