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