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.
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
23 * PURPOSE: Window classes
24 * FILE: subsys/win32k/ntuser/class.c
25 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
27 * 06-06-2001 CSH Created
30 /* INCLUDES ******************************************************************/
37 /* GLOBALS *******************************************************************/
39 /* NOTE - I think we should store this per window station (including gdi objects) */
41 static PDCE FirstDce
= NULL
;
42 static PDC defaultDCstate
= NULL
;
43 //static INT DCECount = 0;
45 #define DCX_CACHECOMPAREMASK (DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN | \
46 DCX_CACHE | DCX_WINDOW | DCX_PARENTCLIP)
48 /* FUNCTIONS *****************************************************************/
51 DceCreateDisplayDC(VOID
)
54 UNICODE_STRING DriverName
;
55 RtlInitUnicodeString(&DriverName
, L
"DISPLAY");
56 hDC
= IntGdiCreateDC(&DriverName
, NULL
, NULL
, NULL
, FALSE
);
68 DceGetVisRgn(PWINDOW_OBJECT Window
, ULONG Flags
, HWND hWndChild
, ULONG CFlags
)
72 VisRgn
= VIS_ComputeVisibleRegion(Window
,
73 0 == (Flags
& DCX_WINDOW
),
74 0 != (Flags
& DCX_CLIPCHILDREN
),
75 0 != (Flags
& DCX_CLIPSIBLINGS
));
78 VisRgn
= NtGdiCreateRectRgn(0, 0, 0, 0);
86 * The NtUserGetWindowDC function retrieves the device context (DC) for the
87 * entire window, including title bar, menus, and scroll bars. A window device
88 * context permits painting anywhere in a window, because the origin of the
89 * device context is the upper-left corner of the window instead of the client
97 NtUserGetWindowDC(HWND hWnd
)
99 return (DWORD
)NtUserGetDCEx(hWnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
103 UserGetWindowDC(PWINDOW_OBJECT Wnd
)
105 return (DWORD
)UserGetDCEx(Wnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
109 NtUserGetDC(HWND hWnd
)
111 return NtUserGetDCEx(hWnd
, NULL
, NULL
== hWnd
? DCX_CACHE
| DCX_WINDOW
: DCX_USESTYLE
);
115 DceAllocDCE(PWINDOW_OBJECT Window OPTIONAL
, DCE_TYPE Type
)
119 pDce
= ExAllocatePoolWithTag(PagedPool
, sizeof(DCE
), TAG_PDCE
);
123 pDce
->hDC
= DceCreateDisplayDC();
126 ExFreePoolWithTag(pDce
, TAG_PDCE
);
130 // If NULL, first time through! Build the default window dc!
132 if (NULL
== defaultDCstate
) // Ultra HAX! Dedicated to GvG!
133 { // This is a cheesy way to do this.
134 PDC dc
= DC_LockDc ( pDce
->hDC
);
135 defaultDCstate
= ExAllocatePoolWithTag(PagedPool
, sizeof(DC
), TAG_DC
);
136 RtlZeroMemory(defaultDCstate
, sizeof(DC
));
137 IntGdiCopyToSaveState(dc
, defaultDCstate
);
141 pDce
->hwndCurrent
= (Window
? Window
->hSelf
: NULL
);
142 pDce
->hClipRgn
= NULL
;
143 pDce
->pProcess
= NULL
;
145 KeEnterCriticalRegion();
146 pDce
->next
= FirstDce
;
148 KeLeaveCriticalRegion();
150 if (Type
== DCE_WINDOW_DC
) //Window DCE have ownership.
151 { // Process should already own it.
152 pDce
->pProcess
= PsGetCurrentProcess();
156 DPRINT("FREE DCATTR!!!! NOT DCE_WINDOW_DC!!!!! hDC-> %x\n", pDce
->hDC
);
157 DC_FreeDcAttr(pDce
->hDC
); // Free the dcattr!
158 DC_SetOwnership(pDce
->hDC
, NULL
); // This hDC is inaccessible!
161 if (Type
!= DCE_CACHE_DC
)
163 pDce
->DCXFlags
= DCX_DCEBUSY
;
167 if (Window
->Style
& WS_CLIPCHILDREN
)
169 pDce
->DCXFlags
|= DCX_CLIPCHILDREN
;
171 if (Window
->Style
& WS_CLIPSIBLINGS
)
173 pDce
->DCXFlags
|= DCX_CLIPSIBLINGS
;
179 pDce
->DCXFlags
= DCX_CACHE
| DCX_DCEEMPTY
;
186 DceSetDrawable(PWINDOW_OBJECT Window OPTIONAL
, HDC hDC
, ULONG Flags
,
189 DC
*dc
= DC_LockDc(hDC
);
200 if (Flags
& DCX_WINDOW
)
202 dc
->w
.DCOrgX
= Window
->Wnd
->WindowRect
.left
;
203 dc
->w
.DCOrgY
= Window
->Wnd
->WindowRect
.top
;
207 dc
->w
.DCOrgX
= Window
->Wnd
->ClientRect
.left
;
208 dc
->w
.DCOrgY
= Window
->Wnd
->ClientRect
.top
;
216 DceDeleteClipRgn(DCE
* Dce
)
218 Dce
->DCXFlags
&= ~(DCX_EXCLUDERGN
| DCX_INTERSECTRGN
);
220 if (Dce
->DCXFlags
& DCX_KEEPCLIPRGN
)
222 Dce
->DCXFlags
&= ~DCX_KEEPCLIPRGN
;
224 else if (Dce
->hClipRgn
!= NULL
)
226 NtGdiDeleteObject(Dce
->hClipRgn
);
229 Dce
->hClipRgn
= NULL
;
231 /* make it dirty so that the vis rgn gets recomputed next time */
232 Dce
->DCXFlags
|= DCX_DCEDIRTY
;
236 DceReleaseDC(DCE
* dce
, BOOL EndPaint
)
238 if (DCX_DCEBUSY
!= (dce
->DCXFlags
& (DCX_DCEEMPTY
| DCX_DCEBUSY
)))
243 /* restore previous visible region */
245 if ((dce
->DCXFlags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
)) &&
246 ((dce
->DCXFlags
& DCX_CACHE
) || EndPaint
))
248 DceDeleteClipRgn(dce
);
251 if (dce
->DCXFlags
& DCX_CACHE
)
253 if (!(dce
->DCXFlags
& DCX_NORESETATTRS
))
255 /* make the DC clean so that SetDCState doesn't try to update the vis rgn */
256 IntGdiSetHookFlags(dce
->hDC
, DCHF_VALIDATEVISRGN
);
258 PDC dc
= DC_LockDc ( dce
->hDC
);
259 IntGdiCopyFromSaveState(dc
, defaultDCstate
, dce
->hDC
); // Was SetDCState.
261 dce
->DCXFlags
&= ~DCX_DCEBUSY
;
262 if (dce
->DCXFlags
& DCX_DCEDIRTY
)
264 /* don't keep around invalidated entries
265 * because SetDCState() disables hVisRgn updates
266 * by removing dirty bit. */
267 dce
->hwndCurrent
= 0;
268 dce
->DCXFlags
&= DCX_CACHE
;
269 dce
->DCXFlags
|= DCX_DCEEMPTY
;
272 DPRINT("Exit!!!!! DCX_CACHE!!!!!! hDC-> %x \n", dce
->hDC
);
273 DC_FreeDcAttr(dce
->hDC
); // Free the dcattr.
274 DC_SetOwnership(dce
->hDC
, NULL
); // Set hDC inaccessible mode.
275 dce
->pProcess
= NULL
; // Reset ownership.
281 DceUpdateVisRgn(DCE
*Dce
, PWINDOW_OBJECT Window
, ULONG Flags
)
283 HANDLE hRgnVisible
= NULL
;
285 PWINDOW_OBJECT DesktopWindow
;
287 if (Flags
& DCX_PARENTCLIP
)
289 PWINDOW_OBJECT Parent
;
291 Parent
= Window
->Parent
;
298 if (Parent
->Style
& WS_CLIPSIBLINGS
)
300 DcxFlags
= DCX_CLIPSIBLINGS
|
301 (Flags
& ~(DCX_CLIPCHILDREN
| DCX_WINDOW
));
305 DcxFlags
= Flags
& ~(DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
| DCX_WINDOW
);
307 hRgnVisible
= DceGetVisRgn(Parent
, DcxFlags
, Window
->hSelf
, Flags
);
309 else if (Window
== NULL
)
311 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
312 if (NULL
!= DesktopWindow
)
314 hRgnVisible
= UnsafeIntCreateRectRgnIndirect(&DesktopWindow
->Wnd
->WindowRect
);
323 hRgnVisible
= DceGetVisRgn(Window
, Flags
, 0, 0);
327 if (Flags
& DCX_INTERSECTRGN
)
329 if(Dce
->hClipRgn
!= NULL
)
331 NtGdiCombineRgn(hRgnVisible
, hRgnVisible
, Dce
->hClipRgn
, RGN_AND
);
335 if(hRgnVisible
!= NULL
)
337 NtGdiDeleteObject(hRgnVisible
);
339 hRgnVisible
= NtGdiCreateRectRgn(0, 0, 0, 0);
343 if (Flags
& DCX_EXCLUDERGN
&& Dce
->hClipRgn
!= NULL
)
345 NtGdiCombineRgn(hRgnVisible
, hRgnVisible
, Dce
->hClipRgn
, RGN_DIFF
);
348 Dce
->DCXFlags
&= ~DCX_DCEDIRTY
;
349 IntGdiSelectVisRgn(Dce
->hDC
, hRgnVisible
);
353 IntEngWindowChanged(Window
, WOC_RGN_CLIENT
);
356 if (hRgnVisible
!= NULL
)
358 NtGdiDeleteObject(hRgnVisible
);
363 UserGetDCEx(PWINDOW_OBJECT Window OPTIONAL
, HANDLE ClipRegion
, ULONG Flags
)
365 PWINDOW_OBJECT Parent
;
368 BOOL UpdateVisRgn
= TRUE
;
369 BOOL UpdateClipOrigin
= FALSE
;
373 Flags
&= ~DCX_USESTYLE
;
376 if (NULL
== Window
|| NULL
== Window
->Dce
)
381 if (Flags
& DCX_USESTYLE
)
383 Flags
&= ~(DCX_CLIPCHILDREN
| DCX_CLIPSIBLINGS
| DCX_PARENTCLIP
);
385 if (Window
->Style
& WS_CLIPSIBLINGS
)
387 Flags
|= DCX_CLIPSIBLINGS
;
390 if (!(Flags
& DCX_WINDOW
))
392 if (Window
->Class
->Style
& CS_PARENTDC
)
394 Flags
|= DCX_PARENTCLIP
;
397 if (Window
->Style
& WS_CLIPCHILDREN
&&
398 !(Window
->Style
& WS_MINIMIZE
))
400 Flags
|= DCX_CLIPCHILDREN
;
409 if (Flags
& DCX_NOCLIPCHILDREN
)
412 Flags
&= ~(DCX_PARENTCLIP
| DCX_CLIPCHILDREN
);
415 if (Flags
& DCX_WINDOW
)
417 Flags
= (Flags
& ~DCX_CLIPCHILDREN
) | DCX_CACHE
;
420 Parent
= (Window
? Window
->Parent
: NULL
);
422 if (NULL
== Window
|| !(Window
->Style
& WS_CHILD
) || NULL
== Parent
)
424 Flags
&= ~DCX_PARENTCLIP
;
426 else if (Flags
& DCX_PARENTCLIP
)
429 if ((Window
->Style
& WS_VISIBLE
) &&
430 (Parent
->Style
& WS_VISIBLE
))
432 Flags
&= ~DCX_CLIPCHILDREN
;
433 if (Parent
->Style
& WS_CLIPSIBLINGS
)
435 Flags
|= DCX_CLIPSIBLINGS
;
440 DcxFlags
= Flags
& DCX_CACHECOMPAREMASK
;
442 if (Flags
& DCX_CACHE
)
444 DCE
* DceEmpty
= NULL
;
445 DCE
* DceUnused
= NULL
;
446 KeEnterCriticalRegion();
447 for (Dce
= FirstDce
; Dce
!= NULL
; Dce
= Dce
->next
)
449 if ((Dce
->DCXFlags
& (DCX_CACHE
| DCX_DCEBUSY
)) == DCX_CACHE
)
452 if (Dce
->DCXFlags
& DCX_DCEEMPTY
)
456 else if (Dce
->hwndCurrent
== (Window
? Window
->hSelf
: NULL
) &&
457 ((Dce
->DCXFlags
& DCX_CACHECOMPAREMASK
) == DcxFlags
))
460 UpdateVisRgn
= FALSE
;
463 UpdateClipOrigin
= TRUE
;
468 KeLeaveCriticalRegion();
472 Dce
= (DceEmpty
== NULL
) ? DceUnused
: DceEmpty
;
477 Dce
= DceAllocDCE(NULL
, DCE_CACHE_DC
);
483 if (NULL
!= Dce
&& Dce
->hwndCurrent
== (Window
? Window
->hSelf
: NULL
))
485 UpdateVisRgn
= FALSE
; /* updated automatically, via DCHook() */
489 /* we should free dce->clip_rgn here, but Windows apparently doesn't */
490 Dce
->DCXFlags
&= ~(DCX_EXCLUDERGN
| DCX_INTERSECTRGN
);
491 Dce
->hClipRgn
= NULL
;
504 Dce
->hwndCurrent
= (Window
? Window
->hSelf
: NULL
);
505 Dce
->DCXFlags
= Flags
| DCX_DCEBUSY
;
507 if (0 == (Flags
& (DCX_EXCLUDERGN
| DCX_INTERSECTRGN
)) && NULL
!= ClipRegion
)
509 if (Flags
& DCX_KEEPCLIPRGN
)
510 NtGdiDeleteObject(ClipRegion
);
515 if (NULL
!= Dce
->hClipRgn
)
517 DceDeleteClipRgn(Dce
);
518 Dce
->hClipRgn
= NULL
;
522 if (0 != (Flags
& DCX_INTERSECTUPDATE
) && NULL
== ClipRegion
)
524 Flags
|= DCX_INTERSECTRGN
| DCX_KEEPCLIPRGN
;
525 Dce
->DCXFlags
|= DCX_INTERSECTRGN
| DCX_KEEPCLIPRGN
;
526 ClipRegion
= Window
->UpdateRegion
;
529 if (ClipRegion
== (HRGN
) 1)
531 if (!(Flags
& DCX_WINDOW
))
533 Dce
->hClipRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->Wnd
->ClientRect
);
537 Dce
->hClipRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->Wnd
->WindowRect
);
540 else if (ClipRegion
!= NULL
)
542 Dce
->hClipRgn
= ClipRegion
;
545 DceSetDrawable(Window
, Dce
->hDC
, Flags
, UpdateClipOrigin
);
549 DceUpdateVisRgn(Dce
, Window
, Flags
);
552 if (Dce
->DCXFlags
& DCX_CACHE
)
554 DPRINT("ENTER!!!!!! DCX_CACHE!!!!!! hDC-> %x\n", Dce
->hDC
);
555 // Need to set ownership so Sync dcattr will work.
556 DC_SetOwnership( Dce
->hDC
, PsGetCurrentProcess());
557 DC_AllocateDcAttr( Dce
->hDC
); // Allocate new dcattr
558 DCU_SynchDcAttrtoUser( Dce
->hDC
, -1); // Copy data from dc to dcattr
559 Dce
->pProcess
= PsGetCurrentProcess(); // Set the temp owning process
567 NtUserGetDCEx(HWND hWnd OPTIONAL
, HANDLE ClipRegion
, ULONG Flags
)
569 PWINDOW_OBJECT Wnd
=NULL
;
572 DPRINT("Enter NtUserGetDCEx\n");
573 UserEnterExclusive();
575 if (hWnd
&& !(Wnd
= UserGetWindowObject(hWnd
)))
580 RETURN( UserGetDCEx(Wnd
, ClipRegion
, Flags
));
583 DPRINT("Leave NtUserGetDCEx, ret=%i\n",_ret_
);
590 DCE_Cleanup(PDCE pDce
)
593 KeEnterCriticalRegion();
594 if (pDce
== FirstDce
)
596 FirstDce
= pDce
->next
;
601 for (PrevInList
= FirstDce
; NULL
!= PrevInList
; PrevInList
= PrevInList
->next
)
603 if (pDce
== PrevInList
->next
)
605 PrevInList
->next
= pDce
->next
;
609 assert(NULL
!= PrevInList
);
611 KeLeaveCriticalRegion();
612 return NULL
!= PrevInList
;
616 IntWindowFromDC(HDC hDc
)
620 KeEnterCriticalRegion();
621 for (Dce
= FirstDce
; Dce
!= NULL
; Dce
= Dce
->next
)
625 Ret
= Dce
->hwndCurrent
;
629 KeLeaveCriticalRegion();
635 UserReleaseDC(PWINDOW_OBJECT Window
, HDC hDc
, BOOL EndPaint
)
642 DPRINT("%p %p\n", Window
, hDc
);
643 KeEnterCriticalRegion();
644 while (dce
&& (dce
->hDC
!= hDc
))
648 KeLeaveCriticalRegion();
649 if (dce
&& (dce
->DCXFlags
& DCX_DCEBUSY
))
651 nRet
= DceReleaseDC(dce
, EndPaint
);
658 /***********************************************************************
662 DceFreeDCE(PDCE pdce
, BOOLEAN Force
)
675 SetDCHook(pdce
->hDC
, NULL
, 0L);
678 if(Force
&& !GDIOBJ_OwnedByCurrentProcess(GdiHandleTable
, pdce
->hDC
))
680 DPRINT1("Change ownership for DCE!\n");
681 INT Index
= GDI_HANDLE_GET_INDEX(pdce
->hDC
);
682 PGDI_TABLE_ENTRY Entry
= &GdiHandleTable
->Entries
[Index
];
684 // Must take control of handles that are not in the process of going away.
685 if ((Entry
->Type
& ~GDI_ENTRY_REUSE_MASK
) != 0 && Entry
->KernelData
!= NULL
)
687 DC_SetOwnership( pdce
->hDC
, PsGetCurrentProcess());
691 DPRINT1("Attempted to change ownership of an DCEhDC 0x%x currently being destroyed!!!\n",pdce
->hDC
);
695 NtGdiDeleteObjectApp(pdce
->hDC
);
696 if (pdce
->hClipRgn
&& ! (pdce
->DCXFlags
& DCX_KEEPCLIPRGN
))
698 NtGdiDeleteObject(pdce
->hClipRgn
);
702 ExFreePoolWithTag(pdce
, TAG_PDCE
);
704 if (FirstDce
== NULL
)
706 ExFreePoolWithTag(defaultDCstate
, TAG_DC
);
707 defaultDCstate
= NULL
;
712 /***********************************************************************
715 * Remove owned DCE and reset unreleased cache DCEs.
718 DceFreeWindowDCE(PWINDOW_OBJECT Window
)
723 KeEnterCriticalRegion();
726 if (pDCE
->hwndCurrent
== Window
->hSelf
)
728 if (pDCE
== Window
->Dce
) /* owned or Class DCE*/
730 if (Window
->Class
->Style
& CS_OWNDC
) /* owned DCE*/
732 pDCE
= DceFreeDCE(pDCE
, FALSE
);
736 else if (pDCE
->DCXFlags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
)) /* Class DCE*/
738 DceDeleteClipRgn(pDCE
);
739 pDCE
->hwndCurrent
= 0;
744 if (pDCE
->DCXFlags
& DCX_DCEBUSY
) /* shared cache DCE */
746 /* FIXME: AFAICS we are doing the right thing here so
747 * this should be a DPRINT. But this is best left as an ERR
748 * because the 'application error' is likely to come from
749 * another part of Wine (i.e. it's our fault after all).
750 * We should change this to DPRINT when ReactOS is more stable
753 DPRINT1("[%p] GetDC() without ReleaseDC()!\n", Window
->hSelf
);
754 DceReleaseDC(pDCE
, FALSE
);
757 pDCE
->DCXFlags
&= DCX_CACHE
;
758 pDCE
->DCXFlags
|= DCX_DCEEMPTY
;
759 pDCE
->hwndCurrent
= 0;
764 KeLeaveCriticalRegion();
770 while (FirstDce
!= NULL
)
772 FirstDce
= DceFreeDCE(FirstDce
, TRUE
);
777 DceResetActiveDCEs(PWINDOW_OBJECT Window
)
781 PWINDOW_OBJECT CurrentWindow
;
792 if (0 == (pDCE
->DCXFlags
& DCX_DCEEMPTY
))
794 if (Window
->hSelf
== pDCE
->hwndCurrent
)
796 CurrentWindow
= Window
;
800 CurrentWindow
= UserGetWindowObject(pDCE
->hwndCurrent
);
801 if (NULL
== CurrentWindow
)
808 dc
= DC_LockDc(pDCE
->hDC
);
811 // if (Window->hSelf != pDCE->hwndCurrent)
813 // UserDerefObject(CurrentWindow);
818 if (Window
== CurrentWindow
|| IntIsChildWindow(Window
, CurrentWindow
))
820 if (pDCE
->DCXFlags
& DCX_WINDOW
)
822 DeltaX
= CurrentWindow
->Wnd
->WindowRect
.left
- dc
->w
.DCOrgX
;
823 DeltaY
= CurrentWindow
->Wnd
->WindowRect
.top
- dc
->w
.DCOrgY
;
824 dc
->w
.DCOrgX
= CurrentWindow
->Wnd
->WindowRect
.left
;
825 dc
->w
.DCOrgY
= CurrentWindow
->Wnd
->WindowRect
.top
;
829 DeltaX
= CurrentWindow
->Wnd
->ClientRect
.left
- dc
->w
.DCOrgX
;
830 DeltaY
= CurrentWindow
->Wnd
->ClientRect
.top
- dc
->w
.DCOrgY
;
831 dc
->w
.DCOrgX
= CurrentWindow
->Wnd
->ClientRect
.left
;
832 dc
->w
.DCOrgY
= CurrentWindow
->Wnd
->ClientRect
.top
;
834 if (NULL
!= dc
->w
.hClipRgn
)
836 int FASTCALL
CLIPPING_UpdateGCRegion(DC
* Dc
);
837 NtGdiOffsetRgn(dc
->w
.hClipRgn
, DeltaX
, DeltaY
);
838 CLIPPING_UpdateGCRegion(dc
);
840 if (NULL
!= pDCE
->hClipRgn
)
842 NtGdiOffsetRgn(pDCE
->hClipRgn
, DeltaX
, DeltaY
);
847 DceUpdateVisRgn(pDCE
, CurrentWindow
, pDCE
->DCXFlags
);
849 if (Window
->hSelf
!= pDCE
->hwndCurrent
)
851 // IntEngWindowChanged(CurrentWindow, WOC_RGN_CLIENT);
852 // UserDerefObject(CurrentWindow);
860 #define COPY_DEVMODE_VALUE_TO_CALLER(dst, src, member) \
861 Status = MmCopyToCaller(&(dst)->member, &(src)->member, sizeof ((src)->member)); \
862 if (!NT_SUCCESS(Status)) \
864 SetLastNtError(Status); \
871 NtUserEnumDisplaySettings(
872 PUNICODE_STRING lpszDeviceName
,
874 LPDEVMODEW lpDevMode
, /* FIXME is this correct? */
878 LPDEVMODEW pSafeDevMode
;
879 PUNICODE_STRING pSafeDeviceName
= NULL
;
880 UNICODE_STRING SafeDeviceName
;
881 USHORT Size
= 0, ExtraSize
= 0;
883 /* Copy the devmode */
884 Status
= MmCopyFromCaller(&Size
, &lpDevMode
->dmSize
, sizeof (Size
));
885 if (!NT_SUCCESS(Status
))
887 SetLastNtError(Status
);
890 Status
= MmCopyFromCaller(&ExtraSize
, &lpDevMode
->dmDriverExtra
, sizeof (ExtraSize
));
891 if (!NT_SUCCESS(Status
))
893 SetLastNtError(Status
);
896 pSafeDevMode
= ExAllocatePool(PagedPool
, Size
+ ExtraSize
);
897 if (pSafeDevMode
== NULL
)
899 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
902 pSafeDevMode
->dmSize
= Size
;
903 pSafeDevMode
->dmDriverExtra
= ExtraSize
;
905 /* Copy the device name */
906 if (lpszDeviceName
!= NULL
)
908 Status
= IntSafeCopyUnicodeString(&SafeDeviceName
, lpszDeviceName
);
909 if (!NT_SUCCESS(Status
))
911 ExFreePool(pSafeDevMode
);
912 SetLastNtError(Status
);
915 pSafeDeviceName
= &SafeDeviceName
;
918 /* Call internal function */
919 if (!IntEnumDisplaySettings(pSafeDeviceName
, iModeNum
, pSafeDevMode
, dwFlags
))
921 if (pSafeDeviceName
!= NULL
)
922 RtlFreeUnicodeString(pSafeDeviceName
);
923 ExFreePool(pSafeDevMode
);
926 if (pSafeDeviceName
!= NULL
)
927 RtlFreeUnicodeString(pSafeDeviceName
);
929 /* Copy some information back */
930 COPY_DEVMODE_VALUE_TO_CALLER(lpDevMode
, pSafeDevMode
, dmPelsWidth
);
931 COPY_DEVMODE_VALUE_TO_CALLER(lpDevMode
, pSafeDevMode
, dmPelsHeight
);
932 COPY_DEVMODE_VALUE_TO_CALLER(lpDevMode
, pSafeDevMode
, dmBitsPerPel
);
933 COPY_DEVMODE_VALUE_TO_CALLER(lpDevMode
, pSafeDevMode
, dmDisplayFrequency
);
934 COPY_DEVMODE_VALUE_TO_CALLER(lpDevMode
, pSafeDevMode
, dmDisplayFlags
);
936 /* output private/extra driver data */
939 Status
= MmCopyToCaller((PCHAR
)lpDevMode
+ Size
, (PCHAR
)pSafeDevMode
+ Size
, ExtraSize
);
940 if (!NT_SUCCESS(Status
))
942 SetLastNtError(Status
);
943 ExFreePool(pSafeDevMode
);
948 ExFreePool(pSafeDevMode
);
952 #undef COPY_DEVMODE_VALUE_TO_CALLER
957 NtUserChangeDisplaySettings(
958 PUNICODE_STRING lpszDeviceName
,
959 LPDEVMODEW lpDevMode
,
966 PUNICODE_STRING pSafeDeviceName
= NULL
;
967 UNICODE_STRING SafeDeviceName
;
970 /* Check arguments */
971 #ifdef CDS_VIDEOPARAMETERS
973 if (dwflags
!= CDS_VIDEOPARAMETERS
&& lParam
!= NULL
)
980 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
981 return DISP_CHANGE_BADPARAM
;
985 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
986 return DISP_CHANGE_BADPARAM
;
990 Status
= MmCopyFromCaller(&DevMode
.dmSize
, &lpDevMode
->dmSize
, sizeof (DevMode
.dmSize
));
991 if (!NT_SUCCESS(Status
))
993 SetLastNtError(Status
);
994 return DISP_CHANGE_BADPARAM
;
996 DevMode
.dmSize
= min(sizeof (DevMode
), DevMode
.dmSize
);
997 Status
= MmCopyFromCaller(&DevMode
, lpDevMode
, DevMode
.dmSize
);
998 if (!NT_SUCCESS(Status
))
1000 SetLastNtError(Status
);
1001 return DISP_CHANGE_BADPARAM
;
1003 if (DevMode
.dmDriverExtra
> 0)
1005 DbgPrint("(%s:%i) WIN32K: %s lpDevMode->dmDriverExtra is IGNORED!\n", __FILE__
, __LINE__
, __FUNCTION__
);
1006 DevMode
.dmDriverExtra
= 0;
1009 /* Copy the device name */
1010 if (lpszDeviceName
!= NULL
)
1012 Status
= IntSafeCopyUnicodeString(&SafeDeviceName
, lpszDeviceName
);
1013 if (!NT_SUCCESS(Status
))
1015 SetLastNtError(Status
);
1016 return DISP_CHANGE_BADPARAM
;
1018 pSafeDeviceName
= &SafeDeviceName
;
1021 /* Call internal function */
1022 Ret
= IntChangeDisplaySettings(pSafeDeviceName
, &DevMode
, dwflags
, lParam
);
1024 if (pSafeDeviceName
!= NULL
)
1025 RtlFreeUnicodeString(pSafeDeviceName
);
1031 * Select logical palette into device context.
1032 * \param hDC handle to the device context
1033 * \param hpal handle to the palette
1034 * \param ForceBackground If this value is FALSE the logical palette will be copied to the device palette only when the applicatioon
1035 * is in the foreground. If this value is TRUE then map the colors in the logical palette to the device
1036 * palette colors in the best way.
1037 * \return old palette
1039 * \todo implement ForceBackground == TRUE
1041 HPALETTE STDCALL
NtUserSelectPalette(HDC hDC
,
1043 BOOL ForceBackground
)
1046 HPALETTE oldPal
= NULL
;
1049 // FIXME: mark the palette as a [fore\back]ground pal
1050 dc
= DC_LockDc(hDC
);
1053 /* Check if this is a valid palette handle */
1054 PalGDI
= PALETTE_LockPalette(hpal
);
1057 /* Is this a valid palette for this depth? */
1058 if ((dc
->w
.bitsPerPixel
<= 8 && PAL_INDEXED
== PalGDI
->Mode
)
1059 || (8 < dc
->w
.bitsPerPixel
&& PAL_INDEXED
!= PalGDI
->Mode
))
1061 PALETTE_UnlockPalette(PalGDI
);
1062 oldPal
= dc
->w
.hPalette
;
1063 dc
->w
.hPalette
= hpal
;
1065 else if (8 < dc
->w
.bitsPerPixel
&& PAL_INDEXED
== PalGDI
->Mode
)
1067 PALETTE_UnlockPalette(PalGDI
);
1068 oldPal
= dc
->PalIndexed
;
1069 dc
->PalIndexed
= hpal
;
1073 PALETTE_UnlockPalette(PalGDI
);