Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
3.4 KiB

  1. /*
  2. * IDOCSITE.CPP
  3. * IOleDocumentSite for Document Objects CSite class
  4. *
  5. * Copyright (c)1995-1999 Microsoft Corporation, All Rights Reserved
  6. */
  7. #include "stdafx.h"
  8. #include <docobj.h>
  9. #include "DHTMLEd.h"
  10. #include "DHTMLEdit.h"
  11. #include "site.h"
  12. #include "proxyframe.h"
  13. /**
  14. Note: the m_cRef count is provided for debugging purposes only.
  15. CSite controls the destruction of the object through delete,
  16. not reference counting
  17. */
  18. /*
  19. * CImpIOleDocumentSite::CImpIOleDocumentSite
  20. * CImpIOleDocumentSite::~CImpIOleDocumentSite
  21. *
  22. * Parameters (Constructor):
  23. * pSite PCSite of the site we're in.
  24. * pUnkOuter LPUNKNOWN to which we delegate.
  25. */
  26. CImpIOleDocumentSite::CImpIOleDocumentSite( PCSite pSite, LPUNKNOWN pUnkOuter)
  27. {
  28. m_cRef = 0;
  29. m_pSite = pSite;
  30. m_pUnkOuter = pUnkOuter;
  31. }
  32. CImpIOleDocumentSite::~CImpIOleDocumentSite( void )
  33. {
  34. }
  35. /*
  36. * CImpIOleDocumentSite::QueryInterface
  37. * CImpIOleDocumentSite::AddRef
  38. * CImpIOleDocumentSite::Release
  39. *
  40. * Purpose:
  41. * IUnknown members for CImpIOleDocumentSite object.
  42. */
  43. STDMETHODIMP CImpIOleDocumentSite::QueryInterface( REFIID riid, void **ppv )
  44. {
  45. return m_pUnkOuter->QueryInterface( riid, ppv );
  46. }
  47. STDMETHODIMP_(ULONG) CImpIOleDocumentSite::AddRef( void )
  48. {
  49. ++m_cRef;
  50. return m_pUnkOuter->AddRef();
  51. }
  52. STDMETHODIMP_(ULONG) CImpIOleDocumentSite::Release( void )
  53. {
  54. --m_cRef;
  55. return m_pUnkOuter->Release();
  56. }
  57. /*
  58. * CImpIOleDocumentsite::ActivateMe
  59. *
  60. * Purpose:
  61. * Instructs the container to activate the object in this site as
  62. * a document object.
  63. *
  64. * Parameters:
  65. * pView IOleDocumentView * of the object to activate.
  66. *
  67. * Return Value:
  68. * HRESULT S_OK if successful, error code otherwise.
  69. */
  70. STDMETHODIMP CImpIOleDocumentSite::ActivateMe( IOleDocumentView *pView )
  71. {
  72. RECT rc;
  73. IOleDocument* pDoc;
  74. /*
  75. * If we're passed a NULL view pointer, then try to get one from
  76. * the document object (the object within us).
  77. */
  78. if ( NULL == pView )
  79. {
  80. if ( FAILED( m_pSite->GetObjectUnknown()->QueryInterface(
  81. IID_IOleDocument, (void **)&pDoc ) ) )
  82. {
  83. return E_FAIL;
  84. }
  85. if ( FAILED( pDoc->CreateView( m_pSite->GetIPSite(),
  86. NULL, 0, &pView ) ) )
  87. {
  88. pDoc->Release();
  89. return E_OUTOFMEMORY;
  90. }
  91. // Release doc pointer since CreateView is a good com method that addrefs
  92. pDoc->Release();
  93. }
  94. else
  95. {
  96. IOleInPlaceSite* pInplaceSite = NULL;
  97. pView->GetInPlaceSite(&pInplaceSite);
  98. if(pInplaceSite != m_pSite->GetIPSite())
  99. {
  100. //Make sure that the view has our client site
  101. pView->SetInPlaceSite( m_pSite->GetIPSite() );
  102. }
  103. //We're holding onto the pointer, so AddRef it.
  104. pView->AddRef();
  105. if(pInplaceSite)
  106. pInplaceSite->Release();
  107. }
  108. // Activation steps, now that we have a view:
  109. m_pSite->SetDocView( pView );
  110. //This sets up toolbars and menus first
  111. pView->UIActivate( TRUE );
  112. //Set the window size sensitive to new toolbars
  113. m_pSite->GetFrame()->GetControl()->GetClientRect( &rc );
  114. pView->SetRect( &rc );
  115. //Makes it all active
  116. pView->Show( TRUE );
  117. return S_OK;
  118. }