wined3d: Explicitly pass data and gl_info to shader_deselect_depth_blt().
[wine.git] / dlls / user32 / scroll.c
blobfd73bf458efbc08259935dd61974ff2e79d0555f
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 "controls.h"
37 #include "win.h"
38 #include "wine/debug.h"
39 #include "user_private.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(scroll);
43 /* data for a single scroll bar */
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;
53 /* data for window that has (one or two) scroll bars */
54 typedef struct
56 SCROLLBAR_INFO horz;
57 SCROLLBAR_INFO vert;
58 } WINSCROLLBAR_INFO, *LPWINSCROLLBAR_INFO;
60 /* Minimum size of the rectangle between the arrows */
61 #define SCROLL_MIN_RECT 4
63 /* Minimum size of the thumb in pixels */
64 #define SCROLL_MIN_THUMB 6
66 /* Overlap between arrows and thumb */
67 #define SCROLL_ARROW_THUMB_OVERLAP 0
69 /* Delay (in ms) before first repetition when holding the button down */
70 #define SCROLL_FIRST_DELAY 200
72 /* Delay (in ms) between scroll repetitions */
73 #define SCROLL_REPEAT_DELAY 50
75 /* Scroll timer id */
76 #define SCROLL_TIMER 0
78 /* Scroll-bar hit testing */
79 enum SCROLL_HITTEST
81 SCROLL_NOWHERE, /* Outside the scroll bar */
82 SCROLL_TOP_ARROW, /* Top or left arrow */
83 SCROLL_TOP_RECT, /* Rectangle between the top arrow and the thumb */
84 SCROLL_THUMB, /* Thumb rectangle */
85 SCROLL_BOTTOM_RECT, /* Rectangle between the thumb and the bottom arrow */
86 SCROLL_BOTTOM_ARROW /* Bottom or right arrow */
89 /* What to do after SCROLL_SetScrollInfo() */
90 #define SA_SSI_HIDE 0x0001
91 #define SA_SSI_SHOW 0x0002
92 #define SA_SSI_REFRESH 0x0004
93 #define SA_SSI_REPAINT_ARROWS 0x0008
95 /* Thumb-tracking info */
96 static HWND SCROLL_TrackingWin = 0;
97 static INT SCROLL_TrackingBar = 0;
98 static INT SCROLL_TrackingPos = 0;
99 static INT SCROLL_TrackingVal = 0;
100 /* Hit test code of the last button-down event */
101 static enum SCROLL_HITTEST SCROLL_trackHitTest;
102 static BOOL SCROLL_trackVertical;
104 /* Is the moving thumb being displayed? */
105 static BOOL SCROLL_MovingThumb = FALSE;
107 /* Local functions */
108 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar,
109 BOOL fShowH, BOOL fShowV );
110 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar,
111 const SCROLLINFO *info, BOOL bRedraw );
112 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
113 RECT *rect, INT arrowSize,
114 INT thumbSize, INT thumbPos,
115 UINT flags, BOOL vertical,
116 BOOL top_selected, BOOL bottom_selected );
119 /*********************************************************************
120 * scrollbar class descriptor
122 static const WCHAR scrollbarW[] = {'S','c','r','o','l','l','B','a','r',0};
123 const struct builtin_class_descr SCROLL_builtin_class =
125 scrollbarW, /* name */
126 CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC, /* style */
127 WINPROC_SCROLLBAR, /* proc */
128 sizeof(SCROLLBAR_INFO), /* extra */
129 IDC_ARROW, /* cursor */
130 0 /* brush */
133 /***********************************************************************
134 * SCROLL_ScrollInfoValid
136 * Determine if the supplied SCROLLINFO struct is valid.
137 * info [in] The SCROLLINFO struct to be tested
139 static inline BOOL SCROLL_ScrollInfoValid( LPCSCROLLINFO info )
141 return !(info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)
142 || (info->cbSize != sizeof(*info)
143 && info->cbSize != sizeof(*info) - sizeof(info->nTrackPos)));
147 /***********************************************************************
148 * SCROLL_GetInternalInfo
150 * Returns pointer to internal SCROLLBAR_INFO structure for nBar
151 * or NULL if failed (f.i. scroll bar does not exist yet)
152 * If alloc is TRUE and the struct does not exist yet, create it.
154 static SCROLLBAR_INFO *SCROLL_GetInternalInfo( HWND hwnd, INT nBar, BOOL alloc )
156 SCROLLBAR_INFO *infoPtr = NULL;
157 WND *wndPtr = WIN_GetPtr( hwnd );
159 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return NULL;
160 switch(nBar)
162 case SB_HORZ:
163 if (wndPtr->pScroll) infoPtr = &((LPWINSCROLLBAR_INFO)wndPtr->pScroll)->horz;
164 break;
165 case SB_VERT:
166 if (wndPtr->pScroll) infoPtr = &((LPWINSCROLLBAR_INFO)wndPtr->pScroll)->vert;
167 break;
168 case SB_CTL:
169 infoPtr = (SCROLLBAR_INFO *)wndPtr->wExtra;
170 break;
171 case SB_BOTH:
172 WARN("with SB_BOTH\n");
173 break;
176 if (!infoPtr && alloc)
178 WINSCROLLBAR_INFO *winInfoPtr;
180 if (nBar != SB_HORZ && nBar != SB_VERT)
181 WARN("Cannot initialize nBar=%d\n",nBar);
182 else if ((winInfoPtr = HeapAlloc( GetProcessHeap(), 0, sizeof(WINSCROLLBAR_INFO) )))
184 /* Set default values */
185 winInfoPtr->horz.minVal = 0;
186 winInfoPtr->horz.curVal = 0;
187 winInfoPtr->horz.page = 0;
188 /* From MSDN and our own tests:
189 * max for a standard scroll bar is 100 by default. */
190 winInfoPtr->horz.maxVal = 100;
191 winInfoPtr->horz.flags = ESB_ENABLE_BOTH;
192 winInfoPtr->vert = winInfoPtr->horz;
193 wndPtr->pScroll = winInfoPtr;
194 infoPtr = nBar == SB_HORZ ? &winInfoPtr->horz : &winInfoPtr->vert;
197 WIN_ReleasePtr( wndPtr );
198 return infoPtr;
202 /***********************************************************************
203 * SCROLL_GetScrollBarRect
205 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
206 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
207 * 'arrowSize' returns the width or height of an arrow (depending on
208 * the orientation of the scrollbar), 'thumbSize' returns the size of
209 * the thumb, and 'thumbPos' returns the position of the thumb
210 * relative to the left or to the top.
211 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
213 static BOOL SCROLL_GetScrollBarRect( HWND hwnd, INT nBar, RECT *lprect,
214 INT *arrowSize, INT *thumbSize,
215 INT *thumbPos )
217 INT pixels;
218 BOOL vertical;
219 WND *wndPtr = WIN_GetPtr( hwnd );
221 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
223 switch(nBar)
225 case SB_HORZ:
226 WIN_GetRectangles( hwnd, COORDS_WINDOW, NULL, lprect );
227 lprect->top = lprect->bottom;
228 lprect->bottom += GetSystemMetrics(SM_CYHSCROLL);
229 if(wndPtr->dwStyle & WS_VSCROLL)
230 lprect->right++;
231 vertical = FALSE;
232 break;
234 case SB_VERT:
235 WIN_GetRectangles( hwnd, COORDS_WINDOW, NULL, lprect );
236 if((wndPtr->dwExStyle & WS_EX_LEFTSCROLLBAR) != 0)
238 lprect->right = lprect->left;
239 lprect->left -= GetSystemMetrics(SM_CXVSCROLL);
241 else
243 lprect->left = lprect->right;
244 lprect->right += GetSystemMetrics(SM_CXVSCROLL);
246 if(wndPtr->dwStyle & WS_HSCROLL)
247 lprect->bottom++;
248 vertical = TRUE;
249 break;
251 case SB_CTL:
252 GetClientRect( hwnd, lprect );
253 vertical = ((wndPtr->dwStyle & SBS_VERT) != 0);
254 break;
256 default:
257 WIN_ReleasePtr( wndPtr );
258 return FALSE;
261 if (vertical) pixels = lprect->bottom - lprect->top;
262 else pixels = lprect->right - lprect->left;
264 if (pixels <= 2*GetSystemMetrics(SM_CXVSCROLL) + SCROLL_MIN_RECT)
266 if (pixels > SCROLL_MIN_RECT)
267 *arrowSize = (pixels - SCROLL_MIN_RECT) / 2;
268 else
269 *arrowSize = 0;
270 *thumbPos = *thumbSize = 0;
272 else
274 SCROLLBAR_INFO *info = SCROLL_GetInternalInfo( hwnd, nBar, FALSE );
275 if (!info)
277 WARN("called for missing scroll bar\n");
278 WIN_ReleasePtr( wndPtr );
279 return FALSE;
281 *arrowSize = GetSystemMetrics(SM_CXVSCROLL);
282 pixels -= (2 * (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP));
284 if (info->page)
286 *thumbSize = MulDiv(pixels,info->page,(info->maxVal-info->minVal+1));
287 if (*thumbSize < SCROLL_MIN_THUMB) *thumbSize = SCROLL_MIN_THUMB;
289 else *thumbSize = GetSystemMetrics(SM_CXVSCROLL);
291 if (((pixels -= *thumbSize ) < 0) ||
292 ((info->flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH))
294 /* Rectangle too small or scrollbar disabled -> no thumb */
295 *thumbPos = *thumbSize = 0;
297 else
299 INT max = info->maxVal - max( info->page-1, 0 );
300 if (info->minVal >= max)
301 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
302 else
303 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP
304 + MulDiv(pixels, (info->curVal-info->minVal),(max - info->minVal));
307 WIN_ReleasePtr( wndPtr );
308 return vertical;
312 /***********************************************************************
313 * SCROLL_GetThumbVal
315 * Compute the current scroll position based on the thumb position in pixels
316 * from the top of the scroll-bar.
318 static UINT SCROLL_GetThumbVal( SCROLLBAR_INFO *infoPtr, RECT *rect,
319 BOOL vertical, INT pos )
321 INT thumbSize;
322 INT pixels = vertical ? rect->bottom-rect->top : rect->right-rect->left;
323 INT range;
325 if ((pixels -= 2*(GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP)) <= 0)
326 return infoPtr->minVal;
328 if (infoPtr->page)
330 thumbSize = MulDiv(pixels,infoPtr->page,(infoPtr->maxVal-infoPtr->minVal+1));
331 if (thumbSize < SCROLL_MIN_THUMB) thumbSize = SCROLL_MIN_THUMB;
333 else thumbSize = GetSystemMetrics(SM_CXVSCROLL);
335 if ((pixels -= thumbSize) <= 0) return infoPtr->minVal;
337 pos = max( 0, pos - (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP) );
338 if (pos > pixels) pos = pixels;
340 if (!infoPtr->page)
341 range = infoPtr->maxVal - infoPtr->minVal;
342 else
343 range = infoPtr->maxVal - infoPtr->minVal - infoPtr->page + 1;
345 return infoPtr->minVal + MulDiv(pos, range, pixels);
348 /***********************************************************************
349 * SCROLL_PtInRectEx
351 static BOOL SCROLL_PtInRectEx( LPRECT lpRect, POINT pt, BOOL vertical )
353 RECT rect = *lpRect;
354 int scrollbarWidth;
356 /* Pad hit rect to allow mouse to be dragged outside of scrollbar and
357 * still be considered in the scrollbar. */
358 if (vertical)
360 scrollbarWidth = lpRect->right - lpRect->left;
361 rect.left -= scrollbarWidth*8;
362 rect.right += scrollbarWidth*8;
363 rect.top -= scrollbarWidth*2;
364 rect.bottom += scrollbarWidth*2;
366 else
368 scrollbarWidth = lpRect->bottom - lpRect->top;
369 rect.left -= scrollbarWidth*2;
370 rect.right += scrollbarWidth*2;
371 rect.top -= scrollbarWidth*8;
372 rect.bottom += scrollbarWidth*8;
374 return PtInRect( &rect, pt );
377 /***********************************************************************
378 * SCROLL_ClipPos
380 static POINT SCROLL_ClipPos( LPRECT lpRect, POINT pt )
382 if( pt.x < lpRect->left )
383 pt.x = lpRect->left;
384 else
385 if( pt.x > lpRect->right )
386 pt.x = lpRect->right;
388 if( pt.y < lpRect->top )
389 pt.y = lpRect->top;
390 else
391 if( pt.y > lpRect->bottom )
392 pt.y = lpRect->bottom;
394 return pt;
398 /***********************************************************************
399 * SCROLL_HitTest
401 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
403 static enum SCROLL_HITTEST SCROLL_HitTest( HWND hwnd, INT nBar,
404 POINT pt, BOOL bDragging )
406 INT arrowSize, thumbSize, thumbPos;
407 RECT rect;
409 BOOL vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
410 &arrowSize, &thumbSize, &thumbPos );
412 if ( (bDragging && !SCROLL_PtInRectEx( &rect, pt, vertical )) ||
413 (!PtInRect( &rect, pt )) ) return SCROLL_NOWHERE;
415 if (vertical)
417 if (pt.y < rect.top + arrowSize) return SCROLL_TOP_ARROW;
418 if (pt.y >= rect.bottom - arrowSize) return SCROLL_BOTTOM_ARROW;
419 if (!thumbPos) return SCROLL_TOP_RECT;
420 pt.y -= rect.top;
421 if (pt.y < thumbPos) return SCROLL_TOP_RECT;
422 if (pt.y >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
424 else /* horizontal */
426 if (pt.x < rect.left + arrowSize) return SCROLL_TOP_ARROW;
427 if (pt.x >= rect.right - arrowSize) return SCROLL_BOTTOM_ARROW;
428 if (!thumbPos) return SCROLL_TOP_RECT;
429 pt.x -= rect.left;
430 if (pt.x < thumbPos) return SCROLL_TOP_RECT;
431 if (pt.x >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
433 return SCROLL_THUMB;
437 /***********************************************************************
438 * SCROLL_DrawArrows
440 * Draw the scroll bar arrows.
442 static void SCROLL_DrawArrows( HDC hdc, SCROLLBAR_INFO *infoPtr,
443 RECT *rect, INT arrowSize, BOOL vertical,
444 BOOL top_pressed, BOOL bottom_pressed )
446 RECT r;
448 r = *rect;
449 if( vertical )
450 r.bottom = r.top + arrowSize;
451 else
452 r.right = r.left + arrowSize;
454 DrawFrameControl( hdc, &r, DFC_SCROLL,
455 (vertical ? DFCS_SCROLLUP : DFCS_SCROLLLEFT)
456 | (top_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
457 | (infoPtr->flags&ESB_DISABLE_LTUP ? DFCS_INACTIVE : 0 ) );
459 r = *rect;
460 if( vertical )
461 r.top = r.bottom-arrowSize;
462 else
463 r.left = r.right-arrowSize;
465 DrawFrameControl( hdc, &r, DFC_SCROLL,
466 (vertical ? DFCS_SCROLLDOWN : DFCS_SCROLLRIGHT)
467 | (bottom_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
468 | (infoPtr->flags&ESB_DISABLE_RTDN ? DFCS_INACTIVE : 0) );
471 static void SCROLL_DrawMovingThumb( HDC hdc, RECT *rect, BOOL vertical,
472 INT arrowSize, INT thumbSize )
474 INT pos = SCROLL_TrackingPos;
475 INT max_size;
477 if( vertical )
478 max_size = rect->bottom - rect->top;
479 else
480 max_size = rect->right - rect->left;
482 max_size -= (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) + thumbSize;
484 if( pos < (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) )
485 pos = (arrowSize-SCROLL_ARROW_THUMB_OVERLAP);
486 else if( pos > max_size )
487 pos = max_size;
489 SCROLL_DrawInterior_9x( SCROLL_TrackingWin, hdc, SCROLL_TrackingBar,
490 rect, arrowSize, thumbSize, pos,
491 0, vertical, FALSE, FALSE );
493 SCROLL_MovingThumb = !SCROLL_MovingThumb;
496 /***********************************************************************
497 * SCROLL_DrawInterior
499 * Draw the scroll bar interior (everything except the arrows).
501 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
502 RECT *rect, INT arrowSize,
503 INT thumbSize, INT thumbPos,
504 UINT flags, BOOL vertical,
505 BOOL top_selected, BOOL bottom_selected )
507 RECT r;
508 HPEN hSavePen;
509 HBRUSH hSaveBrush,hBrush;
511 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
512 * The window-owned scrollbars need to call DEFWND_ControlColor
513 * to correctly setup default scrollbar colors
515 if (nBar == SB_CTL)
517 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
518 (WPARAM)hdc,(LPARAM)hwnd);
520 else
522 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
525 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
526 hSaveBrush = SelectObject( hdc, hBrush );
528 /* Calculate the scroll rectangle */
529 r = *rect;
530 if (vertical)
532 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
533 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
535 else
537 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
538 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
541 /* Draw the scroll rectangles and thumb */
542 if (!thumbPos) /* No thumb to draw */
544 PatBlt( hdc, r.left, r.top,
545 r.right - r.left, r.bottom - r.top,
546 PATCOPY );
548 /* cleanup and return */
549 SelectObject( hdc, hSavePen );
550 SelectObject( hdc, hSaveBrush );
551 return;
554 if (vertical)
556 PatBlt( hdc, r.left, r.top,
557 r.right - r.left,
558 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
559 top_selected ? 0x0f0000 : PATCOPY );
560 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
561 PatBlt( hdc, r.left, r.top + thumbSize,
562 r.right - r.left,
563 r.bottom - r.top - thumbSize,
564 bottom_selected ? 0x0f0000 : PATCOPY );
565 r.bottom = r.top + thumbSize;
567 else /* horizontal */
569 PatBlt( hdc, r.left, r.top,
570 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
571 r.bottom - r.top,
572 top_selected ? 0x0f0000 : PATCOPY );
573 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
574 PatBlt( hdc, r.left + thumbSize, r.top,
575 r.right - r.left - thumbSize,
576 r.bottom - r.top,
577 bottom_selected ? 0x0f0000 : PATCOPY );
578 r.right = r.left + thumbSize;
581 /* Draw the thumb */
582 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT | BF_MIDDLE );
584 /* cleanup */
585 SelectObject( hdc, hSavePen );
586 SelectObject( hdc, hSaveBrush );
590 static void SCROLL_DrawInterior( HWND hwnd, HDC hdc, INT nBar,
591 RECT *rect, INT arrowSize,
592 INT thumbSize, INT thumbPos,
593 UINT flags, BOOL vertical,
594 BOOL top_selected, BOOL bottom_selected )
596 RECT r;
597 HPEN hSavePen;
598 HBRUSH hSaveBrush,hBrush;
599 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
601 if (Save_SCROLL_MovingThumb &&
602 (SCROLL_TrackingWin == hwnd) &&
603 (SCROLL_TrackingBar == nBar))
604 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
606 /* Select the correct brush and pen */
608 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
609 * The window-owned scrollbars need to call DEFWND_ControlColor
610 * to correctly setup default scrollbar colors
612 if (nBar == SB_CTL) {
613 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
614 (WPARAM)hdc,(LPARAM)hwnd);
615 } else {
616 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
618 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
619 hSaveBrush = SelectObject( hdc, hBrush );
621 /* Calculate the scroll rectangle */
623 r = *rect;
624 if (vertical)
626 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
627 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
629 else
631 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
632 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
635 /* Draw the scroll bar frame */
637 /* Draw the scroll rectangles and thumb */
639 if (!thumbPos) /* No thumb to draw */
641 PatBlt( hdc, r.left, r.top, r.right - r.left, r.bottom - r.top, PATCOPY );
643 /* cleanup and return */
644 SelectObject( hdc, hSavePen );
645 SelectObject( hdc, hSaveBrush );
646 return;
649 if (vertical)
651 PatBlt( hdc, r.left, r.top, r.right - r.left,
652 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
653 top_selected ? 0x0f0000 : PATCOPY );
654 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
655 PatBlt( hdc, r.left, r.top + thumbSize, r.right - r.left,
656 r.bottom - r.top - thumbSize,
657 bottom_selected ? 0x0f0000 : PATCOPY );
658 r.bottom = r.top + thumbSize;
660 else /* horizontal */
662 PatBlt( hdc, r.left, r.top,
663 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
664 r.bottom - r.top, top_selected ? 0x0f0000 : PATCOPY );
665 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
666 PatBlt( hdc, r.left + thumbSize, r.top, r.right - r.left - thumbSize,
667 r.bottom - r.top, bottom_selected ? 0x0f0000 : PATCOPY );
668 r.right = r.left + thumbSize;
671 /* Draw the thumb */
673 SelectObject( hdc, GetSysColorBrush(COLOR_BTNFACE) );
674 Rectangle( hdc, r.left+1, r.top+1, r.right-1, r.bottom-1 );
675 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT );
677 if (Save_SCROLL_MovingThumb &&
678 (SCROLL_TrackingWin == hwnd) &&
679 (SCROLL_TrackingBar == nBar))
680 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
682 /* cleanup */
683 SelectObject( hdc, hSavePen );
684 SelectObject( hdc, hSaveBrush );
688 /***********************************************************************
689 * SCROLL_DrawScrollBar
691 * Redraw the whole scrollbar.
693 void SCROLL_DrawScrollBar( HWND hwnd, HDC hdc, INT nBar,
694 BOOL arrows, BOOL interior )
696 INT arrowSize, thumbSize, thumbPos;
697 RECT rect;
698 BOOL vertical;
699 SCROLLBAR_INFO *infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, TRUE );
700 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
701 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
703 if (!(hwnd = WIN_GetFullHandle( hwnd ))) return;
705 if (!infoPtr ||
706 ((nBar == SB_VERT) && !(style & WS_VSCROLL)) ||
707 ((nBar == SB_HORZ) && !(style & WS_HSCROLL))) return;
708 if (!WIN_IsWindowDrawable( hwnd, FALSE )) return;
710 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
711 &arrowSize, &thumbSize, &thumbPos );
713 /* do not draw if the scrollbar rectangle is empty */
714 if(IsRectEmpty(&rect)) return;
716 if (Save_SCROLL_MovingThumb &&
717 (SCROLL_TrackingWin == hwnd) &&
718 (SCROLL_TrackingBar == nBar))
719 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
721 /* Draw the arrows */
723 if (arrows && arrowSize)
725 if( vertical == SCROLL_trackVertical && GetCapture() == hwnd )
726 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
727 (SCROLL_trackHitTest == SCROLL_TOP_ARROW),
728 (SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW) );
729 else
730 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
731 FALSE, FALSE );
733 if( interior )
734 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
735 thumbPos, infoPtr->flags, vertical, FALSE, FALSE );
737 if (Save_SCROLL_MovingThumb &&
738 (SCROLL_TrackingWin == hwnd) &&
739 (SCROLL_TrackingBar == nBar))
740 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
742 /* if scroll bar has focus, reposition the caret */
743 if(hwnd==GetFocus() && (nBar==SB_CTL))
745 if (!vertical)
747 SetCaretPos(thumbPos+1, rect.top+1);
749 else
751 SetCaretPos(rect.top+1, thumbPos+1);
756 /***********************************************************************
757 * SCROLL_DrawSizeGrip
759 * Draw the size grip.
761 static void SCROLL_DrawSizeGrip( HWND hwnd, HDC hdc)
763 RECT rc;
765 GetClientRect( hwnd, &rc );
766 FillRect( hdc, &rc, GetSysColorBrush(COLOR_SCROLLBAR) );
767 rc.left = max( rc.left, rc.right - GetSystemMetrics(SM_CXVSCROLL) - 1 );
768 rc.top = max( rc.top, rc.bottom - GetSystemMetrics(SM_CYHSCROLL) - 1 );
769 DrawFrameControl( hdc, &rc, DFC_SCROLL, DFCS_SCROLLSIZEGRIP );
773 /***********************************************************************
774 * SCROLL_RefreshScrollBar
776 * Repaint the scroll bar interior after a SetScrollRange() or
777 * SetScrollPos() call.
779 static void SCROLL_RefreshScrollBar( HWND hwnd, INT nBar,
780 BOOL arrows, BOOL interior )
782 HDC hdc = GetDCEx( hwnd, 0,
783 DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW) );
784 if (!hdc) return;
786 SCROLL_DrawScrollBar( hwnd, hdc, nBar, arrows, interior );
787 ReleaseDC( hwnd, hdc );
791 /***********************************************************************
792 * SCROLL_HandleKbdEvent
794 * Handle a keyboard event (only for SB_CTL scrollbars with focus).
796 * PARAMS
797 * hwnd [I] Handle of window with scrollbar(s)
798 * wParam [I] Variable input including enable state
799 * lParam [I] Variable input including input point
801 static void SCROLL_HandleKbdEvent(HWND hwnd, WPARAM wParam, LPARAM lParam)
803 TRACE("hwnd=%p wParam=%ld lParam=%ld\n", hwnd, wParam, lParam);
805 /* hide caret on first KEYDOWN to prevent flicker */
806 if ((lParam & PFD_DOUBLEBUFFER_DONTCARE) == 0)
807 HideCaret(hwnd);
809 switch(wParam)
811 case VK_PRIOR: wParam = SB_PAGEUP; break;
812 case VK_NEXT: wParam = SB_PAGEDOWN; break;
813 case VK_HOME: wParam = SB_TOP; break;
814 case VK_END: wParam = SB_BOTTOM; break;
815 case VK_UP: wParam = SB_LINEUP; break;
816 case VK_DOWN: wParam = SB_LINEDOWN; break;
817 case VK_LEFT: wParam = SB_LINEUP; break;
818 case VK_RIGHT: wParam = SB_LINEDOWN; break;
819 default: return;
821 SendMessageW(GetParent(hwnd),
822 ((GetWindowLongW( hwnd, GWL_STYLE ) & SBS_VERT) ?
823 WM_VSCROLL : WM_HSCROLL), wParam, (LPARAM)hwnd);
827 /***********************************************************************
828 * SCROLL_HandleScrollEvent
830 * Handle a mouse or timer event for the scrollbar.
831 * 'pt' is the location of the mouse event in client (for SB_CTL) or
832 * windows coordinates.
834 static void SCROLL_HandleScrollEvent( HWND hwnd, INT nBar, UINT msg, POINT pt)
836 /* Previous mouse position for timer events */
837 static POINT prevPt;
838 /* Thumb position when tracking started. */
839 static UINT trackThumbPos;
840 /* Position in the scroll-bar of the last button-down event. */
841 static INT lastClickPos;
842 /* Position in the scroll-bar of the last mouse event. */
843 static INT lastMousePos;
845 enum SCROLL_HITTEST hittest;
846 HWND hwndOwner, hwndCtl;
847 BOOL vertical;
848 INT arrowSize, thumbSize, thumbPos;
849 RECT rect;
850 HDC hdc;
852 SCROLLBAR_INFO *infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, FALSE );
853 if (!infoPtr) return;
854 if ((SCROLL_trackHitTest == SCROLL_NOWHERE) && (msg != WM_LBUTTONDOWN))
855 return;
857 if (nBar == SB_CTL && (GetWindowLongW( hwnd, GWL_STYLE ) & (SBS_SIZEGRIP | SBS_SIZEBOX)))
859 switch(msg)
861 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
862 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
863 SetCapture( hwnd );
864 prevPt = pt;
865 SCROLL_trackHitTest = hittest = SCROLL_THUMB;
866 break;
867 case WM_MOUSEMOVE:
868 GetClientRect(GetParent(GetParent(hwnd)),&rect);
869 prevPt = pt;
870 break;
871 case WM_LBUTTONUP:
872 ReleaseCapture();
873 SCROLL_trackHitTest = hittest = SCROLL_NOWHERE;
874 if (hwnd==GetFocus()) ShowCaret(hwnd);
875 break;
876 case WM_SYSTIMER:
877 pt = prevPt;
878 break;
880 return;
883 hdc = GetDCEx( hwnd, 0, DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW));
884 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
885 &arrowSize, &thumbSize, &thumbPos );
886 hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd) : hwnd;
887 hwndCtl = (nBar == SB_CTL) ? hwnd : 0;
889 switch(msg)
891 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
892 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
893 SCROLL_trackVertical = vertical;
894 SCROLL_trackHitTest = hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
895 lastClickPos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
896 lastMousePos = lastClickPos;
897 trackThumbPos = thumbPos;
898 prevPt = pt;
899 if (nBar == SB_CTL && (GetWindowLongW(hwnd, GWL_STYLE) & WS_TABSTOP)) SetFocus( hwnd );
900 SetCapture( hwnd );
901 break;
903 case WM_MOUSEMOVE:
904 hittest = SCROLL_HitTest( hwnd, nBar, pt, TRUE );
905 prevPt = pt;
906 break;
908 case WM_LBUTTONUP:
909 hittest = SCROLL_NOWHERE;
910 ReleaseCapture();
911 /* if scrollbar has focus, show back caret */
912 if (hwnd==GetFocus()) ShowCaret(hwnd);
913 break;
915 case WM_SYSTIMER:
916 pt = prevPt;
917 hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
918 break;
920 default:
921 return; /* Should never happen */
924 TRACE("Event: hwnd=%p bar=%d msg=%s pt=%d,%d hit=%d\n",
925 hwnd, nBar, SPY_GetMsgName(msg,hwnd), pt.x, pt.y, hittest );
927 switch(SCROLL_trackHitTest)
929 case SCROLL_NOWHERE: /* No tracking in progress */
930 break;
932 case SCROLL_TOP_ARROW:
933 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
934 (hittest == SCROLL_trackHitTest), FALSE );
935 if (hittest == SCROLL_trackHitTest)
937 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
939 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
940 SB_LINEUP, (LPARAM)hwndCtl );
943 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
944 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
946 else KillSystemTimer( hwnd, SCROLL_TIMER );
947 break;
949 case SCROLL_TOP_RECT:
950 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
951 thumbPos, infoPtr->flags, vertical,
952 (hittest == SCROLL_trackHitTest), FALSE );
953 if (hittest == SCROLL_trackHitTest)
955 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
957 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
958 SB_PAGEUP, (LPARAM)hwndCtl );
960 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
961 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
963 else KillSystemTimer( hwnd, SCROLL_TIMER );
964 break;
966 case SCROLL_THUMB:
967 if (msg == WM_LBUTTONDOWN)
969 SCROLL_TrackingWin = hwnd;
970 SCROLL_TrackingBar = nBar;
971 SCROLL_TrackingPos = trackThumbPos + lastMousePos - lastClickPos;
972 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
973 vertical,
974 SCROLL_TrackingPos );
975 if (!SCROLL_MovingThumb)
976 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
978 else if (msg == WM_LBUTTONUP)
980 if (SCROLL_MovingThumb)
981 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
983 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
984 thumbPos, infoPtr->flags, vertical,
985 FALSE, FALSE );
987 else /* WM_MOUSEMOVE */
989 INT pos;
991 if (!SCROLL_PtInRectEx( &rect, pt, vertical )) pos = lastClickPos;
992 else
994 pt = SCROLL_ClipPos( &rect, pt );
995 pos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
997 if ( (pos != lastMousePos) || (!SCROLL_MovingThumb) )
999 if (SCROLL_MovingThumb)
1000 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
1001 arrowSize, thumbSize );
1002 lastMousePos = pos;
1003 SCROLL_TrackingPos = trackThumbPos + pos - lastClickPos;
1004 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
1005 vertical,
1006 SCROLL_TrackingPos );
1007 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1008 MAKEWPARAM( SB_THUMBTRACK, SCROLL_TrackingVal),
1009 (LPARAM)hwndCtl );
1010 if (!SCROLL_MovingThumb)
1011 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
1012 arrowSize, thumbSize );
1015 break;
1017 case SCROLL_BOTTOM_RECT:
1018 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
1019 thumbPos, infoPtr->flags, vertical,
1020 FALSE, (hittest == SCROLL_trackHitTest) );
1021 if (hittest == SCROLL_trackHitTest)
1023 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1025 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1026 SB_PAGEDOWN, (LPARAM)hwndCtl );
1028 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1029 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
1031 else KillSystemTimer( hwnd, SCROLL_TIMER );
1032 break;
1034 case SCROLL_BOTTOM_ARROW:
1035 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
1036 FALSE, (hittest == SCROLL_trackHitTest) );
1037 if (hittest == SCROLL_trackHitTest)
1039 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1041 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1042 SB_LINEDOWN, (LPARAM)hwndCtl );
1045 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1046 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
1048 else KillSystemTimer( hwnd, SCROLL_TIMER );
1049 break;
1052 if (msg == WM_LBUTTONDOWN)
1055 if (hittest == SCROLL_THUMB)
1057 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1058 trackThumbPos + lastMousePos - lastClickPos );
1059 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1060 MAKEWPARAM( SB_THUMBTRACK, val ), (LPARAM)hwndCtl );
1064 if (msg == WM_LBUTTONUP)
1066 hittest = SCROLL_trackHitTest;
1067 SCROLL_trackHitTest = SCROLL_NOWHERE; /* Terminate tracking */
1069 if (hittest == SCROLL_THUMB)
1071 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1072 trackThumbPos + lastMousePos - lastClickPos );
1073 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1074 MAKEWPARAM( SB_THUMBPOSITION, val ), (LPARAM)hwndCtl );
1076 /* SB_ENDSCROLL doesn't report thumb position */
1077 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1078 SB_ENDSCROLL, (LPARAM)hwndCtl );
1080 /* Terminate tracking */
1081 SCROLL_TrackingWin = 0;
1084 ReleaseDC( hwnd, hdc );
1088 /***********************************************************************
1089 * SCROLL_TrackScrollBar
1091 * Track a mouse button press on a scroll-bar.
1092 * pt is in screen-coordinates for non-client scroll bars.
1094 void SCROLL_TrackScrollBar( HWND hwnd, INT scrollbar, POINT pt )
1096 MSG msg;
1097 INT xoffset = 0, yoffset = 0;
1099 if (scrollbar != SB_CTL)
1101 RECT rect;
1102 WIN_GetRectangles( hwnd, COORDS_CLIENT, &rect, NULL );
1103 ScreenToClient( hwnd, &pt );
1104 pt.x -= rect.left;
1105 pt.y -= rect.top;
1108 SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt );
1112 if (!GetMessageW( &msg, 0, 0, 0 )) break;
1113 if (CallMsgFilterW( &msg, MSGF_SCROLLBAR )) continue;
1114 if (msg.message == WM_LBUTTONUP ||
1115 msg.message == WM_MOUSEMOVE ||
1116 (msg.message == WM_SYSTIMER && msg.wParam == SCROLL_TIMER))
1118 pt.x = (short)LOWORD(msg.lParam) + xoffset;
1119 pt.y = (short)HIWORD(msg.lParam) + yoffset;
1120 SCROLL_HandleScrollEvent( hwnd, scrollbar, msg.message, pt );
1122 else
1124 TranslateMessage( &msg );
1125 DispatchMessageW( &msg );
1127 if (!IsWindow( hwnd ))
1129 ReleaseCapture();
1130 break;
1132 } while (msg.message != WM_LBUTTONUP && GetCapture() == hwnd);
1136 /***********************************************************************
1137 * SCROLL_CreateScrollBar
1139 * Create a scroll bar
1141 * PARAMS
1142 * hwnd [I] Handle of window with scrollbar(s)
1143 * lpCreate [I] The style and place of the scroll bar
1145 static void SCROLL_CreateScrollBar(HWND hwnd, LPCREATESTRUCTW lpCreate)
1147 LPSCROLLBAR_INFO info = SCROLL_GetInternalInfo(hwnd, SB_CTL, TRUE);
1148 if (!info) return;
1150 TRACE("hwnd=%p lpCreate=%p\n", hwnd, lpCreate);
1152 if (lpCreate->style & WS_DISABLED)
1154 info->flags = ESB_DISABLE_BOTH;
1155 TRACE("Created WS_DISABLED scrollbar\n");
1159 if (lpCreate->style & (SBS_SIZEGRIP | SBS_SIZEBOX))
1161 if (lpCreate->style & SBS_SIZEBOXTOPLEFTALIGN)
1162 MoveWindow( hwnd, lpCreate->x, lpCreate->y, GetSystemMetrics(SM_CXVSCROLL)+1,
1163 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1164 else if(lpCreate->style & SBS_SIZEBOXBOTTOMRIGHTALIGN)
1165 MoveWindow( hwnd, lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1166 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1167 GetSystemMetrics(SM_CXVSCROLL)+1,
1168 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1170 else if (lpCreate->style & SBS_VERT)
1172 if (lpCreate->style & SBS_LEFTALIGN)
1173 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1174 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1175 else if (lpCreate->style & SBS_RIGHTALIGN)
1176 MoveWindow( hwnd,
1177 lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1178 lpCreate->y,
1179 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1181 else /* SBS_HORZ */
1183 if (lpCreate->style & SBS_TOPALIGN)
1184 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1185 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1186 else if (lpCreate->style & SBS_BOTTOMALIGN)
1187 MoveWindow( hwnd,
1188 lpCreate->x,
1189 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1190 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1195 /*************************************************************************
1196 * SCROLL_GetScrollInfo
1198 * Internal helper for the API function
1200 * PARAMS
1201 * hwnd [I] Handle of window with scrollbar(s)
1202 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1203 * info [IO] fMask specifies which values to retrieve
1205 * RETURNS
1206 * FALSE if requested field not filled (f.i. scroll bar does not exist)
1208 static BOOL SCROLL_GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1210 LPSCROLLBAR_INFO infoPtr;
1212 /* handle invalid data structure */
1213 if (!SCROLL_ScrollInfoValid(info)
1214 || !(infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE)))
1215 return FALSE;
1217 /* fill in the desired scroll info structure */
1218 if (info->fMask & SIF_PAGE) info->nPage = infoPtr->page;
1219 if (info->fMask & SIF_POS) info->nPos = infoPtr->curVal;
1220 if ((info->fMask & SIF_TRACKPOS) && (info->cbSize == sizeof(*info)))
1221 info->nTrackPos = (SCROLL_TrackingWin == WIN_GetFullHandle(hwnd)) ? SCROLL_TrackingVal : infoPtr->curVal;
1222 if (info->fMask & SIF_RANGE)
1224 info->nMin = infoPtr->minVal;
1225 info->nMax = infoPtr->maxVal;
1228 TRACE("cbSize %02x fMask %04x nMin %d nMax %d nPage %u nPos %d nTrackPos %d\n",
1229 info->cbSize, info->fMask, info->nMin, info->nMax, info->nPage,
1230 info->nPos, info->nTrackPos);
1232 return (info->fMask & SIF_ALL) != 0;
1236 /*************************************************************************
1237 * SCROLL_GetScrollBarInfo
1239 * Internal helper for the API function
1241 * PARAMS
1242 * hwnd [I] Handle of window with scrollbar(s)
1243 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1244 * info [IO] cbSize specifies the size of the structure
1246 * RETURNS
1247 * FALSE if failed
1249 static BOOL SCROLL_GetScrollBarInfo(HWND hwnd, LONG idObject, LPSCROLLBARINFO info)
1251 LPSCROLLBAR_INFO infoPtr;
1252 INT nBar;
1253 INT nDummy;
1254 DWORD style = GetWindowLongW(hwnd, GWL_STYLE);
1255 BOOL pressed;
1256 RECT rect;
1258 switch (idObject)
1260 case OBJID_CLIENT: nBar = SB_CTL; break;
1261 case OBJID_HSCROLL: nBar = SB_HORZ; break;
1262 case OBJID_VSCROLL: nBar = SB_VERT; break;
1263 default: return FALSE;
1266 /* handle invalid data structure */
1267 if (info->cbSize != sizeof(*info))
1268 return FALSE;
1270 SCROLL_GetScrollBarRect(hwnd, nBar, &info->rcScrollBar, &nDummy,
1271 &info->dxyLineButton, &info->xyThumbTop);
1272 /* rcScrollBar needs to be in screen coordinates */
1273 GetWindowRect(hwnd, &rect);
1274 OffsetRect(&info->rcScrollBar, rect.left, rect.top);
1276 info->xyThumbBottom = info->xyThumbTop + info->dxyLineButton;
1278 infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, TRUE);
1279 if (!infoPtr)
1280 return FALSE;
1282 /* Scroll bar state */
1283 info->rgstate[0] = 0;
1284 if ((nBar == SB_HORZ && !(style & WS_HSCROLL))
1285 || (nBar == SB_VERT && !(style & WS_VSCROLL)))
1286 info->rgstate[0] |= STATE_SYSTEM_INVISIBLE;
1287 if (infoPtr->minVal >= infoPtr->maxVal - max(infoPtr->page - 1, 0))
1289 if (!(info->rgstate[0] & STATE_SYSTEM_INVISIBLE))
1290 info->rgstate[0] |= STATE_SYSTEM_UNAVAILABLE;
1291 else
1292 info->rgstate[0] |= STATE_SYSTEM_OFFSCREEN;
1294 if (nBar == SB_CTL && !IsWindowEnabled(hwnd))
1295 info->rgstate[0] |= STATE_SYSTEM_UNAVAILABLE;
1297 pressed = ((nBar == SB_VERT) == SCROLL_trackVertical && GetCapture() == hwnd);
1299 /* Top/left arrow button state. MSDN says top/right, but I don't believe it */
1300 info->rgstate[1] = 0;
1301 if (pressed && SCROLL_trackHitTest == SCROLL_TOP_ARROW)
1302 info->rgstate[1] |= STATE_SYSTEM_PRESSED;
1303 if (infoPtr->flags & ESB_DISABLE_LTUP)
1304 info->rgstate[1] |= STATE_SYSTEM_UNAVAILABLE;
1306 /* Page up/left region state. MSDN says up/right, but I don't believe it */
1307 info->rgstate[2] = 0;
1308 if (infoPtr->curVal == infoPtr->minVal)
1309 info->rgstate[2] |= STATE_SYSTEM_INVISIBLE;
1310 if (pressed && SCROLL_trackHitTest == SCROLL_TOP_RECT)
1311 info->rgstate[2] |= STATE_SYSTEM_PRESSED;
1313 /* Thumb state */
1314 info->rgstate[3] = 0;
1315 if (pressed && SCROLL_trackHitTest == SCROLL_THUMB)
1316 info->rgstate[3] |= STATE_SYSTEM_PRESSED;
1318 /* Page down/right region state. MSDN says down/left, but I don't believe it */
1319 info->rgstate[4] = 0;
1320 if (infoPtr->curVal >= infoPtr->maxVal - 1)
1321 info->rgstate[4] |= STATE_SYSTEM_INVISIBLE;
1322 if (pressed && SCROLL_trackHitTest == SCROLL_BOTTOM_RECT)
1323 info->rgstate[4] |= STATE_SYSTEM_PRESSED;
1325 /* Bottom/right arrow button state. MSDN says bottom/left, but I don't believe it */
1326 info->rgstate[5] = 0;
1327 if (pressed && SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW)
1328 info->rgstate[5] |= STATE_SYSTEM_PRESSED;
1329 if (infoPtr->flags & ESB_DISABLE_RTDN)
1330 info->rgstate[5] |= STATE_SYSTEM_UNAVAILABLE;
1332 return TRUE;
1336 /*************************************************************************
1337 * SCROLL_GetScrollPos
1339 * Internal helper for the API function
1341 * PARAMS
1342 * hwnd [I] Handle of window with scrollbar(s)
1343 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1345 static INT SCROLL_GetScrollPos(HWND hwnd, INT nBar)
1347 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1348 return infoPtr ? infoPtr->curVal: 0;
1352 /*************************************************************************
1353 * SCROLL_GetScrollRange
1355 * Internal helper for the API function
1357 * PARAMS
1358 * hwnd [I] Handle of window with scrollbar(s)
1359 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1360 * lpMin [O] Where to store minimum value
1361 * lpMax [O] Where to store maximum value
1363 * RETURNS
1364 * Success: TRUE
1365 * Failure: FALSE
1367 static BOOL SCROLL_GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1369 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1371 if (lpMin) *lpMin = infoPtr ? infoPtr->minVal : 0;
1372 if (lpMax) *lpMax = infoPtr ? infoPtr->maxVal : 0;
1374 return TRUE;
1378 /*************************************************************************
1379 * SCROLL_SetScrollRange
1381 * PARAMS
1382 * hwnd [I] Handle of window with scrollbar(s)
1383 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1384 * lpMin [I] Minimum value
1385 * lpMax [I] Maximum value
1388 static BOOL SCROLL_SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal)
1390 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1392 TRACE("hwnd=%p nBar=%d min=%d max=%d\n", hwnd, nBar, minVal, maxVal);
1394 if (infoPtr)
1396 infoPtr->minVal = minVal;
1397 infoPtr->maxVal = maxVal;
1399 return TRUE;
1403 /***********************************************************************
1404 * ScrollBarWndProc_common
1406 LRESULT ScrollBarWndProc_common( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, BOOL unicode )
1408 if (!IsWindow( hwnd )) return 0;
1410 switch(message)
1412 case WM_CREATE:
1413 SCROLL_CreateScrollBar(hwnd, (LPCREATESTRUCTW)lParam);
1414 break;
1416 case WM_ENABLE:
1418 SCROLLBAR_INFO *infoPtr;
1419 if ((infoPtr = SCROLL_GetInternalInfo( hwnd, SB_CTL, FALSE )))
1421 infoPtr->flags = wParam ? ESB_ENABLE_BOTH : ESB_DISABLE_BOTH;
1422 SCROLL_RefreshScrollBar(hwnd, SB_CTL, TRUE, TRUE);
1425 return 0;
1427 case WM_LBUTTONDBLCLK:
1428 case WM_LBUTTONDOWN:
1429 if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEGRIP)
1431 SendMessageW( GetParent(hwnd), WM_SYSCOMMAND,
1432 SC_SIZE + ((GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_LAYOUTRTL) ?
1433 WMSZ_BOTTOMLEFT : WMSZ_BOTTOMRIGHT), lParam );
1435 else
1437 POINT pt;
1438 pt.x = (short)LOWORD(lParam);
1439 pt.y = (short)HIWORD(lParam);
1440 SCROLL_TrackScrollBar( hwnd, SB_CTL, pt );
1442 break;
1443 case WM_LBUTTONUP:
1444 case WM_MOUSEMOVE:
1445 case WM_SYSTIMER:
1447 POINT pt;
1448 pt.x = (short)LOWORD(lParam);
1449 pt.y = (short)HIWORD(lParam);
1450 SCROLL_HandleScrollEvent( hwnd, SB_CTL, message, pt );
1452 break;
1454 case WM_KEYDOWN:
1455 SCROLL_HandleKbdEvent(hwnd, wParam, lParam);
1456 break;
1458 case WM_KEYUP:
1459 ShowCaret(hwnd);
1460 break;
1462 case WM_SETFOCUS:
1464 /* Create a caret when a ScrollBar get focus */
1465 RECT rect;
1466 int arrowSize, thumbSize, thumbPos, vertical;
1467 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,
1468 &arrowSize, &thumbSize, &thumbPos );
1469 if (!vertical)
1471 CreateCaret(hwnd, (HBITMAP)1, thumbSize-2, rect.bottom-rect.top-2);
1472 SetCaretPos(thumbPos+1, rect.top+1);
1474 else
1476 CreateCaret(hwnd, (HBITMAP)1, rect.right-rect.left-2,thumbSize-2);
1477 SetCaretPos(rect.top+1, thumbPos+1);
1479 ShowCaret(hwnd);
1481 break;
1483 case WM_KILLFOCUS:
1485 RECT rect;
1486 int arrowSize, thumbSize, thumbPos, vertical;
1487 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,&arrowSize, &thumbSize, &thumbPos );
1488 if (!vertical){
1489 rect.left=thumbPos+1;
1490 rect.right=rect.left+thumbSize;
1492 else
1494 rect.top=thumbPos+1;
1495 rect.bottom=rect.top+thumbSize;
1497 HideCaret(hwnd);
1498 InvalidateRect(hwnd,&rect,0);
1499 DestroyCaret();
1501 break;
1503 case WM_ERASEBKGND:
1504 return 1;
1506 case WM_GETDLGCODE:
1507 return DLGC_WANTARROWS; /* Windows returns this value */
1509 case WM_PAINT:
1511 PAINTSTRUCT ps;
1512 HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
1513 if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEGRIP)
1515 SCROLL_DrawSizeGrip( hwnd, hdc);
1517 else if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEBOX)
1519 RECT rc;
1520 GetClientRect( hwnd, &rc );
1521 FillRect( hdc, &rc, GetSysColorBrush(COLOR_SCROLLBAR) );
1523 else
1524 SCROLL_DrawScrollBar( hwnd, hdc, SB_CTL, TRUE, TRUE );
1525 if (!wParam) EndPaint(hwnd, &ps);
1527 break;
1529 case WM_SETCURSOR:
1530 if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEGRIP)
1532 ULONG_PTR cursor = (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_LAYOUTRTL) ? IDC_SIZENESW : IDC_SIZENWSE;
1533 return (LRESULT)SetCursor( LoadCursorA( 0, (LPSTR)cursor ));
1535 return DefWindowProcW( hwnd, message, wParam, lParam );
1537 case SBM_SETPOS:
1538 return SetScrollPos( hwnd, SB_CTL, wParam, (BOOL)lParam );
1540 case SBM_GETPOS:
1541 return SCROLL_GetScrollPos(hwnd, SB_CTL);
1543 case SBM_SETRANGEREDRAW:
1544 case SBM_SETRANGE:
1546 INT oldPos = SCROLL_GetScrollPos( hwnd, SB_CTL );
1547 SCROLL_SetScrollRange( hwnd, SB_CTL, wParam, lParam );
1548 if (message == SBM_SETRANGEREDRAW)
1549 SCROLL_RefreshScrollBar( hwnd, SB_CTL, TRUE, TRUE );
1550 if (oldPos != SCROLL_GetScrollPos( hwnd, SB_CTL )) return oldPos;
1552 return 0;
1554 case SBM_GETRANGE:
1555 return SCROLL_GetScrollRange(hwnd, SB_CTL, (LPINT)wParam, (LPINT)lParam);
1557 case SBM_ENABLE_ARROWS:
1558 return EnableScrollBar( hwnd, SB_CTL, wParam );
1560 case SBM_SETSCROLLINFO:
1561 return SCROLL_SetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam, wParam );
1563 case SBM_GETSCROLLINFO:
1564 return SCROLL_GetScrollInfo(hwnd, SB_CTL, (SCROLLINFO *)lParam);
1566 case SBM_GETSCROLLBARINFO:
1567 return SCROLL_GetScrollBarInfo(hwnd, OBJID_CLIENT, (SCROLLBARINFO *)lParam);
1569 case 0x00e5:
1570 case 0x00e7:
1571 case 0x00e8:
1572 case 0x00ec:
1573 case 0x00ed:
1574 case 0x00ee:
1575 case 0x00ef:
1576 ERR("unknown Win32 msg %04x wp=%08lx lp=%08lx\n",
1577 message, wParam, lParam );
1578 break;
1580 default:
1581 if (message >= WM_USER)
1582 WARN("unknown msg %04x wp=%04lx lp=%08lx\n",
1583 message, wParam, lParam );
1584 if (unicode)
1585 return DefWindowProcW( hwnd, message, wParam, lParam );
1586 else
1587 return DefWindowProcA( hwnd, message, wParam, lParam );
1589 return 0;
1593 /*************************************************************************
1594 * SetScrollInfo (USER32.@)
1596 * SetScrollInfo can be used to set the position, upper bound,
1597 * lower bound, and page size of a scrollbar control.
1599 * PARAMS
1600 * hwnd [I] Handle of window with scrollbar(s)
1601 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1602 * info [I] Specifies what to change and new values
1603 * bRedraw [I] Should scrollbar be redrawn afterwards?
1605 * RETURNS
1606 * Scrollbar position
1608 * NOTE
1609 * For 100 lines of text to be displayed in a window of 25 lines,
1610 * one would for instance use info->nMin=0, info->nMax=75
1611 * (corresponding to the 76 different positions of the window on
1612 * the text), and info->nPage=25.
1614 INT WINAPI SetScrollInfo(HWND hwnd, INT nBar, const SCROLLINFO *info, BOOL bRedraw)
1616 TRACE("hwnd=%p nBar=%d info=%p, bRedraw=%d\n", hwnd, nBar, info, bRedraw);
1618 /* Refer SB_CTL requests to the window */
1619 if (nBar == SB_CTL)
1620 return SendMessageW(hwnd, SBM_SETSCROLLINFO, bRedraw, (LPARAM)info);
1621 else
1622 return SCROLL_SetScrollInfo( hwnd, nBar, info, bRedraw );
1625 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar, LPCSCROLLINFO info, BOOL bRedraw )
1627 /* Update the scrollbar state and set action flags according to
1628 * what has to be done graphics wise. */
1630 SCROLLBAR_INFO *infoPtr;
1631 UINT new_flags;
1632 INT action = 0;
1634 /* handle invalid data structure */
1635 if (!SCROLL_ScrollInfoValid(info)
1636 || !(infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, TRUE)))
1637 return 0;
1639 if (TRACE_ON(scroll))
1641 TRACE("hwnd=%p bar=%d", hwnd, nBar);
1642 if (info->fMask & SIF_PAGE) TRACE( " page=%d", info->nPage );
1643 if (info->fMask & SIF_POS) TRACE( " pos=%d", info->nPos );
1644 if (info->fMask & SIF_RANGE) TRACE( " min=%d max=%d", info->nMin, info->nMax );
1645 TRACE("\n");
1648 /* Set the page size */
1650 if (info->fMask & SIF_PAGE)
1652 if( infoPtr->page != info->nPage )
1654 infoPtr->page = info->nPage;
1655 action |= SA_SSI_REFRESH;
1659 /* Set the scroll pos */
1661 if (info->fMask & SIF_POS)
1663 if( infoPtr->curVal != info->nPos )
1665 infoPtr->curVal = info->nPos;
1666 action |= SA_SSI_REFRESH;
1670 /* Set the scroll range */
1672 if (info->fMask & SIF_RANGE)
1674 /* Invalid range -> range is set to (0,0) */
1675 if ((info->nMin > info->nMax) ||
1676 ((UINT)(info->nMax - info->nMin) >= 0x80000000))
1678 action |= SA_SSI_REFRESH;
1679 infoPtr->minVal = 0;
1680 infoPtr->maxVal = 0;
1682 else
1684 if( infoPtr->minVal != info->nMin ||
1685 infoPtr->maxVal != info->nMax )
1687 action |= SA_SSI_REFRESH;
1688 infoPtr->minVal = info->nMin;
1689 infoPtr->maxVal = info->nMax;
1694 /* Make sure the page size is valid */
1695 if (infoPtr->page < 0) infoPtr->page = 0;
1696 else if (infoPtr->page > infoPtr->maxVal - infoPtr->minVal + 1 )
1697 infoPtr->page = infoPtr->maxVal - infoPtr->minVal + 1;
1699 /* Make sure the pos is inside the range */
1701 if (infoPtr->curVal < infoPtr->minVal)
1702 infoPtr->curVal = infoPtr->minVal;
1703 else if (infoPtr->curVal > infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1704 infoPtr->curVal = infoPtr->maxVal - max( infoPtr->page-1, 0 );
1706 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1707 infoPtr->page, infoPtr->curVal,
1708 infoPtr->minVal, infoPtr->maxVal );
1710 /* don't change the scrollbar state if SetScrollInfo
1711 * is just called with SIF_DISABLENOSCROLL
1713 if(!(info->fMask & SIF_ALL)) goto done;
1715 /* Check if the scrollbar should be hidden or disabled */
1717 if (info->fMask & (SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL))
1719 new_flags = infoPtr->flags;
1720 if (infoPtr->minVal >= infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1722 /* Hide or disable scroll-bar */
1723 if (info->fMask & SIF_DISABLENOSCROLL)
1725 new_flags = ESB_DISABLE_BOTH;
1726 action |= SA_SSI_REFRESH;
1728 else if ((nBar != SB_CTL) && (action & SA_SSI_REFRESH))
1730 action = SA_SSI_HIDE;
1733 else /* Show and enable scroll-bar only if no page only changed. */
1734 if (info->fMask != SIF_PAGE)
1736 new_flags = ESB_ENABLE_BOTH;
1737 if ((nBar != SB_CTL) && ( (action & SA_SSI_REFRESH) ))
1738 action |= SA_SSI_SHOW;
1741 if (infoPtr->flags != new_flags) /* check arrow flags */
1743 infoPtr->flags = new_flags;
1744 action |= SA_SSI_REPAINT_ARROWS;
1748 done:
1749 if( action & SA_SSI_HIDE )
1750 SCROLL_ShowScrollBar( hwnd, nBar, FALSE, FALSE );
1751 else
1753 if( action & SA_SSI_SHOW )
1754 if( SCROLL_ShowScrollBar( hwnd, nBar, TRUE, TRUE ) )
1755 return infoPtr->curVal; /* SetWindowPos() already did the painting */
1757 if( bRedraw )
1758 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
1759 else if( action & SA_SSI_REPAINT_ARROWS )
1760 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, FALSE );
1763 /* Return current position */
1764 return infoPtr->curVal;
1768 /*************************************************************************
1769 * GetScrollInfo (USER32.@)
1771 * GetScrollInfo can be used to retrieve the position, upper bound,
1772 * lower bound, and page size of a scrollbar control.
1774 * PARAMS
1775 * hwnd [I] Handle of window with scrollbar(s)
1776 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1777 * info [IO] fMask specifies which values to retrieve
1779 * RETURNS
1780 * TRUE if SCROLLINFO is filled
1781 * ( if nBar is SB_CTL, GetScrollInfo returns TRUE even if nothing
1782 * is filled)
1784 BOOL WINAPI GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1786 TRACE("hwnd=%p nBar=%d info=%p\n", hwnd, nBar, info);
1788 /* Refer SB_CTL requests to the window */
1789 if (nBar == SB_CTL)
1791 SendMessageW(hwnd, SBM_GETSCROLLINFO, 0, (LPARAM)info);
1792 return TRUE;
1794 return SCROLL_GetScrollInfo(hwnd, nBar, info);
1798 /*************************************************************************
1799 * GetScrollBarInfo (USER32.@)
1801 * GetScrollBarInfo can be used to retrieve information about a scrollbar
1802 * control.
1804 * PARAMS
1805 * hwnd [I] Handle of window with scrollbar(s)
1806 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1807 * info [IO] cbSize specifies the size of SCROLLBARINFO
1809 * RETURNS
1810 * TRUE if success
1812 BOOL WINAPI GetScrollBarInfo(HWND hwnd, LONG idObject, LPSCROLLBARINFO info)
1814 TRACE("hwnd=%p idObject=%d info=%p\n", hwnd, idObject, info);
1816 /* Refer OBJID_CLIENT requests to the window */
1817 if (idObject == OBJID_CLIENT)
1818 return SendMessageW(hwnd, SBM_GETSCROLLBARINFO, 0, (LPARAM)info);
1819 else
1820 return SCROLL_GetScrollBarInfo(hwnd, idObject, info);
1824 /*************************************************************************
1825 * SetScrollPos (USER32.@)
1827 * Sets the current position of the scroll thumb.
1829 * PARAMS
1830 * hwnd [I] Handle of window with scrollbar(s)
1831 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1832 * nPos [I] New value
1833 * bRedraw [I] Should scrollbar be redrawn afterwards?
1835 * RETURNS
1836 * Success: Scrollbar position
1837 * Failure: 0
1839 * REMARKS
1840 * Note the ambiguity when 0 is returned. Use GetLastError
1841 * to make sure there was an error (and to know which one).
1843 INT WINAPI SetScrollPos( HWND hwnd, INT nBar, INT nPos, BOOL bRedraw)
1845 SCROLLINFO info;
1846 SCROLLBAR_INFO *infoPtr;
1847 INT oldPos;
1849 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, FALSE ))) return 0;
1850 oldPos = infoPtr->curVal;
1851 info.cbSize = sizeof(info);
1852 info.nPos = nPos;
1853 info.fMask = SIF_POS;
1854 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1855 return oldPos;
1859 /*************************************************************************
1860 * GetScrollPos (USER32.@)
1862 * Gets the current position of the scroll thumb.
1864 * PARAMS
1865 * hwnd [I] Handle of window with scrollbar(s)
1866 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1868 * RETURNS
1869 * Success: Current position
1870 * Failure: 0
1872 * REMARKS
1873 * There is ambiguity when 0 is returned. Use GetLastError
1874 * to make sure there was an error (and to know which one).
1876 INT WINAPI GetScrollPos(HWND hwnd, INT nBar)
1878 TRACE("hwnd=%p nBar=%d\n", hwnd, nBar);
1880 /* Refer SB_CTL requests to the window */
1881 if (nBar == SB_CTL)
1882 return SendMessageW(hwnd, SBM_GETPOS, 0, 0);
1883 else
1884 return SCROLL_GetScrollPos(hwnd, nBar);
1888 /*************************************************************************
1889 * SetScrollRange (USER32.@)
1890 * The SetScrollRange function sets the minimum and maximum scroll box positions
1891 * If nMinPos and nMaxPos is the same value, the scroll bar will hide
1893 * Sets the range of the scroll bar.
1895 * PARAMS
1896 * hwnd [I] Handle of window with scrollbar(s)
1897 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1898 * minVal [I] New minimum value
1899 * maxVal [I] New Maximum value
1900 * bRedraw [I] Should scrollbar be redrawn afterwards?
1902 * RETURNS
1903 * Success: TRUE
1904 * Failure: FALSE
1906 BOOL WINAPI SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal, BOOL bRedraw)
1908 SCROLLINFO info;
1910 TRACE("hwnd=%p nBar=%d min=%d max=%d, bRedraw=%d\n", hwnd, nBar, minVal, maxVal, bRedraw);
1912 info.cbSize = sizeof(info);
1913 info.fMask = SIF_RANGE;
1914 info.nMin = minVal;
1915 info.nMax = maxVal;
1916 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1917 return TRUE;
1921 /*************************************************************************
1922 * SCROLL_SetNCSbState
1924 * Updates both scrollbars at the same time. Used by MDI CalcChildScroll().
1926 INT SCROLL_SetNCSbState(HWND hwnd, int vMin, int vMax, int vPos,
1927 int hMin, int hMax, int hPos)
1929 SCROLLINFO vInfo, hInfo;
1931 vInfo.cbSize = hInfo.cbSize = sizeof(SCROLLINFO);
1932 vInfo.nMin = vMin;
1933 vInfo.nMax = vMax;
1934 vInfo.nPos = vPos;
1935 hInfo.nMin = hMin;
1936 hInfo.nMax = hMax;
1937 hInfo.nPos = hPos;
1938 vInfo.fMask = hInfo.fMask = SIF_RANGE | SIF_POS;
1940 SCROLL_SetScrollInfo( hwnd, SB_VERT, &vInfo, TRUE );
1941 SCROLL_SetScrollInfo( hwnd, SB_HORZ, &hInfo, TRUE );
1943 return 0;
1947 /*************************************************************************
1948 * GetScrollRange (USER32.@)
1950 * Gets the range of the scroll bar.
1952 * PARAMS
1953 * hwnd [I] Handle of window with scrollbar(s)
1954 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1955 * lpMin [O] Where to store minimum value
1956 * lpMax [O] Where to store maximum value
1958 * RETURNS
1959 * TRUE if values is filled
1961 BOOL WINAPI GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1963 TRACE("hwnd=%p nBar=%d lpMin=%p lpMax=%p\n", hwnd, nBar, lpMin, lpMax);
1965 /* Refer SB_CTL requests to the window */
1966 if (nBar == SB_CTL)
1967 SendMessageW(hwnd, SBM_GETRANGE, (WPARAM)lpMin, (LPARAM)lpMax);
1968 else
1969 SCROLL_GetScrollRange(hwnd, nBar, lpMin, lpMax);
1971 return TRUE;
1975 /*************************************************************************
1976 * SCROLL_ShowScrollBar()
1978 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1980 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar, BOOL fShowH, BOOL fShowV )
1982 ULONG old_style, set_bits = 0, clear_bits = 0;
1984 TRACE("hwnd=%p bar=%d horz=%d, vert=%d\n", hwnd, nBar, fShowH, fShowV );
1986 switch(nBar)
1988 case SB_CTL:
1989 ShowWindow( hwnd, fShowH ? SW_SHOW : SW_HIDE );
1990 return TRUE;
1992 case SB_BOTH:
1993 case SB_HORZ:
1994 if (fShowH) set_bits |= WS_HSCROLL;
1995 else clear_bits |= WS_HSCROLL;
1996 if( nBar == SB_HORZ ) break;
1997 /* fall through */
1998 case SB_VERT:
1999 if (fShowV) set_bits |= WS_VSCROLL;
2000 else clear_bits |= WS_VSCROLL;
2001 break;
2003 default:
2004 return FALSE; /* Nothing to do! */
2007 old_style = WIN_SetStyle( hwnd, set_bits, clear_bits );
2008 if ((old_style & clear_bits) != 0 || (old_style & set_bits) != set_bits)
2010 /* frame has been changed, let the window redraw itself */
2011 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
2012 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
2013 return TRUE;
2015 return FALSE; /* no frame changes */
2019 /*************************************************************************
2020 * ShowScrollBar (USER32.@)
2022 * Shows or hides the scroll bar.
2024 * PARAMS
2025 * hwnd [I] Handle of window with scrollbar(s)
2026 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
2027 * fShow [I] TRUE = show, FALSE = hide
2029 * RETURNS
2030 * Success: TRUE
2031 * Failure: FALSE
2033 BOOL WINAPI ShowScrollBar(HWND hwnd, INT nBar, BOOL fShow)
2035 if ( !hwnd )
2036 return FALSE;
2038 SCROLL_ShowScrollBar( hwnd, nBar, (nBar == SB_VERT) ? 0 : fShow,
2039 (nBar == SB_HORZ) ? 0 : fShow );
2040 return TRUE;
2044 /*************************************************************************
2045 * EnableScrollBar (USER32.@)
2047 * Enables or disables the scroll bars.
2049 BOOL WINAPI EnableScrollBar( HWND hwnd, UINT nBar, UINT flags )
2051 BOOL bFineWithMe;
2052 SCROLLBAR_INFO *infoPtr;
2054 flags &= ESB_DISABLE_BOTH;
2056 if (nBar == SB_BOTH)
2058 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, SB_VERT, TRUE ))) return FALSE;
2059 if (!(bFineWithMe = (infoPtr->flags == flags)) )
2061 infoPtr->flags = flags;
2062 SCROLL_RefreshScrollBar( hwnd, SB_VERT, TRUE, TRUE );
2064 nBar = SB_HORZ;
2066 else
2067 bFineWithMe = TRUE;
2069 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, TRUE ))) return FALSE;
2070 if (bFineWithMe && infoPtr->flags == flags) return FALSE;
2071 infoPtr->flags = flags;
2073 if (nBar == SB_CTL && (flags == ESB_DISABLE_BOTH || flags == ESB_ENABLE_BOTH))
2074 EnableWindow(hwnd, flags == ESB_ENABLE_BOTH);
2076 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
2077 return TRUE;