0
|
1 /* Implements a lightweight scrollbar widget.
|
|
2 Copyright (C) 1992, 1993, 1994 Lucid, Inc.
|
|
3
|
|
4 This file is part of the Lucid Widget Library.
|
|
5
|
|
6 The Lucid Widget Library is free software; you can redistribute it and/or
|
|
7 modify it under the terms of the GNU General Public License as published by
|
|
8 the Free Software Foundation; either version 2, or (at your option)
|
|
9 any later version.
|
|
10
|
|
11 The Lucid Widget Library is distributed in the hope that it will be useful,
|
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 GNU General Public License for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
76
|
17 along with XEmacs; see the file COPYING. If not, write to
|
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 Boston, MA 02111-1307, USA. */
|
0
|
20
|
|
21 /* Created by Douglas Keller <dkeller@vnet.ibm.com> */
|
|
22
|
|
23 /*
|
|
24 * Athena-style scrollbar button bindings added on Sun Dec 24 22:03:57 1995
|
|
25 * by Jonathan Stigelman <Stig@hackvan.com>... Ho ho ho!
|
|
26 *
|
|
27 * To use them, put this resource in your .Xdefaults
|
|
28 *
|
|
29 * Emacs*XlwScrollBar.translations: #override \n\
|
|
30 * <Btn1Down>: PageDownOrRight() \n\
|
|
31 * <Btn3Down>: PageUpOrLeft()
|
|
32 *
|
|
33 */
|
|
34
|
|
35 /*
|
|
36 * Resources Supported:
|
|
37 * XmNforeground
|
|
38 * XmNbackground
|
|
39 * XmNtopShadowColor
|
|
40 * XmNtopShadowPixmap
|
|
41 * XmNbottomShadowColor
|
|
42 * XmNbottomShadowPixmap
|
|
43 * XmNtroughColor
|
|
44 * XmNshadowThickness
|
|
45 * XmNshowArrows
|
|
46 * XmNorientation
|
|
47 * XmNborderWidth
|
|
48 *
|
|
49 * XmNminimum
|
|
50 * XmNmaximum
|
|
51 * XmNvalue
|
|
52 * XmNincrement
|
|
53 * XmNpageIncrement
|
|
54 *
|
|
55 * XmNvalueChangedCallback
|
|
56 * XmNincrementCallback
|
|
57 * XmNdecrementCallback
|
|
58 * XmNpageIncrementCallback
|
|
59 * XmNpageDecrementCallback
|
|
60 * XmNtoTopCallback
|
|
61 * XmNtoBottomCallback
|
|
62 * XmNdragCallback
|
|
63 *
|
70
|
64 * XmNknobStyle - values can be: "plain" or "dimple"
|
0
|
65 * XmNarrowPosition - values can be: "opposite" or "same"
|
|
66 *
|
|
67 */
|
|
68
|
|
69 #include <stdio.h>
|
|
70 #include <stdlib.h>
|
|
71 #include <limits.h>
|
|
72
|
|
73 #include <X11/IntrinsicP.h>
|
|
74 #include <X11/StringDefs.h>
|
|
75 #include <X11/bitmaps/gray>
|
|
76
|
|
77 #include "xlwscrollbarP.h"
|
|
78 #include "xlwscrollbar.h"
|
|
79
|
|
80 #define DBUG(x)
|
|
81
|
|
82 #define MINL(x,y) ((((unsigned long) (x)) < ((unsigned long) (y))) \
|
76
|
83 ? ((unsigned long) (x)) : ((unsigned long) (y)))
|
0
|
84
|
76
|
85 #define VERT(w) ((w)->sb.orientation == XmVERTICAL)
|
0
|
86
|
|
87 #define SS_MIN 8
|
|
88
|
70
|
89 #define ARROW_UP 0
|
|
90 #define ARROW_DOWN 1
|
|
91 #define ARROW_LEFT 2
|
|
92 #define ARROW_RIGHT 3
|
|
93
|
|
94 #define ARM_NONE 0
|
|
95 #define ARM_KNOB 1
|
|
96 #define ARM_UP 2
|
|
97 #define ARM_DOWN 3
|
|
98 #define ARM_PAGEUP 4
|
|
99 #define ARM_PAGEDOWN 5
|
0
|
100
|
70
|
101 #define BUTTON_NONE 0
|
|
102 #define BUTTON_KNOB 1
|
|
103 #define BUTTON_UP_ARROW 2
|
|
104 #define BUTTON_DOWN_ARROW 3
|
|
105 #define BUTTON_TROUGH_ABOVE 4
|
|
106 #define BUTTON_TROUGH_BELOW 5
|
0
|
107
|
70
|
108 #define KNOB_PLAIN 0
|
|
109 #define KNOB_DIMPLE 1
|
|
110
|
|
111 /************************************************************************
|
|
112 **
|
|
113 ** Resources
|
|
114 **
|
|
115 */
|
0
|
116 #define offset(field) XtOffset(XlwScrollBarWidget, field)
|
|
117
|
|
118 static XtResource resources[] = {
|
80
|
119 { XmNforeground, XmCForeground, XtRPixel, sizeof(Pixel),
|
2
|
120 offset(sb.foreground), XtRImmediate, (XtPointer) XtDefaultForeground },
|
|
121
|
80
|
122 { XmNtopShadowColor, XmCTopShadowColor, XtRPixel,
|
2
|
123 sizeof(Pixel), offset(sb.topShadowColor), XtRImmediate, (XtPointer) ~0 },
|
80
|
124 { XmNbottomShadowColor, XmCBottomShadowColor, XtRPixel,
|
2
|
125 sizeof(Pixel), offset(sb.bottomShadowColor), XtRImmediate,
|
|
126 (XtPointer)~0 },
|
0
|
127
|
80
|
128 { XmNtopShadowPixmap, XmCTopShadowPixmap, XtRPixmap,
|
2
|
129 sizeof (Pixmap), offset(sb.topShadowPixmap), XtRImmediate,
|
|
130 (XtPointer)None},
|
80
|
131 { XmNbottomShadowPixmap, XmCBottomShadowPixmap,
|
2
|
132 XtRPixmap, sizeof (Pixmap), offset(sb.bottomShadowPixmap),
|
|
133 XtRImmediate, (XtPointer)None},
|
0
|
134
|
80
|
135 { XmNtroughColor, XmCTroughColor, XtRPixel, sizeof(Pixel),
|
0
|
136 offset(sb.troughColor), XtRImmediate, (XtPointer)~0 },
|
|
137
|
80
|
138 { XmNshadowThickness, XmCShadowThickness, XtRInt,
|
2
|
139 sizeof(int), offset(sb.shadowThickness), XtRImmediate, (XtPointer)2 },
|
0
|
140
|
80
|
141 { XmNborderWidth, XmCBorderWidth, XtRDimension,
|
2
|
142 sizeof(Dimension), offset(core.border_width), XtRImmediate,
|
|
143 (XtPointer)0 },
|
0
|
144
|
80
|
145 { XmNshowArrows, XmCShowArrows, XtRBoolean,
|
2
|
146 sizeof(Boolean), offset(sb.showArrows), XtRImmediate, (XtPointer)True },
|
0
|
147
|
80
|
148 { XmNinitialDelay, XmCInitialDelay, XtRInt, sizeof(int),
|
0
|
149 offset(sb.initialDelay), XtRImmediate, (XtPointer) 250 },
|
80
|
150 { XmNrepeatDelay, XmCRepeatDelay, XtRInt, sizeof(int),
|
0
|
151 offset(sb.repeatDelay), XtRImmediate, (XtPointer) 50 },
|
|
152
|
80
|
153 { XmNorientation, XmCOrientation, XtROrientation,
|
2
|
154 sizeof(unsigned char), offset(sb.orientation), XtRImmediate,
|
|
155 (XtPointer) XmVERTICAL },
|
0
|
156
|
80
|
157 { XmNminimum, XmCMinimum, XtRInt, sizeof(int),
|
0
|
158 offset(sb.minimum), XtRImmediate, (XtPointer) 0},
|
80
|
159 { XmNmaximum, XmCMaximum, XtRInt, sizeof(int),
|
0
|
160 offset(sb.maximum), XtRImmediate, (XtPointer) 100},
|
80
|
161 { XmNvalue, XmCValue, XtRInt, sizeof(int),
|
0
|
162 offset(sb.value), XtRImmediate, (XtPointer) 0},
|
80
|
163 { XmNsliderSize, XmCSliderSize, XtRInt, sizeof(int),
|
0
|
164 offset(sb.sliderSize), XtRImmediate, (XtPointer) 10},
|
80
|
165 { XmNincrement, XmCIncrement, XtRInt, sizeof(int),
|
0
|
166 offset(sb.increment), XtRImmediate, (XtPointer) 1},
|
80
|
167 { XmNpageIncrement, XmCPageIncrement, XtRInt, sizeof(int),
|
0
|
168 offset(sb.pageIncrement), XtRImmediate, (XtPointer) 10},
|
|
169
|
80
|
170 { XmNvalueChangedCallback, XmCValueChangedCallback,
|
2
|
171 XtRCallback, sizeof(XtPointer), offset(sb.valueChangedCBL),
|
|
172 XtRCallback, NULL},
|
80
|
173 { XmNincrementCallback, XmCIncrementCallback,
|
2
|
174 XtRCallback, sizeof(XtPointer), offset(sb.incrementCBL),
|
|
175 XtRCallback, NULL},
|
80
|
176 { XmNdecrementCallback, XmCDecrementCallback,
|
2
|
177 XtRCallback, sizeof(XtPointer), offset(sb.decrementCBL),
|
|
178 XtRCallback, NULL},
|
80
|
179 { XmNpageIncrementCallback, XmCPageIncrementCallback,
|
2
|
180 XtRCallback, sizeof(XtPointer), offset(sb.pageIncrementCBL),
|
|
181 XtRCallback, NULL},
|
80
|
182 { XmNpageDecrementCallback, XmCPageDecrementCallback,
|
2
|
183 XtRCallback, sizeof(XtPointer), offset(sb.pageDecrementCBL),
|
|
184 XtRCallback, NULL},
|
80
|
185 { XmNtoTopCallback, XmCToTopCallback, XtRCallback,
|
2
|
186 sizeof(XtPointer), offset(sb.toTopCBL), XtRCallback, NULL},
|
80
|
187 { XmNtoBottomCallback, XmCToBottomCallback, XtRCallback,
|
2
|
188 sizeof(XtPointer), offset(sb.toBottomCBL), XtRCallback, NULL},
|
80
|
189 { XmNdragCallback, XmCDragCallback, XtRCallback,
|
2
|
190 sizeof(XtPointer), offset(sb.dragCBL), XtRCallback, NULL},
|
0
|
191
|
80
|
192 { XmNknobStyle, XmCKnobStyle, XtRString, sizeof(char *),
|
70
|
193 offset(sb.knobStyle), XtRImmediate, NULL},
|
0
|
194
|
80
|
195 { XmNarrowPosition, XmCArrowPosition, XtRString,
|
2
|
196 sizeof(char *), offset(sb.arrowPosition), XtRImmediate, NULL},
|
0
|
197 };
|
|
198
|
70
|
199 /************************************************************************
|
|
200 **
|
|
201 ** Prototypes
|
|
202 **
|
|
203 */
|
0
|
204
|
70
|
205 /*
|
|
206 ** Actions
|
|
207 */
|
|
208 static void Select(Widget w, XEvent *event, String *parms, Cardinal *num_parms);
|
|
209 static void PageUpOrLeft(Widget w, XEvent *event, String *parms, Cardinal *num_parms);
|
|
210 static void PageDownOrRight(Widget w, XEvent *event, String *parms, Cardinal *num_parms);
|
|
211 static void Drag(Widget w, XEvent *event, String *parms, Cardinal *num_parms);
|
|
212 static void Release(Widget w, XEvent *event, String *parms, Cardinal *num_parms);
|
|
213 static void Jump(Widget w, XEvent *event, String *parms, Cardinal *num_parms);
|
|
214 static void Abort(Widget w, XEvent *event, String *parms, Cardinal *num_parms);
|
0
|
215
|
70
|
216 /*
|
|
217 ** Methods
|
|
218 */
|
0
|
219 static void Initialize(Widget treq, Widget tnew, ArgList args, Cardinal *num_args);
|
|
220 static Boolean SetValues(Widget current, Widget request, Widget nw, ArgList args, Cardinal *num_args);
|
|
221 static void Destroy(Widget widget);
|
|
222 static void Redisplay(Widget widget, XEvent *event, Region region);
|
|
223 static void Resize(Widget widget);
|
|
224 static void Realize(Widget widget, XtValueMask *valuemask, XSetWindowAttributes *attr);
|
|
225
|
70
|
226 /*
|
|
227 ** Private
|
|
228 */
|
|
229
|
0
|
230
|
70
|
231 /************************************************************************
|
|
232 **
|
|
233 ** Actions Table
|
|
234 **
|
|
235 */
|
|
236 static XtActionsRec actions[] = {
|
80
|
237 {"Select", Select},
|
|
238 {"PageDownOrRight", PageDownOrRight},
|
|
239 {"PageUpOrLeft", PageUpOrLeft},
|
|
240 {"Drag", Drag},
|
|
241 {"Release", Release},
|
|
242 {"Jump", Jump},
|
|
243 {"Abort", Abort},
|
0
|
244 };
|
|
245
|
70
|
246 /************************************************************************
|
|
247 **
|
|
248 ** Default Translation Table
|
|
249 **
|
|
250 */
|
0
|
251 static char default_translations[] =
|
70
|
252 "<Btn1Down>: Select()\n"
|
|
253 "<Btn1Motion>: Drag()\n"
|
|
254 "<Btn1Up>: Release()\n"
|
|
255 "<Btn2Down>: Jump()\n"
|
|
256 "<Btn2Motion>: Drag()\n"
|
|
257 "<Btn2Up>: Release()\n"
|
|
258 "<Key>Delete: Abort()"
|
0
|
259 ;
|
|
260
|
70
|
261 /************************************************************************
|
|
262 **
|
|
263 ** Class record initalization
|
|
264 **
|
|
265 */
|
0
|
266 XlwScrollBarClassRec xlwScrollBarClassRec = {
|
|
267 /* core_class fields */
|
|
268 {
|
|
269 /* superclass */ (WidgetClass) &coreClassRec,
|
80
|
270 /* class_name */ "XlwScrollBar",
|
0
|
271 /* widget_size */ sizeof(XlwScrollBarRec),
|
|
272 /* class_initialize */ NULL,
|
|
273 /* class_part_init */ NULL,
|
|
274 /* class_inited */ False,
|
|
275 /* initialize */ Initialize,
|
|
276 /* initialize_hook */ NULL,
|
|
277 /* realize */ Realize,
|
|
278 /* actions */ actions,
|
|
279 /* num_actions */ XtNumber(actions),
|
|
280 /* resources */ resources,
|
|
281 /* num_resources */ XtNumber(resources),
|
|
282 /* xrm_class */ NULLQUARK,
|
|
283 /* compress_motion */ True,
|
|
284 /* compress_exposure */ XtExposeCompressMultiple,
|
|
285 /* compress_enterleave */ True,
|
|
286 /* visible_interest */ False,
|
|
287 /* destroy */ Destroy,
|
|
288 /* resize */ Resize,
|
|
289 /* expose */ Redisplay,
|
|
290 /* set_values */ SetValues,
|
|
291 /* set_values_hook */ NULL,
|
|
292 /* set_values_almost */ XtInheritSetValuesAlmost,
|
|
293 /* get_values_hook */ NULL,
|
|
294 /* accept_focus */ NULL,
|
|
295 /* version */ XtVersionDontCheck,
|
|
296 /* callback_private */ NULL,
|
|
297 /* tm_table */ default_translations,
|
|
298 /* query_geometry */ NULL,
|
|
299 },
|
|
300 /* scrollbar_class fields */
|
|
301 {
|
|
302 /* dummy_field */ 0,
|
|
303 },
|
|
304 };
|
|
305
|
|
306 WidgetClass xlwScrollBarWidgetClass = (WidgetClass) &xlwScrollBarClassRec;
|
|
307
|
70
|
308 /************************************************************************
|
|
309 **
|
76
|
310 ** Debug functions
|
70
|
311 **
|
|
312 */
|
0
|
313
|
|
314 #ifdef SHOW_CLEAR
|
76
|
315 static void
|
|
316 myXClearArea(Display *dpy, Drawable d, int x, int y, int w, int h,
|
|
317 Boolean exp, XlwScrollBarWidget widget)
|
0
|
318 {
|
76
|
319 XFillRectangle (dpy, d, widget->sb.topShadowGC, x, y, w, h);
|
|
320 XSync (dpy, False);
|
|
321 sleep (2);
|
|
322 XClearArea (dpy, d, x, y, w, h, exp);
|
0
|
323 }
|
|
324
|
|
325 #define XClearArea(dpy,win,x,y,width,height,exp) myXClearArea(dpy,win,x,y,width,height,exp,w)
|
|
326 #endif
|
|
327
|
|
328 #ifdef CHECK_VALUES
|
76
|
329 static void
|
|
330 check(XlwScrollBarWidget w)
|
0
|
331 {
|
70
|
332 int height;
|
|
333
|
76
|
334 height= widget_h (w);
|
|
335 if (w->sb.showArrows) height -= (2 * arrow_h (w));
|
0
|
336
|
76
|
337 if ((w->sb.above + w->sb.ss + w->sb.below > height) ||
|
0
|
338 (w->sb.value < w->sb.minimum) ||
|
76
|
339 (w->sb.value > w->sb.maximum - w->sb.sliderSize)
|
70
|
340 )
|
76
|
341 {
|
0
|
342 printf("above=%d ss=%d below=%d height=%d\n",
|
|
343 w->sb.above, w->sb.ss, w->sb.below, height);
|
|
344 printf("value=%d min=%d max=%d ss=%d max-ss=%d\n",
|
76
|
345 w->sb.value, w->sb.minimum, w->sb.maximum,
|
|
346 w->sb.sliderSize, w->sb.maximum - w->sb.sliderSize);
|
0
|
347 abort();
|
76
|
348 }
|
0
|
349 }
|
|
350
|
|
351 # define CHECK(w) check(w)
|
|
352 #else
|
|
353 # define CHECK(w)
|
|
354 #endif
|
|
355
|
70
|
356 /************************************************************************
|
|
357 **
|
76
|
358 ** Static functions
|
70
|
359 **
|
|
360 */
|
0
|
361
|
76
|
362 static void
|
|
363 call_callbacks (XlwScrollBarWidget w, int reason,
|
|
364 int value, int pixel, XEvent *event)
|
0
|
365 {
|
|
366 XlwScrollBarCallbackStruct cbs;
|
|
367 Boolean called_anything;
|
|
368
|
76
|
369 cbs.reason = reason;
|
|
370 cbs.event = event;
|
|
371 cbs.value = value;
|
|
372 cbs.pixel = pixel;
|
0
|
373
|
|
374 called_anything = False;
|
|
375
|
76
|
376 switch (reason)
|
|
377 {
|
|
378 case XmCR_VALUE_CHANGED:
|
|
379 XtCallCallbackList ((Widget) w, w->sb.valueChangedCBL, &cbs);
|
|
380 called_anything = True;
|
|
381 break;
|
|
382 case XmCR_INCREMENT:
|
|
383 if (w->sb.incrementCBL)
|
|
384 {
|
|
385 XtCallCallbackList ((Widget) w, w->sb.incrementCBL, &cbs);
|
|
386 called_anything = True;
|
|
387 }
|
|
388 break;
|
|
389 case XmCR_DECREMENT:
|
|
390 if (w->sb.decrementCBL)
|
|
391 {
|
|
392 XtCallCallbackList ((Widget) w, w->sb.decrementCBL, &cbs);
|
|
393 called_anything = True;
|
|
394 }
|
|
395 break;
|
|
396 case XmCR_PAGE_INCREMENT:
|
|
397 if (w->sb.incrementCBL)
|
|
398 {
|
|
399 XtCallCallbackList ((Widget) w, w->sb.pageIncrementCBL, &cbs);
|
0
|
400 called_anything = True;
|
76
|
401 }
|
|
402 break;
|
|
403 case XmCR_PAGE_DECREMENT:
|
|
404 if (w->sb.decrementCBL)
|
|
405 {
|
|
406 XtCallCallbackList ((Widget) w, w->sb.pageDecrementCBL, &cbs);
|
|
407 called_anything = True;
|
|
408 }
|
|
409 break;
|
|
410 case XmCR_TO_TOP:
|
|
411 if (w->sb.toTopCBL)
|
|
412 {
|
|
413 XtCallCallbackList ((Widget) w, w->sb.toTopCBL, &cbs);
|
|
414 called_anything = True;
|
|
415 }
|
|
416 break;
|
|
417 case XmCR_TO_BOTTOM:
|
|
418 if (w->sb.toBottomCBL)
|
|
419 {
|
|
420 XtCallCallbackList ((Widget) w, w->sb.toBottomCBL, &cbs);
|
|
421 called_anything = True;
|
|
422 }
|
|
423 break;
|
|
424 case XmCR_DRAG:
|
|
425 if (w->sb.dragCBL)
|
|
426 {
|
|
427 XtCallCallbackList ((Widget) w, w->sb.dragCBL, &cbs);
|
|
428 }
|
|
429 called_anything = True; /* Special Case */
|
|
430 break;
|
|
431 }
|
0
|
432
|
76
|
433 if (!called_anything)
|
|
434 {
|
0
|
435 cbs.reason = XmCR_VALUE_CHANGED;
|
76
|
436 XtCallCallbackList ((Widget) w, w->sb.valueChangedCBL, &cbs);
|
|
437 }
|
0
|
438 }
|
|
439
|
70
|
440 /*
|
|
441 ** Widget sizes minus the shadow and highlight area
|
|
442 */
|
76
|
443 static int
|
|
444 widget_x (XlwScrollBarWidget w)
|
70
|
445 {
|
76
|
446 return w->sb.shadowThickness;
|
70
|
447 }
|
26
|
448
|
76
|
449 static int
|
|
450 widget_y (XlwScrollBarWidget w)
|
0
|
451 {
|
76
|
452 return w->sb.shadowThickness;
|
0
|
453 }
|
|
454
|
76
|
455 static int
|
|
456 widget_w (XlwScrollBarWidget w)
|
0
|
457 {
|
70
|
458 int width, x = w->sb.shadowThickness;
|
0
|
459
|
76
|
460 width = VERT (w) ? w->core.width : w->core.height;
|
70
|
461
|
76
|
462 if (width <= (2 * x))
|
|
463 return 1;
|
70
|
464 else
|
76
|
465 return width - (2 * x);
|
0
|
466 }
|
|
467
|
76
|
468 static int
|
|
469 widget_h (XlwScrollBarWidget w)
|
0
|
470 {
|
70
|
471 int height, y = w->sb.shadowThickness;
|
|
472
|
76
|
473 height = VERT (w) ? w->core.height : w->core.width;
|
0
|
474
|
76
|
475 if (height <= (2 * y))
|
|
476 return 1;
|
70
|
477 else
|
76
|
478 return height - (2 * y);
|
0
|
479 }
|
|
480
|
76
|
481 static int
|
|
482 arrow_h (XlwScrollBarWidget w)
|
0
|
483 {
|
70
|
484 int width, height;
|
|
485
|
76
|
486 width = widget_w (w);
|
|
487 height= widget_h (w);
|
70
|
488
|
76
|
489 if (width > ((height / 2) - (SS_MIN / 2) - 1))
|
|
490 return (height / 2) - (SS_MIN / 2) - 1 ;
|
70
|
491 else
|
76
|
492 return width;
|
0
|
493 }
|
|
494
|
76
|
495 static int
|
|
496 event_x (XlwScrollBarWidget w, XEvent *event)
|
0
|
497 {
|
76
|
498 return VERT (w) ? event->xbutton.x : event->xbutton.y;
|
0
|
499 }
|
|
500
|
76
|
501 static int
|
|
502 event_y (XlwScrollBarWidget w, XEvent *event)
|
0
|
503 {
|
76
|
504 return VERT (w) ? event->xbutton.y : event->xbutton.x;
|
0
|
505 }
|
|
506
|
70
|
507 /*
|
|
508 ** Safe addition and subtraction
|
|
509 */
|
76
|
510 static int
|
|
511 safe_add (int a, int b)
|
0
|
512 {
|
76
|
513 if (a > 0 && INT_MAX - a < b) return INT_MAX;
|
|
514 else return a + b;
|
0
|
515 }
|
|
516
|
76
|
517 static int
|
|
518 safe_subtract (int a, int b)
|
0
|
519 {
|
76
|
520 if (a < 0 && -(INT_MIN - a) < b) return INT_MIN;
|
|
521 else return a - b;
|
0
|
522 }
|
|
523
|
76
|
524 static int
|
|
525 knob_style (XlwScrollBarWidget w)
|
0
|
526 {
|
76
|
527 return w->sb.knobStyle && w->sb.knobStyle[0] == 'd' ?
|
|
528 KNOB_DIMPLE :
|
|
529 KNOB_PLAIN;
|
|
530 }
|
|
531
|
|
532 static Boolean
|
|
533 arrow_same_end (XlwScrollBarWidget w)
|
|
534 {
|
|
535 return w->sb.arrowPosition && w->sb.arrowPosition[0] == 's' ? True : False;
|
10
|
536 }
|
|
537
|
70
|
538 /*
|
|
539 ** GC and Pixel allocation
|
|
540 */
|
76
|
541 static GC
|
|
542 get_gc (XlwScrollBarWidget w, Pixel fg, Pixel bg, Pixmap pm)
|
0
|
543 {
|
|
544 XGCValues values;
|
|
545 XtGCMask mask;
|
|
546
|
76
|
547 if (pm == w->sb.grayPixmap)
|
|
548 {
|
0
|
549 /* If we're using the gray pixmap, guarantee white on black ...
|
|
550 * otherwise, we could end up with something odd like grey on white
|
|
551 * when we're on a color display that ran out of color cells
|
|
552 */
|
|
553
|
76
|
554 fg = WhitePixelOfScreen (DefaultScreenOfDisplay (XtDisplay (w)));
|
|
555 bg = BlackPixelOfScreen (DefaultScreenOfDisplay (XtDisplay (w)));
|
|
556 }
|
0
|
557
|
|
558 values.foreground = fg;
|
|
559 values.background = bg;
|
|
560 values.fill_style = FillOpaqueStippled;
|
|
561 values.stipple = pm;
|
70
|
562 mask = GCForeground | GCBackground |
|
76
|
563 (pm == None ? 0 : GCStipple | GCFillStyle);
|
|
564 return XtGetGC((Widget) w, mask, &values);
|
0
|
565 }
|
|
566
|
|
567 /* Replacement for XAllocColor() that tries to return the nearest
|
|
568 available color if the colormap is full. From FSF Emacs. */
|
|
569
|
|
570 static int
|
|
571 allocate_nearest_color (Display *display, Colormap screen_colormap,
|
|
572 XColor *color_def)
|
|
573 {
|
76
|
574 int status = XAllocColor (display, screen_colormap, color_def);
|
|
575 if (status)
|
|
576 return status;
|
0
|
577
|
|
578 {
|
|
579 /* If we got to this point, the colormap is full, so we're
|
76
|
580 going to try to get the next closest color.
|
0
|
581 The algorithm used is a least-squares matching, which is
|
|
582 what X uses for closest color matching with StaticColor visuals. */
|
|
583
|
76
|
584 int nearest, x;
|
80
|
585 unsigned long nearest_delta = ULONG_MAX;
|
0
|
586
|
76
|
587 int no_cells = XDisplayCells (display, XDefaultScreen (display));
|
0
|
588 /* Don't use alloca here because lwlib doesn't have the
|
|
589 necessary configuration information that src does. */
|
76
|
590 XColor *cells = (XColor *) malloc (sizeof (XColor) * no_cells);
|
0
|
591
|
|
592 for (x = 0; x < no_cells; x++)
|
|
593 cells[x].pixel = x;
|
|
594
|
|
595 XQueryColors (display, screen_colormap, cells, no_cells);
|
76
|
596
|
80
|
597 for (nearest = 0, x = 0; x < no_cells; x++)
|
0
|
598 {
|
76
|
599 long dred = (color_def->red >> 8) - (cells[x].red >> 8);
|
|
600 long dgreen = (color_def->green >> 8) - (cells[x].green >> 8);
|
|
601 long dblue = (color_def->blue >> 8) - (cells[x].blue >> 8);
|
80
|
602 unsigned long delta = dred * dred + dgreen * dgreen + dblue * dblue;
|
76
|
603
|
80
|
604 if (delta < nearest_delta)
|
0
|
605 {
|
|
606 nearest = x;
|
80
|
607 nearest_delta = delta;
|
0
|
608 }
|
|
609 }
|
76
|
610 color_def->red = cells[nearest].red;
|
0
|
611 color_def->green = cells[nearest].green;
|
76
|
612 color_def->blue = cells[nearest].blue;
|
0
|
613 free (cells);
|
76
|
614 return XAllocColor (display, screen_colormap, color_def);
|
0
|
615 }
|
|
616 }
|
|
617
|
76
|
618 static void
|
|
619 make_shadow_pixels (XlwScrollBarWidget w)
|
0
|
620 {
|
|
621 Display *dpy = XtDisplay((Widget) w);
|
|
622 Colormap cmap = w->core.colormap;
|
|
623 XColor topc, botc;
|
|
624 int top_frobbed, bottom_frobbed;
|
|
625 Pixel bg, fg;
|
|
626
|
|
627 top_frobbed = bottom_frobbed = 0;
|
|
628
|
|
629 bg = w->core.background_pixel;
|
|
630 fg = w->sb.foreground;
|
|
631
|
76
|
632 if (w->sb.topShadowColor == (Pixel)~0) w->sb.topShadowColor = bg;
|
|
633 if (w->sb.bottomShadowColor == (Pixel)~0) w->sb.bottomShadowColor = fg;
|
0
|
634
|
76
|
635 if (w->sb.topShadowColor == bg || w->sb.topShadowColor == fg)
|
|
636 {
|
0
|
637 topc.pixel = bg;
|
76
|
638 XQueryColor (dpy, cmap, &topc);
|
0
|
639 /* don't overflow/wrap! */
|
|
640 topc.red = MINL(65535, topc.red * 1.2);
|
|
641 topc.green = MINL(65535, topc.green * 1.2);
|
|
642 topc.blue = MINL(65535, topc.blue * 1.2);
|
76
|
643 if (allocate_nearest_color (dpy, cmap, &topc))
|
|
644 {
|
|
645 if (topc.pixel == bg)
|
|
646 {
|
|
647 XFreeColors (dpy, cmap, &topc.pixel, 1, 0);
|
0
|
648 topc.red = MINL(65535, topc.red + 0x8000);
|
|
649 topc.green = MINL(65535, topc.green + 0x8000);
|
|
650 topc.blue = MINL(65535, topc.blue + 0x8000);
|
76
|
651 if (allocate_nearest_color (dpy, cmap, &topc))
|
|
652 {
|
0
|
653 w->sb.topShadowColor = topc.pixel;
|
76
|
654 }
|
|
655 }
|
0
|
656 else
|
76
|
657 {
|
0
|
658 w->sb.topShadowColor = topc.pixel;
|
76
|
659 }
|
0
|
660
|
|
661 top_frobbed = 1;
|
76
|
662 }
|
|
663 }
|
0
|
664
|
76
|
665 if (w->sb.bottomShadowColor == fg || w->sb.bottomShadowColor == bg)
|
|
666 {
|
0
|
667 botc.pixel = bg;
|
76
|
668 XQueryColor (dpy, cmap, &botc);
|
0
|
669 botc.red *= 0.6;
|
|
670 botc.green *= 0.6;
|
|
671 botc.blue *= 0.6;
|
76
|
672 if (allocate_nearest_color (dpy, cmap, &botc))
|
|
673 {
|
|
674 if (botc.pixel == bg)
|
|
675 {
|
|
676 XFreeColors (dpy, cmap, &botc.pixel, 1, 0);
|
0
|
677 botc.red = MINL(65535, botc.red + 0x4000);
|
|
678 botc.green = MINL(65535, botc.green + 0x4000);
|
|
679 botc.blue = MINL(65535, botc.blue + 0x4000);
|
76
|
680 if (allocate_nearest_color (dpy, cmap, &botc))
|
|
681 {
|
0
|
682 w->sb.bottomShadowColor = botc.pixel;
|
76
|
683 }
|
|
684 }
|
0
|
685 else
|
76
|
686 {
|
0
|
687 w->sb.bottomShadowColor = botc.pixel;
|
76
|
688 }
|
0
|
689 bottom_frobbed = 1;
|
76
|
690 }
|
|
691 }
|
0
|
692
|
76
|
693 if (top_frobbed && bottom_frobbed)
|
|
694 {
|
0
|
695 int top_avg = ((topc.red / 3) + (topc.green / 3) + (topc.blue / 3));
|
|
696 int bot_avg = ((botc.red / 3) + (botc.green / 3) + (botc.blue / 3));
|
76
|
697 if (bot_avg > top_avg)
|
|
698 {
|
0
|
699 Pixel tmp = w->sb.topShadowColor;
|
|
700 w->sb.topShadowColor = w->sb.bottomShadowColor;
|
|
701 w->sb.bottomShadowColor = tmp;
|
76
|
702 }
|
|
703 else if (topc.pixel == botc.pixel)
|
|
704 {
|
|
705 if (botc.pixel == bg)
|
|
706 w->sb.topShadowColor = bg;
|
0
|
707 else
|
76
|
708 w->sb.bottomShadowColor = fg;
|
|
709 }
|
|
710 }
|
0
|
711
|
76
|
712 if (w->sb.topShadowColor == w->core.background_pixel ||
|
|
713 w->sb.bottomShadowColor == w->core.background_pixel)
|
|
714 {
|
0
|
715 /* Assume we're in mono. This code should be okay even if we're
|
|
716 * really in color but just short on color cells -- We want the
|
|
717 * following behavior, which has been empirically determined to
|
|
718 * work well for all fg/bg combinations in mono: If the trough
|
70
|
719 * and thumb are BOTH black, then use a white top shadow and a
|
0
|
720 * grey bottom shadow, otherwise use a grey top shadow and a
|
|
721 * black bottom shadow.
|
|
722 */
|
|
723
|
76
|
724 Pixel white = WhitePixelOfScreen (DefaultScreenOfDisplay (XtDisplay (w)));
|
|
725 Pixel black = BlackPixelOfScreen (DefaultScreenOfDisplay (XtDisplay (w)));
|
0
|
726
|
70
|
727 /* Note: core.background_pixel is the color of the thumb ... */
|
0
|
728
|
|
729 if (w->core.background_pixel == black &&
|
76
|
730 w->sb.troughColor == black)
|
|
731 {
|
|
732 w->sb.topShadowColor = white;
|
|
733 w->sb.bottomShadowPixmap = w->sb.grayPixmap;
|
|
734 } else {
|
|
735 w->sb.topShadowPixmap = w->sb.grayPixmap;
|
|
736 w->sb.bottomShadowColor = black;
|
|
737 }
|
|
738 }
|
0
|
739 }
|
|
740
|
76
|
741 static void
|
|
742 make_trough_pixel (XlwScrollBarWidget w)
|
0
|
743 {
|
|
744 Display *dpy = XtDisplay((Widget) w);
|
76
|
745 Colormap cmap = DefaultColormapOfScreen (XtScreen ((Widget) w));
|
0
|
746 XColor troughC;
|
|
747
|
76
|
748 if (w->sb.troughColor == (Pixel)~0) w->sb.troughColor = w->core.background_pixel;
|
0
|
749
|
76
|
750 if (w->sb.troughColor == w->core.background_pixel)
|
|
751 {
|
0
|
752 troughC.pixel = w->core.background_pixel;
|
76
|
753 XQueryColor (dpy, cmap, &troughC);
|
0
|
754 troughC.red *= 0.8;
|
|
755 troughC.green *= 0.8;
|
|
756 troughC.blue *= 0.8;
|
76
|
757 if (allocate_nearest_color (dpy, cmap, &troughC))
|
|
758 w->sb.troughColor = troughC.pixel;
|
|
759 }
|
0
|
760 }
|
|
761
|
70
|
762 /*
|
|
763 ** Draw 3d border
|
|
764 */
|
76
|
765 static void
|
|
766 draw_shadows (Display *dpy, Drawable d, GC shine_gc, GC shadow_gc,
|
|
767 int x, int y, int width, int height, int shadowT)
|
0
|
768 {
|
76
|
769 XSegment shine[10], shadow[10];
|
|
770 int i;
|
0
|
771
|
76
|
772 if (shadowT > (width / 2)) shadowT = (width / 2);
|
|
773 if (shadowT > (height / 2)) shadowT = (height / 2);
|
|
774 if (shadowT <= 0) return;
|
0
|
775
|
76
|
776 for (i = 0; i < shadowT; i++)
|
|
777 {
|
|
778 /* Top segments */
|
|
779 shine[i].x1 = x;
|
|
780 shine[i].y2 = shine[i].y1 = y + i;
|
|
781 shine[i].x2 = x + width - i - 1;
|
|
782 /* Left segments */
|
|
783 shine[i + shadowT].x2 = shine[i + shadowT].x1 = x + i;
|
|
784 shine[i + shadowT].y1 = y + shadowT;
|
|
785 shine[i + shadowT].y2 = y + height - i - 1;
|
0
|
786
|
76
|
787 /* Bottom segments */
|
|
788 shadow[i].x1 = x + i;
|
|
789 shadow[i].y2 = shadow[i].y1 = y + height - i - 1;
|
|
790 shadow[i].x2 = x + width - 1 ;
|
|
791 /* Right segments */
|
|
792 shadow[i + shadowT].x2 = shadow[i + shadowT].x1 = x + width - i - 1;
|
|
793 shadow[i + shadowT].y1 = y + i + 1;
|
|
794 shadow[i + shadowT].y2 = y + height - 1 ;
|
|
795 }
|
0
|
796
|
76
|
797 XDrawSegments (dpy, d, shine_gc, shine, shadowT * 2);
|
|
798 XDrawSegments (dpy, d, shadow_gc, shadow, shadowT * 2);
|
0
|
799 }
|
|
800
|
70
|
801 /*
|
|
802 ** Draw 3d arrows, left, up, down, and right
|
|
803 */
|
76
|
804 static int
|
|
805 make_vert_seg (XSegment *seg, int x1, int y1, int x2, int y2, int shadowT)
|
0
|
806 {
|
|
807 int i;
|
|
808
|
76
|
809 for (i=0; i<shadowT; i++)
|
|
810 {
|
70
|
811 seg[i].x1 = x1;
|
|
812 seg[i].y1 = y1 + i;
|
|
813 seg[i].x2 = x2;
|
|
814 seg[i].y2 = y2 + i;
|
76
|
815 }
|
|
816 return shadowT;
|
0
|
817 }
|
|
818
|
76
|
819 static int
|
|
820 make_hor_seg (XSegment *seg, int x1, int y1, int x2, int y2, int shadowT)
|
0
|
821 {
|
|
822 int i;
|
|
823
|
76
|
824 for (i=0; i<shadowT; i++)
|
|
825 {
|
70
|
826 seg[i].x1 = x1 + i;
|
|
827 seg[i].y1 = y1;
|
|
828 seg[i].x2 = x2 + i;
|
|
829 seg[i].y2 = y2;
|
76
|
830 }
|
|
831 return shadowT;
|
0
|
832 }
|
|
833
|
76
|
834 static void
|
|
835 draw_arrow_up (Display *dpy, Drawable win, GC bgGC, GC shineGC, GC shadowGC,
|
|
836 int x, int y, int width, int height, int shadowT)
|
0
|
837 {
|
|
838 XSegment shine[10], shadow[10];
|
|
839 XPoint triangle[3];
|
|
840 int mid;
|
|
841
|
|
842 mid = width / 2;
|
|
843
|
76
|
844 if (shadowT > (width / 2)) shadowT = (width / 2);
|
|
845 if (shadowT > (height / 2)) shadowT = (height / 2);
|
|
846 if (shadowT <= 0) shadowT = 0;
|
0
|
847
|
|
848 /* / */
|
76
|
849 make_vert_seg (shine,
|
70
|
850 x, y + height - shadowT - 1,
|
76
|
851 x + mid, y, shadowT);
|
0
|
852 /* _\ */
|
76
|
853 make_vert_seg (shadow,
|
70
|
854 x, y + height - shadowT - 1,
|
76
|
855 x + width - 1, y + height - shadowT - 1, shadowT);
|
|
856 make_vert_seg (shadow + shadowT,
|
70
|
857 x + mid, y,
|
76
|
858 x + width - 1, y + height - shadowT - 1, shadowT);
|
0
|
859
|
|
860 triangle[0].x = x;
|
|
861 triangle[0].y = y + height - 1;
|
|
862 triangle[1].x = x + mid;
|
|
863 triangle[1].y = y;
|
|
864 triangle[2].x = x + width - 1;
|
|
865 triangle[2].y = y + height - 1;
|
|
866
|
76
|
867 XFillPolygon (dpy, win, bgGC, triangle, 3, Convex, ArcChord);
|
0
|
868
|
76
|
869 XDrawSegments (dpy, win, shadowGC, shadow, shadowT * 2);
|
|
870 XDrawSegments (dpy, win, shineGC, shine, shadowT);
|
0
|
871 }
|
|
872
|
76
|
873 static void
|
|
874 draw_arrow_left (Display *dpy, Drawable win, GC bgGC, GC shineGC, GC shadowGC,
|
|
875 int x, int y, int width, int height, int shadowT)
|
0
|
876 {
|
|
877 XSegment shine[10], shadow[10];
|
|
878 XPoint triangle[3];
|
70
|
879 int mid;
|
0
|
880
|
70
|
881 mid = width / 2;
|
0
|
882
|
76
|
883 if (shadowT > (width / 2)) shadowT = (width / 2);
|
|
884 if (shadowT > (height / 2)) shadowT = (height / 2);
|
|
885 if (shadowT <= 0) shadowT = 0;
|
0
|
886
|
|
887 /* / */
|
76
|
888 make_hor_seg (shine,
|
|
889 x, y + mid,
|
|
890 x + width - shadowT - 1, y, shadowT);
|
0
|
891 /* \| */
|
76
|
892 make_hor_seg (shadow,
|
|
893 x, y + mid,
|
|
894 x + width - shadowT - 1, y + height - 1, shadowT);
|
|
895 make_hor_seg (shadow + shadowT,
|
|
896 x + width - shadowT - 1, y,
|
|
897 x + width - shadowT - 1, y + height - 1, shadowT);
|
0
|
898
|
|
899 triangle[0].x = x + width - 1;
|
|
900 triangle[0].y = y + height - 1;
|
|
901 triangle[1].x = x;
|
|
902 triangle[1].y = y + mid;
|
|
903 triangle[2].x = x + width - 1;
|
|
904 triangle[2].y = y;
|
|
905
|
76
|
906 XFillPolygon (dpy, win, bgGC, triangle, 3, Convex, ArcChord);
|
0
|
907
|
76
|
908 XDrawSegments (dpy, win, shadowGC, shadow, shadowT * 2);
|
|
909 XDrawSegments (dpy, win, shineGC, shine, shadowT);
|
0
|
910 }
|
|
911
|
76
|
912 static void
|
|
913 draw_arrow_down (Display *dpy, Drawable win, GC bgGC, GC shineGC, GC shadowGC,
|
|
914 int x, int y, int width, int height, int shadowT)
|
0
|
915 {
|
|
916 XSegment shine[10], shadow[10];
|
|
917 XPoint triangle[3];
|
|
918 int mid;
|
|
919
|
|
920 mid = width / 2;
|
|
921
|
76
|
922 if (shadowT > (width / 2)) shadowT = (width / 2);
|
|
923 if (shadowT > (height / 2)) shadowT = (height / 2);
|
|
924 if (shadowT <= 0) shadowT = 0;
|
0
|
925
|
|
926 /* \- */
|
76
|
927 make_vert_seg (shine,
|
70
|
928 x, y,
|
76
|
929 x + mid, y + height - shadowT - 1, shadowT);
|
|
930 make_vert_seg (shine + shadowT,
|
70
|
931 x, y,
|
76
|
932 x + width - 1, y, shadowT);
|
0
|
933 /* / */
|
76
|
934 make_vert_seg (shadow,
|
0
|
935 x + width - 1, y,
|
76
|
936 x + mid, y + height - shadowT - 1, shadowT);
|
0
|
937
|
|
938 triangle[0].x = x;
|
|
939 triangle[0].y = y;
|
|
940 triangle[1].x = x + mid;
|
|
941 triangle[1].y = y + height - 1;
|
|
942 triangle[2].x = x + width - 1;
|
|
943 triangle[2].y = y;
|
|
944
|
76
|
945 XFillPolygon (dpy, win, bgGC, triangle, 3, Convex, ArcChord);
|
0
|
946
|
76
|
947 XDrawSegments (dpy, win, shadowGC, shadow, shadowT);
|
|
948 XDrawSegments (dpy, win, shineGC, shine, shadowT * 2);
|
0
|
949 }
|
|
950
|
76
|
951 static void
|
|
952 draw_arrow_right (Display *dpy, Drawable win, GC bgGC, GC shineGC, GC shadowGC,
|
|
953 int x, int y, int width, int height, int shadowT)
|
0
|
954 {
|
|
955 XSegment shine[10], shadow[10];
|
|
956 XPoint triangle[3];
|
|
957 int mid;
|
|
958
|
|
959 mid = width / 2;
|
|
960
|
76
|
961 if (shadowT > (width / 2)) shadowT = (width / 2);
|
|
962 if (shadowT > (height / 2)) shadowT = (height / 2);
|
|
963 if (shadowT <= 0) shadowT = 0;
|
0
|
964
|
|
965 /* |\ */
|
76
|
966 make_hor_seg (shine,
|
70
|
967 x, y,
|
76
|
968 x + width - shadowT - 1, y + mid, shadowT);
|
|
969 make_hor_seg (shine + shadowT,
|
0
|
970 x, y,
|
76
|
971 x, y + height -1, shadowT);
|
0
|
972 /* / */
|
76
|
973 make_hor_seg (shadow,
|
70
|
974 x, y + height -1,
|
76
|
975 x + width - shadowT - 1, y + mid, shadowT);
|
0
|
976
|
|
977 triangle[0].x = x + 1;
|
|
978 triangle[0].y = y + height - 1;
|
70
|
979 triangle[1].x = x + width - 1;
|
0
|
980 triangle[1].y = y + mid;
|
|
981 triangle[2].x = x + 1;
|
|
982 triangle[2].y = y;
|
|
983
|
76
|
984 XFillPolygon (dpy, win, bgGC, triangle, 3, Convex, ArcChord);
|
0
|
985
|
76
|
986 XDrawSegments (dpy, win, shadowGC, shadow, shadowT);
|
|
987 XDrawSegments (dpy, win, shineGC, shine, shadowT * 2);
|
0
|
988 }
|
|
989
|
76
|
990 static void
|
|
991 draw_dimple (Display *dpy, Drawable win, GC shine, GC shadow,
|
|
992 int x, int y, int width, int height)
|
0
|
993 {
|
76
|
994 XDrawArc (dpy, win, shine, x, y, width, height, 46*64, 180*64);
|
|
995 XDrawArc (dpy, win, shadow, x, y, width, height, 45*64, -179*64);
|
0
|
996 }
|
|
997
|
70
|
998 /*
|
|
999 ** Scrollbar values -> pixels, pixels -> scrollbar values
|
|
1000 */
|
0
|
1001
|
76
|
1002 static void
|
|
1003 seg_pixel_sizes (XlwScrollBarWidget w, int *above_return,
|
|
1004 int *ss_return, int *below_return)
|
0
|
1005 {
|
|
1006 float total, height, fuz;
|
|
1007 int value;
|
|
1008 int above, ss, below;
|
|
1009
|
76
|
1010 height= widget_h (w);
|
|
1011 if (w->sb.showArrows) height -= (2 * arrow_h (w));
|
0
|
1012
|
|
1013 value = w->sb.value - w->sb.minimum;
|
|
1014
|
|
1015 total = w->sb.maximum - w->sb.minimum;
|
|
1016 fuz = total / 2;
|
|
1017
|
|
1018 ss = ((height * w->sb.sliderSize + fuz) / total);
|
|
1019 above = ((height * value + fuz) / total);
|
|
1020 below = ((height) - (ss + above));
|
|
1021
|
70
|
1022 /* Dont' let knob get smaller than SS_MIN */
|
76
|
1023 if (ss < SS_MIN)
|
|
1024 {
|
|
1025 /* add a percent amount for integer rounding */
|
|
1026 float tmp = ((((float) (SS_MIN - ss) * (float) value)) / total) + 0.5;
|
0
|
1027
|
76
|
1028 above -= (int) tmp;
|
70
|
1029 ss = SS_MIN;
|
0
|
1030 below = ((height) - (ss + above));
|
|
1031
|
76
|
1032 if (above < 0)
|
|
1033 {
|
0
|
1034 above = 0;
|
|
1035 below = height - ss;
|
76
|
1036 }
|
|
1037 if (below < 0)
|
|
1038 {
|
0
|
1039 above = height - ss;
|
|
1040 below = 0;
|
76
|
1041 }
|
|
1042 if (ss > height)
|
|
1043 {
|
0
|
1044 above = 0;
|
|
1045 ss = height;
|
|
1046 below = 0;
|
76
|
1047 }
|
|
1048 }
|
0
|
1049
|
|
1050 *above_return = above;
|
|
1051 *ss_return = ss;
|
|
1052 *below_return = below;
|
|
1053
|
76
|
1054 CHECK (w);
|
0
|
1055 }
|
|
1056
|
76
|
1057 static void
|
|
1058 verify_values (XlwScrollBarWidget w)
|
0
|
1059 {
|
|
1060 int total = w->sb.maximum - w->sb.minimum;
|
|
1061
|
76
|
1062 if (w->sb.sliderSize > total)
|
0
|
1063 w->sb.sliderSize = total;
|
76
|
1064
|
|
1065 if (w->sb.pageIncrement > total)
|
0
|
1066 w->sb.pageIncrement = total;
|
76
|
1067
|
|
1068 if (w->sb.increment > total)
|
0
|
1069 w->sb.increment = total;
|
76
|
1070
|
|
1071 if (w->sb.value < w->sb.minimum)
|
0
|
1072 w->sb.value = w->sb.minimum;
|
76
|
1073
|
|
1074 if (w->sb.value > w->sb.maximum - w->sb.sliderSize)
|
70
|
1075 w->sb.value = w->sb.maximum - w->sb.sliderSize;
|
0
|
1076 }
|
|
1077
|
76
|
1078 static int
|
|
1079 value_from_pixel (XlwScrollBarWidget w, int above)
|
0
|
1080 {
|
|
1081 float total, height, fuz;
|
|
1082 int value, ss;
|
|
1083
|
76
|
1084 height= widget_h (w);
|
|
1085 if (w->sb.showArrows) height -= (2 * arrow_h (w));
|
0
|
1086
|
|
1087 total = w->sb.maximum - w->sb.minimum;
|
76
|
1088 fuz = height / 2;
|
0
|
1089
|
76
|
1090 ss = ((height * w->sb.sliderSize + (total / 2)) / total);
|
0
|
1091
|
76
|
1092 if (ss < SS_MIN)
|
|
1093 {
|
|
1094 /* add a percent amount for integer rounding */
|
0
|
1095 above += ((((SS_MIN - ss) * above) + fuz) / height);
|
76
|
1096 }
|
0
|
1097
|
|
1098 {
|
76
|
1099 /* Prevent SIGFPE's that would occur if we don't truncate the value. */
|
|
1100 float floatval = w->sb.minimum + ((float)(above * total + fuz) / height);
|
0
|
1101 if (floatval >= (float) INT_MAX)
|
|
1102 value = INT_MAX;
|
|
1103 else if (floatval <= (float) INT_MIN)
|
|
1104 value = INT_MIN;
|
|
1105 else
|
|
1106 value = floatval;
|
|
1107 }
|
|
1108
|
76
|
1109 return value;
|
0
|
1110 }
|
|
1111
|
|
1112
|
76
|
1113 static void
|
|
1114 redraw_dimple (XlwScrollBarWidget w, Display *dpy, Window win,
|
|
1115 int x, int y, int width, int height)
|
0
|
1116 {
|
70
|
1117 GC shine, shadow;
|
|
1118 int shadowT, size;
|
|
1119
|
76
|
1120 if (KNOB_DIMPLE == knob_style (w))
|
|
1121 {
|
|
1122 if (w->sb.armed == ARM_KNOB)
|
|
1123 {
|
|
1124 shine = w->sb.bottomShadowGC;
|
70
|
1125 shadow = w->sb.topShadowGC;
|
76
|
1126 }
|
70
|
1127 else
|
76
|
1128 {
|
|
1129 shine = w->sb.topShadowGC;
|
70
|
1130 shadow = w->sb.bottomShadowGC;
|
76
|
1131 }
|
70
|
1132
|
|
1133 shadowT = w->sb.shadowThickness;
|
0
|
1134
|
|
1135 x += shadowT;
|
|
1136 y += shadowT;
|
|
1137 width -= 2*shadowT;
|
|
1138 height -= 2*shadowT;
|
|
1139
|
|
1140 size = (width < height ? width : height) * 3 / 4;
|
|
1141
|
76
|
1142 if (size%2 != (width < height ? width : height)%2) size--;
|
0
|
1143
|
76
|
1144 DBUG (fprintf (stderr, "%d %d\n",
|
|
1145 x + (width / 2) - (size / 2) - 2*shadowT,
|
|
1146 width - size - shadowT));
|
0
|
1147
|
76
|
1148 draw_dimple (dpy, win, shine, shadow,
|
|
1149 x + (width / 2) - (size / 2),
|
0
|
1150 y + (height / 2) - (size / 2),
|
76
|
1151 size, size);
|
|
1152 }
|
0
|
1153 }
|
|
1154
|
76
|
1155 static void
|
|
1156 draw_knob (XlwScrollBarWidget w, int above, int ss, int below)
|
0
|
1157 {
|
76
|
1158 Display *dpy = XtDisplay ((Widget) w);
|
|
1159 Window win = XtWindow ((Widget) w);
|
70
|
1160 int x, y, width, height;
|
|
1161 int shadowT;
|
0
|
1162
|
76
|
1163 x = widget_x (w);
|
|
1164 y = widget_y (w);
|
|
1165 width = widget_w (w);
|
|
1166 height = widget_h (w);
|
70
|
1167
|
|
1168 shadowT = w->sb.shadowThickness;
|
0
|
1169
|
76
|
1170 if (shadowT > (width / 2)) shadowT = (width / 2);
|
|
1171 if (shadowT > (height / 2)) shadowT = (height / 2);
|
|
1172 if (shadowT <= 0) return;
|
0
|
1173
|
76
|
1174 if (w->sb.showArrows && !arrow_same_end (w)) y += arrow_h (w);
|
0
|
1175
|
70
|
1176 /* trough above knob */
|
76
|
1177 if (above > 0)
|
|
1178 {
|
|
1179 if (VERT (w))
|
|
1180 XClearArea (dpy, win, x, y, width, above, False);
|
0
|
1181 else
|
76
|
1182 XClearArea (dpy, win, y, x, above, width, False);
|
|
1183 }
|
0
|
1184
|
70
|
1185 /* knob */
|
76
|
1186 if (VERT (w))
|
|
1187 {
|
|
1188 draw_shadows (dpy, win, w->sb.topShadowGC, w->sb.bottomShadowGC,
|
0
|
1189 x, y + above, width, ss, shadowT);
|
76
|
1190 XFillRectangle (dpy, win,
|
70
|
1191 w->sb.backgroundGC,
|
76
|
1192 x+shadowT, y + above + shadowT, width-2*shadowT, ss-2*shadowT);
|
|
1193 redraw_dimple (w, dpy, win, x, y + above, width, ss);
|
|
1194 }
|
0
|
1195 else
|
76
|
1196 {
|
|
1197 draw_shadows (dpy, win, w->sb.topShadowGC, w->sb.bottomShadowGC,
|
0
|
1198 y + above, x, ss, width, shadowT);
|
76
|
1199 XFillRectangle (dpy, win,
|
70
|
1200 w->sb.backgroundGC,
|
76
|
1201 y + above + shadowT, x+shadowT, ss-2*shadowT, width-2*shadowT);
|
|
1202 redraw_dimple (w, dpy, win, y + above, x, ss, width);
|
|
1203 }
|
0
|
1204
|
70
|
1205 /* trough below knob */
|
76
|
1206 if (below > 0)
|
|
1207 {
|
|
1208 if (VERT (w))
|
|
1209 XClearArea (dpy, win, x, y + above + ss, width, below, False);
|
0
|
1210 else
|
76
|
1211 XClearArea (dpy, win, y + above + ss, x, below, width, False);
|
|
1212 }
|
0
|
1213
|
76
|
1214 CHECK (w);
|
0
|
1215 }
|
|
1216
|
76
|
1217 static void
|
|
1218 redraw_up_arrow (XlwScrollBarWidget w, Boolean armed, Boolean clear_behind)
|
0
|
1219 {
|
76
|
1220 Display *dpy = XtDisplay ((Widget) w);
|
|
1221 Window win = XtWindow ((Widget) w);
|
70
|
1222 GC bg, shine, shadow;
|
|
1223 int x, y, width, height, arrow_height, shadowT;
|
0
|
1224
|
76
|
1225 x = widget_x (w);
|
|
1226 y = widget_y (w);
|
|
1227 width = widget_w (w);
|
|
1228 height = widget_h (w);
|
|
1229 arrow_height = arrow_h (w);
|
0
|
1230
|
70
|
1231 shadowT = w->sb.shadowThickness;
|
|
1232 bg = w->sb.backgroundGC;
|
0
|
1233
|
76
|
1234 if (armed)
|
|
1235 {
|
70
|
1236 shine = w->sb.bottomShadowGC;
|
|
1237 shadow = w->sb.topShadowGC;
|
76
|
1238 }
|
70
|
1239 else
|
76
|
1240 {
|
70
|
1241 shine = w->sb.topShadowGC;
|
|
1242 shadow = w->sb.bottomShadowGC;
|
76
|
1243 }
|
70
|
1244
|
76
|
1245 if (VERT (w))
|
|
1246 {
|
|
1247 if (arrow_same_end (w))
|
|
1248 {
|
|
1249 y += height - 2 * arrow_h (w) + 2;
|
|
1250 }
|
|
1251 if (clear_behind)
|
|
1252 XClearArea (dpy, win, x, y, width, arrow_height + 1, False);
|
|
1253 draw_arrow_up (dpy, win, bg, shine, shadow,
|
0
|
1254 x + (width - arrow_height)/2, y,
|
76
|
1255 arrow_height, arrow_height, shadowT);
|
|
1256 }
|
0
|
1257 else
|
76
|
1258 {
|
|
1259 if (arrow_same_end (w))
|
|
1260 {
|
|
1261 y += height - 2 * arrow_h (w);
|
|
1262 }
|
|
1263 if (clear_behind)
|
|
1264 XClearArea (dpy, win, y, x, arrow_height + 1, height, False);
|
|
1265 draw_arrow_left (dpy, win, bg, shine, shadow,
|
0
|
1266 y, x + (width - arrow_height)/2,
|
76
|
1267 arrow_height, arrow_height, shadowT);
|
|
1268 }
|
0
|
1269 }
|
|
1270
|
76
|
1271 static void
|
|
1272 redraw_down_arrow (XlwScrollBarWidget w, Boolean armed, Boolean clear_behind)
|
0
|
1273 {
|
76
|
1274 Display *dpy = XtDisplay ((Widget) w);
|
|
1275 Window win = XtWindow ((Widget) w);
|
70
|
1276 GC bg, shine, shadow;
|
|
1277 int x, y, width, height, arrow_height, shadowT;
|
0
|
1278
|
76
|
1279 x = widget_x (w);
|
|
1280 y = widget_y (w);
|
|
1281 width = widget_w (w);
|
|
1282 height = widget_h (w);
|
|
1283 arrow_height = arrow_h (w);
|
0
|
1284
|
70
|
1285 shadowT = w->sb.shadowThickness;
|
|
1286 bg = w->sb.backgroundGC;
|
0
|
1287
|
76
|
1288 if (armed)
|
|
1289 {
|
|
1290 shine = w->sb.bottomShadowGC;
|
|
1291 shadow = w->sb.topShadowGC;
|
|
1292 }
|
0
|
1293 else
|
76
|
1294 {
|
|
1295 shine = w->sb.topShadowGC;
|
|
1296 shadow = w->sb.bottomShadowGC;
|
|
1297 }
|
70
|
1298
|
76
|
1299 if (VERT (w))
|
|
1300 {
|
|
1301 if (clear_behind)
|
|
1302 XClearArea (dpy, win, x, y + height - arrow_height, width,
|
|
1303 arrow_height + 1, False);
|
|
1304 draw_arrow_down (dpy, win, bg, shine, shadow,
|
|
1305 x + (width - arrow_height)/2,
|
|
1306 y + height - arrow_height + 1,
|
|
1307 arrow_height, arrow_height, shadowT);
|
|
1308 }
|
70
|
1309 else
|
76
|
1310 {
|
|
1311 if (clear_behind)
|
|
1312 XClearArea (dpy, win, y + height - arrow_height, x,
|
|
1313 arrow_height + 1, height, False);
|
|
1314 draw_arrow_right (dpy, win, bg, shine, shadow,
|
|
1315 y + height - arrow_height + 1,
|
|
1316 x + (width - arrow_height)/2,
|
|
1317 arrow_height, arrow_height, shadowT);
|
|
1318 }
|
0
|
1319 }
|
|
1320
|
76
|
1321 static void
|
|
1322 redraw_everything (XlwScrollBarWidget w, Region region, Boolean behind_arrows)
|
0
|
1323 {
|
76
|
1324 Display *dpy = XtDisplay ((Widget) w);
|
|
1325 Window win = XtWindow ((Widget) w);
|
70
|
1326 int x, y, width, height, shadowT, tmp;
|
0
|
1327
|
76
|
1328 x = widget_x (w);
|
|
1329 y = widget_y (w);
|
|
1330 width = widget_w (w);
|
|
1331 height = widget_h (w);
|
70
|
1332 shadowT = w->sb.shadowThickness;
|
26
|
1333
|
76
|
1334 if (w->sb.showArrows)
|
|
1335 {
|
|
1336 if (region == NULL || XRectInRegion (region, x, y, width, width))
|
|
1337 {
|
|
1338 redraw_up_arrow (w, False, behind_arrows);
|
|
1339 }
|
|
1340 if (VERT (w))
|
|
1341 {
|
70
|
1342 y = y + height - width + 1;
|
76
|
1343 }
|
70
|
1344 else
|
76
|
1345 {
|
70
|
1346 tmp = y;
|
|
1347 y = x;
|
|
1348 x = tmp + height - width + 1;
|
76
|
1349 }
|
|
1350 if (region == NULL || XRectInRegion (region, x, y, width, width))
|
|
1351 {
|
|
1352 redraw_down_arrow (w, False, behind_arrows);
|
|
1353 }
|
|
1354 }
|
26
|
1355
|
76
|
1356 draw_shadows (dpy, win, w->sb.bottomShadowGC, w->sb.topShadowGC,
|
70
|
1357 0, 0, w->core.width, w->core.height, shadowT);
|
0
|
1358
|
76
|
1359 draw_knob (w, w->sb.above, w->sb.ss, w->sb.below);
|
0
|
1360
|
|
1361 }
|
|
1362
|
70
|
1363 /************************************************************************
|
|
1364 **
|
76
|
1365 ** Method functions
|
70
|
1366 **
|
|
1367 */
|
0
|
1368
|
76
|
1369 static void
|
|
1370 Initialize (Widget treq, Widget tnew, ArgList args, Cardinal *num_args)
|
0
|
1371 {
|
|
1372 XlwScrollBarWidget request = (XlwScrollBarWidget) treq;
|
|
1373 XlwScrollBarWidget w = (XlwScrollBarWidget) tnew;
|
76
|
1374 Display *dpy = XtDisplay ((Widget) w);
|
|
1375 Window win = RootWindowOfScreen (DefaultScreenOfDisplay (dpy));
|
70
|
1376
|
76
|
1377 DBUG (fprintf (stderr, "Initialize\n"));
|
0
|
1378
|
76
|
1379 if (request->core.width == 0) w->core.width += (VERT (w) ? 12 : 25);
|
|
1380 if (request->core.height == 0) w->core.height += (VERT (w) ? 25 : 12);
|
0
|
1381
|
76
|
1382 verify_values (w);
|
0
|
1383
|
|
1384 w->sb.lastY = 0;
|
|
1385 w->sb.above = 0;
|
|
1386 w->sb.ss = 0;
|
|
1387 w->sb.below = 0;
|
|
1388 w->sb.armed = ARM_NONE;
|
|
1389
|
76
|
1390 if (w->sb.shadowThickness > 5) w->sb.shadowThickness = 5;
|
0
|
1391
|
|
1392 w->sb.grayPixmap =
|
76
|
1393 XCreatePixmapFromBitmapData (dpy, win, (char *) gray_bits, gray_width,
|
|
1394 gray_height, 1, 0, 1);
|
0
|
1395
|
76
|
1396 make_trough_pixel (w);
|
|
1397
|
|
1398 make_shadow_pixels (w);
|
0
|
1399
|
76
|
1400 w->sb.backgroundGC =
|
|
1401 get_gc (w, w->core.background_pixel, w->core.background_pixel, None);
|
|
1402 w->sb.topShadowGC =
|
|
1403 get_gc (w, w->sb.topShadowColor, w->core.background_pixel,
|
|
1404 w->sb.topShadowPixmap);
|
|
1405 w->sb.bottomShadowGC =
|
|
1406 get_gc (w, w->sb.bottomShadowColor, w->core.background_pixel,
|
|
1407 w->sb.bottomShadowPixmap);
|
0
|
1408
|
|
1409 w->sb.fullRedrawNext = True;
|
76
|
1410
|
|
1411 w->sb.timerActive = False;
|
0
|
1412 }
|
|
1413
|
76
|
1414 static void
|
|
1415 Destroy (Widget widget)
|
0
|
1416 {
|
|
1417 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
76
|
1418 Display *dpy = XtDisplay ((Widget) w);
|
0
|
1419
|
76
|
1420 DBUG (fprintf (stderr, "Destroy\n"));
|
0
|
1421
|
76
|
1422 XtReleaseGC (widget, w->sb.bottomShadowGC);
|
|
1423 XtReleaseGC (widget, w->sb.topShadowGC);
|
|
1424 XtReleaseGC (widget, w->sb.backgroundGC);
|
10
|
1425
|
76
|
1426 XFreePixmap (dpy, w->sb.grayPixmap);
|
|
1427
|
|
1428 if (w->sb.timerActive)
|
|
1429 XtRemoveTimeOut (w->sb.timerId);
|
0
|
1430 }
|
|
1431
|
76
|
1432 static void
|
|
1433 Realize (Widget widget, XtValueMask *valuemask, XSetWindowAttributes *attr)
|
0
|
1434 {
|
|
1435 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
76
|
1436 Display *dpy = XtDisplay ((Widget) w);
|
0
|
1437 Window win;
|
|
1438 XSetWindowAttributes win_attr;
|
|
1439
|
76
|
1440 DBUG (fprintf (stderr, "Realize\n"));
|
70
|
1441
|
0
|
1442 (*coreClassRec.core_class.realize)(widget, valuemask, attr);
|
|
1443
|
76
|
1444 win = XtWindow ((Widget) w);
|
0
|
1445
|
76
|
1446 seg_pixel_sizes (w, &w->sb.above, &w->sb.ss, &w->sb.below);
|
0
|
1447
|
76
|
1448 XSetWindowBackground (dpy, win, w->sb.troughColor);
|
0
|
1449
|
|
1450 /* Change bit gravity so widget is not cleared on resize */
|
70
|
1451 win_attr.bit_gravity = NorthWestGravity;
|
76
|
1452 XChangeWindowAttributes (dpy, win, CWBitGravity , &win_attr);
|
0
|
1453
|
|
1454 }
|
|
1455
|
76
|
1456 static void
|
|
1457 Resize (Widget widget)
|
0
|
1458 {
|
|
1459 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
76
|
1460 Display *dpy = XtDisplay ((Widget) w);
|
|
1461 Window win = XtWindow ((Widget) w);
|
0
|
1462
|
76
|
1463 if (XtIsRealized (widget))
|
|
1464 {
|
|
1465 DBUG (fprintf (stderr, "Resize = %08lx\n", w));
|
0
|
1466
|
76
|
1467 seg_pixel_sizes (w, &w->sb.above, &w->sb.ss, &w->sb.below);
|
0
|
1468
|
70
|
1469 /*redraw_everything(w, NULL, True);*/
|
0
|
1470
|
|
1471 w->sb.fullRedrawNext = True;
|
|
1472 /* Force expose event */
|
76
|
1473 XClearArea (dpy, win, widget_x(w), widget_y(w), 1, 1, True);
|
|
1474 }
|
0
|
1475 }
|
|
1476
|
76
|
1477 static void
|
|
1478 Redisplay (Widget widget, XEvent *event, Region region)
|
0
|
1479 {
|
|
1480 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
|
1481
|
76
|
1482 DBUG (fprintf (stderr, "Redisplay = %08lx\n", w));
|
0
|
1483
|
76
|
1484 if (XtIsRealized (widget))
|
|
1485 {
|
|
1486 if (w->sb.fullRedrawNext)
|
|
1487 {
|
|
1488 redraw_everything (w, NULL, True);
|
|
1489 }
|
0
|
1490 else
|
76
|
1491 {
|
|
1492 redraw_everything (w, region, False);
|
|
1493 }
|
0
|
1494 w->sb.fullRedrawNext = False;
|
76
|
1495 }
|
0
|
1496 }
|
|
1497
|
76
|
1498 static Boolean
|
|
1499 SetValues (Widget current, Widget request, Widget neww,
|
|
1500 ArgList args, Cardinal *num_args)
|
0
|
1501 {
|
|
1502 XlwScrollBarWidget cur = (XlwScrollBarWidget) current;
|
|
1503 XlwScrollBarWidget w = (XlwScrollBarWidget) neww;
|
|
1504 Boolean do_redisplay = False;
|
|
1505
|
76
|
1506 if (cur->sb.troughColor != w->sb.troughColor)
|
|
1507 {
|
|
1508 if (XtIsRealized ((Widget) w))
|
|
1509 {
|
|
1510 XSetWindowBackground (XtDisplay((Widget) w), XtWindow ((Widget) w),
|
0
|
1511 w->sb.troughColor);
|
|
1512 do_redisplay = True;
|
76
|
1513 }
|
|
1514 }
|
0
|
1515
|
76
|
1516 if (cur->core.background_pixel != w->core.background_pixel)
|
|
1517 {
|
|
1518 XtReleaseGC ((Widget)cur, cur->sb.backgroundGC);
|
|
1519 w->sb.backgroundGC =
|
|
1520 get_gc (w, w->core.background_pixel, w->core.background_pixel, None);
|
0
|
1521 do_redisplay = True;
|
76
|
1522 }
|
0
|
1523
|
76
|
1524 if (cur->sb.topShadowColor != w->sb.topShadowColor ||
|
|
1525 cur->sb.topShadowPixmap != w->sb.topShadowPixmap)
|
|
1526 {
|
|
1527 XtReleaseGC ((Widget)cur, cur->sb.topShadowGC);
|
|
1528 w->sb.topShadowGC =
|
|
1529 get_gc (w, w->sb.topShadowColor, w->core.background_pixel,
|
|
1530 w->sb.topShadowPixmap);
|
0
|
1531 do_redisplay = True;
|
76
|
1532 }
|
0
|
1533
|
76
|
1534 if (cur->sb.bottomShadowColor != w->sb.bottomShadowColor ||
|
|
1535 cur->sb.bottomShadowPixmap != w->sb.bottomShadowPixmap)
|
|
1536 {
|
|
1537 XtReleaseGC ((Widget)cur, cur->sb.bottomShadowGC);
|
|
1538 w->sb.bottomShadowGC =
|
|
1539 get_gc (w, w->sb.bottomShadowColor, w->core.background_pixel,
|
|
1540 w->sb.bottomShadowPixmap);
|
0
|
1541 do_redisplay = True;
|
76
|
1542 }
|
0
|
1543
|
76
|
1544 if (cur->sb.orientation != w->sb.orientation)
|
|
1545 {
|
70
|
1546 do_redisplay = True;
|
76
|
1547 }
|
0
|
1548
|
|
1549
|
76
|
1550 if (cur->sb.minimum != w->sb.minimum ||
|
0
|
1551 cur->sb.maximum != w->sb.maximum ||
|
|
1552 cur->sb.sliderSize != w->sb.sliderSize ||
|
|
1553 cur->sb.value != w->sb.value ||
|
|
1554 cur->sb.pageIncrement != w->sb.pageIncrement ||
|
76
|
1555 cur->sb.increment != w->sb.increment)
|
|
1556 {
|
|
1557 verify_values (w);
|
|
1558 if (XtIsRealized ((Widget) w))
|
|
1559 {
|
|
1560 seg_pixel_sizes (w, &w->sb.above, &w->sb.ss, &w->sb.below);
|
|
1561 draw_knob (w, w->sb.above, w->sb.ss, w->sb.below);
|
|
1562 }
|
|
1563 }
|
0
|
1564
|
76
|
1565 if (w->sb.shadowThickness > 5) w->sb.shadowThickness = 5;
|
0
|
1566
|
76
|
1567 return do_redisplay;
|
0
|
1568 }
|
|
1569
|
76
|
1570 void
|
|
1571 XlwScrollBarGetValues (Widget widget, int *value, int *sliderSize,
|
|
1572 int *increment, int *pageIncrement)
|
0
|
1573 {
|
76
|
1574 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
0
|
1575
|
76
|
1576 if (w && XtClass ((Widget) w) == xlwScrollBarWidgetClass)
|
|
1577 {
|
|
1578 if (value) *value = w->sb.value;
|
|
1579 if (sliderSize) *sliderSize = w->sb.sliderSize;
|
|
1580 if (increment) *increment = w->sb.increment;
|
|
1581 if (pageIncrement) *pageIncrement = w->sb.pageIncrement;
|
|
1582 }
|
0
|
1583 }
|
|
1584
|
76
|
1585 void
|
|
1586 XlwScrollBarSetValues (Widget widget, int value, int sliderSize,
|
|
1587 int increment, int pageIncrement, Boolean notify)
|
0
|
1588 {
|
76
|
1589 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
70
|
1590 int last_value;
|
0
|
1591
|
76
|
1592 if (w && XtClass ((Widget) w) == xlwScrollBarWidgetClass &&
|
0
|
1593 (w->sb.value != value ||
|
|
1594 w->sb.sliderSize != sliderSize ||
|
|
1595 w->sb.increment != increment ||
|
76
|
1596 w->sb.pageIncrement != pageIncrement))
|
|
1597 {
|
0
|
1598 w->sb.value = value;
|
|
1599 w->sb.sliderSize = sliderSize;
|
|
1600 w->sb.increment = increment;
|
|
1601 w->sb.pageIncrement = pageIncrement;
|
|
1602
|
76
|
1603 verify_values (w);
|
70
|
1604
|
76
|
1605 if (XtIsRealized (widget))
|
|
1606 {
|
|
1607 seg_pixel_sizes (w, &w->sb.above, &w->sb.ss, &w->sb.below);
|
|
1608 draw_knob (w, w->sb.above, w->sb.ss, w->sb.below);
|
0
|
1609
|
70
|
1610 last_value = w->sb.value;
|
76
|
1611 w->sb.value = value_from_pixel (w, w->sb.above);
|
|
1612 verify_values (w);
|
0
|
1613
|
76
|
1614 if (w->sb.value != last_value && notify)
|
|
1615 {
|
|
1616 call_callbacks (w, XmCR_VALUE_CHANGED, w->sb.value, 0, NULL);
|
|
1617 }
|
|
1618 }
|
|
1619 }
|
0
|
1620 }
|
|
1621
|
70
|
1622 /************************************************************************
|
|
1623 **
|
76
|
1624 ** Action functions
|
70
|
1625 **
|
|
1626 */
|
0
|
1627
|
76
|
1628 static void
|
|
1629 timer (XtPointer data, XtIntervalId *id)
|
0
|
1630 {
|
76
|
1631 XlwScrollBarWidget w = (XlwScrollBarWidget) data;
|
70
|
1632 int reason, last_value;
|
76
|
1633
|
|
1634 w->sb.timerActive = False;
|
0
|
1635
|
76
|
1636 if (w->sb.armed != ARM_NONE)
|
|
1637 {
|
70
|
1638 last_value = w->sb.value;
|
|
1639 reason = XmCR_NONE;
|
0
|
1640
|
76
|
1641 switch (w->sb.armed)
|
|
1642 {
|
|
1643 case ARM_PAGEUP:
|
|
1644 w->sb.value = safe_subtract (w->sb.value, w->sb.pageIncrement);
|
|
1645 reason = XmCR_PAGE_DECREMENT;
|
|
1646 break;
|
|
1647 case ARM_PAGEDOWN:
|
|
1648 w->sb.value = safe_add (w->sb.value, w->sb.pageIncrement);
|
|
1649 reason = XmCR_PAGE_INCREMENT;
|
|
1650 break;
|
|
1651 case ARM_UP:
|
|
1652 w->sb.value = safe_subtract (w->sb.value, w->sb.increment);
|
|
1653 reason = XmCR_DECREMENT;
|
|
1654 break;
|
|
1655 case ARM_DOWN:
|
|
1656 w->sb.value = safe_add (w->sb.value, w->sb.increment);
|
|
1657 reason = XmCR_INCREMENT;
|
|
1658 break;
|
|
1659 }
|
0
|
1660
|
76
|
1661 verify_values (w);
|
|
1662
|
|
1663 if (last_value != w->sb.value)
|
|
1664 {
|
|
1665 seg_pixel_sizes (w, &w->sb.above, &w->sb.ss, &w->sb.below);
|
|
1666 draw_knob (w, w->sb.above, w->sb.ss, w->sb.below);
|
0
|
1667
|
76
|
1668 call_callbacks (w, reason, w->sb.value, 0, NULL);
|
0
|
1669
|
76
|
1670 w->sb.timerId =
|
|
1671 XtAppAddTimeOut (XtWidgetToApplicationContext ((Widget) w),
|
|
1672 (unsigned long) w->sb.repeatDelay,
|
|
1673 timer, (XtPointer) w);
|
|
1674 w->sb.timerActive = True;
|
|
1675 }
|
|
1676 }
|
0
|
1677 }
|
|
1678
|
76
|
1679 static int
|
|
1680 what_button (XlwScrollBarWidget w, int mouse_x, int mouse_y)
|
0
|
1681 {
|
70
|
1682 int x, y, width, height, arrow_height_top, arrow_height_bottom;
|
|
1683 int where;
|
|
1684
|
76
|
1685 x = widget_x (w);
|
|
1686 y = widget_y (w);
|
|
1687 width = widget_w (w);
|
|
1688 height = widget_h (w);
|
0
|
1689
|
70
|
1690 #if 0
|
76
|
1691 arrow_height = w->sb.showArrows ? arrow_h (w) : 0;
|
70
|
1692 #endif
|
76
|
1693 if (w->sb.showArrows)
|
|
1694 {
|
|
1695 if (arrow_same_end (w))
|
|
1696 {
|
70
|
1697 arrow_height_top = 0;
|
76
|
1698 arrow_height_bottom = 2 * arrow_h (w);
|
|
1699 }
|
70
|
1700 else
|
76
|
1701 {
|
|
1702 arrow_height_top = arrow_height_bottom = arrow_h (w);
|
|
1703 }
|
|
1704 }
|
70
|
1705 else
|
76
|
1706 {
|
70
|
1707 arrow_height_top = arrow_height_bottom = 0;
|
76
|
1708 }
|
0
|
1709
|
70
|
1710 where = BUTTON_NONE;
|
26
|
1711
|
76
|
1712 if (mouse_x > x && mouse_x < (x + width))
|
|
1713 {
|
|
1714 if (mouse_y > (y + arrow_height_top) &&
|
|
1715 mouse_y < (y + height - arrow_height_bottom))
|
|
1716 {
|
|
1717 if (mouse_y < (y + w->sb.above + arrow_height_top))
|
|
1718 {
|
70
|
1719 where = BUTTON_TROUGH_ABOVE;
|
76
|
1720 }
|
|
1721 else if (mouse_y > (y + w->sb.above + w->sb.ss + arrow_height_top))
|
|
1722 {
|
70
|
1723 where = BUTTON_TROUGH_BELOW;
|
76
|
1724 }
|
70
|
1725 else
|
76
|
1726 {
|
70
|
1727 where = BUTTON_KNOB;
|
76
|
1728 }
|
|
1729 }
|
|
1730 else if (arrow_same_end (w))
|
|
1731 {
|
|
1732 if (mouse_y > (y + height - arrow_height_bottom + 1) &&
|
|
1733 mouse_y < (y + height))
|
|
1734 {
|
|
1735 if (mouse_y < (y + height - arrow_height_bottom/2))
|
|
1736 {
|
70
|
1737 where = BUTTON_UP_ARROW;
|
76
|
1738 }
|
70
|
1739 else
|
76
|
1740 {
|
70
|
1741 where = BUTTON_DOWN_ARROW;
|
76
|
1742 }
|
|
1743 }
|
|
1744 }
|
0
|
1745 else
|
76
|
1746 {
|
|
1747 if (mouse_y > y && mouse_y < (y + arrow_height_top))
|
|
1748 {
|
70
|
1749 where = BUTTON_UP_ARROW;
|
76
|
1750 }
|
|
1751 else if (mouse_y > (y + height - arrow_height_bottom + 1) &&
|
|
1752 mouse_y < (y + height))
|
|
1753 {
|
70
|
1754 where = BUTTON_DOWN_ARROW;
|
76
|
1755 }
|
|
1756 }
|
|
1757 }
|
70
|
1758 #if 0
|
76
|
1759 if (mouse_x > x && mouse_x < (x + width))
|
|
1760 {
|
|
1761 if (mouse_y > (y + arrow_height) && mouse_y < (y + height - arrow_height))
|
|
1762 {
|
|
1763 if (mouse_y < (y+w->sb.above+arrow_height))
|
|
1764 {
|
70
|
1765 where = BUTTON_TROUGH_ABOVE;
|
76
|
1766 }
|
|
1767 else if (mouse_y > (y + w->sb.above + w->sb.ss + arrow_height))
|
|
1768 {
|
70
|
1769 where = BUTTON_TROUGH_BELOW;
|
76
|
1770 }
|
70
|
1771 else
|
76
|
1772 {
|
70
|
1773 where = BUTTON_KNOB;
|
76
|
1774 }
|
|
1775 }
|
|
1776 else if (mouse_y > y && mouse_y < (y + arrow_height))
|
|
1777 {
|
70
|
1778 where = BUTTON_UP_ARROW;
|
76
|
1779 }
|
|
1780 else if (mouse_y > (y + height - arrow_height + 1) &&
|
|
1781 mouse_y < (y + height))
|
|
1782 {
|
70
|
1783 where = BUTTON_DOWN_ARROW;
|
76
|
1784 }
|
|
1785 }
|
70
|
1786 #endif
|
76
|
1787 return where;
|
0
|
1788 }
|
|
1789
|
76
|
1790 #define FORCED_SCROLL_NONE 0
|
70
|
1791 #define FORCED_SCROLL_DOWNRIGHT 1
|
|
1792 #define FORCED_SCROLL_UPLEFT 2
|
|
1793
|
|
1794 int forced_scroll_flag = FORCED_SCROLL_NONE;
|
|
1795
|
76
|
1796 static void
|
|
1797 PageDownOrRight (Widget widget, XEvent *event, String *parms, Cardinal *num_parms)
|
0
|
1798 {
|
70
|
1799 forced_scroll_flag = FORCED_SCROLL_DOWNRIGHT;
|
76
|
1800 Select (widget, event, parms, num_parms);
|
70
|
1801 forced_scroll_flag = FORCED_SCROLL_NONE;
|
0
|
1802 }
|
|
1803
|
76
|
1804 static void
|
|
1805 PageUpOrLeft (Widget widget, XEvent *event, String *parms, Cardinal *num_parms)
|
0
|
1806 {
|
70
|
1807 forced_scroll_flag = FORCED_SCROLL_UPLEFT;
|
76
|
1808 Select (widget, event, parms, num_parms);
|
70
|
1809 forced_scroll_flag = FORCED_SCROLL_NONE;
|
0
|
1810 }
|
|
1811
|
76
|
1812 static void
|
|
1813 Select (Widget widget, XEvent *event, String *parms, Cardinal *num_parms)
|
0
|
1814 {
|
76
|
1815 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
70
|
1816 int mouse_x, mouse_y;
|
|
1817 int reason, last_value;
|
|
1818 int sb_button;
|
0
|
1819
|
76
|
1820 DBUG (fprintf (stderr, "Select:\n"));
|
0
|
1821
|
76
|
1822 mouse_x = event_x (w, event);
|
|
1823 mouse_y = event_y (w, event);
|
0
|
1824
|
70
|
1825 w->sb.savedValue = w->sb.value;
|
|
1826
|
|
1827 last_value = w->sb.value;
|
|
1828 reason = XmCR_NONE;
|
0
|
1829
|
76
|
1830 XtGrabKeyboard ((Widget) w, False, GrabModeAsync, GrabModeAsync,
|
|
1831 event->xbutton.time);
|
10
|
1832
|
76
|
1833 sb_button = what_button (w, mouse_x, mouse_y);
|
|
1834
|
|
1835 if (forced_scroll_flag != FORCED_SCROLL_NONE)
|
0
|
1836 {
|
76
|
1837 switch (sb_button)
|
0
|
1838 {
|
|
1839 case BUTTON_TROUGH_ABOVE:
|
|
1840 case BUTTON_TROUGH_BELOW:
|
70
|
1841 case BUTTON_KNOB:
|
0
|
1842 sb_button= BUTTON_NONE; /* cause next switch to fall through */
|
76
|
1843 if (forced_scroll_flag == FORCED_SCROLL_UPLEFT)
|
0
|
1844 {
|
76
|
1845 w->sb.value = safe_subtract (w->sb.value, w->sb.pageIncrement);
|
0
|
1846 w->sb.armed = ARM_PAGEUP;
|
|
1847 reason = XmCR_PAGE_DECREMENT;
|
|
1848 break;
|
|
1849 }
|
76
|
1850 else if (forced_scroll_flag == FORCED_SCROLL_DOWNRIGHT)
|
0
|
1851 {
|
76
|
1852 w->sb.value = safe_add (w->sb.value, w->sb.pageIncrement);
|
0
|
1853 w->sb.armed = ARM_PAGEDOWN;
|
|
1854 reason = XmCR_PAGE_INCREMENT;
|
|
1855 break;
|
|
1856 }
|
|
1857 abort();
|
|
1858 }
|
|
1859 }
|
|
1860
|
76
|
1861 switch (sb_button)
|
|
1862 {
|
|
1863 case BUTTON_TROUGH_ABOVE:
|
|
1864 w->sb.value = safe_subtract (w->sb.value, w->sb.pageIncrement);
|
|
1865 w->sb.armed = ARM_PAGEUP;
|
|
1866 reason = XmCR_PAGE_DECREMENT;
|
|
1867 break;
|
|
1868 case BUTTON_TROUGH_BELOW:
|
|
1869 w->sb.value = safe_add (w->sb.value, w->sb.pageIncrement);
|
|
1870 w->sb.armed = ARM_PAGEDOWN;
|
|
1871 reason = XmCR_PAGE_INCREMENT;
|
|
1872 break;
|
|
1873 case BUTTON_KNOB:
|
|
1874 w->sb.lastY = mouse_y;
|
|
1875 w->sb.armed = ARM_KNOB;
|
|
1876 draw_knob (w, w->sb.above, w->sb.ss, w->sb.below);
|
|
1877 break;
|
|
1878 case BUTTON_UP_ARROW:
|
|
1879 if (event->xbutton.state & ControlMask)
|
|
1880 {
|
|
1881 w->sb.value = INT_MIN;
|
|
1882 w->sb.armed = ARM_UP;
|
|
1883 reason = XmCR_TO_TOP;
|
|
1884 }
|
|
1885 else
|
|
1886 {
|
|
1887 w->sb.value = safe_subtract (w->sb.value, w->sb.increment);
|
|
1888 w->sb.armed = ARM_UP;
|
|
1889 reason = XmCR_DECREMENT;
|
|
1890 }
|
|
1891 redraw_up_arrow (w, True, False);
|
|
1892 break;
|
|
1893 case BUTTON_DOWN_ARROW:
|
|
1894 if (event->xbutton.state & ControlMask)
|
|
1895 {
|
|
1896 w->sb.value = INT_MAX;
|
|
1897 w->sb.armed = ARM_DOWN;
|
|
1898 reason = XmCR_TO_BOTTOM;
|
|
1899 }
|
|
1900 else
|
|
1901 {
|
|
1902 w->sb.value = safe_add (w->sb.value, w->sb.increment);
|
|
1903 w->sb.armed = ARM_DOWN;
|
|
1904 reason = XmCR_INCREMENT;
|
|
1905 }
|
|
1906 redraw_down_arrow (w, True, False);
|
|
1907 break;
|
|
1908 }
|
0
|
1909
|
76
|
1910 verify_values (w);
|
10
|
1911
|
76
|
1912 if (last_value != w->sb.value)
|
|
1913 {
|
|
1914 seg_pixel_sizes (w, &w->sb.above, &w->sb.ss, &w->sb.below);
|
|
1915 draw_knob (w, w->sb.above, w->sb.ss, w->sb.below);
|
70
|
1916
|
76
|
1917 call_callbacks (w, reason, w->sb.value, mouse_y, event);
|
|
1918
|
|
1919 if (w->sb.timerActive)
|
|
1920 XtRemoveTimeOut (w->sb.timerId);
|
0
|
1921
|
76
|
1922 w->sb.timerId =
|
|
1923 XtAppAddTimeOut (XtWidgetToApplicationContext ((Widget) w),
|
|
1924 (unsigned long) w->sb.initialDelay,
|
|
1925 timer, (XtPointer) w);
|
|
1926 w->sb.timerActive = True;
|
|
1927 }
|
0
|
1928
|
76
|
1929 CHECK (w);
|
0
|
1930 }
|
|
1931
|
76
|
1932 static void
|
|
1933 Drag (Widget widget, XEvent *event, String *parms, Cardinal *num_parms)
|
0
|
1934 {
|
76
|
1935 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
70
|
1936 int diff;
|
|
1937 int height, mouse_y;
|
|
1938 int last_value, last_above;
|
|
1939
|
76
|
1940 DBUG (fprintf (stderr, "Drag:\n"));
|
0
|
1941
|
76
|
1942 if (w->sb.armed == ARM_KNOB)
|
|
1943 {
|
|
1944 height = widget_h (w);
|
|
1945 if (w->sb.showArrows) height -= (2 * arrow_h (w));
|
70
|
1946
|
76
|
1947 mouse_y = event_y (w, event);
|
70
|
1948
|
|
1949 diff = mouse_y - w->sb.lastY;
|
|
1950
|
|
1951 last_above = w->sb.above;
|
|
1952 last_value = w->sb.value;
|
0
|
1953
|
76
|
1954 if (diff < 0)
|
|
1955 {
|
70
|
1956 /* up */
|
|
1957 w->sb.above -= (-diff);
|
76
|
1958 if (w->sb.above < 0)
|
|
1959 {
|
70
|
1960 mouse_y = (mouse_y - w->sb.above);
|
|
1961 w->sb.above = 0;
|
|
1962 diff = 0;
|
|
1963 w->sb.below = height - w->sb.ss;
|
76
|
1964 }
|
70
|
1965 w->sb.below -= diff;
|
76
|
1966 CHECK (w);
|
|
1967 }
|
|
1968 else if (diff > 0)
|
|
1969 {
|
70
|
1970 /* down */
|
|
1971 w->sb.above += diff;
|
76
|
1972 if (w->sb.above + w->sb.ss > height)
|
|
1973 {
|
70
|
1974 mouse_y = height + (mouse_y - (w->sb.above + w->sb.ss));
|
|
1975 w->sb.above = height - w->sb.ss;
|
|
1976 diff = 0;
|
|
1977 w->sb.below = 0;
|
76
|
1978 }
|
70
|
1979 w->sb.below -= diff;
|
76
|
1980 CHECK (w);
|
|
1981 }
|
0
|
1982
|
76
|
1983 if (last_above != w->sb.above)
|
|
1984 {
|
|
1985 draw_knob (w, w->sb.above, w->sb.ss, w->sb.below);
|
0
|
1986
|
|
1987 w->sb.lastY = mouse_y;
|
|
1988
|
76
|
1989 w->sb.value = value_from_pixel (w, w->sb.above);
|
|
1990 verify_values (w);
|
|
1991 CHECK (w);
|
0
|
1992
|
76
|
1993 if (w->sb.value != last_value)
|
|
1994 call_callbacks (w, XmCR_DRAG, w->sb.value, event_y (w, event), event);
|
|
1995 }
|
|
1996 }
|
|
1997 CHECK (w);
|
0
|
1998 }
|
|
1999
|
76
|
2000 static void
|
|
2001 Release (Widget widget, XEvent *event, String *parms, Cardinal *num_parms)
|
0
|
2002 {
|
76
|
2003 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
70
|
2004
|
76
|
2005 DBUG (fprintf (stderr, "EndDrag:\n"));
|
0
|
2006
|
76
|
2007 switch (w->sb.armed)
|
|
2008 {
|
|
2009 case ARM_KNOB:
|
|
2010 call_callbacks (w, XmCR_VALUE_CHANGED, w->sb.value, event_y (w, event), event);
|
|
2011 w->sb.armed = ARM_NONE;
|
|
2012 draw_knob (w, w->sb.above, w->sb.ss, w->sb.below);
|
|
2013 break;
|
|
2014 case ARM_UP:
|
|
2015 redraw_up_arrow (w, False, False);
|
|
2016 break;
|
|
2017 case ARM_DOWN:
|
|
2018 redraw_down_arrow (w, False, False);
|
|
2019 break;
|
|
2020 }
|
0
|
2021
|
76
|
2022 XtUngrabKeyboard ((Widget) w, event->xbutton.time);
|
0
|
2023
|
|
2024 w->sb.armed = ARM_NONE;
|
|
2025 }
|
|
2026
|
76
|
2027 static void
|
|
2028 Jump (Widget widget, XEvent *event, String *parms, Cardinal *num_parms)
|
0
|
2029 {
|
76
|
2030 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
70
|
2031 int x, y, width, height, mouse_x, mouse_y;
|
|
2032 int arrow_height;
|
|
2033 int last_above, last_value;
|
0
|
2034
|
76
|
2035 DBUG (fprintf (stderr, "Jump:\n"));
|
0
|
2036
|
76
|
2037 x = widget_x (w);
|
|
2038 y = widget_y (w);
|
|
2039 width = widget_w (w);
|
|
2040 height = widget_h (w);
|
|
2041
|
|
2042 mouse_x = event_x (w, event);
|
|
2043 mouse_y = event_y (w, event);
|
70
|
2044
|
76
|
2045 arrow_height = w->sb.showArrows ? arrow_h (w) : 0;
|
0
|
2046
|
76
|
2047 XtGrabKeyboard ((Widget) w, False, GrabModeAsync, GrabModeAsync,
|
|
2048 event->xbutton.time);
|
70
|
2049
|
76
|
2050 switch (what_button (w, mouse_x, mouse_y))
|
|
2051 {
|
|
2052 case BUTTON_TROUGH_ABOVE:
|
|
2053 case BUTTON_TROUGH_BELOW:
|
|
2054 case BUTTON_KNOB:
|
|
2055 w->sb.savedValue = w->sb.value;
|
70
|
2056
|
76
|
2057 height -= (2*arrow_height);
|
|
2058 y += arrow_height;
|
0
|
2059
|
76
|
2060 last_above = w->sb.above;
|
|
2061 last_value = w->sb.value;
|
70
|
2062
|
76
|
2063 w->sb.armed = ARM_KNOB;
|
|
2064 draw_knob (w, w->sb.above, w->sb.ss, w->sb.below);
|
0
|
2065
|
76
|
2066 w->sb.above = mouse_y - (w->sb.ss / 2) - arrow_height;
|
|
2067 if (w->sb.above < 0)
|
|
2068 {
|
|
2069 w->sb.above = 0;
|
|
2070 }
|
|
2071 else if (w->sb.above + w->sb.ss > height)
|
|
2072 {
|
|
2073 w->sb.above = height - w->sb.ss;
|
|
2074 }
|
|
2075 w->sb.below = (height - (w->sb.ss + w->sb.above));
|
26
|
2076
|
76
|
2077 if (last_above != w->sb.above)
|
|
2078 {
|
|
2079 draw_knob (w, w->sb.above, w->sb.ss, w->sb.below);
|
0
|
2080
|
76
|
2081 w->sb.value = value_from_pixel (w, w->sb.above);
|
|
2082 verify_values (w);
|
|
2083 CHECK (w);
|
0
|
2084
|
76
|
2085 w->sb.lastY = mouse_y;
|
|
2086 w->sb.lastY = w->sb.above + arrow_height + (w->sb.ss / 2);
|
26
|
2087
|
76
|
2088 if (w->sb.value != last_value)
|
|
2089 {
|
|
2090 call_callbacks (w, XmCR_DRAG, w->sb.value, event_y (w, event), event);
|
|
2091 }
|
|
2092 }
|
|
2093 break;
|
|
2094 }
|
|
2095 CHECK (w);
|
0
|
2096 }
|
|
2097
|
76
|
2098 static void
|
|
2099 Abort (Widget widget, XEvent *event, String *parms, Cardinal *num_parms)
|
0
|
2100 {
|
76
|
2101 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
0
|
2102
|
76
|
2103 DBUG (fprintf (stderr, "Abort:\n"));
|
70
|
2104
|
76
|
2105 if (w->sb.armed != ARM_NONE)
|
|
2106 {
|
|
2107 if (w->sb.value != w->sb.savedValue)
|
|
2108 {
|
0
|
2109 w->sb.value = w->sb.savedValue;
|
|
2110
|
76
|
2111 seg_pixel_sizes (w, &w->sb.above, &w->sb.ss, &w->sb.below);
|
|
2112 draw_knob (w, w->sb.above, w->sb.ss, w->sb.below);
|
0
|
2113
|
76
|
2114 call_callbacks (w, XmCR_VALUE_CHANGED, w->sb.value,
|
|
2115 event_y (w, event), event);
|
|
2116 }
|
|
2117
|
|
2118 switch (w->sb.armed)
|
|
2119 {
|
|
2120 case ARM_UP: redraw_up_arrow (w, False, False); break;
|
|
2121 case ARM_DOWN: redraw_down_arrow (w, False, False); break;
|
|
2122 }
|
0
|
2123
|
|
2124 w->sb.armed = ARM_NONE;
|
|
2125
|
76
|
2126 XtUngrabKeyboard ((Widget) w, event->xbutton.time);
|
|
2127 }
|
0
|
2128 }
|