4 * Copyright 1993 Martin Ayotte
5 * Copyright 1994, 1996 Alexandre Julliard
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 * This code was audited for completeness against the documented features
24 * of Comctl32.dll version 6.0 on Oct. 8, 2004, by Dimitrie O. Paun.
26 * Unless otherwise noted, we believe this code to be complete, as per
27 * the specification mentioned above.
28 * If you discover missing features, or bugs, please note them below.
38 #include "wine/debug.h"
39 #include "user_private.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(scroll);
43 /* data for a single scroll bar */
46 INT curVal; /* Current scroll-bar value */
47 INT minVal; /* Minimum scroll-bar value */
48 INT maxVal; /* Maximum scroll-bar value */
49 INT page; /* Page size of scroll bar (Win32) */
50 UINT flags; /* EnableScrollBar flags */
51 } SCROLLBAR_INFO, *LPSCROLLBAR_INFO;
53 /* data for window that has (one or two) scroll bars */
58 } WINSCROLLBAR_INFO, *LPWINSCROLLBAR_INFO;
60 /* Minimum size of the rectangle between the arrows */
61 #define SCROLL_MIN_RECT 4
63 /* Minimum size of the thumb in pixels */
64 #define SCROLL_MIN_THUMB 6
66 /* Overlap between arrows and thumb */
67 #define SCROLL_ARROW_THUMB_OVERLAP 0
69 /* Delay (in ms) before first repetition when holding the button down */
70 #define SCROLL_FIRST_DELAY 200
72 /* Delay (in ms) between scroll repetitions */
73 #define SCROLL_REPEAT_DELAY 50
76 #define SCROLL_TIMER 0
78 /* Scroll-bar hit testing */
81 SCROLL_NOWHERE, /* Outside the scroll bar */
82 SCROLL_TOP_ARROW, /* Top or left arrow */
83 SCROLL_TOP_RECT, /* Rectangle between the top arrow and the thumb */
84 SCROLL_THUMB, /* Thumb rectangle */
85 SCROLL_BOTTOM_RECT, /* Rectangle between the thumb and the bottom arrow */
86 SCROLL_BOTTOM_ARROW /* Bottom or right arrow */
89 /* What to do after SCROLL_SetScrollInfo() */
90 #define SA_SSI_HIDE 0x0001
91 #define SA_SSI_SHOW 0x0002
92 #define SA_SSI_REFRESH 0x0004
93 #define SA_SSI_REPAINT_ARROWS 0x0008
95 /* Thumb-tracking info */
96 static HWND SCROLL_TrackingWin = 0;
97 static INT SCROLL_TrackingBar = 0;
98 static INT SCROLL_TrackingPos = 0;
99 static INT SCROLL_TrackingVal = 0;
100 /* Hit test code of the last button-down event */
101 static enum SCROLL_HITTEST SCROLL_trackHitTest;
102 static BOOL SCROLL_trackVertical;
104 /* Is the moving thumb being displayed? */
105 static BOOL SCROLL_MovingThumb = FALSE;
107 /* Local functions */
108 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar,
109 BOOL fShowH, BOOL fShowV );
110 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar,
111 const SCROLLINFO *info, BOOL bRedraw );
112 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
113 RECT *rect, INT arrowSize,
114 INT thumbSize, INT thumbPos,
115 UINT flags, BOOL vertical,
116 BOOL top_selected, BOOL bottom_selected );
119 /*********************************************************************
120 * scrollbar class descriptor
122 static const WCHAR scrollbarW[] = {'S','c','r','o','l','l','B','a','r',0};
123 const struct builtin_class_descr SCROLL_builtin_class =
125 scrollbarW, /* name */
126 CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC, /* style */
128 BUILTIN_WINPROC(WINPROC_SCROLLBAR), /* procW */
129 sizeof(SCROLLBAR_INFO), /* extra */
130 IDC_ARROW, /* cursor */
134 /***********************************************************************
135 * SCROLL_ScrollInfoValid
137 * Determine if the supplied SCROLLINFO struct is valid.
138 * info [in] The SCROLLINFO struct to be tested
140 static inline BOOL SCROLL_ScrollInfoValid( LPCSCROLLINFO info )
142 return !(info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)
143 || (info->cbSize != sizeof(*info)
144 && info->cbSize != sizeof(*info) - sizeof(info->nTrackPos)));
148 /***********************************************************************
149 * SCROLL_GetInternalInfo
151 * Returns pointer to internal SCROLLBAR_INFO structure for nBar
152 * or NULL if failed (f.i. scroll bar does not exist yet)
153 * If alloc is TRUE and the struct does not exist yet, create it.
155 static SCROLLBAR_INFO *SCROLL_GetInternalInfo( HWND hwnd, INT nBar, BOOL alloc )
157 SCROLLBAR_INFO *infoPtr = NULL;
158 WND *wndPtr = WIN_GetPtr( hwnd );
160 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return NULL;
164 if (wndPtr->pScroll) infoPtr = &((LPWINSCROLLBAR_INFO)wndPtr->pScroll)->horz;
167 if (wndPtr->pScroll) infoPtr = &((LPWINSCROLLBAR_INFO)wndPtr->pScroll)->vert;
170 infoPtr = (SCROLLBAR_INFO *)wndPtr->wExtra;
173 WARN("with SB_BOTH\n");
177 if (!infoPtr && alloc)
179 WINSCROLLBAR_INFO *winInfoPtr;
181 if (nBar != SB_HORZ && nBar != SB_VERT)
182 WARN("Cannot initialize nBar=%d\n",nBar);
183 else if ((winInfoPtr = HeapAlloc( GetProcessHeap(), 0, sizeof(WINSCROLLBAR_INFO) )))
185 /* Set default values */
186 winInfoPtr->horz.minVal = 0;
187 winInfoPtr->horz.curVal = 0;
188 winInfoPtr->horz.page = 0;
189 /* From MSDN and our own tests:
190 * max for a standard scroll bar is 100 by default. */
191 winInfoPtr->horz.maxVal = 100;
192 winInfoPtr->horz.flags = ESB_ENABLE_BOTH;
193 winInfoPtr->vert = winInfoPtr->horz;
194 wndPtr->pScroll = winInfoPtr;
195 infoPtr = nBar == SB_HORZ ? &winInfoPtr->horz : &winInfoPtr->vert;
198 WIN_ReleasePtr( wndPtr );
203 /***********************************************************************
204 * SCROLL_GetScrollBarRect
206 * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
207 * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
208 * 'arrowSize' returns the width or height of an arrow (depending on
209 * the orientation of the scrollbar), 'thumbSize' returns the size of
210 * the thumb, and 'thumbPos' returns the position of the thumb
211 * relative to the left or to the top.
212 * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
214 static BOOL SCROLL_GetScrollBarRect( HWND hwnd, INT nBar, RECT *lprect,
215 INT *arrowSize, INT *thumbSize,
220 WND *wndPtr = WIN_GetPtr( hwnd );
222 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
227 lprect->left = wndPtr->rectClient.left - wndPtr->rectWindow.left;
228 lprect->top = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
229 lprect->right = wndPtr->rectClient.right - wndPtr->rectWindow.left;
230 lprect->bottom = lprect->top + GetSystemMetrics(SM_CYHSCROLL);
231 if(wndPtr->dwStyle & WS_VSCROLL)
237 if((wndPtr->dwExStyle & WS_EX_LEFTSCROLLBAR) != 0)
238 lprect->left = wndPtr->rectClient.left - wndPtr->rectWindow.left - GetSystemMetrics(SM_CXVSCROLL);
240 lprect->left = wndPtr->rectClient.right - wndPtr->rectWindow.left;
241 lprect->top = wndPtr->rectClient.top - wndPtr->rectWindow.top;
242 lprect->right = lprect->left + GetSystemMetrics(SM_CXVSCROLL);
243 lprect->bottom = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
244 if(wndPtr->dwStyle & WS_HSCROLL)
250 GetClientRect( hwnd, lprect );
251 vertical = ((wndPtr->dwStyle & SBS_VERT) != 0);
255 WIN_ReleasePtr( wndPtr );
259 if (vertical) pixels = lprect->bottom - lprect->top;
260 else pixels = lprect->right - lprect->left;
262 if (pixels <= 2*GetSystemMetrics(SM_CXVSCROLL) + SCROLL_MIN_RECT)
264 if (pixels > SCROLL_MIN_RECT)
265 *arrowSize = (pixels - SCROLL_MIN_RECT) / 2;
268 *thumbPos = *thumbSize = 0;
272 SCROLLBAR_INFO *info = SCROLL_GetInternalInfo( hwnd, nBar, FALSE );
275 WARN("called for missing scroll bar\n");
276 WIN_ReleasePtr( wndPtr );
279 *arrowSize = GetSystemMetrics(SM_CXVSCROLL);
280 pixels -= (2 * (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP));
284 *thumbSize = MulDiv(pixels,info->page,(info->maxVal-info->minVal+1));
285 if (*thumbSize < SCROLL_MIN_THUMB) *thumbSize = SCROLL_MIN_THUMB;
287 else *thumbSize = GetSystemMetrics(SM_CXVSCROLL);
289 if (((pixels -= *thumbSize ) < 0) ||
290 ((info->flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH))
292 /* Rectangle too small or scrollbar disabled -> no thumb */
293 *thumbPos = *thumbSize = 0;
297 INT max = info->maxVal - max( info->page-1, 0 );
298 if (info->minVal >= max)
299 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
301 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP
302 + MulDiv(pixels, (info->curVal-info->minVal),(max - info->minVal));
305 WIN_ReleasePtr( wndPtr );
310 /***********************************************************************
313 * Compute the current scroll position based on the thumb position in pixels
314 * from the top of the scroll-bar.
316 static UINT SCROLL_GetThumbVal( SCROLLBAR_INFO *infoPtr, RECT *rect,
317 BOOL vertical, INT pos )
320 INT pixels = vertical ? rect->bottom-rect->top : rect->right-rect->left;
322 if ((pixels -= 2*(GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP)) <= 0)
323 return infoPtr->minVal;
327 thumbSize = MulDiv(pixels,infoPtr->page,(infoPtr->maxVal-infoPtr->minVal+1));
328 if (thumbSize < SCROLL_MIN_THUMB) thumbSize = SCROLL_MIN_THUMB;
330 else thumbSize = GetSystemMetrics(SM_CXVSCROLL);
332 if ((pixels -= thumbSize) <= 0) return infoPtr->minVal;
334 pos = max( 0, pos - (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP) );
335 if (pos > pixels) pos = pixels;
337 if (!infoPtr->page) pos *= infoPtr->maxVal - infoPtr->minVal;
338 else pos *= infoPtr->maxVal - infoPtr->minVal - infoPtr->page + 1;
339 return infoPtr->minVal + ((pos + pixels / 2) / pixels);
342 /***********************************************************************
345 static BOOL SCROLL_PtInRectEx( LPRECT lpRect, POINT pt, BOOL vertical )
350 /* Pad hit rect to allow mouse to be dragged outside of scrollbar and
351 * still be considered in the scrollbar. */
354 scrollbarWidth = lpRect->right - lpRect->left;
355 rect.left -= scrollbarWidth*8;
356 rect.right += scrollbarWidth*8;
357 rect.top -= scrollbarWidth*2;
358 rect.bottom += scrollbarWidth*2;
362 scrollbarWidth = lpRect->bottom - lpRect->top;
363 rect.left -= scrollbarWidth*2;
364 rect.right += scrollbarWidth*2;
365 rect.top -= scrollbarWidth*8;
366 rect.bottom += scrollbarWidth*8;
368 return PtInRect( &rect, pt );
371 /***********************************************************************
374 static POINT SCROLL_ClipPos( LPRECT lpRect, POINT pt )
376 if( pt.x < lpRect->left )
379 if( pt.x > lpRect->right )
380 pt.x = lpRect->right;
382 if( pt.y < lpRect->top )
385 if( pt.y > lpRect->bottom )
386 pt.y = lpRect->bottom;
392 /***********************************************************************
395 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
397 static enum SCROLL_HITTEST SCROLL_HitTest( HWND hwnd, INT nBar,
398 POINT pt, BOOL bDragging )
400 INT arrowSize, thumbSize, thumbPos;
403 BOOL vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
404 &arrowSize, &thumbSize, &thumbPos );
406 if ( (bDragging && !SCROLL_PtInRectEx( &rect, pt, vertical )) ||
407 (!PtInRect( &rect, pt )) ) return SCROLL_NOWHERE;
411 if (pt.y < rect.top + arrowSize) return SCROLL_TOP_ARROW;
412 if (pt.y >= rect.bottom - arrowSize) return SCROLL_BOTTOM_ARROW;
413 if (!thumbPos) return SCROLL_TOP_RECT;
415 if (pt.y < thumbPos) return SCROLL_TOP_RECT;
416 if (pt.y >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
418 else /* horizontal */
420 if (pt.x < rect.left + arrowSize) return SCROLL_TOP_ARROW;
421 if (pt.x >= rect.right - arrowSize) return SCROLL_BOTTOM_ARROW;
422 if (!thumbPos) return SCROLL_TOP_RECT;
424 if (pt.x < thumbPos) return SCROLL_TOP_RECT;
425 if (pt.x >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
431 /***********************************************************************
434 * Draw the scroll bar arrows.
436 static void SCROLL_DrawArrows( HDC hdc, SCROLLBAR_INFO *infoPtr,
437 RECT *rect, INT arrowSize, BOOL vertical,
438 BOOL top_pressed, BOOL bottom_pressed )
444 r.bottom = r.top + arrowSize;
446 r.right = r.left + arrowSize;
448 DrawFrameControl( hdc, &r, DFC_SCROLL,
449 (vertical ? DFCS_SCROLLUP : DFCS_SCROLLLEFT)
450 | (top_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
451 | (infoPtr->flags&ESB_DISABLE_LTUP ? DFCS_INACTIVE : 0 ) );
455 r.top = r.bottom-arrowSize;
457 r.left = r.right-arrowSize;
459 DrawFrameControl( hdc, &r, DFC_SCROLL,
460 (vertical ? DFCS_SCROLLDOWN : DFCS_SCROLLRIGHT)
461 | (bottom_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
462 | (infoPtr->flags&ESB_DISABLE_RTDN ? DFCS_INACTIVE : 0) );
465 static void SCROLL_DrawMovingThumb( HDC hdc, RECT *rect, BOOL vertical,
466 INT arrowSize, INT thumbSize )
468 INT pos = SCROLL_TrackingPos;
472 max_size = rect->bottom - rect->top;
474 max_size = rect->right - rect->left;
476 max_size -= (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) + thumbSize;
478 if( pos < (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) )
479 pos = (arrowSize-SCROLL_ARROW_THUMB_OVERLAP);
480 else if( pos > max_size )
483 SCROLL_DrawInterior_9x( SCROLL_TrackingWin, hdc, SCROLL_TrackingBar,
484 rect, arrowSize, thumbSize, pos,
485 0, vertical, FALSE, FALSE );
487 SCROLL_MovingThumb = !SCROLL_MovingThumb;
490 /***********************************************************************
491 * SCROLL_DrawInterior
493 * Draw the scroll bar interior (everything except the arrows).
495 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar,
496 RECT *rect, INT arrowSize,
497 INT thumbSize, INT thumbPos,
498 UINT flags, BOOL vertical,
499 BOOL top_selected, BOOL bottom_selected )
503 HBRUSH hSaveBrush,hBrush;
505 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
506 * The window-owned scrollbars need to call DEFWND_ControlColor
507 * to correctly setup default scrollbar colors
511 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
512 (WPARAM)hdc,(LPARAM)hwnd);
516 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
519 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
520 hSaveBrush = SelectObject( hdc, hBrush );
522 /* Calculate the scroll rectangle */
526 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
527 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
531 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
532 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
535 /* Draw the scroll rectangles and thumb */
536 if (!thumbPos) /* No thumb to draw */
538 PatBlt( hdc, r.left, r.top,
539 r.right - r.left, r.bottom - r.top,
542 /* cleanup and return */
543 SelectObject( hdc, hSavePen );
544 SelectObject( hdc, hSaveBrush );
550 PatBlt( hdc, r.left, r.top,
552 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
553 top_selected ? 0x0f0000 : PATCOPY );
554 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
555 PatBlt( hdc, r.left, r.top + thumbSize,
557 r.bottom - r.top - thumbSize,
558 bottom_selected ? 0x0f0000 : PATCOPY );
559 r.bottom = r.top + thumbSize;
561 else /* horizontal */
563 PatBlt( hdc, r.left, r.top,
564 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
566 top_selected ? 0x0f0000 : PATCOPY );
567 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
568 PatBlt( hdc, r.left + thumbSize, r.top,
569 r.right - r.left - thumbSize,
571 bottom_selected ? 0x0f0000 : PATCOPY );
572 r.right = r.left + thumbSize;
576 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT | BF_MIDDLE );
579 SelectObject( hdc, hSavePen );
580 SelectObject( hdc, hSaveBrush );
584 static void SCROLL_DrawInterior( HWND hwnd, HDC hdc, INT nBar,
585 RECT *rect, INT arrowSize,
586 INT thumbSize, INT thumbPos,
587 UINT flags, BOOL vertical,
588 BOOL top_selected, BOOL bottom_selected )
592 HBRUSH hSaveBrush,hBrush;
593 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
595 if (Save_SCROLL_MovingThumb &&
596 (SCROLL_TrackingWin == hwnd) &&
597 (SCROLL_TrackingBar == nBar))
598 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
600 /* Select the correct brush and pen */
602 /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
603 * The window-owned scrollbars need to call DEFWND_ControlColor
604 * to correctly setup default scrollbar colors
606 if (nBar == SB_CTL) {
607 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
608 (WPARAM)hdc,(LPARAM)hwnd);
610 hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
612 hSavePen = SelectObject( hdc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
613 hSaveBrush = SelectObject( hdc, hBrush );
615 /* Calculate the scroll rectangle */
620 r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
621 r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
625 r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
626 r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
629 /* Draw the scroll bar frame */
631 /* Draw the scroll rectangles and thumb */
633 if (!thumbPos) /* No thumb to draw */
635 PatBlt( hdc, r.left, r.top, r.right - r.left, r.bottom - r.top, PATCOPY );
637 /* cleanup and return */
638 SelectObject( hdc, hSavePen );
639 SelectObject( hdc, hSaveBrush );
645 PatBlt( hdc, r.left, r.top, r.right - r.left,
646 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
647 top_selected ? 0x0f0000 : PATCOPY );
648 r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
649 PatBlt( hdc, r.left, r.top + thumbSize, r.right - r.left,
650 r.bottom - r.top - thumbSize,
651 bottom_selected ? 0x0f0000 : PATCOPY );
652 r.bottom = r.top + thumbSize;
654 else /* horizontal */
656 PatBlt( hdc, r.left, r.top,
657 thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
658 r.bottom - r.top, top_selected ? 0x0f0000 : PATCOPY );
659 r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
660 PatBlt( hdc, r.left + thumbSize, r.top, r.right - r.left - thumbSize,
661 r.bottom - r.top, bottom_selected ? 0x0f0000 : PATCOPY );
662 r.right = r.left + thumbSize;
667 SelectObject( hdc, GetSysColorBrush(COLOR_BTNFACE) );
668 Rectangle( hdc, r.left+1, r.top+1, r.right-1, r.bottom-1 );
669 DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT );
671 if (Save_SCROLL_MovingThumb &&
672 (SCROLL_TrackingWin == hwnd) &&
673 (SCROLL_TrackingBar == nBar))
674 SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
677 SelectObject( hdc, hSavePen );
678 SelectObject( hdc, hSaveBrush );
682 /***********************************************************************
683 * SCROLL_DrawScrollBar
685 * Redraw the whole scrollbar.
687 void SCROLL_DrawScrollBar( HWND hwnd, HDC hdc, INT nBar,
688 BOOL arrows, BOOL interior )
690 INT arrowSize, thumbSize, thumbPos;
693 SCROLLBAR_INFO *infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, TRUE );
694 BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
695 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
697 if (!(hwnd = WIN_GetFullHandle( hwnd ))) return;
700 ((nBar == SB_VERT) && !(style & WS_VSCROLL)) ||
701 ((nBar == SB_HORZ) && !(style & WS_HSCROLL))) return;
702 if (!WIN_IsWindowDrawable( hwnd, FALSE )) return;
704 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
705 &arrowSize, &thumbSize, &thumbPos );
707 /* do not draw if the scrollbar rectangle is empty */
708 if(IsRectEmpty(&rect)) return;
710 if (Save_SCROLL_MovingThumb &&
711 (SCROLL_TrackingWin == hwnd) &&
712 (SCROLL_TrackingBar == nBar))
713 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
715 /* Draw the arrows */
717 if (arrows && arrowSize)
719 if( vertical == SCROLL_trackVertical && GetCapture() == hwnd )
720 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
721 (SCROLL_trackHitTest == SCROLL_TOP_ARROW),
722 (SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW) );
724 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
728 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
729 thumbPos, infoPtr->flags, vertical, FALSE, FALSE );
731 if (Save_SCROLL_MovingThumb &&
732 (SCROLL_TrackingWin == hwnd) &&
733 (SCROLL_TrackingBar == nBar))
734 SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
736 /* if scroll bar has focus, reposition the caret */
737 if(hwnd==GetFocus() && (nBar==SB_CTL))
741 SetCaretPos(thumbPos+1, rect.top+1);
745 SetCaretPos(rect.top+1, thumbPos+1);
750 /***********************************************************************
751 * SCROLL_DrawSizeGrip
753 * Draw the size grip.
755 static void SCROLL_DrawSizeGrip( HWND hwnd, HDC hdc)
759 GetClientRect( hwnd, &rc );
760 FillRect( hdc, &rc, GetSysColorBrush(COLOR_SCROLLBAR) );
761 rc.left = max( rc.left, rc.right - GetSystemMetrics(SM_CXVSCROLL) - 1 );
762 rc.top = max( rc.top, rc.bottom - GetSystemMetrics(SM_CYHSCROLL) - 1 );
763 DrawFrameControl( hdc, &rc, DFC_SCROLL, DFCS_SCROLLSIZEGRIP );
767 /***********************************************************************
768 * SCROLL_RefreshScrollBar
770 * Repaint the scroll bar interior after a SetScrollRange() or
771 * SetScrollPos() call.
773 static void SCROLL_RefreshScrollBar( HWND hwnd, INT nBar,
774 BOOL arrows, BOOL interior )
776 HDC hdc = GetDCEx( hwnd, 0,
777 DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW) );
780 SCROLL_DrawScrollBar( hwnd, hdc, nBar, arrows, interior );
781 ReleaseDC( hwnd, hdc );
785 /***********************************************************************
786 * SCROLL_HandleKbdEvent
788 * Handle a keyboard event (only for SB_CTL scrollbars with focus).
791 * hwnd [I] Handle of window with scrollbar(s)
792 * wParam [I] Variable input including enable state
793 * lParam [I] Variable input including input point
795 static void SCROLL_HandleKbdEvent(HWND hwnd, WPARAM wParam, LPARAM lParam)
797 TRACE("hwnd=%p wParam=%ld lParam=%ld\n", hwnd, wParam, lParam);
799 /* hide caret on first KEYDOWN to prevent flicker */
800 if ((lParam & PFD_DOUBLEBUFFER_DONTCARE) == 0)
805 case VK_PRIOR: wParam = SB_PAGEUP; break;
806 case VK_NEXT: wParam = SB_PAGEDOWN; break;
807 case VK_HOME: wParam = SB_TOP; break;
808 case VK_END: wParam = SB_BOTTOM; break;
809 case VK_UP: wParam = SB_LINEUP; break;
810 case VK_DOWN: wParam = SB_LINEDOWN; break;
811 case VK_LEFT: wParam = SB_LINEUP; break;
812 case VK_RIGHT: wParam = SB_LINEDOWN; break;
815 SendMessageW(GetParent(hwnd),
816 ((GetWindowLongW( hwnd, GWL_STYLE ) & SBS_VERT) ?
817 WM_VSCROLL : WM_HSCROLL), wParam, (LPARAM)hwnd);
821 /***********************************************************************
822 * SCROLL_HandleScrollEvent
824 * Handle a mouse or timer event for the scrollbar.
825 * 'pt' is the location of the mouse event in client (for SB_CTL) or
826 * windows coordinates.
828 static void SCROLL_HandleScrollEvent( HWND hwnd, INT nBar, UINT msg, POINT pt)
830 /* Previous mouse position for timer events */
832 /* Thumb position when tracking started. */
833 static UINT trackThumbPos;
834 /* Position in the scroll-bar of the last button-down event. */
835 static INT lastClickPos;
836 /* Position in the scroll-bar of the last mouse event. */
837 static INT lastMousePos;
839 enum SCROLL_HITTEST hittest;
840 HWND hwndOwner, hwndCtl;
842 INT arrowSize, thumbSize, thumbPos;
846 SCROLLBAR_INFO *infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, FALSE );
847 if (!infoPtr) return;
848 if ((SCROLL_trackHitTest == SCROLL_NOWHERE) && (msg != WM_LBUTTONDOWN))
851 if (nBar == SB_CTL && (GetWindowLongW( hwnd, GWL_STYLE ) & (SBS_SIZEGRIP | SBS_SIZEBOX)))
855 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
856 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
859 SCROLL_trackHitTest = hittest = SCROLL_THUMB;
862 GetClientRect(GetParent(GetParent(hwnd)),&rect);
867 SCROLL_trackHitTest = hittest = SCROLL_NOWHERE;
868 if (hwnd==GetFocus()) ShowCaret(hwnd);
877 hdc = GetDCEx( hwnd, 0, DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW));
878 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
879 &arrowSize, &thumbSize, &thumbPos );
880 hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd) : hwnd;
881 hwndCtl = (nBar == SB_CTL) ? hwnd : 0;
885 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
886 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
887 SCROLL_trackVertical = vertical;
888 SCROLL_trackHitTest = hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
889 lastClickPos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
890 lastMousePos = lastClickPos;
891 trackThumbPos = thumbPos;
893 if (nBar == SB_CTL && (GetWindowLongW(hwnd, GWL_STYLE) & WS_TABSTOP)) SetFocus( hwnd );
898 hittest = SCROLL_HitTest( hwnd, nBar, pt, TRUE );
903 hittest = SCROLL_NOWHERE;
905 /* if scrollbar has focus, show back caret */
906 if (hwnd==GetFocus()) ShowCaret(hwnd);
911 hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
915 return; /* Should never happen */
918 TRACE("Event: hwnd=%p bar=%d msg=%s pt=%d,%d hit=%d\n",
919 hwnd, nBar, SPY_GetMsgName(msg,hwnd), pt.x, pt.y, hittest );
921 switch(SCROLL_trackHitTest)
923 case SCROLL_NOWHERE: /* No tracking in progress */
926 case SCROLL_TOP_ARROW:
927 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
928 (hittest == SCROLL_trackHitTest), FALSE );
929 if (hittest == SCROLL_trackHitTest)
931 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
933 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
934 SB_LINEUP, (LPARAM)hwndCtl );
937 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
938 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
940 else KillSystemTimer( hwnd, SCROLL_TIMER );
943 case SCROLL_TOP_RECT:
944 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
945 thumbPos, infoPtr->flags, vertical,
946 (hittest == SCROLL_trackHitTest), FALSE );
947 if (hittest == SCROLL_trackHitTest)
949 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
951 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
952 SB_PAGEUP, (LPARAM)hwndCtl );
954 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
955 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
957 else KillSystemTimer( hwnd, SCROLL_TIMER );
961 if (msg == WM_LBUTTONDOWN)
963 SCROLL_TrackingWin = hwnd;
964 SCROLL_TrackingBar = nBar;
965 SCROLL_TrackingPos = trackThumbPos + lastMousePos - lastClickPos;
966 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
968 SCROLL_TrackingPos );
969 if (!SCROLL_MovingThumb)
970 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
972 else if (msg == WM_LBUTTONUP)
974 if (SCROLL_MovingThumb)
975 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
977 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
978 thumbPos, infoPtr->flags, vertical,
981 else /* WM_MOUSEMOVE */
985 if (!SCROLL_PtInRectEx( &rect, pt, vertical )) pos = lastClickPos;
988 pt = SCROLL_ClipPos( &rect, pt );
989 pos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
991 if ( (pos != lastMousePos) || (!SCROLL_MovingThumb) )
993 if (SCROLL_MovingThumb)
994 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
995 arrowSize, thumbSize );
997 SCROLL_TrackingPos = trackThumbPos + pos - lastClickPos;
998 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
1000 SCROLL_TrackingPos );
1001 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1002 MAKEWPARAM( SB_THUMBTRACK, SCROLL_TrackingVal),
1004 if (!SCROLL_MovingThumb)
1005 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
1006 arrowSize, thumbSize );
1011 case SCROLL_BOTTOM_RECT:
1012 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
1013 thumbPos, infoPtr->flags, vertical,
1014 FALSE, (hittest == SCROLL_trackHitTest) );
1015 if (hittest == SCROLL_trackHitTest)
1017 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1019 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1020 SB_PAGEDOWN, (LPARAM)hwndCtl );
1022 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1023 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
1025 else KillSystemTimer( hwnd, SCROLL_TIMER );
1028 case SCROLL_BOTTOM_ARROW:
1029 SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
1030 FALSE, (hittest == SCROLL_trackHitTest) );
1031 if (hittest == SCROLL_trackHitTest)
1033 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1035 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1036 SB_LINEDOWN, (LPARAM)hwndCtl );
1039 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1040 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
1042 else KillSystemTimer( hwnd, SCROLL_TIMER );
1046 if (msg == WM_LBUTTONDOWN)
1049 if (hittest == SCROLL_THUMB)
1051 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1052 trackThumbPos + lastMousePos - lastClickPos );
1053 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1054 MAKEWPARAM( SB_THUMBTRACK, val ), (LPARAM)hwndCtl );
1058 if (msg == WM_LBUTTONUP)
1060 hittest = SCROLL_trackHitTest;
1061 SCROLL_trackHitTest = SCROLL_NOWHERE; /* Terminate tracking */
1063 if (hittest == SCROLL_THUMB)
1065 UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1066 trackThumbPos + lastMousePos - lastClickPos );
1067 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1068 MAKEWPARAM( SB_THUMBPOSITION, val ), (LPARAM)hwndCtl );
1070 /* SB_ENDSCROLL doesn't report thumb position */
1071 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1072 SB_ENDSCROLL, (LPARAM)hwndCtl );
1074 /* Terminate tracking */
1075 SCROLL_TrackingWin = 0;
1078 ReleaseDC( hwnd, hdc );
1082 /***********************************************************************
1083 * SCROLL_TrackScrollBar
1085 * Track a mouse button press on a scroll-bar.
1086 * pt is in screen-coordinates for non-client scroll bars.
1088 void SCROLL_TrackScrollBar( HWND hwnd, INT scrollbar, POINT pt )
1091 INT xoffset = 0, yoffset = 0;
1093 if (scrollbar != SB_CTL)
1095 WND *wndPtr = WIN_GetPtr( hwnd );
1096 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return;
1097 xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
1098 yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
1099 WIN_ReleasePtr( wndPtr );
1100 ScreenToClient( hwnd, &pt );
1105 SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt );
1109 if (!GetMessageW( &msg, 0, 0, 0 )) break;
1110 if (CallMsgFilterW( &msg, MSGF_SCROLLBAR )) continue;
1111 if (msg.message == WM_LBUTTONUP ||
1112 msg.message == WM_MOUSEMOVE ||
1113 (msg.message == WM_SYSTIMER && msg.wParam == SCROLL_TIMER))
1115 pt.x = (short)LOWORD(msg.lParam) + xoffset;
1116 pt.y = (short)HIWORD(msg.lParam) + yoffset;
1117 SCROLL_HandleScrollEvent( hwnd, scrollbar, msg.message, pt );
1121 TranslateMessage( &msg );
1122 DispatchMessageW( &msg );
1124 if (!IsWindow( hwnd ))
1129 } while (msg.message != WM_LBUTTONUP);
1133 /***********************************************************************
1134 * SCROLL_CreateScrollBar
1136 * Create a scroll bar
1139 * hwnd [I] Handle of window with scrollbar(s)
1140 * lpCreate [I] The style and place of the scroll bar
1142 static void SCROLL_CreateScrollBar(HWND hwnd, LPCREATESTRUCTW lpCreate)
1144 LPSCROLLBAR_INFO info = SCROLL_GetInternalInfo(hwnd, SB_CTL, TRUE);
1147 TRACE("hwnd=%p lpCreate=%p\n", hwnd, lpCreate);
1149 if (lpCreate->style & WS_DISABLED)
1151 info->flags = ESB_DISABLE_BOTH;
1152 TRACE("Created WS_DISABLED scrollbar\n");
1156 if (lpCreate->style & (SBS_SIZEGRIP | SBS_SIZEBOX))
1158 if (lpCreate->style & SBS_SIZEBOXTOPLEFTALIGN)
1159 MoveWindow( hwnd, lpCreate->x, lpCreate->y, GetSystemMetrics(SM_CXVSCROLL)+1,
1160 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1161 else if(lpCreate->style & SBS_SIZEBOXBOTTOMRIGHTALIGN)
1162 MoveWindow( hwnd, lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1163 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1164 GetSystemMetrics(SM_CXVSCROLL)+1,
1165 GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1167 else if (lpCreate->style & SBS_VERT)
1169 if (lpCreate->style & SBS_LEFTALIGN)
1170 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1171 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1172 else if (lpCreate->style & SBS_RIGHTALIGN)
1174 lpCreate->x+lpCreate->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1176 GetSystemMetrics(SM_CXVSCROLL)+1, lpCreate->cy, FALSE );
1180 if (lpCreate->style & SBS_TOPALIGN)
1181 MoveWindow( hwnd, lpCreate->x, lpCreate->y,
1182 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1183 else if (lpCreate->style & SBS_BOTTOMALIGN)
1186 lpCreate->y+lpCreate->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1187 lpCreate->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1192 /*************************************************************************
1193 * SCROLL_GetScrollInfo
1195 * Internal helper for the API function
1198 * hwnd [I] Handle of window with scrollbar(s)
1199 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1200 * info [IO] fMask specifies which values to retrieve
1203 * FALSE if requested field not filled (f.i. scroll bar does not exist)
1205 static BOOL SCROLL_GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1207 LPSCROLLBAR_INFO infoPtr;
1209 /* handle invalid data structure */
1210 if (!SCROLL_ScrollInfoValid(info)
1211 || !(infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE)))
1214 /* fill in the desired scroll info structure */
1215 if (info->fMask & SIF_PAGE) info->nPage = infoPtr->page;
1216 if (info->fMask & SIF_POS) info->nPos = infoPtr->curVal;
1217 if ((info->fMask & SIF_TRACKPOS) && (info->cbSize == sizeof(*info)))
1218 info->nTrackPos = (SCROLL_TrackingWin == WIN_GetFullHandle(hwnd)) ? SCROLL_TrackingVal : infoPtr->curVal;
1219 if (info->fMask & SIF_RANGE)
1221 info->nMin = infoPtr->minVal;
1222 info->nMax = infoPtr->maxVal;
1225 TRACE("cbSize %02x fMask %04x nMin %d nMax %d nPage %u nPos %d nTrackPos %d\n",
1226 info->cbSize, info->fMask, info->nMin, info->nMax, info->nPage,
1227 info->nPos, info->nTrackPos);
1229 return (info->fMask & SIF_ALL) != 0;
1233 /*************************************************************************
1234 * SCROLL_GetScrollBarInfo
1236 * Internal helper for the API function
1239 * hwnd [I] Handle of window with scrollbar(s)
1240 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1241 * info [IO] cbSize specifies the size of the structure
1246 static BOOL SCROLL_GetScrollBarInfo(HWND hwnd, LONG idObject, LPSCROLLBARINFO info)
1248 LPSCROLLBAR_INFO infoPtr;
1251 DWORD style = GetWindowLongW(hwnd, GWL_STYLE);
1257 case OBJID_CLIENT: nBar = SB_CTL; break;
1258 case OBJID_HSCROLL: nBar = SB_HORZ; break;
1259 case OBJID_VSCROLL: nBar = SB_VERT; break;
1260 default: return FALSE;
1263 /* handle invalid data structure */
1264 if (info->cbSize != sizeof(*info))
1267 SCROLL_GetScrollBarRect(hwnd, nBar, &info->rcScrollBar, &nDummy,
1268 &info->dxyLineButton, &info->xyThumbTop);
1269 /* rcScrollBar needs to be in screen coordinates */
1270 GetWindowRect(hwnd, &rect);
1271 OffsetRect(&info->rcScrollBar, rect.left, rect.top);
1273 info->xyThumbBottom = info->xyThumbTop + info->dxyLineButton;
1275 infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, TRUE);
1279 /* Scroll bar state */
1280 info->rgstate[0] = 0;
1281 if ((nBar == SB_HORZ && !(style & WS_HSCROLL))
1282 || (nBar == SB_VERT && !(style & WS_VSCROLL)))
1283 info->rgstate[0] |= STATE_SYSTEM_INVISIBLE;
1284 if (infoPtr->minVal >= infoPtr->maxVal - max(infoPtr->page - 1, 0))
1286 if (!(info->rgstate[0] & STATE_SYSTEM_INVISIBLE))
1287 info->rgstate[0] |= STATE_SYSTEM_UNAVAILABLE;
1289 info->rgstate[0] |= STATE_SYSTEM_OFFSCREEN;
1291 if (nBar == SB_CTL && !IsWindowEnabled(hwnd))
1292 info->rgstate[0] |= STATE_SYSTEM_UNAVAILABLE;
1294 pressed = ((nBar == SB_VERT) == SCROLL_trackVertical && GetCapture() == hwnd);
1296 /* Top/left arrow button state. MSDN says top/right, but I don't believe it */
1297 info->rgstate[1] = 0;
1298 if (pressed && SCROLL_trackHitTest == SCROLL_TOP_ARROW)
1299 info->rgstate[1] |= STATE_SYSTEM_PRESSED;
1300 if (infoPtr->flags & ESB_DISABLE_LTUP)
1301 info->rgstate[1] |= STATE_SYSTEM_UNAVAILABLE;
1303 /* Page up/left region state. MSDN says up/right, but I don't believe it */
1304 info->rgstate[2] = 0;
1305 if (infoPtr->curVal == infoPtr->minVal)
1306 info->rgstate[2] |= STATE_SYSTEM_INVISIBLE;
1307 if (pressed && SCROLL_trackHitTest == SCROLL_TOP_RECT)
1308 info->rgstate[2] |= STATE_SYSTEM_PRESSED;
1311 info->rgstate[3] = 0;
1312 if (pressed && SCROLL_trackHitTest == SCROLL_THUMB)
1313 info->rgstate[3] |= STATE_SYSTEM_PRESSED;
1315 /* Page down/right region state. MSDN says down/left, but I don't believe it */
1316 info->rgstate[4] = 0;
1317 if (infoPtr->curVal >= infoPtr->maxVal - 1)
1318 info->rgstate[4] |= STATE_SYSTEM_INVISIBLE;
1319 if (pressed && SCROLL_trackHitTest == SCROLL_BOTTOM_RECT)
1320 info->rgstate[4] |= STATE_SYSTEM_PRESSED;
1322 /* Bottom/right arrow button state. MSDN says bottom/left, but I don't believe it */
1323 info->rgstate[5] = 0;
1324 if (pressed && SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW)
1325 info->rgstate[5] |= STATE_SYSTEM_PRESSED;
1326 if (infoPtr->flags & ESB_DISABLE_RTDN)
1327 info->rgstate[5] |= STATE_SYSTEM_UNAVAILABLE;
1333 /*************************************************************************
1334 * SCROLL_GetScrollPos
1336 * Internal helper for the API function
1339 * hwnd [I] Handle of window with scrollbar(s)
1340 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1342 static INT SCROLL_GetScrollPos(HWND hwnd, INT nBar)
1344 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1345 return infoPtr ? infoPtr->curVal: 0;
1349 /*************************************************************************
1350 * SCROLL_GetScrollRange
1352 * Internal helper for the API function
1355 * hwnd [I] Handle of window with scrollbar(s)
1356 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1357 * lpMin [O] Where to store minimum value
1358 * lpMax [O] Where to store maximum value
1364 static BOOL SCROLL_GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1366 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1368 if (lpMin) *lpMin = infoPtr ? infoPtr->minVal : 0;
1369 if (lpMax) *lpMax = infoPtr ? infoPtr->maxVal : 0;
1375 /*************************************************************************
1376 * SCROLL_SetScrollRange
1379 * hwnd [I] Handle of window with scrollbar(s)
1380 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1381 * lpMin [I] Minimum value
1382 * lpMax [I] Maximum value
1385 static BOOL SCROLL_SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal)
1387 LPSCROLLBAR_INFO infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, FALSE);
1389 TRACE("hwnd=%p nBar=%d min=%d max=%d\n", hwnd, nBar, minVal, maxVal);
1393 infoPtr->minVal = minVal;
1394 infoPtr->maxVal = maxVal;
1400 /***********************************************************************
1401 * ScrollBarWndProc_common
1403 LRESULT ScrollBarWndProc_common( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, BOOL unicode )
1405 if (!IsWindow( hwnd )) return 0;
1410 SCROLL_CreateScrollBar(hwnd, (LPCREATESTRUCTW)lParam);
1415 SCROLLBAR_INFO *infoPtr;
1416 if ((infoPtr = SCROLL_GetInternalInfo( hwnd, SB_CTL, FALSE )))
1418 infoPtr->flags = wParam ? ESB_ENABLE_BOTH : ESB_DISABLE_BOTH;
1419 SCROLL_RefreshScrollBar(hwnd, SB_CTL, TRUE, TRUE);
1424 case WM_LBUTTONDBLCLK:
1425 case WM_LBUTTONDOWN:
1428 pt.x = (short)LOWORD(lParam);
1429 pt.y = (short)HIWORD(lParam);
1430 SCROLL_TrackScrollBar( hwnd, SB_CTL, pt );
1438 pt.x = (short)LOWORD(lParam);
1439 pt.y = (short)HIWORD(lParam);
1440 SCROLL_HandleScrollEvent( hwnd, SB_CTL, message, pt );
1445 SCROLL_HandleKbdEvent(hwnd, wParam, lParam);
1454 /* Create a caret when a ScrollBar get focus */
1456 int arrowSize, thumbSize, thumbPos, vertical;
1457 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,
1458 &arrowSize, &thumbSize, &thumbPos );
1461 CreateCaret(hwnd, (HBITMAP)1, thumbSize-2, rect.bottom-rect.top-2);
1462 SetCaretPos(thumbPos+1, rect.top+1);
1466 CreateCaret(hwnd, (HBITMAP)1, rect.right-rect.left-2,thumbSize-2);
1467 SetCaretPos(rect.top+1, thumbPos+1);
1476 int arrowSize, thumbSize, thumbPos, vertical;
1477 vertical = SCROLL_GetScrollBarRect( hwnd, SB_CTL, &rect,&arrowSize, &thumbSize, &thumbPos );
1479 rect.left=thumbPos+1;
1480 rect.right=rect.left+thumbSize;
1484 rect.top=thumbPos+1;
1485 rect.bottom=rect.top+thumbSize;
1488 InvalidateRect(hwnd,&rect,0);
1497 return DLGC_WANTARROWS; /* Windows returns this value */
1502 HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
1503 if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEGRIP)
1505 SCROLL_DrawSizeGrip( hwnd, hdc);
1507 else if (GetWindowLongW( hwnd, GWL_STYLE ) & SBS_SIZEBOX)
1510 GetClientRect( hwnd, &rc );
1511 FillRect( hdc, &rc, GetSysColorBrush(COLOR_SCROLLBAR) );
1514 SCROLL_DrawScrollBar( hwnd, hdc, SB_CTL, TRUE, TRUE );
1515 if (!wParam) EndPaint(hwnd, &ps);
1520 return SetScrollPos( hwnd, SB_CTL, wParam, (BOOL)lParam );
1523 return SCROLL_GetScrollPos(hwnd, SB_CTL);
1525 case SBM_SETRANGEREDRAW:
1528 INT oldPos = SCROLL_GetScrollPos( hwnd, SB_CTL );
1529 SCROLL_SetScrollRange( hwnd, SB_CTL, wParam, lParam );
1530 if (message == SBM_SETRANGEREDRAW)
1531 SCROLL_RefreshScrollBar( hwnd, SB_CTL, TRUE, TRUE );
1532 if (oldPos != SCROLL_GetScrollPos( hwnd, SB_CTL )) return oldPos;
1537 return SCROLL_GetScrollRange(hwnd, SB_CTL, (LPINT)wParam, (LPINT)lParam);
1539 case SBM_ENABLE_ARROWS:
1540 return EnableScrollBar( hwnd, SB_CTL, wParam );
1542 case SBM_SETSCROLLINFO:
1543 return SCROLL_SetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam, wParam );
1545 case SBM_GETSCROLLINFO:
1546 return SCROLL_GetScrollInfo(hwnd, SB_CTL, (SCROLLINFO *)lParam);
1548 case SBM_GETSCROLLBARINFO:
1549 return SCROLL_GetScrollBarInfo(hwnd, OBJID_CLIENT, (SCROLLBARINFO *)lParam);
1558 ERR("unknown Win32 msg %04x wp=%08lx lp=%08lx\n",
1559 message, wParam, lParam );
1563 if (message >= WM_USER)
1564 WARN("unknown msg %04x wp=%04lx lp=%08lx\n",
1565 message, wParam, lParam );
1567 return DefWindowProcW( hwnd, message, wParam, lParam );
1569 return DefWindowProcA( hwnd, message, wParam, lParam );
1575 /*************************************************************************
1576 * SetScrollInfo (USER32.@)
1578 * SetScrollInfo can be used to set the position, upper bound,
1579 * lower bound, and page size of a scrollbar control.
1582 * hwnd [I] Handle of window with scrollbar(s)
1583 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1584 * info [I] Specifies what to change and new values
1585 * bRedraw [I] Should scrollbar be redrawn afterwards?
1588 * Scrollbar position
1591 * For 100 lines of text to be displayed in a window of 25 lines,
1592 * one would for instance use info->nMin=0, info->nMax=75
1593 * (corresponding to the 76 different positions of the window on
1594 * the text), and info->nPage=25.
1596 INT WINAPI SetScrollInfo(HWND hwnd, INT nBar, const SCROLLINFO *info, BOOL bRedraw)
1598 TRACE("hwnd=%p nBar=%d info=%p, bRedraw=%d\n", hwnd, nBar, info, bRedraw);
1600 /* Refer SB_CTL requests to the window */
1602 return SendMessageW(hwnd, SBM_SETSCROLLINFO, bRedraw, (LPARAM)info);
1604 return SCROLL_SetScrollInfo( hwnd, nBar, info, bRedraw );
1607 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar, LPCSCROLLINFO info, BOOL bRedraw )
1609 /* Update the scrollbar state and set action flags according to
1610 * what has to be done graphics wise. */
1612 SCROLLBAR_INFO *infoPtr;
1616 /* handle invalid data structure */
1617 if (!SCROLL_ScrollInfoValid(info)
1618 || !(infoPtr = SCROLL_GetInternalInfo(hwnd, nBar, TRUE)))
1621 if (TRACE_ON(scroll))
1623 TRACE("hwnd=%p bar=%d", hwnd, nBar);
1624 if (info->fMask & SIF_PAGE) TRACE( " page=%d", info->nPage );
1625 if (info->fMask & SIF_POS) TRACE( " pos=%d", info->nPos );
1626 if (info->fMask & SIF_RANGE) TRACE( " min=%d max=%d", info->nMin, info->nMax );
1630 /* Set the page size */
1632 if (info->fMask & SIF_PAGE)
1634 if( infoPtr->page != info->nPage )
1636 infoPtr->page = info->nPage;
1637 action |= SA_SSI_REFRESH;
1641 /* Set the scroll pos */
1643 if (info->fMask & SIF_POS)
1645 if( infoPtr->curVal != info->nPos )
1647 infoPtr->curVal = info->nPos;
1648 action |= SA_SSI_REFRESH;
1652 /* Set the scroll range */
1654 if (info->fMask & SIF_RANGE)
1656 /* Invalid range -> range is set to (0,0) */
1657 if ((info->nMin > info->nMax) ||
1658 ((UINT)(info->nMax - info->nMin) >= 0x80000000))
1660 action |= SA_SSI_REFRESH;
1661 infoPtr->minVal = 0;
1662 infoPtr->maxVal = 0;
1666 if( infoPtr->minVal != info->nMin ||
1667 infoPtr->maxVal != info->nMax )
1669 action |= SA_SSI_REFRESH;
1670 infoPtr->minVal = info->nMin;
1671 infoPtr->maxVal = info->nMax;
1676 /* Make sure the page size is valid */
1677 if (infoPtr->page < 0) infoPtr->page = 0;
1678 else if (infoPtr->page > infoPtr->maxVal - infoPtr->minVal + 1 )
1679 infoPtr->page = infoPtr->maxVal - infoPtr->minVal + 1;
1681 /* Make sure the pos is inside the range */
1683 if (infoPtr->curVal < infoPtr->minVal)
1684 infoPtr->curVal = infoPtr->minVal;
1685 else if (infoPtr->curVal > infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1686 infoPtr->curVal = infoPtr->maxVal - max( infoPtr->page-1, 0 );
1688 TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1689 infoPtr->page, infoPtr->curVal,
1690 infoPtr->minVal, infoPtr->maxVal );
1692 /* don't change the scrollbar state if SetScrollInfo
1693 * is just called with SIF_DISABLENOSCROLL
1695 if(!(info->fMask & SIF_ALL)) goto done;
1697 /* Check if the scrollbar should be hidden or disabled */
1699 if (info->fMask & (SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL))
1701 new_flags = infoPtr->flags;
1702 if (infoPtr->minVal >= infoPtr->maxVal - max( infoPtr->page-1, 0 ))
1704 /* Hide or disable scroll-bar */
1705 if (info->fMask & SIF_DISABLENOSCROLL)
1707 new_flags = ESB_DISABLE_BOTH;
1708 action |= SA_SSI_REFRESH;
1710 else if ((nBar != SB_CTL) && (action & SA_SSI_REFRESH))
1712 action = SA_SSI_HIDE;
1715 else /* Show and enable scroll-bar only if no page only changed. */
1716 if (info->fMask != SIF_PAGE)
1718 new_flags = ESB_ENABLE_BOTH;
1719 if ((nBar != SB_CTL) && ( (action & SA_SSI_REFRESH) ))
1720 action |= SA_SSI_SHOW;
1723 if (infoPtr->flags != new_flags) /* check arrow flags */
1725 infoPtr->flags = new_flags;
1726 action |= SA_SSI_REPAINT_ARROWS;
1731 if( action & SA_SSI_HIDE )
1732 SCROLL_ShowScrollBar( hwnd, nBar, FALSE, FALSE );
1735 if( action & SA_SSI_SHOW )
1736 if( SCROLL_ShowScrollBar( hwnd, nBar, TRUE, TRUE ) )
1737 return infoPtr->curVal; /* SetWindowPos() already did the painting */
1740 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
1741 else if( action & SA_SSI_REPAINT_ARROWS )
1742 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, FALSE );
1745 /* Return current position */
1746 return infoPtr->curVal;
1750 /*************************************************************************
1751 * GetScrollInfo (USER32.@)
1753 * GetScrollInfo can be used to retrieve the position, upper bound,
1754 * lower bound, and page size of a scrollbar control.
1757 * hwnd [I] Handle of window with scrollbar(s)
1758 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1759 * info [IO] fMask specifies which values to retrieve
1762 * TRUE if SCROLLINFO is filled
1763 * ( if nBar is SB_CTL, GetScrollInfo returns TRUE even if nothing
1766 BOOL WINAPI GetScrollInfo(HWND hwnd, INT nBar, LPSCROLLINFO info)
1768 TRACE("hwnd=%p nBar=%d info=%p\n", hwnd, nBar, info);
1770 /* Refer SB_CTL requests to the window */
1773 SendMessageW(hwnd, SBM_GETSCROLLINFO, 0, (LPARAM)info);
1776 return SCROLL_GetScrollInfo(hwnd, nBar, info);
1780 /*************************************************************************
1781 * GetScrollBarInfo (USER32.@)
1783 * GetScrollBarInfo can be used to retrieve information about a scrollbar
1787 * hwnd [I] Handle of window with scrollbar(s)
1788 * idObject [I] One of OBJID_CLIENT, OBJID_HSCROLL, or OBJID_VSCROLL
1789 * info [IO] cbSize specifies the size of SCROLLBARINFO
1794 BOOL WINAPI GetScrollBarInfo(HWND hwnd, LONG idObject, LPSCROLLBARINFO info)
1796 TRACE("hwnd=%p idObject=%d info=%p\n", hwnd, idObject, info);
1798 /* Refer OBJID_CLIENT requests to the window */
1799 if (idObject == OBJID_CLIENT)
1800 return SendMessageW(hwnd, SBM_GETSCROLLBARINFO, 0, (LPARAM)info);
1802 return SCROLL_GetScrollBarInfo(hwnd, idObject, info);
1806 /*************************************************************************
1807 * SetScrollPos (USER32.@)
1809 * Sets the current position of the scroll thumb.
1812 * hwnd [I] Handle of window with scrollbar(s)
1813 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1814 * nPos [I] New value
1815 * bRedraw [I] Should scrollbar be redrawn afterwards?
1818 * Success: Scrollbar position
1822 * Note the ambiguity when 0 is returned. Use GetLastError
1823 * to make sure there was an error (and to know which one).
1825 INT WINAPI SetScrollPos( HWND hwnd, INT nBar, INT nPos, BOOL bRedraw)
1828 SCROLLBAR_INFO *infoPtr;
1831 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, FALSE ))) return 0;
1832 oldPos = infoPtr->curVal;
1833 info.cbSize = sizeof(info);
1835 info.fMask = SIF_POS;
1836 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1841 /*************************************************************************
1842 * GetScrollPos (USER32.@)
1844 * Gets the current position of the scroll thumb.
1847 * hwnd [I] Handle of window with scrollbar(s)
1848 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1851 * Success: Current position
1855 * There is ambiguity when 0 is returned. Use GetLastError
1856 * to make sure there was an error (and to know which one).
1858 INT WINAPI GetScrollPos(HWND hwnd, INT nBar)
1860 TRACE("hwnd=%p nBar=%d\n", hwnd, nBar);
1862 /* Refer SB_CTL requests to the window */
1864 return SendMessageW(hwnd, SBM_GETPOS, 0, 0);
1866 return SCROLL_GetScrollPos(hwnd, nBar);
1870 /*************************************************************************
1871 * SetScrollRange (USER32.@)
1872 * The SetScrollRange function sets the minimum and maximum scroll box positions
1873 * If nMinPos and nMaxPos is the same value, the scroll bar will hide
1875 * Sets the range of the scroll bar.
1878 * hwnd [I] Handle of window with scrollbar(s)
1879 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1880 * minVal [I] New minimum value
1881 * maxVal [I] New Maximum value
1882 * bRedraw [I] Should scrollbar be redrawn afterwards?
1888 BOOL WINAPI SetScrollRange(HWND hwnd, INT nBar, INT minVal, INT maxVal, BOOL bRedraw)
1892 TRACE("hwnd=%p nBar=%d min=%d max=%d, bRedraw=%d\n", hwnd, nBar, minVal, maxVal, bRedraw);
1894 info.cbSize = sizeof(info);
1895 info.fMask = SIF_RANGE;
1898 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1903 /*************************************************************************
1904 * SCROLL_SetNCSbState
1906 * Updates both scrollbars at the same time. Used by MDI CalcChildScroll().
1908 INT SCROLL_SetNCSbState(HWND hwnd, int vMin, int vMax, int vPos,
1909 int hMin, int hMax, int hPos)
1911 SCROLLINFO vInfo, hInfo;
1913 vInfo.cbSize = hInfo.cbSize = sizeof(SCROLLINFO);
1920 vInfo.fMask = hInfo.fMask = SIF_RANGE | SIF_POS;
1922 SCROLL_SetScrollInfo( hwnd, SB_VERT, &vInfo, TRUE );
1923 SCROLL_SetScrollInfo( hwnd, SB_HORZ, &hInfo, TRUE );
1929 /*************************************************************************
1930 * GetScrollRange (USER32.@)
1932 * Gets the range of the scroll bar.
1935 * hwnd [I] Handle of window with scrollbar(s)
1936 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
1937 * lpMin [O] Where to store minimum value
1938 * lpMax [O] Where to store maximum value
1941 * TRUE if values is filled
1943 BOOL WINAPI GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
1945 TRACE("hwnd=%p nBar=%d lpMin=%p lpMax=%p\n", hwnd, nBar, lpMin, lpMax);
1947 /* Refer SB_CTL requests to the window */
1949 SendMessageW(hwnd, SBM_GETRANGE, (WPARAM)lpMin, (LPARAM)lpMax);
1951 SCROLL_GetScrollRange(hwnd, nBar, lpMin, lpMax);
1957 /*************************************************************************
1958 * SCROLL_ShowScrollBar()
1960 * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1962 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar, BOOL fShowH, BOOL fShowV )
1964 ULONG old_style, set_bits = 0, clear_bits = 0;
1966 TRACE("hwnd=%p bar=%d horz=%d, vert=%d\n", hwnd, nBar, fShowH, fShowV );
1971 ShowWindow( hwnd, fShowH ? SW_SHOW : SW_HIDE );
1976 if (fShowH) set_bits |= WS_HSCROLL;
1977 else clear_bits |= WS_HSCROLL;
1978 if( nBar == SB_HORZ ) break;
1981 if (fShowV) set_bits |= WS_VSCROLL;
1982 else clear_bits |= WS_VSCROLL;
1986 return FALSE; /* Nothing to do! */
1989 old_style = WIN_SetStyle( hwnd, set_bits, clear_bits );
1990 if ((old_style & clear_bits) != 0 || (old_style & set_bits) != set_bits)
1992 /* frame has been changed, let the window redraw itself */
1993 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
1994 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
1997 return FALSE; /* no frame changes */
2001 /*************************************************************************
2002 * ShowScrollBar (USER32.@)
2004 * Shows or hides the scroll bar.
2007 * hwnd [I] Handle of window with scrollbar(s)
2008 * nBar [I] One of SB_HORZ, SB_VERT, or SB_CTL
2009 * fShow [I] TRUE = show, FALSE = hide
2015 BOOL WINAPI ShowScrollBar(HWND hwnd, INT nBar, BOOL fShow)
2020 SCROLL_ShowScrollBar( hwnd, nBar, (nBar == SB_VERT) ? 0 : fShow,
2021 (nBar == SB_HORZ) ? 0 : fShow );
2026 /*************************************************************************
2027 * EnableScrollBar (USER32.@)
2029 * Enables or disables the scroll bars.
2031 BOOL WINAPI EnableScrollBar( HWND hwnd, UINT nBar, UINT flags )
2034 SCROLLBAR_INFO *infoPtr;
2036 flags &= ESB_DISABLE_BOTH;
2038 if (nBar == SB_BOTH)
2040 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, SB_VERT, TRUE ))) return FALSE;
2041 if (!(bFineWithMe = (infoPtr->flags == flags)) )
2043 infoPtr->flags = flags;
2044 SCROLL_RefreshScrollBar( hwnd, SB_VERT, TRUE, TRUE );
2051 if (!(infoPtr = SCROLL_GetInternalInfo( hwnd, nBar, TRUE ))) return FALSE;
2052 if (bFineWithMe && infoPtr->flags == flags) return FALSE;
2053 infoPtr->flags = flags;
2055 if (nBar == SB_CTL && (flags == ESB_DISABLE_BOTH || flags == ESB_ENABLE_BOTH))
2056 EnableWindow(hwnd, flags == ESB_ENABLE_BOTH);
2058 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );