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