diff src/gui_w32.c @ 9013:22c29a515b53 v7.4.1792

commit https://github.com/vim/vim/commit/ab3022196ea4f1496e79b8ee85996e31c45d02f1 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Apr 26 20:59:29 2016 +0200 patch 7.4.1792 Problem: Color name decoding is implemented several times. Solution: Move it to term.c. (Christian Brabandt)
author Christian Brabandt <cb@256bit.org>
date Tue, 26 Apr 2016 21:00:07 +0200
parents c1a5623cfc86
children 7b1200ea03a1
line wrap: on
line diff
--- a/src/gui_w32.c
+++ b/src/gui_w32.c
@@ -1555,16 +1555,6 @@ gui_mch_free_font(GuiFont font)
 	DeleteObject((HFONT)font);
 }
 
-    static int
-hex_digit(int c)
-{
-    if (VIM_ISDIGIT(c))
-	return c - '0';
-    c = TOLOWER_ASC(c);
-    if (c >= 'a' && c <= 'f')
-	return c - 'a' + 10;
-    return -1000;
-}
 /*
  * Return the Pixel value (color) for the given color name.
  * Return INVALCOLOR for error.
@@ -1572,65 +1562,6 @@ hex_digit(int c)
     guicolor_T
 gui_mch_get_color(char_u *name)
 {
-    typedef struct guicolor_tTable
-    {
-	char	    *name;
-	COLORREF    color;
-    } guicolor_tTable;
-
-    static guicolor_tTable table[] =
-    {
-	{"Black",		RGB(0x00, 0x00, 0x00)},
-	{"DarkGray",		RGB(0xA9, 0xA9, 0xA9)},
-	{"DarkGrey",		RGB(0xA9, 0xA9, 0xA9)},
-	{"Gray",		RGB(0xC0, 0xC0, 0xC0)},
-	{"Grey",		RGB(0xC0, 0xC0, 0xC0)},
-	{"LightGray",		RGB(0xD3, 0xD3, 0xD3)},
-	{"LightGrey",		RGB(0xD3, 0xD3, 0xD3)},
-	{"Gray10",		RGB(0x1A, 0x1A, 0x1A)},
-	{"Grey10",		RGB(0x1A, 0x1A, 0x1A)},
-	{"Gray20",		RGB(0x33, 0x33, 0x33)},
-	{"Grey20",		RGB(0x33, 0x33, 0x33)},
-	{"Gray30",		RGB(0x4D, 0x4D, 0x4D)},
-	{"Grey30",		RGB(0x4D, 0x4D, 0x4D)},
-	{"Gray40",		RGB(0x66, 0x66, 0x66)},
-	{"Grey40",		RGB(0x66, 0x66, 0x66)},
-	{"Gray50",		RGB(0x7F, 0x7F, 0x7F)},
-	{"Grey50",		RGB(0x7F, 0x7F, 0x7F)},
-	{"Gray60",		RGB(0x99, 0x99, 0x99)},
-	{"Grey60",		RGB(0x99, 0x99, 0x99)},
-	{"Gray70",		RGB(0xB3, 0xB3, 0xB3)},
-	{"Grey70",		RGB(0xB3, 0xB3, 0xB3)},
-	{"Gray80",		RGB(0xCC, 0xCC, 0xCC)},
-	{"Grey80",		RGB(0xCC, 0xCC, 0xCC)},
-	{"Gray90",		RGB(0xE5, 0xE5, 0xE5)},
-	{"Grey90",		RGB(0xE5, 0xE5, 0xE5)},
-	{"White",		RGB(0xFF, 0xFF, 0xFF)},
-	{"DarkRed",		RGB(0x80, 0x00, 0x00)},
-	{"Red",			RGB(0xFF, 0x00, 0x00)},
-	{"LightRed",		RGB(0xFF, 0xA0, 0xA0)},
-	{"DarkBlue",		RGB(0x00, 0x00, 0x80)},
-	{"Blue",		RGB(0x00, 0x00, 0xFF)},
-	{"LightBlue",		RGB(0xAD, 0xD8, 0xE6)},
-	{"DarkGreen",		RGB(0x00, 0x80, 0x00)},
-	{"Green",		RGB(0x00, 0xFF, 0x00)},
-	{"LightGreen",		RGB(0x90, 0xEE, 0x90)},
-	{"DarkCyan",		RGB(0x00, 0x80, 0x80)},
-	{"Cyan",		RGB(0x00, 0xFF, 0xFF)},
-	{"LightCyan",		RGB(0xE0, 0xFF, 0xFF)},
-	{"DarkMagenta",		RGB(0x80, 0x00, 0x80)},
-	{"Magenta",		RGB(0xFF, 0x00, 0xFF)},
-	{"LightMagenta",	RGB(0xFF, 0xA0, 0xFF)},
-	{"Brown",		RGB(0x80, 0x40, 0x40)},
-	{"Yellow",		RGB(0xFF, 0xFF, 0x00)},
-	{"LightYellow",		RGB(0xFF, 0xFF, 0xE0)},
-	{"DarkYellow",		RGB(0xBB, 0xBB, 0x00)},
-	{"SeaGreen",		RGB(0x2E, 0x8B, 0x57)},
-	{"Orange",		RGB(0xFF, 0xA5, 0x00)},
-	{"Purple",		RGB(0xA0, 0x20, 0xF0)},
-	{"SlateBlue",		RGB(0x6A, 0x5A, 0xCD)},
-	{"Violet",		RGB(0xEE, 0x82, 0xEE)},
-    };
 
     typedef struct SysColorTable
     {
@@ -1677,27 +1608,6 @@ gui_mch_get_color(char_u *name)
 	{"SYS_WINDOWTEXT", COLOR_WINDOWTEXT}
     };
 
-    int		    r, g, b;
-    int		    i;
-
-    if (name[0] == '#' && STRLEN(name) == 7)
-    {
-	/* Name is in "#rrggbb" format */
-	r = hex_digit(name[1]) * 16 + hex_digit(name[2]);
-	g = hex_digit(name[3]) * 16 + hex_digit(name[4]);
-	b = hex_digit(name[5]) * 16 + hex_digit(name[6]);
-	if (r < 0 || g < 0 || b < 0)
-	    return INVALCOLOR;
-	return RGB(r, g, b);
-    }
-    else
-    {
-	/* Check if the name is one of the colors we know */
-	for (i = 0; i < sizeof(table) / sizeof(table[0]); i++)
-	    if (STRICMP(name, table[i].name) == 0)
-		return table[i].color;
-    }
-
     /*
      * Try to look up a system colour.
      */
@@ -1705,55 +1615,7 @@ gui_mch_get_color(char_u *name)
 	if (STRICMP(name, sys_table[i].name) == 0)
 	    return GetSysColor(sys_table[i].color);
 
-    /*
-     * Last attempt. Look in the file "$VIMRUNTIME/rgb.txt".
-     */
-    {
-#define LINE_LEN 100
-	FILE	*fd;
-	char	line[LINE_LEN];
-	char_u	*fname;
-
-	fname = expand_env_save((char_u *)"$VIMRUNTIME/rgb.txt");
-	if (fname == NULL)
-	    return INVALCOLOR;
-
-	fd = mch_fopen((char *)fname, "rt");
-	vim_free(fname);
-	if (fd == NULL)
-	    return INVALCOLOR;
-
-	while (!feof(fd))
-	{
-	    int	    len;
-	    int	    pos;
-	    char    *color;
-
-	    fgets(line, LINE_LEN, fd);
-	    len = (int)STRLEN(line);
-
-	    if (len <= 1 || line[len-1] != '\n')
-		continue;
-
-	    line[len-1] = '\0';
-
-	    i = sscanf(line, "%d %d %d %n", &r, &g, &b, &pos);
-	    if (i != 3)
-		continue;
-
-	    color = line + pos;
-
-	    if (STRICMP(color, name) == 0)
-	    {
-		fclose(fd);
-		return (guicolor_T) RGB(r, g, b);
-	    }
-	}
-
-	fclose(fd);
-    }
-
-    return INVALCOLOR;
+    return gui_get_color_cmn(name);
 }
 /*
  * Return OK if the key with the termcap name "name" is supported.