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