Added exception handling wrapper to a number of server requests.
[wine.git] / controls / scroll.c
blob1a6f68afecfa2917449b2bb2315170865d3b3c74
1 /*
2 * Scrollbar control
4 * Copyright 1993 Martin Ayotte
5 * Copyright 1994, 1996 Alexandre Julliard
6 */
8 #include "windef.h"
9 #include "wingdi.h"
10 #include "wine/winuser16.h"
11 #include "scroll.h"
12 #include "heap.h"
13 #include "win.h"
14 #include "debugtools.h"
15 #include "cache.h"
16 #include "tweak.h"
18 DEFAULT_DEBUG_CHANNEL(scroll)
21 static HBITMAP hUpArrow = 0;
22 static HBITMAP hDnArrow = 0;
23 static HBITMAP hLfArrow = 0;
24 static HBITMAP hRgArrow = 0;
25 static HBITMAP hUpArrowD = 0;
26 static HBITMAP hDnArrowD = 0;
27 static HBITMAP hLfArrowD = 0;
28 static HBITMAP hRgArrowD = 0;
29 static HBITMAP hUpArrowI = 0;
30 static HBITMAP hDnArrowI = 0;
31 static HBITMAP hLfArrowI = 0;
32 static HBITMAP hRgArrowI = 0;
34 #define TOP_ARROW(flags,pressed) \
35 (((flags)&ESB_DISABLE_UP) ? hUpArrowI : ((pressed) ? hUpArrowD:hUpArrow))
36 #define BOTTOM_ARROW(flags,pressed) \
37 (((flags)&ESB_DISABLE_DOWN) ? hDnArrowI : ((pressed) ? hDnArrowD:hDnArrow))
38 #define LEFT_ARROW(flags,pressed) \
39 (((flags)&ESB_DISABLE_LEFT) ? hLfArrowI : ((pressed) ? hLfArrowD:hLfArrow))
40 #define RIGHT_ARROW(flags,pressed) \
41 (((flags)&ESB_DISABLE_RIGHT) ? hRgArrowI : ((pressed) ? hRgArrowD:hRgArrow))
44 /* Minimum size of the rectangle between the arrows */
45 #define SCROLL_MIN_RECT 4
47 /* Minimum size of the thumb in pixels */
48 #define SCROLL_MIN_THUMB 6
50 /* Overlap between arrows and thumb */
51 #define SCROLL_ARROW_THUMB_OVERLAP ((TWEAK_WineLook == WIN31_LOOK) ? 1 : 0)
53 /* Delay (in ms) before first repetition when holding the button down */
54 #define SCROLL_FIRST_DELAY 200
56 /* Delay (in ms) between scroll repetitions */
57 #define SCROLL_REPEAT_DELAY 50
59 /* Scroll timer id */
60 #define SCROLL_TIMER 0
62 /* Scroll-bar hit testing */
63 enum SCROLL_HITTEST
65 SCROLL_NOWHERE, /* Outside the scroll bar */
66 SCROLL_TOP_ARROW, /* Top or left arrow */
67 SCROLL_TOP_RECT, /* Rectangle between the top arrow and the thumb */
68 SCROLL_THUMB, /* Thumb rectangle */
69 SCROLL_BOTTOM_RECT, /* Rectangle between the thumb and the bottom arrow */
70 SCROLL_BOTTOM_ARROW /* Bottom or right arrow */
73 /* What to do after SCROLL_SetScrollInfo() */
74 #define SA_SSI_HIDE 0x0001
75 #define SA_SSI_SHOW 0x0002
76 #define SA_SSI_REFRESH 0x0004
77 #define SA_SSI_REPAINT_ARROWS 0x0008
79 /* Thumb-tracking info */
80 static HWND SCROLL_TrackingWin = 0;
81 static INT SCROLL_TrackingBar = 0;
82 static INT SCROLL_TrackingPos = 0;
83 static INT SCROLL_TrackingVal = 0;
84 /* Hit test code of the last button-down event */
85 static enum SCROLL_HITTEST SCROLL_trackHitTest;
86 static BOOL SCROLL_trackVertical;
88 /* Is the moving thumb being displayed? */
89 static BOOL SCROLL_MovingThumb = FALSE;
91 /* Local functions */
92 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar,
93 BOOL fShowH, BOOL fShowV );
94 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar,
95 const SCROLLINFO *info, INT *action );
96 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
97 RECT *rect, INT arrowSize,
98 INT thumbSize, INT thumbPos,
99 UINT flags, BOOL vertical,
100 BOOL top_selected, BOOL bottom_selected );
103 /***********************************************************************
104 * SCROLL_LoadBitmaps
106 static void SCROLL_LoadBitmaps(void)
108 hUpArrow = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROW) );
109 hDnArrow = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROW) );
110 hLfArrow = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROW) );
111 hRgArrow = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROW) );
112 hUpArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROWD) );
113 hDnArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROWD) );
114 hLfArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROWD) );
115 hRgArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROWD) );
116 hUpArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROWI) );
117 hDnArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROWI) );
118 hLfArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROWI) );
119 hRgArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROWI) );
123 /***********************************************************************
124 * SCROLL_GetPtrScrollInfo
126 static SCROLLBAR_INFO *SCROLL_GetPtrScrollInfo( WND* wndPtr, INT nBar )
128 SCROLLBAR_INFO *infoPtr;
130 if (!wndPtr) return NULL;
131 switch(nBar)
133 case SB_HORZ: infoPtr = (SCROLLBAR_INFO *)wndPtr->pHScroll; break;
134 case SB_VERT: infoPtr = (SCROLLBAR_INFO *)wndPtr->pVScroll; break;
135 case SB_CTL: infoPtr = (SCROLLBAR_INFO *)wndPtr->wExtra; break;
136 default: return NULL;
139 if (!infoPtr) /* Create the info structure if needed */
141 if ((infoPtr = HeapAlloc( SystemHeap, 0, sizeof(SCROLLBAR_INFO) )))
143 infoPtr->MinVal = infoPtr->CurVal = infoPtr->Page = 0;
144 infoPtr->MaxVal = 100;
145 infoPtr->flags = ESB_ENABLE_BOTH;
146 if (nBar == SB_HORZ) wndPtr->pHScroll = infoPtr;
147 else wndPtr->pVScroll = infoPtr;
149 if (!hUpArrow) SCROLL_LoadBitmaps();
151 return infoPtr;
155 /***********************************************************************
156 * SCROLL_GetScrollInfo
158 static SCROLLBAR_INFO *SCROLL_GetScrollInfo( HWND hwnd, INT nBar )
160 SCROLLBAR_INFO *retvalue;
161 WND *wndPtr = WIN_FindWndPtr( hwnd );
162 retvalue = SCROLL_GetPtrScrollInfo( wndPtr, nBar );
163 WIN_ReleaseWndPtr(wndPtr);
164 return retvalue;
168 /***********************************************************************
169 * SCROLL_GetScrollBarRect
171 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
172 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
173 * 'arrowSize' returns the width or height of an arrow (depending on
174 * the orientation of the scrollbar), 'thumbSize' returns the size of
175 * the thumb, and 'thumbPos' returns the position of the thumb
176 * relative to the left or to the top.
177 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
179 static BOOL SCROLL_GetScrollBarRect( HWND hwnd, INT nBar, RECT *lprect,
180 INT *arrowSize, INT *thumbSize,
181 INT *thumbPos )
183 INT pixels;
184 BOOL vertical;
185 WND *wndPtr = WIN_FindWndPtr( hwnd );
187 switch(nBar)
189 case SB_HORZ:
190 lprect->left = wndPtr->rectClient.left - wndPtr->rectWindow.left;
191 lprect->top = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
192 lprect->right = wndPtr->rectClient.right - wndPtr->rectWindow.left;
193 lprect->bottom = lprect->top + GetSystemMetrics(SM_CYHSCROLL);
194 if(wndPtr->dwStyle & WS_BORDER) {
195 lprect->left--;
196 lprect->right++;
197 } else if(wndPtr->dwStyle & WS_VSCROLL)
198 lprect->right++;
199 vertical = FALSE;
200 break;
202 case SB_VERT:
203 lprect->left = wndPtr->rectClient.right - wndPtr->rectWindow.left;
204 lprect->top = wndPtr->rectClient.top - wndPtr->rectWindow.top;
205 lprect->right = lprect->left + GetSystemMetrics(SM_CXVSCROLL);
206 lprect->bottom = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
207 if(wndPtr->dwStyle & WS_BORDER) {
208 lprect->top--;
209 lprect->bottom++;
210 } else if(wndPtr->dwStyle & WS_HSCROLL)
211 lprect->bottom++;
212 vertical = TRUE;
213 break;
215 case SB_CTL:
216 GetClientRect( hwnd, lprect );
217 vertical = ((wndPtr->dwStyle & SBS_VERT) != 0);
218 break;
220 default:
221 WIN_ReleaseWndPtr(wndPtr);
222 return FALSE;
225 if (vertical) pixels = lprect->bottom - lprect->top;
226 else pixels = lprect->right - lprect->left;
228 if (pixels <= 2*GetSystemMetrics(SM_CXVSCROLL) + SCROLL_MIN_RECT)
230 if (pixels > SCROLL_MIN_RECT)
231 *arrowSize = (pixels - SCROLL_MIN_RECT) / 2;
232 else
233 *arrowSize = 0;
234 *thumbPos = *thumbSize = 0;
236 else
238 SCROLLBAR_INFO *info = SCROLL_GetPtrScrollInfo( wndPtr, nBar );
240 *arrowSize = GetSystemMetrics(SM_CXVSCROLL);
241 pixels -= (2 * (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP));
243 if (info->Page)
245 *thumbSize = pixels * info->Page / (info->MaxVal-info->MinVal+1);
246 if (*thumbSize < SCROLL_MIN_THUMB) *thumbSize = SCROLL_MIN_THUMB;
248 else *thumbSize = GetSystemMetrics(SM_CXVSCROLL);
250 if (((pixels -= *thumbSize ) < 0) ||
251 ((info->flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH))
253 /* Rectangle too small or scrollbar disabled -> no thumb */
254 *thumbPos = *thumbSize = 0;
256 else
258 INT max = info->MaxVal - max( info->Page-1, 0 );
259 if (info->MinVal >= max)
260 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
261 else
262 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP
263 + pixels * (info->CurVal-info->MinVal) / (max - info->MinVal);
266 WIN_ReleaseWndPtr(wndPtr);
267 return vertical;
271 /***********************************************************************
272 * SCROLL_GetThumbVal
274 * Compute the current scroll position based on the thumb position in pixels
275 * from the top of the scroll-bar.
277 static UINT SCROLL_GetThumbVal( SCROLLBAR_INFO *infoPtr, RECT *rect,
278 BOOL vertical, INT pos )
280 INT thumbSize;
281 INT pixels = vertical ? rect->bottom-rect->top : rect->right-rect->left;
283 if ((pixels -= 2*(GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP)) <= 0)
284 return infoPtr->MinVal;
286 if (infoPtr->Page)
288 thumbSize = pixels * infoPtr->Page/(infoPtr->MaxVal-infoPtr->MinVal+1);
289 if (thumbSize < SCROLL_MIN_THUMB) thumbSize = SCROLL_MIN_THUMB;
291 else thumbSize = GetSystemMetrics(SM_CXVSCROLL);
293 if ((pixels -= thumbSize) <= 0) return infoPtr->MinVal;
295 pos = max( 0, pos - (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP) );
296 if (pos > pixels) pos = pixels;
298 if (!infoPtr->Page) pos *= infoPtr->MaxVal - infoPtr->MinVal;
299 else pos *= infoPtr->MaxVal - infoPtr->MinVal - infoPtr->Page + 1;
300 return infoPtr->MinVal + ((pos + pixels / 2) / pixels);
303 /***********************************************************************
304 * SCROLL_PtInRectEx
306 static BOOL SCROLL_PtInRectEx( LPRECT lpRect, POINT pt, BOOL vertical )
308 RECT rect = *lpRect;
310 if (vertical)
312 rect.left -= lpRect->right - lpRect->left;
313 rect.right += lpRect->right - lpRect->left;
315 else
317 rect.top -= lpRect->bottom - lpRect->top;
318 rect.bottom += lpRect->bottom - lpRect->top;
320 return PtInRect( &rect, pt );
323 /***********************************************************************
324 * SCROLL_ClipPos
326 static POINT SCROLL_ClipPos( LPRECT lpRect, POINT pt )
328 if( pt.x < lpRect->left )
329 pt.x = lpRect->left;
330 else
331 if( pt.x > lpRect->right )
332 pt.x = lpRect->right;
334 if( pt.y < lpRect->top )
335 pt.y = lpRect->top;
336 else
337 if( pt.y > lpRect->bottom )
338 pt.y = lpRect->bottom;
340 return pt;
344 /***********************************************************************
345 * SCROLL_HitTest
347 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
349 static enum SCROLL_HITTEST SCROLL_HitTest( HWND hwnd, INT nBar,
350 POINT pt, BOOL bDragging )
352 INT arrowSize, thumbSize, thumbPos;
353 RECT rect;
355 BOOL vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
356 &arrowSize, &thumbSize, &thumbPos );
358 if ( (bDragging && !SCROLL_PtInRectEx( &rect, pt, vertical )) ||
359 (!PtInRect( &rect, pt )) ) return SCROLL_NOWHERE;
361 if (vertical)
363 if (pt.y < rect.top + arrowSize) return SCROLL_TOP_ARROW;
364 if (pt.y >= rect.bottom - arrowSize) return SCROLL_BOTTOM_ARROW;
365 if (!thumbPos) return SCROLL_TOP_RECT;
366 pt.y -= rect.top;
367 if (pt.y < thumbPos) return SCROLL_TOP_RECT;
368 if (pt.y >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
370 else /* horizontal */
372 if (pt.x < rect.left + arrowSize) return SCROLL_TOP_ARROW;
373 if (pt.x >= rect.right - arrowSize) return SCROLL_BOTTOM_ARROW;
374 if (!thumbPos) return SCROLL_TOP_RECT;
375 pt.x -= rect.left;
376 if (pt.x < thumbPos) return SCROLL_TOP_RECT;
377 if (pt.x >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
379 return SCROLL_THUMB;
383 /***********************************************************************
384 * SCROLL_DrawArrows
386 * Draw the scroll bar arrows.
388 static void SCROLL_DrawArrows_9x( HDC hdc, SCROLLBAR_INFO *infoPtr,
389 RECT *rect, INT arrowSize, BOOL vertical,
390 BOOL top_pressed, BOOL bottom_pressed )
392 RECT r;
394 r = *rect;
395 if( vertical )
396 r.bottom = r.top + arrowSize;
397 else
398 r.right = r.left + arrowSize;
400 DrawFrameControl( hdc, &r, DFC_SCROLL,
401 (vertical ? DFCS_SCROLLUP : DFCS_SCROLLLEFT)
402 | (top_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
403 | (infoPtr->flags&ESB_DISABLE_LTUP ? DFCS_INACTIVE : 0 ) );
405 r = *rect;
406 if( vertical )
407 r.top = r.bottom-arrowSize;
408 else
409 r.left = r.right-arrowSize;
411 DrawFrameControl( hdc, &r, DFC_SCROLL,
412 (vertical ? DFCS_SCROLLDOWN : DFCS_SCROLLRIGHT)
413 | (bottom_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
414 | (infoPtr->flags&ESB_DISABLE_RTDN ? DFCS_INACTIVE : 0) );
417 static void SCROLL_DrawArrows_31( HDC hdc, SCROLLBAR_INFO *infoPtr,
418 RECT *rect, INT arrowSize, BOOL vertical,
419 BOOL top_pressed, BOOL bottom_pressed )
421 HDC hdcMem = CreateCompatibleDC( hdc );
422 HBITMAP hbmpPrev = SelectObject( hdcMem, vertical ?
423 TOP_ARROW(infoPtr->flags, top_pressed)
424 : LEFT_ARROW(infoPtr->flags, top_pressed));
426 SetStretchBltMode( hdc, STRETCH_DELETESCANS );
427 StretchBlt( hdc, rect->left, rect->top,
428 vertical ? rect->right-rect->left : arrowSize,
429 vertical ? arrowSize : rect->bottom-rect->top,
430 hdcMem, 0, 0,
431 GetSystemMetrics(SM_CXVSCROLL),GetSystemMetrics(SM_CYHSCROLL),
432 SRCCOPY );
434 SelectObject( hdcMem, vertical ?
435 BOTTOM_ARROW( infoPtr->flags, bottom_pressed )
436 : RIGHT_ARROW( infoPtr->flags, bottom_pressed ) );
437 if (vertical)
438 StretchBlt( hdc, rect->left, rect->bottom - arrowSize,
439 rect->right - rect->left, arrowSize,
440 hdcMem, 0, 0,
441 GetSystemMetrics(SM_CXVSCROLL),GetSystemMetrics(SM_CYHSCROLL),
442 SRCCOPY );
443 else
444 StretchBlt( hdc, rect->right - arrowSize, rect->top,
445 arrowSize, rect->bottom - rect->top,
446 hdcMem, 0, 0,
447 GetSystemMetrics(SM_CXVSCROLL), GetSystemMetrics(SM_CYHSCROLL),
448 SRCCOPY );
449 SelectObject( hdcMem, hbmpPrev );
450 DeleteDC( hdcMem );
453 static void SCROLL_DrawArrows( HDC hdc, SCROLLBAR_INFO *infoPtr,
454 RECT *rect, INT arrowSize, BOOL vertical,
455 BOOL top_pressed, BOOL bottom_pressed )
457 if( TWEAK_WineLook == WIN31_LOOK )
458 SCROLL_DrawArrows_31( hdc, infoPtr, rect, arrowSize,
459 vertical, top_pressed,bottom_pressed );
460 else
461 SCROLL_DrawArrows_9x( hdc, infoPtr, rect, arrowSize,
462 vertical, top_pressed,bottom_pressed );
466 /***********************************************************************
467 * SCROLL_DrawMovingThumb
469 * Draw the moving thumb rectangle.
471 static void SCROLL_DrawMovingThumb_31( HDC hdc, RECT *rect, BOOL vertical,
472 INT arrowSize, INT thumbSize )
474 RECT r = *rect;
475 if (vertical)
477 r.top += SCROLL_TrackingPos;
478 if (r.top < rect->top + arrowSize - SCROLL_ARROW_THUMB_OVERLAP)
479 r.top = rect->top + arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
480 if (r.top + thumbSize >
481 rect->bottom - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP))
482 r.top = rect->bottom - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP)
483 - thumbSize;
484 r.bottom = r.top + thumbSize;
486 else
488 r.left += SCROLL_TrackingPos;
489 if (r.left < rect->left + arrowSize - SCROLL_ARROW_THUMB_OVERLAP)
490 r.left = rect->left + arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
491 if (r.left + thumbSize >
492 rect->right - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP))
493 r.left = rect->right - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP)
494 - thumbSize;
495 r.right = r.left + thumbSize;
498 DrawFocusRect( hdc, &r );
499 SCROLL_MovingThumb = !SCROLL_MovingThumb;
502 static void SCROLL_DrawMovingThumb_9x( HDC hdc, RECT *rect, BOOL vertical,
503 INT arrowSize, INT thumbSize )
505 INT pos = SCROLL_TrackingPos;
506 INT max_size;
508 if( vertical )
509 max_size = rect->bottom - rect->top;
510 else
511 max_size = rect->right - rect->left;
513 max_size -= (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) + thumbSize;
515 if( pos < (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) )
516 pos = (arrowSize-SCROLL_ARROW_THUMB_OVERLAP);
517 else if( pos > max_size )
518 pos = max_size;
520 SCROLL_DrawInterior_9x( SCROLL_TrackingWin, hdc, SCROLL_TrackingBar,
521 rect, arrowSize, thumbSize, pos,
522 0, vertical, FALSE, FALSE );
524 SCROLL_MovingThumb = !SCROLL_MovingThumb;
527 static void SCROLL_DrawMovingThumb( HDC hdc, RECT *rect, BOOL vertical,
528 INT arrowSize, INT thumbSize )
530 if( TWEAK_WineLook == WIN31_LOOK )
531 SCROLL_DrawMovingThumb_31( hdc, rect, vertical, arrowSize, thumbSize );
532 else
533 SCROLL_DrawMovingThumb_9x( hdc, rect, vertical, arrowSize, thumbSize );
536 /***********************************************************************
537 * SCROLL_DrawInterior
539 * Draw the scroll bar interior (everything except the arrows).
541 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
542 RECT *rect, INT arrowSize,
543 INT thumbSize, INT thumbPos,
544 UINT flags, BOOL vertical,
545 BOOL top_selected, BOOL bottom_selected )
547 RECT r;
548 HPEN hSavePen;
549 HBRUSH hSaveBrush,hBrush;
551 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
552 * The window-owned scrollbars need to call DEFWND_ControlColor
553 * to correctly setup default scrollbar colors
555 if (nBar == SB_CTL)
557 hBrush = (HBRUSH)SendMessageA( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
558 (WPARAM)hdc,(LPARAM)hwnd);
560 else
562 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
565 hSavePen = SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
566 hSaveBrush = SelectObject( hdc, hBrush );
568 /* Calculate the scroll rectangle */
569 r = *rect;
570 if (vertical)
572 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
573 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
575 else
577 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
578 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
581 /* Draw the scroll rectangles and thumb */
582 if (!thumbPos) /* No thumb to draw */
584 PatBlt( hdc, r.left, r.top,
585 r.right - r.left, r.bottom - r.top,
586 PATCOPY );
588 /* cleanup and return */
589 SelectObject( hdc, hSavePen );
590 SelectObject( hdc, hSaveBrush );
591 return;
594 if (vertical)
596 PatBlt( hdc, r.left, r.top,
597 r.right - r.left,
598 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
599 top_selected ? 0x0f0000 : PATCOPY );
600 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
601 PatBlt( hdc, r.left, r.top + thumbSize,
602 r.right - r.left,
603 r.bottom - r.top - thumbSize,
604 bottom_selected ? 0x0f0000 : PATCOPY );
605 r.bottom = r.top + thumbSize;
607 else /* horizontal */
609 PatBlt( hdc, r.left, r.top,
610 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
611 r.bottom - r.top,
612 top_selected ? 0x0f0000 : PATCOPY );
613 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
614 PatBlt( hdc, r.left + thumbSize, r.top,
615 r.right - r.left - thumbSize,
616 r.bottom - r.top,
617 bottom_selected ? 0x0f0000 : PATCOPY );
618 r.right = r.left + thumbSize;
621 /* Draw the thumb */
622 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT | BF_MIDDLE );
624 /* cleanup */
625 SelectObject( hdc, hSavePen );
626 SelectObject( hdc, hSaveBrush );
630 static void SCROLL_DrawInterior( HWND hwnd, HDC hdc, INT nBar,
631 RECT *rect, INT arrowSize,
632 INT thumbSize, INT thumbPos,
633 UINT flags, BOOL vertical,
634 BOOL top_selected, BOOL bottom_selected )
636 RECT r;
637 HPEN hSavePen;
638 HBRUSH hSaveBrush,hBrush;
639 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
641 if (Save_SCROLL_MovingThumb &&
642 (SCROLL_TrackingWin == hwnd) &&
643 (SCROLL_TrackingBar == nBar))
644 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
646 /* Select the correct brush and pen */
648 if (TWEAK_WineLook == WIN31_LOOK && (flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH)
650 /* This ought to be the color of the parent window */
651 if (TWEAK_WineLook == WIN31_LOOK) {
652 hBrush = GetSysColorBrush(COLOR_WINDOW);
653 } else {
654 /* Under Win9x look & feel, scrollbars don't have a solid border.
655 * To make scrollbar's background different from the window
656 * background, we need to apply a gray 0x55aa pattern brush.
657 * Otherwise it won't look good.
659 hBrush = CACHE_GetPattern55AABrush();
662 else
664 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
665 * The window-owned scrollbars need to call DEFWND_ControlColor
666 * to correctly setup default scrollbar colors
668 if (nBar == SB_CTL) {
669 hBrush = (HBRUSH)SendMessageA( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
670 (WPARAM)hdc,(LPARAM)hwnd);
671 } else {
672 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
675 hSavePen = SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
676 hSaveBrush = SelectObject( hdc, hBrush );
678 /* Calculate the scroll rectangle */
680 r = *rect;
681 if (vertical)
683 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
684 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
686 else
688 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
689 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
692 /* Draw the scroll bar frame */
694 /* Only draw outline if Win 3.1. Mar 24, 1999 - Ronald B. Cemer */
695 if (TWEAK_WineLook == WIN31_LOOK)
696 Rectangle( hdc, r.left, r.top, r.right, r.bottom );
698 /* Draw the scroll rectangles and thumb */
700 if (!thumbPos) /* No thumb to draw */
702 INT offset = (TWEAK_WineLook > WIN31_LOOK) ? 0 : 1;
704 PatBlt( hdc, r.left+offset, r.top+offset,
705 r.right - r.left - 2*offset, r.bottom - r.top - 2*offset,
706 PATCOPY );
708 /* cleanup and return */
709 SelectObject( hdc, hSavePen );
710 SelectObject( hdc, hSaveBrush );
711 return;
714 if (vertical)
716 INT offset = (TWEAK_WineLook == WIN31_LOOK) ? 1 : 0;
718 PatBlt( hdc, r.left + offset, r.top + offset,
719 r.right - r.left - offset*2,
720 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP) - offset,
721 top_selected ? 0x0f0000 : PATCOPY );
722 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
723 PatBlt( hdc, r.left + offset, r.top + thumbSize,
724 r.right - r.left - offset*2,
725 r.bottom - r.top - thumbSize - offset,
726 bottom_selected ? 0x0f0000 : PATCOPY );
727 r.bottom = r.top + thumbSize;
729 else /* horizontal */
731 INT offset = (TWEAK_WineLook == WIN31_LOOK) ? 1 : 0;
733 PatBlt( hdc, r.left + offset, r.top + offset,
734 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
735 r.bottom - r.top - offset*2,
736 top_selected ? 0x0f0000 : PATCOPY );
737 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
738 PatBlt( hdc, r.left + thumbSize, r.top + offset,
739 r.right - r.left - thumbSize - offset,
740 r.bottom - r.top - offset*2,
741 bottom_selected ? 0x0f0000 : PATCOPY );
742 r.right = r.left + thumbSize;
745 /* Draw the thumb */
747 SelectObject( hdc, GetSysColorBrush(COLOR_BTNFACE) );
748 if (TWEAK_WineLook == WIN31_LOOK)
750 Rectangle( hdc, r.left, r.top, r.right, r.bottom );
751 r.top++, r.left++;
753 else
755 Rectangle( hdc, r.left+1, r.top+1, r.right-1, r.bottom-1 );
757 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT );
759 if (Save_SCROLL_MovingThumb &&
760 (SCROLL_TrackingWin == hwnd) &&
761 (SCROLL_TrackingBar == nBar))
762 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
764 /* cleanup */
765 SelectObject( hdc, hSavePen );
766 SelectObject( hdc, hSaveBrush );
770 /***********************************************************************
771 * SCROLL_DrawScrollBar
773 * Redraw the whole scrollbar.
775 void SCROLL_DrawScrollBar( HWND hwnd, HDC hdc, INT nBar,
776 BOOL arrows, BOOL interior )
778 INT arrowSize, thumbSize, thumbPos;
779 RECT rect;
780 BOOL vertical;
781 WND *wndPtr = WIN_FindWndPtr( hwnd );
782 SCROLLBAR_INFO *infoPtr = SCROLL_GetPtrScrollInfo( wndPtr, nBar );
783 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
785 if (!wndPtr || !infoPtr ||
786 ((nBar == SB_VERT) && !(wndPtr->dwStyle & WS_VSCROLL)) ||
787 ((nBar == SB_HORZ) && !(wndPtr->dwStyle & WS_HSCROLL))) goto END;
788 if (!WIN_IsWindowDrawable( wndPtr, FALSE )) goto END;
790 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
791 &arrowSize, &thumbSize, &thumbPos );
793 if (Save_SCROLL_MovingThumb &&
794 (SCROLL_TrackingWin == hwnd) &&
795 (SCROLL_TrackingBar == nBar))
796 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
798 /* Draw the arrows */
800 if (arrows && arrowSize)
802 if( vertical == SCROLL_trackVertical && GetCapture() == hwnd )
803 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
804 (SCROLL_trackHitTest == SCROLL_TOP_ARROW),
805 (SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW) );
806 else
807 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
808 FALSE, FALSE );
810 if( interior )
811 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
812 thumbPos, infoPtr->flags, vertical, FALSE, FALSE );
814 if (Save_SCROLL_MovingThumb &&
815 (SCROLL_TrackingWin == hwnd) &&
816 (SCROLL_TrackingBar == nBar))
817 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
819 END:
820 WIN_ReleaseWndPtr(wndPtr);
824 /***********************************************************************
825 * SCROLL_RefreshScrollBar
827 * Repaint the scroll bar interior after a SetScrollRange() or
828 * SetScrollPos() call.
830 static void SCROLL_RefreshScrollBar( HWND hwnd, INT nBar,
831 BOOL arrows, BOOL interior )
833 HDC hdc = GetDCEx( hwnd, 0,
834 DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW) );
835 if (!hdc) return;
837 SCROLL_DrawScrollBar( hwnd, hdc, nBar, arrows, interior );
838 ReleaseDC( hwnd, hdc );
842 /***********************************************************************
843 * SCROLL_HandleKbdEvent
845 * Handle a keyboard event (only for SB_CTL scrollbars).
847 static void SCROLL_HandleKbdEvent( HWND hwnd, WPARAM wParam )
849 WND *wndPtr = WIN_FindWndPtr( hwnd );
850 WPARAM msg;
852 switch(wParam)
854 case VK_PRIOR: msg = SB_PAGEUP; break;
855 case VK_NEXT: msg = SB_PAGEDOWN; break;
856 case VK_HOME: msg = SB_TOP; break;
857 case VK_END: msg = SB_BOTTOM; break;
858 case VK_UP: msg = SB_LINEUP; break;
859 case VK_DOWN: msg = SB_LINEDOWN; break;
860 default:
861 WIN_ReleaseWndPtr(wndPtr);
862 return;
864 SendMessageA( GetParent(hwnd),
865 (wndPtr->dwStyle & SBS_VERT) ? WM_VSCROLL : WM_HSCROLL,
866 msg, hwnd );
867 WIN_ReleaseWndPtr(wndPtr);
871 /***********************************************************************
872 * SCROLL_HandleScrollEvent
874 * Handle a mouse or timer event for the scrollbar.
875 * 'pt' is the location of the mouse event in client (for SB_CTL) or
876 * windows coordinates.
878 void SCROLL_HandleScrollEvent( HWND hwnd, INT nBar, UINT msg, POINT pt)
880 /* Previous mouse position for timer events */
881 static POINT prevPt;
882 /* Thumb position when tracking started. */
883 static UINT trackThumbPos;
884 /* Position in the scroll-bar of the last button-down event. */
885 static INT lastClickPos;
886 /* Position in the scroll-bar of the last mouse event. */
887 static INT lastMousePos;
889 enum SCROLL_HITTEST hittest;
890 HWND hwndOwner, hwndCtl;
891 BOOL vertical;
892 INT arrowSize, thumbSize, thumbPos;
893 RECT rect;
894 HDC hdc;
896 SCROLLBAR_INFO *infoPtr = SCROLL_GetScrollInfo( hwnd, nBar );
897 if (!infoPtr) return;
898 if ((SCROLL_trackHitTest == SCROLL_NOWHERE) && (msg != WM_LBUTTONDOWN))
899 return;
901 hdc = GetDCEx( hwnd, 0, DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW));
902 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
903 &arrowSize, &thumbSize, &thumbPos );
904 hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd) : hwnd;
905 hwndCtl = (nBar == SB_CTL) ? hwnd : 0;
907 switch(msg)
909 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
910 SCROLL_trackVertical = vertical;
911 SCROLL_trackHitTest = hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
912 lastClickPos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
913 lastMousePos = lastClickPos;
914 trackThumbPos = thumbPos;
915 prevPt = pt;
916 SetCapture( hwnd );
917 if (nBar == SB_CTL) SetFocus( hwnd );
918 break;
920 case WM_MOUSEMOVE:
921 hittest = SCROLL_HitTest( hwnd, nBar, pt, TRUE );
922 prevPt = pt;
923 break;
925 case WM_LBUTTONUP:
926 hittest = SCROLL_NOWHERE;
927 ReleaseCapture();
928 break;
930 case WM_SYSTIMER:
931 pt = prevPt;
932 hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
933 break;
935 default:
936 return; /* Should never happen */
939 TRACE("Event: hwnd=%04x bar=%d msg=%x pt=%ld,%ld hit=%d\n",
940 hwnd, nBar, msg, pt.x, pt.y, hittest );
942 switch(SCROLL_trackHitTest)
944 case SCROLL_NOWHERE: /* No tracking in progress */
945 break;
947 case SCROLL_TOP_ARROW:
948 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
949 (hittest == SCROLL_trackHitTest), FALSE );
950 if (hittest == SCROLL_trackHitTest)
952 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
954 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
955 SB_LINEUP, hwndCtl );
958 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
959 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
960 (TIMERPROC)0 );
962 else KillSystemTimer( hwnd, SCROLL_TIMER );
963 break;
965 case SCROLL_TOP_RECT:
966 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
967 thumbPos, infoPtr->flags, vertical,
968 (hittest == SCROLL_trackHitTest), FALSE );
969 if (hittest == SCROLL_trackHitTest)
971 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
973 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
974 SB_PAGEUP, hwndCtl );
975 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
976 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
977 (TIMERPROC)0 );
980 else KillSystemTimer( hwnd, SCROLL_TIMER );
981 break;
983 case SCROLL_THUMB:
984 if (msg == WM_LBUTTONDOWN)
986 SCROLL_TrackingWin = hwnd;
987 SCROLL_TrackingBar = nBar;
988 SCROLL_TrackingPos = trackThumbPos + lastMousePos - lastClickPos;
989 if (!SCROLL_MovingThumb)
990 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
992 else if (msg == WM_LBUTTONUP)
994 if (SCROLL_MovingThumb)
995 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
996 SCROLL_TrackingWin = 0;
997 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
998 thumbPos, infoPtr->flags, vertical,
999 FALSE, FALSE );
1001 else /* WM_MOUSEMOVE */
1003 UINT pos;
1005 if (!SCROLL_PtInRectEx( &rect, pt, vertical )) pos = lastClickPos;
1006 else
1008 pt = SCROLL_ClipPos( &rect, pt );
1009 pos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
1011 if ( (pos != lastMousePos) || (!SCROLL_MovingThumb) )
1013 if (SCROLL_MovingThumb)
1014 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
1015 arrowSize, thumbSize );
1016 lastMousePos = pos;
1017 SCROLL_TrackingPos = trackThumbPos + pos - lastClickPos;
1018 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
1019 vertical,
1020 SCROLL_TrackingPos );
1021 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1022 MAKEWPARAM( SB_THUMBTRACK, SCROLL_TrackingVal),
1023 hwndCtl );
1024 if (!SCROLL_MovingThumb)
1025 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
1026 arrowSize, thumbSize );
1029 break;
1031 case SCROLL_BOTTOM_RECT:
1032 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
1033 thumbPos, infoPtr->flags, vertical,
1034 FALSE, (hittest == SCROLL_trackHitTest) );
1035 if (hittest == SCROLL_trackHitTest)
1037 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1039 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1040 SB_PAGEDOWN, hwndCtl );
1041 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1042 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1043 (TIMERPROC)0 );
1046 else KillSystemTimer( hwnd, SCROLL_TIMER );
1047 break;
1049 case SCROLL_BOTTOM_ARROW:
1050 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
1051 FALSE, (hittest == SCROLL_trackHitTest) );
1052 if (hittest == SCROLL_trackHitTest)
1054 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1056 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1057 SB_LINEDOWN, hwndCtl );
1060 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1061 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1062 (TIMERPROC)0 );
1064 else KillSystemTimer( hwnd, SCROLL_TIMER );
1065 break;
1068 if (msg == WM_LBUTTONUP)
1070 hittest = SCROLL_trackHitTest;
1071 SCROLL_trackHitTest = SCROLL_NOWHERE; /* Terminate tracking */
1073 if (hittest == SCROLL_THUMB)
1075 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1076 trackThumbPos + lastMousePos - lastClickPos );
1077 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1078 MAKEWPARAM( SB_THUMBPOSITION, val ), hwndCtl );
1080 else
1081 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1082 SB_ENDSCROLL, hwndCtl );
1085 ReleaseDC( hwnd, hdc );
1089 /***********************************************************************
1090 * ScrollBarWndProc
1092 LRESULT WINAPI ScrollBarWndProc( HWND hwnd, UINT message, WPARAM wParam,
1093 LPARAM lParam )
1095 switch(message)
1097 case WM_CREATE:
1099 CREATESTRUCTA *lpCreat = (CREATESTRUCTA *)lParam;
1100 if (lpCreat->style & SBS_SIZEBOX)
1102 FIXME("Unimplemented style SBS_SIZEBOX.\n" );
1103 return 0;
1106 if (lpCreat->style & SBS_VERT)
1108 if (lpCreat->style & SBS_LEFTALIGN)
1109 MoveWindow( hwnd, lpCreat->x, lpCreat->y,
1110 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreat->cy, FALSE );
1111 else if (lpCreat->style & SBS_RIGHTALIGN)
1112 MoveWindow( hwnd,
1113 lpCreat->x+lpCreat->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1114 lpCreat->y,
1115 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreat->cy, FALSE );
1117 else /* SBS_HORZ */
1119 if (lpCreat->style & SBS_TOPALIGN)
1120 MoveWindow( hwnd, lpCreat->x, lpCreat->y,
1121 lpCreat->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1122 else if (lpCreat->style & SBS_BOTTOMALIGN)
1123 MoveWindow( hwnd,
1124 lpCreat->x,
1125 lpCreat->y+lpCreat->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1126 lpCreat->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1129 if (!hUpArrow) SCROLL_LoadBitmaps();
1130 TRACE("ScrollBar creation, hwnd=%04x\n", hwnd );
1131 return 0;
1133 case WM_LBUTTONDOWN:
1134 case WM_LBUTTONUP:
1135 case WM_MOUSEMOVE:
1136 case WM_SYSTIMER:
1138 POINT pt;
1139 CONV_POINT16TO32( (POINT16 *)&lParam, &pt );
1140 SCROLL_HandleScrollEvent( hwnd, SB_CTL, message, pt );
1142 break;
1144 case WM_KEYDOWN:
1145 SCROLL_HandleKbdEvent( hwnd, wParam );
1146 break;
1148 case WM_ERASEBKGND:
1149 return 1;
1151 case WM_GETDLGCODE:
1152 return DLGC_WANTARROWS; /* Windows returns this value */
1154 case WM_PAINT:
1156 PAINTSTRUCT ps;
1157 HDC hdc = BeginPaint( hwnd, &ps );
1158 SCROLL_DrawScrollBar( hwnd, hdc, SB_CTL, TRUE, TRUE );
1159 EndPaint( hwnd, &ps );
1161 break;
1163 case SBM_SETPOS16:
1164 case SBM_SETPOS:
1165 return SetScrollPos( hwnd, SB_CTL, wParam, (BOOL)lParam );
1167 case SBM_GETPOS16:
1168 case SBM_GETPOS:
1169 return GetScrollPos( hwnd, SB_CTL );
1171 case SBM_SETRANGE16:
1172 SetScrollRange( hwnd, SB_CTL, LOWORD(lParam), HIWORD(lParam),
1173 wParam /* FIXME: Is this correct? */ );
1174 return 0;
1176 case SBM_SETRANGE:
1177 SetScrollRange( hwnd, SB_CTL, wParam, lParam, FALSE );
1178 return 0; /* FIXME: return previous position */
1180 case SBM_GETRANGE16:
1181 FIXME("don't know how to handle SBM_GETRANGE16 (wp=%04x,lp=%08lx)\n", wParam, lParam );
1182 return 0;
1184 case SBM_GETRANGE:
1185 GetScrollRange( hwnd, SB_CTL, (LPINT)wParam, (LPINT)lParam );
1186 return 0;
1188 case SBM_ENABLE_ARROWS16:
1189 case SBM_ENABLE_ARROWS:
1190 return EnableScrollBar( hwnd, SB_CTL, wParam );
1192 case SBM_SETRANGEREDRAW:
1193 SetScrollRange( hwnd, SB_CTL, wParam, lParam, TRUE );
1194 return 0; /* FIXME: return previous position */
1196 case SBM_SETSCROLLINFO:
1197 return SetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam, wParam );
1199 case SBM_GETSCROLLINFO:
1200 return GetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam );
1202 case 0x00e5:
1203 case 0x00e7:
1204 case 0x00e8:
1205 case 0x00eb:
1206 case 0x00ec:
1207 case 0x00ed:
1208 case 0x00ee:
1209 case 0x00ef:
1210 ERR("unknown Win32 msg %04x wp=%08x lp=%08lx\n",
1211 message, wParam, lParam );
1212 break;
1214 default:
1215 if (message >= WM_USER)
1216 WARN("unknown msg %04x wp=%04x lp=%08lx\n",
1217 message, wParam, lParam );
1218 return DefWindowProcA( hwnd, message, wParam, lParam );
1220 return 0;
1224 /*************************************************************************
1225 * SetScrollInfo16 (USER.475)
1227 INT16 WINAPI SetScrollInfo16( HWND16 hwnd, INT16 nBar, const SCROLLINFO *info,
1228 BOOL16 bRedraw )
1230 return (INT16)SetScrollInfo( hwnd, nBar, info, bRedraw );
1234 /*************************************************************************
1235 * SetScrollInfo (USER32.501)
1236 * SetScrollInfo can be used to set the position, upper bound,
1237 * lower bound, and page size of a scrollbar control.
1239 * RETURNS
1240 * Scrollbar position
1242 * NOTE
1243 * For 100 lines of text to be displayed in a window of 25 lines,
1244 * one would for instance use info->nMin=0, info->nMax=75
1245 * (corresponding to the 76 different positions of the window on
1246 * the text), and info->nPage=25.
1248 INT WINAPI SetScrollInfo(
1249 HWND hwnd /* [I] Handle of window whose scrollbar will be affected */,
1250 INT nBar /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */,
1251 const SCROLLINFO *info /* [I] Specifies what to change and new values */,
1252 BOOL bRedraw /* [I] Should scrollbar be redrawn afterwards ? */)
1254 INT action;
1255 INT retVal = SCROLL_SetScrollInfo( hwnd, nBar, info, &action );
1257 if( action & SA_SSI_HIDE )
1258 SCROLL_ShowScrollBar( hwnd, nBar, FALSE, FALSE );
1259 else
1261 if( action & SA_SSI_SHOW )
1262 if( SCROLL_ShowScrollBar( hwnd, nBar, TRUE, TRUE ) )
1263 return retVal; /* SetWindowPos() already did the painting */
1265 if( bRedraw && (action & SA_SSI_REFRESH))
1266 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
1267 else if( action & SA_SSI_REPAINT_ARROWS )
1268 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, FALSE );
1270 return retVal;
1273 INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar,
1274 const SCROLLINFO *info, INT *action )
1276 /* Update the scrollbar state and set action flags according to
1277 * what has to be done graphics wise. */
1279 SCROLLBAR_INFO *infoPtr;
1280 UINT new_flags;
1282 *action = 0;
1284 if (!(infoPtr = SCROLL_GetScrollInfo(hwnd, nBar))) return 0;
1285 if (info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)) return 0;
1286 if ((info->cbSize != sizeof(*info)) &&
1287 (info->cbSize != sizeof(*info)-sizeof(info->nTrackPos))) return 0;
1289 if (TRACE_ON(scroll))
1291 DPRINTF( "hwnd=%04x bar=%d", hwnd, nBar);
1292 if (info->fMask & SIF_PAGE) DPRINTF( " page=%d", info->nPage );
1293 if (info->fMask & SIF_POS) DPRINTF( " pos=%d", info->nPos );
1294 if (info->fMask & SIF_RANGE) DPRINTF( " min=%d max=%d", info->nMin, info->nMax );
1295 DPRINTF("\n");
1298 /* Set the page size */
1300 if (info->fMask & SIF_PAGE)
1302 if( infoPtr->Page != info->nPage )
1304 infoPtr->Page = info->nPage;
1305 *action |= SA_SSI_REFRESH;
1309 /* Set the scroll pos */
1311 if (info->fMask & SIF_POS)
1313 if( infoPtr->CurVal != info->nPos )
1315 infoPtr->CurVal = info->nPos;
1316 *action |= SA_SSI_REFRESH;
1320 /* Set the scroll range */
1322 if (info->fMask & SIF_RANGE)
1324 /* Invalid range -> range is set to (0,0) */
1325 if ((info->nMin > info->nMax) ||
1326 ((UINT)(info->nMax - info->nMin) >= 0x80000000))
1328 infoPtr->MinVal = 0;
1329 infoPtr->MaxVal = 0;
1331 else
1333 if( infoPtr->MinVal != info->nMin ||
1334 infoPtr->MaxVal != info->nMax )
1336 *action |= SA_SSI_REFRESH;
1337 infoPtr->MinVal = info->nMin;
1338 infoPtr->MaxVal = info->nMax;
1343 /* Make sure the page size is valid */
1345 if (infoPtr->Page < 0) infoPtr->Page = 0;
1346 else if (infoPtr->Page > infoPtr->MaxVal - infoPtr->MinVal + 1 )
1347 infoPtr->Page = infoPtr->MaxVal - infoPtr->MinVal + 1;
1349 /* Make sure the pos is inside the range */
1351 if (infoPtr->CurVal < infoPtr->MinVal)
1352 infoPtr->CurVal = infoPtr->MinVal;
1353 else if (infoPtr->CurVal > infoPtr->MaxVal - max( infoPtr->Page-1, 0 ))
1354 infoPtr->CurVal = infoPtr->MaxVal - max( infoPtr->Page-1, 0 );
1356 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1357 infoPtr->Page, infoPtr->CurVal,
1358 infoPtr->MinVal, infoPtr->MaxVal );
1360 /* don't change the scrollbar state if SetScrollInfo
1361 * is just called with SIF_DISABLENOSCROLL
1363 if(!(info->fMask & SIF_ALL)) goto done;
1365 /* Check if the scrollbar should be hidden or disabled */
1367 if (info->fMask & (SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL))
1369 new_flags = infoPtr->flags;
1370 if (infoPtr->MinVal >= infoPtr->MaxVal - max( infoPtr->Page-1, 0 ))
1372 /* Hide or disable scroll-bar */
1373 if (info->fMask & SIF_DISABLENOSCROLL)
1375 new_flags = ESB_DISABLE_BOTH;
1376 *action |= SA_SSI_REFRESH;
1378 else if (nBar != SB_CTL)
1380 *action = SA_SSI_HIDE;
1381 goto done;
1384 else /* Show and enable scroll-bar */
1386 new_flags = 0;
1387 if (nBar != SB_CTL)
1388 *action |= SA_SSI_SHOW;
1391 if (infoPtr->flags != new_flags) /* check arrow flags */
1393 infoPtr->flags = new_flags;
1394 *action |= SA_SSI_REPAINT_ARROWS;
1398 done:
1399 /* Return current position */
1401 return infoPtr->CurVal;
1405 /*************************************************************************
1406 * GetScrollInfo16 (USER.476)
1408 BOOL16 WINAPI GetScrollInfo16( HWND16 hwnd, INT16 nBar, LPSCROLLINFO info )
1410 return GetScrollInfo( hwnd, nBar, info );
1414 /*************************************************************************
1415 * GetScrollInfo (USER32.284)
1416 * GetScrollInfo can be used to retrieve the position, upper bound,
1417 * lower bound, and page size of a scrollbar control.
1419 * RETURNS STD
1421 BOOL WINAPI GetScrollInfo(
1422 HWND hwnd /* [I] Handle of window */ ,
1423 INT nBar /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */,
1424 LPSCROLLINFO info /* [IO] (info.fMask [I] specifies which values are to retrieve) */)
1426 SCROLLBAR_INFO *infoPtr;
1428 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return FALSE;
1429 if (info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)) return FALSE;
1430 if ((info->cbSize != sizeof(*info)) &&
1431 (info->cbSize != sizeof(*info)-sizeof(info->nTrackPos))) return FALSE;
1433 if (info->fMask & SIF_PAGE) info->nPage = infoPtr->Page;
1434 if (info->fMask & SIF_POS) info->nPos = infoPtr->CurVal;
1435 if ((info->fMask & SIF_TRACKPOS) && (info->cbSize == sizeof(*info)))
1436 info->nTrackPos = (SCROLL_TrackingWin==hwnd) ? SCROLL_TrackingVal : infoPtr->CurVal;
1437 if (info->fMask & SIF_RANGE)
1439 info->nMin = infoPtr->MinVal;
1440 info->nMax = infoPtr->MaxVal;
1442 return (info->fMask & SIF_ALL) != 0;
1446 /*************************************************************************
1447 * SetScrollPos16 (USER.62)
1449 INT16 WINAPI SetScrollPos16( HWND16 hwnd, INT16 nBar, INT16 nPos,
1450 BOOL16 bRedraw )
1452 return (INT16)SetScrollPos( hwnd, nBar, nPos, bRedraw );
1456 /*************************************************************************
1457 * SetScrollPos (USER32.502)
1459 * RETURNS
1460 * Success: Scrollbar position
1461 * Failure: 0
1463 * REMARKS
1464 * Note the ambiguity when 0 is returned. Use GetLastError
1465 * to make sure there was an error (and to know which one).
1467 INT WINAPI SetScrollPos(
1468 HWND hwnd /* [I] Handle of window whose scrollbar will be affected */,
1469 INT nBar /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */,
1470 INT nPos /* [I] New value */,
1471 BOOL bRedraw /* [I] Should scrollbar be redrawn afterwards ? */ )
1473 SCROLLINFO info;
1474 SCROLLBAR_INFO *infoPtr;
1475 INT oldPos;
1477 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return 0;
1478 oldPos = infoPtr->CurVal;
1479 info.cbSize = sizeof(info);
1480 info.nPos = nPos;
1481 info.fMask = SIF_POS;
1482 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1483 return oldPos;
1487 /*************************************************************************
1488 * GetScrollPos16 (USER.63)
1490 INT16 WINAPI GetScrollPos16( HWND16 hwnd, INT16 nBar )
1492 return (INT16)GetScrollPos( hwnd, nBar );
1496 /*************************************************************************
1497 * GetScrollPos (USER32.285)
1499 * RETURNS
1500 * Success: Current position
1501 * Failure: 0
1503 * REMARKS
1504 * Note the ambiguity when 0 is returned. Use GetLastError
1505 * to make sure there was an error (and to know which one).
1507 INT WINAPI GetScrollPos(
1508 HWND hwnd, /* [I] Handle of window */
1509 INT nBar /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */)
1511 SCROLLBAR_INFO *infoPtr;
1513 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return 0;
1514 return infoPtr->CurVal;
1518 /*************************************************************************
1519 * SetScrollRange16 (USER.64)
1521 void WINAPI SetScrollRange16( HWND16 hwnd, INT16 nBar,
1522 INT16 MinVal, INT16 MaxVal, BOOL16 bRedraw )
1524 /* Invalid range -> range is set to (0,0) */
1525 if ((INT)MaxVal - (INT)MinVal > 0x7fff) MinVal = MaxVal = 0;
1526 SetScrollRange( hwnd, nBar, MinVal, MaxVal, bRedraw );
1530 /*************************************************************************
1531 * SetScrollRange (USER32.503)
1533 * RETURNS STD
1535 BOOL WINAPI SetScrollRange(
1536 HWND hwnd, /* [I] Handle of window whose scrollbar will be affected */
1537 INT nBar, /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */
1538 INT MinVal, /* [I] New minimum value */
1539 INT MaxVal, /* [I] New maximum value */
1540 BOOL bRedraw /* [I] Should scrollbar be redrawn afterwards ? */)
1542 SCROLLINFO info;
1544 info.cbSize = sizeof(info);
1545 info.nMin = MinVal;
1546 info.nMax = MaxVal;
1547 info.fMask = SIF_RANGE;
1548 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1549 return TRUE;
1553 /*************************************************************************
1554 * SCROLL_SetNCSbState
1556 * Updates both scrollbars at the same time. Used by MDI CalcChildScroll().
1558 INT SCROLL_SetNCSbState(WND* wndPtr, int vMin, int vMax, int vPos,
1559 int hMin, int hMax, int hPos)
1561 INT vA, hA;
1562 SCROLLINFO vInfo, hInfo;
1564 vInfo.cbSize = hInfo.cbSize = sizeof(SCROLLINFO);
1565 vInfo.nMin = vMin; hInfo.nMin = hMin;
1566 vInfo.nMax = vMax; hInfo.nMax = hMax;
1567 vInfo.nPos = vPos; hInfo.nPos = hPos;
1568 vInfo.fMask = hInfo.fMask = SIF_RANGE | SIF_POS;
1570 SCROLL_SetScrollInfo( wndPtr->hwndSelf, SB_VERT, &vInfo, &vA );
1571 SCROLL_SetScrollInfo( wndPtr->hwndSelf, SB_HORZ, &hInfo, &hA );
1573 if( !SCROLL_ShowScrollBar( wndPtr->hwndSelf, SB_BOTH,
1574 (hA & SA_SSI_SHOW),(vA & SA_SSI_SHOW) ) )
1576 /* SetWindowPos() wasn't called, just redraw the scrollbars if needed */
1577 if( vA & SA_SSI_REFRESH )
1578 SCROLL_RefreshScrollBar( wndPtr->hwndSelf, SB_VERT, FALSE, TRUE );
1580 if( hA & SA_SSI_REFRESH )
1581 SCROLL_RefreshScrollBar( wndPtr->hwndSelf, SB_HORZ, FALSE, TRUE );
1583 return 0;
1587 /*************************************************************************
1588 * GetScrollRange16 (USER.65)
1590 BOOL16 WINAPI GetScrollRange16( HWND16 hwnd, INT16 nBar,
1591 LPINT16 lpMin, LPINT16 lpMax)
1593 INT min, max;
1594 BOOL16 ret = GetScrollRange( hwnd, nBar, &min, &max );
1595 if (lpMin) *lpMin = min;
1596 if (lpMax) *lpMax = max;
1597 return ret;
1601 /*************************************************************************
1602 * GetScrollRange (USER32.286)
1604 * RETURNS STD
1606 BOOL WINAPI GetScrollRange(
1607 HWND hwnd, /* [I] Handle of window */
1608 INT nBar, /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */
1609 LPINT lpMin, /* [O] Where to store minimum value */
1610 LPINT lpMax /* [O] Where to store maximum value */)
1612 SCROLLBAR_INFO *infoPtr;
1614 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar )))
1616 if (lpMin) lpMin = 0;
1617 if (lpMax) lpMax = 0;
1618 return FALSE;
1620 if (lpMin) *lpMin = infoPtr->MinVal;
1621 if (lpMax) *lpMax = infoPtr->MaxVal;
1622 return TRUE;
1626 /*************************************************************************
1627 * SCROLL_ShowScrollBar()
1629 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1631 BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar,
1632 BOOL fShowH, BOOL fShowV )
1634 WND *wndPtr = WIN_FindWndPtr( hwnd );
1635 BOOL retvalue = FALSE;
1637 if (!wndPtr) return FALSE;
1638 TRACE("hwnd=%04x bar=%d horz=%d, vert=%d\n",
1639 hwnd, nBar, fShowH, fShowV );
1641 switch(nBar)
1643 case SB_CTL:
1644 ShowWindow( hwnd, fShowH ? SW_SHOW : SW_HIDE );
1645 retvalue = TRUE;
1646 goto END;
1648 case SB_BOTH:
1649 case SB_HORZ:
1650 if (fShowH)
1652 fShowH = !(wndPtr->dwStyle & WS_HSCROLL);
1653 wndPtr->dwStyle |= WS_HSCROLL;
1655 else /* hide it */
1657 fShowH = (wndPtr->dwStyle & WS_HSCROLL);
1658 wndPtr->dwStyle &= ~WS_HSCROLL;
1660 if( nBar == SB_HORZ ) {
1661 fShowV = FALSE;
1662 break;
1664 /* fall through */
1666 case SB_VERT:
1667 if (fShowV)
1669 fShowV = !(wndPtr->dwStyle & WS_VSCROLL);
1670 wndPtr->dwStyle |= WS_VSCROLL;
1672 else /* hide it */
1674 fShowV = (wndPtr->dwStyle & WS_VSCROLL);
1675 wndPtr->dwStyle &= ~WS_VSCROLL;
1677 if ( nBar == SB_VERT )
1678 fShowH = FALSE;
1679 break;
1681 default:
1682 retvalue = FALSE; /* Nothing to do! */
1683 goto END;
1686 if( fShowH || fShowV ) /* frame has been changed, let the window redraw itself */
1688 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
1689 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
1690 retvalue = TRUE;
1691 goto END;
1694 retvalue = FALSE; /* no frame changes */
1695 END:
1696 WIN_ReleaseWndPtr(wndPtr);
1697 return retvalue;
1701 /*************************************************************************
1702 * ShowScrollBar16 (USER.267)
1704 void WINAPI ShowScrollBar16( HWND16 hwnd, INT16 nBar, BOOL16 fShow )
1706 SCROLL_ShowScrollBar( hwnd, nBar, (nBar == SB_VERT) ? 0 : fShow,
1707 (nBar == SB_HORZ) ? 0 : fShow );
1711 /*************************************************************************
1712 * ShowScrollBar (USER32.532)
1714 * RETURNS STD
1716 BOOL WINAPI ShowScrollBar(
1717 HWND hwnd, /* [I] Handle of window whose scrollbar(s) will be affected */
1718 INT nBar, /* [I] One of SB_HORZ, SB_VERT, SB_BOTH or SB_CTL */
1719 BOOL fShow /* [I] TRUE = show, FALSE = hide */)
1721 SCROLL_ShowScrollBar( hwnd, nBar, (nBar == SB_VERT) ? 0 : fShow,
1722 (nBar == SB_HORZ) ? 0 : fShow );
1723 return TRUE;
1727 /*************************************************************************
1728 * EnableScrollBar16 (USER.482)
1730 BOOL16 WINAPI EnableScrollBar16( HWND16 hwnd, INT16 nBar, UINT16 flags )
1732 return EnableScrollBar( hwnd, nBar, flags );
1736 /*************************************************************************
1737 * EnableScrollBar (USER32.171)
1739 BOOL WINAPI EnableScrollBar( HWND hwnd, INT nBar, UINT flags )
1741 BOOL bFineWithMe;
1742 SCROLLBAR_INFO *infoPtr;
1744 TRACE("%04x %d %d\n", hwnd, nBar, flags );
1746 flags &= ESB_DISABLE_BOTH;
1748 if (nBar == SB_BOTH)
1750 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, SB_VERT ))) return FALSE;
1751 if (!(bFineWithMe = (infoPtr->flags == flags)) )
1753 infoPtr->flags = flags;
1754 SCROLL_RefreshScrollBar( hwnd, SB_VERT, TRUE, TRUE );
1756 nBar = SB_HORZ;
1758 else
1759 bFineWithMe = TRUE;
1761 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return FALSE;
1762 if (bFineWithMe && infoPtr->flags == flags) return FALSE;
1763 infoPtr->flags = flags;
1765 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
1766 return TRUE;