home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / ole / bindscrb / scribitm.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  3.4 KB  |  123 lines

  1. // scribitm.cpp : implementation of the CScribItem class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1998 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 BASED_CODE THIS_FILE[] = __FILE__;
  22. #endif
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CScribItem implementation
  26.  
  27. IMPLEMENT_DYNAMIC(CScribItem, CDocObjectServerItem)
  28.  
  29. CScribItem::CScribItem(CScribDoc* pContainerDoc)
  30.     : CDocObjectServerItem(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. CScribItem::~CScribItem()
  37. {
  38.     // TODO: add cleanup code here
  39. }
  40.  
  41. void CScribItem::Serialize(CArchive& ar)
  42. {
  43.     // CScribItem::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.         CScribDoc* pDoc = GetDocument();
  53.         ASSERT_VALID(pDoc);
  54.         pDoc->Serialize(ar);
  55.     }
  56. }
  57.  
  58. BOOL CScribItem::OnGetExtent(DVASPECT dwDrawAspect, CSize& rSize)
  59. {
  60.     // This implementation of CScribItem::OnGetExtent only handles
  61.     //  the "content" aspect indicated by DVASPECT_CONTENT.
  62.  
  63.     if (dwDrawAspect != DVASPECT_CONTENT)
  64.         return COleServerItem::OnGetExtent(dwDrawAspect, rSize);
  65.  
  66.     // CScribItem::OnGetExtent is called to get the extent in
  67.     //  HIMETRIC units of the entire item.  The default implementation
  68.     //  here simply returns a hard-coded number of units.
  69.  
  70.     CScribDoc* pDoc = GetDocument();
  71.     ASSERT_VALID(pDoc);
  72.  
  73.     rSize = pDoc->GetDocSize();
  74.     CClientDC dc(NULL);
  75.  
  76.     // set a MM_LOENGLISH based on logical inches
  77.     //  (we can't use MM_LOENGLISH because MM_LOENGLISH uses physical inches)
  78.     dc.SetMapMode(MM_ANISOTROPIC);
  79.     dc.SetViewportExt(dc.GetDeviceCaps(LOGPIXELSX), dc.GetDeviceCaps(LOGPIXELSY));
  80.     dc.SetWindowExt(100, -100);
  81.     dc.LPtoHIMETRIC(&rSize);
  82.  
  83.     return TRUE;
  84. }
  85.  
  86. BOOL CScribItem::OnDraw(CDC* pDC, CSize& /* rSize */)
  87. {
  88.     CScribDoc* pDoc = GetDocument();
  89.     ASSERT_VALID(pDoc);
  90.  
  91.     pDC->SetMapMode(MM_ANISOTROPIC);
  92.     CSize sizeDoc = pDoc->GetDocSize();
  93.     sizeDoc.cy = -sizeDoc.cy;
  94.     pDC->SetWindowOrg(0,0);
  95.     pDC->SetWindowExt(sizeDoc);
  96.  
  97.     CTypedPtrList<CObList,CStroke*>& strokeList = pDoc->m_strokeList;
  98.     POSITION pos = strokeList.GetHeadPosition();
  99.     while (pos != NULL)
  100.     {
  101.         strokeList.GetNext(pos)->DrawStroke(pDC);
  102.     }
  103.  
  104.     return TRUE;
  105. }
  106.  
  107. /////////////////////////////////////////////////////////////////////////////
  108. // CScribItem diagnostics
  109.  
  110. #ifdef _DEBUG
  111. void CScribItem::AssertValid() const
  112. {
  113.     COleServerItem::AssertValid();
  114. }
  115.  
  116. void CScribItem::Dump(CDumpContext& dc) const
  117. {
  118.     COleServerItem::Dump(dc);
  119. }
  120. #endif
  121.  
  122. /////////////////////////////////////////////////////////////////////////////
  123.