2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: subsystems/win32/win32k/ntuser/windc.c
5 * PURPOSE: Keyboard layout management
6 * COPYRIGHT: Copyright 2007 ReactOS
10 /* INCLUDES ******************************************************************/
17 /* GLOBALS *******************************************************************/
19 /* NOTE - I think we should store this per window station (including gdi objects) */
21 static PDCE FirstDce
= NULL
;
22 static PDC defaultDCstate
= NULL
;
23 //static INT DCECount = 0; // Count of DCE in system.
25 #define DCX_CACHECOMPAREMASK (DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN | \
26 DCX_CACHE | DCX_WINDOW | DCX_PARENTCLIP)
28 /* FUNCTIONS *****************************************************************/
31 // This should be moved to dc.c or dcutil.c.
34 DceCreateDisplayDC(VOID
)
37 UNICODE_STRING DriverName
;
38 RtlInitUnicodeString(&DriverName
, L
"DISPLAY");
39 hDC
= IntGdiCreateDC(&DriverName
, NULL
, NULL
, NULL
, FALSE
);
41 // If NULL, first time through! Build the default window dc!
43 if (hDC
&& !defaultDCstate
) // Ultra HAX! Dedicated to GvG!
44 { // This is a cheesy way to do this.
45 PDC dc
= DC_LockDc ( hDC
);
46 defaultDCstate
= ExAllocatePoolWithTag(PagedPool
, sizeof(DC
), TAG_DC
);
47 RtlZeroMemory(defaultDCstate
, sizeof(DC
));
48 IntGdiCopyToSaveState(dc
, defaultDCstate
);
56 DceGetVisRgn(PWINDOW_OBJECT Window
, ULONG Flags
, HWND hWndChild
, ULONG CFlags
)
60 VisRgn
= VIS_ComputeVisibleRegion( Window
,
61 0 == (Flags
& DCX_WINDOW
),
62 0 != (Flags
& DCX_CLIPCHILDREN
),
63 0 != (Flags
& DCX_CLIPSIBLINGS
));
66 VisRgn
= NtGdiCreateRectRgn(0, 0, 0, 0);
73 DceAllocDCE(PWINDOW_OBJECT Window OPTIONAL
, DCE_TYPE Type
)
79 if (Window
) Wnd
= Window
->Wnd
;
81 if (Wnd
) Class
= Wnd
->Class
;
83 if (Type
== DCE_CLASS_DC
)
86 KeEnterCriticalRegion();
90 if (pdce
->Class
== Class
)
93 KeLeaveCriticalRegion();
96 pdce
= (PDCE
)pdce
->List
.Flink
;
97 } while (pdce
!= FirstDce
);
98 KeLeaveCriticalRegion();
101 pDce
= ExAllocatePoolWithTag(PagedPool
, sizeof(DCE
), TAG_PDCE
);
105 pDce
->hDC
= DceCreateDisplayDC();
108 ExFreePoolWithTag(pDce
, TAG_PDCE
);
112 pDce
->hwndCurrent
= (Window
? Window
->hSelf
: NULL
);
113 pDce
->hClipRgn
= NULL
;
114 pDce
->pProcess
= NULL
;
118 KeEnterCriticalRegion();
119 if (FirstDce
== NULL
)
122 InitializeListHead(&FirstDce
->List
);
125 InsertTailList(&FirstDce
->List
, &pDce
->List
);
126 KeLeaveCriticalRegion();
128 DCU_SetDcUndeletable(pDce
->hDC
);
130 if (Type
== DCE_WINDOW_DC
|| Type
== DCE_CLASS_DC
) //Window DCE have ownership.
131 { // Process should already own it.
132 pDce
->pProcess
= PsGetCurrentProcess();
136 PDC dc
= DC_LockDc ( pDce
->hDC
);
137 DPRINT("FREE DCATTR!!!! NOT DCE_WINDOW_DC!!!!! hDC-> %x\n", pDce
->hDC
);
138 MmCopyFromCaller(&dc
->Dc_Attr
, dc
->pDc_Attr
, sizeof(DC_ATTR
));
140 DC_FreeDcAttr(pDce
->hDC
); // Free the dcattr!
141 DC_SetOwnership(pDce
->hDC
, NULL
); // This hDC is inaccessible!
144 if (Type
== DCE_CACHE_DC
)
146 pDce
->DCXFlags
= DCX_CACHE
| DCX_DCEEMPTY
;
150 pDce
->DCXFlags
= DCX_DCEBUSY
;
153 if (Type
== DCE_WINDOW_DC
)
155 if (Wnd
->Style
& WS_CLIPCHILDREN
) pDce
->DCXFlags
|= DCX_CLIPCHILDREN
;
156 if (Wnd
->Style
& WS_CLIPSIBLINGS
) pDce
->DCXFlags
|= DCX_CLIPSIBLINGS
;
164 DceSetDrawable(PWINDOW_OBJECT Window OPTIONAL
, HDC hDC
, ULONG Flags
,
168 DC
*dc
= DC_LockDc(hDC
);
180 if (Flags
& DCX_WINDOW
)
182 dc
->w
.DCOrgX
= Wnd
->WindowRect
.left
;
183 dc
->w
.DCOrgY
= Wnd
->WindowRect
.top
;
187 dc
->w
.DCOrgX
= Wnd
->ClientRect
.left
;
188 dc
->w
.DCOrgY
= Wnd
->ClientRect
.top
;
196 DceDeleteClipRgn(DCE
* Dce
)
198 Dce
->DCXFlags
&= ~(DCX_EXCLUDERGN
| DCX_INTERSECTRGN
);
200 if (Dce
->DCXFlags
& DCX_KEEPCLIPRGN
)
202 Dce
->DCXFlags
&= ~DCX_KEEPCLIPRGN
;
204 else if (Dce
->hClipRgn
!= NULL
)
206 NtGdiDeleteObject(Dce
->hClipRgn
);
209 Dce
->hClipRgn
= NULL
;
211 /* make it dirty so that the vis rgn gets recomputed next time */
212 Dce
->DCXFlags
|= DCX_DCEDIRTY
;
216 DceReleaseDC(DCE
* dce
, BOOL EndPaint
)
218 if (DCX_DCEBUSY
!= (dce
->DCXFlags
& (DCX_DCEEMPTY
| DCX_DCEBUSY
)))
223 /* restore previous visible region */
225 if ((dce
->DCXFlags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
)) &&
226 ((dce
->DCXFlags
& DCX_CACHE
) || EndPaint
))
228 DceDeleteClipRgn(dce
);
231 if (dce
->DCXFlags
& DCX_CACHE
)
233 if (!(dce
->DCXFlags
& DCX_NORESETATTRS
))
236 /* make the DC clean so that SetDCState doesn't try to update the vis rgn */
237 IntGdiSetHookFlags(dce
->hDC
, DCHF_VALIDATEVISRGN
);
239 dc
= DC_LockDc ( dce
->hDC
);
241 IntGdiCopyFromSaveState(dc
, defaultDCstate
, dce
->hDC
); // Was SetDCState.
243 dce
->DCXFlags
&= ~DCX_DCEBUSY
;
244 if (dce
->DCXFlags
& DCX_DCEDIRTY
)
246 /* don't keep around invalidated entries
247 * because SetDCState() disables hVisRgn updates
248 * by removing dirty bit. */
249 dce
->hwndCurrent
= 0;
250 dce
->DCXFlags
&= DCX_CACHE
;
251 dce
->DCXFlags
|= DCX_DCEEMPTY
;
255 { // Save Users Dc_Attr.
256 PDC dc
= DC_LockDc(dce
->hDC
);
259 PDC_ATTR Dc_Attr
= dc
->pDc_Attr
;
260 if(Dc_Attr
) MmCopyFromCaller(&dc
->Dc_Attr
, Dc_Attr
, sizeof(DC_ATTR
));
264 DPRINT("Exit!!!!! DCX_CACHE!!!!!! hDC-> %x \n", dce
->hDC
);
265 DC_FreeDcAttr(dce
->hDC
); // Free the dcattr.
266 DC_SetOwnership(dce
->hDC
, NULL
); // Set hDC inaccessible mode.
267 dce
->pProcess
= NULL
; // Reset ownership.
273 DceUpdateVisRgn(DCE
*Dce
, PWINDOW_OBJECT Window
, ULONG Flags
)
275 HANDLE hRgnVisible
= NULL
;
277 PWINDOW_OBJECT DesktopWindow
;
279 if (Flags
& DCX_PARENTCLIP
)
281 PWINDOW_OBJECT Parent
;
284 Parent
= Window
->Parent
;
291 ParentWnd
= Parent
->Wnd
;
293 if (ParentWnd
->Style
& WS_CLIPSIBLINGS
)
295 DcxFlags
= DCX_CLIPSIBLINGS
|
296 (Flags
& ~(DCX_CLIPCHILDREN
| DCX_WINDOW
));
300 DcxFlags
= Flags
& ~(DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
| DCX_WINDOW
);
302 hRgnVisible
= DceGetVisRgn(Parent
, DcxFlags
, Window
->hSelf
, Flags
);
304 else if (Window
== NULL
)
306 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
307 if (NULL
!= DesktopWindow
)
309 hRgnVisible
= UnsafeIntCreateRectRgnIndirect(&DesktopWindow
->Wnd
->WindowRect
);
318 hRgnVisible
= DceGetVisRgn(Window
, Flags
, 0, 0);
322 if (Flags
& DCX_INTERSECTRGN
)
324 if(Dce
->hClipRgn
!= NULL
)
326 NtGdiCombineRgn(hRgnVisible
, hRgnVisible
, Dce
->hClipRgn
, RGN_AND
);
330 if(hRgnVisible
!= NULL
)
332 NtGdiDeleteObject(hRgnVisible
);
334 hRgnVisible
= NtGdiCreateRectRgn(0, 0, 0, 0);
338 if (Flags
& DCX_EXCLUDERGN
&& Dce
->hClipRgn
!= NULL
)
340 NtGdiCombineRgn(hRgnVisible
, hRgnVisible
, Dce
->hClipRgn
, RGN_DIFF
);
343 Dce
->DCXFlags
&= ~DCX_DCEDIRTY
;
344 IntGdiSelectVisRgn(Dce
->hDC
, hRgnVisible
);
348 IntEngWindowChanged(Window
, WOC_RGN_CLIENT
);
351 if (hRgnVisible
!= NULL
)
353 NtGdiDeleteObject(hRgnVisible
);
358 UserGetDCEx(PWINDOW_OBJECT Window OPTIONAL
, HANDLE ClipRegion
, ULONG Flags
)
360 PWINDOW_OBJECT Parent
;
363 BOOL UpdateVisRgn
= TRUE
;
364 BOOL UpdateClipOrigin
= FALSE
;
368 { // Do the same as GetDC with a NULL.
369 // Window = UserGetWindowObject(IntGetDesktopWindow());
370 // if (Window) Wnd = Window->Wnd;
372 Flags
&= ~DCX_USESTYLE
;
377 if (NULL
== Window
|| NULL
== Window
->Dce
)
382 if (Flags
& DCX_USESTYLE
)
384 Flags
&= ~(DCX_CLIPCHILDREN
| DCX_CLIPSIBLINGS
| DCX_PARENTCLIP
);
386 if (Wnd
->Style
& WS_CLIPSIBLINGS
)
388 Flags
|= DCX_CLIPSIBLINGS
;
391 if (!(Flags
& DCX_WINDOW
))
393 if (Wnd
->Class
->Style
& CS_PARENTDC
)
395 Flags
|= DCX_PARENTCLIP
;
398 if (Wnd
->Style
& WS_CLIPCHILDREN
&&
399 !(Wnd
->Style
& WS_MINIMIZE
))
401 Flags
|= DCX_CLIPCHILDREN
;
410 if (Flags
& DCX_NOCLIPCHILDREN
)
413 Flags
&= ~(DCX_PARENTCLIP
| DCX_CLIPCHILDREN
);
416 if (Flags
& DCX_WINDOW
)
418 Flags
= (Flags
& ~DCX_CLIPCHILDREN
) | DCX_CACHE
;
421 Parent
= (Window
? Window
->Parent
: NULL
);
423 if (NULL
== Window
|| !(Wnd
->Style
& WS_CHILD
) || NULL
== Parent
)
425 Flags
&= ~DCX_PARENTCLIP
;
427 else if (Flags
& DCX_PARENTCLIP
)
430 if ((Wnd
->Style
& WS_VISIBLE
) &&
431 (Parent
->Wnd
->Style
& WS_VISIBLE
))
433 Flags
&= ~DCX_CLIPCHILDREN
;
434 if (Parent
->Wnd
->Style
& WS_CLIPSIBLINGS
)
436 Flags
|= DCX_CLIPSIBLINGS
;
441 DcxFlags
= Flags
& DCX_CACHECOMPAREMASK
;
443 if (Flags
& DCX_CACHE
)
445 DCE
* DceEmpty
= NULL
;
446 DCE
* DceUnused
= NULL
;
447 KeEnterCriticalRegion();
451 // The reason for this you may ask?
452 // Well, it seems ReactOS calls GetDC with out first creating a desktop DC window!
453 // Need to test for null here. Not sure if this is a bug or a feature.
456 if ((Dce
->DCXFlags
& (DCX_CACHE
| DCX_DCEBUSY
)) == DCX_CACHE
)
459 if (Dce
->DCXFlags
& DCX_DCEEMPTY
)
463 else if (Dce
->hwndCurrent
== (Window
? Window
->hSelf
: NULL
) &&
464 ((Dce
->DCXFlags
& DCX_CACHECOMPAREMASK
) == DcxFlags
))
467 UpdateVisRgn
= FALSE
;
470 UpdateClipOrigin
= TRUE
;
474 Dce
= (PDCE
)Dce
->List
.Flink
;
475 } while (Dce
!= FirstDce
);
476 KeLeaveCriticalRegion();
478 Dce
= (DceEmpty
== NULL
) ? DceUnused
: DceEmpty
;
482 Dce
= DceAllocDCE(NULL
, DCE_CACHE_DC
);
488 if (Dce
->hwndCurrent
== Window
->hSelf
)
490 UpdateVisRgn
= FALSE
; /* updated automatically, via DCHook() */
494 /* we should free dce->clip_rgn here, but Windows apparently doesn't */
495 Dce
->DCXFlags
&= ~(DCX_EXCLUDERGN
| DCX_INTERSECTRGN
);
496 Dce
->hClipRgn
= NULL
;
509 if (!GDIOBJ_ValidateHandle(Dce
->hDC
, GDI_OBJECT_TYPE_DC
))
511 DPRINT1("FIXME: Got DCE with invalid hDC!\n");
512 Dce
->hDC
= DceCreateDisplayDC();
513 /* FIXME: Handle error */
516 Dce
->hwndCurrent
= (Window
? Window
->hSelf
: NULL
);
517 Dce
->DCXFlags
= Flags
| DCX_DCEBUSY
;
519 if (0 == (Flags
& (DCX_EXCLUDERGN
| DCX_INTERSECTRGN
)) && NULL
!= ClipRegion
)
521 if (!(Flags
& DCX_KEEPCLIPRGN
))
522 NtGdiDeleteObject(ClipRegion
);
527 if (NULL
!= Dce
->hClipRgn
)
529 DceDeleteClipRgn(Dce
);
533 if (0 != (Flags
& DCX_INTERSECTUPDATE
) && NULL
== ClipRegion
)
535 Flags
|= DCX_INTERSECTRGN
| DCX_KEEPCLIPRGN
;
536 Dce
->DCXFlags
|= DCX_INTERSECTRGN
| DCX_KEEPCLIPRGN
;
537 ClipRegion
= Window
->UpdateRegion
;
540 if (ClipRegion
== (HRGN
) 1)
542 if (!(Flags
& DCX_WINDOW
))
544 Dce
->hClipRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->Wnd
->ClientRect
);
548 Dce
->hClipRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->Wnd
->WindowRect
);
550 Dce
->DCXFlags
&= ~DCX_KEEPCLIPRGN
;
552 else if (ClipRegion
!= NULL
)
554 Dce
->hClipRgn
= ClipRegion
;
557 DceSetDrawable(Window
, Dce
->hDC
, Flags
, UpdateClipOrigin
);
561 DceUpdateVisRgn(Dce
, Window
, Flags
);
564 if (Dce
->DCXFlags
& DCX_CACHE
)
566 DPRINT("ENTER!!!!!! DCX_CACHE!!!!!! hDC-> %x\n", Dce
->hDC
);
567 // Need to set ownership so Sync dcattr will work.
568 DC_SetOwnership( Dce
->hDC
, PsGetCurrentProcess());
569 DC_AllocateDcAttr( Dce
->hDC
); // Allocate new dcattr
570 DCU_SynchDcAttrtoUser( Dce
->hDC
); // Copy data from dc to dcattr
571 Dce
->pProcess
= PsGetCurrentProcess(); // Set the temp owning process
576 /***********************************************************************
580 DceFreeDCE(PDCE pdce
, BOOLEAN Force
)
585 if (NULL
== pdce
) return NULL
;
587 ret
= (PDCE
) pdce
->List
.Flink
;
590 SetDCHook(pdce
->hDC
, NULL
, 0L);
593 if (Force
&& !GDIOBJ_OwnedByCurrentProcess(pdce
->hDC
))
595 DPRINT1("Change ownership for DCE!\n");
597 if (!IsObjectDead((HGDIOBJ
) pdce
->hDC
))
598 DC_SetOwnership( pdce
->hDC
, PsGetCurrentProcess());
601 DPRINT1("Attempted to change ownership of an DCEhDC 0x%x currently being destroyed!!!\n",pdce
->hDC
);
606 if (!Hit
) IntGdiDeleteDC(pdce
->hDC
, TRUE
);
608 if (pdce
->hClipRgn
&& ! (pdce
->DCXFlags
& DCX_KEEPCLIPRGN
))
610 NtGdiDeleteObject(pdce
->hClipRgn
);
613 RemoveEntryList(&pdce
->List
);
614 ExFreePoolWithTag(pdce
, TAG_PDCE
);
619 /***********************************************************************
622 * Remove owned DCE and reset unreleased cache DCEs.
625 DceFreeWindowDCE(PWINDOW_OBJECT Window
)
630 KeEnterCriticalRegion();
633 if (pDCE
->hwndCurrent
== Window
->hSelf
)
635 if (!(pDCE
->DCXFlags
& DCX_CACHE
)) /* owned or Class DCE*/
637 if (Window
->Wnd
->Class
->Style
& CS_CLASSDC
||
638 Window
->Wnd
->Style
& CS_CLASSDC
) /* Test Class first */
640 if (pDCE
->DCXFlags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
)) /* Class DCE*/
641 DceDeleteClipRgn(pDCE
);
642 // Update and reset Vis Rgn and clear the dirty bit.
643 // Should release VisRgn than reset it to default.
644 DceUpdateVisRgn(pDCE
, Window
, pDCE
->DCXFlags
);
645 pDCE
->DCXFlags
= DCX_DCEEMPTY
;
646 pDCE
->hwndCurrent
= 0;
648 else if (Window
->Wnd
->Class
->Style
& CS_OWNDC
||
649 Window
->Wnd
->Style
& CS_OWNDC
) /* owned DCE*/
651 pDCE
= DceFreeDCE(pDCE
, FALSE
);
662 if (pDCE
->DCXFlags
& DCX_DCEBUSY
) /* shared cache DCE */
664 /* FIXME: AFAICS we are doing the right thing here so
665 * this should be a DPRINT. But this is best left as an ERR
666 * because the 'application error' is likely to come from
667 * another part of Wine (i.e. it's our fault after all).
668 * We should change this to DPRINT when ReactOS is more stable
671 DPRINT1("[%p] GetDC() without ReleaseDC()!\n", Window
->hSelf
);
672 DceReleaseDC(pDCE
, FALSE
);
674 pDCE
->DCXFlags
|= DCX_DCEEMPTY
;
675 pDCE
->hwndCurrent
= 0;
678 pDCE
= (PDCE
) pDCE
->List
.Flink
;
679 } while (pDCE
!= FirstDce
);
680 KeLeaveCriticalRegion();
686 while (FirstDce
!= NULL
)
688 FirstDce
= DceFreeDCE(FirstDce
, TRUE
);
693 DceResetActiveDCEs(PWINDOW_OBJECT Window
)
697 PWINDOW_OBJECT CurrentWindow
;
706 if(!pDCE
) return; // Another null test!
709 if (0 == (pDCE
->DCXFlags
& DCX_DCEEMPTY
))
711 if (Window
->hSelf
== pDCE
->hwndCurrent
)
713 CurrentWindow
= Window
;
717 CurrentWindow
= UserGetWindowObject(pDCE
->hwndCurrent
);
718 if (NULL
== CurrentWindow
)
720 pDCE
= (PDCE
) pDCE
->List
.Flink
;
725 if (!GDIOBJ_ValidateHandle(pDCE
->hDC
, GDI_OBJECT_TYPE_DC
) ||
726 (dc
= DC_LockDc(pDCE
->hDC
)) == NULL
)
728 pDCE
= (PDCE
) pDCE
->List
.Flink
;
731 if (Window
== CurrentWindow
|| IntIsChildWindow(Window
, CurrentWindow
))
733 if (pDCE
->DCXFlags
& DCX_WINDOW
)
735 DeltaX
= CurrentWindow
->Wnd
->WindowRect
.left
- dc
->w
.DCOrgX
;
736 DeltaY
= CurrentWindow
->Wnd
->WindowRect
.top
- dc
->w
.DCOrgY
;
737 dc
->w
.DCOrgX
= CurrentWindow
->Wnd
->WindowRect
.left
;
738 dc
->w
.DCOrgY
= CurrentWindow
->Wnd
->WindowRect
.top
;
742 DeltaX
= CurrentWindow
->Wnd
->ClientRect
.left
- dc
->w
.DCOrgX
;
743 DeltaY
= CurrentWindow
->Wnd
->ClientRect
.top
- dc
->w
.DCOrgY
;
744 dc
->w
.DCOrgX
= CurrentWindow
->Wnd
->ClientRect
.left
;
745 dc
->w
.DCOrgY
= CurrentWindow
->Wnd
->ClientRect
.top
;
747 if (NULL
!= dc
->w
.hClipRgn
)
749 int FASTCALL
CLIPPING_UpdateGCRegion(DC
* Dc
);
750 NtGdiOffsetRgn(dc
->w
.hClipRgn
, DeltaX
, DeltaY
);
751 CLIPPING_UpdateGCRegion(dc
);
753 if (NULL
!= pDCE
->hClipRgn
)
755 NtGdiOffsetRgn(pDCE
->hClipRgn
, DeltaX
, DeltaY
);
760 DceUpdateVisRgn(pDCE
, CurrentWindow
, pDCE
->DCXFlags
);
762 if (Window
->hSelf
!= pDCE
->hwndCurrent
)
764 // IntEngWindowChanged(CurrentWindow, WOC_RGN_CLIENT);
765 // UserDerefObject(CurrentWindow);
768 pDCE
=(PDCE
) pDCE
->List
.Flink
;
769 } while (pDCE
!= FirstDce
);
774 IntGetDC(PWINDOW_OBJECT Window
)
778 //"hWnd [in] Handle to the window whose DC is to be retrieved.
779 // If this value is NULL, GetDC retrieves the DC for the entire screen."
780 Window
= UserGetWindowObject(IntGetDesktopWindow());
782 return UserGetDCEx(Window
, NULL
, DCX_CACHE
| DCX_WINDOW
);
786 return UserGetDCEx(Window
, NULL
, DCX_USESTYLE
);
790 IntWindowFromDC(HDC hDc
)
794 KeEnterCriticalRegion();
800 Ret
= Dce
->hwndCurrent
;
803 Dce
= (PDCE
)Dce
->List
.Flink
;
804 } while (Dce
!= FirstDce
);
805 KeLeaveCriticalRegion();
810 UserReleaseDC(PWINDOW_OBJECT Window
, HDC hDc
, BOOL EndPaint
)
816 DPRINT("%p %p\n", Window
, hDc
);
818 KeEnterCriticalRegion();
827 dce
= (PDCE
) dce
->List
.Flink
;
829 while (dce
!= FirstDce
);
830 KeLeaveCriticalRegion();
832 if ( Hit
&& (dce
->DCXFlags
& DCX_DCEBUSY
))
834 nRet
= DceReleaseDC(dce
, EndPaint
);
841 UserGetWindowDC(PWINDOW_OBJECT Wnd
)
843 return UserGetDCEx(Wnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
847 NtUserGetDCEx(HWND hWnd OPTIONAL
, HANDLE ClipRegion
, ULONG Flags
)
849 PWINDOW_OBJECT Wnd
=NULL
;
852 DPRINT("Enter NtUserGetDCEx\n");
853 UserEnterExclusive();
855 if (hWnd
&& !(Wnd
= UserGetWindowObject(hWnd
)))
860 RETURN( UserGetDCEx(Wnd
, ClipRegion
, Flags
));
863 DPRINT("Leave NtUserGetDCEx, ret=%i\n",_ret_
);
871 * The NtUserGetWindowDC function retrieves the device context (DC) for the
872 * entire window, including title bar, menus, and scroll bars. A window device
873 * context permits painting anywhere in a window, because the origin of the
874 * device context is the upper-left corner of the window instead of the client
881 NtUserGetWindowDC(HWND hWnd
)
883 return NtUserGetDCEx(hWnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
887 NtUserGetDC(HWND hWnd
)
889 // We have a problem here! Should call IntGetDC.
890 return NtUserGetDCEx(hWnd
, NULL
, NULL
== hWnd
? DCX_CACHE
| DCX_WINDOW
: DCX_USESTYLE
);
894 * Select logical palette into device context.
895 * \param hDC handle to the device context
896 * \param hpal handle to the palette
897 * \param ForceBackground If this value is FALSE the logical palette will be copied to the device palette only when the applicatioon
898 * is in the foreground. If this value is TRUE then map the colors in the logical palette to the device
899 * palette colors in the best way.
900 * \return old palette
902 * \todo implement ForceBackground == TRUE
904 HPALETTE STDCALL
NtUserSelectPalette(HDC hDC
,
906 BOOL ForceBackground
)
909 HPALETTE oldPal
= NULL
;
912 // FIXME: mark the palette as a [fore\back]ground pal
919 /* Check if this is a valid palette handle */
920 PalGDI
= PALETTE_LockPalette(hpal
);
927 /* Is this a valid palette for this depth? */
928 if ((dc
->w
.bitsPerPixel
<= 8 && PalGDI
->Mode
== PAL_INDEXED
) ||
929 (dc
->w
.bitsPerPixel
> 8 && PalGDI
->Mode
!= PAL_INDEXED
))
931 oldPal
= dc
->DcLevel
.hpal
;
932 dc
->DcLevel
.hpal
= hpal
;
934 else if (8 < dc
->w
.bitsPerPixel
&& PAL_INDEXED
== PalGDI
->Mode
)
936 oldPal
= dc
->DcLevel
.hpal
;
937 dc
->DcLevel
.hpal
= hpal
;
940 PALETTE_UnlockPalette(PalGDI
);