Leaked source code of windows server 2003
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.

315 lines
8.0 KiB

  1. #include "headers.hxx"
  2. #pragma hdrstop
  3. //+----------------------------------------------------------------------------
  4. //
  5. // File:
  6. // utils.cpp
  7. //
  8. // Contents:
  9. // Utility functions for the cache unit test
  10. //
  11. // History:
  12. //
  13. // 04-Sep-94 davepl Created
  14. //
  15. //-----------------------------------------------------------------------------
  16. //+----------------------------------------------------------------------------
  17. //
  18. // Member: TestInstance::AddXXXCacheNode
  19. //
  20. // Synopsis: Adds an empty cache node for various formats
  21. //
  22. // Arguments: [inst] -- ptr to test instance
  23. // [pdwCon] -- ptr to connection ID (out)
  24. //
  25. // Returns: HRESULT
  26. //
  27. // Notes:
  28. //
  29. // History: 23-Aug-94 Davepl Created
  30. //
  31. //-----------------------------------------------------------------------------
  32. HRESULT TestInstance::AddMFCacheNode(DWORD *pdwCon)
  33. {
  34. HRESULT hr;
  35. TraceLog Log(this, "TestInstance::AddMFCacheNode", GS_CACHE, VB_MAXIMUM);
  36. Log.OnEntry (" ( %p ) \n", pdwCon);
  37. Log.OnExit (" ( %X ) [ %p ]\n", &hr, pdwCon);
  38. FORMATETC fetcMF =
  39. {
  40. CF_METAFILEPICT, // Clipformat
  41. NULL, // DVTargetDevice
  42. DVASPECT_CONTENT, // Aspect
  43. -1, // Index
  44. TYMED_MFPICT // TYMED
  45. };
  46. //
  47. // Cache a METAFILE node
  48. //
  49. hr = m_pOleCache->Cache(&fetcMF, ADVF_PRIMEFIRST, pdwCon);
  50. return hr;
  51. }
  52. HRESULT TestInstance::AddEMFCacheNode(DWORD *pdwCon)
  53. {
  54. HRESULT hr;
  55. TraceLog Log(this, "TestInstance::AddEMFCacheNode", GS_CACHE, VB_MAXIMUM);
  56. Log.OnEntry (" ( %p ) \n", pdwCon);
  57. Log.OnExit (" ( %X ) [ %p ]\n", &hr, pdwCon);
  58. FORMATETC fetcEMF = {
  59. CF_ENHMETAFILE, // Clipformat
  60. NULL, // DVTargetDevice
  61. DVASPECT_CONTENT, // Aspect
  62. -1, // Index
  63. TYMED_ENHMF // TYMED
  64. };
  65. //
  66. // Cache an ENH METAFILE node
  67. //
  68. hr = m_pOleCache->Cache(&fetcEMF, ADVF_PRIMEFIRST, pdwCon);
  69. return hr;
  70. }
  71. HRESULT TestInstance::AddDIBCacheNode(DWORD *pdwCon)
  72. {
  73. HRESULT hr;
  74. TraceLog Log(this, "TestInstance::AddDIBCacheNode", GS_CACHE, VB_MAXIMUM);
  75. Log.OnEntry (" ( %p ) \n", pdwCon);
  76. Log.OnExit (" ( %X ) [ %p ]\n", &hr, pdwCon);
  77. FORMATETC fetcDIB = {
  78. CF_DIB, // Clipformat
  79. NULL, // DVTargetDevice
  80. DVASPECT_CONTENT, // Aspect
  81. -1, // Index
  82. TYMED_HGLOBAL // TYMED
  83. };
  84. //
  85. // Cache a DIB node
  86. //
  87. hr = m_pOleCache->Cache(&fetcDIB, ADVF_PRIMEFIRST, pdwCon);
  88. return hr;
  89. }
  90. HRESULT TestInstance::AddBITMAPCacheNode(DWORD *pdwCon)
  91. {
  92. HRESULT hr;
  93. TraceLog Log(this, "TestInstance::AddMFCacheNode", GS_CACHE, VB_MAXIMUM);
  94. Log.OnEntry (" ( %p ) \n", pdwCon);
  95. Log.OnExit (" ( %X ) [ %p ]\n", &hr, pdwCon);
  96. FORMATETC fetcBITMAP = {
  97. CF_BITMAP, // Clipformat
  98. NULL, // DVTargetDevice
  99. DVASPECT_CONTENT, // Aspect
  100. -1, // Index
  101. TYMED_GDI // TYMED
  102. };
  103. //
  104. // Cache a BITMAP node
  105. //
  106. hr = m_pOleCache->Cache(&fetcBITMAP, ADVF_PRIMEFIRST, pdwCon);
  107. return hr;
  108. }
  109. //+----------------------------------------------------------------------------
  110. //
  111. // Function: EltIsInArray
  112. //
  113. // Synopsis: Checks to see if a STATDATA search item is in
  114. // a STATDATA array. Checks clipformat and connection
  115. // ID only.
  116. //
  117. // Arguments: [sdToFind] STATDATA we are looking for
  118. // [rgStat] Array of STATDATAs to look in
  119. // [cCount] Count of STATDATAs in rgStat
  120. //
  121. // Returns: S_OK if found, S_FALSE if not
  122. //
  123. // Notes:
  124. //
  125. // History: 23-Aug-94 Davepl Created
  126. //
  127. //-----------------------------------------------------------------------------
  128. HRESULT EltIsInArray(STATDATA sdToFind, STATDATA rgStat[], DWORD cCount)
  129. {
  130. HRESULT hr = S_FALSE;
  131. TraceLog Log(NULL, "EltIsInArray", GS_CACHE, VB_MAXIMUM);
  132. Log.OnEntry (" ( %p, %p, %d )\n", &sdToFind, rgStat, cCount);
  133. Log.OnExit (" ( %X )\n", &hr);
  134. for (DWORD a=0; a<cCount; a++)
  135. {
  136. if (rgStat[a].formatetc.cfFormat == sdToFind.formatetc.cfFormat &&
  137. rgStat[a].dwConnection == sdToFind.dwConnection)
  138. {
  139. hr = S_OK;
  140. break;
  141. }
  142. }
  143. return hr;
  144. }
  145. //+----------------------------------------------------------------------------
  146. //
  147. // Function: ConvWidthInPelsToLHM
  148. // ConvHeightInPelsToLHM
  149. //
  150. // Synopsis: Converts a measurement in pixels to LOGICAL HIMETRICS.
  151. // If a reference DC is given, it is used, otherwise
  152. // the screen DC is used as a default.
  153. //
  154. // Arguments: [hDC] The reference DC
  155. // [int] The width or height to convert
  156. //
  157. // Returns: S_OK if found, S_FALSE if not
  158. //
  159. // History: 06-Aug-94 Davepl Copy/Paste/Cleanup
  160. //
  161. //-----------------------------------------------------------------------------
  162. const LONG HIMETRIC_PER_INCH = 2540;
  163. int ConvWidthInPelsToLHM(HDC hDC, int iWidthInPix)
  164. {
  165. int iXppli; // Pixels per logical inch along width
  166. int iWidthInHiMetric;
  167. BOOL fSystemDC = FALSE;
  168. if (NULL == hDC)
  169. {
  170. hDC = GetDC(NULL);
  171. fSystemDC = TRUE;
  172. }
  173. iXppli = GetDeviceCaps (hDC, LOGPIXELSX);
  174. // We got pixel units, convert them to logical HIMETRIC along
  175. // the display
  176. iWidthInHiMetric = MulDiv(HIMETRIC_PER_INCH, iWidthInPix, iXppli);
  177. if (fSystemDC)
  178. {
  179. ReleaseDC(NULL, hDC);
  180. }
  181. return iWidthInHiMetric;
  182. }
  183. int ConvHeightInPelsToLHM(HDC hDC, int iHeightInPix)
  184. {
  185. int iYppli; //Pixels per logical inch along height
  186. int iHeightInHiMetric;
  187. BOOL fSystemDC = FALSE;
  188. if (NULL == hDC)
  189. {
  190. hDC = GetDC(NULL);
  191. fSystemDC = TRUE;
  192. }
  193. iYppli = GetDeviceCaps (hDC, LOGPIXELSY);
  194. // We got pixel units, convert them to logical HIMETRIC along the
  195. // display
  196. iHeightInHiMetric = MulDiv(HIMETRIC_PER_INCH, iHeightInPix, iYppli);
  197. if (fSystemDC)
  198. {
  199. ReleaseDC(NULL, hDC);
  200. }
  201. return iHeightInHiMetric;
  202. }
  203. //+----------------------------------------------------------------------------
  204. //
  205. // Function: TestInstance::UncacheFormat
  206. //
  207. // Synopsis: Uncaches the first node found in the cache that
  208. // matches the format specified.
  209. //
  210. // Arguments: [cf] Format to look for
  211. //
  212. // Returns: HRESULT
  213. //
  214. // Notes: If there are multiple nodes (ie: various apsects) of
  215. // the same clipformat, only the first one found is
  216. // removed.
  217. //
  218. // History: 23-Aug-94 Davepl Created
  219. //
  220. //-----------------------------------------------------------------------------
  221. HRESULT TestInstance::UncacheFormat(CLIPFORMAT cf)
  222. {
  223. HRESULT hr;
  224. TraceLog Log(NULL, "TestInstance::UncacheFormat", GS_CACHE, VB_MAXIMUM);
  225. Log.OnEntry (" ( %d )\n", cf);
  226. Log.OnExit (" ( %X )\n", &hr);
  227. BOOL fFound = FALSE;
  228. //
  229. // Get an enumerator on the cache
  230. //
  231. LPENUMSTATDATA pEsd;
  232. hr = m_pOleCache->EnumCache(&pEsd);
  233. if (S_OK == hr)
  234. {
  235. //
  236. // Loop until a failure or until we have removed all of
  237. // the nodes that we thought should exist
  238. //
  239. STATDATA stat;
  240. while (S_OK == hr && FALSE == fFound)
  241. {
  242. hr = pEsd->Next(1, &stat, NULL);
  243. if (S_OK == hr && stat.formatetc.cfFormat == cf)
  244. {
  245. hr = m_pOleCache->Uncache(stat.dwConnection);
  246. if (S_OK == hr)
  247. {
  248. fFound = TRUE;
  249. }
  250. }
  251. }
  252. }
  253. return hr;
  254. }