push 63c1876572cbb61a874995ad42ef27c14590d232
[wine/hacks.git] / dlls / user32 / scroll.c
blobaf35c970794540b2988b977ca0af1682e205adf4
1 /*
2 * Scrollbar control
4 * Copyright 1993 Martin Ayotte
5 * Copyright 1994, 1996 Alexandre Julliard
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 * NOTES
23 * This code was audited for completeness against the documented features
24 * of Comctl32.dll version 6.0 on Oct. 8, 2004, by Dimitrie O. Paun.
26 * Unless otherwise noted, we believe this code to be complete, as per
27 * the specification mentioned above.
28 * If you discover missing features, or bugs, please note them below.
31 #include <stdarg.h>
33 #include "windef.h"
34 #include "winbase.h"
35 #include "wingdi.h"
36 #include "wine/winuser16.h"
37 #include "controls.h"
38 #include "win.h"
39 #include "wine/debug.h"
40 #include "user_private.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(scroll);
44 typedef struct
46 INT curVal; /* Current scroll-bar value */
47 INT minVal; /* Minimum scroll-bar value */
48 INT maxVal; /* Maximum scroll-bar value */
49 INT page; /* Page size of scroll bar (Win32) */
50 UINT flags; /* EnableScrollBar flags */
51 } SCROLLBAR_INFO, *LPSCROLLBAR_INFO;
54 /* Minimum size of the rectangle between the arrows */
55 #define SCROLL_MIN_RECT 4
57 /* Minimum size of the thumb in pixels */
58 #define SCROLL_MIN_THUMB 6
60 /* Overlap between arrows and thumb */
61 #define SCROLL_ARROW_THUMB_OVERLAP 0
63 /* Delay (in ms) before first repetition when holding the button down */
64 #define SCROLL_FIRST_DELAY 200
66 /* Delay (in ms) between scroll repetitions */
67 #define SCROLL_REPEAT_DELAY 50
69 /* Scroll timer id */
70 #define SCROLL_TIMER 0
72 /* Scroll-bar hit testing */
73 enum SCROLL_HITTEST
75 SCROLL_NOWHERE, /* Outside the scroll bar */
76 SCROLL_TOP_ARROW, /* Top or left arrow */
77 SCROLL_TOP_RECT, /* Rectangle between the top arrow and the thumb */
78 SCROLL_THUMB, /* Thumb rectangle */
79 SCROLL_BOTTOM_RECT, /* Rectangle between the thumb and the bottom arrow */
80 SCROLL_BOTTOM_ARROW /* Bottom or right arrow */
83 /* What to do after SCROLL_SetScrollInfo() */
84 #define SA_SSI_HIDE 0x0001
85 #define SA_SSI_SHOW 0x0002
86 #define SA_SSI_REFRESH 0x0004
87 #define SA_SSI_REPAINT_ARROWS 0x0008
89 /* Thumb-tracking info */
90 static HWND SCROLL_TrackingWin = 0;
91 static INT SCROLL_TrackingBar = 0;
92 static INT SCROLL_TrackingPos = 0;
93 static INT SCROLL_TrackingVal = 0;
94 /* Hit test code of the last button-down event */
95 static enum SCROLL_HITTEST SCROLL_trackHitTest;
96 static BOOL SCROLL_trackVertical;
98 /* Is the moving thumb being displayed? */
99 static BOOL SCROLL_MovingThumb = FALSE;
101 /* Local functions */
102 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar,
103 BOOL fShowH, BOOL fShowV );
104 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar,
105 const SCROLLINFO *info, BOOL bRedraw );
106 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
107 RECT *rect, INT arrowSize,
108 INT thumbSize, INT thumbPos,
109 UINT flags, BOOL vertical,
110 BOOL top_selected, BOOL bottom_selected );
111 static LRESULT WINAPI ScrollBarWndProcA( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
112 static LRESULT WINAPI ScrollBarWndProcW( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
115 /*********************************************************************
116 * scrollbar class descriptor
118 static const WCHAR scrollbarW[] = {'S','c','r','o','l','l','B','a','r',0};
119 const struct builtin_class_descr SCROLL_builtin_class =
121 scrollbarW, /* name */
122 CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC, /* style */
123 ScrollBarWndProcA, /* procA */
124 ScrollBarWndProcW, /* procW */
125 sizeof(SCROLLBAR_INFO), /* extra */
126 IDC_ARROW, /* cursor */
127 0 /* brush */
130 /***********************************************************************
131 * SCROLL_ScrollInfoValid
133 * Determine if the supplied SCROLLINFO struct is valid.
134 * info [in] The SCROLLINFO struct to be tested
136 static inline BOOL SCROLL_ScrollInfoValid( LPCSCROLLINFO info )
138 return !(info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)
139 || (info->cbSize != sizeof(*info)
140 && info->cbSize != sizeof(*info) - sizeof(info->nTrackPos)));
144 /***********************************************************************
145 * SCROLL_GetInternalInfo
147 * Returns pointer to internal SCROLLBAR_INFO structure for nBar
148 * or NULL if failed (f.i. scroll bar does not exist yet)
149 * If alloc is TRUE and the struct does not exist yet, create it.
151 static SCROLLBAR_INFO *SCROLL_GetInternalInfo( HWND hwnd, INT nBar, BOOL alloc )
153 SCROLLBAR_INFO *infoPtr = NULL;
154 WND *wndPtr = WIN_GetPtr( hwnd );
156 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return NULL;
157 switch(nBar)
159 case SB_HORZ: infoPtr = (SCROLLBAR_INFO *)wndPtr->pHScroll; break;
160 case SB_VERT: infoPtr = (SCROLLBAR_INFO *)wndPtr->pVScroll; break;
161 case SB_CTL: infoPtr = (SCROLLBAR_INFO *)wndPtr->wExtra; break;
162 case SB_BOTH: WARN("with SB_BOTH\n"); break;
165 if (!infoPtr && alloc)
167 if (nBar != SB_HORZ && nBar != SB_VERT)
168 WARN("Cannot initialize nBar=%d\n",nBar);
169 else if ((infoPtr = HeapAlloc( GetProcessHeap(), 0, sizeof(SCROLLBAR_INFO) )))
171 /* Set default values */
172 infoPtr->minVal = infoPtr->curVal = infoPtr->page = 0;
173 /* From MSDN: max for a standard scroll bar is 100 by default. */
174 infoPtr->maxVal = 100;
175 /* Scroll bar is enabled by default after create */
176 infoPtr->flags = ESB_ENABLE_BOTH;
177 if (nBar == SB_HORZ) wndPtr->pHScroll = infoPtr;
178 else wndPtr->pVScroll = infoPtr;
181 WIN_ReleasePtr( wndPtr );
182 return infoPtr;
186 /***********************************************************************
187 * SCROLL_GetScrollBarRect
189 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
190 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
191 * 'arrowSize' returns the width or height of an arrow (depending on
192 * the orientation of the scrollbar), 'thumbSize' returns the size of
193 * the thumb, and 'thumbPos' returns the position of the thumb
194 * relative to the left or to the top.
195 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
197 static BOOL SCROLL_GetScrollBarRect( HWND hwnd, INT nBar, RECT *lprect,
198 INT *arrowSize, INT *thumbSize,
199 INT *thumbPos )
201 INT pixels;
202 BOOL vertical;
203 WND *wndPtr = WIN_GetPtr( hwnd );
205 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
207 switch(nBar)
209 case SB_HORZ:
210 lprect->left = wndPtr->rectClient.left - wndPtr->rectWindow.left;
211 lprect->top = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
212 lprect->right = wndPtr->rectClient.right - wndPtr->rectWindow.left;
213 lprect->bottom = lprect->top + GetSystemMetrics(SM_CYHSCROLL);
214 if(wndPtr->dwStyle & WS_VSCROLL)
215 lprect->right++;
216 vertical = FALSE;
217 break;
219 case SB_VERT:
220 if((wndPtr->dwExStyle & WS_EX_LEFTSCROLLBAR) != 0)
221 lprect->left = wndPtr->rectClient.left - wndPtr->rectWindow.left - GetSystemMetrics(SM_CXVSCROLL);
222 else
223 lprect->left = wndPtr->rectClient.right - wndPtr->rectWindow.left;
224 lprect->top = wndPtr->rectClient.top - wndPtr->rectWindow.top;
225 lprect->right = lprect->left + GetSystemMetrics(SM_CXVSCROLL);
226 lprect->bottom = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
227 if(wndPtr->dwStyle & WS_HSCROLL)
228 lprect->bottom++;
229 vertical = TRUE;
230 break;
232 case SB_CTL:
233 GetClientRect( hwnd, lprect );
234 vertical = ((wndPtr->dwStyle & SBS_VERT) != 0);
235 break;
237 default:
238 WIN_ReleasePtr( wndPtr );
239 return FALSE;
242 if (vertical) pixels = lprect->bottom - lprect->top;
243 else pixels = lprect->right - lprect->left;
245 if (pixels <= 2*GetSystemMetrics(SM_CXVSCROLL) + SCROLL_MIN_RECT)
247 if (pixels > SCROLL_MIN_RECT)
248 *arrowSize = (pixels - SCROLL_MIN_RECT) / 2;
249 else
250 *arrowSize = 0;
251 *thumbPos = *thumbSize = 0;
253 else
255 SCROLLBAR_INFO *info = SCROLL_GetInternalInfo( hwnd, nBar, FALSE );
256 if (!info)
258 WARN("called for missing scroll bar\n");
259 WIN_ReleasePtr( wndPtr );
260 return FALSE;
262 *arrowSize = GetSystemMetrics(SM_CXVSCROLL);
263 pixels -= (2 * (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP));
265 if (info->page)
267 *thumbSize = MulDiv(pixels,info->page,(info->maxVal-info->minVal+1));
268 if (*thumbSize < SCROLL_MIN_THUMB) *thumbSize = SCROLL_MIN_THUMB;
270 else *thumbSize = GetSystemMetrics(SM_CXVSCROLL);
272 if (((pixels -= *thumbSize ) < 0) ||
273 ((info->flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH))
275 /* Rectangle too small or scrollbar disabled -> no thumb */
276 *thumbPos = *thumbSize = 0;
278 else
280 INT max = info->maxVal - max( info->page-1, 0 );
281 if (info->minVal >= max)
282 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
283 else
284 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP
285 + MulDiv(pixels, (info->curVal-info->minVal),(max - info->minVal));
288 WIN_ReleasePtr( wndPtr );
289 return vertical;
293 /***********************************************************************
294 * SCROLL_GetThumbVal
296 * Compute the current scroll position based on the thumb position in pixels
297 * from the top of the scroll-bar.
299 static UINT SCROLL_GetThumbVal( SCROLLBAR_INFO *infoPtr, RECT *rect,
300 BOOL vertical, INT pos )
302 INT thumbSize;
303 INT pixels = vertical ? rect->bottom-rect->top : rect->right-rect->left;
305 if ((pixels -= 2*(GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP)) <= 0)
306 return infoPtr->minVal;
308 if (infoPtr->page)
310 thumbSize = MulDiv(pixels,infoPtr->page,(infoPtr->maxVal-infoPtr->minVal+1));
311 if (thumbSize < SCROLL_MIN_THUMB) thumbSize = SCROLL_MIN_THUMB;
313 else thumbSize = GetSystemMetrics(SM_CXVSCROLL);
315 if ((pixels -= thumbSize) <= 0) return infoPtr->minVal;
317 pos = max( 0, pos - (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP) );
318 if (pos > pixels) pos = pixels;
320 if (!infoPtr->page) pos *= infoPtr->maxVal - infoPtr->minVal;
321 else pos *= infoPtr->maxVal - infoPtr->minVal - infoPtr->page + 1;
322 return infoPtr->minVal + ((pos + pixels / 2) / pixels);
325 /***********************************************************************
326 * SCROLL_PtInRectEx
328 static BOOL SCROLL_PtInRectEx( LPRECT lpRect, POINT pt, BOOL vertical )
330 RECT rect = *lpRect;
331 int scrollbarWidth;
333 /* Pad hit rect to allow mouse to be dragged outside of scrollbar and
334 * still be considered in the scrollbar. */
335 if (vertical)
337 scrollbarWidth = lpRect->right - lpRect->left;
338 rect.left -= scrollbarWidth*8;
339 rect.right += scrollbarWidth*8;
340 rect.top -= scrollbarWidth*2;
341 rect.bottom += scrollbarWidth*2;
343 else
345 scrollbarWidth = lpRect->bottom - lpRect->top;
346 rect.left -= scrollbarWidth*2;
347 rect.right += scrollbarWidth*2;
348 rect.top -= scrollbarWidth*8;
349 rect.bottom += scrollbarWidth*8;
351 return PtInRect( &rect, pt );
354 /***********************************************************************
355 * SCROLL_ClipPos
357 static POINT SCROLL_ClipPos( LPRECT lpRect, POINT pt )
359 if( pt.x < lpRect->left )
360 pt.x = lpRect->left;
361 else
362 if( pt.x > lpRect->right )
363 pt.x = lpRect->right;
365 if( pt.y < lpRect->top )
366 pt.y = lpRect->top;
367 else
368 if( pt.y > lpRect->bottom )
369 pt.y = lpRect->bottom;
371 return pt;
375 /***********************************************************************
376 * SCROLL_HitTest
378 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
380 static enum SCROLL_HITTEST SCROLL_HitTest( HWND hwnd, INT nBar,
381 POINT pt, BOOL bDragging )
383 INT arrowSize, thumbSize, thumbPos;
384 RECT rect;
386 BOOL vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
387 &arrowSize, &thumbSize, &thumbPos );
389 if ( (bDragging && !SCROLL_PtInRectEx( &rect, pt, vertical )) ||
390 (!PtInRect( &rect, pt )) ) return SCROLL_NOWHERE;
392 if (vertical)
394 if (pt.y < rect.top + arrowSize) return SCROLL_TOP_ARROW;
395 if (pt.y >= rect.bottom - arrowSize) return SCROLL_BOTTOM_ARROW;
396 if (!thumbPos) return SCROLL_TOP_RECT;
397 pt.y -= rect.top;
398 if (pt.y < thumbPos) return SCROLL_TOP_RECT;
399 if (pt.y >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
401 else /* horizontal */
403 if (pt.x < rect.left + arrowSize) return SCROLL_TOP_ARROW;
404 if (pt.x >= rect.right - arrowSize) return SCROLL_BOTTOM_ARROW;
405 if (!thumbPos) return SCROLL_TOP_RECT;
406 pt.x -= rect.left;
407 if (pt.x < thumbPos) return SCROLL_TOP_RECT;
408 if (pt.x >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
410 return SCROLL_THUMB;
414 /***********************************************************************
415 * SCROLL_DrawArrows
417 * Draw the scroll bar arrows.
419 static void SCROLL_DrawArrows( HDC hdc, SCROLLBAR_INFO *infoPtr,
420 RECT *rect, INT arrowSize, BOOL vertical,
421 BOOL top_pressed, BOOL bottom_pressed )
423 RECT r;
425 r = *rect;
426 if( vertical )
427 r.bottom = r.top + arrowSize;
428 else
429 r.right = r.left + arrowSize;
431 DrawFrameControl( hdc, &r, DFC_SCROLL,
432 (vertical ? DFCS_SCROLLUP : DFCS_SCROLLLEFT)
433 | (top_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
434 | (infoPtr->flags&ESB_DISABLE_LTUP ? DFCS_INACTIVE : 0 ) );
436 r = *rect;
437 if( vertical )
438 r.top = r.bottom-arrowSize;
439 else
440 r.left = r.right-arrowSize;
442 DrawFrameControl( hdc, &r, DFC_SCROLL,
443 (vertical ? DFCS_SCROLLDOWN : DFCS_SCROLLRIGHT)
444 | (bottom_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
445 | (infoPtr->flags&ESB_DISABLE_RTDN ? DFCS_INACTIVE : 0) );
448 static void SCROLL_DrawMovingThumb( HDC hdc, RECT *rect, BOOL vertical,
449 INT arrowSize, INT thumbSize )
451 INT pos = SCROLL_TrackingPos;
452 INT max_size;
454 if( vertical )
455 max_size = rect->bottom - rect->top;
456 else
457 max_size = rect->right - rect->left;
459 max_size -= (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) + thumbSize;
461 if( pos < (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) )
462 pos = (arrowSize-SCROLL_ARROW_THUMB_OVERLAP);
463 else if( pos > max_size )
464 pos = max_size;
466 SCROLL_DrawInterior_9x( SCROLL_TrackingWin, hdc, SCROLL_TrackingBar,
467 rect, arrowSize, thumbSize, pos,
468 0, vertical, FALSE, FALSE );
470 SCROLL_MovingThumb = !SCROLL_MovingThumb;
473 /***********************************************************************
474 * SCROLL_DrawInterior
476 * Draw the scroll bar interior (everything except the arrows).
478 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
479 RECT *rect, INT arrowSize,
480 INT thumbSize, INT thumbPos,
481 UINT flags, BOOL vertical,
482 BOOL top_selected, BOOL bottom_selected )
484 RECT r;
485 HPEN hSavePen;
486 HBRUSH hSaveBrush,hBrush;
488 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
489 * The window-owned scrollbars need to call DEFWND_ControlColor
490 * to correctly setup default scrollbar colors
492 if (nBar == SB_CTL)
494 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
495 (WPARAM)hdc,(LPARAM)hwnd);
497 else
499 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
502 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
503 hSaveBrush = SelectObject( hdc, hBrush );
505 /* Calculate the scroll rectangle */
506 r = *rect;
507 if (vertical)
509 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
510 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
512 else
514 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
515 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
518 /* Draw the scroll rectangles and thumb */
519 if (!thumbPos) /* No thumb to draw */
521 PatBlt( hdc, r.left, r.top,
522 r.right - r.left, r.bottom - r.top,
523 PATCOPY );
525 /* cleanup and return */
526 SelectObject( hdc, hSavePen );
527 SelectObject( hdc, hSaveBrush );
528 return;
531 if (vertical)
533 PatBlt( hdc, r.left, r.top,
534 r.right - r.left,
535 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
536 top_selected ? 0x0f0000 : PATCOPY );
537 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
538 PatBlt( hdc, r.left, r.top + thumbSize,
539 r.right - r.left,
540 r.bottom - r.top - thumbSize,
541 bottom_selected ? 0x0f0000 : PATCOPY );
542 r.bottom = r.top + thumbSize;
544 else /* horizontal */
546 PatBlt( hdc, r.left, r.top,
547 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
548 r.bottom - r.top,
549 top_selected ? 0x0f0000 : PATCOPY );
550 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
551 PatBlt( hdc, r.left + thumbSize, r.top,
552 r.right - r.left - thumbSize,
553 r.bottom - r.top,
554 bottom_selected ? 0x0f0000 : PATCOPY );
555 r.right = r.left + thumbSize;
558 /* Draw the thumb */
559 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT | BF_MIDDLE );
561 /* cleanup */
562 SelectObject( hdc, hSavePen );
563 SelectObject( hdc, hSaveBrush );
567 static void SCROLL_DrawInterior( HWND hwnd, HDC hdc, INT nBar,
568 RECT *rect, INT arrowSize,
569 INT thumbSize, INT thumbPos,
570 UINT flags, BOOL vertical,
571 BOOL top_selected, BOOL bottom_selected )
573 RECT r;
574 HPEN hSavePen;
575 HBRUSH hSaveBrush,hBrush;
576 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
578 if (Save_SCROLL_MovingThumb &&
579 (SCROLL_TrackingWin == hwnd) &&
580 (SCROLL_TrackingBar == nBar))
581 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
583 /* Select the correct brush and pen */
585 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
586 * The window-owned scrollbars need to call DEFWND_ControlColor
587 * to correctly setup default scrollbar colors
589 if (nBar == SB_CTL) {
590 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
591 (WPARAM)hdc,(LPARAM)hwnd);
592 } else {
593 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
595 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
596 hSaveBrush = SelectObject( hdc, hBrush );
598 /* Calculate the scroll rectangle */
600 r = *rect;
601 if (vertical)
603 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
604 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
606 else
608 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
609 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
612 /* Draw the scroll bar frame */
614 /* Draw the scroll rectangles and thumb */
616 if (!thumbPos) /* No thumb to draw */
618 PatBlt( hdc, r.left, r.top, r.right - r.left, r.bottom - r.top, PATCOPY );
620 /* cleanup and return */
621 SelectObject( hdc, hSavePen );
622 SelectObject( hdc, hSaveBrush );
623 return;
626 if (vertical)
628 PatBlt( hdc, r.left, r.top, r.right - r.left,
629 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
630 top_selected ? 0x0f0000 : PATCOPY );
631 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
632 PatBlt( hdc, r.left, r.top + thumbSize, r.right - r.left,
633 r.bottom - r.top - thumbSize,
634 bottom_selected ? 0x0f0000 : PATCOPY );
635 r.bottom = r.top + thumbSize;
637 else /* horizontal */
639 PatBlt( hdc, r.left, r.top,
640 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
641 r.bottom - r.top, top_selected ? 0x0f0000 : PATCOPY );
642 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
643 PatBlt( hdc, r.left + thumbSize, r.top, r.right - r.left - thumbSize,
644 r.bottom - r.top, bottom_selected ? 0x0f0000 : PATCOPY );
645 r.right = r.left + thumbSize;
648 /* Draw the thumb */
650 SelectObject( hdc, GetSysColorBrush(COLOR_BTNFACE) );
651 Rectangle( hdc, r.left+1, r.top+1, r.right-1, r.bottom-1 );
652 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT );
654 if (Save_SCROLL_MovingThumb &&
655 (SCROLL_TrackingWin == hwnd) &&
656 (SCROLL_TrackingBar == nBar))
657 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
659 /* cleanup */
660 SelectObject( hdc, hSavePen );
661 SelectObject( hdc, hSaveBrush );
665 /***********************************************************************
666 * SCROLL_DrawScrollBar
668 * Redraw the whole scrollbar.
670 void SCROLL_DrawScrollBar( HWND hwnd, HDC hdc, INT nBar,
671 BOOL arrows, BOOL interior )
673 INT arrowSize, thumbSize, thumbPos;
674 RECT rect;
675 BOOL vertical;
676 SCROLLBAR_INFO *infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, TRUE );
677 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
678 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
680 if (!(hwnd = WIN_GetFullHandle( hwnd ))) return;
682 if (!infoPtr ||
683 ((nBar == SB_VERT) && !(style & WS_VSCROLL)) ||
684 ((nBar == SB_HORZ) && !(style & WS_HSCROLL))) return;
685 if (!WIN_IsWindowDrawable( hwnd, FALSE )) return;
687 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
688 &arrowSize, &thumbSize, &thumbPos );
690 /* do not draw if the scrollbar rectangle is empty */
691 if(IsRectEmpty(&rect)) return;
693 if (Save_SCROLL_MovingThumb &&
694 (SCROLL_TrackingWin == hwnd) &&
695 (SCROLL_TrackingBar == nBar))
696 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
698 /* Draw the arrows */
700 if (arrows && arrowSize)
702 if( vertical == SCROLL_trackVertical && GetCapture() == hwnd )
703 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
704 (SCROLL_trackHitTest == SCROLL_TOP_ARROW),
705 (SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW) );
706 else
707 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
708 FALSE, FALSE );
710 if( interior )
711 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
712 thumbPos, infoPtr->flags, vertical, FALSE, FALSE );
714 if (Save_SCROLL_MovingThumb &&
715 (SCROLL_TrackingWin == hwnd) &&
716 (SCROLL_TrackingBar == nBar))
717 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
719 /* if scroll bar has focus, reposition the caret */
720 if(hwnd==GetFocus() && (nBar==SB_CTL))
722 if (!vertical)
724 SetCaretPos(thumbPos+1, rect.top+1);
726 else
728 SetCaretPos(rect.top+1, thumbPos+1);
733 /***********************************************************************
734 * SCROLL_DrawSizeGrip
736 * Draw the size grip.
738 static void SCROLL_DrawSizeGrip( HWND hwnd, HDC hdc)
740 RECT rc;
742 GetClientRect( hwnd, &rc );
743 FillRect( hdc, &rc, GetSysColorBrush(COLOR_SCROLLBAR) );
744 rc.left = max( rc.left, rc.right - GetSystemMetrics(SM_CXVSCROLL) - 1 );
745 rc.top = max( rc.top, rc.bottom - GetSystemMetrics(SM_CYHSCROLL) - 1 );
746 DrawFrameControl( hdc, &rc, DFC_SCROLL, DFCS_SCROLLSIZEGRIP );
750 /***********************************************************************
751 * SCROLL_RefreshScrollBar
753 * Repaint the scroll bar interior after a SetScrollRange() or
754 * SetScrollPos() call.
756 static void SCROLL_RefreshScrollBar( HWND hwnd, INT nBar,
757 BOOL arrows, BOOL interior )
759 HDC hdc = GetDCEx( hwnd, 0,
760 DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW) );
761 if (!hdc) return;
763 SCROLL_DrawScrollBar( hwnd, hdc, nBar, arrows, interior );
764 ReleaseDC( hwnd, hdc );
768 /***********************************************************************
769 * SCROLL_HandleKbdEvent
771 * Handle a keyboard event (only for SB_CTL scrollbars with focus).
773 * PARAMS
774 * hwnd [I] Handle of window with scrollbar(s)
775 * wParam [I] Variable input including enable state
776 * lParam [I] Variable input including input point
778 static void SCROLL_HandleKbdEvent(HWND hwnd, WPARAM wParam, LPARAM lParam)
780 TRACE("hwnd=%p wParam=%ld lParam=%ld\n", hwnd, wParam, lParam);
782 /* hide caret on first KEYDOWN to prevent flicker */
783 if ((lParam & PFD_DOUBLEBUFFER_DONTCARE) == 0)
784 HideCaret(hwnd);
786 switch(wParam)
788 case VK_PRIOR: wParam = SB_PAGEUP; break;
789 case VK_NEXT: wParam = SB_PAGEDOWN; break;
790 case VK_HOME: wParam = SB_TOP; break;
791 case VK_END: wParam = SB_BOTTOM; break;
792 case VK_UP: wParam = SB_LINEUP; break;
793 case VK_DOWN: wParam = SB_LINEDOWN; break;
794 case VK_LEFT: wParam = SB_LINEUP; break;
795 case VK_RIGHT: wParam = SB_LINEDOWN; break;
796 default: return;
798 SendMessageW(GetParent(hwnd),
799 ((GetWindowLongW( hwnd, GWL_STYLE ) & SBS_VERT) ?
800 WM_VSCROLL : WM_HSCROLL), wParam, (LPARAM)hwnd);
804 /***********************************************************************
805 * SCROLL_HandleScrollEvent
807 * Handle a mouse or timer event for the scrollbar.
808 * 'pt' is the location of the mouse event in client (for SB_CTL) or
809 * windows coordinates.
811 static void SCROLL_HandleScrollEvent( HWND hwnd, INT nBar, UINT msg, POINT pt)
813 /* Previous mouse position for timer events */
814 static POINT prevPt;
815 /* Thumb position when tracking started. */
816 static UINT trackThumbPos;
817 /* Position in the scroll-bar of the last button-down event. */
818 static INT lastClickPos;
819 /* Position in the scroll-bar of the last mouse event. */
820 static INT lastMousePos;
822 enum SCROLL_HITTEST hittest;
823 HWND hwndOwner, hwndCtl;
824 BOOL vertical;
825 INT arrowSize, thumbSize, thumbPos;
826 RECT rect;
827 HDC hdc;
829 SCROLLBAR_INFO *infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, FALSE );
830 if (!infoPtr) return;
831 if ((SCROLL_trackHitTest == SCROLL_NOWHERE) && (msg != WM_LBUTTONDOWN))
832 return;
834 if (nBar == SB_CTL && (GetWindowLongW( hwnd, GWL_STYLE ) & (SBS_SIZEGRIP | SBS_SIZEBOX)))
836 switch(msg)
838 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
839 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
840 SetCapture( hwnd );
841 prevPt = pt;
842 SCROLL_trackHitTest = hittest = SCROLL_THUMB;
843 break;
844 case WM_MOUSEMOVE:
845 GetClientRect(GetParent(GetParent(hwnd)),&rect);
846 prevPt = pt;
847 break;
848 case WM_LBUTTONUP:
849 ReleaseCapture();
850 SCROLL_trackHitTest = hittest = SCROLL_NOWHERE;
851 if (hwnd==GetFocus()) ShowCaret(hwnd);
852 break;
853 case WM_SYSTIMER:
854 pt = prevPt;
855 break;
857 return;
860 hdc = GetDCEx( hwnd, 0, DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW));
861 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
862 &arrowSize, &thumbSize, &thumbPos );
863 hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd) : hwnd;
864 hwndCtl = (nBar == SB_CTL) ? hwnd : 0;
866 switch(msg)
868 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
869 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
870 SCROLL_trackVertical = vertical;
871 SCROLL_trackHitTest = hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
872 lastClickPos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
873 lastMousePos = lastClickPos;
874 trackThumbPos = thumbPos;
875 prevPt = pt;
876 if (nBar == SB_CTL && (GetWindowLongW(hwnd, GWL_STYLE) & WS_TABSTOP)) SetFocus( hwnd );
877 SetCapture( hwnd );
878 break;
880 case WM_MOUSEMOVE:
881 hittest = SCROLL_HitTest( hwnd, nBar, pt, TRUE );
882 prevPt = pt;
883 break;
885 case WM_LBUTTONUP:
886 hittest = SCROLL_NOWHERE;
887 ReleaseCapture();
888 /* if scrollbar has focus, show back caret */
889 if (hwnd==GetFocus()) ShowCaret(hwnd);
890 break;
892 case WM_SYSTIMER:
893 pt = prevPt;
894 hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
895 break;
897 default:
898 return; /* Should never happen */
901 TRACE("Event: hwnd=%p bar=%d msg=%s pt=%d,%d hit=%d\n",
902 hwnd, nBar, SPY_GetMsgName(msg,hwnd), pt.x, pt.y, hittest );
904 switch(SCROLL_trackHitTest)
906 case SCROLL_NOWHERE: /* No tracking in progress */
907 break;
909 case SCROLL_TOP_ARROW:
910 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
911 (hittest == SCROLL_trackHitTest), FALSE );
912 if (hittest == SCROLL_trackHitTest)
914 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
916 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
917 SB_LINEUP, (LPARAM)hwndCtl );
920 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
921 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
922 (TIMERPROC)0 );
924 else KillSystemTimer( hwnd, SCROLL_TIMER );
925 break;
927 case SCROLL_TOP_RECT:
928 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
929 thumbPos, infoPtr->flags, vertical,
930 (hittest == SCROLL_trackHitTest), FALSE );
931 if (hittest == SCROLL_trackHitTest)
933 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
935 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
936 SB_PAGEUP, (LPARAM)hwndCtl );
938 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
939 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
940 (TIMERPROC)0 );
942 else KillSystemTimer( hwnd, SCROLL_TIMER );
943 break;
945 case SCROLL_THUMB:
946 if (msg == WM_LBUTTONDOWN)
948 SCROLL_TrackingWin = hwnd;
949 SCROLL_TrackingBar = nBar;
950 SCROLL_TrackingPos = trackThumbPos + lastMousePos - lastClickPos;
951 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
952 vertical,
953 SCROLL_TrackingPos );
954 if (!SCROLL_MovingThumb)
955 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
957 else if (msg == WM_LBUTTONUP)
959 if (SCROLL_MovingThumb)
960 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
962 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
963 thumbPos, infoPtr->flags, vertical,
964 FALSE, FALSE );
966 else /* WM_MOUSEMOVE */
968 INT pos;
970 if (!SCROLL_PtInRectEx( &rect, pt, vertical )) pos = lastClickPos;
971 else
973 pt = SCROLL_ClipPos( &rect, pt );
974 pos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
976 if ( (pos != lastMousePos) || (!SCROLL_MovingThumb) )
978 if (SCROLL_MovingThumb)
979 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
980 arrowSize, thumbSize );
981 lastMousePos = pos;
982 SCROLL_TrackingPos = trackThumbPos + pos - lastClickPos;
983 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
984 vertical,
985 SCROLL_TrackingPos );
986 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
987 MAKEWPARAM( SB_THUMBTRACK, SCROLL_TrackingVal),
988 (LPARAM)hwndCtl );
989 if (!SCROLL_MovingThumb)
990 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
991 arrowSize, thumbSize );
994 break;
996 case SCROLL_BOTTOM_RECT:
997 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
998 thumbPos, infoPtr->flags, vertical,
999 FALSE, (hittest == SCROLL_trackHitTest) );
1000 if (hittest == SCROLL_trackHitTest)
1002 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1004 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1005 SB_PAGEDOWN, (LPARAM)hwndCtl );
1007 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1008 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1009 (TIMERPROC)0 );
1011 else KillSystemTimer( hwnd, SCROLL_TIMER );
1012 break;
1014 case SCROLL_BOTTOM_ARROW:
1015 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
1016 FALSE, (hittest == SCROLL_trackHitTest) );
1017 if (hittest == SCROLL_trackHitTest)
1019 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1021 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1022 SB_LINEDOWN, (LPARAM)hwndCtl );
1025 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1026 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1027 (TIMERPROC)0 );
1029 else KillSystemTimer( hwnd, SCROLL_TIMER );
1030 break;
1033 if (msg == WM_LBUTTONDOWN)
1036 if (hittest == SCROLL_THUMB)
1038 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1039 trackThumbPos + lastMousePos - lastClickPos );
1040 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1041 MAKEWPARAM( SB_THUMBTRACK, val ), (LPARAM)hwndCtl );
1045 if (msg == WM_LBUTTONUP)
1047 hittest = SCROLL_trackHitTest;
1048 SCROLL_trackHitTest = SCROLL_NOWHERE; /* Terminate tracking */
1050 if (hittest == SCROLL_THUMB)
1052 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1053 trackThumbPos + lastMousePos - lastClickPos );
1054 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1055 MAKEWPARAM( SB_THUMBPOSITION, val ), (LPARAM)hwndCtl );
1057 /* SB_ENDSCROLL doesn't report thumb position */
1058 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1059 SB_ENDSCROLL, (LPARAM)hwndCtl );
1061 /* Terminate tracking */
1062 SCROLL_TrackingWin = 0;
1065 ReleaseDC( hwnd, hdc );
1069 /***********************************************************************
1070 * SCROLL_TrackScrollBar
1072 * Track a mouse button press on a scroll-bar.
1073 * pt is in screen-coordinates for non-client scroll bars.
1075 void SCROLL_TrackScrollBar( HWND hwnd, INT scrollbar, POINT pt )
1077 MSG msg;
1078 INT xoffset = 0, yoffset = 0;
1080 if (scrollbar != SB_CTL)
1082 WND *wndPtr = WIN_GetPtr( hwnd );
1083 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return;
1084 xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
1085 yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
1086 WIN_ReleasePtr( wndPtr );
1087 ScreenToClient( hwnd, &pt );
1088 pt.x += xoffset;
1089 pt.y += yoffset;
1092 SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt );
1096 if (!GetMessageW( &msg, 0, 0, 0 )) break;
1097 if (CallMsgFilterW( &msg, MSGF_SCROLLBAR )) continue;
1098 if (msg.message == WM_LBUTTONUP ||
1099 msg.message == WM_MOUSEMOVE ||
1100 (msg.message == WM_SYSTIMER && msg.wParam == SCROLL_TIMER))
1102 pt.x = (short)LOWORD(msg.lParam) + xoffset;
1103 pt.y = (short)HIWORD(msg.lParam) + yoffset;
1104 SCROLL_HandleScrollEvent( hwnd, scrollbar, msg.message, pt );
1106 else
1108 TranslateMessage( &msg );
1109 DispatchMessageW( &msg );
1111 if (!IsWindow( hwnd ))
1113 ReleaseCapture();
1114 break;
1116 } while (msg.message != WM_LBUTTONUP);
1120 /***********************************************************************
1121 * SCROLL_CreateScrollBar
1123 * Create a scroll bar
1125 * PARAMS
1126 * hwnd [I] Handle of window with scrollbar(s)
1127 * lpCreate [I] The style and place of the scroll bar
1129 static void SCROLL_CreateScrollBar(HWND hwnd, LPCREATESTRUCTW lpCreate)
1131 LPSCROLLBAR_INFO info = SCROLL_GetInternalInfo(hwnd, SB_CTL, TRUE);
1132 if (!info) return;
1134 TRACE("hwnd=%p lpCreate=%p\n", hwnd, lpCreate);
1136 if (lpCreate->style & WS_DISABLED)
1138 info->flags = ESB_DISABLE_BOTH;
1139 TRACE("Created WS_DISABLED scrollbar\n");
1143 if (lpCreate->style & (SBS_SIZEGRIP | SBS_SIZEBOX))
1145 if (lpCreate->style & SBS_SIZEBOXTOPLEFTALIGN)
1146 MoveWindow( hwnd, lpCreate->x, lpCreate->y, GetSystemMetrics(SM_CXVSCROLL)+1,
1147 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1148 else if(lpCreate->style & SBS_SIZEBOXBOTTOMRIGHTALIGN)
1149 MoveWindow( hwnd, lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1150 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1151 GetSystemMetrics(SM_CXVSCROLL)+1,
1152 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1154 else if (lpCreate->style & SBS_VERT)
1156 if (lpCreate->style & SBS_LEFTALIGN)
1157 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1158 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1159 else if (lpCreate->style & SBS_RIGHTALIGN)
1160 MoveWindow( hwnd,
1161 lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1162 lpCreate->y,
1163 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1165 else /* SBS_HORZ */
1167 if (lpCreate->style & SBS_TOPALIGN)
1168 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1169 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1170 else if (lpCreate->style & SBS_BOTTOMALIGN)
1171 MoveWindow( hwnd,
1172 lpCreate->x,
1173 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1174 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1179 /*************************************************************************
1180 * SCROLL_GetScrollInfo
1182 * Internal helper for the API function
1184 * PARAMS
1185 * hwnd [I] Handle of window with scrollbar(s)
1186 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1187 * info [IO] fMask specifies which values to retrieve
1189 * RETURNS
1190 * FALSE if requested field not filled (f.i. scroll bar does not exist)
1192 static BOOL SCROLL_GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1194 LPSCROLLBAR_INFO infoPtr;
1196 /* handle invalid data structure */
1197 if (!SCROLL_ScrollInfoValid(info)
1198 || !(infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE)))
1199 return FALSE;
1201 /* fill in the desired scroll info structure */
1202 if (info->fMask & SIF_PAGE) info->nPage = infoPtr->page;
1203 if (info->fMask & SIF_POS) info->nPos = infoPtr->curVal;
1204 if ((info->fMask & SIF_TRACKPOS) && (info->cbSize == sizeof(*info)))
1205 info->nTrackPos = (SCROLL_TrackingWin == WIN_GetFullHandle(hwnd)) ? SCROLL_TrackingVal : infoPtr->curVal;
1206 if (info->fMask & SIF_RANGE)
1208 info->nMin = infoPtr->minVal;
1209 info->nMax = infoPtr->maxVal;
1212 TRACE("cbSize %02x fMask %04x nMin %d nMax %d nPage %u nPos %d nTrackPos %d\n",
1213 info->cbSize, info->fMask, info->nMin, info->nMax, info->nPage,
1214 info->nPos, info->nTrackPos);
1216 return (info->fMask & SIF_ALL) != 0;
1220 /*************************************************************************
1221 * SCROLL_GetScrollBarInfo
1223 * Internal helper for the API function
1225 * PARAMS
1226 * hwnd [I] Handle of window with scrollbar(s)
1227 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1228 * info [IO] cbSize specifies the size of the structure
1230 * RETURNS
1231 * FALSE if failed
1233 static BOOL SCROLL_GetScrollBarInfo(HWND hwnd, LONG idObject, LPSCROLLBARINFO info)
1235 LPSCROLLBAR_INFO infoPtr;
1236 INT nBar;
1237 INT nDummy;
1238 DWORD style = GetWindowLongW(hwnd, GWL_STYLE);
1239 BOOL pressed;
1241 switch (idObject)
1243 case OBJID_CLIENT: nBar = SB_CTL; break;
1244 case OBJID_HSCROLL: nBar = SB_HORZ; break;
1245 case OBJID_VSCROLL: nBar = SB_VERT; break;
1246 default: return FALSE;
1249 /* handle invalid data structure */
1250 if (info->cbSize != sizeof(*info))
1251 return FALSE;
1253 SCROLL_GetScrollBarRect(hwnd, nBar, &info->rcScrollBar, &nDummy,
1254 &info->dxyLineButton, &info->xyThumbTop);
1256 info->xyThumbBottom = info->xyThumbTop + info->dxyLineButton;
1258 infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, TRUE);
1260 /* Scroll bar state */
1261 info->rgstate[0] = 0;
1262 if ((nBar == SB_HORZ && !(style & WS_HSCROLL))
1263 || (nBar == SB_VERT && !(style & WS_VSCROLL)))
1264 info->rgstate[0] |= STATE_SYSTEM_INVISIBLE;
1265 if (infoPtr->minVal >= infoPtr->maxVal - max(infoPtr->page - 1, 0))
1267 if (!(info->rgstate[0] & STATE_SYSTEM_INVISIBLE))
1268 info->rgstate[0] |= STATE_SYSTEM_UNAVAILABLE;
1269 else
1270 info->rgstate[0] |= STATE_SYSTEM_OFFSCREEN;
1272 if (nBar == SB_CTL && !IsWindowEnabled(hwnd))
1273 info->rgstate[0] |= STATE_SYSTEM_UNAVAILABLE;
1275 pressed = ((nBar == SB_VERT) == SCROLL_trackVertical && GetCapture() == hwnd);
1277 /* Top/left arrow button state. MSDN says top/right, but I don't believe it */
1278 info->rgstate[1] = 0;
1279 if (pressed && SCROLL_trackHitTest == SCROLL_TOP_ARROW)
1280 info->rgstate[1] |= STATE_SYSTEM_PRESSED;
1281 if (infoPtr->flags & ESB_DISABLE_LTUP)
1282 info->rgstate[1] |= STATE_SYSTEM_UNAVAILABLE;
1284 /* Page up/left region state. MSDN says up/right, but I don't believe it */
1285 info->rgstate[2] = 0;
1286 if (infoPtr->curVal == infoPtr->minVal)
1287 info->rgstate[2] |= STATE_SYSTEM_INVISIBLE;
1288 if (pressed && SCROLL_trackHitTest == SCROLL_TOP_RECT)
1289 info->rgstate[2] |= STATE_SYSTEM_PRESSED;
1291 /* Thumb state */
1292 info->rgstate[3] = 0;
1293 if (pressed && SCROLL_trackHitTest == SCROLL_THUMB)
1294 info->rgstate[3] |= STATE_SYSTEM_PRESSED;
1296 /* Page down/right region state. MSDN says down/left, but I don't believe it */
1297 info->rgstate[4] = 0;
1298 if (infoPtr->curVal >= infoPtr->maxVal - 1)
1299 info->rgstate[4] |= STATE_SYSTEM_INVISIBLE;
1300 if (pressed && SCROLL_trackHitTest == SCROLL_BOTTOM_RECT)
1301 info->rgstate[4] |= STATE_SYSTEM_PRESSED;
1303 /* Bottom/right arrow button state. MSDN says bottom/left, but I don't believe it */
1304 info->rgstate[5] = 0;
1305 if (pressed && SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW)
1306 info->rgstate[5] |= STATE_SYSTEM_PRESSED;
1307 if (infoPtr->flags & ESB_DISABLE_RTDN)
1308 info->rgstate[5] |= STATE_SYSTEM_UNAVAILABLE;
1310 return TRUE;
1314 /*************************************************************************
1315 * SCROLL_GetScrollPos
1317 * Internal helper for the API function
1319 * PARAMS
1320 * hwnd [I] Handle of window with scrollbar(s)
1321 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1323 static INT SCROLL_GetScrollPos(HWND hwnd, INT nBar)
1325 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1326 return infoPtr ? infoPtr->curVal: 0;
1330 /*************************************************************************
1331 * SCROLL_GetScrollRange
1333 * Internal helper for the API function
1335 * PARAMS
1336 * hwnd [I] Handle of window with scrollbar(s)
1337 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1338 * lpMin [O] Where to store minimum value
1339 * lpMax [O] Where to store maximum value
1341 * RETURNS
1342 * Success: TRUE
1343 * Failure: FALSE
1345 static BOOL SCROLL_GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1347 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1349 if (lpMin) *lpMin = infoPtr ? infoPtr->minVal : 0;
1350 if (lpMax) *lpMax = infoPtr ? infoPtr->maxVal : 0;
1352 return TRUE;
1356 /*************************************************************************
1357 * SCROLL_SetScrollRange
1359 * PARAMS
1360 * hwnd [I] Handle of window with scrollbar(s)
1361 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1362 * lpMin [I] Minimum value
1363 * lpMax [I] Maximum value
1366 static BOOL SCROLL_SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal)
1368 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1370 TRACE("hwnd=%p nBar=%d min=%d max=%d\n", hwnd, nBar, minVal, maxVal);
1372 if (infoPtr)
1374 infoPtr->minVal = minVal;
1375 infoPtr->maxVal = maxVal;
1377 return TRUE;
1381 /***********************************************************************
1382 * ScrollBarWndProc
1384 static LRESULT ScrollBarWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, BOOL unicode )
1386 if (!IsWindow( hwnd )) return 0;
1388 switch(message)
1390 case WM_CREATE:
1391 SCROLL_CreateScrollBar(hwnd, (LPCREATESTRUCTW)lParam);
1392 break;
1394 case WM_ENABLE:
1396 SCROLLBAR_INFO *infoPtr;
1397 if ((infoPtr = SCROLL_GetInternalInfo( hwnd, SB_CTL, FALSE )))
1399 infoPtr->flags = wParam ? ESB_ENABLE_BOTH : ESB_DISABLE_BOTH;
1400 SCROLL_RefreshScrollBar(hwnd, SB_CTL, TRUE, TRUE);
1403 return 0;
1405 case WM_LBUTTONDBLCLK:
1406 case WM_LBUTTONDOWN:
1408 POINT pt;
1409 pt.x = (short)LOWORD(lParam);
1410 pt.y = (short)HIWORD(lParam);
1411 SCROLL_TrackScrollBar( hwnd, SB_CTL, pt );
1413 break;
1414 case WM_LBUTTONUP:
1415 case WM_MOUSEMOVE:
1416 case WM_SYSTIMER:
1418 POINT pt;
1419 pt.x = (short)LOWORD(lParam);
1420 pt.y = (short)HIWORD(lParam);
1421 SCROLL_HandleScrollEvent( hwnd, SB_CTL, message, pt );
1423 break;
1425 case WM_KEYDOWN:
1426 SCROLL_HandleKbdEvent(hwnd, wParam, lParam);
1427 break;
1429 case WM_KEYUP:
1430 ShowCaret(hwnd);
1431 break;
1433 case WM_SETFOCUS:
1435 /* Create a caret when a ScrollBar get focus */
1436 RECT rect;
1437 int arrowSize, thumbSize, thumbPos, vertical;
1438 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,
1439 &arrowSize, &thumbSize, &thumbPos );
1440 if (!vertical)
1442 CreateCaret(hwnd, (HBITMAP)1, thumbSize-2, rect.bottom-rect.top-2);
1443 SetCaretPos(thumbPos+1, rect.top+1);
1445 else
1447 CreateCaret(hwnd, (HBITMAP)1, rect.right-rect.left-2,thumbSize-2);
1448 SetCaretPos(rect.top+1, thumbPos+1);
1450 ShowCaret(hwnd);
1452 break;
1454 case WM_KILLFOCUS:
1456 RECT rect;
1457 int arrowSize, thumbSize, thumbPos, vertical;
1458 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,&arrowSize, &thumbSize, &thumbPos );
1459 if (!vertical){
1460 rect.left=thumbPos+1;
1461 rect.right=rect.left+thumbSize;
1463 else
1465 rect.top=thumbPos+1;
1466 rect.bottom=rect.top+thumbSize;
1468 HideCaret(hwnd);
1469 InvalidateRect(hwnd,&rect,0);
1470 DestroyCaret();
1472 break;
1474 case WM_ERASEBKGND:
1475 return 1;
1477 case WM_GETDLGCODE:
1478 return DLGC_WANTARROWS; /* Windows returns this value */
1480 case WM_PAINT:
1482 PAINTSTRUCT ps;
1483 HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
1484 if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEGRIP)
1486 SCROLL_DrawSizeGrip( hwnd, hdc);
1488 else if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEBOX)
1490 RECT rc;
1491 GetClientRect( hwnd, &rc );
1492 FillRect( hdc, &rc, GetSysColorBrush(COLOR_SCROLLBAR) );
1494 else
1495 SCROLL_DrawScrollBar( hwnd, hdc, SB_CTL, TRUE, TRUE );
1496 if (!wParam) EndPaint(hwnd, &ps);
1498 break;
1500 case SBM_SETPOS16:
1501 case SBM_SETPOS:
1502 return SetScrollPos( hwnd, SB_CTL, wParam, (BOOL)lParam );
1504 case SBM_GETPOS16:
1505 case SBM_GETPOS:
1506 return SCROLL_GetScrollPos(hwnd, SB_CTL);
1508 case SBM_SETRANGE16:
1509 if (wParam) message = SBM_SETRANGEREDRAW;
1510 wParam = LOWORD(lParam);
1511 lParam = HIWORD(lParam);
1512 /* fall through */
1513 case SBM_SETRANGEREDRAW:
1514 case SBM_SETRANGE:
1516 INT oldPos = SCROLL_GetScrollPos( hwnd, SB_CTL );
1517 SCROLL_SetScrollRange( hwnd, SB_CTL, wParam, lParam );
1518 if (message == SBM_SETRANGEREDRAW)
1519 SCROLL_RefreshScrollBar( hwnd, SB_CTL, TRUE, TRUE );
1520 if (oldPos != SCROLL_GetScrollPos( hwnd, SB_CTL )) return oldPos;
1522 return 0;
1524 case SBM_GETRANGE16:
1526 INT min, max;
1528 SCROLL_GetScrollRange(hwnd, SB_CTL, &min, &max);
1529 return MAKELRESULT(min, max);
1532 case SBM_GETRANGE:
1533 return SCROLL_GetScrollRange(hwnd, SB_CTL, (LPINT)wParam, (LPINT)lParam);
1535 case SBM_ENABLE_ARROWS16:
1536 case SBM_ENABLE_ARROWS:
1537 return EnableScrollBar( hwnd, SB_CTL, wParam );
1539 case SBM_SETSCROLLINFO:
1540 return SCROLL_SetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam, wParam );
1542 case SBM_GETSCROLLINFO:
1543 return SCROLL_GetScrollInfo(hwnd, SB_CTL, (SCROLLINFO *)lParam);
1545 case SBM_GETSCROLLBARINFO:
1546 return SCROLL_GetScrollBarInfo(hwnd, OBJID_CLIENT, (SCROLLBARINFO *)lParam);
1548 case 0x00e5:
1549 case 0x00e7:
1550 case 0x00e8:
1551 case 0x00ec:
1552 case 0x00ed:
1553 case 0x00ee:
1554 case 0x00ef:
1555 ERR("unknown Win32 msg %04x wp=%08lx lp=%08lx\n",
1556 message, wParam, lParam );
1557 break;
1559 default:
1560 if (message >= WM_USER)
1561 WARN("unknown msg %04x wp=%04lx lp=%08lx\n",
1562 message, wParam, lParam );
1563 if (unicode)
1564 return DefWindowProcW( hwnd, message, wParam, lParam );
1565 else
1566 return DefWindowProcA( hwnd, message, wParam, lParam );
1568 return 0;
1572 /***********************************************************************
1573 * ScrollBarWndProcA
1575 static LRESULT WINAPI ScrollBarWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1577 return ScrollBarWndProc( hwnd, message, wParam, lParam, FALSE );
1581 /***********************************************************************
1582 * ScrollBarWndProcW
1584 static LRESULT WINAPI ScrollBarWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1586 return ScrollBarWndProc( hwnd, message, wParam, lParam, TRUE );
1590 /*************************************************************************
1591 * SetScrollInfo (USER32.@)
1593 * SetScrollInfo can be used to set the position, upper bound,
1594 * lower bound, and page size of a scrollbar control.
1596 * PARAMS
1597 * hwnd [I] Handle of window with scrollbar(s)
1598 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1599 * info [I] Specifies what to change and new values
1600 * bRedraw [I] Should scrollbar be redrawn afterwards?
1602 * RETURNS
1603 * Scrollbar position
1605 * NOTE
1606 * For 100 lines of text to be displayed in a window of 25 lines,
1607 * one would for instance use info->nMin=0, info->nMax=75
1608 * (corresponding to the 76 different positions of the window on
1609 * the text), and info->nPage=25.
1611 INT WINAPI SetScrollInfo(HWND hwnd, INT nBar, const SCROLLINFO *info, BOOL bRedraw)
1613 TRACE("hwnd=%p nBar=%d info=%p, bRedraw=%d\n", hwnd, nBar, info, bRedraw);
1615 /* Refer SB_CTL requests to the window */
1616 if (nBar == SB_CTL)
1617 return SendMessageW(hwnd, SBM_SETSCROLLINFO, bRedraw, (LPARAM)info);
1618 else
1619 return SCROLL_SetScrollInfo( hwnd, nBar, info, bRedraw );
1622 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar, LPCSCROLLINFO info, BOOL bRedraw )
1624 /* Update the scrollbar state and set action flags according to
1625 * what has to be done graphics wise. */
1627 SCROLLBAR_INFO *infoPtr;
1628 UINT new_flags;
1629 INT action = 0;
1631 /* handle invalid data structure */
1632 if (!SCROLL_ScrollInfoValid(info)
1633 || !(infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, TRUE)))
1634 return 0;
1636 if (TRACE_ON(scroll))
1638 TRACE("hwnd=%p bar=%d", hwnd, nBar);
1639 if (info->fMask & SIF_PAGE) TRACE( " page=%d", info->nPage );
1640 if (info->fMask & SIF_POS) TRACE( " pos=%d", info->nPos );
1641 if (info->fMask & SIF_RANGE) TRACE( " min=%d max=%d", info->nMin, info->nMax );
1642 TRACE("\n");
1645 /* Set the page size */
1647 if (info->fMask & SIF_PAGE)
1649 if( infoPtr->page != info->nPage )
1651 infoPtr->page = info->nPage;
1652 action |= SA_SSI_REFRESH;
1656 /* Set the scroll pos */
1658 if (info->fMask & SIF_POS)
1660 if( infoPtr->curVal != info->nPos )
1662 infoPtr->curVal = info->nPos;
1663 action |= SA_SSI_REFRESH;
1667 /* Set the scroll range */
1669 if (info->fMask & SIF_RANGE)
1671 /* Invalid range -> range is set to (0,0) */
1672 if ((info->nMin > info->nMax) ||
1673 ((UINT)(info->nMax - info->nMin) >= 0x80000000))
1675 action |= SA_SSI_REFRESH;
1676 infoPtr->minVal = 0;
1677 infoPtr->maxVal = 0;
1679 else
1681 if( infoPtr->minVal != info->nMin ||
1682 infoPtr->maxVal != info->nMax )
1684 action |= SA_SSI_REFRESH;
1685 infoPtr->minVal = info->nMin;
1686 infoPtr->maxVal = info->nMax;
1691 /* Make sure the page size is valid */
1692 if (infoPtr->page < 0) infoPtr->page = 0;
1693 else if (infoPtr->page > infoPtr->maxVal - infoPtr->minVal + 1 )
1694 infoPtr->page = infoPtr->maxVal - infoPtr->minVal + 1;
1696 /* Make sure the pos is inside the range */
1698 if (infoPtr->curVal < infoPtr->minVal)
1699 infoPtr->curVal = infoPtr->minVal;
1700 else if (infoPtr->curVal > infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1701 infoPtr->curVal = infoPtr->maxVal - max( infoPtr->page-1, 0 );
1703 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1704 infoPtr->page, infoPtr->curVal,
1705 infoPtr->minVal, infoPtr->maxVal );
1707 /* don't change the scrollbar state if SetScrollInfo
1708 * is just called with SIF_DISABLENOSCROLL
1710 if(!(info->fMask & SIF_ALL)) goto done;
1712 /* Check if the scrollbar should be hidden or disabled */
1714 if (info->fMask & (SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL))
1716 new_flags = infoPtr->flags;
1717 if (infoPtr->minVal >= infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1719 /* Hide or disable scroll-bar */
1720 if (info->fMask & SIF_DISABLENOSCROLL)
1722 new_flags = ESB_DISABLE_BOTH;
1723 action |= SA_SSI_REFRESH;
1725 else if ((nBar != SB_CTL) && (action & SA_SSI_REFRESH))
1727 action = SA_SSI_HIDE;
1730 else /* Show and enable scroll-bar only if no page only changed. */
1731 if (info->fMask != SIF_PAGE)
1733 new_flags = ESB_ENABLE_BOTH;
1734 if ((nBar != SB_CTL) && ( (action & SA_SSI_REFRESH) ))
1735 action |= SA_SSI_SHOW;
1738 if (infoPtr->flags != new_flags) /* check arrow flags */
1740 infoPtr->flags = new_flags;
1741 action |= SA_SSI_REPAINT_ARROWS;
1745 done:
1746 if( action & SA_SSI_HIDE )
1747 SCROLL_ShowScrollBar( hwnd, nBar, FALSE, FALSE );
1748 else
1750 if( action & SA_SSI_SHOW )
1751 if( SCROLL_ShowScrollBar( hwnd, nBar, TRUE, TRUE ) )
1752 return infoPtr->curVal; /* SetWindowPos() already did the painting */
1754 if( bRedraw )
1755 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
1756 else if( action & SA_SSI_REPAINT_ARROWS )
1757 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, FALSE );
1760 /* Return current position */
1761 return infoPtr->curVal;
1765 /*************************************************************************
1766 * GetScrollInfo (USER32.@)
1768 * GetScrollInfo can be used to retrieve the position, upper bound,
1769 * lower bound, and page size of a scrollbar control.
1771 * PARAMS
1772 * hwnd [I] Handle of window with scrollbar(s)
1773 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1774 * info [IO] fMask specifies which values to retrieve
1776 * RETURNS
1777 * TRUE if SCROLLINFO is filled
1778 * ( if nBar is SB_CTL, GetScrollInfo returns TRUE even if nothing
1779 * is filled)
1781 BOOL WINAPI GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1783 TRACE("hwnd=%p nBar=%d info=%p\n", hwnd, nBar, info);
1785 /* Refer SB_CTL requests to the window */
1786 if (nBar == SB_CTL)
1788 SendMessageW(hwnd, SBM_GETSCROLLINFO, (WPARAM)0, (LPARAM)info);
1789 return TRUE;
1791 return SCROLL_GetScrollInfo(hwnd, nBar, info);
1795 /*************************************************************************
1796 * GetScrollBarInfo (USER32.@)
1798 * GetScrollBarInfo can be used to retrieve information about a scrollbar
1799 * control.
1801 * PARAMS
1802 * hwnd [I] Handle of window with scrollbar(s)
1803 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1804 * info [IO] cbSize specifies the size of SCROLLBARINFO
1806 * RETURNS
1807 * TRUE if success
1809 BOOL WINAPI GetScrollBarInfo(HWND hwnd, LONG idObject, LPSCROLLBARINFO info)
1811 TRACE("hwnd=%p idObject=%d info=%p\n", hwnd, idObject, info);
1813 /* Refer OBJID_CLIENT requests to the window */
1814 if (idObject == OBJID_CLIENT)
1815 return SendMessageW(hwnd, SBM_GETSCROLLBARINFO, (WPARAM)0, (LPARAM)info);
1816 else
1817 return SCROLL_GetScrollBarInfo(hwnd, idObject, info);
1821 /*************************************************************************
1822 * SetScrollPos (USER32.@)
1824 * Sets the current position of the scroll thumb.
1826 * PARAMS
1827 * hwnd [I] Handle of window with scrollbar(s)
1828 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1829 * nPos [I] New value
1830 * bRedraw [I] Should scrollbar be redrawn afterwards?
1832 * RETURNS
1833 * Success: Scrollbar position
1834 * Failure: 0
1836 * REMARKS
1837 * Note the ambiguity when 0 is returned. Use GetLastError
1838 * to make sure there was an error (and to know which one).
1840 INT WINAPI SetScrollPos( HWND hwnd, INT nBar, INT nPos, BOOL bRedraw)
1842 SCROLLINFO info;
1843 SCROLLBAR_INFO *infoPtr;
1844 INT oldPos;
1846 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, FALSE ))) return 0;
1847 oldPos = infoPtr->curVal;
1848 info.cbSize = sizeof(info);
1849 info.nPos = nPos;
1850 info.fMask = SIF_POS;
1851 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1852 return oldPos;
1856 /*************************************************************************
1857 * GetScrollPos (USER32.@)
1859 * Gets the current position of the scroll thumb.
1861 * PARAMS
1862 * hwnd [I] Handle of window with scrollbar(s)
1863 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1865 * RETURNS
1866 * Success: Current position
1867 * Failure: 0
1869 * REMARKS
1870 * There is ambiguity when 0 is returned. Use GetLastError
1871 * to make sure there was an error (and to know which one).
1873 INT WINAPI GetScrollPos(HWND hwnd, INT nBar)
1875 TRACE("hwnd=%p nBar=%d\n", hwnd, nBar);
1877 /* Refer SB_CTL requests to the window */
1878 if (nBar == SB_CTL)
1879 return SendMessageW(hwnd, SBM_GETPOS, (WPARAM)0, (LPARAM)0);
1880 else
1881 return SCROLL_GetScrollPos(hwnd, nBar);
1885 /*************************************************************************
1886 * SetScrollRange (USER32.@)
1887 * The SetScrollRange function sets the minimum and maximum scroll box positions
1888 * If nMinPos and nMaxPos is the same value, the scroll bar will hide
1890 * Sets the range of the scroll bar.
1892 * PARAMS
1893 * hwnd [I] Handle of window with scrollbar(s)
1894 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1895 * minVal [I] New minimum value
1896 * maxVal [I] New Maximum value
1897 * bRedraw [I] Should scrollbar be redrawn afterwards?
1899 * RETURNS
1900 * Success: TRUE
1901 * Failure: FALSE
1903 BOOL WINAPI SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal, BOOL bRedraw)
1905 SCROLLINFO info;
1907 TRACE("hwnd=%p nBar=%d min=%d max=%d, bRedraw=%d\n", hwnd, nBar, minVal, maxVal, bRedraw);
1909 info.cbSize = sizeof(info);
1910 info.fMask = SIF_RANGE;
1911 info.nMin = minVal;
1912 info.nMax = maxVal;
1913 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1914 return TRUE;
1918 /*************************************************************************
1919 * SCROLL_SetNCSbState
1921 * Updates both scrollbars at the same time. Used by MDI CalcChildScroll().
1923 INT SCROLL_SetNCSbState(HWND hwnd, int vMin, int vMax, int vPos,
1924 int hMin, int hMax, int hPos)
1926 SCROLLINFO vInfo, hInfo;
1928 vInfo.cbSize = hInfo.cbSize = sizeof(SCROLLINFO);
1929 vInfo.nMin = vMin;
1930 vInfo.nMax = vMax;
1931 vInfo.nPos = vPos;
1932 hInfo.nMin = hMin;
1933 hInfo.nMax = hMax;
1934 hInfo.nPos = hPos;
1935 vInfo.fMask = hInfo.fMask = SIF_RANGE | SIF_POS;
1937 SCROLL_SetScrollInfo( hwnd, SB_VERT, &vInfo, TRUE );
1938 SCROLL_SetScrollInfo( hwnd, SB_HORZ, &hInfo, TRUE );
1940 return 0;
1944 /*************************************************************************
1945 * GetScrollRange (USER32.@)
1947 * Gets the range of the scroll bar.
1949 * PARAMS
1950 * hwnd [I] Handle of window with scrollbar(s)
1951 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1952 * lpMin [O] Where to store minimum value
1953 * lpMax [O] Where to store maximum value
1955 * RETURNS
1956 * TRUE if values is filled
1958 BOOL WINAPI GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1960 TRACE("hwnd=%p nBar=%d lpMin=%p lpMax=%p\n", hwnd, nBar, lpMin, lpMax);
1962 /* Refer SB_CTL requests to the window */
1963 if (nBar == SB_CTL)
1964 SendMessageW(hwnd, SBM_GETRANGE, (WPARAM)lpMin, (LPARAM)lpMax);
1965 else
1966 SCROLL_GetScrollRange(hwnd, nBar, lpMin, lpMax);
1968 return TRUE;
1972 /*************************************************************************
1973 * SCROLL_ShowScrollBar()
1975 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1977 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar, BOOL fShowH, BOOL fShowV )
1979 ULONG old_style, set_bits = 0, clear_bits = 0;
1981 TRACE("hwnd=%p bar=%d horz=%d, vert=%d\n", hwnd, nBar, fShowH, fShowV );
1983 switch(nBar)
1985 case SB_CTL:
1986 ShowWindow( hwnd, fShowH ? SW_SHOW : SW_HIDE );
1987 return TRUE;
1989 case SB_BOTH:
1990 case SB_HORZ:
1991 if (fShowH) set_bits |= WS_HSCROLL;
1992 else clear_bits |= WS_HSCROLL;
1993 if( nBar == SB_HORZ ) break;
1994 /* fall through */
1995 case SB_VERT:
1996 if (fShowV) set_bits |= WS_VSCROLL;
1997 else clear_bits |= WS_VSCROLL;
1998 break;
2000 default:
2001 return FALSE; /* Nothing to do! */
2004 old_style = WIN_SetStyle( hwnd, set_bits, clear_bits );
2005 if ((old_style & clear_bits) != 0 || (old_style & set_bits) != set_bits)
2007 /* frame has been changed, let the window redraw itself */
2008 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
2009 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
2010 return TRUE;
2012 return FALSE; /* no frame changes */
2016 /*************************************************************************
2017 * ShowScrollBar (USER32.@)
2019 * Shows or hides the scroll bar.
2021 * PARAMS
2022 * hwnd [I] Handle of window with scrollbar(s)
2023 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
2024 * fShow [I] TRUE = show, FALSE = hide
2026 * RETURNS
2027 * Success: TRUE
2028 * Failure: FALSE
2030 BOOL WINAPI ShowScrollBar(HWND hwnd, INT nBar, BOOL fShow)
2032 if ( !hwnd )
2033 return FALSE;
2035 SCROLL_ShowScrollBar( hwnd, nBar, (nBar == SB_VERT) ? 0 : fShow,
2036 (nBar == SB_HORZ) ? 0 : fShow );
2037 return TRUE;
2041 /*************************************************************************
2042 * EnableScrollBar (USER32.@)
2044 * Enables or disables the scroll bars.
2046 BOOL WINAPI EnableScrollBar( HWND hwnd, UINT nBar, UINT flags )
2048 BOOL bFineWithMe;
2049 SCROLLBAR_INFO *infoPtr;
2051 flags &= ESB_DISABLE_BOTH;
2053 if (nBar == SB_BOTH)
2055 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, SB_VERT, TRUE ))) return FALSE;
2056 if (!(bFineWithMe = (infoPtr->flags == flags)) )
2058 infoPtr->flags = flags;
2059 SCROLL_RefreshScrollBar( hwnd, SB_VERT, TRUE, TRUE );
2061 nBar = SB_HORZ;
2063 else
2064 bFineWithMe = TRUE;
2066 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, TRUE ))) return FALSE;
2067 if (bFineWithMe && infoPtr->flags == flags) return FALSE;
2068 infoPtr->flags = flags;
2070 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
2071 return TRUE;