* TabControl.cs: Show the tooltip depending on the value
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / TabPage.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 using System;
27 using System.ComponentModel;
28 using System.ComponentModel.Design;
29 using System.Drawing;
30 using System.Runtime.InteropServices;
31
32 namespace System.Windows.Forms {
33 #if NET_2_0
34         [ComVisible (true)]
35         [ClassInterface (ClassInterfaceType.AutoDispatch)]
36 #endif
37         [DefaultEvent("Click")]
38         [DesignTimeVisible(false)]
39         [DefaultProperty("Text")]
40         [Designer("System.Windows.Forms.Design.TabPageDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
41         [ToolboxItem(false)]
42         public class TabPage : Panel {
43                 #region Fields
44                 private int imageIndex = -1;
45 #if NET_2_0
46                 private string imageKey;
47 #endif
48                 private string tooltip_text = String.Empty;
49                 private Rectangle tab_bounds;
50                 private int row;
51 #if NET_2_0
52                 private bool use_visual_style_back_color;
53 #endif
54                 #endregion      // Fields
55                 
56                 #region Public Constructors
57                 public TabPage ()
58                 {
59                         Visible = true;
60
61                         SetStyle (ControlStyles.CacheText, true);
62                 }
63
64                 public TabPage (string text) : base ()
65                 {
66                         base.Text = text;
67                 }
68
69                 #endregion      // Public Constructors
70
71                 #region .NET 2.0 Public Instance Properties
72 #if NET_2_0
73                 [Browsable (false)]
74                 [EditorBrowsable (EditorBrowsableState.Never)]
75                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
76                 public override bool AutoSize {
77                         get { return base.AutoSize; }
78                         set { base.AutoSize = value; }
79                 }
80
81                 [Browsable (false)]
82                 [Localizable (false)]
83                 [EditorBrowsable (EditorBrowsableState.Never)]
84                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
85                 public override AutoSizeMode AutoSizeMode {
86                         get { return base.AutoSizeMode; }
87                         set { base.AutoSizeMode = value; }
88                 }
89
90                 [Browsable (false)]
91                 [DefaultValue ("{Width=0, Height=0}")]
92                 [EditorBrowsable (EditorBrowsableState.Never)]
93                 public override Size MaximumSize {
94                         get { return base.MaximumSize; }
95                         set { base.MaximumSize = value; }
96                 }
97
98                 [Browsable (false)]
99                 [EditorBrowsable (EditorBrowsableState.Never)]
100                 public override Size MinimumSize {
101                         get { return base.MinimumSize; }
102                         set { base.MinimumSize = value; }
103                 }
104
105                 [Browsable (false)]
106                 [EditorBrowsable (EditorBrowsableState.Never)]
107                 public new Size PreferredSize {
108                         get { return base.PreferredSize; }
109                 }
110                 
111                 [DefaultValue (false)]
112                 public bool UseVisualStyleBackColor {
113                         get { return use_visual_style_back_color; }
114                         set { use_visual_style_back_color = value; }
115                 }
116
117                 public override Color BackColor {
118                         get { return base.BackColor; }
119                         set { use_visual_style_back_color = false; base.BackColor = value; }
120                 }
121 #endif
122                 #endregion
123
124                 #region Public Instance Properties
125                 [Browsable(false)]
126                 [EditorBrowsable(EditorBrowsableState.Never)]
127                 public override AnchorStyles Anchor {
128                         get { return base.Anchor; }
129                         set { base.Anchor = value; }
130                 }
131
132                 [Browsable(false)]
133                 [EditorBrowsable(EditorBrowsableState.Never)]
134                 public override DockStyle Dock {
135                         get { return base.Dock; }
136                         set { base.Dock = value; }
137                 }
138
139                 [Browsable(false)]
140                 [EditorBrowsable(EditorBrowsableState.Never)]
141                 public new bool Enabled {
142                         get { return base.Enabled; }
143                         set { base.Enabled = value; }
144                 }
145
146 #if NET_2_0
147                 [RefreshProperties (RefreshProperties.Repaint)]
148 #endif
149                 [DefaultValue(-1)]
150                 [Editor("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design, typeof(System.Drawing.Design.UITypeEditor))]
151                 [Localizable(true)]
152                 [TypeConverter(typeof(ImageIndexConverter))]
153                 public int ImageIndex {
154                         get { return imageIndex; }
155                         set {
156                                 if (imageIndex == value)
157                                         return;
158                                 imageIndex = value;
159                                 UpdateOwner ();
160                         }
161                 }
162
163 #if NET_2_0
164                 [Localizable (true)]
165                 [RefreshProperties (RefreshProperties.Repaint)]
166                 [DefaultValue ("")]
167                 [Editor ("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design,
168                          "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
169                 [TypeConverter (typeof (ImageKeyConverter))]
170                 public string ImageKey
171                 {
172                         get { return imageKey; }
173                         set {
174                                 imageKey = value;
175                                 TabControl control = this.Parent as TabControl;
176                                 if (control != null) {
177                                         ImageIndex = control.ImageList.Images.IndexOfKey (imageKey);
178                                 }
179                         }
180                 }
181
182 #endif
183
184                 [Browsable(false)]
185                 [EditorBrowsable(EditorBrowsableState.Never)]
186                 public new int TabIndex {
187                         get { return base.TabIndex; }
188                         set { base.TabIndex = value; }
189                 }
190
191                 [Browsable(false)]
192                 [EditorBrowsable(EditorBrowsableState.Never)]
193                 public new bool TabStop {
194                         get { return base.TabStop; }
195                         set { base.TabStop = value; }
196                 }
197
198 #if NET_2_0
199                 [EditorBrowsable (EditorBrowsableState.Always)]
200 #endif
201                 [Browsable(true)]
202                 [Localizable(true)]
203                 public override string Text {
204                         get { return base.Text; }
205                         set {
206                                 if (value == base.Text)
207                                         return;
208                                 base.Text = value;
209                                 UpdateOwner ();
210                         }
211                 }
212
213                 [Localizable(true)]
214                 [DefaultValue("")]
215                 public string ToolTipText {
216                         get { return tooltip_text; }
217                         set {
218                                 if (value == null)
219                                         value = String.Empty;
220                                 tooltip_text = value;
221                         }
222                 }
223
224                 [Browsable(false)]
225                 [EditorBrowsable(EditorBrowsableState.Never)]
226                 public new bool Visible {
227                         get { return base.Visible; }
228                         set { /* according to MS docs we can ignore this */ }
229                 }
230
231                 #endregion      // Public Instance Properties
232
233                 #region Public Static Methods
234                 public static TabPage GetTabPageOfComponent (object comp)
235                 {
236                         Control control = comp as Control;
237                         if (control == null)
238                                 return null;
239                         control = control.Parent;
240                         while (control != null) {
241                                 if (control is TabPage)
242                                         break;
243                                 control = control.Parent;
244                         }
245                         return control as TabPage;
246                 }
247
248                 #endregion      // Public Static Methods
249
250                 #region Public Instance Methods
251                 public override string ToString ()
252                 {
253                         return "TabPage: {" + Text + "}";
254                 }
255
256                 #endregion      // Public Instance Methods
257
258                 #region Internal & Private Methods and Properties
259                 internal Rectangle TabBounds {
260                         get { return tab_bounds; }
261                         set { tab_bounds = value; }
262                 }
263
264                 internal int Row {
265                         get { return row; }
266                         set { row = value; }
267                 }
268
269                 private void UpdateOwner ()
270                 {
271                         if (Owner != null) {
272                                 Owner.Redraw ();
273                         }
274                 }
275
276                 private TabControl Owner {
277                         get { return base.Parent as TabControl; }
278                 }
279
280                 internal void SetVisible (bool value)
281                 {
282                         base.Visible = value;
283                 }
284
285                 #endregion      // Internal & Private Methods and Properties
286
287                 #region Protected Instance Methods
288                 protected override ControlCollection CreateControlsInstance ()
289                 {
290                         return new TabPageControlCollection (this);
291                 }
292
293                 protected override void SetBoundsCore (int x, int y, int width, int height, BoundsSpecified specified) 
294                 {
295                         if (Owner != null && Owner.IsHandleCreated) {
296                                 Rectangle display = Owner.DisplayRectangle;
297
298                                 base.SetBoundsCore (display.X, display.Y,
299                                                         display.Width, display.Height,
300                                                         BoundsSpecified.All);
301                         } else {
302                                 base.SetBoundsCore (x, y, width, height, specified);
303                         }
304                 }
305
306 #if NET_2_0
307                 protected override void OnEnter (EventArgs e)
308                 {
309                         base.OnEnter (e);
310                 }
311
312                 protected override void OnLeave (EventArgs e)
313                 {
314                         base.OnLeave (e);
315                 }
316
317                 protected override void OnPaintBackground (PaintEventArgs e)
318                 {
319                         base.OnPaintBackground (e);
320                 }
321 #endif
322                 #endregion      // Protected Instance Methods
323
324                 #region Events
325 #if NET_2_0
326                 [Browsable (false)]
327                 [EditorBrowsable (EditorBrowsableState.Never)]
328                 public new event EventHandler AutoSizeChanged {
329                         add { base.AutoSizeChanged += value; }
330                         remove { base.AutoSizeChanged -= value; }
331                 }
332 #endif
333
334                 [Browsable(false)]
335                 [EditorBrowsable(EditorBrowsableState.Never)]
336                 public new event EventHandler DockChanged {
337                         add { base.DockChanged += value; }
338                         remove { base.DockChanged -= value; }
339                 }
340
341                 [Browsable(false)]
342                 [EditorBrowsable(EditorBrowsableState.Never)]
343                 public new event EventHandler EnabledChanged {
344                         add { base.EnabledChanged += value; }
345                         remove { base.EnabledChanged -= value; }
346                 }
347
348 #if NET_2_0
349                 [Browsable (false)]
350                 [EditorBrowsable (EditorBrowsableState.Never)]
351                 public new event EventHandler LocationChanged {
352                         add { base.LocationChanged += value; }
353                         remove { base.LocationChanged -= value; }
354                 }
355 #endif
356
357                 [Browsable(false)]
358                 [EditorBrowsable(EditorBrowsableState.Never)]
359                 public new event EventHandler TabIndexChanged {
360                         add { base.TabIndexChanged += value; }
361                         remove { base.TabIndexChanged -= value; }
362                 }
363
364                 [Browsable(false)]
365                 [EditorBrowsable(EditorBrowsableState.Never)]
366                 public new event EventHandler TabStopChanged {
367                         add { base.TabStopChanged += value; }
368                         remove { base.TabStopChanged -= value; }
369                 }
370
371 #if NET_2_0
372                 [Browsable (true)]
373                 [EditorBrowsable (EditorBrowsableState.Always)]
374                 public new event EventHandler TextChanged {
375                         add { base.TextChanged += value; }
376                         remove { base.TextChanged -= value; }
377                 }
378 #endif
379
380                 [Browsable(false)]
381                 [EditorBrowsable(EditorBrowsableState.Never)]
382                 public new event EventHandler VisibleChanged {
383                         add { base.VisibleChanged += value; }
384                         remove { base.VisibleChanged -= value; }
385                 }
386
387                 #endregion      // Events
388
389 #if NET_2_0
390                 [Browsable (false)]
391                 [EditorBrowsable (EditorBrowsableState.Never)]
392                 public new Point Location {
393                         get {
394                                 return base.Location;
395                         }
396
397                         set {
398                                 base.Location = value;
399                         }
400                 }
401 #endif
402                 #region Class TabPageControlCollection
403 #if NET_2_0
404                 [ComVisible (false)]
405 #endif
406                 public class TabPageControlCollection : ControlCollection {
407
408                         //private TabPage owner;
409
410                         public TabPageControlCollection (TabPage owner) : base (owner)
411                         {
412                                 //this.owner = owner;
413                         }
414
415                         public override void Add (Control value)
416                         {
417                                 base.Add (value);
418                         }
419                 }
420                 #endregion      // Class TabPageControlCollection
421
422         }
423
424         
425 }