Added missing dependency for 16-bit resource files.
[wine/multimedia.git] / controls / scroll.c
blob2b8f3f422695db7bd51ebebe88d908de390d2160
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 /* if scroll bar has focus, reposition the caret*/
820 if(hwnd==GetFocus() && (nBar==SB_CTL))
822 if (!vertical)
824 SetCaretPos(thumbPos+1, rect.top+1);
826 else
828 SetCaretPos(rect.top+1, thumbPos+1);
832 END:
833 WIN_ReleaseWndPtr(wndPtr);
837 /***********************************************************************
838 * SCROLL_RefreshScrollBar
840 * Repaint the scroll bar interior after a SetScrollRange() or
841 * SetScrollPos() call.
843 static void SCROLL_RefreshScrollBar( HWND hwnd, INT nBar,
844 BOOL arrows, BOOL interior )
846 HDC hdc = GetDCEx( hwnd, 0,
847 DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW) );
848 if (!hdc) return;
850 SCROLL_DrawScrollBar( hwnd, hdc, nBar, arrows, interior );
851 ReleaseDC( hwnd, hdc );
855 /***********************************************************************
856 * SCROLL_HandleKbdEvent
858 * Handle a keyboard event (only for SB_CTL scrollbars).
860 static void SCROLL_HandleKbdEvent( HWND hwnd, WPARAM wParam )
862 WND *wndPtr = WIN_FindWndPtr( hwnd );
863 WPARAM msg;
865 switch(wParam)
867 case VK_PRIOR: msg = SB_PAGEUP; break;
868 case VK_NEXT: msg = SB_PAGEDOWN; break;
869 case VK_HOME: msg = SB_TOP; break;
870 case VK_END: msg = SB_BOTTOM; break;
871 case VK_UP: msg = SB_LINEUP; break;
872 case VK_DOWN: msg = SB_LINEDOWN; break;
873 default:
874 WIN_ReleaseWndPtr(wndPtr);
875 return;
877 SendMessageA( GetParent(hwnd),
878 (wndPtr->dwStyle & SBS_VERT) ? WM_VSCROLL : WM_HSCROLL,
879 msg, hwnd );
880 WIN_ReleaseWndPtr(wndPtr);
884 /***********************************************************************
885 * SCROLL_HandleScrollEvent
887 * Handle a mouse or timer event for the scrollbar.
888 * 'pt' is the location of the mouse event in client (for SB_CTL) or
889 * windows coordinates.
891 void SCROLL_HandleScrollEvent( HWND hwnd, INT nBar, UINT msg, POINT pt)
893 /* Previous mouse position for timer events */
894 static POINT prevPt;
895 /* Thumb position when tracking started. */
896 static UINT trackThumbPos;
897 /* Position in the scroll-bar of the last button-down event. */
898 static INT lastClickPos;
899 /* Position in the scroll-bar of the last mouse event. */
900 static INT lastMousePos;
902 enum SCROLL_HITTEST hittest;
903 HWND hwndOwner, hwndCtl;
904 BOOL vertical;
905 INT arrowSize, thumbSize, thumbPos;
906 RECT rect;
907 HDC hdc;
909 SCROLLBAR_INFO *infoPtr = SCROLL_GetScrollInfo( hwnd, nBar );
910 if (!infoPtr) return;
911 if ((SCROLL_trackHitTest == SCROLL_NOWHERE) && (msg != WM_LBUTTONDOWN))
912 return;
914 hdc = GetDCEx( hwnd, 0, DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW));
915 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
916 &arrowSize, &thumbSize, &thumbPos );
917 hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd) : hwnd;
918 hwndCtl = (nBar == SB_CTL) ? hwnd : 0;
920 switch(msg)
922 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
923 HideCaret(hwnd); /* hide caret while holding down LBUTTON*/
924 SCROLL_trackVertical = vertical;
925 SCROLL_trackHitTest = hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
926 lastClickPos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
927 lastMousePos = lastClickPos;
928 trackThumbPos = thumbPos;
929 prevPt = pt;
930 SetCapture( hwnd );
931 if (nBar == SB_CTL && (GetWindowLongA(hwnd, GWL_STYLE) & WS_TABSTOP)) SetFocus( hwnd );
932 break;
934 case WM_MOUSEMOVE:
935 hittest = SCROLL_HitTest( hwnd, nBar, pt, TRUE );
936 prevPt = pt;
937 break;
939 case WM_LBUTTONUP:
940 hittest = SCROLL_NOWHERE;
941 ReleaseCapture();
942 /* if scrollbar has focus, show back caret */
943 if (hwnd==GetFocus()) ShowCaret(hwnd);
944 break;
946 case WM_SYSTIMER:
947 pt = prevPt;
948 hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
949 break;
951 default:
952 return; /* Should never happen */
955 TRACE("Event: hwnd=%04x bar=%d msg=%x pt=%ld,%ld hit=%d\n",
956 hwnd, nBar, msg, pt.x, pt.y, hittest );
958 switch(SCROLL_trackHitTest)
960 case SCROLL_NOWHERE: /* No tracking in progress */
961 break;
963 case SCROLL_TOP_ARROW:
964 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
965 (hittest == SCROLL_trackHitTest), FALSE );
966 if (hittest == SCROLL_trackHitTest)
968 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
970 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
971 SB_LINEUP, hwndCtl );
974 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
975 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
976 (TIMERPROC)0 );
978 else KillSystemTimer( hwnd, SCROLL_TIMER );
979 break;
981 case SCROLL_TOP_RECT:
982 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
983 thumbPos, infoPtr->flags, vertical,
984 (hittest == SCROLL_trackHitTest), FALSE );
985 if (hittest == SCROLL_trackHitTest)
987 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
989 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
990 SB_PAGEUP, hwndCtl );
991 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
992 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
993 (TIMERPROC)0 );
996 else KillSystemTimer( hwnd, SCROLL_TIMER );
997 break;
999 case SCROLL_THUMB:
1000 if (msg == WM_LBUTTONDOWN)
1002 SCROLL_TrackingWin = hwnd;
1003 SCROLL_TrackingBar = nBar;
1004 SCROLL_TrackingPos = trackThumbPos + lastMousePos - lastClickPos;
1005 if (!SCROLL_MovingThumb)
1006 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
1008 else if (msg == WM_LBUTTONUP)
1010 if (SCROLL_MovingThumb)
1011 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
1012 SCROLL_TrackingWin = 0;
1013 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
1014 thumbPos, infoPtr->flags, vertical,
1015 FALSE, FALSE );
1017 else /* WM_MOUSEMOVE */
1019 UINT pos;
1021 if (!SCROLL_PtInRectEx( &rect, pt, vertical )) pos = lastClickPos;
1022 else
1024 pt = SCROLL_ClipPos( &rect, pt );
1025 pos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
1027 if ( (pos != lastMousePos) || (!SCROLL_MovingThumb) )
1029 if (SCROLL_MovingThumb)
1030 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
1031 arrowSize, thumbSize );
1032 lastMousePos = pos;
1033 SCROLL_TrackingPos = trackThumbPos + pos - lastClickPos;
1034 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
1035 vertical,
1036 SCROLL_TrackingPos );
1037 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1038 MAKEWPARAM( SB_THUMBTRACK, SCROLL_TrackingVal),
1039 hwndCtl );
1040 if (!SCROLL_MovingThumb)
1041 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
1042 arrowSize, thumbSize );
1045 break;
1047 case SCROLL_BOTTOM_RECT:
1048 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
1049 thumbPos, infoPtr->flags, vertical,
1050 FALSE, (hittest == SCROLL_trackHitTest) );
1051 if (hittest == SCROLL_trackHitTest)
1053 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1055 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1056 SB_PAGEDOWN, hwndCtl );
1057 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1058 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1059 (TIMERPROC)0 );
1062 else KillSystemTimer( hwnd, SCROLL_TIMER );
1063 break;
1065 case SCROLL_BOTTOM_ARROW:
1066 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
1067 FALSE, (hittest == SCROLL_trackHitTest) );
1068 if (hittest == SCROLL_trackHitTest)
1070 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1072 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1073 SB_LINEDOWN, hwndCtl );
1076 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1077 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1078 (TIMERPROC)0 );
1080 else KillSystemTimer( hwnd, SCROLL_TIMER );
1081 break;
1084 if (msg == WM_LBUTTONUP)
1086 hittest = SCROLL_trackHitTest;
1087 SCROLL_trackHitTest = SCROLL_NOWHERE; /* Terminate tracking */
1089 if (hittest == SCROLL_THUMB)
1091 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1092 trackThumbPos + lastMousePos - lastClickPos );
1093 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1094 MAKEWPARAM( SB_THUMBPOSITION, val ), hwndCtl );
1096 else
1097 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1098 SB_ENDSCROLL, hwndCtl );
1101 ReleaseDC( hwnd, hdc );
1105 /***********************************************************************
1106 * ScrollBarWndProc
1108 LRESULT WINAPI ScrollBarWndProc( HWND hwnd, UINT message, WPARAM wParam,
1109 LPARAM lParam )
1111 switch(message)
1113 case WM_CREATE:
1115 CREATESTRUCTA *lpCreat = (CREATESTRUCTA *)lParam;
1116 if (lpCreat->style & SBS_SIZEBOX)
1118 FIXME("Unimplemented style SBS_SIZEBOX.\n" );
1119 return 0;
1122 if (lpCreat->style & SBS_VERT)
1124 if (lpCreat->style & SBS_LEFTALIGN)
1125 MoveWindow( hwnd, lpCreat->x, lpCreat->y,
1126 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreat->cy, FALSE );
1127 else if (lpCreat->style & SBS_RIGHTALIGN)
1128 MoveWindow( hwnd,
1129 lpCreat->x+lpCreat->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1130 lpCreat->y,
1131 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreat->cy, FALSE );
1133 else /* SBS_HORZ */
1135 if (lpCreat->style & SBS_TOPALIGN)
1136 MoveWindow( hwnd, lpCreat->x, lpCreat->y,
1137 lpCreat->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1138 else if (lpCreat->style & SBS_BOTTOMALIGN)
1139 MoveWindow( hwnd,
1140 lpCreat->x,
1141 lpCreat->y+lpCreat->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1142 lpCreat->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1145 if (!hUpArrow) SCROLL_LoadBitmaps();
1146 TRACE("ScrollBar creation, hwnd=%04x\n", hwnd );
1147 return 0;
1149 case WM_LBUTTONDOWN:
1150 case WM_LBUTTONUP:
1151 case WM_MOUSEMOVE:
1152 case WM_SYSTIMER:
1154 POINT pt;
1155 pt.x = SLOWORD(lParam);
1156 pt.y = SHIWORD(lParam);
1157 SCROLL_HandleScrollEvent( hwnd, SB_CTL, message, pt );
1159 break;
1161 /* if key event is received, the scrollbar has the focus*/
1162 case WM_KEYDOWN:
1163 /* hide caret on first KEYDOWN to prevent flicker */
1164 if ((lParam & 0x40000000)==0)
1165 HideCaret(hwnd);
1166 SCROLL_HandleKbdEvent( hwnd, wParam );
1167 break;
1169 case WM_KEYUP:
1170 ShowCaret(hwnd);
1171 break;
1173 case WM_SETFOCUS:
1175 /* Create a caret when a ScrollBar get focus*/
1176 RECT rect;
1177 int arrowSize, thumbSize, thumbPos, vertical;
1178 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,
1179 &arrowSize, &thumbSize, &thumbPos );
1180 if (!vertical)
1182 CreateCaret(hwnd,1, thumbSize-2, rect.bottom-rect.top-2);
1183 SetCaretPos(thumbPos+1, rect.top+1);
1185 else
1187 CreateCaret(hwnd,1, rect.right-rect.left-2,thumbSize-2);
1188 SetCaretPos(rect.top+1, thumbPos+1);
1190 ShowCaret(hwnd);
1192 break;
1194 case WM_KILLFOCUS:
1196 RECT rect;
1197 int arrowSize, thumbSize, thumbPos, vertical;
1198 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,&arrowSize, &thumbSize, &thumbPos );
1199 if (!vertical){
1200 rect.left=thumbPos+1;
1201 rect.right=rect.left+thumbSize;
1203 else
1205 rect.top=thumbPos+1;
1206 rect.bottom=rect.top+thumbSize;
1208 HideCaret(hwnd);
1209 InvalidateRect(hwnd,&rect,0);
1210 DestroyCaret();
1212 break;
1214 case WM_ERASEBKGND:
1215 return 1;
1217 case WM_GETDLGCODE:
1218 return DLGC_WANTARROWS; /* Windows returns this value */
1220 case WM_PAINT:
1222 PAINTSTRUCT ps;
1223 HDC hdc = BeginPaint( hwnd, &ps );
1224 SCROLL_DrawScrollBar( hwnd, hdc, SB_CTL, TRUE, TRUE );
1225 EndPaint( hwnd, &ps );
1227 break;
1229 case SBM_SETPOS16:
1230 case SBM_SETPOS:
1231 return SetScrollPos( hwnd, SB_CTL, wParam, (BOOL)lParam );
1233 case SBM_GETPOS16:
1234 case SBM_GETPOS:
1235 return GetScrollPos( hwnd, SB_CTL );
1237 case SBM_SETRANGE16:
1238 SetScrollRange( hwnd, SB_CTL, LOWORD(lParam), HIWORD(lParam),
1239 wParam /* FIXME: Is this correct? */ );
1240 return 0;
1242 case SBM_SETRANGE:
1243 SetScrollRange( hwnd, SB_CTL, wParam, lParam, FALSE );
1244 return 0; /* FIXME: return previous position */
1246 case SBM_GETRANGE16:
1247 FIXME("don't know how to handle SBM_GETRANGE16 (wp=%04x,lp=%08lx)\n", wParam, lParam );
1248 return 0;
1250 case SBM_GETRANGE:
1251 GetScrollRange( hwnd, SB_CTL, (LPINT)wParam, (LPINT)lParam );
1252 return 0;
1254 case SBM_ENABLE_ARROWS16:
1255 case SBM_ENABLE_ARROWS:
1256 return EnableScrollBar( hwnd, SB_CTL, wParam );
1258 case SBM_SETRANGEREDRAW:
1259 SetScrollRange( hwnd, SB_CTL, wParam, lParam, TRUE );
1260 return 0; /* FIXME: return previous position */
1262 case SBM_SETSCROLLINFO:
1263 return SetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam, wParam );
1265 case SBM_GETSCROLLINFO:
1266 return GetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam );
1268 case 0x00e5:
1269 case 0x00e7:
1270 case 0x00e8:
1271 case 0x00eb:
1272 case 0x00ec:
1273 case 0x00ed:
1274 case 0x00ee:
1275 case 0x00ef:
1276 ERR("unknown Win32 msg %04x wp=%08x lp=%08lx\n",
1277 message, wParam, lParam );
1278 break;
1280 default:
1281 if (message >= WM_USER)
1282 WARN("unknown msg %04x wp=%04x lp=%08lx\n",
1283 message, wParam, lParam );
1284 return DefWindowProcA( hwnd, message, wParam, lParam );
1286 return 0;
1290 /*************************************************************************
1291 * SetScrollInfo16 (USER.475)
1293 INT16 WINAPI SetScrollInfo16( HWND16 hwnd, INT16 nBar, const SCROLLINFO *info,
1294 BOOL16 bRedraw )
1296 return (INT16)SetScrollInfo( hwnd, nBar, info, bRedraw );
1300 /*************************************************************************
1301 * SetScrollInfo (USER32.501)
1302 * SetScrollInfo can be used to set the position, upper bound,
1303 * lower bound, and page size of a scrollbar control.
1305 * RETURNS
1306 * Scrollbar position
1308 * NOTE
1309 * For 100 lines of text to be displayed in a window of 25 lines,
1310 * one would for instance use info->nMin=0, info->nMax=75
1311 * (corresponding to the 76 different positions of the window on
1312 * the text), and info->nPage=25.
1314 INT WINAPI SetScrollInfo(
1315 HWND hwnd /* [I] Handle of window whose scrollbar will be affected */,
1316 INT nBar /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */,
1317 const SCROLLINFO *info /* [I] Specifies what to change and new values */,
1318 BOOL bRedraw /* [I] Should scrollbar be redrawn afterwards ? */)
1320 INT action;
1321 INT retVal = SCROLL_SetScrollInfo( hwnd, nBar, info, &action );
1323 if( action & SA_SSI_HIDE )
1324 SCROLL_ShowScrollBar( hwnd, nBar, FALSE, FALSE );
1325 else
1327 if( action & SA_SSI_SHOW )
1328 if( SCROLL_ShowScrollBar( hwnd, nBar, TRUE, TRUE ) )
1329 return retVal; /* SetWindowPos() already did the painting */
1331 if( bRedraw && (action & SA_SSI_REFRESH))
1332 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
1333 else if( action & SA_SSI_REPAINT_ARROWS )
1334 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, FALSE );
1336 return retVal;
1339 INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar,
1340 const SCROLLINFO *info, INT *action )
1342 /* Update the scrollbar state and set action flags according to
1343 * what has to be done graphics wise. */
1345 SCROLLBAR_INFO *infoPtr;
1346 UINT new_flags;
1347 BOOL bChangeParams = FALSE; /* don't show/hide scrollbar if params don't change */
1349 *action = 0;
1351 if (!(infoPtr = SCROLL_GetScrollInfo(hwnd, nBar))) return 0;
1352 if (info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)) return 0;
1353 if ((info->cbSize != sizeof(*info)) &&
1354 (info->cbSize != sizeof(*info)-sizeof(info->nTrackPos))) return 0;
1356 if (TRACE_ON(scroll))
1358 DPRINTF( "hwnd=%04x bar=%d", hwnd, nBar);
1359 if (info->fMask & SIF_PAGE) DPRINTF( " page=%d", info->nPage );
1360 if (info->fMask & SIF_POS) DPRINTF( " pos=%d", info->nPos );
1361 if (info->fMask & SIF_RANGE) DPRINTF( " min=%d max=%d", info->nMin, info->nMax );
1362 DPRINTF("\n");
1365 /* Set the page size */
1367 if (info->fMask & SIF_PAGE)
1369 if( infoPtr->Page != info->nPage )
1371 infoPtr->Page = info->nPage;
1372 *action |= SA_SSI_REFRESH;
1373 bChangeParams = TRUE;
1377 /* Set the scroll pos */
1379 if (info->fMask & SIF_POS)
1381 if( infoPtr->CurVal != info->nPos )
1383 infoPtr->CurVal = info->nPos;
1384 *action |= SA_SSI_REFRESH;
1388 /* Set the scroll range */
1390 if (info->fMask & SIF_RANGE)
1392 /* Invalid range -> range is set to (0,0) */
1393 if ((info->nMin > info->nMax) ||
1394 ((UINT)(info->nMax - info->nMin) >= 0x80000000))
1396 infoPtr->MinVal = 0;
1397 infoPtr->MaxVal = 0;
1398 bChangeParams = TRUE;
1400 else
1402 if( infoPtr->MinVal != info->nMin ||
1403 infoPtr->MaxVal != info->nMax )
1405 *action |= SA_SSI_REFRESH;
1406 infoPtr->MinVal = info->nMin;
1407 infoPtr->MaxVal = info->nMax;
1408 bChangeParams = TRUE;
1413 /* Make sure the page size is valid */
1415 if (infoPtr->Page < 0) infoPtr->Page = 0;
1416 else if (infoPtr->Page > infoPtr->MaxVal - infoPtr->MinVal + 1 )
1417 infoPtr->Page = infoPtr->MaxVal - infoPtr->MinVal + 1;
1419 /* Make sure the pos is inside the range */
1421 if (infoPtr->CurVal < infoPtr->MinVal)
1422 infoPtr->CurVal = infoPtr->MinVal;
1423 else if (infoPtr->CurVal > infoPtr->MaxVal - max( infoPtr->Page-1, 0 ))
1424 infoPtr->CurVal = infoPtr->MaxVal - max( infoPtr->Page-1, 0 );
1426 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1427 infoPtr->Page, infoPtr->CurVal,
1428 infoPtr->MinVal, infoPtr->MaxVal );
1430 /* don't change the scrollbar state if SetScrollInfo
1431 * is just called with SIF_DISABLENOSCROLL
1433 if(!(info->fMask & SIF_ALL)) goto done;
1435 /* Check if the scrollbar should be hidden or disabled */
1437 if (info->fMask & (SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL))
1439 new_flags = infoPtr->flags;
1440 if (infoPtr->MinVal >= infoPtr->MaxVal - max( infoPtr->Page-1, 0 ))
1442 /* Hide or disable scroll-bar */
1443 if (info->fMask & SIF_DISABLENOSCROLL)
1445 new_flags = ESB_DISABLE_BOTH;
1446 *action |= SA_SSI_REFRESH;
1448 else if ((nBar != SB_CTL) && bChangeParams)
1450 *action = SA_SSI_HIDE;
1451 goto done;
1454 else /* Show and enable scroll-bar */
1456 new_flags = 0;
1457 if ((nBar != SB_CTL) && bChangeParams)
1458 *action |= SA_SSI_SHOW;
1461 if (infoPtr->flags != new_flags) /* check arrow flags */
1463 infoPtr->flags = new_flags;
1464 *action |= SA_SSI_REPAINT_ARROWS;
1468 done:
1469 /* Return current position */
1471 return infoPtr->CurVal;
1475 /*************************************************************************
1476 * GetScrollInfo16 (USER.476)
1478 BOOL16 WINAPI GetScrollInfo16( HWND16 hwnd, INT16 nBar, LPSCROLLINFO info )
1480 return GetScrollInfo( hwnd, nBar, info );
1484 /*************************************************************************
1485 * GetScrollInfo (USER32.284)
1486 * GetScrollInfo can be used to retrieve the position, upper bound,
1487 * lower bound, and page size of a scrollbar control.
1489 * RETURNS STD
1491 BOOL WINAPI GetScrollInfo(
1492 HWND hwnd /* [I] Handle of window */ ,
1493 INT nBar /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */,
1494 LPSCROLLINFO info /* [IO] (info.fMask [I] specifies which values are to retrieve) */)
1496 SCROLLBAR_INFO *infoPtr;
1498 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return FALSE;
1499 if (info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)) return FALSE;
1500 if ((info->cbSize != sizeof(*info)) &&
1501 (info->cbSize != sizeof(*info)-sizeof(info->nTrackPos))) return FALSE;
1503 if (info->fMask & SIF_PAGE) info->nPage = infoPtr->Page;
1504 if (info->fMask & SIF_POS) info->nPos = infoPtr->CurVal;
1505 if ((info->fMask & SIF_TRACKPOS) && (info->cbSize == sizeof(*info)))
1506 info->nTrackPos = (SCROLL_TrackingWin==hwnd) ? SCROLL_TrackingVal : infoPtr->CurVal;
1507 if (info->fMask & SIF_RANGE)
1509 info->nMin = infoPtr->MinVal;
1510 info->nMax = infoPtr->MaxVal;
1512 return (info->fMask & SIF_ALL) != 0;
1516 /*************************************************************************
1517 * SetScrollPos16 (USER.62)
1519 INT16 WINAPI SetScrollPos16( HWND16 hwnd, INT16 nBar, INT16 nPos,
1520 BOOL16 bRedraw )
1522 return (INT16)SetScrollPos( hwnd, nBar, nPos, bRedraw );
1526 /*************************************************************************
1527 * SetScrollPos (USER32.502)
1529 * RETURNS
1530 * Success: Scrollbar position
1531 * Failure: 0
1533 * REMARKS
1534 * Note the ambiguity when 0 is returned. Use GetLastError
1535 * to make sure there was an error (and to know which one).
1537 INT WINAPI SetScrollPos(
1538 HWND hwnd /* [I] Handle of window whose scrollbar will be affected */,
1539 INT nBar /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */,
1540 INT nPos /* [I] New value */,
1541 BOOL bRedraw /* [I] Should scrollbar be redrawn afterwards ? */ )
1543 SCROLLINFO info;
1544 SCROLLBAR_INFO *infoPtr;
1545 INT oldPos;
1547 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return 0;
1548 oldPos = infoPtr->CurVal;
1549 info.cbSize = sizeof(info);
1550 info.nPos = nPos;
1551 info.fMask = SIF_POS;
1552 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1553 return oldPos;
1557 /*************************************************************************
1558 * GetScrollPos16 (USER.63)
1560 INT16 WINAPI GetScrollPos16( HWND16 hwnd, INT16 nBar )
1562 return (INT16)GetScrollPos( hwnd, nBar );
1566 /*************************************************************************
1567 * GetScrollPos (USER32.285)
1569 * RETURNS
1570 * Success: Current position
1571 * Failure: 0
1573 * REMARKS
1574 * Note the ambiguity when 0 is returned. Use GetLastError
1575 * to make sure there was an error (and to know which one).
1577 INT WINAPI GetScrollPos(
1578 HWND hwnd, /* [I] Handle of window */
1579 INT nBar /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */)
1581 SCROLLBAR_INFO *infoPtr;
1583 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return 0;
1584 return infoPtr->CurVal;
1588 /*************************************************************************
1589 * SetScrollRange16 (USER.64)
1591 void WINAPI SetScrollRange16( HWND16 hwnd, INT16 nBar,
1592 INT16 MinVal, INT16 MaxVal, BOOL16 bRedraw )
1594 /* Invalid range -> range is set to (0,0) */
1595 if ((INT)MaxVal - (INT)MinVal > 0x7fff) MinVal = MaxVal = 0;
1596 SetScrollRange( hwnd, nBar, MinVal, MaxVal, bRedraw );
1600 /*************************************************************************
1601 * SetScrollRange (USER32.503)
1603 * RETURNS STD
1605 BOOL WINAPI SetScrollRange(
1606 HWND hwnd, /* [I] Handle of window whose scrollbar will be affected */
1607 INT nBar, /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */
1608 INT MinVal, /* [I] New minimum value */
1609 INT MaxVal, /* [I] New maximum value */
1610 BOOL bRedraw /* [I] Should scrollbar be redrawn afterwards ? */)
1612 SCROLLINFO info;
1614 info.cbSize = sizeof(info);
1615 info.nMin = MinVal;
1616 info.nMax = MaxVal;
1617 info.fMask = SIF_RANGE;
1618 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1619 return TRUE;
1623 /*************************************************************************
1624 * SCROLL_SetNCSbState
1626 * Updates both scrollbars at the same time. Used by MDI CalcChildScroll().
1628 INT SCROLL_SetNCSbState(WND* wndPtr, int vMin, int vMax, int vPos,
1629 int hMin, int hMax, int hPos)
1631 INT vA, hA;
1632 SCROLLINFO vInfo, hInfo;
1634 vInfo.cbSize = hInfo.cbSize = sizeof(SCROLLINFO);
1635 vInfo.nMin = vMin; hInfo.nMin = hMin;
1636 vInfo.nMax = vMax; hInfo.nMax = hMax;
1637 vInfo.nPos = vPos; hInfo.nPos = hPos;
1638 vInfo.fMask = hInfo.fMask = SIF_RANGE | SIF_POS;
1640 SCROLL_SetScrollInfo( wndPtr->hwndSelf, SB_VERT, &vInfo, &vA );
1641 SCROLL_SetScrollInfo( wndPtr->hwndSelf, SB_HORZ, &hInfo, &hA );
1643 if( !SCROLL_ShowScrollBar( wndPtr->hwndSelf, SB_BOTH,
1644 (hA & SA_SSI_SHOW),(vA & SA_SSI_SHOW) ) )
1646 /* SetWindowPos() wasn't called, just redraw the scrollbars if needed */
1647 if( vA & SA_SSI_REFRESH )
1648 SCROLL_RefreshScrollBar( wndPtr->hwndSelf, SB_VERT, FALSE, TRUE );
1650 if( hA & SA_SSI_REFRESH )
1651 SCROLL_RefreshScrollBar( wndPtr->hwndSelf, SB_HORZ, FALSE, TRUE );
1653 return 0;
1657 /*************************************************************************
1658 * GetScrollRange16 (USER.65)
1660 BOOL16 WINAPI GetScrollRange16( HWND16 hwnd, INT16 nBar,
1661 LPINT16 lpMin, LPINT16 lpMax)
1663 INT min, max;
1664 BOOL16 ret = GetScrollRange( hwnd, nBar, &min, &max );
1665 if (lpMin) *lpMin = min;
1666 if (lpMax) *lpMax = max;
1667 return ret;
1671 /*************************************************************************
1672 * GetScrollRange (USER32.286)
1674 * RETURNS STD
1676 BOOL WINAPI GetScrollRange(
1677 HWND hwnd, /* [I] Handle of window */
1678 INT nBar, /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */
1679 LPINT lpMin, /* [O] Where to store minimum value */
1680 LPINT lpMax /* [O] Where to store maximum value */)
1682 SCROLLBAR_INFO *infoPtr;
1684 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar )))
1686 if (lpMin) lpMin = 0;
1687 if (lpMax) lpMax = 0;
1688 return FALSE;
1690 if (lpMin) *lpMin = infoPtr->MinVal;
1691 if (lpMax) *lpMax = infoPtr->MaxVal;
1692 return TRUE;
1696 /*************************************************************************
1697 * SCROLL_ShowScrollBar()
1699 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1701 BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar,
1702 BOOL fShowH, BOOL fShowV )
1704 WND *wndPtr = WIN_FindWndPtr( hwnd );
1705 BOOL retvalue = FALSE;
1707 if (!wndPtr) return FALSE;
1708 TRACE("hwnd=%04x bar=%d horz=%d, vert=%d\n",
1709 hwnd, nBar, fShowH, fShowV );
1711 switch(nBar)
1713 case SB_CTL:
1714 ShowWindow( hwnd, fShowH ? SW_SHOW : SW_HIDE );
1715 retvalue = TRUE;
1716 goto END;
1718 case SB_BOTH:
1719 case SB_HORZ:
1720 if (fShowH)
1722 fShowH = !(wndPtr->dwStyle & WS_HSCROLL);
1723 wndPtr->dwStyle |= WS_HSCROLL;
1725 else /* hide it */
1727 fShowH = (wndPtr->dwStyle & WS_HSCROLL);
1728 wndPtr->dwStyle &= ~WS_HSCROLL;
1730 if( nBar == SB_HORZ ) {
1731 fShowV = FALSE;
1732 break;
1734 /* fall through */
1736 case SB_VERT:
1737 if (fShowV)
1739 fShowV = !(wndPtr->dwStyle & WS_VSCROLL);
1740 wndPtr->dwStyle |= WS_VSCROLL;
1742 else /* hide it */
1744 fShowV = (wndPtr->dwStyle & WS_VSCROLL);
1745 wndPtr->dwStyle &= ~WS_VSCROLL;
1747 if ( nBar == SB_VERT )
1748 fShowH = FALSE;
1749 break;
1751 default:
1752 retvalue = FALSE; /* Nothing to do! */
1753 goto END;
1756 if( fShowH || fShowV ) /* frame has been changed, let the window redraw itself */
1758 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
1759 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
1760 retvalue = TRUE;
1761 goto END;
1764 retvalue = FALSE; /* no frame changes */
1765 END:
1766 WIN_ReleaseWndPtr(wndPtr);
1767 return retvalue;
1771 /*************************************************************************
1772 * ShowScrollBar16 (USER.267)
1774 void WINAPI ShowScrollBar16( HWND16 hwnd, INT16 nBar, BOOL16 fShow )
1776 SCROLL_ShowScrollBar( hwnd, nBar, (nBar == SB_VERT) ? 0 : fShow,
1777 (nBar == SB_HORZ) ? 0 : fShow );
1781 /*************************************************************************
1782 * ShowScrollBar (USER32.532)
1784 * RETURNS STD
1786 BOOL WINAPI ShowScrollBar(
1787 HWND hwnd, /* [I] Handle of window whose scrollbar(s) will be affected */
1788 INT nBar, /* [I] One of SB_HORZ, SB_VERT, SB_BOTH or SB_CTL */
1789 BOOL fShow /* [I] TRUE = show, FALSE = hide */)
1791 SCROLL_ShowScrollBar( hwnd, nBar, (nBar == SB_VERT) ? 0 : fShow,
1792 (nBar == SB_HORZ) ? 0 : fShow );
1793 return TRUE;
1797 /*************************************************************************
1798 * EnableScrollBar16 (USER.482)
1800 BOOL16 WINAPI EnableScrollBar16( HWND16 hwnd, INT16 nBar, UINT16 flags )
1802 return EnableScrollBar( hwnd, nBar, flags );
1806 /*************************************************************************
1807 * EnableScrollBar (USER32.171)
1809 BOOL WINAPI EnableScrollBar( HWND hwnd, INT nBar, UINT flags )
1811 BOOL bFineWithMe;
1812 SCROLLBAR_INFO *infoPtr;
1814 TRACE("%04x %d %d\n", hwnd, nBar, flags );
1816 flags &= ESB_DISABLE_BOTH;
1818 if (nBar == SB_BOTH)
1820 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, SB_VERT ))) return FALSE;
1821 if (!(bFineWithMe = (infoPtr->flags == flags)) )
1823 infoPtr->flags = flags;
1824 SCROLL_RefreshScrollBar( hwnd, SB_VERT, TRUE, TRUE );
1826 nBar = SB_HORZ;
1828 else
1829 bFineWithMe = TRUE;
1831 if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return FALSE;
1832 if (bFineWithMe && infoPtr->flags == flags) return FALSE;
1833 infoPtr->flags = flags;
1835 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
1836 return TRUE;