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
23 * This code was audited for completeness against the documented features
24 * of Comctl32.dll version 6.0 on Oct. 8, 2004, by Dimitrie O. Paun.
26 * Unless otherwise noted, we believe this code to be complete, as per
27 * the specification mentioned above.
28 * If you discover missing features, or bugs, please note them below.
36 #include "wine/winuser16.h"
39 #include "wine/debug.h"
40 #include "user_private.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(scroll
);
46 INT curVal
; /* Current scroll-bar value */
47 INT minVal
; /* Minimum scroll-bar value */
48 INT maxVal
; /* Maximum scroll-bar value */
49 INT page
; /* Page size of scroll bar (Win32) */
50 UINT flags
; /* EnableScrollBar flags */
51 } SCROLLBAR_INFO
, *LPSCROLLBAR_INFO
;
54 /* Minimum size of the rectangle between the arrows */
55 #define SCROLL_MIN_RECT 4
57 /* Minimum size of the thumb in pixels */
58 #define SCROLL_MIN_THUMB 6
60 /* Overlap between arrows and thumb */
61 #define SCROLL_ARROW_THUMB_OVERLAP 0
63 /* Delay (in ms) before first repetition when holding the button down */
64 #define SCROLL_FIRST_DELAY 200
66 /* Delay (in ms) between scroll repetitions */
67 #define SCROLL_REPEAT_DELAY 50
70 #define SCROLL_TIMER 0
72 /* Scroll-bar hit testing */
75 SCROLL_NOWHERE
, /* Outside the scroll bar */
76 SCROLL_TOP_ARROW
, /* Top or left arrow */
77 SCROLL_TOP_RECT
, /* Rectangle between the top arrow and the thumb */
78 SCROLL_THUMB
, /* Thumb rectangle */
79 SCROLL_BOTTOM_RECT
, /* Rectangle between the thumb and the bottom arrow */
80 SCROLL_BOTTOM_ARROW
/* Bottom or right arrow */
83 /* What to do after SCROLL_SetScrollInfo() */
84 #define SA_SSI_HIDE 0x0001
85 #define SA_SSI_SHOW 0x0002
86 #define SA_SSI_REFRESH 0x0004
87 #define SA_SSI_REPAINT_ARROWS 0x0008
89 /* Thumb-tracking info */
90 static HWND SCROLL_TrackingWin
= 0;
91 static INT SCROLL_TrackingBar
= 0;
92 static INT SCROLL_TrackingPos
= 0;
93 static INT SCROLL_TrackingVal
= 0;
94 /* Hit test code of the last button-down event */
95 static enum SCROLL_HITTEST SCROLL_trackHitTest
;
96 static BOOL SCROLL_trackVertical
;
98 /* Is the moving thumb being displayed? */
99 static BOOL SCROLL_MovingThumb
= FALSE
;
101 /* Local functions */
102 static BOOL
SCROLL_ShowScrollBar( HWND hwnd
, INT nBar
,
103 BOOL fShowH
, BOOL fShowV
);
104 static INT
SCROLL_SetScrollInfo( HWND hwnd
, INT nBar
,
105 const SCROLLINFO
*info
, BOOL bRedraw
);
106 static void SCROLL_DrawInterior_9x( HWND hwnd
, HDC hdc
, INT nBar
,
107 RECT
*rect
, INT arrowSize
,
108 INT thumbSize
, INT thumbPos
,
109 UINT flags
, BOOL vertical
,
110 BOOL top_selected
, BOOL bottom_selected
);
111 static LRESULT WINAPI
ScrollBarWndProc( HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
114 /*********************************************************************
115 * scrollbar class descriptor
117 const struct builtin_class_descr SCROLL_builtin_class
=
119 "ScrollBar", /* name */
120 CS_DBLCLKS
| CS_VREDRAW
| CS_HREDRAW
| CS_PARENTDC
, /* style */
121 NULL
, /* procA (winproc is Unicode only) */
122 ScrollBarWndProc
, /* procW */
123 sizeof(SCROLLBAR_INFO
), /* extra */
124 IDC_ARROW
, /* cursor */
128 /***********************************************************************
129 * SCROLL_ScrollInfoValid
131 * Determine if the supplied SCROLLINFO struct is valid.
132 * info [in] The SCROLLINFO struct to be tested
134 static inline BOOL
SCROLL_ScrollInfoValid( LPCSCROLLINFO info
)
136 return !(info
->fMask
& ~(SIF_ALL
| SIF_DISABLENOSCROLL
)
137 || (info
->cbSize
!= sizeof(*info
)
138 && info
->cbSize
!= sizeof(*info
) - sizeof(info
->nTrackPos
)));
142 /***********************************************************************
143 * SCROLL_GetInternalInfo
145 * Returns pointer to internal SCROLLBAR_INFO structure for nBar
146 * or NULL if failed (f.i. scroll bar does not exist yet)
147 * If alloc is TRUE and the struct does not exist yet, create it.
149 static SCROLLBAR_INFO
*SCROLL_GetInternalInfo( HWND hwnd
, INT nBar
, BOOL alloc
)
151 SCROLLBAR_INFO
*infoPtr
= NULL
;
152 WND
*wndPtr
= WIN_GetPtr( hwnd
);
154 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return NULL
;
157 case SB_HORZ
: infoPtr
= (SCROLLBAR_INFO
*)wndPtr
->pHScroll
; break;
158 case SB_VERT
: infoPtr
= (SCROLLBAR_INFO
*)wndPtr
->pVScroll
; break;
159 case SB_CTL
: infoPtr
= (SCROLLBAR_INFO
*)wndPtr
->wExtra
; break;
160 case SB_BOTH
: WARN("with SB_BOTH\n"); break;
163 if (!infoPtr
&& alloc
)
165 if (nBar
!= SB_HORZ
&& nBar
!= SB_VERT
)
166 WARN("Cannot initialize nBar=%d\n",nBar
);
167 else if ((infoPtr
= HeapAlloc( GetProcessHeap(), 0, sizeof(SCROLLBAR_INFO
) )))
169 /* Set default values */
170 infoPtr
->minVal
= infoPtr
->curVal
= infoPtr
->page
= 0;
171 /* From MSDN: max for a standard scroll bar is 100 by default. */
172 infoPtr
->maxVal
= 100;
173 /* Scroll bar is enabled by default after create */
174 infoPtr
->flags
= ESB_ENABLE_BOTH
;
175 if (nBar
== SB_HORZ
) wndPtr
->pHScroll
= infoPtr
;
176 else wndPtr
->pVScroll
= infoPtr
;
179 WIN_ReleasePtr( wndPtr
);
184 /***********************************************************************
185 * SCROLL_GetScrollBarRect
187 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
188 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
189 * 'arrowSize' returns the width or height of an arrow (depending on
190 * the orientation of the scrollbar), 'thumbSize' returns the size of
191 * the thumb, and 'thumbPos' returns the position of the thumb
192 * relative to the left or to the top.
193 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
195 static BOOL
SCROLL_GetScrollBarRect( HWND hwnd
, INT nBar
, RECT
*lprect
,
196 INT
*arrowSize
, INT
*thumbSize
,
201 WND
*wndPtr
= WIN_GetPtr( hwnd
);
203 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
208 lprect
->left
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
209 lprect
->top
= wndPtr
->rectClient
.bottom
- wndPtr
->rectWindow
.top
;
210 lprect
->right
= wndPtr
->rectClient
.right
- wndPtr
->rectWindow
.left
;
211 lprect
->bottom
= lprect
->top
+ GetSystemMetrics(SM_CYHSCROLL
);
212 if(wndPtr
->dwStyle
& WS_BORDER
) {
215 } else if(wndPtr
->dwStyle
& WS_VSCROLL
)
221 if((wndPtr
->dwExStyle
& WS_EX_LEFTSCROLLBAR
) != 0)
222 lprect
->left
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
- GetSystemMetrics(SM_CXVSCROLL
);
224 lprect
->left
= wndPtr
->rectClient
.right
- wndPtr
->rectWindow
.left
;
225 lprect
->top
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
226 lprect
->right
= lprect
->left
+ GetSystemMetrics(SM_CXVSCROLL
);
227 lprect
->bottom
= wndPtr
->rectClient
.bottom
- wndPtr
->rectWindow
.top
;
228 if(wndPtr
->dwStyle
& WS_BORDER
) {
231 } else if(wndPtr
->dwStyle
& WS_HSCROLL
)
237 GetClientRect( hwnd
, lprect
);
238 vertical
= ((wndPtr
->dwStyle
& SBS_VERT
) != 0);
242 WIN_ReleasePtr( wndPtr
);
246 if (vertical
) pixels
= lprect
->bottom
- lprect
->top
;
247 else pixels
= lprect
->right
- lprect
->left
;
249 if (pixels
<= 2*GetSystemMetrics(SM_CXVSCROLL
) + SCROLL_MIN_RECT
)
251 if (pixels
> SCROLL_MIN_RECT
)
252 *arrowSize
= (pixels
- SCROLL_MIN_RECT
) / 2;
255 *thumbPos
= *thumbSize
= 0;
259 SCROLLBAR_INFO
*info
= SCROLL_GetInternalInfo( hwnd
, nBar
, FALSE
);
262 WARN("called for missing scroll bar\n");
263 WIN_ReleasePtr( wndPtr
);
266 *arrowSize
= GetSystemMetrics(SM_CXVSCROLL
);
267 pixels
-= (2 * (GetSystemMetrics(SM_CXVSCROLL
) - SCROLL_ARROW_THUMB_OVERLAP
));
271 *thumbSize
= MulDiv(pixels
,info
->page
,(info
->maxVal
-info
->minVal
+1));
272 if (*thumbSize
< SCROLL_MIN_THUMB
) *thumbSize
= SCROLL_MIN_THUMB
;
274 else *thumbSize
= GetSystemMetrics(SM_CXVSCROLL
);
276 if (((pixels
-= *thumbSize
) < 0) ||
277 ((info
->flags
& ESB_DISABLE_BOTH
) == ESB_DISABLE_BOTH
))
279 /* Rectangle too small or scrollbar disabled -> no thumb */
280 *thumbPos
= *thumbSize
= 0;
284 INT max
= info
->maxVal
- max( info
->page
-1, 0 );
285 if (info
->minVal
>= max
)
286 *thumbPos
= *arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
288 *thumbPos
= *arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
289 + MulDiv(pixels
, (info
->curVal
-info
->minVal
),(max
- info
->minVal
));
292 WIN_ReleasePtr( wndPtr
);
297 /***********************************************************************
300 * Compute the current scroll position based on the thumb position in pixels
301 * from the top of the scroll-bar.
303 static UINT
SCROLL_GetThumbVal( SCROLLBAR_INFO
*infoPtr
, RECT
*rect
,
304 BOOL vertical
, INT pos
)
307 INT pixels
= vertical
? rect
->bottom
-rect
->top
: rect
->right
-rect
->left
;
309 if ((pixels
-= 2*(GetSystemMetrics(SM_CXVSCROLL
) - SCROLL_ARROW_THUMB_OVERLAP
)) <= 0)
310 return infoPtr
->minVal
;
314 thumbSize
= MulDiv(pixels
,infoPtr
->page
,(infoPtr
->maxVal
-infoPtr
->minVal
+1));
315 if (thumbSize
< SCROLL_MIN_THUMB
) thumbSize
= SCROLL_MIN_THUMB
;
317 else thumbSize
= GetSystemMetrics(SM_CXVSCROLL
);
319 if ((pixels
-= thumbSize
) <= 0) return infoPtr
->minVal
;
321 pos
= max( 0, pos
- (GetSystemMetrics(SM_CXVSCROLL
) - SCROLL_ARROW_THUMB_OVERLAP
) );
322 if (pos
> pixels
) pos
= pixels
;
324 if (!infoPtr
->page
) pos
*= infoPtr
->maxVal
- infoPtr
->minVal
;
325 else pos
*= infoPtr
->maxVal
- infoPtr
->minVal
- infoPtr
->page
+ 1;
326 return infoPtr
->minVal
+ ((pos
+ pixels
/ 2) / pixels
);
329 /***********************************************************************
332 static BOOL
SCROLL_PtInRectEx( LPRECT lpRect
, POINT pt
, BOOL vertical
)
338 rect
.left
-= lpRect
->right
- lpRect
->left
;
339 rect
.right
+= lpRect
->right
- lpRect
->left
;
343 rect
.top
-= lpRect
->bottom
- lpRect
->top
;
344 rect
.bottom
+= lpRect
->bottom
- lpRect
->top
;
346 return PtInRect( &rect
, pt
);
349 /***********************************************************************
352 static POINT
SCROLL_ClipPos( LPRECT lpRect
, POINT pt
)
354 if( pt
.x
< lpRect
->left
)
357 if( pt
.x
> lpRect
->right
)
358 pt
.x
= lpRect
->right
;
360 if( pt
.y
< lpRect
->top
)
363 if( pt
.y
> lpRect
->bottom
)
364 pt
.y
= lpRect
->bottom
;
370 /***********************************************************************
373 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
375 static enum SCROLL_HITTEST
SCROLL_HitTest( HWND hwnd
, INT nBar
,
376 POINT pt
, BOOL bDragging
)
378 INT arrowSize
, thumbSize
, thumbPos
;
381 BOOL vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
382 &arrowSize
, &thumbSize
, &thumbPos
);
384 if ( (bDragging
&& !SCROLL_PtInRectEx( &rect
, pt
, vertical
)) ||
385 (!PtInRect( &rect
, pt
)) ) return SCROLL_NOWHERE
;
389 if (pt
.y
< rect
.top
+ arrowSize
) return SCROLL_TOP_ARROW
;
390 if (pt
.y
>= rect
.bottom
- arrowSize
) return SCROLL_BOTTOM_ARROW
;
391 if (!thumbPos
) return SCROLL_TOP_RECT
;
393 if (pt
.y
< thumbPos
) return SCROLL_TOP_RECT
;
394 if (pt
.y
>= thumbPos
+ thumbSize
) return SCROLL_BOTTOM_RECT
;
396 else /* horizontal */
398 if (pt
.x
< rect
.left
+ arrowSize
) return SCROLL_TOP_ARROW
;
399 if (pt
.x
>= rect
.right
- arrowSize
) return SCROLL_BOTTOM_ARROW
;
400 if (!thumbPos
) return SCROLL_TOP_RECT
;
402 if (pt
.x
< thumbPos
) return SCROLL_TOP_RECT
;
403 if (pt
.x
>= thumbPos
+ thumbSize
) return SCROLL_BOTTOM_RECT
;
409 /***********************************************************************
412 * Draw the scroll bar arrows.
414 static void SCROLL_DrawArrows( HDC hdc
, SCROLLBAR_INFO
*infoPtr
,
415 RECT
*rect
, INT arrowSize
, BOOL vertical
,
416 BOOL top_pressed
, BOOL bottom_pressed
)
422 r
.bottom
= r
.top
+ arrowSize
;
424 r
.right
= r
.left
+ arrowSize
;
426 DrawFrameControl( hdc
, &r
, DFC_SCROLL
,
427 (vertical
? DFCS_SCROLLUP
: DFCS_SCROLLLEFT
)
428 | (top_pressed
? (DFCS_PUSHED
| DFCS_FLAT
) : 0 )
429 | (infoPtr
->flags
&ESB_DISABLE_LTUP
? DFCS_INACTIVE
: 0 ) );
433 r
.top
= r
.bottom
-arrowSize
;
435 r
.left
= r
.right
-arrowSize
;
437 DrawFrameControl( hdc
, &r
, DFC_SCROLL
,
438 (vertical
? DFCS_SCROLLDOWN
: DFCS_SCROLLRIGHT
)
439 | (bottom_pressed
? (DFCS_PUSHED
| DFCS_FLAT
) : 0 )
440 | (infoPtr
->flags
&ESB_DISABLE_RTDN
? DFCS_INACTIVE
: 0) );
443 static void SCROLL_DrawMovingThumb( HDC hdc
, RECT
*rect
, BOOL vertical
,
444 INT arrowSize
, INT thumbSize
)
446 INT pos
= SCROLL_TrackingPos
;
450 max_size
= rect
->bottom
- rect
->top
;
452 max_size
= rect
->right
- rect
->left
;
454 max_size
-= (arrowSize
-SCROLL_ARROW_THUMB_OVERLAP
) + thumbSize
;
456 if( pos
< (arrowSize
-SCROLL_ARROW_THUMB_OVERLAP
) )
457 pos
= (arrowSize
-SCROLL_ARROW_THUMB_OVERLAP
);
458 else if( pos
> max_size
)
461 SCROLL_DrawInterior_9x( SCROLL_TrackingWin
, hdc
, SCROLL_TrackingBar
,
462 rect
, arrowSize
, thumbSize
, pos
,
463 0, vertical
, FALSE
, FALSE
);
465 SCROLL_MovingThumb
= !SCROLL_MovingThumb
;
468 /***********************************************************************
469 * SCROLL_DrawInterior
471 * Draw the scroll bar interior (everything except the arrows).
473 static void SCROLL_DrawInterior_9x( HWND hwnd
, HDC hdc
, INT nBar
,
474 RECT
*rect
, INT arrowSize
,
475 INT thumbSize
, INT thumbPos
,
476 UINT flags
, BOOL vertical
,
477 BOOL top_selected
, BOOL bottom_selected
)
481 HBRUSH hSaveBrush
,hBrush
;
483 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
484 * The window-owned scrollbars need to call DEFWND_ControlColor
485 * to correctly setup default scrollbar colors
489 hBrush
= (HBRUSH
)SendMessageW( GetParent(hwnd
), WM_CTLCOLORSCROLLBAR
,
490 (WPARAM
)hdc
,(LPARAM
)hwnd
);
494 hBrush
= DEFWND_ControlColor( hdc
, CTLCOLOR_SCROLLBAR
);
497 hSavePen
= SelectObject( hdc
, SYSCOLOR_GetPen(COLOR_WINDOWFRAME
) );
498 hSaveBrush
= SelectObject( hdc
, hBrush
);
500 /* Calculate the scroll rectangle */
504 r
.top
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
505 r
.bottom
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
509 r
.left
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
510 r
.right
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
513 /* Draw the scroll rectangles and thumb */
514 if (!thumbPos
) /* No thumb to draw */
516 PatBlt( hdc
, r
.left
, r
.top
,
517 r
.right
- r
.left
, r
.bottom
- r
.top
,
520 /* cleanup and return */
521 SelectObject( hdc
, hSavePen
);
522 SelectObject( hdc
, hSaveBrush
);
528 PatBlt( hdc
, r
.left
, r
.top
,
530 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
),
531 top_selected
? 0x0f0000 : PATCOPY
);
532 r
.top
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
533 PatBlt( hdc
, r
.left
, r
.top
+ thumbSize
,
535 r
.bottom
- r
.top
- thumbSize
,
536 bottom_selected
? 0x0f0000 : PATCOPY
);
537 r
.bottom
= r
.top
+ thumbSize
;
539 else /* horizontal */
541 PatBlt( hdc
, r
.left
, r
.top
,
542 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
),
544 top_selected
? 0x0f0000 : PATCOPY
);
545 r
.left
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
546 PatBlt( hdc
, r
.left
+ thumbSize
, r
.top
,
547 r
.right
- r
.left
- thumbSize
,
549 bottom_selected
? 0x0f0000 : PATCOPY
);
550 r
.right
= r
.left
+ thumbSize
;
554 DrawEdge( hdc
, &r
, EDGE_RAISED
, BF_RECT
| BF_MIDDLE
);
557 SelectObject( hdc
, hSavePen
);
558 SelectObject( hdc
, hSaveBrush
);
562 static void SCROLL_DrawInterior( HWND hwnd
, HDC hdc
, INT nBar
,
563 RECT
*rect
, INT arrowSize
,
564 INT thumbSize
, INT thumbPos
,
565 UINT flags
, BOOL vertical
,
566 BOOL top_selected
, BOOL bottom_selected
)
570 HBRUSH hSaveBrush
,hBrush
;
571 BOOL Save_SCROLL_MovingThumb
= SCROLL_MovingThumb
;
573 if (Save_SCROLL_MovingThumb
&&
574 (SCROLL_TrackingWin
== hwnd
) &&
575 (SCROLL_TrackingBar
== nBar
))
576 SCROLL_DrawMovingThumb( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
578 /* Select the correct brush and pen */
580 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
581 * The window-owned scrollbars need to call DEFWND_ControlColor
582 * to correctly setup default scrollbar colors
584 if (nBar
== SB_CTL
) {
585 hBrush
= (HBRUSH
)SendMessageW( GetParent(hwnd
), WM_CTLCOLORSCROLLBAR
,
586 (WPARAM
)hdc
,(LPARAM
)hwnd
);
588 hBrush
= DEFWND_ControlColor( hdc
, CTLCOLOR_SCROLLBAR
);
590 hSavePen
= SelectObject( hdc
, SYSCOLOR_GetPen(COLOR_WINDOWFRAME
) );
591 hSaveBrush
= SelectObject( hdc
, hBrush
);
593 /* Calculate the scroll rectangle */
598 r
.top
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
599 r
.bottom
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
603 r
.left
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
604 r
.right
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
607 /* Draw the scroll bar frame */
609 /* Draw the scroll rectangles and thumb */
611 if (!thumbPos
) /* No thumb to draw */
613 PatBlt( hdc
, r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
, PATCOPY
);
615 /* cleanup and return */
616 SelectObject( hdc
, hSavePen
);
617 SelectObject( hdc
, hSaveBrush
);
623 PatBlt( hdc
, r
.left
, r
.top
, r
.right
- r
.left
,
624 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
),
625 top_selected
? 0x0f0000 : PATCOPY
);
626 r
.top
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
627 PatBlt( hdc
, r
.left
, r
.top
+ thumbSize
, r
.right
- r
.left
,
628 r
.bottom
- r
.top
- thumbSize
,
629 bottom_selected
? 0x0f0000 : PATCOPY
);
630 r
.bottom
= r
.top
+ thumbSize
;
632 else /* horizontal */
634 PatBlt( hdc
, r
.left
, r
.top
,
635 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
),
636 r
.bottom
- r
.top
, top_selected
? 0x0f0000 : PATCOPY
);
637 r
.left
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
638 PatBlt( hdc
, r
.left
+ thumbSize
, r
.top
, r
.right
- r
.left
- thumbSize
,
639 r
.bottom
- r
.top
, bottom_selected
? 0x0f0000 : PATCOPY
);
640 r
.right
= r
.left
+ thumbSize
;
645 SelectObject( hdc
, GetSysColorBrush(COLOR_BTNFACE
) );
646 Rectangle( hdc
, r
.left
+1, r
.top
+1, r
.right
-1, r
.bottom
-1 );
647 DrawEdge( hdc
, &r
, EDGE_RAISED
, BF_RECT
);
649 if (Save_SCROLL_MovingThumb
&&
650 (SCROLL_TrackingWin
== hwnd
) &&
651 (SCROLL_TrackingBar
== nBar
))
652 SCROLL_DrawMovingThumb( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
655 SelectObject( hdc
, hSavePen
);
656 SelectObject( hdc
, hSaveBrush
);
660 /***********************************************************************
661 * SCROLL_DrawScrollBar
663 * Redraw the whole scrollbar.
665 void SCROLL_DrawScrollBar( HWND hwnd
, HDC hdc
, INT nBar
,
666 BOOL arrows
, BOOL interior
)
668 INT arrowSize
, thumbSize
, thumbPos
;
671 SCROLLBAR_INFO
*infoPtr
= SCROLL_GetInternalInfo( hwnd
, nBar
, TRUE
);
672 BOOL Save_SCROLL_MovingThumb
= SCROLL_MovingThumb
;
673 DWORD style
= GetWindowLongW( hwnd
, GWL_STYLE
);
675 if (!(hwnd
= WIN_GetFullHandle( hwnd
))) return;
678 ((nBar
== SB_VERT
) && !(style
& WS_VSCROLL
)) ||
679 ((nBar
== SB_HORZ
) && !(style
& WS_HSCROLL
))) return;
680 if (!WIN_IsWindowDrawable( hwnd
, FALSE
)) return;
682 vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
683 &arrowSize
, &thumbSize
, &thumbPos
);
685 /* do not draw if the scrollbar rectangle is empty */
686 if(IsRectEmpty(&rect
)) return;
688 if (Save_SCROLL_MovingThumb
&&
689 (SCROLL_TrackingWin
== hwnd
) &&
690 (SCROLL_TrackingBar
== nBar
))
691 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
693 /* Draw the arrows */
695 if (arrows
&& arrowSize
)
697 if( vertical
== SCROLL_trackVertical
&& GetCapture() == hwnd
)
698 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
699 (SCROLL_trackHitTest
== SCROLL_TOP_ARROW
),
700 (SCROLL_trackHitTest
== SCROLL_BOTTOM_ARROW
) );
702 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
706 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
707 thumbPos
, infoPtr
->flags
, vertical
, FALSE
, FALSE
);
709 if (Save_SCROLL_MovingThumb
&&
710 (SCROLL_TrackingWin
== hwnd
) &&
711 (SCROLL_TrackingBar
== nBar
))
712 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
714 /* if scroll bar has focus, reposition the caret */
715 if(hwnd
==GetFocus() && (nBar
==SB_CTL
))
719 SetCaretPos(thumbPos
+1, rect
.top
+1);
723 SetCaretPos(rect
.top
+1, thumbPos
+1);
728 /***********************************************************************
729 * SCROLL_DrawSizeGrip
731 * Draw the size grip.
733 static void SCROLL_DrawSizeGrip( HWND hwnd
, HDC hdc
)
737 GetClientRect( hwnd
, &rc
);
738 FillRect( hdc
, &rc
, GetSysColorBrush(COLOR_SCROLLBAR
) );
739 rc
.left
= max( rc
.left
, rc
.right
- GetSystemMetrics(SM_CXVSCROLL
) - 1 );
740 rc
.top
= max( rc
.top
, rc
.bottom
- GetSystemMetrics(SM_CYHSCROLL
) - 1 );
741 DrawFrameControl( hdc
, &rc
, DFC_SCROLL
, DFCS_SCROLLSIZEGRIP
);
745 /***********************************************************************
746 * SCROLL_RefreshScrollBar
748 * Repaint the scroll bar interior after a SetScrollRange() or
749 * SetScrollPos() call.
751 static void SCROLL_RefreshScrollBar( HWND hwnd
, INT nBar
,
752 BOOL arrows
, BOOL interior
)
754 HDC hdc
= GetDCEx( hwnd
, 0,
755 DCX_CACHE
| ((nBar
== SB_CTL
) ? 0 : DCX_WINDOW
) );
758 SCROLL_DrawScrollBar( hwnd
, hdc
, nBar
, arrows
, interior
);
759 ReleaseDC( hwnd
, hdc
);
763 /***********************************************************************
764 * SCROLL_HandleKbdEvent
766 * Handle a keyboard event (only for SB_CTL scrollbars with focus).
769 * hwnd [I] Handle of window with scrollbar(s)
770 * wParam [I] Variable input including enable state
771 * lParam [I] Variable input including input point
773 static void SCROLL_HandleKbdEvent(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
775 TRACE("hwnd=%p wParam=%d lParam=%ld\n", hwnd
, wParam
, lParam
);
777 /* hide caret on first KEYDOWN to prevent flicker */
778 if ((lParam
& PFD_DOUBLEBUFFER_DONTCARE
) == 0)
783 case VK_PRIOR
: wParam
= SB_PAGEUP
; break;
784 case VK_NEXT
: wParam
= SB_PAGEDOWN
; break;
785 case VK_HOME
: wParam
= SB_TOP
; break;
786 case VK_END
: wParam
= SB_BOTTOM
; break;
787 case VK_UP
: wParam
= SB_LINEUP
; break;
788 case VK_DOWN
: wParam
= SB_LINEDOWN
; break;
789 case VK_LEFT
: wParam
= SB_LINEUP
; break;
790 case VK_RIGHT
: wParam
= SB_LINEDOWN
; break;
793 SendMessageW(GetParent(hwnd
),
794 ((GetWindowLongW( hwnd
, GWL_STYLE
) & SBS_VERT
) ?
795 WM_VSCROLL
: WM_HSCROLL
), wParam
, (LPARAM
)hwnd
);
799 /***********************************************************************
800 * SCROLL_HandleScrollEvent
802 * Handle a mouse or timer event for the scrollbar.
803 * 'pt' is the location of the mouse event in client (for SB_CTL) or
804 * windows coordinates.
806 static void SCROLL_HandleScrollEvent( HWND hwnd
, INT nBar
, UINT msg
, POINT pt
)
808 /* Previous mouse position for timer events */
810 /* Thumb position when tracking started. */
811 static UINT trackThumbPos
;
812 /* Position in the scroll-bar of the last button-down event. */
813 static INT lastClickPos
;
814 /* Position in the scroll-bar of the last mouse event. */
815 static INT lastMousePos
;
817 enum SCROLL_HITTEST hittest
;
818 HWND hwndOwner
, hwndCtl
;
820 INT arrowSize
, thumbSize
, thumbPos
;
824 SCROLLBAR_INFO
*infoPtr
= SCROLL_GetInternalInfo( hwnd
, nBar
, FALSE
);
825 if (!infoPtr
) return;
826 if ((SCROLL_trackHitTest
== SCROLL_NOWHERE
) && (msg
!= WM_LBUTTONDOWN
))
829 if (nBar
== SB_CTL
&& (GetWindowLongW( hwnd
, GWL_STYLE
) & (SBS_SIZEGRIP
| SBS_SIZEBOX
)))
833 case WM_LBUTTONDOWN
: /* Initialise mouse tracking */
834 HideCaret(hwnd
); /* hide caret while holding down LBUTTON */
837 SCROLL_trackHitTest
= hittest
= SCROLL_THUMB
;
840 GetClientRect(GetParent(GetParent(hwnd
)),&rect
);
845 SCROLL_trackHitTest
= hittest
= SCROLL_NOWHERE
;
846 if (hwnd
==GetFocus()) ShowCaret(hwnd
);
855 hdc
= GetDCEx( hwnd
, 0, DCX_CACHE
| ((nBar
== SB_CTL
) ? 0 : DCX_WINDOW
));
856 vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
857 &arrowSize
, &thumbSize
, &thumbPos
);
858 hwndOwner
= (nBar
== SB_CTL
) ? GetParent(hwnd
) : hwnd
;
859 hwndCtl
= (nBar
== SB_CTL
) ? hwnd
: 0;
863 case WM_LBUTTONDOWN
: /* Initialise mouse tracking */
864 HideCaret(hwnd
); /* hide caret while holding down LBUTTON */
865 SCROLL_trackVertical
= vertical
;
866 SCROLL_trackHitTest
= hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, FALSE
);
867 lastClickPos
= vertical
? (pt
.y
- rect
.top
) : (pt
.x
- rect
.left
);
868 lastMousePos
= lastClickPos
;
869 trackThumbPos
= thumbPos
;
871 if (nBar
== SB_CTL
&& (GetWindowLongW(hwnd
, GWL_STYLE
) & WS_TABSTOP
)) SetFocus( hwnd
);
876 hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, TRUE
);
881 hittest
= SCROLL_NOWHERE
;
883 /* if scrollbar has focus, show back caret */
884 if (hwnd
==GetFocus()) ShowCaret(hwnd
);
889 hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, FALSE
);
893 return; /* Should never happen */
896 TRACE("Event: hwnd=%p bar=%d msg=%s pt=%d,%d hit=%d\n",
897 hwnd
, nBar
, SPY_GetMsgName(msg
,hwnd
), pt
.x
, pt
.y
, hittest
);
899 switch(SCROLL_trackHitTest
)
901 case SCROLL_NOWHERE
: /* No tracking in progress */
904 case SCROLL_TOP_ARROW
:
905 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
906 (hittest
== SCROLL_trackHitTest
), FALSE
);
907 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
908 thumbPos
, infoPtr
->flags
, vertical
,
909 (hittest
== SCROLL_trackHitTest
), FALSE
);
910 if (hittest
== SCROLL_trackHitTest
)
912 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
914 SendMessageW( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
915 SB_LINEUP
, (LPARAM
)hwndCtl
);
918 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
919 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
922 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
925 case SCROLL_TOP_RECT
:
926 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
927 thumbPos
, infoPtr
->flags
, vertical
,
928 (hittest
== SCROLL_trackHitTest
), FALSE
);
929 if (hittest
== SCROLL_trackHitTest
)
931 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
933 SendMessageW( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
934 SB_PAGEUP
, (LPARAM
)hwndCtl
);
936 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
937 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
940 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
944 if (msg
== WM_LBUTTONDOWN
)
946 SCROLL_TrackingWin
= hwnd
;
947 SCROLL_TrackingBar
= nBar
;
948 SCROLL_TrackingPos
= trackThumbPos
+ lastMousePos
- lastClickPos
;
949 SCROLL_TrackingVal
= SCROLL_GetThumbVal( infoPtr
, &rect
,
951 SCROLL_TrackingPos
);
952 if (!SCROLL_MovingThumb
)
953 SCROLL_DrawMovingThumb(hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
955 else if (msg
== WM_LBUTTONUP
)
957 if (SCROLL_MovingThumb
)
958 SCROLL_DrawMovingThumb(hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
960 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
961 thumbPos
, infoPtr
->flags
, vertical
,
964 else /* WM_MOUSEMOVE */
968 if (!SCROLL_PtInRectEx( &rect
, pt
, vertical
)) pos
= lastClickPos
;
971 pt
= SCROLL_ClipPos( &rect
, pt
);
972 pos
= vertical
? (pt
.y
- rect
.top
) : (pt
.x
- rect
.left
);
974 if ( (pos
!= lastMousePos
) || (!SCROLL_MovingThumb
) )
976 if (SCROLL_MovingThumb
)
977 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
,
978 arrowSize
, thumbSize
);
980 SCROLL_TrackingPos
= trackThumbPos
+ pos
- lastClickPos
;
981 SCROLL_TrackingVal
= SCROLL_GetThumbVal( infoPtr
, &rect
,
983 SCROLL_TrackingPos
);
984 SendMessageW( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
985 MAKEWPARAM( SB_THUMBTRACK
, SCROLL_TrackingVal
),
987 if (!SCROLL_MovingThumb
)
988 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
,
989 arrowSize
, thumbSize
);
994 case SCROLL_BOTTOM_RECT
:
995 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
996 thumbPos
, infoPtr
->flags
, vertical
,
997 FALSE
, (hittest
== SCROLL_trackHitTest
) );
998 if (hittest
== SCROLL_trackHitTest
)
1000 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
1002 SendMessageW( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1003 SB_PAGEDOWN
, (LPARAM
)hwndCtl
);
1005 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
1006 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
1009 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
1012 case SCROLL_BOTTOM_ARROW
:
1013 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
1014 FALSE
, (hittest
== SCROLL_trackHitTest
) );
1015 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
1016 thumbPos
, infoPtr
->flags
, vertical
,
1017 FALSE
, (hittest
== SCROLL_trackHitTest
) );
1018 if (hittest
== SCROLL_trackHitTest
)
1020 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
1022 SendMessageW( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1023 SB_LINEDOWN
, (LPARAM
)hwndCtl
);
1026 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
1027 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
1030 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
1034 if (msg
== WM_LBUTTONDOWN
)
1037 if (hittest
== SCROLL_THUMB
)
1039 UINT val
= SCROLL_GetThumbVal( infoPtr
, &rect
, vertical
,
1040 trackThumbPos
+ lastMousePos
- lastClickPos
);
1041 SendMessageW( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1042 MAKEWPARAM( SB_THUMBTRACK
, val
), (LPARAM
)hwndCtl
);
1046 if (msg
== WM_LBUTTONUP
)
1048 hittest
= SCROLL_trackHitTest
;
1049 SCROLL_trackHitTest
= SCROLL_NOWHERE
; /* Terminate tracking */
1051 if (hittest
== SCROLL_THUMB
)
1053 UINT val
= SCROLL_GetThumbVal( infoPtr
, &rect
, vertical
,
1054 trackThumbPos
+ lastMousePos
- lastClickPos
);
1055 SendMessageW( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1056 MAKEWPARAM( SB_THUMBPOSITION
, val
), (LPARAM
)hwndCtl
);
1058 /* SB_ENDSCROLL doesn't report thumb position */
1059 SendMessageW( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1060 SB_ENDSCROLL
, (LPARAM
)hwndCtl
);
1062 /* Terminate tracking */
1063 SCROLL_TrackingWin
= 0;
1066 ReleaseDC( hwnd
, hdc
);
1070 /***********************************************************************
1071 * SCROLL_TrackScrollBar
1073 * Track a mouse button press on a scroll-bar.
1074 * pt is in screen-coordinates for non-client scroll bars.
1076 void SCROLL_TrackScrollBar( HWND hwnd
, INT scrollbar
, POINT pt
)
1079 INT xoffset
= 0, yoffset
= 0;
1081 if (scrollbar
!= SB_CTL
)
1083 WND
*wndPtr
= WIN_GetPtr( hwnd
);
1084 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return;
1085 xoffset
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
1086 yoffset
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
1087 WIN_ReleasePtr( wndPtr
);
1088 ScreenToClient( hwnd
, &pt
);
1093 SCROLL_HandleScrollEvent( hwnd
, scrollbar
, WM_LBUTTONDOWN
, pt
);
1097 if (!GetMessageW( &msg
, 0, 0, 0 )) break;
1098 if (CallMsgFilterW( &msg
, MSGF_SCROLLBAR
)) continue;
1099 if (msg
.message
== WM_LBUTTONUP
||
1100 msg
.message
== WM_MOUSEMOVE
||
1101 (msg
.message
== WM_SYSTIMER
&& msg
.wParam
== SCROLL_TIMER
))
1103 pt
.x
= (short)LOWORD(msg
.lParam
) + xoffset
;
1104 pt
.y
= (short)HIWORD(msg
.lParam
) + yoffset
;
1105 SCROLL_HandleScrollEvent( hwnd
, scrollbar
, msg
.message
, pt
);
1109 TranslateMessage( &msg
);
1110 DispatchMessageW( &msg
);
1112 if (!IsWindow( hwnd
))
1117 } while (msg
.message
!= WM_LBUTTONUP
);
1121 /***********************************************************************
1122 * SCROLL_CreateScrollBar
1124 * Create a scroll bar
1127 * hwnd [I] Handle of window with scrollbar(s)
1128 * lpCreate [I] The style and place of the scroll bar
1130 static void SCROLL_CreateScrollBar(HWND hwnd
, LPCREATESTRUCTW lpCreate
)
1132 LPSCROLLBAR_INFO info
= SCROLL_GetInternalInfo(hwnd
, SB_CTL
, TRUE
);
1135 TRACE("hwnd=%p lpCreate=%p\n", hwnd
, lpCreate
);
1137 if (lpCreate
->style
& WS_DISABLED
)
1139 info
->flags
= ESB_DISABLE_BOTH
;
1140 TRACE("Created WS_DISABLED scrollbar\n");
1144 if (lpCreate
->style
& (SBS_SIZEGRIP
| SBS_SIZEBOX
))
1146 if (lpCreate
->style
& SBS_SIZEBOXTOPLEFTALIGN
)
1147 MoveWindow( hwnd
, lpCreate
->x
, lpCreate
->y
, GetSystemMetrics(SM_CXVSCROLL
)+1,
1148 GetSystemMetrics(SM_CYHSCROLL
)+1, FALSE
);
1149 else if(lpCreate
->style
& SBS_SIZEBOXBOTTOMRIGHTALIGN
)
1150 MoveWindow( hwnd
, lpCreate
->x
+lpCreate
->cx
-GetSystemMetrics(SM_CXVSCROLL
)-1,
1151 lpCreate
->y
+lpCreate
->cy
-GetSystemMetrics(SM_CYHSCROLL
)-1,
1152 GetSystemMetrics(SM_CXVSCROLL
)+1,
1153 GetSystemMetrics(SM_CYHSCROLL
)+1, FALSE
);
1155 else if (lpCreate
->style
& SBS_VERT
)
1157 if (lpCreate
->style
& SBS_LEFTALIGN
)
1158 MoveWindow( hwnd
, lpCreate
->x
, lpCreate
->y
,
1159 GetSystemMetrics(SM_CXVSCROLL
)+1, lpCreate
->cy
, FALSE
);
1160 else if (lpCreate
->style
& SBS_RIGHTALIGN
)
1162 lpCreate
->x
+lpCreate
->cx
-GetSystemMetrics(SM_CXVSCROLL
)-1,
1164 GetSystemMetrics(SM_CXVSCROLL
)+1, lpCreate
->cy
, FALSE
);
1168 if (lpCreate
->style
& SBS_TOPALIGN
)
1169 MoveWindow( hwnd
, lpCreate
->x
, lpCreate
->y
,
1170 lpCreate
->cx
, GetSystemMetrics(SM_CYHSCROLL
)+1, FALSE
);
1171 else if (lpCreate
->style
& SBS_BOTTOMALIGN
)
1174 lpCreate
->y
+lpCreate
->cy
-GetSystemMetrics(SM_CYHSCROLL
)-1,
1175 lpCreate
->cx
, GetSystemMetrics(SM_CYHSCROLL
)+1, FALSE
);
1180 /*************************************************************************
1181 * SCROLL_GetScrollInfo
1183 * Internal helper for the API function
1186 * hwnd [I] Handle of window with scrollbar(s)
1187 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1188 * info [IO] fMask specifies which values to retrieve
1191 * FALSE if requested field not filled (f.i. scroll bar does not exist)
1193 static BOOL
SCROLL_GetScrollInfo(HWND hwnd
, INT nBar
, LPSCROLLINFO info
)
1195 LPSCROLLBAR_INFO infoPtr
;
1197 /* handle invalid data structure */
1198 if (!SCROLL_ScrollInfoValid(info
)
1199 || !(infoPtr
= SCROLL_GetInternalInfo(hwnd
, nBar
, FALSE
)))
1202 /* fill in the desired scroll info structure */
1203 if (info
->fMask
& SIF_PAGE
) info
->nPage
= infoPtr
->page
;
1204 if (info
->fMask
& SIF_POS
) info
->nPos
= infoPtr
->curVal
;
1205 if ((info
->fMask
& SIF_TRACKPOS
) && (info
->cbSize
== sizeof(*info
)))
1206 info
->nTrackPos
= (SCROLL_TrackingWin
== WIN_GetFullHandle(hwnd
)) ? SCROLL_TrackingVal
: infoPtr
->curVal
;
1207 if (info
->fMask
& SIF_RANGE
)
1209 info
->nMin
= infoPtr
->minVal
;
1210 info
->nMax
= infoPtr
->maxVal
;
1213 TRACE("cbSize %02x fMask %04x nMin %d nMax %d nPage %u nPos %d nTrackPos %d\n",
1214 info
->cbSize
, info
->fMask
, info
->nMin
, info
->nMax
, info
->nPage
,
1215 info
->nPos
, info
->nTrackPos
);
1217 return (info
->fMask
& SIF_ALL
) != 0;
1221 /*************************************************************************
1222 * SCROLL_GetScrollBarInfo
1224 * Internal helper for the API function
1227 * hwnd [I] Handle of window with scrollbar(s)
1228 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1229 * info [IO] cbSize specifies the size of the structure
1234 static BOOL
SCROLL_GetScrollBarInfo(HWND hwnd
, LONG idObject
, LPSCROLLBARINFO info
)
1236 LPSCROLLBAR_INFO infoPtr
;
1239 DWORD style
= GetWindowLongW(hwnd
, GWL_STYLE
);
1244 case OBJID_CLIENT
: nBar
= SB_CTL
; break;
1245 case OBJID_HSCROLL
: nBar
= SB_HORZ
; break;
1246 case OBJID_VSCROLL
: nBar
= SB_VERT
; break;
1247 default: return FALSE
;
1250 /* handle invalid data structure */
1251 if (info
->cbSize
!= sizeof(*info
))
1254 SCROLL_GetScrollBarRect(hwnd
, nBar
, &info
->rcScrollBar
, &nDummy
,
1255 &info
->dxyLineButton
, &info
->xyThumbTop
);
1257 info
->xyThumbBottom
= info
->xyThumbTop
+ info
->dxyLineButton
;
1259 infoPtr
= SCROLL_GetInternalInfo(hwnd
, nBar
, TRUE
);
1261 /* Scroll bar state */
1262 info
->rgstate
[0] = 0;
1263 if ((nBar
== SB_HORZ
&& !(style
& WS_HSCROLL
))
1264 || (nBar
== SB_VERT
&& !(style
& WS_VSCROLL
)))
1265 info
->rgstate
[0] |= STATE_SYSTEM_INVISIBLE
;
1266 if (infoPtr
->minVal
>= infoPtr
->maxVal
- max(infoPtr
->page
- 1, 0))
1268 if (!(info
->rgstate
[0] & STATE_SYSTEM_INVISIBLE
))
1269 info
->rgstate
[0] |= STATE_SYSTEM_UNAVAILABLE
;
1271 info
->rgstate
[0] |= STATE_SYSTEM_OFFSCREEN
;
1273 if (nBar
== SB_CTL
&& !IsWindowEnabled(hwnd
))
1274 info
->rgstate
[0] |= STATE_SYSTEM_UNAVAILABLE
;
1276 pressed
= ((nBar
== SB_VERT
) == SCROLL_trackVertical
&& GetCapture() == hwnd
);
1278 /* Top/left arrow button state. MSDN says top/right, but I don't believe it */
1279 info
->rgstate
[1] = 0;
1280 if (pressed
&& SCROLL_trackHitTest
== SCROLL_TOP_ARROW
)
1281 info
->rgstate
[1] |= STATE_SYSTEM_PRESSED
;
1282 if (infoPtr
->flags
& ESB_DISABLE_LTUP
)
1283 info
->rgstate
[1] |= STATE_SYSTEM_UNAVAILABLE
;
1285 /* Page up/left region state. MSDN says up/right, but I don't believe it */
1286 info
->rgstate
[2] = 0;
1287 if (infoPtr
->curVal
== infoPtr
->minVal
)
1288 info
->rgstate
[2] |= STATE_SYSTEM_INVISIBLE
;
1289 if (pressed
&& SCROLL_trackHitTest
== SCROLL_TOP_RECT
)
1290 info
->rgstate
[2] |= STATE_SYSTEM_PRESSED
;
1293 info
->rgstate
[3] = 0;
1294 if (pressed
&& SCROLL_trackHitTest
== SCROLL_THUMB
)
1295 info
->rgstate
[3] |= STATE_SYSTEM_PRESSED
;
1297 /* Page down/right region state. MSDN says down/left, but I don't believe it */
1298 info
->rgstate
[4] = 0;
1299 if (infoPtr
->curVal
>= infoPtr
->maxVal
- 1)
1300 info
->rgstate
[4] |= STATE_SYSTEM_INVISIBLE
;
1301 if (pressed
&& SCROLL_trackHitTest
== SCROLL_BOTTOM_RECT
)
1302 info
->rgstate
[4] |= STATE_SYSTEM_PRESSED
;
1304 /* Bottom/right arrow button state. MSDN says bottom/left, but I don't believe it */
1305 info
->rgstate
[5] = 0;
1306 if (pressed
&& SCROLL_trackHitTest
== SCROLL_BOTTOM_ARROW
)
1307 info
->rgstate
[5] |= STATE_SYSTEM_PRESSED
;
1308 if (infoPtr
->flags
& ESB_DISABLE_RTDN
)
1309 info
->rgstate
[5] |= STATE_SYSTEM_UNAVAILABLE
;
1315 /*************************************************************************
1316 * SCROLL_GetScrollPos
1318 * Internal helper for the API function
1321 * hwnd [I] Handle of window with scrollbar(s)
1322 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1324 static INT
SCROLL_GetScrollPos(HWND hwnd
, INT nBar
)
1326 LPSCROLLBAR_INFO infoPtr
= SCROLL_GetInternalInfo(hwnd
, nBar
, FALSE
);
1327 return infoPtr
? infoPtr
->curVal
: 0;
1331 /*************************************************************************
1332 * SCROLL_GetScrollRange
1334 * Internal helper for the API function
1337 * hwnd [I] Handle of window with scrollbar(s)
1338 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1339 * lpMin [O] Where to store minimum value
1340 * lpMax [O] Where to store maximum value
1346 static BOOL
SCROLL_GetScrollRange(HWND hwnd
, INT nBar
, LPINT lpMin
, LPINT lpMax
)
1348 LPSCROLLBAR_INFO infoPtr
= SCROLL_GetInternalInfo(hwnd
, nBar
, FALSE
);
1350 if (lpMin
) *lpMin
= infoPtr
? infoPtr
->minVal
: 0;
1351 if (lpMax
) *lpMax
= infoPtr
? infoPtr
->maxVal
: 0;
1357 /*************************************************************************
1358 * SCROLL_SetScrollRange
1361 * hwnd [I] Handle of window with scrollbar(s)
1362 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1363 * lpMin [I] Minimum value
1364 * lpMax [I] Maximum value
1367 static BOOL
SCROLL_SetScrollRange(HWND hwnd
, INT nBar
, INT minVal
, INT maxVal
)
1369 LPSCROLLBAR_INFO infoPtr
= SCROLL_GetInternalInfo(hwnd
, nBar
, FALSE
);
1371 TRACE("hwnd=%p nBar=%d min=%d max=%d\n", hwnd
, nBar
, minVal
, maxVal
);
1375 infoPtr
->minVal
= minVal
;
1376 infoPtr
->maxVal
= maxVal
;
1382 /***********************************************************************
1385 static LRESULT WINAPI
ScrollBarWndProc( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1387 if (!IsWindow( hwnd
)) return 0;
1392 SCROLL_CreateScrollBar(hwnd
, (LPCREATESTRUCTW
)lParam
);
1397 SCROLLBAR_INFO
*infoPtr
;
1398 if ((infoPtr
= SCROLL_GetInternalInfo( hwnd
, SB_CTL
, FALSE
)))
1400 infoPtr
->flags
= wParam
? ESB_ENABLE_BOTH
: ESB_DISABLE_BOTH
;
1401 SCROLL_RefreshScrollBar(hwnd
, SB_CTL
, TRUE
, TRUE
);
1406 case WM_LBUTTONDBLCLK
:
1407 case WM_LBUTTONDOWN
:
1410 pt
.x
= (short)LOWORD(lParam
);
1411 pt
.y
= (short)HIWORD(lParam
);
1412 SCROLL_TrackScrollBar( hwnd
, SB_CTL
, pt
);
1420 pt
.x
= (short)LOWORD(lParam
);
1421 pt
.y
= (short)HIWORD(lParam
);
1422 SCROLL_HandleScrollEvent( hwnd
, SB_CTL
, message
, pt
);
1427 SCROLL_HandleKbdEvent(hwnd
, wParam
, lParam
);
1436 /* Create a caret when a ScrollBar get focus */
1438 int arrowSize
, thumbSize
, thumbPos
, vertical
;
1439 vertical
= SCROLL_GetScrollBarRect( hwnd
, SB_CTL
, &rect
,
1440 &arrowSize
, &thumbSize
, &thumbPos
);
1443 CreateCaret(hwnd
, (HBITMAP
)1, thumbSize
-2, rect
.bottom
-rect
.top
-2);
1444 SetCaretPos(thumbPos
+1, rect
.top
+1);
1448 CreateCaret(hwnd
, (HBITMAP
)1, rect
.right
-rect
.left
-2,thumbSize
-2);
1449 SetCaretPos(rect
.top
+1, thumbPos
+1);
1458 int arrowSize
, thumbSize
, thumbPos
, vertical
;
1459 vertical
= SCROLL_GetScrollBarRect( hwnd
, SB_CTL
, &rect
,&arrowSize
, &thumbSize
, &thumbPos
);
1461 rect
.left
=thumbPos
+1;
1462 rect
.right
=rect
.left
+thumbSize
;
1466 rect
.top
=thumbPos
+1;
1467 rect
.bottom
=rect
.top
+thumbSize
;
1470 InvalidateRect(hwnd
,&rect
,0);
1479 return DLGC_WANTARROWS
; /* Windows returns this value */
1484 HDC hdc
= wParam
? (HDC
)wParam
: BeginPaint(hwnd
, &ps
);
1485 if (GetWindowLongW( hwnd
, GWL_STYLE
) & SBS_SIZEGRIP
)
1487 SCROLL_DrawSizeGrip( hwnd
, hdc
);
1489 else if (GetWindowLongW( hwnd
, GWL_STYLE
) & SBS_SIZEBOX
)
1492 GetClientRect( hwnd
, &rc
);
1493 FillRect( hdc
, &rc
, GetSysColorBrush(COLOR_SCROLLBAR
) );
1496 SCROLL_DrawScrollBar( hwnd
, hdc
, SB_CTL
, TRUE
, TRUE
);
1497 if (!wParam
) EndPaint(hwnd
, &ps
);
1503 return SetScrollPos( hwnd
, SB_CTL
, wParam
, (BOOL
)lParam
);
1507 return SCROLL_GetScrollPos(hwnd
, SB_CTL
);
1509 case SBM_SETRANGE16
:
1510 if (wParam
) message
= SBM_SETRANGEREDRAW
;
1511 wParam
= LOWORD(lParam
);
1512 lParam
= HIWORD(lParam
);
1514 case SBM_SETRANGEREDRAW
:
1517 INT oldPos
= SCROLL_GetScrollPos( hwnd
, SB_CTL
);
1518 SCROLL_SetScrollRange( hwnd
, SB_CTL
, wParam
, lParam
);
1519 if (message
== SBM_SETRANGEREDRAW
)
1520 SCROLL_RefreshScrollBar( hwnd
, SB_CTL
, TRUE
, TRUE
);
1521 if (oldPos
!= SCROLL_GetScrollPos( hwnd
, SB_CTL
)) return oldPos
;
1525 case SBM_GETRANGE16
:
1529 SCROLL_GetScrollRange(hwnd
, SB_CTL
, &min
, &max
);
1530 return MAKELRESULT(min
, max
);
1534 return SCROLL_GetScrollRange(hwnd
, SB_CTL
, (LPINT
)wParam
, (LPINT
)lParam
);
1536 case SBM_ENABLE_ARROWS16
:
1537 case SBM_ENABLE_ARROWS
:
1538 return EnableScrollBar( hwnd
, SB_CTL
, wParam
);
1540 case SBM_SETSCROLLINFO
:
1541 return SCROLL_SetScrollInfo( hwnd
, SB_CTL
, (SCROLLINFO
*)lParam
, wParam
);
1543 case SBM_GETSCROLLINFO
:
1544 return SCROLL_GetScrollInfo(hwnd
, SB_CTL
, (SCROLLINFO
*)lParam
);
1546 case SBM_GETSCROLLBARINFO
:
1547 return SCROLL_GetScrollBarInfo(hwnd
, OBJID_CLIENT
, (SCROLLBARINFO
*)lParam
);
1556 ERR("unknown Win32 msg %04x wp=%08x lp=%08lx\n",
1557 message
, wParam
, lParam
);
1561 if (message
>= WM_USER
)
1562 WARN("unknown msg %04x wp=%04x lp=%08lx\n",
1563 message
, wParam
, lParam
);
1564 return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1570 /*************************************************************************
1571 * SetScrollInfo (USER32.@)
1573 * SetScrollInfo can be used to set the position, upper bound,
1574 * lower bound, and page size of a scrollbar control.
1577 * hwnd [I] Handle of window with scrollbar(s)
1578 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1579 * info [I] Specifies what to change and new values
1580 * bRedraw [I] Should scrollbar be redrawn afterwards?
1583 * Scrollbar position
1586 * For 100 lines of text to be displayed in a window of 25 lines,
1587 * one would for instance use info->nMin=0, info->nMax=75
1588 * (corresponding to the 76 different positions of the window on
1589 * the text), and info->nPage=25.
1591 INT WINAPI
SetScrollInfo(HWND hwnd
, INT nBar
, const SCROLLINFO
*info
, BOOL bRedraw
)
1593 TRACE("hwnd=%p nBar=%d info=%p, bRedraw=%d\n", hwnd
, nBar
, info
, bRedraw
);
1595 /* Refer SB_CTL requests to the window */
1597 return SendMessageW(hwnd
, SBM_SETSCROLLINFO
, bRedraw
, (LPARAM
)info
);
1599 return SCROLL_SetScrollInfo( hwnd
, nBar
, info
, bRedraw
);
1602 static INT
SCROLL_SetScrollInfo( HWND hwnd
, INT nBar
, LPCSCROLLINFO info
, BOOL bRedraw
)
1604 /* Update the scrollbar state and set action flags according to
1605 * what has to be done graphics wise. */
1607 SCROLLBAR_INFO
*infoPtr
;
1611 /* handle invalid data structure */
1612 if (!SCROLL_ScrollInfoValid(info
)
1613 || !(infoPtr
= SCROLL_GetInternalInfo(hwnd
, nBar
, TRUE
)))
1616 if (TRACE_ON(scroll
))
1618 TRACE("hwnd=%p bar=%d", hwnd
, nBar
);
1619 if (info
->fMask
& SIF_PAGE
) TRACE( " page=%d", info
->nPage
);
1620 if (info
->fMask
& SIF_POS
) TRACE( " pos=%d", info
->nPos
);
1621 if (info
->fMask
& SIF_RANGE
) TRACE( " min=%d max=%d", info
->nMin
, info
->nMax
);
1625 /* Set the page size */
1627 if (info
->fMask
& SIF_PAGE
)
1629 if( infoPtr
->page
!= info
->nPage
&& info
->nPage
>= 0)
1631 infoPtr
->page
= info
->nPage
;
1632 action
|= SA_SSI_REFRESH
;
1636 /* Set the scroll pos */
1638 if (info
->fMask
& SIF_POS
)
1640 if( infoPtr
->curVal
!= info
->nPos
)
1642 infoPtr
->curVal
= info
->nPos
;
1643 action
|= SA_SSI_REFRESH
;
1647 /* Set the scroll range */
1649 if (info
->fMask
& SIF_RANGE
)
1651 /* Invalid range -> range is set to (0,0) */
1652 if ((info
->nMin
> info
->nMax
) ||
1653 ((UINT
)(info
->nMax
- info
->nMin
) >= 0x80000000))
1655 action
|= SA_SSI_REFRESH
;
1656 infoPtr
->minVal
= 0;
1657 infoPtr
->maxVal
= 0;
1661 if( infoPtr
->minVal
!= info
->nMin
||
1662 infoPtr
->maxVal
!= info
->nMax
)
1664 action
|= SA_SSI_REFRESH
;
1665 infoPtr
->minVal
= info
->nMin
;
1666 infoPtr
->maxVal
= info
->nMax
;
1671 /* Make sure the page size is valid */
1672 if (infoPtr
->page
< 0) infoPtr
->page
= 0;
1673 else if (infoPtr
->page
> infoPtr
->maxVal
- infoPtr
->minVal
+ 1 )
1674 infoPtr
->page
= infoPtr
->maxVal
- infoPtr
->minVal
+ 1;
1676 /* Make sure the pos is inside the range */
1678 if (infoPtr
->curVal
< infoPtr
->minVal
)
1679 infoPtr
->curVal
= infoPtr
->minVal
;
1680 else if (infoPtr
->curVal
> infoPtr
->maxVal
- max( infoPtr
->page
-1, 0 ))
1681 infoPtr
->curVal
= infoPtr
->maxVal
- max( infoPtr
->page
-1, 0 );
1683 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1684 infoPtr
->page
, infoPtr
->curVal
,
1685 infoPtr
->minVal
, infoPtr
->maxVal
);
1687 /* don't change the scrollbar state if SetScrollInfo
1688 * is just called with SIF_DISABLENOSCROLL
1690 if(!(info
->fMask
& SIF_ALL
)) goto done
;
1692 /* Check if the scrollbar should be hidden or disabled */
1694 if (info
->fMask
& (SIF_RANGE
| SIF_PAGE
| SIF_DISABLENOSCROLL
))
1696 new_flags
= infoPtr
->flags
;
1697 if (infoPtr
->minVal
>= infoPtr
->maxVal
- max( infoPtr
->page
-1, 0 ))
1699 /* Hide or disable scroll-bar */
1700 if (info
->fMask
& SIF_DISABLENOSCROLL
)
1702 new_flags
= ESB_DISABLE_BOTH
;
1703 action
|= SA_SSI_REFRESH
;
1705 else if ((nBar
!= SB_CTL
) && (action
& SA_SSI_REFRESH
))
1707 action
= SA_SSI_HIDE
;
1710 else /* Show and enable scroll-bar only if no page only changed. */
1711 if (info
->fMask
!= SIF_PAGE
)
1713 new_flags
= ESB_ENABLE_BOTH
;
1714 if ((nBar
!= SB_CTL
) && ( (action
& SA_SSI_REFRESH
) ))
1715 action
|= SA_SSI_SHOW
;
1718 if (infoPtr
->flags
!= new_flags
) /* check arrow flags */
1720 infoPtr
->flags
= new_flags
;
1721 action
|= SA_SSI_REPAINT_ARROWS
;
1726 if( action
& SA_SSI_HIDE
)
1727 SCROLL_ShowScrollBar( hwnd
, nBar
, FALSE
, FALSE
);
1730 if( action
& SA_SSI_SHOW
)
1731 if( SCROLL_ShowScrollBar( hwnd
, nBar
, TRUE
, TRUE
) )
1732 return infoPtr
->curVal
; /* SetWindowPos() already did the painting */
1735 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, TRUE
);
1736 else if( action
& SA_SSI_REPAINT_ARROWS
)
1737 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, FALSE
);
1740 /* Return current position */
1741 return infoPtr
->curVal
;
1745 /*************************************************************************
1746 * GetScrollInfo (USER32.@)
1748 * GetScrollInfo can be used to retrieve the position, upper bound,
1749 * lower bound, and page size of a scrollbar control.
1752 * hwnd [I] Handle of window with scrollbar(s)
1753 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1754 * info [IO] fMask specifies which values to retrieve
1757 * TRUE if SCROLLINFO is filled
1758 * ( if nBar is SB_CTL, GetScrollInfo returns TRUE even if nothing
1761 BOOL WINAPI
GetScrollInfo(HWND hwnd
, INT nBar
, LPSCROLLINFO info
)
1763 TRACE("hwnd=%p nBar=%d info=%p\n", hwnd
, nBar
, info
);
1765 /* Refer SB_CTL requests to the window */
1768 SendMessageW(hwnd
, SBM_GETSCROLLINFO
, (WPARAM
)0, (LPARAM
)info
);
1771 return SCROLL_GetScrollInfo(hwnd
, nBar
, info
);
1775 /*************************************************************************
1776 * GetScrollBarInfo (USER32.@)
1778 * GetScrollBarInfo can be used to retrieve information about a scrollbar
1782 * hwnd [I] Handle of window with scrollbar(s)
1783 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1784 * info [IO] cbSize specifies the size of SCROLLBARINFO
1789 BOOL WINAPI
GetScrollBarInfo(HWND hwnd
, LONG idObject
, LPSCROLLBARINFO info
)
1791 TRACE("hwnd=%p idObject=%d info=%p\n", hwnd
, idObject
, info
);
1793 /* Refer OBJID_CLIENT requests to the window */
1794 if (idObject
== OBJID_CLIENT
)
1795 return SendMessageW(hwnd
, SBM_GETSCROLLBARINFO
, (WPARAM
)0, (LPARAM
)info
);
1797 return SCROLL_GetScrollBarInfo(hwnd
, idObject
, info
);
1801 /*************************************************************************
1802 * SetScrollPos (USER32.@)
1804 * Sets the current position of the scroll thumb.
1807 * hwnd [I] Handle of window with scrollbar(s)
1808 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1809 * nPos [I] New value
1810 * bRedraw [I] Should scrollbar be redrawn afterwards?
1813 * Success: Scrollbar position
1817 * Note the ambiguity when 0 is returned. Use GetLastError
1818 * to make sure there was an error (and to know which one).
1820 INT WINAPI
SetScrollPos( HWND hwnd
, INT nBar
, INT nPos
, BOOL bRedraw
)
1823 SCROLLBAR_INFO
*infoPtr
;
1826 if (!(infoPtr
= SCROLL_GetInternalInfo( hwnd
, nBar
, FALSE
))) return 0;
1827 oldPos
= infoPtr
->curVal
;
1828 info
.cbSize
= sizeof(info
);
1830 info
.fMask
= SIF_POS
;
1831 SetScrollInfo( hwnd
, nBar
, &info
, bRedraw
);
1836 /*************************************************************************
1837 * GetScrollPos (USER32.@)
1839 * Gets the current position of the scroll thumb.
1842 * hwnd [I] Handle of window with scrollbar(s)
1843 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1846 * Success: Current position
1850 * There is ambiguity when 0 is returned. Use GetLastError
1851 * to make sure there was an error (and to know which one).
1853 INT WINAPI
GetScrollPos(HWND hwnd
, INT nBar
)
1855 TRACE("hwnd=%p nBar=%d\n", hwnd
, nBar
);
1857 /* Refer SB_CTL requests to the window */
1859 return SendMessageW(hwnd
, SBM_GETPOS
, (WPARAM
)0, (LPARAM
)0);
1861 return SCROLL_GetScrollPos(hwnd
, nBar
);
1865 /*************************************************************************
1866 * SetScrollRange (USER32.@)
1867 * The SetScrollRange function sets the minimum and maximum scroll box positions
1868 * If nMinPos and nMaxPos is the same value, the scroll bar will hide
1870 * Sets the range of the scroll bar.
1873 * hwnd [I] Handle of window with scrollbar(s)
1874 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1875 * minVal [I] New minimum value
1876 * maxVal [I] New Maximum value
1877 * bRedraw [I] Should scrollbar be redrawn afterwards?
1883 BOOL WINAPI
SetScrollRange(HWND hwnd
, INT nBar
, INT minVal
, INT maxVal
, BOOL bRedraw
)
1887 TRACE("hwnd=%p nBar=%d min=%d max=%d, bRedraw=%d\n", hwnd
, nBar
, minVal
, maxVal
, bRedraw
);
1889 info
.cbSize
= sizeof(info
);
1890 info
.fMask
= SIF_RANGE
;
1893 SetScrollInfo( hwnd
, nBar
, &info
, bRedraw
);
1898 /*************************************************************************
1899 * SCROLL_SetNCSbState
1901 * Updates both scrollbars at the same time. Used by MDI CalcChildScroll().
1903 INT
SCROLL_SetNCSbState(HWND hwnd
, int vMin
, int vMax
, int vPos
,
1904 int hMin
, int hMax
, int hPos
)
1906 SCROLLINFO vInfo
, hInfo
;
1908 vInfo
.cbSize
= hInfo
.cbSize
= sizeof(SCROLLINFO
);
1915 vInfo
.fMask
= hInfo
.fMask
= SIF_RANGE
| SIF_POS
;
1917 SCROLL_SetScrollInfo( hwnd
, SB_VERT
, &vInfo
, TRUE
);
1918 SCROLL_SetScrollInfo( hwnd
, SB_HORZ
, &hInfo
, TRUE
);
1924 /*************************************************************************
1925 * GetScrollRange (USER32.@)
1927 * Gets the range of the scroll bar.
1930 * hwnd [I] Handle of window with scrollbar(s)
1931 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1932 * lpMin [O] Where to store minimum value
1933 * lpMax [O] Where to store maximum value
1936 * TRUE if values is filled
1938 BOOL WINAPI
GetScrollRange(HWND hwnd
, INT nBar
, LPINT lpMin
, LPINT lpMax
)
1940 TRACE("hwnd=%p nBar=%d lpMin=%p lpMax=%p\n", hwnd
, nBar
, lpMin
, lpMax
);
1942 /* Refer SB_CTL requests to the window */
1944 SendMessageW(hwnd
, SBM_GETRANGE
, (WPARAM
)lpMin
, (LPARAM
)lpMax
);
1946 SCROLL_GetScrollRange(hwnd
, nBar
, lpMin
, lpMax
);
1952 /*************************************************************************
1953 * SCROLL_ShowScrollBar()
1955 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1957 static BOOL
SCROLL_ShowScrollBar( HWND hwnd
, INT nBar
, BOOL fShowH
, BOOL fShowV
)
1959 ULONG old_style
, set_bits
= 0, clear_bits
= 0;
1961 TRACE("hwnd=%p bar=%d horz=%d, vert=%d\n", hwnd
, nBar
, fShowH
, fShowV
);
1966 ShowWindow( hwnd
, fShowH
? SW_SHOW
: SW_HIDE
);
1971 if (fShowH
) set_bits
|= WS_HSCROLL
;
1972 else clear_bits
|= WS_HSCROLL
;
1973 if( nBar
== SB_HORZ
) break;
1976 if (fShowV
) set_bits
|= WS_VSCROLL
;
1977 else clear_bits
|= WS_VSCROLL
;
1981 return FALSE
; /* Nothing to do! */
1984 old_style
= WIN_SetStyle( hwnd
, set_bits
, clear_bits
);
1985 if ((old_style
& clear_bits
) != 0 || (old_style
& set_bits
) != set_bits
)
1987 /* frame has been changed, let the window redraw itself */
1988 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
1989 | SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
1992 return FALSE
; /* no frame changes */
1996 /*************************************************************************
1997 * ShowScrollBar (USER32.@)
1999 * Shows or hides the scroll bar.
2002 * hwnd [I] Handle of window with scrollbar(s)
2003 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
2004 * fShow [I] TRUE = show, FALSE = hide
2010 BOOL WINAPI
ShowScrollBar(HWND hwnd
, INT nBar
, BOOL fShow
)
2012 SCROLL_ShowScrollBar( hwnd
, nBar
, (nBar
== SB_VERT
) ? 0 : fShow
,
2013 (nBar
== SB_HORZ
) ? 0 : fShow
);
2018 /*************************************************************************
2019 * EnableScrollBar (USER32.@)
2021 * Enables or disables the scroll bars.
2023 BOOL WINAPI
EnableScrollBar( HWND hwnd
, UINT nBar
, UINT flags
)
2026 SCROLLBAR_INFO
*infoPtr
;
2028 TRACE("%p %d %d\n", hwnd
, nBar
, flags
);
2030 flags
&= ESB_DISABLE_BOTH
;
2032 if (nBar
== SB_BOTH
)
2034 if (!(infoPtr
= SCROLL_GetInternalInfo( hwnd
, SB_VERT
, TRUE
))) return FALSE
;
2035 if (!(bFineWithMe
= (infoPtr
->flags
== flags
)) )
2037 infoPtr
->flags
= flags
;
2038 SCROLL_RefreshScrollBar( hwnd
, SB_VERT
, TRUE
, TRUE
);
2045 if (!(infoPtr
= SCROLL_GetInternalInfo( hwnd
, nBar
, TRUE
))) return FALSE
;
2046 if (bFineWithMe
&& infoPtr
->flags
== flags
) return FALSE
;
2047 infoPtr
->flags
= flags
;
2049 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, TRUE
);