4 * Copyright 1993 Martin Ayotte
5 * Copyright 1994, 1996 Alexandre Julliard
12 #include "sysmetrics.h"
20 static HBITMAP32 hUpArrow
= 0;
21 static HBITMAP32 hDnArrow
= 0;
22 static HBITMAP32 hLfArrow
= 0;
23 static HBITMAP32 hRgArrow
= 0;
24 static HBITMAP32 hUpArrowD
= 0;
25 static HBITMAP32 hDnArrowD
= 0;
26 static HBITMAP32 hLfArrowD
= 0;
27 static HBITMAP32 hRgArrowD
= 0;
28 static HBITMAP32 hUpArrowI
= 0;
29 static HBITMAP32 hDnArrowI
= 0;
30 static HBITMAP32 hLfArrowI
= 0;
31 static HBITMAP32 hRgArrowI
= 0;
33 #define TOP_ARROW(flags,pressed) \
34 (((flags)&ESB_DISABLE_UP) ? hUpArrowI : ((pressed) ? hUpArrowD:hUpArrow))
35 #define BOTTOM_ARROW(flags,pressed) \
36 (((flags)&ESB_DISABLE_DOWN) ? hDnArrowI : ((pressed) ? hDnArrowD:hDnArrow))
37 #define LEFT_ARROW(flags,pressed) \
38 (((flags)&ESB_DISABLE_LEFT) ? hLfArrowI : ((pressed) ? hLfArrowD:hLfArrow))
39 #define RIGHT_ARROW(flags,pressed) \
40 (((flags)&ESB_DISABLE_RIGHT) ? hRgArrowI : ((pressed) ? hRgArrowD:hRgArrow))
43 /* Minimum size of the rectangle between the arrows */
44 #define SCROLL_MIN_RECT 4
46 /* Minimum size of the thumb in pixels */
47 #define SCROLL_MIN_THUMB 6
49 /* Overlap between arrows and thumb */
50 #define SCROLL_ARROW_THUMB_OVERLAP 1
52 /* Delay (in ms) before first repetition when holding the button down */
53 #define SCROLL_FIRST_DELAY 200
55 /* Delay (in ms) between scroll repetitions */
56 #define SCROLL_REPEAT_DELAY 50
59 #define SCROLL_TIMER 0
61 /* Scroll-bar hit testing */
64 SCROLL_NOWHERE
, /* Outside the scroll bar */
65 SCROLL_TOP_ARROW
, /* Top or left arrow */
66 SCROLL_TOP_RECT
, /* Rectangle between the top arrow and the thumb */
67 SCROLL_THUMB
, /* Thumb rectangle */
68 SCROLL_BOTTOM_RECT
, /* Rectangle between the thumb and the bottom arrow */
69 SCROLL_BOTTOM_ARROW
/* Bottom or right arrow */
72 /* What to do after SCROLL_SetScrollInfo() */
73 #define SA_SSI_HIDE 0x0001
74 #define SA_SSI_SHOW 0x0002
75 #define SA_SSI_REFRESH 0x0004
76 #define SA_SSI_REPAINT_ARROWS 0x0008
78 /* Thumb-tracking info */
79 static HWND32 SCROLL_TrackingWin
= 0;
80 static INT32 SCROLL_TrackingBar
= 0;
81 static INT32 SCROLL_TrackingPos
= 0;
82 static INT32 SCROLL_TrackingVal
= 0;
83 /* Hit test code of the last button-down event */
84 static enum SCROLL_HITTEST SCROLL_trackHitTest
;
85 static BOOL32 SCROLL_trackVertical
;
87 /* Is the moving thumb being displayed? */
88 static BOOL32 SCROLL_MovingThumb
= FALSE
;
91 static BOOL32
SCROLL_ShowScrollBar( HWND32 hwnd
, INT32 nBar
,
92 BOOL32 fShowH
, BOOL32 fShowV
);
93 static INT32
SCROLL_SetScrollInfo( HWND32 hwnd
, INT32 nBar
,
94 const SCROLLINFO
*info
, INT32
*action
);
96 /***********************************************************************
99 static void SCROLL_LoadBitmaps(void)
101 hUpArrow
= LoadBitmap32A( 0, MAKEINTRESOURCE32A(OBM_UPARROW
) );
102 hDnArrow
= LoadBitmap32A( 0, MAKEINTRESOURCE32A(OBM_DNARROW
) );
103 hLfArrow
= LoadBitmap32A( 0, MAKEINTRESOURCE32A(OBM_LFARROW
) );
104 hRgArrow
= LoadBitmap32A( 0, MAKEINTRESOURCE32A(OBM_RGARROW
) );
105 hUpArrowD
= LoadBitmap32A( 0, MAKEINTRESOURCE32A(OBM_UPARROWD
) );
106 hDnArrowD
= LoadBitmap32A( 0, MAKEINTRESOURCE32A(OBM_DNARROWD
) );
107 hLfArrowD
= LoadBitmap32A( 0, MAKEINTRESOURCE32A(OBM_LFARROWD
) );
108 hRgArrowD
= LoadBitmap32A( 0, MAKEINTRESOURCE32A(OBM_RGARROWD
) );
109 hUpArrowI
= LoadBitmap32A( 0, MAKEINTRESOURCE32A(OBM_UPARROWI
) );
110 hDnArrowI
= LoadBitmap32A( 0, MAKEINTRESOURCE32A(OBM_DNARROWI
) );
111 hLfArrowI
= LoadBitmap32A( 0, MAKEINTRESOURCE32A(OBM_LFARROWI
) );
112 hRgArrowI
= LoadBitmap32A( 0, MAKEINTRESOURCE32A(OBM_RGARROWI
) );
116 /***********************************************************************
117 * SCROLL_GetPtrScrollInfo
119 static SCROLLBAR_INFO
*SCROLL_GetPtrScrollInfo( WND
* wndPtr
, INT32 nBar
)
121 SCROLLBAR_INFO
*infoPtr
;
123 if (!wndPtr
) return NULL
;
126 case SB_HORZ
: infoPtr
= (SCROLLBAR_INFO
*)wndPtr
->pHScroll
; break;
127 case SB_VERT
: infoPtr
= (SCROLLBAR_INFO
*)wndPtr
->pVScroll
; break;
128 case SB_CTL
: infoPtr
= (SCROLLBAR_INFO
*)wndPtr
->wExtra
; break;
129 default: return NULL
;
132 if (!infoPtr
) /* Create the info structure if needed */
134 if ((infoPtr
= HeapAlloc( SystemHeap
, 0, sizeof(SCROLLBAR_INFO
) )))
136 infoPtr
->MinVal
= infoPtr
->CurVal
= infoPtr
->Page
= 0;
137 infoPtr
->MaxVal
= 100;
138 infoPtr
->flags
= ESB_ENABLE_BOTH
;
139 if (nBar
== SB_HORZ
) wndPtr
->pHScroll
= infoPtr
;
140 else wndPtr
->pVScroll
= infoPtr
;
142 if (!hUpArrow
) SCROLL_LoadBitmaps();
148 /***********************************************************************
149 * SCROLL_GetScrollInfo
151 static SCROLLBAR_INFO
*SCROLL_GetScrollInfo( HWND32 hwnd
, INT32 nBar
)
153 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
154 return SCROLL_GetPtrScrollInfo( wndPtr
, nBar
);
158 /***********************************************************************
159 * SCROLL_GetScrollBarRect
161 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
162 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
163 * 'arrowSize' returns the width or height of an arrow (depending on
164 * the orientation of the scrollbar), 'thumbSize' returns the size of
165 * the thumb, and 'thumbPos' returns the position of the thumb
166 * relative to the left or to the top.
167 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
169 static BOOL32
SCROLL_GetScrollBarRect( HWND32 hwnd
, INT32 nBar
, RECT32
*lprect
,
170 INT32
*arrowSize
, INT32
*thumbSize
,
175 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
180 lprect
->left
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
181 lprect
->top
= wndPtr
->rectClient
.bottom
- wndPtr
->rectWindow
.top
;
182 lprect
->right
= wndPtr
->rectClient
.right
- wndPtr
->rectWindow
.left
;
183 lprect
->bottom
= lprect
->top
+ SYSMETRICS_CYHSCROLL
;
184 if(wndPtr
->dwStyle
& WS_BORDER
) {
187 } else if(wndPtr
->dwStyle
& WS_VSCROLL
)
193 lprect
->left
= wndPtr
->rectClient
.right
- wndPtr
->rectWindow
.left
;
194 lprect
->top
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
195 lprect
->right
= lprect
->left
+ SYSMETRICS_CXVSCROLL
;
196 lprect
->bottom
= wndPtr
->rectClient
.bottom
- wndPtr
->rectWindow
.top
;
197 if(wndPtr
->dwStyle
& WS_BORDER
) {
200 } else if(wndPtr
->dwStyle
& WS_HSCROLL
)
206 GetClientRect32( hwnd
, lprect
);
207 vertical
= ((wndPtr
->dwStyle
& SBS_VERT
) != 0);
214 if (vertical
) pixels
= lprect
->bottom
- lprect
->top
;
215 else pixels
= lprect
->right
- lprect
->left
;
217 if (pixels
<= 2*SYSMETRICS_CXVSCROLL
+ SCROLL_MIN_RECT
)
219 if (pixels
> SCROLL_MIN_RECT
)
220 *arrowSize
= (pixels
- SCROLL_MIN_RECT
) / 2;
223 *thumbPos
= *thumbSize
= 0;
227 SCROLLBAR_INFO
*info
= SCROLL_GetPtrScrollInfo( wndPtr
, nBar
);
229 *arrowSize
= SYSMETRICS_CXVSCROLL
;
230 pixels
-= (2 * (SYSMETRICS_CXVSCROLL
- SCROLL_ARROW_THUMB_OVERLAP
));
234 *thumbSize
= pixels
* info
->Page
/ (info
->MaxVal
-info
->MinVal
+1);
235 if (*thumbSize
< SCROLL_MIN_THUMB
) *thumbSize
= SCROLL_MIN_THUMB
;
237 else *thumbSize
= SYSMETRICS_CXVSCROLL
;
239 if (((pixels
-= *thumbSize
) < 0) ||
240 ((info
->flags
& ESB_DISABLE_BOTH
) == ESB_DISABLE_BOTH
))
242 /* Rectangle too small or scrollbar disabled -> no thumb */
243 *thumbPos
= *thumbSize
= 0;
247 INT32 max
= info
->MaxVal
- MAX( info
->Page
-1, 0 );
248 if (info
->MinVal
>= max
)
249 *thumbPos
= *arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
251 *thumbPos
= *arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
252 + pixels
* (info
->CurVal
-info
->MinVal
) / (max
- info
->MinVal
);
259 /***********************************************************************
262 * Compute the current scroll position based on the thumb position in pixels
263 * from the top of the scroll-bar.
265 static UINT32
SCROLL_GetThumbVal( SCROLLBAR_INFO
*infoPtr
, RECT32
*rect
,
266 BOOL32 vertical
, INT32 pos
)
269 INT32 pixels
= vertical
? rect
->bottom
-rect
->top
: rect
->right
-rect
->left
;
271 if ((pixels
-= 2*(SYSMETRICS_CXVSCROLL
- SCROLL_ARROW_THUMB_OVERLAP
)) <= 0)
272 return infoPtr
->MinVal
;
276 thumbSize
= pixels
* infoPtr
->Page
/(infoPtr
->MaxVal
-infoPtr
->MinVal
+1);
277 if (thumbSize
< SCROLL_MIN_THUMB
) thumbSize
= SCROLL_MIN_THUMB
;
279 else thumbSize
= SYSMETRICS_CXVSCROLL
;
281 if ((pixels
-= thumbSize
) <= 0) return infoPtr
->MinVal
;
283 pos
= MAX( 0, pos
- (SYSMETRICS_CXVSCROLL
- SCROLL_ARROW_THUMB_OVERLAP
) );
284 if (pos
> pixels
) pos
= pixels
;
286 if (!infoPtr
->Page
) pos
*= infoPtr
->MaxVal
- infoPtr
->MinVal
;
287 else pos
*= infoPtr
->MaxVal
- infoPtr
->MinVal
- infoPtr
->Page
+ 1;
288 return infoPtr
->MinVal
+ ((pos
+ pixels
/ 2) / pixels
);
291 /***********************************************************************
294 static BOOL32
SCROLL_PtInRectEx( LPRECT32 lpRect
, POINT32 pt
, BOOL32 vertical
)
296 RECT32 rect
= *lpRect
;
300 rect
.left
-= lpRect
->right
- lpRect
->left
;
301 rect
.right
+= lpRect
->right
- lpRect
->left
;
305 rect
.top
-= lpRect
->bottom
- lpRect
->top
;
306 rect
.bottom
+= lpRect
->bottom
- lpRect
->top
;
308 return PtInRect32( &rect
, pt
);
311 /***********************************************************************
314 static POINT32
SCROLL_ClipPos( LPRECT32 lpRect
, POINT32 pt
)
316 if( pt
.x
< lpRect
->left
)
319 if( pt
.x
> lpRect
->right
)
320 pt
.x
= lpRect
->right
;
322 if( pt
.y
< lpRect
->top
)
325 if( pt
.y
> lpRect
->bottom
)
326 pt
.y
= lpRect
->bottom
;
332 /***********************************************************************
335 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
337 static enum SCROLL_HITTEST
SCROLL_HitTest( HWND32 hwnd
, INT32 nBar
,
338 POINT32 pt
, BOOL32 bDragging
)
340 INT32 arrowSize
, thumbSize
, thumbPos
;
343 BOOL32 vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
344 &arrowSize
, &thumbSize
, &thumbPos
);
346 if ( (bDragging
&& !SCROLL_PtInRectEx( &rect
, pt
, vertical
)) ||
347 (!PtInRect32( &rect
, pt
)) ) return SCROLL_NOWHERE
;
351 if (pt
.y
< rect
.top
+ arrowSize
) return SCROLL_TOP_ARROW
;
352 if (pt
.y
>= rect
.bottom
- arrowSize
) return SCROLL_BOTTOM_ARROW
;
353 if (!thumbPos
) return SCROLL_TOP_RECT
;
355 if (pt
.y
< thumbPos
) return SCROLL_TOP_RECT
;
356 if (pt
.y
>= thumbPos
+ thumbSize
) return SCROLL_BOTTOM_RECT
;
358 else /* horizontal */
360 if (pt
.x
< rect
.left
+ arrowSize
) return SCROLL_TOP_ARROW
;
361 if (pt
.x
>= rect
.right
- arrowSize
) return SCROLL_BOTTOM_ARROW
;
362 if (!thumbPos
) return SCROLL_TOP_RECT
;
364 if (pt
.x
< thumbPos
) return SCROLL_TOP_RECT
;
365 if (pt
.x
>= thumbPos
+ thumbSize
) return SCROLL_BOTTOM_RECT
;
371 /***********************************************************************
374 * Draw the scroll bar arrows.
376 static void SCROLL_DrawArrows( HDC32 hdc
, SCROLLBAR_INFO
*infoPtr
,
377 RECT32
*rect
, INT32 arrowSize
, BOOL32 vertical
,
378 BOOL32 top_pressed
, BOOL32 bottom_pressed
)
380 HDC32 hdcMem
= CreateCompatibleDC32( hdc
);
381 HBITMAP32 hbmpPrev
= SelectObject32( hdcMem
, vertical
?
382 TOP_ARROW(infoPtr
->flags
, top_pressed
)
383 : LEFT_ARROW(infoPtr
->flags
, top_pressed
));
385 SetStretchBltMode32( hdc
, STRETCH_DELETESCANS
);
386 StretchBlt32( hdc
, rect
->left
, rect
->top
,
387 vertical
? rect
->right
-rect
->left
: arrowSize
,
388 vertical
? arrowSize
: rect
->bottom
-rect
->top
,
390 SYSMETRICS_CXVSCROLL
, SYSMETRICS_CYHSCROLL
,
393 SelectObject32( hdcMem
, vertical
?
394 BOTTOM_ARROW( infoPtr
->flags
, bottom_pressed
)
395 : RIGHT_ARROW( infoPtr
->flags
, bottom_pressed
) );
397 StretchBlt32( hdc
, rect
->left
, rect
->bottom
- arrowSize
,
398 rect
->right
- rect
->left
, arrowSize
,
400 SYSMETRICS_CXVSCROLL
, SYSMETRICS_CYHSCROLL
,
403 StretchBlt32( hdc
, rect
->right
- arrowSize
, rect
->top
,
404 arrowSize
, rect
->bottom
- rect
->top
,
406 SYSMETRICS_CXVSCROLL
, SYSMETRICS_CYHSCROLL
,
408 SelectObject32( hdcMem
, hbmpPrev
);
409 DeleteDC32( hdcMem
);
413 /***********************************************************************
414 * SCROLL_DrawMovingThumb
416 * Draw the moving thumb rectangle.
418 static void SCROLL_DrawMovingThumb( HDC32 hdc
, RECT32
*rect
, BOOL32 vertical
,
419 INT32 arrowSize
, INT32 thumbSize
)
424 r
.top
+= SCROLL_TrackingPos
;
425 if (r
.top
< rect
->top
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
426 r
.top
= rect
->top
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
427 if (r
.top
+ thumbSize
>
428 rect
->bottom
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
))
429 r
.top
= rect
->bottom
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
431 r
.bottom
= r
.top
+ thumbSize
;
435 r
.left
+= SCROLL_TrackingPos
;
436 if (r
.left
< rect
->left
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
437 r
.left
= rect
->left
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
438 if (r
.left
+ thumbSize
>
439 rect
->right
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
))
440 r
.left
= rect
->right
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
442 r
.right
= r
.left
+ thumbSize
;
444 DrawFocusRect32( hdc
, &r
);
445 SCROLL_MovingThumb
= !SCROLL_MovingThumb
;
449 /***********************************************************************
450 * SCROLL_DrawInterior
452 * Draw the scroll bar interior (everything except the arrows).
454 static void SCROLL_DrawInterior( HWND32 hwnd
, HDC32 hdc
, INT32 nBar
,
455 RECT32
*rect
, INT32 arrowSize
,
456 INT32 thumbSize
, INT32 thumbPos
,
457 UINT32 flags
, BOOL32 vertical
,
458 BOOL32 top_selected
, BOOL32 bottom_selected
)
462 /* Select the correct brush and pen */
464 SelectObject32( hdc
, GetSysColorPen32(COLOR_WINDOWFRAME
) );
465 if ((flags
& ESB_DISABLE_BOTH
) == ESB_DISABLE_BOTH
)
467 /* This ought to be the color of the parent window */
468 SelectObject32( hdc
, GetSysColorBrush32(COLOR_WINDOW
) );
472 if (nBar
== SB_CTL
) /* Only scrollbar controls send WM_CTLCOLOR */
474 HBRUSH32 hbrush
= SendMessage32A(GetParent32(hwnd
),
475 WM_CTLCOLORSCROLLBAR
, hdc
, hwnd
);
476 SelectObject32( hdc
, hbrush
);
478 else SelectObject32( hdc
, GetSysColorBrush32(COLOR_SCROLLBAR
) );
481 /* Calculate the scroll rectangle */
486 r
.top
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
487 r
.bottom
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
491 r
.left
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
492 r
.right
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
495 /* Draw the scroll bar frame */
497 GRAPH_DrawRectangle( hdc
, r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
, 0);
499 /* Draw the scroll rectangles and thumb */
501 if (!thumbPos
) /* No thumb to draw */
503 PatBlt32( hdc
, r
.left
+1, r
.top
+1, r
.right
- r
.left
- 2,
504 r
.bottom
- r
.top
- 2, PATCOPY
);
510 PatBlt32( hdc
, r
.left
+ 1, r
.top
+ 1,
511 r
.right
- r
.left
- 2,
512 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
) - 1,
513 top_selected
? 0x0f0000 : PATCOPY
);
514 r
.top
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
515 PatBlt32( hdc
, r
.left
+ 1, r
.top
+ thumbSize
,
516 r
.right
- r
.left
- 2,
517 r
.bottom
- r
.top
- thumbSize
- 1,
518 bottom_selected
? 0x0f0000 : PATCOPY
);
519 r
.bottom
= r
.top
+ thumbSize
;
521 else /* horizontal */
523 PatBlt32( hdc
, r
.left
+ 1, r
.top
+ 1,
524 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
) - 1,
525 r
.bottom
- r
.top
- 2,
526 top_selected
? 0x0f0000 : PATCOPY
);
527 r
.left
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
528 PatBlt32( hdc
, r
.left
+ thumbSize
, r
.top
+ 1,
529 r
.right
- r
.left
- thumbSize
- 1,
530 r
.bottom
- r
.top
- 2,
531 bottom_selected
? 0x0f0000 : PATCOPY
);
532 r
.right
= r
.left
+ thumbSize
;
537 SelectObject32( hdc
, GetSysColorBrush32(COLOR_BTNFACE
) );
538 Rectangle32( hdc
, r
.left
, r
.top
, r
.right
, r
.bottom
);
539 InflateRect32( &r
, -1, -1 );
540 GRAPH_DrawReliefRect( hdc
, &r
, 1, 2, FALSE
);
541 if (SCROLL_MovingThumb
&&
542 (SCROLL_TrackingWin
== hwnd
) &&
543 (SCROLL_TrackingBar
== nBar
))
545 SCROLL_DrawMovingThumb( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
546 SCROLL_MovingThumb
= TRUE
;
551 /***********************************************************************
552 * SCROLL_DrawScrollBar
554 * Redraw the whole scrollbar.
556 void SCROLL_DrawScrollBar( HWND32 hwnd
, HDC32 hdc
, INT32 nBar
,
557 BOOL32 arrows
, BOOL32 interior
)
559 INT32 arrowSize
, thumbSize
, thumbPos
;
562 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
563 SCROLLBAR_INFO
*infoPtr
= SCROLL_GetPtrScrollInfo( wndPtr
, nBar
);
565 if (!wndPtr
|| !infoPtr
||
566 ((nBar
== SB_VERT
) && !(wndPtr
->dwStyle
& WS_VSCROLL
)) ||
567 ((nBar
== SB_HORZ
) && !(wndPtr
->dwStyle
& WS_HSCROLL
))) return;
568 if (!WIN_IsWindowDrawable( wndPtr
, FALSE
)) return;
570 vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
571 &arrowSize
, &thumbSize
, &thumbPos
);
573 /* Draw the arrows */
575 if (arrows
&& arrowSize
)
577 if( vertical
== SCROLL_trackVertical
&& GetCapture32() == hwnd
)
578 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
579 (SCROLL_trackHitTest
== SCROLL_TOP_ARROW
),
580 (SCROLL_trackHitTest
== SCROLL_BOTTOM_ARROW
) );
582 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
586 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
587 thumbPos
, infoPtr
->flags
, vertical
, FALSE
, FALSE
);
591 /***********************************************************************
592 * SCROLL_RefreshScrollBar
594 * Repaint the scroll bar interior after a SetScrollRange() or
595 * SetScrollPos() call.
597 static void SCROLL_RefreshScrollBar( HWND32 hwnd
, INT32 nBar
,
598 BOOL32 arrows
, BOOL32 interior
)
600 HDC32 hdc
= GetDCEx32( hwnd
, 0,
601 DCX_CACHE
| ((nBar
== SB_CTL
) ? 0 : DCX_WINDOW
) );
604 SCROLL_DrawScrollBar( hwnd
, hdc
, nBar
, arrows
, interior
);
605 ReleaseDC32( hwnd
, hdc
);
609 /***********************************************************************
610 * SCROLL_HandleKbdEvent
612 * Handle a keyboard event (only for SB_CTL scrollbars).
614 static void SCROLL_HandleKbdEvent( HWND32 hwnd
, WPARAM32 wParam
)
616 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
621 case VK_PRIOR
: msg
= SB_PAGEUP
; break;
622 case VK_NEXT
: msg
= SB_PAGEDOWN
; break;
623 case VK_HOME
: msg
= SB_TOP
; break;
624 case VK_END
: msg
= SB_BOTTOM
; break;
625 case VK_UP
: msg
= SB_LINEUP
; break;
626 case VK_DOWN
: msg
= SB_LINEDOWN
; break;
630 SendMessage32A( GetParent32(hwnd
),
631 (wndPtr
->dwStyle
& SBS_VERT
) ? WM_VSCROLL
: WM_HSCROLL
,
636 /***********************************************************************
637 * SCROLL_HandleScrollEvent
639 * Handle a mouse or timer event for the scrollbar.
640 * 'pt' is the location of the mouse event in client (for SB_CTL) or
641 * windows coordinates.
643 void SCROLL_HandleScrollEvent( HWND32 hwnd
, INT32 nBar
, UINT32 msg
, POINT32 pt
)
645 /* Previous mouse position for timer events */
646 static POINT32 prevPt
;
647 /* Thumb position when tracking started. */
648 static UINT32 trackThumbPos
;
649 /* Position in the scroll-bar of the last button-down event. */
650 static INT32 lastClickPos
;
651 /* Position in the scroll-bar of the last mouse event. */
652 static INT32 lastMousePos
;
654 enum SCROLL_HITTEST hittest
;
655 HWND32 hwndOwner
, hwndCtl
;
657 INT32 arrowSize
, thumbSize
, thumbPos
;
661 SCROLLBAR_INFO
*infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
);
662 if (!infoPtr
) return;
663 if ((SCROLL_trackHitTest
== SCROLL_NOWHERE
) && (msg
!= WM_LBUTTONDOWN
))
666 hdc
= GetDCEx32( hwnd
, 0, DCX_CACHE
| ((nBar
== SB_CTL
) ? 0 : DCX_WINDOW
));
667 vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
668 &arrowSize
, &thumbSize
, &thumbPos
);
669 hwndOwner
= (nBar
== SB_CTL
) ? GetParent32(hwnd
) : hwnd
;
670 hwndCtl
= (nBar
== SB_CTL
) ? hwnd
: 0;
674 case WM_LBUTTONDOWN
: /* Initialise mouse tracking */
675 SCROLL_trackVertical
= vertical
;
676 SCROLL_trackHitTest
= hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, FALSE
);
677 lastClickPos
= vertical
? (pt
.y
- rect
.top
) : (pt
.x
- rect
.left
);
678 lastMousePos
= lastClickPos
;
679 trackThumbPos
= thumbPos
;
681 SetCapture32( hwnd
);
682 if (nBar
== SB_CTL
) SetFocus32( hwnd
);
686 hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, TRUE
);
691 hittest
= SCROLL_NOWHERE
;
697 hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, FALSE
);
701 return; /* Should never happen */
704 TRACE(scroll
, "Event: hwnd=%04x bar=%d msg=%x pt=%d,%d hit=%d\n",
705 hwnd
, nBar
, msg
, pt
.x
, pt
.y
, hittest
);
707 switch(SCROLL_trackHitTest
)
709 case SCROLL_NOWHERE
: /* No tracking in progress */
712 case SCROLL_TOP_ARROW
:
713 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
714 (hittest
== SCROLL_trackHitTest
), FALSE
);
715 if (hittest
== SCROLL_trackHitTest
)
717 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
719 SendMessage32A( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
720 SB_LINEUP
, hwndCtl
);
721 SetSystemTimer32( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
722 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
726 else KillSystemTimer32( hwnd
, SCROLL_TIMER
);
729 case SCROLL_TOP_RECT
:
730 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
731 thumbPos
, infoPtr
->flags
, vertical
,
732 (hittest
== SCROLL_trackHitTest
), FALSE
);
733 if (hittest
== SCROLL_trackHitTest
)
735 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
737 SendMessage32A( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
738 SB_PAGEUP
, hwndCtl
);
739 SetSystemTimer32( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
740 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
744 else KillSystemTimer32( hwnd
, SCROLL_TIMER
);
748 if (msg
== WM_LBUTTONDOWN
)
750 SCROLL_TrackingWin
= hwnd
;
751 SCROLL_TrackingBar
= nBar
;
752 SCROLL_TrackingPos
= trackThumbPos
+ lastMousePos
- lastClickPos
;
753 SCROLL_DrawMovingThumb(hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
755 else if (msg
== WM_LBUTTONUP
)
757 SCROLL_TrackingWin
= 0;
758 SCROLL_MovingThumb
= FALSE
;
759 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
760 thumbPos
, infoPtr
->flags
, vertical
,
763 else /* WM_MOUSEMOVE */
767 if (!SCROLL_PtInRectEx( &rect
, pt
, vertical
)) pos
= lastClickPos
;
770 pt
= SCROLL_ClipPos( &rect
, pt
);
771 pos
= vertical
? (pt
.y
- rect
.top
) : (pt
.x
- rect
.left
);
773 if (pos
!= lastMousePos
)
775 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
,
776 arrowSize
, thumbSize
);
778 SCROLL_TrackingPos
= trackThumbPos
+ pos
- lastClickPos
;
779 SCROLL_TrackingVal
= SCROLL_GetThumbVal( infoPtr
, &rect
,
781 SCROLL_TrackingPos
);
782 SendMessage32A( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
783 MAKEWPARAM( SB_THUMBTRACK
, SCROLL_TrackingVal
),
785 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
,
786 arrowSize
, thumbSize
);
791 case SCROLL_BOTTOM_RECT
:
792 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
793 thumbPos
, infoPtr
->flags
, vertical
,
794 FALSE
, (hittest
== SCROLL_trackHitTest
) );
795 if (hittest
== SCROLL_trackHitTest
)
797 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
799 SendMessage32A( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
800 SB_PAGEDOWN
, hwndCtl
);
801 SetSystemTimer32( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
802 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
806 else KillSystemTimer32( hwnd
, SCROLL_TIMER
);
809 case SCROLL_BOTTOM_ARROW
:
810 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
811 FALSE
, (hittest
== SCROLL_trackHitTest
) );
812 if (hittest
== SCROLL_trackHitTest
)
814 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
816 SendMessage32A( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
817 SB_LINEDOWN
, hwndCtl
);
818 SetSystemTimer32( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
819 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
823 else KillSystemTimer32( hwnd
, SCROLL_TIMER
);
827 if (msg
== WM_LBUTTONUP
)
829 hittest
= SCROLL_trackHitTest
;
830 SCROLL_trackHitTest
= SCROLL_NOWHERE
; /* Terminate tracking */
832 if (hittest
== SCROLL_THUMB
)
834 UINT32 val
= SCROLL_GetThumbVal( infoPtr
, &rect
, vertical
,
835 trackThumbPos
+ lastMousePos
- lastClickPos
);
836 SendMessage32A( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
837 MAKEWPARAM( SB_THUMBPOSITION
, val
), hwndCtl
);
840 SendMessage32A( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
841 SB_ENDSCROLL
, hwndCtl
);
844 ReleaseDC32( hwnd
, hdc
);
848 /***********************************************************************
851 LRESULT WINAPI
ScrollBarWndProc( HWND32 hwnd
, UINT32 message
, WPARAM32 wParam
,
858 CREATESTRUCT32A
*lpCreat
= (CREATESTRUCT32A
*)lParam
;
859 if (lpCreat
->style
& SBS_SIZEBOX
)
861 FIXME(scroll
, "Unimplemented style SBS_SIZEBOX.\n" );
865 if (lpCreat
->style
& SBS_VERT
)
867 if (lpCreat
->style
& SBS_LEFTALIGN
)
868 MoveWindow32( hwnd
, lpCreat
->x
, lpCreat
->y
,
869 SYSMETRICS_CXVSCROLL
+1, lpCreat
->cy
, FALSE
);
870 else if (lpCreat
->style
& SBS_RIGHTALIGN
)
872 lpCreat
->x
+lpCreat
->cx
-SYSMETRICS_CXVSCROLL
-1,
874 SYSMETRICS_CXVSCROLL
+1, lpCreat
->cy
, FALSE
);
878 if (lpCreat
->style
& SBS_TOPALIGN
)
879 MoveWindow32( hwnd
, lpCreat
->x
, lpCreat
->y
,
880 lpCreat
->cx
, SYSMETRICS_CYHSCROLL
+1, FALSE
);
881 else if (lpCreat
->style
& SBS_BOTTOMALIGN
)
884 lpCreat
->y
+lpCreat
->cy
-SYSMETRICS_CYHSCROLL
-1,
885 lpCreat
->cx
, SYSMETRICS_CYHSCROLL
+1, FALSE
);
888 if (!hUpArrow
) SCROLL_LoadBitmaps();
889 TRACE(scroll
, "ScrollBar creation, hwnd=%04x\n", hwnd
);
898 CONV_POINT16TO32( (POINT16
*)&lParam
, &pt
);
899 SCROLL_HandleScrollEvent( hwnd
, SB_CTL
, message
, pt
);
904 SCROLL_HandleKbdEvent( hwnd
, wParam
);
911 return DLGC_WANTARROWS
; /* Windows returns this value */
916 HDC32 hdc
= BeginPaint32( hwnd
, &ps
);
917 SCROLL_DrawScrollBar( hwnd
, hdc
, SB_CTL
, TRUE
, TRUE
);
918 EndPaint32( hwnd
, &ps
);
924 return SetScrollPos32( hwnd
, SB_CTL
, wParam
, (BOOL32
)lParam
);
928 return GetScrollPos32( hwnd
, SB_CTL
);
931 SetScrollRange32( hwnd
, SB_CTL
, LOWORD(lParam
), HIWORD(lParam
),
932 wParam
/* FIXME: Is this correct? */ );
936 SetScrollRange32( hwnd
, SB_CTL
, wParam
, lParam
, FALSE
);
937 return 0; /* FIXME: return previous position */
940 FIXME(scroll
, "don't know how to handle SBM_GETRANGE16 (wp=%04x,lp=%08lx)\n", wParam
, lParam
);
944 GetScrollRange32( hwnd
, SB_CTL
, (LPINT32
)wParam
, (LPINT32
)lParam
);
947 case SBM_ENABLE_ARROWS16
:
948 case SBM_ENABLE_ARROWS32
:
949 return EnableScrollBar32( hwnd
, SB_CTL
, wParam
);
951 case SBM_SETRANGEREDRAW32
:
952 SetScrollRange32( hwnd
, SB_CTL
, wParam
, lParam
, TRUE
);
953 return 0; /* FIXME: return previous position */
955 case SBM_SETSCROLLINFO32
:
956 return SetScrollInfo32( hwnd
, SB_CTL
, (SCROLLINFO
*)lParam
, wParam
);
958 case SBM_GETSCROLLINFO32
:
959 return GetScrollInfo32( hwnd
, SB_CTL
, (SCROLLINFO
*)lParam
);
969 ERR(scroll
, "unknown Win32 msg %04x wp=%08x lp=%08lx\n",
970 message
, wParam
, lParam
);
974 if (message
>= WM_USER
)
975 WARN(scroll
, "unknown msg %04x wp=%04x lp=%08lx\n",
976 message
, wParam
, lParam
);
977 return DefWindowProc32A( hwnd
, message
, wParam
, lParam
);
983 /*************************************************************************
984 * SetScrollInfo16 (USER.475)
986 INT16 WINAPI
SetScrollInfo16( HWND16 hwnd
, INT16 nBar
, const SCROLLINFO
*info
,
989 return (INT16
)SetScrollInfo32( hwnd
, nBar
, info
, bRedraw
);
993 /*************************************************************************
994 * SetScrollInfo32 (USER32.501)
995 * SetScrollInfo32 can be used to set the position, upper bound,
996 * lower bound, and page size of a scrollbar control.
1002 * For 100 lines of text to be displayed in a window of 25 lines,
1003 * one would for instance use info->nMin=0, info->nMax=75
1004 * (corresponding to the 76 different positions of the window on
1005 * the text), and info->nPage=25.
1007 INT32 WINAPI
SetScrollInfo32(
1008 HWND32 hwnd
/* [I] Handle of window whose scrollbar will be affected */,
1009 INT32 nBar
/* [I] One of SB_HORZ, SB_VERT, or SB_CTL */,
1010 const SCROLLINFO
*info
/* [I] Specifies what to change and new values */,
1011 BOOL32 bRedraw
/* [I] Should scrollbar be redrawn afterwards ? */)
1014 INT32 retVal
= SCROLL_SetScrollInfo( hwnd
, nBar
, info
, &action
);
1016 if( action
& SA_SSI_HIDE
)
1017 SCROLL_ShowScrollBar( hwnd
, nBar
, FALSE
, FALSE
);
1020 if( action
& SA_SSI_SHOW
)
1021 if( SCROLL_ShowScrollBar( hwnd
, nBar
, TRUE
, TRUE
) )
1022 return retVal
; /* SetWindowPos() already did the painting */
1024 if( bRedraw
&& (action
& SA_SSI_REFRESH
))
1025 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, TRUE
);
1026 else if( action
& SA_SSI_REPAINT_ARROWS
)
1027 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, FALSE
);
1032 INT32
SCROLL_SetScrollInfo( HWND32 hwnd
, INT32 nBar
,
1033 const SCROLLINFO
*info
, INT32
*action
)
1035 /* Update the scrollbar state and set action flags according to
1036 * what has to be done graphics wise. */
1038 SCROLLBAR_INFO
*infoPtr
;
1041 dbg_decl_str(scroll
, 256);
1045 if (!(infoPtr
= SCROLL_GetScrollInfo(hwnd
, nBar
))) return 0;
1046 if (info
->fMask
& ~(SIF_ALL
| SIF_DISABLENOSCROLL
)) return 0;
1047 if ((info
->cbSize
!= sizeof(*info
)) &&
1048 (info
->cbSize
!= sizeof(*info
)-sizeof(info
->nTrackPos
))) return 0;
1050 /* Set the page size */
1052 if (info
->fMask
& SIF_PAGE
)
1054 dsprintf(scroll
, " page=%d", info
->nPage
);
1055 if( infoPtr
->Page
!= info
->nPage
)
1057 infoPtr
->Page
= info
->nPage
;
1058 *action
|= SA_SSI_REFRESH
;
1062 /* Set the scroll pos */
1064 if (info
->fMask
& SIF_POS
)
1066 dsprintf(scroll
, " pos=%d", info
->nPos
);
1067 if( infoPtr
->CurVal
!= info
->nPos
)
1069 infoPtr
->CurVal
= info
->nPos
;
1070 *action
|= SA_SSI_REFRESH
;
1074 /* Set the scroll range */
1076 if (info
->fMask
& SIF_RANGE
)
1078 dsprintf(scroll
, " min=%d max=%d", info
->nMin
, info
->nMax
);
1080 /* Invalid range -> range is set to (0,0) */
1081 if ((info
->nMin
> info
->nMax
) ||
1082 ((UINT32
)(info
->nMax
- info
->nMin
) >= 0x80000000))
1084 infoPtr
->MinVal
= 0;
1085 infoPtr
->MaxVal
= 0;
1089 if( infoPtr
->MinVal
!= info
->nMin
||
1090 infoPtr
->MaxVal
!= info
->nMax
)
1092 *action
|= SA_SSI_REFRESH
;
1093 infoPtr
->MinVal
= info
->nMin
;
1094 infoPtr
->MaxVal
= info
->nMax
;
1099 TRACE(scroll
, "hwnd=%04x bar=%d %s\n",
1100 hwnd
, nBar
, dbg_str(scroll
));
1102 /* Make sure the page size is valid */
1104 if (infoPtr
->Page
< 0) infoPtr
->Page
= 0;
1105 else if (infoPtr
->Page
> infoPtr
->MaxVal
- infoPtr
->MinVal
+ 1 )
1106 infoPtr
->Page
= infoPtr
->MaxVal
- infoPtr
->MinVal
+ 1;
1108 /* Make sure the pos is inside the range */
1110 if (infoPtr
->CurVal
< infoPtr
->MinVal
)
1111 infoPtr
->CurVal
= infoPtr
->MinVal
;
1112 else if (infoPtr
->CurVal
> infoPtr
->MaxVal
- MAX( infoPtr
->Page
-1, 0 ))
1113 infoPtr
->CurVal
= infoPtr
->MaxVal
- MAX( infoPtr
->Page
-1, 0 );
1115 TRACE(scroll
, " new values: page=%d pos=%d min=%d max=%d\n",
1116 infoPtr
->Page
, infoPtr
->CurVal
,
1117 infoPtr
->MinVal
, infoPtr
->MaxVal
);
1119 /* Check if the scrollbar should be hidden or disabled */
1121 if (info
->fMask
& (SIF_RANGE
| SIF_PAGE
| SIF_DISABLENOSCROLL
))
1123 new_flags
= infoPtr
->flags
;
1124 if (infoPtr
->MinVal
>= infoPtr
->MaxVal
- MAX( infoPtr
->Page
-1, 0 ))
1126 /* Hide or disable scroll-bar */
1127 if (info
->fMask
& SIF_DISABLENOSCROLL
)
1129 new_flags
= ESB_DISABLE_BOTH
;
1130 *action
|= SA_SSI_REFRESH
;
1132 else if (nBar
!= SB_CTL
)
1134 *action
= SA_SSI_HIDE
;
1138 else /* Show and enable scroll-bar */
1142 *action
|= SA_SSI_SHOW
;
1145 if (infoPtr
->flags
!= new_flags
) /* check arrow flags */
1147 infoPtr
->flags
= new_flags
;
1148 *action
|= SA_SSI_REPAINT_ARROWS
;
1153 /* Return current position */
1155 return infoPtr
->CurVal
;
1159 /*************************************************************************
1160 * GetScrollInfo16 (USER.476)
1162 BOOL16 WINAPI
GetScrollInfo16( HWND16 hwnd
, INT16 nBar
, LPSCROLLINFO info
)
1164 return GetScrollInfo32( hwnd
, nBar
, info
);
1168 /*************************************************************************
1169 * GetScrollInfo32 (USER32.284)
1170 * GetScrollInfo32 can be used to retrieve the position, upper bound,
1171 * lower bound, and page size of a scrollbar control.
1175 BOOL32 WINAPI
GetScrollInfo32(
1176 HWND32 hwnd
/* [I] Handle of window */ ,
1177 INT32 nBar
/* [I] One of SB_HORZ, SB_VERT, or SB_CTL */,
1178 LPSCROLLINFO info
/* [IO] (info.fMask [I] specifies which values are to retrieve) */)
1180 SCROLLBAR_INFO
*infoPtr
;
1182 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return FALSE
;
1183 if (info
->fMask
& ~(SIF_ALL
| SIF_DISABLENOSCROLL
)) return FALSE
;
1184 if ((info
->cbSize
!= sizeof(*info
)) &&
1185 (info
->cbSize
!= sizeof(*info
)-sizeof(info
->nTrackPos
))) return FALSE
;
1187 if (info
->fMask
& SIF_PAGE
) info
->nPage
= infoPtr
->Page
;
1188 if (info
->fMask
& SIF_POS
) info
->nPos
= infoPtr
->CurVal
;
1189 if ((info
->fMask
& SIF_TRACKPOS
) && (info
->cbSize
== sizeof(*info
)))
1190 info
->nTrackPos
= (SCROLL_TrackingWin
==hwnd
) ? SCROLL_TrackingVal
: 0;
1191 if (info
->fMask
& SIF_RANGE
)
1193 info
->nMin
= infoPtr
->MinVal
;
1194 info
->nMax
= infoPtr
->MaxVal
;
1196 return (info
->fMask
& SIF_ALL
) != 0;
1200 /*************************************************************************
1201 * SetScrollPos16 (USER.62)
1203 INT16 WINAPI
SetScrollPos16( HWND16 hwnd
, INT16 nBar
, INT16 nPos
,
1206 return (INT16
)SetScrollPos32( hwnd
, nBar
, nPos
, bRedraw
);
1210 /*************************************************************************
1211 * SetScrollPos32 (USER32.502)
1214 * Success: Scrollbar position
1218 * Note the ambiguity when 0 is returned. Use GetLastError
1219 * to make sure there was an error (and to know which one).
1221 INT32 WINAPI
SetScrollPos32(
1222 HWND32 hwnd
/* [I] Handle of window whose scrollbar will be affected */,
1223 INT32 nBar
/* [I] One of SB_HORZ, SB_VERT, or SB_CTL */,
1224 INT32 nPos
/* [I] New value */,
1225 BOOL32 bRedraw
/* [I] Should scrollbar be redrawn afterwards ? */ )
1228 SCROLLBAR_INFO
*infoPtr
;
1231 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return 0;
1232 oldPos
= infoPtr
->CurVal
;
1233 info
.cbSize
= sizeof(info
);
1235 info
.fMask
= SIF_POS
;
1236 SetScrollInfo32( hwnd
, nBar
, &info
, bRedraw
);
1241 /*************************************************************************
1242 * GetScrollPos16 (USER.63)
1244 INT16 WINAPI
GetScrollPos16( HWND16 hwnd
, INT16 nBar
)
1246 return (INT16
)GetScrollPos32( hwnd
, nBar
);
1250 /*************************************************************************
1251 * GetScrollPos32 (USER32.285)
1254 * Success: Current position
1258 * Note the ambiguity when 0 is returned. Use GetLastError
1259 * to make sure there was an error (and to know which one).
1261 INT32 WINAPI
GetScrollPos32(
1262 HWND32 hwnd
, /* [I] Handle of window */
1263 INT32 nBar
/* [I] One of SB_HORZ, SB_VERT, or SB_CTL */)
1265 SCROLLBAR_INFO
*infoPtr
;
1267 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return 0;
1268 return infoPtr
->CurVal
;
1272 /*************************************************************************
1273 * SetScrollRange16 (USER.64)
1275 void WINAPI
SetScrollRange16( HWND16 hwnd
, INT16 nBar
,
1276 INT16 MinVal
, INT16 MaxVal
, BOOL16 bRedraw
)
1278 /* Invalid range -> range is set to (0,0) */
1279 if ((INT32
)MaxVal
- (INT32
)MinVal
> 0x7fff) MinVal
= MaxVal
= 0;
1280 SetScrollRange32( hwnd
, nBar
, MinVal
, MaxVal
, bRedraw
);
1284 /*************************************************************************
1285 * SetScrollRange32 (USER32.503)
1289 BOOL32 WINAPI
SetScrollRange32(
1290 HWND32 hwnd
, /* [I] Handle of window whose scrollbar will be affected */
1291 INT32 nBar
, /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */
1292 INT32 MinVal
, /* [I] New minimum value */
1293 INT32 MaxVal
, /* [I] New maximum value */
1294 BOOL32 bRedraw
/* [I] Should scrollbar be redrawn afterwards ? */)
1298 info
.cbSize
= sizeof(info
);
1301 info
.fMask
= SIF_RANGE
;
1302 SetScrollInfo32( hwnd
, nBar
, &info
, bRedraw
);
1307 /*************************************************************************
1308 * SCROLL_SetNCSbState
1310 * Updates both scrollbars at the same time. Used by MDI CalcChildScroll().
1312 INT32
SCROLL_SetNCSbState(WND
* wndPtr
, int vMin
, int vMax
, int vPos
,
1313 int hMin
, int hMax
, int hPos
)
1316 SCROLLINFO vInfo
, hInfo
;
1318 vInfo
.cbSize
= hInfo
.cbSize
= sizeof(SCROLLINFO
);
1319 vInfo
.nMin
= vMin
; hInfo
.nMin
= hMin
;
1320 vInfo
.nMax
= vMax
; hInfo
.nMax
= hMax
;
1321 vInfo
.nPos
= vPos
; hInfo
.nPos
= hPos
;
1322 vInfo
.fMask
= hInfo
.fMask
= SIF_RANGE
| SIF_POS
;
1324 SCROLL_SetScrollInfo( wndPtr
->hwndSelf
, SB_VERT
, &vInfo
, &vA
);
1325 SCROLL_SetScrollInfo( wndPtr
->hwndSelf
, SB_HORZ
, &hInfo
, &hA
);
1327 if( !SCROLL_ShowScrollBar( wndPtr
->hwndSelf
, SB_BOTH
,
1328 (hA
& SA_SSI_SHOW
),(vA
& SA_SSI_SHOW
) ) )
1330 /* SetWindowPos() wasn't called, just redraw the scrollbars if needed */
1331 if( vA
& SA_SSI_REFRESH
)
1332 SCROLL_RefreshScrollBar( wndPtr
->hwndSelf
, SB_VERT
, FALSE
, TRUE
);
1334 if( hA
& SA_SSI_REFRESH
)
1335 SCROLL_RefreshScrollBar( wndPtr
->hwndSelf
, SB_HORZ
, FALSE
, TRUE
);
1341 /*************************************************************************
1342 * GetScrollRange16 (USER.65)
1344 BOOL16 WINAPI
GetScrollRange16( HWND16 hwnd
, INT16 nBar
,
1345 LPINT16 lpMin
, LPINT16 lpMax
)
1348 BOOL16 ret
= GetScrollRange32( hwnd
, nBar
, &min
, &max
);
1349 if (lpMin
) *lpMin
= min
;
1350 if (lpMax
) *lpMax
= max
;
1355 /*************************************************************************
1356 * GetScrollRange32 (USER32.286)
1360 BOOL32 WINAPI
GetScrollRange32(
1361 HWND32 hwnd
, /* [I] Handle of window */
1362 INT32 nBar
, /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */
1363 LPINT32 lpMin
, /* [O] Where to store minimum value */
1364 LPINT32 lpMax
/* [O] Where to store maximum value */)
1366 SCROLLBAR_INFO
*infoPtr
;
1368 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
)))
1370 if (lpMin
) lpMin
= 0;
1371 if (lpMax
) lpMax
= 0;
1374 if (lpMin
) *lpMin
= infoPtr
->MinVal
;
1375 if (lpMax
) *lpMax
= infoPtr
->MaxVal
;
1380 /*************************************************************************
1381 * SCROLL_ShowScrollBar()
1383 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1384 * NOTE: fShowV/fShowH must be zero when nBar is SB_HORZ/SB_VERT.
1386 BOOL32
SCROLL_ShowScrollBar( HWND32 hwnd
, INT32 nBar
,
1387 BOOL32 fShowH
, BOOL32 fShowV
)
1389 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
1391 if (!wndPtr
) return FALSE
;
1392 TRACE(scroll
, "hwnd=%04x bar=%d horz=%d, vert=%d\n",
1393 hwnd
, nBar
, fShowH
, fShowV
);
1398 ShowWindow32( hwnd
, fShowH
? SW_SHOW
: SW_HIDE
);
1405 fShowH
= !(wndPtr
->dwStyle
& WS_HSCROLL
);
1406 wndPtr
->dwStyle
|= WS_HSCROLL
;
1410 fShowH
= (wndPtr
->dwStyle
& WS_HSCROLL
);
1411 wndPtr
->dwStyle
&= ~WS_HSCROLL
;
1413 if( nBar
== SB_HORZ
) break;
1419 fShowV
= !(wndPtr
->dwStyle
& WS_VSCROLL
);
1420 wndPtr
->dwStyle
|= WS_VSCROLL
;
1424 fShowV
= (wndPtr
->dwStyle
& WS_VSCROLL
);
1425 wndPtr
->dwStyle
&= ~WS_VSCROLL
;
1430 return FALSE
; /* Nothing to do! */
1433 if( fShowH
|| fShowV
) /* frame has been changed, let the window redraw itself */
1435 SetWindowPos32( hwnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
1436 | SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
1440 return FALSE
; /* no frame changes */
1444 /*************************************************************************
1445 * ShowScrollBar16 (USER.267)
1447 void WINAPI
ShowScrollBar16( HWND16 hwnd
, INT16 nBar
, BOOL16 fShow
)
1449 SCROLL_ShowScrollBar( hwnd
, nBar
, (nBar
== SB_VERT
) ? 0 : fShow
,
1450 (nBar
== SB_HORZ
) ? 0 : fShow
);
1454 /*************************************************************************
1455 * ShowScrollBar32 (USER32.532)
1459 BOOL32 WINAPI
ShowScrollBar32(
1460 HWND32 hwnd
, /* [I] Handle of window whose scrollbar(s) will be affected */
1461 INT32 nBar
, /* [I] One of SB_HORZ, SB_VERT, SB_BOTH or SB_CTL */
1462 BOOL32 fShow
/* [I] TRUE = show, FALSE = hide */)
1464 SCROLL_ShowScrollBar( hwnd
, nBar
, (nBar
== SB_VERT
) ? 0 : fShow
,
1465 (nBar
== SB_HORZ
) ? 0 : fShow
);
1470 /*************************************************************************
1471 * EnableScrollBar16 (USER.482)
1473 BOOL16 WINAPI
EnableScrollBar16( HWND16 hwnd
, INT16 nBar
, UINT16 flags
)
1475 return EnableScrollBar32( hwnd
, nBar
, flags
);
1479 /*************************************************************************
1480 * EnableScrollBar32 (USER32.171)
1482 BOOL32 WINAPI
EnableScrollBar32( HWND32 hwnd
, INT32 nBar
, UINT32 flags
)
1485 SCROLLBAR_INFO
*infoPtr
;
1487 TRACE(scroll
, "%04x %d %d\n", hwnd
, nBar
, flags
);
1489 flags
&= ESB_DISABLE_BOTH
;
1491 if (nBar
== SB_BOTH
)
1493 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, SB_VERT
))) return FALSE
;
1494 if (!(bFineWithMe
= (infoPtr
->flags
== flags
)) )
1496 infoPtr
->flags
= flags
;
1497 SCROLL_RefreshScrollBar( hwnd
, SB_VERT
, TRUE
, TRUE
);
1504 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return FALSE
;
1505 if (bFineWithMe
&& infoPtr
->flags
== flags
) return FALSE
;
1506 infoPtr
->flags
= flags
;
1508 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, TRUE
);