home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / ole / oleview / iviewers / iadvsink.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  5.7 KB  |  282 lines

  1. /*
  2.  * IADVSINK.CPP
  3.  *
  4.  * Implementation of the IAdviseSink interface for the Data User, Chapter 6
  5. /*
  6.  
  7. // This is a part of the Microsoft Foundation Classes C++ library.
  8. // Copyright (C) 1992-1998 Microsoft Corporation
  9. // All rights reserved.
  10. //
  11. // This source code is only intended as a supplement to the
  12. // Microsoft Foundation Classes Reference and related
  13. // electronic documentation provided with the library.
  14. // See these sources for detailed information regarding the
  15. // Microsoft Foundation Classes product.
  16.  
  17. /*
  18.  * Kraig Brockschmidt, Software Design Engineer
  19.  * Microsoft Systems Developer Relations
  20.  *
  21.  * Internet  :  kraigb@microsoft.com
  22.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  23.  */
  24. #include "stdafx.h"
  25. #include "iview.h"
  26. #include "util.h"
  27. #include "idataobj.h"
  28. #include "iadvsink.h"
  29.  
  30. /*
  31.  * CImpIAdviseSink::CImpIAdviseSink
  32.  * CImpIAdviseSink::~CImpIAdviseSink
  33.  *
  34.  * Parameters (Constructor):
  35.  *  pAV             LPAPPVARS to the application
  36.  *
  37.  */
  38.  
  39. CImpIAdviseSink::CImpIAdviseSink( CIDataObjectDlg FAR* lpIDOD )
  40.     {
  41.     m_cRef=0;
  42.     m_pIDOD=lpIDOD;
  43.     return;
  44.     }
  45.  
  46. CImpIAdviseSink::~CImpIAdviseSink(void)
  47.     {
  48.     m_pIDOD->m_pSink = NULL; // make sure the container knows I've been deleted. SteveBl
  49.     return;
  50.     }
  51.  
  52.  
  53.  
  54.  
  55. /*
  56.  * CImpIAdviseSink::QueryInterface
  57.  * CImpIAdviseSink::AddRef
  58.  * CImpIAdviseSink::Release
  59.  *
  60.  * Purpose:
  61.  *  IUnknown members for CImpIAdviseSink object.
  62.  */
  63.  
  64. STDMETHODIMP CImpIAdviseSink::QueryInterface(REFIID riid, LPVOID FAR *ppv)
  65.     {
  66.     *ppv=NULL;
  67.  
  68.     //Any interface on this object is the object pointer.
  69.     if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IAdviseSink))
  70.         *ppv=(LPVOID)this;
  71.  
  72.     /*
  73.      * If we actually assign an interface to ppv we need to AddRef it
  74.      * since we're returning a new pointer.
  75.      */
  76.     if (NULL!=*ppv)
  77.         {
  78.         ((LPUNKNOWN)*ppv)->AddRef();
  79.         return NOERROR;
  80.         }
  81.  
  82.     return ResultFromScode(E_NOINTERFACE);
  83.     }
  84.  
  85.  
  86. STDMETHODIMP_(ULONG) CImpIAdviseSink::AddRef(void)
  87.     {
  88.     return ++m_cRef;
  89.     }
  90.  
  91.  
  92. STDMETHODIMP_(ULONG) CImpIAdviseSink::Release(void)
  93.     {
  94.     ULONG   cRefT;
  95.  
  96.     cRefT=--m_cRef;
  97.  
  98.     if (0==cRefT)
  99.         delete this;
  100.  
  101.     return cRefT;
  102.     }
  103.  
  104.  
  105.  
  106.  
  107. /*
  108.  * IAdviseSink::OnDataChange
  109.  *
  110.  * Purpose:
  111.  *  Notifes the advise sink that data changed in a data object.  On
  112.  *  this message you may request a new data rendering and update your
  113.  *  displays as necessary.  Any data sent to this function is owned
  114.  *  by the caller, not by this advise sink!
  115.  *
  116.  *  All Advise Sink methods should be considered asynchronous and therefore
  117.  *  we should attempt no synchronous calls from within them to an EXE
  118.  *  object.  If we do, we'll get RPC_E_CALLREJECTED as shown below.
  119.  *
  120.  * Parameters:
  121.  *  pFE             LPFORMATETC describing format that changed
  122.  *  pSTM            LPSTGMEDIUM providing the medium in which the data
  123.  *                  is provided.
  124.  *
  125.  * Return Value:
  126.  *  None
  127.  */
  128.  
  129. STDMETHODIMP_(void) CImpIAdviseSink::OnDataChange(LPFORMATETC pFE, LPSTGMEDIUM pSTM)
  130. {
  131.     UINT        cf;
  132.  
  133.     //See if we're interested
  134.     cf=pFE->cfFormat;
  135.  
  136.     if (!(DVASPECT_CONTENT & pFE->dwAspect))
  137.         return;
  138.  
  139. /*
  140.     BOOL        fUsable=TRUE;
  141.     //Check media types
  142.     switch (cf)
  143.     {
  144.     #ifdef UNICODE
  145.         case CF_UNICODETEXT:
  146.     #else
  147.         case CF_TEXT:
  148.     #endif
  149.             fUsable=(BOOL)(TYMED_HGLOBAL & pFE->tymed);
  150.         break;
  151.         case CF_BITMAP:
  152.             fUsable=(BOOL)(TYMED_GDI & pFE->tymed);
  153.         break;
  154.  
  155.         case CF_METAFILEPICT:
  156.             fUsable=(BOOL)(TYMED_MFPICT & pFE->tymed);
  157.         break;
  158.  
  159.         default:
  160.         break;
  161.     }
  162.  
  163.     if (!fUsable)
  164.         return;
  165. */
  166.  
  167.     if (NULL==m_pIDOD->m_lpDO)
  168.         return;
  169.  
  170.     // If we are doing a 'warm link' then the data does not come with the
  171.     // OnDataChange.   Post a message back to ourselves so that we can
  172.     // call GetData when it's convienient
  173.     //
  174.     if (m_pIDOD->m_advf & ADVF_NODATA)
  175.     {
  176.         if (m_pIDOD->m_fDoOnGetDataPosted == FALSE)
  177.         {
  178.             m_pIDOD->m_fDoOnGetDataPosted = TRUE ;
  179.             PostMessage( m_pIDOD->m_hDlg, WM_COMMAND,  IDC_DOGETDATA, 0L ) ;
  180.         }
  181.         return ;
  182.     }
  183.  
  184.     // for Hot links the data comes with the OnDataChange
  185.     m_pIDOD->GotData( pFE, pSTM ) ;
  186.     return ;
  187. }
  188.  
  189. /*
  190.  * IAdviseSink::OnViewChange
  191.  *
  192.  * Purpose:
  193.  *  Notifes the advise sink that presentation data changed in the data
  194.  *  object to which we're connected providing the right time to update
  195.  *  displays using such presentations.
  196.  *
  197.  * Parameters:
  198.  *  dwAspect        DWORD indicating which aspect has changed.
  199.  *  lindex          LONG indicating the piece that changed.
  200.  *
  201.  * Return Value:
  202.  *  None
  203.  */
  204.  
  205. STDMETHODIMP_(void) CImpIAdviseSink::OnViewChange(DWORD , LONG )
  206.     {
  207.     return;
  208.     }
  209.  
  210.  
  211.  
  212.  
  213.  
  214. /*
  215.  * IAdviseSink::OnRename
  216.  *
  217.  * Purpose:
  218.  *  Informs the advise sink that an IOleObject has been renamed, primarily
  219.  *  when its linked.
  220.  *
  221.  * Parameters:
  222.  *  pmk             LPMONIKER providing the new name of the object
  223.  *
  224.  * Return Value:
  225.  *  None
  226.  */
  227.  
  228. STDMETHODIMP_(void) CImpIAdviseSink::OnRename(LPMONIKER)
  229.     {
  230.     return;
  231.     }
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238. /*
  239.  * IAdviseSink::OnSave
  240.  *
  241.  * Purpose:
  242.  *  Informs the advise sink that the OLE object has been saved
  243.  *  persistently.  The primary purpose of this is for containers that
  244.  *  want to make optimizations for objects that are not in a saved
  245.  *  state, so on this you have to disable such optimizations.
  246.  *
  247.  * Parameters:
  248.  *  None
  249.  *
  250.  * Return Value:
  251.  *  None
  252.  */
  253.  
  254. STDMETHODIMP_(void) CImpIAdviseSink::OnSave(void)
  255.     {
  256.     return;
  257.     }
  258.  
  259.  
  260.  
  261.  
  262.  
  263. /*
  264.  * IAdviseSink::OnClose
  265.  *
  266.  * Purpose:
  267.  *  Informs the advise sink that the OLE object has closed and is
  268.  *  no longer bound in any way.  On this you typically change state
  269.  *  variables and redraw shading, etc.
  270.  *
  271.  * Parameters:
  272.  *  None
  273.  *
  274.  * Return Value:
  275.  *  None
  276.  */
  277.  
  278. STDMETHODIMP_(void) CImpIAdviseSink::OnClose(void)
  279.     {
  280.     return;
  281.     }
  282.