[Mono-winforms-list] Patch: Overload CPDrawBorder3D to receive a backcolor

John BouAntoun jba-mono@optusnet.com.au
Mon, 11 Oct 2004 14:53:27 +1000


--=-ObKW9kX32P2XZojoiryo
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi guys,

Not sure if this patch is correct, but here's the reasoning behind it.

For CheckBox FlatStyle.Popup I needed to render a sunken border using
the backcolor of the checkbox, not SystemColors.Control,
SystemColors.ControlDark and so on.

So I rewrote CPDrawBorder3d so that it replaced things like:

SystemColors.ControlDark 

with

ControlPaint.Dark(backColor)

and made it receive a Color parameter called backColor.

I also add a method with the same signature as old CPDrawBorder3D that
simply passed the color SystemColors.Control into the new CPDrawBorder3D
method so that the current use of the method has (hopefully) not
changed.

This is based on the assumption that SystemColors.ControlDark is the
same as ControlPaint.Dark(SystemColors.Control). Is that assumption
correct ?

Anyhow I have made the patch and am sending it through now.

If this gets applied please let me know so I can make the one line
change to the checkbox rendering so that it can call the new
CPDrawBorder3d method.

JBA

--=-ObKW9kX32P2XZojoiryo
Content-Disposition: attachment; filename=CPDrawBorder3DOverload.patch
Content-Type: text/x-patch; name=CPDrawBorder3DOverload.patch; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Index: System.Windows.Forms/ThemeWin32Classic.cs
===================================================================
RCS file: /cvs/public/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs,v
retrieving revision 1.43
diff -u -r1.43 ThemeWin32Classic.cs
--- System.Windows.Forms/ThemeWin32Classic.cs	7 Oct 2004 14:56:51 -0000	1.43
+++ System.Windows.Forms/ThemeWin32Classic.cs	11 Oct 2004 03:25:05 -0000
@@ -2032,8 +2139,13 @@
 			DrawBorderInternal(graphics, bounds.Right-1, bounds.Top, bounds.Right-1, bounds.Bottom-1, rightWidth, rightColor, rightStyle, Border3DSide.Right);
 			DrawBorderInternal(graphics, bounds.Left, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1, bottomWidth, bottomColor, bottomStyle, Border3DSide.Bottom);
 		}
-
+		
+		// overload that receives no back color and uses SystemColors.Control as default
 		public override void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides) {
+			CPDrawBorder3D(graphics, rectangle, style, sides, SystemColors.Control);
+		}
+
+		public virtual void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides, Color backColor) {
 			Pen			penTopLeft;
 			Pen			penTopLeftInner;
 			Pen			penBottomRight;
@@ -2049,20 +2161,20 @@
 			}
 
 			/* default to flat */
-			penTopLeft=SystemPens.ControlDark;
-			penTopLeftInner=SystemPens.ControlDark;
-			penBottomRight=SystemPens.ControlDark;
-			penBottomRightInner=SystemPens.ControlDark;
+			penTopLeft=ResPool.GetPen(ControlPaint.Dark(backColor));
+			penTopLeftInner=ResPool.GetPen(ControlPaint.Dark(backColor));
+			penBottomRight=ResPool.GetPen(ControlPaint.Dark(backColor));
+			penBottomRightInner=ResPool.GetPen(ControlPaint.Dark(backColor));
 
 			if ((style & Border3DStyle.RaisedOuter)!=0) {
-				penTopLeft=SystemPens.ControlLightLight;
-				penBottomRight=SystemPens.ControlDarkDark;
+				penTopLeft=ResPool.GetPen(ControlPaint.LightLight(backColor));
+				penBottomRight=ResPool.GetPen(ControlPaint.DarkDark(backColor));
 				if ((style & (Border3DStyle.RaisedInner | Border3DStyle.SunkenInner))!=0) {
 					doInner=true;
 				}
 			} else if ((style & Border3DStyle.SunkenOuter)!=0) {
-				penTopLeft=SystemPens.ControlDarkDark;
-				penBottomRight=SystemPens.ControlLightLight;
+				penTopLeft=ResPool.GetPen(ControlPaint.DarkDark(backColor));
+				penBottomRight=ResPool.GetPen(ControlPaint.LightLight(backColor));
 				if ((style & (Border3DStyle.RaisedInner | Border3DStyle.SunkenInner))!=0) {
 					doInner=true;
 				}
@@ -2070,24 +2182,24 @@
 
 			if ((style & Border3DStyle.RaisedInner)!=0) {
 				if (doInner) {
-					penTopLeftInner=SystemPens.ControlLight;
-					penBottomRightInner=SystemPens.ControlDark;
+					penTopLeftInner=ResPool.GetPen(ControlPaint.Light(backColor));
+					penBottomRightInner=ResPool.GetPen(ControlPaint.Dark(backColor));
 				} else {
-					penTopLeft=SystemPens.ControlLightLight;
-					penBottomRight=SystemPens.ControlDarkDark;
+					penTopLeft=ResPool.GetPen(ControlPaint.LightLight(backColor));
+					penBottomRight=ResPool.GetPen(ControlPaint.DarkDark(backColor));
 				}
 			} else if ((style & Border3DStyle.SunkenInner)!=0) {
 				if (doInner) {
-					penTopLeftInner=SystemPens.ControlDark;
-					penBottomRightInner=SystemPens.ControlLight;
+					penTopLeftInner=ResPool.GetPen(ControlPaint.Dark(backColor));
+					penBottomRightInner=ResPool.GetPen(ControlPaint.Light(backColor));
 				} else {
-					penTopLeft=SystemPens.ControlDarkDark;
-					penBottomRight=SystemPens.ControlLightLight;
+					penTopLeft=ResPool.GetPen(ControlPaint.DarkDark(backColor));
+					penBottomRight=ResPool.GetPen(ControlPaint.LightLight(backColor));
 				}
 			}
 
 			if ((sides & Border3DSide.Middle)!=0) {
-				graphics.FillRectangle(SystemBrushes.Control, rect);
+				graphics.FillRectangle(ResPool.GetSolidBrush(backColor), rect);
 			}
 
 			if ((sides & Border3DSide.Left)!=0) {
--=-ObKW9kX32P2XZojoiryo--