**** Merged from MCS ****
[mono-project.git] / mcs / class / System.Windows.Forms / System.Windows.Forms / GroupBox.cs
blob14dbccf226e342e9d830b1b4de5de79d295f09e0
1 //
2 // System.Windows.Forms.GroupBox.cs
3 //
4 // Author:
5 // stubbed out by Daniel Carrera (dcarrera@math.toronto.edu)
6 // Dennis Hayes (dennish@raytek.com)
7 // Aleksey Ryabchuk (ryabchuk@yahoo.com)
8 //
9 // (C) 2002/3 Ximian, Inc
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Drawing;
33 using System.ComponentModel;
35 namespace System.Windows.Forms {
37 // <summary>
38 // Represents a Windows group box.
39 // </summary>
41 public class GroupBox : Control {
43 FlatStyle flatStyle;
45 [MonoTODO]
46 public GroupBox() {
47 SetStyle ( ControlStyles.UserPaint, true);
48 SetStyle ( ControlStyles.Selectable, false );
49 TabStop = false;
50 flatStyle = FlatStyle.Standard;
53 [EditorBrowsable (EditorBrowsableState.Never)]
54 public override bool AllowDrop {
55 get { return base.AllowDrop; }
56 set { base.AllowDrop = value; }
59 [MonoTODO]
60 public override Rectangle DisplayRectangle {
61 get {
62 //FIXME:
63 return base.DisplayRectangle;
67 [MonoTODO]
68 public FlatStyle FlatStyle {
69 get { return flatStyle; }
70 set {
71 if ( !Enum.IsDefined ( typeof(FlatStyle), value ) )
72 throw new InvalidEnumArgumentException( "FlatStyle",
73 (int)value,
74 typeof(FlatStyle));
75 flatStyle = value;
79 public override string ToString() {
80 return GetType ( ).FullName.ToString ( ) + ", Text: " + Text;
83 [MonoTODO]
84 protected override CreateParams CreateParams {
85 get {
86 RegisterDefaultWindowClass ( );
88 CreateParams createParams = base.CreateParams;
89 createParams.ClassName = Win32.DEFAULT_WINDOW_CLASS;;
91 createParams.Style = (int) (
92 (int)WindowStyles.WS_CHILDWINDOW |
93 (int)WindowStyles.WS_CLIPCHILDREN |
94 (int)WindowStyles.WS_CLIPSIBLINGS |
95 (int)WindowStyles.WS_OVERLAPPED |
96 (int)WindowStyles.WS_VISIBLE );
98 return createParams;
102 protected override Size DefaultSize {
103 get { return new Size(200,100); }
106 [MonoTODO]
107 protected override void OnFontChanged(EventArgs e) {
108 base.OnFontChanged(e);
109 Invalidate ( );
112 public override string Text {
113 get { return base.Text; }
114 set {
115 base.Text = value;
116 Invalidate ( );
120 [MonoTODO]
121 protected override void OnPaint(PaintEventArgs e) {
122 try {
123 //FIXME: use TextMetrics to calculate coordinates in the method
124 Rectangle bounds = DisplayRectangle;
126 Bitmap bmp = new Bitmap(bounds.Width, bounds.Height, e.Graphics);
127 Graphics paintOn = Graphics.FromImage(bmp);
129 Brush br = new SolidBrush(BackColor);
130 paintOn.FillRectangle(br, bounds);
132 bounds.Y += 5;
133 bounds.Height -= 5;
136 bounds.Inflate(-4,-4);
137 bounds.Y += 2;
139 Color dark = ControlPaint.DarkDark ( BackColor );
140 Color light = ControlPaint.LightLight ( BackColor );
142 ControlPaint.DrawBorder(paintOn, bounds, dark, 1, ButtonBorderStyle.Solid,
143 dark, 1, ButtonBorderStyle.Solid, light, 1, ButtonBorderStyle.Solid,
144 light, 1, ButtonBorderStyle.Solid);
145 bounds.Inflate(-1,-1);
146 ControlPaint.DrawBorder(paintOn, bounds, light, 1, ButtonBorderStyle.Solid,
147 light, 1, ButtonBorderStyle.Solid, dark, 1, ButtonBorderStyle.Solid,
148 dark, 1, ButtonBorderStyle.Solid);
150 SizeF sz = paintOn.MeasureString( Text, Font);
151 sz.Width += 2.0F;
152 paintOn.FillRectangle( br, new RectangleF(new PointF((float)bounds.Left + 3.0F, 0.0F), sz));
154 //JORDI: BUG BUG
155 //paintOn.DrawString(Text, Font, SystemBrushes.ControlText, (float)bounds.Left + 5, 0);
156 e.Graphics.DrawImage(bmp, 0, 0, bmp.Width, bmp.Height);
157 br.Dispose();
158 bmp.Dispose();
160 catch/*(Exception ex)*/ {
162 //base.OnPaint(e);
165 [MonoTODO]
166 protected override bool ProcessMnemonic(char charCode) {
167 //FIXME:
168 return base.ProcessMnemonic(charCode);
171 [MonoTODO]
172 protected override void WndProc(ref Message m) {
173 switch ((Msg) m.Msg) {
174 case Msg.WM_ERASEBKGND:
175 m.Result = (IntPtr)1;
176 break;
177 default:
178 base.WndProc (ref m);
179 break;