iviewobj.cpp
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 5k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. #include "priv.h"
  2. #include "privcpp.h"
  3. const DWORD g_cookie = 111176;
  4. CPackage_IViewObject2::CPackage_IViewObject2(CPackage *pPackage) : 
  5.     _pPackage(pPackage)
  6. {
  7.     ASSERT(_cRef == 0);
  8.     ASSERT(_fFrozen == FALSE);
  9. }
  10. CPackage_IViewObject2::~CPackage_IViewObject2()
  11. {
  12.     DebugMsg(DM_TRACE, "CPackage_IViewObject2 destroyed with ref count %d",_cRef);
  13. }
  14. //////////////////////////////////
  15. //
  16. // IUnknown Methods...
  17. //
  18. HRESULT CPackage_IViewObject2::QueryInterface(REFIID iid, void ** ppv)
  19. {
  20.     return _pPackage->QueryInterface(iid,ppv);
  21. }
  22. ULONG CPackage_IViewObject2::AddRef(void) 
  23. {
  24.     _cRef++;    // interface ref count for debugging
  25.     return _pPackage->AddRef();
  26. }
  27. ULONG CPackage_IViewObject2::Release(void)
  28. {
  29.     _cRef--;    // interface ref count for debugging
  30.     return _pPackage->Release();
  31. }
  32. //////////////////////////////////
  33. //
  34. // IViewObject2 Methods...
  35. //
  36. HRESULT CPackage_IViewObject2::Draw(DWORD dwDrawAspect, LONG lindex,
  37. LPVOID pvAspect, DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw,
  38. LPCRECTL lprcBounds, LPCRECTL lprcWBounds,BOOL (CALLBACK *pfnContinue)(DWORD),
  39. DWORD dwContinue)
  40. {
  41.     DebugMsg(DM_TRACE,"pack vo - Draw() called.");
  42.     
  43.     //
  44.     // NOTE: If we're frozen, we should use a cached represetation, but
  45.     // the icon doesn't really change all that often, so it's kind of 
  46.     // pointless to freeze it, but here's where we'd do it, if we 
  47.     // wanted to.  About the only place this would ever be necessary if 
  48.     // somebody called to freeze us while the user was in the process of 
  49.     // editing the package or something, but I don't think it's something
  50.     // we need to worry about right away.  (Especially since the user can't
  51.     // change the icon right now.)
  52.     //
  53.     IconDraw(_pPackage->_lpic, hdcDraw, (RECT *)lprcBounds);
  54.     return S_OK;
  55. }
  56.     
  57. HRESULT CPackage_IViewObject2::GetColorSet(DWORD dwAspect, LONG lindex, 
  58.                                 LPVOID pvAspect, DVTARGETDEVICE *ptd, 
  59.                                 HDC hdcTargetDev, LPLOGPALETTE *ppColorSet)
  60. {
  61.     DebugMsg(DM_TRACE,"pack vo - GetColorSet() called.");
  62.     
  63.     if (ppColorSet == NULL)
  64.         return E_INVALIDARG;
  65.     
  66.     *ppColorSet = NULL;         // null the out param
  67.     return S_FALSE;
  68. }
  69.     
  70. HRESULT CPackage_IViewObject2::Freeze(DWORD dwDrawAspect, LONG lindex, 
  71.                                       LPVOID pvAspect, LPDWORD pdwFreeze)
  72. {
  73.     DebugMsg(DM_TRACE,"pack vo - Freeze() called.");
  74.     if (pdwFreeze == NULL)
  75.         return E_INVALIDARG;
  76.     
  77.     if (_fFrozen) {
  78.         *pdwFreeze = g_cookie;
  79.         return S_OK;
  80.     }
  81.     
  82.     //
  83.     // This is where we would take a snapshot of the icon to use as
  84.     // the "frozen" image in subsequent routines.  For now, we just
  85.     // return the cookie.  Draw() will use the current icon regardless 
  86.     // of the fFrozen flag.
  87.     //
  88.     
  89.     _fFrozen = TRUE;
  90.     *pdwFreeze = g_cookie;
  91.     
  92.     return S_OK;
  93. }
  94.     
  95. HRESULT CPackage_IViewObject2::Unfreeze(DWORD dwFreeze)
  96. {
  97.     DebugMsg(DM_TRACE,"pack vo - Unfreeze() called.");
  98.     
  99.     // If the pass us an invalid cookie or we're not frozen then bail
  100.     if (dwFreeze != g_cookie || !_fFrozen)
  101.         return OLE_E_NOCONNECTION;
  102.     
  103.     // 
  104.     // This is where we'd get rid of the frozen presentation we saved in
  105.     // IViewObject::Freeze().
  106.     //
  107.     _fFrozen = FALSE;
  108.     return S_OK;
  109. }
  110.     
  111. HRESULT CPackage_IViewObject2::SetAdvise(DWORD dwAspects, DWORD dwAdvf,
  112.                               LPADVISESINK pAdvSink)
  113. {
  114.     DebugMsg(DM_TRACE,"pack vo - SetAdvise() called.");
  115.     
  116.     if (_pPackage->_pViewSink)
  117.         _pPackage->_pViewSink->Release();
  118.     
  119.     _pPackage->_pViewSink = pAdvSink;
  120.     _pPackage->_dwViewAspects = dwAspects;
  121.     _pPackage->_dwViewAdvf = dwAdvf;
  122.     
  123.     if (_pPackage->_pViewSink) 
  124.         _pPackage->_pViewSink->AddRef();
  125.     
  126.     return S_OK;
  127. }
  128.     
  129. HRESULT CPackage_IViewObject2::GetAdvise(LPDWORD pdwAspects, LPDWORD pdwAdvf,
  130.                               LPADVISESINK *ppAdvSink)
  131. {
  132.     DebugMsg(DM_TRACE,"pack vo - GetAdvise() called.");
  133.     
  134.     if (!ppAdvSink || !pdwAdvf || !pdwAspects)
  135.         return E_INVALIDARG;
  136.     
  137.     *ppAdvSink = _pPackage->_pViewSink;
  138.     _pPackage->_pViewSink->AddRef();
  139.     
  140.     if (pdwAspects != NULL)
  141.         *pdwAspects = _pPackage->_dwViewAspects;
  142.     
  143.     if (pdwAdvf != NULL)
  144.         *pdwAdvf = _pPackage->_dwViewAdvf;
  145.     
  146.     return S_OK;
  147. }
  148.     
  149. HRESULT CPackage_IViewObject2::GetExtent(DWORD dwAspect, LONG lindex,
  150. DVTARGETDEVICE *ptd, LPSIZEL pszl)
  151. {
  152.     DebugMsg(DM_TRACE,"pack vo - GetExtent() called.");
  153.     if (pszl == NULL)
  154.         return E_INVALIDARG;
  155.     
  156.     if (!_pPackage->_lpic)
  157.         return OLE_E_BLANK;
  158.             
  159.     pszl->cx = _pPackage->_lpic->rc.right;
  160.     pszl->cy = _pPackage->_lpic->rc.bottom;
  161.     
  162.     pszl->cx = MulDiv(pszl->cx,HIMETRIC_PER_INCH,DEF_LOGPIXELSX);
  163.     pszl->cy = MulDiv(pszl->cy,HIMETRIC_PER_INCH,DEF_LOGPIXELSY);
  164.     
  165.     return S_OK;
  166. }