home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / mfc / src / ctlquick.cpp < prev    next >
C/C++ Source or Header  |  1998-06-16  |  4KB  |  148 lines

  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.  
  11. #include "stdafx.h"
  12.  
  13. #ifdef AFXCTL_CORE1_SEG
  14. #pragma code_seg(AFXCTL_CORE1_SEG)
  15. #endif
  16.  
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. #define new DEBUG_NEW
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25. // _AFXCTL_AMBIENT_CACHE implementation
  26.  
  27. THREAD_LOCAL(_AFXCTL_AMBIENT_CACHE, _afxAmbientCache)
  28.  
  29. _AFXCTL_AMBIENT_CACHE::_AFXCTL_AMBIENT_CACHE()
  30. {
  31. }
  32.  
  33. void _AFXCTL_AMBIENT_CACHE::Cache(QACONTAINER* pQAContainer)
  34. {
  35.     m_bValid = (pQAContainer != NULL);
  36.     if (m_bValid)
  37.     {
  38.         memcpy(&m_dwAmbientFlags, &pQAContainer->dwAmbientFlags,
  39.             sizeof(_AFXCTL_AMBIENT_CACHE) -
  40.             offsetof(_AFXCTL_AMBIENT_CACHE, m_dwAmbientFlags));
  41.         if (m_pFont != NULL)
  42.             m_pFont->AddRef();
  43.     }
  44.     else
  45.     {
  46.         if (m_pFont != NULL)
  47.             m_pFont->Release();
  48.         memset(&m_dwAmbientFlags, 0,
  49.             sizeof(_AFXCTL_AMBIENT_CACHE) -
  50.             offsetof(_AFXCTL_AMBIENT_CACHE, m_dwAmbientFlags));
  51.     }
  52. }
  53.  
  54. /////////////////////////////////////////////////////////////////////////////
  55. // COleControl::XQuickActivate
  56.  
  57. STDMETHODIMP_(ULONG) COleControl::XQuickActivate::AddRef()
  58. {
  59.     // Delegate to our exported AddRef.
  60.     METHOD_PROLOGUE_EX_(COleControl, QuickActivate)
  61.     return (ULONG)pThis->ExternalAddRef();
  62. }
  63.  
  64. STDMETHODIMP_(ULONG) COleControl::XQuickActivate::Release()
  65. {
  66.     // Delegate to our exported Release.
  67.     METHOD_PROLOGUE_EX_(COleControl, QuickActivate)
  68.     return (ULONG)pThis->ExternalRelease();
  69. }
  70.  
  71. STDMETHODIMP COleControl::XQuickActivate::QueryInterface(
  72.     REFIID iid, LPVOID* ppvObj)
  73. {
  74.     // Delegate to our exported QueryInterface.
  75.     METHOD_PROLOGUE_EX_(COleControl, QuickActivate)
  76.     return (HRESULT)pThis->ExternalQueryInterface(&iid, ppvObj);
  77. }
  78.  
  79. STDMETHODIMP COleControl::XQuickActivate::QuickActivate(
  80.     QACONTAINER *pQAContainer, QACONTROL *pQAControl)
  81. {
  82.     METHOD_PROLOGUE_EX_(COleControl, QuickActivate)
  83.  
  84.     // Get the IOleObject interface
  85.     HRESULT hr = S_OK;
  86.     IOleObject* pOleObject = NULL;
  87.     if (FAILED(hr = pThis->ExternalQueryInterface(&IID_IOleObject,
  88.         reinterpret_cast<void**>(&pOleObject))))
  89.     {
  90.         return hr;
  91.     }
  92.  
  93.     // Keep copy of ambient properties
  94.     _afxAmbientCache->Cache(pQAContainer);
  95.  
  96.     // Set client site
  97.     ASSERT(pOleObject != NULL);
  98.     pOleObject->SetClientSite(pQAContainer->pClientSite);
  99.  
  100.     // Establish connections
  101.     DWORD dwDummy;
  102.     if (pQAContainer->pAdviseSink != NULL)
  103.         pOleObject->Advise(pQAContainer->pAdviseSink, &dwDummy);
  104.  
  105.     if (pQAContainer->pPropertyNotifySink != NULL)
  106.         pThis->m_xPropConnPt.m_xConnPt.Advise(pQAContainer->pPropertyNotifySink,
  107.             &pQAControl->dwPropNotifyCookie);
  108.     if (pQAContainer->pUnkEventSink != NULL)
  109.         pThis->m_xEventConnPt.m_xConnPt.Advise(pQAContainer->pUnkEventSink,
  110.             &pQAControl->dwEventCookie);
  111.  
  112.     // Fill in return values
  113.     IViewObjectEx* pViewObject;
  114.     if (SUCCEEDED(pThis->ExternalQueryInterface(&IID_IViewObjectEx,
  115.         reinterpret_cast<void**>(&pViewObject))))
  116.     {
  117.         pViewObject->GetViewStatus(&pQAControl->dwViewStatus);
  118.  
  119.         // Set advise sink on IViewObject, while we're here.
  120.         if (pQAContainer->pAdviseSink != NULL)
  121.             pViewObject->SetAdvise(DVASPECT_CONTENT, 0, pQAContainer->pAdviseSink);
  122.  
  123.         pViewObject->Release();
  124.     }
  125.     else
  126.     {
  127.         pQAControl->dwViewStatus = 0;
  128.     }
  129.  
  130.     pOleObject->GetMiscStatus(DVASPECT_CONTENT, &pQAControl->dwMiscStatus);
  131.  
  132.     pOleObject->Release();
  133.  
  134.     return S_OK;
  135. }
  136.  
  137. STDMETHODIMP COleControl::XQuickActivate::SetContentExtent(LPSIZEL lpsizel)
  138. {
  139.     METHOD_PROLOGUE_EX_(COleControl, QuickActivate)
  140.     return pThis->m_xOleObject.SetExtent(DVASPECT_CONTENT, lpsizel);
  141. }
  142.  
  143. STDMETHODIMP COleControl::XQuickActivate::GetContentExtent(LPSIZEL lpsizel)
  144. {
  145.     METHOD_PROLOGUE_EX_(COleControl, QuickActivate)
  146.     return pThis->m_xOleObject.GetExtent(DVASPECT_CONTENT, lpsizel);
  147. }
  148.