home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / activexcontrol / basectl / todosvr / iodoc.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-05  |  4.3 KB  |  133 lines

  1. //=--------------------------------------------------------------------------=
  2. // IODoc.Cpp
  3. //=--------------------------------------------------------------------------=
  4. // Copyright 1995-1997 Microsoft Corporation.  All Rights Reserved.
  5. //
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 
  7. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 
  8. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 
  9. // PARTICULAR PURPOSE.
  10. //=--------------------------------------------------------------------------=
  11. //
  12. // implementation of the IOleDocument interface for CDocumentObject.
  13. //
  14. #include "CDocObj.H"
  15.  
  16. // for ASSERT and FAIL
  17. //
  18. SZTHISFILE
  19.  
  20. //=--------------------------------------------------------------------------=
  21. // CDocumentObject::CreateView    [IOleDocument]
  22. //=--------------------------------------------------------------------------=
  23. // asks the document object to create a new view sub-object
  24. //
  25. // Parameters:
  26. //    IOleInPlaceSite *   - [in] pointer to container's view site object
  27. //    IStream*            - [in] pointer to stream to initialize view with
  28. //    DWORD               - [in] reserved
  29. //    IOleDocumentView*   - [out] address to put interface pointer to new view
  30. //
  31. // Output:
  32. //    HRESULT             - S_OK, E_POINTER, E_OUTOFMEMORY, E_UNEXPECTED, 
  33. //                          E_FAIL
  34. //
  35. // Notes: 
  36. //      This implementation only supports a single view!
  37. //
  38. STDMETHODIMP CDocumentObject::CreateView(IOleInPlaceSite* pIPSite, IStream* pstm, 
  39.                                          DWORD dwReserved, IOleDocumentView** ppView)
  40. {
  41.     TRACE("\nEntering CDocumentObject::CreateView");
  42.  
  43.     *ppView = NULL;
  44.  
  45.     if (dwReserved != 0 || m_pDocSite == NULL)
  46.         return E_UNEXPECTED;
  47.  
  48.     // We only support a single view...so if view site is already
  49.     // set, fail.
  50.     if (m_pViewSite != NULL)
  51.         return E_FAIL;
  52.  
  53.  
  54.     // Otherwise, connect the view site to our object
  55.     IOleDocumentView* pView = NULL;
  56.     InternalQueryInterface(IID_IOleDocumentView, (void**)&pView);
  57.     ASSERT(pView != NULL, "object must support IID_IOleDocumentView");
  58.  
  59.     HRESULT hr = pView->SetInPlaceSite(pIPSite);
  60.     if (SUCCEEDED(hr))
  61.     {
  62.         // Return the IOleDocumentView pointer 
  63.         *ppView = pView;
  64.  
  65.         // If a saved view state is provided, restore the view state.
  66.         if (pstm)
  67.             hr = pView->ApplyViewState(pstm);
  68.     }
  69.     else
  70.         pView->Release();
  71.  
  72.     TRACE("\nLeaving CDocumentObject::CreateView");
  73.  
  74.     return hr;
  75.  
  76. }
  77.  
  78. //=--------------------------------------------------------------------------=
  79. // CDocumentObject::GetDocMiscStatus    [IOleDocument]
  80. //=--------------------------------------------------------------------------=
  81. // returns miscellaneous status bits describing the document object
  82. //
  83. // Parameters:
  84. //    DWORD *   - [out] address to put misc status bits in
  85. //
  86. // Output:
  87. //    HRESULT   - S_OK, E_POINTER
  88. //
  89. // Notes:
  90. //
  91. STDMETHODIMP CDocumentObject::GetDocMiscStatus(DWORD* pdwStatus)
  92. {
  93.     TRACE("\nCDocumentObject::GetDocMiscStatus");
  94.  
  95.     if (pdwStatus)
  96.     {
  97.         // m_ObjectType (from base class CAutomationObject) is the 
  98.         // index into the global object table...
  99.         *pdwStatus = MISCFLAGSOFDOCOBJECT(m_ObjectType);
  100.         return S_OK;
  101.     }
  102.     else
  103.         return E_POINTER;
  104. }
  105.  
  106. //=--------------------------------------------------------------------------=
  107. // CDocumentObject::EnumViews    [IOleDocument]
  108. //=--------------------------------------------------------------------------=
  109. // creates an enumerator object that enumerates the views of the document object
  110. //
  111. // Parameters:
  112. //    IEnumOleDocumentViews**   - [out] address to put enumerator interface
  113. //    IOleDocumentView**        - [out] address to store single view interface 
  114. //
  115. // Output:
  116. //    HRESULT             - S_OK, E_POINTER, E_OUTOFMEMORY
  117. //
  118. // Notes:
  119. //      This implementation only supports a single view!   
  120. //
  121. STDMETHODIMP CDocumentObject::EnumViews(IEnumOleDocumentViews** ppEnum, 
  122.                                         IOleDocumentView** ppView)
  123. {
  124.     TRACE("\nCDocumentObject::EnumViews");
  125.  
  126.     if (!ppEnum || !ppView)
  127.         return E_POINTER;
  128.  
  129.     // Retrieve pointer to our single view
  130.     *ppEnum = NULL;
  131.     return InternalQueryInterface(IID_IOleDocumentView, (void**)ppView);
  132. }
  133.