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.9 2004/10/15 13:25:50 ravindra
29 // - Removed Redraw (), we get it from ButtonBase.
30 // - Implemented Paint (), to do class specific painting.
32 // Revision 1.8 2004/10/13 02:46:22 pbartok
33 // - Fix from John BouAntoun: Now properly sets the Appearance property
35 // Revision 1.7 2004/09/28 18:44:25 pbartok
36 // - Streamlined Theme interfaces:
37 // * Each DrawXXX method for a control now is passed the object for the
38 // control to be drawn in order to allow accessing any state the theme
41 // * ControlPaint methods for the theme now have a CP prefix to avoid
42 // name clashes with the Draw methods for controls
44 // * Every control now retrieves it's DefaultSize from the current theme
46 // Revision 1.6 2004/09/01 20:01:24 pbartok
47 // - Added missing default
48 // - Added missing region mark
50 // Revision 1.5 2004/09/01 01:55:58 pbartok
51 // - Fixed to match the removal of the needs_redraw concept
53 // Revision 1.4 2004/08/31 18:48:31 pbartok
54 // - Finished (famous last words)
56 // Revision 1.3 2004/08/30 20:42:26 pbartok
57 // - Implemented CheckBox drawing code
59 // Revision 1.2 2004/08/30 15:44:20 pbartok
60 // - Updated to fix broken build. Not complete yet.
62 // Revision 1.1 2004/07/09 05:21:25 pbartok
72 namespace System.Windows.Forms {
73 public class CheckBox : ButtonBase {
74 #region Local Variables
75 internal Appearance appearance;
76 internal bool auto_check;
77 internal ContentAlignment check_alignment;
78 internal ContentAlignment text_alignment;
79 internal CheckState check_state;
80 internal bool three_state;
81 #endregion // Local Variables
84 #region Public Constructors
86 appearance = Appearance.Normal;
88 check_alignment = ContentAlignment.MiddleLeft;
89 text_alignment = ContentAlignment.MiddleLeft;
91 #endregion // Public Constructors
93 #region Public Instance Properties
94 public Appearance Appearance {
100 if (value != appearance) {
102 if (AppearanceChanged != null) {
103 AppearanceChanged(this, EventArgs.Empty);
110 public bool AutoCheck {
120 public ContentAlignment CheckAlign {
122 return check_alignment;
126 if (value != check_alignment) {
127 check_alignment = value;
134 public bool Checked {
136 if (check_state != CheckState.Unchecked) {
143 if (value && (check_state != CheckState.Checked)) {
144 check_state = CheckState.Checked;
146 OnCheckedChanged(EventArgs.Empty);
147 } else if (!value && (check_state != CheckState.Unchecked)) {
148 check_state = CheckState.Unchecked;
150 OnCheckedChanged(EventArgs.Empty);
155 public CheckState CheckState {
161 if (value != check_state) {
162 bool was_checked = (check_state != CheckState.Unchecked);
166 if (was_checked != (check_state != CheckState.Unchecked)) {
167 OnCheckedChanged(EventArgs.Empty);
170 OnCheckStateChanged(EventArgs.Empty);
176 public override ContentAlignment TextAlign {
178 return text_alignment;
182 if (value != text_alignment) {
183 text_alignment = value;
190 public bool ThreeState {
199 #endregion // Public Instance Properties
201 #region Protected Instance Properties
202 protected override CreateParams CreateParams {
204 return base.CreateParams;
208 protected override Size DefaultSize {
210 return new Size(104, 24);
213 #endregion // Protected Instance Properties
215 #region Public Instance Methods
216 public override string ToString() {
217 return base.ToString() + ", CheckState: " + (int)check_state;
219 #endregion // Public Instance Methods
221 #region Protected Instance Methods
222 protected override AccessibleObject CreateAccessibilityInstance() {
223 return base.CreateAccessibilityInstance ();
226 protected virtual void OnAppearanceChanged(EventArgs e) {
227 if (AppearanceChanged != null) {
228 AppearanceChanged(this, e);
232 protected virtual void OnCheckedChanged(EventArgs e) {
233 if (CheckedChanged != null) {
234 CheckedChanged(this, e);
238 protected virtual void OnCheckStateChanged(EventArgs e) {
239 if (CheckStateChanged != null) {
240 CheckStateChanged(this, e);
244 protected override void OnClick(EventArgs e) {
246 switch(check_state) {
247 case CheckState.Unchecked: {
249 CheckState = CheckState.Indeterminate;
251 CheckState = CheckState.Checked;
256 case CheckState.Indeterminate: {
257 CheckState = CheckState.Checked;
261 case CheckState.Checked: {
262 CheckState = CheckState.Unchecked;
269 protected override void OnHandleCreated(EventArgs e) {
270 base.OnHandleCreated (e);
273 protected override void OnMouseUp(MouseEventArgs e) {
277 protected override bool ProcessMnemonic(char charCode) {
278 return base.ProcessMnemonic (charCode);
280 #endregion // Protected Instance Methods
283 public event EventHandler AppearanceChanged;
284 public event EventHandler CheckedChanged;
285 public event EventHandler CheckStateChanged;
288 #region Internal drawing code
289 internal override void Paint (PaintEventArgs pe) {
291 ThemeEngine.Current.DrawCheckBox (this.DeviceContext, this.ClientRectangle, this);
294 pe.Graphics.DrawImage (this.ImageBuffer, pe.ClipRectangle, pe.ClipRectangle, GraphicsUnit.Pixel);
296 #endregion // Internal drawing code