2006-12-04 Chris Toshok <toshok@ximian.com>
[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
31 namespace System.Windows.Forms {
32         [DefaultEvent("Click")]
33         [DesignTimeVisible(false)]
34         [DefaultProperty("Text")]
35         [Designer("System.Windows.Forms.Design.TabPageDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
36         [ToolboxItem(false)]
37         public class TabPage : Panel {
38                 #region Fields
39                 private int image_index = -1;
40                 private string tooltip_text = String.Empty;
41                 private Rectangle tab_bounds;
42                 private int row;
43                 private bool use_visual_style_back_color;
44                 #endregion      // Fields
45                 
46                 #region Public Constructors
47                 public TabPage ()
48                 {
49                         Visible = true;
50
51                         SetStyle (ControlStyles.CacheText, true);
52                 }
53
54                 public TabPage (string text) : base ()
55                 {
56                         base.Text = text;
57                 }
58
59                 #endregion      // Public Constructors
60
61                 #region .NET 2.0 Public Instance Properties
62 #if NET_2_0
63                 public bool UseVisualStyleBackColor {
64                         get { return use_visual_style_back_color; }
65                         set { use_visual_style_back_color = value; }
66                 }
67
68                 public override Color BackColor {
69                         get { return base.BackColor; }
70                         set { use_visual_style_back_color = false; base.BackColor = value; }
71                 }
72 #endif
73                 #endregion
74
75                 #region Public Instance Properties
76                 [Browsable(false)]
77                 [EditorBrowsable(EditorBrowsableState.Never)]
78                 public override AnchorStyles Anchor {
79                         get { return base.Anchor; }
80                         set { base.Anchor = value; }
81                 }
82
83                 [Browsable(false)]
84                 [EditorBrowsable(EditorBrowsableState.Never)]
85                 public override DockStyle Dock {
86                         get { return base.Dock; }
87                         set { base.Dock = value; }
88                 }
89
90                 [Browsable(false)]
91                 [EditorBrowsable(EditorBrowsableState.Never)]
92                 public new bool Enabled {
93                         get { return base.Enabled; }
94                         set { base.Enabled = value; }
95                 }
96
97                 [DefaultValue(-1)]
98                 [Editor("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design, typeof(System.Drawing.Design.UITypeEditor))]
99                 [Localizable(true)]
100                 [TypeConverter(typeof(ImageIndexConverter))]
101                 public int ImageIndex {
102                         get { return image_index; }
103                         set {
104                                 if (image_index == value)
105                                         return;
106                                 image_index = value;
107                                 UpdateOwner ();
108                         }
109                 }
110
111                 [Browsable(false)]
112                 [EditorBrowsable(EditorBrowsableState.Never)]
113                 public new int TabIndex {
114                         get { return base.TabIndex; }
115                         set { base.TabIndex = value; }
116                 }
117
118                 [Browsable(false)]
119                 [EditorBrowsable(EditorBrowsableState.Never)]
120                 public new bool TabStop {
121                         get { return base.TabStop; }
122                         set { base.TabStop = value; }
123                 }
124
125                 [Browsable(true)]
126                 [Localizable(true)]
127                 public override string Text {
128                         get { return base.Text; }
129                         set {
130                                 if (value == base.Text)
131                                         return;
132                                 base.Text = value;
133                                 UpdateOwner ();
134                         }
135                 }
136
137                 [Localizable(true)]
138                 [DefaultValue("")]
139                 public string ToolTipText {
140                         get { return tooltip_text; }
141                         set {
142                                 if (value == null)
143                                         value = String.Empty;
144                                 tooltip_text = value;
145                         }
146                 }
147
148                 [Browsable(false)]
149                 [EditorBrowsable(EditorBrowsableState.Never)]
150                 public new bool Visible {
151                         get { return base.Visible; }
152                         set { /* according to MS docs we can ignore this */ }
153                 }
154
155                 #endregion      // Public Instance Properties
156
157                 #region Public Static Methods
158                 public static TabPage GetTabPageOfComponent (object comp)
159                 {
160                         Control control = comp as Control;
161                         if (control == null)
162                                 return null;
163                         control = control.Parent;
164                         while (control != null) {
165                                 if (control is TabPage)
166                                         break;
167                                 control = control.Parent;
168                         }
169                         return control as TabPage;
170                 }
171
172                 #endregion      // Public Static Methods
173
174                 #region Public Instance Methods
175                 public override string ToString ()
176                 {
177                         return "TabPage: {" + Text + "}";
178                 }
179
180                 #endregion      // Public Instance Methods
181
182                 #region Internal & Private Methods and Properties
183                 internal Rectangle TabBounds {
184                         get { return tab_bounds; }
185                         set { tab_bounds = value; }
186                 }
187
188                 internal int Row {
189                         get { return row; }
190                         set { row = value; }
191                 }
192
193                 private void UpdateOwner ()
194                 {
195                         if (Owner != null) {
196                                 Owner.Redraw ();
197                         }
198                 }
199
200                 private TabControl Owner {
201                         get { return base.Parent as TabControl; }
202                 }
203
204                 internal void SetVisible (bool value)
205                 {
206                         base.Visible = value;
207                 }
208
209                 #endregion      // Internal & Private Methods and Properties
210
211                 #region Protected Instance Methods
212                 protected override ControlCollection CreateControlsInstance ()
213                 {
214                         return new TabPageControlCollection (this);
215                 }
216
217                 protected override void SetBoundsCore (int x, int y, int width, int height, BoundsSpecified specified) 
218                 {
219                         if (Owner != null && Owner.IsHandleCreated) {
220                                 Rectangle display = Owner.DisplayRectangle;
221
222                                 base.SetBoundsCore (display.X, display.Y,
223                                                         display.Width, display.Height,
224                                                         BoundsSpecified.All);
225                         } else {
226                                 base.SetBoundsCore (x, y, width, height, specified);
227                         }
228                 }
229
230                 #endregion      // Protected Instance Methods
231
232                 #region Events
233                 [Browsable(false)]
234                 [EditorBrowsable(EditorBrowsableState.Never)]
235                 public new event EventHandler DockChanged {
236                         add { base.DockChanged += value; }
237                         remove { base.DockChanged -= value; }
238                 }
239
240                 [Browsable(false)]
241                 [EditorBrowsable(EditorBrowsableState.Never)]
242                 public new event EventHandler EnabledChanged {
243                         add { base.EnabledChanged += value; }
244                         remove { base.EnabledChanged -= value; }
245                 }
246
247                 [Browsable(false)]
248                 [EditorBrowsable(EditorBrowsableState.Never)]
249                 public new event EventHandler TabIndexChanged {
250                         add { base.TabIndexChanged += value; }
251                         remove { base.TabIndexChanged -= value; }
252                 }
253
254                 [Browsable(false)]
255                 [EditorBrowsable(EditorBrowsableState.Never)]
256                 public new event EventHandler TabStopChanged {
257                         add { base.TabStopChanged += value; }
258                         remove { base.TabStopChanged -= value; }
259                 }
260
261                 [Browsable(false)]
262                 [EditorBrowsable(EditorBrowsableState.Never)]
263                 public new event EventHandler VisibleChanged {
264                         add { base.VisibleChanged += value; }
265                         remove { base.VisibleChanged -= value; }
266                 }
267
268                 #endregion      // Events
269
270 #if NET_2_0
271                 public new Point Location {
272                         get {
273                                 return base.Location;
274                         }
275
276                         set {
277                                 base.Location = value;
278                         }
279                 }
280 #endif
281                 #region Class TabPageControlCollection
282                 public class TabPageControlCollection : ControlCollection {
283
284                         //private TabPage owner;
285
286                         public TabPageControlCollection (TabPage owner) : base (owner)
287                         {
288                                 //this.owner = owner;
289                         }
290
291                         public override void Add (Control value)
292                         {
293                                 base.Add (value);
294                         }
295                 }
296                 #endregion      // Class TabPageControlCollection
297
298         }
299
300         
301 }