Move get current drive int21 function to winedos.
[wine/multimedia.git] / controls / scroll.c
blobce13566ad203c625499be69bed52a338a8fc8d1c
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 "windef.h"
23 #include "wingdi.h"
24 #include "wine/winuser16.h"
25 #include "controls.h"
26 #include "win.h"
27 #include "wine/debug.h"
28 #include "user.h"
29 #include "message.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(scroll);
33 typedef struct
35 INT curVal; /* Current scroll-bar value */
36 INT minVal; /* Minimum scroll-bar value */
37 INT maxVal; /* Maximum scroll-bar value */
38 INT page; /* Page size of scroll bar (Win32) */
39 UINT flags; /* EnableScrollBar flags */
40 } SCROLLBAR_INFO, *LPSCROLLBAR_INFO;
43 static HBITMAP hUpArrow;
44 static HBITMAP hDnArrow;
45 static HBITMAP hLfArrow;
46 static HBITMAP hRgArrow;
47 static HBITMAP hUpArrowD;
48 static HBITMAP hDnArrowD;
49 static HBITMAP hLfArrowD;
50 static HBITMAP hRgArrowD;
51 static HBITMAP hUpArrowI;
52 static HBITMAP hDnArrowI;
53 static HBITMAP hLfArrowI;
54 static HBITMAP hRgArrowI;
56 #define TOP_ARROW(flags,pressed) \
57 (((flags)&ESB_DISABLE_UP) ? hUpArrowI : ((pressed) ? hUpArrowD:hUpArrow))
58 #define BOTTOM_ARROW(flags,pressed) \
59 (((flags)&ESB_DISABLE_DOWN) ? hDnArrowI : ((pressed) ? hDnArrowD:hDnArrow))
60 #define LEFT_ARROW(flags,pressed) \
61 (((flags)&ESB_DISABLE_LEFT) ? hLfArrowI : ((pressed) ? hLfArrowD:hLfArrow))
62 #define RIGHT_ARROW(flags,pressed) \
63 (((flags)&ESB_DISABLE_RIGHT) ? hRgArrowI : ((pressed) ? hRgArrowD:hRgArrow))
66 /* Minimum size of the rectangle between the arrows */
67 #define SCROLL_MIN_RECT 4
69 /* Minimum size of the thumb in pixels */
70 #define SCROLL_MIN_THUMB 6
72 /* Overlap between arrows and thumb */
73 #define SCROLL_ARROW_THUMB_OVERLAP ((TWEAK_WineLook == WIN31_LOOK) ? 1 : 0)
75 /* Delay (in ms) before first repetition when holding the button down */
76 #define SCROLL_FIRST_DELAY 200
78 /* Delay (in ms) between scroll repetitions */
79 #define SCROLL_REPEAT_DELAY 50
81 /* Scroll timer id */
82 #define SCROLL_TIMER 0
84 /* Scroll-bar hit testing */
85 enum SCROLL_HITTEST
87 SCROLL_NOWHERE, /* Outside the scroll bar */
88 SCROLL_TOP_ARROW, /* Top or left arrow */
89 SCROLL_TOP_RECT, /* Rectangle between the top arrow and the thumb */
90 SCROLL_THUMB, /* Thumb rectangle */
91 SCROLL_BOTTOM_RECT, /* Rectangle between the thumb and the bottom arrow */
92 SCROLL_BOTTOM_ARROW /* Bottom or right arrow */
95 /* What to do after SCROLL_SetScrollInfo() */
96 #define SA_SSI_HIDE 0x0001
97 #define SA_SSI_SHOW 0x0002
98 #define SA_SSI_REFRESH 0x0004
99 #define SA_SSI_REPAINT_ARROWS 0x0008
101 /* Thumb-tracking info */
102 static HWND SCROLL_TrackingWin = 0;
103 static INT SCROLL_TrackingBar = 0;
104 static INT SCROLL_TrackingPos = 0;
105 static INT SCROLL_TrackingVal = 0;
106 /* Hit test code of the last button-down event */
107 static enum SCROLL_HITTEST SCROLL_trackHitTest;
108 static BOOL SCROLL_trackVertical;
110 /* Is the moving thumb being displayed? */
111 static BOOL SCROLL_MovingThumb = FALSE;
113 /* Local functions */
114 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar,
115 BOOL fShowH, BOOL fShowV );
116 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar,
117 const SCROLLINFO *info, INT *action );
118 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
119 RECT *rect, INT arrowSize,
120 INT thumbSize, INT thumbPos,
121 UINT flags, BOOL vertical,
122 BOOL top_selected, BOOL bottom_selected );
123 static LRESULT WINAPI ScrollBarWndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
126 /*********************************************************************
127 * scrollbar class descriptor
129 const struct builtin_class_descr SCROLL_builtin_class =
131 "ScrollBar", /* name */
132 CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC, /* style */
133 NULL, /* procA (winproc is Unicode only) */
134 ScrollBarWndProc, /* procW */
135 sizeof(SCROLLBAR_INFO), /* extra */
136 IDC_ARROWA, /* cursor */
137 0 /* brush */
140 /***********************************************************************
141 * SCROLL_ScrollInfoValid
143 * Determine if the supplied SCROLLINFO struct is valid.
145 inline static BOOL SCROLL_ScrollInfoValid(
146 LPSCROLLINFO info /* [in] The SCROLLINFO struct to be tested */)
148 return !(info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)
149 || (info->cbSize != sizeof(*info)
150 && info->cbSize != sizeof(*info) - sizeof(info->nTrackPos)));
154 /***********************************************************************
155 * SCROLL_LoadBitmaps
157 static void SCROLL_LoadBitmaps(void)
159 hUpArrow = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROW) );
160 hDnArrow = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROW) );
161 hLfArrow = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROW) );
162 hRgArrow = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROW) );
163 hUpArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROWD) );
164 hDnArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROWD) );
165 hLfArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROWD) );
166 hRgArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROWD) );
167 hUpArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROWI) );
168 hDnArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROWI) );
169 hLfArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROWI) );
170 hRgArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROWI) );
174 /***********************************************************************
175 * SCROLL_GetScrollBarInfo
177 static SCROLLBAR_INFO *SCROLL_GetScrollBarInfo( HWND hwnd, INT nBar )
179 SCROLLBAR_INFO *infoPtr;
180 WND *wndPtr = WIN_FindWndPtr( hwnd );
182 if (!wndPtr) return NULL;
183 switch(nBar)
185 case SB_HORZ: infoPtr = (SCROLLBAR_INFO *)wndPtr->pHScroll; break;
186 case SB_VERT: infoPtr = (SCROLLBAR_INFO *)wndPtr->pVScroll; break;
187 case SB_CTL: infoPtr = (SCROLLBAR_INFO *)wndPtr->wExtra; break;
188 default:
189 WIN_ReleaseWndPtr( wndPtr );
190 return NULL;
193 if (!infoPtr) /* Create the info structure if needed */
195 if ((infoPtr = HeapAlloc( GetProcessHeap(), 0, sizeof(SCROLLBAR_INFO) )))
197 infoPtr->minVal = infoPtr->curVal = infoPtr->page = 0;
198 infoPtr->maxVal = 100;
199 infoPtr->flags = ESB_ENABLE_BOTH;
200 if (nBar == SB_HORZ) wndPtr->pHScroll = infoPtr;
201 else wndPtr->pVScroll = infoPtr;
203 if (!hUpArrow) SCROLL_LoadBitmaps();
205 WIN_ReleaseWndPtr( wndPtr );
206 return infoPtr;
210 /***********************************************************************
211 * SCROLL_GetScrollBarRect
213 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
214 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
215 * 'arrowSize' returns the width or height of an arrow (depending on
216 * the orientation of the scrollbar), 'thumbSize' returns the size of
217 * the thumb, and 'thumbPos' returns the position of the thumb
218 * relative to the left or to the top.
219 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
221 static BOOL SCROLL_GetScrollBarRect( HWND hwnd, INT nBar, RECT *lprect,
222 INT *arrowSize, INT *thumbSize,
223 INT *thumbPos )
225 INT pixels;
226 BOOL vertical;
227 WND *wndPtr = WIN_FindWndPtr( hwnd );
229 switch(nBar)
231 case SB_HORZ:
232 lprect->left = wndPtr->rectClient.left - wndPtr->rectWindow.left;
233 lprect->top = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
234 lprect->right = wndPtr->rectClient.right - wndPtr->rectWindow.left;
235 lprect->bottom = lprect->top + GetSystemMetrics(SM_CYHSCROLL);
236 if(wndPtr->dwStyle & WS_BORDER) {
237 lprect->left--;
238 lprect->right++;
239 } else if(wndPtr->dwStyle & WS_VSCROLL)
240 lprect->right++;
241 vertical = FALSE;
242 break;
244 case SB_VERT:
245 if((wndPtr->dwExStyle & WS_EX_LEFTSCROLLBAR) != 0)
246 lprect->left = wndPtr->rectClient.left - wndPtr->rectWindow.left - GetSystemMetrics(SM_CXVSCROLL);
247 else
248 lprect->left = wndPtr->rectClient.right - wndPtr->rectWindow.left;
249 lprect->top = wndPtr->rectClient.top - wndPtr->rectWindow.top;
250 lprect->right = lprect->left + GetSystemMetrics(SM_CXVSCROLL);
251 lprect->bottom = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
252 if(wndPtr->dwStyle & WS_BORDER) {
253 lprect->top--;
254 lprect->bottom++;
255 } else if(wndPtr->dwStyle & WS_HSCROLL)
256 lprect->bottom++;
257 vertical = TRUE;
258 break;
260 case SB_CTL:
261 GetClientRect( hwnd, lprect );
262 vertical = ((wndPtr->dwStyle & SBS_VERT) != 0);
263 break;
265 default:
266 WIN_ReleaseWndPtr(wndPtr);
267 return FALSE;
270 if (vertical) pixels = lprect->bottom - lprect->top;
271 else pixels = lprect->right - lprect->left;
273 if (pixels <= 2*GetSystemMetrics(SM_CXVSCROLL) + SCROLL_MIN_RECT)
275 if (pixels > SCROLL_MIN_RECT)
276 *arrowSize = (pixels - SCROLL_MIN_RECT) / 2;
277 else
278 *arrowSize = 0;
279 *thumbPos = *thumbSize = 0;
281 else
283 SCROLLBAR_INFO *info = SCROLL_GetScrollBarInfo( hwnd, nBar );
285 *arrowSize = GetSystemMetrics(SM_CXVSCROLL);
286 pixels -= (2 * (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP));
288 if (info->page)
290 *thumbSize = MulDiv(pixels,info->page,(info->maxVal-info->minVal+1));
291 if (*thumbSize < SCROLL_MIN_THUMB) *thumbSize = SCROLL_MIN_THUMB;
293 else *thumbSize = GetSystemMetrics(SM_CXVSCROLL);
295 if (((pixels -= *thumbSize ) < 0) ||
296 ((info->flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH))
298 /* Rectangle too small or scrollbar disabled -> no thumb */
299 *thumbPos = *thumbSize = 0;
301 else
303 INT max = info->maxVal - max( info->page-1, 0 );
304 if (info->minVal >= max)
305 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
306 else
307 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP
308 + MulDiv(pixels, (info->curVal-info->minVal),(max - info->minVal));
311 WIN_ReleaseWndPtr(wndPtr);
312 return vertical;
316 /***********************************************************************
317 * SCROLL_GetThumbVal
319 * Compute the current scroll position based on the thumb position in pixels
320 * from the top of the scroll-bar.
322 static UINT SCROLL_GetThumbVal( SCROLLBAR_INFO *infoPtr, RECT *rect,
323 BOOL vertical, INT pos )
325 INT thumbSize;
326 INT pixels = vertical ? rect->bottom-rect->top : rect->right-rect->left;
328 if ((pixels -= 2*(GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP)) <= 0)
329 return infoPtr->minVal;
331 if (infoPtr->page)
333 thumbSize = MulDiv(pixels,infoPtr->page,(infoPtr->maxVal-infoPtr->minVal+1));
334 if (thumbSize < SCROLL_MIN_THUMB) thumbSize = SCROLL_MIN_THUMB;
336 else thumbSize = GetSystemMetrics(SM_CXVSCROLL);
338 if ((pixels -= thumbSize) <= 0) return infoPtr->minVal;
340 pos = max( 0, pos - (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP) );
341 if (pos > pixels) pos = pixels;
343 if (!infoPtr->page) pos *= infoPtr->maxVal - infoPtr->minVal;
344 else pos *= infoPtr->maxVal - infoPtr->minVal - infoPtr->page + 1;
345 return infoPtr->minVal + ((pos + pixels / 2) / pixels);
348 /***********************************************************************
349 * SCROLL_PtInRectEx
351 static BOOL SCROLL_PtInRectEx( LPRECT lpRect, POINT pt, BOOL vertical )
353 RECT rect = *lpRect;
355 if (vertical)
357 rect.left -= lpRect->right - lpRect->left;
358 rect.right += lpRect->right - lpRect->left;
360 else
362 rect.top -= lpRect->bottom - lpRect->top;
363 rect.bottom += lpRect->bottom - lpRect->top;
365 return PtInRect( &rect, pt );
368 /***********************************************************************
369 * SCROLL_ClipPos
371 static POINT SCROLL_ClipPos( LPRECT lpRect, POINT pt )
373 if( pt.x < lpRect->left )
374 pt.x = lpRect->left;
375 else
376 if( pt.x > lpRect->right )
377 pt.x = lpRect->right;
379 if( pt.y < lpRect->top )
380 pt.y = lpRect->top;
381 else
382 if( pt.y > lpRect->bottom )
383 pt.y = lpRect->bottom;
385 return pt;
389 /***********************************************************************
390 * SCROLL_HitTest
392 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
394 static enum SCROLL_HITTEST SCROLL_HitTest( HWND hwnd, INT nBar,
395 POINT pt, BOOL bDragging )
397 INT arrowSize, thumbSize, thumbPos;
398 RECT rect;
400 BOOL vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
401 &arrowSize, &thumbSize, &thumbPos );
403 if ( (bDragging && !SCROLL_PtInRectEx( &rect, pt, vertical )) ||
404 (!PtInRect( &rect, pt )) ) return SCROLL_NOWHERE;
406 if (vertical)
408 if (pt.y < rect.top + arrowSize) return SCROLL_TOP_ARROW;
409 if (pt.y >= rect.bottom - arrowSize) return SCROLL_BOTTOM_ARROW;
410 if (!thumbPos) return SCROLL_TOP_RECT;
411 pt.y -= rect.top;
412 if (pt.y < thumbPos) return SCROLL_TOP_RECT;
413 if (pt.y >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
415 else /* horizontal */
417 if (pt.x < rect.left + arrowSize) return SCROLL_TOP_ARROW;
418 if (pt.x >= rect.right - arrowSize) return SCROLL_BOTTOM_ARROW;
419 if (!thumbPos) return SCROLL_TOP_RECT;
420 pt.x -= rect.left;
421 if (pt.x < thumbPos) return SCROLL_TOP_RECT;
422 if (pt.x >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
424 return SCROLL_THUMB;
428 /***********************************************************************
429 * SCROLL_DrawArrows
431 * Draw the scroll bar arrows.
433 static void SCROLL_DrawArrows_9x( HDC hdc, SCROLLBAR_INFO *infoPtr,
434 RECT *rect, INT arrowSize, BOOL vertical,
435 BOOL top_pressed, BOOL bottom_pressed )
437 RECT r;
439 r = *rect;
440 if( vertical )
441 r.bottom = r.top + arrowSize;
442 else
443 r.right = r.left + arrowSize;
445 DrawFrameControl( hdc, &r, DFC_SCROLL,
446 (vertical ? DFCS_SCROLLUP : DFCS_SCROLLLEFT)
447 | (top_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
448 | (infoPtr->flags&ESB_DISABLE_LTUP ? DFCS_INACTIVE : 0 ) );
450 r = *rect;
451 if( vertical )
452 r.top = r.bottom-arrowSize;
453 else
454 r.left = r.right-arrowSize;
456 DrawFrameControl( hdc, &r, DFC_SCROLL,
457 (vertical ? DFCS_SCROLLDOWN : DFCS_SCROLLRIGHT)
458 | (bottom_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
459 | (infoPtr->flags&ESB_DISABLE_RTDN ? DFCS_INACTIVE : 0) );
462 static void SCROLL_DrawArrows_31( HDC hdc, SCROLLBAR_INFO *infoPtr,
463 RECT *rect, INT arrowSize, BOOL vertical,
464 BOOL top_pressed, BOOL bottom_pressed )
466 HDC hdcMem = CreateCompatibleDC( hdc );
467 HBITMAP hbmpPrev = SelectObject( hdcMem, vertical ?
468 TOP_ARROW(infoPtr->flags, top_pressed)
469 : LEFT_ARROW(infoPtr->flags, top_pressed));
471 SetStretchBltMode( hdc, STRETCH_DELETESCANS );
472 StretchBlt( hdc, rect->left, rect->top,
473 vertical ? rect->right-rect->left : arrowSize,
474 vertical ? arrowSize : rect->bottom-rect->top,
475 hdcMem, 0, 0,
476 GetSystemMetrics(SM_CXVSCROLL),GetSystemMetrics(SM_CYHSCROLL),
477 SRCCOPY );
479 SelectObject( hdcMem, vertical ?
480 BOTTOM_ARROW( infoPtr->flags, bottom_pressed )
481 : RIGHT_ARROW( infoPtr->flags, bottom_pressed ) );
482 if (vertical)
483 StretchBlt( hdc, rect->left, rect->bottom - arrowSize,
484 rect->right - rect->left, arrowSize,
485 hdcMem, 0, 0,
486 GetSystemMetrics(SM_CXVSCROLL),GetSystemMetrics(SM_CYHSCROLL),
487 SRCCOPY );
488 else
489 StretchBlt( hdc, rect->right - arrowSize, rect->top,
490 arrowSize, rect->bottom - rect->top,
491 hdcMem, 0, 0,
492 GetSystemMetrics(SM_CXVSCROLL), GetSystemMetrics(SM_CYHSCROLL),
493 SRCCOPY );
494 SelectObject( hdcMem, hbmpPrev );
495 DeleteDC( hdcMem );
498 static void SCROLL_DrawArrows( HDC hdc, SCROLLBAR_INFO *infoPtr,
499 RECT *rect, INT arrowSize, BOOL vertical,
500 BOOL top_pressed, BOOL bottom_pressed )
502 if( TWEAK_WineLook == WIN31_LOOK )
503 SCROLL_DrawArrows_31( hdc, infoPtr, rect, arrowSize,
504 vertical, top_pressed,bottom_pressed );
505 else
506 SCROLL_DrawArrows_9x( hdc, infoPtr, rect, arrowSize,
507 vertical, top_pressed,bottom_pressed );
511 /***********************************************************************
512 * SCROLL_DrawMovingThumb
514 * Draw the moving thumb rectangle.
516 static void SCROLL_DrawMovingThumb_31( HDC hdc, RECT *rect, BOOL vertical,
517 INT arrowSize, INT thumbSize )
519 RECT r = *rect;
520 if (vertical)
522 r.top += SCROLL_TrackingPos;
523 if (r.top < rect->top + arrowSize - SCROLL_ARROW_THUMB_OVERLAP)
524 r.top = rect->top + arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
525 if (r.top + thumbSize >
526 rect->bottom - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP))
527 r.top = rect->bottom - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP)
528 - thumbSize;
529 r.bottom = r.top + thumbSize;
531 else
533 r.left += SCROLL_TrackingPos;
534 if (r.left < rect->left + arrowSize - SCROLL_ARROW_THUMB_OVERLAP)
535 r.left = rect->left + arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
536 if (r.left + thumbSize >
537 rect->right - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP))
538 r.left = rect->right - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP)
539 - thumbSize;
540 r.right = r.left + thumbSize;
543 DrawFocusRect( hdc, &r );
544 SCROLL_MovingThumb = !SCROLL_MovingThumb;
547 static void SCROLL_DrawMovingThumb_9x( HDC hdc, RECT *rect, BOOL vertical,
548 INT arrowSize, INT thumbSize )
550 INT pos = SCROLL_TrackingPos;
551 INT max_size;
553 if( vertical )
554 max_size = rect->bottom - rect->top;
555 else
556 max_size = rect->right - rect->left;
558 max_size -= (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) + thumbSize;
560 if( pos < (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) )
561 pos = (arrowSize-SCROLL_ARROW_THUMB_OVERLAP);
562 else if( pos > max_size )
563 pos = max_size;
565 SCROLL_DrawInterior_9x( SCROLL_TrackingWin, hdc, SCROLL_TrackingBar,
566 rect, arrowSize, thumbSize, pos,
567 0, vertical, FALSE, FALSE );
569 SCROLL_MovingThumb = !SCROLL_MovingThumb;
572 static void SCROLL_DrawMovingThumb( HDC hdc, RECT *rect, BOOL vertical,
573 INT arrowSize, INT thumbSize )
575 if( TWEAK_WineLook == WIN31_LOOK )
576 SCROLL_DrawMovingThumb_31( hdc, rect, vertical, arrowSize, thumbSize );
577 else
578 SCROLL_DrawMovingThumb_9x( hdc, rect, vertical, arrowSize, thumbSize );
581 /***********************************************************************
582 * SCROLL_DrawInterior
584 * Draw the scroll bar interior (everything except the arrows).
586 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
587 RECT *rect, INT arrowSize,
588 INT thumbSize, INT thumbPos,
589 UINT flags, BOOL vertical,
590 BOOL top_selected, BOOL bottom_selected )
592 RECT r;
593 HPEN hSavePen;
594 HBRUSH hSaveBrush,hBrush;
596 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
597 * The window-owned scrollbars need to call DEFWND_ControlColor
598 * to correctly setup default scrollbar colors
600 if (nBar == SB_CTL)
602 hBrush = (HBRUSH)SendMessageA( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
603 (WPARAM)hdc,(LPARAM)hwnd);
605 else
607 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
610 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
611 hSaveBrush = SelectObject( hdc, hBrush );
613 /* Calculate the scroll rectangle */
614 r = *rect;
615 if (vertical)
617 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
618 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
620 else
622 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
623 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
626 /* Draw the scroll rectangles and thumb */
627 if (!thumbPos) /* No thumb to draw */
629 PatBlt( hdc, r.left, r.top,
630 r.right - r.left, r.bottom - r.top,
631 PATCOPY );
633 /* cleanup and return */
634 SelectObject( hdc, hSavePen );
635 SelectObject( hdc, hSaveBrush );
636 return;
639 if (vertical)
641 PatBlt( hdc, r.left, r.top,
642 r.right - r.left,
643 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
644 top_selected ? 0x0f0000 : PATCOPY );
645 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
646 PatBlt( hdc, r.left, r.top + thumbSize,
647 r.right - r.left,
648 r.bottom - r.top - thumbSize,
649 bottom_selected ? 0x0f0000 : PATCOPY );
650 r.bottom = r.top + thumbSize;
652 else /* horizontal */
654 PatBlt( hdc, r.left, r.top,
655 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
656 r.bottom - r.top,
657 top_selected ? 0x0f0000 : PATCOPY );
658 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
659 PatBlt( hdc, r.left + thumbSize, r.top,
660 r.right - r.left - thumbSize,
661 r.bottom - r.top,
662 bottom_selected ? 0x0f0000 : PATCOPY );
663 r.right = r.left + thumbSize;
666 /* Draw the thumb */
667 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT | BF_MIDDLE );
669 /* cleanup */
670 SelectObject( hdc, hSavePen );
671 SelectObject( hdc, hSaveBrush );
675 static void SCROLL_DrawInterior( HWND hwnd, HDC hdc, INT nBar,
676 RECT *rect, INT arrowSize,
677 INT thumbSize, INT thumbPos,
678 UINT flags, BOOL vertical,
679 BOOL top_selected, BOOL bottom_selected )
681 RECT r;
682 HPEN hSavePen;
683 HBRUSH hSaveBrush,hBrush;
684 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
686 if (Save_SCROLL_MovingThumb &&
687 (SCROLL_TrackingWin == hwnd) &&
688 (SCROLL_TrackingBar == nBar))
689 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
691 /* Select the correct brush and pen */
693 if (TWEAK_WineLook == WIN31_LOOK && (flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH)
695 /* This ought to be the color of the parent window */
696 hBrush = GetSysColorBrush(COLOR_WINDOW);
698 else
700 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
701 * The window-owned scrollbars need to call DEFWND_ControlColor
702 * to correctly setup default scrollbar colors
704 if (nBar == SB_CTL) {
705 hBrush = (HBRUSH)SendMessageA( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
706 (WPARAM)hdc,(LPARAM)hwnd);
707 } else {
708 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
711 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
712 hSaveBrush = SelectObject( hdc, hBrush );
714 /* Calculate the scroll rectangle */
716 r = *rect;
717 if (vertical)
719 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
720 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
722 else
724 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
725 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
728 /* Draw the scroll bar frame */
730 /* Only draw outline if Win 3.1. Mar 24, 1999 - Ronald B. Cemer */
731 if (TWEAK_WineLook == WIN31_LOOK)
732 Rectangle( hdc, r.left, r.top, r.right, r.bottom );
734 /* Draw the scroll rectangles and thumb */
736 if (!thumbPos) /* No thumb to draw */
738 INT offset = (TWEAK_WineLook > WIN31_LOOK) ? 0 : 1;
740 PatBlt( hdc, r.left+offset, r.top+offset,
741 r.right - r.left - 2*offset, r.bottom - r.top - 2*offset,
742 PATCOPY );
744 /* cleanup and return */
745 SelectObject( hdc, hSavePen );
746 SelectObject( hdc, hSaveBrush );
747 return;
750 if (vertical)
752 INT offset = (TWEAK_WineLook == WIN31_LOOK) ? 1 : 0;
754 PatBlt( hdc, r.left + offset, r.top + offset,
755 r.right - r.left - offset*2,
756 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP) - offset,
757 top_selected ? 0x0f0000 : PATCOPY );
758 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
759 PatBlt( hdc, r.left + offset, r.top + thumbSize,
760 r.right - r.left - offset*2,
761 r.bottom - r.top - thumbSize - offset,
762 bottom_selected ? 0x0f0000 : PATCOPY );
763 r.bottom = r.top + thumbSize;
765 else /* horizontal */
767 INT offset = (TWEAK_WineLook == WIN31_LOOK) ? 1 : 0;
769 PatBlt( hdc, r.left + offset, r.top + offset,
770 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
771 r.bottom - r.top - offset*2,
772 top_selected ? 0x0f0000 : PATCOPY );
773 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
774 PatBlt( hdc, r.left + thumbSize, r.top + offset,
775 r.right - r.left - thumbSize - offset,
776 r.bottom - r.top - offset*2,
777 bottom_selected ? 0x0f0000 : PATCOPY );
778 r.right = r.left + thumbSize;
781 /* Draw the thumb */
783 SelectObject( hdc, GetSysColorBrush(COLOR_BTNFACE) );
784 if (TWEAK_WineLook == WIN31_LOOK)
786 Rectangle( hdc, r.left, r.top, r.right, r.bottom );
787 r.top++, r.left++;
789 else
791 Rectangle( hdc, r.left+1, r.top+1, r.right-1, r.bottom-1 );
793 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT );
795 if (Save_SCROLL_MovingThumb &&
796 (SCROLL_TrackingWin == hwnd) &&
797 (SCROLL_TrackingBar == nBar))
798 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
800 /* cleanup */
801 SelectObject( hdc, hSavePen );
802 SelectObject( hdc, hSaveBrush );
806 /***********************************************************************
807 * SCROLL_DrawScrollBar
809 * Redraw the whole scrollbar.
811 void SCROLL_DrawScrollBar( HWND hwnd, HDC hdc, INT nBar,
812 BOOL arrows, BOOL interior )
814 INT arrowSize, thumbSize, thumbPos;
815 RECT rect;
816 BOOL vertical;
817 WND *wndPtr = WIN_FindWndPtr( hwnd );
818 SCROLLBAR_INFO *infoPtr = SCROLL_GetScrollBarInfo( hwnd, nBar );
819 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
821 if (!wndPtr || !infoPtr ||
822 ((nBar == SB_VERT) && !(wndPtr->dwStyle & WS_VSCROLL)) ||
823 ((nBar == SB_HORZ) && !(wndPtr->dwStyle & WS_HSCROLL))) goto END;
824 if (!WIN_IsWindowDrawable( hwnd, FALSE )) goto END;
825 hwnd = wndPtr->hwndSelf; /* make it a full handle */
827 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
828 &arrowSize, &thumbSize, &thumbPos );
830 /* do not draw if the scrollbar rectangle is empty */
831 if(IsRectEmpty(&rect))
832 goto END;
834 if (Save_SCROLL_MovingThumb &&
835 (SCROLL_TrackingWin == hwnd) &&
836 (SCROLL_TrackingBar == nBar))
837 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
839 /* Draw the arrows */
841 if (arrows && arrowSize)
843 if( vertical == SCROLL_trackVertical && GetCapture() == hwnd )
844 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
845 (SCROLL_trackHitTest == SCROLL_TOP_ARROW),
846 (SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW) );
847 else
848 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
849 FALSE, FALSE );
851 if( interior )
852 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
853 thumbPos, infoPtr->flags, vertical, FALSE, FALSE );
855 if (Save_SCROLL_MovingThumb &&
856 (SCROLL_TrackingWin == hwnd) &&
857 (SCROLL_TrackingBar == nBar))
858 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
860 /* if scroll bar has focus, reposition the caret */
861 if(hwnd==GetFocus() && (nBar==SB_CTL))
863 if (!vertical)
865 SetCaretPos(thumbPos+1, rect.top+1);
867 else
869 SetCaretPos(rect.top+1, thumbPos+1);
873 END:
874 WIN_ReleaseWndPtr(wndPtr);
878 /***********************************************************************
879 * SCROLL_RefreshScrollBar
881 * Repaint the scroll bar interior after a SetScrollRange() or
882 * SetScrollPos() call.
884 static void SCROLL_RefreshScrollBar( HWND hwnd, INT nBar,
885 BOOL arrows, BOOL interior )
887 HDC hdc = GetDCEx( hwnd, 0,
888 DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW) );
889 if (!hdc) return;
891 SCROLL_DrawScrollBar( hwnd, hdc, nBar, arrows, interior );
892 ReleaseDC( hwnd, hdc );
896 /***********************************************************************
897 * SCROLL_HandleKbdEvent
899 * Handle a keyboard event (only for SB_CTL scrollbars with focus).
901 static void SCROLL_HandleKbdEvent(
902 HWND hwnd /* [in] Handle of window with scrollbar(s) */,
903 WPARAM wParam /* [in] Variable input including enable state */,
904 LPARAM lParam /* [in] Variable input including input point */)
906 TRACE("hwnd=%p wParam=%d lParam=%ld\n", hwnd, wParam, lParam);
908 /* hide caret on first KEYDOWN to prevent flicker */
909 if ((lParam & PFD_DOUBLEBUFFER_DONTCARE) == 0)
910 HideCaret(hwnd);
912 switch(wParam)
914 case VK_PRIOR: wParam = SB_PAGEUP; break;
915 case VK_NEXT: wParam = SB_PAGEDOWN; break;
916 case VK_HOME: wParam = SB_TOP; break;
917 case VK_END: wParam = SB_BOTTOM; break;
918 case VK_UP: wParam = SB_LINEUP; break;
919 case VK_DOWN: wParam = SB_LINEDOWN; break;
920 default: return;
922 SendMessageW(GetParent(hwnd),
923 ((GetWindowLongA( hwnd, GWL_STYLE ) & SBS_VERT) ?
924 WM_VSCROLL : WM_HSCROLL), wParam, (LPARAM)hwnd);
928 /***********************************************************************
929 * SCROLL_HandleScrollEvent
931 * Handle a mouse or timer event for the scrollbar.
932 * 'pt' is the location of the mouse event in client (for SB_CTL) or
933 * windows coordinates.
935 static void SCROLL_HandleScrollEvent( HWND hwnd, INT nBar, UINT msg, POINT pt)
937 /* Previous mouse position for timer events */
938 static POINT prevPt;
939 /* Thumb position when tracking started. */
940 static UINT trackThumbPos;
941 /* Position in the scroll-bar of the last button-down event. */
942 static INT lastClickPos;
943 /* Position in the scroll-bar of the last mouse event. */
944 static INT lastMousePos;
946 enum SCROLL_HITTEST hittest;
947 HWND hwndOwner, hwndCtl;
948 BOOL vertical;
949 INT arrowSize, thumbSize, thumbPos;
950 RECT rect;
951 HDC hdc;
953 SCROLLBAR_INFO *infoPtr = SCROLL_GetScrollBarInfo( hwnd, nBar );
954 if (!infoPtr) return;
955 if ((SCROLL_trackHitTest == SCROLL_NOWHERE) && (msg != WM_LBUTTONDOWN))
956 return;
958 hdc = GetDCEx( hwnd, 0, DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW));
959 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
960 &arrowSize, &thumbSize, &thumbPos );
961 hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd) : hwnd;
962 hwndCtl = (nBar == SB_CTL) ? hwnd : 0;
964 switch(msg)
966 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
967 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
968 SCROLL_trackVertical = vertical;
969 SCROLL_trackHitTest = hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
970 lastClickPos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
971 lastMousePos = lastClickPos;
972 trackThumbPos = thumbPos;
973 prevPt = pt;
974 if (nBar == SB_CTL && (GetWindowLongA(hwnd, GWL_STYLE) & WS_TABSTOP)) SetFocus( hwnd );
975 SetCapture( hwnd );
976 break;
978 case WM_MOUSEMOVE:
979 hittest = SCROLL_HitTest( hwnd, nBar, pt, TRUE );
980 prevPt = pt;
981 break;
983 case WM_LBUTTONUP:
984 hittest = SCROLL_NOWHERE;
985 ReleaseCapture();
986 /* if scrollbar has focus, show back caret */
987 if (hwnd==GetFocus()) ShowCaret(hwnd);
988 break;
990 case WM_SYSTIMER:
991 pt = prevPt;
992 hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
993 break;
995 default:
996 return; /* Should never happen */
999 TRACE("Event: hwnd=%p bar=%d msg=%s pt=%ld,%ld hit=%d\n",
1000 hwnd, nBar, SPY_GetMsgName(msg,hwnd), pt.x, pt.y, hittest );
1002 switch(SCROLL_trackHitTest)
1004 case SCROLL_NOWHERE: /* No tracking in progress */
1005 break;
1007 case SCROLL_TOP_ARROW:
1008 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
1009 (hittest == SCROLL_trackHitTest), FALSE );
1010 if (hittest == SCROLL_trackHitTest)
1012 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1014 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1015 SB_LINEUP, (LPARAM)hwndCtl );
1018 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1019 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1020 (TIMERPROC)0 );
1022 else KillSystemTimer( hwnd, SCROLL_TIMER );
1023 break;
1025 case SCROLL_TOP_RECT:
1026 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
1027 thumbPos, infoPtr->flags, vertical,
1028 (hittest == SCROLL_trackHitTest), FALSE );
1029 if (hittest == SCROLL_trackHitTest)
1031 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1033 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1034 SB_PAGEUP, (LPARAM)hwndCtl );
1036 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1037 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1038 (TIMERPROC)0 );
1040 else KillSystemTimer( hwnd, SCROLL_TIMER );
1041 break;
1043 case SCROLL_THUMB:
1044 if (msg == WM_LBUTTONDOWN)
1046 SCROLL_TrackingWin = hwnd;
1047 SCROLL_TrackingBar = nBar;
1048 SCROLL_TrackingPos = trackThumbPos + lastMousePos - lastClickPos;
1049 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
1050 vertical,
1051 SCROLL_TrackingPos );
1052 if (!SCROLL_MovingThumb)
1053 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
1055 else if (msg == WM_LBUTTONUP)
1057 if (SCROLL_MovingThumb)
1058 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
1059 SCROLL_TrackingWin = 0;
1060 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
1061 thumbPos, infoPtr->flags, vertical,
1062 FALSE, FALSE );
1064 else /* WM_MOUSEMOVE */
1066 UINT pos;
1068 if (!SCROLL_PtInRectEx( &rect, pt, vertical )) pos = lastClickPos;
1069 else
1071 pt = SCROLL_ClipPos( &rect, pt );
1072 pos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
1074 if ( (pos != lastMousePos) || (!SCROLL_MovingThumb) )
1076 if (SCROLL_MovingThumb)
1077 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
1078 arrowSize, thumbSize );
1079 lastMousePos = pos;
1080 SCROLL_TrackingPos = trackThumbPos + pos - lastClickPos;
1081 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
1082 vertical,
1083 SCROLL_TrackingPos );
1084 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1085 MAKEWPARAM( SB_THUMBTRACK, SCROLL_TrackingVal),
1086 (LPARAM)hwndCtl );
1087 if (!SCROLL_MovingThumb)
1088 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
1089 arrowSize, thumbSize );
1092 break;
1094 case SCROLL_BOTTOM_RECT:
1095 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
1096 thumbPos, infoPtr->flags, vertical,
1097 FALSE, (hittest == SCROLL_trackHitTest) );
1098 if (hittest == SCROLL_trackHitTest)
1100 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1102 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1103 SB_PAGEDOWN, (LPARAM)hwndCtl );
1105 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1106 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1107 (TIMERPROC)0 );
1109 else KillSystemTimer( hwnd, SCROLL_TIMER );
1110 break;
1112 case SCROLL_BOTTOM_ARROW:
1113 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
1114 FALSE, (hittest == SCROLL_trackHitTest) );
1115 if (hittest == SCROLL_trackHitTest)
1117 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1119 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1120 SB_LINEDOWN, (LPARAM)hwndCtl );
1123 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1124 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1125 (TIMERPROC)0 );
1127 else KillSystemTimer( hwnd, SCROLL_TIMER );
1128 break;
1131 if (msg == WM_LBUTTONDOWN)
1134 if (hittest == SCROLL_THUMB)
1136 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1137 trackThumbPos + lastMousePos - lastClickPos );
1138 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1139 MAKEWPARAM( SB_THUMBTRACK, val ), (LPARAM)hwndCtl );
1143 if (msg == WM_LBUTTONUP)
1145 hittest = SCROLL_trackHitTest;
1146 SCROLL_trackHitTest = SCROLL_NOWHERE; /* Terminate tracking */
1148 if (hittest == SCROLL_THUMB)
1150 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1151 trackThumbPos + lastMousePos - lastClickPos );
1152 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1153 MAKEWPARAM( SB_THUMBPOSITION, val ), (LPARAM)hwndCtl );
1155 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1156 SB_ENDSCROLL, (LPARAM)hwndCtl );
1159 ReleaseDC( hwnd, hdc );
1163 /***********************************************************************
1164 * SCROLL_TrackScrollBar
1166 * Track a mouse button press on a scroll-bar.
1167 * pt is in screen-coordinates for non-client scroll bars.
1169 void SCROLL_TrackScrollBar( HWND hwnd, INT scrollbar, POINT pt )
1171 MSG msg;
1172 INT xoffset = 0, yoffset = 0;
1174 if (scrollbar != SB_CTL)
1176 WND *wndPtr = WIN_GetPtr( hwnd );
1177 if (!wndPtr || wndPtr == WND_OTHER_PROCESS) return;
1178 xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
1179 yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
1180 WIN_ReleasePtr( wndPtr );
1181 ScreenToClient( hwnd, &pt );
1182 pt.x += xoffset;
1183 pt.y += yoffset;
1186 SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt );
1190 if (!GetMessageW( &msg, 0, 0, 0 )) break;
1191 if (CallMsgFilterW( &msg, MSGF_SCROLLBAR )) continue;
1192 switch(msg.message)
1194 case WM_LBUTTONUP:
1195 case WM_MOUSEMOVE:
1196 case WM_SYSTIMER:
1197 pt.x = LOWORD(msg.lParam) + xoffset;
1198 pt.y = HIWORD(msg.lParam) + yoffset;
1199 SCROLL_HandleScrollEvent( hwnd, scrollbar, msg.message, pt );
1200 break;
1201 default:
1202 TranslateMessage( &msg );
1203 DispatchMessageW( &msg );
1204 break;
1206 if (!IsWindow( hwnd ))
1208 ReleaseCapture();
1209 break;
1211 } while (msg.message != WM_LBUTTONUP);
1215 /***********************************************************************
1216 * SCROLL_CreateScrollBar
1218 * Create a scroll bar
1220 static void SCROLL_CreateScrollBar(
1221 HWND hwnd /* [in] Handle of window with scrollbar(s) */,
1222 LPCREATESTRUCTW lpCreate /* [in] The style and place of the scroll bar */)
1224 LPSCROLLBAR_INFO info = SCROLL_GetScrollBarInfo(hwnd, SB_CTL);
1225 if (!info) return;
1227 TRACE("hwnd=%p lpCreate=%p\n", hwnd, lpCreate);
1229 if (lpCreate->style & WS_DISABLED)
1231 info->flags = ESB_DISABLE_BOTH;
1232 TRACE("Created WS_DISABLED scrollbar\n");
1235 if (lpCreate->style & SBS_VERT)
1237 if (lpCreate->style & SBS_LEFTALIGN)
1238 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1239 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1240 else if (lpCreate->style & SBS_RIGHTALIGN)
1241 MoveWindow( hwnd,
1242 lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1243 lpCreate->y,
1244 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1246 else /* SBS_HORZ */
1248 if (lpCreate->style & SBS_TOPALIGN)
1249 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1250 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1251 else if (lpCreate->style & SBS_BOTTOMALIGN)
1252 MoveWindow( hwnd,
1253 lpCreate->x,
1254 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1255 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1260 /*************************************************************************
1261 * SCROLL_GetScrollInfo
1263 * Internal helper for the API function
1265 static BOOL SCROLL_GetScrollInfo(
1266 HWND hwnd /* [in] Handle of window with scrollbar(s) */,
1267 INT nBar /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1268 LPSCROLLINFO info /* [in/out] (fMask specifies which values to retrieve) */)
1270 LPSCROLLBAR_INFO infoPtr;
1272 /* handle invalid data structure */
1273 if (!SCROLL_ScrollInfoValid(info)
1274 || !(infoPtr = SCROLL_GetScrollBarInfo(hwnd, nBar)))
1275 return FALSE;
1277 /* fill in the desired scroll info structure */
1278 if (info->fMask & SIF_PAGE) info->nPage = infoPtr->page;
1279 if (info->fMask & SIF_POS) info->nPos = infoPtr->curVal;
1280 if ((info->fMask & SIF_TRACKPOS) && (info->cbSize == sizeof(*info)))
1281 info->nTrackPos = (SCROLL_TrackingWin == WIN_GetFullHandle(hwnd)) ? SCROLL_TrackingVal : infoPtr->curVal;
1282 if (info->fMask & SIF_RANGE)
1284 info->nMin = infoPtr->minVal;
1285 info->nMax = infoPtr->maxVal;
1288 return (info->fMask & SIF_ALL) != 0;
1292 /*************************************************************************
1293 * SCROLL_GetScrollPos
1295 * Internal helper for the API function
1297 static INT SCROLL_GetScrollPos(
1298 HWND hwnd /* [in] Handle of window with scrollbar(s) */,
1299 INT nBar /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */)
1301 LPSCROLLBAR_INFO infoPtr = SCROLL_GetScrollBarInfo(hwnd, nBar);
1302 return infoPtr ? infoPtr->curVal: 0;
1306 /*************************************************************************
1307 * SCROLL_GetScrollRange
1309 * Internal helper for the API function
1311 * RETURNS STD
1313 static BOOL SCROLL_GetScrollRange(
1314 HWND hwnd, /* [in] Handle of window */
1315 INT nBar, /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */
1316 LPINT lpMin, /* [out] Where to store minimum value */
1317 LPINT lpMax /* [out] Where to store maximum value */)
1319 LPSCROLLBAR_INFO infoPtr = SCROLL_GetScrollBarInfo(hwnd, nBar);
1321 if (lpMin) *lpMin = infoPtr ? infoPtr->minVal : 0;
1322 if (lpMax) *lpMax = infoPtr ? infoPtr->maxVal : 0;
1324 return infoPtr ? TRUE : FALSE;
1329 /***********************************************************************
1330 * ScrollBarWndProc
1332 static LRESULT WINAPI ScrollBarWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1334 if (!IsWindow( hwnd )) return 0;
1336 switch(message)
1338 case WM_CREATE:
1339 SCROLL_CreateScrollBar(hwnd, (LPCREATESTRUCTW)lParam);
1340 if (!hUpArrow) SCROLL_LoadBitmaps();
1341 break;
1343 case WM_ENABLE:
1345 SCROLLBAR_INFO *infoPtr;
1346 if ((infoPtr = SCROLL_GetScrollBarInfo( hwnd, SB_CTL )))
1348 infoPtr->flags = wParam ? ESB_ENABLE_BOTH : ESB_DISABLE_BOTH;
1349 SCROLL_RefreshScrollBar(hwnd, SB_CTL, TRUE, TRUE);
1352 return 0;
1354 case WM_LBUTTONDOWN:
1356 POINT pt;
1357 pt.x = SLOWORD(lParam);
1358 pt.y = SHIWORD(lParam);
1359 SCROLL_TrackScrollBar( hwnd, SB_CTL, pt );
1361 break;
1362 case WM_LBUTTONUP:
1363 case WM_MOUSEMOVE:
1364 case WM_SYSTIMER:
1366 POINT pt;
1367 pt.x = SLOWORD(lParam);
1368 pt.y = SHIWORD(lParam);
1369 SCROLL_HandleScrollEvent( hwnd, SB_CTL, message, pt );
1371 break;
1373 case WM_KEYDOWN:
1374 SCROLL_HandleKbdEvent(hwnd, wParam, lParam);
1375 break;
1377 case WM_KEYUP:
1378 ShowCaret(hwnd);
1379 break;
1381 case WM_SETFOCUS:
1383 /* Create a caret when a ScrollBar get focus */
1384 RECT rect;
1385 int arrowSize, thumbSize, thumbPos, vertical;
1386 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,
1387 &arrowSize, &thumbSize, &thumbPos );
1388 if (!vertical)
1390 CreateCaret(hwnd, (HBITMAP)1, thumbSize-2, rect.bottom-rect.top-2);
1391 SetCaretPos(thumbPos+1, rect.top+1);
1393 else
1395 CreateCaret(hwnd, (HBITMAP)1, rect.right-rect.left-2,thumbSize-2);
1396 SetCaretPos(rect.top+1, thumbPos+1);
1398 ShowCaret(hwnd);
1400 break;
1402 case WM_KILLFOCUS:
1404 RECT rect;
1405 int arrowSize, thumbSize, thumbPos, vertical;
1406 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,&arrowSize, &thumbSize, &thumbPos );
1407 if (!vertical){
1408 rect.left=thumbPos+1;
1409 rect.right=rect.left+thumbSize;
1411 else
1413 rect.top=thumbPos+1;
1414 rect.bottom=rect.top+thumbSize;
1416 HideCaret(hwnd);
1417 InvalidateRect(hwnd,&rect,0);
1418 DestroyCaret();
1420 break;
1422 case WM_ERASEBKGND:
1423 return 1;
1425 case WM_GETDLGCODE:
1426 return DLGC_WANTARROWS; /* Windows returns this value */
1428 case WM_PAINT:
1430 PAINTSTRUCT ps;
1431 HDC hdc = BeginPaint( hwnd, &ps );
1432 if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEBOX)
1433 FillRect( hdc, &ps.rcPaint, GetSysColorBrush(COLOR_SCROLLBAR) );
1434 else
1435 SCROLL_DrawScrollBar( hwnd, hdc, SB_CTL, TRUE, TRUE );
1436 EndPaint( hwnd, &ps );
1438 break;
1440 case SBM_SETPOS16:
1441 case SBM_SETPOS:
1442 return SetScrollPos( hwnd, SB_CTL, wParam, (BOOL)lParam );
1444 case SBM_GETPOS16:
1445 case SBM_GETPOS:
1446 return SCROLL_GetScrollPos(hwnd, SB_CTL);
1448 case SBM_SETRANGE16:
1449 SetScrollRange( hwnd, SB_CTL, LOWORD(lParam), HIWORD(lParam),
1450 wParam /* FIXME: Is this correct? */ );
1451 return 0;
1453 case SBM_SETRANGE:
1455 INT oldPos = SCROLL_GetScrollPos( hwnd, SB_CTL );
1456 SetScrollRange( hwnd, SB_CTL, wParam, lParam, FALSE );
1457 if (oldPos != SCROLL_GetScrollPos( hwnd, SB_CTL )) return oldPos;
1459 return 0;
1461 case SBM_GETRANGE16:
1462 FIXME("don't know how to handle SBM_GETRANGE16 (wp=%04x,lp=%08lx)\n", wParam, lParam );
1463 return 0;
1465 case SBM_GETRANGE:
1466 return SCROLL_GetScrollRange(hwnd, SB_CTL, (LPINT)wParam, (LPINT)lParam);
1468 case SBM_ENABLE_ARROWS16:
1469 case SBM_ENABLE_ARROWS:
1470 return EnableScrollBar( hwnd, SB_CTL, wParam );
1472 case SBM_SETRANGEREDRAW:
1474 INT oldPos = SCROLL_GetScrollPos( hwnd, SB_CTL );
1475 SetScrollRange( hwnd, SB_CTL, wParam, lParam, TRUE );
1476 if (oldPos != SCROLL_GetScrollPos( hwnd, SB_CTL )) return oldPos;
1478 return 0;
1480 case SBM_SETSCROLLINFO:
1481 return SetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam, wParam );
1483 case SBM_GETSCROLLINFO:
1484 return SCROLL_GetScrollInfo(hwnd, SB_CTL, (SCROLLINFO *)lParam);
1486 case 0x00e5:
1487 case 0x00e7:
1488 case 0x00e8:
1489 case 0x00eb:
1490 case 0x00ec:
1491 case 0x00ed:
1492 case 0x00ee:
1493 case 0x00ef:
1494 ERR("unknown Win32 msg %04x wp=%08x lp=%08lx\n",
1495 message, wParam, lParam );
1496 break;
1498 default:
1499 if (message >= WM_USER)
1500 WARN("unknown msg %04x wp=%04x lp=%08lx\n",
1501 message, wParam, lParam );
1502 return DefWindowProcW( hwnd, message, wParam, lParam );
1504 return 0;
1508 /*************************************************************************
1509 * SetScrollInfo (USER32.@)
1510 * SetScrollInfo can be used to set the position, upper bound,
1511 * lower bound, and page size of a scrollbar control.
1513 * RETURNS
1514 * Scrollbar position
1516 * NOTE
1517 * For 100 lines of text to be displayed in a window of 25 lines,
1518 * one would for instance use info->nMin=0, info->nMax=75
1519 * (corresponding to the 76 different positions of the window on
1520 * the text), and info->nPage=25.
1522 INT WINAPI SetScrollInfo(
1523 HWND hwnd /* [in] Handle of window whose scrollbar will be affected */,
1524 INT nBar /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1525 const SCROLLINFO *info /* [in] Specifies what to change and new values */,
1526 BOOL bRedraw /* [in] Should scrollbar be redrawn afterwards ? */)
1528 INT action;
1529 INT retVal = SCROLL_SetScrollInfo( hwnd, nBar, info, &action );
1531 if( action & SA_SSI_HIDE )
1532 SCROLL_ShowScrollBar( hwnd, nBar, FALSE, FALSE );
1533 else
1535 if( action & SA_SSI_SHOW )
1536 if( SCROLL_ShowScrollBar( hwnd, nBar, TRUE, TRUE ) )
1537 return retVal; /* SetWindowPos() already did the painting */
1539 if( bRedraw && (action & SA_SSI_REFRESH))
1540 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
1541 else if( action & SA_SSI_REPAINT_ARROWS )
1542 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, FALSE );
1544 return retVal;
1547 INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar,
1548 const SCROLLINFO *info, INT *action )
1550 /* Update the scrollbar state and set action flags according to
1551 * what has to be done graphics wise. */
1553 SCROLLBAR_INFO *infoPtr;
1554 UINT new_flags;
1555 BOOL bChangeParams = FALSE; /* don't show/hide scrollbar if params don't change */
1557 *action = 0;
1559 if (!(infoPtr = SCROLL_GetScrollBarInfo(hwnd, nBar))) return 0;
1560 if (info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)) return 0;
1561 if ((info->cbSize != sizeof(*info)) &&
1562 (info->cbSize != sizeof(*info)-sizeof(info->nTrackPos))) return 0;
1564 if (TRACE_ON(scroll))
1566 TRACE("hwnd=%p bar=%d", hwnd, nBar);
1567 if (info->fMask & SIF_PAGE) TRACE( " page=%d", info->nPage );
1568 if (info->fMask & SIF_POS) TRACE( " pos=%d", info->nPos );
1569 if (info->fMask & SIF_RANGE) TRACE( " min=%d max=%d", info->nMin, info->nMax );
1570 TRACE("\n");
1573 /* Set the page size */
1575 if (info->fMask & SIF_PAGE)
1577 if( infoPtr->page != info->nPage )
1579 infoPtr->page = info->nPage;
1580 *action |= SA_SSI_REFRESH;
1581 bChangeParams = TRUE;
1585 /* Set the scroll pos */
1587 if (info->fMask & SIF_POS)
1589 if( infoPtr->curVal != info->nPos )
1591 infoPtr->curVal = info->nPos;
1592 *action |= SA_SSI_REFRESH;
1596 /* Set the scroll range */
1598 if (info->fMask & SIF_RANGE)
1600 /* Invalid range -> range is set to (0,0) */
1601 if ((info->nMin > info->nMax) ||
1602 ((UINT)(info->nMax - info->nMin) >= 0x80000000))
1604 infoPtr->minVal = 0;
1605 infoPtr->maxVal = 0;
1606 bChangeParams = TRUE;
1608 else
1610 if( infoPtr->minVal != info->nMin ||
1611 infoPtr->maxVal != info->nMax )
1613 *action |= SA_SSI_REFRESH;
1614 infoPtr->minVal = info->nMin;
1615 infoPtr->maxVal = info->nMax;
1616 bChangeParams = TRUE;
1621 /* Make sure the page size is valid */
1623 if (infoPtr->page < 0) infoPtr->page = 0;
1624 else if (infoPtr->page > infoPtr->maxVal - infoPtr->minVal + 1 )
1625 infoPtr->page = infoPtr->maxVal - infoPtr->minVal + 1;
1627 /* Make sure the pos is inside the range */
1629 if (infoPtr->curVal < infoPtr->minVal)
1630 infoPtr->curVal = infoPtr->minVal;
1631 else if (infoPtr->curVal > infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1632 infoPtr->curVal = infoPtr->maxVal - max( infoPtr->page-1, 0 );
1634 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1635 infoPtr->page, infoPtr->curVal,
1636 infoPtr->minVal, infoPtr->maxVal );
1638 /* don't change the scrollbar state if SetScrollInfo
1639 * is just called with SIF_DISABLENOSCROLL
1641 if(!(info->fMask & SIF_ALL)) goto done;
1643 /* Check if the scrollbar should be hidden or disabled */
1645 if (info->fMask & (SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL))
1647 new_flags = infoPtr->flags;
1648 if (infoPtr->minVal >= infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1650 /* Hide or disable scroll-bar */
1651 if (info->fMask & SIF_DISABLENOSCROLL)
1653 new_flags = ESB_DISABLE_BOTH;
1654 *action |= SA_SSI_REFRESH;
1656 else if ((nBar != SB_CTL) && bChangeParams)
1658 *action = SA_SSI_HIDE;
1659 goto done;
1662 else /* Show and enable scroll-bar */
1664 new_flags = 0;
1665 if ((nBar != SB_CTL) && bChangeParams)
1666 *action |= SA_SSI_SHOW;
1669 if (infoPtr->flags != new_flags) /* check arrow flags */
1671 infoPtr->flags = new_flags;
1672 *action |= SA_SSI_REPAINT_ARROWS;
1676 done:
1677 /* Return current position */
1679 return infoPtr->curVal;
1683 /*************************************************************************
1684 * GetScrollInfo (USER32.@)
1686 * GetScrollInfo can be used to retrieve the position, upper bound,
1687 * lower bound, and page size of a scrollbar control.
1689 * RETURNS STD
1691 BOOL WINAPI GetScrollInfo(
1692 HWND hwnd /* [in] Handle of window with scrollbar(s) */,
1693 INT nBar /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1694 LPSCROLLINFO info /* [in/out] (fMask specifies which values to retrieve) */)
1696 TRACE("hwnd=%p nBar=%d info=%p\n", hwnd, nBar, info);
1698 /* Refer SB_CTL requests to the window */
1699 if (nBar == SB_CTL)
1700 return SendMessageA(hwnd, SBM_GETSCROLLINFO, (WPARAM)0, (LPARAM)info);
1701 else
1702 return SCROLL_GetScrollInfo(hwnd, nBar, info);
1706 /*************************************************************************
1707 * SetScrollPos (USER32.@)
1709 * RETURNS
1710 * Success: Scrollbar position
1711 * Failure: 0
1713 * REMARKS
1714 * Note the ambiguity when 0 is returned. Use GetLastError
1715 * to make sure there was an error (and to know which one).
1717 INT WINAPI SetScrollPos(
1718 HWND hwnd /* [in] Handle of window whose scrollbar will be affected */,
1719 INT nBar /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1720 INT nPos /* [in] New value */,
1721 BOOL bRedraw /* [in] Should scrollbar be redrawn afterwards ? */ )
1723 SCROLLINFO info;
1724 SCROLLBAR_INFO *infoPtr;
1725 INT oldPos;
1727 if (!(infoPtr = SCROLL_GetScrollBarInfo( hwnd, nBar ))) return 0;
1728 oldPos = infoPtr->curVal;
1729 info.cbSize = sizeof(info);
1730 info.nPos = nPos;
1731 info.fMask = SIF_POS;
1732 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1733 return oldPos;
1737 /*************************************************************************
1738 * GetScrollPos (USER32.@)
1740 * RETURNS
1741 * Success: Current position
1742 * Failure: 0
1744 * REMARKS
1745 * There is ambiguity when 0 is returned. Use GetLastError
1746 * to make sure there was an error (and to know which one).
1748 INT WINAPI GetScrollPos(
1749 HWND hwnd /* [in] Handle of window with scrollbar(s) */,
1750 INT nBar /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */)
1752 TRACE("hwnd=%p nBar=%d\n", hwnd, nBar);
1754 /* Refer SB_CTL requests to the window */
1755 if (nBar == SB_CTL)
1756 return SendMessageA(hwnd, SBM_GETPOS, (WPARAM)0, (LPARAM)0);
1757 else
1758 return SCROLL_GetScrollPos(hwnd, nBar);
1762 /*************************************************************************
1763 * SetScrollRange (USER32.@)
1765 * RETURNS STD
1767 BOOL WINAPI SetScrollRange(
1768 HWND hwnd, /* [in] Handle of window whose scrollbar will be affected */
1769 INT nBar, /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */
1770 INT minVal, /* [in] New minimum value */
1771 INT maxVal, /* [in] New maximum value */
1772 BOOL bRedraw /* [in] Should scrollbar be redrawn afterwards ? */)
1774 SCROLLINFO info;
1776 info.cbSize = sizeof(info);
1777 info.nMin = minVal;
1778 info.nMax = maxVal;
1779 info.fMask = SIF_RANGE;
1780 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1781 return TRUE;
1785 /*************************************************************************
1786 * SCROLL_SetNCSbState
1788 * Updates both scrollbars at the same time. Used by MDI CalcChildScroll().
1790 INT SCROLL_SetNCSbState(HWND hwnd, int vMin, int vMax, int vPos,
1791 int hMin, int hMax, int hPos)
1793 INT vA, hA;
1794 SCROLLINFO vInfo, hInfo;
1796 vInfo.cbSize = hInfo.cbSize = sizeof(SCROLLINFO);
1797 vInfo.nMin = vMin;
1798 vInfo.nMax = vMax;
1799 vInfo.nPos = vPos;
1800 hInfo.nMin = hMin;
1801 hInfo.nMax = hMax;
1802 hInfo.nPos = hPos;
1803 vInfo.fMask = hInfo.fMask = SIF_RANGE | SIF_POS;
1805 SCROLL_SetScrollInfo( hwnd, SB_VERT, &vInfo, &vA );
1806 SCROLL_SetScrollInfo( hwnd, SB_HORZ, &hInfo, &hA );
1808 if( !SCROLL_ShowScrollBar( hwnd, SB_BOTH,
1809 (hA & SA_SSI_SHOW),(vA & SA_SSI_SHOW) ) )
1811 /* SetWindowPos() wasn't called, just redraw the scrollbars if needed */
1812 if( vA & SA_SSI_REFRESH )
1813 SCROLL_RefreshScrollBar( hwnd, SB_VERT, FALSE, TRUE );
1815 if( hA & SA_SSI_REFRESH )
1816 SCROLL_RefreshScrollBar( hwnd, SB_HORZ, FALSE, TRUE );
1818 return 0;
1822 /*************************************************************************
1823 * GetScrollRange (USER32.@)
1825 * RETURNS STD
1827 BOOL WINAPI GetScrollRange(
1828 HWND hwnd /* [in] Handle of window with scrollbar(s) */,
1829 INT nBar /* [in] One of SB_HORZ, SB_VERT, or SB_CTL */,
1830 LPINT lpMin /* [out] Where to store minimum value */,
1831 LPINT lpMax /* [out] Where to store maximum value */)
1833 TRACE("hwnd=%p nBar=%d lpMin=%p lpMax=%p\n", hwnd, nBar, lpMin, lpMax);
1835 /* Refer SB_CTL requests to the window */
1836 if (nBar == SB_CTL)
1837 return SendMessageA(hwnd, SBM_GETRANGE, (WPARAM)lpMin, (LPARAM)lpMax);
1838 else
1839 return SCROLL_GetScrollRange(hwnd, nBar, lpMin, lpMax);
1843 /*************************************************************************
1844 * SCROLL_ShowScrollBar()
1846 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1848 BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar,
1849 BOOL fShowH, BOOL fShowV )
1851 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
1853 TRACE("hwnd=%p bar=%d horz=%d, vert=%d\n", hwnd, nBar, fShowH, fShowV );
1855 switch(nBar)
1857 case SB_CTL:
1858 ShowWindow( hwnd, fShowH ? SW_SHOW : SW_HIDE );
1859 return TRUE;
1861 case SB_BOTH:
1862 case SB_HORZ:
1863 if (fShowH)
1865 fShowH = !(style & WS_HSCROLL);
1866 style |= WS_HSCROLL;
1868 else /* hide it */
1870 fShowH = (style & WS_HSCROLL);
1871 style &= ~WS_HSCROLL;
1873 if( nBar == SB_HORZ ) {
1874 fShowV = FALSE;
1875 break;
1877 /* fall through */
1879 case SB_VERT:
1880 if (fShowV)
1882 fShowV = !(style & WS_VSCROLL);
1883 style |= WS_VSCROLL;
1885 else /* hide it */
1887 fShowV = (style & WS_VSCROLL);
1888 style &= ~WS_VSCROLL;
1890 if ( nBar == SB_VERT )
1891 fShowH = FALSE;
1892 break;
1894 default:
1895 return FALSE; /* Nothing to do! */
1898 if( fShowH || fShowV ) /* frame has been changed, let the window redraw itself */
1900 WIN_SetStyle( hwnd, style );
1901 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
1902 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
1903 return TRUE;
1905 return FALSE; /* no frame changes */
1909 /*************************************************************************
1910 * ShowScrollBar (USER32.@)
1912 * RETURNS STD
1914 BOOL WINAPI ShowScrollBar(
1915 HWND hwnd, /* [in] Handle of window whose scrollbar(s) will be affected */
1916 INT nBar, /* [in] One of SB_HORZ, SB_VERT, SB_BOTH or SB_CTL */
1917 BOOL fShow /* [in] TRUE = show, FALSE = hide */)
1919 SCROLL_ShowScrollBar( hwnd, nBar, (nBar == SB_VERT) ? 0 : fShow,
1920 (nBar == SB_HORZ) ? 0 : fShow );
1921 return TRUE;
1925 /*************************************************************************
1926 * EnableScrollBar (USER32.@)
1928 BOOL WINAPI EnableScrollBar( HWND hwnd, INT nBar, UINT flags )
1930 BOOL bFineWithMe;
1931 SCROLLBAR_INFO *infoPtr;
1933 TRACE("%p %d %d\n", hwnd, nBar, flags );
1935 flags &= ESB_DISABLE_BOTH;
1937 if (nBar == SB_BOTH)
1939 if (!(infoPtr = SCROLL_GetScrollBarInfo( hwnd, SB_VERT ))) return FALSE;
1940 if (!(bFineWithMe = (infoPtr->flags == flags)) )
1942 infoPtr->flags = flags;
1943 SCROLL_RefreshScrollBar( hwnd, SB_VERT, TRUE, TRUE );
1945 nBar = SB_HORZ;
1947 else
1948 bFineWithMe = TRUE;
1950 if (!(infoPtr = SCROLL_GetScrollBarInfo( hwnd, nBar ))) return FALSE;
1951 if (bFineWithMe && infoPtr->flags == flags) return FALSE;
1952 infoPtr->flags = flags;
1954 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
1955 return TRUE;