1 /* vi:set ts=8 sts=4 sw=4: */
3 * MODIFIED ATHENA SCROLLBAR (USING ARROWHEADS AT ENDS OF TRAVEL)
4 * Modifications Copyright 1992 by Mitch Trachtenberg
5 * Rights, permissions, and disclaimer of warranty are as in the DEC and MIT
7 * $XConsortium: Scrollbar.c,v 1.72 94/04/17 20:12:40 kaleb Exp $
11 * Modified for Vim by Bill Foster and Bram Moolenaar
16 Copyright (c) 1987, 1988, 1994 X Consortium
18 Permission is hereby granted, free of charge, to any person obtaining a copy
19 of this software and associated documentation files (the "Software"), to deal
20 in the Software without restriction, including without limitation the rights
21 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
22 copies of the Software, and to permit persons to whom the Software is
23 furnished to do so, subject to the following conditions:
25 The above copyright notice and this permission notice shall be included in all
26 copies or substantial portions of the Software.
28 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE X
31 CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
32 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
33 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 Except as contained in this notice, the name of the X Consortium shall not be
36 used in advertising or otherwise to promote the sale, use or other dealings in
37 this Software without prior written authorization from the X Consortium.
39 Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
43 Permission to use, copy, modify, and distribute this software and its
44 documentation for any purpose and without fee is hereby granted, provided that
45 the above copyright notice appear in all copies and that both that copyright
46 notice and this permission notice appear in supporting documentation, and that
47 the name of Digital not be used in advertising or publicity pertaining to
48 distribution of the software without specific, written prior permission.
50 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
51 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL DIGITAL
52 BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
53 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
54 OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
55 CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
60 /* created by weissman, Mon Jul 7 13:20:03 1986 */
61 /* converted by swick, Thu Aug 27 1987 */
63 #include <X11/IntrinsicP.h>
64 #include <X11/StringDefs.h>
66 #include <X11/Xaw/XawInit.h>
68 #include "gui_at_sb.h"
70 #include <X11/Xmu/Drawing.h>
72 /* Private definitions. */
74 static char defaultTranslations
[] =
75 "<Btn1Down>: NotifyScroll()\n\
76 <Btn2Down>: MoveThumb() NotifyThumb()\n\
77 <Btn3Down>: NotifyScroll()\n\
78 <Btn4Down>: ScrollOneLineUp()\n\
79 Shift<Btn4Down>: ScrollPageUp()\n\
80 <Btn5Down>: ScrollOneLineDown()\n\
81 Shift<Btn5Down>: ScrollPageDown()\n\
82 <Btn1Motion>: HandleThumb()\n\
83 <Btn3Motion>: HandleThumb()\n\
84 <Btn2Motion>: MoveThumb() NotifyThumb()\n\
85 <BtnUp>: EndScroll()";
87 static float floatZero
= 0.0;
89 #define Offset(field) XtOffsetOf(ScrollbarRec, field)
91 static XtResource resources
[] =
93 {XtNlength
, XtCLength
, XtRDimension
, sizeof(Dimension
),
94 Offset(scrollbar
.length
), XtRImmediate
, (XtPointer
) 1},
95 {XtNthickness
, XtCThickness
, XtRDimension
, sizeof(Dimension
),
96 Offset(scrollbar
.thickness
), XtRImmediate
, (XtPointer
) 14},
97 {XtNorientation
, XtCOrientation
, XtROrientation
, sizeof(XtOrientation
),
98 Offset(scrollbar
.orientation
), XtRImmediate
, (XtPointer
) XtorientVertical
},
99 {XtNscrollProc
, XtCCallback
, XtRCallback
, sizeof(XtPointer
),
100 Offset(scrollbar
.scrollProc
), XtRCallback
, NULL
},
101 {XtNthumbProc
, XtCCallback
, XtRCallback
, sizeof(XtPointer
),
102 Offset(scrollbar
.thumbProc
), XtRCallback
, NULL
},
103 {XtNjumpProc
, XtCCallback
, XtRCallback
, sizeof(XtPointer
),
104 Offset(scrollbar
.jumpProc
), XtRCallback
, NULL
},
105 {XtNthumb
, XtCThumb
, XtRBitmap
, sizeof(Pixmap
),
106 Offset(scrollbar
.thumb
), XtRImmediate
, (XtPointer
) XtUnspecifiedPixmap
},
107 {XtNforeground
, XtCForeground
, XtRPixel
, sizeof(Pixel
),
108 Offset(scrollbar
.foreground
), XtRString
, XtDefaultForeground
},
109 {XtNshown
, XtCShown
, XtRFloat
, sizeof(float),
110 Offset(scrollbar
.shown
), XtRFloat
, (XtPointer
)&floatZero
},
111 {XtNtopOfThumb
, XtCTopOfThumb
, XtRFloat
, sizeof(float),
112 Offset(scrollbar
.top
), XtRFloat
, (XtPointer
)&floatZero
},
113 {XtNmaxOfThumb
, XtCMaxOfThumb
, XtRFloat
, sizeof(float),
114 Offset(scrollbar
.max
), XtRFloat
, (XtPointer
)&floatZero
},
115 {XtNminimumThumb
, XtCMinimumThumb
, XtRDimension
, sizeof(Dimension
),
116 Offset(scrollbar
.min_thumb
), XtRImmediate
, (XtPointer
) 7},
117 {XtNshadowWidth
, XtCShadowWidth
, XtRDimension
, sizeof(Dimension
),
118 Offset(scrollbar
.shadow_width
), XtRImmediate
, (XtPointer
) 1},
119 {XtNtopShadowPixel
, XtCTopShadowPixel
, XtRPixel
, sizeof(Pixel
),
120 Offset(scrollbar
.top_shadow_pixel
), XtRString
, XtDefaultBackground
},
121 {XtNbottomShadowPixel
, XtCBottomShadowPixel
, XtRPixel
, sizeof(Pixel
),
122 Offset(scrollbar
.bot_shadow_pixel
), XtRString
, XtDefaultForeground
},
123 {XtNlimitThumb
, XtCLimitThumb
, XtRBool
, sizeof(Bool
),
124 Offset(scrollbar
.limit_thumb
), XtRImmediate
, (XtPointer
)0}
128 static void ClassInitialize
__ARGS((void));
129 static void Initialize
__ARGS((Widget
, Widget
, ArgList
, Cardinal
*));
130 static void Destroy
__ARGS((Widget
));
131 static void Realize
__ARGS((Widget
, Mask
*, XSetWindowAttributes
*));
132 static void Resize
__ARGS((Widget
));
133 static void Redisplay
__ARGS((Widget
, XEvent
*, Region
));
134 static Boolean SetValues
__ARGS((Widget
, Widget
, Widget
, ArgList
, Cardinal
*));
136 static void HandleThumb
__ARGS((Widget
, XEvent
*, String
*, Cardinal
*));
137 static void MoveThumb
__ARGS((Widget
, XEvent
*, String
*, Cardinal
*));
138 static void NotifyThumb
__ARGS((Widget
, XEvent
*, String
*, Cardinal
*));
139 static void NotifyScroll
__ARGS((Widget
, XEvent
*, String
*, Cardinal
*));
140 static void EndScroll
__ARGS((Widget
, XEvent
*, String
*, Cardinal
*));
141 static void ScrollOneLineUp
__ARGS((Widget
, XEvent
*, String
*, Cardinal
*));
142 static void ScrollOneLineDown
__ARGS((Widget
, XEvent
*, String
*, Cardinal
*));
143 static void ScrollPageUp
__ARGS((Widget
, XEvent
*, String
*, Cardinal
*));
144 static void ScrollPageDown
__ARGS((Widget
, XEvent
*, String
*, Cardinal
*));
145 static void ScrollSome
__ARGS((Widget w
, XEvent
*event
, int call_data
));
146 static void _Xaw3dDrawShadows
__ARGS((Widget
, XEvent
*, Region
, int));
147 static void AllocTopShadowGC
__ARGS((Widget
));
148 static void AllocBotShadowGC
__ARGS((Widget
));
150 static XtActionsRec actions
[] =
152 {"HandleThumb", HandleThumb
},
153 {"MoveThumb", MoveThumb
},
154 {"NotifyThumb", NotifyThumb
},
155 {"NotifyScroll", NotifyScroll
},
156 {"EndScroll", EndScroll
},
157 {"ScrollOneLineUp", ScrollOneLineUp
},
158 {"ScrollOneLineDown", ScrollOneLineDown
},
159 {"ScrollPageUp", ScrollPageUp
},
160 {"ScrollPageDown", ScrollPageDown
}
164 ScrollbarClassRec vim_scrollbarClassRec
=
167 /* superclass */ (WidgetClass
) &simpleClassRec
,
168 /* class_name */ "Scrollbar",
169 /* size */ sizeof(ScrollbarRec
),
170 /* class_initialize */ ClassInitialize
,
171 /* class_part_init */ NULL
,
172 /* class_inited */ FALSE
,
173 /* initialize */ Initialize
,
174 /* initialize_hook */ NULL
,
175 /* realize */ Realize
,
176 /* actions */ actions
,
177 /* num_actions */ XtNumber(actions
),
178 /* resources */ resources
,
179 /* num_resources */ XtNumber(resources
),
180 /* xrm_class */ NULLQUARK
,
181 /* compress_motion */ TRUE
,
182 /* compress_exposure*/ TRUE
,
183 /* compress_enterleave*/ TRUE
,
184 /* visible_interest */ FALSE
,
185 /* destroy */ Destroy
,
187 /* expose */ Redisplay
,
188 /* set_values */ SetValues
,
189 /* set_values_hook */ NULL
,
190 /* set_values_almost */ XtInheritSetValuesAlmost
,
191 /* get_values_hook */ NULL
,
192 /* accept_focus */ NULL
,
193 /* version */ XtVersion
,
194 /* callback_private */ NULL
,
195 /* tm_table */ defaultTranslations
,
196 /* query_geometry */ XtInheritQueryGeometry
,
197 /* display_accelerator*/ XtInheritDisplayAccelerator
,
200 { /* simple fields */
201 /* change_sensitive */ XtInheritChangeSensitive
203 { /* scrollbar fields */
208 WidgetClass vim_scrollbarWidgetClass
= (WidgetClass
)&vim_scrollbarClassRec
;
211 #define PICKLENGTH(widget, x, y) \
212 ((widget->scrollbar.orientation == XtorientHorizontal) ? (x) : (y))
213 #define AT_MIN(x,y) ((x) < (y) ? (x) : (y))
214 #define AT_MAX(x,y) ((x) > (y) ? (x) : (y))
216 #define LINE_DELAY 300
217 #define PAGE_DELAY 300
218 #define LINE_REPEAT 50
219 #define PAGE_REPEAT 250
224 XawInitializeWidgetSet();
225 XtAddConverter( XtRString
, XtROrientation
, XmuCvtStringToOrientation
,
226 (XtConvertArgList
)NULL
, (Cardinal
)0 );
229 #define MARGIN(sbw) (sbw)->scrollbar.thickness + (sbw)->scrollbar.shadow_width
232 FillArea(sbw
, top
, bottom
, fill
, draw_shadow
)
234 Position top
, bottom
;
238 int tlen
= bottom
- top
; /* length of thumb in pixels */
239 int sw
, margin
, floor
;
242 if (bottom
<= 0 || bottom
<= top
)
244 if ((sw
= sbw
->scrollbar
.shadow_width
) < 0)
246 margin
= MARGIN (sbw
);
247 floor
= sbw
->scrollbar
.length
- margin
+ 2;
249 if (sbw
->scrollbar
.orientation
== XtorientHorizontal
)
251 lx
= ((top
< margin
) ? margin
: top
);
253 lw
= (((top
+ tlen
) > floor
) ? floor
- top
: tlen
);
254 lh
= sbw
->core
.height
- 2 * sw
;
259 ly
= ((top
< margin
) ? margin
: top
);
260 lw
= sbw
->core
.width
- 2 * sw
;
261 lh
= (((top
+ tlen
) > floor
) ? floor
- top
: tlen
);
263 if (lh
<= 0 || lw
<= 0)
268 if (!(sbw
->scrollbar
.orientation
== XtorientHorizontal
))
271 XDrawLine (XtDisplay ((Widget
) sbw
), XtWindow ((Widget
) sbw
),
272 sbw
->scrollbar
.top_shadow_GC
,
273 lx
, ly
, lx
+ lw
- 1, ly
);
276 XDrawLine (XtDisplay ((Widget
) sbw
), XtWindow ((Widget
) sbw
),
277 sbw
->scrollbar
.bot_shadow_GC
,
278 lx
, ly
+ lh
- 1, lx
+ lw
- 1, ly
+ lh
- 1);
283 XDrawLine (XtDisplay ((Widget
) sbw
), XtWindow ((Widget
) sbw
),
284 sbw
->scrollbar
.top_shadow_GC
,
285 lx
, ly
, lx
, ly
+ lh
- 1);
288 XDrawLine (XtDisplay ((Widget
) sbw
), XtWindow ((Widget
) sbw
),
289 sbw
->scrollbar
.bot_shadow_GC
,
290 lx
+ lw
- 1, ly
, lx
+ lw
- 1, ly
+ lh
- 1);
297 XFillRectangle(XtDisplay((Widget
) sbw
), XtWindow((Widget
) sbw
),
299 lx
, ly
, (unsigned int) lw
, (unsigned int) lh
);
301 if (!(sbw
->scrollbar
.orientation
== XtorientHorizontal
))
304 XDrawLine(XtDisplay ((Widget
) sbw
), XtWindow ((Widget
) sbw
),
305 sbw
->scrollbar
.top_shadow_GC
,
306 lx
, ly
, lx
, ly
+ lh
- 1);
309 XDrawLine(XtDisplay ((Widget
) sbw
), XtWindow ((Widget
) sbw
),
310 sbw
->scrollbar
.bot_shadow_GC
,
311 lx
+ lw
- 1, ly
, lx
+ lw
- 1, ly
+ lh
- 1);
316 XDrawLine(XtDisplay ((Widget
) sbw
), XtWindow ((Widget
) sbw
),
317 sbw
->scrollbar
.top_shadow_GC
,
318 lx
, ly
, lx
+ lw
- 1, ly
);
321 XDrawLine(XtDisplay ((Widget
) sbw
), XtWindow ((Widget
) sbw
),
322 sbw
->scrollbar
.bot_shadow_GC
,
323 lx
, ly
+ lh
- 1, lx
+ lw
- 1, ly
+ lh
- 1);
328 XClearArea(XtDisplay((Widget
) sbw
), XtWindow((Widget
) sbw
),
329 lx
, ly
, (unsigned int) lw
, (unsigned int) lh
, FALSE
);
333 /* Paint the thumb in the area specified by sbw->top and
334 sbw->shown. The old area is erased. The painting and
335 erasing is done cleverly so that no flickering will occur.
342 Position oldtop
, oldbot
, newtop
, newbot
;
343 Dimension margin
, tzl
;
345 margin
= MARGIN (sbw
);
346 tzl
= sbw
->scrollbar
.length
- 2 * margin
;
347 newtop
= margin
+ (int)(tzl
* sbw
->scrollbar
.top
);
348 newbot
= newtop
+ (int)(tzl
* sbw
->scrollbar
.shown
) + 1;
349 if (newbot
< newtop
+ (int)sbw
->scrollbar
.min_thumb
)
350 newbot
= newtop
+ sbw
->scrollbar
.min_thumb
;
352 oldtop
= sbw
->scrollbar
.topLoc
;
353 oldbot
= oldtop
+ sbw
->scrollbar
.shownLength
;
354 sbw
->scrollbar
.topLoc
= newtop
;
355 sbw
->scrollbar
.shownLength
= newbot
- newtop
;
356 if (XtIsRealized ((Widget
) sbw
))
359 FillArea(sbw
, newtop
, AT_MIN(newbot
, oldtop
+1),1,0);
361 FillArea(sbw
, oldtop
, AT_MIN(newtop
, oldbot
),0,0);
363 FillArea(sbw
, AT_MAX(newbot
, oldtop
), oldbot
, 0,0);
365 FillArea(sbw
, AT_MAX(newtop
, oldbot
-1), newbot
, 1,0);
367 /* Only draw the missing shadows */
368 FillArea(sbw
, newtop
, newbot
, 0, 1);
377 Dimension thickness
= sbw
->scrollbar
.thickness
- 1;
381 if (XtIsRealized((Widget
) sbw
))
383 if ((int)thickness
* 2 > (int)sbw
->scrollbar
.length
)
385 size
= sbw
->scrollbar
.length
/ 2;
386 off
= (int)(thickness
- size
) / 2;
393 point
[0].x
= off
+ sbw
->scrollbar
.shadow_width
;
395 point
[1].x
= thickness
- off
- sbw
->scrollbar
.shadow_width
;
397 point
[2].x
= thickness
/ 2;
398 point
[2].y
= sbw
->scrollbar
.shadow_width
;
400 point
[3].x
= off
+ sbw
->scrollbar
.shadow_width
;
401 point
[3].y
= sbw
->scrollbar
.length
- size
;
402 point
[4].x
= thickness
- off
- sbw
->scrollbar
.shadow_width
;
403 point
[4].y
= sbw
->scrollbar
.length
- size
;
404 point
[5].x
= thickness
/ 2;
405 point
[5].y
= sbw
->scrollbar
.length
- sbw
->scrollbar
.shadow_width
- 1;
407 /* horizontal arrows require that x and y coordinates be swapped */
408 if (sbw
->scrollbar
.orientation
== XtorientHorizontal
)
412 for (n
= 0; n
< 6; n
++)
415 point
[n
].x
= point
[n
].y
;
419 /* draw the up/left arrow */
420 XFillPolygon (XtDisplay ((Widget
) sbw
), XtWindow ((Widget
) sbw
),
423 Convex
, CoordModeOrigin
);
424 XDrawLines (XtDisplay ((Widget
) sbw
), XtWindow ((Widget
) sbw
),
425 sbw
->scrollbar
.bot_shadow_GC
,
428 XDrawLine (XtDisplay ((Widget
) sbw
), XtWindow ((Widget
) sbw
),
429 sbw
->scrollbar
.top_shadow_GC
,
430 point
[0].x
, point
[0].y
,
431 point
[2].x
, point
[2].y
);
432 /* draw the down/right arrow */
433 XFillPolygon (XtDisplay ((Widget
) sbw
), XtWindow ((Widget
) sbw
),
436 Convex
, CoordModeOrigin
);
437 XDrawLine (XtDisplay ((Widget
) sbw
), XtWindow ((Widget
) sbw
),
438 sbw
->scrollbar
.top_shadow_GC
,
439 point
[3].x
, point
[3].y
,
440 point
[4].x
, point
[4].y
);
441 XDrawLine (XtDisplay ((Widget
) sbw
), XtWindow ((Widget
) sbw
),
442 sbw
->scrollbar
.top_shadow_GC
,
443 point
[3].x
, point
[3].y
,
444 point
[5].x
, point
[5].y
);
445 XDrawLine (XtDisplay ((Widget
) sbw
), XtWindow ((Widget
) sbw
),
446 sbw
->scrollbar
.bot_shadow_GC
,
447 point
[4].x
, point
[4].y
,
448 point
[5].x
, point
[5].y
);
456 ScrollbarWidget sbw
= (ScrollbarWidget
) w
;
457 if (sbw
->scrollbar
.timer_id
!= (XtIntervalId
) 0)
458 XtRemoveTimeOut (sbw
->scrollbar
.timer_id
);
459 XtReleaseGC(w
, sbw
->scrollbar
.gc
);
460 XtReleaseGC(w
, sbw
->scrollbar
.top_shadow_GC
);
461 XtReleaseGC(w
, sbw
->scrollbar
.bot_shadow_GC
);
468 ScrollbarWidget sbw
= (ScrollbarWidget
) w
;
471 unsigned int depth
= 1;
473 if (sbw
->scrollbar
.thumb
== XtUnspecifiedPixmap
)
475 sbw
->scrollbar
.thumb
= XmuCreateStippledPixmap (XtScreen(w
),
476 (Pixel
) 1, (Pixel
) 0, depth
);
478 else if (sbw
->scrollbar
.thumb
!= None
)
482 unsigned int width
, height
, bw
;
484 if (XGetGeometry (XtDisplay(w
), sbw
->scrollbar
.thumb
, &root
, &x
, &y
,
485 &width
, &height
, &bw
, &depth
) == 0)
486 EMSG(_("Scrollbar Widget: Could not get geometry of thumb pixmap."));
489 gcValues
.foreground
= sbw
->scrollbar
.foreground
;
490 gcValues
.background
= sbw
->core
.background_pixel
;
491 mask
= GCForeground
| GCBackground
;
493 if (sbw
->scrollbar
.thumb
!= None
)
495 gcValues
.fill_style
= FillSolid
;
498 /* the creation should be non-caching, because */
499 /* we now set and clear clip masks on the gc returned */
500 sbw
->scrollbar
.gc
= XtGetGC (w
, mask
, &gcValues
);
507 if (sbw
->scrollbar
.orientation
== XtorientVertical
)
509 sbw
->scrollbar
.length
= sbw
->core
.height
;
510 sbw
->scrollbar
.thickness
= sbw
->core
.width
;
514 sbw
->scrollbar
.length
= sbw
->core
.width
;
515 sbw
->scrollbar
.thickness
= sbw
->core
.height
;
521 Initialize(request
, new, args
, num_args
)
522 Widget request
; /* what the client asked for */
523 Widget
new; /* what we're going to give him */
527 ScrollbarWidget sbw
= (ScrollbarWidget
) new;
530 AllocTopShadowGC(new);
531 AllocBotShadowGC(new);
533 if (sbw
->core
.width
== 0)
534 sbw
->core
.width
= (sbw
->scrollbar
.orientation
== XtorientVertical
)
535 ? sbw
->scrollbar
.thickness
: sbw
->scrollbar
.length
;
537 if (sbw
->core
.height
== 0)
538 sbw
->core
.height
= (sbw
->scrollbar
.orientation
== XtorientHorizontal
)
539 ? sbw
->scrollbar
.thickness
: sbw
->scrollbar
.length
;
542 sbw
->scrollbar
.scroll_mode
= SMODE_NONE
;
543 sbw
->scrollbar
.timer_id
= (XtIntervalId
)0;
544 sbw
->scrollbar
.topLoc
= 0;
545 sbw
->scrollbar
.shownLength
= sbw
->scrollbar
.min_thumb
;
549 Realize(w
, valueMask
, attributes
)
552 XSetWindowAttributes
*attributes
;
554 /* The Simple widget actually stuffs the value in the valuemask. */
555 (*vim_scrollbarWidgetClass
->core_class
.superclass
->core_class
.realize
)
556 (w
, valueMask
, attributes
);
561 SetValues(current
, request
, desired
, args
, num_args
)
562 Widget current
, /* what I am */
563 request
, /* what he wants me to be */
564 desired
; /* what I will become */
568 ScrollbarWidget sbw
= (ScrollbarWidget
) current
;
569 ScrollbarWidget dsbw
= (ScrollbarWidget
) desired
;
570 Boolean redraw
= FALSE
;
573 * If these values are outside the acceptable range ignore them...
575 if (dsbw
->scrollbar
.top
< 0.0 || dsbw
->scrollbar
.top
> 1.0)
576 dsbw
->scrollbar
.top
= sbw
->scrollbar
.top
;
578 if (dsbw
->scrollbar
.shown
< 0.0 || dsbw
->scrollbar
.shown
> 1.0)
579 dsbw
->scrollbar
.shown
= sbw
->scrollbar
.shown
;
582 * Change colors and stuff...
584 if (XtIsRealized(desired
))
586 if (sbw
->scrollbar
.foreground
!= dsbw
->scrollbar
.foreground
||
587 sbw
->core
.background_pixel
!= dsbw
->core
.background_pixel
||
588 sbw
->scrollbar
.thumb
!= dsbw
->scrollbar
.thumb
)
590 XtReleaseGC(desired
, sbw
->scrollbar
.gc
);
594 if (sbw
->scrollbar
.top
!= dsbw
->scrollbar
.top
||
595 sbw
->scrollbar
.shown
!= dsbw
->scrollbar
.shown
)
605 /* ForgetGravity has taken care of background, but thumb may
606 * have to move as a result of the new size. */
607 SetDimensions ((ScrollbarWidget
) w
);
608 Redisplay(w
, (XEvent
*) NULL
, (Region
)NULL
);
614 Redisplay(w
, event
, region
)
619 ScrollbarWidget sbw
= (ScrollbarWidget
) w
;
621 unsigned int width
, height
;
623 _Xaw3dDrawShadows(w
, event
, region
, FALSE
);
625 if (sbw
->scrollbar
.orientation
== XtorientHorizontal
)
627 x
= sbw
->scrollbar
.topLoc
;
629 width
= sbw
->scrollbar
.shownLength
;
630 height
= sbw
->core
.height
- 2;
635 y
= sbw
->scrollbar
.topLoc
;
636 width
= sbw
->core
.width
- 2;
637 height
= sbw
->scrollbar
.shownLength
;
639 if (region
== NULL
||
640 XRectInRegion (region
, x
, y
, width
, height
) != RectangleOut
)
642 /* Forces entire thumb to be painted. */
643 sbw
->scrollbar
.topLoc
= -(sbw
->scrollbar
.length
+ 1);
646 /* we'd like to be region aware here!!!! */
652 CompareEvents(oldEvent
, newEvent
)
653 XEvent
*oldEvent
, *newEvent
;
655 #define Check(field) if (newEvent->field != oldEvent->field) return False;
661 switch (newEvent
->type
)
664 Check(xmotion
.state
);
668 Check(xbutton
.state
);
669 Check(xbutton
.button
);
678 Check(xcrossing
.mode
);
679 Check(xcrossing
.detail
);
680 Check(xcrossing
.state
);
695 PeekNotifyEvent(dpy
, event
, args
)
700 struct EventData
*eventData
= (struct EventData
*)args
;
702 return ((++eventData
->count
== QLength(dpy
)) /* since PeekIf blocks */
703 || CompareEvents(event
, eventData
->oldEvent
));
713 struct EventData eventData
;
715 if (QLength (XtDisplay (w
)) == 0)
719 eventData
.oldEvent
= event
;
721 XPeekIfEvent (XtDisplay (w
), &newEvent
, PeekNotifyEvent
, (char*)&eventData
);
723 return CompareEvents (event
, &newEvent
);
728 ExtractPosition(event
, x
, y
, state
)
730 Position
*x
, *y
; /* RETURN */
731 unsigned int *state
; /* RETURN */
736 *x
= event
->xmotion
.x
;
737 *y
= event
->xmotion
.y
;
739 *state
= event
->xmotion
.state
;
743 *x
= event
->xbutton
.x
;
744 *y
= event
->xbutton
.y
;
746 *state
= event
->xbutton
.state
;
753 *state
= event
->xkey
.state
;
757 *x
= event
->xcrossing
.x
;
758 *y
= event
->xcrossing
.y
;
760 *state
= event
->xcrossing
.state
;
770 HandleThumb(w
, event
, params
, num_params
)
774 Cardinal
*num_params
;
777 ScrollbarWidget sbw
= (ScrollbarWidget
) w
;
779 ExtractPosition(event
, &x
, &y
, (unsigned int *)NULL
);
780 loc
= PICKLENGTH(sbw
, x
, y
);
781 /* if the motion event puts the pointer in thumb, call Move and Notify */
782 /* also call Move and Notify if we're already in continuous scroll mode */
783 if (sbw
->scrollbar
.scroll_mode
== SMODE_CONT
||
784 (loc
>= sbw
->scrollbar
.topLoc
&&
785 loc
<= sbw
->scrollbar
.topLoc
+ (int)sbw
->scrollbar
.shownLength
))
787 XtCallActionProc(w
, "MoveThumb", event
, params
, *num_params
);
788 XtCallActionProc(w
, "NotifyThumb", event
, params
, *num_params
);
794 RepeatNotify(client_data
, idp
)
795 XtPointer client_data
;
798 ScrollbarWidget sbw
= (ScrollbarWidget
) client_data
;
800 char mode
= sbw
->scrollbar
.scroll_mode
;
803 if (mode
== SMODE_NONE
|| mode
== SMODE_CONT
)
805 sbw
->scrollbar
.timer_id
= (XtIntervalId
)0;
809 if (mode
== SMODE_LINE_DOWN
|| mode
== SMODE_LINE_UP
)
811 call_data
= ONE_LINE_DATA
;
816 call_data
= ONE_PAGE_DATA
;
820 if (mode
== SMODE_PAGE_UP
|| mode
== SMODE_LINE_UP
)
821 call_data
= -call_data
;
823 XtCallCallbacks((Widget
)sbw
, XtNscrollProc
, (XtPointer
)call_data
);
825 sbw
->scrollbar
.timer_id
=
826 XtAppAddTimeOut(XtWidgetToApplicationContext((Widget
)sbw
),
833 * Same as above, but for floating numbers.
836 FloatInRange(num
, small
, big
)
837 float num
, small
, big
;
839 return (num
< small
) ? small
: ((num
> big
) ? big
: num
);
844 ScrollOneLineUp(w
, event
, params
, num_params
)
848 Cardinal
*num_params
;
850 ScrollSome(w
, event
, -ONE_LINE_DATA
);
855 ScrollOneLineDown(w
, event
, params
, num_params
)
859 Cardinal
*num_params
;
861 ScrollSome(w
, event
, ONE_LINE_DATA
);
866 ScrollPageDown(w
, event
, params
, num_params
)
870 Cardinal
*num_params
;
872 ScrollSome(w
, event
, ONE_PAGE_DATA
);
877 ScrollPageUp(w
, event
, params
, num_params
)
881 Cardinal
*num_params
;
883 ScrollSome(w
, event
, -ONE_PAGE_DATA
);
887 ScrollSome(w
, event
, call_data
)
892 ScrollbarWidget sbw
= (ScrollbarWidget
) w
;
894 if (sbw
->scrollbar
.scroll_mode
== SMODE_CONT
) /* if scroll continuous */
897 if (LookAhead(w
, event
))
900 sbw
->scrollbar
.scroll_mode
= SMODE_LINE_UP
;
901 XtCallCallbacks(w
, XtNscrollProc
, (XtPointer
)call_data
);
906 NotifyScroll(w
, event
, params
, num_params
)
910 Cardinal
*num_params
;
912 ScrollbarWidget sbw
= (ScrollbarWidget
) w
;
914 Dimension arrow_size
;
915 unsigned long delay
= 0;
919 if (sbw
->scrollbar
.scroll_mode
== SMODE_CONT
) /* if scroll continuous */
922 if (LookAhead (w
, event
))
925 ExtractPosition(event
, &x
, &y
, &state
);
926 loc
= PICKLENGTH(sbw
, x
, y
);
928 if ((int)sbw
->scrollbar
.thickness
* 2 > (int)sbw
->scrollbar
.length
)
929 arrow_size
= sbw
->scrollbar
.length
/ 2;
931 arrow_size
= sbw
->scrollbar
.thickness
;
934 * handle CTRL modifier
936 if (state
& ControlMask
)
938 if (loc
> sbw
->scrollbar
.topLoc
+ (Position
)sbw
->scrollbar
.shownLength
)
939 call_data
= END_PAGE_DATA
;
941 call_data
= -END_PAGE_DATA
;
942 sbw
->scrollbar
.scroll_mode
= SMODE_NONE
;
945 * handle first arrow zone
947 else if (loc
< (Position
)arrow_size
)
949 call_data
= -ONE_LINE_DATA
;
950 sbw
->scrollbar
.scroll_mode
= SMODE_LINE_UP
;
955 * handle last arrow zone
957 else if (loc
> (Position
)(sbw
->scrollbar
.length
- arrow_size
))
959 call_data
= ONE_LINE_DATA
;
960 sbw
->scrollbar
.scroll_mode
= SMODE_LINE_DOWN
;
965 * handle zone "above" the thumb
967 else if (loc
< sbw
->scrollbar
.topLoc
)
969 call_data
= -ONE_PAGE_DATA
;
970 sbw
->scrollbar
.scroll_mode
= SMODE_PAGE_UP
;
975 * handle zone "below" the thumb
977 else if (loc
> sbw
->scrollbar
.topLoc
+ (Position
)sbw
->scrollbar
.shownLength
)
979 call_data
= ONE_PAGE_DATA
;
980 sbw
->scrollbar
.scroll_mode
= SMODE_PAGE_DOWN
;
985 XtCallCallbacks(w
, XtNscrollProc
, (XtPointer
)call_data
);
987 /* establish autoscroll */
989 sbw
->scrollbar
.timer_id
=
990 XtAppAddTimeOut(XtWidgetToApplicationContext(w
),
991 delay
, RepeatNotify
, (XtPointer
)w
);
996 EndScroll(w
, event
, params
, num_params
)
998 XEvent
*event
; /* unused */
999 String
*params
; /* unused */
1000 Cardinal
*num_params
; /* unused */
1002 ScrollbarWidget sbw
= (ScrollbarWidget
) w
;
1004 sbw
->scrollbar
.scroll_mode
= SMODE_NONE
;
1005 /* no need to remove any autoscroll timeout; it will no-op */
1006 /* because the scroll_mode is SMODE_NONE */
1007 /* but be sure to remove timeout in destroy proc */
1011 FractionLoc(sbw
, x
, y
)
1012 ScrollbarWidget sbw
;
1016 float height
, width
;
1018 margin
= MARGIN(sbw
);
1021 height
= (float)sbw
->core
.height
- 2 * margin
;
1022 width
= (float)sbw
->core
.width
- 2 * margin
;
1023 return PICKLENGTH(sbw
, x
/ width
, y
/ height
);
1028 MoveThumb(w
, event
, params
, num_params
)
1031 String
*params
; /* unused */
1032 Cardinal
*num_params
; /* unused */
1034 ScrollbarWidget sbw
= (ScrollbarWidget
)w
;
1037 char old_mode
= sbw
->scrollbar
.scroll_mode
;
1039 sbw
->scrollbar
.scroll_mode
= SMODE_CONT
; /* indicate continuous scroll */
1041 if (LookAhead(w
, event
))
1044 if (!event
->xmotion
.same_screen
)
1047 ExtractPosition(event
, &x
, &y
, (unsigned int *)NULL
);
1049 top
= FractionLoc(sbw
, x
, y
);
1051 if (old_mode
!= SMODE_CONT
) /* start dragging: set offset */
1053 if (event
->xbutton
.button
== Button2
)
1054 sbw
->scrollbar
.scroll_off
= sbw
->scrollbar
.shown
/ 2.;
1056 sbw
->scrollbar
.scroll_off
= top
- sbw
->scrollbar
.top
;
1059 top
-= sbw
->scrollbar
.scroll_off
;
1060 if (sbw
->scrollbar
.limit_thumb
)
1061 top
= FloatInRange(top
, 0.0,
1062 sbw
->scrollbar
.max
- sbw
->scrollbar
.shown
+ 0.000001);
1064 top
= FloatInRange(top
, 0.0, sbw
->scrollbar
.max
);
1066 sbw
->scrollbar
.top
= top
;
1068 XFlush(XtDisplay(w
)); /* re-draw it before Notifying */
1074 NotifyThumb(w
, event
, params
, num_params
)
1077 String
*params
; /* unused */
1078 Cardinal
*num_params
; /* unused */
1080 ScrollbarWidget sbw
= (ScrollbarWidget
)w
;
1082 if (LookAhead(w
, event
))
1085 /* thumbProc is not pretty, but is necessary for backwards
1086 compatibility on those architectures for which it work{s,ed};
1087 the intent is to pass a (truncated) float by value. */
1088 XtCallCallbacks(w
, XtNthumbProc
, *(XtPointer
*)&sbw
->scrollbar
.top
);
1089 XtCallCallbacks(w
, XtNjumpProc
, (XtPointer
)&sbw
->scrollbar
.top
);
1097 ScrollbarWidget sbw
= (ScrollbarWidget
) w
;
1101 valuemask
= GCForeground
;
1102 myXGCV
.foreground
= sbw
->scrollbar
.top_shadow_pixel
;
1103 sbw
->scrollbar
.top_shadow_GC
= XtGetGC(w
, valuemask
, &myXGCV
);
1111 ScrollbarWidget sbw
= (ScrollbarWidget
) w
;
1115 valuemask
= GCForeground
;
1116 myXGCV
.foreground
= sbw
->scrollbar
.bot_shadow_pixel
;
1117 sbw
->scrollbar
.bot_shadow_GC
= XtGetGC(w
, valuemask
, &myXGCV
);
1122 _Xaw3dDrawShadows(gw
, event
, region
, out
)
1129 ScrollbarWidget sbw
= (ScrollbarWidget
) gw
;
1130 Dimension s
= sbw
->scrollbar
.shadow_width
;
1132 * draw the shadows using the core part width and height,
1133 * and the scrollbar part shadow_width.
1135 * no point to do anything if the shadow_width is 0 or the
1136 * widget has not been realized.
1138 if (s
> 0 && XtIsRealized(gw
))
1140 Dimension h
= sbw
->core
.height
;
1141 Dimension w
= sbw
->core
.width
;
1142 Dimension wms
= w
- s
;
1143 Dimension hms
= h
- s
;
1144 Display
*dpy
= XtDisplay (gw
);
1145 Window win
= XtWindow (gw
);
1150 top
= sbw
->scrollbar
.top_shadow_GC
;
1151 bot
= sbw
->scrollbar
.bot_shadow_GC
;
1155 top
= sbw
->scrollbar
.bot_shadow_GC
;
1156 bot
= sbw
->scrollbar
.top_shadow_GC
;
1159 /* top-left shadow */
1160 if ((region
== NULL
) ||
1161 (XRectInRegion (region
, 0, 0, w
, s
) != RectangleOut
) ||
1162 (XRectInRegion (region
, 0, 0, s
, h
) != RectangleOut
))
1164 pt
[0].x
= 0; pt
[0].y
= h
;
1165 pt
[1].x
= pt
[1].y
= 0;
1166 pt
[2].x
= w
; pt
[2].y
= 0;
1167 pt
[3].x
= wms
; pt
[3].y
= s
;
1168 pt
[4].x
= pt
[4].y
= s
;
1169 pt
[5].x
= s
; pt
[5].y
= hms
;
1170 XFillPolygon (dpy
, win
, top
, pt
, 6, Complex
, CoordModeOrigin
);
1173 /* bottom-right shadow */
1174 if ((region
== NULL
) ||
1175 (XRectInRegion (region
, 0, hms
, w
, s
) != RectangleOut
) ||
1176 (XRectInRegion (region
, wms
, 0, s
, h
) != RectangleOut
))
1178 pt
[0].x
= 0; pt
[0].y
= h
;
1179 pt
[1].x
= w
; pt
[1].y
= h
;
1180 pt
[2].x
= w
; pt
[2].y
= 0;
1181 pt
[3].x
= wms
; pt
[3].y
= s
;
1182 pt
[4].x
= wms
; pt
[4].y
= hms
;
1183 pt
[5].x
= s
; pt
[5].y
= hms
;
1184 XFillPolygon (dpy
, win
, bot
, pt
, 6, Complex
, CoordModeOrigin
);
1191 * Set the scroll bar to the given location.
1194 vim_XawScrollbarSetThumb(w
, top
, shown
, max
)
1196 double top
, shown
, max
;
1198 ScrollbarWidget sbw
= (ScrollbarWidget
) w
;
1200 if (sbw
->scrollbar
.scroll_mode
== SMODE_CONT
) /* if still thumbing */
1203 sbw
->scrollbar
.max
= (max
> 1.0) ? 1.0 :
1204 (max
>= 0.0) ? max
: sbw
->scrollbar
.max
;
1206 sbw
->scrollbar
.top
= (top
> sbw
->scrollbar
.max
) ? sbw
->scrollbar
.max
:
1207 (top
>= 0.0) ? top
: sbw
->scrollbar
.top
;
1209 sbw
->scrollbar
.shown
= (shown
> 1.0) ? 1.0 :
1210 (shown
>= 0.0) ? shown
: sbw
->scrollbar
.shown
;