7 GreDPtoLP(HDC hdc
, LPPOINT lpPoints
, INT nCount
)
10 if (!(dc
= DC_LockDc(hdc
)))
12 EngSetLastError(ERROR_INVALID_HANDLE
);
15 IntDPtoLP(dc
, lpPoints
, nCount
);
21 GreLPtoDP(HDC hdc
, LPPOINT lpPoints
, INT nCount
)
24 if (!(dc
= DC_LockDc(hdc
)))
26 EngSetLastError(ERROR_INVALID_HANDLE
);
29 IntLPtoDP(dc
, lpPoints
, nCount
);
39 if (!(dc
= DC_LockDc(hdc
)))
41 EngSetLastError(ERROR_INVALID_HANDLE
);
44 lBkMode
= dc
->pdcattr
->lBkMode
;
50 GreGetBkColor(HDC hdc
)
54 if (!(dc
= DC_LockDc(hdc
)))
56 EngSetLastError(ERROR_INVALID_HANDLE
);
59 crBk
= dc
->pdcattr
->ulBackgroundClr
;
65 GreGetMapMode(HDC hdc
)
69 if (!(dc
= DC_LockDc(hdc
)))
71 EngSetLastError(ERROR_INVALID_HANDLE
);
74 iMapMode
= dc
->pdcattr
->iMapMode
;
80 GreGetTextColor(HDC hdc
)
83 ULONG ulForegroundClr
;
84 if (!(dc
= DC_LockDc(hdc
)))
86 EngSetLastError(ERROR_INVALID_HANDLE
);
89 ulForegroundClr
= dc
->pdcattr
->ulForegroundClr
;
91 return ulForegroundClr
;
95 IntGdiSetBkColor(HDC hDC
, COLORREF color
)
102 if (!(dc
= DC_LockDc(hDC
)))
104 EngSetLastError(ERROR_INVALID_HANDLE
);
107 pdcattr
= dc
->pdcattr
;
109 oldColor
= pdcattr
->ulBackgroundClr
;
110 pdcattr
->ulBackgroundClr
= color
;
112 if (pdcattr
->crBackgroundClr
!= color
)
114 pdcattr
->ulDirty_
|= (DIRTY_BACKGROUND
|DIRTY_LINE
|DIRTY_FILL
); // Clear Flag if set.
115 pdcattr
->crBackgroundClr
= color
;
117 hBrush
= pdcattr
->hbrush
;
119 NtGdiSelectBrush(hDC
, hBrush
);
124 IntGdiSetBkMode(HDC hDC
, INT Mode
)
130 if (!(dc
= DC_LockDc(hDC
)))
132 EngSetLastError(ERROR_INVALID_HANDLE
);
135 pdcattr
= dc
->pdcattr
;
136 oldMode
= pdcattr
->lBkMode
;
137 pdcattr
->jBkMode
= Mode
;
138 pdcattr
->lBkMode
= Mode
;
145 IntGdiSetTextAlign(HDC hDC
,
155 EngSetLastError(ERROR_INVALID_HANDLE
);
158 pdcattr
= dc
->pdcattr
;
159 prevAlign
= pdcattr
->lTextAlign
;
160 pdcattr
->lTextAlign
= Mode
;
167 IntGdiSetTextColor(HDC hDC
,
174 pdc
= DC_LockDc(hDC
);
177 EngSetLastError(ERROR_INVALID_HANDLE
);
180 pdcattr
= pdc
->pdcattr
;
182 crOldColor
= (COLORREF
) pdcattr
->ulForegroundClr
;
183 pdcattr
->ulForegroundClr
= (ULONG
)color
;
185 if (pdcattr
->crForegroundClr
!= color
)
187 pdcattr
->ulDirty_
|= (DIRTY_TEXT
|DIRTY_LINE
|DIRTY_FILL
);
188 pdcattr
->crForegroundClr
= color
;
191 DC_vUpdateTextBrush(pdc
);
192 DC_vUpdateLineBrush(pdc
);
193 DC_vUpdateFillBrush(pdc
);
201 IntSetDCBrushColor(HDC hdc
, COLORREF crColor
)
203 COLORREF OldColor
= CLR_INVALID
;
205 if (!(dc
= DC_LockDc(hdc
)))
207 EngSetLastError(ERROR_INVALID_HANDLE
);
212 OldColor
= (COLORREF
) dc
->pdcattr
->ulBrushClr
;
213 dc
->pdcattr
->ulBrushClr
= (ULONG
) crColor
;
215 if ( dc
->pdcattr
->crBrushClr
!= crColor
)
217 dc
->pdcattr
->ulDirty_
|= DIRTY_FILL
;
218 dc
->pdcattr
->crBrushClr
= crColor
;
232 PDC pdc
= DC_LockDc(hdc
);
235 EngSetLastError(ERROR_INVALID_HANDLE
);
241 *pptOut
= pdc
->pdcattr
->ptlBrushOrigin
;
244 pdc
->pdcattr
->ptlBrushOrigin
.x
= x
;
245 pdc
->pdcattr
->ptlBrushOrigin
.y
= y
;
247 DC_vSetBrushOrigin(pdc
, x
, y
);
254 IntSetDCPenColor(HDC hdc
, COLORREF crColor
)
258 if (!(dc
= DC_LockDc(hdc
)))
260 EngSetLastError(ERROR_INVALID_PARAMETER
);
264 OldColor
= (COLORREF
)dc
->pdcattr
->ulPenClr
;
265 dc
->pdcattr
->ulPenClr
= (ULONG
)crColor
;
267 if (dc
->pdcattr
->crPenClr
!= crColor
)
269 dc
->pdcattr
->ulDirty_
|= DIRTY_LINE
;
270 dc
->pdcattr
->crPenClr
= crColor
;
278 GreSetStretchBltMode(HDC hDC
, int iStretchMode
)
284 pdc
= DC_LockDc(hDC
);
287 pdcattr
= pdc
->pdcattr
;
288 oSMode
= pdcattr
->lStretchBltMode
;
289 pdcattr
->lStretchBltMode
= iStretchMode
;
291 // Wine returns an error here. We set the default.
292 if ((iStretchMode
<= 0) || (iStretchMode
> MAXSTRETCHBLTMODE
)) iStretchMode
= WHITEONBLACK
;
294 pdcattr
->jStretchBltMode
= iStretchMode
;
301 GreGetGraphicsMode(HDC hdc
)
305 if (!(dc
= DC_LockDc(hdc
)))
307 EngSetLastError(ERROR_INVALID_HANDLE
);
310 GraphicsMode
= dc
->pdcattr
->iGraphicsMode
;
317 DCU_SetDcUndeletable(HDC hDC
)
319 PDC dc
= DC_LockDc(hDC
);
322 EngSetLastError(ERROR_INVALID_HANDLE
);
326 dc
->fs
|= DC_FLAG_PERMANENT
;
333 IntIsPrimarySurface(SURFOBJ
*SurfObj
)
335 if (PrimarySurface
.pSurface
== NULL
)
339 return SurfObj
->hsurf
== PrimarySurface
.pSurface
; // <- FIXME: WTF?
345 IntSetDefaultRegion(PDC pdc
)
349 RECTL rclWnd
, rclClip
;
351 IntGdiReleaseRaoRgn(pdc
);
355 rclWnd
.right
= pdc
->dclevel
.sizl
.cx
;
356 rclWnd
.bottom
= pdc
->dclevel
.sizl
.cy
;
359 //EngAcquireSemaphoreShared(pdc->ppdev->hsemDevLock);
360 if (pdc
->ppdev
->flFlags
& PDEV_META_DEVICE
)
362 pSurface
= pdc
->dclevel
.pSurface
;
363 if (pSurface
&& pSurface
->flags
& PDEV_SURFACE
)
365 rclClip
.left
+= pdc
->ppdev
->ptlOrigion
.x
;
366 rclClip
.top
+= pdc
->ppdev
->ptlOrigion
.y
;
367 rclClip
.right
+= pdc
->ppdev
->ptlOrigion
.x
;
368 rclClip
.bottom
+= pdc
->ppdev
->ptlOrigion
.y
;
371 //EngReleaseSemaphore(pdc->ppdev->hsemDevLock);
375 if (prgn
&& prgn
!= prgnDefault
)
377 REGION_SetRectRgn( prgn
,
385 prgn
= IntSysCreateRectpRgn( rclClip
.left
,
394 pdc
->ptlDCOrig
.x
= 0;
395 pdc
->ptlDCOrig
.y
= 0;
396 pdc
->erclWindow
= rclWnd
;
397 pdc
->erclClip
= rclClip
;
398 /* Might be an InitDC or DCE... */
399 pdc
->ptlFillOrigin
.x
= pdc
->dcattr
.VisRectRegion
.Rect
.right
;
400 pdc
->ptlFillOrigin
.y
= pdc
->dcattr
.VisRectRegion
.Rect
.bottom
;
404 pdc
->prgnVis
= prgnDefault
;
410 NtGdiCancelDC(HDC hDC
)
418 IntGdiSetHookFlags(HDC hDC
, WORD Flags
)
421 DC
*dc
= DC_LockDc(hDC
);
425 EngSetLastError(ERROR_INVALID_HANDLE
);
429 wRet
= dc
->fs
& DC_FLAG_DIRTY_RAO
; // FIXME: Wrong flag!
431 /* Info in "Undocumented Windows" is slightly confusing. */
432 DPRINT("DC %p, Flags %04x\n", hDC
, Flags
);
434 if (Flags
& DCHF_INVALIDATEVISRGN
)
436 /* hVisRgn has to be updated */
437 dc
->fs
|= DC_FLAG_DIRTY_RAO
;
439 else if (Flags
& DCHF_VALIDATEVISRGN
|| 0 == Flags
)
441 //dc->fs &= ~DC_FLAG_DIRTY_RAO;
461 DWORD SafeResult
= 0;
462 NTSTATUS Status
= STATUS_SUCCESS
;
466 EngSetLastError(ERROR_INVALID_PARAMETER
);
470 pdc
= DC_LockDc(hDC
);
473 EngSetLastError(ERROR_INVALID_HANDLE
);
476 pdcattr
= pdc
->pdcattr
;
484 SafeResult
= pdcattr
->lRelAbs
;
487 case GdiGetBreakExtra
:
488 SafeResult
= pdcattr
->lBreakExtra
;
491 case GdiGerCharBreak
:
492 SafeResult
= pdcattr
->cBreak
;
495 case GdiGetArcDirection
:
496 if (pdcattr
->dwLayout
& LAYOUT_RTL
)
497 SafeResult
= AD_CLOCKWISE
- ((pdc
->dclevel
.flPath
& DCPATH_CLOCKWISE
) != 0);
499 SafeResult
= ((pdc
->dclevel
.flPath
& DCPATH_CLOCKWISE
) != 0) + AD_COUNTERCLOCKWISE
;
502 case GdiGetEMFRestorDc
:
503 SafeResult
= pdc
->dclevel
.lSaveDepth
;
506 case GdiGetFontLanguageInfo
:
507 SafeResult
= IntGetFontLanguageInfo(pdc
);
511 SafeResult
= pdc
->dctype
;
515 SafeResult
= pdcattr
->iMapMode
;
518 case GdiGetTextCharExtra
:
519 SafeResult
= pdcattr
->lTextExtra
;
523 EngSetLastError(ERROR_INVALID_PARAMETER
);
532 ProbeForWrite(Result
, sizeof(DWORD
), 1);
533 *Result
= SafeResult
;
535 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
537 Status
= _SEH2_GetExceptionCode();
541 if (!NT_SUCCESS(Status
))
543 SetLastNtError(Status
);
552 _Success_(return != FALSE
)
555 NtGdiGetAndSetDCDword(
559 _Out_ DWORD
*pdwResult
)
565 DWORD SafeResult
= 0;
566 NTSTATUS Status
= STATUS_SUCCESS
;
570 EngSetLastError(ERROR_INVALID_PARAMETER
);
574 pdc
= DC_LockDc(hdc
);
577 EngSetLastError(ERROR_INVALID_HANDLE
);
580 pdcattr
= pdc
->pdcattr
;
584 case GdiGetSetCopyCount
:
585 SafeResult
= pdc
->ulCopyCount
;
586 pdc
->ulCopyCount
= dwIn
;
589 case GdiGetSetTextAlign
:
590 SafeResult
= pdcattr
->lTextAlign
;
591 pdcattr
->lTextAlign
= dwIn
;
592 // pdcattr->flTextAlign = dwIn; // Flags!
595 case GdiGetSetRelAbs
:
596 SafeResult
= pdcattr
->lRelAbs
;
597 pdcattr
->lRelAbs
= dwIn
;
600 case GdiGetSetTextCharExtra
:
601 SafeResult
= pdcattr
->lTextExtra
;
602 pdcattr
->lTextExtra
= dwIn
;
605 case GdiGetSetSelectFont
:
608 case GdiGetSetMapperFlagsInternal
:
611 EngSetLastError(ERROR_INVALID_PARAMETER
);
615 SafeResult
= pdcattr
->flFontMapper
;
616 pdcattr
->flFontMapper
= dwIn
;
619 case GdiGetSetMapMode
:
620 SafeResult
= IntGdiSetMapMode(pdc
, dwIn
);
623 case GdiGetSetArcDirection
:
624 if (dwIn
!= AD_COUNTERCLOCKWISE
&& dwIn
!= AD_CLOCKWISE
)
626 EngSetLastError(ERROR_INVALID_PARAMETER
);
630 if (pdcattr
->dwLayout
& LAYOUT_RTL
) // Right to Left
632 SafeResult
= AD_CLOCKWISE
- ((pdc
->dclevel
.flPath
& DCPATH_CLOCKWISE
) != 0);
633 if (dwIn
== AD_CLOCKWISE
)
635 pdc
->dclevel
.flPath
&= ~DCPATH_CLOCKWISE
;
638 pdc
->dclevel
.flPath
|= DCPATH_CLOCKWISE
;
640 else // Left to Right
642 SafeResult
= ((pdc
->dclevel
.flPath
& DCPATH_CLOCKWISE
) != 0) +
644 if (dwIn
== AD_COUNTERCLOCKWISE
)
646 pdc
->dclevel
.flPath
&= ~DCPATH_CLOCKWISE
;
649 pdc
->dclevel
.flPath
|= DCPATH_CLOCKWISE
;
654 EngSetLastError(ERROR_INVALID_PARAMETER
);
663 ProbeForWrite(pdwResult
, sizeof(DWORD
), 1);
664 *pdwResult
= SafeResult
;
666 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
668 Status
= _SEH2_GetExceptionCode();
672 if (!NT_SUCCESS(Status
))
674 SetLastNtError(Status
);
685 IntUpdateBoundsRect(PDC pdc
, PRECTL pRect
)
687 if (pdc
->fs
& DC_ACCUM_APP
)
689 RECTL_bUnionRect(&pdc
->erclBoundsApp
, &pdc
->erclBoundsApp
, pRect
);
691 if (pdc
->fs
& DC_ACCUM_WMGR
)
693 RECTL_bUnionRect(&pdc
->erclBounds
, &pdc
->erclBounds
, pRect
);
709 if (!(pdc
= DC_LockDc(hdc
))) return 0;
711 if (!(flags
& DCB_WINDOWMGR
))
713 rc
= pdc
->erclBoundsApp
;
715 if (RECTL_bIsEmptyRect(&rc
))
717 rc
.left
= rc
.top
= rc
.right
= rc
.bottom
= 0;
723 if (pdc
->fs
& DC_FLAG_DIRTY_RAO
) CLIPPING_UpdateGCRegion(pdc
);
724 if(!REGION_GetRgnBox(pdc
->prgnRao
, &rcRgn
))
726 REGION_GetRgnBox(pdc
->prgnVis
, &rcRgn
);
728 rc
.left
= max( rc
.left
, 0 );
729 rc
.top
= max( rc
.top
, 0 );
730 rc
.right
= min( rc
.right
, rcRgn
.right
- rcRgn
.left
);
731 rc
.bottom
= min( rc
.bottom
, rcRgn
.bottom
- rcRgn
.top
);
732 DPRINT("Rao dc %p r %d b %d\n",pdc
,rcRgn
.right
- rcRgn
.left
, rcRgn
.bottom
- rcRgn
.top
);
733 DPRINT("rc l %d t %d\n",rc
.left
,rc
.top
);
734 DPRINT(" r %d b %d\n",rc
.right
,rc
.bottom
);
737 IntDPtoLP( pdc
, &rc
, 2 );
738 DPRINT("rc1 l %d t %d\n",rc
.left
,rc
.top
);
739 DPRINT(" r %d b %d\n",rc
.right
,rc
.bottom
);
742 rc
= pdc
->erclBounds
;
744 /* Copy the rect to the caller */
747 ProbeForWrite(prc
, sizeof(RECT
), 1);
750 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
756 if (flags
& DCB_RESET
)
758 if (!(flags
& DCB_WINDOWMGR
))
760 pdc
->erclBoundsApp
.left
= pdc
->erclBoundsApp
.top
= INT_MAX
;
761 pdc
->erclBoundsApp
.right
= pdc
->erclBoundsApp
.bottom
= INT_MIN
;
765 pdc
->erclBounds
.left
= pdc
->erclBounds
.top
= INT_MAX
;
766 pdc
->erclBounds
.right
= pdc
->erclBounds
.bottom
= INT_MIN
;
785 /* Verify arguments */
786 if ((flags
& DCB_ENABLE
) && (flags
& DCB_DISABLE
)) return 0;
789 if (!(pdc
= DC_LockDc(hdc
))) return 0;
791 /* Get the return value */
792 ret
= DCB_RESET
; /* we don't have device-specific bounds */
793 ret
= (pdc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
) ? DCB_ENABLE
: DCB_DISABLE
) |
794 (RECTL_bIsEmptyRect(&pdc
->erclBoundsApp
) ? ret
& DCB_SET
: DCB_SET
);
795 ret
|= (flags
& DCB_WINDOWMGR
);
797 if (flags
& DCB_RESET
)
799 if (!(flags
& DCB_WINDOWMGR
))
801 pdc
->erclBoundsApp
.left
= pdc
->erclBoundsApp
.top
= INT_MAX
;
802 pdc
->erclBoundsApp
.right
= pdc
->erclBoundsApp
.bottom
= INT_MIN
;
806 pdc
->erclBounds
.left
= pdc
->erclBounds
.top
= INT_MAX
;
807 pdc
->erclBounds
.right
= pdc
->erclBounds
.bottom
= INT_MIN
;
811 if (flags
& DCB_ACCUMULATE
&& prc
!= NULL
)
813 /* Capture the rect */
816 ProbeForRead(prc
, sizeof(RECT
), 1);
819 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
822 _SEH2_YIELD(return 0;)
826 RECTL_vMakeWellOrdered(&rcl
);
828 if (!(flags
& DCB_WINDOWMGR
))
830 IntLPtoDP( pdc
, (POINT
*)&rcl
, 2 );
831 RECTL_bUnionRect(&pdc
->erclBoundsApp
, &pdc
->erclBoundsApp
, &rcl
);
834 RECTL_bUnionRect(&pdc
->erclBounds
, &pdc
->erclBounds
, &rcl
);
837 if (flags
& DCB_ENABLE
)
839 if (!(flags
& DCB_WINDOWMGR
))
840 pdc
->fs
|= DC_ACCUM_APP
;
842 pdc
->fs
|= DC_ACCUM_WMGR
;
844 if (flags
& DCB_DISABLE
)
846 if (!(flags
& DCB_WINDOWMGR
))
847 pdc
->fs
&= ~DC_ACCUM_APP
;
849 pdc
->fs
&= ~DC_ACCUM_WMGR
;
855 /* Translates a COLORREF to the right color in the specified DC color space */
857 TranslateCOLORREF(PDC pdc
, COLORREF crColor
)
861 ULONG index
, ulColor
, iBitmapFormat
;
864 /* Get the DC surface */
865 psurfDC
= pdc
->dclevel
.pSurface
;
867 /* If no surface is selected, use the default bitmap */
869 psurfDC
= psurfDefaultBitmap
;
871 /* Check what color type this is */
872 switch (crColor
>> 24)
874 case 0x00: /* RGB color */
877 case 0x01: /* PALETTEINDEX */
878 index
= crColor
& 0xFFFFFF;
879 ppalDC
= pdc
->dclevel
.ppal
;
880 if (index
>= ppalDC
->NumColors
) index
= 0;
882 /* Get the RGB value */
883 crColor
= PALETTE_ulGetRGBColorFromIndex(ppalDC
, index
);
886 case 0x02: /* PALETTERGB */
888 if (pdc
->dclevel
.hpal
!= StockObjects
[DEFAULT_PALETTE
])
890 /* First find the nearest index in the dc palette */
891 ppalDC
= pdc
->dclevel
.ppal
;
892 index
= PALETTE_ulGetNearestIndex(ppalDC
, crColor
& 0xFFFFFF);
894 /* Get the RGB value */
895 crColor
= PALETTE_ulGetRGBColorFromIndex(ppalDC
, index
);
899 /* Use the pure color */
900 crColor
= crColor
& 0x00FFFFFF;
904 case 0x10: /* DIBINDEX */
905 /* Mask the value to match the target bpp */
906 iBitmapFormat
= psurfDC
->SurfObj
.iBitmapFormat
;
907 if (iBitmapFormat
== BMF_1BPP
) index
= crColor
& 0x1;
908 else if (iBitmapFormat
== BMF_4BPP
) index
= crColor
& 0xf;
909 else if (iBitmapFormat
== BMF_8BPP
) index
= crColor
& 0xFF;
910 else if (iBitmapFormat
== BMF_16BPP
) index
= crColor
& 0xFFFF;
911 else index
= crColor
& 0xFFFFFF;
915 DPRINT("Unsupported color type %u passed\n", crColor
>> 24);
919 /* Initialize an XLATEOBJ from RGB to the target surface */
920 EXLATEOBJ_vInitialize(&exlo
, &gpalRGB
, psurfDC
->ppal
, 0xFFFFFF, 0, 0);
922 /* Translate the color to the target format */
923 ulColor
= XLATEOBJ_iXlate(&exlo
.xlo
, crColor
);
925 /* Cleanup the XLATEOBJ */
926 EXLATEOBJ_vCleanup(&exlo
);