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