[Win32SS]
[reactos.git] / reactos / win32ss / user / ntuser / painting.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Win32k subsystem
4 * PURPOSE: Window painting function
5 * FILE: win32ss/user/ntuser/painting.c
6 * PROGRAMER: Filip Navara (xnavara@volny.cz)
7 */
8
9 #include <win32k.h>
10 DBG_DEFAULT_CHANNEL(UserPainting);
11
12 #define RDW_CLIPCHILDREN 4096
13 #define RDW_NOUPDATEDIRTY 32768
14
15 /* PRIVATE FUNCTIONS **********************************************************/
16
17 /**
18 * @name IntIntersectWithParents
19 *
20 * Intersect window rectangle with all parent client rectangles.
21 *
22 * @param Child
23 * Pointer to child window to start intersecting from.
24 * @param WindowRect
25 * Pointer to rectangle that we want to intersect in screen
26 * coordinates on input and intersected rectangle on output (if TRUE
27 * is returned).
28 *
29 * @return
30 * If any parent is minimized or invisible or the resulting rectangle
31 * is empty then FALSE is returned. Otherwise TRUE is returned.
32 */
33
34 BOOL FASTCALL
35 IntIntersectWithParents(PWND Child, RECTL *WindowRect)
36 {
37 PWND ParentWnd;
38
39 if (Child->ExStyle & WS_EX_REDIRECTED)
40 return TRUE;
41
42 ParentWnd = Child->spwndParent;
43 while (ParentWnd != NULL)
44 {
45 if (!(ParentWnd->style & WS_VISIBLE) ||
46 (ParentWnd->style & WS_MINIMIZE) ||
47 !RECTL_bIntersectRect(WindowRect, WindowRect, &ParentWnd->rcClient) )
48 {
49 return FALSE;
50 }
51
52 if (ParentWnd->ExStyle & WS_EX_REDIRECTED)
53 return TRUE;
54
55 ParentWnd = ParentWnd->spwndParent;
56 }
57
58 return TRUE;
59 }
60
61 BOOL FASTCALL
62 IntValidateParents(PWND Child, BOOL Recurse)
63 {
64 RECTL ParentRect, Rect;
65 BOOL Start, Ret = TRUE;
66 PWND ParentWnd = Child;
67 PREGION Rgn = NULL;
68
69 if (ParentWnd->style & WS_CHILD)
70 {
71 do
72 ParentWnd = ParentWnd->spwndParent;
73 while (ParentWnd->style & WS_CHILD);
74 }
75
76 // No pending nonclient paints.
77 if (!(ParentWnd->state & WNDS_SYNCPAINTPENDING)) Recurse = FALSE;
78
79 Start = TRUE;
80 ParentWnd = Child->spwndParent;
81 while (ParentWnd)
82 {
83 if (ParentWnd->style & WS_CLIPCHILDREN)
84 break;
85
86 if (ParentWnd->hrgnUpdate != 0)
87 {
88 if (Recurse)
89 {
90 Ret = FALSE;
91 break;
92 }
93 // Start with child clipping.
94 if (Start)
95 {
96 Start = FALSE;
97
98 Rect = Child->rcWindow;
99
100 if (!IntIntersectWithParents(Child, &Rect)) break;
101
102 Rgn = IntSysCreateRectpRgnIndirect(&Rect);
103
104 if (Child->hrgnClip)
105 {
106 PREGION RgnClip = REGION_LockRgn(Child->hrgnClip);
107 IntGdiCombineRgn(Rgn, Rgn, RgnClip, RGN_AND);
108 REGION_UnlockRgn(RgnClip);
109 }
110 }
111
112 ParentRect = ParentWnd->rcWindow;
113
114 if (!IntIntersectWithParents(ParentWnd, &ParentRect)) break;
115
116 IntInvalidateWindows( ParentWnd,
117 Rgn,
118 RDW_VALIDATE | RDW_NOCHILDREN | RDW_NOUPDATEDIRTY);
119 }
120 ParentWnd = ParentWnd->spwndParent;
121 }
122
123 if (Rgn) REGION_Delete(Rgn);
124
125 return Ret;
126 }
127
128 /*
129 Synchronize painting to the top-level windows of other threads.
130 */
131 VOID FASTCALL
132 IntSendSyncPaint(PWND Wnd, ULONG Flags)
133 {
134 PTHREADINFO ptiCur, ptiWnd;
135 PUSER_SENT_MESSAGE Message;
136 PLIST_ENTRY Entry;
137 BOOL bSend = TRUE;
138
139 ptiWnd = Wnd->head.pti;
140 ptiCur = PsGetCurrentThreadWin32Thread();
141 /*
142 Not the current thread, Wnd is in send Nonclient paint also in send erase background and it is visiable.
143 */
144 if ( Wnd->head.pti != ptiCur &&
145 Wnd->state & WNDS_SENDNCPAINT &&
146 Wnd->state & WNDS_SENDERASEBACKGROUND &&
147 Wnd->style & WS_VISIBLE)
148 {
149 // For testing, if you see this, break out the Champagne and have a party!
150 TRACE("SendSyncPaint Wnd in State!\n");
151 if (!IsListEmpty(&ptiWnd->SentMessagesListHead))
152 {
153 // Scan sent queue messages to see if we received sync paint messages.
154 Entry = ptiWnd->SentMessagesListHead.Flink;
155 Message = CONTAINING_RECORD(Entry, USER_SENT_MESSAGE, ListEntry);
156 do
157 {
158 ERR("LOOP it\n");
159 if (Message->Msg.message == WM_SYNCPAINT &&
160 Message->Msg.hwnd == UserHMGetHandle(Wnd))
161 { // Already received so exit out.
162 ERR("SendSyncPaint Found one in the Sent Msg Queue!\n");
163 bSend = FALSE;
164 break;
165 }
166 Entry = Message->ListEntry.Flink;
167 Message = CONTAINING_RECORD(Entry, USER_SENT_MESSAGE, ListEntry);
168 }
169 while (Entry != &ptiWnd->SentMessagesListHead);
170 }
171 if (bSend)
172 {
173 TRACE("Sending WM_SYNCPAINT\n");
174 // This message has no parameters. But it does! Pass Flags along.
175 co_IntSendMessageNoWait(UserHMGetHandle(Wnd), WM_SYNCPAINT, Flags, 0);
176 Wnd->state |= WNDS_SYNCPAINTPENDING;
177 }
178 }
179
180 // Send to all the children if this is the desktop window.
181 if ( Wnd == UserGetDesktopWindow() )
182 {
183 if ( Flags & RDW_ALLCHILDREN ||
184 ( !(Flags & RDW_NOCHILDREN) && Wnd->style & WS_CLIPCHILDREN))
185 {
186 PWND spwndChild = Wnd->spwndChild;
187 while(spwndChild)
188 {
189 if ( spwndChild->style & WS_CHILD &&
190 spwndChild->head.pti != ptiCur)
191 {
192 spwndChild = spwndChild->spwndNext;
193 continue;
194 }
195 IntSendSyncPaint( spwndChild, Flags );
196 spwndChild = spwndChild->spwndNext;
197 }
198 }
199 }
200 }
201
202 /*
203 * @name IntCalcWindowRgn
204 *
205 * Get a window or client region.
206 */
207
208 HRGN FASTCALL
209 IntCalcWindowRgn(PWND Wnd, BOOL Client)
210 {
211 HRGN hRgnWindow;
212
213 if (Client)
214 {
215 hRgnWindow = NtGdiCreateRectRgn(
216 Wnd->rcClient.left,
217 Wnd->rcClient.top,
218 Wnd->rcClient.right,
219 Wnd->rcClient.bottom);
220 }
221 else
222 {
223 hRgnWindow = NtGdiCreateRectRgn(
224 Wnd->rcWindow.left,
225 Wnd->rcWindow.top,
226 Wnd->rcWindow.right,
227 Wnd->rcWindow.bottom);
228 }
229
230 if (Wnd->hrgnClip != NULL && !(Wnd->style & WS_MINIMIZE))
231 {
232 NtGdiOffsetRgn(hRgnWindow,
233 -Wnd->rcWindow.left,
234 -Wnd->rcWindow.top);
235 NtGdiCombineRgn(hRgnWindow, hRgnWindow, Wnd->hrgnClip, RGN_AND);
236 NtGdiOffsetRgn(hRgnWindow,
237 Wnd->rcWindow.left,
238 Wnd->rcWindow.top);
239 }
240
241 return hRgnWindow;
242 }
243
244 /*
245 * @name IntGetNCUpdateRgn
246 *
247 * Get non-client update region of a window and optionally validate it.
248 *
249 * @param Window
250 * Pointer to window to get the NC update region from.
251 * @param Validate
252 * Set to TRUE to force validating the NC update region.
253 *
254 * @return
255 * Handle to NC update region. The caller is responsible for deleting
256 * it.
257 */
258
259 HRGN FASTCALL
260 IntGetNCUpdateRgn(PWND Window, BOOL Validate)
261 {
262 HRGN hRgnNonClient;
263 HRGN hRgnWindow;
264 UINT RgnType, NcType;
265 RECT update;
266
267 if (Window->hrgnUpdate != NULL &&
268 Window->hrgnUpdate != HRGN_WINDOW)
269 {
270 hRgnNonClient = IntCalcWindowRgn(Window, FALSE);
271
272 /*
273 * If region creation fails it's safe to fallback to whole
274 * window region.
275 */
276 if (hRgnNonClient == NULL)
277 {
278 return HRGN_WINDOW;
279 }
280
281 hRgnWindow = IntCalcWindowRgn(Window, TRUE);
282 if (hRgnWindow == NULL)
283 {
284 GreDeleteObject(hRgnNonClient);
285 return HRGN_WINDOW;
286 }
287
288 NcType = IntGdiGetRgnBox(hRgnNonClient, &update);
289
290 RgnType = NtGdiCombineRgn(hRgnNonClient, hRgnNonClient, hRgnWindow, RGN_DIFF);
291
292 if (RgnType == ERROR)
293 {
294 GreDeleteObject(hRgnWindow);
295 GreDeleteObject(hRgnNonClient);
296 return HRGN_WINDOW;
297 }
298 else if (RgnType == NULLREGION)
299 {
300 GreDeleteObject(hRgnWindow);
301 GreDeleteObject(hRgnNonClient);
302 Window->state &= ~WNDS_UPDATEDIRTY;
303 return NULL;
304 }
305
306 /*
307 * Remove the nonclient region from the standard update region if
308 * we were asked for it.
309 */
310
311 if (Validate)
312 {
313 if (NtGdiCombineRgn(Window->hrgnUpdate, Window->hrgnUpdate, hRgnWindow, RGN_AND) == NULLREGION)
314 {
315 IntGdiSetRegionOwner(Window->hrgnUpdate, GDI_OBJ_HMGR_POWNED);
316 GreDeleteObject(Window->hrgnUpdate);
317 Window->state &= ~WNDS_UPDATEDIRTY;
318 Window->hrgnUpdate = NULL;
319 if (!(Window->state & WNDS_INTERNALPAINT))
320 MsqDecPaintCountQueue(Window->head.pti);
321 }
322 }
323
324 /* check if update rgn contains complete nonclient area */
325 if (NcType == SIMPLEREGION)
326 {
327 RECT window;
328 IntGetWindowRect( Window, &window );
329
330 if (IntEqualRect( &window, &update ))
331 {
332 GreDeleteObject(hRgnNonClient);
333 hRgnNonClient = HRGN_WINDOW;
334 }
335 }
336
337 GreDeleteObject(hRgnWindow);
338
339 return hRgnNonClient;
340 }
341 else
342 {
343 return Window->hrgnUpdate;
344 }
345 }
346
347 VOID FASTCALL
348 IntSendNCPaint(PWND pWnd, HRGN hRgn)
349 {
350 pWnd->state &= ~WNDS_SENDNCPAINT;
351
352 if ( pWnd == GetW32ThreadInfo()->MessageQueue->spwndActive &&
353 !(pWnd->state & WNDS_ACTIVEFRAME))
354 {
355 pWnd->state |= WNDS_ACTIVEFRAME;
356 pWnd->state &= ~WNDS_NONCPAINT;
357 hRgn = HRGN_WINDOW;
358 }
359
360 if (pWnd->state2 & WNDS2_FORCEFULLNCPAINTCLIPRGN)
361 {
362 pWnd->state2 &= ~WNDS2_FORCEFULLNCPAINTCLIPRGN;
363 hRgn = HRGN_WINDOW;
364 }
365
366 if (hRgn) co_IntSendMessage(UserHMGetHandle(pWnd), WM_NCPAINT, (WPARAM)hRgn, 0);
367 }
368
369 VOID FASTCALL
370 IntSendChildNCPaint(PWND pWnd)
371 {
372 pWnd = pWnd->spwndChild;
373 while(pWnd)
374 {
375 if (pWnd->hrgnUpdate == NULL && pWnd->state & WNDS_SENDNCPAINT)
376 {
377 USER_REFERENCE_ENTRY Ref;
378 UserRefObjectCo(pWnd, &Ref);
379 IntSendNCPaint(pWnd, HRGN_WINDOW);
380 UserDerefObjectCo(pWnd);
381 }
382 pWnd = pWnd->spwndNext;
383 }
384 }
385
386 /*
387 * IntPaintWindows
388 *
389 * Internal function used by IntRedrawWindow.
390 */
391
392 VOID FASTCALL
393 co_IntPaintWindows(PWND Wnd, ULONG Flags, BOOL Recurse)
394 {
395 HDC hDC;
396 HWND hWnd = Wnd->head.h;
397 HRGN TempRegion = NULL;
398
399 Wnd->state &= ~WNDS_PAINTNOTPROCESSED;
400
401 if (Wnd->state & WNDS_SENDNCPAINT ||
402 Wnd->state & WNDS_SENDERASEBACKGROUND)
403 {
404 if (!(Wnd->style & WS_VISIBLE))
405 {
406 Wnd->state &= ~(WNDS_SENDNCPAINT|WNDS_SENDERASEBACKGROUND|WNDS_ERASEBACKGROUND);
407 return;
408 }
409 else
410 {
411 if (Wnd->hrgnUpdate == NULL)
412 {
413 Wnd->state &= ~(WNDS_SENDERASEBACKGROUND|WNDS_ERASEBACKGROUND);
414 }
415
416 if (Wnd->head.pti == PsGetCurrentThreadWin32Thread())
417 {
418 if (Wnd->state & WNDS_SENDNCPAINT)
419 {
420 TempRegion = IntGetNCUpdateRgn(Wnd, TRUE);
421
422 IntSendNCPaint(Wnd, TempRegion);
423
424 if (TempRegion > HRGN_WINDOW && GreIsHandleValid(TempRegion))
425 {
426 /* NOTE: The region can already be deleted! */
427 GreDeleteObject(TempRegion);
428 }
429 }
430
431 if (Wnd->state & WNDS_SENDERASEBACKGROUND)
432 {
433 PTHREADINFO pti = PsGetCurrentThreadWin32Thread();
434 if (Wnd->hrgnUpdate)
435 {
436 hDC = UserGetDCEx( Wnd,
437 Wnd->hrgnUpdate,
438 DCX_CACHE|DCX_USESTYLE|DCX_INTERSECTRGN|DCX_KEEPCLIPRGN);
439
440 if (Wnd->head.pti->ppi != pti->ppi)
441 {
442 ERR("Sending DC to another Process!!!\n");
443 }
444
445 Wnd->state &= ~(WNDS_SENDERASEBACKGROUND|WNDS_ERASEBACKGROUND);
446 // Kill the loop, so Clear before we send.
447 if (!co_IntSendMessage(hWnd, WM_ERASEBKGND, (WPARAM)hDC, 0))
448 {
449 Wnd->state |= (WNDS_SENDERASEBACKGROUND|WNDS_ERASEBACKGROUND);
450 }
451 UserReleaseDC(Wnd, hDC, FALSE);
452 }
453 }
454 }
455
456 }
457 }
458
459 /*
460 * Check that the window is still valid at this point
461 */
462 if (!IntIsWindow(hWnd))
463 {
464 return;
465 }
466
467 /*
468 * Paint child windows.
469 */
470
471 if (!(Flags & RDW_NOCHILDREN) &&
472 !(Wnd->style & WS_MINIMIZE) &&
473 ( Flags & RDW_ALLCHILDREN ||
474 (Flags & RDW_CLIPCHILDREN && Wnd->style & WS_CLIPCHILDREN) ) )
475 {
476 HWND *List, *phWnd;
477 PTHREADINFO pti = PsGetCurrentThreadWin32Thread();
478
479 if ((List = IntWinListChildren(Wnd)))
480 {
481 for (phWnd = List; *phWnd; ++phWnd)
482 {
483 if ((Wnd = UserGetWindowObject(*phWnd)) == NULL)
484 continue;
485
486 if (Wnd->head.pti != pti && Wnd->style & WS_CHILD)
487 continue;
488
489 if (Wnd->style & WS_VISIBLE)
490 {
491 USER_REFERENCE_ENTRY Ref;
492 UserRefObjectCo(Wnd, &Ref);
493 co_IntPaintWindows(Wnd, Flags, TRUE);
494 UserDerefObjectCo(Wnd);
495 }
496 }
497 ExFreePoolWithTag(List, USERTAG_WINDOWLIST);
498 }
499 }
500 }
501
502 /*
503 * IntUpdateWindows
504 *
505 * Internal function used by IntRedrawWindow, simplecall.
506 */
507
508 VOID FASTCALL
509 co_IntUpdateWindows(PWND Wnd, ULONG Flags, BOOL Recurse)
510 {
511 HWND hWnd = Wnd->head.h;
512
513 if ((Wnd->hrgnUpdate != NULL || Wnd->state & WNDS_INTERNALPAINT))
514 {
515 if (Wnd->hrgnUpdate)
516 {
517 if (!IntValidateParents(Wnd, Recurse))
518 {
519 return;
520 }
521 }
522
523 if (Wnd->state & WNDS_INTERNALPAINT)
524 {
525 Wnd->state &= ~WNDS_INTERNALPAINT;
526
527 if (Wnd->hrgnUpdate == NULL)
528 MsqDecPaintCountQueue(Wnd->head.pti);
529 }
530
531 Wnd->state |= WNDS_PAINTNOTPROCESSED;
532 Wnd->state &= ~WNDS_UPDATEDIRTY;
533
534 Wnd->state2 |= WNDS2_WMPAINTSENT;
535 co_IntSendMessage(hWnd, WM_PAINT, 0, 0);
536
537 if (Wnd->state & WNDS_PAINTNOTPROCESSED)
538 {
539 USER_REFERENCE_ENTRY Ref;
540 UserRefObjectCo(Wnd, &Ref);
541 co_IntPaintWindows(Wnd, RDW_NOCHILDREN, FALSE);
542 UserDerefObjectCo(Wnd);
543 }
544 }
545
546 // Force flags as a toggle. Fixes msg:test_paint_messages:WmChildPaintNc.
547 Flags = (Flags & RDW_NOCHILDREN) ? RDW_NOCHILDREN : RDW_ALLCHILDREN; // All children is the default.
548
549 /*
550 * Update child windows.
551 */
552
553 if (!(Flags & RDW_NOCHILDREN) &&
554 Flags & RDW_ALLCHILDREN &&
555 Wnd != UserGetDesktopWindow() )
556 {
557 PWND Child;
558
559 for (Child = Wnd->spwndChild; Child; Child = Child->spwndNext)
560 {
561 /* transparent window, check for non-transparent sibling to paint first, then skip it */
562 if ( Child->ExStyle & WS_EX_TRANSPARENT &&
563 ( Child->hrgnUpdate != NULL || Child->state & WNDS_INTERNALPAINT ) )
564 {
565 PWND Next = Child->spwndNext;
566 while (Next)
567 {
568 if ( Next->hrgnUpdate != NULL || Next->state & WNDS_INTERNALPAINT ) break;
569
570 Next = Next->spwndNext;
571 }
572
573 if (Next) continue;
574 }
575
576 if ( Child->style & WS_VISIBLE)
577 {
578 USER_REFERENCE_ENTRY Ref;
579 UserRefObjectCo(Child, &Ref);
580 co_IntUpdateWindows(Child, Flags, TRUE);
581 UserDerefObjectCo(Child);
582 }
583 }
584 }
585 }
586
587 VOID FASTCALL
588 UserUpdateWindows(PWND pWnd, ULONG Flags)
589 {
590 // If transparent and any sibling windows below needs to be painted, leave.
591 if (pWnd->ExStyle & WS_EX_TRANSPARENT)
592 {
593 PWND Next = pWnd->spwndNext;
594
595 while(Next)
596 {
597 if ( Next->head.pti == pWnd->head.pti &&
598 ( Next->hrgnUpdate != NULL || Next->state & WNDS_INTERNALPAINT) )
599 {
600 return;
601 }
602
603 Next = Next->spwndNext;
604 }
605 }
606 co_IntUpdateWindows(pWnd, Flags, FALSE);
607 }
608
609 VOID FASTCALL
610 UserSyncAndPaintWindows(PWND pWnd, ULONG Flags)
611 {
612 PWND Parent = pWnd;
613 // Find parent, if it needs to be painted, leave.
614 while(TRUE)
615 {
616 if ((Parent = Parent->spwndParent) == NULL) break;
617 if ( Parent->style & WS_CLIPCHILDREN ) break;
618 if ( Parent->hrgnUpdate != NULL || Parent->state & WNDS_INTERNALPAINT ) return;
619 }
620
621 IntSendSyncPaint(pWnd, Flags);
622 co_IntPaintWindows(pWnd, Flags, FALSE);
623 }
624
625 /*
626 * IntInvalidateWindows
627 *
628 * Internal function used by IntRedrawWindow, UserRedrawDesktop,
629 * co_WinPosSetWindowPos, co_UserRedrawWindow.
630 */
631 VOID FASTCALL
632 IntInvalidateWindows(PWND Wnd, PREGION Rgn, ULONG Flags)
633 {
634 INT RgnType = NULLREGION;
635 BOOL HadPaintMessage;
636
637 TRACE("IntInvalidateWindows start Rgn %p\n",Rgn);
638
639 if ( Rgn > PRGN_WINDOW )
640 {
641 /*
642 * If the nonclient is not to be redrawn, clip the region to the client
643 * rect
644 */
645 if ((Flags & RDW_INVALIDATE) != 0 && (Flags & RDW_FRAME) == 0)
646 {
647 PREGION RgnClient;
648
649 RgnClient = IntSysCreateRectpRgnIndirect(&Wnd->rcClient);
650 if (RgnClient)
651 {
652 RgnType = IntGdiCombineRgn(Rgn, Rgn, RgnClient, RGN_AND);
653 REGION_Delete(RgnClient);
654 }
655 }
656
657 /*
658 * Clip the given region with window rectangle (or region)
659 */
660
661 if (!Wnd->hrgnClip || (Wnd->style & WS_MINIMIZE))
662 {
663 PREGION RgnWindow = IntSysCreateRectpRgnIndirect(&Wnd->rcWindow);
664 if (RgnWindow)
665 {
666 RgnType = IntGdiCombineRgn(Rgn, Rgn, RgnWindow, RGN_AND);
667 REGION_Delete(RgnWindow);
668 }
669 }
670 else
671 {
672 PREGION RgnClip = REGION_LockRgn(Wnd->hrgnClip);
673 if (RgnClip)
674 {
675 REGION_bOffsetRgn(Rgn,
676 -Wnd->rcWindow.left,
677 -Wnd->rcWindow.top);
678 RgnType = IntGdiCombineRgn(Rgn, Rgn, RgnClip, RGN_AND);
679 REGION_bOffsetRgn(Rgn,
680 Wnd->rcWindow.left,
681 Wnd->rcWindow.top);
682 REGION_UnlockRgn(RgnClip);
683 }
684 }
685 }
686 else
687 {
688 RgnType == NULLREGION;
689 }
690
691 /*
692 * Save current state of pending updates
693 */
694
695 HadPaintMessage = IntIsWindowDirty(Wnd);
696
697 /*
698 * Update the region and flags
699 */
700
701 // The following flags are used to invalidate the window.
702 if (Flags & (RDW_INVALIDATE|RDW_INTERNALPAINT|RDW_ERASE|RDW_FRAME))
703 {
704 if (Flags & RDW_INTERNALPAINT)
705 {
706 Wnd->state |= WNDS_INTERNALPAINT;
707 }
708
709 if (Flags & RDW_INVALIDATE )
710 {
711 PREGION RgnUpdate;
712
713 Wnd->state &= ~WNDS_NONCPAINT;
714
715 /* If not the same thread set it dirty. */
716 if (Wnd->head.pti != PsGetCurrentThreadWin32Thread())
717 {
718 Wnd->state |= WNDS_UPDATEDIRTY;
719 if (Wnd->state2 & WNDS2_WMPAINTSENT)
720 Wnd->state2 |= WNDS2_ENDPAINTINVALIDATE;
721 }
722
723 if (Flags & RDW_FRAME)
724 Wnd->state |= WNDS_SENDNCPAINT;
725
726 if (Flags & RDW_ERASE)
727 Wnd->state |= WNDS_SENDERASEBACKGROUND;
728
729 if (RgnType != NULLREGION && Rgn > PRGN_WINDOW)
730 {
731 if (Wnd->hrgnUpdate == NULL)
732 {
733 Wnd->hrgnUpdate = NtGdiCreateRectRgn(0, 0, 0, 0);
734 IntGdiSetRegionOwner(Wnd->hrgnUpdate, GDI_OBJ_HMGR_PUBLIC);
735 }
736
737 if (Wnd->hrgnUpdate != HRGN_WINDOW)
738 {
739 RgnUpdate = REGION_LockRgn(Wnd->hrgnUpdate);
740 if (RgnUpdate)
741 {
742 RgnType = IntGdiCombineRgn(RgnUpdate, RgnUpdate, Rgn, RGN_OR);
743 REGION_UnlockRgn(RgnUpdate);
744 if (RgnType == NULLREGION)
745 {
746 IntGdiSetRegionOwner(Wnd->hrgnUpdate, GDI_OBJ_HMGR_POWNED);
747 GreDeleteObject(Wnd->hrgnUpdate);
748 Wnd->hrgnUpdate = NULL;
749 }
750 }
751 }
752 }
753
754 Flags |= RDW_ERASE|RDW_FRAME; // For children.
755
756 }
757
758 if (!HadPaintMessage && IntIsWindowDirty(Wnd))
759 {
760 MsqIncPaintCountQueue(Wnd->head.pti);
761 }
762
763 } // The following flags are used to validate the window.
764 else if (Flags & (RDW_VALIDATE|RDW_NOINTERNALPAINT|RDW_NOERASE|RDW_NOFRAME))
765 {
766 if (Wnd->state & WNDS_UPDATEDIRTY && !(Flags & RDW_NOUPDATEDIRTY))
767 return;
768
769 if (Flags & RDW_NOINTERNALPAINT)
770 {
771 Wnd->state &= ~WNDS_INTERNALPAINT;
772 }
773
774 if (Flags & RDW_VALIDATE)
775 {
776 if (Flags & RDW_NOFRAME)
777 Wnd->state &= ~WNDS_SENDNCPAINT;
778
779 if (Flags & RDW_NOERASE)
780 Wnd->state &= ~(WNDS_SENDERASEBACKGROUND|WNDS_ERASEBACKGROUND);
781
782 if (Wnd->hrgnUpdate > HRGN_WINDOW && RgnType != NULLREGION && Rgn > PRGN_WINDOW)
783 {
784 PREGION RgnUpdate = REGION_LockRgn(Wnd->hrgnUpdate);
785
786 if (RgnUpdate)
787 {
788 RgnType = IntGdiCombineRgn(RgnUpdate, RgnUpdate, Rgn, RGN_DIFF);
789 REGION_UnlockRgn(RgnUpdate);
790
791 if (RgnType == NULLREGION)
792 {
793 IntGdiSetRegionOwner(Wnd->hrgnUpdate, GDI_OBJ_HMGR_POWNED);
794 GreDeleteObject(Wnd->hrgnUpdate);
795 Wnd->hrgnUpdate = NULL;
796 }
797 }
798 }
799 // If update is null, do not erase.
800 if (Wnd->hrgnUpdate == NULL)
801 {
802 Wnd->state &= ~(WNDS_SENDERASEBACKGROUND|WNDS_ERASEBACKGROUND);
803 }
804 }
805
806 if (HadPaintMessage && !IntIsWindowDirty(Wnd))
807 {
808 MsqDecPaintCountQueue(Wnd->head.pti);
809 }
810 }
811
812 /*
813 * Process children if needed
814 */
815
816 if (!(Flags & RDW_NOCHILDREN) &&
817 !(Wnd->style & WS_MINIMIZE) &&
818 ((Flags & RDW_ALLCHILDREN) || !(Wnd->style & WS_CLIPCHILDREN)))
819 {
820 PWND Child;
821
822 for (Child = Wnd->spwndChild; Child; Child = Child->spwndNext)
823 {
824 if (Child->style & WS_VISIBLE)
825 {
826 /*
827 * Recursive call to update children hrgnUpdate
828 */
829 PREGION RgnTemp = IntSysCreateRectpRgn(0, 0, 0, 0);
830 if (RgnTemp)
831 {
832 if (Rgn > PRGN_WINDOW) IntGdiCombineRgn(RgnTemp, Rgn, 0, RGN_COPY);
833 IntInvalidateWindows(Child, ((Rgn > PRGN_WINDOW)?RgnTemp:Rgn), Flags);
834 REGION_Delete(RgnTemp);
835 }
836 }
837 }
838 }
839 TRACE("IntInvalidateWindows exit\n");
840 }
841
842 /*
843 * IntIsWindowDrawable
844 *
845 * Remarks
846 * Window is drawable when it is visible and all parents are not
847 * minimized.
848 */
849
850 BOOL FASTCALL
851 IntIsWindowDrawable(PWND Wnd)
852 {
853 PWND WndObject;
854
855 for (WndObject = Wnd; WndObject != NULL; WndObject = WndObject->spwndParent)
856 {
857 if ( WndObject->state2 & WNDS2_INDESTROY ||
858 WndObject->state & WNDS_DESTROYED ||
859 !WndObject ||
860 !(WndObject->style & WS_VISIBLE) ||
861 ((WndObject->style & WS_MINIMIZE) && (WndObject != Wnd)))
862 {
863 return FALSE;
864 }
865 }
866
867 return TRUE;
868 }
869
870 /*
871 * IntRedrawWindow
872 *
873 * Internal version of NtUserRedrawWindow that takes WND as
874 * first parameter.
875 */
876
877 BOOL FASTCALL
878 co_UserRedrawWindow(
879 PWND Window,
880 const RECTL* UpdateRect,
881 PREGION UpdateRgn,
882 ULONG Flags)
883 {
884 PREGION TmpRgn = NULL;
885 TRACE("co_UserRedrawWindow start Rgn %p\n",UpdateRgn);
886
887 /*
888 * Step 1.
889 * Validation of passed parameters.
890 */
891
892 if (!IntIsWindowDrawable(Window))
893 {
894 return TRUE; // Just do nothing!!!
895 }
896
897 if (Window == NULL)
898 {
899 Window = UserGetDesktopWindow();
900 }
901
902 /*
903 * Step 2.
904 * Transform the parameters UpdateRgn and UpdateRect into
905 * a region hRgn specified in screen coordinates.
906 */
907
908 if (Flags & (RDW_INVALIDATE | RDW_VALIDATE)) // Both are OKAY!
909 {
910 /* We can't hold lock on GDI objects while doing roundtrips to user mode,
911 * so use a copy instead */
912 if (UpdateRgn)
913 {
914 TmpRgn = IntSysCreateRectpRgn(0, 0, 0, 0);
915
916 if (UpdateRgn > PRGN_WINDOW)
917 {
918 IntGdiCombineRgn(TmpRgn, UpdateRgn, NULL, RGN_COPY);
919 }
920
921 if (Window != UserGetDesktopWindow())
922 {
923 REGION_bOffsetRgn(TmpRgn, Window->rcClient.left, Window->rcClient.top);
924 }
925 }
926 else
927 {
928 if (UpdateRect != NULL)
929 {
930 if (Window == UserGetDesktopWindow())
931 {
932 TmpRgn = IntSysCreateRectpRgnIndirect(UpdateRect);
933 }
934 else
935 {
936 TmpRgn = IntSysCreateRectpRgn(Window->rcClient.left + UpdateRect->left,
937 Window->rcClient.top + UpdateRect->top,
938 Window->rcClient.left + UpdateRect->right,
939 Window->rcClient.top + UpdateRect->bottom);
940 }
941 }
942 else
943 {
944 if ((Flags & (RDW_INVALIDATE | RDW_FRAME)) == (RDW_INVALIDATE | RDW_FRAME) ||
945 (Flags & (RDW_VALIDATE | RDW_NOFRAME)) == (RDW_VALIDATE | RDW_NOFRAME))
946 {
947 if (!RECTL_bIsEmptyRect(&Window->rcWindow))
948 TmpRgn = IntSysCreateRectpRgnIndirect(&Window->rcWindow);
949 }
950 else
951 {
952 if (!RECTL_bIsEmptyRect(&Window->rcClient))
953 TmpRgn = IntSysCreateRectpRgnIndirect(&Window->rcClient);
954 }
955 }
956 }
957 }
958
959 /* Fixes test RDW_INTERNALPAINT behavior */
960 if (TmpRgn == NULL)
961 {
962 TmpRgn = PRGN_WINDOW; // Need a region so the bits can be set!!!
963 }
964
965 /*
966 * Step 3.
967 * Adjust the window update region depending on hRgn and flags.
968 */
969
970 if (Flags & (RDW_INVALIDATE | RDW_VALIDATE | RDW_INTERNALPAINT | RDW_NOINTERNALPAINT) &&
971 TmpRgn != NULL)
972 {
973 IntInvalidateWindows(Window, TmpRgn, Flags);
974 }
975
976 /*
977 * Step 4.
978 * Repaint and erase windows if needed.
979 */
980
981 if (Flags & RDW_UPDATENOW)
982 {
983 UserUpdateWindows(Window, Flags);
984 }
985 else if (Flags & RDW_ERASENOW)
986 {
987 if ((Flags & (RDW_NOCHILDREN|RDW_ALLCHILDREN)) == 0)
988 Flags |= RDW_CLIPCHILDREN;
989
990 UserSyncAndPaintWindows(Window, Flags);
991 }
992
993 /*
994 * Step 5.
995 * Cleanup ;-)
996 */
997
998 if (TmpRgn > PRGN_WINDOW)
999 {
1000 REGION_Delete(TmpRgn);
1001 }
1002 TRACE("co_UserRedrawWindow exit\n");
1003
1004 return TRUE;
1005 }
1006
1007 BOOL FASTCALL
1008 IntIsWindowDirty(PWND Wnd)
1009 {
1010 return ( Wnd->style & WS_VISIBLE &&
1011 ( Wnd->hrgnUpdate != NULL ||
1012 Wnd->state & WNDS_INTERNALPAINT ) );
1013 }
1014
1015 /*
1016 Conditions to paint any window:
1017
1018 1. Update region is not null.
1019 2. Internal paint flag is set.
1020 3. Paint count is not zero.
1021
1022 */
1023 PWND FASTCALL
1024 IntFindWindowToRepaint(PWND Window, PTHREADINFO Thread)
1025 {
1026 PWND hChild;
1027 PWND TempWindow;
1028
1029 for (; Window != NULL; Window = Window->spwndNext)
1030 {
1031 if (IntWndBelongsToThread(Window, Thread))
1032 {
1033 if (IntIsWindowDirty(Window))
1034 {
1035 /* Make sure all non-transparent siblings are already drawn. */
1036 if (Window->ExStyle & WS_EX_TRANSPARENT)
1037 {
1038 for (TempWindow = Window->spwndNext; TempWindow != NULL;
1039 TempWindow = TempWindow->spwndNext)
1040 {
1041 if (!(TempWindow->ExStyle & WS_EX_TRANSPARENT) &&
1042 IntWndBelongsToThread(TempWindow, Thread) &&
1043 IntIsWindowDirty(TempWindow))
1044 {
1045 return TempWindow;
1046 }
1047 }
1048 }
1049 return Window;
1050 }
1051 }
1052 /* find a child of the specified window that needs repainting */
1053 if (Window->spwndChild)
1054 {
1055 hChild = IntFindWindowToRepaint(Window->spwndChild, Thread);
1056 if (hChild != NULL)
1057 return hChild;
1058 }
1059 }
1060 return Window;
1061 }
1062
1063 BOOL FASTCALL
1064 IntGetPaintMessage(
1065 PWND Window,
1066 UINT MsgFilterMin,
1067 UINT MsgFilterMax,
1068 PTHREADINFO Thread,
1069 MSG *Message,
1070 BOOL Remove)
1071 {
1072 PWND PaintWnd, StartWnd;
1073
1074 if ((MsgFilterMin != 0 || MsgFilterMax != 0) &&
1075 (MsgFilterMin > WM_PAINT || MsgFilterMax < WM_PAINT))
1076 return FALSE;
1077
1078 if (Thread->TIF_flags & TIF_SYSTEMTHREAD )
1079 {
1080 ERR("WM_PAINT is in a System Thread!\n");
1081 }
1082
1083 StartWnd = UserGetDesktopWindow();
1084 PaintWnd = IntFindWindowToRepaint(StartWnd, Thread);
1085
1086 Message->hwnd = PaintWnd ? UserHMGetHandle(PaintWnd) : NULL;
1087
1088 if (Message->hwnd == NULL && Thread->cPaintsReady)
1089 {
1090 // Find note in window.c:"PAINTING BUG".
1091 ERR("WARNING SOMETHING HAS GONE WRONG: Thread marked as containing dirty windows, but no dirty windows found! Counts %u\n",Thread->cPaintsReady);
1092 /* Hack to stop spamming the debug log ! */
1093 Thread->cPaintsReady = 0;
1094 return FALSE;
1095 }
1096
1097 if (Message->hwnd == NULL)
1098 return FALSE;
1099
1100 if (!(Window == NULL ||
1101 PaintWnd == Window ||
1102 IntIsChildWindow(Window, PaintWnd))) /* check that it is a child of the specified parent */
1103 return FALSE;
1104
1105 if (PaintWnd->state & WNDS_INTERNALPAINT)
1106 {
1107 PaintWnd->state &= ~WNDS_INTERNALPAINT;
1108 if (!PaintWnd->hrgnUpdate)
1109 MsqDecPaintCountQueue(Thread);
1110 }
1111 PaintWnd->state2 &= ~WNDS2_STARTPAINT;
1112 PaintWnd->state &= ~WNDS_UPDATEDIRTY;
1113
1114 Window = PaintWnd;
1115 while( Window && Window != UserGetDesktopWindow())
1116 {
1117 // Role back and check for clip children, do not set if any.
1118 if (Window->spwndParent && !(Window->spwndParent->style & WS_CLIPCHILDREN))
1119 {
1120 PaintWnd->state2 |= WNDS2_WMPAINTSENT;
1121 }
1122 Window = Window->spwndParent;
1123 }
1124
1125 Message->wParam = Message->lParam = 0;
1126 Message->message = WM_PAINT;
1127 return TRUE;
1128 }
1129
1130 BOOL
1131 FASTCALL
1132 IntPrintWindow(
1133 PWND pwnd,
1134 HDC hdcBlt,
1135 UINT nFlags)
1136 {
1137 HDC hdcSrc;
1138 INT cx, cy, xSrc, ySrc;
1139
1140 if ( nFlags & PW_CLIENTONLY)
1141 {
1142 cx = pwnd->rcClient.right - pwnd->rcClient.left;
1143 cy = pwnd->rcClient.bottom - pwnd->rcClient.top;
1144 xSrc = pwnd->rcClient.left - pwnd->rcWindow.left;
1145 ySrc = pwnd->rcClient.top - pwnd->rcWindow.top;
1146 }
1147 else
1148 {
1149 cx = pwnd->rcWindow.right - pwnd->rcWindow.left;
1150 cy = pwnd->rcWindow.bottom - pwnd->rcWindow.top;
1151 xSrc = 0;
1152 ySrc = 0;
1153 }
1154
1155 // TODO: Setup Redirection for Print.
1156 return FALSE;
1157
1158 /* Update the window just incase. */
1159 co_IntUpdateWindows( pwnd, RDW_ALLCHILDREN, FALSE);
1160
1161 hdcSrc = UserGetDCEx( pwnd, NULL, DCX_CACHE|DCX_WINDOW);
1162 /* Print window to printer context. */
1163 NtGdiBitBlt( hdcBlt,
1164 0,
1165 0,
1166 cx,
1167 cy,
1168 hdcSrc,
1169 xSrc,
1170 ySrc,
1171 SRCCOPY,
1172 0,
1173 0);
1174
1175 UserReleaseDC( pwnd, hdcSrc, FALSE);
1176
1177 // TODO: Release Redirection from Print.
1178
1179 return TRUE;
1180 }
1181
1182 BOOL
1183 FASTCALL
1184 IntFlashWindowEx(PWND pWnd, PFLASHWINFO pfwi)
1185 {
1186 DWORD FlashState;
1187 UINT uCount = pfwi->uCount;
1188 BOOL Activate = FALSE, Ret = FALSE;
1189
1190 ASSERT(pfwi);
1191
1192 FlashState = (DWORD)UserGetProp(pWnd, AtomFlashWndState);
1193
1194 if (FlashState == FLASHW_FINISHED)
1195 {
1196 // Cycle has finished, kill timer and set this to Stop.
1197 FlashState |= FLASHW_KILLSYSTIMER;
1198 pfwi->dwFlags = FLASHW_STOP;
1199 }
1200 else
1201 {
1202 if (FlashState)
1203 {
1204 if (pfwi->dwFlags == FLASHW_SYSTIMER)
1205 {
1206 // Called from system timer, restore flags, counts and state.
1207 pfwi->dwFlags = LOWORD(FlashState);
1208 uCount = HIWORD(FlashState);
1209 FlashState = MAKELONG(LOWORD(FlashState),0);
1210 }
1211 else
1212 {
1213 // Clean out the trash! Fix SeaMonkey crash after restart.
1214 FlashState = 0;
1215 }
1216 }
1217
1218 if (FlashState == 0)
1219 { // First time in cycle, setup flash state.
1220 if ( pWnd->state & WNDS_ACTIVEFRAME ||
1221 (pfwi->dwFlags & FLASHW_CAPTION && pWnd->style & (WS_BORDER|WS_DLGFRAME)))
1222 {
1223 FlashState = FLASHW_STARTED|FLASHW_ACTIVE;
1224 }
1225 }
1226
1227 // Set previous window state.
1228 Ret = !!(FlashState & FLASHW_ACTIVE);
1229
1230 if ( pfwi->dwFlags & FLASHW_TIMERNOFG &&
1231 gpqForeground == pWnd->head.pti->MessageQueue )
1232 {
1233 // Flashing until foreground, set this to Stop.
1234 pfwi->dwFlags = FLASHW_STOP;
1235 }
1236 }
1237
1238 // Toggle activate flag.
1239 if ( pfwi->dwFlags == FLASHW_STOP )
1240 {
1241 if (gpqForeground && gpqForeground->spwndActive == pWnd)
1242 Activate = TRUE;
1243 else
1244 Activate = FALSE;
1245 }
1246 else
1247 {
1248 Activate = (FlashState & FLASHW_ACTIVE) == 0;
1249 }
1250
1251 if ( pfwi->dwFlags == FLASHW_STOP || pfwi->dwFlags & FLASHW_CAPTION )
1252 {
1253 co_IntSendMessage(UserHMGetHandle(pWnd), WM_NCACTIVATE, Activate, 0);
1254 }
1255
1256 // FIXME: Check for a Stop Sign here.
1257 if ( pfwi->dwFlags & FLASHW_TRAY )
1258 {
1259 // Need some shell work here too.
1260 TRACE("FIXME: Flash window no Tray support!\n");
1261 }
1262
1263 if ( pfwi->dwFlags == FLASHW_STOP )
1264 {
1265 if (FlashState & FLASHW_KILLSYSTIMER)
1266 {
1267 IntKillTimer(pWnd, ID_EVENT_SYSTIMER_FLASHWIN, TRUE);
1268 }
1269
1270 IntRemoveProp(pWnd, AtomFlashWndState);
1271 }
1272 else
1273 { // Have a count and started, set timer.
1274 if ( uCount )
1275 {
1276 FlashState |= FLASHW_COUNT;
1277
1278 if (!(Activate ^ !!(FlashState & FLASHW_STARTED)))
1279 uCount--;
1280
1281 if (!(FlashState & FLASHW_KILLSYSTIMER))
1282 pfwi->dwFlags |= FLASHW_TIMER;
1283 }
1284
1285 if (pfwi->dwFlags & FLASHW_TIMER)
1286 {
1287 FlashState |= FLASHW_KILLSYSTIMER;
1288
1289 IntSetTimer( pWnd,
1290 ID_EVENT_SYSTIMER_FLASHWIN,
1291 pfwi->dwTimeout ? pfwi->dwTimeout : gpsi->dtCaretBlink,
1292 SystemTimerProc,
1293 TMRF_SYSTEM );
1294 }
1295
1296 if (FlashState & FLASHW_COUNT && uCount == 0)
1297 {
1298 // Keep spinning? Nothing else to do.
1299 FlashState = FLASHW_FINISHED;
1300 }
1301 else
1302 {
1303 // Save state and flags so this can be restored next time through.
1304 FlashState ^= (FlashState ^ -!!(Activate)) & FLASHW_ACTIVE;
1305 FlashState ^= (FlashState ^ pfwi->dwFlags) & (FLASHW_MASK & ~FLASHW_TIMER);
1306 }
1307 FlashState = MAKELONG(LOWORD(FlashState),uCount);
1308 IntSetProp(pWnd, AtomFlashWndState, (HANDLE) FlashState);
1309 }
1310 return Ret;
1311 }
1312
1313 HDC FASTCALL
1314 IntBeginPaint(PWND Window, PPAINTSTRUCT Ps)
1315 {
1316 RECT Rect;
1317 INT type;
1318 BOOL Erase = FALSE;
1319
1320 co_UserHideCaret(Window);
1321
1322 Window->state2 |= WNDS2_STARTPAINT;
1323 Window->state &= ~WNDS_PAINTNOTPROCESSED;
1324
1325 if (Window->state & WNDS_SENDNCPAINT)
1326 {
1327 HRGN hRgn;
1328 // Application can keep update dirty.
1329 do
1330 {
1331 Window->state &= ~WNDS_UPDATEDIRTY;
1332 hRgn = IntGetNCUpdateRgn(Window, FALSE);
1333 IntSendNCPaint(Window, hRgn);
1334 if (hRgn > HRGN_WINDOW && GreIsHandleValid(hRgn))
1335 {
1336 /* NOTE: The region can already be deleted! */
1337 GreDeleteObject(hRgn);
1338 }
1339 }
1340 while(Window->state & WNDS_UPDATEDIRTY);
1341 }
1342 else
1343 {
1344 Window->state &= ~WNDS_UPDATEDIRTY;
1345 }
1346
1347 RtlZeroMemory(Ps, sizeof(PAINTSTRUCT));
1348
1349 if (Window->state2 & WNDS2_ENDPAINTINVALIDATE)
1350 {
1351 ERR("BP: Another thread invalidated this window\n");
1352 }
1353
1354 Ps->hdc = UserGetDCEx( Window,
1355 Window->hrgnUpdate,
1356 DCX_INTERSECTRGN | DCX_USESTYLE);
1357 if (!Ps->hdc)
1358 {
1359 return NULL;
1360 }
1361
1362 // If set, always clear flags out due to the conditions later on for sending the message.
1363 if (Window->state & WNDS_SENDERASEBACKGROUND)
1364 {
1365 Window->state &= ~(WNDS_SENDERASEBACKGROUND|WNDS_ERASEBACKGROUND);
1366 Erase = TRUE;
1367 }
1368
1369 if (Window->hrgnUpdate != NULL)
1370 {
1371 MsqDecPaintCountQueue(Window->head.pti);
1372 IntGdiSetRegionOwner(Window->hrgnUpdate, GDI_OBJ_HMGR_POWNED);
1373 /* The region is part of the dc now and belongs to the process! */
1374 Window->hrgnUpdate = NULL;
1375 }
1376 else
1377 {
1378 if (Window->state & WNDS_INTERNALPAINT)
1379 MsqDecPaintCountQueue(Window->head.pti);
1380 }
1381
1382 type = GdiGetClipBox(Ps->hdc, &Ps->rcPaint);
1383
1384 IntGetClientRect(Window, &Rect);
1385
1386 Window->state &= ~WNDS_INTERNALPAINT;
1387
1388 if ( Erase && // Set to erase,
1389 type != NULLREGION && // don't erase if the clip box is empty,
1390 (!(Window->pcls->style & CS_PARENTDC) || // not parent dc or
1391 RECTL_bIntersectRect( &Rect, &Rect, &Ps->rcPaint) ) ) // intersecting.
1392 {
1393 Ps->fErase = !co_IntSendMessage(UserHMGetHandle(Window), WM_ERASEBKGND, (WPARAM)Ps->hdc, 0);
1394 if ( Ps->fErase )
1395 {
1396 Window->state |= (WNDS_SENDERASEBACKGROUND|WNDS_ERASEBACKGROUND);
1397 }
1398 }
1399 else
1400 {
1401 Ps->fErase = FALSE;
1402 }
1403
1404 IntSendChildNCPaint(Window);
1405
1406 return Ps->hdc;
1407 }
1408
1409 BOOL FASTCALL
1410 IntEndPaint(PWND Wnd, PPAINTSTRUCT Ps)
1411 {
1412 HDC hdc = NULL;
1413
1414 hdc = Ps->hdc;
1415
1416 UserReleaseDC(Wnd, hdc, TRUE);
1417
1418 if (Wnd->state2 & WNDS2_ENDPAINTINVALIDATE)
1419 {
1420 ERR("EP: Another thread invalidated this window\n");
1421 Wnd->state2 &= ~WNDS2_ENDPAINTINVALIDATE;
1422 }
1423
1424 Wnd->state2 &= ~(WNDS2_WMPAINTSENT|WNDS2_STARTPAINT);
1425
1426 co_UserShowCaret(Wnd);
1427
1428 return TRUE;
1429 }
1430
1431 /* PUBLIC FUNCTIONS ***********************************************************/
1432
1433 /*
1434 * NtUserBeginPaint
1435 *
1436 * Status
1437 * @implemented
1438 */
1439
1440 HDC APIENTRY
1441 NtUserBeginPaint(HWND hWnd, PAINTSTRUCT* UnsafePs)
1442 {
1443 PWND Window = NULL;
1444 PAINTSTRUCT Ps;
1445 NTSTATUS Status;
1446 HDC hDC;
1447 USER_REFERENCE_ENTRY Ref;
1448 DECLARE_RETURN(HDC);
1449
1450 TRACE("Enter NtUserBeginPaint\n");
1451 UserEnterExclusive();
1452
1453 if (!(Window = UserGetWindowObject(hWnd)))
1454 {
1455 RETURN( NULL);
1456 }
1457
1458 UserRefObjectCo(Window, &Ref);
1459
1460 hDC = IntBeginPaint(Window, &Ps);
1461
1462 Status = MmCopyToCaller(UnsafePs, &Ps, sizeof(PAINTSTRUCT));
1463 if (! NT_SUCCESS(Status))
1464 {
1465 SetLastNtError(Status);
1466 RETURN(NULL);
1467 }
1468
1469 RETURN(hDC);
1470
1471 CLEANUP:
1472 if (Window) UserDerefObjectCo(Window);
1473
1474 TRACE("Leave NtUserBeginPaint, ret=%p\n",_ret_);
1475 UserLeave();
1476 END_CLEANUP;
1477
1478 }
1479
1480 /*
1481 * NtUserEndPaint
1482 *
1483 * Status
1484 * @implemented
1485 */
1486
1487 BOOL APIENTRY
1488 NtUserEndPaint(HWND hWnd, CONST PAINTSTRUCT* pUnsafePs)
1489 {
1490 NTSTATUS Status = STATUS_SUCCESS;
1491 PWND Window = NULL;
1492 PAINTSTRUCT Ps;
1493 USER_REFERENCE_ENTRY Ref;
1494 DECLARE_RETURN(BOOL);
1495
1496 TRACE("Enter NtUserEndPaint\n");
1497 UserEnterExclusive();
1498
1499 if (!(Window = UserGetWindowObject(hWnd)))
1500 {
1501 RETURN(FALSE);
1502 }
1503
1504 UserRefObjectCo(Window, &Ref); // Here for the exception.
1505
1506 _SEH2_TRY
1507 {
1508 ProbeForRead(pUnsafePs, sizeof(*pUnsafePs), 1);
1509 RtlCopyMemory(&Ps, pUnsafePs, sizeof(PAINTSTRUCT));
1510 }
1511 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
1512 {
1513 Status = _SEH2_GetExceptionCode();
1514 }
1515 _SEH2_END
1516 if (!NT_SUCCESS(Status))
1517 {
1518 RETURN(FALSE);
1519 }
1520
1521 RETURN(IntEndPaint(Window, &Ps));
1522
1523 CLEANUP:
1524 if (Window) UserDerefObjectCo(Window);
1525
1526 TRACE("Leave NtUserEndPaint, ret=%i\n",_ret_);
1527 UserLeave();
1528 END_CLEANUP;
1529 }
1530
1531 /*
1532 * @implemented
1533 */
1534 BOOL APIENTRY
1535 NtUserFlashWindowEx(IN PFLASHWINFO pfwi)
1536 {
1537 PWND pWnd;
1538 FLASHWINFO finfo = {0};
1539 BOOL Ret = TRUE;
1540
1541 UserEnterExclusive();
1542
1543 _SEH2_TRY
1544 {
1545 ProbeForRead(pfwi, sizeof(FLASHWINFO), sizeof(ULONG));
1546 RtlCopyMemory(&finfo, pfwi, sizeof(FLASHWINFO));
1547 }
1548 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
1549 {
1550 SetLastNtError(_SEH2_GetExceptionCode());
1551 Ret = FALSE;
1552 }
1553 _SEH2_END
1554
1555 if (!Ret) goto Exit;
1556
1557 if (!( pWnd = (PWND)UserGetObject(gHandleTable, finfo.hwnd, TYPE_WINDOW)) ||
1558 finfo.cbSize != sizeof(FLASHWINFO) ||
1559 finfo.dwFlags & ~(FLASHW_ALL|FLASHW_TIMER|FLASHW_TIMERNOFG) )
1560 {
1561 EngSetLastError(ERROR_INVALID_PARAMETER);
1562 Ret = FALSE;
1563 goto Exit;
1564 }
1565
1566 Ret = IntFlashWindowEx(pWnd, &finfo);
1567
1568 Exit:
1569 UserLeave();
1570 return Ret;
1571 }
1572
1573 /*
1574 GetUpdateRgn, this fails the same as the old one.
1575 */
1576 INT FASTCALL
1577 co_UserGetUpdateRgn(PWND Window, HRGN hRgn, BOOL bErase)
1578 {
1579 int RegionType;
1580 BOOL Type;
1581 RECTL Rect;
1582
1583 ASSERT_REFS_CO(Window);
1584
1585 if (bErase)
1586 {
1587 USER_REFERENCE_ENTRY Ref;
1588 UserRefObjectCo(Window, &Ref);
1589 co_IntPaintWindows(Window, RDW_NOCHILDREN, FALSE);
1590 UserDerefObjectCo(Window);
1591 }
1592
1593 Window->state &= ~WNDS_UPDATEDIRTY;
1594
1595 if (Window->hrgnUpdate == NULL)
1596 {
1597 NtGdiSetRectRgn(hRgn, 0, 0, 0, 0);
1598 return NULLREGION;
1599 }
1600
1601 Rect = Window->rcClient;
1602 Type = IntIntersectWithParents(Window, &Rect);
1603
1604 if (Window->hrgnUpdate == HRGN_WINDOW)
1605 {
1606 // Trap it out.
1607 ERR("GURn: Caller is passing Window Region 1\n");
1608 if (!Type)
1609 {
1610 NtGdiSetRectRgn(hRgn, 0, 0, 0, 0);
1611 return NULLREGION;
1612 }
1613
1614 RegionType = SIMPLEREGION;
1615
1616 if (Window != UserGetDesktopWindow()) // Window->fnid == FNID_DESKTOP
1617 {
1618 RECTL_vOffsetRect(&Rect,
1619 -Window->rcClient.left,
1620 -Window->rcClient.top);
1621 }
1622 GreSetRectRgnIndirect(hRgn, &Rect);
1623 }
1624 else
1625 {
1626 HRGN hrgnTemp = GreCreateRectRgnIndirect(&Rect);
1627
1628 RegionType = NtGdiCombineRgn(hRgn, hrgnTemp, Window->hrgnUpdate, RGN_AND);
1629
1630 if (RegionType == ERROR || RegionType == NULLREGION)
1631 {
1632 if (hrgnTemp) GreDeleteObject(hrgnTemp);
1633 NtGdiSetRectRgn(hRgn, 0, 0, 0, 0);
1634 return NULLREGION;
1635 }
1636
1637 if (Window != UserGetDesktopWindow()) // Window->fnid == FNID_DESKTOP
1638 {
1639 NtGdiOffsetRgn(hRgn,
1640 -Window->rcClient.left,
1641 -Window->rcClient.top);
1642 }
1643 if (hrgnTemp) GreDeleteObject(hrgnTemp);
1644 }
1645 return RegionType;
1646 }
1647
1648 BOOL FASTCALL
1649 co_UserGetUpdateRect(PWND Window, PRECT pRect, BOOL bErase)
1650 {
1651 INT RegionType;
1652 BOOL Ret = TRUE;
1653
1654 if (bErase)
1655 {
1656 USER_REFERENCE_ENTRY Ref;
1657 UserRefObjectCo(Window, &Ref);
1658 co_IntPaintWindows(Window, RDW_NOCHILDREN, FALSE);
1659 UserDerefObjectCo(Window);
1660 }
1661
1662 Window->state &= ~WNDS_UPDATEDIRTY;
1663
1664 if (Window->hrgnUpdate == NULL)
1665 {
1666 pRect->left = pRect->top = pRect->right = pRect->bottom = 0;
1667 Ret = FALSE;
1668 }
1669 else
1670 {
1671 /* Get the update region bounding box. */
1672 if (Window->hrgnUpdate == HRGN_WINDOW)
1673 {
1674 *pRect = Window->rcClient;
1675 ERR("GURt: Caller is retrieving Window Region 1\n");
1676 }
1677 else
1678 {
1679 RegionType = IntGdiGetRgnBox(Window->hrgnUpdate, pRect);
1680
1681 if (RegionType != ERROR && RegionType != NULLREGION)
1682 RECTL_bIntersectRect(pRect, pRect, &Window->rcClient);
1683 }
1684
1685 if (IntIntersectWithParents(Window, pRect))
1686 {
1687 RECTL_vOffsetRect(pRect,
1688 -Window->rcClient.left,
1689 -Window->rcClient.top);
1690 }
1691 else
1692 {
1693 pRect->left = pRect->top = pRect->right = pRect->bottom = 0;
1694 }
1695 }
1696 return Ret;
1697 }
1698
1699 /*
1700 * NtUserGetUpdateRgn
1701 *
1702 * Status
1703 * @implemented
1704 */
1705
1706 INT APIENTRY
1707 NtUserGetUpdateRgn(HWND hWnd, HRGN hRgn, BOOL bErase)
1708 {
1709 DECLARE_RETURN(INT);
1710 PWND Window;
1711 INT ret;
1712
1713 TRACE("Enter NtUserGetUpdateRgn\n");
1714 UserEnterExclusive();
1715
1716 if (!(Window = UserGetWindowObject(hWnd)))
1717 {
1718 RETURN(ERROR);
1719 }
1720
1721 ret = co_UserGetUpdateRgn(Window, hRgn, bErase);
1722
1723 RETURN(ret);
1724
1725 CLEANUP:
1726 TRACE("Leave NtUserGetUpdateRgn, ret=%i\n",_ret_);
1727 UserLeave();
1728 END_CLEANUP;
1729 }
1730
1731 /*
1732 * NtUserGetUpdateRect
1733 *
1734 * Status
1735 * @implemented
1736 */
1737
1738 BOOL APIENTRY
1739 NtUserGetUpdateRect(HWND hWnd, LPRECT UnsafeRect, BOOL bErase)
1740 {
1741 PWND Window;
1742 RECTL Rect;
1743 NTSTATUS Status;
1744 BOOL Ret;
1745 DECLARE_RETURN(BOOL);
1746
1747 TRACE("Enter NtUserGetUpdateRect\n");
1748 UserEnterExclusive();
1749
1750 if (!(Window = UserGetWindowObject(hWnd)))
1751 {
1752 RETURN(FALSE);
1753 }
1754
1755 Ret = co_UserGetUpdateRect(Window, &Rect, bErase);
1756
1757 if (UnsafeRect != NULL)
1758 {
1759 Status = MmCopyToCaller(UnsafeRect, &Rect, sizeof(RECTL));
1760 if (!NT_SUCCESS(Status))
1761 {
1762 EngSetLastError(ERROR_INVALID_PARAMETER);
1763 RETURN(FALSE);
1764 }
1765 }
1766
1767 RETURN(Ret);
1768
1769 CLEANUP:
1770 TRACE("Leave NtUserGetUpdateRect, ret=%i\n",_ret_);
1771 UserLeave();
1772 END_CLEANUP;
1773 }
1774
1775 /*
1776 * NtUserRedrawWindow
1777 *
1778 * Status
1779 * @implemented
1780 */
1781
1782 BOOL APIENTRY
1783 NtUserRedrawWindow(
1784 HWND hWnd,
1785 CONST RECT *lprcUpdate,
1786 HRGN hrgnUpdate,
1787 UINT flags)
1788 {
1789 RECTL SafeUpdateRect;
1790 PWND Wnd;
1791 BOOL Ret;
1792 USER_REFERENCE_ENTRY Ref;
1793 NTSTATUS Status = STATUS_SUCCESS;
1794 PREGION RgnUpdate = NULL;
1795 DECLARE_RETURN(BOOL);
1796
1797 TRACE("Enter NtUserRedrawWindow\n");
1798 UserEnterExclusive();
1799
1800 if (!(Wnd = UserGetWindowObject(hWnd ? hWnd : IntGetDesktopWindow())))
1801 {
1802 RETURN( FALSE);
1803 }
1804
1805 if (lprcUpdate)
1806 {
1807 _SEH2_TRY
1808 {
1809 ProbeForRead(lprcUpdate, sizeof(RECTL), 1);
1810 RtlCopyMemory(&SafeUpdateRect, lprcUpdate, sizeof(RECTL));
1811 }
1812 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
1813 {
1814 Status = _SEH2_GetExceptionCode();
1815 }
1816 _SEH2_END
1817 if (!NT_SUCCESS(Status))
1818 {
1819 EngSetLastError(RtlNtStatusToDosError(Status));
1820 RETURN( FALSE);
1821 }
1822 }
1823
1824 if ( flags & ~(RDW_ERASE|RDW_FRAME|RDW_INTERNALPAINT|RDW_INVALIDATE|
1825 RDW_NOERASE|RDW_NOFRAME|RDW_NOINTERNALPAINT|RDW_VALIDATE|
1826 RDW_ERASENOW|RDW_UPDATENOW|RDW_ALLCHILDREN|RDW_NOCHILDREN) )
1827 {
1828 /* RedrawWindow fails only in case that flags are invalid */
1829 EngSetLastError(ERROR_INVALID_FLAGS);
1830 RETURN( FALSE);
1831 }
1832
1833 /* We can't hold lock on GDI objects while doing roundtrips to user mode,
1834 * so it will be copied.
1835 */
1836 if (hrgnUpdate > HRGN_WINDOW)
1837 {
1838 RgnUpdate = REGION_LockRgn(hrgnUpdate);
1839 if (!RgnUpdate)
1840 {
1841 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
1842 RETURN(FALSE);
1843 }
1844 REGION_UnlockRgn(RgnUpdate);
1845 }
1846 else if (hrgnUpdate == HRGN_WINDOW) // Trap it out.
1847 {
1848 ERR("NTRW: Caller is passing Window Region 1\n");
1849 }
1850
1851 UserRefObjectCo(Wnd, &Ref);
1852
1853 Ret = co_UserRedrawWindow( Wnd,
1854 lprcUpdate ? &SafeUpdateRect : NULL,
1855 RgnUpdate,
1856 flags);
1857
1858 UserDerefObjectCo(Wnd);
1859
1860 RETURN( Ret);
1861
1862 CLEANUP:
1863 TRACE("Leave NtUserRedrawWindow, ret=%i\n",_ret_);
1864 UserLeave();
1865 END_CLEANUP;
1866 }
1867
1868 static const WCHAR ELLIPSISW[] = {'.','.','.', 0};
1869
1870 BOOL
1871 UserDrawCaptionText(
1872 PWND pWnd,
1873 HDC hDc,
1874 const PUNICODE_STRING Text,
1875 const RECTL *lpRc,
1876 UINT uFlags,
1877 HFONT hFont)
1878 {
1879 HFONT hOldFont = NULL;
1880 COLORREF OldTextColor;
1881 NONCLIENTMETRICSW nclm;
1882 NTSTATUS Status;
1883 BOOLEAN bDeleteFont = FALSE;
1884 SIZE Size;
1885 ULONG fit = 0, Length;
1886 WCHAR szText[128];
1887 RECTL r = *lpRc;
1888
1889 TRACE("UserDrawCaptionText: %wZ\n", Text);
1890
1891 nclm.cbSize = sizeof(nclm);
1892 if(!UserSystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &nclm, 0))
1893 {
1894 ERR("UserSystemParametersInfo() failed!\n");
1895 return FALSE;
1896 }
1897
1898 if (!hFont)
1899 {
1900 if(uFlags & DC_SMALLCAP)
1901 Status = TextIntCreateFontIndirect(&nclm.lfSmCaptionFont, &hFont);
1902 else
1903 Status = TextIntCreateFontIndirect(&nclm.lfCaptionFont, &hFont);
1904
1905 if(!NT_SUCCESS(Status))
1906 {
1907 ERR("TextIntCreateFontIndirect() failed! Status: 0x%x\n", Status);
1908 return FALSE;
1909 }
1910
1911 bDeleteFont = TRUE;
1912 }
1913
1914 IntGdiSetBkMode(hDc, TRANSPARENT);
1915
1916 hOldFont = NtGdiSelectFont(hDc, hFont);
1917
1918 if(uFlags & DC_INBUTTON)
1919 OldTextColor = IntGdiSetTextColor(hDc, IntGetSysColor(COLOR_BTNTEXT));
1920 else
1921 OldTextColor = IntGdiSetTextColor(hDc,
1922 IntGetSysColor(uFlags & DC_ACTIVE ? COLOR_CAPTIONTEXT : COLOR_INACTIVECAPTIONTEXT));
1923
1924 // Adjust for system menu.
1925 if (pWnd && pWnd->style & WS_SYSMENU)
1926 {
1927 r.right -= UserGetSystemMetrics(SM_CYCAPTION) - 1;
1928 if ((pWnd->style & (WS_MAXIMIZEBOX | WS_MINIMIZEBOX)) && !(pWnd->ExStyle & WS_EX_TOOLWINDOW))
1929 {
1930 r.right -= UserGetSystemMetrics(SM_CXSIZE) + 1;
1931 r.right -= UserGetSystemMetrics(SM_CXSIZE) + 1;
1932 }
1933 }
1934
1935 GreGetTextExtentExW(hDc, Text->Buffer, Text->Length/sizeof(WCHAR), r.right - r.left, &fit, 0, &Size, 0);
1936
1937 Length = (Text->Length/sizeof(WCHAR) == fit ? fit : fit+1);
1938
1939 RtlZeroMemory(&szText, sizeof(szText));
1940 RtlCopyMemory(&szText, Text->Buffer, Text->Length);
1941
1942 if (Text->Length/sizeof(WCHAR) > Length && Length > 3)
1943 {
1944 RtlCopyMemory(&szText[Length-3], ELLIPSISW, sizeof(ELLIPSISW));
1945 }
1946
1947 GreExtTextOutW( hDc,
1948 lpRc->left,
1949 lpRc->top + (lpRc->bottom - lpRc->top) / 2 - Size.cy / 2, // DT_SINGLELINE && DT_VCENTER
1950 ETO_CLIPPED,
1951 (RECTL *)lpRc,
1952 (LPWSTR)&szText,
1953 Length,
1954 NULL,
1955 0 );
1956
1957 IntGdiSetTextColor(hDc, OldTextColor);
1958
1959 if (hOldFont)
1960 NtGdiSelectFont(hDc, hOldFont);
1961
1962 if (bDeleteFont)
1963 GreDeleteObject(hFont);
1964
1965 return TRUE;
1966 }
1967
1968 BOOL UserDrawCaption(
1969 PWND pWnd,
1970 HDC hDc,
1971 RECTL *lpRc,
1972 HFONT hFont,
1973 HICON hIcon,
1974 const PUNICODE_STRING Str,
1975 UINT uFlags)
1976 {
1977 BOOL Ret = FALSE;
1978 HBRUSH hBgBrush, hOldBrush = NULL;
1979 RECTL Rect = *lpRc;
1980 BOOL HasIcon;
1981
1982 RECTL_vMakeWellOrdered(lpRc);
1983
1984 if (!hIcon && pWnd != NULL)
1985 {
1986 HasIcon = (uFlags & DC_ICON) && (pWnd->style & WS_SYSMENU)
1987 && !(uFlags & DC_SMALLCAP) && !(pWnd->ExStyle & WS_EX_DLGMODALFRAME)
1988 && !(pWnd->ExStyle & WS_EX_TOOLWINDOW);
1989 }
1990 else
1991 HasIcon = (hIcon != 0);
1992
1993 // Draw the caption background
1994 if((uFlags & DC_GRADIENT) && !(uFlags & DC_INBUTTON))
1995 {
1996 static GRADIENT_RECT gcap = {0, 1};
1997 TRIVERTEX Vertices[2];
1998 COLORREF Colors[2];
1999
2000 Colors[0] = IntGetSysColor((uFlags & DC_ACTIVE) ?
2001 COLOR_ACTIVECAPTION : COLOR_INACTIVECAPTION);
2002
2003 Colors[1] = IntGetSysColor((uFlags & DC_ACTIVE) ?
2004 COLOR_GRADIENTACTIVECAPTION : COLOR_GRADIENTINACTIVECAPTION);
2005
2006 Vertices[0].x = Rect.left;
2007 Vertices[0].y = Rect.top;
2008 Vertices[0].Red = (WORD)Colors[0]<<8;
2009 Vertices[0].Green = (WORD)Colors[0] & 0xFF00;
2010 Vertices[0].Blue = (WORD)(Colors[0]>>8) & 0xFF00;
2011 Vertices[0].Alpha = 0;
2012
2013 Vertices[1].x = Rect.right;
2014 Vertices[1].y = Rect.bottom;
2015 Vertices[1].Red = (WORD)Colors[1]<<8;
2016 Vertices[1].Green = (WORD)Colors[1] & 0xFF00;
2017 Vertices[1].Blue = (WORD)(Colors[1]>>8) & 0xFF00;
2018 Vertices[1].Alpha = 0;
2019
2020 if(!GreGradientFill(hDc, Vertices, 2, &gcap, 1, GRADIENT_FILL_RECT_H))
2021 {
2022 ERR("GreGradientFill() failed!\n");
2023 goto cleanup;
2024 }
2025 }
2026 else
2027 {
2028 if(uFlags & DC_INBUTTON)
2029 hBgBrush = IntGetSysColorBrush(COLOR_3DFACE);
2030 else if(uFlags & DC_ACTIVE)
2031 hBgBrush = IntGetSysColorBrush(COLOR_ACTIVECAPTION);
2032 else
2033 hBgBrush = IntGetSysColorBrush(COLOR_INACTIVECAPTION);
2034
2035 hOldBrush = NtGdiSelectBrush(hDc, hBgBrush);
2036
2037 if(!hOldBrush)
2038 {
2039 ERR("NtGdiSelectBrush() failed!\n");
2040 goto cleanup;
2041 }
2042
2043 if(!NtGdiPatBlt(hDc, Rect.left, Rect.top,
2044 Rect.right - Rect.left,
2045 Rect.bottom - Rect.top,
2046 PATCOPY))
2047 {
2048 ERR("NtGdiPatBlt() failed!\n");
2049 goto cleanup;
2050 }
2051 }
2052
2053 /* Draw icon */
2054 if (HasIcon)
2055 {
2056 PCURICON_OBJECT pIcon = NULL;
2057
2058 if (hIcon)
2059 {
2060 pIcon = UserGetCurIconObject(hIcon);
2061 }
2062 else if (pWnd)
2063 {
2064 pIcon = NC_IconForWindow(pWnd);
2065 // FIXME: NC_IconForWindow should reference it for us */
2066 if (pIcon)
2067 UserReferenceObject(pIcon);
2068 }
2069
2070 if (pIcon)
2071 {
2072 LONG cx = UserGetSystemMetrics(SM_CXSMICON);
2073 LONG cy = UserGetSystemMetrics(SM_CYSMICON);
2074 LONG x = Rect.left - cx/2 + 1 + (Rect.bottom - Rect.top)/2; // this is really what Window does
2075 LONG y = (Rect.top + Rect.bottom)/2 - cy/2; // center
2076 UserDrawIconEx(hDc, x, y, pIcon, cx, cy, 0, NULL, DI_NORMAL);
2077 UserDereferenceObject(pIcon);
2078 }
2079 else
2080 {
2081 HasIcon = FALSE;
2082 }
2083 }
2084
2085 if (HasIcon)
2086 Rect.left += Rect.bottom - Rect.top;
2087
2088 if((uFlags & DC_TEXT))
2089 {
2090 Rect.left += 2;
2091
2092 if (Str)
2093 UserDrawCaptionText(pWnd, hDc, Str, &Rect, uFlags, hFont);
2094 else if (pWnd != NULL) // FIXME: Windows does not do that
2095 {
2096 UNICODE_STRING ustr;
2097 ustr.Buffer = pWnd->strName.Buffer; // FIXME: LARGE_STRING truncated!
2098 ustr.Length = (USHORT)min(pWnd->strName.Length, MAXUSHORT);
2099 ustr.MaximumLength = (USHORT)min(pWnd->strName.MaximumLength, MAXUSHORT);
2100 UserDrawCaptionText(pWnd, hDc, &ustr, &Rect, uFlags, hFont);
2101 }
2102 }
2103
2104 Ret = TRUE;
2105
2106 cleanup:
2107 if (hOldBrush) NtGdiSelectBrush(hDc, hOldBrush);
2108
2109 return Ret;
2110 }
2111
2112 INT
2113 FASTCALL
2114 UserRealizePalette(HDC hdc)
2115 {
2116 HWND hWnd, hWndDesktop;
2117 DWORD Ret;
2118
2119 Ret = IntGdiRealizePalette(hdc);
2120 if (Ret) // There was a change.
2121 {
2122 hWnd = IntWindowFromDC(hdc);
2123 if (hWnd) // Send broadcast if dc is associated with a window.
2124 { // FYI: Thread locked in CallOneParam.
2125 hWndDesktop = IntGetDesktopWindow();
2126 if ( hWndDesktop != hWnd )
2127 {
2128 PWND pWnd = UserGetWindowObject(hWndDesktop);
2129 ERR("RealizePalette Desktop.");
2130 hdc = UserGetWindowDC(pWnd);
2131 IntPaintDesktop(hdc);
2132 UserReleaseDC(pWnd,hdc,FALSE);
2133 }
2134 UserSendNotifyMessage((HWND)HWND_BROADCAST, WM_PALETTECHANGED, (WPARAM)hWnd, 0);
2135 }
2136 }
2137 return Ret;
2138 }
2139
2140 BOOL
2141 APIENTRY
2142 NtUserDrawCaptionTemp(
2143 HWND hWnd,
2144 HDC hDC,
2145 LPCRECT lpRc,
2146 HFONT hFont,
2147 HICON hIcon,
2148 const PUNICODE_STRING str,
2149 UINT uFlags)
2150 {
2151 PWND pWnd = NULL;
2152 UNICODE_STRING SafeStr = {0};
2153 NTSTATUS Status = STATUS_SUCCESS;
2154 RECTL SafeRect;
2155 BOOL Ret;
2156
2157 UserEnterExclusive();
2158
2159 if (hWnd != NULL)
2160 {
2161 if(!(pWnd = UserGetWindowObject(hWnd)))
2162 {
2163 UserLeave();
2164 return FALSE;
2165 }
2166 }
2167
2168 _SEH2_TRY
2169 {
2170 ProbeForRead(lpRc, sizeof(RECTL), sizeof(ULONG));
2171 RtlCopyMemory(&SafeRect, lpRc, sizeof(RECTL));
2172 if (str != NULL)
2173 {
2174 SafeStr = ProbeForReadUnicodeString(str);
2175 if (SafeStr.Length != 0)
2176 {
2177 ProbeForRead( SafeStr.Buffer,
2178 SafeStr.Length,
2179 sizeof(WCHAR));
2180 }
2181 }
2182 }
2183 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
2184 {
2185 Status = _SEH2_GetExceptionCode();
2186 }
2187 _SEH2_END;
2188
2189 if (Status != STATUS_SUCCESS)
2190 {
2191 SetLastNtError(Status);
2192 UserLeave();
2193 return FALSE;
2194 }
2195
2196 if (str != NULL)
2197 Ret = UserDrawCaption(pWnd, hDC, &SafeRect, hFont, hIcon, &SafeStr, uFlags);
2198 else
2199 Ret = UserDrawCaption(pWnd, hDC, &SafeRect, hFont, hIcon, NULL, uFlags);
2200
2201 UserLeave();
2202 return Ret;
2203 }
2204
2205 BOOL
2206 APIENTRY
2207 NtUserDrawCaption(HWND hWnd,
2208 HDC hDC,
2209 LPCRECT lpRc,
2210 UINT uFlags)
2211 {
2212 return NtUserDrawCaptionTemp(hWnd, hDC, lpRc, 0, 0, NULL, uFlags);
2213 }
2214
2215 BOOL
2216 APIENTRY
2217 NtUserInvalidateRect(
2218 HWND hWnd,
2219 CONST RECT *lpUnsafeRect,
2220 BOOL bErase)
2221 {
2222 UINT flags = RDW_INVALIDATE | (bErase ? RDW_ERASE : 0);
2223 if (!hWnd)
2224 {
2225 flags = RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW;
2226 lpUnsafeRect = NULL;
2227 }
2228 return NtUserRedrawWindow(hWnd, lpUnsafeRect, NULL, flags);
2229 }
2230
2231 BOOL
2232 APIENTRY
2233 NtUserInvalidateRgn(
2234 HWND hWnd,
2235 HRGN hRgn,
2236 BOOL bErase)
2237 {
2238 if (!hWnd)
2239 {
2240 EngSetLastError( ERROR_INVALID_WINDOW_HANDLE );
2241 return FALSE;
2242 }
2243 return NtUserRedrawWindow(hWnd, NULL, hRgn, RDW_INVALIDATE | (bErase? RDW_ERASE : 0));
2244 }
2245
2246 BOOL
2247 APIENTRY
2248 NtUserPrintWindow(
2249 HWND hwnd,
2250 HDC hdcBlt,
2251 UINT nFlags)
2252 {
2253 PWND Window;
2254 BOOL Ret = FALSE;
2255
2256 UserEnterExclusive();
2257
2258 if (hwnd)
2259 {
2260 if (!(Window = UserGetWindowObject(hwnd)) || // FIXME:
2261 Window == UserGetDesktopWindow() || // pWnd->fnid == FNID_DESKTOP
2262 Window == UserGetMessageWindow() ) // pWnd->fnid == FNID_MESSAGEWND
2263 {
2264 goto Exit;
2265 }
2266
2267 if ( Window )
2268 {
2269 /* Validate flags and check it as a mask for 0 or 1. */
2270 if ( (nFlags & PW_CLIENTONLY) == nFlags)
2271 Ret = IntPrintWindow( Window, hdcBlt, nFlags);
2272 else
2273 EngSetLastError(ERROR_INVALID_PARAMETER);
2274 }
2275 }
2276 Exit:
2277 UserLeave();
2278 return Ret;
2279 }
2280
2281 /* ValidateRect gets redirected to NtUserValidateRect:
2282 http://blog.csdn.net/ntdll/archive/2005/10/19/509299.aspx */
2283 BOOL
2284 APIENTRY
2285 NtUserValidateRect(
2286 HWND hWnd,
2287 const RECT *lpRect)
2288 {
2289 UINT flags = RDW_VALIDATE;
2290 if (!hWnd)
2291 {
2292 flags = RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW;
2293 lpRect = NULL;
2294 }
2295 return NtUserRedrawWindow(hWnd, lpRect, NULL, flags);
2296 }
2297
2298 /* EOF */