* TabControl.cs: Show the tooltip depending on the value
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / StatusBarPanel.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 // COMPLETE
26
27 using System;
28 using System.Drawing;
29 using System.ComponentModel;
30 using System.ComponentModel.Design;
31 using System.Runtime.InteropServices;
32
33 namespace System.Windows.Forms {
34 #if NET_2_0
35         [ToolboxItem (false)]
36 #endif
37         [DefaultProperty("Text")]
38         [DesignTimeVisible(false)]
39         public class StatusBarPanel : Component, ISupportInitialize {
40                 #region Local Variables
41                 private StatusBar parent;
42
43                 private bool initializing;
44                 private string text = String.Empty;
45                 private string tool_tip_text = String.Empty;
46
47                 private Icon icon;
48                 private HorizontalAlignment alignment = HorizontalAlignment.Left;
49                 private StatusBarPanelAutoSize auto_size = StatusBarPanelAutoSize.None;
50                 private StatusBarPanelBorderStyle border_style = StatusBarPanelBorderStyle.Sunken;
51                 private StatusBarPanelStyle style = StatusBarPanelStyle.Text;
52                 private int width = 100;
53                 private int min_width = 10;
54                 internal int X;
55                 
56 #if NET_2_0
57                 private string name;
58                 private object tag;
59 #endif
60                 #endregion      // Local Variables
61
62                 #region UIA Framework Events
63 #if NET_2_0
64                 static object UIATextChangedEvent = new object ();
65
66                 internal event EventHandler UIATextChanged {
67                         add { Events.AddHandler (UIATextChangedEvent, value); }
68                         remove { Events.RemoveHandler (UIATextChangedEvent, value); }
69                 }
70
71                 internal void OnUIATextChanged (EventArgs e)
72                 {
73                         EventHandler eh = (EventHandler) Events [UIATextChangedEvent];
74                         if (eh != null)
75                                 eh (this, e);
76                 }
77 #endif
78                 #endregion
79
80                 #region Constructors
81                 public StatusBarPanel ()
82                 {
83                 }
84                 #endregion      // Constructors
85
86                 [DefaultValue(HorizontalAlignment.Left)]
87                 [Localizable(true)]
88                 public HorizontalAlignment Alignment {
89                         get { return alignment; }
90                         set { 
91                                 alignment = value; 
92                                 InvalidateContents ();
93                         }
94                 }
95
96 #if NET_2_0
97                 [RefreshProperties (RefreshProperties.All)]
98 #endif
99                 [DefaultValue(StatusBarPanelAutoSize.None)]
100                 public StatusBarPanelAutoSize AutoSize {
101                         get { return auto_size; }
102                         set { 
103                                 auto_size = value; 
104                                 Invalidate ();
105                         }
106                 }
107
108                 [DefaultValue(StatusBarPanelBorderStyle.Sunken)]
109                 [DispId(-504)]
110                 public StatusBarPanelBorderStyle BorderStyle {
111                         get { return border_style; }
112                         set { 
113                                 border_style = value; 
114                                 Invalidate ();
115                         }
116                 }
117
118                 [DefaultValue(null)]
119                 [Localizable(true)]
120                 public Icon Icon {
121                         get { return icon; }
122                         set { 
123                                 icon = value; 
124                                 InvalidateContents ();
125                         }
126                 }
127
128                 [DefaultValue(10)]
129                 [Localizable(true)]
130                 [RefreshProperties(RefreshProperties.All)]
131                 public int MinWidth {
132                         get {
133                         /*
134                                 MSDN says that when AutoSize = None then MinWidth is automatically
135                                 set to Width, but neither v1.1 nor v2.0 behave that way.
136                         */
137                                 return min_width;
138                         }
139                         set {
140 #if NET_2_0
141                                 if (value < 0)
142                                         throw new ArgumentOutOfRangeException ("value");
143 #else
144                                 if (value < 0)
145                                         throw new ArgumentException ("value");
146 #endif
147                                 min_width = value;
148                                 if (min_width > width)
149                                         width = min_width;
150                                 
151                                 Invalidate ();
152                         }
153                 }
154 #if NET_2_0
155                 [Localizable (true)]
156                 public string Name {
157                         get {
158                                 if (name == null)
159                                         return string.Empty;
160                                 return name;
161                         }
162                         set {
163                                 name = value;
164                         }
165                 }
166 #endif
167                 
168                 [DefaultValue(100)]
169                 [Localizable(true)]
170                 public int Width {
171                         get { return width; }
172                         set {
173                                 if (value < 0)
174                                         throw new ArgumentException ("value");
175
176                                 if (initializing)
177                                         width = value;
178                                 else
179                                         SetWidth(value);
180                                 
181                                 Invalidate ();
182                         }
183                 }
184                 
185                 [DefaultValue(StatusBarPanelStyle.Text)]
186                 public StatusBarPanelStyle Style {
187                         get { return style; }
188                         set { 
189                                 style = value; 
190                                 Invalidate ();
191                         }
192                 }
193 #if NET_2_0
194                 [TypeConverter (typeof (StringConverter))]
195                 [Localizable (false)]
196                 [Bindable (true)]
197                 [DefaultValue (null)]
198                 public object Tag {
199                         get {
200                                 return tag;
201                         }
202                         set {
203                                 tag = value;
204                         }
205                 }
206 #endif
207
208                 [DefaultValue("")]
209                 [Localizable(true)]
210                 public string Text {
211                         get { return text; }
212                         set { 
213                                 text = value; 
214                                 InvalidateContents ();
215
216 #if NET_2_0
217                                 // UIA Framework Event: Text Changed
218                                 OnUIATextChanged (EventArgs.Empty);
219 #endif
220                         }
221                 }
222
223                 [DefaultValue("")]
224                 [Localizable(true)]
225                 public string ToolTipText {
226                         get { return tool_tip_text; }
227                         set { tool_tip_text = value; }
228                 }
229
230                 [Browsable(false)]
231                 public StatusBar Parent {
232                         get { return parent; }
233                 }
234
235                 private void Invalidate ()
236                 {
237                         if (parent == null)
238                                 return;
239                         parent.UpdatePanel (this);
240                 }
241
242                 private void InvalidateContents ()
243                 {
244                         if (parent == null)
245                                 return;
246                         parent.UpdatePanelContents (this);
247                 }
248
249                 internal void SetParent (StatusBar parent)
250                 {
251                         this.parent = parent;
252                 }
253
254                 internal void SetWidth (int width)
255                 {
256                         this.width = width;
257                         if (min_width > this.width)
258                                 this.width = min_width;
259                 }
260
261                 public override string ToString ()
262                 {
263                         return "StatusBarPanel: {" + Text +"}";
264                 }
265
266                 protected override void Dispose (bool disposing)
267                 {
268                 }
269
270                 public void BeginInit ()
271                 {
272                         initializing = true;
273                 }
274
275                 public void EndInit ()
276                 {
277                         if (!initializing)
278                                 return;
279                         
280                         if (min_width > width)
281                                 width = min_width;
282                         
283                         initializing = false;
284                 }
285         }
286 }
287
288