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_GetPtrScrollInfo
149 static SCROLLBAR_INFO
*SCROLL_GetPtrScrollInfo( WND
* wndPtr
, INT nBar
)
151 SCROLLBAR_INFO
*infoPtr
;
153 if (!wndPtr
) return NULL
;
156 case SB_HORZ
: infoPtr
= (SCROLLBAR_INFO
*)wndPtr
->pHScroll
; break;
157 case SB_VERT
: infoPtr
= (SCROLLBAR_INFO
*)wndPtr
->pVScroll
; break;
158 case SB_CTL
: infoPtr
= (SCROLLBAR_INFO
*)wndPtr
->wExtra
; break;
159 default: return NULL
;
162 if (!infoPtr
) /* Create the info structure if needed */
164 if ((infoPtr
= HeapAlloc( GetProcessHeap(), 0, sizeof(SCROLLBAR_INFO
) )))
166 infoPtr
->MinVal
= infoPtr
->CurVal
= infoPtr
->Page
= 0;
167 infoPtr
->MaxVal
= 100;
168 infoPtr
->flags
= ESB_ENABLE_BOTH
;
169 if (nBar
== SB_HORZ
) wndPtr
->pHScroll
= infoPtr
;
170 else wndPtr
->pVScroll
= infoPtr
;
172 if (!hUpArrow
) SCROLL_LoadBitmaps();
178 /***********************************************************************
179 * SCROLL_GetScrollInfo
181 static SCROLLBAR_INFO
*SCROLL_GetScrollInfo( HWND hwnd
, INT nBar
)
183 SCROLLBAR_INFO
*retvalue
;
184 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
185 retvalue
= SCROLL_GetPtrScrollInfo( wndPtr
, nBar
);
186 WIN_ReleaseWndPtr(wndPtr
);
191 /***********************************************************************
192 * SCROLL_GetScrollBarRect
194 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
195 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
196 * 'arrowSize' returns the width or height of an arrow (depending on
197 * the orientation of the scrollbar), 'thumbSize' returns the size of
198 * the thumb, and 'thumbPos' returns the position of the thumb
199 * relative to the left or to the top.
200 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
202 static BOOL
SCROLL_GetScrollBarRect( HWND hwnd
, INT nBar
, RECT
*lprect
,
203 INT
*arrowSize
, INT
*thumbSize
,
208 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
213 lprect
->left
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
214 lprect
->top
= wndPtr
->rectClient
.bottom
- wndPtr
->rectWindow
.top
;
215 lprect
->right
= wndPtr
->rectClient
.right
- wndPtr
->rectWindow
.left
;
216 lprect
->bottom
= lprect
->top
+ GetSystemMetrics(SM_CYHSCROLL
);
217 if(wndPtr
->dwStyle
& WS_BORDER
) {
220 } else if(wndPtr
->dwStyle
& WS_VSCROLL
)
226 lprect
->left
= wndPtr
->rectClient
.right
- wndPtr
->rectWindow
.left
;
227 lprect
->top
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
228 lprect
->right
= lprect
->left
+ GetSystemMetrics(SM_CXVSCROLL
);
229 lprect
->bottom
= wndPtr
->rectClient
.bottom
- wndPtr
->rectWindow
.top
;
230 if(wndPtr
->dwStyle
& WS_BORDER
) {
233 } else if(wndPtr
->dwStyle
& WS_HSCROLL
)
239 GetClientRect( hwnd
, lprect
);
240 vertical
= ((wndPtr
->dwStyle
& SBS_VERT
) != 0);
244 WIN_ReleaseWndPtr(wndPtr
);
248 if (vertical
) pixels
= lprect
->bottom
- lprect
->top
;
249 else pixels
= lprect
->right
- lprect
->left
;
251 if (pixels
<= 2*GetSystemMetrics(SM_CXVSCROLL
) + SCROLL_MIN_RECT
)
253 if (pixels
> SCROLL_MIN_RECT
)
254 *arrowSize
= (pixels
- SCROLL_MIN_RECT
) / 2;
257 *thumbPos
= *thumbSize
= 0;
261 SCROLLBAR_INFO
*info
= SCROLL_GetPtrScrollInfo( wndPtr
, nBar
);
263 *arrowSize
= GetSystemMetrics(SM_CXVSCROLL
);
264 pixels
-= (2 * (GetSystemMetrics(SM_CXVSCROLL
) - SCROLL_ARROW_THUMB_OVERLAP
));
268 *thumbSize
= pixels
* info
->Page
/ (info
->MaxVal
-info
->MinVal
+1);
269 if (*thumbSize
< SCROLL_MIN_THUMB
) *thumbSize
= SCROLL_MIN_THUMB
;
271 else *thumbSize
= GetSystemMetrics(SM_CXVSCROLL
);
273 if (((pixels
-= *thumbSize
) < 0) ||
274 ((info
->flags
& ESB_DISABLE_BOTH
) == ESB_DISABLE_BOTH
))
276 /* Rectangle too small or scrollbar disabled -> no thumb */
277 *thumbPos
= *thumbSize
= 0;
281 INT max
= info
->MaxVal
- max( info
->Page
-1, 0 );
282 if (info
->MinVal
>= max
)
283 *thumbPos
= *arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
285 *thumbPos
= *arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
286 + pixels
* (info
->CurVal
-info
->MinVal
) / (max
- info
->MinVal
);
289 WIN_ReleaseWndPtr(wndPtr
);
294 /***********************************************************************
297 * Compute the current scroll position based on the thumb position in pixels
298 * from the top of the scroll-bar.
300 static UINT
SCROLL_GetThumbVal( SCROLLBAR_INFO
*infoPtr
, RECT
*rect
,
301 BOOL vertical
, INT pos
)
304 INT pixels
= vertical
? rect
->bottom
-rect
->top
: rect
->right
-rect
->left
;
306 if ((pixels
-= 2*(GetSystemMetrics(SM_CXVSCROLL
) - SCROLL_ARROW_THUMB_OVERLAP
)) <= 0)
307 return infoPtr
->MinVal
;
311 thumbSize
= pixels
* infoPtr
->Page
/(infoPtr
->MaxVal
-infoPtr
->MinVal
+1);
312 if (thumbSize
< SCROLL_MIN_THUMB
) thumbSize
= SCROLL_MIN_THUMB
;
314 else thumbSize
= GetSystemMetrics(SM_CXVSCROLL
);
316 if ((pixels
-= thumbSize
) <= 0) return infoPtr
->MinVal
;
318 pos
= max( 0, pos
- (GetSystemMetrics(SM_CXVSCROLL
) - SCROLL_ARROW_THUMB_OVERLAP
) );
319 if (pos
> pixels
) pos
= pixels
;
321 if (!infoPtr
->Page
) pos
*= infoPtr
->MaxVal
- infoPtr
->MinVal
;
322 else pos
*= infoPtr
->MaxVal
- infoPtr
->MinVal
- infoPtr
->Page
+ 1;
323 return infoPtr
->MinVal
+ ((pos
+ pixels
/ 2) / pixels
);
326 /***********************************************************************
329 static BOOL
SCROLL_PtInRectEx( LPRECT lpRect
, POINT pt
, BOOL vertical
)
335 rect
.left
-= lpRect
->right
- lpRect
->left
;
336 rect
.right
+= lpRect
->right
- lpRect
->left
;
340 rect
.top
-= lpRect
->bottom
- lpRect
->top
;
341 rect
.bottom
+= lpRect
->bottom
- lpRect
->top
;
343 return PtInRect( &rect
, pt
);
346 /***********************************************************************
349 static POINT
SCROLL_ClipPos( LPRECT lpRect
, POINT pt
)
351 if( pt
.x
< lpRect
->left
)
354 if( pt
.x
> lpRect
->right
)
355 pt
.x
= lpRect
->right
;
357 if( pt
.y
< lpRect
->top
)
360 if( pt
.y
> lpRect
->bottom
)
361 pt
.y
= lpRect
->bottom
;
367 /***********************************************************************
370 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
372 static enum SCROLL_HITTEST
SCROLL_HitTest( HWND hwnd
, INT nBar
,
373 POINT pt
, BOOL bDragging
)
375 INT arrowSize
, thumbSize
, thumbPos
;
378 BOOL vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
379 &arrowSize
, &thumbSize
, &thumbPos
);
381 if ( (bDragging
&& !SCROLL_PtInRectEx( &rect
, pt
, vertical
)) ||
382 (!PtInRect( &rect
, pt
)) ) return SCROLL_NOWHERE
;
386 if (pt
.y
< rect
.top
+ arrowSize
) return SCROLL_TOP_ARROW
;
387 if (pt
.y
>= rect
.bottom
- arrowSize
) return SCROLL_BOTTOM_ARROW
;
388 if (!thumbPos
) return SCROLL_TOP_RECT
;
390 if (pt
.y
< thumbPos
) return SCROLL_TOP_RECT
;
391 if (pt
.y
>= thumbPos
+ thumbSize
) return SCROLL_BOTTOM_RECT
;
393 else /* horizontal */
395 if (pt
.x
< rect
.left
+ arrowSize
) return SCROLL_TOP_ARROW
;
396 if (pt
.x
>= rect
.right
- arrowSize
) return SCROLL_BOTTOM_ARROW
;
397 if (!thumbPos
) return SCROLL_TOP_RECT
;
399 if (pt
.x
< thumbPos
) return SCROLL_TOP_RECT
;
400 if (pt
.x
>= thumbPos
+ thumbSize
) return SCROLL_BOTTOM_RECT
;
406 /***********************************************************************
409 * Draw the scroll bar arrows.
411 static void SCROLL_DrawArrows_9x( HDC hdc
, SCROLLBAR_INFO
*infoPtr
,
412 RECT
*rect
, INT arrowSize
, BOOL vertical
,
413 BOOL top_pressed
, BOOL bottom_pressed
)
419 r
.bottom
= r
.top
+ arrowSize
;
421 r
.right
= r
.left
+ arrowSize
;
423 DrawFrameControl( hdc
, &r
, DFC_SCROLL
,
424 (vertical
? DFCS_SCROLLUP
: DFCS_SCROLLLEFT
)
425 | (top_pressed
? (DFCS_PUSHED
| DFCS_FLAT
) : 0 )
426 | (infoPtr
->flags
&ESB_DISABLE_LTUP
? DFCS_INACTIVE
: 0 ) );
430 r
.top
= r
.bottom
-arrowSize
;
432 r
.left
= r
.right
-arrowSize
;
434 DrawFrameControl( hdc
, &r
, DFC_SCROLL
,
435 (vertical
? DFCS_SCROLLDOWN
: DFCS_SCROLLRIGHT
)
436 | (bottom_pressed
? (DFCS_PUSHED
| DFCS_FLAT
) : 0 )
437 | (infoPtr
->flags
&ESB_DISABLE_RTDN
? DFCS_INACTIVE
: 0) );
440 static void SCROLL_DrawArrows_31( HDC hdc
, SCROLLBAR_INFO
*infoPtr
,
441 RECT
*rect
, INT arrowSize
, BOOL vertical
,
442 BOOL top_pressed
, BOOL bottom_pressed
)
444 HDC hdcMem
= CreateCompatibleDC( hdc
);
445 HBITMAP hbmpPrev
= SelectObject( hdcMem
, vertical
?
446 TOP_ARROW(infoPtr
->flags
, top_pressed
)
447 : LEFT_ARROW(infoPtr
->flags
, top_pressed
));
449 SetStretchBltMode( hdc
, STRETCH_DELETESCANS
);
450 StretchBlt( hdc
, rect
->left
, rect
->top
,
451 vertical
? rect
->right
-rect
->left
: arrowSize
,
452 vertical
? arrowSize
: rect
->bottom
-rect
->top
,
454 GetSystemMetrics(SM_CXVSCROLL
),GetSystemMetrics(SM_CYHSCROLL
),
457 SelectObject( hdcMem
, vertical
?
458 BOTTOM_ARROW( infoPtr
->flags
, bottom_pressed
)
459 : RIGHT_ARROW( infoPtr
->flags
, bottom_pressed
) );
461 StretchBlt( hdc
, rect
->left
, rect
->bottom
- arrowSize
,
462 rect
->right
- rect
->left
, arrowSize
,
464 GetSystemMetrics(SM_CXVSCROLL
),GetSystemMetrics(SM_CYHSCROLL
),
467 StretchBlt( hdc
, rect
->right
- arrowSize
, rect
->top
,
468 arrowSize
, rect
->bottom
- rect
->top
,
470 GetSystemMetrics(SM_CXVSCROLL
), GetSystemMetrics(SM_CYHSCROLL
),
472 SelectObject( hdcMem
, hbmpPrev
);
476 static void SCROLL_DrawArrows( HDC hdc
, SCROLLBAR_INFO
*infoPtr
,
477 RECT
*rect
, INT arrowSize
, BOOL vertical
,
478 BOOL top_pressed
, BOOL bottom_pressed
)
480 if( TWEAK_WineLook
== WIN31_LOOK
)
481 SCROLL_DrawArrows_31( hdc
, infoPtr
, rect
, arrowSize
,
482 vertical
, top_pressed
,bottom_pressed
);
484 SCROLL_DrawArrows_9x( hdc
, infoPtr
, rect
, arrowSize
,
485 vertical
, top_pressed
,bottom_pressed
);
489 /***********************************************************************
490 * SCROLL_DrawMovingThumb
492 * Draw the moving thumb rectangle.
494 static void SCROLL_DrawMovingThumb_31( HDC hdc
, RECT
*rect
, BOOL vertical
,
495 INT arrowSize
, INT thumbSize
)
500 r
.top
+= SCROLL_TrackingPos
;
501 if (r
.top
< rect
->top
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
502 r
.top
= rect
->top
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
503 if (r
.top
+ thumbSize
>
504 rect
->bottom
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
))
505 r
.top
= rect
->bottom
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
507 r
.bottom
= r
.top
+ thumbSize
;
511 r
.left
+= SCROLL_TrackingPos
;
512 if (r
.left
< rect
->left
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
513 r
.left
= rect
->left
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
514 if (r
.left
+ thumbSize
>
515 rect
->right
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
))
516 r
.left
= rect
->right
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
518 r
.right
= r
.left
+ thumbSize
;
521 DrawFocusRect( hdc
, &r
);
522 SCROLL_MovingThumb
= !SCROLL_MovingThumb
;
525 static void SCROLL_DrawMovingThumb_9x( HDC hdc
, RECT
*rect
, BOOL vertical
,
526 INT arrowSize
, INT thumbSize
)
528 INT pos
= SCROLL_TrackingPos
;
532 max_size
= rect
->bottom
- rect
->top
;
534 max_size
= rect
->right
- rect
->left
;
536 max_size
-= (arrowSize
-SCROLL_ARROW_THUMB_OVERLAP
) + thumbSize
;
538 if( pos
< (arrowSize
-SCROLL_ARROW_THUMB_OVERLAP
) )
539 pos
= (arrowSize
-SCROLL_ARROW_THUMB_OVERLAP
);
540 else if( pos
> max_size
)
543 SCROLL_DrawInterior_9x( SCROLL_TrackingWin
, hdc
, SCROLL_TrackingBar
,
544 rect
, arrowSize
, thumbSize
, pos
,
545 0, vertical
, FALSE
, FALSE
);
547 SCROLL_MovingThumb
= !SCROLL_MovingThumb
;
550 static void SCROLL_DrawMovingThumb( HDC hdc
, RECT
*rect
, BOOL vertical
,
551 INT arrowSize
, INT thumbSize
)
553 if( TWEAK_WineLook
== WIN31_LOOK
)
554 SCROLL_DrawMovingThumb_31( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
556 SCROLL_DrawMovingThumb_9x( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
559 /***********************************************************************
560 * SCROLL_DrawInterior
562 * Draw the scroll bar interior (everything except the arrows).
564 static void SCROLL_DrawInterior_9x( HWND hwnd
, HDC hdc
, INT nBar
,
565 RECT
*rect
, INT arrowSize
,
566 INT thumbSize
, INT thumbPos
,
567 UINT flags
, BOOL vertical
,
568 BOOL top_selected
, BOOL bottom_selected
)
572 HBRUSH hSaveBrush
,hBrush
;
574 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
575 * The window-owned scrollbars need to call DEFWND_ControlColor
576 * to correctly setup default scrollbar colors
580 hBrush
= (HBRUSH
)SendMessageA( GetParent(hwnd
), WM_CTLCOLORSCROLLBAR
,
581 (WPARAM
)hdc
,(LPARAM
)hwnd
);
585 hBrush
= DEFWND_ControlColor( hdc
, CTLCOLOR_SCROLLBAR
);
588 hSavePen
= SelectObject( hdc
, GetSysColorPen(COLOR_WINDOWFRAME
) );
589 hSaveBrush
= SelectObject( hdc
, hBrush
);
591 /* Calculate the scroll rectangle */
595 r
.top
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
596 r
.bottom
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
600 r
.left
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
601 r
.right
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
604 /* Draw the scroll rectangles and thumb */
605 if (!thumbPos
) /* No thumb to draw */
607 PatBlt( hdc
, r
.left
, r
.top
,
608 r
.right
- r
.left
, r
.bottom
- r
.top
,
611 /* cleanup and return */
612 SelectObject( hdc
, hSavePen
);
613 SelectObject( hdc
, hSaveBrush
);
619 PatBlt( hdc
, r
.left
, r
.top
,
621 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
),
622 top_selected
? 0x0f0000 : PATCOPY
);
623 r
.top
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
624 PatBlt( hdc
, r
.left
, r
.top
+ thumbSize
,
626 r
.bottom
- r
.top
- thumbSize
,
627 bottom_selected
? 0x0f0000 : PATCOPY
);
628 r
.bottom
= r
.top
+ thumbSize
;
630 else /* horizontal */
632 PatBlt( hdc
, r
.left
, r
.top
,
633 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
),
635 top_selected
? 0x0f0000 : PATCOPY
);
636 r
.left
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
637 PatBlt( hdc
, r
.left
+ thumbSize
, r
.top
,
638 r
.right
- r
.left
- thumbSize
,
640 bottom_selected
? 0x0f0000 : PATCOPY
);
641 r
.right
= r
.left
+ thumbSize
;
645 DrawEdge( hdc
, &r
, EDGE_RAISED
, BF_RECT
| BF_MIDDLE
);
648 SelectObject( hdc
, hSavePen
);
649 SelectObject( hdc
, hSaveBrush
);
653 static void SCROLL_DrawInterior( HWND hwnd
, HDC hdc
, INT nBar
,
654 RECT
*rect
, INT arrowSize
,
655 INT thumbSize
, INT thumbPos
,
656 UINT flags
, BOOL vertical
,
657 BOOL top_selected
, BOOL bottom_selected
)
661 HBRUSH hSaveBrush
,hBrush
;
662 BOOL Save_SCROLL_MovingThumb
= SCROLL_MovingThumb
;
664 if (Save_SCROLL_MovingThumb
&&
665 (SCROLL_TrackingWin
== hwnd
) &&
666 (SCROLL_TrackingBar
== nBar
))
667 SCROLL_DrawMovingThumb( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
669 /* Select the correct brush and pen */
671 if (TWEAK_WineLook
== WIN31_LOOK
&& (flags
& ESB_DISABLE_BOTH
) == ESB_DISABLE_BOTH
)
673 /* This ought to be the color of the parent window */
674 hBrush
= GetSysColorBrush(COLOR_WINDOW
);
678 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
679 * The window-owned scrollbars need to call DEFWND_ControlColor
680 * to correctly setup default scrollbar colors
682 if (nBar
== SB_CTL
) {
683 hBrush
= (HBRUSH
)SendMessageA( GetParent(hwnd
), WM_CTLCOLORSCROLLBAR
,
684 (WPARAM
)hdc
,(LPARAM
)hwnd
);
686 hBrush
= DEFWND_ControlColor( hdc
, CTLCOLOR_SCROLLBAR
);
689 hSavePen
= SelectObject( hdc
, GetSysColorPen(COLOR_WINDOWFRAME
) );
690 hSaveBrush
= SelectObject( hdc
, hBrush
);
692 /* Calculate the scroll rectangle */
697 r
.top
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
698 r
.bottom
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
702 r
.left
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
703 r
.right
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
706 /* Draw the scroll bar frame */
708 /* Only draw outline if Win 3.1. Mar 24, 1999 - Ronald B. Cemer */
709 if (TWEAK_WineLook
== WIN31_LOOK
)
710 Rectangle( hdc
, r
.left
, r
.top
, r
.right
, r
.bottom
);
712 /* Draw the scroll rectangles and thumb */
714 if (!thumbPos
) /* No thumb to draw */
716 INT offset
= (TWEAK_WineLook
> WIN31_LOOK
) ? 0 : 1;
718 PatBlt( hdc
, r
.left
+offset
, r
.top
+offset
,
719 r
.right
- r
.left
- 2*offset
, r
.bottom
- r
.top
- 2*offset
,
722 /* cleanup and return */
723 SelectObject( hdc
, hSavePen
);
724 SelectObject( hdc
, hSaveBrush
);
730 INT offset
= (TWEAK_WineLook
== WIN31_LOOK
) ? 1 : 0;
732 PatBlt( hdc
, r
.left
+ offset
, r
.top
+ offset
,
733 r
.right
- r
.left
- offset
*2,
734 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
) - offset
,
735 top_selected
? 0x0f0000 : PATCOPY
);
736 r
.top
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
737 PatBlt( hdc
, r
.left
+ offset
, r
.top
+ thumbSize
,
738 r
.right
- r
.left
- offset
*2,
739 r
.bottom
- r
.top
- thumbSize
- offset
,
740 bottom_selected
? 0x0f0000 : PATCOPY
);
741 r
.bottom
= r
.top
+ thumbSize
;
743 else /* horizontal */
745 INT offset
= (TWEAK_WineLook
== WIN31_LOOK
) ? 1 : 0;
747 PatBlt( hdc
, r
.left
+ offset
, r
.top
+ offset
,
748 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
),
749 r
.bottom
- r
.top
- offset
*2,
750 top_selected
? 0x0f0000 : PATCOPY
);
751 r
.left
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
752 PatBlt( hdc
, r
.left
+ thumbSize
, r
.top
+ offset
,
753 r
.right
- r
.left
- thumbSize
- offset
,
754 r
.bottom
- r
.top
- offset
*2,
755 bottom_selected
? 0x0f0000 : PATCOPY
);
756 r
.right
= r
.left
+ thumbSize
;
761 SelectObject( hdc
, GetSysColorBrush(COLOR_BTNFACE
) );
762 if (TWEAK_WineLook
== WIN31_LOOK
)
764 Rectangle( hdc
, r
.left
, r
.top
, r
.right
, r
.bottom
);
769 Rectangle( hdc
, r
.left
+1, r
.top
+1, r
.right
-1, r
.bottom
-1 );
771 DrawEdge( hdc
, &r
, EDGE_RAISED
, BF_RECT
);
773 if (Save_SCROLL_MovingThumb
&&
774 (SCROLL_TrackingWin
== hwnd
) &&
775 (SCROLL_TrackingBar
== nBar
))
776 SCROLL_DrawMovingThumb( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
779 SelectObject( hdc
, hSavePen
);
780 SelectObject( hdc
, hSaveBrush
);
784 /***********************************************************************
785 * SCROLL_DrawScrollBar
787 * Redraw the whole scrollbar.
789 void SCROLL_DrawScrollBar( HWND hwnd
, HDC hdc
, INT nBar
,
790 BOOL arrows
, BOOL interior
)
792 INT arrowSize
, thumbSize
, thumbPos
;
795 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
796 SCROLLBAR_INFO
*infoPtr
= SCROLL_GetPtrScrollInfo( wndPtr
, nBar
);
797 BOOL Save_SCROLL_MovingThumb
= SCROLL_MovingThumb
;
799 if (!wndPtr
|| !infoPtr
||
800 ((nBar
== SB_VERT
) && !(wndPtr
->dwStyle
& WS_VSCROLL
)) ||
801 ((nBar
== SB_HORZ
) && !(wndPtr
->dwStyle
& WS_HSCROLL
))) goto END
;
802 if (!WIN_IsWindowDrawable( wndPtr
, FALSE
)) goto END
;
804 vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
805 &arrowSize
, &thumbSize
, &thumbPos
);
807 /* do not draw if the scrollbar rectangle is empty */
808 if(IsRectEmpty(&rect
))
811 if (Save_SCROLL_MovingThumb
&&
812 (SCROLL_TrackingWin
== hwnd
) &&
813 (SCROLL_TrackingBar
== nBar
))
814 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
816 /* Draw the arrows */
818 if (arrows
&& arrowSize
)
820 if( vertical
== SCROLL_trackVertical
&& GetCapture() == hwnd
)
821 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
822 (SCROLL_trackHitTest
== SCROLL_TOP_ARROW
),
823 (SCROLL_trackHitTest
== SCROLL_BOTTOM_ARROW
) );
825 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
829 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
830 thumbPos
, infoPtr
->flags
, vertical
, FALSE
, FALSE
);
832 if (Save_SCROLL_MovingThumb
&&
833 (SCROLL_TrackingWin
== hwnd
) &&
834 (SCROLL_TrackingBar
== nBar
))
835 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
837 /* if scroll bar has focus, reposition the caret*/
838 if(hwnd
==GetFocus() && (nBar
==SB_CTL
))
842 SetCaretPos(thumbPos
+1, rect
.top
+1);
846 SetCaretPos(rect
.top
+1, thumbPos
+1);
851 WIN_ReleaseWndPtr(wndPtr
);
855 /***********************************************************************
856 * SCROLL_RefreshScrollBar
858 * Repaint the scroll bar interior after a SetScrollRange() or
859 * SetScrollPos() call.
861 static void SCROLL_RefreshScrollBar( HWND hwnd
, INT nBar
,
862 BOOL arrows
, BOOL interior
)
864 HDC hdc
= GetDCEx( hwnd
, 0,
865 DCX_CACHE
| ((nBar
== SB_CTL
) ? 0 : DCX_WINDOW
) );
868 SCROLL_DrawScrollBar( hwnd
, hdc
, nBar
, arrows
, interior
);
869 ReleaseDC( hwnd
, hdc
);
873 /***********************************************************************
874 * SCROLL_HandleKbdEvent
876 * Handle a keyboard event (only for SB_CTL scrollbars).
878 static void SCROLL_HandleKbdEvent( HWND hwnd
, WPARAM wParam
)
880 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
885 case VK_PRIOR
: msg
= SB_PAGEUP
; break;
886 case VK_NEXT
: msg
= SB_PAGEDOWN
; break;
887 case VK_HOME
: msg
= SB_TOP
; break;
888 case VK_END
: msg
= SB_BOTTOM
; break;
889 case VK_UP
: msg
= SB_LINEUP
; break;
890 case VK_DOWN
: msg
= SB_LINEDOWN
; break;
892 WIN_ReleaseWndPtr(wndPtr
);
895 SendMessageW( GetParent(hwnd
),
896 (wndPtr
->dwStyle
& SBS_VERT
) ? WM_VSCROLL
: WM_HSCROLL
,
898 WIN_ReleaseWndPtr(wndPtr
);
902 /***********************************************************************
903 * SCROLL_HandleScrollEvent
905 * Handle a mouse or timer event for the scrollbar.
906 * 'pt' is the location of the mouse event in client (for SB_CTL) or
907 * windows coordinates.
909 void SCROLL_HandleScrollEvent( HWND hwnd
, INT nBar
, UINT msg
, POINT pt
)
911 /* Previous mouse position for timer events */
913 /* Thumb position when tracking started. */
914 static UINT trackThumbPos
;
915 /* Position in the scroll-bar of the last button-down event. */
916 static INT lastClickPos
;
917 /* Position in the scroll-bar of the last mouse event. */
918 static INT lastMousePos
;
920 enum SCROLL_HITTEST hittest
;
921 HWND hwndOwner
, hwndCtl
;
923 INT arrowSize
, thumbSize
, thumbPos
;
927 SCROLLBAR_INFO
*infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
);
928 if (!infoPtr
) return;
929 if ((SCROLL_trackHitTest
== SCROLL_NOWHERE
) && (msg
!= WM_LBUTTONDOWN
))
932 hdc
= GetDCEx( hwnd
, 0, DCX_CACHE
| ((nBar
== SB_CTL
) ? 0 : DCX_WINDOW
));
933 vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
934 &arrowSize
, &thumbSize
, &thumbPos
);
935 hwndOwner
= (nBar
== SB_CTL
) ? GetParent(hwnd
) : hwnd
;
936 hwndCtl
= (nBar
== SB_CTL
) ? hwnd
: 0;
940 case WM_LBUTTONDOWN
: /* Initialise mouse tracking */
941 HideCaret(hwnd
); /* hide caret while holding down LBUTTON*/
942 SCROLL_trackVertical
= vertical
;
943 SCROLL_trackHitTest
= hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, FALSE
);
944 lastClickPos
= vertical
? (pt
.y
- rect
.top
) : (pt
.x
- rect
.left
);
945 lastMousePos
= lastClickPos
;
946 trackThumbPos
= thumbPos
;
949 if (nBar
== SB_CTL
&& (GetWindowLongA(hwnd
, GWL_STYLE
) & WS_TABSTOP
)) SetFocus( hwnd
);
953 hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, TRUE
);
958 hittest
= SCROLL_NOWHERE
;
960 /* if scrollbar has focus, show back caret */
961 if (hwnd
==GetFocus()) ShowCaret(hwnd
);
966 hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, FALSE
);
970 return; /* Should never happen */
973 TRACE("Event: hwnd=%04x bar=%d msg=%x pt=%ld,%ld hit=%d\n",
974 hwnd
, nBar
, msg
, pt
.x
, pt
.y
, hittest
);
976 switch(SCROLL_trackHitTest
)
978 case SCROLL_NOWHERE
: /* No tracking in progress */
981 case SCROLL_TOP_ARROW
:
982 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
983 (hittest
== SCROLL_trackHitTest
), FALSE
);
984 if (hittest
== SCROLL_trackHitTest
)
986 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
988 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
989 SB_LINEUP
, hwndCtl
);
992 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
993 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
996 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
999 case SCROLL_TOP_RECT
:
1000 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
1001 thumbPos
, infoPtr
->flags
, vertical
,
1002 (hittest
== SCROLL_trackHitTest
), FALSE
);
1003 if (hittest
== SCROLL_trackHitTest
)
1005 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
1007 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1008 SB_PAGEUP
, hwndCtl
);
1009 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
1010 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
1014 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
1018 if (msg
== WM_LBUTTONDOWN
)
1020 SCROLL_TrackingWin
= hwnd
;
1021 SCROLL_TrackingBar
= nBar
;
1022 SCROLL_TrackingPos
= trackThumbPos
+ lastMousePos
- lastClickPos
;
1023 if (!SCROLL_MovingThumb
)
1024 SCROLL_DrawMovingThumb(hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
1026 else if (msg
== WM_LBUTTONUP
)
1028 if (SCROLL_MovingThumb
)
1029 SCROLL_DrawMovingThumb(hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
1030 SCROLL_TrackingWin
= 0;
1031 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
1032 thumbPos
, infoPtr
->flags
, vertical
,
1035 else /* WM_MOUSEMOVE */
1039 if (!SCROLL_PtInRectEx( &rect
, pt
, vertical
)) pos
= lastClickPos
;
1042 pt
= SCROLL_ClipPos( &rect
, pt
);
1043 pos
= vertical
? (pt
.y
- rect
.top
) : (pt
.x
- rect
.left
);
1045 if ( (pos
!= lastMousePos
) || (!SCROLL_MovingThumb
) )
1047 if (SCROLL_MovingThumb
)
1048 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
,
1049 arrowSize
, thumbSize
);
1051 SCROLL_TrackingPos
= trackThumbPos
+ pos
- lastClickPos
;
1052 SCROLL_TrackingVal
= SCROLL_GetThumbVal( infoPtr
, &rect
,
1054 SCROLL_TrackingPos
);
1055 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1056 MAKEWPARAM( SB_THUMBTRACK
, SCROLL_TrackingVal
),
1058 if (!SCROLL_MovingThumb
)
1059 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
,
1060 arrowSize
, thumbSize
);
1065 case SCROLL_BOTTOM_RECT
:
1066 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
1067 thumbPos
, infoPtr
->flags
, vertical
,
1068 FALSE
, (hittest
== SCROLL_trackHitTest
) );
1069 if (hittest
== SCROLL_trackHitTest
)
1071 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
1073 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1074 SB_PAGEDOWN
, hwndCtl
);
1075 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
1076 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
1080 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
1083 case SCROLL_BOTTOM_ARROW
:
1084 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
1085 FALSE
, (hittest
== SCROLL_trackHitTest
) );
1086 if (hittest
== SCROLL_trackHitTest
)
1088 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
1090 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1091 SB_LINEDOWN
, hwndCtl
);
1094 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
1095 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
1098 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
1102 if (msg
== WM_LBUTTONUP
)
1104 hittest
= SCROLL_trackHitTest
;
1105 SCROLL_trackHitTest
= SCROLL_NOWHERE
; /* Terminate tracking */
1107 if (hittest
== SCROLL_THUMB
)
1109 UINT val
= SCROLL_GetThumbVal( infoPtr
, &rect
, vertical
,
1110 trackThumbPos
+ lastMousePos
- lastClickPos
);
1111 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1112 MAKEWPARAM( SB_THUMBPOSITION
, val
), hwndCtl
);
1115 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1116 SB_ENDSCROLL
, hwndCtl
);
1119 ReleaseDC( hwnd
, hdc
);
1123 /***********************************************************************
1126 static LRESULT WINAPI
ScrollBarWndProc( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1132 CREATESTRUCTW
*lpCreat
= (CREATESTRUCTW
*)lParam
;
1133 if (lpCreat
->style
& SBS_SIZEBOX
)
1135 FIXME("Unimplemented style SBS_SIZEBOX.\n" );
1138 if (lpCreat
->style
& SBS_VERT
)
1140 if (lpCreat
->style
& SBS_LEFTALIGN
)
1141 MoveWindow( hwnd
, lpCreat
->x
, lpCreat
->y
,
1142 GetSystemMetrics(SM_CXVSCROLL
)+1, lpCreat
->cy
, FALSE
);
1143 else if (lpCreat
->style
& SBS_RIGHTALIGN
)
1145 lpCreat
->x
+lpCreat
->cx
-GetSystemMetrics(SM_CXVSCROLL
)-1,
1147 GetSystemMetrics(SM_CXVSCROLL
)+1, lpCreat
->cy
, FALSE
);
1151 if (lpCreat
->style
& SBS_TOPALIGN
)
1152 MoveWindow( hwnd
, lpCreat
->x
, lpCreat
->y
,
1153 lpCreat
->cx
, GetSystemMetrics(SM_CYHSCROLL
)+1, FALSE
);
1154 else if (lpCreat
->style
& SBS_BOTTOMALIGN
)
1157 lpCreat
->y
+lpCreat
->cy
-GetSystemMetrics(SM_CYHSCROLL
)-1,
1158 lpCreat
->cx
, GetSystemMetrics(SM_CYHSCROLL
)+1, FALSE
);
1161 if (!hUpArrow
) SCROLL_LoadBitmaps();
1162 TRACE("ScrollBar creation, hwnd=%04x\n", hwnd
);
1165 case WM_LBUTTONDOWN
:
1171 pt
.x
= SLOWORD(lParam
);
1172 pt
.y
= SHIWORD(lParam
);
1173 SCROLL_HandleScrollEvent( hwnd
, SB_CTL
, message
, pt
);
1177 /* if key event is received, the scrollbar has the focus*/
1179 /* hide caret on first KEYDOWN to prevent flicker */
1180 if ((lParam
& 0x40000000)==0)
1182 SCROLL_HandleKbdEvent( hwnd
, wParam
);
1191 /* Create a caret when a ScrollBar get focus*/
1193 int arrowSize
, thumbSize
, thumbPos
, vertical
;
1194 vertical
= SCROLL_GetScrollBarRect( hwnd
, SB_CTL
, &rect
,
1195 &arrowSize
, &thumbSize
, &thumbPos
);
1198 CreateCaret(hwnd
,1, thumbSize
-2, rect
.bottom
-rect
.top
-2);
1199 SetCaretPos(thumbPos
+1, rect
.top
+1);
1203 CreateCaret(hwnd
,1, rect
.right
-rect
.left
-2,thumbSize
-2);
1204 SetCaretPos(rect
.top
+1, thumbPos
+1);
1213 int arrowSize
, thumbSize
, thumbPos
, vertical
;
1214 vertical
= SCROLL_GetScrollBarRect( hwnd
, SB_CTL
, &rect
,&arrowSize
, &thumbSize
, &thumbPos
);
1216 rect
.left
=thumbPos
+1;
1217 rect
.right
=rect
.left
+thumbSize
;
1221 rect
.top
=thumbPos
+1;
1222 rect
.bottom
=rect
.top
+thumbSize
;
1225 InvalidateRect(hwnd
,&rect
,0);
1234 return DLGC_WANTARROWS
; /* Windows returns this value */
1239 HDC hdc
= BeginPaint( hwnd
, &ps
);
1240 SCROLL_DrawScrollBar( hwnd
, hdc
, SB_CTL
, TRUE
, TRUE
);
1241 EndPaint( hwnd
, &ps
);
1247 return SetScrollPos( hwnd
, SB_CTL
, wParam
, (BOOL
)lParam
);
1251 return GetScrollPos( hwnd
, SB_CTL
);
1253 case SBM_SETRANGE16
:
1254 SetScrollRange( hwnd
, SB_CTL
, LOWORD(lParam
), HIWORD(lParam
),
1255 wParam
/* FIXME: Is this correct? */ );
1259 SetScrollRange( hwnd
, SB_CTL
, wParam
, lParam
, FALSE
);
1260 return 0; /* FIXME: return previous position */
1262 case SBM_GETRANGE16
:
1263 FIXME("don't know how to handle SBM_GETRANGE16 (wp=%04x,lp=%08lx)\n", wParam
, lParam
);
1267 GetScrollRange( hwnd
, SB_CTL
, (LPINT
)wParam
, (LPINT
)lParam
);
1270 case SBM_ENABLE_ARROWS16
:
1271 case SBM_ENABLE_ARROWS
:
1272 return EnableScrollBar( hwnd
, SB_CTL
, wParam
);
1274 case SBM_SETRANGEREDRAW
:
1275 SetScrollRange( hwnd
, SB_CTL
, wParam
, lParam
, TRUE
);
1276 return 0; /* FIXME: return previous position */
1278 case SBM_SETSCROLLINFO
:
1279 return SetScrollInfo( hwnd
, SB_CTL
, (SCROLLINFO
*)lParam
, wParam
);
1281 case SBM_GETSCROLLINFO
:
1282 return GetScrollInfo( hwnd
, SB_CTL
, (SCROLLINFO
*)lParam
);
1292 ERR("unknown Win32 msg %04x wp=%08x lp=%08lx\n",
1293 message
, wParam
, lParam
);
1297 if (message
>= WM_USER
)
1298 WARN("unknown msg %04x wp=%04x lp=%08lx\n",
1299 message
, wParam
, lParam
);
1300 return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1306 /*************************************************************************
1307 * SetScrollInfo16 (USER.475)
1309 INT16 WINAPI
SetScrollInfo16( HWND16 hwnd
, INT16 nBar
, const SCROLLINFO
*info
,
1312 return (INT16
)SetScrollInfo( hwnd
, nBar
, info
, bRedraw
);
1316 /*************************************************************************
1317 * SetScrollInfo (USER32.@)
1318 * SetScrollInfo can be used to set the position, upper bound,
1319 * lower bound, and page size of a scrollbar control.
1322 * Scrollbar position
1325 * For 100 lines of text to be displayed in a window of 25 lines,
1326 * one would for instance use info->nMin=0, info->nMax=75
1327 * (corresponding to the 76 different positions of the window on
1328 * the text), and info->nPage=25.
1330 INT WINAPI
SetScrollInfo(
1331 HWND hwnd
/* [in] Handle of window whose scrollbar will be affected */,
1332 INT nBar
/* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1333 const SCROLLINFO
*info
/* [in] Specifies what to change and new values */,
1334 BOOL bRedraw
/* [in] Should scrollbar be redrawn afterwards ? */)
1337 INT retVal
= SCROLL_SetScrollInfo( hwnd
, nBar
, info
, &action
);
1339 if( action
& SA_SSI_HIDE
)
1340 SCROLL_ShowScrollBar( hwnd
, nBar
, FALSE
, FALSE
);
1343 if( action
& SA_SSI_SHOW
)
1344 if( SCROLL_ShowScrollBar( hwnd
, nBar
, TRUE
, TRUE
) )
1345 return retVal
; /* SetWindowPos() already did the painting */
1347 if( bRedraw
&& (action
& SA_SSI_REFRESH
))
1348 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, TRUE
);
1349 else if( action
& SA_SSI_REPAINT_ARROWS
)
1350 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, FALSE
);
1355 INT
SCROLL_SetScrollInfo( HWND hwnd
, INT nBar
,
1356 const SCROLLINFO
*info
, INT
*action
)
1358 /* Update the scrollbar state and set action flags according to
1359 * what has to be done graphics wise. */
1361 SCROLLBAR_INFO
*infoPtr
;
1363 BOOL bChangeParams
= FALSE
; /* don't show/hide scrollbar if params don't change */
1367 if (!(infoPtr
= SCROLL_GetScrollInfo(hwnd
, nBar
))) return 0;
1368 if (info
->fMask
& ~(SIF_ALL
| SIF_DISABLENOSCROLL
)) return 0;
1369 if ((info
->cbSize
!= sizeof(*info
)) &&
1370 (info
->cbSize
!= sizeof(*info
)-sizeof(info
->nTrackPos
))) return 0;
1372 if (TRACE_ON(scroll
))
1374 TRACE("hwnd=%04x bar=%d", hwnd
, nBar
);
1375 if (info
->fMask
& SIF_PAGE
) DPRINTF( " page=%d", info
->nPage
);
1376 if (info
->fMask
& SIF_POS
) DPRINTF( " pos=%d", info
->nPos
);
1377 if (info
->fMask
& SIF_RANGE
) DPRINTF( " min=%d max=%d", info
->nMin
, info
->nMax
);
1381 /* Set the page size */
1383 if (info
->fMask
& SIF_PAGE
)
1385 if( infoPtr
->Page
!= info
->nPage
)
1387 infoPtr
->Page
= info
->nPage
;
1388 *action
|= SA_SSI_REFRESH
;
1389 bChangeParams
= TRUE
;
1393 /* Set the scroll pos */
1395 if (info
->fMask
& SIF_POS
)
1397 if( infoPtr
->CurVal
!= info
->nPos
)
1399 infoPtr
->CurVal
= info
->nPos
;
1400 *action
|= SA_SSI_REFRESH
;
1404 /* Set the scroll range */
1406 if (info
->fMask
& SIF_RANGE
)
1408 /* Invalid range -> range is set to (0,0) */
1409 if ((info
->nMin
> info
->nMax
) ||
1410 ((UINT
)(info
->nMax
- info
->nMin
) >= 0x80000000))
1412 infoPtr
->MinVal
= 0;
1413 infoPtr
->MaxVal
= 0;
1414 bChangeParams
= TRUE
;
1418 if( infoPtr
->MinVal
!= info
->nMin
||
1419 infoPtr
->MaxVal
!= info
->nMax
)
1421 *action
|= SA_SSI_REFRESH
;
1422 infoPtr
->MinVal
= info
->nMin
;
1423 infoPtr
->MaxVal
= info
->nMax
;
1424 bChangeParams
= TRUE
;
1429 /* Make sure the page size is valid */
1431 if (infoPtr
->Page
< 0) infoPtr
->Page
= 0;
1432 else if (infoPtr
->Page
> infoPtr
->MaxVal
- infoPtr
->MinVal
+ 1 )
1433 infoPtr
->Page
= infoPtr
->MaxVal
- infoPtr
->MinVal
+ 1;
1435 /* Make sure the pos is inside the range */
1437 if (infoPtr
->CurVal
< infoPtr
->MinVal
)
1438 infoPtr
->CurVal
= infoPtr
->MinVal
;
1439 else if (infoPtr
->CurVal
> infoPtr
->MaxVal
- max( infoPtr
->Page
-1, 0 ))
1440 infoPtr
->CurVal
= infoPtr
->MaxVal
- max( infoPtr
->Page
-1, 0 );
1442 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1443 infoPtr
->Page
, infoPtr
->CurVal
,
1444 infoPtr
->MinVal
, infoPtr
->MaxVal
);
1446 /* don't change the scrollbar state if SetScrollInfo
1447 * is just called with SIF_DISABLENOSCROLL
1449 if(!(info
->fMask
& SIF_ALL
)) goto done
;
1451 /* Check if the scrollbar should be hidden or disabled */
1453 if (info
->fMask
& (SIF_RANGE
| SIF_PAGE
| SIF_DISABLENOSCROLL
))
1455 new_flags
= infoPtr
->flags
;
1456 if (infoPtr
->MinVal
>= infoPtr
->MaxVal
- max( infoPtr
->Page
-1, 0 ))
1458 /* Hide or disable scroll-bar */
1459 if (info
->fMask
& SIF_DISABLENOSCROLL
)
1461 new_flags
= ESB_DISABLE_BOTH
;
1462 *action
|= SA_SSI_REFRESH
;
1464 else if ((nBar
!= SB_CTL
) && bChangeParams
)
1466 *action
= SA_SSI_HIDE
;
1470 else /* Show and enable scroll-bar */
1473 if ((nBar
!= SB_CTL
) && bChangeParams
)
1474 *action
|= SA_SSI_SHOW
;
1477 if (infoPtr
->flags
!= new_flags
) /* check arrow flags */
1479 infoPtr
->flags
= new_flags
;
1480 *action
|= SA_SSI_REPAINT_ARROWS
;
1485 /* Return current position */
1487 return infoPtr
->CurVal
;
1491 /*************************************************************************
1492 * GetScrollInfo16 (USER.476)
1494 BOOL16 WINAPI
GetScrollInfo16( HWND16 hwnd
, INT16 nBar
, LPSCROLLINFO info
)
1496 return GetScrollInfo( hwnd
, nBar
, info
);
1500 /*************************************************************************
1501 * GetScrollInfo (USER32.@)
1502 * GetScrollInfo can be used to retrieve the position, upper bound,
1503 * lower bound, and page size of a scrollbar control.
1507 BOOL WINAPI
GetScrollInfo(
1508 HWND hwnd
/* [in] Handle of window */ ,
1509 INT nBar
/* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1510 LPSCROLLINFO info
/* [in/out] (info.fMask [in] specifies which values are to retrieve) */)
1512 SCROLLBAR_INFO
*infoPtr
;
1514 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return FALSE
;
1515 if (info
->fMask
& ~(SIF_ALL
| SIF_DISABLENOSCROLL
)) return FALSE
;
1516 if ((info
->cbSize
!= sizeof(*info
)) &&
1517 (info
->cbSize
!= sizeof(*info
)-sizeof(info
->nTrackPos
))) return FALSE
;
1519 if (info
->fMask
& SIF_PAGE
) info
->nPage
= infoPtr
->Page
;
1520 if (info
->fMask
& SIF_POS
) info
->nPos
= infoPtr
->CurVal
;
1521 if ((info
->fMask
& SIF_TRACKPOS
) && (info
->cbSize
== sizeof(*info
)))
1522 info
->nTrackPos
= (SCROLL_TrackingWin
==hwnd
) ? SCROLL_TrackingVal
: infoPtr
->CurVal
;
1523 if (info
->fMask
& SIF_RANGE
)
1525 info
->nMin
= infoPtr
->MinVal
;
1526 info
->nMax
= infoPtr
->MaxVal
;
1528 return (info
->fMask
& SIF_ALL
) != 0;
1532 /*************************************************************************
1533 * SetScrollPos16 (USER.62)
1535 INT16 WINAPI
SetScrollPos16( HWND16 hwnd
, INT16 nBar
, INT16 nPos
,
1538 return (INT16
)SetScrollPos( hwnd
, nBar
, nPos
, bRedraw
);
1542 /*************************************************************************
1543 * SetScrollPos (USER32.@)
1546 * Success: Scrollbar position
1550 * Note the ambiguity when 0 is returned. Use GetLastError
1551 * to make sure there was an error (and to know which one).
1553 INT WINAPI
SetScrollPos(
1554 HWND hwnd
/* [in] Handle of window whose scrollbar will be affected */,
1555 INT nBar
/* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1556 INT nPos
/* [in] New value */,
1557 BOOL bRedraw
/* [in] Should scrollbar be redrawn afterwards ? */ )
1560 SCROLLBAR_INFO
*infoPtr
;
1563 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return 0;
1564 oldPos
= infoPtr
->CurVal
;
1565 info
.cbSize
= sizeof(info
);
1567 info
.fMask
= SIF_POS
;
1568 SetScrollInfo( hwnd
, nBar
, &info
, bRedraw
);
1573 /*************************************************************************
1574 * GetScrollPos16 (USER.63)
1576 INT16 WINAPI
GetScrollPos16( HWND16 hwnd
, INT16 nBar
)
1578 return (INT16
)GetScrollPos( hwnd
, nBar
);
1582 /*************************************************************************
1583 * GetScrollPos (USER32.@)
1586 * Success: Current position
1590 * Note the ambiguity when 0 is returned. Use GetLastError
1591 * to make sure there was an error (and to know which one).
1593 INT WINAPI
GetScrollPos(
1594 HWND hwnd
, /* [in] Handle of window */
1595 INT nBar
/* [in] One of SB_HORZ, SB_VERT, or SB_CTL */)
1597 SCROLLBAR_INFO
*infoPtr
;
1599 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return 0;
1600 return infoPtr
->CurVal
;
1604 /*************************************************************************
1605 * SetScrollRange16 (USER.64)
1607 void WINAPI
SetScrollRange16( HWND16 hwnd
, INT16 nBar
,
1608 INT16 MinVal
, INT16 MaxVal
, BOOL16 bRedraw
)
1610 /* Invalid range -> range is set to (0,0) */
1611 if ((INT
)MaxVal
- (INT
)MinVal
> 0x7fff) MinVal
= MaxVal
= 0;
1612 SetScrollRange( hwnd
, nBar
, MinVal
, MaxVal
, bRedraw
);
1616 /*************************************************************************
1617 * SetScrollRange (USER32.@)
1621 BOOL WINAPI
SetScrollRange(
1622 HWND hwnd
, /* [in] Handle of window whose scrollbar will be affected */
1623 INT nBar
, /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */
1624 INT MinVal
, /* [in] New minimum value */
1625 INT MaxVal
, /* [in] New maximum value */
1626 BOOL bRedraw
/* [in] Should scrollbar be redrawn afterwards ? */)
1630 info
.cbSize
= sizeof(info
);
1633 info
.fMask
= SIF_RANGE
;
1634 SetScrollInfo( hwnd
, nBar
, &info
, bRedraw
);
1639 /*************************************************************************
1640 * SCROLL_SetNCSbState
1642 * Updates both scrollbars at the same time. Used by MDI CalcChildScroll().
1644 INT
SCROLL_SetNCSbState(WND
* wndPtr
, int vMin
, int vMax
, int vPos
,
1645 int hMin
, int hMax
, int hPos
)
1648 SCROLLINFO vInfo
, hInfo
;
1650 vInfo
.cbSize
= hInfo
.cbSize
= sizeof(SCROLLINFO
);
1651 vInfo
.nMin
= vMin
; hInfo
.nMin
= hMin
;
1652 vInfo
.nMax
= vMax
; hInfo
.nMax
= hMax
;
1653 vInfo
.nPos
= vPos
; hInfo
.nPos
= hPos
;
1654 vInfo
.fMask
= hInfo
.fMask
= SIF_RANGE
| SIF_POS
;
1656 SCROLL_SetScrollInfo( wndPtr
->hwndSelf
, SB_VERT
, &vInfo
, &vA
);
1657 SCROLL_SetScrollInfo( wndPtr
->hwndSelf
, SB_HORZ
, &hInfo
, &hA
);
1659 if( !SCROLL_ShowScrollBar( wndPtr
->hwndSelf
, SB_BOTH
,
1660 (hA
& SA_SSI_SHOW
),(vA
& SA_SSI_SHOW
) ) )
1662 /* SetWindowPos() wasn't called, just redraw the scrollbars if needed */
1663 if( vA
& SA_SSI_REFRESH
)
1664 SCROLL_RefreshScrollBar( wndPtr
->hwndSelf
, SB_VERT
, FALSE
, TRUE
);
1666 if( hA
& SA_SSI_REFRESH
)
1667 SCROLL_RefreshScrollBar( wndPtr
->hwndSelf
, SB_HORZ
, FALSE
, TRUE
);
1673 /*************************************************************************
1674 * GetScrollRange16 (USER.65)
1676 BOOL16 WINAPI
GetScrollRange16( HWND16 hwnd
, INT16 nBar
,
1677 LPINT16 lpMin
, LPINT16 lpMax
)
1680 BOOL16 ret
= GetScrollRange( hwnd
, nBar
, &min
, &max
);
1681 if (lpMin
) *lpMin
= min
;
1682 if (lpMax
) *lpMax
= max
;
1687 /*************************************************************************
1688 * GetScrollRange (USER32.@)
1692 BOOL WINAPI
GetScrollRange(
1693 HWND hwnd
, /* [in] Handle of window */
1694 INT nBar
, /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */
1695 LPINT lpMin
, /* [out] Where to store minimum value */
1696 LPINT lpMax
/* [out] Where to store maximum value */)
1698 SCROLLBAR_INFO
*infoPtr
;
1700 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
)))
1702 if (lpMin
) lpMin
= 0;
1703 if (lpMax
) lpMax
= 0;
1706 if (lpMin
) *lpMin
= infoPtr
->MinVal
;
1707 if (lpMax
) *lpMax
= infoPtr
->MaxVal
;
1712 /*************************************************************************
1713 * SCROLL_ShowScrollBar()
1715 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1717 BOOL
SCROLL_ShowScrollBar( HWND hwnd
, INT nBar
,
1718 BOOL fShowH
, BOOL fShowV
)
1720 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
1721 BOOL retvalue
= FALSE
;
1723 if (!wndPtr
) return FALSE
;
1724 TRACE("hwnd=%04x bar=%d horz=%d, vert=%d\n",
1725 hwnd
, nBar
, fShowH
, fShowV
);
1730 ShowWindow( hwnd
, fShowH
? SW_SHOW
: SW_HIDE
);
1738 fShowH
= !(wndPtr
->dwStyle
& WS_HSCROLL
);
1739 wndPtr
->dwStyle
|= WS_HSCROLL
;
1743 fShowH
= (wndPtr
->dwStyle
& WS_HSCROLL
);
1744 wndPtr
->dwStyle
&= ~WS_HSCROLL
;
1746 if( nBar
== SB_HORZ
) {
1755 fShowV
= !(wndPtr
->dwStyle
& WS_VSCROLL
);
1756 wndPtr
->dwStyle
|= WS_VSCROLL
;
1760 fShowV
= (wndPtr
->dwStyle
& WS_VSCROLL
);
1761 wndPtr
->dwStyle
&= ~WS_VSCROLL
;
1763 if ( nBar
== SB_VERT
)
1768 retvalue
= FALSE
; /* Nothing to do! */
1772 if( fShowH
|| fShowV
) /* frame has been changed, let the window redraw itself */
1774 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
1775 | SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
1780 retvalue
= FALSE
; /* no frame changes */
1782 WIN_ReleaseWndPtr(wndPtr
);
1787 /*************************************************************************
1788 * ShowScrollBar16 (USER.267)
1790 void WINAPI
ShowScrollBar16( HWND16 hwnd
, INT16 nBar
, BOOL16 fShow
)
1792 SCROLL_ShowScrollBar( hwnd
, nBar
, (nBar
== SB_VERT
) ? 0 : fShow
,
1793 (nBar
== SB_HORZ
) ? 0 : fShow
);
1797 /*************************************************************************
1798 * ShowScrollBar (USER32.@)
1802 BOOL WINAPI
ShowScrollBar(
1803 HWND hwnd
, /* [in] Handle of window whose scrollbar(s) will be affected */
1804 INT nBar
, /* [in] One of SB_HORZ, SB_VERT, SB_BOTH or SB_CTL */
1805 BOOL fShow
/* [in] TRUE = show, FALSE = hide */)
1807 SCROLL_ShowScrollBar( hwnd
, nBar
, (nBar
== SB_VERT
) ? 0 : fShow
,
1808 (nBar
== SB_HORZ
) ? 0 : fShow
);
1813 /*************************************************************************
1814 * EnableScrollBar16 (USER.482)
1816 BOOL16 WINAPI
EnableScrollBar16( HWND16 hwnd
, INT16 nBar
, UINT16 flags
)
1818 return EnableScrollBar( hwnd
, nBar
, flags
);
1822 /*************************************************************************
1823 * EnableScrollBar (USER32.@)
1825 BOOL WINAPI
EnableScrollBar( HWND hwnd
, INT nBar
, UINT flags
)
1828 SCROLLBAR_INFO
*infoPtr
;
1830 TRACE("%04x %d %d\n", hwnd
, nBar
, flags
);
1832 flags
&= ESB_DISABLE_BOTH
;
1834 if (nBar
== SB_BOTH
)
1836 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, SB_VERT
))) return FALSE
;
1837 if (!(bFineWithMe
= (infoPtr
->flags
== flags
)) )
1839 infoPtr
->flags
= flags
;
1840 SCROLL_RefreshScrollBar( hwnd
, SB_VERT
, TRUE
, TRUE
);
1847 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return FALSE
;
1848 if (bFineWithMe
&& infoPtr
->flags
== flags
) return FALSE
;
1849 infoPtr
->flags
= flags
;
1851 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, TRUE
);