home *** CD-ROM | disk | FTP | other *** search
/ ActiveX Programming Unleashed CD / AXU.iso / source / chap18 / doserver / binddoc.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-02  |  3.4 KB  |  129 lines

  1. // binddoc.cpp : implementation of the DocObject 
  2. //    OLE server document class
  3. //
  4. // This is a part of the Microsoft Foundation Classes C++ library.
  5. // Copyright (C) 1992-1995 Microsoft Corporation
  6. // All rights reserved.
  7. //
  8. // This source code is only intended as a supplement to the
  9. // Microsoft Foundation Classes Reference and related
  10. // electronic documentation provided with the library.
  11. // See these sources for detailed information regarding the
  12. // Microsoft Foundation Classes product.
  13.  
  14. //BINDER
  15. // CDocObjectServerDoc subclasses MFC's COleServerDoc to add binder-compatible
  16. // OLE interfaces to the class.  The code here declares those extra
  17. // interfaces, provides a rudimentary default command map, and manages
  18. // any IOleDocumentViews active against this document instance.
  19. //BINDER_END
  20.  
  21. #include "stdafx.h"
  22. #include "binddoc.h"
  23.  
  24. #ifdef _DEBUG
  25. #undef THIS_FILE
  26. static char BASED_CODE THIS_FILE[] = __FILE__;
  27. #endif
  28.  
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CDocObjectServerDoc
  31.  
  32. IMPLEMENT_DYNAMIC(CDocObjectServerDoc, COleServerDoc)
  33.  
  34. BEGIN_MESSAGE_MAP(CDocObjectServerDoc, COleServerDoc)
  35.     //{{AFX_MSG_MAP(CDocObjectServerDoc)
  36.         // NOTE - the ClassWizard will add and remove mapping macros here.
  37.     //}}AFX_MSG_MAP
  38. END_MESSAGE_MAP()
  39.  
  40. BEGIN_INTERFACE_MAP(CDocObjectServerDoc, COleServerDoc)
  41.    INTERFACE_PART(CDocObjectServerDoc, IID_IOleObject, DocOleObject)
  42.    INTERFACE_PART(CDocObjectServerDoc, IID_IOleDocument, OleDocument)
  43.    INTERFACE_PART(CDocObjectServerDoc, IID_IOleDocumentView, OleDocumentView)
  44.    INTERFACE_PART(CDocObjectServerDoc, IID_IOleCommandTarget, OleCommandTarget)
  45.    INTERFACE_PART(CDocObjectServerDoc, IID_IPrint, Print)
  46. END_INTERFACE_MAP()
  47.  
  48. // root of OLECMD map can't use BEGIN_OLECMD_MAP macro
  49. const AFX_DATADEF OLE_CMDMAP CDocObjectServerDoc::commandMap =
  50. {
  51. #ifdef _AFXDLL
  52.     &CDocObjectServerDoc::_GetBaseCommandMap,
  53. #else
  54.     NULL,
  55. #endif
  56.     &CDocObjectServerDoc::_commandEntries[0]
  57. };
  58.  
  59. #ifdef _AFXDLL
  60. const OLE_CMDMAP* CDocObjectServerDoc::_GetBaseCommandMap()
  61. {
  62.     return NULL;
  63. }
  64. #endif
  65.  
  66. const OLE_CMDMAP* CDocObjectServerDoc::GetCommandMap() const
  67. {
  68.     return &CDocObjectServerDoc::commandMap;
  69. }
  70.  
  71. const OLE_CMDMAP_ENTRY CDocObjectServerDoc::_commandEntries[] =
  72. {
  73.    { NULL, OLECMDID_SAVEAS, ID_FILE_SAVE_AS },  // ON_OLECMD()
  74.    { NULL, 0, 0 }                               // END_OLECMD_MAP()   
  75. };
  76.  
  77. CDocObjectServerDoc::CDocObjectServerDoc()
  78. {
  79.    // Initialize DocObject data
  80.    m_pDocSite  = NULL;
  81.    m_pViewSite = NULL;
  82.  
  83.    // All Binder-Compatible documents use Compound Files as their 
  84.    // storage mechanism
  85.    EnableCompoundFile(TRUE);
  86. }
  87.  
  88. CDocObjectServerDoc::~CDocObjectServerDoc()
  89. {
  90.     if (m_pDocSite)
  91.       m_pDocSite->Release();
  92. }
  93.  
  94. void CDocObjectServerDoc::OnCloseDocument() 
  95. {
  96.     // Clean up pointer to document site, if any
  97.     if (m_pDocSite)
  98.     {
  99.       m_pDocSite->Release();
  100.       m_pDocSite = NULL;
  101.     }    
  102.     COleServerDoc::OnCloseDocument();
  103. }
  104.  
  105. void CDocObjectServerDoc::ActivateDocObject()
  106. {
  107.    if (IsDocObject())
  108.    {
  109.       ASSERT(m_pDocSite != NULL);
  110.       m_pDocSite->ActivateMe(NULL);
  111.    }
  112. }
  113.  
  114. #ifdef _DEBUG
  115. void CDocObjectServerDoc::AssertValid() const
  116. {
  117.     COleServerDoc::AssertValid();
  118. }
  119.  
  120. void CDocObjectServerDoc::Dump(CDumpContext& dc) const
  121. {
  122.     COleServerDoc::Dump(dc);
  123.     dc << "m_pDocSite = " << m_pDocSite << "\n";
  124.     dc << "m_pViewSite = " << m_pViewSite << "\n";
  125. }
  126. #endif //_DEBUG
  127.  
  128.  
  129.