183
|
1 /* Implements a lightweight scrollbar widget.
|
0
|
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()
|
183
|
34 *
|
0
|
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 *),
|
183
|
195 offset(sb.knobStyle), XtRImmediate, NULL},
|
0
|
196
|
183
|
197 { XmNarrowPosition, XmCArrowPosition, XtRString, sizeof(char *),
|
|
198 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 {
|
183
|
311 printf("above=%d ss=%d below=%d height=%d\n",
|
0
|
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 {
|
183
|
476 return (w->sb.sliderStyle ? w->sb.sliderStyle[0] == 'd' :
|
|
477 w->sb.knobStyle ? w->sb.knobStyle[0] == 'd' :
|
|
478 0) ?
|
102
|
479 SLIDER_DIMPLE :
|
|
480 SLIDER_PLAIN;
|
76
|
481 }
|
|
482
|
|
483 static Boolean
|
|
484 arrow_same_end (XlwScrollBarWidget w)
|
|
485 {
|
|
486 return w->sb.arrowPosition && w->sb.arrowPosition[0] == 's' ? True : False;
|
10
|
487 }
|
|
488
|
102
|
489 /*-------------------------- GC and Pixel allocation --------------------*/
|
76
|
490 static GC
|
|
491 get_gc (XlwScrollBarWidget w, Pixel fg, Pixel bg, Pixmap pm)
|
0
|
492 {
|
|
493 XGCValues values;
|
|
494 XtGCMask mask;
|
|
495
|
76
|
496 if (pm == w->sb.grayPixmap)
|
|
497 {
|
0
|
498 /* If we're using the gray pixmap, guarantee white on black ...
|
|
499 * otherwise, we could end up with something odd like grey on white
|
|
500 * when we're on a color display that ran out of color cells
|
|
501 */
|
|
502
|
76
|
503 fg = WhitePixelOfScreen (DefaultScreenOfDisplay (XtDisplay (w)));
|
|
504 bg = BlackPixelOfScreen (DefaultScreenOfDisplay (XtDisplay (w)));
|
|
505 }
|
183
|
506
|
0
|
507 values.foreground = fg;
|
|
508 values.background = bg;
|
|
509 values.fill_style = FillOpaqueStippled;
|
|
510 values.stipple = pm;
|
102
|
511 mask = GCForeground | GCBackground |
|
|
512 (pm == None ? 0 : GCStipple | GCFillStyle);
|
76
|
513 return XtGetGC((Widget) w, mask, &values);
|
0
|
514 }
|
|
515
|
|
516 /* Replacement for XAllocColor() that tries to return the nearest
|
|
517 available color if the colormap is full. From FSF Emacs. */
|
|
518
|
|
519 static int
|
|
520 allocate_nearest_color (Display *display, Colormap screen_colormap,
|
|
521 XColor *color_def)
|
|
522 {
|
76
|
523 int status = XAllocColor (display, screen_colormap, color_def);
|
|
524 if (status)
|
|
525 return status;
|
0
|
526
|
|
527 {
|
|
528 /* If we got to this point, the colormap is full, so we're
|
76
|
529 going to try to get the next closest color.
|
0
|
530 The algorithm used is a least-squares matching, which is
|
|
531 what X uses for closest color matching with StaticColor visuals. */
|
|
532
|
76
|
533 int nearest, x;
|
80
|
534 unsigned long nearest_delta = ULONG_MAX;
|
0
|
535
|
76
|
536 int no_cells = XDisplayCells (display, XDefaultScreen (display));
|
0
|
537 /* Don't use alloca here because lwlib doesn't have the
|
|
538 necessary configuration information that src does. */
|
76
|
539 XColor *cells = (XColor *) malloc (sizeof (XColor) * no_cells);
|
0
|
540
|
|
541 for (x = 0; x < no_cells; x++)
|
|
542 cells[x].pixel = x;
|
|
543
|
|
544 XQueryColors (display, screen_colormap, cells, no_cells);
|
76
|
545
|
80
|
546 for (nearest = 0, x = 0; x < no_cells; x++)
|
0
|
547 {
|
76
|
548 long dred = (color_def->red >> 8) - (cells[x].red >> 8);
|
|
549 long dgreen = (color_def->green >> 8) - (cells[x].green >> 8);
|
|
550 long dblue = (color_def->blue >> 8) - (cells[x].blue >> 8);
|
80
|
551 unsigned long delta = dred * dred + dgreen * dgreen + dblue * dblue;
|
76
|
552
|
80
|
553 if (delta < nearest_delta)
|
0
|
554 {
|
|
555 nearest = x;
|
80
|
556 nearest_delta = delta;
|
0
|
557 }
|
|
558 }
|
76
|
559 color_def->red = cells[nearest].red;
|
0
|
560 color_def->green = cells[nearest].green;
|
76
|
561 color_def->blue = cells[nearest].blue;
|
0
|
562 free (cells);
|
76
|
563 return XAllocColor (display, screen_colormap, color_def);
|
0
|
564 }
|
|
565 }
|
|
566
|
76
|
567 static void
|
|
568 make_shadow_pixels (XlwScrollBarWidget w)
|
0
|
569 {
|
|
570 Display *dpy = XtDisplay((Widget) w);
|
|
571 Colormap cmap = w->core.colormap;
|
|
572 XColor topc, botc;
|
|
573 int top_frobbed, bottom_frobbed;
|
|
574 Pixel bg, fg;
|
|
575
|
|
576 top_frobbed = bottom_frobbed = 0;
|
|
577
|
|
578 bg = w->core.background_pixel;
|
|
579 fg = w->sb.foreground;
|
|
580
|
76
|
581 if (w->sb.topShadowColor == (Pixel)~0) w->sb.topShadowColor = bg;
|
|
582 if (w->sb.bottomShadowColor == (Pixel)~0) w->sb.bottomShadowColor = fg;
|
0
|
583
|
76
|
584 if (w->sb.topShadowColor == bg || w->sb.topShadowColor == fg)
|
|
585 {
|
0
|
586 topc.pixel = bg;
|
76
|
587 XQueryColor (dpy, cmap, &topc);
|
0
|
588 /* don't overflow/wrap! */
|
|
589 topc.red = MINL(65535, topc.red * 1.2);
|
|
590 topc.green = MINL(65535, topc.green * 1.2);
|
|
591 topc.blue = MINL(65535, topc.blue * 1.2);
|
76
|
592 if (allocate_nearest_color (dpy, cmap, &topc))
|
|
593 {
|
|
594 if (topc.pixel == bg)
|
|
595 {
|
|
596 XFreeColors (dpy, cmap, &topc.pixel, 1, 0);
|
0
|
597 topc.red = MINL(65535, topc.red + 0x8000);
|
|
598 topc.green = MINL(65535, topc.green + 0x8000);
|
|
599 topc.blue = MINL(65535, topc.blue + 0x8000);
|
76
|
600 if (allocate_nearest_color (dpy, cmap, &topc))
|
|
601 {
|
0
|
602 w->sb.topShadowColor = topc.pixel;
|
76
|
603 }
|
|
604 }
|
0
|
605 else
|
76
|
606 {
|
0
|
607 w->sb.topShadowColor = topc.pixel;
|
76
|
608 }
|
0
|
609
|
|
610 top_frobbed = 1;
|
76
|
611 }
|
|
612 }
|
0
|
613
|
76
|
614 if (w->sb.bottomShadowColor == fg || w->sb.bottomShadowColor == bg)
|
|
615 {
|
0
|
616 botc.pixel = bg;
|
76
|
617 XQueryColor (dpy, cmap, &botc);
|
0
|
618 botc.red *= 0.6;
|
|
619 botc.green *= 0.6;
|
|
620 botc.blue *= 0.6;
|
76
|
621 if (allocate_nearest_color (dpy, cmap, &botc))
|
|
622 {
|
|
623 if (botc.pixel == bg)
|
|
624 {
|
|
625 XFreeColors (dpy, cmap, &botc.pixel, 1, 0);
|
0
|
626 botc.red = MINL(65535, botc.red + 0x4000);
|
|
627 botc.green = MINL(65535, botc.green + 0x4000);
|
|
628 botc.blue = MINL(65535, botc.blue + 0x4000);
|
76
|
629 if (allocate_nearest_color (dpy, cmap, &botc))
|
|
630 {
|
0
|
631 w->sb.bottomShadowColor = botc.pixel;
|
76
|
632 }
|
|
633 }
|
0
|
634 else
|
76
|
635 {
|
0
|
636 w->sb.bottomShadowColor = botc.pixel;
|
76
|
637 }
|
0
|
638 bottom_frobbed = 1;
|
76
|
639 }
|
|
640 }
|
0
|
641
|
76
|
642 if (top_frobbed && bottom_frobbed)
|
|
643 {
|
0
|
644 int top_avg = ((topc.red / 3) + (topc.green / 3) + (topc.blue / 3));
|
|
645 int bot_avg = ((botc.red / 3) + (botc.green / 3) + (botc.blue / 3));
|
76
|
646 if (bot_avg > top_avg)
|
|
647 {
|
0
|
648 Pixel tmp = w->sb.topShadowColor;
|
|
649 w->sb.topShadowColor = w->sb.bottomShadowColor;
|
|
650 w->sb.bottomShadowColor = tmp;
|
76
|
651 }
|
|
652 else if (topc.pixel == botc.pixel)
|
|
653 {
|
|
654 if (botc.pixel == bg)
|
|
655 w->sb.topShadowColor = bg;
|
0
|
656 else
|
76
|
657 w->sb.bottomShadowColor = fg;
|
|
658 }
|
|
659 }
|
0
|
660
|
183
|
661 if (w->sb.topShadowColor == w->core.background_pixel ||
|
76
|
662 w->sb.bottomShadowColor == w->core.background_pixel)
|
|
663 {
|
0
|
664 /* Assume we're in mono. This code should be okay even if we're
|
183
|
665 * really in color but just short on color cells -- We want the
|
0
|
666 * following behavior, which has been empirically determined to
|
|
667 * work well for all fg/bg combinations in mono: If the trough
|
102
|
668 * and slider are BOTH black, then use a white top shadow and a
|
0
|
669 * grey bottom shadow, otherwise use a grey top shadow and a
|
|
670 * black bottom shadow.
|
|
671 */
|
|
672
|
76
|
673 Pixel white = WhitePixelOfScreen (DefaultScreenOfDisplay (XtDisplay (w)));
|
|
674 Pixel black = BlackPixelOfScreen (DefaultScreenOfDisplay (XtDisplay (w)));
|
0
|
675
|
102
|
676 /* Note: core.background_pixel is the color of the slider ... */
|
0
|
677
|
|
678 if (w->core.background_pixel == black &&
|
76
|
679 w->sb.troughColor == black)
|
|
680 {
|
|
681 w->sb.topShadowColor = white;
|
|
682 w->sb.bottomShadowPixmap = w->sb.grayPixmap;
|
|
683 } else {
|
|
684 w->sb.topShadowPixmap = w->sb.grayPixmap;
|
|
685 w->sb.bottomShadowColor = black;
|
|
686 }
|
|
687 }
|
0
|
688 }
|
|
689
|
76
|
690 static void
|
|
691 make_trough_pixel (XlwScrollBarWidget w)
|
0
|
692 {
|
|
693 Display *dpy = XtDisplay((Widget) w);
|
76
|
694 Colormap cmap = DefaultColormapOfScreen (XtScreen ((Widget) w));
|
0
|
695 XColor troughC;
|
|
696
|
76
|
697 if (w->sb.troughColor == (Pixel)~0) w->sb.troughColor = w->core.background_pixel;
|
0
|
698
|
76
|
699 if (w->sb.troughColor == w->core.background_pixel)
|
|
700 {
|
0
|
701 troughC.pixel = w->core.background_pixel;
|
76
|
702 XQueryColor (dpy, cmap, &troughC);
|
0
|
703 troughC.red *= 0.8;
|
|
704 troughC.green *= 0.8;
|
|
705 troughC.blue *= 0.8;
|
76
|
706 if (allocate_nearest_color (dpy, cmap, &troughC))
|
|
707 w->sb.troughColor = troughC.pixel;
|
|
708 }
|
0
|
709 }
|
|
710
|
102
|
711 /*-------------------------- Draw 3D Border -----------------------------*/
|
76
|
712 static void
|
|
713 draw_shadows (Display *dpy, Drawable d, GC shine_gc, GC shadow_gc,
|
|
714 int x, int y, int width, int height, int shadowT)
|
0
|
715 {
|
76
|
716 XSegment shine[10], shadow[10];
|
|
717 int i;
|
0
|
718
|
76
|
719 if (shadowT > (width / 2)) shadowT = (width / 2);
|
|
720 if (shadowT > (height / 2)) shadowT = (height / 2);
|
|
721 if (shadowT <= 0) return;
|
0
|
722
|
76
|
723 for (i = 0; i < shadowT; i++)
|
|
724 {
|
|
725 /* Top segments */
|
|
726 shine[i].x1 = x;
|
|
727 shine[i].y2 = shine[i].y1 = y + i;
|
|
728 shine[i].x2 = x + width - i - 1;
|
|
729 /* Left segments */
|
|
730 shine[i + shadowT].x2 = shine[i + shadowT].x1 = x + i;
|
|
731 shine[i + shadowT].y1 = y + shadowT;
|
|
732 shine[i + shadowT].y2 = y + height - i - 1;
|
0
|
733
|
76
|
734 /* Bottom segments */
|
|
735 shadow[i].x1 = x + i;
|
|
736 shadow[i].y2 = shadow[i].y1 = y + height - i - 1;
|
|
737 shadow[i].x2 = x + width - 1 ;
|
|
738 /* Right segments */
|
|
739 shadow[i + shadowT].x2 = shadow[i + shadowT].x1 = x + width - i - 1;
|
|
740 shadow[i + shadowT].y1 = y + i + 1;
|
|
741 shadow[i + shadowT].y2 = y + height - 1 ;
|
|
742 }
|
0
|
743
|
76
|
744 XDrawSegments (dpy, d, shine_gc, shine, shadowT * 2);
|
|
745 XDrawSegments (dpy, d, shadow_gc, shadow, shadowT * 2);
|
0
|
746 }
|
|
747
|
102
|
748 /*------------------ Draw 3D Arrows: left, up, down, right --------------*/
|
76
|
749 static int
|
|
750 make_vert_seg (XSegment *seg, int x1, int y1, int x2, int y2, int shadowT)
|
0
|
751 {
|
|
752 int i;
|
|
753
|
102
|
754 for (i=0; i<shadowT; i++, seg++)
|
76
|
755 {
|
102
|
756 seg->x1 = x1;
|
|
757 seg->y1 = y1++;
|
|
758 seg->x2 = x2;
|
|
759 seg->y2 = y2++;
|
76
|
760 }
|
|
761 return shadowT;
|
0
|
762 }
|
|
763
|
76
|
764 static int
|
|
765 make_hor_seg (XSegment *seg, int x1, int y1, int x2, int y2, int shadowT)
|
0
|
766 {
|
|
767 int i;
|
|
768
|
102
|
769 for (i=0; i<shadowT; i++, seg++)
|
76
|
770 {
|
102
|
771 seg->x1 = x1++;
|
|
772 seg->y1 = y1;
|
|
773 seg->x2 = x2++;
|
|
774 seg->y2 = y2;
|
76
|
775 }
|
|
776 return shadowT;
|
0
|
777 }
|
|
778
|
76
|
779 static void
|
|
780 draw_arrow_up (Display *dpy, Drawable win, GC bgGC, GC shineGC, GC shadowGC,
|
|
781 int x, int y, int width, int height, int shadowT)
|
0
|
782 {
|
|
783 XSegment shine[10], shadow[10];
|
|
784 XPoint triangle[3];
|
|
785 int mid;
|
|
786
|
|
787 mid = width / 2;
|
|
788
|
76
|
789 if (shadowT > (width / 2)) shadowT = (width / 2);
|
|
790 if (shadowT > (height / 2)) shadowT = (height / 2);
|
102
|
791 if (shadowT < 0) shadowT = 0;
|
0
|
792
|
|
793 /* / */
|
76
|
794 make_vert_seg (shine,
|
102
|
795 x, y + height - shadowT - 1,
|
76
|
796 x + mid, y, shadowT);
|
0
|
797 /* _\ */
|
76
|
798 make_vert_seg (shadow,
|
102
|
799 x, y + height - shadowT - 1,
|
76
|
800 x + width - 1, y + height - shadowT - 1, shadowT);
|
|
801 make_vert_seg (shadow + shadowT,
|
102
|
802 x + mid, y,
|
76
|
803 x + width - 1, y + height - shadowT - 1, shadowT);
|
0
|
804
|
|
805 triangle[0].x = x;
|
|
806 triangle[0].y = y + height - 1;
|
|
807 triangle[1].x = x + mid;
|
|
808 triangle[1].y = y;
|
|
809 triangle[2].x = x + width - 1;
|
|
810 triangle[2].y = y + height - 1;
|
|
811
|
76
|
812 XFillPolygon (dpy, win, bgGC, triangle, 3, Convex, ArcChord);
|
0
|
813
|
76
|
814 XDrawSegments (dpy, win, shadowGC, shadow, shadowT * 2);
|
|
815 XDrawSegments (dpy, win, shineGC, shine, shadowT);
|
0
|
816 }
|
|
817
|
76
|
818 static void
|
|
819 draw_arrow_left (Display *dpy, Drawable win, GC bgGC, GC shineGC, GC shadowGC,
|
|
820 int x, int y, int width, int height, int shadowT)
|
0
|
821 {
|
|
822 XSegment shine[10], shadow[10];
|
|
823 XPoint triangle[3];
|
|
824
|
102
|
825 int mid = width / 2;
|
0
|
826
|
76
|
827 if (shadowT > (width / 2)) shadowT = (width / 2);
|
|
828 if (shadowT > (height / 2)) shadowT = (height / 2);
|
102
|
829 if (shadowT < 0) shadowT = 0;
|
0
|
830
|
|
831 /* / */
|
76
|
832 make_hor_seg (shine,
|
102
|
833 x, y + mid,
|
76
|
834 x + width - shadowT - 1, y, shadowT);
|
0
|
835 /* \| */
|
76
|
836 make_hor_seg (shadow,
|
102
|
837 x, y + mid,
|
76
|
838 x + width - shadowT - 1, y + height - 1, shadowT);
|
|
839 make_hor_seg (shadow + shadowT,
|
|
840 x + width - shadowT - 1, y,
|
|
841 x + width - shadowT - 1, y + height - 1, shadowT);
|
0
|
842
|
|
843 triangle[0].x = x + width - 1;
|
|
844 triangle[0].y = y + height - 1;
|
|
845 triangle[1].x = x;
|
|
846 triangle[1].y = y + mid;
|
|
847 triangle[2].x = x + width - 1;
|
|
848 triangle[2].y = y;
|
|
849
|
76
|
850 XFillPolygon (dpy, win, bgGC, triangle, 3, Convex, ArcChord);
|
0
|
851
|
76
|
852 XDrawSegments (dpy, win, shadowGC, shadow, shadowT * 2);
|
|
853 XDrawSegments (dpy, win, shineGC, shine, shadowT);
|
0
|
854 }
|
|
855
|
76
|
856 static void
|
|
857 draw_arrow_down (Display *dpy, Drawable win, GC bgGC, GC shineGC, GC shadowGC,
|
|
858 int x, int y, int width, int height, int shadowT)
|
0
|
859 {
|
|
860 XSegment shine[10], shadow[10];
|
|
861 XPoint triangle[3];
|
|
862 int mid;
|
|
863
|
|
864 mid = width / 2;
|
|
865
|
76
|
866 if (shadowT > (width / 2)) shadowT = (width / 2);
|
|
867 if (shadowT > (height / 2)) shadowT = (height / 2);
|
102
|
868 if (shadowT < 0) shadowT = 0;
|
183
|
869
|
0
|
870 /* \- */
|
76
|
871 make_vert_seg (shine,
|
102
|
872 x, y,
|
76
|
873 x + mid, y + height - shadowT - 1, shadowT);
|
|
874 make_vert_seg (shine + shadowT,
|
102
|
875 x, y,
|
76
|
876 x + width - 1, y, shadowT);
|
0
|
877 /* / */
|
76
|
878 make_vert_seg (shadow,
|
0
|
879 x + width - 1, y,
|
102
|
880 x + mid, y + height - shadowT - 1, shadowT);
|
0
|
881
|
|
882 triangle[0].x = x;
|
|
883 triangle[0].y = y;
|
|
884 triangle[1].x = x + mid;
|
|
885 triangle[1].y = y + height - 1;
|
|
886 triangle[2].x = x + width - 1;
|
|
887 triangle[2].y = y;
|
|
888
|
76
|
889 XFillPolygon (dpy, win, bgGC, triangle, 3, Convex, ArcChord);
|
0
|
890
|
76
|
891 XDrawSegments (dpy, win, shadowGC, shadow, shadowT);
|
|
892 XDrawSegments (dpy, win, shineGC, shine, shadowT * 2);
|
0
|
893 }
|
|
894
|
76
|
895 static void
|
|
896 draw_arrow_right (Display *dpy, Drawable win, GC bgGC, GC shineGC, GC shadowGC,
|
|
897 int x, int y, int width, int height, int shadowT)
|
0
|
898 {
|
|
899 XSegment shine[10], shadow[10];
|
|
900 XPoint triangle[3];
|
|
901 int mid;
|
|
902
|
|
903 mid = width / 2;
|
|
904
|
76
|
905 if (shadowT > (width / 2)) shadowT = (width / 2);
|
|
906 if (shadowT > (height / 2)) shadowT = (height / 2);
|
102
|
907 if (shadowT < 0) shadowT = 0;
|
183
|
908
|
0
|
909 /* |\ */
|
76
|
910 make_hor_seg (shine,
|
102
|
911 x, y,
|
76
|
912 x + width - shadowT - 1, y + mid, shadowT);
|
|
913 make_hor_seg (shine + shadowT,
|
0
|
914 x, y,
|
102
|
915 x, y + height - 1, shadowT);
|
0
|
916 /* / */
|
76
|
917 make_hor_seg (shadow,
|
102
|
918 x, y + height - 1,
|
76
|
919 x + width - shadowT - 1, y + mid, shadowT);
|
0
|
920
|
|
921 triangle[0].x = x + 1;
|
|
922 triangle[0].y = y + height - 1;
|
102
|
923 triangle[1].x = x + width - 1;
|
0
|
924 triangle[1].y = y + mid;
|
|
925 triangle[2].x = x + 1;
|
|
926 triangle[2].y = y;
|
|
927
|
76
|
928 XFillPolygon (dpy, win, bgGC, triangle, 3, Convex, ArcChord);
|
0
|
929
|
76
|
930 XDrawSegments (dpy, win, shadowGC, shadow, shadowT);
|
|
931 XDrawSegments (dpy, win, shineGC, shine, shadowT * 2);
|
0
|
932 }
|
|
933
|
76
|
934 static void
|
|
935 draw_dimple (Display *dpy, Drawable win, GC shine, GC shadow,
|
|
936 int x, int y, int width, int height)
|
0
|
937 {
|
76
|
938 XDrawArc (dpy, win, shine, x, y, width, height, 46*64, 180*64);
|
|
939 XDrawArc (dpy, win, shadow, x, y, width, height, 45*64, -179*64);
|
0
|
940 }
|
|
941
|
102
|
942 /*------- Scrollbar values -> pixels, pixels -> scrollbar values --------*/
|
0
|
943
|
76
|
944 static void
|
|
945 seg_pixel_sizes (XlwScrollBarWidget w, int *above_return,
|
|
946 int *ss_return, int *below_return)
|
0
|
947 {
|
|
948 float total, height, fuz;
|
|
949 int value;
|
|
950 int above, ss, below;
|
|
951
|
76
|
952 height= widget_h (w);
|
|
953 if (w->sb.showArrows) height -= (2 * arrow_h (w));
|
0
|
954
|
|
955 value = w->sb.value - w->sb.minimum;
|
|
956
|
|
957 total = w->sb.maximum - w->sb.minimum;
|
|
958 fuz = total / 2;
|
|
959
|
|
960 ss = ((height * w->sb.sliderSize + fuz) / total);
|
|
961 above = ((height * value + fuz) / total);
|
|
962 below = ((height) - (ss + above));
|
|
963
|
102
|
964 /* Don't let slider get smaller than SS_MIN */
|
76
|
965 if (ss < SS_MIN)
|
|
966 {
|
|
967 /* add a percent amount for integer rounding */
|
|
968 float tmp = ((((float) (SS_MIN - ss) * (float) value)) / total) + 0.5;
|
0
|
969
|
76
|
970 above -= (int) tmp;
|
102
|
971 ss = SS_MIN;
|
0
|
972 below = ((height) - (ss + above));
|
|
973
|
76
|
974 if (above < 0)
|
|
975 {
|
0
|
976 above = 0;
|
|
977 below = height - ss;
|
76
|
978 }
|
|
979 if (below < 0)
|
|
980 {
|
0
|
981 above = height - ss;
|
|
982 below = 0;
|
76
|
983 }
|
|
984 if (ss > height)
|
|
985 {
|
0
|
986 above = 0;
|
|
987 ss = height;
|
|
988 below = 0;
|
76
|
989 }
|
|
990 }
|
0
|
991
|
|
992 *above_return = above;
|
|
993 *ss_return = ss;
|
|
994 *below_return = below;
|
|
995
|
76
|
996 CHECK (w);
|
0
|
997 }
|
|
998
|
76
|
999 static void
|
|
1000 verify_values (XlwScrollBarWidget w)
|
0
|
1001 {
|
|
1002 int total = w->sb.maximum - w->sb.minimum;
|
|
1003
|
76
|
1004 if (w->sb.sliderSize > total)
|
0
|
1005 w->sb.sliderSize = total;
|
76
|
1006
|
|
1007 if (w->sb.pageIncrement > total)
|
0
|
1008 w->sb.pageIncrement = total;
|
76
|
1009
|
|
1010 if (w->sb.increment > total)
|
0
|
1011 w->sb.increment = total;
|
76
|
1012
|
|
1013 if (w->sb.value < w->sb.minimum)
|
0
|
1014 w->sb.value = w->sb.minimum;
|
76
|
1015
|
102
|
1016 if (w->sb.value > w->sb.maximum)
|
|
1017 w->sb.value = w->sb.maximum;
|
|
1018
|
|
1019 if (w->sb.sliderSize > w->sb.maximum - w->sb.value)
|
|
1020 w->sb.sliderSize = w->sb.maximum - w->sb.value;
|
0
|
1021 }
|
|
1022
|
76
|
1023 static int
|
|
1024 value_from_pixel (XlwScrollBarWidget w, int above)
|
0
|
1025 {
|
|
1026 float total, height, fuz;
|
|
1027 int value, ss;
|
|
1028
|
102
|
1029 height = widget_h (w);
|
|
1030 if (w->sb.showArrows)
|
|
1031 height -= (2 * arrow_h (w));
|
0
|
1032
|
|
1033 total = w->sb.maximum - w->sb.minimum;
|
76
|
1034 fuz = height / 2;
|
0
|
1035
|
76
|
1036 ss = ((height * w->sb.sliderSize + (total / 2)) / total);
|
0
|
1037
|
76
|
1038 if (ss < SS_MIN)
|
|
1039 {
|
|
1040 /* add a percent amount for integer rounding */
|
0
|
1041 above += ((((SS_MIN - ss) * above) + fuz) / height);
|
76
|
1042 }
|
0
|
1043
|
|
1044 {
|
76
|
1045 /* Prevent SIGFPE's that would occur if we don't truncate the value. */
|
|
1046 float floatval = w->sb.minimum + ((float)(above * total + fuz) / height);
|
0
|
1047 if (floatval >= (float) INT_MAX)
|
|
1048 value = INT_MAX;
|
|
1049 else if (floatval <= (float) INT_MIN)
|
|
1050 value = INT_MIN;
|
|
1051 else
|
|
1052 value = floatval;
|
|
1053 }
|
|
1054
|
76
|
1055 return value;
|
0
|
1056 }
|
|
1057
|
|
1058
|
76
|
1059 static void
|
|
1060 redraw_dimple (XlwScrollBarWidget w, Display *dpy, Window win,
|
|
1061 int x, int y, int width, int height)
|
0
|
1062 {
|
102
|
1063 if (SLIDER_DIMPLE == slider_style (w))
|
76
|
1064 {
|
102
|
1065 int size;
|
|
1066 int slider_p = (w->sb.armed == ARM_SLIDER);
|
|
1067 GC shine = slider_p ? w->sb.bottomShadowGC : w->sb.topShadowGC;
|
|
1068 GC shadow = slider_p ? w->sb.topShadowGC : w->sb.bottomShadowGC;
|
|
1069 int shadowT = w->sb.shadowThickness;
|
0
|
1070
|
|
1071 x += shadowT;
|
|
1072 y += shadowT;
|
|
1073 width -= 2*shadowT;
|
|
1074 height -= 2*shadowT;
|
|
1075
|
|
1076 size = (width < height ? width : height) * 3 / 4;
|
|
1077
|
76
|
1078 if (size%2 != (width < height ? width : height)%2) size--;
|
0
|
1079
|
76
|
1080 DBUG (fprintf (stderr, "%d %d\n",
|
|
1081 x + (width / 2) - (size / 2) - 2*shadowT,
|
|
1082 width - size - shadowT));
|
0
|
1083
|
76
|
1084 draw_dimple (dpy, win, shine, shadow,
|
|
1085 x + (width / 2) - (size / 2),
|
0
|
1086 y + (height / 2) - (size / 2),
|
76
|
1087 size, size);
|
|
1088 }
|
0
|
1089 }
|
|
1090
|
76
|
1091 static void
|
102
|
1092 draw_slider (XlwScrollBarWidget w, int above, int ss, int below)
|
0
|
1093 {
|
76
|
1094 Display *dpy = XtDisplay ((Widget) w);
|
|
1095 Window win = XtWindow ((Widget) w);
|
0
|
1096
|
102
|
1097 int x = widget_x (w);
|
|
1098 int y = widget_y (w);
|
|
1099 int width = widget_w (w);
|
|
1100 int height = widget_h (w);
|
|
1101 int shadowT = w->sb.shadowThickness;
|
|
1102 int vert_p = VERT (w);
|
0
|
1103
|
76
|
1104 if (shadowT > (width / 2)) shadowT = (width / 2);
|
|
1105 if (shadowT > (height / 2)) shadowT = (height / 2);
|
102
|
1106 if (shadowT < 0) shadowT = 0;
|
0
|
1107
|
102
|
1108 if (w->sb.showArrows && !arrow_same_end (w))
|
|
1109 y += arrow_h (w);
|
0
|
1110
|
102
|
1111 /* trough above slider */
|
76
|
1112 if (above > 0)
|
|
1113 {
|
102
|
1114 if (vert_p)
|
76
|
1115 XClearArea (dpy, win, x, y, width, above, False);
|
0
|
1116 else
|
76
|
1117 XClearArea (dpy, win, y, x, above, width, False);
|
|
1118 }
|
0
|
1119
|
102
|
1120 /* slider */
|
|
1121 if (vert_p)
|
76
|
1122 {
|
|
1123 draw_shadows (dpy, win, w->sb.topShadowGC, w->sb.bottomShadowGC,
|
0
|
1124 x, y + above, width, ss, shadowT);
|
102
|
1125 XFillRectangle (dpy, win, w->sb.backgroundGC,
|
|
1126 x+shadowT, y + above + shadowT,
|
|
1127 width-2*shadowT, ss-2*shadowT);
|
76
|
1128 redraw_dimple (w, dpy, win, x, y + above, width, ss);
|
|
1129 }
|
0
|
1130 else
|
76
|
1131 {
|
|
1132 draw_shadows (dpy, win, w->sb.topShadowGC, w->sb.bottomShadowGC,
|
0
|
1133 y + above, x, ss, width, shadowT);
|
102
|
1134 XFillRectangle (dpy, win, w->sb.backgroundGC,
|
|
1135 y + above + shadowT, x+shadowT,
|
|
1136 ss-2*shadowT, width-2*shadowT);
|
76
|
1137 redraw_dimple (w, dpy, win, y + above, x, ss, width);
|
|
1138 }
|
0
|
1139
|
102
|
1140 /* trough below slider */
|
76
|
1141 if (below > 0)
|
|
1142 {
|
102
|
1143 if (vert_p)
|
76
|
1144 XClearArea (dpy, win, x, y + above + ss, width, below, False);
|
0
|
1145 else
|
76
|
1146 XClearArea (dpy, win, y + above + ss, x, below, width, False);
|
|
1147 }
|
0
|
1148
|
76
|
1149 CHECK (w);
|
0
|
1150 }
|
|
1151
|
76
|
1152 static void
|
|
1153 redraw_up_arrow (XlwScrollBarWidget w, Boolean armed, Boolean clear_behind)
|
0
|
1154 {
|
76
|
1155 Display *dpy = XtDisplay ((Widget) w);
|
|
1156 Window win = XtWindow ((Widget) w);
|
0
|
1157
|
102
|
1158 int x = widget_x (w);
|
|
1159 int y = widget_y (w);
|
|
1160 int width = widget_w (w);
|
|
1161 int height = widget_h (w);
|
|
1162 int shadowT = w->sb.shadowThickness;
|
|
1163 int arrow_height = arrow_h (w);
|
0
|
1164
|
102
|
1165 GC bg = w->sb.backgroundGC;
|
|
1166 GC shine = armed ? w->sb.bottomShadowGC : w->sb.topShadowGC;
|
|
1167 GC shadow = armed ? w->sb.topShadowGC : w->sb.bottomShadowGC;
|
70
|
1168
|
76
|
1169 if (VERT (w))
|
|
1170 {
|
|
1171 if (arrow_same_end (w))
|
102
|
1172 y += height - 2 * arrow_height;
|
76
|
1173 if (clear_behind)
|
|
1174 XClearArea (dpy, win, x, y, width, arrow_height + 1, False);
|
|
1175 draw_arrow_up (dpy, win, bg, shine, shadow,
|
0
|
1176 x + (width - arrow_height)/2, y,
|
76
|
1177 arrow_height, arrow_height, shadowT);
|
|
1178 }
|
0
|
1179 else
|
76
|
1180 {
|
|
1181 if (arrow_same_end (w))
|
102
|
1182 y += height - 2 * arrow_height;
|
76
|
1183 if (clear_behind)
|
|
1184 XClearArea (dpy, win, y, x, arrow_height + 1, height, False);
|
|
1185 draw_arrow_left (dpy, win, bg, shine, shadow,
|
0
|
1186 y, x + (width - arrow_height)/2,
|
76
|
1187 arrow_height, arrow_height, shadowT);
|
|
1188 }
|
0
|
1189 }
|
|
1190
|
76
|
1191 static void
|
|
1192 redraw_down_arrow (XlwScrollBarWidget w, Boolean armed, Boolean clear_behind)
|
0
|
1193 {
|
76
|
1194 Display *dpy = XtDisplay ((Widget) w);
|
|
1195 Window win = XtWindow ((Widget) w);
|
0
|
1196
|
102
|
1197 int x = widget_x (w);
|
|
1198 int y = widget_y (w);
|
|
1199 int width = widget_w (w);
|
|
1200 int height = widget_h (w);
|
|
1201 int shadowT = w->sb.shadowThickness;
|
|
1202 int arrow_height = arrow_h (w);
|
0
|
1203
|
102
|
1204 GC bg = w->sb.backgroundGC;
|
|
1205 GC shine = armed ? w->sb.bottomShadowGC : w->sb.topShadowGC;
|
|
1206 GC shadow = armed ? w->sb.topShadowGC : w->sb.bottomShadowGC;
|
70
|
1207
|
76
|
1208 if (VERT (w))
|
|
1209 {
|
|
1210 if (clear_behind)
|
|
1211 XClearArea (dpy, win, x, y + height - arrow_height, width,
|
|
1212 arrow_height + 1, False);
|
|
1213 draw_arrow_down (dpy, win, bg, shine, shadow,
|
|
1214 x + (width - arrow_height)/2,
|
|
1215 y + height - arrow_height + 1,
|
|
1216 arrow_height, arrow_height, shadowT);
|
|
1217 }
|
70
|
1218 else
|
76
|
1219 {
|
|
1220 if (clear_behind)
|
|
1221 XClearArea (dpy, win, y + height - arrow_height, x,
|
|
1222 arrow_height + 1, height, False);
|
|
1223 draw_arrow_right (dpy, win, bg, shine, shadow,
|
|
1224 y + height - arrow_height + 1,
|
|
1225 x + (width - arrow_height)/2,
|
|
1226 arrow_height, arrow_height, shadowT);
|
|
1227 }
|
0
|
1228 }
|
|
1229
|
76
|
1230 static void
|
|
1231 redraw_everything (XlwScrollBarWidget w, Region region, Boolean behind_arrows)
|
0
|
1232 {
|
76
|
1233 Display *dpy = XtDisplay ((Widget) w);
|
|
1234 Window win = XtWindow ((Widget) w);
|
26
|
1235
|
76
|
1236 if (w->sb.showArrows)
|
|
1237 {
|
102
|
1238 if (region == NULL)
|
76
|
1239 {
|
102
|
1240 redraw_up_arrow (w, False, behind_arrows);
|
|
1241 redraw_down_arrow (w, False, behind_arrows);
|
76
|
1242 }
|
70
|
1243 else
|
76
|
1244 {
|
102
|
1245 int x = widget_x (w);
|
|
1246 int y = widget_y (w);
|
|
1247 int width = widget_w (w);
|
|
1248 int height = widget_h (w);
|
|
1249 int arrow_height = arrow_h (w);
|
|
1250 int ax = x, ay = y;
|
|
1251
|
|
1252 if (arrow_same_end (w))
|
|
1253 {
|
|
1254 if (VERT (w))
|
|
1255 ay = y + height - arrow_height - arrow_height;
|
|
1256 else
|
|
1257 ax = x + height - arrow_height - arrow_height;
|
|
1258 }
|
|
1259 if (XRectInRegion (region, ax, ay, width, width))
|
|
1260 redraw_up_arrow (w, False, behind_arrows);
|
|
1261
|
|
1262 if (VERT (w))
|
|
1263 ay = y + height - arrow_height;
|
|
1264 else
|
|
1265 ax = x + height - arrow_height;
|
|
1266 if (XRectInRegion (region, ax, ay, width, width))
|
|
1267 redraw_down_arrow (w, False, behind_arrows);
|
76
|
1268 }
|
|
1269 }
|
26
|
1270
|
102
|
1271 draw_shadows (dpy, win, w->sb.bottomShadowGC, w->sb.topShadowGC, 0, 0,
|
|
1272 w->core.width, w->core.height, w->sb.shadowThickness);
|
0
|
1273
|
102
|
1274 draw_slider (w, w->sb.above, w->sb.ss, w->sb.below);
|
0
|
1275 }
|
|
1276
|
102
|
1277 /*-------------------------- Method Functions ---------------------------*/
|
0
|
1278
|
76
|
1279 static void
|
|
1280 Initialize (Widget treq, Widget tnew, ArgList args, Cardinal *num_args)
|
0
|
1281 {
|
|
1282 XlwScrollBarWidget request = (XlwScrollBarWidget) treq;
|
|
1283 XlwScrollBarWidget w = (XlwScrollBarWidget) tnew;
|
76
|
1284 Display *dpy = XtDisplay ((Widget) w);
|
|
1285 Window win = RootWindowOfScreen (DefaultScreenOfDisplay (dpy));
|
70
|
1286
|
76
|
1287 if (request->core.width == 0) w->core.width += (VERT (w) ? 12 : 25);
|
|
1288 if (request->core.height == 0) w->core.height += (VERT (w) ? 25 : 12);
|
0
|
1289
|
76
|
1290 verify_values (w);
|
0
|
1291
|
|
1292 w->sb.lastY = 0;
|
|
1293 w->sb.above = 0;
|
|
1294 w->sb.ss = 0;
|
|
1295 w->sb.below = 0;
|
|
1296 w->sb.armed = ARM_NONE;
|
102
|
1297 w->sb.forced_scroll = FORCED_SCROLL_NONE;
|
0
|
1298
|
76
|
1299 if (w->sb.shadowThickness > 5) w->sb.shadowThickness = 5;
|
0
|
1300
|
|
1301 w->sb.grayPixmap =
|
76
|
1302 XCreatePixmapFromBitmapData (dpy, win, (char *) gray_bits, gray_width,
|
|
1303 gray_height, 1, 0, 1);
|
0
|
1304
|
76
|
1305 make_trough_pixel (w);
|
|
1306
|
|
1307 make_shadow_pixels (w);
|
0
|
1308
|
76
|
1309 w->sb.backgroundGC =
|
|
1310 get_gc (w, w->core.background_pixel, w->core.background_pixel, None);
|
|
1311 w->sb.topShadowGC =
|
|
1312 get_gc (w, w->sb.topShadowColor, w->core.background_pixel,
|
|
1313 w->sb.topShadowPixmap);
|
|
1314 w->sb.bottomShadowGC =
|
|
1315 get_gc (w, w->sb.bottomShadowColor, w->core.background_pixel,
|
|
1316 w->sb.bottomShadowPixmap);
|
0
|
1317
|
|
1318 w->sb.fullRedrawNext = True;
|
76
|
1319
|
|
1320 w->sb.timerActive = False;
|
0
|
1321 }
|
|
1322
|
76
|
1323 static void
|
|
1324 Destroy (Widget widget)
|
0
|
1325 {
|
|
1326 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
76
|
1327 Display *dpy = XtDisplay ((Widget) w);
|
0
|
1328
|
76
|
1329 XtReleaseGC (widget, w->sb.bottomShadowGC);
|
|
1330 XtReleaseGC (widget, w->sb.topShadowGC);
|
|
1331 XtReleaseGC (widget, w->sb.backgroundGC);
|
10
|
1332
|
76
|
1333 XFreePixmap (dpy, w->sb.grayPixmap);
|
|
1334
|
|
1335 if (w->sb.timerActive)
|
102
|
1336 {
|
|
1337 XtRemoveTimeOut (w->sb.timerId);
|
|
1338 w->sb.timerActive = False; /* Should be a no-op, but you never know */
|
|
1339 }
|
0
|
1340 }
|
|
1341
|
76
|
1342 static void
|
|
1343 Realize (Widget widget, XtValueMask *valuemask, XSetWindowAttributes *attr)
|
0
|
1344 {
|
|
1345 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
76
|
1346 Display *dpy = XtDisplay ((Widget) w);
|
0
|
1347 Window win;
|
|
1348 XSetWindowAttributes win_attr;
|
|
1349
|
|
1350 (*coreClassRec.core_class.realize)(widget, valuemask, attr);
|
|
1351
|
76
|
1352 win = XtWindow ((Widget) w);
|
0
|
1353
|
76
|
1354 seg_pixel_sizes (w, &w->sb.above, &w->sb.ss, &w->sb.below);
|
0
|
1355
|
76
|
1356 XSetWindowBackground (dpy, win, w->sb.troughColor);
|
0
|
1357
|
|
1358 /* Change bit gravity so widget is not cleared on resize */
|
102
|
1359 win_attr.bit_gravity = NorthWestGravity;
|
76
|
1360 XChangeWindowAttributes (dpy, win, CWBitGravity , &win_attr);
|
0
|
1361
|
|
1362 }
|
|
1363
|
76
|
1364 static void
|
|
1365 Resize (Widget widget)
|
0
|
1366 {
|
|
1367 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
76
|
1368 Display *dpy = XtDisplay ((Widget) w);
|
|
1369 Window win = XtWindow ((Widget) w);
|
0
|
1370
|
76
|
1371 if (XtIsRealized (widget))
|
|
1372 {
|
|
1373 DBUG (fprintf (stderr, "Resize = %08lx\n", w));
|
0
|
1374
|
76
|
1375 seg_pixel_sizes (w, &w->sb.above, &w->sb.ss, &w->sb.below);
|
0
|
1376
|
102
|
1377 /* redraw_everything (w, NULL, True); */
|
0
|
1378
|
|
1379 w->sb.fullRedrawNext = True;
|
|
1380 /* Force expose event */
|
102
|
1381 XClearArea (dpy, win, widget_x (w), widget_y (w), 1, 1, True);
|
|
1382 }
|
|
1383
|
|
1384 if (w->sb.timerActive)
|
|
1385 {
|
|
1386 XtRemoveTimeOut (w->sb.timerId);
|
|
1387 w->sb.timerActive = False;
|
76
|
1388 }
|
0
|
1389 }
|
|
1390
|
76
|
1391 static void
|
|
1392 Redisplay (Widget widget, XEvent *event, Region region)
|
0
|
1393 {
|
|
1394 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
|
1395
|
76
|
1396 DBUG (fprintf (stderr, "Redisplay = %08lx\n", w));
|
0
|
1397
|
76
|
1398 if (XtIsRealized (widget))
|
|
1399 {
|
|
1400 if (w->sb.fullRedrawNext)
|
102
|
1401 redraw_everything (w, NULL, True);
|
0
|
1402 else
|
102
|
1403 redraw_everything (w, region, False);
|
0
|
1404 w->sb.fullRedrawNext = False;
|
76
|
1405 }
|
0
|
1406 }
|
|
1407
|
76
|
1408 static Boolean
|
|
1409 SetValues (Widget current, Widget request, Widget neww,
|
|
1410 ArgList args, Cardinal *num_args)
|
0
|
1411 {
|
|
1412 XlwScrollBarWidget cur = (XlwScrollBarWidget) current;
|
|
1413 XlwScrollBarWidget w = (XlwScrollBarWidget) neww;
|
|
1414 Boolean do_redisplay = False;
|
|
1415
|
76
|
1416 if (cur->sb.troughColor != w->sb.troughColor)
|
|
1417 {
|
|
1418 if (XtIsRealized ((Widget) w))
|
|
1419 {
|
|
1420 XSetWindowBackground (XtDisplay((Widget) w), XtWindow ((Widget) w),
|
0
|
1421 w->sb.troughColor);
|
|
1422 do_redisplay = True;
|
76
|
1423 }
|
|
1424 }
|
0
|
1425
|
76
|
1426 if (cur->core.background_pixel != w->core.background_pixel)
|
|
1427 {
|
|
1428 XtReleaseGC ((Widget)cur, cur->sb.backgroundGC);
|
|
1429 w->sb.backgroundGC =
|
|
1430 get_gc (w, w->core.background_pixel, w->core.background_pixel, None);
|
0
|
1431 do_redisplay = True;
|
76
|
1432 }
|
0
|
1433
|
76
|
1434 if (cur->sb.topShadowColor != w->sb.topShadowColor ||
|
|
1435 cur->sb.topShadowPixmap != w->sb.topShadowPixmap)
|
|
1436 {
|
|
1437 XtReleaseGC ((Widget)cur, cur->sb.topShadowGC);
|
|
1438 w->sb.topShadowGC =
|
|
1439 get_gc (w, w->sb.topShadowColor, w->core.background_pixel,
|
|
1440 w->sb.topShadowPixmap);
|
0
|
1441 do_redisplay = True;
|
76
|
1442 }
|
0
|
1443
|
76
|
1444 if (cur->sb.bottomShadowColor != w->sb.bottomShadowColor ||
|
|
1445 cur->sb.bottomShadowPixmap != w->sb.bottomShadowPixmap)
|
|
1446 {
|
|
1447 XtReleaseGC ((Widget)cur, cur->sb.bottomShadowGC);
|
|
1448 w->sb.bottomShadowGC =
|
|
1449 get_gc (w, w->sb.bottomShadowColor, w->core.background_pixel,
|
|
1450 w->sb.bottomShadowPixmap);
|
0
|
1451 do_redisplay = True;
|
76
|
1452 }
|
0
|
1453
|
76
|
1454 if (cur->sb.orientation != w->sb.orientation)
|
102
|
1455 do_redisplay = True;
|
0
|
1456
|
|
1457
|
76
|
1458 if (cur->sb.minimum != w->sb.minimum ||
|
0
|
1459 cur->sb.maximum != w->sb.maximum ||
|
|
1460 cur->sb.sliderSize != w->sb.sliderSize ||
|
|
1461 cur->sb.value != w->sb.value ||
|
|
1462 cur->sb.pageIncrement != w->sb.pageIncrement ||
|
76
|
1463 cur->sb.increment != w->sb.increment)
|
|
1464 {
|
|
1465 verify_values (w);
|
|
1466 if (XtIsRealized ((Widget) w))
|
|
1467 {
|
|
1468 seg_pixel_sizes (w, &w->sb.above, &w->sb.ss, &w->sb.below);
|
102
|
1469 draw_slider (w, w->sb.above, w->sb.ss, w->sb.below);
|
76
|
1470 }
|
|
1471 }
|
0
|
1472
|
76
|
1473 if (w->sb.shadowThickness > 5) w->sb.shadowThickness = 5;
|
0
|
1474
|
76
|
1475 return do_redisplay;
|
0
|
1476 }
|
|
1477
|
76
|
1478 void
|
|
1479 XlwScrollBarGetValues (Widget widget, int *value, int *sliderSize,
|
|
1480 int *increment, int *pageIncrement)
|
0
|
1481 {
|
76
|
1482 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
0
|
1483
|
76
|
1484 if (w && XtClass ((Widget) w) == xlwScrollBarWidgetClass)
|
|
1485 {
|
|
1486 if (value) *value = w->sb.value;
|
|
1487 if (sliderSize) *sliderSize = w->sb.sliderSize;
|
|
1488 if (increment) *increment = w->sb.increment;
|
|
1489 if (pageIncrement) *pageIncrement = w->sb.pageIncrement;
|
|
1490 }
|
0
|
1491 }
|
|
1492
|
76
|
1493 void
|
|
1494 XlwScrollBarSetValues (Widget widget, int value, int sliderSize,
|
|
1495 int increment, int pageIncrement, Boolean notify)
|
0
|
1496 {
|
76
|
1497 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
0
|
1498
|
76
|
1499 if (w && XtClass ((Widget) w) == xlwScrollBarWidgetClass &&
|
0
|
1500 (w->sb.value != value ||
|
|
1501 w->sb.sliderSize != sliderSize ||
|
|
1502 w->sb.increment != increment ||
|
76
|
1503 w->sb.pageIncrement != pageIncrement))
|
|
1504 {
|
102
|
1505 int last_value = w->sb.value;
|
183
|
1506
|
0
|
1507 w->sb.value = value;
|
|
1508 w->sb.sliderSize = sliderSize;
|
|
1509 w->sb.increment = increment;
|
|
1510 w->sb.pageIncrement = pageIncrement;
|
|
1511
|
76
|
1512 verify_values (w);
|
70
|
1513
|
76
|
1514 if (XtIsRealized (widget))
|
|
1515 {
|
|
1516 seg_pixel_sizes (w, &w->sb.above, &w->sb.ss, &w->sb.below);
|
102
|
1517 draw_slider (w, w->sb.above, w->sb.ss, w->sb.below);
|
0
|
1518
|
76
|
1519 if (w->sb.value != last_value && notify)
|
102
|
1520 call_callbacks (w, XmCR_VALUE_CHANGED, w->sb.value, 0, NULL);
|
76
|
1521 }
|
|
1522 }
|
0
|
1523 }
|
|
1524
|
102
|
1525 /*-------------------------- Action Functions ---------------------------*/
|
0
|
1526
|
76
|
1527 static void
|
|
1528 timer (XtPointer data, XtIntervalId *id)
|
0
|
1529 {
|
76
|
1530 XlwScrollBarWidget w = (XlwScrollBarWidget) data;
|
|
1531 w->sb.timerActive = False;
|
0
|
1532
|
76
|
1533 if (w->sb.armed != ARM_NONE)
|
|
1534 {
|
102
|
1535 int last_value = w->sb.value;
|
173
|
1536 int reason;
|
0
|
1537
|
76
|
1538 switch (w->sb.armed)
|
|
1539 {
|
|
1540 case ARM_PAGEUP:
|
102
|
1541 decrement_value (w, w->sb.pageIncrement);
|
76
|
1542 reason = XmCR_PAGE_DECREMENT;
|
|
1543 break;
|
|
1544 case ARM_PAGEDOWN:
|
102
|
1545 increment_value (w, w->sb.pageIncrement);
|
76
|
1546 reason = XmCR_PAGE_INCREMENT;
|
|
1547 break;
|
|
1548 case ARM_UP:
|
102
|
1549 decrement_value (w, w->sb.increment);
|
76
|
1550 reason = XmCR_DECREMENT;
|
|
1551 break;
|
|
1552 case ARM_DOWN:
|
102
|
1553 increment_value (w, w->sb.increment);
|
76
|
1554 reason = XmCR_INCREMENT;
|
|
1555 break;
|
173
|
1556 default:
|
|
1557 reason = XmCR_NONE;
|
76
|
1558 }
|
0
|
1559
|
76
|
1560 verify_values (w);
|
|
1561
|
|
1562 if (last_value != w->sb.value)
|
|
1563 {
|
|
1564 seg_pixel_sizes (w, &w->sb.above, &w->sb.ss, &w->sb.below);
|
102
|
1565 draw_slider (w, w->sb.above, w->sb.ss, w->sb.below);
|
0
|
1566
|
76
|
1567 call_callbacks (w, reason, w->sb.value, 0, NULL);
|
0
|
1568
|
76
|
1569 w->sb.timerId =
|
|
1570 XtAppAddTimeOut (XtWidgetToApplicationContext ((Widget) w),
|
|
1571 (unsigned long) w->sb.repeatDelay,
|
|
1572 timer, (XtPointer) w);
|
|
1573 w->sb.timerActive = True;
|
|
1574 }
|
|
1575 }
|
0
|
1576 }
|
|
1577
|
102
|
1578 static button_where
|
76
|
1579 what_button (XlwScrollBarWidget w, int mouse_x, int mouse_y)
|
0
|
1580 {
|
102
|
1581 int width = widget_w (w);
|
|
1582 int height = widget_h (w);
|
|
1583 int arrow_height = arrow_h (w);
|
70
|
1584
|
102
|
1585 mouse_x -= widget_x (w);
|
|
1586 mouse_y -= widget_y (w);
|
0
|
1587
|
102
|
1588 if (mouse_x < 0 || mouse_x >= width ||
|
|
1589 mouse_y < 0 || mouse_y >= height)
|
|
1590 return BUTTON_NONE;
|
|
1591
|
76
|
1592 if (w->sb.showArrows)
|
|
1593 {
|
102
|
1594 if (mouse_y >= (height -= arrow_height))
|
|
1595 return BUTTON_DOWN_ARROW;
|
183
|
1596
|
76
|
1597 if (arrow_same_end (w))
|
|
1598 {
|
102
|
1599 if (mouse_y >= (height -= arrow_height))
|
|
1600 return BUTTON_UP_ARROW;
|
76
|
1601 }
|
70
|
1602 else
|
102
|
1603 if ( (mouse_y -= arrow_height) < 0)
|
|
1604 return BUTTON_UP_ARROW;
|
76
|
1605 }
|
183
|
1606
|
102
|
1607 if ( (mouse_y -= w->sb.above) < 0)
|
|
1608 return BUTTON_TROUGH_ABOVE;
|
26
|
1609
|
102
|
1610 if ( (mouse_y -= w->sb.ss) < 0)
|
|
1611 return BUTTON_SLIDER;
|
|
1612
|
|
1613 return BUTTON_TROUGH_BELOW;
|
0
|
1614 }
|
|
1615
|
76
|
1616 static void
|
|
1617 Select (Widget widget, XEvent *event, String *parms, Cardinal *num_parms)
|
0
|
1618 {
|
76
|
1619 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
102
|
1620 button_where sb_button;
|
0
|
1621
|
102
|
1622 int mouse_x = event_x (w, event);
|
|
1623 int mouse_y = event_y (w, event);
|
0
|
1624
|
102
|
1625 int last_value = w->sb.savedValue = w->sb.value;
|
|
1626 int reason = XmCR_NONE;
|
0
|
1627
|
76
|
1628 XtGrabKeyboard ((Widget) w, False, GrabModeAsync, GrabModeAsync,
|
|
1629 event->xbutton.time);
|
10
|
1630
|
76
|
1631 sb_button = what_button (w, mouse_x, mouse_y);
|
|
1632
|
102
|
1633 if (w->sb.forced_scroll != FORCED_SCROLL_NONE)
|
0
|
1634 {
|
102
|
1635 switch (sb_button)
|
0
|
1636 {
|
|
1637 case BUTTON_TROUGH_ABOVE:
|
|
1638 case BUTTON_TROUGH_BELOW:
|
102
|
1639 case BUTTON_SLIDER:
|
0
|
1640 sb_button= BUTTON_NONE; /* cause next switch to fall through */
|
102
|
1641 if (w->sb.forced_scroll == FORCED_SCROLL_UPLEFT)
|
0
|
1642 {
|
102
|
1643 decrement_value (w, w->sb.pageIncrement);
|
0
|
1644 w->sb.armed = ARM_PAGEUP;
|
|
1645 reason = XmCR_PAGE_DECREMENT;
|
|
1646 break;
|
|
1647 }
|
102
|
1648 else if (w->sb.forced_scroll == FORCED_SCROLL_DOWNRIGHT)
|
0
|
1649 {
|
102
|
1650 increment_value (w, w->sb.pageIncrement);
|
0
|
1651 w->sb.armed = ARM_PAGEDOWN;
|
|
1652 reason = XmCR_PAGE_INCREMENT;
|
|
1653 break;
|
|
1654 }
|
|
1655 abort();
|
173
|
1656 default:
|
|
1657 ; /* Do nothing */
|
0
|
1658 }
|
|
1659 }
|
|
1660
|
76
|
1661 switch (sb_button)
|
|
1662 {
|
|
1663 case BUTTON_TROUGH_ABOVE:
|
102
|
1664 decrement_value (w, w->sb.pageIncrement);
|
76
|
1665 w->sb.armed = ARM_PAGEUP;
|
|
1666 reason = XmCR_PAGE_DECREMENT;
|
|
1667 break;
|
|
1668 case BUTTON_TROUGH_BELOW:
|
102
|
1669 increment_value (w, w->sb.pageIncrement);
|
76
|
1670 w->sb.armed = ARM_PAGEDOWN;
|
|
1671 reason = XmCR_PAGE_INCREMENT;
|
|
1672 break;
|
102
|
1673 case BUTTON_SLIDER:
|
76
|
1674 w->sb.lastY = mouse_y;
|
102
|
1675 w->sb.armed = ARM_SLIDER;
|
|
1676 draw_slider (w, w->sb.above, w->sb.ss, w->sb.below);
|
76
|
1677 break;
|
|
1678 case BUTTON_UP_ARROW:
|
|
1679 if (event->xbutton.state & ControlMask)
|
|
1680 {
|
102
|
1681 w->sb.value = w->sb.minimum;
|
76
|
1682 reason = XmCR_TO_TOP;
|
|
1683 }
|
|
1684 else
|
|
1685 {
|
102
|
1686 decrement_value (w, w->sb.increment);
|
76
|
1687 reason = XmCR_DECREMENT;
|
|
1688 }
|
102
|
1689 w->sb.armed = ARM_UP;
|
76
|
1690 redraw_up_arrow (w, True, False);
|
|
1691 break;
|
|
1692 case BUTTON_DOWN_ARROW:
|
|
1693 if (event->xbutton.state & ControlMask)
|
|
1694 {
|
102
|
1695 w->sb.value = w->sb.maximum;
|
76
|
1696 reason = XmCR_TO_BOTTOM;
|
|
1697 }
|
|
1698 else
|
|
1699 {
|
102
|
1700 increment_value (w, w->sb.increment);
|
76
|
1701 reason = XmCR_INCREMENT;
|
|
1702 }
|
102
|
1703 w->sb.armed = ARM_DOWN;
|
76
|
1704 redraw_down_arrow (w, True, False);
|
|
1705 break;
|
173
|
1706 case BUTTON_NONE:
|
|
1707 ; /* Do nothing */
|
76
|
1708 }
|
0
|
1709
|
76
|
1710 verify_values (w);
|
10
|
1711
|
76
|
1712 if (last_value != w->sb.value)
|
|
1713 {
|
|
1714 seg_pixel_sizes (w, &w->sb.above, &w->sb.ss, &w->sb.below);
|
102
|
1715 draw_slider (w, w->sb.above, w->sb.ss, w->sb.below);
|
183
|
1716
|
76
|
1717 call_callbacks (w, reason, w->sb.value, mouse_y, event);
|
|
1718
|
|
1719 if (w->sb.timerActive)
|
|
1720 XtRemoveTimeOut (w->sb.timerId);
|
0
|
1721
|
76
|
1722 w->sb.timerId =
|
|
1723 XtAppAddTimeOut (XtWidgetToApplicationContext ((Widget) w),
|
|
1724 (unsigned long) w->sb.initialDelay,
|
|
1725 timer, (XtPointer) w);
|
|
1726 w->sb.timerActive = True;
|
|
1727 }
|
0
|
1728
|
76
|
1729 CHECK (w);
|
0
|
1730 }
|
|
1731
|
76
|
1732 static void
|
173
|
1733 PageDownOrRight (Widget widget, XEvent *event, String *parms, Cardinal *num_parms)
|
|
1734 {
|
|
1735 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
|
1736 w->sb.forced_scroll = FORCED_SCROLL_DOWNRIGHT;
|
|
1737 Select (widget, event, parms, num_parms);
|
|
1738 w->sb.forced_scroll = FORCED_SCROLL_NONE;
|
|
1739 }
|
|
1740
|
|
1741 static void
|
|
1742 PageUpOrLeft (Widget widget, XEvent *event, String *parms, Cardinal *num_parms)
|
|
1743 {
|
|
1744 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
|
1745 w->sb.forced_scroll = FORCED_SCROLL_UPLEFT;
|
|
1746 Select (widget, event, parms, num_parms);
|
|
1747 w->sb.forced_scroll = FORCED_SCROLL_NONE;
|
|
1748 }
|
|
1749
|
|
1750 static void
|
76
|
1751 Drag (Widget widget, XEvent *event, String *parms, Cardinal *num_parms)
|
0
|
1752 {
|
76
|
1753 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
70
|
1754
|
102
|
1755 if (w->sb.armed == ARM_SLIDER)
|
76
|
1756 {
|
102
|
1757 int mouse_y = event_y (w, event);
|
|
1758 int diff = mouse_y - w->sb.lastY;
|
70
|
1759
|
102
|
1760 if (diff < -(w->sb.above)) /* up */
|
76
|
1761 {
|
102
|
1762 mouse_y -= (diff + w->sb.above);
|
|
1763 diff = -(w->sb.above);
|
76
|
1764 }
|
102
|
1765 else if (diff > w->sb.below) /* down */
|
76
|
1766 {
|
102
|
1767 mouse_y -= (diff - w->sb.below);
|
|
1768 diff = w->sb.below;
|
76
|
1769 }
|
0
|
1770
|
102
|
1771 if (diff)
|
76
|
1772 {
|
102
|
1773 w->sb.above += diff;
|
|
1774 w->sb.below -= diff;
|
|
1775
|
|
1776 draw_slider (w, w->sb.above, w->sb.ss, w->sb.below);
|
0
|
1777
|
|
1778 w->sb.lastY = mouse_y;
|
|
1779
|
76
|
1780 w->sb.value = value_from_pixel (w, w->sb.above);
|
|
1781 verify_values (w);
|
|
1782 CHECK (w);
|
0
|
1783
|
102
|
1784 call_callbacks (w, XmCR_DRAG, w->sb.value, event_y (w, event), event);
|
76
|
1785 }
|
|
1786 }
|
|
1787 CHECK (w);
|
0
|
1788 }
|
|
1789
|
76
|
1790 static void
|
|
1791 Release (Widget widget, XEvent *event, String *parms, Cardinal *num_parms)
|
0
|
1792 {
|
76
|
1793 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
70
|
1794
|
76
|
1795 switch (w->sb.armed)
|
|
1796 {
|
102
|
1797 case ARM_SLIDER:
|
76
|
1798 call_callbacks (w, XmCR_VALUE_CHANGED, w->sb.value, event_y (w, event), event);
|
|
1799 w->sb.armed = ARM_NONE;
|
102
|
1800 draw_slider (w, w->sb.above, w->sb.ss, w->sb.below);
|
76
|
1801 break;
|
|
1802 case ARM_UP:
|
|
1803 redraw_up_arrow (w, False, False);
|
|
1804 break;
|
|
1805 case ARM_DOWN:
|
|
1806 redraw_down_arrow (w, False, False);
|
|
1807 break;
|
173
|
1808 default:
|
|
1809 ; /* Do nothing */
|
76
|
1810 }
|
0
|
1811
|
76
|
1812 XtUngrabKeyboard ((Widget) w, event->xbutton.time);
|
0
|
1813
|
|
1814 w->sb.armed = ARM_NONE;
|
|
1815 }
|
|
1816
|
76
|
1817 static void
|
|
1818 Jump (Widget widget, XEvent *event, String *parms, Cardinal *num_parms)
|
0
|
1819 {
|
76
|
1820 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
102
|
1821 int last_value;
|
0
|
1822
|
102
|
1823 int mouse_x = event_x (w, event);
|
|
1824 int mouse_y = event_y (w, event);
|
0
|
1825
|
102
|
1826 int scroll_region_y = widget_y (w);
|
|
1827 int scroll_region_h = widget_h (w);
|
183
|
1828
|
102
|
1829 if (w->sb.showArrows)
|
|
1830 {
|
|
1831 int arrow_height = arrow_h (w);
|
|
1832 scroll_region_h -= 2 * arrow_height;
|
|
1833 if (!arrow_same_end (w))
|
|
1834 scroll_region_y += arrow_height;
|
|
1835 }
|
0
|
1836
|
76
|
1837 XtGrabKeyboard ((Widget) w, False, GrabModeAsync, GrabModeAsync,
|
|
1838 event->xbutton.time);
|
70
|
1839
|
76
|
1840 switch (what_button (w, mouse_x, mouse_y))
|
|
1841 {
|
|
1842 case BUTTON_TROUGH_ABOVE:
|
|
1843 case BUTTON_TROUGH_BELOW:
|
102
|
1844 case BUTTON_SLIDER:
|
76
|
1845 w->sb.savedValue = w->sb.value;
|
70
|
1846
|
76
|
1847 last_value = w->sb.value;
|
70
|
1848
|
102
|
1849 w->sb.above = mouse_y - (w->sb.ss / 2) - scroll_region_y;
|
76
|
1850 if (w->sb.above < 0)
|
102
|
1851 w->sb.above = 0;
|
183
|
1852 else if (w->sb.above + w->sb.ss > scroll_region_h)
|
102
|
1853 w->sb.above = scroll_region_h - w->sb.ss;
|
|
1854
|
|
1855 w->sb.below = scroll_region_h - w->sb.ss - w->sb.above;
|
26
|
1856
|
102
|
1857 w->sb.armed = ARM_SLIDER;
|
|
1858 draw_slider (w, w->sb.above, w->sb.ss, w->sb.below);
|
0
|
1859
|
102
|
1860 w->sb.value = value_from_pixel (w, w->sb.above);
|
|
1861 verify_values (w);
|
|
1862 CHECK (w);
|
26
|
1863
|
102
|
1864 w->sb.lastY = mouse_y;
|
|
1865
|
|
1866 if (w->sb.value != last_value)
|
|
1867 call_callbacks (w, XmCR_DRAG, w->sb.value, mouse_y, event);
|
183
|
1868
|
76
|
1869 break;
|
173
|
1870 default:
|
|
1871 ; /* Do nothing */
|
76
|
1872 }
|
|
1873 CHECK (w);
|
0
|
1874 }
|
|
1875
|
76
|
1876 static void
|
|
1877 Abort (Widget widget, XEvent *event, String *parms, Cardinal *num_parms)
|
0
|
1878 {
|
76
|
1879 XlwScrollBarWidget w = (XlwScrollBarWidget) widget;
|
0
|
1880
|
76
|
1881 if (w->sb.armed != ARM_NONE)
|
|
1882 {
|
|
1883 if (w->sb.value != w->sb.savedValue)
|
|
1884 {
|
0
|
1885 w->sb.value = w->sb.savedValue;
|
|
1886
|
76
|
1887 seg_pixel_sizes (w, &w->sb.above, &w->sb.ss, &w->sb.below);
|
102
|
1888 draw_slider (w, w->sb.above, w->sb.ss, w->sb.below);
|
0
|
1889
|
76
|
1890 call_callbacks (w, XmCR_VALUE_CHANGED, w->sb.value,
|
|
1891 event_y (w, event), event);
|
|
1892 }
|
|
1893
|
|
1894 switch (w->sb.armed)
|
|
1895 {
|
|
1896 case ARM_UP: redraw_up_arrow (w, False, False); break;
|
|
1897 case ARM_DOWN: redraw_down_arrow (w, False, False); break;
|
173
|
1898 default: ; /* Do nothing */
|
76
|
1899 }
|
0
|
1900
|
|
1901 w->sb.armed = ARM_NONE;
|
|
1902
|
76
|
1903 XtUngrabKeyboard ((Widget) w, event->xbutton.time);
|
|
1904 }
|
0
|
1905 }
|