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 DC_vSetBrushOrigin(pdc
, x
, y
);
251 IntSetDCPenColor(HDC hdc
, COLORREF crColor
)
255 if (!(dc
= DC_LockDc(hdc
)))
257 EngSetLastError(ERROR_INVALID_PARAMETER
);
261 OldColor
= (COLORREF
)dc
->pdcattr
->ulPenClr
;
262 dc
->pdcattr
->ulPenClr
= (ULONG
)crColor
;
264 if (dc
->pdcattr
->crPenClr
!= crColor
)
266 dc
->pdcattr
->ulDirty_
|= DIRTY_LINE
;
267 dc
->pdcattr
->crPenClr
= crColor
;
275 GreSetStretchBltMode(HDC hDC
, int iStretchMode
)
281 pdc
= DC_LockDc(hDC
);
284 pdcattr
= pdc
->pdcattr
;
285 oSMode
= pdcattr
->lStretchBltMode
;
286 pdcattr
->lStretchBltMode
= iStretchMode
;
288 // Wine returns an error here. We set the default.
289 if ((iStretchMode
<= 0) || (iStretchMode
> MAXSTRETCHBLTMODE
)) iStretchMode
= WHITEONBLACK
;
291 pdcattr
->jStretchBltMode
= iStretchMode
;
298 GreGetGraphicsMode(HDC hdc
)
302 if (!(dc
= DC_LockDc(hdc
)))
304 EngSetLastError(ERROR_INVALID_HANDLE
);
307 GraphicsMode
= dc
->pdcattr
->iGraphicsMode
;
314 DCU_SetDcUndeletable(HDC hDC
)
316 PDC dc
= DC_LockDc(hDC
);
319 EngSetLastError(ERROR_INVALID_HANDLE
);
323 dc
->fs
|= DC_FLAG_PERMANENT
;
330 IntIsPrimarySurface(SURFOBJ
*SurfObj
)
332 if (PrimarySurface
.pSurface
== NULL
)
336 return SurfObj
->hsurf
== PrimarySurface
.pSurface
; // <- FIXME: WTF?
342 IntSetDefaultRegion(PDC pdc
)
346 RECTL rclWnd
, rclClip
;
348 IntGdiReleaseRaoRgn(pdc
);
352 rclWnd
.right
= pdc
->dclevel
.sizl
.cx
;
353 rclWnd
.bottom
= pdc
->dclevel
.sizl
.cy
;
356 //EngAcquireSemaphoreShared(pdc->ppdev->hsemDevLock);
357 if (pdc
->ppdev
->flFlags
& PDEV_META_DEVICE
)
359 pSurface
= pdc
->dclevel
.pSurface
;
360 if (pSurface
&& pSurface
->flags
& PDEV_SURFACE
)
362 rclClip
.left
+= pdc
->ppdev
->ptlOrigion
.x
;
363 rclClip
.top
+= pdc
->ppdev
->ptlOrigion
.y
;
364 rclClip
.right
+= pdc
->ppdev
->ptlOrigion
.x
;
365 rclClip
.bottom
+= pdc
->ppdev
->ptlOrigion
.y
;
368 //EngReleaseSemaphore(pdc->ppdev->hsemDevLock);
372 if (prgn
&& prgn
!= prgnDefault
)
374 REGION_SetRectRgn( prgn
,
382 prgn
= IntSysCreateRectpRgn( rclClip
.left
,
391 pdc
->ptlDCOrig
.x
= 0;
392 pdc
->ptlDCOrig
.y
= 0;
393 pdc
->erclWindow
= rclWnd
;
394 pdc
->erclClip
= rclClip
;
395 /* Might be an InitDC or DCE... */
396 pdc
->ptlFillOrigin
.x
= pdc
->dcattr
.VisRectRegion
.Rect
.right
;
397 pdc
->ptlFillOrigin
.y
= pdc
->dcattr
.VisRectRegion
.Rect
.bottom
;
401 pdc
->prgnVis
= prgnDefault
;
407 NtGdiCancelDC(HDC hDC
)
415 IntGdiSetHookFlags(HDC hDC
, WORD Flags
)
418 DC
*dc
= DC_LockDc(hDC
);
422 EngSetLastError(ERROR_INVALID_HANDLE
);
426 wRet
= dc
->fs
& DC_FLAG_DIRTY_RAO
; // FIXME: Wrong flag!
428 /* Info in "Undocumented Windows" is slightly confusing. */
429 DPRINT("DC %p, Flags %04x\n", hDC
, Flags
);
431 if (Flags
& DCHF_INVALIDATEVISRGN
)
433 /* hVisRgn has to be updated */
434 dc
->fs
|= DC_FLAG_DIRTY_RAO
;
436 else if (Flags
& DCHF_VALIDATEVISRGN
|| 0 == Flags
)
438 //dc->fs &= ~DC_FLAG_DIRTY_RAO;
458 DWORD SafeResult
= 0;
459 NTSTATUS Status
= STATUS_SUCCESS
;
463 EngSetLastError(ERROR_INVALID_PARAMETER
);
467 pdc
= DC_LockDc(hDC
);
470 EngSetLastError(ERROR_INVALID_HANDLE
);
473 pdcattr
= pdc
->pdcattr
;
481 SafeResult
= pdcattr
->lRelAbs
;
484 case GdiGetBreakExtra
:
485 SafeResult
= pdcattr
->lBreakExtra
;
488 case GdiGerCharBreak
:
489 SafeResult
= pdcattr
->cBreak
;
492 case GdiGetArcDirection
:
493 if (pdcattr
->dwLayout
& LAYOUT_RTL
)
494 SafeResult
= AD_CLOCKWISE
- ((pdc
->dclevel
.flPath
& DCPATH_CLOCKWISE
) != 0);
496 SafeResult
= ((pdc
->dclevel
.flPath
& DCPATH_CLOCKWISE
) != 0) + AD_COUNTERCLOCKWISE
;
499 case GdiGetEMFRestorDc
:
500 SafeResult
= pdc
->dclevel
.lSaveDepth
;
503 case GdiGetFontLanguageInfo
:
504 SafeResult
= IntGetFontLanguageInfo(pdc
);
508 SafeResult
= pdc
->dctype
;
512 SafeResult
= pdcattr
->iMapMode
;
515 case GdiGetTextCharExtra
:
516 SafeResult
= pdcattr
->lTextExtra
;
520 EngSetLastError(ERROR_INVALID_PARAMETER
);
529 ProbeForWrite(Result
, sizeof(DWORD
), 1);
530 *Result
= SafeResult
;
532 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
534 Status
= _SEH2_GetExceptionCode();
538 if (!NT_SUCCESS(Status
))
540 SetLastNtError(Status
);
549 _Success_(return != FALSE
)
552 NtGdiGetAndSetDCDword(
556 _Out_ DWORD
*pdwResult
)
562 DWORD SafeResult
= 0;
563 NTSTATUS Status
= STATUS_SUCCESS
;
567 EngSetLastError(ERROR_INVALID_PARAMETER
);
571 pdc
= DC_LockDc(hdc
);
574 EngSetLastError(ERROR_INVALID_HANDLE
);
577 pdcattr
= pdc
->pdcattr
;
581 case GdiGetSetCopyCount
:
582 SafeResult
= pdc
->ulCopyCount
;
583 pdc
->ulCopyCount
= dwIn
;
586 case GdiGetSetTextAlign
:
587 SafeResult
= pdcattr
->lTextAlign
;
588 pdcattr
->lTextAlign
= dwIn
;
589 // pdcattr->flTextAlign = dwIn; // Flags!
592 case GdiGetSetRelAbs
:
593 SafeResult
= pdcattr
->lRelAbs
;
594 pdcattr
->lRelAbs
= dwIn
;
597 case GdiGetSetTextCharExtra
:
598 SafeResult
= pdcattr
->lTextExtra
;
599 pdcattr
->lTextExtra
= dwIn
;
602 case GdiGetSetSelectFont
:
605 case GdiGetSetMapperFlagsInternal
:
608 EngSetLastError(ERROR_INVALID_PARAMETER
);
612 SafeResult
= pdcattr
->flFontMapper
;
613 pdcattr
->flFontMapper
= dwIn
;
616 case GdiGetSetMapMode
:
617 SafeResult
= IntGdiSetMapMode(pdc
, dwIn
);
620 case GdiGetSetArcDirection
:
621 if (dwIn
!= AD_COUNTERCLOCKWISE
&& dwIn
!= AD_CLOCKWISE
)
623 EngSetLastError(ERROR_INVALID_PARAMETER
);
627 if (pdcattr
->dwLayout
& LAYOUT_RTL
) // Right to Left
629 SafeResult
= AD_CLOCKWISE
- ((pdc
->dclevel
.flPath
& DCPATH_CLOCKWISE
) != 0);
630 if (dwIn
== AD_CLOCKWISE
)
632 pdc
->dclevel
.flPath
&= ~DCPATH_CLOCKWISE
;
635 pdc
->dclevel
.flPath
|= DCPATH_CLOCKWISE
;
637 else // Left to Right
639 SafeResult
= ((pdc
->dclevel
.flPath
& DCPATH_CLOCKWISE
) != 0) +
641 if (dwIn
== AD_COUNTERCLOCKWISE
)
643 pdc
->dclevel
.flPath
&= ~DCPATH_CLOCKWISE
;
646 pdc
->dclevel
.flPath
|= DCPATH_CLOCKWISE
;
651 EngSetLastError(ERROR_INVALID_PARAMETER
);
660 ProbeForWrite(pdwResult
, sizeof(DWORD
), 1);
661 *pdwResult
= SafeResult
;
663 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
665 Status
= _SEH2_GetExceptionCode();
669 if (!NT_SUCCESS(Status
))
671 SetLastNtError(Status
);
682 IntUpdateBoundsRect(PDC pdc
, PRECTL pRect
)
684 if (pdc
->fs
& DC_ACCUM_APP
)
686 RECTL_bUnionRect(&pdc
->erclBoundsApp
, &pdc
->erclBoundsApp
, pRect
);
688 if (pdc
->fs
& DC_ACCUM_WMGR
)
690 RECTL_bUnionRect(&pdc
->erclBounds
, &pdc
->erclBounds
, pRect
);
706 if (!(pdc
= DC_LockDc(hdc
))) return 0;
708 if (!(flags
& DCB_WINDOWMGR
))
710 rc
= pdc
->erclBoundsApp
;
712 if (RECTL_bIsEmptyRect(&rc
))
714 rc
.left
= rc
.top
= rc
.right
= rc
.bottom
= 0;
720 if (pdc
->fs
& DC_FLAG_DIRTY_RAO
) CLIPPING_UpdateGCRegion(pdc
);
721 if(!REGION_GetRgnBox(pdc
->prgnRao
, &rcRgn
))
723 REGION_GetRgnBox(pdc
->prgnVis
, &rcRgn
);
725 rc
.left
= max( rc
.left
, 0 );
726 rc
.top
= max( rc
.top
, 0 );
727 rc
.right
= min( rc
.right
, rcRgn
.right
- rcRgn
.left
);
728 rc
.bottom
= min( rc
.bottom
, rcRgn
.bottom
- rcRgn
.top
);
729 DPRINT("Rao dc %p r %d b %d\n",pdc
,rcRgn
.right
- rcRgn
.left
, rcRgn
.bottom
- rcRgn
.top
);
730 DPRINT("rc l %d t %d\n",rc
.left
,rc
.top
);
731 DPRINT(" r %d b %d\n",rc
.right
,rc
.bottom
);
734 IntDPtoLP( pdc
, &rc
, 2 );
735 DPRINT("rc1 l %d t %d\n",rc
.left
,rc
.top
);
736 DPRINT(" r %d b %d\n",rc
.right
,rc
.bottom
);
739 rc
= pdc
->erclBounds
;
741 /* Copy the rect to the caller */
744 ProbeForWrite(prc
, sizeof(RECT
), 1);
747 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
753 if (flags
& DCB_RESET
)
755 if (!(flags
& DCB_WINDOWMGR
))
757 pdc
->erclBoundsApp
.left
= pdc
->erclBoundsApp
.top
= INT_MAX
;
758 pdc
->erclBoundsApp
.right
= pdc
->erclBoundsApp
.bottom
= INT_MIN
;
762 pdc
->erclBounds
.left
= pdc
->erclBounds
.top
= INT_MAX
;
763 pdc
->erclBounds
.right
= pdc
->erclBounds
.bottom
= INT_MIN
;
782 /* Verify arguments */
783 if ((flags
& DCB_ENABLE
) && (flags
& DCB_DISABLE
)) return 0;
786 if (!(pdc
= DC_LockDc(hdc
))) return 0;
788 /* Get the return value */
789 ret
= DCB_RESET
; /* we don't have device-specific bounds */
790 ret
= (pdc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
) ? DCB_ENABLE
: DCB_DISABLE
) |
791 (RECTL_bIsEmptyRect(&pdc
->erclBoundsApp
) ? ret
& DCB_SET
: DCB_SET
);
792 ret
|= (flags
& DCB_WINDOWMGR
);
794 if (flags
& DCB_RESET
)
796 if (!(flags
& DCB_WINDOWMGR
))
798 pdc
->erclBoundsApp
.left
= pdc
->erclBoundsApp
.top
= INT_MAX
;
799 pdc
->erclBoundsApp
.right
= pdc
->erclBoundsApp
.bottom
= INT_MIN
;
803 pdc
->erclBounds
.left
= pdc
->erclBounds
.top
= INT_MAX
;
804 pdc
->erclBounds
.right
= pdc
->erclBounds
.bottom
= INT_MIN
;
808 if (flags
& DCB_ACCUMULATE
&& prc
!= NULL
)
810 /* Capture the rect */
813 ProbeForRead(prc
, sizeof(RECT
), 1);
816 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
819 _SEH2_YIELD(return 0;)
823 RECTL_vMakeWellOrdered(&rcl
);
825 if (!(flags
& DCB_WINDOWMGR
))
827 IntLPtoDP( pdc
, (POINT
*)&rcl
, 2 );
828 RECTL_bUnionRect(&pdc
->erclBoundsApp
, &pdc
->erclBoundsApp
, &rcl
);
831 RECTL_bUnionRect(&pdc
->erclBounds
, &pdc
->erclBounds
, &rcl
);
834 if (flags
& DCB_ENABLE
)
836 if (!(flags
& DCB_WINDOWMGR
))
837 pdc
->fs
|= DC_ACCUM_APP
;
839 pdc
->fs
|= DC_ACCUM_WMGR
;
841 if (flags
& DCB_DISABLE
)
843 if (!(flags
& DCB_WINDOWMGR
))
844 pdc
->fs
&= ~DC_ACCUM_APP
;
846 pdc
->fs
&= ~DC_ACCUM_WMGR
;
852 /* Translates a COLORREF to the right color in the specified DC color space */
854 TranslateCOLORREF(PDC pdc
, COLORREF crColor
)
858 ULONG index
, ulColor
, iBitmapFormat
;
861 /* Get the DC surface */
862 psurfDC
= pdc
->dclevel
.pSurface
;
864 /* If no surface is selected, use the default bitmap */
866 psurfDC
= psurfDefaultBitmap
;
868 /* Check what color type this is */
869 switch (crColor
>> 24)
871 case 0x00: /* RGB color */
874 case 0x01: /* PALETTEINDEX */
875 index
= crColor
& 0xFFFFFF;
876 ppalDC
= pdc
->dclevel
.ppal
;
877 if (index
>= ppalDC
->NumColors
) index
= 0;
879 /* Get the RGB value */
880 crColor
= PALETTE_ulGetRGBColorFromIndex(ppalDC
, index
);
883 case 0x02: /* PALETTERGB */
885 if (pdc
->dclevel
.hpal
!= StockObjects
[DEFAULT_PALETTE
])
887 /* First find the nearest index in the dc palette */
888 ppalDC
= pdc
->dclevel
.ppal
;
889 index
= PALETTE_ulGetNearestIndex(ppalDC
, crColor
& 0xFFFFFF);
891 /* Get the RGB value */
892 crColor
= PALETTE_ulGetRGBColorFromIndex(ppalDC
, index
);
896 /* Use the pure color */
897 crColor
= crColor
& 0x00FFFFFF;
901 case 0x10: /* DIBINDEX */
902 /* Mask the value to match the target bpp */
903 iBitmapFormat
= psurfDC
->SurfObj
.iBitmapFormat
;
904 if (iBitmapFormat
== BMF_1BPP
) index
= crColor
& 0x1;
905 else if (iBitmapFormat
== BMF_4BPP
) index
= crColor
& 0xf;
906 else if (iBitmapFormat
== BMF_8BPP
) index
= crColor
& 0xFF;
907 else if (iBitmapFormat
== BMF_16BPP
) index
= crColor
& 0xFFFF;
908 else index
= crColor
& 0xFFFFFF;
912 DPRINT("Unsupported color type %u passed\n", crColor
>> 24);
916 /* Initialize an XLATEOBJ from RGB to the target surface */
917 EXLATEOBJ_vInitialize(&exlo
, &gpalRGB
, psurfDC
->ppal
, 0xFFFFFF, 0, 0);
919 /* Translate the color to the target format */
920 ulColor
= XLATEOBJ_iXlate(&exlo
.xlo
, crColor
);
922 /* Cleanup the XLATEOBJ */
923 EXLATEOBJ_vCleanup(&exlo
);