ctlquick.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10. #include "stdafx.h"
  11. #ifdef AFXCTL_CORE1_SEG
  12. #pragma code_seg(AFXCTL_CORE1_SEG)
  13. #endif
  14. #ifdef _DEBUG
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. #define new DEBUG_NEW
  19. /////////////////////////////////////////////////////////////////////////////
  20. // _AFXCTL_AMBIENT_CACHE implementation
  21. THREAD_LOCAL(_AFXCTL_AMBIENT_CACHE, _afxAmbientCache)
  22. _AFXCTL_AMBIENT_CACHE::_AFXCTL_AMBIENT_CACHE()
  23. {
  24. }
  25. void _AFXCTL_AMBIENT_CACHE::Cache(QACONTAINER* pQAContainer)
  26. {
  27. m_bValid = (pQAContainer != NULL);
  28. if (m_bValid)
  29. {
  30. memcpy(&m_dwAmbientFlags, &pQAContainer->dwAmbientFlags,
  31. sizeof(_AFXCTL_AMBIENT_CACHE) -
  32. offsetof(_AFXCTL_AMBIENT_CACHE, m_dwAmbientFlags));
  33. if (m_pFont != NULL)
  34. m_pFont->AddRef();
  35. }
  36. else
  37. {
  38. if (m_pFont != NULL)
  39. m_pFont->Release();
  40. memset(&m_dwAmbientFlags, 0,
  41. sizeof(_AFXCTL_AMBIENT_CACHE) -
  42. offsetof(_AFXCTL_AMBIENT_CACHE, m_dwAmbientFlags));
  43. }
  44. }
  45. /////////////////////////////////////////////////////////////////////////////
  46. // COleControl::XQuickActivate
  47. STDMETHODIMP_(ULONG) COleControl::XQuickActivate::AddRef()
  48. {
  49. // Delegate to our exported AddRef.
  50. METHOD_PROLOGUE_EX_(COleControl, QuickActivate)
  51. return (ULONG)pThis->ExternalAddRef();
  52. }
  53. STDMETHODIMP_(ULONG) COleControl::XQuickActivate::Release()
  54. {
  55. // Delegate to our exported Release.
  56. METHOD_PROLOGUE_EX_(COleControl, QuickActivate)
  57. return (ULONG)pThis->ExternalRelease();
  58. }
  59. STDMETHODIMP COleControl::XQuickActivate::QueryInterface(
  60. REFIID iid, LPVOID* ppvObj)
  61. {
  62. // Delegate to our exported QueryInterface.
  63. METHOD_PROLOGUE_EX_(COleControl, QuickActivate)
  64. return (HRESULT)pThis->ExternalQueryInterface(&iid, ppvObj);
  65. }
  66. STDMETHODIMP COleControl::XQuickActivate::QuickActivate(
  67. QACONTAINER *pQAContainer, QACONTROL *pQAControl)
  68. {
  69. METHOD_PROLOGUE_EX_(COleControl, QuickActivate)
  70. // Get the IOleObject interface
  71. HRESULT hr = S_OK;
  72. IOleObject* pOleObject = NULL;
  73. if (FAILED(hr = pThis->ExternalQueryInterface(&IID_IOleObject,
  74. reinterpret_cast<void**>(&pOleObject))))
  75. {
  76. return hr;
  77. }
  78. // Keep copy of ambient properties
  79. _afxAmbientCache->Cache(pQAContainer);
  80. // Set client site
  81. ASSERT(pOleObject != NULL);
  82. pOleObject->SetClientSite(pQAContainer->pClientSite);
  83. // Establish connections
  84. DWORD dwDummy;
  85. if (pQAContainer->pAdviseSink != NULL)
  86. pOleObject->Advise(pQAContainer->pAdviseSink, &dwDummy);
  87. if (pQAContainer->pPropertyNotifySink != NULL)
  88. pThis->m_xPropConnPt.m_xConnPt.Advise(pQAContainer->pPropertyNotifySink,
  89. &pQAControl->dwPropNotifyCookie);
  90. if (pQAContainer->pUnkEventSink != NULL)
  91. pThis->m_xEventConnPt.m_xConnPt.Advise(pQAContainer->pUnkEventSink,
  92. &pQAControl->dwEventCookie);
  93. // Fill in return values
  94. IViewObjectEx* pViewObject;
  95. if (SUCCEEDED(pThis->ExternalQueryInterface(&IID_IViewObjectEx,
  96. reinterpret_cast<void**>(&pViewObject))))
  97. {
  98. pViewObject->GetViewStatus(&pQAControl->dwViewStatus);
  99. // Set advise sink on IViewObject, while we're here.
  100. if (pQAContainer->pAdviseSink != NULL)
  101. pViewObject->SetAdvise(DVASPECT_CONTENT, 0, pQAContainer->pAdviseSink);
  102. pViewObject->Release();
  103. }
  104. else
  105. {
  106. pQAControl->dwViewStatus = 0;
  107. }
  108. pOleObject->GetMiscStatus(DVASPECT_CONTENT, &pQAControl->dwMiscStatus);
  109. pOleObject->Release();
  110. return S_OK;
  111. }
  112. STDMETHODIMP COleControl::XQuickActivate::SetContentExtent(LPSIZEL lpsizel)
  113. {
  114. METHOD_PROLOGUE_EX_(COleControl, QuickActivate)
  115. return pThis->m_xOleObject.SetExtent(DVASPECT_CONTENT, lpsizel);
  116. }
  117. STDMETHODIMP COleControl::XQuickActivate::GetContentExtent(LPSIZEL lpsizel)
  118. {
  119. METHOD_PROLOGUE_EX_(COleControl, QuickActivate)
  120. return pThis->m_xOleObject.GetExtent(DVASPECT_CONTENT, lpsizel);
  121. }