Release 940201
[wine.git] / windows / scroll.c
blob34d43fd2c6c8f6ddbfe146cbfa249d0e576e840f
1 /*
2 * Scroll windows and DCs
4 * Copyright David W. Metcalfe, 1993
6 */
8 static char Copyright[] = "Copyright David W. Metcalfe, 1993";
10 #include <stdlib.h>
11 #include "windows.h"
12 #include "gdi.h"
14 static int RgnType;
17 /*************************************************************************
18 * ScrollWindow (USER.61)
21 void ScrollWindow(HWND hwnd, short dx, short dy, LPRECT rect, LPRECT clipRect)
23 HDC hdc;
24 HRGN hrgnUpdate;
25 RECT rc, cliprc;
27 #ifdef DEBUG_SCROLL
28 printf("ScrollWindow: dx=%d, dy=%d, rect=%d,%d,%d,%d\n", dx, dy,
29 rect->left, rect->top, rect->right, rect->bottom);
30 #endif
32 hdc = GetDC(hwnd);
34 if (rect == NULL)
35 GetWindowRect(hwnd, &rc);
36 else
37 CopyRect(&rc, rect);
38 if (clipRect == NULL)
39 GetWindowRect(hwnd, &cliprc);
40 else
41 CopyRect(&cliprc, clipRect);
43 hrgnUpdate = CreateRectRgn(0, 0, 0, 0);
44 ScrollDC(hdc, dx, dy, &rc, &cliprc, hrgnUpdate, NULL);
45 InvalidateRgn(hwnd, hrgnUpdate, TRUE);
46 ReleaseDC(hwnd, hdc);
50 /*************************************************************************
51 * ScrollDC (USER.221)
54 BOOL ScrollDC(HDC hdc, short dx, short dy, LPRECT rc, LPRECT cliprc,
55 HRGN hrgnUpdate, LPRECT rcUpdate)
57 HRGN hrgnClip, hrgn1, hrgn2;
58 POINT src, dest;
59 short width, height;
60 DC *dc = (DC *)GDI_GetObjPtr(hdc, DC_MAGIC);
62 #ifdef DEBUG_SCROLL
63 printf("ScrollDC: dx=%d, dy=%d, rc=%d,%d,%d,%d\n", dx, dy,
64 rc->left, rc->top, rc->right, rc->bottom);
65 #endif
67 if (rc == NULL)
68 return;
70 if (cliprc)
72 hrgnClip = CreateRectRgnIndirect(cliprc);
73 SelectClipRgn(hdc, hrgnClip);
76 if (dx > 0)
78 src.x = XDPTOLP(dc, rc->left);
79 dest.x = XDPTOLP(dc, rc->left + abs(dx));
81 else
83 src.x = XDPTOLP(dc, rc->left + abs(dx));
84 dest.x = XDPTOLP(dc, rc->left);
86 if (dy > 0)
88 src.y = YDPTOLP(dc, rc->top);
89 dest.y = YDPTOLP(dc, rc->top + abs(dy));
91 else
93 src.y = YDPTOLP(dc, rc->top + abs(dy));
94 dest.y = YDPTOLP(dc, rc->top);
97 width = rc->right - rc->left - abs(dx);
98 height = rc->bottom - rc->top - abs(dy);
100 if (!BitBlt(hdc, dest.x, dest.y, width, height, hdc, src.x, src.y,
101 SRCCOPY))
102 return;
104 if (hrgnUpdate)
106 if (dx > 0)
107 hrgn1 = CreateRectRgn(rc->left, rc->top, rc->left+dx, rc->bottom);
108 else if (dx < 0)
109 hrgn1 = CreateRectRgn(rc->right+dx, rc->top, rc->right,
110 rc->bottom);
111 else
112 hrgn1 = CreateRectRgn(0, 0, 0, 0);
114 if (dy > 0)
115 hrgn2 = CreateRectRgn(rc->left, rc->top, rc->right, rc->top+dy);
116 else if (dy < 0)
117 hrgn2 = CreateRectRgn(rc->left, rc->bottom+dy, rc->right,
118 rc->bottom);
119 else
120 hrgn2 = CreateRectRgn(0, 0, 0, 0);
122 RgnType = CombineRgn(hrgnUpdate, hrgn1, hrgn2, RGN_OR);
125 if (rcUpdate)
127 SelectClipRgn(hdc, hrgnUpdate);
128 GetClipBox(hdc, rcUpdate);
133 /*************************************************************************
134 * ScrollWindowEx (USER.319)
137 int ScrollWindowEx(HWND hwnd, short dx, short dy, LPRECT rect, LPRECT clipRect,
138 HRGN hrgnUpdate, LPRECT rcUpdate, WORD flags)
140 HDC hdc;
141 RECT rc, cliprc;
143 #ifdef DEBUG_SCROLL
144 printf("ScrollWindowEx: dx=%d, dy=%d, rect=%d,%d,%d,%d\n", dx, dy,
145 rect->left, rect->top, rect->right, rect->bottom);
146 #endif
148 hdc = GetDC(hwnd);
150 if (rect == NULL)
151 GetWindowRect(hwnd, &rc);
152 else
153 CopyRect(&rc, rect);
154 if (clipRect == NULL)
155 GetWindowRect(hwnd, &cliprc);
156 else
157 CopyRect(&cliprc, clipRect);
159 ScrollDC(hdc, dx, dy, &rc, &cliprc, hrgnUpdate, rcUpdate);
161 if (flags | SW_INVALIDATE)
163 InvalidateRgn(hwnd, hrgnUpdate, FALSE);
165 if (flags | SW_ERASE)
166 SendMessage(hwnd, WM_ERASEBKGND, (WORD)hdc, (LONG)NULL);
169 ReleaseDC(hwnd, hdc);
170 return RgnType;