2 * Interface code to SCROLLBAR widget
4 * Copyright Martin Ayotte, 1993
5 * Copyright Alexandre Julliard, 1994
7 * Small fixes and implemented SB_THUMBPOSITION
8 * by Peter Broadhurst, 940611
13 #include <sys/types.h>
17 #include "sysmetrics.h"
23 /* #define DEBUG_SCROLL */
27 static HBITMAP hUpArrow = 0;
28 static HBITMAP hDnArrow = 0;
29 static HBITMAP hLfArrow = 0;
30 static HBITMAP hRgArrow = 0;
31 static HBITMAP hUpArrowD = 0;
32 static HBITMAP hDnArrowD = 0;
33 static HBITMAP hLfArrowD = 0;
34 static HBITMAP hRgArrowD = 0;
35 static HBITMAP hUpArrowI = 0;
36 static HBITMAP hDnArrowI = 0;
37 static HBITMAP hLfArrowI = 0;
38 static HBITMAP hRgArrowI = 0;
40 #define TOP_ARROW(flags,pressed) \
41 (((flags)&ESB_DISABLE_UP) ? hUpArrowI : ((pressed) ? hUpArrowD:hUpArrow))
42 #define BOTTOM_ARROW(flags,pressed) \
43 (((flags)&ESB_DISABLE_DOWN) ? hDnArrowI : ((pressed) ? hDnArrowD:hDnArrow))
44 #define LEFT_ARROW(flags,pressed) \
45 (((flags)&ESB_DISABLE_LEFT) ? hLfArrowI : ((pressed) ? hLfArrowD:hLfArrow))
46 #define RIGHT_ARROW(flags,pressed) \
47 (((flags)&ESB_DISABLE_RIGHT) ? hRgArrowI : ((pressed) ? hRgArrowD:hRgArrow))
50 /* Minimum size of the rectangle between the arrows */
51 #define SCROLL_MIN_RECT 4
53 /* Delay (in ms) before first repetition when holding the button down */
54 #define SCROLL_FIRST_DELAY 200
56 /* Delay (in ms) between scroll repetitions */
57 #define SCROLL_REPEAT_DELAY 100
60 #define SCROLL_TIMER 0
62 /* Scroll-bar hit testing */
65 SCROLL_NOWHERE, /* Outside the scroll bar */
66 SCROLL_TOP_ARROW, /* Top or left arrow */
67 SCROLL_TOP_RECT, /* Rectangle between the top arrow and the thumb */
68 SCROLL_THUMB, /* Thumb rectangle */
69 SCROLL_BOTTOM_RECT, /* Rectangle between the thumb and the bottom arrow */
70 SCROLL_BOTTOM_ARROW /* Bottom or right arrow */
73 /* Thumb-tracking info */
74 static HWND hwndTracking = 0;
75 static int nBarTracking = 0;
76 static UINT uTrackingPos = 0;
78 /***********************************************************************
81 static void SCROLL_LoadBitmaps(void)
83 hUpArrow = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_UPARROW));
84 hDnArrow = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_DNARROW));
85 hLfArrow = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_LFARROW));
86 hRgArrow = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_RGARROW));
87 hUpArrowD = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_UPARROWD));
88 hDnArrowD = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_DNARROWD));
89 hLfArrowD = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_LFARROWD));
90 hRgArrowD = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_RGARROWD));
91 hUpArrowI = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_UPARROWI));
92 hDnArrowI = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_DNARROWI));
93 hLfArrowI = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_LFARROWI));
94 hRgArrowI = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_RGARROWI));
97 /***********************************************************************
98 * SCROLL_GetPtrScrollInfo
100 static SCROLLINFO *SCROLL_GetPtrScrollInfo( WND* wndPtr, int nBar )
104 if (!wndPtr) return NULL;
107 case SB_HORZ: handle = wndPtr->hHScroll; break;
108 case SB_VERT: handle = wndPtr->hVScroll; break;
109 case SB_CTL: return (SCROLLINFO *)wndPtr->wExtra;
110 default: return NULL;
113 if (!handle) /* Create the info structure if needed */
115 if ((handle = USER_HEAP_ALLOC( sizeof(SCROLLINFO) )))
117 SCROLLINFO *infoPtr = (SCROLLINFO *) USER_HEAP_LIN_ADDR( handle );
118 infoPtr->MinVal = infoPtr->CurVal = 0;
119 infoPtr->MaxVal = 100;
120 infoPtr->flags = ESB_ENABLE_BOTH;
121 if (nBar == SB_HORZ) wndPtr->hHScroll = handle;
122 else wndPtr->hVScroll = handle;
124 if (!hUpArrow) SCROLL_LoadBitmaps();
126 return (SCROLLINFO *) USER_HEAP_LIN_ADDR( handle );
129 /***********************************************************************
130 * SCROLL_GetScrollInfo
132 static SCROLLINFO *SCROLL_GetScrollInfo( HWND hwnd, int nBar )
134 WND *wndPtr = WIN_FindWndPtr( hwnd );
135 return SCROLL_GetPtrScrollInfo( wndPtr, nBar );
139 /***********************************************************************
140 * SCROLL_GetScrollBarRect
142 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
143 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
144 * 'arrowSize' returns the width or height of an arrow (depending on the
145 * orientation of the scrollbar), and 'thumbPos' returns the position of
146 * the thumb relative to the left or to the top.
147 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
149 static BOOL SCROLL_GetScrollBarRect( HWND hwnd, int nBar, RECT16 *lprect,
150 WORD *arrowSize, WORD *thumbPos )
154 WND *wndPtr = WIN_FindWndPtr( hwnd );
159 lprect->left = wndPtr->rectClient.left - wndPtr->rectWindow.left - 1;
160 lprect->top = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
161 lprect->right = wndPtr->rectClient.right - wndPtr->rectWindow.left +1;
162 lprect->bottom = lprect->top + SYSMETRICS_CYHSCROLL + 1;
167 lprect->left = wndPtr->rectClient.right - wndPtr->rectWindow.left;
168 lprect->top = wndPtr->rectClient.top - wndPtr->rectWindow.top - 1;
169 lprect->right = lprect->left + SYSMETRICS_CXVSCROLL + 1;
170 lprect->bottom = wndPtr->rectClient.bottom - wndPtr->rectWindow.top +1;
175 GetClientRect16( hwnd, lprect );
176 vertical = ((wndPtr->dwStyle & SBS_VERT) != 0);
183 if (vertical) pixels = lprect->bottom - lprect->top;
184 else pixels = lprect->right - lprect->left;
186 if (pixels > 2*SYSMETRICS_CXVSCROLL + SCROLL_MIN_RECT)
188 *arrowSize = SYSMETRICS_CXVSCROLL;
190 else if (pixels > SCROLL_MIN_RECT)
192 *arrowSize = (pixels - SCROLL_MIN_RECT) / 2;
196 if ((pixels -= 3*SYSMETRICS_CXVSCROLL+1) > 0)
198 SCROLLINFO *info = SCROLL_GetPtrScrollInfo( wndPtr, nBar );
199 if ((info->flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH)
201 else if (info->MinVal == info->MaxVal)
202 *thumbPos = *arrowSize;
204 *thumbPos = *arrowSize + pixels * (info->CurVal - info->MinVal) /
205 (info->MaxVal - info->MinVal);
212 /***********************************************************************
215 * Compute the current scroll position based on the thumb position in pixels
216 * from the top of the scroll-bar.
218 static UINT SCROLL_GetThumbVal( SCROLLINFO *infoPtr, RECT16 *rect,
219 BOOL vertical, WORD pos )
221 int pixels = vertical ? rect->bottom-rect->top : rect->right-rect->left;
222 if ((pixels -= 3*SYSMETRICS_CXVSCROLL+1) <= 0) return infoPtr->MinVal;
223 pos = MAX( 0, pos - SYSMETRICS_CXVSCROLL );
224 if (pos > pixels) pos = pixels;
225 dprintf_scroll(stddeb,"GetThumbVal: pos=%d ret=%d\n", pos,
227 + (UINT)(((int)pos * (infoPtr->MaxVal-infoPtr->MinVal) + pixels/2)
229 return (infoPtr->MinVal
230 + (UINT)(((int)pos * (infoPtr->MaxVal-infoPtr->MinVal) + pixels/2)
235 /***********************************************************************
238 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
240 static enum SCROLL_HITTEST SCROLL_HitTest( HWND hwnd, int nBar, POINT16 pt )
242 WORD arrowSize, thumbPos;
245 BOOL vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
246 &arrowSize, &thumbPos );
247 if (!PtInRect16( &rect, pt )) return SCROLL_NOWHERE;
251 if (pt.y <= rect.top + arrowSize + 1) return SCROLL_TOP_ARROW;
252 if (pt.y >= rect.bottom - arrowSize) return SCROLL_BOTTOM_ARROW;
253 if (!thumbPos) return SCROLL_TOP_RECT;
255 if (pt.y < (INT)thumbPos) return SCROLL_TOP_RECT;
256 if (pt.y > thumbPos+SYSMETRICS_CYHSCROLL) return SCROLL_BOTTOM_RECT;
259 else /* horizontal */
261 if (pt.x <= rect.left + arrowSize) return SCROLL_TOP_ARROW;
262 if (pt.x >= rect.right - arrowSize) return SCROLL_BOTTOM_ARROW;
263 if (!thumbPos) return SCROLL_TOP_RECT;
265 if (pt.x < (INT)thumbPos) return SCROLL_TOP_RECT;
266 if (pt.x > thumbPos+SYSMETRICS_CXVSCROLL) return SCROLL_BOTTOM_RECT;
272 /***********************************************************************
275 * Draw the scroll bar arrows.
277 static void SCROLL_DrawArrows( HDC hdc, SCROLLINFO *infoPtr, RECT16 *rect,
278 WORD arrowSize, BOOL vertical,
279 BOOL top_pressed, BOOL bottom_pressed )
281 HDC hdcMem = CreateCompatibleDC( hdc );
282 HBITMAP hbmpPrev = SelectObject( hdcMem, vertical ?
283 TOP_ARROW(infoPtr->flags, top_pressed)
284 : LEFT_ARROW(infoPtr->flags, top_pressed));
285 SetStretchBltMode( hdc, STRETCH_DELETESCANS );
286 StretchBlt( hdc, rect->left, rect->top,
287 vertical ? rect->right-rect->left : arrowSize+1,
288 vertical ? arrowSize+1 : rect->bottom-rect->top,
290 SYSMETRICS_CXVSCROLL + 1, SYSMETRICS_CYHSCROLL + 1,
293 SelectObject( hdcMem, vertical ?
294 BOTTOM_ARROW( infoPtr->flags, bottom_pressed )
295 : RIGHT_ARROW( infoPtr->flags, bottom_pressed ) );
297 StretchBlt( hdc, rect->left, rect->bottom - arrowSize - 1,
298 rect->right - rect->left, arrowSize + 1,
300 SYSMETRICS_CXVSCROLL + 1, SYSMETRICS_CYHSCROLL + 1,
303 StretchBlt( hdc, rect->right - arrowSize - 1, rect->top,
304 arrowSize + 1, rect->bottom - rect->top,
306 SYSMETRICS_CXVSCROLL + 1, SYSMETRICS_CYHSCROLL + 1,
308 SelectObject( hdcMem, hbmpPrev );
313 /***********************************************************************
314 * SCROLL_DrawMovingThumb
316 * Draw the moving thumb rectangle.
318 static void SCROLL_DrawMovingThumb( HDC hdc, RECT16 *rect, BOOL vertical,
319 WORD arrowSize, WORD thumbPos )
325 if (r.top < rect->top + arrowSize) r.top = rect->top + arrowSize;
326 if (r.top + SYSMETRICS_CYHSCROLL >= rect->bottom - arrowSize)
327 r.top = rect->bottom - arrowSize - SYSMETRICS_CYHSCROLL - 1;
328 r.bottom = r.top + SYSMETRICS_CYHSCROLL + 1;
333 if (r.left < rect->left + arrowSize) r.left = rect->left + arrowSize;
334 if (r.left + SYSMETRICS_CXVSCROLL >= rect->right - arrowSize)
335 r.left = rect->right - arrowSize - SYSMETRICS_CXVSCROLL - 1;
336 r.right = r.left + SYSMETRICS_CXVSCROLL + 1;
338 InflateRect16( &r, -1, -1 );
339 DrawFocusRect16( hdc, &r );
343 /***********************************************************************
344 * SCROLL_DrawInterior
346 * Draw the scroll bar interior (everything except the arrows).
348 static void SCROLL_DrawInterior( HWND hwnd, HDC hdc, int nBar, RECT16 *rect,
349 WORD arrowSize, WORD thumbPos, WORD flags,
350 BOOL vertical, BOOL top_selected,
351 BOOL bottom_selected )
355 /* Select the correct brush and pen */
357 SelectObject( hdc, sysColorObjects.hpenWindowFrame );
358 if ((flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH)
360 /* This ought to be the color of the parent window */
361 SelectObject( hdc, sysColorObjects.hbrushWindow );
365 if (nBar == SB_CTL) /* Only scrollbar controls send WM_CTLCOLOR */
368 HBRUSH hbrush = SendMessage( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
371 HBRUSH hbrush = SendMessage( GetParent(hwnd), WM_CTLCOLOR, hdc,
372 MAKELONG(hwnd, CTLCOLOR_SCROLLBAR) );
374 SelectObject( hdc, hbrush );
376 else SelectObject( hdc, sysColorObjects.hbrushScrollbar );
379 /* Calculate the scroll rectangle */
385 r.bottom -= arrowSize;
390 r.right -= arrowSize;
393 /* Draw the scroll bar frame */
395 MoveTo( hdc, r.left, r.top );
396 LineTo( hdc, r.right-1, r.top );
397 LineTo( hdc, r.right-1, r.bottom-1 );
398 LineTo( hdc, r.left, r.bottom-1 );
399 LineTo( hdc, r.left, r.top );
401 /* Draw the scroll rectangles and thumb */
403 if (!thumbPos) /* No thumb to draw */
405 PatBlt( hdc, r.left+1, r.top+1, r.right - r.left - 2,
406 r.bottom - r.top - 2, PATCOPY );
412 PatBlt( hdc, r.left + 1, r.top + 1,
413 r.right - r.left - 2,
414 thumbPos - arrowSize,
415 top_selected ? 0x0f0000 : PATCOPY );
416 r.top += thumbPos - arrowSize;
417 PatBlt( hdc, r.left + 1, r.top + SYSMETRICS_CYHSCROLL + 1,
418 r.right - r.left - 2,
419 r.bottom - r.top - SYSMETRICS_CYHSCROLL - 2,
420 bottom_selected ? 0x0f0000 : PATCOPY );
421 r.bottom = r.top + SYSMETRICS_CYHSCROLL + 1;
423 else /* horizontal */
425 PatBlt( hdc, r.left + 1, r.top + 1,
426 thumbPos - arrowSize,
427 r.bottom - r.top - 2,
428 top_selected ? 0x0f0000 : PATCOPY );
429 r.left += thumbPos - arrowSize;
430 PatBlt( hdc, r.left + SYSMETRICS_CYHSCROLL + 1, r.top + 1,
431 r.right - r.left - SYSMETRICS_CYHSCROLL - 2,
432 r.bottom - r.top - 2,
433 bottom_selected ? 0x0f0000 : PATCOPY );
434 r.right = r.left + SYSMETRICS_CXVSCROLL + 1;
439 SelectObject( hdc, sysColorObjects.hbrushBtnFace );
440 Rectangle( hdc, r.left, r.top, r.right, r.bottom );
441 InflateRect16( &r, -1, -1 );
442 GRAPH_DrawReliefRect( hdc, &r, 1, 2, FALSE );
443 if ((hwndTracking == hwnd) && (nBarTracking == nBar))
444 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, uTrackingPos);
448 /***********************************************************************
449 * SCROLL_DrawScrollBar
451 * Redraw the whole scrollbar.
453 void SCROLL_DrawScrollBar( HWND hwnd, HDC hdc, int nBar )
455 WORD arrowSize, thumbPos;
458 WND *wndPtr = WIN_FindWndPtr( hwnd );
459 SCROLLINFO *infoPtr = SCROLL_GetPtrScrollInfo( wndPtr, nBar );
461 if (!wndPtr || !infoPtr ||
462 ((nBar == SB_VERT) && !(wndPtr->dwStyle & WS_VSCROLL)) ||
463 ((nBar == SB_HORZ) && !(wndPtr->dwStyle & WS_HSCROLL))) return;
465 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
466 &arrowSize, &thumbPos );
467 /* Draw the arrows */
469 if (arrowSize) SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize,
470 vertical, FALSE, FALSE );
472 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbPos,
473 infoPtr->flags, vertical, FALSE, FALSE );
477 /***********************************************************************
478 * SCROLL_RefreshScrollBar
480 * Repaint the scroll bar interior after a SetScrollRange() or
481 * SetScrollPos() call.
483 static void SCROLL_RefreshScrollBar( HWND hwnd, int nBar )
485 WORD arrowSize, thumbPos;
489 WND *wndPtr = WIN_FindWndPtr( hwnd );
490 SCROLLINFO *infoPtr = SCROLL_GetPtrScrollInfo( wndPtr, nBar );
492 if (!wndPtr || !infoPtr ||
493 ((nBar == SB_VERT) && !(wndPtr->dwStyle & WS_VSCROLL)) ||
494 ((nBar == SB_HORZ) && !(wndPtr->dwStyle & WS_HSCROLL))) return;
496 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
497 &arrowSize, &thumbPos );
498 hdc = (nBar == SB_CTL) ? GetDC(hwnd) : GetWindowDC(hwnd);
500 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbPos,
501 infoPtr->flags, vertical, FALSE, FALSE );
502 ReleaseDC( hwnd, hdc );
506 /***********************************************************************
507 * SCROLL_HandleKbdEvent
509 * Handle a keyboard event (only for SB_CTL scrollbars).
511 static void SCROLL_HandleKbdEvent( HWND hwnd, WORD wParam )
513 WND *wndPtr = WIN_FindWndPtr( hwnd );
518 case VK_PRIOR: msg = SB_PAGEUP; break;
519 case VK_NEXT: msg = SB_PAGEDOWN; break;
520 case VK_HOME: msg = SB_TOP; break;
521 case VK_END: msg = SB_BOTTOM; break;
522 case VK_UP: msg = SB_LINEUP; break;
523 case VK_DOWN: msg = SB_LINEDOWN; break;
528 SendMessage( GetParent(hwnd),
529 (wndPtr->dwStyle & SBS_VERT) ? WM_VSCROLL : WM_HSCROLL,
532 SendMessage( GetParent(hwnd),
533 (wndPtr->dwStyle & SBS_VERT) ? WM_VSCROLL : WM_HSCROLL,
534 msg, MAKELONG( 0, hwnd ));
539 /***********************************************************************
540 * SCROLL_HandleScrollEvent
542 * Handle a mouse or timer event for the scrollbar.
543 * 'pt' is the location of the mouse event in client (for SB_CTL) or
544 * windows coordinates.
546 void SCROLL_HandleScrollEvent( HWND hwnd, int nBar, WORD msg, POINT16 pt )
548 /* Previous mouse position for timer events */
549 static POINT16 prevPt;
550 /* Hit test code of the last button-down event */
551 static enum SCROLL_HITTEST trackHitTest;
552 /* Thumb position when tracking started. */
553 static UINT trackThumbPos;
554 /* Position in the scroll-bar of the last button-down event. */
555 static int lastClickPos;
556 /* Position in the scroll-bar of the last mouse event. */
557 static int lastMousePos;
559 enum SCROLL_HITTEST hittest;
560 HWND hwndOwner, hwndCtl;
562 WORD arrowSize, thumbPos;
566 SCROLLINFO *infoPtr = SCROLL_GetScrollInfo( hwnd, nBar );
567 if (!infoPtr) return;
568 if ((trackHitTest == SCROLL_NOWHERE) && (msg != WM_LBUTTONDOWN)) return;
570 hdc = (nBar == SB_CTL) ? GetDC(hwnd) : GetWindowDC(hwnd);
571 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
572 &arrowSize, &thumbPos );
573 hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd) : hwnd;
574 hwndCtl = (nBar == SB_CTL) ? hwnd : 0;
578 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
579 trackHitTest = hittest = SCROLL_HitTest( hwnd, nBar, pt );
580 lastClickPos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
581 lastMousePos = lastClickPos;
582 trackThumbPos = thumbPos;
585 if (nBar == SB_CTL) SetFocus( hwnd );
589 hittest = SCROLL_HitTest( hwnd, nBar, pt );
594 hittest = SCROLL_NOWHERE;
600 hittest = SCROLL_HitTest( hwnd, nBar, pt );
604 return; /* Should never happen */
607 dprintf_scroll( stddeb, "ScrollBar Event: hwnd=%04x bar=%d msg=%x pt=%d,%d hit=%d\n",
608 hwnd, nBar, msg, pt.x, pt.y, hittest );
612 case SCROLL_NOWHERE: /* No tracking in progress */
615 case SCROLL_TOP_ARROW:
616 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
617 (hittest == trackHitTest), FALSE );
618 if (hittest == trackHitTest)
620 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
623 SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
624 SB_LINEUP, hwndCtl );
626 SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
627 SB_LINEUP, MAKELONG( 0, hwndCtl ));
629 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
630 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
634 else KillSystemTimer( hwnd, SCROLL_TIMER );
637 case SCROLL_TOP_RECT:
638 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbPos,
639 infoPtr->flags, vertical,
640 (hittest == trackHitTest), FALSE );
641 if (hittest == trackHitTest)
643 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
646 SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
647 SB_PAGEUP, hwndCtl );
649 SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
650 SB_PAGEUP, MAKELONG( 0, hwndCtl ));
652 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
653 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
657 else KillSystemTimer( hwnd, SCROLL_TIMER );
661 if (msg == WM_LBUTTONDOWN)
663 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize,
664 trackThumbPos + lastMousePos - lastClickPos );
668 else if (msg == WM_LBUTTONUP)
671 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbPos,
672 infoPtr->flags, vertical, FALSE, FALSE );
674 else /* WM_MOUSEMOVE */
678 if (!PtInRect16( &rect, pt )) pos = lastClickPos;
679 else pos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
680 if (pos != lastMousePos)
682 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize,
683 trackThumbPos + lastMousePos - lastClickPos );
685 val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
686 trackThumbPos + lastMousePos - lastClickPos );
687 /* Save tracking info */
688 uTrackingPos = trackThumbPos + pos - lastClickPos;
690 SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
691 MAKEWPARAM(SB_THUMBTRACK,val), hwndCtl );
693 SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
694 SB_THUMBTRACK, MAKELONG( val, hwndCtl ));
696 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
697 arrowSize, uTrackingPos );
702 case SCROLL_BOTTOM_RECT:
703 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbPos,
704 infoPtr->flags, vertical,
705 FALSE, (hittest == trackHitTest) );
706 if (hittest == trackHitTest)
708 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
711 SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
712 SB_PAGEDOWN, hwndCtl );
714 SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
715 SB_PAGEDOWN, MAKELONG( 0, hwndCtl ));
717 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
718 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
722 else KillSystemTimer( hwnd, SCROLL_TIMER );
725 case SCROLL_BOTTOM_ARROW:
726 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
727 FALSE, (hittest == trackHitTest) );
728 if (hittest == trackHitTest)
730 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
733 SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
734 SB_LINEDOWN, hwndCtl );
736 SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
737 SB_LINEDOWN, MAKELONG( 0, hwndCtl ));
739 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
740 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
744 else KillSystemTimer( hwnd, SCROLL_TIMER );
748 if (msg == WM_LBUTTONUP)
750 if (trackHitTest == SCROLL_THUMB)
752 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
753 trackThumbPos + lastMousePos - lastClickPos );
755 SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
756 MAKEWPARAM(SB_THUMBPOSITION,val), hwndCtl );
758 SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
759 SB_THUMBPOSITION, MAKELONG( val, hwndCtl ) );
764 SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
765 SB_ENDSCROLL, hwndCtl );
767 SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
768 SB_ENDSCROLL, MAKELONG( 0, hwndCtl ) );
770 trackHitTest = SCROLL_NOWHERE; /* Terminate tracking */
773 ReleaseDC( hwnd, hdc );
777 /***********************************************************************
780 LONG ScrollBarWndProc( HWND hwnd, WORD message, WORD wParam, LONG lParam )
786 CREATESTRUCT16 *lpCreat = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam);
787 if (lpCreat->style & SBS_SIZEBOX)
789 fprintf( stdnimp, "Unimplemented style SBS_SIZEBOX.\n" );
790 return 0; /* FIXME */
793 if (lpCreat->style & SBS_VERT)
795 if (lpCreat->style & SBS_LEFTALIGN)
796 MoveWindow( hwnd, lpCreat->x, lpCreat->y,
797 SYSMETRICS_CXVSCROLL+1, lpCreat->cy, FALSE );
798 else if (lpCreat->style & SBS_RIGHTALIGN)
800 lpCreat->x+lpCreat->cx-SYSMETRICS_CXVSCROLL-1,
802 SYSMETRICS_CXVSCROLL + 1, lpCreat->cy, FALSE );
806 if (lpCreat->style & SBS_TOPALIGN)
807 MoveWindow( hwnd, lpCreat->x, lpCreat->y,
808 lpCreat->cx, SYSMETRICS_CYHSCROLL+1, FALSE );
809 else if (lpCreat->style & SBS_BOTTOMALIGN)
812 lpCreat->y+lpCreat->cy-SYSMETRICS_CYHSCROLL-1,
813 lpCreat->cx, SYSMETRICS_CYHSCROLL+1, FALSE );
816 if (!hUpArrow) SCROLL_LoadBitmaps();
817 dprintf_scroll( stddeb, "ScrollBar creation, hwnd=%04x\n", hwnd );
824 SCROLL_HandleScrollEvent( hwnd, SB_CTL, message, MAKEPOINT16(lParam) );
828 SCROLL_HandleKbdEvent( hwnd, wParam );
835 return DLGC_WANTARROWS; /* Windows returns this value */
840 HDC16 hdc = BeginPaint16( hwnd, &ps );
841 SCROLL_DrawScrollBar( hwnd, hdc, SB_CTL );
842 EndPaint16( hwnd, &ps );
846 case 0x400: /* SB_SETSCROLLPOS */
847 case 0x401: /* SB_GETSCROLLPOS */
848 case 0x402: /* SB_GETSCROLLRANGE */
849 case 0x403: /* SB_ENABLE */
850 case 0x404: /* SB_REDRAW */
851 fprintf(stdnimp,"ScrollBarWndProc: undocumented message %04x, please report\n", message );
854 return DefWindowProc( hwnd, message, wParam, lParam );
860 /*************************************************************************
861 * SetScrollPos (USER.62)
863 int SetScrollPos( HWND hwnd, int nBar, int nPos, BOOL bRedraw )
868 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return 0;
870 dprintf_scroll( stddeb,"SetScrollPos min=%d max=%d pos=%d\n",
871 infoPtr->MinVal, infoPtr->MaxVal, nPos );
873 if (nPos < infoPtr->MinVal) nPos = infoPtr->MinVal;
874 else if (nPos > infoPtr->MaxVal) nPos = infoPtr->MaxVal;
875 oldPos = infoPtr->CurVal;
876 infoPtr->CurVal = nPos;
877 if (bRedraw) SCROLL_RefreshScrollBar( hwnd, nBar );
882 /*************************************************************************
883 * GetScrollPos (USER.63)
885 int GetScrollPos( HWND hwnd, int nBar )
889 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return 0;
890 return infoPtr->CurVal;
894 /*************************************************************************
895 * SetScrollRange (USER.64)
897 void SetScrollRange(HWND hwnd, int nBar, int MinVal, int MaxVal, BOOL bRedraw)
901 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return;
903 dprintf_scroll( stddeb,"SetScrollRange hwnd=%04x bar=%d min=%d max=%d\n",
904 hwnd, nBar, MinVal, MaxVal );
906 /* Invalid range -> range is set to (0,0) */
907 if ((MinVal > MaxVal) || ((long)MaxVal - MinVal > 32767L))
909 if (infoPtr->CurVal < MinVal) infoPtr->CurVal = MinVal;
910 else if (infoPtr->CurVal > MaxVal) infoPtr->CurVal = MaxVal;
911 infoPtr->MinVal = MinVal;
912 infoPtr->MaxVal = MaxVal;
914 /* Non-client scroll-bar is hidden if min==max */
915 if (nBar != SB_CTL) ShowScrollBar( hwnd, nBar, (MinVal != MaxVal) );
916 if (bRedraw) SCROLL_RefreshScrollBar( hwnd, nBar );
919 /*************************************************************************
920 * SCROLL_SetNCSbState
922 * This is for CalcChildScroll in windows/mdi.c
924 DWORD SCROLL_SetNCSbState(WND* wndPtr, int vMin, int vMax, int vPos,
925 int hMin, int hMax, int hPos)
927 SCROLLINFO *infoPtr = SCROLL_GetPtrScrollInfo(wndPtr, SB_VERT);
929 wndPtr->dwStyle |= (WS_VSCROLL | WS_HSCROLL);
933 wndPtr->dwStyle &= ~WS_VSCROLL; }
934 if( vPos > vMax ) vPos = vMax; else if( vPos < vMin ) vPos = vMin;
935 infoPtr->MinVal = vMin;
936 infoPtr->MaxVal = vMax;
937 infoPtr->CurVal = vPos;
939 infoPtr = SCROLL_GetPtrScrollInfo(wndPtr, SB_HORZ);
943 wndPtr->dwStyle &= ~WS_HSCROLL; }
944 if( hPos > hMax ) hPos = hMax; else if( hPos < hMin ) hPos = hMin;
945 infoPtr->MinVal = hMin;
946 infoPtr->MaxVal = hMax;
947 infoPtr->CurVal = hPos;
949 return wndPtr->dwStyle & (WS_VSCROLL | WS_HSCROLL);
952 /*************************************************************************
953 * GetScrollRange (USER.65)
955 void GetScrollRange(HWND hwnd, int nBar, LPINT16 lpMin, LPINT16 lpMax)
959 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return;
960 if (lpMin) *lpMin = infoPtr->MinVal;
961 if (lpMax) *lpMax = infoPtr->MaxVal;
965 /*************************************************************************
966 * ShowScrollBar (USER.267)
968 void ShowScrollBar( HWND hwnd, WORD wBar, BOOL fShow )
970 WND *wndPtr = WIN_FindWndPtr( hwnd );
973 dprintf_scroll( stddeb, "ShowScrollBar: hwnd=%04x bar=%d on=%d\n", hwnd, wBar, fShow );
978 ShowWindow( hwnd, fShow ? SW_SHOW : SW_HIDE );
984 if (wndPtr->dwStyle & WS_HSCROLL) return;
985 wndPtr->dwStyle |= WS_HSCROLL;
989 if (!(wndPtr->dwStyle & WS_HSCROLL)) return;
990 wndPtr->dwStyle &= ~WS_HSCROLL;
997 if (wndPtr->dwStyle & WS_VSCROLL) return;
998 wndPtr->dwStyle |= WS_VSCROLL;
1002 if (!(wndPtr->dwStyle & WS_VSCROLL)) return;
1003 wndPtr->dwStyle &= ~WS_VSCROLL;
1010 if ((wndPtr->dwStyle & WS_HSCROLL)
1011 && (wndPtr->dwStyle & WS_VSCROLL)) return;
1012 wndPtr->dwStyle |= WS_HSCROLL | WS_VSCROLL;
1016 if (!(wndPtr->dwStyle & WS_HSCROLL)
1017 && !(wndPtr->dwStyle & WS_HSCROLL)) return;
1018 wndPtr->dwStyle &= ~(WS_HSCROLL | WS_VSCROLL);
1023 return; /* Nothing to do! */
1025 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
1026 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
1030 /*************************************************************************
1031 * EnableScrollBar (USER.482)
1033 BOOL EnableScrollBar( HWND hwnd, UINT nBar, UINT flags )
1035 SCROLLINFO *infoPtr;
1038 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return FALSE;
1039 dprintf_scroll( stddeb, "EnableScrollBar: %04x %d %d\n", hwnd, nBar, flags );
1040 flags &= ESB_DISABLE_BOTH;
1041 if (infoPtr->flags == flags) return FALSE;
1042 infoPtr->flags = flags;
1044 /* Redraw the whole scroll bar */
1045 hdc = (nBar == SB_CTL) ? GetDC(hwnd) : GetWindowDC(hwnd);
1046 SCROLL_DrawScrollBar( hwnd, hdc, nBar );
1047 ReleaseDC( hwnd, hdc );