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