4 * Copyright 1993 Martin Ayotte
5 * Copyright 1994, 1996 Alexandre Julliard
10 #include "wine/winuser16.h"
13 #include "debugtools.h"
17 DEFAULT_DEBUG_CHANNEL(scroll);
21 INT CurVal; /* Current scroll-bar value */
22 INT MinVal; /* Minimum scroll-bar value */
23 INT MaxVal; /* Maximum scroll-bar value */
24 INT Page; /* Page size of scroll bar (Win32) */
25 UINT flags; /* EnableScrollBar flags */
29 static HBITMAP hUpArrow;
30 static HBITMAP hDnArrow;
31 static HBITMAP hLfArrow;
32 static HBITMAP hRgArrow;
33 static HBITMAP hUpArrowD;
34 static HBITMAP hDnArrowD;
35 static HBITMAP hLfArrowD;
36 static HBITMAP hRgArrowD;
37 static HBITMAP hUpArrowI;
38 static HBITMAP hDnArrowI;
39 static HBITMAP hLfArrowI;
40 static HBITMAP hRgArrowI;
42 #define TOP_ARROW(flags,pressed) \
43 (((flags)&ESB_DISABLE_UP) ? hUpArrowI : ((pressed) ? hUpArrowD:hUpArrow))
44 #define BOTTOM_ARROW(flags,pressed) \
45 (((flags)&ESB_DISABLE_DOWN) ? hDnArrowI : ((pressed) ? hDnArrowD:hDnArrow))
46 #define LEFT_ARROW(flags,pressed) \
47 (((flags)&ESB_DISABLE_LEFT) ? hLfArrowI : ((pressed) ? hLfArrowD:hLfArrow))
48 #define RIGHT_ARROW(flags,pressed) \
49 (((flags)&ESB_DISABLE_RIGHT) ? hRgArrowI : ((pressed) ? hRgArrowD:hRgArrow))
52 /* Minimum size of the rectangle between the arrows */
53 #define SCROLL_MIN_RECT 4
55 /* Minimum size of the thumb in pixels */
56 #define SCROLL_MIN_THUMB 6
58 /* Overlap between arrows and thumb */
59 #define SCROLL_ARROW_THUMB_OVERLAP ((TWEAK_WineLook == WIN31_LOOK) ? 1 : 0)
61 /* Delay (in ms) before first repetition when holding the button down */
62 #define SCROLL_FIRST_DELAY 200
64 /* Delay (in ms) between scroll repetitions */
65 #define SCROLL_REPEAT_DELAY 50
68 #define SCROLL_TIMER 0
70 /* Scroll-bar hit testing */
73 SCROLL_NOWHERE, /* Outside the scroll bar */
74 SCROLL_TOP_ARROW, /* Top or left arrow */
75 SCROLL_TOP_RECT, /* Rectangle between the top arrow and the thumb */
76 SCROLL_THUMB, /* Thumb rectangle */
77 SCROLL_BOTTOM_RECT, /* Rectangle between the thumb and the bottom arrow */
78 SCROLL_BOTTOM_ARROW /* Bottom or right arrow */
81 /* What to do after SCROLL_SetScrollInfo() */
82 #define SA_SSI_HIDE 0x0001
83 #define SA_SSI_SHOW 0x0002
84 #define SA_SSI_REFRESH 0x0004
85 #define SA_SSI_REPAINT_ARROWS 0x0008
87 /* Thumb-tracking info */
88 static HWND SCROLL_TrackingWin = 0;
89 static INT SCROLL_TrackingBar = 0;
90 static INT SCROLL_TrackingPos = 0;
91 static INT SCROLL_TrackingVal = 0;
92 /* Hit test code of the last button-down event */
93 static enum SCROLL_HITTEST SCROLL_trackHitTest;
94 static BOOL SCROLL_trackVertical;
96 /* Is the moving thumb being displayed? */
97 static BOOL SCROLL_MovingThumb = FALSE;
100 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar,
101 BOOL fShowH, BOOL fShowV );
102 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar,
103 const SCROLLINFO *info, INT *action );
104 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
105 RECT *rect, INT arrowSize,
106 INT thumbSize, INT thumbPos,
107 UINT flags, BOOL vertical,
108 BOOL top_selected, BOOL bottom_selected );
109 static LRESULT WINAPI ScrollBarWndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
112 /*********************************************************************
113 * scrollbar class descriptor
115 const struct builtin_class_descr SCROLL_builtin_class =
117 "ScrollBar", /* name */
118 CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC, /* style */
119 NULL, /* procA (winproc is Unicode only) */
120 ScrollBarWndProc, /* procW */
121 sizeof(SCROLLBAR_INFO), /* extra */
122 IDC_ARROWA, /* cursor */
127 /***********************************************************************
130 static void SCROLL_LoadBitmaps(void)
132 hUpArrow = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROW) );
133 hDnArrow = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROW) );
134 hLfArrow = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROW) );
135 hRgArrow = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROW) );
136 hUpArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROWD) );
137 hDnArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROWD) );
138 hLfArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROWD) );
139 hRgArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROWD) );
140 hUpArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROWI) );
141 hDnArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROWI) );
142 hLfArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROWI) );
143 hRgArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROWI) );
147 /***********************************************************************
148 * SCROLL_GetScrollInfo
150 static SCROLLBAR_INFO *SCROLL_GetScrollInfo( HWND hwnd, INT nBar )
152 SCROLLBAR_INFO *infoPtr;
153 WND *wndPtr = WIN_FindWndPtr( hwnd );
155 if (!wndPtr) return NULL;
158 case SB_HORZ: infoPtr = (SCROLLBAR_INFO *)wndPtr->pHScroll; break;
159 case SB_VERT: infoPtr = (SCROLLBAR_INFO *)wndPtr->pVScroll; break;
160 case SB_CTL: infoPtr = (SCROLLBAR_INFO *)wndPtr->wExtra; break;
162 WIN_ReleaseWndPtr( wndPtr );
166 if (!infoPtr) /* Create the info structure if needed */
168 if ((infoPtr = HeapAlloc( GetProcessHeap(), 0, sizeof(SCROLLBAR_INFO) )))
170 infoPtr->MinVal = infoPtr->CurVal = infoPtr->Page = 0;
171 infoPtr->MaxVal = 100;
172 infoPtr->flags = ESB_ENABLE_BOTH;
173 if (nBar == SB_HORZ) wndPtr->pHScroll = infoPtr;
174 else wndPtr->pVScroll = infoPtr;
176 if (!hUpArrow) SCROLL_LoadBitmaps();
178 WIN_ReleaseWndPtr( wndPtr );
183 /***********************************************************************
184 * SCROLL_GetScrollBarRect
186 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
187 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
188 * 'arrowSize' returns the width or height of an arrow (depending on
189 * the orientation of the scrollbar), 'thumbSize' returns the size of
190 * the thumb, and 'thumbPos' returns the position of the thumb
191 * relative to the left or to the top.
192 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
194 static BOOL SCROLL_GetScrollBarRect( HWND hwnd, INT nBar, RECT *lprect,
195 INT *arrowSize, INT *thumbSize,
200 WND *wndPtr = WIN_FindWndPtr( hwnd );
205 lprect->left = wndPtr->rectClient.left - wndPtr->rectWindow.left;
206 lprect->top = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
207 lprect->right = wndPtr->rectClient.right - wndPtr->rectWindow.left;
208 lprect->bottom = lprect->top + GetSystemMetrics(SM_CYHSCROLL);
209 if(wndPtr->dwStyle & WS_BORDER) {
212 } else if(wndPtr->dwStyle & WS_VSCROLL)
218 lprect->left = wndPtr->rectClient.right - wndPtr->rectWindow.left;
219 lprect->top = wndPtr->rectClient.top - wndPtr->rectWindow.top;
220 lprect->right = lprect->left + GetSystemMetrics(SM_CXVSCROLL);
221 lprect->bottom = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
222 if(wndPtr->dwStyle & WS_BORDER) {
225 } else if(wndPtr->dwStyle & WS_HSCROLL)
231 GetClientRect( hwnd, lprect );
232 vertical = ((wndPtr->dwStyle & SBS_VERT) != 0);
236 WIN_ReleaseWndPtr(wndPtr);
240 if (vertical) pixels = lprect->bottom - lprect->top;
241 else pixels = lprect->right - lprect->left;
243 if (pixels <= 2*GetSystemMetrics(SM_CXVSCROLL) + SCROLL_MIN_RECT)
245 if (pixels > SCROLL_MIN_RECT)
246 *arrowSize = (pixels - SCROLL_MIN_RECT) / 2;
249 *thumbPos = *thumbSize = 0;
253 SCROLLBAR_INFO *info = SCROLL_GetScrollInfo( hwnd, nBar );
255 *arrowSize = GetSystemMetrics(SM_CXVSCROLL);
256 pixels -= (2 * (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP));
260 *thumbSize = MulDiv(pixels,info->Page,(info->MaxVal-info->MinVal+1));
261 if (*thumbSize < SCROLL_MIN_THUMB) *thumbSize = SCROLL_MIN_THUMB;
263 else *thumbSize = GetSystemMetrics(SM_CXVSCROLL);
265 if (((pixels -= *thumbSize ) < 0) ||
266 ((info->flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH))
268 /* Rectangle too small or scrollbar disabled -> no thumb */
269 *thumbPos = *thumbSize = 0;
273 INT max = info->MaxVal - max( info->Page-1, 0 );
274 if (info->MinVal >= max)
275 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
277 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP
278 + MulDiv(pixels, (info->CurVal-info->MinVal),(max - info->MinVal));
281 WIN_ReleaseWndPtr(wndPtr);
286 /***********************************************************************
289 * Compute the current scroll position based on the thumb position in pixels
290 * from the top of the scroll-bar.
292 static UINT SCROLL_GetThumbVal( SCROLLBAR_INFO *infoPtr, RECT *rect,
293 BOOL vertical, INT pos )
296 INT pixels = vertical ? rect->bottom-rect->top : rect->right-rect->left;
298 if ((pixels -= 2*(GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP)) <= 0)
299 return infoPtr->MinVal;
303 thumbSize = MulDiv(pixels,infoPtr->Page,(infoPtr->MaxVal-infoPtr->MinVal+1));
304 if (thumbSize < SCROLL_MIN_THUMB) thumbSize = SCROLL_MIN_THUMB;
306 else thumbSize = GetSystemMetrics(SM_CXVSCROLL);
308 if ((pixels -= thumbSize) <= 0) return infoPtr->MinVal;
310 pos = max( 0, pos - (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP) );
311 if (pos > pixels) pos = pixels;
313 if (!infoPtr->Page) pos *= infoPtr->MaxVal - infoPtr->MinVal;
314 else pos *= infoPtr->MaxVal - infoPtr->MinVal - infoPtr->Page + 1;
315 return infoPtr->MinVal + ((pos + pixels / 2) / pixels);
318 /***********************************************************************
321 static BOOL SCROLL_PtInRectEx( LPRECT lpRect, POINT pt, BOOL vertical )
327 rect.left -= lpRect->right - lpRect->left;
328 rect.right += lpRect->right - lpRect->left;
332 rect.top -= lpRect->bottom - lpRect->top;
333 rect.bottom += lpRect->bottom - lpRect->top;
335 return PtInRect( &rect, pt );
338 /***********************************************************************
341 static POINT SCROLL_ClipPos( LPRECT lpRect, POINT pt )
343 if( pt.x < lpRect->left )
346 if( pt.x > lpRect->right )
347 pt.x = lpRect->right;
349 if( pt.y < lpRect->top )
352 if( pt.y > lpRect->bottom )
353 pt.y = lpRect->bottom;
359 /***********************************************************************
362 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
364 static enum SCROLL_HITTEST SCROLL_HitTest( HWND hwnd, INT nBar,
365 POINT pt, BOOL bDragging )
367 INT arrowSize, thumbSize, thumbPos;
370 BOOL vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
371 &arrowSize, &thumbSize, &thumbPos );
373 if ( (bDragging && !SCROLL_PtInRectEx( &rect, pt, vertical )) ||
374 (!PtInRect( &rect, pt )) ) return SCROLL_NOWHERE;
378 if (pt.y < rect.top + arrowSize) return SCROLL_TOP_ARROW;
379 if (pt.y >= rect.bottom - arrowSize) return SCROLL_BOTTOM_ARROW;
380 if (!thumbPos) return SCROLL_TOP_RECT;
382 if (pt.y < thumbPos) return SCROLL_TOP_RECT;
383 if (pt.y >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
385 else /* horizontal */
387 if (pt.x < rect.left + arrowSize) return SCROLL_TOP_ARROW;
388 if (pt.x >= rect.right - arrowSize) return SCROLL_BOTTOM_ARROW;
389 if (!thumbPos) return SCROLL_TOP_RECT;
391 if (pt.x < thumbPos) return SCROLL_TOP_RECT;
392 if (pt.x >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
398 /***********************************************************************
401 * Draw the scroll bar arrows.
403 static void SCROLL_DrawArrows_9x( HDC hdc, SCROLLBAR_INFO *infoPtr,
404 RECT *rect, INT arrowSize, BOOL vertical,
405 BOOL top_pressed, BOOL bottom_pressed )
411 r.bottom = r.top + arrowSize;
413 r.right = r.left + arrowSize;
415 DrawFrameControl( hdc, &r, DFC_SCROLL,
416 (vertical ? DFCS_SCROLLUP : DFCS_SCROLLLEFT)
417 | (top_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
418 | (infoPtr->flags&ESB_DISABLE_LTUP ? DFCS_INACTIVE : 0 ) );
422 r.top = r.bottom-arrowSize;
424 r.left = r.right-arrowSize;
426 DrawFrameControl( hdc, &r, DFC_SCROLL,
427 (vertical ? DFCS_SCROLLDOWN : DFCS_SCROLLRIGHT)
428 | (bottom_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
429 | (infoPtr->flags&ESB_DISABLE_RTDN ? DFCS_INACTIVE : 0) );
432 static void SCROLL_DrawArrows_31( HDC hdc, SCROLLBAR_INFO *infoPtr,
433 RECT *rect, INT arrowSize, BOOL vertical,
434 BOOL top_pressed, BOOL bottom_pressed )
436 HDC hdcMem = CreateCompatibleDC( hdc );
437 HBITMAP hbmpPrev = SelectObject( hdcMem, vertical ?
438 TOP_ARROW(infoPtr->flags, top_pressed)
439 : LEFT_ARROW(infoPtr->flags, top_pressed));
441 SetStretchBltMode( hdc, STRETCH_DELETESCANS );
442 StretchBlt( hdc, rect->left, rect->top,
443 vertical ? rect->right-rect->left : arrowSize,
444 vertical ? arrowSize : rect->bottom-rect->top,
446 GetSystemMetrics(SM_CXVSCROLL),GetSystemMetrics(SM_CYHSCROLL),
449 SelectObject( hdcMem, vertical ?
450 BOTTOM_ARROW( infoPtr->flags, bottom_pressed )
451 : RIGHT_ARROW( infoPtr->flags, bottom_pressed ) );
453 StretchBlt( hdc, rect->left, rect->bottom - arrowSize,
454 rect->right - rect->left, arrowSize,
456 GetSystemMetrics(SM_CXVSCROLL),GetSystemMetrics(SM_CYHSCROLL),
459 StretchBlt( hdc, rect->right - arrowSize, rect->top,
460 arrowSize, rect->bottom - rect->top,
462 GetSystemMetrics(SM_CXVSCROLL), GetSystemMetrics(SM_CYHSCROLL),
464 SelectObject( hdcMem, hbmpPrev );
468 static void SCROLL_DrawArrows( HDC hdc, SCROLLBAR_INFO *infoPtr,
469 RECT *rect, INT arrowSize, BOOL vertical,
470 BOOL top_pressed, BOOL bottom_pressed )
472 if( TWEAK_WineLook == WIN31_LOOK )
473 SCROLL_DrawArrows_31( hdc, infoPtr, rect, arrowSize,
474 vertical, top_pressed,bottom_pressed );
476 SCROLL_DrawArrows_9x( hdc, infoPtr, rect, arrowSize,
477 vertical, top_pressed,bottom_pressed );
481 /***********************************************************************
482 * SCROLL_DrawMovingThumb
484 * Draw the moving thumb rectangle.
486 static void SCROLL_DrawMovingThumb_31( HDC hdc, RECT *rect, BOOL vertical,
487 INT arrowSize, INT thumbSize )
492 r.top += SCROLL_TrackingPos;
493 if (r.top < rect->top + arrowSize - SCROLL_ARROW_THUMB_OVERLAP)
494 r.top = rect->top + arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
495 if (r.top + thumbSize >
496 rect->bottom - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP))
497 r.top = rect->bottom - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP)
499 r.bottom = r.top + thumbSize;
503 r.left += SCROLL_TrackingPos;
504 if (r.left < rect->left + arrowSize - SCROLL_ARROW_THUMB_OVERLAP)
505 r.left = rect->left + arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
506 if (r.left + thumbSize >
507 rect->right - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP))
508 r.left = rect->right - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP)
510 r.right = r.left + thumbSize;
513 DrawFocusRect( hdc, &r );
514 SCROLL_MovingThumb = !SCROLL_MovingThumb;
517 static void SCROLL_DrawMovingThumb_9x( HDC hdc, RECT *rect, BOOL vertical,
518 INT arrowSize, INT thumbSize )
520 INT pos = SCROLL_TrackingPos;
524 max_size = rect->bottom - rect->top;
526 max_size = rect->right - rect->left;
528 max_size -= (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) + thumbSize;
530 if( pos < (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) )
531 pos = (arrowSize-SCROLL_ARROW_THUMB_OVERLAP);
532 else if( pos > max_size )
535 SCROLL_DrawInterior_9x( SCROLL_TrackingWin, hdc, SCROLL_TrackingBar,
536 rect, arrowSize, thumbSize, pos,
537 0, vertical, FALSE, FALSE );
539 SCROLL_MovingThumb = !SCROLL_MovingThumb;
542 static void SCROLL_DrawMovingThumb( HDC hdc, RECT *rect, BOOL vertical,
543 INT arrowSize, INT thumbSize )
545 if( TWEAK_WineLook == WIN31_LOOK )
546 SCROLL_DrawMovingThumb_31( hdc, rect, vertical, arrowSize, thumbSize );
548 SCROLL_DrawMovingThumb_9x( hdc, rect, vertical, arrowSize, thumbSize );
551 /***********************************************************************
552 * SCROLL_DrawInterior
554 * Draw the scroll bar interior (everything except the arrows).
556 static void SCROLL_DrawInterior_9x( 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;
566 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
567 * The window-owned scrollbars need to call DEFWND_ControlColor
568 * to correctly setup default scrollbar colors
572 hBrush = (HBRUSH)SendMessageA( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
573 (WPARAM)hdc,(LPARAM)hwnd);
577 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
580 hSavePen = SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
581 hSaveBrush = SelectObject( hdc, hBrush );
583 /* Calculate the scroll rectangle */
587 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
588 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
592 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
593 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
596 /* Draw the scroll rectangles and thumb */
597 if (!thumbPos) /* No thumb to draw */
599 PatBlt( hdc, r.left, r.top,
600 r.right - r.left, r.bottom - r.top,
603 /* cleanup and return */
604 SelectObject( hdc, hSavePen );
605 SelectObject( hdc, hSaveBrush );
611 PatBlt( hdc, r.left, r.top,
613 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
614 top_selected ? 0x0f0000 : PATCOPY );
615 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
616 PatBlt( hdc, r.left, r.top + thumbSize,
618 r.bottom - r.top - thumbSize,
619 bottom_selected ? 0x0f0000 : PATCOPY );
620 r.bottom = r.top + thumbSize;
622 else /* horizontal */
624 PatBlt( hdc, r.left, r.top,
625 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
627 top_selected ? 0x0f0000 : PATCOPY );
628 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
629 PatBlt( hdc, r.left + thumbSize, r.top,
630 r.right - r.left - thumbSize,
632 bottom_selected ? 0x0f0000 : PATCOPY );
633 r.right = r.left + thumbSize;
637 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT | BF_MIDDLE );
640 SelectObject( hdc, hSavePen );
641 SelectObject( hdc, hSaveBrush );
645 static void SCROLL_DrawInterior( HWND hwnd, HDC hdc, INT nBar,
646 RECT *rect, INT arrowSize,
647 INT thumbSize, INT thumbPos,
648 UINT flags, BOOL vertical,
649 BOOL top_selected, BOOL bottom_selected )
653 HBRUSH hSaveBrush,hBrush;
654 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
656 if (Save_SCROLL_MovingThumb &&
657 (SCROLL_TrackingWin == hwnd) &&
658 (SCROLL_TrackingBar == nBar))
659 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
661 /* Select the correct brush and pen */
663 if (TWEAK_WineLook == WIN31_LOOK && (flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH)
665 /* This ought to be the color of the parent window */
666 hBrush = GetSysColorBrush(COLOR_WINDOW);
670 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
671 * The window-owned scrollbars need to call DEFWND_ControlColor
672 * to correctly setup default scrollbar colors
674 if (nBar == SB_CTL) {
675 hBrush = (HBRUSH)SendMessageA( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
676 (WPARAM)hdc,(LPARAM)hwnd);
678 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
681 hSavePen = SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
682 hSaveBrush = SelectObject( hdc, hBrush );
684 /* Calculate the scroll rectangle */
689 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
690 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
694 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
695 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
698 /* Draw the scroll bar frame */
700 /* Only draw outline if Win 3.1. Mar 24, 1999 - Ronald B. Cemer */
701 if (TWEAK_WineLook == WIN31_LOOK)
702 Rectangle( hdc, r.left, r.top, r.right, r.bottom );
704 /* Draw the scroll rectangles and thumb */
706 if (!thumbPos) /* No thumb to draw */
708 INT offset = (TWEAK_WineLook > WIN31_LOOK) ? 0 : 1;
710 PatBlt( hdc, r.left+offset, r.top+offset,
711 r.right - r.left - 2*offset, r.bottom - r.top - 2*offset,
714 /* cleanup and return */
715 SelectObject( hdc, hSavePen );
716 SelectObject( hdc, hSaveBrush );
722 INT offset = (TWEAK_WineLook == WIN31_LOOK) ? 1 : 0;
724 PatBlt( hdc, r.left + offset, r.top + offset,
725 r.right - r.left - offset*2,
726 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP) - offset,
727 top_selected ? 0x0f0000 : PATCOPY );
728 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
729 PatBlt( hdc, r.left + offset, r.top + thumbSize,
730 r.right - r.left - offset*2,
731 r.bottom - r.top - thumbSize - offset,
732 bottom_selected ? 0x0f0000 : PATCOPY );
733 r.bottom = r.top + thumbSize;
735 else /* horizontal */
737 INT offset = (TWEAK_WineLook == WIN31_LOOK) ? 1 : 0;
739 PatBlt( hdc, r.left + offset, r.top + offset,
740 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
741 r.bottom - r.top - offset*2,
742 top_selected ? 0x0f0000 : PATCOPY );
743 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
744 PatBlt( hdc, r.left + thumbSize, r.top + offset,
745 r.right - r.left - thumbSize - offset,
746 r.bottom - r.top - offset*2,
747 bottom_selected ? 0x0f0000 : PATCOPY );
748 r.right = r.left + thumbSize;
753 SelectObject( hdc, GetSysColorBrush(COLOR_BTNFACE) );
754 if (TWEAK_WineLook == WIN31_LOOK)
756 Rectangle( hdc, r.left, r.top, r.right, r.bottom );
761 Rectangle( hdc, r.left+1, r.top+1, r.right-1, r.bottom-1 );
763 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT );
765 if (Save_SCROLL_MovingThumb &&
766 (SCROLL_TrackingWin == hwnd) &&
767 (SCROLL_TrackingBar == nBar))
768 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
771 SelectObject( hdc, hSavePen );
772 SelectObject( hdc, hSaveBrush );
776 /***********************************************************************
777 * SCROLL_DrawScrollBar
779 * Redraw the whole scrollbar.
781 void SCROLL_DrawScrollBar( HWND hwnd, HDC hdc, INT nBar,
782 BOOL arrows, BOOL interior )
784 INT arrowSize, thumbSize, thumbPos;
787 WND *wndPtr = WIN_FindWndPtr( hwnd );
788 SCROLLBAR_INFO *infoPtr = SCROLL_GetScrollInfo( hwnd, nBar );
789 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
791 if (!wndPtr || !infoPtr ||
792 ((nBar == SB_VERT) && !(wndPtr->dwStyle & WS_VSCROLL)) ||
793 ((nBar == SB_HORZ) && !(wndPtr->dwStyle & WS_HSCROLL))) goto END;
794 if (!WIN_IsWindowDrawable( hwnd, FALSE )) goto END;
795 hwnd = wndPtr->hwndSelf; /* make it a full handle */
797 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
798 &arrowSize, &thumbSize, &thumbPos );
800 /* do not draw if the scrollbar rectangle is empty */
801 if(IsRectEmpty(&rect))
804 if (Save_SCROLL_MovingThumb &&
805 (SCROLL_TrackingWin == hwnd) &&
806 (SCROLL_TrackingBar == nBar))
807 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
809 /* Draw the arrows */
811 if (arrows && arrowSize)
813 if( vertical == SCROLL_trackVertical && GetCapture() == hwnd )
814 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
815 (SCROLL_trackHitTest == SCROLL_TOP_ARROW),
816 (SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW) );
818 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
822 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
823 thumbPos, infoPtr->flags, vertical, FALSE, FALSE );
825 if (Save_SCROLL_MovingThumb &&
826 (SCROLL_TrackingWin == hwnd) &&
827 (SCROLL_TrackingBar == nBar))
828 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
830 /* if scroll bar has focus, reposition the caret */
831 if(hwnd==GetFocus() && (nBar==SB_CTL))
835 SetCaretPos(thumbPos+1, rect.top+1);
839 SetCaretPos(rect.top+1, thumbPos+1);
844 WIN_ReleaseWndPtr(wndPtr);
848 /***********************************************************************
849 * SCROLL_RefreshScrollBar
851 * Repaint the scroll bar interior after a SetScrollRange() or
852 * SetScrollPos() call.
854 static void SCROLL_RefreshScrollBar( HWND hwnd, INT nBar,
855 BOOL arrows, BOOL interior )
857 HDC hdc = GetDCEx( hwnd, 0,
858 DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW) );
861 SCROLL_DrawScrollBar( hwnd, hdc, nBar, arrows, interior );
862 ReleaseDC( hwnd, hdc );
866 /***********************************************************************
867 * SCROLL_HandleKbdEvent
869 * Handle a keyboard event (only for SB_CTL scrollbars).
871 static void SCROLL_HandleKbdEvent( HWND hwnd, WPARAM wParam )
877 case VK_PRIOR: msg = SB_PAGEUP; break;
878 case VK_NEXT: msg = SB_PAGEDOWN; break;
879 case VK_HOME: msg = SB_TOP; break;
880 case VK_END: msg = SB_BOTTOM; break;
881 case VK_UP: msg = SB_LINEUP; break;
882 case VK_DOWN: msg = SB_LINEDOWN; break;
885 SendMessageW( GetParent(hwnd),
886 (GetWindowLongA( hwnd, GWL_STYLE ) & SBS_VERT) ? WM_VSCROLL : WM_HSCROLL,
891 /***********************************************************************
892 * SCROLL_HandleScrollEvent
894 * Handle a mouse or timer event for the scrollbar.
895 * 'pt' is the location of the mouse event in client (for SB_CTL) or
896 * windows coordinates.
898 static void SCROLL_HandleScrollEvent( HWND hwnd, INT nBar, UINT msg, POINT pt)
900 /* Previous mouse position for timer events */
902 /* Thumb position when tracking started. */
903 static UINT trackThumbPos;
904 /* Position in the scroll-bar of the last button-down event. */
905 static INT lastClickPos;
906 /* Position in the scroll-bar of the last mouse event. */
907 static INT lastMousePos;
909 enum SCROLL_HITTEST hittest;
910 HWND hwndOwner, hwndCtl;
912 INT arrowSize, thumbSize, thumbPos;
916 SCROLLBAR_INFO *infoPtr = SCROLL_GetScrollInfo( hwnd, nBar );
917 if (!infoPtr) return;
918 if ((SCROLL_trackHitTest == SCROLL_NOWHERE) && (msg != WM_LBUTTONDOWN))
921 hdc = GetDCEx( hwnd, 0, DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW));
922 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
923 &arrowSize, &thumbSize, &thumbPos );
924 hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd) : hwnd;
925 hwndCtl = (nBar == SB_CTL) ? hwnd : 0;
929 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
930 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
931 SCROLL_trackVertical = vertical;
932 SCROLL_trackHitTest = hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
933 lastClickPos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
934 lastMousePos = lastClickPos;
935 trackThumbPos = thumbPos;
937 if (nBar == SB_CTL && (GetWindowLongA(hwnd, GWL_STYLE) & WS_TABSTOP)) SetFocus( hwnd );
942 hittest = SCROLL_HitTest( hwnd, nBar, pt, TRUE );
947 hittest = SCROLL_NOWHERE;
949 /* if scrollbar has focus, show back caret */
950 if (hwnd==GetFocus()) ShowCaret(hwnd);
955 hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
959 return; /* Should never happen */
962 TRACE("Event: hwnd=%04x bar=%d msg=%s pt=%ld,%ld hit=%d\n",
963 hwnd, nBar, SPY_GetMsgName(msg,hwnd), pt.x, pt.y, hittest );
965 switch(SCROLL_trackHitTest)
967 case SCROLL_NOWHERE: /* No tracking in progress */
970 case SCROLL_TOP_ARROW:
971 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
972 (hittest == SCROLL_trackHitTest), FALSE );
973 if (hittest == SCROLL_trackHitTest)
975 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
977 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
978 SB_LINEUP, (LPARAM)hwndCtl );
981 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
982 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
985 else KillSystemTimer( hwnd, SCROLL_TIMER );
988 case SCROLL_TOP_RECT:
989 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
990 thumbPos, infoPtr->flags, vertical,
991 (hittest == SCROLL_trackHitTest), FALSE );
992 if (hittest == SCROLL_trackHitTest)
994 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
996 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
997 SB_PAGEUP, (LPARAM)hwndCtl );
999 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1000 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1003 else KillSystemTimer( hwnd, SCROLL_TIMER );
1007 if (msg == WM_LBUTTONDOWN)
1009 SCROLL_TrackingWin = hwnd;
1010 SCROLL_TrackingBar = nBar;
1011 SCROLL_TrackingPos = trackThumbPos + lastMousePos - lastClickPos;
1012 if (!SCROLL_MovingThumb)
1013 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
1015 else if (msg == WM_LBUTTONUP)
1017 if (SCROLL_MovingThumb)
1018 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
1019 SCROLL_TrackingWin = 0;
1020 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
1021 thumbPos, infoPtr->flags, vertical,
1024 else /* WM_MOUSEMOVE */
1028 if (!SCROLL_PtInRectEx( &rect, pt, vertical )) pos = lastClickPos;
1031 pt = SCROLL_ClipPos( &rect, pt );
1032 pos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
1034 if ( (pos != lastMousePos) || (!SCROLL_MovingThumb) )
1036 if (SCROLL_MovingThumb)
1037 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
1038 arrowSize, thumbSize );
1040 SCROLL_TrackingPos = trackThumbPos + pos - lastClickPos;
1041 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
1043 SCROLL_TrackingPos );
1044 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1045 MAKEWPARAM( SB_THUMBTRACK, SCROLL_TrackingVal),
1047 if (!SCROLL_MovingThumb)
1048 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
1049 arrowSize, thumbSize );
1054 case SCROLL_BOTTOM_RECT:
1055 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
1056 thumbPos, infoPtr->flags, vertical,
1057 FALSE, (hittest == SCROLL_trackHitTest) );
1058 if (hittest == SCROLL_trackHitTest)
1060 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1062 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1063 SB_PAGEDOWN, (LPARAM)hwndCtl );
1065 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1066 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1069 else KillSystemTimer( hwnd, SCROLL_TIMER );
1072 case SCROLL_BOTTOM_ARROW:
1073 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
1074 FALSE, (hittest == SCROLL_trackHitTest) );
1075 if (hittest == SCROLL_trackHitTest)
1077 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1079 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1080 SB_LINEDOWN, (LPARAM)hwndCtl );
1083 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1084 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1087 else KillSystemTimer( hwnd, SCROLL_TIMER );
1091 if (msg == WM_LBUTTONUP)
1093 hittest = SCROLL_trackHitTest;
1094 SCROLL_trackHitTest = SCROLL_NOWHERE; /* Terminate tracking */
1096 if (hittest == SCROLL_THUMB)
1098 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1099 trackThumbPos + lastMousePos - lastClickPos );
1100 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1101 MAKEWPARAM( SB_THUMBPOSITION, val ), (LPARAM)hwndCtl );
1104 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1105 SB_ENDSCROLL, (LPARAM)hwndCtl );
1108 ReleaseDC( hwnd, hdc );
1112 /***********************************************************************
1113 * SCROLL_TrackScrollBar
1115 * Track a mouse button press on a scroll-bar.
1116 * pt is in screen-coordinates for non-client scroll bars.
1118 void SCROLL_TrackScrollBar( HWND hwnd, INT scrollbar, POINT pt )
1121 INT xoffset = 0, yoffset = 0;
1123 if (scrollbar != SB_CTL)
1125 WND *wndPtr = WIN_GetPtr( hwnd );
1126 if (!wndPtr || wndPtr == WND_OTHER_PROCESS) return;
1127 xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
1128 yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
1129 WIN_ReleasePtr( wndPtr );
1130 ScreenToClient( hwnd, &pt );
1135 SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt );
1139 if (!GetMessageW( &msg, 0, 0, 0 )) break;
1140 if (CallMsgFilterW( &msg, MSGF_SCROLLBAR )) continue;
1146 pt.x = LOWORD(msg.lParam) + xoffset;
1147 pt.y = HIWORD(msg.lParam) + yoffset;
1148 SCROLL_HandleScrollEvent( hwnd, scrollbar, msg.message, pt );
1151 TranslateMessage( &msg );
1152 DispatchMessageW( &msg );
1155 if (!IsWindow( hwnd ))
1160 } while (msg.message != WM_LBUTTONUP);
1164 /***********************************************************************
1167 static LRESULT WINAPI ScrollBarWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1169 if (!IsWindow( hwnd )) return 0;
1175 SCROLLBAR_INFO *infoPtr;
1176 CREATESTRUCTW *lpCreat = (CREATESTRUCTW *)lParam;
1178 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, SB_CTL ))) return -1;
1179 if (lpCreat->style & WS_DISABLED)
1181 TRACE("Created WS_DISABLED scrollbar\n");
1182 infoPtr->flags = ESB_DISABLE_BOTH;
1185 if (lpCreat->style & SBS_SIZEBOX)
1187 FIXME("Unimplemented style SBS_SIZEBOX.\n" );
1190 if (lpCreat->style & SBS_VERT)
1192 if (lpCreat->style & SBS_LEFTALIGN)
1193 MoveWindow( hwnd, lpCreat->x, lpCreat->y,
1194 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreat->cy, FALSE );
1195 else if (lpCreat->style & SBS_RIGHTALIGN)
1197 lpCreat->x+lpCreat->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1199 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreat->cy, FALSE );
1203 if (lpCreat->style & SBS_TOPALIGN)
1204 MoveWindow( hwnd, lpCreat->x, lpCreat->y,
1205 lpCreat->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1206 else if (lpCreat->style & SBS_BOTTOMALIGN)
1209 lpCreat->y+lpCreat->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1210 lpCreat->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1213 if (!hUpArrow) SCROLL_LoadBitmaps();
1214 TRACE("ScrollBar creation, hwnd=%04x\n", hwnd );
1219 SCROLLBAR_INFO *infoPtr;
1220 if ((infoPtr = SCROLL_GetScrollInfo( hwnd, SB_CTL )))
1222 infoPtr->flags = wParam ? ESB_ENABLE_BOTH : ESB_DISABLE_BOTH;
1223 SCROLL_RefreshScrollBar(hwnd, SB_CTL, TRUE, TRUE);
1228 case WM_LBUTTONDOWN:
1231 pt.x = SLOWORD(lParam);
1232 pt.y = SHIWORD(lParam);
1233 SCROLL_TrackScrollBar( hwnd, SB_CTL, pt );
1241 pt.x = SLOWORD(lParam);
1242 pt.y = SHIWORD(lParam);
1243 SCROLL_HandleScrollEvent( hwnd, SB_CTL, message, pt );
1247 /* if key event is received, the scrollbar has the focus */
1249 /* hide caret on first KEYDOWN to prevent flicker */
1250 if ((lParam & 0x40000000)==0)
1252 SCROLL_HandleKbdEvent( hwnd, wParam );
1261 /* Create a caret when a ScrollBar get focus */
1263 int arrowSize, thumbSize, thumbPos, vertical;
1264 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,
1265 &arrowSize, &thumbSize, &thumbPos );
1268 CreateCaret(hwnd,1, thumbSize-2, rect.bottom-rect.top-2);
1269 SetCaretPos(thumbPos+1, rect.top+1);
1273 CreateCaret(hwnd,1, rect.right-rect.left-2,thumbSize-2);
1274 SetCaretPos(rect.top+1, thumbPos+1);
1283 int arrowSize, thumbSize, thumbPos, vertical;
1284 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,&arrowSize, &thumbSize, &thumbPos );
1286 rect.left=thumbPos+1;
1287 rect.right=rect.left+thumbSize;
1291 rect.top=thumbPos+1;
1292 rect.bottom=rect.top+thumbSize;
1295 InvalidateRect(hwnd,&rect,0);
1304 return DLGC_WANTARROWS; /* Windows returns this value */
1309 HDC hdc = BeginPaint( hwnd, &ps );
1310 SCROLL_DrawScrollBar( hwnd, hdc, SB_CTL, TRUE, TRUE );
1311 EndPaint( hwnd, &ps );
1317 return SetScrollPos( hwnd, SB_CTL, wParam, (BOOL)lParam );
1321 return GetScrollPos( hwnd, SB_CTL );
1323 case SBM_SETRANGE16:
1324 SetScrollRange( hwnd, SB_CTL, LOWORD(lParam), HIWORD(lParam),
1325 wParam /* FIXME: Is this correct? */ );
1330 INT oldPos = GetScrollPos( hwnd, SB_CTL );
1331 SetScrollRange( hwnd, SB_CTL, wParam, lParam, FALSE );
1332 if (oldPos != GetScrollPos( hwnd, SB_CTL )) return oldPos;
1336 case SBM_GETRANGE16:
1337 FIXME("don't know how to handle SBM_GETRANGE16 (wp=%04x,lp=%08lx)\n", wParam, lParam );
1341 GetScrollRange( hwnd, SB_CTL, (LPINT)wParam, (LPINT)lParam );
1344 case SBM_ENABLE_ARROWS16:
1345 case SBM_ENABLE_ARROWS:
1346 return EnableScrollBar( hwnd, SB_CTL, wParam );
1348 case SBM_SETRANGEREDRAW:
1350 INT oldPos = GetScrollPos( hwnd, SB_CTL );
1351 SetScrollRange( hwnd, SB_CTL, wParam, lParam, TRUE );
1352 if (oldPos != GetScrollPos( hwnd, SB_CTL )) return oldPos;
1356 case SBM_SETSCROLLINFO:
1357 return SetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam, wParam );
1359 case SBM_GETSCROLLINFO:
1360 return GetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam );
1370 ERR("unknown Win32 msg %04x wp=%08x lp=%08lx\n",
1371 message, wParam, lParam );
1375 if (message >= WM_USER)
1376 WARN("unknown msg %04x wp=%04x lp=%08lx\n",
1377 message, wParam, lParam );
1378 return DefWindowProcW( hwnd, message, wParam, lParam );
1384 /*************************************************************************
1385 * SetScrollInfo (USER32.@)
1386 * SetScrollInfo can be used to set the position, upper bound,
1387 * lower bound, and page size of a scrollbar control.
1390 * Scrollbar position
1393 * For 100 lines of text to be displayed in a window of 25 lines,
1394 * one would for instance use info->nMin=0, info->nMax=75
1395 * (corresponding to the 76 different positions of the window on
1396 * the text), and info->nPage=25.
1398 INT WINAPI SetScrollInfo(
1399 HWND hwnd /* [in] Handle of window whose scrollbar will be affected */,
1400 INT nBar /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1401 const SCROLLINFO *info /* [in] Specifies what to change and new values */,
1402 BOOL bRedraw /* [in] Should scrollbar be redrawn afterwards ? */)
1405 INT retVal = SCROLL_SetScrollInfo( hwnd, nBar, info, &action );
1407 if( action & SA_SSI_HIDE )
1408 SCROLL_ShowScrollBar( hwnd, nBar, FALSE, FALSE );
1411 if( action & SA_SSI_SHOW )
1412 if( SCROLL_ShowScrollBar( hwnd, nBar, TRUE, TRUE ) )
1413 return retVal; /* SetWindowPos() already did the painting */
1415 if( bRedraw && (action & SA_SSI_REFRESH))
1416 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
1417 else if( action & SA_SSI_REPAINT_ARROWS )
1418 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, FALSE );
1423 INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar,
1424 const SCROLLINFO *info, INT *action )
1426 /* Update the scrollbar state and set action flags according to
1427 * what has to be done graphics wise. */
1429 SCROLLBAR_INFO *infoPtr;
1431 BOOL bChangeParams = FALSE; /* don't show/hide scrollbar if params don't change */
1435 if (!(infoPtr = SCROLL_GetScrollInfo(hwnd, nBar))) return 0;
1436 if (info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)) return 0;
1437 if ((info->cbSize != sizeof(*info)) &&
1438 (info->cbSize != sizeof(*info)-sizeof(info->nTrackPos))) return 0;
1440 if (TRACE_ON(scroll))
1442 TRACE("hwnd=%04x bar=%d", hwnd, nBar);
1443 if (info->fMask & SIF_PAGE) DPRINTF( " page=%d", info->nPage );
1444 if (info->fMask & SIF_POS) DPRINTF( " pos=%d", info->nPos );
1445 if (info->fMask & SIF_RANGE) DPRINTF( " min=%d max=%d", info->nMin, info->nMax );
1449 /* Set the page size */
1451 if (info->fMask & SIF_PAGE)
1453 if( infoPtr->Page != info->nPage )
1455 infoPtr->Page = info->nPage;
1456 *action |= SA_SSI_REFRESH;
1457 bChangeParams = TRUE;
1461 /* Set the scroll pos */
1463 if (info->fMask & SIF_POS)
1465 if( infoPtr->CurVal != info->nPos )
1467 infoPtr->CurVal = info->nPos;
1468 *action |= SA_SSI_REFRESH;
1472 /* Set the scroll range */
1474 if (info->fMask & SIF_RANGE)
1476 /* Invalid range -> range is set to (0,0) */
1477 if ((info->nMin > info->nMax) ||
1478 ((UINT)(info->nMax - info->nMin) >= 0x80000000))
1480 infoPtr->MinVal = 0;
1481 infoPtr->MaxVal = 0;
1482 bChangeParams = TRUE;
1486 if( infoPtr->MinVal != info->nMin ||
1487 infoPtr->MaxVal != info->nMax )
1489 *action |= SA_SSI_REFRESH;
1490 infoPtr->MinVal = info->nMin;
1491 infoPtr->MaxVal = info->nMax;
1492 bChangeParams = TRUE;
1497 /* Make sure the page size is valid */
1499 if (infoPtr->Page < 0) infoPtr->Page = 0;
1500 else if (infoPtr->Page > infoPtr->MaxVal - infoPtr->MinVal + 1 )
1501 infoPtr->Page = infoPtr->MaxVal - infoPtr->MinVal + 1;
1503 /* Make sure the pos is inside the range */
1505 if (infoPtr->CurVal < infoPtr->MinVal)
1506 infoPtr->CurVal = infoPtr->MinVal;
1507 else if (infoPtr->CurVal > infoPtr->MaxVal - max( infoPtr->Page-1, 0 ))
1508 infoPtr->CurVal = infoPtr->MaxVal - max( infoPtr->Page-1, 0 );
1510 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1511 infoPtr->Page, infoPtr->CurVal,
1512 infoPtr->MinVal, infoPtr->MaxVal );
1514 /* don't change the scrollbar state if SetScrollInfo
1515 * is just called with SIF_DISABLENOSCROLL
1517 if(!(info->fMask & SIF_ALL)) goto done;
1519 /* Check if the scrollbar should be hidden or disabled */
1521 if (info->fMask & (SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL))
1523 new_flags = infoPtr->flags;
1524 if (infoPtr->MinVal >= infoPtr->MaxVal - max( infoPtr->Page-1, 0 ))
1526 /* Hide or disable scroll-bar */
1527 if (info->fMask & SIF_DISABLENOSCROLL)
1529 new_flags = ESB_DISABLE_BOTH;
1530 *action |= SA_SSI_REFRESH;
1532 else if ((nBar != SB_CTL) && bChangeParams)
1534 *action = SA_SSI_HIDE;
1538 else /* Show and enable scroll-bar */
1541 if ((nBar != SB_CTL) && bChangeParams)
1542 *action |= SA_SSI_SHOW;
1545 if (infoPtr->flags != new_flags) /* check arrow flags */
1547 infoPtr->flags = new_flags;
1548 *action |= SA_SSI_REPAINT_ARROWS;
1553 /* Return current position */
1555 return infoPtr->CurVal;
1559 /*************************************************************************
1560 * GetScrollInfo (USER32.@)
1561 * GetScrollInfo can be used to retrieve the position, upper bound,
1562 * lower bound, and page size of a scrollbar control.
1566 BOOL WINAPI GetScrollInfo(
1567 HWND hwnd /* [in] Handle of window */ ,
1568 INT nBar /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1569 LPSCROLLINFO info /* [in/out] (info.fMask [in] specifies which values are to retrieve) */)
1571 SCROLLBAR_INFO *infoPtr;
1573 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return FALSE;
1574 if (info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)) return FALSE;
1575 if ((info->cbSize != sizeof(*info)) &&
1576 (info->cbSize != sizeof(*info)-sizeof(info->nTrackPos))) return FALSE;
1578 if (info->fMask & SIF_PAGE) info->nPage = infoPtr->Page;
1579 if (info->fMask & SIF_POS) info->nPos = infoPtr->CurVal;
1580 if ((info->fMask & SIF_TRACKPOS) && (info->cbSize == sizeof(*info)))
1581 info->nTrackPos = (SCROLL_TrackingWin == WIN_GetFullHandle(hwnd)) ? SCROLL_TrackingVal : infoPtr->CurVal;
1582 if (info->fMask & SIF_RANGE)
1584 info->nMin = infoPtr->MinVal;
1585 info->nMax = infoPtr->MaxVal;
1587 return (info->fMask & SIF_ALL) != 0;
1591 /*************************************************************************
1592 * SetScrollPos (USER32.@)
1595 * Success: Scrollbar position
1599 * Note the ambiguity when 0 is returned. Use GetLastError
1600 * to make sure there was an error (and to know which one).
1602 INT WINAPI SetScrollPos(
1603 HWND hwnd /* [in] Handle of window whose scrollbar will be affected */,
1604 INT nBar /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1605 INT nPos /* [in] New value */,
1606 BOOL bRedraw /* [in] Should scrollbar be redrawn afterwards ? */ )
1609 SCROLLBAR_INFO *infoPtr;
1612 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return 0;
1613 oldPos = infoPtr->CurVal;
1614 info.cbSize = sizeof(info);
1616 info.fMask = SIF_POS;
1617 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1622 /*************************************************************************
1623 * GetScrollPos (USER32.@)
1626 * Success: Current position
1630 * Note the ambiguity when 0 is returned. Use GetLastError
1631 * to make sure there was an error (and to know which one).
1633 INT WINAPI GetScrollPos(
1634 HWND hwnd, /* [in] Handle of window */
1635 INT nBar /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */)
1637 SCROLLBAR_INFO *infoPtr;
1639 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return 0;
1640 return infoPtr->CurVal;
1644 /*************************************************************************
1645 * SetScrollRange (USER32.@)
1649 BOOL WINAPI SetScrollRange(
1650 HWND hwnd, /* [in] Handle of window whose scrollbar will be affected */
1651 INT nBar, /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */
1652 INT MinVal, /* [in] New minimum value */
1653 INT MaxVal, /* [in] New maximum value */
1654 BOOL bRedraw /* [in] Should scrollbar be redrawn afterwards ? */)
1658 info.cbSize = sizeof(info);
1661 info.fMask = SIF_RANGE;
1662 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1667 /*************************************************************************
1668 * SCROLL_SetNCSbState
1670 * Updates both scrollbars at the same time. Used by MDI CalcChildScroll().
1672 INT SCROLL_SetNCSbState(HWND hwnd, int vMin, int vMax, int vPos,
1673 int hMin, int hMax, int hPos)
1676 SCROLLINFO vInfo, hInfo;
1678 vInfo.cbSize = hInfo.cbSize = sizeof(SCROLLINFO);
1685 vInfo.fMask = hInfo.fMask = SIF_RANGE | SIF_POS;
1687 SCROLL_SetScrollInfo( hwnd, SB_VERT, &vInfo, &vA );
1688 SCROLL_SetScrollInfo( hwnd, SB_HORZ, &hInfo, &hA );
1690 if( !SCROLL_ShowScrollBar( hwnd, SB_BOTH,
1691 (hA & SA_SSI_SHOW),(vA & SA_SSI_SHOW) ) )
1693 /* SetWindowPos() wasn't called, just redraw the scrollbars if needed */
1694 if( vA & SA_SSI_REFRESH )
1695 SCROLL_RefreshScrollBar( hwnd, SB_VERT, FALSE, TRUE );
1697 if( hA & SA_SSI_REFRESH )
1698 SCROLL_RefreshScrollBar( hwnd, SB_HORZ, FALSE, TRUE );
1704 /*************************************************************************
1705 * GetScrollRange (USER32.@)
1709 BOOL WINAPI GetScrollRange(
1710 HWND hwnd, /* [in] Handle of window */
1711 INT nBar, /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */
1712 LPINT lpMin, /* [out] Where to store minimum value */
1713 LPINT lpMax /* [out] Where to store maximum value */)
1715 SCROLLBAR_INFO *infoPtr;
1717 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar )))
1719 if (lpMin) lpMin = 0;
1720 if (lpMax) lpMax = 0;
1723 if (lpMin) *lpMin = infoPtr->MinVal;
1724 if (lpMax) *lpMax = infoPtr->MaxVal;
1729 /*************************************************************************
1730 * SCROLL_ShowScrollBar()
1732 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1734 BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar,
1735 BOOL fShowH, BOOL fShowV )
1737 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
1739 TRACE("hwnd=%04x bar=%d horz=%d, vert=%d\n",
1740 hwnd, nBar, fShowH, fShowV );
1745 ShowWindow( hwnd, fShowH ? SW_SHOW : SW_HIDE );
1752 fShowH = !(style & WS_HSCROLL);
1753 style |= WS_HSCROLL;
1757 fShowH = (style & WS_HSCROLL);
1758 style &= ~WS_HSCROLL;
1760 if( nBar == SB_HORZ ) {
1769 fShowV = !(style & WS_VSCROLL);
1770 style |= WS_VSCROLL;
1774 fShowV = (style & WS_VSCROLL);
1775 style &= ~WS_VSCROLL;
1777 if ( nBar == SB_VERT )
1782 return FALSE; /* Nothing to do! */
1785 if( fShowH || fShowV ) /* frame has been changed, let the window redraw itself */
1787 WIN_SetStyle( hwnd, style );
1788 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
1789 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
1792 return FALSE; /* no frame changes */
1796 /*************************************************************************
1797 * ShowScrollBar (USER32.@)
1801 BOOL WINAPI ShowScrollBar(
1802 HWND hwnd, /* [in] Handle of window whose scrollbar(s) will be affected */
1803 INT nBar, /* [in] One of SB_HORZ, SB_VERT, SB_BOTH or SB_CTL */
1804 BOOL fShow /* [in] TRUE = show, FALSE = hide */)
1806 SCROLL_ShowScrollBar( hwnd, nBar, (nBar == SB_VERT) ? 0 : fShow,
1807 (nBar == SB_HORZ) ? 0 : fShow );
1812 /*************************************************************************
1813 * EnableScrollBar (USER32.@)
1815 BOOL WINAPI EnableScrollBar( HWND hwnd, INT nBar, UINT flags )
1818 SCROLLBAR_INFO *infoPtr;
1820 TRACE("%04x %d %d\n", hwnd, nBar, flags );
1822 flags &= ESB_DISABLE_BOTH;
1824 if (nBar == SB_BOTH)
1826 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, SB_VERT ))) return FALSE;
1827 if (!(bFineWithMe = (infoPtr->flags == flags)) )
1829 infoPtr->flags = flags;
1830 SCROLL_RefreshScrollBar( hwnd, SB_VERT, TRUE, TRUE );
1837 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return FALSE;
1838 if (bFineWithMe && infoPtr->flags == flags) return FALSE;
1839 infoPtr->flags = flags;
1841 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );