Store the kernel32 module handle globally to avoid some
[wine/multimedia.git] / controls / scroll.c
blob036fe62e7bd0a84b140b574194f60f5b93cec84b
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
22 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "wine/winuser16.h"
28 #include "controls.h"
29 #include "win.h"
30 #include "wine/debug.h"
31 #include "user.h"
32 #include "message.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(scroll);
36 typedef struct
38 INT curVal; /* Current scroll-bar value */
39 INT minVal; /* Minimum scroll-bar value */
40 INT maxVal; /* Maximum scroll-bar value */
41 INT page; /* Page size of scroll bar (Win32) */
42 UINT flags; /* EnableScrollBar flags */
43 } SCROLLBAR_INFO, *LPSCROLLBAR_INFO;
46 static HBITMAP hUpArrow;
47 static HBITMAP hDnArrow;
48 static HBITMAP hLfArrow;
49 static HBITMAP hRgArrow;
50 static HBITMAP hUpArrowD;
51 static HBITMAP hDnArrowD;
52 static HBITMAP hLfArrowD;
53 static HBITMAP hRgArrowD;
54 static HBITMAP hUpArrowI;
55 static HBITMAP hDnArrowI;
56 static HBITMAP hLfArrowI;
57 static HBITMAP hRgArrowI;
59 #define TOP_ARROW(flags,pressed) \
60 (((flags)&ESB_DISABLE_UP) ? hUpArrowI : ((pressed) ? hUpArrowD:hUpArrow))
61 #define BOTTOM_ARROW(flags,pressed) \
62 (((flags)&ESB_DISABLE_DOWN) ? hDnArrowI : ((pressed) ? hDnArrowD:hDnArrow))
63 #define LEFT_ARROW(flags,pressed) \
64 (((flags)&ESB_DISABLE_LEFT) ? hLfArrowI : ((pressed) ? hLfArrowD:hLfArrow))
65 #define RIGHT_ARROW(flags,pressed) \
66 (((flags)&ESB_DISABLE_RIGHT) ? hRgArrowI : ((pressed) ? hRgArrowD:hRgArrow))
69 /* Minimum size of the rectangle between the arrows */
70 #define SCROLL_MIN_RECT 4
72 /* Minimum size of the thumb in pixels */
73 #define SCROLL_MIN_THUMB 6
75 /* Overlap between arrows and thumb */
76 #define SCROLL_ARROW_THUMB_OVERLAP ((TWEAK_WineLook == WIN31_LOOK) ? 1 : 0)
78 /* Delay (in ms) before first repetition when holding the button down */
79 #define SCROLL_FIRST_DELAY 200
81 /* Delay (in ms) between scroll repetitions */
82 #define SCROLL_REPEAT_DELAY 50
84 /* Scroll timer id */
85 #define SCROLL_TIMER 0
87 /* Scroll-bar hit testing */
88 enum SCROLL_HITTEST
90 SCROLL_NOWHERE, /* Outside the scroll bar */
91 SCROLL_TOP_ARROW, /* Top or left arrow */
92 SCROLL_TOP_RECT, /* Rectangle between the top arrow and the thumb */
93 SCROLL_THUMB, /* Thumb rectangle */
94 SCROLL_BOTTOM_RECT, /* Rectangle between the thumb and the bottom arrow */
95 SCROLL_BOTTOM_ARROW /* Bottom or right arrow */
98 /* What to do after SCROLL_SetScrollInfo() */
99 #define SA_SSI_HIDE 0x0001
100 #define SA_SSI_SHOW 0x0002
101 #define SA_SSI_REFRESH 0x0004
102 #define SA_SSI_REPAINT_ARROWS 0x0008
104 /* Thumb-tracking info */
105 static HWND SCROLL_TrackingWin = 0;
106 static INT SCROLL_TrackingBar = 0;
107 static INT SCROLL_TrackingPos = 0;
108 static INT SCROLL_TrackingVal = 0;
109 /* Hit test code of the last button-down event */
110 static enum SCROLL_HITTEST SCROLL_trackHitTest;
111 static BOOL SCROLL_trackVertical;
113 /* Is the moving thumb being displayed? */
114 static BOOL SCROLL_MovingThumb = FALSE;
116 /* Local functions */
117 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar,
118 BOOL fShowH, BOOL fShowV );
119 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar,
120 const SCROLLINFO *info, INT *action );
121 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
122 RECT *rect, INT arrowSize,
123 INT thumbSize, INT thumbPos,
124 UINT flags, BOOL vertical,
125 BOOL top_selected, BOOL bottom_selected );
126 static LRESULT WINAPI ScrollBarWndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
129 /*********************************************************************
130 * scrollbar class descriptor
132 const struct builtin_class_descr SCROLL_builtin_class =
134 "ScrollBar", /* name */
135 CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC, /* style */
136 NULL, /* procA (winproc is Unicode only) */
137 ScrollBarWndProc, /* procW */
138 sizeof(SCROLLBAR_INFO), /* extra */
139 IDC_ARROW, /* cursor */
140 0 /* brush */
143 /***********************************************************************
144 * SCROLL_ScrollInfoValid
146 * Determine if the supplied SCROLLINFO struct is valid.
148 inline static BOOL SCROLL_ScrollInfoValid(
149 LPSCROLLINFO info /* [in] The SCROLLINFO struct to be tested */)
151 return !(info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)
152 || (info->cbSize != sizeof(*info)
153 && info->cbSize != sizeof(*info) - sizeof(info->nTrackPos)));
157 /***********************************************************************
158 * SCROLL_LoadBitmaps
160 static void SCROLL_LoadBitmaps(void)
162 hUpArrow = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROW) );
163 hDnArrow = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROW) );
164 hLfArrow = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROW) );
165 hRgArrow = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROW) );
166 hUpArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROWD) );
167 hDnArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROWD) );
168 hLfArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROWD) );
169 hRgArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROWD) );
170 hUpArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROWI) );
171 hDnArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROWI) );
172 hLfArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROWI) );
173 hRgArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROWI) );
177 /***********************************************************************
178 * SCROLL_GetScrollBarInfo
180 static SCROLLBAR_INFO *SCROLL_GetScrollBarInfo( HWND hwnd, INT nBar )
182 SCROLLBAR_INFO *infoPtr;
183 WND *wndPtr = WIN_FindWndPtr( hwnd );
185 if (!wndPtr) return NULL;
186 switch(nBar)
188 case SB_HORZ: infoPtr = (SCROLLBAR_INFO *)wndPtr->pHScroll; break;
189 case SB_VERT: infoPtr = (SCROLLBAR_INFO *)wndPtr->pVScroll; break;
190 case SB_CTL: infoPtr = (SCROLLBAR_INFO *)wndPtr->wExtra; break;
191 default:
192 WIN_ReleaseWndPtr( wndPtr );
193 return NULL;
196 if (!infoPtr) /* Create the info structure if needed */
198 if ((infoPtr = HeapAlloc( GetProcessHeap(), 0, sizeof(SCROLLBAR_INFO) )))
200 infoPtr->minVal = infoPtr->curVal = infoPtr->page = 0;
201 infoPtr->maxVal = 100;
202 infoPtr->flags = ESB_ENABLE_BOTH;
203 if (nBar == SB_HORZ) wndPtr->pHScroll = infoPtr;
204 else wndPtr->pVScroll = infoPtr;
206 if (!hUpArrow) SCROLL_LoadBitmaps();
208 WIN_ReleaseWndPtr( wndPtr );
209 return infoPtr;
213 /***********************************************************************
214 * SCROLL_GetScrollBarRect
216 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
217 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
218 * 'arrowSize' returns the width or height of an arrow (depending on
219 * the orientation of the scrollbar), 'thumbSize' returns the size of
220 * the thumb, and 'thumbPos' returns the position of the thumb
221 * relative to the left or to the top.
222 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
224 static BOOL SCROLL_GetScrollBarRect( HWND hwnd, INT nBar, RECT *lprect,
225 INT *arrowSize, INT *thumbSize,
226 INT *thumbPos )
228 INT pixels;
229 BOOL vertical;
230 WND *wndPtr = WIN_FindWndPtr( hwnd );
232 switch(nBar)
234 case SB_HORZ:
235 lprect->left = wndPtr->rectClient.left - wndPtr->rectWindow.left;
236 lprect->top = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
237 lprect->right = wndPtr->rectClient.right - wndPtr->rectWindow.left;
238 lprect->bottom = lprect->top + GetSystemMetrics(SM_CYHSCROLL);
239 if(wndPtr->dwStyle & WS_BORDER) {
240 lprect->left--;
241 lprect->right++;
242 } else if(wndPtr->dwStyle & WS_VSCROLL)
243 lprect->right++;
244 vertical = FALSE;
245 break;
247 case SB_VERT:
248 if((wndPtr->dwExStyle & WS_EX_LEFTSCROLLBAR) != 0)
249 lprect->left = wndPtr->rectClient.left - wndPtr->rectWindow.left - GetSystemMetrics(SM_CXVSCROLL);
250 else
251 lprect->left = wndPtr->rectClient.right - wndPtr->rectWindow.left;
252 lprect->top = wndPtr->rectClient.top - wndPtr->rectWindow.top;
253 lprect->right = lprect->left + GetSystemMetrics(SM_CXVSCROLL);
254 lprect->bottom = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
255 if(wndPtr->dwStyle & WS_BORDER) {
256 lprect->top--;
257 lprect->bottom++;
258 } else if(wndPtr->dwStyle & WS_HSCROLL)
259 lprect->bottom++;
260 vertical = TRUE;
261 break;
263 case SB_CTL:
264 GetClientRect( hwnd, lprect );
265 vertical = ((wndPtr->dwStyle & SBS_VERT) != 0);
266 break;
268 default:
269 WIN_ReleaseWndPtr(wndPtr);
270 return FALSE;
273 if (vertical) pixels = lprect->bottom - lprect->top;
274 else pixels = lprect->right - lprect->left;
276 if (pixels <= 2*GetSystemMetrics(SM_CXVSCROLL) + SCROLL_MIN_RECT)
278 if (pixels > SCROLL_MIN_RECT)
279 *arrowSize = (pixels - SCROLL_MIN_RECT) / 2;
280 else
281 *arrowSize = 0;
282 *thumbPos = *thumbSize = 0;
284 else
286 SCROLLBAR_INFO *info = SCROLL_GetScrollBarInfo( hwnd, nBar );
288 *arrowSize = GetSystemMetrics(SM_CXVSCROLL);
289 pixels -= (2 * (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP));
291 if (info->page)
293 *thumbSize = MulDiv(pixels,info->page,(info->maxVal-info->minVal+1));
294 if (*thumbSize < SCROLL_MIN_THUMB) *thumbSize = SCROLL_MIN_THUMB;
296 else *thumbSize = GetSystemMetrics(SM_CXVSCROLL);
298 if (((pixels -= *thumbSize ) < 0) ||
299 ((info->flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH))
301 /* Rectangle too small or scrollbar disabled -> no thumb */
302 *thumbPos = *thumbSize = 0;
304 else
306 INT max = info->maxVal - max( info->page-1, 0 );
307 if (info->minVal >= max)
308 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
309 else
310 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP
311 + MulDiv(pixels, (info->curVal-info->minVal),(max - info->minVal));
314 WIN_ReleaseWndPtr(wndPtr);
315 return vertical;
319 /***********************************************************************
320 * SCROLL_GetThumbVal
322 * Compute the current scroll position based on the thumb position in pixels
323 * from the top of the scroll-bar.
325 static UINT SCROLL_GetThumbVal( SCROLLBAR_INFO *infoPtr, RECT *rect,
326 BOOL vertical, INT pos )
328 INT thumbSize;
329 INT pixels = vertical ? rect->bottom-rect->top : rect->right-rect->left;
331 if ((pixels -= 2*(GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP)) <= 0)
332 return infoPtr->minVal;
334 if (infoPtr->page)
336 thumbSize = MulDiv(pixels,infoPtr->page,(infoPtr->maxVal-infoPtr->minVal+1));
337 if (thumbSize < SCROLL_MIN_THUMB) thumbSize = SCROLL_MIN_THUMB;
339 else thumbSize = GetSystemMetrics(SM_CXVSCROLL);
341 if ((pixels -= thumbSize) <= 0) return infoPtr->minVal;
343 pos = max( 0, pos - (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP) );
344 if (pos > pixels) pos = pixels;
346 if (!infoPtr->page) pos *= infoPtr->maxVal - infoPtr->minVal;
347 else pos *= infoPtr->maxVal - infoPtr->minVal - infoPtr->page + 1;
348 return infoPtr->minVal + ((pos + pixels / 2) / pixels);
351 /***********************************************************************
352 * SCROLL_PtInRectEx
354 static BOOL SCROLL_PtInRectEx( LPRECT lpRect, POINT pt, BOOL vertical )
356 RECT rect = *lpRect;
358 if (vertical)
360 rect.left -= lpRect->right - lpRect->left;
361 rect.right += lpRect->right - lpRect->left;
363 else
365 rect.top -= lpRect->bottom - lpRect->top;
366 rect.bottom += lpRect->bottom - lpRect->top;
368 return PtInRect( &rect, pt );
371 /***********************************************************************
372 * SCROLL_ClipPos
374 static POINT SCROLL_ClipPos( LPRECT lpRect, POINT pt )
376 if( pt.x < lpRect->left )
377 pt.x = lpRect->left;
378 else
379 if( pt.x > lpRect->right )
380 pt.x = lpRect->right;
382 if( pt.y < lpRect->top )
383 pt.y = lpRect->top;
384 else
385 if( pt.y > lpRect->bottom )
386 pt.y = lpRect->bottom;
388 return pt;
392 /***********************************************************************
393 * SCROLL_HitTest
395 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
397 static enum SCROLL_HITTEST SCROLL_HitTest( HWND hwnd, INT nBar,
398 POINT pt, BOOL bDragging )
400 INT arrowSize, thumbSize, thumbPos;
401 RECT rect;
403 BOOL vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
404 &arrowSize, &thumbSize, &thumbPos );
406 if ( (bDragging && !SCROLL_PtInRectEx( &rect, pt, vertical )) ||
407 (!PtInRect( &rect, pt )) ) return SCROLL_NOWHERE;
409 if (vertical)
411 if (pt.y < rect.top + arrowSize) return SCROLL_TOP_ARROW;
412 if (pt.y >= rect.bottom - arrowSize) return SCROLL_BOTTOM_ARROW;
413 if (!thumbPos) return SCROLL_TOP_RECT;
414 pt.y -= rect.top;
415 if (pt.y < thumbPos) return SCROLL_TOP_RECT;
416 if (pt.y >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
418 else /* horizontal */
420 if (pt.x < rect.left + arrowSize) return SCROLL_TOP_ARROW;
421 if (pt.x >= rect.right - arrowSize) return SCROLL_BOTTOM_ARROW;
422 if (!thumbPos) return SCROLL_TOP_RECT;
423 pt.x -= rect.left;
424 if (pt.x < thumbPos) return SCROLL_TOP_RECT;
425 if (pt.x >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
427 return SCROLL_THUMB;
431 /***********************************************************************
432 * SCROLL_DrawArrows
434 * Draw the scroll bar arrows.
436 static void SCROLL_DrawArrows_9x( HDC hdc, SCROLLBAR_INFO *infoPtr,
437 RECT *rect, INT arrowSize, BOOL vertical,
438 BOOL top_pressed, BOOL bottom_pressed )
440 RECT r;
442 r = *rect;
443 if( vertical )
444 r.bottom = r.top + arrowSize;
445 else
446 r.right = r.left + arrowSize;
448 DrawFrameControl( hdc, &r, DFC_SCROLL,
449 (vertical ? DFCS_SCROLLUP : DFCS_SCROLLLEFT)
450 | (top_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
451 | (infoPtr->flags&ESB_DISABLE_LTUP ? DFCS_INACTIVE : 0 ) );
453 r = *rect;
454 if( vertical )
455 r.top = r.bottom-arrowSize;
456 else
457 r.left = r.right-arrowSize;
459 DrawFrameControl( hdc, &r, DFC_SCROLL,
460 (vertical ? DFCS_SCROLLDOWN : DFCS_SCROLLRIGHT)
461 | (bottom_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
462 | (infoPtr->flags&ESB_DISABLE_RTDN ? DFCS_INACTIVE : 0) );
465 static void SCROLL_DrawArrows_31( HDC hdc, SCROLLBAR_INFO *infoPtr,
466 RECT *rect, INT arrowSize, BOOL vertical,
467 BOOL top_pressed, BOOL bottom_pressed )
469 HDC hdcMem = CreateCompatibleDC( hdc );
470 HBITMAP hbmpPrev = SelectObject( hdcMem, vertical ?
471 TOP_ARROW(infoPtr->flags, top_pressed)
472 : LEFT_ARROW(infoPtr->flags, top_pressed));
474 SetStretchBltMode( hdc, STRETCH_DELETESCANS );
475 StretchBlt( hdc, rect->left, rect->top,
476 vertical ? rect->right-rect->left : arrowSize,
477 vertical ? arrowSize : rect->bottom-rect->top,
478 hdcMem, 0, 0,
479 GetSystemMetrics(SM_CXVSCROLL),GetSystemMetrics(SM_CYHSCROLL),
480 SRCCOPY );
482 SelectObject( hdcMem, vertical ?
483 BOTTOM_ARROW( infoPtr->flags, bottom_pressed )
484 : RIGHT_ARROW( infoPtr->flags, bottom_pressed ) );
485 if (vertical)
486 StretchBlt( hdc, rect->left, rect->bottom - arrowSize,
487 rect->right - rect->left, arrowSize,
488 hdcMem, 0, 0,
489 GetSystemMetrics(SM_CXVSCROLL),GetSystemMetrics(SM_CYHSCROLL),
490 SRCCOPY );
491 else
492 StretchBlt( hdc, rect->right - arrowSize, rect->top,
493 arrowSize, rect->bottom - rect->top,
494 hdcMem, 0, 0,
495 GetSystemMetrics(SM_CXVSCROLL), GetSystemMetrics(SM_CYHSCROLL),
496 SRCCOPY );
497 SelectObject( hdcMem, hbmpPrev );
498 DeleteDC( hdcMem );
501 static void SCROLL_DrawArrows( HDC hdc, SCROLLBAR_INFO *infoPtr,
502 RECT *rect, INT arrowSize, BOOL vertical,
503 BOOL top_pressed, BOOL bottom_pressed )
505 if( TWEAK_WineLook == WIN31_LOOK )
506 SCROLL_DrawArrows_31( hdc, infoPtr, rect, arrowSize,
507 vertical, top_pressed,bottom_pressed );
508 else
509 SCROLL_DrawArrows_9x( hdc, infoPtr, rect, arrowSize,
510 vertical, top_pressed,bottom_pressed );
514 /***********************************************************************
515 * SCROLL_DrawMovingThumb
517 * Draw the moving thumb rectangle.
519 static void SCROLL_DrawMovingThumb_31( HDC hdc, RECT *rect, BOOL vertical,
520 INT arrowSize, INT thumbSize )
522 RECT r = *rect;
523 if (vertical)
525 r.top += SCROLL_TrackingPos;
526 if (r.top < rect->top + arrowSize - SCROLL_ARROW_THUMB_OVERLAP)
527 r.top = rect->top + arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
528 if (r.top + thumbSize >
529 rect->bottom - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP))
530 r.top = rect->bottom - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP)
531 - thumbSize;
532 r.bottom = r.top + thumbSize;
534 else
536 r.left += SCROLL_TrackingPos;
537 if (r.left < rect->left + arrowSize - SCROLL_ARROW_THUMB_OVERLAP)
538 r.left = rect->left + arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
539 if (r.left + thumbSize >
540 rect->right - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP))
541 r.left = rect->right - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP)
542 - thumbSize;
543 r.right = r.left + thumbSize;
546 DrawFocusRect( hdc, &r );
547 SCROLL_MovingThumb = !SCROLL_MovingThumb;
550 static void SCROLL_DrawMovingThumb_9x( HDC hdc, RECT *rect, BOOL vertical,
551 INT arrowSize, INT thumbSize )
553 INT pos = SCROLL_TrackingPos;
554 INT max_size;
556 if( vertical )
557 max_size = rect->bottom - rect->top;
558 else
559 max_size = rect->right - rect->left;
561 max_size -= (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) + thumbSize;
563 if( pos < (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) )
564 pos = (arrowSize-SCROLL_ARROW_THUMB_OVERLAP);
565 else if( pos > max_size )
566 pos = max_size;
568 SCROLL_DrawInterior_9x( SCROLL_TrackingWin, hdc, SCROLL_TrackingBar,
569 rect, arrowSize, thumbSize, pos,
570 0, vertical, FALSE, FALSE );
572 SCROLL_MovingThumb = !SCROLL_MovingThumb;
575 static void SCROLL_DrawMovingThumb( HDC hdc, RECT *rect, BOOL vertical,
576 INT arrowSize, INT thumbSize )
578 if( TWEAK_WineLook == WIN31_LOOK )
579 SCROLL_DrawMovingThumb_31( hdc, rect, vertical, arrowSize, thumbSize );
580 else
581 SCROLL_DrawMovingThumb_9x( hdc, rect, vertical, arrowSize, thumbSize );
584 /***********************************************************************
585 * SCROLL_DrawInterior
587 * Draw the scroll bar interior (everything except the arrows).
589 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
590 RECT *rect, INT arrowSize,
591 INT thumbSize, INT thumbPos,
592 UINT flags, BOOL vertical,
593 BOOL top_selected, BOOL bottom_selected )
595 RECT r;
596 HPEN hSavePen;
597 HBRUSH hSaveBrush,hBrush;
599 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
600 * The window-owned scrollbars need to call DEFWND_ControlColor
601 * to correctly setup default scrollbar colors
603 if (nBar == SB_CTL)
605 hBrush = (HBRUSH)SendMessageA( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
606 (WPARAM)hdc,(LPARAM)hwnd);
608 else
610 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
613 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
614 hSaveBrush = SelectObject( hdc, hBrush );
616 /* Calculate the scroll rectangle */
617 r = *rect;
618 if (vertical)
620 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
621 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
623 else
625 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
626 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
629 /* Draw the scroll rectangles and thumb */
630 if (!thumbPos) /* No thumb to draw */
632 PatBlt( hdc, r.left, r.top,
633 r.right - r.left, r.bottom - r.top,
634 PATCOPY );
636 /* cleanup and return */
637 SelectObject( hdc, hSavePen );
638 SelectObject( hdc, hSaveBrush );
639 return;
642 if (vertical)
644 PatBlt( hdc, r.left, r.top,
645 r.right - r.left,
646 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
647 top_selected ? 0x0f0000 : PATCOPY );
648 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
649 PatBlt( hdc, r.left, r.top + thumbSize,
650 r.right - r.left,
651 r.bottom - r.top - thumbSize,
652 bottom_selected ? 0x0f0000 : PATCOPY );
653 r.bottom = r.top + thumbSize;
655 else /* horizontal */
657 PatBlt( hdc, r.left, r.top,
658 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
659 r.bottom - r.top,
660 top_selected ? 0x0f0000 : PATCOPY );
661 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
662 PatBlt( hdc, r.left + thumbSize, r.top,
663 r.right - r.left - thumbSize,
664 r.bottom - r.top,
665 bottom_selected ? 0x0f0000 : PATCOPY );
666 r.right = r.left + thumbSize;
669 /* Draw the thumb */
670 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT | BF_MIDDLE );
672 /* cleanup */
673 SelectObject( hdc, hSavePen );
674 SelectObject( hdc, hSaveBrush );
678 static void SCROLL_DrawInterior( HWND hwnd, HDC hdc, INT nBar,
679 RECT *rect, INT arrowSize,
680 INT thumbSize, INT thumbPos,
681 UINT flags, BOOL vertical,
682 BOOL top_selected, BOOL bottom_selected )
684 RECT r;
685 HPEN hSavePen;
686 HBRUSH hSaveBrush,hBrush;
687 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
689 if (Save_SCROLL_MovingThumb &&
690 (SCROLL_TrackingWin == hwnd) &&
691 (SCROLL_TrackingBar == nBar))
692 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
694 /* Select the correct brush and pen */
696 if (TWEAK_WineLook == WIN31_LOOK && (flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH)
698 /* This ought to be the color of the parent window */
699 hBrush = GetSysColorBrush(COLOR_WINDOW);
701 else
703 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
704 * The window-owned scrollbars need to call DEFWND_ControlColor
705 * to correctly setup default scrollbar colors
707 if (nBar == SB_CTL) {
708 hBrush = (HBRUSH)SendMessageA( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
709 (WPARAM)hdc,(LPARAM)hwnd);
710 } else {
711 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
714 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
715 hSaveBrush = SelectObject( hdc, hBrush );
717 /* Calculate the scroll rectangle */
719 r = *rect;
720 if (vertical)
722 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
723 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
725 else
727 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
728 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
731 /* Draw the scroll bar frame */
733 /* Only draw outline if Win 3.1. Mar 24, 1999 - Ronald B. Cemer */
734 if (TWEAK_WineLook == WIN31_LOOK)
735 Rectangle( hdc, r.left, r.top, r.right, r.bottom );
737 /* Draw the scroll rectangles and thumb */
739 if (!thumbPos) /* No thumb to draw */
741 INT offset = (TWEAK_WineLook > WIN31_LOOK) ? 0 : 1;
743 PatBlt( hdc, r.left+offset, r.top+offset,
744 r.right - r.left - 2*offset, r.bottom - r.top - 2*offset,
745 PATCOPY );
747 /* cleanup and return */
748 SelectObject( hdc, hSavePen );
749 SelectObject( hdc, hSaveBrush );
750 return;
753 if (vertical)
755 INT offset = (TWEAK_WineLook == WIN31_LOOK) ? 1 : 0;
757 PatBlt( hdc, r.left + offset, r.top + offset,
758 r.right - r.left - offset*2,
759 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP) - offset,
760 top_selected ? 0x0f0000 : PATCOPY );
761 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
762 PatBlt( hdc, r.left + offset, r.top + thumbSize,
763 r.right - r.left - offset*2,
764 r.bottom - r.top - thumbSize - offset,
765 bottom_selected ? 0x0f0000 : PATCOPY );
766 r.bottom = r.top + thumbSize;
768 else /* horizontal */
770 INT offset = (TWEAK_WineLook == WIN31_LOOK) ? 1 : 0;
772 PatBlt( hdc, r.left + offset, r.top + offset,
773 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
774 r.bottom - r.top - offset*2,
775 top_selected ? 0x0f0000 : PATCOPY );
776 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
777 PatBlt( hdc, r.left + thumbSize, r.top + offset,
778 r.right - r.left - thumbSize - offset,
779 r.bottom - r.top - offset*2,
780 bottom_selected ? 0x0f0000 : PATCOPY );
781 r.right = r.left + thumbSize;
784 /* Draw the thumb */
786 SelectObject( hdc, GetSysColorBrush(COLOR_BTNFACE) );
787 if (TWEAK_WineLook == WIN31_LOOK)
789 Rectangle( hdc, r.left, r.top, r.right, r.bottom );
790 r.top++, r.left++;
792 else
794 Rectangle( hdc, r.left+1, r.top+1, r.right-1, r.bottom-1 );
796 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT );
798 if (Save_SCROLL_MovingThumb &&
799 (SCROLL_TrackingWin == hwnd) &&
800 (SCROLL_TrackingBar == nBar))
801 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
803 /* cleanup */
804 SelectObject( hdc, hSavePen );
805 SelectObject( hdc, hSaveBrush );
809 /***********************************************************************
810 * SCROLL_DrawScrollBar
812 * Redraw the whole scrollbar.
814 void SCROLL_DrawScrollBar( HWND hwnd, HDC hdc, INT nBar,
815 BOOL arrows, BOOL interior )
817 INT arrowSize, thumbSize, thumbPos;
818 RECT rect;
819 BOOL vertical;
820 WND *wndPtr = WIN_FindWndPtr( hwnd );
821 SCROLLBAR_INFO *infoPtr = SCROLL_GetScrollBarInfo( hwnd, nBar );
822 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
824 if (!wndPtr || !infoPtr ||
825 ((nBar == SB_VERT) && !(wndPtr->dwStyle & WS_VSCROLL)) ||
826 ((nBar == SB_HORZ) && !(wndPtr->dwStyle & WS_HSCROLL))) goto END;
827 if (!WIN_IsWindowDrawable( hwnd, FALSE )) goto END;
828 hwnd = wndPtr->hwndSelf; /* make it a full handle */
830 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
831 &arrowSize, &thumbSize, &thumbPos );
833 /* do not draw if the scrollbar rectangle is empty */
834 if(IsRectEmpty(&rect))
835 goto END;
837 if (Save_SCROLL_MovingThumb &&
838 (SCROLL_TrackingWin == hwnd) &&
839 (SCROLL_TrackingBar == nBar))
840 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
842 /* Draw the arrows */
844 if (arrows && arrowSize)
846 if( vertical == SCROLL_trackVertical && GetCapture() == hwnd )
847 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
848 (SCROLL_trackHitTest == SCROLL_TOP_ARROW),
849 (SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW) );
850 else
851 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
852 FALSE, FALSE );
854 if( interior )
855 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
856 thumbPos, infoPtr->flags, vertical, FALSE, FALSE );
858 if (Save_SCROLL_MovingThumb &&
859 (SCROLL_TrackingWin == hwnd) &&
860 (SCROLL_TrackingBar == nBar))
861 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
863 /* if scroll bar has focus, reposition the caret */
864 if(hwnd==GetFocus() && (nBar==SB_CTL))
866 if (!vertical)
868 SetCaretPos(thumbPos+1, rect.top+1);
870 else
872 SetCaretPos(rect.top+1, thumbPos+1);
876 END:
877 WIN_ReleaseWndPtr(wndPtr);
880 /***********************************************************************
881 * SCROLL_DrawSizeGrip
883 * Draw the size grip.
885 static void SCROLL_DrawSizeGrip( HWND hwnd, HDC hdc)
887 RECT rc;
889 GetClientRect( hwnd, &rc );
890 FillRect( hdc, &rc, GetSysColorBrush(COLOR_SCROLLBAR) );
891 rc.left = max( rc.left, rc.right - GetSystemMetrics(SM_CXVSCROLL) - 1 );
892 rc.top = max( rc.top, rc.bottom - GetSystemMetrics(SM_CYHSCROLL) - 1 );
893 DrawFrameControl( hdc, &rc, DFC_SCROLL, DFCS_SCROLLSIZEGRIP );
897 /***********************************************************************
898 * SCROLL_RefreshScrollBar
900 * Repaint the scroll bar interior after a SetScrollRange() or
901 * SetScrollPos() call.
903 static void SCROLL_RefreshScrollBar( HWND hwnd, INT nBar,
904 BOOL arrows, BOOL interior )
906 HDC hdc = GetDCEx( hwnd, 0,
907 DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW) );
908 if (!hdc) return;
910 SCROLL_DrawScrollBar( hwnd, hdc, nBar, arrows, interior );
911 ReleaseDC( hwnd, hdc );
915 /***********************************************************************
916 * SCROLL_HandleKbdEvent
918 * Handle a keyboard event (only for SB_CTL scrollbars with focus).
920 static void SCROLL_HandleKbdEvent(
921 HWND hwnd /* [in] Handle of window with scrollbar(s) */,
922 WPARAM wParam /* [in] Variable input including enable state */,
923 LPARAM lParam /* [in] Variable input including input point */)
925 TRACE("hwnd=%p wParam=%d lParam=%ld\n", hwnd, wParam, lParam);
927 /* hide caret on first KEYDOWN to prevent flicker */
928 if ((lParam & PFD_DOUBLEBUFFER_DONTCARE) == 0)
929 HideCaret(hwnd);
931 switch(wParam)
933 case VK_PRIOR: wParam = SB_PAGEUP; break;
934 case VK_NEXT: wParam = SB_PAGEDOWN; break;
935 case VK_HOME: wParam = SB_TOP; break;
936 case VK_END: wParam = SB_BOTTOM; break;
937 case VK_UP: wParam = SB_LINEUP; break;
938 case VK_DOWN: wParam = SB_LINEDOWN; break;
939 default: return;
941 SendMessageW(GetParent(hwnd),
942 ((GetWindowLongA( hwnd, GWL_STYLE ) & SBS_VERT) ?
943 WM_VSCROLL : WM_HSCROLL), wParam, (LPARAM)hwnd);
947 /***********************************************************************
948 * SCROLL_HandleScrollEvent
950 * Handle a mouse or timer event for the scrollbar.
951 * 'pt' is the location of the mouse event in client (for SB_CTL) or
952 * windows coordinates.
954 static void SCROLL_HandleScrollEvent( HWND hwnd, INT nBar, UINT msg, POINT pt)
956 /* Previous mouse position for timer events */
957 static POINT prevPt;
958 /* Thumb position when tracking started. */
959 static UINT trackThumbPos;
960 /* Position in the scroll-bar of the last button-down event. */
961 static INT lastClickPos;
962 /* Position in the scroll-bar of the last mouse event. */
963 static INT lastMousePos;
965 enum SCROLL_HITTEST hittest;
966 HWND hwndOwner, hwndCtl;
967 BOOL vertical;
968 INT arrowSize, thumbSize, thumbPos;
969 RECT rect;
970 HDC hdc;
972 SCROLLBAR_INFO *infoPtr = SCROLL_GetScrollBarInfo( hwnd, nBar );
973 if (!infoPtr) return;
974 if ((SCROLL_trackHitTest == SCROLL_NOWHERE) && (msg != WM_LBUTTONDOWN))
975 return;
977 if (nBar == SB_CTL && (GetWindowLongW( hwnd, GWL_STYLE ) & (SBS_SIZEGRIP | SBS_SIZEBOX)))
979 switch(msg)
981 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
982 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
983 SetCapture( hwnd );
984 prevPt = pt;
985 SCROLL_trackHitTest = hittest = SCROLL_THUMB;
986 break;
987 case WM_MOUSEMOVE:
988 GetClientRect(GetParent(GetParent(hwnd)),&rect);
989 prevPt = pt;
990 break;
991 case WM_LBUTTONUP:
992 ReleaseCapture();
993 SCROLL_trackHitTest = hittest = SCROLL_NOWHERE;
994 if (hwnd==GetFocus()) ShowCaret(hwnd);
995 break;
996 case WM_SYSTIMER:
997 pt = prevPt;
998 break;
1000 return;
1003 hdc = GetDCEx( hwnd, 0, DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW));
1004 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
1005 &arrowSize, &thumbSize, &thumbPos );
1006 hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd) : hwnd;
1007 hwndCtl = (nBar == SB_CTL) ? hwnd : 0;
1009 switch(msg)
1011 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
1012 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
1013 SCROLL_trackVertical = vertical;
1014 SCROLL_trackHitTest = hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
1015 lastClickPos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
1016 lastMousePos = lastClickPos;
1017 trackThumbPos = thumbPos;
1018 prevPt = pt;
1019 if (nBar == SB_CTL && (GetWindowLongA(hwnd, GWL_STYLE) & WS_TABSTOP)) SetFocus( hwnd );
1020 SetCapture( hwnd );
1021 break;
1023 case WM_MOUSEMOVE:
1024 hittest = SCROLL_HitTest( hwnd, nBar, pt, TRUE );
1025 prevPt = pt;
1026 break;
1028 case WM_LBUTTONUP:
1029 hittest = SCROLL_NOWHERE;
1030 ReleaseCapture();
1031 /* if scrollbar has focus, show back caret */
1032 if (hwnd==GetFocus()) ShowCaret(hwnd);
1033 break;
1035 case WM_SYSTIMER:
1036 pt = prevPt;
1037 hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
1038 break;
1040 default:
1041 return; /* Should never happen */
1044 TRACE("Event: hwnd=%p bar=%d msg=%s pt=%ld,%ld hit=%d\n",
1045 hwnd, nBar, SPY_GetMsgName(msg,hwnd), pt.x, pt.y, hittest );
1047 switch(SCROLL_trackHitTest)
1049 case SCROLL_NOWHERE: /* No tracking in progress */
1050 break;
1052 case SCROLL_TOP_ARROW:
1053 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
1054 (hittest == SCROLL_trackHitTest), FALSE );
1055 if (hittest == SCROLL_trackHitTest)
1057 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1059 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1060 SB_LINEUP, (LPARAM)hwndCtl );
1063 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1064 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1065 (TIMERPROC)0 );
1067 else KillSystemTimer( hwnd, SCROLL_TIMER );
1068 break;
1070 case SCROLL_TOP_RECT:
1071 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
1072 thumbPos, infoPtr->flags, vertical,
1073 (hittest == SCROLL_trackHitTest), FALSE );
1074 if (hittest == SCROLL_trackHitTest)
1076 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1078 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1079 SB_PAGEUP, (LPARAM)hwndCtl );
1081 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1082 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1083 (TIMERPROC)0 );
1085 else KillSystemTimer( hwnd, SCROLL_TIMER );
1086 break;
1088 case SCROLL_THUMB:
1089 if (msg == WM_LBUTTONDOWN)
1091 SCROLL_TrackingWin = hwnd;
1092 SCROLL_TrackingBar = nBar;
1093 SCROLL_TrackingPos = trackThumbPos + lastMousePos - lastClickPos;
1094 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
1095 vertical,
1096 SCROLL_TrackingPos );
1097 if (!SCROLL_MovingThumb)
1098 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
1100 else if (msg == WM_LBUTTONUP)
1102 if (SCROLL_MovingThumb)
1103 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
1104 SCROLL_TrackingWin = 0;
1105 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
1106 thumbPos, infoPtr->flags, vertical,
1107 FALSE, FALSE );
1109 else /* WM_MOUSEMOVE */
1111 UINT pos;
1113 if (!SCROLL_PtInRectEx( &rect, pt, vertical )) pos = lastClickPos;
1114 else
1116 pt = SCROLL_ClipPos( &rect, pt );
1117 pos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
1119 if ( (pos != lastMousePos) || (!SCROLL_MovingThumb) )
1121 if (SCROLL_MovingThumb)
1122 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
1123 arrowSize, thumbSize );
1124 lastMousePos = pos;
1125 SCROLL_TrackingPos = trackThumbPos + pos - lastClickPos;
1126 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
1127 vertical,
1128 SCROLL_TrackingPos );
1129 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1130 MAKEWPARAM( SB_THUMBTRACK, SCROLL_TrackingVal),
1131 (LPARAM)hwndCtl );
1132 if (!SCROLL_MovingThumb)
1133 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
1134 arrowSize, thumbSize );
1137 break;
1139 case SCROLL_BOTTOM_RECT:
1140 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
1141 thumbPos, infoPtr->flags, vertical,
1142 FALSE, (hittest == SCROLL_trackHitTest) );
1143 if (hittest == SCROLL_trackHitTest)
1145 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1147 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1148 SB_PAGEDOWN, (LPARAM)hwndCtl );
1150 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1151 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1152 (TIMERPROC)0 );
1154 else KillSystemTimer( hwnd, SCROLL_TIMER );
1155 break;
1157 case SCROLL_BOTTOM_ARROW:
1158 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
1159 FALSE, (hittest == SCROLL_trackHitTest) );
1160 if (hittest == SCROLL_trackHitTest)
1162 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1164 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1165 SB_LINEDOWN, (LPARAM)hwndCtl );
1168 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1169 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1170 (TIMERPROC)0 );
1172 else KillSystemTimer( hwnd, SCROLL_TIMER );
1173 break;
1176 if (msg == WM_LBUTTONDOWN)
1179 if (hittest == SCROLL_THUMB)
1181 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1182 trackThumbPos + lastMousePos - lastClickPos );
1183 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1184 MAKEWPARAM( SB_THUMBTRACK, val ), (LPARAM)hwndCtl );
1188 if (msg == WM_LBUTTONUP)
1190 hittest = SCROLL_trackHitTest;
1191 SCROLL_trackHitTest = SCROLL_NOWHERE; /* Terminate tracking */
1193 if (hittest == SCROLL_THUMB)
1195 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1196 trackThumbPos + lastMousePos - lastClickPos );
1197 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1198 MAKEWPARAM( SB_THUMBPOSITION, val ), (LPARAM)hwndCtl );
1200 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1201 SB_ENDSCROLL, (LPARAM)hwndCtl );
1204 ReleaseDC( hwnd, hdc );
1208 /***********************************************************************
1209 * SCROLL_TrackScrollBar
1211 * Track a mouse button press on a scroll-bar.
1212 * pt is in screen-coordinates for non-client scroll bars.
1214 void SCROLL_TrackScrollBar( HWND hwnd, INT scrollbar, POINT pt )
1216 MSG msg;
1217 INT xoffset = 0, yoffset = 0;
1219 if (scrollbar != SB_CTL)
1221 WND *wndPtr = WIN_GetPtr( hwnd );
1222 if (!wndPtr || wndPtr == WND_OTHER_PROCESS) return;
1223 xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
1224 yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
1225 WIN_ReleasePtr( wndPtr );
1226 ScreenToClient( hwnd, &pt );
1227 pt.x += xoffset;
1228 pt.y += yoffset;
1231 SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt );
1235 if (!GetMessageW( &msg, 0, 0, 0 )) break;
1236 if (CallMsgFilterW( &msg, MSGF_SCROLLBAR )) continue;
1237 switch(msg.message)
1239 case WM_LBUTTONUP:
1240 case WM_MOUSEMOVE:
1241 case WM_SYSTIMER:
1242 pt.x = LOWORD(msg.lParam) + xoffset;
1243 pt.y = HIWORD(msg.lParam) + yoffset;
1244 SCROLL_HandleScrollEvent( hwnd, scrollbar, msg.message, pt );
1245 break;
1246 default:
1247 TranslateMessage( &msg );
1248 DispatchMessageW( &msg );
1249 break;
1251 if (!IsWindow( hwnd ))
1253 ReleaseCapture();
1254 break;
1256 } while (msg.message != WM_LBUTTONUP);
1260 /***********************************************************************
1261 * SCROLL_CreateScrollBar
1263 * Create a scroll bar
1265 static void SCROLL_CreateScrollBar(
1266 HWND hwnd /* [in] Handle of window with scrollbar(s) */,
1267 LPCREATESTRUCTW lpCreate /* [in] The style and place of the scroll bar */)
1269 LPSCROLLBAR_INFO info = SCROLL_GetScrollBarInfo(hwnd, SB_CTL);
1270 if (!info) return;
1272 TRACE("hwnd=%p lpCreate=%p\n", hwnd, lpCreate);
1274 if (lpCreate->style & WS_DISABLED)
1276 info->flags = ESB_DISABLE_BOTH;
1277 TRACE("Created WS_DISABLED scrollbar\n");
1281 if (lpCreate->style & (SBS_SIZEGRIP | SBS_SIZEBOX))
1283 if (lpCreate->style & SBS_SIZEBOXTOPLEFTALIGN)
1284 MoveWindow( hwnd, lpCreate->x, lpCreate->y, GetSystemMetrics(SM_CXVSCROLL)+1,
1285 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1286 else if(lpCreate->style & SBS_SIZEBOXBOTTOMRIGHTALIGN)
1287 MoveWindow( hwnd, lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1288 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1289 GetSystemMetrics(SM_CXVSCROLL)+1,
1290 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1292 else if (lpCreate->style & SBS_VERT)
1294 if (lpCreate->style & SBS_LEFTALIGN)
1295 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1296 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1297 else if (lpCreate->style & SBS_RIGHTALIGN)
1298 MoveWindow( hwnd,
1299 lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1300 lpCreate->y,
1301 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1303 else /* SBS_HORZ */
1305 if (lpCreate->style & SBS_TOPALIGN)
1306 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1307 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1308 else if (lpCreate->style & SBS_BOTTOMALIGN)
1309 MoveWindow( hwnd,
1310 lpCreate->x,
1311 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1312 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1317 /*************************************************************************
1318 * SCROLL_GetScrollInfo
1320 * Internal helper for the API function
1322 static BOOL SCROLL_GetScrollInfo(
1323 HWND hwnd /* [in] Handle of window with scrollbar(s) */,
1324 INT nBar /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1325 LPSCROLLINFO info /* [in/out] (fMask specifies which values to retrieve) */)
1327 LPSCROLLBAR_INFO infoPtr;
1329 /* handle invalid data structure */
1330 if (!SCROLL_ScrollInfoValid(info)
1331 || !(infoPtr = SCROLL_GetScrollBarInfo(hwnd, nBar)))
1332 return FALSE;
1334 /* fill in the desired scroll info structure */
1335 if (info->fMask & SIF_PAGE) info->nPage = infoPtr->page;
1336 if (info->fMask & SIF_POS) info->nPos = infoPtr->curVal;
1337 if ((info->fMask & SIF_TRACKPOS) && (info->cbSize == sizeof(*info)))
1338 info->nTrackPos = (SCROLL_TrackingWin == WIN_GetFullHandle(hwnd)) ? SCROLL_TrackingVal : infoPtr->curVal;
1339 if (info->fMask & SIF_RANGE)
1341 info->nMin = infoPtr->minVal;
1342 info->nMax = infoPtr->maxVal;
1345 return (info->fMask & SIF_ALL) != 0;
1349 /*************************************************************************
1350 * SCROLL_GetScrollPos
1352 * Internal helper for the API function
1354 static INT SCROLL_GetScrollPos(
1355 HWND hwnd /* [in] Handle of window with scrollbar(s) */,
1356 INT nBar /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */)
1358 LPSCROLLBAR_INFO infoPtr = SCROLL_GetScrollBarInfo(hwnd, nBar);
1359 return infoPtr ? infoPtr->curVal: 0;
1363 /*************************************************************************
1364 * SCROLL_GetScrollRange
1366 * Internal helper for the API function
1368 * RETURNS STD
1370 static BOOL SCROLL_GetScrollRange(
1371 HWND hwnd, /* [in] Handle of window */
1372 INT nBar, /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */
1373 LPINT lpMin, /* [out] Where to store minimum value */
1374 LPINT lpMax /* [out] Where to store maximum value */)
1376 LPSCROLLBAR_INFO infoPtr = SCROLL_GetScrollBarInfo(hwnd, nBar);
1378 if (lpMin) *lpMin = infoPtr ? infoPtr->minVal : 0;
1379 if (lpMax) *lpMax = infoPtr ? infoPtr->maxVal : 0;
1381 return infoPtr ? TRUE : FALSE;
1386 /***********************************************************************
1387 * ScrollBarWndProc
1389 static LRESULT WINAPI ScrollBarWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1391 if (!IsWindow( hwnd )) return 0;
1393 switch(message)
1395 case WM_CREATE:
1396 SCROLL_CreateScrollBar(hwnd, (LPCREATESTRUCTW)lParam);
1397 if (!hUpArrow) SCROLL_LoadBitmaps();
1398 break;
1400 case WM_ENABLE:
1402 SCROLLBAR_INFO *infoPtr;
1403 if ((infoPtr = SCROLL_GetScrollBarInfo( hwnd, SB_CTL )))
1405 infoPtr->flags = wParam ? ESB_ENABLE_BOTH : ESB_DISABLE_BOTH;
1406 SCROLL_RefreshScrollBar(hwnd, SB_CTL, TRUE, TRUE);
1409 return 0;
1411 case WM_LBUTTONDOWN:
1413 POINT pt;
1414 pt.x = (short)LOWORD(lParam);
1415 pt.y = (short)HIWORD(lParam);
1416 SCROLL_TrackScrollBar( hwnd, SB_CTL, pt );
1418 break;
1419 case WM_LBUTTONUP:
1420 case WM_MOUSEMOVE:
1421 case WM_SYSTIMER:
1423 POINT pt;
1424 pt.x = (short)LOWORD(lParam);
1425 pt.y = (short)HIWORD(lParam);
1426 SCROLL_HandleScrollEvent( hwnd, SB_CTL, message, pt );
1428 break;
1430 case WM_KEYDOWN:
1431 SCROLL_HandleKbdEvent(hwnd, wParam, lParam);
1432 break;
1434 case WM_KEYUP:
1435 ShowCaret(hwnd);
1436 break;
1438 case WM_SETFOCUS:
1440 /* Create a caret when a ScrollBar get focus */
1441 RECT rect;
1442 int arrowSize, thumbSize, thumbPos, vertical;
1443 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,
1444 &arrowSize, &thumbSize, &thumbPos );
1445 if (!vertical)
1447 CreateCaret(hwnd, (HBITMAP)1, thumbSize-2, rect.bottom-rect.top-2);
1448 SetCaretPos(thumbPos+1, rect.top+1);
1450 else
1452 CreateCaret(hwnd, (HBITMAP)1, rect.right-rect.left-2,thumbSize-2);
1453 SetCaretPos(rect.top+1, thumbPos+1);
1455 ShowCaret(hwnd);
1457 break;
1459 case WM_KILLFOCUS:
1461 RECT rect;
1462 int arrowSize, thumbSize, thumbPos, vertical;
1463 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,&arrowSize, &thumbSize, &thumbPos );
1464 if (!vertical){
1465 rect.left=thumbPos+1;
1466 rect.right=rect.left+thumbSize;
1468 else
1470 rect.top=thumbPos+1;
1471 rect.bottom=rect.top+thumbSize;
1473 HideCaret(hwnd);
1474 InvalidateRect(hwnd,&rect,0);
1475 DestroyCaret();
1477 break;
1479 case WM_ERASEBKGND:
1480 return 1;
1482 case WM_GETDLGCODE:
1483 return DLGC_WANTARROWS; /* Windows returns this value */
1485 case WM_PAINT:
1487 PAINTSTRUCT ps;
1488 HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
1489 if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEGRIP)
1491 SCROLL_DrawSizeGrip( hwnd, hdc);
1493 else if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEBOX)
1495 RECT rc;
1496 GetClientRect( hwnd, &rc );
1497 FillRect( hdc, &rc, GetSysColorBrush(COLOR_SCROLLBAR) );
1499 else
1500 SCROLL_DrawScrollBar( hwnd, hdc, SB_CTL, TRUE, TRUE );
1501 if (!wParam) EndPaint(hwnd, &ps);
1503 break;
1505 case SBM_SETPOS16:
1506 case SBM_SETPOS:
1507 return SetScrollPos( hwnd, SB_CTL, wParam, (BOOL)lParam );
1509 case SBM_GETPOS16:
1510 case SBM_GETPOS:
1511 return SCROLL_GetScrollPos(hwnd, SB_CTL);
1513 case SBM_SETRANGE16:
1514 SetScrollRange( hwnd, SB_CTL, LOWORD(lParam), HIWORD(lParam),
1515 wParam /* FIXME: Is this correct? */ );
1516 return 0;
1518 case SBM_SETRANGE:
1520 INT oldPos = SCROLL_GetScrollPos( hwnd, SB_CTL );
1521 SetScrollRange( hwnd, SB_CTL, wParam, lParam, FALSE );
1522 if (oldPos != SCROLL_GetScrollPos( hwnd, SB_CTL )) return oldPos;
1524 return 0;
1526 case SBM_GETRANGE16:
1527 FIXME("don't know how to handle SBM_GETRANGE16 (wp=%04x,lp=%08lx)\n", wParam, lParam );
1528 return 0;
1530 case SBM_GETRANGE:
1531 return SCROLL_GetScrollRange(hwnd, SB_CTL, (LPINT)wParam, (LPINT)lParam);
1533 case SBM_ENABLE_ARROWS16:
1534 case SBM_ENABLE_ARROWS:
1535 return EnableScrollBar( hwnd, SB_CTL, wParam );
1537 case SBM_SETRANGEREDRAW:
1539 INT oldPos = SCROLL_GetScrollPos( hwnd, SB_CTL );
1540 SetScrollRange( hwnd, SB_CTL, wParam, lParam, TRUE );
1541 if (oldPos != SCROLL_GetScrollPos( hwnd, SB_CTL )) return oldPos;
1543 return 0;
1545 case SBM_SETSCROLLINFO:
1546 return SetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam, wParam );
1548 case SBM_GETSCROLLINFO:
1549 return SCROLL_GetScrollInfo(hwnd, SB_CTL, (SCROLLINFO *)lParam);
1551 case 0x00e5:
1552 case 0x00e7:
1553 case 0x00e8:
1554 case 0x00eb:
1555 case 0x00ec:
1556 case 0x00ed:
1557 case 0x00ee:
1558 case 0x00ef:
1559 ERR("unknown Win32 msg %04x wp=%08x lp=%08lx\n",
1560 message, wParam, lParam );
1561 break;
1563 default:
1564 if (message >= WM_USER)
1565 WARN("unknown msg %04x wp=%04x lp=%08lx\n",
1566 message, wParam, lParam );
1567 return DefWindowProcW( hwnd, message, wParam, lParam );
1569 return 0;
1573 /*************************************************************************
1574 * SetScrollInfo (USER32.@)
1575 * SetScrollInfo can be used to set the position, upper bound,
1576 * lower bound, and page size of a scrollbar control.
1578 * RETURNS
1579 * Scrollbar position
1581 * NOTE
1582 * For 100 lines of text to be displayed in a window of 25 lines,
1583 * one would for instance use info->nMin=0, info->nMax=75
1584 * (corresponding to the 76 different positions of the window on
1585 * the text), and info->nPage=25.
1587 INT WINAPI SetScrollInfo(
1588 HWND hwnd /* [in] Handle of window whose scrollbar will be affected */,
1589 INT nBar /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1590 const SCROLLINFO *info /* [in] Specifies what to change and new values */,
1591 BOOL bRedraw /* [in] Should scrollbar be redrawn afterwards ? */)
1593 INT action;
1594 INT retVal = SCROLL_SetScrollInfo( hwnd, nBar, info, &action );
1596 if( action & SA_SSI_HIDE )
1597 SCROLL_ShowScrollBar( hwnd, nBar, FALSE, FALSE );
1598 else
1600 if( action & SA_SSI_SHOW )
1601 if( SCROLL_ShowScrollBar( hwnd, nBar, TRUE, TRUE ) )
1602 return retVal; /* SetWindowPos() already did the painting */
1604 if( bRedraw )
1605 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
1606 else if( action & SA_SSI_REPAINT_ARROWS )
1607 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, FALSE );
1609 return retVal;
1612 INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar,
1613 const SCROLLINFO *info, INT *action )
1615 /* Update the scrollbar state and set action flags according to
1616 * what has to be done graphics wise. */
1618 SCROLLBAR_INFO *infoPtr;
1619 UINT new_flags;
1620 BOOL bChangeParams = FALSE; /* don't show/hide scrollbar if params don't change */
1622 *action = 0;
1624 if (!(infoPtr = SCROLL_GetScrollBarInfo(hwnd, nBar))) return 0;
1625 if (info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)) return 0;
1626 if ((info->cbSize != sizeof(*info)) &&
1627 (info->cbSize != sizeof(*info)-sizeof(info->nTrackPos))) return 0;
1629 if (TRACE_ON(scroll))
1631 TRACE("hwnd=%p bar=%d", hwnd, nBar);
1632 if (info->fMask & SIF_PAGE) TRACE( " page=%d", info->nPage );
1633 if (info->fMask & SIF_POS) TRACE( " pos=%d", info->nPos );
1634 if (info->fMask & SIF_RANGE) TRACE( " min=%d max=%d", info->nMin, info->nMax );
1635 TRACE("\n");
1638 /* Set the page size */
1640 if (info->fMask & SIF_PAGE)
1642 if( infoPtr->page != info->nPage )
1644 infoPtr->page = info->nPage;
1645 *action |= SA_SSI_REFRESH;
1646 bChangeParams = TRUE;
1650 /* Set the scroll pos */
1652 if (info->fMask & SIF_POS)
1654 if( infoPtr->curVal != info->nPos )
1656 infoPtr->curVal = info->nPos;
1657 *action |= SA_SSI_REFRESH;
1661 /* Set the scroll range */
1663 if (info->fMask & SIF_RANGE)
1665 /* Invalid range -> range is set to (0,0) */
1666 if ((info->nMin > info->nMax) ||
1667 ((UINT)(info->nMax - info->nMin) >= 0x80000000))
1669 infoPtr->minVal = 0;
1670 infoPtr->maxVal = 0;
1671 bChangeParams = TRUE;
1673 else
1675 if( infoPtr->minVal != info->nMin ||
1676 infoPtr->maxVal != info->nMax )
1678 *action |= SA_SSI_REFRESH;
1679 infoPtr->minVal = info->nMin;
1680 infoPtr->maxVal = info->nMax;
1681 bChangeParams = TRUE;
1686 /* Make sure the page size is valid */
1688 if (infoPtr->page < 0) infoPtr->page = 0;
1689 else if (infoPtr->page > infoPtr->maxVal - infoPtr->minVal + 1 )
1690 infoPtr->page = infoPtr->maxVal - infoPtr->minVal + 1;
1692 /* Make sure the pos is inside the range */
1694 if (infoPtr->curVal < infoPtr->minVal)
1695 infoPtr->curVal = infoPtr->minVal;
1696 else if (infoPtr->curVal > infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1697 infoPtr->curVal = infoPtr->maxVal - max( infoPtr->page-1, 0 );
1699 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1700 infoPtr->page, infoPtr->curVal,
1701 infoPtr->minVal, infoPtr->maxVal );
1703 /* don't change the scrollbar state if SetScrollInfo
1704 * is just called with SIF_DISABLENOSCROLL
1706 if(!(info->fMask & SIF_ALL)) goto done;
1708 /* Check if the scrollbar should be hidden or disabled */
1710 if (info->fMask & (SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL))
1712 new_flags = infoPtr->flags;
1713 if (infoPtr->minVal >= infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1715 /* Hide or disable scroll-bar */
1716 if (info->fMask & SIF_DISABLENOSCROLL)
1718 new_flags = ESB_DISABLE_BOTH;
1719 *action |= SA_SSI_REFRESH;
1721 else if ((nBar != SB_CTL) && bChangeParams)
1723 *action = SA_SSI_HIDE;
1724 goto done;
1727 else /* Show and enable scroll-bar */
1729 new_flags = 0;
1730 if ((nBar != SB_CTL) && bChangeParams)
1731 *action |= SA_SSI_SHOW;
1734 if (infoPtr->flags != new_flags) /* check arrow flags */
1736 infoPtr->flags = new_flags;
1737 *action |= SA_SSI_REPAINT_ARROWS;
1741 done:
1742 /* Return current position */
1744 return infoPtr->curVal;
1748 /*************************************************************************
1749 * GetScrollInfo (USER32.@)
1751 * GetScrollInfo can be used to retrieve the position, upper bound,
1752 * lower bound, and page size of a scrollbar control.
1754 * RETURNS STD
1756 BOOL WINAPI GetScrollInfo(
1757 HWND hwnd /* [in] Handle of window with scrollbar(s) */,
1758 INT nBar /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1759 LPSCROLLINFO info /* [in/out] (fMask specifies which values to retrieve) */)
1761 TRACE("hwnd=%p nBar=%d info=%p\n", hwnd, nBar, info);
1763 /* Refer SB_CTL requests to the window */
1764 if (nBar == SB_CTL)
1765 return SendMessageA(hwnd, SBM_GETSCROLLINFO, (WPARAM)0, (LPARAM)info);
1766 else
1767 return SCROLL_GetScrollInfo(hwnd, nBar, info);
1771 /*************************************************************************
1772 * SetScrollPos (USER32.@)
1774 * RETURNS
1775 * Success: Scrollbar position
1776 * Failure: 0
1778 * REMARKS
1779 * Note the ambiguity when 0 is returned. Use GetLastError
1780 * to make sure there was an error (and to know which one).
1782 INT WINAPI SetScrollPos(
1783 HWND hwnd /* [in] Handle of window whose scrollbar will be affected */,
1784 INT nBar /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1785 INT nPos /* [in] New value */,
1786 BOOL bRedraw /* [in] Should scrollbar be redrawn afterwards ? */ )
1788 SCROLLINFO info;
1789 SCROLLBAR_INFO *infoPtr;
1790 INT oldPos;
1792 if (!(infoPtr = SCROLL_GetScrollBarInfo( hwnd, nBar ))) return 0;
1793 oldPos = infoPtr->curVal;
1794 info.cbSize = sizeof(info);
1795 info.nPos = nPos;
1796 info.fMask = SIF_POS;
1797 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1798 return oldPos;
1802 /*************************************************************************
1803 * GetScrollPos (USER32.@)
1805 * RETURNS
1806 * Success: Current position
1807 * Failure: 0
1809 * REMARKS
1810 * There is ambiguity when 0 is returned. Use GetLastError
1811 * to make sure there was an error (and to know which one).
1813 INT WINAPI GetScrollPos(
1814 HWND hwnd /* [in] Handle of window with scrollbar(s) */,
1815 INT nBar /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */)
1817 TRACE("hwnd=%p nBar=%d\n", hwnd, nBar);
1819 /* Refer SB_CTL requests to the window */
1820 if (nBar == SB_CTL)
1821 return SendMessageA(hwnd, SBM_GETPOS, (WPARAM)0, (LPARAM)0);
1822 else
1823 return SCROLL_GetScrollPos(hwnd, nBar);
1827 /*************************************************************************
1828 * SetScrollRange (USER32.@)
1830 * RETURNS STD
1832 BOOL WINAPI SetScrollRange(
1833 HWND hwnd, /* [in] Handle of window whose scrollbar will be affected */
1834 INT nBar, /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */
1835 INT minVal, /* [in] New minimum value */
1836 INT maxVal, /* [in] New maximum value */
1837 BOOL bRedraw /* [in] Should scrollbar be redrawn afterwards ? */)
1839 SCROLLINFO info;
1841 info.cbSize = sizeof(info);
1842 info.nMin = minVal;
1843 info.nMax = maxVal;
1844 info.fMask = SIF_RANGE;
1845 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1846 return TRUE;
1850 /*************************************************************************
1851 * SCROLL_SetNCSbState
1853 * Updates both scrollbars at the same time. Used by MDI CalcChildScroll().
1855 INT SCROLL_SetNCSbState(HWND hwnd, int vMin, int vMax, int vPos,
1856 int hMin, int hMax, int hPos)
1858 INT vA, hA;
1859 SCROLLINFO vInfo, hInfo;
1861 vInfo.cbSize = hInfo.cbSize = sizeof(SCROLLINFO);
1862 vInfo.nMin = vMin;
1863 vInfo.nMax = vMax;
1864 vInfo.nPos = vPos;
1865 hInfo.nMin = hMin;
1866 hInfo.nMax = hMax;
1867 hInfo.nPos = hPos;
1868 vInfo.fMask = hInfo.fMask = SIF_RANGE | SIF_POS;
1870 SCROLL_SetScrollInfo( hwnd, SB_VERT, &vInfo, &vA );
1871 SCROLL_SetScrollInfo( hwnd, SB_HORZ, &hInfo, &hA );
1873 if( !SCROLL_ShowScrollBar( hwnd, SB_BOTH,
1874 (hA & SA_SSI_SHOW),(vA & SA_SSI_SHOW) ) )
1876 /* SetWindowPos() wasn't called, just redraw the scrollbars if needed */
1877 if( vA & SA_SSI_REFRESH )
1878 SCROLL_RefreshScrollBar( hwnd, SB_VERT, FALSE, TRUE );
1880 if( hA & SA_SSI_REFRESH )
1881 SCROLL_RefreshScrollBar( hwnd, SB_HORZ, FALSE, TRUE );
1883 return 0;
1887 /*************************************************************************
1888 * GetScrollRange (USER32.@)
1890 * RETURNS STD
1892 BOOL WINAPI GetScrollRange(
1893 HWND hwnd /* [in] Handle of window with scrollbar(s) */,
1894 INT nBar /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1895 LPINT lpMin /* [out] Where to store minimum value */,
1896 LPINT lpMax /* [out] Where to store maximum value */)
1898 TRACE("hwnd=%p nBar=%d lpMin=%p lpMax=%p\n", hwnd, nBar, lpMin, lpMax);
1900 /* Refer SB_CTL requests to the window */
1901 if (nBar == SB_CTL)
1902 return SendMessageA(hwnd, SBM_GETRANGE, (WPARAM)lpMin, (LPARAM)lpMax);
1903 else
1904 return SCROLL_GetScrollRange(hwnd, nBar, lpMin, lpMax);
1908 /*************************************************************************
1909 * SCROLL_ShowScrollBar()
1911 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1913 BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar,
1914 BOOL fShowH, BOOL fShowV )
1916 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
1918 TRACE("hwnd=%p bar=%d horz=%d, vert=%d\n", hwnd, nBar, fShowH, fShowV );
1920 switch(nBar)
1922 case SB_CTL:
1923 ShowWindow( hwnd, fShowH ? SW_SHOW : SW_HIDE );
1924 return TRUE;
1926 case SB_BOTH:
1927 case SB_HORZ:
1928 if (fShowH)
1930 fShowH = !(style & WS_HSCROLL);
1931 style |= WS_HSCROLL;
1933 else /* hide it */
1935 fShowH = (style & WS_HSCROLL);
1936 style &= ~WS_HSCROLL;
1938 if( nBar == SB_HORZ ) {
1939 fShowV = FALSE;
1940 break;
1942 /* fall through */
1944 case SB_VERT:
1945 if (fShowV)
1947 fShowV = !(style & WS_VSCROLL);
1948 style |= WS_VSCROLL;
1950 else /* hide it */
1952 fShowV = (style & WS_VSCROLL);
1953 style &= ~WS_VSCROLL;
1955 if ( nBar == SB_VERT )
1956 fShowH = FALSE;
1957 break;
1959 default:
1960 return FALSE; /* Nothing to do! */
1963 if( fShowH || fShowV ) /* frame has been changed, let the window redraw itself */
1965 WIN_SetStyle( hwnd, style );
1966 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
1967 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
1968 return TRUE;
1970 return FALSE; /* no frame changes */
1974 /*************************************************************************
1975 * ShowScrollBar (USER32.@)
1977 * RETURNS STD
1979 BOOL WINAPI ShowScrollBar(
1980 HWND hwnd, /* [in] Handle of window whose scrollbar(s) will be affected */
1981 INT nBar, /* [in] One of SB_HORZ, SB_VERT, SB_BOTH or SB_CTL */
1982 BOOL fShow /* [in] TRUE = show, FALSE = hide */)
1984 SCROLL_ShowScrollBar( hwnd, nBar, (nBar == SB_VERT) ? 0 : fShow,
1985 (nBar == SB_HORZ) ? 0 : fShow );
1986 return TRUE;
1990 /*************************************************************************
1991 * EnableScrollBar (USER32.@)
1993 BOOL WINAPI EnableScrollBar( HWND hwnd, INT nBar, UINT flags )
1995 BOOL bFineWithMe;
1996 SCROLLBAR_INFO *infoPtr;
1998 TRACE("%p %d %d\n", hwnd, nBar, flags );
2000 flags &= ESB_DISABLE_BOTH;
2002 if (nBar == SB_BOTH)
2004 if (!(infoPtr = SCROLL_GetScrollBarInfo( hwnd, SB_VERT ))) return FALSE;
2005 if (!(bFineWithMe = (infoPtr->flags == flags)) )
2007 infoPtr->flags = flags;
2008 SCROLL_RefreshScrollBar( hwnd, SB_VERT, TRUE, TRUE );
2010 nBar = SB_HORZ;
2012 else
2013 bFineWithMe = TRUE;
2015 if (!(infoPtr = SCROLL_GetScrollBarInfo( hwnd, nBar ))) return FALSE;
2016 if (bFineWithMe && infoPtr->flags == flags) return FALSE;
2017 infoPtr->flags = flags;
2019 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
2020 return TRUE;