4 * Copyright 1993 Martin Ayotte
5 * Copyright 1994, 1996 Alexandre Julliard
10 #include "wine/winuser16.h"
13 #include "debugtools.h"
16 DEFAULT_DEBUG_CHANNEL(scroll
);
20 INT CurVal
; /* Current scroll-bar value */
21 INT MinVal
; /* Minimum scroll-bar value */
22 INT MaxVal
; /* Maximum scroll-bar value */
23 INT Page
; /* Page size of scroll bar (Win32) */
24 UINT flags
; /* EnableScrollBar flags */
28 static HBITMAP hUpArrow
;
29 static HBITMAP hDnArrow
;
30 static HBITMAP hLfArrow
;
31 static HBITMAP hRgArrow
;
32 static HBITMAP hUpArrowD
;
33 static HBITMAP hDnArrowD
;
34 static HBITMAP hLfArrowD
;
35 static HBITMAP hRgArrowD
;
36 static HBITMAP hUpArrowI
;
37 static HBITMAP hDnArrowI
;
38 static HBITMAP hLfArrowI
;
39 static HBITMAP hRgArrowI
;
41 #define TOP_ARROW(flags,pressed) \
42 (((flags)&ESB_DISABLE_UP) ? hUpArrowI : ((pressed) ? hUpArrowD:hUpArrow))
43 #define BOTTOM_ARROW(flags,pressed) \
44 (((flags)&ESB_DISABLE_DOWN) ? hDnArrowI : ((pressed) ? hDnArrowD:hDnArrow))
45 #define LEFT_ARROW(flags,pressed) \
46 (((flags)&ESB_DISABLE_LEFT) ? hLfArrowI : ((pressed) ? hLfArrowD:hLfArrow))
47 #define RIGHT_ARROW(flags,pressed) \
48 (((flags)&ESB_DISABLE_RIGHT) ? hRgArrowI : ((pressed) ? hRgArrowD:hRgArrow))
51 /* Minimum size of the rectangle between the arrows */
52 #define SCROLL_MIN_RECT 4
54 /* Minimum size of the thumb in pixels */
55 #define SCROLL_MIN_THUMB 6
57 /* Overlap between arrows and thumb */
58 #define SCROLL_ARROW_THUMB_OVERLAP ((TWEAK_WineLook == WIN31_LOOK) ? 1 : 0)
60 /* Delay (in ms) before first repetition when holding the button down */
61 #define SCROLL_FIRST_DELAY 200
63 /* Delay (in ms) between scroll repetitions */
64 #define SCROLL_REPEAT_DELAY 50
67 #define SCROLL_TIMER 0
69 /* Scroll-bar hit testing */
72 SCROLL_NOWHERE
, /* Outside the scroll bar */
73 SCROLL_TOP_ARROW
, /* Top or left arrow */
74 SCROLL_TOP_RECT
, /* Rectangle between the top arrow and the thumb */
75 SCROLL_THUMB
, /* Thumb rectangle */
76 SCROLL_BOTTOM_RECT
, /* Rectangle between the thumb and the bottom arrow */
77 SCROLL_BOTTOM_ARROW
/* Bottom or right arrow */
80 /* What to do after SCROLL_SetScrollInfo() */
81 #define SA_SSI_HIDE 0x0001
82 #define SA_SSI_SHOW 0x0002
83 #define SA_SSI_REFRESH 0x0004
84 #define SA_SSI_REPAINT_ARROWS 0x0008
86 /* Thumb-tracking info */
87 static HWND SCROLL_TrackingWin
= 0;
88 static INT SCROLL_TrackingBar
= 0;
89 static INT SCROLL_TrackingPos
= 0;
90 static INT SCROLL_TrackingVal
= 0;
91 /* Hit test code of the last button-down event */
92 static enum SCROLL_HITTEST SCROLL_trackHitTest
;
93 static BOOL SCROLL_trackVertical
;
95 /* Is the moving thumb being displayed? */
96 static BOOL SCROLL_MovingThumb
= FALSE
;
99 static BOOL
SCROLL_ShowScrollBar( HWND hwnd
, INT nBar
,
100 BOOL fShowH
, BOOL fShowV
);
101 static INT
SCROLL_SetScrollInfo( HWND hwnd
, INT nBar
,
102 const SCROLLINFO
*info
, INT
*action
);
103 static void SCROLL_DrawInterior_9x( HWND hwnd
, HDC hdc
, INT nBar
,
104 RECT
*rect
, INT arrowSize
,
105 INT thumbSize
, INT thumbPos
,
106 UINT flags
, BOOL vertical
,
107 BOOL top_selected
, BOOL bottom_selected
);
108 static LRESULT WINAPI
ScrollBarWndProc( HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
111 /*********************************************************************
112 * scrollbar class descriptor
114 const struct builtin_class_descr SCROLL_builtin_class
=
116 "ScrollBar", /* name */
117 CS_GLOBALCLASS
| CS_DBLCLKS
| CS_VREDRAW
| CS_HREDRAW
| CS_PARENTDC
, /* style */
118 NULL
, /* procA (winproc is Unicode only) */
119 ScrollBarWndProc
, /* procW */
120 sizeof(SCROLLBAR_INFO
), /* extra */
121 IDC_ARROWA
, /* cursor */
126 /***********************************************************************
129 static void SCROLL_LoadBitmaps(void)
131 hUpArrow
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROW
) );
132 hDnArrow
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROW
) );
133 hLfArrow
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROW
) );
134 hRgArrow
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROW
) );
135 hUpArrowD
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROWD
) );
136 hDnArrowD
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROWD
) );
137 hLfArrowD
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROWD
) );
138 hRgArrowD
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROWD
) );
139 hUpArrowI
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROWI
) );
140 hDnArrowI
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROWI
) );
141 hLfArrowI
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROWI
) );
142 hRgArrowI
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROWI
) );
146 /***********************************************************************
147 * SCROLL_GetScrollInfo
149 static SCROLLBAR_INFO
*SCROLL_GetScrollInfo( HWND hwnd
, INT nBar
)
151 SCROLLBAR_INFO
*infoPtr
;
152 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
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;
161 WIN_ReleaseWndPtr( wndPtr
);
165 if (!infoPtr
) /* Create the info structure if needed */
167 if ((infoPtr
= HeapAlloc( GetProcessHeap(), 0, sizeof(SCROLLBAR_INFO
) )))
169 infoPtr
->MinVal
= infoPtr
->CurVal
= infoPtr
->Page
= 0;
170 infoPtr
->MaxVal
= 100;
171 infoPtr
->flags
= ESB_ENABLE_BOTH
;
172 if (nBar
== SB_HORZ
) wndPtr
->pHScroll
= infoPtr
;
173 else wndPtr
->pVScroll
= infoPtr
;
175 if (!hUpArrow
) SCROLL_LoadBitmaps();
177 WIN_ReleaseWndPtr( wndPtr
);
182 /***********************************************************************
183 * SCROLL_GetScrollBarRect
185 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
186 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
187 * 'arrowSize' returns the width or height of an arrow (depending on
188 * the orientation of the scrollbar), 'thumbSize' returns the size of
189 * the thumb, and 'thumbPos' returns the position of the thumb
190 * relative to the left or to the top.
191 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
193 static BOOL
SCROLL_GetScrollBarRect( HWND hwnd
, INT nBar
, RECT
*lprect
,
194 INT
*arrowSize
, INT
*thumbSize
,
199 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
204 lprect
->left
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
205 lprect
->top
= wndPtr
->rectClient
.bottom
- wndPtr
->rectWindow
.top
;
206 lprect
->right
= wndPtr
->rectClient
.right
- wndPtr
->rectWindow
.left
;
207 lprect
->bottom
= lprect
->top
+ GetSystemMetrics(SM_CYHSCROLL
);
208 if(wndPtr
->dwStyle
& WS_BORDER
) {
211 } else if(wndPtr
->dwStyle
& WS_VSCROLL
)
217 lprect
->left
= wndPtr
->rectClient
.right
- wndPtr
->rectWindow
.left
;
218 lprect
->top
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
219 lprect
->right
= lprect
->left
+ GetSystemMetrics(SM_CXVSCROLL
);
220 lprect
->bottom
= wndPtr
->rectClient
.bottom
- wndPtr
->rectWindow
.top
;
221 if(wndPtr
->dwStyle
& WS_BORDER
) {
224 } else if(wndPtr
->dwStyle
& WS_HSCROLL
)
230 GetClientRect( hwnd
, lprect
);
231 vertical
= ((wndPtr
->dwStyle
& SBS_VERT
) != 0);
235 WIN_ReleaseWndPtr(wndPtr
);
239 if (vertical
) pixels
= lprect
->bottom
- lprect
->top
;
240 else pixels
= lprect
->right
- lprect
->left
;
242 if (pixels
<= 2*GetSystemMetrics(SM_CXVSCROLL
) + SCROLL_MIN_RECT
)
244 if (pixels
> SCROLL_MIN_RECT
)
245 *arrowSize
= (pixels
- SCROLL_MIN_RECT
) / 2;
248 *thumbPos
= *thumbSize
= 0;
252 SCROLLBAR_INFO
*info
= SCROLL_GetScrollInfo( hwnd
, nBar
);
254 *arrowSize
= GetSystemMetrics(SM_CXVSCROLL
);
255 pixels
-= (2 * (GetSystemMetrics(SM_CXVSCROLL
) - SCROLL_ARROW_THUMB_OVERLAP
));
259 *thumbSize
= pixels
* info
->Page
/ (info
->MaxVal
-info
->MinVal
+1);
260 if (*thumbSize
< SCROLL_MIN_THUMB
) *thumbSize
= SCROLL_MIN_THUMB
;
262 else *thumbSize
= GetSystemMetrics(SM_CXVSCROLL
);
264 if (((pixels
-= *thumbSize
) < 0) ||
265 ((info
->flags
& ESB_DISABLE_BOTH
) == ESB_DISABLE_BOTH
))
267 /* Rectangle too small or scrollbar disabled -> no thumb */
268 *thumbPos
= *thumbSize
= 0;
272 INT max
= info
->MaxVal
- max( info
->Page
-1, 0 );
273 if (info
->MinVal
>= max
)
274 *thumbPos
= *arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
276 *thumbPos
= *arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
277 + pixels
* (info
->CurVal
-info
->MinVal
) / (max
- info
->MinVal
);
280 WIN_ReleaseWndPtr(wndPtr
);
285 /***********************************************************************
288 * Compute the current scroll position based on the thumb position in pixels
289 * from the top of the scroll-bar.
291 static UINT
SCROLL_GetThumbVal( SCROLLBAR_INFO
*infoPtr
, RECT
*rect
,
292 BOOL vertical
, INT pos
)
295 INT pixels
= vertical
? rect
->bottom
-rect
->top
: rect
->right
-rect
->left
;
297 if ((pixels
-= 2*(GetSystemMetrics(SM_CXVSCROLL
) - SCROLL_ARROW_THUMB_OVERLAP
)) <= 0)
298 return infoPtr
->MinVal
;
302 thumbSize
= pixels
* infoPtr
->Page
/(infoPtr
->MaxVal
-infoPtr
->MinVal
+1);
303 if (thumbSize
< SCROLL_MIN_THUMB
) thumbSize
= SCROLL_MIN_THUMB
;
305 else thumbSize
= GetSystemMetrics(SM_CXVSCROLL
);
307 if ((pixels
-= thumbSize
) <= 0) return infoPtr
->MinVal
;
309 pos
= max( 0, pos
- (GetSystemMetrics(SM_CXVSCROLL
) - SCROLL_ARROW_THUMB_OVERLAP
) );
310 if (pos
> pixels
) pos
= pixels
;
312 if (!infoPtr
->Page
) pos
*= infoPtr
->MaxVal
- infoPtr
->MinVal
;
313 else pos
*= infoPtr
->MaxVal
- infoPtr
->MinVal
- infoPtr
->Page
+ 1;
314 return infoPtr
->MinVal
+ ((pos
+ pixels
/ 2) / pixels
);
317 /***********************************************************************
320 static BOOL
SCROLL_PtInRectEx( LPRECT lpRect
, POINT pt
, BOOL vertical
)
326 rect
.left
-= lpRect
->right
- lpRect
->left
;
327 rect
.right
+= lpRect
->right
- lpRect
->left
;
331 rect
.top
-= lpRect
->bottom
- lpRect
->top
;
332 rect
.bottom
+= lpRect
->bottom
- lpRect
->top
;
334 return PtInRect( &rect
, pt
);
337 /***********************************************************************
340 static POINT
SCROLL_ClipPos( LPRECT lpRect
, POINT pt
)
342 if( pt
.x
< lpRect
->left
)
345 if( pt
.x
> lpRect
->right
)
346 pt
.x
= lpRect
->right
;
348 if( pt
.y
< lpRect
->top
)
351 if( pt
.y
> lpRect
->bottom
)
352 pt
.y
= lpRect
->bottom
;
358 /***********************************************************************
361 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
363 static enum SCROLL_HITTEST
SCROLL_HitTest( HWND hwnd
, INT nBar
,
364 POINT pt
, BOOL bDragging
)
366 INT arrowSize
, thumbSize
, thumbPos
;
369 BOOL vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
370 &arrowSize
, &thumbSize
, &thumbPos
);
372 if ( (bDragging
&& !SCROLL_PtInRectEx( &rect
, pt
, vertical
)) ||
373 (!PtInRect( &rect
, pt
)) ) return SCROLL_NOWHERE
;
377 if (pt
.y
< rect
.top
+ arrowSize
) return SCROLL_TOP_ARROW
;
378 if (pt
.y
>= rect
.bottom
- arrowSize
) return SCROLL_BOTTOM_ARROW
;
379 if (!thumbPos
) return SCROLL_TOP_RECT
;
381 if (pt
.y
< thumbPos
) return SCROLL_TOP_RECT
;
382 if (pt
.y
>= thumbPos
+ thumbSize
) return SCROLL_BOTTOM_RECT
;
384 else /* horizontal */
386 if (pt
.x
< rect
.left
+ arrowSize
) return SCROLL_TOP_ARROW
;
387 if (pt
.x
>= rect
.right
- arrowSize
) return SCROLL_BOTTOM_ARROW
;
388 if (!thumbPos
) return SCROLL_TOP_RECT
;
390 if (pt
.x
< thumbPos
) return SCROLL_TOP_RECT
;
391 if (pt
.x
>= thumbPos
+ thumbSize
) return SCROLL_BOTTOM_RECT
;
397 /***********************************************************************
400 * Draw the scroll bar arrows.
402 static void SCROLL_DrawArrows_9x( HDC hdc
, SCROLLBAR_INFO
*infoPtr
,
403 RECT
*rect
, INT arrowSize
, BOOL vertical
,
404 BOOL top_pressed
, BOOL bottom_pressed
)
410 r
.bottom
= r
.top
+ arrowSize
;
412 r
.right
= r
.left
+ arrowSize
;
414 DrawFrameControl( hdc
, &r
, DFC_SCROLL
,
415 (vertical
? DFCS_SCROLLUP
: DFCS_SCROLLLEFT
)
416 | (top_pressed
? (DFCS_PUSHED
| DFCS_FLAT
) : 0 )
417 | (infoPtr
->flags
&ESB_DISABLE_LTUP
? DFCS_INACTIVE
: 0 ) );
421 r
.top
= r
.bottom
-arrowSize
;
423 r
.left
= r
.right
-arrowSize
;
425 DrawFrameControl( hdc
, &r
, DFC_SCROLL
,
426 (vertical
? DFCS_SCROLLDOWN
: DFCS_SCROLLRIGHT
)
427 | (bottom_pressed
? (DFCS_PUSHED
| DFCS_FLAT
) : 0 )
428 | (infoPtr
->flags
&ESB_DISABLE_RTDN
? DFCS_INACTIVE
: 0) );
431 static void SCROLL_DrawArrows_31( HDC hdc
, SCROLLBAR_INFO
*infoPtr
,
432 RECT
*rect
, INT arrowSize
, BOOL vertical
,
433 BOOL top_pressed
, BOOL bottom_pressed
)
435 HDC hdcMem
= CreateCompatibleDC( hdc
);
436 HBITMAP hbmpPrev
= SelectObject( hdcMem
, vertical
?
437 TOP_ARROW(infoPtr
->flags
, top_pressed
)
438 : LEFT_ARROW(infoPtr
->flags
, top_pressed
));
440 SetStretchBltMode( hdc
, STRETCH_DELETESCANS
);
441 StretchBlt( hdc
, rect
->left
, rect
->top
,
442 vertical
? rect
->right
-rect
->left
: arrowSize
,
443 vertical
? arrowSize
: rect
->bottom
-rect
->top
,
445 GetSystemMetrics(SM_CXVSCROLL
),GetSystemMetrics(SM_CYHSCROLL
),
448 SelectObject( hdcMem
, vertical
?
449 BOTTOM_ARROW( infoPtr
->flags
, bottom_pressed
)
450 : RIGHT_ARROW( infoPtr
->flags
, bottom_pressed
) );
452 StretchBlt( hdc
, rect
->left
, rect
->bottom
- arrowSize
,
453 rect
->right
- rect
->left
, arrowSize
,
455 GetSystemMetrics(SM_CXVSCROLL
),GetSystemMetrics(SM_CYHSCROLL
),
458 StretchBlt( hdc
, rect
->right
- arrowSize
, rect
->top
,
459 arrowSize
, rect
->bottom
- rect
->top
,
461 GetSystemMetrics(SM_CXVSCROLL
), GetSystemMetrics(SM_CYHSCROLL
),
463 SelectObject( hdcMem
, hbmpPrev
);
467 static void SCROLL_DrawArrows( HDC hdc
, SCROLLBAR_INFO
*infoPtr
,
468 RECT
*rect
, INT arrowSize
, BOOL vertical
,
469 BOOL top_pressed
, BOOL bottom_pressed
)
471 if( TWEAK_WineLook
== WIN31_LOOK
)
472 SCROLL_DrawArrows_31( hdc
, infoPtr
, rect
, arrowSize
,
473 vertical
, top_pressed
,bottom_pressed
);
475 SCROLL_DrawArrows_9x( hdc
, infoPtr
, rect
, arrowSize
,
476 vertical
, top_pressed
,bottom_pressed
);
480 /***********************************************************************
481 * SCROLL_DrawMovingThumb
483 * Draw the moving thumb rectangle.
485 static void SCROLL_DrawMovingThumb_31( HDC hdc
, RECT
*rect
, BOOL vertical
,
486 INT arrowSize
, INT thumbSize
)
491 r
.top
+= SCROLL_TrackingPos
;
492 if (r
.top
< rect
->top
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
493 r
.top
= rect
->top
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
494 if (r
.top
+ thumbSize
>
495 rect
->bottom
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
))
496 r
.top
= rect
->bottom
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
498 r
.bottom
= r
.top
+ thumbSize
;
502 r
.left
+= SCROLL_TrackingPos
;
503 if (r
.left
< rect
->left
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
504 r
.left
= rect
->left
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
505 if (r
.left
+ thumbSize
>
506 rect
->right
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
))
507 r
.left
= rect
->right
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
509 r
.right
= r
.left
+ thumbSize
;
512 DrawFocusRect( hdc
, &r
);
513 SCROLL_MovingThumb
= !SCROLL_MovingThumb
;
516 static void SCROLL_DrawMovingThumb_9x( HDC hdc
, RECT
*rect
, BOOL vertical
,
517 INT arrowSize
, INT thumbSize
)
519 INT pos
= SCROLL_TrackingPos
;
523 max_size
= rect
->bottom
- rect
->top
;
525 max_size
= rect
->right
- rect
->left
;
527 max_size
-= (arrowSize
-SCROLL_ARROW_THUMB_OVERLAP
) + thumbSize
;
529 if( pos
< (arrowSize
-SCROLL_ARROW_THUMB_OVERLAP
) )
530 pos
= (arrowSize
-SCROLL_ARROW_THUMB_OVERLAP
);
531 else if( pos
> max_size
)
534 SCROLL_DrawInterior_9x( SCROLL_TrackingWin
, hdc
, SCROLL_TrackingBar
,
535 rect
, arrowSize
, thumbSize
, pos
,
536 0, vertical
, FALSE
, FALSE
);
538 SCROLL_MovingThumb
= !SCROLL_MovingThumb
;
541 static void SCROLL_DrawMovingThumb( HDC hdc
, RECT
*rect
, BOOL vertical
,
542 INT arrowSize
, INT thumbSize
)
544 if( TWEAK_WineLook
== WIN31_LOOK
)
545 SCROLL_DrawMovingThumb_31( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
547 SCROLL_DrawMovingThumb_9x( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
550 /***********************************************************************
551 * SCROLL_DrawInterior
553 * Draw the scroll bar interior (everything except the arrows).
555 static void SCROLL_DrawInterior_9x( HWND hwnd
, HDC hdc
, INT nBar
,
556 RECT
*rect
, INT arrowSize
,
557 INT thumbSize
, INT thumbPos
,
558 UINT flags
, BOOL vertical
,
559 BOOL top_selected
, BOOL bottom_selected
)
563 HBRUSH hSaveBrush
,hBrush
;
565 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
566 * The window-owned scrollbars need to call DEFWND_ControlColor
567 * to correctly setup default scrollbar colors
571 hBrush
= (HBRUSH
)SendMessageA( GetParent(hwnd
), WM_CTLCOLORSCROLLBAR
,
572 (WPARAM
)hdc
,(LPARAM
)hwnd
);
576 hBrush
= DEFWND_ControlColor( hdc
, CTLCOLOR_SCROLLBAR
);
579 hSavePen
= SelectObject( hdc
, GetSysColorPen(COLOR_WINDOWFRAME
) );
580 hSaveBrush
= SelectObject( hdc
, hBrush
);
582 /* Calculate the scroll rectangle */
586 r
.top
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
587 r
.bottom
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
591 r
.left
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
592 r
.right
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
595 /* Draw the scroll rectangles and thumb */
596 if (!thumbPos
) /* No thumb to draw */
598 PatBlt( hdc
, r
.left
, r
.top
,
599 r
.right
- r
.left
, r
.bottom
- r
.top
,
602 /* cleanup and return */
603 SelectObject( hdc
, hSavePen
);
604 SelectObject( hdc
, hSaveBrush
);
610 PatBlt( hdc
, r
.left
, r
.top
,
612 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
),
613 top_selected
? 0x0f0000 : PATCOPY
);
614 r
.top
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
615 PatBlt( hdc
, r
.left
, r
.top
+ thumbSize
,
617 r
.bottom
- r
.top
- thumbSize
,
618 bottom_selected
? 0x0f0000 : PATCOPY
);
619 r
.bottom
= r
.top
+ thumbSize
;
621 else /* horizontal */
623 PatBlt( hdc
, r
.left
, r
.top
,
624 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
),
626 top_selected
? 0x0f0000 : PATCOPY
);
627 r
.left
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
628 PatBlt( hdc
, r
.left
+ thumbSize
, r
.top
,
629 r
.right
- r
.left
- thumbSize
,
631 bottom_selected
? 0x0f0000 : PATCOPY
);
632 r
.right
= r
.left
+ thumbSize
;
636 DrawEdge( hdc
, &r
, EDGE_RAISED
, BF_RECT
| BF_MIDDLE
);
639 SelectObject( hdc
, hSavePen
);
640 SelectObject( hdc
, hSaveBrush
);
644 static void SCROLL_DrawInterior( HWND hwnd
, HDC hdc
, INT nBar
,
645 RECT
*rect
, INT arrowSize
,
646 INT thumbSize
, INT thumbPos
,
647 UINT flags
, BOOL vertical
,
648 BOOL top_selected
, BOOL bottom_selected
)
652 HBRUSH hSaveBrush
,hBrush
;
653 BOOL Save_SCROLL_MovingThumb
= SCROLL_MovingThumb
;
655 if (Save_SCROLL_MovingThumb
&&
656 (SCROLL_TrackingWin
== hwnd
) &&
657 (SCROLL_TrackingBar
== nBar
))
658 SCROLL_DrawMovingThumb( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
660 /* Select the correct brush and pen */
662 if (TWEAK_WineLook
== WIN31_LOOK
&& (flags
& ESB_DISABLE_BOTH
) == ESB_DISABLE_BOTH
)
664 /* This ought to be the color of the parent window */
665 hBrush
= GetSysColorBrush(COLOR_WINDOW
);
669 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
670 * The window-owned scrollbars need to call DEFWND_ControlColor
671 * to correctly setup default scrollbar colors
673 if (nBar
== SB_CTL
) {
674 hBrush
= (HBRUSH
)SendMessageA( GetParent(hwnd
), WM_CTLCOLORSCROLLBAR
,
675 (WPARAM
)hdc
,(LPARAM
)hwnd
);
677 hBrush
= DEFWND_ControlColor( hdc
, CTLCOLOR_SCROLLBAR
);
680 hSavePen
= SelectObject( hdc
, GetSysColorPen(COLOR_WINDOWFRAME
) );
681 hSaveBrush
= SelectObject( hdc
, hBrush
);
683 /* Calculate the scroll rectangle */
688 r
.top
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
689 r
.bottom
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
693 r
.left
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
694 r
.right
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
697 /* Draw the scroll bar frame */
699 /* Only draw outline if Win 3.1. Mar 24, 1999 - Ronald B. Cemer */
700 if (TWEAK_WineLook
== WIN31_LOOK
)
701 Rectangle( hdc
, r
.left
, r
.top
, r
.right
, r
.bottom
);
703 /* Draw the scroll rectangles and thumb */
705 if (!thumbPos
) /* No thumb to draw */
707 INT offset
= (TWEAK_WineLook
> WIN31_LOOK
) ? 0 : 1;
709 PatBlt( hdc
, r
.left
+offset
, r
.top
+offset
,
710 r
.right
- r
.left
- 2*offset
, r
.bottom
- r
.top
- 2*offset
,
713 /* cleanup and return */
714 SelectObject( hdc
, hSavePen
);
715 SelectObject( hdc
, hSaveBrush
);
721 INT offset
= (TWEAK_WineLook
== WIN31_LOOK
) ? 1 : 0;
723 PatBlt( hdc
, r
.left
+ offset
, r
.top
+ offset
,
724 r
.right
- r
.left
- offset
*2,
725 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
) - offset
,
726 top_selected
? 0x0f0000 : PATCOPY
);
727 r
.top
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
728 PatBlt( hdc
, r
.left
+ offset
, r
.top
+ thumbSize
,
729 r
.right
- r
.left
- offset
*2,
730 r
.bottom
- r
.top
- thumbSize
- offset
,
731 bottom_selected
? 0x0f0000 : PATCOPY
);
732 r
.bottom
= r
.top
+ thumbSize
;
734 else /* horizontal */
736 INT offset
= (TWEAK_WineLook
== WIN31_LOOK
) ? 1 : 0;
738 PatBlt( hdc
, r
.left
+ offset
, r
.top
+ offset
,
739 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
),
740 r
.bottom
- r
.top
- offset
*2,
741 top_selected
? 0x0f0000 : PATCOPY
);
742 r
.left
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
743 PatBlt( hdc
, r
.left
+ thumbSize
, r
.top
+ offset
,
744 r
.right
- r
.left
- thumbSize
- offset
,
745 r
.bottom
- r
.top
- offset
*2,
746 bottom_selected
? 0x0f0000 : PATCOPY
);
747 r
.right
= r
.left
+ thumbSize
;
752 SelectObject( hdc
, GetSysColorBrush(COLOR_BTNFACE
) );
753 if (TWEAK_WineLook
== WIN31_LOOK
)
755 Rectangle( hdc
, r
.left
, r
.top
, r
.right
, r
.bottom
);
760 Rectangle( hdc
, r
.left
+1, r
.top
+1, r
.right
-1, r
.bottom
-1 );
762 DrawEdge( hdc
, &r
, EDGE_RAISED
, BF_RECT
);
764 if (Save_SCROLL_MovingThumb
&&
765 (SCROLL_TrackingWin
== hwnd
) &&
766 (SCROLL_TrackingBar
== nBar
))
767 SCROLL_DrawMovingThumb( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
770 SelectObject( hdc
, hSavePen
);
771 SelectObject( hdc
, hSaveBrush
);
775 /***********************************************************************
776 * SCROLL_DrawScrollBar
778 * Redraw the whole scrollbar.
780 void SCROLL_DrawScrollBar( HWND hwnd
, HDC hdc
, INT nBar
,
781 BOOL arrows
, BOOL interior
)
783 INT arrowSize
, thumbSize
, thumbPos
;
786 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
787 SCROLLBAR_INFO
*infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
);
788 BOOL Save_SCROLL_MovingThumb
= SCROLL_MovingThumb
;
790 if (!wndPtr
|| !infoPtr
||
791 ((nBar
== SB_VERT
) && !(wndPtr
->dwStyle
& WS_VSCROLL
)) ||
792 ((nBar
== SB_HORZ
) && !(wndPtr
->dwStyle
& WS_HSCROLL
))) goto END
;
793 if (!WIN_IsWindowDrawable( wndPtr
, FALSE
)) goto END
;
794 hwnd
= wndPtr
->hwndSelf
; /* make it a full handle */
796 vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
797 &arrowSize
, &thumbSize
, &thumbPos
);
799 /* do not draw if the scrollbar rectangle is empty */
800 if(IsRectEmpty(&rect
))
803 if (Save_SCROLL_MovingThumb
&&
804 (SCROLL_TrackingWin
== hwnd
) &&
805 (SCROLL_TrackingBar
== nBar
))
806 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
808 /* Draw the arrows */
810 if (arrows
&& arrowSize
)
812 if( vertical
== SCROLL_trackVertical
&& GetCapture() == hwnd
)
813 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
814 (SCROLL_trackHitTest
== SCROLL_TOP_ARROW
),
815 (SCROLL_trackHitTest
== SCROLL_BOTTOM_ARROW
) );
817 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
821 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
822 thumbPos
, infoPtr
->flags
, vertical
, FALSE
, FALSE
);
824 if (Save_SCROLL_MovingThumb
&&
825 (SCROLL_TrackingWin
== hwnd
) &&
826 (SCROLL_TrackingBar
== nBar
))
827 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
829 /* if scroll bar has focus, reposition the caret */
830 if(hwnd
==GetFocus() && (nBar
==SB_CTL
))
834 SetCaretPos(thumbPos
+1, rect
.top
+1);
838 SetCaretPos(rect
.top
+1, thumbPos
+1);
843 WIN_ReleaseWndPtr(wndPtr
);
847 /***********************************************************************
848 * SCROLL_RefreshScrollBar
850 * Repaint the scroll bar interior after a SetScrollRange() or
851 * SetScrollPos() call.
853 static void SCROLL_RefreshScrollBar( HWND hwnd
, INT nBar
,
854 BOOL arrows
, BOOL interior
)
856 HDC hdc
= GetDCEx( hwnd
, 0,
857 DCX_CACHE
| ((nBar
== SB_CTL
) ? 0 : DCX_WINDOW
) );
860 SCROLL_DrawScrollBar( hwnd
, hdc
, nBar
, arrows
, interior
);
861 ReleaseDC( hwnd
, hdc
);
865 /***********************************************************************
866 * SCROLL_HandleKbdEvent
868 * Handle a keyboard event (only for SB_CTL scrollbars).
870 static void SCROLL_HandleKbdEvent( HWND hwnd
, WPARAM wParam
)
876 case VK_PRIOR
: msg
= SB_PAGEUP
; break;
877 case VK_NEXT
: msg
= SB_PAGEDOWN
; break;
878 case VK_HOME
: msg
= SB_TOP
; break;
879 case VK_END
: msg
= SB_BOTTOM
; break;
880 case VK_UP
: msg
= SB_LINEUP
; break;
881 case VK_DOWN
: msg
= SB_LINEDOWN
; break;
884 SendMessageW( GetParent(hwnd
),
885 (GetWindowLongA( hwnd
, GWL_STYLE
) & SBS_VERT
) ? WM_VSCROLL
: WM_HSCROLL
,
890 /***********************************************************************
891 * SCROLL_HandleScrollEvent
893 * Handle a mouse or timer event for the scrollbar.
894 * 'pt' is the location of the mouse event in client (for SB_CTL) or
895 * windows coordinates.
897 void SCROLL_HandleScrollEvent( HWND hwnd
, INT nBar
, UINT msg
, POINT pt
)
899 /* Previous mouse position for timer events */
901 /* Thumb position when tracking started. */
902 static UINT trackThumbPos
;
903 /* Position in the scroll-bar of the last button-down event. */
904 static INT lastClickPos
;
905 /* Position in the scroll-bar of the last mouse event. */
906 static INT lastMousePos
;
908 enum SCROLL_HITTEST hittest
;
909 HWND hwndOwner
, hwndCtl
;
911 INT arrowSize
, thumbSize
, thumbPos
;
915 SCROLLBAR_INFO
*infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
);
916 if (!infoPtr
) return;
917 if ((SCROLL_trackHitTest
== SCROLL_NOWHERE
) && (msg
!= WM_LBUTTONDOWN
))
920 hdc
= GetDCEx( hwnd
, 0, DCX_CACHE
| ((nBar
== SB_CTL
) ? 0 : DCX_WINDOW
));
921 vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
922 &arrowSize
, &thumbSize
, &thumbPos
);
923 hwndOwner
= (nBar
== SB_CTL
) ? GetParent(hwnd
) : hwnd
;
924 hwndCtl
= (nBar
== SB_CTL
) ? hwnd
: 0;
928 case WM_LBUTTONDOWN
: /* Initialise mouse tracking */
929 HideCaret(hwnd
); /* hide caret while holding down LBUTTON */
930 SCROLL_trackVertical
= vertical
;
931 SCROLL_trackHitTest
= hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, FALSE
);
932 lastClickPos
= vertical
? (pt
.y
- rect
.top
) : (pt
.x
- rect
.left
);
933 lastMousePos
= lastClickPos
;
934 trackThumbPos
= thumbPos
;
937 if (nBar
== SB_CTL
&& (GetWindowLongA(hwnd
, GWL_STYLE
) & WS_TABSTOP
)) SetFocus( hwnd
);
941 hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, TRUE
);
946 hittest
= SCROLL_NOWHERE
;
948 /* if scrollbar has focus, show back caret */
949 if (hwnd
==GetFocus()) ShowCaret(hwnd
);
954 hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, FALSE
);
958 return; /* Should never happen */
961 TRACE("Event: hwnd=%04x bar=%d msg=%x pt=%ld,%ld hit=%d\n",
962 hwnd
, nBar
, msg
, pt
.x
, pt
.y
, hittest
);
964 switch(SCROLL_trackHitTest
)
966 case SCROLL_NOWHERE
: /* No tracking in progress */
969 case SCROLL_TOP_ARROW
:
970 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
971 (hittest
== SCROLL_trackHitTest
), FALSE
);
972 if (hittest
== SCROLL_trackHitTest
)
974 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
976 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
977 SB_LINEUP
, hwndCtl
);
980 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
981 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
984 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
987 case SCROLL_TOP_RECT
:
988 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
989 thumbPos
, infoPtr
->flags
, vertical
,
990 (hittest
== SCROLL_trackHitTest
), FALSE
);
991 if (hittest
== SCROLL_trackHitTest
)
993 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
995 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
996 SB_PAGEUP
, hwndCtl
);
998 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
999 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
1002 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
1006 if (msg
== WM_LBUTTONDOWN
)
1008 SCROLL_TrackingWin
= hwnd
;
1009 SCROLL_TrackingBar
= nBar
;
1010 SCROLL_TrackingPos
= trackThumbPos
+ lastMousePos
- lastClickPos
;
1011 if (!SCROLL_MovingThumb
)
1012 SCROLL_DrawMovingThumb(hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
1014 else if (msg
== WM_LBUTTONUP
)
1016 if (SCROLL_MovingThumb
)
1017 SCROLL_DrawMovingThumb(hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
1018 SCROLL_TrackingWin
= 0;
1019 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
1020 thumbPos
, infoPtr
->flags
, vertical
,
1023 else /* WM_MOUSEMOVE */
1027 if (!SCROLL_PtInRectEx( &rect
, pt
, vertical
)) pos
= lastClickPos
;
1030 pt
= SCROLL_ClipPos( &rect
, pt
);
1031 pos
= vertical
? (pt
.y
- rect
.top
) : (pt
.x
- rect
.left
);
1033 if ( (pos
!= lastMousePos
) || (!SCROLL_MovingThumb
) )
1035 if (SCROLL_MovingThumb
)
1036 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
,
1037 arrowSize
, thumbSize
);
1039 SCROLL_TrackingPos
= trackThumbPos
+ pos
- lastClickPos
;
1040 SCROLL_TrackingVal
= SCROLL_GetThumbVal( infoPtr
, &rect
,
1042 SCROLL_TrackingPos
);
1043 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1044 MAKEWPARAM( SB_THUMBTRACK
, SCROLL_TrackingVal
),
1046 if (!SCROLL_MovingThumb
)
1047 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
,
1048 arrowSize
, thumbSize
);
1053 case SCROLL_BOTTOM_RECT
:
1054 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
1055 thumbPos
, infoPtr
->flags
, vertical
,
1056 FALSE
, (hittest
== SCROLL_trackHitTest
) );
1057 if (hittest
== SCROLL_trackHitTest
)
1059 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
1061 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1062 SB_PAGEDOWN
, hwndCtl
);
1064 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
1065 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
1068 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
1071 case SCROLL_BOTTOM_ARROW
:
1072 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
1073 FALSE
, (hittest
== SCROLL_trackHitTest
) );
1074 if (hittest
== SCROLL_trackHitTest
)
1076 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
1078 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1079 SB_LINEDOWN
, hwndCtl
);
1082 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
1083 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
1086 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
1090 if (msg
== WM_LBUTTONUP
)
1092 hittest
= SCROLL_trackHitTest
;
1093 SCROLL_trackHitTest
= SCROLL_NOWHERE
; /* Terminate tracking */
1095 if (hittest
== SCROLL_THUMB
)
1097 UINT val
= SCROLL_GetThumbVal( infoPtr
, &rect
, vertical
,
1098 trackThumbPos
+ lastMousePos
- lastClickPos
);
1099 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1100 MAKEWPARAM( SB_THUMBPOSITION
, val
), hwndCtl
);
1103 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1104 SB_ENDSCROLL
, hwndCtl
);
1107 ReleaseDC( hwnd
, hdc
);
1111 /***********************************************************************
1114 static LRESULT WINAPI
ScrollBarWndProc( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1116 if (!IsWindow( hwnd
)) return 0;
1122 CREATESTRUCTW
*lpCreat
= (CREATESTRUCTW
*)lParam
;
1123 if (lpCreat
->style
& SBS_SIZEBOX
)
1125 FIXME("Unimplemented style SBS_SIZEBOX.\n" );
1128 if (lpCreat
->style
& SBS_VERT
)
1130 if (lpCreat
->style
& SBS_LEFTALIGN
)
1131 MoveWindow( hwnd
, lpCreat
->x
, lpCreat
->y
,
1132 GetSystemMetrics(SM_CXVSCROLL
)+1, lpCreat
->cy
, FALSE
);
1133 else if (lpCreat
->style
& SBS_RIGHTALIGN
)
1135 lpCreat
->x
+lpCreat
->cx
-GetSystemMetrics(SM_CXVSCROLL
)-1,
1137 GetSystemMetrics(SM_CXVSCROLL
)+1, lpCreat
->cy
, FALSE
);
1141 if (lpCreat
->style
& SBS_TOPALIGN
)
1142 MoveWindow( hwnd
, lpCreat
->x
, lpCreat
->y
,
1143 lpCreat
->cx
, GetSystemMetrics(SM_CYHSCROLL
)+1, FALSE
);
1144 else if (lpCreat
->style
& SBS_BOTTOMALIGN
)
1147 lpCreat
->y
+lpCreat
->cy
-GetSystemMetrics(SM_CYHSCROLL
)-1,
1148 lpCreat
->cx
, GetSystemMetrics(SM_CYHSCROLL
)+1, FALSE
);
1151 if (!hUpArrow
) SCROLL_LoadBitmaps();
1152 TRACE("ScrollBar creation, hwnd=%04x\n", hwnd
);
1155 case WM_LBUTTONDOWN
:
1161 pt
.x
= SLOWORD(lParam
);
1162 pt
.y
= SHIWORD(lParam
);
1163 SCROLL_HandleScrollEvent( hwnd
, SB_CTL
, message
, pt
);
1167 /* if key event is received, the scrollbar has the focus */
1169 /* hide caret on first KEYDOWN to prevent flicker */
1170 if ((lParam
& 0x40000000)==0)
1172 SCROLL_HandleKbdEvent( hwnd
, wParam
);
1181 /* Create a caret when a ScrollBar get focus */
1183 int arrowSize
, thumbSize
, thumbPos
, vertical
;
1184 vertical
= SCROLL_GetScrollBarRect( hwnd
, SB_CTL
, &rect
,
1185 &arrowSize
, &thumbSize
, &thumbPos
);
1188 CreateCaret(hwnd
,1, thumbSize
-2, rect
.bottom
-rect
.top
-2);
1189 SetCaretPos(thumbPos
+1, rect
.top
+1);
1193 CreateCaret(hwnd
,1, rect
.right
-rect
.left
-2,thumbSize
-2);
1194 SetCaretPos(rect
.top
+1, thumbPos
+1);
1203 int arrowSize
, thumbSize
, thumbPos
, vertical
;
1204 vertical
= SCROLL_GetScrollBarRect( hwnd
, SB_CTL
, &rect
,&arrowSize
, &thumbSize
, &thumbPos
);
1206 rect
.left
=thumbPos
+1;
1207 rect
.right
=rect
.left
+thumbSize
;
1211 rect
.top
=thumbPos
+1;
1212 rect
.bottom
=rect
.top
+thumbSize
;
1215 InvalidateRect(hwnd
,&rect
,0);
1224 return DLGC_WANTARROWS
; /* Windows returns this value */
1229 HDC hdc
= BeginPaint( hwnd
, &ps
);
1230 SCROLL_DrawScrollBar( hwnd
, hdc
, SB_CTL
, TRUE
, TRUE
);
1231 EndPaint( hwnd
, &ps
);
1237 return SetScrollPos( hwnd
, SB_CTL
, wParam
, (BOOL
)lParam
);
1241 return GetScrollPos( hwnd
, SB_CTL
);
1243 case SBM_SETRANGE16
:
1244 SetScrollRange( hwnd
, SB_CTL
, LOWORD(lParam
), HIWORD(lParam
),
1245 wParam
/* FIXME: Is this correct? */ );
1250 INT oldPos
= GetScrollPos( hwnd
, SB_CTL
);
1251 SetScrollRange( hwnd
, SB_CTL
, wParam
, lParam
, FALSE
);
1252 if (oldPos
!= GetScrollPos( hwnd
, SB_CTL
)) return oldPos
;
1256 case SBM_GETRANGE16
:
1257 FIXME("don't know how to handle SBM_GETRANGE16 (wp=%04x,lp=%08lx)\n", wParam
, lParam
);
1261 GetScrollRange( hwnd
, SB_CTL
, (LPINT
)wParam
, (LPINT
)lParam
);
1264 case SBM_ENABLE_ARROWS16
:
1265 case SBM_ENABLE_ARROWS
:
1266 return EnableScrollBar( hwnd
, SB_CTL
, wParam
);
1268 case SBM_SETRANGEREDRAW
:
1270 INT oldPos
= GetScrollPos( hwnd
, SB_CTL
);
1271 SetScrollRange( hwnd
, SB_CTL
, wParam
, lParam
, TRUE
);
1272 if (oldPos
!= GetScrollPos( hwnd
, SB_CTL
)) return oldPos
;
1276 case SBM_SETSCROLLINFO
:
1277 return SetScrollInfo( hwnd
, SB_CTL
, (SCROLLINFO
*)lParam
, wParam
);
1279 case SBM_GETSCROLLINFO
:
1280 return GetScrollInfo( hwnd
, SB_CTL
, (SCROLLINFO
*)lParam
);
1290 ERR("unknown Win32 msg %04x wp=%08x lp=%08lx\n",
1291 message
, wParam
, lParam
);
1295 if (message
>= WM_USER
)
1296 WARN("unknown msg %04x wp=%04x lp=%08lx\n",
1297 message
, wParam
, lParam
);
1298 return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1304 /*************************************************************************
1305 * SetScrollInfo (USER.475)
1307 INT16 WINAPI
SetScrollInfo16( HWND16 hwnd
, INT16 nBar
, const SCROLLINFO
*info
,
1310 return (INT16
)SetScrollInfo( hwnd
, nBar
, info
, bRedraw
);
1314 /*************************************************************************
1315 * SetScrollInfo (USER32.@)
1316 * SetScrollInfo can be used to set the position, upper bound,
1317 * lower bound, and page size of a scrollbar control.
1320 * Scrollbar position
1323 * For 100 lines of text to be displayed in a window of 25 lines,
1324 * one would for instance use info->nMin=0, info->nMax=75
1325 * (corresponding to the 76 different positions of the window on
1326 * the text), and info->nPage=25.
1328 INT WINAPI
SetScrollInfo(
1329 HWND hwnd
/* [in] Handle of window whose scrollbar will be affected */,
1330 INT nBar
/* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1331 const SCROLLINFO
*info
/* [in] Specifies what to change and new values */,
1332 BOOL bRedraw
/* [in] Should scrollbar be redrawn afterwards ? */)
1335 INT retVal
= SCROLL_SetScrollInfo( hwnd
, nBar
, info
, &action
);
1337 if( action
& SA_SSI_HIDE
)
1338 SCROLL_ShowScrollBar( hwnd
, nBar
, FALSE
, FALSE
);
1341 if( action
& SA_SSI_SHOW
)
1342 if( SCROLL_ShowScrollBar( hwnd
, nBar
, TRUE
, TRUE
) )
1343 return retVal
; /* SetWindowPos() already did the painting */
1345 if( bRedraw
&& (action
& SA_SSI_REFRESH
))
1346 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, TRUE
);
1347 else if( action
& SA_SSI_REPAINT_ARROWS
)
1348 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, FALSE
);
1353 INT
SCROLL_SetScrollInfo( HWND hwnd
, INT nBar
,
1354 const SCROLLINFO
*info
, INT
*action
)
1356 /* Update the scrollbar state and set action flags according to
1357 * what has to be done graphics wise. */
1359 SCROLLBAR_INFO
*infoPtr
;
1361 BOOL bChangeParams
= FALSE
; /* don't show/hide scrollbar if params don't change */
1365 if (!(infoPtr
= SCROLL_GetScrollInfo(hwnd
, nBar
))) return 0;
1366 if (info
->fMask
& ~(SIF_ALL
| SIF_DISABLENOSCROLL
)) return 0;
1367 if ((info
->cbSize
!= sizeof(*info
)) &&
1368 (info
->cbSize
!= sizeof(*info
)-sizeof(info
->nTrackPos
))) return 0;
1370 if (TRACE_ON(scroll
))
1372 TRACE("hwnd=%04x bar=%d", hwnd
, nBar
);
1373 if (info
->fMask
& SIF_PAGE
) DPRINTF( " page=%d", info
->nPage
);
1374 if (info
->fMask
& SIF_POS
) DPRINTF( " pos=%d", info
->nPos
);
1375 if (info
->fMask
& SIF_RANGE
) DPRINTF( " min=%d max=%d", info
->nMin
, info
->nMax
);
1379 /* Set the page size */
1381 if (info
->fMask
& SIF_PAGE
)
1383 if( infoPtr
->Page
!= info
->nPage
)
1385 infoPtr
->Page
= info
->nPage
;
1386 *action
|= SA_SSI_REFRESH
;
1387 bChangeParams
= TRUE
;
1391 /* Set the scroll pos */
1393 if (info
->fMask
& SIF_POS
)
1395 if( infoPtr
->CurVal
!= info
->nPos
)
1397 infoPtr
->CurVal
= info
->nPos
;
1398 *action
|= SA_SSI_REFRESH
;
1402 /* Set the scroll range */
1404 if (info
->fMask
& SIF_RANGE
)
1406 /* Invalid range -> range is set to (0,0) */
1407 if ((info
->nMin
> info
->nMax
) ||
1408 ((UINT
)(info
->nMax
- info
->nMin
) >= 0x80000000))
1410 infoPtr
->MinVal
= 0;
1411 infoPtr
->MaxVal
= 0;
1412 bChangeParams
= TRUE
;
1416 if( infoPtr
->MinVal
!= info
->nMin
||
1417 infoPtr
->MaxVal
!= info
->nMax
)
1419 *action
|= SA_SSI_REFRESH
;
1420 infoPtr
->MinVal
= info
->nMin
;
1421 infoPtr
->MaxVal
= info
->nMax
;
1422 bChangeParams
= TRUE
;
1427 /* Make sure the page size is valid */
1429 if (infoPtr
->Page
< 0) infoPtr
->Page
= 0;
1430 else if (infoPtr
->Page
> infoPtr
->MaxVal
- infoPtr
->MinVal
+ 1 )
1431 infoPtr
->Page
= infoPtr
->MaxVal
- infoPtr
->MinVal
+ 1;
1433 /* Make sure the pos is inside the range */
1435 if (infoPtr
->CurVal
< infoPtr
->MinVal
)
1436 infoPtr
->CurVal
= infoPtr
->MinVal
;
1437 else if (infoPtr
->CurVal
> infoPtr
->MaxVal
- max( infoPtr
->Page
-1, 0 ))
1438 infoPtr
->CurVal
= infoPtr
->MaxVal
- max( infoPtr
->Page
-1, 0 );
1440 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1441 infoPtr
->Page
, infoPtr
->CurVal
,
1442 infoPtr
->MinVal
, infoPtr
->MaxVal
);
1444 /* don't change the scrollbar state if SetScrollInfo
1445 * is just called with SIF_DISABLENOSCROLL
1447 if(!(info
->fMask
& SIF_ALL
)) goto done
;
1449 /* Check if the scrollbar should be hidden or disabled */
1451 if (info
->fMask
& (SIF_RANGE
| SIF_PAGE
| SIF_DISABLENOSCROLL
))
1453 new_flags
= infoPtr
->flags
;
1454 if (infoPtr
->MinVal
>= infoPtr
->MaxVal
- max( infoPtr
->Page
-1, 0 ))
1456 /* Hide or disable scroll-bar */
1457 if (info
->fMask
& SIF_DISABLENOSCROLL
)
1459 new_flags
= ESB_DISABLE_BOTH
;
1460 *action
|= SA_SSI_REFRESH
;
1462 else if ((nBar
!= SB_CTL
) && bChangeParams
)
1464 *action
= SA_SSI_HIDE
;
1468 else /* Show and enable scroll-bar */
1471 if ((nBar
!= SB_CTL
) && bChangeParams
)
1472 *action
|= SA_SSI_SHOW
;
1475 if (infoPtr
->flags
!= new_flags
) /* check arrow flags */
1477 infoPtr
->flags
= new_flags
;
1478 *action
|= SA_SSI_REPAINT_ARROWS
;
1483 /* Return current position */
1485 return infoPtr
->CurVal
;
1489 /*************************************************************************
1490 * GetScrollInfo (USER.476)
1492 BOOL16 WINAPI
GetScrollInfo16( HWND16 hwnd
, INT16 nBar
, LPSCROLLINFO info
)
1494 return GetScrollInfo( hwnd
, nBar
, info
);
1498 /*************************************************************************
1499 * GetScrollInfo (USER32.@)
1500 * GetScrollInfo can be used to retrieve the position, upper bound,
1501 * lower bound, and page size of a scrollbar control.
1505 BOOL WINAPI
GetScrollInfo(
1506 HWND hwnd
/* [in] Handle of window */ ,
1507 INT nBar
/* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1508 LPSCROLLINFO info
/* [in/out] (info.fMask [in] specifies which values are to retrieve) */)
1510 SCROLLBAR_INFO
*infoPtr
;
1512 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return FALSE
;
1513 if (info
->fMask
& ~(SIF_ALL
| SIF_DISABLENOSCROLL
)) return FALSE
;
1514 if ((info
->cbSize
!= sizeof(*info
)) &&
1515 (info
->cbSize
!= sizeof(*info
)-sizeof(info
->nTrackPos
))) return FALSE
;
1517 if (info
->fMask
& SIF_PAGE
) info
->nPage
= infoPtr
->Page
;
1518 if (info
->fMask
& SIF_POS
) info
->nPos
= infoPtr
->CurVal
;
1519 if ((info
->fMask
& SIF_TRACKPOS
) && (info
->cbSize
== sizeof(*info
)))
1520 info
->nTrackPos
= (SCROLL_TrackingWin
== WIN_GetFullHandle(hwnd
)) ? SCROLL_TrackingVal
: infoPtr
->CurVal
;
1521 if (info
->fMask
& SIF_RANGE
)
1523 info
->nMin
= infoPtr
->MinVal
;
1524 info
->nMax
= infoPtr
->MaxVal
;
1526 return (info
->fMask
& SIF_ALL
) != 0;
1530 /*************************************************************************
1531 * SetScrollPos (USER.62)
1533 INT16 WINAPI
SetScrollPos16( HWND16 hwnd
, INT16 nBar
, INT16 nPos
,
1536 return (INT16
)SetScrollPos( hwnd
, nBar
, nPos
, bRedraw
);
1540 /*************************************************************************
1541 * SetScrollPos (USER32.@)
1544 * Success: Scrollbar position
1548 * Note the ambiguity when 0 is returned. Use GetLastError
1549 * to make sure there was an error (and to know which one).
1551 INT WINAPI
SetScrollPos(
1552 HWND hwnd
/* [in] Handle of window whose scrollbar will be affected */,
1553 INT nBar
/* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1554 INT nPos
/* [in] New value */,
1555 BOOL bRedraw
/* [in] Should scrollbar be redrawn afterwards ? */ )
1558 SCROLLBAR_INFO
*infoPtr
;
1561 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return 0;
1562 oldPos
= infoPtr
->CurVal
;
1563 info
.cbSize
= sizeof(info
);
1565 info
.fMask
= SIF_POS
;
1566 SetScrollInfo( hwnd
, nBar
, &info
, bRedraw
);
1571 /*************************************************************************
1572 * GetScrollPos (USER.63)
1574 INT16 WINAPI
GetScrollPos16( HWND16 hwnd
, INT16 nBar
)
1576 return (INT16
)GetScrollPos( hwnd
, nBar
);
1580 /*************************************************************************
1581 * GetScrollPos (USER32.@)
1584 * Success: Current position
1588 * Note the ambiguity when 0 is returned. Use GetLastError
1589 * to make sure there was an error (and to know which one).
1591 INT WINAPI
GetScrollPos(
1592 HWND hwnd
, /* [in] Handle of window */
1593 INT nBar
/* [in] One of SB_HORZ, SB_VERT, or SB_CTL */)
1595 SCROLLBAR_INFO
*infoPtr
;
1597 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return 0;
1598 return infoPtr
->CurVal
;
1602 /*************************************************************************
1603 * SetScrollRange (USER.64)
1605 void WINAPI
SetScrollRange16( HWND16 hwnd
, INT16 nBar
,
1606 INT16 MinVal
, INT16 MaxVal
, BOOL16 bRedraw
)
1608 /* Invalid range -> range is set to (0,0) */
1609 if ((INT
)MaxVal
- (INT
)MinVal
> 0x7fff) MinVal
= MaxVal
= 0;
1610 SetScrollRange( hwnd
, nBar
, MinVal
, MaxVal
, bRedraw
);
1614 /*************************************************************************
1615 * SetScrollRange (USER32.@)
1619 BOOL WINAPI
SetScrollRange(
1620 HWND hwnd
, /* [in] Handle of window whose scrollbar will be affected */
1621 INT nBar
, /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */
1622 INT MinVal
, /* [in] New minimum value */
1623 INT MaxVal
, /* [in] New maximum value */
1624 BOOL bRedraw
/* [in] Should scrollbar be redrawn afterwards ? */)
1628 info
.cbSize
= sizeof(info
);
1631 info
.fMask
= SIF_RANGE
;
1632 SetScrollInfo( hwnd
, nBar
, &info
, bRedraw
);
1637 /*************************************************************************
1638 * SCROLL_SetNCSbState
1640 * Updates both scrollbars at the same time. Used by MDI CalcChildScroll().
1642 INT
SCROLL_SetNCSbState(HWND hwnd
, int vMin
, int vMax
, int vPos
,
1643 int hMin
, int hMax
, int hPos
)
1646 SCROLLINFO vInfo
, hInfo
;
1648 vInfo
.cbSize
= hInfo
.cbSize
= sizeof(SCROLLINFO
);
1655 vInfo
.fMask
= hInfo
.fMask
= SIF_RANGE
| SIF_POS
;
1657 SCROLL_SetScrollInfo( hwnd
, SB_VERT
, &vInfo
, &vA
);
1658 SCROLL_SetScrollInfo( hwnd
, SB_HORZ
, &hInfo
, &hA
);
1660 if( !SCROLL_ShowScrollBar( hwnd
, 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( hwnd
, SB_VERT
, FALSE
, TRUE
);
1667 if( hA
& SA_SSI_REFRESH
)
1668 SCROLL_RefreshScrollBar( hwnd
, SB_HORZ
, FALSE
, TRUE
);
1674 /*************************************************************************
1675 * GetScrollRange (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 * ShowScrollBar (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 * EnableScrollBar (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
);