d3d11: Remove null dxgi object checks.
[wine.git] / dlls / user32 / scroll.c
blobb6f15b4a295a832cd369064e4d86505d9b49198f
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 BOOL painted; /* Whether the scroll bar is painted by DefWinProc() */
43 } SCROLLBAR_INFO, *LPSCROLLBAR_INFO;
45 /* data for window that has (one or two) scroll bars */
46 typedef struct
48 SCROLLBAR_INFO horz;
49 SCROLLBAR_INFO vert;
50 } WINSCROLLBAR_INFO, *LPWINSCROLLBAR_INFO;
52 typedef struct
54 DWORD magic;
55 SCROLLBAR_INFO info;
56 } SCROLLBAR_WNDDATA;
58 #define SCROLLBAR_MAGIC 0x5c6011ba
60 /* Minimum size of the rectangle between the arrows */
61 #define SCROLL_MIN_RECT 4
63 /* Minimum size of the thumb in pixels */
64 #define SCROLL_MIN_THUMB 8
66 /* Overlap between arrows and thumb */
67 #define SCROLL_ARROW_THUMB_OVERLAP 0
69 /* Delay (in ms) before first repetition when holding the button down */
70 #define SCROLL_FIRST_DELAY 200
72 /* Delay (in ms) between scroll repetitions */
73 #define SCROLL_REPEAT_DELAY 50
75 /* Scroll timer id */
76 #define SCROLL_TIMER 0
78 /* What to do after SCROLL_SetScrollInfo() */
79 #define SA_SSI_HIDE 0x0001
80 #define SA_SSI_SHOW 0x0002
81 #define SA_SSI_REFRESH 0x0004
82 #define SA_SSI_REPAINT_ARROWS 0x0008
84 /* Scroll Bar tracking information */
85 static struct SCROLL_TRACKING_INFO g_tracking_info;
87 /* Is the moving thumb being displayed? */
88 static BOOL SCROLL_MovingThumb = FALSE;
90 /* Local functions */
91 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar,
92 BOOL fShowH, BOOL fShowV );
93 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar,
94 const SCROLLINFO *info, BOOL bRedraw );
96 /*********************************************************************
97 * scrollbar class descriptor
99 const struct builtin_class_descr SCROLL_builtin_class =
101 L"ScrollBar", /* name */
102 CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC, /* style */
103 WINPROC_SCROLLBAR, /* proc */
104 sizeof(SCROLLBAR_WNDDATA), /* extra */
105 IDC_ARROW, /* cursor */
106 0 /* brush */
109 /***********************************************************************
110 * SCROLL_ScrollInfoValid
112 * Determine if the supplied SCROLLINFO struct is valid.
113 * info [in] The SCROLLINFO struct to be tested
115 static inline BOOL SCROLL_ScrollInfoValid( LPCSCROLLINFO info )
117 return !(info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)
118 || (info->cbSize != sizeof(*info)
119 && info->cbSize != sizeof(*info) - sizeof(info->nTrackPos)));
123 /***********************************************************************
124 * SCROLL_GetInternalInfo
126 * Returns pointer to internal SCROLLBAR_INFO structure for nBar
127 * or NULL if failed (f.i. scroll bar does not exist yet)
128 * If alloc is TRUE and the struct does not exist yet, create it.
130 static SCROLLBAR_INFO *SCROLL_GetInternalInfo( HWND hwnd, INT nBar, BOOL alloc )
132 SCROLLBAR_INFO *infoPtr = NULL;
133 WND *wndPtr = WIN_GetPtr( hwnd );
135 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return NULL;
136 switch(nBar)
138 case SB_HORZ:
139 if (wndPtr->pScroll) infoPtr = &((LPWINSCROLLBAR_INFO)wndPtr->pScroll)->horz;
140 break;
141 case SB_VERT:
142 if (wndPtr->pScroll) infoPtr = &((LPWINSCROLLBAR_INFO)wndPtr->pScroll)->vert;
143 break;
144 case SB_CTL:
145 if (wndPtr->cbWndExtra >= sizeof(SCROLLBAR_WNDDATA))
147 SCROLLBAR_WNDDATA *data = (SCROLLBAR_WNDDATA*)wndPtr->wExtra;
148 if (data->magic == SCROLLBAR_MAGIC)
149 infoPtr = &data->info;
151 if (!infoPtr) WARN("window is not a scrollbar control\n");
152 break;
153 case SB_BOTH:
154 WARN("with SB_BOTH\n");
155 break;
158 if (!infoPtr && alloc)
160 WINSCROLLBAR_INFO *winInfoPtr;
162 if (nBar != SB_HORZ && nBar != SB_VERT)
163 WARN("Cannot initialize nBar=%d\n",nBar);
164 else if ((winInfoPtr = HeapAlloc( GetProcessHeap(), 0, sizeof(WINSCROLLBAR_INFO) )))
166 /* Set default values */
167 winInfoPtr->horz.minVal = 0;
168 winInfoPtr->horz.curVal = 0;
169 winInfoPtr->horz.page = 0;
170 /* From MSDN and our own tests:
171 * max for a standard scroll bar is 100 by default. */
172 winInfoPtr->horz.maxVal = 100;
173 winInfoPtr->horz.flags = ESB_ENABLE_BOTH;
174 winInfoPtr->vert = winInfoPtr->horz;
175 wndPtr->pScroll = winInfoPtr;
176 infoPtr = nBar == SB_HORZ ? &winInfoPtr->horz : &winInfoPtr->vert;
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, min_thumb_size;
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 WIN_GetRectangles( hwnd, COORDS_WINDOW, NULL, lprect );
209 lprect->top = lprect->bottom;
210 lprect->bottom += GetSystemMetrics(SM_CYHSCROLL);
211 if(wndPtr->dwStyle & WS_VSCROLL)
212 lprect->right++;
213 vertical = FALSE;
214 break;
216 case SB_VERT:
217 WIN_GetRectangles( hwnd, COORDS_WINDOW, NULL, lprect );
218 if((wndPtr->dwExStyle & WS_EX_LEFTSCROLLBAR) != 0)
220 lprect->right = lprect->left;
221 lprect->left -= GetSystemMetrics(SM_CXVSCROLL);
223 else
225 lprect->left = lprect->right;
226 lprect->right += GetSystemMetrics(SM_CXVSCROLL);
228 if(wndPtr->dwStyle & WS_HSCROLL)
229 lprect->bottom++;
230 vertical = TRUE;
231 break;
233 case SB_CTL:
234 GetClientRect( hwnd, lprect );
235 vertical = ((wndPtr->dwStyle & SBS_VERT) != 0);
236 break;
238 default:
239 WIN_ReleasePtr( wndPtr );
240 return FALSE;
243 if (vertical) pixels = lprect->bottom - lprect->top;
244 else pixels = lprect->right - lprect->left;
246 if (pixels <= 2*GetSystemMetrics(SM_CXVSCROLL) + SCROLL_MIN_RECT)
248 if (pixels > SCROLL_MIN_RECT)
249 *arrowSize = (pixels - SCROLL_MIN_RECT) / 2;
250 else
251 *arrowSize = 0;
252 *thumbPos = *thumbSize = 0;
254 else
256 SCROLLBAR_INFO *info = SCROLL_GetInternalInfo( hwnd, nBar, TRUE );
257 if (!info)
259 WARN("called for missing scroll bar\n");
260 WIN_ReleasePtr( wndPtr );
261 return FALSE;
263 *arrowSize = GetSystemMetrics(SM_CXVSCROLL);
264 pixels -= (2 * (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP));
266 if (info->page)
268 *thumbSize = MulDiv(pixels,info->page,(info->maxVal-info->minVal+1));
269 min_thumb_size = MulDiv(SCROLL_MIN_THUMB, GetDpiForWindow(hwnd), 96);
270 if (*thumbSize < min_thumb_size) *thumbSize = min_thumb_size;
272 else *thumbSize = GetSystemMetrics(SM_CXVSCROLL);
274 if (((pixels -= *thumbSize ) < 0) ||
275 ((info->flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH))
277 /* Rectangle too small or scrollbar disabled -> no thumb */
278 *thumbPos = *thumbSize = 0;
280 else
282 INT max = info->maxVal - max( info->page-1, 0 );
283 if (info->minVal >= max)
284 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
285 else
286 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP
287 + MulDiv(pixels, (info->curVal-info->minVal),(max - info->minVal));
290 WIN_ReleasePtr( wndPtr );
291 return vertical;
294 static void SCROLL_GetScrollBarDrawInfo( HWND hwnd, INT bar,
295 const struct SCROLL_TRACKING_INFO *tracking_info,
296 RECT *rect, INT *arrow_size, INT *thumb_size,
297 INT *thumb_pos, BOOL *vertical )
299 INT pos, max_size;
301 if (bar == SB_CTL && GetWindowLongW( hwnd, GWL_STYLE ) & (SBS_SIZEGRIP | SBS_SIZEBOX))
303 GetClientRect( hwnd, rect );
304 *arrow_size = 0;
305 *thumb_pos = 0;
306 *thumb_size = 0;
307 *vertical = FALSE;
308 return;
311 *vertical = SCROLL_GetScrollBarRect( hwnd, bar, rect, arrow_size, thumb_size, thumb_pos );
313 if (SCROLL_MovingThumb && tracking_info->win == hwnd && tracking_info->bar == bar)
315 max_size = *vertical ? rect->bottom - rect->top : rect->right - rect->left;
316 max_size -= *arrow_size - SCROLL_ARROW_THUMB_OVERLAP + *thumb_size;
318 pos = tracking_info->thumb_pos;
319 if (pos < *arrow_size - SCROLL_ARROW_THUMB_OVERLAP)
320 pos = *arrow_size - SCROLL_ARROW_THUMB_OVERLAP;
321 else if (pos > max_size)
322 pos = max_size;
324 *thumb_pos = pos;
328 /***********************************************************************
329 * SCROLL_GetThumbVal
331 * Compute the current scroll position based on the thumb position in pixels
332 * from the top of the scroll-bar.
334 static UINT SCROLL_GetThumbVal( HWND hwnd, SCROLLBAR_INFO *infoPtr, RECT *rect, BOOL vertical,
335 INT pos )
337 INT thumbSize, minThumbSize;
338 INT pixels = vertical ? rect->bottom-rect->top : rect->right-rect->left;
339 INT range;
341 if ((pixels -= 2*(GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP)) <= 0)
342 return infoPtr->minVal;
344 if (infoPtr->page)
346 thumbSize = MulDiv(pixels,infoPtr->page,(infoPtr->maxVal-infoPtr->minVal+1));
347 minThumbSize = MulDiv(SCROLL_MIN_THUMB, GetDpiForWindow(hwnd), 96);
348 if (thumbSize < minThumbSize) thumbSize = minThumbSize;
350 else thumbSize = GetSystemMetrics(SM_CXVSCROLL);
352 if ((pixels -= thumbSize) <= 0) return infoPtr->minVal;
354 pos = max( 0, pos - (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP) );
355 if (pos > pixels) pos = pixels;
357 if (!infoPtr->page)
358 range = infoPtr->maxVal - infoPtr->minVal;
359 else
360 range = infoPtr->maxVal - infoPtr->minVal - infoPtr->page + 1;
362 return infoPtr->minVal + MulDiv(pos, range, pixels);
365 /***********************************************************************
366 * SCROLL_PtInRectEx
368 static BOOL SCROLL_PtInRectEx( LPRECT lpRect, POINT pt, BOOL vertical )
370 RECT rect = *lpRect;
371 int scrollbarWidth;
373 /* Pad hit rect to allow mouse to be dragged outside of scrollbar and
374 * still be considered in the scrollbar. */
375 if (vertical)
377 scrollbarWidth = lpRect->right - lpRect->left;
378 InflateRect(&rect, scrollbarWidth * 8, scrollbarWidth * 2);
380 else
382 scrollbarWidth = lpRect->bottom - lpRect->top;
383 InflateRect(&rect, scrollbarWidth * 2, scrollbarWidth * 8);
385 return PtInRect( &rect, pt );
388 /***********************************************************************
389 * SCROLL_ClipPos
391 static POINT SCROLL_ClipPos( LPRECT lpRect, POINT pt )
393 if( pt.x < lpRect->left )
394 pt.x = lpRect->left;
395 else
396 if( pt.x > lpRect->right )
397 pt.x = lpRect->right;
399 if( pt.y < lpRect->top )
400 pt.y = lpRect->top;
401 else
402 if( pt.y > lpRect->bottom )
403 pt.y = lpRect->bottom;
405 return pt;
409 /***********************************************************************
410 * SCROLL_HitTest
412 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
414 static enum SCROLL_HITTEST SCROLL_HitTest( HWND hwnd, INT nBar,
415 POINT pt, BOOL bDragging )
417 INT arrowSize, thumbSize, thumbPos;
418 RECT rect;
420 BOOL vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
421 &arrowSize, &thumbSize, &thumbPos );
423 if ( (bDragging && !SCROLL_PtInRectEx( &rect, pt, vertical )) ||
424 (!PtInRect( &rect, pt )) ) return SCROLL_NOWHERE;
426 if (vertical)
428 if (pt.y < rect.top + arrowSize) return SCROLL_TOP_ARROW;
429 if (pt.y >= rect.bottom - arrowSize) return SCROLL_BOTTOM_ARROW;
430 if (!thumbPos) return SCROLL_TOP_RECT;
431 pt.y -= rect.top;
432 if (pt.y < thumbPos) return SCROLL_TOP_RECT;
433 if (pt.y >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
435 else /* horizontal */
437 if (pt.x < rect.left + arrowSize) return SCROLL_TOP_ARROW;
438 if (pt.x >= rect.right - arrowSize) return SCROLL_BOTTOM_ARROW;
439 if (!thumbPos) return SCROLL_TOP_RECT;
440 pt.x -= rect.left;
441 if (pt.x < thumbPos) return SCROLL_TOP_RECT;
442 if (pt.x >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
444 return SCROLL_THUMB;
448 /***********************************************************************
449 * SCROLL_DrawArrows
451 * Draw the scroll bar arrows.
453 static void SCROLL_DrawArrows( HDC hdc, SCROLLBAR_INFO *infoPtr,
454 RECT *rect, INT arrowSize, BOOL vertical,
455 BOOL top_pressed, BOOL bottom_pressed )
457 RECT r;
459 r = *rect;
460 if( vertical )
461 r.bottom = r.top + arrowSize;
462 else
463 r.right = r.left + arrowSize;
465 DrawFrameControl( hdc, &r, DFC_SCROLL,
466 (vertical ? DFCS_SCROLLUP : DFCS_SCROLLLEFT)
467 | (top_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
468 | (infoPtr->flags&ESB_DISABLE_LTUP ? DFCS_INACTIVE : 0 ) );
470 r = *rect;
471 if( vertical )
472 r.top = r.bottom-arrowSize;
473 else
474 r.left = r.right-arrowSize;
476 DrawFrameControl( hdc, &r, DFC_SCROLL,
477 (vertical ? DFCS_SCROLLDOWN : DFCS_SCROLLRIGHT)
478 | (bottom_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
479 | (infoPtr->flags&ESB_DISABLE_RTDN ? DFCS_INACTIVE : 0) );
482 /***********************************************************************
483 * SCROLL_DrawInterior
485 * Draw the scroll bar interior (everything except the arrows).
487 static void SCROLL_DrawInterior( HWND hwnd, HDC hdc, INT nBar,
488 RECT *rect, INT arrowSize,
489 INT thumbSize, INT thumbPos,
490 UINT flags, BOOL vertical,
491 BOOL top_selected, BOOL bottom_selected )
493 RECT r;
494 HPEN hSavePen;
495 HBRUSH hSaveBrush,hBrush;
497 /* Select the correct brush and pen */
499 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
500 * The window-owned scrollbars need to call DEFWND_ControlColor
501 * to correctly setup default scrollbar colors
503 if (nBar == SB_CTL) {
504 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
505 (WPARAM)hdc,(LPARAM)hwnd);
506 } else {
507 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
509 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
510 hSaveBrush = SelectObject( hdc, hBrush );
512 /* Calculate the scroll rectangle */
514 r = *rect;
515 if (vertical)
517 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
518 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
520 else
522 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
523 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
526 /* Draw the scroll bar frame */
528 /* Draw the scroll rectangles and thumb */
530 if (!thumbPos) /* No thumb to draw */
532 PatBlt( hdc, r.left, r.top, r.right - r.left, r.bottom - r.top, PATCOPY );
534 /* cleanup and return */
535 SelectObject( hdc, hSavePen );
536 SelectObject( hdc, hSaveBrush );
537 return;
540 if (vertical)
542 PatBlt( hdc, r.left, r.top, r.right - r.left,
543 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
544 top_selected ? 0x0f0000 : PATCOPY );
545 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
546 PatBlt( hdc, r.left, r.top + thumbSize, r.right - r.left,
547 r.bottom - r.top - thumbSize,
548 bottom_selected ? 0x0f0000 : PATCOPY );
549 r.bottom = r.top + thumbSize;
551 else /* horizontal */
553 PatBlt( hdc, r.left, r.top,
554 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
555 r.bottom - r.top, top_selected ? 0x0f0000 : PATCOPY );
556 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
557 PatBlt( hdc, r.left + thumbSize, r.top, r.right - r.left - thumbSize,
558 r.bottom - r.top, bottom_selected ? 0x0f0000 : PATCOPY );
559 r.right = r.left + thumbSize;
562 /* Draw the thumb */
564 SelectObject( hdc, GetSysColorBrush(COLOR_BTNFACE) );
565 Rectangle( hdc, r.left+1, r.top+1, r.right-1, r.bottom-1 );
566 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT );
568 /* cleanup */
569 SelectObject( hdc, hSavePen );
570 SelectObject( hdc, hSaveBrush );
573 void WINAPI USER_ScrollBarDraw( HWND hwnd, HDC hdc, INT nBar, enum SCROLL_HITTEST hit_test,
574 const struct SCROLL_TRACKING_INFO *tracking_info, BOOL arrows,
575 BOOL interior, RECT *rect, INT arrowSize, INT thumbPos,
576 INT thumbSize, BOOL vertical )
578 SCROLLBAR_INFO *infoPtr;
580 if (nBar == SB_CTL)
582 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
584 if (style & SBS_SIZEGRIP)
586 RECT rc = *rect;
588 FillRect( hdc, &rc, GetSysColorBrush( COLOR_BTNFACE ) );
589 rc.left = max( rc.left, rc.right - GetSystemMetrics( SM_CXVSCROLL ) - 1 );
590 rc.top = max( rc.top, rc.bottom - GetSystemMetrics( SM_CYHSCROLL ) - 1 );
591 DrawFrameControl( hdc, &rc, DFC_SCROLL, DFCS_SCROLLSIZEGRIP );
592 return;
595 if (style & SBS_SIZEBOX)
597 FillRect( hdc, rect, GetSysColorBrush( COLOR_BTNFACE ) );
598 return;
602 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, TRUE )))
603 return;
605 /* Draw the arrows */
607 if (arrows && arrowSize)
609 if (vertical == tracking_info->vertical && GetCapture() == hwnd)
610 SCROLL_DrawArrows( hdc, infoPtr, rect, arrowSize, vertical,
611 hit_test == tracking_info->hit_test && hit_test == SCROLL_TOP_ARROW,
612 hit_test == tracking_info->hit_test && hit_test == SCROLL_BOTTOM_ARROW );
613 else
614 SCROLL_DrawArrows( hdc, infoPtr, rect, arrowSize, vertical, FALSE, FALSE );
617 if (interior)
619 if (vertical == tracking_info->vertical && GetCapture() == hwnd)
621 SCROLL_DrawInterior( hwnd, hdc, nBar, rect, arrowSize, thumbSize, thumbPos,
622 infoPtr->flags, vertical,
623 hit_test == tracking_info->hit_test && hit_test == SCROLL_TOP_RECT,
624 hit_test == tracking_info->hit_test && hit_test == SCROLL_BOTTOM_RECT );
626 else
628 SCROLL_DrawInterior( hwnd, hdc, nBar, rect, arrowSize, thumbSize, thumbPos,
629 infoPtr->flags, vertical, FALSE, FALSE );
633 /* if scroll bar has focus, reposition the caret */
634 if(hwnd==GetFocus() && (nBar==SB_CTL))
636 if (!vertical)
638 SetCaretPos(thumbPos + 1, rect->top + 1);
640 else
642 SetCaretPos(rect->top + 1, thumbPos + 1);
647 void WINAPI SCROLL_SetStandardScrollPainted( HWND hwnd, INT bar, BOOL painted )
649 LPSCROLLBAR_INFO info;
651 if (bar != SB_HORZ && bar != SB_VERT)
652 return;
654 info = SCROLL_GetInternalInfo( hwnd, bar, FALSE );
655 if (info)
656 info->painted = painted;
659 static BOOL SCROLL_IsStandardScrollPainted( HWND hwnd, INT bar )
661 LPSCROLLBAR_INFO info;
663 if (bar != SB_HORZ && bar != SB_VERT)
664 return FALSE;
666 info = SCROLL_GetInternalInfo( hwnd, bar, FALSE );
667 return info ? info->painted : FALSE;
670 /***********************************************************************
671 * SCROLL_DrawScrollBar
673 * Redraw the whole scrollbar.
675 void SCROLL_DrawScrollBar( HWND hwnd, HDC hdc, INT bar, enum SCROLL_HITTEST hit_test,
676 const struct SCROLL_TRACKING_INFO *tracking_info, BOOL draw_arrows,
677 BOOL draw_interior )
679 INT arrow_size, thumb_size, thumb_pos;
680 RECT rect, clip_box, intersect;
681 BOOL vertical;
682 DWORD style;
684 if (!(hwnd = WIN_GetFullHandle( hwnd )))
685 return;
687 style = GetWindowLongW( hwnd, GWL_STYLE );
688 if ((bar == SB_VERT && !(style & WS_VSCROLL)) || (bar == SB_HORZ && !(style & WS_HSCROLL)))
689 return;
691 if (!WIN_IsWindowDrawable( hwnd, FALSE ))
692 return;
694 SCROLL_GetScrollBarDrawInfo( hwnd, bar, tracking_info, &rect, &arrow_size, &thumb_size,
695 &thumb_pos, &vertical );
696 /* do not draw if the scrollbar rectangle is empty */
697 if (IsRectEmpty( &rect ))
698 return;
700 TRACE("hwnd %p, hdc %p, bar %d, hit_test %d, tracking_info(win %p, bar %d, thumb_pos %d, "
701 "track_pos %d, vertical %d, hit_test %d), draw_arrows %d, draw_interior %d, rect %s, "
702 "arrow_size %d, thumb_pos %d, thumb_val %d, vertical %d, captured window %p\n", hwnd, hdc,
703 bar, hit_test, tracking_info->win, tracking_info->bar, tracking_info->thumb_pos,
704 tracking_info->thumb_val, tracking_info->vertical, tracking_info->hit_test, draw_arrows,
705 draw_interior, wine_dbgstr_rect(&rect), arrow_size, thumb_pos, thumb_size, vertical,
706 GetCapture());
707 user_api->pScrollBarDraw( hwnd, hdc, bar, hit_test, tracking_info, draw_arrows, draw_interior,
708 &rect, arrow_size, thumb_pos, thumb_size, vertical );
710 if (bar == SB_HORZ || bar == SB_VERT)
712 GetClipBox( hdc, &clip_box );
713 if (IntersectRect(&intersect, &rect, &clip_box))
714 SCROLL_SetStandardScrollPainted( hwnd, bar, TRUE );
718 void SCROLL_DrawNCScrollBar( HWND hwnd, HDC hdc, BOOL draw_horizontal, BOOL draw_vertical )
720 if (draw_horizontal)
721 SCROLL_DrawScrollBar( hwnd, hdc, SB_HORZ, g_tracking_info.hit_test, &g_tracking_info, TRUE, TRUE );
722 if (draw_vertical)
723 SCROLL_DrawScrollBar( hwnd, hdc, SB_VERT, g_tracking_info.hit_test, &g_tracking_info, TRUE, TRUE );
726 /***********************************************************************
727 * SCROLL_RefreshScrollBar
729 * Repaint the scroll bar interior after a SetScrollRange() or
730 * SetScrollPos() call.
732 static void SCROLL_RefreshScrollBar( HWND hwnd, INT nBar,
733 BOOL arrows, BOOL interior )
735 HDC hdc = NtUserGetDCEx( hwnd, 0, DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW) );
736 if (!hdc) return;
738 SCROLL_DrawScrollBar( hwnd, hdc, nBar, g_tracking_info.hit_test, &g_tracking_info, arrows, interior );
739 NtUserReleaseDC( hwnd, hdc );
743 /***********************************************************************
744 * SCROLL_HandleKbdEvent
746 * Handle a keyboard event (only for SB_CTL scrollbars with focus).
748 * PARAMS
749 * hwnd [I] Handle of window with scrollbar(s)
750 * wParam [I] Variable input including enable state
751 * lParam [I] Variable input including input point
753 static void SCROLL_HandleKbdEvent(HWND hwnd, WPARAM wParam, LPARAM lParam)
755 TRACE("hwnd=%p wParam=%Id lParam=%Id\n", hwnd, wParam, lParam);
757 /* hide caret on first KEYDOWN to prevent flicker */
758 if ((lParam & PFD_DOUBLEBUFFER_DONTCARE) == 0)
759 NtUserHideCaret( hwnd );
761 switch(wParam)
763 case VK_PRIOR: wParam = SB_PAGEUP; break;
764 case VK_NEXT: wParam = SB_PAGEDOWN; break;
765 case VK_HOME: wParam = SB_TOP; break;
766 case VK_END: wParam = SB_BOTTOM; break;
767 case VK_UP: wParam = SB_LINEUP; break;
768 case VK_DOWN: wParam = SB_LINEDOWN; break;
769 case VK_LEFT: wParam = SB_LINEUP; break;
770 case VK_RIGHT: wParam = SB_LINEDOWN; break;
771 default: return;
773 SendMessageW(GetParent(hwnd),
774 ((GetWindowLongW( hwnd, GWL_STYLE ) & SBS_VERT) ?
775 WM_VSCROLL : WM_HSCROLL), wParam, (LPARAM)hwnd);
779 /***********************************************************************
780 * SCROLL_HandleScrollEvent
782 * Handle a mouse or timer event for the scrollbar.
783 * 'pt' is the location of the mouse event in client (for SB_CTL) or
784 * windows coordinates.
786 void SCROLL_HandleScrollEvent( HWND hwnd, INT nBar, UINT msg, POINT pt )
788 /* Previous mouse position for timer events */
789 static POINT prevPt;
790 /* Thumb position when tracking started. */
791 static UINT trackThumbPos;
792 /* Position in the scroll-bar of the last button-down event. */
793 static INT lastClickPos;
794 /* Position in the scroll-bar of the last mouse event. */
795 static INT lastMousePos;
797 enum SCROLL_HITTEST hittest;
798 HWND hwndOwner, hwndCtl;
799 TRACKMOUSEEVENT tme;
800 BOOL vertical;
801 INT arrowSize, thumbSize, thumbPos;
802 RECT rect;
803 HDC hdc;
805 SCROLLBAR_INFO *infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, FALSE );
806 if (!infoPtr) return;
807 if ((g_tracking_info.hit_test == SCROLL_NOWHERE)
808 && (msg != WM_LBUTTONDOWN && msg != WM_MOUSEMOVE && msg != WM_MOUSELEAVE
809 && msg != WM_NCMOUSEMOVE && msg != WM_NCMOUSELEAVE))
810 return;
812 if (nBar == SB_CTL && (GetWindowLongW( hwnd, GWL_STYLE ) & (SBS_SIZEGRIP | SBS_SIZEBOX)))
814 switch(msg)
816 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
817 NtUserHideCaret( hwnd ); /* hide caret while holding down LBUTTON */
818 NtUserSetCapture( hwnd );
819 prevPt = pt;
820 g_tracking_info.hit_test = hittest = SCROLL_THUMB;
821 break;
822 case WM_MOUSEMOVE:
823 GetClientRect(GetParent(GetParent(hwnd)),&rect);
824 prevPt = pt;
825 break;
826 case WM_LBUTTONUP:
827 ReleaseCapture();
828 g_tracking_info.hit_test = hittest = SCROLL_NOWHERE;
829 if (hwnd == GetFocus()) NtUserShowCaret( hwnd );
830 break;
831 case WM_SYSTIMER:
832 pt = prevPt;
833 break;
835 return;
838 hdc = NtUserGetDCEx( hwnd, 0, DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW));
839 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
840 &arrowSize, &thumbSize, &thumbPos );
841 hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd) : hwnd;
842 hwndCtl = (nBar == SB_CTL) ? hwnd : 0;
844 switch(msg)
846 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
847 NtUserHideCaret( hwnd ); /* hide caret while holding down LBUTTON */
848 g_tracking_info.vertical = vertical;
849 g_tracking_info.hit_test = hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
850 lastClickPos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
851 lastMousePos = lastClickPos;
852 trackThumbPos = thumbPos;
853 prevPt = pt;
854 if (nBar == SB_CTL && (GetWindowLongW(hwnd, GWL_STYLE) & WS_TABSTOP)) NtUserSetFocus( hwnd );
855 NtUserSetCapture( hwnd );
856 break;
858 case WM_MOUSEMOVE:
859 hittest = SCROLL_HitTest( hwnd, nBar, pt, vertical == g_tracking_info.vertical && GetCapture() == hwnd );
860 prevPt = pt;
862 if (nBar != SB_CTL)
863 break;
865 tme.cbSize = sizeof(tme);
866 tme.dwFlags = TME_QUERY;
867 NtUserTrackMouseEvent( &tme );
868 if (!(tme.dwFlags & TME_LEAVE) || tme.hwndTrack != hwnd)
870 tme.dwFlags = TME_LEAVE;
871 tme.hwndTrack = hwnd;
872 NtUserTrackMouseEvent( &tme );
875 break;
877 case WM_NCMOUSEMOVE:
878 hittest = SCROLL_HitTest( hwnd, nBar, pt, vertical == g_tracking_info.vertical && GetCapture() == hwnd );
879 prevPt = pt;
881 if (nBar == SB_CTL)
882 break;
884 tme.cbSize = sizeof(tme);
885 tme.dwFlags = TME_QUERY;
886 NtUserTrackMouseEvent( &tme );
887 if (((tme.dwFlags & (TME_NONCLIENT | TME_LEAVE)) != (TME_NONCLIENT | TME_LEAVE)) || tme.hwndTrack != hwnd)
889 tme.dwFlags = TME_NONCLIENT | TME_LEAVE;
890 tme.hwndTrack = hwnd;
891 NtUserTrackMouseEvent( &tme );
894 break;
896 case WM_NCMOUSELEAVE:
897 if (nBar == SB_CTL)
898 return;
900 hittest = SCROLL_NOWHERE;
901 break;
903 case WM_MOUSELEAVE:
904 if (nBar != SB_CTL)
905 return;
907 hittest = SCROLL_NOWHERE;
908 break;
910 case WM_LBUTTONUP:
911 hittest = SCROLL_NOWHERE;
912 ReleaseCapture();
913 /* if scrollbar has focus, show back caret */
914 if (hwnd == GetFocus()) NtUserShowCaret( hwnd );
915 break;
917 case WM_SYSTIMER:
918 pt = prevPt;
919 hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
920 break;
922 default:
923 return; /* Should never happen */
926 TRACE("Event: hwnd=%p bar=%d msg=%s pt=%ld,%ld hit=%d\n",
927 hwnd, nBar, SPY_GetMsgName(msg,hwnd), pt.x, pt.y, hittest );
929 switch (g_tracking_info.hit_test)
931 case SCROLL_NOWHERE: /* No tracking in progress */
932 /* For standard scroll bars, hovered state gets painted only when the scroll bar was
933 * previously painted by DefWinProc(). If an application handles WM_NCPAINT by itself, then
934 * the scrollbar shouldn't be repainted here to avoid overwriting the application painted
935 * content */
936 if (msg == WM_MOUSEMOVE || msg == WM_MOUSELEAVE
937 || ((msg == WM_NCMOUSEMOVE || msg == WM_NCMOUSELEAVE)
938 && SCROLL_IsStandardScrollPainted( hwnd, nBar)))
939 SCROLL_DrawScrollBar( hwnd, hdc, nBar, hittest, &g_tracking_info, TRUE, TRUE );
940 break;
942 case SCROLL_TOP_ARROW:
943 SCROLL_DrawScrollBar( hwnd, hdc, nBar, hittest, &g_tracking_info, TRUE, FALSE );
944 if (hittest == g_tracking_info.hit_test)
946 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
948 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
949 SB_LINEUP, (LPARAM)hwndCtl );
952 NtUserSetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
953 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY );
955 else KillSystemTimer( hwnd, SCROLL_TIMER );
956 break;
958 case SCROLL_TOP_RECT:
959 SCROLL_DrawScrollBar( hwnd, hdc, nBar, hittest, &g_tracking_info, FALSE, TRUE );
960 if (hittest == g_tracking_info.hit_test)
962 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
964 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
965 SB_PAGEUP, (LPARAM)hwndCtl );
967 NtUserSetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
968 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY );
970 else KillSystemTimer( hwnd, SCROLL_TIMER );
971 break;
973 case SCROLL_THUMB:
974 if (msg == WM_LBUTTONDOWN)
976 g_tracking_info.win = hwnd;
977 g_tracking_info.bar = nBar;
978 g_tracking_info.thumb_pos = trackThumbPos + lastMousePos - lastClickPos;
979 g_tracking_info.thumb_val = SCROLL_GetThumbVal( hwnd, infoPtr, &rect, vertical,
980 g_tracking_info.thumb_pos );
981 if (!SCROLL_MovingThumb)
983 SCROLL_MovingThumb = TRUE;
984 SCROLL_DrawScrollBar( hwnd, hdc, nBar, hittest, &g_tracking_info, FALSE, TRUE );
987 else if (msg == WM_LBUTTONUP)
989 SCROLL_DrawScrollBar( hwnd, hdc, nBar, SCROLL_NOWHERE, &g_tracking_info, FALSE, TRUE );
991 else if (msg == WM_MOUSEMOVE)
993 INT pos;
995 if (!SCROLL_PtInRectEx( &rect, pt, vertical )) pos = lastClickPos;
996 else
998 pt = SCROLL_ClipPos( &rect, pt );
999 pos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
1001 if ( (pos != lastMousePos) || (!SCROLL_MovingThumb) )
1003 lastMousePos = pos;
1004 g_tracking_info.thumb_pos = trackThumbPos + pos - lastClickPos;
1005 g_tracking_info.thumb_val = SCROLL_GetThumbVal( hwnd, infoPtr, &rect, vertical,
1006 g_tracking_info.thumb_pos );
1007 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1008 MAKEWPARAM( SB_THUMBTRACK, g_tracking_info.thumb_val ),
1009 (LPARAM)hwndCtl );
1010 SCROLL_MovingThumb = TRUE;
1011 SCROLL_DrawScrollBar( hwnd, hdc, nBar, hittest, &g_tracking_info, FALSE, TRUE );
1014 break;
1016 case SCROLL_BOTTOM_RECT:
1017 SCROLL_DrawScrollBar( hwnd, hdc, nBar, hittest, &g_tracking_info, FALSE, TRUE );
1018 if (hittest == g_tracking_info.hit_test)
1020 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1022 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1023 SB_PAGEDOWN, (LPARAM)hwndCtl );
1025 NtUserSetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1026 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY );
1028 else KillSystemTimer( hwnd, SCROLL_TIMER );
1029 break;
1031 case SCROLL_BOTTOM_ARROW:
1032 SCROLL_DrawScrollBar( hwnd, hdc, nBar, hittest, &g_tracking_info, TRUE, FALSE );
1033 if (hittest == g_tracking_info.hit_test)
1035 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1037 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1038 SB_LINEDOWN, (LPARAM)hwndCtl );
1041 NtUserSetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1042 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY );
1044 else KillSystemTimer( hwnd, SCROLL_TIMER );
1045 break;
1048 if (msg == WM_LBUTTONDOWN)
1051 if (hittest == SCROLL_THUMB)
1053 UINT val = SCROLL_GetThumbVal( hwnd, infoPtr, &rect, vertical,
1054 trackThumbPos + lastMousePos - lastClickPos );
1055 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1056 MAKEWPARAM( SB_THUMBTRACK, val ), (LPARAM)hwndCtl );
1060 if (msg == WM_LBUTTONUP)
1062 hittest = g_tracking_info.hit_test;
1063 g_tracking_info.hit_test = SCROLL_NOWHERE; /* Terminate tracking */
1065 if (hittest == SCROLL_THUMB)
1067 UINT val = SCROLL_GetThumbVal( hwnd, infoPtr, &rect, vertical,
1068 trackThumbPos + lastMousePos - lastClickPos );
1069 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1070 MAKEWPARAM( SB_THUMBPOSITION, val ), (LPARAM)hwndCtl );
1072 /* SB_ENDSCROLL doesn't report thumb position */
1073 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1074 SB_ENDSCROLL, (LPARAM)hwndCtl );
1076 /* Terminate tracking */
1077 g_tracking_info.win = 0;
1078 SCROLL_MovingThumb = FALSE;
1079 hittest = SCROLL_NOWHERE;
1080 SCROLL_DrawScrollBar( hwnd, hdc, nBar, hittest, &g_tracking_info, TRUE, TRUE );
1083 NtUserReleaseDC( hwnd, hdc );
1087 /***********************************************************************
1088 * SCROLL_TrackScrollBar
1090 * Track a mouse button press on a scroll-bar.
1091 * pt is in screen-coordinates for non-client scroll bars.
1093 void SCROLL_TrackScrollBar( HWND hwnd, INT scrollbar, POINT pt )
1095 MSG msg;
1096 RECT rect;
1098 if (scrollbar != SB_CTL)
1100 WIN_GetRectangles( hwnd, COORDS_CLIENT, &rect, NULL );
1101 ScreenToClient( hwnd, &pt );
1102 pt.x -= rect.left;
1103 pt.y -= rect.top;
1105 else
1106 rect.left = rect.top = 0;
1108 SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt );
1112 if (!GetMessageW( &msg, 0, 0, 0 )) break;
1113 if (NtUserCallMsgFilter( &msg, MSGF_SCROLLBAR )) continue;
1114 if (msg.message == WM_LBUTTONUP ||
1115 msg.message == WM_MOUSEMOVE ||
1116 msg.message == WM_MOUSELEAVE ||
1117 msg.message == WM_NCMOUSEMOVE ||
1118 msg.message == WM_NCMOUSELEAVE ||
1119 (msg.message == WM_SYSTIMER && msg.wParam == SCROLL_TIMER))
1121 pt.x = (short)LOWORD(msg.lParam) - rect.left;
1122 pt.y = (short)HIWORD(msg.lParam) - rect.top;
1123 SCROLL_HandleScrollEvent( hwnd, scrollbar, msg.message, pt );
1125 else
1127 TranslateMessage( &msg );
1128 DispatchMessageW( &msg );
1130 if (!IsWindow( hwnd ))
1132 ReleaseCapture();
1133 break;
1135 } while (msg.message != WM_LBUTTONUP && GetCapture() == hwnd);
1139 /***********************************************************************
1140 * SCROLL_CreateScrollBar
1142 * Create a scroll bar
1144 * PARAMS
1145 * hwnd [I] Handle of window with scrollbar(s)
1146 * lpCreate [I] The style and place of the scroll bar
1148 static void SCROLL_CreateScrollBar(HWND hwnd, LPCREATESTRUCTW lpCreate)
1150 LPSCROLLBAR_INFO info = NULL;
1151 WND *win;
1153 TRACE("hwnd=%p lpCreate=%p\n", hwnd, lpCreate);
1155 win = WIN_GetPtr(hwnd);
1156 if (win->cbWndExtra >= sizeof(SCROLLBAR_WNDDATA))
1158 SCROLLBAR_WNDDATA *data = (SCROLLBAR_WNDDATA*)win->wExtra;
1159 data->magic = SCROLLBAR_MAGIC;
1160 info = &data->info;
1162 else WARN("Not enough extra data\n");
1163 WIN_ReleasePtr(win);
1164 if (!info) return;
1166 if (lpCreate->style & WS_DISABLED)
1168 info->flags = ESB_DISABLE_BOTH;
1169 TRACE("Created WS_DISABLED scrollbar\n");
1172 if (lpCreate->style & (SBS_SIZEGRIP | SBS_SIZEBOX))
1174 if (lpCreate->style & SBS_SIZEBOXTOPLEFTALIGN)
1175 NtUserMoveWindow( hwnd, lpCreate->x, lpCreate->y, GetSystemMetrics(SM_CXVSCROLL)+1,
1176 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1177 else if(lpCreate->style & SBS_SIZEBOXBOTTOMRIGHTALIGN)
1178 NtUserMoveWindow( hwnd, lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1179 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1180 GetSystemMetrics(SM_CXVSCROLL)+1,
1181 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1183 else if (lpCreate->style & SBS_VERT)
1185 if (lpCreate->style & SBS_LEFTALIGN)
1186 NtUserMoveWindow( hwnd, lpCreate->x, lpCreate->y,
1187 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1188 else if (lpCreate->style & SBS_RIGHTALIGN)
1189 NtUserMoveWindow( hwnd,
1190 lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1191 lpCreate->y,
1192 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1194 else /* SBS_HORZ */
1196 if (lpCreate->style & SBS_TOPALIGN)
1197 NtUserMoveWindow( hwnd, lpCreate->x, lpCreate->y,
1198 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1199 else if (lpCreate->style & SBS_BOTTOMALIGN)
1200 NtUserMoveWindow( hwnd,
1201 lpCreate->x,
1202 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1203 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1208 /*************************************************************************
1209 * SCROLL_GetScrollInfo
1211 * Internal helper for the API function
1213 * PARAMS
1214 * hwnd [I] Handle of window with scrollbar(s)
1215 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1216 * info [IO] fMask specifies which values to retrieve
1218 * RETURNS
1219 * FALSE if requested field not filled (f.i. scroll bar does not exist)
1221 static BOOL SCROLL_GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1223 LPSCROLLBAR_INFO infoPtr;
1225 /* handle invalid data structure */
1226 if (!SCROLL_ScrollInfoValid(info)
1227 || !(infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE)))
1228 return FALSE;
1230 /* fill in the desired scroll info structure */
1231 if (info->fMask & SIF_PAGE) info->nPage = infoPtr->page;
1232 if (info->fMask & SIF_POS) info->nPos = infoPtr->curVal;
1233 if ((info->fMask & SIF_TRACKPOS) && (info->cbSize == sizeof(*info)))
1234 info->nTrackPos = (g_tracking_info.win == WIN_GetFullHandle(hwnd)) ? g_tracking_info.thumb_val : infoPtr->curVal;
1235 if (info->fMask & SIF_RANGE)
1237 info->nMin = infoPtr->minVal;
1238 info->nMax = infoPtr->maxVal;
1241 TRACE("cbSize %02x fMask %04x nMin %d nMax %d nPage %u nPos %d nTrackPos %d\n",
1242 info->cbSize, info->fMask, info->nMin, info->nMax, info->nPage,
1243 info->nPos, info->nTrackPos);
1245 return (info->fMask & SIF_ALL) != 0;
1249 /*************************************************************************
1250 * SCROLL_GetScrollBarInfo
1252 * Internal helper for the API function
1254 * PARAMS
1255 * hwnd [I] Handle of window with scrollbar(s)
1256 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1257 * info [IO] cbSize specifies the size of the structure
1259 * RETURNS
1260 * FALSE if failed
1262 static BOOL SCROLL_GetScrollBarInfo(HWND hwnd, LONG idObject, LPSCROLLBARINFO info)
1264 LPSCROLLBAR_INFO infoPtr;
1265 INT nBar;
1266 INT nDummy;
1267 DWORD style = GetWindowLongW(hwnd, GWL_STYLE);
1268 BOOL pressed;
1269 RECT rect;
1271 switch (idObject)
1273 case OBJID_CLIENT: nBar = SB_CTL; break;
1274 case OBJID_HSCROLL: nBar = SB_HORZ; break;
1275 case OBJID_VSCROLL: nBar = SB_VERT; break;
1276 default: return FALSE;
1279 /* handle invalid data structure */
1280 if (info->cbSize != sizeof(*info))
1281 return FALSE;
1283 SCROLL_GetScrollBarRect(hwnd, nBar, &info->rcScrollBar, &nDummy,
1284 &info->dxyLineButton, &info->xyThumbTop);
1285 /* rcScrollBar needs to be in screen coordinates */
1286 GetWindowRect(hwnd, &rect);
1287 OffsetRect(&info->rcScrollBar, rect.left, rect.top);
1289 info->xyThumbBottom = info->xyThumbTop + info->dxyLineButton;
1291 infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, TRUE);
1292 if (!infoPtr)
1293 return FALSE;
1295 /* Scroll bar state */
1296 info->rgstate[0] = 0;
1297 if ((nBar == SB_HORZ && !(style & WS_HSCROLL))
1298 || (nBar == SB_VERT && !(style & WS_VSCROLL)))
1299 info->rgstate[0] |= STATE_SYSTEM_INVISIBLE;
1300 if (infoPtr->minVal >= infoPtr->maxVal - max(infoPtr->page - 1, 0))
1302 if (!(info->rgstate[0] & STATE_SYSTEM_INVISIBLE))
1303 info->rgstate[0] |= STATE_SYSTEM_UNAVAILABLE;
1304 else
1305 info->rgstate[0] |= STATE_SYSTEM_OFFSCREEN;
1307 if (nBar == SB_CTL && !IsWindowEnabled(hwnd))
1308 info->rgstate[0] |= STATE_SYSTEM_UNAVAILABLE;
1310 pressed = ((nBar == SB_VERT) == g_tracking_info.vertical && GetCapture() == hwnd);
1312 /* Top/left arrow button state. MSDN says top/right, but I don't believe it */
1313 info->rgstate[1] = 0;
1314 if (pressed && g_tracking_info.hit_test == SCROLL_TOP_ARROW)
1315 info->rgstate[1] |= STATE_SYSTEM_PRESSED;
1316 if (infoPtr->flags & ESB_DISABLE_LTUP)
1317 info->rgstate[1] |= STATE_SYSTEM_UNAVAILABLE;
1319 /* Page up/left region state. MSDN says up/right, but I don't believe it */
1320 info->rgstate[2] = 0;
1321 if (infoPtr->curVal == infoPtr->minVal)
1322 info->rgstate[2] |= STATE_SYSTEM_INVISIBLE;
1323 if (pressed && g_tracking_info.hit_test == SCROLL_TOP_RECT)
1324 info->rgstate[2] |= STATE_SYSTEM_PRESSED;
1326 /* Thumb state */
1327 info->rgstate[3] = 0;
1328 if (pressed && g_tracking_info.hit_test == SCROLL_THUMB)
1329 info->rgstate[3] |= STATE_SYSTEM_PRESSED;
1331 /* Page down/right region state. MSDN says down/left, but I don't believe it */
1332 info->rgstate[4] = 0;
1333 if (infoPtr->curVal >= infoPtr->maxVal - 1)
1334 info->rgstate[4] |= STATE_SYSTEM_INVISIBLE;
1335 if (pressed && g_tracking_info.hit_test == SCROLL_BOTTOM_RECT)
1336 info->rgstate[4] |= STATE_SYSTEM_PRESSED;
1338 /* Bottom/right arrow button state. MSDN says bottom/left, but I don't believe it */
1339 info->rgstate[5] = 0;
1340 if (pressed && g_tracking_info.hit_test == SCROLL_BOTTOM_ARROW)
1341 info->rgstate[5] |= STATE_SYSTEM_PRESSED;
1342 if (infoPtr->flags & ESB_DISABLE_RTDN)
1343 info->rgstate[5] |= STATE_SYSTEM_UNAVAILABLE;
1345 return TRUE;
1349 /*************************************************************************
1350 * SCROLL_GetScrollPos
1352 * Internal helper for the API function
1354 * PARAMS
1355 * hwnd [I] Handle of window with scrollbar(s)
1356 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1358 static INT SCROLL_GetScrollPos(HWND hwnd, INT nBar)
1360 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1361 return infoPtr ? infoPtr->curVal: 0;
1365 /*************************************************************************
1366 * SCROLL_GetScrollRange
1368 * Internal helper for the API function
1370 * PARAMS
1371 * hwnd [I] Handle of window with scrollbar(s)
1372 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1373 * lpMin [O] Where to store minimum value
1374 * lpMax [O] Where to store maximum value
1376 * RETURNS
1377 * Success: TRUE
1378 * Failure: FALSE
1380 static BOOL SCROLL_GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1382 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1384 if (lpMin) *lpMin = infoPtr ? infoPtr->minVal : 0;
1385 if (lpMax) *lpMax = infoPtr ? infoPtr->maxVal : 0;
1387 return TRUE;
1391 /*************************************************************************
1392 * SCROLL_SetScrollRange
1394 * PARAMS
1395 * hwnd [I] Handle of window with scrollbar(s)
1396 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1397 * lpMin [I] Minimum value
1398 * lpMax [I] Maximum value
1401 static BOOL SCROLL_SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal)
1403 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1405 TRACE("hwnd=%p nBar=%d min=%d max=%d\n", hwnd, nBar, minVal, maxVal);
1407 if (infoPtr)
1409 infoPtr->minVal = minVal;
1410 infoPtr->maxVal = maxVal;
1412 return TRUE;
1415 LRESULT WINAPI USER_ScrollBarProc( 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_NCMOUSEMOVE:
1454 case WM_NCMOUSELEAVE:
1455 case WM_MOUSEMOVE:
1456 case WM_MOUSELEAVE:
1457 case WM_SYSTIMER:
1459 POINT pt;
1460 pt.x = (short)LOWORD(lParam);
1461 pt.y = (short)HIWORD(lParam);
1462 SCROLL_HandleScrollEvent( hwnd, SB_CTL, message, pt );
1464 break;
1466 case WM_KEYDOWN:
1467 SCROLL_HandleKbdEvent(hwnd, wParam, lParam);
1468 break;
1470 case WM_KEYUP:
1471 NtUserShowCaret( hwnd );
1472 break;
1474 case WM_SETFOCUS:
1476 /* Create a caret when a ScrollBar get focus */
1477 RECT rect;
1478 int arrowSize, thumbSize, thumbPos, vertical;
1479 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,
1480 &arrowSize, &thumbSize, &thumbPos );
1481 if (!vertical)
1483 NtUserCreateCaret( hwnd, (HBITMAP)1, thumbSize - 2, rect.bottom - rect.top - 2 );
1484 SetCaretPos(thumbPos+1, rect.top+1);
1486 else
1488 NtUserCreateCaret( hwnd, (HBITMAP)1, rect.right - rect.left - 2, thumbSize - 2);
1489 SetCaretPos(rect.top+1, thumbPos+1);
1491 NtUserShowCaret( hwnd );
1493 break;
1495 case WM_KILLFOCUS:
1497 RECT rect;
1498 int arrowSize, thumbSize, thumbPos, vertical;
1499 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,&arrowSize, &thumbSize, &thumbPos );
1500 if (!vertical){
1501 rect.left=thumbPos+1;
1502 rect.right=rect.left+thumbSize;
1504 else
1506 rect.top=thumbPos+1;
1507 rect.bottom=rect.top+thumbSize;
1509 NtUserHideCaret( hwnd );
1510 NtUserInvalidateRect( hwnd, &rect, 0 );
1511 DestroyCaret();
1513 break;
1515 case WM_ERASEBKGND:
1516 return 1;
1518 case WM_GETDLGCODE:
1519 return DLGC_WANTARROWS; /* Windows returns this value */
1521 case WM_PAINT:
1523 PAINTSTRUCT ps;
1524 HDC hdc = wParam ? (HDC)wParam : NtUserBeginPaint( hwnd, &ps );
1525 SCROLL_DrawScrollBar( hwnd, hdc, SB_CTL, g_tracking_info.hit_test, &g_tracking_info, TRUE, TRUE );
1526 if (!wParam) NtUserEndPaint( hwnd, &ps );
1528 break;
1530 case WM_SETCURSOR:
1531 if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEGRIP)
1533 ULONG_PTR cursor = (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_LAYOUTRTL) ? IDC_SIZENESW : IDC_SIZENWSE;
1534 return (LRESULT)NtUserSetCursor( LoadCursorA( 0, (LPSTR)cursor ));
1536 return DefWindowProcW( hwnd, message, wParam, lParam );
1538 case SBM_SETPOS:
1539 return SetScrollPos( hwnd, SB_CTL, wParam, (BOOL)lParam );
1541 case SBM_GETPOS:
1542 return SCROLL_GetScrollPos(hwnd, SB_CTL);
1544 case SBM_SETRANGEREDRAW:
1545 case SBM_SETRANGE:
1547 INT oldPos = SCROLL_GetScrollPos( hwnd, SB_CTL );
1548 SCROLL_SetScrollRange( hwnd, SB_CTL, wParam, lParam );
1549 if (message == SBM_SETRANGEREDRAW)
1550 SCROLL_RefreshScrollBar( hwnd, SB_CTL, TRUE, TRUE );
1551 if (oldPos != SCROLL_GetScrollPos( hwnd, SB_CTL )) return oldPos;
1553 return 0;
1555 case SBM_GETRANGE:
1556 return SCROLL_GetScrollRange(hwnd, SB_CTL, (LPINT)wParam, (LPINT)lParam);
1558 case SBM_ENABLE_ARROWS:
1559 return EnableScrollBar( hwnd, SB_CTL, wParam );
1561 case SBM_SETSCROLLINFO:
1562 return SCROLL_SetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam, wParam );
1564 case SBM_GETSCROLLINFO:
1565 return SCROLL_GetScrollInfo(hwnd, SB_CTL, (SCROLLINFO *)lParam);
1567 case SBM_GETSCROLLBARINFO:
1568 return SCROLL_GetScrollBarInfo(hwnd, OBJID_CLIENT, (SCROLLBARINFO *)lParam);
1570 case 0x00e5:
1571 case 0x00e7:
1572 case 0x00e8:
1573 case 0x00ec:
1574 case 0x00ed:
1575 case 0x00ee:
1576 case 0x00ef:
1577 ERR("unknown Win32 msg %04x wp=%08Ix lp=%08Ix\n",
1578 message, wParam, lParam );
1579 break;
1581 default:
1582 if (message >= WM_USER)
1583 WARN("unknown msg %04x wp=%04Ix lp=%08Ix\n",
1584 message, wParam, lParam );
1585 if (unicode)
1586 return DefWindowProcW( hwnd, message, wParam, lParam );
1587 else
1588 return DefWindowProcA( hwnd, message, wParam, lParam );
1590 return 0;
1593 /***********************************************************************
1594 * ScrollBarWndProc_common
1596 LRESULT ScrollBarWndProc_common( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode )
1598 return user_api->pScrollBarWndProc( hwnd, msg, wParam, lParam, unicode );
1601 /*************************************************************************
1602 * SetScrollInfo (USER32.@)
1604 * SetScrollInfo can be used to set the position, upper bound,
1605 * lower bound, and page size of a scrollbar control.
1607 * PARAMS
1608 * hwnd [I] Handle of window with scrollbar(s)
1609 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1610 * info [I] Specifies what to change and new values
1611 * bRedraw [I] Should scrollbar be redrawn afterwards?
1613 * RETURNS
1614 * Scrollbar position
1616 * NOTE
1617 * For 100 lines of text to be displayed in a window of 25 lines,
1618 * one would for instance use info->nMin=0, info->nMax=75
1619 * (corresponding to the 76 different positions of the window on
1620 * the text), and info->nPage=25.
1622 INT WINAPI DECLSPEC_HOTPATCH SetScrollInfo(HWND hwnd, INT nBar, const SCROLLINFO *info, BOOL bRedraw)
1624 TRACE("hwnd=%p nBar=%d info=%p, bRedraw=%d\n", hwnd, nBar, info, bRedraw);
1626 /* Refer SB_CTL requests to the window */
1627 if (nBar == SB_CTL)
1628 return SendMessageW(hwnd, SBM_SETSCROLLINFO, bRedraw, (LPARAM)info);
1629 else
1630 return SCROLL_SetScrollInfo( hwnd, nBar, info, bRedraw );
1633 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar, LPCSCROLLINFO info, BOOL bRedraw )
1635 /* Update the scrollbar state and set action flags according to
1636 * what has to be done graphics wise. */
1638 SCROLLBAR_INFO *infoPtr;
1639 UINT new_flags;
1640 INT action = 0;
1642 /* handle invalid data structure */
1643 if (!SCROLL_ScrollInfoValid(info)
1644 || !(infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, TRUE)))
1645 return 0;
1647 if (TRACE_ON(scroll))
1649 TRACE("hwnd=%p bar=%d", hwnd, nBar);
1650 if (info->fMask & SIF_PAGE) TRACE( " page=%d", info->nPage );
1651 if (info->fMask & SIF_POS) TRACE( " pos=%d", info->nPos );
1652 if (info->fMask & SIF_RANGE) TRACE( " min=%d max=%d", info->nMin, info->nMax );
1653 TRACE("\n");
1656 /* Set the page size */
1658 if (info->fMask & SIF_PAGE)
1660 if( infoPtr->page != info->nPage )
1662 infoPtr->page = info->nPage;
1663 action |= SA_SSI_REFRESH;
1667 /* Set the scroll pos */
1669 if (info->fMask & SIF_POS)
1671 if( infoPtr->curVal != info->nPos )
1673 infoPtr->curVal = info->nPos;
1674 action |= SA_SSI_REFRESH;
1678 /* Set the scroll range */
1680 if (info->fMask & SIF_RANGE)
1682 /* Invalid range -> range is set to (0,0) */
1683 if ((info->nMin > info->nMax) ||
1684 ((UINT)(info->nMax - info->nMin) >= 0x80000000))
1686 action |= SA_SSI_REFRESH;
1687 infoPtr->minVal = 0;
1688 infoPtr->maxVal = 0;
1690 else
1692 if( infoPtr->minVal != info->nMin ||
1693 infoPtr->maxVal != info->nMax )
1695 action |= SA_SSI_REFRESH;
1696 infoPtr->minVal = info->nMin;
1697 infoPtr->maxVal = info->nMax;
1702 /* Make sure the page size is valid */
1703 if (infoPtr->page < 0) infoPtr->page = 0;
1704 else if (infoPtr->page > infoPtr->maxVal - infoPtr->minVal + 1 )
1705 infoPtr->page = infoPtr->maxVal - infoPtr->minVal + 1;
1707 /* Make sure the pos is inside the range */
1709 if (infoPtr->curVal < infoPtr->minVal)
1710 infoPtr->curVal = infoPtr->minVal;
1711 else if (infoPtr->curVal > infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1712 infoPtr->curVal = infoPtr->maxVal - max( infoPtr->page-1, 0 );
1714 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1715 infoPtr->page, infoPtr->curVal,
1716 infoPtr->minVal, infoPtr->maxVal );
1718 /* don't change the scrollbar state if SetScrollInfo
1719 * is just called with SIF_DISABLENOSCROLL
1721 if(!(info->fMask & SIF_ALL)) goto done;
1723 /* Check if the scrollbar should be hidden or disabled */
1725 if (info->fMask & (SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL))
1727 new_flags = infoPtr->flags;
1728 if (infoPtr->minVal >= infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1730 /* Hide or disable scroll-bar */
1731 if (info->fMask & SIF_DISABLENOSCROLL)
1733 new_flags = ESB_DISABLE_BOTH;
1734 action |= SA_SSI_REFRESH;
1736 else if ((nBar != SB_CTL) && (action & SA_SSI_REFRESH))
1738 action = SA_SSI_HIDE;
1741 else /* Show and enable scroll-bar only if no page only changed. */
1742 if (info->fMask != SIF_PAGE)
1744 new_flags = ESB_ENABLE_BOTH;
1745 if ((nBar != SB_CTL) && ( (action & SA_SSI_REFRESH) ))
1746 action |= SA_SSI_SHOW;
1749 if (nBar == SB_CTL && bRedraw && IsWindowVisible(hwnd) &&
1750 (new_flags == ESB_ENABLE_BOTH || new_flags == ESB_DISABLE_BOTH))
1752 EnableWindow(hwnd, new_flags == ESB_ENABLE_BOTH);
1755 if (infoPtr->flags != new_flags) /* check arrow flags */
1757 infoPtr->flags = new_flags;
1758 action |= SA_SSI_REPAINT_ARROWS;
1762 done:
1763 if( action & SA_SSI_HIDE )
1764 SCROLL_ShowScrollBar( hwnd, nBar, FALSE, FALSE );
1765 else
1767 if( action & SA_SSI_SHOW )
1768 if( SCROLL_ShowScrollBar( hwnd, nBar, TRUE, TRUE ) )
1769 return infoPtr->curVal; /* SetWindowPos() already did the painting */
1771 if( bRedraw )
1772 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
1773 else if( action & SA_SSI_REPAINT_ARROWS )
1774 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, FALSE );
1777 /* Return current position */
1778 return infoPtr->curVal;
1782 /*************************************************************************
1783 * GetScrollInfo (USER32.@)
1785 * GetScrollInfo can be used to retrieve the position, upper bound,
1786 * lower bound, and page size of a scrollbar control.
1788 * PARAMS
1789 * hwnd [I] Handle of window with scrollbar(s)
1790 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1791 * info [IO] fMask specifies which values to retrieve
1793 * RETURNS
1794 * TRUE if SCROLLINFO is filled
1795 * ( if nBar is SB_CTL, GetScrollInfo returns TRUE even if nothing
1796 * is filled)
1798 BOOL WINAPI DECLSPEC_HOTPATCH GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1800 TRACE("hwnd=%p nBar=%d info=%p\n", hwnd, nBar, info);
1802 /* Refer SB_CTL requests to the window */
1803 if (nBar == SB_CTL)
1805 SendMessageW(hwnd, SBM_GETSCROLLINFO, 0, (LPARAM)info);
1806 return TRUE;
1808 return SCROLL_GetScrollInfo(hwnd, nBar, info);
1812 /*************************************************************************
1813 * GetScrollBarInfo (USER32.@)
1815 * GetScrollBarInfo can be used to retrieve information about a scrollbar
1816 * control.
1818 * PARAMS
1819 * hwnd [I] Handle of window with scrollbar(s)
1820 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1821 * info [IO] cbSize specifies the size of SCROLLBARINFO
1823 * RETURNS
1824 * TRUE if success
1826 BOOL WINAPI GetScrollBarInfo(HWND hwnd, LONG idObject, LPSCROLLBARINFO info)
1828 TRACE("hwnd=%p idObject=%ld info=%p\n", hwnd, idObject, info);
1830 /* Refer OBJID_CLIENT requests to the window */
1831 if (idObject == OBJID_CLIENT)
1832 return SendMessageW(hwnd, SBM_GETSCROLLBARINFO, 0, (LPARAM)info);
1833 else
1834 return SCROLL_GetScrollBarInfo(hwnd, idObject, info);
1838 /*************************************************************************
1839 * SetScrollPos (USER32.@)
1841 * Sets the current position of the scroll thumb.
1843 * PARAMS
1844 * hwnd [I] Handle of window with scrollbar(s)
1845 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1846 * nPos [I] New value
1847 * bRedraw [I] Should scrollbar be redrawn afterwards?
1849 * RETURNS
1850 * Success: Scrollbar position
1851 * Failure: 0
1853 * REMARKS
1854 * Note the ambiguity when 0 is returned. Use GetLastError
1855 * to make sure there was an error (and to know which one).
1857 INT WINAPI DECLSPEC_HOTPATCH SetScrollPos( HWND hwnd, INT nBar, INT nPos, BOOL bRedraw)
1859 SCROLLINFO info;
1860 SCROLLBAR_INFO *infoPtr;
1861 INT oldPos = 0;
1863 if ((infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, FALSE ))) oldPos = infoPtr->curVal;
1864 info.cbSize = sizeof(info);
1865 info.nPos = nPos;
1866 info.fMask = SIF_POS;
1867 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1868 return oldPos;
1872 /*************************************************************************
1873 * GetScrollPos (USER32.@)
1875 * Gets the current position of the scroll thumb.
1877 * PARAMS
1878 * hwnd [I] Handle of window with scrollbar(s)
1879 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1881 * RETURNS
1882 * Success: Current position
1883 * Failure: 0
1885 * REMARKS
1886 * There is ambiguity when 0 is returned. Use GetLastError
1887 * to make sure there was an error (and to know which one).
1889 INT WINAPI DECLSPEC_HOTPATCH GetScrollPos(HWND hwnd, INT nBar)
1891 TRACE("hwnd=%p nBar=%d\n", hwnd, nBar);
1893 /* Refer SB_CTL requests to the window */
1894 if (nBar == SB_CTL)
1895 return SendMessageW(hwnd, SBM_GETPOS, 0, 0);
1896 else
1897 return SCROLL_GetScrollPos(hwnd, nBar);
1901 /*************************************************************************
1902 * SetScrollRange (USER32.@)
1903 * The SetScrollRange function sets the minimum and maximum scroll box positions
1904 * If nMinPos and nMaxPos is the same value, the scroll bar will hide
1906 * Sets the range of the scroll bar.
1908 * PARAMS
1909 * hwnd [I] Handle of window with scrollbar(s)
1910 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1911 * minVal [I] New minimum value
1912 * maxVal [I] New Maximum value
1913 * bRedraw [I] Should scrollbar be redrawn afterwards?
1915 * RETURNS
1916 * Success: TRUE
1917 * Failure: FALSE
1919 BOOL WINAPI DECLSPEC_HOTPATCH SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal, BOOL bRedraw)
1921 SCROLLINFO info;
1923 TRACE("hwnd=%p nBar=%d min=%d max=%d, bRedraw=%d\n", hwnd, nBar, minVal, maxVal, bRedraw);
1925 info.cbSize = sizeof(info);
1926 info.fMask = SIF_RANGE;
1927 info.nMin = minVal;
1928 info.nMax = maxVal;
1929 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1930 return TRUE;
1934 /*************************************************************************
1935 * GetScrollRange (USER32.@)
1937 * Gets the range of the scroll bar.
1939 * PARAMS
1940 * hwnd [I] Handle of window with scrollbar(s)
1941 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1942 * lpMin [O] Where to store minimum value
1943 * lpMax [O] Where to store maximum value
1945 * RETURNS
1946 * TRUE if values is filled
1948 BOOL WINAPI DECLSPEC_HOTPATCH GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1950 TRACE("hwnd=%p nBar=%d lpMin=%p lpMax=%p\n", hwnd, nBar, lpMin, lpMax);
1952 /* Refer SB_CTL requests to the window */
1953 if (nBar == SB_CTL)
1954 SendMessageW(hwnd, SBM_GETRANGE, (WPARAM)lpMin, (LPARAM)lpMax);
1955 else
1956 SCROLL_GetScrollRange(hwnd, nBar, lpMin, lpMax);
1958 return TRUE;
1962 /*************************************************************************
1963 * SCROLL_ShowScrollBar()
1965 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1967 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar, BOOL fShowH, BOOL fShowV )
1969 ULONG old_style, set_bits = 0, clear_bits = 0;
1971 TRACE("hwnd=%p bar=%d horz=%d, vert=%d\n", hwnd, nBar, fShowH, fShowV );
1973 switch(nBar)
1975 case SB_CTL:
1976 NtUserShowWindow( hwnd, fShowH ? SW_SHOW : SW_HIDE );
1977 return TRUE;
1979 case SB_BOTH:
1980 case SB_HORZ:
1981 if (fShowH) set_bits |= WS_HSCROLL;
1982 else clear_bits |= WS_HSCROLL;
1983 if( nBar == SB_HORZ ) break;
1984 /* fall through */
1985 case SB_VERT:
1986 if (fShowV) set_bits |= WS_VSCROLL;
1987 else clear_bits |= WS_VSCROLL;
1988 break;
1990 default:
1991 return FALSE; /* Nothing to do! */
1994 old_style = WIN_SetStyle( hwnd, set_bits, clear_bits );
1995 if ((old_style & clear_bits) != 0 || (old_style & set_bits) != set_bits)
1997 /* frame has been changed, let the window redraw itself */
1998 NtUserSetWindowPos( hwnd, 0, 0, 0, 0, 0,
1999 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
2000 return TRUE;
2002 return FALSE; /* no frame changes */
2006 /*************************************************************************
2007 * ShowScrollBar (USER32.@)
2009 * Shows or hides the scroll bar.
2011 * PARAMS
2012 * hwnd [I] Handle of window with scrollbar(s)
2013 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
2014 * fShow [I] TRUE = show, FALSE = hide
2016 * RETURNS
2017 * Success: TRUE
2018 * Failure: FALSE
2020 BOOL WINAPI DECLSPEC_HOTPATCH ShowScrollBar(HWND hwnd, INT nBar, BOOL fShow)
2022 if ( !hwnd )
2023 return FALSE;
2025 SCROLL_ShowScrollBar( hwnd, nBar, (nBar == SB_VERT) ? 0 : fShow,
2026 (nBar == SB_HORZ) ? 0 : fShow );
2027 return TRUE;
2031 /*************************************************************************
2032 * EnableScrollBar (USER32.@)
2034 * Enables or disables the scroll bars.
2036 BOOL WINAPI DECLSPEC_HOTPATCH EnableScrollBar( HWND hwnd, UINT nBar, UINT flags )
2038 BOOL bFineWithMe;
2039 SCROLLBAR_INFO *infoPtr;
2041 flags &= ESB_DISABLE_BOTH;
2043 if (nBar == SB_BOTH)
2045 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, SB_VERT, TRUE ))) return FALSE;
2046 if (!(bFineWithMe = (infoPtr->flags == flags)) )
2048 infoPtr->flags = flags;
2049 SCROLL_RefreshScrollBar( hwnd, SB_VERT, TRUE, TRUE );
2051 nBar = SB_HORZ;
2053 else
2054 bFineWithMe = nBar != SB_CTL;
2056 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, TRUE ))) return FALSE;
2057 if (bFineWithMe && infoPtr->flags == flags) return FALSE;
2058 infoPtr->flags = flags;
2060 if (nBar == SB_CTL && (flags == ESB_DISABLE_BOTH || flags == ESB_ENABLE_BOTH))
2061 EnableWindow(hwnd, flags == ESB_ENABLE_BOTH);
2063 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
2064 return TRUE;