- Added ActiveMdiChild method
[mono.git] / mcs / class / System.Windows.Forms / Gtk / StatusBarPanel.cs
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
10 //
11
12 using System;
13 using System.ComponentModel;
14 using System.Drawing;
15 namespace System.Windows.Forms {
16
17         /// <summary>
18         ///     Represents a panel in a StatusBar control.
19         /// </summary>
20         public class StatusBarPanel : Component, ISupportInitialize {
21
22                 //
23                 //  --- Private Fields
24                 //
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;
36
37                 //
38                 //  --- Constructors/Destructors
39                 //
40                 public StatusBarPanel() : base()
41                 {
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;
49                 }
50
51                 //
52                 //  --- Public Methods
53                 //
54                 public void BeginInit()
55                 {
56                         suppressUpdates = true;
57                 }
58
59                 public void EndInit()
60                 {
61                         suppressUpdates = false;
62                         UpdateParent( true, true, null );
63                 }
64
65                 public override string ToString()
66                 {
67                         return "StatusBarPanel: {" + Text + "}";
68                 }
69                 //
70                 //  --- Public Properties
71                 //
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));
79
80                                 alignment = value; 
81                                 UpdateParent ( false, true, this );
82                         }
83                 }
84
85                 public StatusBarPanelAutoSize AutoSize {
86                         get { return autoSize; }
87                         set
88                         {
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 );
95                         }
96                 }
97
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));
105
106                                 borderStyle = value;
107                                 UpdateParent ( false, true, this );
108                         }
109                 }
110
111                 public Icon Icon {
112                         get { return icon; }
113                         set { 
114                                 icon = value; 
115                                 UpdateParent (  true, false, null );
116                         }
117                 }
118
119                 public int MinWidth 
120                 {
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 );
129                         }
130                 }
131
132                 public StatusBar Parent {
133                         get { return parent; }
134                 }
135
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 );
145                         }
146                 }
147
148                 public string Text {
149                         get { return text; }
150                         set { 
151                                 text = value;
152                                 UpdateParent ( AutoSize == StatusBarPanelAutoSize.Contents, true, this );
153                         }
154                 }
155
156                 public string ToolTipText 
157                 {
158                         get { return toolTipText; }
159                         set { 
160                                 toolTipText = value;
161                                 UpdateTooltips ( this );
162                         }
163                 }
164
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 );
176                         }
177                 }
178
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;
185                         }
186                         return Width;
187                 }
188
189                 private void UpdateParent (  bool UpdateParts, bool UpdateText, StatusBarPanel p ) {
190                         if ( Parent != null && suppressUpdates != true)
191                                 Parent.UpdatePanels ( UpdateParts, UpdateText, p );
192                 }
193
194                 private void UpdateTooltips ( StatusBarPanel p ) {
195                         if ( Parent != null && suppressUpdates != true)
196                                 Parent.UpdateToolTips ( p );
197                 }
198
199                 internal void SetParent ( StatusBar prnt ) {
200                         parent = prnt;
201                 }
202         }
203 }