4 * Copyright 1993 Martin Ayotte
5 * Copyright 1994, 1996 Alexandre Julliard
10 #include "wine/winuser16.h"
14 #include "debugtools.h"
18 DEFAULT_DEBUG_CHANNEL(scroll
)
21 static HBITMAP hUpArrow
= 0;
22 static HBITMAP hDnArrow
= 0;
23 static HBITMAP hLfArrow
= 0;
24 static HBITMAP hRgArrow
= 0;
25 static HBITMAP hUpArrowD
= 0;
26 static HBITMAP hDnArrowD
= 0;
27 static HBITMAP hLfArrowD
= 0;
28 static HBITMAP hRgArrowD
= 0;
29 static HBITMAP hUpArrowI
= 0;
30 static HBITMAP hDnArrowI
= 0;
31 static HBITMAP hLfArrowI
= 0;
32 static HBITMAP hRgArrowI
= 0;
34 #define TOP_ARROW(flags,pressed) \
35 (((flags)&ESB_DISABLE_UP) ? hUpArrowI : ((pressed) ? hUpArrowD:hUpArrow))
36 #define BOTTOM_ARROW(flags,pressed) \
37 (((flags)&ESB_DISABLE_DOWN) ? hDnArrowI : ((pressed) ? hDnArrowD:hDnArrow))
38 #define LEFT_ARROW(flags,pressed) \
39 (((flags)&ESB_DISABLE_LEFT) ? hLfArrowI : ((pressed) ? hLfArrowD:hLfArrow))
40 #define RIGHT_ARROW(flags,pressed) \
41 (((flags)&ESB_DISABLE_RIGHT) ? hRgArrowI : ((pressed) ? hRgArrowD:hRgArrow))
44 /* Minimum size of the rectangle between the arrows */
45 #define SCROLL_MIN_RECT 4
47 /* Minimum size of the thumb in pixels */
48 #define SCROLL_MIN_THUMB 6
50 /* Overlap between arrows and thumb */
51 #define SCROLL_ARROW_THUMB_OVERLAP ((TWEAK_WineLook == WIN31_LOOK) ? 1 : 0)
53 /* Delay (in ms) before first repetition when holding the button down */
54 #define SCROLL_FIRST_DELAY 200
56 /* Delay (in ms) between scroll repetitions */
57 #define SCROLL_REPEAT_DELAY 50
60 #define SCROLL_TIMER 0
62 /* Scroll-bar hit testing */
65 SCROLL_NOWHERE
, /* Outside the scroll bar */
66 SCROLL_TOP_ARROW
, /* Top or left arrow */
67 SCROLL_TOP_RECT
, /* Rectangle between the top arrow and the thumb */
68 SCROLL_THUMB
, /* Thumb rectangle */
69 SCROLL_BOTTOM_RECT
, /* Rectangle between the thumb and the bottom arrow */
70 SCROLL_BOTTOM_ARROW
/* Bottom or right arrow */
73 /* What to do after SCROLL_SetScrollInfo() */
74 #define SA_SSI_HIDE 0x0001
75 #define SA_SSI_SHOW 0x0002
76 #define SA_SSI_REFRESH 0x0004
77 #define SA_SSI_REPAINT_ARROWS 0x0008
79 /* Thumb-tracking info */
80 static HWND SCROLL_TrackingWin
= 0;
81 static INT SCROLL_TrackingBar
= 0;
82 static INT SCROLL_TrackingPos
= 0;
83 static INT SCROLL_TrackingVal
= 0;
84 /* Hit test code of the last button-down event */
85 static enum SCROLL_HITTEST SCROLL_trackHitTest
;
86 static BOOL SCROLL_trackVertical
;
88 /* Is the moving thumb being displayed? */
89 static BOOL SCROLL_MovingThumb
= FALSE
;
92 static BOOL
SCROLL_ShowScrollBar( HWND hwnd
, INT nBar
,
93 BOOL fShowH
, BOOL fShowV
);
94 static INT
SCROLL_SetScrollInfo( HWND hwnd
, INT nBar
,
95 const SCROLLINFO
*info
, INT
*action
);
96 static void SCROLL_DrawInterior_9x( HWND hwnd
, HDC hdc
, INT nBar
,
97 RECT
*rect
, INT arrowSize
,
98 INT thumbSize
, INT thumbPos
,
99 UINT flags
, BOOL vertical
,
100 BOOL top_selected
, BOOL bottom_selected
);
103 /***********************************************************************
106 static void SCROLL_LoadBitmaps(void)
108 hUpArrow
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROW
) );
109 hDnArrow
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROW
) );
110 hLfArrow
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROW
) );
111 hRgArrow
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROW
) );
112 hUpArrowD
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROWD
) );
113 hDnArrowD
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROWD
) );
114 hLfArrowD
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROWD
) );
115 hRgArrowD
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROWD
) );
116 hUpArrowI
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROWI
) );
117 hDnArrowI
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROWI
) );
118 hLfArrowI
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROWI
) );
119 hRgArrowI
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROWI
) );
123 /***********************************************************************
124 * SCROLL_GetPtrScrollInfo
126 static SCROLLBAR_INFO
*SCROLL_GetPtrScrollInfo( WND
* wndPtr
, INT nBar
)
128 SCROLLBAR_INFO
*infoPtr
;
130 if (!wndPtr
) return NULL
;
133 case SB_HORZ
: infoPtr
= (SCROLLBAR_INFO
*)wndPtr
->pHScroll
; break;
134 case SB_VERT
: infoPtr
= (SCROLLBAR_INFO
*)wndPtr
->pVScroll
; break;
135 case SB_CTL
: infoPtr
= (SCROLLBAR_INFO
*)wndPtr
->wExtra
; break;
136 default: return NULL
;
139 if (!infoPtr
) /* Create the info structure if needed */
141 if ((infoPtr
= HeapAlloc( SystemHeap
, 0, sizeof(SCROLLBAR_INFO
) )))
143 infoPtr
->MinVal
= infoPtr
->CurVal
= infoPtr
->Page
= 0;
144 infoPtr
->MaxVal
= 100;
145 infoPtr
->flags
= ESB_ENABLE_BOTH
;
146 if (nBar
== SB_HORZ
) wndPtr
->pHScroll
= infoPtr
;
147 else wndPtr
->pVScroll
= infoPtr
;
149 if (!hUpArrow
) SCROLL_LoadBitmaps();
155 /***********************************************************************
156 * SCROLL_GetScrollInfo
158 static SCROLLBAR_INFO
*SCROLL_GetScrollInfo( HWND hwnd
, INT nBar
)
160 SCROLLBAR_INFO
*retvalue
;
161 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
162 retvalue
= SCROLL_GetPtrScrollInfo( wndPtr
, nBar
);
163 WIN_ReleaseWndPtr(wndPtr
);
168 /***********************************************************************
169 * SCROLL_GetScrollBarRect
171 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
172 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
173 * 'arrowSize' returns the width or height of an arrow (depending on
174 * the orientation of the scrollbar), 'thumbSize' returns the size of
175 * the thumb, and 'thumbPos' returns the position of the thumb
176 * relative to the left or to the top.
177 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
179 static BOOL
SCROLL_GetScrollBarRect( HWND hwnd
, INT nBar
, RECT
*lprect
,
180 INT
*arrowSize
, INT
*thumbSize
,
185 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
190 lprect
->left
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
191 lprect
->top
= wndPtr
->rectClient
.bottom
- wndPtr
->rectWindow
.top
;
192 lprect
->right
= wndPtr
->rectClient
.right
- wndPtr
->rectWindow
.left
;
193 lprect
->bottom
= lprect
->top
+ GetSystemMetrics(SM_CYHSCROLL
);
194 if(wndPtr
->dwStyle
& WS_BORDER
) {
197 } else if(wndPtr
->dwStyle
& WS_VSCROLL
)
203 lprect
->left
= wndPtr
->rectClient
.right
- wndPtr
->rectWindow
.left
;
204 lprect
->top
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
205 lprect
->right
= lprect
->left
+ GetSystemMetrics(SM_CXVSCROLL
);
206 lprect
->bottom
= wndPtr
->rectClient
.bottom
- wndPtr
->rectWindow
.top
;
207 if(wndPtr
->dwStyle
& WS_BORDER
) {
210 } else if(wndPtr
->dwStyle
& WS_HSCROLL
)
216 GetClientRect( hwnd
, lprect
);
217 vertical
= ((wndPtr
->dwStyle
& SBS_VERT
) != 0);
221 WIN_ReleaseWndPtr(wndPtr
);
225 if (vertical
) pixels
= lprect
->bottom
- lprect
->top
;
226 else pixels
= lprect
->right
- lprect
->left
;
228 if (pixels
<= 2*GetSystemMetrics(SM_CXVSCROLL
) + SCROLL_MIN_RECT
)
230 if (pixels
> SCROLL_MIN_RECT
)
231 *arrowSize
= (pixels
- SCROLL_MIN_RECT
) / 2;
234 *thumbPos
= *thumbSize
= 0;
238 SCROLLBAR_INFO
*info
= SCROLL_GetPtrScrollInfo( wndPtr
, nBar
);
240 *arrowSize
= GetSystemMetrics(SM_CXVSCROLL
);
241 pixels
-= (2 * (GetSystemMetrics(SM_CXVSCROLL
) - SCROLL_ARROW_THUMB_OVERLAP
));
245 *thumbSize
= pixels
* info
->Page
/ (info
->MaxVal
-info
->MinVal
+1);
246 if (*thumbSize
< SCROLL_MIN_THUMB
) *thumbSize
= SCROLL_MIN_THUMB
;
248 else *thumbSize
= GetSystemMetrics(SM_CXVSCROLL
);
250 if (((pixels
-= *thumbSize
) < 0) ||
251 ((info
->flags
& ESB_DISABLE_BOTH
) == ESB_DISABLE_BOTH
))
253 /* Rectangle too small or scrollbar disabled -> no thumb */
254 *thumbPos
= *thumbSize
= 0;
258 INT max
= info
->MaxVal
- MAX( info
->Page
-1, 0 );
259 if (info
->MinVal
>= max
)
260 *thumbPos
= *arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
262 *thumbPos
= *arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
263 + pixels
* (info
->CurVal
-info
->MinVal
) / (max
- info
->MinVal
);
266 WIN_ReleaseWndPtr(wndPtr
);
271 /***********************************************************************
274 * Compute the current scroll position based on the thumb position in pixels
275 * from the top of the scroll-bar.
277 static UINT
SCROLL_GetThumbVal( SCROLLBAR_INFO
*infoPtr
, RECT
*rect
,
278 BOOL vertical
, INT pos
)
281 INT pixels
= vertical
? rect
->bottom
-rect
->top
: rect
->right
-rect
->left
;
283 if ((pixels
-= 2*(GetSystemMetrics(SM_CXVSCROLL
) - SCROLL_ARROW_THUMB_OVERLAP
)) <= 0)
284 return infoPtr
->MinVal
;
288 thumbSize
= pixels
* infoPtr
->Page
/(infoPtr
->MaxVal
-infoPtr
->MinVal
+1);
289 if (thumbSize
< SCROLL_MIN_THUMB
) thumbSize
= SCROLL_MIN_THUMB
;
291 else thumbSize
= GetSystemMetrics(SM_CXVSCROLL
);
293 if ((pixels
-= thumbSize
) <= 0) return infoPtr
->MinVal
;
295 pos
= MAX( 0, pos
- (GetSystemMetrics(SM_CXVSCROLL
) - SCROLL_ARROW_THUMB_OVERLAP
) );
296 if (pos
> pixels
) pos
= pixels
;
298 if (!infoPtr
->Page
) pos
*= infoPtr
->MaxVal
- infoPtr
->MinVal
;
299 else pos
*= infoPtr
->MaxVal
- infoPtr
->MinVal
- infoPtr
->Page
+ 1;
300 return infoPtr
->MinVal
+ ((pos
+ pixels
/ 2) / pixels
);
303 /***********************************************************************
306 static BOOL
SCROLL_PtInRectEx( LPRECT lpRect
, POINT pt
, BOOL vertical
)
312 rect
.left
-= lpRect
->right
- lpRect
->left
;
313 rect
.right
+= lpRect
->right
- lpRect
->left
;
317 rect
.top
-= lpRect
->bottom
- lpRect
->top
;
318 rect
.bottom
+= lpRect
->bottom
- lpRect
->top
;
320 return PtInRect( &rect
, pt
);
323 /***********************************************************************
326 static POINT
SCROLL_ClipPos( LPRECT lpRect
, POINT pt
)
328 if( pt
.x
< lpRect
->left
)
331 if( pt
.x
> lpRect
->right
)
332 pt
.x
= lpRect
->right
;
334 if( pt
.y
< lpRect
->top
)
337 if( pt
.y
> lpRect
->bottom
)
338 pt
.y
= lpRect
->bottom
;
344 /***********************************************************************
347 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
349 static enum SCROLL_HITTEST
SCROLL_HitTest( HWND hwnd
, INT nBar
,
350 POINT pt
, BOOL bDragging
)
352 INT arrowSize
, thumbSize
, thumbPos
;
355 BOOL vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
356 &arrowSize
, &thumbSize
, &thumbPos
);
358 if ( (bDragging
&& !SCROLL_PtInRectEx( &rect
, pt
, vertical
)) ||
359 (!PtInRect( &rect
, pt
)) ) return SCROLL_NOWHERE
;
363 if (pt
.y
< rect
.top
+ arrowSize
) return SCROLL_TOP_ARROW
;
364 if (pt
.y
>= rect
.bottom
- arrowSize
) return SCROLL_BOTTOM_ARROW
;
365 if (!thumbPos
) return SCROLL_TOP_RECT
;
367 if (pt
.y
< thumbPos
) return SCROLL_TOP_RECT
;
368 if (pt
.y
>= thumbPos
+ thumbSize
) return SCROLL_BOTTOM_RECT
;
370 else /* horizontal */
372 if (pt
.x
< rect
.left
+ arrowSize
) return SCROLL_TOP_ARROW
;
373 if (pt
.x
>= rect
.right
- arrowSize
) return SCROLL_BOTTOM_ARROW
;
374 if (!thumbPos
) return SCROLL_TOP_RECT
;
376 if (pt
.x
< thumbPos
) return SCROLL_TOP_RECT
;
377 if (pt
.x
>= thumbPos
+ thumbSize
) return SCROLL_BOTTOM_RECT
;
383 /***********************************************************************
386 * Draw the scroll bar arrows.
388 static void SCROLL_DrawArrows_9x( HDC hdc
, SCROLLBAR_INFO
*infoPtr
,
389 RECT
*rect
, INT arrowSize
, BOOL vertical
,
390 BOOL top_pressed
, BOOL bottom_pressed
)
396 r
.bottom
= r
.top
+ arrowSize
;
398 r
.right
= r
.left
+ arrowSize
;
400 DrawFrameControl( hdc
, &r
, DFC_SCROLL
,
401 (vertical
? DFCS_SCROLLUP
: DFCS_SCROLLLEFT
)
402 | (top_pressed
? (DFCS_PUSHED
| DFCS_FLAT
) : 0 )
403 | (infoPtr
->flags
&ESB_DISABLE_LTUP
? DFCS_INACTIVE
: 0 ) );
407 r
.top
= r
.bottom
-arrowSize
;
409 r
.left
= r
.right
-arrowSize
;
411 DrawFrameControl( hdc
, &r
, DFC_SCROLL
,
412 (vertical
? DFCS_SCROLLDOWN
: DFCS_SCROLLRIGHT
)
413 | (bottom_pressed
? (DFCS_PUSHED
| DFCS_FLAT
) : 0 )
414 | (infoPtr
->flags
&ESB_DISABLE_RTDN
? DFCS_INACTIVE
: 0) );
417 static void SCROLL_DrawArrows_31( HDC hdc
, SCROLLBAR_INFO
*infoPtr
,
418 RECT
*rect
, INT arrowSize
, BOOL vertical
,
419 BOOL top_pressed
, BOOL bottom_pressed
)
421 HDC hdcMem
= CreateCompatibleDC( hdc
);
422 HBITMAP hbmpPrev
= SelectObject( hdcMem
, vertical
?
423 TOP_ARROW(infoPtr
->flags
, top_pressed
)
424 : LEFT_ARROW(infoPtr
->flags
, top_pressed
));
426 SetStretchBltMode( hdc
, STRETCH_DELETESCANS
);
427 StretchBlt( hdc
, rect
->left
, rect
->top
,
428 vertical
? rect
->right
-rect
->left
: arrowSize
,
429 vertical
? arrowSize
: rect
->bottom
-rect
->top
,
431 GetSystemMetrics(SM_CXVSCROLL
),GetSystemMetrics(SM_CYHSCROLL
),
434 SelectObject( hdcMem
, vertical
?
435 BOTTOM_ARROW( infoPtr
->flags
, bottom_pressed
)
436 : RIGHT_ARROW( infoPtr
->flags
, bottom_pressed
) );
438 StretchBlt( hdc
, rect
->left
, rect
->bottom
- arrowSize
,
439 rect
->right
- rect
->left
, arrowSize
,
441 GetSystemMetrics(SM_CXVSCROLL
),GetSystemMetrics(SM_CYHSCROLL
),
444 StretchBlt( hdc
, rect
->right
- arrowSize
, rect
->top
,
445 arrowSize
, rect
->bottom
- rect
->top
,
447 GetSystemMetrics(SM_CXVSCROLL
), GetSystemMetrics(SM_CYHSCROLL
),
449 SelectObject( hdcMem
, hbmpPrev
);
453 static void SCROLL_DrawArrows( HDC hdc
, SCROLLBAR_INFO
*infoPtr
,
454 RECT
*rect
, INT arrowSize
, BOOL vertical
,
455 BOOL top_pressed
, BOOL bottom_pressed
)
457 if( TWEAK_WineLook
== WIN31_LOOK
)
458 SCROLL_DrawArrows_31( hdc
, infoPtr
, rect
, arrowSize
,
459 vertical
, top_pressed
,bottom_pressed
);
461 SCROLL_DrawArrows_9x( hdc
, infoPtr
, rect
, arrowSize
,
462 vertical
, top_pressed
,bottom_pressed
);
466 /***********************************************************************
467 * SCROLL_DrawMovingThumb
469 * Draw the moving thumb rectangle.
471 static void SCROLL_DrawMovingThumb_31( HDC hdc
, RECT
*rect
, BOOL vertical
,
472 INT arrowSize
, INT thumbSize
)
477 r
.top
+= SCROLL_TrackingPos
;
478 if (r
.top
< rect
->top
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
479 r
.top
= rect
->top
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
480 if (r
.top
+ thumbSize
>
481 rect
->bottom
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
))
482 r
.top
= rect
->bottom
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
484 r
.bottom
= r
.top
+ thumbSize
;
488 r
.left
+= SCROLL_TrackingPos
;
489 if (r
.left
< rect
->left
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
490 r
.left
= rect
->left
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
491 if (r
.left
+ thumbSize
>
492 rect
->right
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
))
493 r
.left
= rect
->right
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
495 r
.right
= r
.left
+ thumbSize
;
498 DrawFocusRect( hdc
, &r
);
499 SCROLL_MovingThumb
= !SCROLL_MovingThumb
;
502 static void SCROLL_DrawMovingThumb_9x( HDC hdc
, RECT
*rect
, BOOL vertical
,
503 INT arrowSize
, INT thumbSize
)
505 INT pos
= SCROLL_TrackingPos
;
509 max_size
= rect
->bottom
- rect
->top
;
511 max_size
= rect
->right
- rect
->left
;
513 max_size
-= (arrowSize
-SCROLL_ARROW_THUMB_OVERLAP
) + thumbSize
;
515 if( pos
< (arrowSize
-SCROLL_ARROW_THUMB_OVERLAP
) )
516 pos
= (arrowSize
-SCROLL_ARROW_THUMB_OVERLAP
);
517 else if( pos
> max_size
)
520 SCROLL_DrawInterior_9x( SCROLL_TrackingWin
, hdc
, SCROLL_TrackingBar
,
521 rect
, arrowSize
, thumbSize
, pos
,
522 0, vertical
, FALSE
, FALSE
);
524 SCROLL_MovingThumb
= !SCROLL_MovingThumb
;
527 static void SCROLL_DrawMovingThumb( HDC hdc
, RECT
*rect
, BOOL vertical
,
528 INT arrowSize
, INT thumbSize
)
530 if( TWEAK_WineLook
== WIN31_LOOK
)
531 SCROLL_DrawMovingThumb_31( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
533 SCROLL_DrawMovingThumb_9x( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
536 /***********************************************************************
537 * SCROLL_DrawInterior
539 * Draw the scroll bar interior (everything except the arrows).
541 static void SCROLL_DrawInterior_9x( HWND hwnd
, HDC hdc
, INT nBar
,
542 RECT
*rect
, INT arrowSize
,
543 INT thumbSize
, INT thumbPos
,
544 UINT flags
, BOOL vertical
,
545 BOOL top_selected
, BOOL bottom_selected
)
549 HBRUSH hSaveBrush
,hBrush
;
551 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
552 * The window-owned scrollbars need to call DEFWND_ControlColor
553 * to correctly setup default scrollbar colors
557 hBrush
= (HBRUSH
)SendMessageA( GetParent(hwnd
), WM_CTLCOLORSCROLLBAR
,
558 (WPARAM
)hdc
,(LPARAM
)hwnd
);
562 hBrush
= DEFWND_ControlColor( hdc
, CTLCOLOR_SCROLLBAR
);
565 hSavePen
= SelectObject( hdc
, GetSysColorPen(COLOR_WINDOWFRAME
) );
566 hSaveBrush
= SelectObject( hdc
, hBrush
);
568 /* Calculate the scroll rectangle */
572 r
.top
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
573 r
.bottom
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
577 r
.left
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
578 r
.right
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
581 /* Draw the scroll rectangles and thumb */
582 if (!thumbPos
) /* No thumb to draw */
584 PatBlt( hdc
, r
.left
, r
.top
,
585 r
.right
- r
.left
, r
.bottom
- r
.top
,
588 /* cleanup and return */
589 SelectObject( hdc
, hSavePen
);
590 SelectObject( hdc
, hSaveBrush
);
596 PatBlt( hdc
, r
.left
, r
.top
,
598 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
),
599 top_selected
? 0x0f0000 : PATCOPY
);
600 r
.top
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
601 PatBlt( hdc
, r
.left
, r
.top
+ thumbSize
,
603 r
.bottom
- r
.top
- thumbSize
,
604 bottom_selected
? 0x0f0000 : PATCOPY
);
605 r
.bottom
= r
.top
+ thumbSize
;
607 else /* horizontal */
609 PatBlt( hdc
, r
.left
, r
.top
,
610 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
),
612 top_selected
? 0x0f0000 : PATCOPY
);
613 r
.left
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
614 PatBlt( hdc
, r
.left
+ thumbSize
, r
.top
,
615 r
.right
- r
.left
- thumbSize
,
617 bottom_selected
? 0x0f0000 : PATCOPY
);
618 r
.right
= r
.left
+ thumbSize
;
622 DrawEdge( hdc
, &r
, EDGE_RAISED
, BF_RECT
| BF_MIDDLE
);
625 SelectObject( hdc
, hSavePen
);
626 SelectObject( hdc
, hSaveBrush
);
630 static void SCROLL_DrawInterior( HWND hwnd
, HDC hdc
, INT nBar
,
631 RECT
*rect
, INT arrowSize
,
632 INT thumbSize
, INT thumbPos
,
633 UINT flags
, BOOL vertical
,
634 BOOL top_selected
, BOOL bottom_selected
)
638 HBRUSH hSaveBrush
,hBrush
;
639 BOOL Save_SCROLL_MovingThumb
= SCROLL_MovingThumb
;
641 if (Save_SCROLL_MovingThumb
&&
642 (SCROLL_TrackingWin
== hwnd
) &&
643 (SCROLL_TrackingBar
== nBar
))
644 SCROLL_DrawMovingThumb( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
646 /* Select the correct brush and pen */
648 if (TWEAK_WineLook
== WIN31_LOOK
&& (flags
& ESB_DISABLE_BOTH
) == ESB_DISABLE_BOTH
)
650 /* This ought to be the color of the parent window */
651 if (TWEAK_WineLook
== WIN31_LOOK
) {
652 hBrush
= GetSysColorBrush(COLOR_WINDOW
);
654 /* Under Win9x look & feel, scrollbars don't have a solid border.
655 * To make scrollbar's background different from the window
656 * background, we need to apply a gray 0x55aa pattern brush.
657 * Otherwise it won't look good.
659 hBrush
= CACHE_GetPattern55AABrush();
664 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
665 * The window-owned scrollbars need to call DEFWND_ControlColor
666 * to correctly setup default scrollbar colors
668 if (nBar
== SB_CTL
) {
669 hBrush
= (HBRUSH
)SendMessageA( GetParent(hwnd
), WM_CTLCOLORSCROLLBAR
,
670 (WPARAM
)hdc
,(LPARAM
)hwnd
);
672 hBrush
= DEFWND_ControlColor( hdc
, CTLCOLOR_SCROLLBAR
);
675 hSavePen
= SelectObject( hdc
, GetSysColorPen(COLOR_WINDOWFRAME
) );
676 hSaveBrush
= SelectObject( hdc
, hBrush
);
678 /* Calculate the scroll rectangle */
683 r
.top
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
684 r
.bottom
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
688 r
.left
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
689 r
.right
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
692 /* Draw the scroll bar frame */
694 /* Only draw outline if Win 3.1. Mar 24, 1999 - Ronald B. Cemer */
695 if (TWEAK_WineLook
== WIN31_LOOK
)
696 Rectangle( hdc
, r
.left
, r
.top
, r
.right
, r
.bottom
);
698 /* Draw the scroll rectangles and thumb */
700 if (!thumbPos
) /* No thumb to draw */
702 INT offset
= (TWEAK_WineLook
> WIN31_LOOK
) ? 0 : 1;
704 PatBlt( hdc
, r
.left
+offset
, r
.top
+offset
,
705 r
.right
- r
.left
- 2*offset
, r
.bottom
- r
.top
- 2*offset
,
708 /* cleanup and return */
709 SelectObject( hdc
, hSavePen
);
710 SelectObject( hdc
, hSaveBrush
);
716 INT offset
= (TWEAK_WineLook
== WIN31_LOOK
) ? 1 : 0;
718 PatBlt( hdc
, r
.left
+ offset
, r
.top
+ offset
,
719 r
.right
- r
.left
- offset
*2,
720 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
) - offset
,
721 top_selected
? 0x0f0000 : PATCOPY
);
722 r
.top
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
723 PatBlt( hdc
, r
.left
+ offset
, r
.top
+ thumbSize
,
724 r
.right
- r
.left
- offset
*2,
725 r
.bottom
- r
.top
- thumbSize
- offset
,
726 bottom_selected
? 0x0f0000 : PATCOPY
);
727 r
.bottom
= r
.top
+ thumbSize
;
729 else /* horizontal */
731 INT offset
= (TWEAK_WineLook
== WIN31_LOOK
) ? 1 : 0;
733 PatBlt( hdc
, r
.left
+ offset
, r
.top
+ offset
,
734 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
),
735 r
.bottom
- r
.top
- offset
*2,
736 top_selected
? 0x0f0000 : PATCOPY
);
737 r
.left
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
738 PatBlt( hdc
, r
.left
+ thumbSize
, r
.top
+ offset
,
739 r
.right
- r
.left
- thumbSize
- offset
,
740 r
.bottom
- r
.top
- offset
*2,
741 bottom_selected
? 0x0f0000 : PATCOPY
);
742 r
.right
= r
.left
+ thumbSize
;
747 SelectObject( hdc
, GetSysColorBrush(COLOR_BTNFACE
) );
748 if (TWEAK_WineLook
== WIN31_LOOK
)
750 Rectangle( hdc
, r
.left
, r
.top
, r
.right
, r
.bottom
);
755 Rectangle( hdc
, r
.left
+1, r
.top
+1, r
.right
-1, r
.bottom
-1 );
757 DrawEdge( hdc
, &r
, EDGE_RAISED
, BF_RECT
);
759 if (Save_SCROLL_MovingThumb
&&
760 (SCROLL_TrackingWin
== hwnd
) &&
761 (SCROLL_TrackingBar
== nBar
))
762 SCROLL_DrawMovingThumb( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
765 SelectObject( hdc
, hSavePen
);
766 SelectObject( hdc
, hSaveBrush
);
770 /***********************************************************************
771 * SCROLL_DrawScrollBar
773 * Redraw the whole scrollbar.
775 void SCROLL_DrawScrollBar( HWND hwnd
, HDC hdc
, INT nBar
,
776 BOOL arrows
, BOOL interior
)
778 INT arrowSize
, thumbSize
, thumbPos
;
781 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
782 SCROLLBAR_INFO
*infoPtr
= SCROLL_GetPtrScrollInfo( wndPtr
, nBar
);
783 BOOL Save_SCROLL_MovingThumb
= SCROLL_MovingThumb
;
785 if (!wndPtr
|| !infoPtr
||
786 ((nBar
== SB_VERT
) && !(wndPtr
->dwStyle
& WS_VSCROLL
)) ||
787 ((nBar
== SB_HORZ
) && !(wndPtr
->dwStyle
& WS_HSCROLL
))) goto END
;
788 if (!WIN_IsWindowDrawable( wndPtr
, FALSE
)) goto END
;
790 vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
791 &arrowSize
, &thumbSize
, &thumbPos
);
793 if (Save_SCROLL_MovingThumb
&&
794 (SCROLL_TrackingWin
== hwnd
) &&
795 (SCROLL_TrackingBar
== nBar
))
796 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
798 /* Draw the arrows */
800 if (arrows
&& arrowSize
)
802 if( vertical
== SCROLL_trackVertical
&& GetCapture() == hwnd
)
803 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
804 (SCROLL_trackHitTest
== SCROLL_TOP_ARROW
),
805 (SCROLL_trackHitTest
== SCROLL_BOTTOM_ARROW
) );
807 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
811 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
812 thumbPos
, infoPtr
->flags
, vertical
, FALSE
, FALSE
);
814 if (Save_SCROLL_MovingThumb
&&
815 (SCROLL_TrackingWin
== hwnd
) &&
816 (SCROLL_TrackingBar
== nBar
))
817 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
820 WIN_ReleaseWndPtr(wndPtr
);
824 /***********************************************************************
825 * SCROLL_RefreshScrollBar
827 * Repaint the scroll bar interior after a SetScrollRange() or
828 * SetScrollPos() call.
830 static void SCROLL_RefreshScrollBar( HWND hwnd
, INT nBar
,
831 BOOL arrows
, BOOL interior
)
833 HDC hdc
= GetDCEx( hwnd
, 0,
834 DCX_CACHE
| ((nBar
== SB_CTL
) ? 0 : DCX_WINDOW
) );
837 SCROLL_DrawScrollBar( hwnd
, hdc
, nBar
, arrows
, interior
);
838 ReleaseDC( hwnd
, hdc
);
842 /***********************************************************************
843 * SCROLL_HandleKbdEvent
845 * Handle a keyboard event (only for SB_CTL scrollbars).
847 static void SCROLL_HandleKbdEvent( HWND hwnd
, WPARAM wParam
)
849 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
854 case VK_PRIOR
: msg
= SB_PAGEUP
; break;
855 case VK_NEXT
: msg
= SB_PAGEDOWN
; break;
856 case VK_HOME
: msg
= SB_TOP
; break;
857 case VK_END
: msg
= SB_BOTTOM
; break;
858 case VK_UP
: msg
= SB_LINEUP
; break;
859 case VK_DOWN
: msg
= SB_LINEDOWN
; break;
861 WIN_ReleaseWndPtr(wndPtr
);
864 SendMessageA( GetParent(hwnd
),
865 (wndPtr
->dwStyle
& SBS_VERT
) ? WM_VSCROLL
: WM_HSCROLL
,
867 WIN_ReleaseWndPtr(wndPtr
);
871 /***********************************************************************
872 * SCROLL_HandleScrollEvent
874 * Handle a mouse or timer event for the scrollbar.
875 * 'pt' is the location of the mouse event in client (for SB_CTL) or
876 * windows coordinates.
878 void SCROLL_HandleScrollEvent( HWND hwnd
, INT nBar
, UINT msg
, POINT pt
)
880 /* Previous mouse position for timer events */
882 /* Thumb position when tracking started. */
883 static UINT trackThumbPos
;
884 /* Position in the scroll-bar of the last button-down event. */
885 static INT lastClickPos
;
886 /* Position in the scroll-bar of the last mouse event. */
887 static INT lastMousePos
;
889 enum SCROLL_HITTEST hittest
;
890 HWND hwndOwner
, hwndCtl
;
892 INT arrowSize
, thumbSize
, thumbPos
;
896 SCROLLBAR_INFO
*infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
);
897 if (!infoPtr
) return;
898 if ((SCROLL_trackHitTest
== SCROLL_NOWHERE
) && (msg
!= WM_LBUTTONDOWN
))
901 hdc
= GetDCEx( hwnd
, 0, DCX_CACHE
| ((nBar
== SB_CTL
) ? 0 : DCX_WINDOW
));
902 vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
903 &arrowSize
, &thumbSize
, &thumbPos
);
904 hwndOwner
= (nBar
== SB_CTL
) ? GetParent(hwnd
) : hwnd
;
905 hwndCtl
= (nBar
== SB_CTL
) ? hwnd
: 0;
909 case WM_LBUTTONDOWN
: /* Initialise mouse tracking */
910 SCROLL_trackVertical
= vertical
;
911 SCROLL_trackHitTest
= hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, FALSE
);
912 lastClickPos
= vertical
? (pt
.y
- rect
.top
) : (pt
.x
- rect
.left
);
913 lastMousePos
= lastClickPos
;
914 trackThumbPos
= thumbPos
;
917 if (nBar
== SB_CTL
) SetFocus( hwnd
);
921 hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, TRUE
);
926 hittest
= SCROLL_NOWHERE
;
932 hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, FALSE
);
936 return; /* Should never happen */
939 TRACE("Event: hwnd=%04x bar=%d msg=%x pt=%ld,%ld hit=%d\n",
940 hwnd
, nBar
, msg
, pt
.x
, pt
.y
, hittest
);
942 switch(SCROLL_trackHitTest
)
944 case SCROLL_NOWHERE
: /* No tracking in progress */
947 case SCROLL_TOP_ARROW
:
948 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
949 (hittest
== SCROLL_trackHitTest
), FALSE
);
950 if (hittest
== SCROLL_trackHitTest
)
952 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
954 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
955 SB_LINEUP
, hwndCtl
);
958 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
959 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
962 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
965 case SCROLL_TOP_RECT
:
966 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
967 thumbPos
, infoPtr
->flags
, vertical
,
968 (hittest
== SCROLL_trackHitTest
), FALSE
);
969 if (hittest
== SCROLL_trackHitTest
)
971 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
973 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
974 SB_PAGEUP
, hwndCtl
);
975 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
976 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
980 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
984 if (msg
== WM_LBUTTONDOWN
)
986 SCROLL_TrackingWin
= hwnd
;
987 SCROLL_TrackingBar
= nBar
;
988 SCROLL_TrackingPos
= trackThumbPos
+ lastMousePos
- lastClickPos
;
989 if (!SCROLL_MovingThumb
)
990 SCROLL_DrawMovingThumb(hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
992 else if (msg
== WM_LBUTTONUP
)
994 if (SCROLL_MovingThumb
)
995 SCROLL_DrawMovingThumb(hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
996 SCROLL_TrackingWin
= 0;
997 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
998 thumbPos
, infoPtr
->flags
, vertical
,
1001 else /* WM_MOUSEMOVE */
1005 if (!SCROLL_PtInRectEx( &rect
, pt
, vertical
)) pos
= lastClickPos
;
1008 pt
= SCROLL_ClipPos( &rect
, pt
);
1009 pos
= vertical
? (pt
.y
- rect
.top
) : (pt
.x
- rect
.left
);
1011 if ( (pos
!= lastMousePos
) || (!SCROLL_MovingThumb
) )
1013 if (SCROLL_MovingThumb
)
1014 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
,
1015 arrowSize
, thumbSize
);
1017 SCROLL_TrackingPos
= trackThumbPos
+ pos
- lastClickPos
;
1018 SCROLL_TrackingVal
= SCROLL_GetThumbVal( infoPtr
, &rect
,
1020 SCROLL_TrackingPos
);
1021 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1022 MAKEWPARAM( SB_THUMBTRACK
, SCROLL_TrackingVal
),
1024 if (!SCROLL_MovingThumb
)
1025 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
,
1026 arrowSize
, thumbSize
);
1031 case SCROLL_BOTTOM_RECT
:
1032 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
1033 thumbPos
, infoPtr
->flags
, vertical
,
1034 FALSE
, (hittest
== SCROLL_trackHitTest
) );
1035 if (hittest
== SCROLL_trackHitTest
)
1037 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
1039 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1040 SB_PAGEDOWN
, hwndCtl
);
1041 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
1042 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
1046 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
1049 case SCROLL_BOTTOM_ARROW
:
1050 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
1051 FALSE
, (hittest
== SCROLL_trackHitTest
) );
1052 if (hittest
== SCROLL_trackHitTest
)
1054 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
1056 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1057 SB_LINEDOWN
, hwndCtl
);
1060 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
1061 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
1064 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
1068 if (msg
== WM_LBUTTONUP
)
1070 hittest
= SCROLL_trackHitTest
;
1071 SCROLL_trackHitTest
= SCROLL_NOWHERE
; /* Terminate tracking */
1073 if (hittest
== SCROLL_THUMB
)
1075 UINT val
= SCROLL_GetThumbVal( infoPtr
, &rect
, vertical
,
1076 trackThumbPos
+ lastMousePos
- lastClickPos
);
1077 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1078 MAKEWPARAM( SB_THUMBPOSITION
, val
), hwndCtl
);
1081 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1082 SB_ENDSCROLL
, hwndCtl
);
1085 ReleaseDC( hwnd
, hdc
);
1089 /***********************************************************************
1092 LRESULT WINAPI
ScrollBarWndProc( HWND hwnd
, UINT message
, WPARAM wParam
,
1099 CREATESTRUCTA
*lpCreat
= (CREATESTRUCTA
*)lParam
;
1100 if (lpCreat
->style
& SBS_SIZEBOX
)
1102 FIXME("Unimplemented style SBS_SIZEBOX.\n" );
1106 if (lpCreat
->style
& SBS_VERT
)
1108 if (lpCreat
->style
& SBS_LEFTALIGN
)
1109 MoveWindow( hwnd
, lpCreat
->x
, lpCreat
->y
,
1110 GetSystemMetrics(SM_CXVSCROLL
)+1, lpCreat
->cy
, FALSE
);
1111 else if (lpCreat
->style
& SBS_RIGHTALIGN
)
1113 lpCreat
->x
+lpCreat
->cx
-GetSystemMetrics(SM_CXVSCROLL
)-1,
1115 GetSystemMetrics(SM_CXVSCROLL
)+1, lpCreat
->cy
, FALSE
);
1119 if (lpCreat
->style
& SBS_TOPALIGN
)
1120 MoveWindow( hwnd
, lpCreat
->x
, lpCreat
->y
,
1121 lpCreat
->cx
, GetSystemMetrics(SM_CYHSCROLL
)+1, FALSE
);
1122 else if (lpCreat
->style
& SBS_BOTTOMALIGN
)
1125 lpCreat
->y
+lpCreat
->cy
-GetSystemMetrics(SM_CYHSCROLL
)-1,
1126 lpCreat
->cx
, GetSystemMetrics(SM_CYHSCROLL
)+1, FALSE
);
1129 if (!hUpArrow
) SCROLL_LoadBitmaps();
1130 TRACE("ScrollBar creation, hwnd=%04x\n", hwnd
);
1133 case WM_LBUTTONDOWN
:
1139 CONV_POINT16TO32( (POINT16
*)&lParam
, &pt
);
1140 SCROLL_HandleScrollEvent( hwnd
, SB_CTL
, message
, pt
);
1145 SCROLL_HandleKbdEvent( hwnd
, wParam
);
1152 return DLGC_WANTARROWS
; /* Windows returns this value */
1157 HDC hdc
= BeginPaint( hwnd
, &ps
);
1158 SCROLL_DrawScrollBar( hwnd
, hdc
, SB_CTL
, TRUE
, TRUE
);
1159 EndPaint( hwnd
, &ps
);
1165 return SetScrollPos( hwnd
, SB_CTL
, wParam
, (BOOL
)lParam
);
1169 return GetScrollPos( hwnd
, SB_CTL
);
1171 case SBM_SETRANGE16
:
1172 SetScrollRange( hwnd
, SB_CTL
, LOWORD(lParam
), HIWORD(lParam
),
1173 wParam
/* FIXME: Is this correct? */ );
1177 SetScrollRange( hwnd
, SB_CTL
, wParam
, lParam
, FALSE
);
1178 return 0; /* FIXME: return previous position */
1180 case SBM_GETRANGE16
:
1181 FIXME("don't know how to handle SBM_GETRANGE16 (wp=%04x,lp=%08lx)\n", wParam
, lParam
);
1185 GetScrollRange( hwnd
, SB_CTL
, (LPINT
)wParam
, (LPINT
)lParam
);
1188 case SBM_ENABLE_ARROWS16
:
1189 case SBM_ENABLE_ARROWS
:
1190 return EnableScrollBar( hwnd
, SB_CTL
, wParam
);
1192 case SBM_SETRANGEREDRAW
:
1193 SetScrollRange( hwnd
, SB_CTL
, wParam
, lParam
, TRUE
);
1194 return 0; /* FIXME: return previous position */
1196 case SBM_SETSCROLLINFO
:
1197 return SetScrollInfo( hwnd
, SB_CTL
, (SCROLLINFO
*)lParam
, wParam
);
1199 case SBM_GETSCROLLINFO
:
1200 return GetScrollInfo( hwnd
, SB_CTL
, (SCROLLINFO
*)lParam
);
1210 ERR("unknown Win32 msg %04x wp=%08x lp=%08lx\n",
1211 message
, wParam
, lParam
);
1215 if (message
>= WM_USER
)
1216 WARN("unknown msg %04x wp=%04x lp=%08lx\n",
1217 message
, wParam
, lParam
);
1218 return DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1224 /*************************************************************************
1225 * SetScrollInfo16 (USER.475)
1227 INT16 WINAPI
SetScrollInfo16( HWND16 hwnd
, INT16 nBar
, const SCROLLINFO
*info
,
1230 return (INT16
)SetScrollInfo( hwnd
, nBar
, info
, bRedraw
);
1234 /*************************************************************************
1235 * SetScrollInfo32 (USER32.501)
1236 * SetScrollInfo32 can be used to set the position, upper bound,
1237 * lower bound, and page size of a scrollbar control.
1240 * Scrollbar position
1243 * For 100 lines of text to be displayed in a window of 25 lines,
1244 * one would for instance use info->nMin=0, info->nMax=75
1245 * (corresponding to the 76 different positions of the window on
1246 * the text), and info->nPage=25.
1248 INT WINAPI
SetScrollInfo(
1249 HWND hwnd
/* [I] Handle of window whose scrollbar will be affected */,
1250 INT nBar
/* [I] One of SB_HORZ, SB_VERT, or SB_CTL */,
1251 const SCROLLINFO
*info
/* [I] Specifies what to change and new values */,
1252 BOOL bRedraw
/* [I] Should scrollbar be redrawn afterwards ? */)
1255 INT retVal
= SCROLL_SetScrollInfo( hwnd
, nBar
, info
, &action
);
1257 if( action
& SA_SSI_HIDE
)
1258 SCROLL_ShowScrollBar( hwnd
, nBar
, FALSE
, FALSE
);
1261 if( action
& SA_SSI_SHOW
)
1262 if( SCROLL_ShowScrollBar( hwnd
, nBar
, TRUE
, TRUE
) )
1263 return retVal
; /* SetWindowPos() already did the painting */
1265 if( bRedraw
&& (action
& SA_SSI_REFRESH
))
1266 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, TRUE
);
1267 else if( action
& SA_SSI_REPAINT_ARROWS
)
1268 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, FALSE
);
1273 INT
SCROLL_SetScrollInfo( HWND hwnd
, INT nBar
,
1274 const SCROLLINFO
*info
, INT
*action
)
1276 /* Update the scrollbar state and set action flags according to
1277 * what has to be done graphics wise. */
1279 SCROLLBAR_INFO
*infoPtr
;
1284 if (!(infoPtr
= SCROLL_GetScrollInfo(hwnd
, nBar
))) return 0;
1285 if (info
->fMask
& ~(SIF_ALL
| SIF_DISABLENOSCROLL
)) return 0;
1286 if ((info
->cbSize
!= sizeof(*info
)) &&
1287 (info
->cbSize
!= sizeof(*info
)-sizeof(info
->nTrackPos
))) return 0;
1289 if (TRACE_ON(scroll
))
1291 DPRINTF( "hwnd=%04x bar=%d", hwnd
, nBar
);
1292 if (info
->fMask
& SIF_PAGE
) DPRINTF( " page=%d", info
->nPage
);
1293 if (info
->fMask
& SIF_POS
) DPRINTF( " pos=%d", info
->nPos
);
1294 if (info
->fMask
& SIF_RANGE
) DPRINTF( " min=%d max=%d", info
->nMin
, info
->nMax
);
1298 /* Set the page size */
1300 if (info
->fMask
& SIF_PAGE
)
1302 if( infoPtr
->Page
!= info
->nPage
)
1304 infoPtr
->Page
= info
->nPage
;
1305 *action
|= SA_SSI_REFRESH
;
1309 /* Set the scroll pos */
1311 if (info
->fMask
& SIF_POS
)
1313 if( infoPtr
->CurVal
!= info
->nPos
)
1315 infoPtr
->CurVal
= info
->nPos
;
1316 *action
|= SA_SSI_REFRESH
;
1320 /* Set the scroll range */
1322 if (info
->fMask
& SIF_RANGE
)
1324 /* Invalid range -> range is set to (0,0) */
1325 if ((info
->nMin
> info
->nMax
) ||
1326 ((UINT
)(info
->nMax
- info
->nMin
) >= 0x80000000))
1328 infoPtr
->MinVal
= 0;
1329 infoPtr
->MaxVal
= 0;
1333 if( infoPtr
->MinVal
!= info
->nMin
||
1334 infoPtr
->MaxVal
!= info
->nMax
)
1336 *action
|= SA_SSI_REFRESH
;
1337 infoPtr
->MinVal
= info
->nMin
;
1338 infoPtr
->MaxVal
= info
->nMax
;
1343 /* Make sure the page size is valid */
1345 if (infoPtr
->Page
< 0) infoPtr
->Page
= 0;
1346 else if (infoPtr
->Page
> infoPtr
->MaxVal
- infoPtr
->MinVal
+ 1 )
1347 infoPtr
->Page
= infoPtr
->MaxVal
- infoPtr
->MinVal
+ 1;
1349 /* Make sure the pos is inside the range */
1351 if (infoPtr
->CurVal
< infoPtr
->MinVal
)
1352 infoPtr
->CurVal
= infoPtr
->MinVal
;
1353 else if (infoPtr
->CurVal
> infoPtr
->MaxVal
- MAX( infoPtr
->Page
-1, 0 ))
1354 infoPtr
->CurVal
= infoPtr
->MaxVal
- MAX( infoPtr
->Page
-1, 0 );
1356 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1357 infoPtr
->Page
, infoPtr
->CurVal
,
1358 infoPtr
->MinVal
, infoPtr
->MaxVal
);
1360 /* don't change the scrollbar state if SetScrollInfo
1361 * is just called with SIF_DISABLENOSCROLL
1363 if(!(info
->fMask
& SIF_ALL
)) goto done
;
1365 /* Check if the scrollbar should be hidden or disabled */
1367 if (info
->fMask
& (SIF_RANGE
| SIF_PAGE
| SIF_DISABLENOSCROLL
))
1369 new_flags
= infoPtr
->flags
;
1370 if (infoPtr
->MinVal
>= infoPtr
->MaxVal
- MAX( infoPtr
->Page
-1, 0 ))
1372 /* Hide or disable scroll-bar */
1373 if (info
->fMask
& SIF_DISABLENOSCROLL
)
1375 new_flags
= ESB_DISABLE_BOTH
;
1376 *action
|= SA_SSI_REFRESH
;
1378 else if (nBar
!= SB_CTL
)
1380 *action
= SA_SSI_HIDE
;
1384 else /* Show and enable scroll-bar */
1388 *action
|= SA_SSI_SHOW
;
1391 if (infoPtr
->flags
!= new_flags
) /* check arrow flags */
1393 infoPtr
->flags
= new_flags
;
1394 *action
|= SA_SSI_REPAINT_ARROWS
;
1399 /* Return current position */
1401 return infoPtr
->CurVal
;
1405 /*************************************************************************
1406 * GetScrollInfo16 (USER.476)
1408 BOOL16 WINAPI
GetScrollInfo16( HWND16 hwnd
, INT16 nBar
, LPSCROLLINFO info
)
1410 return GetScrollInfo( hwnd
, nBar
, info
);
1414 /*************************************************************************
1415 * GetScrollInfo32 (USER32.284)
1416 * GetScrollInfo32 can be used to retrieve the position, upper bound,
1417 * lower bound, and page size of a scrollbar control.
1421 BOOL WINAPI
GetScrollInfo(
1422 HWND hwnd
/* [I] Handle of window */ ,
1423 INT nBar
/* [I] One of SB_HORZ, SB_VERT, or SB_CTL */,
1424 LPSCROLLINFO info
/* [IO] (info.fMask [I] specifies which values are to retrieve) */)
1426 SCROLLBAR_INFO
*infoPtr
;
1428 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return FALSE
;
1429 if (info
->fMask
& ~(SIF_ALL
| SIF_DISABLENOSCROLL
)) return FALSE
;
1430 if ((info
->cbSize
!= sizeof(*info
)) &&
1431 (info
->cbSize
!= sizeof(*info
)-sizeof(info
->nTrackPos
))) return FALSE
;
1433 if (info
->fMask
& SIF_PAGE
) info
->nPage
= infoPtr
->Page
;
1434 if (info
->fMask
& SIF_POS
) info
->nPos
= infoPtr
->CurVal
;
1435 if ((info
->fMask
& SIF_TRACKPOS
) && (info
->cbSize
== sizeof(*info
)))
1436 info
->nTrackPos
= (SCROLL_TrackingWin
==hwnd
) ? SCROLL_TrackingVal
: infoPtr
->CurVal
;
1437 if (info
->fMask
& SIF_RANGE
)
1439 info
->nMin
= infoPtr
->MinVal
;
1440 info
->nMax
= infoPtr
->MaxVal
;
1442 return (info
->fMask
& SIF_ALL
) != 0;
1446 /*************************************************************************
1447 * SetScrollPos16 (USER.62)
1449 INT16 WINAPI
SetScrollPos16( HWND16 hwnd
, INT16 nBar
, INT16 nPos
,
1452 return (INT16
)SetScrollPos( hwnd
, nBar
, nPos
, bRedraw
);
1456 /*************************************************************************
1457 * SetScrollPos32 (USER32.502)
1460 * Success: Scrollbar position
1464 * Note the ambiguity when 0 is returned. Use GetLastError
1465 * to make sure there was an error (and to know which one).
1467 INT WINAPI
SetScrollPos(
1468 HWND hwnd
/* [I] Handle of window whose scrollbar will be affected */,
1469 INT nBar
/* [I] One of SB_HORZ, SB_VERT, or SB_CTL */,
1470 INT nPos
/* [I] New value */,
1471 BOOL bRedraw
/* [I] Should scrollbar be redrawn afterwards ? */ )
1474 SCROLLBAR_INFO
*infoPtr
;
1477 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return 0;
1478 oldPos
= infoPtr
->CurVal
;
1479 info
.cbSize
= sizeof(info
);
1481 info
.fMask
= SIF_POS
;
1482 SetScrollInfo( hwnd
, nBar
, &info
, bRedraw
);
1487 /*************************************************************************
1488 * GetScrollPos16 (USER.63)
1490 INT16 WINAPI
GetScrollPos16( HWND16 hwnd
, INT16 nBar
)
1492 return (INT16
)GetScrollPos( hwnd
, nBar
);
1496 /*************************************************************************
1497 * GetScrollPos32 (USER32.285)
1500 * Success: Current position
1504 * Note the ambiguity when 0 is returned. Use GetLastError
1505 * to make sure there was an error (and to know which one).
1507 INT WINAPI
GetScrollPos(
1508 HWND hwnd
, /* [I] Handle of window */
1509 INT nBar
/* [I] One of SB_HORZ, SB_VERT, or SB_CTL */)
1511 SCROLLBAR_INFO
*infoPtr
;
1513 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return 0;
1514 return infoPtr
->CurVal
;
1518 /*************************************************************************
1519 * SetScrollRange16 (USER.64)
1521 void WINAPI
SetScrollRange16( HWND16 hwnd
, INT16 nBar
,
1522 INT16 MinVal
, INT16 MaxVal
, BOOL16 bRedraw
)
1524 /* Invalid range -> range is set to (0,0) */
1525 if ((INT
)MaxVal
- (INT
)MinVal
> 0x7fff) MinVal
= MaxVal
= 0;
1526 SetScrollRange( hwnd
, nBar
, MinVal
, MaxVal
, bRedraw
);
1530 /*************************************************************************
1531 * SetScrollRange32 (USER32.503)
1535 BOOL WINAPI
SetScrollRange(
1536 HWND hwnd
, /* [I] Handle of window whose scrollbar will be affected */
1537 INT nBar
, /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */
1538 INT MinVal
, /* [I] New minimum value */
1539 INT MaxVal
, /* [I] New maximum value */
1540 BOOL bRedraw
/* [I] Should scrollbar be redrawn afterwards ? */)
1544 info
.cbSize
= sizeof(info
);
1547 info
.fMask
= SIF_RANGE
;
1548 SetScrollInfo( hwnd
, nBar
, &info
, bRedraw
);
1553 /*************************************************************************
1554 * SCROLL_SetNCSbState
1556 * Updates both scrollbars at the same time. Used by MDI CalcChildScroll().
1558 INT
SCROLL_SetNCSbState(WND
* wndPtr
, int vMin
, int vMax
, int vPos
,
1559 int hMin
, int hMax
, int hPos
)
1562 SCROLLINFO vInfo
, hInfo
;
1564 vInfo
.cbSize
= hInfo
.cbSize
= sizeof(SCROLLINFO
);
1565 vInfo
.nMin
= vMin
; hInfo
.nMin
= hMin
;
1566 vInfo
.nMax
= vMax
; hInfo
.nMax
= hMax
;
1567 vInfo
.nPos
= vPos
; hInfo
.nPos
= hPos
;
1568 vInfo
.fMask
= hInfo
.fMask
= SIF_RANGE
| SIF_POS
;
1570 SCROLL_SetScrollInfo( wndPtr
->hwndSelf
, SB_VERT
, &vInfo
, &vA
);
1571 SCROLL_SetScrollInfo( wndPtr
->hwndSelf
, SB_HORZ
, &hInfo
, &hA
);
1573 if( !SCROLL_ShowScrollBar( wndPtr
->hwndSelf
, SB_BOTH
,
1574 (hA
& SA_SSI_SHOW
),(vA
& SA_SSI_SHOW
) ) )
1576 /* SetWindowPos() wasn't called, just redraw the scrollbars if needed */
1577 if( vA
& SA_SSI_REFRESH
)
1578 SCROLL_RefreshScrollBar( wndPtr
->hwndSelf
, SB_VERT
, FALSE
, TRUE
);
1580 if( hA
& SA_SSI_REFRESH
)
1581 SCROLL_RefreshScrollBar( wndPtr
->hwndSelf
, SB_HORZ
, FALSE
, TRUE
);
1587 /*************************************************************************
1588 * GetScrollRange16 (USER.65)
1590 BOOL16 WINAPI
GetScrollRange16( HWND16 hwnd
, INT16 nBar
,
1591 LPINT16 lpMin
, LPINT16 lpMax
)
1594 BOOL16 ret
= GetScrollRange( hwnd
, nBar
, &min
, &max
);
1595 if (lpMin
) *lpMin
= min
;
1596 if (lpMax
) *lpMax
= max
;
1601 /*************************************************************************
1602 * GetScrollRange32 (USER32.286)
1606 BOOL WINAPI
GetScrollRange(
1607 HWND hwnd
, /* [I] Handle of window */
1608 INT nBar
, /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */
1609 LPINT lpMin
, /* [O] Where to store minimum value */
1610 LPINT lpMax
/* [O] Where to store maximum value */)
1612 SCROLLBAR_INFO
*infoPtr
;
1614 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
)))
1616 if (lpMin
) lpMin
= 0;
1617 if (lpMax
) lpMax
= 0;
1620 if (lpMin
) *lpMin
= infoPtr
->MinVal
;
1621 if (lpMax
) *lpMax
= infoPtr
->MaxVal
;
1626 /*************************************************************************
1627 * SCROLL_ShowScrollBar()
1629 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1630 * NOTE: fShowV/fShowH must be zero when nBar is SB_HORZ/SB_VERT.
1632 BOOL
SCROLL_ShowScrollBar( HWND hwnd
, INT nBar
,
1633 BOOL fShowH
, BOOL fShowV
)
1635 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
1636 BOOL retvalue
= FALSE
;
1638 if (!wndPtr
) return FALSE
;
1639 TRACE("hwnd=%04x bar=%d horz=%d, vert=%d\n",
1640 hwnd
, nBar
, fShowH
, fShowV
);
1645 ShowWindow( hwnd
, fShowH
? SW_SHOW
: SW_HIDE
);
1653 fShowH
= !(wndPtr
->dwStyle
& WS_HSCROLL
);
1654 wndPtr
->dwStyle
|= WS_HSCROLL
;
1658 fShowH
= (wndPtr
->dwStyle
& WS_HSCROLL
);
1659 wndPtr
->dwStyle
&= ~WS_HSCROLL
;
1661 if( nBar
== SB_HORZ
) {
1670 fShowV
= !(wndPtr
->dwStyle
& WS_VSCROLL
);
1671 wndPtr
->dwStyle
|= WS_VSCROLL
;
1675 fShowV
= (wndPtr
->dwStyle
& WS_VSCROLL
);
1676 wndPtr
->dwStyle
&= ~WS_VSCROLL
;
1678 if ( nBar
== SB_VERT
)
1683 retvalue
= FALSE
; /* Nothing to do! */
1687 if( fShowH
|| fShowV
) /* frame has been changed, let the window redraw itself */
1689 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
1690 | SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
1695 retvalue
= FALSE
; /* no frame changes */
1697 WIN_ReleaseWndPtr(wndPtr
);
1702 /*************************************************************************
1703 * ShowScrollBar16 (USER.267)
1705 void WINAPI
ShowScrollBar16( HWND16 hwnd
, INT16 nBar
, BOOL16 fShow
)
1707 SCROLL_ShowScrollBar( hwnd
, nBar
, (nBar
== SB_VERT
) ? 0 : fShow
,
1708 (nBar
== SB_HORZ
) ? 0 : fShow
);
1712 /*************************************************************************
1713 * ShowScrollBar32 (USER32.532)
1717 BOOL WINAPI
ShowScrollBar(
1718 HWND hwnd
, /* [I] Handle of window whose scrollbar(s) will be affected */
1719 INT nBar
, /* [I] One of SB_HORZ, SB_VERT, SB_BOTH or SB_CTL */
1720 BOOL fShow
/* [I] TRUE = show, FALSE = hide */)
1722 SCROLL_ShowScrollBar( hwnd
, nBar
, (nBar
== SB_VERT
) ? 0 : fShow
,
1723 (nBar
== SB_HORZ
) ? 0 : fShow
);
1728 /*************************************************************************
1729 * EnableScrollBar16 (USER.482)
1731 BOOL16 WINAPI
EnableScrollBar16( HWND16 hwnd
, INT16 nBar
, UINT16 flags
)
1733 return EnableScrollBar( hwnd
, nBar
, flags
);
1737 /*************************************************************************
1738 * EnableScrollBar32 (USER32.171)
1740 BOOL WINAPI
EnableScrollBar( HWND hwnd
, INT nBar
, UINT flags
)
1743 SCROLLBAR_INFO
*infoPtr
;
1745 TRACE("%04x %d %d\n", hwnd
, nBar
, flags
);
1747 flags
&= ESB_DISABLE_BOTH
;
1749 if (nBar
== SB_BOTH
)
1751 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, SB_VERT
))) return FALSE
;
1752 if (!(bFineWithMe
= (infoPtr
->flags
== flags
)) )
1754 infoPtr
->flags
= flags
;
1755 SCROLL_RefreshScrollBar( hwnd
, SB_VERT
, TRUE
, TRUE
);
1762 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return FALSE
;
1763 if (bFineWithMe
&& infoPtr
->flags
== flags
) return FALSE
;
1764 infoPtr
->flags
= flags
;
1766 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, TRUE
);