7 IntGdiSetBkColor(HDC hDC
, COLORREF color
)
14 if (!(dc
= DC_LockDc(hDC
)))
16 EngSetLastError(ERROR_INVALID_HANDLE
);
19 pdcattr
= dc
->pdcattr
;
20 oldColor
= pdcattr
->crBackgroundClr
;
21 pdcattr
->crBackgroundClr
= color
;
22 pdcattr
->ulBackgroundClr
= (ULONG
)color
;
23 pdcattr
->ulDirty_
|= DIRTY_BACKGROUND
|DIRTY_LINE
|DIRTY_FILL
; // Clear Flag if set.
24 hBrush
= pdcattr
->hbrush
;
26 NtGdiSelectBrush(hDC
, hBrush
);
31 IntGdiSetBkMode(HDC hDC
, INT Mode
)
37 if (!(dc
= DC_LockDc(hDC
)))
39 EngSetLastError(ERROR_INVALID_HANDLE
);
42 pdcattr
= dc
->pdcattr
;
43 oldMode
= pdcattr
->lBkMode
;
44 pdcattr
->jBkMode
= Mode
;
45 pdcattr
->lBkMode
= Mode
;
52 IntGdiSetTextAlign(HDC hDC
,
62 EngSetLastError(ERROR_INVALID_HANDLE
);
65 pdcattr
= dc
->pdcattr
;
66 prevAlign
= pdcattr
->lTextAlign
;
67 pdcattr
->lTextAlign
= Mode
;
74 IntGdiSetTextColor(HDC hDC
,
84 EngSetLastError(ERROR_INVALID_HANDLE
);
87 pdcattr
= pdc
->pdcattr
;
89 // What about ulForegroundClr, like in gdi32?
90 crOldColor
= pdcattr
->crForegroundClr
;
91 pdcattr
->crForegroundClr
= color
;
92 DC_vUpdateTextBrush(pdc
);
101 DCU_SetDcUndeletable(HDC hDC
)
103 PDC dc
= DC_LockDc(hDC
);
106 EngSetLastError(ERROR_INVALID_HANDLE
);
110 dc
->fs
|= DC_FLAG_PERMANENT
;
117 IntIsPrimarySurface(SURFOBJ
*SurfObj
)
119 if (PrimarySurface
.pSurface
== NULL
)
123 return SurfObj
->hsurf
== PrimarySurface
.pSurface
; // <- FIXME: WTF?
129 IntSetDefaultRegion(PDC pdc
)
133 RECTL rclWnd
, rclClip
;
135 IntGdiReleaseRaoRgn(pdc
);
139 rclWnd
.right
= pdc
->dclevel
.sizl
.cx
;
140 rclWnd
.bottom
= pdc
->dclevel
.sizl
.cy
;
143 //EngAcquireSemaphoreShared(pdc->ppdev->hsemDevLock);
144 if (pdc
->ppdev
->flFlags
& PDEV_META_DEVICE
)
146 pSurface
= pdc
->dclevel
.pSurface
;
147 if (pSurface
&& pSurface
->flags
& PDEV_SURFACE
)
149 rclClip
.left
+= pdc
->ppdev
->ptlOrigion
.x
;
150 rclClip
.top
+= pdc
->ppdev
->ptlOrigion
.y
;
151 rclClip
.right
+= pdc
->ppdev
->ptlOrigion
.x
;
152 rclClip
.bottom
+= pdc
->ppdev
->ptlOrigion
.y
;
155 //EngReleaseSemaphore(pdc->ppdev->hsemDevLock);
159 if (prgn
&& prgn
!= prgnDefault
)
161 REGION_SetRectRgn( prgn
,
169 prgn
= IntSysCreateRectpRgn( rclClip
.left
,
178 pdc
->ptlDCOrig
.x
= 0;
179 pdc
->ptlDCOrig
.y
= 0;
180 pdc
->erclWindow
= rclWnd
;
181 pdc
->erclClip
= rclClip
;
182 /* Might be an InitDC or DCE... */
183 pdc
->ptlFillOrigin
.x
= pdc
->dcattr
.VisRectRegion
.Rect
.right
;
184 pdc
->ptlFillOrigin
.y
= pdc
->dcattr
.VisRectRegion
.Rect
.bottom
;
188 pdc
->prgnVis
= prgnDefault
;
194 NtGdiCancelDC(HDC hDC
)
202 IntGdiSetHookFlags(HDC hDC
, WORD Flags
)
205 DC
*dc
= DC_LockDc(hDC
);
209 EngSetLastError(ERROR_INVALID_HANDLE
);
213 wRet
= dc
->fs
& DC_FLAG_DIRTY_RAO
; // FIXME: Wrong flag!
215 /* Info in "Undocumented Windows" is slightly confusing. */
216 DPRINT("DC %p, Flags %04x\n", hDC
, Flags
);
218 if (Flags
& DCHF_INVALIDATEVISRGN
)
220 /* hVisRgn has to be updated */
221 dc
->fs
|= DC_FLAG_DIRTY_RAO
;
223 else if (Flags
& DCHF_VALIDATEVISRGN
|| 0 == Flags
)
225 dc
->fs
&= ~DC_FLAG_DIRTY_RAO
;
245 DWORD SafeResult
= 0;
246 NTSTATUS Status
= STATUS_SUCCESS
;
250 EngSetLastError(ERROR_INVALID_PARAMETER
);
254 pdc
= DC_LockDc(hDC
);
257 EngSetLastError(ERROR_INVALID_HANDLE
);
260 pdcattr
= pdc
->pdcattr
;
268 SafeResult
= pdcattr
->lRelAbs
;
271 case GdiGetBreakExtra
:
272 SafeResult
= pdcattr
->lBreakExtra
;
275 case GdiGerCharBreak
:
276 SafeResult
= pdcattr
->cBreak
;
279 case GdiGetArcDirection
:
280 if (pdcattr
->dwLayout
& LAYOUT_RTL
)
281 SafeResult
= AD_CLOCKWISE
- ((pdc
->dclevel
.flPath
& DCPATH_CLOCKWISE
) != 0);
283 SafeResult
= ((pdc
->dclevel
.flPath
& DCPATH_CLOCKWISE
) != 0) + AD_COUNTERCLOCKWISE
;
286 case GdiGetEMFRestorDc
:
289 case GdiGetFontLanguageInfo
:
290 SafeResult
= IntGetFontLanguageInfo(pdc
);
294 SafeResult
= pdc
->dctype
;
298 SafeResult
= pdcattr
->iMapMode
;
301 case GdiGetTextCharExtra
:
302 SafeResult
= pdcattr
->lTextExtra
;
306 EngSetLastError(ERROR_INVALID_PARAMETER
);
315 ProbeForWrite(Result
, sizeof(DWORD
), 1);
316 *Result
= SafeResult
;
318 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
320 Status
= _SEH2_GetExceptionCode();
324 if (!NT_SUCCESS(Status
))
326 SetLastNtError(Status
);
335 BOOL
_Success_(return != FALSE
)
337 NtGdiGetAndSetDCDword(
341 _Out_ DWORD
*pdwResult
)
347 DWORD SafeResult
= 0;
348 NTSTATUS Status
= STATUS_SUCCESS
;
352 EngSetLastError(ERROR_INVALID_PARAMETER
);
356 pdc
= DC_LockDc(hdc
);
359 EngSetLastError(ERROR_INVALID_HANDLE
);
362 pdcattr
= pdc
->pdcattr
;
366 case GdiGetSetCopyCount
:
367 SafeResult
= pdc
->ulCopyCount
;
368 pdc
->ulCopyCount
= dwIn
;
371 case GdiGetSetTextAlign
:
372 SafeResult
= pdcattr
->lTextAlign
;
373 pdcattr
->lTextAlign
= dwIn
;
374 // pdcattr->flTextAlign = dwIn; // Flags!
377 case GdiGetSetRelAbs
:
378 SafeResult
= pdcattr
->lRelAbs
;
379 pdcattr
->lRelAbs
= dwIn
;
382 case GdiGetSetTextCharExtra
:
383 SafeResult
= pdcattr
->lTextExtra
;
384 pdcattr
->lTextExtra
= dwIn
;
387 case GdiGetSetSelectFont
:
390 case GdiGetSetMapperFlagsInternal
:
393 EngSetLastError(ERROR_INVALID_PARAMETER
);
397 SafeResult
= pdcattr
->flFontMapper
;
398 pdcattr
->flFontMapper
= dwIn
;
401 case GdiGetSetMapMode
:
402 SafeResult
= IntGdiSetMapMode(pdc
, dwIn
);
405 case GdiGetSetArcDirection
:
406 if (dwIn
!= AD_COUNTERCLOCKWISE
&& dwIn
!= AD_CLOCKWISE
)
408 EngSetLastError(ERROR_INVALID_PARAMETER
);
412 if (pdcattr
->dwLayout
& LAYOUT_RTL
) // Right to Left
414 SafeResult
= AD_CLOCKWISE
- ((pdc
->dclevel
.flPath
& DCPATH_CLOCKWISE
) != 0);
415 if (dwIn
== AD_CLOCKWISE
)
417 pdc
->dclevel
.flPath
&= ~DCPATH_CLOCKWISE
;
420 pdc
->dclevel
.flPath
|= DCPATH_CLOCKWISE
;
422 else // Left to Right
424 SafeResult
= ((pdc
->dclevel
.flPath
& DCPATH_CLOCKWISE
) != 0) +
426 if (dwIn
== AD_COUNTERCLOCKWISE
)
428 pdc
->dclevel
.flPath
&= ~DCPATH_CLOCKWISE
;
431 pdc
->dclevel
.flPath
|= DCPATH_CLOCKWISE
;
436 EngSetLastError(ERROR_INVALID_PARAMETER
);
445 ProbeForWrite(pdwResult
, sizeof(DWORD
), 1);
446 *pdwResult
= SafeResult
;
448 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
450 Status
= _SEH2_GetExceptionCode();
454 if (!NT_SUCCESS(Status
))
456 SetLastNtError(Status
);
476 if (!(pdc
= DC_LockDc(hdc
))) return 0;
478 /* Get the return value */
479 ret
= pdc
->fs
& DC_ACCUM_APP
? DCB_ENABLE
: DCB_DISABLE
;
480 ret
|= RECTL_bIsEmptyRect(&pdc
->erclBoundsApp
) ? DCB_RESET
: DCB_SET
;
482 /* Copy the rect to the caller */
485 ProbeForWrite(prc
, sizeof(RECT
), 1);
486 *prc
= pdc
->erclBoundsApp
;
488 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
494 if (flags
& DCB_RESET
)
496 RECTL_vSetEmptyRect(&pdc
->erclBoundsApp
);
515 /* Verify arguments */
516 if ((flags
& DCB_ENABLE
) && (flags
& DCB_DISABLE
)) return 0;
519 if (!(pdc
= DC_LockDc(hdc
))) return 0;
521 /* Get the return value */
522 ret
= pdc
->fs
& DC_ACCUM_APP
? DCB_ENABLE
: DCB_DISABLE
;
523 ret
|= RECTL_bIsEmptyRect(&pdc
->erclBoundsApp
) ? DCB_RESET
: DCB_SET
;
525 if (flags
& DCB_RESET
)
527 RECTL_vSetEmptyRect(&pdc
->erclBoundsApp
);
530 if (flags
& DCB_ACCUMULATE
)
532 /* Capture the rect */
535 ProbeForRead(prc
, sizeof(RECT
), 1);
538 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
541 _SEH2_YIELD(return 0;)
545 RECTL_vMakeWellOrdered(&rcl
);
546 RECTL_bUnionRect(&pdc
->erclBoundsApp
, &pdc
->erclBoundsApp
, &rcl
);
549 if (flags
& DCB_ENABLE
) pdc
->fs
|= DC_ACCUM_APP
;
550 if (flags
& DCB_DISABLE
) pdc
->fs
&= ~DC_ACCUM_APP
;
555 /* Translates a COLORREF to the right color in the specified DC color space */
557 TranslateCOLORREF(PDC pdc
, COLORREF crColor
)
561 ULONG index
, ulColor
, iBitmapFormat
;
564 /* Get the DC surface */
565 psurfDC
= pdc
->dclevel
.pSurface
;
567 /* If no surface is selected, use the default bitmap */
569 psurfDC
= psurfDefaultBitmap
;
571 /* Check what color type this is */
572 switch (crColor
>> 24)
574 case 0x00: /* RGB color */
577 case 0x01: /* PALETTEINDEX */
578 index
= crColor
& 0xFFFFFF;
579 ppalDC
= pdc
->dclevel
.ppal
;
580 if (index
>= ppalDC
->NumColors
) index
= 0;
582 /* Get the RGB value */
583 crColor
= PALETTE_ulGetRGBColorFromIndex(ppalDC
, index
);
586 case 0x02: /* PALETTERGB */
588 if (pdc
->dclevel
.hpal
!= StockObjects
[DEFAULT_PALETTE
])
590 /* First find the nearest index in the dc palette */
591 ppalDC
= pdc
->dclevel
.ppal
;
592 index
= PALETTE_ulGetNearestIndex(ppalDC
, crColor
& 0xFFFFFF);
594 /* Get the RGB value */
595 crColor
= PALETTE_ulGetRGBColorFromIndex(ppalDC
, index
);
599 /* Use the pure color */
600 crColor
= crColor
& 0x00FFFFFF;
604 case 0x10: /* DIBINDEX */
605 /* Mask the value to match the target bpp */
606 iBitmapFormat
= psurfDC
->SurfObj
.iBitmapFormat
;
607 if (iBitmapFormat
== BMF_1BPP
) index
= crColor
& 0x1;
608 else if (iBitmapFormat
== BMF_4BPP
) index
= crColor
& 0xf;
609 else if (iBitmapFormat
== BMF_8BPP
) index
= crColor
& 0xFF;
610 else if (iBitmapFormat
== BMF_16BPP
) index
= crColor
& 0xFFFF;
611 else index
= crColor
& 0xFFFFFF;
615 DPRINT("Unsupported color type %u passed\n", crColor
>> 24);
619 /* Initialize an XLATEOBJ from RGB to the target surface */
620 EXLATEOBJ_vInitialize(&exlo
, &gpalRGB
, psurfDC
->ppal
, 0xFFFFFF, 0, 0);
622 /* Translate the color to the target format */
623 ulColor
= XLATEOBJ_iXlate(&exlo
.xlo
, crColor
);
625 /* Cleanup the XLATEOBJ */
626 EXLATEOBJ_vCleanup(&exlo
);