* Control.cs : some fixes, added call to OnControlAdded, update visibility flag...
[mono.git] / mcs / class / System.Windows.Forms / System.Windows.Forms / GroupBox.cs
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 // (C) 2002/3 Ximian, Inc
8 //
9 using System.Drawing;
10
11 namespace System.Windows.Forms {
12
13         // <summary>
14         // </summary>
15
16         public class GroupBox : Control {
17
18                 //
19                 //  --- Constructor
20                 //
21
22                 [MonoTODO]
23                 public GroupBox() {
24                         //SubClassWndProc_ = true;
25                 }
26
27                 //
28                 //  --- Public Properties
29                 //
30
31                 [MonoTODO]
32                 public override bool AllowDrop {
33                         get {
34                                 //FIXME:
35                                 return base.AllowDrop;
36                         }
37                         set {
38                                 //FIXME:
39                                 base.AllowDrop = value;
40                         }
41                 }
42
43                 [MonoTODO]
44                 public override Rectangle DisplayRectangle {
45                         get {
46                                 //FIXME:
47                                 return base.DisplayRectangle;
48                         }
49                 }
50
51                 [MonoTODO]
52                 public FlatStyle FlatStyle {
53                         get {
54                                 throw new NotImplementedException ();
55                         }
56                         set {
57                                 //FIXME:
58                         }
59                 }
60
61                 //
62                 //  --- Public Methods
63                 //
64
65                 [MonoTODO]
66                 public override string ToString() {
67                         //FIXME:
68                         return base.ToString();
69                 }
70
71
72                 static private bool classRegistered = false;
73                 //
74                 //  --- Protected Properties
75                 //
76                 [MonoTODO]
77                 protected override CreateParams CreateParams {
78                         get {
79                                 if (!classRegistered) {
80                                         WNDCLASS wndClass = new WNDCLASS();
81  
82                                         wndClass.style = (int) (CS_.CS_DBLCLKS);
83                                         wndClass.lpfnWndProc = NativeWindow.GetWindowProc();
84                                         wndClass.cbClsExtra = 0;
85                                         wndClass.cbWndExtra = 0;
86                                         wndClass.hInstance = (IntPtr)0;
87                                         wndClass.hIcon = (IntPtr)0;
88                                         wndClass.hCursor = Win32.LoadCursor( (IntPtr)0, LC_.IDC_ARROW);
89                                         wndClass.hbrBackground = (IntPtr)((int)GetSysColorIndex.COLOR_BTNFACE + 1);
90                                         wndClass.lpszMenuName = "";
91                                         wndClass.lpszClassName = "mono_static_control";
92     
93                                         if (Win32.RegisterClass(ref wndClass) != 0) 
94                                                 classRegistered = true; 
95                                 }               
96
97                                 CreateParams createParams = base.CreateParams;
98         
99                                 createParams.ClassName = "mono_static_control";
100
101                                 createParams.Style = (int) (
102                                         (int)WindowStyles.WS_CHILDWINDOW |
103                                         (int)SS_Static_Control_Types.SS_LEFT |
104                                         (int)WindowStyles.WS_CLIPCHILDREN |
105                                         (int)WindowStyles.WS_CLIPSIBLINGS |
106                                         (int)WindowStyles.WS_OVERLAPPED |
107                                         (int)WindowStyles.WS_VISIBLE );
108
109                                 return createParams;
110                         }
111                 }
112
113                 [MonoTODO]
114                 protected override Size DefaultSize {
115                         get {
116                                 return new Size(200,100);//correct value
117                         }
118                 }
119
120                 //
121                 //  --- Protected Methods
122                 //
123
124                 [MonoTODO]
125                 protected override void OnFontChanged(EventArgs e) {
126                         //FIXME:
127                         base.OnFontChanged(e);
128                 }
129
130                 protected virtual void OnPaintBackground (PaintEventArgs e)
131                 {
132                 }
133
134                 [MonoTODO]
135                 protected override void OnPaint(PaintEventArgs e) {
136                         try {
137                                 //FIXME: use TextMetrics to calculate coordinates in the method
138                                 Rectangle bounds = new Rectangle(new Point(0,0), Size);
139
140                                 Bitmap bmp = new Bitmap(bounds.Width, bounds.Height, e.Graphics);
141                                 Graphics paintOn = Graphics.FromImage(bmp);
142
143                                 Brush br = new SolidBrush(BackColor);
144                                 paintOn.FillRectangle(br, bounds);
145                                 bounds.Inflate(-4,-4);
146                                 bounds.Y += 2;
147                                 ControlPaint.DrawBorder(paintOn, bounds, SystemColors.ControlDark, 1, ButtonBorderStyle.Solid,
148                                         SystemColors.ControlDark, 1, ButtonBorderStyle.Solid, SystemColors.ControlLightLight, 1, ButtonBorderStyle.Solid,
149                                         SystemColors.ControlLightLight, 1, ButtonBorderStyle.Solid);
150                                 bounds.Inflate(-1,-1);
151                                 ControlPaint.DrawBorder(paintOn, bounds, SystemColors.ControlLightLight, 1, ButtonBorderStyle.Solid,
152                                         SystemColors.ControlLightLight, 1, ButtonBorderStyle.Solid, SystemColors.ControlDark, 1, ButtonBorderStyle.Solid,
153                                         SystemColors.ControlDark, 1, ButtonBorderStyle.Solid);
154                                 SizeF sz = paintOn.MeasureString( Text, Font);
155                                 sz.Width += 2.0F;
156                                 paintOn.FillRectangle( br, new RectangleF(new PointF((float)bounds.Left + 3.0F, 0.0F), sz));
157                                 paintOn.DrawString(Text, Font, SystemBrushes.ControlText, (float)bounds.Left + 5, 0);
158                                 e.Graphics.DrawImage(bmp, 0, 0, bmp.Width, bmp.Height);
159                                 br.Dispose();
160                                 bmp.Dispose();
161                         }
162                         catch(Exception ex) {
163                         }
164                         //base.OnPaint(e);
165                 }
166
167                 [MonoTODO]
168                 protected override bool ProcessMnemonic(char charCode) {
169                         //FIXME:
170                         return base.ProcessMnemonic(charCode);
171                 }
172
173                 [MonoTODO]
174                 protected override void WndProc(ref Message m) {
175                         switch (m.Msg) {
176                                 case Msg.WM_ERASEBKGND:
177                                         m.Result = (IntPtr)1;
178                                         break;
179                                 default:
180                                         base.WndProc (ref m);
181                                         break;
182                         }
183                 }
184
185         }
186 }