Release 940405
[wine/gsoc-2012-control.git] / controls / scroll.c
blob1d05ee37e331ee9cf7097246239d65382f6c625a
1 /*
2 * Interface code to SCROLLBAR widget
4 * Copyright Martin Ayotte, 1993
6 */
8 /*
9 #define DEBUG_SCROLL
11 static char Copyright[] = "Copyright Martin Ayotte, 1993";
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include <sys/types.h>
16 #include <sys/stat.h>
17 #include "windows.h"
18 #include "sysmetrics.h"
19 #include "scroll.h"
20 #include "heap.h"
21 #include "win.h"
22 #include "prototypes.h"
24 HBITMAP hUpArrow = 0;
25 HBITMAP hDnArrow = 0;
26 HBITMAP hLfArrow = 0;
27 HBITMAP hRgArrow = 0;
28 HBITMAP hUpArrowD = 0;
29 HBITMAP hDnArrowD = 0;
30 HBITMAP hLfArrowD = 0;
31 HBITMAP hRgArrowD = 0;
33 LPHEADSCROLL ScrollBarGetWindowAndStorage(HWND hWnd, WND **wndPtr);
34 LPHEADSCROLL ScrollBarGetStorageHeader(HWND hWnd);
35 LPHEADSCROLL GetScrollObjectStruct(HWND hWnd, int nBar);
36 void ScrollBarButtonDown(HWND hWnd, int nBar, int x, int y);
37 void ScrollBarButtonUp(HWND hWnd, int nBar, int x, int y);
38 void ScrollBarMouseMove(HWND hWnd, int nBar, WORD wParam, int x, int y);
39 void StdDrawScrollBar(HWND hWnd, HDC hDC, int nBar, LPRECT lprect, LPHEADSCROLL lphs);
40 int CreateScrollBarStruct(HWND hWnd);
41 void NC_CreateScrollBars(HWND hWnd);
42 LPHEADSCROLL AllocScrollBar(DWORD dwStyle, int width, int height);
45 /***********************************************************************
46 * WIDGETS_ScrollBarWndProc
48 LONG ScrollBarWndProc( HWND hWnd, WORD message, WORD wParam, LONG lParam )
50 WORD wRet;
51 short x, y;
52 short width, height;
53 WND *wndPtr;
54 LPHEADSCROLL lphs;
55 PAINTSTRUCT ps;
56 HDC hDC;
57 BITMAP bm;
58 RECT rect, rect2;
59 static RECT rectsel;
60 switch(message)
62 case WM_CREATE:
63 CreateScrollBarStruct(hWnd);
64 #ifdef DEBUG_SCROLL
65 printf("ScrollBar Creation !\n");
66 #endif
67 return 0;
68 case WM_DESTROY:
69 lphs = ScrollBarGetWindowAndStorage(hWnd, &wndPtr);
70 if (lphs == 0) return 0;
71 #ifdef DEBUG_SCROLL
72 printf("ScrollBar WM_DESTROY %lX !\n", lphs);
73 #endif
74 free(lphs);
75 *((LPHEADSCROLL *)&wndPtr->wExtra[1]) = 0;
76 return 0;
78 case WM_LBUTTONDOWN:
79 SetCapture(hWnd);
80 ScrollBarButtonDown(hWnd, SB_CTL, LOWORD(lParam), HIWORD(lParam));
81 break;
82 case WM_LBUTTONUP:
83 ReleaseCapture();
84 ScrollBarButtonUp(hWnd, SB_CTL, LOWORD(lParam), HIWORD(lParam));
85 break;
87 case WM_MOUSEMOVE:
88 ScrollBarMouseMove(hWnd, SB_CTL, wParam, LOWORD(lParam), HIWORD(lParam));
89 break;
90 case WM_KEYDOWN:
91 case WM_KEYUP:
92 case WM_CHAR:
93 lphs = ScrollBarGetWindowAndStorage(hWnd, &wndPtr);
94 return(SendMessage(wndPtr->hwndParent, message, wParam, lParam));
96 case WM_TIMER:
97 #ifdef DEBUG_SCROLL
98 printf("ScrollBar WM_TIMER wParam=%X lParam=%lX !\n", wParam, lParam);
99 #endif
100 lphs = ScrollBarGetWindowAndStorage(hWnd, &wndPtr);
101 KillTimer(hWnd, wParam);
102 switch(lphs->ButtonDown) {
103 case 0:
104 lphs->TimerPending = FALSE;
105 return 0;
106 case 1:
107 case 3:
108 SendMessage(wndPtr->hwndParent, lphs->Direction,
109 SB_LINEUP, MAKELONG(0, hWnd));
110 break;
111 case 2:
112 case 4:
113 SendMessage(wndPtr->hwndParent, lphs->Direction,
114 SB_LINEDOWN, MAKELONG(0, hWnd));
115 break;
116 case 5:
117 SendMessage(wndPtr->hwndParent, lphs->Direction,
118 SB_PAGEUP, MAKELONG(0, hWnd));
119 break;
120 case 6:
121 SendMessage(wndPtr->hwndParent, lphs->Direction,
122 SB_PAGEDOWN, MAKELONG(0, hWnd));
123 break;
125 SetTimer(hWnd, 1, 100, NULL);
126 return 0;
128 case WM_PAINT:
129 hDC = BeginPaint(hWnd, &ps);
130 lphs = ScrollBarGetStorageHeader(hWnd);
131 if (lphs != NULL) {
132 GetClientRect(hWnd, &rect);
133 StdDrawScrollBar(hWnd, hDC, SB_CTL, &rect, lphs);
135 EndPaint(hWnd, &ps);
136 break;
137 default:
138 return DefWindowProc( hWnd, message, wParam, lParam );
140 return(0);
145 void ScrollBarButtonDown(HWND hWnd, int nBar, int x, int y)
147 LPHEADSCROLL lphs;
148 HWND hWndParent;
149 RECT rect, rect2;
150 int width, height;
151 LONG dwOwner;
152 lphs = GetScrollObjectStruct(hWnd, nBar);
153 if (nBar == SB_CTL) {
154 hWndParent = GetParent(hWnd);
155 dwOwner = MAKELONG(0, lphs->hWndOwner);
156 #ifdef DEBUG_SCROLL
157 printf("ScrollBarButtonDown SB_CTL // x=%d y=%d\n", x, y);
158 #endif
160 else {
161 hWndParent = hWnd;
162 dwOwner = 0L;
163 #ifdef DEBUG_SCROLL
164 printf("ScrollBarButtonDown SB_?SCROLL // x=%d y=%d\n", x, y);
165 #endif
168 SetFocus(lphs->hWndOwner);
170 CopyRect(&rect, &lphs->rect);
171 #ifdef DEBUG_SCROLL
172 printf("ScrollDown / x=%d y=%d left=%d top=%d right=%d bottom=%d \n",
173 x, y, rect.left, rect.top, rect.right, rect.bottom);
174 #endif
175 if (lphs->Direction == WM_VSCROLL) {
176 width = rect.right - rect.left;
177 if (y < (lphs->CurPix + width)) {
178 if (y < width) {
179 lphs->ButtonDown = 1;
180 CopyRect(&rect2, &rect);
181 rect2.bottom = rect2.top + width;
182 InvalidateRect(lphs->hWndOwner, &rect2, TRUE);
183 #ifdef DEBUG_SCROLL
184 printf("ScrollBarButtonDown send SB_LINEUP\n");
185 #endif
186 SendMessage(hWndParent, lphs->Direction,
187 SB_LINEUP, dwOwner);
189 else {
190 lphs->ButtonDown = 5;
191 #ifdef DEBUG_SCROLL
192 printf("ScrollBarButtonDown send SB_PAGEUP\n");
193 #endif
194 SendMessage(hWndParent, lphs->Direction,
195 SB_PAGEUP, dwOwner);
198 if (y > (lphs->CurPix + (width << 1))) {
199 if (y > (rect.bottom - rect.top - width)) {
200 lphs->ButtonDown = 2;
201 CopyRect(&rect2, &rect);
202 rect2.top = rect2.bottom - width;
203 InvalidateRect(lphs->hWndOwner, &rect2, TRUE);
204 #ifdef DEBUG_SCROLL
205 printf("ScrollBarButtonDown send SB_LINEDOWN\n");
206 #endif
207 SendMessage(hWndParent, lphs->Direction,
208 SB_LINEDOWN, dwOwner);
210 else {
211 lphs->ButtonDown = 6;
212 #ifdef DEBUG_SCROLL
213 printf("ScrollBarButtonDown send SB_PAGEDOWN\n");
214 #endif
215 SendMessage(hWndParent, lphs->Direction,
216 SB_PAGEDOWN, dwOwner);
219 if ((y > (lphs->CurPix + width)) &&
220 (y < (lphs->CurPix + (width << 1)))) {
221 lphs->ThumbActive = TRUE;
222 #ifdef DEBUG_SCROLL
223 printf("THUMB DOWN !\n");
224 #endif
227 else {
228 height = rect.bottom - rect.top;
229 if (x < (lphs->CurPix + height)) {
230 if (x < height) {
231 lphs->ButtonDown = 3;
232 CopyRect(&rect2, &rect);
233 rect2.right = rect2.left + height;
234 InvalidateRect(lphs->hWndOwner, &rect2, TRUE);
235 #ifdef DEBUG_SCROLL
236 printf("ScrollBarButtonDown send SB_LINEUP\n");
237 #endif
238 SendMessage(hWndParent, lphs->Direction,
239 SB_LINEUP, dwOwner);
241 else {
242 lphs->ButtonDown = 5;
243 #ifdef DEBUG_SCROLL
244 printf("ScrollBarButtonDown send SB_PAGEUP\n");
245 #endif
246 SendMessage(hWndParent, lphs->Direction,
247 SB_PAGEUP, dwOwner);
250 if (x > (lphs->CurPix + (height << 1))) {
251 if (x > (rect.right - rect.left - height)) {
252 lphs->ButtonDown = 4;
253 CopyRect(&rect2, &rect);
254 rect2.left = rect2.right - height;
255 InvalidateRect(lphs->hWndOwner, &rect2, TRUE);
256 #ifdef DEBUG_SCROLL
257 printf("ScrollBarButtonDown send SB_LINEDOWN\n");
258 #endif
259 SendMessage(hWndParent, lphs->Direction,
260 SB_LINEDOWN, dwOwner);
262 else {
263 lphs->ButtonDown = 6;
264 #ifdef DEBUG_SCROLL
265 printf("ScrollBarButtonDown send SB_PAGEDOWN\n");
266 #endif
267 SendMessage(hWndParent, lphs->Direction,
268 SB_PAGEDOWN, dwOwner);
271 if ((x > (lphs->CurPix + height)) &&
272 (x < (lphs->CurPix + (height << 1)))) {
273 lphs->ThumbActive = TRUE;
274 #ifdef DEBUG_SCROLL
275 printf("THUMB DOWN !\n");
276 #endif
279 if (lphs->ButtonDown != 0) {
280 UpdateWindow(lphs->hWndOwner);
281 if (!lphs->TimerPending && nBar == SB_CTL) {
282 lphs->TimerPending = TRUE;
283 SetTimer(lphs->hWndOwner, 1, 500, NULL);
289 void ScrollBarButtonUp(HWND hWnd, int nBar, int x, int y)
291 LPHEADSCROLL lphs;
292 RECT rect, rect2;
293 HDC hDC;
294 #ifdef DEBUG_SCROLL
295 printf("ScrollBarButtonUp // x=%d y=%d\n", x, y);
296 #endif
297 lphs = GetScrollObjectStruct(hWnd, nBar);
298 lphs->ThumbActive = FALSE;
299 if (lphs->ButtonDown != 0) {
300 lphs->ButtonDown = 0;
301 GetClientRect(lphs->hWndOwner, &rect);
302 if (nBar == SB_CTL) {
303 InvalidateRect(lphs->hWndOwner, &rect, TRUE);
304 UpdateWindow(lphs->hWndOwner);
306 else {
307 hDC = GetWindowDC(lphs->hWndOwner);
308 StdDrawScrollBar(lphs->hWndOwner, hDC, nBar, &lphs->rect, lphs);
309 ReleaseDC(lphs->hWndOwner, hDC);
315 void ScrollBarMouseMove(HWND hWnd, int nBar, WORD wParam, int x, int y)
317 LPHEADSCROLL lphs;
318 HWND hWndParent;
319 HWND hWndOwner;
320 LONG dwOwner;
321 if ((wParam & MK_LBUTTON) == 0) return;
322 lphs = GetScrollObjectStruct(hWnd, nBar);
323 if (lphs->ThumbActive == 0) return;
324 if (nBar == SB_CTL) {
325 hWndParent = GetParent(hWnd);
326 hWndOwner = lphs->hWndOwner;
327 #ifdef DEBUG_SCROLL
328 printf("ScrollBarButtonMove SB_CTL // x=%d y=%d\n", x, y);
329 #endif
331 else {
332 hWndParent = hWnd;
333 hWndOwner = 0;
334 #ifdef DEBUG_SCROLL
335 printf("ScrollBarButtonMove SB_?SCROLL // x=%d y=%d\n", x, y);
336 #endif
338 if (lphs->Direction == WM_VSCROLL) {
339 int butsiz = lphs->rect.right - lphs->rect.left;
340 y = y - butsiz - (butsiz >> 1);
342 else {
343 int butsiz = lphs->rect.bottom - lphs->rect.top;
344 y = x - butsiz - (butsiz >> 1);
346 x = (y * (lphs->MaxVal - lphs->MinVal) /
347 lphs->MaxPix) + lphs->MinVal;
348 #ifdef DEBUG_SCROLL
349 printf("Scroll WM_MOUSEMOVE val=%d pix=%d\n", x, y);
350 #endif
351 SendMessage(hWndParent, lphs->Direction,
352 SB_THUMBTRACK, MAKELONG(x, hWndOwner));
356 LPHEADSCROLL ScrollBarGetWindowAndStorage(HWND hWnd, WND **wndPtr)
358 WND *Ptr;
359 LPHEADSCROLL lphs;
360 *(wndPtr) = Ptr = WIN_FindWndPtr(hWnd);
361 if (Ptr == 0) {
362 printf("Bad Window handle on ScrollBar !\n");
363 return 0;
365 lphs = *((LPHEADSCROLL *)&Ptr->wExtra[1]);
366 return lphs;
370 LPHEADSCROLL ScrollBarGetStorageHeader(HWND hWnd)
372 WND *wndPtr;
373 LPHEADSCROLL lphs;
374 wndPtr = WIN_FindWndPtr(hWnd);
375 if (wndPtr == 0) {
376 printf("Bad Window handle on ScrollBar !\n");
377 return 0;
379 lphs = *((LPHEADSCROLL *)&wndPtr->wExtra[1]);
380 return lphs;
385 void StdDrawScrollBar(HWND hWnd, HDC hDC, int nBar, LPRECT lprect, LPHEADSCROLL lphs)
387 HWND hWndParent;
388 HBRUSH hBrush;
389 HDC hMemDC;
390 BITMAP bm;
391 RECT rect;
392 UINT i, w, h, siz;
393 char C[128];
394 if (lphs == NULL) return;
395 #ifdef DEBUG_SCROLL
396 if (lphs->Direction == WM_VSCROLL)
397 printf("StdDrawScrollBar Vertical left=%d top=%d right=%d bottom=%d !\n",
398 lprect->left, lprect->top, lprect->right, lprect->bottom);
399 else
400 printf("StdDrawScrollBar Horizontal left=%d top=%d right=%d bottom=%d !\n",
401 lprect->left, lprect->top, lprect->right, lprect->bottom);
402 #endif
403 if (nBar == SB_CTL)
404 hWndParent = GetParent(hWnd);
405 else
406 hWndParent = lphs->hWndOwner;
407 hBrush = SendMessage(hWndParent, WM_CTLCOLOR, (WORD)hDC,
408 MAKELONG(hWnd, CTLCOLOR_SCROLLBAR));
409 if (hBrush == (HBRUSH)NULL) hBrush = GetStockObject(LTGRAY_BRUSH);
410 CopyRect(&lphs->rect, lprect);
411 CopyRect(&rect, lprect);
412 w = rect.right - rect.left;
413 h = rect.bottom - rect.top;
414 if (lphs->Direction == WM_VSCROLL)
415 lphs->MaxPix = h - 3 * w;
416 else
417 lphs->MaxPix = w - 3 * h;
418 if (lphs->MaxVal != lphs->MinVal)
419 lphs->CurPix = lphs->MaxPix * (abs((short)lphs->CurVal) - abs(lphs->MinVal)) /
420 (abs(lphs->MaxVal) - abs(lphs->MinVal));
421 if (lphs->CurPix > lphs->MaxPix) lphs->CurPix = lphs->MaxPix;
422 hMemDC = CreateCompatibleDC(hDC);
423 if (lphs->Direction == WM_VSCROLL) {
424 GetObject(hUpArrow, sizeof(BITMAP), (LPSTR)&bm);
425 if (lphs->ButtonDown == 1)
426 SelectObject(hMemDC, hUpArrowD);
427 else
428 SelectObject(hMemDC, hUpArrow);
429 StretchBlt(hDC, rect.left, rect.top, w, w, hMemDC,
430 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
431 GetObject(hDnArrow, sizeof(BITMAP), (LPSTR)&bm);
432 if (lphs->ButtonDown == 2)
433 SelectObject(hMemDC, hDnArrowD);
434 else
435 SelectObject(hMemDC, hDnArrow);
436 StretchBlt(hDC, rect.left, rect.bottom - w, w, w, hMemDC,
437 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
438 rect.top += w;
439 rect.bottom -= w;
441 else {
442 GetObject(hLfArrow, sizeof(BITMAP), (LPSTR)&bm);
443 if (lphs->ButtonDown == 3)
444 SelectObject(hMemDC, hLfArrowD);
445 else
446 SelectObject(hMemDC, hLfArrow);
447 StretchBlt(hDC, rect.left, rect.top, h, h, hMemDC,
448 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
449 GetObject(hRgArrow, sizeof(BITMAP), (LPSTR)&bm);
450 if (lphs->ButtonDown == 4)
451 SelectObject(hMemDC, hRgArrowD);
452 else
453 SelectObject(hMemDC, hRgArrow);
454 StretchBlt(hDC, rect.right - h, rect.top, h, h, hMemDC,
455 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
456 rect.left += h;
457 rect.right -= h;
459 DeleteDC(hMemDC);
460 FillRect(hDC, &rect, hBrush);
461 if (lphs->Direction == WM_VSCROLL)
462 SetRect(&rect, rect.left, rect.top + lphs->CurPix,
463 rect.left + w, rect.top + lphs->CurPix + w);
464 else
465 SetRect(&rect, rect.left + lphs->CurPix, rect.top,
466 rect.left + lphs->CurPix + h, rect.top + h);
468 if (lphs->Direction == WM_VSCROLL)
469 SetRect(&rect, rect.left, rect.top + lphs->CurPix + w,
470 rect.left + w, rect.top + lphs->CurPix + (w << 1));
471 else
472 SetRect(&rect, rect.left + lphs->CurPix + h, rect.top,
473 rect.left + lphs->CurPix + (h << 1), rect.top + h);
475 FrameRect(hDC, &rect, GetStockObject(BLACK_BRUSH));
476 InflateRect(&rect, -1, -1);
477 FillRect(hDC, &rect, GetStockObject(LTGRAY_BRUSH));
478 DrawReliefRect(hDC, rect, 2, 0);
479 InflateRect(&rect, -3, -3);
480 DrawReliefRect(hDC, rect, 1, 1);
485 int CreateScrollBarStruct(HWND hWnd)
487 RECT rect;
488 int width, height;
489 WND *wndPtr;
490 LPHEADSCROLL lphs;
491 wndPtr = WIN_FindWndPtr(hWnd);
492 width = wndPtr->rectClient.right - wndPtr->rectClient.left;
493 height = wndPtr->rectClient.bottom - wndPtr->rectClient.top;
494 if (width <= height)
495 lphs = AllocScrollBar(WS_VSCROLL, width, height);
496 else
497 lphs = AllocScrollBar(WS_HSCROLL, width, height);
498 #ifdef DEBUG_SCROLL
499 printf("CreateScrollBarStruct %lX !\n", lphs);
500 #endif
501 *((LPHEADSCROLL *)&wndPtr->wExtra[1]) = lphs;
502 lphs->hWndOwner = hWnd;
503 CopyRect(&lphs->rect, &wndPtr->rectClient);
504 return TRUE;
509 LPHEADSCROLL AllocScrollBar(DWORD dwStyle, int width, int height)
511 LPHEADSCROLL lphs;
512 if (hUpArrow == (HBITMAP)NULL)
513 hUpArrow = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_UPARROWI));
514 if (hDnArrow == (HBITMAP)NULL)
515 hDnArrow = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_DNARROWI));
516 if (hLfArrow == (HBITMAP)NULL)
517 hLfArrow = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_LFARROWI));
518 if (hRgArrow == (HBITMAP)NULL)
519 hRgArrow = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_RGARROWI));
520 if (hUpArrowD == (HBITMAP)NULL)
521 hUpArrowD = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_UPARROWD));
522 if (hDnArrowD == (HBITMAP)NULL)
523 hDnArrowD = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_DNARROWD));
524 if (hLfArrowD == (HBITMAP)NULL)
525 hLfArrowD = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_LFARROWD));
526 if (hRgArrowD == (HBITMAP)NULL)
527 hRgArrowD = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_RGARROWD));
528 lphs = (LPHEADSCROLL)malloc(sizeof(HEADSCROLL));
529 if (lphs == 0) {
530 printf("Bad Memory Alloc on ScrollBar !\n");
531 return NULL;
533 lphs->ThumbActive = FALSE;
534 lphs->TimerPending = FALSE;
535 lphs->ButtonDown = 0;
536 lphs->MinVal = 0;
537 lphs->MaxVal = 100;
538 lphs->CurVal = 0;
539 lphs->CurPix = 0;
540 if (dwStyle & WS_VSCROLL) {
541 lphs->MaxPix = height - 3 * width;
542 lphs->Direction = WM_VSCROLL;
544 else {
545 lphs->MaxPix = width - 3 * height;
546 lphs->Direction = WM_HSCROLL;
548 if (lphs->MaxPix < 1) lphs->MaxPix = 1;
549 return lphs;
553 void NC_CreateScrollBars(HWND hWnd)
555 RECT rect;
556 int width, height;
557 WND *wndPtr;
558 LPHEADSCROLL lphs;
559 wndPtr = WIN_FindWndPtr(hWnd);
560 width = wndPtr->rectClient.right - wndPtr->rectClient.left;
561 height = wndPtr->rectClient.bottom - wndPtr->rectClient.top;
562 if (wndPtr->dwStyle & WS_VSCROLL) {
563 if (wndPtr->dwStyle & WS_HSCROLL) height -= SYSMETRICS_CYHSCROLL;
564 lphs = AllocScrollBar(WS_VSCROLL, SYSMETRICS_CXVSCROLL, height);
565 #ifdef DEBUG_SCROLL
566 printf("NC_CreateScrollBars Vertical %lX !\n", lphs);
567 #endif
568 lphs->hWndOwner = hWnd;
569 wndPtr->VScroll = lphs;
571 if (wndPtr->dwStyle & WS_HSCROLL) {
572 if (wndPtr->dwStyle & WS_VSCROLL) width -= SYSMETRICS_CYVSCROLL;
573 lphs = AllocScrollBar(WS_HSCROLL, width, SYSMETRICS_CYHSCROLL);
574 #ifdef DEBUG_SCROLL
575 printf("NC_CreateScrollBars Horizontal %lX !\n", lphs);
576 #endif
577 lphs->hWndOwner = hWnd;
578 wndPtr->HScroll = lphs;
583 /*************************************************************************
584 * GetScrollObjectStruct [internal]
586 LPHEADSCROLL GetScrollObjectStruct(HWND hWnd, int nBar)
588 WND *wndPtr;
589 if (nBar != SB_CTL) {
590 wndPtr = WIN_FindWndPtr(hWnd);
591 if (nBar == SB_VERT) return (LPHEADSCROLL)wndPtr->VScroll;
592 if (nBar == SB_HORZ) return (LPHEADSCROLL)wndPtr->HScroll;
593 return NULL;
595 return ScrollBarGetStorageHeader(hWnd);
599 /*************************************************************************
600 * SetScrollPos [USER.62]
602 int SetScrollPos(HWND hWnd, int nBar, int nPos, BOOL bRedraw)
604 LPHEADSCROLL lphs;
605 HDC hDC;
606 int nRet;
607 lphs = GetScrollObjectStruct(hWnd, nBar);
608 if (lphs == NULL) return 0;
609 nRet = lphs->CurVal;
610 lphs->CurVal = (short)nPos;
611 if (lphs->MaxVal != lphs->MinVal)
612 lphs->CurPix = lphs->MaxPix * (abs((short)nPos) - abs(lphs->MinVal)) /
613 (abs(lphs->MaxVal) - abs(lphs->MinVal));
614 if (lphs->CurPix > lphs->MaxPix) lphs->CurPix = lphs->MaxPix;
615 #ifdef DEBUG_SCROLL
616 printf("SetScrollPos val=%d pixval=%d pixmax%d\n",
617 (short)nPos, lphs->CurPix, lphs->MaxPix);
618 printf("SetScrollPos min=%d max=%d\n",
619 lphs->MinVal, lphs->MaxVal);
620 #endif
621 if ((bRedraw) && (IsWindowVisible(lphs->hWndOwner))) {
622 if (nBar == SB_CTL) {
623 InvalidateRect(lphs->hWndOwner, &lphs->rect, TRUE);
624 UpdateWindow(lphs->hWndOwner);
626 else {
627 if (lphs->rect.right != 0 && lphs->rect.bottom != 0) {
628 hDC = GetWindowDC(lphs->hWndOwner);
629 StdDrawScrollBar(lphs->hWndOwner, hDC, nBar, &lphs->rect, lphs);
630 ReleaseDC(lphs->hWndOwner, hDC);
634 return nRet;
639 /*************************************************************************
640 * GetScrollPos [USER.63]
642 int GetScrollPos(HWND hWnd, int nBar)
644 LPHEADSCROLL lphs;
645 lphs = GetScrollObjectStruct(hWnd, nBar);
646 if (lphs == NULL) return 0;
647 return lphs->CurVal;
652 /*************************************************************************
653 * SetScrollRange [USER.64]
655 void SetScrollRange(HWND hWnd, int nBar, int MinPos, int MaxPos, BOOL bRedraw)
657 LPHEADSCROLL lphs;
658 HDC hDC;
659 lphs = GetScrollObjectStruct(hWnd, nBar);
660 if (lphs == NULL) return;
661 lphs->MinVal = (short)MinPos;
662 lphs->MaxVal = (short)MaxPos;
663 if (lphs->MaxVal != lphs->MinVal)
664 lphs->CurPix = abs(lphs->MaxVal) *
665 (abs(lphs->CurVal) - abs(lphs->MinVal)) /
666 (abs(lphs->MaxVal) - abs(lphs->MinVal));
667 if (lphs->CurPix > lphs->MaxPix) lphs->CurPix = lphs->MaxPix;
668 #ifdef DEBUG_SCROLL
669 printf("SetScrollRange min=%d max=%d\n", lphs->MinVal, lphs->MaxVal);
670 #endif
671 if ((bRedraw) && (IsWindowVisible(lphs->hWndOwner))) {
672 if (nBar == SB_CTL) {
673 InvalidateRect(lphs->hWndOwner, &lphs->rect, TRUE);
674 UpdateWindow(lphs->hWndOwner);
676 else {
677 if (lphs->rect.right != 0 && lphs->rect.bottom != 0) {
678 hDC = GetWindowDC(lphs->hWndOwner);
679 StdDrawScrollBar(lphs->hWndOwner, hDC, nBar, &lphs->rect, lphs);
680 ReleaseDC(lphs->hWndOwner, hDC);
688 /*************************************************************************
689 * GetScrollRange [USER.65]
691 void GetScrollRange(HWND hWnd, int nBar, LPINT lpMin, LPINT lpMax)
693 LPHEADSCROLL lphs;
694 lphs = GetScrollObjectStruct(hWnd, nBar);
695 if (lphs == NULL) return;
696 *lpMin = lphs->MinVal;
697 *lpMax = lphs->MaxVal;
702 /*************************************************************************
703 * ShowScrollBar [USER.267]
705 void ShowScrollBar(HWND hWnd, WORD wBar, BOOL bFlag)
707 WND *wndPtr;
708 #ifdef DEBUG_SCROLL
709 printf("ShowScrollBar hWnd=%04X wBar=%d bFlag=%d\n", hWnd, wBar, bFlag);
710 #endif
711 if (wBar == SB_CTL) {
712 if (bFlag)
713 ShowWindow(hWnd, SW_SHOW);
714 else
715 ShowWindow(hWnd, SW_HIDE);
716 return;
718 wndPtr = WIN_FindWndPtr(hWnd);
720 if ((wBar == SB_VERT) || (wBar == SB_BOTH)) {
721 if (bFlag)
722 wndPtr->dwStyle |= WS_VSCROLL;
723 else
724 wndPtr->dwStyle &= 0xFFFFFFFFL ^ WS_VSCROLL;
726 if ((wBar == SB_HORZ) || (wBar == SB_BOTH)) {
727 if (bFlag)
728 wndPtr->dwStyle |= WS_HSCROLL;
729 else
730 wndPtr->dwStyle &= 0xFFFFFFFFL ^ WS_HSCROLL;