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 / chap10 / cocosmo / iadvsink.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  6.0 KB  |  330 lines

  1. /*
  2.  * IADVSINK.CPP
  3.  * Component Cosmo Chapter 10
  4.  *
  5.  * Implementation of the CPolylineAdviseSink and CImpIAdviseSink
  6.  * interfaces for Component Cosmo.  CPolylineAdviseSink moved
  7.  * here from document.cpp to live with all the advise stuff.
  8.  *
  9.  * Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  10.  *
  11.  * Kraig Brockschmidt, Microsoft
  12.  * Internet  :  kraigb@microsoft.com
  13.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  14.  */
  15.  
  16.  
  17. #include "cocosmo.h"
  18.  
  19.  
  20. /*
  21.  * CPolylineAdviseSink::CPolylineAdviseSink
  22.  * CPolylineAdviseSink::~CPolylineAdviseSink
  23.  *
  24.  * Constructor Parameters:
  25.  *  pDoc            PCCosmoDoc to store in this object
  26.  */
  27.  
  28. CPolylineAdviseSink::CPolylineAdviseSink(PCCosmoDoc pDoc)
  29.     {
  30.     m_pDoc=pDoc;
  31.     m_cRef=0;
  32.     AddRef();
  33.     return;
  34.     }
  35.  
  36.  
  37. CPolylineAdviseSink::~CPolylineAdviseSink(void)
  38.     {
  39.     return;
  40.     }
  41.  
  42.  
  43.  
  44.  
  45. /*
  46.  * CPolylineAdviseSink::QueryInterface
  47.  * CPolylineAdviseSink::AddRef
  48.  * CPolylineAdviseSink::Release
  49.  *
  50.  * Purpose:
  51.  *  IUnknown members for this IPolylineAdviseSink implementations.
  52.  */
  53.  
  54. STDMETHODIMP CPolylineAdviseSink::QueryInterface(REFIID riid
  55.     , PPVOID ppv)
  56.     {
  57.     //CHAPTER10MOD
  58.     return m_pDoc->QueryInterface(riid, ppv);
  59.     //End CHAPTER10MOD
  60.     }
  61.  
  62.  
  63. STDMETHODIMP_(ULONG) CPolylineAdviseSink::AddRef(void)
  64.     {
  65.     return ++m_cRef;
  66.     }
  67.  
  68.  
  69. STDMETHODIMP_(ULONG) CPolylineAdviseSink::Release(void)
  70.     {
  71.     if (0L!=--m_cRef)
  72.         return m_cRef;
  73.  
  74.     delete this;
  75.     return 0;
  76.     }
  77.  
  78.  
  79.  
  80.  
  81. /*
  82.  * CPolylineAdviseSink::OnPointChange
  83.  *
  84.  * Purpose:
  85.  *  Informs the document that the polyline added or removed a point.
  86.  *
  87.  * Parameters:
  88.  *  None
  89.  *
  90.  * Return Value:
  91.  *  None
  92.  */
  93.  
  94. STDMETHODIMP_(void) CPolylineAdviseSink::OnPointChange(void)
  95.     {
  96.     m_pDoc->FDirtySet(TRUE);
  97.     return;
  98.     }
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105. /*
  106.  * CPolylineAdviseSink::OnSizeChange
  107.  *
  108.  * Purpose:
  109.  *  Informs the document that the polyline changed size.
  110.  *
  111.  * Parameters:
  112.  *  None
  113.  *
  114.  * Return Value:
  115.  *  None
  116.  */
  117.  
  118. STDMETHODIMP_(void) CPolylineAdviseSink::OnSizeChange(void)
  119.     {
  120.     RECT            rc;
  121.     DWORD           dwStyle;
  122.     HWND            hWnd;
  123.  
  124.     /*
  125.      * Polyline window is informing us that it changed size in
  126.      * response to setting it's data.  Therefore we have to
  127.      * size ourselves accordingly but without moving the screen
  128.      * position of the polyline window.
  129.      */
  130.  
  131.     m_pDoc->m_fNoSize=TRUE;
  132.  
  133.     //Set the document window size.
  134.     m_pDoc->m_pPL->Window(&hWnd);
  135.     GetWindowRect(hWnd, &rc);
  136.     InflateRect(&rc, 8, 8);
  137.  
  138.     //Adjust for a window sans menu
  139.     dwStyle=GetWindowLong(m_pDoc->m_hWnd, GWL_STYLE);
  140.     AdjustWindowRect(&rc, dwStyle, FALSE);
  141.  
  142.     SetWindowPos(m_pDoc->m_hWnd, NULL, 0, 0, rc.right-rc.left
  143.         , rc.bottom-rc.top, SWP_NOMOVE | SWP_NOZORDER);
  144.  
  145.     if (NULL!=m_pDoc->m_pAdv)
  146.         m_pDoc->m_pAdv->OnSizeChange(m_pDoc, &rc);
  147.  
  148.     m_pDoc->m_fNoSize=FALSE;
  149.     m_pDoc->FDirtySet(TRUE);
  150.  
  151.     return;
  152.     }
  153.  
  154.  
  155.  
  156.  
  157. //CHAPTER10MOD
  158. //OnDataChange in CImpIAdviseSink now
  159. //End CHAPTER10MOD
  160.  
  161.  
  162.  
  163. /*
  164.  * CPolylineAdviseSink::OnColorChange
  165.  *
  166.  * Purpose:
  167.  *  Informs the document that the polyline data changed a color.
  168.  *
  169.  * Parameters:
  170.  *  None
  171.  *
  172.  * Return Value:
  173.  *  None
  174.  */
  175.  
  176. STDMETHODIMP_(void) CPolylineAdviseSink::OnColorChange(void)
  177.     {
  178.     m_pDoc->FDirtySet(TRUE);
  179.     return;
  180.     }
  181.  
  182.  
  183.  
  184.  
  185.  
  186. /*
  187.  * CPolylineAdviseSink::OnLineStyleChange
  188.  *
  189.  * Purpose:
  190.  *  Informs the document that the polyline changed its line style.
  191.  *
  192.  * Parameters:
  193.  *  None
  194.  *
  195.  * Return Value:
  196.  *  None
  197.  */
  198.  
  199. STDMETHODIMP_(void) CPolylineAdviseSink::OnLineStyleChange(void)
  200.     {
  201.     m_pDoc->FDirtySet(TRUE);
  202.     return;
  203.     }
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210. //CHAPTER10MOD
  211. /*
  212.  * CImpIAdviseSink::CImpIAdviseSink
  213.  * CImpIAdviseSink::~CImpIAdviseSink
  214.  *
  215.  * Parameters (Constructor):
  216.  *  pObj            LPVOID of the object we're in.
  217.  *  pUnkOuter       LPUNKNOWN for delegation of IUnknown members.
  218.  */
  219.  
  220. CImpIAdviseSink::CImpIAdviseSink(LPVOID pObj, LPUNKNOWN pUnkOuter)
  221.     {
  222.     m_cRef=0;
  223.     m_pObj=pObj;
  224.     m_pUnkOuter=pUnkOuter;
  225.     return;
  226.     }
  227.  
  228. CImpIAdviseSink::~CImpIAdviseSink(void)
  229.     {
  230.     return;
  231.     }
  232.  
  233.  
  234.  
  235.  
  236. /*
  237.  * CImpIAdviseSink::QueryInterface
  238.  * CImpIAdviseSink::AddRef
  239.  * CImpIAdviseSink::Release
  240.  *
  241.  * Purpose:
  242.  *  IUnknown members for CImpIAdviseSink object.
  243.  */
  244.  
  245. STDMETHODIMP CImpIAdviseSink::QueryInterface(REFIID riid
  246.     , PPVOID ppv)
  247.     {
  248.     return m_pUnkOuter->QueryInterface(riid, ppv);
  249.     }
  250.  
  251.  
  252. STDMETHODIMP_(ULONG) CImpIAdviseSink::AddRef(void)
  253.     {
  254.     ++m_cRef;
  255.     return m_pUnkOuter->AddRef();
  256.     }
  257.  
  258. STDMETHODIMP_(ULONG) CImpIAdviseSink::Release(void)
  259.     {
  260.     --m_cRef;
  261.     return m_pUnkOuter->Release();
  262.     }
  263.  
  264.  
  265.  
  266.  
  267. /*
  268.  * CImpIAdviseSink::OnDataChange
  269.  *
  270.  * Purpose:
  271.  *  Notifes the advise sink that data changed in a data object.
  272.  *  On this message you may request a new data rendering and
  273.  *  update your displays as necessary.
  274.  *
  275.  * Parameters:
  276.  *  pFEIn           LPFORMATETC describing format that changed
  277.  *  pSTM            LPSTGMEDIUM providing the medium in which the
  278.  *                  data is provided.
  279.  *
  280.  * Return Value:
  281.  *  None
  282.  */
  283.  
  284. STDMETHODIMP_(void) CImpIAdviseSink::OnDataChange(LPFORMATETC pFEIn
  285.     , LPSTGMEDIUM pSTM)
  286.     {
  287.     PCCosmoDoc      m_pDoc=(PCCosmoDoc)m_pObj;
  288.  
  289.     /*
  290.      * This code is from former CPolylineAdviseSink::OnDataChange.
  291.      * The only advise we asked for was on the Polyline native
  292.      * format which is all we'll be notified for.
  293.      */
  294.     if (NULL!=m_pDoc->m_pAdv)
  295.         m_pDoc->m_pAdv->OnDataChange(m_pDoc);
  296.  
  297.     m_pDoc->FDirtySet(TRUE);
  298.     return;
  299.     }
  300.  
  301.  
  302.  
  303.  
  304. STDMETHODIMP_(void) CImpIAdviseSink::OnViewChange(DWORD dwAspect
  305.     , LONG lindex)
  306.     {
  307.     return;
  308.     }
  309.  
  310.  
  311. STDMETHODIMP_(void) CImpIAdviseSink::OnRename(LPMONIKER pmk)
  312.     {
  313.     return;
  314.     }
  315.  
  316.  
  317. STDMETHODIMP_(void) CImpIAdviseSink::OnSave(void)
  318.     {
  319.     return;
  320.     }
  321.  
  322.  
  323. STDMETHODIMP_(void) CImpIAdviseSink::OnClose(void)
  324.     {
  325.     return;
  326.     }
  327.  
  328.  
  329. //End CHAPTER10MOD
  330.