# Patch created by marioluca
# Date: Fri Aug 1 16:09:12 CEST 2003
# Repository: pnetlib
# Comments:
#
# ----------------------------------------------------------------------
# Implementation of RadioButton class.
# Note that FlatStyle.Flat and FlatStyle.Popup are correct only with
# Appearance.Normal setting since DrawButton(...) does not handle Flat
# styles.
#
# Modified Files:
# System.Windows.Forms/RadioButton.cs
# System.Windows.Forms/Themes/DefaultThemePainter.cs
# samples/samples.build
# New Files:
# samples/radiobuttons.cs
# ----------------------------------------------------------------------
#### End of Preamble ####
#### Patch data follows ####
Index: System.Windows.Forms/RadioButton.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Windows.Forms/RadioButton.cs,v
retrieving revision 1.1
diff -c -r1.1 RadioButton.cs
*** System.Windows.Forms/RadioButton.cs 30 Jul 2003 17:15:14 -0000 1.1
--- System.Windows.Forms/RadioButton.cs 1 Aug 2003 14:01:20 -0000
***************
*** 1,8 ****
/*
* RadioButton.cs - Implementation of the
! * "System.Windows.Forms.RichTextBoxFinds" class.
*
! * Copyright (C) 2003 Neil Cawse.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
--- 1,11 ----
/*
* RadioButton.cs - Implementation of the
! * "System.Windows.Forms.RadioButton" class.
*
! * Copyright (C) 2003 Southern Storm Software, Pty Ltd.
! *
! * Contributions from Mario Luca Bernardi
! * ContentAligment code from Simon Guidon
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
***************
*** 18,182 ****
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
namespace System.Windows.Forms
{
! using System.Drawing;
! using System.ComponentModel;
! public class RadioButton : ButtonBase {
! Appearance appearance;
! bool autoCheck;
! ContentAlignment checkAlign;
! bool checked_;
! public RadioButton()
{
! appearance = Appearance.Normal;
! autoCheck = true;
! checkAlign = ContentAlignment.MiddleLeft;
! checked_ = false;
! TextAlign = ContentAlignment.MiddleLeft;
}
!
! public Appearance Appearance
{
! get
{
! return appearance;
}
! set
{
! if ( !Enum.IsDefined ( typeof(Appearance), value ) )
! throw new InvalidEnumArgumentException( "Appearance", (int)value, typeof(Appearance));
! if ( appearance != value ) {
! appearance = value;
!
! if ( IsHandleCreated )
! ;
! if ( AppearanceChanged != null )
! AppearanceChanged ( this, EventArgs.Empty );
}
}
- }
! public bool AutoCheck {
! get
{
! return autoCheck;
}
! set
{
! if ( autoCheck != value )
{
! autoCheck = value;
! if ( IsHandleCreated )
! ;
}
}
- }
! public ContentAlignment CheckAlign {
! get
{
! return checkAlign;
}
! set
{
! if ( !Enum.IsDefined ( typeof(ContentAlignment), value ) )
! throw new InvalidEnumArgumentException( "CheckAlign", (int)value, typeof(Appearance));
! if ( checkAlign != value ) {
! ;
}
}
}
! public bool Checked {
! get
{
! return checked_;
}
! set
{
! if ( checked_ != value )
{
! checked_ = value;
!
! UpdateCheck();
! OnCheckedChanged (EventArgs.Empty);
}
}
! }
! public override ContentAlignment TextAlign {
! get
{
! return base.TextAlign;
}
!
! set
{
! base.TextAlign = value;
}
- }
! public void PerformClick()
! {
! Checked = !Checked;
! OnClick ( EventArgs.Empty );
! }
! public override string ToString()
! {
! return GetType().FullName.ToString () + ", Checked: " + Checked.ToString ( );
! }
- public event EventHandler AppearanceChanged;
- public event EventHandler CheckedChanged;
! protected override ImeMode DefaultImeMode {
! get { return ImeMode.Disable; }
! }
- protected override Size DefaultSize {
- get { return new Size(104,24); }
- }
! protected virtual void OnCheckedChanged(EventArgs e)
! {
! if ( CheckedChanged != null )
! CheckedChanged ( this, e );
! }
! protected override void OnClick(EventArgs e)
! {
! bool check = Checked;
! if ( checked_ != check ) {
! checked_ = check;
! OnCheckedChanged ( EventArgs.Empty );
}
! base.OnClick ( e );
! }
- protected override void OnHandleCreated(EventArgs e)
- {
- base.OnHandleCreated ( e );
- UpdateCheck ( );
- }
! private void UpdateCheck ( ) {
! if ( IsHandleCreated )
! ;
! }
! }
! }
--- 21,629 ----
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+ using System;
+ using System.Drawing;
+ using System.Drawing.Drawing2D;
+ using System.ComponentModel;
+ using System.Windows.Forms;
+ using System.Windows.Forms.Themes;
namespace System.Windows.Forms
{
! public class RadioButton : ButtonBase
! {
! // ---- Private data ----------------------------------------------------//
! private Appearance appearance;
! private ContentAlignment checkAlign;
! private bool autoCheck;
! private CheckState state;
! private ImeMode defaultImeMode;
! private Size defaultSize;
! private bool justreleased;
! private int checkX;
! private int checkY;
! private int checkSize = 13;
! // ---- end of Private data ---------------------------------------------//
!
! // ---- Public contructors ----------------------------------------------//
! public RadioButton()
! {
! Appearance = Appearance.Normal;
! defaultSize = new Size(104, 24);
! Size = defaultSize;
! checkAlign = ContentAlignment.MiddleLeft;
! TextAlign = ContentAlignment.MiddleLeft;
! entered=false;
! pressed=false;
! }
! // ---- end of Public constructors --------------------------------------//
!
!
! // ---- Private Methods -------------------------------------------------//
! private void Redraw()
! {
! // Bail out if the button is not currently visible.
! if(!Visible || !IsHandleCreated)
! {
! return;
! }
!
! // Redraw the button.
! Graphics graphics = CreateGraphics();
! Draw(graphics);
! graphics.Dispose();
! }
!
! private void DrawPopupRadioButton
! (Graphics graphics, int x, int y, int width,
! int height, ButtonState state)
! {
! Color ControlAreaColor = new Color();
! Color CheckColor = new Color();
!
! if ((state & ButtonState.Flat) == 0 ) {
! // Take care of the radio background & border.
! // FlatStyle.Popup mouse over effect
!
! if ((state==ButtonState.Normal)||(state==ButtonState.Checked))
! // ControlLightLight background for ( Normal || Checked )
! ControlAreaColor = SystemColors.ControlLightLight;
! else
! // ControlLightLight background for everything else
! ControlAreaColor = SystemColors.ControlLightLight;
!
! Brush brush = new SolidBrush(ControlAreaColor);
! graphics.FillEllipse(brush, x+1 , y+1 , width-1 , width-1 );
! brush.Dispose();
!
! Pen mypen = new Pen(SystemColors.ControlLight,1);
! graphics.DrawArc(mypen,x+2,y+2,width-2,width-2,30,190);
! Pen mypen1 = new Pen(SystemColors.ControlLight,1);
! graphics.DrawArc(mypen1,x+2,y+2,width-2,width-2,220,180);
!
! Pen mypen2 = new Pen(SystemColors.ControlDark,1);
! graphics.DrawArc(mypen2,x+1,y+1,width,width,30,190);
! Pen mypen3 = new Pen(SystemColors.ControlLightLight,1);
! graphics.DrawArc(mypen3,x+1,y+1,width,width,220,180);
!
! }
! else
! {
! // Take care of background & border
! // Flat Popup Style
! state -= ButtonState.Flat;
! if ((state==ButtonState.Normal)||
! (state==ButtonState.Checked)||
! (state==ButtonState.Pushed)||
! (state==(ButtonState.Checked | ButtonState.Pushed)))
! // ControlLightLight background for ( Normal || Checked )
! ControlAreaColor = SystemColors.ControlLightLight;
! else
! // ControlLightLight background for everything else
! ControlAreaColor = SystemColors.Control;
! state |= ButtonState.Flat;
!
! Brush clear = new SolidBrush(SystemColors.Control);
! graphics.FillEllipse(clear, x-2 , y-2 , width+4 , width+4 );
! clear.Dispose();
!
! Brush brush = new SolidBrush(ControlAreaColor);
! graphics.FillEllipse(brush, x+1 , y+1 , width-1 , width-1 );
! brush.Dispose();
!
! Pen mypen = new Pen(Color.Gray,1);
! graphics.DrawArc(mypen,x+1,y+1,width-1,width-1,0,360);
! }
!
! // Take care of the radio's check ( popup style )
! if ((state & ButtonState.Checked)!=0)
! {
! if (((state & ButtonState.Inactive)!=0)||((state & ButtonState.Pushed)!=0))
! CheckColor=SystemColors.GrayText;
! else
! CheckColor=SystemColors.ControlText;
!
! Brush brush = new SolidBrush(CheckColor);
! graphics.FillEllipse(brush, x + 5, y + 5, 5, 5);
! brush.Dispose();
! }
! }
!
!
! internal new virtual ButtonState CalculateState()
! {
! ButtonState state = ButtonState.Normal;
!
! if (this.state == CheckState.Checked){
! state |= ButtonState.Checked;
! if (appearance==appearance.Button)
! state |= ButtonState.Pushed;
! }
!
! if (base.FlatStyle == FlatStyle.Flat)
! state |= ButtonState.Flat;
! if (base.FlatStyle == FlatStyle.Popup)
! state |= ButtonState.Flat;
! if(Enabled)
{
! if(entered && pressed)
! {
! state |= ButtonState.Pushed;
! if (this.FlatStyle == FlatStyle.Popup)
! state -= ButtonState.Flat;
! }
! else if(entered && ((state & ButtonState.Flat)!=0))
! {
! if (this.FlatStyle != FlatStyle.Popup)
! state |= ButtonState.Inactive;
! else
! {
! state -= ButtonState.Flat;
! }
! }
}
! else
{
! state |= ButtonState.Inactive;
! }
! return state;
! }
!
! internal override void Draw(Graphics graphics)
! {
! DrawBox(graphics);
! DrawText(graphics);
! }
!
! private void DrawBox(Graphics graphics)
{
! int checkX = 0;
! int checkY = 0;
!
! switch (checkAlign)
! {
! case ContentAlignment.BottomCenter:
! checkX = (Width / 2) - (checkSize / 2);
! checkY = Height - checkSize - 1;
! break;
! case ContentAlignment.BottomLeft:
! checkX = 0;
! checkY = Height - checkSize - 1;
! break;
! case ContentAlignment.BottomRight:
! checkX = Width - checkSize - 1;
! checkY = Height - checkSize - 1;
! break;
! case ContentAlignment.MiddleCenter:
! checkX = (Width / 2) - (checkSize / 2);
! checkY = (Height / 2) - (checkSize / 2);
! break;
! case ContentAlignment.MiddleLeft:
! checkX = 0;
! checkY = (Height / 2) - (checkSize / 2);
! break;
! case ContentAlignment.MiddleRight:
! checkX = Width - checkSize - 1;
! checkY = (Height / 2) - (checkSize / 2);
! break;
! case ContentAlignment.TopCenter:
! checkX = (Width / 2) - (checkSize / 2);
! checkY = 0;
! break;
! case ContentAlignment.TopLeft:
! checkX = 0;
! checkY = 0;
! break;
! case ContentAlignment.TopRight:
! checkX = Width - checkSize - 1;
! checkY = 0;
! break;
! }
!
! // Calculate ButtonState needed by DrawRadioButton
! ButtonState checkState = CalculateState();
! if (appearance == Appearance.Normal)
! if (this.FlatStyle != FlatStyle.Popup)
! ThemeManager.MainPainter.DrawRadioButton(graphics, checkX, checkY, checkSize, checkSize, checkState);
! else
! DrawPopupRadioButton(graphics,checkX,checkY,checkSize,checkSize,checkState);
! else
! ControlPaint.DrawButton(graphics, 0,0, Size.Width, Size.Height, checkState);
!
}
! private void DrawText(Graphics graphics)
{
! int x = 0;
! int y = 2;
! int width = Width - 2;
! int height = Height - 4;
!
! SizeF textSize = graphics.MeasureString(Text, Font);
! StringFormat format = new StringFormat();
! format.Alignment = StringAlignment.Near;
! format.LineAlignment = StringAlignment.Far;
! switch (checkAlign)
! {
! case ContentAlignment.BottomCenter:
! height = checkY + 2;
! break;
! case ContentAlignment.BottomLeft:
! x = checkX + checkSize + 3;
! width -= x;
! break;
! case ContentAlignment.BottomRight:
! width -= checkSize;
! break;
! case ContentAlignment.MiddleCenter:
! break;
! case ContentAlignment.MiddleLeft:
! x = checkX + checkSize + 3;
! width -= x;
! break;
! case ContentAlignment.MiddleRight:
! x = checkX + checkSize + 3;
! width -= x;
! break;
! case ContentAlignment.TopCenter:
! y = checkY + checkSize + 3;
! height -= y - 2;
! break;
! case ContentAlignment.TopLeft:
! x = checkX + checkSize + 3;
! width -= x;
! break;
! case ContentAlignment.TopRight:
! width -= checkSize;
! break;
! }
! switch (TextAlign)
! {
! case ContentAlignment.BottomCenter:
! format.Alignment = StringAlignment.Center;
! format.LineAlignment = StringAlignment.Far;
! break;
! case ContentAlignment.BottomLeft:
! format.Alignment = StringAlignment.Near;
! format.LineAlignment = StringAlignment.Far;
! break;
! case ContentAlignment.BottomRight:
! format.Alignment = StringAlignment.Far;
! format.LineAlignment = StringAlignment.Far;
! break;
! case ContentAlignment.MiddleCenter:
! format.Alignment = StringAlignment.Center;
! format.LineAlignment = StringAlignment.Center;
! break;
! case ContentAlignment.MiddleLeft:
! format.LineAlignment = StringAlignment.Center;
! break;
! case ContentAlignment.MiddleRight:
! format.Alignment = StringAlignment.Far;
! format.LineAlignment = StringAlignment.Center;
! break;
! case ContentAlignment.TopCenter:
! format.Alignment = StringAlignment.Center;
! format.LineAlignment = StringAlignment.Near;
! break;
! case ContentAlignment.TopLeft:
! format.Alignment = StringAlignment.Near;
! format.LineAlignment = StringAlignment.Near;
! break;
! case ContentAlignment.TopRight:
! format.Alignment = StringAlignment.Far;
! format.LineAlignment = StringAlignment.Near;
! break;
! }
! Brush brush = new SolidBrush(ForeColor);
! if (appearance == Appearance.Button) {
! x-=10;
! ButtonState radiostate = CalculateState();
! if ((radiostate & ButtonState.Pushed)!=0){
! x++;
! y++;
! }
}
+ Rectangle rect = new Rectangle(x, y, width, height);
+ graphics.DrawString(Text, Font, brush, rect, format);
+ brush.Dispose();
}
! // Set the radiobutton state - used by the toolkit in response to events.
! internal void SetCheckState(CheckState state)
{
! this.state = state;
}
!
! // Get or set the check box state.
! private CheckState CheckState
{
! get
! {
! return state;
! }
! set
{
! if(state != value)
! {
! state = value;
! }
! }
! }
!
! // ---- end of Private Methods -----------------------------------------//
!
! // ---- Public Properties ----------------------------------------------//
!
! // Gets or sets the value that determines the appearance
! // of a check box control.
! public Appearance Appearance
! {
! get
! {
! return appearance;
! }
! set
! {
! appearance = value;
}
}
! // Get or set the "auto check" style for this check box.
! public bool AutoCheck
{
! get
! {
! return autoCheck;
! }
! set
! {
! if(autoCheck != value)
! {
! autoCheck = value;
! }
! }
}
!
! // Gets or sets the horizontal and vertical alignment of a check box on a check box control.
! public ContentAlignment CheckAlign
{
! get
! {
! return checkAlign;
! }
! set
! {
! checkAlign = value;
! Invalidate();
! }
! }
! // Get or set the checked state as a simple boolean value.
! public bool Checked
! {
! get
! {
! return (CheckState != CheckState.Unchecked);
! }
! set
! {
! if(value)
! {
! CheckState = CheckState.Checked;
! }
! else
! {
! CheckState = CheckState.Unchecked;
! }
}
}
+
+
+ // Gets or sets the site of the control.
+ #if CONFIG_COMPONENT_MODEL
+ public override ISite Site
+ {
+ get
+ {
+ return base.Site;
+ }
+ set
+ {
+ base.Site = value;
}
+ }
+ #endif
! // Gets or sets the alignment of the text on the RadioButton control.
! public override ContentAlignment TextAlign
{
! get
! {
! return base.TextAlign;
! }
! set
! {
! base.TextAlign = value;
! Invalidate();
! }
}
! // ---- end of Public Properties ---------------------------------------//
!
!
! // ---- Public Methods -------------------------------------------------//
!
! public override string ToString()
! {
! return GetType().FullName.ToString () + ", Checked: " + Checked.ToString ( );
! }
!
!
! // ---- end of Public Methods ------------------------------------------//
!
!
! // ---- Public Events --------------------------------------------------//
!
! // Occurs when the value of the Appearance property changes.
! public event EventHandler AppearanceChanged;
!
! // Occurs when the value of the Checked property changes.
! public event EventHandler CheckedChanged;
!
! // ---- end of Public Events -------------------------------------------//
!
!
!
! // ---- Protected Properties -------------------------------------------//
!
! // Gets the required creation parameters when the control handle is
! // created.
! protected override CreateParams CreateParams
{
! get
{
! return base.CreateParams;
}
}
! // Gets the default Input Method Editor (IME) mode supported by this control.
! protected override ImeMode DefaultImeMode
! {
! get
! {
! return defaultImeMode;
! }
! }
! // Gets the default size of the control.
! protected override Size DefaultSize
! {
! get
! {
! return defaultSize;
! }
! }
! // ---- end of Protected Propertied ------------------------------------//
!
! // ---- Protected Methods ----------------------------------------------//
!
! // Raises the AppearanceChanged event.
! protected virtual void OnAppearanceChanged(EventArgs e)
{
! if (AppearanceChanged != null)
! AppearanceChanged(this, e);
}
!
! // Raises the CheckedChanged event.
! protected virtual void OnCheckedChanged(EventArgs e)
{
! if ( CheckedChanged != null )
! CheckedChanged ( this, e );
}
! // Raises the Click event.
! protected override void OnClick(EventArgs e)
! {
! base.OnClick(e);
! }
! // Raises the HandleCreated event.
! protected override void OnHandleCreated(EventArgs e)
! {
! base.OnHandleCreated(e);
! }
! // Override MouseEnter event from ButtonBase
! protected override void OnMouseEnter(EventArgs e) {
! entered=true;
! Redraw();
! base.OnMouseEnter(e);
! }
!
! // Override MouseLeave event from ButtonBase
! protected override void OnMouseLeave(EventArgs e) {
! entered=false;
! Redraw();
!
! base.OnMouseLeave(e);
! }
!
! protected override void OnMouseDown(MouseEventArgs e) {
! // Console.WriteLine("CheckBox::OnMouseDown");
! pressed=true;
! Redraw();
! base.OnMouseDown(e);
! }
! // Raises the MouseUp event.
! protected override void OnMouseUp(MouseEventArgs mevent)
! {
! pressed=false;
! if (state == CheckState.Unchecked)
! {
! state = CheckState.Checked;
! for (int i=0;i
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+