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) {
142 ThemeEngine.Current.DrawRadioButton(this.DeviceContext, this.ClientRectangle, this);
147 private void ReceivedFocus(object sender, EventArgs e) {
\r
150 #endregion // Private Methods
152 #region Public Instance Properties
153 [DefaultValue(Appearance.Normal)]
155 public Appearance Appearance {
161 if (value != appearance) {
163 if (AppearanceChanged != null) {
164 AppearanceChanged(this, EventArgs.Empty);
172 public bool AutoCheck {
184 [DefaultValue(ContentAlignment.MiddleLeft)]
185 public ContentAlignment CheckAlign {
187 return radiobutton_alignment;
191 if (value != radiobutton_alignment) {
192 radiobutton_alignment = value;
199 [DefaultValue(false)]
200 public bool Checked {
202 if (check_state != CheckState.Unchecked) {
209 if (value && (check_state != CheckState.Checked)) {
211 check_state = CheckState.Checked;
213 OnCheckedChanged(EventArgs.Empty);
214 } else if (!value && (check_state != CheckState.Unchecked)) {
215 check_state = CheckState.Unchecked;
217 OnCheckedChanged(EventArgs.Empty);
222 [DefaultValue(false)]
223 public new bool TabStop {
233 [DefaultValue(ContentAlignment.MiddleLeft)]
235 public override ContentAlignment TextAlign {
237 return text_alignment;
241 if (value != text_alignment) {
242 text_alignment = value;
247 #endregion // Public Instance Properties
249 #region Protected Instance Properties
250 protected override CreateParams CreateParams {
252 SetStyle(ControlStyles.AllPaintingInWmPaint, true);
253 SetStyle(ControlStyles.UserPaint, true);
255 return base.CreateParams;
259 protected override Size DefaultSize {
261 return ThemeEngine.Current.RadioButtonDefaultSize;
264 #endregion // Protected Instance Properties
266 #region Public Instance Methods
267 public void PerformClick() {
268 OnClick(EventArgs.Empty);
271 public override string ToString() {
272 return base.ToString() + ", Checked: " + this.Checked;
274 #endregion // Public Instance Methods
276 #region Protected Instance Methods
277 protected override AccessibleObject CreateAccessibilityInstance() {
278 return base.CreateAccessibilityInstance ();
281 protected virtual void OnCheckedChanged(EventArgs e) {
282 if (CheckedChanged != null) {
283 CheckedChanged(this, e);
287 protected override void OnClick(EventArgs e) {
297 protected override void OnEnter(EventArgs e) {
301 protected override void OnHandleCreated(EventArgs e) {
302 base.OnHandleCreated(e);
305 protected override void OnMouseUp(MouseEventArgs mevent) {
306 base.OnMouseUp(mevent);
309 protected override bool ProcessMnemonic(char charCode) {
310 if (IsMnemonic(charCode, Text) == true) {
316 return base.ProcessMnemonic(charCode);
318 #endregion // Protected Instance Methods
321 public event EventHandler AppearanceChanged;
322 public event EventHandler CheckedChanged;
325 [EditorBrowsable (EditorBrowsableState.Never)]
326 public event EventHandler DoubleClick;
327 #endregion // Events
\r