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
);
657 IntUpdateBoundsRect(PDC pdc
, PRECTL pRect
)
659 if (pdc
->fs
& DC_ACCUM_APP
)
661 RECTL_bUnionRect(&pdc
->erclBoundsApp
, &pdc
->erclBoundsApp
, pRect
);
663 if (pdc
->fs
& DC_ACCUM_WMGR
)
665 RECTL_bUnionRect(&pdc
->erclBounds
, &pdc
->erclBounds
, pRect
);
681 if (!(pdc
= DC_LockDc(hdc
))) return 0;
683 if (!(flags
& DCB_WINDOWMGR
))
685 rc
= pdc
->erclBoundsApp
;
687 if (RECTL_bIsEmptyRect(&rc
))
689 rc
.left
= rc
.top
= rc
.right
= rc
.bottom
= 0;
695 if (pdc
->fs
& DC_FLAG_DIRTY_RAO
) CLIPPING_UpdateGCRegion(pdc
);
696 if(!REGION_GetRgnBox(pdc
->prgnRao
, &rcRgn
))
698 REGION_GetRgnBox(pdc
->prgnVis
, &rcRgn
);
700 rc
.left
= max( rc
.left
, 0 );
701 rc
.top
= max( rc
.top
, 0 );
702 rc
.right
= min( rc
.right
, rcRgn
.right
- rcRgn
.left
);
703 rc
.bottom
= min( rc
.bottom
, rcRgn
.bottom
- rcRgn
.top
);
704 DPRINT("Rao dc %p r %d b %d\n",pdc
,rcRgn
.right
- rcRgn
.left
, rcRgn
.bottom
- rcRgn
.top
);
705 DPRINT("rc l %d t %d\n",rc
.left
,rc
.top
);
706 DPRINT(" r %d b %d\n",rc
.right
,rc
.bottom
);
709 IntDPtoLP( pdc
, &rc
, 2 );
710 DPRINT("rc1 l %d t %d\n",rc
.left
,rc
.top
);
711 DPRINT(" r %d b %d\n",rc
.right
,rc
.bottom
);
714 rc
= pdc
->erclBounds
;
716 /* Copy the rect to the caller */
719 ProbeForWrite(prc
, sizeof(RECT
), 1);
722 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
728 if (flags
& DCB_RESET
)
730 if (!(flags
& DCB_WINDOWMGR
))
732 pdc
->erclBoundsApp
.left
= pdc
->erclBoundsApp
.top
= INT_MAX
;
733 pdc
->erclBoundsApp
.right
= pdc
->erclBoundsApp
.bottom
= INT_MIN
;
737 pdc
->erclBounds
.left
= pdc
->erclBounds
.top
= INT_MAX
;
738 pdc
->erclBounds
.right
= pdc
->erclBounds
.bottom
= INT_MIN
;
757 /* Verify arguments */
758 if ((flags
& DCB_ENABLE
) && (flags
& DCB_DISABLE
)) return 0;
761 if (!(pdc
= DC_LockDc(hdc
))) return 0;
763 /* Get the return value */
764 ret
= DCB_RESET
; /* we don't have device-specific bounds */
765 ret
= (pdc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
) ? DCB_ENABLE
: DCB_DISABLE
) |
766 (RECTL_bIsEmptyRect(&pdc
->erclBoundsApp
) ? ret
& DCB_SET
: DCB_SET
);
767 ret
|= (flags
& DCB_WINDOWMGR
);
769 if (flags
& DCB_RESET
)
771 if (!(flags
& DCB_WINDOWMGR
))
773 pdc
->erclBoundsApp
.left
= pdc
->erclBoundsApp
.top
= INT_MAX
;
774 pdc
->erclBoundsApp
.right
= pdc
->erclBoundsApp
.bottom
= INT_MIN
;
778 pdc
->erclBounds
.left
= pdc
->erclBounds
.top
= INT_MAX
;
779 pdc
->erclBounds
.right
= pdc
->erclBounds
.bottom
= INT_MIN
;
783 if (flags
& DCB_ACCUMULATE
&& prc
!= NULL
)
785 /* Capture the rect */
788 ProbeForRead(prc
, sizeof(RECT
), 1);
791 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
794 _SEH2_YIELD(return 0;)
798 RECTL_vMakeWellOrdered(&rcl
);
800 if (!(flags
& DCB_WINDOWMGR
))
802 IntLPtoDP( pdc
, (POINT
*)&rcl
, 2 );
803 RECTL_bUnionRect(&pdc
->erclBoundsApp
, &pdc
->erclBoundsApp
, &rcl
);
806 RECTL_bUnionRect(&pdc
->erclBounds
, &pdc
->erclBounds
, &rcl
);
809 if (flags
& DCB_ENABLE
)
811 if (!(flags
& DCB_WINDOWMGR
))
812 pdc
->fs
|= DC_ACCUM_APP
;
814 pdc
->fs
|= DC_ACCUM_WMGR
;
816 if (flags
& DCB_DISABLE
)
818 if (!(flags
& DCB_WINDOWMGR
))
819 pdc
->fs
&= ~DC_ACCUM_APP
;
821 pdc
->fs
&= ~DC_ACCUM_WMGR
;
827 /* Translates a COLORREF to the right color in the specified DC color space */
829 TranslateCOLORREF(PDC pdc
, COLORREF crColor
)
833 ULONG index
, ulColor
, iBitmapFormat
;
836 /* Get the DC surface */
837 psurfDC
= pdc
->dclevel
.pSurface
;
839 /* If no surface is selected, use the default bitmap */
841 psurfDC
= psurfDefaultBitmap
;
843 /* Check what color type this is */
844 switch (crColor
>> 24)
846 case 0x00: /* RGB color */
849 case 0x01: /* PALETTEINDEX */
850 index
= crColor
& 0xFFFFFF;
851 ppalDC
= pdc
->dclevel
.ppal
;
852 if (index
>= ppalDC
->NumColors
) index
= 0;
854 /* Get the RGB value */
855 crColor
= PALETTE_ulGetRGBColorFromIndex(ppalDC
, index
);
858 case 0x02: /* PALETTERGB */
860 if (pdc
->dclevel
.hpal
!= StockObjects
[DEFAULT_PALETTE
])
862 /* First find the nearest index in the dc palette */
863 ppalDC
= pdc
->dclevel
.ppal
;
864 index
= PALETTE_ulGetNearestIndex(ppalDC
, crColor
& 0xFFFFFF);
866 /* Get the RGB value */
867 crColor
= PALETTE_ulGetRGBColorFromIndex(ppalDC
, index
);
871 /* Use the pure color */
872 crColor
= crColor
& 0x00FFFFFF;
876 case 0x10: /* DIBINDEX */
877 /* Mask the value to match the target bpp */
878 iBitmapFormat
= psurfDC
->SurfObj
.iBitmapFormat
;
879 if (iBitmapFormat
== BMF_1BPP
) index
= crColor
& 0x1;
880 else if (iBitmapFormat
== BMF_4BPP
) index
= crColor
& 0xf;
881 else if (iBitmapFormat
== BMF_8BPP
) index
= crColor
& 0xFF;
882 else if (iBitmapFormat
== BMF_16BPP
) index
= crColor
& 0xFFFF;
883 else index
= crColor
& 0xFFFFFF;
887 DPRINT("Unsupported color type %u passed\n", crColor
>> 24);
891 /* Initialize an XLATEOBJ from RGB to the target surface */
892 EXLATEOBJ_vInitialize(&exlo
, &gpalRGB
, psurfDC
->ppal
, 0xFFFFFF, 0, 0);
894 /* Translate the color to the target format */
895 ulColor
= XLATEOBJ_iXlate(&exlo
.xlo
, crColor
);
897 /* Cleanup the XLATEOBJ */
898 EXLATEOBJ_vCleanup(&exlo
);