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
29 #include "wine/debug.h"
30 #include "user_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(scroll
);
34 /* data for a single scroll bar */
37 INT curVal
; /* Current scroll-bar value */
38 INT minVal
; /* Minimum scroll-bar value */
39 INT maxVal
; /* Maximum scroll-bar value */
40 INT page
; /* Page size of scroll bar (Win32) */
41 UINT flags
; /* EnableScrollBar flags */
42 } SCROLLBAR_INFO
, *LPSCROLLBAR_INFO
;
44 /* data for window that has (one or two) scroll bars */
49 } WINSCROLLBAR_INFO
, *LPWINSCROLLBAR_INFO
;
57 #define SCROLLBAR_MAGIC 0x5c6011ba
59 /* Minimum size of the rectangle between the arrows */
60 #define SCROLL_MIN_RECT 4
62 /* Minimum size of the thumb in pixels */
63 #define SCROLL_MIN_THUMB 6
65 /* Overlap between arrows and thumb */
66 #define SCROLL_ARROW_THUMB_OVERLAP 0
68 /* Delay (in ms) before first repetition when holding the button down */
69 #define SCROLL_FIRST_DELAY 200
71 /* Delay (in ms) between scroll repetitions */
72 #define SCROLL_REPEAT_DELAY 50
75 #define SCROLL_TIMER 0
77 /* What to do after SCROLL_SetScrollInfo() */
78 #define SA_SSI_HIDE 0x0001
79 #define SA_SSI_SHOW 0x0002
80 #define SA_SSI_REFRESH 0x0004
81 #define SA_SSI_REPAINT_ARROWS 0x0008
83 /* Scroll Bar tracking information */
84 static struct SCROLL_TRACKING_INFO g_tracking_info
;
86 /* Is the moving thumb being displayed? */
87 static BOOL SCROLL_MovingThumb
= FALSE
;
90 static BOOL
SCROLL_ShowScrollBar( HWND hwnd
, INT nBar
,
91 BOOL fShowH
, BOOL fShowV
);
92 static INT
SCROLL_SetScrollInfo( HWND hwnd
, INT nBar
,
93 const SCROLLINFO
*info
, BOOL bRedraw
);
95 /*********************************************************************
96 * scrollbar class descriptor
98 const struct builtin_class_descr SCROLL_builtin_class
=
100 L
"ScrollBar", /* name */
101 CS_DBLCLKS
| CS_VREDRAW
| CS_HREDRAW
| CS_PARENTDC
, /* style */
102 WINPROC_SCROLLBAR
, /* proc */
103 sizeof(SCROLLBAR_WNDDATA
), /* extra */
104 IDC_ARROW
, /* cursor */
108 /***********************************************************************
109 * SCROLL_ScrollInfoValid
111 * Determine if the supplied SCROLLINFO struct is valid.
112 * info [in] The SCROLLINFO struct to be tested
114 static inline BOOL
SCROLL_ScrollInfoValid( LPCSCROLLINFO info
)
116 return !(info
->fMask
& ~(SIF_ALL
| SIF_DISABLENOSCROLL
)
117 || (info
->cbSize
!= sizeof(*info
)
118 && info
->cbSize
!= sizeof(*info
) - sizeof(info
->nTrackPos
)));
122 /***********************************************************************
123 * SCROLL_GetInternalInfo
125 * Returns pointer to internal SCROLLBAR_INFO structure for nBar
126 * or NULL if failed (f.i. scroll bar does not exist yet)
127 * If alloc is TRUE and the struct does not exist yet, create it.
129 static SCROLLBAR_INFO
*SCROLL_GetInternalInfo( HWND hwnd
, INT nBar
, BOOL alloc
)
131 SCROLLBAR_INFO
*infoPtr
= NULL
;
132 WND
*wndPtr
= WIN_GetPtr( hwnd
);
134 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return NULL
;
138 if (wndPtr
->pScroll
) infoPtr
= &((LPWINSCROLLBAR_INFO
)wndPtr
->pScroll
)->horz
;
141 if (wndPtr
->pScroll
) infoPtr
= &((LPWINSCROLLBAR_INFO
)wndPtr
->pScroll
)->vert
;
144 if (wndPtr
->cbWndExtra
>= sizeof(SCROLLBAR_WNDDATA
))
146 SCROLLBAR_WNDDATA
*data
= (SCROLLBAR_WNDDATA
*)wndPtr
->wExtra
;
147 if (data
->magic
== SCROLLBAR_MAGIC
)
148 infoPtr
= &data
->info
;
150 if (!infoPtr
) WARN("window is not a scrollbar control\n");
153 WARN("with SB_BOTH\n");
157 if (!infoPtr
&& alloc
)
159 WINSCROLLBAR_INFO
*winInfoPtr
;
161 if (nBar
!= SB_HORZ
&& nBar
!= SB_VERT
)
162 WARN("Cannot initialize nBar=%d\n",nBar
);
163 else if ((winInfoPtr
= HeapAlloc( GetProcessHeap(), 0, sizeof(WINSCROLLBAR_INFO
) )))
165 /* Set default values */
166 winInfoPtr
->horz
.minVal
= 0;
167 winInfoPtr
->horz
.curVal
= 0;
168 winInfoPtr
->horz
.page
= 0;
169 /* From MSDN and our own tests:
170 * max for a standard scroll bar is 100 by default. */
171 winInfoPtr
->horz
.maxVal
= 100;
172 winInfoPtr
->horz
.flags
= ESB_ENABLE_BOTH
;
173 winInfoPtr
->vert
= winInfoPtr
->horz
;
174 wndPtr
->pScroll
= winInfoPtr
;
175 infoPtr
= nBar
== SB_HORZ
? &winInfoPtr
->horz
: &winInfoPtr
->vert
;
178 WIN_ReleasePtr( wndPtr
);
183 /***********************************************************************
184 * SCROLL_GetScrollBarRect
186 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
187 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
188 * 'arrowSize' returns the width or height of an arrow (depending on
189 * the orientation of the scrollbar), 'thumbSize' returns the size of
190 * the thumb, and 'thumbPos' returns the position of the thumb
191 * relative to the left or to the top.
192 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
194 static BOOL
SCROLL_GetScrollBarRect( HWND hwnd
, INT nBar
, RECT
*lprect
,
195 INT
*arrowSize
, INT
*thumbSize
,
200 WND
*wndPtr
= WIN_GetPtr( hwnd
);
202 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
207 WIN_GetRectangles( hwnd
, COORDS_WINDOW
, NULL
, lprect
);
208 lprect
->top
= lprect
->bottom
;
209 lprect
->bottom
+= GetSystemMetrics(SM_CYHSCROLL
);
210 if(wndPtr
->dwStyle
& WS_VSCROLL
)
216 WIN_GetRectangles( hwnd
, COORDS_WINDOW
, NULL
, lprect
);
217 if((wndPtr
->dwExStyle
& WS_EX_LEFTSCROLLBAR
) != 0)
219 lprect
->right
= lprect
->left
;
220 lprect
->left
-= GetSystemMetrics(SM_CXVSCROLL
);
224 lprect
->left
= lprect
->right
;
225 lprect
->right
+= GetSystemMetrics(SM_CXVSCROLL
);
227 if(wndPtr
->dwStyle
& WS_HSCROLL
)
233 GetClientRect( hwnd
, lprect
);
234 vertical
= ((wndPtr
->dwStyle
& SBS_VERT
) != 0);
238 WIN_ReleasePtr( wndPtr
);
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;
251 *thumbPos
= *thumbSize
= 0;
255 SCROLLBAR_INFO
*info
= SCROLL_GetInternalInfo( hwnd
, nBar
, TRUE
);
258 WARN("called for missing scroll bar\n");
259 WIN_ReleasePtr( wndPtr
);
262 *arrowSize
= GetSystemMetrics(SM_CXVSCROLL
);
263 pixels
-= (2 * (GetSystemMetrics(SM_CXVSCROLL
) - SCROLL_ARROW_THUMB_OVERLAP
));
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;
280 INT max
= info
->maxVal
- max( info
->page
-1, 0 );
281 if (info
->minVal
>= max
)
282 *thumbPos
= *arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
284 *thumbPos
= *arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
285 + MulDiv(pixels
, (info
->curVal
-info
->minVal
),(max
- info
->minVal
));
288 WIN_ReleasePtr( wndPtr
);
292 static void SCROLL_GetScrollBarDrawInfo( HWND hwnd
, INT bar
,
293 const struct SCROLL_TRACKING_INFO
*tracking_info
,
294 RECT
*rect
, INT
*arrow_size
, INT
*thumb_size
,
295 INT
*thumb_pos
, BOOL
*vertical
)
299 if (bar
== SB_CTL
&& GetWindowLongW( hwnd
, GWL_STYLE
) & (SBS_SIZEGRIP
| SBS_SIZEBOX
))
301 GetClientRect( hwnd
, rect
);
309 *vertical
= SCROLL_GetScrollBarRect( hwnd
, bar
, rect
, arrow_size
, thumb_size
, thumb_pos
);
311 if (SCROLL_MovingThumb
&& tracking_info
->win
== hwnd
&& tracking_info
->bar
== bar
)
313 max_size
= *vertical
? rect
->bottom
- rect
->top
: rect
->right
- rect
->left
;
314 max_size
-= *arrow_size
- SCROLL_ARROW_THUMB_OVERLAP
+ *thumb_size
;
316 pos
= tracking_info
->thumb_pos
;
317 if (pos
< *arrow_size
- SCROLL_ARROW_THUMB_OVERLAP
)
318 pos
= *arrow_size
- SCROLL_ARROW_THUMB_OVERLAP
;
319 else if (pos
> max_size
)
326 /***********************************************************************
329 * Compute the current scroll position based on the thumb position in pixels
330 * from the top of the scroll-bar.
332 static UINT
SCROLL_GetThumbVal( SCROLLBAR_INFO
*infoPtr
, RECT
*rect
,
333 BOOL vertical
, INT pos
)
336 INT pixels
= vertical
? rect
->bottom
-rect
->top
: rect
->right
-rect
->left
;
339 if ((pixels
-= 2*(GetSystemMetrics(SM_CXVSCROLL
) - SCROLL_ARROW_THUMB_OVERLAP
)) <= 0)
340 return infoPtr
->minVal
;
344 thumbSize
= MulDiv(pixels
,infoPtr
->page
,(infoPtr
->maxVal
-infoPtr
->minVal
+1));
345 if (thumbSize
< SCROLL_MIN_THUMB
) thumbSize
= SCROLL_MIN_THUMB
;
347 else thumbSize
= GetSystemMetrics(SM_CXVSCROLL
);
349 if ((pixels
-= thumbSize
) <= 0) return infoPtr
->minVal
;
351 pos
= max( 0, pos
- (GetSystemMetrics(SM_CXVSCROLL
) - SCROLL_ARROW_THUMB_OVERLAP
) );
352 if (pos
> pixels
) pos
= pixels
;
355 range
= infoPtr
->maxVal
- infoPtr
->minVal
;
357 range
= infoPtr
->maxVal
- infoPtr
->minVal
- infoPtr
->page
+ 1;
359 return infoPtr
->minVal
+ MulDiv(pos
, range
, pixels
);
362 /***********************************************************************
365 static BOOL
SCROLL_PtInRectEx( LPRECT lpRect
, POINT pt
, BOOL vertical
)
370 /* Pad hit rect to allow mouse to be dragged outside of scrollbar and
371 * still be considered in the scrollbar. */
374 scrollbarWidth
= lpRect
->right
- lpRect
->left
;
375 InflateRect(&rect
, scrollbarWidth
* 8, scrollbarWidth
* 2);
379 scrollbarWidth
= lpRect
->bottom
- lpRect
->top
;
380 InflateRect(&rect
, scrollbarWidth
* 2, scrollbarWidth
* 8);
382 return PtInRect( &rect
, pt
);
385 /***********************************************************************
388 static POINT
SCROLL_ClipPos( LPRECT lpRect
, POINT pt
)
390 if( pt
.x
< lpRect
->left
)
393 if( pt
.x
> lpRect
->right
)
394 pt
.x
= lpRect
->right
;
396 if( pt
.y
< lpRect
->top
)
399 if( pt
.y
> lpRect
->bottom
)
400 pt
.y
= lpRect
->bottom
;
406 /***********************************************************************
409 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
411 static enum SCROLL_HITTEST
SCROLL_HitTest( HWND hwnd
, INT nBar
,
412 POINT pt
, BOOL bDragging
)
414 INT arrowSize
, thumbSize
, thumbPos
;
417 BOOL vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
418 &arrowSize
, &thumbSize
, &thumbPos
);
420 if ( (bDragging
&& !SCROLL_PtInRectEx( &rect
, pt
, vertical
)) ||
421 (!PtInRect( &rect
, pt
)) ) return SCROLL_NOWHERE
;
425 if (pt
.y
< rect
.top
+ arrowSize
) return SCROLL_TOP_ARROW
;
426 if (pt
.y
>= rect
.bottom
- arrowSize
) return SCROLL_BOTTOM_ARROW
;
427 if (!thumbPos
) return SCROLL_TOP_RECT
;
429 if (pt
.y
< thumbPos
) return SCROLL_TOP_RECT
;
430 if (pt
.y
>= thumbPos
+ thumbSize
) return SCROLL_BOTTOM_RECT
;
432 else /* horizontal */
434 if (pt
.x
< rect
.left
+ arrowSize
) return SCROLL_TOP_ARROW
;
435 if (pt
.x
>= rect
.right
- arrowSize
) return SCROLL_BOTTOM_ARROW
;
436 if (!thumbPos
) return SCROLL_TOP_RECT
;
438 if (pt
.x
< thumbPos
) return SCROLL_TOP_RECT
;
439 if (pt
.x
>= thumbPos
+ thumbSize
) return SCROLL_BOTTOM_RECT
;
445 /***********************************************************************
448 * Draw the scroll bar arrows.
450 static void SCROLL_DrawArrows( HDC hdc
, SCROLLBAR_INFO
*infoPtr
,
451 RECT
*rect
, INT arrowSize
, BOOL vertical
,
452 BOOL top_pressed
, BOOL bottom_pressed
)
458 r
.bottom
= r
.top
+ arrowSize
;
460 r
.right
= r
.left
+ arrowSize
;
462 DrawFrameControl( hdc
, &r
, DFC_SCROLL
,
463 (vertical
? DFCS_SCROLLUP
: DFCS_SCROLLLEFT
)
464 | (top_pressed
? (DFCS_PUSHED
| DFCS_FLAT
) : 0 )
465 | (infoPtr
->flags
&ESB_DISABLE_LTUP
? DFCS_INACTIVE
: 0 ) );
469 r
.top
= r
.bottom
-arrowSize
;
471 r
.left
= r
.right
-arrowSize
;
473 DrawFrameControl( hdc
, &r
, DFC_SCROLL
,
474 (vertical
? DFCS_SCROLLDOWN
: DFCS_SCROLLRIGHT
)
475 | (bottom_pressed
? (DFCS_PUSHED
| DFCS_FLAT
) : 0 )
476 | (infoPtr
->flags
&ESB_DISABLE_RTDN
? DFCS_INACTIVE
: 0) );
479 /***********************************************************************
480 * SCROLL_DrawInterior
482 * Draw the scroll bar interior (everything except the arrows).
484 static void SCROLL_DrawInterior( HWND hwnd
, HDC hdc
, INT nBar
,
485 RECT
*rect
, INT arrowSize
,
486 INT thumbSize
, INT thumbPos
,
487 UINT flags
, BOOL vertical
,
488 BOOL top_selected
, BOOL bottom_selected
)
492 HBRUSH hSaveBrush
,hBrush
;
494 /* Select the correct brush and pen */
496 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
497 * The window-owned scrollbars need to call DEFWND_ControlColor
498 * to correctly setup default scrollbar colors
500 if (nBar
== SB_CTL
) {
501 hBrush
= (HBRUSH
)SendMessageW( GetParent(hwnd
), WM_CTLCOLORSCROLLBAR
,
502 (WPARAM
)hdc
,(LPARAM
)hwnd
);
504 hBrush
= DEFWND_ControlColor( hdc
, CTLCOLOR_SCROLLBAR
);
506 hSavePen
= SelectObject( hdc
, SYSCOLOR_GetPen(COLOR_WINDOWFRAME
) );
507 hSaveBrush
= SelectObject( hdc
, hBrush
);
509 /* Calculate the scroll rectangle */
514 r
.top
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
515 r
.bottom
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
519 r
.left
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
520 r
.right
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
523 /* Draw the scroll bar frame */
525 /* Draw the scroll rectangles and thumb */
527 if (!thumbPos
) /* No thumb to draw */
529 PatBlt( hdc
, r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
, PATCOPY
);
531 /* cleanup and return */
532 SelectObject( hdc
, hSavePen
);
533 SelectObject( hdc
, hSaveBrush
);
539 PatBlt( hdc
, r
.left
, r
.top
, r
.right
- r
.left
,
540 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
),
541 top_selected
? 0x0f0000 : PATCOPY
);
542 r
.top
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
543 PatBlt( hdc
, r
.left
, r
.top
+ thumbSize
, r
.right
- r
.left
,
544 r
.bottom
- r
.top
- thumbSize
,
545 bottom_selected
? 0x0f0000 : PATCOPY
);
546 r
.bottom
= r
.top
+ thumbSize
;
548 else /* horizontal */
550 PatBlt( hdc
, r
.left
, r
.top
,
551 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
),
552 r
.bottom
- r
.top
, top_selected
? 0x0f0000 : PATCOPY
);
553 r
.left
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
554 PatBlt( hdc
, r
.left
+ thumbSize
, r
.top
, r
.right
- r
.left
- thumbSize
,
555 r
.bottom
- r
.top
, bottom_selected
? 0x0f0000 : PATCOPY
);
556 r
.right
= r
.left
+ thumbSize
;
561 SelectObject( hdc
, GetSysColorBrush(COLOR_BTNFACE
) );
562 Rectangle( hdc
, r
.left
+1, r
.top
+1, r
.right
-1, r
.bottom
-1 );
563 DrawEdge( hdc
, &r
, EDGE_RAISED
, BF_RECT
);
566 SelectObject( hdc
, hSavePen
);
567 SelectObject( hdc
, hSaveBrush
);
570 void WINAPI
USER_ScrollBarDraw( HWND hwnd
, HDC hdc
, INT nBar
, enum SCROLL_HITTEST hit_test
,
571 const struct SCROLL_TRACKING_INFO
*tracking_info
, BOOL arrows
,
572 BOOL interior
, RECT
*rect
, INT arrowSize
, INT thumbPos
,
573 INT thumbSize
, BOOL vertical
)
575 SCROLLBAR_INFO
*infoPtr
;
579 DWORD style
= GetWindowLongW( hwnd
, GWL_STYLE
);
581 if (style
& SBS_SIZEGRIP
)
585 FillRect( hdc
, &rc
, GetSysColorBrush( COLOR_SCROLLBAR
) );
586 rc
.left
= max( rc
.left
, rc
.right
- GetSystemMetrics( SM_CXVSCROLL
) - 1 );
587 rc
.top
= max( rc
.top
, rc
.bottom
- GetSystemMetrics( SM_CYHSCROLL
) - 1 );
588 DrawFrameControl( hdc
, &rc
, DFC_SCROLL
, DFCS_SCROLLSIZEGRIP
);
592 if (style
& SBS_SIZEBOX
)
594 FillRect( hdc
, rect
, GetSysColorBrush( COLOR_SCROLLBAR
) );
599 if (!(infoPtr
= SCROLL_GetInternalInfo( hwnd
, nBar
, TRUE
)))
602 /* Draw the arrows */
604 if (arrows
&& arrowSize
)
606 if (vertical
== tracking_info
->vertical
&& GetCapture() == hwnd
)
607 SCROLL_DrawArrows( hdc
, infoPtr
, rect
, arrowSize
, vertical
,
608 hit_test
== tracking_info
->hit_test
&& hit_test
== SCROLL_TOP_ARROW
,
609 hit_test
== tracking_info
->hit_test
&& hit_test
== SCROLL_BOTTOM_ARROW
);
611 SCROLL_DrawArrows( hdc
, infoPtr
, rect
, arrowSize
, vertical
, FALSE
, FALSE
);
616 if (vertical
== tracking_info
->vertical
&& GetCapture() == hwnd
)
618 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, rect
, arrowSize
, thumbSize
, thumbPos
,
619 infoPtr
->flags
, vertical
,
620 hit_test
== tracking_info
->hit_test
&& hit_test
== SCROLL_TOP_RECT
,
621 hit_test
== tracking_info
->hit_test
&& hit_test
== SCROLL_BOTTOM_RECT
);
625 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, rect
, arrowSize
, thumbSize
, thumbPos
,
626 infoPtr
->flags
, vertical
, FALSE
, FALSE
);
630 /* if scroll bar has focus, reposition the caret */
631 if(hwnd
==GetFocus() && (nBar
==SB_CTL
))
635 SetCaretPos(thumbPos
+ 1, rect
->top
+ 1);
639 SetCaretPos(rect
->top
+ 1, thumbPos
+ 1);
644 /***********************************************************************
645 * SCROLL_DrawScrollBar
647 * Redraw the whole scrollbar.
649 void SCROLL_DrawScrollBar( HWND hwnd
, HDC hdc
, INT bar
, enum SCROLL_HITTEST hit_test
,
650 const struct SCROLL_TRACKING_INFO
*tracking_info
, BOOL draw_arrows
,
653 INT arrow_size
, thumb_size
, thumb_pos
;
658 if (!(hwnd
= WIN_GetFullHandle( hwnd
)))
661 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
662 if ((bar
== SB_VERT
&& !(style
& WS_VSCROLL
)) || (bar
== SB_HORZ
&& !(style
& WS_HSCROLL
)))
665 if (!WIN_IsWindowDrawable( hwnd
, FALSE
))
668 SCROLL_GetScrollBarDrawInfo( hwnd
, bar
, tracking_info
, &rect
, &arrow_size
, &thumb_size
,
669 &thumb_pos
, &vertical
);
670 /* do not draw if the scrollbar rectangle is empty */
671 if (IsRectEmpty( &rect
))
674 TRACE("hwnd %p, hdc %p, bar %d, hit_test %d, tracking_info(win %p, bar %d, thumb_pos %d, "
675 "track_pos %d, vertical %d, hit_test %d), draw_arrows %d, draw_interior %d, rect %s, "
676 "arrow_size %d, thumb_pos %d, thumb_val %d, vertical %d, captured window %p\n", hwnd
, hdc
,
677 bar
, hit_test
, tracking_info
->win
, tracking_info
->bar
, tracking_info
->thumb_pos
,
678 tracking_info
->thumb_val
, tracking_info
->vertical
, tracking_info
->hit_test
, draw_arrows
,
679 draw_interior
, wine_dbgstr_rect(&rect
), arrow_size
, thumb_pos
, thumb_size
, vertical
,
681 user_api
->pScrollBarDraw( hwnd
, hdc
, bar
, hit_test
, tracking_info
, draw_arrows
, draw_interior
,
682 &rect
, arrow_size
, thumb_pos
, thumb_size
, vertical
);
685 void SCROLL_DrawNCScrollBar( HWND hwnd
, HDC hdc
, BOOL draw_horizontal
, BOOL draw_vertical
)
688 SCROLL_DrawScrollBar( hwnd
, hdc
, SB_HORZ
, g_tracking_info
.hit_test
, &g_tracking_info
, TRUE
, TRUE
);
690 SCROLL_DrawScrollBar( hwnd
, hdc
, SB_VERT
, g_tracking_info
.hit_test
, &g_tracking_info
, TRUE
, TRUE
);
693 /***********************************************************************
694 * SCROLL_RefreshScrollBar
696 * Repaint the scroll bar interior after a SetScrollRange() or
697 * SetScrollPos() call.
699 static void SCROLL_RefreshScrollBar( HWND hwnd
, INT nBar
,
700 BOOL arrows
, BOOL interior
)
702 HDC hdc
= GetDCEx( hwnd
, 0,
703 DCX_CACHE
| ((nBar
== SB_CTL
) ? 0 : DCX_WINDOW
) );
706 SCROLL_DrawScrollBar( hwnd
, hdc
, nBar
, g_tracking_info
.hit_test
, &g_tracking_info
, arrows
, interior
);
707 ReleaseDC( hwnd
, hdc
);
711 /***********************************************************************
712 * SCROLL_HandleKbdEvent
714 * Handle a keyboard event (only for SB_CTL scrollbars with focus).
717 * hwnd [I] Handle of window with scrollbar(s)
718 * wParam [I] Variable input including enable state
719 * lParam [I] Variable input including input point
721 static void SCROLL_HandleKbdEvent(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
723 TRACE("hwnd=%p wParam=%ld lParam=%ld\n", hwnd
, wParam
, lParam
);
725 /* hide caret on first KEYDOWN to prevent flicker */
726 if ((lParam
& PFD_DOUBLEBUFFER_DONTCARE
) == 0)
731 case VK_PRIOR
: wParam
= SB_PAGEUP
; break;
732 case VK_NEXT
: wParam
= SB_PAGEDOWN
; break;
733 case VK_HOME
: wParam
= SB_TOP
; break;
734 case VK_END
: wParam
= SB_BOTTOM
; break;
735 case VK_UP
: wParam
= SB_LINEUP
; break;
736 case VK_DOWN
: wParam
= SB_LINEDOWN
; break;
737 case VK_LEFT
: wParam
= SB_LINEUP
; break;
738 case VK_RIGHT
: wParam
= SB_LINEDOWN
; break;
741 SendMessageW(GetParent(hwnd
),
742 ((GetWindowLongW( hwnd
, GWL_STYLE
) & SBS_VERT
) ?
743 WM_VSCROLL
: WM_HSCROLL
), wParam
, (LPARAM
)hwnd
);
747 /***********************************************************************
748 * SCROLL_HandleScrollEvent
750 * Handle a mouse or timer event for the scrollbar.
751 * 'pt' is the location of the mouse event in client (for SB_CTL) or
752 * windows coordinates.
754 void SCROLL_HandleScrollEvent( HWND hwnd
, INT nBar
, UINT msg
, POINT pt
)
756 /* Previous mouse position for timer events */
758 /* Thumb position when tracking started. */
759 static UINT trackThumbPos
;
760 /* Position in the scroll-bar of the last button-down event. */
761 static INT lastClickPos
;
762 /* Position in the scroll-bar of the last mouse event. */
763 static INT lastMousePos
;
765 enum SCROLL_HITTEST hittest
;
766 HWND hwndOwner
, hwndCtl
;
769 INT arrowSize
, thumbSize
, thumbPos
;
773 SCROLLBAR_INFO
*infoPtr
= SCROLL_GetInternalInfo( hwnd
, nBar
, FALSE
);
774 if (!infoPtr
) return;
775 if ((g_tracking_info
.hit_test
== SCROLL_NOWHERE
)
776 && (msg
!= WM_LBUTTONDOWN
&& msg
!= WM_MOUSEMOVE
&& msg
!= WM_MOUSELEAVE
777 && msg
!= WM_NCMOUSEMOVE
&& msg
!= WM_NCMOUSELEAVE
))
780 if (nBar
== SB_CTL
&& (GetWindowLongW( hwnd
, GWL_STYLE
) & (SBS_SIZEGRIP
| SBS_SIZEBOX
)))
784 case WM_LBUTTONDOWN
: /* Initialise mouse tracking */
785 HideCaret(hwnd
); /* hide caret while holding down LBUTTON */
788 g_tracking_info
.hit_test
= hittest
= SCROLL_THUMB
;
791 GetClientRect(GetParent(GetParent(hwnd
)),&rect
);
796 g_tracking_info
.hit_test
= hittest
= SCROLL_NOWHERE
;
797 if (hwnd
==GetFocus()) ShowCaret(hwnd
);
806 hdc
= GetDCEx( hwnd
, 0, DCX_CACHE
| ((nBar
== SB_CTL
) ? 0 : DCX_WINDOW
));
807 vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
808 &arrowSize
, &thumbSize
, &thumbPos
);
809 hwndOwner
= (nBar
== SB_CTL
) ? GetParent(hwnd
) : hwnd
;
810 hwndCtl
= (nBar
== SB_CTL
) ? hwnd
: 0;
814 case WM_LBUTTONDOWN
: /* Initialise mouse tracking */
815 HideCaret(hwnd
); /* hide caret while holding down LBUTTON */
816 g_tracking_info
.vertical
= vertical
;
817 g_tracking_info
.hit_test
= hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, FALSE
);
818 lastClickPos
= vertical
? (pt
.y
- rect
.top
) : (pt
.x
- rect
.left
);
819 lastMousePos
= lastClickPos
;
820 trackThumbPos
= thumbPos
;
822 if (nBar
== SB_CTL
&& (GetWindowLongW(hwnd
, GWL_STYLE
) & WS_TABSTOP
)) SetFocus( hwnd
);
827 hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, vertical
== g_tracking_info
.vertical
&& GetCapture() == hwnd
);
833 tme
.cbSize
= sizeof(tme
);
834 tme
.dwFlags
= TME_QUERY
;
835 TrackMouseEvent( &tme
);
836 if (!(tme
.dwFlags
& TME_LEAVE
) || tme
.hwndTrack
!= hwnd
)
838 tme
.dwFlags
= TME_LEAVE
;
839 tme
.hwndTrack
= hwnd
;
840 TrackMouseEvent( &tme
);
846 hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, vertical
== g_tracking_info
.vertical
&& GetCapture() == hwnd
);
852 tme
.cbSize
= sizeof(tme
);
853 tme
.dwFlags
= TME_QUERY
;
854 TrackMouseEvent( &tme
);
855 if (((tme
.dwFlags
& (TME_NONCLIENT
| TME_LEAVE
)) != (TME_NONCLIENT
| TME_LEAVE
)) || tme
.hwndTrack
!= hwnd
)
857 tme
.dwFlags
= TME_NONCLIENT
| TME_LEAVE
;
858 tme
.hwndTrack
= hwnd
;
859 TrackMouseEvent( &tme
);
864 case WM_NCMOUSELEAVE
:
868 hittest
= SCROLL_NOWHERE
;
875 hittest
= SCROLL_NOWHERE
;
879 hittest
= SCROLL_NOWHERE
;
881 /* if scrollbar has focus, show back caret */
882 if (hwnd
==GetFocus()) ShowCaret(hwnd
);
887 hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, FALSE
);
891 return; /* Should never happen */
894 TRACE("Event: hwnd=%p bar=%d msg=%s pt=%d,%d hit=%d\n",
895 hwnd
, nBar
, SPY_GetMsgName(msg
,hwnd
), pt
.x
, pt
.y
, hittest
);
897 switch (g_tracking_info
.hit_test
)
899 case SCROLL_NOWHERE
: /* No tracking in progress */
900 if (msg
== WM_MOUSEMOVE
|| msg
== WM_MOUSELEAVE
|| msg
== WM_NCMOUSEMOVE
|| msg
== WM_NCMOUSELEAVE
)
901 SCROLL_DrawScrollBar( hwnd
, hdc
, nBar
, hittest
, &g_tracking_info
, TRUE
, TRUE
);
904 case SCROLL_TOP_ARROW
:
905 SCROLL_DrawScrollBar( hwnd
, hdc
, nBar
, hittest
, &g_tracking_info
, TRUE
, FALSE
);
906 if (hittest
== g_tracking_info
.hit_test
)
908 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
910 SendMessageW( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
911 SB_LINEUP
, (LPARAM
)hwndCtl
);
914 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
915 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
, NULL
);
917 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
920 case SCROLL_TOP_RECT
:
921 SCROLL_DrawScrollBar( hwnd
, hdc
, nBar
, hittest
, &g_tracking_info
, FALSE
, TRUE
);
922 if (hittest
== g_tracking_info
.hit_test
)
924 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
926 SendMessageW( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
927 SB_PAGEUP
, (LPARAM
)hwndCtl
);
929 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
930 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
, NULL
);
932 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
936 if (msg
== WM_LBUTTONDOWN
)
938 g_tracking_info
.win
= hwnd
;
939 g_tracking_info
.bar
= nBar
;
940 g_tracking_info
.thumb_pos
= trackThumbPos
+ lastMousePos
- lastClickPos
;
941 g_tracking_info
.thumb_val
= SCROLL_GetThumbVal( infoPtr
, &rect
, vertical
,
942 g_tracking_info
.thumb_pos
);
943 if (!SCROLL_MovingThumb
)
945 SCROLL_MovingThumb
= TRUE
;
946 SCROLL_DrawScrollBar( hwnd
, hdc
, nBar
, hittest
, &g_tracking_info
, FALSE
, TRUE
);
949 else if (msg
== WM_LBUTTONUP
)
951 SCROLL_DrawScrollBar( hwnd
, hdc
, nBar
, SCROLL_NOWHERE
, &g_tracking_info
, FALSE
, TRUE
);
953 else if (msg
== WM_MOUSEMOVE
)
957 if (!SCROLL_PtInRectEx( &rect
, pt
, vertical
)) pos
= lastClickPos
;
960 pt
= SCROLL_ClipPos( &rect
, pt
);
961 pos
= vertical
? (pt
.y
- rect
.top
) : (pt
.x
- rect
.left
);
963 if ( (pos
!= lastMousePos
) || (!SCROLL_MovingThumb
) )
966 g_tracking_info
.thumb_pos
= trackThumbPos
+ pos
- lastClickPos
;
967 g_tracking_info
.thumb_val
= SCROLL_GetThumbVal( infoPtr
, &rect
, vertical
,
968 g_tracking_info
.thumb_pos
);
969 SendMessageW( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
970 MAKEWPARAM( SB_THUMBTRACK
, g_tracking_info
.thumb_val
),
972 SCROLL_MovingThumb
= TRUE
;
973 SCROLL_DrawScrollBar( hwnd
, hdc
, nBar
, hittest
, &g_tracking_info
, FALSE
, TRUE
);
978 case SCROLL_BOTTOM_RECT
:
979 SCROLL_DrawScrollBar( hwnd
, hdc
, nBar
, hittest
, &g_tracking_info
, FALSE
, TRUE
);
980 if (hittest
== g_tracking_info
.hit_test
)
982 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
984 SendMessageW( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
985 SB_PAGEDOWN
, (LPARAM
)hwndCtl
);
987 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
988 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
, NULL
);
990 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
993 case SCROLL_BOTTOM_ARROW
:
994 SCROLL_DrawScrollBar( hwnd
, hdc
, nBar
, hittest
, &g_tracking_info
, TRUE
, FALSE
);
995 if (hittest
== g_tracking_info
.hit_test
)
997 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
999 SendMessageW( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1000 SB_LINEDOWN
, (LPARAM
)hwndCtl
);
1003 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
1004 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
, NULL
);
1006 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
1010 if (msg
== WM_LBUTTONDOWN
)
1013 if (hittest
== SCROLL_THUMB
)
1015 UINT val
= SCROLL_GetThumbVal( infoPtr
, &rect
, vertical
,
1016 trackThumbPos
+ lastMousePos
- lastClickPos
);
1017 SendMessageW( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1018 MAKEWPARAM( SB_THUMBTRACK
, val
), (LPARAM
)hwndCtl
);
1022 if (msg
== WM_LBUTTONUP
)
1024 hittest
= g_tracking_info
.hit_test
;
1025 g_tracking_info
.hit_test
= SCROLL_NOWHERE
; /* Terminate tracking */
1027 if (hittest
== SCROLL_THUMB
)
1029 UINT val
= SCROLL_GetThumbVal( infoPtr
, &rect
, vertical
,
1030 trackThumbPos
+ lastMousePos
- lastClickPos
);
1031 SendMessageW( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1032 MAKEWPARAM( SB_THUMBPOSITION
, val
), (LPARAM
)hwndCtl
);
1034 /* SB_ENDSCROLL doesn't report thumb position */
1035 SendMessageW( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1036 SB_ENDSCROLL
, (LPARAM
)hwndCtl
);
1038 /* Terminate tracking */
1039 g_tracking_info
.win
= 0;
1040 SCROLL_MovingThumb
= FALSE
;
1041 hittest
= SCROLL_NOWHERE
;
1042 SCROLL_DrawScrollBar( hwnd
, hdc
, nBar
, hittest
, &g_tracking_info
, TRUE
, TRUE
);
1045 ReleaseDC( hwnd
, hdc
);
1049 /***********************************************************************
1050 * SCROLL_TrackScrollBar
1052 * Track a mouse button press on a scroll-bar.
1053 * pt is in screen-coordinates for non-client scroll bars.
1055 void SCROLL_TrackScrollBar( HWND hwnd
, INT scrollbar
, POINT pt
)
1060 if (scrollbar
!= SB_CTL
)
1062 WIN_GetRectangles( hwnd
, COORDS_CLIENT
, &rect
, NULL
);
1063 ScreenToClient( hwnd
, &pt
);
1068 rect
.left
= rect
.top
= 0;
1070 SCROLL_HandleScrollEvent( hwnd
, scrollbar
, WM_LBUTTONDOWN
, pt
);
1074 if (!GetMessageW( &msg
, 0, 0, 0 )) break;
1075 if (CallMsgFilterW( &msg
, MSGF_SCROLLBAR
)) continue;
1076 if (msg
.message
== WM_LBUTTONUP
||
1077 msg
.message
== WM_MOUSEMOVE
||
1078 msg
.message
== WM_MOUSELEAVE
||
1079 msg
.message
== WM_NCMOUSEMOVE
||
1080 msg
.message
== WM_NCMOUSELEAVE
||
1081 (msg
.message
== WM_SYSTIMER
&& msg
.wParam
== SCROLL_TIMER
))
1083 pt
.x
= (short)LOWORD(msg
.lParam
) - rect
.left
;
1084 pt
.y
= (short)HIWORD(msg
.lParam
) - rect
.top
;
1085 SCROLL_HandleScrollEvent( hwnd
, scrollbar
, msg
.message
, pt
);
1089 TranslateMessage( &msg
);
1090 DispatchMessageW( &msg
);
1092 if (!IsWindow( hwnd
))
1097 } while (msg
.message
!= WM_LBUTTONUP
&& GetCapture() == hwnd
);
1101 /***********************************************************************
1102 * SCROLL_CreateScrollBar
1104 * Create a scroll bar
1107 * hwnd [I] Handle of window with scrollbar(s)
1108 * lpCreate [I] The style and place of the scroll bar
1110 static void SCROLL_CreateScrollBar(HWND hwnd
, LPCREATESTRUCTW lpCreate
)
1112 LPSCROLLBAR_INFO info
= NULL
;
1115 TRACE("hwnd=%p lpCreate=%p\n", hwnd
, lpCreate
);
1117 win
= WIN_GetPtr(hwnd
);
1118 if (win
->cbWndExtra
>= sizeof(SCROLLBAR_WNDDATA
))
1120 SCROLLBAR_WNDDATA
*data
= (SCROLLBAR_WNDDATA
*)win
->wExtra
;
1121 data
->magic
= SCROLLBAR_MAGIC
;
1124 else WARN("Not enough extra data\n");
1125 WIN_ReleasePtr(win
);
1128 if (lpCreate
->style
& WS_DISABLED
)
1130 info
->flags
= ESB_DISABLE_BOTH
;
1131 TRACE("Created WS_DISABLED scrollbar\n");
1134 if (lpCreate
->style
& (SBS_SIZEGRIP
| SBS_SIZEBOX
))
1136 if (lpCreate
->style
& SBS_SIZEBOXTOPLEFTALIGN
)
1137 MoveWindow( hwnd
, lpCreate
->x
, lpCreate
->y
, GetSystemMetrics(SM_CXVSCROLL
)+1,
1138 GetSystemMetrics(SM_CYHSCROLL
)+1, FALSE
);
1139 else if(lpCreate
->style
& SBS_SIZEBOXBOTTOMRIGHTALIGN
)
1140 MoveWindow( hwnd
, lpCreate
->x
+lpCreate
->cx
-GetSystemMetrics(SM_CXVSCROLL
)-1,
1141 lpCreate
->y
+lpCreate
->cy
-GetSystemMetrics(SM_CYHSCROLL
)-1,
1142 GetSystemMetrics(SM_CXVSCROLL
)+1,
1143 GetSystemMetrics(SM_CYHSCROLL
)+1, FALSE
);
1145 else if (lpCreate
->style
& SBS_VERT
)
1147 if (lpCreate
->style
& SBS_LEFTALIGN
)
1148 MoveWindow( hwnd
, lpCreate
->x
, lpCreate
->y
,
1149 GetSystemMetrics(SM_CXVSCROLL
)+1, lpCreate
->cy
, FALSE
);
1150 else if (lpCreate
->style
& SBS_RIGHTALIGN
)
1152 lpCreate
->x
+lpCreate
->cx
-GetSystemMetrics(SM_CXVSCROLL
)-1,
1154 GetSystemMetrics(SM_CXVSCROLL
)+1, lpCreate
->cy
, FALSE
);
1158 if (lpCreate
->style
& SBS_TOPALIGN
)
1159 MoveWindow( hwnd
, lpCreate
->x
, lpCreate
->y
,
1160 lpCreate
->cx
, GetSystemMetrics(SM_CYHSCROLL
)+1, FALSE
);
1161 else if (lpCreate
->style
& SBS_BOTTOMALIGN
)
1164 lpCreate
->y
+lpCreate
->cy
-GetSystemMetrics(SM_CYHSCROLL
)-1,
1165 lpCreate
->cx
, GetSystemMetrics(SM_CYHSCROLL
)+1, FALSE
);
1170 /*************************************************************************
1171 * SCROLL_GetScrollInfo
1173 * Internal helper for the API function
1176 * hwnd [I] Handle of window with scrollbar(s)
1177 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1178 * info [IO] fMask specifies which values to retrieve
1181 * FALSE if requested field not filled (f.i. scroll bar does not exist)
1183 static BOOL
SCROLL_GetScrollInfo(HWND hwnd
, INT nBar
, LPSCROLLINFO info
)
1185 LPSCROLLBAR_INFO infoPtr
;
1187 /* handle invalid data structure */
1188 if (!SCROLL_ScrollInfoValid(info
)
1189 || !(infoPtr
= SCROLL_GetInternalInfo(hwnd
, nBar
, FALSE
)))
1192 /* fill in the desired scroll info structure */
1193 if (info
->fMask
& SIF_PAGE
) info
->nPage
= infoPtr
->page
;
1194 if (info
->fMask
& SIF_POS
) info
->nPos
= infoPtr
->curVal
;
1195 if ((info
->fMask
& SIF_TRACKPOS
) && (info
->cbSize
== sizeof(*info
)))
1196 info
->nTrackPos
= (g_tracking_info
.win
== WIN_GetFullHandle(hwnd
)) ? g_tracking_info
.thumb_val
: infoPtr
->curVal
;
1197 if (info
->fMask
& SIF_RANGE
)
1199 info
->nMin
= infoPtr
->minVal
;
1200 info
->nMax
= infoPtr
->maxVal
;
1203 TRACE("cbSize %02x fMask %04x nMin %d nMax %d nPage %u nPos %d nTrackPos %d\n",
1204 info
->cbSize
, info
->fMask
, info
->nMin
, info
->nMax
, info
->nPage
,
1205 info
->nPos
, info
->nTrackPos
);
1207 return (info
->fMask
& SIF_ALL
) != 0;
1211 /*************************************************************************
1212 * SCROLL_GetScrollBarInfo
1214 * Internal helper for the API function
1217 * hwnd [I] Handle of window with scrollbar(s)
1218 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1219 * info [IO] cbSize specifies the size of the structure
1224 static BOOL
SCROLL_GetScrollBarInfo(HWND hwnd
, LONG idObject
, LPSCROLLBARINFO info
)
1226 LPSCROLLBAR_INFO infoPtr
;
1229 DWORD style
= GetWindowLongW(hwnd
, GWL_STYLE
);
1235 case OBJID_CLIENT
: nBar
= SB_CTL
; break;
1236 case OBJID_HSCROLL
: nBar
= SB_HORZ
; break;
1237 case OBJID_VSCROLL
: nBar
= SB_VERT
; break;
1238 default: return FALSE
;
1241 /* handle invalid data structure */
1242 if (info
->cbSize
!= sizeof(*info
))
1245 SCROLL_GetScrollBarRect(hwnd
, nBar
, &info
->rcScrollBar
, &nDummy
,
1246 &info
->dxyLineButton
, &info
->xyThumbTop
);
1247 /* rcScrollBar needs to be in screen coordinates */
1248 GetWindowRect(hwnd
, &rect
);
1249 OffsetRect(&info
->rcScrollBar
, rect
.left
, rect
.top
);
1251 info
->xyThumbBottom
= info
->xyThumbTop
+ info
->dxyLineButton
;
1253 infoPtr
= SCROLL_GetInternalInfo(hwnd
, nBar
, TRUE
);
1257 /* Scroll bar state */
1258 info
->rgstate
[0] = 0;
1259 if ((nBar
== SB_HORZ
&& !(style
& WS_HSCROLL
))
1260 || (nBar
== SB_VERT
&& !(style
& WS_VSCROLL
)))
1261 info
->rgstate
[0] |= STATE_SYSTEM_INVISIBLE
;
1262 if (infoPtr
->minVal
>= infoPtr
->maxVal
- max(infoPtr
->page
- 1, 0))
1264 if (!(info
->rgstate
[0] & STATE_SYSTEM_INVISIBLE
))
1265 info
->rgstate
[0] |= STATE_SYSTEM_UNAVAILABLE
;
1267 info
->rgstate
[0] |= STATE_SYSTEM_OFFSCREEN
;
1269 if (nBar
== SB_CTL
&& !IsWindowEnabled(hwnd
))
1270 info
->rgstate
[0] |= STATE_SYSTEM_UNAVAILABLE
;
1272 pressed
= ((nBar
== SB_VERT
) == g_tracking_info
.vertical
&& GetCapture() == hwnd
);
1274 /* Top/left arrow button state. MSDN says top/right, but I don't believe it */
1275 info
->rgstate
[1] = 0;
1276 if (pressed
&& g_tracking_info
.hit_test
== SCROLL_TOP_ARROW
)
1277 info
->rgstate
[1] |= STATE_SYSTEM_PRESSED
;
1278 if (infoPtr
->flags
& ESB_DISABLE_LTUP
)
1279 info
->rgstate
[1] |= STATE_SYSTEM_UNAVAILABLE
;
1281 /* Page up/left region state. MSDN says up/right, but I don't believe it */
1282 info
->rgstate
[2] = 0;
1283 if (infoPtr
->curVal
== infoPtr
->minVal
)
1284 info
->rgstate
[2] |= STATE_SYSTEM_INVISIBLE
;
1285 if (pressed
&& g_tracking_info
.hit_test
== SCROLL_TOP_RECT
)
1286 info
->rgstate
[2] |= STATE_SYSTEM_PRESSED
;
1289 info
->rgstate
[3] = 0;
1290 if (pressed
&& g_tracking_info
.hit_test
== SCROLL_THUMB
)
1291 info
->rgstate
[3] |= STATE_SYSTEM_PRESSED
;
1293 /* Page down/right region state. MSDN says down/left, but I don't believe it */
1294 info
->rgstate
[4] = 0;
1295 if (infoPtr
->curVal
>= infoPtr
->maxVal
- 1)
1296 info
->rgstate
[4] |= STATE_SYSTEM_INVISIBLE
;
1297 if (pressed
&& g_tracking_info
.hit_test
== SCROLL_BOTTOM_RECT
)
1298 info
->rgstate
[4] |= STATE_SYSTEM_PRESSED
;
1300 /* Bottom/right arrow button state. MSDN says bottom/left, but I don't believe it */
1301 info
->rgstate
[5] = 0;
1302 if (pressed
&& g_tracking_info
.hit_test
== SCROLL_BOTTOM_ARROW
)
1303 info
->rgstate
[5] |= STATE_SYSTEM_PRESSED
;
1304 if (infoPtr
->flags
& ESB_DISABLE_RTDN
)
1305 info
->rgstate
[5] |= STATE_SYSTEM_UNAVAILABLE
;
1311 /*************************************************************************
1312 * SCROLL_GetScrollPos
1314 * Internal helper for the API function
1317 * hwnd [I] Handle of window with scrollbar(s)
1318 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1320 static INT
SCROLL_GetScrollPos(HWND hwnd
, INT nBar
)
1322 LPSCROLLBAR_INFO infoPtr
= SCROLL_GetInternalInfo(hwnd
, nBar
, FALSE
);
1323 return infoPtr
? infoPtr
->curVal
: 0;
1327 /*************************************************************************
1328 * SCROLL_GetScrollRange
1330 * Internal helper for the API function
1333 * hwnd [I] Handle of window with scrollbar(s)
1334 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1335 * lpMin [O] Where to store minimum value
1336 * lpMax [O] Where to store maximum value
1342 static BOOL
SCROLL_GetScrollRange(HWND hwnd
, INT nBar
, LPINT lpMin
, LPINT lpMax
)
1344 LPSCROLLBAR_INFO infoPtr
= SCROLL_GetInternalInfo(hwnd
, nBar
, FALSE
);
1346 if (lpMin
) *lpMin
= infoPtr
? infoPtr
->minVal
: 0;
1347 if (lpMax
) *lpMax
= infoPtr
? infoPtr
->maxVal
: 0;
1353 /*************************************************************************
1354 * SCROLL_SetScrollRange
1357 * hwnd [I] Handle of window with scrollbar(s)
1358 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1359 * lpMin [I] Minimum value
1360 * lpMax [I] Maximum value
1363 static BOOL
SCROLL_SetScrollRange(HWND hwnd
, INT nBar
, INT minVal
, INT maxVal
)
1365 LPSCROLLBAR_INFO infoPtr
= SCROLL_GetInternalInfo(hwnd
, nBar
, FALSE
);
1367 TRACE("hwnd=%p nBar=%d min=%d max=%d\n", hwnd
, nBar
, minVal
, maxVal
);
1371 infoPtr
->minVal
= minVal
;
1372 infoPtr
->maxVal
= maxVal
;
1377 LRESULT WINAPI
USER_ScrollBarProc( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
1379 if (!IsWindow( hwnd
)) return 0;
1384 SCROLL_CreateScrollBar(hwnd
, (LPCREATESTRUCTW
)lParam
);
1389 SCROLLBAR_INFO
*infoPtr
;
1390 if ((infoPtr
= SCROLL_GetInternalInfo( hwnd
, SB_CTL
, FALSE
)))
1392 infoPtr
->flags
= wParam
? ESB_ENABLE_BOTH
: ESB_DISABLE_BOTH
;
1393 SCROLL_RefreshScrollBar(hwnd
, SB_CTL
, TRUE
, TRUE
);
1398 case WM_LBUTTONDBLCLK
:
1399 case WM_LBUTTONDOWN
:
1400 if (GetWindowLongW( hwnd
, GWL_STYLE
) & SBS_SIZEGRIP
)
1402 SendMessageW( GetParent(hwnd
), WM_SYSCOMMAND
,
1403 SC_SIZE
+ ((GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_LAYOUTRTL
) ?
1404 WMSZ_BOTTOMLEFT
: WMSZ_BOTTOMRIGHT
), lParam
);
1409 pt
.x
= (short)LOWORD(lParam
);
1410 pt
.y
= (short)HIWORD(lParam
);
1411 SCROLL_TrackScrollBar( hwnd
, SB_CTL
, pt
);
1415 case WM_NCMOUSEMOVE
:
1416 case WM_NCMOUSELEAVE
:
1422 pt
.x
= (short)LOWORD(lParam
);
1423 pt
.y
= (short)HIWORD(lParam
);
1424 SCROLL_HandleScrollEvent( hwnd
, SB_CTL
, message
, pt
);
1429 SCROLL_HandleKbdEvent(hwnd
, wParam
, lParam
);
1438 /* Create a caret when a ScrollBar get focus */
1440 int arrowSize
, thumbSize
, thumbPos
, vertical
;
1441 vertical
= SCROLL_GetScrollBarRect( hwnd
, SB_CTL
, &rect
,
1442 &arrowSize
, &thumbSize
, &thumbPos
);
1445 CreateCaret(hwnd
, (HBITMAP
)1, thumbSize
-2, rect
.bottom
-rect
.top
-2);
1446 SetCaretPos(thumbPos
+1, rect
.top
+1);
1450 CreateCaret(hwnd
, (HBITMAP
)1, rect
.right
-rect
.left
-2,thumbSize
-2);
1451 SetCaretPos(rect
.top
+1, thumbPos
+1);
1460 int arrowSize
, thumbSize
, thumbPos
, vertical
;
1461 vertical
= SCROLL_GetScrollBarRect( hwnd
, SB_CTL
, &rect
,&arrowSize
, &thumbSize
, &thumbPos
);
1463 rect
.left
=thumbPos
+1;
1464 rect
.right
=rect
.left
+thumbSize
;
1468 rect
.top
=thumbPos
+1;
1469 rect
.bottom
=rect
.top
+thumbSize
;
1472 InvalidateRect(hwnd
,&rect
,0);
1481 return DLGC_WANTARROWS
; /* Windows returns this value */
1486 HDC hdc
= wParam
? (HDC
)wParam
: BeginPaint(hwnd
, &ps
);
1487 SCROLL_DrawScrollBar( hwnd
, hdc
, SB_CTL
, g_tracking_info
.hit_test
, &g_tracking_info
, TRUE
, TRUE
);
1488 if (!wParam
) EndPaint(hwnd
, &ps
);
1493 if (GetWindowLongW( hwnd
, GWL_STYLE
) & SBS_SIZEGRIP
)
1495 ULONG_PTR cursor
= (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_LAYOUTRTL
) ? IDC_SIZENESW
: IDC_SIZENWSE
;
1496 return (LRESULT
)SetCursor( LoadCursorA( 0, (LPSTR
)cursor
));
1498 return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1501 return SetScrollPos( hwnd
, SB_CTL
, wParam
, (BOOL
)lParam
);
1504 return SCROLL_GetScrollPos(hwnd
, SB_CTL
);
1506 case SBM_SETRANGEREDRAW
:
1509 INT oldPos
= SCROLL_GetScrollPos( hwnd
, SB_CTL
);
1510 SCROLL_SetScrollRange( hwnd
, SB_CTL
, wParam
, lParam
);
1511 if (message
== SBM_SETRANGEREDRAW
)
1512 SCROLL_RefreshScrollBar( hwnd
, SB_CTL
, TRUE
, TRUE
);
1513 if (oldPos
!= SCROLL_GetScrollPos( hwnd
, SB_CTL
)) return oldPos
;
1518 return SCROLL_GetScrollRange(hwnd
, SB_CTL
, (LPINT
)wParam
, (LPINT
)lParam
);
1520 case SBM_ENABLE_ARROWS
:
1521 return EnableScrollBar( hwnd
, SB_CTL
, wParam
);
1523 case SBM_SETSCROLLINFO
:
1524 return SCROLL_SetScrollInfo( hwnd
, SB_CTL
, (SCROLLINFO
*)lParam
, wParam
);
1526 case SBM_GETSCROLLINFO
:
1527 return SCROLL_GetScrollInfo(hwnd
, SB_CTL
, (SCROLLINFO
*)lParam
);
1529 case SBM_GETSCROLLBARINFO
:
1530 return SCROLL_GetScrollBarInfo(hwnd
, OBJID_CLIENT
, (SCROLLBARINFO
*)lParam
);
1539 ERR("unknown Win32 msg %04x wp=%08lx lp=%08lx\n",
1540 message
, wParam
, lParam
);
1544 if (message
>= WM_USER
)
1545 WARN("unknown msg %04x wp=%04lx lp=%08lx\n",
1546 message
, wParam
, lParam
);
1548 return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1550 return DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1555 /***********************************************************************
1556 * ScrollBarWndProc_common
1558 LRESULT
ScrollBarWndProc_common( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
1560 return user_api
->pScrollBarWndProc( hwnd
, msg
, wParam
, lParam
, unicode
);
1563 /*************************************************************************
1564 * SetScrollInfo (USER32.@)
1566 * SetScrollInfo can be used to set the position, upper bound,
1567 * lower bound, and page size of a scrollbar control.
1570 * hwnd [I] Handle of window with scrollbar(s)
1571 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1572 * info [I] Specifies what to change and new values
1573 * bRedraw [I] Should scrollbar be redrawn afterwards?
1576 * Scrollbar position
1579 * For 100 lines of text to be displayed in a window of 25 lines,
1580 * one would for instance use info->nMin=0, info->nMax=75
1581 * (corresponding to the 76 different positions of the window on
1582 * the text), and info->nPage=25.
1584 INT WINAPI DECLSPEC_HOTPATCH
SetScrollInfo(HWND hwnd
, INT nBar
, const SCROLLINFO
*info
, BOOL bRedraw
)
1586 TRACE("hwnd=%p nBar=%d info=%p, bRedraw=%d\n", hwnd
, nBar
, info
, bRedraw
);
1588 /* Refer SB_CTL requests to the window */
1590 return SendMessageW(hwnd
, SBM_SETSCROLLINFO
, bRedraw
, (LPARAM
)info
);
1592 return SCROLL_SetScrollInfo( hwnd
, nBar
, info
, bRedraw
);
1595 static INT
SCROLL_SetScrollInfo( HWND hwnd
, INT nBar
, LPCSCROLLINFO info
, BOOL bRedraw
)
1597 /* Update the scrollbar state and set action flags according to
1598 * what has to be done graphics wise. */
1600 SCROLLBAR_INFO
*infoPtr
;
1604 /* handle invalid data structure */
1605 if (!SCROLL_ScrollInfoValid(info
)
1606 || !(infoPtr
= SCROLL_GetInternalInfo(hwnd
, nBar
, TRUE
)))
1609 if (TRACE_ON(scroll
))
1611 TRACE("hwnd=%p bar=%d", hwnd
, nBar
);
1612 if (info
->fMask
& SIF_PAGE
) TRACE( " page=%d", info
->nPage
);
1613 if (info
->fMask
& SIF_POS
) TRACE( " pos=%d", info
->nPos
);
1614 if (info
->fMask
& SIF_RANGE
) TRACE( " min=%d max=%d", info
->nMin
, info
->nMax
);
1618 /* Set the page size */
1620 if (info
->fMask
& SIF_PAGE
)
1622 if( infoPtr
->page
!= info
->nPage
)
1624 infoPtr
->page
= info
->nPage
;
1625 action
|= SA_SSI_REFRESH
;
1629 /* Set the scroll pos */
1631 if (info
->fMask
& SIF_POS
)
1633 if( infoPtr
->curVal
!= info
->nPos
)
1635 infoPtr
->curVal
= info
->nPos
;
1636 action
|= SA_SSI_REFRESH
;
1640 /* Set the scroll range */
1642 if (info
->fMask
& SIF_RANGE
)
1644 /* Invalid range -> range is set to (0,0) */
1645 if ((info
->nMin
> info
->nMax
) ||
1646 ((UINT
)(info
->nMax
- info
->nMin
) >= 0x80000000))
1648 action
|= SA_SSI_REFRESH
;
1649 infoPtr
->minVal
= 0;
1650 infoPtr
->maxVal
= 0;
1654 if( infoPtr
->minVal
!= info
->nMin
||
1655 infoPtr
->maxVal
!= info
->nMax
)
1657 action
|= SA_SSI_REFRESH
;
1658 infoPtr
->minVal
= info
->nMin
;
1659 infoPtr
->maxVal
= info
->nMax
;
1664 /* Make sure the page size is valid */
1665 if (infoPtr
->page
< 0) infoPtr
->page
= 0;
1666 else if (infoPtr
->page
> infoPtr
->maxVal
- infoPtr
->minVal
+ 1 )
1667 infoPtr
->page
= infoPtr
->maxVal
- infoPtr
->minVal
+ 1;
1669 /* Make sure the pos is inside the range */
1671 if (infoPtr
->curVal
< infoPtr
->minVal
)
1672 infoPtr
->curVal
= infoPtr
->minVal
;
1673 else if (infoPtr
->curVal
> infoPtr
->maxVal
- max( infoPtr
->page
-1, 0 ))
1674 infoPtr
->curVal
= infoPtr
->maxVal
- max( infoPtr
->page
-1, 0 );
1676 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1677 infoPtr
->page
, infoPtr
->curVal
,
1678 infoPtr
->minVal
, infoPtr
->maxVal
);
1680 /* don't change the scrollbar state if SetScrollInfo
1681 * is just called with SIF_DISABLENOSCROLL
1683 if(!(info
->fMask
& SIF_ALL
)) goto done
;
1685 /* Check if the scrollbar should be hidden or disabled */
1687 if (info
->fMask
& (SIF_RANGE
| SIF_PAGE
| SIF_DISABLENOSCROLL
))
1689 new_flags
= infoPtr
->flags
;
1690 if (infoPtr
->minVal
>= infoPtr
->maxVal
- max( infoPtr
->page
-1, 0 ))
1692 /* Hide or disable scroll-bar */
1693 if (info
->fMask
& SIF_DISABLENOSCROLL
)
1695 new_flags
= ESB_DISABLE_BOTH
;
1696 action
|= SA_SSI_REFRESH
;
1698 else if ((nBar
!= SB_CTL
) && (action
& SA_SSI_REFRESH
))
1700 action
= SA_SSI_HIDE
;
1703 else /* Show and enable scroll-bar only if no page only changed. */
1704 if (info
->fMask
!= SIF_PAGE
)
1706 new_flags
= ESB_ENABLE_BOTH
;
1707 if ((nBar
!= SB_CTL
) && ( (action
& SA_SSI_REFRESH
) ))
1708 action
|= SA_SSI_SHOW
;
1711 if (nBar
== SB_CTL
&& bRedraw
&& IsWindowVisible(hwnd
) &&
1712 (new_flags
== ESB_ENABLE_BOTH
|| new_flags
== ESB_DISABLE_BOTH
))
1714 EnableWindow(hwnd
, new_flags
== ESB_ENABLE_BOTH
);
1717 if (infoPtr
->flags
!= new_flags
) /* check arrow flags */
1719 infoPtr
->flags
= new_flags
;
1720 action
|= SA_SSI_REPAINT_ARROWS
;
1725 if( action
& SA_SSI_HIDE
)
1726 SCROLL_ShowScrollBar( hwnd
, nBar
, FALSE
, FALSE
);
1729 if( action
& SA_SSI_SHOW
)
1730 if( SCROLL_ShowScrollBar( hwnd
, nBar
, TRUE
, TRUE
) )
1731 return infoPtr
->curVal
; /* SetWindowPos() already did the painting */
1734 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, TRUE
);
1735 else if( action
& SA_SSI_REPAINT_ARROWS
)
1736 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, FALSE
);
1739 /* Return current position */
1740 return infoPtr
->curVal
;
1744 /*************************************************************************
1745 * GetScrollInfo (USER32.@)
1747 * GetScrollInfo can be used to retrieve the position, upper bound,
1748 * lower bound, and page size of a scrollbar control.
1751 * hwnd [I] Handle of window with scrollbar(s)
1752 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1753 * info [IO] fMask specifies which values to retrieve
1756 * TRUE if SCROLLINFO is filled
1757 * ( if nBar is SB_CTL, GetScrollInfo returns TRUE even if nothing
1760 BOOL WINAPI DECLSPEC_HOTPATCH
GetScrollInfo(HWND hwnd
, INT nBar
, LPSCROLLINFO info
)
1762 TRACE("hwnd=%p nBar=%d info=%p\n", hwnd
, nBar
, info
);
1764 /* Refer SB_CTL requests to the window */
1767 SendMessageW(hwnd
, SBM_GETSCROLLINFO
, 0, (LPARAM
)info
);
1770 return SCROLL_GetScrollInfo(hwnd
, nBar
, info
);
1774 /*************************************************************************
1775 * GetScrollBarInfo (USER32.@)
1777 * GetScrollBarInfo can be used to retrieve information about a scrollbar
1781 * hwnd [I] Handle of window with scrollbar(s)
1782 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1783 * info [IO] cbSize specifies the size of SCROLLBARINFO
1788 BOOL WINAPI
GetScrollBarInfo(HWND hwnd
, LONG idObject
, LPSCROLLBARINFO info
)
1790 TRACE("hwnd=%p idObject=%d info=%p\n", hwnd
, idObject
, info
);
1792 /* Refer OBJID_CLIENT requests to the window */
1793 if (idObject
== OBJID_CLIENT
)
1794 return SendMessageW(hwnd
, SBM_GETSCROLLBARINFO
, 0, (LPARAM
)info
);
1796 return SCROLL_GetScrollBarInfo(hwnd
, idObject
, info
);
1800 /*************************************************************************
1801 * SetScrollPos (USER32.@)
1803 * Sets the current position of the scroll thumb.
1806 * hwnd [I] Handle of window with scrollbar(s)
1807 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1808 * nPos [I] New value
1809 * bRedraw [I] Should scrollbar be redrawn afterwards?
1812 * Success: Scrollbar position
1816 * Note the ambiguity when 0 is returned. Use GetLastError
1817 * to make sure there was an error (and to know which one).
1819 INT WINAPI DECLSPEC_HOTPATCH
SetScrollPos( HWND hwnd
, INT nBar
, INT nPos
, BOOL bRedraw
)
1822 SCROLLBAR_INFO
*infoPtr
;
1825 if ((infoPtr
= SCROLL_GetInternalInfo( hwnd
, nBar
, FALSE
))) oldPos
= infoPtr
->curVal
;
1826 info
.cbSize
= sizeof(info
);
1828 info
.fMask
= SIF_POS
;
1829 SetScrollInfo( hwnd
, nBar
, &info
, bRedraw
);
1834 /*************************************************************************
1835 * GetScrollPos (USER32.@)
1837 * Gets the current position of the scroll thumb.
1840 * hwnd [I] Handle of window with scrollbar(s)
1841 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1844 * Success: Current position
1848 * There is ambiguity when 0 is returned. Use GetLastError
1849 * to make sure there was an error (and to know which one).
1851 INT WINAPI DECLSPEC_HOTPATCH
GetScrollPos(HWND hwnd
, INT nBar
)
1853 TRACE("hwnd=%p nBar=%d\n", hwnd
, nBar
);
1855 /* Refer SB_CTL requests to the window */
1857 return SendMessageW(hwnd
, SBM_GETPOS
, 0, 0);
1859 return SCROLL_GetScrollPos(hwnd
, nBar
);
1863 /*************************************************************************
1864 * SetScrollRange (USER32.@)
1865 * The SetScrollRange function sets the minimum and maximum scroll box positions
1866 * If nMinPos and nMaxPos is the same value, the scroll bar will hide
1868 * Sets the range of the scroll bar.
1871 * hwnd [I] Handle of window with scrollbar(s)
1872 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1873 * minVal [I] New minimum value
1874 * maxVal [I] New Maximum value
1875 * bRedraw [I] Should scrollbar be redrawn afterwards?
1881 BOOL WINAPI DECLSPEC_HOTPATCH
SetScrollRange(HWND hwnd
, INT nBar
, INT minVal
, INT maxVal
, BOOL bRedraw
)
1885 TRACE("hwnd=%p nBar=%d min=%d max=%d, bRedraw=%d\n", hwnd
, nBar
, minVal
, maxVal
, bRedraw
);
1887 info
.cbSize
= sizeof(info
);
1888 info
.fMask
= SIF_RANGE
;
1891 SetScrollInfo( hwnd
, nBar
, &info
, bRedraw
);
1896 /*************************************************************************
1897 * GetScrollRange (USER32.@)
1899 * Gets the range of the scroll bar.
1902 * hwnd [I] Handle of window with scrollbar(s)
1903 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1904 * lpMin [O] Where to store minimum value
1905 * lpMax [O] Where to store maximum value
1908 * TRUE if values is filled
1910 BOOL WINAPI DECLSPEC_HOTPATCH
GetScrollRange(HWND hwnd
, INT nBar
, LPINT lpMin
, LPINT lpMax
)
1912 TRACE("hwnd=%p nBar=%d lpMin=%p lpMax=%p\n", hwnd
, nBar
, lpMin
, lpMax
);
1914 /* Refer SB_CTL requests to the window */
1916 SendMessageW(hwnd
, SBM_GETRANGE
, (WPARAM
)lpMin
, (LPARAM
)lpMax
);
1918 SCROLL_GetScrollRange(hwnd
, nBar
, lpMin
, lpMax
);
1924 /*************************************************************************
1925 * SCROLL_ShowScrollBar()
1927 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1929 static BOOL
SCROLL_ShowScrollBar( HWND hwnd
, INT nBar
, BOOL fShowH
, BOOL fShowV
)
1931 ULONG old_style
, set_bits
= 0, clear_bits
= 0;
1933 TRACE("hwnd=%p bar=%d horz=%d, vert=%d\n", hwnd
, nBar
, fShowH
, fShowV
);
1938 ShowWindow( hwnd
, fShowH
? SW_SHOW
: SW_HIDE
);
1943 if (fShowH
) set_bits
|= WS_HSCROLL
;
1944 else clear_bits
|= WS_HSCROLL
;
1945 if( nBar
== SB_HORZ
) break;
1948 if (fShowV
) set_bits
|= WS_VSCROLL
;
1949 else clear_bits
|= WS_VSCROLL
;
1953 return FALSE
; /* Nothing to do! */
1956 old_style
= WIN_SetStyle( hwnd
, set_bits
, clear_bits
);
1957 if ((old_style
& clear_bits
) != 0 || (old_style
& set_bits
) != set_bits
)
1959 /* frame has been changed, let the window redraw itself */
1960 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
1961 | SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
1964 return FALSE
; /* no frame changes */
1968 /*************************************************************************
1969 * ShowScrollBar (USER32.@)
1971 * Shows or hides the scroll bar.
1974 * hwnd [I] Handle of window with scrollbar(s)
1975 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1976 * fShow [I] TRUE = show, FALSE = hide
1982 BOOL WINAPI DECLSPEC_HOTPATCH
ShowScrollBar(HWND hwnd
, INT nBar
, BOOL fShow
)
1987 SCROLL_ShowScrollBar( hwnd
, nBar
, (nBar
== SB_VERT
) ? 0 : fShow
,
1988 (nBar
== SB_HORZ
) ? 0 : fShow
);
1993 /*************************************************************************
1994 * EnableScrollBar (USER32.@)
1996 * Enables or disables the scroll bars.
1998 BOOL WINAPI DECLSPEC_HOTPATCH
EnableScrollBar( HWND hwnd
, UINT nBar
, UINT flags
)
2001 SCROLLBAR_INFO
*infoPtr
;
2003 flags
&= ESB_DISABLE_BOTH
;
2005 if (nBar
== SB_BOTH
)
2007 if (!(infoPtr
= SCROLL_GetInternalInfo( hwnd
, SB_VERT
, TRUE
))) return FALSE
;
2008 if (!(bFineWithMe
= (infoPtr
->flags
== flags
)) )
2010 infoPtr
->flags
= flags
;
2011 SCROLL_RefreshScrollBar( hwnd
, SB_VERT
, TRUE
, TRUE
);
2016 bFineWithMe
= nBar
!= SB_CTL
;
2018 if (!(infoPtr
= SCROLL_GetInternalInfo( hwnd
, nBar
, TRUE
))) return FALSE
;
2019 if (bFineWithMe
&& infoPtr
->flags
== flags
) return FALSE
;
2020 infoPtr
->flags
= flags
;
2022 if (nBar
== SB_CTL
&& (flags
== ESB_DISABLE_BOTH
|| flags
== ESB_ENABLE_BOTH
))
2023 EnableWindow(hwnd
, flags
== ESB_ENABLE_BOTH
);
2025 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, TRUE
);