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"
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
;
64 /*************************************************************************
65 * ScrollWindow (USER32.@)
68 BOOL WINAPI
ScrollWindow( HWND hwnd
, INT dx
, INT dy
,
69 const RECT
*rect
, const RECT
*clipRect
)
72 (ERROR
!= ScrollWindowEx( hwnd
, dx
, dy
, rect
, clipRect
, 0, NULL
,
73 (rect
? 0 : SW_SCROLLCHILDREN
) |
77 /*************************************************************************
80 * dx, dy, lprcScroll and lprcClip are all in logical coordinates (msdn is wrong)
81 * hrgnUpdate is returned in device coordinates with rcUpdate in logical coordinates.
83 BOOL WINAPI
ScrollDC( HDC hdc
, INT dx
, INT dy
, const RECT
*lprcScroll
,
84 const RECT
*lprcClip
, HRGN hrgnUpdate
, LPRECT lprcUpdate
)
87 RECT rSrc
, rClipped_src
, rClip
, rDst
, offset
;
89 TRACE( "%p %d,%d hrgnUpdate=%p lprcUpdate = %p\n", hdc
, dx
, dy
, hrgnUpdate
, lprcUpdate
);
90 if (lprcClip
) TRACE( "lprcClip = %s\n", wine_dbgstr_rect(lprcClip
));
91 if (lprcScroll
) TRACE( "lprcScroll = %s\n", wine_dbgstr_rect(lprcScroll
));
93 /* compute device clipping region (in device coordinates) */
95 if (lprcScroll
) rSrc
= *lprcScroll
;
96 else GetClipBox( hdc
, &rSrc
);
97 LPtoDP(hdc
, (LPPOINT
)&rSrc
, 2);
99 if (lprcClip
) rClip
= *lprcClip
;
100 else GetClipBox( hdc
, &rClip
);
101 LPtoDP(hdc
, (LPPOINT
)&rClip
, 2);
103 IntersectRect( &rClipped_src
, &rSrc
, &rClip
);
104 TRACE("rSrc %s rClip %s clipped rSrc %s\n", wine_dbgstr_rect(&rSrc
),
105 wine_dbgstr_rect(&rClip
), wine_dbgstr_rect(&rClipped_src
));
108 SetRect(&offset
, 0, 0, dx
, dy
);
109 LPtoDP(hdc
, (LPPOINT
)&offset
, 2);
110 OffsetRect( &rDst
, offset
.right
- offset
.left
, offset
.bottom
- offset
.top
);
111 TRACE("rDst before clipping %s\n", wine_dbgstr_rect(&rDst
));
112 IntersectRect( &rDst
, &rDst
, &rClip
);
113 TRACE("rDst after clipping %s\n", wine_dbgstr_rect(&rDst
));
115 if (!IsRectEmpty(&rDst
))
118 RECT rDst_lp
= rDst
, rSrc_lp
= rDst
;
120 OffsetRect( &rSrc_lp
, offset
.left
- offset
.right
, offset
.top
- offset
.bottom
);
121 DPtoLP(hdc
, (LPPOINT
)&rDst_lp
, 2);
122 DPtoLP(hdc
, (LPPOINT
)&rSrc_lp
, 2);
124 if (!BitBlt( hdc
, rDst_lp
.left
, rDst_lp
.top
,
125 rDst_lp
.right
- rDst_lp
.left
, rDst_lp
.bottom
- rDst_lp
.top
,
126 hdc
, rSrc_lp
.left
, rSrc_lp
.top
, SRCCOPY
))
130 /* compute update areas. This is the clipped source or'ed with the unclipped source translated minus the
131 clipped src translated (rDst) all clipped to rClip */
133 if (hrgnUpdate
|| lprcUpdate
)
135 HRGN hrgn
= hrgnUpdate
, hrgn2
;
137 if (hrgn
) SetRectRgn( hrgn
, rClipped_src
.left
, rClipped_src
.top
, rClipped_src
.right
, rClipped_src
.bottom
);
138 else hrgn
= CreateRectRgn( rClipped_src
.left
, rClipped_src
.top
, rClipped_src
.right
, rClipped_src
.bottom
);
140 hrgn2
= CreateRectRgnIndirect( &rSrc
);
141 OffsetRgn(hrgn2
, offset
.right
- offset
.left
, offset
.bottom
- offset
.top
);
142 CombineRgn(hrgn
, hrgn
, hrgn2
, RGN_OR
);
144 SetRectRgn( hrgn2
, rDst
.left
, rDst
.top
, rDst
.right
, rDst
.bottom
);
145 CombineRgn( hrgn
, hrgn
, hrgn2
, RGN_DIFF
);
147 SetRectRgn( hrgn2
, rClip
.left
, rClip
.top
, rClip
.right
, rClip
.bottom
);
148 CombineRgn( hrgn
, hrgn
, hrgn2
, RGN_AND
);
152 GetRgnBox( hrgn
, lprcUpdate
);
154 /* Put the lprcUpdate in logical coordinate */
155 DPtoLP( hdc
, (LPPOINT
)lprcUpdate
, 2 );
156 TRACE("returning lprcUpdate %s\n", wine_dbgstr_rect(lprcUpdate
));
158 if (!hrgnUpdate
) DeleteObject( hrgn
);
159 DeleteObject( hrgn2
);
165 /*************************************************************************
166 * ScrollWindowEx (USER32.@)
168 * NOTE: Use this function instead of ScrollWindow32
170 INT WINAPI
ScrollWindowEx( HWND hwnd
, INT dx
, INT dy
,
171 const RECT
*rect
, const RECT
*clipRect
,
172 HRGN hrgnUpdate
, LPRECT rcUpdate
,
178 if (!WIN_IsWindowDrawable( hwnd
, TRUE
)) return ERROR
;
179 hwnd
= WIN_GetFullHandle( hwnd
);
181 GetClientRect(hwnd
, &rc
);
182 if (rect
) IntersectRect(&rc
, &rc
, rect
);
184 if (clipRect
) IntersectRect(&cliprc
,&rc
,clipRect
);
187 if (!IsRectEmpty(&cliprc
) && (dx
|| dy
))
190 HWND hwndCaret
= fix_caret(hwnd
, &caretrc
, flags
);
192 if (USER_Driver
.pScrollWindowEx
)
193 result
= USER_Driver
.pScrollWindowEx( hwnd
, dx
, dy
, rect
, clipRect
,
194 hrgnUpdate
, rcUpdate
, flags
);
196 result
= ERROR
; /* FIXME: we should have a fallback implementation */
200 SetCaretPos( caretrc
.left
+ dx
, caretrc
.top
+ dy
);
201 ShowCaret(hwndCaret
);