Release 950122
[wine/multimedia.git] / windows / scroll.c
blobd662983e36c5eaf54bcc0708bbec54fb10abe9ef
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=%d,%d,%d,%d\n",
31 dx, dy, rect->left, rect->top, rect->right, 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=%d,%d,%d,%d\n", dx, dy,
64 rc->left, rc->top, rc->right, 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=%d,%d,%d,%d\n",
140 dx, dy, rect->left, rect->top, rect->right, rect->bottom);
142 hdc = GetDC(hwnd);
144 if (rect == NULL)
145 GetClientRect(hwnd, &rc);
146 else
147 CopyRect(&rc, rect);
148 if (clipRect == NULL)
149 GetClientRect(hwnd, &cliprc);
150 else
151 CopyRect(&cliprc, clipRect);
153 ScrollDC(hdc, dx, dy, &rc, &cliprc, hrgnUpdate, rcUpdate);
155 if (flags | SW_INVALIDATE)
157 RedrawWindow( hwnd, NULL, hrgnUpdate, RDW_INVALIDATE | RDW_ERASE |
158 ((flags & SW_ERASE) ? RDW_ERASENOW : 0));
161 ReleaseDC(hwnd, hdc);
162 return RgnType;