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 // Dennis Hayes dennish@raytek.com
24 // Peter Bartok pbartok@novell.com
30 using System.ComponentModel;
32 using System.Runtime.InteropServices;
34 namespace System.Windows.Forms {
35 [DefaultProperty("Checked")]
36 [DefaultEvent("CheckedChanged")]
37 public class CheckBox : ButtonBase {
38 #region Local Variables
39 internal Appearance appearance;
40 internal bool auto_check;
41 internal ContentAlignment check_alignment;
42 internal CheckState check_state;
43 internal bool three_state;
44 #endregion // Local Variables
46 #region CheckBoxAccessibleObject Subclass
48 public class CheckBoxAccessibleObject : ControlAccessibleObject {
49 #region CheckBoxAccessibleObject Local Variables
50 private CheckBox owner;
51 #endregion // CheckBoxAccessibleObject Local Variables
53 #region CheckBoxAccessibleObject Constructors
54 public CheckBoxAccessibleObject(Control owner) : base(owner) {
55 this.owner = (CheckBox)owner;
57 #endregion // CheckBoxAccessibleObject Constructors
59 #region CheckBoxAccessibleObject Properties
60 public override string DefaultAction {
66 public override AccessibleRole Role {
68 return AccessibleRole.CheckButton;
72 public override AccessibleStates State {
74 AccessibleStates retval;
76 retval = AccessibleStates.Default;
78 if (owner.check_state == CheckState.Checked) {
79 retval |= AccessibleStates.Checked;
83 retval |= AccessibleStates.Focused;
87 retval |= AccessibleStates.Focusable;
93 #endregion // CheckBoxAccessibleObject Properties
95 #endregion // CheckBoxAccessibleObject Sub-class
97 #region Public Constructors
99 appearance = Appearance.Normal;
101 check_alignment = ContentAlignment.MiddleLeft;
102 text_alignment = ContentAlignment.MiddleLeft;
104 #endregion // Public Constructors
106 #region Internal Methods
107 internal override void Draw (PaintEventArgs pe) {
109 ThemeEngine.Current.DrawCheckBox (this.DeviceContext, this.ClientRectangle, this);
114 internal override void HaveDoubleClick() {
115 if (DoubleClick != null) DoubleClick(this, EventArgs.Empty);
117 #endregion // Internal Methods
119 #region Public Instance Properties
120 [DefaultValue(Appearance.Normal)]
122 public Appearance Appearance {
128 if (value != appearance) {
130 if (AppearanceChanged != null) {
131 AppearanceChanged(this, EventArgs.Empty);
139 public bool AutoCheck {
151 [DefaultValue(ContentAlignment.MiddleLeft)]
152 public ContentAlignment CheckAlign {
154 return check_alignment;
158 if (value != check_alignment) {
159 check_alignment = value;
167 [RefreshProperties(RefreshProperties.All)]
168 [DefaultValue(false)]
169 public bool Checked {
171 if (check_state != CheckState.Unchecked) {
178 if (value && (check_state != CheckState.Checked)) {
179 check_state = CheckState.Checked;
181 OnCheckedChanged(EventArgs.Empty);
182 } else if (!value && (check_state != CheckState.Unchecked)) {
183 check_state = CheckState.Unchecked;
185 OnCheckedChanged(EventArgs.Empty);
190 [DefaultValue(CheckState.Unchecked)]
191 [RefreshProperties(RefreshProperties.All)]
193 public CheckState CheckState {
199 if (value != check_state) {
200 bool was_checked = (check_state != CheckState.Unchecked);
204 if (was_checked != (check_state != CheckState.Unchecked)) {
205 OnCheckedChanged(EventArgs.Empty);
208 OnCheckStateChanged(EventArgs.Empty);
214 [DefaultValue(ContentAlignment.MiddleLeft)]
216 public override ContentAlignment TextAlign {
218 return text_alignment;
222 if (value != text_alignment) {
223 text_alignment = value;
230 [DefaultValue(false)]
231 public bool ThreeState {
240 #endregion // Public Instance Properties
242 #region Protected Instance Properties
243 protected override CreateParams CreateParams {
245 return base.CreateParams;
249 protected override Size DefaultSize {
251 return new Size(104, 24);
254 #endregion // Protected Instance Properties
256 #region Public Instance Methods
257 public override string ToString() {
258 return base.ToString() + ", CheckState: " + (int)check_state;
260 #endregion // Public Instance Methods
262 #region Protected Instance Methods
263 protected override AccessibleObject CreateAccessibilityInstance() {
264 return base.CreateAccessibilityInstance ();
267 protected virtual void OnAppearanceChanged(EventArgs e) {
268 if (AppearanceChanged != null) {
269 AppearanceChanged(this, e);
273 protected virtual void OnCheckedChanged(EventArgs e) {
274 if (CheckedChanged != null) {
275 CheckedChanged(this, e);
279 protected virtual void OnCheckStateChanged(EventArgs e) {
280 if (CheckStateChanged != null) {
281 CheckStateChanged(this, e);
285 protected override void OnClick(EventArgs e) {
287 switch(check_state) {
288 case CheckState.Unchecked: {
290 CheckState = CheckState.Indeterminate;
292 CheckState = CheckState.Checked;
297 case CheckState.Indeterminate: {
298 CheckState = CheckState.Checked;
302 case CheckState.Checked: {
303 CheckState = CheckState.Unchecked;
310 protected override void OnHandleCreated(EventArgs e) {
311 base.OnHandleCreated (e);
314 protected override void OnMouseUp(MouseEventArgs e) {
318 protected override bool ProcessMnemonic(char charCode) {
319 if (IsMnemonic(charCode, Text) == true) {
321 OnClick(EventArgs.Empty);
325 return base.ProcessMnemonic(charCode);
327 #endregion // Protected Instance Methods
330 public event EventHandler AppearanceChanged;
331 public event EventHandler CheckedChanged;
332 public event EventHandler CheckStateChanged;
337 [EditorBrowsable (EditorBrowsableState.Never)]
338 public event EventHandler DoubleClick;