2 * Scroll windows and DCs
4 * Copyright David W. Metcalfe, 1993
5 * Alex Korobka 1995,1996
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "wine/winuser16.h"
30 #include "user_private.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(scroll
);
36 /*************************************************************************
39 static HWND
fix_caret(HWND hWnd
, LPRECT lprc
, UINT flags
)
43 if (!GetGUIThreadInfo( GetCurrentThreadId(), &info
)) return 0;
44 if (!info
.hwndCaret
) return 0;
45 if (info
.hwndCaret
== hWnd
||
46 ((flags
& SW_SCROLLCHILDREN
) && IsChild(hWnd
, info
.hwndCaret
)))
49 pt
.x
= info
.rcCaret
.left
;
50 pt
.y
= info
.rcCaret
.top
;
51 MapWindowPoints( info
.hwndCaret
, hWnd
, (LPPOINT
)&info
.rcCaret
, 2 );
52 if( IntersectRect(lprc
, lprc
, &info
.rcCaret
) )
57 return info
.hwndCaret
;
63 /*************************************************************************
64 * ScrollWindowEx (USER32.@)
66 * Note: contrary to what the doc says, pixels that are scrolled from the
67 * outside of clipRect to the inside are NOT painted.
70 INT WINAPI
ScrollWindowEx( HWND hwnd
, INT dx
, INT dy
,
71 const RECT
*rect
, const RECT
*clipRect
,
72 HRGN hrgnUpdate
, LPRECT rcUpdate
,
75 INT retVal
= NULLREGION
;
77 BOOL bUpdate
= (rcUpdate
|| hrgnUpdate
|| flags
& (SW_INVALIDATE
| SW_ERASE
));
84 HWND hwndCaret
= NULL
;
86 TRACE( "%p, %d,%d hrgnUpdate=%p rcUpdate = %p %s %04x\n",
87 hwnd
, dx
, dy
, hrgnUpdate
, rcUpdate
, wine_dbgstr_rect(rect
), flags
);
88 TRACE( "clipRect = %s\n", wine_dbgstr_rect(clipRect
));
89 if( flags
& ~( SW_SCROLLCHILDREN
| SW_INVALIDATE
| SW_ERASE
))
90 FIXME("some flags (%04x) are unhandled\n", flags
);
92 rdw_flags
= (flags
& SW_ERASE
) && (flags
& SW_INVALIDATE
) ?
93 RDW_INVALIDATE
| RDW_ERASE
: RDW_INVALIDATE
;
95 if (!WIN_IsWindowDrawable( hwnd
, TRUE
)) return ERROR
;
96 hwnd
= WIN_GetFullHandle( hwnd
);
98 GetClientRect(hwnd
, &rc
);
99 if (rect
) IntersectRect(&rc
, &rc
, rect
);
101 if (clipRect
) IntersectRect(&cliprc
,&rc
,clipRect
);
104 if( hrgnUpdate
) bOwnRgn
= FALSE
;
105 else if( bUpdate
) hrgnUpdate
= CreateRectRgn( 0, 0, 0, 0 );
107 if( !IsRectEmpty(&cliprc
) && (dx
|| dy
)) {
108 DWORD dcxflags
= DCX_CACHE
;
109 DWORD style
= GetWindowLongW( hwnd
, GWL_STYLE
);
111 hwndCaret
= fix_caret(hwnd
, &caretrc
, flags
);
113 if( style
& WS_CLIPSIBLINGS
) dcxflags
|= DCX_CLIPSIBLINGS
;
114 if( GetClassLongW( hwnd
, GCL_STYLE
) & CS_PARENTDC
)
115 dcxflags
|= DCX_PARENTCLIP
;
116 if( !(flags
& SW_SCROLLCHILDREN
) && (style
& WS_CLIPCHILDREN
))
117 dcxflags
|= DCX_CLIPCHILDREN
;
118 hDC
= GetDCEx( hwnd
, 0, dcxflags
);
121 ScrollDC( hDC
, dx
, dy
, &rc
, &cliprc
, hrgnUpdate
, rcUpdate
);
123 ReleaseDC( hwnd
, hDC
);
126 RedrawWindow( hwnd
, NULL
, hrgnUpdate
, rdw_flags
);
129 /* If the windows has an update region, this must be
130 * scrolled as well. Keep a copy in hrgnWinupd
131 * to be added to hrngUpdate at the end. */
132 hrgnTemp
= CreateRectRgn( 0, 0, 0, 0 );
133 retVal
= GetUpdateRgn( hwnd
, hrgnTemp
, FALSE
);
134 if (retVal
!= NULLREGION
)
136 HRGN hrgnClip
= CreateRectRgnIndirect(&cliprc
);
138 hrgnWinupd
= CreateRectRgn( 0, 0, 0, 0);
139 CombineRgn( hrgnWinupd
, hrgnTemp
, 0, RGN_COPY
);
141 OffsetRgn( hrgnTemp
, dx
, dy
);
142 CombineRgn( hrgnTemp
, hrgnTemp
, hrgnClip
, RGN_AND
);
144 CombineRgn( hrgnWinupd
, hrgnWinupd
, hrgnTemp
, RGN_OR
);
145 RedrawWindow( hwnd
, NULL
, hrgnTemp
, rdw_flags
);
146 DeleteObject( hrgnClip
);
148 DeleteObject( hrgnTemp
);
150 /* nothing was scrolled */
152 SetRectRgn( hrgnUpdate
, 0, 0, 0, 0 );
153 SetRectEmpty( rcUpdate
);
156 if( flags
& SW_SCROLLCHILDREN
)
158 HWND
*list
= WIN_ListChildren( hwnd
);
163 for (i
= 0; list
[i
]; i
++)
165 GetWindowRect( list
[i
], &r
);
166 MapWindowPoints( 0, hwnd
, (POINT
*)&r
, 2 );
167 if (!rect
|| IntersectRect(&dummy
, &r
, rect
))
168 SetWindowPos( list
[i
], 0, r
.left
+ dx
, r
.top
+ dy
, 0, 0,
169 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
|
170 SWP_NOREDRAW
| SWP_DEFERERASE
);
172 HeapFree( GetProcessHeap(), 0, list
);
176 if( flags
& (SW_INVALIDATE
| SW_ERASE
) )
177 RedrawWindow( hwnd
, NULL
, hrgnUpdate
, rdw_flags
|
178 ((flags
& SW_SCROLLCHILDREN
) ? RDW_ALLCHILDREN
: 0 ) );
181 CombineRgn( hrgnUpdate
, hrgnUpdate
, hrgnWinupd
, RGN_OR
);
182 DeleteObject( hrgnWinupd
);
186 SetCaretPos( caretrc
.left
+ dx
, caretrc
.top
+ dy
);
187 ShowCaret(hwndCaret
);
190 if( bOwnRgn
&& hrgnUpdate
) DeleteObject( hrgnUpdate
);
195 /*************************************************************************
196 * ScrollWindow (USER32.@)
199 BOOL WINAPI
ScrollWindow( HWND hwnd
, INT dx
, INT dy
,
200 const RECT
*rect
, const RECT
*clipRect
)
203 (ERROR
!= ScrollWindowEx( hwnd
, dx
, dy
, rect
, clipRect
, 0, NULL
,
204 (rect
? 0 : SW_SCROLLCHILDREN
) |
205 SW_INVALIDATE
| SW_ERASE
));
208 /*************************************************************************
209 * ScrollDC (USER32.@)
211 * dx, dy, lprcScroll and lprcClip are all in logical coordinates (msdn is
212 * wrong) hrgnUpdate is returned in device coordinates with rcUpdate in
213 * logical coordinates.
215 BOOL WINAPI
ScrollDC( HDC hdc
, INT dx
, INT dy
, const RECT
*lprcScroll
,
216 const RECT
*lprcClip
, HRGN hrgnUpdate
, LPRECT lprcUpdate
)
219 if (USER_Driver
.pScrollDC
)
220 return USER_Driver
.pScrollDC( hdc
, dx
, dy
, lprcScroll
, lprcClip
, hrgnUpdate
, lprcUpdate
);