2006-12-26 Jonathan Pobst <monkey@jpobst.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ControlPaint.cs
index e6f8dc3104701286984c245b5b7a021f6dd31459..d633c8721db64938fc7edf7a54353bf3712c644e 100644 (file)
 // Authors:
 //     Peter Bartok    pbartok@novell.com
 //
-//
-// $Log: ControlPaint.cs,v $
-// Revision 1.3  2004/08/11 22:20:59  pbartok
-// - Signature fixes
-//
-// Revision 1.2  2004/07/26 17:42:03  jordi
-// Theme support
-//
-// Revision 1.1  2004/07/09 05:21:25  pbartok
-// - Initial check-in
-//
-//
+
 
 // NOT COMPLETE
 
@@ -61,14 +50,6 @@ namespace System.Windows.Forms {
                #endregion      // Private Enumerations
 
                #region Helpers
-               private static Color Win32ToColor(int Win32Color) {
-                       return(Color.FromArgb(
-                               (int)(Win32Color) & 0xff0000 >> 16,             // blue
-                               (int)(Win32Color) & 0xff00 >> 8,                // green
-                               (int)(Win32Color) & 0xff                        // red
-                       ));
-               }
-
                internal static void Color2HBS(Color color, out int h, out int l, out int s) {
                        int     r;
                        int     g;
@@ -91,7 +72,6 @@ namespace System.Windows.Forms {
                        if (cMax==cMin) {               // Achromatic
                                h=0;                                    // h undefined
                                s=0;
-                               l=r;
                                return;
                        }
 
@@ -195,38 +175,96 @@ namespace System.Windows.Forms {
                }
 
                public static Color Light(Color baseColor) {
-                       return Light( baseColor, 10.0f);
-               }
-
-               public static Color Light(Color baseColor,float percOfLightLight) {
+                       return Light(baseColor, 0.5f);
+               }
+
+               public static Color Light(Color baseColor,float per) {
+                       if (baseColor.ToArgb () == ThemeEngine.Current.ColorControl.ToArgb ()) {
+                               int r_sub, g_sub, b_sub;
+                               Color color;
+
+                               if (per <= 0f)
+                                       return ThemeEngine.Current.ColorControlLight;
+
+                               if (per == 1.0f)                                        
+                                       return ThemeEngine.Current.ColorControlLightLight;
+                               
+                               r_sub = ThemeEngine.Current.ColorControlLightLight.R - ThemeEngine.Current.ColorControlLight.R;
+                               g_sub = ThemeEngine.Current.ColorControlLightLight.G - ThemeEngine.Current.ColorControlLight.G;
+                               b_sub = ThemeEngine.Current.ColorControlLightLight.B - ThemeEngine.Current.ColorControlLight.B;
+                                                               
+                               color = Color.FromArgb (ThemeEngine.Current.ColorControlLight.A,
+                                               (int) (ThemeEngine.Current.ColorControlLight.R + (r_sub * per)),
+                                               (int) (ThemeEngine.Current.ColorControlLight.G + (g_sub * per)),
+                                               (int) (ThemeEngine.Current.ColorControlLight.B + (b_sub * per)));
+                               
+                               return color;
+                       }
+                       
                        int H, I, S;
 
                        ControlPaint.Color2HBS(baseColor, out H, out I, out S);
-                       int NewIntensity = Math.Min( 255, I + ((255*(int)percOfLightLight)/100));
-                       return ControlPaint.HBS2Color(H, NewIntensity, S);
+                       int NewIntensity =  Math.Min (255, I + (int)((255 - I) * 0.5f * per));
+                       
+                       return ControlPaint.HBS2Color(H, NewIntensity, S);                      
                }
 
-               public static Color LightLight(Color baseColor) {
-                       return Light( baseColor, 20.0f);
+               public static Color LightLight(Color baseColor) {                       
+                       return Light(baseColor, 1.0f);
                }
 
                public static Color Dark(Color baseColor) {
-                       return Dark(baseColor, 10.0f);
-               }
-
-               public static Color Dark(Color baseColor,float percOfDarkDark) {
+                       return Dark(baseColor, 0.5f);
+               }
+
+               public static Color Dark(Color baseColor,float per) {   
+
+                       if (baseColor.ToArgb () == ThemeEngine.Current.ColorControl.ToArgb ()) {
+                               
+                               int r_sub, g_sub, b_sub;
+                               Color color;
+
+                               if (per <= 0f)
+                                       return ThemeEngine.Current.ColorControlDark;
+
+                               if (per == 1.0f)
+                                       return ThemeEngine.Current.ColorControlDarkDark;
+                                                                                                       
+                               r_sub = ThemeEngine.Current.ColorControlDarkDark.R - ThemeEngine.Current.ColorControlDark.R;
+                               g_sub = ThemeEngine.Current.ColorControlDarkDark.G - ThemeEngine.Current.ColorControlDark.G;
+                               b_sub = ThemeEngine.Current.ColorControlDarkDark.B - ThemeEngine.Current.ColorControlDark.B;
+                                                               
+                               color = Color.FromArgb (ThemeEngine.Current.ColorControlDark.A,
+                                               (int) (ThemeEngine.Current.ColorControlDark.R + (r_sub * per)),
+                                               (int) (ThemeEngine.Current.ColorControlDark.G + (g_sub * per)),
+                                               (int) (ThemeEngine.Current.ColorControlDark.B + (b_sub * per)));
+                               return color;
+                       }
+               
                        int H, I, S;
-                       ControlPaint.Color2HBS(baseColor, out H, out I, out S);
-                       int NewIntensity = Math.Max(0, I - ((255*(int)percOfDarkDark) / 100));
+
+                       ControlPaint.Color2HBS(baseColor, out H, out I, out S);                 
+                       int PreIntensity = Math.Max (0, I - (int) (I * 0.333f));
+                       int NewIntensity =  Math.Max (0, PreIntensity - (int) (PreIntensity * per));
                        return ControlPaint.HBS2Color(H, NewIntensity, S);
                }
 
-               public static Color DarkDark(Color baseColor) {
-                       return Dark(baseColor, 20.0f);
+               public static Color DarkDark(Color baseColor) {                 
+                       return Dark(baseColor, 1.0f);
                }
 
                public static void DrawBorder(Graphics graphics, Rectangle bounds, Color color, ButtonBorderStyle style) {
-                       DrawBorder(graphics, bounds, color, 1, style, color, 1, style, color, 1, style, color, 1, style);
+                       int line_width_top_left = 1;
+                       int line_width_bottom_right = 1;
+                       
+                       if (style == ButtonBorderStyle.Inset)
+                               line_width_top_left = 2;
+                       if (style == ButtonBorderStyle.Outset) {
+                               line_width_bottom_right = 2;
+                               line_width_top_left = 2;
+                       }
+                       
+                       DrawBorder(graphics, bounds, color, line_width_top_left, style, color, line_width_top_left, style, color, line_width_bottom_right, style, color, line_width_bottom_right, style);
                }
 
                public static void DrawBorder( Graphics graphics, Rectangle bounds, Color leftColor, int leftWidth,
@@ -234,26 +272,26 @@ namespace System.Windows.Forms {
                        Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor, int bottomWidth,
                        ButtonBorderStyle bottomStyle) {
 
-                       ThemeEngine.Current.DrawBorder (graphics, bounds, leftColor, leftWidth,
+                       ThemeEngine.Current.CPDrawBorder (graphics, bounds, leftColor, leftWidth,
                                leftStyle, topColor, topWidth, topStyle, rightColor, rightWidth, rightStyle,
                                bottomColor, bottomWidth, bottomStyle);
                }
 
 
                public static void DrawBorder3D(Graphics graphics, Rectangle rectangle) {
-                       DrawBorder3D(graphics, rectangle, Border3DStyle.Etched, Border3DSide.All);
+                       DrawBorder3D(graphics, rectangle, Border3DStyle.Etched, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
                }
 
                public static void DrawBorder3D(Graphics graphics, Rectangle rectangle, Border3DStyle style) {
-                       DrawBorder3D(graphics, rectangle, style, Border3DSide.All);
+                       DrawBorder3D(graphics, rectangle, style, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
                }
 
                public static void DrawBorder3D(Graphics graphics, int x, int y, int width, int height) {
-                       DrawBorder3D(graphics, new Rectangle(x, y, width, height), Border3DStyle.Etched, Border3DSide.All);
+                       DrawBorder3D(graphics, new Rectangle(x, y, width, height), Border3DStyle.Etched, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
                }
 
                public static void DrawBorder3D(Graphics graphics, int x, int y, int width, int height, Border3DStyle style) {
-                       DrawBorder3D(graphics, new Rectangle(x, y, width, height), style, Border3DSide.All);
+                       DrawBorder3D(graphics, new Rectangle(x, y, width, height), style, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
                }
 
                public static void DrawBorder3D( Graphics graphics, int x, int y, int width, int height, Border3DStyle style,Border3DSide sides) {
@@ -262,7 +300,7 @@ namespace System.Windows.Forms {
 
                public static void DrawBorder3D( Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides) {
 
-                       ThemeEngine.Current.DrawBorder3D (graphics, rectangle, style, sides);
+                       ThemeEngine.Current.CPDrawBorder3D (graphics, rectangle, style, sides);
                }
 
                public static void DrawButton( Graphics graphics, int x, int y, int width, int height, ButtonState state) {
@@ -271,7 +309,7 @@ namespace System.Windows.Forms {
 
                public static void DrawButton( Graphics graphics, Rectangle rectangle, ButtonState state) {
 
-                       ThemeEngine.Current.DrawButton (graphics, rectangle, state);
+                       ThemeEngine.Current.CPDrawButton (graphics, rectangle, state);
                }
 
 
@@ -281,7 +319,7 @@ namespace System.Windows.Forms {
 
                public static void DrawCaptionButton(Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state) {
 
-                       ThemeEngine.Current.DrawCaptionButton (graphics, rectangle, button, state);
+                       ThemeEngine.Current.CPDrawCaptionButton (graphics, rectangle, button, state);
                }
 
                public static void DrawCheckBox(Graphics graphics, int x, int y, int width, int height, ButtonState state) {
@@ -290,12 +328,12 @@ namespace System.Windows.Forms {
 
                public static void DrawCheckBox(Graphics graphics, Rectangle rectangle, ButtonState state) {
 
-                       ThemeEngine.Current.DrawCheckBox (graphics, rectangle, state);
+                       ThemeEngine.Current.CPDrawCheckBox (graphics, rectangle, state);
                }
 
                public static void DrawComboButton(Graphics graphics, Rectangle rectangle, ButtonState state) {
 
-                       ThemeEngine.Current.DrawComboButton (graphics, rectangle,  state);
+                       ThemeEngine.Current.CPDrawComboButton (graphics, rectangle,  state);
                }
 
                public static void DrawComboButton(Graphics graphics, int x, int y, int width, int height, ButtonState state) {
@@ -304,41 +342,41 @@ namespace System.Windows.Forms {
 
                public static void DrawContainerGrabHandle(Graphics graphics, Rectangle bounds) {
 
-                       ThemeEngine.Current.DrawContainerGrabHandle (graphics, bounds);
+                       ThemeEngine.Current.CPDrawContainerGrabHandle (graphics, bounds);
                }
 
                public static void DrawFocusRectangle( Graphics graphics, Rectangle rectangle) {
-                       DrawFocusRectangle(graphics, rectangle, Color.White, Color.Black);
+                       DrawFocusRectangle(graphics, rectangle, SystemColors.Control, SystemColors.ControlText);
                }
 
                public static void DrawFocusRectangle( Graphics graphics, Rectangle rectangle, Color foreColor, Color backColor) {
 
-                       ThemeEngine.Current.DrawFocusRectangle (graphics, rectangle, foreColor, backColor);
+                       ThemeEngine.Current.CPDrawFocusRectangle (graphics, rectangle, foreColor, backColor);
                }
 
                public static void DrawGrabHandle(Graphics graphics, Rectangle rectangle, bool primary, bool enabled) {
 
-                       ThemeEngine.Current.DrawGrabHandle (graphics, rectangle, primary, enabled);
+                       ThemeEngine.Current.CPDrawGrabHandle (graphics, rectangle, primary, enabled);
                }
 
                public static void DrawGrid(Graphics graphics, Rectangle area, Size pixelsBetweenDots, Color backColor) {
 
-                       ThemeEngine.Current.DrawGrid (graphics, area, pixelsBetweenDots, backColor);
+                       ThemeEngine.Current.CPDrawGrid (graphics, area, pixelsBetweenDots, backColor);
                }
 
                public static void DrawImageDisabled(Graphics graphics, Image image, int x, int y, Color background) {
 
-                       ThemeEngine.Current.DrawImageDisabled (graphics, image, x, y, background);
+                       ThemeEngine.Current.CPDrawImageDisabled (graphics, image, x, y, background);
                }
 
                public static void DrawLockedFrame(Graphics graphics, Rectangle rectangle, bool primary) {
 
-                       ThemeEngine.Current.DrawLockedFrame (graphics, rectangle, primary);
+                       ThemeEngine.Current.CPDrawLockedFrame (graphics, rectangle, primary);
                }
 
                public static void DrawMenuGlyph(Graphics graphics, Rectangle rectangle, MenuGlyph glyph) {
 
-                       ThemeEngine.Current.DrawMenuGlyph (graphics, rectangle, glyph);
+                       ThemeEngine.Current.CPDrawMenuGlyph (graphics, rectangle, glyph, ThemeEngine.Current.ColorMenuText);
                }
 
                public static void DrawMenuGlyph(Graphics graphics, int x, int y, int width, int height, MenuGlyph glyph) {
@@ -360,41 +398,42 @@ namespace System.Windows.Forms {
 
                public static void DrawRadioButton(Graphics graphics, Rectangle rectangle, ButtonState state) {
 
-                       ThemeEngine.Current.DrawRadioButton (graphics, rectangle, state);
+                       ThemeEngine.Current.CPDrawRadioButton (graphics, rectangle, state);
                }
 
-               [MonoTODO("Figure out a good System.Drawing way for XOR drawing")]
                public static void DrawReversibleFrame(Rectangle rectangle, Color backColor, FrameStyle style) {
-                       throw new NotImplementedException();
+                       XplatUI.DrawReversibleFrame (rectangle, backColor, style);
                }
 
-               [MonoTODO("Figure out a good System.Drawing way for XOR drawing")]
                public static void DrawReversibleLine(Point start, Point end, Color backColor) {
-                       throw new NotImplementedException();
+                       XplatUI.DrawReversibleLine (start, end, backColor);
                }
 
-               [MonoTODO("Figure out a good System.Drawing way for XOR drawing")]
                public static void FillReversibleRectangle(Rectangle rectangle, Color backColor) {
-                       throw new NotImplementedException();
+                       XplatUI.FillReversibleRectangle (rectangle, backColor);
                }
 
-
                public static void DrawScrollButton (Graphics graphics, int x, int y, int width, int height, ScrollButton button, ButtonState state) {
-                       ThemeEngine.Current.DrawScrollButton (graphics, new Rectangle(x, y, width, height), button, state);
+                       ThemeEngine.Current.CPDrawScrollButton (graphics, new Rectangle(x, y, width, height), button, state);
                }
 
                public static void DrawScrollButton (Graphics graphics, Rectangle rectangle, ScrollButton button, ButtonState state) {
-                       ThemeEngine.Current.DrawScrollButton (graphics, rectangle, button, state);
+                       ThemeEngine.Current.CPDrawScrollButton (graphics, rectangle, button, state);
                }
 
                [MonoTODO]
+               private static bool DSFNotImpl = false;
                public static void DrawSelectionFrame(Graphics graphics, bool active, Rectangle outsideRect, Rectangle insideRect, Color backColor) {
-                       throw new NotImplementedException();
+                       if (!DSFNotImpl) {
+                               DSFNotImpl = true;
+                               Console.WriteLine("NOT IMPLEMENTED: DrawSelectionFrame(Graphics graphics, bool active, Rectangle outsideRect, Rectangle insideRect, Color backColor)");
+                       }
+                       //throw new NotImplementedException();
                }
 
                public static void DrawSizeGrip (Graphics graphics, Color backColor, Rectangle bounds)
                {
-                       ThemeEngine.Current.DrawSizeGrip (graphics,  backColor,  bounds);
+                       ThemeEngine.Current.CPDrawSizeGrip (graphics,  backColor,  bounds);
                }
 
                public static void DrawSizeGrip(Graphics graphics, Color backColor, int x, int y, int width, int height) {
@@ -403,7 +442,7 @@ namespace System.Windows.Forms {
 
                public static void DrawStringDisabled(Graphics graphics, string s, Font font, Color color, RectangleF layoutRectangle, StringFormat format) {
 
-                       ThemeEngine.Current.DrawStringDisabled (graphics, s, font, color, layoutRectangle, format);
+                       ThemeEngine.Current.CPDrawStringDisabled (graphics, s, font, color, layoutRectangle, format);
                }
                #endregion      // Public Static Methods
        }