1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004-2005 Novell, Inc.
23 // Peter Bartok pbartok@novell.com
28 using System.ComponentModel;
30 using System.Drawing.Text;
31 using System.Runtime.InteropServices;
33 namespace System.Windows.Forms {
34 [DefaultProperty("Checked")]
35 [DefaultEvent("CheckedChanged")]
36 public class RadioButton : ButtonBase {
37 #region Local Variables
38 internal Appearance appearance;
39 internal bool auto_check;
40 internal ContentAlignment radiobutton_alignment;
41 internal CheckState check_state;
42 #endregion // Local Variables
44 #region RadioButtonAccessibleObject Subclass
46 public class RadioButtonAccessibleObject : ControlAccessibleObject {
47 #region RadioButtonAccessibleObject Local Variables
48 private RadioButton owner;
49 #endregion // RadioButtonAccessibleObject Local Variables
51 #region RadioButtonAccessibleObject Constructors
52 public RadioButtonAccessibleObject(RadioButton owner) : base(owner) {
55 #endregion // RadioButtonAccessibleObject Constructors
57 #region RadioButtonAccessibleObject Properties
58 public override string DefaultAction {
64 public override AccessibleRole Role {
66 return AccessibleRole.RadioButton;
70 public override AccessibleStates State {
72 AccessibleStates retval;
74 retval = AccessibleStates.Default;
76 if (owner.check_state == CheckState.Checked) {
77 retval |= AccessibleStates.Checked;
81 retval |= AccessibleStates.Focused;
85 retval |= AccessibleStates.Focusable;
91 #endregion // RadioButtonAccessibleObject Properties
93 #region RadioButtonAccessibleObject Methods
94 public override void DoDefaultAction() {
97 #endregion // RadioButtonAccessibleObject Methods
99 #endregion // RadioButtonAccessibleObject Sub-class
101 #region Public Constructors
102 public RadioButton() {
103 appearance = Appearance.Normal;
105 radiobutton_alignment = ContentAlignment.MiddleLeft;
106 text_alignment = ContentAlignment.MiddleLeft;
108 GotFocus +=new EventHandler(ReceivedFocus);
110 #endregion // Public Constructors
112 #region Private Methods
113 private void UpdateSiblings() {
116 if (auto_check == false) {
120 // Remove tabstop property from and uncheck our radio-button siblings
123 for (int i = 0; i < c.child_controls.Count; i++) {
124 if ((this != c.child_controls[i]) && (c.child_controls[i] is RadioButton)) {
125 if (((RadioButton)(c.child_controls[i])).auto_check) {
126 c.child_controls[i].TabStop = false;
127 ((RadioButton)(c.child_controls[i])).Checked = false;
136 internal override void HaveDoubleClick() {
137 if (DoubleClick != null) DoubleClick(this, EventArgs.Empty);
140 internal override void Draw (PaintEventArgs pe) {
141 ThemeEngine.Current.DrawRadioButton (pe.Graphics, this.ClientRectangle, this);
144 private void ReceivedFocus(object sender, EventArgs e) {
\r
147 #endregion // Private Methods
149 #region Public Instance Properties
150 [DefaultValue(Appearance.Normal)]
152 public Appearance Appearance {
158 if (value != appearance) {
160 if (AppearanceChanged != null) {
161 AppearanceChanged(this, EventArgs.Empty);
169 public bool AutoCheck {
181 [DefaultValue(ContentAlignment.MiddleLeft)]
182 public ContentAlignment CheckAlign {
184 return radiobutton_alignment;
188 if (value != radiobutton_alignment) {
189 radiobutton_alignment = value;
196 [DefaultValue(false)]
197 public bool Checked {
199 if (check_state != CheckState.Unchecked) {
206 if (value && (check_state != CheckState.Checked)) {
208 check_state = CheckState.Checked;
210 OnCheckedChanged(EventArgs.Empty);
211 } else if (!value && (check_state != CheckState.Unchecked)) {
212 check_state = CheckState.Unchecked;
214 OnCheckedChanged(EventArgs.Empty);
219 [DefaultValue(false)]
220 public new bool TabStop {
230 [DefaultValue(ContentAlignment.MiddleLeft)]
232 public override ContentAlignment TextAlign {
234 return text_alignment;
238 if (value != text_alignment) {
239 text_alignment = value;
244 #endregion // Public Instance Properties
246 #region Protected Instance Properties
247 protected override CreateParams CreateParams {
249 SetStyle(ControlStyles.AllPaintingInWmPaint, true);
250 SetStyle(ControlStyles.UserPaint, true);
252 return base.CreateParams;
256 protected override Size DefaultSize {
258 return ThemeEngine.Current.RadioButtonDefaultSize;
261 #endregion // Protected Instance Properties
263 #region Public Instance Methods
264 public void PerformClick() {
265 OnClick(EventArgs.Empty);
268 public override string ToString() {
269 return base.ToString() + ", Checked: " + this.Checked;
271 #endregion // Public Instance Methods
273 #region Protected Instance Methods
274 protected override AccessibleObject CreateAccessibilityInstance() {
277 ao = base.CreateAccessibilityInstance ();
278 ao.role = AccessibleRole.RadioButton;
283 protected virtual void OnCheckedChanged(EventArgs e) {
284 if (CheckedChanged != null) {
285 CheckedChanged(this, e);
289 protected override void OnClick(EventArgs e) {
301 protected override void OnEnter(EventArgs e) {
305 protected override void OnHandleCreated(EventArgs e) {
306 base.OnHandleCreated(e);
309 protected override void OnMouseUp(MouseEventArgs mevent) {
310 base.OnMouseUp(mevent);
313 protected override bool ProcessMnemonic(char charCode) {
314 if (IsMnemonic(charCode, Text) == true) {
320 return base.ProcessMnemonic(charCode);
322 #endregion // Protected Instance Methods
325 public event EventHandler AppearanceChanged;
326 public event EventHandler CheckedChanged;
329 [EditorBrowsable (EditorBrowsableState.Never)]
330 public event EventHandler DoubleClick;
331 #endregion // Events
\r