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