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
27 #include "wine/winuser16.h"
30 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(scroll
);
38 INT curVal
; /* Current scroll-bar value */
39 INT minVal
; /* Minimum scroll-bar value */
40 INT maxVal
; /* Maximum scroll-bar value */
41 INT page
; /* Page size of scroll bar (Win32) */
42 UINT flags
; /* EnableScrollBar flags */
43 } SCROLLBAR_INFO
, *LPSCROLLBAR_INFO
;
46 static HBITMAP hUpArrow
;
47 static HBITMAP hDnArrow
;
48 static HBITMAP hLfArrow
;
49 static HBITMAP hRgArrow
;
50 static HBITMAP hUpArrowD
;
51 static HBITMAP hDnArrowD
;
52 static HBITMAP hLfArrowD
;
53 static HBITMAP hRgArrowD
;
54 static HBITMAP hUpArrowI
;
55 static HBITMAP hDnArrowI
;
56 static HBITMAP hLfArrowI
;
57 static HBITMAP hRgArrowI
;
59 #define TOP_ARROW(flags,pressed) \
60 (((flags)&ESB_DISABLE_UP) ? hUpArrowI : ((pressed) ? hUpArrowD:hUpArrow))
61 #define BOTTOM_ARROW(flags,pressed) \
62 (((flags)&ESB_DISABLE_DOWN) ? hDnArrowI : ((pressed) ? hDnArrowD:hDnArrow))
63 #define LEFT_ARROW(flags,pressed) \
64 (((flags)&ESB_DISABLE_LEFT) ? hLfArrowI : ((pressed) ? hLfArrowD:hLfArrow))
65 #define RIGHT_ARROW(flags,pressed) \
66 (((flags)&ESB_DISABLE_RIGHT) ? hRgArrowI : ((pressed) ? hRgArrowD:hRgArrow))
69 /* Minimum size of the rectangle between the arrows */
70 #define SCROLL_MIN_RECT 4
72 /* Minimum size of the thumb in pixels */
73 #define SCROLL_MIN_THUMB 6
75 /* Overlap between arrows and thumb */
76 #define SCROLL_ARROW_THUMB_OVERLAP ((TWEAK_WineLook == WIN31_LOOK) ? 1 : 0)
78 /* Delay (in ms) before first repetition when holding the button down */
79 #define SCROLL_FIRST_DELAY 200
81 /* Delay (in ms) between scroll repetitions */
82 #define SCROLL_REPEAT_DELAY 50
85 #define SCROLL_TIMER 0
87 /* Scroll-bar hit testing */
90 SCROLL_NOWHERE
, /* Outside the scroll bar */
91 SCROLL_TOP_ARROW
, /* Top or left arrow */
92 SCROLL_TOP_RECT
, /* Rectangle between the top arrow and the thumb */
93 SCROLL_THUMB
, /* Thumb rectangle */
94 SCROLL_BOTTOM_RECT
, /* Rectangle between the thumb and the bottom arrow */
95 SCROLL_BOTTOM_ARROW
/* Bottom or right arrow */
98 /* What to do after SCROLL_SetScrollInfo() */
99 #define SA_SSI_HIDE 0x0001
100 #define SA_SSI_SHOW 0x0002
101 #define SA_SSI_REFRESH 0x0004
102 #define SA_SSI_REPAINT_ARROWS 0x0008
104 /* Thumb-tracking info */
105 static HWND SCROLL_TrackingWin
= 0;
106 static INT SCROLL_TrackingBar
= 0;
107 static INT SCROLL_TrackingPos
= 0;
108 static INT SCROLL_TrackingVal
= 0;
109 /* Hit test code of the last button-down event */
110 static enum SCROLL_HITTEST SCROLL_trackHitTest
;
111 static BOOL SCROLL_trackVertical
;
113 /* Is the moving thumb being displayed? */
114 static BOOL SCROLL_MovingThumb
= FALSE
;
116 /* Local functions */
117 static BOOL
SCROLL_ShowScrollBar( HWND hwnd
, INT nBar
,
118 BOOL fShowH
, BOOL fShowV
);
119 static INT
SCROLL_SetScrollInfo( HWND hwnd
, INT nBar
,
120 const SCROLLINFO
*info
, INT
*action
);
121 static void SCROLL_DrawInterior_9x( HWND hwnd
, HDC hdc
, INT nBar
,
122 RECT
*rect
, INT arrowSize
,
123 INT thumbSize
, INT thumbPos
,
124 UINT flags
, BOOL vertical
,
125 BOOL top_selected
, BOOL bottom_selected
);
126 static LRESULT WINAPI
ScrollBarWndProc( HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
129 /*********************************************************************
130 * scrollbar class descriptor
132 const struct builtin_class_descr SCROLL_builtin_class
=
134 "ScrollBar", /* name */
135 CS_GLOBALCLASS
| CS_DBLCLKS
| CS_VREDRAW
| CS_HREDRAW
| CS_PARENTDC
, /* style */
136 NULL
, /* procA (winproc is Unicode only) */
137 ScrollBarWndProc
, /* procW */
138 sizeof(SCROLLBAR_INFO
), /* extra */
139 IDC_ARROW
, /* cursor */
143 /***********************************************************************
144 * SCROLL_ScrollInfoValid
146 * Determine if the supplied SCROLLINFO struct is valid.
148 inline static BOOL
SCROLL_ScrollInfoValid(
149 LPSCROLLINFO info
/* [in] The SCROLLINFO struct to be tested */)
151 return !(info
->fMask
& ~(SIF_ALL
| SIF_DISABLENOSCROLL
)
152 || (info
->cbSize
!= sizeof(*info
)
153 && info
->cbSize
!= sizeof(*info
) - sizeof(info
->nTrackPos
)));
157 /***********************************************************************
160 static void SCROLL_LoadBitmaps(void)
162 hUpArrow
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROW
) );
163 hDnArrow
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROW
) );
164 hLfArrow
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROW
) );
165 hRgArrow
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROW
) );
166 hUpArrowD
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROWD
) );
167 hDnArrowD
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROWD
) );
168 hLfArrowD
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROWD
) );
169 hRgArrowD
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROWD
) );
170 hUpArrowI
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROWI
) );
171 hDnArrowI
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROWI
) );
172 hLfArrowI
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROWI
) );
173 hRgArrowI
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROWI
) );
177 /***********************************************************************
178 * SCROLL_GetScrollBarInfo
180 static SCROLLBAR_INFO
*SCROLL_GetScrollBarInfo( HWND hwnd
, INT nBar
)
182 SCROLLBAR_INFO
*infoPtr
;
183 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
185 if (!wndPtr
) return NULL
;
188 case SB_HORZ
: infoPtr
= (SCROLLBAR_INFO
*)wndPtr
->pHScroll
; break;
189 case SB_VERT
: infoPtr
= (SCROLLBAR_INFO
*)wndPtr
->pVScroll
; break;
190 case SB_CTL
: infoPtr
= (SCROLLBAR_INFO
*)wndPtr
->wExtra
; break;
192 WIN_ReleaseWndPtr( wndPtr
);
196 if (!infoPtr
) /* Create the info structure if needed */
198 if ((infoPtr
= HeapAlloc( GetProcessHeap(), 0, sizeof(SCROLLBAR_INFO
) )))
200 infoPtr
->minVal
= infoPtr
->curVal
= infoPtr
->page
= 0;
201 infoPtr
->maxVal
= 100;
202 infoPtr
->flags
= ESB_ENABLE_BOTH
;
203 if (nBar
== SB_HORZ
) wndPtr
->pHScroll
= infoPtr
;
204 else wndPtr
->pVScroll
= infoPtr
;
206 if (!hUpArrow
) SCROLL_LoadBitmaps();
208 WIN_ReleaseWndPtr( wndPtr
);
213 /***********************************************************************
214 * SCROLL_GetScrollBarRect
216 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
217 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
218 * 'arrowSize' returns the width or height of an arrow (depending on
219 * the orientation of the scrollbar), 'thumbSize' returns the size of
220 * the thumb, and 'thumbPos' returns the position of the thumb
221 * relative to the left or to the top.
222 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
224 static BOOL
SCROLL_GetScrollBarRect( HWND hwnd
, INT nBar
, RECT
*lprect
,
225 INT
*arrowSize
, INT
*thumbSize
,
230 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
235 lprect
->left
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
236 lprect
->top
= wndPtr
->rectClient
.bottom
- wndPtr
->rectWindow
.top
;
237 lprect
->right
= wndPtr
->rectClient
.right
- wndPtr
->rectWindow
.left
;
238 lprect
->bottom
= lprect
->top
+ GetSystemMetrics(SM_CYHSCROLL
);
239 if(wndPtr
->dwStyle
& WS_BORDER
) {
242 } else if(wndPtr
->dwStyle
& WS_VSCROLL
)
248 if((wndPtr
->dwExStyle
& WS_EX_LEFTSCROLLBAR
) != 0)
249 lprect
->left
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
- GetSystemMetrics(SM_CXVSCROLL
);
251 lprect
->left
= wndPtr
->rectClient
.right
- wndPtr
->rectWindow
.left
;
252 lprect
->top
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
253 lprect
->right
= lprect
->left
+ GetSystemMetrics(SM_CXVSCROLL
);
254 lprect
->bottom
= wndPtr
->rectClient
.bottom
- wndPtr
->rectWindow
.top
;
255 if(wndPtr
->dwStyle
& WS_BORDER
) {
258 } else if(wndPtr
->dwStyle
& WS_HSCROLL
)
264 GetClientRect( hwnd
, lprect
);
265 vertical
= ((wndPtr
->dwStyle
& SBS_VERT
) != 0);
269 WIN_ReleaseWndPtr(wndPtr
);
273 if (vertical
) pixels
= lprect
->bottom
- lprect
->top
;
274 else pixels
= lprect
->right
- lprect
->left
;
276 if (pixels
<= 2*GetSystemMetrics(SM_CXVSCROLL
) + SCROLL_MIN_RECT
)
278 if (pixels
> SCROLL_MIN_RECT
)
279 *arrowSize
= (pixels
- SCROLL_MIN_RECT
) / 2;
282 *thumbPos
= *thumbSize
= 0;
286 SCROLLBAR_INFO
*info
= SCROLL_GetScrollBarInfo( hwnd
, nBar
);
288 *arrowSize
= GetSystemMetrics(SM_CXVSCROLL
);
289 pixels
-= (2 * (GetSystemMetrics(SM_CXVSCROLL
) - SCROLL_ARROW_THUMB_OVERLAP
));
293 *thumbSize
= MulDiv(pixels
,info
->page
,(info
->maxVal
-info
->minVal
+1));
294 if (*thumbSize
< SCROLL_MIN_THUMB
) *thumbSize
= SCROLL_MIN_THUMB
;
296 else *thumbSize
= GetSystemMetrics(SM_CXVSCROLL
);
298 if (((pixels
-= *thumbSize
) < 0) ||
299 ((info
->flags
& ESB_DISABLE_BOTH
) == ESB_DISABLE_BOTH
))
301 /* Rectangle too small or scrollbar disabled -> no thumb */
302 *thumbPos
= *thumbSize
= 0;
306 INT max
= info
->maxVal
- max( info
->page
-1, 0 );
307 if (info
->minVal
>= max
)
308 *thumbPos
= *arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
310 *thumbPos
= *arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
311 + MulDiv(pixels
, (info
->curVal
-info
->minVal
),(max
- info
->minVal
));
314 WIN_ReleaseWndPtr(wndPtr
);
319 /***********************************************************************
322 * Compute the current scroll position based on the thumb position in pixels
323 * from the top of the scroll-bar.
325 static UINT
SCROLL_GetThumbVal( SCROLLBAR_INFO
*infoPtr
, RECT
*rect
,
326 BOOL vertical
, INT pos
)
329 INT pixels
= vertical
? rect
->bottom
-rect
->top
: rect
->right
-rect
->left
;
331 if ((pixels
-= 2*(GetSystemMetrics(SM_CXVSCROLL
) - SCROLL_ARROW_THUMB_OVERLAP
)) <= 0)
332 return infoPtr
->minVal
;
336 thumbSize
= MulDiv(pixels
,infoPtr
->page
,(infoPtr
->maxVal
-infoPtr
->minVal
+1));
337 if (thumbSize
< SCROLL_MIN_THUMB
) thumbSize
= SCROLL_MIN_THUMB
;
339 else thumbSize
= GetSystemMetrics(SM_CXVSCROLL
);
341 if ((pixels
-= thumbSize
) <= 0) return infoPtr
->minVal
;
343 pos
= max( 0, pos
- (GetSystemMetrics(SM_CXVSCROLL
) - SCROLL_ARROW_THUMB_OVERLAP
) );
344 if (pos
> pixels
) pos
= pixels
;
346 if (!infoPtr
->page
) pos
*= infoPtr
->maxVal
- infoPtr
->minVal
;
347 else pos
*= infoPtr
->maxVal
- infoPtr
->minVal
- infoPtr
->page
+ 1;
348 return infoPtr
->minVal
+ ((pos
+ pixels
/ 2) / pixels
);
351 /***********************************************************************
354 static BOOL
SCROLL_PtInRectEx( LPRECT lpRect
, POINT pt
, BOOL vertical
)
360 rect
.left
-= lpRect
->right
- lpRect
->left
;
361 rect
.right
+= lpRect
->right
- lpRect
->left
;
365 rect
.top
-= lpRect
->bottom
- lpRect
->top
;
366 rect
.bottom
+= lpRect
->bottom
- lpRect
->top
;
368 return PtInRect( &rect
, pt
);
371 /***********************************************************************
374 static POINT
SCROLL_ClipPos( LPRECT lpRect
, POINT pt
)
376 if( pt
.x
< lpRect
->left
)
379 if( pt
.x
> lpRect
->right
)
380 pt
.x
= lpRect
->right
;
382 if( pt
.y
< lpRect
->top
)
385 if( pt
.y
> lpRect
->bottom
)
386 pt
.y
= lpRect
->bottom
;
392 /***********************************************************************
395 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
397 static enum SCROLL_HITTEST
SCROLL_HitTest( HWND hwnd
, INT nBar
,
398 POINT pt
, BOOL bDragging
)
400 INT arrowSize
, thumbSize
, thumbPos
;
403 BOOL vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
404 &arrowSize
, &thumbSize
, &thumbPos
);
406 if ( (bDragging
&& !SCROLL_PtInRectEx( &rect
, pt
, vertical
)) ||
407 (!PtInRect( &rect
, pt
)) ) return SCROLL_NOWHERE
;
411 if (pt
.y
< rect
.top
+ arrowSize
) return SCROLL_TOP_ARROW
;
412 if (pt
.y
>= rect
.bottom
- arrowSize
) return SCROLL_BOTTOM_ARROW
;
413 if (!thumbPos
) return SCROLL_TOP_RECT
;
415 if (pt
.y
< thumbPos
) return SCROLL_TOP_RECT
;
416 if (pt
.y
>= thumbPos
+ thumbSize
) return SCROLL_BOTTOM_RECT
;
418 else /* horizontal */
420 if (pt
.x
< rect
.left
+ arrowSize
) return SCROLL_TOP_ARROW
;
421 if (pt
.x
>= rect
.right
- arrowSize
) return SCROLL_BOTTOM_ARROW
;
422 if (!thumbPos
) return SCROLL_TOP_RECT
;
424 if (pt
.x
< thumbPos
) return SCROLL_TOP_RECT
;
425 if (pt
.x
>= thumbPos
+ thumbSize
) return SCROLL_BOTTOM_RECT
;
431 /***********************************************************************
434 * Draw the scroll bar arrows.
436 static void SCROLL_DrawArrows_9x( HDC hdc
, SCROLLBAR_INFO
*infoPtr
,
437 RECT
*rect
, INT arrowSize
, BOOL vertical
,
438 BOOL top_pressed
, BOOL bottom_pressed
)
444 r
.bottom
= r
.top
+ arrowSize
;
446 r
.right
= r
.left
+ arrowSize
;
448 DrawFrameControl( hdc
, &r
, DFC_SCROLL
,
449 (vertical
? DFCS_SCROLLUP
: DFCS_SCROLLLEFT
)
450 | (top_pressed
? (DFCS_PUSHED
| DFCS_FLAT
) : 0 )
451 | (infoPtr
->flags
&ESB_DISABLE_LTUP
? DFCS_INACTIVE
: 0 ) );
455 r
.top
= r
.bottom
-arrowSize
;
457 r
.left
= r
.right
-arrowSize
;
459 DrawFrameControl( hdc
, &r
, DFC_SCROLL
,
460 (vertical
? DFCS_SCROLLDOWN
: DFCS_SCROLLRIGHT
)
461 | (bottom_pressed
? (DFCS_PUSHED
| DFCS_FLAT
) : 0 )
462 | (infoPtr
->flags
&ESB_DISABLE_RTDN
? DFCS_INACTIVE
: 0) );
465 static void SCROLL_DrawArrows_31( HDC hdc
, SCROLLBAR_INFO
*infoPtr
,
466 RECT
*rect
, INT arrowSize
, BOOL vertical
,
467 BOOL top_pressed
, BOOL bottom_pressed
)
469 HDC hdcMem
= CreateCompatibleDC( hdc
);
470 HBITMAP hbmpPrev
= SelectObject( hdcMem
, vertical
?
471 TOP_ARROW(infoPtr
->flags
, top_pressed
)
472 : LEFT_ARROW(infoPtr
->flags
, top_pressed
));
474 SetStretchBltMode( hdc
, STRETCH_DELETESCANS
);
475 StretchBlt( hdc
, rect
->left
, rect
->top
,
476 vertical
? rect
->right
-rect
->left
: arrowSize
,
477 vertical
? arrowSize
: rect
->bottom
-rect
->top
,
479 GetSystemMetrics(SM_CXVSCROLL
),GetSystemMetrics(SM_CYHSCROLL
),
482 SelectObject( hdcMem
, vertical
?
483 BOTTOM_ARROW( infoPtr
->flags
, bottom_pressed
)
484 : RIGHT_ARROW( infoPtr
->flags
, bottom_pressed
) );
486 StretchBlt( hdc
, rect
->left
, rect
->bottom
- arrowSize
,
487 rect
->right
- rect
->left
, arrowSize
,
489 GetSystemMetrics(SM_CXVSCROLL
),GetSystemMetrics(SM_CYHSCROLL
),
492 StretchBlt( hdc
, rect
->right
- arrowSize
, rect
->top
,
493 arrowSize
, rect
->bottom
- rect
->top
,
495 GetSystemMetrics(SM_CXVSCROLL
), GetSystemMetrics(SM_CYHSCROLL
),
497 SelectObject( hdcMem
, hbmpPrev
);
501 static void SCROLL_DrawArrows( HDC hdc
, SCROLLBAR_INFO
*infoPtr
,
502 RECT
*rect
, INT arrowSize
, BOOL vertical
,
503 BOOL top_pressed
, BOOL bottom_pressed
)
505 if( TWEAK_WineLook
== WIN31_LOOK
)
506 SCROLL_DrawArrows_31( hdc
, infoPtr
, rect
, arrowSize
,
507 vertical
, top_pressed
,bottom_pressed
);
509 SCROLL_DrawArrows_9x( hdc
, infoPtr
, rect
, arrowSize
,
510 vertical
, top_pressed
,bottom_pressed
);
514 /***********************************************************************
515 * SCROLL_DrawMovingThumb
517 * Draw the moving thumb rectangle.
519 static void SCROLL_DrawMovingThumb_31( HDC hdc
, RECT
*rect
, BOOL vertical
,
520 INT arrowSize
, INT thumbSize
)
525 r
.top
+= SCROLL_TrackingPos
;
526 if (r
.top
< rect
->top
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
527 r
.top
= rect
->top
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
528 if (r
.top
+ thumbSize
>
529 rect
->bottom
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
))
530 r
.top
= rect
->bottom
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
532 r
.bottom
= r
.top
+ thumbSize
;
536 r
.left
+= SCROLL_TrackingPos
;
537 if (r
.left
< rect
->left
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
538 r
.left
= rect
->left
+ arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
539 if (r
.left
+ thumbSize
>
540 rect
->right
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
))
541 r
.left
= rect
->right
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
)
543 r
.right
= r
.left
+ thumbSize
;
546 DrawFocusRect( hdc
, &r
);
547 SCROLL_MovingThumb
= !SCROLL_MovingThumb
;
550 static void SCROLL_DrawMovingThumb_9x( HDC hdc
, RECT
*rect
, BOOL vertical
,
551 INT arrowSize
, INT thumbSize
)
553 INT pos
= SCROLL_TrackingPos
;
557 max_size
= rect
->bottom
- rect
->top
;
559 max_size
= rect
->right
- rect
->left
;
561 max_size
-= (arrowSize
-SCROLL_ARROW_THUMB_OVERLAP
) + thumbSize
;
563 if( pos
< (arrowSize
-SCROLL_ARROW_THUMB_OVERLAP
) )
564 pos
= (arrowSize
-SCROLL_ARROW_THUMB_OVERLAP
);
565 else if( pos
> max_size
)
568 SCROLL_DrawInterior_9x( SCROLL_TrackingWin
, hdc
, SCROLL_TrackingBar
,
569 rect
, arrowSize
, thumbSize
, pos
,
570 0, vertical
, FALSE
, FALSE
);
572 SCROLL_MovingThumb
= !SCROLL_MovingThumb
;
575 static void SCROLL_DrawMovingThumb( HDC hdc
, RECT
*rect
, BOOL vertical
,
576 INT arrowSize
, INT thumbSize
)
578 if( TWEAK_WineLook
== WIN31_LOOK
)
579 SCROLL_DrawMovingThumb_31( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
581 SCROLL_DrawMovingThumb_9x( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
584 /***********************************************************************
585 * SCROLL_DrawInterior
587 * Draw the scroll bar interior (everything except the arrows).
589 static void SCROLL_DrawInterior_9x( HWND hwnd
, HDC hdc
, INT nBar
,
590 RECT
*rect
, INT arrowSize
,
591 INT thumbSize
, INT thumbPos
,
592 UINT flags
, BOOL vertical
,
593 BOOL top_selected
, BOOL bottom_selected
)
597 HBRUSH hSaveBrush
,hBrush
;
599 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
600 * The window-owned scrollbars need to call DEFWND_ControlColor
601 * to correctly setup default scrollbar colors
605 hBrush
= (HBRUSH
)SendMessageA( GetParent(hwnd
), WM_CTLCOLORSCROLLBAR
,
606 (WPARAM
)hdc
,(LPARAM
)hwnd
);
610 hBrush
= DEFWND_ControlColor( hdc
, CTLCOLOR_SCROLLBAR
);
613 hSavePen
= SelectObject( hdc
, SYSCOLOR_GetPen(COLOR_WINDOWFRAME
) );
614 hSaveBrush
= SelectObject( hdc
, hBrush
);
616 /* Calculate the scroll rectangle */
620 r
.top
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
621 r
.bottom
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
625 r
.left
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
626 r
.right
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
629 /* Draw the scroll rectangles and thumb */
630 if (!thumbPos
) /* No thumb to draw */
632 PatBlt( hdc
, r
.left
, r
.top
,
633 r
.right
- r
.left
, r
.bottom
- r
.top
,
636 /* cleanup and return */
637 SelectObject( hdc
, hSavePen
);
638 SelectObject( hdc
, hSaveBrush
);
644 PatBlt( hdc
, r
.left
, r
.top
,
646 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
),
647 top_selected
? 0x0f0000 : PATCOPY
);
648 r
.top
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
649 PatBlt( hdc
, r
.left
, r
.top
+ thumbSize
,
651 r
.bottom
- r
.top
- thumbSize
,
652 bottom_selected
? 0x0f0000 : PATCOPY
);
653 r
.bottom
= r
.top
+ thumbSize
;
655 else /* horizontal */
657 PatBlt( hdc
, r
.left
, r
.top
,
658 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
),
660 top_selected
? 0x0f0000 : PATCOPY
);
661 r
.left
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
662 PatBlt( hdc
, r
.left
+ thumbSize
, r
.top
,
663 r
.right
- r
.left
- thumbSize
,
665 bottom_selected
? 0x0f0000 : PATCOPY
);
666 r
.right
= r
.left
+ thumbSize
;
670 DrawEdge( hdc
, &r
, EDGE_RAISED
, BF_RECT
| BF_MIDDLE
);
673 SelectObject( hdc
, hSavePen
);
674 SelectObject( hdc
, hSaveBrush
);
678 static void SCROLL_DrawInterior( HWND hwnd
, HDC hdc
, INT nBar
,
679 RECT
*rect
, INT arrowSize
,
680 INT thumbSize
, INT thumbPos
,
681 UINT flags
, BOOL vertical
,
682 BOOL top_selected
, BOOL bottom_selected
)
686 HBRUSH hSaveBrush
,hBrush
;
687 BOOL Save_SCROLL_MovingThumb
= SCROLL_MovingThumb
;
689 if (Save_SCROLL_MovingThumb
&&
690 (SCROLL_TrackingWin
== hwnd
) &&
691 (SCROLL_TrackingBar
== nBar
))
692 SCROLL_DrawMovingThumb( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
694 /* Select the correct brush and pen */
696 if (TWEAK_WineLook
== WIN31_LOOK
&& (flags
& ESB_DISABLE_BOTH
) == ESB_DISABLE_BOTH
)
698 /* This ought to be the color of the parent window */
699 hBrush
= GetSysColorBrush(COLOR_WINDOW
);
703 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
704 * The window-owned scrollbars need to call DEFWND_ControlColor
705 * to correctly setup default scrollbar colors
707 if (nBar
== SB_CTL
) {
708 hBrush
= (HBRUSH
)SendMessageA( GetParent(hwnd
), WM_CTLCOLORSCROLLBAR
,
709 (WPARAM
)hdc
,(LPARAM
)hwnd
);
711 hBrush
= DEFWND_ControlColor( hdc
, CTLCOLOR_SCROLLBAR
);
714 hSavePen
= SelectObject( hdc
, SYSCOLOR_GetPen(COLOR_WINDOWFRAME
) );
715 hSaveBrush
= SelectObject( hdc
, hBrush
);
717 /* Calculate the scroll rectangle */
722 r
.top
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
723 r
.bottom
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
727 r
.left
+= arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
;
728 r
.right
-= (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
731 /* Draw the scroll bar frame */
733 /* Only draw outline if Win 3.1. Mar 24, 1999 - Ronald B. Cemer */
734 if (TWEAK_WineLook
== WIN31_LOOK
)
735 Rectangle( hdc
, r
.left
, r
.top
, r
.right
, r
.bottom
);
737 /* Draw the scroll rectangles and thumb */
739 if (!thumbPos
) /* No thumb to draw */
741 INT offset
= (TWEAK_WineLook
> WIN31_LOOK
) ? 0 : 1;
743 PatBlt( hdc
, r
.left
+offset
, r
.top
+offset
,
744 r
.right
- r
.left
- 2*offset
, r
.bottom
- r
.top
- 2*offset
,
747 /* cleanup and return */
748 SelectObject( hdc
, hSavePen
);
749 SelectObject( hdc
, hSaveBrush
);
755 INT offset
= (TWEAK_WineLook
== WIN31_LOOK
) ? 1 : 0;
757 PatBlt( hdc
, r
.left
+ offset
, r
.top
+ offset
,
758 r
.right
- r
.left
- offset
*2,
759 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
) - offset
,
760 top_selected
? 0x0f0000 : PATCOPY
);
761 r
.top
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
762 PatBlt( hdc
, r
.left
+ offset
, r
.top
+ thumbSize
,
763 r
.right
- r
.left
- offset
*2,
764 r
.bottom
- r
.top
- thumbSize
- offset
,
765 bottom_selected
? 0x0f0000 : PATCOPY
);
766 r
.bottom
= r
.top
+ thumbSize
;
768 else /* horizontal */
770 INT offset
= (TWEAK_WineLook
== WIN31_LOOK
) ? 1 : 0;
772 PatBlt( hdc
, r
.left
+ offset
, r
.top
+ offset
,
773 thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
),
774 r
.bottom
- r
.top
- offset
*2,
775 top_selected
? 0x0f0000 : PATCOPY
);
776 r
.left
+= thumbPos
- (arrowSize
- SCROLL_ARROW_THUMB_OVERLAP
);
777 PatBlt( hdc
, r
.left
+ thumbSize
, r
.top
+ offset
,
778 r
.right
- r
.left
- thumbSize
- offset
,
779 r
.bottom
- r
.top
- offset
*2,
780 bottom_selected
? 0x0f0000 : PATCOPY
);
781 r
.right
= r
.left
+ thumbSize
;
786 SelectObject( hdc
, GetSysColorBrush(COLOR_BTNFACE
) );
787 if (TWEAK_WineLook
== WIN31_LOOK
)
789 Rectangle( hdc
, r
.left
, r
.top
, r
.right
, r
.bottom
);
794 Rectangle( hdc
, r
.left
+1, r
.top
+1, r
.right
-1, r
.bottom
-1 );
796 DrawEdge( hdc
, &r
, EDGE_RAISED
, BF_RECT
);
798 if (Save_SCROLL_MovingThumb
&&
799 (SCROLL_TrackingWin
== hwnd
) &&
800 (SCROLL_TrackingBar
== nBar
))
801 SCROLL_DrawMovingThumb( hdc
, rect
, vertical
, arrowSize
, thumbSize
);
804 SelectObject( hdc
, hSavePen
);
805 SelectObject( hdc
, hSaveBrush
);
809 /***********************************************************************
810 * SCROLL_DrawScrollBar
812 * Redraw the whole scrollbar.
814 void SCROLL_DrawScrollBar( HWND hwnd
, HDC hdc
, INT nBar
,
815 BOOL arrows
, BOOL interior
)
817 INT arrowSize
, thumbSize
, thumbPos
;
820 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
821 SCROLLBAR_INFO
*infoPtr
= SCROLL_GetScrollBarInfo( hwnd
, nBar
);
822 BOOL Save_SCROLL_MovingThumb
= SCROLL_MovingThumb
;
824 if (!wndPtr
|| !infoPtr
||
825 ((nBar
== SB_VERT
) && !(wndPtr
->dwStyle
& WS_VSCROLL
)) ||
826 ((nBar
== SB_HORZ
) && !(wndPtr
->dwStyle
& WS_HSCROLL
))) goto END
;
827 if (!WIN_IsWindowDrawable( hwnd
, FALSE
)) goto END
;
828 hwnd
= wndPtr
->hwndSelf
; /* make it a full handle */
830 vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
831 &arrowSize
, &thumbSize
, &thumbPos
);
833 /* do not draw if the scrollbar rectangle is empty */
834 if(IsRectEmpty(&rect
))
837 if (Save_SCROLL_MovingThumb
&&
838 (SCROLL_TrackingWin
== hwnd
) &&
839 (SCROLL_TrackingBar
== nBar
))
840 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
842 /* Draw the arrows */
844 if (arrows
&& arrowSize
)
846 if( vertical
== SCROLL_trackVertical
&& GetCapture() == hwnd
)
847 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
848 (SCROLL_trackHitTest
== SCROLL_TOP_ARROW
),
849 (SCROLL_trackHitTest
== SCROLL_BOTTOM_ARROW
) );
851 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
855 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
856 thumbPos
, infoPtr
->flags
, vertical
, FALSE
, FALSE
);
858 if (Save_SCROLL_MovingThumb
&&
859 (SCROLL_TrackingWin
== hwnd
) &&
860 (SCROLL_TrackingBar
== nBar
))
861 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
863 /* if scroll bar has focus, reposition the caret */
864 if(hwnd
==GetFocus() && (nBar
==SB_CTL
))
868 SetCaretPos(thumbPos
+1, rect
.top
+1);
872 SetCaretPos(rect
.top
+1, thumbPos
+1);
877 WIN_ReleaseWndPtr(wndPtr
);
880 /***********************************************************************
881 * SCROLL_DrawSizeGrip
883 * Draw the size grip.
885 static void SCROLL_DrawSizeGrip( HWND hwnd
, HDC hdc
)
889 GetClientRect( hwnd
, &rc
);
890 FillRect( hdc
, &rc
, GetSysColorBrush(COLOR_SCROLLBAR
) );
891 rc
.left
= max( rc
.left
, rc
.right
- GetSystemMetrics(SM_CXVSCROLL
) - 1 );
892 rc
.top
= max( rc
.top
, rc
.bottom
- GetSystemMetrics(SM_CYHSCROLL
) - 1 );
893 DrawFrameControl( hdc
, &rc
, DFC_SCROLL
, DFCS_SCROLLSIZEGRIP
);
897 /***********************************************************************
898 * SCROLL_RefreshScrollBar
900 * Repaint the scroll bar interior after a SetScrollRange() or
901 * SetScrollPos() call.
903 static void SCROLL_RefreshScrollBar( HWND hwnd
, INT nBar
,
904 BOOL arrows
, BOOL interior
)
906 HDC hdc
= GetDCEx( hwnd
, 0,
907 DCX_CACHE
| ((nBar
== SB_CTL
) ? 0 : DCX_WINDOW
) );
910 SCROLL_DrawScrollBar( hwnd
, hdc
, nBar
, arrows
, interior
);
911 ReleaseDC( hwnd
, hdc
);
915 /***********************************************************************
916 * SCROLL_HandleKbdEvent
918 * Handle a keyboard event (only for SB_CTL scrollbars with focus).
920 static void SCROLL_HandleKbdEvent(
921 HWND hwnd
/* [in] Handle of window with scrollbar(s) */,
922 WPARAM wParam
/* [in] Variable input including enable state */,
923 LPARAM lParam
/* [in] Variable input including input point */)
925 TRACE("hwnd=%p wParam=%d lParam=%ld\n", hwnd
, wParam
, lParam
);
927 /* hide caret on first KEYDOWN to prevent flicker */
928 if ((lParam
& PFD_DOUBLEBUFFER_DONTCARE
) == 0)
933 case VK_PRIOR
: wParam
= SB_PAGEUP
; break;
934 case VK_NEXT
: wParam
= SB_PAGEDOWN
; break;
935 case VK_HOME
: wParam
= SB_TOP
; break;
936 case VK_END
: wParam
= SB_BOTTOM
; break;
937 case VK_UP
: wParam
= SB_LINEUP
; break;
938 case VK_DOWN
: wParam
= SB_LINEDOWN
; break;
941 SendMessageW(GetParent(hwnd
),
942 ((GetWindowLongA( hwnd
, GWL_STYLE
) & SBS_VERT
) ?
943 WM_VSCROLL
: WM_HSCROLL
), wParam
, (LPARAM
)hwnd
);
947 /***********************************************************************
948 * SCROLL_HandleScrollEvent
950 * Handle a mouse or timer event for the scrollbar.
951 * 'pt' is the location of the mouse event in client (for SB_CTL) or
952 * windows coordinates.
954 static void SCROLL_HandleScrollEvent( HWND hwnd
, INT nBar
, UINT msg
, POINT pt
)
956 /* Previous mouse position for timer events */
958 /* Thumb position when tracking started. */
959 static UINT trackThumbPos
;
960 /* Position in the scroll-bar of the last button-down event. */
961 static INT lastClickPos
;
962 /* Position in the scroll-bar of the last mouse event. */
963 static INT lastMousePos
;
965 enum SCROLL_HITTEST hittest
;
966 HWND hwndOwner
, hwndCtl
;
968 INT arrowSize
, thumbSize
, thumbPos
;
972 SCROLLBAR_INFO
*infoPtr
= SCROLL_GetScrollBarInfo( hwnd
, nBar
);
973 if (!infoPtr
) return;
974 if ((SCROLL_trackHitTest
== SCROLL_NOWHERE
) && (msg
!= WM_LBUTTONDOWN
))
977 if (GetWindowLongW( hwnd
, GWL_STYLE
) & (SBS_SIZEGRIP
| SBS_SIZEBOX
))
981 case WM_LBUTTONDOWN
: /* Initialise mouse tracking */
982 HideCaret(hwnd
); /* hide caret while holding down LBUTTON */
985 SCROLL_trackHitTest
= hittest
= SCROLL_THUMB
;
988 GetClientRect(GetParent(GetParent(hwnd
)),&rect
);
993 SCROLL_trackHitTest
= hittest
= SCROLL_NOWHERE
;
994 if (hwnd
==GetFocus()) ShowCaret(hwnd
);
1003 hdc
= GetDCEx( hwnd
, 0, DCX_CACHE
| ((nBar
== SB_CTL
) ? 0 : DCX_WINDOW
));
1004 vertical
= SCROLL_GetScrollBarRect( hwnd
, nBar
, &rect
,
1005 &arrowSize
, &thumbSize
, &thumbPos
);
1006 hwndOwner
= (nBar
== SB_CTL
) ? GetParent(hwnd
) : hwnd
;
1007 hwndCtl
= (nBar
== SB_CTL
) ? hwnd
: 0;
1011 case WM_LBUTTONDOWN
: /* Initialise mouse tracking */
1012 HideCaret(hwnd
); /* hide caret while holding down LBUTTON */
1013 SCROLL_trackVertical
= vertical
;
1014 SCROLL_trackHitTest
= hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, FALSE
);
1015 lastClickPos
= vertical
? (pt
.y
- rect
.top
) : (pt
.x
- rect
.left
);
1016 lastMousePos
= lastClickPos
;
1017 trackThumbPos
= thumbPos
;
1019 if (nBar
== SB_CTL
&& (GetWindowLongA(hwnd
, GWL_STYLE
) & WS_TABSTOP
)) SetFocus( hwnd
);
1024 hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, TRUE
);
1029 hittest
= SCROLL_NOWHERE
;
1031 /* if scrollbar has focus, show back caret */
1032 if (hwnd
==GetFocus()) ShowCaret(hwnd
);
1037 hittest
= SCROLL_HitTest( hwnd
, nBar
, pt
, FALSE
);
1041 return; /* Should never happen */
1044 TRACE("Event: hwnd=%p bar=%d msg=%s pt=%ld,%ld hit=%d\n",
1045 hwnd
, nBar
, SPY_GetMsgName(msg
,hwnd
), pt
.x
, pt
.y
, hittest
);
1047 switch(SCROLL_trackHitTest
)
1049 case SCROLL_NOWHERE
: /* No tracking in progress */
1052 case SCROLL_TOP_ARROW
:
1053 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
1054 (hittest
== SCROLL_trackHitTest
), FALSE
);
1055 if (hittest
== SCROLL_trackHitTest
)
1057 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
1059 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1060 SB_LINEUP
, (LPARAM
)hwndCtl
);
1063 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
1064 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
1067 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
1070 case SCROLL_TOP_RECT
:
1071 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
1072 thumbPos
, infoPtr
->flags
, vertical
,
1073 (hittest
== SCROLL_trackHitTest
), FALSE
);
1074 if (hittest
== SCROLL_trackHitTest
)
1076 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
1078 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1079 SB_PAGEUP
, (LPARAM
)hwndCtl
);
1081 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
1082 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
1085 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
1089 if (msg
== WM_LBUTTONDOWN
)
1091 SCROLL_TrackingWin
= hwnd
;
1092 SCROLL_TrackingBar
= nBar
;
1093 SCROLL_TrackingPos
= trackThumbPos
+ lastMousePos
- lastClickPos
;
1094 SCROLL_TrackingVal
= SCROLL_GetThumbVal( infoPtr
, &rect
,
1096 SCROLL_TrackingPos
);
1097 if (!SCROLL_MovingThumb
)
1098 SCROLL_DrawMovingThumb(hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
1100 else if (msg
== WM_LBUTTONUP
)
1102 if (SCROLL_MovingThumb
)
1103 SCROLL_DrawMovingThumb(hdc
, &rect
, vertical
, arrowSize
, thumbSize
);
1104 SCROLL_TrackingWin
= 0;
1105 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
1106 thumbPos
, infoPtr
->flags
, vertical
,
1109 else /* WM_MOUSEMOVE */
1113 if (!SCROLL_PtInRectEx( &rect
, pt
, vertical
)) pos
= lastClickPos
;
1116 pt
= SCROLL_ClipPos( &rect
, pt
);
1117 pos
= vertical
? (pt
.y
- rect
.top
) : (pt
.x
- rect
.left
);
1119 if ( (pos
!= lastMousePos
) || (!SCROLL_MovingThumb
) )
1121 if (SCROLL_MovingThumb
)
1122 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
,
1123 arrowSize
, thumbSize
);
1125 SCROLL_TrackingPos
= trackThumbPos
+ pos
- lastClickPos
;
1126 SCROLL_TrackingVal
= SCROLL_GetThumbVal( infoPtr
, &rect
,
1128 SCROLL_TrackingPos
);
1129 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1130 MAKEWPARAM( SB_THUMBTRACK
, SCROLL_TrackingVal
),
1132 if (!SCROLL_MovingThumb
)
1133 SCROLL_DrawMovingThumb( hdc
, &rect
, vertical
,
1134 arrowSize
, thumbSize
);
1139 case SCROLL_BOTTOM_RECT
:
1140 SCROLL_DrawInterior( hwnd
, hdc
, nBar
, &rect
, arrowSize
, thumbSize
,
1141 thumbPos
, infoPtr
->flags
, vertical
,
1142 FALSE
, (hittest
== SCROLL_trackHitTest
) );
1143 if (hittest
== SCROLL_trackHitTest
)
1145 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
1147 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1148 SB_PAGEDOWN
, (LPARAM
)hwndCtl
);
1150 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
1151 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
1154 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
1157 case SCROLL_BOTTOM_ARROW
:
1158 SCROLL_DrawArrows( hdc
, infoPtr
, &rect
, arrowSize
, vertical
,
1159 FALSE
, (hittest
== SCROLL_trackHitTest
) );
1160 if (hittest
== SCROLL_trackHitTest
)
1162 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_SYSTIMER
))
1164 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1165 SB_LINEDOWN
, (LPARAM
)hwndCtl
);
1168 SetSystemTimer( hwnd
, SCROLL_TIMER
, (msg
== WM_LBUTTONDOWN
) ?
1169 SCROLL_FIRST_DELAY
: SCROLL_REPEAT_DELAY
,
1172 else KillSystemTimer( hwnd
, SCROLL_TIMER
);
1176 if (msg
== WM_LBUTTONDOWN
)
1179 if (hittest
== SCROLL_THUMB
)
1181 UINT val
= SCROLL_GetThumbVal( infoPtr
, &rect
, vertical
,
1182 trackThumbPos
+ lastMousePos
- lastClickPos
);
1183 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1184 MAKEWPARAM( SB_THUMBTRACK
, val
), (LPARAM
)hwndCtl
);
1188 if (msg
== WM_LBUTTONUP
)
1190 hittest
= SCROLL_trackHitTest
;
1191 SCROLL_trackHitTest
= SCROLL_NOWHERE
; /* Terminate tracking */
1193 if (hittest
== SCROLL_THUMB
)
1195 UINT val
= SCROLL_GetThumbVal( infoPtr
, &rect
, vertical
,
1196 trackThumbPos
+ lastMousePos
- lastClickPos
);
1197 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1198 MAKEWPARAM( SB_THUMBPOSITION
, val
), (LPARAM
)hwndCtl
);
1200 SendMessageA( hwndOwner
, vertical
? WM_VSCROLL
: WM_HSCROLL
,
1201 SB_ENDSCROLL
, (LPARAM
)hwndCtl
);
1204 ReleaseDC( hwnd
, hdc
);
1208 /***********************************************************************
1209 * SCROLL_TrackScrollBar
1211 * Track a mouse button press on a scroll-bar.
1212 * pt is in screen-coordinates for non-client scroll bars.
1214 void SCROLL_TrackScrollBar( HWND hwnd
, INT scrollbar
, POINT pt
)
1217 INT xoffset
= 0, yoffset
= 0;
1219 if (scrollbar
!= SB_CTL
)
1221 WND
*wndPtr
= WIN_GetPtr( hwnd
);
1222 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
) return;
1223 xoffset
= wndPtr
->rectClient
.left
- wndPtr
->rectWindow
.left
;
1224 yoffset
= wndPtr
->rectClient
.top
- wndPtr
->rectWindow
.top
;
1225 WIN_ReleasePtr( wndPtr
);
1226 ScreenToClient( hwnd
, &pt
);
1231 SCROLL_HandleScrollEvent( hwnd
, scrollbar
, WM_LBUTTONDOWN
, pt
);
1235 if (!GetMessageW( &msg
, 0, 0, 0 )) break;
1236 if (CallMsgFilterW( &msg
, MSGF_SCROLLBAR
)) continue;
1242 pt
.x
= LOWORD(msg
.lParam
) + xoffset
;
1243 pt
.y
= HIWORD(msg
.lParam
) + yoffset
;
1244 SCROLL_HandleScrollEvent( hwnd
, scrollbar
, msg
.message
, pt
);
1247 TranslateMessage( &msg
);
1248 DispatchMessageW( &msg
);
1251 if (!IsWindow( hwnd
))
1256 } while (msg
.message
!= WM_LBUTTONUP
);
1260 /***********************************************************************
1261 * SCROLL_CreateScrollBar
1263 * Create a scroll bar
1265 static void SCROLL_CreateScrollBar(
1266 HWND hwnd
/* [in] Handle of window with scrollbar(s) */,
1267 LPCREATESTRUCTW lpCreate
/* [in] The style and place of the scroll bar */)
1269 LPSCROLLBAR_INFO info
= SCROLL_GetScrollBarInfo(hwnd
, SB_CTL
);
1272 TRACE("hwnd=%p lpCreate=%p\n", hwnd
, lpCreate
);
1274 if (lpCreate
->style
& WS_DISABLED
)
1276 info
->flags
= ESB_DISABLE_BOTH
;
1277 TRACE("Created WS_DISABLED scrollbar\n");
1281 if (lpCreate
->style
& SBS_SIZEBOXTOPLEFTALIGN
)
1283 MoveWindow( hwnd
, lpCreate
->x
, lpCreate
->y
, GetSystemMetrics(SM_CXVSCROLL
)+1,
1284 GetSystemMetrics(SM_CYHSCROLL
)+1, FALSE
);
1286 else if(lpCreate
->style
& SBS_SIZEBOXBOTTOMRIGHTALIGN
)
1288 MoveWindow( hwnd
, lpCreate
->x
+lpCreate
->cx
-GetSystemMetrics(SM_CXVSCROLL
)-1,
1289 lpCreate
->y
+lpCreate
->cy
-GetSystemMetrics(SM_CYHSCROLL
)-1,
1290 GetSystemMetrics(SM_CXVSCROLL
)+1,
1291 GetSystemMetrics(SM_CYHSCROLL
)+1, FALSE
);
1293 else if (lpCreate
->style
& SBS_VERT
)
1295 if (lpCreate
->style
& SBS_LEFTALIGN
)
1296 MoveWindow( hwnd
, lpCreate
->x
, lpCreate
->y
,
1297 GetSystemMetrics(SM_CXVSCROLL
)+1, lpCreate
->cy
, FALSE
);
1298 else if (lpCreate
->style
& SBS_RIGHTALIGN
)
1300 lpCreate
->x
+lpCreate
->cx
-GetSystemMetrics(SM_CXVSCROLL
)-1,
1302 GetSystemMetrics(SM_CXVSCROLL
)+1, lpCreate
->cy
, FALSE
);
1306 if (lpCreate
->style
& SBS_TOPALIGN
)
1307 MoveWindow( hwnd
, lpCreate
->x
, lpCreate
->y
,
1308 lpCreate
->cx
, GetSystemMetrics(SM_CYHSCROLL
)+1, FALSE
);
1309 else if (lpCreate
->style
& SBS_BOTTOMALIGN
)
1312 lpCreate
->y
+lpCreate
->cy
-GetSystemMetrics(SM_CYHSCROLL
)-1,
1313 lpCreate
->cx
, GetSystemMetrics(SM_CYHSCROLL
)+1, FALSE
);
1318 /*************************************************************************
1319 * SCROLL_GetScrollInfo
1321 * Internal helper for the API function
1323 static BOOL
SCROLL_GetScrollInfo(
1324 HWND hwnd
/* [in] Handle of window with scrollbar(s) */,
1325 INT nBar
/* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1326 LPSCROLLINFO info
/* [in/out] (fMask specifies which values to retrieve) */)
1328 LPSCROLLBAR_INFO infoPtr
;
1330 /* handle invalid data structure */
1331 if (!SCROLL_ScrollInfoValid(info
)
1332 || !(infoPtr
= SCROLL_GetScrollBarInfo(hwnd
, nBar
)))
1335 /* fill in the desired scroll info structure */
1336 if (info
->fMask
& SIF_PAGE
) info
->nPage
= infoPtr
->page
;
1337 if (info
->fMask
& SIF_POS
) info
->nPos
= infoPtr
->curVal
;
1338 if ((info
->fMask
& SIF_TRACKPOS
) && (info
->cbSize
== sizeof(*info
)))
1339 info
->nTrackPos
= (SCROLL_TrackingWin
== WIN_GetFullHandle(hwnd
)) ? SCROLL_TrackingVal
: infoPtr
->curVal
;
1340 if (info
->fMask
& SIF_RANGE
)
1342 info
->nMin
= infoPtr
->minVal
;
1343 info
->nMax
= infoPtr
->maxVal
;
1346 return (info
->fMask
& SIF_ALL
) != 0;
1350 /*************************************************************************
1351 * SCROLL_GetScrollPos
1353 * Internal helper for the API function
1355 static INT
SCROLL_GetScrollPos(
1356 HWND hwnd
/* [in] Handle of window with scrollbar(s) */,
1357 INT nBar
/* [in] One of SB_HORZ, SB_VERT, or SB_CTL */)
1359 LPSCROLLBAR_INFO infoPtr
= SCROLL_GetScrollBarInfo(hwnd
, nBar
);
1360 return infoPtr
? infoPtr
->curVal
: 0;
1364 /*************************************************************************
1365 * SCROLL_GetScrollRange
1367 * Internal helper for the API function
1371 static BOOL
SCROLL_GetScrollRange(
1372 HWND hwnd
, /* [in] Handle of window */
1373 INT nBar
, /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */
1374 LPINT lpMin
, /* [out] Where to store minimum value */
1375 LPINT lpMax
/* [out] Where to store maximum value */)
1377 LPSCROLLBAR_INFO infoPtr
= SCROLL_GetScrollBarInfo(hwnd
, nBar
);
1379 if (lpMin
) *lpMin
= infoPtr
? infoPtr
->minVal
: 0;
1380 if (lpMax
) *lpMax
= infoPtr
? infoPtr
->maxVal
: 0;
1382 return infoPtr
? TRUE
: FALSE
;
1387 /***********************************************************************
1390 static LRESULT WINAPI
ScrollBarWndProc( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1392 if (!IsWindow( hwnd
)) return 0;
1397 SCROLL_CreateScrollBar(hwnd
, (LPCREATESTRUCTW
)lParam
);
1398 if (!hUpArrow
) SCROLL_LoadBitmaps();
1403 SCROLLBAR_INFO
*infoPtr
;
1404 if ((infoPtr
= SCROLL_GetScrollBarInfo( hwnd
, SB_CTL
)))
1406 infoPtr
->flags
= wParam
? ESB_ENABLE_BOTH
: ESB_DISABLE_BOTH
;
1407 SCROLL_RefreshScrollBar(hwnd
, SB_CTL
, TRUE
, TRUE
);
1412 case WM_LBUTTONDOWN
:
1415 pt
.x
= (short)LOWORD(lParam
);
1416 pt
.y
= (short)HIWORD(lParam
);
1417 SCROLL_TrackScrollBar( hwnd
, SB_CTL
, pt
);
1425 pt
.x
= (short)LOWORD(lParam
);
1426 pt
.y
= (short)HIWORD(lParam
);
1427 SCROLL_HandleScrollEvent( hwnd
, SB_CTL
, message
, pt
);
1432 SCROLL_HandleKbdEvent(hwnd
, wParam
, lParam
);
1441 /* Create a caret when a ScrollBar get focus */
1443 int arrowSize
, thumbSize
, thumbPos
, vertical
;
1444 vertical
= SCROLL_GetScrollBarRect( hwnd
, SB_CTL
, &rect
,
1445 &arrowSize
, &thumbSize
, &thumbPos
);
1448 CreateCaret(hwnd
, (HBITMAP
)1, thumbSize
-2, rect
.bottom
-rect
.top
-2);
1449 SetCaretPos(thumbPos
+1, rect
.top
+1);
1453 CreateCaret(hwnd
, (HBITMAP
)1, rect
.right
-rect
.left
-2,thumbSize
-2);
1454 SetCaretPos(rect
.top
+1, thumbPos
+1);
1463 int arrowSize
, thumbSize
, thumbPos
, vertical
;
1464 vertical
= SCROLL_GetScrollBarRect( hwnd
, SB_CTL
, &rect
,&arrowSize
, &thumbSize
, &thumbPos
);
1466 rect
.left
=thumbPos
+1;
1467 rect
.right
=rect
.left
+thumbSize
;
1471 rect
.top
=thumbPos
+1;
1472 rect
.bottom
=rect
.top
+thumbSize
;
1475 InvalidateRect(hwnd
,&rect
,0);
1484 return DLGC_WANTARROWS
; /* Windows returns this value */
1489 HDC hdc
= wParam
? (HDC
)wParam
: BeginPaint(hwnd
, &ps
);
1490 if (GetWindowLongW( hwnd
, GWL_STYLE
) & SBS_SIZEGRIP
)
1492 SCROLL_DrawSizeGrip( hwnd
, hdc
);
1494 else if (GetWindowLongW( hwnd
, GWL_STYLE
) & SBS_SIZEBOX
)
1497 GetClientRect( hwnd
, &rc
);
1498 FillRect( hdc
, &rc
, GetSysColorBrush(COLOR_SCROLLBAR
) );
1501 SCROLL_DrawScrollBar( hwnd
, hdc
, SB_CTL
, TRUE
, TRUE
);
1502 if (!wParam
) EndPaint(hwnd
, &ps
);
1508 return SetScrollPos( hwnd
, SB_CTL
, wParam
, (BOOL
)lParam
);
1512 return SCROLL_GetScrollPos(hwnd
, SB_CTL
);
1514 case SBM_SETRANGE16
:
1515 SetScrollRange( hwnd
, SB_CTL
, LOWORD(lParam
), HIWORD(lParam
),
1516 wParam
/* FIXME: Is this correct? */ );
1521 INT oldPos
= SCROLL_GetScrollPos( hwnd
, SB_CTL
);
1522 SetScrollRange( hwnd
, SB_CTL
, wParam
, lParam
, FALSE
);
1523 if (oldPos
!= SCROLL_GetScrollPos( hwnd
, SB_CTL
)) return oldPos
;
1527 case SBM_GETRANGE16
:
1528 FIXME("don't know how to handle SBM_GETRANGE16 (wp=%04x,lp=%08lx)\n", wParam
, lParam
);
1532 return SCROLL_GetScrollRange(hwnd
, SB_CTL
, (LPINT
)wParam
, (LPINT
)lParam
);
1534 case SBM_ENABLE_ARROWS16
:
1535 case SBM_ENABLE_ARROWS
:
1536 return EnableScrollBar( hwnd
, SB_CTL
, wParam
);
1538 case SBM_SETRANGEREDRAW
:
1540 INT oldPos
= SCROLL_GetScrollPos( hwnd
, SB_CTL
);
1541 SetScrollRange( hwnd
, SB_CTL
, wParam
, lParam
, TRUE
);
1542 if (oldPos
!= SCROLL_GetScrollPos( hwnd
, SB_CTL
)) return oldPos
;
1546 case SBM_SETSCROLLINFO
:
1547 return SetScrollInfo( hwnd
, SB_CTL
, (SCROLLINFO
*)lParam
, wParam
);
1549 case SBM_GETSCROLLINFO
:
1550 return SCROLL_GetScrollInfo(hwnd
, SB_CTL
, (SCROLLINFO
*)lParam
);
1560 ERR("unknown Win32 msg %04x wp=%08x lp=%08lx\n",
1561 message
, wParam
, lParam
);
1565 if (message
>= WM_USER
)
1566 WARN("unknown msg %04x wp=%04x lp=%08lx\n",
1567 message
, wParam
, lParam
);
1568 return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1574 /*************************************************************************
1575 * SetScrollInfo (USER32.@)
1576 * SetScrollInfo can be used to set the position, upper bound,
1577 * lower bound, and page size of a scrollbar control.
1580 * Scrollbar position
1583 * For 100 lines of text to be displayed in a window of 25 lines,
1584 * one would for instance use info->nMin=0, info->nMax=75
1585 * (corresponding to the 76 different positions of the window on
1586 * the text), and info->nPage=25.
1588 INT WINAPI
SetScrollInfo(
1589 HWND hwnd
/* [in] Handle of window whose scrollbar will be affected */,
1590 INT nBar
/* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1591 const SCROLLINFO
*info
/* [in] Specifies what to change and new values */,
1592 BOOL bRedraw
/* [in] Should scrollbar be redrawn afterwards ? */)
1595 INT retVal
= SCROLL_SetScrollInfo( hwnd
, nBar
, info
, &action
);
1597 if( action
& SA_SSI_HIDE
)
1598 SCROLL_ShowScrollBar( hwnd
, nBar
, FALSE
, FALSE
);
1601 if( action
& SA_SSI_SHOW
)
1602 if( SCROLL_ShowScrollBar( hwnd
, nBar
, TRUE
, TRUE
) )
1603 return retVal
; /* SetWindowPos() already did the painting */
1606 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, TRUE
);
1607 else if( action
& SA_SSI_REPAINT_ARROWS
)
1608 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, FALSE
);
1613 INT
SCROLL_SetScrollInfo( HWND hwnd
, INT nBar
,
1614 const SCROLLINFO
*info
, INT
*action
)
1616 /* Update the scrollbar state and set action flags according to
1617 * what has to be done graphics wise. */
1619 SCROLLBAR_INFO
*infoPtr
;
1621 BOOL bChangeParams
= FALSE
; /* don't show/hide scrollbar if params don't change */
1625 if (!(infoPtr
= SCROLL_GetScrollBarInfo(hwnd
, nBar
))) return 0;
1626 if (info
->fMask
& ~(SIF_ALL
| SIF_DISABLENOSCROLL
)) return 0;
1627 if ((info
->cbSize
!= sizeof(*info
)) &&
1628 (info
->cbSize
!= sizeof(*info
)-sizeof(info
->nTrackPos
))) return 0;
1630 if (TRACE_ON(scroll
))
1632 TRACE("hwnd=%p bar=%d", hwnd
, nBar
);
1633 if (info
->fMask
& SIF_PAGE
) TRACE( " page=%d", info
->nPage
);
1634 if (info
->fMask
& SIF_POS
) TRACE( " pos=%d", info
->nPos
);
1635 if (info
->fMask
& SIF_RANGE
) TRACE( " min=%d max=%d", info
->nMin
, info
->nMax
);
1639 /* Set the page size */
1641 if (info
->fMask
& SIF_PAGE
)
1643 if( infoPtr
->page
!= info
->nPage
)
1645 infoPtr
->page
= info
->nPage
;
1646 *action
|= SA_SSI_REFRESH
;
1647 bChangeParams
= TRUE
;
1651 /* Set the scroll pos */
1653 if (info
->fMask
& SIF_POS
)
1655 if( infoPtr
->curVal
!= info
->nPos
)
1657 infoPtr
->curVal
= info
->nPos
;
1658 *action
|= SA_SSI_REFRESH
;
1662 /* Set the scroll range */
1664 if (info
->fMask
& SIF_RANGE
)
1666 /* Invalid range -> range is set to (0,0) */
1667 if ((info
->nMin
> info
->nMax
) ||
1668 ((UINT
)(info
->nMax
- info
->nMin
) >= 0x80000000))
1670 infoPtr
->minVal
= 0;
1671 infoPtr
->maxVal
= 0;
1672 bChangeParams
= TRUE
;
1676 if( infoPtr
->minVal
!= info
->nMin
||
1677 infoPtr
->maxVal
!= info
->nMax
)
1679 *action
|= SA_SSI_REFRESH
;
1680 infoPtr
->minVal
= info
->nMin
;
1681 infoPtr
->maxVal
= info
->nMax
;
1682 bChangeParams
= TRUE
;
1687 /* Make sure the page size is valid */
1689 if (infoPtr
->page
< 0) infoPtr
->page
= 0;
1690 else if (infoPtr
->page
> infoPtr
->maxVal
- infoPtr
->minVal
+ 1 )
1691 infoPtr
->page
= infoPtr
->maxVal
- infoPtr
->minVal
+ 1;
1693 /* Make sure the pos is inside the range */
1695 if (infoPtr
->curVal
< infoPtr
->minVal
)
1696 infoPtr
->curVal
= infoPtr
->minVal
;
1697 else if (infoPtr
->curVal
> infoPtr
->maxVal
- max( infoPtr
->page
-1, 0 ))
1698 infoPtr
->curVal
= infoPtr
->maxVal
- max( infoPtr
->page
-1, 0 );
1700 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1701 infoPtr
->page
, infoPtr
->curVal
,
1702 infoPtr
->minVal
, infoPtr
->maxVal
);
1704 /* don't change the scrollbar state if SetScrollInfo
1705 * is just called with SIF_DISABLENOSCROLL
1707 if(!(info
->fMask
& SIF_ALL
)) goto done
;
1709 /* Check if the scrollbar should be hidden or disabled */
1711 if (info
->fMask
& (SIF_RANGE
| SIF_PAGE
| SIF_DISABLENOSCROLL
))
1713 new_flags
= infoPtr
->flags
;
1714 if (infoPtr
->minVal
>= infoPtr
->maxVal
- max( infoPtr
->page
-1, 0 ))
1716 /* Hide or disable scroll-bar */
1717 if (info
->fMask
& SIF_DISABLENOSCROLL
)
1719 new_flags
= ESB_DISABLE_BOTH
;
1720 *action
|= SA_SSI_REFRESH
;
1722 else if ((nBar
!= SB_CTL
) && bChangeParams
)
1724 *action
= SA_SSI_HIDE
;
1728 else /* Show and enable scroll-bar */
1731 if ((nBar
!= SB_CTL
) && bChangeParams
)
1732 *action
|= SA_SSI_SHOW
;
1735 if (infoPtr
->flags
!= new_flags
) /* check arrow flags */
1737 infoPtr
->flags
= new_flags
;
1738 *action
|= SA_SSI_REPAINT_ARROWS
;
1743 /* Return current position */
1745 return infoPtr
->curVal
;
1749 /*************************************************************************
1750 * GetScrollInfo (USER32.@)
1752 * GetScrollInfo can be used to retrieve the position, upper bound,
1753 * lower bound, and page size of a scrollbar control.
1757 BOOL WINAPI
GetScrollInfo(
1758 HWND hwnd
/* [in] Handle of window with scrollbar(s) */,
1759 INT nBar
/* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1760 LPSCROLLINFO info
/* [in/out] (fMask specifies which values to retrieve) */)
1762 TRACE("hwnd=%p nBar=%d info=%p\n", hwnd
, nBar
, info
);
1764 /* Refer SB_CTL requests to the window */
1766 return SendMessageA(hwnd
, SBM_GETSCROLLINFO
, (WPARAM
)0, (LPARAM
)info
);
1768 return SCROLL_GetScrollInfo(hwnd
, nBar
, info
);
1772 /*************************************************************************
1773 * SetScrollPos (USER32.@)
1776 * Success: Scrollbar position
1780 * Note the ambiguity when 0 is returned. Use GetLastError
1781 * to make sure there was an error (and to know which one).
1783 INT WINAPI
SetScrollPos(
1784 HWND hwnd
/* [in] Handle of window whose scrollbar will be affected */,
1785 INT nBar
/* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1786 INT nPos
/* [in] New value */,
1787 BOOL bRedraw
/* [in] Should scrollbar be redrawn afterwards ? */ )
1790 SCROLLBAR_INFO
*infoPtr
;
1793 if (!(infoPtr
= SCROLL_GetScrollBarInfo( hwnd
, nBar
))) return 0;
1794 oldPos
= infoPtr
->curVal
;
1795 info
.cbSize
= sizeof(info
);
1797 info
.fMask
= SIF_POS
;
1798 SetScrollInfo( hwnd
, nBar
, &info
, bRedraw
);
1803 /*************************************************************************
1804 * GetScrollPos (USER32.@)
1807 * Success: Current position
1811 * There is ambiguity when 0 is returned. Use GetLastError
1812 * to make sure there was an error (and to know which one).
1814 INT WINAPI
GetScrollPos(
1815 HWND hwnd
/* [in] Handle of window with scrollbar(s) */,
1816 INT nBar
/* [in] One of SB_HORZ, SB_VERT, or SB_CTL */)
1818 TRACE("hwnd=%p nBar=%d\n", hwnd
, nBar
);
1820 /* Refer SB_CTL requests to the window */
1822 return SendMessageA(hwnd
, SBM_GETPOS
, (WPARAM
)0, (LPARAM
)0);
1824 return SCROLL_GetScrollPos(hwnd
, nBar
);
1828 /*************************************************************************
1829 * SetScrollRange (USER32.@)
1833 BOOL WINAPI
SetScrollRange(
1834 HWND hwnd
, /* [in] Handle of window whose scrollbar will be affected */
1835 INT nBar
, /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */
1836 INT minVal
, /* [in] New minimum value */
1837 INT maxVal
, /* [in] New maximum value */
1838 BOOL bRedraw
/* [in] Should scrollbar be redrawn afterwards ? */)
1842 info
.cbSize
= sizeof(info
);
1845 info
.fMask
= SIF_RANGE
;
1846 SetScrollInfo( hwnd
, nBar
, &info
, bRedraw
);
1851 /*************************************************************************
1852 * SCROLL_SetNCSbState
1854 * Updates both scrollbars at the same time. Used by MDI CalcChildScroll().
1856 INT
SCROLL_SetNCSbState(HWND hwnd
, int vMin
, int vMax
, int vPos
,
1857 int hMin
, int hMax
, int hPos
)
1860 SCROLLINFO vInfo
, hInfo
;
1862 vInfo
.cbSize
= hInfo
.cbSize
= sizeof(SCROLLINFO
);
1869 vInfo
.fMask
= hInfo
.fMask
= SIF_RANGE
| SIF_POS
;
1871 SCROLL_SetScrollInfo( hwnd
, SB_VERT
, &vInfo
, &vA
);
1872 SCROLL_SetScrollInfo( hwnd
, SB_HORZ
, &hInfo
, &hA
);
1874 if( !SCROLL_ShowScrollBar( hwnd
, SB_BOTH
,
1875 (hA
& SA_SSI_SHOW
),(vA
& SA_SSI_SHOW
) ) )
1877 /* SetWindowPos() wasn't called, just redraw the scrollbars if needed */
1878 if( vA
& SA_SSI_REFRESH
)
1879 SCROLL_RefreshScrollBar( hwnd
, SB_VERT
, FALSE
, TRUE
);
1881 if( hA
& SA_SSI_REFRESH
)
1882 SCROLL_RefreshScrollBar( hwnd
, SB_HORZ
, FALSE
, TRUE
);
1888 /*************************************************************************
1889 * GetScrollRange (USER32.@)
1893 BOOL WINAPI
GetScrollRange(
1894 HWND hwnd
/* [in] Handle of window with scrollbar(s) */,
1895 INT nBar
/* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1896 LPINT lpMin
/* [out] Where to store minimum value */,
1897 LPINT lpMax
/* [out] Where to store maximum value */)
1899 TRACE("hwnd=%p nBar=%d lpMin=%p lpMax=%p\n", hwnd
, nBar
, lpMin
, lpMax
);
1901 /* Refer SB_CTL requests to the window */
1903 return SendMessageA(hwnd
, SBM_GETRANGE
, (WPARAM
)lpMin
, (LPARAM
)lpMax
);
1905 return SCROLL_GetScrollRange(hwnd
, nBar
, lpMin
, lpMax
);
1909 /*************************************************************************
1910 * SCROLL_ShowScrollBar()
1912 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1914 BOOL
SCROLL_ShowScrollBar( HWND hwnd
, INT nBar
,
1915 BOOL fShowH
, BOOL fShowV
)
1917 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1919 TRACE("hwnd=%p bar=%d horz=%d, vert=%d\n", hwnd
, nBar
, fShowH
, fShowV
);
1924 ShowWindow( hwnd
, fShowH
? SW_SHOW
: SW_HIDE
);
1931 fShowH
= !(style
& WS_HSCROLL
);
1932 style
|= WS_HSCROLL
;
1936 fShowH
= (style
& WS_HSCROLL
);
1937 style
&= ~WS_HSCROLL
;
1939 if( nBar
== SB_HORZ
) {
1948 fShowV
= !(style
& WS_VSCROLL
);
1949 style
|= WS_VSCROLL
;
1953 fShowV
= (style
& WS_VSCROLL
);
1954 style
&= ~WS_VSCROLL
;
1956 if ( nBar
== SB_VERT
)
1961 return FALSE
; /* Nothing to do! */
1964 if( fShowH
|| fShowV
) /* frame has been changed, let the window redraw itself */
1966 WIN_SetStyle( hwnd
, style
);
1967 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
1968 | SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
1971 return FALSE
; /* no frame changes */
1975 /*************************************************************************
1976 * ShowScrollBar (USER32.@)
1980 BOOL WINAPI
ShowScrollBar(
1981 HWND hwnd
, /* [in] Handle of window whose scrollbar(s) will be affected */
1982 INT nBar
, /* [in] One of SB_HORZ, SB_VERT, SB_BOTH or SB_CTL */
1983 BOOL fShow
/* [in] TRUE = show, FALSE = hide */)
1985 SCROLL_ShowScrollBar( hwnd
, nBar
, (nBar
== SB_VERT
) ? 0 : fShow
,
1986 (nBar
== SB_HORZ
) ? 0 : fShow
);
1991 /*************************************************************************
1992 * EnableScrollBar (USER32.@)
1994 BOOL WINAPI
EnableScrollBar( HWND hwnd
, INT nBar
, UINT flags
)
1997 SCROLLBAR_INFO
*infoPtr
;
1999 TRACE("%p %d %d\n", hwnd
, nBar
, flags
);
2001 flags
&= ESB_DISABLE_BOTH
;
2003 if (nBar
== SB_BOTH
)
2005 if (!(infoPtr
= SCROLL_GetScrollBarInfo( hwnd
, SB_VERT
))) return FALSE
;
2006 if (!(bFineWithMe
= (infoPtr
->flags
== flags
)) )
2008 infoPtr
->flags
= flags
;
2009 SCROLL_RefreshScrollBar( hwnd
, SB_VERT
, TRUE
, TRUE
);
2016 if (!(infoPtr
= SCROLL_GetScrollBarInfo( hwnd
, nBar
))) return FALSE
;
2017 if (bFineWithMe
&& infoPtr
->flags
== flags
) return FALSE
;
2018 infoPtr
->flags
= flags
;
2020 SCROLL_RefreshScrollBar( hwnd
, nBar
, TRUE
, TRUE
);