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