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
23 #include "wine/port.h"
30 #define WIN32_NO_STATUS
35 #include "wine/server.h"
37 #include "user_private.h"
39 #include "wine/gdi_driver.h"
40 #include "wine/list.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(win
);
48 struct list entry
; /* entry in global DCE list */
53 LONG count
; /* usage count; 0 or 1 for cache DCEs, always 1 for window DCEs,
54 always >= 1 for class DCEs */
57 static struct list dce_list
= LIST_INIT(dce_list
);
59 static BOOL CALLBACK
dc_hook( HDC hDC
, WORD code
, DWORD_PTR data
, LPARAM lParam
);
61 static const WCHAR displayW
[] = { 'D','I','S','P','L','A','Y',0 };
64 /***********************************************************************
67 static void dump_rdw_flags(UINT flags
)
70 if (flags
& RDW_INVALIDATE
) TRACE(" RDW_INVALIDATE");
71 if (flags
& RDW_INTERNALPAINT
) TRACE(" RDW_INTERNALPAINT");
72 if (flags
& RDW_ERASE
) TRACE(" RDW_ERASE");
73 if (flags
& RDW_VALIDATE
) TRACE(" RDW_VALIDATE");
74 if (flags
& RDW_NOINTERNALPAINT
) TRACE(" RDW_NOINTERNALPAINT");
75 if (flags
& RDW_NOERASE
) TRACE(" RDW_NOERASE");
76 if (flags
& RDW_NOCHILDREN
) TRACE(" RDW_NOCHILDREN");
77 if (flags
& RDW_ALLCHILDREN
) TRACE(" RDW_ALLCHILDREN");
78 if (flags
& RDW_UPDATENOW
) TRACE(" RDW_UPDATENOW");
79 if (flags
& RDW_ERASENOW
) TRACE(" RDW_ERASENOW");
80 if (flags
& RDW_FRAME
) TRACE(" RDW_FRAME");
81 if (flags
& RDW_NOFRAME
) TRACE(" RDW_NOFRAME");
88 RDW_NOINTERNALPAINT | \
97 if (flags
& ~RDW_FLAGS
) TRACE(" %04x", flags
& ~RDW_FLAGS
);
103 /***********************************************************************
104 * update_visible_region
106 * Set the visible region and X11 drawable for the DC associated to
109 static void update_visible_region( struct dce
*dce
)
111 struct window_surface
*surface
= NULL
;
115 DWORD flags
= dce
->flags
;
116 DWORD paint_flags
= 0;
118 RECT win_rect
, top_rect
;
121 /* don't clip siblings if using parent clip region */
122 if (flags
& DCX_PARENTCLIP
) flags
&= ~DCX_CLIPSIBLINGS
;
124 /* fetch the visible region from the server */
127 RGNDATA
*data
= HeapAlloc( GetProcessHeap(), 0, sizeof(*data
) + size
- 1 );
130 SERVER_START_REQ( get_visible_region
)
132 req
->window
= wine_server_user_handle( dce
->hwnd
);
134 wine_server_set_reply( req
, data
->Buffer
, size
);
135 if (!(status
= wine_server_call( req
)))
137 size_t reply_size
= wine_server_reply_size( reply
);
138 data
->rdh
.dwSize
= sizeof(data
->rdh
);
139 data
->rdh
.iType
= RDH_RECTANGLES
;
140 data
->rdh
.nCount
= reply_size
/ sizeof(RECT
);
141 data
->rdh
.nRgnSize
= reply_size
;
142 vis_rgn
= ExtCreateRegion( NULL
, size
, data
);
144 top_win
= wine_server_ptr_handle( reply
->top_win
);
145 win_rect
.left
= reply
->win_rect
.left
;
146 win_rect
.top
= reply
->win_rect
.top
;
147 win_rect
.right
= reply
->win_rect
.right
;
148 win_rect
.bottom
= reply
->win_rect
.bottom
;
149 top_rect
.left
= reply
->top_rect
.left
;
150 top_rect
.top
= reply
->top_rect
.top
;
151 top_rect
.right
= reply
->top_rect
.right
;
152 top_rect
.bottom
= reply
->top_rect
.bottom
;
153 paint_flags
= reply
->paint_flags
;
155 else size
= reply
->total_size
;
158 HeapFree( GetProcessHeap(), 0, data
);
159 } while (status
== STATUS_BUFFER_OVERFLOW
);
161 if (status
|| !vis_rgn
) return;
163 USER_Driver
->pGetDC( dce
->hdc
, dce
->hwnd
, top_win
, &win_rect
, &top_rect
, flags
);
165 if (dce
->clip_rgn
) CombineRgn( vis_rgn
, vis_rgn
, dce
->clip_rgn
,
166 (flags
& DCX_INTERSECTRGN
) ? RGN_AND
: RGN_DIFF
);
168 /* don't use a surface to paint the client area of OpenGL windows */
169 if (!(paint_flags
& SET_WINPOS_PIXEL_FORMAT
) || (flags
& DCX_WINDOW
))
171 win
= WIN_GetPtr( top_win
);
172 if (win
&& win
!= WND_DESKTOP
&& win
!= WND_OTHER_PROCESS
)
174 surface
= win
->surface
;
175 if (surface
) window_surface_add_ref( surface
);
176 WIN_ReleasePtr( win
);
180 if (!surface
) top_rect
= get_virtual_screen_rect();
181 __wine_set_visible_region( dce
->hdc
, vis_rgn
, &win_rect
, &top_rect
, surface
);
182 if (surface
) window_surface_release( surface
);
186 /***********************************************************************
189 static void release_dce( struct dce
*dce
)
191 if (!dce
->hwnd
) return; /* already released */
193 __wine_set_visible_region( dce
->hdc
, 0, &dummy_surface
.rect
, &dummy_surface
.rect
, &dummy_surface
);
194 USER_Driver
->pReleaseDC( dce
->hwnd
, dce
->hdc
);
196 if (dce
->clip_rgn
) DeleteObject( dce
->clip_rgn
);
199 dce
->flags
&= DCX_CACHE
;
203 /***********************************************************************
206 static void delete_clip_rgn( struct dce
*dce
)
208 if (!dce
->clip_rgn
) return; /* nothing to do */
210 dce
->flags
&= ~(DCX_EXCLUDERGN
| DCX_INTERSECTRGN
);
211 DeleteObject( dce
->clip_rgn
);
214 /* make it dirty so that the vis rgn gets recomputed next time */
215 SetHookFlags( dce
->hdc
, DCHF_INVALIDATEVISRGN
);
219 /***********************************************************************
222 * Allocate a new DCE.
224 static struct dce
*alloc_dce(void)
228 if (!(dce
= HeapAlloc( GetProcessHeap(), 0, sizeof(*dce
) ))) return NULL
;
229 if (!(dce
->hdc
= CreateDCW( displayW
, NULL
, NULL
, NULL
)))
231 HeapFree( GetProcessHeap(), 0, dce
);
239 /* store DCE handle in DC hook data field */
240 SetDCHook( dce
->hdc
, dc_hook
, (DWORD_PTR
)dce
);
241 SetHookFlags( dce
->hdc
, DCHF_INVALIDATEVISRGN
);
246 /***********************************************************************
249 static struct dce
*get_window_dce( HWND hwnd
)
252 WND
*win
= WIN_GetPtr( hwnd
);
254 if (!win
|| win
== WND_OTHER_PROCESS
|| win
== WND_DESKTOP
) return NULL
;
257 if (!dce
&& (dce
= get_class_dce( win
->class )))
262 WIN_ReleasePtr( win
);
264 if (!dce
) /* try to allocate one */
266 struct dce
*dce_to_free
= NULL
;
267 LONG class_style
= GetClassLongW( hwnd
, GCL_STYLE
);
269 if (class_style
& CS_CLASSDC
)
271 if (!(dce
= alloc_dce())) return NULL
;
273 win
= WIN_GetPtr( hwnd
);
274 if (win
&& win
!= WND_OTHER_PROCESS
&& win
!= WND_DESKTOP
)
276 if (win
->dce
) /* another thread beat us to it */
281 else if ((win
->dce
= set_class_dce( win
->class, dce
)) != dce
)
290 list_add_tail( &dce_list
, &dce
->entry
);
292 WIN_ReleasePtr( win
);
294 else dce_to_free
= dce
;
296 else if (class_style
& CS_OWNDC
)
298 if (!(dce
= alloc_dce())) return NULL
;
300 win
= WIN_GetPtr( hwnd
);
301 if (win
&& win
!= WND_OTHER_PROCESS
&& win
!= WND_DESKTOP
)
303 if (win
->dwStyle
& WS_CLIPCHILDREN
) dce
->flags
|= DCX_CLIPCHILDREN
;
304 if (win
->dwStyle
& WS_CLIPSIBLINGS
) dce
->flags
|= DCX_CLIPSIBLINGS
;
305 if (win
->dce
) /* another thread beat us to it */
315 list_add_tail( &dce_list
, &dce
->entry
);
317 WIN_ReleasePtr( win
);
319 else dce_to_free
= dce
;
324 SetDCHook( dce_to_free
->hdc
, NULL
, 0 );
325 DeleteDC( dce_to_free
->hdc
);
326 HeapFree( GetProcessHeap(), 0, dce_to_free
);
327 if (dce_to_free
== dce
)
335 /***********************************************************************
338 * Free a class or window DCE.
340 void free_dce( struct dce
*dce
, HWND hwnd
)
348 /* turn it into a cache entry */
349 SetHookFlags( dce
->hdc
, DCHF_RESETDC
);
351 dce
->flags
|= DCX_CACHE
;
353 else if (dce
->hwnd
== hwnd
)
359 /* now check for cache DCEs */
363 LIST_FOR_EACH_ENTRY( dce
, &dce_list
, struct dce
, entry
)
365 if (dce
->hwnd
!= hwnd
) continue;
366 if (!(dce
->flags
& DCX_CACHE
)) continue;
368 if (dce
->count
) WARN( "GetDC() without ReleaseDC() for window %p\n", hwnd
);
378 /***********************************************************************
381 * Mark the associated DC as dirty to force a refresh of the visible region
383 static void make_dc_dirty( struct dce
*dce
)
387 /* Don't bother with visible regions of unused DCEs */
388 TRACE("\tpurged %p dce [%p]\n", dce
, dce
->hwnd
);
393 /* Set dirty bits in the hDC and DCE structs */
394 TRACE("\tfixed up %p dce [%p]\n", dce
, dce
->hwnd
);
395 SetHookFlags( dce
->hdc
, DCHF_INVALIDATEVISRGN
);
400 /***********************************************************************
403 * It is called from SetWindowPos() - we have to
404 * mark as dirty all busy DCEs for windows that have pWnd->parent as
405 * an ancestor and whose client rect intersects with specified update
406 * rectangle. In addition, pWnd->parent DCEs may need to be updated if
407 * DCX_CLIPCHILDREN flag is set.
409 void invalidate_dce( WND
*win
, const RECT
*extra_rect
)
414 if (!win
->parent
) return;
416 GetWindowRect( win
->obj
.handle
, &window_rect
);
418 TRACE("%p parent %p %s (%s)\n",
419 win
->obj
.handle
, win
->parent
, wine_dbgstr_rect(&window_rect
), wine_dbgstr_rect(extra_rect
) );
421 /* walk all DCEs and fixup non-empty entries */
423 LIST_FOR_EACH_ENTRY( dce
, &dce_list
, struct dce
, entry
)
425 TRACE( "%p: hwnd %p dcx %08x %s %s\n", dce
, dce
->hwnd
, dce
->flags
,
426 (dce
->flags
& DCX_CACHE
) ? "Cache" : "Owned", dce
->count
? "InUse" : "" );
428 if (!dce
->hwnd
) continue;
429 if ((dce
->hwnd
== win
->parent
) && !(dce
->flags
& DCX_CLIPCHILDREN
))
430 continue; /* child window positions don't bother us */
432 /* if DCE window is a child of hwnd, it has to be invalidated */
433 if (dce
->hwnd
== win
->obj
.handle
|| IsChild( win
->obj
.handle
, dce
->hwnd
))
435 make_dc_dirty( dce
);
439 /* otherwise check if the window rectangle intersects this DCE window */
440 if (win
->parent
== dce
->hwnd
|| IsChild( win
->parent
, dce
->hwnd
))
443 GetWindowRect( dce
->hwnd
, &dce_rect
);
444 if (IntersectRect( &tmp
, &dce_rect
, &window_rect
) ||
445 (extra_rect
&& IntersectRect( &tmp
, &dce_rect
, extra_rect
)))
446 make_dc_dirty( dce
);
451 /***********************************************************************
454 * Implementation of ReleaseDC.
456 static INT
release_dc( HWND hwnd
, HDC hdc
, BOOL end_paint
)
461 TRACE("%p %p\n", hwnd
, hdc
);
464 dce
= (struct dce
*)GetDCHook( hdc
, NULL
);
465 if (dce
&& dce
->count
)
467 if (!(dce
->flags
& DCX_NORESETATTRS
)) SetHookFlags( dce
->hdc
, DCHF_RESETDC
);
468 if (end_paint
|| (dce
->flags
& DCX_CACHE
)) delete_clip_rgn( dce
);
469 if (dce
->flags
& DCX_CACHE
) dce
->count
= 0;
477 /***********************************************************************
480 * See "Undoc. Windows" for hints (DC, SetDCHook, SetHookFlags)..
482 static BOOL CALLBACK
dc_hook( HDC hDC
, WORD code
, DWORD_PTR data
, LPARAM lParam
)
485 struct dce
*dce
= (struct dce
*)data
;
487 TRACE("hDC = %p, %u\n", hDC
, code
);
490 assert( dce
->hdc
== hDC
);
494 case DCHC_INVALIDVISRGN
:
495 /* GDI code calls this when it detects that the
496 * DC is dirty (usually after SetHookFlags()). This
497 * means that we have to recompute the visible region.
499 if (dce
->count
) update_visible_region( dce
);
500 else /* non-fatal but shouldn't happen */
501 WARN("DC is not in use!\n");
505 * Windows will not let you delete a DC that is busy
506 * (between GetDC and ReleaseDC)
511 WARN("Application trying to delete a busy DC %p\n", dce
->hdc
);
516 list_remove( &dce
->entry
);
517 if (dce
->clip_rgn
) DeleteObject( dce
->clip_rgn
);
518 HeapFree( GetProcessHeap(), 0, dce
);
527 /***********************************************************************
530 * Return update region (in screen coordinates) for a window.
532 static HRGN
get_update_region( HWND hwnd
, UINT
*flags
, HWND
*child
)
541 if (!(data
= HeapAlloc( GetProcessHeap(), 0, sizeof(*data
) + size
- 1 )))
543 SetLastError( ERROR_OUTOFMEMORY
);
547 SERVER_START_REQ( get_update_region
)
549 req
->window
= wine_server_user_handle( hwnd
);
550 req
->from_child
= wine_server_user_handle( child
? *child
: 0 );
552 wine_server_set_reply( req
, data
->Buffer
, size
);
553 if (!(status
= wine_server_call( req
)))
555 size_t reply_size
= wine_server_reply_size( reply
);
556 data
->rdh
.dwSize
= sizeof(data
->rdh
);
557 data
->rdh
.iType
= RDH_RECTANGLES
;
558 data
->rdh
.nCount
= reply_size
/ sizeof(RECT
);
559 data
->rdh
.nRgnSize
= reply_size
;
560 hrgn
= ExtCreateRegion( NULL
, size
, data
);
561 if (child
) *child
= wine_server_ptr_handle( reply
->child
);
562 *flags
= reply
->flags
;
564 else size
= reply
->total_size
;
567 HeapFree( GetProcessHeap(), 0, data
);
568 } while (status
== STATUS_BUFFER_OVERFLOW
);
570 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
575 /***********************************************************************
578 * Get only the update flags, not the update region.
580 static BOOL
get_update_flags( HWND hwnd
, HWND
*child
, UINT
*flags
)
584 SERVER_START_REQ( get_update_region
)
586 req
->window
= wine_server_user_handle( hwnd
);
587 req
->from_child
= wine_server_user_handle( child
? *child
: 0 );
588 req
->flags
= *flags
| UPDATE_NOREGION
;
589 if ((ret
= !wine_server_call_err( req
)))
591 if (child
) *child
= wine_server_ptr_handle( reply
->child
);
592 *flags
= reply
->flags
;
600 /***********************************************************************
601 * redraw_window_rects
603 * Redraw part of a window.
605 static BOOL
redraw_window_rects( HWND hwnd
, UINT flags
, const RECT
*rects
, UINT count
)
609 if (!(flags
& (RDW_INVALIDATE
|RDW_VALIDATE
|RDW_INTERNALPAINT
|RDW_NOINTERNALPAINT
)))
610 return TRUE
; /* nothing to do */
612 SERVER_START_REQ( redraw_window
)
614 req
->window
= wine_server_user_handle( hwnd
);
616 wine_server_add_data( req
, rects
, count
* sizeof(RECT
) );
617 ret
= !wine_server_call_err( req
);
624 /***********************************************************************
627 * Send a WM_NCPAINT message if needed, and return the resulting update region (in screen coords).
628 * Helper for erase_now and BeginPaint.
630 static HRGN
send_ncpaint( HWND hwnd
, HWND
*child
, UINT
*flags
)
632 HRGN whole_rgn
= get_update_region( hwnd
, flags
, child
);
635 if (child
) hwnd
= *child
;
637 if (hwnd
== GetDesktopWindow()) return whole_rgn
;
644 /* check if update rgn overlaps with nonclient area */
645 type
= GetRgnBox( whole_rgn
, &update
);
646 WIN_GetRectangles( hwnd
, COORDS_SCREEN
, 0, &client
);
648 if ((*flags
& UPDATE_NONCLIENT
) ||
649 update
.left
< client
.left
|| update
.top
< client
.top
||
650 update
.right
> client
.right
|| update
.bottom
> client
.bottom
)
652 client_rgn
= CreateRectRgnIndirect( &client
);
653 CombineRgn( client_rgn
, client_rgn
, whole_rgn
, RGN_AND
);
655 /* check if update rgn contains complete nonclient area */
656 if (type
== SIMPLEREGION
)
659 GetWindowRect( hwnd
, &window
);
660 if (EqualRect( &window
, &update
))
662 DeleteObject( whole_rgn
);
669 client_rgn
= whole_rgn
;
673 if (whole_rgn
) /* NOTE: WM_NCPAINT allows wParam to be 1 */
675 if (*flags
& UPDATE_NONCLIENT
) SendMessageW( hwnd
, WM_NCPAINT
, (WPARAM
)whole_rgn
, 0 );
676 if (whole_rgn
> (HRGN
)1) DeleteObject( whole_rgn
);
683 /***********************************************************************
686 * Send a WM_ERASEBKGND message if needed, and optionally return the DC for painting.
687 * If a DC is requested, the region is selected into it. In all cases the region is deleted.
688 * Helper for erase_now and BeginPaint.
690 static BOOL
send_erase( HWND hwnd
, UINT flags
, HRGN client_rgn
,
691 RECT
*clip_rect
, HDC
*hdc_ret
)
693 BOOL need_erase
= (flags
& UPDATE_DELAYED_ERASE
) != 0;
697 if (!clip_rect
) clip_rect
= &dummy
;
698 if (hdc_ret
|| (flags
& UPDATE_ERASE
))
700 UINT dcx_flags
= DCX_INTERSECTRGN
| DCX_USESTYLE
;
701 if (IsIconic(hwnd
)) dcx_flags
|= DCX_WINDOW
;
703 if ((hdc
= GetDCEx( hwnd
, client_rgn
, dcx_flags
)))
705 INT type
= GetClipBox( hdc
, clip_rect
);
707 if (flags
& UPDATE_ERASE
)
709 /* don't erase if the clip box is empty */
710 if (type
!= NULLREGION
)
711 need_erase
= !SendMessageW( hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0 );
713 if (!hdc_ret
) release_dc( hwnd
, hdc
, TRUE
);
716 if (hdc_ret
) *hdc_ret
= hdc
;
718 if (!hdc
) DeleteObject( client_rgn
);
723 /***********************************************************************
726 * Implementation of RDW_ERASENOW behavior.
728 void erase_now( HWND hwnd
, UINT rdw_flags
)
732 BOOL need_erase
= FALSE
;
734 /* loop while we find a child to repaint */
737 UINT flags
= UPDATE_NONCLIENT
| UPDATE_ERASE
;
739 if (rdw_flags
& RDW_NOCHILDREN
) flags
|= UPDATE_NOCHILDREN
;
740 else if (rdw_flags
& RDW_ALLCHILDREN
) flags
|= UPDATE_ALLCHILDREN
;
741 if (need_erase
) flags
|= UPDATE_DELAYED_ERASE
;
743 if (!(hrgn
= send_ncpaint( hwnd
, &child
, &flags
))) break;
744 need_erase
= send_erase( child
, flags
, hrgn
, NULL
, NULL
);
746 if (!flags
) break; /* nothing more to do */
747 if ((rdw_flags
& RDW_NOCHILDREN
) && !need_erase
) break;
752 /***********************************************************************
755 * Move the window bits when a window is resized or its surface recreated.
757 void move_window_bits( HWND hwnd
, struct window_surface
*old_surface
,
758 struct window_surface
*new_surface
,
759 const RECT
*visible_rect
, const RECT
*old_visible_rect
,
760 const RECT
*client_rect
, const RECT
*valid_rects
)
762 RECT dst
= valid_rects
[0];
763 RECT src
= valid_rects
[1];
765 if (new_surface
!= old_surface
||
766 src
.left
- old_visible_rect
->left
!= dst
.left
- visible_rect
->left
||
767 src
.top
- old_visible_rect
->top
!= dst
.top
- visible_rect
->top
)
769 char buffer
[FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )];
770 BITMAPINFO
*info
= (BITMAPINFO
*)buffer
;
772 UINT flags
= UPDATE_NOCHILDREN
;
773 HRGN rgn
= get_update_region( hwnd
, &flags
, NULL
);
774 HDC hdc
= GetDCEx( hwnd
, rgn
, DCX_CACHE
| DCX_EXCLUDERGN
);
776 OffsetRect( &dst
, -client_rect
->left
, -client_rect
->top
);
777 TRACE( "copying %s -> %s\n", wine_dbgstr_rect(&src
), wine_dbgstr_rect(&dst
) );
778 bits
= old_surface
->funcs
->get_info( old_surface
, info
);
779 old_surface
->funcs
->lock( old_surface
);
780 SetDIBitsToDevice( hdc
, dst
.left
, dst
.top
, dst
.right
- dst
.left
, dst
.bottom
- dst
.top
,
781 src
.left
- old_visible_rect
->left
- old_surface
->rect
.left
,
782 old_surface
->rect
.bottom
- (src
.bottom
- old_visible_rect
->top
),
783 0, old_surface
->rect
.bottom
- old_surface
->rect
.top
,
784 bits
, info
, DIB_RGB_COLORS
);
785 old_surface
->funcs
->unlock( old_surface
);
786 ReleaseDC( hwnd
, hdc
);
791 /***********************************************************************
794 * Implementation of RDW_UPDATENOW behavior.
796 static void update_now( HWND hwnd
, UINT rdw_flags
)
800 /* desktop window never gets WM_PAINT, only WM_ERASEBKGND */
801 if (hwnd
== GetDesktopWindow()) erase_now( hwnd
, rdw_flags
| RDW_NOCHILDREN
);
803 /* loop while we find a child to repaint */
806 UINT flags
= UPDATE_PAINT
| UPDATE_INTERNALPAINT
;
808 if (rdw_flags
& RDW_NOCHILDREN
) flags
|= UPDATE_NOCHILDREN
;
809 else if (rdw_flags
& RDW_ALLCHILDREN
) flags
|= UPDATE_ALLCHILDREN
;
811 if (!get_update_flags( hwnd
, &child
, &flags
)) break;
812 if (!flags
) break; /* nothing more to do */
814 SendMessageW( child
, WM_PAINT
, 0, 0 );
815 if (rdw_flags
& RDW_NOCHILDREN
) break;
820 /*************************************************************************
823 * Helper for ScrollWindowEx:
824 * If the return value is 0, no special caret handling is necessary.
825 * Otherwise the return value is the handle of the window that owns the
826 * caret. Its caret needs to be hidden during the scroll operation and
827 * moved to new_caret_pos if move_caret is TRUE.
829 static HWND
fix_caret(HWND hWnd
, const RECT
*scroll_rect
, INT dx
, INT dy
,
830 UINT flags
, LPBOOL move_caret
, LPPOINT new_caret_pos
)
833 RECT rect
, mapped_rcCaret
;
834 BOOL hide_caret
= FALSE
;
836 info
.cbSize
= sizeof(info
);
837 if (!GetGUIThreadInfo( GetCurrentThreadId(), &info
)) return 0;
838 if (!info
.hwndCaret
) return 0;
840 if (info
.hwndCaret
== hWnd
)
842 /* Move the caret if it's (partially) in the source rectangle */
843 if (IntersectRect(&rect
, scroll_rect
, &info
.rcCaret
))
847 new_caret_pos
->x
= info
.rcCaret
.left
+ dx
;
848 new_caret_pos
->y
= info
.rcCaret
.top
+ dy
;
854 /* Hide the caret if it's in the destination rectangle */
856 OffsetRect(&rect
, dx
, dy
);
857 hide_caret
= IntersectRect(&rect
, &rect
, &info
.rcCaret
);
862 if ((flags
& SW_SCROLLCHILDREN
) && IsChild(hWnd
, info
.hwndCaret
))
866 /* Hide the caret if it's in the source or in the destination
868 mapped_rcCaret
= info
.rcCaret
;
869 MapWindowPoints(info
.hwndCaret
, hWnd
, (LPPOINT
)&mapped_rcCaret
, 2);
871 if (IntersectRect(&rect
, scroll_rect
, &mapped_rcCaret
))
878 OffsetRect(&rect
, dx
, dy
);
879 hide_caret
= IntersectRect(&rect
, &rect
, &mapped_rcCaret
);
888 HideCaret(info
.hwndCaret
);
889 return info
.hwndCaret
;
896 /***********************************************************************
897 * BeginPaint (USER32.@)
899 HDC WINAPI
BeginPaint( HWND hwnd
, PAINTSTRUCT
*lps
)
905 UINT flags
= UPDATE_NONCLIENT
| UPDATE_ERASE
| UPDATE_PAINT
| UPDATE_INTERNALPAINT
| UPDATE_NOCHILDREN
;
909 if (!(hrgn
= send_ncpaint( hwnd
, NULL
, &flags
))) return 0;
911 erase
= send_erase( hwnd
, flags
, hrgn
, &rect
, &hdc
);
913 TRACE("hdc = %p box = (%s), fErase = %d\n", hdc
, wine_dbgstr_rect(&rect
), erase
);
917 release_dc( hwnd
, hdc
, TRUE
);
927 /***********************************************************************
928 * EndPaint (USER32.@)
930 BOOL WINAPI
EndPaint( HWND hwnd
, const PAINTSTRUCT
*lps
)
933 flush_window_surfaces( FALSE
);
934 if (!lps
) return FALSE
;
935 release_dc( hwnd
, lps
->hdc
, TRUE
);
940 /***********************************************************************
943 HDC WINAPI
GetDCEx( HWND hwnd
, HRGN hrgnClip
, DWORD flags
)
945 const DWORD clip_flags
= DCX_PARENTCLIP
| DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
| DCX_WINDOW
;
946 const DWORD user_flags
= clip_flags
| DCX_NORESETATTRS
; /* flags that can be set by user */
948 BOOL bUpdateVisRgn
= TRUE
;
950 LONG window_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
952 if (!hwnd
) hwnd
= GetDesktopWindow();
953 else hwnd
= WIN_GetFullHandle( hwnd
);
955 TRACE("hwnd %p, hrgnClip %p, flags %08x\n", hwnd
, hrgnClip
, flags
);
957 if (!IsWindow(hwnd
)) return 0;
961 if (flags
& (DCX_WINDOW
| DCX_PARENTCLIP
)) flags
|= DCX_CACHE
;
963 if (flags
& DCX_USESTYLE
)
965 flags
&= ~(DCX_CLIPCHILDREN
| DCX_CLIPSIBLINGS
| DCX_PARENTCLIP
);
967 if (window_style
& WS_CLIPSIBLINGS
) flags
|= DCX_CLIPSIBLINGS
;
969 if (!(flags
& DCX_WINDOW
))
971 if (GetClassLongW( hwnd
, GCL_STYLE
) & CS_PARENTDC
) flags
|= DCX_PARENTCLIP
;
973 if (window_style
& WS_CLIPCHILDREN
&& !(window_style
& WS_MINIMIZE
))
974 flags
|= DCX_CLIPCHILDREN
;
978 if (flags
& DCX_WINDOW
) flags
&= ~DCX_CLIPCHILDREN
;
980 parent
= GetAncestor( hwnd
, GA_PARENT
);
981 if (!parent
|| (parent
== GetDesktopWindow()))
982 flags
= (flags
& ~DCX_PARENTCLIP
) | DCX_CLIPSIBLINGS
;
984 /* it seems parent clip is ignored when clipping siblings or children */
985 if (flags
& (DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
)) flags
&= ~DCX_PARENTCLIP
;
987 if( flags
& DCX_PARENTCLIP
)
989 LONG parent_style
= GetWindowLongW( parent
, GWL_STYLE
);
990 if( (window_style
& WS_VISIBLE
) && (parent_style
& WS_VISIBLE
) )
992 flags
&= ~DCX_CLIPCHILDREN
;
993 if (parent_style
& WS_CLIPSIBLINGS
) flags
|= DCX_CLIPSIBLINGS
;
997 /* find a suitable DCE */
999 if ((flags
& DCX_CACHE
) || !(dce
= get_window_dce( hwnd
)))
1001 struct dce
*dceEmpty
= NULL
, *dceUnused
= NULL
;
1003 /* Strategy: First, we attempt to find a non-empty but unused DCE with
1004 * compatible flags. Next, we look for an empty entry. If the cache is
1005 * full we have to purge one of the unused entries.
1008 LIST_FOR_EACH_ENTRY( dce
, &dce_list
, struct dce
, entry
)
1010 if ((dce
->flags
& DCX_CACHE
) && !dce
->count
)
1014 if (!dce
->hwnd
) dceEmpty
= dce
;
1015 else if ((dce
->hwnd
== hwnd
) && !((dce
->flags
^ flags
) & clip_flags
))
1017 TRACE("\tfound valid %p dce [%p], flags %08x\n",
1018 dce
, hwnd
, dce
->flags
);
1019 bUpdateVisRgn
= FALSE
;
1025 if (&dce
->entry
== &dce_list
) /* nothing found */
1026 dce
= dceEmpty
? dceEmpty
: dceUnused
;
1028 if (dce
) dce
->count
= 1;
1032 /* if there's no dce empty or unused, allocate a new one */
1035 if (!(dce
= alloc_dce())) return 0;
1036 dce
->flags
= DCX_CACHE
;
1038 list_add_head( &dce_list
, &dce
->entry
);
1044 flags
|= DCX_NORESETATTRS
;
1045 if (dce
->hwnd
== hwnd
)
1047 TRACE("\tskipping hVisRgn update\n");
1048 bUpdateVisRgn
= FALSE
; /* updated automatically, via DCHook() */
1052 /* we should free dce->clip_rgn here, but Windows apparently doesn't */
1053 dce
->flags
&= ~(DCX_EXCLUDERGN
| DCX_INTERSECTRGN
);
1058 if (flags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
))
1060 /* if the extra clip region has changed, get rid of the old one */
1061 if (dce
->clip_rgn
!= hrgnClip
|| ((flags
^ dce
->flags
) & (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
)))
1062 delete_clip_rgn( dce
);
1063 dce
->clip_rgn
= hrgnClip
;
1064 if (!dce
->clip_rgn
) dce
->clip_rgn
= CreateRectRgn( 0, 0, 0, 0 );
1065 dce
->flags
|= flags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
);
1066 bUpdateVisRgn
= TRUE
;
1069 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_LAYOUTRTL
) SetLayout( dce
->hdc
, LAYOUT_RTL
);
1072 dce
->flags
= (dce
->flags
& ~user_flags
) | (flags
& user_flags
);
1074 if (SetHookFlags( dce
->hdc
, DCHF_VALIDATEVISRGN
)) bUpdateVisRgn
= TRUE
; /* DC was dirty */
1076 if (bUpdateVisRgn
) update_visible_region( dce
);
1078 TRACE("(%p,%p,0x%x): returning %p\n", hwnd
, hrgnClip
, flags
, dce
->hdc
);
1083 /***********************************************************************
1086 * Get a device context.
1089 * Success: Handle to the device context
1092 HDC WINAPI
GetDC( HWND hwnd
)
1094 if (!hwnd
) return GetDCEx( 0, 0, DCX_CACHE
| DCX_WINDOW
);
1095 return GetDCEx( hwnd
, 0, DCX_USESTYLE
);
1099 /***********************************************************************
1100 * GetWindowDC (USER32.@)
1102 HDC WINAPI
GetWindowDC( HWND hwnd
)
1104 return GetDCEx( hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
1108 /***********************************************************************
1109 * ReleaseDC (USER32.@)
1111 * Release a device context.
1114 * Success: Non-zero. Resources used by hdc are released.
1117 INT WINAPI
ReleaseDC( HWND hwnd
, HDC hdc
)
1119 return release_dc( hwnd
, hdc
, FALSE
);
1123 /**********************************************************************
1124 * WindowFromDC (USER32.@)
1126 HWND WINAPI
WindowFromDC( HDC hdc
)
1132 dce
= (struct dce
*)GetDCHook( hdc
, NULL
);
1133 if (dce
) hwnd
= dce
->hwnd
;
1139 /***********************************************************************
1140 * LockWindowUpdate (USER32.@)
1142 * Enables or disables painting in the chosen window.
1145 * hwnd [I] handle to a window.
1148 * If successful, returns nonzero value. Otherwise,
1152 * You can lock only one window at a time.
1154 BOOL WINAPI
LockWindowUpdate( HWND hwnd
)
1156 static HWND lockedWnd
;
1158 FIXME("(%p), partial stub!\n",hwnd
);
1165 /* Unlock lockedWnd */
1166 /* FIXME: Do something */
1170 /* Attempted to lock a second window */
1171 /* Return FALSE and do nothing */
1182 /***********************************************************************
1183 * RedrawWindow (USER32.@)
1185 BOOL WINAPI
RedrawWindow( HWND hwnd
, const RECT
*rect
, HRGN hrgn
, UINT flags
)
1187 static const RECT empty
;
1190 if (!hwnd
) hwnd
= GetDesktopWindow();
1197 GetRgnBox( hrgn
, &r
);
1198 TRACE( "%p region %p box %s ", hwnd
, hrgn
, wine_dbgstr_rect(&r
) );
1201 TRACE( "%p rect %s ", hwnd
, wine_dbgstr_rect(rect
) );
1203 TRACE( "%p whole window ", hwnd
);
1205 dump_rdw_flags(flags
);
1208 /* process pending expose events before painting */
1209 if (flags
& RDW_UPDATENOW
) USER_Driver
->pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, QS_PAINT
, 0 );
1213 if (IsRectEmpty( rect
)) rect
= &empty
;
1214 ret
= redraw_window_rects( hwnd
, flags
, rect
, 1 );
1218 ret
= redraw_window_rects( hwnd
, flags
, NULL
, 0 );
1220 else /* need to build a list of the region rectangles */
1223 RGNDATA
*data
= NULL
;
1225 if (!(size
= GetRegionData( hrgn
, 0, NULL
))) return FALSE
;
1226 if (!(data
= HeapAlloc( GetProcessHeap(), 0, size
))) return FALSE
;
1227 GetRegionData( hrgn
, size
, data
);
1228 if (!data
->rdh
.nCount
) /* empty region -> use a single all-zero rectangle */
1229 ret
= redraw_window_rects( hwnd
, flags
, &empty
, 1 );
1231 ret
= redraw_window_rects( hwnd
, flags
, (const RECT
*)data
->Buffer
, data
->rdh
.nCount
);
1232 HeapFree( GetProcessHeap(), 0, data
);
1235 if (flags
& RDW_UPDATENOW
) update_now( hwnd
, flags
);
1236 else if (flags
& RDW_ERASENOW
) erase_now( hwnd
, flags
);
1242 /***********************************************************************
1243 * UpdateWindow (USER32.@)
1245 BOOL WINAPI
UpdateWindow( HWND hwnd
)
1249 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1253 return RedrawWindow( hwnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
1257 /***********************************************************************
1258 * InvalidateRgn (USER32.@)
1260 BOOL WINAPI
InvalidateRgn( HWND hwnd
, HRGN hrgn
, BOOL erase
)
1264 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1268 return RedrawWindow(hwnd
, NULL
, hrgn
, RDW_INVALIDATE
| (erase
? RDW_ERASE
: 0) );
1272 /***********************************************************************
1273 * InvalidateRect (USER32.@)
1275 * MSDN: if hwnd parameter is NULL, InvalidateRect invalidates and redraws
1276 * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
1278 BOOL WINAPI
InvalidateRect( HWND hwnd
, const RECT
*rect
, BOOL erase
)
1280 UINT flags
= RDW_INVALIDATE
| (erase
? RDW_ERASE
: 0);
1284 flags
= RDW_ALLCHILDREN
| RDW_INVALIDATE
| RDW_FRAME
| RDW_ERASE
| RDW_ERASENOW
;
1288 return RedrawWindow( hwnd
, rect
, 0, flags
);
1292 /***********************************************************************
1293 * ValidateRgn (USER32.@)
1295 BOOL WINAPI
ValidateRgn( HWND hwnd
, HRGN hrgn
)
1299 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1303 return RedrawWindow( hwnd
, NULL
, hrgn
, RDW_VALIDATE
);
1307 /***********************************************************************
1308 * ValidateRect (USER32.@)
1310 * MSDN: if hwnd parameter is NULL, ValidateRect invalidates and redraws
1311 * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
1313 BOOL WINAPI
ValidateRect( HWND hwnd
, const RECT
*rect
)
1315 UINT flags
= RDW_VALIDATE
;
1319 flags
= RDW_ALLCHILDREN
| RDW_INVALIDATE
| RDW_FRAME
| RDW_ERASE
| RDW_ERASENOW
;
1323 return RedrawWindow( hwnd
, rect
, 0, flags
);
1327 /***********************************************************************
1328 * GetUpdateRgn (USER32.@)
1330 INT WINAPI
GetUpdateRgn( HWND hwnd
, HRGN hrgn
, BOOL erase
)
1333 UINT flags
= UPDATE_NOCHILDREN
;
1336 if (erase
) flags
|= UPDATE_NONCLIENT
| UPDATE_ERASE
;
1338 if ((update_rgn
= send_ncpaint( hwnd
, NULL
, &flags
)))
1340 retval
= CombineRgn( hrgn
, update_rgn
, 0, RGN_COPY
);
1341 if (send_erase( hwnd
, flags
, update_rgn
, NULL
, NULL
))
1343 flags
= UPDATE_DELAYED_ERASE
;
1344 get_update_flags( hwnd
, NULL
, &flags
);
1346 /* map region to client coordinates */
1347 map_window_region( 0, hwnd
, hrgn
);
1353 /***********************************************************************
1354 * GetUpdateRect (USER32.@)
1356 BOOL WINAPI
GetUpdateRect( HWND hwnd
, LPRECT rect
, BOOL erase
)
1358 UINT flags
= UPDATE_NOCHILDREN
;
1362 if (erase
) flags
|= UPDATE_NONCLIENT
| UPDATE_ERASE
;
1364 if (!(update_rgn
= send_ncpaint( hwnd
, NULL
, &flags
))) return FALSE
;
1368 if (GetRgnBox( update_rgn
, rect
) != NULLREGION
)
1370 HDC hdc
= GetDCEx( hwnd
, 0, DCX_USESTYLE
);
1371 DWORD layout
= SetLayout( hdc
, 0 ); /* MapWindowPoints mirrors already */
1372 MapWindowPoints( 0, hwnd
, (LPPOINT
)rect
, 2 );
1373 DPtoLP( hdc
, (LPPOINT
)rect
, 2 );
1374 SetLayout( hdc
, layout
);
1375 ReleaseDC( hwnd
, hdc
);
1378 need_erase
= send_erase( hwnd
, flags
, update_rgn
, NULL
, NULL
);
1380 /* check if we still have an update region */
1381 flags
= UPDATE_PAINT
| UPDATE_NOCHILDREN
;
1382 if (need_erase
) flags
|= UPDATE_DELAYED_ERASE
;
1383 return (get_update_flags( hwnd
, NULL
, &flags
) && (flags
& UPDATE_PAINT
));
1387 /***********************************************************************
1388 * ExcludeUpdateRgn (USER32.@)
1390 INT WINAPI
ExcludeUpdateRgn( HDC hdc
, HWND hwnd
)
1392 HRGN update_rgn
= CreateRectRgn( 0, 0, 0, 0 );
1393 INT ret
= GetUpdateRgn( hwnd
, update_rgn
, FALSE
);
1399 GetDCOrgEx( hdc
, &pt
);
1400 MapWindowPoints( 0, hwnd
, &pt
, 1 );
1401 OffsetRgn( update_rgn
, -pt
.x
, -pt
.y
);
1402 ret
= ExtSelectClipRgn( hdc
, update_rgn
, RGN_DIFF
);
1403 DeleteObject( update_rgn
);
1409 static INT
scroll_window( HWND hwnd
, INT dx
, INT dy
, const RECT
*rect
, const RECT
*clipRect
,
1410 HRGN hrgnUpdate
, LPRECT rcUpdate
, UINT flags
, BOOL is_ex
)
1412 INT retVal
= NULLREGION
;
1413 BOOL bOwnRgn
= TRUE
;
1414 BOOL bUpdate
= (rcUpdate
|| hrgnUpdate
|| flags
& (SW_INVALIDATE
| SW_ERASE
));
1417 HRGN hrgnWinupd
= 0;
1420 HWND hwndCaret
= NULL
;
1421 BOOL moveCaret
= FALSE
;
1424 TRACE( "%p, %d,%d hrgnUpdate=%p rcUpdate = %p %s %04x\n",
1425 hwnd
, dx
, dy
, hrgnUpdate
, rcUpdate
, wine_dbgstr_rect(rect
), flags
);
1426 TRACE( "clipRect = %s\n", wine_dbgstr_rect(clipRect
));
1427 if( flags
& ~( SW_SCROLLCHILDREN
| SW_INVALIDATE
| SW_ERASE
))
1428 FIXME("some flags (%04x) are unhandled\n", flags
);
1430 rdw_flags
= (flags
& SW_ERASE
) && (flags
& SW_INVALIDATE
) ?
1431 RDW_INVALIDATE
| RDW_ERASE
: RDW_INVALIDATE
;
1433 if (!WIN_IsWindowDrawable( hwnd
, TRUE
)) return ERROR
;
1434 hwnd
= WIN_GetFullHandle( hwnd
);
1436 GetClientRect(hwnd
, &rc
);
1438 if (clipRect
) IntersectRect(&cliprc
,&rc
,clipRect
);
1441 if (rect
) IntersectRect(&rc
, &rc
, rect
);
1443 if( hrgnUpdate
) bOwnRgn
= FALSE
;
1444 else if( bUpdate
) hrgnUpdate
= CreateRectRgn( 0, 0, 0, 0 );
1446 newCaretPos
.x
= newCaretPos
.y
= 0;
1448 if( !IsRectEmpty(&cliprc
) && (dx
|| dy
)) {
1450 DWORD style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1452 hwndCaret
= fix_caret(hwnd
, &rc
, dx
, dy
, flags
, &moveCaret
, &newCaretPos
);
1454 if (is_ex
) dcxflags
|= DCX_CACHE
;
1455 if( style
& WS_CLIPSIBLINGS
) dcxflags
|= DCX_CLIPSIBLINGS
;
1456 if( GetClassLongW( hwnd
, GCL_STYLE
) & CS_PARENTDC
)
1457 dcxflags
|= DCX_PARENTCLIP
;
1458 if( !(flags
& SW_SCROLLCHILDREN
) && (style
& WS_CLIPCHILDREN
))
1459 dcxflags
|= DCX_CLIPCHILDREN
;
1460 hDC
= GetDCEx( hwnd
, 0, dcxflags
);
1463 ScrollDC( hDC
, dx
, dy
, &rc
, &cliprc
, hrgnUpdate
, rcUpdate
);
1465 ReleaseDC( hwnd
, hDC
);
1468 RedrawWindow( hwnd
, NULL
, hrgnUpdate
, rdw_flags
);
1471 /* If the windows has an update region, this must be
1472 * scrolled as well. Keep a copy in hrgnWinupd
1473 * to be added to hrngUpdate at the end. */
1474 hrgnTemp
= CreateRectRgn( 0, 0, 0, 0 );
1475 retVal
= GetUpdateRgn( hwnd
, hrgnTemp
, FALSE
);
1476 if (retVal
!= NULLREGION
)
1478 HRGN hrgnClip
= CreateRectRgnIndirect(&cliprc
);
1480 hrgnWinupd
= CreateRectRgn( 0, 0, 0, 0);
1481 CombineRgn( hrgnWinupd
, hrgnTemp
, 0, RGN_COPY
);
1483 OffsetRgn( hrgnTemp
, dx
, dy
);
1484 CombineRgn( hrgnTemp
, hrgnTemp
, hrgnClip
, RGN_AND
);
1486 CombineRgn( hrgnWinupd
, hrgnWinupd
, hrgnTemp
, RGN_OR
);
1487 RedrawWindow( hwnd
, NULL
, hrgnTemp
, rdw_flags
);
1489 /* Catch the case where the scrolling amount exceeds the size of the
1490 * original window. This generated a second update area that is the
1491 * location where the original scrolled content would end up.
1492 * This second region is not returned by the ScrollDC and sets
1493 * ScrollWindowEx apart from just a ScrollDC.
1495 * This has been verified with testing on windows.
1497 if (abs(dx
) > abs(rc
.right
- rc
.left
) ||
1498 abs(dy
) > abs(rc
.bottom
- rc
.top
))
1500 SetRectRgn( hrgnTemp
, rc
.left
+ dx
, rc
.top
+ dy
, rc
.right
+dx
, rc
.bottom
+ dy
);
1501 CombineRgn( hrgnTemp
, hrgnTemp
, hrgnClip
, RGN_AND
);
1502 CombineRgn( hrgnUpdate
, hrgnUpdate
, hrgnTemp
, RGN_OR
);
1505 CombineRgn( hrgnWinupd
, hrgnWinupd
, hrgnTemp
, RGN_OR
);
1507 DeleteObject( hrgnClip
);
1509 DeleteObject( hrgnTemp
);
1511 /* nothing was scrolled */
1513 SetRectRgn( hrgnUpdate
, 0, 0, 0, 0 );
1514 SetRectEmpty( rcUpdate
);
1517 if( flags
& SW_SCROLLCHILDREN
)
1519 HWND
*list
= WIN_ListChildren( hwnd
);
1524 for (i
= 0; list
[i
]; i
++)
1526 WIN_GetRectangles( list
[i
], COORDS_PARENT
, &r
, NULL
);
1527 if (!rect
|| IntersectRect(&dummy
, &r
, rect
))
1528 SetWindowPos( list
[i
], 0, r
.left
+ dx
, r
.top
+ dy
, 0, 0,
1529 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
|
1530 SWP_NOREDRAW
| SWP_DEFERERASE
);
1532 HeapFree( GetProcessHeap(), 0, list
);
1536 if( flags
& (SW_INVALIDATE
| SW_ERASE
) )
1537 RedrawWindow( hwnd
, NULL
, hrgnUpdate
, rdw_flags
|
1538 ((flags
& SW_SCROLLCHILDREN
) ? RDW_ALLCHILDREN
: 0 ) );
1541 CombineRgn( hrgnUpdate
, hrgnUpdate
, hrgnWinupd
, RGN_OR
);
1542 DeleteObject( hrgnWinupd
);
1546 if ( moveCaret
) SetCaretPos( newCaretPos
.x
, newCaretPos
.y
);
1547 ShowCaret(hwndCaret
);
1550 if( bOwnRgn
&& hrgnUpdate
) DeleteObject( hrgnUpdate
);
1556 /*************************************************************************
1557 * ScrollWindowEx (USER32.@)
1559 * Note: contrary to what the doc says, pixels that are scrolled from the
1560 * outside of clipRect to the inside are NOT painted.
1563 INT WINAPI
ScrollWindowEx( HWND hwnd
, INT dx
, INT dy
,
1564 const RECT
*rect
, const RECT
*clipRect
,
1565 HRGN hrgnUpdate
, LPRECT rcUpdate
,
1568 return scroll_window( hwnd
, dx
, dy
, rect
, clipRect
, hrgnUpdate
, rcUpdate
, flags
, TRUE
);
1571 /*************************************************************************
1572 * ScrollWindow (USER32.@)
1575 BOOL WINAPI
ScrollWindow( HWND hwnd
, INT dx
, INT dy
,
1576 const RECT
*rect
, const RECT
*clipRect
)
1578 return scroll_window( hwnd
, dx
, dy
, rect
, clipRect
, 0, NULL
,
1579 SW_INVALIDATE
| SW_ERASE
| (rect
? 0 : SW_SCROLLCHILDREN
), FALSE
) != ERROR
;
1583 /*************************************************************************
1584 * ScrollDC (USER32.@)
1586 * dx, dy, lprcScroll and lprcClip are all in logical coordinates (msdn is
1587 * wrong) hrgnUpdate is returned in device coordinates with rcUpdate in
1588 * logical coordinates.
1590 BOOL WINAPI
ScrollDC( HDC hdc
, INT dx
, INT dy
, const RECT
*scroll
, const RECT
*clip
,
1591 HRGN ret_update_rgn
, LPRECT update_rect
)
1594 HRGN update_rgn
= ret_update_rgn
;
1595 RECT src_rect
, clip_rect
, offset
;
1597 HRGN dstrgn
, cliprgn
, visrgn
;
1600 TRACE( "dx,dy %d,%d scroll %s clip %s update %p rect %p\n",
1601 dx
, dy
, wine_dbgstr_rect(scroll
), wine_dbgstr_rect(clip
), ret_update_rgn
, update_rect
);
1603 /* get the visible region */
1604 visrgn
= CreateRectRgn( 0, 0, 0, 0 );
1605 GetRandomRgn( hdc
, visrgn
, SYSRGN
);
1606 if (!(GetVersion() & 0x80000000))
1609 GetDCOrgEx( hdc
, &org
);
1610 OffsetRgn( visrgn
, -org
.x
, -org
.y
);
1613 /* intersect with the clipping region if the DC has one */
1614 cliprgn
= CreateRectRgn( 0, 0, 0, 0);
1615 if (GetClipRgn( hdc
, cliprgn
) != 1)
1617 DeleteObject( cliprgn
);
1620 else CombineRgn( visrgn
, visrgn
, cliprgn
, RGN_AND
);
1622 /* only those pixels in the scroll rectangle that remain in the clipping
1623 * rect are scrolled. */
1627 GetClipBox( hdc
, &clip_rect
);
1628 src_rect
= clip_rect
;
1629 OffsetRect( &clip_rect
, -dx
, -dy
);
1630 IntersectRect( &src_rect
, &src_rect
, &clip_rect
);
1632 /* if an scroll rectangle is specified, only the pixels within that
1633 * rectangle are scrolled */
1634 if (scroll
) IntersectRect( &src_rect
, &src_rect
, scroll
);
1636 /* now convert to device coordinates */
1637 LPtoDP( hdc
, (LPPOINT
)&src_rect
, 2 );
1638 TRACE( "source rect: %s\n", wine_dbgstr_rect(&src_rect
) );
1639 /* also dx and dy */
1640 SetRect( &offset
, 0, 0, dx
, dy
);
1641 LPtoDP( hdc
, (LPPOINT
)&offset
, 2 );
1642 dxdev
= offset
.right
- offset
.left
;
1643 dydev
= offset
.bottom
- offset
.top
;
1645 /* now intersect with the visible region to get the pixels that will actually scroll */
1646 dstrgn
= CreateRectRgnIndirect( &src_rect
);
1647 CombineRgn( dstrgn
, dstrgn
, visrgn
, RGN_AND
);
1648 OffsetRgn( dstrgn
, dxdev
, dydev
);
1649 ExtSelectClipRgn( hdc
, dstrgn
, RGN_AND
);
1651 /* compute the update areas. This is the combined clip rectangle
1652 * minus the scrolled region, and intersected with the visible region. */
1653 if (ret_update_rgn
|| update_rect
)
1655 /* intersect clip and scroll rectangles, allowing NULL values */
1659 IntersectRect( &clip_rect
, clip
, scroll
);
1661 clip_rect
= *scroll
;
1666 GetClipBox( hdc
, &clip_rect
);
1668 /* Convert the combined clip rectangle to device coordinates */
1669 LPtoDP( hdc
, (LPPOINT
)&clip_rect
, 2 );
1671 SetRectRgn( update_rgn
, clip_rect
.left
, clip_rect
.top
, clip_rect
.right
, clip_rect
.bottom
);
1673 update_rgn
= CreateRectRgnIndirect( &clip_rect
);
1675 CombineRgn( update_rgn
, update_rgn
, visrgn
, RGN_AND
);
1676 CombineRgn( update_rgn
, update_rgn
, dstrgn
, RGN_DIFF
);
1679 ret
= USER_Driver
->pScrollDC( hdc
, dx
, dy
, update_rgn
);
1681 if (ret
&& update_rect
)
1683 GetRgnBox( update_rgn
, update_rect
);
1684 DPtoLP( hdc
, (LPPOINT
)update_rect
, 2 );
1685 TRACE( "returning update_rect %s\n", wine_dbgstr_rect(update_rect
) );
1687 if (!ret_update_rgn
) DeleteObject( update_rgn
);
1688 SelectClipRgn( hdc
, cliprgn
);
1689 if (cliprgn
) DeleteObject( cliprgn
);
1690 DeleteObject( visrgn
);
1691 DeleteObject( dstrgn
);
1695 /************************************************************************
1696 * PrintWindow (USER32.@)
1699 BOOL WINAPI
PrintWindow(HWND hwnd
, HDC hdcBlt
, UINT nFlags
)
1701 UINT flags
= PRF_CHILDREN
| PRF_ERASEBKGND
| PRF_OWNED
| PRF_CLIENT
;
1702 if(!(nFlags
& PW_CLIENTONLY
))
1704 flags
|= PRF_NONCLIENT
;
1706 SendMessageW(hwnd
, WM_PRINT
, (WPARAM
)hdcBlt
, flags
);