user32: Fix variable type in SCROLL_HandleScrollEvent(). Remove useless check in...
[wine/multimedia.git] / dlls / user32 / scroll.c
blob78564b04a8975e6bc465ab3c33e06e050d56d9a0
1 /*
2 * Scrollbar control
4 * Copyright 1993 Martin Ayotte
5 * Copyright 1994, 1996 Alexandre Julliard
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 * NOTES
23 * This code was audited for completeness against the documented features
24 * of Comctl32.dll version 6.0 on Oct. 8, 2004, by Dimitrie O. Paun.
26 * Unless otherwise noted, we believe this code to be complete, as per
27 * the specification mentioned above.
28 * If you discover missing features, or bugs, please note them below.
31 #include <stdarg.h>
33 #include "windef.h"
34 #include "winbase.h"
35 #include "wingdi.h"
36 #include "wine/winuser16.h"
37 #include "controls.h"
38 #include "win.h"
39 #include "wine/debug.h"
40 #include "user_private.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(scroll);
44 typedef struct
46 INT curVal; /* Current scroll-bar value */
47 INT minVal; /* Minimum scroll-bar value */
48 INT maxVal; /* Maximum scroll-bar value */
49 INT page; /* Page size of scroll bar (Win32) */
50 UINT flags; /* EnableScrollBar flags */
51 } SCROLLBAR_INFO, *LPSCROLLBAR_INFO;
54 /* Minimum size of the rectangle between the arrows */
55 #define SCROLL_MIN_RECT 4
57 /* Minimum size of the thumb in pixels */
58 #define SCROLL_MIN_THUMB 6
60 /* Overlap between arrows and thumb */
61 #define SCROLL_ARROW_THUMB_OVERLAP 0
63 /* Delay (in ms) before first repetition when holding the button down */
64 #define SCROLL_FIRST_DELAY 200
66 /* Delay (in ms) between scroll repetitions */
67 #define SCROLL_REPEAT_DELAY 50
69 /* Scroll timer id */
70 #define SCROLL_TIMER 0
72 /* Scroll-bar hit testing */
73 enum SCROLL_HITTEST
75 SCROLL_NOWHERE, /* Outside the scroll bar */
76 SCROLL_TOP_ARROW, /* Top or left arrow */
77 SCROLL_TOP_RECT, /* Rectangle between the top arrow and the thumb */
78 SCROLL_THUMB, /* Thumb rectangle */
79 SCROLL_BOTTOM_RECT, /* Rectangle between the thumb and the bottom arrow */
80 SCROLL_BOTTOM_ARROW /* Bottom or right arrow */
83 /* What to do after SCROLL_SetScrollInfo() */
84 #define SA_SSI_HIDE 0x0001
85 #define SA_SSI_SHOW 0x0002
86 #define SA_SSI_REFRESH 0x0004
87 #define SA_SSI_REPAINT_ARROWS 0x0008
89 /* Thumb-tracking info */
90 static HWND SCROLL_TrackingWin = 0;
91 static INT SCROLL_TrackingBar = 0;
92 static INT SCROLL_TrackingPos = 0;
93 static INT SCROLL_TrackingVal = 0;
94 /* Hit test code of the last button-down event */
95 static enum SCROLL_HITTEST SCROLL_trackHitTest;
96 static BOOL SCROLL_trackVertical;
98 /* Is the moving thumb being displayed? */
99 static BOOL SCROLL_MovingThumb = FALSE;
101 /* Local functions */
102 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar,
103 BOOL fShowH, BOOL fShowV );
104 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar,
105 const SCROLLINFO *info, BOOL bRedraw );
106 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
107 RECT *rect, INT arrowSize,
108 INT thumbSize, INT thumbPos,
109 UINT flags, BOOL vertical,
110 BOOL top_selected, BOOL bottom_selected );
111 static LRESULT WINAPI ScrollBarWndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
114 /*********************************************************************
115 * scrollbar class descriptor
117 static const WCHAR scrollbarW[] = {'S','c','r','o','l','l','B','a','r',0};
118 const struct builtin_class_descr SCROLL_builtin_class =
120 scrollbarW, /* name */
121 CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC, /* style */
122 NULL, /* procA (winproc is Unicode only) */
123 ScrollBarWndProc, /* procW */
124 sizeof(SCROLLBAR_INFO), /* extra */
125 IDC_ARROW, /* cursor */
126 0 /* brush */
129 /***********************************************************************
130 * SCROLL_ScrollInfoValid
132 * Determine if the supplied SCROLLINFO struct is valid.
133 * info [in] The SCROLLINFO struct to be tested
135 static inline BOOL SCROLL_ScrollInfoValid( LPCSCROLLINFO info )
137 return !(info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)
138 || (info->cbSize != sizeof(*info)
139 && info->cbSize != sizeof(*info) - sizeof(info->nTrackPos)));
143 /***********************************************************************
144 * SCROLL_GetInternalInfo
146 * Returns pointer to internal SCROLLBAR_INFO structure for nBar
147 * or NULL if failed (f.i. scroll bar does not exist yet)
148 * If alloc is TRUE and the struct does not exist yet, create it.
150 static SCROLLBAR_INFO *SCROLL_GetInternalInfo( HWND hwnd, INT nBar, BOOL alloc )
152 SCROLLBAR_INFO *infoPtr = NULL;
153 WND *wndPtr = WIN_GetPtr( hwnd );
155 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return NULL;
156 switch(nBar)
158 case SB_HORZ: infoPtr = (SCROLLBAR_INFO *)wndPtr->pHScroll; break;
159 case SB_VERT: infoPtr = (SCROLLBAR_INFO *)wndPtr->pVScroll; break;
160 case SB_CTL: infoPtr = (SCROLLBAR_INFO *)wndPtr->wExtra; break;
161 case SB_BOTH: WARN("with SB_BOTH\n"); break;
164 if (!infoPtr && alloc)
166 if (nBar != SB_HORZ && nBar != SB_VERT)
167 WARN("Cannot initialize nBar=%d\n",nBar);
168 else if ((infoPtr = HeapAlloc( GetProcessHeap(), 0, sizeof(SCROLLBAR_INFO) )))
170 /* Set default values */
171 infoPtr->minVal = infoPtr->curVal = infoPtr->page = 0;
172 /* From MSDN: max for a standard scroll bar is 100 by default. */
173 infoPtr->maxVal = 100;
174 /* Scroll bar is enabled by default after create */
175 infoPtr->flags = ESB_ENABLE_BOTH;
176 if (nBar == SB_HORZ) wndPtr->pHScroll = infoPtr;
177 else wndPtr->pVScroll = infoPtr;
180 WIN_ReleasePtr( wndPtr );
181 return infoPtr;
185 /***********************************************************************
186 * SCROLL_GetScrollBarRect
188 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
189 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
190 * 'arrowSize' returns the width or height of an arrow (depending on
191 * the orientation of the scrollbar), 'thumbSize' returns the size of
192 * the thumb, and 'thumbPos' returns the position of the thumb
193 * relative to the left or to the top.
194 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
196 static BOOL SCROLL_GetScrollBarRect( HWND hwnd, INT nBar, RECT *lprect,
197 INT *arrowSize, INT *thumbSize,
198 INT *thumbPos )
200 INT pixels;
201 BOOL vertical;
202 WND *wndPtr = WIN_GetPtr( hwnd );
204 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
206 switch(nBar)
208 case SB_HORZ:
209 lprect->left = wndPtr->rectClient.left - wndPtr->rectWindow.left;
210 lprect->top = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
211 lprect->right = wndPtr->rectClient.right - wndPtr->rectWindow.left;
212 lprect->bottom = lprect->top + GetSystemMetrics(SM_CYHSCROLL);
213 if(wndPtr->dwStyle & WS_BORDER) {
214 lprect->left--;
215 lprect->right++;
216 } else if(wndPtr->dwStyle & WS_VSCROLL)
217 lprect->right++;
218 vertical = FALSE;
219 break;
221 case SB_VERT:
222 if((wndPtr->dwExStyle & WS_EX_LEFTSCROLLBAR) != 0)
223 lprect->left = wndPtr->rectClient.left - wndPtr->rectWindow.left - GetSystemMetrics(SM_CXVSCROLL);
224 else
225 lprect->left = wndPtr->rectClient.right - wndPtr->rectWindow.left;
226 lprect->top = wndPtr->rectClient.top - wndPtr->rectWindow.top;
227 lprect->right = lprect->left + GetSystemMetrics(SM_CXVSCROLL);
228 lprect->bottom = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
229 if(wndPtr->dwStyle & WS_BORDER) {
230 lprect->top--;
231 lprect->bottom++;
232 } else if(wndPtr->dwStyle & WS_HSCROLL)
233 lprect->bottom++;
234 vertical = TRUE;
235 break;
237 case SB_CTL:
238 GetClientRect( hwnd, lprect );
239 vertical = ((wndPtr->dwStyle & SBS_VERT) != 0);
240 break;
242 default:
243 WIN_ReleasePtr( wndPtr );
244 return FALSE;
247 if (vertical) pixels = lprect->bottom - lprect->top;
248 else pixels = lprect->right - lprect->left;
250 if (pixels <= 2*GetSystemMetrics(SM_CXVSCROLL) + SCROLL_MIN_RECT)
252 if (pixels > SCROLL_MIN_RECT)
253 *arrowSize = (pixels - SCROLL_MIN_RECT) / 2;
254 else
255 *arrowSize = 0;
256 *thumbPos = *thumbSize = 0;
258 else
260 SCROLLBAR_INFO *info = SCROLL_GetInternalInfo( hwnd, nBar, FALSE );
261 if (!info)
263 WARN("called for missing scroll bar\n");
264 WIN_ReleasePtr( wndPtr );
265 return FALSE;
267 *arrowSize = GetSystemMetrics(SM_CXVSCROLL);
268 pixels -= (2 * (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP));
270 if (info->page)
272 *thumbSize = MulDiv(pixels,info->page,(info->maxVal-info->minVal+1));
273 if (*thumbSize < SCROLL_MIN_THUMB) *thumbSize = SCROLL_MIN_THUMB;
275 else *thumbSize = GetSystemMetrics(SM_CXVSCROLL);
277 if (((pixels -= *thumbSize ) < 0) ||
278 ((info->flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH))
280 /* Rectangle too small or scrollbar disabled -> no thumb */
281 *thumbPos = *thumbSize = 0;
283 else
285 INT max = info->maxVal - max( info->page-1, 0 );
286 if (info->minVal >= max)
287 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
288 else
289 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP
290 + MulDiv(pixels, (info->curVal-info->minVal),(max - info->minVal));
293 WIN_ReleasePtr( wndPtr );
294 return vertical;
298 /***********************************************************************
299 * SCROLL_GetThumbVal
301 * Compute the current scroll position based on the thumb position in pixels
302 * from the top of the scroll-bar.
304 static UINT SCROLL_GetThumbVal( SCROLLBAR_INFO *infoPtr, RECT *rect,
305 BOOL vertical, INT pos )
307 INT thumbSize;
308 INT pixels = vertical ? rect->bottom-rect->top : rect->right-rect->left;
310 if ((pixels -= 2*(GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP)) <= 0)
311 return infoPtr->minVal;
313 if (infoPtr->page)
315 thumbSize = MulDiv(pixels,infoPtr->page,(infoPtr->maxVal-infoPtr->minVal+1));
316 if (thumbSize < SCROLL_MIN_THUMB) thumbSize = SCROLL_MIN_THUMB;
318 else thumbSize = GetSystemMetrics(SM_CXVSCROLL);
320 if ((pixels -= thumbSize) <= 0) return infoPtr->minVal;
322 pos = max( 0, pos - (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP) );
323 if (pos > pixels) pos = pixels;
325 if (!infoPtr->page) pos *= infoPtr->maxVal - infoPtr->minVal;
326 else pos *= infoPtr->maxVal - infoPtr->minVal - infoPtr->page + 1;
327 return infoPtr->minVal + ((pos + pixels / 2) / pixels);
330 /***********************************************************************
331 * SCROLL_PtInRectEx
333 static BOOL SCROLL_PtInRectEx( LPRECT lpRect, POINT pt, BOOL vertical )
335 RECT rect = *lpRect;
337 if (vertical)
339 rect.left -= lpRect->right - lpRect->left;
340 rect.right += lpRect->right - lpRect->left;
342 else
344 rect.top -= lpRect->bottom - lpRect->top;
345 rect.bottom += lpRect->bottom - lpRect->top;
347 return PtInRect( &rect, pt );
350 /***********************************************************************
351 * SCROLL_ClipPos
353 static POINT SCROLL_ClipPos( LPRECT lpRect, POINT pt )
355 if( pt.x < lpRect->left )
356 pt.x = lpRect->left;
357 else
358 if( pt.x > lpRect->right )
359 pt.x = lpRect->right;
361 if( pt.y < lpRect->top )
362 pt.y = lpRect->top;
363 else
364 if( pt.y > lpRect->bottom )
365 pt.y = lpRect->bottom;
367 return pt;
371 /***********************************************************************
372 * SCROLL_HitTest
374 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
376 static enum SCROLL_HITTEST SCROLL_HitTest( HWND hwnd, INT nBar,
377 POINT pt, BOOL bDragging )
379 INT arrowSize, thumbSize, thumbPos;
380 RECT rect;
382 BOOL vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
383 &arrowSize, &thumbSize, &thumbPos );
385 if ( (bDragging && !SCROLL_PtInRectEx( &rect, pt, vertical )) ||
386 (!PtInRect( &rect, pt )) ) return SCROLL_NOWHERE;
388 if (vertical)
390 if (pt.y < rect.top + arrowSize) return SCROLL_TOP_ARROW;
391 if (pt.y >= rect.bottom - arrowSize) return SCROLL_BOTTOM_ARROW;
392 if (!thumbPos) return SCROLL_TOP_RECT;
393 pt.y -= rect.top;
394 if (pt.y < thumbPos) return SCROLL_TOP_RECT;
395 if (pt.y >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
397 else /* horizontal */
399 if (pt.x < rect.left + arrowSize) return SCROLL_TOP_ARROW;
400 if (pt.x >= rect.right - arrowSize) return SCROLL_BOTTOM_ARROW;
401 if (!thumbPos) return SCROLL_TOP_RECT;
402 pt.x -= rect.left;
403 if (pt.x < thumbPos) return SCROLL_TOP_RECT;
404 if (pt.x >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
406 return SCROLL_THUMB;
410 /***********************************************************************
411 * SCROLL_DrawArrows
413 * Draw the scroll bar arrows.
415 static void SCROLL_DrawArrows( HDC hdc, SCROLLBAR_INFO *infoPtr,
416 RECT *rect, INT arrowSize, BOOL vertical,
417 BOOL top_pressed, BOOL bottom_pressed )
419 RECT r;
421 r = *rect;
422 if( vertical )
423 r.bottom = r.top + arrowSize;
424 else
425 r.right = r.left + arrowSize;
427 DrawFrameControl( hdc, &r, DFC_SCROLL,
428 (vertical ? DFCS_SCROLLUP : DFCS_SCROLLLEFT)
429 | (top_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
430 | (infoPtr->flags&ESB_DISABLE_LTUP ? DFCS_INACTIVE : 0 ) );
432 r = *rect;
433 if( vertical )
434 r.top = r.bottom-arrowSize;
435 else
436 r.left = r.right-arrowSize;
438 DrawFrameControl( hdc, &r, DFC_SCROLL,
439 (vertical ? DFCS_SCROLLDOWN : DFCS_SCROLLRIGHT)
440 | (bottom_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
441 | (infoPtr->flags&ESB_DISABLE_RTDN ? DFCS_INACTIVE : 0) );
444 static void SCROLL_DrawMovingThumb( HDC hdc, RECT *rect, BOOL vertical,
445 INT arrowSize, INT thumbSize )
447 INT pos = SCROLL_TrackingPos;
448 INT max_size;
450 if( vertical )
451 max_size = rect->bottom - rect->top;
452 else
453 max_size = rect->right - rect->left;
455 max_size -= (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) + thumbSize;
457 if( pos < (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) )
458 pos = (arrowSize-SCROLL_ARROW_THUMB_OVERLAP);
459 else if( pos > max_size )
460 pos = max_size;
462 SCROLL_DrawInterior_9x( SCROLL_TrackingWin, hdc, SCROLL_TrackingBar,
463 rect, arrowSize, thumbSize, pos,
464 0, vertical, FALSE, FALSE );
466 SCROLL_MovingThumb = !SCROLL_MovingThumb;
469 /***********************************************************************
470 * SCROLL_DrawInterior
472 * Draw the scroll bar interior (everything except the arrows).
474 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
475 RECT *rect, INT arrowSize,
476 INT thumbSize, INT thumbPos,
477 UINT flags, BOOL vertical,
478 BOOL top_selected, BOOL bottom_selected )
480 RECT r;
481 HPEN hSavePen;
482 HBRUSH hSaveBrush,hBrush;
484 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
485 * The window-owned scrollbars need to call DEFWND_ControlColor
486 * to correctly setup default scrollbar colors
488 if (nBar == SB_CTL)
490 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
491 (WPARAM)hdc,(LPARAM)hwnd);
493 else
495 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
498 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
499 hSaveBrush = SelectObject( hdc, hBrush );
501 /* Calculate the scroll rectangle */
502 r = *rect;
503 if (vertical)
505 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
506 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
508 else
510 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
511 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
514 /* Draw the scroll rectangles and thumb */
515 if (!thumbPos) /* No thumb to draw */
517 PatBlt( hdc, r.left, r.top,
518 r.right - r.left, r.bottom - r.top,
519 PATCOPY );
521 /* cleanup and return */
522 SelectObject( hdc, hSavePen );
523 SelectObject( hdc, hSaveBrush );
524 return;
527 if (vertical)
529 PatBlt( hdc, r.left, r.top,
530 r.right - r.left,
531 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
532 top_selected ? 0x0f0000 : PATCOPY );
533 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
534 PatBlt( hdc, r.left, r.top + thumbSize,
535 r.right - r.left,
536 r.bottom - r.top - thumbSize,
537 bottom_selected ? 0x0f0000 : PATCOPY );
538 r.bottom = r.top + thumbSize;
540 else /* horizontal */
542 PatBlt( hdc, r.left, r.top,
543 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
544 r.bottom - r.top,
545 top_selected ? 0x0f0000 : PATCOPY );
546 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
547 PatBlt( hdc, r.left + thumbSize, r.top,
548 r.right - r.left - thumbSize,
549 r.bottom - r.top,
550 bottom_selected ? 0x0f0000 : PATCOPY );
551 r.right = r.left + thumbSize;
554 /* Draw the thumb */
555 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT | BF_MIDDLE );
557 /* cleanup */
558 SelectObject( hdc, hSavePen );
559 SelectObject( hdc, hSaveBrush );
563 static void SCROLL_DrawInterior( HWND hwnd, HDC hdc, INT nBar,
564 RECT *rect, INT arrowSize,
565 INT thumbSize, INT thumbPos,
566 UINT flags, BOOL vertical,
567 BOOL top_selected, BOOL bottom_selected )
569 RECT r;
570 HPEN hSavePen;
571 HBRUSH hSaveBrush,hBrush;
572 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
574 if (Save_SCROLL_MovingThumb &&
575 (SCROLL_TrackingWin == hwnd) &&
576 (SCROLL_TrackingBar == nBar))
577 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
579 /* Select the correct brush and pen */
581 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
582 * The window-owned scrollbars need to call DEFWND_ControlColor
583 * to correctly setup default scrollbar colors
585 if (nBar == SB_CTL) {
586 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
587 (WPARAM)hdc,(LPARAM)hwnd);
588 } else {
589 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
591 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
592 hSaveBrush = SelectObject( hdc, hBrush );
594 /* Calculate the scroll rectangle */
596 r = *rect;
597 if (vertical)
599 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
600 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
602 else
604 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
605 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
608 /* Draw the scroll bar frame */
610 /* Draw the scroll rectangles and thumb */
612 if (!thumbPos) /* No thumb to draw */
614 PatBlt( hdc, r.left, r.top, r.right - r.left, r.bottom - r.top, PATCOPY );
616 /* cleanup and return */
617 SelectObject( hdc, hSavePen );
618 SelectObject( hdc, hSaveBrush );
619 return;
622 if (vertical)
624 PatBlt( hdc, r.left, r.top, r.right - r.left,
625 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
626 top_selected ? 0x0f0000 : PATCOPY );
627 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
628 PatBlt( hdc, r.left, r.top + thumbSize, r.right - r.left,
629 r.bottom - r.top - thumbSize,
630 bottom_selected ? 0x0f0000 : PATCOPY );
631 r.bottom = r.top + thumbSize;
633 else /* horizontal */
635 PatBlt( hdc, r.left, r.top,
636 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
637 r.bottom - r.top, top_selected ? 0x0f0000 : PATCOPY );
638 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
639 PatBlt( hdc, r.left + thumbSize, r.top, r.right - r.left - thumbSize,
640 r.bottom - r.top, bottom_selected ? 0x0f0000 : PATCOPY );
641 r.right = r.left + thumbSize;
644 /* Draw the thumb */
646 SelectObject( hdc, GetSysColorBrush(COLOR_BTNFACE) );
647 Rectangle( hdc, r.left+1, r.top+1, r.right-1, r.bottom-1 );
648 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT );
650 if (Save_SCROLL_MovingThumb &&
651 (SCROLL_TrackingWin == hwnd) &&
652 (SCROLL_TrackingBar == nBar))
653 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
655 /* cleanup */
656 SelectObject( hdc, hSavePen );
657 SelectObject( hdc, hSaveBrush );
661 /***********************************************************************
662 * SCROLL_DrawScrollBar
664 * Redraw the whole scrollbar.
666 void SCROLL_DrawScrollBar( HWND hwnd, HDC hdc, INT nBar,
667 BOOL arrows, BOOL interior )
669 INT arrowSize, thumbSize, thumbPos;
670 RECT rect;
671 BOOL vertical;
672 SCROLLBAR_INFO *infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, TRUE );
673 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
674 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
676 if (!(hwnd = WIN_GetFullHandle( hwnd ))) return;
678 if (!infoPtr ||
679 ((nBar == SB_VERT) && !(style & WS_VSCROLL)) ||
680 ((nBar == SB_HORZ) && !(style & WS_HSCROLL))) return;
681 if (!WIN_IsWindowDrawable( hwnd, FALSE )) return;
683 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
684 &arrowSize, &thumbSize, &thumbPos );
686 /* do not draw if the scrollbar rectangle is empty */
687 if(IsRectEmpty(&rect)) return;
689 if (Save_SCROLL_MovingThumb &&
690 (SCROLL_TrackingWin == hwnd) &&
691 (SCROLL_TrackingBar == nBar))
692 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
694 /* Draw the arrows */
696 if (arrows && arrowSize)
698 if( vertical == SCROLL_trackVertical && GetCapture() == hwnd )
699 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
700 (SCROLL_trackHitTest == SCROLL_TOP_ARROW),
701 (SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW) );
702 else
703 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
704 FALSE, FALSE );
706 if( interior )
707 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
708 thumbPos, infoPtr->flags, vertical, FALSE, FALSE );
710 if (Save_SCROLL_MovingThumb &&
711 (SCROLL_TrackingWin == hwnd) &&
712 (SCROLL_TrackingBar == nBar))
713 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
715 /* if scroll bar has focus, reposition the caret */
716 if(hwnd==GetFocus() && (nBar==SB_CTL))
718 if (!vertical)
720 SetCaretPos(thumbPos+1, rect.top+1);
722 else
724 SetCaretPos(rect.top+1, thumbPos+1);
729 /***********************************************************************
730 * SCROLL_DrawSizeGrip
732 * Draw the size grip.
734 static void SCROLL_DrawSizeGrip( HWND hwnd, HDC hdc)
736 RECT rc;
738 GetClientRect( hwnd, &rc );
739 FillRect( hdc, &rc, GetSysColorBrush(COLOR_SCROLLBAR) );
740 rc.left = max( rc.left, rc.right - GetSystemMetrics(SM_CXVSCROLL) - 1 );
741 rc.top = max( rc.top, rc.bottom - GetSystemMetrics(SM_CYHSCROLL) - 1 );
742 DrawFrameControl( hdc, &rc, DFC_SCROLL, DFCS_SCROLLSIZEGRIP );
746 /***********************************************************************
747 * SCROLL_RefreshScrollBar
749 * Repaint the scroll bar interior after a SetScrollRange() or
750 * SetScrollPos() call.
752 static void SCROLL_RefreshScrollBar( HWND hwnd, INT nBar,
753 BOOL arrows, BOOL interior )
755 HDC hdc = GetDCEx( hwnd, 0,
756 DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW) );
757 if (!hdc) return;
759 SCROLL_DrawScrollBar( hwnd, hdc, nBar, arrows, interior );
760 ReleaseDC( hwnd, hdc );
764 /***********************************************************************
765 * SCROLL_HandleKbdEvent
767 * Handle a keyboard event (only for SB_CTL scrollbars with focus).
769 * PARAMS
770 * hwnd [I] Handle of window with scrollbar(s)
771 * wParam [I] Variable input including enable state
772 * lParam [I] Variable input including input point
774 static void SCROLL_HandleKbdEvent(HWND hwnd, WPARAM wParam, LPARAM lParam)
776 TRACE("hwnd=%p wParam=%ld lParam=%ld\n", hwnd, wParam, lParam);
778 /* hide caret on first KEYDOWN to prevent flicker */
779 if ((lParam & PFD_DOUBLEBUFFER_DONTCARE) == 0)
780 HideCaret(hwnd);
782 switch(wParam)
784 case VK_PRIOR: wParam = SB_PAGEUP; break;
785 case VK_NEXT: wParam = SB_PAGEDOWN; break;
786 case VK_HOME: wParam = SB_TOP; break;
787 case VK_END: wParam = SB_BOTTOM; break;
788 case VK_UP: wParam = SB_LINEUP; break;
789 case VK_DOWN: wParam = SB_LINEDOWN; break;
790 case VK_LEFT: wParam = SB_LINEUP; break;
791 case VK_RIGHT: wParam = SB_LINEDOWN; break;
792 default: return;
794 SendMessageW(GetParent(hwnd),
795 ((GetWindowLongW( hwnd, GWL_STYLE ) & SBS_VERT) ?
796 WM_VSCROLL : WM_HSCROLL), wParam, (LPARAM)hwnd);
800 /***********************************************************************
801 * SCROLL_HandleScrollEvent
803 * Handle a mouse or timer event for the scrollbar.
804 * 'pt' is the location of the mouse event in client (for SB_CTL) or
805 * windows coordinates.
807 static void SCROLL_HandleScrollEvent( HWND hwnd, INT nBar, UINT msg, POINT pt)
809 /* Previous mouse position for timer events */
810 static POINT prevPt;
811 /* Thumb position when tracking started. */
812 static UINT trackThumbPos;
813 /* Position in the scroll-bar of the last button-down event. */
814 static INT lastClickPos;
815 /* Position in the scroll-bar of the last mouse event. */
816 static INT lastMousePos;
818 enum SCROLL_HITTEST hittest;
819 HWND hwndOwner, hwndCtl;
820 BOOL vertical;
821 INT arrowSize, thumbSize, thumbPos;
822 RECT rect;
823 HDC hdc;
825 SCROLLBAR_INFO *infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, FALSE );
826 if (!infoPtr) return;
827 if ((SCROLL_trackHitTest == SCROLL_NOWHERE) && (msg != WM_LBUTTONDOWN))
828 return;
830 if (nBar == SB_CTL && (GetWindowLongW( hwnd, GWL_STYLE ) & (SBS_SIZEGRIP | SBS_SIZEBOX)))
832 switch(msg)
834 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
835 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
836 SetCapture( hwnd );
837 prevPt = pt;
838 SCROLL_trackHitTest = hittest = SCROLL_THUMB;
839 break;
840 case WM_MOUSEMOVE:
841 GetClientRect(GetParent(GetParent(hwnd)),&rect);
842 prevPt = pt;
843 break;
844 case WM_LBUTTONUP:
845 ReleaseCapture();
846 SCROLL_trackHitTest = hittest = SCROLL_NOWHERE;
847 if (hwnd==GetFocus()) ShowCaret(hwnd);
848 break;
849 case WM_SYSTIMER:
850 pt = prevPt;
851 break;
853 return;
856 hdc = GetDCEx( hwnd, 0, DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW));
857 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
858 &arrowSize, &thumbSize, &thumbPos );
859 hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd) : hwnd;
860 hwndCtl = (nBar == SB_CTL) ? hwnd : 0;
862 switch(msg)
864 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
865 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
866 SCROLL_trackVertical = vertical;
867 SCROLL_trackHitTest = hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
868 lastClickPos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
869 lastMousePos = lastClickPos;
870 trackThumbPos = thumbPos;
871 prevPt = pt;
872 if (nBar == SB_CTL && (GetWindowLongW(hwnd, GWL_STYLE) & WS_TABSTOP)) SetFocus( hwnd );
873 SetCapture( hwnd );
874 break;
876 case WM_MOUSEMOVE:
877 hittest = SCROLL_HitTest( hwnd, nBar, pt, TRUE );
878 prevPt = pt;
879 break;
881 case WM_LBUTTONUP:
882 hittest = SCROLL_NOWHERE;
883 ReleaseCapture();
884 /* if scrollbar has focus, show back caret */
885 if (hwnd==GetFocus()) ShowCaret(hwnd);
886 break;
888 case WM_SYSTIMER:
889 pt = prevPt;
890 hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
891 break;
893 default:
894 return; /* Should never happen */
897 TRACE("Event: hwnd=%p bar=%d msg=%s pt=%d,%d hit=%d\n",
898 hwnd, nBar, SPY_GetMsgName(msg,hwnd), pt.x, pt.y, hittest );
900 switch(SCROLL_trackHitTest)
902 case SCROLL_NOWHERE: /* No tracking in progress */
903 break;
905 case SCROLL_TOP_ARROW:
906 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
907 (hittest == SCROLL_trackHitTest), FALSE );
908 if (hittest == SCROLL_trackHitTest)
910 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
912 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
913 SB_LINEUP, (LPARAM)hwndCtl );
916 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
917 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
918 (TIMERPROC)0 );
920 else KillSystemTimer( hwnd, SCROLL_TIMER );
921 break;
923 case SCROLL_TOP_RECT:
924 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
925 thumbPos, infoPtr->flags, vertical,
926 (hittest == SCROLL_trackHitTest), FALSE );
927 if (hittest == SCROLL_trackHitTest)
929 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
931 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
932 SB_PAGEUP, (LPARAM)hwndCtl );
934 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
935 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
936 (TIMERPROC)0 );
938 else KillSystemTimer( hwnd, SCROLL_TIMER );
939 break;
941 case SCROLL_THUMB:
942 if (msg == WM_LBUTTONDOWN)
944 SCROLL_TrackingWin = hwnd;
945 SCROLL_TrackingBar = nBar;
946 SCROLL_TrackingPos = trackThumbPos + lastMousePos - lastClickPos;
947 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
948 vertical,
949 SCROLL_TrackingPos );
950 if (!SCROLL_MovingThumb)
951 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
953 else if (msg == WM_LBUTTONUP)
955 if (SCROLL_MovingThumb)
956 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
958 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
959 thumbPos, infoPtr->flags, vertical,
960 FALSE, FALSE );
962 else /* WM_MOUSEMOVE */
964 INT pos;
966 if (!SCROLL_PtInRectEx( &rect, pt, vertical )) pos = lastClickPos;
967 else
969 pt = SCROLL_ClipPos( &rect, pt );
970 pos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
972 if ( (pos != lastMousePos) || (!SCROLL_MovingThumb) )
974 if (SCROLL_MovingThumb)
975 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
976 arrowSize, thumbSize );
977 lastMousePos = pos;
978 SCROLL_TrackingPos = trackThumbPos + pos - lastClickPos;
979 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
980 vertical,
981 SCROLL_TrackingPos );
982 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
983 MAKEWPARAM( SB_THUMBTRACK, SCROLL_TrackingVal),
984 (LPARAM)hwndCtl );
985 if (!SCROLL_MovingThumb)
986 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
987 arrowSize, thumbSize );
990 break;
992 case SCROLL_BOTTOM_RECT:
993 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
994 thumbPos, infoPtr->flags, vertical,
995 FALSE, (hittest == SCROLL_trackHitTest) );
996 if (hittest == SCROLL_trackHitTest)
998 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1000 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1001 SB_PAGEDOWN, (LPARAM)hwndCtl );
1003 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1004 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1005 (TIMERPROC)0 );
1007 else KillSystemTimer( hwnd, SCROLL_TIMER );
1008 break;
1010 case SCROLL_BOTTOM_ARROW:
1011 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
1012 FALSE, (hittest == SCROLL_trackHitTest) );
1013 if (hittest == SCROLL_trackHitTest)
1015 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1017 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1018 SB_LINEDOWN, (LPARAM)hwndCtl );
1021 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1022 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1023 (TIMERPROC)0 );
1025 else KillSystemTimer( hwnd, SCROLL_TIMER );
1026 break;
1029 if (msg == WM_LBUTTONDOWN)
1032 if (hittest == SCROLL_THUMB)
1034 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1035 trackThumbPos + lastMousePos - lastClickPos );
1036 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1037 MAKEWPARAM( SB_THUMBTRACK, val ), (LPARAM)hwndCtl );
1041 if (msg == WM_LBUTTONUP)
1043 hittest = SCROLL_trackHitTest;
1044 SCROLL_trackHitTest = SCROLL_NOWHERE; /* Terminate tracking */
1046 if (hittest == SCROLL_THUMB)
1048 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1049 trackThumbPos + lastMousePos - lastClickPos );
1050 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1051 MAKEWPARAM( SB_THUMBPOSITION, val ), (LPARAM)hwndCtl );
1053 /* SB_ENDSCROLL doesn't report thumb position */
1054 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1055 SB_ENDSCROLL, (LPARAM)hwndCtl );
1057 /* Terminate tracking */
1058 SCROLL_TrackingWin = 0;
1061 ReleaseDC( hwnd, hdc );
1065 /***********************************************************************
1066 * SCROLL_TrackScrollBar
1068 * Track a mouse button press on a scroll-bar.
1069 * pt is in screen-coordinates for non-client scroll bars.
1071 void SCROLL_TrackScrollBar( HWND hwnd, INT scrollbar, POINT pt )
1073 MSG msg;
1074 INT xoffset = 0, yoffset = 0;
1076 if (scrollbar != SB_CTL)
1078 WND *wndPtr = WIN_GetPtr( hwnd );
1079 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return;
1080 xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
1081 yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
1082 WIN_ReleasePtr( wndPtr );
1083 ScreenToClient( hwnd, &pt );
1084 pt.x += xoffset;
1085 pt.y += yoffset;
1088 SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt );
1092 if (!GetMessageW( &msg, 0, 0, 0 )) break;
1093 if (CallMsgFilterW( &msg, MSGF_SCROLLBAR )) continue;
1094 if (msg.message == WM_LBUTTONUP ||
1095 msg.message == WM_MOUSEMOVE ||
1096 (msg.message == WM_SYSTIMER && msg.wParam == SCROLL_TIMER))
1098 pt.x = (short)LOWORD(msg.lParam) + xoffset;
1099 pt.y = (short)HIWORD(msg.lParam) + yoffset;
1100 SCROLL_HandleScrollEvent( hwnd, scrollbar, msg.message, pt );
1102 else
1104 TranslateMessage( &msg );
1105 DispatchMessageW( &msg );
1107 if (!IsWindow( hwnd ))
1109 ReleaseCapture();
1110 break;
1112 } while (msg.message != WM_LBUTTONUP);
1116 /***********************************************************************
1117 * SCROLL_CreateScrollBar
1119 * Create a scroll bar
1121 * PARAMS
1122 * hwnd [I] Handle of window with scrollbar(s)
1123 * lpCreate [I] The style and place of the scroll bar
1125 static void SCROLL_CreateScrollBar(HWND hwnd, LPCREATESTRUCTW lpCreate)
1127 LPSCROLLBAR_INFO info = SCROLL_GetInternalInfo(hwnd, SB_CTL, TRUE);
1128 if (!info) return;
1130 TRACE("hwnd=%p lpCreate=%p\n", hwnd, lpCreate);
1132 if (lpCreate->style & WS_DISABLED)
1134 info->flags = ESB_DISABLE_BOTH;
1135 TRACE("Created WS_DISABLED scrollbar\n");
1139 if (lpCreate->style & (SBS_SIZEGRIP | SBS_SIZEBOX))
1141 if (lpCreate->style & SBS_SIZEBOXTOPLEFTALIGN)
1142 MoveWindow( hwnd, lpCreate->x, lpCreate->y, GetSystemMetrics(SM_CXVSCROLL)+1,
1143 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1144 else if(lpCreate->style & SBS_SIZEBOXBOTTOMRIGHTALIGN)
1145 MoveWindow( hwnd, lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1146 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1147 GetSystemMetrics(SM_CXVSCROLL)+1,
1148 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1150 else if (lpCreate->style & SBS_VERT)
1152 if (lpCreate->style & SBS_LEFTALIGN)
1153 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1154 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1155 else if (lpCreate->style & SBS_RIGHTALIGN)
1156 MoveWindow( hwnd,
1157 lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1158 lpCreate->y,
1159 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1161 else /* SBS_HORZ */
1163 if (lpCreate->style & SBS_TOPALIGN)
1164 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1165 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1166 else if (lpCreate->style & SBS_BOTTOMALIGN)
1167 MoveWindow( hwnd,
1168 lpCreate->x,
1169 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1170 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1175 /*************************************************************************
1176 * SCROLL_GetScrollInfo
1178 * Internal helper for the API function
1180 * PARAMS
1181 * hwnd [I] Handle of window with scrollbar(s)
1182 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1183 * info [IO] fMask specifies which values to retrieve
1185 * RETURNS
1186 * FALSE if requested field not filled (f.i. scroll bar does not exist)
1188 static BOOL SCROLL_GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1190 LPSCROLLBAR_INFO infoPtr;
1192 /* handle invalid data structure */
1193 if (!SCROLL_ScrollInfoValid(info)
1194 || !(infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE)))
1195 return FALSE;
1197 /* fill in the desired scroll info structure */
1198 if (info->fMask & SIF_PAGE) info->nPage = infoPtr->page;
1199 if (info->fMask & SIF_POS) info->nPos = infoPtr->curVal;
1200 if ((info->fMask & SIF_TRACKPOS) && (info->cbSize == sizeof(*info)))
1201 info->nTrackPos = (SCROLL_TrackingWin == WIN_GetFullHandle(hwnd)) ? SCROLL_TrackingVal : infoPtr->curVal;
1202 if (info->fMask & SIF_RANGE)
1204 info->nMin = infoPtr->minVal;
1205 info->nMax = infoPtr->maxVal;
1208 TRACE("cbSize %02x fMask %04x nMin %d nMax %d nPage %u nPos %d nTrackPos %d\n",
1209 info->cbSize, info->fMask, info->nMin, info->nMax, info->nPage,
1210 info->nPos, info->nTrackPos);
1212 return (info->fMask & SIF_ALL) != 0;
1216 /*************************************************************************
1217 * SCROLL_GetScrollBarInfo
1219 * Internal helper for the API function
1221 * PARAMS
1222 * hwnd [I] Handle of window with scrollbar(s)
1223 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1224 * info [IO] cbSize specifies the size of the structure
1226 * RETURNS
1227 * FALSE if failed
1229 static BOOL SCROLL_GetScrollBarInfo(HWND hwnd, LONG idObject, LPSCROLLBARINFO info)
1231 LPSCROLLBAR_INFO infoPtr;
1232 INT nBar;
1233 INT nDummy;
1234 DWORD style = GetWindowLongW(hwnd, GWL_STYLE);
1235 BOOL pressed;
1237 switch (idObject)
1239 case OBJID_CLIENT: nBar = SB_CTL; break;
1240 case OBJID_HSCROLL: nBar = SB_HORZ; break;
1241 case OBJID_VSCROLL: nBar = SB_VERT; break;
1242 default: return FALSE;
1245 /* handle invalid data structure */
1246 if (info->cbSize != sizeof(*info))
1247 return FALSE;
1249 SCROLL_GetScrollBarRect(hwnd, nBar, &info->rcScrollBar, &nDummy,
1250 &info->dxyLineButton, &info->xyThumbTop);
1252 info->xyThumbBottom = info->xyThumbTop + info->dxyLineButton;
1254 infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, TRUE);
1256 /* Scroll bar state */
1257 info->rgstate[0] = 0;
1258 if ((nBar == SB_HORZ && !(style & WS_HSCROLL))
1259 || (nBar == SB_VERT && !(style & WS_VSCROLL)))
1260 info->rgstate[0] |= STATE_SYSTEM_INVISIBLE;
1261 if (infoPtr->minVal >= infoPtr->maxVal - max(infoPtr->page - 1, 0))
1263 if (!(info->rgstate[0] & STATE_SYSTEM_INVISIBLE))
1264 info->rgstate[0] |= STATE_SYSTEM_UNAVAILABLE;
1265 else
1266 info->rgstate[0] |= STATE_SYSTEM_OFFSCREEN;
1268 if (nBar == SB_CTL && !IsWindowEnabled(hwnd))
1269 info->rgstate[0] |= STATE_SYSTEM_UNAVAILABLE;
1271 pressed = ((nBar == SB_VERT) == SCROLL_trackVertical && GetCapture() == hwnd);
1273 /* Top/left arrow button state. MSDN says top/right, but I don't believe it */
1274 info->rgstate[1] = 0;
1275 if (pressed && SCROLL_trackHitTest == SCROLL_TOP_ARROW)
1276 info->rgstate[1] |= STATE_SYSTEM_PRESSED;
1277 if (infoPtr->flags & ESB_DISABLE_LTUP)
1278 info->rgstate[1] |= STATE_SYSTEM_UNAVAILABLE;
1280 /* Page up/left region state. MSDN says up/right, but I don't believe it */
1281 info->rgstate[2] = 0;
1282 if (infoPtr->curVal == infoPtr->minVal)
1283 info->rgstate[2] |= STATE_SYSTEM_INVISIBLE;
1284 if (pressed && SCROLL_trackHitTest == SCROLL_TOP_RECT)
1285 info->rgstate[2] |= STATE_SYSTEM_PRESSED;
1287 /* Thumb state */
1288 info->rgstate[3] = 0;
1289 if (pressed && SCROLL_trackHitTest == SCROLL_THUMB)
1290 info->rgstate[3] |= STATE_SYSTEM_PRESSED;
1292 /* Page down/right region state. MSDN says down/left, but I don't believe it */
1293 info->rgstate[4] = 0;
1294 if (infoPtr->curVal >= infoPtr->maxVal - 1)
1295 info->rgstate[4] |= STATE_SYSTEM_INVISIBLE;
1296 if (pressed && SCROLL_trackHitTest == SCROLL_BOTTOM_RECT)
1297 info->rgstate[4] |= STATE_SYSTEM_PRESSED;
1299 /* Bottom/right arrow button state. MSDN says bottom/left, but I don't believe it */
1300 info->rgstate[5] = 0;
1301 if (pressed && SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW)
1302 info->rgstate[5] |= STATE_SYSTEM_PRESSED;
1303 if (infoPtr->flags & ESB_DISABLE_RTDN)
1304 info->rgstate[5] |= STATE_SYSTEM_UNAVAILABLE;
1306 return TRUE;
1310 /*************************************************************************
1311 * SCROLL_GetScrollPos
1313 * Internal helper for the API function
1315 * PARAMS
1316 * hwnd [I] Handle of window with scrollbar(s)
1317 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1319 static INT SCROLL_GetScrollPos(HWND hwnd, INT nBar)
1321 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1322 return infoPtr ? infoPtr->curVal: 0;
1326 /*************************************************************************
1327 * SCROLL_GetScrollRange
1329 * Internal helper for the API function
1331 * PARAMS
1332 * hwnd [I] Handle of window with scrollbar(s)
1333 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1334 * lpMin [O] Where to store minimum value
1335 * lpMax [O] Where to store maximum value
1337 * RETURNS
1338 * Success: TRUE
1339 * Failure: FALSE
1341 static BOOL SCROLL_GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1343 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1345 if (lpMin) *lpMin = infoPtr ? infoPtr->minVal : 0;
1346 if (lpMax) *lpMax = infoPtr ? infoPtr->maxVal : 0;
1348 return TRUE;
1352 /*************************************************************************
1353 * SCROLL_SetScrollRange
1355 * PARAMS
1356 * hwnd [I] Handle of window with scrollbar(s)
1357 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1358 * lpMin [I] Minimum value
1359 * lpMax [I] Maximum value
1362 static BOOL SCROLL_SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal)
1364 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1366 TRACE("hwnd=%p nBar=%d min=%d max=%d\n", hwnd, nBar, minVal, maxVal);
1368 if (infoPtr)
1370 infoPtr->minVal = minVal;
1371 infoPtr->maxVal = maxVal;
1373 return TRUE;
1377 /***********************************************************************
1378 * ScrollBarWndProc
1380 static LRESULT WINAPI ScrollBarWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1382 if (!IsWindow( hwnd )) return 0;
1384 switch(message)
1386 case WM_CREATE:
1387 SCROLL_CreateScrollBar(hwnd, (LPCREATESTRUCTW)lParam);
1388 break;
1390 case WM_ENABLE:
1392 SCROLLBAR_INFO *infoPtr;
1393 if ((infoPtr = SCROLL_GetInternalInfo( hwnd, SB_CTL, FALSE )))
1395 infoPtr->flags = wParam ? ESB_ENABLE_BOTH : ESB_DISABLE_BOTH;
1396 SCROLL_RefreshScrollBar(hwnd, SB_CTL, TRUE, TRUE);
1399 return 0;
1401 case WM_LBUTTONDBLCLK:
1402 case WM_LBUTTONDOWN:
1404 POINT pt;
1405 pt.x = (short)LOWORD(lParam);
1406 pt.y = (short)HIWORD(lParam);
1407 SCROLL_TrackScrollBar( hwnd, SB_CTL, pt );
1409 break;
1410 case WM_LBUTTONUP:
1411 case WM_MOUSEMOVE:
1412 case WM_SYSTIMER:
1414 POINT pt;
1415 pt.x = (short)LOWORD(lParam);
1416 pt.y = (short)HIWORD(lParam);
1417 SCROLL_HandleScrollEvent( hwnd, SB_CTL, message, pt );
1419 break;
1421 case WM_KEYDOWN:
1422 SCROLL_HandleKbdEvent(hwnd, wParam, lParam);
1423 break;
1425 case WM_KEYUP:
1426 ShowCaret(hwnd);
1427 break;
1429 case WM_SETFOCUS:
1431 /* Create a caret when a ScrollBar get focus */
1432 RECT rect;
1433 int arrowSize, thumbSize, thumbPos, vertical;
1434 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,
1435 &arrowSize, &thumbSize, &thumbPos );
1436 if (!vertical)
1438 CreateCaret(hwnd, (HBITMAP)1, thumbSize-2, rect.bottom-rect.top-2);
1439 SetCaretPos(thumbPos+1, rect.top+1);
1441 else
1443 CreateCaret(hwnd, (HBITMAP)1, rect.right-rect.left-2,thumbSize-2);
1444 SetCaretPos(rect.top+1, thumbPos+1);
1446 ShowCaret(hwnd);
1448 break;
1450 case WM_KILLFOCUS:
1452 RECT rect;
1453 int arrowSize, thumbSize, thumbPos, vertical;
1454 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,&arrowSize, &thumbSize, &thumbPos );
1455 if (!vertical){
1456 rect.left=thumbPos+1;
1457 rect.right=rect.left+thumbSize;
1459 else
1461 rect.top=thumbPos+1;
1462 rect.bottom=rect.top+thumbSize;
1464 HideCaret(hwnd);
1465 InvalidateRect(hwnd,&rect,0);
1466 DestroyCaret();
1468 break;
1470 case WM_ERASEBKGND:
1471 return 1;
1473 case WM_GETDLGCODE:
1474 return DLGC_WANTARROWS; /* Windows returns this value */
1476 case WM_PAINT:
1478 PAINTSTRUCT ps;
1479 HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
1480 if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEGRIP)
1482 SCROLL_DrawSizeGrip( hwnd, hdc);
1484 else if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEBOX)
1486 RECT rc;
1487 GetClientRect( hwnd, &rc );
1488 FillRect( hdc, &rc, GetSysColorBrush(COLOR_SCROLLBAR) );
1490 else
1491 SCROLL_DrawScrollBar( hwnd, hdc, SB_CTL, TRUE, TRUE );
1492 if (!wParam) EndPaint(hwnd, &ps);
1494 break;
1496 case SBM_SETPOS16:
1497 case SBM_SETPOS:
1498 return SetScrollPos( hwnd, SB_CTL, wParam, (BOOL)lParam );
1500 case SBM_GETPOS16:
1501 case SBM_GETPOS:
1502 return SCROLL_GetScrollPos(hwnd, SB_CTL);
1504 case SBM_SETRANGE16:
1505 if (wParam) message = SBM_SETRANGEREDRAW;
1506 wParam = LOWORD(lParam);
1507 lParam = HIWORD(lParam);
1508 /* fall through */
1509 case SBM_SETRANGEREDRAW:
1510 case SBM_SETRANGE:
1512 INT oldPos = SCROLL_GetScrollPos( hwnd, SB_CTL );
1513 SCROLL_SetScrollRange( hwnd, SB_CTL, wParam, lParam );
1514 if (message == SBM_SETRANGEREDRAW)
1515 SCROLL_RefreshScrollBar( hwnd, SB_CTL, TRUE, TRUE );
1516 if (oldPos != SCROLL_GetScrollPos( hwnd, SB_CTL )) return oldPos;
1518 return 0;
1520 case SBM_GETRANGE16:
1522 INT min, max;
1524 SCROLL_GetScrollRange(hwnd, SB_CTL, &min, &max);
1525 return MAKELRESULT(min, max);
1528 case SBM_GETRANGE:
1529 return SCROLL_GetScrollRange(hwnd, SB_CTL, (LPINT)wParam, (LPINT)lParam);
1531 case SBM_ENABLE_ARROWS16:
1532 case SBM_ENABLE_ARROWS:
1533 return EnableScrollBar( hwnd, SB_CTL, wParam );
1535 case SBM_SETSCROLLINFO:
1536 return SCROLL_SetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam, wParam );
1538 case SBM_GETSCROLLINFO:
1539 return SCROLL_GetScrollInfo(hwnd, SB_CTL, (SCROLLINFO *)lParam);
1541 case SBM_GETSCROLLBARINFO:
1542 return SCROLL_GetScrollBarInfo(hwnd, OBJID_CLIENT, (SCROLLBARINFO *)lParam);
1544 case 0x00e5:
1545 case 0x00e7:
1546 case 0x00e8:
1547 case 0x00ec:
1548 case 0x00ed:
1549 case 0x00ee:
1550 case 0x00ef:
1551 ERR("unknown Win32 msg %04x wp=%08lx lp=%08lx\n",
1552 message, wParam, lParam );
1553 break;
1555 default:
1556 if (message >= WM_USER)
1557 WARN("unknown msg %04x wp=%04lx lp=%08lx\n",
1558 message, wParam, lParam );
1559 return DefWindowProcW( hwnd, message, wParam, lParam );
1561 return 0;
1565 /*************************************************************************
1566 * SetScrollInfo (USER32.@)
1568 * SetScrollInfo can be used to set the position, upper bound,
1569 * lower bound, and page size of a scrollbar control.
1571 * PARAMS
1572 * hwnd [I] Handle of window with scrollbar(s)
1573 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1574 * info [I] Specifies what to change and new values
1575 * bRedraw [I] Should scrollbar be redrawn afterwards?
1577 * RETURNS
1578 * Scrollbar position
1580 * NOTE
1581 * For 100 lines of text to be displayed in a window of 25 lines,
1582 * one would for instance use info->nMin=0, info->nMax=75
1583 * (corresponding to the 76 different positions of the window on
1584 * the text), and info->nPage=25.
1586 INT WINAPI SetScrollInfo(HWND hwnd, INT nBar, const SCROLLINFO *info, BOOL bRedraw)
1588 TRACE("hwnd=%p nBar=%d info=%p, bRedraw=%d\n", hwnd, nBar, info, bRedraw);
1590 /* Refer SB_CTL requests to the window */
1591 if (nBar == SB_CTL)
1592 return SendMessageW(hwnd, SBM_SETSCROLLINFO, bRedraw, (LPARAM)info);
1593 else
1594 return SCROLL_SetScrollInfo( hwnd, nBar, info, bRedraw );
1597 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar, LPCSCROLLINFO info, BOOL bRedraw )
1599 /* Update the scrollbar state and set action flags according to
1600 * what has to be done graphics wise. */
1602 SCROLLBAR_INFO *infoPtr;
1603 UINT new_flags;
1604 INT action = 0;
1606 /* handle invalid data structure */
1607 if (!SCROLL_ScrollInfoValid(info)
1608 || !(infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, TRUE)))
1609 return 0;
1611 if (TRACE_ON(scroll))
1613 TRACE("hwnd=%p bar=%d", hwnd, nBar);
1614 if (info->fMask & SIF_PAGE) TRACE( " page=%d", info->nPage );
1615 if (info->fMask & SIF_POS) TRACE( " pos=%d", info->nPos );
1616 if (info->fMask & SIF_RANGE) TRACE( " min=%d max=%d", info->nMin, info->nMax );
1617 TRACE("\n");
1620 /* Set the page size */
1622 if (info->fMask & SIF_PAGE)
1624 if( infoPtr->page != info->nPage )
1626 infoPtr->page = info->nPage;
1627 action |= SA_SSI_REFRESH;
1631 /* Set the scroll pos */
1633 if (info->fMask & SIF_POS)
1635 if( infoPtr->curVal != info->nPos )
1637 infoPtr->curVal = info->nPos;
1638 action |= SA_SSI_REFRESH;
1642 /* Set the scroll range */
1644 if (info->fMask & SIF_RANGE)
1646 /* Invalid range -> range is set to (0,0) */
1647 if ((info->nMin > info->nMax) ||
1648 ((UINT)(info->nMax - info->nMin) >= 0x80000000))
1650 action |= SA_SSI_REFRESH;
1651 infoPtr->minVal = 0;
1652 infoPtr->maxVal = 0;
1654 else
1656 if( infoPtr->minVal != info->nMin ||
1657 infoPtr->maxVal != info->nMax )
1659 action |= SA_SSI_REFRESH;
1660 infoPtr->minVal = info->nMin;
1661 infoPtr->maxVal = info->nMax;
1666 /* Make sure the page size is valid */
1667 if (infoPtr->page < 0) infoPtr->page = 0;
1668 else if (infoPtr->page > infoPtr->maxVal - infoPtr->minVal + 1 )
1669 infoPtr->page = infoPtr->maxVal - infoPtr->minVal + 1;
1671 /* Make sure the pos is inside the range */
1673 if (infoPtr->curVal < infoPtr->minVal)
1674 infoPtr->curVal = infoPtr->minVal;
1675 else if (infoPtr->curVal > infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1676 infoPtr->curVal = infoPtr->maxVal - max( infoPtr->page-1, 0 );
1678 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1679 infoPtr->page, infoPtr->curVal,
1680 infoPtr->minVal, infoPtr->maxVal );
1682 /* don't change the scrollbar state if SetScrollInfo
1683 * is just called with SIF_DISABLENOSCROLL
1685 if(!(info->fMask & SIF_ALL)) goto done;
1687 /* Check if the scrollbar should be hidden or disabled */
1689 if (info->fMask & (SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL))
1691 new_flags = infoPtr->flags;
1692 if (infoPtr->minVal >= infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1694 /* Hide or disable scroll-bar */
1695 if (info->fMask & SIF_DISABLENOSCROLL)
1697 new_flags = ESB_DISABLE_BOTH;
1698 action |= SA_SSI_REFRESH;
1700 else if ((nBar != SB_CTL) && (action & SA_SSI_REFRESH))
1702 action = SA_SSI_HIDE;
1705 else /* Show and enable scroll-bar only if no page only changed. */
1706 if (info->fMask != SIF_PAGE)
1708 new_flags = ESB_ENABLE_BOTH;
1709 if ((nBar != SB_CTL) && ( (action & SA_SSI_REFRESH) ))
1710 action |= SA_SSI_SHOW;
1713 if (infoPtr->flags != new_flags) /* check arrow flags */
1715 infoPtr->flags = new_flags;
1716 action |= SA_SSI_REPAINT_ARROWS;
1720 done:
1721 if( action & SA_SSI_HIDE )
1722 SCROLL_ShowScrollBar( hwnd, nBar, FALSE, FALSE );
1723 else
1725 if( action & SA_SSI_SHOW )
1726 if( SCROLL_ShowScrollBar( hwnd, nBar, TRUE, TRUE ) )
1727 return infoPtr->curVal; /* SetWindowPos() already did the painting */
1729 if( bRedraw )
1730 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
1731 else if( action & SA_SSI_REPAINT_ARROWS )
1732 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, FALSE );
1735 /* Return current position */
1736 return infoPtr->curVal;
1740 /*************************************************************************
1741 * GetScrollInfo (USER32.@)
1743 * GetScrollInfo can be used to retrieve the position, upper bound,
1744 * lower bound, and page size of a scrollbar control.
1746 * PARAMS
1747 * hwnd [I] Handle of window with scrollbar(s)
1748 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1749 * info [IO] fMask specifies which values to retrieve
1751 * RETURNS
1752 * TRUE if SCROLLINFO is filled
1753 * ( if nBar is SB_CTL, GetScrollInfo returns TRUE even if nothing
1754 * is filled)
1756 BOOL WINAPI GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1758 TRACE("hwnd=%p nBar=%d info=%p\n", hwnd, nBar, info);
1760 /* Refer SB_CTL requests to the window */
1761 if (nBar == SB_CTL)
1763 SendMessageW(hwnd, SBM_GETSCROLLINFO, (WPARAM)0, (LPARAM)info);
1764 return TRUE;
1766 return SCROLL_GetScrollInfo(hwnd, nBar, info);
1770 /*************************************************************************
1771 * GetScrollBarInfo (USER32.@)
1773 * GetScrollBarInfo can be used to retrieve information about a scrollbar
1774 * control.
1776 * PARAMS
1777 * hwnd [I] Handle of window with scrollbar(s)
1778 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1779 * info [IO] cbSize specifies the size of SCROLLBARINFO
1781 * RETURNS
1782 * TRUE if success
1784 BOOL WINAPI GetScrollBarInfo(HWND hwnd, LONG idObject, LPSCROLLBARINFO info)
1786 TRACE("hwnd=%p idObject=%d info=%p\n", hwnd, idObject, info);
1788 /* Refer OBJID_CLIENT requests to the window */
1789 if (idObject == OBJID_CLIENT)
1790 return SendMessageW(hwnd, SBM_GETSCROLLBARINFO, (WPARAM)0, (LPARAM)info);
1791 else
1792 return SCROLL_GetScrollBarInfo(hwnd, idObject, info);
1796 /*************************************************************************
1797 * SetScrollPos (USER32.@)
1799 * Sets the current position of the scroll thumb.
1801 * PARAMS
1802 * hwnd [I] Handle of window with scrollbar(s)
1803 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1804 * nPos [I] New value
1805 * bRedraw [I] Should scrollbar be redrawn afterwards?
1807 * RETURNS
1808 * Success: Scrollbar position
1809 * Failure: 0
1811 * REMARKS
1812 * Note the ambiguity when 0 is returned. Use GetLastError
1813 * to make sure there was an error (and to know which one).
1815 INT WINAPI SetScrollPos( HWND hwnd, INT nBar, INT nPos, BOOL bRedraw)
1817 SCROLLINFO info;
1818 SCROLLBAR_INFO *infoPtr;
1819 INT oldPos;
1821 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, FALSE ))) return 0;
1822 oldPos = infoPtr->curVal;
1823 info.cbSize = sizeof(info);
1824 info.nPos = nPos;
1825 info.fMask = SIF_POS;
1826 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1827 return oldPos;
1831 /*************************************************************************
1832 * GetScrollPos (USER32.@)
1834 * Gets the current position of the scroll thumb.
1836 * PARAMS
1837 * hwnd [I] Handle of window with scrollbar(s)
1838 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1840 * RETURNS
1841 * Success: Current position
1842 * Failure: 0
1844 * REMARKS
1845 * There is ambiguity when 0 is returned. Use GetLastError
1846 * to make sure there was an error (and to know which one).
1848 INT WINAPI GetScrollPos(HWND hwnd, INT nBar)
1850 TRACE("hwnd=%p nBar=%d\n", hwnd, nBar);
1852 /* Refer SB_CTL requests to the window */
1853 if (nBar == SB_CTL)
1854 return SendMessageW(hwnd, SBM_GETPOS, (WPARAM)0, (LPARAM)0);
1855 else
1856 return SCROLL_GetScrollPos(hwnd, nBar);
1860 /*************************************************************************
1861 * SetScrollRange (USER32.@)
1862 * The SetScrollRange function sets the minimum and maximum scroll box positions
1863 * If nMinPos and nMaxPos is the same value, the scroll bar will hide
1865 * Sets the range of the scroll bar.
1867 * PARAMS
1868 * hwnd [I] Handle of window with scrollbar(s)
1869 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1870 * minVal [I] New minimum value
1871 * maxVal [I] New Maximum value
1872 * bRedraw [I] Should scrollbar be redrawn afterwards?
1874 * RETURNS
1875 * Success: TRUE
1876 * Failure: FALSE
1878 BOOL WINAPI SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal, BOOL bRedraw)
1880 SCROLLINFO info;
1882 TRACE("hwnd=%p nBar=%d min=%d max=%d, bRedraw=%d\n", hwnd, nBar, minVal, maxVal, bRedraw);
1884 info.cbSize = sizeof(info);
1885 info.fMask = SIF_RANGE;
1886 info.nMin = minVal;
1887 info.nMax = maxVal;
1888 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1889 return TRUE;
1893 /*************************************************************************
1894 * SCROLL_SetNCSbState
1896 * Updates both scrollbars at the same time. Used by MDI CalcChildScroll().
1898 INT SCROLL_SetNCSbState(HWND hwnd, int vMin, int vMax, int vPos,
1899 int hMin, int hMax, int hPos)
1901 SCROLLINFO vInfo, hInfo;
1903 vInfo.cbSize = hInfo.cbSize = sizeof(SCROLLINFO);
1904 vInfo.nMin = vMin;
1905 vInfo.nMax = vMax;
1906 vInfo.nPos = vPos;
1907 hInfo.nMin = hMin;
1908 hInfo.nMax = hMax;
1909 hInfo.nPos = hPos;
1910 vInfo.fMask = hInfo.fMask = SIF_RANGE | SIF_POS;
1912 SCROLL_SetScrollInfo( hwnd, SB_VERT, &vInfo, TRUE );
1913 SCROLL_SetScrollInfo( hwnd, SB_HORZ, &hInfo, TRUE );
1915 return 0;
1919 /*************************************************************************
1920 * GetScrollRange (USER32.@)
1922 * Gets the range of the scroll bar.
1924 * PARAMS
1925 * hwnd [I] Handle of window with scrollbar(s)
1926 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1927 * lpMin [O] Where to store minimum value
1928 * lpMax [O] Where to store maximum value
1930 * RETURNS
1931 * TRUE if values is filled
1933 BOOL WINAPI GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1935 TRACE("hwnd=%p nBar=%d lpMin=%p lpMax=%p\n", hwnd, nBar, lpMin, lpMax);
1937 /* Refer SB_CTL requests to the window */
1938 if (nBar == SB_CTL)
1939 SendMessageW(hwnd, SBM_GETRANGE, (WPARAM)lpMin, (LPARAM)lpMax);
1940 else
1941 SCROLL_GetScrollRange(hwnd, nBar, lpMin, lpMax);
1943 return TRUE;
1947 /*************************************************************************
1948 * SCROLL_ShowScrollBar()
1950 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1952 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar, BOOL fShowH, BOOL fShowV )
1954 ULONG old_style, set_bits = 0, clear_bits = 0;
1956 TRACE("hwnd=%p bar=%d horz=%d, vert=%d\n", hwnd, nBar, fShowH, fShowV );
1958 switch(nBar)
1960 case SB_CTL:
1961 ShowWindow( hwnd, fShowH ? SW_SHOW : SW_HIDE );
1962 return TRUE;
1964 case SB_BOTH:
1965 case SB_HORZ:
1966 if (fShowH) set_bits |= WS_HSCROLL;
1967 else clear_bits |= WS_HSCROLL;
1968 if( nBar == SB_HORZ ) break;
1969 /* fall through */
1970 case SB_VERT:
1971 if (fShowV) set_bits |= WS_VSCROLL;
1972 else clear_bits |= WS_VSCROLL;
1973 break;
1975 default:
1976 return FALSE; /* Nothing to do! */
1979 old_style = WIN_SetStyle( hwnd, set_bits, clear_bits );
1980 if ((old_style & clear_bits) != 0 || (old_style & set_bits) != set_bits)
1982 /* frame has been changed, let the window redraw itself */
1983 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
1984 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
1985 return TRUE;
1987 return FALSE; /* no frame changes */
1991 /*************************************************************************
1992 * ShowScrollBar (USER32.@)
1994 * Shows or hides the scroll bar.
1996 * PARAMS
1997 * hwnd [I] Handle of window with scrollbar(s)
1998 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1999 * fShow [I] TRUE = show, FALSE = hide
2001 * RETURNS
2002 * Success: TRUE
2003 * Failure: FALSE
2005 BOOL WINAPI ShowScrollBar(HWND hwnd, INT nBar, BOOL fShow)
2007 SCROLL_ShowScrollBar( hwnd, nBar, (nBar == SB_VERT) ? 0 : fShow,
2008 (nBar == SB_HORZ) ? 0 : fShow );
2009 return TRUE;
2013 /*************************************************************************
2014 * EnableScrollBar (USER32.@)
2016 * Enables or disables the scroll bars.
2018 BOOL WINAPI EnableScrollBar( HWND hwnd, UINT nBar, UINT flags )
2020 BOOL bFineWithMe;
2021 SCROLLBAR_INFO *infoPtr;
2023 flags &= ESB_DISABLE_BOTH;
2025 if (nBar == SB_BOTH)
2027 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, SB_VERT, TRUE ))) return FALSE;
2028 if (!(bFineWithMe = (infoPtr->flags == flags)) )
2030 infoPtr->flags = flags;
2031 SCROLL_RefreshScrollBar( hwnd, SB_VERT, TRUE, TRUE );
2033 nBar = SB_HORZ;
2035 else
2036 bFineWithMe = TRUE;
2038 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, TRUE ))) return FALSE;
2039 if (bFineWithMe && infoPtr->flags == flags) return FALSE;
2040 infoPtr->flags = flags;
2042 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
2043 return TRUE;