4 * Copyright 1993 Martin Ayotte
5 * Copyright 1994, 1996 Alexandre Julliard
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * This code was audited for completeness against the documented features
24 * of Comctl32.dll version 6.0 on Oct. 8, 2004, by Dimitrie O. Paun.
26 * Unless otherwise noted, we believe this code to be complete, as per
27 * the specification mentioned above.
28 * If you discover missing features, or bugs, please note them below.
32 * - SBM_GETSCROLLBARINFO
41 #include "wine/winuser16.h"
44 #include "wine/debug.h"
45 #include "user_private.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(scroll);
52 INT curVal; /* Current scroll-bar value */
53 INT minVal; /* Minimum scroll-bar value */
54 INT maxVal; /* Maximum scroll-bar value */
55 INT page; /* Page size of scroll bar (Win32) */
56 UINT flags; /* EnableScrollBar flags */
57 } SCROLLBAR_INFO, *LPSCROLLBAR_INFO;
60 /* Minimum size of the rectangle between the arrows */
61 #define SCROLL_MIN_RECT 4
63 /* Minimum size of the thumb in pixels */
64 #define SCROLL_MIN_THUMB 6
66 /* Overlap between arrows and thumb */
67 #define SCROLL_ARROW_THUMB_OVERLAP 0
69 /* Delay (in ms) before first repetition when holding the button down */
70 #define SCROLL_FIRST_DELAY 200
72 /* Delay (in ms) between scroll repetitions */
73 #define SCROLL_REPEAT_DELAY 50
76 #define SCROLL_TIMER 0
78 /* Scroll-bar hit testing */
81 SCROLL_NOWHERE, /* Outside the scroll bar */
82 SCROLL_TOP_ARROW, /* Top or left arrow */
83 SCROLL_TOP_RECT, /* Rectangle between the top arrow and the thumb */
84 SCROLL_THUMB, /* Thumb rectangle */
85 SCROLL_BOTTOM_RECT, /* Rectangle between the thumb and the bottom arrow */
86 SCROLL_BOTTOM_ARROW /* Bottom or right arrow */
89 /* What to do after SCROLL_SetScrollInfo() */
90 #define SA_SSI_HIDE 0x0001
91 #define SA_SSI_SHOW 0x0002
92 #define SA_SSI_REFRESH 0x0004
93 #define SA_SSI_REPAINT_ARROWS 0x0008
95 /* Thumb-tracking info */
96 static HWND SCROLL_TrackingWin = 0;
97 static INT SCROLL_TrackingBar = 0;
98 static INT SCROLL_TrackingPos = 0;
99 static INT SCROLL_TrackingVal = 0;
100 /* Hit test code of the last button-down event */
101 static enum SCROLL_HITTEST SCROLL_trackHitTest;
102 static BOOL SCROLL_trackVertical;
104 /* Is the moving thumb being displayed? */
105 static BOOL SCROLL_MovingThumb = FALSE;
107 /* Local functions */
108 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar,
109 BOOL fShowH, BOOL fShowV );
110 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar,
111 const SCROLLINFO *info, BOOL bRedraw );
112 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
113 RECT *rect, INT arrowSize,
114 INT thumbSize, INT thumbPos,
115 UINT flags, BOOL vertical,
116 BOOL top_selected, BOOL bottom_selected );
117 static LRESULT WINAPI ScrollBarWndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
120 /*********************************************************************
121 * scrollbar class descriptor
123 const struct builtin_class_descr SCROLL_builtin_class =
125 "ScrollBar", /* name */
126 CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC, /* style */
127 NULL, /* procA (winproc is Unicode only) */
128 ScrollBarWndProc, /* procW */
129 sizeof(SCROLLBAR_INFO), /* extra */
130 IDC_ARROW, /* cursor */
134 /***********************************************************************
135 * SCROLL_ScrollInfoValid
137 * Determine if the supplied SCROLLINFO struct is valid.
139 inline static BOOL SCROLL_ScrollInfoValid(
140 LPSCROLLINFO info /* [in] The SCROLLINFO struct to be tested */)
142 return !(info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)
143 || (info->cbSize != sizeof(*info)
144 && info->cbSize != sizeof(*info) - sizeof(info->nTrackPos)));
148 /***********************************************************************
149 * SCROLL_GetScrollBarInfo
151 static SCROLLBAR_INFO *SCROLL_GetScrollBarInfo( HWND hwnd, INT nBar )
153 SCROLLBAR_INFO *infoPtr;
154 WND *wndPtr = WIN_GetPtr( hwnd );
156 if (!wndPtr || wndPtr == WND_OTHER_PROCESS) return NULL;
159 case SB_HORZ: infoPtr = (SCROLLBAR_INFO *)wndPtr->pHScroll; break;
160 case SB_VERT: infoPtr = (SCROLLBAR_INFO *)wndPtr->pVScroll; break;
161 case SB_CTL: infoPtr = (SCROLLBAR_INFO *)wndPtr->wExtra; break;
163 WIN_ReleaseWndPtr( wndPtr );
167 if (!infoPtr) /* Create the info structure if needed */
169 if ((infoPtr = HeapAlloc( GetProcessHeap(), 0, sizeof(SCROLLBAR_INFO) )))
171 infoPtr->minVal = infoPtr->curVal = infoPtr->page = 0;
172 infoPtr->maxVal = 100;
173 infoPtr->flags = ESB_ENABLE_BOTH;
174 if (nBar == SB_HORZ) wndPtr->pHScroll = infoPtr;
175 else wndPtr->pVScroll = infoPtr;
178 WIN_ReleasePtr( wndPtr );
183 /***********************************************************************
184 * SCROLL_GetScrollBarRect
186 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
187 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
188 * 'arrowSize' returns the width or height of an arrow (depending on
189 * the orientation of the scrollbar), 'thumbSize' returns the size of
190 * the thumb, and 'thumbPos' returns the position of the thumb
191 * relative to the left or to the top.
192 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
194 static BOOL SCROLL_GetScrollBarRect( HWND hwnd, INT nBar, RECT *lprect,
195 INT *arrowSize, INT *thumbSize,
200 WND *wndPtr = WIN_GetPtr( hwnd );
202 if (!wndPtr || wndPtr == WND_OTHER_PROCESS) return FALSE;
207 lprect->left = wndPtr->rectClient.left - wndPtr->rectWindow.left;
208 lprect->top = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
209 lprect->right = wndPtr->rectClient.right - wndPtr->rectWindow.left;
210 lprect->bottom = lprect->top + GetSystemMetrics(SM_CYHSCROLL);
211 if(wndPtr->dwStyle & WS_BORDER) {
214 } else if(wndPtr->dwStyle & WS_VSCROLL)
220 if((wndPtr->dwExStyle & WS_EX_LEFTSCROLLBAR) != 0)
221 lprect->left = wndPtr->rectClient.left - wndPtr->rectWindow.left - GetSystemMetrics(SM_CXVSCROLL);
223 lprect->left = wndPtr->rectClient.right - wndPtr->rectWindow.left;
224 lprect->top = wndPtr->rectClient.top - wndPtr->rectWindow.top;
225 lprect->right = lprect->left + GetSystemMetrics(SM_CXVSCROLL);
226 lprect->bottom = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
227 if(wndPtr->dwStyle & WS_BORDER) {
230 } else if(wndPtr->dwStyle & WS_HSCROLL)
236 GetClientRect( hwnd, lprect );
237 vertical = ((wndPtr->dwStyle & SBS_VERT) != 0);
241 WIN_ReleasePtr( wndPtr );
245 if (vertical) pixels = lprect->bottom - lprect->top;
246 else pixels = lprect->right - lprect->left;
248 if (pixels <= 2*GetSystemMetrics(SM_CXVSCROLL) + SCROLL_MIN_RECT)
250 if (pixels > SCROLL_MIN_RECT)
251 *arrowSize = (pixels - SCROLL_MIN_RECT) / 2;
254 *thumbPos = *thumbSize = 0;
258 SCROLLBAR_INFO *info = SCROLL_GetScrollBarInfo( hwnd, nBar );
260 *arrowSize = GetSystemMetrics(SM_CXVSCROLL);
261 pixels -= (2 * (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP));
265 *thumbSize = MulDiv(pixels,info->page,(info->maxVal-info->minVal+1));
266 if (*thumbSize < SCROLL_MIN_THUMB) *thumbSize = SCROLL_MIN_THUMB;
268 else *thumbSize = GetSystemMetrics(SM_CXVSCROLL);
270 if (((pixels -= *thumbSize ) < 0) ||
271 ((info->flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH))
273 /* Rectangle too small or scrollbar disabled -> no thumb */
274 *thumbPos = *thumbSize = 0;
278 INT max = info->maxVal - max( info->page-1, 0 );
279 if (info->minVal >= max)
280 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
282 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP
283 + MulDiv(pixels, (info->curVal-info->minVal),(max - info->minVal));
286 WIN_ReleasePtr( wndPtr );
291 /***********************************************************************
294 * Compute the current scroll position based on the thumb position in pixels
295 * from the top of the scroll-bar.
297 static UINT SCROLL_GetThumbVal( SCROLLBAR_INFO *infoPtr, RECT *rect,
298 BOOL vertical, INT pos )
301 INT pixels = vertical ? rect->bottom-rect->top : rect->right-rect->left;
303 if ((pixels -= 2*(GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP)) <= 0)
304 return infoPtr->minVal;
308 thumbSize = MulDiv(pixels,infoPtr->page,(infoPtr->maxVal-infoPtr->minVal+1));
309 if (thumbSize < SCROLL_MIN_THUMB) thumbSize = SCROLL_MIN_THUMB;
311 else thumbSize = GetSystemMetrics(SM_CXVSCROLL);
313 if ((pixels -= thumbSize) <= 0) return infoPtr->minVal;
315 pos = max( 0, pos - (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP) );
316 if (pos > pixels) pos = pixels;
318 if (!infoPtr->page) pos *= infoPtr->maxVal - infoPtr->minVal;
319 else pos *= infoPtr->maxVal - infoPtr->minVal - infoPtr->page + 1;
320 return infoPtr->minVal + ((pos + pixels / 2) / pixels);
323 /***********************************************************************
326 static BOOL SCROLL_PtInRectEx( LPRECT lpRect, POINT pt, BOOL vertical )
332 rect.left -= lpRect->right - lpRect->left;
333 rect.right += lpRect->right - lpRect->left;
337 rect.top -= lpRect->bottom - lpRect->top;
338 rect.bottom += lpRect->bottom - lpRect->top;
340 return PtInRect( &rect, pt );
343 /***********************************************************************
346 static POINT SCROLL_ClipPos( LPRECT lpRect, POINT pt )
348 if( pt.x < lpRect->left )
351 if( pt.x > lpRect->right )
352 pt.x = lpRect->right;
354 if( pt.y < lpRect->top )
357 if( pt.y > lpRect->bottom )
358 pt.y = lpRect->bottom;
364 /***********************************************************************
367 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
369 static enum SCROLL_HITTEST SCROLL_HitTest( HWND hwnd, INT nBar,
370 POINT pt, BOOL bDragging )
372 INT arrowSize, thumbSize, thumbPos;
375 BOOL vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
376 &arrowSize, &thumbSize, &thumbPos );
378 if ( (bDragging && !SCROLL_PtInRectEx( &rect, pt, vertical )) ||
379 (!PtInRect( &rect, pt )) ) return SCROLL_NOWHERE;
383 if (pt.y < rect.top + arrowSize) return SCROLL_TOP_ARROW;
384 if (pt.y >= rect.bottom - arrowSize) return SCROLL_BOTTOM_ARROW;
385 if (!thumbPos) return SCROLL_TOP_RECT;
387 if (pt.y < thumbPos) return SCROLL_TOP_RECT;
388 if (pt.y >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
390 else /* horizontal */
392 if (pt.x < rect.left + arrowSize) return SCROLL_TOP_ARROW;
393 if (pt.x >= rect.right - arrowSize) return SCROLL_BOTTOM_ARROW;
394 if (!thumbPos) return SCROLL_TOP_RECT;
396 if (pt.x < thumbPos) return SCROLL_TOP_RECT;
397 if (pt.x >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
403 /***********************************************************************
406 * Draw the scroll bar arrows.
408 static void SCROLL_DrawArrows( HDC hdc, SCROLLBAR_INFO *infoPtr,
409 RECT *rect, INT arrowSize, BOOL vertical,
410 BOOL top_pressed, BOOL bottom_pressed )
416 r.bottom = r.top + arrowSize;
418 r.right = r.left + arrowSize;
420 DrawFrameControl( hdc, &r, DFC_SCROLL,
421 (vertical ? DFCS_SCROLLUP : DFCS_SCROLLLEFT)
422 | (top_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
423 | (infoPtr->flags&ESB_DISABLE_LTUP ? DFCS_INACTIVE : 0 ) );
427 r.top = r.bottom-arrowSize;
429 r.left = r.right-arrowSize;
431 DrawFrameControl( hdc, &r, DFC_SCROLL,
432 (vertical ? DFCS_SCROLLDOWN : DFCS_SCROLLRIGHT)
433 | (bottom_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
434 | (infoPtr->flags&ESB_DISABLE_RTDN ? DFCS_INACTIVE : 0) );
437 static void SCROLL_DrawMovingThumb( HDC hdc, RECT *rect, BOOL vertical,
438 INT arrowSize, INT thumbSize )
440 INT pos = SCROLL_TrackingPos;
444 max_size = rect->bottom - rect->top;
446 max_size = rect->right - rect->left;
448 max_size -= (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) + thumbSize;
450 if( pos < (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) )
451 pos = (arrowSize-SCROLL_ARROW_THUMB_OVERLAP);
452 else if( pos > max_size )
455 SCROLL_DrawInterior_9x( SCROLL_TrackingWin, hdc, SCROLL_TrackingBar,
456 rect, arrowSize, thumbSize, pos,
457 0, vertical, FALSE, FALSE );
459 SCROLL_MovingThumb = !SCROLL_MovingThumb;
462 /***********************************************************************
463 * SCROLL_DrawInterior
465 * Draw the scroll bar interior (everything except the arrows).
467 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
468 RECT *rect, INT arrowSize,
469 INT thumbSize, INT thumbPos,
470 UINT flags, BOOL vertical,
471 BOOL top_selected, BOOL bottom_selected )
475 HBRUSH hSaveBrush,hBrush;
477 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
478 * The window-owned scrollbars need to call DEFWND_ControlColor
479 * to correctly setup default scrollbar colors
483 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
484 (WPARAM)hdc,(LPARAM)hwnd);
488 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
491 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
492 hSaveBrush = SelectObject( hdc, hBrush );
494 /* Calculate the scroll rectangle */
498 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
499 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
503 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
504 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
507 /* Draw the scroll rectangles and thumb */
508 if (!thumbPos) /* No thumb to draw */
510 PatBlt( hdc, r.left, r.top,
511 r.right - r.left, r.bottom - r.top,
514 /* cleanup and return */
515 SelectObject( hdc, hSavePen );
516 SelectObject( hdc, hSaveBrush );
522 PatBlt( hdc, r.left, r.top,
524 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
525 top_selected ? 0x0f0000 : PATCOPY );
526 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
527 PatBlt( hdc, r.left, r.top + thumbSize,
529 r.bottom - r.top - thumbSize,
530 bottom_selected ? 0x0f0000 : PATCOPY );
531 r.bottom = r.top + thumbSize;
533 else /* horizontal */
535 PatBlt( hdc, r.left, r.top,
536 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
538 top_selected ? 0x0f0000 : PATCOPY );
539 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
540 PatBlt( hdc, r.left + thumbSize, r.top,
541 r.right - r.left - thumbSize,
543 bottom_selected ? 0x0f0000 : PATCOPY );
544 r.right = r.left + thumbSize;
548 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT | BF_MIDDLE );
551 SelectObject( hdc, hSavePen );
552 SelectObject( hdc, hSaveBrush );
556 static void SCROLL_DrawInterior( HWND hwnd, HDC hdc, INT nBar,
557 RECT *rect, INT arrowSize,
558 INT thumbSize, INT thumbPos,
559 UINT flags, BOOL vertical,
560 BOOL top_selected, BOOL bottom_selected )
564 HBRUSH hSaveBrush,hBrush;
565 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
567 if (Save_SCROLL_MovingThumb &&
568 (SCROLL_TrackingWin == hwnd) &&
569 (SCROLL_TrackingBar == nBar))
570 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
572 /* Select the correct brush and pen */
574 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
575 * The window-owned scrollbars need to call DEFWND_ControlColor
576 * to correctly setup default scrollbar colors
578 if (nBar == SB_CTL) {
579 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
580 (WPARAM)hdc,(LPARAM)hwnd);
582 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
584 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
585 hSaveBrush = SelectObject( hdc, hBrush );
587 /* Calculate the scroll rectangle */
592 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
593 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
597 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
598 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
601 /* Draw the scroll bar frame */
603 /* Draw the scroll rectangles and thumb */
605 if (!thumbPos) /* No thumb to draw */
607 PatBlt( hdc, r.left, r.top, r.right - r.left, r.bottom - r.top, PATCOPY );
609 /* cleanup and return */
610 SelectObject( hdc, hSavePen );
611 SelectObject( hdc, hSaveBrush );
617 PatBlt( hdc, r.left, r.top, r.right - r.left,
618 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
619 top_selected ? 0x0f0000 : PATCOPY );
620 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
621 PatBlt( hdc, r.left, r.top + thumbSize, r.right - r.left,
622 r.bottom - r.top - thumbSize,
623 bottom_selected ? 0x0f0000 : PATCOPY );
624 r.bottom = r.top + thumbSize;
626 else /* horizontal */
628 PatBlt( hdc, r.left, r.top,
629 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
630 r.bottom - r.top, top_selected ? 0x0f0000 : PATCOPY );
631 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
632 PatBlt( hdc, r.left + thumbSize, r.top, r.right - r.left - thumbSize,
633 r.bottom - r.top, bottom_selected ? 0x0f0000 : PATCOPY );
634 r.right = r.left + thumbSize;
639 SelectObject( hdc, GetSysColorBrush(COLOR_BTNFACE) );
640 Rectangle( hdc, r.left+1, r.top+1, r.right-1, r.bottom-1 );
641 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT );
643 if (Save_SCROLL_MovingThumb &&
644 (SCROLL_TrackingWin == hwnd) &&
645 (SCROLL_TrackingBar == nBar))
646 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
649 SelectObject( hdc, hSavePen );
650 SelectObject( hdc, hSaveBrush );
654 /***********************************************************************
655 * SCROLL_DrawScrollBar
657 * Redraw the whole scrollbar.
659 void SCROLL_DrawScrollBar( HWND hwnd, HDC hdc, INT nBar,
660 BOOL arrows, BOOL interior )
662 INT arrowSize, thumbSize, thumbPos;
665 SCROLLBAR_INFO *infoPtr = SCROLL_GetScrollBarInfo( hwnd, nBar );
666 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
667 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
669 if (!(hwnd = WIN_GetFullHandle( hwnd ))) return;
672 ((nBar == SB_VERT) && !(style & WS_VSCROLL)) ||
673 ((nBar == SB_HORZ) && !(style & WS_HSCROLL))) return;
674 if (!WIN_IsWindowDrawable( hwnd, FALSE )) return;
676 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
677 &arrowSize, &thumbSize, &thumbPos );
679 /* do not draw if the scrollbar rectangle is empty */
680 if(IsRectEmpty(&rect)) return;
682 if (Save_SCROLL_MovingThumb &&
683 (SCROLL_TrackingWin == hwnd) &&
684 (SCROLL_TrackingBar == nBar))
685 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
687 /* Draw the arrows */
689 if (arrows && arrowSize)
691 if( vertical == SCROLL_trackVertical && GetCapture() == hwnd )
692 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
693 (SCROLL_trackHitTest == SCROLL_TOP_ARROW),
694 (SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW) );
696 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
700 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
701 thumbPos, infoPtr->flags, vertical, FALSE, FALSE );
703 if (Save_SCROLL_MovingThumb &&
704 (SCROLL_TrackingWin == hwnd) &&
705 (SCROLL_TrackingBar == nBar))
706 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
708 /* if scroll bar has focus, reposition the caret */
709 if(hwnd==GetFocus() && (nBar==SB_CTL))
713 SetCaretPos(thumbPos+1, rect.top+1);
717 SetCaretPos(rect.top+1, thumbPos+1);
722 /***********************************************************************
723 * SCROLL_DrawSizeGrip
725 * Draw the size grip.
727 static void SCROLL_DrawSizeGrip( HWND hwnd, HDC hdc)
731 GetClientRect( hwnd, &rc );
732 FillRect( hdc, &rc, GetSysColorBrush(COLOR_SCROLLBAR) );
733 rc.left = max( rc.left, rc.right - GetSystemMetrics(SM_CXVSCROLL) - 1 );
734 rc.top = max( rc.top, rc.bottom - GetSystemMetrics(SM_CYHSCROLL) - 1 );
735 DrawFrameControl( hdc, &rc, DFC_SCROLL, DFCS_SCROLLSIZEGRIP );
739 /***********************************************************************
740 * SCROLL_RefreshScrollBar
742 * Repaint the scroll bar interior after a SetScrollRange() or
743 * SetScrollPos() call.
745 static void SCROLL_RefreshScrollBar( HWND hwnd, INT nBar,
746 BOOL arrows, BOOL interior )
748 HDC hdc = GetDCEx( hwnd, 0,
749 DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW) );
752 SCROLL_DrawScrollBar( hwnd, hdc, nBar, arrows, interior );
753 ReleaseDC( hwnd, hdc );
757 /***********************************************************************
758 * SCROLL_HandleKbdEvent
760 * Handle a keyboard event (only for SB_CTL scrollbars with focus).
763 * hwnd [I] Handle of window with scrollbar(s)
764 * wParam [I] Variable input including enable state
765 * lParam [I] Variable input including input point
767 static void SCROLL_HandleKbdEvent(HWND hwnd, WPARAM wParam, LPARAM lParam)
769 TRACE("hwnd=%p wParam=%d lParam=%ld\n", hwnd, wParam, lParam);
771 /* hide caret on first KEYDOWN to prevent flicker */
772 if ((lParam & PFD_DOUBLEBUFFER_DONTCARE) == 0)
777 case VK_PRIOR: wParam = SB_PAGEUP; break;
778 case VK_NEXT: wParam = SB_PAGEDOWN; break;
779 case VK_HOME: wParam = SB_TOP; break;
780 case VK_END: wParam = SB_BOTTOM; break;
781 case VK_UP: wParam = SB_LINEUP; break;
782 case VK_DOWN: wParam = SB_LINEDOWN; break;
785 SendMessageW(GetParent(hwnd),
786 ((GetWindowLongW( hwnd, GWL_STYLE ) & SBS_VERT) ?
787 WM_VSCROLL : WM_HSCROLL), wParam, (LPARAM)hwnd);
791 /***********************************************************************
792 * SCROLL_HandleScrollEvent
794 * Handle a mouse or timer event for the scrollbar.
795 * 'pt' is the location of the mouse event in client (for SB_CTL) or
796 * windows coordinates.
798 static void SCROLL_HandleScrollEvent( HWND hwnd, INT nBar, UINT msg, POINT pt)
800 /* Previous mouse position for timer events */
802 /* Thumb position when tracking started. */
803 static UINT trackThumbPos;
804 /* Position in the scroll-bar of the last button-down event. */
805 static INT lastClickPos;
806 /* Position in the scroll-bar of the last mouse event. */
807 static INT lastMousePos;
809 enum SCROLL_HITTEST hittest;
810 HWND hwndOwner, hwndCtl;
812 INT arrowSize, thumbSize, thumbPos;
816 SCROLLBAR_INFO *infoPtr = SCROLL_GetScrollBarInfo( hwnd, nBar );
817 if (!infoPtr) return;
818 if ((SCROLL_trackHitTest == SCROLL_NOWHERE) && (msg != WM_LBUTTONDOWN))
821 if (nBar == SB_CTL && (GetWindowLongW( hwnd, GWL_STYLE ) & (SBS_SIZEGRIP | SBS_SIZEBOX)))
825 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
826 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
829 SCROLL_trackHitTest = hittest = SCROLL_THUMB;
832 GetClientRect(GetParent(GetParent(hwnd)),&rect);
837 SCROLL_trackHitTest = hittest = SCROLL_NOWHERE;
838 if (hwnd==GetFocus()) ShowCaret(hwnd);
847 hdc = GetDCEx( hwnd, 0, DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW));
848 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
849 &arrowSize, &thumbSize, &thumbPos );
850 hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd) : hwnd;
851 hwndCtl = (nBar == SB_CTL) ? hwnd : 0;
855 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
856 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
857 SCROLL_trackVertical = vertical;
858 SCROLL_trackHitTest = hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
859 lastClickPos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
860 lastMousePos = lastClickPos;
861 trackThumbPos = thumbPos;
863 if (nBar == SB_CTL && (GetWindowLongW(hwnd, GWL_STYLE) & WS_TABSTOP)) SetFocus( hwnd );
868 hittest = SCROLL_HitTest( hwnd, nBar, pt, TRUE );
873 hittest = SCROLL_NOWHERE;
875 /* if scrollbar has focus, show back caret */
876 if (hwnd==GetFocus()) ShowCaret(hwnd);
881 hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
885 return; /* Should never happen */
888 TRACE("Event: hwnd=%p bar=%d msg=%s pt=%ld,%ld hit=%d\n",
889 hwnd, nBar, SPY_GetMsgName(msg,hwnd), pt.x, pt.y, hittest );
891 switch(SCROLL_trackHitTest)
893 case SCROLL_NOWHERE: /* No tracking in progress */
896 case SCROLL_TOP_ARROW:
897 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
898 (hittest == SCROLL_trackHitTest), FALSE );
899 if (hittest == SCROLL_trackHitTest)
901 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
903 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
904 SB_LINEUP, (LPARAM)hwndCtl );
907 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
908 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
911 else KillSystemTimer( hwnd, SCROLL_TIMER );
914 case SCROLL_TOP_RECT:
915 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
916 thumbPos, infoPtr->flags, vertical,
917 (hittest == SCROLL_trackHitTest), FALSE );
918 if (hittest == SCROLL_trackHitTest)
920 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
922 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
923 SB_PAGEUP, (LPARAM)hwndCtl );
925 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
926 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
929 else KillSystemTimer( hwnd, SCROLL_TIMER );
933 if (msg == WM_LBUTTONDOWN)
935 SCROLL_TrackingWin = hwnd;
936 SCROLL_TrackingBar = nBar;
937 SCROLL_TrackingPos = trackThumbPos + lastMousePos - lastClickPos;
938 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
940 SCROLL_TrackingPos );
941 if (!SCROLL_MovingThumb)
942 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
944 else if (msg == WM_LBUTTONUP)
946 if (SCROLL_MovingThumb)
947 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
948 SCROLL_TrackingWin = 0;
949 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
950 thumbPos, infoPtr->flags, vertical,
953 else /* WM_MOUSEMOVE */
957 if (!SCROLL_PtInRectEx( &rect, pt, vertical )) pos = lastClickPos;
960 pt = SCROLL_ClipPos( &rect, pt );
961 pos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
963 if ( (pos != lastMousePos) || (!SCROLL_MovingThumb) )
965 if (SCROLL_MovingThumb)
966 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
967 arrowSize, thumbSize );
969 SCROLL_TrackingPos = trackThumbPos + pos - lastClickPos;
970 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
972 SCROLL_TrackingPos );
973 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
974 MAKEWPARAM( SB_THUMBTRACK, SCROLL_TrackingVal),
976 if (!SCROLL_MovingThumb)
977 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
978 arrowSize, thumbSize );
983 case SCROLL_BOTTOM_RECT:
984 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
985 thumbPos, infoPtr->flags, vertical,
986 FALSE, (hittest == SCROLL_trackHitTest) );
987 if (hittest == SCROLL_trackHitTest)
989 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
991 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
992 SB_PAGEDOWN, (LPARAM)hwndCtl );
994 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
995 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
998 else KillSystemTimer( hwnd, SCROLL_TIMER );
1001 case SCROLL_BOTTOM_ARROW:
1002 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
1003 FALSE, (hittest == SCROLL_trackHitTest) );
1004 if (hittest == SCROLL_trackHitTest)
1006 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1008 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1009 SB_LINEDOWN, (LPARAM)hwndCtl );
1012 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1013 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1016 else KillSystemTimer( hwnd, SCROLL_TIMER );
1020 if (msg == WM_LBUTTONDOWN)
1023 if (hittest == SCROLL_THUMB)
1025 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1026 trackThumbPos + lastMousePos - lastClickPos );
1027 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1028 MAKEWPARAM( SB_THUMBTRACK, val ), (LPARAM)hwndCtl );
1032 if (msg == WM_LBUTTONUP)
1034 hittest = SCROLL_trackHitTest;
1035 SCROLL_trackHitTest = SCROLL_NOWHERE; /* Terminate tracking */
1037 if (hittest == SCROLL_THUMB)
1039 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1040 trackThumbPos + lastMousePos - lastClickPos );
1041 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1042 MAKEWPARAM( SB_THUMBPOSITION, val ), (LPARAM)hwndCtl );
1044 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1045 SB_ENDSCROLL, (LPARAM)hwndCtl );
1048 ReleaseDC( hwnd, hdc );
1052 /***********************************************************************
1053 * SCROLL_TrackScrollBar
1055 * Track a mouse button press on a scroll-bar.
1056 * pt is in screen-coordinates for non-client scroll bars.
1058 void SCROLL_TrackScrollBar( HWND hwnd, INT scrollbar, POINT pt )
1061 INT xoffset = 0, yoffset = 0;
1063 if (scrollbar != SB_CTL)
1065 WND *wndPtr = WIN_GetPtr( hwnd );
1066 if (!wndPtr || wndPtr == WND_OTHER_PROCESS) return;
1067 xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
1068 yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
1069 WIN_ReleasePtr( wndPtr );
1070 ScreenToClient( hwnd, &pt );
1075 SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt );
1079 if (!GetMessageW( &msg, 0, 0, 0 )) break;
1080 if (CallMsgFilterW( &msg, MSGF_SCROLLBAR )) continue;
1086 pt.x = (short)LOWORD(msg.lParam) + xoffset;
1087 pt.y = (short)HIWORD(msg.lParam) + yoffset;
1088 SCROLL_HandleScrollEvent( hwnd, scrollbar, msg.message, pt );
1091 TranslateMessage( &msg );
1092 DispatchMessageW( &msg );
1095 if (!IsWindow( hwnd ))
1100 } while (msg.message != WM_LBUTTONUP);
1104 /***********************************************************************
1105 * SCROLL_CreateScrollBar
1107 * Create a scroll bar
1110 * hwnd [I] Handle of window with scrollbar(s)
1111 * lpCreate [I] The style and place of the scroll bar
1113 static void SCROLL_CreateScrollBar(HWND hwnd, LPCREATESTRUCTW lpCreate)
1115 LPSCROLLBAR_INFO info = SCROLL_GetScrollBarInfo(hwnd, SB_CTL);
1118 TRACE("hwnd=%p lpCreate=%p\n", hwnd, lpCreate);
1120 if (lpCreate->style & WS_DISABLED)
1122 info->flags = ESB_DISABLE_BOTH;
1123 TRACE("Created WS_DISABLED scrollbar\n");
1127 if (lpCreate->style & (SBS_SIZEGRIP | SBS_SIZEBOX))
1129 if (lpCreate->style & SBS_SIZEBOXTOPLEFTALIGN)
1130 MoveWindow( hwnd, lpCreate->x, lpCreate->y, GetSystemMetrics(SM_CXVSCROLL)+1,
1131 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1132 else if(lpCreate->style & SBS_SIZEBOXBOTTOMRIGHTALIGN)
1133 MoveWindow( hwnd, lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1134 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1135 GetSystemMetrics(SM_CXVSCROLL)+1,
1136 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1138 else if (lpCreate->style & SBS_VERT)
1140 if (lpCreate->style & SBS_LEFTALIGN)
1141 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1142 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1143 else if (lpCreate->style & SBS_RIGHTALIGN)
1145 lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1147 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1151 if (lpCreate->style & SBS_TOPALIGN)
1152 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1153 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1154 else if (lpCreate->style & SBS_BOTTOMALIGN)
1157 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1158 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1163 /*************************************************************************
1164 * SCROLL_GetScrollInfo
1166 * Internal helper for the API function
1169 * hwnd [I] Handle of window with scrollbar(s)
1170 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1171 * info [IO] fMask specifies which values to retrieve
1173 static BOOL SCROLL_GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1175 LPSCROLLBAR_INFO infoPtr;
1177 /* handle invalid data structure */
1178 if (!SCROLL_ScrollInfoValid(info)
1179 || !(infoPtr = SCROLL_GetScrollBarInfo(hwnd, nBar)))
1182 /* fill in the desired scroll info structure */
1183 if (info->fMask & SIF_PAGE) info->nPage = infoPtr->page;
1184 if (info->fMask & SIF_POS) info->nPos = infoPtr->curVal;
1185 if ((info->fMask & SIF_TRACKPOS) && (info->cbSize == sizeof(*info)))
1186 info->nTrackPos = (SCROLL_TrackingWin == WIN_GetFullHandle(hwnd)) ? SCROLL_TrackingVal : infoPtr->curVal;
1187 if (info->fMask & SIF_RANGE)
1189 info->nMin = infoPtr->minVal;
1190 info->nMax = infoPtr->maxVal;
1193 return (info->fMask & SIF_ALL) != 0;
1197 /*************************************************************************
1198 * SCROLL_GetScrollPos
1200 * Internal helper for the API function
1203 * hwnd [I] Handle of window with scrollbar(s)
1204 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1206 static INT SCROLL_GetScrollPos(HWND hwnd, INT nBar)
1208 LPSCROLLBAR_INFO infoPtr = SCROLL_GetScrollBarInfo(hwnd, nBar);
1209 return infoPtr ? infoPtr->curVal: 0;
1213 /*************************************************************************
1214 * SCROLL_GetScrollRange
1216 * Internal helper for the API function
1219 * hwnd [I] Handle of window with scrollbar(s)
1220 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1221 * lpMin [O] Where to store minimum value
1222 * lpMax [O] Where to store maximum value
1226 static BOOL SCROLL_GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1228 LPSCROLLBAR_INFO infoPtr = SCROLL_GetScrollBarInfo(hwnd, nBar);
1230 if (lpMin) *lpMin = infoPtr ? infoPtr->minVal : 0;
1231 if (lpMax) *lpMax = infoPtr ? infoPtr->maxVal : 0;
1237 /*************************************************************************
1238 * SCROLL_SetScrollRange
1241 * hwnd [I] Handle of window with scrollbar(s)
1242 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1243 * lpMin [I] Minimum value
1244 * lpMax [I] Maximum value
1247 static BOOL SCROLL_SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal)
1249 LPSCROLLBAR_INFO infoPtr = SCROLL_GetScrollBarInfo(hwnd, nBar);
1251 TRACE("hwnd=%p nBar=%d min=%d max=%d\n", hwnd, nBar, minVal, maxVal);
1255 infoPtr->minVal = minVal;
1256 infoPtr->maxVal = maxVal;
1262 /***********************************************************************
1265 static LRESULT WINAPI ScrollBarWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1267 if (!IsWindow( hwnd )) return 0;
1272 SCROLL_CreateScrollBar(hwnd, (LPCREATESTRUCTW)lParam);
1277 SCROLLBAR_INFO *infoPtr;
1278 if ((infoPtr = SCROLL_GetScrollBarInfo( hwnd, SB_CTL )))
1280 infoPtr->flags = wParam ? ESB_ENABLE_BOTH : ESB_DISABLE_BOTH;
1281 SCROLL_RefreshScrollBar(hwnd, SB_CTL, TRUE, TRUE);
1286 case WM_LBUTTONDBLCLK:
1287 case WM_LBUTTONDOWN:
1290 pt.x = (short)LOWORD(lParam);
1291 pt.y = (short)HIWORD(lParam);
1292 SCROLL_TrackScrollBar( hwnd, SB_CTL, pt );
1300 pt.x = (short)LOWORD(lParam);
1301 pt.y = (short)HIWORD(lParam);
1302 SCROLL_HandleScrollEvent( hwnd, SB_CTL, message, pt );
1307 SCROLL_HandleKbdEvent(hwnd, wParam, lParam);
1316 /* Create a caret when a ScrollBar get focus */
1318 int arrowSize, thumbSize, thumbPos, vertical;
1319 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,
1320 &arrowSize, &thumbSize, &thumbPos );
1323 CreateCaret(hwnd, (HBITMAP)1, thumbSize-2, rect.bottom-rect.top-2);
1324 SetCaretPos(thumbPos+1, rect.top+1);
1328 CreateCaret(hwnd, (HBITMAP)1, rect.right-rect.left-2,thumbSize-2);
1329 SetCaretPos(rect.top+1, thumbPos+1);
1338 int arrowSize, thumbSize, thumbPos, vertical;
1339 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,&arrowSize, &thumbSize, &thumbPos );
1341 rect.left=thumbPos+1;
1342 rect.right=rect.left+thumbSize;
1346 rect.top=thumbPos+1;
1347 rect.bottom=rect.top+thumbSize;
1350 InvalidateRect(hwnd,&rect,0);
1359 return DLGC_WANTARROWS; /* Windows returns this value */
1364 HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
1365 if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEGRIP)
1367 SCROLL_DrawSizeGrip( hwnd, hdc);
1369 else if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEBOX)
1372 GetClientRect( hwnd, &rc );
1373 FillRect( hdc, &rc, GetSysColorBrush(COLOR_SCROLLBAR) );
1376 SCROLL_DrawScrollBar( hwnd, hdc, SB_CTL, TRUE, TRUE );
1377 if (!wParam) EndPaint(hwnd, &ps);
1383 return SetScrollPos( hwnd, SB_CTL, wParam, (BOOL)lParam );
1387 return SCROLL_GetScrollPos(hwnd, SB_CTL);
1389 case SBM_SETRANGE16:
1390 if (wParam) message = SBM_SETRANGEREDRAW;
1391 wParam = LOWORD(lParam);
1392 lParam = HIWORD(lParam);
1394 case SBM_SETRANGEREDRAW:
1397 INT oldPos = SCROLL_GetScrollPos( hwnd, SB_CTL );
1398 SCROLL_SetScrollRange( hwnd, SB_CTL, wParam, lParam );
1399 if (message == SBM_SETRANGEREDRAW)
1400 SCROLL_RefreshScrollBar( hwnd, SB_CTL, TRUE, TRUE );
1401 if (oldPos != SCROLL_GetScrollPos( hwnd, SB_CTL )) return oldPos;
1405 case SBM_GETRANGE16:
1409 SCROLL_GetScrollRange(hwnd, SB_CTL, &min, &max);
1410 return MAKELRESULT(min, max);
1414 return SCROLL_GetScrollRange(hwnd, SB_CTL, (LPINT)wParam, (LPINT)lParam);
1416 case SBM_ENABLE_ARROWS16:
1417 case SBM_ENABLE_ARROWS:
1418 return EnableScrollBar( hwnd, SB_CTL, wParam );
1420 case SBM_SETSCROLLINFO:
1421 return SCROLL_SetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam, wParam );
1423 case SBM_GETSCROLLINFO:
1424 return SCROLL_GetScrollInfo(hwnd, SB_CTL, (SCROLLINFO *)lParam);
1434 ERR("unknown Win32 msg %04x wp=%08x lp=%08lx\n",
1435 message, wParam, lParam );
1439 if (message >= WM_USER)
1440 WARN("unknown msg %04x wp=%04x lp=%08lx\n",
1441 message, wParam, lParam );
1442 return DefWindowProcW( hwnd, message, wParam, lParam );
1448 /*************************************************************************
1449 * SetScrollInfo (USER32.@)
1451 * SetScrollInfo can be used to set the position, upper bound,
1452 * lower bound, and page size of a scrollbar control.
1455 * hwnd [I] Handle of window with scrollbar(s)
1456 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1457 * info [I] Specifies what to change and new values
1458 * bRedraw [I] Should scrollbar be redrawn afterwards?
1461 * Scrollbar position
1464 * For 100 lines of text to be displayed in a window of 25 lines,
1465 * one would for instance use info->nMin=0, info->nMax=75
1466 * (corresponding to the 76 different positions of the window on
1467 * the text), and info->nPage=25.
1469 INT WINAPI SetScrollInfo(HWND hwnd, INT nBar, const SCROLLINFO *info, BOOL bRedraw)
1471 TRACE("hwnd=%p nBar=%d info=%p, bRedraw=%d\n", hwnd, nBar, info, bRedraw);
1473 /* Refer SB_CTL requests to the window */
1475 return SendMessageW(hwnd, SBM_SETSCROLLINFO, bRedraw, (LPARAM)info);
1477 return SCROLL_SetScrollInfo( hwnd, nBar, info, bRedraw );
1480 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar, const SCROLLINFO *info, BOOL bRedraw )
1482 /* Update the scrollbar state and set action flags according to
1483 * what has to be done graphics wise. */
1485 SCROLLBAR_INFO *infoPtr;
1487 BOOL bChangeParams = FALSE; /* don't show/hide scrollbar if params don't change */
1490 if (!(infoPtr = SCROLL_GetScrollBarInfo(hwnd, nBar))) return 0;
1491 if (info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)) return 0;
1492 if ((info->cbSize != sizeof(*info)) &&
1493 (info->cbSize != sizeof(*info)-sizeof(info->nTrackPos))) return 0;
1495 if (TRACE_ON(scroll))
1497 TRACE("hwnd=%p bar=%d", hwnd, nBar);
1498 if (info->fMask & SIF_PAGE) TRACE( " page=%d", info->nPage );
1499 if (info->fMask & SIF_POS) TRACE( " pos=%d", info->nPos );
1500 if (info->fMask & SIF_RANGE) TRACE( " min=%d max=%d", info->nMin, info->nMax );
1504 /* Set the page size */
1506 if (info->fMask & SIF_PAGE)
1508 if( infoPtr->page != info->nPage )
1510 infoPtr->page = info->nPage;
1511 action |= SA_SSI_REFRESH;
1512 bChangeParams = TRUE;
1516 /* Set the scroll pos */
1518 if (info->fMask & SIF_POS)
1520 if( infoPtr->curVal != info->nPos )
1522 infoPtr->curVal = info->nPos;
1523 action |= SA_SSI_REFRESH;
1527 /* Set the scroll range */
1529 if (info->fMask & SIF_RANGE)
1531 /* Invalid range -> range is set to (0,0) */
1532 if ((info->nMin > info->nMax) ||
1533 ((UINT)(info->nMax - info->nMin) >= 0x80000000))
1535 infoPtr->minVal = 0;
1536 infoPtr->maxVal = 0;
1537 bChangeParams = TRUE;
1541 if( infoPtr->minVal != info->nMin ||
1542 infoPtr->maxVal != info->nMax )
1544 action |= SA_SSI_REFRESH;
1545 infoPtr->minVal = info->nMin;
1546 infoPtr->maxVal = info->nMax;
1547 bChangeParams = TRUE;
1552 /* Make sure the page size is valid */
1554 if (infoPtr->page < 0) infoPtr->page = 0;
1555 else if (infoPtr->page > infoPtr->maxVal - infoPtr->minVal + 1 )
1556 infoPtr->page = infoPtr->maxVal - infoPtr->minVal + 1;
1558 /* Make sure the pos is inside the range */
1560 if (infoPtr->curVal < infoPtr->minVal)
1561 infoPtr->curVal = infoPtr->minVal;
1562 else if (infoPtr->curVal > infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1563 infoPtr->curVal = infoPtr->maxVal - max( infoPtr->page-1, 0 );
1565 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1566 infoPtr->page, infoPtr->curVal,
1567 infoPtr->minVal, infoPtr->maxVal );
1569 /* don't change the scrollbar state if SetScrollInfo
1570 * is just called with SIF_DISABLENOSCROLL
1572 if(!(info->fMask & SIF_ALL)) goto done;
1574 /* Check if the scrollbar should be hidden or disabled */
1576 if (info->fMask & (SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL))
1578 new_flags = infoPtr->flags;
1579 if (infoPtr->minVal >= infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1581 /* Hide or disable scroll-bar */
1582 if (info->fMask & SIF_DISABLENOSCROLL)
1584 new_flags = ESB_DISABLE_BOTH;
1585 action |= SA_SSI_REFRESH;
1587 else if ((nBar != SB_CTL) && bChangeParams)
1589 action = SA_SSI_HIDE;
1593 else /* Show and enable scroll-bar */
1596 if ((nBar != SB_CTL) && bChangeParams)
1597 action |= SA_SSI_SHOW;
1600 if (infoPtr->flags != new_flags) /* check arrow flags */
1602 infoPtr->flags = new_flags;
1603 action |= SA_SSI_REPAINT_ARROWS;
1608 if( action & SA_SSI_HIDE )
1609 SCROLL_ShowScrollBar( hwnd, nBar, FALSE, FALSE );
1612 if( action & SA_SSI_SHOW )
1613 if( SCROLL_ShowScrollBar( hwnd, nBar, TRUE, TRUE ) )
1614 return infoPtr->curVal; /* SetWindowPos() already did the painting */
1617 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
1618 else if( action & SA_SSI_REPAINT_ARROWS )
1619 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, FALSE );
1622 /* Return current position */
1623 return infoPtr->curVal;
1627 /*************************************************************************
1628 * GetScrollInfo (USER32.@)
1630 * GetScrollInfo can be used to retrieve the position, upper bound,
1631 * lower bound, and page size of a scrollbar control.
1634 * hwnd [I] Handle of window with scrollbar(s)
1635 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1636 * info [IO] fMask specifies which values to retrieve
1640 BOOL WINAPI GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1642 TRACE("hwnd=%p nBar=%d info=%p\n", hwnd, nBar, info);
1644 /* Refer SB_CTL requests to the window */
1646 SendMessageW(hwnd, SBM_GETSCROLLINFO, (WPARAM)0, (LPARAM)info);
1648 SCROLL_GetScrollInfo(hwnd, nBar, info);
1654 /*************************************************************************
1655 * SetScrollPos (USER32.@)
1657 * Sets the current position of the scroll thumb.
1660 * hwnd [I] Handle of window with scrollbar(s)
1661 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1662 * nPos [I] New value
1663 * bRedraw [I] Should scrollbar be redrawn afterwards?
1666 * Success: Scrollbar position
1670 * Note the ambiguity when 0 is returned. Use GetLastError
1671 * to make sure there was an error (and to know which one).
1673 INT WINAPI SetScrollPos( HWND hwnd, INT nBar, INT nPos, BOOL bRedraw)
1676 SCROLLBAR_INFO *infoPtr;
1679 if (!(infoPtr = SCROLL_GetScrollBarInfo( hwnd, nBar ))) return 0;
1680 oldPos = infoPtr->curVal;
1681 info.cbSize = sizeof(info);
1683 info.fMask = SIF_POS;
1684 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1689 /*************************************************************************
1690 * GetScrollPos (USER32.@)
1692 * Gets the current position of the scroll thumb.
1695 * hwnd [I] Handle of window with scrollbar(s)
1696 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1699 * Success: Current position
1703 * There is ambiguity when 0 is returned. Use GetLastError
1704 * to make sure there was an error (and to know which one).
1706 INT WINAPI GetScrollPos(HWND hwnd, INT nBar)
1708 TRACE("hwnd=%p nBar=%d\n", hwnd, nBar);
1710 /* Refer SB_CTL requests to the window */
1712 return SendMessageW(hwnd, SBM_GETPOS, (WPARAM)0, (LPARAM)0);
1714 return SCROLL_GetScrollPos(hwnd, nBar);
1718 /*************************************************************************
1719 * SetScrollRange (USER32.@)
1721 * Sets the range of the scroll bar.
1724 * hwnd [I] Handle of window with scrollbar(s)
1725 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1726 * minVal [I] New minimum value
1727 * maxVal [I] New Maximum value
1728 * bRedraw [I] Should scrollbar be redrawn afterwards?
1732 BOOL WINAPI SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal, BOOL bRedraw)
1736 TRACE("hwnd=%p nBar=%d min=%d max=%d, bRedraw=%d\n", hwnd, nBar, minVal, maxVal, bRedraw);
1738 info.cbSize = sizeof(info);
1739 info.fMask = SIF_RANGE;
1742 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1747 /*************************************************************************
1748 * SCROLL_SetNCSbState
1750 * Updates both scrollbars at the same time. Used by MDI CalcChildScroll().
1752 INT SCROLL_SetNCSbState(HWND hwnd, int vMin, int vMax, int vPos,
1753 int hMin, int hMax, int hPos)
1755 SCROLLINFO vInfo, hInfo;
1757 vInfo.cbSize = hInfo.cbSize = sizeof(SCROLLINFO);
1764 vInfo.fMask = hInfo.fMask = SIF_RANGE | SIF_POS;
1766 SCROLL_SetScrollInfo( hwnd, SB_VERT, &vInfo, TRUE );
1767 SCROLL_SetScrollInfo( hwnd, SB_HORZ, &hInfo, TRUE );
1773 /*************************************************************************
1774 * GetScrollRange (USER32.@)
1776 * Gets the range of the scroll bar.
1779 * hwnd [I] Handle of window with scrollbar(s)
1780 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1781 * lpMin [O] Where to store minimum value
1782 * lpMax [O] Where to store maximum value
1786 BOOL WINAPI GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1788 TRACE("hwnd=%p nBar=%d lpMin=%p lpMax=%p\n", hwnd, nBar, lpMin, lpMax);
1790 /* Refer SB_CTL requests to the window */
1792 SendMessageW(hwnd, SBM_GETRANGE, (WPARAM)lpMin, (LPARAM)lpMax);
1794 SCROLL_GetScrollRange(hwnd, nBar, lpMin, lpMax);
1800 /*************************************************************************
1801 * SCROLL_ShowScrollBar()
1803 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1805 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar, BOOL fShowH, BOOL fShowV )
1807 ULONG old_style, set_bits = 0, clear_bits = 0;
1809 TRACE("hwnd=%p bar=%d horz=%d, vert=%d\n", hwnd, nBar, fShowH, fShowV );
1814 ShowWindow( hwnd, fShowH ? SW_SHOW : SW_HIDE );
1819 if (fShowH) set_bits |= WS_HSCROLL;
1820 else clear_bits |= WS_HSCROLL;
1821 if( nBar == SB_HORZ ) break;
1824 if (fShowV) set_bits |= WS_VSCROLL;
1825 else clear_bits |= WS_VSCROLL;
1829 return FALSE; /* Nothing to do! */
1832 old_style = WIN_SetStyle( hwnd, set_bits, clear_bits );
1833 if ((old_style & clear_bits) != 0 || (old_style & set_bits) != set_bits)
1835 /* frame has been changed, let the window redraw itself */
1836 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
1837 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
1840 return FALSE; /* no frame changes */
1844 /*************************************************************************
1845 * ShowScrollBar (USER32.@)
1847 * Shows or hides the scroll bar.
1850 * hwnd [I] Handle of window with scrollbar(s)
1851 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1852 * fShow [I] TRUE = show, FALSE = hide
1856 BOOL WINAPI ShowScrollBar(HWND hwnd, INT nBar, BOOL fShow)
1858 SCROLL_ShowScrollBar( hwnd, nBar, (nBar == SB_VERT) ? 0 : fShow,
1859 (nBar == SB_HORZ) ? 0 : fShow );
1864 /*************************************************************************
1865 * EnableScrollBar (USER32.@)
1867 * Enables or disables the scroll bars.
1869 BOOL WINAPI EnableScrollBar( HWND hwnd, INT nBar, UINT flags )
1872 SCROLLBAR_INFO *infoPtr;
1874 TRACE("%p %d %d\n", hwnd, nBar, flags );
1876 flags &= ESB_DISABLE_BOTH;
1878 if (nBar == SB_BOTH)
1880 if (!(infoPtr = SCROLL_GetScrollBarInfo( hwnd, SB_VERT ))) return FALSE;
1881 if (!(bFineWithMe = (infoPtr->flags == flags)) )
1883 infoPtr->flags = flags;
1884 SCROLL_RefreshScrollBar( hwnd, SB_VERT, TRUE, TRUE );
1891 if (!(infoPtr = SCROLL_GetScrollBarInfo( hwnd, nBar ))) return FALSE;
1892 if (bFineWithMe && infoPtr->flags == flags) return FALSE;
1893 infoPtr->flags = flags;
1895 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );