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 / chap21 / patron / iclisite.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  6.3 KB  |  302 lines

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