Пример #1
0
 private static void EnsureColorTable()
 {
     if (KnownColorTable.colorTable == null)
     {
         KnownColorTable.InitColorTable();
     }
 }
Пример #2
0
 public static string KnownColorToName(KnownColor color)
 {
     KnownColorTable.EnsureColorNameTable();
     if (color <= KnownColor.MenuHighlight)
     {
         return(KnownColorTable.colorNameTable[(int)color]);
     }
     return(null);
 }
Пример #3
0
 public static int KnownColorToArgb(KnownColor color)
 {
     KnownColorTable.EnsureColorTable();
     if (color <= KnownColor.MenuHighlight)
     {
         return(KnownColorTable.colorTable[(int)color]);
     }
     return(0);
 }
Пример #4
0
 public static Color ArgbToKnownColor(int targetARGB)
 {
     KnownColorTable.EnsureColorTable();
     for (int i = 0; i < KnownColorTable.colorTable.Length; i++)
     {
         if (KnownColorTable.colorTable[i] == targetARGB)
         {
             Color result = Color.FromKnownColor((KnownColor)i);
             if (!result.IsSystemColor)
             {
                 return(result);
             }
         }
     }
     return(Color.FromArgb(targetARGB));
 }
Пример #5
0
 private static void UpdateSystemColors(int[] colorTable)
 {
     colorTable[1]   = KnownColorTable.SystemColorToArgb(10);
     colorTable[2]   = KnownColorTable.SystemColorToArgb(2);
     colorTable[3]   = KnownColorTable.SystemColorToArgb(9);
     colorTable[4]   = KnownColorTable.SystemColorToArgb(12);
     colorTable[168] = KnownColorTable.SystemColorToArgb(15);
     colorTable[169] = KnownColorTable.SystemColorToArgb(20);
     colorTable[170] = KnownColorTable.SystemColorToArgb(16);
     colorTable[5]   = KnownColorTable.SystemColorToArgb(15);
     colorTable[6]   = KnownColorTable.SystemColorToArgb(16);
     colorTable[7]   = KnownColorTable.SystemColorToArgb(21);
     colorTable[8]   = KnownColorTable.SystemColorToArgb(22);
     colorTable[9]   = KnownColorTable.SystemColorToArgb(20);
     colorTable[10]  = KnownColorTable.SystemColorToArgb(18);
     colorTable[11]  = KnownColorTable.SystemColorToArgb(1);
     colorTable[171] = KnownColorTable.SystemColorToArgb(27);
     colorTable[172] = KnownColorTable.SystemColorToArgb(28);
     colorTable[12]  = KnownColorTable.SystemColorToArgb(17);
     colorTable[13]  = KnownColorTable.SystemColorToArgb(13);
     colorTable[14]  = KnownColorTable.SystemColorToArgb(14);
     colorTable[15]  = KnownColorTable.SystemColorToArgb(26);
     colorTable[16]  = KnownColorTable.SystemColorToArgb(11);
     colorTable[17]  = KnownColorTable.SystemColorToArgb(3);
     colorTable[18]  = KnownColorTable.SystemColorToArgb(19);
     colorTable[19]  = KnownColorTable.SystemColorToArgb(24);
     colorTable[20]  = KnownColorTable.SystemColorToArgb(23);
     colorTable[21]  = KnownColorTable.SystemColorToArgb(4);
     colorTable[173] = KnownColorTable.SystemColorToArgb(30);
     colorTable[174] = KnownColorTable.SystemColorToArgb(29);
     colorTable[22]  = KnownColorTable.SystemColorToArgb(7);
     colorTable[23]  = KnownColorTable.SystemColorToArgb(0);
     colorTable[24]  = KnownColorTable.SystemColorToArgb(5);
     colorTable[25]  = KnownColorTable.SystemColorToArgb(6);
     colorTable[26]  = KnownColorTable.SystemColorToArgb(8);
 }
        public static Color FromOle(int oleColor)
        {
            if (((oleColor & ((int)0xff000000L)) == -2147483648) && ((oleColor & 0xffffff) <= 30))
            {
                switch (oleColor)
                {
                case -2147483648:
                    return(Color.FromKnownColor(KnownColor.ScrollBar));

                case -2147483647:
                    return(Color.FromKnownColor(KnownColor.Desktop));

                case -2147483646:
                    return(Color.FromKnownColor(KnownColor.ActiveCaption));

                case -2147483645:
                    return(Color.FromKnownColor(KnownColor.InactiveCaption));

                case -2147483644:
                    return(Color.FromKnownColor(KnownColor.Menu));

                case -2147483643:
                    return(Color.FromKnownColor(KnownColor.Window));

                case -2147483642:
                    return(Color.FromKnownColor(KnownColor.WindowFrame));

                case -2147483641:
                    return(Color.FromKnownColor(KnownColor.MenuText));

                case -2147483640:
                    return(Color.FromKnownColor(KnownColor.WindowText));

                case -2147483639:
                    return(Color.FromKnownColor(KnownColor.ActiveCaptionText));

                case -2147483638:
                    return(Color.FromKnownColor(KnownColor.ActiveBorder));

                case -2147483637:
                    return(Color.FromKnownColor(KnownColor.InactiveBorder));

                case -2147483636:
                    return(Color.FromKnownColor(KnownColor.AppWorkspace));

                case -2147483635:
                    return(Color.FromKnownColor(KnownColor.Highlight));

                case -2147483634:
                    return(Color.FromKnownColor(KnownColor.HighlightText));

                case -2147483633:
                    return(Color.FromKnownColor(KnownColor.Control));

                case -2147483632:
                    return(Color.FromKnownColor(KnownColor.ControlDark));

                case -2147483631:
                    return(Color.FromKnownColor(KnownColor.GrayText));

                case -2147483630:
                    return(Color.FromKnownColor(KnownColor.ControlText));

                case -2147483629:
                    return(Color.FromKnownColor(KnownColor.InactiveCaptionText));

                case -2147483628:
                    return(Color.FromKnownColor(KnownColor.ControlLightLight));

                case -2147483627:
                    return(Color.FromKnownColor(KnownColor.ControlDarkDark));

                case -2147483626:
                    return(Color.FromKnownColor(KnownColor.ControlLight));

                case -2147483625:
                    return(Color.FromKnownColor(KnownColor.InfoText));

                case -2147483624:
                    return(Color.FromKnownColor(KnownColor.Info));

                case -2147483622:
                    return(Color.FromKnownColor(KnownColor.HotTrack));

                case -2147483621:
                    return(Color.FromKnownColor(KnownColor.GradientActiveCaption));

                case -2147483620:
                    return(Color.FromKnownColor(KnownColor.GradientInactiveCaption));

                case -2147483619:
                    return(Color.FromKnownColor(KnownColor.MenuHighlight));

                case -2147483618:
                    return(Color.FromKnownColor(KnownColor.MenuBar));
                }
            }
            return(KnownColorTable.ArgbToKnownColor(Color.FromArgb((byte)(oleColor & 0xff), (byte)((oleColor >> 8) & 0xff), (byte)((oleColor >> 0x10) & 0xff)).ToArgb()));
        }
Пример #7
0
        /// <summary>
        /// Translates an Ole color value to a GDI+ <see cref='Color'/>.
        /// </summary>
        public static Color FromOle(int oleColor)
        {
            // IMPORTANT: This signature is invoked directly by the runtime marshaler and cannot change without
            // also updating the runtime.

            if ((oleColor & OleSystemColorFlag) != 0)
            {
                switch (oleColor)
                {
                case unchecked ((int)0x8000000A):
                    return(Color.FromKnownColor(KnownColor.ActiveBorder));

                case unchecked ((int)0x80000002):
                    return(Color.FromKnownColor(KnownColor.ActiveCaption));

                case unchecked ((int)0x80000009):
                    return(Color.FromKnownColor(KnownColor.ActiveCaptionText));

                case unchecked ((int)0x8000000C):
                    return(Color.FromKnownColor(KnownColor.AppWorkspace));

                case unchecked ((int)0x8000000F):
                    return(Color.FromKnownColor(KnownColor.Control));

                case unchecked ((int)0x80000010):
                    return(Color.FromKnownColor(KnownColor.ControlDark));

                case unchecked ((int)0x80000015):
                    return(Color.FromKnownColor(KnownColor.ControlDarkDark));

                case unchecked ((int)0x80000016):
                    return(Color.FromKnownColor(KnownColor.ControlLight));

                case unchecked ((int)0x80000014):
                    return(Color.FromKnownColor(KnownColor.ControlLightLight));

                case unchecked ((int)0x80000012):
                    return(Color.FromKnownColor(KnownColor.ControlText));

                case unchecked ((int)0x80000001):
                    return(Color.FromKnownColor(KnownColor.Desktop));

                case unchecked ((int)0x8000001B):
                    return(Color.FromKnownColor(KnownColor.GradientActiveCaption));

                case unchecked ((int)0x8000001C):
                    return(Color.FromKnownColor(KnownColor.GradientInactiveCaption));

                case unchecked ((int)0x80000011):
                    return(Color.FromKnownColor(KnownColor.GrayText));

                case unchecked ((int)0x8000000D):
                    return(Color.FromKnownColor(KnownColor.Highlight));

                case unchecked ((int)0x8000000E):
                    return(Color.FromKnownColor(KnownColor.HighlightText));

                case unchecked ((int)0x8000001A):
                    return(Color.FromKnownColor(KnownColor.HotTrack));

                case unchecked ((int)0x8000000B):
                    return(Color.FromKnownColor(KnownColor.InactiveBorder));

                case unchecked ((int)0x80000003):
                    return(Color.FromKnownColor(KnownColor.InactiveCaption));

                case unchecked ((int)0x80000013):
                    return(Color.FromKnownColor(KnownColor.InactiveCaptionText));

                case unchecked ((int)0x80000018):
                    return(Color.FromKnownColor(KnownColor.Info));

                case unchecked ((int)0x80000017):
                    return(Color.FromKnownColor(KnownColor.InfoText));

                case unchecked ((int)0x80000004):
                    return(Color.FromKnownColor(KnownColor.Menu));

                case unchecked ((int)0x8000001E):
                    return(Color.FromKnownColor(KnownColor.MenuBar));

                case unchecked ((int)0x8000001D):
                    return(Color.FromKnownColor(KnownColor.MenuHighlight));

                case unchecked ((int)0x80000007):
                    return(Color.FromKnownColor(KnownColor.MenuText));

                case unchecked ((int)0x80000000):
                    return(Color.FromKnownColor(KnownColor.ScrollBar));

                case unchecked ((int)0x80000005):
                    return(Color.FromKnownColor(KnownColor.Window));

                case unchecked ((int)0x80000006):
                    return(Color.FromKnownColor(KnownColor.WindowFrame));

                case unchecked ((int)0x80000008):
                    return(Color.FromKnownColor(KnownColor.WindowText));
                }
            }

            // When we don't find a system color, we treat the color as a COLORREF
            return(KnownColorTable.ArgbToKnownColor(COLORREFToARGB((uint)oleColor)));
        }
        /// <summary>
        /// Translates an Ole color value to a GDI+ <see cref='Color'/>.
        /// </summary>
        public static Color FromOle(int oleColor)
        {
            //    WARNING!!! WARNING!!! WARNING!!! WARNING!!!
            //    WARNING!!! WARNING!!! WARNING!!! WARNING!!!
            //    We must never have another method called ToOle() with a different signature.
            //    This is so that we can push into the runtime a custom marshaller for OLE_COLOR to Color.

            switch (oleColor)
            {
            case unchecked ((int)0x8000000A):
                return(ColorUtil.FromKnownColor(KnownColor.ActiveBorder));

            case unchecked ((int)0x80000002):
                return(ColorUtil.FromKnownColor(KnownColor.ActiveCaption));

            case unchecked ((int)0x80000009):
                return(ColorUtil.FromKnownColor(KnownColor.ActiveCaptionText));

            case unchecked ((int)0x8000000C):
                return(ColorUtil.FromKnownColor(KnownColor.AppWorkspace));

            case unchecked ((int)0x8000000F):
                return(ColorUtil.FromKnownColor(KnownColor.Control));

            case unchecked ((int)0x80000010):
                return(ColorUtil.FromKnownColor(KnownColor.ControlDark));

            case unchecked ((int)0x80000015):
                return(ColorUtil.FromKnownColor(KnownColor.ControlDarkDark));

            case unchecked ((int)0x80000016):
                return(ColorUtil.FromKnownColor(KnownColor.ControlLight));

            case unchecked ((int)0x80000014):
                return(ColorUtil.FromKnownColor(KnownColor.ControlLightLight));

            case unchecked ((int)0x80000012):
                return(ColorUtil.FromKnownColor(KnownColor.ControlText));

            case unchecked ((int)0x80000001):
                return(ColorUtil.FromKnownColor(KnownColor.Desktop));

            case unchecked ((int)0x8000001B):
                return(ColorUtil.FromKnownColor(KnownColor.GradientActiveCaption));

            case unchecked ((int)0x8000001C):
                return(ColorUtil.FromKnownColor(KnownColor.GradientInactiveCaption));

            case unchecked ((int)0x80000011):
                return(ColorUtil.FromKnownColor(KnownColor.GrayText));

            case unchecked ((int)0x8000000D):
                return(ColorUtil.FromKnownColor(KnownColor.Highlight));

            case unchecked ((int)0x8000000E):
                return(ColorUtil.FromKnownColor(KnownColor.HighlightText));

            case unchecked ((int)0x8000001A):
                return(ColorUtil.FromKnownColor(KnownColor.HotTrack));

            case unchecked ((int)0x8000000B):
                return(ColorUtil.FromKnownColor(KnownColor.InactiveBorder));

            case unchecked ((int)0x80000003):
                return(ColorUtil.FromKnownColor(KnownColor.InactiveCaption));

            case unchecked ((int)0x80000013):
                return(ColorUtil.FromKnownColor(KnownColor.InactiveCaptionText));

            case unchecked ((int)0x80000018):
                return(ColorUtil.FromKnownColor(KnownColor.Info));

            case unchecked ((int)0x80000017):
                return(ColorUtil.FromKnownColor(KnownColor.InfoText));

            case unchecked ((int)0x80000004):
                return(ColorUtil.FromKnownColor(KnownColor.Menu));

            case unchecked ((int)0x8000001E):
                return(ColorUtil.FromKnownColor(KnownColor.MenuBar));

            case unchecked ((int)0x8000001D):
                return(ColorUtil.FromKnownColor(KnownColor.MenuHighlight));

            case unchecked ((int)0x80000007):
                return(ColorUtil.FromKnownColor(KnownColor.MenuText));

            case unchecked ((int)0x80000000):
                return(ColorUtil.FromKnownColor(KnownColor.ScrollBar));

            case unchecked ((int)0x80000005):
                return(ColorUtil.FromKnownColor(KnownColor.Window));

            case unchecked ((int)0x80000006):
                return(ColorUtil.FromKnownColor(KnownColor.WindowFrame));

            case unchecked ((int)0x80000008):
                return(ColorUtil.FromKnownColor(KnownColor.WindowText));
            }

            Color color = Color.FromArgb((byte)((oleColor >> Win32RedShift) & 0xFF),
                                         (byte)((oleColor >> Win32GreenShift) & 0xFF),
                                         (byte)((oleColor >> Win32BlueShift) & 0xFF));

            return(KnownColorTable.ArgbToKnownColor(color.ToArgb()));
        }
Пример #9
0
 private static void InitColorTable()
 {
     int[] arg_1B_0 = new int[175];
     KnownColorTable.UpdateSystemColors(arg_1B_0);
     arg_1B_0[27]  = 16777215;
     arg_1B_0[28]  = -984833;
     arg_1B_0[29]  = -332841;
     arg_1B_0[30]  = -16711681;
     arg_1B_0[31]  = -8388652;
     arg_1B_0[32]  = -983041;
     arg_1B_0[33]  = -657956;
     arg_1B_0[34]  = -6972;
     arg_1B_0[35]  = -16777216;
     arg_1B_0[36]  = -5171;
     arg_1B_0[37]  = -16776961;
     arg_1B_0[38]  = -7722014;
     arg_1B_0[39]  = -5952982;
     arg_1B_0[40]  = -2180985;
     arg_1B_0[41]  = -10510688;
     arg_1B_0[42]  = -8388864;
     arg_1B_0[43]  = -2987746;
     arg_1B_0[44]  = -32944;
     arg_1B_0[45]  = -10185235;
     arg_1B_0[46]  = -1828;
     arg_1B_0[47]  = -2354116;
     arg_1B_0[48]  = -16711681;
     arg_1B_0[49]  = -16777077;
     arg_1B_0[50]  = -16741493;
     arg_1B_0[51]  = -4684277;
     arg_1B_0[52]  = -5658199;
     arg_1B_0[53]  = -16751616;
     arg_1B_0[54]  = -4343957;
     arg_1B_0[55]  = -7667573;
     arg_1B_0[56]  = -11179217;
     arg_1B_0[57]  = -29696;
     arg_1B_0[58]  = -6737204;
     arg_1B_0[59]  = -7667712;
     arg_1B_0[60]  = -1468806;
     arg_1B_0[61]  = -7357301;
     arg_1B_0[62]  = -12042869;
     arg_1B_0[63]  = -13676721;
     arg_1B_0[64]  = -16724271;
     arg_1B_0[65]  = -7077677;
     arg_1B_0[66]  = -60269;
     arg_1B_0[67]  = -16728065;
     arg_1B_0[68]  = -9868951;
     arg_1B_0[69]  = -14774017;
     arg_1B_0[70]  = -5103070;
     arg_1B_0[71]  = -1296;
     arg_1B_0[72]  = -14513374;
     arg_1B_0[73]  = -65281;
     arg_1B_0[74]  = -2302756;
     arg_1B_0[75]  = -460545;
     arg_1B_0[76]  = -10496;
     arg_1B_0[77]  = -2448096;
     arg_1B_0[78]  = -8355712;
     arg_1B_0[79]  = -16744448;
     arg_1B_0[80]  = -5374161;
     arg_1B_0[81]  = -983056;
     arg_1B_0[82]  = -38476;
     arg_1B_0[83]  = -3318692;
     arg_1B_0[84]  = -11861886;
     arg_1B_0[85]  = -16;
     arg_1B_0[86]  = -989556;
     arg_1B_0[87]  = -1644806;
     arg_1B_0[88]  = -3851;
     arg_1B_0[89]  = -8586240;
     arg_1B_0[90]  = -1331;
     arg_1B_0[91]  = -5383962;
     arg_1B_0[92]  = -1015680;
     arg_1B_0[93]  = -2031617;
     arg_1B_0[94]  = -329006;
     arg_1B_0[95]  = -2894893;
     arg_1B_0[96]  = -7278960;
     arg_1B_0[97]  = -18751;
     arg_1B_0[98]  = -24454;
     arg_1B_0[99]  = -14634326;
     arg_1B_0[100] = -7876870;
     arg_1B_0[101] = -8943463;
     arg_1B_0[102] = -5192482;
     arg_1B_0[103] = -32;
     arg_1B_0[104] = -16711936;
     arg_1B_0[105] = -13447886;
     arg_1B_0[106] = -331546;
     arg_1B_0[107] = -65281;
     arg_1B_0[108] = -8388608;
     arg_1B_0[109] = -10039894;
     arg_1B_0[110] = -16777011;
     arg_1B_0[111] = -4565549;
     arg_1B_0[112] = -7114533;
     arg_1B_0[113] = -12799119;
     arg_1B_0[114] = -8689426;
     arg_1B_0[115] = -16713062;
     arg_1B_0[116] = -12004916;
     arg_1B_0[117] = -3730043;
     arg_1B_0[118] = -15132304;
     arg_1B_0[119] = -655366;
     arg_1B_0[120] = -6943;
     arg_1B_0[121] = -6987;
     arg_1B_0[122] = -8531;
     arg_1B_0[123] = -16777088;
     arg_1B_0[124] = -133658;
     arg_1B_0[125] = -8355840;
     arg_1B_0[126] = -9728477;
     arg_1B_0[127] = -23296;
     arg_1B_0[128] = -47872;
     arg_1B_0[129] = -2461482;
     arg_1B_0[130] = -1120086;
     arg_1B_0[131] = -6751336;
     arg_1B_0[132] = -5247250;
     arg_1B_0[133] = -2396013;
     arg_1B_0[134] = -4139;
     arg_1B_0[135] = -9543;
     arg_1B_0[136] = -3308225;
     arg_1B_0[137] = -16181;
     arg_1B_0[138] = -2252579;
     arg_1B_0[139] = -5185306;
     arg_1B_0[140] = -8388480;
     arg_1B_0[141] = -65536;
     arg_1B_0[142] = -4419697;
     arg_1B_0[143] = -12490271;
     arg_1B_0[144] = -7650029;
     arg_1B_0[145] = -360334;
     arg_1B_0[146] = -744352;
     arg_1B_0[147] = -13726889;
     arg_1B_0[148] = -2578;
     arg_1B_0[149] = -6270419;
     arg_1B_0[150] = -4144960;
     arg_1B_0[151] = -7876885;
     arg_1B_0[152] = -9807155;
     arg_1B_0[153] = -9404272;
     arg_1B_0[154] = -1286;
     arg_1B_0[155] = -16711809;
     arg_1B_0[156] = -12156236;
     arg_1B_0[157] = -2968436;
     arg_1B_0[158] = -16744320;
     arg_1B_0[159] = -2572328;
     arg_1B_0[160] = -40121;
     arg_1B_0[161] = -12525360;
     arg_1B_0[162] = -1146130;
     arg_1B_0[163] = -663885;
     arg_1B_0[164] = -1;
     arg_1B_0[165] = -657931;
     arg_1B_0[166] = -256;
     arg_1B_0[167] = -6632142;
     KnownColorTable.colorTable = arg_1B_0;
 }
Пример #10
0
 private static int FromWin32Value(int value)
 {
     return(KnownColorTable.Encode(255, value & 255, value >> 8 & 255, value >> 16 & 255));
 }