Mercurial > hg > xemacs-beta
comparison lwlib/xlwscrollbar.c @ 3094:ad2f4ae9895b
[xemacs-hg @ 2005-11-26 11:45:47 by stephent]
Xft merge. <87k6ev4p8q.fsf@tleepslib.sk.tsukuba.ac.jp>
author | stephent |
---|---|
date | Sat, 26 Nov 2005 11:46:25 +0000 |
parents | 04bc9d2f42c7 |
children | 383ab474a241 |
comparison
equal
deleted
inserted
replaced
3093:769dc945b085 | 3094:ad2f4ae9895b |
---|---|
76 | 76 |
77 #include <X11/IntrinsicP.h> | 77 #include <X11/IntrinsicP.h> |
78 #include <X11/StringDefs.h> | 78 #include <X11/StringDefs.h> |
79 #include <X11/bitmaps/gray> | 79 #include <X11/bitmaps/gray> |
80 | 80 |
81 #include "lwlib-colors.h" | |
82 | |
81 #include "xlwscrollbarP.h" | 83 #include "xlwscrollbarP.h" |
82 #include "xlwscrollbar.h" | 84 #include "xlwscrollbar.h" |
83 | 85 |
84 #ifdef USE_DEBUG_MALLOC | 86 #ifdef USE_DEBUG_MALLOC |
85 #include <dmalloc.h> | 87 #include <dmalloc.h> |
521 (values.stipple == None ? 0 : GCStipple | GCFillStyle); | 523 (values.stipple == None ? 0 : GCStipple | GCFillStyle); |
522 | 524 |
523 return XtGetGC((Widget) w, mask, &values); | 525 return XtGetGC((Widget) w, mask, &values); |
524 } | 526 } |
525 | 527 |
526 /* Replacement for XAllocColor() that tries to return the nearest | |
527 available color if the colormap is full. From FSF Emacs. */ | |
528 | |
529 static int | |
530 allocate_nearest_color (Display *display, Colormap screen_colormap, | |
531 XColor *color_def) | |
532 { | |
533 int status = XAllocColor (display, screen_colormap, color_def); | |
534 if (status) | |
535 return status; | |
536 | |
537 { | |
538 /* If we got to this point, the colormap is full, so we're | |
539 going to try to get the next closest color. | |
540 The algorithm used is a least-squares matching, which is | |
541 what X uses for closest color matching with StaticColor visuals. */ | |
542 | |
543 int nearest, x; | |
544 unsigned long nearest_delta = ULONG_MAX; | |
545 | |
546 int no_cells = XDisplayCells (display, XDefaultScreen (display)); | |
547 /* Don't use alloca here because lwlib doesn't have the | |
548 necessary configuration information that src does. */ | |
549 XColor *cells = (XColor *) malloc (sizeof (XColor) * no_cells); | |
550 | |
551 for (x = 0; x < no_cells; x++) | |
552 cells[x].pixel = x; | |
553 | |
554 XQueryColors (display, screen_colormap, cells, no_cells); | |
555 | |
556 for (nearest = 0, x = 0; x < no_cells; x++) | |
557 { | |
558 long dred = (color_def->red >> 8) - (cells[x].red >> 8); | |
559 long dgreen = (color_def->green >> 8) - (cells[x].green >> 8); | |
560 long dblue = (color_def->blue >> 8) - (cells[x].blue >> 8); | |
561 unsigned long delta = dred * dred + dgreen * dgreen + dblue * dblue; | |
562 | |
563 if (delta < nearest_delta) | |
564 { | |
565 nearest = x; | |
566 nearest_delta = delta; | |
567 } | |
568 } | |
569 color_def->red = cells[nearest].red; | |
570 color_def->green = cells[nearest].green; | |
571 color_def->blue = cells[nearest].blue; | |
572 free (cells); | |
573 return XAllocColor (display, screen_colormap, color_def); | |
574 } | |
575 } | |
576 | |
577 static void | 528 static void |
578 make_shadow_pixels (XlwScrollBarWidget w) | 529 make_shadow_pixels (XlwScrollBarWidget w) |
579 { | 530 { |
580 Display *dpy = XtDisplay((Widget) w); | 531 Display *dpy = XtDisplay ((Widget) w); |
581 Colormap cmap = w->core.colormap; | 532 Colormap cmap = w->core.colormap; |
582 XColor topc, botc; | 533 XColor topc, botc; |
583 int top_frobbed, bottom_frobbed; | 534 int top_frobbed, bottom_frobbed; |
584 Pixel bg, fg; | 535 Pixel bg, fg; |
536 Visual *visual; | |
537 int ignored; | |
538 | |
539 visual_info_from_widget ((Widget) w, &visual, &ignored); | |
540 /* #### Apparently this is called before any shell has a visual? | |
541 or maybe the widget doesn't have a parent yet? */ | |
542 if (visual == CopyFromParent) | |
543 { | |
544 Screen *screen = DefaultScreenOfDisplay (dpy); | |
545 visual = DefaultVisualOfScreen (screen); | |
546 } | |
585 | 547 |
586 top_frobbed = bottom_frobbed = 0; | 548 top_frobbed = bottom_frobbed = 0; |
587 | 549 |
588 bg = w->core.background_pixel; | 550 bg = w->core.background_pixel; |
589 fg = w->sb.foreground; | 551 fg = w->sb.foreground; |
593 | 555 |
594 if (w->sb.topShadowColor == bg || w->sb.topShadowColor == fg) | 556 if (w->sb.topShadowColor == bg || w->sb.topShadowColor == fg) |
595 { | 557 { |
596 topc.pixel = bg; | 558 topc.pixel = bg; |
597 XQueryColor (dpy, cmap, &topc); | 559 XQueryColor (dpy, cmap, &topc); |
560 /* #### can we use a (generalized) xft_convert_color here? */ | |
598 /* don't overflow/wrap! */ | 561 /* don't overflow/wrap! */ |
599 topc.red = MINL(65535, topc.red * 1.2); | 562 topc.red = MINL(65535, topc.red * 1.2); |
600 topc.green = MINL(65535, topc.green * 1.2); | 563 topc.green = MINL(65535, topc.green * 1.2); |
601 topc.blue = MINL(65535, topc.blue * 1.2); | 564 topc.blue = MINL(65535, topc.blue * 1.2); |
602 if (allocate_nearest_color (dpy, cmap, &topc)) | 565 if (x_allocate_nearest_color (dpy, cmap, visual, &topc)) |
603 { | 566 { |
604 if (topc.pixel == bg) | 567 if (topc.pixel == bg) |
605 { | 568 { |
606 XFreeColors (dpy, cmap, &topc.pixel, 1, 0); | 569 XFreeColors (dpy, cmap, &topc.pixel, 1, 0); |
607 topc.red = MINL(65535, topc.red + 0x8000); | 570 topc.red = MINL(65535, topc.red + 0x8000); |
608 topc.green = MINL(65535, topc.green + 0x8000); | 571 topc.green = MINL(65535, topc.green + 0x8000); |
609 topc.blue = MINL(65535, topc.blue + 0x8000); | 572 topc.blue = MINL(65535, topc.blue + 0x8000); |
610 if (allocate_nearest_color (dpy, cmap, &topc)) | 573 if (x_allocate_nearest_color (dpy, cmap, visual, &topc)) |
611 { | 574 { |
612 w->sb.topShadowColor = topc.pixel; | 575 w->sb.topShadowColor = topc.pixel; |
613 } | 576 } |
614 } | 577 } |
615 else | 578 else |
626 botc.pixel = bg; | 589 botc.pixel = bg; |
627 XQueryColor (dpy, cmap, &botc); | 590 XQueryColor (dpy, cmap, &botc); |
628 botc.red = (botc.red * 3) / 5; | 591 botc.red = (botc.red * 3) / 5; |
629 botc.green = (botc.green * 3) / 5; | 592 botc.green = (botc.green * 3) / 5; |
630 botc.blue = (botc.blue * 3) / 5; | 593 botc.blue = (botc.blue * 3) / 5; |
631 if (allocate_nearest_color (dpy, cmap, &botc)) | 594 if (x_allocate_nearest_color (dpy, cmap, visual, &botc)) |
632 { | 595 { |
633 if (botc.pixel == bg) | 596 if (botc.pixel == bg) |
634 { | 597 { |
635 XFreeColors (dpy, cmap, &botc.pixel, 1, 0); | 598 XFreeColors (dpy, cmap, &botc.pixel, 1, 0); |
636 botc.red = MINL(65535, botc.red + 0x4000); | 599 botc.red = MINL(65535, botc.red + 0x4000); |
637 botc.green = MINL(65535, botc.green + 0x4000); | 600 botc.green = MINL(65535, botc.green + 0x4000); |
638 botc.blue = MINL(65535, botc.blue + 0x4000); | 601 botc.blue = MINL(65535, botc.blue + 0x4000); |
639 if (allocate_nearest_color (dpy, cmap, &botc)) | 602 if (x_allocate_nearest_color (dpy, cmap, visual, &botc)) |
640 { | 603 { |
641 w->sb.bottomShadowColor = botc.pixel; | 604 w->sb.bottomShadowColor = botc.pixel; |
642 } | 605 } |
643 } | 606 } |
644 else | 607 else |
701 make_trough_pixel (XlwScrollBarWidget w) | 664 make_trough_pixel (XlwScrollBarWidget w) |
702 { | 665 { |
703 Display *dpy = XtDisplay((Widget) w); | 666 Display *dpy = XtDisplay((Widget) w); |
704 Colormap cmap = w->core.colormap; | 667 Colormap cmap = w->core.colormap; |
705 XColor troughC; | 668 XColor troughC; |
669 Visual *visual; | |
670 int ignored; | |
671 | |
672 visual_info_from_widget ((Widget) w, &visual, &ignored); | |
673 /* #### Apparently this is called before any shell has a visual? | |
674 or maybe the widget doesn't have a parent yet? */ | |
675 if (visual == CopyFromParent) | |
676 { | |
677 Screen *screen = DefaultScreenOfDisplay (dpy); | |
678 visual = DefaultVisualOfScreen (screen); | |
679 } | |
706 | 680 |
707 if (w->sb.troughColor == (Pixel)~0) w->sb.troughColor = w->core.background_pixel; | 681 if (w->sb.troughColor == (Pixel)~0) w->sb.troughColor = w->core.background_pixel; |
708 | 682 |
709 if (w->sb.troughColor == w->core.background_pixel) | 683 if (w->sb.troughColor == w->core.background_pixel) |
710 { | 684 { |
711 troughC.pixel = w->core.background_pixel; | 685 troughC.pixel = w->core.background_pixel; |
712 XQueryColor (dpy, cmap, &troughC); | 686 XQueryColor (dpy, cmap, &troughC); |
713 troughC.red = (troughC.red * 4) / 5; | 687 troughC.red = (troughC.red * 4) / 5; |
714 troughC.green = (troughC.green * 4) / 5; | 688 troughC.green = (troughC.green * 4) / 5; |
715 troughC.blue = (troughC.blue * 4) / 5; | 689 troughC.blue = (troughC.blue * 4) / 5; |
716 if (allocate_nearest_color (dpy, cmap, &troughC)) | 690 if (x_allocate_nearest_color (dpy, cmap, visual, &troughC)) |
717 w->sb.troughColor = troughC.pixel; | 691 w->sb.troughColor = troughC.pixel; |
718 } | 692 } |
719 } | 693 } |
720 | 694 |
721 /*-------------------------- Draw 3D Border -----------------------------*/ | 695 /*-------------------------- Draw 3D Border -----------------------------*/ |