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 / chap07 / cosmo / document.cpp < prev    next >
C/C++ Source or Header  |  1995-05-03  |  19KB  |  917 lines

  1. /*
  2.  * DOCUMENT.CPP
  3.  * Cosmo Chapter 7
  4.  *
  5.  * Implementation of the CCosmoDoc derivation of CDocument as
  6.  * well as an implementation of CPolylineAdviseSink.
  7.  *
  8.  * Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  9.  *
  10.  * Kraig Brockschmidt, Microsoft
  11.  * Internet  :  kraigb@microsoft.com
  12.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  13.  */
  14.  
  15.  
  16. #include "cosmo.h"
  17.  
  18.  
  19. /*
  20.  * CCosmoDoc::CCosmoDoc
  21.  * CCosmoDoc::~CCosmoDoc
  22.  *
  23.  * Constructor Parameters:
  24.  *  hInst           HINSTANCE of the application.
  25.  *  pFR             PCFrame of the frame object.
  26.  *  pAdv            PCDocumentAdviseSink to notify on events
  27.  */
  28.  
  29. CCosmoDoc::CCosmoDoc(HINSTANCE hInst, PCFrame pFR
  30.     , PCDocumentAdviseSink pAdv)
  31.     : CDocument(hInst, pFR, pAdv)
  32.     {
  33.     m_pPL=NULL;
  34.     m_pPLAdv=NULL;
  35.     m_uPrevSize=SIZE_RESTORED;
  36.     return;
  37.     }
  38.  
  39.  
  40. CCosmoDoc::~CCosmoDoc(void)
  41.     {
  42.     //Clean up the allocations we did in Init
  43.     if (NULL!=m_pPL)
  44.         delete m_pPL;
  45.  
  46.     if (NULL!=m_pPLAdv)
  47.         delete m_pPLAdv;
  48.  
  49.     return;
  50.     }
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57. /*
  58.  * CCosmoDoc::Init
  59.  *
  60.  * Purpose:
  61.  *  Initializes an already created document window.  The client
  62.  *  actually creates the window for us, then passes that here for
  63.  *  further initialization.
  64.  *
  65.  * Parameters:
  66.  *  pDI             PDOCUMENTINIT containing initialization
  67.  *                  parameters.
  68.  *
  69.  * Return Value:
  70.  *  BOOL            TRUE if the function succeeded, FALSE otherwise.
  71.  */
  72.  
  73. BOOL CCosmoDoc::Init(PDOCUMENTINIT pDI)
  74.     {
  75.     RECT        rc;
  76.  
  77.     //Change the stringtable range to our customization.
  78.     pDI->idsMin=IDS_DOCUMENTMIN;
  79.     pDI->idsMax=IDS_DOCUMENTMAX;
  80.  
  81.     //Do default initialization
  82.     if (!CDocument::Init(pDI))
  83.         return FALSE;
  84.  
  85.     //Add the Polyline stuff we need.
  86.     m_pPLAdv=new CPolylineAdviseSink(this);
  87.     m_pPL   =new CPolyline(m_hInst);
  88.  
  89.     //Attempt to create our contained Polyline.
  90.     GetClientRect(m_hWnd, &rc);
  91.     InflateRect(&rc, -8, -8);
  92.  
  93.     if (!m_pPL->Init(m_hWnd, &rc, WS_CHILD | WS_VISIBLE
  94.         , ID_POLYLINE, m_pPLAdv))
  95.         return FALSE;
  96.  
  97.     return TRUE;
  98.     }
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106. /*
  107.  * CCosmoDoc::FMessageHook
  108.  *
  109.  * Purpose:
  110.  *  Processes WM_SIZE for the document so we can resize
  111.  *  the Polyline.
  112.  *
  113.  * Parameters:
  114.  *  <WndProc Parameters>
  115.  *  pLRes           LRESULT * in which to store the return
  116.  *                  value for the message.
  117.  *
  118.  * Return Value:
  119.  *  BOOL            TRUE to prevent further processing,
  120.  *                  FALSE otherwise.
  121.  */
  122.  
  123. BOOL CCosmoDoc::FMessageHook(HWND hWnd, UINT iMsg, WPARAM wParam
  124.     , LPARAM lParam, LRESULT *pLRes)
  125.     {
  126.     UINT        dx, dy;
  127.     RECT        rc;
  128.  
  129.     *pLRes=0;
  130.  
  131.     if (WM_SIZE==iMsg)
  132.         {
  133.         //Don't effect the Polyline size to or from minimized state.
  134.         if (SIZE_MINIMIZED!=wParam && SIZE_MINIMIZED !=m_uPrevSize)
  135.             {
  136.             //When we change size, resize any Polyline we hold.
  137.             dx=LOWORD(lParam);
  138.             dy=HIWORD(lParam);
  139.  
  140.             /*
  141.              * If we are getting WM_SIZE in response to a Polyline
  142.              * notification, then don't resize the Polyline window
  143.              * again.
  144.              */
  145.             if (!m_fNoSize && NULL!=m_pPL)
  146.                 {
  147.                 //Resize the polyline to fit the new client
  148.                 SetRect(&rc, 8, 8, dx-8, dy-8);
  149.                 m_pPL->RectSet(&rc, FALSE);
  150.  
  151.                 /*
  152.                  * We consider sizing something that makes the file
  153.                  * dirty, but not until we've finished the create
  154.                  * process, which is why we set fNoDirty to FALSE
  155.                  * in WM_CREATE since we get a WM_SIZE on the first
  156.                  * creation.
  157.                  */
  158.                 if (!m_fNoDirty)
  159.                     FDirtySet(TRUE);
  160.  
  161.                 SetRect(&rc, 0, 0, dx, dy);
  162.  
  163.                 if (NULL!=m_pAdv)
  164.                     m_pAdv->OnSizeChange(this, &rc);
  165.  
  166.                 m_fNoDirty=FALSE;
  167.                 }
  168.             }
  169.  
  170.         m_uPrevSize=wParam;
  171.         }
  172.  
  173.     /*
  174.      * We return FALSE even on WM_SIZE so we can let the default
  175.      * procedure handle maximized MDI child windows appropriately.
  176.      */
  177.     return FALSE;
  178.     }
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187. /*
  188.  * CCosmoDoc::Clear
  189.  *
  190.  * Purpose:
  191.  *  Sets all contents in the document back to defaults with
  192.  *  no filename.
  193.  *
  194.  * Paramters:
  195.  *  None
  196.  *
  197.  * Return Value:
  198.  *  None
  199.  */
  200.  
  201. void CCosmoDoc::Clear(void)
  202.     {
  203.     //Completely reset the polyline
  204.     m_pPL->New();
  205.  
  206.     CDocument::Clear();
  207.     m_lVer=0;
  208.     return;
  209.     }
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216. /*
  217.  * CCosmoDoc::Load
  218.  *
  219.  * Purpose:
  220.  *  Loads a given document without any user interface overwriting
  221.  *  the previous contents of the Polyline window.  We do this by
  222.  *  opening the file and telling the Polyline to load itself from
  223.  *  that file.
  224.  *
  225.  * Parameters:
  226.  *  fChangeFile     BOOL indicating if we're to update the window
  227.  *                  title and the filename from using this file.
  228.  *  pszFile         LPTSTR to the filename to load, NULL if the file
  229.  *                  is new and untitled.
  230.  *
  231.  * Return Value:
  232.  *  UINT            An error value from DOCERR_*
  233.  */
  234.  
  235. UINT CCosmoDoc::Load(BOOL fChangeFile, LPTSTR pszFile)
  236.     {
  237.     //CHAPTER7MOD
  238.     HRESULT         hr;
  239.     LPSTORAGE       pIStorage;
  240.     //End CHAPTER7MOD
  241.  
  242.     if (NULL==pszFile)
  243.         {
  244.         //For a new untitled document, just rename ourselves.
  245.         Rename(NULL);
  246.         m_lVer=VERSIONCURRENT;
  247.         return DOCERR_NONE;
  248.         }
  249.  
  250.     //CHAPTER7MOD
  251.     /*
  252.      * If not a Compound File, open the file using STGM_CONVERT in
  253.      * transacted mode to see old files as a storage with one stream
  254.      * called "CONTENTS" (which is conveniently the name we use
  255.      * in the new files).  We must use STGM_TRANSACTED here or else
  256.      * the old file will be immediately converted on disk:  we only
  257.      * want a converted image in memory from which to read.  In
  258.      * addition, note that we need STGM_READWRITE as well since
  259.      * conversion is inherently a write operation.
  260.      */
  261.  
  262.     pIStorage=NULL;
  263.  
  264.     if (NOERROR!=StgIsStorageFile(pszFile))
  265.         {
  266.         hr=StgCreateDocfile(pszFile,STGM_TRANSACTED | STGM_READWRITE
  267.             | STGM_CONVERT | STGM_SHARE_EXCLUSIVE, 0, &pIStorage);
  268.  
  269.         if (FAILED(hr))
  270.             {
  271.             //If denied write access, try to load the old way
  272.             if (STG_E_ACCESSDENIED==GetScode(hr))
  273.                 m_lVer=m_pPL->ReadFromFile(pszFile);
  274.             else
  275.                 return DOCERR_COULDNOTOPEN;
  276.             }
  277.         }
  278.     else
  279.         {
  280.         hr=StgOpenStorage(pszFile, NULL, STGM_DIRECT | STGM_READ
  281.             | STGM_SHARE_EXCLUSIVE, NULL, 0, &pIStorage);
  282.  
  283.         if (FAILED(hr))
  284.             return DOCERR_COULDNOTOPEN;
  285.         }
  286.  
  287.     if (NULL!=pIStorage)
  288.         {
  289.         m_lVer=m_pPL->ReadFromStorage(pIStorage);
  290.         pIStorage->Release();
  291.         }
  292.     //End CHAPTER7MOD
  293.  
  294.     if (POLYLINE_E_READFAILURE==m_lVer)
  295.         return DOCERR_READFAILURE;
  296.  
  297.     if (POLYLINE_E_UNSUPPORTEDVERSION==m_lVer)
  298.         return DOCERR_UNSUPPORTEDVERSION;
  299.  
  300.     if (fChangeFile)
  301.         Rename(pszFile);
  302.  
  303.     //Importing a file makes things dirty
  304.     FDirtySet(!fChangeFile);
  305.  
  306.     return DOCERR_NONE;
  307.     }
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315. /*
  316.  * CCosmoDoc::Save
  317.  *
  318.  * Purpose:
  319.  *  Writes the file to a known filename, requiring that the user has
  320.  *  previously used FileOpen or FileSaveAs to provide a filename.
  321.  *
  322.  * Parameters:
  323.  *  uType           UINT indicating the type of file the user
  324.  *                  requested to save in the File Save As dialog.
  325.  *  pszFile         LPTSTR under which to save.  If NULL, use the
  326.  *                  current name.
  327.  *
  328.  * Return Value:
  329.  *  UINT            An error value from DOCERR_*
  330.  */
  331.  
  332. UINT CCosmoDoc::Save(UINT uType, LPTSTR pszFile)
  333.     {
  334.     LONG        lVer, lRet;
  335.     UINT        uTemp;
  336.     BOOL        fRename=TRUE;
  337.     //CHAPTER7MOD
  338.     HRESULT     hr;
  339.     LPSTORAGE   pIStorage;
  340.     //End CHAPTER7MOD
  341.  
  342.     if (NULL==pszFile)
  343.         {
  344.         fRename=FALSE;
  345.         pszFile=m_szFile;
  346.         }
  347.  
  348.     /*
  349.      * Type 1 is the current version, type 2 is version 1.0 of the
  350.      * Polyline so we use this to send the right version to
  351.      * CPolyline::WriteToFile/WriteToStorage.
  352.      */
  353.  
  354.     switch (uType)
  355.         {
  356.         case 0:         //From Save, use loaded version.
  357.             lVer=m_lVer;
  358.             break;
  359.  
  360.         case 1:
  361.             lVer=VERSIONCURRENT;
  362.             break;
  363.  
  364.         case 2:
  365.             lVer=MAKELONG(0, 1);    //1.0
  366.             break;
  367.  
  368.         default:
  369.             return DOCERR_UNSUPPORTEDVERSION;
  370.         }
  371.  
  372.     /*
  373.      * If the version the user wants to save is different from the
  374.      * version that we loaded and m_lVer is not zero (new doc),
  375.      * then inform the user of the version change and verify.
  376.      */
  377.     if (0!=m_lVer && m_lVer!=lVer)
  378.         {
  379.         TCHAR       szMsg[128];
  380.  
  381.         wsprintf(szMsg, PSZ(IDS_VERSIONCHANGE)
  382.             , (UINT)HIWORD(m_lVer), (UINT)LOWORD(m_lVer)
  383.             , (UINT)HIWORD(lVer), (UINT)LOWORD(lVer));
  384.  
  385.         uTemp=MessageBox(m_hWnd, szMsg, PSZ(IDS_DOCUMENTCAPTION)
  386.             , MB_YESNOCANCEL);
  387.  
  388.         if (IDCANCEL==uTemp)
  389.             return DOCERR_CANCELLED;
  390.  
  391.         //If the user won't upgrade, revert to loaded version.
  392.         if (IDNO==uTemp)
  393.             lVer=m_lVer;
  394.         }
  395.  
  396.     //CHAPTER7MOD
  397.     /*
  398.      * Use old WriteToFile code for version 1 data, otherwise
  399.      * use structured storage through WriteToStorage.
  400.      */
  401.     if (lVer==MAKELONG(0, 1))
  402.         lRet=m_pPL->WriteToFile(pszFile, lVer);
  403.     else
  404.         {
  405.         hr=StgCreateDocfile(pszFile, STGM_DIRECT | STGM_READWRITE
  406.             | STGM_CREATE | STGM_SHARE_EXCLUSIVE, 0, &pIStorage);
  407.  
  408.         if (FAILED(hr))
  409.             return DOCERR_COULDNOTOPEN;
  410.  
  411.         //Mark this as one of our class
  412.         WriteClassStg(pIStorage, CLSID_CosmoFigure);
  413.  
  414.         //Write user-readable class information
  415.         WriteFmtUserTypeStg(pIStorage, m_cf
  416.             , PSZ(IDS_CLIPBOARDFORMAT));
  417.  
  418.         lRet=m_pPL->WriteToStorage(pIStorage, lVer);
  419.         pIStorage->Release();
  420.         }
  421.     //End CHAPTER7MOD
  422.  
  423.     if (POLYLINE_E_NONE!=lRet)
  424.         return DOCERR_WRITEFAILURE;
  425.  
  426.     //Saving makes us clean
  427.     FDirtySet(FALSE);
  428.  
  429.     //Update the known version of this document.
  430.     m_lVer=lVer;
  431.  
  432.     if (fRename)
  433.         Rename(pszFile);
  434.  
  435.     return DOCERR_NONE;
  436.     }
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443. /*
  444.  * CCosmoDoc::Undo
  445.  *
  446.  * Purpose:
  447.  *  Reverses a previous action.
  448.  *
  449.  * Parameters:
  450.  *  None
  451.  *
  452.  * Return Value:
  453.  *  None
  454.  */
  455.  
  456. void CCosmoDoc::Undo(void)
  457.     {
  458.     m_pPL->Undo();
  459.     return;
  460.     }
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467. /*
  468.  * CCosmoDoc::Clip
  469.  *
  470.  * Purpose:
  471.  *  Places a private format, a metafile, and a bitmap of the display
  472.  *  on the clipboard, optionally implementing Cut by deleting the
  473.  *  data in the current window after rendering.
  474.  *
  475.  * Parameters:
  476.  *  hWndFrame       HWND of the main window.
  477.  *  fCut            BOOL indicating cut (TRUE) or copy (FALSE).
  478.  *
  479.  * Return Value:
  480.  *  BOOL            TRUE if successful, FALSE otherwise.
  481.  */
  482.  
  483. BOOL CCosmoDoc::Clip(HWND hWndFrame, BOOL fCut)
  484.     {
  485.     BOOL            fRet=TRUE;
  486.     HGLOBAL         hMem;
  487.     UINT            i;
  488.  
  489.     //This array is so we can loop over the formats we provide.
  490.     static UINT     rgcf[3]={0, CF_METAFILEPICT, CF_BITMAP};
  491.     const UINT      cFormats=3;
  492.  
  493.     if (!OpenClipboard(hWndFrame))
  494.         return FALSE;
  495.  
  496.     //Clean out whatever junk is in the clipboard.
  497.     EmptyClipboard();
  498.  
  499.     rgcf[0]=m_cf;
  500.  
  501.     for (i=0; i < cFormats; i++)
  502.         {
  503.         //Copy private data first.
  504.         hMem=RenderFormat(rgcf[i]);
  505.  
  506.         if (NULL!=hMem)
  507.             SetClipboardData(rgcf[i], hMem);
  508.         else
  509.             fRet &=FALSE;
  510.         }
  511.  
  512.     //Free clipboard ownership.
  513.     CloseClipboard();
  514.  
  515.     //Delete our current data if "cut" succeeded.
  516.     if (fRet && fCut)
  517.         {
  518.         m_pPL->New();
  519.         FDirtySet(TRUE);
  520.         }
  521.  
  522.     return fRet;
  523.     }
  524.  
  525.  
  526.  
  527.  
  528.  
  529. /*
  530.  * CCosmoDoc::RenderFormat
  531.  *
  532.  * Purpose:
  533.  *  Renders a specific clipboard format into global memory.
  534.  *
  535.  * Parameters:
  536.  *  cf              UINT format to render.
  537.  *
  538.  * Return Value:
  539.  *  HGLOBAL         Global memory handle containing the data.
  540.  */
  541.  
  542. HGLOBAL CCosmoDoc::RenderFormat(UINT cf)
  543.     {
  544.     HGLOBAL     hMem;
  545.  
  546.     if (cf==m_cf)
  547.         {
  548.         m_pPL->DataGetMem(VERSIONCURRENT, &hMem);
  549.         return hMem;
  550.         }
  551.  
  552.     switch (cf)
  553.         {
  554.         case CF_METAFILEPICT:
  555.             return m_pPL->RenderMetafilePict();
  556.  
  557.         case CF_BITMAP:
  558.             return (HGLOBAL)m_pPL->RenderBitmap();
  559.         }
  560.  
  561.     return NULL;
  562.     }
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570. /*
  571.  * CCosmoDoc::FQueryPaste
  572.  *
  573.  * Purpose:
  574.  *  Determines if we can paste data from the clipboard.
  575.  *
  576.  * Parameters:
  577.  *  None
  578.  *
  579.  * Return Value:
  580.  *  BOOL            TRUE if data is available, FALSE otherwise.
  581.  */
  582.  
  583. BOOL CCosmoDoc::FQueryPaste(void)
  584.     {
  585.     return IsClipboardFormatAvailable(m_cf);
  586.     }
  587.  
  588.  
  589.  
  590.  
  591.  
  592. /*
  593.  * CCosmoDoc::Paste
  594.  *
  595.  * Purpose:
  596.  *  Retrieves the private data format from the clipboard and sets it
  597.  *  to the current figure in the editor window.
  598.  *
  599.  *  Note that if this function is called, then the clipboard format
  600.  *  is available because the Paste menu item is only enabled if the
  601.  *  format is present.
  602.  *
  603.  * Parameters:
  604.  *  hWndFrame       HWND of the main window.
  605.  *
  606.  * Return Value:
  607.  *  BOOL            TRUE if successful, FALSE otherwise.
  608.  */
  609.  
  610. BOOL CCosmoDoc::Paste(HWND hWndFrame)
  611.     {
  612.     HGLOBAL         hMem;
  613.     PPOLYLINEDATA   ppl;
  614.     BOOL            fRet=FALSE;
  615.  
  616.     if (!OpenClipboard(hWndFrame))
  617.         return FALSE;
  618.  
  619.     hMem=GetClipboardData(m_cf);
  620.  
  621.     if (NULL!=hMem)
  622.         {
  623.         ppl=(PPOLYLINEDATA)GlobalLock(hMem);
  624.  
  625.         //TRUE in wParam to cause PLN_SIZECHANGE notification
  626.         m_pPL->DataSet(ppl, FALSE, TRUE);
  627.         GlobalUnlock(hMem);
  628.  
  629.         FDirtySet(TRUE);
  630.         fRet=TRUE;
  631.         }
  632.  
  633.     CloseClipboard();
  634.     return fRet;
  635.     }
  636.  
  637.  
  638.  
  639.  
  640.  
  641.  
  642. /*
  643.  * CCosmoDoc::ColorSet
  644.  *
  645.  * Purpose:
  646.  *  Changes a color used in our contained Polyline.
  647.  *
  648.  * Parameters:
  649.  *  iColor          UINT index of the color to change.
  650.  *  cr              COLORREF new color.
  651.  *
  652.  * Return Value:
  653.  *  COLORREF        Previous color for the given index.
  654.  */
  655.  
  656. COLORREF CCosmoDoc::ColorSet(UINT iColor, COLORREF cr)
  657.     {
  658.     return m_pPL->ColorSet(iColor, cr);
  659.     }
  660.  
  661.  
  662.  
  663.  
  664.  
  665. /*
  666.  * CCosmoDoc::ColorGet
  667.  *
  668.  * Purpose:
  669.  *  Retrieves a color currently in use in the Polyline.
  670.  *
  671.  * Parameters:
  672.  *  iColor          UINT index of the color to retrieve.
  673.  *
  674.  * Return Value:
  675.  *  COLORREF        Current color for the given index.
  676.  */
  677.  
  678. COLORREF CCosmoDoc::ColorGet(UINT iColor)
  679.     {
  680.     return m_pPL->ColorGet(iColor);
  681.     }
  682.  
  683.  
  684.  
  685.  
  686.  
  687.  
  688. /*
  689.  * CCosmoDoc::LineStyleSet
  690.  *
  691.  * Purpose:
  692.  *  Changes the line style currently used in the Polyline
  693.  *
  694.  * Parameters:
  695.  *  iStyle          UINT index of the new line style to use.
  696.  *
  697.  * Return Value:
  698.  *  UINT            Previous line style.
  699.  */
  700.  
  701.  
  702. UINT CCosmoDoc::LineStyleSet(UINT iStyle)
  703.     {
  704.     return m_pPL->LineStyleSet(iStyle);
  705.     }
  706.  
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713. /*
  714.  * CCosmoDoc::LineStyleGet
  715.  *
  716.  * Purpose:
  717.  *  Retrieves the line style currently used in the Polyline
  718.  *
  719.  * Parameters:
  720.  *  None
  721.  *
  722.  * Return Value:
  723.  *  UINT            Current line style.
  724.  */
  725.  
  726.  
  727. UINT CCosmoDoc::LineStyleGet(void)
  728.     {
  729.     if (NULL==m_pPL)    //m_pPL might not be valid yet
  730.         return 0L;
  731.  
  732.     return m_pPL->LineStyleGet();
  733.     }
  734.  
  735.  
  736.  
  737.  
  738.  
  739.  
  740.  
  741.  
  742. /*
  743.  * CPolylineAdviseSink::CPolylineAdviseSink
  744.  * CPolylineAdviseSink::~CPolylineAdviseSink
  745.  *
  746.  * Constructor Parameters:
  747.  *  pv              LPVOID to store in this object
  748.  */
  749.  
  750. CPolylineAdviseSink::CPolylineAdviseSink(LPVOID pv)
  751.     {
  752.     m_pv=pv;
  753.     return;
  754.     }
  755.  
  756.  
  757. CPolylineAdviseSink::~CPolylineAdviseSink(void)
  758.     {
  759.     return;
  760.     }
  761.  
  762.  
  763.  
  764.  
  765.  
  766. /*
  767.  * CPolylineAdviseSink::OnPointChange
  768.  *
  769.  * Purpose:
  770.  *  Informs the document that the polyline added or removed a point.
  771.  *
  772.  * Parameters:
  773.  *  None
  774.  *
  775.  * Return Value:
  776.  *  None
  777.  */
  778.  
  779. void CPolylineAdviseSink::OnPointChange(void)
  780.     {
  781.     PCDocument      pDoc=(PCDocument)m_pv;
  782.  
  783.     pDoc->FDirtySet(TRUE);
  784.     return;
  785.     }
  786.  
  787.  
  788.  
  789.  
  790.  
  791.  
  792. /*
  793.  * CPolylineAdviseSink::OnSizeChange
  794.  *
  795.  * Purpose:
  796.  *  Informs the document that the polyline changed size.
  797.  *
  798.  * Parameters:
  799.  *  None
  800.  *
  801.  * Return Value:
  802.  *  None
  803.  */
  804.  
  805. void CPolylineAdviseSink::OnSizeChange(void)
  806.     {
  807.     PCCosmoDoc      pDoc=(PCCosmoDoc)m_pv;
  808.     RECT            rc;
  809.     DWORD           dwStyle;
  810.  
  811.     /*
  812.      * Polyline window is informing us that it changed size in
  813.      * response to setting it's data.  Therefore we have to
  814.      * size ourselves accordingly but without moving the screen
  815.      * position of the polyline window.
  816.      */
  817.  
  818.     pDoc->m_fNoSize=TRUE;
  819.  
  820.     //Set the document window size.
  821.     GetWindowRect(pDoc->m_pPL->Window(), &rc);
  822.     InflateRect(&rc, 8, 8);
  823.  
  824.     //Adjust for a window sans menu
  825.     dwStyle=GetWindowLong(pDoc->m_hWnd, GWL_STYLE);
  826.     AdjustWindowRect(&rc, dwStyle, FALSE);
  827.  
  828.     SetWindowPos(pDoc->m_hWnd, NULL, 0, 0, rc.right-rc.left
  829.         , rc.bottom-rc.top, SWP_NOMOVE | SWP_NOZORDER);
  830.  
  831.     if (NULL!=pDoc->m_pAdv)
  832.         pDoc->m_pAdv->OnSizeChange(pDoc, &rc);
  833.  
  834.     pDoc->m_fNoSize=FALSE;
  835.     pDoc->FDirtySet(TRUE);
  836.  
  837.     return;
  838.     }
  839.  
  840.  
  841.  
  842.  
  843.  
  844. /*
  845.  * CPolylineAdviseSink::OnDataChange
  846.  *
  847.  * Purpose:
  848.  *  Informs the document that the polyline data changed.
  849.  *
  850.  * Parameters:
  851.  *  None
  852.  *
  853.  * Return Value:
  854.  *  None
  855.  */
  856.  
  857. void CPolylineAdviseSink::OnDataChange(void)
  858.     {
  859.     PCCosmoDoc      pDoc=(PCCosmoDoc)m_pv;
  860.  
  861.     if (NULL!=pDoc->m_pAdv)
  862.         pDoc->m_pAdv->OnDataChange(pDoc);
  863.  
  864.     pDoc->FDirtySet(TRUE);
  865.     return;
  866.     }
  867.  
  868.  
  869.  
  870.  
  871.  
  872. /*
  873.  * CPolylineAdviseSink::OnColorChange
  874.  *
  875.  * Purpose:
  876.  *  Informs the document that the polyline data changed a color.
  877.  *
  878.  * Parameters:
  879.  *  None
  880.  *
  881.  * Return Value:
  882.  *  None
  883.  */
  884.  
  885. void CPolylineAdviseSink::OnColorChange(void)
  886.     {
  887.     PCCosmoDoc      pDoc=(PCCosmoDoc)m_pv;
  888.  
  889.     pDoc->FDirtySet(TRUE);
  890.     return;
  891.     }
  892.  
  893.  
  894.  
  895.  
  896.  
  897. /*
  898.  * CPolylineAdviseSink::OnLineStyleChange
  899.  *
  900.  * Purpose:
  901.  *  Informs the document that the polyline changed its line style.
  902.  *
  903.  * Parameters:
  904.  *  None
  905.  *
  906.  * Return Value:
  907.  *  None
  908.  */
  909.  
  910. void CPolylineAdviseSink::OnLineStyleChange(void)
  911.     {
  912.     PCCosmoDoc      pDoc=(PCCosmoDoc)m_pv;
  913.  
  914.     pDoc->FDirtySet(TRUE);
  915.     return;
  916.     }
  917.