[Mono-winforms-list] Patch: CheckBox fixes (flatstyle and others)

John BouAntoun jba-mono@optusnet.com.au
Wed, 06 Oct 2004 20:53:03 +1000


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

Hey guys, 

Another patch from me, this one is for checkbox.

The following fixes are in this patch:

1) Fix CheckBox.Appearance setter (same as radio button)
2) Make background of checkbox be painted in window color
3) Draw flatstyle properly
4) Draw FlatStyle.Popup properly.

Note: The existing CheckBox rendering has some code to render pushed
state in it (with a hatched brush), but the checkbox should never
display the pushed state unless it's rendered as Appearance.Button, and
in that instance shouldn't the button handle the pushed state ?

Regards,

JBA

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

? CheckBoxFixes.patch
? Makefile.SWF
? Makefile.solution.SWF
? SWF.cmbx
? SWF.mdsx
? SWF.pidb
? SWF.prjx
? make.sh
Index: System.Windows.Forms/CheckBox.cs
===================================================================
RCS file: /cvs/public/mcs/class/Managed.Windows.Forms/System.Windows.Forms/CheckBox.cs,v
retrieving revision 1.7
diff -r1.7 CheckBox.cs
94c94
< 					value = appearance;
---
> 					appearance = value;
Index: System.Windows.Forms/ThemeWin32Classic.cs
===================================================================
RCS file: /cvs/public/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs,v
retrieving revision 1.41
diff -r1.41 ThemeWin32Classic.cs
580,581c580,582
< 			if (checkbox.appearance!=Appearance.Button) {
< 				ControlPaint.DrawCheckBox(dc, checkbox_rectangle, state);
---
> 			// establish if we are rendering a flat style of some sort
> 			if (checkbox.FlatStyle == FlatStyle.Flat || checkbox.FlatStyle == FlatStyle.Popup) {
> 				DrawFlatStyleCheckBox (dc, checkbox_rectangle, checkbox);
583c584,589
< 				ControlPaint.DrawButton(dc, text_rectangle, state);
---
> 				// render as per normal
> 				if (checkbox.appearance!=Appearance.Button) {
> 					ControlPaint.DrawCheckBox(dc, checkbox_rectangle, state);
> 				} else {
> 					ControlPaint.DrawButton(dc, text_rectangle, state);
> 				}
584a591,593
> 			
> 			// win32 compat - win32 seems to give the text a slight (3px) offset when rendering
> 			Rectangle inner_text_rectangle = new Rectangle (text_rectangle.X + 3, text_rectangle.Y, Math.Max (text_rectangle.Width - 3, 0), text_rectangle.Height); 
588c597
< 			dc.DrawString(checkbox.Text, checkbox.Font, sb, text_rectangle, text_format);
---
> 			dc.DrawString(checkbox.Text, checkbox.Font, sb, inner_text_rectangle, text_format);
595a605,666
> 		// renders a checkBox with the Flat and Popup FlatStyle
> 		private void DrawFlatStyleCheckBox (Graphics graphics, Rectangle rectangle, CheckBox checkbox)
> 		{
> 			Pen			pen;
> 			int			lineWidth;
> 			Rectangle	rect;
> 			int			Scale;
> 		
> 			// most of this code has been copied over from DrawFrameControl and adapted to work flatstyle
> 
> 			/* FIXME: I'm sure there's an easier way to calculate all this, but it should do for now */
> 
> 			// fill in background color
> 			graphics.FillRectangle(ResPool.GetSolidBrush (SystemColors.Window),rectangle);
> 
> 			// not sure what this is meant to do in the first place?
> 			/* Goes first, affects the background */
> /*			if ((State & DrawFrameControlStates.Pushed)!=0) {
> 				HatchBrush	hatchBrush=new HatchBrush(HatchStyle.Percent50, SystemColors.ControlLight, SystemColors.ControlLightLight);
> 				graphics.FillRectangle(hatchBrush,rectangle);
> 				hatchBrush.Dispose();
> 			}
> */
> 			/* flat style part */
> 			if (checkbox.FlatStyle == FlatStyle.Flat) {
> 				ControlPaint.DrawBorder(graphics, rectangle, SystemColors.ControlText, ButtonBorderStyle.Solid);
> 			} else {
> 				// must be popup, so if entered draw bottom right of sunken effect
> 				if (checkbox.is_entered) {
> 					// draw bottom right side
> 					CPDrawBorder3D (graphics, rectangle, Border3DStyle.SunkenInner, Border3DSide.Bottom | Border3DSide.Right);
> 					// draw top left
> 					graphics.DrawLine(SystemPens.ControlDark, rectangle.X, rectangle.Y, rectangle.X, rectangle.Y+rectangle.Height);
> 					graphics.DrawLine(SystemPens.ControlDark, rectangle.X, rectangle.Y, Math.Max(rectangle.X + rectangle.Width - 1, 0), rectangle.Y);					
> 				} else {
> 					// draw the outer border
> 					ControlPaint.DrawBorder(graphics, rectangle, SystemColors.ControlDark, ButtonBorderStyle.Solid);
> 				}
> 			}
> 
> 			/* Make sure we've got at least a line width of 1 */
> 			lineWidth=Math.Max(3, rectangle.Width/6);
> 			Scale=Math.Max(1, rectangle.Width/12);
> 
> 			rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
> 			if (checkbox.Enabled) {
> 				pen=SystemPens.ControlDark;
> 			} else {
> 				pen=SystemPens.ControlText;
> 			}
> 
> 			if (checkbox.Checked) {
> 				/* Need to draw a check-mark */
> 				for (int i=0; i<lineWidth; i++) {
> 					graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
> 					graphics.DrawLine(pen, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i, rect.Left+lineWidth/2+6*Scale, rect.Top+lineWidth-2*Scale+i);
> 				}
> 
> 			}					
> 		}
> 
> 
3067a3139,3141
> 
> 					// fill in background color
> 					graphics.FillRectangle(ResPool.GetSolidBrush (SystemColors.Window),rectangle);

--=-YbVUv5n8I5blboxdk4Qf--