**** Merged from MCS ****
[mono-project.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / TabPage.cs
blobc7925c20eb76d83546fc4fbe2040ba49ff2f653d
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.
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.
20 // Copyright (c) 2004 Novell, Inc.
22 // Authors:
23 // Jackson Harper (jackson@ximian.com)
26 using System;
27 using System.Drawing;
29 namespace System.Windows.Forms {
31 public class TabPage : Panel {
33 private int image_index = -1;
34 private string tooltip_text = String.Empty;
35 private Rectangle tab_bounds;
36 private int row;
38 public TabPage ()
40 Visible = true;
43 public TabPage (string text) : base ()
45 Text = text;
48 public override AnchorStyles Anchor {
49 get { return base.Anchor; }
50 set { base.Anchor = value; }
53 public override DockStyle Dock {
54 get { return base.Dock; }
55 set { base.Dock = value; }
58 public new bool Enabled {
59 get { return base.Enabled; }
60 set { base.Enabled = value; }
63 public int ImageIndex {
64 get { return image_index; }
65 set {
66 if (image_index == value)
67 return;
68 image_index = value;
69 UpdateOwner ();
73 public new int TabIndex {
74 get { return base.TabIndex; }
75 set { base.TabIndex = value; }
78 public new bool TabStop {
79 get { return base.TabStop; }
80 set { base.TabStop = value; }
83 public override string Text {
84 get { return base.Text; }
85 set {
86 if (value == Text)
87 return;
88 base.Text = value;
89 UpdateOwner ();
93 public string ToolTipText {
94 get { return tooltip_text; }
95 set {
96 if (value == null)
97 value = String.Empty;
98 tooltip_text = value;
102 public new bool Visible {
103 get { return base.Visible; }
104 set { base.Visible = value; }
107 public new event EventHandler DockChanged {
108 add { base.DockChanged += value; }
109 remove { base.DockChanged -= value; }
112 public new event EventHandler EnabledChanged {
113 add { base.EnabledChanged += value; }
114 remove { base.EnabledChanged -= value; }
117 public new event EventHandler TabIndexChanged {
118 add { base.TabIndexChanged += value; }
119 remove { base.TabIndexChanged -= value; }
122 public new event EventHandler TabStopChanged {
123 add { base.TabStopChanged += value; }
124 remove { base.TabStopChanged -= value; }
127 public new event EventHandler VisibleChanged {
128 add { base.VisibleChanged += value; }
129 remove { base.VisibleChanged -= value; }
132 public static TabPage GetTabPageOfComponent (object comp)
134 Control control = comp as Control;
135 if (control == null)
136 return null;
137 control = control.Parent;
138 while (control != null) {
139 if (control is TabPage)
140 break;
141 control = control.Parent;
143 return control as TabPage;
146 public override string ToString ()
148 return "TabPage: {" + Text + "}";
151 internal Rectangle TabBounds {
152 get { return tab_bounds; }
153 set { tab_bounds = value; }
156 internal int Row {
157 get { return row; }
158 set { row = value; }
161 private void UpdateOwner ()
163 if (Owner != null) {
164 // Will do some loving to the owner here
168 private TabControl Owner {
169 get { return base.Parent as TabControl; }
172 protected override ControlCollection CreateControlsInstance ()
174 return new TabPageControlCollection (this);
177 protected override void SetBoundsCore (int x, int y, int width, int height, BoundsSpecified specified)
179 if (Owner != null && Owner.IsHandleCreated) {
180 Rectangle display = Owner.DisplayRectangle;
181 base.SetBoundsCore (Owner.DisplayRectangle.X, Owner.DisplayRectangle.Y,
182 Owner.DisplayRectangle.Width, Owner.DisplayRectangle.Height,
183 BoundsSpecified.All);
184 } else {
185 base.SetBoundsCore (x, y, width, height, specified);
189 public class TabPageControlCollection : ControlCollection {
191 private TabPage owner;
193 public TabPageControlCollection (TabPage owner) : base (owner)
195 this.owner = owner;
198 public void Add (Control value)
200 base.Add (value);