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
;
226 IntSetDCPenColor(HDC hdc
, COLORREF crColor
)
230 if (!(dc
= DC_LockDc(hdc
)))
232 EngSetLastError(ERROR_INVALID_PARAMETER
);
236 OldColor
= (COLORREF
)dc
->pdcattr
->ulPenClr
;
237 dc
->pdcattr
->ulPenClr
= (ULONG
)crColor
;
239 if (dc
->pdcattr
->crPenClr
!= crColor
)
241 dc
->pdcattr
->ulDirty_
|= DIRTY_LINE
;
242 dc
->pdcattr
->crPenClr
= crColor
;
250 GreSetStretchBltMode(HDC hDC
, int iStretchMode
)
256 pdc
= DC_LockDc(hDC
);
259 pdcattr
= pdc
->pdcattr
;
260 oSMode
= pdcattr
->lStretchBltMode
;
261 pdcattr
->lStretchBltMode
= iStretchMode
;
263 // Wine returns an error here. We set the default.
264 if ((iStretchMode
<= 0) || (iStretchMode
> MAXSTRETCHBLTMODE
)) iStretchMode
= WHITEONBLACK
;
266 pdcattr
->jStretchBltMode
= iStretchMode
;
273 GreGetGraphicsMode(HDC hdc
)
277 if (!(dc
= DC_LockDc(hdc
)))
279 EngSetLastError(ERROR_INVALID_HANDLE
);
282 GraphicsMode
= dc
->pdcattr
->iGraphicsMode
;
289 DCU_SetDcUndeletable(HDC hDC
)
291 PDC dc
= DC_LockDc(hDC
);
294 EngSetLastError(ERROR_INVALID_HANDLE
);
298 dc
->fs
|= DC_FLAG_PERMANENT
;
305 IntIsPrimarySurface(SURFOBJ
*SurfObj
)
307 if (PrimarySurface
.pSurface
== NULL
)
311 return SurfObj
->hsurf
== PrimarySurface
.pSurface
; // <- FIXME: WTF?
317 IntSetDefaultRegion(PDC pdc
)
321 RECTL rclWnd
, rclClip
;
323 IntGdiReleaseRaoRgn(pdc
);
327 rclWnd
.right
= pdc
->dclevel
.sizl
.cx
;
328 rclWnd
.bottom
= pdc
->dclevel
.sizl
.cy
;
331 //EngAcquireSemaphoreShared(pdc->ppdev->hsemDevLock);
332 if (pdc
->ppdev
->flFlags
& PDEV_META_DEVICE
)
334 pSurface
= pdc
->dclevel
.pSurface
;
335 if (pSurface
&& pSurface
->flags
& PDEV_SURFACE
)
337 rclClip
.left
+= pdc
->ppdev
->ptlOrigion
.x
;
338 rclClip
.top
+= pdc
->ppdev
->ptlOrigion
.y
;
339 rclClip
.right
+= pdc
->ppdev
->ptlOrigion
.x
;
340 rclClip
.bottom
+= pdc
->ppdev
->ptlOrigion
.y
;
343 //EngReleaseSemaphore(pdc->ppdev->hsemDevLock);
347 if (prgn
&& prgn
!= prgnDefault
)
349 REGION_SetRectRgn( prgn
,
357 prgn
= IntSysCreateRectpRgn( rclClip
.left
,
366 pdc
->ptlDCOrig
.x
= 0;
367 pdc
->ptlDCOrig
.y
= 0;
368 pdc
->erclWindow
= rclWnd
;
369 pdc
->erclClip
= rclClip
;
370 /* Might be an InitDC or DCE... */
371 pdc
->ptlFillOrigin
.x
= pdc
->dcattr
.VisRectRegion
.Rect
.right
;
372 pdc
->ptlFillOrigin
.y
= pdc
->dcattr
.VisRectRegion
.Rect
.bottom
;
376 pdc
->prgnVis
= prgnDefault
;
382 NtGdiCancelDC(HDC hDC
)
390 IntGdiSetHookFlags(HDC hDC
, WORD Flags
)
393 DC
*dc
= DC_LockDc(hDC
);
397 EngSetLastError(ERROR_INVALID_HANDLE
);
401 wRet
= dc
->fs
& DC_FLAG_DIRTY_RAO
; // FIXME: Wrong flag!
403 /* Info in "Undocumented Windows" is slightly confusing. */
404 DPRINT("DC %p, Flags %04x\n", hDC
, Flags
);
406 if (Flags
& DCHF_INVALIDATEVISRGN
)
408 /* hVisRgn has to be updated */
409 dc
->fs
|= DC_FLAG_DIRTY_RAO
;
411 else if (Flags
& DCHF_VALIDATEVISRGN
|| 0 == Flags
)
413 //dc->fs &= ~DC_FLAG_DIRTY_RAO;
433 DWORD SafeResult
= 0;
434 NTSTATUS Status
= STATUS_SUCCESS
;
438 EngSetLastError(ERROR_INVALID_PARAMETER
);
442 pdc
= DC_LockDc(hDC
);
445 EngSetLastError(ERROR_INVALID_HANDLE
);
448 pdcattr
= pdc
->pdcattr
;
456 SafeResult
= pdcattr
->lRelAbs
;
459 case GdiGetBreakExtra
:
460 SafeResult
= pdcattr
->lBreakExtra
;
463 case GdiGerCharBreak
:
464 SafeResult
= pdcattr
->cBreak
;
467 case GdiGetArcDirection
:
468 if (pdcattr
->dwLayout
& LAYOUT_RTL
)
469 SafeResult
= AD_CLOCKWISE
- ((pdc
->dclevel
.flPath
& DCPATH_CLOCKWISE
) != 0);
471 SafeResult
= ((pdc
->dclevel
.flPath
& DCPATH_CLOCKWISE
) != 0) + AD_COUNTERCLOCKWISE
;
474 case GdiGetEMFRestorDc
:
475 SafeResult
= pdc
->dclevel
.lSaveDepth
;
478 case GdiGetFontLanguageInfo
:
479 SafeResult
= IntGetFontLanguageInfo(pdc
);
483 SafeResult
= pdc
->dctype
;
487 SafeResult
= pdcattr
->iMapMode
;
490 case GdiGetTextCharExtra
:
491 SafeResult
= pdcattr
->lTextExtra
;
495 EngSetLastError(ERROR_INVALID_PARAMETER
);
504 ProbeForWrite(Result
, sizeof(DWORD
), 1);
505 *Result
= SafeResult
;
507 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
509 Status
= _SEH2_GetExceptionCode();
513 if (!NT_SUCCESS(Status
))
515 SetLastNtError(Status
);
524 _Success_(return != FALSE
)
527 NtGdiGetAndSetDCDword(
531 _Out_ DWORD
*pdwResult
)
537 DWORD SafeResult
= 0;
538 NTSTATUS Status
= STATUS_SUCCESS
;
542 EngSetLastError(ERROR_INVALID_PARAMETER
);
546 pdc
= DC_LockDc(hdc
);
549 EngSetLastError(ERROR_INVALID_HANDLE
);
552 pdcattr
= pdc
->pdcattr
;
556 case GdiGetSetCopyCount
:
557 SafeResult
= pdc
->ulCopyCount
;
558 pdc
->ulCopyCount
= dwIn
;
561 case GdiGetSetTextAlign
:
562 SafeResult
= pdcattr
->lTextAlign
;
563 pdcattr
->lTextAlign
= dwIn
;
564 // pdcattr->flTextAlign = dwIn; // Flags!
567 case GdiGetSetRelAbs
:
568 SafeResult
= pdcattr
->lRelAbs
;
569 pdcattr
->lRelAbs
= dwIn
;
572 case GdiGetSetTextCharExtra
:
573 SafeResult
= pdcattr
->lTextExtra
;
574 pdcattr
->lTextExtra
= dwIn
;
577 case GdiGetSetSelectFont
:
580 case GdiGetSetMapperFlagsInternal
:
583 EngSetLastError(ERROR_INVALID_PARAMETER
);
587 SafeResult
= pdcattr
->flFontMapper
;
588 pdcattr
->flFontMapper
= dwIn
;
591 case GdiGetSetMapMode
:
592 SafeResult
= IntGdiSetMapMode(pdc
, dwIn
);
595 case GdiGetSetArcDirection
:
596 if (dwIn
!= AD_COUNTERCLOCKWISE
&& dwIn
!= AD_CLOCKWISE
)
598 EngSetLastError(ERROR_INVALID_PARAMETER
);
602 if (pdcattr
->dwLayout
& LAYOUT_RTL
) // Right to Left
604 SafeResult
= AD_CLOCKWISE
- ((pdc
->dclevel
.flPath
& DCPATH_CLOCKWISE
) != 0);
605 if (dwIn
== AD_CLOCKWISE
)
607 pdc
->dclevel
.flPath
&= ~DCPATH_CLOCKWISE
;
610 pdc
->dclevel
.flPath
|= DCPATH_CLOCKWISE
;
612 else // Left to Right
614 SafeResult
= ((pdc
->dclevel
.flPath
& DCPATH_CLOCKWISE
) != 0) +
616 if (dwIn
== AD_COUNTERCLOCKWISE
)
618 pdc
->dclevel
.flPath
&= ~DCPATH_CLOCKWISE
;
621 pdc
->dclevel
.flPath
|= DCPATH_CLOCKWISE
;
626 EngSetLastError(ERROR_INVALID_PARAMETER
);
635 ProbeForWrite(pdwResult
, sizeof(DWORD
), 1);
636 *pdwResult
= SafeResult
;
638 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
640 Status
= _SEH2_GetExceptionCode();
644 if (!NT_SUCCESS(Status
))
646 SetLastNtError(Status
);
666 if (!(pdc
= DC_LockDc(hdc
))) return 0;
668 /* Get the return value */
669 ret
= pdc
->fs
& DC_ACCUM_APP
? DCB_ENABLE
: DCB_DISABLE
;
670 ret
|= RECTL_bIsEmptyRect(&pdc
->erclBoundsApp
) ? DCB_RESET
: DCB_SET
;
672 /* Copy the rect to the caller */
675 ProbeForWrite(prc
, sizeof(RECT
), 1);
676 *prc
= pdc
->erclBoundsApp
;
678 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
684 if (flags
& DCB_RESET
)
686 RECTL_vSetEmptyRect(&pdc
->erclBoundsApp
);
705 /* Verify arguments */
706 if ((flags
& DCB_ENABLE
) && (flags
& DCB_DISABLE
)) return 0;
709 if (!(pdc
= DC_LockDc(hdc
))) return 0;
711 /* Get the return value */
712 ret
= pdc
->fs
& DC_ACCUM_APP
? DCB_ENABLE
: DCB_DISABLE
;
713 ret
|= RECTL_bIsEmptyRect(&pdc
->erclBoundsApp
) ? DCB_RESET
: DCB_SET
;
715 if (flags
& DCB_RESET
)
717 RECTL_vSetEmptyRect(&pdc
->erclBoundsApp
);
720 if (flags
& DCB_ACCUMULATE
&& prc
!= NULL
)
722 /* Capture the rect */
725 ProbeForRead(prc
, sizeof(RECT
), 1);
728 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
731 _SEH2_YIELD(return 0;)
735 RECTL_vMakeWellOrdered(&rcl
);
736 RECTL_bUnionRect(&pdc
->erclBoundsApp
, &pdc
->erclBoundsApp
, &rcl
);
739 if (flags
& DCB_ENABLE
) pdc
->fs
|= DC_ACCUM_APP
;
740 if (flags
& DCB_DISABLE
) pdc
->fs
&= ~DC_ACCUM_APP
;
745 /* Translates a COLORREF to the right color in the specified DC color space */
747 TranslateCOLORREF(PDC pdc
, COLORREF crColor
)
751 ULONG index
, ulColor
, iBitmapFormat
;
754 /* Get the DC surface */
755 psurfDC
= pdc
->dclevel
.pSurface
;
757 /* If no surface is selected, use the default bitmap */
759 psurfDC
= psurfDefaultBitmap
;
761 /* Check what color type this is */
762 switch (crColor
>> 24)
764 case 0x00: /* RGB color */
767 case 0x01: /* PALETTEINDEX */
768 index
= crColor
& 0xFFFFFF;
769 ppalDC
= pdc
->dclevel
.ppal
;
770 if (index
>= ppalDC
->NumColors
) index
= 0;
772 /* Get the RGB value */
773 crColor
= PALETTE_ulGetRGBColorFromIndex(ppalDC
, index
);
776 case 0x02: /* PALETTERGB */
778 if (pdc
->dclevel
.hpal
!= StockObjects
[DEFAULT_PALETTE
])
780 /* First find the nearest index in the dc palette */
781 ppalDC
= pdc
->dclevel
.ppal
;
782 index
= PALETTE_ulGetNearestIndex(ppalDC
, crColor
& 0xFFFFFF);
784 /* Get the RGB value */
785 crColor
= PALETTE_ulGetRGBColorFromIndex(ppalDC
, index
);
789 /* Use the pure color */
790 crColor
= crColor
& 0x00FFFFFF;
794 case 0x10: /* DIBINDEX */
795 /* Mask the value to match the target bpp */
796 iBitmapFormat
= psurfDC
->SurfObj
.iBitmapFormat
;
797 if (iBitmapFormat
== BMF_1BPP
) index
= crColor
& 0x1;
798 else if (iBitmapFormat
== BMF_4BPP
) index
= crColor
& 0xf;
799 else if (iBitmapFormat
== BMF_8BPP
) index
= crColor
& 0xFF;
800 else if (iBitmapFormat
== BMF_16BPP
) index
= crColor
& 0xFFFF;
801 else index
= crColor
& 0xFFFFFF;
805 DPRINT("Unsupported color type %u passed\n", crColor
>> 24);
809 /* Initialize an XLATEOBJ from RGB to the target surface */
810 EXLATEOBJ_vInitialize(&exlo
, &gpalRGB
, psurfDC
->ppal
, 0xFFFFFF, 0, 0);
812 /* Translate the color to the target format */
813 ulColor
= XLATEOBJ_iXlate(&exlo
.xlo
, crColor
);
815 /* Cleanup the XLATEOBJ */
816 EXLATEOBJ_vCleanup(&exlo
);