d3d11: Report D3D11_FORMAT_SUPPORT_TYPED_UNORDERED_ACCESS_VIEW in CheckFormatSupport().
[wine.git] / dlls / user32 / scroll.c
bloba63039262c78a2aeb9747550f3f171c7e52944ba
1 /*
2 * Scrollbar control
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "controls.h"
28 #include "win.h"
29 #include "wine/debug.h"
30 #include "user_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(scroll);
34 /* data for a single scroll bar */
35 typedef struct
37 INT curVal; /* Current scroll-bar value */
38 INT minVal; /* Minimum scroll-bar value */
39 INT maxVal; /* Maximum scroll-bar value */
40 INT page; /* Page size of scroll bar (Win32) */
41 UINT flags; /* EnableScrollBar flags */
42 } SCROLLBAR_INFO, *LPSCROLLBAR_INFO;
44 /* data for window that has (one or two) scroll bars */
45 typedef struct
47 SCROLLBAR_INFO horz;
48 SCROLLBAR_INFO vert;
49 } WINSCROLLBAR_INFO, *LPWINSCROLLBAR_INFO;
51 typedef struct
53 DWORD magic;
54 SCROLLBAR_INFO info;
55 } SCROLLBAR_WNDDATA;
57 #define SCROLLBAR_MAGIC 0x5c6011ba
59 /* Minimum size of the rectangle between the arrows */
60 #define SCROLL_MIN_RECT 4
62 /* Minimum size of the thumb in pixels */
63 #define SCROLL_MIN_THUMB 6
65 /* Overlap between arrows and thumb */
66 #define SCROLL_ARROW_THUMB_OVERLAP 0
68 /* Delay (in ms) before first repetition when holding the button down */
69 #define SCROLL_FIRST_DELAY 200
71 /* Delay (in ms) between scroll repetitions */
72 #define SCROLL_REPEAT_DELAY 50
74 /* Scroll timer id */
75 #define SCROLL_TIMER 0
77 /* Scroll-bar hit testing */
78 enum SCROLL_HITTEST
80 SCROLL_NOWHERE, /* Outside the scroll bar */
81 SCROLL_TOP_ARROW, /* Top or left arrow */
82 SCROLL_TOP_RECT, /* Rectangle between the top arrow and the thumb */
83 SCROLL_THUMB, /* Thumb rectangle */
84 SCROLL_BOTTOM_RECT, /* Rectangle between the thumb and the bottom arrow */
85 SCROLL_BOTTOM_ARROW /* Bottom or right arrow */
88 /* What to do after SCROLL_SetScrollInfo() */
89 #define SA_SSI_HIDE 0x0001
90 #define SA_SSI_SHOW 0x0002
91 #define SA_SSI_REFRESH 0x0004
92 #define SA_SSI_REPAINT_ARROWS 0x0008
94 /* Thumb-tracking info */
95 static HWND SCROLL_TrackingWin = 0;
96 static INT SCROLL_TrackingBar = 0;
97 static INT SCROLL_TrackingPos = 0;
98 static INT SCROLL_TrackingVal = 0;
99 /* Hit test code of the last button-down event */
100 static enum SCROLL_HITTEST SCROLL_trackHitTest;
101 static BOOL SCROLL_trackVertical;
103 /* Is the moving thumb being displayed? */
104 static BOOL SCROLL_MovingThumb = FALSE;
106 /* Local functions */
107 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar,
108 BOOL fShowH, BOOL fShowV );
109 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar,
110 const SCROLLINFO *info, BOOL bRedraw );
111 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
112 RECT *rect, INT arrowSize,
113 INT thumbSize, INT thumbPos,
114 UINT flags, BOOL vertical,
115 BOOL top_selected, BOOL bottom_selected );
118 /*********************************************************************
119 * scrollbar class descriptor
121 const struct builtin_class_descr SCROLL_builtin_class =
123 L"ScrollBar", /* name */
124 CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC, /* style */
125 WINPROC_SCROLLBAR, /* proc */
126 sizeof(SCROLLBAR_WNDDATA), /* extra */
127 IDC_ARROW, /* cursor */
128 0 /* brush */
131 /***********************************************************************
132 * SCROLL_ScrollInfoValid
134 * Determine if the supplied SCROLLINFO struct is valid.
135 * info [in] The SCROLLINFO struct to be tested
137 static inline BOOL SCROLL_ScrollInfoValid( LPCSCROLLINFO info )
139 return !(info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)
140 || (info->cbSize != sizeof(*info)
141 && info->cbSize != sizeof(*info) - sizeof(info->nTrackPos)));
145 /***********************************************************************
146 * SCROLL_GetInternalInfo
148 * Returns pointer to internal SCROLLBAR_INFO structure for nBar
149 * or NULL if failed (f.i. scroll bar does not exist yet)
150 * If alloc is TRUE and the struct does not exist yet, create it.
152 static SCROLLBAR_INFO *SCROLL_GetInternalInfo( HWND hwnd, INT nBar, BOOL alloc )
154 SCROLLBAR_INFO *infoPtr = NULL;
155 WND *wndPtr = WIN_GetPtr( hwnd );
157 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return NULL;
158 switch(nBar)
160 case SB_HORZ:
161 if (wndPtr->pScroll) infoPtr = &((LPWINSCROLLBAR_INFO)wndPtr->pScroll)->horz;
162 break;
163 case SB_VERT:
164 if (wndPtr->pScroll) infoPtr = &((LPWINSCROLLBAR_INFO)wndPtr->pScroll)->vert;
165 break;
166 case SB_CTL:
167 if (wndPtr->cbWndExtra >= sizeof(SCROLLBAR_WNDDATA))
169 SCROLLBAR_WNDDATA *data = (SCROLLBAR_WNDDATA*)wndPtr->wExtra;
170 if (data->magic == SCROLLBAR_MAGIC)
171 infoPtr = &data->info;
173 if (!infoPtr) WARN("window is not a scrollbar control\n");
174 break;
175 case SB_BOTH:
176 WARN("with SB_BOTH\n");
177 break;
180 if (!infoPtr && alloc)
182 WINSCROLLBAR_INFO *winInfoPtr;
184 if (nBar != SB_HORZ && nBar != SB_VERT)
185 WARN("Cannot initialize nBar=%d\n",nBar);
186 else if ((winInfoPtr = HeapAlloc( GetProcessHeap(), 0, sizeof(WINSCROLLBAR_INFO) )))
188 /* Set default values */
189 winInfoPtr->horz.minVal = 0;
190 winInfoPtr->horz.curVal = 0;
191 winInfoPtr->horz.page = 0;
192 /* From MSDN and our own tests:
193 * max for a standard scroll bar is 100 by default. */
194 winInfoPtr->horz.maxVal = 100;
195 winInfoPtr->horz.flags = ESB_ENABLE_BOTH;
196 winInfoPtr->vert = winInfoPtr->horz;
197 wndPtr->pScroll = winInfoPtr;
198 infoPtr = nBar == SB_HORZ ? &winInfoPtr->horz : &winInfoPtr->vert;
201 WIN_ReleasePtr( wndPtr );
202 return infoPtr;
206 /***********************************************************************
207 * SCROLL_GetScrollBarRect
209 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
210 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
211 * 'arrowSize' returns the width or height of an arrow (depending on
212 * the orientation of the scrollbar), 'thumbSize' returns the size of
213 * the thumb, and 'thumbPos' returns the position of the thumb
214 * relative to the left or to the top.
215 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
217 static BOOL SCROLL_GetScrollBarRect( HWND hwnd, INT nBar, RECT *lprect,
218 INT *arrowSize, INT *thumbSize,
219 INT *thumbPos )
221 INT pixels;
222 BOOL vertical;
223 WND *wndPtr = WIN_GetPtr( hwnd );
225 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
227 switch(nBar)
229 case SB_HORZ:
230 WIN_GetRectangles( hwnd, COORDS_WINDOW, NULL, lprect );
231 lprect->top = lprect->bottom;
232 lprect->bottom += GetSystemMetrics(SM_CYHSCROLL);
233 if(wndPtr->dwStyle & WS_VSCROLL)
234 lprect->right++;
235 vertical = FALSE;
236 break;
238 case SB_VERT:
239 WIN_GetRectangles( hwnd, COORDS_WINDOW, NULL, lprect );
240 if((wndPtr->dwExStyle & WS_EX_LEFTSCROLLBAR) != 0)
242 lprect->right = lprect->left;
243 lprect->left -= GetSystemMetrics(SM_CXVSCROLL);
245 else
247 lprect->left = lprect->right;
248 lprect->right += GetSystemMetrics(SM_CXVSCROLL);
250 if(wndPtr->dwStyle & WS_HSCROLL)
251 lprect->bottom++;
252 vertical = TRUE;
253 break;
255 case SB_CTL:
256 GetClientRect( hwnd, lprect );
257 vertical = ((wndPtr->dwStyle & SBS_VERT) != 0);
258 break;
260 default:
261 WIN_ReleasePtr( wndPtr );
262 return FALSE;
265 if (vertical) pixels = lprect->bottom - lprect->top;
266 else pixels = lprect->right - lprect->left;
268 if (pixels <= 2*GetSystemMetrics(SM_CXVSCROLL) + SCROLL_MIN_RECT)
270 if (pixels > SCROLL_MIN_RECT)
271 *arrowSize = (pixels - SCROLL_MIN_RECT) / 2;
272 else
273 *arrowSize = 0;
274 *thumbPos = *thumbSize = 0;
276 else
278 SCROLLBAR_INFO *info = SCROLL_GetInternalInfo( hwnd, nBar, FALSE );
279 if (!info)
281 WARN("called for missing scroll bar\n");
282 WIN_ReleasePtr( wndPtr );
283 return FALSE;
285 *arrowSize = GetSystemMetrics(SM_CXVSCROLL);
286 pixels -= (2 * (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP));
288 if (info->page)
290 *thumbSize = MulDiv(pixels,info->page,(info->maxVal-info->minVal+1));
291 if (*thumbSize < SCROLL_MIN_THUMB) *thumbSize = SCROLL_MIN_THUMB;
293 else *thumbSize = GetSystemMetrics(SM_CXVSCROLL);
295 if (((pixels -= *thumbSize ) < 0) ||
296 ((info->flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH))
298 /* Rectangle too small or scrollbar disabled -> no thumb */
299 *thumbPos = *thumbSize = 0;
301 else
303 INT max = info->maxVal - max( info->page-1, 0 );
304 if (info->minVal >= max)
305 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
306 else
307 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP
308 + MulDiv(pixels, (info->curVal-info->minVal),(max - info->minVal));
311 WIN_ReleasePtr( wndPtr );
312 return vertical;
316 /***********************************************************************
317 * SCROLL_GetThumbVal
319 * Compute the current scroll position based on the thumb position in pixels
320 * from the top of the scroll-bar.
322 static UINT SCROLL_GetThumbVal( SCROLLBAR_INFO *infoPtr, RECT *rect,
323 BOOL vertical, INT pos )
325 INT thumbSize;
326 INT pixels = vertical ? rect->bottom-rect->top : rect->right-rect->left;
327 INT range;
329 if ((pixels -= 2*(GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP)) <= 0)
330 return infoPtr->minVal;
332 if (infoPtr->page)
334 thumbSize = MulDiv(pixels,infoPtr->page,(infoPtr->maxVal-infoPtr->minVal+1));
335 if (thumbSize < SCROLL_MIN_THUMB) thumbSize = SCROLL_MIN_THUMB;
337 else thumbSize = GetSystemMetrics(SM_CXVSCROLL);
339 if ((pixels -= thumbSize) <= 0) return infoPtr->minVal;
341 pos = max( 0, pos - (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP) );
342 if (pos > pixels) pos = pixels;
344 if (!infoPtr->page)
345 range = infoPtr->maxVal - infoPtr->minVal;
346 else
347 range = infoPtr->maxVal - infoPtr->minVal - infoPtr->page + 1;
349 return infoPtr->minVal + MulDiv(pos, range, pixels);
352 /***********************************************************************
353 * SCROLL_PtInRectEx
355 static BOOL SCROLL_PtInRectEx( LPRECT lpRect, POINT pt, BOOL vertical )
357 RECT rect = *lpRect;
358 int scrollbarWidth;
360 /* Pad hit rect to allow mouse to be dragged outside of scrollbar and
361 * still be considered in the scrollbar. */
362 if (vertical)
364 scrollbarWidth = lpRect->right - lpRect->left;
365 InflateRect(&rect, scrollbarWidth * 8, scrollbarWidth * 2);
367 else
369 scrollbarWidth = lpRect->bottom - lpRect->top;
370 InflateRect(&rect, scrollbarWidth * 2, scrollbarWidth * 8);
372 return PtInRect( &rect, pt );
375 /***********************************************************************
376 * SCROLL_ClipPos
378 static POINT SCROLL_ClipPos( LPRECT lpRect, POINT pt )
380 if( pt.x < lpRect->left )
381 pt.x = lpRect->left;
382 else
383 if( pt.x > lpRect->right )
384 pt.x = lpRect->right;
386 if( pt.y < lpRect->top )
387 pt.y = lpRect->top;
388 else
389 if( pt.y > lpRect->bottom )
390 pt.y = lpRect->bottom;
392 return pt;
396 /***********************************************************************
397 * SCROLL_HitTest
399 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
401 static enum SCROLL_HITTEST SCROLL_HitTest( HWND hwnd, INT nBar,
402 POINT pt, BOOL bDragging )
404 INT arrowSize, thumbSize, thumbPos;
405 RECT rect;
407 BOOL vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
408 &arrowSize, &thumbSize, &thumbPos );
410 if ( (bDragging && !SCROLL_PtInRectEx( &rect, pt, vertical )) ||
411 (!PtInRect( &rect, pt )) ) return SCROLL_NOWHERE;
413 if (vertical)
415 if (pt.y < rect.top + arrowSize) return SCROLL_TOP_ARROW;
416 if (pt.y >= rect.bottom - arrowSize) return SCROLL_BOTTOM_ARROW;
417 if (!thumbPos) return SCROLL_TOP_RECT;
418 pt.y -= rect.top;
419 if (pt.y < thumbPos) return SCROLL_TOP_RECT;
420 if (pt.y >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
422 else /* horizontal */
424 if (pt.x < rect.left + arrowSize) return SCROLL_TOP_ARROW;
425 if (pt.x >= rect.right - arrowSize) return SCROLL_BOTTOM_ARROW;
426 if (!thumbPos) return SCROLL_TOP_RECT;
427 pt.x -= rect.left;
428 if (pt.x < thumbPos) return SCROLL_TOP_RECT;
429 if (pt.x >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
431 return SCROLL_THUMB;
435 /***********************************************************************
436 * SCROLL_DrawArrows
438 * Draw the scroll bar arrows.
440 static void SCROLL_DrawArrows( HDC hdc, SCROLLBAR_INFO *infoPtr,
441 RECT *rect, INT arrowSize, BOOL vertical,
442 BOOL top_pressed, BOOL bottom_pressed )
444 RECT r;
446 r = *rect;
447 if( vertical )
448 r.bottom = r.top + arrowSize;
449 else
450 r.right = r.left + arrowSize;
452 DrawFrameControl( hdc, &r, DFC_SCROLL,
453 (vertical ? DFCS_SCROLLUP : DFCS_SCROLLLEFT)
454 | (top_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
455 | (infoPtr->flags&ESB_DISABLE_LTUP ? DFCS_INACTIVE : 0 ) );
457 r = *rect;
458 if( vertical )
459 r.top = r.bottom-arrowSize;
460 else
461 r.left = r.right-arrowSize;
463 DrawFrameControl( hdc, &r, DFC_SCROLL,
464 (vertical ? DFCS_SCROLLDOWN : DFCS_SCROLLRIGHT)
465 | (bottom_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
466 | (infoPtr->flags&ESB_DISABLE_RTDN ? DFCS_INACTIVE : 0) );
469 static void SCROLL_DrawMovingThumb( HDC hdc, RECT *rect, BOOL vertical,
470 INT arrowSize, INT thumbSize )
472 INT pos = SCROLL_TrackingPos;
473 INT max_size;
475 if( vertical )
476 max_size = rect->bottom - rect->top;
477 else
478 max_size = rect->right - rect->left;
480 max_size -= (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) + thumbSize;
482 if( pos < (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) )
483 pos = (arrowSize-SCROLL_ARROW_THUMB_OVERLAP);
484 else if( pos > max_size )
485 pos = max_size;
487 SCROLL_DrawInterior_9x( SCROLL_TrackingWin, hdc, SCROLL_TrackingBar,
488 rect, arrowSize, thumbSize, pos,
489 0, vertical, FALSE, FALSE );
491 SCROLL_MovingThumb = !SCROLL_MovingThumb;
494 /***********************************************************************
495 * SCROLL_DrawInterior
497 * Draw the scroll bar interior (everything except the arrows).
499 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
500 RECT *rect, INT arrowSize,
501 INT thumbSize, INT thumbPos,
502 UINT flags, BOOL vertical,
503 BOOL top_selected, BOOL bottom_selected )
505 RECT r;
506 HPEN hSavePen;
507 HBRUSH hSaveBrush,hBrush;
509 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
510 * The window-owned scrollbars need to call DEFWND_ControlColor
511 * to correctly setup default scrollbar colors
513 if (nBar == SB_CTL)
515 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
516 (WPARAM)hdc,(LPARAM)hwnd);
518 else
520 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
523 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
524 hSaveBrush = SelectObject( hdc, hBrush );
526 /* Calculate the scroll rectangle */
527 r = *rect;
528 if (vertical)
530 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
531 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
533 else
535 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
536 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
539 /* Draw the scroll rectangles and thumb */
540 if (!thumbPos) /* No thumb to draw */
542 PatBlt( hdc, r.left, r.top,
543 r.right - r.left, r.bottom - r.top,
544 PATCOPY );
546 /* cleanup and return */
547 SelectObject( hdc, hSavePen );
548 SelectObject( hdc, hSaveBrush );
549 return;
552 if (vertical)
554 PatBlt( hdc, r.left, r.top,
555 r.right - r.left,
556 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
557 top_selected ? 0x0f0000 : PATCOPY );
558 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
559 PatBlt( hdc, r.left, r.top + thumbSize,
560 r.right - r.left,
561 r.bottom - r.top - thumbSize,
562 bottom_selected ? 0x0f0000 : PATCOPY );
563 r.bottom = r.top + thumbSize;
565 else /* horizontal */
567 PatBlt( hdc, r.left, r.top,
568 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
569 r.bottom - r.top,
570 top_selected ? 0x0f0000 : PATCOPY );
571 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
572 PatBlt( hdc, r.left + thumbSize, r.top,
573 r.right - r.left - thumbSize,
574 r.bottom - r.top,
575 bottom_selected ? 0x0f0000 : PATCOPY );
576 r.right = r.left + thumbSize;
579 /* Draw the thumb */
580 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT | BF_MIDDLE );
582 /* cleanup */
583 SelectObject( hdc, hSavePen );
584 SelectObject( hdc, hSaveBrush );
588 static void SCROLL_DrawInterior( HWND hwnd, HDC hdc, INT nBar,
589 RECT *rect, INT arrowSize,
590 INT thumbSize, INT thumbPos,
591 UINT flags, BOOL vertical,
592 BOOL top_selected, BOOL bottom_selected )
594 RECT r;
595 HPEN hSavePen;
596 HBRUSH hSaveBrush,hBrush;
597 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
599 if (Save_SCROLL_MovingThumb &&
600 (SCROLL_TrackingWin == hwnd) &&
601 (SCROLL_TrackingBar == nBar))
602 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
604 /* Select the correct brush and pen */
606 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
607 * The window-owned scrollbars need to call DEFWND_ControlColor
608 * to correctly setup default scrollbar colors
610 if (nBar == SB_CTL) {
611 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
612 (WPARAM)hdc,(LPARAM)hwnd);
613 } else {
614 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
616 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
617 hSaveBrush = SelectObject( hdc, hBrush );
619 /* Calculate the scroll rectangle */
621 r = *rect;
622 if (vertical)
624 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
625 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
627 else
629 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
630 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
633 /* Draw the scroll bar frame */
635 /* Draw the scroll rectangles and thumb */
637 if (!thumbPos) /* No thumb to draw */
639 PatBlt( hdc, r.left, r.top, r.right - r.left, r.bottom - r.top, PATCOPY );
641 /* cleanup and return */
642 SelectObject( hdc, hSavePen );
643 SelectObject( hdc, hSaveBrush );
644 return;
647 if (vertical)
649 PatBlt( hdc, r.left, r.top, r.right - r.left,
650 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
651 top_selected ? 0x0f0000 : PATCOPY );
652 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
653 PatBlt( hdc, r.left, r.top + thumbSize, r.right - r.left,
654 r.bottom - r.top - thumbSize,
655 bottom_selected ? 0x0f0000 : PATCOPY );
656 r.bottom = r.top + thumbSize;
658 else /* horizontal */
660 PatBlt( hdc, r.left, r.top,
661 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
662 r.bottom - r.top, top_selected ? 0x0f0000 : PATCOPY );
663 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
664 PatBlt( hdc, r.left + thumbSize, r.top, r.right - r.left - thumbSize,
665 r.bottom - r.top, bottom_selected ? 0x0f0000 : PATCOPY );
666 r.right = r.left + thumbSize;
669 /* Draw the thumb */
671 SelectObject( hdc, GetSysColorBrush(COLOR_BTNFACE) );
672 Rectangle( hdc, r.left+1, r.top+1, r.right-1, r.bottom-1 );
673 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT );
675 if (Save_SCROLL_MovingThumb &&
676 (SCROLL_TrackingWin == hwnd) &&
677 (SCROLL_TrackingBar == nBar))
678 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
680 /* cleanup */
681 SelectObject( hdc, hSavePen );
682 SelectObject( hdc, hSaveBrush );
686 /***********************************************************************
687 * SCROLL_DrawScrollBar
689 * Redraw the whole scrollbar.
691 void SCROLL_DrawScrollBar( HWND hwnd, HDC hdc, INT nBar,
692 BOOL arrows, BOOL interior )
694 INT arrowSize, thumbSize, thumbPos;
695 RECT rect;
696 BOOL vertical;
697 SCROLLBAR_INFO *infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, TRUE );
698 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
699 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
701 if (!(hwnd = WIN_GetFullHandle( hwnd ))) return;
703 if (!infoPtr ||
704 ((nBar == SB_VERT) && !(style & WS_VSCROLL)) ||
705 ((nBar == SB_HORZ) && !(style & WS_HSCROLL))) return;
706 if (!WIN_IsWindowDrawable( hwnd, FALSE )) return;
708 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
709 &arrowSize, &thumbSize, &thumbPos );
711 /* do not draw if the scrollbar rectangle is empty */
712 if(IsRectEmpty(&rect)) return;
714 if (Save_SCROLL_MovingThumb &&
715 (SCROLL_TrackingWin == hwnd) &&
716 (SCROLL_TrackingBar == nBar))
717 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
719 /* Draw the arrows */
721 if (arrows && arrowSize)
723 if( vertical == SCROLL_trackVertical && GetCapture() == hwnd )
724 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
725 (SCROLL_trackHitTest == SCROLL_TOP_ARROW),
726 (SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW) );
727 else
728 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
729 FALSE, FALSE );
731 if( interior )
732 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
733 thumbPos, infoPtr->flags, vertical, FALSE, FALSE );
735 if (Save_SCROLL_MovingThumb &&
736 (SCROLL_TrackingWin == hwnd) &&
737 (SCROLL_TrackingBar == nBar))
738 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
740 /* if scroll bar has focus, reposition the caret */
741 if(hwnd==GetFocus() && (nBar==SB_CTL))
743 if (!vertical)
745 SetCaretPos(thumbPos+1, rect.top+1);
747 else
749 SetCaretPos(rect.top+1, thumbPos+1);
754 /***********************************************************************
755 * SCROLL_DrawSizeGrip
757 * Draw the size grip.
759 static void SCROLL_DrawSizeGrip( HWND hwnd, HDC hdc)
761 RECT rc;
763 GetClientRect( hwnd, &rc );
764 FillRect( hdc, &rc, GetSysColorBrush(COLOR_SCROLLBAR) );
765 rc.left = max( rc.left, rc.right - GetSystemMetrics(SM_CXVSCROLL) - 1 );
766 rc.top = max( rc.top, rc.bottom - GetSystemMetrics(SM_CYHSCROLL) - 1 );
767 DrawFrameControl( hdc, &rc, DFC_SCROLL, DFCS_SCROLLSIZEGRIP );
771 /***********************************************************************
772 * SCROLL_RefreshScrollBar
774 * Repaint the scroll bar interior after a SetScrollRange() or
775 * SetScrollPos() call.
777 static void SCROLL_RefreshScrollBar( HWND hwnd, INT nBar,
778 BOOL arrows, BOOL interior )
780 HDC hdc = GetDCEx( hwnd, 0,
781 DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW) );
782 if (!hdc) return;
784 SCROLL_DrawScrollBar( hwnd, hdc, nBar, arrows, interior );
785 ReleaseDC( hwnd, hdc );
789 /***********************************************************************
790 * SCROLL_HandleKbdEvent
792 * Handle a keyboard event (only for SB_CTL scrollbars with focus).
794 * PARAMS
795 * hwnd [I] Handle of window with scrollbar(s)
796 * wParam [I] Variable input including enable state
797 * lParam [I] Variable input including input point
799 static void SCROLL_HandleKbdEvent(HWND hwnd, WPARAM wParam, LPARAM lParam)
801 TRACE("hwnd=%p wParam=%ld lParam=%ld\n", hwnd, wParam, lParam);
803 /* hide caret on first KEYDOWN to prevent flicker */
804 if ((lParam & PFD_DOUBLEBUFFER_DONTCARE) == 0)
805 HideCaret(hwnd);
807 switch(wParam)
809 case VK_PRIOR: wParam = SB_PAGEUP; break;
810 case VK_NEXT: wParam = SB_PAGEDOWN; break;
811 case VK_HOME: wParam = SB_TOP; break;
812 case VK_END: wParam = SB_BOTTOM; break;
813 case VK_UP: wParam = SB_LINEUP; break;
814 case VK_DOWN: wParam = SB_LINEDOWN; break;
815 case VK_LEFT: wParam = SB_LINEUP; break;
816 case VK_RIGHT: wParam = SB_LINEDOWN; break;
817 default: return;
819 SendMessageW(GetParent(hwnd),
820 ((GetWindowLongW( hwnd, GWL_STYLE ) & SBS_VERT) ?
821 WM_VSCROLL : WM_HSCROLL), wParam, (LPARAM)hwnd);
825 /***********************************************************************
826 * SCROLL_HandleScrollEvent
828 * Handle a mouse or timer event for the scrollbar.
829 * 'pt' is the location of the mouse event in client (for SB_CTL) or
830 * windows coordinates.
832 static void SCROLL_HandleScrollEvent( HWND hwnd, INT nBar, UINT msg, POINT pt)
834 /* Previous mouse position for timer events */
835 static POINT prevPt;
836 /* Thumb position when tracking started. */
837 static UINT trackThumbPos;
838 /* Position in the scroll-bar of the last button-down event. */
839 static INT lastClickPos;
840 /* Position in the scroll-bar of the last mouse event. */
841 static INT lastMousePos;
843 enum SCROLL_HITTEST hittest;
844 HWND hwndOwner, hwndCtl;
845 BOOL vertical;
846 INT arrowSize, thumbSize, thumbPos;
847 RECT rect;
848 HDC hdc;
850 SCROLLBAR_INFO *infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, FALSE );
851 if (!infoPtr) return;
852 if ((SCROLL_trackHitTest == SCROLL_NOWHERE) && (msg != WM_LBUTTONDOWN))
853 return;
855 if (nBar == SB_CTL && (GetWindowLongW( hwnd, GWL_STYLE ) & (SBS_SIZEGRIP | SBS_SIZEBOX)))
857 switch(msg)
859 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
860 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
861 SetCapture( hwnd );
862 prevPt = pt;
863 SCROLL_trackHitTest = hittest = SCROLL_THUMB;
864 break;
865 case WM_MOUSEMOVE:
866 GetClientRect(GetParent(GetParent(hwnd)),&rect);
867 prevPt = pt;
868 break;
869 case WM_LBUTTONUP:
870 ReleaseCapture();
871 SCROLL_trackHitTest = hittest = SCROLL_NOWHERE;
872 if (hwnd==GetFocus()) ShowCaret(hwnd);
873 break;
874 case WM_SYSTIMER:
875 pt = prevPt;
876 break;
878 return;
881 hdc = GetDCEx( hwnd, 0, DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW));
882 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
883 &arrowSize, &thumbSize, &thumbPos );
884 hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd) : hwnd;
885 hwndCtl = (nBar == SB_CTL) ? hwnd : 0;
887 switch(msg)
889 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
890 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
891 SCROLL_trackVertical = vertical;
892 SCROLL_trackHitTest = hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
893 lastClickPos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
894 lastMousePos = lastClickPos;
895 trackThumbPos = thumbPos;
896 prevPt = pt;
897 if (nBar == SB_CTL && (GetWindowLongW(hwnd, GWL_STYLE) & WS_TABSTOP)) SetFocus( hwnd );
898 SetCapture( hwnd );
899 break;
901 case WM_MOUSEMOVE:
902 hittest = SCROLL_HitTest( hwnd, nBar, pt, TRUE );
903 prevPt = pt;
904 break;
906 case WM_LBUTTONUP:
907 hittest = SCROLL_NOWHERE;
908 ReleaseCapture();
909 /* if scrollbar has focus, show back caret */
910 if (hwnd==GetFocus()) ShowCaret(hwnd);
911 break;
913 case WM_SYSTIMER:
914 pt = prevPt;
915 hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
916 break;
918 default:
919 return; /* Should never happen */
922 TRACE("Event: hwnd=%p bar=%d msg=%s pt=%d,%d hit=%d\n",
923 hwnd, nBar, SPY_GetMsgName(msg,hwnd), pt.x, pt.y, hittest );
925 switch(SCROLL_trackHitTest)
927 case SCROLL_NOWHERE: /* No tracking in progress */
928 break;
930 case SCROLL_TOP_ARROW:
931 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
932 (hittest == SCROLL_trackHitTest), FALSE );
933 if (hittest == SCROLL_trackHitTest)
935 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
937 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
938 SB_LINEUP, (LPARAM)hwndCtl );
941 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
942 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
944 else KillSystemTimer( hwnd, SCROLL_TIMER );
945 break;
947 case SCROLL_TOP_RECT:
948 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
949 thumbPos, infoPtr->flags, vertical,
950 (hittest == SCROLL_trackHitTest), FALSE );
951 if (hittest == SCROLL_trackHitTest)
953 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
955 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
956 SB_PAGEUP, (LPARAM)hwndCtl );
958 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
959 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
961 else KillSystemTimer( hwnd, SCROLL_TIMER );
962 break;
964 case SCROLL_THUMB:
965 if (msg == WM_LBUTTONDOWN)
967 SCROLL_TrackingWin = hwnd;
968 SCROLL_TrackingBar = nBar;
969 SCROLL_TrackingPos = trackThumbPos + lastMousePos - lastClickPos;
970 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
971 vertical,
972 SCROLL_TrackingPos );
973 if (!SCROLL_MovingThumb)
974 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
976 else if (msg == WM_LBUTTONUP)
978 if (SCROLL_MovingThumb)
979 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
981 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
982 thumbPos, infoPtr->flags, vertical,
983 FALSE, FALSE );
985 else /* WM_MOUSEMOVE */
987 INT pos;
989 if (!SCROLL_PtInRectEx( &rect, pt, vertical )) pos = lastClickPos;
990 else
992 pt = SCROLL_ClipPos( &rect, pt );
993 pos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
995 if ( (pos != lastMousePos) || (!SCROLL_MovingThumb) )
997 if (SCROLL_MovingThumb)
998 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
999 arrowSize, thumbSize );
1000 lastMousePos = pos;
1001 SCROLL_TrackingPos = trackThumbPos + pos - lastClickPos;
1002 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
1003 vertical,
1004 SCROLL_TrackingPos );
1005 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1006 MAKEWPARAM( SB_THUMBTRACK, SCROLL_TrackingVal),
1007 (LPARAM)hwndCtl );
1008 if (!SCROLL_MovingThumb)
1009 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
1010 arrowSize, thumbSize );
1013 break;
1015 case SCROLL_BOTTOM_RECT:
1016 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
1017 thumbPos, infoPtr->flags, vertical,
1018 FALSE, (hittest == SCROLL_trackHitTest) );
1019 if (hittest == SCROLL_trackHitTest)
1021 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1023 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1024 SB_PAGEDOWN, (LPARAM)hwndCtl );
1026 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1027 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
1029 else KillSystemTimer( hwnd, SCROLL_TIMER );
1030 break;
1032 case SCROLL_BOTTOM_ARROW:
1033 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
1034 FALSE, (hittest == SCROLL_trackHitTest) );
1035 if (hittest == SCROLL_trackHitTest)
1037 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1039 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1040 SB_LINEDOWN, (LPARAM)hwndCtl );
1043 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1044 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
1046 else KillSystemTimer( hwnd, SCROLL_TIMER );
1047 break;
1050 if (msg == WM_LBUTTONDOWN)
1053 if (hittest == SCROLL_THUMB)
1055 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1056 trackThumbPos + lastMousePos - lastClickPos );
1057 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1058 MAKEWPARAM( SB_THUMBTRACK, val ), (LPARAM)hwndCtl );
1062 if (msg == WM_LBUTTONUP)
1064 hittest = SCROLL_trackHitTest;
1065 SCROLL_trackHitTest = SCROLL_NOWHERE; /* Terminate tracking */
1067 if (hittest == SCROLL_THUMB)
1069 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1070 trackThumbPos + lastMousePos - lastClickPos );
1071 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1072 MAKEWPARAM( SB_THUMBPOSITION, val ), (LPARAM)hwndCtl );
1074 /* SB_ENDSCROLL doesn't report thumb position */
1075 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1076 SB_ENDSCROLL, (LPARAM)hwndCtl );
1078 /* Terminate tracking */
1079 SCROLL_TrackingWin = 0;
1082 ReleaseDC( hwnd, hdc );
1086 /***********************************************************************
1087 * SCROLL_TrackScrollBar
1089 * Track a mouse button press on a scroll-bar.
1090 * pt is in screen-coordinates for non-client scroll bars.
1092 void SCROLL_TrackScrollBar( HWND hwnd, INT scrollbar, POINT pt )
1094 MSG msg;
1095 RECT rect;
1097 if (scrollbar != SB_CTL)
1099 WIN_GetRectangles( hwnd, COORDS_CLIENT, &rect, NULL );
1100 ScreenToClient( hwnd, &pt );
1101 pt.x -= rect.left;
1102 pt.y -= rect.top;
1104 else
1105 rect.left = rect.top = 0;
1107 SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt );
1111 if (!GetMessageW( &msg, 0, 0, 0 )) break;
1112 if (CallMsgFilterW( &msg, MSGF_SCROLLBAR )) continue;
1113 if (msg.message == WM_LBUTTONUP ||
1114 msg.message == WM_MOUSEMOVE ||
1115 (msg.message == WM_SYSTIMER && msg.wParam == SCROLL_TIMER))
1117 pt.x = (short)LOWORD(msg.lParam) - rect.left;
1118 pt.y = (short)HIWORD(msg.lParam) - rect.top;
1119 SCROLL_HandleScrollEvent( hwnd, scrollbar, msg.message, pt );
1121 else
1123 TranslateMessage( &msg );
1124 DispatchMessageW( &msg );
1126 if (!IsWindow( hwnd ))
1128 ReleaseCapture();
1129 break;
1131 } while (msg.message != WM_LBUTTONUP && GetCapture() == hwnd);
1135 /***********************************************************************
1136 * SCROLL_CreateScrollBar
1138 * Create a scroll bar
1140 * PARAMS
1141 * hwnd [I] Handle of window with scrollbar(s)
1142 * lpCreate [I] The style and place of the scroll bar
1144 static void SCROLL_CreateScrollBar(HWND hwnd, LPCREATESTRUCTW lpCreate)
1146 LPSCROLLBAR_INFO info = NULL;
1147 WND *win;
1149 TRACE("hwnd=%p lpCreate=%p\n", hwnd, lpCreate);
1151 win = WIN_GetPtr(hwnd);
1152 if (win->cbWndExtra >= sizeof(SCROLLBAR_WNDDATA))
1154 SCROLLBAR_WNDDATA *data = (SCROLLBAR_WNDDATA*)win->wExtra;
1155 data->magic = SCROLLBAR_MAGIC;
1156 info = &data->info;
1158 else WARN("Not enough extra data\n");
1159 WIN_ReleasePtr(win);
1160 if (!info) return;
1162 if (lpCreate->style & WS_DISABLED)
1164 info->flags = ESB_DISABLE_BOTH;
1165 TRACE("Created WS_DISABLED scrollbar\n");
1168 if (lpCreate->style & (SBS_SIZEGRIP | SBS_SIZEBOX))
1170 if (lpCreate->style & SBS_SIZEBOXTOPLEFTALIGN)
1171 MoveWindow( hwnd, lpCreate->x, lpCreate->y, GetSystemMetrics(SM_CXVSCROLL)+1,
1172 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1173 else if(lpCreate->style & SBS_SIZEBOXBOTTOMRIGHTALIGN)
1174 MoveWindow( hwnd, lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1175 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1176 GetSystemMetrics(SM_CXVSCROLL)+1,
1177 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1179 else if (lpCreate->style & SBS_VERT)
1181 if (lpCreate->style & SBS_LEFTALIGN)
1182 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1183 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1184 else if (lpCreate->style & SBS_RIGHTALIGN)
1185 MoveWindow( hwnd,
1186 lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1187 lpCreate->y,
1188 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1190 else /* SBS_HORZ */
1192 if (lpCreate->style & SBS_TOPALIGN)
1193 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1194 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1195 else if (lpCreate->style & SBS_BOTTOMALIGN)
1196 MoveWindow( hwnd,
1197 lpCreate->x,
1198 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1199 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1204 /*************************************************************************
1205 * SCROLL_GetScrollInfo
1207 * Internal helper for the API function
1209 * PARAMS
1210 * hwnd [I] Handle of window with scrollbar(s)
1211 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1212 * info [IO] fMask specifies which values to retrieve
1214 * RETURNS
1215 * FALSE if requested field not filled (f.i. scroll bar does not exist)
1217 static BOOL SCROLL_GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1219 LPSCROLLBAR_INFO infoPtr;
1221 /* handle invalid data structure */
1222 if (!SCROLL_ScrollInfoValid(info)
1223 || !(infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE)))
1224 return FALSE;
1226 /* fill in the desired scroll info structure */
1227 if (info->fMask & SIF_PAGE) info->nPage = infoPtr->page;
1228 if (info->fMask & SIF_POS) info->nPos = infoPtr->curVal;
1229 if ((info->fMask & SIF_TRACKPOS) && (info->cbSize == sizeof(*info)))
1230 info->nTrackPos = (SCROLL_TrackingWin == WIN_GetFullHandle(hwnd)) ? SCROLL_TrackingVal : infoPtr->curVal;
1231 if (info->fMask & SIF_RANGE)
1233 info->nMin = infoPtr->minVal;
1234 info->nMax = infoPtr->maxVal;
1237 TRACE("cbSize %02x fMask %04x nMin %d nMax %d nPage %u nPos %d nTrackPos %d\n",
1238 info->cbSize, info->fMask, info->nMin, info->nMax, info->nPage,
1239 info->nPos, info->nTrackPos);
1241 return (info->fMask & SIF_ALL) != 0;
1245 /*************************************************************************
1246 * SCROLL_GetScrollBarInfo
1248 * Internal helper for the API function
1250 * PARAMS
1251 * hwnd [I] Handle of window with scrollbar(s)
1252 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1253 * info [IO] cbSize specifies the size of the structure
1255 * RETURNS
1256 * FALSE if failed
1258 static BOOL SCROLL_GetScrollBarInfo(HWND hwnd, LONG idObject, LPSCROLLBARINFO info)
1260 LPSCROLLBAR_INFO infoPtr;
1261 INT nBar;
1262 INT nDummy;
1263 DWORD style = GetWindowLongW(hwnd, GWL_STYLE);
1264 BOOL pressed;
1265 RECT rect;
1267 switch (idObject)
1269 case OBJID_CLIENT: nBar = SB_CTL; break;
1270 case OBJID_HSCROLL: nBar = SB_HORZ; break;
1271 case OBJID_VSCROLL: nBar = SB_VERT; break;
1272 default: return FALSE;
1275 /* handle invalid data structure */
1276 if (info->cbSize != sizeof(*info))
1277 return FALSE;
1279 SCROLL_GetScrollBarRect(hwnd, nBar, &info->rcScrollBar, &nDummy,
1280 &info->dxyLineButton, &info->xyThumbTop);
1281 /* rcScrollBar needs to be in screen coordinates */
1282 GetWindowRect(hwnd, &rect);
1283 OffsetRect(&info->rcScrollBar, rect.left, rect.top);
1285 info->xyThumbBottom = info->xyThumbTop + info->dxyLineButton;
1287 infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, TRUE);
1288 if (!infoPtr)
1289 return FALSE;
1291 /* Scroll bar state */
1292 info->rgstate[0] = 0;
1293 if ((nBar == SB_HORZ && !(style & WS_HSCROLL))
1294 || (nBar == SB_VERT && !(style & WS_VSCROLL)))
1295 info->rgstate[0] |= STATE_SYSTEM_INVISIBLE;
1296 if (infoPtr->minVal >= infoPtr->maxVal - max(infoPtr->page - 1, 0))
1298 if (!(info->rgstate[0] & STATE_SYSTEM_INVISIBLE))
1299 info->rgstate[0] |= STATE_SYSTEM_UNAVAILABLE;
1300 else
1301 info->rgstate[0] |= STATE_SYSTEM_OFFSCREEN;
1303 if (nBar == SB_CTL && !IsWindowEnabled(hwnd))
1304 info->rgstate[0] |= STATE_SYSTEM_UNAVAILABLE;
1306 pressed = ((nBar == SB_VERT) == SCROLL_trackVertical && GetCapture() == hwnd);
1308 /* Top/left arrow button state. MSDN says top/right, but I don't believe it */
1309 info->rgstate[1] = 0;
1310 if (pressed && SCROLL_trackHitTest == SCROLL_TOP_ARROW)
1311 info->rgstate[1] |= STATE_SYSTEM_PRESSED;
1312 if (infoPtr->flags & ESB_DISABLE_LTUP)
1313 info->rgstate[1] |= STATE_SYSTEM_UNAVAILABLE;
1315 /* Page up/left region state. MSDN says up/right, but I don't believe it */
1316 info->rgstate[2] = 0;
1317 if (infoPtr->curVal == infoPtr->minVal)
1318 info->rgstate[2] |= STATE_SYSTEM_INVISIBLE;
1319 if (pressed && SCROLL_trackHitTest == SCROLL_TOP_RECT)
1320 info->rgstate[2] |= STATE_SYSTEM_PRESSED;
1322 /* Thumb state */
1323 info->rgstate[3] = 0;
1324 if (pressed && SCROLL_trackHitTest == SCROLL_THUMB)
1325 info->rgstate[3] |= STATE_SYSTEM_PRESSED;
1327 /* Page down/right region state. MSDN says down/left, but I don't believe it */
1328 info->rgstate[4] = 0;
1329 if (infoPtr->curVal >= infoPtr->maxVal - 1)
1330 info->rgstate[4] |= STATE_SYSTEM_INVISIBLE;
1331 if (pressed && SCROLL_trackHitTest == SCROLL_BOTTOM_RECT)
1332 info->rgstate[4] |= STATE_SYSTEM_PRESSED;
1334 /* Bottom/right arrow button state. MSDN says bottom/left, but I don't believe it */
1335 info->rgstate[5] = 0;
1336 if (pressed && SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW)
1337 info->rgstate[5] |= STATE_SYSTEM_PRESSED;
1338 if (infoPtr->flags & ESB_DISABLE_RTDN)
1339 info->rgstate[5] |= STATE_SYSTEM_UNAVAILABLE;
1341 return TRUE;
1345 /*************************************************************************
1346 * SCROLL_GetScrollPos
1348 * Internal helper for the API function
1350 * PARAMS
1351 * hwnd [I] Handle of window with scrollbar(s)
1352 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1354 static INT SCROLL_GetScrollPos(HWND hwnd, INT nBar)
1356 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1357 return infoPtr ? infoPtr->curVal: 0;
1361 /*************************************************************************
1362 * SCROLL_GetScrollRange
1364 * Internal helper for the API function
1366 * PARAMS
1367 * hwnd [I] Handle of window with scrollbar(s)
1368 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1369 * lpMin [O] Where to store minimum value
1370 * lpMax [O] Where to store maximum value
1372 * RETURNS
1373 * Success: TRUE
1374 * Failure: FALSE
1376 static BOOL SCROLL_GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1378 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1380 if (lpMin) *lpMin = infoPtr ? infoPtr->minVal : 0;
1381 if (lpMax) *lpMax = infoPtr ? infoPtr->maxVal : 0;
1383 return TRUE;
1387 /*************************************************************************
1388 * SCROLL_SetScrollRange
1390 * PARAMS
1391 * hwnd [I] Handle of window with scrollbar(s)
1392 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1393 * lpMin [I] Minimum value
1394 * lpMax [I] Maximum value
1397 static BOOL SCROLL_SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal)
1399 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1401 TRACE("hwnd=%p nBar=%d min=%d max=%d\n", hwnd, nBar, minVal, maxVal);
1403 if (infoPtr)
1405 infoPtr->minVal = minVal;
1406 infoPtr->maxVal = maxVal;
1408 return TRUE;
1412 /***********************************************************************
1413 * ScrollBarWndProc_common
1415 LRESULT ScrollBarWndProc_common( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, BOOL unicode )
1417 if (!IsWindow( hwnd )) return 0;
1419 switch(message)
1421 case WM_CREATE:
1422 SCROLL_CreateScrollBar(hwnd, (LPCREATESTRUCTW)lParam);
1423 break;
1425 case WM_ENABLE:
1427 SCROLLBAR_INFO *infoPtr;
1428 if ((infoPtr = SCROLL_GetInternalInfo( hwnd, SB_CTL, FALSE )))
1430 infoPtr->flags = wParam ? ESB_ENABLE_BOTH : ESB_DISABLE_BOTH;
1431 SCROLL_RefreshScrollBar(hwnd, SB_CTL, TRUE, TRUE);
1434 return 0;
1436 case WM_LBUTTONDBLCLK:
1437 case WM_LBUTTONDOWN:
1438 if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEGRIP)
1440 SendMessageW( GetParent(hwnd), WM_SYSCOMMAND,
1441 SC_SIZE + ((GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_LAYOUTRTL) ?
1442 WMSZ_BOTTOMLEFT : WMSZ_BOTTOMRIGHT), lParam );
1444 else
1446 POINT pt;
1447 pt.x = (short)LOWORD(lParam);
1448 pt.y = (short)HIWORD(lParam);
1449 SCROLL_TrackScrollBar( hwnd, SB_CTL, pt );
1451 break;
1452 case WM_LBUTTONUP:
1453 case WM_MOUSEMOVE:
1454 case WM_SYSTIMER:
1456 POINT pt;
1457 pt.x = (short)LOWORD(lParam);
1458 pt.y = (short)HIWORD(lParam);
1459 SCROLL_HandleScrollEvent( hwnd, SB_CTL, message, pt );
1461 break;
1463 case WM_KEYDOWN:
1464 SCROLL_HandleKbdEvent(hwnd, wParam, lParam);
1465 break;
1467 case WM_KEYUP:
1468 ShowCaret(hwnd);
1469 break;
1471 case WM_SETFOCUS:
1473 /* Create a caret when a ScrollBar get focus */
1474 RECT rect;
1475 int arrowSize, thumbSize, thumbPos, vertical;
1476 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,
1477 &arrowSize, &thumbSize, &thumbPos );
1478 if (!vertical)
1480 CreateCaret(hwnd, (HBITMAP)1, thumbSize-2, rect.bottom-rect.top-2);
1481 SetCaretPos(thumbPos+1, rect.top+1);
1483 else
1485 CreateCaret(hwnd, (HBITMAP)1, rect.right-rect.left-2,thumbSize-2);
1486 SetCaretPos(rect.top+1, thumbPos+1);
1488 ShowCaret(hwnd);
1490 break;
1492 case WM_KILLFOCUS:
1494 RECT rect;
1495 int arrowSize, thumbSize, thumbPos, vertical;
1496 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,&arrowSize, &thumbSize, &thumbPos );
1497 if (!vertical){
1498 rect.left=thumbPos+1;
1499 rect.right=rect.left+thumbSize;
1501 else
1503 rect.top=thumbPos+1;
1504 rect.bottom=rect.top+thumbSize;
1506 HideCaret(hwnd);
1507 InvalidateRect(hwnd,&rect,0);
1508 DestroyCaret();
1510 break;
1512 case WM_ERASEBKGND:
1513 return 1;
1515 case WM_GETDLGCODE:
1516 return DLGC_WANTARROWS; /* Windows returns this value */
1518 case WM_PAINT:
1520 PAINTSTRUCT ps;
1521 HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
1522 if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEGRIP)
1524 SCROLL_DrawSizeGrip( hwnd, hdc);
1526 else if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEBOX)
1528 RECT rc;
1529 GetClientRect( hwnd, &rc );
1530 FillRect( hdc, &rc, GetSysColorBrush(COLOR_SCROLLBAR) );
1532 else
1533 SCROLL_DrawScrollBar( hwnd, hdc, SB_CTL, TRUE, TRUE );
1534 if (!wParam) EndPaint(hwnd, &ps);
1536 break;
1538 case WM_SETCURSOR:
1539 if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEGRIP)
1541 ULONG_PTR cursor = (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_LAYOUTRTL) ? IDC_SIZENESW : IDC_SIZENWSE;
1542 return (LRESULT)SetCursor( LoadCursorA( 0, (LPSTR)cursor ));
1544 return DefWindowProcW( hwnd, message, wParam, lParam );
1546 case SBM_SETPOS:
1547 return SetScrollPos( hwnd, SB_CTL, wParam, (BOOL)lParam );
1549 case SBM_GETPOS:
1550 return SCROLL_GetScrollPos(hwnd, SB_CTL);
1552 case SBM_SETRANGEREDRAW:
1553 case SBM_SETRANGE:
1555 INT oldPos = SCROLL_GetScrollPos( hwnd, SB_CTL );
1556 SCROLL_SetScrollRange( hwnd, SB_CTL, wParam, lParam );
1557 if (message == SBM_SETRANGEREDRAW)
1558 SCROLL_RefreshScrollBar( hwnd, SB_CTL, TRUE, TRUE );
1559 if (oldPos != SCROLL_GetScrollPos( hwnd, SB_CTL )) return oldPos;
1561 return 0;
1563 case SBM_GETRANGE:
1564 return SCROLL_GetScrollRange(hwnd, SB_CTL, (LPINT)wParam, (LPINT)lParam);
1566 case SBM_ENABLE_ARROWS:
1567 return EnableScrollBar( hwnd, SB_CTL, wParam );
1569 case SBM_SETSCROLLINFO:
1570 return SCROLL_SetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam, wParam );
1572 case SBM_GETSCROLLINFO:
1573 return SCROLL_GetScrollInfo(hwnd, SB_CTL, (SCROLLINFO *)lParam);
1575 case SBM_GETSCROLLBARINFO:
1576 return SCROLL_GetScrollBarInfo(hwnd, OBJID_CLIENT, (SCROLLBARINFO *)lParam);
1578 case 0x00e5:
1579 case 0x00e7:
1580 case 0x00e8:
1581 case 0x00ec:
1582 case 0x00ed:
1583 case 0x00ee:
1584 case 0x00ef:
1585 ERR("unknown Win32 msg %04x wp=%08lx lp=%08lx\n",
1586 message, wParam, lParam );
1587 break;
1589 default:
1590 if (message >= WM_USER)
1591 WARN("unknown msg %04x wp=%04lx lp=%08lx\n",
1592 message, wParam, lParam );
1593 if (unicode)
1594 return DefWindowProcW( hwnd, message, wParam, lParam );
1595 else
1596 return DefWindowProcA( hwnd, message, wParam, lParam );
1598 return 0;
1602 /*************************************************************************
1603 * SetScrollInfo (USER32.@)
1605 * SetScrollInfo can be used to set the position, upper bound,
1606 * lower bound, and page size of a scrollbar control.
1608 * PARAMS
1609 * hwnd [I] Handle of window with scrollbar(s)
1610 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1611 * info [I] Specifies what to change and new values
1612 * bRedraw [I] Should scrollbar be redrawn afterwards?
1614 * RETURNS
1615 * Scrollbar position
1617 * NOTE
1618 * For 100 lines of text to be displayed in a window of 25 lines,
1619 * one would for instance use info->nMin=0, info->nMax=75
1620 * (corresponding to the 76 different positions of the window on
1621 * the text), and info->nPage=25.
1623 INT WINAPI DECLSPEC_HOTPATCH SetScrollInfo(HWND hwnd, INT nBar, const SCROLLINFO *info, BOOL bRedraw)
1625 TRACE("hwnd=%p nBar=%d info=%p, bRedraw=%d\n", hwnd, nBar, info, bRedraw);
1627 /* Refer SB_CTL requests to the window */
1628 if (nBar == SB_CTL)
1629 return SendMessageW(hwnd, SBM_SETSCROLLINFO, bRedraw, (LPARAM)info);
1630 else
1631 return SCROLL_SetScrollInfo( hwnd, nBar, info, bRedraw );
1634 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar, LPCSCROLLINFO info, BOOL bRedraw )
1636 /* Update the scrollbar state and set action flags according to
1637 * what has to be done graphics wise. */
1639 SCROLLBAR_INFO *infoPtr;
1640 UINT new_flags;
1641 INT action = 0;
1643 /* handle invalid data structure */
1644 if (!SCROLL_ScrollInfoValid(info)
1645 || !(infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, TRUE)))
1646 return 0;
1648 if (TRACE_ON(scroll))
1650 TRACE("hwnd=%p bar=%d", hwnd, nBar);
1651 if (info->fMask & SIF_PAGE) TRACE( " page=%d", info->nPage );
1652 if (info->fMask & SIF_POS) TRACE( " pos=%d", info->nPos );
1653 if (info->fMask & SIF_RANGE) TRACE( " min=%d max=%d", info->nMin, info->nMax );
1654 TRACE("\n");
1657 /* Set the page size */
1659 if (info->fMask & SIF_PAGE)
1661 if( infoPtr->page != info->nPage )
1663 infoPtr->page = info->nPage;
1664 action |= SA_SSI_REFRESH;
1668 /* Set the scroll pos */
1670 if (info->fMask & SIF_POS)
1672 if( infoPtr->curVal != info->nPos )
1674 infoPtr->curVal = info->nPos;
1675 action |= SA_SSI_REFRESH;
1679 /* Set the scroll range */
1681 if (info->fMask & SIF_RANGE)
1683 /* Invalid range -> range is set to (0,0) */
1684 if ((info->nMin > info->nMax) ||
1685 ((UINT)(info->nMax - info->nMin) >= 0x80000000))
1687 action |= SA_SSI_REFRESH;
1688 infoPtr->minVal = 0;
1689 infoPtr->maxVal = 0;
1691 else
1693 if( infoPtr->minVal != info->nMin ||
1694 infoPtr->maxVal != info->nMax )
1696 action |= SA_SSI_REFRESH;
1697 infoPtr->minVal = info->nMin;
1698 infoPtr->maxVal = info->nMax;
1703 /* Make sure the page size is valid */
1704 if (infoPtr->page < 0) infoPtr->page = 0;
1705 else if (infoPtr->page > infoPtr->maxVal - infoPtr->minVal + 1 )
1706 infoPtr->page = infoPtr->maxVal - infoPtr->minVal + 1;
1708 /* Make sure the pos is inside the range */
1710 if (infoPtr->curVal < infoPtr->minVal)
1711 infoPtr->curVal = infoPtr->minVal;
1712 else if (infoPtr->curVal > infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1713 infoPtr->curVal = infoPtr->maxVal - max( infoPtr->page-1, 0 );
1715 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1716 infoPtr->page, infoPtr->curVal,
1717 infoPtr->minVal, infoPtr->maxVal );
1719 /* don't change the scrollbar state if SetScrollInfo
1720 * is just called with SIF_DISABLENOSCROLL
1722 if(!(info->fMask & SIF_ALL)) goto done;
1724 /* Check if the scrollbar should be hidden or disabled */
1726 if (info->fMask & (SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL))
1728 new_flags = infoPtr->flags;
1729 if (infoPtr->minVal >= infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1731 /* Hide or disable scroll-bar */
1732 if (info->fMask & SIF_DISABLENOSCROLL)
1734 new_flags = ESB_DISABLE_BOTH;
1735 action |= SA_SSI_REFRESH;
1737 else if ((nBar != SB_CTL) && (action & SA_SSI_REFRESH))
1739 action = SA_SSI_HIDE;
1742 else /* Show and enable scroll-bar only if no page only changed. */
1743 if (info->fMask != SIF_PAGE)
1745 new_flags = ESB_ENABLE_BOTH;
1746 if ((nBar != SB_CTL) && ( (action & SA_SSI_REFRESH) ))
1747 action |= SA_SSI_SHOW;
1750 if (nBar == SB_CTL && bRedraw && IsWindowVisible(hwnd) &&
1751 (new_flags == ESB_ENABLE_BOTH || new_flags == ESB_DISABLE_BOTH))
1753 EnableWindow(hwnd, new_flags == ESB_ENABLE_BOTH);
1756 if (infoPtr->flags != new_flags) /* check arrow flags */
1758 infoPtr->flags = new_flags;
1759 action |= SA_SSI_REPAINT_ARROWS;
1763 done:
1764 if( action & SA_SSI_HIDE )
1765 SCROLL_ShowScrollBar( hwnd, nBar, FALSE, FALSE );
1766 else
1768 if( action & SA_SSI_SHOW )
1769 if( SCROLL_ShowScrollBar( hwnd, nBar, TRUE, TRUE ) )
1770 return infoPtr->curVal; /* SetWindowPos() already did the painting */
1772 if( bRedraw )
1773 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
1774 else if( action & SA_SSI_REPAINT_ARROWS )
1775 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, FALSE );
1778 /* Return current position */
1779 return infoPtr->curVal;
1783 /*************************************************************************
1784 * GetScrollInfo (USER32.@)
1786 * GetScrollInfo can be used to retrieve the position, upper bound,
1787 * lower bound, and page size of a scrollbar control.
1789 * PARAMS
1790 * hwnd [I] Handle of window with scrollbar(s)
1791 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1792 * info [IO] fMask specifies which values to retrieve
1794 * RETURNS
1795 * TRUE if SCROLLINFO is filled
1796 * ( if nBar is SB_CTL, GetScrollInfo returns TRUE even if nothing
1797 * is filled)
1799 BOOL WINAPI DECLSPEC_HOTPATCH GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1801 TRACE("hwnd=%p nBar=%d info=%p\n", hwnd, nBar, info);
1803 /* Refer SB_CTL requests to the window */
1804 if (nBar == SB_CTL)
1806 SendMessageW(hwnd, SBM_GETSCROLLINFO, 0, (LPARAM)info);
1807 return TRUE;
1809 return SCROLL_GetScrollInfo(hwnd, nBar, info);
1813 /*************************************************************************
1814 * GetScrollBarInfo (USER32.@)
1816 * GetScrollBarInfo can be used to retrieve information about a scrollbar
1817 * control.
1819 * PARAMS
1820 * hwnd [I] Handle of window with scrollbar(s)
1821 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1822 * info [IO] cbSize specifies the size of SCROLLBARINFO
1824 * RETURNS
1825 * TRUE if success
1827 BOOL WINAPI GetScrollBarInfo(HWND hwnd, LONG idObject, LPSCROLLBARINFO info)
1829 TRACE("hwnd=%p idObject=%d info=%p\n", hwnd, idObject, info);
1831 /* Refer OBJID_CLIENT requests to the window */
1832 if (idObject == OBJID_CLIENT)
1833 return SendMessageW(hwnd, SBM_GETSCROLLBARINFO, 0, (LPARAM)info);
1834 else
1835 return SCROLL_GetScrollBarInfo(hwnd, idObject, info);
1839 /*************************************************************************
1840 * SetScrollPos (USER32.@)
1842 * Sets the current position of the scroll thumb.
1844 * PARAMS
1845 * hwnd [I] Handle of window with scrollbar(s)
1846 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1847 * nPos [I] New value
1848 * bRedraw [I] Should scrollbar be redrawn afterwards?
1850 * RETURNS
1851 * Success: Scrollbar position
1852 * Failure: 0
1854 * REMARKS
1855 * Note the ambiguity when 0 is returned. Use GetLastError
1856 * to make sure there was an error (and to know which one).
1858 INT WINAPI DECLSPEC_HOTPATCH SetScrollPos( HWND hwnd, INT nBar, INT nPos, BOOL bRedraw)
1860 SCROLLINFO info;
1861 SCROLLBAR_INFO *infoPtr;
1862 INT oldPos = 0;
1864 if ((infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, FALSE ))) oldPos = infoPtr->curVal;
1865 info.cbSize = sizeof(info);
1866 info.nPos = nPos;
1867 info.fMask = SIF_POS;
1868 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1869 return oldPos;
1873 /*************************************************************************
1874 * GetScrollPos (USER32.@)
1876 * Gets the current position of the scroll thumb.
1878 * PARAMS
1879 * hwnd [I] Handle of window with scrollbar(s)
1880 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1882 * RETURNS
1883 * Success: Current position
1884 * Failure: 0
1886 * REMARKS
1887 * There is ambiguity when 0 is returned. Use GetLastError
1888 * to make sure there was an error (and to know which one).
1890 INT WINAPI DECLSPEC_HOTPATCH GetScrollPos(HWND hwnd, INT nBar)
1892 TRACE("hwnd=%p nBar=%d\n", hwnd, nBar);
1894 /* Refer SB_CTL requests to the window */
1895 if (nBar == SB_CTL)
1896 return SendMessageW(hwnd, SBM_GETPOS, 0, 0);
1897 else
1898 return SCROLL_GetScrollPos(hwnd, nBar);
1902 /*************************************************************************
1903 * SetScrollRange (USER32.@)
1904 * The SetScrollRange function sets the minimum and maximum scroll box positions
1905 * If nMinPos and nMaxPos is the same value, the scroll bar will hide
1907 * Sets the range of the scroll bar.
1909 * PARAMS
1910 * hwnd [I] Handle of window with scrollbar(s)
1911 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1912 * minVal [I] New minimum value
1913 * maxVal [I] New Maximum value
1914 * bRedraw [I] Should scrollbar be redrawn afterwards?
1916 * RETURNS
1917 * Success: TRUE
1918 * Failure: FALSE
1920 BOOL WINAPI DECLSPEC_HOTPATCH SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal, BOOL bRedraw)
1922 SCROLLINFO info;
1924 TRACE("hwnd=%p nBar=%d min=%d max=%d, bRedraw=%d\n", hwnd, nBar, minVal, maxVal, bRedraw);
1926 info.cbSize = sizeof(info);
1927 info.fMask = SIF_RANGE;
1928 info.nMin = minVal;
1929 info.nMax = maxVal;
1930 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1931 return TRUE;
1935 /*************************************************************************
1936 * GetScrollRange (USER32.@)
1938 * Gets the range of the scroll bar.
1940 * PARAMS
1941 * hwnd [I] Handle of window with scrollbar(s)
1942 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1943 * lpMin [O] Where to store minimum value
1944 * lpMax [O] Where to store maximum value
1946 * RETURNS
1947 * TRUE if values is filled
1949 BOOL WINAPI DECLSPEC_HOTPATCH GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1951 TRACE("hwnd=%p nBar=%d lpMin=%p lpMax=%p\n", hwnd, nBar, lpMin, lpMax);
1953 /* Refer SB_CTL requests to the window */
1954 if (nBar == SB_CTL)
1955 SendMessageW(hwnd, SBM_GETRANGE, (WPARAM)lpMin, (LPARAM)lpMax);
1956 else
1957 SCROLL_GetScrollRange(hwnd, nBar, lpMin, lpMax);
1959 return TRUE;
1963 /*************************************************************************
1964 * SCROLL_ShowScrollBar()
1966 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1968 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar, BOOL fShowH, BOOL fShowV )
1970 ULONG old_style, set_bits = 0, clear_bits = 0;
1972 TRACE("hwnd=%p bar=%d horz=%d, vert=%d\n", hwnd, nBar, fShowH, fShowV );
1974 switch(nBar)
1976 case SB_CTL:
1977 ShowWindow( hwnd, fShowH ? SW_SHOW : SW_HIDE );
1978 return TRUE;
1980 case SB_BOTH:
1981 case SB_HORZ:
1982 if (fShowH) set_bits |= WS_HSCROLL;
1983 else clear_bits |= WS_HSCROLL;
1984 if( nBar == SB_HORZ ) break;
1985 /* fall through */
1986 case SB_VERT:
1987 if (fShowV) set_bits |= WS_VSCROLL;
1988 else clear_bits |= WS_VSCROLL;
1989 break;
1991 default:
1992 return FALSE; /* Nothing to do! */
1995 old_style = WIN_SetStyle( hwnd, set_bits, clear_bits );
1996 if ((old_style & clear_bits) != 0 || (old_style & set_bits) != set_bits)
1998 /* frame has been changed, let the window redraw itself */
1999 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
2000 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
2001 return TRUE;
2003 return FALSE; /* no frame changes */
2007 /*************************************************************************
2008 * ShowScrollBar (USER32.@)
2010 * Shows or hides the scroll bar.
2012 * PARAMS
2013 * hwnd [I] Handle of window with scrollbar(s)
2014 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
2015 * fShow [I] TRUE = show, FALSE = hide
2017 * RETURNS
2018 * Success: TRUE
2019 * Failure: FALSE
2021 BOOL WINAPI DECLSPEC_HOTPATCH ShowScrollBar(HWND hwnd, INT nBar, BOOL fShow)
2023 if ( !hwnd )
2024 return FALSE;
2026 SCROLL_ShowScrollBar( hwnd, nBar, (nBar == SB_VERT) ? 0 : fShow,
2027 (nBar == SB_HORZ) ? 0 : fShow );
2028 return TRUE;
2032 /*************************************************************************
2033 * EnableScrollBar (USER32.@)
2035 * Enables or disables the scroll bars.
2037 BOOL WINAPI DECLSPEC_HOTPATCH EnableScrollBar( HWND hwnd, UINT nBar, UINT flags )
2039 BOOL bFineWithMe;
2040 SCROLLBAR_INFO *infoPtr;
2042 flags &= ESB_DISABLE_BOTH;
2044 if (nBar == SB_BOTH)
2046 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, SB_VERT, TRUE ))) return FALSE;
2047 if (!(bFineWithMe = (infoPtr->flags == flags)) )
2049 infoPtr->flags = flags;
2050 SCROLL_RefreshScrollBar( hwnd, SB_VERT, TRUE, TRUE );
2052 nBar = SB_HORZ;
2054 else
2055 bFineWithMe = nBar != SB_CTL;
2057 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, TRUE ))) return FALSE;
2058 if (bFineWithMe && infoPtr->flags == flags) return FALSE;
2059 infoPtr->flags = flags;
2061 if (nBar == SB_CTL && (flags == ESB_DISABLE_BOTH || flags == ESB_ENABLE_BOTH))
2062 EnableWindow(hwnd, flags == ESB_ENABLE_BOTH);
2064 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
2065 return TRUE;