include/mscvpdb.h: Use flexible array members for the rest of structures.
[wine.git] / dlls / win32u / dce.c
blob4a672d6c519a4f20d5f74229699cb5ebb0898786
1 /*
2 * Window painting functions
4 * Copyright 1993, 1994, 1995, 2001, 2004, 2005, 2008 Alexandre Julliard
5 * Copyright 1996, 1997, 1999 Alex Korobka
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #if 0
23 #pragma makedep unix
24 #endif
26 #include <assert.h>
27 #include <pthread.h>
28 #include "ntstatus.h"
29 #define WIN32_NO_STATUS
30 #include "ntgdi_private.h"
31 #include "ntuser_private.h"
32 #include "wine/server.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(win);
37 struct dce
39 struct list entry; /* entry in global DCE list */
40 HDC hdc;
41 HWND hwnd;
42 HRGN clip_rgn;
43 UINT flags;
44 LONG count; /* usage count; 0 or 1 for cache DCEs, always 1 for window DCEs,
45 always >= 1 for class DCEs */
48 static struct list dce_list = LIST_INIT(dce_list);
50 #define DCE_CACHE_SIZE 64
52 static struct list window_surfaces = LIST_INIT( window_surfaces );
53 static pthread_mutex_t surfaces_lock = PTHREAD_MUTEX_INITIALIZER;
55 /*******************************************************************
56 * Dummy window surface for windows that shouldn't get painted.
59 static void dummy_surface_set_clip( struct window_surface *window_surface, const RECT *rects, UINT count )
61 /* nothing to do */
64 static BOOL dummy_surface_flush( struct window_surface *window_surface, const RECT *rect, const RECT *dirty,
65 const BITMAPINFO *color_info, const void *color_bits, BOOL shape_changed,
66 const BITMAPINFO *shape_info, const void *shape_bits )
68 /* nothing to do */
69 return TRUE;
72 static void dummy_surface_destroy( struct window_surface *window_surface )
74 /* nothing to do */
77 static const struct window_surface_funcs dummy_surface_funcs =
79 dummy_surface_set_clip,
80 dummy_surface_flush,
81 dummy_surface_destroy
84 struct window_surface dummy_surface =
86 .funcs = &dummy_surface_funcs,
87 .ref = 1,
88 .rect = {.right = 1, .bottom = 1},
89 .mutex = PTHREAD_MUTEX_INITIALIZER,
92 /*******************************************************************
93 * Off-screen window surface.
96 static void offscreen_window_surface_set_clip( struct window_surface *surface, const RECT *rects, UINT count )
100 static BOOL offscreen_window_surface_flush( struct window_surface *surface, const RECT *rect, const RECT *dirty,
101 const BITMAPINFO *color_info, const void *color_bits, BOOL shape_changed,
102 const BITMAPINFO *shape_info, const void *shape_bits )
104 return TRUE;
107 static void offscreen_window_surface_destroy( struct window_surface *surface )
109 free( surface );
112 static const struct window_surface_funcs offscreen_window_surface_funcs =
114 offscreen_window_surface_set_clip,
115 offscreen_window_surface_flush,
116 offscreen_window_surface_destroy
119 void create_offscreen_window_surface( HWND hwnd, const RECT *surface_rect, struct window_surface **window_surface )
121 char buffer[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
122 BITMAPINFO *info = (BITMAPINFO *)buffer;
123 struct window_surface *surface, *previous;
125 TRACE( "hwnd %p, surface_rect %s, window_surface %p.\n", hwnd, wine_dbgstr_rect( surface_rect ), window_surface );
127 /* check that old surface is an offscreen_window_surface, or release it */
128 if ((previous = *window_surface) && previous->funcs == &offscreen_window_surface_funcs &&
129 EqualRect( surface_rect, &previous->rect )) return;
130 if (previous) window_surface_release( previous );
131 *window_surface = NULL;
133 memset( info, 0, sizeof(*info) );
134 info->bmiHeader.biSize = sizeof(info->bmiHeader);
135 info->bmiHeader.biWidth = surface_rect->right;
136 info->bmiHeader.biHeight = -surface_rect->bottom; /* top-down */
137 info->bmiHeader.biPlanes = 1;
138 info->bmiHeader.biBitCount = 32;
139 info->bmiHeader.biSizeImage = get_dib_image_size( info );
140 info->bmiHeader.biCompression = BI_RGB;
142 /* create a new window surface */
143 if (!(surface = calloc(1, sizeof(*surface)))) return;
144 window_surface_init( surface, &offscreen_window_surface_funcs, hwnd, surface_rect, info, 0 );
146 TRACE( "created window surface %p\n", surface );
147 *window_surface = surface;
150 /* window surface common helpers */
152 static UINT get_color_component( UINT color, UINT mask )
154 int shift;
155 for (shift = 0; !(mask & 1); shift++) mask >>= 1;
156 return (color * mask / 255) << shift;
159 static COLORREF get_color_key( const BITMAPINFO *info, COLORREF color_key )
161 if (color_key == CLR_INVALID) return CLR_INVALID;
162 if (info->bmiHeader.biBitCount <= 8) return CLR_INVALID;
163 if (color_key & (1 << 24)) /* PALETTEINDEX */ return 0;
164 if (color_key >> 16 == 0x10ff) /* DIBINDEX */ return 0;
166 if (info->bmiHeader.biCompression == BI_BITFIELDS)
168 UINT *masks = (UINT *)info->bmiColors;
169 return get_color_component( GetRValue( color_key ), masks[0] ) |
170 get_color_component( GetGValue( color_key ), masks[1] ) |
171 get_color_component( GetBValue( color_key ), masks[2] );
174 return (GetRValue( color_key ) << 16) | (GetGValue( color_key ) << 8) | GetBValue( color_key );
177 static void set_surface_shape_rect( BYTE *bits, UINT stride, const RECT *rect )
179 BYTE *begin = bits + rect->top * stride, *end = bits + rect->bottom * stride;
180 UINT l = rect->left / 8, l_mask, r = rect->right / 8, r_mask;
182 /* 1bpp bitmaps use MSB for lowest X */
183 l_mask = (1 << (8 - (rect->left & 7))) - 1;
184 r_mask = (1 << (8 - (rect->right & 7))) - 1;
185 if (r_mask == 0xff) { r--; r_mask = 0; } /* avoid writing to the next byte */
187 if (rect->right - rect->left == 8 * stride) memset( begin, 0xff, end - begin );
188 else if (l == r) for (bits = begin; bits < end; bits += stride) bits[l] |= l_mask & r_mask;
189 else if (l < r)
191 for (bits = begin; bits < end; bits += stride)
193 bits[l] |= l_mask;
194 memset( bits + l + 1, 0xff, r - l - 1 );
195 bits[r] |= ~r_mask;
200 static void *window_surface_get_shape( struct window_surface *surface, BITMAPINFO *info )
202 struct bitblt_coords coords = {0};
203 struct gdi_image_bits gdi_bits;
204 BITMAPOBJ *bmp;
206 if (!(bmp = GDI_GetObjPtr( surface->shape_bitmap, NTGDI_OBJ_BITMAP ))) return NULL;
207 get_image_from_bitmap( bmp, info, &gdi_bits, &coords );
208 GDI_ReleaseObj( surface->shape_bitmap );
210 return gdi_bits.ptr;
213 static BYTE shape_from_alpha_mask( UINT32 *bits, UINT32 alpha_mask, UINT32 alpha )
215 BYTE i, bit, mask = 0;
216 for (i = 0, bit = 7; i < 8; i++, bit--) mask |= ((bits[i] & alpha_mask) == alpha) << bit;
217 return ~mask;
220 static BYTE shape_from_color_key_16( UINT16 *bits, UINT16 color_mask, UINT16 color_key )
222 BYTE i, bit, mask = 0;
223 for (i = 0, bit = 7; i < 8; i++, bit--) mask |= ((bits[i] & color_mask) == color_key) << bit;
224 return ~mask;
227 static BYTE shape_from_color_key_32( UINT32 *bits, UINT32 color_mask, UINT32 color_key )
229 BYTE i, bit, mask = 0;
230 for (i = 0, bit = 7; i < 8; i++, bit--) mask |= ((bits[i] & color_mask) == color_key) << bit;
231 return ~mask;
234 static BOOL set_surface_shape( struct window_surface *surface, const RECT *rect, const RECT *dirty,
235 const BITMAPINFO *color_info, void *color_bits )
237 UINT width, height, x, y, shape_stride, color_stride, alpha_mask = surface->alpha_mask;
238 char shape_buf[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
239 BITMAPINFO *shape_info = (BITMAPINFO *)shape_buf;
240 COLORREF color_key = surface->color_key;
241 void *shape_bits, *old_shape;
242 RECT *shape_rect, tmp_rect;
243 WINEREGION *data;
244 BOOL ret;
246 width = color_info->bmiHeader.biWidth;
247 height = abs( color_info->bmiHeader.biHeight );
248 assert( !(width & 7) ); /* expect 1bpp bitmap to be aligned on bytes */
250 if (!surface->shape_bitmap) surface->shape_bitmap = NtGdiCreateBitmap( width, height, 1, 1, NULL );
251 if (!(shape_bits = window_surface_get_shape( surface, shape_info ))) return FALSE;
253 old_shape = malloc( shape_info->bmiHeader.biSizeImage );
254 memcpy( old_shape, shape_bits, shape_info->bmiHeader.biSizeImage );
256 color_stride = color_info->bmiHeader.biSizeImage / height;
257 shape_stride = shape_info->bmiHeader.biSizeImage / abs( shape_info->bmiHeader.biHeight );
259 if (!surface->shape_region) set_surface_shape_rect( shape_bits, shape_stride, dirty );
260 else if ((data = GDI_GetObjPtr( surface->shape_region, NTGDI_OBJ_REGION )))
262 if (EqualRect( rect, dirty )) memset( shape_bits, 0, shape_info->bmiHeader.biSizeImage );
263 for (shape_rect = data->rects; shape_rect < data->rects + data->numRects; shape_rect++)
265 if (!intersect_rect( &tmp_rect, shape_rect, dirty )) continue;
266 set_surface_shape_rect( shape_bits, shape_stride, &tmp_rect );
268 GDI_ReleaseObj( surface->shape_region );
271 switch (color_info->bmiHeader.biBitCount)
273 case 16:
275 UINT *masks = (UINT *)color_info->bmiColors, color_mask;
276 BYTE *shape = shape_bits, *color = color_bits;
278 if (color_key == CLR_INVALID) color_mask = 0;
279 else color_mask = masks[0] | masks[1] | masks[2];
280 if (!color_mask) break;
282 color += dirty->top * color_stride;
283 shape += dirty->top * shape_stride;
285 for (y = dirty->top; y < dirty->bottom; y++, color += color_stride, shape += shape_stride)
287 for (x = dirty->left; x < dirty->right; x += 8)
289 shape[x / 8] &= shape_from_color_key_16( (UINT16 *)color + x, color_mask, color_key );
292 break;
294 case 24: case 32:
296 BYTE *shape = shape_bits, *color = color_bits;
297 UINT color_mask, alpha = 0;
299 if (color_key == CLR_INVALID) color_mask = 0;
300 else if (color_info->bmiHeader.biCompression == BI_RGB) color_mask = 0xffffff;
301 else
303 UINT *masks = (UINT *)color_info->bmiColors;
304 color_mask = masks[0] | masks[1] | masks[2];
306 if (!alpha_mask && !color_mask) break;
307 if (!alpha_mask) alpha = -1;
309 color += dirty->top * color_stride;
310 shape += dirty->top * shape_stride;
312 for (y = dirty->top; y < dirty->bottom; y++, color += color_stride, shape += shape_stride)
314 for (x = dirty->left; x < dirty->right; x += 8)
316 shape[x / 8] &= shape_from_alpha_mask( (UINT32 *)color + x, alpha_mask, alpha );
317 shape[x / 8] &= shape_from_color_key_32( (UINT32 *)color + x, color_mask, color_key );
320 break;
324 ret = memcmp( old_shape, shape_bits, shape_info->bmiHeader.biSizeImage );
325 free( old_shape );
326 return ret;
329 static BOOL clear_surface_shape( struct window_surface *surface )
331 if (!surface->shape_bitmap) return FALSE;
332 NtGdiDeleteObjectApp( surface->shape_bitmap );
333 surface->shape_bitmap = 0;
334 return TRUE;
337 static BOOL update_surface_shape( struct window_surface *surface, const RECT *rect, const RECT *dirty,
338 const BITMAPINFO *color_info, void *color_bits )
340 if (surface == &dummy_surface) return FALSE;
342 if (surface->shape_region || surface->alpha_mask || surface->color_key != CLR_INVALID)
343 return set_surface_shape( surface, rect, dirty, color_info, color_bits );
344 else
345 return clear_surface_shape( surface );
348 W32KAPI BOOL window_surface_init( struct window_surface *surface, const struct window_surface_funcs *funcs,
349 HWND hwnd, const RECT *rect, BITMAPINFO *info, HBITMAP bitmap )
351 surface->funcs = funcs;
352 surface->ref = 1;
353 surface->hwnd = hwnd;
354 surface->rect = *rect;
355 surface->color_key = CLR_INVALID;
356 surface->alpha_bits = -1;
357 surface->alpha_mask = 0;
358 pthread_mutex_init( &surface->mutex, NULL );
359 reset_bounds( &surface->bounds );
361 if (!bitmap) bitmap = NtGdiCreateDIBSection( 0, NULL, 0, info, DIB_RGB_COLORS, 0, 0, 0, NULL );
362 if (!(surface->color_bitmap = bitmap)) return FALSE;
364 return TRUE;
367 W32KAPI void window_surface_add_ref( struct window_surface *surface )
369 InterlockedIncrement( &surface->ref );
372 W32KAPI void window_surface_release( struct window_surface *surface )
374 ULONG ret = InterlockedDecrement( &surface->ref );
375 if (!ret)
377 if (surface != &dummy_surface) pthread_mutex_destroy( &surface->mutex );
378 if (surface->clip_region) NtGdiDeleteObjectApp( surface->clip_region );
379 if (surface->color_bitmap) NtGdiDeleteObjectApp( surface->color_bitmap );
380 if (surface->shape_bitmap) NtGdiDeleteObjectApp( surface->shape_bitmap );
381 surface->funcs->destroy( surface );
385 W32KAPI void window_surface_lock( struct window_surface *surface )
387 if (surface == &dummy_surface) return;
388 pthread_mutex_lock( &surface->mutex );
391 W32KAPI void window_surface_unlock( struct window_surface *surface )
393 if (surface == &dummy_surface) return;
394 pthread_mutex_unlock( &surface->mutex );
397 void *window_surface_get_color( struct window_surface *surface, BITMAPINFO *info )
399 struct bitblt_coords coords = {0};
400 struct gdi_image_bits gdi_bits;
401 BITMAPOBJ *bmp;
403 if (surface == &dummy_surface)
405 static BITMAPINFOHEADER header = {.biSize = sizeof(header), .biWidth = 1, .biHeight = 1,
406 .biPlanes = 1, .biBitCount = 32, .biCompression = BI_RGB};
407 static DWORD dummy_data;
409 info->bmiHeader = header;
410 return &dummy_data;
413 if (!(bmp = GDI_GetObjPtr( surface->color_bitmap, NTGDI_OBJ_BITMAP ))) return NULL;
414 get_image_from_bitmap( bmp, info, &gdi_bits, &coords );
415 GDI_ReleaseObj( surface->color_bitmap );
417 return gdi_bits.ptr;
420 W32KAPI void window_surface_flush( struct window_surface *surface )
422 char color_buf[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
423 char shape_buf[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
424 BITMAPINFO *color_info = (BITMAPINFO *)color_buf;
425 BITMAPINFO *shape_info = (BITMAPINFO *)shape_buf;
426 RECT dirty = surface->rect, bounds;
427 void *color_bits;
429 window_surface_lock( surface );
431 /* align bounds / dirty rect to help with 1bpp shape bitmap updates */
432 bounds.left = surface->bounds.left & ~7;
433 bounds.top = surface->bounds.top;
434 bounds.right = (surface->bounds.right + 7) & ~7;
435 bounds.bottom = surface->bounds.bottom;
437 OffsetRect( &dirty, -dirty.left, -dirty.top );
439 if (intersect_rect( &dirty, &dirty, &bounds ) && (color_bits = window_surface_get_color( surface, color_info )))
441 BOOL shape_changed = update_surface_shape( surface, &surface->rect, &dirty, color_info, color_bits );
442 void *shape_bits = window_surface_get_shape( surface, shape_info );
444 TRACE( "Flushing hwnd %p, surface %p %s, bounds %s, dirty %s\n", surface->hwnd, surface,
445 wine_dbgstr_rect( &surface->rect ), wine_dbgstr_rect( &surface->bounds ), wine_dbgstr_rect( &dirty ) );
447 if (surface->funcs->flush( surface, &surface->rect, &dirty, color_info, color_bits,
448 shape_changed, shape_info, shape_bits ))
449 reset_bounds( &surface->bounds );
452 window_surface_unlock( surface );
455 W32KAPI void window_surface_set_layered( struct window_surface *surface, COLORREF color_key, UINT alpha_bits, UINT alpha_mask )
457 char color_buf[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
458 BITMAPINFO *color_info = (BITMAPINFO *)color_buf;
459 void *color_bits;
461 window_surface_lock( surface );
462 if ((color_bits = window_surface_get_color( surface, color_info )))
464 color_key = get_color_key( color_info, color_key );
465 if (color_key != surface->color_key)
467 surface->color_key = color_key;
468 surface->bounds = surface->rect;
470 if (alpha_bits != surface->alpha_bits)
472 surface->alpha_bits = alpha_bits;
473 surface->bounds = surface->rect;
475 if (alpha_mask != surface->alpha_mask)
477 surface->alpha_mask = alpha_mask;
478 surface->bounds = surface->rect;
481 window_surface_unlock( surface );
484 W32KAPI void window_surface_set_clip( struct window_surface *surface, HRGN clip_region )
486 window_surface_lock( surface );
488 if (!clip_region && surface->clip_region)
490 TRACE( "hwnd %p, surface %p %s, clearing clip region\n", surface->hwnd, surface,
491 wine_dbgstr_rect( &surface->rect ) );
493 NtGdiDeleteObjectApp( surface->clip_region );
494 surface->clip_region = 0;
495 surface->funcs->set_clip( surface, NULL, 0 );
497 else if (clip_region && !NtGdiEqualRgn( clip_region, surface->clip_region ))
499 WINEREGION *data;
501 TRACE( "hwnd %p, surface %p %s, setting clip region %p\n", surface->hwnd, surface,
502 wine_dbgstr_rect( &surface->rect ), clip_region );
504 if (!surface->clip_region) surface->clip_region = NtGdiCreateRectRgn( 0, 0, 0, 0 );
505 NtGdiCombineRgn( surface->clip_region, clip_region, 0, RGN_COPY );
507 if ((data = GDI_GetObjPtr( clip_region, NTGDI_OBJ_REGION )))
509 surface->funcs->set_clip( surface, data->rects, data->numRects );
510 GDI_ReleaseObj( clip_region );
514 window_surface_unlock( surface );
517 W32KAPI void window_surface_set_shape( struct window_surface *surface, HRGN shape_region )
519 window_surface_lock( surface );
521 if (!shape_region && surface->shape_region)
523 NtGdiDeleteObjectApp( surface->shape_region );
524 surface->shape_region = 0;
525 surface->bounds = surface->rect;
527 else if (shape_region && !NtGdiEqualRgn( shape_region, surface->shape_region ))
529 if (!surface->shape_region) surface->shape_region = NtGdiCreateRectRgn( 0, 0, 0, 0 );
530 NtGdiCombineRgn( surface->shape_region, shape_region, 0, RGN_COPY );
531 surface->bounds = surface->rect;
534 window_surface_unlock( surface );
536 window_surface_flush( surface );
539 /*******************************************************************
540 * register_window_surface
542 * Register a window surface in the global list, possibly replacing another one.
544 void register_window_surface( struct window_surface *old, struct window_surface *new )
546 if (old == &dummy_surface) old = NULL;
547 if (new == &dummy_surface) new = NULL;
548 if (old == new) return;
549 pthread_mutex_lock( &surfaces_lock );
550 if (old) list_remove( &old->entry );
551 if (new) list_add_tail( &window_surfaces, &new->entry );
552 pthread_mutex_unlock( &surfaces_lock );
555 /*******************************************************************
556 * flush_window_surfaces
558 * Flush pending output from all window surfaces.
560 void flush_window_surfaces( BOOL idle )
562 static DWORD last_idle;
563 DWORD now;
564 struct window_surface *surface;
566 pthread_mutex_lock( &surfaces_lock );
567 now = NtGetTickCount();
568 if (idle) last_idle = now;
569 /* if not idle, we only flush if there's evidence that the app never goes idle */
570 else if ((int)(now - last_idle) < 50) goto done;
572 LIST_FOR_EACH_ENTRY( surface, &window_surfaces, struct window_surface, entry )
573 window_surface_flush( surface );
574 done:
575 pthread_mutex_unlock( &surfaces_lock );
578 /***********************************************************************
579 * dump_rdw_flags
581 static void dump_rdw_flags(UINT flags)
583 TRACE("flags:");
584 if (flags & RDW_INVALIDATE) TRACE(" RDW_INVALIDATE");
585 if (flags & RDW_INTERNALPAINT) TRACE(" RDW_INTERNALPAINT");
586 if (flags & RDW_ERASE) TRACE(" RDW_ERASE");
587 if (flags & RDW_VALIDATE) TRACE(" RDW_VALIDATE");
588 if (flags & RDW_NOINTERNALPAINT) TRACE(" RDW_NOINTERNALPAINT");
589 if (flags & RDW_NOERASE) TRACE(" RDW_NOERASE");
590 if (flags & RDW_NOCHILDREN) TRACE(" RDW_NOCHILDREN");
591 if (flags & RDW_ALLCHILDREN) TRACE(" RDW_ALLCHILDREN");
592 if (flags & RDW_UPDATENOW) TRACE(" RDW_UPDATENOW");
593 if (flags & RDW_ERASENOW) TRACE(" RDW_ERASENOW");
594 if (flags & RDW_FRAME) TRACE(" RDW_FRAME");
595 if (flags & RDW_NOFRAME) TRACE(" RDW_NOFRAME");
597 #define RDW_FLAGS \
598 (RDW_INVALIDATE | \
599 RDW_INTERNALPAINT | \
600 RDW_ERASE | \
601 RDW_VALIDATE | \
602 RDW_NOINTERNALPAINT | \
603 RDW_NOERASE | \
604 RDW_NOCHILDREN | \
605 RDW_ALLCHILDREN | \
606 RDW_UPDATENOW | \
607 RDW_ERASENOW | \
608 RDW_FRAME | \
609 RDW_NOFRAME)
611 if (flags & ~RDW_FLAGS) TRACE(" %04x", flags & ~RDW_FLAGS);
612 TRACE("\n");
613 #undef RDW_FLAGS
616 /***********************************************************************
617 * update_visible_region
619 * Set the visible region and X11 drawable for the DC associated to
620 * a given window.
622 static void update_visible_region( struct dce *dce )
624 struct window_surface *surface = NULL;
625 NTSTATUS status;
626 HRGN vis_rgn = 0;
627 HWND top_win = 0;
628 DWORD flags = dce->flags;
629 DWORD paint_flags = 0;
630 size_t size = 256;
631 RECT win_rect, top_rect;
632 WND *win;
634 /* don't clip siblings if using parent clip region */
635 if (flags & DCX_PARENTCLIP) flags &= ~DCX_CLIPSIBLINGS;
637 /* fetch the visible region from the server */
640 RGNDATA *data = malloc( sizeof(*data) + size - 1 );
641 if (!data) return;
643 SERVER_START_REQ( get_visible_region )
645 req->window = wine_server_user_handle( dce->hwnd );
646 req->flags = flags;
647 wine_server_set_reply( req, data->Buffer, size );
648 if (!(status = wine_server_call( req )))
650 size_t reply_size = wine_server_reply_size( reply );
651 data->rdh.dwSize = sizeof(data->rdh);
652 data->rdh.iType = RDH_RECTANGLES;
653 data->rdh.nCount = reply_size / sizeof(RECT);
654 data->rdh.nRgnSize = reply_size;
655 vis_rgn = NtGdiExtCreateRegion( NULL, data->rdh.dwSize + data->rdh.nRgnSize, data );
656 top_win = wine_server_ptr_handle( reply->top_win );
657 win_rect = wine_server_get_rect( reply->win_rect );
658 top_rect = wine_server_get_rect( reply->top_rect );
659 paint_flags = reply->paint_flags;
661 else size = reply->total_size;
663 SERVER_END_REQ;
664 free( data );
665 } while (status == STATUS_BUFFER_OVERFLOW);
667 if (status || !vis_rgn) return;
669 user_driver->pGetDC( dce->hdc, dce->hwnd, top_win, &win_rect, &top_rect, flags );
671 if (dce->clip_rgn) NtGdiCombineRgn( vis_rgn, vis_rgn, dce->clip_rgn,
672 (flags & DCX_INTERSECTRGN) ? RGN_AND : RGN_DIFF );
674 /* don't use a surface to paint the client area of OpenGL windows */
675 if (!(paint_flags & SET_WINPOS_PIXEL_FORMAT) || (flags & DCX_WINDOW))
677 win = get_win_ptr( top_win );
678 if (win && win != WND_DESKTOP && win != WND_OTHER_PROCESS)
680 surface = win->surface;
681 if (surface) window_surface_add_ref( surface );
682 release_win_ptr( win );
686 if (!surface) SetRectEmpty( &top_rect );
687 set_visible_region( dce->hdc, vis_rgn, &win_rect, &top_rect, surface );
688 if (surface) window_surface_release( surface );
691 /***********************************************************************
692 * release_dce
694 static void release_dce( struct dce *dce )
696 if (!dce->hwnd) return; /* already released */
698 set_visible_region( dce->hdc, 0, &dummy_surface.rect, &dummy_surface.rect, &dummy_surface );
699 user_driver->pReleaseDC( dce->hwnd, dce->hdc );
701 if (dce->clip_rgn) NtGdiDeleteObjectApp( dce->clip_rgn );
702 dce->clip_rgn = 0;
703 dce->hwnd = 0;
704 dce->flags &= DCX_CACHE;
707 /***********************************************************************
708 * delete_clip_rgn
710 static void delete_clip_rgn( struct dce *dce )
712 if (!dce->clip_rgn) return; /* nothing to do */
714 dce->flags &= ~(DCX_EXCLUDERGN | DCX_INTERSECTRGN);
715 NtGdiDeleteObjectApp( dce->clip_rgn );
716 dce->clip_rgn = 0;
718 /* make it dirty so that the vis rgn gets recomputed next time */
719 set_dce_flags( dce->hdc, DCHF_INVALIDATEVISRGN );
722 /***********************************************************************
723 * delete_dce
725 BOOL delete_dce( struct dce *dce )
727 BOOL ret = TRUE;
729 TRACE( "hdc = %p\n", dce->hdc );
731 user_lock();
732 if (!(dce->flags & DCX_CACHE))
734 WARN("Application trying to delete an owned DC %p\n", dce->hdc);
735 ret = FALSE;
737 else
739 list_remove( &dce->entry );
740 if (dce->clip_rgn) NtGdiDeleteObjectApp( dce->clip_rgn );
741 free( dce );
743 user_unlock();
744 return ret;
747 /***********************************************************************
748 * update_dc
750 * Make sure the DC vis region is up to date.
751 * This function may need user lock so the GDI lock should _not_
752 * be held when calling it.
754 void update_dc( DC *dc )
756 if (!dc->dirty) return;
757 dc->dirty = 0;
758 if (dc->dce)
760 if (dc->dce->count) update_visible_region( dc->dce );
761 else /* non-fatal but shouldn't happen */
762 WARN("DC is not in use!\n");
766 /***********************************************************************
767 * alloc_dce
769 * Allocate a new DCE.
771 static struct dce *alloc_dce(void)
773 struct dce *dce;
775 if (!(dce = malloc( sizeof(*dce) ))) return NULL;
776 if (!(dce->hdc = NtGdiOpenDCW( NULL, NULL, NULL, 0, TRUE, 0, NULL, NULL )))
778 free( dce );
779 return 0;
781 dce->hwnd = 0;
782 dce->clip_rgn = 0;
783 dce->flags = 0;
784 dce->count = 1;
786 set_dc_dce( dce->hdc, dce );
787 return dce;
790 /***********************************************************************
791 * get_window_dce
793 static struct dce *get_window_dce( HWND hwnd )
795 struct dce *dce;
796 WND *win = get_win_ptr( hwnd );
798 if (!win || win == WND_OTHER_PROCESS || win == WND_DESKTOP) return NULL;
800 dce = win->dce;
801 if (!dce && (dce = get_class_dce( win->class )))
803 win->dce = dce;
804 dce->count++;
806 release_win_ptr( win );
808 if (!dce) /* try to allocate one */
810 struct dce *dce_to_free = NULL;
811 LONG class_style = get_class_long( hwnd, GCL_STYLE, FALSE );
813 if (class_style & CS_CLASSDC)
815 if (!(dce = alloc_dce())) return NULL;
817 win = get_win_ptr( hwnd );
818 if (win && win != WND_OTHER_PROCESS && win != WND_DESKTOP)
820 if (win->dce) /* another thread beat us to it */
822 dce_to_free = dce;
823 dce = win->dce;
825 else if ((win->dce = set_class_dce( win->class, dce )) != dce)
827 dce_to_free = dce;
828 dce = win->dce;
829 dce->count++;
831 else
833 dce->count++;
834 list_add_tail( &dce_list, &dce->entry );
836 release_win_ptr( win );
838 else dce_to_free = dce;
840 else if (class_style & CS_OWNDC)
842 if (!(dce = alloc_dce())) return NULL;
844 win = get_win_ptr( hwnd );
845 if (win && win != WND_OTHER_PROCESS && win != WND_DESKTOP)
847 if (win->dwStyle & WS_CLIPCHILDREN) dce->flags |= DCX_CLIPCHILDREN;
848 if (win->dwStyle & WS_CLIPSIBLINGS) dce->flags |= DCX_CLIPSIBLINGS;
849 if (win->dce) /* another thread beat us to it */
851 dce_to_free = dce;
852 dce = win->dce;
854 else
856 win->dce = dce;
857 dce->hwnd = hwnd;
858 list_add_tail( &dce_list, &dce->entry );
860 release_win_ptr( win );
862 else dce_to_free = dce;
865 if (dce_to_free)
867 set_dc_dce( dce_to_free->hdc, NULL );
868 NtGdiDeleteObjectApp( dce_to_free->hdc );
869 free( dce_to_free );
870 if (dce_to_free == dce)
871 dce = NULL;
874 return dce;
877 /***********************************************************************
878 * free_dce
880 * Free a class or window DCE.
882 void free_dce( struct dce *dce, HWND hwnd )
884 struct dce *dce_to_free = NULL;
886 user_lock();
888 if (dce)
890 if (!--dce->count)
892 release_dce( dce );
893 list_remove( &dce->entry );
894 dce_to_free = dce;
896 else if (dce->hwnd == hwnd)
898 release_dce( dce );
902 /* now check for cache DCEs */
904 if (hwnd)
906 LIST_FOR_EACH_ENTRY( dce, &dce_list, struct dce, entry )
908 if (dce->hwnd != hwnd) continue;
909 if (!(dce->flags & DCX_CACHE)) break;
911 release_dce( dce );
912 if (dce->count)
914 WARN( "GetDC() without ReleaseDC() for window %p\n", hwnd );
915 dce->count = 0;
916 set_dce_flags( dce->hdc, DCHF_DISABLEDC );
921 user_unlock();
923 if (dce_to_free)
925 set_dc_dce( dce_to_free->hdc, NULL );
926 NtGdiDeleteObjectApp( dce_to_free->hdc );
927 free( dce_to_free );
931 /***********************************************************************
932 * make_dc_dirty
934 * Mark the associated DC as dirty to force a refresh of the visible region
936 static void make_dc_dirty( struct dce *dce )
938 if (!dce->count)
940 /* Don't bother with visible regions of unused DCEs */
941 TRACE("purged %p hwnd %p\n", dce->hdc, dce->hwnd);
942 release_dce( dce );
944 else
946 /* Set dirty bits in the hDC and DCE structs */
947 TRACE("fixed up %p hwnd %p\n", dce->hdc, dce->hwnd);
948 set_dce_flags( dce->hdc, DCHF_INVALIDATEVISRGN );
952 /***********************************************************************
953 * invalidate_dce
955 * It is called from SetWindowPos() - we have to
956 * mark as dirty all busy DCEs for windows that have pWnd->parent as
957 * an ancestor and whose client rect intersects with specified update
958 * rectangle. In addition, pWnd->parent DCEs may need to be updated if
959 * DCX_CLIPCHILDREN flag is set.
961 void invalidate_dce( WND *win, const RECT *extra_rect )
963 UINT context;
964 RECT window_rect;
965 struct dce *dce;
967 if (!win->parent) return;
969 context = set_thread_dpi_awareness_context( get_window_dpi_awareness_context( win->obj.handle ));
970 get_window_rect( win->obj.handle, &window_rect, get_thread_dpi() );
972 TRACE("%p parent %p %s (%s)\n",
973 win->obj.handle, win->parent, wine_dbgstr_rect(&window_rect), wine_dbgstr_rect(extra_rect) );
975 /* walk all DCEs and fixup non-empty entries */
977 LIST_FOR_EACH_ENTRY( dce, &dce_list, struct dce, entry )
979 if (!dce->hwnd) continue;
981 TRACE( "%p: hwnd %p dcx %08x %s %s\n", dce->hdc, dce->hwnd, dce->flags,
982 (dce->flags & DCX_CACHE) ? "Cache" : "Owned", dce->count ? "InUse" : "" );
984 if ((dce->hwnd == win->parent) && !(dce->flags & DCX_CLIPCHILDREN))
985 continue; /* child window positions don't bother us */
987 /* if DCE window is a child of hwnd, it has to be invalidated */
988 if (dce->hwnd == win->obj.handle || is_child( win->obj.handle, dce->hwnd ))
990 make_dc_dirty( dce );
991 continue;
994 /* otherwise check if the window rectangle intersects this DCE window */
995 if (win->parent == dce->hwnd || is_child( win->parent, dce->hwnd ))
997 RECT dce_rect, tmp;
998 get_window_rect( dce->hwnd, &dce_rect, get_thread_dpi() );
999 if (intersect_rect( &tmp, &dce_rect, &window_rect ) ||
1000 (extra_rect && intersect_rect( &tmp, &dce_rect, extra_rect )))
1001 make_dc_dirty( dce );
1004 set_thread_dpi_awareness_context( context );
1007 /***********************************************************************
1008 * release_dc
1010 static INT release_dc( HWND hwnd, HDC hdc, BOOL end_paint )
1012 struct dce *dce;
1013 BOOL ret = FALSE;
1015 TRACE( "%p %p\n", hwnd, hdc );
1017 user_lock();
1018 dce = get_dc_dce( hdc );
1019 if (dce && dce->count && dce->hwnd)
1021 if (!(dce->flags & DCX_NORESETATTRS)) set_dce_flags( dce->hdc, DCHF_RESETDC );
1022 if (end_paint || (dce->flags & DCX_CACHE)) delete_clip_rgn( dce );
1023 if (dce->flags & DCX_CACHE)
1025 dce->count = 0;
1026 set_dce_flags( dce->hdc, DCHF_DISABLEDC );
1028 ret = TRUE;
1030 user_unlock();
1031 return ret;
1034 /***********************************************************************
1035 * NtUserGetDCEx (win32u.@)
1037 HDC WINAPI NtUserGetDCEx( HWND hwnd, HRGN clip_rgn, DWORD flags )
1039 const DWORD clip_flags = DCX_PARENTCLIP | DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN | DCX_WINDOW;
1040 const DWORD user_flags = clip_flags | DCX_NORESETATTRS; /* flags that can be set by user */
1041 BOOL update_vis_rgn = TRUE;
1042 struct dce *dce;
1043 HWND parent;
1044 LONG window_style = get_window_long( hwnd, GWL_STYLE );
1046 if (!hwnd) hwnd = get_desktop_window();
1047 else hwnd = get_full_window_handle( hwnd );
1049 TRACE( "hwnd %p, clip_rgn %p, flags %08x\n", hwnd, clip_rgn, (int)flags );
1051 if (!is_window(hwnd)) return 0;
1053 /* fixup flags */
1055 if (flags & (DCX_WINDOW | DCX_PARENTCLIP)) flags |= DCX_CACHE;
1057 if (flags & DCX_USESTYLE)
1059 flags &= ~(DCX_CLIPCHILDREN | DCX_CLIPSIBLINGS | DCX_PARENTCLIP);
1061 if (window_style & WS_CLIPSIBLINGS) flags |= DCX_CLIPSIBLINGS;
1063 if (!(flags & DCX_WINDOW))
1065 if (get_class_long( hwnd, GCL_STYLE, FALSE ) & CS_PARENTDC) flags |= DCX_PARENTCLIP;
1067 if (window_style & WS_CLIPCHILDREN && !(window_style & WS_MINIMIZE))
1068 flags |= DCX_CLIPCHILDREN;
1072 if (flags & DCX_WINDOW) flags &= ~DCX_CLIPCHILDREN;
1074 parent = NtUserGetAncestor( hwnd, GA_PARENT );
1075 if (!parent || (parent == get_desktop_window()))
1076 flags = (flags & ~DCX_PARENTCLIP) | DCX_CLIPSIBLINGS;
1078 /* it seems parent clip is ignored when clipping siblings or children */
1079 if (flags & (DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN)) flags &= ~DCX_PARENTCLIP;
1081 if( flags & DCX_PARENTCLIP )
1083 LONG parent_style = get_window_long( parent, GWL_STYLE );
1084 if( (window_style & WS_VISIBLE) && (parent_style & WS_VISIBLE) )
1086 flags &= ~DCX_CLIPCHILDREN;
1087 if (parent_style & WS_CLIPSIBLINGS) flags |= DCX_CLIPSIBLINGS;
1091 /* find a suitable DCE */
1093 if ((flags & DCX_CACHE) || !(dce = get_window_dce( hwnd )))
1095 struct dce *dceEmpty = NULL, *dceUnused = NULL, *found = NULL;
1096 unsigned int count = 0;
1098 /* Strategy: First, we attempt to find a non-empty but unused DCE with
1099 * compatible flags. Next, we look for an empty entry. If the cache is
1100 * full we have to purge one of the unused entries.
1102 user_lock();
1103 LIST_FOR_EACH_ENTRY( dce, &dce_list, struct dce, entry )
1105 if (!(dce->flags & DCX_CACHE)) break;
1106 count++;
1107 if (dce->count) continue;
1108 dceUnused = dce;
1109 if (!dce->hwnd) dceEmpty = dce;
1110 else if ((dce->hwnd == hwnd) && !((dce->flags ^ flags) & clip_flags))
1112 TRACE( "found valid %p hwnd %p, flags %08x\n", dce->hdc, hwnd, dce->flags );
1113 found = dce;
1114 update_vis_rgn = FALSE;
1115 break;
1118 if (!found) found = dceEmpty;
1119 if (!found && count >= DCE_CACHE_SIZE) found = dceUnused;
1121 dce = found;
1122 if (dce)
1124 dce->count = 1;
1125 set_dce_flags( dce->hdc, DCHF_ENABLEDC );
1127 user_unlock();
1129 /* if there's no dce empty or unused, allocate a new one */
1130 if (!dce)
1132 if (!(dce = alloc_dce())) return 0;
1133 dce->flags = DCX_CACHE;
1134 user_lock();
1135 list_add_head( &dce_list, &dce->entry );
1136 user_unlock();
1139 else
1141 flags |= DCX_NORESETATTRS;
1142 if (dce->hwnd != hwnd)
1144 /* we should free dce->clip_rgn here, but Windows apparently doesn't */
1145 dce->flags &= ~(DCX_EXCLUDERGN | DCX_INTERSECTRGN);
1146 dce->clip_rgn = 0;
1148 else update_vis_rgn = FALSE; /* updated automatically, via DCHook() */
1151 if (flags & (DCX_INTERSECTRGN | DCX_EXCLUDERGN))
1153 /* if the extra clip region has changed, get rid of the old one */
1154 if (dce->clip_rgn != clip_rgn || ((flags ^ dce->flags) & (DCX_INTERSECTRGN | DCX_EXCLUDERGN)))
1155 delete_clip_rgn( dce );
1156 dce->clip_rgn = clip_rgn;
1157 if (!dce->clip_rgn) dce->clip_rgn = NtGdiCreateRectRgn( 0, 0, 0, 0 );
1158 dce->flags |= flags & (DCX_INTERSECTRGN | DCX_EXCLUDERGN);
1159 update_vis_rgn = TRUE;
1162 if (get_window_long( hwnd, GWL_EXSTYLE ) & WS_EX_LAYOUTRTL)
1163 NtGdiSetLayout( dce->hdc, -1, LAYOUT_RTL );
1165 dce->hwnd = hwnd;
1166 dce->flags = (dce->flags & ~user_flags) | (flags & user_flags);
1168 /* cross-process invalidation is not supported yet, so always update the vis rgn */
1169 if (!is_current_process_window( hwnd )) update_vis_rgn = TRUE;
1171 if (set_dce_flags( dce->hdc, DCHF_VALIDATEVISRGN )) update_vis_rgn = TRUE; /* DC was dirty */
1173 if (update_vis_rgn) update_visible_region( dce );
1175 TRACE( "(%p,%p,0x%x): returning %p%s\n", hwnd, clip_rgn, (int)flags, dce->hdc,
1176 update_vis_rgn ? " (updated)" : "" );
1177 return dce->hdc;
1180 /***********************************************************************
1181 * NtUserReleaseDC (win32u.@)
1183 INT WINAPI NtUserReleaseDC( HWND hwnd, HDC hdc )
1185 return release_dc( hwnd, hdc, FALSE );
1188 /***********************************************************************
1189 * NtUserGetDC (win32u.@)
1191 HDC WINAPI NtUserGetDC( HWND hwnd )
1193 if (!hwnd) return NtUserGetDCEx( 0, 0, DCX_CACHE | DCX_WINDOW );
1194 return NtUserGetDCEx( hwnd, 0, DCX_USESTYLE );
1197 /***********************************************************************
1198 * NtUserGetWindowDC (win32u.@)
1200 HDC WINAPI NtUserGetWindowDC( HWND hwnd )
1202 return NtUserGetDCEx( hwnd, 0, DCX_USESTYLE | DCX_WINDOW );
1205 /**********************************************************************
1206 * NtUserWindowFromDC (win32u.@)
1208 HWND WINAPI NtUserWindowFromDC( HDC hdc )
1210 struct dce *dce;
1211 HWND hwnd = 0;
1213 user_lock();
1214 dce = get_dc_dce( hdc );
1215 if (dce) hwnd = dce->hwnd;
1216 user_unlock();
1217 return hwnd;
1220 /***********************************************************************
1221 * get_update_region
1223 * Return update region (in screen coordinates) for a window.
1225 static HRGN get_update_region( HWND hwnd, UINT *flags, HWND *child )
1227 HRGN hrgn = 0;
1228 NTSTATUS status;
1229 RGNDATA *data;
1230 size_t size = 256;
1234 if (!(data = malloc( sizeof(*data) + size - 1 )))
1236 RtlSetLastWin32Error( ERROR_OUTOFMEMORY );
1237 return 0;
1240 SERVER_START_REQ( get_update_region )
1242 req->window = wine_server_user_handle( hwnd );
1243 req->from_child = wine_server_user_handle( child ? *child : 0 );
1244 req->flags = *flags;
1245 wine_server_set_reply( req, data->Buffer, size );
1246 if (!(status = wine_server_call( req )))
1248 size_t reply_size = wine_server_reply_size( reply );
1249 data->rdh.dwSize = sizeof(data->rdh);
1250 data->rdh.iType = RDH_RECTANGLES;
1251 data->rdh.nCount = reply_size / sizeof(RECT);
1252 data->rdh.nRgnSize = reply_size;
1253 hrgn = NtGdiExtCreateRegion( NULL, data->rdh.dwSize + data->rdh.nRgnSize, data );
1254 if (child) *child = wine_server_ptr_handle( reply->child );
1255 *flags = reply->flags;
1257 else size = reply->total_size;
1259 SERVER_END_REQ;
1260 free( data );
1261 } while (status == STATUS_BUFFER_OVERFLOW);
1263 if (status) RtlSetLastWin32Error( RtlNtStatusToDosError(status) );
1264 return hrgn;
1267 /***********************************************************************
1268 * redraw_window_rects
1270 * Redraw part of a window.
1272 static BOOL redraw_window_rects( HWND hwnd, UINT flags, const RECT *rects, UINT count )
1274 BOOL ret;
1276 if (!(flags & (RDW_INVALIDATE|RDW_VALIDATE|RDW_INTERNALPAINT|RDW_NOINTERNALPAINT)))
1277 return TRUE; /* nothing to do */
1279 SERVER_START_REQ( redraw_window )
1281 req->window = wine_server_user_handle( hwnd );
1282 req->flags = flags;
1283 wine_server_add_data( req, rects, count * sizeof(RECT) );
1284 ret = !wine_server_call_err( req );
1286 SERVER_END_REQ;
1287 return ret;
1290 /***********************************************************************
1291 * get_update_flags
1293 * Get only the update flags, not the update region.
1295 static BOOL get_update_flags( HWND hwnd, HWND *child, UINT *flags )
1297 BOOL ret;
1299 SERVER_START_REQ( get_update_region )
1301 req->window = wine_server_user_handle( hwnd );
1302 req->from_child = wine_server_user_handle( child ? *child : 0 );
1303 req->flags = *flags | UPDATE_NOREGION;
1304 if ((ret = !wine_server_call_err( req )))
1306 if (child) *child = wine_server_ptr_handle( reply->child );
1307 *flags = reply->flags;
1310 SERVER_END_REQ;
1311 return ret;
1314 /***********************************************************************
1315 * send_ncpaint
1317 * Send a WM_NCPAINT message if needed, and return the resulting update region (in screen coords).
1318 * Helper for erase_now and BeginPaint.
1320 static HRGN send_ncpaint( HWND hwnd, HWND *child, UINT *flags )
1322 HRGN whole_rgn = get_update_region( hwnd, flags, child );
1323 HRGN client_rgn = 0;
1324 DWORD style;
1326 if (child) hwnd = *child;
1328 if (hwnd == get_desktop_window()) return whole_rgn;
1330 if (whole_rgn)
1332 UINT context;
1333 RECT client, window, update;
1334 INT type;
1336 context = set_thread_dpi_awareness_context( get_window_dpi_awareness_context( hwnd ));
1338 /* check if update rgn overlaps with nonclient area */
1339 type = NtGdiGetRgnBox( whole_rgn, &update );
1340 get_window_rects( hwnd, COORDS_SCREEN, &window, &client, get_thread_dpi() );
1342 if ((*flags & UPDATE_NONCLIENT) ||
1343 update.left < client.left || update.top < client.top ||
1344 update.right > client.right || update.bottom > client.bottom)
1346 client_rgn = NtGdiCreateRectRgn( client.left, client.top, client.right, client.bottom );
1347 NtGdiCombineRgn( client_rgn, client_rgn, whole_rgn, RGN_AND );
1349 /* check if update rgn contains complete nonclient area */
1350 if (type == SIMPLEREGION && EqualRect( &window, &update ))
1352 NtGdiDeleteObjectApp( whole_rgn );
1353 whole_rgn = (HRGN)1;
1356 else
1358 client_rgn = whole_rgn;
1359 whole_rgn = 0;
1362 if (whole_rgn) /* NOTE: WM_NCPAINT allows wParam to be 1 */
1364 if (*flags & UPDATE_NONCLIENT)
1366 /* Mark standard scroll bars as not painted before sending WM_NCPAINT */
1367 style = get_window_long( hwnd, GWL_STYLE );
1368 if (style & WS_HSCROLL)
1369 set_standard_scroll_painted( hwnd, SB_HORZ, FALSE );
1370 if (style & WS_VSCROLL)
1371 set_standard_scroll_painted( hwnd, SB_VERT, FALSE );
1373 send_message( hwnd, WM_NCPAINT, (WPARAM)whole_rgn, 0 );
1375 if (whole_rgn > (HRGN)1) NtGdiDeleteObjectApp( whole_rgn );
1377 set_thread_dpi_awareness_context( context );
1379 return client_rgn;
1382 /***********************************************************************
1383 * send_erase
1385 * Send a WM_ERASEBKGND message if needed, and optionally return the DC for painting.
1386 * If a DC is requested, the region is selected into it. In all cases the region is deleted.
1387 * Helper for erase_now and BeginPaint.
1389 static BOOL send_erase( HWND hwnd, UINT flags, HRGN client_rgn,
1390 RECT *clip_rect, HDC *hdc_ret )
1392 BOOL need_erase = (flags & UPDATE_DELAYED_ERASE) != 0;
1393 HDC hdc = 0;
1394 RECT dummy;
1396 if (!clip_rect) clip_rect = &dummy;
1397 if (hdc_ret || (flags & UPDATE_ERASE))
1399 UINT dcx_flags = DCX_INTERSECTRGN | DCX_USESTYLE;
1400 if (is_iconic(hwnd)) dcx_flags |= DCX_WINDOW;
1402 if ((hdc = NtUserGetDCEx( hwnd, client_rgn, dcx_flags )))
1404 INT type = NtGdiGetAppClipBox( hdc, clip_rect );
1406 if (flags & UPDATE_ERASE)
1408 /* don't erase if the clip box is empty */
1409 if (type != NULLREGION)
1410 need_erase = !send_message( hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0 );
1412 if (!hdc_ret) release_dc( hwnd, hdc, TRUE );
1415 if (hdc_ret) *hdc_ret = hdc;
1417 if (!hdc) NtGdiDeleteObjectApp( client_rgn );
1418 return need_erase;
1421 /***********************************************************************
1422 * move_window_bits
1424 * Move the window bits when a window is resized, or moved within a parent window.
1426 void move_window_bits( HWND hwnd, const RECT *visible_rect, const RECT *old_visible_rect,
1427 const RECT *window_rect, const RECT *valid_rects )
1429 RECT dst = valid_rects[0];
1430 RECT src = valid_rects[1];
1432 if (src.left - old_visible_rect->left != dst.left - visible_rect->left ||
1433 src.top - old_visible_rect->top != dst.top - visible_rect->top)
1435 UINT flags = UPDATE_NOCHILDREN | UPDATE_CLIPCHILDREN;
1436 HRGN rgn = get_update_region( hwnd, &flags, NULL );
1437 HDC hdc = NtUserGetDCEx( hwnd, rgn, DCX_CACHE | DCX_WINDOW | DCX_EXCLUDERGN );
1439 TRACE( "copying %s -> %s\n", wine_dbgstr_rect( &src ), wine_dbgstr_rect( &dst ));
1440 OffsetRect( &src, -window_rect->left, -window_rect->top );
1441 OffsetRect( &dst, -window_rect->left, -window_rect->top );
1443 NtGdiStretchBlt( hdc, dst.left, dst.top, dst.right - dst.left, dst.bottom - dst.top,
1444 hdc, src.left, src.top, src.right - src.left, src.bottom - src.top, SRCCOPY, 0 );
1445 NtUserReleaseDC( hwnd, hdc );
1450 /***********************************************************************
1451 * move_window_bits_surface
1453 * Move the window bits from a previous window surface when its surface is recreated.
1455 void move_window_bits_surface( HWND hwnd, const RECT *window_rect, struct window_surface *old_surface,
1456 const RECT *old_visible_rect, const RECT *valid_rects )
1458 char buffer[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
1459 BITMAPINFO *info = (BITMAPINFO *)buffer;
1460 UINT flags = UPDATE_NOCHILDREN | UPDATE_CLIPCHILDREN;
1461 HRGN rgn = get_update_region( hwnd, &flags, NULL );
1462 HDC hdc = NtUserGetDCEx( hwnd, rgn, DCX_CACHE | DCX_WINDOW | DCX_EXCLUDERGN );
1463 void *bits;
1465 RECT dst = valid_rects[0];
1466 RECT src = valid_rects[1];
1468 TRACE( "copying %s -> %s\n", wine_dbgstr_rect( &src ), wine_dbgstr_rect( &dst ));
1469 OffsetRect( &src, -old_visible_rect->left, -old_visible_rect->top );
1470 OffsetRect( &dst, -window_rect->left, -window_rect->top );
1472 window_surface_lock( old_surface );
1473 bits = window_surface_get_color( old_surface, info );
1474 NtGdiSetDIBitsToDeviceInternal( hdc, dst.left, dst.top, dst.right - dst.left, dst.bottom - dst.top,
1475 src.left - old_surface->rect.left, old_surface->rect.bottom - src.bottom,
1476 0, old_surface->rect.bottom - old_surface->rect.top,
1477 bits, info, DIB_RGB_COLORS, 0, 0, FALSE, NULL );
1478 window_surface_unlock( old_surface );
1479 NtUserReleaseDC( hwnd, hdc );
1483 /***********************************************************************
1484 * NtUserBeginPaint (win32u.@)
1486 HDC WINAPI NtUserBeginPaint( HWND hwnd, PAINTSTRUCT *ps )
1488 HRGN hrgn;
1489 HDC hdc;
1490 BOOL erase;
1491 RECT rect;
1492 UINT flags = UPDATE_NONCLIENT | UPDATE_ERASE | UPDATE_PAINT | UPDATE_INTERNALPAINT | UPDATE_NOCHILDREN;
1494 NtUserHideCaret( hwnd );
1496 if (!(hrgn = send_ncpaint( hwnd, NULL, &flags ))) return 0;
1498 erase = send_erase( hwnd, flags, hrgn, &rect, &hdc );
1500 TRACE( "hdc = %p box = (%s), fErase = %d\n", hdc, wine_dbgstr_rect(&rect), erase );
1502 if (!ps)
1504 release_dc( hwnd, hdc, TRUE );
1505 return 0;
1507 ps->fErase = erase;
1508 ps->rcPaint = rect;
1509 ps->hdc = hdc;
1510 return hdc;
1513 /***********************************************************************
1514 * NtUserEndPaint (win32u.@)
1516 BOOL WINAPI NtUserEndPaint( HWND hwnd, const PAINTSTRUCT *ps )
1518 NtUserShowCaret( hwnd );
1519 flush_window_surfaces( FALSE );
1520 if (!ps) return FALSE;
1521 release_dc( hwnd, ps->hdc, TRUE );
1522 return TRUE;
1525 /***********************************************************************
1526 * erase_now
1528 * Implementation of RDW_ERASENOW behavior.
1530 void erase_now( HWND hwnd, UINT rdw_flags )
1532 HWND child = 0;
1533 HRGN hrgn;
1534 BOOL need_erase = FALSE;
1536 /* loop while we find a child to repaint */
1537 for (;;)
1539 UINT flags = UPDATE_NONCLIENT | UPDATE_ERASE;
1541 if (rdw_flags & RDW_NOCHILDREN) flags |= UPDATE_NOCHILDREN;
1542 else if (rdw_flags & RDW_ALLCHILDREN) flags |= UPDATE_ALLCHILDREN;
1543 if (need_erase) flags |= UPDATE_DELAYED_ERASE;
1545 if (!(hrgn = send_ncpaint( hwnd, &child, &flags ))) break;
1546 need_erase = send_erase( child, flags, hrgn, NULL, NULL );
1548 if (!flags) break; /* nothing more to do */
1549 if ((rdw_flags & RDW_NOCHILDREN) && !need_erase) break;
1553 /***********************************************************************
1554 * update_now
1556 * Implementation of RDW_UPDATENOW behavior.
1558 static void update_now( HWND hwnd, UINT rdw_flags )
1560 HWND child = 0;
1562 /* desktop window never gets WM_PAINT, only WM_ERASEBKGND */
1563 if (hwnd == get_desktop_window()) erase_now( hwnd, rdw_flags | RDW_NOCHILDREN );
1565 /* loop while we find a child to repaint */
1566 for (;;)
1568 UINT flags = UPDATE_PAINT | UPDATE_INTERNALPAINT;
1570 if (rdw_flags & RDW_NOCHILDREN) flags |= UPDATE_NOCHILDREN;
1571 else if (rdw_flags & RDW_ALLCHILDREN) flags |= UPDATE_ALLCHILDREN;
1573 if (!get_update_flags( hwnd, &child, &flags )) break;
1574 if (!flags) break; /* nothing more to do */
1576 send_message( child, WM_PAINT, 0, 0 );
1577 if (rdw_flags & RDW_NOCHILDREN) break;
1581 /***********************************************************************
1582 * NtUserRedrawWindow (win32u.@)
1584 BOOL WINAPI NtUserRedrawWindow( HWND hwnd, const RECT *rect, HRGN hrgn, UINT flags )
1586 static const RECT empty;
1587 BOOL ret;
1589 if (TRACE_ON(win))
1591 if (hrgn)
1593 RECT r;
1594 NtGdiGetRgnBox( hrgn, &r );
1595 TRACE( "%p region %p box %s ", hwnd, hrgn, wine_dbgstr_rect(&r) );
1597 else if (rect)
1598 TRACE( "%p rect %s ", hwnd, wine_dbgstr_rect(rect) );
1599 else
1600 TRACE( "%p whole window ", hwnd );
1602 dump_rdw_flags(flags);
1605 /* process pending expose events before painting */
1606 if (flags & RDW_UPDATENOW) user_driver->pProcessEvents( QS_PAINT );
1608 if (rect && !hrgn)
1610 RECT ordered = *rect;
1612 order_rect( &ordered );
1613 if (IsRectEmpty( &ordered )) ordered = empty;
1614 ret = redraw_window_rects( hwnd, flags, &ordered, 1 );
1616 else if (!hrgn)
1618 ret = redraw_window_rects( hwnd, flags, NULL, 0 );
1620 else /* need to build a list of the region rectangles */
1622 DWORD size;
1623 RGNDATA *data;
1625 if (!(size = NtGdiGetRegionData( hrgn, 0, NULL ))) return FALSE;
1626 if (!(data = malloc( size ))) return FALSE;
1627 NtGdiGetRegionData( hrgn, size, data );
1628 if (!data->rdh.nCount) /* empty region -> use a single all-zero rectangle */
1629 ret = redraw_window_rects( hwnd, flags, &empty, 1 );
1630 else
1631 ret = redraw_window_rects( hwnd, flags, (const RECT *)data->Buffer, data->rdh.nCount );
1632 free( data );
1635 if (!hwnd) hwnd = get_desktop_window();
1637 if (flags & RDW_UPDATENOW) update_now( hwnd, flags );
1638 else if (flags & RDW_ERASENOW) erase_now( hwnd, flags );
1640 return ret;
1643 /***********************************************************************
1644 * NtUserValidateRect (win32u.@)
1646 BOOL WINAPI NtUserValidateRect( HWND hwnd, const RECT *rect )
1648 UINT flags = RDW_VALIDATE;
1650 if (!hwnd)
1652 flags = RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW;
1653 rect = NULL;
1656 return NtUserRedrawWindow( hwnd, rect, 0, flags );
1659 /***********************************************************************
1660 * NtUserGetUpdateRgn (win32u.@)
1662 INT WINAPI NtUserGetUpdateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
1664 INT retval = ERROR;
1665 UINT flags = UPDATE_NOCHILDREN, context;
1666 HRGN update_rgn;
1668 context = set_thread_dpi_awareness_context( get_window_dpi_awareness_context( hwnd ));
1670 if (erase) flags |= UPDATE_NONCLIENT | UPDATE_ERASE;
1672 if ((update_rgn = send_ncpaint( hwnd, NULL, &flags )))
1674 retval = NtGdiCombineRgn( hrgn, update_rgn, 0, RGN_COPY );
1675 if (send_erase( hwnd, flags, update_rgn, NULL, NULL ))
1677 flags = UPDATE_DELAYED_ERASE;
1678 get_update_flags( hwnd, NULL, &flags );
1680 /* map region to client coordinates */
1681 map_window_region( 0, hwnd, hrgn );
1683 set_thread_dpi_awareness_context( context );
1684 return retval;
1687 /***********************************************************************
1688 * NtUserGetUpdateRect (win32u.@)
1690 BOOL WINAPI NtUserGetUpdateRect( HWND hwnd, RECT *rect, BOOL erase )
1692 UINT flags = UPDATE_NOCHILDREN;
1693 HRGN update_rgn;
1694 BOOL need_erase;
1696 if (erase) flags |= UPDATE_NONCLIENT | UPDATE_ERASE;
1698 if (!(update_rgn = send_ncpaint( hwnd, NULL, &flags ))) return FALSE;
1700 if (rect && NtGdiGetRgnBox( update_rgn, rect ) != NULLREGION)
1702 HDC hdc = NtUserGetDCEx( hwnd, 0, DCX_USESTYLE );
1703 DWORD layout = NtGdiSetLayout( hdc, -1, 0 ); /* map_window_points mirrors already */
1704 UINT win_dpi = get_dpi_for_window( hwnd );
1705 map_window_points( 0, hwnd, (POINT *)rect, 2, win_dpi );
1706 *rect = map_dpi_rect( *rect, win_dpi, get_thread_dpi() );
1707 NtGdiTransformPoints( hdc, (POINT *)rect, (POINT *)rect, 2, NtGdiDPtoLP );
1708 NtGdiSetLayout( hdc, -1, layout );
1709 NtUserReleaseDC( hwnd, hdc );
1711 need_erase = send_erase( hwnd, flags, update_rgn, NULL, NULL );
1713 /* check if we still have an update region */
1714 flags = UPDATE_PAINT | UPDATE_NOCHILDREN;
1715 if (need_erase) flags |= UPDATE_DELAYED_ERASE;
1716 return get_update_flags( hwnd, NULL, &flags ) && (flags & UPDATE_PAINT);
1719 /***********************************************************************
1720 * NtUserExcludeUpdateRgn (win32u.@)
1722 INT WINAPI NtUserExcludeUpdateRgn( HDC hdc, HWND hwnd )
1724 HRGN update_rgn = NtGdiCreateRectRgn( 0, 0, 0, 0 );
1725 INT ret = NtUserGetUpdateRgn( hwnd, update_rgn, FALSE );
1727 if (ret != ERROR)
1729 UINT context;
1730 POINT pt;
1732 context = set_thread_dpi_awareness_context( get_window_dpi_awareness_context( hwnd ));
1733 NtGdiGetDCPoint( hdc, NtGdiGetDCOrg, &pt );
1734 map_window_points( 0, hwnd, &pt, 1, get_thread_dpi() );
1735 NtGdiOffsetRgn( update_rgn, -pt.x, -pt.y );
1736 ret = NtGdiExtSelectClipRgn( hdc, update_rgn, RGN_DIFF );
1737 set_thread_dpi_awareness_context( context );
1739 NtGdiDeleteObjectApp( update_rgn );
1740 return ret;
1743 /***********************************************************************
1744 * NtUserInvalidateRgn (win32u.@)
1746 BOOL WINAPI NtUserInvalidateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
1748 if (!hwnd)
1750 RtlSetLastWin32Error( ERROR_INVALID_WINDOW_HANDLE );
1751 return FALSE;
1754 return NtUserRedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
1757 /***********************************************************************
1758 * NtUserInvalidateRect (win32u.@)
1760 BOOL WINAPI NtUserInvalidateRect( HWND hwnd, const RECT *rect, BOOL erase )
1762 UINT flags = RDW_INVALIDATE | (erase ? RDW_ERASE : 0);
1764 if (!hwnd)
1766 flags = RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW;
1767 rect = NULL;
1770 return NtUserRedrawWindow( hwnd, rect, 0, flags );
1773 /***********************************************************************
1774 * NtUserLockWindowUpdate (win32u.@)
1776 BOOL WINAPI NtUserLockWindowUpdate( HWND hwnd )
1778 static HWND locked_hwnd;
1780 FIXME( "(%p), partial stub!\n", hwnd );
1782 if (!hwnd)
1784 locked_hwnd = NULL;
1785 return TRUE;
1787 return !InterlockedCompareExchangePointer( (void **)&locked_hwnd, hwnd, 0 );
1790 /*************************************************************************
1791 * fix_caret
1793 * Helper for NtUserScrollWindowEx:
1794 * If the return value is 0, no special caret handling is necessary.
1795 * Otherwise the return value is the handle of the window that owns the
1796 * caret. Its caret needs to be hidden during the scroll operation and
1797 * moved to new_caret_pos if move_caret is TRUE.
1799 static HWND fix_caret( HWND hwnd, const RECT *scroll_rect, INT dx, INT dy,
1800 UINT flags, BOOL *move_caret, POINT *new_caret_pos )
1802 RECT rect, mapped_caret;
1803 GUITHREADINFO info;
1805 info.cbSize = sizeof(info);
1806 if (!NtUserGetGUIThreadInfo( GetCurrentThreadId(), &info )) return 0;
1807 if (!info.hwndCaret) return 0;
1809 mapped_caret = info.rcCaret;
1810 if (info.hwndCaret == hwnd)
1812 /* The caret needs to be moved along with scrolling even if it's
1813 * outside the visible area. Otherwise, when the caret is scrolled
1814 * out from the view, the position won't get updated anymore and
1815 * the caret will never scroll back again. */
1816 *move_caret = TRUE;
1817 new_caret_pos->x = info.rcCaret.left + dx;
1818 new_caret_pos->y = info.rcCaret.top + dy;
1820 else
1822 *move_caret = FALSE;
1823 if (!(flags & SW_SCROLLCHILDREN) || !is_child( hwnd, info.hwndCaret ))
1824 return 0;
1825 map_window_points( info.hwndCaret, hwnd, (POINT *)&mapped_caret, 2, get_thread_dpi() );
1828 /* If the caret is not in the src/dest rects, all is fine done. */
1829 if (!intersect_rect( &rect, scroll_rect, &mapped_caret ))
1831 rect = *scroll_rect;
1832 OffsetRect( &rect, dx, dy );
1833 if (!intersect_rect( &rect, &rect, &mapped_caret ))
1834 return 0;
1837 /* Indicate that the caret needs to be updated during the scrolling. */
1838 return info.hwndCaret;
1841 /*************************************************************************
1842 * NtUserScrollWindowEx (win32u.@)
1844 * Note: contrary to what the doc says, pixels that are scrolled from the
1845 * outside of clipRect to the inside are NOT painted.
1847 INT WINAPI NtUserScrollWindowEx( HWND hwnd, INT dx, INT dy, const RECT *rect,
1848 const RECT *clip_rect, HRGN update_rgn,
1849 RECT *update_rect, UINT flags )
1851 BOOL update = update_rect || update_rgn || flags & (SW_INVALIDATE | SW_ERASE);
1852 BOOL own_rgn = TRUE, move_caret = FALSE;
1853 HRGN temp_rgn, winupd_rgn = 0;
1854 INT retval = NULLREGION;
1855 HWND caret_hwnd = NULL;
1856 POINT new_caret_pos;
1857 RECT rc, cliprc;
1858 int rdw_flags;
1859 HDC hdc;
1861 TRACE( "%p, %d,%d update_rgn=%p update_rect = %p %s %04x\n",
1862 hwnd, dx, dy, update_rgn, update_rect, wine_dbgstr_rect(rect), flags );
1863 TRACE( "clip_rect = %s\n", wine_dbgstr_rect(clip_rect) );
1864 if (flags & ~(SW_SCROLLCHILDREN | SW_INVALIDATE | SW_ERASE | SW_NODCCACHE))
1865 FIXME( "some flags (%04x) are unhandled\n", flags );
1867 rdw_flags = (flags & SW_ERASE) && (flags & SW_INVALIDATE) ?
1868 RDW_INVALIDATE | RDW_ERASE : RDW_INVALIDATE;
1870 if (!is_window_drawable( hwnd, TRUE )) return ERROR;
1871 hwnd = get_full_window_handle( hwnd );
1873 get_client_rect( hwnd, &rc, get_thread_dpi() );
1874 if (clip_rect) intersect_rect( &cliprc, &rc, clip_rect );
1875 else cliprc = rc;
1877 if (rect) intersect_rect( &rc, &rc, rect );
1878 if (update_rgn) own_rgn = FALSE;
1879 else if (update) update_rgn = NtGdiCreateRectRgn( 0, 0, 0, 0 );
1881 new_caret_pos.x = new_caret_pos.y = 0;
1883 if (!IsRectEmpty( &cliprc ) && (dx || dy))
1885 DWORD style = get_window_long( hwnd, GWL_STYLE );
1886 DWORD dcxflags = 0;
1888 caret_hwnd = fix_caret( hwnd, &rc, dx, dy, flags, &move_caret, &new_caret_pos );
1889 if (caret_hwnd) NtUserHideCaret( caret_hwnd );
1891 if (!(flags & SW_NODCCACHE)) dcxflags |= DCX_CACHE;
1892 if (style & WS_CLIPSIBLINGS) dcxflags |= DCX_CLIPSIBLINGS;
1893 if (get_class_long( hwnd, GCL_STYLE, FALSE ) & CS_PARENTDC) dcxflags |= DCX_PARENTCLIP;
1894 if (!(flags & SW_SCROLLCHILDREN) && (style & WS_CLIPCHILDREN))
1895 dcxflags |= DCX_CLIPCHILDREN;
1896 hdc = NtUserGetDCEx( hwnd, 0, dcxflags);
1897 if (hdc)
1899 NtUserScrollDC( hdc, dx, dy, &rc, &cliprc, update_rgn, update_rect );
1900 NtUserReleaseDC( hwnd, hdc );
1901 if (!update) NtUserRedrawWindow( hwnd, NULL, update_rgn, rdw_flags );
1904 /* If the windows has an update region, this must be scrolled as well.
1905 * Keep a copy in winupd_rgn to be added to hrngUpdate at the end. */
1906 temp_rgn = NtGdiCreateRectRgn( 0, 0, 0, 0 );
1907 retval = NtUserGetUpdateRgn( hwnd, temp_rgn, FALSE );
1908 if (retval != NULLREGION)
1910 HRGN clip_rgn = NtGdiCreateRectRgn( cliprc.left, cliprc.top,
1911 cliprc.right, cliprc.bottom );
1912 if (!own_rgn)
1914 winupd_rgn = NtGdiCreateRectRgn( 0, 0, 0, 0);
1915 NtGdiCombineRgn( winupd_rgn, temp_rgn, 0, RGN_COPY);
1917 NtGdiOffsetRgn( temp_rgn, dx, dy );
1918 NtGdiCombineRgn( temp_rgn, temp_rgn, clip_rgn, RGN_AND );
1919 if (!own_rgn) NtGdiCombineRgn( winupd_rgn, winupd_rgn, temp_rgn, RGN_OR );
1920 NtUserRedrawWindow( hwnd, NULL, temp_rgn, rdw_flags );
1923 * Catch the case where the scrolling amount exceeds the size of the
1924 * original window. This generated a second update area that is the
1925 * location where the original scrolled content would end up.
1926 * This second region is not returned by the ScrollDC and sets
1927 * ScrollWindowEx apart from just a ScrollDC.
1929 * This has been verified with testing on windows.
1931 if (abs( dx ) > abs( rc.right - rc.left ) || abs( dy ) > abs( rc.bottom - rc.top ))
1933 NtGdiSetRectRgn( temp_rgn, rc.left + dx, rc.top + dy, rc.right+dx, rc.bottom + dy );
1934 NtGdiCombineRgn( temp_rgn, temp_rgn, clip_rgn, RGN_AND );
1935 NtGdiCombineRgn( update_rgn, update_rgn, temp_rgn, RGN_OR );
1937 if (update_rect)
1939 RECT temp_rect;
1940 NtGdiGetRgnBox( temp_rgn, &temp_rect );
1941 union_rect( update_rect, update_rect, &temp_rect );
1944 if (!own_rgn) NtGdiCombineRgn( winupd_rgn, winupd_rgn, temp_rgn, RGN_OR );
1946 NtGdiDeleteObjectApp( clip_rgn );
1948 NtGdiDeleteObjectApp( temp_rgn );
1950 else
1952 /* nothing was scrolled */
1953 if (!own_rgn) NtGdiSetRectRgn( update_rgn, 0, 0, 0, 0 );
1954 SetRectEmpty( update_rect );
1957 if (flags & SW_SCROLLCHILDREN)
1959 HWND *list = list_window_children( 0, hwnd, NULL, 0 );
1960 if (list)
1962 RECT r, dummy;
1963 int i;
1965 for (i = 0; list[i]; i++)
1967 get_window_rects( list[i], COORDS_PARENT, &r, NULL, get_thread_dpi() );
1968 if (!rect || intersect_rect( &dummy, &r, rect ))
1969 NtUserSetWindowPos( list[i], 0, r.left + dx, r.top + dy, 0, 0,
1970 SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE |
1971 SWP_NOREDRAW | SWP_DEFERERASE );
1973 free( list );
1977 if (flags & (SW_INVALIDATE | SW_ERASE))
1978 NtUserRedrawWindow( hwnd, NULL, update_rgn, rdw_flags |
1979 ((flags & SW_SCROLLCHILDREN) ? RDW_ALLCHILDREN : 0 ) );
1981 if (winupd_rgn)
1983 NtGdiCombineRgn( update_rgn, update_rgn, winupd_rgn, RGN_OR );
1984 NtGdiDeleteObjectApp( winupd_rgn );
1987 if (move_caret) set_caret_pos( new_caret_pos.x, new_caret_pos.y );
1988 if (caret_hwnd) NtUserShowCaret( caret_hwnd );
1989 if (own_rgn && update_rgn) NtGdiDeleteObjectApp( update_rgn );
1991 return retval;
1994 /************************************************************************
1995 * NtUserPrintWindow (win32u.@)
1997 BOOL WINAPI NtUserPrintWindow( HWND hwnd, HDC hdc, UINT flags )
1999 UINT prf_flags = PRF_CHILDREN | PRF_ERASEBKGND | PRF_OWNED | PRF_CLIENT;
2000 if (!(flags & PW_CLIENTONLY)) prf_flags |= PRF_NONCLIENT;
2001 send_message( hwnd, WM_PRINT, (WPARAM)hdc, prf_flags );
2002 return TRUE;