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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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.
40 #include "wine/debug.h"
41 #include "user_private.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(scroll);
45 /* data for a single scroll bar */
48 INT curVal; /* Current scroll-bar value */
49 INT minVal; /* Minimum scroll-bar value */
50 INT maxVal; /* Maximum scroll-bar value */
51 INT page; /* Page size of scroll bar (Win32) */
52 UINT flags; /* EnableScrollBar flags */
53 } SCROLLBAR_INFO, *LPSCROLLBAR_INFO;
55 /* data for window that has (one or two) scroll bars */
60 } WINSCROLLBAR_INFO, *LPWINSCROLLBAR_INFO;
62 /* Minimum size of the rectangle between the arrows */
63 #define SCROLL_MIN_RECT 4
65 /* Minimum size of the thumb in pixels */
66 #define SCROLL_MIN_THUMB 6
68 /* Overlap between arrows and thumb */
69 #define SCROLL_ARROW_THUMB_OVERLAP 0
71 /* Delay (in ms) before first repetition when holding the button down */
72 #define SCROLL_FIRST_DELAY 200
74 /* Delay (in ms) between scroll repetitions */
75 #define SCROLL_REPEAT_DELAY 50
78 #define SCROLL_TIMER 0
80 /* Scroll-bar hit testing */
83 SCROLL_NOWHERE, /* Outside the scroll bar */
84 SCROLL_TOP_ARROW, /* Top or left arrow */
85 SCROLL_TOP_RECT, /* Rectangle between the top arrow and the thumb */
86 SCROLL_THUMB, /* Thumb rectangle */
87 SCROLL_BOTTOM_RECT, /* Rectangle between the thumb and the bottom arrow */
88 SCROLL_BOTTOM_ARROW /* Bottom or right arrow */
91 /* What to do after SCROLL_SetScrollInfo() */
92 #define SA_SSI_HIDE 0x0001
93 #define SA_SSI_SHOW 0x0002
94 #define SA_SSI_REFRESH 0x0004
95 #define SA_SSI_REPAINT_ARROWS 0x0008
97 /* Thumb-tracking info */
98 static HWND SCROLL_TrackingWin = 0;
99 static INT SCROLL_TrackingBar = 0;
100 static INT SCROLL_TrackingPos = 0;
101 static INT SCROLL_TrackingVal = 0;
102 /* Hit test code of the last button-down event */
103 static enum SCROLL_HITTEST SCROLL_trackHitTest;
104 static BOOL SCROLL_trackVertical;
106 /* Is the moving thumb being displayed? */
107 static BOOL SCROLL_MovingThumb = FALSE;
109 /* Local functions */
110 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar,
111 BOOL fShowH, BOOL fShowV );
112 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar,
113 const SCROLLINFO *info, BOOL bRedraw );
114 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
115 RECT *rect, INT arrowSize,
116 INT thumbSize, INT thumbPos,
117 UINT flags, BOOL vertical,
118 BOOL top_selected, BOOL bottom_selected );
121 /*********************************************************************
122 * scrollbar class descriptor
124 static const WCHAR scrollbarW[] = {'S','c','r','o','l','l','B','a','r',0};
125 const struct builtin_class_descr SCROLL_builtin_class =
127 scrollbarW, /* name */
128 CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC, /* style */
129 WINPROC_SCROLLBAR, /* proc */
130 sizeof(SCROLLBAR_INFO), /* extra */
131 IDC_ARROW, /* cursor */
135 /***********************************************************************
136 * SCROLL_ScrollInfoValid
138 * Determine if the supplied SCROLLINFO struct is valid.
139 * info [in] The SCROLLINFO struct to be tested
141 static inline BOOL SCROLL_ScrollInfoValid( LPCSCROLLINFO info )
143 return !(info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)
144 || (info->cbSize != sizeof(*info)
145 && info->cbSize != sizeof(*info) - sizeof(info->nTrackPos)));
149 /***********************************************************************
150 * SCROLL_GetInternalInfo
152 * Returns pointer to internal SCROLLBAR_INFO structure for nBar
153 * or NULL if failed (f.i. scroll bar does not exist yet)
154 * If alloc is TRUE and the struct does not exist yet, create it.
156 static SCROLLBAR_INFO *SCROLL_GetInternalInfo( HWND hwnd, INT nBar, BOOL alloc )
158 SCROLLBAR_INFO *infoPtr = NULL;
159 WND *wndPtr = WIN_GetPtr( hwnd );
161 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return NULL;
165 if (wndPtr->pScroll) infoPtr = &((LPWINSCROLLBAR_INFO)wndPtr->pScroll)->horz;
168 if (wndPtr->pScroll) infoPtr = &((LPWINSCROLLBAR_INFO)wndPtr->pScroll)->vert;
171 infoPtr = (SCROLLBAR_INFO *)wndPtr->wExtra;
174 WARN("with SB_BOTH\n");
178 if (!infoPtr && alloc)
180 WINSCROLLBAR_INFO *winInfoPtr;
182 if (nBar != SB_HORZ && nBar != SB_VERT)
183 WARN("Cannot initialize nBar=%d\n",nBar);
184 else if ((winInfoPtr = HeapAlloc( GetProcessHeap(), 0, sizeof(WINSCROLLBAR_INFO) )))
186 /* Set default values */
187 winInfoPtr->horz.minVal = 0;
188 winInfoPtr->horz.curVal = 0;
189 winInfoPtr->horz.page = 0;
190 /* From MSDN and our own tests:
191 * max for a standard scroll bar is 100 by default. */
192 winInfoPtr->horz.maxVal = 100;
193 winInfoPtr->horz.flags = ESB_ENABLE_BOTH;
194 winInfoPtr->vert = winInfoPtr->horz;
195 wndPtr->pScroll = winInfoPtr;
196 infoPtr = nBar == SB_HORZ ? &winInfoPtr->horz : &winInfoPtr->vert;
199 WIN_ReleasePtr( wndPtr );
204 /***********************************************************************
205 * SCROLL_GetScrollBarRect
207 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
208 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
209 * 'arrowSize' returns the width or height of an arrow (depending on
210 * the orientation of the scrollbar), 'thumbSize' returns the size of
211 * the thumb, and 'thumbPos' returns the position of the thumb
212 * relative to the left or to the top.
213 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
215 static BOOL SCROLL_GetScrollBarRect( HWND hwnd, INT nBar, RECT *lprect,
216 INT *arrowSize, INT *thumbSize,
221 WND *wndPtr = WIN_GetPtr( hwnd );
223 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
228 WIN_GetRectangles( hwnd, COORDS_WINDOW, NULL, lprect );
229 lprect->top = lprect->bottom;
230 lprect->bottom += GetSystemMetrics(SM_CYHSCROLL);
231 if(wndPtr->dwStyle & WS_VSCROLL)
237 WIN_GetRectangles( hwnd, COORDS_WINDOW, NULL, lprect );
238 if((wndPtr->dwExStyle & WS_EX_LEFTSCROLLBAR) != 0)
240 lprect->right = lprect->left;
241 lprect->left -= GetSystemMetrics(SM_CXVSCROLL);
245 lprect->left = lprect->right;
246 lprect->right += GetSystemMetrics(SM_CXVSCROLL);
248 if(wndPtr->dwStyle & WS_HSCROLL)
254 GetClientRect( hwnd, lprect );
255 vertical = ((wndPtr->dwStyle & SBS_VERT) != 0);
259 WIN_ReleasePtr( wndPtr );
263 if (vertical) pixels = lprect->bottom - lprect->top;
264 else pixels = lprect->right - lprect->left;
266 if (pixels <= 2*GetSystemMetrics(SM_CXVSCROLL) + SCROLL_MIN_RECT)
268 if (pixels > SCROLL_MIN_RECT)
269 *arrowSize = (pixels - SCROLL_MIN_RECT) / 2;
272 *thumbPos = *thumbSize = 0;
276 SCROLLBAR_INFO *info = SCROLL_GetInternalInfo( hwnd, nBar, FALSE );
279 WARN("called for missing scroll bar\n");
280 WIN_ReleasePtr( wndPtr );
283 *arrowSize = GetSystemMetrics(SM_CXVSCROLL);
284 pixels -= (2 * (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP));
288 *thumbSize = MulDiv(pixels,info->page,(info->maxVal-info->minVal+1));
289 if (*thumbSize < SCROLL_MIN_THUMB) *thumbSize = SCROLL_MIN_THUMB;
291 else *thumbSize = GetSystemMetrics(SM_CXVSCROLL);
293 if (((pixels -= *thumbSize ) < 0) ||
294 ((info->flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH))
296 /* Rectangle too small or scrollbar disabled -> no thumb */
297 *thumbPos = *thumbSize = 0;
301 INT max = info->maxVal - max( info->page-1, 0 );
302 if (info->minVal >= max)
303 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
305 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP
306 + MulDiv(pixels, (info->curVal-info->minVal),(max - info->minVal));
309 WIN_ReleasePtr( wndPtr );
314 /***********************************************************************
317 * Compute the current scroll position based on the thumb position in pixels
318 * from the top of the scroll-bar.
320 static UINT SCROLL_GetThumbVal( SCROLLBAR_INFO *infoPtr, RECT *rect,
321 BOOL vertical, INT pos )
324 INT pixels = vertical ? rect->bottom-rect->top : rect->right-rect->left;
327 if ((pixels -= 2*(GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP)) <= 0)
328 return infoPtr->minVal;
332 thumbSize = MulDiv(pixels,infoPtr->page,(infoPtr->maxVal-infoPtr->minVal+1));
333 if (thumbSize < SCROLL_MIN_THUMB) thumbSize = SCROLL_MIN_THUMB;
335 else thumbSize = GetSystemMetrics(SM_CXVSCROLL);
337 if ((pixels -= thumbSize) <= 0) return infoPtr->minVal;
339 pos = max( 0, pos - (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP) );
340 if (pos > pixels) pos = pixels;
343 range = infoPtr->maxVal - infoPtr->minVal;
345 range = infoPtr->maxVal - infoPtr->minVal - infoPtr->page + 1;
347 return infoPtr->minVal + MulDiv(pos, range, pixels);
350 /***********************************************************************
353 static BOOL SCROLL_PtInRectEx( LPRECT lpRect, POINT pt, BOOL vertical )
358 /* Pad hit rect to allow mouse to be dragged outside of scrollbar and
359 * still be considered in the scrollbar. */
362 scrollbarWidth = lpRect->right - lpRect->left;
363 rect.left -= scrollbarWidth*8;
364 rect.right += scrollbarWidth*8;
365 rect.top -= scrollbarWidth*2;
366 rect.bottom += scrollbarWidth*2;
370 scrollbarWidth = lpRect->bottom - lpRect->top;
371 rect.left -= scrollbarWidth*2;
372 rect.right += scrollbarWidth*2;
373 rect.top -= scrollbarWidth*8;
374 rect.bottom += scrollbarWidth*8;
376 return PtInRect( &rect, pt );
379 /***********************************************************************
382 static POINT SCROLL_ClipPos( LPRECT lpRect, POINT pt )
384 if( pt.x < lpRect->left )
387 if( pt.x > lpRect->right )
388 pt.x = lpRect->right;
390 if( pt.y < lpRect->top )
393 if( pt.y > lpRect->bottom )
394 pt.y = lpRect->bottom;
400 /***********************************************************************
403 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
405 static enum SCROLL_HITTEST SCROLL_HitTest( HWND hwnd, INT nBar,
406 POINT pt, BOOL bDragging )
408 INT arrowSize, thumbSize, thumbPos;
411 BOOL vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
412 &arrowSize, &thumbSize, &thumbPos );
414 if ( (bDragging && !SCROLL_PtInRectEx( &rect, pt, vertical )) ||
415 (!PtInRect( &rect, pt )) ) return SCROLL_NOWHERE;
419 if (pt.y < rect.top + arrowSize) return SCROLL_TOP_ARROW;
420 if (pt.y >= rect.bottom - arrowSize) return SCROLL_BOTTOM_ARROW;
421 if (!thumbPos) return SCROLL_TOP_RECT;
423 if (pt.y < thumbPos) return SCROLL_TOP_RECT;
424 if (pt.y >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
426 else /* horizontal */
428 if (pt.x < rect.left + arrowSize) return SCROLL_TOP_ARROW;
429 if (pt.x >= rect.right - arrowSize) return SCROLL_BOTTOM_ARROW;
430 if (!thumbPos) return SCROLL_TOP_RECT;
432 if (pt.x < thumbPos) return SCROLL_TOP_RECT;
433 if (pt.x >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
439 /***********************************************************************
442 * Draw the scroll bar arrows.
444 static void SCROLL_DrawArrows( HDC hdc, SCROLLBAR_INFO *infoPtr,
445 RECT *rect, INT arrowSize, BOOL vertical,
446 BOOL top_pressed, BOOL bottom_pressed )
452 r.bottom = r.top + arrowSize;
454 r.right = r.left + arrowSize;
456 DrawFrameControl( hdc, &r, DFC_SCROLL,
457 (vertical ? DFCS_SCROLLUP : DFCS_SCROLLLEFT)
458 | (top_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
459 | (infoPtr->flags&ESB_DISABLE_LTUP ? DFCS_INACTIVE : 0 ) );
463 r.top = r.bottom-arrowSize;
465 r.left = r.right-arrowSize;
467 DrawFrameControl( hdc, &r, DFC_SCROLL,
468 (vertical ? DFCS_SCROLLDOWN : DFCS_SCROLLRIGHT)
469 | (bottom_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
470 | (infoPtr->flags&ESB_DISABLE_RTDN ? DFCS_INACTIVE : 0) );
473 static void SCROLL_DrawMovingThumb( HDC hdc, RECT *rect, BOOL vertical,
474 INT arrowSize, INT thumbSize )
476 INT pos = SCROLL_TrackingPos;
480 max_size = rect->bottom - rect->top;
482 max_size = rect->right - rect->left;
484 max_size -= (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) + thumbSize;
486 if( pos < (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) )
487 pos = (arrowSize-SCROLL_ARROW_THUMB_OVERLAP);
488 else if( pos > max_size )
491 SCROLL_DrawInterior_9x( SCROLL_TrackingWin, hdc, SCROLL_TrackingBar,
492 rect, arrowSize, thumbSize, pos,
493 0, vertical, FALSE, FALSE );
495 SCROLL_MovingThumb = !SCROLL_MovingThumb;
498 /***********************************************************************
499 * SCROLL_DrawInterior
501 * Draw the scroll bar interior (everything except the arrows).
503 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
504 RECT *rect, INT arrowSize,
505 INT thumbSize, INT thumbPos,
506 UINT flags, BOOL vertical,
507 BOOL top_selected, BOOL bottom_selected )
511 HBRUSH hSaveBrush,hBrush;
513 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
514 * The window-owned scrollbars need to call DEFWND_ControlColor
515 * to correctly setup default scrollbar colors
519 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
520 (WPARAM)hdc,(LPARAM)hwnd);
524 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
527 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
528 hSaveBrush = SelectObject( hdc, hBrush );
530 /* Calculate the scroll rectangle */
534 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
535 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
539 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
540 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
543 /* Draw the scroll rectangles and thumb */
544 if (!thumbPos) /* No thumb to draw */
546 PatBlt( hdc, r.left, r.top,
547 r.right - r.left, r.bottom - r.top,
550 /* cleanup and return */
551 SelectObject( hdc, hSavePen );
552 SelectObject( hdc, hSaveBrush );
558 PatBlt( hdc, r.left, r.top,
560 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
561 top_selected ? 0x0f0000 : PATCOPY );
562 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
563 PatBlt( hdc, r.left, r.top + thumbSize,
565 r.bottom - r.top - thumbSize,
566 bottom_selected ? 0x0f0000 : PATCOPY );
567 r.bottom = r.top + thumbSize;
569 else /* horizontal */
571 PatBlt( hdc, r.left, r.top,
572 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
574 top_selected ? 0x0f0000 : PATCOPY );
575 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
576 PatBlt( hdc, r.left + thumbSize, r.top,
577 r.right - r.left - thumbSize,
579 bottom_selected ? 0x0f0000 : PATCOPY );
580 r.right = r.left + thumbSize;
584 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT | BF_MIDDLE );
587 SelectObject( hdc, hSavePen );
588 SelectObject( hdc, hSaveBrush );
592 static void SCROLL_DrawInterior( HWND hwnd, HDC hdc, INT nBar,
593 RECT *rect, INT arrowSize,
594 INT thumbSize, INT thumbPos,
595 UINT flags, BOOL vertical,
596 BOOL top_selected, BOOL bottom_selected )
600 HBRUSH hSaveBrush,hBrush;
601 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
603 if (Save_SCROLL_MovingThumb &&
604 (SCROLL_TrackingWin == hwnd) &&
605 (SCROLL_TrackingBar == nBar))
606 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
608 /* Select the correct brush and pen */
610 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
611 * The window-owned scrollbars need to call DEFWND_ControlColor
612 * to correctly setup default scrollbar colors
614 if (nBar == SB_CTL) {
615 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
616 (WPARAM)hdc,(LPARAM)hwnd);
618 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
620 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
621 hSaveBrush = SelectObject( hdc, hBrush );
623 /* Calculate the scroll rectangle */
628 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
629 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
633 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
634 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
637 /* Draw the scroll bar frame */
639 /* Draw the scroll rectangles and thumb */
641 if (!thumbPos) /* No thumb to draw */
643 PatBlt( hdc, r.left, r.top, r.right - r.left, r.bottom - r.top, PATCOPY );
645 /* cleanup and return */
646 SelectObject( hdc, hSavePen );
647 SelectObject( hdc, hSaveBrush );
653 PatBlt( hdc, r.left, r.top, r.right - r.left,
654 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
655 top_selected ? 0x0f0000 : PATCOPY );
656 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
657 PatBlt( hdc, r.left, r.top + thumbSize, r.right - r.left,
658 r.bottom - r.top - thumbSize,
659 bottom_selected ? 0x0f0000 : PATCOPY );
660 r.bottom = r.top + thumbSize;
662 else /* horizontal */
664 PatBlt( hdc, r.left, r.top,
665 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
666 r.bottom - r.top, top_selected ? 0x0f0000 : PATCOPY );
667 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
668 PatBlt( hdc, r.left + thumbSize, r.top, r.right - r.left - thumbSize,
669 r.bottom - r.top, bottom_selected ? 0x0f0000 : PATCOPY );
670 r.right = r.left + thumbSize;
675 SelectObject( hdc, GetSysColorBrush(COLOR_BTNFACE) );
676 Rectangle( hdc, r.left+1, r.top+1, r.right-1, r.bottom-1 );
677 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT );
679 if (Save_SCROLL_MovingThumb &&
680 (SCROLL_TrackingWin == hwnd) &&
681 (SCROLL_TrackingBar == nBar))
682 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
685 SelectObject( hdc, hSavePen );
686 SelectObject( hdc, hSaveBrush );
690 /***********************************************************************
691 * SCROLL_DrawScrollBar
693 * Redraw the whole scrollbar.
695 void SCROLL_DrawScrollBar( HWND hwnd, HDC hdc, INT nBar,
696 BOOL arrows, BOOL interior )
698 INT arrowSize, thumbSize, thumbPos;
701 SCROLLBAR_INFO *infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, TRUE );
702 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
703 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
705 if (!(hwnd = WIN_GetFullHandle( hwnd ))) return;
708 ((nBar == SB_VERT) && !(style & WS_VSCROLL)) ||
709 ((nBar == SB_HORZ) && !(style & WS_HSCROLL))) return;
710 if (!WIN_IsWindowDrawable( hwnd, FALSE )) return;
712 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
713 &arrowSize, &thumbSize, &thumbPos );
715 /* do not draw if the scrollbar rectangle is empty */
716 if(IsRectEmpty(&rect)) return;
718 if (Save_SCROLL_MovingThumb &&
719 (SCROLL_TrackingWin == hwnd) &&
720 (SCROLL_TrackingBar == nBar))
721 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
723 /* Draw the arrows */
725 if (arrows && arrowSize)
727 if( vertical == SCROLL_trackVertical && GetCapture() == hwnd )
728 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
729 (SCROLL_trackHitTest == SCROLL_TOP_ARROW),
730 (SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW) );
732 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
736 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
737 thumbPos, infoPtr->flags, vertical, FALSE, FALSE );
739 if (Save_SCROLL_MovingThumb &&
740 (SCROLL_TrackingWin == hwnd) &&
741 (SCROLL_TrackingBar == nBar))
742 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
744 /* if scroll bar has focus, reposition the caret */
745 if(hwnd==GetFocus() && (nBar==SB_CTL))
749 SetCaretPos(thumbPos+1, rect.top+1);
753 SetCaretPos(rect.top+1, thumbPos+1);
758 /***********************************************************************
759 * SCROLL_DrawSizeGrip
761 * Draw the size grip.
763 static void SCROLL_DrawSizeGrip( HWND hwnd, HDC hdc)
767 GetClientRect( hwnd, &rc );
768 FillRect( hdc, &rc, GetSysColorBrush(COLOR_SCROLLBAR) );
769 rc.left = max( rc.left, rc.right - GetSystemMetrics(SM_CXVSCROLL) - 1 );
770 rc.top = max( rc.top, rc.bottom - GetSystemMetrics(SM_CYHSCROLL) - 1 );
771 DrawFrameControl( hdc, &rc, DFC_SCROLL, DFCS_SCROLLSIZEGRIP );
775 /***********************************************************************
776 * SCROLL_RefreshScrollBar
778 * Repaint the scroll bar interior after a SetScrollRange() or
779 * SetScrollPos() call.
781 static void SCROLL_RefreshScrollBar( HWND hwnd, INT nBar,
782 BOOL arrows, BOOL interior )
784 HDC hdc = GetDCEx( hwnd, 0,
785 DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW) );
788 SCROLL_DrawScrollBar( hwnd, hdc, nBar, arrows, interior );
789 ReleaseDC( hwnd, hdc );
793 /***********************************************************************
794 * SCROLL_HandleKbdEvent
796 * Handle a keyboard event (only for SB_CTL scrollbars with focus).
799 * hwnd [I] Handle of window with scrollbar(s)
800 * wParam [I] Variable input including enable state
801 * lParam [I] Variable input including input point
803 static void SCROLL_HandleKbdEvent(HWND hwnd, WPARAM wParam, LPARAM lParam)
805 TRACE("hwnd=%p wParam=%ld lParam=%ld\n", hwnd, wParam, lParam);
807 /* hide caret on first KEYDOWN to prevent flicker */
808 if ((lParam & PFD_DOUBLEBUFFER_DONTCARE) == 0)
813 case VK_PRIOR: wParam = SB_PAGEUP; break;
814 case VK_NEXT: wParam = SB_PAGEDOWN; break;
815 case VK_HOME: wParam = SB_TOP; break;
816 case VK_END: wParam = SB_BOTTOM; break;
817 case VK_UP: wParam = SB_LINEUP; break;
818 case VK_DOWN: wParam = SB_LINEDOWN; break;
819 case VK_LEFT: wParam = SB_LINEUP; break;
820 case VK_RIGHT: wParam = SB_LINEDOWN; break;
823 SendMessageW(GetParent(hwnd),
824 ((GetWindowLongW( hwnd, GWL_STYLE ) & SBS_VERT) ?
825 WM_VSCROLL : WM_HSCROLL), wParam, (LPARAM)hwnd);
829 /***********************************************************************
830 * SCROLL_HandleScrollEvent
832 * Handle a mouse or timer event for the scrollbar.
833 * 'pt' is the location of the mouse event in client (for SB_CTL) or
834 * windows coordinates.
836 static void SCROLL_HandleScrollEvent( HWND hwnd, INT nBar, UINT msg, POINT pt)
838 /* Previous mouse position for timer events */
840 /* Thumb position when tracking started. */
841 static UINT trackThumbPos;
842 /* Position in the scroll-bar of the last button-down event. */
843 static INT lastClickPos;
844 /* Position in the scroll-bar of the last mouse event. */
845 static INT lastMousePos;
847 enum SCROLL_HITTEST hittest;
848 HWND hwndOwner, hwndCtl;
850 INT arrowSize, thumbSize, thumbPos;
854 SCROLLBAR_INFO *infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, FALSE );
855 if (!infoPtr) return;
856 if ((SCROLL_trackHitTest == SCROLL_NOWHERE) && (msg != WM_LBUTTONDOWN))
859 if (nBar == SB_CTL && (GetWindowLongW( hwnd, GWL_STYLE ) & (SBS_SIZEGRIP | SBS_SIZEBOX)))
863 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
864 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
867 SCROLL_trackHitTest = hittest = SCROLL_THUMB;
870 GetClientRect(GetParent(GetParent(hwnd)),&rect);
875 SCROLL_trackHitTest = hittest = SCROLL_NOWHERE;
876 if (hwnd==GetFocus()) ShowCaret(hwnd);
885 hdc = GetDCEx( hwnd, 0, DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW));
886 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
887 &arrowSize, &thumbSize, &thumbPos );
888 hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd) : hwnd;
889 hwndCtl = (nBar == SB_CTL) ? hwnd : 0;
893 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
894 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
895 SCROLL_trackVertical = vertical;
896 SCROLL_trackHitTest = hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
897 lastClickPos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
898 lastMousePos = lastClickPos;
899 trackThumbPos = thumbPos;
901 if (nBar == SB_CTL && (GetWindowLongW(hwnd, GWL_STYLE) & WS_TABSTOP)) SetFocus( hwnd );
906 hittest = SCROLL_HitTest( hwnd, nBar, pt, TRUE );
911 hittest = SCROLL_NOWHERE;
913 /* if scrollbar has focus, show back caret */
914 if (hwnd==GetFocus()) ShowCaret(hwnd);
919 hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
923 return; /* Should never happen */
926 TRACE("Event: hwnd=%p bar=%d msg=%s pt=%d,%d hit=%d\n",
927 hwnd, nBar, SPY_GetMsgName(msg,hwnd), pt.x, pt.y, hittest );
929 switch(SCROLL_trackHitTest)
931 case SCROLL_NOWHERE: /* No tracking in progress */
934 case SCROLL_TOP_ARROW:
935 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
936 (hittest == SCROLL_trackHitTest), FALSE );
937 if (hittest == SCROLL_trackHitTest)
939 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
941 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
942 SB_LINEUP, (LPARAM)hwndCtl );
945 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
946 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
948 else KillSystemTimer( hwnd, SCROLL_TIMER );
951 case SCROLL_TOP_RECT:
952 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
953 thumbPos, infoPtr->flags, vertical,
954 (hittest == SCROLL_trackHitTest), FALSE );
955 if (hittest == SCROLL_trackHitTest)
957 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
959 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
960 SB_PAGEUP, (LPARAM)hwndCtl );
962 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
963 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
965 else KillSystemTimer( hwnd, SCROLL_TIMER );
969 if (msg == WM_LBUTTONDOWN)
971 SCROLL_TrackingWin = hwnd;
972 SCROLL_TrackingBar = nBar;
973 SCROLL_TrackingPos = trackThumbPos + lastMousePos - lastClickPos;
974 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
976 SCROLL_TrackingPos );
977 if (!SCROLL_MovingThumb)
978 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
980 else if (msg == WM_LBUTTONUP)
982 if (SCROLL_MovingThumb)
983 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
985 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
986 thumbPos, infoPtr->flags, vertical,
989 else /* WM_MOUSEMOVE */
993 if (!SCROLL_PtInRectEx( &rect, pt, vertical )) pos = lastClickPos;
996 pt = SCROLL_ClipPos( &rect, pt );
997 pos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
999 if ( (pos != lastMousePos) || (!SCROLL_MovingThumb) )
1001 if (SCROLL_MovingThumb)
1002 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
1003 arrowSize, thumbSize );
1005 SCROLL_TrackingPos = trackThumbPos + pos - lastClickPos;
1006 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
1008 SCROLL_TrackingPos );
1009 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1010 MAKEWPARAM( SB_THUMBTRACK, SCROLL_TrackingVal),
1012 if (!SCROLL_MovingThumb)
1013 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
1014 arrowSize, thumbSize );
1019 case SCROLL_BOTTOM_RECT:
1020 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
1021 thumbPos, infoPtr->flags, vertical,
1022 FALSE, (hittest == SCROLL_trackHitTest) );
1023 if (hittest == SCROLL_trackHitTest)
1025 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1027 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1028 SB_PAGEDOWN, (LPARAM)hwndCtl );
1030 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1031 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
1033 else KillSystemTimer( hwnd, SCROLL_TIMER );
1036 case SCROLL_BOTTOM_ARROW:
1037 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
1038 FALSE, (hittest == SCROLL_trackHitTest) );
1039 if (hittest == SCROLL_trackHitTest)
1041 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1043 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1044 SB_LINEDOWN, (LPARAM)hwndCtl );
1047 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1048 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
1050 else KillSystemTimer( hwnd, SCROLL_TIMER );
1054 if (msg == WM_LBUTTONDOWN)
1057 if (hittest == SCROLL_THUMB)
1059 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1060 trackThumbPos + lastMousePos - lastClickPos );
1061 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1062 MAKEWPARAM( SB_THUMBTRACK, val ), (LPARAM)hwndCtl );
1066 if (msg == WM_LBUTTONUP)
1068 hittest = SCROLL_trackHitTest;
1069 SCROLL_trackHitTest = SCROLL_NOWHERE; /* Terminate tracking */
1071 if (hittest == SCROLL_THUMB)
1073 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1074 trackThumbPos + lastMousePos - lastClickPos );
1075 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1076 MAKEWPARAM( SB_THUMBPOSITION, val ), (LPARAM)hwndCtl );
1078 /* SB_ENDSCROLL doesn't report thumb position */
1079 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1080 SB_ENDSCROLL, (LPARAM)hwndCtl );
1082 /* Terminate tracking */
1083 SCROLL_TrackingWin = 0;
1086 ReleaseDC( hwnd, hdc );
1090 /***********************************************************************
1091 * SCROLL_TrackScrollBar
1093 * Track a mouse button press on a scroll-bar.
1094 * pt is in screen-coordinates for non-client scroll bars.
1096 void SCROLL_TrackScrollBar( HWND hwnd, INT scrollbar, POINT pt )
1099 INT xoffset = 0, yoffset = 0;
1101 if (scrollbar != SB_CTL)
1104 WIN_GetRectangles( hwnd, COORDS_CLIENT, &rect, NULL );
1105 ScreenToClient( hwnd, &pt );
1110 SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt );
1114 if (!GetMessageW( &msg, 0, 0, 0 )) break;
1115 if (CallMsgFilterW( &msg, MSGF_SCROLLBAR )) continue;
1116 if (msg.message == WM_LBUTTONUP ||
1117 msg.message == WM_MOUSEMOVE ||
1118 (msg.message == WM_SYSTIMER && msg.wParam == SCROLL_TIMER))
1120 pt.x = (short)LOWORD(msg.lParam) + xoffset;
1121 pt.y = (short)HIWORD(msg.lParam) + yoffset;
1122 SCROLL_HandleScrollEvent( hwnd, scrollbar, msg.message, pt );
1126 TranslateMessage( &msg );
1127 DispatchMessageW( &msg );
1129 if (!IsWindow( hwnd ))
1134 } while (msg.message != WM_LBUTTONUP && GetCapture() == hwnd);
1138 /***********************************************************************
1139 * SCROLL_CreateScrollBar
1141 * Create a scroll bar
1144 * hwnd [I] Handle of window with scrollbar(s)
1145 * lpCreate [I] The style and place of the scroll bar
1147 static void SCROLL_CreateScrollBar(HWND hwnd, LPCREATESTRUCTW lpCreate)
1149 LPSCROLLBAR_INFO info = SCROLL_GetInternalInfo(hwnd, SB_CTL, TRUE);
1152 TRACE("hwnd=%p lpCreate=%p\n", hwnd, lpCreate);
1154 if (lpCreate->style & WS_DISABLED)
1156 info->flags = ESB_DISABLE_BOTH;
1157 TRACE("Created WS_DISABLED scrollbar\n");
1161 if (lpCreate->style & (SBS_SIZEGRIP | SBS_SIZEBOX))
1163 if (lpCreate->style & SBS_SIZEBOXTOPLEFTALIGN)
1164 MoveWindow( hwnd, lpCreate->x, lpCreate->y, GetSystemMetrics(SM_CXVSCROLL)+1,
1165 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1166 else if(lpCreate->style & SBS_SIZEBOXBOTTOMRIGHTALIGN)
1167 MoveWindow( hwnd, lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1168 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1169 GetSystemMetrics(SM_CXVSCROLL)+1,
1170 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1172 else if (lpCreate->style & SBS_VERT)
1174 if (lpCreate->style & SBS_LEFTALIGN)
1175 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1176 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1177 else if (lpCreate->style & SBS_RIGHTALIGN)
1179 lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1181 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1185 if (lpCreate->style & SBS_TOPALIGN)
1186 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1187 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1188 else if (lpCreate->style & SBS_BOTTOMALIGN)
1191 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1192 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1197 /*************************************************************************
1198 * SCROLL_GetScrollInfo
1200 * Internal helper for the API function
1203 * hwnd [I] Handle of window with scrollbar(s)
1204 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1205 * info [IO] fMask specifies which values to retrieve
1208 * FALSE if requested field not filled (f.i. scroll bar does not exist)
1210 static BOOL SCROLL_GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1212 LPSCROLLBAR_INFO infoPtr;
1214 /* handle invalid data structure */
1215 if (!SCROLL_ScrollInfoValid(info)
1216 || !(infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE)))
1219 /* fill in the desired scroll info structure */
1220 if (info->fMask & SIF_PAGE) info->nPage = infoPtr->page;
1221 if (info->fMask & SIF_POS) info->nPos = infoPtr->curVal;
1222 if ((info->fMask & SIF_TRACKPOS) && (info->cbSize == sizeof(*info)))
1223 info->nTrackPos = (SCROLL_TrackingWin == WIN_GetFullHandle(hwnd)) ? SCROLL_TrackingVal : infoPtr->curVal;
1224 if (info->fMask & SIF_RANGE)
1226 info->nMin = infoPtr->minVal;
1227 info->nMax = infoPtr->maxVal;
1230 TRACE("cbSize %02x fMask %04x nMin %d nMax %d nPage %u nPos %d nTrackPos %d\n",
1231 info->cbSize, info->fMask, info->nMin, info->nMax, info->nPage,
1232 info->nPos, info->nTrackPos);
1234 return (info->fMask & SIF_ALL) != 0;
1238 /*************************************************************************
1239 * SCROLL_GetScrollBarInfo
1241 * Internal helper for the API function
1244 * hwnd [I] Handle of window with scrollbar(s)
1245 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1246 * info [IO] cbSize specifies the size of the structure
1251 static BOOL SCROLL_GetScrollBarInfo(HWND hwnd, LONG idObject, LPSCROLLBARINFO info)
1253 LPSCROLLBAR_INFO infoPtr;
1256 DWORD style = GetWindowLongW(hwnd, GWL_STYLE);
1262 case OBJID_CLIENT: nBar = SB_CTL; break;
1263 case OBJID_HSCROLL: nBar = SB_HORZ; break;
1264 case OBJID_VSCROLL: nBar = SB_VERT; break;
1265 default: return FALSE;
1268 /* handle invalid data structure */
1269 if (info->cbSize != sizeof(*info))
1272 SCROLL_GetScrollBarRect(hwnd, nBar, &info->rcScrollBar, &nDummy,
1273 &info->dxyLineButton, &info->xyThumbTop);
1274 /* rcScrollBar needs to be in screen coordinates */
1275 GetWindowRect(hwnd, &rect);
1276 OffsetRect(&info->rcScrollBar, rect.left, rect.top);
1278 info->xyThumbBottom = info->xyThumbTop + info->dxyLineButton;
1280 infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, TRUE);
1284 /* Scroll bar state */
1285 info->rgstate[0] = 0;
1286 if ((nBar == SB_HORZ && !(style & WS_HSCROLL))
1287 || (nBar == SB_VERT && !(style & WS_VSCROLL)))
1288 info->rgstate[0] |= STATE_SYSTEM_INVISIBLE;
1289 if (infoPtr->minVal >= infoPtr->maxVal - max(infoPtr->page - 1, 0))
1291 if (!(info->rgstate[0] & STATE_SYSTEM_INVISIBLE))
1292 info->rgstate[0] |= STATE_SYSTEM_UNAVAILABLE;
1294 info->rgstate[0] |= STATE_SYSTEM_OFFSCREEN;
1296 if (nBar == SB_CTL && !IsWindowEnabled(hwnd))
1297 info->rgstate[0] |= STATE_SYSTEM_UNAVAILABLE;
1299 pressed = ((nBar == SB_VERT) == SCROLL_trackVertical && GetCapture() == hwnd);
1301 /* Top/left arrow button state. MSDN says top/right, but I don't believe it */
1302 info->rgstate[1] = 0;
1303 if (pressed && SCROLL_trackHitTest == SCROLL_TOP_ARROW)
1304 info->rgstate[1] |= STATE_SYSTEM_PRESSED;
1305 if (infoPtr->flags & ESB_DISABLE_LTUP)
1306 info->rgstate[1] |= STATE_SYSTEM_UNAVAILABLE;
1308 /* Page up/left region state. MSDN says up/right, but I don't believe it */
1309 info->rgstate[2] = 0;
1310 if (infoPtr->curVal == infoPtr->minVal)
1311 info->rgstate[2] |= STATE_SYSTEM_INVISIBLE;
1312 if (pressed && SCROLL_trackHitTest == SCROLL_TOP_RECT)
1313 info->rgstate[2] |= STATE_SYSTEM_PRESSED;
1316 info->rgstate[3] = 0;
1317 if (pressed && SCROLL_trackHitTest == SCROLL_THUMB)
1318 info->rgstate[3] |= STATE_SYSTEM_PRESSED;
1320 /* Page down/right region state. MSDN says down/left, but I don't believe it */
1321 info->rgstate[4] = 0;
1322 if (infoPtr->curVal >= infoPtr->maxVal - 1)
1323 info->rgstate[4] |= STATE_SYSTEM_INVISIBLE;
1324 if (pressed && SCROLL_trackHitTest == SCROLL_BOTTOM_RECT)
1325 info->rgstate[4] |= STATE_SYSTEM_PRESSED;
1327 /* Bottom/right arrow button state. MSDN says bottom/left, but I don't believe it */
1328 info->rgstate[5] = 0;
1329 if (pressed && SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW)
1330 info->rgstate[5] |= STATE_SYSTEM_PRESSED;
1331 if (infoPtr->flags & ESB_DISABLE_RTDN)
1332 info->rgstate[5] |= STATE_SYSTEM_UNAVAILABLE;
1338 /*************************************************************************
1339 * SCROLL_GetScrollPos
1341 * Internal helper for the API function
1344 * hwnd [I] Handle of window with scrollbar(s)
1345 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1347 static INT SCROLL_GetScrollPos(HWND hwnd, INT nBar)
1349 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1350 return infoPtr ? infoPtr->curVal: 0;
1354 /*************************************************************************
1355 * SCROLL_GetScrollRange
1357 * Internal helper for the API function
1360 * hwnd [I] Handle of window with scrollbar(s)
1361 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1362 * lpMin [O] Where to store minimum value
1363 * lpMax [O] Where to store maximum value
1369 static BOOL SCROLL_GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1371 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1373 if (lpMin) *lpMin = infoPtr ? infoPtr->minVal : 0;
1374 if (lpMax) *lpMax = infoPtr ? infoPtr->maxVal : 0;
1380 /*************************************************************************
1381 * SCROLL_SetScrollRange
1384 * hwnd [I] Handle of window with scrollbar(s)
1385 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1386 * lpMin [I] Minimum value
1387 * lpMax [I] Maximum value
1390 static BOOL SCROLL_SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal)
1392 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1394 TRACE("hwnd=%p nBar=%d min=%d max=%d\n", hwnd, nBar, minVal, maxVal);
1398 infoPtr->minVal = minVal;
1399 infoPtr->maxVal = maxVal;
1405 /***********************************************************************
1406 * ScrollBarWndProc_common
1408 LRESULT ScrollBarWndProc_common( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, BOOL unicode )
1410 if (!IsWindow( hwnd )) return 0;
1415 SCROLL_CreateScrollBar(hwnd, (LPCREATESTRUCTW)lParam);
1420 SCROLLBAR_INFO *infoPtr;
1421 if ((infoPtr = SCROLL_GetInternalInfo( hwnd, SB_CTL, FALSE )))
1423 infoPtr->flags = wParam ? ESB_ENABLE_BOTH : ESB_DISABLE_BOTH;
1424 SCROLL_RefreshScrollBar(hwnd, SB_CTL, TRUE, TRUE);
1429 case WM_LBUTTONDBLCLK:
1430 case WM_LBUTTONDOWN:
1431 if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEGRIP)
1433 SendMessageW( GetParent(hwnd), WM_SYSCOMMAND,
1434 SC_SIZE + ((GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_LAYOUTRTL) ?
1435 WMSZ_BOTTOMLEFT : WMSZ_BOTTOMRIGHT), lParam );
1440 pt.x = (short)LOWORD(lParam);
1441 pt.y = (short)HIWORD(lParam);
1442 SCROLL_TrackScrollBar( hwnd, SB_CTL, pt );
1450 pt.x = (short)LOWORD(lParam);
1451 pt.y = (short)HIWORD(lParam);
1452 SCROLL_HandleScrollEvent( hwnd, SB_CTL, message, pt );
1457 SCROLL_HandleKbdEvent(hwnd, wParam, lParam);
1466 /* Create a caret when a ScrollBar get focus */
1468 int arrowSize, thumbSize, thumbPos, vertical;
1469 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,
1470 &arrowSize, &thumbSize, &thumbPos );
1473 CreateCaret(hwnd, (HBITMAP)1, thumbSize-2, rect.bottom-rect.top-2);
1474 SetCaretPos(thumbPos+1, rect.top+1);
1478 CreateCaret(hwnd, (HBITMAP)1, rect.right-rect.left-2,thumbSize-2);
1479 SetCaretPos(rect.top+1, thumbPos+1);
1488 int arrowSize, thumbSize, thumbPos, vertical;
1489 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,&arrowSize, &thumbSize, &thumbPos );
1491 rect.left=thumbPos+1;
1492 rect.right=rect.left+thumbSize;
1496 rect.top=thumbPos+1;
1497 rect.bottom=rect.top+thumbSize;
1500 InvalidateRect(hwnd,&rect,0);
1509 return DLGC_WANTARROWS; /* Windows returns this value */
1514 HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
1515 if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEGRIP)
1517 SCROLL_DrawSizeGrip( hwnd, hdc);
1519 else if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEBOX)
1522 GetClientRect( hwnd, &rc );
1523 FillRect( hdc, &rc, GetSysColorBrush(COLOR_SCROLLBAR) );
1526 SCROLL_DrawScrollBar( hwnd, hdc, SB_CTL, TRUE, TRUE );
1527 if (!wParam) EndPaint(hwnd, &ps);
1532 if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEGRIP)
1534 ULONG_PTR cursor = (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_LAYOUTRTL) ? IDC_SIZENESW : IDC_SIZENWSE;
1535 return (LRESULT)SetCursor( LoadCursorA( 0, (LPSTR)cursor ));
1537 return DefWindowProcW( hwnd, message, wParam, lParam );
1540 return SetScrollPos( hwnd, SB_CTL, wParam, (BOOL)lParam );
1543 return SCROLL_GetScrollPos(hwnd, SB_CTL);
1545 case SBM_SETRANGEREDRAW:
1548 INT oldPos = SCROLL_GetScrollPos( hwnd, SB_CTL );
1549 SCROLL_SetScrollRange( hwnd, SB_CTL, wParam, lParam );
1550 if (message == SBM_SETRANGEREDRAW)
1551 SCROLL_RefreshScrollBar( hwnd, SB_CTL, TRUE, TRUE );
1552 if (oldPos != SCROLL_GetScrollPos( hwnd, SB_CTL )) return oldPos;
1557 return SCROLL_GetScrollRange(hwnd, SB_CTL, (LPINT)wParam, (LPINT)lParam);
1559 case SBM_ENABLE_ARROWS:
1560 return EnableScrollBar( hwnd, SB_CTL, wParam );
1562 case SBM_SETSCROLLINFO:
1563 return SCROLL_SetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam, wParam );
1565 case SBM_GETSCROLLINFO:
1566 return SCROLL_GetScrollInfo(hwnd, SB_CTL, (SCROLLINFO *)lParam);
1568 case SBM_GETSCROLLBARINFO:
1569 return SCROLL_GetScrollBarInfo(hwnd, OBJID_CLIENT, (SCROLLBARINFO *)lParam);
1578 ERR("unknown Win32 msg %04x wp=%08lx lp=%08lx\n",
1579 message, wParam, lParam );
1583 if (message >= WM_USER)
1584 WARN("unknown msg %04x wp=%04lx lp=%08lx\n",
1585 message, wParam, lParam );
1587 return DefWindowProcW( hwnd, message, wParam, lParam );
1589 return DefWindowProcA( hwnd, message, wParam, lParam );
1595 /*************************************************************************
1596 * SetScrollInfo (USER32.@)
1598 * SetScrollInfo can be used to set the position, upper bound,
1599 * lower bound, and page size of a scrollbar control.
1602 * hwnd [I] Handle of window with scrollbar(s)
1603 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1604 * info [I] Specifies what to change and new values
1605 * bRedraw [I] Should scrollbar be redrawn afterwards?
1608 * Scrollbar position
1611 * For 100 lines of text to be displayed in a window of 25 lines,
1612 * one would for instance use info->nMin=0, info->nMax=75
1613 * (corresponding to the 76 different positions of the window on
1614 * the text), and info->nPage=25.
1616 INT WINAPI DECLSPEC_HOTPATCH SetScrollInfo(HWND hwnd, INT nBar, const SCROLLINFO *info, BOOL bRedraw)
1618 TRACE("hwnd=%p nBar=%d info=%p, bRedraw=%d\n", hwnd, nBar, info, bRedraw);
1620 /* Refer SB_CTL requests to the window */
1622 return SendMessageW(hwnd, SBM_SETSCROLLINFO, bRedraw, (LPARAM)info);
1624 return SCROLL_SetScrollInfo( hwnd, nBar, info, bRedraw );
1627 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar, LPCSCROLLINFO info, BOOL bRedraw )
1629 /* Update the scrollbar state and set action flags according to
1630 * what has to be done graphics wise. */
1632 SCROLLBAR_INFO *infoPtr;
1636 /* handle invalid data structure */
1637 if (!SCROLL_ScrollInfoValid(info)
1638 || !(infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, TRUE)))
1641 if (TRACE_ON(scroll))
1643 TRACE("hwnd=%p bar=%d", hwnd, nBar);
1644 if (info->fMask & SIF_PAGE) TRACE( " page=%d", info->nPage );
1645 if (info->fMask & SIF_POS) TRACE( " pos=%d", info->nPos );
1646 if (info->fMask & SIF_RANGE) TRACE( " min=%d max=%d", info->nMin, info->nMax );
1650 /* Set the page size */
1652 if (info->fMask & SIF_PAGE)
1654 if( infoPtr->page != info->nPage )
1656 infoPtr->page = info->nPage;
1657 action |= SA_SSI_REFRESH;
1661 /* Set the scroll pos */
1663 if (info->fMask & SIF_POS)
1665 if( infoPtr->curVal != info->nPos )
1667 infoPtr->curVal = info->nPos;
1668 action |= SA_SSI_REFRESH;
1672 /* Set the scroll range */
1674 if (info->fMask & SIF_RANGE)
1676 /* Invalid range -> range is set to (0,0) */
1677 if ((info->nMin > info->nMax) ||
1678 ((UINT)(info->nMax - info->nMin) >= 0x80000000))
1680 action |= SA_SSI_REFRESH;
1681 infoPtr->minVal = 0;
1682 infoPtr->maxVal = 0;
1686 if( infoPtr->minVal != info->nMin ||
1687 infoPtr->maxVal != info->nMax )
1689 action |= SA_SSI_REFRESH;
1690 infoPtr->minVal = info->nMin;
1691 infoPtr->maxVal = info->nMax;
1696 /* Make sure the page size is valid */
1697 if (infoPtr->page < 0) infoPtr->page = 0;
1698 else if (infoPtr->page > infoPtr->maxVal - infoPtr->minVal + 1 )
1699 infoPtr->page = infoPtr->maxVal - infoPtr->minVal + 1;
1701 /* Make sure the pos is inside the range */
1703 if (infoPtr->curVal < infoPtr->minVal)
1704 infoPtr->curVal = infoPtr->minVal;
1705 else if (infoPtr->curVal > infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1706 infoPtr->curVal = infoPtr->maxVal - max( infoPtr->page-1, 0 );
1708 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1709 infoPtr->page, infoPtr->curVal,
1710 infoPtr->minVal, infoPtr->maxVal );
1712 /* don't change the scrollbar state if SetScrollInfo
1713 * is just called with SIF_DISABLENOSCROLL
1715 if(!(info->fMask & SIF_ALL)) goto done;
1717 /* Check if the scrollbar should be hidden or disabled */
1719 if (info->fMask & (SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL))
1721 new_flags = infoPtr->flags;
1722 if (infoPtr->minVal >= infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1724 /* Hide or disable scroll-bar */
1725 if (info->fMask & SIF_DISABLENOSCROLL)
1727 new_flags = ESB_DISABLE_BOTH;
1728 action |= SA_SSI_REFRESH;
1730 else if ((nBar != SB_CTL) && (action & SA_SSI_REFRESH))
1732 action = SA_SSI_HIDE;
1735 else /* Show and enable scroll-bar only if no page only changed. */
1736 if (info->fMask != SIF_PAGE)
1738 new_flags = ESB_ENABLE_BOTH;
1739 if ((nBar != SB_CTL) && ( (action & SA_SSI_REFRESH) ))
1740 action |= SA_SSI_SHOW;
1743 if (infoPtr->flags != new_flags) /* check arrow flags */
1745 infoPtr->flags = new_flags;
1746 action |= SA_SSI_REPAINT_ARROWS;
1751 if( action & SA_SSI_HIDE )
1752 SCROLL_ShowScrollBar( hwnd, nBar, FALSE, FALSE );
1755 if( action & SA_SSI_SHOW )
1756 if( SCROLL_ShowScrollBar( hwnd, nBar, TRUE, TRUE ) )
1757 return infoPtr->curVal; /* SetWindowPos() already did the painting */
1760 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
1761 else if( action & SA_SSI_REPAINT_ARROWS )
1762 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, FALSE );
1765 /* Return current position */
1766 return infoPtr->curVal;
1770 /*************************************************************************
1771 * GetScrollInfo (USER32.@)
1773 * GetScrollInfo can be used to retrieve the position, upper bound,
1774 * lower bound, and page size of a scrollbar control.
1777 * hwnd [I] Handle of window with scrollbar(s)
1778 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1779 * info [IO] fMask specifies which values to retrieve
1782 * TRUE if SCROLLINFO is filled
1783 * ( if nBar is SB_CTL, GetScrollInfo returns TRUE even if nothing
1786 BOOL WINAPI DECLSPEC_HOTPATCH GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1788 TRACE("hwnd=%p nBar=%d info=%p\n", hwnd, nBar, info);
1790 /* Refer SB_CTL requests to the window */
1793 SendMessageW(hwnd, SBM_GETSCROLLINFO, 0, (LPARAM)info);
1796 return SCROLL_GetScrollInfo(hwnd, nBar, info);
1800 /*************************************************************************
1801 * GetScrollBarInfo (USER32.@)
1803 * GetScrollBarInfo can be used to retrieve information about a scrollbar
1807 * hwnd [I] Handle of window with scrollbar(s)
1808 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1809 * info [IO] cbSize specifies the size of SCROLLBARINFO
1814 BOOL WINAPI GetScrollBarInfo(HWND hwnd, LONG idObject, LPSCROLLBARINFO info)
1816 TRACE("hwnd=%p idObject=%d info=%p\n", hwnd, idObject, info);
1818 /* Refer OBJID_CLIENT requests to the window */
1819 if (idObject == OBJID_CLIENT)
1820 return SendMessageW(hwnd, SBM_GETSCROLLBARINFO, 0, (LPARAM)info);
1822 return SCROLL_GetScrollBarInfo(hwnd, idObject, info);
1826 /*************************************************************************
1827 * SetScrollPos (USER32.@)
1829 * Sets the current position of the scroll thumb.
1832 * hwnd [I] Handle of window with scrollbar(s)
1833 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1834 * nPos [I] New value
1835 * bRedraw [I] Should scrollbar be redrawn afterwards?
1838 * Success: Scrollbar position
1842 * Note the ambiguity when 0 is returned. Use GetLastError
1843 * to make sure there was an error (and to know which one).
1845 INT WINAPI DECLSPEC_HOTPATCH SetScrollPos( HWND hwnd, INT nBar, INT nPos, BOOL bRedraw)
1848 SCROLLBAR_INFO *infoPtr;
1851 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, FALSE ))) return 0;
1852 oldPos = infoPtr->curVal;
1853 info.cbSize = sizeof(info);
1855 info.fMask = SIF_POS;
1856 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1861 /*************************************************************************
1862 * GetScrollPos (USER32.@)
1864 * Gets the current position of the scroll thumb.
1867 * hwnd [I] Handle of window with scrollbar(s)
1868 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1871 * Success: Current position
1875 * There is ambiguity when 0 is returned. Use GetLastError
1876 * to make sure there was an error (and to know which one).
1878 INT WINAPI DECLSPEC_HOTPATCH GetScrollPos(HWND hwnd, INT nBar)
1880 TRACE("hwnd=%p nBar=%d\n", hwnd, nBar);
1882 /* Refer SB_CTL requests to the window */
1884 return SendMessageW(hwnd, SBM_GETPOS, 0, 0);
1886 return SCROLL_GetScrollPos(hwnd, nBar);
1890 /*************************************************************************
1891 * SetScrollRange (USER32.@)
1892 * The SetScrollRange function sets the minimum and maximum scroll box positions
1893 * If nMinPos and nMaxPos is the same value, the scroll bar will hide
1895 * Sets the range of the scroll bar.
1898 * hwnd [I] Handle of window with scrollbar(s)
1899 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1900 * minVal [I] New minimum value
1901 * maxVal [I] New Maximum value
1902 * bRedraw [I] Should scrollbar be redrawn afterwards?
1908 BOOL WINAPI DECLSPEC_HOTPATCH SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal, BOOL bRedraw)
1912 TRACE("hwnd=%p nBar=%d min=%d max=%d, bRedraw=%d\n", hwnd, nBar, minVal, maxVal, bRedraw);
1914 info.cbSize = sizeof(info);
1915 info.fMask = SIF_RANGE;
1918 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1923 /*************************************************************************
1924 * GetScrollRange (USER32.@)
1926 * Gets the range of the scroll bar.
1929 * hwnd [I] Handle of window with scrollbar(s)
1930 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1931 * lpMin [O] Where to store minimum value
1932 * lpMax [O] Where to store maximum value
1935 * TRUE if values is filled
1937 BOOL WINAPI DECLSPEC_HOTPATCH GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1939 TRACE("hwnd=%p nBar=%d lpMin=%p lpMax=%p\n", hwnd, nBar, lpMin, lpMax);
1941 /* Refer SB_CTL requests to the window */
1943 SendMessageW(hwnd, SBM_GETRANGE, (WPARAM)lpMin, (LPARAM)lpMax);
1945 SCROLL_GetScrollRange(hwnd, nBar, lpMin, lpMax);
1951 /*************************************************************************
1952 * SCROLL_ShowScrollBar()
1954 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1956 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar, BOOL fShowH, BOOL fShowV )
1958 ULONG old_style, set_bits = 0, clear_bits = 0;
1960 TRACE("hwnd=%p bar=%d horz=%d, vert=%d\n", hwnd, nBar, fShowH, fShowV );
1965 ShowWindow( hwnd, fShowH ? SW_SHOW : SW_HIDE );
1970 if (fShowH) set_bits |= WS_HSCROLL;
1971 else clear_bits |= WS_HSCROLL;
1972 if( nBar == SB_HORZ ) break;
1975 if (fShowV) set_bits |= WS_VSCROLL;
1976 else clear_bits |= WS_VSCROLL;
1980 return FALSE; /* Nothing to do! */
1983 old_style = WIN_SetStyle( hwnd, set_bits, clear_bits );
1984 if ((old_style & clear_bits) != 0 || (old_style & set_bits) != set_bits)
1986 /* frame has been changed, let the window redraw itself */
1987 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
1988 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
1991 return FALSE; /* no frame changes */
1995 /*************************************************************************
1996 * ShowScrollBar (USER32.@)
1998 * Shows or hides the scroll bar.
2001 * hwnd [I] Handle of window with scrollbar(s)
2002 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
2003 * fShow [I] TRUE = show, FALSE = hide
2009 BOOL WINAPI DECLSPEC_HOTPATCH ShowScrollBar(HWND hwnd, INT nBar, BOOL fShow)
2014 SCROLL_ShowScrollBar( hwnd, nBar, (nBar == SB_VERT) ? 0 : fShow,
2015 (nBar == SB_HORZ) ? 0 : fShow );
2020 /*************************************************************************
2021 * EnableScrollBar (USER32.@)
2023 * Enables or disables the scroll bars.
2025 BOOL WINAPI DECLSPEC_HOTPATCH EnableScrollBar( HWND hwnd, UINT nBar, UINT flags )
2028 SCROLLBAR_INFO *infoPtr;
2030 flags &= ESB_DISABLE_BOTH;
2032 if (nBar == SB_BOTH)
2034 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, SB_VERT, TRUE ))) return FALSE;
2035 if (!(bFineWithMe = (infoPtr->flags == flags)) )
2037 infoPtr->flags = flags;
2038 SCROLL_RefreshScrollBar( hwnd, SB_VERT, TRUE, TRUE );
2045 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, TRUE ))) return FALSE;
2046 if (bFineWithMe && infoPtr->flags == flags) return FALSE;
2047 infoPtr->flags = flags;
2049 if (nBar == SB_CTL && (flags == ESB_DISABLE_BOTH || flags == ESB_ENABLE_BOTH))
2050 EnableWindow(hwnd, flags == ESB_ENABLE_BOTH);
2052 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );