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 GreGetMapMode(HDC hdc
)
54 if (!(dc
= DC_LockDc(hdc
)))
56 EngSetLastError(ERROR_INVALID_HANDLE
);
59 iMapMode
= dc
->pdcattr
->iMapMode
;
65 GreGetTextColor(HDC hdc
)
68 ULONG ulForegroundClr
;
69 if (!(dc
= DC_LockDc(hdc
)))
71 EngSetLastError(ERROR_INVALID_HANDLE
);
74 ulForegroundClr
= dc
->pdcattr
->ulForegroundClr
;
76 return ulForegroundClr
;
80 IntGdiSetBkColor(HDC hDC
, COLORREF color
)
87 if (!(dc
= DC_LockDc(hDC
)))
89 EngSetLastError(ERROR_INVALID_HANDLE
);
92 pdcattr
= dc
->pdcattr
;
93 oldColor
= pdcattr
->crBackgroundClr
;
94 pdcattr
->crBackgroundClr
= color
;
95 pdcattr
->ulBackgroundClr
= (ULONG
)color
;
96 pdcattr
->ulDirty_
|= DIRTY_BACKGROUND
|DIRTY_LINE
|DIRTY_FILL
; // Clear Flag if set.
97 hBrush
= pdcattr
->hbrush
;
99 NtGdiSelectBrush(hDC
, hBrush
);
104 IntGdiSetBkMode(HDC hDC
, INT Mode
)
110 if (!(dc
= DC_LockDc(hDC
)))
112 EngSetLastError(ERROR_INVALID_HANDLE
);
115 pdcattr
= dc
->pdcattr
;
116 oldMode
= pdcattr
->lBkMode
;
117 pdcattr
->jBkMode
= Mode
;
118 pdcattr
->lBkMode
= Mode
;
125 IntGdiSetTextAlign(HDC hDC
,
135 EngSetLastError(ERROR_INVALID_HANDLE
);
138 pdcattr
= dc
->pdcattr
;
139 prevAlign
= pdcattr
->lTextAlign
;
140 pdcattr
->lTextAlign
= Mode
;
147 IntGdiSetTextColor(HDC hDC
,
154 pdc
= DC_LockDc(hDC
);
157 EngSetLastError(ERROR_INVALID_HANDLE
);
160 pdcattr
= pdc
->pdcattr
;
162 // What about ulForegroundClr, like in gdi32?
163 crOldColor
= pdcattr
->crForegroundClr
;
164 pdcattr
->crForegroundClr
= color
;
165 DC_vUpdateTextBrush(pdc
);
173 IntSetDCBrushColor(HDC hdc
, COLORREF crColor
)
175 COLORREF OldColor
= CLR_INVALID
;
177 if (!(dc
= DC_LockDc(hdc
)))
179 EngSetLastError(ERROR_INVALID_HANDLE
);
184 OldColor
= (COLORREF
) dc
->pdcattr
->ulBrushClr
;
185 dc
->pdcattr
->ulBrushClr
= (ULONG
) crColor
;
187 if ( dc
->pdcattr
->crBrushClr
!= crColor
)
189 dc
->pdcattr
->ulDirty_
|= DIRTY_FILL
;
190 dc
->pdcattr
->crBrushClr
= crColor
;
198 IntSetDCPenColor(HDC hdc
, COLORREF crColor
)
202 if (!(dc
= DC_LockDc(hdc
)))
204 EngSetLastError(ERROR_INVALID_PARAMETER
);
208 OldColor
= (COLORREF
)dc
->pdcattr
->ulPenClr
;
209 dc
->pdcattr
->ulPenClr
= (ULONG
)crColor
;
211 if (dc
->pdcattr
->crPenClr
!= crColor
)
213 dc
->pdcattr
->ulDirty_
|= DIRTY_LINE
;
214 dc
->pdcattr
->crPenClr
= crColor
;
222 GreSetStretchBltMode(HDC hDC
, int iStretchMode
)
228 pdc
= DC_LockDc(hDC
);
231 pdcattr
= pdc
->pdcattr
;
232 oSMode
= pdcattr
->lStretchBltMode
;
233 pdcattr
->lStretchBltMode
= iStretchMode
;
235 // Wine returns an error here. We set the default.
236 if ((iStretchMode
<= 0) || (iStretchMode
> MAXSTRETCHBLTMODE
)) iStretchMode
= WHITEONBLACK
;
238 pdcattr
->jStretchBltMode
= iStretchMode
;
245 GreGetGraphicsMode(HDC hdc
)
249 if (!(dc
= DC_LockDc(hdc
)))
251 EngSetLastError(ERROR_INVALID_HANDLE
);
254 GraphicsMode
= dc
->pdcattr
->iGraphicsMode
;;
261 DCU_SetDcUndeletable(HDC hDC
)
263 PDC dc
= DC_LockDc(hDC
);
266 EngSetLastError(ERROR_INVALID_HANDLE
);
270 dc
->fs
|= DC_FLAG_PERMANENT
;
277 IntIsPrimarySurface(SURFOBJ
*SurfObj
)
279 if (PrimarySurface
.pSurface
== NULL
)
283 return SurfObj
->hsurf
== PrimarySurface
.pSurface
; // <- FIXME: WTF?
289 IntSetDefaultRegion(PDC pdc
)
293 RECTL rclWnd
, rclClip
;
295 IntGdiReleaseRaoRgn(pdc
);
299 rclWnd
.right
= pdc
->dclevel
.sizl
.cx
;
300 rclWnd
.bottom
= pdc
->dclevel
.sizl
.cy
;
303 //EngAcquireSemaphoreShared(pdc->ppdev->hsemDevLock);
304 if (pdc
->ppdev
->flFlags
& PDEV_META_DEVICE
)
306 pSurface
= pdc
->dclevel
.pSurface
;
307 if (pSurface
&& pSurface
->flags
& PDEV_SURFACE
)
309 rclClip
.left
+= pdc
->ppdev
->ptlOrigion
.x
;
310 rclClip
.top
+= pdc
->ppdev
->ptlOrigion
.y
;
311 rclClip
.right
+= pdc
->ppdev
->ptlOrigion
.x
;
312 rclClip
.bottom
+= pdc
->ppdev
->ptlOrigion
.y
;
315 //EngReleaseSemaphore(pdc->ppdev->hsemDevLock);
319 if (prgn
&& prgn
!= prgnDefault
)
321 REGION_SetRectRgn( prgn
,
329 prgn
= IntSysCreateRectpRgn( rclClip
.left
,
338 pdc
->ptlDCOrig
.x
= 0;
339 pdc
->ptlDCOrig
.y
= 0;
340 pdc
->erclWindow
= rclWnd
;
341 pdc
->erclClip
= rclClip
;
342 /* Might be an InitDC or DCE... */
343 pdc
->ptlFillOrigin
.x
= pdc
->dcattr
.VisRectRegion
.Rect
.right
;
344 pdc
->ptlFillOrigin
.y
= pdc
->dcattr
.VisRectRegion
.Rect
.bottom
;
348 pdc
->prgnVis
= prgnDefault
;
354 NtGdiCancelDC(HDC hDC
)
362 IntGdiSetHookFlags(HDC hDC
, WORD Flags
)
365 DC
*dc
= DC_LockDc(hDC
);
369 EngSetLastError(ERROR_INVALID_HANDLE
);
373 wRet
= dc
->fs
& DC_FLAG_DIRTY_RAO
; // FIXME: Wrong flag!
375 /* Info in "Undocumented Windows" is slightly confusing. */
376 DPRINT("DC %p, Flags %04x\n", hDC
, Flags
);
378 if (Flags
& DCHF_INVALIDATEVISRGN
)
380 /* hVisRgn has to be updated */
381 dc
->fs
|= DC_FLAG_DIRTY_RAO
;
383 else if (Flags
& DCHF_VALIDATEVISRGN
|| 0 == Flags
)
385 //dc->fs &= ~DC_FLAG_DIRTY_RAO;
405 DWORD SafeResult
= 0;
406 NTSTATUS Status
= STATUS_SUCCESS
;
410 EngSetLastError(ERROR_INVALID_PARAMETER
);
414 pdc
= DC_LockDc(hDC
);
417 EngSetLastError(ERROR_INVALID_HANDLE
);
420 pdcattr
= pdc
->pdcattr
;
428 SafeResult
= pdcattr
->lRelAbs
;
431 case GdiGetBreakExtra
:
432 SafeResult
= pdcattr
->lBreakExtra
;
435 case GdiGerCharBreak
:
436 SafeResult
= pdcattr
->cBreak
;
439 case GdiGetArcDirection
:
440 if (pdcattr
->dwLayout
& LAYOUT_RTL
)
441 SafeResult
= AD_CLOCKWISE
- ((pdc
->dclevel
.flPath
& DCPATH_CLOCKWISE
) != 0);
443 SafeResult
= ((pdc
->dclevel
.flPath
& DCPATH_CLOCKWISE
) != 0) + AD_COUNTERCLOCKWISE
;
446 case GdiGetEMFRestorDc
:
447 SafeResult
= pdc
->dclevel
.lSaveDepth
;
450 case GdiGetFontLanguageInfo
:
451 SafeResult
= IntGetFontLanguageInfo(pdc
);
455 SafeResult
= pdc
->dctype
;
459 SafeResult
= pdcattr
->iMapMode
;
462 case GdiGetTextCharExtra
:
463 SafeResult
= pdcattr
->lTextExtra
;
467 EngSetLastError(ERROR_INVALID_PARAMETER
);
476 ProbeForWrite(Result
, sizeof(DWORD
), 1);
477 *Result
= SafeResult
;
479 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
481 Status
= _SEH2_GetExceptionCode();
485 if (!NT_SUCCESS(Status
))
487 SetLastNtError(Status
);
496 _Success_(return != FALSE
)
499 NtGdiGetAndSetDCDword(
503 _Out_ DWORD
*pdwResult
)
509 DWORD SafeResult
= 0;
510 NTSTATUS Status
= STATUS_SUCCESS
;
514 EngSetLastError(ERROR_INVALID_PARAMETER
);
518 pdc
= DC_LockDc(hdc
);
521 EngSetLastError(ERROR_INVALID_HANDLE
);
524 pdcattr
= pdc
->pdcattr
;
528 case GdiGetSetCopyCount
:
529 SafeResult
= pdc
->ulCopyCount
;
530 pdc
->ulCopyCount
= dwIn
;
533 case GdiGetSetTextAlign
:
534 SafeResult
= pdcattr
->lTextAlign
;
535 pdcattr
->lTextAlign
= dwIn
;
536 // pdcattr->flTextAlign = dwIn; // Flags!
539 case GdiGetSetRelAbs
:
540 SafeResult
= pdcattr
->lRelAbs
;
541 pdcattr
->lRelAbs
= dwIn
;
544 case GdiGetSetTextCharExtra
:
545 SafeResult
= pdcattr
->lTextExtra
;
546 pdcattr
->lTextExtra
= dwIn
;
549 case GdiGetSetSelectFont
:
552 case GdiGetSetMapperFlagsInternal
:
555 EngSetLastError(ERROR_INVALID_PARAMETER
);
559 SafeResult
= pdcattr
->flFontMapper
;
560 pdcattr
->flFontMapper
= dwIn
;
563 case GdiGetSetMapMode
:
564 SafeResult
= IntGdiSetMapMode(pdc
, dwIn
);
567 case GdiGetSetArcDirection
:
568 if (dwIn
!= AD_COUNTERCLOCKWISE
&& dwIn
!= AD_CLOCKWISE
)
570 EngSetLastError(ERROR_INVALID_PARAMETER
);
574 if (pdcattr
->dwLayout
& LAYOUT_RTL
) // Right to Left
576 SafeResult
= AD_CLOCKWISE
- ((pdc
->dclevel
.flPath
& DCPATH_CLOCKWISE
) != 0);
577 if (dwIn
== AD_CLOCKWISE
)
579 pdc
->dclevel
.flPath
&= ~DCPATH_CLOCKWISE
;
582 pdc
->dclevel
.flPath
|= DCPATH_CLOCKWISE
;
584 else // Left to Right
586 SafeResult
= ((pdc
->dclevel
.flPath
& DCPATH_CLOCKWISE
) != 0) +
588 if (dwIn
== AD_COUNTERCLOCKWISE
)
590 pdc
->dclevel
.flPath
&= ~DCPATH_CLOCKWISE
;
593 pdc
->dclevel
.flPath
|= DCPATH_CLOCKWISE
;
598 EngSetLastError(ERROR_INVALID_PARAMETER
);
607 ProbeForWrite(pdwResult
, sizeof(DWORD
), 1);
608 *pdwResult
= SafeResult
;
610 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
612 Status
= _SEH2_GetExceptionCode();
616 if (!NT_SUCCESS(Status
))
618 SetLastNtError(Status
);
638 if (!(pdc
= DC_LockDc(hdc
))) return 0;
640 /* Get the return value */
641 ret
= pdc
->fs
& DC_ACCUM_APP
? DCB_ENABLE
: DCB_DISABLE
;
642 ret
|= RECTL_bIsEmptyRect(&pdc
->erclBoundsApp
) ? DCB_RESET
: DCB_SET
;
644 /* Copy the rect to the caller */
647 ProbeForWrite(prc
, sizeof(RECT
), 1);
648 *prc
= pdc
->erclBoundsApp
;
650 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
656 if (flags
& DCB_RESET
)
658 RECTL_vSetEmptyRect(&pdc
->erclBoundsApp
);
677 /* Verify arguments */
678 if ((flags
& DCB_ENABLE
) && (flags
& DCB_DISABLE
)) return 0;
681 if (!(pdc
= DC_LockDc(hdc
))) return 0;
683 /* Get the return value */
684 ret
= pdc
->fs
& DC_ACCUM_APP
? DCB_ENABLE
: DCB_DISABLE
;
685 ret
|= RECTL_bIsEmptyRect(&pdc
->erclBoundsApp
) ? DCB_RESET
: DCB_SET
;
687 if (flags
& DCB_RESET
)
689 RECTL_vSetEmptyRect(&pdc
->erclBoundsApp
);
692 if (flags
& DCB_ACCUMULATE
&& prc
!= NULL
)
694 /* Capture the rect */
697 ProbeForRead(prc
, sizeof(RECT
), 1);
700 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
703 _SEH2_YIELD(return 0;)
707 RECTL_vMakeWellOrdered(&rcl
);
708 RECTL_bUnionRect(&pdc
->erclBoundsApp
, &pdc
->erclBoundsApp
, &rcl
);
711 if (flags
& DCB_ENABLE
) pdc
->fs
|= DC_ACCUM_APP
;
712 if (flags
& DCB_DISABLE
) pdc
->fs
&= ~DC_ACCUM_APP
;
717 /* Translates a COLORREF to the right color in the specified DC color space */
719 TranslateCOLORREF(PDC pdc
, COLORREF crColor
)
723 ULONG index
, ulColor
, iBitmapFormat
;
726 /* Get the DC surface */
727 psurfDC
= pdc
->dclevel
.pSurface
;
729 /* If no surface is selected, use the default bitmap */
731 psurfDC
= psurfDefaultBitmap
;
733 /* Check what color type this is */
734 switch (crColor
>> 24)
736 case 0x00: /* RGB color */
739 case 0x01: /* PALETTEINDEX */
740 index
= crColor
& 0xFFFFFF;
741 ppalDC
= pdc
->dclevel
.ppal
;
742 if (index
>= ppalDC
->NumColors
) index
= 0;
744 /* Get the RGB value */
745 crColor
= PALETTE_ulGetRGBColorFromIndex(ppalDC
, index
);
748 case 0x02: /* PALETTERGB */
750 if (pdc
->dclevel
.hpal
!= StockObjects
[DEFAULT_PALETTE
])
752 /* First find the nearest index in the dc palette */
753 ppalDC
= pdc
->dclevel
.ppal
;
754 index
= PALETTE_ulGetNearestIndex(ppalDC
, crColor
& 0xFFFFFF);
756 /* Get the RGB value */
757 crColor
= PALETTE_ulGetRGBColorFromIndex(ppalDC
, index
);
761 /* Use the pure color */
762 crColor
= crColor
& 0x00FFFFFF;
766 case 0x10: /* DIBINDEX */
767 /* Mask the value to match the target bpp */
768 iBitmapFormat
= psurfDC
->SurfObj
.iBitmapFormat
;
769 if (iBitmapFormat
== BMF_1BPP
) index
= crColor
& 0x1;
770 else if (iBitmapFormat
== BMF_4BPP
) index
= crColor
& 0xf;
771 else if (iBitmapFormat
== BMF_8BPP
) index
= crColor
& 0xFF;
772 else if (iBitmapFormat
== BMF_16BPP
) index
= crColor
& 0xFFFF;
773 else index
= crColor
& 0xFFFFFF;
777 DPRINT("Unsupported color type %u passed\n", crColor
>> 24);
781 /* Initialize an XLATEOBJ from RGB to the target surface */
782 EXLATEOBJ_vInitialize(&exlo
, &gpalRGB
, psurfDC
->ppal
, 0xFFFFFF, 0, 0);
784 /* Translate the color to the target format */
785 ulColor
= XLATEOBJ_iXlate(&exlo
.xlo
, crColor
);
787 /* Cleanup the XLATEOBJ */
788 EXLATEOBJ_vCleanup(&exlo
);