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