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 / iadvsink.cpp < prev    next >
C/C++ Source or Header  |  1995-05-03  |  5KB  |  218 lines

  1. /*
  2.  * IADVSINK.CPP
  3.  * Patron Chapter 22
  4.  *
  5.  * Implementation of the IAdviseSink interface for Patron's tenants.
  6.  *
  7.  * Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  8.  *
  9.  * Kraig Brockschmidt, Microsoft
  10.  * Internet  :  kraigb@microsoft.com
  11.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  12.  */
  13.  
  14.  
  15. #include "patron.h"
  16.  
  17.  
  18. /*
  19.  * CImpIAdviseSink::CImpIAdviseSink
  20.  * CImpIAdviseSink::~CImpIAdviseSink
  21.  *
  22.  * Parameters (Constructor):
  23.  *  pTenant         PCTenant of the tenant we're in.
  24.  *  pUnkOuter       LPUNKNOWN to which we delegate.
  25.  */
  26.  
  27. CImpIAdviseSink::CImpIAdviseSink(PCTenant pTenant
  28.     , LPUNKNOWN pUnkOuter)
  29.     {
  30.     m_cRef=0;
  31.     m_pTen=pTenant;
  32.     m_pUnkOuter=pUnkOuter;
  33.     return;
  34.     }
  35.  
  36. CImpIAdviseSink::~CImpIAdviseSink(void)
  37.     {
  38.     return;
  39.     }
  40.  
  41.  
  42.  
  43.  
  44. /*
  45.  * CImpIAdviseSink::QueryInterface
  46.  * CImpIAdviseSink::AddRef
  47.  * CImpIAdviseSink::Release
  48.  *
  49.  * Purpose:
  50.  *  IUnknown members for CImpIAdviseSink object.
  51.  */
  52.  
  53. STDMETHODIMP CImpIAdviseSink::QueryInterface(REFIID riid, PPVOID ppv)
  54.     {
  55.     return m_pUnkOuter->QueryInterface(riid, ppv);
  56.     }
  57.  
  58.  
  59. STDMETHODIMP_(ULONG) CImpIAdviseSink::AddRef(void)
  60.     {
  61.     ++m_cRef;
  62.     return m_pUnkOuter->AddRef();
  63.     }
  64.  
  65. STDMETHODIMP_(ULONG) CImpIAdviseSink::Release(void)
  66.     {
  67.     --m_cRef;
  68.     return m_pUnkOuter->Release();
  69.     }
  70.  
  71.  
  72.  
  73.  
  74. /*
  75.  * CImpIAdviseSink::OnDataChange
  76.  *
  77.  * Unused since we don't IDataObject::Advise.
  78.  */
  79.  
  80. STDMETHODIMP_(void) CImpIAdviseSink::OnDataChange(LPFORMATETC pFEIn
  81.     , LPSTGMEDIUM pSTM)
  82.     {
  83.     return;
  84.     }
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92. /*
  93.  * CImpIAdviseSink::OnViewChange
  94.  *
  95.  * Purpose:
  96.  *  Notifes the advise sink that presentation data changed in the
  97.  *  data object to which we're connected providing the right time
  98.  *  to update displays using such presentations.
  99.  *
  100.  * Parameters:
  101.  *  dwAspect        DWORD indicating which aspect has changed.
  102.  *  lindex          LONG indicating the piece that changed.
  103.  *
  104.  * Return Value:
  105.  *  None
  106.  */
  107.  
  108. STDMETHODIMP_(void) CImpIAdviseSink::OnViewChange(DWORD dwAspect
  109.     , LONG lindex)
  110.     {
  111.     //Repaint only if this is the right aspect
  112.     if (dwAspect==m_pTen->m_fe.dwAspect)
  113.         {
  114.         m_pTen->m_pPG->m_fDirty=TRUE;
  115.         m_pTen->Repaint();
  116.         }
  117.  
  118.     return;
  119.     }
  120.  
  121.  
  122.  
  123.  
  124.  
  125. /*
  126.  * CImpIAdviseSink::OnRename
  127.  *
  128.  * Purpose:
  129.  *  Informs the advise sink that a linked object has been renamed.
  130.  *  Generally only the OLE default handler cares about this.
  131.  *
  132.  * Parameters:
  133.  *  pmk             LPMONIKER providing the new name of the object
  134.  *
  135.  * Return Value:
  136.  *  None
  137.  */
  138.  
  139. STDMETHODIMP_(void) CImpIAdviseSink::OnRename(LPMONIKER pmk)
  140.     {
  141.     /*
  142.      * As a container this is unimportant to us since it really
  143.      * tells the handler's implementation of IOleLink that the
  144.      * object's moniker has changed.  Since we get this call
  145.      * from the handler, we don't have to do anything ourselves.
  146.      */
  147.     return;
  148.     }
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155. /*
  156.  * CImpIAdviseSink::OnSave
  157.  *
  158.  * Purpose:
  159.  *  Informs the advise sink that the OLE object has been saved
  160.  *  persistently.  The primary purpose of this is for containers
  161.  *  that want to make optimizations for objects that are not in a
  162.  *  saved state, so on this you have to disable such optimizations.
  163.  *
  164.  * Parameters:
  165.  *  None
  166.  *
  167.  * Return Value:
  168.  *  None
  169.  */
  170.  
  171. STDMETHODIMP_(void) CImpIAdviseSink::OnSave(void)
  172.     {
  173.     /*
  174.      * A Container has nothing to do here as this notification is
  175.      * only useful when we have an ADVFCACHE_ONSAVE advise set up,
  176.      * which we don't.  So we ignore it.
  177.      */
  178.     return;
  179.     }
  180.  
  181.  
  182.  
  183.  
  184.  
  185. /*
  186.  * CImpIAdviseSink::OnClose
  187.  *
  188.  * Purpose:
  189.  *  Informs the advise sink that the OLE object has closed and is
  190.  *  no longer bound in any way.
  191.  *
  192.  * Parameters:
  193.  *  None
  194.  *
  195.  * Return Value:
  196.  *  None
  197.  */
  198.  
  199. STDMETHODIMP_(void) CImpIAdviseSink::OnClose(void)
  200.     {
  201.     /*
  202.      * This doesn't have much to do with us again as it's only
  203.      * used to notify the handler's IOleLink implementation of the
  204.      * change in the object.  We don't have to do anything since
  205.      * we'll also get an IOleClientSite::OnShowWindow(FALSE) to
  206.      * tell us to repaint.
  207.      */
  208.  
  209.     /*
  210.      * If we are dealing with an OLE 1.0 server it may not call
  211.      * IOleClientSite::OnShowWindow(FALSE) properly, so to protect
  212.      * ourselves we make sure the object is drawn as closed on
  213.      * this notification.
  214.      */
  215.     m_pTen->ShowAsOpen(FALSE);
  216.     return;
  217.     }
  218.