**** Merged from MCS ****
[mono-project.git] / mcs / class / System.Windows.Forms / Gtk / StatusBarPanel.cs
blobf0bcc39d70bf57246c6e934de18ccbb9bdfdb2e5
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
12 using System;
13 using System.ComponentModel;
14 using System.Drawing;
15 namespace System.Windows.Forms {
17 /// <summary>
18 /// Represents a panel in a StatusBar control.
19 /// </summary>
20 public class StatusBarPanel : Component, ISupportInitialize {
23 // --- Private Fields
25 private HorizontalAlignment alignment;
26 private StatusBarPanelAutoSize autoSize;
27 private StatusBarPanelBorderStyle borderStyle;
28 private Icon icon;
29 private int minWidth;
30 private StatusBar parent;
31 private StatusBarPanelStyle style;
32 private string text;
33 private string toolTipText;
34 private int width;
35 private bool suppressUpdates;
38 // --- Constructors/Destructors
40 public StatusBarPanel() : base()
42 alignment = HorizontalAlignment.Left;
43 autoSize = StatusBarPanelAutoSize.None;
44 borderStyle = StatusBarPanelBorderStyle.Sunken;
45 minWidth = 10;
46 style = StatusBarPanelStyle.Text;
47 width = 100;
48 suppressUpdates = false;
52 // --- Public Methods
54 public void BeginInit()
56 suppressUpdates = true;
59 public void EndInit()
61 suppressUpdates = false;
62 UpdateParent( true, true, null );
65 public override string ToString()
67 return "StatusBarPanel: {" + Text + "}";
70 // --- Public Properties
72 public HorizontalAlignment Alignment {
73 get { return alignment; }
74 set {
75 if ( !Enum.IsDefined ( typeof(HorizontalAlignment), value ) )
76 throw new InvalidEnumArgumentException( "Alignment",
77 (int)value,
78 typeof(HorizontalAlignment));
80 alignment = value;
81 UpdateParent ( false, true, this );
85 public StatusBarPanelAutoSize AutoSize {
86 get { return autoSize; }
87 set
89 if ( !Enum.IsDefined ( typeof(StatusBarPanelAutoSize), value ) )
90 throw new InvalidEnumArgumentException( "AutoSize",
91 (int)value,
92 typeof(StatusBarPanelAutoSize));
93 autoSize = value;
94 UpdateParent ( true, false, null );
98 public StatusBarPanelBorderStyle BorderStyle {
99 get { return borderStyle; }
100 set {
101 if ( !Enum.IsDefined ( typeof(StatusBarPanelBorderStyle), value ) )
102 throw new InvalidEnumArgumentException( "BorderStyle",
103 (int)value,
104 typeof(StatusBarPanelBorderStyle));
106 borderStyle = value;
107 UpdateParent ( false, true, this );
111 public Icon Icon {
112 get { return icon; }
113 set {
114 icon = value;
115 UpdateParent ( true, false, null );
119 public int MinWidth
121 get { return minWidth; }
122 set {
123 if ( value < 0 )
124 throw new ArgumentException(
125 string.Format("'{0}' is not a valid value for 'value'. 'value' must be greater than or equal to 0.",
126 value ) ) ;
127 minWidth = value;
128 UpdateParent ( true, false, null );
132 public StatusBar Parent {
133 get { return parent; }
136 public StatusBarPanelStyle Style {
137 get { return style; }
138 set {
139 if ( !Enum.IsDefined ( typeof(StatusBarPanelStyle), value ) )
140 throw new InvalidEnumArgumentException( "Style",
141 (int)value,
142 typeof(StatusBarPanelStyle));
143 style = value;
144 UpdateParent ( false, true, this );
148 public string Text {
149 get { return text; }
150 set {
151 text = value;
152 UpdateParent ( AutoSize == StatusBarPanelAutoSize.Contents, true, this );
156 public string ToolTipText
158 get { return toolTipText; }
159 set {
160 toolTipText = value;
161 UpdateTooltips ( this );
165 public int Width {
166 get { return width; }
167 set {
168 // According to MS documentation this method
169 // should throw ArgumentException if value < MinWidth,
170 // but it does not actually happens.
171 if ( value < MinWidth )
172 width = MinWidth;
173 else
174 width = value;
175 UpdateParent ( true, false, null );
179 public int GetContentWidth ( ) {
180 if( Parent != null) {
181 int cxsize = 0;
182 if ( Text != null ) {}
183 //cxsize = Win32.GetTextExtent( Parent.Handle, Text ).cx;
184 return cxsize < MinWidth ? MinWidth : cxsize;
186 return Width;
189 private void UpdateParent ( bool UpdateParts, bool UpdateText, StatusBarPanel p ) {
190 if ( Parent != null && suppressUpdates != true)
191 Parent.UpdatePanels ( UpdateParts, UpdateText, p );
194 private void UpdateTooltips ( StatusBarPanel p ) {
195 if ( Parent != null && suppressUpdates != true)
196 Parent.UpdateToolTips ( p );
199 internal void SetParent ( StatusBar prnt ) {
200 parent = prnt;