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
31 #include "wine/debug.h"
32 #include "user_private.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(scroll
);
36 /* data for a single scroll bar */
39 INT curVal
; /* Current scroll-bar value */
40 INT minVal
; /* Minimum scroll-bar value */
41 INT maxVal
; /* Maximum scroll-bar value */
42 INT page
; /* Page size of scroll bar (Win32) */
43 UINT flags
; /* EnableScrollBar flags */
44 } SCROLLBAR_INFO
, *LPSCROLLBAR_INFO
;
46 /* data for window that has (one or two) scroll bars */
51 } WINSCROLLBAR_INFO
, *LPWINSCROLLBAR_INFO
;
53 /* Minimum size of the rectangle between the arrows */
54 #define SCROLL_MIN_RECT 4
56 /* Minimum size of the thumb in pixels */
57 #define SCROLL_MIN_THUMB 6
59 /* Overlap between arrows and thumb */
60 #define SCROLL_ARROW_THUMB_OVERLAP 0
62 /* Delay (in ms) before first repetition when holding the button down */
63 #define SCROLL_FIRST_DELAY 200
65 /* Delay (in ms) between scroll repetitions */
66 #define SCROLL_REPEAT_DELAY 50
69 #define SCROLL_TIMER 0
71 /* Scroll-bar hit testing */
74 SCROLL_NOWHERE
, /* Outside the scroll bar */
75 SCROLL_TOP_ARROW
, /* Top or left arrow */
76 SCROLL_TOP_RECT
, /* Rectangle between the top arrow and the thumb */
77 SCROLL_THUMB
, /* Thumb rectangle */
78 SCROLL_BOTTOM_RECT
, /* Rectangle between the thumb and the bottom arrow */
79 SCROLL_BOTTOM_ARROW
/* Bottom or right arrow */
82 /* What to do after SCROLL_SetScrollInfo() */
83 #define SA_SSI_HIDE 0x0001
84 #define SA_SSI_SHOW 0x0002
85 #define SA_SSI_REFRESH 0x0004
86 #define SA_SSI_REPAINT_ARROWS 0x0008
88 /* Thumb-tracking info */
89 static HWND SCROLL_TrackingWin
= 0;
90 static INT SCROLL_TrackingBar
= 0;
91 static INT SCROLL_TrackingPos
= 0;
92 static INT SCROLL_TrackingVal
= 0;
93 /* Hit test code of the last button-down event */
94 static enum SCROLL_HITTEST SCROLL_trackHitTest
;
95 static BOOL SCROLL_trackVertical
;
97 /* Is the moving thumb being displayed? */
98 static BOOL SCROLL_MovingThumb
= FALSE
;
100 /* Local functions */
101 static BOOL
SCROLL_ShowScrollBar( HWND hwnd
, INT nBar
,
102 BOOL fShowH
, BOOL fShowV
);
103 static INT
SCROLL_SetScrollInfo( HWND hwnd
, INT nBar
,
104 const SCROLLINFO
*info
, BOOL bRedraw
);
105 static void SCROLL_DrawInterior_9x( HWND hwnd
, HDC hdc
, INT nBar
,
106 RECT
*rect
, INT arrowSize
,
107 INT thumbSize
, INT thumbPos
,
108 UINT flags
, BOOL vertical
,
109 BOOL top_selected
, BOOL bottom_selected
);
112 /*********************************************************************
113 * scrollbar class descriptor
115 static const WCHAR scrollbarW
[] = {'S','c','r','o','l','l','B','a','r',0};
116 const struct builtin_class_descr SCROLL_builtin_class
=
118 scrollbarW
, /* name */
119 CS_DBLCLKS
| CS_VREDRAW
| CS_HREDRAW
| CS_PARENTDC
, /* style */
120 WINPROC_SCROLLBAR
, /* proc */
121 sizeof(SCROLLBAR_INFO
), /* extra */
122 IDC_ARROW
, /* cursor */
126 /***********************************************************************
127 * SCROLL_ScrollInfoValid
129 * Determine if the supplied SCROLLINFO struct is valid.
130 * info [in] The SCROLLINFO struct to be tested
132 static inline BOOL
SCROLL_ScrollInfoValid( LPCSCROLLINFO info
)
134 return !(info
->fMask
& ~(SIF_ALL
| SIF_DISABLENOSCROLL
)
135 || (info
->cbSize
!= sizeof(*info
)
136 && info
->cbSize
!= sizeof(*info
) - sizeof(info
->nTrackPos
)));
140 /***********************************************************************
141 * SCROLL_GetInternalInfo
143 * Returns pointer to internal SCROLLBAR_INFO structure for nBar
144 * or NULL if failed (f.i. scroll bar does not exist yet)
145 * If alloc is TRUE and the struct does not exist yet, create it.
147 static SCROLLBAR_INFO
*SCROLL_GetInternalInfo( HWND hwnd
, INT nBar
, BOOL alloc
)
149 SCROLLBAR_INFO
*infoPtr
= NULL
;
150 WND
*wndPtr
= WIN_GetPtr( hwnd
);
152 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return NULL
;
156 if (wndPtr
->pScroll
) infoPtr
= &((LPWINSCROLLBAR_INFO
)wndPtr
->pScroll
)->horz
;
159 if (wndPtr
->pScroll
) infoPtr
= &((LPWINSCROLLBAR_INFO
)wndPtr
->pScroll
)->vert
;
162 infoPtr
= (SCROLLBAR_INFO
*)wndPtr
->wExtra
;
165 WARN("with SB_BOTH\n");
169 if (!infoPtr
&& alloc
)
171 WINSCROLLBAR_INFO
*winInfoPtr
;
173 if (nBar
!= SB_HORZ
&& nBar
!= SB_VERT
)
174 WARN("Cannot initialize nBar=%d\n",nBar
);
175 else if ((winInfoPtr
= HeapAlloc( GetProcessHeap(), 0, sizeof(WINSCROLLBAR_INFO
) )))
177 /* Set default values */
178 winInfoPtr
->horz
.minVal
= 0;
179 winInfoPtr
->horz
.curVal
= 0;
180 winInfoPtr
->horz
.page
= 0;
181 /* From MSDN and our own tests:
182 * max for a standard scroll bar is 100 by default. */
183 winInfoPtr
->horz
.maxVal
= 100;
184 winInfoPtr
->horz
.flags
= ESB_ENABLE_BOTH
;
185 winInfoPtr
->vert
= winInfoPtr
->horz
;
186 wndPtr
->pScroll
= winInfoPtr
;
187 infoPtr
= nBar
== SB_HORZ
? &winInfoPtr
->horz
: &winInfoPtr
->vert
;
190 WIN_ReleasePtr( wndPtr
);
195 /***********************************************************************
196 * SCROLL_GetScrollBarRect
198 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
199 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
200 * 'arrowSize' returns the width or height of an arrow (depending on
201 * the orientation of the scrollbar), 'thumbSize' returns the size of
202 * the thumb, and 'thumbPos' returns the position of the thumb
203 * relative to the left or to the top.
204 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
206 static BOOL
SCROLL_GetScrollBarRect( HWND hwnd
, INT nBar
, RECT
*lprect
,
207 INT
*arrowSize
, INT
*thumbSize
,
212 WND
*wndPtr
= WIN_GetPtr( hwnd
);
214 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
219 WIN_GetRectangles( hwnd
, COORDS_WINDOW
, NULL
, lprect
);
220 lprect
->top
= lprect
->bottom
;
221 lprect
->bottom
+= GetSystemMetrics(SM_CYHSCROLL
);
222 if(wndPtr
->dwStyle
& WS_VSCROLL
)
228 WIN_GetRectangles( hwnd
, COORDS_WINDOW
, NULL
, lprect
);
229 if((wndPtr
->dwExStyle
& WS_EX_LEFTSCROLLBAR
) != 0)
231 lprect
->right
= lprect
->left
;
232 lprect
->left
-= GetSystemMetrics(SM_CXVSCROLL
);
236 lprect
->left
= lprect
->right
;
237 lprect
->right
+= GetSystemMetrics(SM_CXVSCROLL
);
239 if(wndPtr
->dwStyle
& WS_HSCROLL
)
245 GetClientRect( hwnd
, lprect
);
246 vertical
= ((wndPtr
->dwStyle
& SBS_VERT
) != 0);
250 WIN_ReleasePtr( wndPtr
);
254 if (vertical
) pixels
= lprect
->bottom
- lprect
->top
;
255 else pixels
= lprect
->right
- lprect
->left
;
257 if (pixels
<= 2*GetSystemMetrics(SM_CXVSCROLL
) + SCROLL_MIN_RECT
)
259 if (pixels
> SCROLL_MIN_RECT
)
260 *arrowSize
= (pixels
- SCROLL_MIN_RECT
) / 2;
263 *thumbPos
= *thumbSize
= 0;
267 SCROLLBAR_INFO
*info
= SCROLL_GetInternalInfo( hwnd
, nBar
, FALSE
);
270 WARN("called for missing scroll bar\n");
271 WIN_ReleasePtr( wndPtr
);
274 *arrowSize
= GetSystemMetrics(SM_CXVSCROLL
);
275 pixels
-= (2 * (GetSystemMetrics(SM_CXVSCROLL
) - SCROLL_ARROW_THUMB_OVERLAP
));
279 *thumbSize
= MulDiv(pixels
,info
->page
,(info
->maxVal
-info
->minVal
+1));
280 if (*thumbSize
< SCROLL_MIN_THUMB
) *thumbSize
= SCROLL_MIN_THUMB
;
282 else *thumbSize
= GetSystemMetrics(SM_CXVSCROLL
);
284 if (((pixels
-= *thumbSize
) < 0) ||
285 ((info
->flags
& ESB_DISABLE_BOTH
) == ESB_DISABLE_BOTH
))
287 /* Rectangle too small or scrollbar disabled -> no thumb */
288 *thumbPos
= *thumbSize
= 0;
292 INT max
= info
->maxVal
- max( info
->page
-1, 0 );
293 if (info
->minVal
>= max
)
294 *thumbPos
= *arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
296 *thumbPos
= *arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
297 + MulDiv(pixels
, (info
->curVal
-info
->minVal
),(max
- info
->minVal
));
300 WIN_ReleasePtr( wndPtr
);
305 /***********************************************************************
308 * Compute the current scroll position based on the thumb position in pixels
309 * from the top of the scroll-bar.
311 static UINT
SCROLL_GetThumbVal( SCROLLBAR_INFO
*infoPtr
, RECT
*rect
,
312 BOOL vertical
, INT pos
)
315 INT pixels
= vertical
? rect
->bottom
-rect
->top
: rect
->right
-rect
->left
;
318 if ((pixels
-= 2*(GetSystemMetrics(SM_CXVSCROLL
) - SCROLL_ARROW_THUMB_OVERLAP
)) <= 0)
319 return infoPtr
->minVal
;
323 thumbSize
= MulDiv(pixels
,infoPtr
->page
,(infoPtr
->maxVal
-infoPtr
->minVal
+1));
324 if (thumbSize
< SCROLL_MIN_THUMB
) thumbSize
= SCROLL_MIN_THUMB
;
326 else thumbSize
= GetSystemMetrics(SM_CXVSCROLL
);
328 if ((pixels
-= thumbSize
) <= 0) return infoPtr
->minVal
;
330 pos
= max( 0, pos
- (GetSystemMetrics(SM_CXVSCROLL
) - SCROLL_ARROW_THUMB_OVERLAP
) );
331 if (pos
> pixels
) pos
= pixels
;
334 range
= infoPtr
->maxVal
- infoPtr
->minVal
;
336 range
= infoPtr
->maxVal
- infoPtr
->minVal
- infoPtr
->page
+ 1;
338 return infoPtr
->minVal
+ MulDiv(pos
, range
, pixels
);
341 /***********************************************************************
344 static BOOL
SCROLL_PtInRectEx( LPRECT lpRect
, POINT pt
, BOOL vertical
)
349 /* Pad hit rect to allow mouse to be dragged outside of scrollbar and
350 * still be considered in the scrollbar. */
353 scrollbarWidth
= lpRect
->right
- lpRect
->left
;
354 InflateRect(&rect
, scrollbarWidth
* 8, scrollbarWidth
* 2);
358 scrollbarWidth
= lpRect
->bottom
- lpRect
->top
;
359 InflateRect(&rect
, scrollbarWidth
* 2, scrollbarWidth
* 8);
361 return PtInRect( &rect
, pt
);
364 /***********************************************************************
367 static POINT
SCROLL_ClipPos( LPRECT lpRect
, POINT pt
)
369 if( pt
.x
< lpRect
->left
)
372 if( pt
.x
> lpRect
->right
)
373 pt
.x
= lpRect
->right
;
375 if( pt
.y
< lpRect
->top
)
378 if( pt
.y
> lpRect
->bottom
)
379 pt
.y
= lpRect
->bottom
;
385 /***********************************************************************
388 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
390 static enum SCROLL_HITTEST
SCROLL_HitTest( HWND hwnd
, INT nBar
,
391 POINT pt
, BOOL bDragging
)
393 INT arrowSize
, thumbSize
, thumbPos
;
396 BOOL vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
397 &arrowSize
, &thumbSize
, &thumbPos
);
399 if ( (bDragging
&& !SCROLL_PtInRectEx( &rect
, pt
, vertical
)) ||
400 (!PtInRect( &rect
, pt
)) ) return SCROLL_NOWHERE
;
404 if (pt
.y
< rect
.top
+ arrowSize
) return SCROLL_TOP_ARROW
;
405 if (pt
.y
>= rect
.bottom
- arrowSize
) return SCROLL_BOTTOM_ARROW
;
406 if (!thumbPos
) return SCROLL_TOP_RECT
;
408 if (pt
.y
< thumbPos
) return SCROLL_TOP_RECT
;
409 if (pt
.y
>= thumbPos
+ thumbSize
) return SCROLL_BOTTOM_RECT
;
411 else /* horizontal */
413 if (pt
.x
< rect
.left
+ arrowSize
) return SCROLL_TOP_ARROW
;
414 if (pt
.x
>= rect
.right
- arrowSize
) return SCROLL_BOTTOM_ARROW
;
415 if (!thumbPos
) return SCROLL_TOP_RECT
;
417 if (pt
.x
< thumbPos
) return SCROLL_TOP_RECT
;
418 if (pt
.x
>= thumbPos
+ thumbSize
) return SCROLL_BOTTOM_RECT
;
424 /***********************************************************************
427 * Draw the scroll bar arrows.
429 static void SCROLL_DrawArrows( HDC hdc
, SCROLLBAR_INFO
*infoPtr
,
430 RECT
*rect
, INT arrowSize
, BOOL vertical
,
431 BOOL top_pressed
, BOOL bottom_pressed
)
437 r
.bottom
= r
.top
+ arrowSize
;
439 r
.right
= r
.left
+ arrowSize
;
441 DrawFrameControl( hdc
, &r
, DFC_SCROLL
,
442 (vertical
? DFCS_SCROLLUP
: DFCS_SCROLLLEFT
)
443 | (top_pressed
? (DFCS_PUSHED
| DFCS_FLAT
) : 0 )
444 | (infoPtr
->flags
&ESB_DISABLE_LTUP
? DFCS_INACTIVE
: 0 ) );
448 r
.top
= r
.bottom
-arrowSize
;
450 r
.left
= r
.right
-arrowSize
;
452 DrawFrameControl( hdc
, &r
, DFC_SCROLL
,
453 (vertical
? DFCS_SCROLLDOWN
: DFCS_SCROLLRIGHT
)
454 | (bottom_pressed
? (DFCS_PUSHED
| DFCS_FLAT
) : 0 )
455 | (infoPtr
->flags
&ESB_DISABLE_RTDN
? DFCS_INACTIVE
: 0) );
458 static void SCROLL_DrawMovingThumb( HDC hdc
, RECT
*rect
, BOOL vertical
,
459 INT arrowSize
, INT thumbSize
)
461 INT pos
= SCROLL_TrackingPos
;
465 max_size
= rect
->bottom
- rect
->top
;
467 max_size
= rect
->right
- rect
->left
;
469 max_size
-= (arrowSize
-SCROLL_ARROW_THUMB_OVERLAP
) + thumbSize
;
471 if( pos
< (arrowSize
-SCROLL_ARROW_THUMB_OVERLAP
) )
472 pos
= (arrowSize
-SCROLL_ARROW_THUMB_OVERLAP
);
473 else if( pos
> max_size
)
476 SCROLL_DrawInterior_9x( SCROLL_TrackingWin
, hdc
, SCROLL_TrackingBar
,
477 rect
, arrowSize
, thumbSize
, pos
,
478 0, vertical
, FALSE
, FALSE
);
480 SCROLL_MovingThumb
= !SCROLL_MovingThumb
;
483 /***********************************************************************
484 * SCROLL_DrawInterior
486 * Draw the scroll bar interior (everything except the arrows).
488 static void SCROLL_DrawInterior_9x( HWND hwnd
, HDC hdc
, INT nBar
,
489 RECT
*rect
, INT arrowSize
,
490 INT thumbSize
, INT thumbPos
,
491 UINT flags
, BOOL vertical
,
492 BOOL top_selected
, BOOL bottom_selected
)
496 HBRUSH hSaveBrush
,hBrush
;
498 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
499 * The window-owned scrollbars need to call DEFWND_ControlColor
500 * to correctly setup default scrollbar colors
504 hBrush
= (HBRUSH
)SendMessageW( GetParent(hwnd
), WM_CTLCOLORSCROLLBAR
,
505 (WPARAM
)hdc
,(LPARAM
)hwnd
);
509 hBrush
= DEFWND_ControlColor( hdc
, CTLCOLOR_SCROLLBAR
);
512 hSavePen
= SelectObject( hdc
, SYSCOLOR_GetPen(COLOR_WINDOWFRAME
) );
513 hSaveBrush
= SelectObject( hdc
, hBrush
);
515 /* Calculate the scroll rectangle */
519 r
.top
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
520 r
.bottom
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
524 r
.left
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
525 r
.right
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
528 /* Draw the scroll rectangles and thumb */
529 if (!thumbPos
) /* No thumb to draw */
531 PatBlt( hdc
, r
.left
, r
.top
,
532 r
.right
- r
.left
, r
.bottom
- r
.top
,
535 /* cleanup and return */
536 SelectObject( hdc
, hSavePen
);
537 SelectObject( hdc
, hSaveBrush
);
543 PatBlt( hdc
, r
.left
, r
.top
,
545 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
),
546 top_selected
? 0x0f0000 : PATCOPY
);
547 r
.top
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
548 PatBlt( hdc
, r
.left
, r
.top
+ thumbSize
,
550 r
.bottom
- r
.top
- thumbSize
,
551 bottom_selected
? 0x0f0000 : PATCOPY
);
552 r
.bottom
= r
.top
+ thumbSize
;
554 else /* horizontal */
556 PatBlt( hdc
, r
.left
, r
.top
,
557 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
),
559 top_selected
? 0x0f0000 : PATCOPY
);
560 r
.left
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
561 PatBlt( hdc
, r
.left
+ thumbSize
, r
.top
,
562 r
.right
- r
.left
- thumbSize
,
564 bottom_selected
? 0x0f0000 : PATCOPY
);
565 r
.right
= r
.left
+ thumbSize
;
569 DrawEdge( hdc
, &r
, EDGE_RAISED
, BF_RECT
| BF_MIDDLE
);
572 SelectObject( hdc
, hSavePen
);
573 SelectObject( hdc
, hSaveBrush
);
577 static void SCROLL_DrawInterior( HWND hwnd
, HDC hdc
, INT nBar
,
578 RECT
*rect
, INT arrowSize
,
579 INT thumbSize
, INT thumbPos
,
580 UINT flags
, BOOL vertical
,
581 BOOL top_selected
, BOOL bottom_selected
)
585 HBRUSH hSaveBrush
,hBrush
;
586 BOOL Save_SCROLL_MovingThumb
= SCROLL_MovingThumb
;
588 if (Save_SCROLL_MovingThumb
&&
589 (SCROLL_TrackingWin
== hwnd
) &&
590 (SCROLL_TrackingBar
== nBar
))
591 SCROLL_DrawMovingThumb( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
593 /* Select the correct brush and pen */
595 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
596 * The window-owned scrollbars need to call DEFWND_ControlColor
597 * to correctly setup default scrollbar colors
599 if (nBar
== SB_CTL
) {
600 hBrush
= (HBRUSH
)SendMessageW( GetParent(hwnd
), WM_CTLCOLORSCROLLBAR
,
601 (WPARAM
)hdc
,(LPARAM
)hwnd
);
603 hBrush
= DEFWND_ControlColor( hdc
, CTLCOLOR_SCROLLBAR
);
605 hSavePen
= SelectObject( hdc
, SYSCOLOR_GetPen(COLOR_WINDOWFRAME
) );
606 hSaveBrush
= SelectObject( hdc
, hBrush
);
608 /* Calculate the scroll rectangle */
613 r
.top
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
614 r
.bottom
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
618 r
.left
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
619 r
.right
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
622 /* Draw the scroll bar frame */
624 /* Draw the scroll rectangles and thumb */
626 if (!thumbPos
) /* No thumb to draw */
628 PatBlt( hdc
, r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
, PATCOPY
);
630 /* cleanup and return */
631 SelectObject( hdc
, hSavePen
);
632 SelectObject( hdc
, hSaveBrush
);
638 PatBlt( hdc
, r
.left
, r
.top
, r
.right
- r
.left
,
639 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
),
640 top_selected
? 0x0f0000 : PATCOPY
);
641 r
.top
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
642 PatBlt( hdc
, r
.left
, r
.top
+ thumbSize
, r
.right
- r
.left
,
643 r
.bottom
- r
.top
- thumbSize
,
644 bottom_selected
? 0x0f0000 : PATCOPY
);
645 r
.bottom
= r
.top
+ thumbSize
;
647 else /* horizontal */
649 PatBlt( hdc
, r
.left
, r
.top
,
650 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
),
651 r
.bottom
- r
.top
, top_selected
? 0x0f0000 : PATCOPY
);
652 r
.left
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
653 PatBlt( hdc
, r
.left
+ thumbSize
, r
.top
, r
.right
- r
.left
- thumbSize
,
654 r
.bottom
- r
.top
, bottom_selected
? 0x0f0000 : PATCOPY
);
655 r
.right
= r
.left
+ thumbSize
;
660 SelectObject( hdc
, GetSysColorBrush(COLOR_BTNFACE
) );
661 Rectangle( hdc
, r
.left
+1, r
.top
+1, r
.right
-1, r
.bottom
-1 );
662 DrawEdge( hdc
, &r
, EDGE_RAISED
, BF_RECT
);
664 if (Save_SCROLL_MovingThumb
&&
665 (SCROLL_TrackingWin
== hwnd
) &&
666 (SCROLL_TrackingBar
== nBar
))
667 SCROLL_DrawMovingThumb( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
670 SelectObject( hdc
, hSavePen
);
671 SelectObject( hdc
, hSaveBrush
);
675 /***********************************************************************
676 * SCROLL_DrawScrollBar
678 * Redraw the whole scrollbar.
680 void SCROLL_DrawScrollBar( HWND hwnd
, HDC hdc
, INT nBar
,
681 BOOL arrows
, BOOL interior
)
683 INT arrowSize
, thumbSize
, thumbPos
;
686 SCROLLBAR_INFO
*infoPtr
= SCROLL_GetInternalInfo( hwnd
, nBar
, TRUE
);
687 BOOL Save_SCROLL_MovingThumb
= SCROLL_MovingThumb
;
688 DWORD style
= GetWindowLongW( hwnd
, GWL_STYLE
);
690 if (!(hwnd
= WIN_GetFullHandle( hwnd
))) return;
693 ((nBar
== SB_VERT
) && !(style
& WS_VSCROLL
)) ||
694 ((nBar
== SB_HORZ
) && !(style
& WS_HSCROLL
))) return;
695 if (!WIN_IsWindowDrawable( hwnd
, FALSE
)) return;
697 vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
698 &arrowSize
, &thumbSize
, &thumbPos
);
700 /* do not draw if the scrollbar rectangle is empty */
701 if(IsRectEmpty(&rect
)) return;
703 if (Save_SCROLL_MovingThumb
&&
704 (SCROLL_TrackingWin
== hwnd
) &&
705 (SCROLL_TrackingBar
== nBar
))
706 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
708 /* Draw the arrows */
710 if (arrows
&& arrowSize
)
712 if( vertical
== SCROLL_trackVertical
&& GetCapture() == hwnd
)
713 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
714 (SCROLL_trackHitTest
== SCROLL_TOP_ARROW
),
715 (SCROLL_trackHitTest
== SCROLL_BOTTOM_ARROW
) );
717 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
721 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
722 thumbPos
, infoPtr
->flags
, vertical
, FALSE
, FALSE
);
724 if (Save_SCROLL_MovingThumb
&&
725 (SCROLL_TrackingWin
== hwnd
) &&
726 (SCROLL_TrackingBar
== nBar
))
727 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
729 /* if scroll bar has focus, reposition the caret */
730 if(hwnd
==GetFocus() && (nBar
==SB_CTL
))
734 SetCaretPos(thumbPos
+1, rect
.top
+1);
738 SetCaretPos(rect
.top
+1, thumbPos
+1);
743 /***********************************************************************
744 * SCROLL_DrawSizeGrip
746 * Draw the size grip.
748 static void SCROLL_DrawSizeGrip( HWND hwnd
, HDC hdc
)
752 GetClientRect( hwnd
, &rc
);
753 FillRect( hdc
, &rc
, GetSysColorBrush(COLOR_SCROLLBAR
) );
754 rc
.left
= max( rc
.left
, rc
.right
- GetSystemMetrics(SM_CXVSCROLL
) - 1 );
755 rc
.top
= max( rc
.top
, rc
.bottom
- GetSystemMetrics(SM_CYHSCROLL
) - 1 );
756 DrawFrameControl( hdc
, &rc
, DFC_SCROLL
, DFCS_SCROLLSIZEGRIP
);
760 /***********************************************************************
761 * SCROLL_RefreshScrollBar
763 * Repaint the scroll bar interior after a SetScrollRange() or
764 * SetScrollPos() call.
766 static void SCROLL_RefreshScrollBar( HWND hwnd
, INT nBar
,
767 BOOL arrows
, BOOL interior
)
769 HDC hdc
= GetDCEx( hwnd
, 0,
770 DCX_CACHE
| ((nBar
== SB_CTL
) ? 0 : DCX_WINDOW
) );
773 SCROLL_DrawScrollBar( hwnd
, hdc
, nBar
, arrows
, interior
);
774 ReleaseDC( hwnd
, hdc
);
778 /***********************************************************************
779 * SCROLL_HandleKbdEvent
781 * Handle a keyboard event (only for SB_CTL scrollbars with focus).
784 * hwnd [I] Handle of window with scrollbar(s)
785 * wParam [I] Variable input including enable state
786 * lParam [I] Variable input including input point
788 static void SCROLL_HandleKbdEvent(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
790 TRACE("hwnd=%p wParam=%ld lParam=%ld\n", hwnd
, wParam
, lParam
);
792 /* hide caret on first KEYDOWN to prevent flicker */
793 if ((lParam
& PFD_DOUBLEBUFFER_DONTCARE
) == 0)
798 case VK_PRIOR
: wParam
= SB_PAGEUP
; break;
799 case VK_NEXT
: wParam
= SB_PAGEDOWN
; break;
800 case VK_HOME
: wParam
= SB_TOP
; break;
801 case VK_END
: wParam
= SB_BOTTOM
; break;
802 case VK_UP
: wParam
= SB_LINEUP
; break;
803 case VK_DOWN
: wParam
= SB_LINEDOWN
; break;
804 case VK_LEFT
: wParam
= SB_LINEUP
; break;
805 case VK_RIGHT
: wParam
= SB_LINEDOWN
; break;
808 SendMessageW(GetParent(hwnd
),
809 ((GetWindowLongW( hwnd
, GWL_STYLE
) & SBS_VERT
) ?
810 WM_VSCROLL
: WM_HSCROLL
), wParam
, (LPARAM
)hwnd
);
814 /***********************************************************************
815 * SCROLL_HandleScrollEvent
817 * Handle a mouse or timer event for the scrollbar.
818 * 'pt' is the location of the mouse event in client (for SB_CTL) or
819 * windows coordinates.
821 static void SCROLL_HandleScrollEvent( HWND hwnd
, INT nBar
, UINT msg
, POINT pt
)
823 /* Previous mouse position for timer events */
825 /* Thumb position when tracking started. */
826 static UINT trackThumbPos
;
827 /* Position in the scroll-bar of the last button-down event. */
828 static INT lastClickPos
;
829 /* Position in the scroll-bar of the last mouse event. */
830 static INT lastMousePos
;
832 enum SCROLL_HITTEST hittest
;
833 HWND hwndOwner
, hwndCtl
;
835 INT arrowSize
, thumbSize
, thumbPos
;
839 SCROLLBAR_INFO
*infoPtr
= SCROLL_GetInternalInfo( hwnd
, nBar
, FALSE
);
840 if (!infoPtr
) return;
841 if ((SCROLL_trackHitTest
== SCROLL_NOWHERE
) && (msg
!= WM_LBUTTONDOWN
))
844 if (nBar
== SB_CTL
&& (GetWindowLongW( hwnd
, GWL_STYLE
) & (SBS_SIZEGRIP
| SBS_SIZEBOX
)))
848 case WM_LBUTTONDOWN
: /* Initialise mouse tracking */
849 HideCaret(hwnd
); /* hide caret while holding down LBUTTON */
852 SCROLL_trackHitTest
= hittest
= SCROLL_THUMB
;
855 GetClientRect(GetParent(GetParent(hwnd
)),&rect
);
860 SCROLL_trackHitTest
= hittest
= SCROLL_NOWHERE
;
861 if (hwnd
==GetFocus()) ShowCaret(hwnd
);
870 hdc
= GetDCEx( hwnd
, 0, DCX_CACHE
| ((nBar
== SB_CTL
) ? 0 : DCX_WINDOW
));
871 vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
872 &arrowSize
, &thumbSize
, &thumbPos
);
873 hwndOwner
= (nBar
== SB_CTL
) ? GetParent(hwnd
) : hwnd
;
874 hwndCtl
= (nBar
== SB_CTL
) ? hwnd
: 0;
878 case WM_LBUTTONDOWN
: /* Initialise mouse tracking */
879 HideCaret(hwnd
); /* hide caret while holding down LBUTTON */
880 SCROLL_trackVertical
= vertical
;
881 SCROLL_trackHitTest
= hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, FALSE
);
882 lastClickPos
= vertical
? (pt
.y
- rect
.top
) : (pt
.x
- rect
.left
);
883 lastMousePos
= lastClickPos
;
884 trackThumbPos
= thumbPos
;
886 if (nBar
== SB_CTL
&& (GetWindowLongW(hwnd
, GWL_STYLE
) & WS_TABSTOP
)) SetFocus( hwnd
);
891 hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, TRUE
);
896 hittest
= SCROLL_NOWHERE
;
898 /* if scrollbar has focus, show back caret */
899 if (hwnd
==GetFocus()) ShowCaret(hwnd
);
904 hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, FALSE
);
908 return; /* Should never happen */
911 TRACE("Event: hwnd=%p bar=%d msg=%s pt=%d,%d hit=%d\n",
912 hwnd
, nBar
, SPY_GetMsgName(msg
,hwnd
), pt
.x
, pt
.y
, hittest
);
914 switch(SCROLL_trackHitTest
)
916 case SCROLL_NOWHERE
: /* No tracking in progress */
919 case SCROLL_TOP_ARROW
:
920 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
921 (hittest
== SCROLL_trackHitTest
), FALSE
);
922 if (hittest
== SCROLL_trackHitTest
)
924 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
926 SendMessageW( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
927 SB_LINEUP
, (LPARAM
)hwndCtl
);
930 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
931 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
, NULL
);
933 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
936 case SCROLL_TOP_RECT
:
937 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
938 thumbPos
, infoPtr
->flags
, vertical
,
939 (hittest
== SCROLL_trackHitTest
), FALSE
);
940 if (hittest
== SCROLL_trackHitTest
)
942 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
944 SendMessageW( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
945 SB_PAGEUP
, (LPARAM
)hwndCtl
);
947 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
948 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
, NULL
);
950 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
954 if (msg
== WM_LBUTTONDOWN
)
956 SCROLL_TrackingWin
= hwnd
;
957 SCROLL_TrackingBar
= nBar
;
958 SCROLL_TrackingPos
= trackThumbPos
+ lastMousePos
- lastClickPos
;
959 SCROLL_TrackingVal
= SCROLL_GetThumbVal( infoPtr
, &rect
,
961 SCROLL_TrackingPos
);
962 if (!SCROLL_MovingThumb
)
963 SCROLL_DrawMovingThumb(hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
965 else if (msg
== WM_LBUTTONUP
)
967 if (SCROLL_MovingThumb
)
968 SCROLL_DrawMovingThumb(hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
970 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
971 thumbPos
, infoPtr
->flags
, vertical
,
974 else /* WM_MOUSEMOVE */
978 if (!SCROLL_PtInRectEx( &rect
, pt
, vertical
)) pos
= lastClickPos
;
981 pt
= SCROLL_ClipPos( &rect
, pt
);
982 pos
= vertical
? (pt
.y
- rect
.top
) : (pt
.x
- rect
.left
);
984 if ( (pos
!= lastMousePos
) || (!SCROLL_MovingThumb
) )
986 if (SCROLL_MovingThumb
)
987 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
,
988 arrowSize
, thumbSize
);
990 SCROLL_TrackingPos
= trackThumbPos
+ pos
- lastClickPos
;
991 SCROLL_TrackingVal
= SCROLL_GetThumbVal( infoPtr
, &rect
,
993 SCROLL_TrackingPos
);
994 SendMessageW( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
995 MAKEWPARAM( SB_THUMBTRACK
, SCROLL_TrackingVal
),
997 if (!SCROLL_MovingThumb
)
998 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
,
999 arrowSize
, thumbSize
);
1004 case SCROLL_BOTTOM_RECT
:
1005 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
1006 thumbPos
, infoPtr
->flags
, vertical
,
1007 FALSE
, (hittest
== SCROLL_trackHitTest
) );
1008 if (hittest
== SCROLL_trackHitTest
)
1010 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
1012 SendMessageW( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1013 SB_PAGEDOWN
, (LPARAM
)hwndCtl
);
1015 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
1016 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
, NULL
);
1018 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
1021 case SCROLL_BOTTOM_ARROW
:
1022 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
1023 FALSE
, (hittest
== SCROLL_trackHitTest
) );
1024 if (hittest
== SCROLL_trackHitTest
)
1026 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
1028 SendMessageW( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1029 SB_LINEDOWN
, (LPARAM
)hwndCtl
);
1032 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
1033 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
, NULL
);
1035 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
1039 if (msg
== WM_LBUTTONDOWN
)
1042 if (hittest
== SCROLL_THUMB
)
1044 UINT val
= SCROLL_GetThumbVal( infoPtr
, &rect
, vertical
,
1045 trackThumbPos
+ lastMousePos
- lastClickPos
);
1046 SendMessageW( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1047 MAKEWPARAM( SB_THUMBTRACK
, val
), (LPARAM
)hwndCtl
);
1051 if (msg
== WM_LBUTTONUP
)
1053 hittest
= SCROLL_trackHitTest
;
1054 SCROLL_trackHitTest
= SCROLL_NOWHERE
; /* Terminate tracking */
1056 if (hittest
== SCROLL_THUMB
)
1058 UINT val
= SCROLL_GetThumbVal( infoPtr
, &rect
, vertical
,
1059 trackThumbPos
+ lastMousePos
- lastClickPos
);
1060 SendMessageW( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1061 MAKEWPARAM( SB_THUMBPOSITION
, val
), (LPARAM
)hwndCtl
);
1063 /* SB_ENDSCROLL doesn't report thumb position */
1064 SendMessageW( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1065 SB_ENDSCROLL
, (LPARAM
)hwndCtl
);
1067 /* Terminate tracking */
1068 SCROLL_TrackingWin
= 0;
1071 ReleaseDC( hwnd
, hdc
);
1075 /***********************************************************************
1076 * SCROLL_TrackScrollBar
1078 * Track a mouse button press on a scroll-bar.
1079 * pt is in screen-coordinates for non-client scroll bars.
1081 void SCROLL_TrackScrollBar( HWND hwnd
, INT scrollbar
, POINT pt
)
1085 if (scrollbar
!= SB_CTL
)
1088 WIN_GetRectangles( hwnd
, COORDS_CLIENT
, &rect
, NULL
);
1089 ScreenToClient( hwnd
, &pt
);
1094 SCROLL_HandleScrollEvent( hwnd
, scrollbar
, WM_LBUTTONDOWN
, pt
);
1098 if (!GetMessageW( &msg
, 0, 0, 0 )) break;
1099 if (CallMsgFilterW( &msg
, MSGF_SCROLLBAR
)) continue;
1100 if (msg
.message
== WM_LBUTTONUP
||
1101 msg
.message
== WM_MOUSEMOVE
||
1102 (msg
.message
== WM_SYSTIMER
&& msg
.wParam
== SCROLL_TIMER
))
1104 pt
.x
= (short)LOWORD(msg
.lParam
);
1105 pt
.y
= (short)HIWORD(msg
.lParam
);
1106 SCROLL_HandleScrollEvent( hwnd
, scrollbar
, msg
.message
, pt
);
1110 TranslateMessage( &msg
);
1111 DispatchMessageW( &msg
);
1113 if (!IsWindow( hwnd
))
1118 } while (msg
.message
!= WM_LBUTTONUP
&& GetCapture() == hwnd
);
1122 /***********************************************************************
1123 * SCROLL_CreateScrollBar
1125 * Create a scroll bar
1128 * hwnd [I] Handle of window with scrollbar(s)
1129 * lpCreate [I] The style and place of the scroll bar
1131 static void SCROLL_CreateScrollBar(HWND hwnd
, LPCREATESTRUCTW lpCreate
)
1133 LPSCROLLBAR_INFO info
= SCROLL_GetInternalInfo(hwnd
, SB_CTL
, TRUE
);
1136 TRACE("hwnd=%p lpCreate=%p\n", hwnd
, lpCreate
);
1138 if (lpCreate
->style
& WS_DISABLED
)
1140 info
->flags
= ESB_DISABLE_BOTH
;
1141 TRACE("Created WS_DISABLED scrollbar\n");
1145 if (lpCreate
->style
& (SBS_SIZEGRIP
| SBS_SIZEBOX
))
1147 if (lpCreate
->style
& SBS_SIZEBOXTOPLEFTALIGN
)
1148 MoveWindow( hwnd
, lpCreate
->x
, lpCreate
->y
, GetSystemMetrics(SM_CXVSCROLL
)+1,
1149 GetSystemMetrics(SM_CYHSCROLL
)+1, FALSE
);
1150 else if(lpCreate
->style
& SBS_SIZEBOXBOTTOMRIGHTALIGN
)
1151 MoveWindow( hwnd
, lpCreate
->x
+lpCreate
->cx
-GetSystemMetrics(SM_CXVSCROLL
)-1,
1152 lpCreate
->y
+lpCreate
->cy
-GetSystemMetrics(SM_CYHSCROLL
)-1,
1153 GetSystemMetrics(SM_CXVSCROLL
)+1,
1154 GetSystemMetrics(SM_CYHSCROLL
)+1, FALSE
);
1156 else if (lpCreate
->style
& SBS_VERT
)
1158 if (lpCreate
->style
& SBS_LEFTALIGN
)
1159 MoveWindow( hwnd
, lpCreate
->x
, lpCreate
->y
,
1160 GetSystemMetrics(SM_CXVSCROLL
)+1, lpCreate
->cy
, FALSE
);
1161 else if (lpCreate
->style
& SBS_RIGHTALIGN
)
1163 lpCreate
->x
+lpCreate
->cx
-GetSystemMetrics(SM_CXVSCROLL
)-1,
1165 GetSystemMetrics(SM_CXVSCROLL
)+1, lpCreate
->cy
, FALSE
);
1169 if (lpCreate
->style
& SBS_TOPALIGN
)
1170 MoveWindow( hwnd
, lpCreate
->x
, lpCreate
->y
,
1171 lpCreate
->cx
, GetSystemMetrics(SM_CYHSCROLL
)+1, FALSE
);
1172 else if (lpCreate
->style
& SBS_BOTTOMALIGN
)
1175 lpCreate
->y
+lpCreate
->cy
-GetSystemMetrics(SM_CYHSCROLL
)-1,
1176 lpCreate
->cx
, GetSystemMetrics(SM_CYHSCROLL
)+1, FALSE
);
1181 /*************************************************************************
1182 * SCROLL_GetScrollInfo
1184 * Internal helper for the API function
1187 * hwnd [I] Handle of window with scrollbar(s)
1188 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1189 * info [IO] fMask specifies which values to retrieve
1192 * FALSE if requested field not filled (f.i. scroll bar does not exist)
1194 static BOOL
SCROLL_GetScrollInfo(HWND hwnd
, INT nBar
, LPSCROLLINFO info
)
1196 LPSCROLLBAR_INFO infoPtr
;
1198 /* handle invalid data structure */
1199 if (!SCROLL_ScrollInfoValid(info
)
1200 || !(infoPtr
= SCROLL_GetInternalInfo(hwnd
, nBar
, FALSE
)))
1203 /* fill in the desired scroll info structure */
1204 if (info
->fMask
& SIF_PAGE
) info
->nPage
= infoPtr
->page
;
1205 if (info
->fMask
& SIF_POS
) info
->nPos
= infoPtr
->curVal
;
1206 if ((info
->fMask
& SIF_TRACKPOS
) && (info
->cbSize
== sizeof(*info
)))
1207 info
->nTrackPos
= (SCROLL_TrackingWin
== WIN_GetFullHandle(hwnd
)) ? SCROLL_TrackingVal
: infoPtr
->curVal
;
1208 if (info
->fMask
& SIF_RANGE
)
1210 info
->nMin
= infoPtr
->minVal
;
1211 info
->nMax
= infoPtr
->maxVal
;
1214 TRACE("cbSize %02x fMask %04x nMin %d nMax %d nPage %u nPos %d nTrackPos %d\n",
1215 info
->cbSize
, info
->fMask
, info
->nMin
, info
->nMax
, info
->nPage
,
1216 info
->nPos
, info
->nTrackPos
);
1218 return (info
->fMask
& SIF_ALL
) != 0;
1222 /*************************************************************************
1223 * SCROLL_GetScrollBarInfo
1225 * Internal helper for the API function
1228 * hwnd [I] Handle of window with scrollbar(s)
1229 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1230 * info [IO] cbSize specifies the size of the structure
1235 static BOOL
SCROLL_GetScrollBarInfo(HWND hwnd
, LONG idObject
, LPSCROLLBARINFO info
)
1237 LPSCROLLBAR_INFO infoPtr
;
1240 DWORD style
= GetWindowLongW(hwnd
, GWL_STYLE
);
1246 case OBJID_CLIENT
: nBar
= SB_CTL
; break;
1247 case OBJID_HSCROLL
: nBar
= SB_HORZ
; break;
1248 case OBJID_VSCROLL
: nBar
= SB_VERT
; break;
1249 default: return FALSE
;
1252 /* handle invalid data structure */
1253 if (info
->cbSize
!= sizeof(*info
))
1256 SCROLL_GetScrollBarRect(hwnd
, nBar
, &info
->rcScrollBar
, &nDummy
,
1257 &info
->dxyLineButton
, &info
->xyThumbTop
);
1258 /* rcScrollBar needs to be in screen coordinates */
1259 GetWindowRect(hwnd
, &rect
);
1260 OffsetRect(&info
->rcScrollBar
, rect
.left
, rect
.top
);
1262 info
->xyThumbBottom
= info
->xyThumbTop
+ info
->dxyLineButton
;
1264 infoPtr
= SCROLL_GetInternalInfo(hwnd
, nBar
, TRUE
);
1268 /* Scroll bar state */
1269 info
->rgstate
[0] = 0;
1270 if ((nBar
== SB_HORZ
&& !(style
& WS_HSCROLL
))
1271 || (nBar
== SB_VERT
&& !(style
& WS_VSCROLL
)))
1272 info
->rgstate
[0] |= STATE_SYSTEM_INVISIBLE
;
1273 if (infoPtr
->minVal
>= infoPtr
->maxVal
- max(infoPtr
->page
- 1, 0))
1275 if (!(info
->rgstate
[0] & STATE_SYSTEM_INVISIBLE
))
1276 info
->rgstate
[0] |= STATE_SYSTEM_UNAVAILABLE
;
1278 info
->rgstate
[0] |= STATE_SYSTEM_OFFSCREEN
;
1280 if (nBar
== SB_CTL
&& !IsWindowEnabled(hwnd
))
1281 info
->rgstate
[0] |= STATE_SYSTEM_UNAVAILABLE
;
1283 pressed
= ((nBar
== SB_VERT
) == SCROLL_trackVertical
&& GetCapture() == hwnd
);
1285 /* Top/left arrow button state. MSDN says top/right, but I don't believe it */
1286 info
->rgstate
[1] = 0;
1287 if (pressed
&& SCROLL_trackHitTest
== SCROLL_TOP_ARROW
)
1288 info
->rgstate
[1] |= STATE_SYSTEM_PRESSED
;
1289 if (infoPtr
->flags
& ESB_DISABLE_LTUP
)
1290 info
->rgstate
[1] |= STATE_SYSTEM_UNAVAILABLE
;
1292 /* Page up/left region state. MSDN says up/right, but I don't believe it */
1293 info
->rgstate
[2] = 0;
1294 if (infoPtr
->curVal
== infoPtr
->minVal
)
1295 info
->rgstate
[2] |= STATE_SYSTEM_INVISIBLE
;
1296 if (pressed
&& SCROLL_trackHitTest
== SCROLL_TOP_RECT
)
1297 info
->rgstate
[2] |= STATE_SYSTEM_PRESSED
;
1300 info
->rgstate
[3] = 0;
1301 if (pressed
&& SCROLL_trackHitTest
== SCROLL_THUMB
)
1302 info
->rgstate
[3] |= STATE_SYSTEM_PRESSED
;
1304 /* Page down/right region state. MSDN says down/left, but I don't believe it */
1305 info
->rgstate
[4] = 0;
1306 if (infoPtr
->curVal
>= infoPtr
->maxVal
- 1)
1307 info
->rgstate
[4] |= STATE_SYSTEM_INVISIBLE
;
1308 if (pressed
&& SCROLL_trackHitTest
== SCROLL_BOTTOM_RECT
)
1309 info
->rgstate
[4] |= STATE_SYSTEM_PRESSED
;
1311 /* Bottom/right arrow button state. MSDN says bottom/left, but I don't believe it */
1312 info
->rgstate
[5] = 0;
1313 if (pressed
&& SCROLL_trackHitTest
== SCROLL_BOTTOM_ARROW
)
1314 info
->rgstate
[5] |= STATE_SYSTEM_PRESSED
;
1315 if (infoPtr
->flags
& ESB_DISABLE_RTDN
)
1316 info
->rgstate
[5] |= STATE_SYSTEM_UNAVAILABLE
;
1322 /*************************************************************************
1323 * SCROLL_GetScrollPos
1325 * Internal helper for the API function
1328 * hwnd [I] Handle of window with scrollbar(s)
1329 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1331 static INT
SCROLL_GetScrollPos(HWND hwnd
, INT nBar
)
1333 LPSCROLLBAR_INFO infoPtr
= SCROLL_GetInternalInfo(hwnd
, nBar
, FALSE
);
1334 return infoPtr
? infoPtr
->curVal
: 0;
1338 /*************************************************************************
1339 * SCROLL_GetScrollRange
1341 * Internal helper for the API function
1344 * hwnd [I] Handle of window with scrollbar(s)
1345 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1346 * lpMin [O] Where to store minimum value
1347 * lpMax [O] Where to store maximum value
1353 static BOOL
SCROLL_GetScrollRange(HWND hwnd
, INT nBar
, LPINT lpMin
, LPINT lpMax
)
1355 LPSCROLLBAR_INFO infoPtr
= SCROLL_GetInternalInfo(hwnd
, nBar
, FALSE
);
1357 if (lpMin
) *lpMin
= infoPtr
? infoPtr
->minVal
: 0;
1358 if (lpMax
) *lpMax
= infoPtr
? infoPtr
->maxVal
: 0;
1364 /*************************************************************************
1365 * SCROLL_SetScrollRange
1368 * hwnd [I] Handle of window with scrollbar(s)
1369 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1370 * lpMin [I] Minimum value
1371 * lpMax [I] Maximum value
1374 static BOOL
SCROLL_SetScrollRange(HWND hwnd
, INT nBar
, INT minVal
, INT maxVal
)
1376 LPSCROLLBAR_INFO infoPtr
= SCROLL_GetInternalInfo(hwnd
, nBar
, FALSE
);
1378 TRACE("hwnd=%p nBar=%d min=%d max=%d\n", hwnd
, nBar
, minVal
, maxVal
);
1382 infoPtr
->minVal
= minVal
;
1383 infoPtr
->maxVal
= maxVal
;
1389 /***********************************************************************
1390 * ScrollBarWndProc_common
1392 LRESULT
ScrollBarWndProc_common( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
1394 if (!IsWindow( hwnd
)) return 0;
1399 SCROLL_CreateScrollBar(hwnd
, (LPCREATESTRUCTW
)lParam
);
1404 SCROLLBAR_INFO
*infoPtr
;
1405 if ((infoPtr
= SCROLL_GetInternalInfo( hwnd
, SB_CTL
, FALSE
)))
1407 infoPtr
->flags
= wParam
? ESB_ENABLE_BOTH
: ESB_DISABLE_BOTH
;
1408 SCROLL_RefreshScrollBar(hwnd
, SB_CTL
, TRUE
, TRUE
);
1413 case WM_LBUTTONDBLCLK
:
1414 case WM_LBUTTONDOWN
:
1415 if (GetWindowLongW( hwnd
, GWL_STYLE
) & SBS_SIZEGRIP
)
1417 SendMessageW( GetParent(hwnd
), WM_SYSCOMMAND
,
1418 SC_SIZE
+ ((GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_LAYOUTRTL
) ?
1419 WMSZ_BOTTOMLEFT
: WMSZ_BOTTOMRIGHT
), lParam
);
1424 pt
.x
= (short)LOWORD(lParam
);
1425 pt
.y
= (short)HIWORD(lParam
);
1426 SCROLL_TrackScrollBar( hwnd
, SB_CTL
, pt
);
1434 pt
.x
= (short)LOWORD(lParam
);
1435 pt
.y
= (short)HIWORD(lParam
);
1436 SCROLL_HandleScrollEvent( hwnd
, SB_CTL
, message
, pt
);
1441 SCROLL_HandleKbdEvent(hwnd
, wParam
, lParam
);
1450 /* Create a caret when a ScrollBar get focus */
1452 int arrowSize
, thumbSize
, thumbPos
, vertical
;
1453 vertical
= SCROLL_GetScrollBarRect( hwnd
, SB_CTL
, &rect
,
1454 &arrowSize
, &thumbSize
, &thumbPos
);
1457 CreateCaret(hwnd
, (HBITMAP
)1, thumbSize
-2, rect
.bottom
-rect
.top
-2);
1458 SetCaretPos(thumbPos
+1, rect
.top
+1);
1462 CreateCaret(hwnd
, (HBITMAP
)1, rect
.right
-rect
.left
-2,thumbSize
-2);
1463 SetCaretPos(rect
.top
+1, thumbPos
+1);
1472 int arrowSize
, thumbSize
, thumbPos
, vertical
;
1473 vertical
= SCROLL_GetScrollBarRect( hwnd
, SB_CTL
, &rect
,&arrowSize
, &thumbSize
, &thumbPos
);
1475 rect
.left
=thumbPos
+1;
1476 rect
.right
=rect
.left
+thumbSize
;
1480 rect
.top
=thumbPos
+1;
1481 rect
.bottom
=rect
.top
+thumbSize
;
1484 InvalidateRect(hwnd
,&rect
,0);
1493 return DLGC_WANTARROWS
; /* Windows returns this value */
1498 HDC hdc
= wParam
? (HDC
)wParam
: BeginPaint(hwnd
, &ps
);
1499 if (GetWindowLongW( hwnd
, GWL_STYLE
) & SBS_SIZEGRIP
)
1501 SCROLL_DrawSizeGrip( hwnd
, hdc
);
1503 else if (GetWindowLongW( hwnd
, GWL_STYLE
) & SBS_SIZEBOX
)
1506 GetClientRect( hwnd
, &rc
);
1507 FillRect( hdc
, &rc
, GetSysColorBrush(COLOR_SCROLLBAR
) );
1510 SCROLL_DrawScrollBar( hwnd
, hdc
, SB_CTL
, TRUE
, TRUE
);
1511 if (!wParam
) EndPaint(hwnd
, &ps
);
1516 if (GetWindowLongW( hwnd
, GWL_STYLE
) & SBS_SIZEGRIP
)
1518 ULONG_PTR cursor
= (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_LAYOUTRTL
) ? IDC_SIZENESW
: IDC_SIZENWSE
;
1519 return (LRESULT
)SetCursor( LoadCursorA( 0, (LPSTR
)cursor
));
1521 return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1524 return SetScrollPos( hwnd
, SB_CTL
, wParam
, (BOOL
)lParam
);
1527 return SCROLL_GetScrollPos(hwnd
, SB_CTL
);
1529 case SBM_SETRANGEREDRAW
:
1532 INT oldPos
= SCROLL_GetScrollPos( hwnd
, SB_CTL
);
1533 SCROLL_SetScrollRange( hwnd
, SB_CTL
, wParam
, lParam
);
1534 if (message
== SBM_SETRANGEREDRAW
)
1535 SCROLL_RefreshScrollBar( hwnd
, SB_CTL
, TRUE
, TRUE
);
1536 if (oldPos
!= SCROLL_GetScrollPos( hwnd
, SB_CTL
)) return oldPos
;
1541 return SCROLL_GetScrollRange(hwnd
, SB_CTL
, (LPINT
)wParam
, (LPINT
)lParam
);
1543 case SBM_ENABLE_ARROWS
:
1544 return EnableScrollBar( hwnd
, SB_CTL
, wParam
);
1546 case SBM_SETSCROLLINFO
:
1547 return SCROLL_SetScrollInfo( hwnd
, SB_CTL
, (SCROLLINFO
*)lParam
, wParam
);
1549 case SBM_GETSCROLLINFO
:
1550 return SCROLL_GetScrollInfo(hwnd
, SB_CTL
, (SCROLLINFO
*)lParam
);
1552 case SBM_GETSCROLLBARINFO
:
1553 return SCROLL_GetScrollBarInfo(hwnd
, OBJID_CLIENT
, (SCROLLBARINFO
*)lParam
);
1562 ERR("unknown Win32 msg %04x wp=%08lx lp=%08lx\n",
1563 message
, wParam
, lParam
);
1567 if (message
>= WM_USER
)
1568 WARN("unknown msg %04x wp=%04lx lp=%08lx\n",
1569 message
, wParam
, lParam
);
1571 return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1573 return DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1579 /*************************************************************************
1580 * SetScrollInfo (USER32.@)
1582 * SetScrollInfo can be used to set the position, upper bound,
1583 * lower bound, and page size of a scrollbar control.
1586 * hwnd [I] Handle of window with scrollbar(s)
1587 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1588 * info [I] Specifies what to change and new values
1589 * bRedraw [I] Should scrollbar be redrawn afterwards?
1592 * Scrollbar position
1595 * For 100 lines of text to be displayed in a window of 25 lines,
1596 * one would for instance use info->nMin=0, info->nMax=75
1597 * (corresponding to the 76 different positions of the window on
1598 * the text), and info->nPage=25.
1600 INT WINAPI DECLSPEC_HOTPATCH
SetScrollInfo(HWND hwnd
, INT nBar
, const SCROLLINFO
*info
, BOOL bRedraw
)
1602 TRACE("hwnd=%p nBar=%d info=%p, bRedraw=%d\n", hwnd
, nBar
, info
, bRedraw
);
1604 /* Refer SB_CTL requests to the window */
1606 return SendMessageW(hwnd
, SBM_SETSCROLLINFO
, bRedraw
, (LPARAM
)info
);
1608 return SCROLL_SetScrollInfo( hwnd
, nBar
, info
, bRedraw
);
1611 static INT
SCROLL_SetScrollInfo( HWND hwnd
, INT nBar
, LPCSCROLLINFO info
, BOOL bRedraw
)
1613 /* Update the scrollbar state and set action flags according to
1614 * what has to be done graphics wise. */
1616 SCROLLBAR_INFO
*infoPtr
;
1620 /* handle invalid data structure */
1621 if (!SCROLL_ScrollInfoValid(info
)
1622 || !(infoPtr
= SCROLL_GetInternalInfo(hwnd
, nBar
, TRUE
)))
1625 if (TRACE_ON(scroll
))
1627 TRACE("hwnd=%p bar=%d", hwnd
, nBar
);
1628 if (info
->fMask
& SIF_PAGE
) TRACE( " page=%d", info
->nPage
);
1629 if (info
->fMask
& SIF_POS
) TRACE( " pos=%d", info
->nPos
);
1630 if (info
->fMask
& SIF_RANGE
) TRACE( " min=%d max=%d", info
->nMin
, info
->nMax
);
1634 /* Set the page size */
1636 if (info
->fMask
& SIF_PAGE
)
1638 if( infoPtr
->page
!= info
->nPage
)
1640 infoPtr
->page
= info
->nPage
;
1641 action
|= SA_SSI_REFRESH
;
1645 /* Set the scroll pos */
1647 if (info
->fMask
& SIF_POS
)
1649 if( infoPtr
->curVal
!= info
->nPos
)
1651 infoPtr
->curVal
= info
->nPos
;
1652 action
|= SA_SSI_REFRESH
;
1656 /* Set the scroll range */
1658 if (info
->fMask
& SIF_RANGE
)
1660 /* Invalid range -> range is set to (0,0) */
1661 if ((info
->nMin
> info
->nMax
) ||
1662 ((UINT
)(info
->nMax
- info
->nMin
) >= 0x80000000))
1664 action
|= SA_SSI_REFRESH
;
1665 infoPtr
->minVal
= 0;
1666 infoPtr
->maxVal
= 0;
1670 if( infoPtr
->minVal
!= info
->nMin
||
1671 infoPtr
->maxVal
!= info
->nMax
)
1673 action
|= SA_SSI_REFRESH
;
1674 infoPtr
->minVal
= info
->nMin
;
1675 infoPtr
->maxVal
= info
->nMax
;
1680 /* Make sure the page size is valid */
1681 if (infoPtr
->page
< 0) infoPtr
->page
= 0;
1682 else if (infoPtr
->page
> infoPtr
->maxVal
- infoPtr
->minVal
+ 1 )
1683 infoPtr
->page
= infoPtr
->maxVal
- infoPtr
->minVal
+ 1;
1685 /* Make sure the pos is inside the range */
1687 if (infoPtr
->curVal
< infoPtr
->minVal
)
1688 infoPtr
->curVal
= infoPtr
->minVal
;
1689 else if (infoPtr
->curVal
> infoPtr
->maxVal
- max( infoPtr
->page
-1, 0 ))
1690 infoPtr
->curVal
= infoPtr
->maxVal
- max( infoPtr
->page
-1, 0 );
1692 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1693 infoPtr
->page
, infoPtr
->curVal
,
1694 infoPtr
->minVal
, infoPtr
->maxVal
);
1696 /* don't change the scrollbar state if SetScrollInfo
1697 * is just called with SIF_DISABLENOSCROLL
1699 if(!(info
->fMask
& SIF_ALL
)) goto done
;
1701 /* Check if the scrollbar should be hidden or disabled */
1703 if (info
->fMask
& (SIF_RANGE
| SIF_PAGE
| SIF_DISABLENOSCROLL
))
1705 new_flags
= infoPtr
->flags
;
1706 if (infoPtr
->minVal
>= infoPtr
->maxVal
- max( infoPtr
->page
-1, 0 ))
1708 /* Hide or disable scroll-bar */
1709 if (info
->fMask
& SIF_DISABLENOSCROLL
)
1711 new_flags
= ESB_DISABLE_BOTH
;
1712 action
|= SA_SSI_REFRESH
;
1714 else if ((nBar
!= SB_CTL
) && (action
& SA_SSI_REFRESH
))
1716 action
= SA_SSI_HIDE
;
1719 else /* Show and enable scroll-bar only if no page only changed. */
1720 if (info
->fMask
!= SIF_PAGE
)
1722 new_flags
= ESB_ENABLE_BOTH
;
1723 if ((nBar
!= SB_CTL
) && ( (action
& SA_SSI_REFRESH
) ))
1724 action
|= SA_SSI_SHOW
;
1727 if (infoPtr
->flags
!= new_flags
) /* check arrow flags */
1729 infoPtr
->flags
= new_flags
;
1730 action
|= SA_SSI_REPAINT_ARROWS
;
1735 if( action
& SA_SSI_HIDE
)
1736 SCROLL_ShowScrollBar( hwnd
, nBar
, FALSE
, FALSE
);
1739 if( action
& SA_SSI_SHOW
)
1740 if( SCROLL_ShowScrollBar( hwnd
, nBar
, TRUE
, TRUE
) )
1741 return infoPtr
->curVal
; /* SetWindowPos() already did the painting */
1744 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, TRUE
);
1745 else if( action
& SA_SSI_REPAINT_ARROWS
)
1746 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, FALSE
);
1749 /* Return current position */
1750 return infoPtr
->curVal
;
1754 /*************************************************************************
1755 * GetScrollInfo (USER32.@)
1757 * GetScrollInfo can be used to retrieve the position, upper bound,
1758 * lower bound, and page size of a scrollbar control.
1761 * hwnd [I] Handle of window with scrollbar(s)
1762 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1763 * info [IO] fMask specifies which values to retrieve
1766 * TRUE if SCROLLINFO is filled
1767 * ( if nBar is SB_CTL, GetScrollInfo returns TRUE even if nothing
1770 BOOL WINAPI DECLSPEC_HOTPATCH
GetScrollInfo(HWND hwnd
, INT nBar
, LPSCROLLINFO info
)
1772 TRACE("hwnd=%p nBar=%d info=%p\n", hwnd
, nBar
, info
);
1774 /* Refer SB_CTL requests to the window */
1777 SendMessageW(hwnd
, SBM_GETSCROLLINFO
, 0, (LPARAM
)info
);
1780 return SCROLL_GetScrollInfo(hwnd
, nBar
, info
);
1784 /*************************************************************************
1785 * GetScrollBarInfo (USER32.@)
1787 * GetScrollBarInfo can be used to retrieve information about a scrollbar
1791 * hwnd [I] Handle of window with scrollbar(s)
1792 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1793 * info [IO] cbSize specifies the size of SCROLLBARINFO
1798 BOOL WINAPI
GetScrollBarInfo(HWND hwnd
, LONG idObject
, LPSCROLLBARINFO info
)
1800 TRACE("hwnd=%p idObject=%d info=%p\n", hwnd
, idObject
, info
);
1802 /* Refer OBJID_CLIENT requests to the window */
1803 if (idObject
== OBJID_CLIENT
)
1804 return SendMessageW(hwnd
, SBM_GETSCROLLBARINFO
, 0, (LPARAM
)info
);
1806 return SCROLL_GetScrollBarInfo(hwnd
, idObject
, info
);
1810 /*************************************************************************
1811 * SetScrollPos (USER32.@)
1813 * Sets the current position of the scroll thumb.
1816 * hwnd [I] Handle of window with scrollbar(s)
1817 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1818 * nPos [I] New value
1819 * bRedraw [I] Should scrollbar be redrawn afterwards?
1822 * Success: Scrollbar position
1826 * Note the ambiguity when 0 is returned. Use GetLastError
1827 * to make sure there was an error (and to know which one).
1829 INT WINAPI DECLSPEC_HOTPATCH
SetScrollPos( HWND hwnd
, INT nBar
, INT nPos
, BOOL bRedraw
)
1832 SCROLLBAR_INFO
*infoPtr
;
1835 if (!(infoPtr
= SCROLL_GetInternalInfo( hwnd
, nBar
, FALSE
))) return 0;
1836 oldPos
= infoPtr
->curVal
;
1837 info
.cbSize
= sizeof(info
);
1839 info
.fMask
= SIF_POS
;
1840 SetScrollInfo( hwnd
, nBar
, &info
, bRedraw
);
1845 /*************************************************************************
1846 * GetScrollPos (USER32.@)
1848 * Gets the current position of the scroll thumb.
1851 * hwnd [I] Handle of window with scrollbar(s)
1852 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1855 * Success: Current position
1859 * There is ambiguity when 0 is returned. Use GetLastError
1860 * to make sure there was an error (and to know which one).
1862 INT WINAPI DECLSPEC_HOTPATCH
GetScrollPos(HWND hwnd
, INT nBar
)
1864 TRACE("hwnd=%p nBar=%d\n", hwnd
, nBar
);
1866 /* Refer SB_CTL requests to the window */
1868 return SendMessageW(hwnd
, SBM_GETPOS
, 0, 0);
1870 return SCROLL_GetScrollPos(hwnd
, nBar
);
1874 /*************************************************************************
1875 * SetScrollRange (USER32.@)
1876 * The SetScrollRange function sets the minimum and maximum scroll box positions
1877 * If nMinPos and nMaxPos is the same value, the scroll bar will hide
1879 * Sets the range of the scroll bar.
1882 * hwnd [I] Handle of window with scrollbar(s)
1883 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1884 * minVal [I] New minimum value
1885 * maxVal [I] New Maximum value
1886 * bRedraw [I] Should scrollbar be redrawn afterwards?
1892 BOOL WINAPI DECLSPEC_HOTPATCH
SetScrollRange(HWND hwnd
, INT nBar
, INT minVal
, INT maxVal
, BOOL bRedraw
)
1896 TRACE("hwnd=%p nBar=%d min=%d max=%d, bRedraw=%d\n", hwnd
, nBar
, minVal
, maxVal
, bRedraw
);
1898 info
.cbSize
= sizeof(info
);
1899 info
.fMask
= SIF_RANGE
;
1902 SetScrollInfo( hwnd
, nBar
, &info
, bRedraw
);
1907 /*************************************************************************
1908 * GetScrollRange (USER32.@)
1910 * Gets the range of the scroll bar.
1913 * hwnd [I] Handle of window with scrollbar(s)
1914 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1915 * lpMin [O] Where to store minimum value
1916 * lpMax [O] Where to store maximum value
1919 * TRUE if values is filled
1921 BOOL WINAPI DECLSPEC_HOTPATCH
GetScrollRange(HWND hwnd
, INT nBar
, LPINT lpMin
, LPINT lpMax
)
1923 TRACE("hwnd=%p nBar=%d lpMin=%p lpMax=%p\n", hwnd
, nBar
, lpMin
, lpMax
);
1925 /* Refer SB_CTL requests to the window */
1927 SendMessageW(hwnd
, SBM_GETRANGE
, (WPARAM
)lpMin
, (LPARAM
)lpMax
);
1929 SCROLL_GetScrollRange(hwnd
, nBar
, lpMin
, lpMax
);
1935 /*************************************************************************
1936 * SCROLL_ShowScrollBar()
1938 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1940 static BOOL
SCROLL_ShowScrollBar( HWND hwnd
, INT nBar
, BOOL fShowH
, BOOL fShowV
)
1942 ULONG old_style
, set_bits
= 0, clear_bits
= 0;
1944 TRACE("hwnd=%p bar=%d horz=%d, vert=%d\n", hwnd
, nBar
, fShowH
, fShowV
);
1949 ShowWindow( hwnd
, fShowH
? SW_SHOW
: SW_HIDE
);
1954 if (fShowH
) set_bits
|= WS_HSCROLL
;
1955 else clear_bits
|= WS_HSCROLL
;
1956 if( nBar
== SB_HORZ
) break;
1959 if (fShowV
) set_bits
|= WS_VSCROLL
;
1960 else clear_bits
|= WS_VSCROLL
;
1964 return FALSE
; /* Nothing to do! */
1967 old_style
= WIN_SetStyle( hwnd
, set_bits
, clear_bits
);
1968 if ((old_style
& clear_bits
) != 0 || (old_style
& set_bits
) != set_bits
)
1970 /* frame has been changed, let the window redraw itself */
1971 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
1972 | SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
1975 return FALSE
; /* no frame changes */
1979 /*************************************************************************
1980 * ShowScrollBar (USER32.@)
1982 * Shows or hides the scroll bar.
1985 * hwnd [I] Handle of window with scrollbar(s)
1986 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1987 * fShow [I] TRUE = show, FALSE = hide
1993 BOOL WINAPI DECLSPEC_HOTPATCH
ShowScrollBar(HWND hwnd
, INT nBar
, BOOL fShow
)
1998 SCROLL_ShowScrollBar( hwnd
, nBar
, (nBar
== SB_VERT
) ? 0 : fShow
,
1999 (nBar
== SB_HORZ
) ? 0 : fShow
);
2004 /*************************************************************************
2005 * EnableScrollBar (USER32.@)
2007 * Enables or disables the scroll bars.
2009 BOOL WINAPI DECLSPEC_HOTPATCH
EnableScrollBar( HWND hwnd
, UINT nBar
, UINT flags
)
2012 SCROLLBAR_INFO
*infoPtr
;
2014 flags
&= ESB_DISABLE_BOTH
;
2016 if (nBar
== SB_BOTH
)
2018 if (!(infoPtr
= SCROLL_GetInternalInfo( hwnd
, SB_VERT
, TRUE
))) return FALSE
;
2019 if (!(bFineWithMe
= (infoPtr
->flags
== flags
)) )
2021 infoPtr
->flags
= flags
;
2022 SCROLL_RefreshScrollBar( hwnd
, SB_VERT
, TRUE
, TRUE
);
2027 bFineWithMe
= nBar
!= SB_CTL
;
2029 if (!(infoPtr
= SCROLL_GetInternalInfo( hwnd
, nBar
, TRUE
))) return FALSE
;
2030 if (bFineWithMe
&& infoPtr
->flags
== flags
) return FALSE
;
2031 infoPtr
->flags
= flags
;
2033 if (nBar
== SB_CTL
&& (flags
== ESB_DISABLE_BOTH
|| flags
== ESB_ENABLE_BOTH
))
2034 EnableWindow(hwnd
, flags
== ESB_ENABLE_BOTH
);
2036 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, TRUE
);