home *** CD-ROM | disk | FTP | other *** search
/ ActiveX Programming Unleashed CD / AXU.iso / source / chap04 / lst42 / srvritem.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-26  |  3.0 KB  |  108 lines

  1. // SrvrItem.cpp : implementation of the CLst42SrvrItem class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "lst42.h"
  6.  
  7. #include "lst42Doc.h"
  8. #include "SrvrItem.h"
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CLst42SrvrItem implementation
  18.  
  19. IMPLEMENT_DYNAMIC(CLst42SrvrItem, COleServerItem)
  20.  
  21. CLst42SrvrItem::CLst42SrvrItem(CLst42Doc* pContainerDoc)
  22.     : COleServerItem(pContainerDoc, TRUE)
  23. {
  24.     // TODO: add one-time construction code here
  25.     //  (eg, adding additional clipboard formats to the item's data source)
  26. }
  27.  
  28. CLst42SrvrItem::~CLst42SrvrItem()
  29. {
  30.     // TODO: add cleanup code here
  31. }
  32.  
  33. void CLst42SrvrItem::Serialize(CArchive& ar)
  34. {
  35.     // CLst42SrvrItem::Serialize will be called by the framework if
  36.     //  the item is copied to the clipboard.  This can happen automatically
  37.     //  through the OLE callback OnGetClipboardData.  A good default for
  38.     //  the embedded item is simply to delegate to the document's Serialize
  39.     //  function.  If you support links, then you will want to serialize
  40.     //  just a portion of the document.
  41.  
  42.     if (!IsLinkedItem())
  43.     {
  44.         CLst42Doc* pDoc = GetDocument();
  45.         ASSERT_VALID(pDoc);
  46.         pDoc->Serialize(ar);
  47.     }
  48. }
  49.  
  50. BOOL CLst42SrvrItem::OnGetExtent(DVASPECT dwDrawAspect, CSize& rSize)
  51. {
  52.     // Most applications, like this one, only handle drawing the content
  53.     //  aspect of the item.  If you wish to support other aspects, such
  54.     //  as DVASPECT_THUMBNAIL (by overriding OnDrawEx), then this
  55.     //  implementation of OnGetExtent should be modified to handle the
  56.     //  additional aspect(s).
  57.  
  58.     if (dwDrawAspect != DVASPECT_CONTENT)
  59.         return COleServerItem::OnGetExtent(dwDrawAspect, rSize);
  60.  
  61.     // CLst42SrvrItem::OnGetExtent is called to get the extent in
  62.     //  HIMETRIC units of the entire item.  The default implementation
  63.     //  here simply returns a hard-coded number of units.
  64.  
  65.     CLst42Doc* pDoc = GetDocument();
  66.     ASSERT_VALID(pDoc);
  67.  
  68.     // TODO: replace this arbitrary size
  69.  
  70.     rSize = CSize(3000, 3000);   // 3000 x 3000 HIMETRIC units
  71.  
  72.     return TRUE;
  73. }
  74.  
  75. BOOL CLst42SrvrItem::OnDraw(CDC* pDC, CSize& rSize)
  76. {
  77.     CLst42Doc* pDoc = GetDocument();
  78.     ASSERT_VALID(pDoc);
  79.  
  80.     // TODO: set mapping mode and extent
  81.     //  (The extent is usually the same as the size returned from OnGetExtent)
  82.     pDC->SetMapMode(MM_ANISOTROPIC);
  83.     pDC->SetWindowOrg(0,0);
  84.     pDC->SetWindowExt(3000, 3000);
  85.  
  86.     // TODO: add drawing code here.  Optionally, fill in the HIMETRIC extent.
  87.     //  All drawing takes place in the metafile device context (pDC).
  88.  
  89.     return TRUE;
  90. }
  91.  
  92. /////////////////////////////////////////////////////////////////////////////
  93. // CLst42SrvrItem diagnostics
  94.  
  95. #ifdef _DEBUG
  96. void CLst42SrvrItem::AssertValid() const
  97. {
  98.     COleServerItem::AssertValid();
  99. }
  100.  
  101. void CLst42SrvrItem::Dump(CDumpContext& dc) const
  102. {
  103.     COleServerItem::Dump(dc);
  104. }
  105. #endif
  106.  
  107. /////////////////////////////////////////////////////////////////////////////
  108.