OSDN Git Service

Update copyright year
[radegast/radegast.git] / Radegast / Core / Types / ToolStripCheckBox.cs
1 // 
2 // Radegast Metaverse Client
3 // Copyright (c) 2009-2014, Radegast Development Team
4 // All rights reserved.
5 // 
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
8 // 
9 //     * Redistributions of source code must retain the above copyright notice,
10 //       this list of conditions and the following disclaimer.
11 //     * Redistributions in binary form must reproduce the above copyright
12 //       notice, this list of conditions and the following disclaimer in the
13 //       documentation and/or other materials provided with the distribution.
14 //     * Neither the name of the application "Radegast", nor the names of its
15 //       contributors may be used to endorse or promote products derived from
16 //       this software without specific prior written permission.
17 // 
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // $Id$
30 //
31 using System;
32 using System.Windows.Forms;
33 using System.Windows.Forms.Design;
34 using System.ComponentModel;
35
36 namespace Radegast
37 {
38     [ToolStripItemDesignerAvailability(
39         ToolStripItemDesignerAvailability.ToolStrip)]
40     public partial class ToolStripCheckBox
41         : ToolStripControlHost
42     {
43         public CheckBox CheckBoxControl
44         {
45             get
46             {
47                 return Control as CheckBox;
48             }
49         }
50
51         /// <summary>
52         /// Is check box ticked
53         /// </summary>
54         [Category("Appearance")]
55         public bool Checked
56         {
57             get
58             {
59                 return CheckBoxControl.Checked;
60             }
61             set
62             {
63                 CheckBoxControl.Checked = value;
64             }
65         }
66
67         /// <summary>
68         /// Checked state
69         /// </summary>
70         [Category("Appearance")]
71         public CheckState CheckState
72         {
73             get
74             {
75                 return CheckBoxControl.CheckState;
76             }
77             set
78             {
79                 CheckBoxControl.CheckState = value;
80             }
81         }
82
83         /// <summary>
84         /// Label text
85         /// </summary>
86         [Category("Appearance")]
87         public override string Text
88         {
89             get
90             {
91                 return CheckBoxControl.Text;
92             }
93             set
94             {
95                 CheckBoxControl.Text = value;
96             }
97         }
98
99         /// <summary>
100         /// Occurs when check property is changed
101         /// </summary>
102         [Category("Misc")]
103         public event EventHandler CheckedChanged;
104
105         /// <summary>
106         /// Occurs when check state of the control changes
107         /// </summary>
108         [Category("Misc")]
109         public event EventHandler CheckStateChanged;
110
111         public ToolStripCheckBox()
112             : base(new CheckBox())
113         {
114             CheckBoxControl.MouseHover += new EventHandler(chk_MouseHover);
115         }
116
117         void chk_MouseHover(object sender, EventArgs e)
118         {
119             this.OnMouseHover(e);
120         }
121  
122         protected override void OnSubscribeControlEvents(Control c)
123         {
124             base.OnSubscribeControlEvents(c);
125             ((CheckBox)c).CheckedChanged += new EventHandler(ToolStripCheckBox_CheckedChanged);
126             ((CheckBox)c).CheckStateChanged += new EventHandler(ToolStripCheckBox_CheckStateChanged);
127         }
128
129         protected override void OnUnsubscribeControlEvents(Control c)
130         {
131             base.OnUnsubscribeControlEvents(c);
132             ((CheckBox)c).CheckedChanged -= new EventHandler(ToolStripCheckBox_CheckedChanged);
133             ((CheckBox)c).CheckStateChanged -= new EventHandler(ToolStripCheckBox_CheckStateChanged);
134         }
135
136         void ToolStripCheckBox_CheckedChanged(object sender, EventArgs e)
137         {
138             if (CheckedChanged != null)
139             {
140                 CheckedChanged(this, e);
141             }
142         }
143
144         void ToolStripCheckBox_CheckStateChanged(object sender, EventArgs e)
145         {
146             if (CheckStateChanged != null)
147             {
148                 CheckStateChanged(this, e);
149             }
150         }
151     }
152 }