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? */ );
1260 INT oldPos
= GetScrollPos( hwnd
, SB_CTL
);
1261 SetScrollRange( hwnd
, SB_CTL
, wParam
, lParam
, FALSE
);
1262 if (oldPos
!= GetScrollPos( hwnd
, SB_CTL
)) return oldPos
;
1266 case SBM_GETRANGE16
:
1267 FIXME("don't know how to handle SBM_GETRANGE16 (wp=%04x,lp=%08lx)\n", wParam
, lParam
);
1271 GetScrollRange( hwnd
, SB_CTL
, (LPINT
)wParam
, (LPINT
)lParam
);
1274 case SBM_ENABLE_ARROWS16
:
1275 case SBM_ENABLE_ARROWS
:
1276 return EnableScrollBar( hwnd
, SB_CTL
, wParam
);
1278 case SBM_SETRANGEREDRAW
:
1280 INT oldPos
= GetScrollPos( hwnd
, SB_CTL
);
1281 SetScrollRange( hwnd
, SB_CTL
, wParam
, lParam
, TRUE
);
1282 if (oldPos
!= GetScrollPos( hwnd
, SB_CTL
)) return oldPos
;
1286 case SBM_SETSCROLLINFO
:
1287 return SetScrollInfo( hwnd
, SB_CTL
, (SCROLLINFO
*)lParam
, wParam
);
1289 case SBM_GETSCROLLINFO
:
1290 return GetScrollInfo( hwnd
, SB_CTL
, (SCROLLINFO
*)lParam
);
1300 ERR("unknown Win32 msg %04x wp=%08x lp=%08lx\n",
1301 message
, wParam
, lParam
);
1305 if (message
>= WM_USER
)
1306 WARN("unknown msg %04x wp=%04x lp=%08lx\n",
1307 message
, wParam
, lParam
);
1308 return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1314 /*************************************************************************
1315 * SetScrollInfo (USER.475)
1317 INT16 WINAPI
SetScrollInfo16( HWND16 hwnd
, INT16 nBar
, const SCROLLINFO
*info
,
1320 return (INT16
)SetScrollInfo( hwnd
, nBar
, info
, bRedraw
);
1324 /*************************************************************************
1325 * SetScrollInfo (USER32.@)
1326 * SetScrollInfo can be used to set the position, upper bound,
1327 * lower bound, and page size of a scrollbar control.
1330 * Scrollbar position
1333 * For 100 lines of text to be displayed in a window of 25 lines,
1334 * one would for instance use info->nMin=0, info->nMax=75
1335 * (corresponding to the 76 different positions of the window on
1336 * the text), and info->nPage=25.
1338 INT WINAPI
SetScrollInfo(
1339 HWND hwnd
/* [in] Handle of window whose scrollbar will be affected */,
1340 INT nBar
/* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1341 const SCROLLINFO
*info
/* [in] Specifies what to change and new values */,
1342 BOOL bRedraw
/* [in] Should scrollbar be redrawn afterwards ? */)
1345 INT retVal
= SCROLL_SetScrollInfo( hwnd
, nBar
, info
, &action
);
1347 if( action
& SA_SSI_HIDE
)
1348 SCROLL_ShowScrollBar( hwnd
, nBar
, FALSE
, FALSE
);
1351 if( action
& SA_SSI_SHOW
)
1352 if( SCROLL_ShowScrollBar( hwnd
, nBar
, TRUE
, TRUE
) )
1353 return retVal
; /* SetWindowPos() already did the painting */
1355 if( bRedraw
&& (action
& SA_SSI_REFRESH
))
1356 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, TRUE
);
1357 else if( action
& SA_SSI_REPAINT_ARROWS
)
1358 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, FALSE
);
1363 INT
SCROLL_SetScrollInfo( HWND hwnd
, INT nBar
,
1364 const SCROLLINFO
*info
, INT
*action
)
1366 /* Update the scrollbar state and set action flags according to
1367 * what has to be done graphics wise. */
1369 SCROLLBAR_INFO
*infoPtr
;
1371 BOOL bChangeParams
= FALSE
; /* don't show/hide scrollbar if params don't change */
1375 if (!(infoPtr
= SCROLL_GetScrollInfo(hwnd
, nBar
))) return 0;
1376 if (info
->fMask
& ~(SIF_ALL
| SIF_DISABLENOSCROLL
)) return 0;
1377 if ((info
->cbSize
!= sizeof(*info
)) &&
1378 (info
->cbSize
!= sizeof(*info
)-sizeof(info
->nTrackPos
))) return 0;
1380 if (TRACE_ON(scroll
))
1382 TRACE("hwnd=%04x bar=%d", hwnd
, nBar
);
1383 if (info
->fMask
& SIF_PAGE
) DPRINTF( " page=%d", info
->nPage
);
1384 if (info
->fMask
& SIF_POS
) DPRINTF( " pos=%d", info
->nPos
);
1385 if (info
->fMask
& SIF_RANGE
) DPRINTF( " min=%d max=%d", info
->nMin
, info
->nMax
);
1389 /* Set the page size */
1391 if (info
->fMask
& SIF_PAGE
)
1393 if( infoPtr
->Page
!= info
->nPage
)
1395 infoPtr
->Page
= info
->nPage
;
1396 *action
|= SA_SSI_REFRESH
;
1397 bChangeParams
= TRUE
;
1401 /* Set the scroll pos */
1403 if (info
->fMask
& SIF_POS
)
1405 if( infoPtr
->CurVal
!= info
->nPos
)
1407 infoPtr
->CurVal
= info
->nPos
;
1408 *action
|= SA_SSI_REFRESH
;
1412 /* Set the scroll range */
1414 if (info
->fMask
& SIF_RANGE
)
1416 /* Invalid range -> range is set to (0,0) */
1417 if ((info
->nMin
> info
->nMax
) ||
1418 ((UINT
)(info
->nMax
- info
->nMin
) >= 0x80000000))
1420 infoPtr
->MinVal
= 0;
1421 infoPtr
->MaxVal
= 0;
1422 bChangeParams
= TRUE
;
1426 if( infoPtr
->MinVal
!= info
->nMin
||
1427 infoPtr
->MaxVal
!= info
->nMax
)
1429 *action
|= SA_SSI_REFRESH
;
1430 infoPtr
->MinVal
= info
->nMin
;
1431 infoPtr
->MaxVal
= info
->nMax
;
1432 bChangeParams
= TRUE
;
1437 /* Make sure the page size is valid */
1439 if (infoPtr
->Page
< 0) infoPtr
->Page
= 0;
1440 else if (infoPtr
->Page
> infoPtr
->MaxVal
- infoPtr
->MinVal
+ 1 )
1441 infoPtr
->Page
= infoPtr
->MaxVal
- infoPtr
->MinVal
+ 1;
1443 /* Make sure the pos is inside the range */
1445 if (infoPtr
->CurVal
< infoPtr
->MinVal
)
1446 infoPtr
->CurVal
= infoPtr
->MinVal
;
1447 else if (infoPtr
->CurVal
> infoPtr
->MaxVal
- max( infoPtr
->Page
-1, 0 ))
1448 infoPtr
->CurVal
= infoPtr
->MaxVal
- max( infoPtr
->Page
-1, 0 );
1450 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1451 infoPtr
->Page
, infoPtr
->CurVal
,
1452 infoPtr
->MinVal
, infoPtr
->MaxVal
);
1454 /* don't change the scrollbar state if SetScrollInfo
1455 * is just called with SIF_DISABLENOSCROLL
1457 if(!(info
->fMask
& SIF_ALL
)) goto done
;
1459 /* Check if the scrollbar should be hidden or disabled */
1461 if (info
->fMask
& (SIF_RANGE
| SIF_PAGE
| SIF_DISABLENOSCROLL
))
1463 new_flags
= infoPtr
->flags
;
1464 if (infoPtr
->MinVal
>= infoPtr
->MaxVal
- max( infoPtr
->Page
-1, 0 ))
1466 /* Hide or disable scroll-bar */
1467 if (info
->fMask
& SIF_DISABLENOSCROLL
)
1469 new_flags
= ESB_DISABLE_BOTH
;
1470 *action
|= SA_SSI_REFRESH
;
1472 else if ((nBar
!= SB_CTL
) && bChangeParams
)
1474 *action
= SA_SSI_HIDE
;
1478 else /* Show and enable scroll-bar */
1481 if ((nBar
!= SB_CTL
) && bChangeParams
)
1482 *action
|= SA_SSI_SHOW
;
1485 if (infoPtr
->flags
!= new_flags
) /* check arrow flags */
1487 infoPtr
->flags
= new_flags
;
1488 *action
|= SA_SSI_REPAINT_ARROWS
;
1493 /* Return current position */
1495 return infoPtr
->CurVal
;
1499 /*************************************************************************
1500 * GetScrollInfo (USER.476)
1502 BOOL16 WINAPI
GetScrollInfo16( HWND16 hwnd
, INT16 nBar
, LPSCROLLINFO info
)
1504 return GetScrollInfo( hwnd
, nBar
, info
);
1508 /*************************************************************************
1509 * GetScrollInfo (USER32.@)
1510 * GetScrollInfo can be used to retrieve the position, upper bound,
1511 * lower bound, and page size of a scrollbar control.
1515 BOOL WINAPI
GetScrollInfo(
1516 HWND hwnd
/* [in] Handle of window */ ,
1517 INT nBar
/* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1518 LPSCROLLINFO info
/* [in/out] (info.fMask [in] specifies which values are to retrieve) */)
1520 SCROLLBAR_INFO
*infoPtr
;
1522 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return FALSE
;
1523 if (info
->fMask
& ~(SIF_ALL
| SIF_DISABLENOSCROLL
)) return FALSE
;
1524 if ((info
->cbSize
!= sizeof(*info
)) &&
1525 (info
->cbSize
!= sizeof(*info
)-sizeof(info
->nTrackPos
))) return FALSE
;
1527 if (info
->fMask
& SIF_PAGE
) info
->nPage
= infoPtr
->Page
;
1528 if (info
->fMask
& SIF_POS
) info
->nPos
= infoPtr
->CurVal
;
1529 if ((info
->fMask
& SIF_TRACKPOS
) && (info
->cbSize
== sizeof(*info
)))
1530 info
->nTrackPos
= (SCROLL_TrackingWin
==hwnd
) ? SCROLL_TrackingVal
: infoPtr
->CurVal
;
1531 if (info
->fMask
& SIF_RANGE
)
1533 info
->nMin
= infoPtr
->MinVal
;
1534 info
->nMax
= infoPtr
->MaxVal
;
1536 return (info
->fMask
& SIF_ALL
) != 0;
1540 /*************************************************************************
1541 * SetScrollPos (USER.62)
1543 INT16 WINAPI
SetScrollPos16( HWND16 hwnd
, INT16 nBar
, INT16 nPos
,
1546 return (INT16
)SetScrollPos( hwnd
, nBar
, nPos
, bRedraw
);
1550 /*************************************************************************
1551 * SetScrollPos (USER32.@)
1554 * Success: Scrollbar position
1558 * Note the ambiguity when 0 is returned. Use GetLastError
1559 * to make sure there was an error (and to know which one).
1561 INT WINAPI
SetScrollPos(
1562 HWND hwnd
/* [in] Handle of window whose scrollbar will be affected */,
1563 INT nBar
/* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1564 INT nPos
/* [in] New value */,
1565 BOOL bRedraw
/* [in] Should scrollbar be redrawn afterwards ? */ )
1568 SCROLLBAR_INFO
*infoPtr
;
1571 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return 0;
1572 oldPos
= infoPtr
->CurVal
;
1573 info
.cbSize
= sizeof(info
);
1575 info
.fMask
= SIF_POS
;
1576 SetScrollInfo( hwnd
, nBar
, &info
, bRedraw
);
1581 /*************************************************************************
1582 * GetScrollPos (USER.63)
1584 INT16 WINAPI
GetScrollPos16( HWND16 hwnd
, INT16 nBar
)
1586 return (INT16
)GetScrollPos( hwnd
, nBar
);
1590 /*************************************************************************
1591 * GetScrollPos (USER32.@)
1594 * Success: Current position
1598 * Note the ambiguity when 0 is returned. Use GetLastError
1599 * to make sure there was an error (and to know which one).
1601 INT WINAPI
GetScrollPos(
1602 HWND hwnd
, /* [in] Handle of window */
1603 INT nBar
/* [in] One of SB_HORZ, SB_VERT, or SB_CTL */)
1605 SCROLLBAR_INFO
*infoPtr
;
1607 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return 0;
1608 return infoPtr
->CurVal
;
1612 /*************************************************************************
1613 * SetScrollRange (USER.64)
1615 void WINAPI
SetScrollRange16( HWND16 hwnd
, INT16 nBar
,
1616 INT16 MinVal
, INT16 MaxVal
, BOOL16 bRedraw
)
1618 /* Invalid range -> range is set to (0,0) */
1619 if ((INT
)MaxVal
- (INT
)MinVal
> 0x7fff) MinVal
= MaxVal
= 0;
1620 SetScrollRange( hwnd
, nBar
, MinVal
, MaxVal
, bRedraw
);
1624 /*************************************************************************
1625 * SetScrollRange (USER32.@)
1629 BOOL WINAPI
SetScrollRange(
1630 HWND hwnd
, /* [in] Handle of window whose scrollbar will be affected */
1631 INT nBar
, /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */
1632 INT MinVal
, /* [in] New minimum value */
1633 INT MaxVal
, /* [in] New maximum value */
1634 BOOL bRedraw
/* [in] Should scrollbar be redrawn afterwards ? */)
1638 info
.cbSize
= sizeof(info
);
1641 info
.fMask
= SIF_RANGE
;
1642 SetScrollInfo( hwnd
, nBar
, &info
, bRedraw
);
1647 /*************************************************************************
1648 * SCROLL_SetNCSbState
1650 * Updates both scrollbars at the same time. Used by MDI CalcChildScroll().
1652 INT
SCROLL_SetNCSbState(WND
* wndPtr
, int vMin
, int vMax
, int vPos
,
1653 int hMin
, int hMax
, int hPos
)
1656 SCROLLINFO vInfo
, hInfo
;
1658 vInfo
.cbSize
= hInfo
.cbSize
= sizeof(SCROLLINFO
);
1659 vInfo
.nMin
= vMin
; hInfo
.nMin
= hMin
;
1660 vInfo
.nMax
= vMax
; hInfo
.nMax
= hMax
;
1661 vInfo
.nPos
= vPos
; hInfo
.nPos
= hPos
;
1662 vInfo
.fMask
= hInfo
.fMask
= SIF_RANGE
| SIF_POS
;
1664 SCROLL_SetScrollInfo( wndPtr
->hwndSelf
, SB_VERT
, &vInfo
, &vA
);
1665 SCROLL_SetScrollInfo( wndPtr
->hwndSelf
, SB_HORZ
, &hInfo
, &hA
);
1667 if( !SCROLL_ShowScrollBar( wndPtr
->hwndSelf
, SB_BOTH
,
1668 (hA
& SA_SSI_SHOW
),(vA
& SA_SSI_SHOW
) ) )
1670 /* SetWindowPos() wasn't called, just redraw the scrollbars if needed */
1671 if( vA
& SA_SSI_REFRESH
)
1672 SCROLL_RefreshScrollBar( wndPtr
->hwndSelf
, SB_VERT
, FALSE
, TRUE
);
1674 if( hA
& SA_SSI_REFRESH
)
1675 SCROLL_RefreshScrollBar( wndPtr
->hwndSelf
, SB_HORZ
, FALSE
, TRUE
);
1681 /*************************************************************************
1682 * GetScrollRange (USER.65)
1684 BOOL16 WINAPI
GetScrollRange16( HWND16 hwnd
, INT16 nBar
,
1685 LPINT16 lpMin
, LPINT16 lpMax
)
1688 BOOL16 ret
= GetScrollRange( hwnd
, nBar
, &min
, &max
);
1689 if (lpMin
) *lpMin
= min
;
1690 if (lpMax
) *lpMax
= max
;
1695 /*************************************************************************
1696 * GetScrollRange (USER32.@)
1700 BOOL WINAPI
GetScrollRange(
1701 HWND hwnd
, /* [in] Handle of window */
1702 INT nBar
, /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */
1703 LPINT lpMin
, /* [out] Where to store minimum value */
1704 LPINT lpMax
/* [out] Where to store maximum value */)
1706 SCROLLBAR_INFO
*infoPtr
;
1708 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
)))
1710 if (lpMin
) lpMin
= 0;
1711 if (lpMax
) lpMax
= 0;
1714 if (lpMin
) *lpMin
= infoPtr
->MinVal
;
1715 if (lpMax
) *lpMax
= infoPtr
->MaxVal
;
1720 /*************************************************************************
1721 * SCROLL_ShowScrollBar()
1723 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1725 BOOL
SCROLL_ShowScrollBar( HWND hwnd
, INT nBar
,
1726 BOOL fShowH
, BOOL fShowV
)
1728 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
1729 BOOL retvalue
= FALSE
;
1731 if (!wndPtr
) return FALSE
;
1732 TRACE("hwnd=%04x bar=%d horz=%d, vert=%d\n",
1733 hwnd
, nBar
, fShowH
, fShowV
);
1738 ShowWindow( hwnd
, fShowH
? SW_SHOW
: SW_HIDE
);
1746 fShowH
= !(wndPtr
->dwStyle
& WS_HSCROLL
);
1747 wndPtr
->dwStyle
|= WS_HSCROLL
;
1751 fShowH
= (wndPtr
->dwStyle
& WS_HSCROLL
);
1752 wndPtr
->dwStyle
&= ~WS_HSCROLL
;
1754 if( nBar
== SB_HORZ
) {
1763 fShowV
= !(wndPtr
->dwStyle
& WS_VSCROLL
);
1764 wndPtr
->dwStyle
|= WS_VSCROLL
;
1768 fShowV
= (wndPtr
->dwStyle
& WS_VSCROLL
);
1769 wndPtr
->dwStyle
&= ~WS_VSCROLL
;
1771 if ( nBar
== SB_VERT
)
1776 retvalue
= FALSE
; /* Nothing to do! */
1780 if( fShowH
|| fShowV
) /* frame has been changed, let the window redraw itself */
1782 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
1783 | SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
1788 retvalue
= FALSE
; /* no frame changes */
1790 WIN_ReleaseWndPtr(wndPtr
);
1795 /*************************************************************************
1796 * ShowScrollBar (USER.267)
1798 void WINAPI
ShowScrollBar16( HWND16 hwnd
, INT16 nBar
, BOOL16 fShow
)
1800 SCROLL_ShowScrollBar( hwnd
, nBar
, (nBar
== SB_VERT
) ? 0 : fShow
,
1801 (nBar
== SB_HORZ
) ? 0 : fShow
);
1805 /*************************************************************************
1806 * ShowScrollBar (USER32.@)
1810 BOOL WINAPI
ShowScrollBar(
1811 HWND hwnd
, /* [in] Handle of window whose scrollbar(s) will be affected */
1812 INT nBar
, /* [in] One of SB_HORZ, SB_VERT, SB_BOTH or SB_CTL */
1813 BOOL fShow
/* [in] TRUE = show, FALSE = hide */)
1815 SCROLL_ShowScrollBar( hwnd
, nBar
, (nBar
== SB_VERT
) ? 0 : fShow
,
1816 (nBar
== SB_HORZ
) ? 0 : fShow
);
1821 /*************************************************************************
1822 * EnableScrollBar (USER.482)
1824 BOOL16 WINAPI
EnableScrollBar16( HWND16 hwnd
, INT16 nBar
, UINT16 flags
)
1826 return EnableScrollBar( hwnd
, nBar
, flags
);
1830 /*************************************************************************
1831 * EnableScrollBar (USER32.@)
1833 BOOL WINAPI
EnableScrollBar( HWND hwnd
, INT nBar
, UINT flags
)
1836 SCROLLBAR_INFO
*infoPtr
;
1838 TRACE("%04x %d %d\n", hwnd
, nBar
, flags
);
1840 flags
&= ESB_DISABLE_BOTH
;
1842 if (nBar
== SB_BOTH
)
1844 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, SB_VERT
))) return FALSE
;
1845 if (!(bFineWithMe
= (infoPtr
->flags
== flags
)) )
1847 infoPtr
->flags
= flags
;
1848 SCROLL_RefreshScrollBar( hwnd
, SB_VERT
, TRUE
, TRUE
);
1855 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return FALSE
;
1856 if (bFineWithMe
&& infoPtr
->flags
== flags
) return FALSE
;
1857 infoPtr
->flags
= flags
;
1859 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, TRUE
);