* ImageList.cs: When the image stream is set pull all the images
[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 // COMPLETE
33
34 using System.Drawing;
35 using System.ComponentModel;
36 using System.ComponentModel.Design;
37
38 namespace System.Windows.Forms
39 {
40         [DefaultProperty("Text")]
41         [DefaultEvent("Enter")]
42         [Designer ("System.Windows.Forms.Design.GroupBoxDesigner, " + Consts.AssemblySystem_Design, (string)null)]
43         public class GroupBox : Control
44         {
45                 private FlatStyle flat_style;
46                 private Rectangle display_rectangle = new Rectangle ();
47
48                 #region Events
49                 [Browsable(false)]
50                 [EditorBrowsable(EditorBrowsableState.Advanced)]
51                 public new event EventHandler Click;
52
53                 [Browsable(false)]
54                 [EditorBrowsable(EditorBrowsableState.Advanced)]
55                 public new event EventHandler DoubleClick;
56
57                 [Browsable(false)]
58                 [EditorBrowsable(EditorBrowsableState.Advanced)]
59                 public new event KeyEventHandler KeyDown;
60
61                 [Browsable(false)]
62                 [EditorBrowsable(EditorBrowsableState.Advanced)]
63                 public new event KeyPressEventHandler KeyPress;
64
65                 [Browsable(false)]
66                 [EditorBrowsable(EditorBrowsableState.Advanced)]
67                 public new event KeyEventHandler KeyUp;
68
69                 [Browsable(false)]
70                 [EditorBrowsable(EditorBrowsableState.Advanced)]
71                 public new event MouseEventHandler MouseDown;
72
73                 [Browsable(false)]
74                 [EditorBrowsable(EditorBrowsableState.Advanced)]
75                 public new event EventHandler MouseEnter;
76
77                 [Browsable(false)]
78                 [EditorBrowsable(EditorBrowsableState.Advanced)]
79                 public new event EventHandler MouseLeave;
80
81                 [Browsable(false)]
82                 [EditorBrowsable(EditorBrowsableState.Advanced)]
83                 public new event MouseEventHandler MouseMove;
84
85                 [Browsable(false)]
86                 [EditorBrowsable(EditorBrowsableState.Advanced)]
87                 public new event MouseEventHandler MouseUp;
88
89                 [Browsable(false)]
90                 [EditorBrowsable(EditorBrowsableState.Advanced)]
91                 public new event EventHandler TabStopChanged;
92                 #endregion Events
93
94                 public GroupBox ()
95                 {
96                         TabStop = false;
97                         flat_style = FlatStyle.Standard;
98
99                         SetStyle(ControlStyles.ContainerControl, true);
100                         SetStyle(ControlStyles.Selectable, false);
101                         SetStyle (ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
102                 }
103
104                 #region Public Properties
105                 [Browsable(false)]
106                 [EditorBrowsable(EditorBrowsableState.Advanced)]
107                 public override bool AllowDrop {
108                         get { return base.AllowDrop;  }
109                         set { base.AllowDrop = value; }
110                 }
111
112                 protected override CreateParams CreateParams {
113                         get { return base.CreateParams; }
114                 }
115
116                 protected override Size DefaultSize {
117                         get { return ThemeEngine.Current.GroupBoxDefaultSize;}
118                 }
119
120                 public override Rectangle DisplayRectangle {
121                         get {
122                                 display_rectangle.X = 3;
123                                 display_rectangle.Y = Font.Height + 3;
124                                 display_rectangle.Width = Width - 6;
125                                 display_rectangle.Height = Height - Font.Height - 6;
126                                 return display_rectangle;
127                         }
128                 }
129
130                 [DefaultValue(FlatStyle.Standard)]
131                 public FlatStyle FlatStyle {
132                         get { return flat_style; }
133                         set {
134                                 if (!Enum.IsDefined (typeof (FlatStyle), value))
135                                          new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for FlatStyle", value));
136
137                                 if (flat_style == value)
138                                         return;
139                                         
140                                 flat_style = value;
141                                 Refresh ();
142                         }
143                 }
144
145                 [Browsable(false)]
146                 [EditorBrowsable(EditorBrowsableState.Advanced)]
147                 public new bool TabStop {
148                         get { return base.TabStop;  }
149                         set { base.TabStop = value; }
150                 }
151
152                 [Localizable(true)]
153                 public override string Text {
154                         get { return base.Text; }
155                         set {
156                                 if (base.Text == value)
157                                         return;
158
159                                 base.Text = value;
160                                 Refresh ();
161                         }
162                 }
163
164                 #endregion //Public Properties
165
166                 #region Public Methods
167                 protected override void OnFontChanged (EventArgs e)
168                 {
169                         base.OnFontChanged (e);
170                         Refresh ();
171                 }
172
173                 protected override void OnPaint (PaintEventArgs pevent)
174                 {
175                         Draw ();
176                         pevent.Graphics.DrawImage (ImageBuffer, 0, 0);
177                 }
178
179                 protected override bool ProcessMnemonic (char charCode)
180                 {
181                         if (IsMnemonic(charCode, Text) == true) {
182                                 // Select item next in line in tab order
183                                 if (this.parent != null) {
184                                         parent.SelectNextControl(this, true, false, true, false);
185                                 }
186                                 return true;
187                         }
188                         
189                         return base.ProcessMnemonic (charCode);
190                 }
191
192                 public override string ToString()
193                 {
194                         return GetType ().FullName.ToString () + ", Text: " + Text;
195                 }
196
197                 protected override void WndProc(ref Message m) {
198                         switch ((Msg) m.Msg) {
199                                 case Msg.WM_ERASEBKGND:
200                                         m.Result = (IntPtr)1;
201                                         break;
202                                 default:
203                                         base.WndProc (ref m);
204                                         break;
205                         }
206                 }
207                                 
208                 #endregion Public Methods
209                 
210                 #region Private Methods
211
212                 private void Draw ()
213                 {                       
214                         ThemeEngine.Current.DrawGroupBox (DeviceContext, ClientRectangle, this);                        
215                 }
216                 
217                 #endregion // Private Methods
218         }
219 }