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:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
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.
20 // Copyright (C) 2004-2006 Novell, Inc.
23 // Jordi Mas i Hernandez jordi@ximian.com
24 // Peter Dennis Bartok pbartok@novell.com
30 using System.ComponentModel;
31 using System.Drawing.Imaging;
32 using System.Drawing.Drawing2D;
34 namespace System.Windows.Forms
36 [DefaultProperty ("Value")]
41 class ProgressBar : Control
43 #region Local Variables
48 internal Rectangle client_area = new Rectangle ();
50 internal ProgressBarStyle style;
52 #endregion // Local Variables
56 [EditorBrowsable (EditorBrowsableState.Never)]
57 public new event EventHandler BackColorChanged {
58 add { base.BackColorChanged += value; }
59 remove { base.BackColorChanged -= value; }
63 [EditorBrowsable (EditorBrowsableState.Never)]
64 public new event EventHandler BackgroundImageChanged {
65 add { base.BackgroundImageChanged += value; }
66 remove { base.BackgroundImageChanged -= value; }
70 [EditorBrowsable (EditorBrowsableState.Never)]
71 public new event EventHandler CausesValidationChanged {
72 add { base.CausesValidationChanged += value; }
73 remove { base.CausesValidationChanged -= value; }
77 [EditorBrowsable (EditorBrowsableState.Never)]
78 public new event EventHandler DoubleClick {
79 add { base.DoubleClick += value; }
80 remove { base.DoubleClick -= value; }
84 [EditorBrowsable (EditorBrowsableState.Never)]
85 public new event EventHandler Enter {
86 add { base.Enter += value; }
87 remove { base.Enter -= value; }
91 [EditorBrowsable (EditorBrowsableState.Never)]
92 public new event EventHandler FontChanged {
93 add { base.FontChanged += value; }
94 remove { base.FontChanged -= value; }
98 [EditorBrowsable (EditorBrowsableState.Never)]
99 public new event EventHandler ForeColorChanged {
100 add { base.ForeColorChanged += value; }
101 remove { base.ForeColorChanged -= value; }
105 [EditorBrowsable (EditorBrowsableState.Never)]
106 public new event EventHandler ImeModeChanged {
107 add { base.ImeModeChanged += value; }
108 remove { base.ImeModeChanged -= value; }
112 [EditorBrowsable (EditorBrowsableState.Never)]
113 public new event KeyEventHandler KeyDown {
114 add { base.KeyDown += value; }
115 remove { base.KeyDown -= value; }
119 [EditorBrowsable (EditorBrowsableState.Never)]
120 public new event KeyPressEventHandler KeyPress {
121 add { base.KeyPress += value; }
122 remove { base.KeyPress -= value; }
126 [EditorBrowsable (EditorBrowsableState.Never)]
127 public new event KeyEventHandler KeyUp {
128 add { base.KeyUp += value; }
129 remove { base.KeyUp -= value; }
133 [EditorBrowsable (EditorBrowsableState.Never)]
134 public new event EventHandler Leave {
135 add { base.Leave += value; }
136 remove { base.Leave -= value; }
140 [EditorBrowsable (EditorBrowsableState.Never)]
141 public new event PaintEventHandler Paint {
142 add { base.Paint += value; }
143 remove { base.Paint -= value; }
147 [EditorBrowsable (EditorBrowsableState.Never)]
148 public new event EventHandler RightToLeftChanged {
149 add { base.RightToLeftChanged += value; }
150 remove { base.RightToLeftChanged -= value; }
154 [EditorBrowsable (EditorBrowsableState.Never)]
155 public new event EventHandler TabStopChanged {
156 add { base.TabStopChanged += value; }
157 remove { base.TabStopChanged -= value; }
161 [EditorBrowsable (EditorBrowsableState.Never)]
162 public new event EventHandler TextChanged {
163 add { base.TextChanged += value; }
164 remove { base.TextChanged -= value; }
168 #region Public Constructors
176 base.Resize += new EventHandler (OnResizeTB);
178 SetStyle (ControlStyles.UserPaint |
179 ControlStyles.Selectable |
180 ControlStyles.ResizeRedraw |
183 | ControlStyles.UseTextForAccessibility
187 #endregion // Public Constructors
189 #region Public Instance Properties
192 [EditorBrowsable (EditorBrowsableState.Never)]
193 public override bool AllowDrop
195 get { return base.AllowDrop; }
197 base.AllowDrop = value;
201 // Setting this property in MS .Net 1.1 does not have any visual effect and it
202 // does not fire a BackColorChanged event
204 [EditorBrowsable (EditorBrowsableState.Never)]
205 public override Color BackColor
207 get { return base.BackColor; }
208 set { base.BackColor = value; }
211 // Setting this property in MS .Net 1.1 does not have any visual effect and it
212 // does not fire a BackgroundImageChanged event
214 [EditorBrowsable (EditorBrowsableState.Never)]
215 public override Image BackgroundImage
217 get { return base.BackgroundImage; }
218 set { base.BackgroundImage = value; }
222 [EditorBrowsable (EditorBrowsableState.Never)]
223 public new bool CausesValidation
225 get { return base.CausesValidation; }
226 set { base.CausesValidation = value; }
229 protected override CreateParams CreateParams
231 get { return base.CreateParams; }
234 protected override ImeMode DefaultImeMode
236 get { return base.DefaultImeMode; }
239 protected override Size DefaultSize
241 get { return ThemeEngine.Current.ProgressBarDefaultSize; }
244 // Setting this property in MS .Net 1.1 does not have any visual effect and it
245 // does not fire a FontChanged event
247 [EditorBrowsable (EditorBrowsableState.Never)]
248 public override Font Font
250 get { return base.Font; }
251 set { base.Font = value; }
254 // Setting this property in MS .Net 1.1 does not have any visual effect and it
255 // does not fire a FontChanged event
257 [EditorBrowsable (EditorBrowsableState.Never)]
258 public override Color ForeColor
260 get { return base.ForeColor; }
261 set { base.ForeColor = value; }
265 [EditorBrowsable (EditorBrowsableState.Never)]
266 public new ImeMode ImeMode
268 get { return base.ImeMode; }
269 set { base.ImeMode = value; }
272 [RefreshProperties(RefreshProperties.Repaint)]
281 throw new ArgumentException(
282 string.Format("Value '{0}' must be greater than or equal to 0.", value ));
289 [RefreshProperties(RefreshProperties.Repaint)]
297 throw new ArgumentException(
298 string.Format("Value '{0}' must be greater than or equal to 0.", value ));
306 [EditorBrowsable (EditorBrowsableState.Never)]
307 public override RightToLeft RightToLeft
309 get { return base.RightToLeft; }
310 set { base.RightToLeft = value; }
324 [MonoTODO("Currently only implements the 1.1 behavior")]
326 // This means that we must implement Blocks, Continuous and Marquee
329 public ProgressBarStyle Style {
339 int marquee_animation_speed = 350;
340 [MonoTODO("Currently does nothing")]
341 public int MarqueeAnimationSpeed {
343 return marquee_animation_speed;
347 marquee_animation_speed = value;
353 [EditorBrowsable (EditorBrowsableState.Never)]
354 public new bool TabStop
356 get { return base.TabStop; }
357 set { base.TabStop = value; }
361 [EditorBrowsable (EditorBrowsableState.Never)]
363 public override string Text
365 get { return base.Text; }
366 set { base.Text = value; }
377 if (value < Minimum || value > Maximum)
378 throw new ArgumentException(
379 string.Format("'{0}' is not a valid value for 'Value'. 'Value' should be between 'Minimum' and 'Maximum'", value));
387 #endregion // Protected Instance Properties
389 #region Public Instance Methods
391 protected override void CreateHandle ()
393 base.CreateHandle ();
396 public void Increment (int value)
398 int newValue = Value + value;
400 if (newValue < Minimum)
403 if (newValue > Maximum)
410 protected override void OnHandleCreated (EventArgs e)
412 base.OnHandleCreated (e);
417 public void PerformStep ()
419 if (Value >= Maximum)
422 Value = Maximum < Value + Step ? Maximum : Value + Step;
423 Refresh (); // FIXME - calculate delta and only expose that
426 public override string ToString()
428 return string.Format ("{0}, Minimum: {1}, Maximum: {2}, Value: {3}",
429 GetType().FullName.ToString (),
435 #endregion // Public Instance Methods
437 #region Private Instance Methods
438 private void UpdateAreas ()
440 client_area.X = client_area.Y = 2;
441 client_area.Width = Width - 4;
442 client_area.Height = Height - 4;
445 private void OnResizeTB (Object o, EventArgs e)
447 if (Width <= 0 || Height <= 0)
451 Invalidate(); // Invalidate the full surface, blocks will not match
454 internal override void OnPaintInternal (PaintEventArgs pevent)
456 ThemeEngine.Current.DrawProgressBar (pevent.Graphics, pevent.ClipRectangle, this);