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.

410 lines
9.4 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: drawattr.cxx
  3. *
  4. * Copyright (c) 1990-1999 Microsoft Corporation
  5. \**************************************************************************/
  6. #include "precomp.hxx"
  7. extern DC_ATTR DcAttrDefault;
  8. /******************************Public*Routine******************************\
  9. * GreSetROP2
  10. *
  11. * Set the foreground mix mode. Return the old foreground mode or 0 if
  12. * hdc is invalid.
  13. *
  14. * History:
  15. * Thu 25-Nov-1993 -by- Patrick Haluptzok [patrickh]
  16. * Smaller code.
  17. *
  18. * 28-Nov-1990 -by- Eric Kutter [erick]
  19. * Wrote it.
  20. \**************************************************************************/
  21. ULONG GreSetROP2(HDC hdc,int iROP)
  22. {
  23. ULONG iOldROP = 0;
  24. XDCOBJ dco(hdc);
  25. if (dco.bValid())
  26. {
  27. iOldROP = dco.pdc->jROP2();
  28. dco.pdc->jROP2((BYTE)iROP);
  29. dco.vUnlockFast();
  30. }
  31. return(iOldROP);
  32. }
  33. /******************************Public*Routine******************************\
  34. * GreGetBkColor
  35. *
  36. * Get the back ground color. Return CLR_INVALID if invalid hdc.
  37. *
  38. * History:
  39. * Thu 25-Nov-1993 -by- Patrick Haluptzok [patrickh]
  40. * Smaller code.
  41. *
  42. * 28-Nov-1990 -by- Eric Kutter [erick]
  43. * Wrote it.
  44. \**************************************************************************/
  45. COLORREF GreGetBkColor(HDC hdc)
  46. {
  47. GDITraceHandle(GreGetBkColor, "(%X)\n", (va_list)&hdc, hdc);
  48. COLORREF clrRet = CLR_INVALID;
  49. XDCOBJ dco(hdc);
  50. if (dco.bValid())
  51. {
  52. clrRet = dco.pdc->ulBackClr();
  53. dco.vUnlockFast();
  54. }
  55. return(clrRet);
  56. }
  57. /******************************Public*Routine******************************\
  58. * GreSetBkColor
  59. *
  60. * Set the back ground color.
  61. *
  62. * History:
  63. * Thu 25-Nov-1993 -by- Patrick Haluptzok [patrickh]
  64. * smaller, don't dirty brush unnecesarily.
  65. *
  66. * 28-Nov-1990 -by- Eric Kutter [erick]
  67. * Wrote it.
  68. \**************************************************************************/
  69. COLORREF GreSetBkColor(HDC hdc,COLORREF cr)
  70. {
  71. GDITrace(GreSetBkColor, "(%X, %X)\n", (va_list)&hdc);
  72. COLORREF crOld = CLR_INVALID;
  73. XDCOBJ dco(hdc);
  74. if (dco.bValid())
  75. {
  76. crOld = dco.pdc->ulBackClr();
  77. dco.pdc->ulBackClr(cr);
  78. cr &= 0x13ffffff;
  79. if (cr != crOld)
  80. {
  81. dco.pdc->crBackClr(cr);
  82. dco.pdc->ulDirtyAdd(DIRTY_FILL|DIRTY_LINE|DIRTY_BACKGROUND);
  83. }
  84. dco.vUnlockFast();
  85. }
  86. GDITrace(GreSetBkColor, " returns %X\n", (va_list)&crOld);
  87. return(crOld);
  88. }
  89. /******************************Public*Routine******************************\
  90. * GreSetGraphicsMode
  91. *
  92. * Set graphics mode to default or advanced.
  93. *
  94. * History:
  95. * 3-11-94 -by- Lingyun Wang [lingyunw]
  96. * moved client side attr to server side
  97. *
  98. * Thu 25-Nov-1993 -by- Patrick Haluptzok [patrickh]
  99. * Smaller code.
  100. *
  101. * 19-Oct-1992 -by- Bodin Dresevic [BodinD]
  102. * Wrote it.
  103. \**************************************************************************/
  104. int GreSetGraphicsMode(HDC hdc, int iMode)
  105. {
  106. ULONG ulModeOld = 0;
  107. XDCOBJ dco(hdc);
  108. if (dco.bValid())
  109. {
  110. ulModeOld = dco.pdc->iGraphicsMode();
  111. if ((iMode == GM_COMPATIBLE) || (iMode == GM_ADVANCED))
  112. {
  113. dco.pdc->iGraphicsMode(iMode);
  114. }
  115. else
  116. {
  117. WARNING("GreSetGraphicsMode passed invalid mode");
  118. }
  119. dco.vUnlockFast();
  120. }
  121. return((int)ulModeOld);
  122. }
  123. /******************************Public*Routine******************************\
  124. * GreGetBkMode
  125. *
  126. * Get the background mix mode.
  127. *
  128. * History:
  129. *
  130. * Thu 25-Nov-1993 -by- Patrick Haluptzok [patrickh]
  131. * Smaller code.
  132. *
  133. * 28-Nov-1990 -by- Eric Kutter [erick]
  134. * Wrote it.
  135. \**************************************************************************/
  136. int GreGetBkMode(HDC hdc)
  137. {
  138. ULONG ulRet = 0;
  139. XDCOBJ dco(hdc);
  140. if (dco.bValid())
  141. {
  142. ulRet = dco.pdc->lBkMode();
  143. dco.vUnlockFast();
  144. }
  145. return((int)ulRet);
  146. }
  147. /******************************Public*Routine******************************\
  148. * GreSetBkMode
  149. *
  150. * Set the background mix mode. This must be either OPAQUE or TRANSPARENT.
  151. * If it is not one of these values or the hdc is invalid, return 0.
  152. * If it is a valid mode, return the old mode in the dc.
  153. *
  154. * History:
  155. * 3-Nov-1994 -by- Lingyun Wang [lingyunw]
  156. * Moved client side BkMode to Server side
  157. *
  158. * Thu 25-Nov-1993 -by- Patrick Haluptzok [patrickh]
  159. * Smaller code.
  160. *
  161. * 28-Nov-1990 -by- Eric Kutter [erick]
  162. * Wrote it.
  163. \**************************************************************************/
  164. int GreSetBkMode(HDC hdc,int iBkMode)
  165. {
  166. ULONG ulBkModeOld = 0;
  167. XDCOBJ dco(hdc);
  168. if (dco.bValid())
  169. {
  170. ulBkModeOld = dco.pdc->lBkMode();
  171. dco.pdc->lBkMode(iBkMode);
  172. if ((iBkMode != OPAQUE) && (iBkMode != TRANSPARENT))
  173. {
  174. iBkMode = TRANSPARENT;
  175. WARNING("ulBkModeOld passed bad mode\n");
  176. }
  177. dco.pdc->jBkMode((BYTE)iBkMode);
  178. dco.vUnlockFast();
  179. }
  180. return((int)ulBkModeOld);
  181. }
  182. /******************************Public*Routine******************************\
  183. * GreSetPolyFillMode
  184. *
  185. * Set the polyline fill mode to either ALTERNATE or WINDING. Any other
  186. * value is invalid and causes an error to be returned. An error is also
  187. * returned if hdc is invalid.
  188. * If successful, return the old fill mode.
  189. *
  190. * History:
  191. * Thu 25-Nov-1993 -by- Patrick Haluptzok [patrickh]
  192. * Smaller code.
  193. *
  194. * 28-Nov-1990 -by- Eric Kutter [erick]
  195. * Wrote it.
  196. \**************************************************************************/
  197. ULONG GreSetPolyFillMode(HDC hdc, int iPolyFillMode)
  198. {
  199. ULONG ulPolyFillModeOld = 0;
  200. XDCOBJ dco(hdc);
  201. if (dco.bValid())
  202. {
  203. ulPolyFillModeOld = dco.pdc->lFillMode();
  204. dco.pdc->lFillMode(iPolyFillMode);
  205. if (iPolyFillMode != WINDING)
  206. {
  207. iPolyFillMode = ALTERNATE;
  208. WARNING("GreSetPolyFillMode passed bad mode");
  209. }
  210. dco.pdc->jFillMode((BYTE)iPolyFillMode);
  211. dco.vUnlockFast();
  212. }
  213. return(ulPolyFillModeOld);
  214. }
  215. /******************************Public*Routine******************************\
  216. * GreSetStretchBltMode
  217. *
  218. * Set the current stretch blt mode. iStretchMode must be one of:
  219. * BLACKONWHITE
  220. * COLORONCOLOR
  221. * WHITEONBLACK
  222. * HALFTONE
  223. *
  224. * If hdc is invalid or iStretchMode is not one of the above, 0 is returned.
  225. * Otherwise, the old stretch blt mode value is returned.
  226. *
  227. * History:
  228. * 3-11-94 -by- Lingyun Wang [lingyunw]
  229. * Moved client side attr to server side
  230. *
  231. * Thu 25-Nov-1993 -by- Patrick Haluptzok [patrickh]
  232. * Smaller code.
  233. *
  234. * Tue 28-May-1991 -by- Patrick Haluptzok [patrickh]
  235. * fixed return value bug, rewrote to compile smaller by nesting
  236. *
  237. * 28-Nov-1990 -by- Eric Kutter [erick]
  238. * Wrote it.
  239. \**************************************************************************/
  240. int GreSetStretchBltMode(HDC hdc, int iStretchMode)
  241. {
  242. ULONG ulStretchModeOld = 0;
  243. XDCOBJ dco(hdc);
  244. if (dco.bValid())
  245. {
  246. ulStretchModeOld = dco.pdc->lStretchBltMode();
  247. dco.pdc->lStretchBltMode(iStretchMode);
  248. if (iStretchMode > MAXSTRETCHBLTMODE)
  249. {
  250. iStretchMode = (DWORD) WHITEONBLACK;
  251. WARNING("GreSetStretchBltMode passed bad mode");
  252. }
  253. dco.pdc->jStretchBltMode((BYTE)iStretchMode);
  254. dco.vUnlockFast();
  255. }
  256. return((int)ulStretchModeOld);
  257. }
  258. /******************************Public*Routine******************************\
  259. * GreGetTextColor
  260. *
  261. * Get the current text color.
  262. *
  263. * History:
  264. * Thu 25-Nov-1993 -by- Patrick Haluptzok [patrickh]
  265. * Smaller code.
  266. *
  267. * 28-Nov-1990 -by- Eric Kutter [erick]
  268. * Wrote it.
  269. \**************************************************************************/
  270. COLORREF GreGetTextColor(HDC hdc)
  271. {
  272. COLORREF clr = CLR_INVALID;
  273. XDCOBJ dco(hdc);
  274. if (dco.bValid())
  275. {
  276. clr = dco.pdc->ulTextClr();
  277. dco.vUnlockFast();
  278. }
  279. return(clr);
  280. }
  281. /******************************Public*Routine******************************\
  282. * GreSetTextColor
  283. *
  284. * Set the current text color.
  285. *
  286. * History:
  287. * Thu 25-Nov-1993 -by- Patrick Haluptzok [patrickh]
  288. * Smaller code.
  289. *
  290. * 28-Nov-1990 -by- Eric Kutter [erick]
  291. * Wrote it.
  292. \**************************************************************************/
  293. COLORREF GreSetTextColor(HDC hdc, COLORREF cr)
  294. {
  295. COLORREF crOld = CLR_INVALID;
  296. XDCOBJ dco(hdc);
  297. if (dco.bValid())
  298. {
  299. crOld = dco.pdc->ulTextClr();
  300. dco.pdc->ulTextClr(cr);
  301. cr &= 0x13ffffff;
  302. if (cr != crOld)
  303. {
  304. dco.pdc->crTextClr(cr);
  305. dco.pdc->ulDirtyAdd(DIRTY_FILL|DIRTY_LINE|DIRTY_TEXT);
  306. }
  307. dco.vUnlockFast();
  308. }
  309. return(crOld);
  310. }
  311. /******************************Public*Routine******************************\
  312. * GreGetFillBrush
  313. *
  314. * Return the fill brush of the DC
  315. *
  316. * Arguments:
  317. *
  318. * hdc
  319. *
  320. * Return Value:
  321. *
  322. * hbrush or NULL
  323. *
  324. \**************************************************************************/
  325. extern "C"
  326. HBRUSH
  327. GreGetFillBrush(HDC hdc)
  328. {
  329. HBRUSH hbrRet = NULL;
  330. XDCOBJ dcobj(hdc);
  331. if (dcobj.bValid())
  332. {
  333. hbrRet = (HBRUSH)(dcobj.pdc->pbrushFill())->hGet();
  334. dcobj.vUnlockFast();
  335. }
  336. return(hbrRet);
  337. }
  338.