4 * Copyright 1993 Martin Ayotte
5 * Copyright 1994, 1996 Alexandre Julliard
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * This code was audited for completeness against the documented features
24 * of Comctl32.dll version 6.0 on Oct. 8, 2004, by Dimitrie O. Paun.
26 * Unless otherwise noted, we believe this code to be complete, as per
27 * the specification mentioned above.
28 * If you discover missing features, or bugs, please note them below.
32 * - SBM_GETSCROLLBARINFO
41 #include "wine/winuser16.h"
44 #include "wine/debug.h"
45 #include "user_private.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(scroll);
52 INT curVal; /* Current scroll-bar value */
53 INT minVal; /* Minimum scroll-bar value */
54 INT maxVal; /* Maximum scroll-bar value */
55 INT page; /* Page size of scroll bar (Win32) */
56 UINT flags; /* EnableScrollBar flags */
57 } SCROLLBAR_INFO, *LPSCROLLBAR_INFO;
60 /* Minimum size of the rectangle between the arrows */
61 #define SCROLL_MIN_RECT 4
63 /* Minimum size of the thumb in pixels */
64 #define SCROLL_MIN_THUMB 6
66 /* Overlap between arrows and thumb */
67 #define SCROLL_ARROW_THUMB_OVERLAP 0
69 /* Delay (in ms) before first repetition when holding the button down */
70 #define SCROLL_FIRST_DELAY 200
72 /* Delay (in ms) between scroll repetitions */
73 #define SCROLL_REPEAT_DELAY 50
76 #define SCROLL_TIMER 0
78 /* Scroll-bar hit testing */
81 SCROLL_NOWHERE, /* Outside the scroll bar */
82 SCROLL_TOP_ARROW, /* Top or left arrow */
83 SCROLL_TOP_RECT, /* Rectangle between the top arrow and the thumb */
84 SCROLL_THUMB, /* Thumb rectangle */
85 SCROLL_BOTTOM_RECT, /* Rectangle between the thumb and the bottom arrow */
86 SCROLL_BOTTOM_ARROW /* Bottom or right arrow */
89 /* What to do after SCROLL_SetScrollInfo() */
90 #define SA_SSI_HIDE 0x0001
91 #define SA_SSI_SHOW 0x0002
92 #define SA_SSI_REFRESH 0x0004
93 #define SA_SSI_REPAINT_ARROWS 0x0008
95 /* Thumb-tracking info */
96 static HWND SCROLL_TrackingWin = 0;
97 static INT SCROLL_TrackingBar = 0;
98 static INT SCROLL_TrackingPos = 0;
99 static INT SCROLL_TrackingVal = 0;
100 /* Hit test code of the last button-down event */
101 static enum SCROLL_HITTEST SCROLL_trackHitTest;
102 static BOOL SCROLL_trackVertical;
104 /* Is the moving thumb being displayed? */
105 static BOOL SCROLL_MovingThumb = FALSE;
107 /* Local functions */
108 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar,
109 BOOL fShowH, BOOL fShowV );
110 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar,
111 const SCROLLINFO *info, BOOL bRedraw );
112 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
113 RECT *rect, INT arrowSize,
114 INT thumbSize, INT thumbPos,
115 UINT flags, BOOL vertical,
116 BOOL top_selected, BOOL bottom_selected );
117 static LRESULT WINAPI ScrollBarWndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
120 /*********************************************************************
121 * scrollbar class descriptor
123 const struct builtin_class_descr SCROLL_builtin_class =
125 "ScrollBar", /* name */
126 CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC, /* style */
127 NULL, /* procA (winproc is Unicode only) */
128 ScrollBarWndProc, /* procW */
129 sizeof(SCROLLBAR_INFO), /* extra */
130 IDC_ARROW, /* cursor */
134 /***********************************************************************
135 * SCROLL_ScrollInfoValid
137 * Determine if the supplied SCROLLINFO struct is valid.
139 inline static BOOL SCROLL_ScrollInfoValid(
140 LPSCROLLINFO info /* [in] The SCROLLINFO struct to be tested */)
142 return !(info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)
143 || (info->cbSize != sizeof(*info)
144 && info->cbSize != sizeof(*info) - sizeof(info->nTrackPos)));
148 /***********************************************************************
149 * SCROLL_GetScrollBarInfo
151 static SCROLLBAR_INFO *SCROLL_GetScrollBarInfo( HWND hwnd, INT nBar )
153 SCROLLBAR_INFO *infoPtr;
154 WND *wndPtr = WIN_FindWndPtr( hwnd );
156 if (!wndPtr) return NULL;
159 case SB_HORZ: infoPtr = (SCROLLBAR_INFO *)wndPtr->pHScroll; break;
160 case SB_VERT: infoPtr = (SCROLLBAR_INFO *)wndPtr->pVScroll; break;
161 case SB_CTL: infoPtr = (SCROLLBAR_INFO *)wndPtr->wExtra; break;
163 WIN_ReleaseWndPtr( wndPtr );
167 if (!infoPtr) /* Create the info structure if needed */
169 if ((infoPtr = HeapAlloc( GetProcessHeap(), 0, sizeof(SCROLLBAR_INFO) )))
171 infoPtr->minVal = infoPtr->curVal = infoPtr->page = 0;
172 infoPtr->maxVal = 100;
173 infoPtr->flags = ESB_ENABLE_BOTH;
174 if (nBar == SB_HORZ) wndPtr->pHScroll = infoPtr;
175 else wndPtr->pVScroll = infoPtr;
178 WIN_ReleaseWndPtr( wndPtr );
183 /***********************************************************************
184 * SCROLL_GetScrollBarRect
186 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
187 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
188 * 'arrowSize' returns the width or height of an arrow (depending on
189 * the orientation of the scrollbar), 'thumbSize' returns the size of
190 * the thumb, and 'thumbPos' returns the position of the thumb
191 * relative to the left or to the top.
192 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
194 static BOOL SCROLL_GetScrollBarRect( HWND hwnd, INT nBar, RECT *lprect,
195 INT *arrowSize, INT *thumbSize,
200 WND *wndPtr = WIN_FindWndPtr( hwnd );
205 lprect->left = wndPtr->rectClient.left - wndPtr->rectWindow.left;
206 lprect->top = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
207 lprect->right = wndPtr->rectClient.right - wndPtr->rectWindow.left;
208 lprect->bottom = lprect->top + GetSystemMetrics(SM_CYHSCROLL);
209 if(wndPtr->dwStyle & WS_BORDER) {
212 } else if(wndPtr->dwStyle & WS_VSCROLL)
218 if((wndPtr->dwExStyle & WS_EX_LEFTSCROLLBAR) != 0)
219 lprect->left = wndPtr->rectClient.left - wndPtr->rectWindow.left - GetSystemMetrics(SM_CXVSCROLL);
221 lprect->left = wndPtr->rectClient.right - wndPtr->rectWindow.left;
222 lprect->top = wndPtr->rectClient.top - wndPtr->rectWindow.top;
223 lprect->right = lprect->left + GetSystemMetrics(SM_CXVSCROLL);
224 lprect->bottom = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
225 if(wndPtr->dwStyle & WS_BORDER) {
228 } else if(wndPtr->dwStyle & WS_HSCROLL)
234 GetClientRect( hwnd, lprect );
235 vertical = ((wndPtr->dwStyle & SBS_VERT) != 0);
239 WIN_ReleaseWndPtr(wndPtr);
243 if (vertical) pixels = lprect->bottom - lprect->top;
244 else pixels = lprect->right - lprect->left;
246 if (pixels <= 2*GetSystemMetrics(SM_CXVSCROLL) + SCROLL_MIN_RECT)
248 if (pixels > SCROLL_MIN_RECT)
249 *arrowSize = (pixels - SCROLL_MIN_RECT) / 2;
252 *thumbPos = *thumbSize = 0;
256 SCROLLBAR_INFO *info = SCROLL_GetScrollBarInfo( hwnd, nBar );
258 *arrowSize = GetSystemMetrics(SM_CXVSCROLL);
259 pixels -= (2 * (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP));
263 *thumbSize = MulDiv(pixels,info->page,(info->maxVal-info->minVal+1));
264 if (*thumbSize < SCROLL_MIN_THUMB) *thumbSize = SCROLL_MIN_THUMB;
266 else *thumbSize = GetSystemMetrics(SM_CXVSCROLL);
268 if (((pixels -= *thumbSize ) < 0) ||
269 ((info->flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH))
271 /* Rectangle too small or scrollbar disabled -> no thumb */
272 *thumbPos = *thumbSize = 0;
276 INT max = info->maxVal - max( info->page-1, 0 );
277 if (info->minVal >= max)
278 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
280 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP
281 + MulDiv(pixels, (info->curVal-info->minVal),(max - info->minVal));
284 WIN_ReleaseWndPtr(wndPtr);
289 /***********************************************************************
292 * Compute the current scroll position based on the thumb position in pixels
293 * from the top of the scroll-bar.
295 static UINT SCROLL_GetThumbVal( SCROLLBAR_INFO *infoPtr, RECT *rect,
296 BOOL vertical, INT pos )
299 INT pixels = vertical ? rect->bottom-rect->top : rect->right-rect->left;
301 if ((pixels -= 2*(GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP)) <= 0)
302 return infoPtr->minVal;
306 thumbSize = MulDiv(pixels,infoPtr->page,(infoPtr->maxVal-infoPtr->minVal+1));
307 if (thumbSize < SCROLL_MIN_THUMB) thumbSize = SCROLL_MIN_THUMB;
309 else thumbSize = GetSystemMetrics(SM_CXVSCROLL);
311 if ((pixels -= thumbSize) <= 0) return infoPtr->minVal;
313 pos = max( 0, pos - (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP) );
314 if (pos > pixels) pos = pixels;
316 if (!infoPtr->page) pos *= infoPtr->maxVal - infoPtr->minVal;
317 else pos *= infoPtr->maxVal - infoPtr->minVal - infoPtr->page + 1;
318 return infoPtr->minVal + ((pos + pixels / 2) / pixels);
321 /***********************************************************************
324 static BOOL SCROLL_PtInRectEx( LPRECT lpRect, POINT pt, BOOL vertical )
330 rect.left -= lpRect->right - lpRect->left;
331 rect.right += lpRect->right - lpRect->left;
335 rect.top -= lpRect->bottom - lpRect->top;
336 rect.bottom += lpRect->bottom - lpRect->top;
338 return PtInRect( &rect, pt );
341 /***********************************************************************
344 static POINT SCROLL_ClipPos( LPRECT lpRect, POINT pt )
346 if( pt.x < lpRect->left )
349 if( pt.x > lpRect->right )
350 pt.x = lpRect->right;
352 if( pt.y < lpRect->top )
355 if( pt.y > lpRect->bottom )
356 pt.y = lpRect->bottom;
362 /***********************************************************************
365 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
367 static enum SCROLL_HITTEST SCROLL_HitTest( HWND hwnd, INT nBar,
368 POINT pt, BOOL bDragging )
370 INT arrowSize, thumbSize, thumbPos;
373 BOOL vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
374 &arrowSize, &thumbSize, &thumbPos );
376 if ( (bDragging && !SCROLL_PtInRectEx( &rect, pt, vertical )) ||
377 (!PtInRect( &rect, pt )) ) return SCROLL_NOWHERE;
381 if (pt.y < rect.top + arrowSize) return SCROLL_TOP_ARROW;
382 if (pt.y >= rect.bottom - arrowSize) return SCROLL_BOTTOM_ARROW;
383 if (!thumbPos) return SCROLL_TOP_RECT;
385 if (pt.y < thumbPos) return SCROLL_TOP_RECT;
386 if (pt.y >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
388 else /* horizontal */
390 if (pt.x < rect.left + arrowSize) return SCROLL_TOP_ARROW;
391 if (pt.x >= rect.right - arrowSize) return SCROLL_BOTTOM_ARROW;
392 if (!thumbPos) return SCROLL_TOP_RECT;
394 if (pt.x < thumbPos) return SCROLL_TOP_RECT;
395 if (pt.x >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
401 /***********************************************************************
404 * Draw the scroll bar arrows.
406 static void SCROLL_DrawArrows( HDC hdc, SCROLLBAR_INFO *infoPtr,
407 RECT *rect, INT arrowSize, BOOL vertical,
408 BOOL top_pressed, BOOL bottom_pressed )
414 r.bottom = r.top + arrowSize;
416 r.right = r.left + arrowSize;
418 DrawFrameControl( hdc, &r, DFC_SCROLL,
419 (vertical ? DFCS_SCROLLUP : DFCS_SCROLLLEFT)
420 | (top_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
421 | (infoPtr->flags&ESB_DISABLE_LTUP ? DFCS_INACTIVE : 0 ) );
425 r.top = r.bottom-arrowSize;
427 r.left = r.right-arrowSize;
429 DrawFrameControl( hdc, &r, DFC_SCROLL,
430 (vertical ? DFCS_SCROLLDOWN : DFCS_SCROLLRIGHT)
431 | (bottom_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
432 | (infoPtr->flags&ESB_DISABLE_RTDN ? DFCS_INACTIVE : 0) );
435 static void SCROLL_DrawMovingThumb( HDC hdc, RECT *rect, BOOL vertical,
436 INT arrowSize, INT thumbSize )
438 INT pos = SCROLL_TrackingPos;
442 max_size = rect->bottom - rect->top;
444 max_size = rect->right - rect->left;
446 max_size -= (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) + thumbSize;
448 if( pos < (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) )
449 pos = (arrowSize-SCROLL_ARROW_THUMB_OVERLAP);
450 else if( pos > max_size )
453 SCROLL_DrawInterior_9x( SCROLL_TrackingWin, hdc, SCROLL_TrackingBar,
454 rect, arrowSize, thumbSize, pos,
455 0, vertical, FALSE, FALSE );
457 SCROLL_MovingThumb = !SCROLL_MovingThumb;
460 /***********************************************************************
461 * SCROLL_DrawInterior
463 * Draw the scroll bar interior (everything except the arrows).
465 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
466 RECT *rect, INT arrowSize,
467 INT thumbSize, INT thumbPos,
468 UINT flags, BOOL vertical,
469 BOOL top_selected, BOOL bottom_selected )
473 HBRUSH hSaveBrush,hBrush;
475 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
476 * The window-owned scrollbars need to call DEFWND_ControlColor
477 * to correctly setup default scrollbar colors
481 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
482 (WPARAM)hdc,(LPARAM)hwnd);
486 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
489 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
490 hSaveBrush = SelectObject( hdc, hBrush );
492 /* Calculate the scroll rectangle */
496 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
497 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
501 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
502 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
505 /* Draw the scroll rectangles and thumb */
506 if (!thumbPos) /* No thumb to draw */
508 PatBlt( hdc, r.left, r.top,
509 r.right - r.left, r.bottom - r.top,
512 /* cleanup and return */
513 SelectObject( hdc, hSavePen );
514 SelectObject( hdc, hSaveBrush );
520 PatBlt( hdc, r.left, r.top,
522 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
523 top_selected ? 0x0f0000 : PATCOPY );
524 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
525 PatBlt( hdc, r.left, r.top + thumbSize,
527 r.bottom - r.top - thumbSize,
528 bottom_selected ? 0x0f0000 : PATCOPY );
529 r.bottom = r.top + thumbSize;
531 else /* horizontal */
533 PatBlt( hdc, r.left, r.top,
534 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
536 top_selected ? 0x0f0000 : PATCOPY );
537 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
538 PatBlt( hdc, r.left + thumbSize, r.top,
539 r.right - r.left - thumbSize,
541 bottom_selected ? 0x0f0000 : PATCOPY );
542 r.right = r.left + thumbSize;
546 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT | BF_MIDDLE );
549 SelectObject( hdc, hSavePen );
550 SelectObject( hdc, hSaveBrush );
554 static void SCROLL_DrawInterior( HWND hwnd, HDC hdc, INT nBar,
555 RECT *rect, INT arrowSize,
556 INT thumbSize, INT thumbPos,
557 UINT flags, BOOL vertical,
558 BOOL top_selected, BOOL bottom_selected )
562 HBRUSH hSaveBrush,hBrush;
563 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
565 if (Save_SCROLL_MovingThumb &&
566 (SCROLL_TrackingWin == hwnd) &&
567 (SCROLL_TrackingBar == nBar))
568 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
570 /* Select the correct brush and pen */
572 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
573 * The window-owned scrollbars need to call DEFWND_ControlColor
574 * to correctly setup default scrollbar colors
576 if (nBar == SB_CTL) {
577 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
578 (WPARAM)hdc,(LPARAM)hwnd);
580 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
582 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
583 hSaveBrush = SelectObject( hdc, hBrush );
585 /* Calculate the scroll rectangle */
590 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
591 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
595 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
596 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
599 /* Draw the scroll bar frame */
601 /* Draw the scroll rectangles and thumb */
603 if (!thumbPos) /* No thumb to draw */
605 PatBlt( hdc, r.left, r.top, r.right - r.left, r.bottom - r.top, PATCOPY );
607 /* cleanup and return */
608 SelectObject( hdc, hSavePen );
609 SelectObject( hdc, hSaveBrush );
615 PatBlt( hdc, r.left, r.top, r.right - r.left,
616 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
617 top_selected ? 0x0f0000 : PATCOPY );
618 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
619 PatBlt( hdc, r.left, r.top + thumbSize, r.right - r.left,
620 r.bottom - r.top - thumbSize,
621 bottom_selected ? 0x0f0000 : PATCOPY );
622 r.bottom = r.top + thumbSize;
624 else /* horizontal */
626 PatBlt( hdc, r.left, r.top,
627 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
628 r.bottom - r.top, top_selected ? 0x0f0000 : PATCOPY );
629 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
630 PatBlt( hdc, r.left + thumbSize, r.top, r.right - r.left - thumbSize,
631 r.bottom - r.top, bottom_selected ? 0x0f0000 : PATCOPY );
632 r.right = r.left + thumbSize;
637 SelectObject( hdc, GetSysColorBrush(COLOR_BTNFACE) );
638 Rectangle( hdc, r.left+1, r.top+1, r.right-1, r.bottom-1 );
639 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT );
641 if (Save_SCROLL_MovingThumb &&
642 (SCROLL_TrackingWin == hwnd) &&
643 (SCROLL_TrackingBar == nBar))
644 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
647 SelectObject( hdc, hSavePen );
648 SelectObject( hdc, hSaveBrush );
652 /***********************************************************************
653 * SCROLL_DrawScrollBar
655 * Redraw the whole scrollbar.
657 void SCROLL_DrawScrollBar( HWND hwnd, HDC hdc, INT nBar,
658 BOOL arrows, BOOL interior )
660 INT arrowSize, thumbSize, thumbPos;
663 WND *wndPtr = WIN_FindWndPtr( hwnd );
664 SCROLLBAR_INFO *infoPtr = SCROLL_GetScrollBarInfo( hwnd, nBar );
665 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
667 if (!wndPtr || !infoPtr ||
668 ((nBar == SB_VERT) && !(wndPtr->dwStyle & WS_VSCROLL)) ||
669 ((nBar == SB_HORZ) && !(wndPtr->dwStyle & WS_HSCROLL))) goto END;
670 if (!WIN_IsWindowDrawable( hwnd, FALSE )) goto END;
671 hwnd = wndPtr->hwndSelf; /* make it a full handle */
673 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
674 &arrowSize, &thumbSize, &thumbPos );
676 /* do not draw if the scrollbar rectangle is empty */
677 if(IsRectEmpty(&rect))
680 if (Save_SCROLL_MovingThumb &&
681 (SCROLL_TrackingWin == hwnd) &&
682 (SCROLL_TrackingBar == nBar))
683 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
685 /* Draw the arrows */
687 if (arrows && arrowSize)
689 if( vertical == SCROLL_trackVertical && GetCapture() == hwnd )
690 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
691 (SCROLL_trackHitTest == SCROLL_TOP_ARROW),
692 (SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW) );
694 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
698 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
699 thumbPos, infoPtr->flags, vertical, FALSE, FALSE );
701 if (Save_SCROLL_MovingThumb &&
702 (SCROLL_TrackingWin == hwnd) &&
703 (SCROLL_TrackingBar == nBar))
704 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
706 /* if scroll bar has focus, reposition the caret */
707 if(hwnd==GetFocus() && (nBar==SB_CTL))
711 SetCaretPos(thumbPos+1, rect.top+1);
715 SetCaretPos(rect.top+1, thumbPos+1);
720 WIN_ReleaseWndPtr(wndPtr);
723 /***********************************************************************
724 * SCROLL_DrawSizeGrip
726 * Draw the size grip.
728 static void SCROLL_DrawSizeGrip( HWND hwnd, HDC hdc)
732 GetClientRect( hwnd, &rc );
733 FillRect( hdc, &rc, GetSysColorBrush(COLOR_SCROLLBAR) );
734 rc.left = max( rc.left, rc.right - GetSystemMetrics(SM_CXVSCROLL) - 1 );
735 rc.top = max( rc.top, rc.bottom - GetSystemMetrics(SM_CYHSCROLL) - 1 );
736 DrawFrameControl( hdc, &rc, DFC_SCROLL, DFCS_SCROLLSIZEGRIP );
740 /***********************************************************************
741 * SCROLL_RefreshScrollBar
743 * Repaint the scroll bar interior after a SetScrollRange() or
744 * SetScrollPos() call.
746 static void SCROLL_RefreshScrollBar( HWND hwnd, INT nBar,
747 BOOL arrows, BOOL interior )
749 HDC hdc = GetDCEx( hwnd, 0,
750 DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW) );
753 SCROLL_DrawScrollBar( hwnd, hdc, nBar, arrows, interior );
754 ReleaseDC( hwnd, hdc );
758 /***********************************************************************
759 * SCROLL_HandleKbdEvent
761 * Handle a keyboard event (only for SB_CTL scrollbars with focus).
764 * hwnd [I] Handle of window with scrollbar(s)
765 * wParam [I] Variable input including enable state
766 * lParam [I] Variable input including input point
768 static void SCROLL_HandleKbdEvent(HWND hwnd, WPARAM wParam, LPARAM lParam)
770 TRACE("hwnd=%p wParam=%d lParam=%ld\n", hwnd, wParam, lParam);
772 /* hide caret on first KEYDOWN to prevent flicker */
773 if ((lParam & PFD_DOUBLEBUFFER_DONTCARE) == 0)
778 case VK_PRIOR: wParam = SB_PAGEUP; break;
779 case VK_NEXT: wParam = SB_PAGEDOWN; break;
780 case VK_HOME: wParam = SB_TOP; break;
781 case VK_END: wParam = SB_BOTTOM; break;
782 case VK_UP: wParam = SB_LINEUP; break;
783 case VK_DOWN: wParam = SB_LINEDOWN; break;
786 SendMessageW(GetParent(hwnd),
787 ((GetWindowLongW( hwnd, GWL_STYLE ) & SBS_VERT) ?
788 WM_VSCROLL : WM_HSCROLL), wParam, (LPARAM)hwnd);
792 /***********************************************************************
793 * SCROLL_HandleScrollEvent
795 * Handle a mouse or timer event for the scrollbar.
796 * 'pt' is the location of the mouse event in client (for SB_CTL) or
797 * windows coordinates.
799 static void SCROLL_HandleScrollEvent( HWND hwnd, INT nBar, UINT msg, POINT pt)
801 /* Previous mouse position for timer events */
803 /* Thumb position when tracking started. */
804 static UINT trackThumbPos;
805 /* Position in the scroll-bar of the last button-down event. */
806 static INT lastClickPos;
807 /* Position in the scroll-bar of the last mouse event. */
808 static INT lastMousePos;
810 enum SCROLL_HITTEST hittest;
811 HWND hwndOwner, hwndCtl;
813 INT arrowSize, thumbSize, thumbPos;
817 SCROLLBAR_INFO *infoPtr = SCROLL_GetScrollBarInfo( hwnd, nBar );
818 if (!infoPtr) return;
819 if ((SCROLL_trackHitTest == SCROLL_NOWHERE) && (msg != WM_LBUTTONDOWN))
822 if (nBar == SB_CTL && (GetWindowLongW( hwnd, GWL_STYLE ) & (SBS_SIZEGRIP | SBS_SIZEBOX)))
826 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
827 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
830 SCROLL_trackHitTest = hittest = SCROLL_THUMB;
833 GetClientRect(GetParent(GetParent(hwnd)),&rect);
838 SCROLL_trackHitTest = hittest = SCROLL_NOWHERE;
839 if (hwnd==GetFocus()) ShowCaret(hwnd);
848 hdc = GetDCEx( hwnd, 0, DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW));
849 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
850 &arrowSize, &thumbSize, &thumbPos );
851 hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd) : hwnd;
852 hwndCtl = (nBar == SB_CTL) ? hwnd : 0;
856 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
857 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
858 SCROLL_trackVertical = vertical;
859 SCROLL_trackHitTest = hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
860 lastClickPos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
861 lastMousePos = lastClickPos;
862 trackThumbPos = thumbPos;
864 if (nBar == SB_CTL && (GetWindowLongW(hwnd, GWL_STYLE) & WS_TABSTOP)) SetFocus( hwnd );
869 hittest = SCROLL_HitTest( hwnd, nBar, pt, TRUE );
874 hittest = SCROLL_NOWHERE;
876 /* if scrollbar has focus, show back caret */
877 if (hwnd==GetFocus()) ShowCaret(hwnd);
882 hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
886 return; /* Should never happen */
889 TRACE("Event: hwnd=%p bar=%d msg=%s pt=%ld,%ld hit=%d\n",
890 hwnd, nBar, SPY_GetMsgName(msg,hwnd), pt.x, pt.y, hittest );
892 switch(SCROLL_trackHitTest)
894 case SCROLL_NOWHERE: /* No tracking in progress */
897 case SCROLL_TOP_ARROW:
898 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
899 (hittest == SCROLL_trackHitTest), FALSE );
900 if (hittest == SCROLL_trackHitTest)
902 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
904 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
905 SB_LINEUP, (LPARAM)hwndCtl );
908 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
909 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
912 else KillSystemTimer( hwnd, SCROLL_TIMER );
915 case SCROLL_TOP_RECT:
916 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
917 thumbPos, infoPtr->flags, vertical,
918 (hittest == SCROLL_trackHitTest), FALSE );
919 if (hittest == SCROLL_trackHitTest)
921 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
923 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
924 SB_PAGEUP, (LPARAM)hwndCtl );
926 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
927 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
930 else KillSystemTimer( hwnd, SCROLL_TIMER );
934 if (msg == WM_LBUTTONDOWN)
936 SCROLL_TrackingWin = hwnd;
937 SCROLL_TrackingBar = nBar;
938 SCROLL_TrackingPos = trackThumbPos + lastMousePos - lastClickPos;
939 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
941 SCROLL_TrackingPos );
942 if (!SCROLL_MovingThumb)
943 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
945 else if (msg == WM_LBUTTONUP)
947 if (SCROLL_MovingThumb)
948 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
949 SCROLL_TrackingWin = 0;
950 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
951 thumbPos, infoPtr->flags, vertical,
954 else /* WM_MOUSEMOVE */
958 if (!SCROLL_PtInRectEx( &rect, pt, vertical )) pos = lastClickPos;
961 pt = SCROLL_ClipPos( &rect, pt );
962 pos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
964 if ( (pos != lastMousePos) || (!SCROLL_MovingThumb) )
966 if (SCROLL_MovingThumb)
967 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
968 arrowSize, thumbSize );
970 SCROLL_TrackingPos = trackThumbPos + pos - lastClickPos;
971 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
973 SCROLL_TrackingPos );
974 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
975 MAKEWPARAM( SB_THUMBTRACK, SCROLL_TrackingVal),
977 if (!SCROLL_MovingThumb)
978 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
979 arrowSize, thumbSize );
984 case SCROLL_BOTTOM_RECT:
985 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
986 thumbPos, infoPtr->flags, vertical,
987 FALSE, (hittest == SCROLL_trackHitTest) );
988 if (hittest == SCROLL_trackHitTest)
990 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
992 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
993 SB_PAGEDOWN, (LPARAM)hwndCtl );
995 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
996 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
999 else KillSystemTimer( hwnd, SCROLL_TIMER );
1002 case SCROLL_BOTTOM_ARROW:
1003 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
1004 FALSE, (hittest == SCROLL_trackHitTest) );
1005 if (hittest == SCROLL_trackHitTest)
1007 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1009 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1010 SB_LINEDOWN, (LPARAM)hwndCtl );
1013 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1014 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1017 else KillSystemTimer( hwnd, SCROLL_TIMER );
1021 if (msg == WM_LBUTTONDOWN)
1024 if (hittest == SCROLL_THUMB)
1026 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1027 trackThumbPos + lastMousePos - lastClickPos );
1028 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1029 MAKEWPARAM( SB_THUMBTRACK, val ), (LPARAM)hwndCtl );
1033 if (msg == WM_LBUTTONUP)
1035 hittest = SCROLL_trackHitTest;
1036 SCROLL_trackHitTest = SCROLL_NOWHERE; /* Terminate tracking */
1038 if (hittest == SCROLL_THUMB)
1040 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1041 trackThumbPos + lastMousePos - lastClickPos );
1042 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1043 MAKEWPARAM( SB_THUMBPOSITION, val ), (LPARAM)hwndCtl );
1045 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1046 SB_ENDSCROLL, (LPARAM)hwndCtl );
1049 ReleaseDC( hwnd, hdc );
1053 /***********************************************************************
1054 * SCROLL_TrackScrollBar
1056 * Track a mouse button press on a scroll-bar.
1057 * pt is in screen-coordinates for non-client scroll bars.
1059 void SCROLL_TrackScrollBar( HWND hwnd, INT scrollbar, POINT pt )
1062 INT xoffset = 0, yoffset = 0;
1064 if (scrollbar != SB_CTL)
1066 WND *wndPtr = WIN_GetPtr( hwnd );
1067 if (!wndPtr || wndPtr == WND_OTHER_PROCESS) return;
1068 xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
1069 yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
1070 WIN_ReleasePtr( wndPtr );
1071 ScreenToClient( hwnd, &pt );
1076 SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt );
1080 if (!GetMessageW( &msg, 0, 0, 0 )) break;
1081 if (CallMsgFilterW( &msg, MSGF_SCROLLBAR )) continue;
1087 pt.x = (short)LOWORD(msg.lParam) + xoffset;
1088 pt.y = (short)HIWORD(msg.lParam) + yoffset;
1089 SCROLL_HandleScrollEvent( hwnd, scrollbar, msg.message, pt );
1092 TranslateMessage( &msg );
1093 DispatchMessageW( &msg );
1096 if (!IsWindow( hwnd ))
1101 } while (msg.message != WM_LBUTTONUP);
1105 /***********************************************************************
1106 * SCROLL_CreateScrollBar
1108 * Create a scroll bar
1111 * hwnd [I] Handle of window with scrollbar(s)
1112 * lpCreate [I] The style and place of the scroll bar
1114 static void SCROLL_CreateScrollBar(HWND hwnd, LPCREATESTRUCTW lpCreate)
1116 LPSCROLLBAR_INFO info = SCROLL_GetScrollBarInfo(hwnd, SB_CTL);
1119 TRACE("hwnd=%p lpCreate=%p\n", hwnd, lpCreate);
1121 if (lpCreate->style & WS_DISABLED)
1123 info->flags = ESB_DISABLE_BOTH;
1124 TRACE("Created WS_DISABLED scrollbar\n");
1128 if (lpCreate->style & (SBS_SIZEGRIP | SBS_SIZEBOX))
1130 if (lpCreate->style & SBS_SIZEBOXTOPLEFTALIGN)
1131 MoveWindow( hwnd, lpCreate->x, lpCreate->y, GetSystemMetrics(SM_CXVSCROLL)+1,
1132 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1133 else if(lpCreate->style & SBS_SIZEBOXBOTTOMRIGHTALIGN)
1134 MoveWindow( hwnd, lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1135 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1136 GetSystemMetrics(SM_CXVSCROLL)+1,
1137 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1139 else if (lpCreate->style & SBS_VERT)
1141 if (lpCreate->style & SBS_LEFTALIGN)
1142 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1143 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1144 else if (lpCreate->style & SBS_RIGHTALIGN)
1146 lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1148 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1152 if (lpCreate->style & SBS_TOPALIGN)
1153 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1154 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1155 else if (lpCreate->style & SBS_BOTTOMALIGN)
1158 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1159 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1164 /*************************************************************************
1165 * SCROLL_GetScrollInfo
1167 * Internal helper for the API function
1170 * hwnd [I] Handle of window with scrollbar(s)
1171 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1172 * info [IO] fMask specifies which values to retrieve
1174 static BOOL SCROLL_GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1176 LPSCROLLBAR_INFO infoPtr;
1178 /* handle invalid data structure */
1179 if (!SCROLL_ScrollInfoValid(info)
1180 || !(infoPtr = SCROLL_GetScrollBarInfo(hwnd, nBar)))
1183 /* fill in the desired scroll info structure */
1184 if (info->fMask & SIF_PAGE) info->nPage = infoPtr->page;
1185 if (info->fMask & SIF_POS) info->nPos = infoPtr->curVal;
1186 if ((info->fMask & SIF_TRACKPOS) && (info->cbSize == sizeof(*info)))
1187 info->nTrackPos = (SCROLL_TrackingWin == WIN_GetFullHandle(hwnd)) ? SCROLL_TrackingVal : infoPtr->curVal;
1188 if (info->fMask & SIF_RANGE)
1190 info->nMin = infoPtr->minVal;
1191 info->nMax = infoPtr->maxVal;
1194 return (info->fMask & SIF_ALL) != 0;
1198 /*************************************************************************
1199 * SCROLL_GetScrollPos
1201 * Internal helper for the API function
1204 * hwnd [I] Handle of window with scrollbar(s)
1205 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1207 static INT SCROLL_GetScrollPos(HWND hwnd, INT nBar)
1209 LPSCROLLBAR_INFO infoPtr = SCROLL_GetScrollBarInfo(hwnd, nBar);
1210 return infoPtr ? infoPtr->curVal: 0;
1214 /*************************************************************************
1215 * SCROLL_GetScrollRange
1217 * Internal helper for the API function
1220 * hwnd [I] Handle of window with scrollbar(s)
1221 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1222 * lpMin [O] Where to store minimum value
1223 * lpMax [O] Where to store maximum value
1227 static BOOL SCROLL_GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1229 LPSCROLLBAR_INFO infoPtr = SCROLL_GetScrollBarInfo(hwnd, nBar);
1231 if (lpMin) *lpMin = infoPtr ? infoPtr->minVal : 0;
1232 if (lpMax) *lpMax = infoPtr ? infoPtr->maxVal : 0;
1238 /*************************************************************************
1239 * SCROLL_SetScrollRange
1242 * hwnd [I] Handle of window with scrollbar(s)
1243 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1244 * lpMin [I] Minimum value
1245 * lpMax [I] Maximum value
1248 static BOOL SCROLL_SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal)
1250 LPSCROLLBAR_INFO infoPtr = SCROLL_GetScrollBarInfo(hwnd, nBar);
1252 TRACE("hwnd=%p nBar=%d min=%d max=%d\n", hwnd, nBar, minVal, maxVal);
1256 infoPtr->minVal = minVal;
1257 infoPtr->maxVal = maxVal;
1263 /***********************************************************************
1266 static LRESULT WINAPI ScrollBarWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1268 if (!IsWindow( hwnd )) return 0;
1273 SCROLL_CreateScrollBar(hwnd, (LPCREATESTRUCTW)lParam);
1278 SCROLLBAR_INFO *infoPtr;
1279 if ((infoPtr = SCROLL_GetScrollBarInfo( hwnd, SB_CTL )))
1281 infoPtr->flags = wParam ? ESB_ENABLE_BOTH : ESB_DISABLE_BOTH;
1282 SCROLL_RefreshScrollBar(hwnd, SB_CTL, TRUE, TRUE);
1287 case WM_LBUTTONDBLCLK:
1288 case WM_LBUTTONDOWN:
1291 pt.x = (short)LOWORD(lParam);
1292 pt.y = (short)HIWORD(lParam);
1293 SCROLL_TrackScrollBar( hwnd, SB_CTL, pt );
1301 pt.x = (short)LOWORD(lParam);
1302 pt.y = (short)HIWORD(lParam);
1303 SCROLL_HandleScrollEvent( hwnd, SB_CTL, message, pt );
1308 SCROLL_HandleKbdEvent(hwnd, wParam, lParam);
1317 /* Create a caret when a ScrollBar get focus */
1319 int arrowSize, thumbSize, thumbPos, vertical;
1320 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,
1321 &arrowSize, &thumbSize, &thumbPos );
1324 CreateCaret(hwnd, (HBITMAP)1, thumbSize-2, rect.bottom-rect.top-2);
1325 SetCaretPos(thumbPos+1, rect.top+1);
1329 CreateCaret(hwnd, (HBITMAP)1, rect.right-rect.left-2,thumbSize-2);
1330 SetCaretPos(rect.top+1, thumbPos+1);
1339 int arrowSize, thumbSize, thumbPos, vertical;
1340 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,&arrowSize, &thumbSize, &thumbPos );
1342 rect.left=thumbPos+1;
1343 rect.right=rect.left+thumbSize;
1347 rect.top=thumbPos+1;
1348 rect.bottom=rect.top+thumbSize;
1351 InvalidateRect(hwnd,&rect,0);
1360 return DLGC_WANTARROWS; /* Windows returns this value */
1365 HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
1366 if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEGRIP)
1368 SCROLL_DrawSizeGrip( hwnd, hdc);
1370 else if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEBOX)
1373 GetClientRect( hwnd, &rc );
1374 FillRect( hdc, &rc, GetSysColorBrush(COLOR_SCROLLBAR) );
1377 SCROLL_DrawScrollBar( hwnd, hdc, SB_CTL, TRUE, TRUE );
1378 if (!wParam) EndPaint(hwnd, &ps);
1384 return SetScrollPos( hwnd, SB_CTL, wParam, (BOOL)lParam );
1388 return SCROLL_GetScrollPos(hwnd, SB_CTL);
1390 case SBM_SETRANGE16:
1391 if (wParam) message = SBM_SETRANGEREDRAW;
1392 wParam = LOWORD(lParam);
1393 lParam = HIWORD(lParam);
1395 case SBM_SETRANGEREDRAW:
1398 INT oldPos = SCROLL_GetScrollPos( hwnd, SB_CTL );
1399 SCROLL_SetScrollRange( hwnd, SB_CTL, wParam, lParam );
1400 if (message == SBM_SETRANGEREDRAW)
1401 SCROLL_RefreshScrollBar( hwnd, SB_CTL, TRUE, TRUE );
1402 if (oldPos != SCROLL_GetScrollPos( hwnd, SB_CTL )) return oldPos;
1406 case SBM_GETRANGE16:
1410 SCROLL_GetScrollRange(hwnd, SB_CTL, &min, &max);
1411 return MAKELRESULT(min, max);
1415 return SCROLL_GetScrollRange(hwnd, SB_CTL, (LPINT)wParam, (LPINT)lParam);
1417 case SBM_ENABLE_ARROWS16:
1418 case SBM_ENABLE_ARROWS:
1419 return EnableScrollBar( hwnd, SB_CTL, wParam );
1421 case SBM_SETSCROLLINFO:
1422 return SCROLL_SetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam, wParam );
1424 case SBM_GETSCROLLINFO:
1425 return SCROLL_GetScrollInfo(hwnd, SB_CTL, (SCROLLINFO *)lParam);
1435 ERR("unknown Win32 msg %04x wp=%08x lp=%08lx\n",
1436 message, wParam, lParam );
1440 if (message >= WM_USER)
1441 WARN("unknown msg %04x wp=%04x lp=%08lx\n",
1442 message, wParam, lParam );
1443 return DefWindowProcW( hwnd, message, wParam, lParam );
1449 /*************************************************************************
1450 * SetScrollInfo (USER32.@)
1451 * SetScrollInfo can be used to set the position, upper bound,
1452 * lower bound, and page size of a scrollbar control.
1455 * hwnd [I] Handle of window with scrollbar(s)
1456 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1457 * info [I] Specifies what to change and new values
1458 * bRedraw [I] Should scrollbar be redrawn afterwards?
1461 * Scrollbar position
1464 * For 100 lines of text to be displayed in a window of 25 lines,
1465 * one would for instance use info->nMin=0, info->nMax=75
1466 * (corresponding to the 76 different positions of the window on
1467 * the text), and info->nPage=25.
1469 INT WINAPI SetScrollInfo(HWND hwnd, INT nBar, const SCROLLINFO *info, BOOL bRedraw)
1471 TRACE("hwnd=%p nBar=%d info=%p, bRedraw=%d\n", hwnd, nBar, info, bRedraw);
1473 /* Refer SB_CTL requests to the window */
1475 return SendMessageW(hwnd, SBM_SETSCROLLINFO, bRedraw, (LPARAM)info);
1477 return SCROLL_SetScrollInfo( hwnd, nBar, info, bRedraw );
1480 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar, const SCROLLINFO *info, BOOL bRedraw )
1482 /* Update the scrollbar state and set action flags according to
1483 * what has to be done graphics wise. */
1485 SCROLLBAR_INFO *infoPtr;
1487 BOOL bChangeParams = FALSE; /* don't show/hide scrollbar if params don't change */
1490 if (!(infoPtr = SCROLL_GetScrollBarInfo(hwnd, nBar))) return 0;
1491 if (info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)) return 0;
1492 if ((info->cbSize != sizeof(*info)) &&
1493 (info->cbSize != sizeof(*info)-sizeof(info->nTrackPos))) return 0;
1495 if (TRACE_ON(scroll))
1497 TRACE("hwnd=%p bar=%d", hwnd, nBar);
1498 if (info->fMask & SIF_PAGE) TRACE( " page=%d", info->nPage );
1499 if (info->fMask & SIF_POS) TRACE( " pos=%d", info->nPos );
1500 if (info->fMask & SIF_RANGE) TRACE( " min=%d max=%d", info->nMin, info->nMax );
1504 /* Set the page size */
1506 if (info->fMask & SIF_PAGE)
1508 if( infoPtr->page != info->nPage )
1510 infoPtr->page = info->nPage;
1511 action |= SA_SSI_REFRESH;
1512 bChangeParams = TRUE;
1516 /* Set the scroll pos */
1518 if (info->fMask & SIF_POS)
1520 if( infoPtr->curVal != info->nPos )
1522 infoPtr->curVal = info->nPos;
1523 action |= SA_SSI_REFRESH;
1527 /* Set the scroll range */
1529 if (info->fMask & SIF_RANGE)
1531 /* Invalid range -> range is set to (0,0) */
1532 if ((info->nMin > info->nMax) ||
1533 ((UINT)(info->nMax - info->nMin) >= 0x80000000))
1535 infoPtr->minVal = 0;
1536 infoPtr->maxVal = 0;
1537 bChangeParams = TRUE;
1541 if( infoPtr->minVal != info->nMin ||
1542 infoPtr->maxVal != info->nMax )
1544 action |= SA_SSI_REFRESH;
1545 infoPtr->minVal = info->nMin;
1546 infoPtr->maxVal = info->nMax;
1547 bChangeParams = TRUE;
1552 /* Make sure the page size is valid */
1554 if (infoPtr->page < 0) infoPtr->page = 0;
1555 else if (infoPtr->page > infoPtr->maxVal - infoPtr->minVal + 1 )
1556 infoPtr->page = infoPtr->maxVal - infoPtr->minVal + 1;
1558 /* Make sure the pos is inside the range */
1560 if (infoPtr->curVal < infoPtr->minVal)
1561 infoPtr->curVal = infoPtr->minVal;
1562 else if (infoPtr->curVal > infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1563 infoPtr->curVal = infoPtr->maxVal - max( infoPtr->page-1, 0 );
1565 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1566 infoPtr->page, infoPtr->curVal,
1567 infoPtr->minVal, infoPtr->maxVal );
1569 /* don't change the scrollbar state if SetScrollInfo
1570 * is just called with SIF_DISABLENOSCROLL
1572 if(!(info->fMask & SIF_ALL)) goto done;
1574 /* Check if the scrollbar should be hidden or disabled */
1576 if (info->fMask & (SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL))
1578 new_flags = infoPtr->flags;
1579 if (infoPtr->minVal >= infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1581 /* Hide or disable scroll-bar */
1582 if (info->fMask & SIF_DISABLENOSCROLL)
1584 new_flags = ESB_DISABLE_BOTH;
1585 action |= SA_SSI_REFRESH;
1587 else if ((nBar != SB_CTL) && bChangeParams)
1589 action = SA_SSI_HIDE;
1593 else /* Show and enable scroll-bar */
1596 if ((nBar != SB_CTL) && bChangeParams)
1597 action |= SA_SSI_SHOW;
1600 if (infoPtr->flags != new_flags) /* check arrow flags */
1602 infoPtr->flags = new_flags;
1603 action |= SA_SSI_REPAINT_ARROWS;
1608 if( action & SA_SSI_HIDE )
1609 SCROLL_ShowScrollBar( hwnd, nBar, FALSE, FALSE );
1612 if( action & SA_SSI_SHOW )
1613 if( SCROLL_ShowScrollBar( hwnd, nBar, TRUE, TRUE ) )
1614 return infoPtr->curVal; /* SetWindowPos() already did the painting */
1617 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
1618 else if( action & SA_SSI_REPAINT_ARROWS )
1619 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, FALSE );
1622 /* Return current position */
1623 return infoPtr->curVal;
1627 /*************************************************************************
1628 * GetScrollInfo (USER32.@)
1630 * GetScrollInfo can be used to retrieve the position, upper bound,
1631 * lower bound, and page size of a scrollbar control.
1634 * hwnd [I] Handle of window with scrollbar(s)
1635 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1636 * info [IO] fMask specifies which values to retrieve
1640 BOOL WINAPI GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1642 TRACE("hwnd=%p nBar=%d info=%p\n", hwnd, nBar, info);
1644 /* Refer SB_CTL requests to the window */
1646 SendMessageW(hwnd, SBM_GETSCROLLINFO, (WPARAM)0, (LPARAM)info);
1648 SCROLL_GetScrollInfo(hwnd, nBar, info);
1654 /*************************************************************************
1655 * SetScrollPos (USER32.@)
1658 * hwnd [I] Handle of window with scrollbar(s)
1659 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1660 * nPos [I] New value
1661 * bRedraw [I] Should scrollbar be redrawn afterwards?
1664 * Success: Scrollbar position
1668 * Note the ambiguity when 0 is returned. Use GetLastError
1669 * to make sure there was an error (and to know which one).
1671 INT WINAPI SetScrollPos( HWND hwnd, INT nBar, INT nPos, BOOL bRedraw)
1674 SCROLLBAR_INFO *infoPtr;
1677 if (!(infoPtr = SCROLL_GetScrollBarInfo( hwnd, nBar ))) return 0;
1678 oldPos = infoPtr->curVal;
1679 info.cbSize = sizeof(info);
1681 info.fMask = SIF_POS;
1682 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1687 /*************************************************************************
1688 * GetScrollPos (USER32.@)
1691 * hwnd [I] Handle of window with scrollbar(s)
1692 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1695 * Success: Current position
1699 * There is ambiguity when 0 is returned. Use GetLastError
1700 * to make sure there was an error (and to know which one).
1702 INT WINAPI GetScrollPos(HWND hwnd, INT nBar)
1704 TRACE("hwnd=%p nBar=%d\n", hwnd, nBar);
1706 /* Refer SB_CTL requests to the window */
1708 return SendMessageW(hwnd, SBM_GETPOS, (WPARAM)0, (LPARAM)0);
1710 return SCROLL_GetScrollPos(hwnd, nBar);
1714 /*************************************************************************
1715 * SetScrollRange (USER32.@)
1718 * hwnd [I] Handle of window with scrollbar(s)
1719 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1720 * minVal [I] New minimum value
1721 * maxVal [I] New Maximum value
1722 * bRedraw [I] Should scrollbar be redrawn afterwards?
1726 BOOL WINAPI SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal, BOOL bRedraw)
1730 TRACE("hwnd=%p nBar=%d min=%d max=%d, bRedraw=%d\n", hwnd, nBar, minVal, maxVal, bRedraw);
1732 info.cbSize = sizeof(info);
1733 info.fMask = SIF_RANGE;
1736 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1741 /*************************************************************************
1742 * SCROLL_SetNCSbState
1744 * Updates both scrollbars at the same time. Used by MDI CalcChildScroll().
1746 INT SCROLL_SetNCSbState(HWND hwnd, int vMin, int vMax, int vPos,
1747 int hMin, int hMax, int hPos)
1749 SCROLLINFO vInfo, hInfo;
1751 vInfo.cbSize = hInfo.cbSize = sizeof(SCROLLINFO);
1758 vInfo.fMask = hInfo.fMask = SIF_RANGE | SIF_POS;
1760 SCROLL_SetScrollInfo( hwnd, SB_VERT, &vInfo, TRUE );
1761 SCROLL_SetScrollInfo( hwnd, SB_HORZ, &hInfo, TRUE );
1767 /*************************************************************************
1768 * GetScrollRange (USER32.@)
1771 * hwnd [I] Handle of window with scrollbar(s)
1772 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1773 * lpMin [O] Where to store minimum value
1774 * lpMax [O] Where to store maximum value
1778 BOOL WINAPI GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1780 TRACE("hwnd=%p nBar=%d lpMin=%p lpMax=%p\n", hwnd, nBar, lpMin, lpMax);
1782 /* Refer SB_CTL requests to the window */
1784 SendMessageW(hwnd, SBM_GETRANGE, (WPARAM)lpMin, (LPARAM)lpMax);
1786 SCROLL_GetScrollRange(hwnd, nBar, lpMin, lpMax);
1792 /*************************************************************************
1793 * SCROLL_ShowScrollBar()
1795 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1797 BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar,
1798 BOOL fShowH, BOOL fShowV )
1800 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
1802 TRACE("hwnd=%p bar=%d horz=%d, vert=%d\n", hwnd, nBar, fShowH, fShowV );
1807 ShowWindow( hwnd, fShowH ? SW_SHOW : SW_HIDE );
1814 fShowH = !(style & WS_HSCROLL);
1815 style |= WS_HSCROLL;
1819 fShowH = (style & WS_HSCROLL);
1820 style &= ~WS_HSCROLL;
1822 if( nBar == SB_HORZ ) {
1831 fShowV = !(style & WS_VSCROLL);
1832 style |= WS_VSCROLL;
1836 fShowV = (style & WS_VSCROLL);
1837 style &= ~WS_VSCROLL;
1839 if ( nBar == SB_VERT )
1844 return FALSE; /* Nothing to do! */
1847 if( fShowH || fShowV ) /* frame has been changed, let the window redraw itself */
1849 WIN_SetStyle( hwnd, style );
1850 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
1851 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
1854 return FALSE; /* no frame changes */
1858 /*************************************************************************
1859 * ShowScrollBar (USER32.@)
1862 * hwnd [I] Handle of window with scrollbar(s)
1863 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1864 * fShow [I] TRUE = show, FALSE = hide
1868 BOOL WINAPI ShowScrollBar(HWND hwnd, INT nBar, BOOL fShow)
1870 SCROLL_ShowScrollBar( hwnd, nBar, (nBar == SB_VERT) ? 0 : fShow,
1871 (nBar == SB_HORZ) ? 0 : fShow );
1876 /*************************************************************************
1877 * EnableScrollBar (USER32.@)
1879 BOOL WINAPI EnableScrollBar( HWND hwnd, INT nBar, UINT flags )
1882 SCROLLBAR_INFO *infoPtr;
1884 TRACE("%p %d %d\n", hwnd, nBar, flags );
1886 flags &= ESB_DISABLE_BOTH;
1888 if (nBar == SB_BOTH)
1890 if (!(infoPtr = SCROLL_GetScrollBarInfo( hwnd, SB_VERT ))) return FALSE;
1891 if (!(bFineWithMe = (infoPtr->flags == flags)) )
1893 infoPtr->flags = flags;
1894 SCROLL_RefreshScrollBar( hwnd, SB_VERT, TRUE, TRUE );
1901 if (!(infoPtr = SCROLL_GetScrollBarInfo( hwnd, nBar ))) return FALSE;
1902 if (bFineWithMe && infoPtr->flags == flags) return FALSE;
1903 infoPtr->flags = flags;
1905 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );