[System.Drawing] Add ifdefs to source code used by Xamarin.iOS/Mac to make it compile...
[mono.git] / mcs / class / System.Drawing / System.Drawing / KnownColors.cs
index 3873df5c3e8684f547f6292718f117ee6c1df226..0440d8e30599a99504dc91416f1abaa2a5613aba 100644 (file)
 
 namespace System.Drawing {
 
-#if NET_2_0
        internal static class KnownColors {
-#else
-       internal class KnownColors {
-
-               private KnownColors ()
-               {
-               }
-#endif
+               // FindColorMatch relies on the index + 1 == KnowColor match
                static internal uint[] ArgbValues = new uint[] {
                        0x00000000,     /* 000 - Empty */
                        0xFFD4D0C8,     /* 001 - ActiveBorder */
@@ -208,7 +201,6 @@ namespace System.Drawing {
                        0xFFF5F5F5,     /* 165 - WhiteSmoke */
                        0xFFFFFF00,     /* 166 - Yellow */
                        0xFF9ACD32,     /* 167 - YellowGreen */
-#if NET_2_0
                        0xFFECE9D8,     /* 168 - ButtonFace */
                        0xFFFFFFFF,     /* 169 - ButtonHighlight */
                        0xFFACA899,     /* 170 - ButtonShadow */
@@ -216,9 +208,9 @@ namespace System.Drawing {
                        0xFF9DB9EB,     /* 172 - GradientInactiveCaption */
                        0xFFECE9D8,     /* 173 - MenuBar */
                        0xFF316AC5,     /* 174 - MenuHighlight */
-#endif
                };
 
+#if !MONOTOUCH && !MONOMAC
                static KnownColors ()
                {
                        if (GDIPlus.RunningOnWindows ()) {
@@ -265,7 +257,6 @@ namespace System.Drawing {
                        ArgbValues [(int)KnownColor.Window] = GetSysColor (GetSysColorIndex.COLOR_WINDOW);
                        ArgbValues [(int)KnownColor.WindowFrame] = GetSysColor (GetSysColorIndex.COLOR_WINDOWFRAME);
                        ArgbValues [(int)KnownColor.WindowText] = GetSysColor (GetSysColorIndex.COLOR_WINDOWTEXT);
-#if NET_2_0
                        ArgbValues [(int)KnownColor.ButtonFace] = GetSysColor (GetSysColorIndex.COLOR_BTNFACE);
                        ArgbValues [(int)KnownColor.ButtonHighlight] = GetSysColor (GetSysColorIndex.COLOR_BTNHIGHLIGHT);
                        ArgbValues [(int)KnownColor.ButtonShadow] = GetSysColor (GetSysColorIndex.COLOR_BTNSHADOW);
@@ -273,8 +264,8 @@ namespace System.Drawing {
                        ArgbValues [(int)KnownColor.GradientInactiveCaption] = GetSysColor (GetSysColorIndex.COLOR_GRADIENTINACTIVECAPTION);
                        ArgbValues [(int)KnownColor.MenuBar] = GetSysColor (GetSysColorIndex.COLOR_MENUBAR);
                        ArgbValues [(int)KnownColor.MenuHighlight] = GetSysColor (GetSysColorIndex.COLOR_MENUHIGHLIGHT);
-#endif
                }
+#endif
 
                public static Color FromKnownColor (KnownColor kc)
                {
@@ -283,9 +274,6 @@ namespace System.Drawing {
                        if ((n <= 0) || (n >= ArgbValues.Length)) {
                                // This is what it returns!
                                c = Color.FromArgb (0, 0, 0, 0);
-#if ONLY_1_1
-                               c.name = kc.ToString ();
-#endif
                                c.state |= (short) Color.ColorType.Named;
                        } else {
                                c = new Color ();
@@ -293,9 +281,6 @@ namespace System.Drawing {
                                if ((n < 27) || (n > 169))
                                        c.state |= (short) Color.ColorType.System;
                                c.Value = ArgbValues [n];
-#if ONLY_1_1
-                               c.name = GetName (n);
-#endif
                        }
                        c.knownColor = n;
                        return c;
@@ -471,7 +456,6 @@ namespace System.Drawing {
                        case 165:       return "WhiteSmoke";
                        case 166:       return "Yellow";
                        case 167:       return "YellowGreen";
-#if NET_2_0
                        case 168:       return "ButtonFace";
                        case 169:       return "ButtonHighlight";
                        case 170:       return "ButtonShadow";
@@ -479,7 +463,6 @@ namespace System.Drawing {
                        case 172:       return "GradientInactiveCaption";
                        case 173:       return "MenuBar";
                        case 174:       return "MenuHighlight";
-#endif
                        default:        return String.Empty;
                        }
                }
@@ -489,13 +472,20 @@ namespace System.Drawing {
                        return GetName ((short)kc);
                }
 
+               // FIXME: Linear scan
                public static Color FindColorMatch (Color c)
                {
                        uint argb = (uint) c.ToArgb ();
-                       for (int i = 0; i < KnownColors.ArgbValues.Length; i++) {
+                       
+                       // 1-based
+                       const int first_real_color_index = (int) KnownColor.AliceBlue;
+                       const int last_real_color_index = (int) KnownColor.YellowGreen;
+                       
+                       for (int i = first_real_color_index - 1; i < last_real_color_index; i++) {
                                if (argb == KnownColors.ArgbValues [i])
                                        return KnownColors.FromKnownColor ((KnownColor)i);
-                        }
+                       }
+                       
                        return Color.Empty;
                }