2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[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 // Autors:
24 //              Jordi Mas i Hernandez, jordi@ximian.com
25 //
26 // TODO:
27 //
28 // Copyright (C) Novell Inc., 2004
29 //
30 //
31
32 // COMPLETE
33
34 using System.Drawing;
35 using System.ComponentModel;
36
37 namespace System.Windows.Forms
38 {
39         public class GroupBox : Control
40         {
41                 private FlatStyle flat_style;
42                 private Rectangle display_rectangle = new Rectangle ();
43
44                 #region Events
45                 public new event EventHandler Click;
46                 public new event EventHandler DoubleClick;
47                 public new event KeyEventHandler KeyDown;
48                 public new event KeyPressEventHandler KeyPress;
49                 public new event KeyEventHandler KeyUp;
50                 public new event MouseEventHandler MouseDown;
51                 public new event EventHandler MouseEnter;
52                 public new event EventHandler MouseLeave;
53                 public new event MouseEventHandler MouseMove;
54                 public new event MouseEventHandler MouseUp;
55                 public new event EventHandler TabStopChanged;
56                 #endregion Events
57
58                 public GroupBox ()
59                 {
60                         TabStop = false;
61                         flat_style = FlatStyle.Standard;
62
63                         SetStyle(ControlStyles.ContainerControl, true);
64                         SetStyle(ControlStyles.Selectable, false);
65                 }
66
67                 #region Public Properties
68                 public override bool AllowDrop {
69                         get { return base.AllowDrop;  }
70                         set { base.AllowDrop = value; }
71                 }
72
73                 protected override CreateParams CreateParams {
74                         get { return base.CreateParams; }
75                 }
76
77                 protected override Size DefaultSize {
78                         get { return ThemeEngine.Current.GroupBoxDefaultSize;}
79                 }
80
81                 public override Rectangle DisplayRectangle {
82                         get {
83                                 display_rectangle.X = 3;
84                                 display_rectangle.Y = Font.Height + 3;
85                                 display_rectangle.Width = Width - 6;
86                                 display_rectangle.Height = Height - Font.Height - 6;
87                                 return display_rectangle;
88                         }
89                 }
90
91                 public FlatStyle FlatStyle {
92                         get { return flat_style; }
93                         set {
94                                 if (!Enum.IsDefined (typeof (FlatStyle), value))
95                                          new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for FlatStyle", value));
96
97                                 if (flat_style == value)
98                                         return;
99                                         
100                                 flat_style = value;
101                                 Refresh ();
102                         }
103                 }
104
105                 public new bool TabStop {
106                         get { return base.TabStop;  }
107                         set { base.TabStop = value; }
108                 }
109
110                 public override string Text {
111                         get { return base.Text; }
112                         set {
113                                 if (base.Text == value)
114                                         return;
115
116                                 base.Text = value;
117                                 Refresh ();
118                         }
119                 }
120
121                 #endregion //Public Properties
122
123                 #region Public Methods
124                 protected override void OnFontChanged (EventArgs e)
125                 {
126                         base.OnFontChanged (e);
127                         Refresh ();
128                 }
129
130                 protected override void OnPaint (PaintEventArgs pevent)
131                 {
132                         Draw ();
133                         pevent.Graphics.DrawImage (ImageBuffer, 0, 0);
134                 }
135
136                 protected override bool ProcessMnemonic (char charCode)
137                 {
138                         return base.ProcessMnemonic(charCode);
139                 }
140
141                 public override string ToString()
142                 {
143                         return GetType ().FullName.ToString () + ", Text: " + Text;
144                 }
145
146                 protected override void WndProc(ref Message m) {
147                         switch ((Msg) m.Msg) {
148                                 case Msg.WM_ERASEBKGND:
149                                         m.Result = (IntPtr)1;
150                                         break;
151                                 default:
152                                         base.WndProc (ref m);
153                                         break;
154                         }
155                 }
156                                 
157                 #endregion Public Methods
158                 
159                 #region Private Methods
160
161                 private void Draw ()
162                 {                       
163                         ThemeEngine.Current.DrawGroupBox (DeviceContext, ClientRectangle, this);                        
164                 }
165                 
166                 #endregion // Private Methods
167         }
168 }