4 * Copyright 1993 Martin Ayotte
5 * Copyright 1994, 1996 Alexandre Julliard
8 #include "wine/winuser16.h"
9 #include "sysmetrics.h"
16 static HBITMAP hUpArrow
= 0;
17 static HBITMAP hDnArrow
= 0;
18 static HBITMAP hLfArrow
= 0;
19 static HBITMAP hRgArrow
= 0;
20 static HBITMAP hUpArrowD
= 0;
21 static HBITMAP hDnArrowD
= 0;
22 static HBITMAP hLfArrowD
= 0;
23 static HBITMAP hRgArrowD
= 0;
24 static HBITMAP hUpArrowI
= 0;
25 static HBITMAP hDnArrowI
= 0;
26 static HBITMAP hLfArrowI
= 0;
27 static HBITMAP hRgArrowI
= 0;
29 #define TOP_ARROW(flags,pressed) \
30 (((flags)&ESB_DISABLE_UP) ? hUpArrowI : ((pressed) ? hUpArrowD:hUpArrow))
31 #define BOTTOM_ARROW(flags,pressed) \
32 (((flags)&ESB_DISABLE_DOWN) ? hDnArrowI : ((pressed) ? hDnArrowD:hDnArrow))
33 #define LEFT_ARROW(flags,pressed) \
34 (((flags)&ESB_DISABLE_LEFT) ? hLfArrowI : ((pressed) ? hLfArrowD:hLfArrow))
35 #define RIGHT_ARROW(flags,pressed) \
36 (((flags)&ESB_DISABLE_RIGHT) ? hRgArrowI : ((pressed) ? hRgArrowD:hRgArrow))
39 /* Minimum size of the rectangle between the arrows */
40 #define SCROLL_MIN_RECT 4
42 /* Minimum size of the thumb in pixels */
43 #define SCROLL_MIN_THUMB 6
45 /* Overlap between arrows and thumb */
46 #define SCROLL_ARROW_THUMB_OVERLAP 1
48 /* Delay (in ms) before first repetition when holding the button down */
49 #define SCROLL_FIRST_DELAY 200
51 /* Delay (in ms) between scroll repetitions */
52 #define SCROLL_REPEAT_DELAY 50
55 #define SCROLL_TIMER 0
57 /* Scroll-bar hit testing */
60 SCROLL_NOWHERE
, /* Outside the scroll bar */
61 SCROLL_TOP_ARROW
, /* Top or left arrow */
62 SCROLL_TOP_RECT
, /* Rectangle between the top arrow and the thumb */
63 SCROLL_THUMB
, /* Thumb rectangle */
64 SCROLL_BOTTOM_RECT
, /* Rectangle between the thumb and the bottom arrow */
65 SCROLL_BOTTOM_ARROW
/* Bottom or right arrow */
68 /* What to do after SCROLL_SetScrollInfo() */
69 #define SA_SSI_HIDE 0x0001
70 #define SA_SSI_SHOW 0x0002
71 #define SA_SSI_REFRESH 0x0004
72 #define SA_SSI_REPAINT_ARROWS 0x0008
74 /* Thumb-tracking info */
75 static HWND SCROLL_TrackingWin
= 0;
76 static INT SCROLL_TrackingBar
= 0;
77 static INT SCROLL_TrackingPos
= 0;
78 static INT SCROLL_TrackingVal
= 0;
79 /* Hit test code of the last button-down event */
80 static enum SCROLL_HITTEST SCROLL_trackHitTest
;
81 static BOOL SCROLL_trackVertical
;
83 /* Is the moving thumb being displayed? */
84 static BOOL SCROLL_MovingThumb
= FALSE
;
87 static BOOL
SCROLL_ShowScrollBar( HWND hwnd
, INT nBar
,
88 BOOL fShowH
, BOOL fShowV
);
89 static INT
SCROLL_SetScrollInfo( HWND hwnd
, INT nBar
,
90 const SCROLLINFO
*info
, INT
*action
);
92 /***********************************************************************
95 static void SCROLL_LoadBitmaps(void)
97 hUpArrow
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROW
) );
98 hDnArrow
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROW
) );
99 hLfArrow
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROW
) );
100 hRgArrow
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROW
) );
101 hUpArrowD
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROWD
) );
102 hDnArrowD
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROWD
) );
103 hLfArrowD
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROWD
) );
104 hRgArrowD
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROWD
) );
105 hUpArrowI
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROWI
) );
106 hDnArrowI
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROWI
) );
107 hLfArrowI
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROWI
) );
108 hRgArrowI
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROWI
) );
112 /***********************************************************************
113 * SCROLL_GetPtrScrollInfo
115 static SCROLLBAR_INFO
*SCROLL_GetPtrScrollInfo( WND
* wndPtr
, INT nBar
)
117 SCROLLBAR_INFO
*infoPtr
;
119 if (!wndPtr
) return NULL
;
122 case SB_HORZ
: infoPtr
= (SCROLLBAR_INFO
*)wndPtr
->pHScroll
; break;
123 case SB_VERT
: infoPtr
= (SCROLLBAR_INFO
*)wndPtr
->pVScroll
; break;
124 case SB_CTL
: infoPtr
= (SCROLLBAR_INFO
*)wndPtr
->wExtra
; break;
125 default: return NULL
;
128 if (!infoPtr
) /* Create the info structure if needed */
130 if ((infoPtr
= HeapAlloc( SystemHeap
, 0, sizeof(SCROLLBAR_INFO
) )))
132 infoPtr
->MinVal
= infoPtr
->CurVal
= infoPtr
->Page
= 0;
133 infoPtr
->MaxVal
= 100;
134 infoPtr
->flags
= ESB_ENABLE_BOTH
;
135 if (nBar
== SB_HORZ
) wndPtr
->pHScroll
= infoPtr
;
136 else wndPtr
->pVScroll
= infoPtr
;
138 if (!hUpArrow
) SCROLL_LoadBitmaps();
144 /***********************************************************************
145 * SCROLL_GetScrollInfo
147 static SCROLLBAR_INFO
*SCROLL_GetScrollInfo( HWND hwnd
, INT nBar
)
149 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
150 return SCROLL_GetPtrScrollInfo( wndPtr
, nBar
);
154 /***********************************************************************
155 * SCROLL_GetScrollBarRect
157 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
158 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
159 * 'arrowSize' returns the width or height of an arrow (depending on
160 * the orientation of the scrollbar), 'thumbSize' returns the size of
161 * the thumb, and 'thumbPos' returns the position of the thumb
162 * relative to the left or to the top.
163 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
165 static BOOL
SCROLL_GetScrollBarRect( HWND hwnd
, INT nBar
, RECT
*lprect
,
166 INT
*arrowSize
, INT
*thumbSize
,
171 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
176 lprect
->left
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
177 lprect
->top
= wndPtr
->rectClient
.bottom
- wndPtr
->rectWindow
.top
;
178 lprect
->right
= wndPtr
->rectClient
.right
- wndPtr
->rectWindow
.left
;
179 lprect
->bottom
= lprect
->top
+ SYSMETRICS_CYHSCROLL
;
180 if(wndPtr
->dwStyle
& WS_BORDER
) {
183 } else if(wndPtr
->dwStyle
& WS_VSCROLL
)
189 lprect
->left
= wndPtr
->rectClient
.right
- wndPtr
->rectWindow
.left
;
190 lprect
->top
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
191 lprect
->right
= lprect
->left
+ SYSMETRICS_CXVSCROLL
;
192 lprect
->bottom
= wndPtr
->rectClient
.bottom
- wndPtr
->rectWindow
.top
;
193 if(wndPtr
->dwStyle
& WS_BORDER
) {
196 } else if(wndPtr
->dwStyle
& WS_HSCROLL
)
202 GetClientRect( hwnd
, lprect
);
203 vertical
= ((wndPtr
->dwStyle
& SBS_VERT
) != 0);
210 if (vertical
) pixels
= lprect
->bottom
- lprect
->top
;
211 else pixels
= lprect
->right
- lprect
->left
;
213 if (pixels
<= 2*SYSMETRICS_CXVSCROLL
+ SCROLL_MIN_RECT
)
215 if (pixels
> SCROLL_MIN_RECT
)
216 *arrowSize
= (pixels
- SCROLL_MIN_RECT
) / 2;
219 *thumbPos
= *thumbSize
= 0;
223 SCROLLBAR_INFO
*info
= SCROLL_GetPtrScrollInfo( wndPtr
, nBar
);
225 *arrowSize
= SYSMETRICS_CXVSCROLL
;
226 pixels
-= (2 * (SYSMETRICS_CXVSCROLL
- SCROLL_ARROW_THUMB_OVERLAP
));
230 *thumbSize
= pixels
* info
->Page
/ (info
->MaxVal
-info
->MinVal
+1);
231 if (*thumbSize
< SCROLL_MIN_THUMB
) *thumbSize
= SCROLL_MIN_THUMB
;
233 else *thumbSize
= SYSMETRICS_CXVSCROLL
;
235 if (((pixels
-= *thumbSize
) < 0) ||
236 ((info
->flags
& ESB_DISABLE_BOTH
) == ESB_DISABLE_BOTH
))
238 /* Rectangle too small or scrollbar disabled -> no thumb */
239 *thumbPos
= *thumbSize
= 0;
243 INT max
= info
->MaxVal
- MAX( info
->Page
-1, 0 );
244 if (info
->MinVal
>= max
)
245 *thumbPos
= *arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
247 *thumbPos
= *arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
248 + pixels
* (info
->CurVal
-info
->MinVal
) / (max
- info
->MinVal
);
255 /***********************************************************************
258 * Compute the current scroll position based on the thumb position in pixels
259 * from the top of the scroll-bar.
261 static UINT
SCROLL_GetThumbVal( SCROLLBAR_INFO
*infoPtr
, RECT
*rect
,
262 BOOL vertical
, INT pos
)
265 INT pixels
= vertical
? rect
->bottom
-rect
->top
: rect
->right
-rect
->left
;
267 if ((pixels
-= 2*(SYSMETRICS_CXVSCROLL
- SCROLL_ARROW_THUMB_OVERLAP
)) <= 0)
268 return infoPtr
->MinVal
;
272 thumbSize
= pixels
* infoPtr
->Page
/(infoPtr
->MaxVal
-infoPtr
->MinVal
+1);
273 if (thumbSize
< SCROLL_MIN_THUMB
) thumbSize
= SCROLL_MIN_THUMB
;
275 else thumbSize
= SYSMETRICS_CXVSCROLL
;
277 if ((pixels
-= thumbSize
) <= 0) return infoPtr
->MinVal
;
279 pos
= MAX( 0, pos
- (SYSMETRICS_CXVSCROLL
- SCROLL_ARROW_THUMB_OVERLAP
) );
280 if (pos
> pixels
) pos
= pixels
;
282 if (!infoPtr
->Page
) pos
*= infoPtr
->MaxVal
- infoPtr
->MinVal
;
283 else pos
*= infoPtr
->MaxVal
- infoPtr
->MinVal
- infoPtr
->Page
+ 1;
284 return infoPtr
->MinVal
+ ((pos
+ pixels
/ 2) / pixels
);
287 /***********************************************************************
290 static BOOL
SCROLL_PtInRectEx( LPRECT lpRect
, POINT pt
, BOOL vertical
)
296 rect
.left
-= lpRect
->right
- lpRect
->left
;
297 rect
.right
+= lpRect
->right
- lpRect
->left
;
301 rect
.top
-= lpRect
->bottom
- lpRect
->top
;
302 rect
.bottom
+= lpRect
->bottom
- lpRect
->top
;
304 return PtInRect( &rect
, pt
);
307 /***********************************************************************
310 static POINT
SCROLL_ClipPos( LPRECT lpRect
, POINT pt
)
312 if( pt
.x
< lpRect
->left
)
315 if( pt
.x
> lpRect
->right
)
316 pt
.x
= lpRect
->right
;
318 if( pt
.y
< lpRect
->top
)
321 if( pt
.y
> lpRect
->bottom
)
322 pt
.y
= lpRect
->bottom
;
328 /***********************************************************************
331 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
333 static enum SCROLL_HITTEST
SCROLL_HitTest( HWND hwnd
, INT nBar
,
334 POINT pt
, BOOL bDragging
)
336 INT arrowSize
, thumbSize
, thumbPos
;
339 BOOL vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
340 &arrowSize
, &thumbSize
, &thumbPos
);
342 if ( (bDragging
&& !SCROLL_PtInRectEx( &rect
, pt
, vertical
)) ||
343 (!PtInRect( &rect
, pt
)) ) return SCROLL_NOWHERE
;
347 if (pt
.y
< rect
.top
+ arrowSize
) return SCROLL_TOP_ARROW
;
348 if (pt
.y
>= rect
.bottom
- arrowSize
) return SCROLL_BOTTOM_ARROW
;
349 if (!thumbPos
) return SCROLL_TOP_RECT
;
351 if (pt
.y
< thumbPos
) return SCROLL_TOP_RECT
;
352 if (pt
.y
>= thumbPos
+ thumbSize
) return SCROLL_BOTTOM_RECT
;
354 else /* horizontal */
356 if (pt
.x
< rect
.left
+ arrowSize
) return SCROLL_TOP_ARROW
;
357 if (pt
.x
>= rect
.right
- arrowSize
) return SCROLL_BOTTOM_ARROW
;
358 if (!thumbPos
) return SCROLL_TOP_RECT
;
360 if (pt
.x
< thumbPos
) return SCROLL_TOP_RECT
;
361 if (pt
.x
>= thumbPos
+ thumbSize
) return SCROLL_BOTTOM_RECT
;
367 /***********************************************************************
370 * Draw the scroll bar arrows.
372 static void SCROLL_DrawArrows( HDC hdc
, SCROLLBAR_INFO
*infoPtr
,
373 RECT
*rect
, INT arrowSize
, BOOL vertical
,
374 BOOL top_pressed
, BOOL bottom_pressed
)
376 HDC hdcMem
= CreateCompatibleDC( hdc
);
377 HBITMAP hbmpPrev
= SelectObject( hdcMem
, vertical
?
378 TOP_ARROW(infoPtr
->flags
, top_pressed
)
379 : LEFT_ARROW(infoPtr
->flags
, top_pressed
));
381 SetStretchBltMode( hdc
, STRETCH_DELETESCANS
);
382 StretchBlt( hdc
, rect
->left
, rect
->top
,
383 vertical
? rect
->right
-rect
->left
: arrowSize
,
384 vertical
? arrowSize
: rect
->bottom
-rect
->top
,
386 SYSMETRICS_CXVSCROLL
, SYSMETRICS_CYHSCROLL
,
389 SelectObject( hdcMem
, vertical
?
390 BOTTOM_ARROW( infoPtr
->flags
, bottom_pressed
)
391 : RIGHT_ARROW( infoPtr
->flags
, bottom_pressed
) );
393 StretchBlt( hdc
, rect
->left
, rect
->bottom
- arrowSize
,
394 rect
->right
- rect
->left
, arrowSize
,
396 SYSMETRICS_CXVSCROLL
, SYSMETRICS_CYHSCROLL
,
399 StretchBlt( hdc
, rect
->right
- arrowSize
, rect
->top
,
400 arrowSize
, rect
->bottom
- rect
->top
,
402 SYSMETRICS_CXVSCROLL
, SYSMETRICS_CYHSCROLL
,
404 SelectObject( hdcMem
, hbmpPrev
);
409 /***********************************************************************
410 * SCROLL_DrawMovingThumb
412 * Draw the moving thumb rectangle.
414 static void SCROLL_DrawMovingThumb( HDC hdc
, RECT
*rect
, BOOL vertical
,
415 INT arrowSize
, INT thumbSize
)
420 r
.top
+= SCROLL_TrackingPos
;
421 if (r
.top
< rect
->top
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
422 r
.top
= rect
->top
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
423 if (r
.top
+ thumbSize
>
424 rect
->bottom
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
))
425 r
.top
= rect
->bottom
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
427 r
.bottom
= r
.top
+ thumbSize
;
431 r
.left
+= SCROLL_TrackingPos
;
432 if (r
.left
< rect
->left
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
433 r
.left
= rect
->left
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
434 if (r
.left
+ thumbSize
>
435 rect
->right
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
))
436 r
.left
= rect
->right
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
438 r
.right
= r
.left
+ thumbSize
;
440 DrawFocusRect( hdc
, &r
);
441 SCROLL_MovingThumb
= !SCROLL_MovingThumb
;
445 /***********************************************************************
446 * SCROLL_DrawInterior
448 * Draw the scroll bar interior (everything except the arrows).
450 static void SCROLL_DrawInterior( HWND hwnd
, HDC hdc
, INT nBar
,
451 RECT
*rect
, INT arrowSize
,
452 INT thumbSize
, INT thumbPos
,
453 UINT flags
, BOOL vertical
,
454 BOOL top_selected
, BOOL bottom_selected
)
458 /* Select the correct brush and pen */
460 SelectObject( hdc
, GetSysColorPen(COLOR_WINDOWFRAME
) );
461 if ((flags
& ESB_DISABLE_BOTH
) == ESB_DISABLE_BOTH
)
463 /* This ought to be the color of the parent window */
464 SelectObject( hdc
, GetSysColorBrush(COLOR_WINDOW
) );
468 if (nBar
== SB_CTL
) /* Only scrollbar controls send WM_CTLCOLOR */
470 HBRUSH hbrush
= SendMessageA(GetParent(hwnd
),
471 WM_CTLCOLORSCROLLBAR
, hdc
, hwnd
);
472 SelectObject( hdc
, hbrush
);
474 else SelectObject( hdc
, GetSysColorBrush(COLOR_SCROLLBAR
) );
477 /* Calculate the scroll rectangle */
482 r
.top
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
483 r
.bottom
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
487 r
.left
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
488 r
.right
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
491 /* Draw the scroll bar frame */
493 Rectangle( hdc
, r
.left
, r
.top
, r
.right
, r
.bottom
);
495 /* Draw the scroll rectangles and thumb */
497 if (!thumbPos
) /* No thumb to draw */
499 PatBlt( hdc
, r
.left
+1, r
.top
+1, r
.right
- r
.left
- 2,
500 r
.bottom
- r
.top
- 2, PATCOPY
);
506 PatBlt( hdc
, r
.left
+ 1, r
.top
+ 1,
507 r
.right
- r
.left
- 2,
508 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
) - 1,
509 top_selected
? 0x0f0000 : PATCOPY
);
510 r
.top
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
511 PatBlt( hdc
, r
.left
+ 1, r
.top
+ thumbSize
,
512 r
.right
- r
.left
- 2,
513 r
.bottom
- r
.top
- thumbSize
- 1,
514 bottom_selected
? 0x0f0000 : PATCOPY
);
515 r
.bottom
= r
.top
+ thumbSize
;
517 else /* horizontal */
519 PatBlt( hdc
, r
.left
+ 1, r
.top
+ 1,
520 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
) - 1,
521 r
.bottom
- r
.top
- 2,
522 top_selected
? 0x0f0000 : PATCOPY
);
523 r
.left
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
524 PatBlt( hdc
, r
.left
+ thumbSize
, r
.top
+ 1,
525 r
.right
- r
.left
- thumbSize
- 1,
526 r
.bottom
- r
.top
- 2,
527 bottom_selected
? 0x0f0000 : PATCOPY
);
528 r
.right
= r
.left
+ thumbSize
;
533 SelectObject( hdc
, GetSysColorBrush(COLOR_BTNFACE
) );
534 Rectangle( hdc
, r
.left
, r
.top
, r
.right
, r
.bottom
);
536 DrawEdge( hdc
, &r
, EDGE_RAISED
, BF_RECT
);
537 if (SCROLL_MovingThumb
&&
538 (SCROLL_TrackingWin
== hwnd
) &&
539 (SCROLL_TrackingBar
== nBar
))
541 SCROLL_DrawMovingThumb( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
542 SCROLL_MovingThumb
= TRUE
;
547 /***********************************************************************
548 * SCROLL_DrawScrollBar
550 * Redraw the whole scrollbar.
552 void SCROLL_DrawScrollBar( HWND hwnd
, HDC hdc
, INT nBar
,
553 BOOL arrows
, BOOL interior
)
555 INT arrowSize
, thumbSize
, thumbPos
;
558 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
559 SCROLLBAR_INFO
*infoPtr
= SCROLL_GetPtrScrollInfo( wndPtr
, nBar
);
561 if (!wndPtr
|| !infoPtr
||
562 ((nBar
== SB_VERT
) && !(wndPtr
->dwStyle
& WS_VSCROLL
)) ||
563 ((nBar
== SB_HORZ
) && !(wndPtr
->dwStyle
& WS_HSCROLL
))) return;
564 if (!WIN_IsWindowDrawable( wndPtr
, FALSE
)) return;
566 vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
567 &arrowSize
, &thumbSize
, &thumbPos
);
569 /* Draw the arrows */
571 if (arrows
&& arrowSize
)
573 if( vertical
== SCROLL_trackVertical
&& GetCapture() == hwnd
)
574 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
575 (SCROLL_trackHitTest
== SCROLL_TOP_ARROW
),
576 (SCROLL_trackHitTest
== SCROLL_BOTTOM_ARROW
) );
578 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
582 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
583 thumbPos
, infoPtr
->flags
, vertical
, FALSE
, FALSE
);
587 /***********************************************************************
588 * SCROLL_RefreshScrollBar
590 * Repaint the scroll bar interior after a SetScrollRange() or
591 * SetScrollPos() call.
593 static void SCROLL_RefreshScrollBar( HWND hwnd
, INT nBar
,
594 BOOL arrows
, BOOL interior
)
596 HDC hdc
= GetDCEx( hwnd
, 0,
597 DCX_CACHE
| ((nBar
== SB_CTL
) ? 0 : DCX_WINDOW
) );
600 SCROLL_DrawScrollBar( hwnd
, hdc
, nBar
, arrows
, interior
);
601 ReleaseDC( hwnd
, hdc
);
605 /***********************************************************************
606 * SCROLL_HandleKbdEvent
608 * Handle a keyboard event (only for SB_CTL scrollbars).
610 static void SCROLL_HandleKbdEvent( HWND hwnd
, WPARAM wParam
)
612 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
617 case VK_PRIOR
: msg
= SB_PAGEUP
; break;
618 case VK_NEXT
: msg
= SB_PAGEDOWN
; break;
619 case VK_HOME
: msg
= SB_TOP
; break;
620 case VK_END
: msg
= SB_BOTTOM
; break;
621 case VK_UP
: msg
= SB_LINEUP
; break;
622 case VK_DOWN
: msg
= SB_LINEDOWN
; break;
626 SendMessageA( GetParent(hwnd
),
627 (wndPtr
->dwStyle
& SBS_VERT
) ? WM_VSCROLL
: WM_HSCROLL
,
632 /***********************************************************************
633 * SCROLL_HandleScrollEvent
635 * Handle a mouse or timer event for the scrollbar.
636 * 'pt' is the location of the mouse event in client (for SB_CTL) or
637 * windows coordinates.
639 void SCROLL_HandleScrollEvent( HWND hwnd
, INT nBar
, UINT msg
, POINT pt
)
641 /* Previous mouse position for timer events */
643 /* Thumb position when tracking started. */
644 static UINT trackThumbPos
;
645 /* Position in the scroll-bar of the last button-down event. */
646 static INT lastClickPos
;
647 /* Position in the scroll-bar of the last mouse event. */
648 static INT lastMousePos
;
650 enum SCROLL_HITTEST hittest
;
651 HWND hwndOwner
, hwndCtl
;
653 INT arrowSize
, thumbSize
, thumbPos
;
657 SCROLLBAR_INFO
*infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
);
658 if (!infoPtr
) return;
659 if ((SCROLL_trackHitTest
== SCROLL_NOWHERE
) && (msg
!= WM_LBUTTONDOWN
))
662 hdc
= GetDCEx( hwnd
, 0, DCX_CACHE
| ((nBar
== SB_CTL
) ? 0 : DCX_WINDOW
));
663 vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
664 &arrowSize
, &thumbSize
, &thumbPos
);
665 hwndOwner
= (nBar
== SB_CTL
) ? GetParent(hwnd
) : hwnd
;
666 hwndCtl
= (nBar
== SB_CTL
) ? hwnd
: 0;
670 case WM_LBUTTONDOWN
: /* Initialise mouse tracking */
671 SCROLL_trackVertical
= vertical
;
672 SCROLL_trackHitTest
= hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, FALSE
);
673 lastClickPos
= vertical
? (pt
.y
- rect
.top
) : (pt
.x
- rect
.left
);
674 lastMousePos
= lastClickPos
;
675 trackThumbPos
= thumbPos
;
678 if (nBar
== SB_CTL
) SetFocus( hwnd
);
682 hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, TRUE
);
687 hittest
= SCROLL_NOWHERE
;
693 hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, FALSE
);
697 return; /* Should never happen */
700 TRACE(scroll
, "Event: hwnd=%04x bar=%d msg=%x pt=%ld,%ld hit=%d\n",
701 hwnd
, nBar
, msg
, pt
.x
, pt
.y
, hittest
);
703 switch(SCROLL_trackHitTest
)
705 case SCROLL_NOWHERE
: /* No tracking in progress */
708 case SCROLL_TOP_ARROW
:
709 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
710 (hittest
== SCROLL_trackHitTest
), FALSE
);
711 if (hittest
== SCROLL_trackHitTest
)
713 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
715 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
716 SB_LINEUP
, hwndCtl
);
717 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
718 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
722 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
725 case SCROLL_TOP_RECT
:
726 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
727 thumbPos
, infoPtr
->flags
, vertical
,
728 (hittest
== SCROLL_trackHitTest
), FALSE
);
729 if (hittest
== SCROLL_trackHitTest
)
731 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
733 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
734 SB_PAGEUP
, hwndCtl
);
735 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
736 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
740 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
744 if (msg
== WM_LBUTTONDOWN
)
746 SCROLL_TrackingWin
= hwnd
;
747 SCROLL_TrackingBar
= nBar
;
748 SCROLL_TrackingPos
= trackThumbPos
+ lastMousePos
- lastClickPos
;
749 SCROLL_DrawMovingThumb(hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
751 else if (msg
== WM_LBUTTONUP
)
753 SCROLL_TrackingWin
= 0;
754 SCROLL_MovingThumb
= FALSE
;
755 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
756 thumbPos
, infoPtr
->flags
, vertical
,
759 else /* WM_MOUSEMOVE */
763 if (!SCROLL_PtInRectEx( &rect
, pt
, vertical
)) pos
= lastClickPos
;
766 pt
= SCROLL_ClipPos( &rect
, pt
);
767 pos
= vertical
? (pt
.y
- rect
.top
) : (pt
.x
- rect
.left
);
769 if (pos
!= lastMousePos
)
771 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
,
772 arrowSize
, thumbSize
);
774 SCROLL_TrackingPos
= trackThumbPos
+ pos
- lastClickPos
;
775 SCROLL_TrackingVal
= SCROLL_GetThumbVal( infoPtr
, &rect
,
777 SCROLL_TrackingPos
);
778 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
779 MAKEWPARAM( SB_THUMBTRACK
, SCROLL_TrackingVal
),
781 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
,
782 arrowSize
, thumbSize
);
787 case SCROLL_BOTTOM_RECT
:
788 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
789 thumbPos
, infoPtr
->flags
, vertical
,
790 FALSE
, (hittest
== SCROLL_trackHitTest
) );
791 if (hittest
== SCROLL_trackHitTest
)
793 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
795 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
796 SB_PAGEDOWN
, hwndCtl
);
797 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
798 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
802 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
805 case SCROLL_BOTTOM_ARROW
:
806 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
807 FALSE
, (hittest
== SCROLL_trackHitTest
) );
808 if (hittest
== SCROLL_trackHitTest
)
810 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
812 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
813 SB_LINEDOWN
, hwndCtl
);
814 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
815 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
819 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
823 if (msg
== WM_LBUTTONUP
)
825 hittest
= SCROLL_trackHitTest
;
826 SCROLL_trackHitTest
= SCROLL_NOWHERE
; /* Terminate tracking */
828 if (hittest
== SCROLL_THUMB
)
830 UINT val
= SCROLL_GetThumbVal( infoPtr
, &rect
, vertical
,
831 trackThumbPos
+ lastMousePos
- lastClickPos
);
832 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
833 MAKEWPARAM( SB_THUMBPOSITION
, val
), hwndCtl
);
836 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
837 SB_ENDSCROLL
, hwndCtl
);
840 ReleaseDC( hwnd
, hdc
);
844 /***********************************************************************
847 LRESULT WINAPI
ScrollBarWndProc( HWND hwnd
, UINT message
, WPARAM wParam
,
854 CREATESTRUCTA
*lpCreat
= (CREATESTRUCTA
*)lParam
;
855 if (lpCreat
->style
& SBS_SIZEBOX
)
857 FIXME(scroll
, "Unimplemented style SBS_SIZEBOX.\n" );
861 if (lpCreat
->style
& SBS_VERT
)
863 if (lpCreat
->style
& SBS_LEFTALIGN
)
864 MoveWindow( hwnd
, lpCreat
->x
, lpCreat
->y
,
865 SYSMETRICS_CXVSCROLL
+1, lpCreat
->cy
, FALSE
);
866 else if (lpCreat
->style
& SBS_RIGHTALIGN
)
868 lpCreat
->x
+lpCreat
->cx
-SYSMETRICS_CXVSCROLL
-1,
870 SYSMETRICS_CXVSCROLL
+1, lpCreat
->cy
, FALSE
);
874 if (lpCreat
->style
& SBS_TOPALIGN
)
875 MoveWindow( hwnd
, lpCreat
->x
, lpCreat
->y
,
876 lpCreat
->cx
, SYSMETRICS_CYHSCROLL
+1, FALSE
);
877 else if (lpCreat
->style
& SBS_BOTTOMALIGN
)
880 lpCreat
->y
+lpCreat
->cy
-SYSMETRICS_CYHSCROLL
-1,
881 lpCreat
->cx
, SYSMETRICS_CYHSCROLL
+1, FALSE
);
884 if (!hUpArrow
) SCROLL_LoadBitmaps();
885 TRACE(scroll
, "ScrollBar creation, hwnd=%04x\n", hwnd
);
894 CONV_POINT16TO32( (POINT16
*)&lParam
, &pt
);
895 SCROLL_HandleScrollEvent( hwnd
, SB_CTL
, message
, pt
);
900 SCROLL_HandleKbdEvent( hwnd
, wParam
);
907 return DLGC_WANTARROWS
; /* Windows returns this value */
912 HDC hdc
= BeginPaint( hwnd
, &ps
);
913 SCROLL_DrawScrollBar( hwnd
, hdc
, SB_CTL
, TRUE
, TRUE
);
914 EndPaint( hwnd
, &ps
);
920 return SetScrollPos( hwnd
, SB_CTL
, wParam
, (BOOL
)lParam
);
924 return GetScrollPos( hwnd
, SB_CTL
);
927 SetScrollRange( hwnd
, SB_CTL
, LOWORD(lParam
), HIWORD(lParam
),
928 wParam
/* FIXME: Is this correct? */ );
932 SetScrollRange( hwnd
, SB_CTL
, wParam
, lParam
, FALSE
);
933 return 0; /* FIXME: return previous position */
936 FIXME(scroll
, "don't know how to handle SBM_GETRANGE16 (wp=%04x,lp=%08lx)\n", wParam
, lParam
);
940 GetScrollRange( hwnd
, SB_CTL
, (LPINT
)wParam
, (LPINT
)lParam
);
943 case SBM_ENABLE_ARROWS16
:
944 case SBM_ENABLE_ARROWS
:
945 return EnableScrollBar( hwnd
, SB_CTL
, wParam
);
947 case SBM_SETRANGEREDRAW
:
948 SetScrollRange( hwnd
, SB_CTL
, wParam
, lParam
, TRUE
);
949 return 0; /* FIXME: return previous position */
951 case SBM_SETSCROLLINFO
:
952 return SetScrollInfo( hwnd
, SB_CTL
, (SCROLLINFO
*)lParam
, wParam
);
954 case SBM_GETSCROLLINFO
:
955 return GetScrollInfo( hwnd
, SB_CTL
, (SCROLLINFO
*)lParam
);
965 ERR(scroll
, "unknown Win32 msg %04x wp=%08x lp=%08lx\n",
966 message
, wParam
, lParam
);
970 if (message
>= WM_USER
)
971 WARN(scroll
, "unknown msg %04x wp=%04x lp=%08lx\n",
972 message
, wParam
, lParam
);
973 return DefWindowProcA( hwnd
, message
, wParam
, lParam
);
979 /*************************************************************************
980 * SetScrollInfo16 (USER.475)
982 INT16 WINAPI
SetScrollInfo16( HWND16 hwnd
, INT16 nBar
, const SCROLLINFO
*info
,
985 return (INT16
)SetScrollInfo( hwnd
, nBar
, info
, bRedraw
);
989 /*************************************************************************
990 * SetScrollInfo32 (USER32.501)
991 * SetScrollInfo32 can be used to set the position, upper bound,
992 * lower bound, and page size of a scrollbar control.
998 * For 100 lines of text to be displayed in a window of 25 lines,
999 * one would for instance use info->nMin=0, info->nMax=75
1000 * (corresponding to the 76 different positions of the window on
1001 * the text), and info->nPage=25.
1003 INT WINAPI
SetScrollInfo(
1004 HWND hwnd
/* [I] Handle of window whose scrollbar will be affected */,
1005 INT nBar
/* [I] One of SB_HORZ, SB_VERT, or SB_CTL */,
1006 const SCROLLINFO
*info
/* [I] Specifies what to change and new values */,
1007 BOOL bRedraw
/* [I] Should scrollbar be redrawn afterwards ? */)
1010 INT retVal
= SCROLL_SetScrollInfo( hwnd
, nBar
, info
, &action
);
1012 if( action
& SA_SSI_HIDE
)
1013 SCROLL_ShowScrollBar( hwnd
, nBar
, FALSE
, FALSE
);
1016 if( action
& SA_SSI_SHOW
)
1017 if( SCROLL_ShowScrollBar( hwnd
, nBar
, TRUE
, TRUE
) )
1018 return retVal
; /* SetWindowPos() already did the painting */
1020 if( bRedraw
&& (action
& SA_SSI_REFRESH
))
1021 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, TRUE
);
1022 else if( action
& SA_SSI_REPAINT_ARROWS
)
1023 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, FALSE
);
1028 INT
SCROLL_SetScrollInfo( HWND hwnd
, INT nBar
,
1029 const SCROLLINFO
*info
, INT
*action
)
1031 /* Update the scrollbar state and set action flags according to
1032 * what has to be done graphics wise. */
1034 SCROLLBAR_INFO
*infoPtr
;
1037 dbg_decl_str(scroll
, 256);
1041 if (!(infoPtr
= SCROLL_GetScrollInfo(hwnd
, nBar
))) return 0;
1042 if (info
->fMask
& ~(SIF_ALL
| SIF_DISABLENOSCROLL
)) return 0;
1043 if ((info
->cbSize
!= sizeof(*info
)) &&
1044 (info
->cbSize
!= sizeof(*info
)-sizeof(info
->nTrackPos
))) return 0;
1046 /* Set the page size */
1048 if (info
->fMask
& SIF_PAGE
)
1050 dsprintf(scroll
, " page=%d", info
->nPage
);
1051 if( infoPtr
->Page
!= info
->nPage
)
1053 infoPtr
->Page
= info
->nPage
;
1054 *action
|= SA_SSI_REFRESH
;
1058 /* Set the scroll pos */
1060 if (info
->fMask
& SIF_POS
)
1062 dsprintf(scroll
, " pos=%d", info
->nPos
);
1063 if( infoPtr
->CurVal
!= info
->nPos
)
1065 infoPtr
->CurVal
= info
->nPos
;
1066 *action
|= SA_SSI_REFRESH
;
1070 /* Set the scroll range */
1072 if (info
->fMask
& SIF_RANGE
)
1074 dsprintf(scroll
, " min=%d max=%d", info
->nMin
, info
->nMax
);
1076 /* Invalid range -> range is set to (0,0) */
1077 if ((info
->nMin
> info
->nMax
) ||
1078 ((UINT
)(info
->nMax
- info
->nMin
) >= 0x80000000))
1080 infoPtr
->MinVal
= 0;
1081 infoPtr
->MaxVal
= 0;
1085 if( infoPtr
->MinVal
!= info
->nMin
||
1086 infoPtr
->MaxVal
!= info
->nMax
)
1088 *action
|= SA_SSI_REFRESH
;
1089 infoPtr
->MinVal
= info
->nMin
;
1090 infoPtr
->MaxVal
= info
->nMax
;
1095 TRACE(scroll
, "hwnd=%04x bar=%d %s\n",
1096 hwnd
, nBar
, dbg_str(scroll
));
1098 /* Make sure the page size is valid */
1100 if (infoPtr
->Page
< 0) infoPtr
->Page
= 0;
1101 else if (infoPtr
->Page
> infoPtr
->MaxVal
- infoPtr
->MinVal
+ 1 )
1102 infoPtr
->Page
= infoPtr
->MaxVal
- infoPtr
->MinVal
+ 1;
1104 /* Make sure the pos is inside the range */
1106 if (infoPtr
->CurVal
< infoPtr
->MinVal
)
1107 infoPtr
->CurVal
= infoPtr
->MinVal
;
1108 else if (infoPtr
->CurVal
> infoPtr
->MaxVal
- MAX( infoPtr
->Page
-1, 0 ))
1109 infoPtr
->CurVal
= infoPtr
->MaxVal
- MAX( infoPtr
->Page
-1, 0 );
1111 TRACE(scroll
, " new values: page=%d pos=%d min=%d max=%d\n",
1112 infoPtr
->Page
, infoPtr
->CurVal
,
1113 infoPtr
->MinVal
, infoPtr
->MaxVal
);
1115 /* Check if the scrollbar should be hidden or disabled */
1117 if (info
->fMask
& (SIF_RANGE
| SIF_PAGE
| SIF_DISABLENOSCROLL
))
1119 new_flags
= infoPtr
->flags
;
1120 if (infoPtr
->MinVal
>= infoPtr
->MaxVal
- MAX( infoPtr
->Page
-1, 0 ))
1122 /* Hide or disable scroll-bar */
1123 if (info
->fMask
& SIF_DISABLENOSCROLL
)
1125 new_flags
= ESB_DISABLE_BOTH
;
1126 *action
|= SA_SSI_REFRESH
;
1128 else if (nBar
!= SB_CTL
)
1130 *action
= SA_SSI_HIDE
;
1134 else /* Show and enable scroll-bar */
1138 *action
|= SA_SSI_SHOW
;
1141 if (infoPtr
->flags
!= new_flags
) /* check arrow flags */
1143 infoPtr
->flags
= new_flags
;
1144 *action
|= SA_SSI_REPAINT_ARROWS
;
1149 /* Return current position */
1151 return infoPtr
->CurVal
;
1155 /*************************************************************************
1156 * GetScrollInfo16 (USER.476)
1158 BOOL16 WINAPI
GetScrollInfo16( HWND16 hwnd
, INT16 nBar
, LPSCROLLINFO info
)
1160 return GetScrollInfo( hwnd
, nBar
, info
);
1164 /*************************************************************************
1165 * GetScrollInfo32 (USER32.284)
1166 * GetScrollInfo32 can be used to retrieve the position, upper bound,
1167 * lower bound, and page size of a scrollbar control.
1171 BOOL WINAPI
GetScrollInfo(
1172 HWND hwnd
/* [I] Handle of window */ ,
1173 INT nBar
/* [I] One of SB_HORZ, SB_VERT, or SB_CTL */,
1174 LPSCROLLINFO info
/* [IO] (info.fMask [I] specifies which values are to retrieve) */)
1176 SCROLLBAR_INFO
*infoPtr
;
1178 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return FALSE
;
1179 if (info
->fMask
& ~(SIF_ALL
| SIF_DISABLENOSCROLL
)) return FALSE
;
1180 if ((info
->cbSize
!= sizeof(*info
)) &&
1181 (info
->cbSize
!= sizeof(*info
)-sizeof(info
->nTrackPos
))) return FALSE
;
1183 if (info
->fMask
& SIF_PAGE
) info
->nPage
= infoPtr
->Page
;
1184 if (info
->fMask
& SIF_POS
) info
->nPos
= infoPtr
->CurVal
;
1185 if ((info
->fMask
& SIF_TRACKPOS
) && (info
->cbSize
== sizeof(*info
)))
1186 info
->nTrackPos
= (SCROLL_TrackingWin
==hwnd
) ? SCROLL_TrackingVal
: 0;
1187 if (info
->fMask
& SIF_RANGE
)
1189 info
->nMin
= infoPtr
->MinVal
;
1190 info
->nMax
= infoPtr
->MaxVal
;
1192 return (info
->fMask
& SIF_ALL
) != 0;
1196 /*************************************************************************
1197 * SetScrollPos16 (USER.62)
1199 INT16 WINAPI
SetScrollPos16( HWND16 hwnd
, INT16 nBar
, INT16 nPos
,
1202 return (INT16
)SetScrollPos( hwnd
, nBar
, nPos
, bRedraw
);
1206 /*************************************************************************
1207 * SetScrollPos32 (USER32.502)
1210 * Success: Scrollbar position
1214 * Note the ambiguity when 0 is returned. Use GetLastError
1215 * to make sure there was an error (and to know which one).
1217 INT WINAPI
SetScrollPos(
1218 HWND hwnd
/* [I] Handle of window whose scrollbar will be affected */,
1219 INT nBar
/* [I] One of SB_HORZ, SB_VERT, or SB_CTL */,
1220 INT nPos
/* [I] New value */,
1221 BOOL bRedraw
/* [I] Should scrollbar be redrawn afterwards ? */ )
1224 SCROLLBAR_INFO
*infoPtr
;
1227 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return 0;
1228 oldPos
= infoPtr
->CurVal
;
1229 info
.cbSize
= sizeof(info
);
1231 info
.fMask
= SIF_POS
;
1232 SetScrollInfo( hwnd
, nBar
, &info
, bRedraw
);
1237 /*************************************************************************
1238 * GetScrollPos16 (USER.63)
1240 INT16 WINAPI
GetScrollPos16( HWND16 hwnd
, INT16 nBar
)
1242 return (INT16
)GetScrollPos( hwnd
, nBar
);
1246 /*************************************************************************
1247 * GetScrollPos32 (USER32.285)
1250 * Success: Current position
1254 * Note the ambiguity when 0 is returned. Use GetLastError
1255 * to make sure there was an error (and to know which one).
1257 INT WINAPI
GetScrollPos(
1258 HWND hwnd
, /* [I] Handle of window */
1259 INT nBar
/* [I] One of SB_HORZ, SB_VERT, or SB_CTL */)
1261 SCROLLBAR_INFO
*infoPtr
;
1263 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return 0;
1264 return infoPtr
->CurVal
;
1268 /*************************************************************************
1269 * SetScrollRange16 (USER.64)
1271 void WINAPI
SetScrollRange16( HWND16 hwnd
, INT16 nBar
,
1272 INT16 MinVal
, INT16 MaxVal
, BOOL16 bRedraw
)
1274 /* Invalid range -> range is set to (0,0) */
1275 if ((INT
)MaxVal
- (INT
)MinVal
> 0x7fff) MinVal
= MaxVal
= 0;
1276 SetScrollRange( hwnd
, nBar
, MinVal
, MaxVal
, bRedraw
);
1280 /*************************************************************************
1281 * SetScrollRange32 (USER32.503)
1285 BOOL WINAPI
SetScrollRange(
1286 HWND hwnd
, /* [I] Handle of window whose scrollbar will be affected */
1287 INT nBar
, /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */
1288 INT MinVal
, /* [I] New minimum value */
1289 INT MaxVal
, /* [I] New maximum value */
1290 BOOL bRedraw
/* [I] Should scrollbar be redrawn afterwards ? */)
1294 info
.cbSize
= sizeof(info
);
1297 info
.fMask
= SIF_RANGE
;
1298 SetScrollInfo( hwnd
, nBar
, &info
, bRedraw
);
1303 /*************************************************************************
1304 * SCROLL_SetNCSbState
1306 * Updates both scrollbars at the same time. Used by MDI CalcChildScroll().
1308 INT
SCROLL_SetNCSbState(WND
* wndPtr
, int vMin
, int vMax
, int vPos
,
1309 int hMin
, int hMax
, int hPos
)
1312 SCROLLINFO vInfo
, hInfo
;
1314 vInfo
.cbSize
= hInfo
.cbSize
= sizeof(SCROLLINFO
);
1315 vInfo
.nMin
= vMin
; hInfo
.nMin
= hMin
;
1316 vInfo
.nMax
= vMax
; hInfo
.nMax
= hMax
;
1317 vInfo
.nPos
= vPos
; hInfo
.nPos
= hPos
;
1318 vInfo
.fMask
= hInfo
.fMask
= SIF_RANGE
| SIF_POS
;
1320 SCROLL_SetScrollInfo( wndPtr
->hwndSelf
, SB_VERT
, &vInfo
, &vA
);
1321 SCROLL_SetScrollInfo( wndPtr
->hwndSelf
, SB_HORZ
, &hInfo
, &hA
);
1323 if( !SCROLL_ShowScrollBar( wndPtr
->hwndSelf
, SB_BOTH
,
1324 (hA
& SA_SSI_SHOW
),(vA
& SA_SSI_SHOW
) ) )
1326 /* SetWindowPos() wasn't called, just redraw the scrollbars if needed */
1327 if( vA
& SA_SSI_REFRESH
)
1328 SCROLL_RefreshScrollBar( wndPtr
->hwndSelf
, SB_VERT
, FALSE
, TRUE
);
1330 if( hA
& SA_SSI_REFRESH
)
1331 SCROLL_RefreshScrollBar( wndPtr
->hwndSelf
, SB_HORZ
, FALSE
, TRUE
);
1337 /*************************************************************************
1338 * GetScrollRange16 (USER.65)
1340 BOOL16 WINAPI
GetScrollRange16( HWND16 hwnd
, INT16 nBar
,
1341 LPINT16 lpMin
, LPINT16 lpMax
)
1344 BOOL16 ret
= GetScrollRange( hwnd
, nBar
, &min
, &max
);
1345 if (lpMin
) *lpMin
= min
;
1346 if (lpMax
) *lpMax
= max
;
1351 /*************************************************************************
1352 * GetScrollRange32 (USER32.286)
1356 BOOL WINAPI
GetScrollRange(
1357 HWND hwnd
, /* [I] Handle of window */
1358 INT nBar
, /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */
1359 LPINT lpMin
, /* [O] Where to store minimum value */
1360 LPINT lpMax
/* [O] Where to store maximum value */)
1362 SCROLLBAR_INFO
*infoPtr
;
1364 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
)))
1366 if (lpMin
) lpMin
= 0;
1367 if (lpMax
) lpMax
= 0;
1370 if (lpMin
) *lpMin
= infoPtr
->MinVal
;
1371 if (lpMax
) *lpMax
= infoPtr
->MaxVal
;
1376 /*************************************************************************
1377 * SCROLL_ShowScrollBar()
1379 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1380 * NOTE: fShowV/fShowH must be zero when nBar is SB_HORZ/SB_VERT.
1382 BOOL
SCROLL_ShowScrollBar( HWND hwnd
, INT nBar
,
1383 BOOL fShowH
, BOOL fShowV
)
1385 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
1387 if (!wndPtr
) return FALSE
;
1388 TRACE(scroll
, "hwnd=%04x bar=%d horz=%d, vert=%d\n",
1389 hwnd
, nBar
, fShowH
, fShowV
);
1394 ShowWindow( hwnd
, fShowH
? SW_SHOW
: SW_HIDE
);
1401 fShowH
= !(wndPtr
->dwStyle
& WS_HSCROLL
);
1402 wndPtr
->dwStyle
|= WS_HSCROLL
;
1406 fShowH
= (wndPtr
->dwStyle
& WS_HSCROLL
);
1407 wndPtr
->dwStyle
&= ~WS_HSCROLL
;
1409 if( nBar
== SB_HORZ
) break;
1415 fShowV
= !(wndPtr
->dwStyle
& WS_VSCROLL
);
1416 wndPtr
->dwStyle
|= WS_VSCROLL
;
1420 fShowV
= (wndPtr
->dwStyle
& WS_VSCROLL
);
1421 wndPtr
->dwStyle
&= ~WS_VSCROLL
;
1426 return FALSE
; /* Nothing to do! */
1429 if( fShowH
|| fShowV
) /* frame has been changed, let the window redraw itself */
1431 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
1432 | SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
1436 return FALSE
; /* no frame changes */
1440 /*************************************************************************
1441 * ShowScrollBar16 (USER.267)
1443 void WINAPI
ShowScrollBar16( HWND16 hwnd
, INT16 nBar
, BOOL16 fShow
)
1445 SCROLL_ShowScrollBar( hwnd
, nBar
, (nBar
== SB_VERT
) ? 0 : fShow
,
1446 (nBar
== SB_HORZ
) ? 0 : fShow
);
1450 /*************************************************************************
1451 * ShowScrollBar32 (USER32.532)
1455 BOOL WINAPI
ShowScrollBar(
1456 HWND hwnd
, /* [I] Handle of window whose scrollbar(s) will be affected */
1457 INT nBar
, /* [I] One of SB_HORZ, SB_VERT, SB_BOTH or SB_CTL */
1458 BOOL fShow
/* [I] TRUE = show, FALSE = hide */)
1460 SCROLL_ShowScrollBar( hwnd
, nBar
, (nBar
== SB_VERT
) ? 0 : fShow
,
1461 (nBar
== SB_HORZ
) ? 0 : fShow
);
1466 /*************************************************************************
1467 * EnableScrollBar16 (USER.482)
1469 BOOL16 WINAPI
EnableScrollBar16( HWND16 hwnd
, INT16 nBar
, UINT16 flags
)
1471 return EnableScrollBar( hwnd
, nBar
, flags
);
1475 /*************************************************************************
1476 * EnableScrollBar32 (USER32.171)
1478 BOOL WINAPI
EnableScrollBar( HWND hwnd
, INT nBar
, UINT flags
)
1481 SCROLLBAR_INFO
*infoPtr
;
1483 TRACE(scroll
, "%04x %d %d\n", hwnd
, nBar
, flags
);
1485 flags
&= ESB_DISABLE_BOTH
;
1487 if (nBar
== SB_BOTH
)
1489 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, SB_VERT
))) return FALSE
;
1490 if (!(bFineWithMe
= (infoPtr
->flags
== flags
)) )
1492 infoPtr
->flags
= flags
;
1493 SCROLL_RefreshScrollBar( hwnd
, SB_VERT
, TRUE
, TRUE
);
1500 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return FALSE
;
1501 if (bFineWithMe
&& infoPtr
->flags
== flags
) return FALSE
;
1502 infoPtr
->flags
= flags
;
1504 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, TRUE
);