Release 951105
[wine/multimedia.git] / windows / scroll.c
blobb24fcbfe1f1c142e2d321cac114ec879195ce17d
1 /*
2 * Scroll windows and DCs
4 * Copyright David W. Metcalfe, 1993
6 */
8 #include <stdlib.h>
9 #include "windows.h"
10 #include "gdi.h"
11 #include "scroll.h"
12 #include "stddebug.h"
13 /* #define DEBUG_SCROLL */
14 #include "debug.h"
17 static int RgnType;
20 /*************************************************************************
21 * ScrollWindow (USER.61)
24 void ScrollWindow(HWND hwnd, short dx, short dy, LPRECT rect, LPRECT clipRect)
26 HDC hdc;
27 HRGN hrgnUpdate;
28 RECT rc, cliprc;
30 dprintf_scroll(stddeb,"ScrollWindow: dx=%d, dy=%d, rect=%ld,%ld,%ld,%ld\n",
31 dx, dy, (LONG)rect->left, (LONG)rect->top, (LONG)rect->right, (LONG)rect->bottom);
33 hdc = GetDC(hwnd);
35 if (rect == NULL)
36 GetClientRect(hwnd, &rc);
37 else
38 CopyRect(&rc, rect);
39 if (clipRect == NULL)
40 GetClientRect(hwnd, &cliprc);
41 else
42 CopyRect(&cliprc, clipRect);
44 hrgnUpdate = CreateRectRgn(0, 0, 0, 0);
45 ScrollDC(hdc, dx, dy, &rc, &cliprc, hrgnUpdate, NULL);
46 InvalidateRgn(hwnd, hrgnUpdate, TRUE);
47 ReleaseDC(hwnd, hdc);
51 /*************************************************************************
52 * ScrollDC (USER.221)
55 BOOL ScrollDC(HDC hdc, short dx, short dy, LPRECT rc, LPRECT cliprc,
56 HRGN hrgnUpdate, LPRECT rcUpdate)
58 HRGN hrgnClip, hrgn1, hrgn2;
59 POINT src, dest;
60 short width, height;
61 DC *dc = (DC *)GDI_GetObjPtr(hdc, DC_MAGIC);
63 dprintf_scroll(stddeb, "ScrollDC: dx=%d, dy=%d, rc=%ld,%ld,%ld,%ld\n", dx, dy,
64 (LONG)rc->left, (LONG)rc->top, (LONG)rc->right, (LONG)rc->bottom);
66 if (rc == NULL)
67 return FALSE;
69 if (cliprc)
71 hrgnClip = CreateRectRgnIndirect(cliprc);
72 SelectClipRgn(hdc, hrgnClip);
75 if (dx > 0)
77 src.x = XDPTOLP(dc, rc->left);
78 dest.x = XDPTOLP(dc, rc->left + abs(dx));
80 else
82 src.x = XDPTOLP(dc, rc->left + abs(dx));
83 dest.x = XDPTOLP(dc, rc->left);
85 if (dy > 0)
87 src.y = YDPTOLP(dc, rc->top);
88 dest.y = YDPTOLP(dc, rc->top + abs(dy));
90 else
92 src.y = YDPTOLP(dc, rc->top + abs(dy));
93 dest.y = YDPTOLP(dc, rc->top);
96 width = rc->right - rc->left - abs(dx);
97 height = rc->bottom - rc->top - abs(dy);
99 if (!BitBlt(hdc, dest.x, dest.y, width, height, hdc, src.x, src.y,
100 SRCCOPY))
101 return FALSE;
103 if (hrgnUpdate)
105 if (dx > 0)
106 hrgn1 = CreateRectRgn(rc->left, rc->top, rc->left+dx, rc->bottom);
107 else if (dx < 0)
108 hrgn1 = CreateRectRgn(rc->right+dx, rc->top, rc->right,
109 rc->bottom);
110 else
111 hrgn1 = CreateRectRgn(0, 0, 0, 0);
113 if (dy > 0)
114 hrgn2 = CreateRectRgn(rc->left, rc->top, rc->right, rc->top+dy);
115 else if (dy < 0)
116 hrgn2 = CreateRectRgn(rc->left, rc->bottom+dy, rc->right,
117 rc->bottom);
118 else
119 hrgn2 = CreateRectRgn(0, 0, 0, 0);
121 RgnType = CombineRgn(hrgnUpdate, hrgn1, hrgn2, RGN_OR);
124 if (rcUpdate) GetRgnBox( hrgnUpdate, rcUpdate );
125 return TRUE;
129 /*************************************************************************
130 * ScrollWindowEx (USER.319)
133 int ScrollWindowEx(HWND hwnd, short dx, short dy, LPRECT rect, LPRECT clipRect,
134 HRGN hrgnUpdate, LPRECT rcUpdate, WORD flags)
136 HDC hdc;
137 RECT rc, cliprc;
139 dprintf_scroll(stddeb,"ScrollWindowEx: dx=%d, dy=%d, rect=%ld,%ld,%ld,%ld\n",
140 dx, dy, (LONG)rect->left, (LONG)rect->top, (LONG)rect->right,
141 (LONG)rect->bottom);
143 hdc = GetDC(hwnd);
145 if (rect == NULL)
146 GetClientRect(hwnd, &rc);
147 else
148 CopyRect(&rc, rect);
149 if (clipRect == NULL)
150 GetClientRect(hwnd, &cliprc);
151 else
152 CopyRect(&cliprc, clipRect);
154 ScrollDC(hdc, dx, dy, &rc, &cliprc, hrgnUpdate, rcUpdate);
156 if (flags | SW_INVALIDATE)
158 RedrawWindow( hwnd, NULL, hrgnUpdate, RDW_INVALIDATE | RDW_ERASE |
159 ((flags & SW_ERASE) ? RDW_ERASENOW : 0));
162 ReleaseDC(hwnd, hdc);
163 return RgnType;