Store the tab pages row
[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 Novell, Inc.
21 //
22 // Authors:
23 //      Jackson Harper (jackson@ximian.com)
24
25
26 using System;
27 using System.Drawing;
28
29 namespace System.Windows.Forms {
30
31         public class TabPage : Panel {
32
33                 private int image_index = -1;
34                 private string tooltip_text = String.Empty;
35                 private Rectangle tab_bounds;
36                 private int row;
37                 
38                 public TabPage ()
39                 {
40                         Visible = true;
41                 }
42
43                 public TabPage (string text) : base ()
44                 {
45                         Text = text;
46                 }
47
48                 public override AnchorStyles Anchor {
49                         get { return base.Anchor; }
50                         set { base.Anchor = value; }
51                 }
52
53                 public override DockStyle Dock {
54                         get { return base.Dock; }
55                         set { base.Dock = value; }
56                 }
57
58                 public new bool Enabled {
59                         get { return base.Enabled; }
60                         set { base.Enabled = value; }
61                 }
62
63                 public int ImageIndex {
64                         get { return image_index; }
65                         set {
66                                 if (image_index == value)
67                                         return;
68                                 image_index = value;
69                                 UpdateOwner ();
70                         }
71                 }
72
73                 public new int TabIndex {
74                         get { return base.TabIndex; }
75                         set { base.TabIndex = value; }
76                 }
77
78                 public new bool TabStop {
79                         get { return base.TabStop; }
80                         set { base.TabStop = value; }
81                 }
82
83                 public override string Text {
84                         get { return base.Text; }
85                         set {
86                                 if (value == Text)
87                                         return;
88                                 base.Text = value;
89                                 UpdateOwner ();
90                         }
91                 }
92
93                 public string ToolTipText {
94                         get { return tooltip_text; }
95                         set {
96                                 if (value == null)
97                                         value = String.Empty;
98                                 tooltip_text = value;
99                         }
100                 }
101
102                 public new bool Visible {
103                         get { return base.Visible; }
104                         set { base.Visible = value; }
105                 }
106
107                 public new event EventHandler DockChanged {
108                         add { base.DockChanged += value; }
109                         remove { base.DockChanged -= value; }
110                 }
111
112                 public new event EventHandler EnabledChanged {
113                         add { base.EnabledChanged += value; }
114                         remove { base.EnabledChanged -= value; }
115                 }
116
117                 public new event EventHandler TabIndexChanged {
118                         add { base.TabIndexChanged += value; }
119                         remove { base.TabIndexChanged -= value; }
120                 }
121
122                 public new event EventHandler TabStopChanged {
123                         add { base.TabStopChanged += value; }
124                         remove { base.TabStopChanged -= value; }
125                 }
126
127                 public new event EventHandler VisibleChanged {
128                         add { base.VisibleChanged += value; }
129                         remove { base.VisibleChanged -= value; }
130                 }
131
132                 public static TabPage GetTabPageOfComponent (object comp)
133                 {
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;
142                         }
143                         return control as TabPage;
144                 }
145
146                 public override string ToString ()
147                 {
148                         return "TabPage: {" + Text + "}";
149                 }
150
151                 internal Rectangle TabBounds {
152                         get { return tab_bounds; }
153                         set { tab_bounds = value; }
154                 }
155
156                 internal int Row {
157                         get { return row; }
158                         set { row = value; }
159                 }
160
161                 private void UpdateOwner ()
162                 {
163                         if (Owner != null) {
164                                 // Will do some loving to the owner here
165                         }
166                 }
167
168                 private TabControl Owner {
169                         get { return base.Parent as TabControl; }
170                 }
171
172                 protected override ControlCollection CreateControlsInstance ()
173                 {
174                         return new TabPageControlCollection (this);
175                 }
176
177                 protected override void SetBoundsCore (int x, int y, int width, int height, BoundsSpecified specified) 
178                 {
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);
186                         }
187                 }
188
189                 public class TabPageControlCollection : ControlCollection {
190
191                         private TabPage owner;
192
193                         public TabPageControlCollection (TabPage owner) : base (owner)
194                         {
195                                 this.owner = owner;
196                         }
197
198                         public void Add (Control value)
199                         {
200                                 base.Add (value);
201                         }
202                 }
203         }
204
205         
206 }