4 * Copyright 1993 Martin Ayotte
5 * Copyright 1994, 1996 Alexandre Julliard
10 #include "wine/winuser16.h"
13 #include "debugtools.h"
17 DEFAULT_DEBUG_CHANNEL(scroll
);
21 INT CurVal
; /* Current scroll-bar value */
22 INT MinVal
; /* Minimum scroll-bar value */
23 INT MaxVal
; /* Maximum scroll-bar value */
24 INT Page
; /* Page size of scroll bar (Win32) */
25 UINT flags
; /* EnableScrollBar flags */
29 static HBITMAP hUpArrow
;
30 static HBITMAP hDnArrow
;
31 static HBITMAP hLfArrow
;
32 static HBITMAP hRgArrow
;
33 static HBITMAP hUpArrowD
;
34 static HBITMAP hDnArrowD
;
35 static HBITMAP hLfArrowD
;
36 static HBITMAP hRgArrowD
;
37 static HBITMAP hUpArrowI
;
38 static HBITMAP hDnArrowI
;
39 static HBITMAP hLfArrowI
;
40 static HBITMAP hRgArrowI
;
42 #define TOP_ARROW(flags,pressed) \
43 (((flags)&ESB_DISABLE_UP) ? hUpArrowI : ((pressed) ? hUpArrowD:hUpArrow))
44 #define BOTTOM_ARROW(flags,pressed) \
45 (((flags)&ESB_DISABLE_DOWN) ? hDnArrowI : ((pressed) ? hDnArrowD:hDnArrow))
46 #define LEFT_ARROW(flags,pressed) \
47 (((flags)&ESB_DISABLE_LEFT) ? hLfArrowI : ((pressed) ? hLfArrowD:hLfArrow))
48 #define RIGHT_ARROW(flags,pressed) \
49 (((flags)&ESB_DISABLE_RIGHT) ? hRgArrowI : ((pressed) ? hRgArrowD:hRgArrow))
52 /* Minimum size of the rectangle between the arrows */
53 #define SCROLL_MIN_RECT 4
55 /* Minimum size of the thumb in pixels */
56 #define SCROLL_MIN_THUMB 6
58 /* Overlap between arrows and thumb */
59 #define SCROLL_ARROW_THUMB_OVERLAP ((TWEAK_WineLook == WIN31_LOOK) ? 1 : 0)
61 /* Delay (in ms) before first repetition when holding the button down */
62 #define SCROLL_FIRST_DELAY 200
64 /* Delay (in ms) between scroll repetitions */
65 #define SCROLL_REPEAT_DELAY 50
68 #define SCROLL_TIMER 0
70 /* Scroll-bar hit testing */
73 SCROLL_NOWHERE
, /* Outside the scroll bar */
74 SCROLL_TOP_ARROW
, /* Top or left arrow */
75 SCROLL_TOP_RECT
, /* Rectangle between the top arrow and the thumb */
76 SCROLL_THUMB
, /* Thumb rectangle */
77 SCROLL_BOTTOM_RECT
, /* Rectangle between the thumb and the bottom arrow */
78 SCROLL_BOTTOM_ARROW
/* Bottom or right arrow */
81 /* What to do after SCROLL_SetScrollInfo() */
82 #define SA_SSI_HIDE 0x0001
83 #define SA_SSI_SHOW 0x0002
84 #define SA_SSI_REFRESH 0x0004
85 #define SA_SSI_REPAINT_ARROWS 0x0008
87 /* Thumb-tracking info */
88 static HWND SCROLL_TrackingWin
= 0;
89 static INT SCROLL_TrackingBar
= 0;
90 static INT SCROLL_TrackingPos
= 0;
91 static INT SCROLL_TrackingVal
= 0;
92 /* Hit test code of the last button-down event */
93 static enum SCROLL_HITTEST SCROLL_trackHitTest
;
94 static BOOL SCROLL_trackVertical
;
96 /* Is the moving thumb being displayed? */
97 static BOOL SCROLL_MovingThumb
= FALSE
;
100 static BOOL
SCROLL_ShowScrollBar( HWND hwnd
, INT nBar
,
101 BOOL fShowH
, BOOL fShowV
);
102 static INT
SCROLL_SetScrollInfo( HWND hwnd
, INT nBar
,
103 const SCROLLINFO
*info
, INT
*action
);
104 static void SCROLL_DrawInterior_9x( HWND hwnd
, HDC hdc
, INT nBar
,
105 RECT
*rect
, INT arrowSize
,
106 INT thumbSize
, INT thumbPos
,
107 UINT flags
, BOOL vertical
,
108 BOOL top_selected
, BOOL bottom_selected
);
109 static LRESULT WINAPI
ScrollBarWndProc( HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
112 /*********************************************************************
113 * scrollbar class descriptor
115 const struct builtin_class_descr SCROLL_builtin_class
=
117 "ScrollBar", /* name */
118 CS_GLOBALCLASS
| CS_DBLCLKS
| CS_VREDRAW
| CS_HREDRAW
| CS_PARENTDC
, /* style */
119 NULL
, /* procA (winproc is Unicode only) */
120 ScrollBarWndProc
, /* procW */
121 sizeof(SCROLLBAR_INFO
), /* extra */
122 IDC_ARROWA
, /* cursor */
127 /***********************************************************************
130 static void SCROLL_LoadBitmaps(void)
132 hUpArrow
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROW
) );
133 hDnArrow
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROW
) );
134 hLfArrow
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROW
) );
135 hRgArrow
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROW
) );
136 hUpArrowD
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROWD
) );
137 hDnArrowD
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROWD
) );
138 hLfArrowD
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROWD
) );
139 hRgArrowD
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROWD
) );
140 hUpArrowI
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROWI
) );
141 hDnArrowI
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROWI
) );
142 hLfArrowI
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROWI
) );
143 hRgArrowI
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROWI
) );
147 /***********************************************************************
148 * SCROLL_GetScrollInfo
150 static SCROLLBAR_INFO
*SCROLL_GetScrollInfo( HWND hwnd
, INT nBar
)
152 SCROLLBAR_INFO
*infoPtr
;
153 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
155 if (!wndPtr
) return NULL
;
158 case SB_HORZ
: infoPtr
= (SCROLLBAR_INFO
*)wndPtr
->pHScroll
; break;
159 case SB_VERT
: infoPtr
= (SCROLLBAR_INFO
*)wndPtr
->pVScroll
; break;
160 case SB_CTL
: infoPtr
= (SCROLLBAR_INFO
*)wndPtr
->wExtra
; break;
162 WIN_ReleaseWndPtr( wndPtr
);
166 if (!infoPtr
) /* Create the info structure if needed */
168 if ((infoPtr
= HeapAlloc( GetProcessHeap(), 0, sizeof(SCROLLBAR_INFO
) )))
170 infoPtr
->MinVal
= infoPtr
->CurVal
= infoPtr
->Page
= 0;
171 infoPtr
->MaxVal
= 100;
172 infoPtr
->flags
= ESB_ENABLE_BOTH
;
173 if (nBar
== SB_HORZ
) wndPtr
->pHScroll
= infoPtr
;
174 else wndPtr
->pVScroll
= infoPtr
;
176 if (!hUpArrow
) SCROLL_LoadBitmaps();
178 WIN_ReleaseWndPtr( wndPtr
);
183 /***********************************************************************
184 * SCROLL_GetScrollBarRect
186 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
187 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
188 * 'arrowSize' returns the width or height of an arrow (depending on
189 * the orientation of the scrollbar), 'thumbSize' returns the size of
190 * the thumb, and 'thumbPos' returns the position of the thumb
191 * relative to the left or to the top.
192 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
194 static BOOL
SCROLL_GetScrollBarRect( HWND hwnd
, INT nBar
, RECT
*lprect
,
195 INT
*arrowSize
, INT
*thumbSize
,
200 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
205 lprect
->left
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
206 lprect
->top
= wndPtr
->rectClient
.bottom
- wndPtr
->rectWindow
.top
;
207 lprect
->right
= wndPtr
->rectClient
.right
- wndPtr
->rectWindow
.left
;
208 lprect
->bottom
= lprect
->top
+ GetSystemMetrics(SM_CYHSCROLL
);
209 if(wndPtr
->dwStyle
& WS_BORDER
) {
212 } else if(wndPtr
->dwStyle
& WS_VSCROLL
)
218 lprect
->left
= wndPtr
->rectClient
.right
- wndPtr
->rectWindow
.left
;
219 lprect
->top
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
220 lprect
->right
= lprect
->left
+ GetSystemMetrics(SM_CXVSCROLL
);
221 lprect
->bottom
= wndPtr
->rectClient
.bottom
- wndPtr
->rectWindow
.top
;
222 if(wndPtr
->dwStyle
& WS_BORDER
) {
225 } else if(wndPtr
->dwStyle
& WS_HSCROLL
)
231 GetClientRect( hwnd
, lprect
);
232 vertical
= ((wndPtr
->dwStyle
& SBS_VERT
) != 0);
236 WIN_ReleaseWndPtr(wndPtr
);
240 if (vertical
) pixels
= lprect
->bottom
- lprect
->top
;
241 else pixels
= lprect
->right
- lprect
->left
;
243 if (pixels
<= 2*GetSystemMetrics(SM_CXVSCROLL
) + SCROLL_MIN_RECT
)
245 if (pixels
> SCROLL_MIN_RECT
)
246 *arrowSize
= (pixels
- SCROLL_MIN_RECT
) / 2;
249 *thumbPos
= *thumbSize
= 0;
253 SCROLLBAR_INFO
*info
= SCROLL_GetScrollInfo( hwnd
, nBar
);
255 *arrowSize
= GetSystemMetrics(SM_CXVSCROLL
);
256 pixels
-= (2 * (GetSystemMetrics(SM_CXVSCROLL
) - SCROLL_ARROW_THUMB_OVERLAP
));
260 *thumbSize
= pixels
* info
->Page
/ (info
->MaxVal
-info
->MinVal
+1);
261 if (*thumbSize
< SCROLL_MIN_THUMB
) *thumbSize
= SCROLL_MIN_THUMB
;
263 else *thumbSize
= GetSystemMetrics(SM_CXVSCROLL
);
265 if (((pixels
-= *thumbSize
) < 0) ||
266 ((info
->flags
& ESB_DISABLE_BOTH
) == ESB_DISABLE_BOTH
))
268 /* Rectangle too small or scrollbar disabled -> no thumb */
269 *thumbPos
= *thumbSize
= 0;
273 INT max
= info
->MaxVal
- max( info
->Page
-1, 0 );
274 if (info
->MinVal
>= max
)
275 *thumbPos
= *arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
277 *thumbPos
= *arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
278 + pixels
* (info
->CurVal
-info
->MinVal
) / (max
- info
->MinVal
);
281 WIN_ReleaseWndPtr(wndPtr
);
286 /***********************************************************************
289 * Compute the current scroll position based on the thumb position in pixels
290 * from the top of the scroll-bar.
292 static UINT
SCROLL_GetThumbVal( SCROLLBAR_INFO
*infoPtr
, RECT
*rect
,
293 BOOL vertical
, INT pos
)
296 INT pixels
= vertical
? rect
->bottom
-rect
->top
: rect
->right
-rect
->left
;
298 if ((pixels
-= 2*(GetSystemMetrics(SM_CXVSCROLL
) - SCROLL_ARROW_THUMB_OVERLAP
)) <= 0)
299 return infoPtr
->MinVal
;
303 thumbSize
= pixels
* infoPtr
->Page
/(infoPtr
->MaxVal
-infoPtr
->MinVal
+1);
304 if (thumbSize
< SCROLL_MIN_THUMB
) thumbSize
= SCROLL_MIN_THUMB
;
306 else thumbSize
= GetSystemMetrics(SM_CXVSCROLL
);
308 if ((pixels
-= thumbSize
) <= 0) return infoPtr
->MinVal
;
310 pos
= max( 0, pos
- (GetSystemMetrics(SM_CXVSCROLL
) - SCROLL_ARROW_THUMB_OVERLAP
) );
311 if (pos
> pixels
) pos
= pixels
;
313 if (!infoPtr
->Page
) pos
*= infoPtr
->MaxVal
- infoPtr
->MinVal
;
314 else pos
*= infoPtr
->MaxVal
- infoPtr
->MinVal
- infoPtr
->Page
+ 1;
315 return infoPtr
->MinVal
+ ((pos
+ pixels
/ 2) / pixels
);
318 /***********************************************************************
321 static BOOL
SCROLL_PtInRectEx( LPRECT lpRect
, POINT pt
, BOOL vertical
)
327 rect
.left
-= lpRect
->right
- lpRect
->left
;
328 rect
.right
+= lpRect
->right
- lpRect
->left
;
332 rect
.top
-= lpRect
->bottom
- lpRect
->top
;
333 rect
.bottom
+= lpRect
->bottom
- lpRect
->top
;
335 return PtInRect( &rect
, pt
);
338 /***********************************************************************
341 static POINT
SCROLL_ClipPos( LPRECT lpRect
, POINT pt
)
343 if( pt
.x
< lpRect
->left
)
346 if( pt
.x
> lpRect
->right
)
347 pt
.x
= lpRect
->right
;
349 if( pt
.y
< lpRect
->top
)
352 if( pt
.y
> lpRect
->bottom
)
353 pt
.y
= lpRect
->bottom
;
359 /***********************************************************************
362 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
364 static enum SCROLL_HITTEST
SCROLL_HitTest( HWND hwnd
, INT nBar
,
365 POINT pt
, BOOL bDragging
)
367 INT arrowSize
, thumbSize
, thumbPos
;
370 BOOL vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
371 &arrowSize
, &thumbSize
, &thumbPos
);
373 if ( (bDragging
&& !SCROLL_PtInRectEx( &rect
, pt
, vertical
)) ||
374 (!PtInRect( &rect
, pt
)) ) return SCROLL_NOWHERE
;
378 if (pt
.y
< rect
.top
+ arrowSize
) return SCROLL_TOP_ARROW
;
379 if (pt
.y
>= rect
.bottom
- arrowSize
) return SCROLL_BOTTOM_ARROW
;
380 if (!thumbPos
) return SCROLL_TOP_RECT
;
382 if (pt
.y
< thumbPos
) return SCROLL_TOP_RECT
;
383 if (pt
.y
>= thumbPos
+ thumbSize
) return SCROLL_BOTTOM_RECT
;
385 else /* horizontal */
387 if (pt
.x
< rect
.left
+ arrowSize
) return SCROLL_TOP_ARROW
;
388 if (pt
.x
>= rect
.right
- arrowSize
) return SCROLL_BOTTOM_ARROW
;
389 if (!thumbPos
) return SCROLL_TOP_RECT
;
391 if (pt
.x
< thumbPos
) return SCROLL_TOP_RECT
;
392 if (pt
.x
>= thumbPos
+ thumbSize
) return SCROLL_BOTTOM_RECT
;
398 /***********************************************************************
401 * Draw the scroll bar arrows.
403 static void SCROLL_DrawArrows_9x( HDC hdc
, SCROLLBAR_INFO
*infoPtr
,
404 RECT
*rect
, INT arrowSize
, BOOL vertical
,
405 BOOL top_pressed
, BOOL bottom_pressed
)
411 r
.bottom
= r
.top
+ arrowSize
;
413 r
.right
= r
.left
+ arrowSize
;
415 DrawFrameControl( hdc
, &r
, DFC_SCROLL
,
416 (vertical
? DFCS_SCROLLUP
: DFCS_SCROLLLEFT
)
417 | (top_pressed
? (DFCS_PUSHED
| DFCS_FLAT
) : 0 )
418 | (infoPtr
->flags
&ESB_DISABLE_LTUP
? DFCS_INACTIVE
: 0 ) );
422 r
.top
= r
.bottom
-arrowSize
;
424 r
.left
= r
.right
-arrowSize
;
426 DrawFrameControl( hdc
, &r
, DFC_SCROLL
,
427 (vertical
? DFCS_SCROLLDOWN
: DFCS_SCROLLRIGHT
)
428 | (bottom_pressed
? (DFCS_PUSHED
| DFCS_FLAT
) : 0 )
429 | (infoPtr
->flags
&ESB_DISABLE_RTDN
? DFCS_INACTIVE
: 0) );
432 static void SCROLL_DrawArrows_31( HDC hdc
, SCROLLBAR_INFO
*infoPtr
,
433 RECT
*rect
, INT arrowSize
, BOOL vertical
,
434 BOOL top_pressed
, BOOL bottom_pressed
)
436 HDC hdcMem
= CreateCompatibleDC( hdc
);
437 HBITMAP hbmpPrev
= SelectObject( hdcMem
, vertical
?
438 TOP_ARROW(infoPtr
->flags
, top_pressed
)
439 : LEFT_ARROW(infoPtr
->flags
, top_pressed
));
441 SetStretchBltMode( hdc
, STRETCH_DELETESCANS
);
442 StretchBlt( hdc
, rect
->left
, rect
->top
,
443 vertical
? rect
->right
-rect
->left
: arrowSize
,
444 vertical
? arrowSize
: rect
->bottom
-rect
->top
,
446 GetSystemMetrics(SM_CXVSCROLL
),GetSystemMetrics(SM_CYHSCROLL
),
449 SelectObject( hdcMem
, vertical
?
450 BOTTOM_ARROW( infoPtr
->flags
, bottom_pressed
)
451 : RIGHT_ARROW( infoPtr
->flags
, bottom_pressed
) );
453 StretchBlt( hdc
, rect
->left
, rect
->bottom
- arrowSize
,
454 rect
->right
- rect
->left
, arrowSize
,
456 GetSystemMetrics(SM_CXVSCROLL
),GetSystemMetrics(SM_CYHSCROLL
),
459 StretchBlt( hdc
, rect
->right
- arrowSize
, rect
->top
,
460 arrowSize
, rect
->bottom
- rect
->top
,
462 GetSystemMetrics(SM_CXVSCROLL
), GetSystemMetrics(SM_CYHSCROLL
),
464 SelectObject( hdcMem
, hbmpPrev
);
468 static void SCROLL_DrawArrows( HDC hdc
, SCROLLBAR_INFO
*infoPtr
,
469 RECT
*rect
, INT arrowSize
, BOOL vertical
,
470 BOOL top_pressed
, BOOL bottom_pressed
)
472 if( TWEAK_WineLook
== WIN31_LOOK
)
473 SCROLL_DrawArrows_31( hdc
, infoPtr
, rect
, arrowSize
,
474 vertical
, top_pressed
,bottom_pressed
);
476 SCROLL_DrawArrows_9x( hdc
, infoPtr
, rect
, arrowSize
,
477 vertical
, top_pressed
,bottom_pressed
);
481 /***********************************************************************
482 * SCROLL_DrawMovingThumb
484 * Draw the moving thumb rectangle.
486 static void SCROLL_DrawMovingThumb_31( HDC hdc
, RECT
*rect
, BOOL vertical
,
487 INT arrowSize
, INT thumbSize
)
492 r
.top
+= SCROLL_TrackingPos
;
493 if (r
.top
< rect
->top
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
494 r
.top
= rect
->top
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
495 if (r
.top
+ thumbSize
>
496 rect
->bottom
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
))
497 r
.top
= rect
->bottom
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
499 r
.bottom
= r
.top
+ thumbSize
;
503 r
.left
+= SCROLL_TrackingPos
;
504 if (r
.left
< rect
->left
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
505 r
.left
= rect
->left
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
506 if (r
.left
+ thumbSize
>
507 rect
->right
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
))
508 r
.left
= rect
->right
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
510 r
.right
= r
.left
+ thumbSize
;
513 DrawFocusRect( hdc
, &r
);
514 SCROLL_MovingThumb
= !SCROLL_MovingThumb
;
517 static void SCROLL_DrawMovingThumb_9x( HDC hdc
, RECT
*rect
, BOOL vertical
,
518 INT arrowSize
, INT thumbSize
)
520 INT pos
= SCROLL_TrackingPos
;
524 max_size
= rect
->bottom
- rect
->top
;
526 max_size
= rect
->right
- rect
->left
;
528 max_size
-= (arrowSize
-SCROLL_ARROW_THUMB_OVERLAP
) + thumbSize
;
530 if( pos
< (arrowSize
-SCROLL_ARROW_THUMB_OVERLAP
) )
531 pos
= (arrowSize
-SCROLL_ARROW_THUMB_OVERLAP
);
532 else if( pos
> max_size
)
535 SCROLL_DrawInterior_9x( SCROLL_TrackingWin
, hdc
, SCROLL_TrackingBar
,
536 rect
, arrowSize
, thumbSize
, pos
,
537 0, vertical
, FALSE
, FALSE
);
539 SCROLL_MovingThumb
= !SCROLL_MovingThumb
;
542 static void SCROLL_DrawMovingThumb( HDC hdc
, RECT
*rect
, BOOL vertical
,
543 INT arrowSize
, INT thumbSize
)
545 if( TWEAK_WineLook
== WIN31_LOOK
)
546 SCROLL_DrawMovingThumb_31( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
548 SCROLL_DrawMovingThumb_9x( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
551 /***********************************************************************
552 * SCROLL_DrawInterior
554 * Draw the scroll bar interior (everything except the arrows).
556 static void SCROLL_DrawInterior_9x( HWND hwnd
, HDC hdc
, INT nBar
,
557 RECT
*rect
, INT arrowSize
,
558 INT thumbSize
, INT thumbPos
,
559 UINT flags
, BOOL vertical
,
560 BOOL top_selected
, BOOL bottom_selected
)
564 HBRUSH hSaveBrush
,hBrush
;
566 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
567 * The window-owned scrollbars need to call DEFWND_ControlColor
568 * to correctly setup default scrollbar colors
572 hBrush
= (HBRUSH
)SendMessageA( GetParent(hwnd
), WM_CTLCOLORSCROLLBAR
,
573 (WPARAM
)hdc
,(LPARAM
)hwnd
);
577 hBrush
= DEFWND_ControlColor( hdc
, CTLCOLOR_SCROLLBAR
);
580 hSavePen
= SelectObject( hdc
, GetSysColorPen(COLOR_WINDOWFRAME
) );
581 hSaveBrush
= SelectObject( hdc
, hBrush
);
583 /* Calculate the scroll rectangle */
587 r
.top
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
588 r
.bottom
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
592 r
.left
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
593 r
.right
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
596 /* Draw the scroll rectangles and thumb */
597 if (!thumbPos
) /* No thumb to draw */
599 PatBlt( hdc
, r
.left
, r
.top
,
600 r
.right
- r
.left
, r
.bottom
- r
.top
,
603 /* cleanup and return */
604 SelectObject( hdc
, hSavePen
);
605 SelectObject( hdc
, hSaveBrush
);
611 PatBlt( hdc
, r
.left
, r
.top
,
613 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
),
614 top_selected
? 0x0f0000 : PATCOPY
);
615 r
.top
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
616 PatBlt( hdc
, r
.left
, r
.top
+ thumbSize
,
618 r
.bottom
- r
.top
- thumbSize
,
619 bottom_selected
? 0x0f0000 : PATCOPY
);
620 r
.bottom
= r
.top
+ thumbSize
;
622 else /* horizontal */
624 PatBlt( hdc
, r
.left
, r
.top
,
625 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
),
627 top_selected
? 0x0f0000 : PATCOPY
);
628 r
.left
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
629 PatBlt( hdc
, r
.left
+ thumbSize
, r
.top
,
630 r
.right
- r
.left
- thumbSize
,
632 bottom_selected
? 0x0f0000 : PATCOPY
);
633 r
.right
= r
.left
+ thumbSize
;
637 DrawEdge( hdc
, &r
, EDGE_RAISED
, BF_RECT
| BF_MIDDLE
);
640 SelectObject( hdc
, hSavePen
);
641 SelectObject( hdc
, hSaveBrush
);
645 static void SCROLL_DrawInterior( HWND hwnd
, HDC hdc
, INT nBar
,
646 RECT
*rect
, INT arrowSize
,
647 INT thumbSize
, INT thumbPos
,
648 UINT flags
, BOOL vertical
,
649 BOOL top_selected
, BOOL bottom_selected
)
653 HBRUSH hSaveBrush
,hBrush
;
654 BOOL Save_SCROLL_MovingThumb
= SCROLL_MovingThumb
;
656 if (Save_SCROLL_MovingThumb
&&
657 (SCROLL_TrackingWin
== hwnd
) &&
658 (SCROLL_TrackingBar
== nBar
))
659 SCROLL_DrawMovingThumb( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
661 /* Select the correct brush and pen */
663 if (TWEAK_WineLook
== WIN31_LOOK
&& (flags
& ESB_DISABLE_BOTH
) == ESB_DISABLE_BOTH
)
665 /* This ought to be the color of the parent window */
666 hBrush
= GetSysColorBrush(COLOR_WINDOW
);
670 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
671 * The window-owned scrollbars need to call DEFWND_ControlColor
672 * to correctly setup default scrollbar colors
674 if (nBar
== SB_CTL
) {
675 hBrush
= (HBRUSH
)SendMessageA( GetParent(hwnd
), WM_CTLCOLORSCROLLBAR
,
676 (WPARAM
)hdc
,(LPARAM
)hwnd
);
678 hBrush
= DEFWND_ControlColor( hdc
, CTLCOLOR_SCROLLBAR
);
681 hSavePen
= SelectObject( hdc
, GetSysColorPen(COLOR_WINDOWFRAME
) );
682 hSaveBrush
= SelectObject( hdc
, hBrush
);
684 /* Calculate the scroll rectangle */
689 r
.top
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
690 r
.bottom
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
694 r
.left
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
695 r
.right
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
698 /* Draw the scroll bar frame */
700 /* Only draw outline if Win 3.1. Mar 24, 1999 - Ronald B. Cemer */
701 if (TWEAK_WineLook
== WIN31_LOOK
)
702 Rectangle( hdc
, r
.left
, r
.top
, r
.right
, r
.bottom
);
704 /* Draw the scroll rectangles and thumb */
706 if (!thumbPos
) /* No thumb to draw */
708 INT offset
= (TWEAK_WineLook
> WIN31_LOOK
) ? 0 : 1;
710 PatBlt( hdc
, r
.left
+offset
, r
.top
+offset
,
711 r
.right
- r
.left
- 2*offset
, r
.bottom
- r
.top
- 2*offset
,
714 /* cleanup and return */
715 SelectObject( hdc
, hSavePen
);
716 SelectObject( hdc
, hSaveBrush
);
722 INT offset
= (TWEAK_WineLook
== WIN31_LOOK
) ? 1 : 0;
724 PatBlt( hdc
, r
.left
+ offset
, r
.top
+ offset
,
725 r
.right
- r
.left
- offset
*2,
726 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
) - offset
,
727 top_selected
? 0x0f0000 : PATCOPY
);
728 r
.top
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
729 PatBlt( hdc
, r
.left
+ offset
, r
.top
+ thumbSize
,
730 r
.right
- r
.left
- offset
*2,
731 r
.bottom
- r
.top
- thumbSize
- offset
,
732 bottom_selected
? 0x0f0000 : PATCOPY
);
733 r
.bottom
= r
.top
+ thumbSize
;
735 else /* horizontal */
737 INT offset
= (TWEAK_WineLook
== WIN31_LOOK
) ? 1 : 0;
739 PatBlt( hdc
, r
.left
+ offset
, r
.top
+ offset
,
740 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
),
741 r
.bottom
- r
.top
- offset
*2,
742 top_selected
? 0x0f0000 : PATCOPY
);
743 r
.left
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
744 PatBlt( hdc
, r
.left
+ thumbSize
, r
.top
+ offset
,
745 r
.right
- r
.left
- thumbSize
- offset
,
746 r
.bottom
- r
.top
- offset
*2,
747 bottom_selected
? 0x0f0000 : PATCOPY
);
748 r
.right
= r
.left
+ thumbSize
;
753 SelectObject( hdc
, GetSysColorBrush(COLOR_BTNFACE
) );
754 if (TWEAK_WineLook
== WIN31_LOOK
)
756 Rectangle( hdc
, r
.left
, r
.top
, r
.right
, r
.bottom
);
761 Rectangle( hdc
, r
.left
+1, r
.top
+1, r
.right
-1, r
.bottom
-1 );
763 DrawEdge( hdc
, &r
, EDGE_RAISED
, BF_RECT
);
765 if (Save_SCROLL_MovingThumb
&&
766 (SCROLL_TrackingWin
== hwnd
) &&
767 (SCROLL_TrackingBar
== nBar
))
768 SCROLL_DrawMovingThumb( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
771 SelectObject( hdc
, hSavePen
);
772 SelectObject( hdc
, hSaveBrush
);
776 /***********************************************************************
777 * SCROLL_DrawScrollBar
779 * Redraw the whole scrollbar.
781 void SCROLL_DrawScrollBar( HWND hwnd
, HDC hdc
, INT nBar
,
782 BOOL arrows
, BOOL interior
)
784 INT arrowSize
, thumbSize
, thumbPos
;
787 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
788 SCROLLBAR_INFO
*infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
);
789 BOOL Save_SCROLL_MovingThumb
= SCROLL_MovingThumb
;
791 if (!wndPtr
|| !infoPtr
||
792 ((nBar
== SB_VERT
) && !(wndPtr
->dwStyle
& WS_VSCROLL
)) ||
793 ((nBar
== SB_HORZ
) && !(wndPtr
->dwStyle
& WS_HSCROLL
))) goto END
;
794 if (!WIN_IsWindowDrawable( wndPtr
, FALSE
)) goto END
;
795 hwnd
= wndPtr
->hwndSelf
; /* make it a full handle */
797 vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
798 &arrowSize
, &thumbSize
, &thumbPos
);
800 /* do not draw if the scrollbar rectangle is empty */
801 if(IsRectEmpty(&rect
))
804 if (Save_SCROLL_MovingThumb
&&
805 (SCROLL_TrackingWin
== hwnd
) &&
806 (SCROLL_TrackingBar
== nBar
))
807 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
809 /* Draw the arrows */
811 if (arrows
&& arrowSize
)
813 if( vertical
== SCROLL_trackVertical
&& GetCapture() == hwnd
)
814 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
815 (SCROLL_trackHitTest
== SCROLL_TOP_ARROW
),
816 (SCROLL_trackHitTest
== SCROLL_BOTTOM_ARROW
) );
818 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
822 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
823 thumbPos
, infoPtr
->flags
, vertical
, FALSE
, FALSE
);
825 if (Save_SCROLL_MovingThumb
&&
826 (SCROLL_TrackingWin
== hwnd
) &&
827 (SCROLL_TrackingBar
== nBar
))
828 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
830 /* if scroll bar has focus, reposition the caret */
831 if(hwnd
==GetFocus() && (nBar
==SB_CTL
))
835 SetCaretPos(thumbPos
+1, rect
.top
+1);
839 SetCaretPos(rect
.top
+1, thumbPos
+1);
844 WIN_ReleaseWndPtr(wndPtr
);
848 /***********************************************************************
849 * SCROLL_RefreshScrollBar
851 * Repaint the scroll bar interior after a SetScrollRange() or
852 * SetScrollPos() call.
854 static void SCROLL_RefreshScrollBar( HWND hwnd
, INT nBar
,
855 BOOL arrows
, BOOL interior
)
857 HDC hdc
= GetDCEx( hwnd
, 0,
858 DCX_CACHE
| ((nBar
== SB_CTL
) ? 0 : DCX_WINDOW
) );
861 SCROLL_DrawScrollBar( hwnd
, hdc
, nBar
, arrows
, interior
);
862 ReleaseDC( hwnd
, hdc
);
866 /***********************************************************************
867 * SCROLL_HandleKbdEvent
869 * Handle a keyboard event (only for SB_CTL scrollbars).
871 static void SCROLL_HandleKbdEvent( HWND hwnd
, WPARAM wParam
)
877 case VK_PRIOR
: msg
= SB_PAGEUP
; break;
878 case VK_NEXT
: msg
= SB_PAGEDOWN
; break;
879 case VK_HOME
: msg
= SB_TOP
; break;
880 case VK_END
: msg
= SB_BOTTOM
; break;
881 case VK_UP
: msg
= SB_LINEUP
; break;
882 case VK_DOWN
: msg
= SB_LINEDOWN
; break;
885 SendMessageW( GetParent(hwnd
),
886 (GetWindowLongA( hwnd
, GWL_STYLE
) & SBS_VERT
) ? WM_VSCROLL
: WM_HSCROLL
,
891 /***********************************************************************
892 * SCROLL_HandleScrollEvent
894 * Handle a mouse or timer event for the scrollbar.
895 * 'pt' is the location of the mouse event in client (for SB_CTL) or
896 * windows coordinates.
898 void SCROLL_HandleScrollEvent( HWND hwnd
, INT nBar
, UINT msg
, POINT pt
)
900 /* Previous mouse position for timer events */
902 /* Thumb position when tracking started. */
903 static UINT trackThumbPos
;
904 /* Position in the scroll-bar of the last button-down event. */
905 static INT lastClickPos
;
906 /* Position in the scroll-bar of the last mouse event. */
907 static INT lastMousePos
;
909 enum SCROLL_HITTEST hittest
;
910 HWND hwndOwner
, hwndCtl
;
912 INT arrowSize
, thumbSize
, thumbPos
;
916 SCROLLBAR_INFO
*infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
);
917 if (!infoPtr
) return;
918 if ((SCROLL_trackHitTest
== SCROLL_NOWHERE
) && (msg
!= WM_LBUTTONDOWN
))
921 hdc
= GetDCEx( hwnd
, 0, DCX_CACHE
| ((nBar
== SB_CTL
) ? 0 : DCX_WINDOW
));
922 vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
923 &arrowSize
, &thumbSize
, &thumbPos
);
924 hwndOwner
= (nBar
== SB_CTL
) ? GetParent(hwnd
) : hwnd
;
925 hwndCtl
= (nBar
== SB_CTL
) ? hwnd
: 0;
929 case WM_LBUTTONDOWN
: /* Initialise mouse tracking */
930 HideCaret(hwnd
); /* hide caret while holding down LBUTTON */
931 SCROLL_trackVertical
= vertical
;
932 SCROLL_trackHitTest
= hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, FALSE
);
933 lastClickPos
= vertical
? (pt
.y
- rect
.top
) : (pt
.x
- rect
.left
);
934 lastMousePos
= lastClickPos
;
935 trackThumbPos
= thumbPos
;
937 if (nBar
== SB_CTL
&& (GetWindowLongA(hwnd
, GWL_STYLE
) & WS_TABSTOP
)) SetFocus( hwnd
);
942 hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, TRUE
);
947 hittest
= SCROLL_NOWHERE
;
949 /* if scrollbar has focus, show back caret */
950 if (hwnd
==GetFocus()) ShowCaret(hwnd
);
955 hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, FALSE
);
959 return; /* Should never happen */
962 TRACE("Event: hwnd=%04x bar=%d msg=%s pt=%ld,%ld hit=%d\n",
963 hwnd
, nBar
, SPY_GetMsgName(msg
,hwnd
), pt
.x
, pt
.y
, hittest
);
965 switch(SCROLL_trackHitTest
)
967 case SCROLL_NOWHERE
: /* No tracking in progress */
970 case SCROLL_TOP_ARROW
:
971 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
972 (hittest
== SCROLL_trackHitTest
), FALSE
);
973 if (hittest
== SCROLL_trackHitTest
)
975 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
977 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
978 SB_LINEUP
, (LPARAM
)hwndCtl
);
981 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
982 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
985 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
988 case SCROLL_TOP_RECT
:
989 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
990 thumbPos
, infoPtr
->flags
, vertical
,
991 (hittest
== SCROLL_trackHitTest
), FALSE
);
992 if (hittest
== SCROLL_trackHitTest
)
994 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
996 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
997 SB_PAGEUP
, (LPARAM
)hwndCtl
);
999 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
1000 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
1003 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
1007 if (msg
== WM_LBUTTONDOWN
)
1009 SCROLL_TrackingWin
= hwnd
;
1010 SCROLL_TrackingBar
= nBar
;
1011 SCROLL_TrackingPos
= trackThumbPos
+ lastMousePos
- lastClickPos
;
1012 if (!SCROLL_MovingThumb
)
1013 SCROLL_DrawMovingThumb(hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
1015 else if (msg
== WM_LBUTTONUP
)
1017 if (SCROLL_MovingThumb
)
1018 SCROLL_DrawMovingThumb(hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
1019 SCROLL_TrackingWin
= 0;
1020 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
1021 thumbPos
, infoPtr
->flags
, vertical
,
1024 else /* WM_MOUSEMOVE */
1028 if (!SCROLL_PtInRectEx( &rect
, pt
, vertical
)) pos
= lastClickPos
;
1031 pt
= SCROLL_ClipPos( &rect
, pt
);
1032 pos
= vertical
? (pt
.y
- rect
.top
) : (pt
.x
- rect
.left
);
1034 if ( (pos
!= lastMousePos
) || (!SCROLL_MovingThumb
) )
1036 if (SCROLL_MovingThumb
)
1037 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
,
1038 arrowSize
, thumbSize
);
1040 SCROLL_TrackingPos
= trackThumbPos
+ pos
- lastClickPos
;
1041 SCROLL_TrackingVal
= SCROLL_GetThumbVal( infoPtr
, &rect
,
1043 SCROLL_TrackingPos
);
1044 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1045 MAKEWPARAM( SB_THUMBTRACK
, SCROLL_TrackingVal
),
1047 if (!SCROLL_MovingThumb
)
1048 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
,
1049 arrowSize
, thumbSize
);
1054 case SCROLL_BOTTOM_RECT
:
1055 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
1056 thumbPos
, infoPtr
->flags
, vertical
,
1057 FALSE
, (hittest
== SCROLL_trackHitTest
) );
1058 if (hittest
== SCROLL_trackHitTest
)
1060 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
1062 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1063 SB_PAGEDOWN
, (LPARAM
)hwndCtl
);
1065 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
1066 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
1069 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
1072 case SCROLL_BOTTOM_ARROW
:
1073 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
1074 FALSE
, (hittest
== SCROLL_trackHitTest
) );
1075 if (hittest
== SCROLL_trackHitTest
)
1077 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
1079 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1080 SB_LINEDOWN
, (LPARAM
)hwndCtl
);
1083 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
1084 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
1087 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
1091 if (msg
== WM_LBUTTONUP
)
1093 hittest
= SCROLL_trackHitTest
;
1094 SCROLL_trackHitTest
= SCROLL_NOWHERE
; /* Terminate tracking */
1096 if (hittest
== SCROLL_THUMB
)
1098 UINT val
= SCROLL_GetThumbVal( infoPtr
, &rect
, vertical
,
1099 trackThumbPos
+ lastMousePos
- lastClickPos
);
1100 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1101 MAKEWPARAM( SB_THUMBPOSITION
, val
), (LPARAM
)hwndCtl
);
1104 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1105 SB_ENDSCROLL
, (LPARAM
)hwndCtl
);
1108 ReleaseDC( hwnd
, hdc
);
1112 /***********************************************************************
1115 static LRESULT WINAPI
ScrollBarWndProc( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1117 if (!IsWindow( hwnd
)) return 0;
1123 CREATESTRUCTW
*lpCreat
= (CREATESTRUCTW
*)lParam
;
1124 if (lpCreat
->style
& SBS_SIZEBOX
)
1126 FIXME("Unimplemented style SBS_SIZEBOX.\n" );
1129 if (lpCreat
->style
& SBS_VERT
)
1131 if (lpCreat
->style
& SBS_LEFTALIGN
)
1132 MoveWindow( hwnd
, lpCreat
->x
, lpCreat
->y
,
1133 GetSystemMetrics(SM_CXVSCROLL
)+1, lpCreat
->cy
, FALSE
);
1134 else if (lpCreat
->style
& SBS_RIGHTALIGN
)
1136 lpCreat
->x
+lpCreat
->cx
-GetSystemMetrics(SM_CXVSCROLL
)-1,
1138 GetSystemMetrics(SM_CXVSCROLL
)+1, lpCreat
->cy
, FALSE
);
1142 if (lpCreat
->style
& SBS_TOPALIGN
)
1143 MoveWindow( hwnd
, lpCreat
->x
, lpCreat
->y
,
1144 lpCreat
->cx
, GetSystemMetrics(SM_CYHSCROLL
)+1, FALSE
);
1145 else if (lpCreat
->style
& SBS_BOTTOMALIGN
)
1148 lpCreat
->y
+lpCreat
->cy
-GetSystemMetrics(SM_CYHSCROLL
)-1,
1149 lpCreat
->cx
, GetSystemMetrics(SM_CYHSCROLL
)+1, FALSE
);
1152 if (!hUpArrow
) SCROLL_LoadBitmaps();
1153 TRACE("ScrollBar creation, hwnd=%04x\n", hwnd
);
1156 case WM_LBUTTONDOWN
:
1161 pt
.x
= SLOWORD(lParam
);
1162 pt
.y
= SHIWORD(lParam
);
1164 SCROLL_HandleScrollEvent( hwnd
, SB_CTL
, message
, pt
);
1166 TRACE("Doing LBUTTONDOWN loop hwnd=%08x\n", hwnd
);
1168 if (!GetMessageW( &msg
, 0, 0, 0 )) break;
1169 if (CallMsgFilterW( &msg
, MSGF_SCROLLBAR
)) continue;
1175 pt
.x
= LOWORD(msg
.lParam
);
1176 pt
.y
= HIWORD(msg
.lParam
);
1177 SCROLL_HandleScrollEvent( hwnd
, SB_CTL
, msg
.message
, pt
);
1180 TranslateMessage( &msg
);
1181 DispatchMessageW( &msg
);
1184 if (!IsWindow( hwnd
))
1189 } while (msg
.message
!= WM_LBUTTONUP
);
1190 TRACE("Out ofLBUTTON loop hwnd=%08x\n", hwnd
);
1198 pt
.x
= SLOWORD(lParam
);
1199 pt
.y
= SHIWORD(lParam
);
1200 SCROLL_HandleScrollEvent( hwnd
, SB_CTL
, message
, pt
);
1204 /* if key event is received, the scrollbar has the focus */
1206 /* hide caret on first KEYDOWN to prevent flicker */
1207 if ((lParam
& 0x40000000)==0)
1209 SCROLL_HandleKbdEvent( hwnd
, wParam
);
1218 /* Create a caret when a ScrollBar get focus */
1220 int arrowSize
, thumbSize
, thumbPos
, vertical
;
1221 vertical
= SCROLL_GetScrollBarRect( hwnd
, SB_CTL
, &rect
,
1222 &arrowSize
, &thumbSize
, &thumbPos
);
1225 CreateCaret(hwnd
,1, thumbSize
-2, rect
.bottom
-rect
.top
-2);
1226 SetCaretPos(thumbPos
+1, rect
.top
+1);
1230 CreateCaret(hwnd
,1, rect
.right
-rect
.left
-2,thumbSize
-2);
1231 SetCaretPos(rect
.top
+1, thumbPos
+1);
1240 int arrowSize
, thumbSize
, thumbPos
, vertical
;
1241 vertical
= SCROLL_GetScrollBarRect( hwnd
, SB_CTL
, &rect
,&arrowSize
, &thumbSize
, &thumbPos
);
1243 rect
.left
=thumbPos
+1;
1244 rect
.right
=rect
.left
+thumbSize
;
1248 rect
.top
=thumbPos
+1;
1249 rect
.bottom
=rect
.top
+thumbSize
;
1252 InvalidateRect(hwnd
,&rect
,0);
1261 return DLGC_WANTARROWS
; /* Windows returns this value */
1266 HDC hdc
= BeginPaint( hwnd
, &ps
);
1267 SCROLL_DrawScrollBar( hwnd
, hdc
, SB_CTL
, TRUE
, TRUE
);
1268 EndPaint( hwnd
, &ps
);
1274 return SetScrollPos( hwnd
, SB_CTL
, wParam
, (BOOL
)lParam
);
1278 return GetScrollPos( hwnd
, SB_CTL
);
1280 case SBM_SETRANGE16
:
1281 SetScrollRange( hwnd
, SB_CTL
, LOWORD(lParam
), HIWORD(lParam
),
1282 wParam
/* FIXME: Is this correct? */ );
1287 INT oldPos
= GetScrollPos( hwnd
, SB_CTL
);
1288 SetScrollRange( hwnd
, SB_CTL
, wParam
, lParam
, FALSE
);
1289 if (oldPos
!= GetScrollPos( hwnd
, SB_CTL
)) return oldPos
;
1293 case SBM_GETRANGE16
:
1294 FIXME("don't know how to handle SBM_GETRANGE16 (wp=%04x,lp=%08lx)\n", wParam
, lParam
);
1298 GetScrollRange( hwnd
, SB_CTL
, (LPINT
)wParam
, (LPINT
)lParam
);
1301 case SBM_ENABLE_ARROWS16
:
1302 case SBM_ENABLE_ARROWS
:
1303 return EnableScrollBar( hwnd
, SB_CTL
, wParam
);
1305 case SBM_SETRANGEREDRAW
:
1307 INT oldPos
= GetScrollPos( hwnd
, SB_CTL
);
1308 SetScrollRange( hwnd
, SB_CTL
, wParam
, lParam
, TRUE
);
1309 if (oldPos
!= GetScrollPos( hwnd
, SB_CTL
)) return oldPos
;
1313 case SBM_SETSCROLLINFO
:
1314 return SetScrollInfo( hwnd
, SB_CTL
, (SCROLLINFO
*)lParam
, wParam
);
1316 case SBM_GETSCROLLINFO
:
1317 return GetScrollInfo( hwnd
, SB_CTL
, (SCROLLINFO
*)lParam
);
1327 ERR("unknown Win32 msg %04x wp=%08x lp=%08lx\n",
1328 message
, wParam
, lParam
);
1332 if (message
>= WM_USER
)
1333 WARN("unknown msg %04x wp=%04x lp=%08lx\n",
1334 message
, wParam
, lParam
);
1335 return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1341 /*************************************************************************
1342 * SetScrollInfo (USER32.@)
1343 * SetScrollInfo can be used to set the position, upper bound,
1344 * lower bound, and page size of a scrollbar control.
1347 * Scrollbar position
1350 * For 100 lines of text to be displayed in a window of 25 lines,
1351 * one would for instance use info->nMin=0, info->nMax=75
1352 * (corresponding to the 76 different positions of the window on
1353 * the text), and info->nPage=25.
1355 INT WINAPI
SetScrollInfo(
1356 HWND hwnd
/* [in] Handle of window whose scrollbar will be affected */,
1357 INT nBar
/* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1358 const SCROLLINFO
*info
/* [in] Specifies what to change and new values */,
1359 BOOL bRedraw
/* [in] Should scrollbar be redrawn afterwards ? */)
1362 INT retVal
= SCROLL_SetScrollInfo( hwnd
, nBar
, info
, &action
);
1364 if( action
& SA_SSI_HIDE
)
1365 SCROLL_ShowScrollBar( hwnd
, nBar
, FALSE
, FALSE
);
1368 if( action
& SA_SSI_SHOW
)
1369 if( SCROLL_ShowScrollBar( hwnd
, nBar
, TRUE
, TRUE
) )
1370 return retVal
; /* SetWindowPos() already did the painting */
1372 if( bRedraw
&& (action
& SA_SSI_REFRESH
))
1373 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, TRUE
);
1374 else if( action
& SA_SSI_REPAINT_ARROWS
)
1375 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, FALSE
);
1380 INT
SCROLL_SetScrollInfo( HWND hwnd
, INT nBar
,
1381 const SCROLLINFO
*info
, INT
*action
)
1383 /* Update the scrollbar state and set action flags according to
1384 * what has to be done graphics wise. */
1386 SCROLLBAR_INFO
*infoPtr
;
1388 BOOL bChangeParams
= FALSE
; /* don't show/hide scrollbar if params don't change */
1392 if (!(infoPtr
= SCROLL_GetScrollInfo(hwnd
, nBar
))) return 0;
1393 if (info
->fMask
& ~(SIF_ALL
| SIF_DISABLENOSCROLL
)) return 0;
1394 if ((info
->cbSize
!= sizeof(*info
)) &&
1395 (info
->cbSize
!= sizeof(*info
)-sizeof(info
->nTrackPos
))) return 0;
1397 if (TRACE_ON(scroll
))
1399 TRACE("hwnd=%04x bar=%d", hwnd
, nBar
);
1400 if (info
->fMask
& SIF_PAGE
) DPRINTF( " page=%d", info
->nPage
);
1401 if (info
->fMask
& SIF_POS
) DPRINTF( " pos=%d", info
->nPos
);
1402 if (info
->fMask
& SIF_RANGE
) DPRINTF( " min=%d max=%d", info
->nMin
, info
->nMax
);
1406 /* Set the page size */
1408 if (info
->fMask
& SIF_PAGE
)
1410 if( infoPtr
->Page
!= info
->nPage
)
1412 infoPtr
->Page
= info
->nPage
;
1413 *action
|= SA_SSI_REFRESH
;
1414 bChangeParams
= TRUE
;
1418 /* Set the scroll pos */
1420 if (info
->fMask
& SIF_POS
)
1422 if( infoPtr
->CurVal
!= info
->nPos
)
1424 infoPtr
->CurVal
= info
->nPos
;
1425 *action
|= SA_SSI_REFRESH
;
1429 /* Set the scroll range */
1431 if (info
->fMask
& SIF_RANGE
)
1433 /* Invalid range -> range is set to (0,0) */
1434 if ((info
->nMin
> info
->nMax
) ||
1435 ((UINT
)(info
->nMax
- info
->nMin
) >= 0x80000000))
1437 infoPtr
->MinVal
= 0;
1438 infoPtr
->MaxVal
= 0;
1439 bChangeParams
= TRUE
;
1443 if( infoPtr
->MinVal
!= info
->nMin
||
1444 infoPtr
->MaxVal
!= info
->nMax
)
1446 *action
|= SA_SSI_REFRESH
;
1447 infoPtr
->MinVal
= info
->nMin
;
1448 infoPtr
->MaxVal
= info
->nMax
;
1449 bChangeParams
= TRUE
;
1454 /* Make sure the page size is valid */
1456 if (infoPtr
->Page
< 0) infoPtr
->Page
= 0;
1457 else if (infoPtr
->Page
> infoPtr
->MaxVal
- infoPtr
->MinVal
+ 1 )
1458 infoPtr
->Page
= infoPtr
->MaxVal
- infoPtr
->MinVal
+ 1;
1460 /* Make sure the pos is inside the range */
1462 if (infoPtr
->CurVal
< infoPtr
->MinVal
)
1463 infoPtr
->CurVal
= infoPtr
->MinVal
;
1464 else if (infoPtr
->CurVal
> infoPtr
->MaxVal
- max( infoPtr
->Page
-1, 0 ))
1465 infoPtr
->CurVal
= infoPtr
->MaxVal
- max( infoPtr
->Page
-1, 0 );
1467 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1468 infoPtr
->Page
, infoPtr
->CurVal
,
1469 infoPtr
->MinVal
, infoPtr
->MaxVal
);
1471 /* don't change the scrollbar state if SetScrollInfo
1472 * is just called with SIF_DISABLENOSCROLL
1474 if(!(info
->fMask
& SIF_ALL
)) goto done
;
1476 /* Check if the scrollbar should be hidden or disabled */
1478 if (info
->fMask
& (SIF_RANGE
| SIF_PAGE
| SIF_DISABLENOSCROLL
))
1480 new_flags
= infoPtr
->flags
;
1481 if (infoPtr
->MinVal
>= infoPtr
->MaxVal
- max( infoPtr
->Page
-1, 0 ))
1483 /* Hide or disable scroll-bar */
1484 if (info
->fMask
& SIF_DISABLENOSCROLL
)
1486 new_flags
= ESB_DISABLE_BOTH
;
1487 *action
|= SA_SSI_REFRESH
;
1489 else if ((nBar
!= SB_CTL
) && bChangeParams
)
1491 *action
= SA_SSI_HIDE
;
1495 else /* Show and enable scroll-bar */
1498 if ((nBar
!= SB_CTL
) && bChangeParams
)
1499 *action
|= SA_SSI_SHOW
;
1502 if (infoPtr
->flags
!= new_flags
) /* check arrow flags */
1504 infoPtr
->flags
= new_flags
;
1505 *action
|= SA_SSI_REPAINT_ARROWS
;
1510 /* Return current position */
1512 return infoPtr
->CurVal
;
1516 /*************************************************************************
1517 * GetScrollInfo (USER32.@)
1518 * GetScrollInfo can be used to retrieve the position, upper bound,
1519 * lower bound, and page size of a scrollbar control.
1523 BOOL WINAPI
GetScrollInfo(
1524 HWND hwnd
/* [in] Handle of window */ ,
1525 INT nBar
/* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1526 LPSCROLLINFO info
/* [in/out] (info.fMask [in] specifies which values are to retrieve) */)
1528 SCROLLBAR_INFO
*infoPtr
;
1530 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return FALSE
;
1531 if (info
->fMask
& ~(SIF_ALL
| SIF_DISABLENOSCROLL
)) return FALSE
;
1532 if ((info
->cbSize
!= sizeof(*info
)) &&
1533 (info
->cbSize
!= sizeof(*info
)-sizeof(info
->nTrackPos
))) return FALSE
;
1535 if (info
->fMask
& SIF_PAGE
) info
->nPage
= infoPtr
->Page
;
1536 if (info
->fMask
& SIF_POS
) info
->nPos
= infoPtr
->CurVal
;
1537 if ((info
->fMask
& SIF_TRACKPOS
) && (info
->cbSize
== sizeof(*info
)))
1538 info
->nTrackPos
= (SCROLL_TrackingWin
== WIN_GetFullHandle(hwnd
)) ? SCROLL_TrackingVal
: infoPtr
->CurVal
;
1539 if (info
->fMask
& SIF_RANGE
)
1541 info
->nMin
= infoPtr
->MinVal
;
1542 info
->nMax
= infoPtr
->MaxVal
;
1544 return (info
->fMask
& SIF_ALL
) != 0;
1548 /*************************************************************************
1549 * SetScrollPos (USER32.@)
1552 * Success: Scrollbar position
1556 * Note the ambiguity when 0 is returned. Use GetLastError
1557 * to make sure there was an error (and to know which one).
1559 INT WINAPI
SetScrollPos(
1560 HWND hwnd
/* [in] Handle of window whose scrollbar will be affected */,
1561 INT nBar
/* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1562 INT nPos
/* [in] New value */,
1563 BOOL bRedraw
/* [in] Should scrollbar be redrawn afterwards ? */ )
1566 SCROLLBAR_INFO
*infoPtr
;
1569 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return 0;
1570 oldPos
= infoPtr
->CurVal
;
1571 info
.cbSize
= sizeof(info
);
1573 info
.fMask
= SIF_POS
;
1574 SetScrollInfo( hwnd
, nBar
, &info
, bRedraw
);
1579 /*************************************************************************
1580 * GetScrollPos (USER32.@)
1583 * Success: Current position
1587 * Note the ambiguity when 0 is returned. Use GetLastError
1588 * to make sure there was an error (and to know which one).
1590 INT WINAPI
GetScrollPos(
1591 HWND hwnd
, /* [in] Handle of window */
1592 INT nBar
/* [in] One of SB_HORZ, SB_VERT, or SB_CTL */)
1594 SCROLLBAR_INFO
*infoPtr
;
1596 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return 0;
1597 return infoPtr
->CurVal
;
1601 /*************************************************************************
1602 * SetScrollRange (USER32.@)
1606 BOOL WINAPI
SetScrollRange(
1607 HWND hwnd
, /* [in] Handle of window whose scrollbar will be affected */
1608 INT nBar
, /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */
1609 INT MinVal
, /* [in] New minimum value */
1610 INT MaxVal
, /* [in] New maximum value */
1611 BOOL bRedraw
/* [in] Should scrollbar be redrawn afterwards ? */)
1615 info
.cbSize
= sizeof(info
);
1618 info
.fMask
= SIF_RANGE
;
1619 SetScrollInfo( hwnd
, nBar
, &info
, bRedraw
);
1624 /*************************************************************************
1625 * SCROLL_SetNCSbState
1627 * Updates both scrollbars at the same time. Used by MDI CalcChildScroll().
1629 INT
SCROLL_SetNCSbState(HWND hwnd
, int vMin
, int vMax
, int vPos
,
1630 int hMin
, int hMax
, int hPos
)
1633 SCROLLINFO vInfo
, hInfo
;
1635 vInfo
.cbSize
= hInfo
.cbSize
= sizeof(SCROLLINFO
);
1642 vInfo
.fMask
= hInfo
.fMask
= SIF_RANGE
| SIF_POS
;
1644 SCROLL_SetScrollInfo( hwnd
, SB_VERT
, &vInfo
, &vA
);
1645 SCROLL_SetScrollInfo( hwnd
, SB_HORZ
, &hInfo
, &hA
);
1647 if( !SCROLL_ShowScrollBar( hwnd
, SB_BOTH
,
1648 (hA
& SA_SSI_SHOW
),(vA
& SA_SSI_SHOW
) ) )
1650 /* SetWindowPos() wasn't called, just redraw the scrollbars if needed */
1651 if( vA
& SA_SSI_REFRESH
)
1652 SCROLL_RefreshScrollBar( hwnd
, SB_VERT
, FALSE
, TRUE
);
1654 if( hA
& SA_SSI_REFRESH
)
1655 SCROLL_RefreshScrollBar( hwnd
, SB_HORZ
, FALSE
, TRUE
);
1661 /*************************************************************************
1662 * GetScrollRange (USER32.@)
1666 BOOL WINAPI
GetScrollRange(
1667 HWND hwnd
, /* [in] Handle of window */
1668 INT nBar
, /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */
1669 LPINT lpMin
, /* [out] Where to store minimum value */
1670 LPINT lpMax
/* [out] Where to store maximum value */)
1672 SCROLLBAR_INFO
*infoPtr
;
1674 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
)))
1676 if (lpMin
) lpMin
= 0;
1677 if (lpMax
) lpMax
= 0;
1680 if (lpMin
) *lpMin
= infoPtr
->MinVal
;
1681 if (lpMax
) *lpMax
= infoPtr
->MaxVal
;
1686 /*************************************************************************
1687 * SCROLL_ShowScrollBar()
1689 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1691 BOOL
SCROLL_ShowScrollBar( HWND hwnd
, INT nBar
,
1692 BOOL fShowH
, BOOL fShowV
)
1694 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
1695 BOOL retvalue
= FALSE
;
1697 if (!wndPtr
) return FALSE
;
1698 TRACE("hwnd=%04x bar=%d horz=%d, vert=%d\n",
1699 hwnd
, nBar
, fShowH
, fShowV
);
1704 ShowWindow( hwnd
, fShowH
? SW_SHOW
: SW_HIDE
);
1712 fShowH
= !(wndPtr
->dwStyle
& WS_HSCROLL
);
1713 wndPtr
->dwStyle
|= WS_HSCROLL
;
1717 fShowH
= (wndPtr
->dwStyle
& WS_HSCROLL
);
1718 wndPtr
->dwStyle
&= ~WS_HSCROLL
;
1720 if( nBar
== SB_HORZ
) {
1729 fShowV
= !(wndPtr
->dwStyle
& WS_VSCROLL
);
1730 wndPtr
->dwStyle
|= WS_VSCROLL
;
1734 fShowV
= (wndPtr
->dwStyle
& WS_VSCROLL
);
1735 wndPtr
->dwStyle
&= ~WS_VSCROLL
;
1737 if ( nBar
== SB_VERT
)
1742 retvalue
= FALSE
; /* Nothing to do! */
1746 if( fShowH
|| fShowV
) /* frame has been changed, let the window redraw itself */
1748 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
1749 | SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
1754 retvalue
= FALSE
; /* no frame changes */
1756 WIN_ReleaseWndPtr(wndPtr
);
1761 /*************************************************************************
1762 * ShowScrollBar (USER32.@)
1766 BOOL WINAPI
ShowScrollBar(
1767 HWND hwnd
, /* [in] Handle of window whose scrollbar(s) will be affected */
1768 INT nBar
, /* [in] One of SB_HORZ, SB_VERT, SB_BOTH or SB_CTL */
1769 BOOL fShow
/* [in] TRUE = show, FALSE = hide */)
1771 SCROLL_ShowScrollBar( hwnd
, nBar
, (nBar
== SB_VERT
) ? 0 : fShow
,
1772 (nBar
== SB_HORZ
) ? 0 : fShow
);
1777 /*************************************************************************
1778 * EnableScrollBar (USER32.@)
1780 BOOL WINAPI
EnableScrollBar( HWND hwnd
, INT nBar
, UINT flags
)
1783 SCROLLBAR_INFO
*infoPtr
;
1785 TRACE("%04x %d %d\n", hwnd
, nBar
, flags
);
1787 flags
&= ESB_DISABLE_BOTH
;
1789 if (nBar
== SB_BOTH
)
1791 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, SB_VERT
))) return FALSE
;
1792 if (!(bFineWithMe
= (infoPtr
->flags
== flags
)) )
1794 infoPtr
->flags
= flags
;
1795 SCROLL_RefreshScrollBar( hwnd
, SB_VERT
, TRUE
, TRUE
);
1802 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return FALSE
;
1803 if (bFineWithMe
&& infoPtr
->flags
== flags
) return FALSE
;
1804 infoPtr
->flags
= flags
;
1806 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, TRUE
);