comparison src/objects-msw.c @ 227:0e522484dd2a r20-5b12

Import from CVS: tag r20-5b12
author cvs
date Mon, 13 Aug 2007 10:12:37 +0200
parents d44af0c54775
children 557eaa0339bf
comparison
equal deleted inserted replaced
226:eea38c7ad7b4 227:0e522484dd2a
714 {"Gray100" , PALETTERGB (255,255,255)}, 714 {"Gray100" , PALETTERGB (255,255,255)},
715 {"Grey100" , PALETTERGB (255,255,255)}, 715 {"Grey100" , PALETTERGB (255,255,255)},
716 {"White" , PALETTERGB (255,255,255)} 716 {"White" , PALETTERGB (255,255,255)}
717 }; 717 };
718 718
719 static int
720 hexval (char c)
721 {
722 if (c >= 'a' && c <= 'f')
723 return c-'a' + 10;
724 return c-'0';
725 }
726
727
719 static COLORREF 728 static COLORREF
720 mswindows_string_to_color(CONST char *name) 729 mswindows_string_to_color(CONST char *name)
721 { 730 {
722 int color, i; 731 int i;
723 732 unsigned int r, g, b;
733
724 if (*name == '#') 734 if (*name == '#')
725 { 735 {
726 /* mswindows numeric names look like "#BBGGRR" */ 736 /* numeric names look like "#RRGGBB" */
737 /* XXX accept other formats? */
727 if (strlen(name)!=7) 738 if (strlen(name)!=7)
728 return (-1); 739 return (-1);
729 for (i=1; i<7; i++) 740 for (i=1; i<7; i++)
730 if (!isxdigit(name[i])) 741 {
731 return(-1); 742 if (!isxdigit(name[i]))
732 if (sscanf(name+1, "%x", &color) == 1) 743 return(-1);
733 return(0x02000000 | color); /* See PALETTERGB in docs */ 744 name[i] = tolower(name[i]);
745 }
746 r = hexval(name[1]) * 16 + hexval(name[2]);
747 g = hexval(name[3]) * 16 + hexval(name[4]);
748 b = hexval(name[5]) * 16 + hexval(name[6]);
749 return (PALETTERGB (r, g, b));
734 } 750 }
735 else 751 else
736 { 752 {
737 for(i=0; i<(sizeof(mswindows_X_color_map)/sizeof(colormap_t)); i++) 753 for(i=0; i<(sizeof(mswindows_X_color_map)/sizeof(colormap_t)); i++)
738 if (!stricmp(name, mswindows_X_color_map[i].name)) 754 if (!stricmp(name, mswindows_X_color_map[i].name))
772 Lisp_Object printcharfun, 788 Lisp_Object printcharfun,
773 int escapeflag) 789 int escapeflag)
774 { 790 {
775 char buf[32]; 791 char buf[32];
776 COLORREF color = COLOR_INSTANCE_MSWINDOWS_COLOR (c); 792 COLORREF color = COLOR_INSTANCE_MSWINDOWS_COLOR (c);
777 sprintf (buf, " %06ld=(%02X,%02X,%02X)", color & 0xffffff, 793 sprintf (buf, " %06ld=(%04X,%04X,%04X)", color & 0xffffff,
778 GetRValue(color), GetGValue(color), GetBValue(color)); 794 GetRValue(color)<<8, GetGValue(color)<<8, GetBValue(color)<<8);
779 write_c_string (buf, printcharfun); 795 write_c_string (buf, printcharfun);
780 } 796 }
781 797
782 static void 798 static void
783 mswindows_finalize_color_instance (struct Lisp_Color_Instance *c) 799 mswindows_finalize_color_instance (struct Lisp_Color_Instance *c)
806 822
807 static Lisp_Object 823 static Lisp_Object
808 mswindows_color_instance_rgb_components (struct Lisp_Color_Instance *c) 824 mswindows_color_instance_rgb_components (struct Lisp_Color_Instance *c)
809 { 825 {
810 COLORREF color = COLOR_INSTANCE_MSWINDOWS_COLOR (c); 826 COLORREF color = COLOR_INSTANCE_MSWINDOWS_COLOR (c);
811 return (list3 (make_int (GetRValue(color)), 827 return (list3 (make_int (GetRValue(color)<<8),
812 make_int (GetGValue(color)), 828 make_int (GetGValue(color)<<8),
813 make_int (GetBValue(color)))); 829 make_int (GetBValue(color)<<8)));
814 } 830 }
815 831
816 static int 832 static int
817 mswindows_valid_color_name_p (struct device *d, Lisp_Object color) 833 mswindows_valid_color_name_p (struct device *d, Lisp_Object color)
818 { 834 {