17a84e134Smrg/***********************************************************
27a84e134Smrg
37a84e134SmrgCopyright 1987, 1988, 1994, 1998  The Open Group
47a84e134Smrg
57a84e134SmrgPermission to use, copy, modify, distribute, and sell this software and its
67a84e134Smrgdocumentation for any purpose is hereby granted without fee, provided that
77a84e134Smrgthe above copyright notice appear in all copies and that both that
87a84e134Smrgcopyright notice and this permission notice appear in supporting
97a84e134Smrgdocumentation.
107a84e134Smrg
117a84e134SmrgThe above copyright notice and this permission notice shall be included in
127a84e134Smrgall copies or substantial portions of the Software.
137a84e134Smrg
147a84e134SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
157a84e134SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
167a84e134SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
177a84e134SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
187a84e134SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
197a84e134SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
207a84e134Smrg
217a84e134SmrgExcept as contained in this notice, the name of The Open Group shall not be
227a84e134Smrgused in advertising or otherwise to promote the sale, use or other dealings
237a84e134Smrgin this Software without prior written authorization from The Open Group.
247a84e134Smrg
257a84e134Smrg
267a84e134SmrgCopyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
277a84e134Smrg
287a84e134Smrg                        All Rights Reserved
297a84e134Smrg
30421c997bSmrgPermission to use, copy, modify, and distribute this software and its
31421c997bSmrgdocumentation for any purpose and without fee is hereby granted,
327a84e134Smrgprovided that the above copyright notice appear in all copies and that
33421c997bSmrgboth that copyright notice and this permission notice appear in
347a84e134Smrgsupporting documentation, and that the name of Digital not be
357a84e134Smrgused in advertising or publicity pertaining to distribution of the
36421c997bSmrgsoftware without specific, written prior permission.
377a84e134Smrg
387a84e134SmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
397a84e134SmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
407a84e134SmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
417a84e134SmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
427a84e134SmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
437a84e134SmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
447a84e134SmrgSOFTWARE.
457a84e134Smrg
467a84e134Smrg******************************************************************/
477a84e134Smrg
487a84e134Smrg#ifdef HAVE_CONFIG_H
497a84e134Smrg#include <config.h>
507a84e134Smrg#endif
517a84e134Smrg#include <X11/IntrinsicP.h>
527a84e134Smrg#include <X11/StringDefs.h>
537a84e134Smrg#include <X11/Xmu/Drawing.h>
547a84e134Smrg#include <X11/Xaw/ScrollbarP.h>
557a84e134Smrg#include <X11/Xaw/XawInit.h>
567a84e134Smrg#include "Private.h"
577a84e134Smrg
587a84e134Smrg#define NoButton	-1
597a84e134Smrg#define PICKLENGTH(widget, x, y)					\
607a84e134Smrg(((widget)->scrollbar.orientation == XtorientHorizontal) ? (x) : (y))
617a84e134Smrg
627a84e134Smrg/*
637a84e134Smrg * Class Methods
647a84e134Smrg */
657a84e134Smrgstatic void XawScrollbarClassInitialize(void);
667a84e134Smrgstatic void XawScrollbarDestroy(Widget);
677a84e134Smrgstatic void XawScrollbarInitialize(Widget, Widget, ArgList, Cardinal*_args);
687a84e134Smrgstatic void XawScrollbarRealize(Widget, Mask*, XSetWindowAttributes*);
697a84e134Smrgstatic void XawScrollbarRedisplay(Widget, XEvent*, Region);
707a84e134Smrgstatic void XawScrollbarResize(Widget);
717a84e134Smrgstatic Boolean XawScrollbarSetValues(Widget, Widget, Widget,
727a84e134Smrg				     ArgList, Cardinal*);
737a84e134Smrg
747a84e134Smrg/*
757a84e134Smrg * Prototypes
767a84e134Smrg */
777a84e134Smrgstatic Boolean CompareEvents(XEvent*, XEvent*);
787a84e134Smrgstatic void CreateGC(Widget);
797a84e134Smrgstatic float FloatInRange(float, float, float);
807a84e134Smrgstatic float FractionLoc(ScrollbarWidget, int, int);
817a84e134Smrgstatic void ExtractPosition(XEvent*, Position*, Position*);
827a84e134Smrgstatic int InRange(int, int, int);
837a84e134Smrgstatic void FillArea(ScrollbarWidget, int, int, int);
847a84e134Smrgstatic Bool LookAhead(Widget, XEvent*);
857a84e134Smrgstatic void PaintThumb(ScrollbarWidget);
867a84e134Smrgstatic Bool PeekNotifyEvent(Display*, XEvent*, char*);
877a84e134Smrgstatic void SetDimensions(ScrollbarWidget);
887a84e134Smrg
897a84e134Smrg/*
907a84e134Smrg * Actions
917a84e134Smrg */
927a84e134Smrgstatic void EndScroll(Widget, XEvent*, String*, Cardinal*);
937a84e134Smrgstatic void MoveThumb(Widget, XEvent*, String*, Cardinal*);
947a84e134Smrgstatic void NotifyScroll(Widget, XEvent*, String*, Cardinal*);
957a84e134Smrgstatic void NotifyThumb(Widget, XEvent*, String*, Cardinal*);
967a84e134Smrgstatic void StartScroll(Widget, XEvent*, String*, Cardinal*);
977a84e134Smrg
987a84e134Smrg/*
997a84e134Smrg * Initialization
1007a84e134Smrg */
1017a84e134Smrgstatic char defaultTranslations[] =
1027a84e134Smrg"<Btn1Down>:"	"StartScroll(Forward)\n"
1037a84e134Smrg"<Btn2Down>:"	"StartScroll(Continuous) MoveThumb() NotifyThumb()\n"
1047a84e134Smrg"<Btn3Down>:"	"StartScroll(Backward)\n"
1055ec34c4cSmrg"<Btn4Down>:"	"StartScroll(Backward)\n"
1065ec34c4cSmrg"<Btn5Down>:"	"StartScroll(Forward)\n"
1077a84e134Smrg"<Btn2Motion>:"	"MoveThumb() NotifyThumb()\n"
1087a84e134Smrg"<BtnUp>:"	"NotifyScroll(Proportional) EndScroll()\n";
1097a84e134Smrg
1107a84e134Smrgstatic float floatZero = 0.0;
1117a84e134Smrg
1127a84e134Smrg#define Offset(field) XtOffsetOf(ScrollbarRec, field)
1137a84e134Smrg
1147a84e134Smrgstatic XtResource resources[] = {
1157a84e134Smrg  {
1167a84e134Smrg    XtNlength,
1177a84e134Smrg    XtCLength,
1187a84e134Smrg    XtRDimension,
1197a84e134Smrg    sizeof(Dimension),
1207a84e134Smrg    Offset(scrollbar.length),
1217a84e134Smrg    XtRImmediate,
1227a84e134Smrg    (XtPointer)1
1237a84e134Smrg  },
1247a84e134Smrg  {
1257a84e134Smrg    XtNthickness,
1267a84e134Smrg    XtCThickness,
1277a84e134Smrg    XtRDimension,
1287a84e134Smrg    sizeof(Dimension),
1297a84e134Smrg    Offset(scrollbar.thickness),
1307a84e134Smrg    XtRImmediate,
1317a84e134Smrg    (XtPointer)14
1327a84e134Smrg  },
1337a84e134Smrg  {
1347a84e134Smrg    XtNorientation,
1357a84e134Smrg    XtCOrientation,
1367a84e134Smrg    XtROrientation,
1377a84e134Smrg    sizeof(XtOrientation),
1387a84e134Smrg    Offset(scrollbar.orientation),
1397a84e134Smrg    XtRImmediate,
1407a84e134Smrg    (XtPointer)XtorientVertical
1417a84e134Smrg  },
1427a84e134Smrg  {
1437a84e134Smrg    XtNscrollProc,
1447a84e134Smrg    XtCCallback,
1457a84e134Smrg    XtRCallback,
1467a84e134Smrg    sizeof(XtPointer),
1477a84e134Smrg    Offset(scrollbar.scrollProc),
1487a84e134Smrg    XtRCallback,
1497a84e134Smrg    NULL
1507a84e134Smrg  },
1517a84e134Smrg  {
1527a84e134Smrg    XtNthumbProc,
1537a84e134Smrg    XtCCallback,
1547a84e134Smrg    XtRCallback,
1557a84e134Smrg    sizeof(XtPointer),
1567a84e134Smrg    Offset(scrollbar.thumbProc),
1577a84e134Smrg    XtRCallback,
1587a84e134Smrg    NULL
1597a84e134Smrg  },
1607a84e134Smrg  {
1617a84e134Smrg    XtNjumpProc,
1627a84e134Smrg    XtCCallback,
1637a84e134Smrg    XtRCallback,
1647a84e134Smrg    sizeof(XtPointer),
1657a84e134Smrg    Offset(scrollbar.jumpProc),
1667a84e134Smrg    XtRCallback,
1677a84e134Smrg    NULL
1687a84e134Smrg  },
1697a84e134Smrg  {
1707a84e134Smrg    XtNthumb,
1717a84e134Smrg    XtCThumb,
1727a84e134Smrg    XtRBitmap,
1737a84e134Smrg    sizeof(Pixmap),
1747a84e134Smrg    Offset(scrollbar.thumb),
1757a84e134Smrg    XtRImmediate,
1767a84e134Smrg    (XtPointer)XtUnspecifiedPixmap
1777a84e134Smrg  },
1787a84e134Smrg  {
1797a84e134Smrg    XtNforeground,
1807a84e134Smrg    XtCForeground,
1817a84e134Smrg    XtRPixel,
1827a84e134Smrg    sizeof(Pixel),
1837a84e134Smrg    Offset(scrollbar.foreground),
1847a84e134Smrg    XtRString,
1855ec34c4cSmrg    (XtPointer)XtDefaultForeground
1867a84e134Smrg  },
1877a84e134Smrg  {
1887a84e134Smrg    XtNshown,
1897a84e134Smrg    XtCShown,
1907a84e134Smrg    XtRFloat,
1917a84e134Smrg    sizeof(float),
1927a84e134Smrg    Offset(scrollbar.shown),
1937a84e134Smrg    XtRFloat,
1947a84e134Smrg    (XtPointer)&floatZero
1957a84e134Smrg  },
1967a84e134Smrg  {
1977a84e134Smrg    XtNtopOfThumb,
1987a84e134Smrg    XtCTopOfThumb,
1997a84e134Smrg    XtRFloat,
2007a84e134Smrg    sizeof(float),
2017a84e134Smrg    Offset(scrollbar.top),
2027a84e134Smrg    XtRFloat,
2037a84e134Smrg    (XtPointer)&floatZero
2047a84e134Smrg  },
2057a84e134Smrg  {
2067a84e134Smrg    XtNscrollVCursor,
2077a84e134Smrg    XtCCursor,
2087a84e134Smrg    XtRCursor,
2097a84e134Smrg    sizeof(Cursor),
2107a84e134Smrg    Offset(scrollbar.verCursor),
2117a84e134Smrg    XtRString,
2125ec34c4cSmrg    (XtPointer)"sb_v_double_arrow"
2137a84e134Smrg  },
2147a84e134Smrg  {
2157a84e134Smrg    XtNscrollHCursor,
2167a84e134Smrg    XtCCursor,
2177a84e134Smrg    XtRCursor,
2187a84e134Smrg    sizeof(Cursor),
2197a84e134Smrg    Offset(scrollbar.horCursor),
2207a84e134Smrg    XtRString,
2215ec34c4cSmrg    (XtPointer)"sb_h_double_arrow"
2227a84e134Smrg  },
2237a84e134Smrg  {
2247a84e134Smrg    XtNscrollUCursor,
2257a84e134Smrg    XtCCursor,
2267a84e134Smrg    XtRCursor,
2277a84e134Smrg    sizeof(Cursor),
2287a84e134Smrg    Offset(scrollbar.upCursor),
2297a84e134Smrg    XtRString,
2305ec34c4cSmrg    (XtPointer)"sb_up_arrow"
2317a84e134Smrg  },
2327a84e134Smrg  {
2337a84e134Smrg    XtNscrollDCursor,
2347a84e134Smrg    XtCCursor,
2357a84e134Smrg    XtRCursor,
2367a84e134Smrg    sizeof(Cursor),
2377a84e134Smrg    Offset(scrollbar.downCursor),
2387a84e134Smrg    XtRString,
2395ec34c4cSmrg    (XtPointer)"sb_down_arrow"
2407a84e134Smrg  },
2417a84e134Smrg  {
2427a84e134Smrg    XtNscrollLCursor,
2437a84e134Smrg    XtCCursor,
2447a84e134Smrg    XtRCursor,
2457a84e134Smrg    sizeof(Cursor),
2467a84e134Smrg    Offset(scrollbar.leftCursor),
2477a84e134Smrg    XtRString,
2485ec34c4cSmrg    (XtPointer)"sb_left_arrow"
2497a84e134Smrg  },
2507a84e134Smrg  {
2517a84e134Smrg    XtNscrollRCursor,
2527a84e134Smrg    XtCCursor,
2537a84e134Smrg    XtRCursor,
2547a84e134Smrg    sizeof(Cursor),
2557a84e134Smrg    Offset(scrollbar.rightCursor),
2567a84e134Smrg    XtRString,
2575ec34c4cSmrg    (XtPointer)"sb_right_arrow"
2587a84e134Smrg  },
2597a84e134Smrg  {
2607a84e134Smrg    XtNminimumThumb,
2617a84e134Smrg    XtCMinimumThumb,
2627a84e134Smrg    XtRDimension,
2637a84e134Smrg    sizeof(Dimension),
2647a84e134Smrg    Offset(scrollbar.min_thumb),
2657a84e134Smrg    XtRImmediate,
2667a84e134Smrg    (XtPointer)7
2677a84e134Smrg  },
2687a84e134Smrg};
2697a84e134Smrg#undef Offset
2707a84e134Smrg
2717a84e134Smrgstatic XtActionsRec actions[] = {
2727a84e134Smrg	{"StartScroll",		StartScroll},
2737a84e134Smrg	{"MoveThumb",		MoveThumb},
2747a84e134Smrg	{"NotifyThumb",		NotifyThumb},
2757a84e134Smrg	{"NotifyScroll",	NotifyScroll},
2767a84e134Smrg	{"EndScroll",		EndScroll},
2777a84e134Smrg};
2787a84e134Smrg
2797a84e134Smrg#define Superclass (&simpleClassRec)
2807a84e134SmrgScrollbarClassRec scrollbarClassRec = {
2817a84e134Smrg  /* core */
2827a84e134Smrg  {
2837a84e134Smrg    (WidgetClass)&simpleClassRec,	/* superclass */
2847a84e134Smrg    "Scrollbar",			/* class_name */
2857a84e134Smrg    sizeof(ScrollbarRec),		/* widget_size */
2867a84e134Smrg    XawScrollbarClassInitialize,	/* class_initialize */
2877a84e134Smrg    NULL,				/* class_part_init */
2887a84e134Smrg    False,				/* class_inited */
2897a84e134Smrg    XawScrollbarInitialize,		/* initialize */
2907a84e134Smrg    NULL,				/* initialize_hook */
2917a84e134Smrg    XawScrollbarRealize,		/* realize */
2927a84e134Smrg    actions,				/* actions */
2937a84e134Smrg    XtNumber(actions),			/* num_actions */
2947a84e134Smrg    resources,				/* resources */
2957a84e134Smrg    XtNumber(resources),		/* num_resources */
2967a84e134Smrg    NULLQUARK,				/* xrm_class */
2977a84e134Smrg    True,				/* compress_motion */
2987a84e134Smrg    True,				/* compress_exposure */
2997a84e134Smrg    True,				/* compress_enterleave */
3007a84e134Smrg    False,				/* visible_interest */
3017a84e134Smrg    XawScrollbarDestroy,		/* destroy */
3027a84e134Smrg    XawScrollbarResize,			/* resize */
3037a84e134Smrg    XawScrollbarRedisplay,		/* expose */
3047a84e134Smrg    XawScrollbarSetValues,		/* set_values */
3057a84e134Smrg    NULL,				/* set_values_hook */
3067a84e134Smrg    XtInheritSetValuesAlmost,		/* set_values_almost */
3077a84e134Smrg    NULL,				/* get_values_hook */
3087a84e134Smrg    NULL,				/* accept_focus */
3097a84e134Smrg    XtVersion,				/* version */
3107a84e134Smrg    NULL,				/* callback_private */
3117a84e134Smrg    defaultTranslations,		/* tm_table */
3127a84e134Smrg    XtInheritQueryGeometry,		/* query_geometry */
3137a84e134Smrg    XtInheritDisplayAccelerator,	/* display_accelerator */
3147a84e134Smrg    NULL,				/* extension */
3157a84e134Smrg  },
3167a84e134Smrg  /* simple */
3177a84e134Smrg  {
3187a84e134Smrg    XtInheritChangeSensitive,		/* change_sensitive */
319efbcb2bfSmrg#ifndef OLDXAW
320efbcb2bfSmrg    NULL,
321efbcb2bfSmrg#endif
3227a84e134Smrg  },
3237a84e134Smrg  /* scrollbar */
3247a84e134Smrg  {
3257a84e134Smrg    NULL,				/* extension */
3267a84e134Smrg  },
3277a84e134Smrg};
3287a84e134Smrg
3297a84e134SmrgWidgetClass scrollbarWidgetClass = (WidgetClass)&scrollbarClassRec;
3307a84e134Smrg
3317a84e134Smrg/*
3327a84e134Smrg * Implementation
3337a84e134Smrg */
3347a84e134Smrgstatic void
3357a84e134SmrgXawScrollbarClassInitialize(void)
3367a84e134Smrg{
3377a84e134Smrg    XawInitializeWidgetSet();
3387a84e134Smrg    XtAddConverter(XtRString, XtROrientation, XmuCvtStringToOrientation,
3397a84e134Smrg		   NULL, 0);
3407a84e134Smrg    XtSetTypeConverter(XtROrientation, XtRString, XmuCvtOrientationToString,
3417a84e134Smrg		       NULL, 0, XtCacheNone, NULL);
3427a84e134Smrg}
3437a84e134Smrg
3447a84e134Smrg/*
3457a84e134Smrg * Make sure the first number is within the range specified by the other
3467a84e134Smrg * two numbers.
3477a84e134Smrg */
3487a84e134Smrgstatic int
3497a84e134SmrgInRange(int num, int small, int big)
3507a84e134Smrg{
3517a84e134Smrg    return ((num < small) ? small : ((num > big) ? big : num));
3527a84e134Smrg}
3537a84e134Smrg
3547a84e134Smrg/*
3557a84e134Smrg * Same as above, but for floating numbers
3567a84e134Smrg */
3577a84e134Smrgstatic float
3587a84e134SmrgFloatInRange(float num, float small, float big)
3597a84e134Smrg{
3607a84e134Smrg    return ((num < small) ? small : ((num > big) ? big : num));
3617a84e134Smrg}
3627a84e134Smrg
3637a84e134Smrg/* Fill the area specified by top and bottom with the given pattern */
3647a84e134Smrgstatic float
3657a84e134SmrgFractionLoc(ScrollbarWidget w, int x, int y)
3667a84e134Smrg{
3677a84e134Smrg    float   result;
3687a84e134Smrg
3695ec34c4cSmrg    result = PICKLENGTH(w, (float)x / (float)XtWidth(w), (float)y / (float)XtHeight(w));
3707a84e134Smrg
3717a84e134Smrg    return (FloatInRange(result, 0.0, 1.0));
3727a84e134Smrg}
3737a84e134Smrg
3747a84e134Smrgstatic void
3757a84e134SmrgFillArea(ScrollbarWidget w, int top, int bottom, int thumb)
3767a84e134Smrg{
3777a84e134Smrg    Dimension length;
3787a84e134Smrg
3797a84e134Smrg    top = XawMax(1, top);
380421c997bSmrg    if (w->scrollbar.orientation == XtorientHorizontal)
3817a84e134Smrg    bottom = XawMin(bottom, XtWidth(w) - 1);
3827a84e134Smrg    else
3837a84e134Smrg    bottom = XawMin(bottom, XtHeight(w) - 1);
3847a84e134Smrg
3857a84e134Smrg    if (bottom <= top)
3867a84e134Smrg	return;
3877a84e134Smrg
3885ec34c4cSmrg    length = (Dimension)(bottom - top);
3897a84e134Smrg
3907a84e134Smrg    switch(thumb) {
3917a84e134Smrg	/* Fill the new Thumb location */
3927a84e134Smrg	case 1:
393421c997bSmrg	    if (w->scrollbar.orientation == XtorientHorizontal)
3947a84e134Smrg		XFillRectangle(XtDisplay(w), XtWindow(w), w->scrollbar.gc,
3955ec34c4cSmrg			       top, 1, length, (unsigned)(XtHeight(w) - 2));
3967a84e134Smrg	    else
3977a84e134Smrg		XFillRectangle(XtDisplay(w), XtWindow(w), w->scrollbar.gc,
3985ec34c4cSmrg			       1, top, (unsigned)(XtWidth(w) - 2), length);
3997a84e134Smrg	    break;
4007a84e134Smrg	/* Clear the old Thumb location */
4017a84e134Smrg	case 0:
402421c997bSmrg	    if (w->scrollbar.orientation == XtorientHorizontal)
4037a84e134Smrg		XClearArea(XtDisplay(w), XtWindow(w),
4045ec34c4cSmrg			   top, 1, length, (unsigned)(XtHeight(w) - 2), False);
4057a84e134Smrg	    else
4067a84e134Smrg		XClearArea(XtDisplay(w), XtWindow(w),
4075ec34c4cSmrg			   1, top, (unsigned)(XtWidth(w) - 2), length, False);
4087a84e134Smrg	    break;
4097a84e134Smrg    }
4107a84e134Smrg}
4117a84e134Smrg
4127a84e134Smrg
4137a84e134Smrg/* Paint the thumb in the area specified by w->top and
4147a84e134Smrg   w->shown.  The old area is erased.  The painting and
4157a84e134Smrg   erasing is done cleverly so that no flickering will occur. */
4167a84e134Smrgstatic void
4177a84e134SmrgPaintThumb(ScrollbarWidget w)
4187a84e134Smrg{
4197a84e134Smrg    Position oldtop, oldbot, newtop, newbot;
4207a84e134Smrg
4217a84e134Smrg    oldtop = w->scrollbar.topLoc;
4225ec34c4cSmrg    oldbot = (Position)(oldtop + w->scrollbar.shownLength);
4235ec34c4cSmrg    newtop = (Position)(w->scrollbar.length * w->scrollbar.top);
4245ec34c4cSmrg    newbot = (Position)(newtop + (int)(w->scrollbar.length * w->scrollbar.shown));
425421c997bSmrg    if (newbot < newtop + (int)w->scrollbar.min_thumb)
4265ec34c4cSmrg	newbot = (Position)(newtop + w->scrollbar.min_thumb);
4277a84e134Smrg    w->scrollbar.topLoc = newtop;
4285ec34c4cSmrg    w->scrollbar.shownLength = (Dimension)(newbot - newtop);
4297a84e134Smrg
4307a84e134Smrg    if (XtIsRealized((Widget)w)) {
4317a84e134Smrg	if (newtop < oldtop)
4327a84e134Smrg	    FillArea(w, newtop, XawMin(newbot, oldtop), 1);
4337a84e134Smrg	if (newtop > oldtop)
4347a84e134Smrg	    FillArea(w, oldtop, XawMin(newtop, oldbot), 0);
4357a84e134Smrg	if (newbot < oldbot)
4367a84e134Smrg	    FillArea(w, XawMax(newbot, oldtop), oldbot, 0);
4377a84e134Smrg	if (newbot > oldbot)
4387a84e134Smrg	    FillArea(w, XawMax(newtop, oldbot), newbot, 1);
4397a84e134Smrg    }
4407a84e134Smrg}
4417a84e134Smrg
4427a84e134Smrgstatic void
4437a84e134SmrgSetDimensions(ScrollbarWidget w)
4447a84e134Smrg{
4457a84e134Smrg    if (w->scrollbar.orientation == XtorientVertical) {
4467a84e134Smrg	w->scrollbar.length = XtHeight(w);
4477a84e134Smrg	w->scrollbar.thickness = XtWidth(w);
4487a84e134Smrg    }
4497a84e134Smrg    else {
4507a84e134Smrg	w->scrollbar.length = XtWidth(w);
4517a84e134Smrg	w->scrollbar.thickness = XtHeight(w);
4527a84e134Smrg    }
4537a84e134Smrg}
4547a84e134Smrg
4557a84e134Smrgstatic void
4567a84e134SmrgXawScrollbarDestroy(Widget w)
4577a84e134Smrg{
4587a84e134Smrg    ScrollbarWidget sbw = (ScrollbarWidget)w;
459421c997bSmrg
4607a84e134Smrg    XtReleaseGC(w, sbw->scrollbar.gc);
4617a84e134Smrg}
4627a84e134Smrg
4637a84e134Smrgstatic void
4647a84e134SmrgCreateGC(Widget w)
4657a84e134Smrg{
4667a84e134Smrg    ScrollbarWidget sbw = (ScrollbarWidget)w;
4677a84e134Smrg    XGCValues gcValues;
4687a84e134Smrg    XtGCMask mask;
4697a84e134Smrg    unsigned int depth = 1;
4707a84e134Smrg
4717a84e134Smrg    if (sbw->scrollbar.thumb == XtUnspecifiedPixmap)
4727a84e134Smrg	sbw->scrollbar.thumb = XmuCreateStippledPixmap(XtScreen(w),
4737a84e134Smrg						       (Pixel)1, (Pixel)0,
4747a84e134Smrg						       depth);
4757a84e134Smrg    else if (sbw->scrollbar.thumb != None) {
4767a84e134Smrg	Window root;
4777a84e134Smrg	int x, y;
4787a84e134Smrg	unsigned int width, height, bw;
4797a84e134Smrg
4807a84e134Smrg	XGetGeometry(XtDisplay(w), sbw->scrollbar.thumb, &root, &x, &y,
4817a84e134Smrg		     &width, &height, &bw, &depth);
4827a84e134Smrg    }
4837a84e134Smrg
4847a84e134Smrg    gcValues.foreground = sbw->scrollbar.foreground;
4857a84e134Smrg    gcValues.background = sbw->core.background_pixel;
4867a84e134Smrg    mask = GCForeground | GCBackground;
4877a84e134Smrg
4887a84e134Smrg    if (sbw->scrollbar.thumb != None) {
4897a84e134Smrg	if (depth == 1) {
4907a84e134Smrg	    gcValues.fill_style = FillOpaqueStippled;
4917a84e134Smrg	    gcValues.stipple = sbw->scrollbar.thumb;
4927a84e134Smrg	    mask |= GCFillStyle | GCStipple;
4937a84e134Smrg	}
4947a84e134Smrg	else {
4957a84e134Smrg	    gcValues.fill_style = FillTiled;
4967a84e134Smrg	    gcValues.tile = sbw->scrollbar.thumb;
4977a84e134Smrg	    mask |= GCFillStyle | GCTile;
4987a84e134Smrg	}
4997a84e134Smrg    }
5007a84e134Smrg    sbw->scrollbar.gc = XtGetGC(w, mask, &gcValues);
5017a84e134Smrg}
5027a84e134Smrg
5037a84e134Smrg/* ARGSUSED */
5047a84e134Smrgstatic void
5055ec34c4cSmrgXawScrollbarInitialize(Widget request _X_UNUSED, Widget cnew,
5065ec34c4cSmrg		       ArgList args _X_UNUSED, Cardinal *num_args _X_UNUSED)
5077a84e134Smrg{
5087a84e134Smrg    ScrollbarWidget w = (ScrollbarWidget)cnew;
5097a84e134Smrg
5107a84e134Smrg    CreateGC(cnew);
5117a84e134Smrg
5127a84e134Smrg    if (XtWidth(w) == 0)
5137a84e134Smrg	XtWidth(w) = w->scrollbar.orientation == XtorientVertical ?
5147a84e134Smrg			w->scrollbar.thickness : w->scrollbar.length;
5157a84e134Smrg
5167a84e134Smrg    if (XtHeight(w) == 0)
5177a84e134Smrg	XtHeight(w) = w->scrollbar.orientation == XtorientHorizontal ?
5187a84e134Smrg			w->scrollbar.thickness : w->scrollbar.length;
5197a84e134Smrg
5207a84e134Smrg    SetDimensions(w);
5217a84e134Smrg    w->scrollbar.direction = 0;
5227a84e134Smrg    w->scrollbar.topLoc = 0;
5237a84e134Smrg    w->scrollbar.shownLength = w->scrollbar.min_thumb;
5247a84e134Smrg}
5257a84e134Smrg
5267a84e134Smrgstatic void
5277a84e134SmrgXawScrollbarRealize(Widget gw, Mask *valueMask,
5287a84e134Smrg		    XSetWindowAttributes *attributes)
5297a84e134Smrg{
5307a84e134Smrg    ScrollbarWidget w = (ScrollbarWidget)gw;
5317a84e134Smrg
5327a84e134Smrg    w->scrollbar.inactiveCursor = w->scrollbar.orientation == XtorientVertical ?
5337a84e134Smrg		w->scrollbar.verCursor : w->scrollbar.horCursor;
5347a84e134Smrg
5357a84e134Smrg    XtVaSetValues(gw, XtNcursor, w->scrollbar.inactiveCursor, NULL);
5367a84e134Smrg
537421c997bSmrg    /*
5387a84e134Smrg     * The Simple widget actually stuffs the value in the valuemask
5397a84e134Smrg     */
5407a84e134Smrg    (*scrollbarWidgetClass->core_class.superclass->core_class.realize)
5417a84e134Smrg	(gw, valueMask, attributes);
5427a84e134Smrg}
5437a84e134Smrg
5447a84e134Smrg/*ARGSUSED*/
545421c997bSmrgstatic Boolean
5465ec34c4cSmrgXawScrollbarSetValues(Widget current, Widget request _X_UNUSED, Widget desired,
5475ec34c4cSmrg		      ArgList args _X_UNUSED, Cardinal *num_args _X_UNUSED)
5487a84e134Smrg{
5497a84e134Smrg    ScrollbarWidget w = (ScrollbarWidget)current;
5507a84e134Smrg    ScrollbarWidget dw = (ScrollbarWidget)desired;
5517a84e134Smrg    Boolean redraw = False;
5527a84e134Smrg
5537a84e134Smrg    /*
5547a84e134Smrg     * If these values are outside the acceptable range ignore them...
5557a84e134Smrg     */
5567a84e134Smrg    if (dw->scrollbar.top < 0.0 || dw->scrollbar.top > 1.0)
5577a84e134Smrg	dw->scrollbar.top = w->scrollbar.top;
5587a84e134Smrg
5597a84e134Smrg    if (dw->scrollbar.shown < 0.0 || dw->scrollbar.shown > 1.0)
5607a84e134Smrg	dw->scrollbar.shown = w->scrollbar.shown;
5617a84e134Smrg
5627a84e134Smrg    if (XtIsRealized (desired)) {
5637a84e134Smrg	if (w->scrollbar.foreground != dw->scrollbar.foreground ||
5647a84e134Smrg	    w->core.background_pixel != dw->core.background_pixel ||
5657a84e134Smrg	    w->scrollbar.thumb != dw->scrollbar.thumb) {
5667a84e134Smrg	    XtReleaseGC((Widget)dw, w->scrollbar.gc);
5677a84e134Smrg	    CreateGC((Widget)dw);
5687a84e134Smrg	    redraw = True;
5697a84e134Smrg	}
5707a84e134Smrg	if (w->scrollbar.top != dw->scrollbar.top ||
5717a84e134Smrg	    w->scrollbar.shown != dw->scrollbar.shown)
5727a84e134Smrg	    redraw = True;
5737a84e134Smrg    }
5747a84e134Smrg
5757a84e134Smrg    return (redraw);
5767a84e134Smrg}
5777a84e134Smrg
5787a84e134Smrgstatic void
5797a84e134SmrgXawScrollbarResize(Widget gw)
5807a84e134Smrg{
5817a84e134Smrg    /* ForgetGravity has taken care of background, but thumb may
5827a84e134Smrg     * have to move as a result of the new size. */
5837a84e134Smrg    SetDimensions((ScrollbarWidget)gw);
5847a84e134Smrg    XawScrollbarRedisplay(gw, NULL, NULL);
5857a84e134Smrg}
5867a84e134Smrg
5877a84e134Smrg/*ARGSUSED*/
5887a84e134Smrgstatic void
5897a84e134SmrgXawScrollbarRedisplay(Widget gw, XEvent *event, Region region)
5907a84e134Smrg{
5917a84e134Smrg    ScrollbarWidget w = (ScrollbarWidget)gw;
5927a84e134Smrg    int x, y;
5937a84e134Smrg    unsigned int width, height;
5947a84e134Smrg
5957a84e134Smrg    if (Superclass->core_class.expose)
5967a84e134Smrg	(*Superclass->core_class.expose)(gw, event, region);
5977a84e134Smrg
5987a84e134Smrg    if (w->scrollbar.orientation == XtorientHorizontal) {
5997a84e134Smrg	x = w->scrollbar.topLoc;
6007a84e134Smrg	y = 1;
6015ec34c4cSmrg	width = (unsigned)(w->scrollbar.shownLength);
6025ec34c4cSmrg	height = (unsigned)(XtHeight(w) - 2);
6037a84e134Smrg    }
6047a84e134Smrg    else {
6057a84e134Smrg	x = 1;
6067a84e134Smrg	y = w->scrollbar.topLoc;
6075ec34c4cSmrg	width = (unsigned)(XtWidth(w) - 2);
6085ec34c4cSmrg	height = (unsigned)(w->scrollbar.shownLength);
6097a84e134Smrg    }
6107a84e134Smrg
6117a84e134Smrg    if (region == NULL ||
6127a84e134Smrg	XRectInRegion(region, x, y, width, height) != RectangleOut) {
6137a84e134Smrg	/* Forces entire thumb to be painted */
6145ec34c4cSmrg	w->scrollbar.topLoc = (Position)(-(w->scrollbar.length + 1));
6157a84e134Smrg	PaintThumb(w);
6167a84e134Smrg    }
6177a84e134Smrg}
6187a84e134Smrg
6197a84e134Smrg/*ARGSUSED*/
6207a84e134Smrgstatic void
6215ec34c4cSmrgStartScroll(Widget gw, XEvent *event _X_UNUSED, String *params, Cardinal *num_params)
6227a84e134Smrg{
6237a84e134Smrg    ScrollbarWidget w = (ScrollbarWidget)gw;
6247a84e134Smrg    Cursor cursor;
6257a84e134Smrg    char direction;
6267a84e134Smrg
6277a84e134Smrg    if (w->scrollbar.direction != 0)	/* if we're already scrolling */
6287a84e134Smrg	return;
6297a84e134Smrg    if (*num_params > 0)
6307a84e134Smrg	direction = *params[0];
6317a84e134Smrg    else
6327a84e134Smrg	direction = 'C';
6337a84e134Smrg
6347a84e134Smrg    w->scrollbar.direction = direction;
6357a84e134Smrg
6367a84e134Smrg    switch(direction) {
6377a84e134Smrg	case 'B':
6387a84e134Smrg	case 'b':
6397a84e134Smrg	    cursor = w->scrollbar.orientation == XtorientVertical ?
6407a84e134Smrg		w->scrollbar.downCursor : w->scrollbar.rightCursor;
6417a84e134Smrg	    break;
6427a84e134Smrg	case 'F':
6437a84e134Smrg	case 'f':
6447a84e134Smrg	    cursor = w->scrollbar.orientation == XtorientVertical ?
6457a84e134Smrg		w->scrollbar.upCursor : w->scrollbar.leftCursor;
6467a84e134Smrg	    break;
6477a84e134Smrg	case 'C':
6487a84e134Smrg	case 'c':
6497a84e134Smrg	     cursor = w->scrollbar.orientation == XtorientVertical ?
6507a84e134Smrg		w->scrollbar.rightCursor : w->scrollbar.upCursor;
6517a84e134Smrg	     break;
6527a84e134Smrg	default:
6537a84e134Smrg	     return;	/* invalid invocation */
6547a84e134Smrg    }
6557a84e134Smrg
6567a84e134Smrg    XtVaSetValues(gw, XtNcursor, cursor, NULL);
6577a84e134Smrg
6587a84e134Smrg    XFlush(XtDisplay(w));
6597a84e134Smrg}
6607a84e134Smrg
6617a84e134Smrgstatic Boolean
6627a84e134SmrgCompareEvents(XEvent *oldEvent, XEvent *newEvent)
6637a84e134Smrg{
6647a84e134Smrg#define Check(field) if (newEvent->field != oldEvent->field) return (False)
6657a84e134Smrg
6667a84e134Smrg    Check(xany.display);
6677a84e134Smrg    Check(xany.type);
6687a84e134Smrg    Check(xany.window);
6697a84e134Smrg
6707a84e134Smrg    switch(newEvent->type) {
6717a84e134Smrg	case MotionNotify:
6727a84e134Smrg	    Check(xmotion.state);
6737a84e134Smrg	    break;
6747a84e134Smrg	case ButtonPress:
6757a84e134Smrg	case ButtonRelease:
6767a84e134Smrg	    Check(xbutton.state);
6777a84e134Smrg	    Check(xbutton.button);
6787a84e134Smrg	    break;
6797a84e134Smrg	case KeyPress:
6807a84e134Smrg	case KeyRelease:
6817a84e134Smrg	    Check(xkey.state);
6827a84e134Smrg	    Check(xkey.keycode);
6837a84e134Smrg	    break;
6847a84e134Smrg	case EnterNotify:
6857a84e134Smrg	case LeaveNotify:
6867a84e134Smrg	    Check(xcrossing.mode);
6877a84e134Smrg	    Check(xcrossing.detail);
6887a84e134Smrg	    Check(xcrossing.state);
6897a84e134Smrg	    break;
6907a84e134Smrg    }
6917a84e134Smrg#undef Check
6927a84e134Smrg
6937a84e134Smrg    return (True);
6947a84e134Smrg}
6957a84e134Smrg
6967a84e134Smrgstruct EventData {
6977a84e134Smrg    XEvent *oldEvent;
6987a84e134Smrg    int count;
6997a84e134Smrg};
7007a84e134Smrg
7017a84e134Smrgstatic Bool
7027a84e134SmrgPeekNotifyEvent(Display *dpy, XEvent *event, char *args)
7037a84e134Smrg{
7047a84e134Smrg    struct EventData *eventData = (struct EventData*)args;
7057a84e134Smrg
7067a84e134Smrg    return (++eventData->count == QLength(dpy)	/* since PeekIf blocks */
7077a84e134Smrg	    || CompareEvents(event, eventData->oldEvent));
7087a84e134Smrg}
7097a84e134Smrg
7107a84e134Smrgstatic Bool
7117a84e134SmrgLookAhead(Widget w, XEvent *event)
7127a84e134Smrg{
7137a84e134Smrg    XEvent newEvent;
7147a84e134Smrg    struct EventData eventData;
7157a84e134Smrg
7167a84e134Smrg    if (QLength(XtDisplay(w)) == 0)
7177a84e134Smrg	return (False);
7187a84e134Smrg
7197a84e134Smrg    eventData.count = 0;
7207a84e134Smrg    eventData.oldEvent = event;
7217a84e134Smrg
7227a84e134Smrg    XPeekIfEvent(XtDisplay(w), &newEvent, PeekNotifyEvent, (char*)&eventData);
7237a84e134Smrg
7247a84e134Smrg    if (CompareEvents(event, &newEvent))
7257a84e134Smrg	return (True);
7267a84e134Smrg
7277a84e134Smrg    return (False);
7287a84e134Smrg}
7297a84e134Smrg
7307a84e134Smrgstatic void
7317a84e134SmrgExtractPosition(XEvent *event, Position *x, Position *y)
7327a84e134Smrg{
7337a84e134Smrg    switch(event->type) {
7347a84e134Smrg	case MotionNotify:
7355ec34c4cSmrg	    *x = (Position)event->xmotion.x;
7365ec34c4cSmrg	    *y = (Position)event->xmotion.y;
7377a84e134Smrg	    break;
7387a84e134Smrg	case ButtonPress:
7397a84e134Smrg	case ButtonRelease:
7405ec34c4cSmrg	    *x = (Position)event->xbutton.x;
7415ec34c4cSmrg	    *y = (Position)event->xbutton.y;
7427a84e134Smrg	    break;
7437a84e134Smrg	case KeyPress:
7447a84e134Smrg	case KeyRelease:
7455ec34c4cSmrg	    *x = (Position)event->xkey.x;
7465ec34c4cSmrg	    *y = (Position)event->xkey.y;
7477a84e134Smrg	    break;
7487a84e134Smrg	case EnterNotify:
7497a84e134Smrg	case LeaveNotify:
7505ec34c4cSmrg	    *x = (Position)event->xcrossing.x;
7515ec34c4cSmrg	    *y = (Position)event->xcrossing.y;
7527a84e134Smrg	    break;
7537a84e134Smrg	default:
7547a84e134Smrg	    *x = 0;
7557a84e134Smrg	    *y = 0;
7567a84e134Smrg	    break;
7577a84e134Smrg    }
7587a84e134Smrg}
7597a84e134Smrg
7607a84e134Smrgstatic void
7617a84e134SmrgNotifyScroll(Widget gw, XEvent *event, String *params, Cardinal *num_params)
7627a84e134Smrg{
7637a84e134Smrg    ScrollbarWidget w = (ScrollbarWidget)gw;
7647a84e134Smrg    long call_data = 0;
7657a84e134Smrg    char style;
7667a84e134Smrg    Position x, y;
7677a84e134Smrg
7687a84e134Smrg    if (w->scrollbar.direction == 0)	/* if no StartScroll */
7697a84e134Smrg	return;
7707a84e134Smrg
7717a84e134Smrg    if (LookAhead(gw, event))
7727a84e134Smrg	return;
7737a84e134Smrg
7747a84e134Smrg    if (*num_params > 0)
7757a84e134Smrg	style = *params[0];
7767a84e134Smrg    else
7777a84e134Smrg	style = 'P';
7787a84e134Smrg
7797a84e134Smrg    switch(style) {
7807a84e134Smrg	case 'P':    /* Proportional */
7817a84e134Smrg	case 'p':
7827a84e134Smrg	    ExtractPosition(event, &x, &y);
7837a84e134Smrg	    call_data = InRange(PICKLENGTH(w, x, y), 0, (int)w->scrollbar.length);
7847a84e134Smrg	    break;
7857a84e134Smrg	case 'F':    /* FullLength */
7867a84e134Smrg	case 'f':
7877a84e134Smrg	    call_data = w->scrollbar.length;
7887a84e134Smrg	    break;
7897a84e134Smrg    }
7907a84e134Smrg
7917a84e134Smrg    switch(w->scrollbar.direction) {
7927a84e134Smrg	case 'B':
7937a84e134Smrg	case 'b':
7947a84e134Smrg	    call_data = -call_data;
7957a84e134Smrg	    /*FALLTHROUGH*/
7967a84e134Smrg	case 'F':
7977a84e134Smrg	case 'f':
7987a84e134Smrg	    XtCallCallbacks(gw, XtNscrollProc, (XtPointer)call_data);
7997a84e134Smrg	    break;
8007a84e134Smrg	case 'C':
8017a84e134Smrg	case 'c':    /* NotifyThumb has already called the thumbProc(s) */
8027a84e134Smrg	    break;
8037a84e134Smrg    }
8047a84e134Smrg}
8057a84e134Smrg
8067a84e134Smrg/*ARGSUSED*/
8077a84e134Smrgstatic void
8085ec34c4cSmrgEndScroll(Widget gw, XEvent *event _X_UNUSED, String *params _X_UNUSED, Cardinal *num_params _X_UNUSED)
8097a84e134Smrg{
8107a84e134Smrg    ScrollbarWidget w = (ScrollbarWidget)gw;
8117a84e134Smrg
8127a84e134Smrg    XtVaSetValues(gw, XtNcursor, w->scrollbar.inactiveCursor, NULL);
8135b16253fSmrg    XFlush(XtDisplay(w));		/* make sure it get propagated */
8147a84e134Smrg
8157a84e134Smrg    w->scrollbar.direction = 0;
8167a84e134Smrg}
8177a84e134Smrg
8187a84e134Smrg/*ARGSUSED*/
8197a84e134Smrgstatic void
8205ec34c4cSmrgMoveThumb(Widget gw, XEvent *event, String *params _X_UNUSED, Cardinal *num_params _X_UNUSED)
8217a84e134Smrg{
8227a84e134Smrg    ScrollbarWidget w = (ScrollbarWidget)gw;
8237a84e134Smrg    Position x, y;
8247a84e134Smrg
8257a84e134Smrg    if (w->scrollbar.direction == 0)	/* if no StartScroll */
8267a84e134Smrg	return;
8277a84e134Smrg
8287a84e134Smrg    if (LookAhead(gw, event))
8297a84e134Smrg	return;
8307a84e134Smrg
8317a84e134Smrg    if (!event->xmotion.same_screen)
8327a84e134Smrg	return;
8337a84e134Smrg
8347a84e134Smrg    ExtractPosition(event, &x, &y);
8357a84e134Smrg    w->scrollbar.top = FractionLoc(w, x, y);
8367a84e134Smrg}
8377a84e134Smrg
8387a84e134Smrg/*ARGSUSED*/
8397a84e134Smrgstatic void
8405ec34c4cSmrgNotifyThumb(Widget gw, XEvent *event, String *params _X_UNUSED, Cardinal *num_params _X_UNUSED)
8417a84e134Smrg{
8427a84e134Smrg    ScrollbarWidget w = (ScrollbarWidget)gw;
8437a84e134Smrg    union {
8447a84e134Smrg	XtPointer xtp;
8457a84e134Smrg	float xtf;
8467a84e134Smrg    } xtpf;
8477a84e134Smrg
8487a84e134Smrg    if (w->scrollbar.direction == 0)	/* if no StartScroll */
8497a84e134Smrg	return;
8507a84e134Smrg
8517a84e134Smrg    if (LookAhead(gw, event))
8527a84e134Smrg	return;
8537a84e134Smrg
8547a84e134Smrg    /* thumbProc is not pretty, but is necessary for backwards
8557a84e134Smrg       compatibility on those architectures for which it work{s,ed};
8567a84e134Smrg       the intent is to pass a (truncated) float by value. */
8577a84e134Smrg    xtpf.xtf = w->scrollbar.top;
8587a84e134Smrg    XtCallCallbacks(gw, XtNthumbProc, xtpf.xtp);
8597a84e134Smrg    XtCallCallbacks(gw, XtNjumpProc, (XtPointer)&w->scrollbar.top);
8607a84e134Smrg
8617a84e134Smrg    PaintThumb(w);
8627a84e134Smrg}
8637a84e134Smrg
8647a84e134Smrg/*
8657a84e134Smrg *  Public routines
8667a84e134Smrg */
8677a84e134Smrg/* Set the scroll bar to the given location. */
8687a84e134Smrgvoid
8697a84e134SmrgXawScrollbarSetThumb(Widget gw,
8707a84e134Smrg#if NeedWidePrototypes
8717a84e134Smrg		     double top, double shown
8727a84e134Smrg#else
8737a84e134Smrg		     float top, float shown
8747a84e134Smrg#endif
8757a84e134Smrg		     )
8767a84e134Smrg{
8777a84e134Smrg    ScrollbarWidget w = (ScrollbarWidget)gw;
8787a84e134Smrg
8797a84e134Smrg    if (w->scrollbar.direction == 'c')	/* if still thumbing */
8807a84e134Smrg	return;
8817a84e134Smrg
8825ec34c4cSmrg    w->scrollbar.top = (float)((top > 1.0)
8835ec34c4cSmrg			       ? 1.0
8845ec34c4cSmrg			       : ((top >= 0.0)
8855ec34c4cSmrg			          ? top
8865ec34c4cSmrg			          : w->scrollbar.top));
8875ec34c4cSmrg
8885ec34c4cSmrg    w->scrollbar.shown = (float)((shown > 1.0)
8895ec34c4cSmrg				  ? 1.0
8905ec34c4cSmrg				  : (shown >= 0.0
8915ec34c4cSmrg				     ? shown
8925ec34c4cSmrg				     : w->scrollbar.shown));
8937a84e134Smrg    PaintThumb(w);
8947a84e134Smrg}
895