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