shlwapi/tests: Fix another test on Vista.
[wine.git] / dlls / user32 / scroll.c
blobddfacd6f083341726501f329081e34811ecf3c15
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 <stdarg.h>
33 #include "windef.h"
34 #include "winbase.h"
35 #include "wingdi.h"
36 #include "wine/winuser16.h"
37 #include "controls.h"
38 #include "win.h"
39 #include "wine/debug.h"
40 #include "user_private.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(scroll);
44 typedef struct
46 INT curVal; /* Current scroll-bar value */
47 INT minVal; /* Minimum scroll-bar value */
48 INT maxVal; /* Maximum scroll-bar value */
49 INT page; /* Page size of scroll bar (Win32) */
50 UINT flags; /* EnableScrollBar flags */
51 } SCROLLBAR_INFO, *LPSCROLLBAR_INFO;
54 /* Minimum size of the rectangle between the arrows */
55 #define SCROLL_MIN_RECT 4
57 /* Minimum size of the thumb in pixels */
58 #define SCROLL_MIN_THUMB 6
60 /* Overlap between arrows and thumb */
61 #define SCROLL_ARROW_THUMB_OVERLAP 0
63 /* Delay (in ms) before first repetition when holding the button down */
64 #define SCROLL_FIRST_DELAY 200
66 /* Delay (in ms) between scroll repetitions */
67 #define SCROLL_REPEAT_DELAY 50
69 /* Scroll timer id */
70 #define SCROLL_TIMER 0
72 /* Scroll-bar hit testing */
73 enum SCROLL_HITTEST
75 SCROLL_NOWHERE, /* Outside the scroll bar */
76 SCROLL_TOP_ARROW, /* Top or left arrow */
77 SCROLL_TOP_RECT, /* Rectangle between the top arrow and the thumb */
78 SCROLL_THUMB, /* Thumb rectangle */
79 SCROLL_BOTTOM_RECT, /* Rectangle between the thumb and the bottom arrow */
80 SCROLL_BOTTOM_ARROW /* Bottom or right arrow */
83 /* What to do after SCROLL_SetScrollInfo() */
84 #define SA_SSI_HIDE 0x0001
85 #define SA_SSI_SHOW 0x0002
86 #define SA_SSI_REFRESH 0x0004
87 #define SA_SSI_REPAINT_ARROWS 0x0008
89 /* Thumb-tracking info */
90 static HWND SCROLL_TrackingWin = 0;
91 static INT SCROLL_TrackingBar = 0;
92 static INT SCROLL_TrackingPos = 0;
93 static INT SCROLL_TrackingVal = 0;
94 /* Hit test code of the last button-down event */
95 static enum SCROLL_HITTEST SCROLL_trackHitTest;
96 static BOOL SCROLL_trackVertical;
98 /* Is the moving thumb being displayed? */
99 static BOOL SCROLL_MovingThumb = FALSE;
101 /* Local functions */
102 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar,
103 BOOL fShowH, BOOL fShowV );
104 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar,
105 const SCROLLINFO *info, BOOL bRedraw );
106 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
107 RECT *rect, INT arrowSize,
108 INT thumbSize, INT thumbPos,
109 UINT flags, BOOL vertical,
110 BOOL top_selected, BOOL bottom_selected );
111 static LRESULT WINAPI ScrollBarWndProcA( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
112 static LRESULT WINAPI ScrollBarWndProcW( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
115 /*********************************************************************
116 * scrollbar class descriptor
118 static const WCHAR scrollbarW[] = {'S','c','r','o','l','l','B','a','r',0};
119 const struct builtin_class_descr SCROLL_builtin_class =
121 scrollbarW, /* name */
122 CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC, /* style */
123 ScrollBarWndProcA, /* procA */
124 ScrollBarWndProcW, /* procW */
125 sizeof(SCROLLBAR_INFO), /* extra */
126 IDC_ARROW, /* cursor */
127 0 /* brush */
130 /***********************************************************************
131 * SCROLL_ScrollInfoValid
133 * Determine if the supplied SCROLLINFO struct is valid.
134 * info [in] The SCROLLINFO struct to be tested
136 static inline BOOL SCROLL_ScrollInfoValid( LPCSCROLLINFO info )
138 return !(info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)
139 || (info->cbSize != sizeof(*info)
140 && info->cbSize != sizeof(*info) - sizeof(info->nTrackPos)));
144 /***********************************************************************
145 * SCROLL_GetInternalInfo
147 * Returns pointer to internal SCROLLBAR_INFO structure for nBar
148 * or NULL if failed (f.i. scroll bar does not exist yet)
149 * If alloc is TRUE and the struct does not exist yet, create it.
151 static SCROLLBAR_INFO *SCROLL_GetInternalInfo( HWND hwnd, INT nBar, BOOL alloc )
153 SCROLLBAR_INFO *infoPtr = NULL;
154 WND *wndPtr = WIN_GetPtr( hwnd );
156 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return NULL;
157 switch(nBar)
159 case SB_HORZ: infoPtr = (SCROLLBAR_INFO *)wndPtr->pHScroll; break;
160 case SB_VERT: infoPtr = (SCROLLBAR_INFO *)wndPtr->pVScroll; break;
161 case SB_CTL: infoPtr = (SCROLLBAR_INFO *)wndPtr->wExtra; break;
162 case SB_BOTH: WARN("with SB_BOTH\n"); break;
165 if (!infoPtr && alloc)
167 if (nBar != SB_HORZ && nBar != SB_VERT)
168 WARN("Cannot initialize nBar=%d\n",nBar);
169 else if ((infoPtr = HeapAlloc( GetProcessHeap(), 0, sizeof(SCROLLBAR_INFO) )))
171 /* Set default values */
172 infoPtr->minVal = infoPtr->curVal = infoPtr->page = 0;
173 /* From MSDN: max for a standard scroll bar is 100 by default. */
174 infoPtr->maxVal = 100;
175 /* Scroll bar is enabled by default after create */
176 infoPtr->flags = ESB_ENABLE_BOTH;
177 if (nBar == SB_HORZ) wndPtr->pHScroll = infoPtr;
178 else wndPtr->pVScroll = infoPtr;
181 WIN_ReleasePtr( wndPtr );
182 return infoPtr;
186 /***********************************************************************
187 * SCROLL_GetScrollBarRect
189 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
190 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
191 * 'arrowSize' returns the width or height of an arrow (depending on
192 * the orientation of the scrollbar), 'thumbSize' returns the size of
193 * the thumb, and 'thumbPos' returns the position of the thumb
194 * relative to the left or to the top.
195 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
197 static BOOL SCROLL_GetScrollBarRect( HWND hwnd, INT nBar, RECT *lprect,
198 INT *arrowSize, INT *thumbSize,
199 INT *thumbPos )
201 INT pixels;
202 BOOL vertical;
203 WND *wndPtr = WIN_GetPtr( hwnd );
205 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
207 switch(nBar)
209 case SB_HORZ:
210 lprect->left = wndPtr->rectClient.left - wndPtr->rectWindow.left;
211 lprect->top = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
212 lprect->right = wndPtr->rectClient.right - wndPtr->rectWindow.left;
213 lprect->bottom = lprect->top + GetSystemMetrics(SM_CYHSCROLL);
214 if(wndPtr->dwStyle & WS_VSCROLL)
215 lprect->right++;
216 vertical = FALSE;
217 break;
219 case SB_VERT:
220 if((wndPtr->dwExStyle & WS_EX_LEFTSCROLLBAR) != 0)
221 lprect->left = wndPtr->rectClient.left - wndPtr->rectWindow.left - GetSystemMetrics(SM_CXVSCROLL);
222 else
223 lprect->left = wndPtr->rectClient.right - wndPtr->rectWindow.left;
224 lprect->top = wndPtr->rectClient.top - wndPtr->rectWindow.top;
225 lprect->right = lprect->left + GetSystemMetrics(SM_CXVSCROLL);
226 lprect->bottom = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
227 if(wndPtr->dwStyle & WS_HSCROLL)
228 lprect->bottom++;
229 vertical = TRUE;
230 break;
232 case SB_CTL:
233 GetClientRect( hwnd, lprect );
234 vertical = ((wndPtr->dwStyle & SBS_VERT) != 0);
235 break;
237 default:
238 WIN_ReleasePtr( wndPtr );
239 return FALSE;
242 if (vertical) pixels = lprect->bottom - lprect->top;
243 else pixels = lprect->right - lprect->left;
245 if (pixels <= 2*GetSystemMetrics(SM_CXVSCROLL) + SCROLL_MIN_RECT)
247 if (pixels > SCROLL_MIN_RECT)
248 *arrowSize = (pixels - SCROLL_MIN_RECT) / 2;
249 else
250 *arrowSize = 0;
251 *thumbPos = *thumbSize = 0;
253 else
255 SCROLLBAR_INFO *info = SCROLL_GetInternalInfo( hwnd, nBar, FALSE );
256 if (!info)
258 WARN("called for missing scroll bar\n");
259 WIN_ReleasePtr( wndPtr );
260 return FALSE;
262 *arrowSize = GetSystemMetrics(SM_CXVSCROLL);
263 pixels -= (2 * (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP));
265 if (info->page)
267 *thumbSize = MulDiv(pixels,info->page,(info->maxVal-info->minVal+1));
268 if (*thumbSize < SCROLL_MIN_THUMB) *thumbSize = SCROLL_MIN_THUMB;
270 else *thumbSize = GetSystemMetrics(SM_CXVSCROLL);
272 if (((pixels -= *thumbSize ) < 0) ||
273 ((info->flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH))
275 /* Rectangle too small or scrollbar disabled -> no thumb */
276 *thumbPos = *thumbSize = 0;
278 else
280 INT max = info->maxVal - max( info->page-1, 0 );
281 if (info->minVal >= max)
282 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
283 else
284 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP
285 + MulDiv(pixels, (info->curVal-info->minVal),(max - info->minVal));
288 WIN_ReleasePtr( wndPtr );
289 return vertical;
293 /***********************************************************************
294 * SCROLL_GetThumbVal
296 * Compute the current scroll position based on the thumb position in pixels
297 * from the top of the scroll-bar.
299 static UINT SCROLL_GetThumbVal( SCROLLBAR_INFO *infoPtr, RECT *rect,
300 BOOL vertical, INT pos )
302 INT thumbSize;
303 INT pixels = vertical ? rect->bottom-rect->top : rect->right-rect->left;
305 if ((pixels -= 2*(GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP)) <= 0)
306 return infoPtr->minVal;
308 if (infoPtr->page)
310 thumbSize = MulDiv(pixels,infoPtr->page,(infoPtr->maxVal-infoPtr->minVal+1));
311 if (thumbSize < SCROLL_MIN_THUMB) thumbSize = SCROLL_MIN_THUMB;
313 else thumbSize = GetSystemMetrics(SM_CXVSCROLL);
315 if ((pixels -= thumbSize) <= 0) return infoPtr->minVal;
317 pos = max( 0, pos - (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP) );
318 if (pos > pixels) pos = pixels;
320 if (!infoPtr->page) pos *= infoPtr->maxVal - infoPtr->minVal;
321 else pos *= infoPtr->maxVal - infoPtr->minVal - infoPtr->page + 1;
322 return infoPtr->minVal + ((pos + pixels / 2) / pixels);
325 /***********************************************************************
326 * SCROLL_PtInRectEx
328 static BOOL SCROLL_PtInRectEx( LPRECT lpRect, POINT pt, BOOL vertical )
330 RECT rect = *lpRect;
332 if (vertical)
334 rect.left -= lpRect->right - lpRect->left;
335 rect.right += lpRect->right - lpRect->left;
337 else
339 rect.top -= lpRect->bottom - lpRect->top;
340 rect.bottom += lpRect->bottom - lpRect->top;
342 return PtInRect( &rect, pt );
345 /***********************************************************************
346 * SCROLL_ClipPos
348 static POINT SCROLL_ClipPos( LPRECT lpRect, POINT pt )
350 if( pt.x < lpRect->left )
351 pt.x = lpRect->left;
352 else
353 if( pt.x > lpRect->right )
354 pt.x = lpRect->right;
356 if( pt.y < lpRect->top )
357 pt.y = lpRect->top;
358 else
359 if( pt.y > lpRect->bottom )
360 pt.y = lpRect->bottom;
362 return pt;
366 /***********************************************************************
367 * SCROLL_HitTest
369 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
371 static enum SCROLL_HITTEST SCROLL_HitTest( HWND hwnd, INT nBar,
372 POINT pt, BOOL bDragging )
374 INT arrowSize, thumbSize, thumbPos;
375 RECT rect;
377 BOOL vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
378 &arrowSize, &thumbSize, &thumbPos );
380 if ( (bDragging && !SCROLL_PtInRectEx( &rect, pt, vertical )) ||
381 (!PtInRect( &rect, pt )) ) return SCROLL_NOWHERE;
383 if (vertical)
385 if (pt.y < rect.top + arrowSize) return SCROLL_TOP_ARROW;
386 if (pt.y >= rect.bottom - arrowSize) return SCROLL_BOTTOM_ARROW;
387 if (!thumbPos) return SCROLL_TOP_RECT;
388 pt.y -= rect.top;
389 if (pt.y < thumbPos) return SCROLL_TOP_RECT;
390 if (pt.y >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
392 else /* horizontal */
394 if (pt.x < rect.left + arrowSize) return SCROLL_TOP_ARROW;
395 if (pt.x >= rect.right - arrowSize) return SCROLL_BOTTOM_ARROW;
396 if (!thumbPos) return SCROLL_TOP_RECT;
397 pt.x -= rect.left;
398 if (pt.x < thumbPos) return SCROLL_TOP_RECT;
399 if (pt.x >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
401 return SCROLL_THUMB;
405 /***********************************************************************
406 * SCROLL_DrawArrows
408 * Draw the scroll bar arrows.
410 static void SCROLL_DrawArrows( HDC hdc, SCROLLBAR_INFO *infoPtr,
411 RECT *rect, INT arrowSize, BOOL vertical,
412 BOOL top_pressed, BOOL bottom_pressed )
414 RECT r;
416 r = *rect;
417 if( vertical )
418 r.bottom = r.top + arrowSize;
419 else
420 r.right = r.left + arrowSize;
422 DrawFrameControl( hdc, &r, DFC_SCROLL,
423 (vertical ? DFCS_SCROLLUP : DFCS_SCROLLLEFT)
424 | (top_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
425 | (infoPtr->flags&ESB_DISABLE_LTUP ? DFCS_INACTIVE : 0 ) );
427 r = *rect;
428 if( vertical )
429 r.top = r.bottom-arrowSize;
430 else
431 r.left = r.right-arrowSize;
433 DrawFrameControl( hdc, &r, DFC_SCROLL,
434 (vertical ? DFCS_SCROLLDOWN : DFCS_SCROLLRIGHT)
435 | (bottom_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
436 | (infoPtr->flags&ESB_DISABLE_RTDN ? DFCS_INACTIVE : 0) );
439 static void SCROLL_DrawMovingThumb( HDC hdc, RECT *rect, BOOL vertical,
440 INT arrowSize, INT thumbSize )
442 INT pos = SCROLL_TrackingPos;
443 INT max_size;
445 if( vertical )
446 max_size = rect->bottom - rect->top;
447 else
448 max_size = rect->right - rect->left;
450 max_size -= (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) + thumbSize;
452 if( pos < (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) )
453 pos = (arrowSize-SCROLL_ARROW_THUMB_OVERLAP);
454 else if( pos > max_size )
455 pos = max_size;
457 SCROLL_DrawInterior_9x( SCROLL_TrackingWin, hdc, SCROLL_TrackingBar,
458 rect, arrowSize, thumbSize, pos,
459 0, vertical, FALSE, FALSE );
461 SCROLL_MovingThumb = !SCROLL_MovingThumb;
464 /***********************************************************************
465 * SCROLL_DrawInterior
467 * Draw the scroll bar interior (everything except the arrows).
469 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
470 RECT *rect, INT arrowSize,
471 INT thumbSize, INT thumbPos,
472 UINT flags, BOOL vertical,
473 BOOL top_selected, BOOL bottom_selected )
475 RECT r;
476 HPEN hSavePen;
477 HBRUSH hSaveBrush,hBrush;
479 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
480 * The window-owned scrollbars need to call DEFWND_ControlColor
481 * to correctly setup default scrollbar colors
483 if (nBar == SB_CTL)
485 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
486 (WPARAM)hdc,(LPARAM)hwnd);
488 else
490 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
493 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
494 hSaveBrush = SelectObject( hdc, hBrush );
496 /* Calculate the scroll rectangle */
497 r = *rect;
498 if (vertical)
500 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
501 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
503 else
505 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
506 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
509 /* Draw the scroll rectangles and thumb */
510 if (!thumbPos) /* No thumb to draw */
512 PatBlt( hdc, r.left, r.top,
513 r.right - r.left, r.bottom - r.top,
514 PATCOPY );
516 /* cleanup and return */
517 SelectObject( hdc, hSavePen );
518 SelectObject( hdc, hSaveBrush );
519 return;
522 if (vertical)
524 PatBlt( hdc, r.left, r.top,
525 r.right - r.left,
526 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
527 top_selected ? 0x0f0000 : PATCOPY );
528 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
529 PatBlt( hdc, r.left, r.top + thumbSize,
530 r.right - r.left,
531 r.bottom - r.top - thumbSize,
532 bottom_selected ? 0x0f0000 : PATCOPY );
533 r.bottom = r.top + thumbSize;
535 else /* horizontal */
537 PatBlt( hdc, r.left, r.top,
538 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
539 r.bottom - r.top,
540 top_selected ? 0x0f0000 : PATCOPY );
541 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
542 PatBlt( hdc, r.left + thumbSize, r.top,
543 r.right - r.left - thumbSize,
544 r.bottom - r.top,
545 bottom_selected ? 0x0f0000 : PATCOPY );
546 r.right = r.left + thumbSize;
549 /* Draw the thumb */
550 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT | BF_MIDDLE );
552 /* cleanup */
553 SelectObject( hdc, hSavePen );
554 SelectObject( hdc, hSaveBrush );
558 static void SCROLL_DrawInterior( HWND hwnd, HDC hdc, INT nBar,
559 RECT *rect, INT arrowSize,
560 INT thumbSize, INT thumbPos,
561 UINT flags, BOOL vertical,
562 BOOL top_selected, BOOL bottom_selected )
564 RECT r;
565 HPEN hSavePen;
566 HBRUSH hSaveBrush,hBrush;
567 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
569 if (Save_SCROLL_MovingThumb &&
570 (SCROLL_TrackingWin == hwnd) &&
571 (SCROLL_TrackingBar == nBar))
572 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
574 /* Select the correct brush and pen */
576 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
577 * The window-owned scrollbars need to call DEFWND_ControlColor
578 * to correctly setup default scrollbar colors
580 if (nBar == SB_CTL) {
581 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
582 (WPARAM)hdc,(LPARAM)hwnd);
583 } else {
584 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
586 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
587 hSaveBrush = SelectObject( hdc, hBrush );
589 /* Calculate the scroll rectangle */
591 r = *rect;
592 if (vertical)
594 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
595 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
597 else
599 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
600 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
603 /* Draw the scroll bar frame */
605 /* Draw the scroll rectangles and thumb */
607 if (!thumbPos) /* No thumb to draw */
609 PatBlt( hdc, r.left, r.top, r.right - r.left, r.bottom - r.top, PATCOPY );
611 /* cleanup and return */
612 SelectObject( hdc, hSavePen );
613 SelectObject( hdc, hSaveBrush );
614 return;
617 if (vertical)
619 PatBlt( hdc, r.left, r.top, r.right - r.left,
620 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
621 top_selected ? 0x0f0000 : PATCOPY );
622 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
623 PatBlt( hdc, r.left, r.top + thumbSize, r.right - r.left,
624 r.bottom - r.top - thumbSize,
625 bottom_selected ? 0x0f0000 : PATCOPY );
626 r.bottom = r.top + thumbSize;
628 else /* horizontal */
630 PatBlt( hdc, r.left, r.top,
631 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
632 r.bottom - r.top, top_selected ? 0x0f0000 : PATCOPY );
633 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
634 PatBlt( hdc, r.left + thumbSize, r.top, r.right - r.left - thumbSize,
635 r.bottom - r.top, bottom_selected ? 0x0f0000 : PATCOPY );
636 r.right = r.left + thumbSize;
639 /* Draw the thumb */
641 SelectObject( hdc, GetSysColorBrush(COLOR_BTNFACE) );
642 Rectangle( hdc, r.left+1, r.top+1, r.right-1, r.bottom-1 );
643 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT );
645 if (Save_SCROLL_MovingThumb &&
646 (SCROLL_TrackingWin == hwnd) &&
647 (SCROLL_TrackingBar == nBar))
648 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
650 /* cleanup */
651 SelectObject( hdc, hSavePen );
652 SelectObject( hdc, hSaveBrush );
656 /***********************************************************************
657 * SCROLL_DrawScrollBar
659 * Redraw the whole scrollbar.
661 void SCROLL_DrawScrollBar( HWND hwnd, HDC hdc, INT nBar,
662 BOOL arrows, BOOL interior )
664 INT arrowSize, thumbSize, thumbPos;
665 RECT rect;
666 BOOL vertical;
667 SCROLLBAR_INFO *infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, TRUE );
668 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
669 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
671 if (!(hwnd = WIN_GetFullHandle( hwnd ))) return;
673 if (!infoPtr ||
674 ((nBar == SB_VERT) && !(style & WS_VSCROLL)) ||
675 ((nBar == SB_HORZ) && !(style & WS_HSCROLL))) return;
676 if (!WIN_IsWindowDrawable( hwnd, FALSE )) return;
678 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
679 &arrowSize, &thumbSize, &thumbPos );
681 /* do not draw if the scrollbar rectangle is empty */
682 if(IsRectEmpty(&rect)) return;
684 if (Save_SCROLL_MovingThumb &&
685 (SCROLL_TrackingWin == hwnd) &&
686 (SCROLL_TrackingBar == nBar))
687 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
689 /* Draw the arrows */
691 if (arrows && arrowSize)
693 if( vertical == SCROLL_trackVertical && GetCapture() == hwnd )
694 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
695 (SCROLL_trackHitTest == SCROLL_TOP_ARROW),
696 (SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW) );
697 else
698 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
699 FALSE, FALSE );
701 if( interior )
702 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
703 thumbPos, infoPtr->flags, vertical, FALSE, FALSE );
705 if (Save_SCROLL_MovingThumb &&
706 (SCROLL_TrackingWin == hwnd) &&
707 (SCROLL_TrackingBar == nBar))
708 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
710 /* if scroll bar has focus, reposition the caret */
711 if(hwnd==GetFocus() && (nBar==SB_CTL))
713 if (!vertical)
715 SetCaretPos(thumbPos+1, rect.top+1);
717 else
719 SetCaretPos(rect.top+1, thumbPos+1);
724 /***********************************************************************
725 * SCROLL_DrawSizeGrip
727 * Draw the size grip.
729 static void SCROLL_DrawSizeGrip( HWND hwnd, HDC hdc)
731 RECT rc;
733 GetClientRect( hwnd, &rc );
734 FillRect( hdc, &rc, GetSysColorBrush(COLOR_SCROLLBAR) );
735 rc.left = max( rc.left, rc.right - GetSystemMetrics(SM_CXVSCROLL) - 1 );
736 rc.top = max( rc.top, rc.bottom - GetSystemMetrics(SM_CYHSCROLL) - 1 );
737 DrawFrameControl( hdc, &rc, DFC_SCROLL, DFCS_SCROLLSIZEGRIP );
741 /***********************************************************************
742 * SCROLL_RefreshScrollBar
744 * Repaint the scroll bar interior after a SetScrollRange() or
745 * SetScrollPos() call.
747 static void SCROLL_RefreshScrollBar( HWND hwnd, INT nBar,
748 BOOL arrows, BOOL interior )
750 HDC hdc = GetDCEx( hwnd, 0,
751 DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW) );
752 if (!hdc) return;
754 SCROLL_DrawScrollBar( hwnd, hdc, nBar, arrows, interior );
755 ReleaseDC( hwnd, hdc );
759 /***********************************************************************
760 * SCROLL_HandleKbdEvent
762 * Handle a keyboard event (only for SB_CTL scrollbars with focus).
764 * PARAMS
765 * hwnd [I] Handle of window with scrollbar(s)
766 * wParam [I] Variable input including enable state
767 * lParam [I] Variable input including input point
769 static void SCROLL_HandleKbdEvent(HWND hwnd, WPARAM wParam, LPARAM lParam)
771 TRACE("hwnd=%p wParam=%ld lParam=%ld\n", hwnd, wParam, lParam);
773 /* hide caret on first KEYDOWN to prevent flicker */
774 if ((lParam & PFD_DOUBLEBUFFER_DONTCARE) == 0)
775 HideCaret(hwnd);
777 switch(wParam)
779 case VK_PRIOR: wParam = SB_PAGEUP; break;
780 case VK_NEXT: wParam = SB_PAGEDOWN; break;
781 case VK_HOME: wParam = SB_TOP; break;
782 case VK_END: wParam = SB_BOTTOM; break;
783 case VK_UP: wParam = SB_LINEUP; break;
784 case VK_DOWN: wParam = SB_LINEDOWN; break;
785 case VK_LEFT: wParam = SB_LINEUP; break;
786 case VK_RIGHT: wParam = SB_LINEDOWN; break;
787 default: return;
789 SendMessageW(GetParent(hwnd),
790 ((GetWindowLongW( hwnd, GWL_STYLE ) & SBS_VERT) ?
791 WM_VSCROLL : WM_HSCROLL), wParam, (LPARAM)hwnd);
795 /***********************************************************************
796 * SCROLL_HandleScrollEvent
798 * Handle a mouse or timer event for the scrollbar.
799 * 'pt' is the location of the mouse event in client (for SB_CTL) or
800 * windows coordinates.
802 static void SCROLL_HandleScrollEvent( HWND hwnd, INT nBar, UINT msg, POINT pt)
804 /* Previous mouse position for timer events */
805 static POINT prevPt;
806 /* Thumb position when tracking started. */
807 static UINT trackThumbPos;
808 /* Position in the scroll-bar of the last button-down event. */
809 static INT lastClickPos;
810 /* Position in the scroll-bar of the last mouse event. */
811 static INT lastMousePos;
813 enum SCROLL_HITTEST hittest;
814 HWND hwndOwner, hwndCtl;
815 BOOL vertical;
816 INT arrowSize, thumbSize, thumbPos;
817 RECT rect;
818 HDC hdc;
820 SCROLLBAR_INFO *infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, FALSE );
821 if (!infoPtr) return;
822 if ((SCROLL_trackHitTest == SCROLL_NOWHERE) && (msg != WM_LBUTTONDOWN))
823 return;
825 if (nBar == SB_CTL && (GetWindowLongW( hwnd, GWL_STYLE ) & (SBS_SIZEGRIP | SBS_SIZEBOX)))
827 switch(msg)
829 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
830 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
831 SetCapture( hwnd );
832 prevPt = pt;
833 SCROLL_trackHitTest = hittest = SCROLL_THUMB;
834 break;
835 case WM_MOUSEMOVE:
836 GetClientRect(GetParent(GetParent(hwnd)),&rect);
837 prevPt = pt;
838 break;
839 case WM_LBUTTONUP:
840 ReleaseCapture();
841 SCROLL_trackHitTest = hittest = SCROLL_NOWHERE;
842 if (hwnd==GetFocus()) ShowCaret(hwnd);
843 break;
844 case WM_SYSTIMER:
845 pt = prevPt;
846 break;
848 return;
851 hdc = GetDCEx( hwnd, 0, DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW));
852 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
853 &arrowSize, &thumbSize, &thumbPos );
854 hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd) : hwnd;
855 hwndCtl = (nBar == SB_CTL) ? hwnd : 0;
857 switch(msg)
859 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
860 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
861 SCROLL_trackVertical = vertical;
862 SCROLL_trackHitTest = hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
863 lastClickPos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
864 lastMousePos = lastClickPos;
865 trackThumbPos = thumbPos;
866 prevPt = pt;
867 if (nBar == SB_CTL && (GetWindowLongW(hwnd, GWL_STYLE) & WS_TABSTOP)) SetFocus( hwnd );
868 SetCapture( hwnd );
869 break;
871 case WM_MOUSEMOVE:
872 hittest = SCROLL_HitTest( hwnd, nBar, pt, TRUE );
873 prevPt = pt;
874 break;
876 case WM_LBUTTONUP:
877 hittest = SCROLL_NOWHERE;
878 ReleaseCapture();
879 /* if scrollbar has focus, show back caret */
880 if (hwnd==GetFocus()) ShowCaret(hwnd);
881 break;
883 case WM_SYSTIMER:
884 pt = prevPt;
885 hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
886 break;
888 default:
889 return; /* Should never happen */
892 TRACE("Event: hwnd=%p bar=%d msg=%s pt=%d,%d hit=%d\n",
893 hwnd, nBar, SPY_GetMsgName(msg,hwnd), pt.x, pt.y, hittest );
895 switch(SCROLL_trackHitTest)
897 case SCROLL_NOWHERE: /* No tracking in progress */
898 break;
900 case SCROLL_TOP_ARROW:
901 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
902 (hittest == SCROLL_trackHitTest), FALSE );
903 if (hittest == SCROLL_trackHitTest)
905 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
907 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
908 SB_LINEUP, (LPARAM)hwndCtl );
911 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
912 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
913 (TIMERPROC)0 );
915 else KillSystemTimer( hwnd, SCROLL_TIMER );
916 break;
918 case SCROLL_TOP_RECT:
919 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
920 thumbPos, infoPtr->flags, vertical,
921 (hittest == SCROLL_trackHitTest), FALSE );
922 if (hittest == SCROLL_trackHitTest)
924 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
926 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
927 SB_PAGEUP, (LPARAM)hwndCtl );
929 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
930 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
931 (TIMERPROC)0 );
933 else KillSystemTimer( hwnd, SCROLL_TIMER );
934 break;
936 case SCROLL_THUMB:
937 if (msg == WM_LBUTTONDOWN)
939 SCROLL_TrackingWin = hwnd;
940 SCROLL_TrackingBar = nBar;
941 SCROLL_TrackingPos = trackThumbPos + lastMousePos - lastClickPos;
942 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
943 vertical,
944 SCROLL_TrackingPos );
945 if (!SCROLL_MovingThumb)
946 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
948 else if (msg == WM_LBUTTONUP)
950 if (SCROLL_MovingThumb)
951 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
953 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
954 thumbPos, infoPtr->flags, vertical,
955 FALSE, FALSE );
957 else /* WM_MOUSEMOVE */
959 INT pos;
961 if (!SCROLL_PtInRectEx( &rect, pt, vertical )) pos = lastClickPos;
962 else
964 pt = SCROLL_ClipPos( &rect, pt );
965 pos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
967 if ( (pos != lastMousePos) || (!SCROLL_MovingThumb) )
969 if (SCROLL_MovingThumb)
970 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
971 arrowSize, thumbSize );
972 lastMousePos = pos;
973 SCROLL_TrackingPos = trackThumbPos + pos - lastClickPos;
974 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
975 vertical,
976 SCROLL_TrackingPos );
977 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
978 MAKEWPARAM( SB_THUMBTRACK, SCROLL_TrackingVal),
979 (LPARAM)hwndCtl );
980 if (!SCROLL_MovingThumb)
981 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
982 arrowSize, thumbSize );
985 break;
987 case SCROLL_BOTTOM_RECT:
988 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
989 thumbPos, infoPtr->flags, vertical,
990 FALSE, (hittest == SCROLL_trackHitTest) );
991 if (hittest == SCROLL_trackHitTest)
993 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
995 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
996 SB_PAGEDOWN, (LPARAM)hwndCtl );
998 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
999 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1000 (TIMERPROC)0 );
1002 else KillSystemTimer( hwnd, SCROLL_TIMER );
1003 break;
1005 case SCROLL_BOTTOM_ARROW:
1006 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
1007 FALSE, (hittest == SCROLL_trackHitTest) );
1008 if (hittest == SCROLL_trackHitTest)
1010 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1012 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1013 SB_LINEDOWN, (LPARAM)hwndCtl );
1016 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1017 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1018 (TIMERPROC)0 );
1020 else KillSystemTimer( hwnd, SCROLL_TIMER );
1021 break;
1024 if (msg == WM_LBUTTONDOWN)
1027 if (hittest == SCROLL_THUMB)
1029 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1030 trackThumbPos + lastMousePos - lastClickPos );
1031 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1032 MAKEWPARAM( SB_THUMBTRACK, val ), (LPARAM)hwndCtl );
1036 if (msg == WM_LBUTTONUP)
1038 hittest = SCROLL_trackHitTest;
1039 SCROLL_trackHitTest = SCROLL_NOWHERE; /* Terminate tracking */
1041 if (hittest == SCROLL_THUMB)
1043 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1044 trackThumbPos + lastMousePos - lastClickPos );
1045 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1046 MAKEWPARAM( SB_THUMBPOSITION, val ), (LPARAM)hwndCtl );
1048 /* SB_ENDSCROLL doesn't report thumb position */
1049 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1050 SB_ENDSCROLL, (LPARAM)hwndCtl );
1052 /* Terminate tracking */
1053 SCROLL_TrackingWin = 0;
1056 ReleaseDC( hwnd, hdc );
1060 /***********************************************************************
1061 * SCROLL_TrackScrollBar
1063 * Track a mouse button press on a scroll-bar.
1064 * pt is in screen-coordinates for non-client scroll bars.
1066 void SCROLL_TrackScrollBar( HWND hwnd, INT scrollbar, POINT pt )
1068 MSG msg;
1069 INT xoffset = 0, yoffset = 0;
1071 if (scrollbar != SB_CTL)
1073 WND *wndPtr = WIN_GetPtr( hwnd );
1074 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return;
1075 xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
1076 yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
1077 WIN_ReleasePtr( wndPtr );
1078 ScreenToClient( hwnd, &pt );
1079 pt.x += xoffset;
1080 pt.y += yoffset;
1083 SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt );
1087 if (!GetMessageW( &msg, 0, 0, 0 )) break;
1088 if (CallMsgFilterW( &msg, MSGF_SCROLLBAR )) continue;
1089 if (msg.message == WM_LBUTTONUP ||
1090 msg.message == WM_MOUSEMOVE ||
1091 (msg.message == WM_SYSTIMER && msg.wParam == SCROLL_TIMER))
1093 pt.x = (short)LOWORD(msg.lParam) + xoffset;
1094 pt.y = (short)HIWORD(msg.lParam) + yoffset;
1095 SCROLL_HandleScrollEvent( hwnd, scrollbar, msg.message, pt );
1097 else
1099 TranslateMessage( &msg );
1100 DispatchMessageW( &msg );
1102 if (!IsWindow( hwnd ))
1104 ReleaseCapture();
1105 break;
1107 } while (msg.message != WM_LBUTTONUP);
1111 /***********************************************************************
1112 * SCROLL_CreateScrollBar
1114 * Create a scroll bar
1116 * PARAMS
1117 * hwnd [I] Handle of window with scrollbar(s)
1118 * lpCreate [I] The style and place of the scroll bar
1120 static void SCROLL_CreateScrollBar(HWND hwnd, LPCREATESTRUCTW lpCreate)
1122 LPSCROLLBAR_INFO info = SCROLL_GetInternalInfo(hwnd, SB_CTL, TRUE);
1123 if (!info) return;
1125 TRACE("hwnd=%p lpCreate=%p\n", hwnd, lpCreate);
1127 if (lpCreate->style & WS_DISABLED)
1129 info->flags = ESB_DISABLE_BOTH;
1130 TRACE("Created WS_DISABLED scrollbar\n");
1134 if (lpCreate->style & (SBS_SIZEGRIP | SBS_SIZEBOX))
1136 if (lpCreate->style & SBS_SIZEBOXTOPLEFTALIGN)
1137 MoveWindow( hwnd, lpCreate->x, lpCreate->y, GetSystemMetrics(SM_CXVSCROLL)+1,
1138 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1139 else if(lpCreate->style & SBS_SIZEBOXBOTTOMRIGHTALIGN)
1140 MoveWindow( hwnd, lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1141 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1142 GetSystemMetrics(SM_CXVSCROLL)+1,
1143 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1145 else if (lpCreate->style & SBS_VERT)
1147 if (lpCreate->style & SBS_LEFTALIGN)
1148 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1149 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1150 else if (lpCreate->style & SBS_RIGHTALIGN)
1151 MoveWindow( hwnd,
1152 lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1153 lpCreate->y,
1154 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1156 else /* SBS_HORZ */
1158 if (lpCreate->style & SBS_TOPALIGN)
1159 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1160 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1161 else if (lpCreate->style & SBS_BOTTOMALIGN)
1162 MoveWindow( hwnd,
1163 lpCreate->x,
1164 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1165 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1170 /*************************************************************************
1171 * SCROLL_GetScrollInfo
1173 * Internal helper for the API function
1175 * PARAMS
1176 * hwnd [I] Handle of window with scrollbar(s)
1177 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1178 * info [IO] fMask specifies which values to retrieve
1180 * RETURNS
1181 * FALSE if requested field not filled (f.i. scroll bar does not exist)
1183 static BOOL SCROLL_GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1185 LPSCROLLBAR_INFO infoPtr;
1187 /* handle invalid data structure */
1188 if (!SCROLL_ScrollInfoValid(info)
1189 || !(infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE)))
1190 return FALSE;
1192 /* fill in the desired scroll info structure */
1193 if (info->fMask & SIF_PAGE) info->nPage = infoPtr->page;
1194 if (info->fMask & SIF_POS) info->nPos = infoPtr->curVal;
1195 if ((info->fMask & SIF_TRACKPOS) && (info->cbSize == sizeof(*info)))
1196 info->nTrackPos = (SCROLL_TrackingWin == WIN_GetFullHandle(hwnd)) ? SCROLL_TrackingVal : infoPtr->curVal;
1197 if (info->fMask & SIF_RANGE)
1199 info->nMin = infoPtr->minVal;
1200 info->nMax = infoPtr->maxVal;
1203 TRACE("cbSize %02x fMask %04x nMin %d nMax %d nPage %u nPos %d nTrackPos %d\n",
1204 info->cbSize, info->fMask, info->nMin, info->nMax, info->nPage,
1205 info->nPos, info->nTrackPos);
1207 return (info->fMask & SIF_ALL) != 0;
1211 /*************************************************************************
1212 * SCROLL_GetScrollBarInfo
1214 * Internal helper for the API function
1216 * PARAMS
1217 * hwnd [I] Handle of window with scrollbar(s)
1218 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1219 * info [IO] cbSize specifies the size of the structure
1221 * RETURNS
1222 * FALSE if failed
1224 static BOOL SCROLL_GetScrollBarInfo(HWND hwnd, LONG idObject, LPSCROLLBARINFO info)
1226 LPSCROLLBAR_INFO infoPtr;
1227 INT nBar;
1228 INT nDummy;
1229 DWORD style = GetWindowLongW(hwnd, GWL_STYLE);
1230 BOOL pressed;
1232 switch (idObject)
1234 case OBJID_CLIENT: nBar = SB_CTL; break;
1235 case OBJID_HSCROLL: nBar = SB_HORZ; break;
1236 case OBJID_VSCROLL: nBar = SB_VERT; break;
1237 default: return FALSE;
1240 /* handle invalid data structure */
1241 if (info->cbSize != sizeof(*info))
1242 return FALSE;
1244 SCROLL_GetScrollBarRect(hwnd, nBar, &info->rcScrollBar, &nDummy,
1245 &info->dxyLineButton, &info->xyThumbTop);
1247 info->xyThumbBottom = info->xyThumbTop + info->dxyLineButton;
1249 infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, TRUE);
1251 /* Scroll bar state */
1252 info->rgstate[0] = 0;
1253 if ((nBar == SB_HORZ && !(style & WS_HSCROLL))
1254 || (nBar == SB_VERT && !(style & WS_VSCROLL)))
1255 info->rgstate[0] |= STATE_SYSTEM_INVISIBLE;
1256 if (infoPtr->minVal >= infoPtr->maxVal - max(infoPtr->page - 1, 0))
1258 if (!(info->rgstate[0] & STATE_SYSTEM_INVISIBLE))
1259 info->rgstate[0] |= STATE_SYSTEM_UNAVAILABLE;
1260 else
1261 info->rgstate[0] |= STATE_SYSTEM_OFFSCREEN;
1263 if (nBar == SB_CTL && !IsWindowEnabled(hwnd))
1264 info->rgstate[0] |= STATE_SYSTEM_UNAVAILABLE;
1266 pressed = ((nBar == SB_VERT) == SCROLL_trackVertical && GetCapture() == hwnd);
1268 /* Top/left arrow button state. MSDN says top/right, but I don't believe it */
1269 info->rgstate[1] = 0;
1270 if (pressed && SCROLL_trackHitTest == SCROLL_TOP_ARROW)
1271 info->rgstate[1] |= STATE_SYSTEM_PRESSED;
1272 if (infoPtr->flags & ESB_DISABLE_LTUP)
1273 info->rgstate[1] |= STATE_SYSTEM_UNAVAILABLE;
1275 /* Page up/left region state. MSDN says up/right, but I don't believe it */
1276 info->rgstate[2] = 0;
1277 if (infoPtr->curVal == infoPtr->minVal)
1278 info->rgstate[2] |= STATE_SYSTEM_INVISIBLE;
1279 if (pressed && SCROLL_trackHitTest == SCROLL_TOP_RECT)
1280 info->rgstate[2] |= STATE_SYSTEM_PRESSED;
1282 /* Thumb state */
1283 info->rgstate[3] = 0;
1284 if (pressed && SCROLL_trackHitTest == SCROLL_THUMB)
1285 info->rgstate[3] |= STATE_SYSTEM_PRESSED;
1287 /* Page down/right region state. MSDN says down/left, but I don't believe it */
1288 info->rgstate[4] = 0;
1289 if (infoPtr->curVal >= infoPtr->maxVal - 1)
1290 info->rgstate[4] |= STATE_SYSTEM_INVISIBLE;
1291 if (pressed && SCROLL_trackHitTest == SCROLL_BOTTOM_RECT)
1292 info->rgstate[4] |= STATE_SYSTEM_PRESSED;
1294 /* Bottom/right arrow button state. MSDN says bottom/left, but I don't believe it */
1295 info->rgstate[5] = 0;
1296 if (pressed && SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW)
1297 info->rgstate[5] |= STATE_SYSTEM_PRESSED;
1298 if (infoPtr->flags & ESB_DISABLE_RTDN)
1299 info->rgstate[5] |= STATE_SYSTEM_UNAVAILABLE;
1301 return TRUE;
1305 /*************************************************************************
1306 * SCROLL_GetScrollPos
1308 * Internal helper for the API function
1310 * PARAMS
1311 * hwnd [I] Handle of window with scrollbar(s)
1312 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1314 static INT SCROLL_GetScrollPos(HWND hwnd, INT nBar)
1316 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1317 return infoPtr ? infoPtr->curVal: 0;
1321 /*************************************************************************
1322 * SCROLL_GetScrollRange
1324 * Internal helper for the API function
1326 * PARAMS
1327 * hwnd [I] Handle of window with scrollbar(s)
1328 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1329 * lpMin [O] Where to store minimum value
1330 * lpMax [O] Where to store maximum value
1332 * RETURNS
1333 * Success: TRUE
1334 * Failure: FALSE
1336 static BOOL SCROLL_GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1338 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1340 if (lpMin) *lpMin = infoPtr ? infoPtr->minVal : 0;
1341 if (lpMax) *lpMax = infoPtr ? infoPtr->maxVal : 0;
1343 return TRUE;
1347 /*************************************************************************
1348 * SCROLL_SetScrollRange
1350 * PARAMS
1351 * hwnd [I] Handle of window with scrollbar(s)
1352 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1353 * lpMin [I] Minimum value
1354 * lpMax [I] Maximum value
1357 static BOOL SCROLL_SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal)
1359 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1361 TRACE("hwnd=%p nBar=%d min=%d max=%d\n", hwnd, nBar, minVal, maxVal);
1363 if (infoPtr)
1365 infoPtr->minVal = minVal;
1366 infoPtr->maxVal = maxVal;
1368 return TRUE;
1372 /***********************************************************************
1373 * ScrollBarWndProc
1375 static LRESULT ScrollBarWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, BOOL unicode )
1377 if (!IsWindow( hwnd )) return 0;
1379 switch(message)
1381 case WM_CREATE:
1382 SCROLL_CreateScrollBar(hwnd, (LPCREATESTRUCTW)lParam);
1383 break;
1385 case WM_ENABLE:
1387 SCROLLBAR_INFO *infoPtr;
1388 if ((infoPtr = SCROLL_GetInternalInfo( hwnd, SB_CTL, FALSE )))
1390 infoPtr->flags = wParam ? ESB_ENABLE_BOTH : ESB_DISABLE_BOTH;
1391 SCROLL_RefreshScrollBar(hwnd, SB_CTL, TRUE, TRUE);
1394 return 0;
1396 case WM_LBUTTONDBLCLK:
1397 case WM_LBUTTONDOWN:
1399 POINT pt;
1400 pt.x = (short)LOWORD(lParam);
1401 pt.y = (short)HIWORD(lParam);
1402 SCROLL_TrackScrollBar( hwnd, SB_CTL, pt );
1404 break;
1405 case WM_LBUTTONUP:
1406 case WM_MOUSEMOVE:
1407 case WM_SYSTIMER:
1409 POINT pt;
1410 pt.x = (short)LOWORD(lParam);
1411 pt.y = (short)HIWORD(lParam);
1412 SCROLL_HandleScrollEvent( hwnd, SB_CTL, message, pt );
1414 break;
1416 case WM_KEYDOWN:
1417 SCROLL_HandleKbdEvent(hwnd, wParam, lParam);
1418 break;
1420 case WM_KEYUP:
1421 ShowCaret(hwnd);
1422 break;
1424 case WM_SETFOCUS:
1426 /* Create a caret when a ScrollBar get focus */
1427 RECT rect;
1428 int arrowSize, thumbSize, thumbPos, vertical;
1429 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,
1430 &arrowSize, &thumbSize, &thumbPos );
1431 if (!vertical)
1433 CreateCaret(hwnd, (HBITMAP)1, thumbSize-2, rect.bottom-rect.top-2);
1434 SetCaretPos(thumbPos+1, rect.top+1);
1436 else
1438 CreateCaret(hwnd, (HBITMAP)1, rect.right-rect.left-2,thumbSize-2);
1439 SetCaretPos(rect.top+1, thumbPos+1);
1441 ShowCaret(hwnd);
1443 break;
1445 case WM_KILLFOCUS:
1447 RECT rect;
1448 int arrowSize, thumbSize, thumbPos, vertical;
1449 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,&arrowSize, &thumbSize, &thumbPos );
1450 if (!vertical){
1451 rect.left=thumbPos+1;
1452 rect.right=rect.left+thumbSize;
1454 else
1456 rect.top=thumbPos+1;
1457 rect.bottom=rect.top+thumbSize;
1459 HideCaret(hwnd);
1460 InvalidateRect(hwnd,&rect,0);
1461 DestroyCaret();
1463 break;
1465 case WM_ERASEBKGND:
1466 return 1;
1468 case WM_GETDLGCODE:
1469 return DLGC_WANTARROWS; /* Windows returns this value */
1471 case WM_PAINT:
1473 PAINTSTRUCT ps;
1474 HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
1475 if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEGRIP)
1477 SCROLL_DrawSizeGrip( hwnd, hdc);
1479 else if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEBOX)
1481 RECT rc;
1482 GetClientRect( hwnd, &rc );
1483 FillRect( hdc, &rc, GetSysColorBrush(COLOR_SCROLLBAR) );
1485 else
1486 SCROLL_DrawScrollBar( hwnd, hdc, SB_CTL, TRUE, TRUE );
1487 if (!wParam) EndPaint(hwnd, &ps);
1489 break;
1491 case SBM_SETPOS16:
1492 case SBM_SETPOS:
1493 return SetScrollPos( hwnd, SB_CTL, wParam, (BOOL)lParam );
1495 case SBM_GETPOS16:
1496 case SBM_GETPOS:
1497 return SCROLL_GetScrollPos(hwnd, SB_CTL);
1499 case SBM_SETRANGE16:
1500 if (wParam) message = SBM_SETRANGEREDRAW;
1501 wParam = LOWORD(lParam);
1502 lParam = HIWORD(lParam);
1503 /* fall through */
1504 case SBM_SETRANGEREDRAW:
1505 case SBM_SETRANGE:
1507 INT oldPos = SCROLL_GetScrollPos( hwnd, SB_CTL );
1508 SCROLL_SetScrollRange( hwnd, SB_CTL, wParam, lParam );
1509 if (message == SBM_SETRANGEREDRAW)
1510 SCROLL_RefreshScrollBar( hwnd, SB_CTL, TRUE, TRUE );
1511 if (oldPos != SCROLL_GetScrollPos( hwnd, SB_CTL )) return oldPos;
1513 return 0;
1515 case SBM_GETRANGE16:
1517 INT min, max;
1519 SCROLL_GetScrollRange(hwnd, SB_CTL, &min, &max);
1520 return MAKELRESULT(min, max);
1523 case SBM_GETRANGE:
1524 return SCROLL_GetScrollRange(hwnd, SB_CTL, (LPINT)wParam, (LPINT)lParam);
1526 case SBM_ENABLE_ARROWS16:
1527 case SBM_ENABLE_ARROWS:
1528 return EnableScrollBar( hwnd, SB_CTL, wParam );
1530 case SBM_SETSCROLLINFO:
1531 return SCROLL_SetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam, wParam );
1533 case SBM_GETSCROLLINFO:
1534 return SCROLL_GetScrollInfo(hwnd, SB_CTL, (SCROLLINFO *)lParam);
1536 case SBM_GETSCROLLBARINFO:
1537 return SCROLL_GetScrollBarInfo(hwnd, OBJID_CLIENT, (SCROLLBARINFO *)lParam);
1539 case 0x00e5:
1540 case 0x00e7:
1541 case 0x00e8:
1542 case 0x00ec:
1543 case 0x00ed:
1544 case 0x00ee:
1545 case 0x00ef:
1546 ERR("unknown Win32 msg %04x wp=%08lx lp=%08lx\n",
1547 message, wParam, lParam );
1548 break;
1550 default:
1551 if (message >= WM_USER)
1552 WARN("unknown msg %04x wp=%04lx lp=%08lx\n",
1553 message, wParam, lParam );
1554 if (unicode)
1555 return DefWindowProcW( hwnd, message, wParam, lParam );
1556 else
1557 return DefWindowProcA( hwnd, message, wParam, lParam );
1559 return 0;
1563 /***********************************************************************
1564 * ScrollBarWndProcA
1566 static LRESULT WINAPI ScrollBarWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1568 return ScrollBarWndProc( hwnd, message, wParam, lParam, FALSE );
1572 /***********************************************************************
1573 * ScrollBarWndProcW
1575 static LRESULT WINAPI ScrollBarWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1577 return ScrollBarWndProc( hwnd, message, wParam, lParam, TRUE );
1581 /*************************************************************************
1582 * SetScrollInfo (USER32.@)
1584 * SetScrollInfo can be used to set the position, upper bound,
1585 * lower bound, and page size of a scrollbar control.
1587 * PARAMS
1588 * hwnd [I] Handle of window with scrollbar(s)
1589 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1590 * info [I] Specifies what to change and new values
1591 * bRedraw [I] Should scrollbar be redrawn afterwards?
1593 * RETURNS
1594 * Scrollbar position
1596 * NOTE
1597 * For 100 lines of text to be displayed in a window of 25 lines,
1598 * one would for instance use info->nMin=0, info->nMax=75
1599 * (corresponding to the 76 different positions of the window on
1600 * the text), and info->nPage=25.
1602 INT WINAPI SetScrollInfo(HWND hwnd, INT nBar, const SCROLLINFO *info, BOOL bRedraw)
1604 TRACE("hwnd=%p nBar=%d info=%p, bRedraw=%d\n", hwnd, nBar, info, bRedraw);
1606 /* Refer SB_CTL requests to the window */
1607 if (nBar == SB_CTL)
1608 return SendMessageW(hwnd, SBM_SETSCROLLINFO, bRedraw, (LPARAM)info);
1609 else
1610 return SCROLL_SetScrollInfo( hwnd, nBar, info, bRedraw );
1613 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar, LPCSCROLLINFO info, BOOL bRedraw )
1615 /* Update the scrollbar state and set action flags according to
1616 * what has to be done graphics wise. */
1618 SCROLLBAR_INFO *infoPtr;
1619 UINT new_flags;
1620 INT action = 0;
1622 /* handle invalid data structure */
1623 if (!SCROLL_ScrollInfoValid(info)
1624 || !(infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, TRUE)))
1625 return 0;
1627 if (TRACE_ON(scroll))
1629 TRACE("hwnd=%p bar=%d", hwnd, nBar);
1630 if (info->fMask & SIF_PAGE) TRACE( " page=%d", info->nPage );
1631 if (info->fMask & SIF_POS) TRACE( " pos=%d", info->nPos );
1632 if (info->fMask & SIF_RANGE) TRACE( " min=%d max=%d", info->nMin, info->nMax );
1633 TRACE("\n");
1636 /* Set the page size */
1638 if (info->fMask & SIF_PAGE)
1640 if( infoPtr->page != info->nPage )
1642 infoPtr->page = info->nPage;
1643 action |= SA_SSI_REFRESH;
1647 /* Set the scroll pos */
1649 if (info->fMask & SIF_POS)
1651 if( infoPtr->curVal != info->nPos )
1653 infoPtr->curVal = info->nPos;
1654 action |= SA_SSI_REFRESH;
1658 /* Set the scroll range */
1660 if (info->fMask & SIF_RANGE)
1662 /* Invalid range -> range is set to (0,0) */
1663 if ((info->nMin > info->nMax) ||
1664 ((UINT)(info->nMax - info->nMin) >= 0x80000000))
1666 action |= SA_SSI_REFRESH;
1667 infoPtr->minVal = 0;
1668 infoPtr->maxVal = 0;
1670 else
1672 if( infoPtr->minVal != info->nMin ||
1673 infoPtr->maxVal != info->nMax )
1675 action |= SA_SSI_REFRESH;
1676 infoPtr->minVal = info->nMin;
1677 infoPtr->maxVal = info->nMax;
1682 /* Make sure the page size is valid */
1683 if (infoPtr->page < 0) infoPtr->page = 0;
1684 else if (infoPtr->page > infoPtr->maxVal - infoPtr->minVal + 1 )
1685 infoPtr->page = infoPtr->maxVal - infoPtr->minVal + 1;
1687 /* Make sure the pos is inside the range */
1689 if (infoPtr->curVal < infoPtr->minVal)
1690 infoPtr->curVal = infoPtr->minVal;
1691 else if (infoPtr->curVal > infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1692 infoPtr->curVal = infoPtr->maxVal - max( infoPtr->page-1, 0 );
1694 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1695 infoPtr->page, infoPtr->curVal,
1696 infoPtr->minVal, infoPtr->maxVal );
1698 /* don't change the scrollbar state if SetScrollInfo
1699 * is just called with SIF_DISABLENOSCROLL
1701 if(!(info->fMask & SIF_ALL)) goto done;
1703 /* Check if the scrollbar should be hidden or disabled */
1705 if (info->fMask & (SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL))
1707 new_flags = infoPtr->flags;
1708 if (infoPtr->minVal >= infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1710 /* Hide or disable scroll-bar */
1711 if (info->fMask & SIF_DISABLENOSCROLL)
1713 new_flags = ESB_DISABLE_BOTH;
1714 action |= SA_SSI_REFRESH;
1716 else if ((nBar != SB_CTL) && (action & SA_SSI_REFRESH))
1718 action = SA_SSI_HIDE;
1721 else /* Show and enable scroll-bar only if no page only changed. */
1722 if (info->fMask != SIF_PAGE)
1724 new_flags = ESB_ENABLE_BOTH;
1725 if ((nBar != SB_CTL) && ( (action & SA_SSI_REFRESH) ))
1726 action |= SA_SSI_SHOW;
1729 if (infoPtr->flags != new_flags) /* check arrow flags */
1731 infoPtr->flags = new_flags;
1732 action |= SA_SSI_REPAINT_ARROWS;
1736 done:
1737 if( action & SA_SSI_HIDE )
1738 SCROLL_ShowScrollBar( hwnd, nBar, FALSE, FALSE );
1739 else
1741 if( action & SA_SSI_SHOW )
1742 if( SCROLL_ShowScrollBar( hwnd, nBar, TRUE, TRUE ) )
1743 return infoPtr->curVal; /* SetWindowPos() already did the painting */
1745 if( bRedraw )
1746 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
1747 else if( action & SA_SSI_REPAINT_ARROWS )
1748 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, FALSE );
1751 /* Return current position */
1752 return infoPtr->curVal;
1756 /*************************************************************************
1757 * GetScrollInfo (USER32.@)
1759 * GetScrollInfo can be used to retrieve the position, upper bound,
1760 * lower bound, and page size of a scrollbar control.
1762 * PARAMS
1763 * hwnd [I] Handle of window with scrollbar(s)
1764 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1765 * info [IO] fMask specifies which values to retrieve
1767 * RETURNS
1768 * TRUE if SCROLLINFO is filled
1769 * ( if nBar is SB_CTL, GetScrollInfo returns TRUE even if nothing
1770 * is filled)
1772 BOOL WINAPI GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1774 TRACE("hwnd=%p nBar=%d info=%p\n", hwnd, nBar, info);
1776 /* Refer SB_CTL requests to the window */
1777 if (nBar == SB_CTL)
1779 SendMessageW(hwnd, SBM_GETSCROLLINFO, (WPARAM)0, (LPARAM)info);
1780 return TRUE;
1782 return SCROLL_GetScrollInfo(hwnd, nBar, info);
1786 /*************************************************************************
1787 * GetScrollBarInfo (USER32.@)
1789 * GetScrollBarInfo can be used to retrieve information about a scrollbar
1790 * control.
1792 * PARAMS
1793 * hwnd [I] Handle of window with scrollbar(s)
1794 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1795 * info [IO] cbSize specifies the size of SCROLLBARINFO
1797 * RETURNS
1798 * TRUE if success
1800 BOOL WINAPI GetScrollBarInfo(HWND hwnd, LONG idObject, LPSCROLLBARINFO info)
1802 TRACE("hwnd=%p idObject=%d info=%p\n", hwnd, idObject, info);
1804 /* Refer OBJID_CLIENT requests to the window */
1805 if (idObject == OBJID_CLIENT)
1806 return SendMessageW(hwnd, SBM_GETSCROLLBARINFO, (WPARAM)0, (LPARAM)info);
1807 else
1808 return SCROLL_GetScrollBarInfo(hwnd, idObject, info);
1812 /*************************************************************************
1813 * SetScrollPos (USER32.@)
1815 * Sets the current position of the scroll thumb.
1817 * PARAMS
1818 * hwnd [I] Handle of window with scrollbar(s)
1819 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1820 * nPos [I] New value
1821 * bRedraw [I] Should scrollbar be redrawn afterwards?
1823 * RETURNS
1824 * Success: Scrollbar position
1825 * Failure: 0
1827 * REMARKS
1828 * Note the ambiguity when 0 is returned. Use GetLastError
1829 * to make sure there was an error (and to know which one).
1831 INT WINAPI SetScrollPos( HWND hwnd, INT nBar, INT nPos, BOOL bRedraw)
1833 SCROLLINFO info;
1834 SCROLLBAR_INFO *infoPtr;
1835 INT oldPos;
1837 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, FALSE ))) return 0;
1838 oldPos = infoPtr->curVal;
1839 info.cbSize = sizeof(info);
1840 info.nPos = nPos;
1841 info.fMask = SIF_POS;
1842 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1843 return oldPos;
1847 /*************************************************************************
1848 * GetScrollPos (USER32.@)
1850 * Gets the current position of the scroll thumb.
1852 * PARAMS
1853 * hwnd [I] Handle of window with scrollbar(s)
1854 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1856 * RETURNS
1857 * Success: Current position
1858 * Failure: 0
1860 * REMARKS
1861 * There is ambiguity when 0 is returned. Use GetLastError
1862 * to make sure there was an error (and to know which one).
1864 INT WINAPI GetScrollPos(HWND hwnd, INT nBar)
1866 TRACE("hwnd=%p nBar=%d\n", hwnd, nBar);
1868 /* Refer SB_CTL requests to the window */
1869 if (nBar == SB_CTL)
1870 return SendMessageW(hwnd, SBM_GETPOS, (WPARAM)0, (LPARAM)0);
1871 else
1872 return SCROLL_GetScrollPos(hwnd, nBar);
1876 /*************************************************************************
1877 * SetScrollRange (USER32.@)
1878 * The SetScrollRange function sets the minimum and maximum scroll box positions
1879 * If nMinPos and nMaxPos is the same value, the scroll bar will hide
1881 * Sets the range of the scroll bar.
1883 * PARAMS
1884 * hwnd [I] Handle of window with scrollbar(s)
1885 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1886 * minVal [I] New minimum value
1887 * maxVal [I] New Maximum value
1888 * bRedraw [I] Should scrollbar be redrawn afterwards?
1890 * RETURNS
1891 * Success: TRUE
1892 * Failure: FALSE
1894 BOOL WINAPI SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal, BOOL bRedraw)
1896 SCROLLINFO info;
1898 TRACE("hwnd=%p nBar=%d min=%d max=%d, bRedraw=%d\n", hwnd, nBar, minVal, maxVal, bRedraw);
1900 info.cbSize = sizeof(info);
1901 info.fMask = SIF_RANGE;
1902 info.nMin = minVal;
1903 info.nMax = maxVal;
1904 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1905 return TRUE;
1909 /*************************************************************************
1910 * SCROLL_SetNCSbState
1912 * Updates both scrollbars at the same time. Used by MDI CalcChildScroll().
1914 INT SCROLL_SetNCSbState(HWND hwnd, int vMin, int vMax, int vPos,
1915 int hMin, int hMax, int hPos)
1917 SCROLLINFO vInfo, hInfo;
1919 vInfo.cbSize = hInfo.cbSize = sizeof(SCROLLINFO);
1920 vInfo.nMin = vMin;
1921 vInfo.nMax = vMax;
1922 vInfo.nPos = vPos;
1923 hInfo.nMin = hMin;
1924 hInfo.nMax = hMax;
1925 hInfo.nPos = hPos;
1926 vInfo.fMask = hInfo.fMask = SIF_RANGE | SIF_POS;
1928 SCROLL_SetScrollInfo( hwnd, SB_VERT, &vInfo, TRUE );
1929 SCROLL_SetScrollInfo( hwnd, SB_HORZ, &hInfo, TRUE );
1931 return 0;
1935 /*************************************************************************
1936 * GetScrollRange (USER32.@)
1938 * Gets the range of the scroll bar.
1940 * PARAMS
1941 * hwnd [I] Handle of window with scrollbar(s)
1942 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1943 * lpMin [O] Where to store minimum value
1944 * lpMax [O] Where to store maximum value
1946 * RETURNS
1947 * TRUE if values is filled
1949 BOOL WINAPI GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1951 TRACE("hwnd=%p nBar=%d lpMin=%p lpMax=%p\n", hwnd, nBar, lpMin, lpMax);
1953 /* Refer SB_CTL requests to the window */
1954 if (nBar == SB_CTL)
1955 SendMessageW(hwnd, SBM_GETRANGE, (WPARAM)lpMin, (LPARAM)lpMax);
1956 else
1957 SCROLL_GetScrollRange(hwnd, nBar, lpMin, lpMax);
1959 return TRUE;
1963 /*************************************************************************
1964 * SCROLL_ShowScrollBar()
1966 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1968 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar, BOOL fShowH, BOOL fShowV )
1970 ULONG old_style, set_bits = 0, clear_bits = 0;
1972 TRACE("hwnd=%p bar=%d horz=%d, vert=%d\n", hwnd, nBar, fShowH, fShowV );
1974 switch(nBar)
1976 case SB_CTL:
1977 ShowWindow( hwnd, fShowH ? SW_SHOW : SW_HIDE );
1978 return TRUE;
1980 case SB_BOTH:
1981 case SB_HORZ:
1982 if (fShowH) set_bits |= WS_HSCROLL;
1983 else clear_bits |= WS_HSCROLL;
1984 if( nBar == SB_HORZ ) break;
1985 /* fall through */
1986 case SB_VERT:
1987 if (fShowV) set_bits |= WS_VSCROLL;
1988 else clear_bits |= WS_VSCROLL;
1989 break;
1991 default:
1992 return FALSE; /* Nothing to do! */
1995 old_style = WIN_SetStyle( hwnd, set_bits, clear_bits );
1996 if ((old_style & clear_bits) != 0 || (old_style & set_bits) != set_bits)
1998 /* frame has been changed, let the window redraw itself */
1999 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
2000 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
2001 return TRUE;
2003 return FALSE; /* no frame changes */
2007 /*************************************************************************
2008 * ShowScrollBar (USER32.@)
2010 * Shows or hides the scroll bar.
2012 * PARAMS
2013 * hwnd [I] Handle of window with scrollbar(s)
2014 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
2015 * fShow [I] TRUE = show, FALSE = hide
2017 * RETURNS
2018 * Success: TRUE
2019 * Failure: FALSE
2021 BOOL WINAPI ShowScrollBar(HWND hwnd, INT nBar, BOOL fShow)
2023 if ( !hwnd )
2024 return FALSE;
2026 SCROLL_ShowScrollBar( hwnd, nBar, (nBar == SB_VERT) ? 0 : fShow,
2027 (nBar == SB_HORZ) ? 0 : fShow );
2028 return TRUE;
2032 /*************************************************************************
2033 * EnableScrollBar (USER32.@)
2035 * Enables or disables the scroll bars.
2037 BOOL WINAPI EnableScrollBar( HWND hwnd, UINT nBar, UINT flags )
2039 BOOL bFineWithMe;
2040 SCROLLBAR_INFO *infoPtr;
2042 flags &= ESB_DISABLE_BOTH;
2044 if (nBar == SB_BOTH)
2046 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, SB_VERT, TRUE ))) return FALSE;
2047 if (!(bFineWithMe = (infoPtr->flags == flags)) )
2049 infoPtr->flags = flags;
2050 SCROLL_RefreshScrollBar( hwnd, SB_VERT, TRUE, TRUE );
2052 nBar = SB_HORZ;
2054 else
2055 bFineWithMe = TRUE;
2057 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, TRUE ))) return FALSE;
2058 if (bFineWithMe && infoPtr->flags == flags) return FALSE;
2059 infoPtr->flags = flags;
2061 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
2062 return TRUE;