4 * Copyright 1993 Martin Ayotte
5 * Copyright 1994, 1996 Alexandre Julliard
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * This code was audited for completeness against the documented features
24 * of Comctl32.dll version 6.0 on Oct. 8, 2004, by Dimitrie O. Paun.
26 * Unless otherwise noted, we believe this code to be complete, as per
27 * the specification mentioned above.
28 * If you discover missing features, or bugs, please note them below.
32 * - SBM_GETSCROLLBARINFO
41 #include "wine/winuser16.h"
44 #include "wine/debug.h"
45 #include "user_private.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(scroll);
52 INT curVal; /* Current scroll-bar value */
53 INT minVal; /* Minimum scroll-bar value */
54 INT maxVal; /* Maximum scroll-bar value */
55 INT page; /* Page size of scroll bar (Win32) */
56 UINT flags; /* EnableScrollBar flags */
57 } SCROLLBAR_INFO, *LPSCROLLBAR_INFO;
60 /* Minimum size of the rectangle between the arrows */
61 #define SCROLL_MIN_RECT 4
63 /* Minimum size of the thumb in pixels */
64 #define SCROLL_MIN_THUMB 6
66 /* Overlap between arrows and thumb */
67 #define SCROLL_ARROW_THUMB_OVERLAP 0
69 /* Delay (in ms) before first repetition when holding the button down */
70 #define SCROLL_FIRST_DELAY 200
72 /* Delay (in ms) between scroll repetitions */
73 #define SCROLL_REPEAT_DELAY 50
76 #define SCROLL_TIMER 0
78 /* Scroll-bar hit testing */
81 SCROLL_NOWHERE, /* Outside the scroll bar */
82 SCROLL_TOP_ARROW, /* Top or left arrow */
83 SCROLL_TOP_RECT, /* Rectangle between the top arrow and the thumb */
84 SCROLL_THUMB, /* Thumb rectangle */
85 SCROLL_BOTTOM_RECT, /* Rectangle between the thumb and the bottom arrow */
86 SCROLL_BOTTOM_ARROW /* Bottom or right arrow */
89 /* What to do after SCROLL_SetScrollInfo() */
90 #define SA_SSI_HIDE 0x0001
91 #define SA_SSI_SHOW 0x0002
92 #define SA_SSI_REFRESH 0x0004
93 #define SA_SSI_REPAINT_ARROWS 0x0008
95 /* Thumb-tracking info */
96 static HWND SCROLL_TrackingWin = 0;
97 static INT SCROLL_TrackingBar = 0;
98 static INT SCROLL_TrackingPos = 0;
99 static INT SCROLL_TrackingVal = 0;
100 /* Hit test code of the last button-down event */
101 static enum SCROLL_HITTEST SCROLL_trackHitTest;
102 static BOOL SCROLL_trackVertical;
104 /* Is the moving thumb being displayed? */
105 static BOOL SCROLL_MovingThumb = FALSE;
107 /* Local functions */
108 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar,
109 BOOL fShowH, BOOL fShowV );
110 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar,
111 const SCROLLINFO *info, BOOL bRedraw );
112 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
113 RECT *rect, INT arrowSize,
114 INT thumbSize, INT thumbPos,
115 UINT flags, BOOL vertical,
116 BOOL top_selected, BOOL bottom_selected );
117 static LRESULT WINAPI ScrollBarWndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
120 /*********************************************************************
121 * scrollbar class descriptor
123 const struct builtin_class_descr SCROLL_builtin_class =
125 "ScrollBar", /* name */
126 CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC, /* style */
127 NULL, /* procA (winproc is Unicode only) */
128 ScrollBarWndProc, /* procW */
129 sizeof(SCROLLBAR_INFO), /* extra */
130 IDC_ARROW, /* cursor */
134 /***********************************************************************
135 * SCROLL_ScrollInfoValid
137 * Determine if the supplied SCROLLINFO struct is valid.
138 * info [in] The SCROLLINFO struct to be tested
140 inline static BOOL SCROLL_ScrollInfoValid( LPCSCROLLINFO info )
142 return !(info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)
143 || (info->cbSize != sizeof(*info)
144 && info->cbSize != sizeof(*info) - sizeof(info->nTrackPos)));
148 /***********************************************************************
149 * SCROLL_GetInternalInfo
151 * Returns pointer to internal SCROLLBAR_INFO structure for nBar
152 * or NULL if failed (f.i. scroll bar does not exist yet)
153 * If alloc is TRUE and the struct does not exist yet, create it.
155 static SCROLLBAR_INFO *SCROLL_GetInternalInfo( HWND hwnd, INT nBar, BOOL alloc )
157 SCROLLBAR_INFO *infoPtr = NULL;
158 WND *wndPtr = WIN_GetPtr( hwnd );
160 if (!wndPtr || wndPtr == WND_OTHER_PROCESS) return NULL;
163 case SB_HORZ: infoPtr = (SCROLLBAR_INFO *)wndPtr->pHScroll; break;
164 case SB_VERT: infoPtr = (SCROLLBAR_INFO *)wndPtr->pVScroll; break;
165 case SB_CTL: infoPtr = (SCROLLBAR_INFO *)wndPtr->wExtra; break;
166 case SB_BOTH: WARN("with SB_BOTH"); break;
169 if (!infoPtr && alloc)
171 if (nBar != SB_HORZ && nBar != SB_VERT)
172 WARN("Cannot initialize nBar=%d\n",nBar);
173 else if ((infoPtr = HeapAlloc( GetProcessHeap(), 0, sizeof(SCROLLBAR_INFO) )))
175 /* Set default values */
176 infoPtr->minVal = infoPtr->curVal = infoPtr->page = 0;
177 /* From MSDN: max for a standard scroll bar is 100 by default. */
178 infoPtr->maxVal = 100;
179 /* Scroll bar is enabled by default after create */
180 infoPtr->flags = ESB_ENABLE_BOTH;
181 if (nBar == SB_HORZ) wndPtr->pHScroll = infoPtr;
182 else wndPtr->pVScroll = infoPtr;
185 WIN_ReleasePtr( wndPtr );
190 /***********************************************************************
191 * SCROLL_GetScrollBarRect
193 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
194 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
195 * 'arrowSize' returns the width or height of an arrow (depending on
196 * the orientation of the scrollbar), 'thumbSize' returns the size of
197 * the thumb, and 'thumbPos' returns the position of the thumb
198 * relative to the left or to the top.
199 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
201 static BOOL SCROLL_GetScrollBarRect( HWND hwnd, INT nBar, RECT *lprect,
202 INT *arrowSize, INT *thumbSize,
207 WND *wndPtr = WIN_GetPtr( hwnd );
209 if (!wndPtr || wndPtr == WND_OTHER_PROCESS) return FALSE;
214 lprect->left = wndPtr->rectClient.left - wndPtr->rectWindow.left;
215 lprect->top = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
216 lprect->right = wndPtr->rectClient.right - wndPtr->rectWindow.left;
217 lprect->bottom = lprect->top + GetSystemMetrics(SM_CYHSCROLL);
218 if(wndPtr->dwStyle & WS_BORDER) {
221 } else if(wndPtr->dwStyle & WS_VSCROLL)
227 if((wndPtr->dwExStyle & WS_EX_LEFTSCROLLBAR) != 0)
228 lprect->left = wndPtr->rectClient.left - wndPtr->rectWindow.left - GetSystemMetrics(SM_CXVSCROLL);
230 lprect->left = wndPtr->rectClient.right - wndPtr->rectWindow.left;
231 lprect->top = wndPtr->rectClient.top - wndPtr->rectWindow.top;
232 lprect->right = lprect->left + GetSystemMetrics(SM_CXVSCROLL);
233 lprect->bottom = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
234 if(wndPtr->dwStyle & WS_BORDER) {
237 } else if(wndPtr->dwStyle & WS_HSCROLL)
243 GetClientRect( hwnd, lprect );
244 vertical = ((wndPtr->dwStyle & SBS_VERT) != 0);
248 WIN_ReleasePtr( wndPtr );
252 if (vertical) pixels = lprect->bottom - lprect->top;
253 else pixels = lprect->right - lprect->left;
255 if (pixels <= 2*GetSystemMetrics(SM_CXVSCROLL) + SCROLL_MIN_RECT)
257 if (pixels > SCROLL_MIN_RECT)
258 *arrowSize = (pixels - SCROLL_MIN_RECT) / 2;
261 *thumbPos = *thumbSize = 0;
265 SCROLLBAR_INFO *info = SCROLL_GetInternalInfo( hwnd, nBar, FALSE );
268 WARN("called for missing scroll bar");
271 *arrowSize = GetSystemMetrics(SM_CXVSCROLL);
272 pixels -= (2 * (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP));
276 *thumbSize = MulDiv(pixels,info->page,(info->maxVal-info->minVal+1));
277 if (*thumbSize < SCROLL_MIN_THUMB) *thumbSize = SCROLL_MIN_THUMB;
279 else *thumbSize = GetSystemMetrics(SM_CXVSCROLL);
281 if (((pixels -= *thumbSize ) < 0) ||
282 ((info->flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH))
284 /* Rectangle too small or scrollbar disabled -> no thumb */
285 *thumbPos = *thumbSize = 0;
289 INT max = info->maxVal - max( info->page-1, 0 );
290 if (info->minVal >= max)
291 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
293 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP
294 + MulDiv(pixels, (info->curVal-info->minVal),(max - info->minVal));
297 WIN_ReleasePtr( wndPtr );
302 /***********************************************************************
305 * Compute the current scroll position based on the thumb position in pixels
306 * from the top of the scroll-bar.
308 static UINT SCROLL_GetThumbVal( SCROLLBAR_INFO *infoPtr, RECT *rect,
309 BOOL vertical, INT pos )
312 INT pixels = vertical ? rect->bottom-rect->top : rect->right-rect->left;
314 if ((pixels -= 2*(GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP)) <= 0)
315 return infoPtr->minVal;
319 thumbSize = MulDiv(pixels,infoPtr->page,(infoPtr->maxVal-infoPtr->minVal+1));
320 if (thumbSize < SCROLL_MIN_THUMB) thumbSize = SCROLL_MIN_THUMB;
322 else thumbSize = GetSystemMetrics(SM_CXVSCROLL);
324 if ((pixels -= thumbSize) <= 0) return infoPtr->minVal;
326 pos = max( 0, pos - (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP) );
327 if (pos > pixels) pos = pixels;
329 if (!infoPtr->page) pos *= infoPtr->maxVal - infoPtr->minVal;
330 else pos *= infoPtr->maxVal - infoPtr->minVal - infoPtr->page + 1;
331 return infoPtr->minVal + ((pos + pixels / 2) / pixels);
334 /***********************************************************************
337 static BOOL SCROLL_PtInRectEx( LPRECT lpRect, POINT pt, BOOL vertical )
343 rect.left -= lpRect->right - lpRect->left;
344 rect.right += lpRect->right - lpRect->left;
348 rect.top -= lpRect->bottom - lpRect->top;
349 rect.bottom += lpRect->bottom - lpRect->top;
351 return PtInRect( &rect, pt );
354 /***********************************************************************
357 static POINT SCROLL_ClipPos( LPRECT lpRect, POINT pt )
359 if( pt.x < lpRect->left )
362 if( pt.x > lpRect->right )
363 pt.x = lpRect->right;
365 if( pt.y < lpRect->top )
368 if( pt.y > lpRect->bottom )
369 pt.y = lpRect->bottom;
375 /***********************************************************************
378 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
380 static enum SCROLL_HITTEST SCROLL_HitTest( HWND hwnd, INT nBar,
381 POINT pt, BOOL bDragging )
383 INT arrowSize, thumbSize, thumbPos;
386 BOOL vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
387 &arrowSize, &thumbSize, &thumbPos );
389 if ( (bDragging && !SCROLL_PtInRectEx( &rect, pt, vertical )) ||
390 (!PtInRect( &rect, pt )) ) return SCROLL_NOWHERE;
394 if (pt.y < rect.top + arrowSize) return SCROLL_TOP_ARROW;
395 if (pt.y >= rect.bottom - arrowSize) return SCROLL_BOTTOM_ARROW;
396 if (!thumbPos) return SCROLL_TOP_RECT;
398 if (pt.y < thumbPos) return SCROLL_TOP_RECT;
399 if (pt.y >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
401 else /* horizontal */
403 if (pt.x < rect.left + arrowSize) return SCROLL_TOP_ARROW;
404 if (pt.x >= rect.right - arrowSize) return SCROLL_BOTTOM_ARROW;
405 if (!thumbPos) return SCROLL_TOP_RECT;
407 if (pt.x < thumbPos) return SCROLL_TOP_RECT;
408 if (pt.x >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
414 /***********************************************************************
417 * Draw the scroll bar arrows.
419 static void SCROLL_DrawArrows( HDC hdc, SCROLLBAR_INFO *infoPtr,
420 RECT *rect, INT arrowSize, BOOL vertical,
421 BOOL top_pressed, BOOL bottom_pressed )
427 r.bottom = r.top + arrowSize;
429 r.right = r.left + arrowSize;
431 DrawFrameControl( hdc, &r, DFC_SCROLL,
432 (vertical ? DFCS_SCROLLUP : DFCS_SCROLLLEFT)
433 | (top_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
434 | (infoPtr->flags&ESB_DISABLE_LTUP ? DFCS_INACTIVE : 0 ) );
438 r.top = r.bottom-arrowSize;
440 r.left = r.right-arrowSize;
442 DrawFrameControl( hdc, &r, DFC_SCROLL,
443 (vertical ? DFCS_SCROLLDOWN : DFCS_SCROLLRIGHT)
444 | (bottom_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
445 | (infoPtr->flags&ESB_DISABLE_RTDN ? DFCS_INACTIVE : 0) );
448 static void SCROLL_DrawMovingThumb( HDC hdc, RECT *rect, BOOL vertical,
449 INT arrowSize, INT thumbSize )
451 INT pos = SCROLL_TrackingPos;
455 max_size = rect->bottom - rect->top;
457 max_size = rect->right - rect->left;
459 max_size -= (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) + thumbSize;
461 if( pos < (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) )
462 pos = (arrowSize-SCROLL_ARROW_THUMB_OVERLAP);
463 else if( pos > max_size )
466 SCROLL_DrawInterior_9x( SCROLL_TrackingWin, hdc, SCROLL_TrackingBar,
467 rect, arrowSize, thumbSize, pos,
468 0, vertical, FALSE, FALSE );
470 SCROLL_MovingThumb = !SCROLL_MovingThumb;
473 /***********************************************************************
474 * SCROLL_DrawInterior
476 * Draw the scroll bar interior (everything except the arrows).
478 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
479 RECT *rect, INT arrowSize,
480 INT thumbSize, INT thumbPos,
481 UINT flags, BOOL vertical,
482 BOOL top_selected, BOOL bottom_selected )
486 HBRUSH hSaveBrush,hBrush;
488 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
489 * The window-owned scrollbars need to call DEFWND_ControlColor
490 * to correctly setup default scrollbar colors
494 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
495 (WPARAM)hdc,(LPARAM)hwnd);
499 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
502 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
503 hSaveBrush = SelectObject( hdc, hBrush );
505 /* Calculate the scroll rectangle */
509 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
510 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
514 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
515 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
518 /* Draw the scroll rectangles and thumb */
519 if (!thumbPos) /* No thumb to draw */
521 PatBlt( hdc, r.left, r.top,
522 r.right - r.left, r.bottom - r.top,
525 /* cleanup and return */
526 SelectObject( hdc, hSavePen );
527 SelectObject( hdc, hSaveBrush );
533 PatBlt( hdc, r.left, r.top,
535 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
536 top_selected ? 0x0f0000 : PATCOPY );
537 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
538 PatBlt( hdc, r.left, r.top + thumbSize,
540 r.bottom - r.top - thumbSize,
541 bottom_selected ? 0x0f0000 : PATCOPY );
542 r.bottom = r.top + thumbSize;
544 else /* horizontal */
546 PatBlt( hdc, r.left, r.top,
547 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
549 top_selected ? 0x0f0000 : PATCOPY );
550 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
551 PatBlt( hdc, r.left + thumbSize, r.top,
552 r.right - r.left - thumbSize,
554 bottom_selected ? 0x0f0000 : PATCOPY );
555 r.right = r.left + thumbSize;
559 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT | BF_MIDDLE );
562 SelectObject( hdc, hSavePen );
563 SelectObject( hdc, hSaveBrush );
567 static void SCROLL_DrawInterior( HWND hwnd, HDC hdc, INT nBar,
568 RECT *rect, INT arrowSize,
569 INT thumbSize, INT thumbPos,
570 UINT flags, BOOL vertical,
571 BOOL top_selected, BOOL bottom_selected )
575 HBRUSH hSaveBrush,hBrush;
576 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
578 if (Save_SCROLL_MovingThumb &&
579 (SCROLL_TrackingWin == hwnd) &&
580 (SCROLL_TrackingBar == nBar))
581 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
583 /* Select the correct brush and pen */
585 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
586 * The window-owned scrollbars need to call DEFWND_ControlColor
587 * to correctly setup default scrollbar colors
589 if (nBar == SB_CTL) {
590 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
591 (WPARAM)hdc,(LPARAM)hwnd);
593 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
595 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
596 hSaveBrush = SelectObject( hdc, hBrush );
598 /* Calculate the scroll rectangle */
603 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
604 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
608 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
609 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
612 /* Draw the scroll bar frame */
614 /* Draw the scroll rectangles and thumb */
616 if (!thumbPos) /* No thumb to draw */
618 PatBlt( hdc, r.left, r.top, r.right - r.left, r.bottom - r.top, PATCOPY );
620 /* cleanup and return */
621 SelectObject( hdc, hSavePen );
622 SelectObject( hdc, hSaveBrush );
628 PatBlt( hdc, r.left, r.top, r.right - r.left,
629 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
630 top_selected ? 0x0f0000 : PATCOPY );
631 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
632 PatBlt( hdc, r.left, r.top + thumbSize, r.right - r.left,
633 r.bottom - r.top - thumbSize,
634 bottom_selected ? 0x0f0000 : PATCOPY );
635 r.bottom = r.top + thumbSize;
637 else /* horizontal */
639 PatBlt( hdc, r.left, r.top,
640 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
641 r.bottom - r.top, top_selected ? 0x0f0000 : PATCOPY );
642 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
643 PatBlt( hdc, r.left + thumbSize, r.top, r.right - r.left - thumbSize,
644 r.bottom - r.top, bottom_selected ? 0x0f0000 : PATCOPY );
645 r.right = r.left + thumbSize;
650 SelectObject( hdc, GetSysColorBrush(COLOR_BTNFACE) );
651 Rectangle( hdc, r.left+1, r.top+1, r.right-1, r.bottom-1 );
652 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT );
654 if (Save_SCROLL_MovingThumb &&
655 (SCROLL_TrackingWin == hwnd) &&
656 (SCROLL_TrackingBar == nBar))
657 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
660 SelectObject( hdc, hSavePen );
661 SelectObject( hdc, hSaveBrush );
665 /***********************************************************************
666 * SCROLL_DrawScrollBar
668 * Redraw the whole scrollbar.
670 void SCROLL_DrawScrollBar( HWND hwnd, HDC hdc, INT nBar,
671 BOOL arrows, BOOL interior )
673 INT arrowSize, thumbSize, thumbPos;
676 SCROLLBAR_INFO *infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, FALSE );
677 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
678 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
680 if (!(hwnd = WIN_GetFullHandle( hwnd ))) return;
683 ((nBar == SB_VERT) && !(style & WS_VSCROLL)) ||
684 ((nBar == SB_HORZ) && !(style & WS_HSCROLL))) return;
685 if (!WIN_IsWindowDrawable( hwnd, FALSE )) return;
687 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
688 &arrowSize, &thumbSize, &thumbPos );
690 /* do not draw if the scrollbar rectangle is empty */
691 if(IsRectEmpty(&rect)) return;
693 if (Save_SCROLL_MovingThumb &&
694 (SCROLL_TrackingWin == hwnd) &&
695 (SCROLL_TrackingBar == nBar))
696 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
698 /* Draw the arrows */
700 if (arrows && arrowSize)
702 if( vertical == SCROLL_trackVertical && GetCapture() == hwnd )
703 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
704 (SCROLL_trackHitTest == SCROLL_TOP_ARROW),
705 (SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW) );
707 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
711 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
712 thumbPos, infoPtr->flags, vertical, FALSE, FALSE );
714 if (Save_SCROLL_MovingThumb &&
715 (SCROLL_TrackingWin == hwnd) &&
716 (SCROLL_TrackingBar == nBar))
717 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
719 /* if scroll bar has focus, reposition the caret */
720 if(hwnd==GetFocus() && (nBar==SB_CTL))
724 SetCaretPos(thumbPos+1, rect.top+1);
728 SetCaretPos(rect.top+1, thumbPos+1);
733 /***********************************************************************
734 * SCROLL_DrawSizeGrip
736 * Draw the size grip.
738 static void SCROLL_DrawSizeGrip( HWND hwnd, HDC hdc)
742 GetClientRect( hwnd, &rc );
743 FillRect( hdc, &rc, GetSysColorBrush(COLOR_SCROLLBAR) );
744 rc.left = max( rc.left, rc.right - GetSystemMetrics(SM_CXVSCROLL) - 1 );
745 rc.top = max( rc.top, rc.bottom - GetSystemMetrics(SM_CYHSCROLL) - 1 );
746 DrawFrameControl( hdc, &rc, DFC_SCROLL, DFCS_SCROLLSIZEGRIP );
750 /***********************************************************************
751 * SCROLL_RefreshScrollBar
753 * Repaint the scroll bar interior after a SetScrollRange() or
754 * SetScrollPos() call.
756 static void SCROLL_RefreshScrollBar( HWND hwnd, INT nBar,
757 BOOL arrows, BOOL interior )
759 HDC hdc = GetDCEx( hwnd, 0,
760 DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW) );
763 SCROLL_DrawScrollBar( hwnd, hdc, nBar, arrows, interior );
764 ReleaseDC( hwnd, hdc );
768 /***********************************************************************
769 * SCROLL_HandleKbdEvent
771 * Handle a keyboard event (only for SB_CTL scrollbars with focus).
774 * hwnd [I] Handle of window with scrollbar(s)
775 * wParam [I] Variable input including enable state
776 * lParam [I] Variable input including input point
778 static void SCROLL_HandleKbdEvent(HWND hwnd, WPARAM wParam, LPARAM lParam)
780 TRACE("hwnd=%p wParam=%d lParam=%ld\n", hwnd, wParam, lParam);
782 /* hide caret on first KEYDOWN to prevent flicker */
783 if ((lParam & PFD_DOUBLEBUFFER_DONTCARE) == 0)
788 case VK_PRIOR: wParam = SB_PAGEUP; break;
789 case VK_NEXT: wParam = SB_PAGEDOWN; break;
790 case VK_HOME: wParam = SB_TOP; break;
791 case VK_END: wParam = SB_BOTTOM; break;
792 case VK_UP: wParam = SB_LINEUP; break;
793 case VK_DOWN: wParam = SB_LINEDOWN; break;
796 SendMessageW(GetParent(hwnd),
797 ((GetWindowLongW( hwnd, GWL_STYLE ) & SBS_VERT) ?
798 WM_VSCROLL : WM_HSCROLL), wParam, (LPARAM)hwnd);
802 /***********************************************************************
803 * SCROLL_HandleScrollEvent
805 * Handle a mouse or timer event for the scrollbar.
806 * 'pt' is the location of the mouse event in client (for SB_CTL) or
807 * windows coordinates.
809 static void SCROLL_HandleScrollEvent( HWND hwnd, INT nBar, UINT msg, POINT pt)
811 /* Previous mouse position for timer events */
813 /* Thumb position when tracking started. */
814 static UINT trackThumbPos;
815 /* Position in the scroll-bar of the last button-down event. */
816 static INT lastClickPos;
817 /* Position in the scroll-bar of the last mouse event. */
818 static INT lastMousePos;
820 enum SCROLL_HITTEST hittest;
821 HWND hwndOwner, hwndCtl;
823 INT arrowSize, thumbSize, thumbPos;
827 SCROLLBAR_INFO *infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, FALSE );
828 if (!infoPtr) return;
829 if ((SCROLL_trackHitTest == SCROLL_NOWHERE) && (msg != WM_LBUTTONDOWN))
832 if (nBar == SB_CTL && (GetWindowLongW( hwnd, GWL_STYLE ) & (SBS_SIZEGRIP | SBS_SIZEBOX)))
836 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
837 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
840 SCROLL_trackHitTest = hittest = SCROLL_THUMB;
843 GetClientRect(GetParent(GetParent(hwnd)),&rect);
848 SCROLL_trackHitTest = hittest = SCROLL_NOWHERE;
849 if (hwnd==GetFocus()) ShowCaret(hwnd);
858 hdc = GetDCEx( hwnd, 0, DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW));
859 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
860 &arrowSize, &thumbSize, &thumbPos );
861 hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd) : hwnd;
862 hwndCtl = (nBar == SB_CTL) ? hwnd : 0;
866 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
867 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
868 SCROLL_trackVertical = vertical;
869 SCROLL_trackHitTest = hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
870 lastClickPos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
871 lastMousePos = lastClickPos;
872 trackThumbPos = thumbPos;
874 if (nBar == SB_CTL && (GetWindowLongW(hwnd, GWL_STYLE) & WS_TABSTOP)) SetFocus( hwnd );
879 hittest = SCROLL_HitTest( hwnd, nBar, pt, TRUE );
884 hittest = SCROLL_NOWHERE;
886 /* if scrollbar has focus, show back caret */
887 if (hwnd==GetFocus()) ShowCaret(hwnd);
892 hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
896 return; /* Should never happen */
899 TRACE("Event: hwnd=%p bar=%d msg=%s pt=%ld,%ld hit=%d\n",
900 hwnd, nBar, SPY_GetMsgName(msg,hwnd), pt.x, pt.y, hittest );
902 switch(SCROLL_trackHitTest)
904 case SCROLL_NOWHERE: /* No tracking in progress */
907 case SCROLL_TOP_ARROW:
908 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
909 (hittest == SCROLL_trackHitTest), FALSE );
910 if (hittest == SCROLL_trackHitTest)
912 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
914 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
915 SB_LINEUP, (LPARAM)hwndCtl );
918 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
919 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
922 else KillSystemTimer( hwnd, SCROLL_TIMER );
925 case SCROLL_TOP_RECT:
926 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
927 thumbPos, infoPtr->flags, vertical,
928 (hittest == SCROLL_trackHitTest), FALSE );
929 if (hittest == SCROLL_trackHitTest)
931 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
933 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
934 SB_PAGEUP, (LPARAM)hwndCtl );
936 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
937 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
940 else KillSystemTimer( hwnd, SCROLL_TIMER );
944 if (msg == WM_LBUTTONDOWN)
946 SCROLL_TrackingWin = hwnd;
947 SCROLL_TrackingBar = nBar;
948 SCROLL_TrackingPos = trackThumbPos + lastMousePos - lastClickPos;
949 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
951 SCROLL_TrackingPos );
952 if (!SCROLL_MovingThumb)
953 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
955 else if (msg == WM_LBUTTONUP)
957 if (SCROLL_MovingThumb)
958 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
959 SCROLL_TrackingWin = 0;
960 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
961 thumbPos, infoPtr->flags, vertical,
964 else /* WM_MOUSEMOVE */
968 if (!SCROLL_PtInRectEx( &rect, pt, vertical )) pos = lastClickPos;
971 pt = SCROLL_ClipPos( &rect, pt );
972 pos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
974 if ( (pos != lastMousePos) || (!SCROLL_MovingThumb) )
976 if (SCROLL_MovingThumb)
977 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
978 arrowSize, thumbSize );
980 SCROLL_TrackingPos = trackThumbPos + pos - lastClickPos;
981 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
983 SCROLL_TrackingPos );
984 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
985 MAKEWPARAM( SB_THUMBTRACK, SCROLL_TrackingVal),
987 if (!SCROLL_MovingThumb)
988 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
989 arrowSize, thumbSize );
994 case SCROLL_BOTTOM_RECT:
995 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
996 thumbPos, infoPtr->flags, vertical,
997 FALSE, (hittest == SCROLL_trackHitTest) );
998 if (hittest == SCROLL_trackHitTest)
1000 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1002 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1003 SB_PAGEDOWN, (LPARAM)hwndCtl );
1005 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1006 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1009 else KillSystemTimer( hwnd, SCROLL_TIMER );
1012 case SCROLL_BOTTOM_ARROW:
1013 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
1014 FALSE, (hittest == SCROLL_trackHitTest) );
1015 if (hittest == SCROLL_trackHitTest)
1017 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1019 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1020 SB_LINEDOWN, (LPARAM)hwndCtl );
1023 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1024 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1027 else KillSystemTimer( hwnd, SCROLL_TIMER );
1031 if (msg == WM_LBUTTONDOWN)
1034 if (hittest == SCROLL_THUMB)
1036 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1037 trackThumbPos + lastMousePos - lastClickPos );
1038 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1039 MAKEWPARAM( SB_THUMBTRACK, val ), (LPARAM)hwndCtl );
1043 if (msg == WM_LBUTTONUP)
1045 hittest = SCROLL_trackHitTest;
1046 SCROLL_trackHitTest = SCROLL_NOWHERE; /* Terminate tracking */
1048 if (hittest == SCROLL_THUMB)
1050 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1051 trackThumbPos + lastMousePos - lastClickPos );
1052 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1053 MAKEWPARAM( SB_THUMBPOSITION, val ), (LPARAM)hwndCtl );
1055 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1056 SB_ENDSCROLL, (LPARAM)hwndCtl );
1059 ReleaseDC( hwnd, hdc );
1063 /***********************************************************************
1064 * SCROLL_TrackScrollBar
1066 * Track a mouse button press on a scroll-bar.
1067 * pt is in screen-coordinates for non-client scroll bars.
1069 void SCROLL_TrackScrollBar( HWND hwnd, INT scrollbar, POINT pt )
1072 INT xoffset = 0, yoffset = 0;
1074 if (scrollbar != SB_CTL)
1076 WND *wndPtr = WIN_GetPtr( hwnd );
1077 if (!wndPtr || wndPtr == WND_OTHER_PROCESS) return;
1078 xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
1079 yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
1080 WIN_ReleasePtr( wndPtr );
1081 ScreenToClient( hwnd, &pt );
1086 SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt );
1090 if (!GetMessageW( &msg, 0, 0, 0 )) break;
1091 if (CallMsgFilterW( &msg, MSGF_SCROLLBAR )) continue;
1097 pt.x = (short)LOWORD(msg.lParam) + xoffset;
1098 pt.y = (short)HIWORD(msg.lParam) + yoffset;
1099 SCROLL_HandleScrollEvent( hwnd, scrollbar, msg.message, pt );
1102 TranslateMessage( &msg );
1103 DispatchMessageW( &msg );
1106 if (!IsWindow( hwnd ))
1111 } while (msg.message != WM_LBUTTONUP);
1115 /***********************************************************************
1116 * SCROLL_CreateScrollBar
1118 * Create a scroll bar
1121 * hwnd [I] Handle of window with scrollbar(s)
1122 * lpCreate [I] The style and place of the scroll bar
1124 static void SCROLL_CreateScrollBar(HWND hwnd, LPCREATESTRUCTW lpCreate)
1126 LPSCROLLBAR_INFO info = SCROLL_GetInternalInfo(hwnd, SB_CTL, TRUE);
1129 TRACE("hwnd=%p lpCreate=%p\n", hwnd, lpCreate);
1131 if (lpCreate->style & WS_DISABLED)
1133 info->flags = ESB_DISABLE_BOTH;
1134 TRACE("Created WS_DISABLED scrollbar\n");
1138 if (lpCreate->style & (SBS_SIZEGRIP | SBS_SIZEBOX))
1140 if (lpCreate->style & SBS_SIZEBOXTOPLEFTALIGN)
1141 MoveWindow( hwnd, lpCreate->x, lpCreate->y, GetSystemMetrics(SM_CXVSCROLL)+1,
1142 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1143 else if(lpCreate->style & SBS_SIZEBOXBOTTOMRIGHTALIGN)
1144 MoveWindow( hwnd, lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1145 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1146 GetSystemMetrics(SM_CXVSCROLL)+1,
1147 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1149 else if (lpCreate->style & SBS_VERT)
1151 if (lpCreate->style & SBS_LEFTALIGN)
1152 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1153 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1154 else if (lpCreate->style & SBS_RIGHTALIGN)
1156 lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1158 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1162 if (lpCreate->style & SBS_TOPALIGN)
1163 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1164 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1165 else if (lpCreate->style & SBS_BOTTOMALIGN)
1168 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1169 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1174 /*************************************************************************
1175 * SCROLL_GetScrollInfo
1177 * Internal helper for the API function
1180 * hwnd [I] Handle of window with scrollbar(s)
1181 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1182 * info [IO] fMask specifies which values to retrieve
1185 * FALSE if requested field not filled (f.i. scroll bar does not exist)
1187 static BOOL SCROLL_GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1189 LPSCROLLBAR_INFO infoPtr;
1191 /* handle invalid data structure */
1192 if (!SCROLL_ScrollInfoValid(info)
1193 || !(infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE)))
1196 /* fill in the desired scroll info structure */
1197 if (info->fMask & SIF_PAGE) info->nPage = infoPtr->page;
1198 if (info->fMask & SIF_POS) info->nPos = infoPtr->curVal;
1199 if ((info->fMask & SIF_TRACKPOS) && (info->cbSize == sizeof(*info)))
1200 info->nTrackPos = (SCROLL_TrackingWin == WIN_GetFullHandle(hwnd)) ? SCROLL_TrackingVal : infoPtr->curVal;
1201 if (info->fMask & SIF_RANGE)
1203 info->nMin = infoPtr->minVal;
1204 info->nMax = infoPtr->maxVal;
1207 return (info->fMask & SIF_ALL) != 0;
1211 /*************************************************************************
1212 * SCROLL_GetScrollPos
1214 * Internal helper for the API function
1217 * hwnd [I] Handle of window with scrollbar(s)
1218 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1220 static INT SCROLL_GetScrollPos(HWND hwnd, INT nBar)
1222 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1223 return infoPtr ? infoPtr->curVal: 0;
1227 /*************************************************************************
1228 * SCROLL_GetScrollRange
1230 * Internal helper for the API function
1233 * hwnd [I] Handle of window with scrollbar(s)
1234 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1235 * lpMin [O] Where to store minimum value
1236 * lpMax [O] Where to store maximum value
1240 static BOOL SCROLL_GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1242 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1246 if (lpMin) *lpMin = infoPtr ? infoPtr->minVal : 0;
1247 if (lpMax) *lpMax = infoPtr ? infoPtr->maxVal : 0;
1253 /*************************************************************************
1254 * SCROLL_SetScrollRange
1257 * hwnd [I] Handle of window with scrollbar(s)
1258 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1259 * lpMin [I] Minimum value
1260 * lpMax [I] Maximum value
1263 static BOOL SCROLL_SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal)
1265 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1267 TRACE("hwnd=%p nBar=%d min=%d max=%d\n", hwnd, nBar, minVal, maxVal);
1271 infoPtr->minVal = minVal;
1272 infoPtr->maxVal = maxVal;
1278 /***********************************************************************
1281 static LRESULT WINAPI ScrollBarWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1283 if (!IsWindow( hwnd )) return 0;
1288 SCROLL_CreateScrollBar(hwnd, (LPCREATESTRUCTW)lParam);
1293 SCROLLBAR_INFO *infoPtr;
1294 if ((infoPtr = SCROLL_GetInternalInfo( hwnd, SB_CTL, FALSE )))
1296 infoPtr->flags = wParam ? ESB_ENABLE_BOTH : ESB_DISABLE_BOTH;
1297 SCROLL_RefreshScrollBar(hwnd, SB_CTL, TRUE, TRUE);
1302 case WM_LBUTTONDBLCLK:
1303 case WM_LBUTTONDOWN:
1306 pt.x = (short)LOWORD(lParam);
1307 pt.y = (short)HIWORD(lParam);
1308 SCROLL_TrackScrollBar( hwnd, SB_CTL, pt );
1316 pt.x = (short)LOWORD(lParam);
1317 pt.y = (short)HIWORD(lParam);
1318 SCROLL_HandleScrollEvent( hwnd, SB_CTL, message, pt );
1323 SCROLL_HandleKbdEvent(hwnd, wParam, lParam);
1332 /* Create a caret when a ScrollBar get focus */
1334 int arrowSize, thumbSize, thumbPos, vertical;
1335 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,
1336 &arrowSize, &thumbSize, &thumbPos );
1339 CreateCaret(hwnd, (HBITMAP)1, thumbSize-2, rect.bottom-rect.top-2);
1340 SetCaretPos(thumbPos+1, rect.top+1);
1344 CreateCaret(hwnd, (HBITMAP)1, rect.right-rect.left-2,thumbSize-2);
1345 SetCaretPos(rect.top+1, thumbPos+1);
1354 int arrowSize, thumbSize, thumbPos, vertical;
1355 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,&arrowSize, &thumbSize, &thumbPos );
1357 rect.left=thumbPos+1;
1358 rect.right=rect.left+thumbSize;
1362 rect.top=thumbPos+1;
1363 rect.bottom=rect.top+thumbSize;
1366 InvalidateRect(hwnd,&rect,0);
1375 return DLGC_WANTARROWS; /* Windows returns this value */
1380 HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
1381 if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEGRIP)
1383 SCROLL_DrawSizeGrip( hwnd, hdc);
1385 else if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEBOX)
1388 GetClientRect( hwnd, &rc );
1389 FillRect( hdc, &rc, GetSysColorBrush(COLOR_SCROLLBAR) );
1392 SCROLL_DrawScrollBar( hwnd, hdc, SB_CTL, TRUE, TRUE );
1393 if (!wParam) EndPaint(hwnd, &ps);
1399 return SetScrollPos( hwnd, SB_CTL, wParam, (BOOL)lParam );
1403 return SCROLL_GetScrollPos(hwnd, SB_CTL);
1405 case SBM_SETRANGE16:
1406 if (wParam) message = SBM_SETRANGEREDRAW;
1407 wParam = LOWORD(lParam);
1408 lParam = HIWORD(lParam);
1410 case SBM_SETRANGEREDRAW:
1413 INT oldPos = SCROLL_GetScrollPos( hwnd, SB_CTL );
1414 SCROLL_SetScrollRange( hwnd, SB_CTL, wParam, lParam );
1415 if (message == SBM_SETRANGEREDRAW)
1416 SCROLL_RefreshScrollBar( hwnd, SB_CTL, TRUE, TRUE );
1417 if (oldPos != SCROLL_GetScrollPos( hwnd, SB_CTL )) return oldPos;
1421 case SBM_GETRANGE16:
1425 SCROLL_GetScrollRange(hwnd, SB_CTL, &min, &max);
1426 return MAKELRESULT(min, max);
1430 return SCROLL_GetScrollRange(hwnd, SB_CTL, (LPINT)wParam, (LPINT)lParam);
1432 case SBM_ENABLE_ARROWS16:
1433 case SBM_ENABLE_ARROWS:
1434 return EnableScrollBar( hwnd, SB_CTL, wParam );
1436 case SBM_SETSCROLLINFO:
1437 return SCROLL_SetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam, wParam );
1439 case SBM_GETSCROLLINFO:
1440 return SCROLL_GetScrollInfo(hwnd, SB_CTL, (SCROLLINFO *)lParam);
1450 ERR("unknown Win32 msg %04x wp=%08x lp=%08lx\n",
1451 message, wParam, lParam );
1455 if (message >= WM_USER)
1456 WARN("unknown msg %04x wp=%04x lp=%08lx\n",
1457 message, wParam, lParam );
1458 return DefWindowProcW( hwnd, message, wParam, lParam );
1464 /*************************************************************************
1465 * SetScrollInfo (USER32.@)
1467 * SetScrollInfo can be used to set the position, upper bound,
1468 * lower bound, and page size of a scrollbar control.
1471 * hwnd [I] Handle of window with scrollbar(s)
1472 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1473 * info [I] Specifies what to change and new values
1474 * bRedraw [I] Should scrollbar be redrawn afterwards?
1477 * Scrollbar position
1480 * For 100 lines of text to be displayed in a window of 25 lines,
1481 * one would for instance use info->nMin=0, info->nMax=75
1482 * (corresponding to the 76 different positions of the window on
1483 * the text), and info->nPage=25.
1485 INT WINAPI SetScrollInfo(HWND hwnd, INT nBar, const SCROLLINFO *info, BOOL bRedraw)
1487 TRACE("hwnd=%p nBar=%d info=%p, bRedraw=%d\n", hwnd, nBar, info, bRedraw);
1489 /* Refer SB_CTL requests to the window */
1491 return SendMessageW(hwnd, SBM_SETSCROLLINFO, bRedraw, (LPARAM)info);
1493 return SCROLL_SetScrollInfo( hwnd, nBar, info, bRedraw );
1496 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar, LPCSCROLLINFO info, BOOL bRedraw )
1498 /* Update the scrollbar state and set action flags according to
1499 * what has to be done graphics wise. */
1501 SCROLLBAR_INFO *infoPtr;
1505 /* handle invalid data structure */
1506 if (!SCROLL_ScrollInfoValid(info)
1507 || !(infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, TRUE)))
1510 if (TRACE_ON(scroll))
1512 TRACE("hwnd=%p bar=%d", hwnd, nBar);
1513 if (info->fMask & SIF_PAGE) TRACE( " page=%d", info->nPage );
1514 if (info->fMask & SIF_POS) TRACE( " pos=%d", info->nPos );
1515 if (info->fMask & SIF_RANGE) TRACE( " min=%d max=%d", info->nMin, info->nMax );
1519 /* Set the page size */
1521 if (info->fMask & SIF_PAGE)
1523 if( infoPtr->page != info->nPage && info->nPage >= 0)
1525 infoPtr->page = info->nPage;
1526 action |= SA_SSI_REFRESH;
1530 /* Set the scroll pos */
1532 if (info->fMask & SIF_POS)
1534 if( infoPtr->curVal != info->nPos )
1536 infoPtr->curVal = info->nPos;
1537 action |= SA_SSI_REFRESH;
1541 /* Set the scroll range */
1543 if (info->fMask & SIF_RANGE)
1545 /* Invalid range -> range is set to (0,0) */
1546 if ((info->nMin > info->nMax) ||
1547 ((UINT)(info->nMax - info->nMin) >= 0x80000000))
1549 action |= SA_SSI_REFRESH;
1550 infoPtr->minVal = 0;
1551 infoPtr->maxVal = 0;
1555 if( infoPtr->minVal != info->nMin ||
1556 infoPtr->maxVal != info->nMax )
1558 action |= SA_SSI_REFRESH;
1559 infoPtr->minVal = info->nMin;
1560 infoPtr->maxVal = info->nMax;
1565 /* Make sure the page size is valid */
1566 if (infoPtr->page < 0) infoPtr->page = 0;
1567 else if (infoPtr->page > infoPtr->maxVal - infoPtr->minVal + 1 )
1568 infoPtr->page = infoPtr->maxVal - infoPtr->minVal + 1;
1570 /* Make sure the pos is inside the range */
1572 if (infoPtr->curVal < infoPtr->minVal)
1573 infoPtr->curVal = infoPtr->minVal;
1574 else if (infoPtr->curVal > infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1575 infoPtr->curVal = infoPtr->maxVal - max( infoPtr->page-1, 0 );
1577 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1578 infoPtr->page, infoPtr->curVal,
1579 infoPtr->minVal, infoPtr->maxVal );
1581 /* don't change the scrollbar state if SetScrollInfo
1582 * is just called with SIF_DISABLENOSCROLL
1584 if(!(info->fMask & SIF_ALL)) goto done;
1586 /* Check if the scrollbar should be hidden or disabled */
1588 if (info->fMask & (SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL))
1590 new_flags = infoPtr->flags;
1591 if (infoPtr->minVal >= infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1593 /* Hide or disable scroll-bar */
1594 if (info->fMask & SIF_DISABLENOSCROLL)
1596 new_flags = ESB_DISABLE_BOTH;
1597 action |= SA_SSI_REFRESH;
1599 else if ((nBar != SB_CTL) && (action & SA_SSI_REFRESH))
1601 action = SA_SSI_HIDE;
1604 else /* Show and enable scroll-bar only if no page only changed. */
1605 if (info->fMask != SIF_PAGE)
1607 new_flags = ESB_ENABLE_BOTH;
1608 if ((nBar != SB_CTL) && ( (action & SA_SSI_REFRESH) ))
1609 action |= SA_SSI_SHOW;
1612 if (infoPtr->flags != new_flags) /* check arrow flags */
1614 infoPtr->flags = new_flags;
1615 action |= SA_SSI_REPAINT_ARROWS;
1620 if( action & SA_SSI_HIDE )
1621 SCROLL_ShowScrollBar( hwnd, nBar, FALSE, FALSE );
1624 if( action & SA_SSI_SHOW )
1625 if( SCROLL_ShowScrollBar( hwnd, nBar, TRUE, TRUE ) )
1626 return infoPtr->curVal; /* SetWindowPos() already did the painting */
1629 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
1630 else if( action & SA_SSI_REPAINT_ARROWS )
1631 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, FALSE );
1634 /* Return current position */
1635 return infoPtr->curVal;
1639 /*************************************************************************
1640 * GetScrollInfo (USER32.@)
1642 * GetScrollInfo can be used to retrieve the position, upper bound,
1643 * lower bound, and page size of a scrollbar control.
1646 * hwnd [I] Handle of window with scrollbar(s)
1647 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1648 * info [IO] fMask specifies which values to retrieve
1651 * TRUE if SCROLLINFO is filled
1653 BOOL WINAPI GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1655 TRACE("hwnd=%p nBar=%d info=%p\n", hwnd, nBar, info);
1657 /* Refer SB_CTL requests to the window */
1659 SendMessageW(hwnd, SBM_GETSCROLLINFO, (WPARAM)0, (LPARAM)info);
1661 SCROLL_GetScrollInfo(hwnd, nBar, info);
1667 /*************************************************************************
1668 * SetScrollPos (USER32.@)
1670 * Sets the current position of the scroll thumb.
1673 * hwnd [I] Handle of window with scrollbar(s)
1674 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1675 * nPos [I] New value
1676 * bRedraw [I] Should scrollbar be redrawn afterwards?
1679 * Success: Scrollbar position
1683 * Note the ambiguity when 0 is returned. Use GetLastError
1684 * to make sure there was an error (and to know which one).
1686 INT WINAPI SetScrollPos( HWND hwnd, INT nBar, INT nPos, BOOL bRedraw)
1689 SCROLLBAR_INFO *infoPtr;
1692 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, FALSE ))) return 0;
1693 oldPos = infoPtr->curVal;
1694 info.cbSize = sizeof(info);
1696 info.fMask = SIF_POS;
1697 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1702 /*************************************************************************
1703 * GetScrollPos (USER32.@)
1705 * Gets the current position of the scroll thumb.
1708 * hwnd [I] Handle of window with scrollbar(s)
1709 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1712 * Success: Current position
1716 * There is ambiguity when 0 is returned. Use GetLastError
1717 * to make sure there was an error (and to know which one).
1719 INT WINAPI GetScrollPos(HWND hwnd, INT nBar)
1721 TRACE("hwnd=%p nBar=%d\n", hwnd, nBar);
1723 /* Refer SB_CTL requests to the window */
1725 return SendMessageW(hwnd, SBM_GETPOS, (WPARAM)0, (LPARAM)0);
1727 return SCROLL_GetScrollPos(hwnd, nBar);
1731 /*************************************************************************
1732 * SetScrollRange (USER32.@)
1733 * The SetScrollRange function sets the minimum and maximum scroll box positions
1734 * If nMinPos and nMaxPos is the same value, the scroll bar will hide
1736 * Sets the range of the scroll bar.
1739 * hwnd [I] Handle of window with scrollbar(s)
1740 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1741 * minVal [I] New minimum value
1742 * maxVal [I] New Maximum value
1743 * bRedraw [I] Should scrollbar be redrawn afterwards?
1747 BOOL WINAPI SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal, BOOL bRedraw)
1751 TRACE("hwnd=%p nBar=%d min=%d max=%d, bRedraw=%d\n", hwnd, nBar, minVal, maxVal, bRedraw);
1753 info.cbSize = sizeof(info);
1754 info.fMask = SIF_RANGE;
1757 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1762 /*************************************************************************
1763 * SCROLL_SetNCSbState
1765 * Updates both scrollbars at the same time. Used by MDI CalcChildScroll().
1767 INT SCROLL_SetNCSbState(HWND hwnd, int vMin, int vMax, int vPos,
1768 int hMin, int hMax, int hPos)
1770 SCROLLINFO vInfo, hInfo;
1772 vInfo.cbSize = hInfo.cbSize = sizeof(SCROLLINFO);
1779 vInfo.fMask = hInfo.fMask = SIF_RANGE | SIF_POS;
1781 SCROLL_SetScrollInfo( hwnd, SB_VERT, &vInfo, TRUE );
1782 SCROLL_SetScrollInfo( hwnd, SB_HORZ, &hInfo, TRUE );
1788 /*************************************************************************
1789 * GetScrollRange (USER32.@)
1791 * Gets the range of the scroll bar.
1794 * hwnd [I] Handle of window with scrollbar(s)
1795 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1796 * lpMin [O] Where to store minimum value
1797 * lpMax [O] Where to store maximum value
1800 * TRUE if values is filled
1802 BOOL WINAPI GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1804 TRACE("hwnd=%p nBar=%d lpMin=%p lpMax=%p\n", hwnd, nBar, lpMin, lpMax);
1806 /* Refer SB_CTL requests to the window */
1808 SendMessageW(hwnd, SBM_GETRANGE, (WPARAM)lpMin, (LPARAM)lpMax);
1810 SCROLL_GetScrollRange(hwnd, nBar, lpMin, lpMax);
1816 /*************************************************************************
1817 * SCROLL_ShowScrollBar()
1819 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1821 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar, BOOL fShowH, BOOL fShowV )
1823 ULONG old_style, set_bits = 0, clear_bits = 0;
1825 TRACE("hwnd=%p bar=%d horz=%d, vert=%d\n", hwnd, nBar, fShowH, fShowV );
1830 ShowWindow( hwnd, fShowH ? SW_SHOW : SW_HIDE );
1835 if (fShowH) set_bits |= WS_HSCROLL;
1836 else clear_bits |= WS_HSCROLL;
1837 if( nBar == SB_HORZ ) break;
1840 if (fShowV) set_bits |= WS_VSCROLL;
1841 else clear_bits |= WS_VSCROLL;
1845 return FALSE; /* Nothing to do! */
1848 old_style = WIN_SetStyle( hwnd, set_bits, clear_bits );
1849 if ((old_style & clear_bits) != 0 || (old_style & set_bits) != set_bits)
1851 /* frame has been changed, let the window redraw itself */
1852 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
1853 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
1856 return FALSE; /* no frame changes */
1860 /*************************************************************************
1861 * ShowScrollBar (USER32.@)
1863 * Shows or hides the scroll bar.
1866 * hwnd [I] Handle of window with scrollbar(s)
1867 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1868 * fShow [I] TRUE = show, FALSE = hide
1872 BOOL WINAPI ShowScrollBar(HWND hwnd, INT nBar, BOOL fShow)
1874 SCROLL_ShowScrollBar( hwnd, nBar, (nBar == SB_VERT) ? 0 : fShow,
1875 (nBar == SB_HORZ) ? 0 : fShow );
1880 /*************************************************************************
1881 * EnableScrollBar (USER32.@)
1883 * Enables or disables the scroll bars.
1885 BOOL WINAPI EnableScrollBar( HWND hwnd, INT nBar, UINT flags )
1888 SCROLLBAR_INFO *infoPtr;
1890 TRACE("%p %d %d\n", hwnd, nBar, flags );
1892 flags &= ESB_DISABLE_BOTH;
1894 if (nBar == SB_BOTH)
1896 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, SB_VERT, TRUE ))) return FALSE;
1897 if (!(bFineWithMe = (infoPtr->flags == flags)) )
1899 infoPtr->flags = flags;
1900 SCROLL_RefreshScrollBar( hwnd, SB_VERT, TRUE, TRUE );
1907 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, TRUE ))) return FALSE;
1908 if (bFineWithMe && infoPtr->flags == flags) return FALSE;
1909 infoPtr->flags = flags;
1911 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );