2009-11-17 Jeffrey Stedfast <fejj@novell.com>
[moon.git] / class / System.Windows / System.Windows.Automation.Peers / ToggleButtonAutomationPeer.cs
blobcbd1b807bea4bed56cc07b032d9b50a2cf47775b
1 /*
2 * ToggleButtonAutomationPeer.cs.
4 * Contact:
5 * Moonlight List (moonlight-list@lists.ximian.com)
7 * Copyright 2009 Novell, Inc. (http://www.novell.com)
9 * See the LICENSE file included with the distribution for details.
13 using System;
14 using System.Windows.Automation;
15 using System.Windows.Automation.Provider;
16 using System.Windows.Controls;
17 using System.Windows.Controls.Primitives;
19 namespace System.Windows.Automation.Peers
21 public class ToggleButtonAutomationPeer : ButtonBaseAutomationPeer, IToggleProvider
23 public ToggleButtonAutomationPeer (ToggleButton owner)
24 : base (owner)
26 this.owner = owner;
28 // UIA Event TogglePatternIdentifiers.ToggleStateProperty
29 // raised by ToggleButton.OnIsCheckedPropertyChanged().
30 toggleState = ToggleState;
33 public override object GetPattern (PatternInterface patternInterface)
35 if (patternInterface == PatternInterface.Toggle)
36 return this;
37 return base.GetPattern (patternInterface);
40 protected override string GetClassNameCore ()
42 return "Button";
45 protected override AutomationControlType GetAutomationControlTypeCore ()
47 return AutomationControlType.Button;
50 #region IToggleProvider implementation
52 void IToggleProvider.Toggle ()
54 if (!owner.IsEnabled)
55 throw new ElementNotEnabledException ();
57 bool? isChecked = owner.IsChecked;
58 if (isChecked == true)
59 owner.IsChecked = owner.IsThreeState ? null : ((bool?) false);
60 else
61 owner.IsChecked = (bool?) isChecked.HasValue;
64 ToggleState IToggleProvider.ToggleState {
65 get { return ToggleState; }
68 #endregion
70 internal virtual void RaiseToggleStateChanged ()
72 RaisePropertyChangedEvent (TogglePatternIdentifiers.ToggleStateProperty,
73 toggleState,
74 ToggleState);
75 toggleState = ToggleState;
78 private ToggleState ToggleState {
79 get {
80 bool? isChecked = owner.IsChecked;
81 if (isChecked.HasValue)
82 return (isChecked == true) ? ToggleState.On : ToggleState.Off;
83 return ToggleState.Indeterminate;
87 private ToggleButton owner;
88 private ToggleState toggleState;