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 Novell, Inc.
23 // Peter Bartok pbartok@novell.com
25 // $Log: RadioButton.cs,v $
26 // Revision 1.8 2004/10/15 13:32:45 ravindra
27 // - Renamed Paint() method to Draw() for clarity. Also, moved
28 // DrawImage() to OnPaint().
30 // Revision 1.7 2004/10/15 13:25:50 ravindra
31 // - Removed Redraw (), we get it from ButtonBase.
32 // - Implemented Paint (), to do class specific painting.
34 // Revision 1.6 2004/10/05 18:23:54 jackson
37 // Revision 1.5 2004/09/30 17:34:08 jackson
38 // Fix typo. Patch by John BouAntoun.
40 // Revision 1.4 2004/09/28 18:44:25 pbartok
41 // - Streamlined Theme interfaces:
42 // * Each DrawXXX method for a control now is passed the object for the
43 // control to be drawn in order to allow accessing any state the theme
46 // * ControlPaint methods for the theme now have a CP prefix to avoid
47 // name clashes with the Draw methods for controls
49 // * Every control now retrieves it's DefaultSize from the current theme
51 // Revision 1.3 2004/09/02 20:26:48 pbartok
52 // - Added missing RadioButton.RadioButtonAccessibleObject class
54 // Revision 1.2 2004/09/01 20:44:11 pbartok
57 // Revision 1.1 2004/09/01 20:40:02 pbartok
58 // - Functional initial check-in
66 using System.Drawing.Text;
68 namespace System.Windows.Forms {
69 public class RadioButton : ButtonBase {
70 #region Local Variables
71 internal Appearance appearance;
72 internal bool auto_check;
73 internal ContentAlignment radiobutton_alignment;
74 internal ContentAlignment text_alignment;
75 internal CheckState check_state;
76 private bool is_tabstop;
77 #endregion // Local Variables
79 #region RadioButtonAccessibleObject Subclass
80 public class RadioButtonAccessibleObject : ControlAccessibleObject {
81 #region RadioButtonAccessibleObject Local Variables
82 private RadioButton owner;
83 #endregion // RadioButtonAccessibleObject Local Variables
85 #region RadioButtonAccessibleObject Constructors
86 public RadioButtonAccessibleObject(RadioButton owner) : base(owner) {
89 #endregion // RadioButtonAccessibleObject Constructors
91 #region RadioButtonAccessibleObject Properties
92 public override string DefaultAction {
98 public override AccessibleRole Role {
100 return AccessibleRole.RadioButton;
104 public override AccessibleStates State {
106 AccessibleStates retval;
108 retval = AccessibleStates.Default;
110 if (owner.check_state == CheckState.Checked) {
111 retval |= AccessibleStates.Checked;
115 retval |= AccessibleStates.Focused;
118 if (owner.CanFocus) {
119 retval |= AccessibleStates.Focusable;
125 #endregion // RadioButtonAccessibleObject Properties
127 #region RadioButtonAccessibleObject Methods
128 public override void DoDefaultAction() {
129 owner.PerformClick();
131 #endregion // RadioButtonAccessibleObject Methods
133 #endregion // RadioButtonAccessibleObject Sub-class
135 #region Public Constructors
136 public RadioButton() {
137 appearance = Appearance.Normal;
139 radiobutton_alignment = ContentAlignment.MiddleLeft;
140 text_alignment = ContentAlignment.MiddleLeft;
143 #endregion // Public Constructors
145 #region Public Instance Properties
146 public Appearance Appearance {
152 if (value != appearance) {
154 if (AppearanceChanged != null) {
155 AppearanceChanged(this, EventArgs.Empty);
162 public bool AutoCheck {
172 public ContentAlignment CheckAlign {
174 return radiobutton_alignment;
178 if (value != radiobutton_alignment) {
179 radiobutton_alignment = value;
186 public bool Checked {
188 if (check_state != CheckState.Unchecked) {
195 if (value && (check_state != CheckState.Checked)) {
196 check_state = CheckState.Checked;
198 OnCheckedChanged(EventArgs.Empty);
199 } else if (!value && (check_state != CheckState.Unchecked)) {
200 check_state = CheckState.Unchecked;
202 OnCheckedChanged(EventArgs.Empty);
207 public bool TabStop {
217 public override ContentAlignment TextAlign {
219 return text_alignment;
223 if (value != text_alignment) {
224 text_alignment = value;
229 #endregion // Public Instance Properties
231 #region Protected Instance Properties
232 protected override CreateParams CreateParams {
234 SetStyle(ControlStyles.AllPaintingInWmPaint, true);
235 SetStyle(ControlStyles.UserPaint, true);
237 return base.CreateParams;
241 protected override Size DefaultSize {
243 return ThemeEngine.Current.RadioButtonDefaultSize;
246 #endregion // Protected Instance Properties
248 #region Public Instance Methods
249 public void PerformClick() {
\r
250 OnClick(EventArgs.Empty);
\r
253 public override string ToString() {
\r
254 return base.ToString() + ", Checked: " + this.Checked;
\r
256 #endregion // Public Instance Methods
258 #region Protected Instance Methods
259 protected override AccessibleObject CreateAccessibilityInstance() {
260 return base.CreateAccessibilityInstance ();
263 protected virtual void OnCheckedChanged(EventArgs e) {
264 if (CheckedChanged != null) {
265 CheckedChanged(this, e);
269 protected override void OnClick(EventArgs e) {
275 protected override void OnEnter(EventArgs e) {
279 protected override void OnHandleCreated(EventArgs e) {
280 base.OnHandleCreated(e);
283 protected override void OnMouseUp(MouseEventArgs mevent) {
284 base.OnMouseUp(mevent);
287 protected override bool ProcessMnemonic(char charCode) {
288 return base.ProcessMnemonic(charCode);
290 #endregion // Protected Instance Methods
293 public event EventHandler AppearanceChanged;
294 public event EventHandler CheckedChanged;
297 #region Internal Drawing Code
298 internal override void Draw (PaintEventArgs pe) {
300 ThemeEngine.Current.DrawRadioButton(this.DeviceContext, this.ClientRectangle, this);
304 #endregion // Internal Drawing Code