2 // System.Windows.Forms.StatusBarPanel
5 // stubbed out by Richard Baumann (biochem333@nyc.rr.com)
6 // Dennis Hayes (dennish@Raytek.com)
7 // Aleksey Ryabchuk (ryabchuk@yahoo.com)
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:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
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.
34 using System
.ComponentModel
;
36 namespace System
.Windows
.Forms
{
39 /// Represents a panel in a StatusBar control.
41 public class StatusBarPanel
: Component
, ISupportInitialize
{
46 private HorizontalAlignment alignment
;
47 private StatusBarPanelAutoSize autoSize
;
48 private StatusBarPanelBorderStyle borderStyle
;
51 private StatusBar parent
;
52 private StatusBarPanelStyle style
;
54 private string toolTipText
;
56 private bool suppressUpdates
;
59 // --- Constructors/Destructors
61 public StatusBarPanel() : base()
63 alignment
= HorizontalAlignment
.Left
;
64 autoSize
= StatusBarPanelAutoSize
.None
;
65 borderStyle
= StatusBarPanelBorderStyle
.Sunken
;
67 style
= StatusBarPanelStyle
.Text
;
69 suppressUpdates
= false;
75 public void BeginInit()
77 suppressUpdates
= true;
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; }
96 if ( !Enum
.IsDefined ( typeof(HorizontalAlignment
), value ) )
97 throw new InvalidEnumArgumentException( "Alignment",
99 typeof(HorizontalAlignment
));
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",
113 typeof(StatusBarPanelAutoSize
));
115 UpdateParent ( true, false, null );
119 public StatusBarPanelBorderStyle BorderStyle
{
120 get { return borderStyle; }
122 if ( !Enum
.IsDefined ( typeof(StatusBarPanelBorderStyle
), value ) )
123 throw new InvalidEnumArgumentException( "BorderStyle",
125 typeof(StatusBarPanelBorderStyle
));
128 UpdateParent ( false, true, this );
136 UpdateParent ( true, false, null );
142 get { return minWidth; }
145 throw new ArgumentException(
146 string.Format("'{0}' is not a valid value for 'value'. 'value' must be greater than or equal to 0.",
149 UpdateParent ( true, false, null );
153 public StatusBar Parent
{
154 get { return parent; }
157 public StatusBarPanelStyle Style
{
158 get { return style; }
160 if ( !Enum
.IsDefined ( typeof(StatusBarPanelStyle
), value ) )
161 throw new InvalidEnumArgumentException( "Style",
163 typeof(StatusBarPanelStyle
));
165 UpdateParent ( false, true, this );
173 UpdateParent ( AutoSize
== StatusBarPanelAutoSize
.Contents
, true, this );
177 public string ToolTipText
179 get { return toolTipText; }
182 UpdateTooltips ( this );
187 get { return width; }
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
)
196 UpdateParent ( true, false, null );
200 public int GetContentWidth ( ) {
201 if( Parent
!= null) {
204 cxsize
= Win32
.GetTextExtent( Parent
.Handle
, Text
).cx
;
205 return cxsize
< MinWidth
? MinWidth
: cxsize
;
211 protected override void Dispose(bool disposing
) {
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
) {