Source code of Windows XP (NT5)
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.

182 lines
4.8 KiB

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