4 * Copyright 1993 Martin Ayotte
5 * Copyright 1994, 1996 Alexandre Julliard
10 #include "wine/winuser16.h"
14 #include "debugtools.h"
18 DEFAULT_DEBUG_CHANNEL(scroll);
22 INT CurVal; /* Current scroll-bar value */
23 INT MinVal; /* Minimum scroll-bar value */
24 INT MaxVal; /* Maximum scroll-bar value */
25 INT Page; /* Page size of scroll bar (Win32) */
26 UINT flags; /* EnableScrollBar flags */
30 static HBITMAP hUpArrow;
31 static HBITMAP hDnArrow;
32 static HBITMAP hLfArrow;
33 static HBITMAP hRgArrow;
34 static HBITMAP hUpArrowD;
35 static HBITMAP hDnArrowD;
36 static HBITMAP hLfArrowD;
37 static HBITMAP hRgArrowD;
38 static HBITMAP hUpArrowI;
39 static HBITMAP hDnArrowI;
40 static HBITMAP hLfArrowI;
41 static HBITMAP hRgArrowI;
43 #define TOP_ARROW(flags,pressed) \
44 (((flags)&ESB_DISABLE_UP) ? hUpArrowI : ((pressed) ? hUpArrowD:hUpArrow))
45 #define BOTTOM_ARROW(flags,pressed) \
46 (((flags)&ESB_DISABLE_DOWN) ? hDnArrowI : ((pressed) ? hDnArrowD:hDnArrow))
47 #define LEFT_ARROW(flags,pressed) \
48 (((flags)&ESB_DISABLE_LEFT) ? hLfArrowI : ((pressed) ? hLfArrowD:hLfArrow))
49 #define RIGHT_ARROW(flags,pressed) \
50 (((flags)&ESB_DISABLE_RIGHT) ? hRgArrowI : ((pressed) ? hRgArrowD:hRgArrow))
53 /* Minimum size of the rectangle between the arrows */
54 #define SCROLL_MIN_RECT 4
56 /* Minimum size of the thumb in pixels */
57 #define SCROLL_MIN_THUMB 6
59 /* Overlap between arrows and thumb */
60 #define SCROLL_ARROW_THUMB_OVERLAP ((TWEAK_WineLook == WIN31_LOOK) ? 1 : 0)
62 /* Delay (in ms) before first repetition when holding the button down */
63 #define SCROLL_FIRST_DELAY 200
65 /* Delay (in ms) between scroll repetitions */
66 #define SCROLL_REPEAT_DELAY 50
69 #define SCROLL_TIMER 0
71 /* Scroll-bar hit testing */
74 SCROLL_NOWHERE, /* Outside the scroll bar */
75 SCROLL_TOP_ARROW, /* Top or left arrow */
76 SCROLL_TOP_RECT, /* Rectangle between the top arrow and the thumb */
77 SCROLL_THUMB, /* Thumb rectangle */
78 SCROLL_BOTTOM_RECT, /* Rectangle between the thumb and the bottom arrow */
79 SCROLL_BOTTOM_ARROW /* Bottom or right arrow */
82 /* What to do after SCROLL_SetScrollInfo() */
83 #define SA_SSI_HIDE 0x0001
84 #define SA_SSI_SHOW 0x0002
85 #define SA_SSI_REFRESH 0x0004
86 #define SA_SSI_REPAINT_ARROWS 0x0008
88 /* Thumb-tracking info */
89 static HWND SCROLL_TrackingWin = 0;
90 static INT SCROLL_TrackingBar = 0;
91 static INT SCROLL_TrackingPos = 0;
92 static INT SCROLL_TrackingVal = 0;
93 /* Hit test code of the last button-down event */
94 static enum SCROLL_HITTEST SCROLL_trackHitTest;
95 static BOOL SCROLL_trackVertical;
97 /* Is the moving thumb being displayed? */
98 static BOOL SCROLL_MovingThumb = FALSE;
100 /* Local functions */
101 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar,
102 BOOL fShowH, BOOL fShowV );
103 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar,
104 const SCROLLINFO *info, INT *action );
105 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
106 RECT *rect, INT arrowSize,
107 INT thumbSize, INT thumbPos,
108 UINT flags, BOOL vertical,
109 BOOL top_selected, BOOL bottom_selected );
110 static LRESULT WINAPI ScrollBarWndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
113 /*********************************************************************
114 * scrollbar class descriptor
116 const struct builtin_class_descr SCROLL_builtin_class =
118 "ScrollBar", /* name */
119 CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC, /* style */
120 NULL, /* procA (winproc is Unicode only) */
121 ScrollBarWndProc, /* procW */
122 sizeof(SCROLLBAR_INFO), /* extra */
123 IDC_ARROWA, /* cursor */
128 /***********************************************************************
131 static void SCROLL_LoadBitmaps(void)
133 hUpArrow = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROW) );
134 hDnArrow = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROW) );
135 hLfArrow = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROW) );
136 hRgArrow = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROW) );
137 hUpArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROWD) );
138 hDnArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROWD) );
139 hLfArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROWD) );
140 hRgArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROWD) );
141 hUpArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROWI) );
142 hDnArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROWI) );
143 hLfArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROWI) );
144 hRgArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROWI) );
148 /***********************************************************************
149 * SCROLL_GetPtrScrollInfo
151 static SCROLLBAR_INFO *SCROLL_GetPtrScrollInfo( WND* wndPtr, INT nBar )
153 SCROLLBAR_INFO *infoPtr;
155 if (!wndPtr) return NULL;
158 case SB_HORZ: infoPtr = (SCROLLBAR_INFO *)wndPtr->pHScroll; break;
159 case SB_VERT: infoPtr = (SCROLLBAR_INFO *)wndPtr->pVScroll; break;
160 case SB_CTL: infoPtr = (SCROLLBAR_INFO *)wndPtr->wExtra; break;
161 default: return NULL;
164 if (!infoPtr) /* Create the info structure if needed */
166 if ((infoPtr = HeapAlloc( SystemHeap, 0, sizeof(SCROLLBAR_INFO) )))
168 infoPtr->MinVal = infoPtr->CurVal = infoPtr->Page = 0;
169 infoPtr->MaxVal = 100;
170 infoPtr->flags = ESB_ENABLE_BOTH;
171 if (nBar == SB_HORZ) wndPtr->pHScroll = infoPtr;
172 else wndPtr->pVScroll = infoPtr;
174 if (!hUpArrow) SCROLL_LoadBitmaps();
180 /***********************************************************************
181 * SCROLL_GetScrollInfo
183 static SCROLLBAR_INFO *SCROLL_GetScrollInfo( HWND hwnd, INT nBar )
185 SCROLLBAR_INFO *retvalue;
186 WND *wndPtr = WIN_FindWndPtr( hwnd );
187 retvalue = SCROLL_GetPtrScrollInfo( wndPtr, nBar );
188 WIN_ReleaseWndPtr(wndPtr);
193 /***********************************************************************
194 * SCROLL_GetScrollBarRect
196 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
197 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
198 * 'arrowSize' returns the width or height of an arrow (depending on
199 * the orientation of the scrollbar), 'thumbSize' returns the size of
200 * the thumb, and 'thumbPos' returns the position of the thumb
201 * relative to the left or to the top.
202 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
204 static BOOL SCROLL_GetScrollBarRect( HWND hwnd, INT nBar, RECT *lprect,
205 INT *arrowSize, INT *thumbSize,
210 WND *wndPtr = WIN_FindWndPtr( hwnd );
215 lprect->left = wndPtr->rectClient.left - wndPtr->rectWindow.left;
216 lprect->top = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
217 lprect->right = wndPtr->rectClient.right - wndPtr->rectWindow.left;
218 lprect->bottom = lprect->top + GetSystemMetrics(SM_CYHSCROLL);
219 if(wndPtr->dwStyle & WS_BORDER) {
222 } else if(wndPtr->dwStyle & WS_VSCROLL)
228 lprect->left = wndPtr->rectClient.right - wndPtr->rectWindow.left;
229 lprect->top = wndPtr->rectClient.top - wndPtr->rectWindow.top;
230 lprect->right = lprect->left + GetSystemMetrics(SM_CXVSCROLL);
231 lprect->bottom = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
232 if(wndPtr->dwStyle & WS_BORDER) {
235 } else if(wndPtr->dwStyle & WS_HSCROLL)
241 GetClientRect( hwnd, lprect );
242 vertical = ((wndPtr->dwStyle & SBS_VERT) != 0);
246 WIN_ReleaseWndPtr(wndPtr);
250 if (vertical) pixels = lprect->bottom - lprect->top;
251 else pixels = lprect->right - lprect->left;
253 if (pixels <= 2*GetSystemMetrics(SM_CXVSCROLL) + SCROLL_MIN_RECT)
255 if (pixels > SCROLL_MIN_RECT)
256 *arrowSize = (pixels - SCROLL_MIN_RECT) / 2;
259 *thumbPos = *thumbSize = 0;
263 SCROLLBAR_INFO *info = SCROLL_GetPtrScrollInfo( wndPtr, nBar );
265 *arrowSize = GetSystemMetrics(SM_CXVSCROLL);
266 pixels -= (2 * (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP));
270 *thumbSize = pixels * info->Page / (info->MaxVal-info->MinVal+1);
271 if (*thumbSize < SCROLL_MIN_THUMB) *thumbSize = SCROLL_MIN_THUMB;
273 else *thumbSize = GetSystemMetrics(SM_CXVSCROLL);
275 if (((pixels -= *thumbSize ) < 0) ||
276 ((info->flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH))
278 /* Rectangle too small or scrollbar disabled -> no thumb */
279 *thumbPos = *thumbSize = 0;
283 INT max = info->MaxVal - max( info->Page-1, 0 );
284 if (info->MinVal >= max)
285 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
287 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP
288 + pixels * (info->CurVal-info->MinVal) / (max - info->MinVal);
291 WIN_ReleaseWndPtr(wndPtr);
296 /***********************************************************************
299 * Compute the current scroll position based on the thumb position in pixels
300 * from the top of the scroll-bar.
302 static UINT SCROLL_GetThumbVal( SCROLLBAR_INFO *infoPtr, RECT *rect,
303 BOOL vertical, INT pos )
306 INT pixels = vertical ? rect->bottom-rect->top : rect->right-rect->left;
308 if ((pixels -= 2*(GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP)) <= 0)
309 return infoPtr->MinVal;
313 thumbSize = pixels * infoPtr->Page/(infoPtr->MaxVal-infoPtr->MinVal+1);
314 if (thumbSize < SCROLL_MIN_THUMB) thumbSize = SCROLL_MIN_THUMB;
316 else thumbSize = GetSystemMetrics(SM_CXVSCROLL);
318 if ((pixels -= thumbSize) <= 0) return infoPtr->MinVal;
320 pos = max( 0, pos - (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP) );
321 if (pos > pixels) pos = pixels;
323 if (!infoPtr->Page) pos *= infoPtr->MaxVal - infoPtr->MinVal;
324 else pos *= infoPtr->MaxVal - infoPtr->MinVal - infoPtr->Page + 1;
325 return infoPtr->MinVal + ((pos + pixels / 2) / pixels);
328 /***********************************************************************
331 static BOOL SCROLL_PtInRectEx( LPRECT lpRect, POINT pt, BOOL vertical )
337 rect.left -= lpRect->right - lpRect->left;
338 rect.right += lpRect->right - lpRect->left;
342 rect.top -= lpRect->bottom - lpRect->top;
343 rect.bottom += lpRect->bottom - lpRect->top;
345 return PtInRect( &rect, pt );
348 /***********************************************************************
351 static POINT SCROLL_ClipPos( LPRECT lpRect, POINT pt )
353 if( pt.x < lpRect->left )
356 if( pt.x > lpRect->right )
357 pt.x = lpRect->right;
359 if( pt.y < lpRect->top )
362 if( pt.y > lpRect->bottom )
363 pt.y = lpRect->bottom;
369 /***********************************************************************
372 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
374 static enum SCROLL_HITTEST SCROLL_HitTest( HWND hwnd, INT nBar,
375 POINT pt, BOOL bDragging )
377 INT arrowSize, thumbSize, thumbPos;
380 BOOL vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
381 &arrowSize, &thumbSize, &thumbPos );
383 if ( (bDragging && !SCROLL_PtInRectEx( &rect, pt, vertical )) ||
384 (!PtInRect( &rect, pt )) ) return SCROLL_NOWHERE;
388 if (pt.y < rect.top + arrowSize) return SCROLL_TOP_ARROW;
389 if (pt.y >= rect.bottom - arrowSize) return SCROLL_BOTTOM_ARROW;
390 if (!thumbPos) return SCROLL_TOP_RECT;
392 if (pt.y < thumbPos) return SCROLL_TOP_RECT;
393 if (pt.y >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
395 else /* horizontal */
397 if (pt.x < rect.left + arrowSize) return SCROLL_TOP_ARROW;
398 if (pt.x >= rect.right - arrowSize) return SCROLL_BOTTOM_ARROW;
399 if (!thumbPos) return SCROLL_TOP_RECT;
401 if (pt.x < thumbPos) return SCROLL_TOP_RECT;
402 if (pt.x >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
408 /***********************************************************************
411 * Draw the scroll bar arrows.
413 static void SCROLL_DrawArrows_9x( HDC hdc, SCROLLBAR_INFO *infoPtr,
414 RECT *rect, INT arrowSize, BOOL vertical,
415 BOOL top_pressed, BOOL bottom_pressed )
421 r.bottom = r.top + arrowSize;
423 r.right = r.left + arrowSize;
425 DrawFrameControl( hdc, &r, DFC_SCROLL,
426 (vertical ? DFCS_SCROLLUP : DFCS_SCROLLLEFT)
427 | (top_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
428 | (infoPtr->flags&ESB_DISABLE_LTUP ? DFCS_INACTIVE : 0 ) );
432 r.top = r.bottom-arrowSize;
434 r.left = r.right-arrowSize;
436 DrawFrameControl( hdc, &r, DFC_SCROLL,
437 (vertical ? DFCS_SCROLLDOWN : DFCS_SCROLLRIGHT)
438 | (bottom_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
439 | (infoPtr->flags&ESB_DISABLE_RTDN ? DFCS_INACTIVE : 0) );
442 static void SCROLL_DrawArrows_31( HDC hdc, SCROLLBAR_INFO *infoPtr,
443 RECT *rect, INT arrowSize, BOOL vertical,
444 BOOL top_pressed, BOOL bottom_pressed )
446 HDC hdcMem = CreateCompatibleDC( hdc );
447 HBITMAP hbmpPrev = SelectObject( hdcMem, vertical ?
448 TOP_ARROW(infoPtr->flags, top_pressed)
449 : LEFT_ARROW(infoPtr->flags, top_pressed));
451 SetStretchBltMode( hdc, STRETCH_DELETESCANS );
452 StretchBlt( hdc, rect->left, rect->top,
453 vertical ? rect->right-rect->left : arrowSize,
454 vertical ? arrowSize : rect->bottom-rect->top,
456 GetSystemMetrics(SM_CXVSCROLL),GetSystemMetrics(SM_CYHSCROLL),
459 SelectObject( hdcMem, vertical ?
460 BOTTOM_ARROW( infoPtr->flags, bottom_pressed )
461 : RIGHT_ARROW( infoPtr->flags, bottom_pressed ) );
463 StretchBlt( hdc, rect->left, rect->bottom - arrowSize,
464 rect->right - rect->left, arrowSize,
466 GetSystemMetrics(SM_CXVSCROLL),GetSystemMetrics(SM_CYHSCROLL),
469 StretchBlt( hdc, rect->right - arrowSize, rect->top,
470 arrowSize, rect->bottom - rect->top,
472 GetSystemMetrics(SM_CXVSCROLL), GetSystemMetrics(SM_CYHSCROLL),
474 SelectObject( hdcMem, hbmpPrev );
478 static void SCROLL_DrawArrows( HDC hdc, SCROLLBAR_INFO *infoPtr,
479 RECT *rect, INT arrowSize, BOOL vertical,
480 BOOL top_pressed, BOOL bottom_pressed )
482 if( TWEAK_WineLook == WIN31_LOOK )
483 SCROLL_DrawArrows_31( hdc, infoPtr, rect, arrowSize,
484 vertical, top_pressed,bottom_pressed );
486 SCROLL_DrawArrows_9x( hdc, infoPtr, rect, arrowSize,
487 vertical, top_pressed,bottom_pressed );
491 /***********************************************************************
492 * SCROLL_DrawMovingThumb
494 * Draw the moving thumb rectangle.
496 static void SCROLL_DrawMovingThumb_31( HDC hdc, RECT *rect, BOOL vertical,
497 INT arrowSize, INT thumbSize )
502 r.top += SCROLL_TrackingPos;
503 if (r.top < rect->top + arrowSize - SCROLL_ARROW_THUMB_OVERLAP)
504 r.top = rect->top + arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
505 if (r.top + thumbSize >
506 rect->bottom - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP))
507 r.top = rect->bottom - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP)
509 r.bottom = r.top + thumbSize;
513 r.left += SCROLL_TrackingPos;
514 if (r.left < rect->left + arrowSize - SCROLL_ARROW_THUMB_OVERLAP)
515 r.left = rect->left + arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
516 if (r.left + thumbSize >
517 rect->right - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP))
518 r.left = rect->right - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP)
520 r.right = r.left + thumbSize;
523 DrawFocusRect( hdc, &r );
524 SCROLL_MovingThumb = !SCROLL_MovingThumb;
527 static void SCROLL_DrawMovingThumb_9x( HDC hdc, RECT *rect, BOOL vertical,
528 INT arrowSize, INT thumbSize )
530 INT pos = SCROLL_TrackingPos;
534 max_size = rect->bottom - rect->top;
536 max_size = rect->right - rect->left;
538 max_size -= (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) + thumbSize;
540 if( pos < (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) )
541 pos = (arrowSize-SCROLL_ARROW_THUMB_OVERLAP);
542 else if( pos > max_size )
545 SCROLL_DrawInterior_9x( SCROLL_TrackingWin, hdc, SCROLL_TrackingBar,
546 rect, arrowSize, thumbSize, pos,
547 0, vertical, FALSE, FALSE );
549 SCROLL_MovingThumb = !SCROLL_MovingThumb;
552 static void SCROLL_DrawMovingThumb( HDC hdc, RECT *rect, BOOL vertical,
553 INT arrowSize, INT thumbSize )
555 if( TWEAK_WineLook == WIN31_LOOK )
556 SCROLL_DrawMovingThumb_31( hdc, rect, vertical, arrowSize, thumbSize );
558 SCROLL_DrawMovingThumb_9x( hdc, rect, vertical, arrowSize, thumbSize );
561 /***********************************************************************
562 * SCROLL_DrawInterior
564 * Draw the scroll bar interior (everything except the arrows).
566 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
567 RECT *rect, INT arrowSize,
568 INT thumbSize, INT thumbPos,
569 UINT flags, BOOL vertical,
570 BOOL top_selected, BOOL bottom_selected )
574 HBRUSH hSaveBrush,hBrush;
576 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
577 * The window-owned scrollbars need to call DEFWND_ControlColor
578 * to correctly setup default scrollbar colors
582 hBrush = (HBRUSH)SendMessageA( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
583 (WPARAM)hdc,(LPARAM)hwnd);
587 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
590 hSavePen = SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
591 hSaveBrush = SelectObject( hdc, hBrush );
593 /* Calculate the scroll rectangle */
597 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
598 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
602 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
603 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
606 /* Draw the scroll rectangles and thumb */
607 if (!thumbPos) /* No thumb to draw */
609 PatBlt( hdc, r.left, r.top,
610 r.right - r.left, r.bottom - r.top,
613 /* cleanup and return */
614 SelectObject( hdc, hSavePen );
615 SelectObject( hdc, hSaveBrush );
621 PatBlt( hdc, r.left, r.top,
623 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
624 top_selected ? 0x0f0000 : PATCOPY );
625 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
626 PatBlt( hdc, r.left, r.top + thumbSize,
628 r.bottom - r.top - thumbSize,
629 bottom_selected ? 0x0f0000 : PATCOPY );
630 r.bottom = r.top + thumbSize;
632 else /* horizontal */
634 PatBlt( hdc, r.left, r.top,
635 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
637 top_selected ? 0x0f0000 : PATCOPY );
638 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
639 PatBlt( hdc, r.left + thumbSize, r.top,
640 r.right - r.left - thumbSize,
642 bottom_selected ? 0x0f0000 : PATCOPY );
643 r.right = r.left + thumbSize;
647 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT | BF_MIDDLE );
650 SelectObject( hdc, hSavePen );
651 SelectObject( hdc, hSaveBrush );
655 static void SCROLL_DrawInterior( HWND hwnd, HDC hdc, INT nBar,
656 RECT *rect, INT arrowSize,
657 INT thumbSize, INT thumbPos,
658 UINT flags, BOOL vertical,
659 BOOL top_selected, BOOL bottom_selected )
663 HBRUSH hSaveBrush,hBrush;
664 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
666 if (Save_SCROLL_MovingThumb &&
667 (SCROLL_TrackingWin == hwnd) &&
668 (SCROLL_TrackingBar == nBar))
669 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
671 /* Select the correct brush and pen */
673 if (TWEAK_WineLook == WIN31_LOOK && (flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH)
675 /* This ought to be the color of the parent window */
676 if (TWEAK_WineLook == WIN31_LOOK) {
677 hBrush = GetSysColorBrush(COLOR_WINDOW);
679 /* Under Win9x look & feel, scrollbars don't have a solid border.
680 * To make scrollbar's background different from the window
681 * background, we need to apply a gray 0x55aa pattern brush.
682 * Otherwise it won't look good.
684 hBrush = CACHE_GetPattern55AABrush();
689 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
690 * The window-owned scrollbars need to call DEFWND_ControlColor
691 * to correctly setup default scrollbar colors
693 if (nBar == SB_CTL) {
694 hBrush = (HBRUSH)SendMessageA( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
695 (WPARAM)hdc,(LPARAM)hwnd);
697 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
700 hSavePen = SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
701 hSaveBrush = SelectObject( hdc, hBrush );
703 /* Calculate the scroll rectangle */
708 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
709 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
713 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
714 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
717 /* Draw the scroll bar frame */
719 /* Only draw outline if Win 3.1. Mar 24, 1999 - Ronald B. Cemer */
720 if (TWEAK_WineLook == WIN31_LOOK)
721 Rectangle( hdc, r.left, r.top, r.right, r.bottom );
723 /* Draw the scroll rectangles and thumb */
725 if (!thumbPos) /* No thumb to draw */
727 INT offset = (TWEAK_WineLook > WIN31_LOOK) ? 0 : 1;
729 PatBlt( hdc, r.left+offset, r.top+offset,
730 r.right - r.left - 2*offset, r.bottom - r.top - 2*offset,
733 /* cleanup and return */
734 SelectObject( hdc, hSavePen );
735 SelectObject( hdc, hSaveBrush );
741 INT offset = (TWEAK_WineLook == WIN31_LOOK) ? 1 : 0;
743 PatBlt( hdc, r.left + offset, r.top + offset,
744 r.right - r.left - offset*2,
745 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP) - offset,
746 top_selected ? 0x0f0000 : PATCOPY );
747 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
748 PatBlt( hdc, r.left + offset, r.top + thumbSize,
749 r.right - r.left - offset*2,
750 r.bottom - r.top - thumbSize - offset,
751 bottom_selected ? 0x0f0000 : PATCOPY );
752 r.bottom = r.top + thumbSize;
754 else /* horizontal */
756 INT offset = (TWEAK_WineLook == WIN31_LOOK) ? 1 : 0;
758 PatBlt( hdc, r.left + offset, r.top + offset,
759 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
760 r.bottom - r.top - offset*2,
761 top_selected ? 0x0f0000 : PATCOPY );
762 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
763 PatBlt( hdc, r.left + thumbSize, r.top + offset,
764 r.right - r.left - thumbSize - offset,
765 r.bottom - r.top - offset*2,
766 bottom_selected ? 0x0f0000 : PATCOPY );
767 r.right = r.left + thumbSize;
772 SelectObject( hdc, GetSysColorBrush(COLOR_BTNFACE) );
773 if (TWEAK_WineLook == WIN31_LOOK)
775 Rectangle( hdc, r.left, r.top, r.right, r.bottom );
780 Rectangle( hdc, r.left+1, r.top+1, r.right-1, r.bottom-1 );
782 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT );
784 if (Save_SCROLL_MovingThumb &&
785 (SCROLL_TrackingWin == hwnd) &&
786 (SCROLL_TrackingBar == nBar))
787 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
790 SelectObject( hdc, hSavePen );
791 SelectObject( hdc, hSaveBrush );
795 /***********************************************************************
796 * SCROLL_DrawScrollBar
798 * Redraw the whole scrollbar.
800 void SCROLL_DrawScrollBar( HWND hwnd, HDC hdc, INT nBar,
801 BOOL arrows, BOOL interior )
803 INT arrowSize, thumbSize, thumbPos;
806 WND *wndPtr = WIN_FindWndPtr( hwnd );
807 SCROLLBAR_INFO *infoPtr = SCROLL_GetPtrScrollInfo( wndPtr, nBar );
808 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
810 if (!wndPtr || !infoPtr ||
811 ((nBar == SB_VERT) && !(wndPtr->dwStyle & WS_VSCROLL)) ||
812 ((nBar == SB_HORZ) && !(wndPtr->dwStyle & WS_HSCROLL))) goto END;
813 if (!WIN_IsWindowDrawable( wndPtr, FALSE )) goto END;
815 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
816 &arrowSize, &thumbSize, &thumbPos );
818 /* do not draw if the scrollbar rectangle is empty */
819 if(IsRectEmpty(&rect))
822 if (Save_SCROLL_MovingThumb &&
823 (SCROLL_TrackingWin == hwnd) &&
824 (SCROLL_TrackingBar == nBar))
825 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
827 /* Draw the arrows */
829 if (arrows && arrowSize)
831 if( vertical == SCROLL_trackVertical && GetCapture() == hwnd )
832 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
833 (SCROLL_trackHitTest == SCROLL_TOP_ARROW),
834 (SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW) );
836 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
840 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
841 thumbPos, infoPtr->flags, vertical, FALSE, FALSE );
843 if (Save_SCROLL_MovingThumb &&
844 (SCROLL_TrackingWin == hwnd) &&
845 (SCROLL_TrackingBar == nBar))
846 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
848 /* if scroll bar has focus, reposition the caret*/
849 if(hwnd==GetFocus() && (nBar==SB_CTL))
853 SetCaretPos(thumbPos+1, rect.top+1);
857 SetCaretPos(rect.top+1, thumbPos+1);
862 WIN_ReleaseWndPtr(wndPtr);
866 /***********************************************************************
867 * SCROLL_RefreshScrollBar
869 * Repaint the scroll bar interior after a SetScrollRange() or
870 * SetScrollPos() call.
872 static void SCROLL_RefreshScrollBar( HWND hwnd, INT nBar,
873 BOOL arrows, BOOL interior )
875 HDC hdc = GetDCEx( hwnd, 0,
876 DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW) );
879 SCROLL_DrawScrollBar( hwnd, hdc, nBar, arrows, interior );
880 ReleaseDC( hwnd, hdc );
884 /***********************************************************************
885 * SCROLL_HandleKbdEvent
887 * Handle a keyboard event (only for SB_CTL scrollbars).
889 static void SCROLL_HandleKbdEvent( HWND hwnd, WPARAM wParam )
891 WND *wndPtr = WIN_FindWndPtr( hwnd );
896 case VK_PRIOR: msg = SB_PAGEUP; break;
897 case VK_NEXT: msg = SB_PAGEDOWN; break;
898 case VK_HOME: msg = SB_TOP; break;
899 case VK_END: msg = SB_BOTTOM; break;
900 case VK_UP: msg = SB_LINEUP; break;
901 case VK_DOWN: msg = SB_LINEDOWN; break;
903 WIN_ReleaseWndPtr(wndPtr);
906 SendMessageW( GetParent(hwnd),
907 (wndPtr->dwStyle & SBS_VERT) ? WM_VSCROLL : WM_HSCROLL,
909 WIN_ReleaseWndPtr(wndPtr);
913 /***********************************************************************
914 * SCROLL_HandleScrollEvent
916 * Handle a mouse or timer event for the scrollbar.
917 * 'pt' is the location of the mouse event in client (for SB_CTL) or
918 * windows coordinates.
920 void SCROLL_HandleScrollEvent( HWND hwnd, INT nBar, UINT msg, POINT pt)
922 /* Previous mouse position for timer events */
924 /* Thumb position when tracking started. */
925 static UINT trackThumbPos;
926 /* Position in the scroll-bar of the last button-down event. */
927 static INT lastClickPos;
928 /* Position in the scroll-bar of the last mouse event. */
929 static INT lastMousePos;
931 enum SCROLL_HITTEST hittest;
932 HWND hwndOwner, hwndCtl;
934 INT arrowSize, thumbSize, thumbPos;
938 SCROLLBAR_INFO *infoPtr = SCROLL_GetScrollInfo( hwnd, nBar );
939 if (!infoPtr) return;
940 if ((SCROLL_trackHitTest == SCROLL_NOWHERE) && (msg != WM_LBUTTONDOWN))
943 hdc = GetDCEx( hwnd, 0, DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW));
944 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
945 &arrowSize, &thumbSize, &thumbPos );
946 hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd) : hwnd;
947 hwndCtl = (nBar == SB_CTL) ? hwnd : 0;
951 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
952 HideCaret(hwnd); /* hide caret while holding down LBUTTON*/
953 SCROLL_trackVertical = vertical;
954 SCROLL_trackHitTest = hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
955 lastClickPos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
956 lastMousePos = lastClickPos;
957 trackThumbPos = thumbPos;
960 if (nBar == SB_CTL && (GetWindowLongA(hwnd, GWL_STYLE) & WS_TABSTOP)) SetFocus( hwnd );
964 hittest = SCROLL_HitTest( hwnd, nBar, pt, TRUE );
969 hittest = SCROLL_NOWHERE;
971 /* if scrollbar has focus, show back caret */
972 if (hwnd==GetFocus()) ShowCaret(hwnd);
977 hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
981 return; /* Should never happen */
984 TRACE("Event: hwnd=%04x bar=%d msg=%x pt=%ld,%ld hit=%d\n",
985 hwnd, nBar, msg, pt.x, pt.y, hittest );
987 switch(SCROLL_trackHitTest)
989 case SCROLL_NOWHERE: /* No tracking in progress */
992 case SCROLL_TOP_ARROW:
993 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
994 (hittest == SCROLL_trackHitTest), FALSE );
995 if (hittest == SCROLL_trackHitTest)
997 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
999 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1000 SB_LINEUP, hwndCtl );
1003 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1004 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1007 else KillSystemTimer( hwnd, SCROLL_TIMER );
1010 case SCROLL_TOP_RECT:
1011 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
1012 thumbPos, infoPtr->flags, vertical,
1013 (hittest == SCROLL_trackHitTest), FALSE );
1014 if (hittest == SCROLL_trackHitTest)
1016 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1018 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1019 SB_PAGEUP, hwndCtl );
1020 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1021 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1025 else KillSystemTimer( hwnd, SCROLL_TIMER );
1029 if (msg == WM_LBUTTONDOWN)
1031 SCROLL_TrackingWin = hwnd;
1032 SCROLL_TrackingBar = nBar;
1033 SCROLL_TrackingPos = trackThumbPos + lastMousePos - lastClickPos;
1034 if (!SCROLL_MovingThumb)
1035 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
1037 else if (msg == WM_LBUTTONUP)
1039 if (SCROLL_MovingThumb)
1040 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
1041 SCROLL_TrackingWin = 0;
1042 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
1043 thumbPos, infoPtr->flags, vertical,
1046 else /* WM_MOUSEMOVE */
1050 if (!SCROLL_PtInRectEx( &rect, pt, vertical )) pos = lastClickPos;
1053 pt = SCROLL_ClipPos( &rect, pt );
1054 pos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
1056 if ( (pos != lastMousePos) || (!SCROLL_MovingThumb) )
1058 if (SCROLL_MovingThumb)
1059 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
1060 arrowSize, thumbSize );
1062 SCROLL_TrackingPos = trackThumbPos + pos - lastClickPos;
1063 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
1065 SCROLL_TrackingPos );
1066 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1067 MAKEWPARAM( SB_THUMBTRACK, SCROLL_TrackingVal),
1069 if (!SCROLL_MovingThumb)
1070 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
1071 arrowSize, thumbSize );
1076 case SCROLL_BOTTOM_RECT:
1077 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
1078 thumbPos, infoPtr->flags, vertical,
1079 FALSE, (hittest == SCROLL_trackHitTest) );
1080 if (hittest == SCROLL_trackHitTest)
1082 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1084 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1085 SB_PAGEDOWN, hwndCtl );
1086 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1087 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1091 else KillSystemTimer( hwnd, SCROLL_TIMER );
1094 case SCROLL_BOTTOM_ARROW:
1095 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
1096 FALSE, (hittest == SCROLL_trackHitTest) );
1097 if (hittest == SCROLL_trackHitTest)
1099 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1101 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1102 SB_LINEDOWN, hwndCtl );
1105 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1106 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1109 else KillSystemTimer( hwnd, SCROLL_TIMER );
1113 if (msg == WM_LBUTTONUP)
1115 hittest = SCROLL_trackHitTest;
1116 SCROLL_trackHitTest = SCROLL_NOWHERE; /* Terminate tracking */
1118 if (hittest == SCROLL_THUMB)
1120 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1121 trackThumbPos + lastMousePos - lastClickPos );
1122 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1123 MAKEWPARAM( SB_THUMBPOSITION, val ), hwndCtl );
1126 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1127 SB_ENDSCROLL, hwndCtl );
1130 ReleaseDC( hwnd, hdc );
1134 /***********************************************************************
1137 static LRESULT WINAPI ScrollBarWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1143 CREATESTRUCTW *lpCreat = (CREATESTRUCTW *)lParam;
1144 if (lpCreat->style & SBS_SIZEBOX)
1146 FIXME("Unimplemented style SBS_SIZEBOX.\n" );
1149 if (lpCreat->style & SBS_VERT)
1151 if (lpCreat->style & SBS_LEFTALIGN)
1152 MoveWindow( hwnd, lpCreat->x, lpCreat->y,
1153 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreat->cy, FALSE );
1154 else if (lpCreat->style & SBS_RIGHTALIGN)
1156 lpCreat->x+lpCreat->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1158 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreat->cy, FALSE );
1162 if (lpCreat->style & SBS_TOPALIGN)
1163 MoveWindow( hwnd, lpCreat->x, lpCreat->y,
1164 lpCreat->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1165 else if (lpCreat->style & SBS_BOTTOMALIGN)
1168 lpCreat->y+lpCreat->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1169 lpCreat->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1172 if (!hUpArrow) SCROLL_LoadBitmaps();
1173 TRACE("ScrollBar creation, hwnd=%04x\n", hwnd );
1176 case WM_LBUTTONDOWN:
1182 pt.x = SLOWORD(lParam);
1183 pt.y = SHIWORD(lParam);
1184 SCROLL_HandleScrollEvent( hwnd, SB_CTL, message, pt );
1188 /* if key event is received, the scrollbar has the focus*/
1190 /* hide caret on first KEYDOWN to prevent flicker */
1191 if ((lParam & 0x40000000)==0)
1193 SCROLL_HandleKbdEvent( hwnd, wParam );
1202 /* Create a caret when a ScrollBar get focus*/
1204 int arrowSize, thumbSize, thumbPos, vertical;
1205 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,
1206 &arrowSize, &thumbSize, &thumbPos );
1209 CreateCaret(hwnd,1, thumbSize-2, rect.bottom-rect.top-2);
1210 SetCaretPos(thumbPos+1, rect.top+1);
1214 CreateCaret(hwnd,1, rect.right-rect.left-2,thumbSize-2);
1215 SetCaretPos(rect.top+1, thumbPos+1);
1224 int arrowSize, thumbSize, thumbPos, vertical;
1225 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,&arrowSize, &thumbSize, &thumbPos );
1227 rect.left=thumbPos+1;
1228 rect.right=rect.left+thumbSize;
1232 rect.top=thumbPos+1;
1233 rect.bottom=rect.top+thumbSize;
1236 InvalidateRect(hwnd,&rect,0);
1245 return DLGC_WANTARROWS; /* Windows returns this value */
1250 HDC hdc = BeginPaint( hwnd, &ps );
1251 SCROLL_DrawScrollBar( hwnd, hdc, SB_CTL, TRUE, TRUE );
1252 EndPaint( hwnd, &ps );
1258 return SetScrollPos( hwnd, SB_CTL, wParam, (BOOL)lParam );
1262 return GetScrollPos( hwnd, SB_CTL );
1264 case SBM_SETRANGE16:
1265 SetScrollRange( hwnd, SB_CTL, LOWORD(lParam), HIWORD(lParam),
1266 wParam /* FIXME: Is this correct? */ );
1270 SetScrollRange( hwnd, SB_CTL, wParam, lParam, FALSE );
1271 return 0; /* FIXME: return previous position */
1273 case SBM_GETRANGE16:
1274 FIXME("don't know how to handle SBM_GETRANGE16 (wp=%04x,lp=%08lx)\n", wParam, lParam );
1278 GetScrollRange( hwnd, SB_CTL, (LPINT)wParam, (LPINT)lParam );
1281 case SBM_ENABLE_ARROWS16:
1282 case SBM_ENABLE_ARROWS:
1283 return EnableScrollBar( hwnd, SB_CTL, wParam );
1285 case SBM_SETRANGEREDRAW:
1286 SetScrollRange( hwnd, SB_CTL, wParam, lParam, TRUE );
1287 return 0; /* FIXME: return previous position */
1289 case SBM_SETSCROLLINFO:
1290 return SetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam, wParam );
1292 case SBM_GETSCROLLINFO:
1293 return GetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam );
1303 ERR("unknown Win32 msg %04x wp=%08x lp=%08lx\n",
1304 message, wParam, lParam );
1308 if (message >= WM_USER)
1309 WARN("unknown msg %04x wp=%04x lp=%08lx\n",
1310 message, wParam, lParam );
1311 return DefWindowProcW( hwnd, message, wParam, lParam );
1317 /*************************************************************************
1318 * SetScrollInfo16 (USER.475)
1320 INT16 WINAPI SetScrollInfo16( HWND16 hwnd, INT16 nBar, const SCROLLINFO *info,
1323 return (INT16)SetScrollInfo( hwnd, nBar, info, bRedraw );
1327 /*************************************************************************
1328 * SetScrollInfo (USER32.501)
1329 * SetScrollInfo can be used to set the position, upper bound,
1330 * lower bound, and page size of a scrollbar control.
1333 * Scrollbar position
1336 * For 100 lines of text to be displayed in a window of 25 lines,
1337 * one would for instance use info->nMin=0, info->nMax=75
1338 * (corresponding to the 76 different positions of the window on
1339 * the text), and info->nPage=25.
1341 INT WINAPI SetScrollInfo(
1342 HWND hwnd /* [in] Handle of window whose scrollbar will be affected */,
1343 INT nBar /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1344 const SCROLLINFO *info /* [in] Specifies what to change and new values */,
1345 BOOL bRedraw /* [in] Should scrollbar be redrawn afterwards ? */)
1348 INT retVal = SCROLL_SetScrollInfo( hwnd, nBar, info, &action );
1350 if( action & SA_SSI_HIDE )
1351 SCROLL_ShowScrollBar( hwnd, nBar, FALSE, FALSE );
1354 if( action & SA_SSI_SHOW )
1355 if( SCROLL_ShowScrollBar( hwnd, nBar, TRUE, TRUE ) )
1356 return retVal; /* SetWindowPos() already did the painting */
1358 if( bRedraw && (action & SA_SSI_REFRESH))
1359 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
1360 else if( action & SA_SSI_REPAINT_ARROWS )
1361 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, FALSE );
1366 INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar,
1367 const SCROLLINFO *info, INT *action )
1369 /* Update the scrollbar state and set action flags according to
1370 * what has to be done graphics wise. */
1372 SCROLLBAR_INFO *infoPtr;
1374 BOOL bChangeParams = FALSE; /* don't show/hide scrollbar if params don't change */
1378 if (!(infoPtr = SCROLL_GetScrollInfo(hwnd, nBar))) return 0;
1379 if (info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)) return 0;
1380 if ((info->cbSize != sizeof(*info)) &&
1381 (info->cbSize != sizeof(*info)-sizeof(info->nTrackPos))) return 0;
1383 if (TRACE_ON(scroll))
1385 DPRINTF( "hwnd=%04x bar=%d", hwnd, nBar);
1386 if (info->fMask & SIF_PAGE) DPRINTF( " page=%d", info->nPage );
1387 if (info->fMask & SIF_POS) DPRINTF( " pos=%d", info->nPos );
1388 if (info->fMask & SIF_RANGE) DPRINTF( " min=%d max=%d", info->nMin, info->nMax );
1392 /* Set the page size */
1394 if (info->fMask & SIF_PAGE)
1396 if( infoPtr->Page != info->nPage )
1398 infoPtr->Page = info->nPage;
1399 *action |= SA_SSI_REFRESH;
1400 bChangeParams = TRUE;
1404 /* Set the scroll pos */
1406 if (info->fMask & SIF_POS)
1408 if( infoPtr->CurVal != info->nPos )
1410 infoPtr->CurVal = info->nPos;
1411 *action |= SA_SSI_REFRESH;
1415 /* Set the scroll range */
1417 if (info->fMask & SIF_RANGE)
1419 /* Invalid range -> range is set to (0,0) */
1420 if ((info->nMin > info->nMax) ||
1421 ((UINT)(info->nMax - info->nMin) >= 0x80000000))
1423 infoPtr->MinVal = 0;
1424 infoPtr->MaxVal = 0;
1425 bChangeParams = TRUE;
1429 if( infoPtr->MinVal != info->nMin ||
1430 infoPtr->MaxVal != info->nMax )
1432 *action |= SA_SSI_REFRESH;
1433 infoPtr->MinVal = info->nMin;
1434 infoPtr->MaxVal = info->nMax;
1435 bChangeParams = TRUE;
1440 /* Make sure the page size is valid */
1442 if (infoPtr->Page < 0) infoPtr->Page = 0;
1443 else if (infoPtr->Page > infoPtr->MaxVal - infoPtr->MinVal + 1 )
1444 infoPtr->Page = infoPtr->MaxVal - infoPtr->MinVal + 1;
1446 /* Make sure the pos is inside the range */
1448 if (infoPtr->CurVal < infoPtr->MinVal)
1449 infoPtr->CurVal = infoPtr->MinVal;
1450 else if (infoPtr->CurVal > infoPtr->MaxVal - max( infoPtr->Page-1, 0 ))
1451 infoPtr->CurVal = infoPtr->MaxVal - max( infoPtr->Page-1, 0 );
1453 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1454 infoPtr->Page, infoPtr->CurVal,
1455 infoPtr->MinVal, infoPtr->MaxVal );
1457 /* don't change the scrollbar state if SetScrollInfo
1458 * is just called with SIF_DISABLENOSCROLL
1460 if(!(info->fMask & SIF_ALL)) goto done;
1462 /* Check if the scrollbar should be hidden or disabled */
1464 if (info->fMask & (SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL))
1466 new_flags = infoPtr->flags;
1467 if (infoPtr->MinVal >= infoPtr->MaxVal - max( infoPtr->Page-1, 0 ))
1469 /* Hide or disable scroll-bar */
1470 if (info->fMask & SIF_DISABLENOSCROLL)
1472 new_flags = ESB_DISABLE_BOTH;
1473 *action |= SA_SSI_REFRESH;
1475 else if ((nBar != SB_CTL) && bChangeParams)
1477 *action = SA_SSI_HIDE;
1481 else /* Show and enable scroll-bar */
1484 if ((nBar != SB_CTL) && bChangeParams)
1485 *action |= SA_SSI_SHOW;
1488 if (infoPtr->flags != new_flags) /* check arrow flags */
1490 infoPtr->flags = new_flags;
1491 *action |= SA_SSI_REPAINT_ARROWS;
1496 /* Return current position */
1498 return infoPtr->CurVal;
1502 /*************************************************************************
1503 * GetScrollInfo16 (USER.476)
1505 BOOL16 WINAPI GetScrollInfo16( HWND16 hwnd, INT16 nBar, LPSCROLLINFO info )
1507 return GetScrollInfo( hwnd, nBar, info );
1511 /*************************************************************************
1512 * GetScrollInfo (USER32.284)
1513 * GetScrollInfo can be used to retrieve the position, upper bound,
1514 * lower bound, and page size of a scrollbar control.
1518 BOOL WINAPI GetScrollInfo(
1519 HWND hwnd /* [in] Handle of window */ ,
1520 INT nBar /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1521 LPSCROLLINFO info /* [in/out] (info.fMask [in] specifies which values are to retrieve) */)
1523 SCROLLBAR_INFO *infoPtr;
1525 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return FALSE;
1526 if (info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)) return FALSE;
1527 if ((info->cbSize != sizeof(*info)) &&
1528 (info->cbSize != sizeof(*info)-sizeof(info->nTrackPos))) return FALSE;
1530 if (info->fMask & SIF_PAGE) info->nPage = infoPtr->Page;
1531 if (info->fMask & SIF_POS) info->nPos = infoPtr->CurVal;
1532 if ((info->fMask & SIF_TRACKPOS) && (info->cbSize == sizeof(*info)))
1533 info->nTrackPos = (SCROLL_TrackingWin==hwnd) ? SCROLL_TrackingVal : infoPtr->CurVal;
1534 if (info->fMask & SIF_RANGE)
1536 info->nMin = infoPtr->MinVal;
1537 info->nMax = infoPtr->MaxVal;
1539 return (info->fMask & SIF_ALL) != 0;
1543 /*************************************************************************
1544 * SetScrollPos16 (USER.62)
1546 INT16 WINAPI SetScrollPos16( HWND16 hwnd, INT16 nBar, INT16 nPos,
1549 return (INT16)SetScrollPos( hwnd, nBar, nPos, bRedraw );
1553 /*************************************************************************
1554 * SetScrollPos (USER32.502)
1557 * Success: Scrollbar position
1561 * Note the ambiguity when 0 is returned. Use GetLastError
1562 * to make sure there was an error (and to know which one).
1564 INT WINAPI SetScrollPos(
1565 HWND hwnd /* [in] Handle of window whose scrollbar will be affected */,
1566 INT nBar /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1567 INT nPos /* [in] New value */,
1568 BOOL bRedraw /* [in] Should scrollbar be redrawn afterwards ? */ )
1571 SCROLLBAR_INFO *infoPtr;
1574 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return 0;
1575 oldPos = infoPtr->CurVal;
1576 info.cbSize = sizeof(info);
1578 info.fMask = SIF_POS;
1579 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1584 /*************************************************************************
1585 * GetScrollPos16 (USER.63)
1587 INT16 WINAPI GetScrollPos16( HWND16 hwnd, INT16 nBar )
1589 return (INT16)GetScrollPos( hwnd, nBar );
1593 /*************************************************************************
1594 * GetScrollPos (USER32.285)
1597 * Success: Current position
1601 * Note the ambiguity when 0 is returned. Use GetLastError
1602 * to make sure there was an error (and to know which one).
1604 INT WINAPI GetScrollPos(
1605 HWND hwnd, /* [in] Handle of window */
1606 INT nBar /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */)
1608 SCROLLBAR_INFO *infoPtr;
1610 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return 0;
1611 return infoPtr->CurVal;
1615 /*************************************************************************
1616 * SetScrollRange16 (USER.64)
1618 void WINAPI SetScrollRange16( HWND16 hwnd, INT16 nBar,
1619 INT16 MinVal, INT16 MaxVal, BOOL16 bRedraw )
1621 /* Invalid range -> range is set to (0,0) */
1622 if ((INT)MaxVal - (INT)MinVal > 0x7fff) MinVal = MaxVal = 0;
1623 SetScrollRange( hwnd, nBar, MinVal, MaxVal, bRedraw );
1627 /*************************************************************************
1628 * SetScrollRange (USER32.503)
1632 BOOL WINAPI SetScrollRange(
1633 HWND hwnd, /* [in] Handle of window whose scrollbar will be affected */
1634 INT nBar, /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */
1635 INT MinVal, /* [in] New minimum value */
1636 INT MaxVal, /* [in] New maximum value */
1637 BOOL bRedraw /* [in] Should scrollbar be redrawn afterwards ? */)
1641 info.cbSize = sizeof(info);
1644 info.fMask = SIF_RANGE;
1645 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1650 /*************************************************************************
1651 * SCROLL_SetNCSbState
1653 * Updates both scrollbars at the same time. Used by MDI CalcChildScroll().
1655 INT SCROLL_SetNCSbState(WND* wndPtr, int vMin, int vMax, int vPos,
1656 int hMin, int hMax, int hPos)
1659 SCROLLINFO vInfo, hInfo;
1661 vInfo.cbSize = hInfo.cbSize = sizeof(SCROLLINFO);
1662 vInfo.nMin = vMin; hInfo.nMin = hMin;
1663 vInfo.nMax = vMax; hInfo.nMax = hMax;
1664 vInfo.nPos = vPos; hInfo.nPos = hPos;
1665 vInfo.fMask = hInfo.fMask = SIF_RANGE | SIF_POS;
1667 SCROLL_SetScrollInfo( wndPtr->hwndSelf, SB_VERT, &vInfo, &vA );
1668 SCROLL_SetScrollInfo( wndPtr->hwndSelf, SB_HORZ, &hInfo, &hA );
1670 if( !SCROLL_ShowScrollBar( wndPtr->hwndSelf, SB_BOTH,
1671 (hA & SA_SSI_SHOW),(vA & SA_SSI_SHOW) ) )
1673 /* SetWindowPos() wasn't called, just redraw the scrollbars if needed */
1674 if( vA & SA_SSI_REFRESH )
1675 SCROLL_RefreshScrollBar( wndPtr->hwndSelf, SB_VERT, FALSE, TRUE );
1677 if( hA & SA_SSI_REFRESH )
1678 SCROLL_RefreshScrollBar( wndPtr->hwndSelf, SB_HORZ, FALSE, TRUE );
1684 /*************************************************************************
1685 * GetScrollRange16 (USER.65)
1687 BOOL16 WINAPI GetScrollRange16( HWND16 hwnd, INT16 nBar,
1688 LPINT16 lpMin, LPINT16 lpMax)
1691 BOOL16 ret = GetScrollRange( hwnd, nBar, &min, &max );
1692 if (lpMin) *lpMin = min;
1693 if (lpMax) *lpMax = max;
1698 /*************************************************************************
1699 * GetScrollRange (USER32.286)
1703 BOOL WINAPI GetScrollRange(
1704 HWND hwnd, /* [in] Handle of window */
1705 INT nBar, /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */
1706 LPINT lpMin, /* [out] Where to store minimum value */
1707 LPINT lpMax /* [out] Where to store maximum value */)
1709 SCROLLBAR_INFO *infoPtr;
1711 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar )))
1713 if (lpMin) lpMin = 0;
1714 if (lpMax) lpMax = 0;
1717 if (lpMin) *lpMin = infoPtr->MinVal;
1718 if (lpMax) *lpMax = infoPtr->MaxVal;
1723 /*************************************************************************
1724 * SCROLL_ShowScrollBar()
1726 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1728 BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar,
1729 BOOL fShowH, BOOL fShowV )
1731 WND *wndPtr = WIN_FindWndPtr( hwnd );
1732 BOOL retvalue = FALSE;
1734 if (!wndPtr) return FALSE;
1735 TRACE("hwnd=%04x bar=%d horz=%d, vert=%d\n",
1736 hwnd, nBar, fShowH, fShowV );
1741 ShowWindow( hwnd, fShowH ? SW_SHOW : SW_HIDE );
1749 fShowH = !(wndPtr->dwStyle & WS_HSCROLL);
1750 wndPtr->dwStyle |= WS_HSCROLL;
1754 fShowH = (wndPtr->dwStyle & WS_HSCROLL);
1755 wndPtr->dwStyle &= ~WS_HSCROLL;
1757 if( nBar == SB_HORZ ) {
1766 fShowV = !(wndPtr->dwStyle & WS_VSCROLL);
1767 wndPtr->dwStyle |= WS_VSCROLL;
1771 fShowV = (wndPtr->dwStyle & WS_VSCROLL);
1772 wndPtr->dwStyle &= ~WS_VSCROLL;
1774 if ( nBar == SB_VERT )
1779 retvalue = FALSE; /* Nothing to do! */
1783 if( fShowH || fShowV ) /* frame has been changed, let the window redraw itself */
1785 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
1786 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
1791 retvalue = FALSE; /* no frame changes */
1793 WIN_ReleaseWndPtr(wndPtr);
1798 /*************************************************************************
1799 * ShowScrollBar16 (USER.267)
1801 void WINAPI ShowScrollBar16( HWND16 hwnd, INT16 nBar, BOOL16 fShow )
1803 SCROLL_ShowScrollBar( hwnd, nBar, (nBar == SB_VERT) ? 0 : fShow,
1804 (nBar == SB_HORZ) ? 0 : fShow );
1808 /*************************************************************************
1809 * ShowScrollBar (USER32.532)
1813 BOOL WINAPI ShowScrollBar(
1814 HWND hwnd, /* [in] Handle of window whose scrollbar(s) will be affected */
1815 INT nBar, /* [in] One of SB_HORZ, SB_VERT, SB_BOTH or SB_CTL */
1816 BOOL fShow /* [in] TRUE = show, FALSE = hide */)
1818 SCROLL_ShowScrollBar( hwnd, nBar, (nBar == SB_VERT) ? 0 : fShow,
1819 (nBar == SB_HORZ) ? 0 : fShow );
1824 /*************************************************************************
1825 * EnableScrollBar16 (USER.482)
1827 BOOL16 WINAPI EnableScrollBar16( HWND16 hwnd, INT16 nBar, UINT16 flags )
1829 return EnableScrollBar( hwnd, nBar, flags );
1833 /*************************************************************************
1834 * EnableScrollBar (USER32.171)
1836 BOOL WINAPI EnableScrollBar( HWND hwnd, INT nBar, UINT flags )
1839 SCROLLBAR_INFO *infoPtr;
1841 TRACE("%04x %d %d\n", hwnd, nBar, flags );
1843 flags &= ESB_DISABLE_BOTH;
1845 if (nBar == SB_BOTH)
1847 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, SB_VERT ))) return FALSE;
1848 if (!(bFineWithMe = (infoPtr->flags == flags)) )
1850 infoPtr->flags = flags;
1851 SCROLL_RefreshScrollBar( hwnd, SB_VERT, TRUE, TRUE );
1858 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return FALSE;
1859 if (bFineWithMe && infoPtr->flags == flags) return FALSE;
1860 infoPtr->flags = flags;
1862 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );