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

  1. // binddcmt.cpp : implementation of the DocObject OLE
  2. //        server document class IOleDocument interface
  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. // This file contains the core implementation of the binder document.
  16. // The IOleDocument interface can manage views of the document.
  17. //BINDER_END
  18.  
  19. #include "stdafx.h"
  20. #include "binddoc.h"
  21.  
  22. #ifdef _DEBUG
  23. #undef THIS_FILE
  24. static char BASED_CODE THIS_FILE[] = __FILE__;
  25. #endif
  26.  
  27. STDMETHODIMP_(ULONG) CDocObjectServerDoc::XOleDocument::AddRef()
  28. {
  29.     METHOD_PROLOGUE_EX(CDocObjectServerDoc, OleDocument)
  30.     return pThis->ExternalAddRef();
  31. }
  32.  
  33. STDMETHODIMP_(ULONG) CDocObjectServerDoc::XOleDocument::Release()
  34. {
  35.     METHOD_PROLOGUE_EX(CDocObjectServerDoc, OleDocument)
  36.     return pThis->ExternalRelease();
  37. }
  38.  
  39. STDMETHODIMP CDocObjectServerDoc::XOleDocument::QueryInterface(
  40.     REFIID iid, LPVOID* ppvObj)
  41. {
  42.     METHOD_PROLOGUE_EX(CDocObjectServerDoc, OleDocument)
  43.     return pThis->ExternalQueryInterface(&iid, ppvObj);
  44. }
  45.  
  46. STDMETHODIMP CDocObjectServerDoc::XOleDocument::CreateView(
  47.    LPOLEINPLACESITE pipsite, LPSTREAM pstm, 
  48.    DWORD dwReserved, LPOLEDOCUMENTVIEW* ppview)
  49. {
  50.    METHOD_PROLOGUE_EX(CDocObjectServerDoc, OleDocument)
  51.    ASSERT_VALID(pThis);
  52.  
  53.    *ppview = NULL;
  54.  
  55.    HRESULT hr = E_FAIL;
  56.  
  57.    if (dwReserved == 0 && pThis->m_pDocSite != NULL)
  58.    {
  59.       // We only support a single view...so if view site is already
  60.       // set, fail.
  61.       if (pThis->m_pViewSite == NULL)
  62.       {
  63.          LPOLEDOCUMENTVIEW pView =
  64.             (LPOLEDOCUMENTVIEW)pThis->GetInterface(&IID_IOleDocumentView);
  65.          ASSERT(pView != NULL);
  66.  
  67.          // Set the site for the view
  68.          hr = pView->SetInPlaceSite(pipsite);
  69.          if (hr == NOERROR)
  70.          {
  71.             // Return the IOleDocumentView pointer 
  72.             pView->AddRef();
  73.             *ppview = pView;
  74.          }
  75.  
  76.          // If a saved view state is provided, restore the view state
  77.          if (pstm)
  78.             hr = pView->ApplyViewState(pstm);
  79.       }
  80.       else
  81.          TRACE0("CDocObjectServerDoc::XOleDocument::CreateView view already exists!\n");
  82.    }
  83.  
  84.    return hr;
  85. }
  86.  
  87. STDMETHODIMP CDocObjectServerDoc::XOleDocument::GetDocMiscStatus( 
  88.    LPDWORD pdwStatus)
  89. {
  90.    METHOD_PROLOGUE_EX(CDocObjectServerDoc, OleDocument)
  91.    ASSERT_VALID(pThis);
  92.    ASSERT(pdwStatus != NULL);
  93.  
  94.    // Our implementation of DocObjects can't create multiple views,
  95.    // does not support complex rectangles, supports open editing,
  96.    // and supports read/write to a file. Thus DOCMISC == 0.
  97.    *pdwStatus = 0;
  98.  
  99.    return NOERROR;
  100. }
  101.         
  102. STDMETHODIMP CDocObjectServerDoc::XOleDocument::EnumViews( 
  103.    LPENUMOLEDOCUMENTVIEWS* ppEnumView, LPOLEDOCUMENTVIEW* ppView)
  104. {
  105.    METHOD_PROLOGUE_EX(CDocObjectServerDoc, OleDocument)
  106.    ASSERT_VALID(pThis);
  107.    ASSERT(ppEnumView != NULL);
  108.    ASSERT(ppView != NULL);
  109.  
  110.    // We only support a single view
  111.    *ppEnumView = NULL;
  112.    HRESULT hr = QueryInterface(IID_IOleDocumentView, (LPVOID*)ppView);
  113.  
  114.    return hr;
  115. }
  116.         
  117.