2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /* $Id: dc.c,v 1.135 2004/05/14 16:55:18 navaraf Exp $
21 * DC.C - Device context functions
26 #ifndef OBJ_COLORSPACE
27 #define OBJ_COLORSPACE (14)
30 static GDIDEVICE PrimarySurface
;
32 /* FIXME: DCs should probably be thread safe */
35 * DC device-independent Get/SetXXX functions
36 * (RJJ) swiped from WINE
39 #define DC_GET_VAL( func_type, func_name, dc_field ) \
40 func_type STDCALL func_name( HDC hdc ) \
43 PDC dc = DC_LockDc( hdc ); \
46 SetLastWin32Error(ERROR_INVALID_HANDLE); \
54 /* DC_GET_VAL_EX is used to define functions returning a POINT or a SIZE. It is
55 * important that the function has the right signature, for the implementation
56 * we can do whatever we want.
58 #define DC_GET_VAL_EX( FuncName, ret_x, ret_y, type, ax, ay ) \
59 VOID FASTCALL Int##FuncName ( PDC dc, LP##type pt) \
66 BOOL STDCALL NtGdi##FuncName ( HDC hdc, LP##type pt ) \
73 SetLastWin32Error(ERROR_INVALID_PARAMETER); \
76 if(!(dc = DC_LockDc(hdc))) \
78 SetLastWin32Error(ERROR_INVALID_HANDLE); \
81 Int##FuncName( dc, &Safept); \
83 Status = MmCopyToCaller(pt, &Safept, sizeof( type )); \
84 if(!NT_SUCCESS(Status)) \
86 SetLastNtError(Status); \
92 #define DC_SET_MODE( func_name, dc_field, min_val, max_val ) \
93 INT STDCALL func_name( HDC hdc, INT mode ) \
97 if ((mode < min_val) || (mode > max_val)) \
99 SetLastWin32Error(ERROR_INVALID_PARAMETER); \
102 dc = DC_LockDc ( hdc ); \
105 SetLastWin32Error(ERROR_INVALID_HANDLE); \
108 prevMode = dc->dc_field; \
109 dc->dc_field = mode; \
110 DC_UnlockDc ( hdc ); \
115 // --------------------------------------------------------- File Statics
117 // ----------------------------------------------------- Public Functions
120 NtGdiCancelDC(HDC hDC
)
126 NtGdiCreateCompatableDC(HDC hDC
)
130 HDC hNewDC
, DisplayDC
;
133 UNICODE_STRING DriverName
;
138 RtlInitUnicodeString(&DriverName
, L
"DISPLAY");
139 DisplayDC
= IntGdiCreateDC(&DriverName
, NULL
, NULL
, NULL
);
140 if (NULL
== DisplayDC
)
147 /* Allocate a new DC based on the original DC's device */
148 OrigDC
= DC_LockDc(hDC
);
151 if (NULL
!= DisplayDC
)
153 NtGdiDeleteDC(DisplayDC
);
157 hNewDC
= DC_AllocDC(&OrigDC
->DriverName
);
162 if (NULL
!= DisplayDC
)
164 NtGdiDeleteDC(DisplayDC
);
168 NewDC
= DC_LockDc( hNewDC
);
170 /* Copy information from original DC to new DC */
171 NewDC
->hSelf
= hNewDC
;
173 NewDC
->PDev
= OrigDC
->PDev
;
174 NewDC
->DMW
= OrigDC
->DMW
;
175 memcpy(NewDC
->FillPatternSurfaces
,
176 OrigDC
->FillPatternSurfaces
,
177 sizeof OrigDC
->FillPatternSurfaces
);
178 NewDC
->GDIInfo
= OrigDC
->GDIInfo
;
179 NewDC
->DevInfo
= OrigDC
->DevInfo
;
180 NewDC
->w
.bitsPerPixel
= OrigDC
->w
.bitsPerPixel
;
182 /* DriverName is copied in the AllocDC routine */
183 NewDC
->DeviceDriver
= OrigDC
->DeviceDriver
;
184 NewDC
->wndOrgX
= OrigDC
->wndOrgX
;
185 NewDC
->wndOrgY
= OrigDC
->wndOrgY
;
186 NewDC
->wndExtX
= OrigDC
->wndExtX
;
187 NewDC
->wndExtY
= OrigDC
->wndExtY
;
188 NewDC
->vportOrgX
= OrigDC
->vportOrgX
;
189 NewDC
->vportOrgY
= OrigDC
->vportOrgY
;
190 NewDC
->vportExtX
= OrigDC
->vportExtX
;
191 NewDC
->vportExtY
= OrigDC
->vportExtY
;
193 /* Create default bitmap */
194 if (!(hBitmap
= NtGdiCreateBitmap( 1, 1, 1, NewDC
->w
.bitsPerPixel
, NULL
)))
197 DC_UnlockDc( hNewDC
);
199 if (NULL
!= DisplayDC
)
201 NtGdiDeleteDC(DisplayDC
);
205 NewDC
->w
.flags
= DC_MEMORY
;
206 NewDC
->w
.hBitmap
= hBitmap
;
207 NewDC
->w
.hFirstBitmap
= hBitmap
;
208 NewDC
->GDIDevice
= OrigDC
->GDIDevice
;
209 pb
= BITMAPOBJ_LockBitmap(hBitmap
);
210 NewDC
->Surface
= (HSURF
)BitmapToSurf(pb
, NewDC
->GDIDevice
);
211 BITMAPOBJ_UnlockBitmap(hBitmap
);
213 NewDC
->w
.hPalette
= OrigDC
->w
.hPalette
;
214 NewDC
->w
.textColor
= OrigDC
->w
.textColor
;
215 NewDC
->w
.textAlign
= OrigDC
->w
.textAlign
;
216 NewDC
->w
.backgroundColor
= OrigDC
->w
.backgroundColor
;
217 NewDC
->w
.backgroundMode
= OrigDC
->w
.backgroundMode
;
219 if (NULL
!= DisplayDC
)
221 NtGdiDeleteDC(DisplayDC
);
225 hVisRgn
= NtGdiCreateRectRgn(0, 0, 1, 1);
226 NtGdiSelectVisRgn(hNewDC
, hVisRgn
);
227 NtGdiDeleteObject(hVisRgn
);
235 GetRegistryPath(PUNICODE_STRING RegistryPath
, ULONG DisplayNumber
)
237 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
238 WCHAR DeviceNameBuffer
[20];
241 swprintf(DeviceNameBuffer
, L
"\\Device\\Video%d", DisplayNumber
);
242 RtlInitUnicodeString(RegistryPath
, NULL
);
243 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
244 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_REQUIRED
| RTL_QUERY_REGISTRY_DIRECT
;
245 QueryTable
[0].Name
= DeviceNameBuffer
;
246 QueryTable
[0].EntryContext
= RegistryPath
;
248 Status
= RtlQueryRegistryValues(RTL_REGISTRY_DEVICEMAP
,
253 if (! NT_SUCCESS(Status
))
255 DPRINT1("No \\Device\\Video%d value in DEVICEMAP\\VIDEO found\n", DisplayNumber
);
259 DPRINT("RegistryPath %S\n", RegistryPath
->Buffer
);
265 FindDriverFileNames(PUNICODE_STRING DriverFileNames
, ULONG DisplayNumber
)
267 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
268 UNICODE_STRING RegistryPath
;
271 if (! GetRegistryPath(&RegistryPath
, DisplayNumber
))
273 DPRINT("GetRegistryPath failed\n");
277 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
278 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_REQUIRED
| RTL_QUERY_REGISTRY_DIRECT
;
279 QueryTable
[0].Name
= L
"InstalledDisplayDrivers";
280 QueryTable
[0].EntryContext
= DriverFileNames
;
282 Status
= RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE
,
287 RtlFreeUnicodeString(&RegistryPath
);
288 if (! NT_SUCCESS(Status
))
290 DPRINT1("No InstalledDisplayDrivers value in service entry found\n");
294 DPRINT("DriverFileNames %S\n", DriverFileNames
->Buffer
);
299 static NTSTATUS STDCALL
300 DevModeCallback(IN PWSTR ValueName
,
303 IN ULONG ValueLength
,
305 IN PVOID EntryContext
)
307 PDEVMODEW DevMode
= (PDEVMODEW
) Context
;
309 DPRINT("Found registry value for name %S: type %d, length %d\n",
310 ValueName
, ValueType
, ValueLength
);
312 if (REG_DWORD
== ValueType
&& sizeof(DWORD
) == ValueLength
)
314 if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.BitsPerPel"))
316 DevMode
->dmBitsPerPel
= *((DWORD
*) ValueData
);
318 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.Flags"))
320 DevMode
->dmDisplayFlags
= *((DWORD
*) ValueData
);
322 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.VRefresh"))
324 DevMode
->dmDisplayFrequency
= *((DWORD
*) ValueData
);
326 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.XPanning"))
328 DevMode
->dmPanningWidth
= *((DWORD
*) ValueData
);
330 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.XResolution"))
332 DevMode
->dmPelsWidth
= *((DWORD
*) ValueData
);
334 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.YPanning"))
336 DevMode
->dmPanningHeight
= *((DWORD
*) ValueData
);
338 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.YResolution"))
340 DevMode
->dmPelsHeight
= *((DWORD
*) ValueData
);
344 return STATUS_SUCCESS
;
348 SetupDevMode(PDEVMODEW DevMode
, ULONG DisplayNumber
)
350 static WCHAR RegistryMachineSystem
[] = L
"\\REGISTRY\\MACHINE\\SYSTEM\\";
351 static WCHAR CurrentControlSet
[] = L
"CURRENTCONTROLSET\\";
352 static WCHAR ControlSet
[] = L
"CONTROLSET";
353 static WCHAR Insert
[] = L
"Hardware Profiles\\Current\\System\\CurrentControlSet\\";
354 UNICODE_STRING RegistryPath
;
356 PWCHAR AfterControlSet
;
358 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
361 if (! GetRegistryPath(&RegistryPath
, DisplayNumber
))
363 DPRINT("GetRegistryPath failed\n");
367 Valid
= (0 == _wcsnicmp(RegistryPath
.Buffer
, RegistryMachineSystem
,
368 wcslen(RegistryMachineSystem
)));
371 AfterControlSet
= RegistryPath
.Buffer
+ wcslen(RegistryMachineSystem
);
372 if (0 == _wcsnicmp(AfterControlSet
, CurrentControlSet
, wcslen(CurrentControlSet
)))
374 AfterControlSet
+= wcslen(CurrentControlSet
);
376 else if (0 == _wcsnicmp(AfterControlSet
, ControlSet
, wcslen(ControlSet
)))
378 AfterControlSet
+= wcslen(ControlSet
);
379 while (L
'0' <= *AfterControlSet
&& L
'9' <= *AfterControlSet
)
383 Valid
= (L
'\\' == *AfterControlSet
);
394 ProfilePath
= ExAllocatePoolWithTag(PagedPool
,
395 (wcslen(RegistryPath
.Buffer
) +
396 wcslen(Insert
) + 1) * sizeof(WCHAR
),
398 if (NULL
!= ProfilePath
)
400 wcsncpy(ProfilePath
, RegistryPath
.Buffer
, AfterControlSet
- RegistryPath
.Buffer
);
401 wcscpy(ProfilePath
+ (AfterControlSet
- RegistryPath
.Buffer
), Insert
);
402 wcscat(ProfilePath
, AfterControlSet
);
404 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
405 QueryTable
[0].QueryRoutine
= DevModeCallback
;
406 QueryTable
[0].Flags
= 0;
407 QueryTable
[0].Name
= NULL
;
408 QueryTable
[0].EntryContext
= NULL
;
409 QueryTable
[0].DefaultType
= REG_NONE
;
410 QueryTable
[0].DefaultData
= NULL
;
411 QueryTable
[0].DefaultLength
= 0;
413 Status
= RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE
,
418 if (! NT_SUCCESS(Status
))
420 DPRINT("RtlQueryRegistryValues for %S failed with status 0x%08x\n",
421 ProfilePath
, Status
);
426 DPRINT("dmBitsPerPel %d dmDisplayFrequency %d dmPelsWidth %d dmPelsHeight %d\n",
427 DevMode
->dmBitsPerPel
, DevMode
->dmDisplayFrequency
,
428 DevMode
->dmPelsWidth
, DevMode
->dmPelsHeight
);
429 if (0 == DevMode
->dmBitsPerPel
|| 0 == DevMode
->dmDisplayFrequency
430 || 0 == DevMode
->dmPelsWidth
|| 0 == DevMode
->dmPelsHeight
)
432 DPRINT("Not all required devmode members are set\n");
437 ExFreePool(ProfilePath
);
446 DPRINT1("Unparsable registry path %S in DEVICEMAP\\VIDEO0", RegistryPath
.Buffer
);
449 RtlFreeUnicodeString(&RegistryPath
);
453 RtlZeroMemory(DevMode
, sizeof(DEVMODEW
));
460 IntCreatePrimarySurface()
462 PGD_ENABLEDRIVER GDEnableDriver
;
466 UNICODE_STRING DriverFileNames
;
472 for (DisplayNumber
= 0; ; DisplayNumber
++)
474 DPRINT("Trying to load display driver no. %d\n", DisplayNumber
);
476 RtlZeroMemory(&PrimarySurface
, sizeof(PrimarySurface
));
477 ExInitializeFastMutex(&PrimarySurface
.DriverLock
);
479 PrimarySurface
.VideoFileObject
= DRIVER_FindMPDriver(DisplayNumber
);
481 /* Open the miniport driver */
482 if (PrimarySurface
.VideoFileObject
== NULL
)
484 DPRINT1("FindMPDriver failed\n");
488 /* Retrieve DDI driver names from registry */
489 RtlInitUnicodeString(&DriverFileNames
, NULL
);
490 if (!FindDriverFileNames(&DriverFileNames
, DisplayNumber
))
492 DPRINT1("FindDriverFileNames failed\n");
498 * DriverFileNames may be a list of drivers in REG_SZ_MULTI format,
499 * scan all of them until a good one found.
501 CurrentName
= DriverFileNames
.Buffer
;
504 CurrentName
< DriverFileNames
.Buffer
+ DriverFileNames
.Length
)
506 /* Get the DDI driver's entry point */
507 GDEnableDriver
= DRIVER_FindDDIDriver(CurrentName
);
508 if (NULL
== GDEnableDriver
)
510 DPRINT("FindDDIDriver failed for %S\n", CurrentName
);
514 /* Call DDI driver's EnableDriver function */
515 RtlZeroMemory(&DED
, sizeof(DED
));
517 if (! GDEnableDriver(DDI_DRIVER_VERSION_NT5_01
, sizeof(DED
), &DED
))
519 DPRINT("DrvEnableDriver failed for %S\n", CurrentName
);
529 /* Skip to the next name but never get past the Unicode string */
530 while (L
'\0' != *CurrentName
&&
531 CurrentName
< DriverFileNames
.Buffer
+ DriverFileNames
.Length
)
535 if (CurrentName
< DriverFileNames
.Buffer
+ DriverFileNames
.Length
)
542 RtlFreeUnicodeString(&DriverFileNames
);
546 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
547 DPRINT1("No suitable DDI driver found\n");
552 DPRINT("Display driver %S loaded\n", CurrentName
);
554 DPRINT("Building DDI Functions\n");
556 /* Construct DDI driver function dispatch table */
557 if (!DRIVER_BuildDDIFunctions(&DED
, &PrimarySurface
.DriverFunctions
))
559 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
560 DPRINT1("BuildDDIFunctions failed\n");
564 /* Allocate a phyical device handle from the driver */
565 if (SetupDevMode(&PrimarySurface
.DMW
, DisplayNumber
))
567 PrimarySurface
.PDev
= PrimarySurface
.DriverFunctions
.EnablePDev(
571 PrimarySurface
.FillPatterns
,
572 sizeof(PrimarySurface
.GDIInfo
),
573 (ULONG
*) &PrimarySurface
.GDIInfo
,
574 sizeof(PrimarySurface
.DevInfo
),
575 &PrimarySurface
.DevInfo
,
578 (HANDLE
) (PrimarySurface
.VideoFileObject
->DeviceObject
));
579 DoDefault
= (NULL
== PrimarySurface
.PDev
);
582 DPRINT1("DrvEnablePDev with registry parameters failed\n");
592 RtlZeroMemory(&(PrimarySurface
.DMW
), sizeof(DEVMODEW
));
593 PrimarySurface
.PDev
= PrimarySurface
.DriverFunctions
.EnablePDev(
597 PrimarySurface
.FillPatterns
,
598 sizeof(PrimarySurface
.GDIInfo
),
599 (ULONG
*) &PrimarySurface
.GDIInfo
,
600 sizeof(PrimarySurface
.DevInfo
),
601 &PrimarySurface
.DevInfo
,
604 (HANDLE
) (PrimarySurface
.VideoFileObject
->DeviceObject
));
606 if (NULL
== PrimarySurface
.PDev
)
608 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
609 DPRINT1("DrvEnablePDEV with default parameters failed\n");
610 DPRINT1("Perhaps DDI driver doesn't match miniport driver?\n");
616 if (0 == PrimarySurface
.GDIInfo
.ulLogPixelsX
)
618 DPRINT("Adjusting GDIInfo.ulLogPixelsX\n");
619 PrimarySurface
.GDIInfo
.ulLogPixelsX
= 96;
621 if (0 == PrimarySurface
.GDIInfo
.ulLogPixelsY
)
623 DPRINT("Adjusting GDIInfo.ulLogPixelsY\n");
624 PrimarySurface
.GDIInfo
.ulLogPixelsY
= 96;
627 DPRINT("calling completePDev\n");
629 /* Complete initialization of the physical device */
630 PrimarySurface
.DriverFunctions
.CompletePDev(
632 (HDEV
)&PrimarySurface
);
634 DPRINT("calling DRIVER_ReferenceDriver\n");
636 DRIVER_ReferenceDriver(L
"DISPLAY");
638 DPRINT("calling EnableSurface\n");
640 /* Enable the drawing surface */
641 PrimarySurface
.Handle
=
642 PrimarySurface
.DriverFunctions
.EnableSurface(PrimarySurface
.PDev
);
643 if (NULL
== PrimarySurface
.Handle
)
645 /* PrimarySurface.DriverFunctions.AssertMode(PrimarySurface.PDev, FALSE);*/
646 PrimarySurface
.DriverFunctions
.DisablePDev(PrimarySurface
.PDev
);
647 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
648 DPRINT1("DrvEnableSurface failed\n");
653 SurfObj
= (SURFOBJ
*)AccessUserObject((ULONG
) PrimarySurface
.Handle
);
654 SurfObj
->dhpdev
= PrimarySurface
.PDev
;
655 SurfGDI
= (PSURFGDI
)AccessInternalObject((ULONG
) PrimarySurface
.Handle
);
657 IntGetActiveDesktop(),
658 SurfGDI
->SurfObj
.sizlBitmap
.cx
,
659 SurfGDI
->SurfObj
.sizlBitmap
.cy
);
667 IntDestroyPrimarySurface()
674 DRIVER_UnreferenceDriver(L
"DISPLAY");
677 DPRINT("Hiding mouse pointer\n" );
678 SurfObj
= (SURFOBJ
*)AccessUserObject((ULONG
) PrimarySurface
.Handle
);
679 SurfGDI
= (PSURFGDI
)AccessInternalObject((ULONG
) PrimarySurface
.Handle
);
680 SurfGDI
->SetPointerShape(SurfObj
, NULL
, NULL
, NULL
, 0, 0, 0, 0, 0, 0);
682 DPRINT("Reseting display\n" );
683 PrimarySurface
.DriverFunctions
.AssertMode(PrimarySurface
.PDev
, FALSE
);
684 PrimarySurface
.DriverFunctions
.DisableSurface(PrimarySurface
.PDev
);
685 PrimarySurface
.DriverFunctions
.DisablePDev(PrimarySurface
.PDev
);
689 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
693 IntGdiCreateDC(PUNICODE_STRING Driver
,
694 PUNICODE_STRING Device
,
695 PUNICODE_STRING Output
,
696 CONST PDEVMODEW InitData
)
703 UNICODE_STRING StdDriver
;
705 RtlInitUnicodeString(&StdDriver
, L
"DISPLAY");
707 if (NULL
== Driver
|| 0 == RtlCompareUnicodeString(Driver
, &StdDriver
, TRUE
))
709 if (! IntGraphicsCheck(TRUE
))
711 DPRINT1("Unable to initialize graphics, returning NULL dc\n");
716 /* Check for existing DC object */
717 if ((hNewDC
= DC_FindOpenDC(Driver
)) != NULL
)
720 return NtGdiCreateCompatableDC(hDC
);
723 if (Driver
!= NULL
&& Driver
->Buffer
!= NULL
)
725 DPRINT("NAME: %S\n", Driver
->Buffer
); // FIXME: Should not crash if NULL
728 /* Allocate a DC object */
729 if ((hNewDC
= DC_AllocDC(Driver
)) == NULL
)
734 NewDC
= DC_LockDc( hNewDC
);
737 NewDC
->DMW
= PrimarySurface
.DMW
;
738 NewDC
->DevInfo
= &PrimarySurface
.DevInfo
;
739 NewDC
->GDIInfo
= &PrimarySurface
.GDIInfo
;
740 memcpy(NewDC
->FillPatternSurfaces
, PrimarySurface
.FillPatterns
,
741 sizeof(NewDC
->FillPatternSurfaces
));
742 NewDC
->PDev
= PrimarySurface
.PDev
;
743 NewDC
->Surface
= PrimarySurface
.Handle
;
744 NewDC
->GDIDevice
= (HDEV
)&PrimarySurface
;
745 NewDC
->DriverFunctions
= PrimarySurface
.DriverFunctions
;
747 NewDC
->DMW
.dmSize
= sizeof(NewDC
->DMW
);
748 NewDC
->DMW
.dmFields
= 0x000fc000;
750 /* FIXME: get mode selection information from somewhere */
752 NewDC
->DMW
.dmLogPixels
= 96;
753 SurfGDI
= (PSURFGDI
)AccessInternalObject((ULONG
) PrimarySurface
.Handle
);
754 NewDC
->DMW
.dmBitsPerPel
= SurfGDI
->BitsPerPixel
;
755 NewDC
->DMW
.dmPelsWidth
= SurfGDI
->SurfObj
.sizlBitmap
.cx
;
756 NewDC
->DMW
.dmPelsHeight
= SurfGDI
->SurfObj
.sizlBitmap
.cy
;
757 NewDC
->DMW
.dmDisplayFlags
= 0;
758 NewDC
->DMW
.dmDisplayFrequency
= 0;
760 NewDC
->w
.bitsPerPixel
= SurfGDI
->BitsPerPixel
; // FIXME: set this here??
762 NewDC
->w
.hPalette
= NewDC
->DevInfo
->hpalDefault
;
764 DPRINT("Bits per pel: %u\n", NewDC
->w
.bitsPerPixel
);
766 DC_UnlockDc( hNewDC
);
768 hVisRgn
= NtGdiCreateRectRgn(0, 0, SurfGDI
->SurfObj
.sizlBitmap
.cx
,
769 SurfGDI
->SurfObj
.sizlBitmap
.cy
);
770 NtGdiSelectVisRgn(hNewDC
, hVisRgn
);
771 NtGdiDeleteObject(hVisRgn
);
773 /* Initialize the DC state */
775 NtGdiSetTextColor(hNewDC
, RGB(0, 0, 0));
776 NtGdiSetTextAlign(hNewDC
, TA_TOP
);
777 NtGdiSetBkColor(hNewDC
, RGB(255, 255, 255));
778 NtGdiSetBkMode(hNewDC
, OPAQUE
);
784 NtGdiCreateDC(PUNICODE_STRING Driver
,
785 PUNICODE_STRING Device
,
786 PUNICODE_STRING Output
,
787 CONST PDEVMODEW InitData
)
789 UNICODE_STRING SafeDriver
, SafeDevice
;
790 DEVMODEW SafeInitData
;
796 Status
= MmCopyFromCaller(&SafeInitData
, InitData
, sizeof(DEVMODEW
));
797 if(!NT_SUCCESS(Status
))
799 SetLastNtError(Status
);
802 /* FIXME - InitData can have some more bytes! */
807 Status
= IntSafeCopyUnicodeString(&SafeDriver
, Driver
);
808 if(!NT_SUCCESS(Status
))
810 SetLastNtError(Status
);
817 Status
= IntSafeCopyUnicodeString(&SafeDevice
, Device
);
818 if(!NT_SUCCESS(Status
))
820 RtlFreeUnicodeString(&SafeDriver
);
821 SetLastNtError(Status
);
826 Ret
= IntGdiCreateDC(&SafeDriver
, &SafeDevice
, NULL
, &SafeInitData
);
832 NtGdiCreateIC(PUNICODE_STRING Driver
,
833 PUNICODE_STRING Device
,
834 PUNICODE_STRING Output
,
835 CONST PDEVMODEW DevMode
)
837 /* FIXME: this should probably do something else... */
838 return NtGdiCreateDC(Driver
, Device
, Output
, DevMode
);
842 NtGdiDeleteDC(HDC DCHandle
)
846 DCToDelete
= DC_LockDc(DCHandle
);
847 if (DCToDelete
== NULL
)
851 DPRINT( "Deleting DC\n" );
853 /* First delete all saved DCs */
854 while (DCToDelete
->saveLevel
)
859 savedHDC
= DC_GetNextDC (DCToDelete
);
860 savedDC
= DC_LockDc (savedHDC
);
865 DC_SetNextDC (DCToDelete
, DC_GetNextDC (savedDC
));
866 DCToDelete
->saveLevel
--;
867 DC_UnlockDc( savedHDC
);
868 NtGdiDeleteDC (savedHDC
);
871 /* Free GDI resources allocated to this DC */
872 if (!(DCToDelete
->w
.flags
& DC_SAVED
))
875 NtGdiSelectObject (DCHandle, STOCK_BLACK_PEN);
876 NtGdiSelectObject (DCHandle, STOCK_WHITE_BRUSH);
877 NtGdiSelectObject (DCHandle, STOCK_SYSTEM_FONT);
878 DC_LockDC (DCHandle); NtGdiSelectObject does not recognize stock objects yet */
879 if (DCToDelete
->w
.flags
& DC_MEMORY
)
881 EngDeleteSurface (DCToDelete
->Surface
);
882 NtGdiDeleteObject (DCToDelete
->w
.hFirstBitmap
);
885 if (DCToDelete
->w
.hClipRgn
)
887 NtGdiDeleteObject (DCToDelete
->w
.hClipRgn
);
889 if (DCToDelete
->w
.hVisRgn
)
891 NtGdiDeleteObject (DCToDelete
->w
.hVisRgn
);
893 if (NULL
!= DCToDelete
->CombinedClip
)
895 IntEngDeleteClipRegion(DCToDelete
->CombinedClip
);
897 if (DCToDelete
->w
.hGCClipRgn
)
899 NtGdiDeleteObject (DCToDelete
->w
.hGCClipRgn
);
902 PATH_DestroyGdiPath (&DCToDelete
->w
.path
);
904 DC_UnlockDc( DCHandle
);
905 DC_FreeDC ( DCHandle
);
911 NtGdiDrawEscape(HDC hDC
,
920 NtGdiEnumObjects(HDC hDC
,
922 GOBJENUMPROC ObjectFunc
,
928 DC_GET_VAL( COLORREF
, NtGdiGetBkColor
, w
.backgroundColor
)
929 DC_GET_VAL( INT
, NtGdiGetBkMode
, w
.backgroundMode
)
930 DC_GET_VAL_EX( GetBrushOrgEx
, w
.brushOrgX
, w
.brushOrgY
, POINT
, x
, y
)
931 DC_GET_VAL( HRGN
, NtGdiGetClipRgn
, w
.hClipRgn
)
934 NtGdiGetCurrentObject(HDC hDC
, UINT ObjectType
)
939 if(!(dc
= DC_LockDc(hDC
)))
941 SetLastWin32Error(ERROR_INVALID_HANDLE
);
948 SelObject
= dc
->w
.hPen
;
951 SelObject
= dc
->w
.hBrush
;
954 DPRINT1("FIXME: NtGdiGetCurrentObject() ObjectType OBJ_PAL not supported yet!\n");
957 SelObject
= dc
->w
.hFont
;
960 SelObject
= dc
->w
.hBitmap
;
963 DPRINT1("FIXME: NtGdiGetCurrentObject() ObjectType OBJ_COLORSPACE not supported yet!\n");
967 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
975 DC_GET_VAL_EX ( GetCurrentPositionEx
, w
.CursPosX
, w
.CursPosY
, POINT
, x
, y
)
978 IntGdiGetDCOrgEx(DC
*dc
, LPPOINT Point
)
980 Point
->x
= dc
->w
.DCOrgX
;
981 Point
->y
= dc
->w
.DCOrgY
;
987 NtGdiGetDCOrgEx(HDC hDC
, LPPOINT Point
)
996 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1000 dc
= DC_LockDc(hDC
);
1003 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1007 Ret
= IntGdiGetDCOrgEx(dc
, &SafePoint
);
1009 Status
= MmCopyToCaller(Point
, &SafePoint
, sizeof(POINT
));
1010 if(!NT_SUCCESS(Status
))
1012 SetLastNtError(Status
);
1022 NtGdiSetBkColor(HDC hDC
, COLORREF color
)
1028 if (!(dc
= DC_LockDc(hDC
)))
1030 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1034 oldColor
= dc
->w
.backgroundColor
;
1035 dc
->w
.backgroundColor
= color
;
1036 hBrush
= dc
->w
.hBrush
;
1037 DC_UnlockDc ( hDC
);
1038 NtGdiSelectObject(hDC
, hBrush
);
1043 NtGdiGetDCState(HDC hDC
)
1048 dc
= DC_LockDc(hDC
);
1051 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1055 hnewdc
= DC_AllocDC(NULL
);
1061 newdc
= DC_LockDc( hnewdc
);
1064 newdc
->w
.flags
= dc
->w
.flags
| DC_SAVED
;
1065 newdc
->w
.hPen
= dc
->w
.hPen
;
1066 newdc
->w
.hBrush
= dc
->w
.hBrush
;
1067 newdc
->w
.hFont
= dc
->w
.hFont
;
1068 newdc
->w
.hBitmap
= dc
->w
.hBitmap
;
1069 newdc
->w
.hFirstBitmap
= dc
->w
.hFirstBitmap
;
1071 newdc
->w
.hDevice
= dc
->w
.hDevice
;
1073 newdc
->w
.hPalette
= dc
->w
.hPalette
;
1074 newdc
->w
.totalExtent
= dc
->w
.totalExtent
;
1075 newdc
->w
.bitsPerPixel
= dc
->w
.bitsPerPixel
;
1076 newdc
->w
.ROPmode
= dc
->w
.ROPmode
;
1077 newdc
->w
.polyFillMode
= dc
->w
.polyFillMode
;
1078 newdc
->w
.stretchBltMode
= dc
->w
.stretchBltMode
;
1079 newdc
->w
.relAbsMode
= dc
->w
.relAbsMode
;
1080 newdc
->w
.backgroundMode
= dc
->w
.backgroundMode
;
1081 newdc
->w
.backgroundColor
= dc
->w
.backgroundColor
;
1082 newdc
->w
.textColor
= dc
->w
.textColor
;
1083 newdc
->w
.brushOrgX
= dc
->w
.brushOrgX
;
1084 newdc
->w
.brushOrgY
= dc
->w
.brushOrgY
;
1085 newdc
->w
.textAlign
= dc
->w
.textAlign
;
1086 newdc
->w
.charExtra
= dc
->w
.charExtra
;
1087 newdc
->w
.breakTotalExtra
= dc
->w
.breakTotalExtra
;
1088 newdc
->w
.breakCount
= dc
->w
.breakCount
;
1089 newdc
->w
.breakExtra
= dc
->w
.breakExtra
;
1090 newdc
->w
.breakRem
= dc
->w
.breakRem
;
1091 newdc
->w
.MapMode
= dc
->w
.MapMode
;
1092 newdc
->w
.GraphicsMode
= dc
->w
.GraphicsMode
;
1094 /* Apparently, the DC origin is not changed by [GS]etDCState */
1095 newdc
->w
.DCOrgX
= dc
->w
.DCOrgX
;
1096 newdc
->w
.DCOrgY
= dc
->w
.DCOrgY
;
1098 newdc
->w
.CursPosX
= dc
->w
.CursPosX
;
1099 newdc
->w
.CursPosY
= dc
->w
.CursPosY
;
1100 newdc
->w
.ArcDirection
= dc
->w
.ArcDirection
;
1101 newdc
->w
.xformWorld2Wnd
= dc
->w
.xformWorld2Wnd
;
1102 newdc
->w
.xformWorld2Vport
= dc
->w
.xformWorld2Vport
;
1103 newdc
->w
.xformVport2World
= dc
->w
.xformVport2World
;
1104 newdc
->w
.vport2WorldValid
= dc
->w
.vport2WorldValid
;
1105 newdc
->wndOrgX
= dc
->wndOrgX
;
1106 newdc
->wndOrgY
= dc
->wndOrgY
;
1107 newdc
->wndExtX
= dc
->wndExtX
;
1108 newdc
->wndExtY
= dc
->wndExtY
;
1109 newdc
->vportOrgX
= dc
->vportOrgX
;
1110 newdc
->vportOrgY
= dc
->vportOrgY
;
1111 newdc
->vportExtX
= dc
->vportExtX
;
1112 newdc
->vportExtY
= dc
->vportExtY
;
1114 newdc
->hSelf
= hnewdc
;
1115 newdc
->saveLevel
= 0;
1118 PATH_InitGdiPath( &newdc
->w
.path
);
1121 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
1123 newdc
->w
.hGCClipRgn
= newdc
->w
.hVisRgn
= 0;
1126 newdc
->w
.hClipRgn
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
1127 NtGdiCombineRgn( newdc
->w
.hClipRgn
, dc
->w
.hClipRgn
, 0, RGN_COPY
);
1129 DC_UnlockDc( hnewdc
);
1137 NtGdiSetDCState ( HDC hDC
, HDC hDCSave
)
1141 dc
= DC_LockDc ( hDC
);
1144 dcs
= DC_LockDc ( hDCSave
);
1147 if ( dcs
->w
.flags
& DC_SAVED
)
1149 dc
->w
.flags
= dcs
->w
.flags
& ~DC_SAVED
;
1151 dc
->w
.hFirstBitmap
= dcs
->w
.hFirstBitmap
;
1154 dc
->w
.hDevice
= dcs
->w
.hDevice
;
1157 dc
->w
.totalExtent
= dcs
->w
.totalExtent
;
1158 dc
->w
.ROPmode
= dcs
->w
.ROPmode
;
1159 dc
->w
.polyFillMode
= dcs
->w
.polyFillMode
;
1160 dc
->w
.stretchBltMode
= dcs
->w
.stretchBltMode
;
1161 dc
->w
.relAbsMode
= dcs
->w
.relAbsMode
;
1162 dc
->w
.backgroundMode
= dcs
->w
.backgroundMode
;
1163 dc
->w
.backgroundColor
= dcs
->w
.backgroundColor
;
1164 dc
->w
.textColor
= dcs
->w
.textColor
;
1165 dc
->w
.brushOrgX
= dcs
->w
.brushOrgX
;
1166 dc
->w
.brushOrgY
= dcs
->w
.brushOrgY
;
1167 dc
->w
.textAlign
= dcs
->w
.textAlign
;
1168 dc
->w
.charExtra
= dcs
->w
.charExtra
;
1169 dc
->w
.breakTotalExtra
= dcs
->w
.breakTotalExtra
;
1170 dc
->w
.breakCount
= dcs
->w
.breakCount
;
1171 dc
->w
.breakExtra
= dcs
->w
.breakExtra
;
1172 dc
->w
.breakRem
= dcs
->w
.breakRem
;
1173 dc
->w
.MapMode
= dcs
->w
.MapMode
;
1174 dc
->w
.GraphicsMode
= dcs
->w
.GraphicsMode
;
1176 /* Apparently, the DC origin is not changed by [GS]etDCState */
1177 dc
->w
.DCOrgX
= dcs
->w
.DCOrgX
;
1178 dc
->w
.DCOrgY
= dcs
->w
.DCOrgY
;
1180 dc
->w
.CursPosX
= dcs
->w
.CursPosX
;
1181 dc
->w
.CursPosY
= dcs
->w
.CursPosY
;
1182 dc
->w
.ArcDirection
= dcs
->w
.ArcDirection
;
1184 dc
->w
.xformWorld2Wnd
= dcs
->w
.xformWorld2Wnd
;
1185 dc
->w
.xformWorld2Vport
= dcs
->w
.xformWorld2Vport
;
1186 dc
->w
.xformVport2World
= dcs
->w
.xformVport2World
;
1187 dc
->w
.vport2WorldValid
= dcs
->w
.vport2WorldValid
;
1189 dc
->wndOrgX
= dcs
->wndOrgX
;
1190 dc
->wndOrgY
= dcs
->wndOrgY
;
1191 dc
->wndExtX
= dcs
->wndExtX
;
1192 dc
->wndExtY
= dcs
->wndExtY
;
1193 dc
->vportOrgX
= dcs
->vportOrgX
;
1194 dc
->vportOrgY
= dcs
->vportOrgY
;
1195 dc
->vportExtX
= dcs
->vportExtX
;
1196 dc
->vportExtY
= dcs
->vportExtY
;
1198 if (!(dc
->w
.flags
& DC_MEMORY
))
1200 dc
->w
.bitsPerPixel
= dcs
->w
.bitsPerPixel
;
1204 if (dcs
->w
.hClipRgn
)
1206 if (!dc
->w
.hClipRgn
)
1208 dc
->w
.hClipRgn
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
1210 NtGdiCombineRgn( dc
->w
.hClipRgn
, dcs
->w
.hClipRgn
, 0, RGN_COPY
);
1216 NtGdiDeleteObject( dc
->w
.hClipRgn
);
1221 CLIPPING_UpdateGCRegion( dc
);
1222 DC_UnlockDc ( hDC
);
1224 DC_UnlockDc ( hDC
);
1225 NtGdiSelectClipRgn(hDC
, dcs
->w
.hClipRgn
);
1228 NtGdiSelectObject( hDC
, dcs
->w
.hBitmap
);
1229 NtGdiSelectObject( hDC
, dcs
->w
.hBrush
);
1230 NtGdiSelectObject( hDC
, dcs
->w
.hFont
);
1231 NtGdiSelectObject( hDC
, dcs
->w
.hPen
);
1232 NtGdiSetBkColor( hDC
, dcs
->w
.backgroundColor
);
1233 NtGdiSetTextColor( hDC
, dcs
->w
.textColor
);
1235 NtGdiSelectPalette( hDC
, dcs
->w
.hPalette
, FALSE
);
1238 GDISelectPalette16( hDC
, dcs
->w
.hPalette
, FALSE
);
1243 DC_UnlockDc ( hDCSave
);
1245 DC_UnlockDc ( hDC
);
1246 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1250 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1254 NtGdiGetDeviceCaps(HDC hDC
,
1261 dc
= DC_LockDc(hDC
);
1264 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1268 /* Retrieve capability */
1272 ret
= dc
->GDIInfo
->ulVersion
;
1276 ret
= dc
->GDIInfo
->ulTechnology
;
1280 ret
= dc
->GDIInfo
->ulHorzSize
;
1284 ret
= dc
->GDIInfo
->ulVertSize
;
1288 ret
= dc
->GDIInfo
->ulHorzRes
;
1292 ret
= dc
->GDIInfo
->ulVertRes
;
1296 ret
= dc
->GDIInfo
->ulLogPixelsX
;
1300 ret
= dc
->GDIInfo
->ulLogPixelsY
;
1304 ret
= dc
->GDIInfo
->cBitsPixel
;
1308 ret
= dc
->GDIInfo
->cPlanes
;
1312 UNIMPLEMENTED
; /* FIXME */
1316 UNIMPLEMENTED
; /* FIXME */
1320 UNIMPLEMENTED
; /* FIXME */
1324 ret
= dc
->GDIInfo
->ulNumColors
;
1328 ret
= dc
->GDIInfo
->ulAspectX
;
1332 ret
= dc
->GDIInfo
->ulAspectY
;
1336 ret
= dc
->GDIInfo
->ulAspectXY
;
1340 UNIMPLEMENTED
; /* FIXME */
1344 UNIMPLEMENTED
; /* FIXME */
1348 ret
= dc
->GDIInfo
->ulNumPalReg
; /* FIXME not sure */
1356 UNIMPLEMENTED
; /* FIXME */
1360 if(NtGdiEscape(hDC
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0)
1370 case PHYSICALHEIGHT
:
1371 if(NtGdiEscape(hDC
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0)
1381 case PHYSICALOFFSETX
:
1382 if(NtGdiEscape(hDC
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0)
1392 case PHYSICALOFFSETY
:
1393 if(NtGdiEscape(hDC
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0)
1404 UNIMPLEMENTED
; /* FIXME */
1407 case SCALINGFACTORX
:
1408 if(NtGdiEscape(hDC
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0)
1418 case SCALINGFACTORY
:
1419 if(NtGdiEscape(hDC
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0)
1430 ret
= dc
->GDIInfo
->flRaster
;
1434 UNIMPLEMENTED
; /* FIXME */
1438 UNIMPLEMENTED
; /* FIXME */
1442 UNIMPLEMENTED
; /* FIXME */
1446 ret
= dc
->GDIInfo
->flTextCaps
;
1454 DPRINT("(%04x,%d): returning %d\n", hDC
, Index
, ret
);
1460 DC_GET_VAL( INT
, NtGdiGetMapMode
, w
.MapMode
)
1461 DC_GET_VAL( INT
, NtGdiGetPolyFillMode
, w
.polyFillMode
)
1464 IntGdiGetObject(HANDLE Handle
, INT Count
, LPVOID Buffer
)
1466 PGDIOBJHDR GdiObject
;
1470 GdiObject
= GDIOBJ_LockObj(Handle
, GDI_OBJECT_TYPE_DONTCARE
);
1471 if (NULL
== GdiObject
)
1473 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1477 ObjectType
= GDIOBJ_GetObjectType(Handle
);
1481 case GDI_OBJECT_TYPE_PEN
:
1482 Result
= PEN_GetObject((PENOBJ
*) GdiObject
, Count
, Buffer
);
1484 case GDI_OBJECT_TYPE_BRUSH
:
1485 Result
= BRUSH_GetObject((BRUSHOBJ
*) GdiObject
, Count
, Buffer
);
1488 case GDI_OBJECT_TYPE_BITMAP
:
1489 Result
= BITMAP_GetObject((BITMAPOBJ
*) GdiObject
, Count
, Buffer
);
1491 case GDI_OBJECT_TYPE_FONT
:
1492 Result
= FontGetObject((PTEXTOBJ
) GdiObject
, Count
, Buffer
);
1494 // Fix the LOGFONT structure for the stock fonts
1495 if (FIRST_STOCK_HANDLE
<= Handle
&& Handle
<= LAST_STOCK_HANDLE
)
1497 FixStockFontSizeW(Handle
, Count
, Buffer
);
1502 case GDI_OBJECT_TYPE_PALETTE
:
1503 Result
= PALETTE_GetObject((PALETTEOBJ
*) GdiObject
, Count
, Buffer
);
1507 DPRINT1("GDI object type 0x%08x not implemented\n", ObjectType
);
1511 GDIOBJ_UnlockObj(Handle
, GDI_OBJECT_TYPE_DONTCARE
);
1517 NtGdiGetObject(HANDLE handle
, INT count
, LPVOID buffer
)
1528 SafeBuf
= ExAllocatePoolWithTag(NonPagedPool
, count
, TAG_GDIOBJ
);
1531 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1535 Ret
= IntGdiGetObject(handle
, count
, SafeBuf
);
1537 Status
= MmCopyToCaller(buffer
, SafeBuf
, count
);
1538 ExFreePool(SafeBuf
);
1539 if(!NT_SUCCESS(Status
))
1541 SetLastNtError(Status
);
1549 NtGdiGetObjectType(HANDLE handle
)
1555 ptr
= GDIOBJ_LockObj(handle
, GDI_OBJECT_TYPE_DONTCARE
);
1558 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1562 objectType
= GDIOBJ_GetObjectType(handle
);
1565 case GDI_OBJECT_TYPE_PEN
:
1568 case GDI_OBJECT_TYPE_BRUSH
:
1571 case GDI_OBJECT_TYPE_BITMAP
:
1572 result
= OBJ_BITMAP
;
1574 case GDI_OBJECT_TYPE_FONT
:
1577 case GDI_OBJECT_TYPE_PALETTE
:
1580 case GDI_OBJECT_TYPE_REGION
:
1581 result
= OBJ_REGION
;
1583 case GDI_OBJECT_TYPE_DC
:
1586 case GDI_OBJECT_TYPE_METADC
:
1587 result
= OBJ_METADC
;
1589 case GDI_OBJECT_TYPE_METAFILE
:
1590 result
= OBJ_METAFILE
;
1592 case GDI_OBJECT_TYPE_ENHMETAFILE
:
1593 result
= OBJ_ENHMETAFILE
;
1595 case GDI_OBJECT_TYPE_ENHMETADC
:
1596 result
= OBJ_ENHMETADC
;
1598 case GDI_OBJECT_TYPE_EXTPEN
:
1599 result
= OBJ_EXTPEN
;
1601 case GDI_OBJECT_TYPE_MEMDC
:
1605 DPRINT1("Magic 0x%08x not implemented\n", objectType
);
1608 GDIOBJ_UnlockObj(handle
, GDI_OBJECT_TYPE_DONTCARE
);
1612 DC_GET_VAL( INT
, NtGdiGetRelAbs
, w
.relAbsMode
)
1613 DC_GET_VAL( INT
, NtGdiGetROP2
, w
.ROPmode
)
1614 DC_GET_VAL( INT
, NtGdiGetStretchBltMode
, w
.stretchBltMode
)
1615 DC_GET_VAL( UINT
, NtGdiGetTextAlign
, w
.textAlign
)
1616 DC_GET_VAL( COLORREF
, NtGdiGetTextColor
, w
.textColor
)
1617 DC_GET_VAL_EX( GetViewportExtEx
, vportExtX
, vportExtY
, SIZE
, cx
, cy
)
1618 DC_GET_VAL_EX( GetViewportOrgEx
, vportOrgX
, vportOrgY
, POINT
, x
, y
)
1619 DC_GET_VAL_EX( GetWindowExtEx
, wndExtX
, wndExtY
, SIZE
, cx
, cy
)
1620 DC_GET_VAL_EX( GetWindowOrgEx
, wndOrgX
, wndOrgY
, POINT
, x
, y
)
1623 NtGdiResetDC(HDC hDC
, CONST DEVMODEW
*InitData
)
1629 NtGdiRestoreDC(HDC hDC
, INT SaveLevel
)
1634 DPRINT("NtGdiRestoreDC(%lx, %d)\n", hDC
, SaveLevel
);
1636 dc
= DC_LockDc(hDC
);
1639 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1643 if (SaveLevel
== -1)
1644 SaveLevel
= dc
->saveLevel
;
1646 if ((SaveLevel
< 1) || (SaveLevel
> dc
->saveLevel
))
1650 while (dc
->saveLevel
>= SaveLevel
)
1652 HDC hdcs
= DC_GetNextDC (dc
);
1654 dcs
= DC_LockDc (hdcs
);
1659 DC_SetNextDC (dcs
, DC_GetNextDC (dcs
));
1660 if (--dc
->saveLevel
< SaveLevel
)
1663 DC_UnlockDc( hdcs
);
1664 NtGdiSetDCState(hDC
, hdcs
);
1666 if (!PATH_AssignGdiPath( &dc
->w
.path
, &dcs
->w
.path
))
1668 /* FIXME: This might not be quite right, since we're
1669 * returning FALSE but still destroying the saved DC state */
1673 dc
= DC_LockDc(hDC
);
1681 DC_UnlockDc( hdcs
);
1683 NtGdiDeleteDC (hdcs
);
1690 NtGdiSaveDC(HDC hDC
)
1696 DPRINT("NtGdiSaveDC(%lx)\n", hDC
);
1698 if (!(hdcs
= NtGdiGetDCState(hDC
)))
1703 dcs
= DC_LockDc (hdcs
);
1706 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1709 dc
= DC_LockDc (hDC
);
1713 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1718 /* Copy path. The reason why path saving / restoring is in SaveDC/
1719 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
1720 * functions are only in Win16 (which doesn't have paths) and that
1721 * SetDCState doesn't allow us to signal an error (which can happen
1722 * when copying paths).
1724 if (!PATH_AssignGdiPath (&dcs
->w
.path
, &dc
->w
.path
))
1726 NtGdiDeleteDC (hdcs
);
1731 DC_SetNextDC (dcs
, DC_GetNextDC (dc
));
1732 DC_SetNextDC (dc
, hdcs
);
1733 ret
= ++dc
->saveLevel
;
1734 DC_UnlockDc( hdcs
);
1742 NtGdiSelectObject(HDC hDC
, HGDIOBJ hGDIObj
)
1744 HGDIOBJ objOrg
= NULL
; // default to failure
1753 COLORREF MonoColorMap
[2];
1754 ULONG NumColors
, Index
;
1758 if(!hDC
|| !hGDIObj
) return NULL
;
1760 dc
= DC_LockDc(hDC
);
1763 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1767 objectType
= GDIOBJ_GetObjectType(hGDIObj
);
1771 case GDI_OBJECT_TYPE_PEN
:
1773 /* Convert the color of the pen to the format of the DC */
1774 PalGDI
= PALETTE_LockPalette(dc
->w
.hPalette
);
1777 Mode
= PalGDI
->Mode
;
1778 PALETTE_UnlockPalette(dc
->w
.hPalette
);
1779 XlateObj
= (XLATEOBJ
*)IntEngCreateXlate(Mode
, PAL_RGB
, dc
->w
.hPalette
, NULL
);
1780 if (NULL
!= XlateObj
)
1782 pen
= PENOBJ_LockPen((HPEN
) hGDIObj
);
1785 if (pen
->flAttrs
& GDIBRUSH_IS_SOLID
)
1787 pen
->BrushObject
.iSolidColor
=
1788 XLATEOBJ_iXlate(XlateObj
, pen
->BrushAttr
.lbColor
);
1792 pen
->BrushObject
.iSolidColor
= 0xFFFFFFFF;
1794 pen
->crBack
= XLATEOBJ_iXlate(XlateObj
, dc
->w
.backgroundColor
);
1795 pen
->crFore
= XLATEOBJ_iXlate(XlateObj
, dc
->w
.textColor
);
1796 PENOBJ_UnlockPen((HPEN
) hGDIObj
);
1797 objOrg
= (HGDIOBJ
)dc
->w
.hPen
;
1798 dc
->w
.hPen
= hGDIObj
;
1802 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1804 EngDeleteXlate(XlateObj
);
1808 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
1813 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1817 case GDI_OBJECT_TYPE_BRUSH
:
1819 /* Convert the color of the brush to the format of the DC */
1820 PalGDI
= PALETTE_LockPalette(dc
->w
.hPalette
);
1823 Mode
= PalGDI
->Mode
;
1824 PALETTE_UnlockPalette(dc
->w
.hPalette
);
1825 XlateObj
= (XLATEOBJ
*)IntEngCreateXlate(Mode
, PAL_RGB
, dc
->w
.hPalette
, NULL
);
1826 if (NULL
!= XlateObj
)
1828 brush
= BRUSHOBJ_LockBrush((HBRUSH
) hGDIObj
);
1831 if (brush
->flAttrs
& GDIBRUSH_IS_SOLID
)
1833 brush
->BrushObject
.iSolidColor
=
1834 XLATEOBJ_iXlate(XlateObj
, brush
->BrushAttr
.lbColor
);
1838 brush
->BrushObject
.iSolidColor
= 0xFFFFFFFF;
1840 brush
->crBack
= XLATEOBJ_iXlate(XlateObj
, dc
->w
.backgroundColor
);
1841 brush
->crFore
= XLATEOBJ_iXlate(XlateObj
, ((brush
->flAttrs
& GDIBRUSH_IS_HATCH
) ?
1842 brush
->BrushAttr
.lbColor
: dc
->w
.textColor
));
1843 /* according to the documentation of SetBrushOrgEx(), the origin is assigned to the
1844 next brush selected into the DC, so we should set it here */
1845 brush
->ptOrigin
.x
= dc
->w
.brushOrgX
;
1846 brush
->ptOrigin
.y
= dc
->w
.brushOrgY
;
1848 BRUSHOBJ_UnlockBrush((HBRUSH
) hGDIObj
);
1849 objOrg
= (HGDIOBJ
)dc
->w
.hBrush
;
1850 dc
->w
.hBrush
= (HBRUSH
) hGDIObj
;
1854 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1856 EngDeleteXlate(XlateObj
);
1860 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
1865 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1869 case GDI_OBJECT_TYPE_FONT
:
1870 objOrg
= (HGDIOBJ
)dc
->w
.hFont
;
1871 dc
->w
.hFont
= (HFONT
) hGDIObj
;
1872 TextIntRealizeFont(dc
->w
.hFont
);
1875 case GDI_OBJECT_TYPE_BITMAP
:
1876 // must be memory dc to select bitmap
1877 if (!(dc
->w
.flags
& DC_MEMORY
))
1882 pb
= BITMAPOBJ_LockBitmap(hGDIObj
);
1885 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1889 objOrg
= (HGDIOBJ
)dc
->w
.hBitmap
;
1891 /* Release the old bitmap, lock the new one and convert it to a SURF */
1892 EngDeleteSurface(dc
->Surface
);
1893 dc
->w
.hBitmap
= hGDIObj
;
1894 dc
->Surface
= (HSURF
)BitmapToSurf(pb
, dc
->GDIDevice
);
1896 // if we're working with a DIB, get the palette [fixme: only create if the selected palette is null]
1899 dc
->w
.bitsPerPixel
= pb
->dib
->dsBmih
.biBitCount
;
1901 if(pb
->dib
->dsBmih
.biBitCount
<= 8)
1903 if(pb
->dib
->dsBmih
.biBitCount
== 1) { NumColors
= 2; } else
1904 if(pb
->dib
->dsBmih
.biBitCount
== 4) { NumColors
= 16; } else
1905 if(pb
->dib
->dsBmih
.biBitCount
== 8) { NumColors
= 256; }
1907 ColorMap
= ExAllocatePoolWithTag(PagedPool
, sizeof(COLORREF
) * NumColors
, TAG_DC
);
1909 for (Index
= 0; Index
< NumColors
; Index
++)
1911 ColorMap
[Index
] = RGB(pb
->ColorMap
[Index
].rgbRed
,
1912 pb
->ColorMap
[Index
].rgbGreen
,
1913 pb
->ColorMap
[Index
].rgbBlue
);
1915 dc
->w
.hPalette
= PALETTE_AllocPalette(PAL_INDEXED
, NumColors
, (ULONG
*) ColorMap
, 0, 0, 0);
1916 ExFreePool(ColorMap
);
1918 else if ( 16 == pb
->dib
->dsBmih
.biBitCount
)
1920 dc
->w
.hPalette
= PALETTE_AllocPalette(PAL_BITFIELDS
, pb
->dib
->dsBmih
.biClrUsed
, NULL
, 0x7c00, 0x03e0, 0x001f);
1922 else if(pb
->dib
->dsBmih
.biBitCount
>= 24)
1924 dc
->w
.hPalette
= PALETTE_AllocPalette(PAL_RGB
, pb
->dib
->dsBmih
.biClrUsed
, NULL
, 0, 0, 0);
1929 dc
->w
.bitsPerPixel
= pb
->bitmap
.bmBitsPixel
;
1930 if (1 == dc
->w
.bitsPerPixel
)
1932 MonoColorMap
[0] = RGB(0, 0, 0);
1933 MonoColorMap
[1] = RGB(255, 255, 255);
1934 dc
->w
.hPalette
= PALETTE_AllocPalette(PAL_INDEXED
, 2, MonoColorMap
, 0, 0, 0);
1938 dc
->w
.hPalette
= dc
->DevInfo
->hpalDefault
;
1942 DC_UnlockDc ( hDC
);
1943 hVisRgn
= NtGdiCreateRectRgn ( 0, 0, pb
->bitmap
.bmWidth
, pb
->bitmap
.bmHeight
);
1944 NtGdiSelectVisRgn ( hDC
, hVisRgn
);
1945 NtGdiDeleteObject ( hVisRgn
);
1946 BITMAPOBJ_UnlockBitmap(hGDIObj
);
1950 case GDI_OBJECT_TYPE_REGION
:
1952 return (HGDIOBJ
) NtGdiSelectClipRgn(hDC
, (HRGN
) hGDIObj
);
1962 NtGdiSetHookFlags(HDC hDC
, WORD Flags
)
1965 DC
*dc
= DC_LockDc(hDC
);
1969 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1973 wRet
= dc
->w
.flags
& DC_DIRTY
;
1975 /* "Undocumented Windows" info is slightly confusing.
1978 DPRINT("DC %p, Flags %04x\n", hDC
, Flags
);
1980 if (Flags
& DCHF_INVALIDATEVISRGN
)
1982 dc
->w
.flags
|= DC_DIRTY
;
1984 else if (Flags
& DCHF_VALIDATEVISRGN
|| 0 == Flags
)
1986 dc
->w
.flags
&= ~DC_DIRTY
;
1994 DC_SET_MODE( NtGdiSetBkMode
, w
.backgroundMode
, TRANSPARENT
, OPAQUE
)
1995 DC_SET_MODE( NtGdiSetPolyFillMode
, w
.polyFillMode
, ALTERNATE
, WINDING
)
1996 // DC_SET_MODE( NtGdiSetRelAbs, w.relAbsMode, ABSOLUTE, RELATIVE )
1997 DC_SET_MODE( NtGdiSetROP2
, w
.ROPmode
, R2_BLACK
, R2_WHITE
)
1998 DC_SET_MODE( NtGdiSetStretchBltMode
, w
.stretchBltMode
, BLACKONWHITE
, HALFTONE
)
2000 // ---------------------------------------------------- Private Interface
2003 DC_AllocDC(PUNICODE_STRING Driver
)
2011 Buf
= ExAllocatePoolWithTag(PagedPool
, Driver
->MaximumLength
, TAG_DC
);
2016 RtlCopyMemory(Buf
, Driver
->Buffer
, Driver
->MaximumLength
);
2019 hDC
= (HDC
) GDIOBJ_AllocObj(sizeof(DC
), GDI_OBJECT_TYPE_DC
, (GDICLEANUPPROC
) DC_InternalDeleteDC
);
2029 NewDC
= DC_LockDc(hDC
);
2033 RtlCopyMemory(&NewDC
->DriverName
, Driver
, sizeof(UNICODE_STRING
));
2034 NewDC
->DriverName
.Buffer
= Buf
;
2037 NewDC
->w
.xformWorld2Wnd
.eM11
= 1.0f
;
2038 NewDC
->w
.xformWorld2Wnd
.eM12
= 0.0f
;
2039 NewDC
->w
.xformWorld2Wnd
.eM21
= 0.0f
;
2040 NewDC
->w
.xformWorld2Wnd
.eM22
= 1.0f
;
2041 NewDC
->w
.xformWorld2Wnd
.eDx
= 0.0f
;
2042 NewDC
->w
.xformWorld2Wnd
.eDy
= 0.0f
;
2043 NewDC
->w
.xformWorld2Vport
= NewDC
->w
.xformWorld2Wnd
;
2044 NewDC
->w
.xformVport2World
= NewDC
->w
.xformWorld2Wnd
;
2045 NewDC
->w
.vport2WorldValid
= TRUE
;
2046 NewDC
->w
.MapMode
= MM_TEXT
;
2048 NewDC
->w
.hFont
= NtGdiGetStockObject(SYSTEM_FONT
);
2049 TextIntRealizeFont(NewDC
->w
.hFont
);
2051 NewDC
->w
.hPalette
= NtGdiGetStockObject(DEFAULT_PALETTE
);
2059 DC_FindOpenDC(PUNICODE_STRING Driver
)
2065 * Initialize some common fields in the Device Context structure.
2068 DC_InitDC(HDC DCHandle
)
2070 // NtGdiRealizeDefaultPalette(DCHandle);
2072 NtGdiSelectObject(DCHandle
, NtGdiGetStockObject( WHITE_BRUSH
));
2073 NtGdiSelectObject(DCHandle
, NtGdiGetStockObject( BLACK_PEN
));
2074 //NtGdiSelectObject(DCHandle, hFont);
2076 // CLIPPING_UpdateGCRegion(DCToInit);
2081 DC_FreeDC(HDC DCToFree
)
2083 if (!GDIOBJ_FreeObj(DCToFree
, GDI_OBJECT_TYPE_DC
, GDIOBJFLAG_DEFAULT
))
2085 DPRINT("DC_FreeDC failed\n");
2090 DC_InternalDeleteDC( PDC DCToDelete
)
2093 RtlFreeUnicodeString(&DCToDelete
->DriverName
);
2098 DC_GetNextDC (PDC pDC
)
2104 DC_SetNextDC (PDC pDC
, HDC hNextDC
)
2106 pDC
->hNext
= hNextDC
;
2110 DC_UpdateXforms(PDC dc
)
2112 XFORM xformWnd2Vport
;
2113 FLOAT scaleX
, scaleY
;
2115 /* Construct a transformation to do the window-to-viewport conversion */
2116 scaleX
= (dc
->wndExtX
? (FLOAT
)dc
->vportExtX
/ (FLOAT
)dc
->wndExtX
: 0.0);
2117 scaleY
= (dc
->wndExtY
? (FLOAT
)dc
->vportExtY
/ (FLOAT
)dc
->wndExtY
: 0.0);
2118 xformWnd2Vport
.eM11
= scaleX
;
2119 xformWnd2Vport
.eM12
= 0.0;
2120 xformWnd2Vport
.eM21
= 0.0;
2121 xformWnd2Vport
.eM22
= scaleY
;
2122 xformWnd2Vport
.eDx
= (FLOAT
)dc
->vportOrgX
- scaleX
* (FLOAT
)dc
->wndOrgX
;
2123 xformWnd2Vport
.eDy
= (FLOAT
)dc
->vportOrgY
- scaleY
* (FLOAT
)dc
->wndOrgY
;
2125 /* Combine with the world transformation */
2126 IntGdiCombineTransform(&dc
->w
.xformWorld2Vport
, &dc
->w
.xformWorld2Wnd
, &xformWnd2Vport
);
2128 /* Create inverse of world-to-viewport transformation */
2129 dc
->w
.vport2WorldValid
= DC_InvertXform(&dc
->w
.xformWorld2Vport
, &dc
->w
.xformVport2World
);
2133 DC_InvertXform(const XFORM
*xformSrc
,
2138 determinant
= xformSrc
->eM11
*xformSrc
->eM22
- xformSrc
->eM12
*xformSrc
->eM21
;
2139 if (determinant
> -1e-12 && determinant
< 1e-12)
2144 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
2145 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
2146 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
2147 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
2148 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
- xformSrc
->eDy
* xformDest
->eM21
;
2149 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
- xformSrc
->eDy
* xformDest
->eM22
;
2155 DC_SetOwnership(HDC hDC
, PEPROCESS Owner
)
2159 GDIOBJ_SetOwnership(hDC
, Owner
);
2160 DC
= DC_LockDc(hDC
);
2163 if (NULL
!= DC
->w
.hClipRgn
)
2165 GDIOBJ_CopyOwnership(hDC
, DC
->w
.hClipRgn
);
2167 if (NULL
!= DC
->w
.hVisRgn
)
2169 GDIOBJ_CopyOwnership(hDC
, DC
->w
.hVisRgn
);
2171 if (NULL
!= DC
->w
.hGCClipRgn
)
2173 GDIOBJ_CopyOwnership(hDC
, DC
->w
.hGCClipRgn
);
2180 IntIsPrimarySurface(PSURFGDI SurfGDI
)
2182 if (PrimarySurface
.Handle
== NULL
)
2186 return SurfGDI
== (PSURFGDI
)AccessInternalObject((ULONG
) PrimarySurface
.Handle
) ? TRUE
: FALSE
;
2190 * Returns the color of the brush or pen that is currently selected into the DC.
2191 * This function is called from GetDCBrushColor() and GetDCPenColor()
2194 IntGetDCColor(HDC hDC
, ULONG Object
)
2206 if(!(dc
= DC_LockDc(hDC
)))
2208 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2216 if(!(pen
= PENOBJ_LockPen(dc
->w
.hPen
)))
2221 if(!(pen
->flAttrs
& GDIBRUSH_IS_SOLID
))
2223 /* FIXME - just bail here? */
2224 PENOBJ_UnlockPen(dc
->w
.hPen
);
2228 iColor
= pen
->BrushObject
.iSolidColor
;
2229 PENOBJ_UnlockPen(dc
->w
.hPen
);
2234 if(!(brush
= BRUSHOBJ_LockBrush(dc
->w
.hBrush
)))
2239 if(!(brush
->flAttrs
& GDIBRUSH_IS_SOLID
))
2241 /* FIXME - just bail here? */
2242 BRUSHOBJ_UnlockBrush(dc
->w
.hBrush
);
2246 iColor
= brush
->BrushObject
.iSolidColor
;
2247 BRUSHOBJ_UnlockBrush(dc
->w
.hBrush
);
2253 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2258 /* translate the color into RGB */
2261 Pal
= dc
->w
.hPalette
;
2263 Result
= CLR_INVALID
;
2265 if((PalGDI
= PALETTE_LockPalette(dc
->w
.hPalette
)))
2267 Mode
= PalGDI
->Mode
;
2268 PALETTE_UnlockPalette(dc
->w
.hPalette
);
2269 XlateObj
= (XLATEOBJ
*)IntEngCreateXlate(PAL_RGB
, Mode
, NULL
, Pal
);
2272 Result
= XLATEOBJ_iXlate(XlateObj
, iColor
);
2273 EngDeleteXlate(XlateObj
);
2282 * Changes the color of the brush or pen that is currently selected into the DC.
2283 * This function is called from SetDCBrushColor() and SetDCPenColor()
2286 IntSetDCColor(HDC hDC
, ULONG Object
, COLORREF Color
)
2298 if(Color
== CLR_INVALID
)
2300 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2304 if(!(dc
= DC_LockDc(hDC
)))
2306 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2314 if(!(pen
= PENOBJ_LockPen(dc
->w
.hPen
)))
2319 if(!(pen
->flAttrs
& GDIBRUSH_IS_SOLID
))
2321 /* FIXME - just bail here? */
2322 PENOBJ_UnlockPen(dc
->w
.hPen
);
2327 /* save old color index, translate it to RGB later */
2328 iColor
= pen
->BrushObject
.iSolidColor
;
2330 if(!(PalGDI
= PALETTE_LockPalette(dc
->w
.hPalette
)))
2332 PENOBJ_UnlockPen(dc
->w
.hPen
);
2336 Mode
= PalGDI
->Mode
;
2337 PALETTE_UnlockPalette(dc
->w
.hPalette
);
2338 if(!(XlateObj
= (XLATEOBJ
*)IntEngCreateXlate(Mode
, PAL_RGB
, dc
->w
.hPalette
, NULL
)))
2340 PENOBJ_UnlockPen(dc
->w
.hPen
);
2344 pen
->BrushObject
.iSolidColor
= XLATEOBJ_iXlate(XlateObj
, (ULONG
)Color
);
2345 EngDeleteXlate(XlateObj
);
2346 PENOBJ_UnlockPen(dc
->w
.hPen
);
2351 if(!(brush
= BRUSHOBJ_LockBrush(dc
->w
.hBrush
)))
2356 if(!(brush
->flAttrs
& GDIBRUSH_IS_SOLID
))
2358 /* FIXME - just bail here? */
2359 BRUSHOBJ_UnlockBrush(dc
->w
.hBrush
);
2364 /* save old color index, translate it to RGB later */
2365 iColor
= brush
->BrushObject
.iSolidColor
;
2367 if(!(PalGDI
= PALETTE_LockPalette(dc
->w
.hPalette
)))
2369 PENOBJ_UnlockPen(dc
->w
.hPen
);
2373 Mode
= PalGDI
->Mode
;
2374 PALETTE_UnlockPalette(dc
->w
.hPalette
);
2375 if(!(XlateObj
= (XLATEOBJ
*)IntEngCreateXlate(Mode
, PAL_RGB
, dc
->w
.hPalette
, NULL
)))
2377 PENOBJ_UnlockPen(dc
->w
.hPen
);
2381 brush
->BrushObject
.iSolidColor
= XLATEOBJ_iXlate(XlateObj
, (ULONG
)Color
);
2382 EngDeleteXlate(XlateObj
);
2383 BRUSHOBJ_UnlockBrush(dc
->w
.hBrush
);
2389 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2394 /* translate the old color into RGB */
2397 Pal
= dc
->w
.hPalette
;
2399 Result
= CLR_INVALID
;
2401 if((PalGDI
= PALETTE_LockPalette(dc
->w
.hPalette
)))
2403 Mode
= PalGDI
->Mode
;
2404 PALETTE_UnlockPalette(dc
->w
.hPalette
);
2405 XlateObj
= (XLATEOBJ
*)IntEngCreateXlate(PAL_RGB
, Mode
, NULL
, Pal
);
2408 Result
= XLATEOBJ_iXlate(XlateObj
, iColor
);
2409 EngDeleteXlate(XlateObj
);