* TabControl.cs: New method that resizes the tab pages before
[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)]
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                 #endregion      // Fields
44                 
45                 #region Public Constructors
46                 public TabPage ()
47                 {
48                         Visible = true;
49                 }
50
51                 public TabPage (string text) : base ()
52                 {
53                         base.Text = text;
54                 }
55
56                 #endregion      // Public Constructors
57
58                 #region Public Instance Properties
59                 [Browsable(false)]
60                 [EditorBrowsable(EditorBrowsableState.Never)]
61                 public override AnchorStyles Anchor {
62                         get { return base.Anchor; }
63                         set { base.Anchor = value; }
64                 }
65
66                 [Browsable(false)]
67                 [EditorBrowsable(EditorBrowsableState.Never)]
68                 public override DockStyle Dock {
69                         get { return base.Dock; }
70                         set { base.Dock = value; }
71                 }
72
73                 [Browsable(false)]
74                 [EditorBrowsable(EditorBrowsableState.Never)]
75                 public new bool Enabled {
76                         get { return base.Enabled; }
77                         set { base.Enabled = value; }
78                 }
79
80                 [DefaultValue(-1)]
81                 [Editor("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design, typeof(System.Drawing.Design.UITypeEditor))]
82                 [Localizable(true)]
83                 [TypeConverter(typeof(ImageIndexConverter))]
84                 public int ImageIndex {
85                         get { return image_index; }
86                         set {
87                                 if (image_index == value)
88                                         return;
89                                 image_index = value;
90                                 UpdateOwner ();
91                         }
92                 }
93
94                 [Browsable(false)]
95                 [EditorBrowsable(EditorBrowsableState.Never)]
96                 public new int TabIndex {
97                         get { return base.TabIndex; }
98                         set { base.TabIndex = value; }
99                 }
100
101                 [Browsable(false)]
102                 [EditorBrowsable(EditorBrowsableState.Never)]
103                 public new bool TabStop {
104                         get { return base.TabStop; }
105                         set { base.TabStop = value; }
106                 }
107
108                 [Browsable(true)]
109                 [Localizable(true)]
110                 public override string Text {
111                         get { return base.Text; }
112                         set {
113                                 if (value == base.Text)
114                                         return;
115                                 base.Text = value;
116                                 UpdateOwner ();
117                         }
118                 }
119
120                 [Localizable(true)]
121                 [DefaultValue("")]
122                 public string ToolTipText {
123                         get { return tooltip_text; }
124                         set {
125                                 if (value == null)
126                                         value = String.Empty;
127                                 tooltip_text = value;
128                         }
129                 }
130
131                 [Browsable(false)]
132                 [EditorBrowsable(EditorBrowsableState.Never)]
133                 public new bool Visible {
134                         get { return base.Visible; }
135                         set { base.Visible = value; }
136                 }
137
138                 #endregion      // Public Instance Properties
139
140                 #region Public Static Methods
141                 public static TabPage GetTabPageOfComponent (object comp)
142                 {
143                         Control control = comp as Control;
144                         if (control == null)
145                                 return null;
146                         control = control.Parent;
147                         while (control != null) {
148                                 if (control is TabPage)
149                                         break;
150                                 control = control.Parent;
151                         }
152                         return control as TabPage;
153                 }
154
155                 #endregion      // Public Static Methods
156
157                 #region Public Instance Methods
158                 public override string ToString ()
159                 {
160                         return "TabPage: {" + Text + "}";
161                 }
162
163                 #endregion      // Public Instance Methods
164
165                 #region Internal & Private Methods and Properties
166                 internal Rectangle TabBounds {
167                         get { return tab_bounds; }
168                         set { tab_bounds = value; }
169                 }
170
171                 internal int Row {
172                         get { return row; }
173                         set { row = value; }
174                 }
175
176                 private void UpdateOwner ()
177                 {
178                         if (Owner != null) {
179                                 Owner.Redraw ();
180                         }
181                 }
182
183                 private TabControl Owner {
184                         get { return base.Parent as TabControl; }
185                 }
186
187                 #endregion      // Internal & Private Methods and Properties
188
189                 #region Protected Instance Methods
190                 protected override ControlCollection CreateControlsInstance ()
191                 {
192                         return new TabPageControlCollection (this);
193                 }
194
195                 protected override void SetBoundsCore (int x, int y, int width, int height, BoundsSpecified specified) 
196                 {
197                         if (Owner != null && Owner.IsHandleCreated) {
198                                 Rectangle display = Owner.DisplayRectangle;
199
200                                 base.SetBoundsCore (display.X, display.Y,
201                                                         display.Width, display.Height,
202                                                         BoundsSpecified.All);
203                         } else {
204                                 base.SetBoundsCore (x, y, width, height, specified);
205                         }
206                 }
207
208                 #endregion      // Protected Instance Methods
209
210                 #region Events
211                 [Browsable(false)]
212                 [EditorBrowsable(EditorBrowsableState.Never)]
213                 public new event EventHandler DockChanged {
214                         add { base.DockChanged += value; }
215                         remove { base.DockChanged -= value; }
216                 }
217
218                 [Browsable(false)]
219                 [EditorBrowsable(EditorBrowsableState.Never)]
220                 public new event EventHandler EnabledChanged {
221                         add { base.EnabledChanged += value; }
222                         remove { base.EnabledChanged -= value; }
223                 }
224
225                 [Browsable(false)]
226                 [EditorBrowsable(EditorBrowsableState.Never)]
227                 public new event EventHandler TabIndexChanged {
228                         add { base.TabIndexChanged += value; }
229                         remove { base.TabIndexChanged -= value; }
230                 }
231
232                 [Browsable(false)]
233                 [EditorBrowsable(EditorBrowsableState.Never)]
234                 public new event EventHandler TabStopChanged {
235                         add { base.TabStopChanged += value; }
236                         remove { base.TabStopChanged -= value; }
237                 }
238
239                 [Browsable(false)]
240                 [EditorBrowsable(EditorBrowsableState.Never)]
241                 public new event EventHandler VisibleChanged {
242                         add { base.VisibleChanged += value; }
243                         remove { base.VisibleChanged -= value; }
244                 }
245
246                 #endregion      // Events
247
248                 #region Class TabPageControlCollection
249                 public class TabPageControlCollection : ControlCollection {
250
251                         private TabPage owner;
252
253                         public TabPageControlCollection (TabPage owner) : base (owner)
254                         {
255                                 this.owner = owner;
256                         }
257
258                         public void Add (Control value)
259                         {
260                                 base.Add (value);
261                         }
262                 }
263                 #endregion      // Class TabPageControlCollection
264         }
265
266         
267 }