* TabControl.cs: Show the tooltip depending on the value
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / Panel.cs
1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
8 //
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 //
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 //
20 // Copyright (c) 2004-2005 Novell, Inc.
21 //
22 // Authors:
23 //      Jackson Harper (jackson@ximian.com)
24 //
25
26 // COMPLETE
27
28 using System;
29 using System.ComponentModel;
30 using System.ComponentModel.Design;
31 using System.Drawing;
32 using System.Runtime.InteropServices;
33
34 namespace System.Windows.Forms {
35         [DefaultProperty("BorderStyle")]
36         [DefaultEvent("Paint")]
37         [Designer ("System.Windows.Forms.Design.PanelDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
38 #if NET_2_0
39         [Docking (DockingBehavior.Ask)]
40         [ClassInterface (ClassInterfaceType.AutoDispatch)]
41         [ComVisible (true)]
42 #endif
43         public class Panel : ScrollableControl {
44                 #region Constructors & Destructors
45                 public Panel () {
46                         base.TabStop = false;
47                         SetStyle(ControlStyles.Selectable, false);
48                         SetStyle (ControlStyles.SupportsTransparentBackColor, true);
49                 }
50                 #endregion      // Constructors & Destructors
51
52                 #region Public Instance Properties
53 #if NET_2_0
54                 [Browsable (true)]
55                 [EditorBrowsable (EditorBrowsableState.Always)]
56                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Visible)]
57                 public override bool AutoSize {
58                         get { return base.AutoSize; }
59                         set { base.AutoSize = value; }
60                 }
61                 
62                 [Browsable (true)]
63                 [DefaultValue (AutoSizeMode.GrowOnly)]
64                 [Localizable (true)]
65                 public virtual AutoSizeMode AutoSizeMode {
66                         get { return base.GetAutoSizeMode (); }
67                         set { base.SetAutoSizeMode (value); }
68                 }
69 #endif
70
71                 [DefaultValue(BorderStyle.None)]
72                 [DispId(-504)]
73                 public BorderStyle BorderStyle {
74                         get { return InternalBorderStyle; }
75                         set { InternalBorderStyle = value; }
76                 }
77
78                 [DefaultValue(false)]
79                 public new bool TabStop {
80                         get { return base.TabStop; }
81                         set {
82                                 if (value == TabStop)
83                                         return;
84                                 base.TabStop = value;
85                         }
86                 }
87
88                 [Bindable(false)]
89                 [Browsable(false)]
90                 [EditorBrowsable(EditorBrowsableState.Never)]
91                 public override string Text {
92                         get { return base.Text; }
93                         set {
94                                 if (value == Text)
95                                         return;
96                                 base.Text = value;
97                                 Refresh ();
98                         }
99                 }
100                 #endregion      // Public Instance Properties
101
102                 #region Protected Instance Properties
103                 protected override CreateParams CreateParams {
104                         get {
105                                 return base.CreateParams;
106                         }
107                 }
108
109                 protected override Size DefaultSize {
110                         get { return ThemeEngine.Current.PanelDefaultSize; }
111                 }
112                 #endregion      // Proteced Instance Properties
113
114                 #region Public Instance Methods
115                 public override string ToString ()
116                 {
117                         return base.ToString () + ", BorderStyle: " + BorderStyle;
118                 }
119                 #endregion      // Public Instance Methods
120
121                 #region Protected Instance Methods
122                 protected override void OnResize(EventArgs eventargs) {
123                         base.OnResize (eventargs);
124                         Invalidate(true);
125                 }
126
127                 #endregion      // Protected Instance Methods
128
129                 #region Events
130 #if NET_2_0
131                 [Browsable (true)]
132                 [EditorBrowsable (EditorBrowsableState.Always)]
133                 public new event EventHandler AutoSizeChanged {
134                         add { base.AutoSizeChanged += value; }
135                         remove { base.AutoSizeChanged -= value; }
136                 }
137 #endif
138
139                 [Browsable(false)]
140                 [EditorBrowsable(EditorBrowsableState.Never)]
141                 public new event KeyEventHandler KeyDown {
142                         add { base.KeyDown += value; }
143                         remove { base.KeyDown -= value; }
144                 }
145
146                 [Browsable(false)]
147                 [EditorBrowsable(EditorBrowsableState.Never)]
148                 public new event KeyPressEventHandler KeyPress {
149                         add { base.KeyPress += value; }
150                         remove { base.KeyPress -= value; }
151                 }
152
153                 [Browsable(false)]
154                 [EditorBrowsable(EditorBrowsableState.Never)]
155                 public new event KeyEventHandler KeyUp {
156                         add { base.KeyUp += value; }
157                         remove { base.KeyUp -= value; }
158                 }
159
160                 [Browsable(false)]
161                 [EditorBrowsable(EditorBrowsableState.Never)]
162                 public new event EventHandler TextChanged {
163                         add { base.TextChanged += value; }
164                         remove { base.TextChanged -= value; }
165                 }
166                 #endregion
167
168                 #region Internal Methods
169 #if NET_2_0
170                 internal override Size GetPreferredSizeCore (Size proposedSize)
171                 {
172                         Size retsize = Size.Empty;
173
174                         foreach (Control child in Controls) {
175                                 if (child.Dock == DockStyle.Fill) {
176                                         if (child.Bounds.Right > retsize.Width)
177                                                 retsize.Width = child.Bounds.Right;
178                                 } else if (child.Dock != DockStyle.Top && child.Dock != DockStyle.Bottom && (child.Anchor & AnchorStyles.Right) == 0 && (child.Bounds.Right + child.Margin.Right) > retsize.Width)
179                                         retsize.Width = child.Bounds.Right + child.Margin.Right;
180
181                                 if (child.Dock == DockStyle.Fill) {
182                                         if (child.Bounds.Bottom > retsize.Height)
183                                                 retsize.Height = child.Bounds.Bottom;
184                                 } else if (child.Dock != DockStyle.Left && child.Dock != DockStyle.Right && (child.Anchor & AnchorStyles.Bottom) == 0 && (child.Bounds.Bottom + child.Margin.Bottom) > retsize.Height)
185                                         retsize.Height = child.Bounds.Bottom + child.Margin.Bottom;
186                         }
187
188                         return retsize;
189                 }
190 #endif
191                 #endregion
192         }
193 }
194