2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Clipboard Viewer
4 * FILE: base/applications/clipbrd/scrollutils.c
5 * PURPOSE: Scrolling releated helper functions.
6 * PROGRAMMERS: Ricardo Hanke
11 static int InternalSetScrollInfo(HWND hWnd
, int nMin
, int nMax
, UINT nPage
, int nPos
, int fnBar
)
15 ZeroMemory(&si
, sizeof(si
));
16 si
.cbSize
= sizeof(si
);
17 si
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
| SIF_DISABLENOSCROLL
;
23 return SetScrollInfo(hWnd
, fnBar
, &si
, TRUE
);
26 void HandleKeyboardScrollEvents(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
32 SendMessage(hWnd
, WM_VSCROLL
, MAKELONG(SB_LINEUP
, 0), 0);
38 SendMessage(hWnd
, WM_VSCROLL
, MAKELONG(SB_LINEDOWN
, 0), 0);
44 SendMessage(hWnd
, WM_HSCROLL
, MAKELONG(SB_LINEUP
, 0), 0);
50 SendMessage(hWnd
, WM_HSCROLL
, MAKELONG(SB_LINEDOWN
, 0), 0);
56 SendMessage(hWnd
, WM_VSCROLL
, MAKELONG(SB_PAGEUP
, 0), 0);
62 SendMessage(hWnd
, WM_VSCROLL
, MAKELONG(SB_PAGEDOWN
, 0), 0);
73 void HandleMouseScrollEvents(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, LPSCROLLSTATE state
)
79 si
.cbSize
= sizeof(si
);
81 GetScrollInfo(hWnd
, SB_VERT
, &si
);
83 if (Globals
.uLinesToScroll
== WHEEL_PAGESCROLL
)
89 NewPos
= Globals
.uLinesToScroll
* 5;
92 if (GET_WHEEL_DELTA_WPARAM(wParam
) > 0)
94 NewPos
= state
->CurrentY
- NewPos
;
98 NewPos
= state
->CurrentY
+ NewPos
;
101 NewPos
= min(state
->MaxY
, max(0, NewPos
));
103 if (NewPos
== state
->CurrentY
)
108 Delta
= NewPos
- state
->CurrentY
;
110 state
->CurrentY
= NewPos
;
112 ScrollWindowEx(hWnd
, 0, -Delta
, NULL
, NULL
, NULL
, NULL
, SW_INVALIDATE
);
114 si
.cbSize
= sizeof(si
);
116 si
.nPos
= state
->CurrentY
;
117 SetScrollInfo(hWnd
, SB_VERT
, &si
, TRUE
);
120 void HandleHorizontalScrollEvents(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, LPSCROLLSTATE state
)
126 ZeroMemory(&si
, sizeof(si
));
127 si
.cbSize
= sizeof(si
);
128 si
.fMask
= SIF_PAGE
| SIF_TRACKPOS
;
129 GetScrollInfo(hWnd
, SB_HORZ
, &si
);
131 switch (LOWORD(wParam
))
133 case SB_THUMBPOSITION
:
136 NewPos
= si
.nTrackPos
;
142 NewPos
= state
->CurrentX
- 5;
148 NewPos
= state
->CurrentX
+ 5;
154 NewPos
= state
->CurrentX
- si
.nPage
;
160 NewPos
= state
->CurrentX
+ si
.nPage
;
166 NewPos
= state
->CurrentX
;
171 NewPos
= min(state
->MaxX
, max(0, NewPos
));
173 if (NewPos
== state
->CurrentX
)
178 Delta
= NewPos
- state
->CurrentX
;
180 state
->CurrentX
= NewPos
;
182 ScrollWindowEx(hWnd
, -Delta
, 0, NULL
, NULL
, NULL
, NULL
, SW_INVALIDATE
);
184 si
.cbSize
= sizeof(si
);
186 si
.nPos
= state
->CurrentX
;
187 SetScrollInfo(hWnd
, SB_HORZ
, &si
, TRUE
);
190 void HandleVerticalScrollEvents(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, LPSCROLLSTATE state
)
196 ZeroMemory(&si
, sizeof(si
));
197 si
.cbSize
= sizeof(si
);
198 si
.fMask
= SIF_PAGE
| SIF_TRACKPOS
;
199 GetScrollInfo(hWnd
, SB_VERT
, &si
);
201 switch (LOWORD(wParam
))
203 case SB_THUMBPOSITION
:
206 NewPos
= si
.nTrackPos
;
212 NewPos
= state
->CurrentY
- 5;
218 NewPos
= state
->CurrentY
+ 5;
224 NewPos
= state
->CurrentY
- si
.nPage
;
230 NewPos
= state
->CurrentY
+ si
.nPage
;
236 NewPos
= state
->CurrentY
;
241 NewPos
= min(state
->MaxY
, max(0, NewPos
));
243 if (NewPos
== state
->CurrentY
)
248 Delta
= NewPos
- state
->CurrentY
;
250 state
->CurrentY
= NewPos
;
252 ScrollWindowEx(hWnd
, 0, -Delta
, NULL
, NULL
, NULL
, NULL
, SW_INVALIDATE
);
254 si
.cbSize
= sizeof(si
);
256 si
.nPos
= state
->CurrentY
;
257 SetScrollInfo(hWnd
, SB_VERT
, &si
, TRUE
);
260 void UpdateWindowScrollState(HWND hWnd
, HBITMAP hBitmap
, LPSCROLLSTATE lpState
)
265 if (!GetObject(hBitmap
, sizeof(BITMAP
), &bmp
))
271 if (!GetClientRect(hWnd
, &rc
))
276 lpState
->MaxX
= max(bmp
.bmWidth
- rc
.right
, 0);
277 lpState
->CurrentX
= min(lpState
->CurrentX
, lpState
->MaxX
);
278 InternalSetScrollInfo(hWnd
, 0, bmp
.bmWidth
, rc
.right
, lpState
->CurrentX
, SB_HORZ
);
280 lpState
->MaxY
= max(bmp
.bmHeight
- rc
.bottom
, 0);
281 lpState
->CurrentY
= min(lpState
->CurrentY
, lpState
->MaxY
);
282 InternalSetScrollInfo(hWnd
, 0, bmp
.bmHeight
, rc
.bottom
, lpState
->CurrentY
, SB_VERT
);
285 BOOL
ScrollBlt(PAINTSTRUCT ps
, HBITMAP hBmp
, SCROLLSTATE state
)
293 rect
.left
= ps
.rcPaint
.left
;
294 rect
.top
= ps
.rcPaint
.top
;
295 rect
.right
= (ps
.rcPaint
.right
- ps
.rcPaint
.left
);
296 rect
.bottom
= (ps
.rcPaint
.bottom
- ps
.rcPaint
.top
);
298 xpos
= ps
.rcPaint
.left
+ state
.CurrentX
;
299 ypos
= ps
.rcPaint
.top
+ state
.CurrentY
;
303 hdc
= CreateCompatibleDC(ps
.hdc
);
306 if (SelectObject(hdc
, hBmp
))
308 ret
= BitBlt(ps
.hdc
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
, hdc
, xpos
, ypos
, SRCCOPY
);