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 / chap22 / patron / iclisite.cpp < prev    next >
C/C++ Source or Header  |  1995-05-03  |  7KB  |  304 lines

  1. /*
  2.  * ICLISITE.CPP
  3.  * Patron Chapter 22
  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.     switch (dwWhich)
  128.         {
  129.         case OLEWHICHMK_CONTAINER:
  130.             //This is just the file we're living in.
  131.             if (NULL!=m_pTen->m_pmkFile)
  132.                 *ppmk=m_pTen->m_pmkFile;
  133.  
  134.             break;
  135.  
  136.         case OLEWHICHMK_OBJREL:
  137.             //This is everything but the filename.
  138.             if (NULL!=m_pTen->m_pmk)
  139.                 *ppmk=m_pTen->m_pmk;
  140.  
  141.             break;
  142.  
  143.         case OLEWHICHMK_OBJFULL:
  144.             //Concatenate file and relative monikers for this one.
  145.             if (NULL!=m_pTen->m_pmkFile && NULL!=m_pTen->m_pmk)
  146.                 {
  147.                 return m_pTen->m_pmkFile->ComposeWith
  148.                     (m_pTen->m_pmk, FALSE, ppmk);
  149.                 }
  150.  
  151.             break;
  152.         }
  153.  
  154.     if (NULL==*ppmk)
  155.         return ResultFromScode(E_FAIL);
  156.  
  157.     (*ppmk)->AddRef();
  158.     return NOERROR;
  159.     }
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166. /*
  167.  * CImpIOleClientSite::GetContainer
  168.  *
  169.  * Purpose:
  170.  *  Returns a pointer to the document's IOleContainer interface.
  171.  *
  172.  * Parameters:
  173.  *  ppContainer     LPOLECONTAINER * in which to return the
  174.  *                  interface.
  175.  *
  176.  * Return Value:
  177.  *  HRESULT         Standard.
  178.  */
  179.  
  180. STDMETHODIMP CImpIOleClientSite::GetContainer(LPOLECONTAINER
  181.     * ppContainer)
  182.     {
  183.     PCPage  pPage;
  184.  
  185.     *ppContainer=NULL;
  186.  
  187.     /*
  188.      * Here we want to get the interface on the page we're in.
  189.      * The function we call in CPages does not AddRef the page, but
  190.      * QueryInterface does.
  191.      */
  192.     m_pTen->m_pPG->IPageGetFromID((DWORD)-1L, &pPage, FALSE);
  193.  
  194.     if (NULL!=pPage)
  195.         {
  196.         return pPage->QueryInterface(IID_IOleItemContainer
  197.             , (PPVOID)ppContainer);
  198.         }
  199.  
  200.     return ResultFromScode(E_FAIL);
  201.     }
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208. /*
  209.  * CImpIOleClientSite::ShowObject
  210.  *
  211.  * Purpose:
  212.  *  Tells the container to bring the object fully into view as much
  213.  *  as possible, that is, scroll the document.
  214.  *
  215.  * Parameters:
  216.  *  None
  217.  *
  218.  * Return Value:
  219.  *  HRESULT         Standard.
  220.  */
  221.  
  222. STDMETHODIMP CImpIOleClientSite::ShowObject(void)
  223.     {
  224.     HWND        hWnd, hWndT;
  225.  
  226.     /*
  227.      * We let the tenant do this, since it can access the current
  228.      * scroll position as a friend of CPages whereas we cannot.
  229.      */
  230.     //CHAPTER22MOD
  231.     //Don't try to show objects that are always active.
  232.     if (!((OLEMISC_INSIDEOUT | OLEMISC_ACTIVATEWHENVISIBLE)
  233.         & m_pTen->m_grfMisc))
  234.         m_pTen->ShowYourself();
  235.     //End CHAPTER22MOD
  236.  
  237.     //For linking to embedding, show the main window.
  238.     hWndT=GetParent(m_pTen->m_hWnd);
  239.  
  240.     while (NULL!=hWndT)
  241.         {
  242.         hWnd=hWndT;
  243.         hWndT=GetParent(hWnd);
  244.         }
  245.  
  246.     ShowWindow(hWnd, SW_SHOWNOACTIVATE);
  247.  
  248.     //CHAPTER22MOD
  249.     m_pTen->UpdateInPlaceObjectRects(NULL, TRUE);
  250.     //End CHAPTER22MOD
  251.  
  252.     return NOERROR;
  253.     }
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260. /*
  261.  * CImpIOleClientSite::OnShowWindow
  262.  *
  263.  * Purpose:
  264.  *  Informs the container if the object is showing itself or
  265.  *  hiding itself.  This is done only in the opening mode and allows
  266.  *  the container to know when to shade or unshade the object.
  267.  *
  268.  * Parameters:
  269.  *  fShow           BOOL indiciating that the object is being shown
  270.  *                  (TRUE) or hidden (FALSE).
  271.  * Return Value:
  272.  *  HRESULT         Standard.
  273.  */
  274.  
  275. STDMETHODIMP CImpIOleClientSite::OnShowWindow(BOOL fShow)
  276.     {
  277.     //All we have to do is tell the tenant of the open state change.
  278.     m_pTen->ShowAsOpen(fShow);
  279.     return NOERROR;
  280.     }
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287. /*
  288.  * CImpIOleClientSite::RequestNewObjectLayout
  289.  *
  290.  * Purpose:
  291.  *  Called when the object needs more room in the container.
  292.  *
  293.  * Parameters:
  294.  *  None
  295.  *
  296.  * Return Value:
  297.  *  HRESULT         Standard.
  298.  */
  299.  
  300. STDMETHODIMP CImpIOleClientSite::RequestNewObjectLayout(void)
  301.     {
  302.     return ResultFromScode(E_NOTIMPL);
  303.     }
  304.