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
27 // $Log: CheckBox.cs,v $
28 // Revision 1.7 2004/09/28 18:44:25 pbartok
29 // - Streamlined Theme interfaces:
30 // * Each DrawXXX method for a control now is passed the object for the
31 // control to be drawn in order to allow accessing any state the theme
34 // * ControlPaint methods for the theme now have a CP prefix to avoid
35 // name clashes with the Draw methods for controls
37 // * Every control now retrieves it's DefaultSize from the current theme
39 // Revision 1.6 2004/09/01 20:01:24 pbartok
40 // - Added missing default
41 // - Added missing region mark
43 // Revision 1.5 2004/09/01 01:55:58 pbartok
44 // - Fixed to match the removal of the needs_redraw concept
46 // Revision 1.4 2004/08/31 18:48:31 pbartok
47 // - Finished (famous last words)
49 // Revision 1.3 2004/08/30 20:42:26 pbartok
50 // - Implemented CheckBox drawing code
52 // Revision 1.2 2004/08/30 15:44:20 pbartok
53 // - Updated to fix broken build. Not complete yet.
55 // Revision 1.1 2004/07/09 05:21:25 pbartok
65 namespace System.Windows.Forms {
66 public class CheckBox : ButtonBase {
67 #region Local Variables
68 internal Appearance appearance;
69 internal bool auto_check;
70 internal ContentAlignment check_alignment;
71 internal ContentAlignment text_alignment;
72 internal CheckState check_state;
73 internal bool three_state;
74 #endregion // Local Variables
77 #region Public Constructors
79 appearance = Appearance.Normal;
81 check_alignment = ContentAlignment.MiddleLeft;
82 text_alignment = ContentAlignment.MiddleLeft;
84 #endregion // Public Constructors
86 #region Public Instance Properties
87 public Appearance Appearance {
93 if (value != appearance) {
95 if (AppearanceChanged != null) {
96 AppearanceChanged(this, EventArgs.Empty);
103 public bool AutoCheck {
113 public ContentAlignment CheckAlign {
115 return check_alignment;
119 if (value != check_alignment) {
120 check_alignment = value;
127 public bool Checked {
129 if (check_state != CheckState.Unchecked) {
136 if (value && (check_state != CheckState.Checked)) {
137 check_state = CheckState.Checked;
139 OnCheckedChanged(EventArgs.Empty);
140 } else if (!value && (check_state != CheckState.Unchecked)) {
141 check_state = CheckState.Unchecked;
143 OnCheckedChanged(EventArgs.Empty);
148 public CheckState CheckState {
154 if (value != check_state) {
155 bool was_checked = (check_state != CheckState.Unchecked);
159 if (was_checked != (check_state != CheckState.Unchecked)) {
160 OnCheckedChanged(EventArgs.Empty);
163 OnCheckStateChanged(EventArgs.Empty);
169 public override ContentAlignment TextAlign {
171 return text_alignment;
175 if (value != text_alignment) {
176 text_alignment = value;
183 public bool ThreeState {
192 #endregion // Public Instance Properties
194 #region Protected Instance Properties
195 protected override CreateParams CreateParams {
197 return base.CreateParams;
201 protected override Size DefaultSize {
203 return new Size(104, 24);
206 #endregion // Protected Instance Properties
208 #region Public Instance Methods
209 public override string ToString() {
210 return base.ToString() + ", CheckState: " + (int)check_state;
212 #endregion // Public Instance Methods
214 #region Protected Instance Methods
215 protected override AccessibleObject CreateAccessibilityInstance() {
216 return base.CreateAccessibilityInstance ();
219 protected virtual void OnAppearanceChanged(EventArgs e) {
220 if (AppearanceChanged != null) {
221 AppearanceChanged(this, e);
225 protected virtual void OnCheckedChanged(EventArgs e) {
226 if (CheckedChanged != null) {
227 CheckedChanged(this, e);
231 protected virtual void OnCheckStateChanged(EventArgs e) {
232 if (CheckStateChanged != null) {
233 CheckStateChanged(this, e);
237 protected override void OnClick(EventArgs e) {
239 switch(check_state) {
240 case CheckState.Unchecked: {
242 CheckState = CheckState.Indeterminate;
244 CheckState = CheckState.Checked;
249 case CheckState.Indeterminate: {
250 CheckState = CheckState.Checked;
254 case CheckState.Checked: {
255 CheckState = CheckState.Unchecked;
262 protected override void OnHandleCreated(EventArgs e) {
263 base.OnHandleCreated (e);
266 protected override void OnMouseUp(MouseEventArgs e) {
270 protected override bool ProcessMnemonic(char charCode) {
271 return base.ProcessMnemonic (charCode);
273 #endregion // Protected Instance Methods
276 public event EventHandler AppearanceChanged;
277 public event EventHandler CheckedChanged;
278 public event EventHandler CheckStateChanged;
281 #region Internal drawing code
282 internal override void Redraw() {
\r
283 ThemeEngine.Current.DrawCheckBox(this.DeviceContext, this.ClientRectangle, this);
286 #endregion // Internal drawing code