ctlview.cpp 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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_CORE2_SEG
  12. #pragma code_seg(AFXCTL_CORE2_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. // COleControl overridables for IViewObject implementation
  21. BOOL COleControl::OnGetColorSet(DVTARGETDEVICE*, HDC, LPLOGPALETTE*)
  22. {
  23. // Can be overridden by subclass
  24. return FALSE;
  25. }
  26. BOOL COleControl::OnGetViewExtent(DWORD dwDrawAspect, LONG /* lindex */,
  27. DVTARGETDEVICE* /* ptd */, LPSIZEL lpsizel)
  28. {
  29. // Can be overridden by subclass for two-pass drawing
  30. if (dwDrawAspect == DVASPECT_OPAQUE || dwDrawAspect == DVASPECT_TRANSPARENT)
  31. dwDrawAspect = DVASPECT_CONTENT;
  32. return SUCCEEDED(m_xOleObject.GetExtent(dwDrawAspect, lpsizel));
  33. }
  34. BOOL COleControl::OnGetViewRect(DWORD dwAspect, LPRECTL pRect)
  35. {
  36. // Can be overridden by subclass for two-pass drawing
  37. SIZEL size;
  38. OnGetViewExtent(dwAspect, -1, NULL, &size);
  39. pRect->left = 0;
  40. pRect->top = 0;
  41. pRect->right = size.cx;
  42. pRect->bottom = -size.cy;
  43. return TRUE;
  44. }
  45. DWORD COleControl::OnGetViewStatus()
  46. {
  47. // Can be overridden by subclass for two-pass drawing
  48. return VIEWSTATUS_OPAQUE;
  49. }
  50. BOOL COleControl::OnQueryHitPoint(DWORD dwAspect, LPCRECT /* pRectBounds */,
  51. POINT /* ptlLoc */, LONG /* lCloseHint */, DWORD* pHitResult)
  52. {
  53. // Can be overridden by subclass for non-rectangular hit-testing
  54. if (dwAspect == DVASPECT_CONTENT)
  55. {
  56. *pHitResult = HITRESULT_HIT;
  57. return TRUE;
  58. }
  59. else
  60. {
  61. return FALSE;
  62. }
  63. }
  64. BOOL COleControl::OnQueryHitRect(DWORD dwAspect, LPCRECT /* pRectBounds */,
  65. LPCRECT /* prcLoc */, LONG /* lCloseHint */, DWORD* pHitResult)
  66. {
  67. // Can be overridden by subclass for non-rectangular hit-testing
  68. if (dwAspect == DVASPECT_CONTENT)
  69. {
  70. *pHitResult = HITRESULT_HIT;
  71. return TRUE;
  72. }
  73. else
  74. {
  75. return FALSE;
  76. }
  77. }
  78. BOOL COleControl::OnGetNaturalExtent(DWORD /* dwAspect */, LONG /* lindex */,
  79. DVTARGETDEVICE* /* ptd */, HDC /* hicTargetDev */,
  80. DVEXTENTINFO* /* pExtentInfo */, LPSIZEL /* psizel */)
  81. {
  82. // Can be overridden by subclass to provide sizing hints
  83. return FALSE;
  84. }
  85. /////////////////////////////////////////////////////////////////////////////
  86. // COleControl::XViewObject
  87. STDMETHODIMP_(ULONG) COleControl::XViewObject::AddRef()
  88. {
  89. METHOD_PROLOGUE_EX_(COleControl, ViewObject)
  90. return (ULONG)pThis->ExternalAddRef();
  91. }
  92. STDMETHODIMP_(ULONG) COleControl::XViewObject::Release()
  93. {
  94. METHOD_PROLOGUE_EX_(COleControl, ViewObject)
  95. return (ULONG)pThis->ExternalRelease();
  96. }
  97. STDMETHODIMP COleControl::XViewObject::QueryInterface(
  98. REFIID iid, LPVOID* ppvObj)
  99. {
  100. METHOD_PROLOGUE_EX_(COleControl, ViewObject)
  101. return (HRESULT)pThis->ExternalQueryInterface(&iid, ppvObj);
  102. }
  103. STDMETHODIMP COleControl::XViewObject::Draw(DWORD dwDrawAspect, LONG lindex,
  104. void* pvAspect, DVTARGETDEVICE* ptd, HDC hicTargetDev, HDC hdcDraw,
  105. LPCRECTL lprcBounds, LPCRECTL lprcWBounds,
  106. BOOL (CALLBACK* pfnContinue)(DWORD), DWORD dwContinue)
  107. {
  108. METHOD_PROLOGUE_EX(COleControl, ViewObject)
  109. HRESULT hResult = S_OK;
  110. CRect rc;
  111. if (lprcBounds == NULL)
  112. {
  113. if (pThis->m_bInPlaceSiteWndless)
  114. rc.CopyRect(pThis->m_rcPos);
  115. else
  116. return E_INVALIDARG;
  117. }
  118. else
  119. {
  120. rc.SetRect((int)lprcBounds->left, (int)lprcBounds->top,
  121. (int)lprcBounds->right, (int)lprcBounds->bottom);
  122. }
  123. // Check if optimized drawing is permitted
  124. if (pvAspect != NULL && (pThis->GetControlFlags() & canOptimizeDraw))
  125. {
  126. pThis->m_bOptimizedDraw = (((DVASPECTINFO*)pvAspect)->dwFlags &
  127. DVASPECTINFOFLAG_CANOPTIMIZE);
  128. }
  129. AfxLockTempMaps();
  130. // Convert from rectangle from logical to device coordinates,
  131. // save DC state, and switch to MM_TEXT mode. After drawing,
  132. // restore DC state.
  133. switch (dwDrawAspect)
  134. {
  135. case DVASPECT_CONTENT:
  136. if (GetDeviceCaps(hdcDraw, TECHNOLOGY) == DT_METAFILE)
  137. {
  138. // If attributes DC is NULL, create one, based on ptd.
  139. HDC hAttribDC = hicTargetDev;
  140. if (hicTargetDev == NULL)
  141. hAttribDC = ::_AfxOleCreateDC(ptd);
  142. // Draw into the metafile DC.
  143. CMetaFileDC dc;
  144. dc.Attach(hdcDraw);
  145. dc.SetAttribDC(hAttribDC);
  146. pThis->DrawMetafile(&dc, rc);
  147. dc.SetAttribDC(NULL);
  148. dc.Detach();
  149. // If we created an attributes DC, delete it now.
  150. if (hicTargetDev == NULL)
  151. ::DeleteDC(hAttribDC);
  152. }
  153. else
  154. {
  155. CDC* pDC = CDC::FromHandle(hdcDraw);
  156. pThis->DrawContent(pDC, rc);
  157. }
  158. break;
  159. default:
  160. if (pThis->m_pDefIViewObject == NULL)
  161. pThis->m_pDefIViewObject =
  162. (LPVIEWOBJECT)pThis->QueryDefHandler(IID_IViewObject);
  163. if (pThis->m_pDefIViewObject != NULL)
  164. {
  165. hResult = pThis->m_pDefIViewObject->Draw(
  166. dwDrawAspect, lindex, pvAspect, ptd, hicTargetDev, hdcDraw,
  167. lprcBounds, lprcWBounds, pfnContinue, dwContinue);
  168. }
  169. }
  170. AfxUnlockTempMaps();
  171. pThis->m_bOptimizedDraw = FALSE;
  172. return hResult;
  173. }
  174. STDMETHODIMP COleControl::XViewObject::GetColorSet(DWORD dwDrawAspect,
  175. LONG lindex, void*, DVTARGETDEVICE* ptd, HDC hicTargetDev,
  176. LPLOGPALETTE* ppColorSet)
  177. {
  178. METHOD_PROLOGUE_EX(COleControl, ViewObject)
  179. HRESULT hr = E_FAIL;
  180. if ((dwDrawAspect == DVASPECT_CONTENT) && (lindex == -1) &&
  181. pThis->OnGetColorSet(ptd, hicTargetDev, ppColorSet))
  182. {
  183. hr = S_OK;
  184. }
  185. return hr;
  186. }
  187. STDMETHODIMP COleControl::XViewObject::Freeze(DWORD, LONG, void*, DWORD*)
  188. {
  189. return E_NOTIMPL;
  190. }
  191. STDMETHODIMP COleControl::XViewObject::Unfreeze(DWORD)
  192. {
  193. return E_NOTIMPL;
  194. }
  195. STDMETHODIMP COleControl::XViewObject::SetAdvise(DWORD aspects, DWORD advf,
  196. LPADVISESINK pAdvSink)
  197. {
  198. METHOD_PROLOGUE_EX_(COleControl, ViewObject)
  199. _AFXCTL_ADVISE_INFO** ppAdviseInfo = &pThis->m_pAdviseInfo;
  200. // Allocate space for advise info, if necessary.
  201. if (*ppAdviseInfo == NULL)
  202. {
  203. TRY
  204. *ppAdviseInfo = new _AFXCTL_ADVISE_INFO;
  205. END_TRY
  206. if (*ppAdviseInfo == NULL)
  207. return E_OUTOFMEMORY;
  208. }
  209. _AFXCTL_ADVISE_INFO* pAdviseInfo = *ppAdviseInfo;
  210. // Release previous sink, if any.
  211. if (pAdviseInfo->m_pAdvSink != NULL)
  212. pAdviseInfo->m_pAdvSink->Release();
  213. // Store new advise info.
  214. pAdviseInfo->m_dwAspects = aspects;
  215. pAdviseInfo->m_dwAdvf = advf;
  216. pAdviseInfo->m_pAdvSink = pAdvSink;
  217. if (pAdvSink != NULL)
  218. pAdvSink->AddRef();
  219. return S_OK;
  220. }
  221. STDMETHODIMP COleControl::XViewObject::GetAdvise(DWORD* pAspects, DWORD* pAdvf,
  222. LPADVISESINK* ppAdvSink)
  223. {
  224. METHOD_PROLOGUE_EX_(COleControl, ViewObject)
  225. _AFXCTL_ADVISE_INFO* pAdviseInfo = pThis->m_pAdviseInfo;
  226. if ((pAdviseInfo != NULL) && (pAdviseInfo->m_pAdvSink != NULL))
  227. {
  228. if (pAspects != NULL)
  229. *pAspects = pAdviseInfo->m_dwAspects;
  230. if (pAdvf != NULL)
  231. *pAdvf = pAdviseInfo->m_dwAdvf;
  232. if (ppAdvSink != NULL)
  233. {
  234. *ppAdvSink = pAdviseInfo->m_pAdvSink;
  235. if (*ppAdvSink != NULL)
  236. (*ppAdvSink)->AddRef();
  237. }
  238. }
  239. else
  240. {
  241. if (pAspects != NULL)
  242. *pAspects = 0;
  243. if (pAdvf != NULL)
  244. *pAdvf = 0;
  245. if (ppAdvSink != NULL)
  246. *ppAdvSink = NULL;
  247. }
  248. return S_OK;
  249. }
  250. STDMETHODIMP COleControl::XViewObject::GetExtent(DWORD dwDrawAspect,
  251. LONG lindex, DVTARGETDEVICE* ptd, LPSIZEL lpsizel)
  252. {
  253. METHOD_PROLOGUE_EX_(COleControl, ViewObject)
  254. return pThis->OnGetViewExtent(dwDrawAspect, lindex, ptd, lpsizel) ? S_OK :
  255. E_FAIL;
  256. }
  257. STDMETHODIMP COleControl::XViewObject::GetRect(DWORD dwAspect, LPRECTL pRect)
  258. {
  259. METHOD_PROLOGUE_EX_(COleControl, ViewObject)
  260. return pThis->OnGetViewRect(dwAspect, pRect) ? S_OK : DV_E_DVASPECT;
  261. }
  262. STDMETHODIMP COleControl::XViewObject::GetViewStatus(DWORD* pdwStatus)
  263. {
  264. METHOD_PROLOGUE_EX_(COleControl, ViewObject)
  265. *pdwStatus = pThis->OnGetViewStatus();
  266. return S_OK;
  267. }
  268. STDMETHODIMP COleControl::XViewObject::QueryHitPoint(DWORD dwAspect,
  269. LPCRECT pRectBounds, POINT ptlLoc, LONG lCloseHint, DWORD* pHitResult)
  270. {
  271. METHOD_PROLOGUE_EX_(COleControl, ViewObject)
  272. return pThis->OnQueryHitPoint(dwAspect, pRectBounds, ptlLoc, lCloseHint,
  273. pHitResult) ? S_OK : E_FAIL;
  274. }
  275. STDMETHODIMP COleControl::XViewObject::QueryHitRect(DWORD dwAspect,
  276. LPCRECT pRectBounds, LPCRECT prcLoc, LONG lCloseHint, DWORD* pHitResult)
  277. {
  278. METHOD_PROLOGUE_EX_(COleControl, ViewObject)
  279. return pThis->OnQueryHitRect(dwAspect, pRectBounds, prcLoc, lCloseHint,
  280. pHitResult) ? S_OK : E_FAIL;
  281. }
  282. STDMETHODIMP COleControl::XViewObject::GetNaturalExtent(DWORD dwAspect,
  283. LONG lindex, DVTARGETDEVICE* ptd, HDC hicTargetDev,
  284. DVEXTENTINFO* pExtentInfo, LPSIZEL psizel)
  285. {
  286. METHOD_PROLOGUE_EX_(COleControl, ViewObject)
  287. return pThis->OnGetNaturalExtent(dwAspect, lindex, ptd, hicTargetDev,
  288. pExtentInfo, psizel) ? S_OK : E_NOTIMPL;
  289. }
  290. /////////////////////////////////////////////////////////////////////////////
  291. // Force any extra compiler-generated code into AFX_INIT_SEG
  292. #ifdef AFX_INIT_SEG
  293. #pragma code_seg(AFX_INIT_SEG)
  294. #endif