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.
36 #include "wine/winuser16.h"
39 #include "wine/debug.h"
40 #include "user_private.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(scroll);
46 INT curVal; /* Current scroll-bar value */
47 INT minVal; /* Minimum scroll-bar value */
48 INT maxVal; /* Maximum scroll-bar value */
49 INT page; /* Page size of scroll bar (Win32) */
50 UINT flags; /* EnableScrollBar flags */
51 } SCROLLBAR_INFO, *LPSCROLLBAR_INFO;
54 /* Minimum size of the rectangle between the arrows */
55 #define SCROLL_MIN_RECT 4
57 /* Minimum size of the thumb in pixels */
58 #define SCROLL_MIN_THUMB 6
60 /* Overlap between arrows and thumb */
61 #define SCROLL_ARROW_THUMB_OVERLAP 0
63 /* Delay (in ms) before first repetition when holding the button down */
64 #define SCROLL_FIRST_DELAY 200
66 /* Delay (in ms) between scroll repetitions */
67 #define SCROLL_REPEAT_DELAY 50
70 #define SCROLL_TIMER 0
72 /* Scroll-bar hit testing */
75 SCROLL_NOWHERE, /* Outside the scroll bar */
76 SCROLL_TOP_ARROW, /* Top or left arrow */
77 SCROLL_TOP_RECT, /* Rectangle between the top arrow and the thumb */
78 SCROLL_THUMB, /* Thumb rectangle */
79 SCROLL_BOTTOM_RECT, /* Rectangle between the thumb and the bottom arrow */
80 SCROLL_BOTTOM_ARROW /* Bottom or right arrow */
83 /* What to do after SCROLL_SetScrollInfo() */
84 #define SA_SSI_HIDE 0x0001
85 #define SA_SSI_SHOW 0x0002
86 #define SA_SSI_REFRESH 0x0004
87 #define SA_SSI_REPAINT_ARROWS 0x0008
89 /* Thumb-tracking info */
90 static HWND SCROLL_TrackingWin = 0;
91 static INT SCROLL_TrackingBar = 0;
92 static INT SCROLL_TrackingPos = 0;
93 static INT SCROLL_TrackingVal = 0;
94 /* Hit test code of the last button-down event */
95 static enum SCROLL_HITTEST SCROLL_trackHitTest;
96 static BOOL SCROLL_trackVertical;
98 /* Is the moving thumb being displayed? */
99 static BOOL SCROLL_MovingThumb = FALSE;
101 /* Local functions */
102 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar,
103 BOOL fShowH, BOOL fShowV );
104 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar,
105 const SCROLLINFO *info, BOOL bRedraw );
106 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
107 RECT *rect, INT arrowSize,
108 INT thumbSize, INT thumbPos,
109 UINT flags, BOOL vertical,
110 BOOL top_selected, BOOL bottom_selected );
111 static LRESULT WINAPI ScrollBarWndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
114 /*********************************************************************
115 * scrollbar class descriptor
117 static const WCHAR scrollbarW[] = {'S','c','r','o','l','l','B','a','r',0};
118 const struct builtin_class_descr SCROLL_builtin_class =
120 scrollbarW, /* name */
121 CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC, /* style */
122 NULL, /* procA (winproc is Unicode only) */
123 ScrollBarWndProc, /* procW */
124 sizeof(SCROLLBAR_INFO), /* extra */
125 IDC_ARROW, /* cursor */
129 /***********************************************************************
130 * SCROLL_ScrollInfoValid
132 * Determine if the supplied SCROLLINFO struct is valid.
133 * info [in] The SCROLLINFO struct to be tested
135 static inline BOOL SCROLL_ScrollInfoValid( LPCSCROLLINFO info )
137 return !(info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)
138 || (info->cbSize != sizeof(*info)
139 && info->cbSize != sizeof(*info) - sizeof(info->nTrackPos)));
143 /***********************************************************************
144 * SCROLL_GetInternalInfo
146 * Returns pointer to internal SCROLLBAR_INFO structure for nBar
147 * or NULL if failed (f.i. scroll bar does not exist yet)
148 * If alloc is TRUE and the struct does not exist yet, create it.
150 static SCROLLBAR_INFO *SCROLL_GetInternalInfo( HWND hwnd, INT nBar, BOOL alloc )
152 SCROLLBAR_INFO *infoPtr = NULL;
153 WND *wndPtr = WIN_GetPtr( hwnd );
155 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return NULL;
158 case SB_HORZ: infoPtr = (SCROLLBAR_INFO *)wndPtr->pHScroll; break;
159 case SB_VERT: infoPtr = (SCROLLBAR_INFO *)wndPtr->pVScroll; break;
160 case SB_CTL: infoPtr = (SCROLLBAR_INFO *)wndPtr->wExtra; break;
161 case SB_BOTH: WARN("with SB_BOTH\n"); break;
164 if (!infoPtr && alloc)
166 if (nBar != SB_HORZ && nBar != SB_VERT)
167 WARN("Cannot initialize nBar=%d\n",nBar);
168 else if ((infoPtr = HeapAlloc( GetProcessHeap(), 0, sizeof(SCROLLBAR_INFO) )))
170 /* Set default values */
171 infoPtr->minVal = infoPtr->curVal = infoPtr->page = 0;
172 /* From MSDN: max for a standard scroll bar is 100 by default. */
173 infoPtr->maxVal = 100;
174 /* Scroll bar is enabled by default after create */
175 infoPtr->flags = ESB_ENABLE_BOTH;
176 if (nBar == SB_HORZ) wndPtr->pHScroll = infoPtr;
177 else wndPtr->pVScroll = infoPtr;
180 WIN_ReleasePtr( wndPtr );
185 /***********************************************************************
186 * SCROLL_GetScrollBarRect
188 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
189 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
190 * 'arrowSize' returns the width or height of an arrow (depending on
191 * the orientation of the scrollbar), 'thumbSize' returns the size of
192 * the thumb, and 'thumbPos' returns the position of the thumb
193 * relative to the left or to the top.
194 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
196 static BOOL SCROLL_GetScrollBarRect( HWND hwnd, INT nBar, RECT *lprect,
197 INT *arrowSize, INT *thumbSize,
202 WND *wndPtr = WIN_GetPtr( hwnd );
204 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
209 lprect->left = wndPtr->rectClient.left - wndPtr->rectWindow.left;
210 lprect->top = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
211 lprect->right = wndPtr->rectClient.right - wndPtr->rectWindow.left;
212 lprect->bottom = lprect->top + GetSystemMetrics(SM_CYHSCROLL);
213 if(wndPtr->dwStyle & WS_VSCROLL)
219 if((wndPtr->dwExStyle & WS_EX_LEFTSCROLLBAR) != 0)
220 lprect->left = wndPtr->rectClient.left - wndPtr->rectWindow.left - GetSystemMetrics(SM_CXVSCROLL);
222 lprect->left = wndPtr->rectClient.right - wndPtr->rectWindow.left;
223 lprect->top = wndPtr->rectClient.top - wndPtr->rectWindow.top;
224 lprect->right = lprect->left + GetSystemMetrics(SM_CXVSCROLL);
225 lprect->bottom = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
226 if(wndPtr->dwStyle & WS_HSCROLL)
232 GetClientRect( hwnd, lprect );
233 vertical = ((wndPtr->dwStyle & SBS_VERT) != 0);
237 WIN_ReleasePtr( wndPtr );
241 if (vertical) pixels = lprect->bottom - lprect->top;
242 else pixels = lprect->right - lprect->left;
244 if (pixels <= 2*GetSystemMetrics(SM_CXVSCROLL) + SCROLL_MIN_RECT)
246 if (pixels > SCROLL_MIN_RECT)
247 *arrowSize = (pixels - SCROLL_MIN_RECT) / 2;
250 *thumbPos = *thumbSize = 0;
254 SCROLLBAR_INFO *info = SCROLL_GetInternalInfo( hwnd, nBar, FALSE );
257 WARN("called for missing scroll bar\n");
258 WIN_ReleasePtr( wndPtr );
261 *arrowSize = GetSystemMetrics(SM_CXVSCROLL);
262 pixels -= (2 * (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP));
266 *thumbSize = MulDiv(pixels,info->page,(info->maxVal-info->minVal+1));
267 if (*thumbSize < SCROLL_MIN_THUMB) *thumbSize = SCROLL_MIN_THUMB;
269 else *thumbSize = GetSystemMetrics(SM_CXVSCROLL);
271 if (((pixels -= *thumbSize ) < 0) ||
272 ((info->flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH))
274 /* Rectangle too small or scrollbar disabled -> no thumb */
275 *thumbPos = *thumbSize = 0;
279 INT max = info->maxVal - max( info->page-1, 0 );
280 if (info->minVal >= max)
281 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
283 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP
284 + MulDiv(pixels, (info->curVal-info->minVal),(max - info->minVal));
287 WIN_ReleasePtr( wndPtr );
292 /***********************************************************************
295 * Compute the current scroll position based on the thumb position in pixels
296 * from the top of the scroll-bar.
298 static UINT SCROLL_GetThumbVal( SCROLLBAR_INFO *infoPtr, RECT *rect,
299 BOOL vertical, INT pos )
302 INT pixels = vertical ? rect->bottom-rect->top : rect->right-rect->left;
304 if ((pixels -= 2*(GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP)) <= 0)
305 return infoPtr->minVal;
309 thumbSize = MulDiv(pixels,infoPtr->page,(infoPtr->maxVal-infoPtr->minVal+1));
310 if (thumbSize < SCROLL_MIN_THUMB) thumbSize = SCROLL_MIN_THUMB;
312 else thumbSize = GetSystemMetrics(SM_CXVSCROLL);
314 if ((pixels -= thumbSize) <= 0) return infoPtr->minVal;
316 pos = max( 0, pos - (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP) );
317 if (pos > pixels) pos = pixels;
319 if (!infoPtr->page) pos *= infoPtr->maxVal - infoPtr->minVal;
320 else pos *= infoPtr->maxVal - infoPtr->minVal - infoPtr->page + 1;
321 return infoPtr->minVal + ((pos + pixels / 2) / pixels);
324 /***********************************************************************
327 static BOOL SCROLL_PtInRectEx( LPRECT lpRect, POINT pt, BOOL vertical )
333 rect.left -= lpRect->right - lpRect->left;
334 rect.right += lpRect->right - lpRect->left;
338 rect.top -= lpRect->bottom - lpRect->top;
339 rect.bottom += lpRect->bottom - lpRect->top;
341 return PtInRect( &rect, pt );
344 /***********************************************************************
347 static POINT SCROLL_ClipPos( LPRECT lpRect, POINT pt )
349 if( pt.x < lpRect->left )
352 if( pt.x > lpRect->right )
353 pt.x = lpRect->right;
355 if( pt.y < lpRect->top )
358 if( pt.y > lpRect->bottom )
359 pt.y = lpRect->bottom;
365 /***********************************************************************
368 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
370 static enum SCROLL_HITTEST SCROLL_HitTest( HWND hwnd, INT nBar,
371 POINT pt, BOOL bDragging )
373 INT arrowSize, thumbSize, thumbPos;
376 BOOL vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
377 &arrowSize, &thumbSize, &thumbPos );
379 if ( (bDragging && !SCROLL_PtInRectEx( &rect, pt, vertical )) ||
380 (!PtInRect( &rect, pt )) ) return SCROLL_NOWHERE;
384 if (pt.y < rect.top + arrowSize) return SCROLL_TOP_ARROW;
385 if (pt.y >= rect.bottom - arrowSize) return SCROLL_BOTTOM_ARROW;
386 if (!thumbPos) return SCROLL_TOP_RECT;
388 if (pt.y < thumbPos) return SCROLL_TOP_RECT;
389 if (pt.y >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
391 else /* horizontal */
393 if (pt.x < rect.left + arrowSize) return SCROLL_TOP_ARROW;
394 if (pt.x >= rect.right - arrowSize) return SCROLL_BOTTOM_ARROW;
395 if (!thumbPos) return SCROLL_TOP_RECT;
397 if (pt.x < thumbPos) return SCROLL_TOP_RECT;
398 if (pt.x >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
404 /***********************************************************************
407 * Draw the scroll bar arrows.
409 static void SCROLL_DrawArrows( HDC hdc, SCROLLBAR_INFO *infoPtr,
410 RECT *rect, INT arrowSize, BOOL vertical,
411 BOOL top_pressed, BOOL bottom_pressed )
417 r.bottom = r.top + arrowSize;
419 r.right = r.left + arrowSize;
421 DrawFrameControl( hdc, &r, DFC_SCROLL,
422 (vertical ? DFCS_SCROLLUP : DFCS_SCROLLLEFT)
423 | (top_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
424 | (infoPtr->flags&ESB_DISABLE_LTUP ? DFCS_INACTIVE : 0 ) );
428 r.top = r.bottom-arrowSize;
430 r.left = r.right-arrowSize;
432 DrawFrameControl( hdc, &r, DFC_SCROLL,
433 (vertical ? DFCS_SCROLLDOWN : DFCS_SCROLLRIGHT)
434 | (bottom_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
435 | (infoPtr->flags&ESB_DISABLE_RTDN ? DFCS_INACTIVE : 0) );
438 static void SCROLL_DrawMovingThumb( HDC hdc, RECT *rect, BOOL vertical,
439 INT arrowSize, INT thumbSize )
441 INT pos = SCROLL_TrackingPos;
445 max_size = rect->bottom - rect->top;
447 max_size = rect->right - rect->left;
449 max_size -= (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) + thumbSize;
451 if( pos < (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) )
452 pos = (arrowSize-SCROLL_ARROW_THUMB_OVERLAP);
453 else if( pos > max_size )
456 SCROLL_DrawInterior_9x( SCROLL_TrackingWin, hdc, SCROLL_TrackingBar,
457 rect, arrowSize, thumbSize, pos,
458 0, vertical, FALSE, FALSE );
460 SCROLL_MovingThumb = !SCROLL_MovingThumb;
463 /***********************************************************************
464 * SCROLL_DrawInterior
466 * Draw the scroll bar interior (everything except the arrows).
468 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
469 RECT *rect, INT arrowSize,
470 INT thumbSize, INT thumbPos,
471 UINT flags, BOOL vertical,
472 BOOL top_selected, BOOL bottom_selected )
476 HBRUSH hSaveBrush,hBrush;
478 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
479 * The window-owned scrollbars need to call DEFWND_ControlColor
480 * to correctly setup default scrollbar colors
484 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
485 (WPARAM)hdc,(LPARAM)hwnd);
489 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
492 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
493 hSaveBrush = SelectObject( hdc, hBrush );
495 /* Calculate the scroll rectangle */
499 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
500 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
504 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
505 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
508 /* Draw the scroll rectangles and thumb */
509 if (!thumbPos) /* No thumb to draw */
511 PatBlt( hdc, r.left, r.top,
512 r.right - r.left, r.bottom - r.top,
515 /* cleanup and return */
516 SelectObject( hdc, hSavePen );
517 SelectObject( hdc, hSaveBrush );
523 PatBlt( hdc, r.left, r.top,
525 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
526 top_selected ? 0x0f0000 : PATCOPY );
527 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
528 PatBlt( hdc, r.left, r.top + thumbSize,
530 r.bottom - r.top - thumbSize,
531 bottom_selected ? 0x0f0000 : PATCOPY );
532 r.bottom = r.top + thumbSize;
534 else /* horizontal */
536 PatBlt( hdc, r.left, r.top,
537 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
539 top_selected ? 0x0f0000 : PATCOPY );
540 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
541 PatBlt( hdc, r.left + thumbSize, r.top,
542 r.right - r.left - thumbSize,
544 bottom_selected ? 0x0f0000 : PATCOPY );
545 r.right = r.left + thumbSize;
549 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT | BF_MIDDLE );
552 SelectObject( hdc, hSavePen );
553 SelectObject( hdc, hSaveBrush );
557 static void SCROLL_DrawInterior( HWND hwnd, HDC hdc, INT nBar,
558 RECT *rect, INT arrowSize,
559 INT thumbSize, INT thumbPos,
560 UINT flags, BOOL vertical,
561 BOOL top_selected, BOOL bottom_selected )
565 HBRUSH hSaveBrush,hBrush;
566 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
568 if (Save_SCROLL_MovingThumb &&
569 (SCROLL_TrackingWin == hwnd) &&
570 (SCROLL_TrackingBar == nBar))
571 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
573 /* Select the correct brush and pen */
575 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
576 * The window-owned scrollbars need to call DEFWND_ControlColor
577 * to correctly setup default scrollbar colors
579 if (nBar == SB_CTL) {
580 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
581 (WPARAM)hdc,(LPARAM)hwnd);
583 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
585 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
586 hSaveBrush = SelectObject( hdc, hBrush );
588 /* Calculate the scroll rectangle */
593 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
594 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
598 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
599 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
602 /* Draw the scroll bar frame */
604 /* Draw the scroll rectangles and thumb */
606 if (!thumbPos) /* No thumb to draw */
608 PatBlt( hdc, r.left, r.top, r.right - r.left, r.bottom - r.top, PATCOPY );
610 /* cleanup and return */
611 SelectObject( hdc, hSavePen );
612 SelectObject( hdc, hSaveBrush );
618 PatBlt( hdc, r.left, r.top, r.right - r.left,
619 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
620 top_selected ? 0x0f0000 : PATCOPY );
621 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
622 PatBlt( hdc, r.left, r.top + thumbSize, r.right - r.left,
623 r.bottom - r.top - thumbSize,
624 bottom_selected ? 0x0f0000 : PATCOPY );
625 r.bottom = r.top + thumbSize;
627 else /* horizontal */
629 PatBlt( hdc, r.left, r.top,
630 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
631 r.bottom - r.top, top_selected ? 0x0f0000 : PATCOPY );
632 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
633 PatBlt( hdc, r.left + thumbSize, r.top, r.right - r.left - thumbSize,
634 r.bottom - r.top, bottom_selected ? 0x0f0000 : PATCOPY );
635 r.right = r.left + thumbSize;
640 SelectObject( hdc, GetSysColorBrush(COLOR_BTNFACE) );
641 Rectangle( hdc, r.left+1, r.top+1, r.right-1, r.bottom-1 );
642 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT );
644 if (Save_SCROLL_MovingThumb &&
645 (SCROLL_TrackingWin == hwnd) &&
646 (SCROLL_TrackingBar == nBar))
647 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
650 SelectObject( hdc, hSavePen );
651 SelectObject( hdc, hSaveBrush );
655 /***********************************************************************
656 * SCROLL_DrawScrollBar
658 * Redraw the whole scrollbar.
660 void SCROLL_DrawScrollBar( HWND hwnd, HDC hdc, INT nBar,
661 BOOL arrows, BOOL interior )
663 INT arrowSize, thumbSize, thumbPos;
666 SCROLLBAR_INFO *infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, TRUE );
667 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
668 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
670 if (!(hwnd = WIN_GetFullHandle( hwnd ))) return;
673 ((nBar == SB_VERT) && !(style & WS_VSCROLL)) ||
674 ((nBar == SB_HORZ) && !(style & WS_HSCROLL))) return;
675 if (!WIN_IsWindowDrawable( hwnd, FALSE )) return;
677 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
678 &arrowSize, &thumbSize, &thumbPos );
680 /* do not draw if the scrollbar rectangle is empty */
681 if(IsRectEmpty(&rect)) return;
683 if (Save_SCROLL_MovingThumb &&
684 (SCROLL_TrackingWin == hwnd) &&
685 (SCROLL_TrackingBar == nBar))
686 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
688 /* Draw the arrows */
690 if (arrows && arrowSize)
692 if( vertical == SCROLL_trackVertical && GetCapture() == hwnd )
693 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
694 (SCROLL_trackHitTest == SCROLL_TOP_ARROW),
695 (SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW) );
697 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
701 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
702 thumbPos, infoPtr->flags, vertical, FALSE, FALSE );
704 if (Save_SCROLL_MovingThumb &&
705 (SCROLL_TrackingWin == hwnd) &&
706 (SCROLL_TrackingBar == nBar))
707 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
709 /* if scroll bar has focus, reposition the caret */
710 if(hwnd==GetFocus() && (nBar==SB_CTL))
714 SetCaretPos(thumbPos+1, rect.top+1);
718 SetCaretPos(rect.top+1, thumbPos+1);
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=%ld 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;
784 case VK_LEFT: wParam = SB_LINEUP; break;
785 case VK_RIGHT: wParam = SB_LINEDOWN; break;
788 SendMessageW(GetParent(hwnd),
789 ((GetWindowLongW( hwnd, GWL_STYLE ) & SBS_VERT) ?
790 WM_VSCROLL : WM_HSCROLL), wParam, (LPARAM)hwnd);
794 /***********************************************************************
795 * SCROLL_HandleScrollEvent
797 * Handle a mouse or timer event for the scrollbar.
798 * 'pt' is the location of the mouse event in client (for SB_CTL) or
799 * windows coordinates.
801 static void SCROLL_HandleScrollEvent( HWND hwnd, INT nBar, UINT msg, POINT pt)
803 /* Previous mouse position for timer events */
805 /* Thumb position when tracking started. */
806 static UINT trackThumbPos;
807 /* Position in the scroll-bar of the last button-down event. */
808 static INT lastClickPos;
809 /* Position in the scroll-bar of the last mouse event. */
810 static INT lastMousePos;
812 enum SCROLL_HITTEST hittest;
813 HWND hwndOwner, hwndCtl;
815 INT arrowSize, thumbSize, thumbPos;
819 SCROLLBAR_INFO *infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, FALSE );
820 if (!infoPtr) return;
821 if ((SCROLL_trackHitTest == SCROLL_NOWHERE) && (msg != WM_LBUTTONDOWN))
824 if (nBar == SB_CTL && (GetWindowLongW( hwnd, GWL_STYLE ) & (SBS_SIZEGRIP | SBS_SIZEBOX)))
828 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
829 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
832 SCROLL_trackHitTest = hittest = SCROLL_THUMB;
835 GetClientRect(GetParent(GetParent(hwnd)),&rect);
840 SCROLL_trackHitTest = hittest = SCROLL_NOWHERE;
841 if (hwnd==GetFocus()) ShowCaret(hwnd);
850 hdc = GetDCEx( hwnd, 0, DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW));
851 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
852 &arrowSize, &thumbSize, &thumbPos );
853 hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd) : hwnd;
854 hwndCtl = (nBar == SB_CTL) ? hwnd : 0;
858 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
859 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
860 SCROLL_trackVertical = vertical;
861 SCROLL_trackHitTest = hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
862 lastClickPos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
863 lastMousePos = lastClickPos;
864 trackThumbPos = thumbPos;
866 if (nBar == SB_CTL && (GetWindowLongW(hwnd, GWL_STYLE) & WS_TABSTOP)) SetFocus( hwnd );
871 hittest = SCROLL_HitTest( hwnd, nBar, pt, TRUE );
876 hittest = SCROLL_NOWHERE;
878 /* if scrollbar has focus, show back caret */
879 if (hwnd==GetFocus()) ShowCaret(hwnd);
884 hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
888 return; /* Should never happen */
891 TRACE("Event: hwnd=%p bar=%d msg=%s pt=%d,%d hit=%d\n",
892 hwnd, nBar, SPY_GetMsgName(msg,hwnd), pt.x, pt.y, hittest );
894 switch(SCROLL_trackHitTest)
896 case SCROLL_NOWHERE: /* No tracking in progress */
899 case SCROLL_TOP_ARROW:
900 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
901 (hittest == SCROLL_trackHitTest), FALSE );
902 if (hittest == SCROLL_trackHitTest)
904 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
906 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
907 SB_LINEUP, (LPARAM)hwndCtl );
910 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
911 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
914 else KillSystemTimer( hwnd, SCROLL_TIMER );
917 case SCROLL_TOP_RECT:
918 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
919 thumbPos, infoPtr->flags, vertical,
920 (hittest == SCROLL_trackHitTest), FALSE );
921 if (hittest == SCROLL_trackHitTest)
923 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
925 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
926 SB_PAGEUP, (LPARAM)hwndCtl );
928 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
929 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
932 else KillSystemTimer( hwnd, SCROLL_TIMER );
936 if (msg == WM_LBUTTONDOWN)
938 SCROLL_TrackingWin = hwnd;
939 SCROLL_TrackingBar = nBar;
940 SCROLL_TrackingPos = trackThumbPos + lastMousePos - lastClickPos;
941 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
943 SCROLL_TrackingPos );
944 if (!SCROLL_MovingThumb)
945 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
947 else if (msg == WM_LBUTTONUP)
949 if (SCROLL_MovingThumb)
950 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
952 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
953 thumbPos, infoPtr->flags, vertical,
956 else /* WM_MOUSEMOVE */
960 if (!SCROLL_PtInRectEx( &rect, pt, vertical )) pos = lastClickPos;
963 pt = SCROLL_ClipPos( &rect, pt );
964 pos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
966 if ( (pos != lastMousePos) || (!SCROLL_MovingThumb) )
968 if (SCROLL_MovingThumb)
969 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
970 arrowSize, thumbSize );
972 SCROLL_TrackingPos = trackThumbPos + pos - lastClickPos;
973 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
975 SCROLL_TrackingPos );
976 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
977 MAKEWPARAM( SB_THUMBTRACK, SCROLL_TrackingVal),
979 if (!SCROLL_MovingThumb)
980 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
981 arrowSize, thumbSize );
986 case SCROLL_BOTTOM_RECT:
987 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
988 thumbPos, infoPtr->flags, vertical,
989 FALSE, (hittest == SCROLL_trackHitTest) );
990 if (hittest == SCROLL_trackHitTest)
992 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
994 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
995 SB_PAGEDOWN, (LPARAM)hwndCtl );
997 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
998 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1001 else KillSystemTimer( hwnd, SCROLL_TIMER );
1004 case SCROLL_BOTTOM_ARROW:
1005 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
1006 FALSE, (hittest == SCROLL_trackHitTest) );
1007 if (hittest == SCROLL_trackHitTest)
1009 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1011 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1012 SB_LINEDOWN, (LPARAM)hwndCtl );
1015 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1016 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1019 else KillSystemTimer( hwnd, SCROLL_TIMER );
1023 if (msg == WM_LBUTTONDOWN)
1026 if (hittest == SCROLL_THUMB)
1028 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1029 trackThumbPos + lastMousePos - lastClickPos );
1030 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1031 MAKEWPARAM( SB_THUMBTRACK, val ), (LPARAM)hwndCtl );
1035 if (msg == WM_LBUTTONUP)
1037 hittest = SCROLL_trackHitTest;
1038 SCROLL_trackHitTest = SCROLL_NOWHERE; /* Terminate tracking */
1040 if (hittest == SCROLL_THUMB)
1042 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1043 trackThumbPos + lastMousePos - lastClickPos );
1044 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1045 MAKEWPARAM( SB_THUMBPOSITION, val ), (LPARAM)hwndCtl );
1047 /* SB_ENDSCROLL doesn't report thumb position */
1048 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1049 SB_ENDSCROLL, (LPARAM)hwndCtl );
1051 /* Terminate tracking */
1052 SCROLL_TrackingWin = 0;
1055 ReleaseDC( hwnd, hdc );
1059 /***********************************************************************
1060 * SCROLL_TrackScrollBar
1062 * Track a mouse button press on a scroll-bar.
1063 * pt is in screen-coordinates for non-client scroll bars.
1065 void SCROLL_TrackScrollBar( HWND hwnd, INT scrollbar, POINT pt )
1068 INT xoffset = 0, yoffset = 0;
1070 if (scrollbar != SB_CTL)
1072 WND *wndPtr = WIN_GetPtr( hwnd );
1073 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return;
1074 xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
1075 yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
1076 WIN_ReleasePtr( wndPtr );
1077 ScreenToClient( hwnd, &pt );
1082 SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt );
1086 if (!GetMessageW( &msg, 0, 0, 0 )) break;
1087 if (CallMsgFilterW( &msg, MSGF_SCROLLBAR )) continue;
1088 if (msg.message == WM_LBUTTONUP ||
1089 msg.message == WM_MOUSEMOVE ||
1090 (msg.message == WM_SYSTIMER && msg.wParam == SCROLL_TIMER))
1092 pt.x = (short)LOWORD(msg.lParam) + xoffset;
1093 pt.y = (short)HIWORD(msg.lParam) + yoffset;
1094 SCROLL_HandleScrollEvent( hwnd, scrollbar, msg.message, pt );
1098 TranslateMessage( &msg );
1099 DispatchMessageW( &msg );
1101 if (!IsWindow( hwnd ))
1106 } while (msg.message != WM_LBUTTONUP);
1110 /***********************************************************************
1111 * SCROLL_CreateScrollBar
1113 * Create a scroll bar
1116 * hwnd [I] Handle of window with scrollbar(s)
1117 * lpCreate [I] The style and place of the scroll bar
1119 static void SCROLL_CreateScrollBar(HWND hwnd, LPCREATESTRUCTW lpCreate)
1121 LPSCROLLBAR_INFO info = SCROLL_GetInternalInfo(hwnd, SB_CTL, TRUE);
1124 TRACE("hwnd=%p lpCreate=%p\n", hwnd, lpCreate);
1126 if (lpCreate->style & WS_DISABLED)
1128 info->flags = ESB_DISABLE_BOTH;
1129 TRACE("Created WS_DISABLED scrollbar\n");
1133 if (lpCreate->style & (SBS_SIZEGRIP | SBS_SIZEBOX))
1135 if (lpCreate->style & SBS_SIZEBOXTOPLEFTALIGN)
1136 MoveWindow( hwnd, lpCreate->x, lpCreate->y, GetSystemMetrics(SM_CXVSCROLL)+1,
1137 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1138 else if(lpCreate->style & SBS_SIZEBOXBOTTOMRIGHTALIGN)
1139 MoveWindow( hwnd, lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1140 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1141 GetSystemMetrics(SM_CXVSCROLL)+1,
1142 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1144 else if (lpCreate->style & SBS_VERT)
1146 if (lpCreate->style & SBS_LEFTALIGN)
1147 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1148 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1149 else if (lpCreate->style & SBS_RIGHTALIGN)
1151 lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1153 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1157 if (lpCreate->style & SBS_TOPALIGN)
1158 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1159 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1160 else if (lpCreate->style & SBS_BOTTOMALIGN)
1163 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1164 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1169 /*************************************************************************
1170 * SCROLL_GetScrollInfo
1172 * Internal helper for the API function
1175 * hwnd [I] Handle of window with scrollbar(s)
1176 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1177 * info [IO] fMask specifies which values to retrieve
1180 * FALSE if requested field not filled (f.i. scroll bar does not exist)
1182 static BOOL SCROLL_GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1184 LPSCROLLBAR_INFO infoPtr;
1186 /* handle invalid data structure */
1187 if (!SCROLL_ScrollInfoValid(info)
1188 || !(infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE)))
1191 /* fill in the desired scroll info structure */
1192 if (info->fMask & SIF_PAGE) info->nPage = infoPtr->page;
1193 if (info->fMask & SIF_POS) info->nPos = infoPtr->curVal;
1194 if ((info->fMask & SIF_TRACKPOS) && (info->cbSize == sizeof(*info)))
1195 info->nTrackPos = (SCROLL_TrackingWin == WIN_GetFullHandle(hwnd)) ? SCROLL_TrackingVal : infoPtr->curVal;
1196 if (info->fMask & SIF_RANGE)
1198 info->nMin = infoPtr->minVal;
1199 info->nMax = infoPtr->maxVal;
1202 TRACE("cbSize %02x fMask %04x nMin %d nMax %d nPage %u nPos %d nTrackPos %d\n",
1203 info->cbSize, info->fMask, info->nMin, info->nMax, info->nPage,
1204 info->nPos, info->nTrackPos);
1206 return (info->fMask & SIF_ALL) != 0;
1210 /*************************************************************************
1211 * SCROLL_GetScrollBarInfo
1213 * Internal helper for the API function
1216 * hwnd [I] Handle of window with scrollbar(s)
1217 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1218 * info [IO] cbSize specifies the size of the structure
1223 static BOOL SCROLL_GetScrollBarInfo(HWND hwnd, LONG idObject, LPSCROLLBARINFO info)
1225 LPSCROLLBAR_INFO infoPtr;
1228 DWORD style = GetWindowLongW(hwnd, GWL_STYLE);
1233 case OBJID_CLIENT: nBar = SB_CTL; break;
1234 case OBJID_HSCROLL: nBar = SB_HORZ; break;
1235 case OBJID_VSCROLL: nBar = SB_VERT; break;
1236 default: return FALSE;
1239 /* handle invalid data structure */
1240 if (info->cbSize != sizeof(*info))
1243 SCROLL_GetScrollBarRect(hwnd, nBar, &info->rcScrollBar, &nDummy,
1244 &info->dxyLineButton, &info->xyThumbTop);
1246 info->xyThumbBottom = info->xyThumbTop + info->dxyLineButton;
1248 infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, TRUE);
1250 /* Scroll bar state */
1251 info->rgstate[0] = 0;
1252 if ((nBar == SB_HORZ && !(style & WS_HSCROLL))
1253 || (nBar == SB_VERT && !(style & WS_VSCROLL)))
1254 info->rgstate[0] |= STATE_SYSTEM_INVISIBLE;
1255 if (infoPtr->minVal >= infoPtr->maxVal - max(infoPtr->page - 1, 0))
1257 if (!(info->rgstate[0] & STATE_SYSTEM_INVISIBLE))
1258 info->rgstate[0] |= STATE_SYSTEM_UNAVAILABLE;
1260 info->rgstate[0] |= STATE_SYSTEM_OFFSCREEN;
1262 if (nBar == SB_CTL && !IsWindowEnabled(hwnd))
1263 info->rgstate[0] |= STATE_SYSTEM_UNAVAILABLE;
1265 pressed = ((nBar == SB_VERT) == SCROLL_trackVertical && GetCapture() == hwnd);
1267 /* Top/left arrow button state. MSDN says top/right, but I don't believe it */
1268 info->rgstate[1] = 0;
1269 if (pressed && SCROLL_trackHitTest == SCROLL_TOP_ARROW)
1270 info->rgstate[1] |= STATE_SYSTEM_PRESSED;
1271 if (infoPtr->flags & ESB_DISABLE_LTUP)
1272 info->rgstate[1] |= STATE_SYSTEM_UNAVAILABLE;
1274 /* Page up/left region state. MSDN says up/right, but I don't believe it */
1275 info->rgstate[2] = 0;
1276 if (infoPtr->curVal == infoPtr->minVal)
1277 info->rgstate[2] |= STATE_SYSTEM_INVISIBLE;
1278 if (pressed && SCROLL_trackHitTest == SCROLL_TOP_RECT)
1279 info->rgstate[2] |= STATE_SYSTEM_PRESSED;
1282 info->rgstate[3] = 0;
1283 if (pressed && SCROLL_trackHitTest == SCROLL_THUMB)
1284 info->rgstate[3] |= STATE_SYSTEM_PRESSED;
1286 /* Page down/right region state. MSDN says down/left, but I don't believe it */
1287 info->rgstate[4] = 0;
1288 if (infoPtr->curVal >= infoPtr->maxVal - 1)
1289 info->rgstate[4] |= STATE_SYSTEM_INVISIBLE;
1290 if (pressed && SCROLL_trackHitTest == SCROLL_BOTTOM_RECT)
1291 info->rgstate[4] |= STATE_SYSTEM_PRESSED;
1293 /* Bottom/right arrow button state. MSDN says bottom/left, but I don't believe it */
1294 info->rgstate[5] = 0;
1295 if (pressed && SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW)
1296 info->rgstate[5] |= STATE_SYSTEM_PRESSED;
1297 if (infoPtr->flags & ESB_DISABLE_RTDN)
1298 info->rgstate[5] |= STATE_SYSTEM_UNAVAILABLE;
1304 /*************************************************************************
1305 * SCROLL_GetScrollPos
1307 * Internal helper for the API function
1310 * hwnd [I] Handle of window with scrollbar(s)
1311 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1313 static INT SCROLL_GetScrollPos(HWND hwnd, INT nBar)
1315 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1316 return infoPtr ? infoPtr->curVal: 0;
1320 /*************************************************************************
1321 * SCROLL_GetScrollRange
1323 * Internal helper for the API function
1326 * hwnd [I] Handle of window with scrollbar(s)
1327 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1328 * lpMin [O] Where to store minimum value
1329 * lpMax [O] Where to store maximum value
1335 static BOOL SCROLL_GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1337 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1339 if (lpMin) *lpMin = infoPtr ? infoPtr->minVal : 0;
1340 if (lpMax) *lpMax = infoPtr ? infoPtr->maxVal : 0;
1346 /*************************************************************************
1347 * SCROLL_SetScrollRange
1350 * hwnd [I] Handle of window with scrollbar(s)
1351 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1352 * lpMin [I] Minimum value
1353 * lpMax [I] Maximum value
1356 static BOOL SCROLL_SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal)
1358 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1360 TRACE("hwnd=%p nBar=%d min=%d max=%d\n", hwnd, nBar, minVal, maxVal);
1364 infoPtr->minVal = minVal;
1365 infoPtr->maxVal = maxVal;
1371 /***********************************************************************
1374 static LRESULT WINAPI ScrollBarWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1376 if (!IsWindow( hwnd )) return 0;
1381 SCROLL_CreateScrollBar(hwnd, (LPCREATESTRUCTW)lParam);
1386 SCROLLBAR_INFO *infoPtr;
1387 if ((infoPtr = SCROLL_GetInternalInfo( hwnd, SB_CTL, FALSE )))
1389 infoPtr->flags = wParam ? ESB_ENABLE_BOTH : ESB_DISABLE_BOTH;
1390 SCROLL_RefreshScrollBar(hwnd, SB_CTL, TRUE, TRUE);
1395 case WM_LBUTTONDBLCLK:
1396 case WM_LBUTTONDOWN:
1399 pt.x = (short)LOWORD(lParam);
1400 pt.y = (short)HIWORD(lParam);
1401 SCROLL_TrackScrollBar( hwnd, SB_CTL, pt );
1409 pt.x = (short)LOWORD(lParam);
1410 pt.y = (short)HIWORD(lParam);
1411 SCROLL_HandleScrollEvent( hwnd, SB_CTL, message, pt );
1416 SCROLL_HandleKbdEvent(hwnd, wParam, lParam);
1425 /* Create a caret when a ScrollBar get focus */
1427 int arrowSize, thumbSize, thumbPos, vertical;
1428 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,
1429 &arrowSize, &thumbSize, &thumbPos );
1432 CreateCaret(hwnd, (HBITMAP)1, thumbSize-2, rect.bottom-rect.top-2);
1433 SetCaretPos(thumbPos+1, rect.top+1);
1437 CreateCaret(hwnd, (HBITMAP)1, rect.right-rect.left-2,thumbSize-2);
1438 SetCaretPos(rect.top+1, thumbPos+1);
1447 int arrowSize, thumbSize, thumbPos, vertical;
1448 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,&arrowSize, &thumbSize, &thumbPos );
1450 rect.left=thumbPos+1;
1451 rect.right=rect.left+thumbSize;
1455 rect.top=thumbPos+1;
1456 rect.bottom=rect.top+thumbSize;
1459 InvalidateRect(hwnd,&rect,0);
1468 return DLGC_WANTARROWS; /* Windows returns this value */
1473 HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
1474 if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEGRIP)
1476 SCROLL_DrawSizeGrip( hwnd, hdc);
1478 else if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEBOX)
1481 GetClientRect( hwnd, &rc );
1482 FillRect( hdc, &rc, GetSysColorBrush(COLOR_SCROLLBAR) );
1485 SCROLL_DrawScrollBar( hwnd, hdc, SB_CTL, TRUE, TRUE );
1486 if (!wParam) EndPaint(hwnd, &ps);
1492 return SetScrollPos( hwnd, SB_CTL, wParam, (BOOL)lParam );
1496 return SCROLL_GetScrollPos(hwnd, SB_CTL);
1498 case SBM_SETRANGE16:
1499 if (wParam) message = SBM_SETRANGEREDRAW;
1500 wParam = LOWORD(lParam);
1501 lParam = HIWORD(lParam);
1503 case SBM_SETRANGEREDRAW:
1506 INT oldPos = SCROLL_GetScrollPos( hwnd, SB_CTL );
1507 SCROLL_SetScrollRange( hwnd, SB_CTL, wParam, lParam );
1508 if (message == SBM_SETRANGEREDRAW)
1509 SCROLL_RefreshScrollBar( hwnd, SB_CTL, TRUE, TRUE );
1510 if (oldPos != SCROLL_GetScrollPos( hwnd, SB_CTL )) return oldPos;
1514 case SBM_GETRANGE16:
1518 SCROLL_GetScrollRange(hwnd, SB_CTL, &min, &max);
1519 return MAKELRESULT(min, max);
1523 return SCROLL_GetScrollRange(hwnd, SB_CTL, (LPINT)wParam, (LPINT)lParam);
1525 case SBM_ENABLE_ARROWS16:
1526 case SBM_ENABLE_ARROWS:
1527 return EnableScrollBar( hwnd, SB_CTL, wParam );
1529 case SBM_SETSCROLLINFO:
1530 return SCROLL_SetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam, wParam );
1532 case SBM_GETSCROLLINFO:
1533 return SCROLL_GetScrollInfo(hwnd, SB_CTL, (SCROLLINFO *)lParam);
1535 case SBM_GETSCROLLBARINFO:
1536 return SCROLL_GetScrollBarInfo(hwnd, OBJID_CLIENT, (SCROLLBARINFO *)lParam);
1545 ERR("unknown Win32 msg %04x wp=%08lx lp=%08lx\n",
1546 message, wParam, lParam );
1550 if (message >= WM_USER)
1551 WARN("unknown msg %04x wp=%04lx lp=%08lx\n",
1552 message, wParam, lParam );
1553 return DefWindowProcW( hwnd, message, wParam, lParam );
1559 /*************************************************************************
1560 * SetScrollInfo (USER32.@)
1562 * SetScrollInfo can be used to set the position, upper bound,
1563 * lower bound, and page size of a scrollbar control.
1566 * hwnd [I] Handle of window with scrollbar(s)
1567 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1568 * info [I] Specifies what to change and new values
1569 * bRedraw [I] Should scrollbar be redrawn afterwards?
1572 * Scrollbar position
1575 * For 100 lines of text to be displayed in a window of 25 lines,
1576 * one would for instance use info->nMin=0, info->nMax=75
1577 * (corresponding to the 76 different positions of the window on
1578 * the text), and info->nPage=25.
1580 INT WINAPI SetScrollInfo(HWND hwnd, INT nBar, const SCROLLINFO *info, BOOL bRedraw)
1582 TRACE("hwnd=%p nBar=%d info=%p, bRedraw=%d\n", hwnd, nBar, info, bRedraw);
1584 /* Refer SB_CTL requests to the window */
1586 return SendMessageW(hwnd, SBM_SETSCROLLINFO, bRedraw, (LPARAM)info);
1588 return SCROLL_SetScrollInfo( hwnd, nBar, info, bRedraw );
1591 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar, LPCSCROLLINFO info, BOOL bRedraw )
1593 /* Update the scrollbar state and set action flags according to
1594 * what has to be done graphics wise. */
1596 SCROLLBAR_INFO *infoPtr;
1600 /* handle invalid data structure */
1601 if (!SCROLL_ScrollInfoValid(info)
1602 || !(infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, TRUE)))
1605 if (TRACE_ON(scroll))
1607 TRACE("hwnd=%p bar=%d", hwnd, nBar);
1608 if (info->fMask & SIF_PAGE) TRACE( " page=%d", info->nPage );
1609 if (info->fMask & SIF_POS) TRACE( " pos=%d", info->nPos );
1610 if (info->fMask & SIF_RANGE) TRACE( " min=%d max=%d", info->nMin, info->nMax );
1614 /* Set the page size */
1616 if (info->fMask & SIF_PAGE)
1618 if( infoPtr->page != info->nPage )
1620 infoPtr->page = info->nPage;
1621 action |= SA_SSI_REFRESH;
1625 /* Set the scroll pos */
1627 if (info->fMask & SIF_POS)
1629 if( infoPtr->curVal != info->nPos )
1631 infoPtr->curVal = info->nPos;
1632 action |= SA_SSI_REFRESH;
1636 /* Set the scroll range */
1638 if (info->fMask & SIF_RANGE)
1640 /* Invalid range -> range is set to (0,0) */
1641 if ((info->nMin > info->nMax) ||
1642 ((UINT)(info->nMax - info->nMin) >= 0x80000000))
1644 action |= SA_SSI_REFRESH;
1645 infoPtr->minVal = 0;
1646 infoPtr->maxVal = 0;
1650 if( infoPtr->minVal != info->nMin ||
1651 infoPtr->maxVal != info->nMax )
1653 action |= SA_SSI_REFRESH;
1654 infoPtr->minVal = info->nMin;
1655 infoPtr->maxVal = info->nMax;
1660 /* Make sure the page size is valid */
1661 if (infoPtr->page < 0) infoPtr->page = 0;
1662 else if (infoPtr->page > infoPtr->maxVal - infoPtr->minVal + 1 )
1663 infoPtr->page = infoPtr->maxVal - infoPtr->minVal + 1;
1665 /* Make sure the pos is inside the range */
1667 if (infoPtr->curVal < infoPtr->minVal)
1668 infoPtr->curVal = infoPtr->minVal;
1669 else if (infoPtr->curVal > infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1670 infoPtr->curVal = infoPtr->maxVal - max( infoPtr->page-1, 0 );
1672 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1673 infoPtr->page, infoPtr->curVal,
1674 infoPtr->minVal, infoPtr->maxVal );
1676 /* don't change the scrollbar state if SetScrollInfo
1677 * is just called with SIF_DISABLENOSCROLL
1679 if(!(info->fMask & SIF_ALL)) goto done;
1681 /* Check if the scrollbar should be hidden or disabled */
1683 if (info->fMask & (SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL))
1685 new_flags = infoPtr->flags;
1686 if (infoPtr->minVal >= infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1688 /* Hide or disable scroll-bar */
1689 if (info->fMask & SIF_DISABLENOSCROLL)
1691 new_flags = ESB_DISABLE_BOTH;
1692 action |= SA_SSI_REFRESH;
1694 else if ((nBar != SB_CTL) && (action & SA_SSI_REFRESH))
1696 action = SA_SSI_HIDE;
1699 else /* Show and enable scroll-bar only if no page only changed. */
1700 if (info->fMask != SIF_PAGE)
1702 new_flags = ESB_ENABLE_BOTH;
1703 if ((nBar != SB_CTL) && ( (action & SA_SSI_REFRESH) ))
1704 action |= SA_SSI_SHOW;
1707 if (infoPtr->flags != new_flags) /* check arrow flags */
1709 infoPtr->flags = new_flags;
1710 action |= SA_SSI_REPAINT_ARROWS;
1715 if( action & SA_SSI_HIDE )
1716 SCROLL_ShowScrollBar( hwnd, nBar, FALSE, FALSE );
1719 if( action & SA_SSI_SHOW )
1720 if( SCROLL_ShowScrollBar( hwnd, nBar, TRUE, TRUE ) )
1721 return infoPtr->curVal; /* SetWindowPos() already did the painting */
1724 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
1725 else if( action & SA_SSI_REPAINT_ARROWS )
1726 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, FALSE );
1729 /* Return current position */
1730 return infoPtr->curVal;
1734 /*************************************************************************
1735 * GetScrollInfo (USER32.@)
1737 * GetScrollInfo can be used to retrieve the position, upper bound,
1738 * lower bound, and page size of a scrollbar control.
1741 * hwnd [I] Handle of window with scrollbar(s)
1742 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1743 * info [IO] fMask specifies which values to retrieve
1746 * TRUE if SCROLLINFO is filled
1747 * ( if nBar is SB_CTL, GetScrollInfo returns TRUE even if nothing
1750 BOOL WINAPI GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1752 TRACE("hwnd=%p nBar=%d info=%p\n", hwnd, nBar, info);
1754 /* Refer SB_CTL requests to the window */
1757 SendMessageW(hwnd, SBM_GETSCROLLINFO, (WPARAM)0, (LPARAM)info);
1760 return SCROLL_GetScrollInfo(hwnd, nBar, info);
1764 /*************************************************************************
1765 * GetScrollBarInfo (USER32.@)
1767 * GetScrollBarInfo can be used to retrieve information about a scrollbar
1771 * hwnd [I] Handle of window with scrollbar(s)
1772 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1773 * info [IO] cbSize specifies the size of SCROLLBARINFO
1778 BOOL WINAPI GetScrollBarInfo(HWND hwnd, LONG idObject, LPSCROLLBARINFO info)
1780 TRACE("hwnd=%p idObject=%d info=%p\n", hwnd, idObject, info);
1782 /* Refer OBJID_CLIENT requests to the window */
1783 if (idObject == OBJID_CLIENT)
1784 return SendMessageW(hwnd, SBM_GETSCROLLBARINFO, (WPARAM)0, (LPARAM)info);
1786 return SCROLL_GetScrollBarInfo(hwnd, idObject, info);
1790 /*************************************************************************
1791 * SetScrollPos (USER32.@)
1793 * Sets the current position of the scroll thumb.
1796 * hwnd [I] Handle of window with scrollbar(s)
1797 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1798 * nPos [I] New value
1799 * bRedraw [I] Should scrollbar be redrawn afterwards?
1802 * Success: Scrollbar position
1806 * Note the ambiguity when 0 is returned. Use GetLastError
1807 * to make sure there was an error (and to know which one).
1809 INT WINAPI SetScrollPos( HWND hwnd, INT nBar, INT nPos, BOOL bRedraw)
1812 SCROLLBAR_INFO *infoPtr;
1815 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, FALSE ))) return 0;
1816 oldPos = infoPtr->curVal;
1817 info.cbSize = sizeof(info);
1819 info.fMask = SIF_POS;
1820 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1825 /*************************************************************************
1826 * GetScrollPos (USER32.@)
1828 * Gets the current position of the scroll thumb.
1831 * hwnd [I] Handle of window with scrollbar(s)
1832 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1835 * Success: Current position
1839 * There is ambiguity when 0 is returned. Use GetLastError
1840 * to make sure there was an error (and to know which one).
1842 INT WINAPI GetScrollPos(HWND hwnd, INT nBar)
1844 TRACE("hwnd=%p nBar=%d\n", hwnd, nBar);
1846 /* Refer SB_CTL requests to the window */
1848 return SendMessageW(hwnd, SBM_GETPOS, (WPARAM)0, (LPARAM)0);
1850 return SCROLL_GetScrollPos(hwnd, nBar);
1854 /*************************************************************************
1855 * SetScrollRange (USER32.@)
1856 * The SetScrollRange function sets the minimum and maximum scroll box positions
1857 * If nMinPos and nMaxPos is the same value, the scroll bar will hide
1859 * Sets the range of the scroll bar.
1862 * hwnd [I] Handle of window with scrollbar(s)
1863 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1864 * minVal [I] New minimum value
1865 * maxVal [I] New Maximum value
1866 * bRedraw [I] Should scrollbar be redrawn afterwards?
1872 BOOL WINAPI SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal, BOOL bRedraw)
1876 TRACE("hwnd=%p nBar=%d min=%d max=%d, bRedraw=%d\n", hwnd, nBar, minVal, maxVal, bRedraw);
1878 info.cbSize = sizeof(info);
1879 info.fMask = SIF_RANGE;
1882 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1887 /*************************************************************************
1888 * SCROLL_SetNCSbState
1890 * Updates both scrollbars at the same time. Used by MDI CalcChildScroll().
1892 INT SCROLL_SetNCSbState(HWND hwnd, int vMin, int vMax, int vPos,
1893 int hMin, int hMax, int hPos)
1895 SCROLLINFO vInfo, hInfo;
1897 vInfo.cbSize = hInfo.cbSize = sizeof(SCROLLINFO);
1904 vInfo.fMask = hInfo.fMask = SIF_RANGE | SIF_POS;
1906 SCROLL_SetScrollInfo( hwnd, SB_VERT, &vInfo, TRUE );
1907 SCROLL_SetScrollInfo( hwnd, SB_HORZ, &hInfo, TRUE );
1913 /*************************************************************************
1914 * GetScrollRange (USER32.@)
1916 * Gets the range of the scroll bar.
1919 * hwnd [I] Handle of window with scrollbar(s)
1920 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1921 * lpMin [O] Where to store minimum value
1922 * lpMax [O] Where to store maximum value
1925 * TRUE if values is filled
1927 BOOL WINAPI GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1929 TRACE("hwnd=%p nBar=%d lpMin=%p lpMax=%p\n", hwnd, nBar, lpMin, lpMax);
1931 /* Refer SB_CTL requests to the window */
1933 SendMessageW(hwnd, SBM_GETRANGE, (WPARAM)lpMin, (LPARAM)lpMax);
1935 SCROLL_GetScrollRange(hwnd, nBar, lpMin, lpMax);
1941 /*************************************************************************
1942 * SCROLL_ShowScrollBar()
1944 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1946 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar, BOOL fShowH, BOOL fShowV )
1948 ULONG old_style, set_bits = 0, clear_bits = 0;
1950 TRACE("hwnd=%p bar=%d horz=%d, vert=%d\n", hwnd, nBar, fShowH, fShowV );
1955 ShowWindow( hwnd, fShowH ? SW_SHOW : SW_HIDE );
1960 if (fShowH) set_bits |= WS_HSCROLL;
1961 else clear_bits |= WS_HSCROLL;
1962 if( nBar == SB_HORZ ) break;
1965 if (fShowV) set_bits |= WS_VSCROLL;
1966 else clear_bits |= WS_VSCROLL;
1970 return FALSE; /* Nothing to do! */
1973 old_style = WIN_SetStyle( hwnd, set_bits, clear_bits );
1974 if ((old_style & clear_bits) != 0 || (old_style & set_bits) != set_bits)
1976 /* frame has been changed, let the window redraw itself */
1977 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
1978 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
1981 return FALSE; /* no frame changes */
1985 /*************************************************************************
1986 * ShowScrollBar (USER32.@)
1988 * Shows or hides the scroll bar.
1991 * hwnd [I] Handle of window with scrollbar(s)
1992 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1993 * fShow [I] TRUE = show, FALSE = hide
1999 BOOL WINAPI ShowScrollBar(HWND hwnd, INT nBar, BOOL fShow)
2004 SCROLL_ShowScrollBar( hwnd, nBar, (nBar == SB_VERT) ? 0 : fShow,
2005 (nBar == SB_HORZ) ? 0 : fShow );
2010 /*************************************************************************
2011 * EnableScrollBar (USER32.@)
2013 * Enables or disables the scroll bars.
2015 BOOL WINAPI EnableScrollBar( HWND hwnd, UINT nBar, UINT flags )
2018 SCROLLBAR_INFO *infoPtr;
2020 flags &= ESB_DISABLE_BOTH;
2022 if (nBar == SB_BOTH)
2024 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, SB_VERT, TRUE ))) return FALSE;
2025 if (!(bFineWithMe = (infoPtr->flags == flags)) )
2027 infoPtr->flags = flags;
2028 SCROLL_RefreshScrollBar( hwnd, SB_VERT, TRUE, TRUE );
2035 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, TRUE ))) return FALSE;
2036 if (bFineWithMe && infoPtr->flags == flags) return FALSE;
2037 infoPtr->flags = flags;
2039 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );