crypt32/tests: Add a trailing '\n' to ok() calls.
[wine.git] / dlls / user32 / scroll.c
blob4b572e59f9e07bd8807deb3f69c9a7e957d58142
1 /*
2 * Scrollbar control
4 * Copyright 1993 Martin Ayotte
5 * Copyright 1994, 1996 Alexandre Julliard
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 * NOTES
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.
31 #include "config.h"
33 #include <stdarg.h>
35 #include "windef.h"
36 #include "winbase.h"
37 #include "wingdi.h"
38 #include "controls.h"
39 #include "win.h"
40 #include "wine/debug.h"
41 #include "user_private.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(scroll);
45 /* data for a single scroll bar */
46 typedef struct
48 INT curVal; /* Current scroll-bar value */
49 INT minVal; /* Minimum scroll-bar value */
50 INT maxVal; /* Maximum scroll-bar value */
51 INT page; /* Page size of scroll bar (Win32) */
52 UINT flags; /* EnableScrollBar flags */
53 } SCROLLBAR_INFO, *LPSCROLLBAR_INFO;
55 /* data for window that has (one or two) scroll bars */
56 typedef struct
58 SCROLLBAR_INFO horz;
59 SCROLLBAR_INFO vert;
60 } WINSCROLLBAR_INFO, *LPWINSCROLLBAR_INFO;
62 /* Minimum size of the rectangle between the arrows */
63 #define SCROLL_MIN_RECT 4
65 /* Minimum size of the thumb in pixels */
66 #define SCROLL_MIN_THUMB 6
68 /* Overlap between arrows and thumb */
69 #define SCROLL_ARROW_THUMB_OVERLAP 0
71 /* Delay (in ms) before first repetition when holding the button down */
72 #define SCROLL_FIRST_DELAY 200
74 /* Delay (in ms) between scroll repetitions */
75 #define SCROLL_REPEAT_DELAY 50
77 /* Scroll timer id */
78 #define SCROLL_TIMER 0
80 /* Scroll-bar hit testing */
81 enum SCROLL_HITTEST
83 SCROLL_NOWHERE, /* Outside the scroll bar */
84 SCROLL_TOP_ARROW, /* Top or left arrow */
85 SCROLL_TOP_RECT, /* Rectangle between the top arrow and the thumb */
86 SCROLL_THUMB, /* Thumb rectangle */
87 SCROLL_BOTTOM_RECT, /* Rectangle between the thumb and the bottom arrow */
88 SCROLL_BOTTOM_ARROW /* Bottom or right arrow */
91 /* What to do after SCROLL_SetScrollInfo() */
92 #define SA_SSI_HIDE 0x0001
93 #define SA_SSI_SHOW 0x0002
94 #define SA_SSI_REFRESH 0x0004
95 #define SA_SSI_REPAINT_ARROWS 0x0008
97 /* Thumb-tracking info */
98 static HWND SCROLL_TrackingWin = 0;
99 static INT SCROLL_TrackingBar = 0;
100 static INT SCROLL_TrackingPos = 0;
101 static INT SCROLL_TrackingVal = 0;
102 /* Hit test code of the last button-down event */
103 static enum SCROLL_HITTEST SCROLL_trackHitTest;
104 static BOOL SCROLL_trackVertical;
106 /* Is the moving thumb being displayed? */
107 static BOOL SCROLL_MovingThumb = FALSE;
109 /* Local functions */
110 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar,
111 BOOL fShowH, BOOL fShowV );
112 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar,
113 const SCROLLINFO *info, BOOL bRedraw );
114 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
115 RECT *rect, INT arrowSize,
116 INT thumbSize, INT thumbPos,
117 UINT flags, BOOL vertical,
118 BOOL top_selected, BOOL bottom_selected );
121 /*********************************************************************
122 * scrollbar class descriptor
124 static const WCHAR scrollbarW[] = {'S','c','r','o','l','l','B','a','r',0};
125 const struct builtin_class_descr SCROLL_builtin_class =
127 scrollbarW, /* name */
128 CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC, /* style */
129 WINPROC_SCROLLBAR, /* proc */
130 sizeof(SCROLLBAR_INFO), /* extra */
131 IDC_ARROW, /* cursor */
132 0 /* brush */
135 /***********************************************************************
136 * SCROLL_ScrollInfoValid
138 * Determine if the supplied SCROLLINFO struct is valid.
139 * info [in] The SCROLLINFO struct to be tested
141 static inline BOOL SCROLL_ScrollInfoValid( LPCSCROLLINFO info )
143 return !(info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)
144 || (info->cbSize != sizeof(*info)
145 && info->cbSize != sizeof(*info) - sizeof(info->nTrackPos)));
149 /***********************************************************************
150 * SCROLL_GetInternalInfo
152 * Returns pointer to internal SCROLLBAR_INFO structure for nBar
153 * or NULL if failed (f.i. scroll bar does not exist yet)
154 * If alloc is TRUE and the struct does not exist yet, create it.
156 static SCROLLBAR_INFO *SCROLL_GetInternalInfo( HWND hwnd, INT nBar, BOOL alloc )
158 SCROLLBAR_INFO *infoPtr = NULL;
159 WND *wndPtr = WIN_GetPtr( hwnd );
161 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return NULL;
162 switch(nBar)
164 case SB_HORZ:
165 if (wndPtr->pScroll) infoPtr = &((LPWINSCROLLBAR_INFO)wndPtr->pScroll)->horz;
166 break;
167 case SB_VERT:
168 if (wndPtr->pScroll) infoPtr = &((LPWINSCROLLBAR_INFO)wndPtr->pScroll)->vert;
169 break;
170 case SB_CTL:
171 infoPtr = (SCROLLBAR_INFO *)wndPtr->wExtra;
172 break;
173 case SB_BOTH:
174 WARN("with SB_BOTH\n");
175 break;
178 if (!infoPtr && alloc)
180 WINSCROLLBAR_INFO *winInfoPtr;
182 if (nBar != SB_HORZ && nBar != SB_VERT)
183 WARN("Cannot initialize nBar=%d\n",nBar);
184 else if ((winInfoPtr = HeapAlloc( GetProcessHeap(), 0, sizeof(WINSCROLLBAR_INFO) )))
186 /* Set default values */
187 winInfoPtr->horz.minVal = 0;
188 winInfoPtr->horz.curVal = 0;
189 winInfoPtr->horz.page = 0;
190 /* From MSDN and our own tests:
191 * max for a standard scroll bar is 100 by default. */
192 winInfoPtr->horz.maxVal = 100;
193 winInfoPtr->horz.flags = ESB_ENABLE_BOTH;
194 winInfoPtr->vert = winInfoPtr->horz;
195 wndPtr->pScroll = winInfoPtr;
196 infoPtr = nBar == SB_HORZ ? &winInfoPtr->horz : &winInfoPtr->vert;
199 WIN_ReleasePtr( wndPtr );
200 return infoPtr;
204 /***********************************************************************
205 * SCROLL_GetScrollBarRect
207 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
208 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
209 * 'arrowSize' returns the width or height of an arrow (depending on
210 * the orientation of the scrollbar), 'thumbSize' returns the size of
211 * the thumb, and 'thumbPos' returns the position of the thumb
212 * relative to the left or to the top.
213 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
215 static BOOL SCROLL_GetScrollBarRect( HWND hwnd, INT nBar, RECT *lprect,
216 INT *arrowSize, INT *thumbSize,
217 INT *thumbPos )
219 INT pixels;
220 BOOL vertical;
221 WND *wndPtr = WIN_GetPtr( hwnd );
223 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
225 switch(nBar)
227 case SB_HORZ:
228 WIN_GetRectangles( hwnd, COORDS_WINDOW, NULL, lprect );
229 lprect->top = lprect->bottom;
230 lprect->bottom += GetSystemMetrics(SM_CYHSCROLL);
231 if(wndPtr->dwStyle & WS_VSCROLL)
232 lprect->right++;
233 vertical = FALSE;
234 break;
236 case SB_VERT:
237 WIN_GetRectangles( hwnd, COORDS_WINDOW, NULL, lprect );
238 if((wndPtr->dwExStyle & WS_EX_LEFTSCROLLBAR) != 0)
240 lprect->right = lprect->left;
241 lprect->left -= GetSystemMetrics(SM_CXVSCROLL);
243 else
245 lprect->left = lprect->right;
246 lprect->right += GetSystemMetrics(SM_CXVSCROLL);
248 if(wndPtr->dwStyle & WS_HSCROLL)
249 lprect->bottom++;
250 vertical = TRUE;
251 break;
253 case SB_CTL:
254 GetClientRect( hwnd, lprect );
255 vertical = ((wndPtr->dwStyle & SBS_VERT) != 0);
256 break;
258 default:
259 WIN_ReleasePtr( wndPtr );
260 return FALSE;
263 if (vertical) pixels = lprect->bottom - lprect->top;
264 else pixels = lprect->right - lprect->left;
266 if (pixels <= 2*GetSystemMetrics(SM_CXVSCROLL) + SCROLL_MIN_RECT)
268 if (pixels > SCROLL_MIN_RECT)
269 *arrowSize = (pixels - SCROLL_MIN_RECT) / 2;
270 else
271 *arrowSize = 0;
272 *thumbPos = *thumbSize = 0;
274 else
276 SCROLLBAR_INFO *info = SCROLL_GetInternalInfo( hwnd, nBar, FALSE );
277 if (!info)
279 WARN("called for missing scroll bar\n");
280 WIN_ReleasePtr( wndPtr );
281 return FALSE;
283 *arrowSize = GetSystemMetrics(SM_CXVSCROLL);
284 pixels -= (2 * (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP));
286 if (info->page)
288 *thumbSize = MulDiv(pixels,info->page,(info->maxVal-info->minVal+1));
289 if (*thumbSize < SCROLL_MIN_THUMB) *thumbSize = SCROLL_MIN_THUMB;
291 else *thumbSize = GetSystemMetrics(SM_CXVSCROLL);
293 if (((pixels -= *thumbSize ) < 0) ||
294 ((info->flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH))
296 /* Rectangle too small or scrollbar disabled -> no thumb */
297 *thumbPos = *thumbSize = 0;
299 else
301 INT max = info->maxVal - max( info->page-1, 0 );
302 if (info->minVal >= max)
303 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
304 else
305 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP
306 + MulDiv(pixels, (info->curVal-info->minVal),(max - info->minVal));
309 WIN_ReleasePtr( wndPtr );
310 return vertical;
314 /***********************************************************************
315 * SCROLL_GetThumbVal
317 * Compute the current scroll position based on the thumb position in pixels
318 * from the top of the scroll-bar.
320 static UINT SCROLL_GetThumbVal( SCROLLBAR_INFO *infoPtr, RECT *rect,
321 BOOL vertical, INT pos )
323 INT thumbSize;
324 INT pixels = vertical ? rect->bottom-rect->top : rect->right-rect->left;
325 INT range;
327 if ((pixels -= 2*(GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP)) <= 0)
328 return infoPtr->minVal;
330 if (infoPtr->page)
332 thumbSize = MulDiv(pixels,infoPtr->page,(infoPtr->maxVal-infoPtr->minVal+1));
333 if (thumbSize < SCROLL_MIN_THUMB) thumbSize = SCROLL_MIN_THUMB;
335 else thumbSize = GetSystemMetrics(SM_CXVSCROLL);
337 if ((pixels -= thumbSize) <= 0) return infoPtr->minVal;
339 pos = max( 0, pos - (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP) );
340 if (pos > pixels) pos = pixels;
342 if (!infoPtr->page)
343 range = infoPtr->maxVal - infoPtr->minVal;
344 else
345 range = infoPtr->maxVal - infoPtr->minVal - infoPtr->page + 1;
347 return infoPtr->minVal + MulDiv(pos, range, pixels);
350 /***********************************************************************
351 * SCROLL_PtInRectEx
353 static BOOL SCROLL_PtInRectEx( LPRECT lpRect, POINT pt, BOOL vertical )
355 RECT rect = *lpRect;
356 int scrollbarWidth;
358 /* Pad hit rect to allow mouse to be dragged outside of scrollbar and
359 * still be considered in the scrollbar. */
360 if (vertical)
362 scrollbarWidth = lpRect->right - lpRect->left;
363 InflateRect(&rect, scrollbarWidth * 8, scrollbarWidth * 2);
365 else
367 scrollbarWidth = lpRect->bottom - lpRect->top;
368 InflateRect(&rect, scrollbarWidth * 2, scrollbarWidth * 8);
370 return PtInRect( &rect, pt );
373 /***********************************************************************
374 * SCROLL_ClipPos
376 static POINT SCROLL_ClipPos( LPRECT lpRect, POINT pt )
378 if( pt.x < lpRect->left )
379 pt.x = lpRect->left;
380 else
381 if( pt.x > lpRect->right )
382 pt.x = lpRect->right;
384 if( pt.y < lpRect->top )
385 pt.y = lpRect->top;
386 else
387 if( pt.y > lpRect->bottom )
388 pt.y = lpRect->bottom;
390 return pt;
394 /***********************************************************************
395 * SCROLL_HitTest
397 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
399 static enum SCROLL_HITTEST SCROLL_HitTest( HWND hwnd, INT nBar,
400 POINT pt, BOOL bDragging )
402 INT arrowSize, thumbSize, thumbPos;
403 RECT rect;
405 BOOL vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
406 &arrowSize, &thumbSize, &thumbPos );
408 if ( (bDragging && !SCROLL_PtInRectEx( &rect, pt, vertical )) ||
409 (!PtInRect( &rect, pt )) ) return SCROLL_NOWHERE;
411 if (vertical)
413 if (pt.y < rect.top + arrowSize) return SCROLL_TOP_ARROW;
414 if (pt.y >= rect.bottom - arrowSize) return SCROLL_BOTTOM_ARROW;
415 if (!thumbPos) return SCROLL_TOP_RECT;
416 pt.y -= rect.top;
417 if (pt.y < thumbPos) return SCROLL_TOP_RECT;
418 if (pt.y >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
420 else /* horizontal */
422 if (pt.x < rect.left + arrowSize) return SCROLL_TOP_ARROW;
423 if (pt.x >= rect.right - arrowSize) return SCROLL_BOTTOM_ARROW;
424 if (!thumbPos) return SCROLL_TOP_RECT;
425 pt.x -= rect.left;
426 if (pt.x < thumbPos) return SCROLL_TOP_RECT;
427 if (pt.x >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
429 return SCROLL_THUMB;
433 /***********************************************************************
434 * SCROLL_DrawArrows
436 * Draw the scroll bar arrows.
438 static void SCROLL_DrawArrows( HDC hdc, SCROLLBAR_INFO *infoPtr,
439 RECT *rect, INT arrowSize, BOOL vertical,
440 BOOL top_pressed, BOOL bottom_pressed )
442 RECT r;
444 r = *rect;
445 if( vertical )
446 r.bottom = r.top + arrowSize;
447 else
448 r.right = r.left + arrowSize;
450 DrawFrameControl( hdc, &r, DFC_SCROLL,
451 (vertical ? DFCS_SCROLLUP : DFCS_SCROLLLEFT)
452 | (top_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
453 | (infoPtr->flags&ESB_DISABLE_LTUP ? DFCS_INACTIVE : 0 ) );
455 r = *rect;
456 if( vertical )
457 r.top = r.bottom-arrowSize;
458 else
459 r.left = r.right-arrowSize;
461 DrawFrameControl( hdc, &r, DFC_SCROLL,
462 (vertical ? DFCS_SCROLLDOWN : DFCS_SCROLLRIGHT)
463 | (bottom_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
464 | (infoPtr->flags&ESB_DISABLE_RTDN ? DFCS_INACTIVE : 0) );
467 static void SCROLL_DrawMovingThumb( HDC hdc, RECT *rect, BOOL vertical,
468 INT arrowSize, INT thumbSize )
470 INT pos = SCROLL_TrackingPos;
471 INT max_size;
473 if( vertical )
474 max_size = rect->bottom - rect->top;
475 else
476 max_size = rect->right - rect->left;
478 max_size -= (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) + thumbSize;
480 if( pos < (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) )
481 pos = (arrowSize-SCROLL_ARROW_THUMB_OVERLAP);
482 else if( pos > max_size )
483 pos = max_size;
485 SCROLL_DrawInterior_9x( SCROLL_TrackingWin, hdc, SCROLL_TrackingBar,
486 rect, arrowSize, thumbSize, pos,
487 0, vertical, FALSE, FALSE );
489 SCROLL_MovingThumb = !SCROLL_MovingThumb;
492 /***********************************************************************
493 * SCROLL_DrawInterior
495 * Draw the scroll bar interior (everything except the arrows).
497 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
498 RECT *rect, INT arrowSize,
499 INT thumbSize, INT thumbPos,
500 UINT flags, BOOL vertical,
501 BOOL top_selected, BOOL bottom_selected )
503 RECT r;
504 HPEN hSavePen;
505 HBRUSH hSaveBrush,hBrush;
507 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
508 * The window-owned scrollbars need to call DEFWND_ControlColor
509 * to correctly setup default scrollbar colors
511 if (nBar == SB_CTL)
513 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
514 (WPARAM)hdc,(LPARAM)hwnd);
516 else
518 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
521 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
522 hSaveBrush = SelectObject( hdc, hBrush );
524 /* Calculate the scroll rectangle */
525 r = *rect;
526 if (vertical)
528 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
529 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
531 else
533 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
534 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
537 /* Draw the scroll rectangles and thumb */
538 if (!thumbPos) /* No thumb to draw */
540 PatBlt( hdc, r.left, r.top,
541 r.right - r.left, r.bottom - r.top,
542 PATCOPY );
544 /* cleanup and return */
545 SelectObject( hdc, hSavePen );
546 SelectObject( hdc, hSaveBrush );
547 return;
550 if (vertical)
552 PatBlt( hdc, r.left, r.top,
553 r.right - r.left,
554 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
555 top_selected ? 0x0f0000 : PATCOPY );
556 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
557 PatBlt( hdc, r.left, r.top + thumbSize,
558 r.right - r.left,
559 r.bottom - r.top - thumbSize,
560 bottom_selected ? 0x0f0000 : PATCOPY );
561 r.bottom = r.top + thumbSize;
563 else /* horizontal */
565 PatBlt( hdc, r.left, r.top,
566 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
567 r.bottom - r.top,
568 top_selected ? 0x0f0000 : PATCOPY );
569 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
570 PatBlt( hdc, r.left + thumbSize, r.top,
571 r.right - r.left - thumbSize,
572 r.bottom - r.top,
573 bottom_selected ? 0x0f0000 : PATCOPY );
574 r.right = r.left + thumbSize;
577 /* Draw the thumb */
578 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT | BF_MIDDLE );
580 /* cleanup */
581 SelectObject( hdc, hSavePen );
582 SelectObject( hdc, hSaveBrush );
586 static void SCROLL_DrawInterior( HWND hwnd, HDC hdc, INT nBar,
587 RECT *rect, INT arrowSize,
588 INT thumbSize, INT thumbPos,
589 UINT flags, BOOL vertical,
590 BOOL top_selected, BOOL bottom_selected )
592 RECT r;
593 HPEN hSavePen;
594 HBRUSH hSaveBrush,hBrush;
595 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
597 if (Save_SCROLL_MovingThumb &&
598 (SCROLL_TrackingWin == hwnd) &&
599 (SCROLL_TrackingBar == nBar))
600 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
602 /* Select the correct brush and pen */
604 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
605 * The window-owned scrollbars need to call DEFWND_ControlColor
606 * to correctly setup default scrollbar colors
608 if (nBar == SB_CTL) {
609 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
610 (WPARAM)hdc,(LPARAM)hwnd);
611 } else {
612 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
614 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
615 hSaveBrush = SelectObject( hdc, hBrush );
617 /* Calculate the scroll rectangle */
619 r = *rect;
620 if (vertical)
622 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
623 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
625 else
627 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
628 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
631 /* Draw the scroll bar frame */
633 /* Draw the scroll rectangles and thumb */
635 if (!thumbPos) /* No thumb to draw */
637 PatBlt( hdc, r.left, r.top, r.right - r.left, r.bottom - r.top, PATCOPY );
639 /* cleanup and return */
640 SelectObject( hdc, hSavePen );
641 SelectObject( hdc, hSaveBrush );
642 return;
645 if (vertical)
647 PatBlt( hdc, r.left, r.top, r.right - r.left,
648 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
649 top_selected ? 0x0f0000 : PATCOPY );
650 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
651 PatBlt( hdc, r.left, r.top + thumbSize, r.right - r.left,
652 r.bottom - r.top - thumbSize,
653 bottom_selected ? 0x0f0000 : PATCOPY );
654 r.bottom = r.top + thumbSize;
656 else /* horizontal */
658 PatBlt( hdc, r.left, r.top,
659 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
660 r.bottom - r.top, top_selected ? 0x0f0000 : PATCOPY );
661 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
662 PatBlt( hdc, r.left + thumbSize, r.top, r.right - r.left - thumbSize,
663 r.bottom - r.top, bottom_selected ? 0x0f0000 : PATCOPY );
664 r.right = r.left + thumbSize;
667 /* Draw the thumb */
669 SelectObject( hdc, GetSysColorBrush(COLOR_BTNFACE) );
670 Rectangle( hdc, r.left+1, r.top+1, r.right-1, r.bottom-1 );
671 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT );
673 if (Save_SCROLL_MovingThumb &&
674 (SCROLL_TrackingWin == hwnd) &&
675 (SCROLL_TrackingBar == nBar))
676 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
678 /* cleanup */
679 SelectObject( hdc, hSavePen );
680 SelectObject( hdc, hSaveBrush );
684 /***********************************************************************
685 * SCROLL_DrawScrollBar
687 * Redraw the whole scrollbar.
689 void SCROLL_DrawScrollBar( HWND hwnd, HDC hdc, INT nBar,
690 BOOL arrows, BOOL interior )
692 INT arrowSize, thumbSize, thumbPos;
693 RECT rect;
694 BOOL vertical;
695 SCROLLBAR_INFO *infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, TRUE );
696 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
697 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
699 if (!(hwnd = WIN_GetFullHandle( hwnd ))) return;
701 if (!infoPtr ||
702 ((nBar == SB_VERT) && !(style & WS_VSCROLL)) ||
703 ((nBar == SB_HORZ) && !(style & WS_HSCROLL))) return;
704 if (!WIN_IsWindowDrawable( hwnd, FALSE )) return;
706 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
707 &arrowSize, &thumbSize, &thumbPos );
709 /* do not draw if the scrollbar rectangle is empty */
710 if(IsRectEmpty(&rect)) return;
712 if (Save_SCROLL_MovingThumb &&
713 (SCROLL_TrackingWin == hwnd) &&
714 (SCROLL_TrackingBar == nBar))
715 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
717 /* Draw the arrows */
719 if (arrows && arrowSize)
721 if( vertical == SCROLL_trackVertical && GetCapture() == hwnd )
722 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
723 (SCROLL_trackHitTest == SCROLL_TOP_ARROW),
724 (SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW) );
725 else
726 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
727 FALSE, FALSE );
729 if( interior )
730 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
731 thumbPos, infoPtr->flags, vertical, FALSE, FALSE );
733 if (Save_SCROLL_MovingThumb &&
734 (SCROLL_TrackingWin == hwnd) &&
735 (SCROLL_TrackingBar == nBar))
736 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
738 /* if scroll bar has focus, reposition the caret */
739 if(hwnd==GetFocus() && (nBar==SB_CTL))
741 if (!vertical)
743 SetCaretPos(thumbPos+1, rect.top+1);
745 else
747 SetCaretPos(rect.top+1, thumbPos+1);
752 /***********************************************************************
753 * SCROLL_DrawSizeGrip
755 * Draw the size grip.
757 static void SCROLL_DrawSizeGrip( HWND hwnd, HDC hdc)
759 RECT rc;
761 GetClientRect( hwnd, &rc );
762 FillRect( hdc, &rc, GetSysColorBrush(COLOR_SCROLLBAR) );
763 rc.left = max( rc.left, rc.right - GetSystemMetrics(SM_CXVSCROLL) - 1 );
764 rc.top = max( rc.top, rc.bottom - GetSystemMetrics(SM_CYHSCROLL) - 1 );
765 DrawFrameControl( hdc, &rc, DFC_SCROLL, DFCS_SCROLLSIZEGRIP );
769 /***********************************************************************
770 * SCROLL_RefreshScrollBar
772 * Repaint the scroll bar interior after a SetScrollRange() or
773 * SetScrollPos() call.
775 static void SCROLL_RefreshScrollBar( HWND hwnd, INT nBar,
776 BOOL arrows, BOOL interior )
778 HDC hdc = GetDCEx( hwnd, 0,
779 DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW) );
780 if (!hdc) return;
782 SCROLL_DrawScrollBar( hwnd, hdc, nBar, arrows, interior );
783 ReleaseDC( hwnd, hdc );
787 /***********************************************************************
788 * SCROLL_HandleKbdEvent
790 * Handle a keyboard event (only for SB_CTL scrollbars with focus).
792 * PARAMS
793 * hwnd [I] Handle of window with scrollbar(s)
794 * wParam [I] Variable input including enable state
795 * lParam [I] Variable input including input point
797 static void SCROLL_HandleKbdEvent(HWND hwnd, WPARAM wParam, LPARAM lParam)
799 TRACE("hwnd=%p wParam=%ld lParam=%ld\n", hwnd, wParam, lParam);
801 /* hide caret on first KEYDOWN to prevent flicker */
802 if ((lParam & PFD_DOUBLEBUFFER_DONTCARE) == 0)
803 HideCaret(hwnd);
805 switch(wParam)
807 case VK_PRIOR: wParam = SB_PAGEUP; break;
808 case VK_NEXT: wParam = SB_PAGEDOWN; break;
809 case VK_HOME: wParam = SB_TOP; break;
810 case VK_END: wParam = SB_BOTTOM; break;
811 case VK_UP: wParam = SB_LINEUP; break;
812 case VK_DOWN: wParam = SB_LINEDOWN; break;
813 case VK_LEFT: wParam = SB_LINEUP; break;
814 case VK_RIGHT: wParam = SB_LINEDOWN; break;
815 default: return;
817 SendMessageW(GetParent(hwnd),
818 ((GetWindowLongW( hwnd, GWL_STYLE ) & SBS_VERT) ?
819 WM_VSCROLL : WM_HSCROLL), wParam, (LPARAM)hwnd);
823 /***********************************************************************
824 * SCROLL_HandleScrollEvent
826 * Handle a mouse or timer event for the scrollbar.
827 * 'pt' is the location of the mouse event in client (for SB_CTL) or
828 * windows coordinates.
830 static void SCROLL_HandleScrollEvent( HWND hwnd, INT nBar, UINT msg, POINT pt)
832 /* Previous mouse position for timer events */
833 static POINT prevPt;
834 /* Thumb position when tracking started. */
835 static UINT trackThumbPos;
836 /* Position in the scroll-bar of the last button-down event. */
837 static INT lastClickPos;
838 /* Position in the scroll-bar of the last mouse event. */
839 static INT lastMousePos;
841 enum SCROLL_HITTEST hittest;
842 HWND hwndOwner, hwndCtl;
843 BOOL vertical;
844 INT arrowSize, thumbSize, thumbPos;
845 RECT rect;
846 HDC hdc;
848 SCROLLBAR_INFO *infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, FALSE );
849 if (!infoPtr) return;
850 if ((SCROLL_trackHitTest == SCROLL_NOWHERE) && (msg != WM_LBUTTONDOWN))
851 return;
853 if (nBar == SB_CTL && (GetWindowLongW( hwnd, GWL_STYLE ) & (SBS_SIZEGRIP | SBS_SIZEBOX)))
855 switch(msg)
857 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
858 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
859 SetCapture( hwnd );
860 prevPt = pt;
861 SCROLL_trackHitTest = hittest = SCROLL_THUMB;
862 break;
863 case WM_MOUSEMOVE:
864 GetClientRect(GetParent(GetParent(hwnd)),&rect);
865 prevPt = pt;
866 break;
867 case WM_LBUTTONUP:
868 ReleaseCapture();
869 SCROLL_trackHitTest = hittest = SCROLL_NOWHERE;
870 if (hwnd==GetFocus()) ShowCaret(hwnd);
871 break;
872 case WM_SYSTIMER:
873 pt = prevPt;
874 break;
876 return;
879 hdc = GetDCEx( hwnd, 0, DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW));
880 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
881 &arrowSize, &thumbSize, &thumbPos );
882 hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd) : hwnd;
883 hwndCtl = (nBar == SB_CTL) ? hwnd : 0;
885 switch(msg)
887 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
888 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
889 SCROLL_trackVertical = vertical;
890 SCROLL_trackHitTest = hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
891 lastClickPos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
892 lastMousePos = lastClickPos;
893 trackThumbPos = thumbPos;
894 prevPt = pt;
895 if (nBar == SB_CTL && (GetWindowLongW(hwnd, GWL_STYLE) & WS_TABSTOP)) SetFocus( hwnd );
896 SetCapture( hwnd );
897 break;
899 case WM_MOUSEMOVE:
900 hittest = SCROLL_HitTest( hwnd, nBar, pt, TRUE );
901 prevPt = pt;
902 break;
904 case WM_LBUTTONUP:
905 hittest = SCROLL_NOWHERE;
906 ReleaseCapture();
907 /* if scrollbar has focus, show back caret */
908 if (hwnd==GetFocus()) ShowCaret(hwnd);
909 break;
911 case WM_SYSTIMER:
912 pt = prevPt;
913 hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
914 break;
916 default:
917 return; /* Should never happen */
920 TRACE("Event: hwnd=%p bar=%d msg=%s pt=%d,%d hit=%d\n",
921 hwnd, nBar, SPY_GetMsgName(msg,hwnd), pt.x, pt.y, hittest );
923 switch(SCROLL_trackHitTest)
925 case SCROLL_NOWHERE: /* No tracking in progress */
926 break;
928 case SCROLL_TOP_ARROW:
929 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
930 (hittest == SCROLL_trackHitTest), FALSE );
931 if (hittest == SCROLL_trackHitTest)
933 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
935 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
936 SB_LINEUP, (LPARAM)hwndCtl );
939 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
940 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
942 else KillSystemTimer( hwnd, SCROLL_TIMER );
943 break;
945 case SCROLL_TOP_RECT:
946 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
947 thumbPos, infoPtr->flags, vertical,
948 (hittest == SCROLL_trackHitTest), FALSE );
949 if (hittest == SCROLL_trackHitTest)
951 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
953 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
954 SB_PAGEUP, (LPARAM)hwndCtl );
956 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
957 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
959 else KillSystemTimer( hwnd, SCROLL_TIMER );
960 break;
962 case SCROLL_THUMB:
963 if (msg == WM_LBUTTONDOWN)
965 SCROLL_TrackingWin = hwnd;
966 SCROLL_TrackingBar = nBar;
967 SCROLL_TrackingPos = trackThumbPos + lastMousePos - lastClickPos;
968 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
969 vertical,
970 SCROLL_TrackingPos );
971 if (!SCROLL_MovingThumb)
972 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
974 else if (msg == WM_LBUTTONUP)
976 if (SCROLL_MovingThumb)
977 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
979 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
980 thumbPos, infoPtr->flags, vertical,
981 FALSE, FALSE );
983 else /* WM_MOUSEMOVE */
985 INT pos;
987 if (!SCROLL_PtInRectEx( &rect, pt, vertical )) pos = lastClickPos;
988 else
990 pt = SCROLL_ClipPos( &rect, pt );
991 pos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
993 if ( (pos != lastMousePos) || (!SCROLL_MovingThumb) )
995 if (SCROLL_MovingThumb)
996 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
997 arrowSize, thumbSize );
998 lastMousePos = pos;
999 SCROLL_TrackingPos = trackThumbPos + pos - lastClickPos;
1000 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
1001 vertical,
1002 SCROLL_TrackingPos );
1003 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1004 MAKEWPARAM( SB_THUMBTRACK, SCROLL_TrackingVal),
1005 (LPARAM)hwndCtl );
1006 if (!SCROLL_MovingThumb)
1007 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
1008 arrowSize, thumbSize );
1011 break;
1013 case SCROLL_BOTTOM_RECT:
1014 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
1015 thumbPos, infoPtr->flags, vertical,
1016 FALSE, (hittest == SCROLL_trackHitTest) );
1017 if (hittest == SCROLL_trackHitTest)
1019 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1021 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1022 SB_PAGEDOWN, (LPARAM)hwndCtl );
1024 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1025 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
1027 else KillSystemTimer( hwnd, SCROLL_TIMER );
1028 break;
1030 case SCROLL_BOTTOM_ARROW:
1031 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
1032 FALSE, (hittest == SCROLL_trackHitTest) );
1033 if (hittest == SCROLL_trackHitTest)
1035 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1037 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1038 SB_LINEDOWN, (LPARAM)hwndCtl );
1041 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1042 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
1044 else KillSystemTimer( hwnd, SCROLL_TIMER );
1045 break;
1048 if (msg == WM_LBUTTONDOWN)
1051 if (hittest == SCROLL_THUMB)
1053 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1054 trackThumbPos + lastMousePos - lastClickPos );
1055 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1056 MAKEWPARAM( SB_THUMBTRACK, val ), (LPARAM)hwndCtl );
1060 if (msg == WM_LBUTTONUP)
1062 hittest = SCROLL_trackHitTest;
1063 SCROLL_trackHitTest = SCROLL_NOWHERE; /* Terminate tracking */
1065 if (hittest == SCROLL_THUMB)
1067 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1068 trackThumbPos + lastMousePos - lastClickPos );
1069 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1070 MAKEWPARAM( SB_THUMBPOSITION, val ), (LPARAM)hwndCtl );
1072 /* SB_ENDSCROLL doesn't report thumb position */
1073 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1074 SB_ENDSCROLL, (LPARAM)hwndCtl );
1076 /* Terminate tracking */
1077 SCROLL_TrackingWin = 0;
1080 ReleaseDC( hwnd, hdc );
1084 /***********************************************************************
1085 * SCROLL_TrackScrollBar
1087 * Track a mouse button press on a scroll-bar.
1088 * pt is in screen-coordinates for non-client scroll bars.
1090 void SCROLL_TrackScrollBar( HWND hwnd, INT scrollbar, POINT pt )
1092 MSG msg;
1094 if (scrollbar != SB_CTL)
1096 RECT rect;
1097 WIN_GetRectangles( hwnd, COORDS_CLIENT, &rect, NULL );
1098 ScreenToClient( hwnd, &pt );
1099 pt.x -= rect.left;
1100 pt.y -= rect.top;
1103 SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt );
1107 if (!GetMessageW( &msg, 0, 0, 0 )) break;
1108 if (CallMsgFilterW( &msg, MSGF_SCROLLBAR )) continue;
1109 if (msg.message == WM_LBUTTONUP ||
1110 msg.message == WM_MOUSEMOVE ||
1111 (msg.message == WM_SYSTIMER && msg.wParam == SCROLL_TIMER))
1113 pt.x = (short)LOWORD(msg.lParam);
1114 pt.y = (short)HIWORD(msg.lParam);
1115 SCROLL_HandleScrollEvent( hwnd, scrollbar, msg.message, pt );
1117 else
1119 TranslateMessage( &msg );
1120 DispatchMessageW( &msg );
1122 if (!IsWindow( hwnd ))
1124 ReleaseCapture();
1125 break;
1127 } while (msg.message != WM_LBUTTONUP && GetCapture() == hwnd);
1131 /***********************************************************************
1132 * SCROLL_CreateScrollBar
1134 * Create a scroll bar
1136 * PARAMS
1137 * hwnd [I] Handle of window with scrollbar(s)
1138 * lpCreate [I] The style and place of the scroll bar
1140 static void SCROLL_CreateScrollBar(HWND hwnd, LPCREATESTRUCTW lpCreate)
1142 LPSCROLLBAR_INFO info = SCROLL_GetInternalInfo(hwnd, SB_CTL, TRUE);
1143 if (!info) return;
1145 TRACE("hwnd=%p lpCreate=%p\n", hwnd, lpCreate);
1147 if (lpCreate->style & WS_DISABLED)
1149 info->flags = ESB_DISABLE_BOTH;
1150 TRACE("Created WS_DISABLED scrollbar\n");
1154 if (lpCreate->style & (SBS_SIZEGRIP | SBS_SIZEBOX))
1156 if (lpCreate->style & SBS_SIZEBOXTOPLEFTALIGN)
1157 MoveWindow( hwnd, lpCreate->x, lpCreate->y, GetSystemMetrics(SM_CXVSCROLL)+1,
1158 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1159 else if(lpCreate->style & SBS_SIZEBOXBOTTOMRIGHTALIGN)
1160 MoveWindow( hwnd, lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1161 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1162 GetSystemMetrics(SM_CXVSCROLL)+1,
1163 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1165 else if (lpCreate->style & SBS_VERT)
1167 if (lpCreate->style & SBS_LEFTALIGN)
1168 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1169 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1170 else if (lpCreate->style & SBS_RIGHTALIGN)
1171 MoveWindow( hwnd,
1172 lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1173 lpCreate->y,
1174 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1176 else /* SBS_HORZ */
1178 if (lpCreate->style & SBS_TOPALIGN)
1179 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1180 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1181 else if (lpCreate->style & SBS_BOTTOMALIGN)
1182 MoveWindow( hwnd,
1183 lpCreate->x,
1184 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1185 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1190 /*************************************************************************
1191 * SCROLL_GetScrollInfo
1193 * Internal helper for the API function
1195 * PARAMS
1196 * hwnd [I] Handle of window with scrollbar(s)
1197 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1198 * info [IO] fMask specifies which values to retrieve
1200 * RETURNS
1201 * FALSE if requested field not filled (f.i. scroll bar does not exist)
1203 static BOOL SCROLL_GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1205 LPSCROLLBAR_INFO infoPtr;
1207 /* handle invalid data structure */
1208 if (!SCROLL_ScrollInfoValid(info)
1209 || !(infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE)))
1210 return FALSE;
1212 /* fill in the desired scroll info structure */
1213 if (info->fMask & SIF_PAGE) info->nPage = infoPtr->page;
1214 if (info->fMask & SIF_POS) info->nPos = infoPtr->curVal;
1215 if ((info->fMask & SIF_TRACKPOS) && (info->cbSize == sizeof(*info)))
1216 info->nTrackPos = (SCROLL_TrackingWin == WIN_GetFullHandle(hwnd)) ? SCROLL_TrackingVal : infoPtr->curVal;
1217 if (info->fMask & SIF_RANGE)
1219 info->nMin = infoPtr->minVal;
1220 info->nMax = infoPtr->maxVal;
1223 TRACE("cbSize %02x fMask %04x nMin %d nMax %d nPage %u nPos %d nTrackPos %d\n",
1224 info->cbSize, info->fMask, info->nMin, info->nMax, info->nPage,
1225 info->nPos, info->nTrackPos);
1227 return (info->fMask & SIF_ALL) != 0;
1231 /*************************************************************************
1232 * SCROLL_GetScrollBarInfo
1234 * Internal helper for the API function
1236 * PARAMS
1237 * hwnd [I] Handle of window with scrollbar(s)
1238 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1239 * info [IO] cbSize specifies the size of the structure
1241 * RETURNS
1242 * FALSE if failed
1244 static BOOL SCROLL_GetScrollBarInfo(HWND hwnd, LONG idObject, LPSCROLLBARINFO info)
1246 LPSCROLLBAR_INFO infoPtr;
1247 INT nBar;
1248 INT nDummy;
1249 DWORD style = GetWindowLongW(hwnd, GWL_STYLE);
1250 BOOL pressed;
1251 RECT rect;
1253 switch (idObject)
1255 case OBJID_CLIENT: nBar = SB_CTL; break;
1256 case OBJID_HSCROLL: nBar = SB_HORZ; break;
1257 case OBJID_VSCROLL: nBar = SB_VERT; break;
1258 default: return FALSE;
1261 /* handle invalid data structure */
1262 if (info->cbSize != sizeof(*info))
1263 return FALSE;
1265 SCROLL_GetScrollBarRect(hwnd, nBar, &info->rcScrollBar, &nDummy,
1266 &info->dxyLineButton, &info->xyThumbTop);
1267 /* rcScrollBar needs to be in screen coordinates */
1268 GetWindowRect(hwnd, &rect);
1269 OffsetRect(&info->rcScrollBar, rect.left, rect.top);
1271 info->xyThumbBottom = info->xyThumbTop + info->dxyLineButton;
1273 infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, TRUE);
1274 if (!infoPtr)
1275 return FALSE;
1277 /* Scroll bar state */
1278 info->rgstate[0] = 0;
1279 if ((nBar == SB_HORZ && !(style & WS_HSCROLL))
1280 || (nBar == SB_VERT && !(style & WS_VSCROLL)))
1281 info->rgstate[0] |= STATE_SYSTEM_INVISIBLE;
1282 if (infoPtr->minVal >= infoPtr->maxVal - max(infoPtr->page - 1, 0))
1284 if (!(info->rgstate[0] & STATE_SYSTEM_INVISIBLE))
1285 info->rgstate[0] |= STATE_SYSTEM_UNAVAILABLE;
1286 else
1287 info->rgstate[0] |= STATE_SYSTEM_OFFSCREEN;
1289 if (nBar == SB_CTL && !IsWindowEnabled(hwnd))
1290 info->rgstate[0] |= STATE_SYSTEM_UNAVAILABLE;
1292 pressed = ((nBar == SB_VERT) == SCROLL_trackVertical && GetCapture() == hwnd);
1294 /* Top/left arrow button state. MSDN says top/right, but I don't believe it */
1295 info->rgstate[1] = 0;
1296 if (pressed && SCROLL_trackHitTest == SCROLL_TOP_ARROW)
1297 info->rgstate[1] |= STATE_SYSTEM_PRESSED;
1298 if (infoPtr->flags & ESB_DISABLE_LTUP)
1299 info->rgstate[1] |= STATE_SYSTEM_UNAVAILABLE;
1301 /* Page up/left region state. MSDN says up/right, but I don't believe it */
1302 info->rgstate[2] = 0;
1303 if (infoPtr->curVal == infoPtr->minVal)
1304 info->rgstate[2] |= STATE_SYSTEM_INVISIBLE;
1305 if (pressed && SCROLL_trackHitTest == SCROLL_TOP_RECT)
1306 info->rgstate[2] |= STATE_SYSTEM_PRESSED;
1308 /* Thumb state */
1309 info->rgstate[3] = 0;
1310 if (pressed && SCROLL_trackHitTest == SCROLL_THUMB)
1311 info->rgstate[3] |= STATE_SYSTEM_PRESSED;
1313 /* Page down/right region state. MSDN says down/left, but I don't believe it */
1314 info->rgstate[4] = 0;
1315 if (infoPtr->curVal >= infoPtr->maxVal - 1)
1316 info->rgstate[4] |= STATE_SYSTEM_INVISIBLE;
1317 if (pressed && SCROLL_trackHitTest == SCROLL_BOTTOM_RECT)
1318 info->rgstate[4] |= STATE_SYSTEM_PRESSED;
1320 /* Bottom/right arrow button state. MSDN says bottom/left, but I don't believe it */
1321 info->rgstate[5] = 0;
1322 if (pressed && SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW)
1323 info->rgstate[5] |= STATE_SYSTEM_PRESSED;
1324 if (infoPtr->flags & ESB_DISABLE_RTDN)
1325 info->rgstate[5] |= STATE_SYSTEM_UNAVAILABLE;
1327 return TRUE;
1331 /*************************************************************************
1332 * SCROLL_GetScrollPos
1334 * Internal helper for the API function
1336 * PARAMS
1337 * hwnd [I] Handle of window with scrollbar(s)
1338 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1340 static INT SCROLL_GetScrollPos(HWND hwnd, INT nBar)
1342 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1343 return infoPtr ? infoPtr->curVal: 0;
1347 /*************************************************************************
1348 * SCROLL_GetScrollRange
1350 * Internal helper for the API function
1352 * PARAMS
1353 * hwnd [I] Handle of window with scrollbar(s)
1354 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1355 * lpMin [O] Where to store minimum value
1356 * lpMax [O] Where to store maximum value
1358 * RETURNS
1359 * Success: TRUE
1360 * Failure: FALSE
1362 static BOOL SCROLL_GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1364 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1366 if (lpMin) *lpMin = infoPtr ? infoPtr->minVal : 0;
1367 if (lpMax) *lpMax = infoPtr ? infoPtr->maxVal : 0;
1369 return TRUE;
1373 /*************************************************************************
1374 * SCROLL_SetScrollRange
1376 * PARAMS
1377 * hwnd [I] Handle of window with scrollbar(s)
1378 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1379 * lpMin [I] Minimum value
1380 * lpMax [I] Maximum value
1383 static BOOL SCROLL_SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal)
1385 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1387 TRACE("hwnd=%p nBar=%d min=%d max=%d\n", hwnd, nBar, minVal, maxVal);
1389 if (infoPtr)
1391 infoPtr->minVal = minVal;
1392 infoPtr->maxVal = maxVal;
1394 return TRUE;
1398 /***********************************************************************
1399 * ScrollBarWndProc_common
1401 LRESULT ScrollBarWndProc_common( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, BOOL unicode )
1403 if (!IsWindow( hwnd )) return 0;
1405 switch(message)
1407 case WM_CREATE:
1408 SCROLL_CreateScrollBar(hwnd, (LPCREATESTRUCTW)lParam);
1409 break;
1411 case WM_ENABLE:
1413 SCROLLBAR_INFO *infoPtr;
1414 if ((infoPtr = SCROLL_GetInternalInfo( hwnd, SB_CTL, FALSE )))
1416 infoPtr->flags = wParam ? ESB_ENABLE_BOTH : ESB_DISABLE_BOTH;
1417 SCROLL_RefreshScrollBar(hwnd, SB_CTL, TRUE, TRUE);
1420 return 0;
1422 case WM_LBUTTONDBLCLK:
1423 case WM_LBUTTONDOWN:
1424 if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEGRIP)
1426 SendMessageW( GetParent(hwnd), WM_SYSCOMMAND,
1427 SC_SIZE + ((GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_LAYOUTRTL) ?
1428 WMSZ_BOTTOMLEFT : WMSZ_BOTTOMRIGHT), lParam );
1430 else
1432 POINT pt;
1433 pt.x = (short)LOWORD(lParam);
1434 pt.y = (short)HIWORD(lParam);
1435 SCROLL_TrackScrollBar( hwnd, SB_CTL, pt );
1437 break;
1438 case WM_LBUTTONUP:
1439 case WM_MOUSEMOVE:
1440 case WM_SYSTIMER:
1442 POINT pt;
1443 pt.x = (short)LOWORD(lParam);
1444 pt.y = (short)HIWORD(lParam);
1445 SCROLL_HandleScrollEvent( hwnd, SB_CTL, message, pt );
1447 break;
1449 case WM_KEYDOWN:
1450 SCROLL_HandleKbdEvent(hwnd, wParam, lParam);
1451 break;
1453 case WM_KEYUP:
1454 ShowCaret(hwnd);
1455 break;
1457 case WM_SETFOCUS:
1459 /* Create a caret when a ScrollBar get focus */
1460 RECT rect;
1461 int arrowSize, thumbSize, thumbPos, vertical;
1462 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,
1463 &arrowSize, &thumbSize, &thumbPos );
1464 if (!vertical)
1466 CreateCaret(hwnd, (HBITMAP)1, thumbSize-2, rect.bottom-rect.top-2);
1467 SetCaretPos(thumbPos+1, rect.top+1);
1469 else
1471 CreateCaret(hwnd, (HBITMAP)1, rect.right-rect.left-2,thumbSize-2);
1472 SetCaretPos(rect.top+1, thumbPos+1);
1474 ShowCaret(hwnd);
1476 break;
1478 case WM_KILLFOCUS:
1480 RECT rect;
1481 int arrowSize, thumbSize, thumbPos, vertical;
1482 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,&arrowSize, &thumbSize, &thumbPos );
1483 if (!vertical){
1484 rect.left=thumbPos+1;
1485 rect.right=rect.left+thumbSize;
1487 else
1489 rect.top=thumbPos+1;
1490 rect.bottom=rect.top+thumbSize;
1492 HideCaret(hwnd);
1493 InvalidateRect(hwnd,&rect,0);
1494 DestroyCaret();
1496 break;
1498 case WM_ERASEBKGND:
1499 return 1;
1501 case WM_GETDLGCODE:
1502 return DLGC_WANTARROWS; /* Windows returns this value */
1504 case WM_PAINT:
1506 PAINTSTRUCT ps;
1507 HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
1508 if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEGRIP)
1510 SCROLL_DrawSizeGrip( hwnd, hdc);
1512 else if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEBOX)
1514 RECT rc;
1515 GetClientRect( hwnd, &rc );
1516 FillRect( hdc, &rc, GetSysColorBrush(COLOR_SCROLLBAR) );
1518 else
1519 SCROLL_DrawScrollBar( hwnd, hdc, SB_CTL, TRUE, TRUE );
1520 if (!wParam) EndPaint(hwnd, &ps);
1522 break;
1524 case WM_SETCURSOR:
1525 if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEGRIP)
1527 ULONG_PTR cursor = (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_LAYOUTRTL) ? IDC_SIZENESW : IDC_SIZENWSE;
1528 return (LRESULT)SetCursor( LoadCursorA( 0, (LPSTR)cursor ));
1530 return DefWindowProcW( hwnd, message, wParam, lParam );
1532 case SBM_SETPOS:
1533 return SetScrollPos( hwnd, SB_CTL, wParam, (BOOL)lParam );
1535 case SBM_GETPOS:
1536 return SCROLL_GetScrollPos(hwnd, SB_CTL);
1538 case SBM_SETRANGEREDRAW:
1539 case SBM_SETRANGE:
1541 INT oldPos = SCROLL_GetScrollPos( hwnd, SB_CTL );
1542 SCROLL_SetScrollRange( hwnd, SB_CTL, wParam, lParam );
1543 if (message == SBM_SETRANGEREDRAW)
1544 SCROLL_RefreshScrollBar( hwnd, SB_CTL, TRUE, TRUE );
1545 if (oldPos != SCROLL_GetScrollPos( hwnd, SB_CTL )) return oldPos;
1547 return 0;
1549 case SBM_GETRANGE:
1550 return SCROLL_GetScrollRange(hwnd, SB_CTL, (LPINT)wParam, (LPINT)lParam);
1552 case SBM_ENABLE_ARROWS:
1553 return EnableScrollBar( hwnd, SB_CTL, wParam );
1555 case SBM_SETSCROLLINFO:
1556 return SCROLL_SetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam, wParam );
1558 case SBM_GETSCROLLINFO:
1559 return SCROLL_GetScrollInfo(hwnd, SB_CTL, (SCROLLINFO *)lParam);
1561 case SBM_GETSCROLLBARINFO:
1562 return SCROLL_GetScrollBarInfo(hwnd, OBJID_CLIENT, (SCROLLBARINFO *)lParam);
1564 case 0x00e5:
1565 case 0x00e7:
1566 case 0x00e8:
1567 case 0x00ec:
1568 case 0x00ed:
1569 case 0x00ee:
1570 case 0x00ef:
1571 ERR("unknown Win32 msg %04x wp=%08lx lp=%08lx\n",
1572 message, wParam, lParam );
1573 break;
1575 default:
1576 if (message >= WM_USER)
1577 WARN("unknown msg %04x wp=%04lx lp=%08lx\n",
1578 message, wParam, lParam );
1579 if (unicode)
1580 return DefWindowProcW( hwnd, message, wParam, lParam );
1581 else
1582 return DefWindowProcA( hwnd, message, wParam, lParam );
1584 return 0;
1588 /*************************************************************************
1589 * SetScrollInfo (USER32.@)
1591 * SetScrollInfo can be used to set the position, upper bound,
1592 * lower bound, and page size of a scrollbar control.
1594 * PARAMS
1595 * hwnd [I] Handle of window with scrollbar(s)
1596 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1597 * info [I] Specifies what to change and new values
1598 * bRedraw [I] Should scrollbar be redrawn afterwards?
1600 * RETURNS
1601 * Scrollbar position
1603 * NOTE
1604 * For 100 lines of text to be displayed in a window of 25 lines,
1605 * one would for instance use info->nMin=0, info->nMax=75
1606 * (corresponding to the 76 different positions of the window on
1607 * the text), and info->nPage=25.
1609 INT WINAPI DECLSPEC_HOTPATCH SetScrollInfo(HWND hwnd, INT nBar, const SCROLLINFO *info, BOOL bRedraw)
1611 TRACE("hwnd=%p nBar=%d info=%p, bRedraw=%d\n", hwnd, nBar, info, bRedraw);
1613 /* Refer SB_CTL requests to the window */
1614 if (nBar == SB_CTL)
1615 return SendMessageW(hwnd, SBM_SETSCROLLINFO, bRedraw, (LPARAM)info);
1616 else
1617 return SCROLL_SetScrollInfo( hwnd, nBar, info, bRedraw );
1620 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar, LPCSCROLLINFO info, BOOL bRedraw )
1622 /* Update the scrollbar state and set action flags according to
1623 * what has to be done graphics wise. */
1625 SCROLLBAR_INFO *infoPtr;
1626 UINT new_flags;
1627 INT action = 0;
1629 /* handle invalid data structure */
1630 if (!SCROLL_ScrollInfoValid(info)
1631 || !(infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, TRUE)))
1632 return 0;
1634 if (TRACE_ON(scroll))
1636 TRACE("hwnd=%p bar=%d", hwnd, nBar);
1637 if (info->fMask & SIF_PAGE) TRACE( " page=%d", info->nPage );
1638 if (info->fMask & SIF_POS) TRACE( " pos=%d", info->nPos );
1639 if (info->fMask & SIF_RANGE) TRACE( " min=%d max=%d", info->nMin, info->nMax );
1640 TRACE("\n");
1643 /* Set the page size */
1645 if (info->fMask & SIF_PAGE)
1647 if( infoPtr->page != info->nPage )
1649 infoPtr->page = info->nPage;
1650 action |= SA_SSI_REFRESH;
1654 /* Set the scroll pos */
1656 if (info->fMask & SIF_POS)
1658 if( infoPtr->curVal != info->nPos )
1660 infoPtr->curVal = info->nPos;
1661 action |= SA_SSI_REFRESH;
1665 /* Set the scroll range */
1667 if (info->fMask & SIF_RANGE)
1669 /* Invalid range -> range is set to (0,0) */
1670 if ((info->nMin > info->nMax) ||
1671 ((UINT)(info->nMax - info->nMin) >= 0x80000000))
1673 action |= SA_SSI_REFRESH;
1674 infoPtr->minVal = 0;
1675 infoPtr->maxVal = 0;
1677 else
1679 if( infoPtr->minVal != info->nMin ||
1680 infoPtr->maxVal != info->nMax )
1682 action |= SA_SSI_REFRESH;
1683 infoPtr->minVal = info->nMin;
1684 infoPtr->maxVal = info->nMax;
1689 /* Make sure the page size is valid */
1690 if (infoPtr->page < 0) infoPtr->page = 0;
1691 else if (infoPtr->page > infoPtr->maxVal - infoPtr->minVal + 1 )
1692 infoPtr->page = infoPtr->maxVal - infoPtr->minVal + 1;
1694 /* Make sure the pos is inside the range */
1696 if (infoPtr->curVal < infoPtr->minVal)
1697 infoPtr->curVal = infoPtr->minVal;
1698 else if (infoPtr->curVal > infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1699 infoPtr->curVal = infoPtr->maxVal - max( infoPtr->page-1, 0 );
1701 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1702 infoPtr->page, infoPtr->curVal,
1703 infoPtr->minVal, infoPtr->maxVal );
1705 /* don't change the scrollbar state if SetScrollInfo
1706 * is just called with SIF_DISABLENOSCROLL
1708 if(!(info->fMask & SIF_ALL)) goto done;
1710 /* Check if the scrollbar should be hidden or disabled */
1712 if (info->fMask & (SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL))
1714 new_flags = infoPtr->flags;
1715 if (infoPtr->minVal >= infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1717 /* Hide or disable scroll-bar */
1718 if (info->fMask & SIF_DISABLENOSCROLL)
1720 new_flags = ESB_DISABLE_BOTH;
1721 action |= SA_SSI_REFRESH;
1723 else if ((nBar != SB_CTL) && (action & SA_SSI_REFRESH))
1725 action = SA_SSI_HIDE;
1728 else /* Show and enable scroll-bar only if no page only changed. */
1729 if (info->fMask != SIF_PAGE)
1731 new_flags = ESB_ENABLE_BOTH;
1732 if ((nBar != SB_CTL) && ( (action & SA_SSI_REFRESH) ))
1733 action |= SA_SSI_SHOW;
1736 if (infoPtr->flags != new_flags) /* check arrow flags */
1738 infoPtr->flags = new_flags;
1739 action |= SA_SSI_REPAINT_ARROWS;
1743 done:
1744 if( action & SA_SSI_HIDE )
1745 SCROLL_ShowScrollBar( hwnd, nBar, FALSE, FALSE );
1746 else
1748 if( action & SA_SSI_SHOW )
1749 if( SCROLL_ShowScrollBar( hwnd, nBar, TRUE, TRUE ) )
1750 return infoPtr->curVal; /* SetWindowPos() already did the painting */
1752 if( bRedraw )
1753 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
1754 else if( action & SA_SSI_REPAINT_ARROWS )
1755 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, FALSE );
1758 /* Return current position */
1759 return infoPtr->curVal;
1763 /*************************************************************************
1764 * GetScrollInfo (USER32.@)
1766 * GetScrollInfo can be used to retrieve the position, upper bound,
1767 * lower bound, and page size of a scrollbar control.
1769 * PARAMS
1770 * hwnd [I] Handle of window with scrollbar(s)
1771 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1772 * info [IO] fMask specifies which values to retrieve
1774 * RETURNS
1775 * TRUE if SCROLLINFO is filled
1776 * ( if nBar is SB_CTL, GetScrollInfo returns TRUE even if nothing
1777 * is filled)
1779 BOOL WINAPI DECLSPEC_HOTPATCH GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1781 TRACE("hwnd=%p nBar=%d info=%p\n", hwnd, nBar, info);
1783 /* Refer SB_CTL requests to the window */
1784 if (nBar == SB_CTL)
1786 SendMessageW(hwnd, SBM_GETSCROLLINFO, 0, (LPARAM)info);
1787 return TRUE;
1789 return SCROLL_GetScrollInfo(hwnd, nBar, info);
1793 /*************************************************************************
1794 * GetScrollBarInfo (USER32.@)
1796 * GetScrollBarInfo can be used to retrieve information about a scrollbar
1797 * control.
1799 * PARAMS
1800 * hwnd [I] Handle of window with scrollbar(s)
1801 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1802 * info [IO] cbSize specifies the size of SCROLLBARINFO
1804 * RETURNS
1805 * TRUE if success
1807 BOOL WINAPI GetScrollBarInfo(HWND hwnd, LONG idObject, LPSCROLLBARINFO info)
1809 TRACE("hwnd=%p idObject=%d info=%p\n", hwnd, idObject, info);
1811 /* Refer OBJID_CLIENT requests to the window */
1812 if (idObject == OBJID_CLIENT)
1813 return SendMessageW(hwnd, SBM_GETSCROLLBARINFO, 0, (LPARAM)info);
1814 else
1815 return SCROLL_GetScrollBarInfo(hwnd, idObject, info);
1819 /*************************************************************************
1820 * SetScrollPos (USER32.@)
1822 * Sets the current position of the scroll thumb.
1824 * PARAMS
1825 * hwnd [I] Handle of window with scrollbar(s)
1826 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1827 * nPos [I] New value
1828 * bRedraw [I] Should scrollbar be redrawn afterwards?
1830 * RETURNS
1831 * Success: Scrollbar position
1832 * Failure: 0
1834 * REMARKS
1835 * Note the ambiguity when 0 is returned. Use GetLastError
1836 * to make sure there was an error (and to know which one).
1838 INT WINAPI DECLSPEC_HOTPATCH SetScrollPos( HWND hwnd, INT nBar, INT nPos, BOOL bRedraw)
1840 SCROLLINFO info;
1841 SCROLLBAR_INFO *infoPtr;
1842 INT oldPos;
1844 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, FALSE ))) return 0;
1845 oldPos = infoPtr->curVal;
1846 info.cbSize = sizeof(info);
1847 info.nPos = nPos;
1848 info.fMask = SIF_POS;
1849 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1850 return oldPos;
1854 /*************************************************************************
1855 * GetScrollPos (USER32.@)
1857 * Gets the current position of the scroll thumb.
1859 * PARAMS
1860 * hwnd [I] Handle of window with scrollbar(s)
1861 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1863 * RETURNS
1864 * Success: Current position
1865 * Failure: 0
1867 * REMARKS
1868 * There is ambiguity when 0 is returned. Use GetLastError
1869 * to make sure there was an error (and to know which one).
1871 INT WINAPI DECLSPEC_HOTPATCH GetScrollPos(HWND hwnd, INT nBar)
1873 TRACE("hwnd=%p nBar=%d\n", hwnd, nBar);
1875 /* Refer SB_CTL requests to the window */
1876 if (nBar == SB_CTL)
1877 return SendMessageW(hwnd, SBM_GETPOS, 0, 0);
1878 else
1879 return SCROLL_GetScrollPos(hwnd, nBar);
1883 /*************************************************************************
1884 * SetScrollRange (USER32.@)
1885 * The SetScrollRange function sets the minimum and maximum scroll box positions
1886 * If nMinPos and nMaxPos is the same value, the scroll bar will hide
1888 * Sets the range of the scroll bar.
1890 * PARAMS
1891 * hwnd [I] Handle of window with scrollbar(s)
1892 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1893 * minVal [I] New minimum value
1894 * maxVal [I] New Maximum value
1895 * bRedraw [I] Should scrollbar be redrawn afterwards?
1897 * RETURNS
1898 * Success: TRUE
1899 * Failure: FALSE
1901 BOOL WINAPI DECLSPEC_HOTPATCH SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal, BOOL bRedraw)
1903 SCROLLINFO info;
1905 TRACE("hwnd=%p nBar=%d min=%d max=%d, bRedraw=%d\n", hwnd, nBar, minVal, maxVal, bRedraw);
1907 info.cbSize = sizeof(info);
1908 info.fMask = SIF_RANGE;
1909 info.nMin = minVal;
1910 info.nMax = maxVal;
1911 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1912 return TRUE;
1916 /*************************************************************************
1917 * GetScrollRange (USER32.@)
1919 * Gets the range of the scroll bar.
1921 * PARAMS
1922 * hwnd [I] Handle of window with scrollbar(s)
1923 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1924 * lpMin [O] Where to store minimum value
1925 * lpMax [O] Where to store maximum value
1927 * RETURNS
1928 * TRUE if values is filled
1930 BOOL WINAPI DECLSPEC_HOTPATCH GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1932 TRACE("hwnd=%p nBar=%d lpMin=%p lpMax=%p\n", hwnd, nBar, lpMin, lpMax);
1934 /* Refer SB_CTL requests to the window */
1935 if (nBar == SB_CTL)
1936 SendMessageW(hwnd, SBM_GETRANGE, (WPARAM)lpMin, (LPARAM)lpMax);
1937 else
1938 SCROLL_GetScrollRange(hwnd, nBar, lpMin, lpMax);
1940 return TRUE;
1944 /*************************************************************************
1945 * SCROLL_ShowScrollBar()
1947 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1949 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar, BOOL fShowH, BOOL fShowV )
1951 ULONG old_style, set_bits = 0, clear_bits = 0;
1953 TRACE("hwnd=%p bar=%d horz=%d, vert=%d\n", hwnd, nBar, fShowH, fShowV );
1955 switch(nBar)
1957 case SB_CTL:
1958 ShowWindow( hwnd, fShowH ? SW_SHOW : SW_HIDE );
1959 return TRUE;
1961 case SB_BOTH:
1962 case SB_HORZ:
1963 if (fShowH) set_bits |= WS_HSCROLL;
1964 else clear_bits |= WS_HSCROLL;
1965 if( nBar == SB_HORZ ) break;
1966 /* fall through */
1967 case SB_VERT:
1968 if (fShowV) set_bits |= WS_VSCROLL;
1969 else clear_bits |= WS_VSCROLL;
1970 break;
1972 default:
1973 return FALSE; /* Nothing to do! */
1976 old_style = WIN_SetStyle( hwnd, set_bits, clear_bits );
1977 if ((old_style & clear_bits) != 0 || (old_style & set_bits) != set_bits)
1979 /* frame has been changed, let the window redraw itself */
1980 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
1981 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
1982 return TRUE;
1984 return FALSE; /* no frame changes */
1988 /*************************************************************************
1989 * ShowScrollBar (USER32.@)
1991 * Shows or hides the scroll bar.
1993 * PARAMS
1994 * hwnd [I] Handle of window with scrollbar(s)
1995 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1996 * fShow [I] TRUE = show, FALSE = hide
1998 * RETURNS
1999 * Success: TRUE
2000 * Failure: FALSE
2002 BOOL WINAPI DECLSPEC_HOTPATCH ShowScrollBar(HWND hwnd, INT nBar, BOOL fShow)
2004 if ( !hwnd )
2005 return FALSE;
2007 SCROLL_ShowScrollBar( hwnd, nBar, (nBar == SB_VERT) ? 0 : fShow,
2008 (nBar == SB_HORZ) ? 0 : fShow );
2009 return TRUE;
2013 /*************************************************************************
2014 * EnableScrollBar (USER32.@)
2016 * Enables or disables the scroll bars.
2018 BOOL WINAPI DECLSPEC_HOTPATCH EnableScrollBar( HWND hwnd, UINT nBar, UINT flags )
2020 BOOL bFineWithMe;
2021 SCROLLBAR_INFO *infoPtr;
2023 flags &= ESB_DISABLE_BOTH;
2025 if (nBar == SB_BOTH)
2027 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, SB_VERT, TRUE ))) return FALSE;
2028 if (!(bFineWithMe = (infoPtr->flags == flags)) )
2030 infoPtr->flags = flags;
2031 SCROLL_RefreshScrollBar( hwnd, SB_VERT, TRUE, TRUE );
2033 nBar = SB_HORZ;
2035 else
2036 bFineWithMe = nBar != SB_CTL;
2038 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, TRUE ))) return FALSE;
2039 if (bFineWithMe && infoPtr->flags == flags) return FALSE;
2040 infoPtr->flags = flags;
2042 if (nBar == SB_CTL && (flags == ESB_DISABLE_BOTH || flags == ESB_ENABLE_BOTH))
2043 EnableWindow(hwnd, flags == ESB_ENABLE_BOTH);
2045 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
2046 return TRUE;