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
)
113 //"hWnd [in] Handle to the window whose DC is to be retrieved.
114 // If this value is NULL, GetDC retrieves the DC for the entire screen."
115 hWnd
= IntGetDesktopWindow();
117 return NtUserGetDCEx(hWnd
, NULL
, DCX_CACHE
| DCX_WINDOW
);
121 return NtUserGetDCEx(hWnd
, NULL
, DCX_USESTYLE
);
125 DceAllocDCE(PWINDOW_OBJECT Window OPTIONAL
, DCE_TYPE Type
)
133 pDce
= ExAllocatePoolWithTag(PagedPool
, sizeof(DCE
), TAG_PDCE
);
137 pDce
->hDC
= DceCreateDisplayDC();
140 ExFreePoolWithTag(pDce
, TAG_PDCE
);
144 // If NULL, first time through! Build the default window dc!
146 if (NULL
== defaultDCstate
) // Ultra HAX! Dedicated to GvG!
147 { // This is a cheesy way to do this.
148 PDC dc
= DC_LockDc ( pDce
->hDC
);
149 defaultDCstate
= ExAllocatePoolWithTag(PagedPool
, sizeof(DC
), TAG_DC
);
150 RtlZeroMemory(defaultDCstate
, sizeof(DC
));
151 IntGdiCopyToSaveState(dc
, defaultDCstate
);
155 pDce
->hwndCurrent
= (Window
? Window
->hSelf
: NULL
);
156 pDce
->hClipRgn
= NULL
;
157 pDce
->pProcess
= NULL
;
159 KeEnterCriticalRegion();
160 pDce
->next
= FirstDce
;
162 KeLeaveCriticalRegion();
164 if (Type
== DCE_WINDOW_DC
) //Window DCE have ownership.
165 { // Process should already own it.
166 pDce
->pProcess
= PsGetCurrentProcess();
170 PDC dc
= DC_LockDc ( pDce
->hDC
);
171 DPRINT("FREE DCATTR!!!! NOT DCE_WINDOW_DC!!!!! hDC-> %x\n", pDce
->hDC
);
172 MmCopyFromCaller(&dc
->Dc_Attr
, dc
->pDc_Attr
, sizeof(DC_ATTR
));
174 DC_FreeDcAttr(pDce
->hDC
); // Free the dcattr!
175 DC_SetOwnership(pDce
->hDC
, NULL
); // This hDC is inaccessible!
178 if (Type
!= DCE_CACHE_DC
)
180 pDce
->DCXFlags
= DCX_DCEBUSY
;
184 if (Wnd
->Style
& WS_CLIPCHILDREN
)
186 pDce
->DCXFlags
|= DCX_CLIPCHILDREN
;
188 if (Wnd
->Style
& WS_CLIPSIBLINGS
)
190 pDce
->DCXFlags
|= DCX_CLIPSIBLINGS
;
196 pDce
->DCXFlags
= DCX_CACHE
| DCX_DCEEMPTY
;
203 DceSetDrawable(PWINDOW_OBJECT Window OPTIONAL
, HDC hDC
, ULONG Flags
,
207 DC
*dc
= DC_LockDc(hDC
);
219 if (Flags
& DCX_WINDOW
)
221 dc
->w
.DCOrgX
= Wnd
->WindowRect
.left
;
222 dc
->w
.DCOrgY
= Wnd
->WindowRect
.top
;
226 dc
->w
.DCOrgX
= Wnd
->ClientRect
.left
;
227 dc
->w
.DCOrgY
= Wnd
->ClientRect
.top
;
235 DceDeleteClipRgn(DCE
* Dce
)
237 Dce
->DCXFlags
&= ~(DCX_EXCLUDERGN
| DCX_INTERSECTRGN
);
239 if (Dce
->DCXFlags
& DCX_KEEPCLIPRGN
)
241 Dce
->DCXFlags
&= ~DCX_KEEPCLIPRGN
;
243 else if (Dce
->hClipRgn
!= NULL
)
245 NtGdiDeleteObject(Dce
->hClipRgn
);
248 Dce
->hClipRgn
= NULL
;
250 /* make it dirty so that the vis rgn gets recomputed next time */
251 Dce
->DCXFlags
|= DCX_DCEDIRTY
;
255 DceReleaseDC(DCE
* dce
, BOOL EndPaint
)
257 if (DCX_DCEBUSY
!= (dce
->DCXFlags
& (DCX_DCEEMPTY
| DCX_DCEBUSY
)))
262 /* restore previous visible region */
264 if ((dce
->DCXFlags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
)) &&
265 ((dce
->DCXFlags
& DCX_CACHE
) || EndPaint
))
267 DceDeleteClipRgn(dce
);
270 if (dce
->DCXFlags
& DCX_CACHE
)
272 if (!(dce
->DCXFlags
& DCX_NORESETATTRS
))
275 /* make the DC clean so that SetDCState doesn't try to update the vis rgn */
276 IntGdiSetHookFlags(dce
->hDC
, DCHF_VALIDATEVISRGN
);
278 dc
= DC_LockDc ( dce
->hDC
);
279 IntGdiCopyFromSaveState(dc
, defaultDCstate
, dce
->hDC
); // Was SetDCState.
281 dce
->DCXFlags
&= ~DCX_DCEBUSY
;
282 if (dce
->DCXFlags
& DCX_DCEDIRTY
)
284 /* don't keep around invalidated entries
285 * because SetDCState() disables hVisRgn updates
286 * by removing dirty bit. */
287 dce
->hwndCurrent
= 0;
288 dce
->DCXFlags
&= DCX_CACHE
;
289 dce
->DCXFlags
|= DCX_DCEEMPTY
;
293 { // Save Users Dc_Attr.
294 PDC dc
= DC_LockDc(dce
->hDC
);
297 PDC_ATTR Dc_Attr
= dc
->pDc_Attr
;
298 if(Dc_Attr
) MmCopyFromCaller(&dc
->Dc_Attr
, Dc_Attr
, sizeof(DC_ATTR
));
302 DPRINT("Exit!!!!! DCX_CACHE!!!!!! hDC-> %x \n", dce
->hDC
);
303 DC_FreeDcAttr(dce
->hDC
); // Free the dcattr.
304 DC_SetOwnership(dce
->hDC
, NULL
); // Set hDC inaccessible mode.
305 dce
->pProcess
= NULL
; // Reset ownership.
311 DceUpdateVisRgn(DCE
*Dce
, PWINDOW_OBJECT Window
, ULONG Flags
)
313 HANDLE hRgnVisible
= NULL
;
315 PWINDOW_OBJECT DesktopWindow
;
317 if (Flags
& DCX_PARENTCLIP
)
319 PWINDOW_OBJECT Parent
;
322 Parent
= Window
->Parent
;
329 ParentWnd
= Parent
->Wnd
;
331 if (ParentWnd
->Style
& WS_CLIPSIBLINGS
)
333 DcxFlags
= DCX_CLIPSIBLINGS
|
334 (Flags
& ~(DCX_CLIPCHILDREN
| DCX_WINDOW
));
338 DcxFlags
= Flags
& ~(DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
| DCX_WINDOW
);
340 hRgnVisible
= DceGetVisRgn(Parent
, DcxFlags
, Window
->hSelf
, Flags
);
342 else if (Window
== NULL
)
344 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
345 if (NULL
!= DesktopWindow
)
347 hRgnVisible
= UnsafeIntCreateRectRgnIndirect(&DesktopWindow
->Wnd
->WindowRect
);
356 hRgnVisible
= DceGetVisRgn(Window
, Flags
, 0, 0);
360 if (Flags
& DCX_INTERSECTRGN
)
362 if(Dce
->hClipRgn
!= NULL
)
364 NtGdiCombineRgn(hRgnVisible
, hRgnVisible
, Dce
->hClipRgn
, RGN_AND
);
368 if(hRgnVisible
!= NULL
)
370 NtGdiDeleteObject(hRgnVisible
);
372 hRgnVisible
= NtGdiCreateRectRgn(0, 0, 0, 0);
376 if (Flags
& DCX_EXCLUDERGN
&& Dce
->hClipRgn
!= NULL
)
378 NtGdiCombineRgn(hRgnVisible
, hRgnVisible
, Dce
->hClipRgn
, RGN_DIFF
);
381 Dce
->DCXFlags
&= ~DCX_DCEDIRTY
;
382 IntGdiSelectVisRgn(Dce
->hDC
, hRgnVisible
);
386 IntEngWindowChanged(Window
, WOC_RGN_CLIENT
);
389 if (hRgnVisible
!= NULL
)
391 NtGdiDeleteObject(hRgnVisible
);
396 UserGetDCEx(PWINDOW_OBJECT Window OPTIONAL
, HANDLE ClipRegion
, ULONG Flags
)
398 PWINDOW_OBJECT Parent
;
401 BOOL UpdateVisRgn
= TRUE
;
402 BOOL UpdateClipOrigin
= FALSE
;
407 Flags
&= ~DCX_USESTYLE
;
412 if (NULL
== Window
|| NULL
== Window
->Dce
)
417 if (Flags
& DCX_USESTYLE
)
419 Flags
&= ~(DCX_CLIPCHILDREN
| DCX_CLIPSIBLINGS
| DCX_PARENTCLIP
);
421 if (Wnd
->Style
& WS_CLIPSIBLINGS
)
423 Flags
|= DCX_CLIPSIBLINGS
;
426 if (!(Flags
& DCX_WINDOW
))
428 if (Wnd
->Class
->Style
& CS_PARENTDC
)
430 Flags
|= DCX_PARENTCLIP
;
433 if (Wnd
->Style
& WS_CLIPCHILDREN
&&
434 !(Wnd
->Style
& WS_MINIMIZE
))
436 Flags
|= DCX_CLIPCHILDREN
;
445 if (Flags
& DCX_NOCLIPCHILDREN
)
448 Flags
&= ~(DCX_PARENTCLIP
| DCX_CLIPCHILDREN
);
451 if (Flags
& DCX_WINDOW
)
453 Flags
= (Flags
& ~DCX_CLIPCHILDREN
) | DCX_CACHE
;
456 Parent
= (Window
? Window
->Parent
: NULL
);
458 if (NULL
== Window
|| !(Wnd
->Style
& WS_CHILD
) || NULL
== Parent
)
460 Flags
&= ~DCX_PARENTCLIP
;
462 else if (Flags
& DCX_PARENTCLIP
)
465 if ((Wnd
->Style
& WS_VISIBLE
) &&
466 (Parent
->Wnd
->Style
& WS_VISIBLE
))
468 Flags
&= ~DCX_CLIPCHILDREN
;
469 if (Parent
->Wnd
->Style
& WS_CLIPSIBLINGS
)
471 Flags
|= DCX_CLIPSIBLINGS
;
476 DcxFlags
= Flags
& DCX_CACHECOMPAREMASK
;
478 if (Flags
& DCX_CACHE
)
480 DCE
* DceEmpty
= NULL
;
481 DCE
* DceUnused
= NULL
;
482 KeEnterCriticalRegion();
483 for (Dce
= FirstDce
; Dce
!= NULL
; Dce
= Dce
->next
)
485 if ((Dce
->DCXFlags
& (DCX_CACHE
| DCX_DCEBUSY
)) == DCX_CACHE
)
488 if (Dce
->DCXFlags
& DCX_DCEEMPTY
)
492 else if (Dce
->hwndCurrent
== (Window
? Window
->hSelf
: NULL
) &&
493 ((Dce
->DCXFlags
& DCX_CACHECOMPAREMASK
) == DcxFlags
))
496 UpdateVisRgn
= FALSE
;
499 UpdateClipOrigin
= TRUE
;
504 KeLeaveCriticalRegion();
508 Dce
= (DceEmpty
== NULL
) ? DceUnused
: DceEmpty
;
513 Dce
= DceAllocDCE(NULL
, DCE_CACHE_DC
);
519 if (NULL
!= Dce
&& Dce
->hwndCurrent
== (Window
? Window
->hSelf
: NULL
))
521 UpdateVisRgn
= FALSE
; /* updated automatically, via DCHook() */
525 /* we should free dce->clip_rgn here, but Windows apparently doesn't */
526 Dce
->DCXFlags
&= ~(DCX_EXCLUDERGN
| DCX_INTERSECTRGN
);
527 Dce
->hClipRgn
= NULL
;
540 Dce
->hwndCurrent
= (Window
? Window
->hSelf
: NULL
);
541 Dce
->DCXFlags
= Flags
| DCX_DCEBUSY
;
543 if (0 == (Flags
& (DCX_EXCLUDERGN
| DCX_INTERSECTRGN
)) && NULL
!= ClipRegion
)
545 if (Flags
& DCX_KEEPCLIPRGN
)
546 NtGdiDeleteObject(ClipRegion
);
551 if (NULL
!= Dce
->hClipRgn
)
553 DceDeleteClipRgn(Dce
);
554 Dce
->hClipRgn
= NULL
;
558 if (0 != (Flags
& DCX_INTERSECTUPDATE
) && NULL
== ClipRegion
)
560 Flags
|= DCX_INTERSECTRGN
| DCX_KEEPCLIPRGN
;
561 Dce
->DCXFlags
|= DCX_INTERSECTRGN
| DCX_KEEPCLIPRGN
;
562 ClipRegion
= Window
->UpdateRegion
;
565 if (ClipRegion
== (HRGN
) 1)
567 if (!(Flags
& DCX_WINDOW
))
569 Dce
->hClipRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->Wnd
->ClientRect
);
573 Dce
->hClipRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->Wnd
->WindowRect
);
576 else if (ClipRegion
!= NULL
)
578 Dce
->hClipRgn
= ClipRegion
;
581 DceSetDrawable(Window
, Dce
->hDC
, Flags
, UpdateClipOrigin
);
585 DceUpdateVisRgn(Dce
, Window
, Flags
);
588 if (Dce
->DCXFlags
& DCX_CACHE
)
590 DPRINT("ENTER!!!!!! DCX_CACHE!!!!!! hDC-> %x\n", Dce
->hDC
);
591 // Need to set ownership so Sync dcattr will work.
592 DC_SetOwnership( Dce
->hDC
, PsGetCurrentProcess());
593 DC_AllocateDcAttr( Dce
->hDC
); // Allocate new dcattr
594 DCU_SynchDcAttrtoUser( Dce
->hDC
); // Copy data from dc to dcattr
595 Dce
->pProcess
= PsGetCurrentProcess(); // Set the temp owning process
603 NtUserGetDCEx(HWND hWnd OPTIONAL
, HANDLE ClipRegion
, ULONG Flags
)
605 PWINDOW_OBJECT Wnd
=NULL
;
608 DPRINT("Enter NtUserGetDCEx\n");
609 UserEnterExclusive();
611 if (hWnd
&& !(Wnd
= UserGetWindowObject(hWnd
)))
616 RETURN( UserGetDCEx(Wnd
, ClipRegion
, Flags
));
619 DPRINT("Leave NtUserGetDCEx, ret=%i\n",_ret_
);
626 DCE_Cleanup(PDCE pDce
)
629 KeEnterCriticalRegion();
630 if (pDce
== FirstDce
)
632 FirstDce
= pDce
->next
;
637 for (PrevInList
= FirstDce
; NULL
!= PrevInList
; PrevInList
= PrevInList
->next
)
639 if (pDce
== PrevInList
->next
)
641 PrevInList
->next
= pDce
->next
;
645 assert(NULL
!= PrevInList
);
647 KeLeaveCriticalRegion();
648 return NULL
!= PrevInList
;
652 IntWindowFromDC(HDC hDc
)
656 KeEnterCriticalRegion();
657 for (Dce
= FirstDce
; Dce
!= NULL
; Dce
= Dce
->next
)
661 Ret
= Dce
->hwndCurrent
;
665 KeLeaveCriticalRegion();
671 UserReleaseDC(PWINDOW_OBJECT Window
, HDC hDc
, BOOL EndPaint
)
678 DPRINT("%p %p\n", Window
, hDc
);
679 KeEnterCriticalRegion();
680 while (dce
&& (dce
->hDC
!= hDc
))
684 KeLeaveCriticalRegion();
685 if (dce
&& (dce
->DCXFlags
& DCX_DCEBUSY
))
687 nRet
= DceReleaseDC(dce
, EndPaint
);
694 /***********************************************************************
698 DceFreeDCE(PDCE pdce
, BOOLEAN Force
)
711 SetDCHook(pdce
->hDC
, NULL
, 0L);
714 if(Force
&& !GDIOBJ_OwnedByCurrentProcess(GdiHandleTable
, pdce
->hDC
))
716 DPRINT1("Change ownership for DCE!\n");
718 if(!IsObjectDead((HGDIOBJ
) pdce
->hDC
))
719 DC_SetOwnership( pdce
->hDC
, PsGetCurrentProcess());
722 DPRINT1("Attempted to change ownership of an DCEhDC 0x%x currently being destroyed!!!\n",pdce
->hDC
);
726 NtGdiDeleteObjectApp(pdce
->hDC
);
727 if (pdce
->hClipRgn
&& ! (pdce
->DCXFlags
& DCX_KEEPCLIPRGN
))
729 NtGdiDeleteObject(pdce
->hClipRgn
);
733 ExFreePoolWithTag(pdce
, TAG_PDCE
);
735 if (FirstDce
== NULL
)
737 ExFreePoolWithTag(defaultDCstate
, TAG_DC
);
738 defaultDCstate
= NULL
;
743 /***********************************************************************
746 * Remove owned DCE and reset unreleased cache DCEs.
749 DceFreeWindowDCE(PWINDOW_OBJECT Window
)
754 KeEnterCriticalRegion();
757 if (pDCE
->hwndCurrent
== Window
->hSelf
)
759 if (pDCE
== Window
->Dce
) /* owned or Class DCE*/
761 if (Window
->Wnd
->Class
->Style
& CS_OWNDC
) /* owned DCE*/
763 pDCE
= DceFreeDCE(pDCE
, FALSE
);
767 else if (pDCE
->DCXFlags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
)) /* Class DCE*/
769 DceDeleteClipRgn(pDCE
);
770 pDCE
->hwndCurrent
= 0;
775 if (pDCE
->DCXFlags
& DCX_DCEBUSY
) /* shared cache DCE */
777 /* FIXME: AFAICS we are doing the right thing here so
778 * this should be a DPRINT. But this is best left as an ERR
779 * because the 'application error' is likely to come from
780 * another part of Wine (i.e. it's our fault after all).
781 * We should change this to DPRINT when ReactOS is more stable
784 DPRINT1("[%p] GetDC() without ReleaseDC()!\n", Window
->hSelf
);
785 DceReleaseDC(pDCE
, FALSE
);
788 pDCE
->DCXFlags
&= DCX_CACHE
;
789 pDCE
->DCXFlags
|= DCX_DCEEMPTY
;
790 pDCE
->hwndCurrent
= 0;
795 KeLeaveCriticalRegion();
801 while (FirstDce
!= NULL
)
803 FirstDce
= DceFreeDCE(FirstDce
, TRUE
);
808 DceResetActiveDCEs(PWINDOW_OBJECT Window
)
812 PWINDOW_OBJECT CurrentWindow
;
823 if (0 == (pDCE
->DCXFlags
& DCX_DCEEMPTY
))
825 if (Window
->hSelf
== pDCE
->hwndCurrent
)
827 CurrentWindow
= Window
;
831 CurrentWindow
= UserGetWindowObject(pDCE
->hwndCurrent
);
832 if (NULL
== CurrentWindow
)
839 dc
= DC_LockDc(pDCE
->hDC
);
842 // if (Window->hSelf != pDCE->hwndCurrent)
844 // UserDerefObject(CurrentWindow);
849 if (Window
== CurrentWindow
|| IntIsChildWindow(Window
, CurrentWindow
))
851 if (pDCE
->DCXFlags
& DCX_WINDOW
)
853 DeltaX
= CurrentWindow
->Wnd
->WindowRect
.left
- dc
->w
.DCOrgX
;
854 DeltaY
= CurrentWindow
->Wnd
->WindowRect
.top
- dc
->w
.DCOrgY
;
855 dc
->w
.DCOrgX
= CurrentWindow
->Wnd
->WindowRect
.left
;
856 dc
->w
.DCOrgY
= CurrentWindow
->Wnd
->WindowRect
.top
;
860 DeltaX
= CurrentWindow
->Wnd
->ClientRect
.left
- dc
->w
.DCOrgX
;
861 DeltaY
= CurrentWindow
->Wnd
->ClientRect
.top
- dc
->w
.DCOrgY
;
862 dc
->w
.DCOrgX
= CurrentWindow
->Wnd
->ClientRect
.left
;
863 dc
->w
.DCOrgY
= CurrentWindow
->Wnd
->ClientRect
.top
;
865 if (NULL
!= dc
->w
.hClipRgn
)
867 int FASTCALL
CLIPPING_UpdateGCRegion(DC
* Dc
);
868 NtGdiOffsetRgn(dc
->w
.hClipRgn
, DeltaX
, DeltaY
);
869 CLIPPING_UpdateGCRegion(dc
);
871 if (NULL
!= pDCE
->hClipRgn
)
873 NtGdiOffsetRgn(pDCE
->hClipRgn
, DeltaX
, DeltaY
);
878 DceUpdateVisRgn(pDCE
, CurrentWindow
, pDCE
->DCXFlags
);
880 if (Window
->hSelf
!= pDCE
->hwndCurrent
)
882 // IntEngWindowChanged(CurrentWindow, WOC_RGN_CLIENT);
883 // UserDerefObject(CurrentWindow);
891 #define COPY_DEVMODE_VALUE_TO_CALLER(dst, src, member) \
892 Status = MmCopyToCaller(&(dst)->member, &(src)->member, sizeof ((src)->member)); \
893 if (!NT_SUCCESS(Status)) \
895 SetLastNtError(Status); \
902 NtUserEnumDisplaySettings(
903 PUNICODE_STRING lpszDeviceName
,
905 LPDEVMODEW lpDevMode
, /* FIXME is this correct? */
909 LPDEVMODEW pSafeDevMode
;
910 PUNICODE_STRING pSafeDeviceName
= NULL
;
911 UNICODE_STRING SafeDeviceName
;
912 USHORT Size
= 0, ExtraSize
= 0;
914 /* Copy the devmode */
915 Status
= MmCopyFromCaller(&Size
, &lpDevMode
->dmSize
, sizeof (Size
));
916 if (!NT_SUCCESS(Status
))
918 SetLastNtError(Status
);
921 Status
= MmCopyFromCaller(&ExtraSize
, &lpDevMode
->dmDriverExtra
, sizeof (ExtraSize
));
922 if (!NT_SUCCESS(Status
))
924 SetLastNtError(Status
);
927 pSafeDevMode
= ExAllocatePool(PagedPool
, Size
+ ExtraSize
);
928 if (pSafeDevMode
== NULL
)
930 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
933 pSafeDevMode
->dmSize
= Size
;
934 pSafeDevMode
->dmDriverExtra
= ExtraSize
;
936 /* Copy the device name */
937 if (lpszDeviceName
!= NULL
)
939 Status
= IntSafeCopyUnicodeString(&SafeDeviceName
, lpszDeviceName
);
940 if (!NT_SUCCESS(Status
))
942 ExFreePool(pSafeDevMode
);
943 SetLastNtError(Status
);
946 pSafeDeviceName
= &SafeDeviceName
;
949 /* Call internal function */
950 if (!IntEnumDisplaySettings(pSafeDeviceName
, iModeNum
, pSafeDevMode
, dwFlags
))
952 if (pSafeDeviceName
!= NULL
)
953 RtlFreeUnicodeString(pSafeDeviceName
);
954 ExFreePool(pSafeDevMode
);
957 if (pSafeDeviceName
!= NULL
)
958 RtlFreeUnicodeString(pSafeDeviceName
);
960 /* Copy some information back */
961 COPY_DEVMODE_VALUE_TO_CALLER(lpDevMode
, pSafeDevMode
, dmPelsWidth
);
962 COPY_DEVMODE_VALUE_TO_CALLER(lpDevMode
, pSafeDevMode
, dmPelsHeight
);
963 COPY_DEVMODE_VALUE_TO_CALLER(lpDevMode
, pSafeDevMode
, dmBitsPerPel
);
964 COPY_DEVMODE_VALUE_TO_CALLER(lpDevMode
, pSafeDevMode
, dmDisplayFrequency
);
965 COPY_DEVMODE_VALUE_TO_CALLER(lpDevMode
, pSafeDevMode
, dmDisplayFlags
);
967 /* output private/extra driver data */
970 Status
= MmCopyToCaller((PCHAR
)lpDevMode
+ Size
, (PCHAR
)pSafeDevMode
+ Size
, ExtraSize
);
971 if (!NT_SUCCESS(Status
))
973 SetLastNtError(Status
);
974 ExFreePool(pSafeDevMode
);
979 ExFreePool(pSafeDevMode
);
983 #undef COPY_DEVMODE_VALUE_TO_CALLER
988 NtUserChangeDisplaySettings(
989 PUNICODE_STRING lpszDeviceName
,
990 LPDEVMODEW lpDevMode
,
997 PUNICODE_STRING pSafeDeviceName
= NULL
;
998 UNICODE_STRING SafeDeviceName
;
1001 /* Check arguments */
1002 #ifdef CDS_VIDEOPARAMETERS
1004 if (dwflags
!= CDS_VIDEOPARAMETERS
&& lParam
!= NULL
)
1011 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1012 return DISP_CHANGE_BADPARAM
;
1016 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1017 return DISP_CHANGE_BADPARAM
;
1021 Status
= MmCopyFromCaller(&DevMode
.dmSize
, &lpDevMode
->dmSize
, sizeof (DevMode
.dmSize
));
1022 if (!NT_SUCCESS(Status
))
1024 SetLastNtError(Status
);
1025 return DISP_CHANGE_BADPARAM
;
1027 DevMode
.dmSize
= min(sizeof (DevMode
), DevMode
.dmSize
);
1028 Status
= MmCopyFromCaller(&DevMode
, lpDevMode
, DevMode
.dmSize
);
1029 if (!NT_SUCCESS(Status
))
1031 SetLastNtError(Status
);
1032 return DISP_CHANGE_BADPARAM
;
1034 if (DevMode
.dmDriverExtra
> 0)
1036 DbgPrint("(%s:%i) WIN32K: %s lpDevMode->dmDriverExtra is IGNORED!\n", __FILE__
, __LINE__
, __FUNCTION__
);
1037 DevMode
.dmDriverExtra
= 0;
1040 /* Copy the device name */
1041 if (lpszDeviceName
!= NULL
)
1043 Status
= IntSafeCopyUnicodeString(&SafeDeviceName
, lpszDeviceName
);
1044 if (!NT_SUCCESS(Status
))
1046 SetLastNtError(Status
);
1047 return DISP_CHANGE_BADPARAM
;
1049 pSafeDeviceName
= &SafeDeviceName
;
1052 /* Call internal function */
1053 Ret
= IntChangeDisplaySettings(pSafeDeviceName
, &DevMode
, dwflags
, lParam
);
1055 if (pSafeDeviceName
!= NULL
)
1056 RtlFreeUnicodeString(pSafeDeviceName
);
1062 * Select logical palette into device context.
1063 * \param hDC handle to the device context
1064 * \param hpal handle to the palette
1065 * \param ForceBackground If this value is FALSE the logical palette will be copied to the device palette only when the applicatioon
1066 * is in the foreground. If this value is TRUE then map the colors in the logical palette to the device
1067 * palette colors in the best way.
1068 * \return old palette
1070 * \todo implement ForceBackground == TRUE
1072 HPALETTE STDCALL
NtUserSelectPalette(HDC hDC
,
1074 BOOL ForceBackground
)
1077 HPALETTE oldPal
= NULL
;
1080 // FIXME: mark the palette as a [fore\back]ground pal
1081 dc
= DC_LockDc(hDC
);
1084 /* Check if this is a valid palette handle */
1085 PalGDI
= PALETTE_LockPalette(hpal
);
1088 /* Is this a valid palette for this depth? */
1089 if ((dc
->w
.bitsPerPixel
<= 8 && PAL_INDEXED
== PalGDI
->Mode
)
1090 || (8 < dc
->w
.bitsPerPixel
&& PAL_INDEXED
!= PalGDI
->Mode
))
1092 PALETTE_UnlockPalette(PalGDI
);
1093 oldPal
= dc
->w
.hPalette
;
1094 dc
->w
.hPalette
= hpal
;
1096 else if (8 < dc
->w
.bitsPerPixel
&& PAL_INDEXED
== PalGDI
->Mode
)
1098 PALETTE_UnlockPalette(PalGDI
);
1099 oldPal
= dc
->PalIndexed
;
1100 dc
->PalIndexed
= hpal
;
1104 PALETTE_UnlockPalette(PalGDI
);