**** Merged from MCS ****
[mono-project.git] / mcs / class / System.Windows.Forms / System.Windows.Forms / StatusBarPanel.cs
blobddc43e371741953d755a5f249d9906c6f4651b3a
1 //
2 // System.Windows.Forms.StatusBarPanel
3 //
4 // Author:
5 // stubbed out by Richard Baumann (biochem333@nyc.rr.com)
6 // Dennis Hayes (dennish@Raytek.com)
7 // Aleksey Ryabchuk (ryabchuk@yahoo.com)
8 //
9 // (C) Ximian, Inc., 2002/3
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System;
34 using System.ComponentModel;
35 using System.Drawing;
36 namespace System.Windows.Forms {
38 /// <summary>
39 /// Represents a panel in a StatusBar control.
40 /// </summary>
41 public class StatusBarPanel : Component, ISupportInitialize {
44 // --- Private Fields
46 private HorizontalAlignment alignment;
47 private StatusBarPanelAutoSize autoSize;
48 private StatusBarPanelBorderStyle borderStyle;
49 private Icon icon;
50 private int minWidth;
51 private StatusBar parent;
52 private StatusBarPanelStyle style;
53 private string text;
54 private string toolTipText;
55 private int width;
56 private bool suppressUpdates;
59 // --- Constructors/Destructors
61 public StatusBarPanel() : base()
63 alignment = HorizontalAlignment.Left;
64 autoSize = StatusBarPanelAutoSize.None;
65 borderStyle = StatusBarPanelBorderStyle.Sunken;
66 minWidth = 10;
67 style = StatusBarPanelStyle.Text;
68 width = 100;
69 suppressUpdates = false;
73 // --- Public Methods
75 public void BeginInit()
77 suppressUpdates = true;
80 public void EndInit()
82 suppressUpdates = false;
83 UpdateParent( true, true, null );
86 public override string ToString()
88 return "StatusBarPanel: {" + Text + "}";
91 // --- Public Properties
93 public HorizontalAlignment Alignment {
94 get { return alignment; }
95 set {
96 if ( !Enum.IsDefined ( typeof(HorizontalAlignment), value ) )
97 throw new InvalidEnumArgumentException( "Alignment",
98 (int)value,
99 typeof(HorizontalAlignment));
101 alignment = value;
102 UpdateParent ( false, true, this );
106 public StatusBarPanelAutoSize AutoSize {
107 get { return autoSize; }
110 if ( !Enum.IsDefined ( typeof(StatusBarPanelAutoSize), value ) )
111 throw new InvalidEnumArgumentException( "AutoSize",
112 (int)value,
113 typeof(StatusBarPanelAutoSize));
114 autoSize = value;
115 UpdateParent ( true, false, null );
119 public StatusBarPanelBorderStyle BorderStyle {
120 get { return borderStyle; }
121 set {
122 if ( !Enum.IsDefined ( typeof(StatusBarPanelBorderStyle), value ) )
123 throw new InvalidEnumArgumentException( "BorderStyle",
124 (int)value,
125 typeof(StatusBarPanelBorderStyle));
127 borderStyle = value;
128 UpdateParent ( false, true, this );
132 public Icon Icon {
133 get { return icon; }
134 set {
135 icon = value;
136 UpdateParent ( true, false, null );
140 public int MinWidth
142 get { return minWidth; }
143 set {
144 if ( value < 0 )
145 throw new ArgumentException(
146 string.Format("'{0}' is not a valid value for 'value'. 'value' must be greater than or equal to 0.",
147 value ) ) ;
148 minWidth = value;
149 UpdateParent ( true, false, null );
153 public StatusBar Parent {
154 get { return parent; }
157 public StatusBarPanelStyle Style {
158 get { return style; }
159 set {
160 if ( !Enum.IsDefined ( typeof(StatusBarPanelStyle), value ) )
161 throw new InvalidEnumArgumentException( "Style",
162 (int)value,
163 typeof(StatusBarPanelStyle));
164 style = value;
165 UpdateParent ( false, true, this );
169 public string Text {
170 get { return text; }
171 set {
172 text = value;
173 UpdateParent ( AutoSize == StatusBarPanelAutoSize.Contents, true, this );
177 public string ToolTipText
179 get { return toolTipText; }
180 set {
181 toolTipText = value;
182 UpdateTooltips ( this );
186 public int Width {
187 get { return width; }
188 set {
189 // According to MS documentation this method
190 // should throw ArgumentException if value < MinWidth,
191 // but it does not actually happens.
192 if ( value < MinWidth )
193 width = MinWidth;
194 else
195 width = value;
196 UpdateParent ( true, false, null );
200 public int GetContentWidth ( ) {
201 if( Parent != null) {
202 int cxsize = 0;
203 if ( Text != null )
204 cxsize = Win32.GetTextExtent( Parent.Handle, Text ).cx;
205 return cxsize < MinWidth ? MinWidth : cxsize;
207 return Width;
210 [MonoTODO]
211 protected override void Dispose(bool disposing) {
212 // FIXME:
213 base.Dispose(disposing);
216 private void UpdateParent ( bool UpdateParts, bool UpdateText, StatusBarPanel p ) {
217 if ( Parent != null && suppressUpdates != true)
218 Parent.UpdatePanels ( UpdateParts, UpdateText, p );
221 private void UpdateTooltips ( StatusBarPanel p ) {
222 if ( Parent != null && suppressUpdates != true)
223 Parent.UpdateToolTips ( p );
226 internal void SetParent ( StatusBar prnt ) {
227 parent = prnt;