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 */
74 /***********************************************************************
77 static void SCROLL_LoadBitmaps(void)
79 hUpArrow = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_UPARROW));
80 hDnArrow = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_DNARROW));
81 hLfArrow = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_LFARROW));
82 hRgArrow = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_RGARROW));
83 hUpArrowD = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_UPARROWD));
84 hDnArrowD = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_DNARROWD));
85 hLfArrowD = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_LFARROWD));
86 hRgArrowD = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_RGARROWD));
87 hUpArrowI = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_UPARROWI));
88 hDnArrowI = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_DNARROWI));
89 hLfArrowI = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_LFARROWI));
90 hRgArrowI = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_RGARROWI));
94 /***********************************************************************
95 * SCROLL_GetScrollInfo
97 static SCROLLINFO *SCROLL_GetScrollInfo( HWND hwnd, int nBar )
100 WND *wndPtr = WIN_FindWndPtr( hwnd );
104 case SB_HORZ: handle = wndPtr->hHScroll; break;
105 case SB_VERT: handle = wndPtr->hVScroll; break;
106 case SB_CTL: return (SCROLLINFO *)wndPtr->wExtra;
107 default: return NULL;
110 if (!handle) /* Create the info structure if needed */
112 if ((handle = USER_HEAP_ALLOC( GMEM_MOVEABLE, sizeof(SCROLLINFO) )))
114 SCROLLINFO *infoPtr = (SCROLLINFO *) USER_HEAP_ADDR( handle );
115 infoPtr->MinVal = infoPtr->CurVal = 0;
116 infoPtr->MaxVal = 100;
117 infoPtr->flags = ESB_ENABLE_BOTH;
118 if (nBar == SB_HORZ) wndPtr->hHScroll = handle;
119 else wndPtr->hVScroll = handle;
121 if (!hUpArrow) SCROLL_LoadBitmaps();
123 return (SCROLLINFO *) USER_HEAP_ADDR( handle );
127 /***********************************************************************
128 * SCROLL_GetScrollBarRect
130 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
131 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
132 * 'arrowSize' returns the width or height of an arrow (depending on the
133 * orientation of the scrollbar), and 'thumbPos' returns the position of
134 * the thumb relative to the left or to the top.
135 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
137 static BOOL SCROLL_GetScrollBarRect( HWND hwnd, int nBar, RECT *lprect,
138 WORD *arrowSize, WORD *thumbPos )
142 WND *wndPtr = WIN_FindWndPtr( hwnd );
147 lprect->left = wndPtr->rectClient.left - wndPtr->rectWindow.left - 1;
148 lprect->top = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
149 lprect->right = wndPtr->rectClient.right - wndPtr->rectWindow.left +1;
150 lprect->bottom = lprect->top + SYSMETRICS_CYHSCROLL + 1;
155 lprect->left = wndPtr->rectClient.right - wndPtr->rectWindow.left;
156 lprect->top = wndPtr->rectClient.top - wndPtr->rectWindow.top - 1;
157 lprect->right = lprect->left + SYSMETRICS_CXVSCROLL + 1;
158 lprect->bottom = wndPtr->rectClient.bottom - wndPtr->rectWindow.top +1;
163 GetClientRect( hwnd, lprect );
164 vertical = ((wndPtr->dwStyle & SBS_VERT) != 0);
171 if (vertical) pixels = lprect->bottom - lprect->top;
172 else pixels = lprect->right - lprect->left;
174 if (pixels > 2*SYSMETRICS_CXVSCROLL + SCROLL_MIN_RECT)
176 *arrowSize = SYSMETRICS_CXVSCROLL;
178 else if (pixels > SCROLL_MIN_RECT)
180 *arrowSize = (pixels - SCROLL_MIN_RECT) / 2;
184 if ((pixels -= 3*SYSMETRICS_CXVSCROLL+1) > 0)
186 SCROLLINFO *info = SCROLL_GetScrollInfo( hwnd, nBar );
187 if ((info->flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH)
189 else if (info->MinVal == info->MaxVal)
190 *thumbPos = *arrowSize;
192 *thumbPos = *arrowSize + pixels * (info->CurVal - info->MinVal) /
193 (info->MaxVal - info->MinVal);
200 /***********************************************************************
203 * Compute the current scroll position based on the thumb position in pixels
204 * from the top of the scroll-bar.
206 static UINT SCROLL_GetThumbVal( SCROLLINFO *infoPtr, RECT *rect,
207 WORD arrowSize, BOOL vertical, WORD pos )
209 int pixels = vertical ? rect->bottom-rect->top : rect->right-rect->left;
210 if ((pixels -= 3*SYSMETRICS_CXVSCROLL+1) <= 0) return infoPtr->MinVal;
211 pos = max( 0, pos - SYSMETRICS_CXVSCROLL );
212 if (pos > pixels) pos = pixels;
213 dprintf_scroll(stddeb,"GetThumbVal: pos=%d ret=%d\n", pos,
215 + (UINT)(((int)pos * (infoPtr->MaxVal-infoPtr->MinVal) + pixels/2)
217 return (infoPtr->MinVal
218 + (UINT)(((int)pos * (infoPtr->MaxVal-infoPtr->MinVal) + pixels/2)
223 /***********************************************************************
226 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
228 static enum SCROLL_HITTEST SCROLL_HitTest( HWND hwnd, int nBar, POINT pt )
230 WORD arrowSize, thumbPos;
233 BOOL vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
234 &arrowSize, &thumbPos );
235 if (!PtInRect( &rect, pt )) return SCROLL_NOWHERE;
239 if (pt.y <= rect.top + arrowSize + 1) return SCROLL_TOP_ARROW;
240 if (pt.y >= rect.bottom - arrowSize) return SCROLL_BOTTOM_ARROW;
241 if (!thumbPos) return SCROLL_TOP_RECT;
243 if (pt.y < (INT)thumbPos) return SCROLL_TOP_RECT;
244 if (pt.y > thumbPos+SYSMETRICS_CYHSCROLL) return SCROLL_BOTTOM_RECT;
247 else /* horizontal */
249 if (pt.x <= rect.left + arrowSize) return SCROLL_TOP_ARROW;
250 if (pt.x >= rect.right - arrowSize) return SCROLL_BOTTOM_ARROW;
251 if (!thumbPos) return SCROLL_TOP_RECT;
253 if (pt.x < (INT)thumbPos) return SCROLL_TOP_RECT;
254 if (pt.x > thumbPos+SYSMETRICS_CXVSCROLL) return SCROLL_BOTTOM_RECT;
260 /***********************************************************************
263 * Draw the scroll bar arrows.
265 static void SCROLL_DrawArrows( HDC hdc, SCROLLINFO *infoPtr, RECT *rect,
266 WORD arrowSize, BOOL vertical,
267 BOOL top_pressed, BOOL bottom_pressed )
269 HDC hdcMem = CreateCompatibleDC( hdc );
270 HBITMAP hbmpPrev = SelectObject( hdcMem, vertical ?
271 TOP_ARROW(infoPtr->flags, top_pressed)
272 : LEFT_ARROW(infoPtr->flags, top_pressed));
273 SetStretchBltMode( hdc, STRETCH_DELETESCANS );
274 StretchBlt( hdc, rect->left, rect->top,
275 vertical ? rect->right-rect->left : arrowSize+1,
276 vertical ? arrowSize+1 : rect->bottom-rect->top,
278 SYSMETRICS_CXVSCROLL + 1, SYSMETRICS_CYHSCROLL + 1,
281 SelectObject( hdcMem, vertical ?
282 BOTTOM_ARROW( infoPtr->flags, bottom_pressed )
283 : RIGHT_ARROW( infoPtr->flags, bottom_pressed ) );
285 StretchBlt( hdc, rect->left, rect->bottom - arrowSize - 1,
286 rect->right - rect->left, arrowSize + 1,
288 SYSMETRICS_CXVSCROLL + 1, SYSMETRICS_CYHSCROLL + 1,
291 StretchBlt( hdc, rect->right - arrowSize - 1, rect->top,
292 arrowSize + 1, rect->bottom - rect->top,
294 SYSMETRICS_CXVSCROLL + 1, SYSMETRICS_CYHSCROLL + 1,
296 SelectObject( hdcMem, hbmpPrev );
301 /***********************************************************************
302 * SCROLL_DrawMovingThumb
304 * Draw the moving thumb rectangle.
306 static void SCROLL_DrawMovingThumb( HDC hdc, RECT *rect, BOOL vertical,
307 WORD arrowSize, WORD thumbPos )
313 if (r.top < rect->top + arrowSize) r.top = rect->top + arrowSize;
314 if (r.top + SYSMETRICS_CYHSCROLL >= rect->bottom - arrowSize)
315 r.top = rect->bottom - arrowSize - SYSMETRICS_CYHSCROLL - 1;
316 r.bottom = r.top + SYSMETRICS_CYHSCROLL + 1;
321 if (r.left < rect->left + arrowSize) r.left = rect->left + arrowSize;
322 if (r.left + SYSMETRICS_CXVSCROLL >= rect->right - arrowSize)
323 r.left = rect->right - arrowSize - SYSMETRICS_CXVSCROLL - 1;
324 r.right = r.left + SYSMETRICS_CXVSCROLL + 1;
326 InflateRect( &r, -1, -1 );
327 DrawFocusRect( hdc, &r );
331 /***********************************************************************
332 * SCROLL_DrawInterior
334 * Draw the scroll bar interior (everything except the arrows).
336 static void SCROLL_DrawInterior( HWND hwnd, HDC hdc, int nBar, RECT *rect,
337 WORD arrowSize, WORD thumbPos, WORD flags,
338 BOOL vertical, BOOL top_selected,
339 BOOL bottom_selected )
342 WND *wndPtr = WIN_FindWndPtr( hwnd );
343 if (((nBar == SB_VERT) && !(wndPtr->dwStyle & WS_VSCROLL))
344 || ((nBar == SB_HORZ) && (!wndPtr->dwStyle & WS_HSCROLL))) return;
346 /* Select the correct brush and pen */
348 SelectObject( hdc, sysColorObjects.hpenWindowFrame );
349 if ((flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH)
351 /* This ought to be the color of the parent window */
352 SelectObject( hdc, sysColorObjects.hbrushWindow );
356 if (nBar == SB_CTL) /* Only scrollbar controls send WM_CTLCOLOR */
358 HBRUSH hbrush = SendMessage( GetParent(hwnd), WM_CTLCOLOR, hdc,
359 MAKELONG(hwnd, CTLCOLOR_SCROLLBAR) );
360 SelectObject( hdc, hbrush );
362 else SelectObject( hdc, sysColorObjects.hbrushScrollbar );
365 /* Calculate the scroll rectangle */
371 r.bottom -= arrowSize;
376 r.right -= arrowSize;
379 /* Draw the scroll bar frame */
381 MoveTo( hdc, r.left, r.top );
382 LineTo( hdc, r.right-1, r.top );
383 LineTo( hdc, r.right-1, r.bottom-1 );
384 LineTo( hdc, r.left, r.bottom-1 );
385 LineTo( hdc, r.left, r.top );
387 /* Draw the scroll rectangles and thumb */
389 if (!thumbPos) /* No thumb to draw */
391 PatBlt( hdc, r.left+1, r.top+1, r.right - r.left - 2,
392 r.bottom - r.top - 2, PATCOPY );
398 PatBlt( hdc, r.left + 1, r.top + 1,
399 r.right - r.left - 2,
400 thumbPos - arrowSize,
401 top_selected ? 0x0f0000 : PATCOPY );
402 r.top += thumbPos - arrowSize;
403 PatBlt( hdc, r.left + 1, r.top + SYSMETRICS_CYHSCROLL + 1,
404 r.right - r.left - 2,
405 r.bottom - r.top - SYSMETRICS_CYHSCROLL - 2,
406 bottom_selected ? 0x0f0000 : PATCOPY );
407 r.bottom = r.top + SYSMETRICS_CYHSCROLL + 1;
409 else /* horizontal */
411 PatBlt( hdc, r.left + 1, r.top + 1,
412 thumbPos - arrowSize,
413 r.bottom - r.top - 2,
414 top_selected ? 0x0f0000 : PATCOPY );
415 r.left += thumbPos - arrowSize;
416 PatBlt( hdc, r.left + SYSMETRICS_CYHSCROLL + 1, r.top + 1,
417 r.right - r.left - SYSMETRICS_CYHSCROLL - 2,
418 r.bottom - r.top - 2,
419 bottom_selected ? 0x0f0000 : PATCOPY );
420 r.right = r.left + SYSMETRICS_CXVSCROLL + 1;
425 SelectObject( hdc, sysColorObjects.hbrushBtnFace );
426 Rectangle( hdc, r.left, r.top, r.right, r.bottom );
427 InflateRect( &r, -1, -1 );
428 GRAPH_DrawReliefRect( hdc, &r, 1, 2, FALSE );
432 /***********************************************************************
433 * SCROLL_DrawScrollBar
435 * Redraw the whole scrollbar.
437 void SCROLL_DrawScrollBar( HWND hwnd, HDC hdc, int nBar )
439 WORD arrowSize, thumbPos;
443 SCROLLINFO *infoPtr = SCROLL_GetScrollInfo( hwnd, nBar );
444 if (!infoPtr) return;
445 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
446 &arrowSize, &thumbPos );
447 /* Draw the arrows */
449 if (arrowSize) SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize,
450 vertical, FALSE, FALSE );
452 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbPos,
453 infoPtr->flags, vertical, FALSE, FALSE );
457 /***********************************************************************
458 * SCROLL_RefreshScrollBar
460 * Repaint the scroll bar interior after a SetScrollRange() or
461 * SetScrollPos() call.
463 static void SCROLL_RefreshScrollBar( HWND hwnd, int nBar )
465 WORD arrowSize, thumbPos;
470 SCROLLINFO *infoPtr = SCROLL_GetScrollInfo( hwnd, nBar );
471 if (!infoPtr) return;
472 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
473 &arrowSize, &thumbPos );
474 hdc = (nBar == SB_CTL) ? GetDC(hwnd) : GetWindowDC(hwnd);
476 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbPos,
477 infoPtr->flags, vertical, FALSE, FALSE );
478 ReleaseDC( hwnd, hdc );
482 /***********************************************************************
483 * SCROLL_HandleKbdEvent
485 * Handle a keyboard event (only for SB_CTL scrollbars).
487 static void SCROLL_HandleKbdEvent( HWND hwnd, WORD wParam )
489 WND *wndPtr = WIN_FindWndPtr( hwnd );
494 case VK_PRIOR: msg = SB_PAGEUP; break;
495 case VK_NEXT: msg = SB_PAGEDOWN; break;
496 case VK_HOME: msg = SB_TOP; break;
497 case VK_END: msg = SB_BOTTOM; break;
498 case VK_UP: msg = SB_LINEUP; break;
499 case VK_DOWN: msg = SB_LINEDOWN; break;
503 SendMessage( GetParent(hwnd),
504 (wndPtr->dwStyle & SBS_VERT) ? WM_VSCROLL : WM_HSCROLL,
505 msg, MAKELONG( 0, hwnd ));
509 /***********************************************************************
510 * SCROLL_HandleScrollEvent
512 * Handle a mouse or timer event for the scrollbar.
513 * 'pt' is the location of the mouse event in client (for SB_CTL) or
514 * windows coordinates.
516 void SCROLL_HandleScrollEvent( HWND hwnd, int nBar, WORD msg, POINT pt )
518 /* Previous mouse position for timer events */
520 /* Hit test code of the last button-down event */
521 static enum SCROLL_HITTEST trackHitTest;
522 /* Thumb position when tracking started. */
523 static UINT trackThumbPos;
524 /* Position in the scroll-bar of the last button-down event. */
525 static int lastClickPos;
526 /* Position in the scroll-bar of the last mouse event. */
527 static int lastMousePos;
529 enum SCROLL_HITTEST hittest;
530 HWND hwndOwner, hwndCtl;
532 WORD arrowSize, thumbPos;
536 SCROLLINFO *infoPtr = SCROLL_GetScrollInfo( hwnd, nBar );
537 if (!infoPtr) return;
538 if ((trackHitTest == SCROLL_NOWHERE) && (msg != WM_LBUTTONDOWN)) return;
540 hdc = (nBar == SB_CTL) ? GetDC(hwnd) : GetWindowDC(hwnd);
541 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
542 &arrowSize, &thumbPos );
543 hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd) : hwnd;
544 hwndCtl = (nBar == SB_CTL) ? hwnd : 0;
548 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
549 trackHitTest = hittest = SCROLL_HitTest( hwnd, nBar, pt );
550 lastClickPos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
551 lastMousePos = lastClickPos;
552 trackThumbPos = thumbPos;
555 if (nBar == SB_CTL) SetFocus( hwnd );
559 hittest = SCROLL_HitTest( hwnd, nBar, pt );
564 hittest = SCROLL_NOWHERE;
570 hittest = SCROLL_HitTest( hwnd, nBar, pt );
574 return; /* Should never happen */
577 dprintf_scroll( stddeb, "ScrollBar Event: hwnd=%x bar=%d msg=%x pt=%d,%d hit=%d\n",
578 hwnd, nBar, msg, pt.x, pt.y, hittest );
582 case SCROLL_NOWHERE: /* No tracking in progress */
585 case SCROLL_TOP_ARROW:
586 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
587 (hittest == trackHitTest), FALSE );
588 if (hittest == trackHitTest)
590 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
591 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
592 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
593 SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
594 SB_LINEUP, MAKELONG( 0, hwndCtl ));
596 else KillSystemTimer( hwnd, SCROLL_TIMER );
599 case SCROLL_TOP_RECT:
600 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbPos,
601 infoPtr->flags, vertical,
602 (hittest == trackHitTest), FALSE );
603 if (hittest == trackHitTest)
605 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
606 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
607 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
608 SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
609 SB_PAGEUP, MAKELONG( 0, hwndCtl ));
611 else KillSystemTimer( hwnd, SCROLL_TIMER );
615 if (msg == WM_LBUTTONDOWN)
616 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize,
617 trackThumbPos + lastMousePos - lastClickPos );
618 else if (msg == WM_LBUTTONUP)
619 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbPos,
620 infoPtr->flags, vertical, FALSE, FALSE );
621 else /* WM_MOUSEMOVE */
625 if (!PtInRect( &rect, pt )) pos = lastClickPos;
626 else pos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
627 if (pos != lastMousePos)
629 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize,
630 trackThumbPos + lastMousePos - lastClickPos );
631 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize,
632 trackThumbPos + pos - lastClickPos );
634 val = SCROLL_GetThumbVal( infoPtr, &rect, vertical, arrowSize,
635 trackThumbPos + lastMousePos - lastClickPos );
636 SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
637 SB_THUMBTRACK, MAKELONG( val, hwndCtl ));
642 case SCROLL_BOTTOM_RECT:
643 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbPos,
644 infoPtr->flags, vertical,
645 FALSE, (hittest == trackHitTest) );
646 if (hittest == trackHitTest)
648 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
649 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
650 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
651 SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
652 SB_PAGEDOWN, MAKELONG( 0, hwndCtl ));
654 else KillSystemTimer( hwnd, SCROLL_TIMER );
657 case SCROLL_BOTTOM_ARROW:
658 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
659 FALSE, (hittest == trackHitTest) );
660 if (hittest == trackHitTest)
662 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
663 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
664 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
665 SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
666 SB_LINEDOWN, MAKELONG( 0, hwndCtl ));
668 else KillSystemTimer( hwnd, SCROLL_TIMER );
672 if (msg == WM_LBUTTONUP)
674 if (trackHitTest == SCROLL_THUMB)
676 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical, arrowSize,
677 trackThumbPos + lastMousePos - lastClickPos );
678 SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
679 SB_THUMBPOSITION, MAKELONG( val, hwndCtl ) );
682 SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
683 SB_ENDSCROLL, MAKELONG( 0, hwndCtl ) );
684 trackHitTest = SCROLL_NOWHERE; /* Terminate tracking */
687 ReleaseDC( hwnd, hdc );
691 /***********************************************************************
694 LONG ScrollBarWndProc( HWND hwnd, WORD message, WORD wParam, LONG lParam )
700 CREATESTRUCT *lpCreat = (CREATESTRUCT *)lParam;
701 if (lpCreat->style & SBS_SIZEBOX)
703 fprintf( stdnimp, "Unimplemented style SBS_SIZEBOX.\n" );
707 if (lpCreat->style & SBS_VERT)
709 if (lpCreat->style & SBS_LEFTALIGN)
710 MoveWindow( hwnd, lpCreat->x, lpCreat->y,
711 SYSMETRICS_CXVSCROLL+1, lpCreat->cy, FALSE );
712 else if (lpCreat->style & SBS_RIGHTALIGN)
714 lpCreat->x+lpCreat->cx-SYSMETRICS_CXVSCROLL-1,
716 SYSMETRICS_CXVSCROLL + 1, lpCreat->cy, FALSE );
720 if (lpCreat->style & SBS_TOPALIGN)
721 MoveWindow( hwnd, lpCreat->x, lpCreat->y,
722 lpCreat->cx, SYSMETRICS_CYHSCROLL+1, FALSE );
723 else if (lpCreat->style & SBS_BOTTOMALIGN)
726 lpCreat->y+lpCreat->cy-SYSMETRICS_CYHSCROLL-1,
727 lpCreat->cx, SYSMETRICS_CYHSCROLL+1, FALSE );
730 if (!hUpArrow) SCROLL_LoadBitmaps();
731 dprintf_scroll( stddeb, "ScrollBar creation, hwnd=%d\n", hwnd );
738 SCROLL_HandleScrollEvent( hwnd, SB_CTL, message, MAKEPOINT(lParam) );
742 SCROLL_HandleKbdEvent( hwnd, wParam );
751 HDC hdc = BeginPaint( hwnd, &ps );
752 SCROLL_DrawScrollBar( hwnd, hdc, SB_CTL );
753 EndPaint( hwnd, &ps );
758 return DefWindowProc( hwnd, message, wParam, lParam );
764 /*************************************************************************
765 * SetScrollPos (USER.62)
767 int SetScrollPos( HWND hwnd, int nBar, int nPos, BOOL bRedraw )
772 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return 0;
774 dprintf_scroll( stddeb,"SetScrollPos min=%d max=%d pos=%d\n",
775 infoPtr->MinVal, infoPtr->MaxVal, nPos );
777 if (nPos < infoPtr->MinVal) nPos = infoPtr->MinVal;
778 else if (nPos > infoPtr->MaxVal) nPos = infoPtr->MaxVal;
779 oldPos = infoPtr->CurVal;
780 infoPtr->CurVal = nPos;
781 if (bRedraw) SCROLL_RefreshScrollBar( hwnd, nBar );
786 /*************************************************************************
787 * GetScrollPos (USER.63)
789 int GetScrollPos( HWND hwnd, int nBar )
793 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return 0;
794 return infoPtr->CurVal;
798 /*************************************************************************
799 * SetScrollRange (USER.64)
801 void SetScrollRange(HWND hwnd, int nBar, int MinVal, int MaxVal, BOOL bRedraw)
805 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return;
807 dprintf_scroll( stddeb,"SetScrollRange hwnd=%x bar=%d min=%d max=%d\n",
808 hwnd, nBar, MinVal, MaxVal );
810 /* Invalid range -> range is set to (0,0) */
811 if ((MinVal > MaxVal) || ((long)MaxVal - MinVal > 32767L))
813 if (infoPtr->CurVal < MinVal) infoPtr->CurVal = MinVal;
814 else if (infoPtr->CurVal > MaxVal) infoPtr->CurVal = MaxVal;
815 infoPtr->MinVal = MinVal;
816 infoPtr->MaxVal = MaxVal;
818 /* Non-client scroll-bar is hidden if min==max */
819 if (nBar != SB_CTL) ShowScrollBar( hwnd, nBar, (MinVal != MaxVal) );
820 if (bRedraw) SCROLL_RefreshScrollBar( hwnd, nBar );
824 /*************************************************************************
825 * GetScrollRange (USER.65)
827 void GetScrollRange(HWND hwnd, int nBar, LPINT lpMin, LPINT lpMax)
831 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return;
832 if (lpMin) *lpMin = infoPtr->MinVal;
833 if (lpMax) *lpMax = infoPtr->MaxVal;
837 /*************************************************************************
838 * ShowScrollBar (USER.267)
840 void ShowScrollBar( HWND hwnd, WORD wBar, BOOL fShow )
842 WND *wndPtr = WIN_FindWndPtr( hwnd );
845 dprintf_scroll( stddeb, "ShowScrollBar: hwnd=%x bar=%d on=%d\n", hwnd, wBar, fShow );
850 ShowWindow( hwnd, fShow ? SW_SHOW : SW_HIDE );
856 if (wndPtr->dwStyle & WS_HSCROLL) return;
857 wndPtr->dwStyle |= WS_HSCROLL;
861 if (!(wndPtr->dwStyle & WS_HSCROLL)) return;
862 wndPtr->dwStyle &= ~WS_HSCROLL;
869 if (wndPtr->dwStyle & WS_VSCROLL) return;
870 wndPtr->dwStyle |= WS_VSCROLL;
874 if (!(wndPtr->dwStyle & WS_VSCROLL)) return;
875 wndPtr->dwStyle &= ~WS_VSCROLL;
882 if ((wndPtr->dwStyle & WS_HSCROLL)
883 && (wndPtr->dwStyle & WS_VSCROLL)) return;
884 wndPtr->dwStyle |= WS_HSCROLL | WS_VSCROLL;
888 if (!(wndPtr->dwStyle & WS_HSCROLL)
889 && !(wndPtr->dwStyle & WS_HSCROLL)) return;
890 wndPtr->dwStyle &= ~(WS_HSCROLL | WS_VSCROLL);
895 return; /* Nothing to do! */
897 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
898 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
899 /* FIXME: Hack until SetWindowPos works correctly */
900 InvalidateRect( hwnd, NULL, TRUE );
904 /*************************************************************************
905 * EnableScrollBar (USER.482)
907 BOOL EnableScrollBar( HWND hwnd, INT nBar, UINT flags )
912 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return FALSE;
913 dprintf_scroll( stddeb, "EnableScrollBar: %x %d %d\n", hwnd, nBar, flags );
914 flags &= ESB_DISABLE_BOTH;
915 if (infoPtr->flags == flags) return FALSE;
916 infoPtr->flags = flags;
918 /* Redraw the whole scroll bar */
919 hdc = (nBar == SB_CTL) ? GetDC(hwnd) : GetWindowDC(hwnd);
920 SCROLL_DrawScrollBar( hwnd, hdc, nBar );
921 ReleaseDC( hwnd, hdc );