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 / chap14 / cosmo / document.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  21.3 KB  |  1,027 lines

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