Moved implementation of EnumDisplaySettings from ASCII to Unicode.
[wine] / windows / scroll.c
1 /*
2  * Scroll windows and DCs
3  *
4  * Copyright  David W. Metcalfe, 1993
5  *            Alex Korobka       1995,1996
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #include <stdlib.h>
23
24 #include "windef.h"
25 #include "wingdi.h"
26 #include "wine/winuser16.h"
27 #include "winuser.h"
28 #include "user.h"
29 #include "win.h"
30 #include "wine/debug.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(scroll);
33
34 /*************************************************************************
35  *             fix_caret
36  */
37 static HWND fix_caret(HWND hWnd, LPRECT lprc, UINT flags)
38 {
39     GUITHREADINFO info;
40
41     if (!GetGUIThreadInfo( GetCurrentThreadId(), &info )) return 0;
42     if (!info.hwndCaret) return 0;
43     if (info.hwndCaret == hWnd ||
44         ((flags & SW_SCROLLCHILDREN) && IsChild(hWnd, info.hwndCaret)))
45     {
46         POINT pt;
47         pt.x = info.rcCaret.left;
48         pt.y = info.rcCaret.top;
49         MapWindowPoints( info.hwndCaret, hWnd, (LPPOINT)&info.rcCaret, 2 );
50         if( IntersectRect(lprc, lprc, &info.rcCaret) )
51         {
52             HideCaret(0);
53             lprc->left = pt.x;
54             lprc->top = pt.y;
55             return info.hwndCaret;
56         }
57     }
58     return 0;
59 }
60
61
62 /*************************************************************************
63  *              ScrollWindow (USER32.@)
64  *
65  */
66 BOOL WINAPI ScrollWindow( HWND hwnd, INT dx, INT dy,
67                               const RECT *rect, const RECT *clipRect )
68 {
69     return
70         (ERROR != ScrollWindowEx( hwnd, dx, dy, rect, clipRect, 0, NULL,
71                                     (rect ? 0 : SW_SCROLLCHILDREN) |
72                                     SW_INVALIDATE ));
73 }
74
75 /*************************************************************************
76  *              ScrollDC (USER32.@)
77  *
78  *   Only the hrgnUpdate is return in device coordinate.
79  *   rcUpdate must be returned in logical coordinate to comply with win API.
80  *
81  */
82 BOOL WINAPI ScrollDC( HDC hdc, INT dx, INT dy, const RECT *rc,
83                           const RECT *prLClip, HRGN hrgnUpdate,
84                           LPRECT rcUpdate )
85 {
86     if (USER_Driver.pScrollDC)
87         return USER_Driver.pScrollDC( hdc, dx, dy, rc, prLClip, hrgnUpdate, rcUpdate );
88     return FALSE;
89 }
90
91
92 /*************************************************************************
93  *              ScrollWindowEx (USER32.@)
94  *
95  * NOTE: Use this function instead of ScrollWindow32
96  */
97 INT WINAPI ScrollWindowEx( HWND hwnd, INT dx, INT dy,
98                                const RECT *rect, const RECT *clipRect,
99                                HRGN hrgnUpdate, LPRECT rcUpdate,
100                                UINT flags )
101 {
102     RECT rc, cliprc;
103     INT result;
104     
105     if (!WIN_IsWindowDrawable( hwnd, TRUE )) return ERROR;
106     hwnd = WIN_GetFullHandle( hwnd );
107
108     GetClientRect(hwnd, &rc);
109     if (rect) IntersectRect(&rc, &rc, rect);
110
111     if (clipRect) IntersectRect(&cliprc,&rc,clipRect);
112     else cliprc = rc;
113
114     if (!IsRectEmpty(&cliprc) && (dx || dy))
115     {
116         RECT caretrc = rc;
117         HWND hwndCaret = fix_caret(hwnd, &caretrc, flags);
118
119         if (USER_Driver.pScrollWindowEx)
120             result = USER_Driver.pScrollWindowEx( hwnd, dx, dy, &rc, &cliprc,
121                                                   hrgnUpdate, rcUpdate, flags );
122         else
123             result = ERROR; /* FIXME: we should have a fallback implementation */
124         
125         if( hwndCaret )
126         {
127             SetCaretPos( caretrc.left + dx, caretrc.top + dy );
128             ShowCaret(hwndCaret);
129         }
130     }
131     else 
132         result = NULLREGION;
133     
134     return result;
135 }