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