[prev in list] [next in list] [prev in thread] [next in thread]
List: mono-winforms-list
Subject: Re: [Mono-winforms-list] Patch (diff -u): CheckBox fixes
From: John BouAntoun <jba-mono () optusnet ! com ! au>
Date: 2004-10-06 11:04:07
Message-ID: 1097060647.4131.7.camel () localhost ! localdomain
[Download RAW message or body]
This time with the patch created with diff -u
On Wed, 2004-10-06 at 20:53 +1000, John BouAntoun wrote:
> 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
["CheckBoxFixes.patch" (CheckBoxFixes.patch)]
? 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 -u -r1.7 CheckBox.cs
--- System.Windows.Forms/CheckBox.cs 28 Sep 2004 18:44:25 -0000 1.7
+++ System.Windows.Forms/CheckBox.cs 6 Oct 2004 09:45:45 -0000
@@ -91,7 +91,7 @@
set {
if (value != appearance) {
- value = appearance;
+ appearance = value;
if (AppearanceChanged != null) {
AppearanceChanged(this, EventArgs.Empty);
}
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 -u -r1.41 ThemeWin32Classic.cs
--- System.Windows.Forms/ThemeWin32Classic.cs 5 Oct 2004 16:15:30 -0000 1.41
+++ System.Windows.Forms/ThemeWin32Classic.cs 6 Oct 2004 09:45:47 -0000
@@ -577,15 +577,24 @@
dc.FillRectangle(sb, checkbox.ClientRectangle);
sb.Dispose();
- 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);
} else {
- 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);
+ }
}
+
+ // 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);
/* Place the text; to be compatible with Windows place it after the checkbox has \
been drawn */ sb=new SolidBrush(checkbox.ForeColor);
- dc.DrawString(checkbox.Text, checkbox.Font, sb, text_rectangle, text_format);
+ dc.DrawString(checkbox.Text, checkbox.Font, sb, inner_text_rectangle, \
text_format); sb.Dispose();
if (checkbox.Focused) {
@@ -593,6 +602,68 @@
}
}
+ // 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); + }
+
+ }
+ }
+
+
#endregion // CheckBox
#region GroupBox
@@ -3065,6 +3136,9 @@
int lineWidth;
Rectangle rect;
int Scale;
+
+ // fill in background color
+ graphics.FillRectangle(ResPool.GetSolidBrush (SystemColors.Window),rectangle);
/* FIXME: I'm sure there's an easier way to calculate all this, but it should \
do for now */
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic