Add a real stub for Advpack.extract.
[wine/wine64.git] / dlls / user / scroll.c
blob895ae4e93fca22b02caeee458337b3c29c0653eb
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * NOTES
23 * This code was audited for completeness against the documented features
24 * of Comctl32.dll version 6.0 on Oct. 8, 2004, by Dimitrie O. Paun.
26 * Unless otherwise noted, we believe this code to be complete, as per
27 * the specification mentioned above.
28 * If you discover missing features, or bugs, please note them below.
31 #include <stdarg.h>
33 #include "windef.h"
34 #include "winbase.h"
35 #include "wingdi.h"
36 #include "wine/winuser16.h"
37 #include "controls.h"
38 #include "win.h"
39 #include "wine/debug.h"
40 #include "user_private.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(scroll);
44 typedef struct
46 INT curVal; /* Current scroll-bar value */
47 INT minVal; /* Minimum scroll-bar value */
48 INT maxVal; /* Maximum scroll-bar value */
49 INT page; /* Page size of scroll bar (Win32) */
50 UINT flags; /* EnableScrollBar flags */
51 } SCROLLBAR_INFO, *LPSCROLLBAR_INFO;
54 /* Minimum size of the rectangle between the arrows */
55 #define SCROLL_MIN_RECT 4
57 /* Minimum size of the thumb in pixels */
58 #define SCROLL_MIN_THUMB 6
60 /* Overlap between arrows and thumb */
61 #define SCROLL_ARROW_THUMB_OVERLAP 0
63 /* Delay (in ms) before first repetition when holding the button down */
64 #define SCROLL_FIRST_DELAY 200
66 /* Delay (in ms) between scroll repetitions */
67 #define SCROLL_REPEAT_DELAY 50
69 /* Scroll timer id */
70 #define SCROLL_TIMER 0
72 /* Scroll-bar hit testing */
73 enum SCROLL_HITTEST
75 SCROLL_NOWHERE, /* Outside the scroll bar */
76 SCROLL_TOP_ARROW, /* Top or left arrow */
77 SCROLL_TOP_RECT, /* Rectangle between the top arrow and the thumb */
78 SCROLL_THUMB, /* Thumb rectangle */
79 SCROLL_BOTTOM_RECT, /* Rectangle between the thumb and the bottom arrow */
80 SCROLL_BOTTOM_ARROW /* Bottom or right arrow */
83 /* What to do after SCROLL_SetScrollInfo() */
84 #define SA_SSI_HIDE 0x0001
85 #define SA_SSI_SHOW 0x0002
86 #define SA_SSI_REFRESH 0x0004
87 #define SA_SSI_REPAINT_ARROWS 0x0008
89 /* Thumb-tracking info */
90 static HWND SCROLL_TrackingWin = 0;
91 static INT SCROLL_TrackingBar = 0;
92 static INT SCROLL_TrackingPos = 0;
93 static INT SCROLL_TrackingVal = 0;
94 /* Hit test code of the last button-down event */
95 static enum SCROLL_HITTEST SCROLL_trackHitTest;
96 static BOOL SCROLL_trackVertical;
98 /* Is the moving thumb being displayed? */
99 static BOOL SCROLL_MovingThumb = FALSE;
101 /* Local functions */
102 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar,
103 BOOL fShowH, BOOL fShowV );
104 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar,
105 const SCROLLINFO *info, BOOL bRedraw );
106 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
107 RECT *rect, INT arrowSize,
108 INT thumbSize, INT thumbPos,
109 UINT flags, BOOL vertical,
110 BOOL top_selected, BOOL bottom_selected );
111 static LRESULT WINAPI ScrollBarWndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
114 /*********************************************************************
115 * scrollbar class descriptor
117 const struct builtin_class_descr SCROLL_builtin_class =
119 "ScrollBar", /* name */
120 CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC, /* style */
121 NULL, /* procA (winproc is Unicode only) */
122 ScrollBarWndProc, /* procW */
123 sizeof(SCROLLBAR_INFO), /* extra */
124 IDC_ARROW, /* cursor */
125 0 /* brush */
128 /***********************************************************************
129 * SCROLL_ScrollInfoValid
131 * Determine if the supplied SCROLLINFO struct is valid.
132 * info [in] The SCROLLINFO struct to be tested
134 inline static BOOL SCROLL_ScrollInfoValid( LPCSCROLLINFO info )
136 return !(info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)
137 || (info->cbSize != sizeof(*info)
138 && info->cbSize != sizeof(*info) - sizeof(info->nTrackPos)));
142 /***********************************************************************
143 * SCROLL_GetInternalInfo
145 * Returns pointer to internal SCROLLBAR_INFO structure for nBar
146 * or NULL if failed (f.i. scroll bar does not exist yet)
147 * If alloc is TRUE and the struct does not exist yet, create it.
149 static SCROLLBAR_INFO *SCROLL_GetInternalInfo( HWND hwnd, INT nBar, BOOL alloc )
151 SCROLLBAR_INFO *infoPtr = NULL;
152 WND *wndPtr = WIN_GetPtr( hwnd );
154 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return NULL;
155 switch(nBar)
157 case SB_HORZ: infoPtr = (SCROLLBAR_INFO *)wndPtr->pHScroll; break;
158 case SB_VERT: infoPtr = (SCROLLBAR_INFO *)wndPtr->pVScroll; break;
159 case SB_CTL: infoPtr = (SCROLLBAR_INFO *)wndPtr->wExtra; break;
160 case SB_BOTH: WARN("with SB_BOTH"); break;
163 if (!infoPtr && alloc)
165 if (nBar != SB_HORZ && nBar != SB_VERT)
166 WARN("Cannot initialize nBar=%d\n",nBar);
167 else if ((infoPtr = HeapAlloc( GetProcessHeap(), 0, sizeof(SCROLLBAR_INFO) )))
169 /* Set default values */
170 infoPtr->minVal = infoPtr->curVal = infoPtr->page = 0;
171 /* From MSDN: max for a standard scroll bar is 100 by default. */
172 infoPtr->maxVal = 100;
173 /* Scroll bar is enabled by default after create */
174 infoPtr->flags = ESB_ENABLE_BOTH;
175 if (nBar == SB_HORZ) wndPtr->pHScroll = infoPtr;
176 else wndPtr->pVScroll = infoPtr;
179 WIN_ReleasePtr( wndPtr );
180 return infoPtr;
184 /***********************************************************************
185 * SCROLL_GetScrollBarRect
187 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
188 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
189 * 'arrowSize' returns the width or height of an arrow (depending on
190 * the orientation of the scrollbar), 'thumbSize' returns the size of
191 * the thumb, and 'thumbPos' returns the position of the thumb
192 * relative to the left or to the top.
193 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
195 static BOOL SCROLL_GetScrollBarRect( HWND hwnd, INT nBar, RECT *lprect,
196 INT *arrowSize, INT *thumbSize,
197 INT *thumbPos )
199 INT pixels;
200 BOOL vertical;
201 WND *wndPtr = WIN_GetPtr( hwnd );
203 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
205 switch(nBar)
207 case SB_HORZ:
208 lprect->left = wndPtr->rectClient.left - wndPtr->rectWindow.left;
209 lprect->top = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
210 lprect->right = wndPtr->rectClient.right - wndPtr->rectWindow.left;
211 lprect->bottom = lprect->top + GetSystemMetrics(SM_CYHSCROLL);
212 if(wndPtr->dwStyle & WS_BORDER) {
213 lprect->left--;
214 lprect->right++;
215 } else if(wndPtr->dwStyle & WS_VSCROLL)
216 lprect->right++;
217 vertical = FALSE;
218 break;
220 case SB_VERT:
221 if((wndPtr->dwExStyle & WS_EX_LEFTSCROLLBAR) != 0)
222 lprect->left = wndPtr->rectClient.left - wndPtr->rectWindow.left - GetSystemMetrics(SM_CXVSCROLL);
223 else
224 lprect->left = wndPtr->rectClient.right - wndPtr->rectWindow.left;
225 lprect->top = wndPtr->rectClient.top - wndPtr->rectWindow.top;
226 lprect->right = lprect->left + GetSystemMetrics(SM_CXVSCROLL);
227 lprect->bottom = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
228 if(wndPtr->dwStyle & WS_BORDER) {
229 lprect->top--;
230 lprect->bottom++;
231 } else if(wndPtr->dwStyle & WS_HSCROLL)
232 lprect->bottom++;
233 vertical = TRUE;
234 break;
236 case SB_CTL:
237 GetClientRect( hwnd, lprect );
238 vertical = ((wndPtr->dwStyle & SBS_VERT) != 0);
239 break;
241 default:
242 WIN_ReleasePtr( wndPtr );
243 return FALSE;
246 if (vertical) pixels = lprect->bottom - lprect->top;
247 else pixels = lprect->right - lprect->left;
249 if (pixels <= 2*GetSystemMetrics(SM_CXVSCROLL) + SCROLL_MIN_RECT)
251 if (pixels > SCROLL_MIN_RECT)
252 *arrowSize = (pixels - SCROLL_MIN_RECT) / 2;
253 else
254 *arrowSize = 0;
255 *thumbPos = *thumbSize = 0;
257 else
259 SCROLLBAR_INFO *info = SCROLL_GetInternalInfo( hwnd, nBar, FALSE );
260 if (!info)
262 WARN("called for missing scroll bar");
263 return FALSE;
265 *arrowSize = GetSystemMetrics(SM_CXVSCROLL);
266 pixels -= (2 * (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP));
268 if (info->page)
270 *thumbSize = MulDiv(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;
281 else
283 INT max = info->maxVal - max( info->page-1, 0 );
284 if (info->minVal >= max)
285 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
286 else
287 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP
288 + MulDiv(pixels, (info->curVal-info->minVal),(max - info->minVal));
291 WIN_ReleasePtr( wndPtr );
292 return vertical;
296 /***********************************************************************
297 * SCROLL_GetThumbVal
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 )
305 INT thumbSize;
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;
311 if (infoPtr->page)
313 thumbSize = MulDiv(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 /***********************************************************************
329 * SCROLL_PtInRectEx
331 static BOOL SCROLL_PtInRectEx( LPRECT lpRect, POINT pt, BOOL vertical )
333 RECT rect = *lpRect;
335 if (vertical)
337 rect.left -= lpRect->right - lpRect->left;
338 rect.right += lpRect->right - lpRect->left;
340 else
342 rect.top -= lpRect->bottom - lpRect->top;
343 rect.bottom += lpRect->bottom - lpRect->top;
345 return PtInRect( &rect, pt );
348 /***********************************************************************
349 * SCROLL_ClipPos
351 static POINT SCROLL_ClipPos( LPRECT lpRect, POINT pt )
353 if( pt.x < lpRect->left )
354 pt.x = lpRect->left;
355 else
356 if( pt.x > lpRect->right )
357 pt.x = lpRect->right;
359 if( pt.y < lpRect->top )
360 pt.y = lpRect->top;
361 else
362 if( pt.y > lpRect->bottom )
363 pt.y = lpRect->bottom;
365 return pt;
369 /***********************************************************************
370 * SCROLL_HitTest
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;
378 RECT rect;
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;
386 if (vertical)
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;
391 pt.y -= rect.top;
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;
400 pt.x -= rect.left;
401 if (pt.x < thumbPos) return SCROLL_TOP_RECT;
402 if (pt.x >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
404 return SCROLL_THUMB;
408 /***********************************************************************
409 * SCROLL_DrawArrows
411 * Draw the scroll bar arrows.
413 static void SCROLL_DrawArrows( HDC hdc, SCROLLBAR_INFO *infoPtr,
414 RECT *rect, INT arrowSize, BOOL vertical,
415 BOOL top_pressed, BOOL bottom_pressed )
417 RECT r;
419 r = *rect;
420 if( vertical )
421 r.bottom = r.top + arrowSize;
422 else
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 ) );
430 r = *rect;
431 if( vertical )
432 r.top = r.bottom-arrowSize;
433 else
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_DrawMovingThumb( HDC hdc, RECT *rect, BOOL vertical,
443 INT arrowSize, INT thumbSize )
445 INT pos = SCROLL_TrackingPos;
446 INT max_size;
448 if( vertical )
449 max_size = rect->bottom - rect->top;
450 else
451 max_size = rect->right - rect->left;
453 max_size -= (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) + thumbSize;
455 if( pos < (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) )
456 pos = (arrowSize-SCROLL_ARROW_THUMB_OVERLAP);
457 else if( pos > max_size )
458 pos = max_size;
460 SCROLL_DrawInterior_9x( SCROLL_TrackingWin, hdc, SCROLL_TrackingBar,
461 rect, arrowSize, thumbSize, pos,
462 0, vertical, FALSE, FALSE );
464 SCROLL_MovingThumb = !SCROLL_MovingThumb;
467 /***********************************************************************
468 * SCROLL_DrawInterior
470 * Draw the scroll bar interior (everything except the arrows).
472 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
473 RECT *rect, INT arrowSize,
474 INT thumbSize, INT thumbPos,
475 UINT flags, BOOL vertical,
476 BOOL top_selected, BOOL bottom_selected )
478 RECT r;
479 HPEN hSavePen;
480 HBRUSH hSaveBrush,hBrush;
482 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
483 * The window-owned scrollbars need to call DEFWND_ControlColor
484 * to correctly setup default scrollbar colors
486 if (nBar == SB_CTL)
488 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
489 (WPARAM)hdc,(LPARAM)hwnd);
491 else
493 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
496 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
497 hSaveBrush = SelectObject( hdc, hBrush );
499 /* Calculate the scroll rectangle */
500 r = *rect;
501 if (vertical)
503 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
504 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
506 else
508 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
509 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
512 /* Draw the scroll rectangles and thumb */
513 if (!thumbPos) /* No thumb to draw */
515 PatBlt( hdc, r.left, r.top,
516 r.right - r.left, r.bottom - r.top,
517 PATCOPY );
519 /* cleanup and return */
520 SelectObject( hdc, hSavePen );
521 SelectObject( hdc, hSaveBrush );
522 return;
525 if (vertical)
527 PatBlt( hdc, r.left, r.top,
528 r.right - r.left,
529 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
530 top_selected ? 0x0f0000 : PATCOPY );
531 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
532 PatBlt( hdc, r.left, r.top + thumbSize,
533 r.right - r.left,
534 r.bottom - r.top - thumbSize,
535 bottom_selected ? 0x0f0000 : PATCOPY );
536 r.bottom = r.top + thumbSize;
538 else /* horizontal */
540 PatBlt( hdc, r.left, r.top,
541 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
542 r.bottom - r.top,
543 top_selected ? 0x0f0000 : PATCOPY );
544 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
545 PatBlt( hdc, r.left + thumbSize, r.top,
546 r.right - r.left - thumbSize,
547 r.bottom - r.top,
548 bottom_selected ? 0x0f0000 : PATCOPY );
549 r.right = r.left + thumbSize;
552 /* Draw the thumb */
553 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT | BF_MIDDLE );
555 /* cleanup */
556 SelectObject( hdc, hSavePen );
557 SelectObject( hdc, hSaveBrush );
561 static void SCROLL_DrawInterior( HWND hwnd, HDC hdc, INT nBar,
562 RECT *rect, INT arrowSize,
563 INT thumbSize, INT thumbPos,
564 UINT flags, BOOL vertical,
565 BOOL top_selected, BOOL bottom_selected )
567 RECT r;
568 HPEN hSavePen;
569 HBRUSH hSaveBrush,hBrush;
570 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
572 if (Save_SCROLL_MovingThumb &&
573 (SCROLL_TrackingWin == hwnd) &&
574 (SCROLL_TrackingBar == nBar))
575 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
577 /* Select the correct brush and pen */
579 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
580 * The window-owned scrollbars need to call DEFWND_ControlColor
581 * to correctly setup default scrollbar colors
583 if (nBar == SB_CTL) {
584 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
585 (WPARAM)hdc,(LPARAM)hwnd);
586 } else {
587 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
589 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
590 hSaveBrush = SelectObject( hdc, hBrush );
592 /* Calculate the scroll rectangle */
594 r = *rect;
595 if (vertical)
597 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
598 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
600 else
602 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
603 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
606 /* Draw the scroll bar frame */
608 /* Draw the scroll rectangles and thumb */
610 if (!thumbPos) /* No thumb to draw */
612 PatBlt( hdc, r.left, r.top, r.right - r.left, r.bottom - r.top, PATCOPY );
614 /* cleanup and return */
615 SelectObject( hdc, hSavePen );
616 SelectObject( hdc, hSaveBrush );
617 return;
620 if (vertical)
622 PatBlt( hdc, r.left, r.top, r.right - r.left,
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, r.right - r.left,
627 r.bottom - r.top - thumbSize,
628 bottom_selected ? 0x0f0000 : PATCOPY );
629 r.bottom = r.top + thumbSize;
631 else /* horizontal */
633 PatBlt( hdc, r.left, r.top,
634 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
635 r.bottom - r.top, top_selected ? 0x0f0000 : PATCOPY );
636 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
637 PatBlt( hdc, r.left + thumbSize, r.top, r.right - r.left - thumbSize,
638 r.bottom - r.top, bottom_selected ? 0x0f0000 : PATCOPY );
639 r.right = r.left + thumbSize;
642 /* Draw the thumb */
644 SelectObject( hdc, GetSysColorBrush(COLOR_BTNFACE) );
645 Rectangle( hdc, r.left+1, r.top+1, r.right-1, r.bottom-1 );
646 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT );
648 if (Save_SCROLL_MovingThumb &&
649 (SCROLL_TrackingWin == hwnd) &&
650 (SCROLL_TrackingBar == nBar))
651 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
653 /* cleanup */
654 SelectObject( hdc, hSavePen );
655 SelectObject( hdc, hSaveBrush );
659 /***********************************************************************
660 * SCROLL_DrawScrollBar
662 * Redraw the whole scrollbar.
664 void SCROLL_DrawScrollBar( HWND hwnd, HDC hdc, INT nBar,
665 BOOL arrows, BOOL interior )
667 INT arrowSize, thumbSize, thumbPos;
668 RECT rect;
669 BOOL vertical;
670 SCROLLBAR_INFO *infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, TRUE );
671 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
672 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
674 if (!(hwnd = WIN_GetFullHandle( hwnd ))) return;
676 if (!infoPtr ||
677 ((nBar == SB_VERT) && !(style & WS_VSCROLL)) ||
678 ((nBar == SB_HORZ) && !(style & WS_HSCROLL))) return;
679 if (!WIN_IsWindowDrawable( hwnd, FALSE )) return;
681 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
682 &arrowSize, &thumbSize, &thumbPos );
684 /* do not draw if the scrollbar rectangle is empty */
685 if(IsRectEmpty(&rect)) return;
687 if (Save_SCROLL_MovingThumb &&
688 (SCROLL_TrackingWin == hwnd) &&
689 (SCROLL_TrackingBar == nBar))
690 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
692 /* Draw the arrows */
694 if (arrows && arrowSize)
696 if( vertical == SCROLL_trackVertical && GetCapture() == hwnd )
697 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
698 (SCROLL_trackHitTest == SCROLL_TOP_ARROW),
699 (SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW) );
700 else
701 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
702 FALSE, FALSE );
704 if( interior )
705 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
706 thumbPos, infoPtr->flags, vertical, FALSE, FALSE );
708 if (Save_SCROLL_MovingThumb &&
709 (SCROLL_TrackingWin == hwnd) &&
710 (SCROLL_TrackingBar == nBar))
711 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
713 /* if scroll bar has focus, reposition the caret */
714 if(hwnd==GetFocus() && (nBar==SB_CTL))
716 if (!vertical)
718 SetCaretPos(thumbPos+1, rect.top+1);
720 else
722 SetCaretPos(rect.top+1, thumbPos+1);
727 /***********************************************************************
728 * SCROLL_DrawSizeGrip
730 * Draw the size grip.
732 static void SCROLL_DrawSizeGrip( HWND hwnd, HDC hdc)
734 RECT rc;
736 GetClientRect( hwnd, &rc );
737 FillRect( hdc, &rc, GetSysColorBrush(COLOR_SCROLLBAR) );
738 rc.left = max( rc.left, rc.right - GetSystemMetrics(SM_CXVSCROLL) - 1 );
739 rc.top = max( rc.top, rc.bottom - GetSystemMetrics(SM_CYHSCROLL) - 1 );
740 DrawFrameControl( hdc, &rc, DFC_SCROLL, DFCS_SCROLLSIZEGRIP );
744 /***********************************************************************
745 * SCROLL_RefreshScrollBar
747 * Repaint the scroll bar interior after a SetScrollRange() or
748 * SetScrollPos() call.
750 static void SCROLL_RefreshScrollBar( HWND hwnd, INT nBar,
751 BOOL arrows, BOOL interior )
753 HDC hdc = GetDCEx( hwnd, 0,
754 DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW) );
755 if (!hdc) return;
757 SCROLL_DrawScrollBar( hwnd, hdc, nBar, arrows, interior );
758 ReleaseDC( hwnd, hdc );
762 /***********************************************************************
763 * SCROLL_HandleKbdEvent
765 * Handle a keyboard event (only for SB_CTL scrollbars with focus).
767 * PARAMS
768 * hwnd [I] Handle of window with scrollbar(s)
769 * wParam [I] Variable input including enable state
770 * lParam [I] Variable input including input point
772 static void SCROLL_HandleKbdEvent(HWND hwnd, WPARAM wParam, LPARAM lParam)
774 TRACE("hwnd=%p wParam=%d lParam=%ld\n", hwnd, wParam, lParam);
776 /* hide caret on first KEYDOWN to prevent flicker */
777 if ((lParam & PFD_DOUBLEBUFFER_DONTCARE) == 0)
778 HideCaret(hwnd);
780 switch(wParam)
782 case VK_PRIOR: wParam = SB_PAGEUP; break;
783 case VK_NEXT: wParam = SB_PAGEDOWN; break;
784 case VK_HOME: wParam = SB_TOP; break;
785 case VK_END: wParam = SB_BOTTOM; break;
786 case VK_UP: wParam = SB_LINEUP; break;
787 case VK_DOWN: wParam = SB_LINEDOWN; break;
788 case VK_LEFT: wParam = SB_LINEUP; break;
789 case VK_RIGHT: wParam = SB_LINEDOWN; break;
790 default: return;
792 SendMessageW(GetParent(hwnd),
793 ((GetWindowLongW( hwnd, GWL_STYLE ) & SBS_VERT) ?
794 WM_VSCROLL : WM_HSCROLL), wParam, (LPARAM)hwnd);
798 /***********************************************************************
799 * SCROLL_HandleScrollEvent
801 * Handle a mouse or timer event for the scrollbar.
802 * 'pt' is the location of the mouse event in client (for SB_CTL) or
803 * windows coordinates.
805 static void SCROLL_HandleScrollEvent( HWND hwnd, INT nBar, UINT msg, POINT pt)
807 /* Previous mouse position for timer events */
808 static POINT prevPt;
809 /* Thumb position when tracking started. */
810 static UINT trackThumbPos;
811 /* Position in the scroll-bar of the last button-down event. */
812 static INT lastClickPos;
813 /* Position in the scroll-bar of the last mouse event. */
814 static INT lastMousePos;
816 enum SCROLL_HITTEST hittest;
817 HWND hwndOwner, hwndCtl;
818 BOOL vertical;
819 INT arrowSize, thumbSize, thumbPos;
820 RECT rect;
821 HDC hdc;
823 SCROLLBAR_INFO *infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, FALSE );
824 if (!infoPtr) return;
825 if ((SCROLL_trackHitTest == SCROLL_NOWHERE) && (msg != WM_LBUTTONDOWN))
826 return;
828 if (nBar == SB_CTL && (GetWindowLongW( hwnd, GWL_STYLE ) & (SBS_SIZEGRIP | SBS_SIZEBOX)))
830 switch(msg)
832 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
833 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
834 SetCapture( hwnd );
835 prevPt = pt;
836 SCROLL_trackHitTest = hittest = SCROLL_THUMB;
837 break;
838 case WM_MOUSEMOVE:
839 GetClientRect(GetParent(GetParent(hwnd)),&rect);
840 prevPt = pt;
841 break;
842 case WM_LBUTTONUP:
843 ReleaseCapture();
844 SCROLL_trackHitTest = hittest = SCROLL_NOWHERE;
845 if (hwnd==GetFocus()) ShowCaret(hwnd);
846 break;
847 case WM_SYSTIMER:
848 pt = prevPt;
849 break;
851 return;
854 hdc = GetDCEx( hwnd, 0, DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW));
855 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
856 &arrowSize, &thumbSize, &thumbPos );
857 hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd) : hwnd;
858 hwndCtl = (nBar == SB_CTL) ? hwnd : 0;
860 switch(msg)
862 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
863 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
864 SCROLL_trackVertical = vertical;
865 SCROLL_trackHitTest = hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
866 lastClickPos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
867 lastMousePos = lastClickPos;
868 trackThumbPos = thumbPos;
869 prevPt = pt;
870 if (nBar == SB_CTL && (GetWindowLongW(hwnd, GWL_STYLE) & WS_TABSTOP)) SetFocus( hwnd );
871 SetCapture( hwnd );
872 break;
874 case WM_MOUSEMOVE:
875 hittest = SCROLL_HitTest( hwnd, nBar, pt, TRUE );
876 prevPt = pt;
877 break;
879 case WM_LBUTTONUP:
880 hittest = SCROLL_NOWHERE;
881 ReleaseCapture();
882 /* if scrollbar has focus, show back caret */
883 if (hwnd==GetFocus()) ShowCaret(hwnd);
884 break;
886 case WM_SYSTIMER:
887 pt = prevPt;
888 hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
889 break;
891 default:
892 return; /* Should never happen */
895 TRACE("Event: hwnd=%p bar=%d msg=%s pt=%ld,%ld hit=%d\n",
896 hwnd, nBar, SPY_GetMsgName(msg,hwnd), pt.x, pt.y, hittest );
898 switch(SCROLL_trackHitTest)
900 case SCROLL_NOWHERE: /* No tracking in progress */
901 break;
903 case SCROLL_TOP_ARROW:
904 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
905 (hittest == SCROLL_trackHitTest), FALSE );
906 if (hittest == SCROLL_trackHitTest)
908 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
910 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
911 SB_LINEUP, (LPARAM)hwndCtl );
914 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
915 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
916 (TIMERPROC)0 );
918 else KillSystemTimer( hwnd, SCROLL_TIMER );
919 break;
921 case SCROLL_TOP_RECT:
922 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
923 thumbPos, infoPtr->flags, vertical,
924 (hittest == SCROLL_trackHitTest), FALSE );
925 if (hittest == SCROLL_trackHitTest)
927 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
929 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
930 SB_PAGEUP, (LPARAM)hwndCtl );
932 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
933 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
934 (TIMERPROC)0 );
936 else KillSystemTimer( hwnd, SCROLL_TIMER );
937 break;
939 case SCROLL_THUMB:
940 if (msg == WM_LBUTTONDOWN)
942 SCROLL_TrackingWin = hwnd;
943 SCROLL_TrackingBar = nBar;
944 SCROLL_TrackingPos = trackThumbPos + lastMousePos - lastClickPos;
945 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
946 vertical,
947 SCROLL_TrackingPos );
948 if (!SCROLL_MovingThumb)
949 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
951 else if (msg == WM_LBUTTONUP)
953 if (SCROLL_MovingThumb)
954 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
955 SCROLL_TrackingWin = 0;
956 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
957 thumbPos, infoPtr->flags, vertical,
958 FALSE, FALSE );
960 else /* WM_MOUSEMOVE */
962 UINT pos;
964 if (!SCROLL_PtInRectEx( &rect, pt, vertical )) pos = lastClickPos;
965 else
967 pt = SCROLL_ClipPos( &rect, pt );
968 pos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
970 if ( (pos != lastMousePos) || (!SCROLL_MovingThumb) )
972 if (SCROLL_MovingThumb)
973 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
974 arrowSize, thumbSize );
975 lastMousePos = pos;
976 SCROLL_TrackingPos = trackThumbPos + pos - lastClickPos;
977 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
978 vertical,
979 SCROLL_TrackingPos );
980 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
981 MAKEWPARAM( SB_THUMBTRACK, SCROLL_TrackingVal),
982 (LPARAM)hwndCtl );
983 if (!SCROLL_MovingThumb)
984 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
985 arrowSize, thumbSize );
988 break;
990 case SCROLL_BOTTOM_RECT:
991 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
992 thumbPos, infoPtr->flags, vertical,
993 FALSE, (hittest == SCROLL_trackHitTest) );
994 if (hittest == SCROLL_trackHitTest)
996 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
998 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
999 SB_PAGEDOWN, (LPARAM)hwndCtl );
1001 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1002 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1003 (TIMERPROC)0 );
1005 else KillSystemTimer( hwnd, SCROLL_TIMER );
1006 break;
1008 case SCROLL_BOTTOM_ARROW:
1009 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
1010 FALSE, (hittest == SCROLL_trackHitTest) );
1011 if (hittest == SCROLL_trackHitTest)
1013 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1015 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1016 SB_LINEDOWN, (LPARAM)hwndCtl );
1019 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1020 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1021 (TIMERPROC)0 );
1023 else KillSystemTimer( hwnd, SCROLL_TIMER );
1024 break;
1027 if (msg == WM_LBUTTONDOWN)
1030 if (hittest == SCROLL_THUMB)
1032 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1033 trackThumbPos + lastMousePos - lastClickPos );
1034 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1035 MAKEWPARAM( SB_THUMBTRACK, val ), (LPARAM)hwndCtl );
1039 if (msg == WM_LBUTTONUP)
1041 hittest = SCROLL_trackHitTest;
1042 SCROLL_trackHitTest = SCROLL_NOWHERE; /* Terminate tracking */
1044 if (hittest == SCROLL_THUMB)
1046 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1047 trackThumbPos + lastMousePos - lastClickPos );
1048 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1049 MAKEWPARAM( SB_THUMBPOSITION, val ), (LPARAM)hwndCtl );
1051 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1052 SB_ENDSCROLL, (LPARAM)hwndCtl );
1055 ReleaseDC( hwnd, hdc );
1059 /***********************************************************************
1060 * SCROLL_TrackScrollBar
1062 * Track a mouse button press on a scroll-bar.
1063 * pt is in screen-coordinates for non-client scroll bars.
1065 void SCROLL_TrackScrollBar( HWND hwnd, INT scrollbar, POINT pt )
1067 MSG msg;
1068 INT xoffset = 0, yoffset = 0;
1070 if (scrollbar != SB_CTL)
1072 WND *wndPtr = WIN_GetPtr( hwnd );
1073 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return;
1074 xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
1075 yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
1076 WIN_ReleasePtr( wndPtr );
1077 ScreenToClient( hwnd, &pt );
1078 pt.x += xoffset;
1079 pt.y += yoffset;
1082 SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt );
1086 if (!GetMessageW( &msg, 0, 0, 0 )) break;
1087 if (CallMsgFilterW( &msg, MSGF_SCROLLBAR )) continue;
1088 if (msg.message == WM_LBUTTONUP ||
1089 msg.message == WM_MOUSEMOVE ||
1090 (msg.message == WM_SYSTIMER && msg.wParam == SCROLL_TIMER))
1092 pt.x = (short)LOWORD(msg.lParam) + xoffset;
1093 pt.y = (short)HIWORD(msg.lParam) + yoffset;
1094 SCROLL_HandleScrollEvent( hwnd, scrollbar, msg.message, pt );
1096 else
1098 TranslateMessage( &msg );
1099 DispatchMessageW( &msg );
1101 if (!IsWindow( hwnd ))
1103 ReleaseCapture();
1104 break;
1106 } while (msg.message != WM_LBUTTONUP);
1110 /***********************************************************************
1111 * SCROLL_CreateScrollBar
1113 * Create a scroll bar
1115 * PARAMS
1116 * hwnd [I] Handle of window with scrollbar(s)
1117 * lpCreate [I] The style and place of the scroll bar
1119 static void SCROLL_CreateScrollBar(HWND hwnd, LPCREATESTRUCTW lpCreate)
1121 LPSCROLLBAR_INFO info = SCROLL_GetInternalInfo(hwnd, SB_CTL, TRUE);
1122 if (!info) return;
1124 TRACE("hwnd=%p lpCreate=%p\n", hwnd, lpCreate);
1126 if (lpCreate->style & WS_DISABLED)
1128 info->flags = ESB_DISABLE_BOTH;
1129 TRACE("Created WS_DISABLED scrollbar\n");
1133 if (lpCreate->style & (SBS_SIZEGRIP | SBS_SIZEBOX))
1135 if (lpCreate->style & SBS_SIZEBOXTOPLEFTALIGN)
1136 MoveWindow( hwnd, lpCreate->x, lpCreate->y, GetSystemMetrics(SM_CXVSCROLL)+1,
1137 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1138 else if(lpCreate->style & SBS_SIZEBOXBOTTOMRIGHTALIGN)
1139 MoveWindow( hwnd, lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1140 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1141 GetSystemMetrics(SM_CXVSCROLL)+1,
1142 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1144 else if (lpCreate->style & SBS_VERT)
1146 if (lpCreate->style & SBS_LEFTALIGN)
1147 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1148 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1149 else if (lpCreate->style & SBS_RIGHTALIGN)
1150 MoveWindow( hwnd,
1151 lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1152 lpCreate->y,
1153 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1155 else /* SBS_HORZ */
1157 if (lpCreate->style & SBS_TOPALIGN)
1158 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1159 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1160 else if (lpCreate->style & SBS_BOTTOMALIGN)
1161 MoveWindow( hwnd,
1162 lpCreate->x,
1163 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1164 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1169 /*************************************************************************
1170 * SCROLL_GetScrollInfo
1172 * Internal helper for the API function
1174 * PARAMS
1175 * hwnd [I] Handle of window with scrollbar(s)
1176 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1177 * info [IO] fMask specifies which values to retrieve
1179 * RETURNS
1180 * FALSE if requested field not filled (f.i. scroll bar does not exist)
1182 static BOOL SCROLL_GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1184 LPSCROLLBAR_INFO infoPtr;
1186 /* handle invalid data structure */
1187 if (!SCROLL_ScrollInfoValid(info)
1188 || !(infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE)))
1189 return FALSE;
1191 /* fill in the desired scroll info structure */
1192 if (info->fMask & SIF_PAGE) info->nPage = infoPtr->page;
1193 if (info->fMask & SIF_POS) info->nPos = infoPtr->curVal;
1194 if ((info->fMask & SIF_TRACKPOS) && (info->cbSize == sizeof(*info)))
1195 info->nTrackPos = (SCROLL_TrackingWin == WIN_GetFullHandle(hwnd)) ? SCROLL_TrackingVal : infoPtr->curVal;
1196 if (info->fMask & SIF_RANGE)
1198 info->nMin = infoPtr->minVal;
1199 info->nMax = infoPtr->maxVal;
1202 return (info->fMask & SIF_ALL) != 0;
1206 /*************************************************************************
1207 * SCROLL_GetScrollBarInfo
1209 * Internal helper for the API function
1211 * PARAMS
1212 * hwnd [I] Handle of window with scrollbar(s)
1213 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1214 * info [IO] cbSize specifies the size of the structure
1216 * RETURNS
1217 * FALSE if failed
1219 static BOOL SCROLL_GetScrollBarInfo(HWND hwnd, LONG idObject, LPSCROLLBARINFO info)
1221 LPSCROLLBAR_INFO infoPtr;
1222 INT nBar;
1223 INT nDummy;
1224 DWORD style = GetWindowLongW(hwnd, GWL_STYLE);
1225 BOOL pressed;
1227 switch (idObject)
1229 case OBJID_CLIENT: nBar = SB_CTL; break;
1230 case OBJID_HSCROLL: nBar = SB_HORZ; break;
1231 case OBJID_VSCROLL: nBar = SB_VERT; break;
1232 default: return FALSE;
1235 /* handle invalid data structure */
1236 if (info->cbSize != sizeof(*info))
1237 return FALSE;
1239 SCROLL_GetScrollBarRect(hwnd, nBar, &info->rcScrollBar, &nDummy,
1240 &info->dxyLineButton, &info->xyThumbTop);
1242 info->xyThumbBottom = info->xyThumbTop + info->dxyLineButton;
1244 infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, TRUE);
1246 /* Scroll bar state */
1247 info->rgstate[0] = 0;
1248 if ((nBar == SB_HORZ && !(style & WS_HSCROLL))
1249 || (nBar == SB_VERT && !(style & WS_VSCROLL)))
1250 info->rgstate[0] |= STATE_SYSTEM_INVISIBLE;
1251 if (infoPtr->minVal >= infoPtr->maxVal - max(infoPtr->page - 1, 0))
1253 if (!(info->rgstate[0] & STATE_SYSTEM_INVISIBLE))
1254 info->rgstate[0] |= STATE_SYSTEM_UNAVAILABLE;
1255 else
1256 info->rgstate[0] |= STATE_SYSTEM_OFFSCREEN;
1258 if (nBar == SB_CTL && !IsWindowEnabled(hwnd))
1259 info->rgstate[0] |= STATE_SYSTEM_UNAVAILABLE;
1261 pressed = ((nBar == SB_VERT) == SCROLL_trackVertical && GetCapture() == hwnd);
1263 /* Top/left arrow button state. MSDN says top/right, but I don't believe it */
1264 info->rgstate[1] = 0;
1265 if (pressed && SCROLL_trackHitTest == SCROLL_TOP_ARROW)
1266 info->rgstate[1] |= STATE_SYSTEM_PRESSED;
1267 if (infoPtr->flags & ESB_DISABLE_LTUP)
1268 info->rgstate[1] |= STATE_SYSTEM_UNAVAILABLE;
1270 /* Page up/left region state. MSDN says up/right, but I don't believe it */
1271 info->rgstate[2] = 0;
1272 if (infoPtr->curVal == infoPtr->minVal)
1273 info->rgstate[2] |= STATE_SYSTEM_INVISIBLE;
1274 if (pressed && SCROLL_trackHitTest == SCROLL_TOP_RECT)
1275 info->rgstate[2] |= STATE_SYSTEM_PRESSED;
1277 /* Thumb state */
1278 info->rgstate[3] = 0;
1279 if (pressed && SCROLL_trackHitTest == SCROLL_THUMB)
1280 info->rgstate[3] |= STATE_SYSTEM_PRESSED;
1282 /* Page down/right region state. MSDN says down/left, but I don't believe it */
1283 info->rgstate[4] = 0;
1284 if (infoPtr->curVal >= infoPtr->maxVal - 1)
1285 info->rgstate[4] |= STATE_SYSTEM_INVISIBLE;
1286 if (pressed && SCROLL_trackHitTest == SCROLL_BOTTOM_RECT)
1287 info->rgstate[4] |= STATE_SYSTEM_PRESSED;
1289 /* Bottom/right arrow button state. MSDN says bottom/left, but I don't believe it */
1290 info->rgstate[5] = 0;
1291 if (pressed && SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW)
1292 info->rgstate[5] |= STATE_SYSTEM_PRESSED;
1293 if (infoPtr->flags & ESB_DISABLE_RTDN)
1294 info->rgstate[5] |= STATE_SYSTEM_UNAVAILABLE;
1296 return TRUE;
1300 /*************************************************************************
1301 * SCROLL_GetScrollPos
1303 * Internal helper for the API function
1305 * PARAMS
1306 * hwnd [I] Handle of window with scrollbar(s)
1307 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1309 static INT SCROLL_GetScrollPos(HWND hwnd, INT nBar)
1311 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1312 return infoPtr ? infoPtr->curVal: 0;
1316 /*************************************************************************
1317 * SCROLL_GetScrollRange
1319 * Internal helper for the API function
1321 * PARAMS
1322 * hwnd [I] Handle of window with scrollbar(s)
1323 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1324 * lpMin [O] Where to store minimum value
1325 * lpMax [O] Where to store maximum value
1327 * RETURNS STD
1329 static BOOL SCROLL_GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1331 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1333 if (lpMin) *lpMin = infoPtr ? infoPtr->minVal : 0;
1334 if (lpMax) *lpMax = infoPtr ? infoPtr->maxVal : 0;
1336 return TRUE;
1340 /*************************************************************************
1341 * SCROLL_SetScrollRange
1343 * PARAMS
1344 * hwnd [I] Handle of window with scrollbar(s)
1345 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1346 * lpMin [I] Minimum value
1347 * lpMax [I] Maximum value
1350 static BOOL SCROLL_SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal)
1352 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1354 TRACE("hwnd=%p nBar=%d min=%d max=%d\n", hwnd, nBar, minVal, maxVal);
1356 if (infoPtr)
1358 infoPtr->minVal = minVal;
1359 infoPtr->maxVal = maxVal;
1361 return TRUE;
1365 /***********************************************************************
1366 * ScrollBarWndProc
1368 static LRESULT WINAPI ScrollBarWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1370 if (!IsWindow( hwnd )) return 0;
1372 switch(message)
1374 case WM_CREATE:
1375 SCROLL_CreateScrollBar(hwnd, (LPCREATESTRUCTW)lParam);
1376 break;
1378 case WM_ENABLE:
1380 SCROLLBAR_INFO *infoPtr;
1381 if ((infoPtr = SCROLL_GetInternalInfo( hwnd, SB_CTL, FALSE )))
1383 infoPtr->flags = wParam ? ESB_ENABLE_BOTH : ESB_DISABLE_BOTH;
1384 SCROLL_RefreshScrollBar(hwnd, SB_CTL, TRUE, TRUE);
1387 return 0;
1389 case WM_LBUTTONDBLCLK:
1390 case WM_LBUTTONDOWN:
1392 POINT pt;
1393 pt.x = (short)LOWORD(lParam);
1394 pt.y = (short)HIWORD(lParam);
1395 SCROLL_TrackScrollBar( hwnd, SB_CTL, pt );
1397 break;
1398 case WM_LBUTTONUP:
1399 case WM_MOUSEMOVE:
1400 case WM_SYSTIMER:
1402 POINT pt;
1403 pt.x = (short)LOWORD(lParam);
1404 pt.y = (short)HIWORD(lParam);
1405 SCROLL_HandleScrollEvent( hwnd, SB_CTL, message, pt );
1407 break;
1409 case WM_KEYDOWN:
1410 SCROLL_HandleKbdEvent(hwnd, wParam, lParam);
1411 break;
1413 case WM_KEYUP:
1414 ShowCaret(hwnd);
1415 break;
1417 case WM_SETFOCUS:
1419 /* Create a caret when a ScrollBar get focus */
1420 RECT rect;
1421 int arrowSize, thumbSize, thumbPos, vertical;
1422 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,
1423 &arrowSize, &thumbSize, &thumbPos );
1424 if (!vertical)
1426 CreateCaret(hwnd, (HBITMAP)1, thumbSize-2, rect.bottom-rect.top-2);
1427 SetCaretPos(thumbPos+1, rect.top+1);
1429 else
1431 CreateCaret(hwnd, (HBITMAP)1, rect.right-rect.left-2,thumbSize-2);
1432 SetCaretPos(rect.top+1, thumbPos+1);
1434 ShowCaret(hwnd);
1436 break;
1438 case WM_KILLFOCUS:
1440 RECT rect;
1441 int arrowSize, thumbSize, thumbPos, vertical;
1442 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,&arrowSize, &thumbSize, &thumbPos );
1443 if (!vertical){
1444 rect.left=thumbPos+1;
1445 rect.right=rect.left+thumbSize;
1447 else
1449 rect.top=thumbPos+1;
1450 rect.bottom=rect.top+thumbSize;
1452 HideCaret(hwnd);
1453 InvalidateRect(hwnd,&rect,0);
1454 DestroyCaret();
1456 break;
1458 case WM_ERASEBKGND:
1459 return 1;
1461 case WM_GETDLGCODE:
1462 return DLGC_WANTARROWS; /* Windows returns this value */
1464 case WM_PAINT:
1466 PAINTSTRUCT ps;
1467 HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
1468 if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEGRIP)
1470 SCROLL_DrawSizeGrip( hwnd, hdc);
1472 else if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEBOX)
1474 RECT rc;
1475 GetClientRect( hwnd, &rc );
1476 FillRect( hdc, &rc, GetSysColorBrush(COLOR_SCROLLBAR) );
1478 else
1479 SCROLL_DrawScrollBar( hwnd, hdc, SB_CTL, TRUE, TRUE );
1480 if (!wParam) EndPaint(hwnd, &ps);
1482 break;
1484 case SBM_SETPOS16:
1485 case SBM_SETPOS:
1486 return SetScrollPos( hwnd, SB_CTL, wParam, (BOOL)lParam );
1488 case SBM_GETPOS16:
1489 case SBM_GETPOS:
1490 return SCROLL_GetScrollPos(hwnd, SB_CTL);
1492 case SBM_SETRANGE16:
1493 if (wParam) message = SBM_SETRANGEREDRAW;
1494 wParam = LOWORD(lParam);
1495 lParam = HIWORD(lParam);
1496 /* fall through */
1497 case SBM_SETRANGEREDRAW:
1498 case SBM_SETRANGE:
1500 INT oldPos = SCROLL_GetScrollPos( hwnd, SB_CTL );
1501 SCROLL_SetScrollRange( hwnd, SB_CTL, wParam, lParam );
1502 if (message == SBM_SETRANGEREDRAW)
1503 SCROLL_RefreshScrollBar( hwnd, SB_CTL, TRUE, TRUE );
1504 if (oldPos != SCROLL_GetScrollPos( hwnd, SB_CTL )) return oldPos;
1506 return 0;
1508 case SBM_GETRANGE16:
1510 INT min, max;
1512 SCROLL_GetScrollRange(hwnd, SB_CTL, &min, &max);
1513 return MAKELRESULT(min, max);
1516 case SBM_GETRANGE:
1517 return SCROLL_GetScrollRange(hwnd, SB_CTL, (LPINT)wParam, (LPINT)lParam);
1519 case SBM_ENABLE_ARROWS16:
1520 case SBM_ENABLE_ARROWS:
1521 return EnableScrollBar( hwnd, SB_CTL, wParam );
1523 case SBM_SETSCROLLINFO:
1524 return SCROLL_SetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam, wParam );
1526 case SBM_GETSCROLLINFO:
1527 return SCROLL_GetScrollInfo(hwnd, SB_CTL, (SCROLLINFO *)lParam);
1529 case SBM_GETSCROLLBARINFO:
1530 return SCROLL_GetScrollBarInfo(hwnd, OBJID_CLIENT, (SCROLLBARINFO *)lParam);
1532 case 0x00e5:
1533 case 0x00e7:
1534 case 0x00e8:
1535 case 0x00ec:
1536 case 0x00ed:
1537 case 0x00ee:
1538 case 0x00ef:
1539 ERR("unknown Win32 msg %04x wp=%08x lp=%08lx\n",
1540 message, wParam, lParam );
1541 break;
1543 default:
1544 if (message >= WM_USER)
1545 WARN("unknown msg %04x wp=%04x lp=%08lx\n",
1546 message, wParam, lParam );
1547 return DefWindowProcW( hwnd, message, wParam, lParam );
1549 return 0;
1553 /*************************************************************************
1554 * SetScrollInfo (USER32.@)
1556 * SetScrollInfo can be used to set the position, upper bound,
1557 * lower bound, and page size of a scrollbar control.
1559 * PARAMS
1560 * hwnd [I] Handle of window with scrollbar(s)
1561 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1562 * info [I] Specifies what to change and new values
1563 * bRedraw [I] Should scrollbar be redrawn afterwards?
1565 * RETURNS
1566 * Scrollbar position
1568 * NOTE
1569 * For 100 lines of text to be displayed in a window of 25 lines,
1570 * one would for instance use info->nMin=0, info->nMax=75
1571 * (corresponding to the 76 different positions of the window on
1572 * the text), and info->nPage=25.
1574 INT WINAPI SetScrollInfo(HWND hwnd, INT nBar, const SCROLLINFO *info, BOOL bRedraw)
1576 TRACE("hwnd=%p nBar=%d info=%p, bRedraw=%d\n", hwnd, nBar, info, bRedraw);
1578 /* Refer SB_CTL requests to the window */
1579 if (nBar == SB_CTL)
1580 return SendMessageW(hwnd, SBM_SETSCROLLINFO, bRedraw, (LPARAM)info);
1581 else
1582 return SCROLL_SetScrollInfo( hwnd, nBar, info, bRedraw );
1585 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar, LPCSCROLLINFO info, BOOL bRedraw )
1587 /* Update the scrollbar state and set action flags according to
1588 * what has to be done graphics wise. */
1590 SCROLLBAR_INFO *infoPtr;
1591 UINT new_flags;
1592 INT action = 0;
1594 /* handle invalid data structure */
1595 if (!SCROLL_ScrollInfoValid(info)
1596 || !(infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, TRUE)))
1597 return 0;
1599 if (TRACE_ON(scroll))
1601 TRACE("hwnd=%p bar=%d", hwnd, nBar);
1602 if (info->fMask & SIF_PAGE) TRACE( " page=%d", info->nPage );
1603 if (info->fMask & SIF_POS) TRACE( " pos=%d", info->nPos );
1604 if (info->fMask & SIF_RANGE) TRACE( " min=%d max=%d", info->nMin, info->nMax );
1605 TRACE("\n");
1608 /* Set the page size */
1610 if (info->fMask & SIF_PAGE)
1612 if( infoPtr->page != info->nPage && info->nPage >= 0)
1614 infoPtr->page = info->nPage;
1615 action |= SA_SSI_REFRESH;
1619 /* Set the scroll pos */
1621 if (info->fMask & SIF_POS)
1623 if( infoPtr->curVal != info->nPos )
1625 infoPtr->curVal = info->nPos;
1626 action |= SA_SSI_REFRESH;
1630 /* Set the scroll range */
1632 if (info->fMask & SIF_RANGE)
1634 /* Invalid range -> range is set to (0,0) */
1635 if ((info->nMin > info->nMax) ||
1636 ((UINT)(info->nMax - info->nMin) >= 0x80000000))
1638 action |= SA_SSI_REFRESH;
1639 infoPtr->minVal = 0;
1640 infoPtr->maxVal = 0;
1642 else
1644 if( infoPtr->minVal != info->nMin ||
1645 infoPtr->maxVal != info->nMax )
1647 action |= SA_SSI_REFRESH;
1648 infoPtr->minVal = info->nMin;
1649 infoPtr->maxVal = info->nMax;
1654 /* Make sure the page size is valid */
1655 if (infoPtr->page < 0) infoPtr->page = 0;
1656 else if (infoPtr->page > infoPtr->maxVal - infoPtr->minVal + 1 )
1657 infoPtr->page = infoPtr->maxVal - infoPtr->minVal + 1;
1659 /* Make sure the pos is inside the range */
1661 if (infoPtr->curVal < infoPtr->minVal)
1662 infoPtr->curVal = infoPtr->minVal;
1663 else if (infoPtr->curVal > infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1664 infoPtr->curVal = infoPtr->maxVal - max( infoPtr->page-1, 0 );
1666 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1667 infoPtr->page, infoPtr->curVal,
1668 infoPtr->minVal, infoPtr->maxVal );
1670 /* don't change the scrollbar state if SetScrollInfo
1671 * is just called with SIF_DISABLENOSCROLL
1673 if(!(info->fMask & SIF_ALL)) goto done;
1675 /* Check if the scrollbar should be hidden or disabled */
1677 if (info->fMask & (SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL))
1679 new_flags = infoPtr->flags;
1680 if (infoPtr->minVal >= infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1682 /* Hide or disable scroll-bar */
1683 if (info->fMask & SIF_DISABLENOSCROLL)
1685 new_flags = ESB_DISABLE_BOTH;
1686 action |= SA_SSI_REFRESH;
1688 else if ((nBar != SB_CTL) && (action & SA_SSI_REFRESH))
1690 action = SA_SSI_HIDE;
1693 else /* Show and enable scroll-bar only if no page only changed. */
1694 if (info->fMask != SIF_PAGE)
1696 new_flags = ESB_ENABLE_BOTH;
1697 if ((nBar != SB_CTL) && ( (action & SA_SSI_REFRESH) ))
1698 action |= SA_SSI_SHOW;
1701 if (infoPtr->flags != new_flags) /* check arrow flags */
1703 infoPtr->flags = new_flags;
1704 action |= SA_SSI_REPAINT_ARROWS;
1708 done:
1709 if( action & SA_SSI_HIDE )
1710 SCROLL_ShowScrollBar( hwnd, nBar, FALSE, FALSE );
1711 else
1713 if( action & SA_SSI_SHOW )
1714 if( SCROLL_ShowScrollBar( hwnd, nBar, TRUE, TRUE ) )
1715 return infoPtr->curVal; /* SetWindowPos() already did the painting */
1717 if( bRedraw )
1718 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
1719 else if( action & SA_SSI_REPAINT_ARROWS )
1720 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, FALSE );
1723 /* Return current position */
1724 return infoPtr->curVal;
1728 /*************************************************************************
1729 * GetScrollInfo (USER32.@)
1731 * GetScrollInfo can be used to retrieve the position, upper bound,
1732 * lower bound, and page size of a scrollbar control.
1734 * PARAMS
1735 * hwnd [I] Handle of window with scrollbar(s)
1736 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1737 * info [IO] fMask specifies which values to retrieve
1739 * RETURNS
1740 * TRUE if SCROLLINFO is filled
1741 * ( if nBar is SB_CTL, GetScrollInfo returns TRUE even if nothing
1742 * is filled)
1744 BOOL WINAPI GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1746 TRACE("hwnd=%p nBar=%d info=%p\n", hwnd, nBar, info);
1748 /* Refer SB_CTL requests to the window */
1749 if (nBar == SB_CTL)
1751 SendMessageW(hwnd, SBM_GETSCROLLINFO, (WPARAM)0, (LPARAM)info);
1752 return TRUE;
1754 return SCROLL_GetScrollInfo(hwnd, nBar, info);
1758 /*************************************************************************
1759 * GetScrollBarInfo (USER32.@)
1761 * GetScrollBarInfo can be used to retrieve information about a scrollbar
1762 * control.
1764 * PARAMS
1765 * hwnd [I] Handle of window with scrollbar(s)
1766 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1767 * info [IO] cbSize specifies the size of SCROLLBARINFO
1769 * RETURNS
1770 * TRUE if success
1772 BOOL WINAPI GetScrollBarInfo(HWND hwnd, LONG idObject, LPSCROLLBARINFO info)
1774 TRACE("hwnd=%p idObject=%ld info=%p\n", hwnd, idObject, info);
1776 /* Refer OBJID_CLIENT requests to the window */
1777 if (idObject == OBJID_CLIENT)
1778 return SendMessageW(hwnd, SBM_GETSCROLLBARINFO, (WPARAM)0, (LPARAM)info);
1779 else
1780 return SCROLL_GetScrollBarInfo(hwnd, idObject, info);
1784 /*************************************************************************
1785 * SetScrollPos (USER32.@)
1787 * Sets the current position of the scroll thumb.
1789 * PARAMS
1790 * hwnd [I] Handle of window with scrollbar(s)
1791 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1792 * nPos [I] New value
1793 * bRedraw [I] Should scrollbar be redrawn afterwards?
1795 * RETURNS
1796 * Success: Scrollbar position
1797 * Failure: 0
1799 * REMARKS
1800 * Note the ambiguity when 0 is returned. Use GetLastError
1801 * to make sure there was an error (and to know which one).
1803 INT WINAPI SetScrollPos( HWND hwnd, INT nBar, INT nPos, BOOL bRedraw)
1805 SCROLLINFO info;
1806 SCROLLBAR_INFO *infoPtr;
1807 INT oldPos;
1809 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, FALSE ))) return 0;
1810 oldPos = infoPtr->curVal;
1811 info.cbSize = sizeof(info);
1812 info.nPos = nPos;
1813 info.fMask = SIF_POS;
1814 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1815 return oldPos;
1819 /*************************************************************************
1820 * GetScrollPos (USER32.@)
1822 * Gets the current position of the scroll thumb.
1824 * PARAMS
1825 * hwnd [I] Handle of window with scrollbar(s)
1826 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1828 * RETURNS
1829 * Success: Current position
1830 * Failure: 0
1832 * REMARKS
1833 * There is ambiguity when 0 is returned. Use GetLastError
1834 * to make sure there was an error (and to know which one).
1836 INT WINAPI GetScrollPos(HWND hwnd, INT nBar)
1838 TRACE("hwnd=%p nBar=%d\n", hwnd, nBar);
1840 /* Refer SB_CTL requests to the window */
1841 if (nBar == SB_CTL)
1842 return SendMessageW(hwnd, SBM_GETPOS, (WPARAM)0, (LPARAM)0);
1843 else
1844 return SCROLL_GetScrollPos(hwnd, nBar);
1848 /*************************************************************************
1849 * SetScrollRange (USER32.@)
1850 * The SetScrollRange function sets the minimum and maximum scroll box positions
1851 * If nMinPos and nMaxPos is the same value, the scroll bar will hide
1853 * Sets the range of the scroll bar.
1855 * PARAMS
1856 * hwnd [I] Handle of window with scrollbar(s)
1857 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1858 * minVal [I] New minimum value
1859 * maxVal [I] New Maximum value
1860 * bRedraw [I] Should scrollbar be redrawn afterwards?
1862 * RETURNS STD
1864 BOOL WINAPI SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal, BOOL bRedraw)
1866 SCROLLINFO info;
1868 TRACE("hwnd=%p nBar=%d min=%d max=%d, bRedraw=%d\n", hwnd, nBar, minVal, maxVal, bRedraw);
1870 info.cbSize = sizeof(info);
1871 info.fMask = SIF_RANGE;
1872 info.nMin = minVal;
1873 info.nMax = maxVal;
1874 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1875 return TRUE;
1879 /*************************************************************************
1880 * SCROLL_SetNCSbState
1882 * Updates both scrollbars at the same time. Used by MDI CalcChildScroll().
1884 INT SCROLL_SetNCSbState(HWND hwnd, int vMin, int vMax, int vPos,
1885 int hMin, int hMax, int hPos)
1887 SCROLLINFO vInfo, hInfo;
1889 vInfo.cbSize = hInfo.cbSize = sizeof(SCROLLINFO);
1890 vInfo.nMin = vMin;
1891 vInfo.nMax = vMax;
1892 vInfo.nPos = vPos;
1893 hInfo.nMin = hMin;
1894 hInfo.nMax = hMax;
1895 hInfo.nPos = hPos;
1896 vInfo.fMask = hInfo.fMask = SIF_RANGE | SIF_POS;
1898 SCROLL_SetScrollInfo( hwnd, SB_VERT, &vInfo, TRUE );
1899 SCROLL_SetScrollInfo( hwnd, SB_HORZ, &hInfo, TRUE );
1901 return 0;
1905 /*************************************************************************
1906 * GetScrollRange (USER32.@)
1908 * Gets the range of the scroll bar.
1910 * PARAMS
1911 * hwnd [I] Handle of window with scrollbar(s)
1912 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1913 * lpMin [O] Where to store minimum value
1914 * lpMax [O] Where to store maximum value
1916 * RETURNS
1917 * TRUE if values is filled
1919 BOOL WINAPI GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1921 TRACE("hwnd=%p nBar=%d lpMin=%p lpMax=%p\n", hwnd, nBar, lpMin, lpMax);
1923 /* Refer SB_CTL requests to the window */
1924 if (nBar == SB_CTL)
1925 SendMessageW(hwnd, SBM_GETRANGE, (WPARAM)lpMin, (LPARAM)lpMax);
1926 else
1927 SCROLL_GetScrollRange(hwnd, nBar, lpMin, lpMax);
1929 return TRUE;
1933 /*************************************************************************
1934 * SCROLL_ShowScrollBar()
1936 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1938 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar, BOOL fShowH, BOOL fShowV )
1940 ULONG old_style, set_bits = 0, clear_bits = 0;
1942 TRACE("hwnd=%p bar=%d horz=%d, vert=%d\n", hwnd, nBar, fShowH, fShowV );
1944 switch(nBar)
1946 case SB_CTL:
1947 ShowWindow( hwnd, fShowH ? SW_SHOW : SW_HIDE );
1948 return TRUE;
1950 case SB_BOTH:
1951 case SB_HORZ:
1952 if (fShowH) set_bits |= WS_HSCROLL;
1953 else clear_bits |= WS_HSCROLL;
1954 if( nBar == SB_HORZ ) break;
1955 /* fall through */
1956 case SB_VERT:
1957 if (fShowV) set_bits |= WS_VSCROLL;
1958 else clear_bits |= WS_VSCROLL;
1959 break;
1961 default:
1962 return FALSE; /* Nothing to do! */
1965 old_style = WIN_SetStyle( hwnd, set_bits, clear_bits );
1966 if ((old_style & clear_bits) != 0 || (old_style & set_bits) != set_bits)
1968 /* frame has been changed, let the window redraw itself */
1969 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
1970 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
1971 return TRUE;
1973 return FALSE; /* no frame changes */
1977 /*************************************************************************
1978 * ShowScrollBar (USER32.@)
1980 * Shows or hides the scroll bar.
1982 * PARAMS
1983 * hwnd [I] Handle of window with scrollbar(s)
1984 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1985 * fShow [I] TRUE = show, FALSE = hide
1987 * RETURNS STD
1989 BOOL WINAPI ShowScrollBar(HWND hwnd, INT nBar, BOOL fShow)
1991 SCROLL_ShowScrollBar( hwnd, nBar, (nBar == SB_VERT) ? 0 : fShow,
1992 (nBar == SB_HORZ) ? 0 : fShow );
1993 return TRUE;
1997 /*************************************************************************
1998 * EnableScrollBar (USER32.@)
2000 * Enables or disables the scroll bars.
2002 BOOL WINAPI EnableScrollBar( HWND hwnd, INT nBar, UINT flags )
2004 BOOL bFineWithMe;
2005 SCROLLBAR_INFO *infoPtr;
2007 TRACE("%p %d %d\n", hwnd, nBar, flags );
2009 flags &= ESB_DISABLE_BOTH;
2011 if (nBar == SB_BOTH)
2013 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, SB_VERT, TRUE ))) return FALSE;
2014 if (!(bFineWithMe = (infoPtr->flags == flags)) )
2016 infoPtr->flags = flags;
2017 SCROLL_RefreshScrollBar( hwnd, SB_VERT, TRUE, TRUE );
2019 nBar = SB_HORZ;
2021 else
2022 bFineWithMe = TRUE;
2024 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, TRUE ))) return FALSE;
2025 if (bFineWithMe && infoPtr->flags == flags) return FALSE;
2026 infoPtr->flags = flags;
2028 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
2029 return TRUE;