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.

622 lines
19 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: dcmod.c *
  3. * *
  4. * Client side stubs for functions that modify the state of the DC in the *
  5. * server. *
  6. * *
  7. * Created: 05-Jun-1991 01:49:42 *
  8. * Author: Charles Whitmer [chuckwh] *
  9. * *
  10. * Copyright (c) 1991-1999 Microsoft Corporation *
  11. \**************************************************************************/
  12. #include "precomp.h"
  13. #pragma hdrstop
  14. #include "winuserk.h"
  15. BOOL InitDeviceInfo(PLDC pldc, HDC hdc);
  16. VOID vComputePageXform(PLDC pldc);
  17. DWORD GetAndSetDCDWord( HDC, UINT, UINT, UINT, WORD, UINT );
  18. #define DBG_XFORM 0
  19. /******************************Public*Routine******************************\
  20. * MoveToEx *
  21. * *
  22. * Client side stub. It's important to batch this call whenever we can. *
  23. * *
  24. * History: *
  25. * Thu 06-Jun-1991 23:10:01 -by- Charles Whitmer [chuckwh] *
  26. * Wrote it. *
  27. \**************************************************************************/
  28. BOOL META WINAPI MoveToEx(HDC hdc,int x,int y,LPPOINT pptl)
  29. {
  30. BOOL bRet = FALSE;
  31. PDC_ATTR pDcAttr;
  32. FIXUP_HANDLE(hdc);
  33. if (IS_ALTDC_TYPE(hdc))
  34. {
  35. PLDC pldc;
  36. if (IS_METADC16_TYPE(hdc))
  37. return (MF16_RecordParms3(hdc,x,y,META_MOVETO));
  38. DC_PLDC(hdc,pldc,bRet);
  39. if (pldc->iType == LO_METADC)
  40. {
  41. if (!MF_SetDD(hdc,(DWORD)x,(DWORD)y,EMR_MOVETOEX))
  42. return(bRet);
  43. }
  44. }
  45. PSHARED_GET_VALIDATE(pDcAttr,hdc,DC_TYPE);
  46. if (pDcAttr)
  47. {
  48. bRet = TRUE;
  49. if (pptl != NULL)
  50. {
  51. // If the logical-space version of the current position is
  52. // invalid, then the device-space version of the current
  53. // position is guaranteed to be valid. So we can reverse
  54. // the current transform on that to compute the logical-
  55. // space version:
  56. if (pDcAttr->ulDirty_ & DIRTY_PTLCURRENT)
  57. {
  58. *((POINTL*)pptl) = pDcAttr->ptfxCurrent;
  59. pptl->x = FXTOL(pptl->x);
  60. pptl->y = FXTOL(pptl->y);
  61. bRet = DPtoLP(hdc,pptl,1);
  62. }
  63. else
  64. {
  65. *((POINTL*)pptl) = pDcAttr->ptlCurrent;
  66. }
  67. }
  68. pDcAttr->ptlCurrent.x = x;
  69. pDcAttr->ptlCurrent.y = y;
  70. // We now know the new logical-space version of the current position
  71. // (but not the device-space version). Mark it as such. We also
  72. // have to reset the style-state for styled pens.
  73. pDcAttr->ulDirty_ &= ~DIRTY_PTLCURRENT;
  74. pDcAttr->ulDirty_ |= (DIRTY_PTFXCURRENT | DIRTY_STYLESTATE);
  75. }
  76. else
  77. {
  78. GdiSetLastError(ERROR_INVALID_PARAMETER);
  79. }
  80. return(bRet);
  81. }
  82. /******************************Public*Routine******************************\
  83. * OffsetClipRgn *
  84. * *
  85. * Client side stub. *
  86. * *
  87. * History: *
  88. * Thu 06-Jun-1991 23:10:01 -by- Charles Whitmer [chuckwh] *
  89. * Wrote it. *
  90. \**************************************************************************/
  91. int META WINAPI OffsetClipRgn(HDC hdc,int x,int y)
  92. {
  93. int iRet = RGN_ERROR;
  94. FIXUP_HANDLE(hdc);
  95. if (IS_ALTDC_TYPE(hdc))
  96. {
  97. PLDC pldc;
  98. if (IS_METADC16_TYPE(hdc))
  99. return(MF16_RecordParms3(hdc,x,y,META_OFFSETCLIPRGN));
  100. DC_PLDC(hdc,pldc,iRet);
  101. if (pldc->iType == LO_METADC)
  102. {
  103. if (!MF_OffsetClipRgn(hdc,x,y))
  104. return(iRet);
  105. }
  106. }
  107. return(NtGdiOffsetClipRgn(hdc,x,y));
  108. }
  109. /******************************Public*Routine******************************\
  110. * SetMetaRgn
  111. *
  112. * Client side stub.
  113. *
  114. * History:
  115. * Tue Apr 07 17:05:37 1992 -by- Hock San Lee [hockl]
  116. * Wrote it.
  117. \**************************************************************************/
  118. int WINAPI SetMetaRgn(HDC hdc)
  119. {
  120. int iRet = RGN_ERROR;
  121. FIXUP_HANDLE(hdc);
  122. if (IS_ALTDC_TYPE(hdc))
  123. {
  124. PLDC pldc;
  125. DC_PLDC(hdc,pldc,iRet);
  126. if (pldc->iType == LO_METADC && !MF_SetMetaRgn(hdc))
  127. return(iRet);
  128. }
  129. return(NtGdiSetMetaRgn(hdc));
  130. }
  131. /******************************Public*Routine******************************\
  132. * SelectPalette *
  133. * *
  134. * Client side stub. *
  135. * *
  136. * History: *
  137. * Thu 06-Jun-1991 23:10:01 -by- Charles Whitmer [chuckwh] *
  138. * Wrote it. *
  139. \**************************************************************************/
  140. HPALETTE META WINAPI SelectPalette(HDC hdc,HPALETTE hpal,BOOL b)
  141. {
  142. ULONG_PTR hRet = 0;
  143. FIXUP_HANDLE(hdc);
  144. FIXUP_HANDLE(hpal);
  145. if (IS_ALTDC_TYPE(hdc))
  146. {
  147. PLDC pldc;
  148. if (IS_METADC16_TYPE(hdc))
  149. return ((HPALETTE)(ULONG_PTR)MF16_SelectPalette(hdc,hpal));
  150. DC_PLDC(hdc,pldc,(HPALETTE)hRet);
  151. if (pldc->iType == LO_METADC)
  152. {
  153. if (!MF_SelectAnyObject(hdc,(HANDLE)hpal,EMR_SELECTPALETTE))
  154. return((HPALETTE) hRet);
  155. }
  156. }
  157. return(NtUserSelectPalette(hdc,hpal,b));
  158. }
  159. /******************************Public*Routine******************************\
  160. * SetMapperFlags *
  161. * *
  162. * Client side stub. *
  163. * *
  164. * History: *
  165. * Thu 06-Jun-1991 23:10:01 -by- Charles Whitmer [chuckwh] *
  166. * Wrote it. *
  167. \**************************************************************************/
  168. DWORD META WINAPI SetMapperFlags(HDC hdc,DWORD fl)
  169. {
  170. DWORD dwRet;
  171. PDC_ATTR pdcattr;
  172. FIXUP_HANDLE(hdc);
  173. PSHARED_GET_VALIDATE(pdcattr,hdc,DC_TYPE);
  174. if (pdcattr)
  175. {
  176. CHECK_AND_FLUSH_TEXT (hdc, pdcattr);
  177. if (fl & (~ASPECT_FILTERING))
  178. {
  179. WARNING("gdisrv!GreSetMapperFlags(): unknown flag\n");
  180. GdiSetLastError(ERROR_INVALID_PARAMETER);
  181. dwRet = GDI_ERROR;
  182. }
  183. else
  184. {
  185. dwRet = pdcattr->flFontMapper;
  186. pdcattr->flFontMapper = fl;
  187. }
  188. }
  189. else
  190. {
  191. WARNING("gdi32!SetMapperFlags(): invalid hdc\n");
  192. GdiSetLastError(ERROR_INVALID_PARAMETER);
  193. dwRet = GDI_ERROR;
  194. }
  195. return(dwRet);
  196. }
  197. // SetMapperFlagsInternal - no metafile version.
  198. DWORD SetMapperFlagsInternal(HDC hdc,DWORD fl)
  199. {
  200. return(GetAndSetDCDWord( hdc,
  201. GASDDW_MAPPERFLAGS,
  202. fl,
  203. EMR_MAX+1,
  204. EMR_MAX+1,
  205. GDI_ERROR ));
  206. }
  207. /******************************Public*Routine******************************\
  208. * SetSystemPaletteUse *
  209. * *
  210. * Client side stub. *
  211. * *
  212. * This function is not metafile'd. *
  213. * *
  214. * History: *
  215. * Thu 06-Jun-1991 23:10:01 -by- Charles Whitmer [chuckwh] *
  216. * Wrote it. *
  217. \**************************************************************************/
  218. UINT META WINAPI SetSystemPaletteUse(HDC hdc,UINT iMode)
  219. {
  220. FIXUP_HANDLE(hdc);
  221. return(NtGdiSetSystemPaletteUse(hdc,iMode));
  222. }
  223. /******************************Public*Routine******************************\
  224. * SetTextJustification *
  225. * *
  226. * Client side stub. *
  227. * *
  228. * History: *
  229. * Thu 14-Jan-1993 03:30:27 -by- Charles Whitmer [chuckwh] *
  230. * Save a copy in the LDC for computing text extent. *
  231. * *
  232. * Thu 06-Jun-1991 23:10:01 -by- Charles Whitmer [chuckwh] *
  233. * Wrote it. *
  234. \**************************************************************************/
  235. BOOL META WINAPI SetTextJustification(HDC hdc,int dx,int cBreak)
  236. {
  237. PDC_ATTR pdcattr;
  238. BOOL bRet = FALSE;
  239. FIXUP_HANDLE(hdc);
  240. if (IS_METADC16_TYPE(hdc))
  241. return (MF16_RecordParms3(hdc,dx,cBreak,META_SETTEXTJUSTIFICATION));
  242. PSHARED_GET_VALIDATE(pdcattr,hdc,DC_TYPE);
  243. if (pdcattr)
  244. {
  245. CHECK_AND_FLUSH_TEXT (hdc, pdcattr);
  246. pdcattr->lBreakExtra = dx;
  247. pdcattr->cBreak = cBreak;
  248. bRet = TRUE;
  249. }
  250. return(bRet);
  251. }
  252. /******************************Public*Routine******************************\
  253. * SetArcDirection
  254. *
  255. * Client side stub. Batches the call.
  256. *
  257. * History:
  258. * 20-Mar-1992 -by- J. Andrew Goossen [andrewgo]
  259. * Wrote it.
  260. \**************************************************************************/
  261. int META WINAPI SetArcDirection(HDC hdc,int iArcDirection)
  262. {
  263. FIXUP_HANDLE(hdc);
  264. return(GetAndSetDCDWord( hdc,
  265. GASDDW_ARCDIRECTION,
  266. iArcDirection,
  267. EMR_MAX+1,
  268. EMR_MAX+1,
  269. ERROR));
  270. }
  271. /******************************Public*Routine******************************\
  272. * SetMiterLimit
  273. *
  274. * Client side stub. Batches the call whenever it can.
  275. *
  276. * History:
  277. * 13-Sep-1991 -by- J. Andrew Goossen [andrewgo]
  278. * Wrote it.
  279. \**************************************************************************/
  280. BOOL META WINAPI SetMiterLimit(HDC hdc,FLOAT e,PFLOAT pe)
  281. {
  282. BOOL bRet = FALSE;
  283. FIXUP_HANDLE(hdc);
  284. if (IS_ALTDC_TYPE(hdc))
  285. {
  286. PLDC pldc;
  287. DC_PLDC(hdc,pldc,bRet);
  288. if (pldc->iType == LO_METADC && !MF_SetD(hdc,(DWORD)e,EMR_SETMITERLIMIT))
  289. return(bRet);
  290. }
  291. return(NtGdiSetMiterLimit(hdc,FLOATARG(e),FLOATPTRARG(pe)));
  292. }
  293. /******************************Public*Routine******************************\
  294. * SetFontXform
  295. *
  296. * Client side stub. Batches the call whenever it can.
  297. * This is an internal function.
  298. *
  299. * History:
  300. * Tue Nov 24 09:54:15 1992 -by- Hock San Lee [hockl] *
  301. * Wrote it.
  302. \**************************************************************************/
  303. BOOL SetFontXform(HDC hdc,FLOAT exScale,FLOAT eyScale)
  304. {
  305. BOOL bRet = FALSE;
  306. FIXUP_HANDLE(hdc);
  307. // This function is called only by the metafile playback code.
  308. // If hdc is an enhanced metafile DC, we need to remember the scales
  309. // so that we can metafile it in the compatible ExtTextOut or PolyTextOut
  310. // record that follows.
  311. if (IS_ALTDC_TYPE(hdc))
  312. {
  313. PLDC pldc;
  314. DC_PLDC(hdc,pldc,bRet);
  315. if (pldc->iType == LO_METADC && !MF_SetFontXform(hdc,exScale,eyScale))
  316. return(bRet);
  317. }
  318. // If the dc is mirrored then do not mirror the text at play back time.
  319. if (GetLayout(hdc) & LAYOUT_RTL) {
  320. exScale = -exScale;
  321. }
  322. return(NtGdiSetFontXform(hdc,FLOATARG(exScale),FLOATARG(eyScale)));
  323. }
  324. /******************************Public*Routine******************************\
  325. * SetBrushOrgEx *
  326. * *
  327. * Client side stub. *
  328. * *
  329. * History: *
  330. * Thu 06-Jun-1991 23:10:01 -by- Charles Whitmer [chuckwh] *
  331. * Wrote it. *
  332. \**************************************************************************/
  333. BOOL META WINAPI SetBrushOrgEx(HDC hdc,int x,int y,LPPOINT pptl)
  334. {
  335. BOOL bRet = FALSE;
  336. PDC_ATTR pdcattr;
  337. FIXUP_HANDLE(hdc);
  338. if (IS_ALTDC_TYPE(hdc))
  339. {
  340. PLDC pldc;
  341. DC_PLDC(hdc,pldc,bRet);
  342. if (pldc->iType == LO_METADC && !MF_SetBrushOrgEx(hdc,x,y))
  343. return(bRet);
  344. }
  345. PSHARED_GET_VALIDATE(pdcattr,hdc,DC_TYPE);
  346. if (pdcattr != NULL)
  347. {
  348. if (pptl != (LPPOINT)NULL)
  349. {
  350. *pptl = *((LPPOINT)&pdcattr->ptlBrushOrigin);
  351. }
  352. if (
  353. (pdcattr->ptlBrushOrigin.x != x) ||
  354. (pdcattr->ptlBrushOrigin.y != y)
  355. )
  356. {
  357. BEGIN_BATCH_HDC(hdc,pdcattr,BatchTypeSetBrushOrg,BATCHSETBRUSHORG);
  358. pdcattr->ptlBrushOrigin.x = x;
  359. pdcattr->ptlBrushOrigin.y = y;
  360. pBatch->x = x;
  361. pBatch->y = y;
  362. COMPLETE_BATCH_COMMAND();
  363. }
  364. bRet = TRUE;
  365. }
  366. else
  367. {
  368. UNBATCHED_COMMAND:
  369. bRet = NtGdiSetBrushOrg(hdc,x,y,pptl);
  370. }
  371. return(bRet);
  372. }
  373. /******************************Public*Routine******************************\
  374. * RealizePalette *
  375. * *
  376. * Client side stub. *
  377. * *
  378. * History: *
  379. * Thu 06-Jun-1991 23:10:01 -by- Charles Whitmer [chuckwh] *
  380. * Wrote it. *
  381. \**************************************************************************/
  382. UINT WINAPI RealizePalette(HDC hdc)
  383. {
  384. FIXUP_HANDLE(hdc);
  385. if (IS_ALTDC_TYPE(hdc))
  386. {
  387. UINT uRet = 0xFFFFFFFF;
  388. PLDC pldc;
  389. if (IS_METADC16_TYPE(hdc))
  390. return((UINT) MF16_RealizePalette(hdc));
  391. DC_PLDC(hdc,pldc,uRet);
  392. if (pldc->iType == LO_METADC)
  393. {
  394. HPALETTE hpal = (HPALETTE)GetDCObject(hdc,LO_PALETTE_TYPE);
  395. if ((pmetalink16Get(hpal) != NULL) && !MF_RealizePalette(hpal))
  396. return(uRet);
  397. }
  398. }
  399. return(UserRealizePalette(hdc));
  400. }
  401. /******************************Public*Routine******************************\
  402. * GetBoundsRect
  403. *
  404. * Client side stub.
  405. *
  406. * History:
  407. * 06-Apr-1992 -by- Donald Sidoroff [donalds]
  408. * Wrote it.
  409. \**************************************************************************/
  410. UINT WINAPI GetBoundsRect(HDC hdc, LPRECT lprc, UINT fl)
  411. {
  412. FIXUP_HANDLE(hdc);
  413. // Applications can never set DCB_WINDOWMGR
  414. return(NtGdiGetBoundsRect(hdc, lprc, fl & ~DCB_WINDOWMGR));
  415. }
  416. UINT WINAPI GetBoundsRectAlt(HDC hdc, LPRECT lprc, UINT fl)
  417. {
  418. FIXUP_HANDLE(hdc);
  419. return(NtGdiGetBoundsRect(hdc,lprc,fl));
  420. }
  421. /******************************Public*Routine******************************\
  422. * SetBoundsRect
  423. *
  424. * Client side stub.
  425. *
  426. * History:
  427. * 06-Apr-1992 -by- Donald Sidoroff [donalds]
  428. * Wrote it.
  429. \**************************************************************************/
  430. UINT WINAPI SetBoundsRect(HDC hdc, CONST RECT *lprc, UINT fl)
  431. {
  432. FIXUP_HANDLE(hdc);
  433. // Applications can never set DCB_WINDOWMGR
  434. return(NtGdiSetBoundsRect(hdc, (LPRECT)lprc, fl & ~DCB_WINDOWMGR));
  435. }
  436. UINT WINAPI SetBoundsRectAlt(HDC hdc, CONST RECT *lprc, UINT fl)
  437. {
  438. FIXUP_HANDLE(hdc);
  439. return(NtGdiSetBoundsRect(hdc,(LPRECT)lprc,fl));
  440. }
  441. /******************************Public*Routine******************************\
  442. * CancelDC1()
  443. *
  444. * History:
  445. * 14-Apr-1992 -by- - by - Eric Kutter [erick]
  446. * Wrote it.
  447. \**************************************************************************/
  448. BOOL WINAPI CancelDC(HDC hdc)
  449. {
  450. BOOL bRes = FALSE;
  451. PDC_ATTR pDcAttr;
  452. FIXUP_HANDLE(hdc);
  453. if (IS_ALTDC_TYPE(hdc) && !IS_METADC16_TYPE(hdc))
  454. {
  455. PLDC pldc;
  456. DC_PLDC(hdc,pldc,bRes);
  457. if (pldc->fl & LDC_DOC_STARTED)
  458. {
  459. pldc->fl |= LDC_DOC_CANCELLED;
  460. }
  461. bRes = NtGdiCancelDC(hdc);
  462. }
  463. // If we are in the process of playing the metafile, stop the playback.
  464. PSHARED_GET_VALIDATE(pDcAttr,hdc,DC_TYPE);
  465. if (pDcAttr)
  466. {
  467. pDcAttr->ulDirty_ &= ~DC_PLAYMETAFILE;
  468. bRes = TRUE;
  469. }
  470. return(bRes);
  471. }
  472. /******************************Public*Function*****************************\
  473. * SetColorAdjustment
  474. *
  475. * Set the color adjustment data for a given DC.
  476. *
  477. * History:
  478. * 07-Aug-1992 -by- Wendy Wu [wendywu]
  479. * Wrote it.
  480. \**************************************************************************/
  481. BOOL META APIENTRY SetColorAdjustment(HDC hdc, CONST COLORADJUSTMENT * pca)
  482. {
  483. FIXUP_HANDLE(hdc);
  484. if (IS_ALTDC_TYPE(hdc))
  485. {
  486. BOOL bRet = FALSE;
  487. PLDC pldc;
  488. DC_PLDC(hdc,pldc,bRet);
  489. if (pldc->iType == LO_METADC && !MF_SetColorAdjustment(hdc, pca))
  490. {
  491. return(bRet);
  492. }
  493. }
  494. return(NtGdiSetColorAdjustment(hdc,(COLORADJUSTMENT*)pca));
  495. }