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

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