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.10 2004/10/15 13:32:45 ravindra
29 // - Renamed Paint() method to Draw() for clarity. Also, moved
30 // DrawImage() to OnPaint().
32 // Revision 1.9 2004/10/15 13:25:50 ravindra
33 // - Removed Redraw (), we get it from ButtonBase.
34 // - Implemented Paint (), to do class specific painting.
36 // Revision 1.8 2004/10/13 02:46:22 pbartok
37 // - Fix from John BouAntoun: Now properly sets the Appearance property
39 // Revision 1.7 2004/09/28 18:44:25 pbartok
40 // - Streamlined Theme interfaces:
41 // * Each DrawXXX method for a control now is passed the object for the
42 // control to be drawn in order to allow accessing any state the theme
45 // * ControlPaint methods for the theme now have a CP prefix to avoid
46 // name clashes with the Draw methods for controls
48 // * Every control now retrieves it's DefaultSize from the current theme
50 // Revision 1.6 2004/09/01 20:01:24 pbartok
51 // - Added missing default
52 // - Added missing region mark
54 // Revision 1.5 2004/09/01 01:55:58 pbartok
55 // - Fixed to match the removal of the needs_redraw concept
57 // Revision 1.4 2004/08/31 18:48:31 pbartok
58 // - Finished (famous last words)
60 // Revision 1.3 2004/08/30 20:42:26 pbartok
61 // - Implemented CheckBox drawing code
63 // Revision 1.2 2004/08/30 15:44:20 pbartok
64 // - Updated to fix broken build. Not complete yet.
66 // Revision 1.1 2004/07/09 05:21:25 pbartok
76 namespace System
.Windows
.Forms
{
77 public class CheckBox
: ButtonBase
{
78 #region Local Variables
79 internal Appearance appearance
;
80 internal bool auto_check
;
81 internal ContentAlignment check_alignment
;
82 internal ContentAlignment text_alignment
;
83 internal CheckState check_state
;
84 internal bool three_state
;
85 #endregion // Local Variables
88 #region Public Constructors
90 appearance
= Appearance
.Normal
;
92 check_alignment
= ContentAlignment
.MiddleLeft
;
93 text_alignment
= ContentAlignment
.MiddleLeft
;
95 #endregion // Public Constructors
97 #region Public Instance Properties
98 public Appearance Appearance
{
104 if (value != appearance
) {
106 if (AppearanceChanged
!= null) {
107 AppearanceChanged(this, EventArgs
.Empty
);
114 public bool AutoCheck
{
124 public ContentAlignment CheckAlign
{
126 return check_alignment
;
130 if (value != check_alignment
) {
131 check_alignment
= value;
138 public bool Checked
{
140 if (check_state
!= CheckState
.Unchecked
) {
147 if (value && (check_state
!= CheckState
.Checked
)) {
148 check_state
= CheckState
.Checked
;
150 OnCheckedChanged(EventArgs
.Empty
);
151 } else if (!value && (check_state
!= CheckState
.Unchecked
)) {
152 check_state
= CheckState
.Unchecked
;
154 OnCheckedChanged(EventArgs
.Empty
);
159 public CheckState CheckState
{
165 if (value != check_state
) {
166 bool was_checked
= (check_state
!= CheckState
.Unchecked
);
170 if (was_checked
!= (check_state
!= CheckState
.Unchecked
)) {
171 OnCheckedChanged(EventArgs
.Empty
);
174 OnCheckStateChanged(EventArgs
.Empty
);
180 public override ContentAlignment TextAlign
{
182 return text_alignment
;
186 if (value != text_alignment
) {
187 text_alignment
= value;
194 public bool ThreeState
{
203 #endregion // Public Instance Properties
205 #region Protected Instance Properties
206 protected override CreateParams CreateParams
{
208 return base.CreateParams
;
212 protected override Size DefaultSize
{
214 return new Size(104, 24);
217 #endregion // Protected Instance Properties
219 #region Public Instance Methods
220 public override string ToString() {
221 return base.ToString() + ", CheckState: " + (int)check_state
;
223 #endregion // Public Instance Methods
225 #region Protected Instance Methods
226 protected override AccessibleObject
CreateAccessibilityInstance() {
227 return base.CreateAccessibilityInstance ();
230 protected virtual void OnAppearanceChanged(EventArgs e
) {
231 if (AppearanceChanged
!= null) {
232 AppearanceChanged(this, e
);
236 protected virtual void OnCheckedChanged(EventArgs e
) {
237 if (CheckedChanged
!= null) {
238 CheckedChanged(this, e
);
242 protected virtual void OnCheckStateChanged(EventArgs e
) {
243 if (CheckStateChanged
!= null) {
244 CheckStateChanged(this, e
);
248 protected override void OnClick(EventArgs e
) {
250 switch(check_state
) {
251 case CheckState
.Unchecked
: {
253 CheckState
= CheckState
.Indeterminate
;
255 CheckState
= CheckState
.Checked
;
260 case CheckState
.Indeterminate
: {
261 CheckState
= CheckState
.Checked
;
265 case CheckState
.Checked
: {
266 CheckState
= CheckState
.Unchecked
;
273 protected override void OnHandleCreated(EventArgs e
) {
274 base.OnHandleCreated (e
);
277 protected override void OnMouseUp(MouseEventArgs e
) {
281 protected override bool ProcessMnemonic(char charCode
) {
282 return base.ProcessMnemonic (charCode
);
284 #endregion // Protected Instance Methods
287 public event EventHandler AppearanceChanged
;
288 public event EventHandler CheckedChanged
;
289 public event EventHandler CheckStateChanged
;
292 #region Internal drawing code
293 internal override void Draw (PaintEventArgs pe
) {
295 ThemeEngine
.Current
.DrawCheckBox (this.DeviceContext
, this.ClientRectangle
, this);
299 #endregion // Internal drawing code