4 * Copyright 1993 Martin Ayotte
5 * Copyright 1994, 1996 Alexandre Julliard
10 #include "wine/winuser16.h"
14 #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_GetPtrScrollInfo
150 static SCROLLBAR_INFO
*SCROLL_GetPtrScrollInfo( WND
* wndPtr
, INT nBar
)
152 SCROLLBAR_INFO
*infoPtr
;
154 if (!wndPtr
) return NULL
;
157 case SB_HORZ
: infoPtr
= (SCROLLBAR_INFO
*)wndPtr
->pHScroll
; break;
158 case SB_VERT
: infoPtr
= (SCROLLBAR_INFO
*)wndPtr
->pVScroll
; break;
159 case SB_CTL
: infoPtr
= (SCROLLBAR_INFO
*)wndPtr
->wExtra
; break;
160 default: return NULL
;
163 if (!infoPtr
) /* Create the info structure if needed */
165 if ((infoPtr
= HeapAlloc( SystemHeap
, 0, sizeof(SCROLLBAR_INFO
) )))
167 infoPtr
->MinVal
= infoPtr
->CurVal
= infoPtr
->Page
= 0;
168 infoPtr
->MaxVal
= 100;
169 infoPtr
->flags
= ESB_ENABLE_BOTH
;
170 if (nBar
== SB_HORZ
) wndPtr
->pHScroll
= infoPtr
;
171 else wndPtr
->pVScroll
= infoPtr
;
173 if (!hUpArrow
) SCROLL_LoadBitmaps();
179 /***********************************************************************
180 * SCROLL_GetScrollInfo
182 static SCROLLBAR_INFO
*SCROLL_GetScrollInfo( HWND hwnd
, INT nBar
)
184 SCROLLBAR_INFO
*retvalue
;
185 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
186 retvalue
= SCROLL_GetPtrScrollInfo( wndPtr
, nBar
);
187 WIN_ReleaseWndPtr(wndPtr
);
192 /***********************************************************************
193 * SCROLL_GetScrollBarRect
195 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
196 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
197 * 'arrowSize' returns the width or height of an arrow (depending on
198 * the orientation of the scrollbar), 'thumbSize' returns the size of
199 * the thumb, and 'thumbPos' returns the position of the thumb
200 * relative to the left or to the top.
201 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
203 static BOOL
SCROLL_GetScrollBarRect( HWND hwnd
, INT nBar
, RECT
*lprect
,
204 INT
*arrowSize
, INT
*thumbSize
,
209 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
214 lprect
->left
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
215 lprect
->top
= wndPtr
->rectClient
.bottom
- wndPtr
->rectWindow
.top
;
216 lprect
->right
= wndPtr
->rectClient
.right
- wndPtr
->rectWindow
.left
;
217 lprect
->bottom
= lprect
->top
+ GetSystemMetrics(SM_CYHSCROLL
);
218 if(wndPtr
->dwStyle
& WS_BORDER
) {
221 } else if(wndPtr
->dwStyle
& WS_VSCROLL
)
227 lprect
->left
= wndPtr
->rectClient
.right
- wndPtr
->rectWindow
.left
;
228 lprect
->top
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
229 lprect
->right
= lprect
->left
+ GetSystemMetrics(SM_CXVSCROLL
);
230 lprect
->bottom
= wndPtr
->rectClient
.bottom
- wndPtr
->rectWindow
.top
;
231 if(wndPtr
->dwStyle
& WS_BORDER
) {
234 } else if(wndPtr
->dwStyle
& WS_HSCROLL
)
240 GetClientRect( hwnd
, lprect
);
241 vertical
= ((wndPtr
->dwStyle
& SBS_VERT
) != 0);
245 WIN_ReleaseWndPtr(wndPtr
);
249 if (vertical
) pixels
= lprect
->bottom
- lprect
->top
;
250 else pixels
= lprect
->right
- lprect
->left
;
252 if (pixels
<= 2*GetSystemMetrics(SM_CXVSCROLL
) + SCROLL_MIN_RECT
)
254 if (pixels
> SCROLL_MIN_RECT
)
255 *arrowSize
= (pixels
- SCROLL_MIN_RECT
) / 2;
258 *thumbPos
= *thumbSize
= 0;
262 SCROLLBAR_INFO
*info
= SCROLL_GetPtrScrollInfo( wndPtr
, nBar
);
264 *arrowSize
= GetSystemMetrics(SM_CXVSCROLL
);
265 pixels
-= (2 * (GetSystemMetrics(SM_CXVSCROLL
) - SCROLL_ARROW_THUMB_OVERLAP
));
269 *thumbSize
= pixels
* info
->Page
/ (info
->MaxVal
-info
->MinVal
+1);
270 if (*thumbSize
< SCROLL_MIN_THUMB
) *thumbSize
= SCROLL_MIN_THUMB
;
272 else *thumbSize
= GetSystemMetrics(SM_CXVSCROLL
);
274 if (((pixels
-= *thumbSize
) < 0) ||
275 ((info
->flags
& ESB_DISABLE_BOTH
) == ESB_DISABLE_BOTH
))
277 /* Rectangle too small or scrollbar disabled -> no thumb */
278 *thumbPos
= *thumbSize
= 0;
282 INT max
= info
->MaxVal
- max( info
->Page
-1, 0 );
283 if (info
->MinVal
>= max
)
284 *thumbPos
= *arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
286 *thumbPos
= *arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
287 + pixels
* (info
->CurVal
-info
->MinVal
) / (max
- info
->MinVal
);
290 WIN_ReleaseWndPtr(wndPtr
);
295 /***********************************************************************
298 * Compute the current scroll position based on the thumb position in pixels
299 * from the top of the scroll-bar.
301 static UINT
SCROLL_GetThumbVal( SCROLLBAR_INFO
*infoPtr
, RECT
*rect
,
302 BOOL vertical
, INT pos
)
305 INT pixels
= vertical
? rect
->bottom
-rect
->top
: rect
->right
-rect
->left
;
307 if ((pixels
-= 2*(GetSystemMetrics(SM_CXVSCROLL
) - SCROLL_ARROW_THUMB_OVERLAP
)) <= 0)
308 return infoPtr
->MinVal
;
312 thumbSize
= pixels
* infoPtr
->Page
/(infoPtr
->MaxVal
-infoPtr
->MinVal
+1);
313 if (thumbSize
< SCROLL_MIN_THUMB
) thumbSize
= SCROLL_MIN_THUMB
;
315 else thumbSize
= GetSystemMetrics(SM_CXVSCROLL
);
317 if ((pixels
-= thumbSize
) <= 0) return infoPtr
->MinVal
;
319 pos
= max( 0, pos
- (GetSystemMetrics(SM_CXVSCROLL
) - SCROLL_ARROW_THUMB_OVERLAP
) );
320 if (pos
> pixels
) pos
= pixels
;
322 if (!infoPtr
->Page
) pos
*= infoPtr
->MaxVal
- infoPtr
->MinVal
;
323 else pos
*= infoPtr
->MaxVal
- infoPtr
->MinVal
- infoPtr
->Page
+ 1;
324 return infoPtr
->MinVal
+ ((pos
+ pixels
/ 2) / pixels
);
327 /***********************************************************************
330 static BOOL
SCROLL_PtInRectEx( LPRECT lpRect
, POINT pt
, BOOL vertical
)
336 rect
.left
-= lpRect
->right
- lpRect
->left
;
337 rect
.right
+= lpRect
->right
- lpRect
->left
;
341 rect
.top
-= lpRect
->bottom
- lpRect
->top
;
342 rect
.bottom
+= lpRect
->bottom
- lpRect
->top
;
344 return PtInRect( &rect
, pt
);
347 /***********************************************************************
350 static POINT
SCROLL_ClipPos( LPRECT lpRect
, POINT pt
)
352 if( pt
.x
< lpRect
->left
)
355 if( pt
.x
> lpRect
->right
)
356 pt
.x
= lpRect
->right
;
358 if( pt
.y
< lpRect
->top
)
361 if( pt
.y
> lpRect
->bottom
)
362 pt
.y
= lpRect
->bottom
;
368 /***********************************************************************
371 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
373 static enum SCROLL_HITTEST
SCROLL_HitTest( HWND hwnd
, INT nBar
,
374 POINT pt
, BOOL bDragging
)
376 INT arrowSize
, thumbSize
, thumbPos
;
379 BOOL vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
380 &arrowSize
, &thumbSize
, &thumbPos
);
382 if ( (bDragging
&& !SCROLL_PtInRectEx( &rect
, pt
, vertical
)) ||
383 (!PtInRect( &rect
, pt
)) ) return SCROLL_NOWHERE
;
387 if (pt
.y
< rect
.top
+ arrowSize
) return SCROLL_TOP_ARROW
;
388 if (pt
.y
>= rect
.bottom
- arrowSize
) return SCROLL_BOTTOM_ARROW
;
389 if (!thumbPos
) return SCROLL_TOP_RECT
;
391 if (pt
.y
< thumbPos
) return SCROLL_TOP_RECT
;
392 if (pt
.y
>= thumbPos
+ thumbSize
) return SCROLL_BOTTOM_RECT
;
394 else /* horizontal */
396 if (pt
.x
< rect
.left
+ arrowSize
) return SCROLL_TOP_ARROW
;
397 if (pt
.x
>= rect
.right
- arrowSize
) return SCROLL_BOTTOM_ARROW
;
398 if (!thumbPos
) return SCROLL_TOP_RECT
;
400 if (pt
.x
< thumbPos
) return SCROLL_TOP_RECT
;
401 if (pt
.x
>= thumbPos
+ thumbSize
) return SCROLL_BOTTOM_RECT
;
407 /***********************************************************************
410 * Draw the scroll bar arrows.
412 static void SCROLL_DrawArrows_9x( HDC hdc
, SCROLLBAR_INFO
*infoPtr
,
413 RECT
*rect
, INT arrowSize
, BOOL vertical
,
414 BOOL top_pressed
, BOOL bottom_pressed
)
420 r
.bottom
= r
.top
+ arrowSize
;
422 r
.right
= r
.left
+ arrowSize
;
424 DrawFrameControl( hdc
, &r
, DFC_SCROLL
,
425 (vertical
? DFCS_SCROLLUP
: DFCS_SCROLLLEFT
)
426 | (top_pressed
? (DFCS_PUSHED
| DFCS_FLAT
) : 0 )
427 | (infoPtr
->flags
&ESB_DISABLE_LTUP
? DFCS_INACTIVE
: 0 ) );
431 r
.top
= r
.bottom
-arrowSize
;
433 r
.left
= r
.right
-arrowSize
;
435 DrawFrameControl( hdc
, &r
, DFC_SCROLL
,
436 (vertical
? DFCS_SCROLLDOWN
: DFCS_SCROLLRIGHT
)
437 | (bottom_pressed
? (DFCS_PUSHED
| DFCS_FLAT
) : 0 )
438 | (infoPtr
->flags
&ESB_DISABLE_RTDN
? DFCS_INACTIVE
: 0) );
441 static void SCROLL_DrawArrows_31( HDC hdc
, SCROLLBAR_INFO
*infoPtr
,
442 RECT
*rect
, INT arrowSize
, BOOL vertical
,
443 BOOL top_pressed
, BOOL bottom_pressed
)
445 HDC hdcMem
= CreateCompatibleDC( hdc
);
446 HBITMAP hbmpPrev
= SelectObject( hdcMem
, vertical
?
447 TOP_ARROW(infoPtr
->flags
, top_pressed
)
448 : LEFT_ARROW(infoPtr
->flags
, top_pressed
));
450 SetStretchBltMode( hdc
, STRETCH_DELETESCANS
);
451 StretchBlt( hdc
, rect
->left
, rect
->top
,
452 vertical
? rect
->right
-rect
->left
: arrowSize
,
453 vertical
? arrowSize
: rect
->bottom
-rect
->top
,
455 GetSystemMetrics(SM_CXVSCROLL
),GetSystemMetrics(SM_CYHSCROLL
),
458 SelectObject( hdcMem
, vertical
?
459 BOTTOM_ARROW( infoPtr
->flags
, bottom_pressed
)
460 : RIGHT_ARROW( infoPtr
->flags
, bottom_pressed
) );
462 StretchBlt( hdc
, rect
->left
, rect
->bottom
- arrowSize
,
463 rect
->right
- rect
->left
, arrowSize
,
465 GetSystemMetrics(SM_CXVSCROLL
),GetSystemMetrics(SM_CYHSCROLL
),
468 StretchBlt( hdc
, rect
->right
- arrowSize
, rect
->top
,
469 arrowSize
, rect
->bottom
- rect
->top
,
471 GetSystemMetrics(SM_CXVSCROLL
), GetSystemMetrics(SM_CYHSCROLL
),
473 SelectObject( hdcMem
, hbmpPrev
);
477 static void SCROLL_DrawArrows( HDC hdc
, SCROLLBAR_INFO
*infoPtr
,
478 RECT
*rect
, INT arrowSize
, BOOL vertical
,
479 BOOL top_pressed
, BOOL bottom_pressed
)
481 if( TWEAK_WineLook
== WIN31_LOOK
)
482 SCROLL_DrawArrows_31( hdc
, infoPtr
, rect
, arrowSize
,
483 vertical
, top_pressed
,bottom_pressed
);
485 SCROLL_DrawArrows_9x( hdc
, infoPtr
, rect
, arrowSize
,
486 vertical
, top_pressed
,bottom_pressed
);
490 /***********************************************************************
491 * SCROLL_DrawMovingThumb
493 * Draw the moving thumb rectangle.
495 static void SCROLL_DrawMovingThumb_31( HDC hdc
, RECT
*rect
, BOOL vertical
,
496 INT arrowSize
, INT thumbSize
)
501 r
.top
+= SCROLL_TrackingPos
;
502 if (r
.top
< rect
->top
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
503 r
.top
= rect
->top
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
504 if (r
.top
+ thumbSize
>
505 rect
->bottom
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
))
506 r
.top
= rect
->bottom
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
508 r
.bottom
= r
.top
+ thumbSize
;
512 r
.left
+= SCROLL_TrackingPos
;
513 if (r
.left
< rect
->left
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
514 r
.left
= rect
->left
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
515 if (r
.left
+ thumbSize
>
516 rect
->right
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
))
517 r
.left
= rect
->right
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
519 r
.right
= r
.left
+ thumbSize
;
522 DrawFocusRect( hdc
, &r
);
523 SCROLL_MovingThumb
= !SCROLL_MovingThumb
;
526 static void SCROLL_DrawMovingThumb_9x( HDC hdc
, RECT
*rect
, BOOL vertical
,
527 INT arrowSize
, INT thumbSize
)
529 INT pos
= SCROLL_TrackingPos
;
533 max_size
= rect
->bottom
- rect
->top
;
535 max_size
= rect
->right
- rect
->left
;
537 max_size
-= (arrowSize
-SCROLL_ARROW_THUMB_OVERLAP
) + thumbSize
;
539 if( pos
< (arrowSize
-SCROLL_ARROW_THUMB_OVERLAP
) )
540 pos
= (arrowSize
-SCROLL_ARROW_THUMB_OVERLAP
);
541 else if( pos
> max_size
)
544 SCROLL_DrawInterior_9x( SCROLL_TrackingWin
, hdc
, SCROLL_TrackingBar
,
545 rect
, arrowSize
, thumbSize
, pos
,
546 0, vertical
, FALSE
, FALSE
);
548 SCROLL_MovingThumb
= !SCROLL_MovingThumb
;
551 static void SCROLL_DrawMovingThumb( HDC hdc
, RECT
*rect
, BOOL vertical
,
552 INT arrowSize
, INT thumbSize
)
554 if( TWEAK_WineLook
== WIN31_LOOK
)
555 SCROLL_DrawMovingThumb_31( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
557 SCROLL_DrawMovingThumb_9x( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
560 /***********************************************************************
561 * SCROLL_DrawInterior
563 * Draw the scroll bar interior (everything except the arrows).
565 static void SCROLL_DrawInterior_9x( HWND hwnd
, HDC hdc
, INT nBar
,
566 RECT
*rect
, INT arrowSize
,
567 INT thumbSize
, INT thumbPos
,
568 UINT flags
, BOOL vertical
,
569 BOOL top_selected
, BOOL bottom_selected
)
573 HBRUSH hSaveBrush
,hBrush
;
575 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
576 * The window-owned scrollbars need to call DEFWND_ControlColor
577 * to correctly setup default scrollbar colors
581 hBrush
= (HBRUSH
)SendMessageA( GetParent(hwnd
), WM_CTLCOLORSCROLLBAR
,
582 (WPARAM
)hdc
,(LPARAM
)hwnd
);
586 hBrush
= DEFWND_ControlColor( hdc
, CTLCOLOR_SCROLLBAR
);
589 hSavePen
= SelectObject( hdc
, GetSysColorPen(COLOR_WINDOWFRAME
) );
590 hSaveBrush
= SelectObject( hdc
, hBrush
);
592 /* Calculate the scroll rectangle */
596 r
.top
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
597 r
.bottom
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
601 r
.left
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
602 r
.right
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
605 /* Draw the scroll rectangles and thumb */
606 if (!thumbPos
) /* No thumb to draw */
608 PatBlt( hdc
, r
.left
, r
.top
,
609 r
.right
- r
.left
, r
.bottom
- r
.top
,
612 /* cleanup and return */
613 SelectObject( hdc
, hSavePen
);
614 SelectObject( hdc
, hSaveBrush
);
620 PatBlt( hdc
, r
.left
, r
.top
,
622 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
),
623 top_selected
? 0x0f0000 : PATCOPY
);
624 r
.top
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
625 PatBlt( hdc
, r
.left
, r
.top
+ thumbSize
,
627 r
.bottom
- r
.top
- thumbSize
,
628 bottom_selected
? 0x0f0000 : PATCOPY
);
629 r
.bottom
= r
.top
+ thumbSize
;
631 else /* horizontal */
633 PatBlt( hdc
, r
.left
, r
.top
,
634 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
),
636 top_selected
? 0x0f0000 : PATCOPY
);
637 r
.left
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
638 PatBlt( hdc
, r
.left
+ thumbSize
, r
.top
,
639 r
.right
- r
.left
- thumbSize
,
641 bottom_selected
? 0x0f0000 : PATCOPY
);
642 r
.right
= r
.left
+ thumbSize
;
646 DrawEdge( hdc
, &r
, EDGE_RAISED
, BF_RECT
| BF_MIDDLE
);
649 SelectObject( hdc
, hSavePen
);
650 SelectObject( hdc
, hSaveBrush
);
654 static void SCROLL_DrawInterior( HWND hwnd
, HDC hdc
, INT nBar
,
655 RECT
*rect
, INT arrowSize
,
656 INT thumbSize
, INT thumbPos
,
657 UINT flags
, BOOL vertical
,
658 BOOL top_selected
, BOOL bottom_selected
)
662 HBRUSH hSaveBrush
,hBrush
;
663 BOOL Save_SCROLL_MovingThumb
= SCROLL_MovingThumb
;
665 if (Save_SCROLL_MovingThumb
&&
666 (SCROLL_TrackingWin
== hwnd
) &&
667 (SCROLL_TrackingBar
== nBar
))
668 SCROLL_DrawMovingThumb( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
670 /* Select the correct brush and pen */
672 if (TWEAK_WineLook
== WIN31_LOOK
&& (flags
& ESB_DISABLE_BOTH
) == ESB_DISABLE_BOTH
)
674 /* This ought to be the color of the parent window */
675 hBrush
= GetSysColorBrush(COLOR_WINDOW
);
679 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
680 * The window-owned scrollbars need to call DEFWND_ControlColor
681 * to correctly setup default scrollbar colors
683 if (nBar
== SB_CTL
) {
684 hBrush
= (HBRUSH
)SendMessageA( GetParent(hwnd
), WM_CTLCOLORSCROLLBAR
,
685 (WPARAM
)hdc
,(LPARAM
)hwnd
);
687 hBrush
= DEFWND_ControlColor( hdc
, CTLCOLOR_SCROLLBAR
);
690 hSavePen
= SelectObject( hdc
, GetSysColorPen(COLOR_WINDOWFRAME
) );
691 hSaveBrush
= SelectObject( hdc
, hBrush
);
693 /* Calculate the scroll rectangle */
698 r
.top
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
699 r
.bottom
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
703 r
.left
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
704 r
.right
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
707 /* Draw the scroll bar frame */
709 /* Only draw outline if Win 3.1. Mar 24, 1999 - Ronald B. Cemer */
710 if (TWEAK_WineLook
== WIN31_LOOK
)
711 Rectangle( hdc
, r
.left
, r
.top
, r
.right
, r
.bottom
);
713 /* Draw the scroll rectangles and thumb */
715 if (!thumbPos
) /* No thumb to draw */
717 INT offset
= (TWEAK_WineLook
> WIN31_LOOK
) ? 0 : 1;
719 PatBlt( hdc
, r
.left
+offset
, r
.top
+offset
,
720 r
.right
- r
.left
- 2*offset
, r
.bottom
- r
.top
- 2*offset
,
723 /* cleanup and return */
724 SelectObject( hdc
, hSavePen
);
725 SelectObject( hdc
, hSaveBrush
);
731 INT offset
= (TWEAK_WineLook
== WIN31_LOOK
) ? 1 : 0;
733 PatBlt( hdc
, r
.left
+ offset
, r
.top
+ offset
,
734 r
.right
- r
.left
- offset
*2,
735 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
) - offset
,
736 top_selected
? 0x0f0000 : PATCOPY
);
737 r
.top
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
738 PatBlt( hdc
, r
.left
+ offset
, r
.top
+ thumbSize
,
739 r
.right
- r
.left
- offset
*2,
740 r
.bottom
- r
.top
- thumbSize
- offset
,
741 bottom_selected
? 0x0f0000 : PATCOPY
);
742 r
.bottom
= r
.top
+ thumbSize
;
744 else /* horizontal */
746 INT offset
= (TWEAK_WineLook
== WIN31_LOOK
) ? 1 : 0;
748 PatBlt( hdc
, r
.left
+ offset
, r
.top
+ offset
,
749 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
),
750 r
.bottom
- r
.top
- offset
*2,
751 top_selected
? 0x0f0000 : PATCOPY
);
752 r
.left
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
753 PatBlt( hdc
, r
.left
+ thumbSize
, r
.top
+ offset
,
754 r
.right
- r
.left
- thumbSize
- offset
,
755 r
.bottom
- r
.top
- offset
*2,
756 bottom_selected
? 0x0f0000 : PATCOPY
);
757 r
.right
= r
.left
+ thumbSize
;
762 SelectObject( hdc
, GetSysColorBrush(COLOR_BTNFACE
) );
763 if (TWEAK_WineLook
== WIN31_LOOK
)
765 Rectangle( hdc
, r
.left
, r
.top
, r
.right
, r
.bottom
);
770 Rectangle( hdc
, r
.left
+1, r
.top
+1, r
.right
-1, r
.bottom
-1 );
772 DrawEdge( hdc
, &r
, EDGE_RAISED
, BF_RECT
);
774 if (Save_SCROLL_MovingThumb
&&
775 (SCROLL_TrackingWin
== hwnd
) &&
776 (SCROLL_TrackingBar
== nBar
))
777 SCROLL_DrawMovingThumb( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
780 SelectObject( hdc
, hSavePen
);
781 SelectObject( hdc
, hSaveBrush
);
785 /***********************************************************************
786 * SCROLL_DrawScrollBar
788 * Redraw the whole scrollbar.
790 void SCROLL_DrawScrollBar( HWND hwnd
, HDC hdc
, INT nBar
,
791 BOOL arrows
, BOOL interior
)
793 INT arrowSize
, thumbSize
, thumbPos
;
796 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
797 SCROLLBAR_INFO
*infoPtr
= SCROLL_GetPtrScrollInfo( wndPtr
, nBar
);
798 BOOL Save_SCROLL_MovingThumb
= SCROLL_MovingThumb
;
800 if (!wndPtr
|| !infoPtr
||
801 ((nBar
== SB_VERT
) && !(wndPtr
->dwStyle
& WS_VSCROLL
)) ||
802 ((nBar
== SB_HORZ
) && !(wndPtr
->dwStyle
& WS_HSCROLL
))) goto END
;
803 if (!WIN_IsWindowDrawable( wndPtr
, FALSE
)) goto END
;
805 vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
806 &arrowSize
, &thumbSize
, &thumbPos
);
808 /* do not draw if the scrollbar rectangle is empty */
809 if(IsRectEmpty(&rect
))
812 if (Save_SCROLL_MovingThumb
&&
813 (SCROLL_TrackingWin
== hwnd
) &&
814 (SCROLL_TrackingBar
== nBar
))
815 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
817 /* Draw the arrows */
819 if (arrows
&& arrowSize
)
821 if( vertical
== SCROLL_trackVertical
&& GetCapture() == hwnd
)
822 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
823 (SCROLL_trackHitTest
== SCROLL_TOP_ARROW
),
824 (SCROLL_trackHitTest
== SCROLL_BOTTOM_ARROW
) );
826 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
830 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
831 thumbPos
, infoPtr
->flags
, vertical
, FALSE
, FALSE
);
833 if (Save_SCROLL_MovingThumb
&&
834 (SCROLL_TrackingWin
== hwnd
) &&
835 (SCROLL_TrackingBar
== nBar
))
836 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
838 /* if scroll bar has focus, reposition the caret*/
839 if(hwnd
==GetFocus() && (nBar
==SB_CTL
))
843 SetCaretPos(thumbPos
+1, rect
.top
+1);
847 SetCaretPos(rect
.top
+1, thumbPos
+1);
852 WIN_ReleaseWndPtr(wndPtr
);
856 /***********************************************************************
857 * SCROLL_RefreshScrollBar
859 * Repaint the scroll bar interior after a SetScrollRange() or
860 * SetScrollPos() call.
862 static void SCROLL_RefreshScrollBar( HWND hwnd
, INT nBar
,
863 BOOL arrows
, BOOL interior
)
865 HDC hdc
= GetDCEx( hwnd
, 0,
866 DCX_CACHE
| ((nBar
== SB_CTL
) ? 0 : DCX_WINDOW
) );
869 SCROLL_DrawScrollBar( hwnd
, hdc
, nBar
, arrows
, interior
);
870 ReleaseDC( hwnd
, hdc
);
874 /***********************************************************************
875 * SCROLL_HandleKbdEvent
877 * Handle a keyboard event (only for SB_CTL scrollbars).
879 static void SCROLL_HandleKbdEvent( HWND hwnd
, WPARAM wParam
)
881 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
886 case VK_PRIOR
: msg
= SB_PAGEUP
; break;
887 case VK_NEXT
: msg
= SB_PAGEDOWN
; break;
888 case VK_HOME
: msg
= SB_TOP
; break;
889 case VK_END
: msg
= SB_BOTTOM
; break;
890 case VK_UP
: msg
= SB_LINEUP
; break;
891 case VK_DOWN
: msg
= SB_LINEDOWN
; break;
893 WIN_ReleaseWndPtr(wndPtr
);
896 SendMessageW( GetParent(hwnd
),
897 (wndPtr
->dwStyle
& SBS_VERT
) ? WM_VSCROLL
: WM_HSCROLL
,
899 WIN_ReleaseWndPtr(wndPtr
);
903 /***********************************************************************
904 * SCROLL_HandleScrollEvent
906 * Handle a mouse or timer event for the scrollbar.
907 * 'pt' is the location of the mouse event in client (for SB_CTL) or
908 * windows coordinates.
910 void SCROLL_HandleScrollEvent( HWND hwnd
, INT nBar
, UINT msg
, POINT pt
)
912 /* Previous mouse position for timer events */
914 /* Thumb position when tracking started. */
915 static UINT trackThumbPos
;
916 /* Position in the scroll-bar of the last button-down event. */
917 static INT lastClickPos
;
918 /* Position in the scroll-bar of the last mouse event. */
919 static INT lastMousePos
;
921 enum SCROLL_HITTEST hittest
;
922 HWND hwndOwner
, hwndCtl
;
924 INT arrowSize
, thumbSize
, thumbPos
;
928 SCROLLBAR_INFO
*infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
);
929 if (!infoPtr
) return;
930 if ((SCROLL_trackHitTest
== SCROLL_NOWHERE
) && (msg
!= WM_LBUTTONDOWN
))
933 hdc
= GetDCEx( hwnd
, 0, DCX_CACHE
| ((nBar
== SB_CTL
) ? 0 : DCX_WINDOW
));
934 vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
935 &arrowSize
, &thumbSize
, &thumbPos
);
936 hwndOwner
= (nBar
== SB_CTL
) ? GetParent(hwnd
) : hwnd
;
937 hwndCtl
= (nBar
== SB_CTL
) ? hwnd
: 0;
941 case WM_LBUTTONDOWN
: /* Initialise mouse tracking */
942 HideCaret(hwnd
); /* hide caret while holding down LBUTTON*/
943 SCROLL_trackVertical
= vertical
;
944 SCROLL_trackHitTest
= hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, FALSE
);
945 lastClickPos
= vertical
? (pt
.y
- rect
.top
) : (pt
.x
- rect
.left
);
946 lastMousePos
= lastClickPos
;
947 trackThumbPos
= thumbPos
;
950 if (nBar
== SB_CTL
&& (GetWindowLongA(hwnd
, GWL_STYLE
) & WS_TABSTOP
)) SetFocus( hwnd
);
954 hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, TRUE
);
959 hittest
= SCROLL_NOWHERE
;
961 /* if scrollbar has focus, show back caret */
962 if (hwnd
==GetFocus()) ShowCaret(hwnd
);
967 hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, FALSE
);
971 return; /* Should never happen */
974 TRACE("Event: hwnd=%04x bar=%d msg=%x pt=%ld,%ld hit=%d\n",
975 hwnd
, nBar
, msg
, pt
.x
, pt
.y
, hittest
);
977 switch(SCROLL_trackHitTest
)
979 case SCROLL_NOWHERE
: /* No tracking in progress */
982 case SCROLL_TOP_ARROW
:
983 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
984 (hittest
== SCROLL_trackHitTest
), FALSE
);
985 if (hittest
== SCROLL_trackHitTest
)
987 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
989 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
990 SB_LINEUP
, hwndCtl
);
993 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
994 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
997 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
1000 case SCROLL_TOP_RECT
:
1001 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
1002 thumbPos
, infoPtr
->flags
, vertical
,
1003 (hittest
== SCROLL_trackHitTest
), FALSE
);
1004 if (hittest
== SCROLL_trackHitTest
)
1006 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
1008 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1009 SB_PAGEUP
, hwndCtl
);
1010 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
1011 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
1015 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
1019 if (msg
== WM_LBUTTONDOWN
)
1021 SCROLL_TrackingWin
= hwnd
;
1022 SCROLL_TrackingBar
= nBar
;
1023 SCROLL_TrackingPos
= trackThumbPos
+ lastMousePos
- lastClickPos
;
1024 if (!SCROLL_MovingThumb
)
1025 SCROLL_DrawMovingThumb(hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
1027 else if (msg
== WM_LBUTTONUP
)
1029 if (SCROLL_MovingThumb
)
1030 SCROLL_DrawMovingThumb(hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
1031 SCROLL_TrackingWin
= 0;
1032 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
1033 thumbPos
, infoPtr
->flags
, vertical
,
1036 else /* WM_MOUSEMOVE */
1040 if (!SCROLL_PtInRectEx( &rect
, pt
, vertical
)) pos
= lastClickPos
;
1043 pt
= SCROLL_ClipPos( &rect
, pt
);
1044 pos
= vertical
? (pt
.y
- rect
.top
) : (pt
.x
- rect
.left
);
1046 if ( (pos
!= lastMousePos
) || (!SCROLL_MovingThumb
) )
1048 if (SCROLL_MovingThumb
)
1049 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
,
1050 arrowSize
, thumbSize
);
1052 SCROLL_TrackingPos
= trackThumbPos
+ pos
- lastClickPos
;
1053 SCROLL_TrackingVal
= SCROLL_GetThumbVal( infoPtr
, &rect
,
1055 SCROLL_TrackingPos
);
1056 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1057 MAKEWPARAM( SB_THUMBTRACK
, SCROLL_TrackingVal
),
1059 if (!SCROLL_MovingThumb
)
1060 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
,
1061 arrowSize
, thumbSize
);
1066 case SCROLL_BOTTOM_RECT
:
1067 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
1068 thumbPos
, infoPtr
->flags
, vertical
,
1069 FALSE
, (hittest
== SCROLL_trackHitTest
) );
1070 if (hittest
== SCROLL_trackHitTest
)
1072 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
1074 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1075 SB_PAGEDOWN
, hwndCtl
);
1076 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
1077 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
1081 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
1084 case SCROLL_BOTTOM_ARROW
:
1085 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
1086 FALSE
, (hittest
== SCROLL_trackHitTest
) );
1087 if (hittest
== SCROLL_trackHitTest
)
1089 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
1091 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1092 SB_LINEDOWN
, hwndCtl
);
1095 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
1096 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
1099 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
1103 if (msg
== WM_LBUTTONUP
)
1105 hittest
= SCROLL_trackHitTest
;
1106 SCROLL_trackHitTest
= SCROLL_NOWHERE
; /* Terminate tracking */
1108 if (hittest
== SCROLL_THUMB
)
1110 UINT val
= SCROLL_GetThumbVal( infoPtr
, &rect
, vertical
,
1111 trackThumbPos
+ lastMousePos
- lastClickPos
);
1112 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1113 MAKEWPARAM( SB_THUMBPOSITION
, val
), hwndCtl
);
1116 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1117 SB_ENDSCROLL
, hwndCtl
);
1120 ReleaseDC( hwnd
, hdc
);
1124 /***********************************************************************
1127 static LRESULT WINAPI
ScrollBarWndProc( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1133 CREATESTRUCTW
*lpCreat
= (CREATESTRUCTW
*)lParam
;
1134 if (lpCreat
->style
& SBS_SIZEBOX
)
1136 FIXME("Unimplemented style SBS_SIZEBOX.\n" );
1139 if (lpCreat
->style
& SBS_VERT
)
1141 if (lpCreat
->style
& SBS_LEFTALIGN
)
1142 MoveWindow( hwnd
, lpCreat
->x
, lpCreat
->y
,
1143 GetSystemMetrics(SM_CXVSCROLL
)+1, lpCreat
->cy
, FALSE
);
1144 else if (lpCreat
->style
& SBS_RIGHTALIGN
)
1146 lpCreat
->x
+lpCreat
->cx
-GetSystemMetrics(SM_CXVSCROLL
)-1,
1148 GetSystemMetrics(SM_CXVSCROLL
)+1, lpCreat
->cy
, FALSE
);
1152 if (lpCreat
->style
& SBS_TOPALIGN
)
1153 MoveWindow( hwnd
, lpCreat
->x
, lpCreat
->y
,
1154 lpCreat
->cx
, GetSystemMetrics(SM_CYHSCROLL
)+1, FALSE
);
1155 else if (lpCreat
->style
& SBS_BOTTOMALIGN
)
1158 lpCreat
->y
+lpCreat
->cy
-GetSystemMetrics(SM_CYHSCROLL
)-1,
1159 lpCreat
->cx
, GetSystemMetrics(SM_CYHSCROLL
)+1, FALSE
);
1162 if (!hUpArrow
) SCROLL_LoadBitmaps();
1163 TRACE("ScrollBar creation, hwnd=%04x\n", hwnd
);
1166 case WM_LBUTTONDOWN
:
1172 pt
.x
= SLOWORD(lParam
);
1173 pt
.y
= SHIWORD(lParam
);
1174 SCROLL_HandleScrollEvent( hwnd
, SB_CTL
, message
, pt
);
1178 /* if key event is received, the scrollbar has the focus*/
1180 /* hide caret on first KEYDOWN to prevent flicker */
1181 if ((lParam
& 0x40000000)==0)
1183 SCROLL_HandleKbdEvent( hwnd
, wParam
);
1192 /* Create a caret when a ScrollBar get focus*/
1194 int arrowSize
, thumbSize
, thumbPos
, vertical
;
1195 vertical
= SCROLL_GetScrollBarRect( hwnd
, SB_CTL
, &rect
,
1196 &arrowSize
, &thumbSize
, &thumbPos
);
1199 CreateCaret(hwnd
,1, thumbSize
-2, rect
.bottom
-rect
.top
-2);
1200 SetCaretPos(thumbPos
+1, rect
.top
+1);
1204 CreateCaret(hwnd
,1, rect
.right
-rect
.left
-2,thumbSize
-2);
1205 SetCaretPos(rect
.top
+1, thumbPos
+1);
1214 int arrowSize
, thumbSize
, thumbPos
, vertical
;
1215 vertical
= SCROLL_GetScrollBarRect( hwnd
, SB_CTL
, &rect
,&arrowSize
, &thumbSize
, &thumbPos
);
1217 rect
.left
=thumbPos
+1;
1218 rect
.right
=rect
.left
+thumbSize
;
1222 rect
.top
=thumbPos
+1;
1223 rect
.bottom
=rect
.top
+thumbSize
;
1226 InvalidateRect(hwnd
,&rect
,0);
1235 return DLGC_WANTARROWS
; /* Windows returns this value */
1240 HDC hdc
= BeginPaint( hwnd
, &ps
);
1241 SCROLL_DrawScrollBar( hwnd
, hdc
, SB_CTL
, TRUE
, TRUE
);
1242 EndPaint( hwnd
, &ps
);
1248 return SetScrollPos( hwnd
, SB_CTL
, wParam
, (BOOL
)lParam
);
1252 return GetScrollPos( hwnd
, SB_CTL
);
1254 case SBM_SETRANGE16
:
1255 SetScrollRange( hwnd
, SB_CTL
, LOWORD(lParam
), HIWORD(lParam
),
1256 wParam
/* FIXME: Is this correct? */ );
1260 SetScrollRange( hwnd
, SB_CTL
, wParam
, lParam
, FALSE
);
1261 return 0; /* FIXME: return previous position */
1263 case SBM_GETRANGE16
:
1264 FIXME("don't know how to handle SBM_GETRANGE16 (wp=%04x,lp=%08lx)\n", wParam
, lParam
);
1268 GetScrollRange( hwnd
, SB_CTL
, (LPINT
)wParam
, (LPINT
)lParam
);
1271 case SBM_ENABLE_ARROWS16
:
1272 case SBM_ENABLE_ARROWS
:
1273 return EnableScrollBar( hwnd
, SB_CTL
, wParam
);
1275 case SBM_SETRANGEREDRAW
:
1276 SetScrollRange( hwnd
, SB_CTL
, wParam
, lParam
, TRUE
);
1277 return 0; /* FIXME: return previous position */
1279 case SBM_SETSCROLLINFO
:
1280 return SetScrollInfo( hwnd
, SB_CTL
, (SCROLLINFO
*)lParam
, wParam
);
1282 case SBM_GETSCROLLINFO
:
1283 return GetScrollInfo( hwnd
, SB_CTL
, (SCROLLINFO
*)lParam
);
1293 ERR("unknown Win32 msg %04x wp=%08x lp=%08lx\n",
1294 message
, wParam
, lParam
);
1298 if (message
>= WM_USER
)
1299 WARN("unknown msg %04x wp=%04x lp=%08lx\n",
1300 message
, wParam
, lParam
);
1301 return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1307 /*************************************************************************
1308 * SetScrollInfo16 (USER.475)
1310 INT16 WINAPI
SetScrollInfo16( HWND16 hwnd
, INT16 nBar
, const SCROLLINFO
*info
,
1313 return (INT16
)SetScrollInfo( hwnd
, nBar
, info
, bRedraw
);
1317 /*************************************************************************
1318 * SetScrollInfo (USER32.@)
1319 * SetScrollInfo can be used to set the position, upper bound,
1320 * lower bound, and page size of a scrollbar control.
1323 * Scrollbar position
1326 * For 100 lines of text to be displayed in a window of 25 lines,
1327 * one would for instance use info->nMin=0, info->nMax=75
1328 * (corresponding to the 76 different positions of the window on
1329 * the text), and info->nPage=25.
1331 INT WINAPI
SetScrollInfo(
1332 HWND hwnd
/* [in] Handle of window whose scrollbar will be affected */,
1333 INT nBar
/* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1334 const SCROLLINFO
*info
/* [in] Specifies what to change and new values */,
1335 BOOL bRedraw
/* [in] Should scrollbar be redrawn afterwards ? */)
1338 INT retVal
= SCROLL_SetScrollInfo( hwnd
, nBar
, info
, &action
);
1340 if( action
& SA_SSI_HIDE
)
1341 SCROLL_ShowScrollBar( hwnd
, nBar
, FALSE
, FALSE
);
1344 if( action
& SA_SSI_SHOW
)
1345 if( SCROLL_ShowScrollBar( hwnd
, nBar
, TRUE
, TRUE
) )
1346 return retVal
; /* SetWindowPos() already did the painting */
1348 if( bRedraw
&& (action
& SA_SSI_REFRESH
))
1349 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, TRUE
);
1350 else if( action
& SA_SSI_REPAINT_ARROWS
)
1351 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, FALSE
);
1356 INT
SCROLL_SetScrollInfo( HWND hwnd
, INT nBar
,
1357 const SCROLLINFO
*info
, INT
*action
)
1359 /* Update the scrollbar state and set action flags according to
1360 * what has to be done graphics wise. */
1362 SCROLLBAR_INFO
*infoPtr
;
1364 BOOL bChangeParams
= FALSE
; /* don't show/hide scrollbar if params don't change */
1368 if (!(infoPtr
= SCROLL_GetScrollInfo(hwnd
, nBar
))) return 0;
1369 if (info
->fMask
& ~(SIF_ALL
| SIF_DISABLENOSCROLL
)) return 0;
1370 if ((info
->cbSize
!= sizeof(*info
)) &&
1371 (info
->cbSize
!= sizeof(*info
)-sizeof(info
->nTrackPos
))) return 0;
1373 if (TRACE_ON(scroll
))
1375 TRACE("hwnd=%04x bar=%d", hwnd
, nBar
);
1376 if (info
->fMask
& SIF_PAGE
) DPRINTF( " page=%d", info
->nPage
);
1377 if (info
->fMask
& SIF_POS
) DPRINTF( " pos=%d", info
->nPos
);
1378 if (info
->fMask
& SIF_RANGE
) DPRINTF( " min=%d max=%d", info
->nMin
, info
->nMax
);
1382 /* Set the page size */
1384 if (info
->fMask
& SIF_PAGE
)
1386 if( infoPtr
->Page
!= info
->nPage
)
1388 infoPtr
->Page
= info
->nPage
;
1389 *action
|= SA_SSI_REFRESH
;
1390 bChangeParams
= TRUE
;
1394 /* Set the scroll pos */
1396 if (info
->fMask
& SIF_POS
)
1398 if( infoPtr
->CurVal
!= info
->nPos
)
1400 infoPtr
->CurVal
= info
->nPos
;
1401 *action
|= SA_SSI_REFRESH
;
1405 /* Set the scroll range */
1407 if (info
->fMask
& SIF_RANGE
)
1409 /* Invalid range -> range is set to (0,0) */
1410 if ((info
->nMin
> info
->nMax
) ||
1411 ((UINT
)(info
->nMax
- info
->nMin
) >= 0x80000000))
1413 infoPtr
->MinVal
= 0;
1414 infoPtr
->MaxVal
= 0;
1415 bChangeParams
= TRUE
;
1419 if( infoPtr
->MinVal
!= info
->nMin
||
1420 infoPtr
->MaxVal
!= info
->nMax
)
1422 *action
|= SA_SSI_REFRESH
;
1423 infoPtr
->MinVal
= info
->nMin
;
1424 infoPtr
->MaxVal
= info
->nMax
;
1425 bChangeParams
= TRUE
;
1430 /* Make sure the page size is valid */
1432 if (infoPtr
->Page
< 0) infoPtr
->Page
= 0;
1433 else if (infoPtr
->Page
> infoPtr
->MaxVal
- infoPtr
->MinVal
+ 1 )
1434 infoPtr
->Page
= infoPtr
->MaxVal
- infoPtr
->MinVal
+ 1;
1436 /* Make sure the pos is inside the range */
1438 if (infoPtr
->CurVal
< infoPtr
->MinVal
)
1439 infoPtr
->CurVal
= infoPtr
->MinVal
;
1440 else if (infoPtr
->CurVal
> infoPtr
->MaxVal
- max( infoPtr
->Page
-1, 0 ))
1441 infoPtr
->CurVal
= infoPtr
->MaxVal
- max( infoPtr
->Page
-1, 0 );
1443 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1444 infoPtr
->Page
, infoPtr
->CurVal
,
1445 infoPtr
->MinVal
, infoPtr
->MaxVal
);
1447 /* don't change the scrollbar state if SetScrollInfo
1448 * is just called with SIF_DISABLENOSCROLL
1450 if(!(info
->fMask
& SIF_ALL
)) goto done
;
1452 /* Check if the scrollbar should be hidden or disabled */
1454 if (info
->fMask
& (SIF_RANGE
| SIF_PAGE
| SIF_DISABLENOSCROLL
))
1456 new_flags
= infoPtr
->flags
;
1457 if (infoPtr
->MinVal
>= infoPtr
->MaxVal
- max( infoPtr
->Page
-1, 0 ))
1459 /* Hide or disable scroll-bar */
1460 if (info
->fMask
& SIF_DISABLENOSCROLL
)
1462 new_flags
= ESB_DISABLE_BOTH
;
1463 *action
|= SA_SSI_REFRESH
;
1465 else if ((nBar
!= SB_CTL
) && bChangeParams
)
1467 *action
= SA_SSI_HIDE
;
1471 else /* Show and enable scroll-bar */
1474 if ((nBar
!= SB_CTL
) && bChangeParams
)
1475 *action
|= SA_SSI_SHOW
;
1478 if (infoPtr
->flags
!= new_flags
) /* check arrow flags */
1480 infoPtr
->flags
= new_flags
;
1481 *action
|= SA_SSI_REPAINT_ARROWS
;
1486 /* Return current position */
1488 return infoPtr
->CurVal
;
1492 /*************************************************************************
1493 * GetScrollInfo16 (USER.476)
1495 BOOL16 WINAPI
GetScrollInfo16( HWND16 hwnd
, INT16 nBar
, LPSCROLLINFO info
)
1497 return GetScrollInfo( hwnd
, nBar
, info
);
1501 /*************************************************************************
1502 * GetScrollInfo (USER32.@)
1503 * GetScrollInfo can be used to retrieve the position, upper bound,
1504 * lower bound, and page size of a scrollbar control.
1508 BOOL WINAPI
GetScrollInfo(
1509 HWND hwnd
/* [in] Handle of window */ ,
1510 INT nBar
/* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1511 LPSCROLLINFO info
/* [in/out] (info.fMask [in] specifies which values are to retrieve) */)
1513 SCROLLBAR_INFO
*infoPtr
;
1515 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return FALSE
;
1516 if (info
->fMask
& ~(SIF_ALL
| SIF_DISABLENOSCROLL
)) return FALSE
;
1517 if ((info
->cbSize
!= sizeof(*info
)) &&
1518 (info
->cbSize
!= sizeof(*info
)-sizeof(info
->nTrackPos
))) return FALSE
;
1520 if (info
->fMask
& SIF_PAGE
) info
->nPage
= infoPtr
->Page
;
1521 if (info
->fMask
& SIF_POS
) info
->nPos
= infoPtr
->CurVal
;
1522 if ((info
->fMask
& SIF_TRACKPOS
) && (info
->cbSize
== sizeof(*info
)))
1523 info
->nTrackPos
= (SCROLL_TrackingWin
==hwnd
) ? SCROLL_TrackingVal
: infoPtr
->CurVal
;
1524 if (info
->fMask
& SIF_RANGE
)
1526 info
->nMin
= infoPtr
->MinVal
;
1527 info
->nMax
= infoPtr
->MaxVal
;
1529 return (info
->fMask
& SIF_ALL
) != 0;
1533 /*************************************************************************
1534 * SetScrollPos16 (USER.62)
1536 INT16 WINAPI
SetScrollPos16( HWND16 hwnd
, INT16 nBar
, INT16 nPos
,
1539 return (INT16
)SetScrollPos( hwnd
, nBar
, nPos
, bRedraw
);
1543 /*************************************************************************
1544 * SetScrollPos (USER32.@)
1547 * Success: Scrollbar position
1551 * Note the ambiguity when 0 is returned. Use GetLastError
1552 * to make sure there was an error (and to know which one).
1554 INT WINAPI
SetScrollPos(
1555 HWND hwnd
/* [in] Handle of window whose scrollbar will be affected */,
1556 INT nBar
/* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1557 INT nPos
/* [in] New value */,
1558 BOOL bRedraw
/* [in] Should scrollbar be redrawn afterwards ? */ )
1561 SCROLLBAR_INFO
*infoPtr
;
1564 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return 0;
1565 oldPos
= infoPtr
->CurVal
;
1566 info
.cbSize
= sizeof(info
);
1568 info
.fMask
= SIF_POS
;
1569 SetScrollInfo( hwnd
, nBar
, &info
, bRedraw
);
1574 /*************************************************************************
1575 * GetScrollPos16 (USER.63)
1577 INT16 WINAPI
GetScrollPos16( HWND16 hwnd
, INT16 nBar
)
1579 return (INT16
)GetScrollPos( hwnd
, nBar
);
1583 /*************************************************************************
1584 * GetScrollPos (USER32.@)
1587 * Success: Current position
1591 * Note the ambiguity when 0 is returned. Use GetLastError
1592 * to make sure there was an error (and to know which one).
1594 INT WINAPI
GetScrollPos(
1595 HWND hwnd
, /* [in] Handle of window */
1596 INT nBar
/* [in] One of SB_HORZ, SB_VERT, or SB_CTL */)
1598 SCROLLBAR_INFO
*infoPtr
;
1600 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return 0;
1601 return infoPtr
->CurVal
;
1605 /*************************************************************************
1606 * SetScrollRange16 (USER.64)
1608 void WINAPI
SetScrollRange16( HWND16 hwnd
, INT16 nBar
,
1609 INT16 MinVal
, INT16 MaxVal
, BOOL16 bRedraw
)
1611 /* Invalid range -> range is set to (0,0) */
1612 if ((INT
)MaxVal
- (INT
)MinVal
> 0x7fff) MinVal
= MaxVal
= 0;
1613 SetScrollRange( hwnd
, nBar
, MinVal
, MaxVal
, bRedraw
);
1617 /*************************************************************************
1618 * SetScrollRange (USER32.@)
1622 BOOL WINAPI
SetScrollRange(
1623 HWND hwnd
, /* [in] Handle of window whose scrollbar will be affected */
1624 INT nBar
, /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */
1625 INT MinVal
, /* [in] New minimum value */
1626 INT MaxVal
, /* [in] New maximum value */
1627 BOOL bRedraw
/* [in] Should scrollbar be redrawn afterwards ? */)
1631 info
.cbSize
= sizeof(info
);
1634 info
.fMask
= SIF_RANGE
;
1635 SetScrollInfo( hwnd
, nBar
, &info
, bRedraw
);
1640 /*************************************************************************
1641 * SCROLL_SetNCSbState
1643 * Updates both scrollbars at the same time. Used by MDI CalcChildScroll().
1645 INT
SCROLL_SetNCSbState(WND
* wndPtr
, int vMin
, int vMax
, int vPos
,
1646 int hMin
, int hMax
, int hPos
)
1649 SCROLLINFO vInfo
, hInfo
;
1651 vInfo
.cbSize
= hInfo
.cbSize
= sizeof(SCROLLINFO
);
1652 vInfo
.nMin
= vMin
; hInfo
.nMin
= hMin
;
1653 vInfo
.nMax
= vMax
; hInfo
.nMax
= hMax
;
1654 vInfo
.nPos
= vPos
; hInfo
.nPos
= hPos
;
1655 vInfo
.fMask
= hInfo
.fMask
= SIF_RANGE
| SIF_POS
;
1657 SCROLL_SetScrollInfo( wndPtr
->hwndSelf
, SB_VERT
, &vInfo
, &vA
);
1658 SCROLL_SetScrollInfo( wndPtr
->hwndSelf
, SB_HORZ
, &hInfo
, &hA
);
1660 if( !SCROLL_ShowScrollBar( wndPtr
->hwndSelf
, SB_BOTH
,
1661 (hA
& SA_SSI_SHOW
),(vA
& SA_SSI_SHOW
) ) )
1663 /* SetWindowPos() wasn't called, just redraw the scrollbars if needed */
1664 if( vA
& SA_SSI_REFRESH
)
1665 SCROLL_RefreshScrollBar( wndPtr
->hwndSelf
, SB_VERT
, FALSE
, TRUE
);
1667 if( hA
& SA_SSI_REFRESH
)
1668 SCROLL_RefreshScrollBar( wndPtr
->hwndSelf
, SB_HORZ
, FALSE
, TRUE
);
1674 /*************************************************************************
1675 * GetScrollRange16 (USER.65)
1677 BOOL16 WINAPI
GetScrollRange16( HWND16 hwnd
, INT16 nBar
,
1678 LPINT16 lpMin
, LPINT16 lpMax
)
1681 BOOL16 ret
= GetScrollRange( hwnd
, nBar
, &min
, &max
);
1682 if (lpMin
) *lpMin
= min
;
1683 if (lpMax
) *lpMax
= max
;
1688 /*************************************************************************
1689 * GetScrollRange (USER32.@)
1693 BOOL WINAPI
GetScrollRange(
1694 HWND hwnd
, /* [in] Handle of window */
1695 INT nBar
, /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */
1696 LPINT lpMin
, /* [out] Where to store minimum value */
1697 LPINT lpMax
/* [out] Where to store maximum value */)
1699 SCROLLBAR_INFO
*infoPtr
;
1701 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
)))
1703 if (lpMin
) lpMin
= 0;
1704 if (lpMax
) lpMax
= 0;
1707 if (lpMin
) *lpMin
= infoPtr
->MinVal
;
1708 if (lpMax
) *lpMax
= infoPtr
->MaxVal
;
1713 /*************************************************************************
1714 * SCROLL_ShowScrollBar()
1716 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1718 BOOL
SCROLL_ShowScrollBar( HWND hwnd
, INT nBar
,
1719 BOOL fShowH
, BOOL fShowV
)
1721 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
1722 BOOL retvalue
= FALSE
;
1724 if (!wndPtr
) return FALSE
;
1725 TRACE("hwnd=%04x bar=%d horz=%d, vert=%d\n",
1726 hwnd
, nBar
, fShowH
, fShowV
);
1731 ShowWindow( hwnd
, fShowH
? SW_SHOW
: SW_HIDE
);
1739 fShowH
= !(wndPtr
->dwStyle
& WS_HSCROLL
);
1740 wndPtr
->dwStyle
|= WS_HSCROLL
;
1744 fShowH
= (wndPtr
->dwStyle
& WS_HSCROLL
);
1745 wndPtr
->dwStyle
&= ~WS_HSCROLL
;
1747 if( nBar
== SB_HORZ
) {
1756 fShowV
= !(wndPtr
->dwStyle
& WS_VSCROLL
);
1757 wndPtr
->dwStyle
|= WS_VSCROLL
;
1761 fShowV
= (wndPtr
->dwStyle
& WS_VSCROLL
);
1762 wndPtr
->dwStyle
&= ~WS_VSCROLL
;
1764 if ( nBar
== SB_VERT
)
1769 retvalue
= FALSE
; /* Nothing to do! */
1773 if( fShowH
|| fShowV
) /* frame has been changed, let the window redraw itself */
1775 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
1776 | SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
1781 retvalue
= FALSE
; /* no frame changes */
1783 WIN_ReleaseWndPtr(wndPtr
);
1788 /*************************************************************************
1789 * ShowScrollBar16 (USER.267)
1791 void WINAPI
ShowScrollBar16( HWND16 hwnd
, INT16 nBar
, BOOL16 fShow
)
1793 SCROLL_ShowScrollBar( hwnd
, nBar
, (nBar
== SB_VERT
) ? 0 : fShow
,
1794 (nBar
== SB_HORZ
) ? 0 : fShow
);
1798 /*************************************************************************
1799 * ShowScrollBar (USER32.@)
1803 BOOL WINAPI
ShowScrollBar(
1804 HWND hwnd
, /* [in] Handle of window whose scrollbar(s) will be affected */
1805 INT nBar
, /* [in] One of SB_HORZ, SB_VERT, SB_BOTH or SB_CTL */
1806 BOOL fShow
/* [in] TRUE = show, FALSE = hide */)
1808 SCROLL_ShowScrollBar( hwnd
, nBar
, (nBar
== SB_VERT
) ? 0 : fShow
,
1809 (nBar
== SB_HORZ
) ? 0 : fShow
);
1814 /*************************************************************************
1815 * EnableScrollBar16 (USER.482)
1817 BOOL16 WINAPI
EnableScrollBar16( HWND16 hwnd
, INT16 nBar
, UINT16 flags
)
1819 return EnableScrollBar( hwnd
, nBar
, flags
);
1823 /*************************************************************************
1824 * EnableScrollBar (USER32.@)
1826 BOOL WINAPI
EnableScrollBar( HWND hwnd
, INT nBar
, UINT flags
)
1829 SCROLLBAR_INFO
*infoPtr
;
1831 TRACE("%04x %d %d\n", hwnd
, nBar
, flags
);
1833 flags
&= ESB_DISABLE_BOTH
;
1835 if (nBar
== SB_BOTH
)
1837 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, SB_VERT
))) return FALSE
;
1838 if (!(bFineWithMe
= (infoPtr
->flags
== flags
)) )
1840 infoPtr
->flags
= flags
;
1841 SCROLL_RefreshScrollBar( hwnd
, SB_VERT
, TRUE
, TRUE
);
1848 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return FALSE
;
1849 if (bFineWithMe
&& infoPtr
->flags
== flags
) return FALSE
;
1850 infoPtr
->flags
= flags
;
1852 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, TRUE
);