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 / idocsite.cpp < prev    next >
C/C++ Source or Header  |  1997-08-12  |  4KB  |  146 lines

  1. /*
  2.  * IDOCSITE.CPP
  3.  * IOleDocumentSite 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.  * CImpIOleDocumentSite::CImpIOleDocumentSite
  14.  * CImpIOleDocumentSite::~CImpIOleDocumentSite
  15.  *
  16.  * Parameters (Constructor):
  17.  *  pSite           PCSite of the site we're in.
  18.  *  pUnkOuter       LPUNKNOWN to which we delegate.
  19.  */
  20.  
  21. CImpIOleDocumentSite::CImpIOleDocumentSite(PCSite pSite
  22.     , LPUNKNOWN pUnkOuter)
  23.     {
  24.     m_cRef=0;
  25.     m_pSite=pSite;
  26.     m_pUnkOuter=pUnkOuter;
  27.     return;
  28.     }
  29.  
  30. CImpIOleDocumentSite::~CImpIOleDocumentSite(void)
  31.     {
  32.     return;
  33.     }
  34.  
  35.  
  36.  
  37. /*
  38.  * CImpIOleDocumentSite::QueryInterface
  39.  * CImpIOleDocumentSite::AddRef
  40.  * CImpIOleDocumentSite::Release
  41.  *
  42.  * Purpose:
  43.  *  IUnknown members for CImpIOleDocumentSite object.
  44.  */
  45.  
  46. STDMETHODIMP CImpIOleDocumentSite::QueryInterface(REFIID riid
  47.     , void **ppv)
  48.     {
  49.     return m_pUnkOuter->QueryInterface(riid, ppv);
  50.     }
  51.  
  52.  
  53. STDMETHODIMP_(ULONG) CImpIOleDocumentSite::AddRef(void)
  54.     {
  55.     ++m_cRef;
  56.     return m_pUnkOuter->AddRef();
  57.     }
  58.  
  59. STDMETHODIMP_(ULONG) CImpIOleDocumentSite::Release(void)
  60.     {
  61.     --m_cRef;
  62.     return m_pUnkOuter->Release();
  63.     }
  64.  
  65.  
  66.  
  67.  
  68. /*
  69.  * CImpIOleDocumentsite::ActivateMe
  70.  *
  71.  * Purpose:
  72.  *  Instructs the container to activate the object in this site as
  73.  *  a document object.
  74.  *
  75.  * Parameters:
  76.  *  pView           IOleDocumentView * of the object to activate.
  77.  *
  78.  * Return Value:
  79.  *  HRESULT         NOERROR if successful, error code otherwise.
  80.  */
  81.  
  82. STDMETHODIMP CImpIOleDocumentSite::ActivateMe(IOleDocumentView *pView)
  83.     {
  84.     RECT                rc;
  85.     IOleDocument*       pDoc;
  86.     
  87.     /*
  88.      * If we're passed a NULL view pointer, then try to get one from
  89.      * the document object (the object within us).
  90.      */
  91.     if (NULL==pView)
  92.         {
  93.  
  94.         if (FAILED(m_pSite->m_pObj->QueryInterface(IID_IOleDocument
  95.             , (void **)&pDoc)))
  96.             return E_FAIL;
  97.  
  98.         if (FAILED(pDoc->CreateView(m_pSite->m_pImpIOleIPSite
  99.             , m_pSite->m_pIStream, 0, &pView)))            
  100.             return E_OUTOFMEMORY;
  101.  
  102.         // Release doc pointer since CreateView is a good com method that addrefs
  103.         pDoc->Release();
  104.         }        
  105.     else
  106.         {
  107.         //Make sure that the view has our client site
  108.         pView->SetInPlaceSite(m_pSite->m_pImpIOleIPSite);
  109.  
  110.         //We're holding onto the pointer, so AddRef it.
  111.         pView->AddRef();
  112.         }
  113.  
  114.  
  115.     /*
  116.      * Activation steps, now that we have a view:
  117.      *
  118.      *  1.  Call IOleDocumentView::SetInPlaceSite (assume done since
  119.      *      either the view already knows, or IOleDocument::CreateView
  120.      *      has done it already.
  121.      *
  122.      *  2.  Call IOleDocumentView::SetRect to give a bunch of space to
  123.      *      the view.  In our case this is the whole client area of
  124.      *      the CPages window.  (Patron doesn't use SetRectComplex)
  125.      *
  126.      *  3.  Call IOleDocumentView::Show to make the thing visible.
  127.      *
  128.      *  4.  Call IOleDocumentView::UIActivate to finish the job.
  129.      *
  130.      */
  131.  
  132.     m_pSite->m_fDocObj=TRUE;
  133.     m_pSite->m_pIOleDocView=pView;
  134.     
  135.     //This sets up toolbars and menus first    
  136.     pView->UIActivate(TRUE);
  137.  
  138.     //Set the window size sensitive to new toolbars
  139.     GetClientRect(m_pSite->m_hWnd, &rc);
  140.     pView->SetRect(&rc);
  141.  
  142.     //Makes it all active
  143.     pView->Show(TRUE);    
  144.     return NOERROR;
  145.     }
  146.