home *** CD-ROM | disk | FTP | other *** search
/ ActiveX Programming Unleashed CD / AXU.iso / source / chap18 / doserver / srvritem.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-14  |  3.5 KB  |  117 lines

  1. // SrvrItem.cpp : implementation of the CDoServerSrvrItem class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "DoServer.h"
  6.  
  7. #include "DoServerDoc.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. // CDoServerSrvrItem implementation
  18.  
  19. IMPLEMENT_DYNAMIC(CDoServerSrvrItem, CDocObjectServerItem)    // DocObject modification
  20.  
  21. CDoServerSrvrItem::CDoServerSrvrItem(CDoServerDoc* pContainerDoc)
  22.     : CDocObjectServerItem(pContainerDoc, TRUE)                // DocObject modification
  23. {
  24.     // TODO: add one-time construction code here
  25.     //  (eg, adding additional clipboard formats to the item's data source)
  26. }
  27.  
  28. CDoServerSrvrItem::~CDoServerSrvrItem()
  29. {
  30.     // TODO: add cleanup code here
  31. }
  32.  
  33. void CDoServerSrvrItem::Serialize(CArchive& ar)
  34. {
  35.     // CDoServerSrvrItem::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.         CDoServerDoc* pDoc = GetDocument();
  45.         ASSERT_VALID(pDoc);
  46.         pDoc->Serialize(ar);
  47.     }
  48. }
  49.  
  50. BOOL CDoServerSrvrItem::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.     // CDoServerSrvrItem::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.     CDoServerDoc* pDoc = GetDocument();
  66.     ASSERT_VALID(pDoc);
  67.  
  68.     // TODO: replace this arbitrary size
  69.     CClientDC dc(NULL);                                // OLE server addition
  70.     dc.SetMapMode(MM_ANISOTROPIC);                    // OLE server addition
  71.     pDoc->GetExtent(&dc, rSize);                    // OLE server addition
  72.     dc.LPtoHIMETRIC(&rSize);                        // OLE server addition
  73.  
  74. //    rSize = CSize(3000, 3000);   // 3000 x 3000 HIMETRIC units
  75.  
  76.     return TRUE;
  77. }
  78.  
  79. BOOL CDoServerSrvrItem::OnDraw(CDC* pDC, CSize& rSize)
  80. {
  81.     CDoServerDoc* pDoc = GetDocument();
  82.     ASSERT_VALID(pDoc);
  83.  
  84.     // TODO: set mapping mode and extent
  85.     //  (The extent is usually the same as the size returned from OnGetExtent)
  86.  
  87.     OnGetExtent(DVASPECT_CONTENT, rSize);            // OLE server addition
  88.     pDC->SetMapMode(MM_ANISOTROPIC);
  89.     pDC->SetWindowOrg(0,0);
  90.     pDC->SetWindowExt(rSize.cx, rSize.cy);            // OLE server addition
  91. //    pDC->SetWindowExt(3000, 3000);
  92.  
  93.     // TODO: add drawing code here.  Optionally, fill in the HIMETRIC extent.
  94.     //  All drawing takes place in the metafile device context (pDC).
  95.  
  96.     pDoc->Draw(pDC);                                // OLE server addition
  97.  
  98.     return TRUE;
  99. }
  100.  
  101. /////////////////////////////////////////////////////////////////////////////
  102. // CDoServerSrvrItem diagnostics
  103.  
  104. #ifdef _DEBUG
  105. void CDoServerSrvrItem::AssertValid() const
  106. {
  107.     COleServerItem::AssertValid();
  108. }
  109.  
  110. void CDoServerSrvrItem::Dump(CDumpContext& dc) const
  111. {
  112.     COleServerItem::Dump(dc);
  113. }
  114. #endif
  115.  
  116. /////////////////////////////////////////////////////////////////////////////
  117.