- Implement 2.0 image key feature.
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / GroupBox.cs
1 //
2 // System.Windows.Forms.GroupBox.cs
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 //
23 // Authors:
24 //              Jordi Mas i Hernandez, jordi@ximian.com
25 //
26 // TODO:
27 //
28 // Copyright (C) Novell Inc., 2004-2005
29 //
30 //
31
32 using System.Drawing;
33 using System.ComponentModel;
34 using System.ComponentModel.Design;
35 using System.Runtime.InteropServices;
36
37 namespace System.Windows.Forms
38 {
39         [DefaultProperty("Text")]
40         [DefaultEvent("Enter")]
41         [Designer ("System.Windows.Forms.Design.GroupBoxDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
42 #if NET_2_0
43         [ClassInterface (ClassInterfaceType.AutoDispatch)]
44         [ComVisible (true)]
45 #endif
46         public class GroupBox : Control
47         {
48                 private FlatStyle flat_style;
49                 private Rectangle display_rectangle = new Rectangle ();
50
51                 #region Events
52                 [Browsable(false)]
53                 [EditorBrowsable(EditorBrowsableState.Advanced)]
54                 public new event EventHandler Click {
55                         add { base.Click += value; }
56                         remove { base.Click -= value; }
57                 }
58
59                 [Browsable(false)]
60                 [EditorBrowsable(EditorBrowsableState.Advanced)]
61                 public new event EventHandler DoubleClick {
62                         add { base.DoubleClick += value; }
63                         remove { base.DoubleClick -= value; }
64                 }
65
66                 [Browsable(false)]
67                 [EditorBrowsable(EditorBrowsableState.Advanced)]
68                 public new event KeyEventHandler KeyDown {
69                         add { base.KeyDown += value; }
70                         remove { base.KeyDown -= value; }
71                 }
72
73                 [Browsable(false)]
74                 [EditorBrowsable(EditorBrowsableState.Advanced)]
75                 public new event KeyPressEventHandler KeyPress {
76                         add { base.KeyPress += value; }
77                         remove { base.KeyPress -= value; }
78                 }
79
80                 [Browsable(false)]
81                 [EditorBrowsable(EditorBrowsableState.Advanced)]
82                 public new event KeyEventHandler KeyUp {
83                         add { base.KeyUp += value; }
84                         remove { base.KeyUp -= value; }
85                 }
86
87                 [Browsable(false)]
88                 [EditorBrowsable(EditorBrowsableState.Advanced)]
89                 public new event MouseEventHandler MouseDown {
90                         add { base.MouseDown += value; }
91                         remove { base.MouseDown -= value; }
92                 }
93
94                 [Browsable(false)]
95                 [EditorBrowsable(EditorBrowsableState.Advanced)]
96                 public new event EventHandler MouseEnter {
97                         add { base.MouseEnter += value; }
98                         remove { base.MouseEnter -= value; }
99                 }
100
101                 [Browsable(false)]
102                 [EditorBrowsable(EditorBrowsableState.Advanced)]
103                 public new event EventHandler MouseLeave {
104                         add { base.MouseLeave += value; }
105                         remove { base.MouseLeave -= value; }
106                 }
107
108                 [Browsable(false)]
109                 [EditorBrowsable(EditorBrowsableState.Advanced)]
110                 public new event MouseEventHandler MouseMove {
111                         add { base.MouseMove += value; }
112                         remove { base.MouseMove -= value; }
113                 }
114
115                 [Browsable(false)]
116                 [EditorBrowsable(EditorBrowsableState.Advanced)]
117                 public new event MouseEventHandler MouseUp {
118                         add { base.MouseUp += value; }
119                         remove { base.MouseUp -= value; }
120                 }
121
122                 [Browsable(false)]
123                 [EditorBrowsable(EditorBrowsableState.Advanced)]
124                 public new event EventHandler TabStopChanged {
125                         add { base.TabStopChanged += value; }
126                         remove { base.TabStopChanged -= value; }
127                 }
128                 #endregion Events
129
130                 public GroupBox ()
131                 {
132                         TabStop = false;
133                         flat_style = FlatStyle.Standard;
134
135                         SetStyle(ControlStyles.ContainerControl | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true);
136                         SetStyle(ControlStyles.Selectable, false);
137                 }
138
139                 #region Public Properties
140                 [Browsable(false)]
141                 [EditorBrowsable(EditorBrowsableState.Advanced)]
142                 public override bool AllowDrop {
143                         get { return base.AllowDrop;  }
144                         set { base.AllowDrop = value; }
145                 }
146
147                 protected override CreateParams CreateParams {
148                         get { return base.CreateParams; }
149                 }
150
151                 protected override Size DefaultSize {
152                         get { return ThemeEngine.Current.GroupBoxDefaultSize;}
153                 }
154
155                 public override Rectangle DisplayRectangle {
156                         get {
157                                 display_rectangle.X = 3;
158                                 display_rectangle.Y = Font.Height + 3;
159                                 display_rectangle.Width = Width - 6;
160                                 display_rectangle.Height = Height - Font.Height - 6;
161                                 return display_rectangle;
162                         }
163                 }
164
165                 [DefaultValue(FlatStyle.Standard)]
166                 public FlatStyle FlatStyle {
167                         get { return flat_style; }
168                         set {
169                                 if (!Enum.IsDefined (typeof (FlatStyle), value))
170                                          new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for FlatStyle", value));
171
172                                 if (flat_style == value)
173                                         return;
174                                         
175                                 flat_style = value;
176                                 Refresh ();
177                         }
178                 }
179
180                 [Browsable(false)]
181                 [EditorBrowsable(EditorBrowsableState.Advanced)]
182                 public new bool TabStop {
183                         get { return base.TabStop;  }
184                         set { base.TabStop = value; }
185                 }
186
187                 [Localizable(true)]
188                 public override string Text {
189                         get { return base.Text; }
190                         set {
191                                 if (base.Text == value)
192                                         return;
193
194                                 base.Text = value;
195                                 Refresh ();
196                         }
197                 }
198
199                 #endregion //Public Properties
200
201                 #region Public Methods
202                 protected override void OnFontChanged (EventArgs e)
203                 {
204                         base.OnFontChanged (e);
205                         Refresh ();
206                 }
207
208                 protected override void OnPaint (PaintEventArgs pevent)
209                 {
210                         ThemeEngine.Current.DrawGroupBox (pevent.Graphics, ClientRectangle, this);
211                         base.OnPaint(pevent);
212                 }
213
214                 protected override bool ProcessMnemonic (char charCode)
215                 {
216                         if (IsMnemonic(charCode, Text) == true) {
217                                 // Select item next in line in tab order
218                                 if (this.Parent != null) {
219                                         Parent.SelectNextControl(this, true, false, true, false);
220                                 }
221                                 return true;
222                         }
223                         
224                         return base.ProcessMnemonic (charCode);
225                 }
226
227                 public override string ToString()
228                 {
229                         return GetType ().FullName.ToString () + ", Text: " + Text;
230                 }
231
232                 protected override void WndProc(ref Message m) {
233                         base.WndProc (ref m);
234                 }
235                                 
236                 #endregion Public Methods
237 #if NET_2_0
238                 [DefaultValue (false)]
239                 public bool UseCompatibleTextRendering {
240                         get {
241                                 return use_compatible_text_rendering;
242                         }
243
244                         set {
245                                 use_compatible_text_rendering = value;
246                         }
247                 }
248 #endif
249         }
250 }