dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/System.Windows.Forms ButtonBase.cs, 1


From: Richard Baumann <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/System.Windows.Forms ButtonBase.cs, 1.7, 1.8 ControlPaint.cs, 1.10, 1.11 RadioButton.cs, 1.1, 1.2
Date: Sun, 03 Aug 2003 15:21:19 -0400

Update of /cvsroot/dotgnu-pnet/pnetlib/System.Windows.Forms
In directory subversions:/tmp/cvs-serv2885/System.Windows.Forms

Modified Files:
        ButtonBase.cs ControlPaint.cs RadioButton.cs 
Log Message:
Apply cleaned up and reviewed savannah patch #1785, "RadioButton 
Implementation".


Index: ButtonBase.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Windows.Forms/ButtonBase.cs,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** ButtonBase.cs       8 Jul 2003 23:54:28 -0000       1.7
--- ButtonBase.cs       3 Aug 2003 19:21:17 -0000       1.8
***************
*** 141,145 ****
                                }
                        }
!       public virtual ContentAlignment TextAlign
                        {
                                get
--- 141,150 ----
                                }
                        }
! #if !CONFIG_COMPACT_FORMS
!       public
! #else
!       internal
! #endif
!       virtual ContentAlignment TextAlign
                        {
                                get
***************
*** 209,212 ****
--- 214,223 ----
                                // Nothing to do in this implementation.
                                base.Dispose(disposing);
+                       }
+ 
+       // Get the correct string format, based on text alignment and RTL info.
+       internal StringFormat GetStringFormat()
+                       {
+                               return format;
                        }
  

Index: ControlPaint.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Windows.Forms/ControlPaint.cs,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -r1.10 -r1.11
*** ControlPaint.cs     8 Jul 2003 10:45:00 -0000       1.10
--- ControlPaint.cs     3 Aug 2003 19:21:17 -0000       1.11
***************
*** 430,435 ****
                                 int height, ButtonState state)
                        {
!                               ThemeManager.MainPainter.DrawRadioButton
!                                       (graphics, x, y, width, height, state);
                        }
  
--- 430,439 ----
                                 int height, ButtonState state)
                        {
!                               using (Brush bg = new 
SolidBrush(SystemColors.Control))
!                               {
!                                       ThemeManager.MainPainter.DrawRadioButton
!                                               (graphics, x, y, width, height, 
state,
!                                                SystemColors.ControlText, 
SystemColors.Control, bg);
!                               }
                        }
  

Index: RadioButton.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Windows.Forms/RadioButton.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** RadioButton.cs      30 Jul 2003 17:15:14 -0000      1.1
--- RadioButton.cs      3 Aug 2003 19:21:17 -0000       1.2
***************
*** 1,7 ****
  /*
   * 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
--- 1,10 ----
  /*
   * RadioButton.cs - Implementation of the
!  *                    "System.Windows.Forms.RadioButton" class.
   *
!  * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
!  *
!  * Contributions from Mario Luca Bernardi
!  * Contributions from Simon Guindon
   *
   * This program is free software; you can redistribute it and/or modify
***************
*** 23,182 ****
  {
  
  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 )
!                               ;
!               }
!        }
! }
--- 26,504 ----
  {
  
+ using System;
  using System.Drawing;
+ using System.Drawing.Drawing2D;
  using System.ComponentModel;
+ using System.Windows.Forms;
+ using System.Windows.Forms.Themes;
+ 
+ public class RadioButton : ButtonBase
+ {
+       // Internal state.
+       private Appearance appearance;
+       private ContentAlignment checkAlign;
+       private Rectangle content;
+       private bool autoCheck;
+       private bool isChecked;
+       private bool needsLayout;
+       private int checkX;
+       private int checkY;
+ 
+       private static readonly int checkSize = 13;
+ 
+       // Constructor.
+       public RadioButton() : base()
+                       {
+                               appearance = Appearance.Normal;
+                               checkAlign = ContentAlignment.MiddleLeft;
+                               TextAlign = ContentAlignment.MiddleLeft;
+                               entered = false;
+                               pressed = false;
+                               autoCheck = true;
+                               isChecked = false;
+                               needsLayout = true;
+                       }
+ 
  
  
  
  
! #if !CONFIG_COMPACT_FORMS
!       // Get or set the appearance of this radio button control.
!       public Appearance Appearance
                        {
!                               get { return appearance; }
!                               set
!                               {
!                                       if (appearance != value)
!                                       {
!                                               if 
(!Enum.IsDefined(typeof(Appearance), value))
!                                               {
!                                               #if CONFIG_COMPONENT_MODEL
!                                                       throw new 
InvalidEnumArgumentException
!                                                               ("Appearance", 
(int)value, typeof(Appearance));
!                                               #else
!                                                       throw new 
ArgumentException
!                                                               ("Appearance = 
"+(int)value);
!                                               #endif
!                                               }
!                                               appearance = value;
!                                               needsLayout = true;
!                                               Redraw();
!                                               
OnAppearanceChanged(EventArgs.Empty);
!                                       }
!                               }
                        }
  
!       // Get or set the "auto check" style for this radio button.
!       public bool AutoCheck
                        {
!                               get { return autoCheck; }
!                               set
!                               {
!                                       if (autoCheck != value)
!                                       {
!                                               autoCheck = value;
!                                       }
!                               }
!                       }
  
!       // Get or set alignment of the check box on this radio button control.
!       public ContentAlignment CheckAlign
!                       {
!                               get { return checkAlign; }
!                               set
!                               {
!                                       if (checkAlign != value)
!                                       {
!                                               if 
(!Enum.IsDefined(typeof(ContentAlignment), value))
!                                               {
!                                               #if CONFIG_COMPONENT_MODEL
!                                                       throw new 
InvalidEnumArgumentException
!                                                               ("CheckAlign", 
(int)value,
!                                                                
typeof(ContentAlignment));
!                                               #else
!                                                       throw new 
ArgumentException
!                                                               ("CheckAlign = 
"+(int)value);
!                                               #endif
!                                               }
!                                               checkAlign = value;
!                                               needsLayout = true;
!                                               Redraw();
!                                       }
!                               }
!                       }
! #endif
  
!       // Get or set the checked state as a simple boolean value.
!       public bool Checked
!                       {
!                               get { return isChecked; }
!                               set
!                               {
!                                       if (isChecked != value)
!                                       {
!                                               isChecked = value;
!                                               Redraw();
!                                               
OnCheckedChanged(EventArgs.Empty);
!                                       }
                                }
                        }
  
! #if !CONFIG_COMPACT_FORMS
!       // Gets the required creation parameters when the control handle is
!       // created.
!       protected override CreateParams CreateParams
                        {
!                               get { return base.CreateParams; }
                        }
! #endif
! 
! #if !CONFIG_COMPACT_FORMS
!       // Gets the default size of the control.
!       protected
! #else
!       internal
! #endif
!       override Size DefaultSize
!                       {
!                               get { return new Size(104, 24); }
!                       }
! 
! #if !CONFIG_COMPACT_FORMS
!       // Gets or sets the alignment of the text on the RadioButton control.
!       public
! #else
!       internal
! #endif
!       override ContentAlignment TextAlign
                        {
!                               get { return base.TextAlign; }
!                               set { base.TextAlign = value; }
!                       }
! 
! 
! 
! 
!       // Calculate the current state of the button for its visual appearance.
!       internal override ButtonState CalculateState()
!                       {
!                               ButtonState state = ButtonState.Normal;
! 
!                               if (FlatStyle == FlatStyle.Flat ||
!                                   (FlatStyle == FlatStyle.Popup && !entered))
                                {
!                                       state |= ButtonState.Flat;
!                               }
! 
!                               if (isChecked)
!                               {
!                                       state |= ButtonState.Checked;
!                                       if (appearance == appearance.Button)
!                                       {
!                                               state |= ButtonState.Pushed;
!                                       }
!                               }
  
!                               if (Enabled)
!                               {
!                                       if (entered && pressed)
!                                       {
!                                               state |= ButtonState.Pushed;
!                                       }
!                               }
!                               else
!                               {
!                                       state |= ButtonState.Inactive;
                                }
+                               return state;
                        }
  
! #if !CONFIG_COMPACT_FORMS
!       protected override AccessibleObject CreateAccessibilityInstance()
                        {
!                               return base.CreateAccessibilityInstance();
                        }
! #endif
! 
!       // Draw the button in its current state on a Graphics surface.
!       internal override void Draw(Graphics graphics)
                        {
!                               // calculate ButtonState needed by 
DrawRadioButton
!                               ButtonState state = CalculateState();
!                               StringFormat format = GetStringFormat();
! 
!                               if (needsLayout) { LayoutElements(); }
  
!                               if (appearance == Appearance.Button)
!                               {
!                                       ThemeManager.MainPainter.DrawButton
!                                               (graphics, 0, 0, content.Width, 
content.Height,
!                                                state, ForeColor, BackColor, 
false);
!                               }
!                               else
!                               {
!                                       using (Brush bg = 
CreateBackgroundBrush())
!                                       {
!                                               
ThemeManager.MainPainter.DrawRadioButton
!                                                       (graphics, checkX, 
checkY, checkSize, checkSize,
!                                                        state, ForeColor, 
BackColor, bg);
!                                       }
!                               }
! 
!                               // TODO: image drawing
! 
!                               Rectangle rect = content;
!                               if (appearance == Appearance.Button)
!                               {
!                                       int x = content.X;
!                                       int y = content.Y;
!                                       int width = content.Width;
!                                       int height = content.Height;
!                                       x += 2;
!                                       y += 2;
!                                       width -= 4;
!                                       height -= 4;
!                                       if ((state & ButtonState.Pushed) != 0)
!                                       {
!                                               ++x;
!                                               ++x;
!                                       }
!                                       rect = new Rectangle(x, y, width, 
height);
!                               }
! 
!                               if (Enabled)
!                               {
!                                       using (Brush brush = new 
SolidBrush(ForeColor))
!                                       {
!                                               graphics.DrawString(Text, Font, 
brush, rect, format);
!                                       }
!                               }
!                               else
!                               {
!                                       
ControlPaint.DrawStringDisabled(graphics, Text, Font, ForeColor, rect, format);
!                               }
!                       }
! 
!       // Layout the elements of this radio button control.
!       private void LayoutElements()
!                       {
!                               needsLayout = false;
! 
!                               Size clientSize = ClientSize;
!                               int width = clientSize.Width;
!                               int height = clientSize.Height;
! 
!                               if (appearance == Appearance.Button)
!                               {
!                                       checkX = 0;
!                                       checkY = 0;
!                                       content = new Rectangle(0, 0, width, 
height);
!                               }
!                               else
!                               {
!                                       switch (checkAlign)
!                                       {
!                                               case ContentAlignment.TopLeft:
!                                               {
!                                                       checkX = 0;
!                                                       checkY = 0;
!                                                       content = new 
Rectangle(checkSize+3, 0,
!                                                                               
width-checkSize-3, height);
!                                               }
!                                               break;
! 
!                                               case ContentAlignment.TopCenter:
!                                               {
!                                                       checkX = (width/2) - 
(checkSize/2);
!                                                       checkY = 0;
!                                                       content = new 
Rectangle(0, checkSize+3,
!                                                                               
width, height-checkSize-3);
!                                               }
!                                               break;
! 
!                                               case ContentAlignment.TopRight:
!                                               {
!                                                       checkX = width - 
checkSize - 1;
!                                                       checkY = 0;
!                                                       content = new 
Rectangle(0, 0, width-checkX, height);
!                                               }
!                                               break;
! 
!                                               case 
ContentAlignment.MiddleLeft:
!                                               {
!                                                       checkX = 0;
!                                                       checkY = (height/2) - 
(checkSize/2);
!                                                       content = new 
Rectangle(checkSize+3, 0,
!                                                                               
width-checkSize-3, height);
!                                               }
!                                               break;
! 
!                                               case 
ContentAlignment.MiddleCenter:
!                                               {
!                                                       // for this alignment, 
the text is placed under
!                                                       // the check box of the 
radio button
!                                                       checkX = (width/2) - 
(checkSize/2);
!                                                       checkY = (height/2) - 
(checkSize/2);
!                                                       content = new 
Rectangle(0, 0, width, height);
!                                               }
!                                               break;
! 
!                                               case 
ContentAlignment.MiddleRight:
!                                               {
!                                                       checkX = width - 
checkSize - 1;
!                                                       checkY = (height/2) - 
(checkSize/2);
!                                                       content = new 
Rectangle(0, 0, width-checkX, height);
!                                               }
!                                               break;
! 
!                                               case 
ContentAlignment.BottomLeft:
!                                               {
!                                                       checkX = 0;
!                                                       checkY = height - 
checkSize - 1;
!                                                       content = new 
Rectangle(checkSize+3, 0,
!                                                                               
width-checkSize-3, height);
!                                               }
!                                               break;
! 
!                                               case 
ContentAlignment.BottomCenter:
!                                               {
!                                                       checkX = (width/2) - 
(checkSize/2);
!                                                       checkY = height - 
checkSize - 1;
!                                                       content = new 
Rectangle(0, 0,
!                                                                               
width, height-checkSize-3);
!                                               }
!                                               break;
! 
!                                               case 
ContentAlignment.BottomRight:
!                                               {
!                                                       checkX = width - 
checkSize - 1;
!                                                       checkY = height - 
checkSize - 1;
!                                                       content = new 
Rectangle(0, 0, width-checkX, height);
!                                               }
!                                               break;
!                                       }
                                }
                        }
  
!       // 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)
!                       {
!                               if (!isChecked && autoCheck && Enabled)
!                               {
!                                       if (Parent != null)
!                                       {
!                                               foreach (Control c in 
Parent.Controls)
!                                               {
!                                                       RadioButton rb = c as 
RadioButton;
!                                                       if ((rb != null) && (rb 
!= this))
!                                                       {
!                                                               rb.Checked = 
false;
!                                                       }
!                                               }
!                                       }
!                                       Checked = true;
                                }
+                               base.OnClick(e);
                        }
  
!       // Raises the HandleCreated event.
!       protected override void OnHandleCreated(EventArgs e)
                        {
!                               base.OnHandleCreated(e);
                        }
! 
!       protected override void OnMouseDown(MouseEventArgs e)
                        {
!                               pressed = true;
!                               Redraw();
!                               base.OnMouseDown(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);
!                       }
  
!       // Raises the MouseUp event.
!       protected override void OnMouseUp(MouseEventArgs e)
!                       {
!                               pressed = false;
!                               OnClick(EventArgs.Empty);
!                               base.OnMouseUp(e);
!                       }
  
!       // Clicks this radio button.
!       public void PerformClick()
!                       {
!                               OnClick(EventArgs.Empty);
!                       }
  
!       // Processes a mnemonic character.
!       protected override bool ProcessMnemonic(char charCode)
!                       {
!                               return false;
!                       }
  
!       // Redraw the button after a state change.
!       private void Redraw()
!                       {
!                               // Bail out if the button is not currently 
visible.
!                               if (!Visible || !IsHandleCreated) { return; }
  
!                               // Redraw the button.
!                               using (Graphics graphics = CreateGraphics())
!                               {
!                                       Draw(graphics);
!                               }
!                       }
  
!       public override string ToString()
!                       {
!                               return GetType().FullName.ToString() + ", 
Checked: " + Checked.ToString();
                        }
  
  
  
! 
! 
! 
! 
!       // 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;
! 
! }; // class RadioButton
! 
! }; // namespace System.Windows.Forms





reply via email to

[Prev in Thread] Current Thread [Next in Thread]