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.8 2004/10/13 02:46:22 pbartok
29 // - Fix from John BouAntoun: Now properly sets the Appearance property
31 // Revision 1.7 2004/09/28 18:44:25 pbartok
32 // - Streamlined Theme interfaces:
33 // * Each DrawXXX method for a control now is passed the object for the
34 // control to be drawn in order to allow accessing any state the theme
37 // * ControlPaint methods for the theme now have a CP prefix to avoid
38 // name clashes with the Draw methods for controls
40 // * Every control now retrieves it's DefaultSize from the current theme
42 // Revision 1.6 2004/09/01 20:01:24 pbartok
43 // - Added missing default
44 // - Added missing region mark
46 // Revision 1.5 2004/09/01 01:55:58 pbartok
47 // - Fixed to match the removal of the needs_redraw concept
49 // Revision 1.4 2004/08/31 18:48:31 pbartok
50 // - Finished (famous last words)
52 // Revision 1.3 2004/08/30 20:42:26 pbartok
53 // - Implemented CheckBox drawing code
55 // Revision 1.2 2004/08/30 15:44:20 pbartok
56 // - Updated to fix broken build. Not complete yet.
58 // Revision 1.1 2004/07/09 05:21:25 pbartok
68 namespace System.Windows.Forms {
69 public class CheckBox : ButtonBase {
70 #region Local Variables
71 internal Appearance appearance;
72 internal bool auto_check;
73 internal ContentAlignment check_alignment;
74 internal ContentAlignment text_alignment;
75 internal CheckState check_state;
76 internal bool three_state;
77 #endregion // Local Variables
80 #region Public Constructors
82 appearance = Appearance.Normal;
84 check_alignment = ContentAlignment.MiddleLeft;
85 text_alignment = ContentAlignment.MiddleLeft;
87 #endregion // Public Constructors
89 #region Public Instance Properties
90 public Appearance Appearance {
96 if (value != appearance) {
98 if (AppearanceChanged != null) {
99 AppearanceChanged(this, EventArgs.Empty);
106 public bool AutoCheck {
116 public ContentAlignment CheckAlign {
118 return check_alignment;
122 if (value != check_alignment) {
123 check_alignment = value;
130 public bool Checked {
132 if (check_state != CheckState.Unchecked) {
139 if (value && (check_state != CheckState.Checked)) {
140 check_state = CheckState.Checked;
142 OnCheckedChanged(EventArgs.Empty);
143 } else if (!value && (check_state != CheckState.Unchecked)) {
144 check_state = CheckState.Unchecked;
146 OnCheckedChanged(EventArgs.Empty);
151 public CheckState CheckState {
157 if (value != check_state) {
158 bool was_checked = (check_state != CheckState.Unchecked);
162 if (was_checked != (check_state != CheckState.Unchecked)) {
163 OnCheckedChanged(EventArgs.Empty);
166 OnCheckStateChanged(EventArgs.Empty);
172 public override ContentAlignment TextAlign {
174 return text_alignment;
178 if (value != text_alignment) {
179 text_alignment = value;
186 public bool ThreeState {
195 #endregion // Public Instance Properties
197 #region Protected Instance Properties
198 protected override CreateParams CreateParams {
200 return base.CreateParams;
204 protected override Size DefaultSize {
206 return new Size(104, 24);
209 #endregion // Protected Instance Properties
211 #region Public Instance Methods
212 public override string ToString() {
213 return base.ToString() + ", CheckState: " + (int)check_state;
215 #endregion // Public Instance Methods
217 #region Protected Instance Methods
218 protected override AccessibleObject CreateAccessibilityInstance() {
219 return base.CreateAccessibilityInstance ();
222 protected virtual void OnAppearanceChanged(EventArgs e) {
223 if (AppearanceChanged != null) {
224 AppearanceChanged(this, e);
228 protected virtual void OnCheckedChanged(EventArgs e) {
229 if (CheckedChanged != null) {
230 CheckedChanged(this, e);
234 protected virtual void OnCheckStateChanged(EventArgs e) {
235 if (CheckStateChanged != null) {
236 CheckStateChanged(this, e);
240 protected override void OnClick(EventArgs e) {
242 switch(check_state) {
243 case CheckState.Unchecked: {
245 CheckState = CheckState.Indeterminate;
247 CheckState = CheckState.Checked;
252 case CheckState.Indeterminate: {
253 CheckState = CheckState.Checked;
257 case CheckState.Checked: {
258 CheckState = CheckState.Unchecked;
265 protected override void OnHandleCreated(EventArgs e) {
266 base.OnHandleCreated (e);
269 protected override void OnMouseUp(MouseEventArgs e) {
273 protected override bool ProcessMnemonic(char charCode) {
274 return base.ProcessMnemonic (charCode);
276 #endregion // Protected Instance Methods
279 public event EventHandler AppearanceChanged;
280 public event EventHandler CheckedChanged;
281 public event EventHandler CheckStateChanged;
284 #region Internal drawing code
285 internal override void Redraw() {
\r
286 ThemeEngine.Current.DrawCheckBox(this.DeviceContext, this.ClientRectangle, this);
289 #endregion // Internal drawing code