ntoskrnl.exe/tests: Fix path buffer allocation size.
[wine.git] / dlls / user32 / scroll.c
blobd611cf006029159a964de46baefdd59b605691ca
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
22 #include "config.h"
24 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wingdi.h"
29 #include "controls.h"
30 #include "win.h"
31 #include "wine/debug.h"
32 #include "user_private.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(scroll);
36 /* data for a single scroll bar */
37 typedef struct
39 INT curVal; /* Current scroll-bar value */
40 INT minVal; /* Minimum scroll-bar value */
41 INT maxVal; /* Maximum scroll-bar value */
42 INT page; /* Page size of scroll bar (Win32) */
43 UINT flags; /* EnableScrollBar flags */
44 } SCROLLBAR_INFO, *LPSCROLLBAR_INFO;
46 /* data for window that has (one or two) scroll bars */
47 typedef struct
49 SCROLLBAR_INFO horz;
50 SCROLLBAR_INFO vert;
51 } WINSCROLLBAR_INFO, *LPWINSCROLLBAR_INFO;
53 typedef struct
55 DWORD magic;
56 SCROLLBAR_INFO info;
57 } SCROLLBAR_WNDDATA;
59 #define SCROLLBAR_MAGIC 0x5c6011ba
61 /* Minimum size of the rectangle between the arrows */
62 #define SCROLL_MIN_RECT 4
64 /* Minimum size of the thumb in pixels */
65 #define SCROLL_MIN_THUMB 6
67 /* Overlap between arrows and thumb */
68 #define SCROLL_ARROW_THUMB_OVERLAP 0
70 /* Delay (in ms) before first repetition when holding the button down */
71 #define SCROLL_FIRST_DELAY 200
73 /* Delay (in ms) between scroll repetitions */
74 #define SCROLL_REPEAT_DELAY 50
76 /* Scroll timer id */
77 #define SCROLL_TIMER 0
79 /* Scroll-bar hit testing */
80 enum SCROLL_HITTEST
82 SCROLL_NOWHERE, /* Outside the scroll bar */
83 SCROLL_TOP_ARROW, /* Top or left arrow */
84 SCROLL_TOP_RECT, /* Rectangle between the top arrow and the thumb */
85 SCROLL_THUMB, /* Thumb rectangle */
86 SCROLL_BOTTOM_RECT, /* Rectangle between the thumb and the bottom arrow */
87 SCROLL_BOTTOM_ARROW /* Bottom or right arrow */
90 /* What to do after SCROLL_SetScrollInfo() */
91 #define SA_SSI_HIDE 0x0001
92 #define SA_SSI_SHOW 0x0002
93 #define SA_SSI_REFRESH 0x0004
94 #define SA_SSI_REPAINT_ARROWS 0x0008
96 /* Thumb-tracking info */
97 static HWND SCROLL_TrackingWin = 0;
98 static INT SCROLL_TrackingBar = 0;
99 static INT SCROLL_TrackingPos = 0;
100 static INT SCROLL_TrackingVal = 0;
101 /* Hit test code of the last button-down event */
102 static enum SCROLL_HITTEST SCROLL_trackHitTest;
103 static BOOL SCROLL_trackVertical;
105 /* Is the moving thumb being displayed? */
106 static BOOL SCROLL_MovingThumb = FALSE;
108 /* Local functions */
109 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar,
110 BOOL fShowH, BOOL fShowV );
111 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar,
112 const SCROLLINFO *info, BOOL bRedraw );
113 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
114 RECT *rect, INT arrowSize,
115 INT thumbSize, INT thumbPos,
116 UINT flags, BOOL vertical,
117 BOOL top_selected, BOOL bottom_selected );
120 /*********************************************************************
121 * scrollbar class descriptor
123 static const WCHAR scrollbarW[] = {'S','c','r','o','l','l','B','a','r',0};
124 const struct builtin_class_descr SCROLL_builtin_class =
126 scrollbarW, /* name */
127 CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC, /* style */
128 WINPROC_SCROLLBAR, /* proc */
129 sizeof(SCROLLBAR_WNDDATA), /* extra */
130 IDC_ARROW, /* cursor */
131 0 /* brush */
134 /***********************************************************************
135 * SCROLL_ScrollInfoValid
137 * Determine if the supplied SCROLLINFO struct is valid.
138 * info [in] The SCROLLINFO struct to be tested
140 static inline BOOL SCROLL_ScrollInfoValid( LPCSCROLLINFO info )
142 return !(info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)
143 || (info->cbSize != sizeof(*info)
144 && info->cbSize != sizeof(*info) - sizeof(info->nTrackPos)));
148 /***********************************************************************
149 * SCROLL_GetInternalInfo
151 * Returns pointer to internal SCROLLBAR_INFO structure for nBar
152 * or NULL if failed (f.i. scroll bar does not exist yet)
153 * If alloc is TRUE and the struct does not exist yet, create it.
155 static SCROLLBAR_INFO *SCROLL_GetInternalInfo( HWND hwnd, INT nBar, BOOL alloc )
157 SCROLLBAR_INFO *infoPtr = NULL;
158 WND *wndPtr = WIN_GetPtr( hwnd );
160 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return NULL;
161 switch(nBar)
163 case SB_HORZ:
164 if (wndPtr->pScroll) infoPtr = &((LPWINSCROLLBAR_INFO)wndPtr->pScroll)->horz;
165 break;
166 case SB_VERT:
167 if (wndPtr->pScroll) infoPtr = &((LPWINSCROLLBAR_INFO)wndPtr->pScroll)->vert;
168 break;
169 case SB_CTL:
170 if (wndPtr->cbWndExtra >= sizeof(SCROLLBAR_WNDDATA))
172 SCROLLBAR_WNDDATA *data = (SCROLLBAR_WNDDATA*)wndPtr->wExtra;
173 if (data->magic == SCROLLBAR_MAGIC)
174 infoPtr = &data->info;
176 if (!infoPtr) WARN("window is not a scrollbar control\n");
177 break;
178 case SB_BOTH:
179 WARN("with SB_BOTH\n");
180 break;
183 if (!infoPtr && alloc)
185 WINSCROLLBAR_INFO *winInfoPtr;
187 if (nBar != SB_HORZ && nBar != SB_VERT)
188 WARN("Cannot initialize nBar=%d\n",nBar);
189 else if ((winInfoPtr = HeapAlloc( GetProcessHeap(), 0, sizeof(WINSCROLLBAR_INFO) )))
191 /* Set default values */
192 winInfoPtr->horz.minVal = 0;
193 winInfoPtr->horz.curVal = 0;
194 winInfoPtr->horz.page = 0;
195 /* From MSDN and our own tests:
196 * max for a standard scroll bar is 100 by default. */
197 winInfoPtr->horz.maxVal = 100;
198 winInfoPtr->horz.flags = ESB_ENABLE_BOTH;
199 winInfoPtr->vert = winInfoPtr->horz;
200 wndPtr->pScroll = winInfoPtr;
201 infoPtr = nBar == SB_HORZ ? &winInfoPtr->horz : &winInfoPtr->vert;
204 WIN_ReleasePtr( wndPtr );
205 return infoPtr;
209 /***********************************************************************
210 * SCROLL_GetScrollBarRect
212 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
213 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
214 * 'arrowSize' returns the width or height of an arrow (depending on
215 * the orientation of the scrollbar), 'thumbSize' returns the size of
216 * the thumb, and 'thumbPos' returns the position of the thumb
217 * relative to the left or to the top.
218 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
220 static BOOL SCROLL_GetScrollBarRect( HWND hwnd, INT nBar, RECT *lprect,
221 INT *arrowSize, INT *thumbSize,
222 INT *thumbPos )
224 INT pixels;
225 BOOL vertical;
226 WND *wndPtr = WIN_GetPtr( hwnd );
228 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
230 switch(nBar)
232 case SB_HORZ:
233 WIN_GetRectangles( hwnd, COORDS_WINDOW, NULL, lprect );
234 lprect->top = lprect->bottom;
235 lprect->bottom += GetSystemMetrics(SM_CYHSCROLL);
236 if(wndPtr->dwStyle & WS_VSCROLL)
237 lprect->right++;
238 vertical = FALSE;
239 break;
241 case SB_VERT:
242 WIN_GetRectangles( hwnd, COORDS_WINDOW, NULL, lprect );
243 if((wndPtr->dwExStyle & WS_EX_LEFTSCROLLBAR) != 0)
245 lprect->right = lprect->left;
246 lprect->left -= GetSystemMetrics(SM_CXVSCROLL);
248 else
250 lprect->left = lprect->right;
251 lprect->right += GetSystemMetrics(SM_CXVSCROLL);
253 if(wndPtr->dwStyle & WS_HSCROLL)
254 lprect->bottom++;
255 vertical = TRUE;
256 break;
258 case SB_CTL:
259 GetClientRect( hwnd, lprect );
260 vertical = ((wndPtr->dwStyle & SBS_VERT) != 0);
261 break;
263 default:
264 WIN_ReleasePtr( wndPtr );
265 return FALSE;
268 if (vertical) pixels = lprect->bottom - lprect->top;
269 else pixels = lprect->right - lprect->left;
271 if (pixels <= 2*GetSystemMetrics(SM_CXVSCROLL) + SCROLL_MIN_RECT)
273 if (pixels > SCROLL_MIN_RECT)
274 *arrowSize = (pixels - SCROLL_MIN_RECT) / 2;
275 else
276 *arrowSize = 0;
277 *thumbPos = *thumbSize = 0;
279 else
281 SCROLLBAR_INFO *info = SCROLL_GetInternalInfo( hwnd, nBar, FALSE );
282 if (!info)
284 WARN("called for missing scroll bar\n");
285 WIN_ReleasePtr( wndPtr );
286 return FALSE;
288 *arrowSize = GetSystemMetrics(SM_CXVSCROLL);
289 pixels -= (2 * (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP));
291 if (info->page)
293 *thumbSize = MulDiv(pixels,info->page,(info->maxVal-info->minVal+1));
294 if (*thumbSize < SCROLL_MIN_THUMB) *thumbSize = SCROLL_MIN_THUMB;
296 else *thumbSize = GetSystemMetrics(SM_CXVSCROLL);
298 if (((pixels -= *thumbSize ) < 0) ||
299 ((info->flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH))
301 /* Rectangle too small or scrollbar disabled -> no thumb */
302 *thumbPos = *thumbSize = 0;
304 else
306 INT max = info->maxVal - max( info->page-1, 0 );
307 if (info->minVal >= max)
308 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
309 else
310 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP
311 + MulDiv(pixels, (info->curVal-info->minVal),(max - info->minVal));
314 WIN_ReleasePtr( wndPtr );
315 return vertical;
319 /***********************************************************************
320 * SCROLL_GetThumbVal
322 * Compute the current scroll position based on the thumb position in pixels
323 * from the top of the scroll-bar.
325 static UINT SCROLL_GetThumbVal( SCROLLBAR_INFO *infoPtr, RECT *rect,
326 BOOL vertical, INT pos )
328 INT thumbSize;
329 INT pixels = vertical ? rect->bottom-rect->top : rect->right-rect->left;
330 INT range;
332 if ((pixels -= 2*(GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP)) <= 0)
333 return infoPtr->minVal;
335 if (infoPtr->page)
337 thumbSize = MulDiv(pixels,infoPtr->page,(infoPtr->maxVal-infoPtr->minVal+1));
338 if (thumbSize < SCROLL_MIN_THUMB) thumbSize = SCROLL_MIN_THUMB;
340 else thumbSize = GetSystemMetrics(SM_CXVSCROLL);
342 if ((pixels -= thumbSize) <= 0) return infoPtr->minVal;
344 pos = max( 0, pos - (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP) );
345 if (pos > pixels) pos = pixels;
347 if (!infoPtr->page)
348 range = infoPtr->maxVal - infoPtr->minVal;
349 else
350 range = infoPtr->maxVal - infoPtr->minVal - infoPtr->page + 1;
352 return infoPtr->minVal + MulDiv(pos, range, pixels);
355 /***********************************************************************
356 * SCROLL_PtInRectEx
358 static BOOL SCROLL_PtInRectEx( LPRECT lpRect, POINT pt, BOOL vertical )
360 RECT rect = *lpRect;
361 int scrollbarWidth;
363 /* Pad hit rect to allow mouse to be dragged outside of scrollbar and
364 * still be considered in the scrollbar. */
365 if (vertical)
367 scrollbarWidth = lpRect->right - lpRect->left;
368 InflateRect(&rect, scrollbarWidth * 8, scrollbarWidth * 2);
370 else
372 scrollbarWidth = lpRect->bottom - lpRect->top;
373 InflateRect(&rect, scrollbarWidth * 2, scrollbarWidth * 8);
375 return PtInRect( &rect, pt );
378 /***********************************************************************
379 * SCROLL_ClipPos
381 static POINT SCROLL_ClipPos( LPRECT lpRect, POINT pt )
383 if( pt.x < lpRect->left )
384 pt.x = lpRect->left;
385 else
386 if( pt.x > lpRect->right )
387 pt.x = lpRect->right;
389 if( pt.y < lpRect->top )
390 pt.y = lpRect->top;
391 else
392 if( pt.y > lpRect->bottom )
393 pt.y = lpRect->bottom;
395 return pt;
399 /***********************************************************************
400 * SCROLL_HitTest
402 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
404 static enum SCROLL_HITTEST SCROLL_HitTest( HWND hwnd, INT nBar,
405 POINT pt, BOOL bDragging )
407 INT arrowSize, thumbSize, thumbPos;
408 RECT rect;
410 BOOL vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
411 &arrowSize, &thumbSize, &thumbPos );
413 if ( (bDragging && !SCROLL_PtInRectEx( &rect, pt, vertical )) ||
414 (!PtInRect( &rect, pt )) ) return SCROLL_NOWHERE;
416 if (vertical)
418 if (pt.y < rect.top + arrowSize) return SCROLL_TOP_ARROW;
419 if (pt.y >= rect.bottom - arrowSize) return SCROLL_BOTTOM_ARROW;
420 if (!thumbPos) return SCROLL_TOP_RECT;
421 pt.y -= rect.top;
422 if (pt.y < thumbPos) return SCROLL_TOP_RECT;
423 if (pt.y >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
425 else /* horizontal */
427 if (pt.x < rect.left + arrowSize) return SCROLL_TOP_ARROW;
428 if (pt.x >= rect.right - arrowSize) return SCROLL_BOTTOM_ARROW;
429 if (!thumbPos) return SCROLL_TOP_RECT;
430 pt.x -= rect.left;
431 if (pt.x < thumbPos) return SCROLL_TOP_RECT;
432 if (pt.x >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
434 return SCROLL_THUMB;
438 /***********************************************************************
439 * SCROLL_DrawArrows
441 * Draw the scroll bar arrows.
443 static void SCROLL_DrawArrows( HDC hdc, SCROLLBAR_INFO *infoPtr,
444 RECT *rect, INT arrowSize, BOOL vertical,
445 BOOL top_pressed, BOOL bottom_pressed )
447 RECT r;
449 r = *rect;
450 if( vertical )
451 r.bottom = r.top + arrowSize;
452 else
453 r.right = r.left + arrowSize;
455 DrawFrameControl( hdc, &r, DFC_SCROLL,
456 (vertical ? DFCS_SCROLLUP : DFCS_SCROLLLEFT)
457 | (top_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
458 | (infoPtr->flags&ESB_DISABLE_LTUP ? DFCS_INACTIVE : 0 ) );
460 r = *rect;
461 if( vertical )
462 r.top = r.bottom-arrowSize;
463 else
464 r.left = r.right-arrowSize;
466 DrawFrameControl( hdc, &r, DFC_SCROLL,
467 (vertical ? DFCS_SCROLLDOWN : DFCS_SCROLLRIGHT)
468 | (bottom_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
469 | (infoPtr->flags&ESB_DISABLE_RTDN ? DFCS_INACTIVE : 0) );
472 static void SCROLL_DrawMovingThumb( HDC hdc, RECT *rect, BOOL vertical,
473 INT arrowSize, INT thumbSize )
475 INT pos = SCROLL_TrackingPos;
476 INT max_size;
478 if( vertical )
479 max_size = rect->bottom - rect->top;
480 else
481 max_size = rect->right - rect->left;
483 max_size -= (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) + thumbSize;
485 if( pos < (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) )
486 pos = (arrowSize-SCROLL_ARROW_THUMB_OVERLAP);
487 else if( pos > max_size )
488 pos = max_size;
490 SCROLL_DrawInterior_9x( SCROLL_TrackingWin, hdc, SCROLL_TrackingBar,
491 rect, arrowSize, thumbSize, pos,
492 0, vertical, FALSE, FALSE );
494 SCROLL_MovingThumb = !SCROLL_MovingThumb;
497 /***********************************************************************
498 * SCROLL_DrawInterior
500 * Draw the scroll bar interior (everything except the arrows).
502 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
503 RECT *rect, INT arrowSize,
504 INT thumbSize, INT thumbPos,
505 UINT flags, BOOL vertical,
506 BOOL top_selected, BOOL bottom_selected )
508 RECT r;
509 HPEN hSavePen;
510 HBRUSH hSaveBrush,hBrush;
512 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
513 * The window-owned scrollbars need to call DEFWND_ControlColor
514 * to correctly setup default scrollbar colors
516 if (nBar == SB_CTL)
518 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
519 (WPARAM)hdc,(LPARAM)hwnd);
521 else
523 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
526 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
527 hSaveBrush = SelectObject( hdc, hBrush );
529 /* Calculate the scroll rectangle */
530 r = *rect;
531 if (vertical)
533 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
534 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
536 else
538 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
539 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
542 /* Draw the scroll rectangles and thumb */
543 if (!thumbPos) /* No thumb to draw */
545 PatBlt( hdc, r.left, r.top,
546 r.right - r.left, r.bottom - r.top,
547 PATCOPY );
549 /* cleanup and return */
550 SelectObject( hdc, hSavePen );
551 SelectObject( hdc, hSaveBrush );
552 return;
555 if (vertical)
557 PatBlt( hdc, r.left, r.top,
558 r.right - r.left,
559 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
560 top_selected ? 0x0f0000 : PATCOPY );
561 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
562 PatBlt( hdc, r.left, r.top + thumbSize,
563 r.right - r.left,
564 r.bottom - r.top - thumbSize,
565 bottom_selected ? 0x0f0000 : PATCOPY );
566 r.bottom = r.top + thumbSize;
568 else /* horizontal */
570 PatBlt( hdc, r.left, r.top,
571 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
572 r.bottom - r.top,
573 top_selected ? 0x0f0000 : PATCOPY );
574 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
575 PatBlt( hdc, r.left + thumbSize, r.top,
576 r.right - r.left - thumbSize,
577 r.bottom - r.top,
578 bottom_selected ? 0x0f0000 : PATCOPY );
579 r.right = r.left + thumbSize;
582 /* Draw the thumb */
583 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT | BF_MIDDLE );
585 /* cleanup */
586 SelectObject( hdc, hSavePen );
587 SelectObject( hdc, hSaveBrush );
591 static void SCROLL_DrawInterior( HWND hwnd, HDC hdc, INT nBar,
592 RECT *rect, INT arrowSize,
593 INT thumbSize, INT thumbPos,
594 UINT flags, BOOL vertical,
595 BOOL top_selected, BOOL bottom_selected )
597 RECT r;
598 HPEN hSavePen;
599 HBRUSH hSaveBrush,hBrush;
600 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
602 if (Save_SCROLL_MovingThumb &&
603 (SCROLL_TrackingWin == hwnd) &&
604 (SCROLL_TrackingBar == nBar))
605 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
607 /* Select the correct brush and pen */
609 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
610 * The window-owned scrollbars need to call DEFWND_ControlColor
611 * to correctly setup default scrollbar colors
613 if (nBar == SB_CTL) {
614 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
615 (WPARAM)hdc,(LPARAM)hwnd);
616 } else {
617 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
619 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
620 hSaveBrush = SelectObject( hdc, hBrush );
622 /* Calculate the scroll rectangle */
624 r = *rect;
625 if (vertical)
627 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
628 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
630 else
632 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
633 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
636 /* Draw the scroll bar frame */
638 /* Draw the scroll rectangles and thumb */
640 if (!thumbPos) /* No thumb to draw */
642 PatBlt( hdc, r.left, r.top, r.right - r.left, r.bottom - r.top, PATCOPY );
644 /* cleanup and return */
645 SelectObject( hdc, hSavePen );
646 SelectObject( hdc, hSaveBrush );
647 return;
650 if (vertical)
652 PatBlt( hdc, r.left, r.top, r.right - r.left,
653 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
654 top_selected ? 0x0f0000 : PATCOPY );
655 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
656 PatBlt( hdc, r.left, r.top + thumbSize, r.right - r.left,
657 r.bottom - r.top - thumbSize,
658 bottom_selected ? 0x0f0000 : PATCOPY );
659 r.bottom = r.top + thumbSize;
661 else /* horizontal */
663 PatBlt( hdc, r.left, r.top,
664 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
665 r.bottom - r.top, top_selected ? 0x0f0000 : PATCOPY );
666 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
667 PatBlt( hdc, r.left + thumbSize, r.top, r.right - r.left - thumbSize,
668 r.bottom - r.top, bottom_selected ? 0x0f0000 : PATCOPY );
669 r.right = r.left + thumbSize;
672 /* Draw the thumb */
674 SelectObject( hdc, GetSysColorBrush(COLOR_BTNFACE) );
675 Rectangle( hdc, r.left+1, r.top+1, r.right-1, r.bottom-1 );
676 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT );
678 if (Save_SCROLL_MovingThumb &&
679 (SCROLL_TrackingWin == hwnd) &&
680 (SCROLL_TrackingBar == nBar))
681 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
683 /* cleanup */
684 SelectObject( hdc, hSavePen );
685 SelectObject( hdc, hSaveBrush );
689 /***********************************************************************
690 * SCROLL_DrawScrollBar
692 * Redraw the whole scrollbar.
694 void SCROLL_DrawScrollBar( HWND hwnd, HDC hdc, INT nBar,
695 BOOL arrows, BOOL interior )
697 INT arrowSize, thumbSize, thumbPos;
698 RECT rect;
699 BOOL vertical;
700 SCROLLBAR_INFO *infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, TRUE );
701 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
702 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
704 if (!(hwnd = WIN_GetFullHandle( hwnd ))) return;
706 if (!infoPtr ||
707 ((nBar == SB_VERT) && !(style & WS_VSCROLL)) ||
708 ((nBar == SB_HORZ) && !(style & WS_HSCROLL))) return;
709 if (!WIN_IsWindowDrawable( hwnd, FALSE )) return;
711 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
712 &arrowSize, &thumbSize, &thumbPos );
714 /* do not draw if the scrollbar rectangle is empty */
715 if(IsRectEmpty(&rect)) return;
717 if (Save_SCROLL_MovingThumb &&
718 (SCROLL_TrackingWin == hwnd) &&
719 (SCROLL_TrackingBar == nBar))
720 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
722 /* Draw the arrows */
724 if (arrows && arrowSize)
726 if( vertical == SCROLL_trackVertical && GetCapture() == hwnd )
727 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
728 (SCROLL_trackHitTest == SCROLL_TOP_ARROW),
729 (SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW) );
730 else
731 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
732 FALSE, FALSE );
734 if( interior )
735 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
736 thumbPos, infoPtr->flags, vertical, FALSE, FALSE );
738 if (Save_SCROLL_MovingThumb &&
739 (SCROLL_TrackingWin == hwnd) &&
740 (SCROLL_TrackingBar == nBar))
741 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
743 /* if scroll bar has focus, reposition the caret */
744 if(hwnd==GetFocus() && (nBar==SB_CTL))
746 if (!vertical)
748 SetCaretPos(thumbPos+1, rect.top+1);
750 else
752 SetCaretPos(rect.top+1, thumbPos+1);
757 /***********************************************************************
758 * SCROLL_DrawSizeGrip
760 * Draw the size grip.
762 static void SCROLL_DrawSizeGrip( HWND hwnd, HDC hdc)
764 RECT rc;
766 GetClientRect( hwnd, &rc );
767 FillRect( hdc, &rc, GetSysColorBrush(COLOR_SCROLLBAR) );
768 rc.left = max( rc.left, rc.right - GetSystemMetrics(SM_CXVSCROLL) - 1 );
769 rc.top = max( rc.top, rc.bottom - GetSystemMetrics(SM_CYHSCROLL) - 1 );
770 DrawFrameControl( hdc, &rc, DFC_SCROLL, DFCS_SCROLLSIZEGRIP );
774 /***********************************************************************
775 * SCROLL_RefreshScrollBar
777 * Repaint the scroll bar interior after a SetScrollRange() or
778 * SetScrollPos() call.
780 static void SCROLL_RefreshScrollBar( HWND hwnd, INT nBar,
781 BOOL arrows, BOOL interior )
783 HDC hdc = GetDCEx( hwnd, 0,
784 DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW) );
785 if (!hdc) return;
787 SCROLL_DrawScrollBar( hwnd, hdc, nBar, arrows, interior );
788 ReleaseDC( hwnd, hdc );
792 /***********************************************************************
793 * SCROLL_HandleKbdEvent
795 * Handle a keyboard event (only for SB_CTL scrollbars with focus).
797 * PARAMS
798 * hwnd [I] Handle of window with scrollbar(s)
799 * wParam [I] Variable input including enable state
800 * lParam [I] Variable input including input point
802 static void SCROLL_HandleKbdEvent(HWND hwnd, WPARAM wParam, LPARAM lParam)
804 TRACE("hwnd=%p wParam=%ld lParam=%ld\n", hwnd, wParam, lParam);
806 /* hide caret on first KEYDOWN to prevent flicker */
807 if ((lParam & PFD_DOUBLEBUFFER_DONTCARE) == 0)
808 HideCaret(hwnd);
810 switch(wParam)
812 case VK_PRIOR: wParam = SB_PAGEUP; break;
813 case VK_NEXT: wParam = SB_PAGEDOWN; break;
814 case VK_HOME: wParam = SB_TOP; break;
815 case VK_END: wParam = SB_BOTTOM; break;
816 case VK_UP: wParam = SB_LINEUP; break;
817 case VK_DOWN: wParam = SB_LINEDOWN; break;
818 case VK_LEFT: wParam = SB_LINEUP; break;
819 case VK_RIGHT: wParam = SB_LINEDOWN; break;
820 default: return;
822 SendMessageW(GetParent(hwnd),
823 ((GetWindowLongW( hwnd, GWL_STYLE ) & SBS_VERT) ?
824 WM_VSCROLL : WM_HSCROLL), wParam, (LPARAM)hwnd);
828 /***********************************************************************
829 * SCROLL_HandleScrollEvent
831 * Handle a mouse or timer event for the scrollbar.
832 * 'pt' is the location of the mouse event in client (for SB_CTL) or
833 * windows coordinates.
835 static void SCROLL_HandleScrollEvent( HWND hwnd, INT nBar, UINT msg, POINT pt)
837 /* Previous mouse position for timer events */
838 static POINT prevPt;
839 /* Thumb position when tracking started. */
840 static UINT trackThumbPos;
841 /* Position in the scroll-bar of the last button-down event. */
842 static INT lastClickPos;
843 /* Position in the scroll-bar of the last mouse event. */
844 static INT lastMousePos;
846 enum SCROLL_HITTEST hittest;
847 HWND hwndOwner, hwndCtl;
848 BOOL vertical;
849 INT arrowSize, thumbSize, thumbPos;
850 RECT rect;
851 HDC hdc;
853 SCROLLBAR_INFO *infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, FALSE );
854 if (!infoPtr) return;
855 if ((SCROLL_trackHitTest == SCROLL_NOWHERE) && (msg != WM_LBUTTONDOWN))
856 return;
858 if (nBar == SB_CTL && (GetWindowLongW( hwnd, GWL_STYLE ) & (SBS_SIZEGRIP | SBS_SIZEBOX)))
860 switch(msg)
862 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
863 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
864 SetCapture( hwnd );
865 prevPt = pt;
866 SCROLL_trackHitTest = hittest = SCROLL_THUMB;
867 break;
868 case WM_MOUSEMOVE:
869 GetClientRect(GetParent(GetParent(hwnd)),&rect);
870 prevPt = pt;
871 break;
872 case WM_LBUTTONUP:
873 ReleaseCapture();
874 SCROLL_trackHitTest = hittest = SCROLL_NOWHERE;
875 if (hwnd==GetFocus()) ShowCaret(hwnd);
876 break;
877 case WM_SYSTIMER:
878 pt = prevPt;
879 break;
881 return;
884 hdc = GetDCEx( hwnd, 0, DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW));
885 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
886 &arrowSize, &thumbSize, &thumbPos );
887 hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd) : hwnd;
888 hwndCtl = (nBar == SB_CTL) ? hwnd : 0;
890 switch(msg)
892 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
893 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
894 SCROLL_trackVertical = vertical;
895 SCROLL_trackHitTest = hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
896 lastClickPos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
897 lastMousePos = lastClickPos;
898 trackThumbPos = thumbPos;
899 prevPt = pt;
900 if (nBar == SB_CTL && (GetWindowLongW(hwnd, GWL_STYLE) & WS_TABSTOP)) SetFocus( hwnd );
901 SetCapture( hwnd );
902 break;
904 case WM_MOUSEMOVE:
905 hittest = SCROLL_HitTest( hwnd, nBar, pt, TRUE );
906 prevPt = pt;
907 break;
909 case WM_LBUTTONUP:
910 hittest = SCROLL_NOWHERE;
911 ReleaseCapture();
912 /* if scrollbar has focus, show back caret */
913 if (hwnd==GetFocus()) ShowCaret(hwnd);
914 break;
916 case WM_SYSTIMER:
917 pt = prevPt;
918 hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
919 break;
921 default:
922 return; /* Should never happen */
925 TRACE("Event: hwnd=%p bar=%d msg=%s pt=%d,%d hit=%d\n",
926 hwnd, nBar, SPY_GetMsgName(msg,hwnd), pt.x, pt.y, hittest );
928 switch(SCROLL_trackHitTest)
930 case SCROLL_NOWHERE: /* No tracking in progress */
931 break;
933 case SCROLL_TOP_ARROW:
934 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
935 (hittest == SCROLL_trackHitTest), FALSE );
936 if (hittest == SCROLL_trackHitTest)
938 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
940 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
941 SB_LINEUP, (LPARAM)hwndCtl );
944 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
945 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
947 else KillSystemTimer( hwnd, SCROLL_TIMER );
948 break;
950 case SCROLL_TOP_RECT:
951 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
952 thumbPos, infoPtr->flags, vertical,
953 (hittest == SCROLL_trackHitTest), FALSE );
954 if (hittest == SCROLL_trackHitTest)
956 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
958 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
959 SB_PAGEUP, (LPARAM)hwndCtl );
961 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
962 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
964 else KillSystemTimer( hwnd, SCROLL_TIMER );
965 break;
967 case SCROLL_THUMB:
968 if (msg == WM_LBUTTONDOWN)
970 SCROLL_TrackingWin = hwnd;
971 SCROLL_TrackingBar = nBar;
972 SCROLL_TrackingPos = trackThumbPos + lastMousePos - lastClickPos;
973 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
974 vertical,
975 SCROLL_TrackingPos );
976 if (!SCROLL_MovingThumb)
977 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
979 else if (msg == WM_LBUTTONUP)
981 if (SCROLL_MovingThumb)
982 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
984 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
985 thumbPos, infoPtr->flags, vertical,
986 FALSE, FALSE );
988 else /* WM_MOUSEMOVE */
990 INT pos;
992 if (!SCROLL_PtInRectEx( &rect, pt, vertical )) pos = lastClickPos;
993 else
995 pt = SCROLL_ClipPos( &rect, pt );
996 pos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
998 if ( (pos != lastMousePos) || (!SCROLL_MovingThumb) )
1000 if (SCROLL_MovingThumb)
1001 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
1002 arrowSize, thumbSize );
1003 lastMousePos = pos;
1004 SCROLL_TrackingPos = trackThumbPos + pos - lastClickPos;
1005 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
1006 vertical,
1007 SCROLL_TrackingPos );
1008 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1009 MAKEWPARAM( SB_THUMBTRACK, SCROLL_TrackingVal),
1010 (LPARAM)hwndCtl );
1011 if (!SCROLL_MovingThumb)
1012 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
1013 arrowSize, thumbSize );
1016 break;
1018 case SCROLL_BOTTOM_RECT:
1019 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
1020 thumbPos, infoPtr->flags, vertical,
1021 FALSE, (hittest == SCROLL_trackHitTest) );
1022 if (hittest == SCROLL_trackHitTest)
1024 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1026 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1027 SB_PAGEDOWN, (LPARAM)hwndCtl );
1029 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1030 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
1032 else KillSystemTimer( hwnd, SCROLL_TIMER );
1033 break;
1035 case SCROLL_BOTTOM_ARROW:
1036 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
1037 FALSE, (hittest == SCROLL_trackHitTest) );
1038 if (hittest == SCROLL_trackHitTest)
1040 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1042 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1043 SB_LINEDOWN, (LPARAM)hwndCtl );
1046 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1047 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
1049 else KillSystemTimer( hwnd, SCROLL_TIMER );
1050 break;
1053 if (msg == WM_LBUTTONDOWN)
1056 if (hittest == SCROLL_THUMB)
1058 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1059 trackThumbPos + lastMousePos - lastClickPos );
1060 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1061 MAKEWPARAM( SB_THUMBTRACK, val ), (LPARAM)hwndCtl );
1065 if (msg == WM_LBUTTONUP)
1067 hittest = SCROLL_trackHitTest;
1068 SCROLL_trackHitTest = SCROLL_NOWHERE; /* Terminate tracking */
1070 if (hittest == SCROLL_THUMB)
1072 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1073 trackThumbPos + lastMousePos - lastClickPos );
1074 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1075 MAKEWPARAM( SB_THUMBPOSITION, val ), (LPARAM)hwndCtl );
1077 /* SB_ENDSCROLL doesn't report thumb position */
1078 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1079 SB_ENDSCROLL, (LPARAM)hwndCtl );
1081 /* Terminate tracking */
1082 SCROLL_TrackingWin = 0;
1085 ReleaseDC( hwnd, hdc );
1089 /***********************************************************************
1090 * SCROLL_TrackScrollBar
1092 * Track a mouse button press on a scroll-bar.
1093 * pt is in screen-coordinates for non-client scroll bars.
1095 void SCROLL_TrackScrollBar( HWND hwnd, INT scrollbar, POINT pt )
1097 MSG msg;
1098 RECT rect;
1100 if (scrollbar != SB_CTL)
1102 WIN_GetRectangles( hwnd, COORDS_CLIENT, &rect, NULL );
1103 ScreenToClient( hwnd, &pt );
1104 pt.x -= rect.left;
1105 pt.y -= rect.top;
1107 else
1108 rect.left = rect.top = 0;
1110 SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt );
1114 if (!GetMessageW( &msg, 0, 0, 0 )) break;
1115 if (CallMsgFilterW( &msg, MSGF_SCROLLBAR )) continue;
1116 if (msg.message == WM_LBUTTONUP ||
1117 msg.message == WM_MOUSEMOVE ||
1118 (msg.message == WM_SYSTIMER && msg.wParam == SCROLL_TIMER))
1120 pt.x = (short)LOWORD(msg.lParam) - rect.left;
1121 pt.y = (short)HIWORD(msg.lParam) - rect.top;
1122 SCROLL_HandleScrollEvent( hwnd, scrollbar, msg.message, pt );
1124 else
1126 TranslateMessage( &msg );
1127 DispatchMessageW( &msg );
1129 if (!IsWindow( hwnd ))
1131 ReleaseCapture();
1132 break;
1134 } while (msg.message != WM_LBUTTONUP && GetCapture() == hwnd);
1138 /***********************************************************************
1139 * SCROLL_CreateScrollBar
1141 * Create a scroll bar
1143 * PARAMS
1144 * hwnd [I] Handle of window with scrollbar(s)
1145 * lpCreate [I] The style and place of the scroll bar
1147 static void SCROLL_CreateScrollBar(HWND hwnd, LPCREATESTRUCTW lpCreate)
1149 LPSCROLLBAR_INFO info = NULL;
1150 WND *win;
1152 TRACE("hwnd=%p lpCreate=%p\n", hwnd, lpCreate);
1154 win = WIN_GetPtr(hwnd);
1155 if (win->cbWndExtra >= sizeof(SCROLLBAR_WNDDATA))
1157 SCROLLBAR_WNDDATA *data = (SCROLLBAR_WNDDATA*)win->wExtra;
1158 data->magic = SCROLLBAR_MAGIC;
1159 info = &data->info;
1161 else WARN("Not enough extra data\n");
1162 WIN_ReleasePtr(win);
1163 if (!info) return;
1165 if (lpCreate->style & WS_DISABLED)
1167 info->flags = ESB_DISABLE_BOTH;
1168 TRACE("Created WS_DISABLED scrollbar\n");
1171 if (lpCreate->style & (SBS_SIZEGRIP | SBS_SIZEBOX))
1173 if (lpCreate->style & SBS_SIZEBOXTOPLEFTALIGN)
1174 MoveWindow( hwnd, lpCreate->x, lpCreate->y, GetSystemMetrics(SM_CXVSCROLL)+1,
1175 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1176 else if(lpCreate->style & SBS_SIZEBOXBOTTOMRIGHTALIGN)
1177 MoveWindow( hwnd, lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1178 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1179 GetSystemMetrics(SM_CXVSCROLL)+1,
1180 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1182 else if (lpCreate->style & SBS_VERT)
1184 if (lpCreate->style & SBS_LEFTALIGN)
1185 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1186 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1187 else if (lpCreate->style & SBS_RIGHTALIGN)
1188 MoveWindow( hwnd,
1189 lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1190 lpCreate->y,
1191 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1193 else /* SBS_HORZ */
1195 if (lpCreate->style & SBS_TOPALIGN)
1196 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1197 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1198 else if (lpCreate->style & SBS_BOTTOMALIGN)
1199 MoveWindow( hwnd,
1200 lpCreate->x,
1201 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1202 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1207 /*************************************************************************
1208 * SCROLL_GetScrollInfo
1210 * Internal helper for the API function
1212 * PARAMS
1213 * hwnd [I] Handle of window with scrollbar(s)
1214 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1215 * info [IO] fMask specifies which values to retrieve
1217 * RETURNS
1218 * FALSE if requested field not filled (f.i. scroll bar does not exist)
1220 static BOOL SCROLL_GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1222 LPSCROLLBAR_INFO infoPtr;
1224 /* handle invalid data structure */
1225 if (!SCROLL_ScrollInfoValid(info)
1226 || !(infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE)))
1227 return FALSE;
1229 /* fill in the desired scroll info structure */
1230 if (info->fMask & SIF_PAGE) info->nPage = infoPtr->page;
1231 if (info->fMask & SIF_POS) info->nPos = infoPtr->curVal;
1232 if ((info->fMask & SIF_TRACKPOS) && (info->cbSize == sizeof(*info)))
1233 info->nTrackPos = (SCROLL_TrackingWin == WIN_GetFullHandle(hwnd)) ? SCROLL_TrackingVal : infoPtr->curVal;
1234 if (info->fMask & SIF_RANGE)
1236 info->nMin = infoPtr->minVal;
1237 info->nMax = infoPtr->maxVal;
1240 TRACE("cbSize %02x fMask %04x nMin %d nMax %d nPage %u nPos %d nTrackPos %d\n",
1241 info->cbSize, info->fMask, info->nMin, info->nMax, info->nPage,
1242 info->nPos, info->nTrackPos);
1244 return (info->fMask & SIF_ALL) != 0;
1248 /*************************************************************************
1249 * SCROLL_GetScrollBarInfo
1251 * Internal helper for the API function
1253 * PARAMS
1254 * hwnd [I] Handle of window with scrollbar(s)
1255 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1256 * info [IO] cbSize specifies the size of the structure
1258 * RETURNS
1259 * FALSE if failed
1261 static BOOL SCROLL_GetScrollBarInfo(HWND hwnd, LONG idObject, LPSCROLLBARINFO info)
1263 LPSCROLLBAR_INFO infoPtr;
1264 INT nBar;
1265 INT nDummy;
1266 DWORD style = GetWindowLongW(hwnd, GWL_STYLE);
1267 BOOL pressed;
1268 RECT rect;
1270 switch (idObject)
1272 case OBJID_CLIENT: nBar = SB_CTL; break;
1273 case OBJID_HSCROLL: nBar = SB_HORZ; break;
1274 case OBJID_VSCROLL: nBar = SB_VERT; break;
1275 default: return FALSE;
1278 /* handle invalid data structure */
1279 if (info->cbSize != sizeof(*info))
1280 return FALSE;
1282 SCROLL_GetScrollBarRect(hwnd, nBar, &info->rcScrollBar, &nDummy,
1283 &info->dxyLineButton, &info->xyThumbTop);
1284 /* rcScrollBar needs to be in screen coordinates */
1285 GetWindowRect(hwnd, &rect);
1286 OffsetRect(&info->rcScrollBar, rect.left, rect.top);
1288 info->xyThumbBottom = info->xyThumbTop + info->dxyLineButton;
1290 infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, TRUE);
1291 if (!infoPtr)
1292 return FALSE;
1294 /* Scroll bar state */
1295 info->rgstate[0] = 0;
1296 if ((nBar == SB_HORZ && !(style & WS_HSCROLL))
1297 || (nBar == SB_VERT && !(style & WS_VSCROLL)))
1298 info->rgstate[0] |= STATE_SYSTEM_INVISIBLE;
1299 if (infoPtr->minVal >= infoPtr->maxVal - max(infoPtr->page - 1, 0))
1301 if (!(info->rgstate[0] & STATE_SYSTEM_INVISIBLE))
1302 info->rgstate[0] |= STATE_SYSTEM_UNAVAILABLE;
1303 else
1304 info->rgstate[0] |= STATE_SYSTEM_OFFSCREEN;
1306 if (nBar == SB_CTL && !IsWindowEnabled(hwnd))
1307 info->rgstate[0] |= STATE_SYSTEM_UNAVAILABLE;
1309 pressed = ((nBar == SB_VERT) == SCROLL_trackVertical && GetCapture() == hwnd);
1311 /* Top/left arrow button state. MSDN says top/right, but I don't believe it */
1312 info->rgstate[1] = 0;
1313 if (pressed && SCROLL_trackHitTest == SCROLL_TOP_ARROW)
1314 info->rgstate[1] |= STATE_SYSTEM_PRESSED;
1315 if (infoPtr->flags & ESB_DISABLE_LTUP)
1316 info->rgstate[1] |= STATE_SYSTEM_UNAVAILABLE;
1318 /* Page up/left region state. MSDN says up/right, but I don't believe it */
1319 info->rgstate[2] = 0;
1320 if (infoPtr->curVal == infoPtr->minVal)
1321 info->rgstate[2] |= STATE_SYSTEM_INVISIBLE;
1322 if (pressed && SCROLL_trackHitTest == SCROLL_TOP_RECT)
1323 info->rgstate[2] |= STATE_SYSTEM_PRESSED;
1325 /* Thumb state */
1326 info->rgstate[3] = 0;
1327 if (pressed && SCROLL_trackHitTest == SCROLL_THUMB)
1328 info->rgstate[3] |= STATE_SYSTEM_PRESSED;
1330 /* Page down/right region state. MSDN says down/left, but I don't believe it */
1331 info->rgstate[4] = 0;
1332 if (infoPtr->curVal >= infoPtr->maxVal - 1)
1333 info->rgstate[4] |= STATE_SYSTEM_INVISIBLE;
1334 if (pressed && SCROLL_trackHitTest == SCROLL_BOTTOM_RECT)
1335 info->rgstate[4] |= STATE_SYSTEM_PRESSED;
1337 /* Bottom/right arrow button state. MSDN says bottom/left, but I don't believe it */
1338 info->rgstate[5] = 0;
1339 if (pressed && SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW)
1340 info->rgstate[5] |= STATE_SYSTEM_PRESSED;
1341 if (infoPtr->flags & ESB_DISABLE_RTDN)
1342 info->rgstate[5] |= STATE_SYSTEM_UNAVAILABLE;
1344 return TRUE;
1348 /*************************************************************************
1349 * SCROLL_GetScrollPos
1351 * Internal helper for the API function
1353 * PARAMS
1354 * hwnd [I] Handle of window with scrollbar(s)
1355 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1357 static INT SCROLL_GetScrollPos(HWND hwnd, INT nBar)
1359 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1360 return infoPtr ? infoPtr->curVal: 0;
1364 /*************************************************************************
1365 * SCROLL_GetScrollRange
1367 * Internal helper for the API function
1369 * PARAMS
1370 * hwnd [I] Handle of window with scrollbar(s)
1371 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1372 * lpMin [O] Where to store minimum value
1373 * lpMax [O] Where to store maximum value
1375 * RETURNS
1376 * Success: TRUE
1377 * Failure: FALSE
1379 static BOOL SCROLL_GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1381 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1383 if (lpMin) *lpMin = infoPtr ? infoPtr->minVal : 0;
1384 if (lpMax) *lpMax = infoPtr ? infoPtr->maxVal : 0;
1386 return TRUE;
1390 /*************************************************************************
1391 * SCROLL_SetScrollRange
1393 * PARAMS
1394 * hwnd [I] Handle of window with scrollbar(s)
1395 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1396 * lpMin [I] Minimum value
1397 * lpMax [I] Maximum value
1400 static BOOL SCROLL_SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal)
1402 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1404 TRACE("hwnd=%p nBar=%d min=%d max=%d\n", hwnd, nBar, minVal, maxVal);
1406 if (infoPtr)
1408 infoPtr->minVal = minVal;
1409 infoPtr->maxVal = maxVal;
1411 return TRUE;
1415 /***********************************************************************
1416 * ScrollBarWndProc_common
1418 LRESULT ScrollBarWndProc_common( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, BOOL unicode )
1420 if (!IsWindow( hwnd )) return 0;
1422 switch(message)
1424 case WM_CREATE:
1425 SCROLL_CreateScrollBar(hwnd, (LPCREATESTRUCTW)lParam);
1426 break;
1428 case WM_ENABLE:
1430 SCROLLBAR_INFO *infoPtr;
1431 if ((infoPtr = SCROLL_GetInternalInfo( hwnd, SB_CTL, FALSE )))
1433 infoPtr->flags = wParam ? ESB_ENABLE_BOTH : ESB_DISABLE_BOTH;
1434 SCROLL_RefreshScrollBar(hwnd, SB_CTL, TRUE, TRUE);
1437 return 0;
1439 case WM_LBUTTONDBLCLK:
1440 case WM_LBUTTONDOWN:
1441 if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEGRIP)
1443 SendMessageW( GetParent(hwnd), WM_SYSCOMMAND,
1444 SC_SIZE + ((GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_LAYOUTRTL) ?
1445 WMSZ_BOTTOMLEFT : WMSZ_BOTTOMRIGHT), lParam );
1447 else
1449 POINT pt;
1450 pt.x = (short)LOWORD(lParam);
1451 pt.y = (short)HIWORD(lParam);
1452 SCROLL_TrackScrollBar( hwnd, SB_CTL, pt );
1454 break;
1455 case WM_LBUTTONUP:
1456 case WM_MOUSEMOVE:
1457 case WM_SYSTIMER:
1459 POINT pt;
1460 pt.x = (short)LOWORD(lParam);
1461 pt.y = (short)HIWORD(lParam);
1462 SCROLL_HandleScrollEvent( hwnd, SB_CTL, message, pt );
1464 break;
1466 case WM_KEYDOWN:
1467 SCROLL_HandleKbdEvent(hwnd, wParam, lParam);
1468 break;
1470 case WM_KEYUP:
1471 ShowCaret(hwnd);
1472 break;
1474 case WM_SETFOCUS:
1476 /* Create a caret when a ScrollBar get focus */
1477 RECT rect;
1478 int arrowSize, thumbSize, thumbPos, vertical;
1479 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,
1480 &arrowSize, &thumbSize, &thumbPos );
1481 if (!vertical)
1483 CreateCaret(hwnd, (HBITMAP)1, thumbSize-2, rect.bottom-rect.top-2);
1484 SetCaretPos(thumbPos+1, rect.top+1);
1486 else
1488 CreateCaret(hwnd, (HBITMAP)1, rect.right-rect.left-2,thumbSize-2);
1489 SetCaretPos(rect.top+1, thumbPos+1);
1491 ShowCaret(hwnd);
1493 break;
1495 case WM_KILLFOCUS:
1497 RECT rect;
1498 int arrowSize, thumbSize, thumbPos, vertical;
1499 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,&arrowSize, &thumbSize, &thumbPos );
1500 if (!vertical){
1501 rect.left=thumbPos+1;
1502 rect.right=rect.left+thumbSize;
1504 else
1506 rect.top=thumbPos+1;
1507 rect.bottom=rect.top+thumbSize;
1509 HideCaret(hwnd);
1510 InvalidateRect(hwnd,&rect,0);
1511 DestroyCaret();
1513 break;
1515 case WM_ERASEBKGND:
1516 return 1;
1518 case WM_GETDLGCODE:
1519 return DLGC_WANTARROWS; /* Windows returns this value */
1521 case WM_PAINT:
1523 PAINTSTRUCT ps;
1524 HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
1525 if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEGRIP)
1527 SCROLL_DrawSizeGrip( hwnd, hdc);
1529 else if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEBOX)
1531 RECT rc;
1532 GetClientRect( hwnd, &rc );
1533 FillRect( hdc, &rc, GetSysColorBrush(COLOR_SCROLLBAR) );
1535 else
1536 SCROLL_DrawScrollBar( hwnd, hdc, SB_CTL, TRUE, TRUE );
1537 if (!wParam) EndPaint(hwnd, &ps);
1539 break;
1541 case WM_SETCURSOR:
1542 if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEGRIP)
1544 ULONG_PTR cursor = (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_LAYOUTRTL) ? IDC_SIZENESW : IDC_SIZENWSE;
1545 return (LRESULT)SetCursor( LoadCursorA( 0, (LPSTR)cursor ));
1547 return DefWindowProcW( hwnd, message, wParam, lParam );
1549 case SBM_SETPOS:
1550 return SetScrollPos( hwnd, SB_CTL, wParam, (BOOL)lParam );
1552 case SBM_GETPOS:
1553 return SCROLL_GetScrollPos(hwnd, SB_CTL);
1555 case SBM_SETRANGEREDRAW:
1556 case SBM_SETRANGE:
1558 INT oldPos = SCROLL_GetScrollPos( hwnd, SB_CTL );
1559 SCROLL_SetScrollRange( hwnd, SB_CTL, wParam, lParam );
1560 if (message == SBM_SETRANGEREDRAW)
1561 SCROLL_RefreshScrollBar( hwnd, SB_CTL, TRUE, TRUE );
1562 if (oldPos != SCROLL_GetScrollPos( hwnd, SB_CTL )) return oldPos;
1564 return 0;
1566 case SBM_GETRANGE:
1567 return SCROLL_GetScrollRange(hwnd, SB_CTL, (LPINT)wParam, (LPINT)lParam);
1569 case SBM_ENABLE_ARROWS:
1570 return EnableScrollBar( hwnd, SB_CTL, wParam );
1572 case SBM_SETSCROLLINFO:
1573 return SCROLL_SetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam, wParam );
1575 case SBM_GETSCROLLINFO:
1576 return SCROLL_GetScrollInfo(hwnd, SB_CTL, (SCROLLINFO *)lParam);
1578 case SBM_GETSCROLLBARINFO:
1579 return SCROLL_GetScrollBarInfo(hwnd, OBJID_CLIENT, (SCROLLBARINFO *)lParam);
1581 case 0x00e5:
1582 case 0x00e7:
1583 case 0x00e8:
1584 case 0x00ec:
1585 case 0x00ed:
1586 case 0x00ee:
1587 case 0x00ef:
1588 ERR("unknown Win32 msg %04x wp=%08lx lp=%08lx\n",
1589 message, wParam, lParam );
1590 break;
1592 default:
1593 if (message >= WM_USER)
1594 WARN("unknown msg %04x wp=%04lx lp=%08lx\n",
1595 message, wParam, lParam );
1596 if (unicode)
1597 return DefWindowProcW( hwnd, message, wParam, lParam );
1598 else
1599 return DefWindowProcA( hwnd, message, wParam, lParam );
1601 return 0;
1605 /*************************************************************************
1606 * SetScrollInfo (USER32.@)
1608 * SetScrollInfo can be used to set the position, upper bound,
1609 * lower bound, and page size of a scrollbar control.
1611 * PARAMS
1612 * hwnd [I] Handle of window with scrollbar(s)
1613 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1614 * info [I] Specifies what to change and new values
1615 * bRedraw [I] Should scrollbar be redrawn afterwards?
1617 * RETURNS
1618 * Scrollbar position
1620 * NOTE
1621 * For 100 lines of text to be displayed in a window of 25 lines,
1622 * one would for instance use info->nMin=0, info->nMax=75
1623 * (corresponding to the 76 different positions of the window on
1624 * the text), and info->nPage=25.
1626 INT WINAPI DECLSPEC_HOTPATCH SetScrollInfo(HWND hwnd, INT nBar, const SCROLLINFO *info, BOOL bRedraw)
1628 TRACE("hwnd=%p nBar=%d info=%p, bRedraw=%d\n", hwnd, nBar, info, bRedraw);
1630 /* Refer SB_CTL requests to the window */
1631 if (nBar == SB_CTL)
1632 return SendMessageW(hwnd, SBM_SETSCROLLINFO, bRedraw, (LPARAM)info);
1633 else
1634 return SCROLL_SetScrollInfo( hwnd, nBar, info, bRedraw );
1637 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar, LPCSCROLLINFO info, BOOL bRedraw )
1639 /* Update the scrollbar state and set action flags according to
1640 * what has to be done graphics wise. */
1642 SCROLLBAR_INFO *infoPtr;
1643 UINT new_flags;
1644 INT action = 0;
1646 /* handle invalid data structure */
1647 if (!SCROLL_ScrollInfoValid(info)
1648 || !(infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, TRUE)))
1649 return 0;
1651 if (TRACE_ON(scroll))
1653 TRACE("hwnd=%p bar=%d", hwnd, nBar);
1654 if (info->fMask & SIF_PAGE) TRACE( " page=%d", info->nPage );
1655 if (info->fMask & SIF_POS) TRACE( " pos=%d", info->nPos );
1656 if (info->fMask & SIF_RANGE) TRACE( " min=%d max=%d", info->nMin, info->nMax );
1657 TRACE("\n");
1660 /* Set the page size */
1662 if (info->fMask & SIF_PAGE)
1664 if( infoPtr->page != info->nPage )
1666 infoPtr->page = info->nPage;
1667 action |= SA_SSI_REFRESH;
1671 /* Set the scroll pos */
1673 if (info->fMask & SIF_POS)
1675 if( infoPtr->curVal != info->nPos )
1677 infoPtr->curVal = info->nPos;
1678 action |= SA_SSI_REFRESH;
1682 /* Set the scroll range */
1684 if (info->fMask & SIF_RANGE)
1686 /* Invalid range -> range is set to (0,0) */
1687 if ((info->nMin > info->nMax) ||
1688 ((UINT)(info->nMax - info->nMin) >= 0x80000000))
1690 action |= SA_SSI_REFRESH;
1691 infoPtr->minVal = 0;
1692 infoPtr->maxVal = 0;
1694 else
1696 if( infoPtr->minVal != info->nMin ||
1697 infoPtr->maxVal != info->nMax )
1699 action |= SA_SSI_REFRESH;
1700 infoPtr->minVal = info->nMin;
1701 infoPtr->maxVal = info->nMax;
1706 /* Make sure the page size is valid */
1707 if (infoPtr->page < 0) infoPtr->page = 0;
1708 else if (infoPtr->page > infoPtr->maxVal - infoPtr->minVal + 1 )
1709 infoPtr->page = infoPtr->maxVal - infoPtr->minVal + 1;
1711 /* Make sure the pos is inside the range */
1713 if (infoPtr->curVal < infoPtr->minVal)
1714 infoPtr->curVal = infoPtr->minVal;
1715 else if (infoPtr->curVal > infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1716 infoPtr->curVal = infoPtr->maxVal - max( infoPtr->page-1, 0 );
1718 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1719 infoPtr->page, infoPtr->curVal,
1720 infoPtr->minVal, infoPtr->maxVal );
1722 /* don't change the scrollbar state if SetScrollInfo
1723 * is just called with SIF_DISABLENOSCROLL
1725 if(!(info->fMask & SIF_ALL)) goto done;
1727 /* Check if the scrollbar should be hidden or disabled */
1729 if (info->fMask & (SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL))
1731 new_flags = infoPtr->flags;
1732 if (infoPtr->minVal >= infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1734 /* Hide or disable scroll-bar */
1735 if (info->fMask & SIF_DISABLENOSCROLL)
1737 new_flags = ESB_DISABLE_BOTH;
1738 action |= SA_SSI_REFRESH;
1740 else if ((nBar != SB_CTL) && (action & SA_SSI_REFRESH))
1742 action = SA_SSI_HIDE;
1745 else /* Show and enable scroll-bar only if no page only changed. */
1746 if (info->fMask != SIF_PAGE)
1748 new_flags = ESB_ENABLE_BOTH;
1749 if ((nBar != SB_CTL) && ( (action & SA_SSI_REFRESH) ))
1750 action |= SA_SSI_SHOW;
1753 if (infoPtr->flags != new_flags) /* check arrow flags */
1755 infoPtr->flags = new_flags;
1756 action |= SA_SSI_REPAINT_ARROWS;
1760 done:
1761 if( action & SA_SSI_HIDE )
1762 SCROLL_ShowScrollBar( hwnd, nBar, FALSE, FALSE );
1763 else
1765 if( action & SA_SSI_SHOW )
1766 if( SCROLL_ShowScrollBar( hwnd, nBar, TRUE, TRUE ) )
1767 return infoPtr->curVal; /* SetWindowPos() already did the painting */
1769 if( bRedraw )
1770 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
1771 else if( action & SA_SSI_REPAINT_ARROWS )
1772 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, FALSE );
1775 /* Return current position */
1776 return infoPtr->curVal;
1780 /*************************************************************************
1781 * GetScrollInfo (USER32.@)
1783 * GetScrollInfo can be used to retrieve the position, upper bound,
1784 * lower bound, and page size of a scrollbar control.
1786 * PARAMS
1787 * hwnd [I] Handle of window with scrollbar(s)
1788 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1789 * info [IO] fMask specifies which values to retrieve
1791 * RETURNS
1792 * TRUE if SCROLLINFO is filled
1793 * ( if nBar is SB_CTL, GetScrollInfo returns TRUE even if nothing
1794 * is filled)
1796 BOOL WINAPI DECLSPEC_HOTPATCH GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1798 TRACE("hwnd=%p nBar=%d info=%p\n", hwnd, nBar, info);
1800 /* Refer SB_CTL requests to the window */
1801 if (nBar == SB_CTL)
1803 SendMessageW(hwnd, SBM_GETSCROLLINFO, 0, (LPARAM)info);
1804 return TRUE;
1806 return SCROLL_GetScrollInfo(hwnd, nBar, info);
1810 /*************************************************************************
1811 * GetScrollBarInfo (USER32.@)
1813 * GetScrollBarInfo can be used to retrieve information about a scrollbar
1814 * control.
1816 * PARAMS
1817 * hwnd [I] Handle of window with scrollbar(s)
1818 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1819 * info [IO] cbSize specifies the size of SCROLLBARINFO
1821 * RETURNS
1822 * TRUE if success
1824 BOOL WINAPI GetScrollBarInfo(HWND hwnd, LONG idObject, LPSCROLLBARINFO info)
1826 TRACE("hwnd=%p idObject=%d info=%p\n", hwnd, idObject, info);
1828 /* Refer OBJID_CLIENT requests to the window */
1829 if (idObject == OBJID_CLIENT)
1830 return SendMessageW(hwnd, SBM_GETSCROLLBARINFO, 0, (LPARAM)info);
1831 else
1832 return SCROLL_GetScrollBarInfo(hwnd, idObject, info);
1836 /*************************************************************************
1837 * SetScrollPos (USER32.@)
1839 * Sets the current position of the scroll thumb.
1841 * PARAMS
1842 * hwnd [I] Handle of window with scrollbar(s)
1843 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1844 * nPos [I] New value
1845 * bRedraw [I] Should scrollbar be redrawn afterwards?
1847 * RETURNS
1848 * Success: Scrollbar position
1849 * Failure: 0
1851 * REMARKS
1852 * Note the ambiguity when 0 is returned. Use GetLastError
1853 * to make sure there was an error (and to know which one).
1855 INT WINAPI DECLSPEC_HOTPATCH SetScrollPos( HWND hwnd, INT nBar, INT nPos, BOOL bRedraw)
1857 SCROLLINFO info;
1858 SCROLLBAR_INFO *infoPtr;
1859 INT oldPos = 0;
1861 if ((infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, FALSE ))) oldPos = infoPtr->curVal;
1862 info.cbSize = sizeof(info);
1863 info.nPos = nPos;
1864 info.fMask = SIF_POS;
1865 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1866 return oldPos;
1870 /*************************************************************************
1871 * GetScrollPos (USER32.@)
1873 * Gets the current position of the scroll thumb.
1875 * PARAMS
1876 * hwnd [I] Handle of window with scrollbar(s)
1877 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1879 * RETURNS
1880 * Success: Current position
1881 * Failure: 0
1883 * REMARKS
1884 * There is ambiguity when 0 is returned. Use GetLastError
1885 * to make sure there was an error (and to know which one).
1887 INT WINAPI DECLSPEC_HOTPATCH GetScrollPos(HWND hwnd, INT nBar)
1889 TRACE("hwnd=%p nBar=%d\n", hwnd, nBar);
1891 /* Refer SB_CTL requests to the window */
1892 if (nBar == SB_CTL)
1893 return SendMessageW(hwnd, SBM_GETPOS, 0, 0);
1894 else
1895 return SCROLL_GetScrollPos(hwnd, nBar);
1899 /*************************************************************************
1900 * SetScrollRange (USER32.@)
1901 * The SetScrollRange function sets the minimum and maximum scroll box positions
1902 * If nMinPos and nMaxPos is the same value, the scroll bar will hide
1904 * Sets the range of the scroll bar.
1906 * PARAMS
1907 * hwnd [I] Handle of window with scrollbar(s)
1908 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1909 * minVal [I] New minimum value
1910 * maxVal [I] New Maximum value
1911 * bRedraw [I] Should scrollbar be redrawn afterwards?
1913 * RETURNS
1914 * Success: TRUE
1915 * Failure: FALSE
1917 BOOL WINAPI DECLSPEC_HOTPATCH SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal, BOOL bRedraw)
1919 SCROLLINFO info;
1921 TRACE("hwnd=%p nBar=%d min=%d max=%d, bRedraw=%d\n", hwnd, nBar, minVal, maxVal, bRedraw);
1923 info.cbSize = sizeof(info);
1924 info.fMask = SIF_RANGE;
1925 info.nMin = minVal;
1926 info.nMax = maxVal;
1927 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1928 return TRUE;
1932 /*************************************************************************
1933 * GetScrollRange (USER32.@)
1935 * Gets the range of the scroll bar.
1937 * PARAMS
1938 * hwnd [I] Handle of window with scrollbar(s)
1939 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1940 * lpMin [O] Where to store minimum value
1941 * lpMax [O] Where to store maximum value
1943 * RETURNS
1944 * TRUE if values is filled
1946 BOOL WINAPI DECLSPEC_HOTPATCH GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1948 TRACE("hwnd=%p nBar=%d lpMin=%p lpMax=%p\n", hwnd, nBar, lpMin, lpMax);
1950 /* Refer SB_CTL requests to the window */
1951 if (nBar == SB_CTL)
1952 SendMessageW(hwnd, SBM_GETRANGE, (WPARAM)lpMin, (LPARAM)lpMax);
1953 else
1954 SCROLL_GetScrollRange(hwnd, nBar, lpMin, lpMax);
1956 return TRUE;
1960 /*************************************************************************
1961 * SCROLL_ShowScrollBar()
1963 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1965 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar, BOOL fShowH, BOOL fShowV )
1967 ULONG old_style, set_bits = 0, clear_bits = 0;
1969 TRACE("hwnd=%p bar=%d horz=%d, vert=%d\n", hwnd, nBar, fShowH, fShowV );
1971 switch(nBar)
1973 case SB_CTL:
1974 ShowWindow( hwnd, fShowH ? SW_SHOW : SW_HIDE );
1975 return TRUE;
1977 case SB_BOTH:
1978 case SB_HORZ:
1979 if (fShowH) set_bits |= WS_HSCROLL;
1980 else clear_bits |= WS_HSCROLL;
1981 if( nBar == SB_HORZ ) break;
1982 /* fall through */
1983 case SB_VERT:
1984 if (fShowV) set_bits |= WS_VSCROLL;
1985 else clear_bits |= WS_VSCROLL;
1986 break;
1988 default:
1989 return FALSE; /* Nothing to do! */
1992 old_style = WIN_SetStyle( hwnd, set_bits, clear_bits );
1993 if ((old_style & clear_bits) != 0 || (old_style & set_bits) != set_bits)
1995 /* frame has been changed, let the window redraw itself */
1996 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
1997 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
1998 return TRUE;
2000 return FALSE; /* no frame changes */
2004 /*************************************************************************
2005 * ShowScrollBar (USER32.@)
2007 * Shows or hides the scroll bar.
2009 * PARAMS
2010 * hwnd [I] Handle of window with scrollbar(s)
2011 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
2012 * fShow [I] TRUE = show, FALSE = hide
2014 * RETURNS
2015 * Success: TRUE
2016 * Failure: FALSE
2018 BOOL WINAPI DECLSPEC_HOTPATCH ShowScrollBar(HWND hwnd, INT nBar, BOOL fShow)
2020 if ( !hwnd )
2021 return FALSE;
2023 SCROLL_ShowScrollBar( hwnd, nBar, (nBar == SB_VERT) ? 0 : fShow,
2024 (nBar == SB_HORZ) ? 0 : fShow );
2025 return TRUE;
2029 /*************************************************************************
2030 * EnableScrollBar (USER32.@)
2032 * Enables or disables the scroll bars.
2034 BOOL WINAPI DECLSPEC_HOTPATCH EnableScrollBar( HWND hwnd, UINT nBar, UINT flags )
2036 BOOL bFineWithMe;
2037 SCROLLBAR_INFO *infoPtr;
2039 flags &= ESB_DISABLE_BOTH;
2041 if (nBar == SB_BOTH)
2043 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, SB_VERT, TRUE ))) return FALSE;
2044 if (!(bFineWithMe = (infoPtr->flags == flags)) )
2046 infoPtr->flags = flags;
2047 SCROLL_RefreshScrollBar( hwnd, SB_VERT, TRUE, TRUE );
2049 nBar = SB_HORZ;
2051 else
2052 bFineWithMe = nBar != SB_CTL;
2054 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, TRUE ))) return FALSE;
2055 if (bFineWithMe && infoPtr->flags == flags) return FALSE;
2056 infoPtr->flags = flags;
2058 if (nBar == SB_CTL && (flags == ESB_DISABLE_BOTH || flags == ESB_ENABLE_BOTH))
2059 EnableWindow(hwnd, flags == ESB_ENABLE_BOTH);
2061 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
2062 return TRUE;