* ListView.cs: When doing layout calculations don't use a ref
[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 Constructors
63                 public StatusBarPanel ()
64                 {
65                 }
66                 #endregion      // Constructors
67
68                 [DefaultValue(HorizontalAlignment.Left)]
69                 [Localizable(true)]
70                 public HorizontalAlignment Alignment {
71                         get { return alignment; }
72                         set { 
73                                 alignment = value; 
74                                 InvalidateContents ();
75                         }
76                 }
77
78 #if NET_2_0
79                 [RefreshProperties (RefreshProperties.All)]
80 #endif
81                 [DefaultValue(StatusBarPanelAutoSize.None)]
82                 public StatusBarPanelAutoSize AutoSize {
83                         get { return auto_size; }
84                         set { 
85                                 auto_size = value; 
86                                 Invalidate ();
87                         }
88                 }
89
90                 [DefaultValue(StatusBarPanelBorderStyle.Sunken)]
91                 [DispId(-504)]
92                 public StatusBarPanelBorderStyle BorderStyle {
93                         get { return border_style; }
94                         set { 
95                                 border_style = value; 
96                                 Invalidate ();
97                         }
98                 }
99
100                 [DefaultValue(null)]
101                 [Localizable(true)]
102                 public Icon Icon {
103                         get { return icon; }
104                         set { 
105                                 icon = value; 
106                                 InvalidateContents ();
107                         }
108                 }
109
110                 [DefaultValue(10)]
111                 [Localizable(true)]
112                 [RefreshProperties(RefreshProperties.All)]
113                 public int MinWidth {
114                         get {
115                         /*
116                                 MSDN says that when AutoSize = None then MinWidth is automatically
117                                 set to Width, but neither v1.1 nor v2.0 behave that way.
118                         */
119                                 return min_width;
120                         }
121                         set {
122 #if NET_2_0
123                                 if (value < 0)
124                                         throw new ArgumentOutOfRangeException ("value");
125 #else
126                                 if (value < 0)
127                                         throw new ArgumentException ("value");
128 #endif
129                                 min_width = value;
130                                 if (min_width > width)
131                                         width = min_width;
132                                 
133                                 Invalidate ();
134                         }
135                 }
136 #if NET_2_0
137                 [Localizable (true)]
138                 public string Name {
139                         get {
140                                 if (name == null)
141                                         return string.Empty;
142                                 return name;
143                         }
144                         set {
145                                 name = value;
146                         }
147                 }
148 #endif
149                 
150                 [DefaultValue(100)]
151                 [Localizable(true)]
152                 public int Width {
153                         get { return width; }
154                         set {
155                                 if (value < 0)
156                                         throw new ArgumentException ("value");
157
158                                 if (initializing)
159                                         width = value;
160                                 else
161                                         SetWidth(value);
162                                 
163                                 Invalidate ();
164                         }
165                 }
166                 
167                 [DefaultValue(StatusBarPanelStyle.Text)]
168                 public StatusBarPanelStyle Style {
169                         get { return style; }
170                         set { 
171                                 style = value; 
172                                 Invalidate ();
173                         }
174                 }
175 #if NET_2_0
176                 [TypeConverter (typeof (StringConverter))]
177                 [Localizable (false)]
178                 [Bindable (true)]
179                 [DefaultValue (null)]
180                 public object Tag {
181                         get {
182                                 return tag;
183                         }
184                         set {
185                                 tag = value;
186                         }
187                 }
188 #endif
189
190                 [DefaultValue("")]
191                 [Localizable(true)]
192                 public string Text {
193                         get { return text; }
194                         set { 
195                                 text = value; 
196                                 InvalidateContents ();
197                         }
198                 }
199
200                 [DefaultValue("")]
201                 [Localizable(true)]
202                 public string ToolTipText {
203                         get { return tool_tip_text; }
204                         set { tool_tip_text = value; }
205                 }
206
207                 [Browsable(false)]
208                 public StatusBar Parent {
209                         get { return parent; }
210                 }
211
212                 private void Invalidate ()
213                 {
214                         if (parent == null)
215                                 return;
216                         parent.UpdatePanel (this);
217                 }
218
219                 private void InvalidateContents ()
220                 {
221                         if (parent == null)
222                                 return;
223                         parent.UpdatePanelContents (this);
224                 }
225
226                 internal void SetParent (StatusBar parent)
227                 {
228                         this.parent = parent;
229                 }
230
231                 internal void SetWidth (int width)
232                 {
233                         this.width = width;
234                         if (min_width > this.width)
235                                 this.width = min_width;
236                 }
237
238                 public override string ToString ()
239                 {
240                         return "StatusBarPanel: {" + Text +"}";
241                 }
242
243                 protected override void Dispose (bool disposing)
244                 {
245                 }
246
247                 public void BeginInit ()
248                 {
249                         initializing = true;
250                 }
251
252                 public void EndInit ()
253                 {
254                         if (!initializing)
255                                 return;
256                         
257                         if (min_width > width)
258                                 width = min_width;
259                         
260                         initializing = false;
261                 }
262         }
263 }
264
265