ntdll/tests: Add some tests for opening objects through symlinks.
[wine.git] / dlls / user32 / scroll.c
blobb28ee4471809e6d8d6a6caba7f85fb8b2ee3f655
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 rect.left -= scrollbarWidth*8;
364 rect.right += scrollbarWidth*8;
365 rect.top -= scrollbarWidth*2;
366 rect.bottom += scrollbarWidth*2;
368 else
370 scrollbarWidth = lpRect->bottom - lpRect->top;
371 rect.left -= scrollbarWidth*2;
372 rect.right += scrollbarWidth*2;
373 rect.top -= scrollbarWidth*8;
374 rect.bottom += scrollbarWidth*8;
376 return PtInRect( &rect, pt );
379 /***********************************************************************
380 * SCROLL_ClipPos
382 static POINT SCROLL_ClipPos( LPRECT lpRect, POINT pt )
384 if( pt.x < lpRect->left )
385 pt.x = lpRect->left;
386 else
387 if( pt.x > lpRect->right )
388 pt.x = lpRect->right;
390 if( pt.y < lpRect->top )
391 pt.y = lpRect->top;
392 else
393 if( pt.y > lpRect->bottom )
394 pt.y = lpRect->bottom;
396 return pt;
400 /***********************************************************************
401 * SCROLL_HitTest
403 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
405 static enum SCROLL_HITTEST SCROLL_HitTest( HWND hwnd, INT nBar,
406 POINT pt, BOOL bDragging )
408 INT arrowSize, thumbSize, thumbPos;
409 RECT rect;
411 BOOL vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
412 &arrowSize, &thumbSize, &thumbPos );
414 if ( (bDragging && !SCROLL_PtInRectEx( &rect, pt, vertical )) ||
415 (!PtInRect( &rect, pt )) ) return SCROLL_NOWHERE;
417 if (vertical)
419 if (pt.y < rect.top + arrowSize) return SCROLL_TOP_ARROW;
420 if (pt.y >= rect.bottom - arrowSize) return SCROLL_BOTTOM_ARROW;
421 if (!thumbPos) return SCROLL_TOP_RECT;
422 pt.y -= rect.top;
423 if (pt.y < thumbPos) return SCROLL_TOP_RECT;
424 if (pt.y >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
426 else /* horizontal */
428 if (pt.x < rect.left + arrowSize) return SCROLL_TOP_ARROW;
429 if (pt.x >= rect.right - arrowSize) return SCROLL_BOTTOM_ARROW;
430 if (!thumbPos) return SCROLL_TOP_RECT;
431 pt.x -= rect.left;
432 if (pt.x < thumbPos) return SCROLL_TOP_RECT;
433 if (pt.x >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
435 return SCROLL_THUMB;
439 /***********************************************************************
440 * SCROLL_DrawArrows
442 * Draw the scroll bar arrows.
444 static void SCROLL_DrawArrows( HDC hdc, SCROLLBAR_INFO *infoPtr,
445 RECT *rect, INT arrowSize, BOOL vertical,
446 BOOL top_pressed, BOOL bottom_pressed )
448 RECT r;
450 r = *rect;
451 if( vertical )
452 r.bottom = r.top + arrowSize;
453 else
454 r.right = r.left + arrowSize;
456 DrawFrameControl( hdc, &r, DFC_SCROLL,
457 (vertical ? DFCS_SCROLLUP : DFCS_SCROLLLEFT)
458 | (top_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
459 | (infoPtr->flags&ESB_DISABLE_LTUP ? DFCS_INACTIVE : 0 ) );
461 r = *rect;
462 if( vertical )
463 r.top = r.bottom-arrowSize;
464 else
465 r.left = r.right-arrowSize;
467 DrawFrameControl( hdc, &r, DFC_SCROLL,
468 (vertical ? DFCS_SCROLLDOWN : DFCS_SCROLLRIGHT)
469 | (bottom_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
470 | (infoPtr->flags&ESB_DISABLE_RTDN ? DFCS_INACTIVE : 0) );
473 static void SCROLL_DrawMovingThumb( HDC hdc, RECT *rect, BOOL vertical,
474 INT arrowSize, INT thumbSize )
476 INT pos = SCROLL_TrackingPos;
477 INT max_size;
479 if( vertical )
480 max_size = rect->bottom - rect->top;
481 else
482 max_size = rect->right - rect->left;
484 max_size -= (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) + thumbSize;
486 if( pos < (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) )
487 pos = (arrowSize-SCROLL_ARROW_THUMB_OVERLAP);
488 else if( pos > max_size )
489 pos = max_size;
491 SCROLL_DrawInterior_9x( SCROLL_TrackingWin, hdc, SCROLL_TrackingBar,
492 rect, arrowSize, thumbSize, pos,
493 0, vertical, FALSE, FALSE );
495 SCROLL_MovingThumb = !SCROLL_MovingThumb;
498 /***********************************************************************
499 * SCROLL_DrawInterior
501 * Draw the scroll bar interior (everything except the arrows).
503 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
504 RECT *rect, INT arrowSize,
505 INT thumbSize, INT thumbPos,
506 UINT flags, BOOL vertical,
507 BOOL top_selected, BOOL bottom_selected )
509 RECT r;
510 HPEN hSavePen;
511 HBRUSH hSaveBrush,hBrush;
513 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
514 * The window-owned scrollbars need to call DEFWND_ControlColor
515 * to correctly setup default scrollbar colors
517 if (nBar == SB_CTL)
519 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
520 (WPARAM)hdc,(LPARAM)hwnd);
522 else
524 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
527 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
528 hSaveBrush = SelectObject( hdc, hBrush );
530 /* Calculate the scroll rectangle */
531 r = *rect;
532 if (vertical)
534 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
535 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
537 else
539 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
540 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
543 /* Draw the scroll rectangles and thumb */
544 if (!thumbPos) /* No thumb to draw */
546 PatBlt( hdc, r.left, r.top,
547 r.right - r.left, r.bottom - r.top,
548 PATCOPY );
550 /* cleanup and return */
551 SelectObject( hdc, hSavePen );
552 SelectObject( hdc, hSaveBrush );
553 return;
556 if (vertical)
558 PatBlt( hdc, r.left, r.top,
559 r.right - r.left,
560 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
561 top_selected ? 0x0f0000 : PATCOPY );
562 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
563 PatBlt( hdc, r.left, r.top + thumbSize,
564 r.right - r.left,
565 r.bottom - r.top - thumbSize,
566 bottom_selected ? 0x0f0000 : PATCOPY );
567 r.bottom = r.top + thumbSize;
569 else /* horizontal */
571 PatBlt( hdc, r.left, r.top,
572 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
573 r.bottom - r.top,
574 top_selected ? 0x0f0000 : PATCOPY );
575 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
576 PatBlt( hdc, r.left + thumbSize, r.top,
577 r.right - r.left - thumbSize,
578 r.bottom - r.top,
579 bottom_selected ? 0x0f0000 : PATCOPY );
580 r.right = r.left + thumbSize;
583 /* Draw the thumb */
584 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT | BF_MIDDLE );
586 /* cleanup */
587 SelectObject( hdc, hSavePen );
588 SelectObject( hdc, hSaveBrush );
592 static void SCROLL_DrawInterior( HWND hwnd, HDC hdc, INT nBar,
593 RECT *rect, INT arrowSize,
594 INT thumbSize, INT thumbPos,
595 UINT flags, BOOL vertical,
596 BOOL top_selected, BOOL bottom_selected )
598 RECT r;
599 HPEN hSavePen;
600 HBRUSH hSaveBrush,hBrush;
601 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
603 if (Save_SCROLL_MovingThumb &&
604 (SCROLL_TrackingWin == hwnd) &&
605 (SCROLL_TrackingBar == nBar))
606 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
608 /* Select the correct brush and pen */
610 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
611 * The window-owned scrollbars need to call DEFWND_ControlColor
612 * to correctly setup default scrollbar colors
614 if (nBar == SB_CTL) {
615 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
616 (WPARAM)hdc,(LPARAM)hwnd);
617 } else {
618 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
620 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
621 hSaveBrush = SelectObject( hdc, hBrush );
623 /* Calculate the scroll rectangle */
625 r = *rect;
626 if (vertical)
628 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
629 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
631 else
633 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
634 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
637 /* Draw the scroll bar frame */
639 /* Draw the scroll rectangles and thumb */
641 if (!thumbPos) /* No thumb to draw */
643 PatBlt( hdc, r.left, r.top, r.right - r.left, r.bottom - r.top, PATCOPY );
645 /* cleanup and return */
646 SelectObject( hdc, hSavePen );
647 SelectObject( hdc, hSaveBrush );
648 return;
651 if (vertical)
653 PatBlt( hdc, r.left, r.top, r.right - r.left,
654 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
655 top_selected ? 0x0f0000 : PATCOPY );
656 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
657 PatBlt( hdc, r.left, r.top + thumbSize, r.right - r.left,
658 r.bottom - r.top - thumbSize,
659 bottom_selected ? 0x0f0000 : PATCOPY );
660 r.bottom = r.top + thumbSize;
662 else /* horizontal */
664 PatBlt( hdc, r.left, r.top,
665 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
666 r.bottom - r.top, top_selected ? 0x0f0000 : PATCOPY );
667 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
668 PatBlt( hdc, r.left + thumbSize, r.top, r.right - r.left - thumbSize,
669 r.bottom - r.top, bottom_selected ? 0x0f0000 : PATCOPY );
670 r.right = r.left + thumbSize;
673 /* Draw the thumb */
675 SelectObject( hdc, GetSysColorBrush(COLOR_BTNFACE) );
676 Rectangle( hdc, r.left+1, r.top+1, r.right-1, r.bottom-1 );
677 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT );
679 if (Save_SCROLL_MovingThumb &&
680 (SCROLL_TrackingWin == hwnd) &&
681 (SCROLL_TrackingBar == nBar))
682 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
684 /* cleanup */
685 SelectObject( hdc, hSavePen );
686 SelectObject( hdc, hSaveBrush );
690 /***********************************************************************
691 * SCROLL_DrawScrollBar
693 * Redraw the whole scrollbar.
695 void SCROLL_DrawScrollBar( HWND hwnd, HDC hdc, INT nBar,
696 BOOL arrows, BOOL interior )
698 INT arrowSize, thumbSize, thumbPos;
699 RECT rect;
700 BOOL vertical;
701 SCROLLBAR_INFO *infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, TRUE );
702 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
703 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
705 if (!(hwnd = WIN_GetFullHandle( hwnd ))) return;
707 if (!infoPtr ||
708 ((nBar == SB_VERT) && !(style & WS_VSCROLL)) ||
709 ((nBar == SB_HORZ) && !(style & WS_HSCROLL))) return;
710 if (!WIN_IsWindowDrawable( hwnd, FALSE )) return;
712 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
713 &arrowSize, &thumbSize, &thumbPos );
715 /* do not draw if the scrollbar rectangle is empty */
716 if(IsRectEmpty(&rect)) return;
718 if (Save_SCROLL_MovingThumb &&
719 (SCROLL_TrackingWin == hwnd) &&
720 (SCROLL_TrackingBar == nBar))
721 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
723 /* Draw the arrows */
725 if (arrows && arrowSize)
727 if( vertical == SCROLL_trackVertical && GetCapture() == hwnd )
728 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
729 (SCROLL_trackHitTest == SCROLL_TOP_ARROW),
730 (SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW) );
731 else
732 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
733 FALSE, FALSE );
735 if( interior )
736 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
737 thumbPos, infoPtr->flags, vertical, FALSE, FALSE );
739 if (Save_SCROLL_MovingThumb &&
740 (SCROLL_TrackingWin == hwnd) &&
741 (SCROLL_TrackingBar == nBar))
742 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
744 /* if scroll bar has focus, reposition the caret */
745 if(hwnd==GetFocus() && (nBar==SB_CTL))
747 if (!vertical)
749 SetCaretPos(thumbPos+1, rect.top+1);
751 else
753 SetCaretPos(rect.top+1, thumbPos+1);
758 /***********************************************************************
759 * SCROLL_DrawSizeGrip
761 * Draw the size grip.
763 static void SCROLL_DrawSizeGrip( HWND hwnd, HDC hdc)
765 RECT rc;
767 GetClientRect( hwnd, &rc );
768 FillRect( hdc, &rc, GetSysColorBrush(COLOR_SCROLLBAR) );
769 rc.left = max( rc.left, rc.right - GetSystemMetrics(SM_CXVSCROLL) - 1 );
770 rc.top = max( rc.top, rc.bottom - GetSystemMetrics(SM_CYHSCROLL) - 1 );
771 DrawFrameControl( hdc, &rc, DFC_SCROLL, DFCS_SCROLLSIZEGRIP );
775 /***********************************************************************
776 * SCROLL_RefreshScrollBar
778 * Repaint the scroll bar interior after a SetScrollRange() or
779 * SetScrollPos() call.
781 static void SCROLL_RefreshScrollBar( HWND hwnd, INT nBar,
782 BOOL arrows, BOOL interior )
784 HDC hdc = GetDCEx( hwnd, 0,
785 DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW) );
786 if (!hdc) return;
788 SCROLL_DrawScrollBar( hwnd, hdc, nBar, arrows, interior );
789 ReleaseDC( hwnd, hdc );
793 /***********************************************************************
794 * SCROLL_HandleKbdEvent
796 * Handle a keyboard event (only for SB_CTL scrollbars with focus).
798 * PARAMS
799 * hwnd [I] Handle of window with scrollbar(s)
800 * wParam [I] Variable input including enable state
801 * lParam [I] Variable input including input point
803 static void SCROLL_HandleKbdEvent(HWND hwnd, WPARAM wParam, LPARAM lParam)
805 TRACE("hwnd=%p wParam=%ld lParam=%ld\n", hwnd, wParam, lParam);
807 /* hide caret on first KEYDOWN to prevent flicker */
808 if ((lParam & PFD_DOUBLEBUFFER_DONTCARE) == 0)
809 HideCaret(hwnd);
811 switch(wParam)
813 case VK_PRIOR: wParam = SB_PAGEUP; break;
814 case VK_NEXT: wParam = SB_PAGEDOWN; break;
815 case VK_HOME: wParam = SB_TOP; break;
816 case VK_END: wParam = SB_BOTTOM; break;
817 case VK_UP: wParam = SB_LINEUP; break;
818 case VK_DOWN: wParam = SB_LINEDOWN; break;
819 case VK_LEFT: wParam = SB_LINEUP; break;
820 case VK_RIGHT: wParam = SB_LINEDOWN; break;
821 default: return;
823 SendMessageW(GetParent(hwnd),
824 ((GetWindowLongW( hwnd, GWL_STYLE ) & SBS_VERT) ?
825 WM_VSCROLL : WM_HSCROLL), wParam, (LPARAM)hwnd);
829 /***********************************************************************
830 * SCROLL_HandleScrollEvent
832 * Handle a mouse or timer event for the scrollbar.
833 * 'pt' is the location of the mouse event in client (for SB_CTL) or
834 * windows coordinates.
836 static void SCROLL_HandleScrollEvent( HWND hwnd, INT nBar, UINT msg, POINT pt)
838 /* Previous mouse position for timer events */
839 static POINT prevPt;
840 /* Thumb position when tracking started. */
841 static UINT trackThumbPos;
842 /* Position in the scroll-bar of the last button-down event. */
843 static INT lastClickPos;
844 /* Position in the scroll-bar of the last mouse event. */
845 static INT lastMousePos;
847 enum SCROLL_HITTEST hittest;
848 HWND hwndOwner, hwndCtl;
849 BOOL vertical;
850 INT arrowSize, thumbSize, thumbPos;
851 RECT rect;
852 HDC hdc;
854 SCROLLBAR_INFO *infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, FALSE );
855 if (!infoPtr) return;
856 if ((SCROLL_trackHitTest == SCROLL_NOWHERE) && (msg != WM_LBUTTONDOWN))
857 return;
859 if (nBar == SB_CTL && (GetWindowLongW( hwnd, GWL_STYLE ) & (SBS_SIZEGRIP | SBS_SIZEBOX)))
861 switch(msg)
863 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
864 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
865 SetCapture( hwnd );
866 prevPt = pt;
867 SCROLL_trackHitTest = hittest = SCROLL_THUMB;
868 break;
869 case WM_MOUSEMOVE:
870 GetClientRect(GetParent(GetParent(hwnd)),&rect);
871 prevPt = pt;
872 break;
873 case WM_LBUTTONUP:
874 ReleaseCapture();
875 SCROLL_trackHitTest = hittest = SCROLL_NOWHERE;
876 if (hwnd==GetFocus()) ShowCaret(hwnd);
877 break;
878 case WM_SYSTIMER:
879 pt = prevPt;
880 break;
882 return;
885 hdc = GetDCEx( hwnd, 0, DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW));
886 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
887 &arrowSize, &thumbSize, &thumbPos );
888 hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd) : hwnd;
889 hwndCtl = (nBar == SB_CTL) ? hwnd : 0;
891 switch(msg)
893 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
894 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
895 SCROLL_trackVertical = vertical;
896 SCROLL_trackHitTest = hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
897 lastClickPos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
898 lastMousePos = lastClickPos;
899 trackThumbPos = thumbPos;
900 prevPt = pt;
901 if (nBar == SB_CTL && (GetWindowLongW(hwnd, GWL_STYLE) & WS_TABSTOP)) SetFocus( hwnd );
902 SetCapture( hwnd );
903 break;
905 case WM_MOUSEMOVE:
906 hittest = SCROLL_HitTest( hwnd, nBar, pt, TRUE );
907 prevPt = pt;
908 break;
910 case WM_LBUTTONUP:
911 hittest = SCROLL_NOWHERE;
912 ReleaseCapture();
913 /* if scrollbar has focus, show back caret */
914 if (hwnd==GetFocus()) ShowCaret(hwnd);
915 break;
917 case WM_SYSTIMER:
918 pt = prevPt;
919 hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
920 break;
922 default:
923 return; /* Should never happen */
926 TRACE("Event: hwnd=%p bar=%d msg=%s pt=%d,%d hit=%d\n",
927 hwnd, nBar, SPY_GetMsgName(msg,hwnd), pt.x, pt.y, hittest );
929 switch(SCROLL_trackHitTest)
931 case SCROLL_NOWHERE: /* No tracking in progress */
932 break;
934 case SCROLL_TOP_ARROW:
935 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
936 (hittest == SCROLL_trackHitTest), FALSE );
937 if (hittest == SCROLL_trackHitTest)
939 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
941 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
942 SB_LINEUP, (LPARAM)hwndCtl );
945 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
946 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
948 else KillSystemTimer( hwnd, SCROLL_TIMER );
949 break;
951 case SCROLL_TOP_RECT:
952 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
953 thumbPos, infoPtr->flags, vertical,
954 (hittest == SCROLL_trackHitTest), FALSE );
955 if (hittest == SCROLL_trackHitTest)
957 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
959 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
960 SB_PAGEUP, (LPARAM)hwndCtl );
962 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
963 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
965 else KillSystemTimer( hwnd, SCROLL_TIMER );
966 break;
968 case SCROLL_THUMB:
969 if (msg == WM_LBUTTONDOWN)
971 SCROLL_TrackingWin = hwnd;
972 SCROLL_TrackingBar = nBar;
973 SCROLL_TrackingPos = trackThumbPos + lastMousePos - lastClickPos;
974 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
975 vertical,
976 SCROLL_TrackingPos );
977 if (!SCROLL_MovingThumb)
978 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
980 else if (msg == WM_LBUTTONUP)
982 if (SCROLL_MovingThumb)
983 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
985 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
986 thumbPos, infoPtr->flags, vertical,
987 FALSE, FALSE );
989 else /* WM_MOUSEMOVE */
991 INT pos;
993 if (!SCROLL_PtInRectEx( &rect, pt, vertical )) pos = lastClickPos;
994 else
996 pt = SCROLL_ClipPos( &rect, pt );
997 pos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
999 if ( (pos != lastMousePos) || (!SCROLL_MovingThumb) )
1001 if (SCROLL_MovingThumb)
1002 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
1003 arrowSize, thumbSize );
1004 lastMousePos = pos;
1005 SCROLL_TrackingPos = trackThumbPos + pos - lastClickPos;
1006 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
1007 vertical,
1008 SCROLL_TrackingPos );
1009 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1010 MAKEWPARAM( SB_THUMBTRACK, SCROLL_TrackingVal),
1011 (LPARAM)hwndCtl );
1012 if (!SCROLL_MovingThumb)
1013 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
1014 arrowSize, thumbSize );
1017 break;
1019 case SCROLL_BOTTOM_RECT:
1020 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
1021 thumbPos, infoPtr->flags, vertical,
1022 FALSE, (hittest == SCROLL_trackHitTest) );
1023 if (hittest == SCROLL_trackHitTest)
1025 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1027 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1028 SB_PAGEDOWN, (LPARAM)hwndCtl );
1030 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1031 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
1033 else KillSystemTimer( hwnd, SCROLL_TIMER );
1034 break;
1036 case SCROLL_BOTTOM_ARROW:
1037 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
1038 FALSE, (hittest == SCROLL_trackHitTest) );
1039 if (hittest == SCROLL_trackHitTest)
1041 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1043 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1044 SB_LINEDOWN, (LPARAM)hwndCtl );
1047 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1048 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
1050 else KillSystemTimer( hwnd, SCROLL_TIMER );
1051 break;
1054 if (msg == WM_LBUTTONDOWN)
1057 if (hittest == SCROLL_THUMB)
1059 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1060 trackThumbPos + lastMousePos - lastClickPos );
1061 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1062 MAKEWPARAM( SB_THUMBTRACK, val ), (LPARAM)hwndCtl );
1066 if (msg == WM_LBUTTONUP)
1068 hittest = SCROLL_trackHitTest;
1069 SCROLL_trackHitTest = SCROLL_NOWHERE; /* Terminate tracking */
1071 if (hittest == SCROLL_THUMB)
1073 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1074 trackThumbPos + lastMousePos - lastClickPos );
1075 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1076 MAKEWPARAM( SB_THUMBPOSITION, val ), (LPARAM)hwndCtl );
1078 /* SB_ENDSCROLL doesn't report thumb position */
1079 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1080 SB_ENDSCROLL, (LPARAM)hwndCtl );
1082 /* Terminate tracking */
1083 SCROLL_TrackingWin = 0;
1086 ReleaseDC( hwnd, hdc );
1090 /***********************************************************************
1091 * SCROLL_TrackScrollBar
1093 * Track a mouse button press on a scroll-bar.
1094 * pt is in screen-coordinates for non-client scroll bars.
1096 void SCROLL_TrackScrollBar( HWND hwnd, INT scrollbar, POINT pt )
1098 MSG msg;
1100 if (scrollbar != SB_CTL)
1102 RECT rect;
1103 WIN_GetRectangles( hwnd, COORDS_CLIENT, &rect, NULL );
1104 ScreenToClient( hwnd, &pt );
1105 pt.x -= rect.left;
1106 pt.y -= rect.top;
1109 SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt );
1113 if (!GetMessageW( &msg, 0, 0, 0 )) break;
1114 if (CallMsgFilterW( &msg, MSGF_SCROLLBAR )) continue;
1115 if (msg.message == WM_LBUTTONUP ||
1116 msg.message == WM_MOUSEMOVE ||
1117 (msg.message == WM_SYSTIMER && msg.wParam == SCROLL_TIMER))
1119 pt.x = (short)LOWORD(msg.lParam);
1120 pt.y = (short)HIWORD(msg.lParam);
1121 SCROLL_HandleScrollEvent( hwnd, scrollbar, msg.message, pt );
1123 else
1125 TranslateMessage( &msg );
1126 DispatchMessageW( &msg );
1128 if (!IsWindow( hwnd ))
1130 ReleaseCapture();
1131 break;
1133 } while (msg.message != WM_LBUTTONUP && GetCapture() == hwnd);
1137 /***********************************************************************
1138 * SCROLL_CreateScrollBar
1140 * Create a scroll bar
1142 * PARAMS
1143 * hwnd [I] Handle of window with scrollbar(s)
1144 * lpCreate [I] The style and place of the scroll bar
1146 static void SCROLL_CreateScrollBar(HWND hwnd, LPCREATESTRUCTW lpCreate)
1148 LPSCROLLBAR_INFO info = SCROLL_GetInternalInfo(hwnd, SB_CTL, TRUE);
1149 if (!info) return;
1151 TRACE("hwnd=%p lpCreate=%p\n", hwnd, lpCreate);
1153 if (lpCreate->style & WS_DISABLED)
1155 info->flags = ESB_DISABLE_BOTH;
1156 TRACE("Created WS_DISABLED scrollbar\n");
1160 if (lpCreate->style & (SBS_SIZEGRIP | SBS_SIZEBOX))
1162 if (lpCreate->style & SBS_SIZEBOXTOPLEFTALIGN)
1163 MoveWindow( hwnd, lpCreate->x, lpCreate->y, GetSystemMetrics(SM_CXVSCROLL)+1,
1164 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1165 else if(lpCreate->style & SBS_SIZEBOXBOTTOMRIGHTALIGN)
1166 MoveWindow( hwnd, lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1167 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1168 GetSystemMetrics(SM_CXVSCROLL)+1,
1169 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1171 else if (lpCreate->style & SBS_VERT)
1173 if (lpCreate->style & SBS_LEFTALIGN)
1174 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1175 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1176 else if (lpCreate->style & SBS_RIGHTALIGN)
1177 MoveWindow( hwnd,
1178 lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1179 lpCreate->y,
1180 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1182 else /* SBS_HORZ */
1184 if (lpCreate->style & SBS_TOPALIGN)
1185 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1186 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1187 else if (lpCreate->style & SBS_BOTTOMALIGN)
1188 MoveWindow( hwnd,
1189 lpCreate->x,
1190 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1191 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1196 /*************************************************************************
1197 * SCROLL_GetScrollInfo
1199 * Internal helper for the API function
1201 * PARAMS
1202 * hwnd [I] Handle of window with scrollbar(s)
1203 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1204 * info [IO] fMask specifies which values to retrieve
1206 * RETURNS
1207 * FALSE if requested field not filled (f.i. scroll bar does not exist)
1209 static BOOL SCROLL_GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1211 LPSCROLLBAR_INFO infoPtr;
1213 /* handle invalid data structure */
1214 if (!SCROLL_ScrollInfoValid(info)
1215 || !(infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE)))
1216 return FALSE;
1218 /* fill in the desired scroll info structure */
1219 if (info->fMask & SIF_PAGE) info->nPage = infoPtr->page;
1220 if (info->fMask & SIF_POS) info->nPos = infoPtr->curVal;
1221 if ((info->fMask & SIF_TRACKPOS) && (info->cbSize == sizeof(*info)))
1222 info->nTrackPos = (SCROLL_TrackingWin == WIN_GetFullHandle(hwnd)) ? SCROLL_TrackingVal : infoPtr->curVal;
1223 if (info->fMask & SIF_RANGE)
1225 info->nMin = infoPtr->minVal;
1226 info->nMax = infoPtr->maxVal;
1229 TRACE("cbSize %02x fMask %04x nMin %d nMax %d nPage %u nPos %d nTrackPos %d\n",
1230 info->cbSize, info->fMask, info->nMin, info->nMax, info->nPage,
1231 info->nPos, info->nTrackPos);
1233 return (info->fMask & SIF_ALL) != 0;
1237 /*************************************************************************
1238 * SCROLL_GetScrollBarInfo
1240 * Internal helper for the API function
1242 * PARAMS
1243 * hwnd [I] Handle of window with scrollbar(s)
1244 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1245 * info [IO] cbSize specifies the size of the structure
1247 * RETURNS
1248 * FALSE if failed
1250 static BOOL SCROLL_GetScrollBarInfo(HWND hwnd, LONG idObject, LPSCROLLBARINFO info)
1252 LPSCROLLBAR_INFO infoPtr;
1253 INT nBar;
1254 INT nDummy;
1255 DWORD style = GetWindowLongW(hwnd, GWL_STYLE);
1256 BOOL pressed;
1257 RECT rect;
1259 switch (idObject)
1261 case OBJID_CLIENT: nBar = SB_CTL; break;
1262 case OBJID_HSCROLL: nBar = SB_HORZ; break;
1263 case OBJID_VSCROLL: nBar = SB_VERT; break;
1264 default: return FALSE;
1267 /* handle invalid data structure */
1268 if (info->cbSize != sizeof(*info))
1269 return FALSE;
1271 SCROLL_GetScrollBarRect(hwnd, nBar, &info->rcScrollBar, &nDummy,
1272 &info->dxyLineButton, &info->xyThumbTop);
1273 /* rcScrollBar needs to be in screen coordinates */
1274 GetWindowRect(hwnd, &rect);
1275 OffsetRect(&info->rcScrollBar, rect.left, rect.top);
1277 info->xyThumbBottom = info->xyThumbTop + info->dxyLineButton;
1279 infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, TRUE);
1280 if (!infoPtr)
1281 return FALSE;
1283 /* Scroll bar state */
1284 info->rgstate[0] = 0;
1285 if ((nBar == SB_HORZ && !(style & WS_HSCROLL))
1286 || (nBar == SB_VERT && !(style & WS_VSCROLL)))
1287 info->rgstate[0] |= STATE_SYSTEM_INVISIBLE;
1288 if (infoPtr->minVal >= infoPtr->maxVal - max(infoPtr->page - 1, 0))
1290 if (!(info->rgstate[0] & STATE_SYSTEM_INVISIBLE))
1291 info->rgstate[0] |= STATE_SYSTEM_UNAVAILABLE;
1292 else
1293 info->rgstate[0] |= STATE_SYSTEM_OFFSCREEN;
1295 if (nBar == SB_CTL && !IsWindowEnabled(hwnd))
1296 info->rgstate[0] |= STATE_SYSTEM_UNAVAILABLE;
1298 pressed = ((nBar == SB_VERT) == SCROLL_trackVertical && GetCapture() == hwnd);
1300 /* Top/left arrow button state. MSDN says top/right, but I don't believe it */
1301 info->rgstate[1] = 0;
1302 if (pressed && SCROLL_trackHitTest == SCROLL_TOP_ARROW)
1303 info->rgstate[1] |= STATE_SYSTEM_PRESSED;
1304 if (infoPtr->flags & ESB_DISABLE_LTUP)
1305 info->rgstate[1] |= STATE_SYSTEM_UNAVAILABLE;
1307 /* Page up/left region state. MSDN says up/right, but I don't believe it */
1308 info->rgstate[2] = 0;
1309 if (infoPtr->curVal == infoPtr->minVal)
1310 info->rgstate[2] |= STATE_SYSTEM_INVISIBLE;
1311 if (pressed && SCROLL_trackHitTest == SCROLL_TOP_RECT)
1312 info->rgstate[2] |= STATE_SYSTEM_PRESSED;
1314 /* Thumb state */
1315 info->rgstate[3] = 0;
1316 if (pressed && SCROLL_trackHitTest == SCROLL_THUMB)
1317 info->rgstate[3] |= STATE_SYSTEM_PRESSED;
1319 /* Page down/right region state. MSDN says down/left, but I don't believe it */
1320 info->rgstate[4] = 0;
1321 if (infoPtr->curVal >= infoPtr->maxVal - 1)
1322 info->rgstate[4] |= STATE_SYSTEM_INVISIBLE;
1323 if (pressed && SCROLL_trackHitTest == SCROLL_BOTTOM_RECT)
1324 info->rgstate[4] |= STATE_SYSTEM_PRESSED;
1326 /* Bottom/right arrow button state. MSDN says bottom/left, but I don't believe it */
1327 info->rgstate[5] = 0;
1328 if (pressed && SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW)
1329 info->rgstate[5] |= STATE_SYSTEM_PRESSED;
1330 if (infoPtr->flags & ESB_DISABLE_RTDN)
1331 info->rgstate[5] |= STATE_SYSTEM_UNAVAILABLE;
1333 return TRUE;
1337 /*************************************************************************
1338 * SCROLL_GetScrollPos
1340 * Internal helper for the API function
1342 * PARAMS
1343 * hwnd [I] Handle of window with scrollbar(s)
1344 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1346 static INT SCROLL_GetScrollPos(HWND hwnd, INT nBar)
1348 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1349 return infoPtr ? infoPtr->curVal: 0;
1353 /*************************************************************************
1354 * SCROLL_GetScrollRange
1356 * Internal helper for the API function
1358 * PARAMS
1359 * hwnd [I] Handle of window with scrollbar(s)
1360 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1361 * lpMin [O] Where to store minimum value
1362 * lpMax [O] Where to store maximum value
1364 * RETURNS
1365 * Success: TRUE
1366 * Failure: FALSE
1368 static BOOL SCROLL_GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1370 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1372 if (lpMin) *lpMin = infoPtr ? infoPtr->minVal : 0;
1373 if (lpMax) *lpMax = infoPtr ? infoPtr->maxVal : 0;
1375 return TRUE;
1379 /*************************************************************************
1380 * SCROLL_SetScrollRange
1382 * PARAMS
1383 * hwnd [I] Handle of window with scrollbar(s)
1384 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1385 * lpMin [I] Minimum value
1386 * lpMax [I] Maximum value
1389 static BOOL SCROLL_SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal)
1391 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1393 TRACE("hwnd=%p nBar=%d min=%d max=%d\n", hwnd, nBar, minVal, maxVal);
1395 if (infoPtr)
1397 infoPtr->minVal = minVal;
1398 infoPtr->maxVal = maxVal;
1400 return TRUE;
1404 /***********************************************************************
1405 * ScrollBarWndProc_common
1407 LRESULT ScrollBarWndProc_common( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, BOOL unicode )
1409 if (!IsWindow( hwnd )) return 0;
1411 switch(message)
1413 case WM_CREATE:
1414 SCROLL_CreateScrollBar(hwnd, (LPCREATESTRUCTW)lParam);
1415 break;
1417 case WM_ENABLE:
1419 SCROLLBAR_INFO *infoPtr;
1420 if ((infoPtr = SCROLL_GetInternalInfo( hwnd, SB_CTL, FALSE )))
1422 infoPtr->flags = wParam ? ESB_ENABLE_BOTH : ESB_DISABLE_BOTH;
1423 SCROLL_RefreshScrollBar(hwnd, SB_CTL, TRUE, TRUE);
1426 return 0;
1428 case WM_LBUTTONDBLCLK:
1429 case WM_LBUTTONDOWN:
1430 if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEGRIP)
1432 SendMessageW( GetParent(hwnd), WM_SYSCOMMAND,
1433 SC_SIZE + ((GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_LAYOUTRTL) ?
1434 WMSZ_BOTTOMLEFT : WMSZ_BOTTOMRIGHT), lParam );
1436 else
1438 POINT pt;
1439 pt.x = (short)LOWORD(lParam);
1440 pt.y = (short)HIWORD(lParam);
1441 SCROLL_TrackScrollBar( hwnd, SB_CTL, pt );
1443 break;
1444 case WM_LBUTTONUP:
1445 case WM_MOUSEMOVE:
1446 case WM_SYSTIMER:
1448 POINT pt;
1449 pt.x = (short)LOWORD(lParam);
1450 pt.y = (short)HIWORD(lParam);
1451 SCROLL_HandleScrollEvent( hwnd, SB_CTL, message, pt );
1453 break;
1455 case WM_KEYDOWN:
1456 SCROLL_HandleKbdEvent(hwnd, wParam, lParam);
1457 break;
1459 case WM_KEYUP:
1460 ShowCaret(hwnd);
1461 break;
1463 case WM_SETFOCUS:
1465 /* Create a caret when a ScrollBar get focus */
1466 RECT rect;
1467 int arrowSize, thumbSize, thumbPos, vertical;
1468 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,
1469 &arrowSize, &thumbSize, &thumbPos );
1470 if (!vertical)
1472 CreateCaret(hwnd, (HBITMAP)1, thumbSize-2, rect.bottom-rect.top-2);
1473 SetCaretPos(thumbPos+1, rect.top+1);
1475 else
1477 CreateCaret(hwnd, (HBITMAP)1, rect.right-rect.left-2,thumbSize-2);
1478 SetCaretPos(rect.top+1, thumbPos+1);
1480 ShowCaret(hwnd);
1482 break;
1484 case WM_KILLFOCUS:
1486 RECT rect;
1487 int arrowSize, thumbSize, thumbPos, vertical;
1488 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,&arrowSize, &thumbSize, &thumbPos );
1489 if (!vertical){
1490 rect.left=thumbPos+1;
1491 rect.right=rect.left+thumbSize;
1493 else
1495 rect.top=thumbPos+1;
1496 rect.bottom=rect.top+thumbSize;
1498 HideCaret(hwnd);
1499 InvalidateRect(hwnd,&rect,0);
1500 DestroyCaret();
1502 break;
1504 case WM_ERASEBKGND:
1505 return 1;
1507 case WM_GETDLGCODE:
1508 return DLGC_WANTARROWS; /* Windows returns this value */
1510 case WM_PAINT:
1512 PAINTSTRUCT ps;
1513 HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
1514 if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEGRIP)
1516 SCROLL_DrawSizeGrip( hwnd, hdc);
1518 else if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEBOX)
1520 RECT rc;
1521 GetClientRect( hwnd, &rc );
1522 FillRect( hdc, &rc, GetSysColorBrush(COLOR_SCROLLBAR) );
1524 else
1525 SCROLL_DrawScrollBar( hwnd, hdc, SB_CTL, TRUE, TRUE );
1526 if (!wParam) EndPaint(hwnd, &ps);
1528 break;
1530 case WM_SETCURSOR:
1531 if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEGRIP)
1533 ULONG_PTR cursor = (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_LAYOUTRTL) ? IDC_SIZENESW : IDC_SIZENWSE;
1534 return (LRESULT)SetCursor( LoadCursorA( 0, (LPSTR)cursor ));
1536 return DefWindowProcW( hwnd, message, wParam, lParam );
1538 case SBM_SETPOS:
1539 return SetScrollPos( hwnd, SB_CTL, wParam, (BOOL)lParam );
1541 case SBM_GETPOS:
1542 return SCROLL_GetScrollPos(hwnd, SB_CTL);
1544 case SBM_SETRANGEREDRAW:
1545 case SBM_SETRANGE:
1547 INT oldPos = SCROLL_GetScrollPos( hwnd, SB_CTL );
1548 SCROLL_SetScrollRange( hwnd, SB_CTL, wParam, lParam );
1549 if (message == SBM_SETRANGEREDRAW)
1550 SCROLL_RefreshScrollBar( hwnd, SB_CTL, TRUE, TRUE );
1551 if (oldPos != SCROLL_GetScrollPos( hwnd, SB_CTL )) return oldPos;
1553 return 0;
1555 case SBM_GETRANGE:
1556 return SCROLL_GetScrollRange(hwnd, SB_CTL, (LPINT)wParam, (LPINT)lParam);
1558 case SBM_ENABLE_ARROWS:
1559 return EnableScrollBar( hwnd, SB_CTL, wParam );
1561 case SBM_SETSCROLLINFO:
1562 return SCROLL_SetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam, wParam );
1564 case SBM_GETSCROLLINFO:
1565 return SCROLL_GetScrollInfo(hwnd, SB_CTL, (SCROLLINFO *)lParam);
1567 case SBM_GETSCROLLBARINFO:
1568 return SCROLL_GetScrollBarInfo(hwnd, OBJID_CLIENT, (SCROLLBARINFO *)lParam);
1570 case 0x00e5:
1571 case 0x00e7:
1572 case 0x00e8:
1573 case 0x00ec:
1574 case 0x00ed:
1575 case 0x00ee:
1576 case 0x00ef:
1577 ERR("unknown Win32 msg %04x wp=%08lx lp=%08lx\n",
1578 message, wParam, lParam );
1579 break;
1581 default:
1582 if (message >= WM_USER)
1583 WARN("unknown msg %04x wp=%04lx lp=%08lx\n",
1584 message, wParam, lParam );
1585 if (unicode)
1586 return DefWindowProcW( hwnd, message, wParam, lParam );
1587 else
1588 return DefWindowProcA( hwnd, message, wParam, lParam );
1590 return 0;
1594 /*************************************************************************
1595 * SetScrollInfo (USER32.@)
1597 * SetScrollInfo can be used to set the position, upper bound,
1598 * lower bound, and page size of a scrollbar control.
1600 * PARAMS
1601 * hwnd [I] Handle of window with scrollbar(s)
1602 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1603 * info [I] Specifies what to change and new values
1604 * bRedraw [I] Should scrollbar be redrawn afterwards?
1606 * RETURNS
1607 * Scrollbar position
1609 * NOTE
1610 * For 100 lines of text to be displayed in a window of 25 lines,
1611 * one would for instance use info->nMin=0, info->nMax=75
1612 * (corresponding to the 76 different positions of the window on
1613 * the text), and info->nPage=25.
1615 INT WINAPI DECLSPEC_HOTPATCH SetScrollInfo(HWND hwnd, INT nBar, const SCROLLINFO *info, BOOL bRedraw)
1617 TRACE("hwnd=%p nBar=%d info=%p, bRedraw=%d\n", hwnd, nBar, info, bRedraw);
1619 /* Refer SB_CTL requests to the window */
1620 if (nBar == SB_CTL)
1621 return SendMessageW(hwnd, SBM_SETSCROLLINFO, bRedraw, (LPARAM)info);
1622 else
1623 return SCROLL_SetScrollInfo( hwnd, nBar, info, bRedraw );
1626 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar, LPCSCROLLINFO info, BOOL bRedraw )
1628 /* Update the scrollbar state and set action flags according to
1629 * what has to be done graphics wise. */
1631 SCROLLBAR_INFO *infoPtr;
1632 UINT new_flags;
1633 INT action = 0;
1635 /* handle invalid data structure */
1636 if (!SCROLL_ScrollInfoValid(info)
1637 || !(infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, TRUE)))
1638 return 0;
1640 if (TRACE_ON(scroll))
1642 TRACE("hwnd=%p bar=%d", hwnd, nBar);
1643 if (info->fMask & SIF_PAGE) TRACE( " page=%d", info->nPage );
1644 if (info->fMask & SIF_POS) TRACE( " pos=%d", info->nPos );
1645 if (info->fMask & SIF_RANGE) TRACE( " min=%d max=%d", info->nMin, info->nMax );
1646 TRACE("\n");
1649 /* Set the page size */
1651 if (info->fMask & SIF_PAGE)
1653 if( infoPtr->page != info->nPage )
1655 infoPtr->page = info->nPage;
1656 action |= SA_SSI_REFRESH;
1660 /* Set the scroll pos */
1662 if (info->fMask & SIF_POS)
1664 if( infoPtr->curVal != info->nPos )
1666 infoPtr->curVal = info->nPos;
1667 action |= SA_SSI_REFRESH;
1671 /* Set the scroll range */
1673 if (info->fMask & SIF_RANGE)
1675 /* Invalid range -> range is set to (0,0) */
1676 if ((info->nMin > info->nMax) ||
1677 ((UINT)(info->nMax - info->nMin) >= 0x80000000))
1679 action |= SA_SSI_REFRESH;
1680 infoPtr->minVal = 0;
1681 infoPtr->maxVal = 0;
1683 else
1685 if( infoPtr->minVal != info->nMin ||
1686 infoPtr->maxVal != info->nMax )
1688 action |= SA_SSI_REFRESH;
1689 infoPtr->minVal = info->nMin;
1690 infoPtr->maxVal = info->nMax;
1695 /* Make sure the page size is valid */
1696 if (infoPtr->page < 0) infoPtr->page = 0;
1697 else if (infoPtr->page > infoPtr->maxVal - infoPtr->minVal + 1 )
1698 infoPtr->page = infoPtr->maxVal - infoPtr->minVal + 1;
1700 /* Make sure the pos is inside the range */
1702 if (infoPtr->curVal < infoPtr->minVal)
1703 infoPtr->curVal = infoPtr->minVal;
1704 else if (infoPtr->curVal > infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1705 infoPtr->curVal = infoPtr->maxVal - max( infoPtr->page-1, 0 );
1707 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1708 infoPtr->page, infoPtr->curVal,
1709 infoPtr->minVal, infoPtr->maxVal );
1711 /* don't change the scrollbar state if SetScrollInfo
1712 * is just called with SIF_DISABLENOSCROLL
1714 if(!(info->fMask & SIF_ALL)) goto done;
1716 /* Check if the scrollbar should be hidden or disabled */
1718 if (info->fMask & (SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL))
1720 new_flags = infoPtr->flags;
1721 if (infoPtr->minVal >= infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1723 /* Hide or disable scroll-bar */
1724 if (info->fMask & SIF_DISABLENOSCROLL)
1726 new_flags = ESB_DISABLE_BOTH;
1727 action |= SA_SSI_REFRESH;
1729 else if ((nBar != SB_CTL) && (action & SA_SSI_REFRESH))
1731 action = SA_SSI_HIDE;
1734 else /* Show and enable scroll-bar only if no page only changed. */
1735 if (info->fMask != SIF_PAGE)
1737 new_flags = ESB_ENABLE_BOTH;
1738 if ((nBar != SB_CTL) && ( (action & SA_SSI_REFRESH) ))
1739 action |= SA_SSI_SHOW;
1742 if (infoPtr->flags != new_flags) /* check arrow flags */
1744 infoPtr->flags = new_flags;
1745 action |= SA_SSI_REPAINT_ARROWS;
1749 done:
1750 if( action & SA_SSI_HIDE )
1751 SCROLL_ShowScrollBar( hwnd, nBar, FALSE, FALSE );
1752 else
1754 if( action & SA_SSI_SHOW )
1755 if( SCROLL_ShowScrollBar( hwnd, nBar, TRUE, TRUE ) )
1756 return infoPtr->curVal; /* SetWindowPos() already did the painting */
1758 if( bRedraw )
1759 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
1760 else if( action & SA_SSI_REPAINT_ARROWS )
1761 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, FALSE );
1764 /* Return current position */
1765 return infoPtr->curVal;
1769 /*************************************************************************
1770 * GetScrollInfo (USER32.@)
1772 * GetScrollInfo can be used to retrieve the position, upper bound,
1773 * lower bound, and page size of a scrollbar control.
1775 * PARAMS
1776 * hwnd [I] Handle of window with scrollbar(s)
1777 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1778 * info [IO] fMask specifies which values to retrieve
1780 * RETURNS
1781 * TRUE if SCROLLINFO is filled
1782 * ( if nBar is SB_CTL, GetScrollInfo returns TRUE even if nothing
1783 * is filled)
1785 BOOL WINAPI DECLSPEC_HOTPATCH GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1787 TRACE("hwnd=%p nBar=%d info=%p\n", hwnd, nBar, info);
1789 /* Refer SB_CTL requests to the window */
1790 if (nBar == SB_CTL)
1792 SendMessageW(hwnd, SBM_GETSCROLLINFO, 0, (LPARAM)info);
1793 return TRUE;
1795 return SCROLL_GetScrollInfo(hwnd, nBar, info);
1799 /*************************************************************************
1800 * GetScrollBarInfo (USER32.@)
1802 * GetScrollBarInfo can be used to retrieve information about a scrollbar
1803 * control.
1805 * PARAMS
1806 * hwnd [I] Handle of window with scrollbar(s)
1807 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1808 * info [IO] cbSize specifies the size of SCROLLBARINFO
1810 * RETURNS
1811 * TRUE if success
1813 BOOL WINAPI GetScrollBarInfo(HWND hwnd, LONG idObject, LPSCROLLBARINFO info)
1815 TRACE("hwnd=%p idObject=%d info=%p\n", hwnd, idObject, info);
1817 /* Refer OBJID_CLIENT requests to the window */
1818 if (idObject == OBJID_CLIENT)
1819 return SendMessageW(hwnd, SBM_GETSCROLLBARINFO, 0, (LPARAM)info);
1820 else
1821 return SCROLL_GetScrollBarInfo(hwnd, idObject, info);
1825 /*************************************************************************
1826 * SetScrollPos (USER32.@)
1828 * Sets the current position of the scroll thumb.
1830 * PARAMS
1831 * hwnd [I] Handle of window with scrollbar(s)
1832 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1833 * nPos [I] New value
1834 * bRedraw [I] Should scrollbar be redrawn afterwards?
1836 * RETURNS
1837 * Success: Scrollbar position
1838 * Failure: 0
1840 * REMARKS
1841 * Note the ambiguity when 0 is returned. Use GetLastError
1842 * to make sure there was an error (and to know which one).
1844 INT WINAPI DECLSPEC_HOTPATCH SetScrollPos( HWND hwnd, INT nBar, INT nPos, BOOL bRedraw)
1846 SCROLLINFO info;
1847 SCROLLBAR_INFO *infoPtr;
1848 INT oldPos;
1850 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, FALSE ))) return 0;
1851 oldPos = infoPtr->curVal;
1852 info.cbSize = sizeof(info);
1853 info.nPos = nPos;
1854 info.fMask = SIF_POS;
1855 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1856 return oldPos;
1860 /*************************************************************************
1861 * GetScrollPos (USER32.@)
1863 * Gets the current position of the scroll thumb.
1865 * PARAMS
1866 * hwnd [I] Handle of window with scrollbar(s)
1867 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1869 * RETURNS
1870 * Success: Current position
1871 * Failure: 0
1873 * REMARKS
1874 * There is ambiguity when 0 is returned. Use GetLastError
1875 * to make sure there was an error (and to know which one).
1877 INT WINAPI DECLSPEC_HOTPATCH GetScrollPos(HWND hwnd, INT nBar)
1879 TRACE("hwnd=%p nBar=%d\n", hwnd, nBar);
1881 /* Refer SB_CTL requests to the window */
1882 if (nBar == SB_CTL)
1883 return SendMessageW(hwnd, SBM_GETPOS, 0, 0);
1884 else
1885 return SCROLL_GetScrollPos(hwnd, nBar);
1889 /*************************************************************************
1890 * SetScrollRange (USER32.@)
1891 * The SetScrollRange function sets the minimum and maximum scroll box positions
1892 * If nMinPos and nMaxPos is the same value, the scroll bar will hide
1894 * Sets the range of the scroll bar.
1896 * PARAMS
1897 * hwnd [I] Handle of window with scrollbar(s)
1898 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1899 * minVal [I] New minimum value
1900 * maxVal [I] New Maximum value
1901 * bRedraw [I] Should scrollbar be redrawn afterwards?
1903 * RETURNS
1904 * Success: TRUE
1905 * Failure: FALSE
1907 BOOL WINAPI DECLSPEC_HOTPATCH SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal, BOOL bRedraw)
1909 SCROLLINFO info;
1911 TRACE("hwnd=%p nBar=%d min=%d max=%d, bRedraw=%d\n", hwnd, nBar, minVal, maxVal, bRedraw);
1913 info.cbSize = sizeof(info);
1914 info.fMask = SIF_RANGE;
1915 info.nMin = minVal;
1916 info.nMax = maxVal;
1917 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1918 return TRUE;
1922 /*************************************************************************
1923 * GetScrollRange (USER32.@)
1925 * Gets the range of the scroll bar.
1927 * PARAMS
1928 * hwnd [I] Handle of window with scrollbar(s)
1929 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1930 * lpMin [O] Where to store minimum value
1931 * lpMax [O] Where to store maximum value
1933 * RETURNS
1934 * TRUE if values is filled
1936 BOOL WINAPI DECLSPEC_HOTPATCH GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1938 TRACE("hwnd=%p nBar=%d lpMin=%p lpMax=%p\n", hwnd, nBar, lpMin, lpMax);
1940 /* Refer SB_CTL requests to the window */
1941 if (nBar == SB_CTL)
1942 SendMessageW(hwnd, SBM_GETRANGE, (WPARAM)lpMin, (LPARAM)lpMax);
1943 else
1944 SCROLL_GetScrollRange(hwnd, nBar, lpMin, lpMax);
1946 return TRUE;
1950 /*************************************************************************
1951 * SCROLL_ShowScrollBar()
1953 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1955 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar, BOOL fShowH, BOOL fShowV )
1957 ULONG old_style, set_bits = 0, clear_bits = 0;
1959 TRACE("hwnd=%p bar=%d horz=%d, vert=%d\n", hwnd, nBar, fShowH, fShowV );
1961 switch(nBar)
1963 case SB_CTL:
1964 ShowWindow( hwnd, fShowH ? SW_SHOW : SW_HIDE );
1965 return TRUE;
1967 case SB_BOTH:
1968 case SB_HORZ:
1969 if (fShowH) set_bits |= WS_HSCROLL;
1970 else clear_bits |= WS_HSCROLL;
1971 if( nBar == SB_HORZ ) break;
1972 /* fall through */
1973 case SB_VERT:
1974 if (fShowV) set_bits |= WS_VSCROLL;
1975 else clear_bits |= WS_VSCROLL;
1976 break;
1978 default:
1979 return FALSE; /* Nothing to do! */
1982 old_style = WIN_SetStyle( hwnd, set_bits, clear_bits );
1983 if ((old_style & clear_bits) != 0 || (old_style & set_bits) != set_bits)
1985 /* frame has been changed, let the window redraw itself */
1986 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
1987 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
1988 return TRUE;
1990 return FALSE; /* no frame changes */
1994 /*************************************************************************
1995 * ShowScrollBar (USER32.@)
1997 * Shows or hides the scroll bar.
1999 * PARAMS
2000 * hwnd [I] Handle of window with scrollbar(s)
2001 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
2002 * fShow [I] TRUE = show, FALSE = hide
2004 * RETURNS
2005 * Success: TRUE
2006 * Failure: FALSE
2008 BOOL WINAPI DECLSPEC_HOTPATCH ShowScrollBar(HWND hwnd, INT nBar, BOOL fShow)
2010 if ( !hwnd )
2011 return FALSE;
2013 SCROLL_ShowScrollBar( hwnd, nBar, (nBar == SB_VERT) ? 0 : fShow,
2014 (nBar == SB_HORZ) ? 0 : fShow );
2015 return TRUE;
2019 /*************************************************************************
2020 * EnableScrollBar (USER32.@)
2022 * Enables or disables the scroll bars.
2024 BOOL WINAPI DECLSPEC_HOTPATCH EnableScrollBar( HWND hwnd, UINT nBar, UINT flags )
2026 BOOL bFineWithMe;
2027 SCROLLBAR_INFO *infoPtr;
2029 flags &= ESB_DISABLE_BOTH;
2031 if (nBar == SB_BOTH)
2033 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, SB_VERT, TRUE ))) return FALSE;
2034 if (!(bFineWithMe = (infoPtr->flags == flags)) )
2036 infoPtr->flags = flags;
2037 SCROLL_RefreshScrollBar( hwnd, SB_VERT, TRUE, TRUE );
2039 nBar = SB_HORZ;
2041 else
2042 bFineWithMe = TRUE;
2044 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, TRUE ))) return FALSE;
2045 if (bFineWithMe && infoPtr->flags == flags) return FALSE;
2046 infoPtr->flags = flags;
2048 if (nBar == SB_CTL && (flags == ESB_DISABLE_BOTH || flags == ESB_ENABLE_BOTH))
2049 EnableWindow(hwnd, flags == ESB_ENABLE_BOTH);
2051 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
2052 return TRUE;