home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / SCRIB7.PAK / SCRIBITM.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  3.6 KB  |  126 lines

  1. // ScribItm.cpp : implementation of the CScribbleItem class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1995 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "Scribble.h"
  15.  
  16. #include "ScribDoc.h"
  17. #include "ScribItm.h"
  18.  
  19. #ifdef _DEBUG
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CScribbleItem implementation
  26.  
  27. IMPLEMENT_DYNAMIC(CScribbleItem, COleServerItem)
  28.  
  29. CScribbleItem::CScribbleItem(CScribbleDoc* pContainerDoc)
  30.     : COleServerItem(pContainerDoc, TRUE)
  31. {
  32.     // TODO: add one-time construction code here
  33.     //  (eg, adding additional clipboard formats to the item's data source)
  34. }
  35.  
  36. CScribbleItem::~CScribbleItem()
  37. {
  38.     // TODO: add cleanup code here
  39. }
  40.  
  41. void CScribbleItem::Serialize(CArchive& ar)
  42. {
  43.     // CScribbleItem::Serialize will be called by the framework if
  44.     //  the item is copied to the clipboard.  This can happen automatically
  45.     //  through the OLE callback OnGetClipboardData.  A good default for
  46.     //  the embedded item is simply to delegate to the document's Serialize
  47.     //  function.  If you support links, then you will want to serialize
  48.     //  just a portion of the document.
  49.  
  50.     if (!IsLinkedItem())
  51.     {
  52.         CScribbleDoc* pDoc = GetDocument();
  53.         ASSERT_VALID(pDoc);
  54.         pDoc->Serialize(ar);
  55.     }
  56. }
  57.  
  58. BOOL CScribbleItem::OnGetExtent(DVASPECT dwDrawAspect, CSize& rSize)
  59. {
  60.     // Most applications, like this one, only handle drawing the content
  61.     //  aspect of the item.  If you wish to support other aspects, such
  62.     //  as DVASPECT_THUMBNAIL (by overriding OnDrawEx), then this
  63.     //  implementation of OnGetExtent should be modified to handle the
  64.     //  additional aspect(s).
  65.  
  66.     if (dwDrawAspect != DVASPECT_CONTENT)
  67.         return COleServerItem::OnGetExtent(dwDrawAspect, rSize);
  68.  
  69.     // CScribbleItem::OnGetExtent is called to get the extent in
  70.     //  HIMETRIC units of the entire item.  The default implementation
  71.     //  here simply returns a hard-coded number of units.
  72.  
  73.     CScribbleDoc* pDoc = GetDocument();
  74.     ASSERT_VALID(pDoc);
  75.  
  76.     rSize = pDoc->GetDocSize();
  77.     CClientDC dc(NULL);
  78.  
  79.         // use a mapping mode based on logical units
  80.     //  (we can't use MM_LOENGLISH because MM_LOENGLISH uses physical inches)
  81.     dc.SetMapMode(MM_ANISOTROPIC);
  82.     dc.SetViewportExt(dc.GetDeviceCaps(LOGPIXELSX), dc.GetDeviceCaps(LOGPIXELSY));
  83.     dc.SetWindowExt(100, -100);
  84.     dc.LPtoHIMETRIC(&rSize);
  85.  
  86.     return TRUE;
  87. }
  88.  
  89. BOOL CScribbleItem::OnDraw(CDC* pDC, CSize& /* rSize */)
  90. {
  91.     CScribbleDoc* pDoc = GetDocument();
  92.     ASSERT_VALID(pDoc);
  93.  
  94.     pDC->SetMapMode(MM_ANISOTROPIC);
  95.     CSize sizeDoc = pDoc->GetDocSize();
  96.     sizeDoc.cy = -sizeDoc.cy;
  97.     pDC->SetWindowOrg(0,0);
  98.     pDC->SetWindowExt(sizeDoc);
  99.  
  100.     CTypedPtrList<CObList,CStroke*>& strokeList = pDoc->m_strokeList;
  101.     POSITION pos = strokeList.GetHeadPosition();
  102.     while (pos != NULL)
  103.     {
  104.         strokeList.GetNext(pos)->DrawStroke(pDC);
  105.     }
  106.  
  107.     return TRUE;
  108. }
  109.  
  110. /////////////////////////////////////////////////////////////////////////////
  111. // CScribbleItem diagnostics
  112.  
  113. #ifdef _DEBUG
  114. void CScribbleItem::AssertValid() const
  115. {
  116.     COleServerItem::AssertValid();
  117. }
  118.  
  119. void CScribbleItem::Dump(CDumpContext& dc) const
  120. {
  121.     COleServerItem::Dump(dc);
  122. }
  123. #endif
  124.  
  125. /////////////////////////////////////////////////////////////////////////////
  126.