4 * Copyright 1993 Martin Ayotte
5 * Copyright 1994, 1996 Alexandre Julliard
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "wine/winuser16.h"
27 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(scroll
);
35 INT CurVal
; /* Current scroll-bar value */
36 INT MinVal
; /* Minimum scroll-bar value */
37 INT MaxVal
; /* Maximum scroll-bar value */
38 INT Page
; /* Page size of scroll bar (Win32) */
39 UINT flags
; /* EnableScrollBar flags */
43 static HBITMAP hUpArrow
;
44 static HBITMAP hDnArrow
;
45 static HBITMAP hLfArrow
;
46 static HBITMAP hRgArrow
;
47 static HBITMAP hUpArrowD
;
48 static HBITMAP hDnArrowD
;
49 static HBITMAP hLfArrowD
;
50 static HBITMAP hRgArrowD
;
51 static HBITMAP hUpArrowI
;
52 static HBITMAP hDnArrowI
;
53 static HBITMAP hLfArrowI
;
54 static HBITMAP hRgArrowI
;
56 #define TOP_ARROW(flags,pressed) \
57 (((flags)&ESB_DISABLE_UP) ? hUpArrowI : ((pressed) ? hUpArrowD:hUpArrow))
58 #define BOTTOM_ARROW(flags,pressed) \
59 (((flags)&ESB_DISABLE_DOWN) ? hDnArrowI : ((pressed) ? hDnArrowD:hDnArrow))
60 #define LEFT_ARROW(flags,pressed) \
61 (((flags)&ESB_DISABLE_LEFT) ? hLfArrowI : ((pressed) ? hLfArrowD:hLfArrow))
62 #define RIGHT_ARROW(flags,pressed) \
63 (((flags)&ESB_DISABLE_RIGHT) ? hRgArrowI : ((pressed) ? hRgArrowD:hRgArrow))
66 /* Minimum size of the rectangle between the arrows */
67 #define SCROLL_MIN_RECT 4
69 /* Minimum size of the thumb in pixels */
70 #define SCROLL_MIN_THUMB 6
72 /* Overlap between arrows and thumb */
73 #define SCROLL_ARROW_THUMB_OVERLAP ((TWEAK_WineLook == WIN31_LOOK) ? 1 : 0)
75 /* Delay (in ms) before first repetition when holding the button down */
76 #define SCROLL_FIRST_DELAY 200
78 /* Delay (in ms) between scroll repetitions */
79 #define SCROLL_REPEAT_DELAY 50
82 #define SCROLL_TIMER 0
84 /* Scroll-bar hit testing */
87 SCROLL_NOWHERE
, /* Outside the scroll bar */
88 SCROLL_TOP_ARROW
, /* Top or left arrow */
89 SCROLL_TOP_RECT
, /* Rectangle between the top arrow and the thumb */
90 SCROLL_THUMB
, /* Thumb rectangle */
91 SCROLL_BOTTOM_RECT
, /* Rectangle between the thumb and the bottom arrow */
92 SCROLL_BOTTOM_ARROW
/* Bottom or right arrow */
95 /* What to do after SCROLL_SetScrollInfo() */
96 #define SA_SSI_HIDE 0x0001
97 #define SA_SSI_SHOW 0x0002
98 #define SA_SSI_REFRESH 0x0004
99 #define SA_SSI_REPAINT_ARROWS 0x0008
101 /* Thumb-tracking info */
102 static HWND SCROLL_TrackingWin
= 0;
103 static INT SCROLL_TrackingBar
= 0;
104 static INT SCROLL_TrackingPos
= 0;
105 static INT SCROLL_TrackingVal
= 0;
106 /* Hit test code of the last button-down event */
107 static enum SCROLL_HITTEST SCROLL_trackHitTest
;
108 static BOOL SCROLL_trackVertical
;
110 /* Is the moving thumb being displayed? */
111 static BOOL SCROLL_MovingThumb
= FALSE
;
113 /* Local functions */
114 static BOOL
SCROLL_ShowScrollBar( HWND hwnd
, INT nBar
,
115 BOOL fShowH
, BOOL fShowV
);
116 static INT
SCROLL_SetScrollInfo( HWND hwnd
, INT nBar
,
117 const SCROLLINFO
*info
, INT
*action
);
118 static void SCROLL_DrawInterior_9x( HWND hwnd
, HDC hdc
, INT nBar
,
119 RECT
*rect
, INT arrowSize
,
120 INT thumbSize
, INT thumbPos
,
121 UINT flags
, BOOL vertical
,
122 BOOL top_selected
, BOOL bottom_selected
);
123 static LRESULT WINAPI
ScrollBarWndProc( HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
126 /*********************************************************************
127 * scrollbar class descriptor
129 const struct builtin_class_descr SCROLL_builtin_class
=
131 "ScrollBar", /* name */
132 CS_GLOBALCLASS
| CS_DBLCLKS
| CS_VREDRAW
| CS_HREDRAW
| CS_PARENTDC
, /* style */
133 NULL
, /* procA (winproc is Unicode only) */
134 ScrollBarWndProc
, /* procW */
135 sizeof(SCROLLBAR_INFO
), /* extra */
136 IDC_ARROWA
, /* cursor */
141 /***********************************************************************
144 static void SCROLL_LoadBitmaps(void)
146 hUpArrow
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROW
) );
147 hDnArrow
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROW
) );
148 hLfArrow
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROW
) );
149 hRgArrow
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROW
) );
150 hUpArrowD
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROWD
) );
151 hDnArrowD
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROWD
) );
152 hLfArrowD
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROWD
) );
153 hRgArrowD
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROWD
) );
154 hUpArrowI
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROWI
) );
155 hDnArrowI
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROWI
) );
156 hLfArrowI
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROWI
) );
157 hRgArrowI
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROWI
) );
161 /***********************************************************************
162 * SCROLL_GetScrollInfo
164 static SCROLLBAR_INFO
*SCROLL_GetScrollInfo( HWND hwnd
, INT nBar
)
166 SCROLLBAR_INFO
*infoPtr
;
167 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
169 if (!wndPtr
) return NULL
;
172 case SB_HORZ
: infoPtr
= (SCROLLBAR_INFO
*)wndPtr
->pHScroll
; break;
173 case SB_VERT
: infoPtr
= (SCROLLBAR_INFO
*)wndPtr
->pVScroll
; break;
174 case SB_CTL
: infoPtr
= (SCROLLBAR_INFO
*)wndPtr
->wExtra
; break;
176 WIN_ReleaseWndPtr( wndPtr
);
180 if (!infoPtr
) /* Create the info structure if needed */
182 if ((infoPtr
= HeapAlloc( GetProcessHeap(), 0, sizeof(SCROLLBAR_INFO
) )))
184 infoPtr
->MinVal
= infoPtr
->CurVal
= infoPtr
->Page
= 0;
185 infoPtr
->MaxVal
= 100;
186 infoPtr
->flags
= ESB_ENABLE_BOTH
;
187 if (nBar
== SB_HORZ
) wndPtr
->pHScroll
= infoPtr
;
188 else wndPtr
->pVScroll
= infoPtr
;
190 if (!hUpArrow
) SCROLL_LoadBitmaps();
192 WIN_ReleaseWndPtr( wndPtr
);
197 /***********************************************************************
198 * SCROLL_GetScrollBarRect
200 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
201 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
202 * 'arrowSize' returns the width or height of an arrow (depending on
203 * the orientation of the scrollbar), 'thumbSize' returns the size of
204 * the thumb, and 'thumbPos' returns the position of the thumb
205 * relative to the left or to the top.
206 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
208 static BOOL
SCROLL_GetScrollBarRect( HWND hwnd
, INT nBar
, RECT
*lprect
,
209 INT
*arrowSize
, INT
*thumbSize
,
214 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
219 lprect
->left
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
220 lprect
->top
= wndPtr
->rectClient
.bottom
- wndPtr
->rectWindow
.top
;
221 lprect
->right
= wndPtr
->rectClient
.right
- wndPtr
->rectWindow
.left
;
222 lprect
->bottom
= lprect
->top
+ GetSystemMetrics(SM_CYHSCROLL
);
223 if(wndPtr
->dwStyle
& WS_BORDER
) {
226 } else if(wndPtr
->dwStyle
& WS_VSCROLL
)
232 lprect
->left
= wndPtr
->rectClient
.right
- wndPtr
->rectWindow
.left
;
233 lprect
->top
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
234 lprect
->right
= lprect
->left
+ GetSystemMetrics(SM_CXVSCROLL
);
235 lprect
->bottom
= wndPtr
->rectClient
.bottom
- wndPtr
->rectWindow
.top
;
236 if(wndPtr
->dwStyle
& WS_BORDER
) {
239 } else if(wndPtr
->dwStyle
& WS_HSCROLL
)
245 GetClientRect( hwnd
, lprect
);
246 vertical
= ((wndPtr
->dwStyle
& SBS_VERT
) != 0);
250 WIN_ReleaseWndPtr(wndPtr
);
254 if (vertical
) pixels
= lprect
->bottom
- lprect
->top
;
255 else pixels
= lprect
->right
- lprect
->left
;
257 if (pixels
<= 2*GetSystemMetrics(SM_CXVSCROLL
) + SCROLL_MIN_RECT
)
259 if (pixels
> SCROLL_MIN_RECT
)
260 *arrowSize
= (pixels
- SCROLL_MIN_RECT
) / 2;
263 *thumbPos
= *thumbSize
= 0;
267 SCROLLBAR_INFO
*info
= SCROLL_GetScrollInfo( hwnd
, nBar
);
269 *arrowSize
= GetSystemMetrics(SM_CXVSCROLL
);
270 pixels
-= (2 * (GetSystemMetrics(SM_CXVSCROLL
) - SCROLL_ARROW_THUMB_OVERLAP
));
274 *thumbSize
= MulDiv(pixels
,info
->Page
,(info
->MaxVal
-info
->MinVal
+1));
275 if (*thumbSize
< SCROLL_MIN_THUMB
) *thumbSize
= SCROLL_MIN_THUMB
;
277 else *thumbSize
= GetSystemMetrics(SM_CXVSCROLL
);
279 if (((pixels
-= *thumbSize
) < 0) ||
280 ((info
->flags
& ESB_DISABLE_BOTH
) == ESB_DISABLE_BOTH
))
282 /* Rectangle too small or scrollbar disabled -> no thumb */
283 *thumbPos
= *thumbSize
= 0;
287 INT max
= info
->MaxVal
- max( info
->Page
-1, 0 );
288 if (info
->MinVal
>= max
)
289 *thumbPos
= *arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
291 *thumbPos
= *arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
292 + MulDiv(pixels
, (info
->CurVal
-info
->MinVal
),(max
- info
->MinVal
));
295 WIN_ReleaseWndPtr(wndPtr
);
300 /***********************************************************************
303 * Compute the current scroll position based on the thumb position in pixels
304 * from the top of the scroll-bar.
306 static UINT
SCROLL_GetThumbVal( SCROLLBAR_INFO
*infoPtr
, RECT
*rect
,
307 BOOL vertical
, INT pos
)
310 INT pixels
= vertical
? rect
->bottom
-rect
->top
: rect
->right
-rect
->left
;
312 if ((pixels
-= 2*(GetSystemMetrics(SM_CXVSCROLL
) - SCROLL_ARROW_THUMB_OVERLAP
)) <= 0)
313 return infoPtr
->MinVal
;
317 thumbSize
= MulDiv(pixels
,infoPtr
->Page
,(infoPtr
->MaxVal
-infoPtr
->MinVal
+1));
318 if (thumbSize
< SCROLL_MIN_THUMB
) thumbSize
= SCROLL_MIN_THUMB
;
320 else thumbSize
= GetSystemMetrics(SM_CXVSCROLL
);
322 if ((pixels
-= thumbSize
) <= 0) return infoPtr
->MinVal
;
324 pos
= max( 0, pos
- (GetSystemMetrics(SM_CXVSCROLL
) - SCROLL_ARROW_THUMB_OVERLAP
) );
325 if (pos
> pixels
) pos
= pixels
;
327 if (!infoPtr
->Page
) pos
*= infoPtr
->MaxVal
- infoPtr
->MinVal
;
328 else pos
*= infoPtr
->MaxVal
- infoPtr
->MinVal
- infoPtr
->Page
+ 1;
329 return infoPtr
->MinVal
+ ((pos
+ pixels
/ 2) / pixels
);
332 /***********************************************************************
335 static BOOL
SCROLL_PtInRectEx( LPRECT lpRect
, POINT pt
, BOOL vertical
)
341 rect
.left
-= lpRect
->right
- lpRect
->left
;
342 rect
.right
+= lpRect
->right
- lpRect
->left
;
346 rect
.top
-= lpRect
->bottom
- lpRect
->top
;
347 rect
.bottom
+= lpRect
->bottom
- lpRect
->top
;
349 return PtInRect( &rect
, pt
);
352 /***********************************************************************
355 static POINT
SCROLL_ClipPos( LPRECT lpRect
, POINT pt
)
357 if( pt
.x
< lpRect
->left
)
360 if( pt
.x
> lpRect
->right
)
361 pt
.x
= lpRect
->right
;
363 if( pt
.y
< lpRect
->top
)
366 if( pt
.y
> lpRect
->bottom
)
367 pt
.y
= lpRect
->bottom
;
373 /***********************************************************************
376 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
378 static enum SCROLL_HITTEST
SCROLL_HitTest( HWND hwnd
, INT nBar
,
379 POINT pt
, BOOL bDragging
)
381 INT arrowSize
, thumbSize
, thumbPos
;
384 BOOL vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
385 &arrowSize
, &thumbSize
, &thumbPos
);
387 if ( (bDragging
&& !SCROLL_PtInRectEx( &rect
, pt
, vertical
)) ||
388 (!PtInRect( &rect
, pt
)) ) return SCROLL_NOWHERE
;
392 if (pt
.y
< rect
.top
+ arrowSize
) return SCROLL_TOP_ARROW
;
393 if (pt
.y
>= rect
.bottom
- arrowSize
) return SCROLL_BOTTOM_ARROW
;
394 if (!thumbPos
) return SCROLL_TOP_RECT
;
396 if (pt
.y
< thumbPos
) return SCROLL_TOP_RECT
;
397 if (pt
.y
>= thumbPos
+ thumbSize
) return SCROLL_BOTTOM_RECT
;
399 else /* horizontal */
401 if (pt
.x
< rect
.left
+ arrowSize
) return SCROLL_TOP_ARROW
;
402 if (pt
.x
>= rect
.right
- arrowSize
) return SCROLL_BOTTOM_ARROW
;
403 if (!thumbPos
) return SCROLL_TOP_RECT
;
405 if (pt
.x
< thumbPos
) return SCROLL_TOP_RECT
;
406 if (pt
.x
>= thumbPos
+ thumbSize
) return SCROLL_BOTTOM_RECT
;
412 /***********************************************************************
415 * Draw the scroll bar arrows.
417 static void SCROLL_DrawArrows_9x( HDC hdc
, SCROLLBAR_INFO
*infoPtr
,
418 RECT
*rect
, INT arrowSize
, BOOL vertical
,
419 BOOL top_pressed
, BOOL bottom_pressed
)
425 r
.bottom
= r
.top
+ arrowSize
;
427 r
.right
= r
.left
+ arrowSize
;
429 DrawFrameControl( hdc
, &r
, DFC_SCROLL
,
430 (vertical
? DFCS_SCROLLUP
: DFCS_SCROLLLEFT
)
431 | (top_pressed
? (DFCS_PUSHED
| DFCS_FLAT
) : 0 )
432 | (infoPtr
->flags
&ESB_DISABLE_LTUP
? DFCS_INACTIVE
: 0 ) );
436 r
.top
= r
.bottom
-arrowSize
;
438 r
.left
= r
.right
-arrowSize
;
440 DrawFrameControl( hdc
, &r
, DFC_SCROLL
,
441 (vertical
? DFCS_SCROLLDOWN
: DFCS_SCROLLRIGHT
)
442 | (bottom_pressed
? (DFCS_PUSHED
| DFCS_FLAT
) : 0 )
443 | (infoPtr
->flags
&ESB_DISABLE_RTDN
? DFCS_INACTIVE
: 0) );
446 static void SCROLL_DrawArrows_31( HDC hdc
, SCROLLBAR_INFO
*infoPtr
,
447 RECT
*rect
, INT arrowSize
, BOOL vertical
,
448 BOOL top_pressed
, BOOL bottom_pressed
)
450 HDC hdcMem
= CreateCompatibleDC( hdc
);
451 HBITMAP hbmpPrev
= SelectObject( hdcMem
, vertical
?
452 TOP_ARROW(infoPtr
->flags
, top_pressed
)
453 : LEFT_ARROW(infoPtr
->flags
, top_pressed
));
455 SetStretchBltMode( hdc
, STRETCH_DELETESCANS
);
456 StretchBlt( hdc
, rect
->left
, rect
->top
,
457 vertical
? rect
->right
-rect
->left
: arrowSize
,
458 vertical
? arrowSize
: rect
->bottom
-rect
->top
,
460 GetSystemMetrics(SM_CXVSCROLL
),GetSystemMetrics(SM_CYHSCROLL
),
463 SelectObject( hdcMem
, vertical
?
464 BOTTOM_ARROW( infoPtr
->flags
, bottom_pressed
)
465 : RIGHT_ARROW( infoPtr
->flags
, bottom_pressed
) );
467 StretchBlt( hdc
, rect
->left
, rect
->bottom
- arrowSize
,
468 rect
->right
- rect
->left
, arrowSize
,
470 GetSystemMetrics(SM_CXVSCROLL
),GetSystemMetrics(SM_CYHSCROLL
),
473 StretchBlt( hdc
, rect
->right
- arrowSize
, rect
->top
,
474 arrowSize
, rect
->bottom
- rect
->top
,
476 GetSystemMetrics(SM_CXVSCROLL
), GetSystemMetrics(SM_CYHSCROLL
),
478 SelectObject( hdcMem
, hbmpPrev
);
482 static void SCROLL_DrawArrows( HDC hdc
, SCROLLBAR_INFO
*infoPtr
,
483 RECT
*rect
, INT arrowSize
, BOOL vertical
,
484 BOOL top_pressed
, BOOL bottom_pressed
)
486 if( TWEAK_WineLook
== WIN31_LOOK
)
487 SCROLL_DrawArrows_31( hdc
, infoPtr
, rect
, arrowSize
,
488 vertical
, top_pressed
,bottom_pressed
);
490 SCROLL_DrawArrows_9x( hdc
, infoPtr
, rect
, arrowSize
,
491 vertical
, top_pressed
,bottom_pressed
);
495 /***********************************************************************
496 * SCROLL_DrawMovingThumb
498 * Draw the moving thumb rectangle.
500 static void SCROLL_DrawMovingThumb_31( HDC hdc
, RECT
*rect
, BOOL vertical
,
501 INT arrowSize
, INT thumbSize
)
506 r
.top
+= SCROLL_TrackingPos
;
507 if (r
.top
< rect
->top
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
508 r
.top
= rect
->top
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
509 if (r
.top
+ thumbSize
>
510 rect
->bottom
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
))
511 r
.top
= rect
->bottom
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
513 r
.bottom
= r
.top
+ thumbSize
;
517 r
.left
+= SCROLL_TrackingPos
;
518 if (r
.left
< rect
->left
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
519 r
.left
= rect
->left
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
520 if (r
.left
+ thumbSize
>
521 rect
->right
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
))
522 r
.left
= rect
->right
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
524 r
.right
= r
.left
+ thumbSize
;
527 DrawFocusRect( hdc
, &r
);
528 SCROLL_MovingThumb
= !SCROLL_MovingThumb
;
531 static void SCROLL_DrawMovingThumb_9x( HDC hdc
, RECT
*rect
, BOOL vertical
,
532 INT arrowSize
, INT thumbSize
)
534 INT pos
= SCROLL_TrackingPos
;
538 max_size
= rect
->bottom
- rect
->top
;
540 max_size
= rect
->right
- rect
->left
;
542 max_size
-= (arrowSize
-SCROLL_ARROW_THUMB_OVERLAP
) + thumbSize
;
544 if( pos
< (arrowSize
-SCROLL_ARROW_THUMB_OVERLAP
) )
545 pos
= (arrowSize
-SCROLL_ARROW_THUMB_OVERLAP
);
546 else if( pos
> max_size
)
549 SCROLL_DrawInterior_9x( SCROLL_TrackingWin
, hdc
, SCROLL_TrackingBar
,
550 rect
, arrowSize
, thumbSize
, pos
,
551 0, vertical
, FALSE
, FALSE
);
553 SCROLL_MovingThumb
= !SCROLL_MovingThumb
;
556 static void SCROLL_DrawMovingThumb( HDC hdc
, RECT
*rect
, BOOL vertical
,
557 INT arrowSize
, INT thumbSize
)
559 if( TWEAK_WineLook
== WIN31_LOOK
)
560 SCROLL_DrawMovingThumb_31( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
562 SCROLL_DrawMovingThumb_9x( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
565 /***********************************************************************
566 * SCROLL_DrawInterior
568 * Draw the scroll bar interior (everything except the arrows).
570 static void SCROLL_DrawInterior_9x( HWND hwnd
, HDC hdc
, INT nBar
,
571 RECT
*rect
, INT arrowSize
,
572 INT thumbSize
, INT thumbPos
,
573 UINT flags
, BOOL vertical
,
574 BOOL top_selected
, BOOL bottom_selected
)
578 HBRUSH hSaveBrush
,hBrush
;
580 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
581 * The window-owned scrollbars need to call DEFWND_ControlColor
582 * to correctly setup default scrollbar colors
586 hBrush
= (HBRUSH
)SendMessageA( GetParent(hwnd
), WM_CTLCOLORSCROLLBAR
,
587 (WPARAM
)hdc
,(LPARAM
)hwnd
);
591 hBrush
= DEFWND_ControlColor( hdc
, CTLCOLOR_SCROLLBAR
);
594 hSavePen
= SelectObject( hdc
, SYSCOLOR_GetPen(COLOR_WINDOWFRAME
) );
595 hSaveBrush
= SelectObject( hdc
, hBrush
);
597 /* Calculate the scroll rectangle */
601 r
.top
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
602 r
.bottom
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
606 r
.left
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
607 r
.right
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
610 /* Draw the scroll rectangles and thumb */
611 if (!thumbPos
) /* No thumb to draw */
613 PatBlt( hdc
, r
.left
, r
.top
,
614 r
.right
- r
.left
, r
.bottom
- r
.top
,
617 /* cleanup and return */
618 SelectObject( hdc
, hSavePen
);
619 SelectObject( hdc
, hSaveBrush
);
625 PatBlt( hdc
, r
.left
, r
.top
,
627 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
),
628 top_selected
? 0x0f0000 : PATCOPY
);
629 r
.top
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
630 PatBlt( hdc
, r
.left
, r
.top
+ thumbSize
,
632 r
.bottom
- r
.top
- thumbSize
,
633 bottom_selected
? 0x0f0000 : PATCOPY
);
634 r
.bottom
= r
.top
+ thumbSize
;
636 else /* horizontal */
638 PatBlt( hdc
, r
.left
, r
.top
,
639 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
),
641 top_selected
? 0x0f0000 : PATCOPY
);
642 r
.left
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
643 PatBlt( hdc
, r
.left
+ thumbSize
, r
.top
,
644 r
.right
- r
.left
- thumbSize
,
646 bottom_selected
? 0x0f0000 : PATCOPY
);
647 r
.right
= r
.left
+ thumbSize
;
651 DrawEdge( hdc
, &r
, EDGE_RAISED
, BF_RECT
| BF_MIDDLE
);
654 SelectObject( hdc
, hSavePen
);
655 SelectObject( hdc
, hSaveBrush
);
659 static void SCROLL_DrawInterior( HWND hwnd
, HDC hdc
, INT nBar
,
660 RECT
*rect
, INT arrowSize
,
661 INT thumbSize
, INT thumbPos
,
662 UINT flags
, BOOL vertical
,
663 BOOL top_selected
, BOOL bottom_selected
)
667 HBRUSH hSaveBrush
,hBrush
;
668 BOOL Save_SCROLL_MovingThumb
= SCROLL_MovingThumb
;
670 if (Save_SCROLL_MovingThumb
&&
671 (SCROLL_TrackingWin
== hwnd
) &&
672 (SCROLL_TrackingBar
== nBar
))
673 SCROLL_DrawMovingThumb( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
675 /* Select the correct brush and pen */
677 if (TWEAK_WineLook
== WIN31_LOOK
&& (flags
& ESB_DISABLE_BOTH
) == ESB_DISABLE_BOTH
)
679 /* This ought to be the color of the parent window */
680 hBrush
= GetSysColorBrush(COLOR_WINDOW
);
684 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
685 * The window-owned scrollbars need to call DEFWND_ControlColor
686 * to correctly setup default scrollbar colors
688 if (nBar
== SB_CTL
) {
689 hBrush
= (HBRUSH
)SendMessageA( GetParent(hwnd
), WM_CTLCOLORSCROLLBAR
,
690 (WPARAM
)hdc
,(LPARAM
)hwnd
);
692 hBrush
= DEFWND_ControlColor( hdc
, CTLCOLOR_SCROLLBAR
);
695 hSavePen
= SelectObject( hdc
, SYSCOLOR_GetPen(COLOR_WINDOWFRAME
) );
696 hSaveBrush
= SelectObject( hdc
, hBrush
);
698 /* Calculate the scroll rectangle */
703 r
.top
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
704 r
.bottom
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
708 r
.left
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
709 r
.right
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
712 /* Draw the scroll bar frame */
714 /* Only draw outline if Win 3.1. Mar 24, 1999 - Ronald B. Cemer */
715 if (TWEAK_WineLook
== WIN31_LOOK
)
716 Rectangle( hdc
, r
.left
, r
.top
, r
.right
, r
.bottom
);
718 /* Draw the scroll rectangles and thumb */
720 if (!thumbPos
) /* No thumb to draw */
722 INT offset
= (TWEAK_WineLook
> WIN31_LOOK
) ? 0 : 1;
724 PatBlt( hdc
, r
.left
+offset
, r
.top
+offset
,
725 r
.right
- r
.left
- 2*offset
, r
.bottom
- r
.top
- 2*offset
,
728 /* cleanup and return */
729 SelectObject( hdc
, hSavePen
);
730 SelectObject( hdc
, hSaveBrush
);
736 INT offset
= (TWEAK_WineLook
== WIN31_LOOK
) ? 1 : 0;
738 PatBlt( hdc
, r
.left
+ offset
, r
.top
+ offset
,
739 r
.right
- r
.left
- offset
*2,
740 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
) - offset
,
741 top_selected
? 0x0f0000 : PATCOPY
);
742 r
.top
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
743 PatBlt( hdc
, r
.left
+ offset
, r
.top
+ thumbSize
,
744 r
.right
- r
.left
- offset
*2,
745 r
.bottom
- r
.top
- thumbSize
- offset
,
746 bottom_selected
? 0x0f0000 : PATCOPY
);
747 r
.bottom
= r
.top
+ thumbSize
;
749 else /* horizontal */
751 INT offset
= (TWEAK_WineLook
== WIN31_LOOK
) ? 1 : 0;
753 PatBlt( hdc
, r
.left
+ offset
, r
.top
+ offset
,
754 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
),
755 r
.bottom
- r
.top
- offset
*2,
756 top_selected
? 0x0f0000 : PATCOPY
);
757 r
.left
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
758 PatBlt( hdc
, r
.left
+ thumbSize
, r
.top
+ offset
,
759 r
.right
- r
.left
- thumbSize
- offset
,
760 r
.bottom
- r
.top
- offset
*2,
761 bottom_selected
? 0x0f0000 : PATCOPY
);
762 r
.right
= r
.left
+ thumbSize
;
767 SelectObject( hdc
, GetSysColorBrush(COLOR_BTNFACE
) );
768 if (TWEAK_WineLook
== WIN31_LOOK
)
770 Rectangle( hdc
, r
.left
, r
.top
, r
.right
, r
.bottom
);
775 Rectangle( hdc
, r
.left
+1, r
.top
+1, r
.right
-1, r
.bottom
-1 );
777 DrawEdge( hdc
, &r
, EDGE_RAISED
, BF_RECT
);
779 if (Save_SCROLL_MovingThumb
&&
780 (SCROLL_TrackingWin
== hwnd
) &&
781 (SCROLL_TrackingBar
== nBar
))
782 SCROLL_DrawMovingThumb( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
785 SelectObject( hdc
, hSavePen
);
786 SelectObject( hdc
, hSaveBrush
);
790 /***********************************************************************
791 * SCROLL_DrawScrollBar
793 * Redraw the whole scrollbar.
795 void SCROLL_DrawScrollBar( HWND hwnd
, HDC hdc
, INT nBar
,
796 BOOL arrows
, BOOL interior
)
798 INT arrowSize
, thumbSize
, thumbPos
;
801 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
802 SCROLLBAR_INFO
*infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
);
803 BOOL Save_SCROLL_MovingThumb
= SCROLL_MovingThumb
;
805 if (!wndPtr
|| !infoPtr
||
806 ((nBar
== SB_VERT
) && !(wndPtr
->dwStyle
& WS_VSCROLL
)) ||
807 ((nBar
== SB_HORZ
) && !(wndPtr
->dwStyle
& WS_HSCROLL
))) goto END
;
808 if (!WIN_IsWindowDrawable( hwnd
, FALSE
)) goto END
;
809 hwnd
= wndPtr
->hwndSelf
; /* make it a full handle */
811 vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
812 &arrowSize
, &thumbSize
, &thumbPos
);
814 /* do not draw if the scrollbar rectangle is empty */
815 if(IsRectEmpty(&rect
))
818 if (Save_SCROLL_MovingThumb
&&
819 (SCROLL_TrackingWin
== hwnd
) &&
820 (SCROLL_TrackingBar
== nBar
))
821 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
823 /* Draw the arrows */
825 if (arrows
&& arrowSize
)
827 if( vertical
== SCROLL_trackVertical
&& GetCapture() == hwnd
)
828 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
829 (SCROLL_trackHitTest
== SCROLL_TOP_ARROW
),
830 (SCROLL_trackHitTest
== SCROLL_BOTTOM_ARROW
) );
832 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
836 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
837 thumbPos
, infoPtr
->flags
, vertical
, FALSE
, FALSE
);
839 if (Save_SCROLL_MovingThumb
&&
840 (SCROLL_TrackingWin
== hwnd
) &&
841 (SCROLL_TrackingBar
== nBar
))
842 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
844 /* if scroll bar has focus, reposition the caret */
845 if(hwnd
==GetFocus() && (nBar
==SB_CTL
))
849 SetCaretPos(thumbPos
+1, rect
.top
+1);
853 SetCaretPos(rect
.top
+1, thumbPos
+1);
858 WIN_ReleaseWndPtr(wndPtr
);
862 /***********************************************************************
863 * SCROLL_RefreshScrollBar
865 * Repaint the scroll bar interior after a SetScrollRange() or
866 * SetScrollPos() call.
868 static void SCROLL_RefreshScrollBar( HWND hwnd
, INT nBar
,
869 BOOL arrows
, BOOL interior
)
871 HDC hdc
= GetDCEx( hwnd
, 0,
872 DCX_CACHE
| ((nBar
== SB_CTL
) ? 0 : DCX_WINDOW
) );
875 SCROLL_DrawScrollBar( hwnd
, hdc
, nBar
, arrows
, interior
);
876 ReleaseDC( hwnd
, hdc
);
880 /***********************************************************************
881 * SCROLL_HandleKbdEvent
883 * Handle a keyboard event (only for SB_CTL scrollbars).
885 static void SCROLL_HandleKbdEvent( HWND hwnd
, WPARAM wParam
)
891 case VK_PRIOR
: msg
= SB_PAGEUP
; break;
892 case VK_NEXT
: msg
= SB_PAGEDOWN
; break;
893 case VK_HOME
: msg
= SB_TOP
; break;
894 case VK_END
: msg
= SB_BOTTOM
; break;
895 case VK_UP
: msg
= SB_LINEUP
; break;
896 case VK_DOWN
: msg
= SB_LINEDOWN
; break;
899 SendMessageW( GetParent(hwnd
),
900 (GetWindowLongA( hwnd
, GWL_STYLE
) & SBS_VERT
) ? WM_VSCROLL
: WM_HSCROLL
,
905 /***********************************************************************
906 * SCROLL_HandleScrollEvent
908 * Handle a mouse or timer event for the scrollbar.
909 * 'pt' is the location of the mouse event in client (for SB_CTL) or
910 * windows coordinates.
912 static void SCROLL_HandleScrollEvent( HWND hwnd
, INT nBar
, UINT msg
, POINT pt
)
914 /* Previous mouse position for timer events */
916 /* Thumb position when tracking started. */
917 static UINT trackThumbPos
;
918 /* Position in the scroll-bar of the last button-down event. */
919 static INT lastClickPos
;
920 /* Position in the scroll-bar of the last mouse event. */
921 static INT lastMousePos
;
923 enum SCROLL_HITTEST hittest
;
924 HWND hwndOwner
, hwndCtl
;
926 INT arrowSize
, thumbSize
, thumbPos
;
930 SCROLLBAR_INFO
*infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
);
931 if (!infoPtr
) return;
932 if ((SCROLL_trackHitTest
== SCROLL_NOWHERE
) && (msg
!= WM_LBUTTONDOWN
))
935 hdc
= GetDCEx( hwnd
, 0, DCX_CACHE
| ((nBar
== SB_CTL
) ? 0 : DCX_WINDOW
));
936 vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
937 &arrowSize
, &thumbSize
, &thumbPos
);
938 hwndOwner
= (nBar
== SB_CTL
) ? GetParent(hwnd
) : hwnd
;
939 hwndCtl
= (nBar
== SB_CTL
) ? hwnd
: 0;
943 case WM_LBUTTONDOWN
: /* Initialise mouse tracking */
944 HideCaret(hwnd
); /* hide caret while holding down LBUTTON */
945 SCROLL_trackVertical
= vertical
;
946 SCROLL_trackHitTest
= hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, FALSE
);
947 lastClickPos
= vertical
? (pt
.y
- rect
.top
) : (pt
.x
- rect
.left
);
948 lastMousePos
= lastClickPos
;
949 trackThumbPos
= thumbPos
;
951 if (nBar
== SB_CTL
&& (GetWindowLongA(hwnd
, GWL_STYLE
) & WS_TABSTOP
)) SetFocus( hwnd
);
956 hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, TRUE
);
961 hittest
= SCROLL_NOWHERE
;
963 /* if scrollbar has focus, show back caret */
964 if (hwnd
==GetFocus()) ShowCaret(hwnd
);
969 hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, FALSE
);
973 return; /* Should never happen */
976 TRACE("Event: hwnd=%04x bar=%d msg=%s pt=%ld,%ld hit=%d\n",
977 hwnd
, nBar
, SPY_GetMsgName(msg
,hwnd
), pt
.x
, pt
.y
, hittest
);
979 switch(SCROLL_trackHitTest
)
981 case SCROLL_NOWHERE
: /* No tracking in progress */
984 case SCROLL_TOP_ARROW
:
985 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
986 (hittest
== SCROLL_trackHitTest
), FALSE
);
987 if (hittest
== SCROLL_trackHitTest
)
989 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
991 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
992 SB_LINEUP
, (LPARAM
)hwndCtl
);
995 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
996 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
999 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
1002 case SCROLL_TOP_RECT
:
1003 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
1004 thumbPos
, infoPtr
->flags
, vertical
,
1005 (hittest
== SCROLL_trackHitTest
), FALSE
);
1006 if (hittest
== SCROLL_trackHitTest
)
1008 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
1010 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1011 SB_PAGEUP
, (LPARAM
)hwndCtl
);
1013 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
1014 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
1017 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
1021 if (msg
== WM_LBUTTONDOWN
)
1023 SCROLL_TrackingWin
= hwnd
;
1024 SCROLL_TrackingBar
= nBar
;
1025 SCROLL_TrackingPos
= trackThumbPos
+ lastMousePos
- lastClickPos
;
1026 if (!SCROLL_MovingThumb
)
1027 SCROLL_DrawMovingThumb(hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
1029 else if (msg
== WM_LBUTTONUP
)
1031 if (SCROLL_MovingThumb
)
1032 SCROLL_DrawMovingThumb(hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
1033 SCROLL_TrackingWin
= 0;
1034 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
1035 thumbPos
, infoPtr
->flags
, vertical
,
1038 else /* WM_MOUSEMOVE */
1042 if (!SCROLL_PtInRectEx( &rect
, pt
, vertical
)) pos
= lastClickPos
;
1045 pt
= SCROLL_ClipPos( &rect
, pt
);
1046 pos
= vertical
? (pt
.y
- rect
.top
) : (pt
.x
- rect
.left
);
1048 if ( (pos
!= lastMousePos
) || (!SCROLL_MovingThumb
) )
1050 if (SCROLL_MovingThumb
)
1051 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
,
1052 arrowSize
, thumbSize
);
1054 SCROLL_TrackingPos
= trackThumbPos
+ pos
- lastClickPos
;
1055 SCROLL_TrackingVal
= SCROLL_GetThumbVal( infoPtr
, &rect
,
1057 SCROLL_TrackingPos
);
1058 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1059 MAKEWPARAM( SB_THUMBTRACK
, SCROLL_TrackingVal
),
1061 if (!SCROLL_MovingThumb
)
1062 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
,
1063 arrowSize
, thumbSize
);
1068 case SCROLL_BOTTOM_RECT
:
1069 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
1070 thumbPos
, infoPtr
->flags
, vertical
,
1071 FALSE
, (hittest
== SCROLL_trackHitTest
) );
1072 if (hittest
== SCROLL_trackHitTest
)
1074 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
1076 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1077 SB_PAGEDOWN
, (LPARAM
)hwndCtl
);
1079 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
1080 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
1083 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
1086 case SCROLL_BOTTOM_ARROW
:
1087 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
1088 FALSE
, (hittest
== SCROLL_trackHitTest
) );
1089 if (hittest
== SCROLL_trackHitTest
)
1091 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
1093 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1094 SB_LINEDOWN
, (LPARAM
)hwndCtl
);
1097 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
1098 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
1101 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
1105 if (msg
== WM_LBUTTONDOWN
)
1108 if (hittest
== SCROLL_THUMB
)
1110 UINT val
= SCROLL_GetThumbVal( infoPtr
, &rect
, vertical
,
1111 trackThumbPos
+ lastMousePos
- lastClickPos
);
1112 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1113 MAKEWPARAM( SB_THUMBTRACK
, val
), (LPARAM
)hwndCtl
);
1117 if (msg
== WM_LBUTTONUP
)
1119 hittest
= SCROLL_trackHitTest
;
1120 SCROLL_trackHitTest
= SCROLL_NOWHERE
; /* Terminate tracking */
1122 if (hittest
== SCROLL_THUMB
)
1124 UINT val
= SCROLL_GetThumbVal( infoPtr
, &rect
, vertical
,
1125 trackThumbPos
+ lastMousePos
- lastClickPos
);
1126 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1127 MAKEWPARAM( SB_THUMBPOSITION
, val
), (LPARAM
)hwndCtl
);
1129 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1130 SB_ENDSCROLL
, (LPARAM
)hwndCtl
);
1133 ReleaseDC( hwnd
, hdc
);
1137 /***********************************************************************
1138 * SCROLL_TrackScrollBar
1140 * Track a mouse button press on a scroll-bar.
1141 * pt is in screen-coordinates for non-client scroll bars.
1143 void SCROLL_TrackScrollBar( HWND hwnd
, INT scrollbar
, POINT pt
)
1146 INT xoffset
= 0, yoffset
= 0;
1148 if (scrollbar
!= SB_CTL
)
1150 WND
*wndPtr
= WIN_GetPtr( hwnd
);
1151 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
) return;
1152 xoffset
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
1153 yoffset
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
1154 WIN_ReleasePtr( wndPtr
);
1155 ScreenToClient( hwnd
, &pt
);
1160 SCROLL_HandleScrollEvent( hwnd
, scrollbar
, WM_LBUTTONDOWN
, pt
);
1164 if (!GetMessageW( &msg
, 0, 0, 0 )) break;
1165 if (CallMsgFilterW( &msg
, MSGF_SCROLLBAR
)) continue;
1171 pt
.x
= LOWORD(msg
.lParam
) + xoffset
;
1172 pt
.y
= HIWORD(msg
.lParam
) + yoffset
;
1173 SCROLL_HandleScrollEvent( hwnd
, scrollbar
, msg
.message
, pt
);
1176 TranslateMessage( &msg
);
1177 DispatchMessageW( &msg
);
1180 if (!IsWindow( hwnd
))
1185 } while (msg
.message
!= WM_LBUTTONUP
);
1189 /***********************************************************************
1192 static LRESULT WINAPI
ScrollBarWndProc( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1194 if (!IsWindow( hwnd
)) return 0;
1200 SCROLLBAR_INFO
*infoPtr
;
1201 CREATESTRUCTW
*lpCreat
= (CREATESTRUCTW
*)lParam
;
1203 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, SB_CTL
))) return -1;
1204 if (lpCreat
->style
& WS_DISABLED
)
1206 TRACE("Created WS_DISABLED scrollbar\n");
1207 infoPtr
->flags
= ESB_DISABLE_BOTH
;
1210 if (lpCreat
->style
& SBS_SIZEBOX
)
1212 FIXME("Unimplemented style SBS_SIZEBOX.\n" );
1215 if (lpCreat
->style
& SBS_VERT
)
1217 if (lpCreat
->style
& SBS_LEFTALIGN
)
1218 MoveWindow( hwnd
, lpCreat
->x
, lpCreat
->y
,
1219 GetSystemMetrics(SM_CXVSCROLL
)+1, lpCreat
->cy
, FALSE
);
1220 else if (lpCreat
->style
& SBS_RIGHTALIGN
)
1222 lpCreat
->x
+lpCreat
->cx
-GetSystemMetrics(SM_CXVSCROLL
)-1,
1224 GetSystemMetrics(SM_CXVSCROLL
)+1, lpCreat
->cy
, FALSE
);
1228 if (lpCreat
->style
& SBS_TOPALIGN
)
1229 MoveWindow( hwnd
, lpCreat
->x
, lpCreat
->y
,
1230 lpCreat
->cx
, GetSystemMetrics(SM_CYHSCROLL
)+1, FALSE
);
1231 else if (lpCreat
->style
& SBS_BOTTOMALIGN
)
1234 lpCreat
->y
+lpCreat
->cy
-GetSystemMetrics(SM_CYHSCROLL
)-1,
1235 lpCreat
->cx
, GetSystemMetrics(SM_CYHSCROLL
)+1, FALSE
);
1238 if (!hUpArrow
) SCROLL_LoadBitmaps();
1239 TRACE("ScrollBar creation, hwnd=%04x\n", hwnd
);
1244 SCROLLBAR_INFO
*infoPtr
;
1245 if ((infoPtr
= SCROLL_GetScrollInfo( hwnd
, SB_CTL
)))
1247 infoPtr
->flags
= wParam
? ESB_ENABLE_BOTH
: ESB_DISABLE_BOTH
;
1248 SCROLL_RefreshScrollBar(hwnd
, SB_CTL
, TRUE
, TRUE
);
1253 case WM_LBUTTONDOWN
:
1256 pt
.x
= SLOWORD(lParam
);
1257 pt
.y
= SHIWORD(lParam
);
1258 SCROLL_TrackScrollBar( hwnd
, SB_CTL
, pt
);
1266 pt
.x
= SLOWORD(lParam
);
1267 pt
.y
= SHIWORD(lParam
);
1268 SCROLL_HandleScrollEvent( hwnd
, SB_CTL
, message
, pt
);
1272 /* if key event is received, the scrollbar has the focus */
1274 /* hide caret on first KEYDOWN to prevent flicker */
1275 if ((lParam
& 0x40000000)==0)
1277 SCROLL_HandleKbdEvent( hwnd
, wParam
);
1286 /* Create a caret when a ScrollBar get focus */
1288 int arrowSize
, thumbSize
, thumbPos
, vertical
;
1289 vertical
= SCROLL_GetScrollBarRect( hwnd
, SB_CTL
, &rect
,
1290 &arrowSize
, &thumbSize
, &thumbPos
);
1293 CreateCaret(hwnd
,1, thumbSize
-2, rect
.bottom
-rect
.top
-2);
1294 SetCaretPos(thumbPos
+1, rect
.top
+1);
1298 CreateCaret(hwnd
,1, rect
.right
-rect
.left
-2,thumbSize
-2);
1299 SetCaretPos(rect
.top
+1, thumbPos
+1);
1308 int arrowSize
, thumbSize
, thumbPos
, vertical
;
1309 vertical
= SCROLL_GetScrollBarRect( hwnd
, SB_CTL
, &rect
,&arrowSize
, &thumbSize
, &thumbPos
);
1311 rect
.left
=thumbPos
+1;
1312 rect
.right
=rect
.left
+thumbSize
;
1316 rect
.top
=thumbPos
+1;
1317 rect
.bottom
=rect
.top
+thumbSize
;
1320 InvalidateRect(hwnd
,&rect
,0);
1329 return DLGC_WANTARROWS
; /* Windows returns this value */
1334 HDC hdc
= BeginPaint( hwnd
, &ps
);
1335 SCROLL_DrawScrollBar( hwnd
, hdc
, SB_CTL
, TRUE
, TRUE
);
1336 EndPaint( hwnd
, &ps
);
1342 return SetScrollPos( hwnd
, SB_CTL
, wParam
, (BOOL
)lParam
);
1346 return GetScrollPos( hwnd
, SB_CTL
);
1348 case SBM_SETRANGE16
:
1349 SetScrollRange( hwnd
, SB_CTL
, LOWORD(lParam
), HIWORD(lParam
),
1350 wParam
/* FIXME: Is this correct? */ );
1355 INT oldPos
= GetScrollPos( hwnd
, SB_CTL
);
1356 SetScrollRange( hwnd
, SB_CTL
, wParam
, lParam
, FALSE
);
1357 if (oldPos
!= GetScrollPos( hwnd
, SB_CTL
)) return oldPos
;
1361 case SBM_GETRANGE16
:
1362 FIXME("don't know how to handle SBM_GETRANGE16 (wp=%04x,lp=%08lx)\n", wParam
, lParam
);
1366 GetScrollRange( hwnd
, SB_CTL
, (LPINT
)wParam
, (LPINT
)lParam
);
1369 case SBM_ENABLE_ARROWS16
:
1370 case SBM_ENABLE_ARROWS
:
1371 return EnableScrollBar( hwnd
, SB_CTL
, wParam
);
1373 case SBM_SETRANGEREDRAW
:
1375 INT oldPos
= GetScrollPos( hwnd
, SB_CTL
);
1376 SetScrollRange( hwnd
, SB_CTL
, wParam
, lParam
, TRUE
);
1377 if (oldPos
!= GetScrollPos( hwnd
, SB_CTL
)) return oldPos
;
1381 case SBM_SETSCROLLINFO
:
1382 return SetScrollInfo( hwnd
, SB_CTL
, (SCROLLINFO
*)lParam
, wParam
);
1384 case SBM_GETSCROLLINFO
:
1385 return GetScrollInfo( hwnd
, SB_CTL
, (SCROLLINFO
*)lParam
);
1395 ERR("unknown Win32 msg %04x wp=%08x lp=%08lx\n",
1396 message
, wParam
, lParam
);
1400 if (message
>= WM_USER
)
1401 WARN("unknown msg %04x wp=%04x lp=%08lx\n",
1402 message
, wParam
, lParam
);
1403 return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1409 /*************************************************************************
1410 * SetScrollInfo (USER32.@)
1411 * SetScrollInfo can be used to set the position, upper bound,
1412 * lower bound, and page size of a scrollbar control.
1415 * Scrollbar position
1418 * For 100 lines of text to be displayed in a window of 25 lines,
1419 * one would for instance use info->nMin=0, info->nMax=75
1420 * (corresponding to the 76 different positions of the window on
1421 * the text), and info->nPage=25.
1423 INT WINAPI
SetScrollInfo(
1424 HWND hwnd
/* [in] Handle of window whose scrollbar will be affected */,
1425 INT nBar
/* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1426 const SCROLLINFO
*info
/* [in] Specifies what to change and new values */,
1427 BOOL bRedraw
/* [in] Should scrollbar be redrawn afterwards ? */)
1430 INT retVal
= SCROLL_SetScrollInfo( hwnd
, nBar
, info
, &action
);
1432 if( action
& SA_SSI_HIDE
)
1433 SCROLL_ShowScrollBar( hwnd
, nBar
, FALSE
, FALSE
);
1436 if( action
& SA_SSI_SHOW
)
1437 if( SCROLL_ShowScrollBar( hwnd
, nBar
, TRUE
, TRUE
) )
1438 return retVal
; /* SetWindowPos() already did the painting */
1440 if( bRedraw
&& (action
& SA_SSI_REFRESH
))
1441 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, TRUE
);
1442 else if( action
& SA_SSI_REPAINT_ARROWS
)
1443 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, FALSE
);
1448 INT
SCROLL_SetScrollInfo( HWND hwnd
, INT nBar
,
1449 const SCROLLINFO
*info
, INT
*action
)
1451 /* Update the scrollbar state and set action flags according to
1452 * what has to be done graphics wise. */
1454 SCROLLBAR_INFO
*infoPtr
;
1456 BOOL bChangeParams
= FALSE
; /* don't show/hide scrollbar if params don't change */
1460 if (!(infoPtr
= SCROLL_GetScrollInfo(hwnd
, nBar
))) return 0;
1461 if (info
->fMask
& ~(SIF_ALL
| SIF_DISABLENOSCROLL
)) return 0;
1462 if ((info
->cbSize
!= sizeof(*info
)) &&
1463 (info
->cbSize
!= sizeof(*info
)-sizeof(info
->nTrackPos
))) return 0;
1465 if (TRACE_ON(scroll
))
1467 TRACE("hwnd=%04x bar=%d", hwnd
, nBar
);
1468 if (info
->fMask
& SIF_PAGE
) DPRINTF( " page=%d", info
->nPage
);
1469 if (info
->fMask
& SIF_POS
) DPRINTF( " pos=%d", info
->nPos
);
1470 if (info
->fMask
& SIF_RANGE
) DPRINTF( " min=%d max=%d", info
->nMin
, info
->nMax
);
1474 /* Set the page size */
1476 if (info
->fMask
& SIF_PAGE
)
1478 if( infoPtr
->Page
!= info
->nPage
)
1480 infoPtr
->Page
= info
->nPage
;
1481 *action
|= SA_SSI_REFRESH
;
1482 bChangeParams
= TRUE
;
1486 /* Set the scroll pos */
1488 if (info
->fMask
& SIF_POS
)
1490 if( infoPtr
->CurVal
!= info
->nPos
)
1492 infoPtr
->CurVal
= info
->nPos
;
1493 *action
|= SA_SSI_REFRESH
;
1497 /* Set the scroll range */
1499 if (info
->fMask
& SIF_RANGE
)
1501 /* Invalid range -> range is set to (0,0) */
1502 if ((info
->nMin
> info
->nMax
) ||
1503 ((UINT
)(info
->nMax
- info
->nMin
) >= 0x80000000))
1505 infoPtr
->MinVal
= 0;
1506 infoPtr
->MaxVal
= 0;
1507 bChangeParams
= TRUE
;
1511 if( infoPtr
->MinVal
!= info
->nMin
||
1512 infoPtr
->MaxVal
!= info
->nMax
)
1514 *action
|= SA_SSI_REFRESH
;
1515 infoPtr
->MinVal
= info
->nMin
;
1516 infoPtr
->MaxVal
= info
->nMax
;
1517 bChangeParams
= TRUE
;
1522 /* Make sure the page size is valid */
1524 if (infoPtr
->Page
< 0) infoPtr
->Page
= 0;
1525 else if (infoPtr
->Page
> infoPtr
->MaxVal
- infoPtr
->MinVal
+ 1 )
1526 infoPtr
->Page
= infoPtr
->MaxVal
- infoPtr
->MinVal
+ 1;
1528 /* Make sure the pos is inside the range */
1530 if (infoPtr
->CurVal
< infoPtr
->MinVal
)
1531 infoPtr
->CurVal
= infoPtr
->MinVal
;
1532 else if (infoPtr
->CurVal
> infoPtr
->MaxVal
- max( infoPtr
->Page
-1, 0 ))
1533 infoPtr
->CurVal
= infoPtr
->MaxVal
- max( infoPtr
->Page
-1, 0 );
1535 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1536 infoPtr
->Page
, infoPtr
->CurVal
,
1537 infoPtr
->MinVal
, infoPtr
->MaxVal
);
1539 /* don't change the scrollbar state if SetScrollInfo
1540 * is just called with SIF_DISABLENOSCROLL
1542 if(!(info
->fMask
& SIF_ALL
)) goto done
;
1544 /* Check if the scrollbar should be hidden or disabled */
1546 if (info
->fMask
& (SIF_RANGE
| SIF_PAGE
| SIF_DISABLENOSCROLL
))
1548 new_flags
= infoPtr
->flags
;
1549 if (infoPtr
->MinVal
>= infoPtr
->MaxVal
- max( infoPtr
->Page
-1, 0 ))
1551 /* Hide or disable scroll-bar */
1552 if (info
->fMask
& SIF_DISABLENOSCROLL
)
1554 new_flags
= ESB_DISABLE_BOTH
;
1555 *action
|= SA_SSI_REFRESH
;
1557 else if ((nBar
!= SB_CTL
) && bChangeParams
)
1559 *action
= SA_SSI_HIDE
;
1563 else /* Show and enable scroll-bar */
1566 if ((nBar
!= SB_CTL
) && bChangeParams
)
1567 *action
|= SA_SSI_SHOW
;
1570 if (infoPtr
->flags
!= new_flags
) /* check arrow flags */
1572 infoPtr
->flags
= new_flags
;
1573 *action
|= SA_SSI_REPAINT_ARROWS
;
1578 /* Return current position */
1580 return infoPtr
->CurVal
;
1584 /*************************************************************************
1585 * GetScrollInfo (USER32.@)
1586 * GetScrollInfo can be used to retrieve the position, upper bound,
1587 * lower bound, and page size of a scrollbar control.
1591 BOOL WINAPI
GetScrollInfo(
1592 HWND hwnd
/* [in] Handle of window */ ,
1593 INT nBar
/* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1594 LPSCROLLINFO info
/* [in/out] (info.fMask [in] specifies which values are to retrieve) */)
1596 SCROLLBAR_INFO
*infoPtr
;
1598 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return FALSE
;
1599 if (info
->fMask
& ~(SIF_ALL
| SIF_DISABLENOSCROLL
)) return FALSE
;
1600 if ((info
->cbSize
!= sizeof(*info
)) &&
1601 (info
->cbSize
!= sizeof(*info
)-sizeof(info
->nTrackPos
))) return FALSE
;
1603 if (info
->fMask
& SIF_PAGE
) info
->nPage
= infoPtr
->Page
;
1604 if (info
->fMask
& SIF_POS
) info
->nPos
= infoPtr
->CurVal
;
1605 if ((info
->fMask
& SIF_TRACKPOS
) && (info
->cbSize
== sizeof(*info
)))
1606 info
->nTrackPos
= (SCROLL_TrackingWin
== WIN_GetFullHandle(hwnd
)) ? SCROLL_TrackingVal
: infoPtr
->CurVal
;
1607 if (info
->fMask
& SIF_RANGE
)
1609 info
->nMin
= infoPtr
->MinVal
;
1610 info
->nMax
= infoPtr
->MaxVal
;
1612 return (info
->fMask
& SIF_ALL
) != 0;
1616 /*************************************************************************
1617 * SetScrollPos (USER32.@)
1620 * Success: Scrollbar position
1624 * Note the ambiguity when 0 is returned. Use GetLastError
1625 * to make sure there was an error (and to know which one).
1627 INT WINAPI
SetScrollPos(
1628 HWND hwnd
/* [in] Handle of window whose scrollbar will be affected */,
1629 INT nBar
/* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1630 INT nPos
/* [in] New value */,
1631 BOOL bRedraw
/* [in] Should scrollbar be redrawn afterwards ? */ )
1634 SCROLLBAR_INFO
*infoPtr
;
1637 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return 0;
1638 oldPos
= infoPtr
->CurVal
;
1639 info
.cbSize
= sizeof(info
);
1641 info
.fMask
= SIF_POS
;
1642 SetScrollInfo( hwnd
, nBar
, &info
, bRedraw
);
1647 /*************************************************************************
1648 * GetScrollPos (USER32.@)
1651 * Success: Current position
1655 * Note the ambiguity when 0 is returned. Use GetLastError
1656 * to make sure there was an error (and to know which one).
1658 INT WINAPI
GetScrollPos(
1659 HWND hwnd
, /* [in] Handle of window */
1660 INT nBar
/* [in] One of SB_HORZ, SB_VERT, or SB_CTL */)
1662 SCROLLBAR_INFO
*infoPtr
;
1664 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return 0;
1665 return infoPtr
->CurVal
;
1669 /*************************************************************************
1670 * SetScrollRange (USER32.@)
1674 BOOL WINAPI
SetScrollRange(
1675 HWND hwnd
, /* [in] Handle of window whose scrollbar will be affected */
1676 INT nBar
, /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */
1677 INT MinVal
, /* [in] New minimum value */
1678 INT MaxVal
, /* [in] New maximum value */
1679 BOOL bRedraw
/* [in] Should scrollbar be redrawn afterwards ? */)
1683 info
.cbSize
= sizeof(info
);
1686 info
.fMask
= SIF_RANGE
;
1687 SetScrollInfo( hwnd
, nBar
, &info
, bRedraw
);
1692 /*************************************************************************
1693 * SCROLL_SetNCSbState
1695 * Updates both scrollbars at the same time. Used by MDI CalcChildScroll().
1697 INT
SCROLL_SetNCSbState(HWND hwnd
, int vMin
, int vMax
, int vPos
,
1698 int hMin
, int hMax
, int hPos
)
1701 SCROLLINFO vInfo
, hInfo
;
1703 vInfo
.cbSize
= hInfo
.cbSize
= sizeof(SCROLLINFO
);
1710 vInfo
.fMask
= hInfo
.fMask
= SIF_RANGE
| SIF_POS
;
1712 SCROLL_SetScrollInfo( hwnd
, SB_VERT
, &vInfo
, &vA
);
1713 SCROLL_SetScrollInfo( hwnd
, SB_HORZ
, &hInfo
, &hA
);
1715 if( !SCROLL_ShowScrollBar( hwnd
, SB_BOTH
,
1716 (hA
& SA_SSI_SHOW
),(vA
& SA_SSI_SHOW
) ) )
1718 /* SetWindowPos() wasn't called, just redraw the scrollbars if needed */
1719 if( vA
& SA_SSI_REFRESH
)
1720 SCROLL_RefreshScrollBar( hwnd
, SB_VERT
, FALSE
, TRUE
);
1722 if( hA
& SA_SSI_REFRESH
)
1723 SCROLL_RefreshScrollBar( hwnd
, SB_HORZ
, FALSE
, TRUE
);
1729 /*************************************************************************
1730 * GetScrollRange (USER32.@)
1734 BOOL WINAPI
GetScrollRange(
1735 HWND hwnd
, /* [in] Handle of window */
1736 INT nBar
, /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */
1737 LPINT lpMin
, /* [out] Where to store minimum value */
1738 LPINT lpMax
/* [out] Where to store maximum value */)
1740 SCROLLBAR_INFO
*infoPtr
;
1742 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
)))
1744 if (lpMin
) lpMin
= 0;
1745 if (lpMax
) lpMax
= 0;
1748 if (lpMin
) *lpMin
= infoPtr
->MinVal
;
1749 if (lpMax
) *lpMax
= infoPtr
->MaxVal
;
1754 /*************************************************************************
1755 * SCROLL_ShowScrollBar()
1757 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1759 BOOL
SCROLL_ShowScrollBar( HWND hwnd
, INT nBar
,
1760 BOOL fShowH
, BOOL fShowV
)
1762 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1764 TRACE("hwnd=%04x bar=%d horz=%d, vert=%d\n",
1765 hwnd
, nBar
, fShowH
, fShowV
);
1770 ShowWindow( hwnd
, fShowH
? SW_SHOW
: SW_HIDE
);
1777 fShowH
= !(style
& WS_HSCROLL
);
1778 style
|= WS_HSCROLL
;
1782 fShowH
= (style
& WS_HSCROLL
);
1783 style
&= ~WS_HSCROLL
;
1785 if( nBar
== SB_HORZ
) {
1794 fShowV
= !(style
& WS_VSCROLL
);
1795 style
|= WS_VSCROLL
;
1799 fShowV
= (style
& WS_VSCROLL
);
1800 style
&= ~WS_VSCROLL
;
1802 if ( nBar
== SB_VERT
)
1807 return FALSE
; /* Nothing to do! */
1810 if( fShowH
|| fShowV
) /* frame has been changed, let the window redraw itself */
1812 WIN_SetStyle( hwnd
, style
);
1813 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
1814 | SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
1817 return FALSE
; /* no frame changes */
1821 /*************************************************************************
1822 * ShowScrollBar (USER32.@)
1826 BOOL WINAPI
ShowScrollBar(
1827 HWND hwnd
, /* [in] Handle of window whose scrollbar(s) will be affected */
1828 INT nBar
, /* [in] One of SB_HORZ, SB_VERT, SB_BOTH or SB_CTL */
1829 BOOL fShow
/* [in] TRUE = show, FALSE = hide */)
1831 SCROLL_ShowScrollBar( hwnd
, nBar
, (nBar
== SB_VERT
) ? 0 : fShow
,
1832 (nBar
== SB_HORZ
) ? 0 : fShow
);
1837 /*************************************************************************
1838 * EnableScrollBar (USER32.@)
1840 BOOL WINAPI
EnableScrollBar( HWND hwnd
, INT nBar
, UINT flags
)
1843 SCROLLBAR_INFO
*infoPtr
;
1845 TRACE("%04x %d %d\n", hwnd
, nBar
, flags
);
1847 flags
&= ESB_DISABLE_BOTH
;
1849 if (nBar
== SB_BOTH
)
1851 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, SB_VERT
))) return FALSE
;
1852 if (!(bFineWithMe
= (infoPtr
->flags
== flags
)) )
1854 infoPtr
->flags
= flags
;
1855 SCROLL_RefreshScrollBar( hwnd
, SB_VERT
, TRUE
, TRUE
);
1862 if (!(infoPtr
= SCROLL_GetScrollInfo( hwnd
, nBar
))) return FALSE
;
1863 if (bFineWithMe
&& infoPtr
->flags
== flags
) return FALSE
;
1864 infoPtr
->flags
= flags
;
1866 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, TRUE
);