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
;
108 oldColor
= pdcattr
->crBackgroundClr
;
109 pdcattr
->crBackgroundClr
= color
;
110 pdcattr
->ulBackgroundClr
= (ULONG
)color
;
111 pdcattr
->ulDirty_
|= DIRTY_BACKGROUND
|DIRTY_LINE
|DIRTY_FILL
; // Clear Flag if set.
112 hBrush
= pdcattr
->hbrush
;
114 NtGdiSelectBrush(hDC
, hBrush
);
119 IntGdiSetBkMode(HDC hDC
, INT Mode
)
125 if (!(dc
= DC_LockDc(hDC
)))
127 EngSetLastError(ERROR_INVALID_HANDLE
);
130 pdcattr
= dc
->pdcattr
;
131 oldMode
= pdcattr
->lBkMode
;
132 pdcattr
->jBkMode
= Mode
;
133 pdcattr
->lBkMode
= Mode
;
140 IntGdiSetTextAlign(HDC hDC
,
150 EngSetLastError(ERROR_INVALID_HANDLE
);
153 pdcattr
= dc
->pdcattr
;
154 prevAlign
= pdcattr
->lTextAlign
;
155 pdcattr
->lTextAlign
= Mode
;
162 IntGdiSetTextColor(HDC hDC
,
169 pdc
= DC_LockDc(hDC
);
172 EngSetLastError(ERROR_INVALID_HANDLE
);
175 pdcattr
= pdc
->pdcattr
;
177 crOldColor
= (COLORREF
) pdcattr
->ulForegroundClr
;
178 pdcattr
->ulForegroundClr
= (ULONG
)color
;
180 if (pdcattr
->crForegroundClr
!= color
)
182 pdcattr
->ulDirty_
|= (DIRTY_TEXT
|DIRTY_LINE
|DIRTY_FILL
);
183 pdcattr
->crForegroundClr
= color
;
186 DC_vUpdateTextBrush(pdc
);
194 IntSetDCBrushColor(HDC hdc
, COLORREF crColor
)
196 COLORREF OldColor
= CLR_INVALID
;
198 if (!(dc
= DC_LockDc(hdc
)))
200 EngSetLastError(ERROR_INVALID_HANDLE
);
205 OldColor
= (COLORREF
) dc
->pdcattr
->ulBrushClr
;
206 dc
->pdcattr
->ulBrushClr
= (ULONG
) crColor
;
208 if ( dc
->pdcattr
->crBrushClr
!= crColor
)
210 dc
->pdcattr
->ulDirty_
|= DIRTY_FILL
;
211 dc
->pdcattr
->crBrushClr
= crColor
;
219 IntSetDCPenColor(HDC hdc
, COLORREF crColor
)
223 if (!(dc
= DC_LockDc(hdc
)))
225 EngSetLastError(ERROR_INVALID_PARAMETER
);
229 OldColor
= (COLORREF
)dc
->pdcattr
->ulPenClr
;
230 dc
->pdcattr
->ulPenClr
= (ULONG
)crColor
;
232 if (dc
->pdcattr
->crPenClr
!= crColor
)
234 dc
->pdcattr
->ulDirty_
|= DIRTY_LINE
;
235 dc
->pdcattr
->crPenClr
= crColor
;
243 GreSetStretchBltMode(HDC hDC
, int iStretchMode
)
249 pdc
= DC_LockDc(hDC
);
252 pdcattr
= pdc
->pdcattr
;
253 oSMode
= pdcattr
->lStretchBltMode
;
254 pdcattr
->lStretchBltMode
= iStretchMode
;
256 // Wine returns an error here. We set the default.
257 if ((iStretchMode
<= 0) || (iStretchMode
> MAXSTRETCHBLTMODE
)) iStretchMode
= WHITEONBLACK
;
259 pdcattr
->jStretchBltMode
= iStretchMode
;
266 GreGetGraphicsMode(HDC hdc
)
270 if (!(dc
= DC_LockDc(hdc
)))
272 EngSetLastError(ERROR_INVALID_HANDLE
);
275 GraphicsMode
= dc
->pdcattr
->iGraphicsMode
;;
282 DCU_SetDcUndeletable(HDC hDC
)
284 PDC dc
= DC_LockDc(hDC
);
287 EngSetLastError(ERROR_INVALID_HANDLE
);
291 dc
->fs
|= DC_FLAG_PERMANENT
;
298 IntIsPrimarySurface(SURFOBJ
*SurfObj
)
300 if (PrimarySurface
.pSurface
== NULL
)
304 return SurfObj
->hsurf
== PrimarySurface
.pSurface
; // <- FIXME: WTF?
310 IntSetDefaultRegion(PDC pdc
)
314 RECTL rclWnd
, rclClip
;
316 IntGdiReleaseRaoRgn(pdc
);
320 rclWnd
.right
= pdc
->dclevel
.sizl
.cx
;
321 rclWnd
.bottom
= pdc
->dclevel
.sizl
.cy
;
324 //EngAcquireSemaphoreShared(pdc->ppdev->hsemDevLock);
325 if (pdc
->ppdev
->flFlags
& PDEV_META_DEVICE
)
327 pSurface
= pdc
->dclevel
.pSurface
;
328 if (pSurface
&& pSurface
->flags
& PDEV_SURFACE
)
330 rclClip
.left
+= pdc
->ppdev
->ptlOrigion
.x
;
331 rclClip
.top
+= pdc
->ppdev
->ptlOrigion
.y
;
332 rclClip
.right
+= pdc
->ppdev
->ptlOrigion
.x
;
333 rclClip
.bottom
+= pdc
->ppdev
->ptlOrigion
.y
;
336 //EngReleaseSemaphore(pdc->ppdev->hsemDevLock);
340 if (prgn
&& prgn
!= prgnDefault
)
342 REGION_SetRectRgn( prgn
,
350 prgn
= IntSysCreateRectpRgn( rclClip
.left
,
359 pdc
->ptlDCOrig
.x
= 0;
360 pdc
->ptlDCOrig
.y
= 0;
361 pdc
->erclWindow
= rclWnd
;
362 pdc
->erclClip
= rclClip
;
363 /* Might be an InitDC or DCE... */
364 pdc
->ptlFillOrigin
.x
= pdc
->dcattr
.VisRectRegion
.Rect
.right
;
365 pdc
->ptlFillOrigin
.y
= pdc
->dcattr
.VisRectRegion
.Rect
.bottom
;
369 pdc
->prgnVis
= prgnDefault
;
375 NtGdiCancelDC(HDC hDC
)
383 IntGdiSetHookFlags(HDC hDC
, WORD Flags
)
386 DC
*dc
= DC_LockDc(hDC
);
390 EngSetLastError(ERROR_INVALID_HANDLE
);
394 wRet
= dc
->fs
& DC_FLAG_DIRTY_RAO
; // FIXME: Wrong flag!
396 /* Info in "Undocumented Windows" is slightly confusing. */
397 DPRINT("DC %p, Flags %04x\n", hDC
, Flags
);
399 if (Flags
& DCHF_INVALIDATEVISRGN
)
401 /* hVisRgn has to be updated */
402 dc
->fs
|= DC_FLAG_DIRTY_RAO
;
404 else if (Flags
& DCHF_VALIDATEVISRGN
|| 0 == Flags
)
406 //dc->fs &= ~DC_FLAG_DIRTY_RAO;
426 DWORD SafeResult
= 0;
427 NTSTATUS Status
= STATUS_SUCCESS
;
431 EngSetLastError(ERROR_INVALID_PARAMETER
);
435 pdc
= DC_LockDc(hDC
);
438 EngSetLastError(ERROR_INVALID_HANDLE
);
441 pdcattr
= pdc
->pdcattr
;
449 SafeResult
= pdcattr
->lRelAbs
;
452 case GdiGetBreakExtra
:
453 SafeResult
= pdcattr
->lBreakExtra
;
456 case GdiGerCharBreak
:
457 SafeResult
= pdcattr
->cBreak
;
460 case GdiGetArcDirection
:
461 if (pdcattr
->dwLayout
& LAYOUT_RTL
)
462 SafeResult
= AD_CLOCKWISE
- ((pdc
->dclevel
.flPath
& DCPATH_CLOCKWISE
) != 0);
464 SafeResult
= ((pdc
->dclevel
.flPath
& DCPATH_CLOCKWISE
) != 0) + AD_COUNTERCLOCKWISE
;
467 case GdiGetEMFRestorDc
:
468 SafeResult
= pdc
->dclevel
.lSaveDepth
;
471 case GdiGetFontLanguageInfo
:
472 SafeResult
= IntGetFontLanguageInfo(pdc
);
476 SafeResult
= pdc
->dctype
;
480 SafeResult
= pdcattr
->iMapMode
;
483 case GdiGetTextCharExtra
:
484 SafeResult
= pdcattr
->lTextExtra
;
488 EngSetLastError(ERROR_INVALID_PARAMETER
);
497 ProbeForWrite(Result
, sizeof(DWORD
), 1);
498 *Result
= SafeResult
;
500 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
502 Status
= _SEH2_GetExceptionCode();
506 if (!NT_SUCCESS(Status
))
508 SetLastNtError(Status
);
517 _Success_(return != FALSE
)
520 NtGdiGetAndSetDCDword(
524 _Out_ DWORD
*pdwResult
)
530 DWORD SafeResult
= 0;
531 NTSTATUS Status
= STATUS_SUCCESS
;
535 EngSetLastError(ERROR_INVALID_PARAMETER
);
539 pdc
= DC_LockDc(hdc
);
542 EngSetLastError(ERROR_INVALID_HANDLE
);
545 pdcattr
= pdc
->pdcattr
;
549 case GdiGetSetCopyCount
:
550 SafeResult
= pdc
->ulCopyCount
;
551 pdc
->ulCopyCount
= dwIn
;
554 case GdiGetSetTextAlign
:
555 SafeResult
= pdcattr
->lTextAlign
;
556 pdcattr
->lTextAlign
= dwIn
;
557 // pdcattr->flTextAlign = dwIn; // Flags!
560 case GdiGetSetRelAbs
:
561 SafeResult
= pdcattr
->lRelAbs
;
562 pdcattr
->lRelAbs
= dwIn
;
565 case GdiGetSetTextCharExtra
:
566 SafeResult
= pdcattr
->lTextExtra
;
567 pdcattr
->lTextExtra
= dwIn
;
570 case GdiGetSetSelectFont
:
573 case GdiGetSetMapperFlagsInternal
:
576 EngSetLastError(ERROR_INVALID_PARAMETER
);
580 SafeResult
= pdcattr
->flFontMapper
;
581 pdcattr
->flFontMapper
= dwIn
;
584 case GdiGetSetMapMode
:
585 SafeResult
= IntGdiSetMapMode(pdc
, dwIn
);
588 case GdiGetSetArcDirection
:
589 if (dwIn
!= AD_COUNTERCLOCKWISE
&& dwIn
!= AD_CLOCKWISE
)
591 EngSetLastError(ERROR_INVALID_PARAMETER
);
595 if (pdcattr
->dwLayout
& LAYOUT_RTL
) // Right to Left
597 SafeResult
= AD_CLOCKWISE
- ((pdc
->dclevel
.flPath
& DCPATH_CLOCKWISE
) != 0);
598 if (dwIn
== AD_CLOCKWISE
)
600 pdc
->dclevel
.flPath
&= ~DCPATH_CLOCKWISE
;
603 pdc
->dclevel
.flPath
|= DCPATH_CLOCKWISE
;
605 else // Left to Right
607 SafeResult
= ((pdc
->dclevel
.flPath
& DCPATH_CLOCKWISE
) != 0) +
609 if (dwIn
== AD_COUNTERCLOCKWISE
)
611 pdc
->dclevel
.flPath
&= ~DCPATH_CLOCKWISE
;
614 pdc
->dclevel
.flPath
|= DCPATH_CLOCKWISE
;
619 EngSetLastError(ERROR_INVALID_PARAMETER
);
628 ProbeForWrite(pdwResult
, sizeof(DWORD
), 1);
629 *pdwResult
= SafeResult
;
631 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
633 Status
= _SEH2_GetExceptionCode();
637 if (!NT_SUCCESS(Status
))
639 SetLastNtError(Status
);
659 if (!(pdc
= DC_LockDc(hdc
))) return 0;
661 /* Get the return value */
662 ret
= pdc
->fs
& DC_ACCUM_APP
? DCB_ENABLE
: DCB_DISABLE
;
663 ret
|= RECTL_bIsEmptyRect(&pdc
->erclBoundsApp
) ? DCB_RESET
: DCB_SET
;
665 /* Copy the rect to the caller */
668 ProbeForWrite(prc
, sizeof(RECT
), 1);
669 *prc
= pdc
->erclBoundsApp
;
671 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
677 if (flags
& DCB_RESET
)
679 RECTL_vSetEmptyRect(&pdc
->erclBoundsApp
);
698 /* Verify arguments */
699 if ((flags
& DCB_ENABLE
) && (flags
& DCB_DISABLE
)) return 0;
702 if (!(pdc
= DC_LockDc(hdc
))) return 0;
704 /* Get the return value */
705 ret
= pdc
->fs
& DC_ACCUM_APP
? DCB_ENABLE
: DCB_DISABLE
;
706 ret
|= RECTL_bIsEmptyRect(&pdc
->erclBoundsApp
) ? DCB_RESET
: DCB_SET
;
708 if (flags
& DCB_RESET
)
710 RECTL_vSetEmptyRect(&pdc
->erclBoundsApp
);
713 if (flags
& DCB_ACCUMULATE
&& prc
!= NULL
)
715 /* Capture the rect */
718 ProbeForRead(prc
, sizeof(RECT
), 1);
721 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
724 _SEH2_YIELD(return 0;)
728 RECTL_vMakeWellOrdered(&rcl
);
729 RECTL_bUnionRect(&pdc
->erclBoundsApp
, &pdc
->erclBoundsApp
, &rcl
);
732 if (flags
& DCB_ENABLE
) pdc
->fs
|= DC_ACCUM_APP
;
733 if (flags
& DCB_DISABLE
) pdc
->fs
&= ~DC_ACCUM_APP
;
738 /* Translates a COLORREF to the right color in the specified DC color space */
740 TranslateCOLORREF(PDC pdc
, COLORREF crColor
)
744 ULONG index
, ulColor
, iBitmapFormat
;
747 /* Get the DC surface */
748 psurfDC
= pdc
->dclevel
.pSurface
;
750 /* If no surface is selected, use the default bitmap */
752 psurfDC
= psurfDefaultBitmap
;
754 /* Check what color type this is */
755 switch (crColor
>> 24)
757 case 0x00: /* RGB color */
760 case 0x01: /* PALETTEINDEX */
761 index
= crColor
& 0xFFFFFF;
762 ppalDC
= pdc
->dclevel
.ppal
;
763 if (index
>= ppalDC
->NumColors
) index
= 0;
765 /* Get the RGB value */
766 crColor
= PALETTE_ulGetRGBColorFromIndex(ppalDC
, index
);
769 case 0x02: /* PALETTERGB */
771 if (pdc
->dclevel
.hpal
!= StockObjects
[DEFAULT_PALETTE
])
773 /* First find the nearest index in the dc palette */
774 ppalDC
= pdc
->dclevel
.ppal
;
775 index
= PALETTE_ulGetNearestIndex(ppalDC
, crColor
& 0xFFFFFF);
777 /* Get the RGB value */
778 crColor
= PALETTE_ulGetRGBColorFromIndex(ppalDC
, index
);
782 /* Use the pure color */
783 crColor
= crColor
& 0x00FFFFFF;
787 case 0x10: /* DIBINDEX */
788 /* Mask the value to match the target bpp */
789 iBitmapFormat
= psurfDC
->SurfObj
.iBitmapFormat
;
790 if (iBitmapFormat
== BMF_1BPP
) index
= crColor
& 0x1;
791 else if (iBitmapFormat
== BMF_4BPP
) index
= crColor
& 0xf;
792 else if (iBitmapFormat
== BMF_8BPP
) index
= crColor
& 0xFF;
793 else if (iBitmapFormat
== BMF_16BPP
) index
= crColor
& 0xFFFF;
794 else index
= crColor
& 0xFFFFFF;
798 DPRINT("Unsupported color type %u passed\n", crColor
>> 24);
802 /* Initialize an XLATEOBJ from RGB to the target surface */
803 EXLATEOBJ_vInitialize(&exlo
, &gpalRGB
, psurfDC
->ppal
, 0xFFFFFF, 0, 0);
805 /* Translate the color to the target format */
806 ulColor
= XLATEOBJ_iXlate(&exlo
.xlo
, crColor
);
808 /* Cleanup the XLATEOBJ */
809 EXLATEOBJ_vCleanup(&exlo
);