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
|
10
|
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 *
|
|
64 * XmNknobStyle - values can be: "plain" or "dimple"
|
|
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))) \
|
10
|
83 ? ((unsigned long) (x)) : ((unsigned long) (y)))
|
0
|
84
|
10
|
85 #define VERT(w) ((w)->sb.orientation == XmVERTICAL)
|
0
|
86
|
|
87 #define SS_MIN 8
|
|
88
|
|
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
|
|
100
|
|
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
|
|
107
|
|
108 #define KNOB_PLAIN 0
|
|
109 #define KNOB_DIMPLE 1
|
|
110
|
|
111 /************************************************************************
|
|
112 **
|
|
113 ** Resources
|
|
114 **
|
|
115 */
|
|
116 #define offset(field) XtOffset(XlwScrollBarWidget, field)
|
|
117
|
|
118 static XtResource resources[] = {
|
2
|
119 { (String) XmNforeground, (String) XmCForeground, XtRPixel, sizeof(Pixel),
|
|
120 offset(sb.foreground), XtRImmediate, (XtPointer) XtDefaultForeground },
|
|
121
|
|
122 { (String) XmNtopShadowColor, (String) XmCTopShadowColor, XtRPixel,
|
|
123 sizeof(Pixel), offset(sb.topShadowColor), XtRImmediate, (XtPointer) ~0 },
|
|
124 { (String) XmNbottomShadowColor, (String) XmCBottomShadowColor, XtRPixel,
|
|
125 sizeof(Pixel), offset(sb.bottomShadowColor), XtRImmediate,
|
|
126 (XtPointer)~0 },
|
0
|
127
|
2
|
128 { (String) XmNtopShadowPixmap, (String) XmCTopShadowPixmap, XtRPixmap,
|
|
129 sizeof (Pixmap), offset(sb.topShadowPixmap), XtRImmediate,
|
|
130 (XtPointer)None},
|
|
131 { (String) XmNbottomShadowPixmap, (String) XmCBottomShadowPixmap,
|
|
132 XtRPixmap, sizeof (Pixmap), offset(sb.bottomShadowPixmap),
|
|
133 XtRImmediate, (XtPointer)None},
|
0
|
134
|
2
|
135 { (String)XmNtroughColor, (String)XmCTroughColor, XtRPixel, sizeof(Pixel),
|
0
|
136 offset(sb.troughColor), XtRImmediate, (XtPointer)~0 },
|
|
137
|
2
|
138 { (String)XmNshadowThickness, (String)XmCShadowThickness, XtRInt,
|
|
139 sizeof(int), offset(sb.shadowThickness), XtRImmediate, (XtPointer)2 },
|
0
|
140
|
2
|
141 { (String) XmNborderWidth, (String) XmCBorderWidth, XtRDimension,
|
|
142 sizeof(Dimension), offset(core.border_width), XtRImmediate,
|
|
143 (XtPointer)0 },
|
0
|
144
|
2
|
145 { (String) XmNshowArrows, (String) XmCShowArrows, XtRBoolean,
|
|
146 sizeof(Boolean), offset(sb.showArrows), XtRImmediate, (XtPointer)True },
|
0
|
147
|
2
|
148 { (String) XmNinitialDelay, (String) XmCInitialDelay, XtRInt, sizeof(int),
|
0
|
149 offset(sb.initialDelay), XtRImmediate, (XtPointer) 250 },
|
2
|
150 { (String) XmNrepeatDelay, (String) XmCRepeatDelay, XtRInt, sizeof(int),
|
0
|
151 offset(sb.repeatDelay), XtRImmediate, (XtPointer) 50 },
|
|
152
|
2
|
153 { (String) XmNorientation, (String) XmCOrientation, XtROrientation,
|
|
154 sizeof(unsigned char), offset(sb.orientation), XtRImmediate,
|
|
155 (XtPointer) XmVERTICAL },
|
0
|
156
|
2
|
157 { (String) XmNminimum, (String) XmCMinimum, XtRInt, sizeof(int),
|
0
|
158 offset(sb.minimum), XtRImmediate, (XtPointer) 0},
|
2
|
159 { (String) XmNmaximum, (String) XmCMaximum, XtRInt, sizeof(int),
|
0
|
160 offset(sb.maximum), XtRImmediate, (XtPointer) 100},
|
2
|
161 { (String) XmNvalue, (String) XmCValue, XtRInt, sizeof(int),
|
0
|
162 offset(sb.value), XtRImmediate, (XtPointer) 0},
|
2
|
163 { (String) XmNsliderSize, (String) XmCSliderSize, XtRInt, sizeof(int),
|
0
|
164 offset(sb.sliderSize), XtRImmediate, (XtPointer) 10},
|
2
|
165 { (String) XmNincrement, (String) XmCIncrement, XtRInt, sizeof(int),
|
0
|
166 offset(sb.increment), XtRImmediate, (XtPointer) 1},
|
2
|
167 { (String)XmNpageIncrement, (String)XmCPageIncrement, XtRInt, sizeof(int),
|
0
|
168 offset(sb.pageIncrement), XtRImmediate, (XtPointer) 10},
|
|
169
|
2
|
170 { (String) XmNvalueChangedCallback, (String) XmCValueChangedCallback,
|
|
171 XtRCallback, sizeof(XtPointer), offset(sb.valueChangedCBL),
|
|
172 XtRCallback, NULL},
|
|
173 { (String) XmNincrementCallback, (String) XmCIncrementCallback,
|
|
174 XtRCallback, sizeof(XtPointer), offset(sb.incrementCBL),
|
|
175 XtRCallback, NULL},
|
|
176 { (String) XmNdecrementCallback, (String) XmCDecrementCallback,
|
|
177 XtRCallback, sizeof(XtPointer), offset(sb.decrementCBL),
|
|
178 XtRCallback, NULL},
|
|
179 { (String) XmNpageIncrementCallback, (String) XmCPageIncrementCallback,
|
|
180 XtRCallback, sizeof(XtPointer), offset(sb.pageIncrementCBL),
|
|
181 XtRCallback, NULL},
|
|
182 { (String) XmNpageDecrementCallback, (String) XmCPageDecrementCallback,
|
|
183 XtRCallback, sizeof(XtPointer), offset(sb.pageDecrementCBL),
|
|
184 XtRCallback, NULL},
|
|
185 { (String) XmNtoTopCallback, (String) XmCToTopCallback, XtRCallback,
|
|
186 sizeof(XtPointer), offset(sb.toTopCBL), XtRCallback, NULL},
|
|
187 { (String) XmNtoBottomCallback, (String) XmCToBottomCallback, XtRCallback,
|
|
188 sizeof(XtPointer), offset(sb.toBottomCBL), XtRCallback, NULL},
|
|
189 { (String) XmNdragCallback, (String) XmCDragCallback, XtRCallback,
|
|
190 sizeof(XtPointer), offset(sb.dragCBL), XtRCallback, NULL},
|
0
|
191
|
2
|
192 { (String) XmNknobStyle, (String) XmCKnobStyle, XtRString, sizeof(char *),
|
0
|
193 offset(sb.knobStyle), XtRImmediate, NULL},
|
|
194
|
2
|
195 { (String) XmNarrowPosition, (String) XmCArrowPosition, XtRString,
|
|
196 sizeof(char *), offset(sb.arrowPosition), XtRImmediate, NULL},
|
0
|
197 };
|
|
198
|
|
199 /************************************************************************
|
|
200 **
|
|
201 ** Prototypes
|
|
202 **
|
|
203 */
|
|
204
|
|
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);
|
|
215
|
|
216 /*
|
|
217 ** Methods
|
|
218 */
|
|
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
|
|
226 /*
|
|
227 ** Private
|
|
228 */
|
|
229
|
|
230
|
|
231 /************************************************************************
|
|
232 **
|
|
233 ** Actions Table
|
|
234 **
|
|
235 */
|
|
236 static XtActionsRec actions[] = {
|
10
|
237 {(String) "Select", Select},
|
|
238 {(String) "PageDownOrRight",PageDownOrRight},
|
|
239 {(String) "PageUpOrLeft", PageUpOrLeft},
|
|
240 {(String) "Drag", Drag},
|
|
241 {(String) "Release", Release},
|
|
242 {(String) "Jump", Jump},
|
|
243 {(String) "Abort", Abort},
|
0
|
244 };
|
|
245
|
|
246 /************************************************************************
|
|
247 **
|
|
248 ** Default Translation Table
|
|
249 **
|
|
250 */
|
|
251 static char default_translations[] =
|
|
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()"
|
|
259 ;
|
|
260
|
|
261 /************************************************************************
|
|
262 **
|
|
263 ** Class record initalization
|
|
264 **
|
|
265 */
|
|
266 XlwScrollBarClassRec xlwScrollBarClassRec = {
|
|
267 /* core_class fields */
|
|
268 {
|
|
269 /* superclass */ (WidgetClass) &coreClassRec,
|
2
|
270 /* class_name */ (String) "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
|
|
308 /************************************************************************
|
|
309 **
|
10
|
310 ** Debug functions
|
0
|
311 **
|
|
312 */
|
|
313
|
|
314 #ifdef SHOW_CLEAR
|
10
|
315 static void
|
|
316 myXClearArea(Display *dpy, Drawable d, int x, int y, int w, int h,
|
|
317 Boolean exp, XlwScrollBarWidget widget)
|
0
|
318 {
|
10
|
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
|
10
|
329 static void
|
|
330 check(XlwScrollBarWidget w)
|
0
|
331 {
|
|
332 int height;
|
|
333
|
10
|
334 height= widget_h (w);
|
|
335 if (w->sb.showArrows) height -= (2 * arrow_h (w));
|
0
|
336
|
10
|
337 if ((w->sb.above + w->sb.ss + w->sb.below > height) ||
|
0
|
338 (w->sb.value < w->sb.minimum) ||
|
10
|
339 (w->sb.value > w->sb.maximum - w->sb.sliderSize)
|
0
|
340 )
|
10
|
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",
|
10
|
345 w->sb.value, w->sb.minimum, w->sb.maximum,
|
|
346 w->sb.sliderSize, w->sb.maximum - w->sb.sliderSize);
|
0
|
347 abort();
|
10
|
348 }
|
0
|
349 }
|
|
350
|
|
351 # define CHECK(w) check(w)
|
|
352 #else
|
|
353 # define CHECK(w)
|
|
354 #endif
|
|
355
|
|
356 /************************************************************************
|
|
357 **
|
10
|
358 ** Static functions
|
0
|
359 **
|
|
360 */
|
|
361
|
10
|
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
|
10
|
369 cbs.reason = reason;
|
|
370 cbs.event = event;
|
|
371 cbs.value = value;
|
|
372 cbs.pixel = pixel;
|
0
|
373
|
|
374 called_anything = False;
|
|
375
|
10
|
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;
|
10
|
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
|
10
|
433 if (!called_anything)
|
|
434 {
|
0
|
435 cbs.reason = XmCR_VALUE_CHANGED;
|
10
|
436 XtCallCallbackList ((Widget) w, w->sb.valueChangedCBL, &cbs);
|
|
437 }
|
0
|
438 }
|
|
439
|
|
440 /*
|
|
441 ** Widget sizes minus the shadow and highlight area
|
|
442 */
|
10
|
443 static int
|
|
444 widget_x (XlwScrollBarWidget w)
|
0
|
445 {
|
10
|
446 return w->sb.shadowThickness;
|
0
|
447 }
|
|
448
|
10
|
449 static int
|
|
450 widget_y (XlwScrollBarWidget w)
|
0
|
451 {
|
10
|
452 return w->sb.shadowThickness;
|
0
|
453 }
|
|
454
|
10
|
455 static int
|
|
456 widget_w (XlwScrollBarWidget w)
|
0
|
457 {
|
|
458 int width, x = w->sb.shadowThickness;
|
|
459
|
10
|
460 width = VERT (w) ? w->core.width : w->core.height;
|
0
|
461
|
10
|
462 if (width <= (2 * x))
|
|
463 return 1;
|
0
|
464 else
|
10
|
465 return width - (2 * x);
|
0
|
466 }
|
|
467
|
10
|
468 static int
|
|
469 widget_h (XlwScrollBarWidget w)
|
0
|
470 {
|
|
471 int height, y = w->sb.shadowThickness;
|
|
472
|
10
|
473 height = VERT (w) ? w->core.height : w->core.width;
|
0
|
474
|
10
|
475 if (height <= (2 * y))
|
|
476 return 1;
|
0
|
477 else
|
10
|
478 return height - (2 * y);
|
0
|
479 }
|
|
480
|
10
|
481 static int
|
|
482 arrow_h (XlwScrollBarWidget w)
|
0
|
483 {
|
|
484 int width, height;
|
|
485
|
10
|
486 width = widget_w (w);
|
|
487 height= widget_h (w);
|
0
|
488
|
10
|
489 if (width > ((height / 2) - (SS_MIN / 2) - 1))
|
|
490 return (height / 2) - (SS_MIN / 2) - 1 ;
|
0
|
491 else
|
10
|
492 return width;
|
0
|
493 }
|
|
494
|
10
|
495 static int
|
|
496 event_x (XlwScrollBarWidget w, XEvent *event)
|
0
|
497 {
|
10
|
498 return VERT (w) ? event->xbutton.x : event->xbutton.y;
|
0
|
499 }
|
|
500
|
10
|
501 static int
|
|
502 event_y (XlwScrollBarWidget w, XEvent *event)
|
0
|
503 {
|
10
|
504 return VERT (w) ? event->xbutton.y : event->xbutton.x;
|
0
|
505 }
|
|
506
|
|
507 /*
|
|
508 ** Safe addition and subtraction
|
|
509 */
|
10
|
510 static int
|
|
511 safe_add (int a, int b)
|
0
|
512 {
|
10
|
513 if (a > 0 && INT_MAX - a < b) return INT_MAX;
|
|
514 else return a + b;
|
0
|
515 }
|
|
516
|
10
|
517 static int
|
|
518 safe_subtract (int a, int b)
|
0
|
519 {
|
10
|
520 if (a < 0 && -(INT_MIN - a) < b) return INT_MIN;
|
|
521 else return a - b;
|
0
|
522 }
|
|
523
|
10
|
524 static int
|
|
525 knob_style (XlwScrollBarWidget w)
|
0
|
526 {
|
10
|
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;
|
0
|
536 }
|
|
537
|
|
538 /*
|
|
539 ** GC and Pixel allocation
|
|
540 */
|
10
|
541 static GC
|
|
542 get_gc (XlwScrollBarWidget w, Pixel fg, Pixel bg, Pixmap pm)
|
0
|
543 {
|
|
544 XGCValues values;
|
|
545 XtGCMask mask;
|
|
546
|
10
|
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
|
10
|
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;
|
|
562 mask = GCForeground | GCBackground |
|
10
|
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 {
|
10
|
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
|
10
|
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
|
10
|
584 int nearest, x;
|
|
585 unsigned long nearest_delta, trial_delta;
|
0
|
586
|
10
|
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. */
|
10
|
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);
|
10
|
596
|
|
597 for (x = 0; x < no_cells; x++)
|
0
|
598 {
|
10
|
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);
|
|
602 trial_delta = dred * dred + dgreen * dgreen + dblue * dblue;
|
|
603
|
|
604 if (x == 0 || trial_delta < nearest_delta)
|
0
|
605 {
|
|
606 nearest = x;
|
|
607 nearest_delta = trial_delta;
|
|
608 }
|
|
609 }
|
10
|
610 color_def->red = cells[nearest].red;
|
0
|
611 color_def->green = cells[nearest].green;
|
10
|
612 color_def->blue = cells[nearest].blue;
|
0
|
613 free (cells);
|
10
|
614 return XAllocColor (display, screen_colormap, color_def);
|
0
|
615 }
|
|
616 }
|
|
617
|
10
|
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
|
10
|
632 if (w->sb.topShadowColor == (Pixel)~0) w->sb.topShadowColor = bg;
|
|
633 if (w->sb.bottomShadowColor == (Pixel)~0) w->sb.bottomShadowColor = fg;
|
0
|
634
|
10
|
635 if (w->sb.topShadowColor == bg || w->sb.topShadowColor == fg)
|
|
636 {
|
0
|
637 topc.pixel = bg;
|
10
|
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);
|
10
|
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);
|
10
|
651 if (allocate_nearest_color (dpy, cmap, &topc))
|
|
652 {
|
0
|
653 w->sb.topShadowColor = topc.pixel;
|
10
|
654 }
|
|
655 }
|
0
|
656 else
|
10
|
657 {
|
0
|
658 w->sb.topShadowColor = topc.pixel;
|
10
|
659 }
|
0
|
660
|
|
661 top_frobbed = 1;
|
10
|
662 }
|
|
663 }
|
0
|
664
|
10
|
665 if (w->sb.bottomShadowColor == fg || w->sb.bottomShadowColor == bg)
|
|
666 {
|
0
|
667 botc.pixel = bg;
|
10
|
668 XQueryColor (dpy, cmap, &botc);
|
0
|
669 botc.red *= 0.6;
|
|
670 botc.green *= 0.6;
|
|
671 botc.blue *= 0.6;
|
10
|
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);
|
10
|
680 if (allocate_nearest_color (dpy, cmap, &botc))
|
|
681 {
|
0
|
682 w->sb.bottomShadowColor = botc.pixel;
|
10
|
683 }
|
|
684 }
|
0
|
685 else
|
10
|
686 {
|
0
|
687 w->sb.bottomShadowColor = botc.pixel;
|
10
|
688 }
|
0
|
689 bottom_frobbed = 1;
|
10
|
690 }
|
|
691 }
|
0
|
692
|
10
|
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));
|
10
|
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;
|
10
|
702 }
|
|
703 else if (topc.pixel == botc.pixel)
|
|
704 {
|
|
705 if (botc.pixel == bg)
|
|
706 w->sb.topShadowColor = bg;
|
0
|
707 else
|
10
|
708 w->sb.bottomShadowColor = fg;
|
|
709 }
|
|
710 }
|
0
|
711
|
10
|
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
|
|
719 * and thumb are BOTH black, then use a white top shadow and a
|
|
720 * grey bottom shadow, otherwise use a grey top shadow and a
|
|
721 * black bottom shadow.
|
|
722 */
|
|
723
|
10
|
724 Pixel white = WhitePixelOfScreen (DefaultScreenOfDisplay (XtDisplay (w)));
|
|
725 Pixel black = BlackPixelOfScreen (DefaultScreenOfDisplay (XtDisplay (w)));
|
0
|
726
|
|
727 /* Note: core.background_pixel is the color of the thumb ... */
|
|
728
|
|
729 if (w->core.background_pixel == black &&
|
10
|
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
|
10
|
741 static void
|
|
742 make_trough_pixel (XlwScrollBarWidget w)
|
0
|
743 {
|
|
744 Display *dpy = XtDisplay((Widget) w);
|
10
|
745 Colormap cmap = DefaultColormapOfScreen (XtScreen ((Widget) w));
|
0
|
746 XColor troughC;
|
|
747
|
10
|
748 if (w->sb.troughColor == (Pixel)~0) w->sb.troughColor = w->core.background_pixel;
|
0
|
749
|
10
|
750 if (w->sb.troughColor == w->core.background_pixel)
|
|
751 {
|
0
|
752 troughC.pixel = w->core.background_pixel;
|
10
|
753 XQueryColor (dpy, cmap, &troughC);
|
0
|
754 troughC.red *= 0.8;
|
|
755 troughC.green *= 0.8;
|
|
756 troughC.blue *= 0.8;
|
10
|
757 if (allocate_nearest_color (dpy, cmap, &troughC))
|
|
758 w->sb.troughColor = troughC.pixel;
|
|
759 }
|
0
|
760 }
|
|
761
|
|
762 /*
|
|
763 ** Draw 3d border
|
|
764 */
|
10
|
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 {
|
10
|
769 XSegment shine[10], shadow[10];
|
|
770 int i;
|
0
|
771
|
10
|
772 if (shadowT > (width / 2)) shadowT = (width / 2);
|
|
773 if (shadowT > (height / 2)) shadowT = (height / 2);
|
|
774 if (shadowT <= 0) return;
|
0
|
775
|
10
|
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
|
10
|
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
|
10
|
797 XDrawSegments (dpy, d, shine_gc, shine, shadowT * 2);
|
|
798 XDrawSegments (dpy, d, shadow_gc, shadow, shadowT * 2);
|
0
|
799 }
|
|
800
|
|
801 /*
|
|
802 ** Draw 3d arrows, left, up, down, and right
|
|
803 */
|
10
|
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
|
10
|
809 for (i=0; i<shadowT; i++)
|
|
810 {
|
0
|
811 seg[i].x1 = x1;
|
|
812 seg[i].y1 = y1 + i;
|
|
813 seg[i].x2 = x2;
|
|
814 seg[i].y2 = y2 + i;
|
10
|
815 }
|
|
816 return shadowT;
|
0
|
817 }
|
|
818
|
10
|
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
|
10
|
824 for (i=0; i<shadowT; i++)
|
|
825 {
|
0
|
826 seg[i].x1 = x1 + i;
|
|
827 seg[i].y1 = y1;
|
|
828 seg[i].x2 = x2 + i;
|
|
829 seg[i].y2 = y2;
|
10
|
830 }
|
|
831 return shadowT;
|
0
|
832 }
|
|
833
|
10
|
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
|
10
|
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 /* / */
|
10
|
849 make_vert_seg (shine,
|
0
|
850 x, y + height - shadowT - 1,
|
10
|
851 x + mid, y, shadowT);
|
0
|
852 /* _\ */
|
10
|
853 make_vert_seg (shadow,
|
0
|
854 x, y + height - shadowT - 1,
|
10
|
855 x + width - 1, y + height - shadowT - 1, shadowT);
|
|
856 make_vert_seg (shadow + shadowT,
|
0
|
857 x + mid, y,
|
10
|
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
|
10
|
867 XFillPolygon (dpy, win, bgGC, triangle, 3, Convex, ArcChord);
|
0
|
868
|
10
|
869 XDrawSegments (dpy, win, shadowGC, shadow, shadowT * 2);
|
|
870 XDrawSegments (dpy, win, shineGC, shine, shadowT);
|
0
|
871 }
|
|
872
|
10
|
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];
|
|
879 int mid;
|
|
880
|
|
881 mid = width / 2;
|
|
882
|
10
|
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 /* / */
|
10
|
888 make_hor_seg (shine,
|
|
889 x, y + mid,
|
|
890 x + width - shadowT - 1, y, shadowT);
|
0
|
891 /* \| */
|
10
|
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
|
10
|
906 XFillPolygon (dpy, win, bgGC, triangle, 3, Convex, ArcChord);
|
0
|
907
|
10
|
908 XDrawSegments (dpy, win, shadowGC, shadow, shadowT * 2);
|
|
909 XDrawSegments (dpy, win, shineGC, shine, shadowT);
|
0
|
910 }
|
|
911
|
10
|
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
|
10
|
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 /* \- */
|
10
|
927 make_vert_seg (shine,
|
0
|
928 x, y,
|
10
|
929 x + mid, y + height - shadowT - 1, shadowT);
|
|
930 make_vert_seg (shine + shadowT,
|
0
|
931 x, y,
|
10
|
932 x + width - 1, y, shadowT);
|
0
|
933 /* / */
|
10
|
934 make_vert_seg (shadow,
|
0
|
935 x + width - 1, y,
|
10
|
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
|
10
|
945 XFillPolygon (dpy, win, bgGC, triangle, 3, Convex, ArcChord);
|
0
|
946
|
10
|
947 XDrawSegments (dpy, win, shadowGC, shadow, shadowT);
|
|
948 XDrawSegments (dpy, win, shineGC, shine, shadowT * 2);
|
0
|
949 }
|
|
950
|
10
|
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
|
10
|
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 /* |\ */
|
10
|
966 make_hor_seg (shine,
|
0
|
967 x, y,
|
10
|
968 x + width - shadowT - 1, y + mid, shadowT);
|
|
969 make_hor_seg (shine + shadowT,
|
0
|
970 x, y,
|
10
|
971 x, y + height -1, shadowT);
|
0
|
972 /* / */
|
10
|
973 make_hor_seg (shadow,
|
0
|
974 x, y + height -1,
|
10
|
975 x + width - shadowT - 1, y + mid, shadowT);
|
0
|
976
|
|
977 triangle[0].x = x + 1;
|
|
978 triangle[0].y = y + height - 1;
|
|
979 triangle[1].x = x + width - 1;
|
|
980 triangle[1].y = y + mid;
|
|
981 triangle[2].x = x + 1;
|
|
982 triangle[2].y = y;
|
|
983
|
10
|
984 XFillPolygon (dpy, win, bgGC, triangle, 3, Convex, ArcChord);
|
0
|
985
|
10
|
986 XDrawSegments (dpy, win, shadowGC, shadow, shadowT);
|
|
987 XDrawSegments (dpy, win, shineGC, shine, shadowT * 2);
|
0
|
988 }
|
|
989
|
10
|
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 {
|
10
|
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
|
|
998 /*
|
|
999 ** Scrollbar values -> pixels, pixels -> scrollbar values
|
|
1000 */
|
|
1001
|
10
|
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
|
10
|
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
|
|
1022 /* Dont' let knob get smaller than SS_MIN */
|
10
|
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
|
10
|
1028 above -= (int) tmp;
|
0
|
1029 ss = SS_MIN;
|
|
1030 below = ((height) - (ss + above));
|
|
1031
|
10
|
1032 if (above < 0)
|
|
1033 {
|
0
|
1034 above = 0;
|
|
1035 below = height - ss;
|
10
|
1036 }
|
|
1037 if (below < 0)
|
|
1038 {
|
0
|
1039 above = height - ss;
|
|
1040 below = 0;
|
10
|
1041 }
|
|
1042 if (ss > height)
|
|
1043 {
|
0
|
1044 above = 0;
|
|
1045 ss = height;
|
|
1046 below = 0;
|
10
|
1047 }
|
|
1048 }
|
0
|
1049
|
|
1050 *above_return = above;
|
|
1051 *ss_return = ss;
|
|
1052 *below_return = below;
|
|
1053
|
10
|
1054 CHECK (w);
|
0
|
1055 }
|
|
1056
|
10
|
1057 static void
|
|
1058 verify_values (XlwScrollBarWidget w)
|
0
|
1059 {
|
|
1060 int total = w->sb.maximum - w->sb.minimum;
|
|
1061
|
10
|
1062 if (w->sb.sliderSize > total)
|
0
|
1063 w->sb.sliderSize = total;
|
10
|
1064
|
|
1065 if (w->sb.pageIncrement > total)
|
0
|
1066 w->sb.pageIncrement = total;
|
10
|
1067
|
|
1068 if (w->sb.increment > total)
|
0
|
1069 w->sb.increment = total;
|
10
|
1070
|
|
1071 if (w->sb.value < w->sb.minimum)
|
0
|
1072 w->sb.value = w->sb.minimum;
|
10
|
1073
|
|
1074 if (w->sb.value > w->sb.maximum - w->sb.sliderSize)
|
0
|
1075 w->sb.value = w->sb.maximum - w->sb.sliderSize;
|
10
|
1076
|
0
|
1077 }
|
|
1078
|
10
|
1079 static int
|
|
1080 value_from_pixel (XlwScrollBarWidget w, int above)
|
0
|
1081 {
|
|
1082 float total, height, fuz;
|
|
1083 int value, ss;
|
|
1084
|
10
|
1085 height= widget_h (w);
|
|
1086 if (w->sb.showArrows) height -= (2 * arrow_h (w));
|
0
|
1087
|
|
1088 total = w->sb.maximum - w->sb.minimum;
|
10
|
1089 fuz = height / 2;
|
0
|
1090
|
10
|
1091 ss = ((height * w->sb.sliderSize + (total / 2)) / total);
|
0
|
1092
|
10
|
1093 if (ss < SS_MIN)
|
|
1094 {
|
|
1095 /* add a percent amount for integer rounding */
|
0
|
1096 above += ((((SS_MIN - ss) * above) + fuz) / height);
|
10
|
1097 }
|
0
|
1098
|
|
1099 {
|
10
|
1100 /* Prevent SIGFPE's that would occur if we don't truncate the value. */
|
|
1101 float floatval = w->sb.minimum + ((float)(above * total + fuz) / height);
|
0
|
1102 if (floatval >= (float) INT_MAX)
|
|
1103 value = INT_MAX;
|
|
1104 else if (floatval <= (float) INT_MIN)
|
|
1105 value = INT_MIN;
|
|
1106 else
|
|
1107 value = floatval;
|
|
1108 }
|
|
1109
|
10
|
1110 return value;
|
0
|
1111 }
|
|
1112
|
|
1113
|
10
|
1114 static void
|
|
1115 redraw_dimple (XlwScrollBarWidget w, Display *dpy, Window win,
|
|
1116 int x, int y, int width, int height)
|
0
|
1117 {
|
|
1118 GC shine, shadow;
|
|
1119 int shadowT, size;
|
|
1120
|
10
|
1121 if (KNOB_DIMPLE == knob_style (w))
|
|
1122 {
|
|
1123 if (w->sb.armed == ARM_KNOB)
|
|
1124 {
|
|
1125 shine = w->sb.bottomShadowGC;
|
0
|
1126 shadow = w->sb.topShadowGC;
|
10
|
1127 }
|
0
|
1128 else
|
10
|
1129 {
|
|
1130 shine = w->sb.topShadowGC;
|
0
|
1131 shadow = w->sb.bottomShadowGC;
|
10
|
1132 }
|
0
|
1133
|
|
1134 shadowT = w->sb.shadowThickness;
|
|
1135
|
|
1136 x += shadowT;
|
|
1137 y += shadowT;
|
|
1138 width -= 2*shadowT;
|
|
1139 height -= 2*shadowT;
|
|
1140
|
|
1141 size = (width < height ? width : height) * 3 / 4;
|
|
1142
|
10
|
1143 if (size%2 != (width < height ? width : height)%2) size--;
|
0
|
1144
|
10
|
1145 DBUG (fprintf (stderr, "%d %d\n",
|
|
1146 x + (width / 2) - (size / 2) - 2*shadowT,
|
|
1147 width - size - shadowT));
|
0
|
1148
|
10
|
1149 draw_dimple (dpy, win, shine, shadow,
|
|
1150 x + (width / 2) - (size / 2),
|
0
|
1151 y + (height / 2) - (size / 2),
|
10
|
1152 size, size);
|
|
1153 }
|
0
|
1154 }
|
|
1155
|
10
|
1156 static void
|
|
1157 draw_knob (XlwScrollBarWidget w, int above, int ss, int below)
|
0
|
1158 {
|
10
|
1159 Display *dpy = XtDisplay ((Widget) w);
|
|
1160 Window win = XtWindow ((Widget) w);
|
0
|
1161 int x, y, width, height;
|
|
1162 int shadowT;
|
|
1163
|
10
|
1164 x = widget_x (w);
|
|
1165 y = widget_y (w);
|
|
1166 width = widget_w (w);
|
|
1167 height = widget_h (w);
|
0
|
1168
|
|
1169 shadowT = w->sb.shadowThickness;
|
|
1170
|
10
|
1171 if (shadowT > (width / 2)) shadowT = (width / 2);
|
|
1172 if (shadowT > (height / 2)) shadowT = (height / 2);
|
|
1173 if (shadowT <= 0) return;
|
0
|
1174
|
10
|
1175 if (w->sb.showArrows && !arrow_same_end (w)) y += arrow_h (w);
|
0
|
1176
|
|
1177 /* trough above knob */
|
10
|
1178 if (above > 0)
|
|
1179 {
|
|
1180 if (VERT (w))
|
|
1181 XClearArea (dpy, win, x, y, width, above, False);
|
0
|
1182 else
|
10
|
1183 XClearArea (dpy, win, y, x, above, width, False);
|
|
1184 }
|
0
|
1185
|
|
1186 /* knob */
|
10
|
1187 if (VERT (w))
|
|
1188 {
|
|
1189 draw_shadows (dpy, win, w->sb.topShadowGC, w->sb.bottomShadowGC,
|
0
|
1190 x, y + above, width, ss, shadowT);
|
10
|
1191 XFillRectangle (dpy, win,
|
0
|
1192 w->sb.backgroundGC,
|
10
|
1193 x+shadowT, y + above + shadowT, width-2*shadowT, ss-2*shadowT);
|
|
1194 redraw_dimple (w, dpy, win, x, y + above, width, ss);
|
|
1195 }
|
0
|
1196 else
|
10
|
1197 {
|
|
1198 draw_shadows (dpy, win, w->sb.topShadowGC, w->sb.bottomShadowGC,
|
0
|
1199 y + above, x, ss, width, shadowT);
|
10
|
1200 XFillRectangle (dpy, win,
|
0
|
1201 w->sb.backgroundGC,
|
10
|
1202 y + above + shadowT, x+shadowT, ss-2*shadowT, width-2*shadowT);
|
|
1203 redraw_dimple (w, dpy, win, y + above, x, ss, width);
|
|
1204 }
|
0
|
1205
|
|
1206 /* trough below knob */
|
10
|
1207 if (below > 0)
|
|
1208 {
|
|
1209 if (VERT (w))
|
|
1210 XClearArea (dpy, win, x, y + above + ss, width, below, False);
|
0
|
1211 else
|
10
|
1212 XClearArea (dpy, win, y + above + ss, x, below, width, False);
|
|
1213 }
|
0
|
1214
|
10
|
1215 CHECK (w);
|
0
|
1216 }
|
|
1217
|
10
|
1218 static void
|
|
1219 redraw_up_arrow (XlwScrollBarWidget w, Boolean armed, Boolean clear_behind)
|
0
|
1220 {
|
10
|
1221 Display *dpy = XtDisplay ((Widget) w);
|
|
1222 Window win = XtWindow ((Widget) w);
|
0
|
1223 GC bg, shine, shadow;
|
|
1224 int x, y, width, height, arrow_height, shadowT;
|
|
1225
|
10
|
1226 x = widget_x (w);
|
|
1227 y = widget_y (w);
|
|
1228 width = widget_w (w);
|
|
1229 height = widget_h (w);
|
|
1230 arrow_height = arrow_h (w);
|
0
|
1231
|
|
1232 shadowT = w->sb.shadowThickness;
|
|
1233 bg = w->sb.backgroundGC;
|
|
1234
|
10
|
1235 if (armed)
|
|
1236 {
|
0
|
1237 shine = w->sb.bottomShadowGC;
|
|
1238 shadow = w->sb.topShadowGC;
|
10
|
1239 }
|
0
|
1240 else
|
10
|
1241 {
|
0
|
1242 shine = w->sb.topShadowGC;
|
|
1243 shadow = w->sb.bottomShadowGC;
|
10
|
1244 }
|
0
|
1245
|
10
|
1246 if (VERT (w))
|
|
1247 {
|
|
1248 if (arrow_same_end (w))
|
|
1249 {
|
|
1250 y += height - 2 * arrow_h (w) + 2;
|
|
1251 }
|
|
1252 if (clear_behind)
|
|
1253 XClearArea (dpy, win, x, y, width, arrow_height + 1, False);
|
|
1254 draw_arrow_up (dpy, win, bg, shine, shadow,
|
0
|
1255 x + (width - arrow_height)/2, y,
|
10
|
1256 arrow_height, arrow_height, shadowT);
|
|
1257 }
|
0
|
1258 else
|
10
|
1259 {
|
|
1260 if (arrow_same_end (w))
|
|
1261 {
|
|
1262 y += height - 2 * arrow_h (w);
|
|
1263 }
|
|
1264 if (clear_behind)
|
|
1265 XClearArea (dpy, win, y, x, arrow_height + 1, height, False);
|
|
1266 draw_arrow_left (dpy, win, bg, shine, shadow,
|
0
|
1267 y, x + (width - arrow_height)/2,
|
10
|
1268 arrow_height, arrow_height, shadowT);
|
|
1269 }
|
0
|
1270 }
|
|
1271
|
10
|
1272 static void
|
|
1273 redraw_down_arrow (XlwScrollBarWidget w, Boolean armed, Boolean clear_behind)
|
0
|
1274 {
|
10
|
1275 Display *dpy = XtDisplay ((Widget) w);
|
|
1276 Window win = XtWindow ((Widget) w);
|
0
|
1277 GC bg, shine, shadow;
|
|
1278 int x, y, width, height, arrow_height, shadowT;
|
|
1279
|
10
|
1280 x = widget_x (w);
|
|
1281 y = widget_y (w);
|
|
1282 width = widget_w (w);
|
|
1283 height = widget_h (w);
|
|
1284 arrow_height = arrow_h (w);
|
0
|
1285
|
|
1286 shadowT = w->sb.shadowThickness;
|
|
1287 bg = w->sb.backgroundGC;
|
|
1288
|
10
|
1289 if (armed)
|
|
1290 {
|
|
1291 shine = w->sb.bottomShadowGC;
|
|
1292 shadow = w->sb.topShadowGC;
|
|
1293 }
|
0
|
1294 else
|
10
|
1295 {
|
|
1296 shine = w->sb.topShadowGC;
|
|
1297 shadow = w->sb.bottomShadowGC;
|
|
1298 }
|
0
|
1299
|
10
|
1300 if (VERT (w))
|
|
1301 {
|
|
1302 if (clear_behind)
|
|
1303 XClearArea (dpy, win, x, y + height - arrow_height, width,
|
|
1304 arrow_height + 1, False);
|
|
1305 draw_arrow_down (dpy, win, bg, shine, shadow,
|
|
1306 x + (width - arrow_height)/2,
|
|
1307 y + height - arrow_height + 1,
|
|
1308 arrow_height, arrow_height, shadowT);
|
|
1309 }
|
0
|
1310 else
|
10
|
1311 {
|
|
1312 if (clear_behind)
|
|
1313 XClearArea (dpy, win, y + height - arrow_height, x,
|
|
1314 arrow_height + 1, height, False);
|
|
1315 draw_arrow_right (dpy, win, bg, shine, shadow,
|
|
1316 y + height - arrow_height + 1,
|
|
1317 x + (width - arrow_height)/2,
|
|
1318 arrow_height, arrow_height, shadowT);
|
|
1319 }
|
0
|
1320 }
|
|
1321
|
10
|
1322 static void
|
|
1323 redraw_everything (XlwScrollBarWidget w, Region region, Boolean behind_arrows)
|
0
|
1324 {
|
10
|
1325 Display *dpy = XtDisplay ((Widget) w);
|
|
1326 Window win = XtWindow ((Widget) w);
|
0
|
1327 int x, y, width, height, shadowT, tmp;
|
|
1328
|
10
|
1329 x = widget_x (w);
|
|
1330 y = widget_y (w);
|
|
1331 width = widget_w (w);
|
|
1332 height = widget_h (w);
|
0
|
1333 shadowT = w->sb.shadowThickness;
|
|
1334
|
10
|
1335 if (w->sb.showArrows)
|
|
1336 {
|
|
1337 if (region == NULL || XRectInRegion (region, x, y, width, width))
|
|
1338 {
|
|
1339 redraw_up_arrow (w, False, behind_arrows);
|
|
1340 }
|
|
1341 if (VERT (w))
|
|
1342 {
|
0
|
1343 y = y + height - width + 1;
|
10
|
1344 }
|
0
|
1345 else
|
10
|
1346 {
|
0
|
1347 tmp = y;
|
|
1348 y = x;
|
|
1349 x = tmp + height - width + 1;
|
10
|
1350 }
|
|
1351 if (region == NULL || XRectInRegion (region, x, y, width, width))
|
|
1352 {
|
|
1353 redraw_down_arrow (w, False, behind_arrows);
|
|
1354 }
|
|
1355 }
|
0
|
1356
|
10
|
1357 draw_shadows (dpy, win, w->sb.bottomShadowGC, w->sb.topShadowGC,
|
0
|
1358 0, 0, w->core.width, w->core.height, shadowT);
|
|
1359
|
10
|
1360 draw_knob (w, w->sb.above, w->sb.ss, w->sb.below);
|
0
|
1361
|
|
1362 }
|
|
1363
|
|
1364 /************************************************************************
|
|
1365 **
|
10
|
1366 ** Method functions
|
0
|
1367 **
|
|
1368 */
|
|
1369
|
10
|
1370 static void
|
|
1371 Initialize (Widget treq, Widget tnew, ArgList args, Cardinal *num_args)
|
0
|
1372 {
|
|
1373 XlwScrollBarWidget request = (XlwScrollBarWidget) treq;
|
|
1374 XlwScrollBarWidget w = (XlwScrollBarWidget) tnew;
|
10
|
1375 Display *dpy = XtDisplay ((Widget) w);
|
|
1376 Window win = RootWindowOfScreen (DefaultScreenOfDisplay (dpy));
|
0
|
1377
|
10
|
1378 DBUG (fprintf (stderr, "Initialize\n"));
|
0
|
1379
|
10
|
1380 if (request->core.width == 0) w->core.width += (VERT (w) ? 12 : 25);
|
|
1381 if (request->core.height == 0) w->core.height += (VERT (w) ? 25 : 12);
|
0
|
1382
|
10
|
1383 verify_values (w);
|
0
|
1384
|
|
1385 w->sb.lastY = 0;
|
|
1386 w->sb.above = 0;
|
|
1387 w->sb.ss = 0;
|
|
1388 w->sb.below = 0;
|
|
1389 w->sb.armed = ARM_NONE;
|
|
1390
|
10
|
1391 if (w->sb.shadowThickness > 5) w->sb.shadowThickness = 5;
|
0
|
1392
|
|
1393 w->sb.grayPixmap =
|
10
|
1394 XCreatePixmapFromBitmapData (dpy, win, (char *) gray_bits, gray_width,
|
|
1395 gray_height, 1, 0, 1);
|
0
|
1396
|
10
|
1397 make_trough_pixel (w);
|
|
1398
|
|
1399 make_shadow_pixels (w);
|
0
|
1400
|
10
|
1401 w->sb.backgroundGC =
|
|
1402 get_gc (w, w->core.background_pixel, w->core.background_pixel, None);
|
|
1403 w->sb.topShadowGC =
|
|
1404 get_gc (w, w->sb.topShadowColor, w->core.background_pixel,
|
|
1405 w->sb.topShadowPixmap);
|
|
1406 w->sb.bottomShadowGC =
|
|
1407 get_gc (w, w->sb.bottomShadowColor, w->core.background_pixel,
|
|
1408 w->sb.bottomShadowPixmap);
|
0
|
1409
|
|
1410 w->sb.fullRedrawNext = True;
|
10
|
1411
|
|
1412 w->sb.timerActive = False;
|
0
|
1413 }
|
|
1414
|
10
|
1415 static void
|
|
1416 Destroy (Widget widget)
|
0
|
1417 {
|
|
1418 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
10
|
1419 Display *dpy = XtDisplay ((Widget) w);
|
0
|
1420
|
10
|
1421 DBUG (fprintf (stderr, "Destroy\n"));
|
0
|
1422
|
10
|
1423 XtReleaseGC (widget, w->sb.bottomShadowGC);
|
|
1424 XtReleaseGC (widget, w->sb.topShadowGC);
|
|
1425 XtReleaseGC (widget, w->sb.backgroundGC);
|
0
|
1426
|
10
|
1427 XFreePixmap (dpy, w->sb.grayPixmap);
|
|
1428
|
|
1429 if (w->sb.timerActive)
|
|
1430 XtRemoveTimeOut (w->sb.timerId);
|
0
|
1431 }
|
|
1432
|
10
|
1433 static void
|
|
1434 Realize (Widget widget, XtValueMask *valuemask, XSetWindowAttributes *attr)
|
0
|
1435 {
|
|
1436 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
10
|
1437 Display *dpy = XtDisplay ((Widget) w);
|
0
|
1438 Window win;
|
|
1439 XSetWindowAttributes win_attr;
|
|
1440
|
10
|
1441 DBUG (fprintf (stderr, "Realize\n"));
|
0
|
1442
|
|
1443 (*coreClassRec.core_class.realize)(widget, valuemask, attr);
|
|
1444
|
10
|
1445 win = XtWindow ((Widget) w);
|
0
|
1446
|
10
|
1447 seg_pixel_sizes (w, &w->sb.above, &w->sb.ss, &w->sb.below);
|
0
|
1448
|
10
|
1449 XSetWindowBackground (dpy, win, w->sb.troughColor);
|
0
|
1450
|
|
1451 /* Change bit gravity so widget is not cleared on resize */
|
|
1452 win_attr.bit_gravity = NorthWestGravity;
|
10
|
1453 XChangeWindowAttributes (dpy, win, CWBitGravity , &win_attr);
|
0
|
1454
|
|
1455 }
|
|
1456
|
10
|
1457 static void
|
|
1458 Resize (Widget widget)
|
0
|
1459 {
|
|
1460 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
10
|
1461 Display *dpy = XtDisplay ((Widget) w);
|
|
1462 Window win = XtWindow ((Widget) w);
|
0
|
1463
|
10
|
1464 if (XtIsRealized (widget))
|
|
1465 {
|
|
1466 DBUG (fprintf (stderr, "Resize = %08lx\n", w));
|
0
|
1467
|
10
|
1468 seg_pixel_sizes (w, &w->sb.above, &w->sb.ss, &w->sb.below);
|
0
|
1469
|
|
1470 /*redraw_everything(w, NULL, True);*/
|
|
1471
|
|
1472 w->sb.fullRedrawNext = True;
|
|
1473 /* Force expose event */
|
10
|
1474 XClearArea (dpy, win, widget_x(w), widget_y(w), 1, 1, True);
|
|
1475 }
|
0
|
1476 }
|
|
1477
|
10
|
1478 static void
|
|
1479 Redisplay (Widget widget, XEvent *event, Region region)
|
0
|
1480 {
|
|
1481 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
|
1482
|
10
|
1483 DBUG (fprintf (stderr, "Redisplay = %08lx\n", w));
|
0
|
1484
|
10
|
1485 if (XtIsRealized (widget))
|
|
1486 {
|
|
1487 if (w->sb.fullRedrawNext)
|
|
1488 {
|
|
1489 redraw_everything (w, NULL, True);
|
|
1490 }
|
0
|
1491 else
|
10
|
1492 {
|
|
1493 redraw_everything (w, region, False);
|
|
1494 }
|
0
|
1495 w->sb.fullRedrawNext = False;
|
10
|
1496 }
|
0
|
1497 }
|
|
1498
|
10
|
1499 static Boolean
|
|
1500 SetValues (Widget current, Widget request, Widget neww,
|
|
1501 ArgList args, Cardinal *num_args)
|
0
|
1502 {
|
|
1503 XlwScrollBarWidget cur = (XlwScrollBarWidget) current;
|
|
1504 XlwScrollBarWidget w = (XlwScrollBarWidget) neww;
|
|
1505 Boolean do_redisplay = False;
|
|
1506
|
10
|
1507 if (cur->sb.troughColor != w->sb.troughColor)
|
|
1508 {
|
|
1509 if (XtIsRealized ((Widget) w))
|
|
1510 {
|
|
1511 XSetWindowBackground (XtDisplay((Widget) w), XtWindow ((Widget) w),
|
0
|
1512 w->sb.troughColor);
|
|
1513 do_redisplay = True;
|
10
|
1514 }
|
|
1515 }
|
0
|
1516
|
10
|
1517 if (cur->core.background_pixel != w->core.background_pixel)
|
|
1518 {
|
|
1519 XtReleaseGC ((Widget)cur, cur->sb.backgroundGC);
|
|
1520 w->sb.backgroundGC =
|
|
1521 get_gc (w, w->core.background_pixel, w->core.background_pixel, None);
|
0
|
1522 do_redisplay = True;
|
10
|
1523 }
|
0
|
1524
|
10
|
1525 if (cur->sb.topShadowColor != w->sb.topShadowColor ||
|
|
1526 cur->sb.topShadowPixmap != w->sb.topShadowPixmap)
|
|
1527 {
|
|
1528 XtReleaseGC ((Widget)cur, cur->sb.topShadowGC);
|
|
1529 w->sb.topShadowGC =
|
|
1530 get_gc (w, w->sb.topShadowColor, w->core.background_pixel,
|
|
1531 w->sb.topShadowPixmap);
|
0
|
1532 do_redisplay = True;
|
10
|
1533 }
|
0
|
1534
|
10
|
1535 if (cur->sb.bottomShadowColor != w->sb.bottomShadowColor ||
|
|
1536 cur->sb.bottomShadowPixmap != w->sb.bottomShadowPixmap)
|
|
1537 {
|
|
1538 XtReleaseGC ((Widget)cur, cur->sb.bottomShadowGC);
|
|
1539 w->sb.bottomShadowGC =
|
|
1540 get_gc (w, w->sb.bottomShadowColor, w->core.background_pixel,
|
|
1541 w->sb.bottomShadowPixmap);
|
0
|
1542 do_redisplay = True;
|
10
|
1543 }
|
0
|
1544
|
10
|
1545 if (cur->sb.orientation != w->sb.orientation)
|
|
1546 {
|
0
|
1547 do_redisplay = True;
|
10
|
1548 }
|
0
|
1549
|
|
1550
|
10
|
1551 if (cur->sb.minimum != w->sb.minimum ||
|
0
|
1552 cur->sb.maximum != w->sb.maximum ||
|
|
1553 cur->sb.sliderSize != w->sb.sliderSize ||
|
|
1554 cur->sb.value != w->sb.value ||
|
|
1555 cur->sb.pageIncrement != w->sb.pageIncrement ||
|
10
|
1556 cur->sb.increment != w->sb.increment)
|
|
1557 {
|
|
1558 verify_values (w);
|
|
1559 if (XtIsRealized ((Widget) w))
|
|
1560 {
|
|
1561 seg_pixel_sizes (w, &w->sb.above, &w->sb.ss, &w->sb.below);
|
|
1562 draw_knob (w, w->sb.above, w->sb.ss, w->sb.below);
|
|
1563 }
|
|
1564 }
|
0
|
1565
|
10
|
1566 if (w->sb.shadowThickness > 5) w->sb.shadowThickness = 5;
|
0
|
1567
|
10
|
1568 return do_redisplay;
|
0
|
1569 }
|
|
1570
|
10
|
1571 void
|
|
1572 XlwScrollBarGetValues (Widget widget, int *value, int *sliderSize,
|
|
1573 int *increment, int *pageIncrement)
|
0
|
1574 {
|
10
|
1575 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
0
|
1576
|
10
|
1577 if (w && XtClass ((Widget) w) == xlwScrollBarWidgetClass)
|
|
1578 {
|
|
1579 if (value) *value = w->sb.value;
|
|
1580 if (sliderSize) *sliderSize = w->sb.sliderSize;
|
|
1581 if (increment) *increment = w->sb.increment;
|
|
1582 if (pageIncrement) *pageIncrement = w->sb.pageIncrement;
|
|
1583 }
|
0
|
1584 }
|
|
1585
|
10
|
1586 void
|
|
1587 XlwScrollBarSetValues (Widget widget, int value, int sliderSize,
|
|
1588 int increment, int pageIncrement, Boolean notify)
|
0
|
1589 {
|
10
|
1590 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
0
|
1591 int last_value;
|
|
1592
|
10
|
1593 if (w && XtClass ((Widget) w) == xlwScrollBarWidgetClass &&
|
0
|
1594 (w->sb.value != value ||
|
|
1595 w->sb.sliderSize != sliderSize ||
|
|
1596 w->sb.increment != increment ||
|
10
|
1597 w->sb.pageIncrement != pageIncrement))
|
|
1598 {
|
0
|
1599 w->sb.value = value;
|
|
1600 w->sb.sliderSize = sliderSize;
|
|
1601 w->sb.increment = increment;
|
|
1602 w->sb.pageIncrement = pageIncrement;
|
|
1603
|
10
|
1604 verify_values (w);
|
0
|
1605
|
10
|
1606 if (XtIsRealized (widget))
|
|
1607 {
|
|
1608 seg_pixel_sizes (w, &w->sb.above, &w->sb.ss, &w->sb.below);
|
|
1609 draw_knob (w, w->sb.above, w->sb.ss, w->sb.below);
|
0
|
1610
|
|
1611 last_value = w->sb.value;
|
10
|
1612 w->sb.value = value_from_pixel (w, w->sb.above);
|
|
1613 verify_values (w);
|
0
|
1614
|
10
|
1615 if (w->sb.value != last_value && notify)
|
|
1616 {
|
|
1617 call_callbacks (w, XmCR_VALUE_CHANGED, w->sb.value, 0, NULL);
|
|
1618 }
|
|
1619 }
|
|
1620 }
|
0
|
1621 }
|
|
1622
|
|
1623 /************************************************************************
|
|
1624 **
|
10
|
1625 ** Action functions
|
0
|
1626 **
|
|
1627 */
|
|
1628
|
10
|
1629 static void
|
|
1630 timer (XtPointer data, XtIntervalId *id)
|
0
|
1631 {
|
10
|
1632 XlwScrollBarWidget w = (XlwScrollBarWidget) data;
|
0
|
1633 int reason, last_value;
|
10
|
1634
|
|
1635 w->sb.timerActive = False;
|
0
|
1636
|
10
|
1637 if (w->sb.armed != ARM_NONE)
|
|
1638 {
|
0
|
1639 last_value = w->sb.value;
|
|
1640 reason = XmCR_NONE;
|
|
1641
|
10
|
1642 switch (w->sb.armed)
|
|
1643 {
|
|
1644 case ARM_PAGEUP:
|
|
1645 w->sb.value = safe_subtract (w->sb.value, w->sb.pageIncrement);
|
|
1646 reason = XmCR_PAGE_DECREMENT;
|
|
1647 break;
|
|
1648 case ARM_PAGEDOWN:
|
|
1649 w->sb.value = safe_add (w->sb.value, w->sb.pageIncrement);
|
|
1650 reason = XmCR_PAGE_INCREMENT;
|
|
1651 break;
|
|
1652 case ARM_UP:
|
|
1653 w->sb.value = safe_subtract (w->sb.value, w->sb.increment);
|
|
1654 reason = XmCR_DECREMENT;
|
|
1655 break;
|
|
1656 case ARM_DOWN:
|
|
1657 w->sb.value = safe_add (w->sb.value, w->sb.increment);
|
|
1658 reason = XmCR_INCREMENT;
|
|
1659 break;
|
|
1660 }
|
0
|
1661
|
10
|
1662 verify_values (w);
|
|
1663
|
|
1664 if (last_value != w->sb.value)
|
|
1665 {
|
|
1666 seg_pixel_sizes (w, &w->sb.above, &w->sb.ss, &w->sb.below);
|
|
1667 draw_knob (w, w->sb.above, w->sb.ss, w->sb.below);
|
0
|
1668
|
10
|
1669 call_callbacks (w, reason, w->sb.value, 0, NULL);
|
0
|
1670
|
10
|
1671 w->sb.timerId =
|
|
1672 XtAppAddTimeOut (XtWidgetToApplicationContext ((Widget) w),
|
|
1673 (unsigned long) w->sb.repeatDelay,
|
|
1674 timer, (XtPointer) w);
|
|
1675 w->sb.timerActive = True;
|
|
1676 }
|
|
1677 }
|
0
|
1678 }
|
|
1679
|
10
|
1680 static int
|
|
1681 what_button (XlwScrollBarWidget w, int mouse_x, int mouse_y)
|
0
|
1682 {
|
|
1683 int x, y, width, height, arrow_height_top, arrow_height_bottom;
|
|
1684 int where;
|
|
1685
|
10
|
1686 x = widget_x (w);
|
|
1687 y = widget_y (w);
|
|
1688 width = widget_w (w);
|
|
1689 height = widget_h (w);
|
0
|
1690
|
|
1691 #if 0
|
10
|
1692 arrow_height = w->sb.showArrows ? arrow_h (w) : 0;
|
0
|
1693 #endif
|
10
|
1694 if (w->sb.showArrows)
|
|
1695 {
|
|
1696 if (arrow_same_end (w))
|
|
1697 {
|
0
|
1698 arrow_height_top = 0;
|
10
|
1699 arrow_height_bottom = 2 * arrow_h (w);
|
|
1700 }
|
0
|
1701 else
|
10
|
1702 {
|
|
1703 arrow_height_top = arrow_height_bottom = arrow_h (w);
|
|
1704 }
|
|
1705 }
|
0
|
1706 else
|
10
|
1707 {
|
0
|
1708 arrow_height_top = arrow_height_bottom = 0;
|
10
|
1709 }
|
0
|
1710
|
|
1711 where = BUTTON_NONE;
|
|
1712
|
10
|
1713 if (mouse_x > x && mouse_x < (x + width))
|
|
1714 {
|
|
1715 if (mouse_y > (y + arrow_height_top) &&
|
|
1716 mouse_y < (y + height - arrow_height_bottom))
|
|
1717 {
|
|
1718 if (mouse_y < (y + w->sb.above + arrow_height_top))
|
|
1719 {
|
0
|
1720 where = BUTTON_TROUGH_ABOVE;
|
10
|
1721 }
|
|
1722 else if (mouse_y > (y + w->sb.above + w->sb.ss + arrow_height_top))
|
|
1723 {
|
0
|
1724 where = BUTTON_TROUGH_BELOW;
|
10
|
1725 }
|
0
|
1726 else
|
10
|
1727 {
|
0
|
1728 where = BUTTON_KNOB;
|
10
|
1729 }
|
|
1730 }
|
|
1731 else if (arrow_same_end (w))
|
|
1732 {
|
|
1733 if (mouse_y > (y + height - arrow_height_bottom + 1) &&
|
|
1734 mouse_y < (y + height))
|
|
1735 {
|
|
1736 if (mouse_y < (y + height - arrow_height_bottom/2))
|
|
1737 {
|
0
|
1738 where = BUTTON_UP_ARROW;
|
10
|
1739 }
|
0
|
1740 else
|
10
|
1741 {
|
0
|
1742 where = BUTTON_DOWN_ARROW;
|
10
|
1743 }
|
|
1744 }
|
|
1745 }
|
0
|
1746 else
|
10
|
1747 {
|
|
1748 if (mouse_y > y && mouse_y < (y + arrow_height_top))
|
|
1749 {
|
0
|
1750 where = BUTTON_UP_ARROW;
|
10
|
1751 }
|
|
1752 else if (mouse_y > (y + height - arrow_height_bottom + 1) &&
|
|
1753 mouse_y < (y + height))
|
|
1754 {
|
0
|
1755 where = BUTTON_DOWN_ARROW;
|
10
|
1756 }
|
|
1757 }
|
|
1758 }
|
0
|
1759 #if 0
|
10
|
1760 if (mouse_x > x && mouse_x < (x + width))
|
|
1761 {
|
|
1762 if (mouse_y > (y + arrow_height) && mouse_y < (y + height - arrow_height))
|
|
1763 {
|
|
1764 if (mouse_y < (y+w->sb.above+arrow_height))
|
|
1765 {
|
0
|
1766 where = BUTTON_TROUGH_ABOVE;
|
10
|
1767 }
|
|
1768 else if (mouse_y > (y + w->sb.above + w->sb.ss + arrow_height))
|
|
1769 {
|
0
|
1770 where = BUTTON_TROUGH_BELOW;
|
10
|
1771 }
|
0
|
1772 else
|
10
|
1773 {
|
0
|
1774 where = BUTTON_KNOB;
|
10
|
1775 }
|
|
1776 }
|
|
1777 else if (mouse_y > y && mouse_y < (y + arrow_height))
|
|
1778 {
|
0
|
1779 where = BUTTON_UP_ARROW;
|
10
|
1780 }
|
|
1781 else if (mouse_y > (y + height - arrow_height + 1) &&
|
|
1782 mouse_y < (y + height))
|
|
1783 {
|
0
|
1784 where = BUTTON_DOWN_ARROW;
|
10
|
1785 }
|
|
1786 }
|
0
|
1787 #endif
|
10
|
1788 return where;
|
0
|
1789 }
|
|
1790
|
10
|
1791 #define FORCED_SCROLL_NONE 0
|
0
|
1792 #define FORCED_SCROLL_DOWNRIGHT 1
|
|
1793 #define FORCED_SCROLL_UPLEFT 2
|
|
1794
|
|
1795 int forced_scroll_flag = FORCED_SCROLL_NONE;
|
|
1796
|
10
|
1797 static void
|
|
1798 PageDownOrRight (Widget widget, XEvent *event, String *parms, Cardinal *num_parms)
|
0
|
1799 {
|
|
1800 forced_scroll_flag = FORCED_SCROLL_DOWNRIGHT;
|
10
|
1801 Select (widget, event, parms, num_parms);
|
0
|
1802 forced_scroll_flag = FORCED_SCROLL_NONE;
|
|
1803 }
|
|
1804
|
10
|
1805 static void
|
|
1806 PageUpOrLeft (Widget widget, XEvent *event, String *parms, Cardinal *num_parms)
|
0
|
1807 {
|
|
1808 forced_scroll_flag = FORCED_SCROLL_UPLEFT;
|
10
|
1809 Select (widget, event, parms, num_parms);
|
0
|
1810 forced_scroll_flag = FORCED_SCROLL_NONE;
|
|
1811 }
|
|
1812
|
10
|
1813 static void
|
|
1814 Select (Widget widget, XEvent *event, String *parms, Cardinal *num_parms)
|
0
|
1815 {
|
10
|
1816 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
0
|
1817 int mouse_x, mouse_y;
|
|
1818 int reason, last_value;
|
|
1819 int sb_button;
|
|
1820
|
10
|
1821 DBUG (fprintf (stderr, "Select:\n"));
|
0
|
1822
|
10
|
1823 mouse_x = event_x (w, event);
|
|
1824 mouse_y = event_y (w, event);
|
0
|
1825
|
|
1826 w->sb.savedValue = w->sb.value;
|
|
1827
|
|
1828 last_value = w->sb.value;
|
|
1829 reason = XmCR_NONE;
|
|
1830
|
10
|
1831 XtGrabKeyboard ((Widget) w, False, GrabModeAsync, GrabModeAsync,
|
|
1832 event->xbutton.time);
|
0
|
1833
|
10
|
1834 sb_button = what_button (w, mouse_x, mouse_y);
|
|
1835
|
|
1836 if (forced_scroll_flag != FORCED_SCROLL_NONE)
|
0
|
1837 {
|
10
|
1838 switch (sb_button)
|
0
|
1839 {
|
|
1840 case BUTTON_TROUGH_ABOVE:
|
|
1841 case BUTTON_TROUGH_BELOW:
|
|
1842 case BUTTON_KNOB:
|
|
1843 sb_button= BUTTON_NONE; /* cause next switch to fall through */
|
10
|
1844 if (forced_scroll_flag == FORCED_SCROLL_UPLEFT)
|
0
|
1845 {
|
10
|
1846 w->sb.value = safe_subtract (w->sb.value, w->sb.pageIncrement);
|
0
|
1847 w->sb.armed = ARM_PAGEUP;
|
|
1848 reason = XmCR_PAGE_DECREMENT;
|
|
1849 break;
|
|
1850 }
|
10
|
1851 else if (forced_scroll_flag == FORCED_SCROLL_DOWNRIGHT)
|
0
|
1852 {
|
10
|
1853 w->sb.value = safe_add (w->sb.value, w->sb.pageIncrement);
|
0
|
1854 w->sb.armed = ARM_PAGEDOWN;
|
|
1855 reason = XmCR_PAGE_INCREMENT;
|
|
1856 break;
|
|
1857 }
|
|
1858 abort();
|
|
1859 }
|
|
1860 }
|
|
1861
|
10
|
1862 switch (sb_button)
|
|
1863 {
|
|
1864 case BUTTON_TROUGH_ABOVE:
|
|
1865 w->sb.value = safe_subtract (w->sb.value, w->sb.pageIncrement);
|
|
1866 w->sb.armed = ARM_PAGEUP;
|
|
1867 reason = XmCR_PAGE_DECREMENT;
|
|
1868 break;
|
|
1869 case BUTTON_TROUGH_BELOW:
|
|
1870 w->sb.value = safe_add (w->sb.value, w->sb.pageIncrement);
|
|
1871 w->sb.armed = ARM_PAGEDOWN;
|
|
1872 reason = XmCR_PAGE_INCREMENT;
|
|
1873 break;
|
|
1874 case BUTTON_KNOB:
|
|
1875 w->sb.lastY = mouse_y;
|
|
1876 w->sb.armed = ARM_KNOB;
|
|
1877 draw_knob (w, w->sb.above, w->sb.ss, w->sb.below);
|
|
1878 break;
|
|
1879 case BUTTON_UP_ARROW:
|
|
1880 if (event->xbutton.state & ControlMask)
|
|
1881 {
|
|
1882 w->sb.value = INT_MIN;
|
|
1883 w->sb.armed = ARM_UP;
|
|
1884 reason = XmCR_TO_TOP;
|
|
1885 }
|
|
1886 else
|
|
1887 {
|
|
1888 w->sb.value = safe_subtract (w->sb.value, w->sb.increment);
|
|
1889 w->sb.armed = ARM_UP;
|
|
1890 reason = XmCR_DECREMENT;
|
|
1891 }
|
|
1892 redraw_up_arrow (w, True, False);
|
|
1893 break;
|
|
1894 case BUTTON_DOWN_ARROW:
|
|
1895 if (event->xbutton.state & ControlMask)
|
|
1896 {
|
|
1897 w->sb.value = INT_MAX;
|
|
1898 w->sb.armed = ARM_DOWN;
|
|
1899 reason = XmCR_TO_BOTTOM;
|
|
1900 }
|
|
1901 else
|
|
1902 {
|
|
1903 w->sb.value = safe_add (w->sb.value, w->sb.increment);
|
|
1904 w->sb.armed = ARM_DOWN;
|
|
1905 reason = XmCR_INCREMENT;
|
|
1906 }
|
|
1907 redraw_down_arrow (w, True, False);
|
|
1908 break;
|
|
1909 }
|
0
|
1910
|
10
|
1911 verify_values (w);
|
0
|
1912
|
10
|
1913 if (last_value != w->sb.value)
|
|
1914 {
|
|
1915 seg_pixel_sizes (w, &w->sb.above, &w->sb.ss, &w->sb.below);
|
|
1916 draw_knob (w, w->sb.above, w->sb.ss, w->sb.below);
|
0
|
1917
|
10
|
1918 call_callbacks (w, reason, w->sb.value, mouse_y, event);
|
|
1919
|
|
1920 if (w->sb.timerActive)
|
|
1921 XtRemoveTimeOut (w->sb.timerId);
|
0
|
1922
|
10
|
1923 w->sb.timerId =
|
|
1924 XtAppAddTimeOut (XtWidgetToApplicationContext ((Widget) w),
|
|
1925 (unsigned long) w->sb.initialDelay,
|
|
1926 timer, (XtPointer) w);
|
|
1927 w->sb.timerActive = True;
|
|
1928 }
|
0
|
1929
|
10
|
1930 CHECK (w);
|
0
|
1931 }
|
|
1932
|
10
|
1933 static void
|
|
1934 Drag (Widget widget, XEvent *event, String *parms, Cardinal *num_parms)
|
0
|
1935 {
|
10
|
1936 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
0
|
1937 int diff;
|
|
1938 int height, mouse_y;
|
|
1939 int last_value, last_above;
|
|
1940
|
10
|
1941 DBUG (fprintf (stderr, "Drag:\n"));
|
0
|
1942
|
10
|
1943 if (w->sb.armed == ARM_KNOB)
|
|
1944 {
|
|
1945 height = widget_h (w);
|
|
1946 if (w->sb.showArrows) height -= (2 * arrow_h (w));
|
0
|
1947
|
10
|
1948 mouse_y = event_y (w, event);
|
0
|
1949
|
|
1950 diff = mouse_y - w->sb.lastY;
|
|
1951
|
|
1952 last_above = w->sb.above;
|
|
1953 last_value = w->sb.value;
|
|
1954
|
10
|
1955 if (diff < 0)
|
|
1956 {
|
0
|
1957 /* up */
|
|
1958 w->sb.above -= (-diff);
|
10
|
1959 if (w->sb.above < 0)
|
|
1960 {
|
0
|
1961 mouse_y = (mouse_y - w->sb.above);
|
|
1962 w->sb.above = 0;
|
|
1963 diff = 0;
|
|
1964 w->sb.below = height - w->sb.ss;
|
10
|
1965 }
|
0
|
1966 w->sb.below -= diff;
|
10
|
1967 CHECK (w);
|
|
1968 }
|
|
1969 else if (diff > 0)
|
|
1970 {
|
0
|
1971 /* down */
|
|
1972 w->sb.above += diff;
|
10
|
1973 if (w->sb.above + w->sb.ss > height)
|
|
1974 {
|
0
|
1975 mouse_y = height + (mouse_y - (w->sb.above + w->sb.ss));
|
|
1976 w->sb.above = height - w->sb.ss;
|
|
1977 diff = 0;
|
|
1978 w->sb.below = 0;
|
10
|
1979 }
|
0
|
1980 w->sb.below -= diff;
|
10
|
1981 CHECK (w);
|
|
1982 }
|
0
|
1983
|
10
|
1984 if (last_above != w->sb.above)
|
|
1985 {
|
|
1986 draw_knob (w, w->sb.above, w->sb.ss, w->sb.below);
|
0
|
1987
|
|
1988 w->sb.lastY = mouse_y;
|
|
1989
|
10
|
1990 w->sb.value = value_from_pixel (w, w->sb.above);
|
|
1991 verify_values (w);
|
|
1992 CHECK (w);
|
0
|
1993
|
10
|
1994 if (w->sb.value != last_value)
|
|
1995 call_callbacks (w, XmCR_DRAG, w->sb.value, event_y (w, event), event);
|
|
1996 }
|
|
1997 }
|
|
1998 CHECK (w);
|
0
|
1999 }
|
|
2000
|
10
|
2001 static void
|
|
2002 Release (Widget widget, XEvent *event, String *parms, Cardinal *num_parms)
|
0
|
2003 {
|
10
|
2004 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
0
|
2005
|
10
|
2006 DBUG (fprintf (stderr, "EndDrag:\n"));
|
0
|
2007
|
10
|
2008 switch (w->sb.armed)
|
|
2009 {
|
|
2010 case ARM_KNOB:
|
|
2011 call_callbacks (w, XmCR_VALUE_CHANGED, w->sb.value, event_y (w, event), event);
|
|
2012 w->sb.armed = ARM_NONE;
|
|
2013 draw_knob (w, w->sb.above, w->sb.ss, w->sb.below);
|
|
2014 break;
|
|
2015 case ARM_UP:
|
|
2016 redraw_up_arrow (w, False, False);
|
|
2017 break;
|
|
2018 case ARM_DOWN:
|
|
2019 redraw_down_arrow (w, False, False);
|
|
2020 break;
|
|
2021 }
|
0
|
2022
|
10
|
2023 XtUngrabKeyboard ((Widget) w, event->xbutton.time);
|
0
|
2024
|
|
2025 w->sb.armed = ARM_NONE;
|
|
2026 }
|
|
2027
|
10
|
2028 static void
|
|
2029 Jump (Widget widget, XEvent *event, String *parms, Cardinal *num_parms)
|
0
|
2030 {
|
10
|
2031 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
0
|
2032 int x, y, width, height, mouse_x, mouse_y;
|
|
2033 int arrow_height;
|
|
2034 int last_above, last_value;
|
|
2035
|
10
|
2036 DBUG (fprintf (stderr, "Jump:\n"));
|
0
|
2037
|
10
|
2038 x = widget_x (w);
|
|
2039 y = widget_y (w);
|
|
2040 width = widget_w (w);
|
|
2041 height = widget_h (w);
|
|
2042
|
|
2043 mouse_x = event_x (w, event);
|
|
2044 mouse_y = event_y (w, event);
|
0
|
2045
|
10
|
2046 arrow_height = w->sb.showArrows ? arrow_h (w) : 0;
|
0
|
2047
|
10
|
2048 XtGrabKeyboard ((Widget) w, False, GrabModeAsync, GrabModeAsync,
|
|
2049 event->xbutton.time);
|
0
|
2050
|
10
|
2051 switch (what_button (w, mouse_x, mouse_y))
|
|
2052 {
|
|
2053 case BUTTON_TROUGH_ABOVE:
|
|
2054 case BUTTON_TROUGH_BELOW:
|
|
2055 case BUTTON_KNOB:
|
|
2056 w->sb.savedValue = w->sb.value;
|
0
|
2057
|
10
|
2058 height -= (2*arrow_height);
|
|
2059 y += arrow_height;
|
0
|
2060
|
10
|
2061 last_above = w->sb.above;
|
|
2062 last_value = w->sb.value;
|
0
|
2063
|
10
|
2064 w->sb.armed = ARM_KNOB;
|
|
2065 draw_knob (w, w->sb.above, w->sb.ss, w->sb.below);
|
0
|
2066
|
10
|
2067 w->sb.above = mouse_y - (w->sb.ss / 2) - arrow_height;
|
|
2068 if (w->sb.above < 0)
|
|
2069 {
|
|
2070 w->sb.above = 0;
|
|
2071 }
|
|
2072 else if (w->sb.above + w->sb.ss > height)
|
|
2073 {
|
|
2074 w->sb.above = height - w->sb.ss;
|
|
2075 }
|
|
2076 w->sb.below = (height - (w->sb.ss + w->sb.above));
|
0
|
2077
|
10
|
2078 if (last_above != w->sb.above)
|
|
2079 {
|
|
2080 draw_knob (w, w->sb.above, w->sb.ss, w->sb.below);
|
0
|
2081
|
10
|
2082 w->sb.value = value_from_pixel (w, w->sb.above);
|
|
2083 verify_values (w);
|
|
2084 CHECK (w);
|
0
|
2085
|
10
|
2086 w->sb.lastY = mouse_y;
|
|
2087 w->sb.lastY = w->sb.above + arrow_height + (w->sb.ss / 2);
|
0
|
2088
|
10
|
2089 if (w->sb.value != last_value)
|
|
2090 {
|
|
2091 call_callbacks (w, XmCR_DRAG, w->sb.value, event_y (w, event), event);
|
|
2092 }
|
|
2093 }
|
|
2094 break;
|
|
2095 }
|
|
2096 CHECK (w);
|
0
|
2097 }
|
|
2098
|
10
|
2099 static void
|
|
2100 Abort (Widget widget, XEvent *event, String *parms, Cardinal *num_parms)
|
0
|
2101 {
|
10
|
2102 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
0
|
2103
|
10
|
2104 DBUG (fprintf (stderr, "Abort:\n"));
|
0
|
2105
|
10
|
2106 if (w->sb.armed != ARM_NONE)
|
|
2107 {
|
|
2108 if (w->sb.value != w->sb.savedValue)
|
|
2109 {
|
0
|
2110 w->sb.value = w->sb.savedValue;
|
|
2111
|
10
|
2112 seg_pixel_sizes (w, &w->sb.above, &w->sb.ss, &w->sb.below);
|
|
2113 draw_knob (w, w->sb.above, w->sb.ss, w->sb.below);
|
0
|
2114
|
10
|
2115 call_callbacks (w, XmCR_VALUE_CHANGED, w->sb.value,
|
|
2116 event_y (w, event), event);
|
|
2117 }
|
|
2118
|
|
2119 switch (w->sb.armed)
|
|
2120 {
|
|
2121 case ARM_UP: redraw_up_arrow (w, False, False); break;
|
|
2122 case ARM_DOWN: redraw_down_arrow (w, False, False); break;
|
|
2123 }
|
0
|
2124
|
|
2125 w->sb.armed = ARM_NONE;
|
|
2126
|
10
|
2127 XtUngrabKeyboard ((Widget) w, event->xbutton.time);
|
|
2128 }
|
0
|
2129 }
|