home *** CD-ROM | disk | FTP | other *** search
/ Mastering Microsoft Visual C++ 4 (2nd Edition) / VisualC4.ISO / servdemo / srvritem.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-30  |  3.5 KB  |  117 lines

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