(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ProgressBar.cs
blob2defa199cb02742c288f112184fe0dd4ae41d5a1
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:
8 //
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 Novell, Inc.
22 // Autors:
23 // Jordi Mas i Hernandez jordi@ximian.com
26 // $Revision: 1.9 $
27 // $Modtime: $
28 // $Log: ProgressBar.cs,v $
29 // Revision 1.9 2004/10/05 04:56:11 jackson
30 // Let the base Control handle the buffers, derived classes should not have to CreateBuffers themselves.
32 // Revision 1.8 2004/09/28 18:44:25 pbartok
33 // - Streamlined Theme interfaces:
34 // * Each DrawXXX method for a control now is passed the object for the
35 // control to be drawn in order to allow accessing any state the theme
36 // might require
38 // * ControlPaint methods for the theme now have a CP prefix to avoid
39 // name clashes with the Draw methods for controls
41 // * Every control now retrieves it's DefaultSize from the current theme
43 // Revision 1.7 2004/08/25 18:29:14 jordi
44 // new methods, properties, and fixes for progressbar
46 // Revision 1.6 2004/08/10 15:41:50 jackson
47 // Allow control to handle buffering
49 // Revision 1.5 2004/07/26 17:42:03 jordi
50 // Theme support
52 // Revision 1.4 2004/07/09 20:13:05 miguel
53 // Spelling
55 // Revision 1.3 2004/07/09 17:25:23 pbartok
56 // - Removed usage of Rectangle for drawing. Miguel pointed out it's faster
58 // Revision 1.2 2004/07/09 17:17:46 miguel
59 // 2004-07-09 Miguel de Icaza <miguel@ximian.com>
61 // * ProgressBar.cs: Fixed spelling for `block'
63 // drawProgressBar: renamed to `DrawProgressBar' to follow the coding
64 // style guidelines.
66 // Avoid using the += on rect.X, that exposed a bug in the compiler.
68 // Revision 1.1 2004/07/09 05:21:25 pbartok
69 // - Initial check-in
73 using System.Drawing;
74 using System.ComponentModel;
75 using System.Drawing.Imaging;
76 using System.Drawing.Drawing2D;
78 namespace System.Windows.Forms
80 public sealed class ProgressBar : Control
82 #region Local Variables
83 private int maximum;
84 private int minimum;
85 internal int step;
86 internal int val;
87 internal Rectangle paint_area = new Rectangle ();
88 internal Rectangle client_area = new Rectangle ();
89 #endregion // Local Variables
91 #region Events
92 public new event EventHandler BackColorChanged;
93 public new event EventHandler BackgroundImageChanged;
94 public new event EventHandler CausesValidationChanged;
95 public new event EventHandler DoubleClick;
96 public new event EventHandler Enter;
97 public new event EventHandler FontChanged;
98 public new event EventHandler ForeColorChanged;
99 public new event EventHandler ImeModeChanged;
100 public new event KeyEventHandler KeyDown;
101 public new event KeyPressEventHandler KeyPress;
102 public new event KeyEventHandler KeyUp;
103 public new event EventHandler Leave;
104 public new event PaintEventHandler Paint;
105 public new event EventHandler RightToLeftChanged;
106 public new event EventHandler TabStopChanged;
107 public new event EventHandler TextChanged;
108 #endregion Events
110 #region Public Constructors
111 public ProgressBar()
113 maximum = 100;
114 minimum = 0;
115 step = 10;
116 val = 0;
118 base.Paint += new PaintEventHandler (OnPaintPB);
119 base.Resize += new EventHandler (OnResizeTB);
121 SetStyle (ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
122 SetStyle (ControlStyles.ResizeRedraw | ControlStyles.Opaque, true);
124 #endregion // Public Constructors
126 #region Public Instance Properties
128 public override bool AllowDrop
130 get { return base.AllowDrop; }
131 set {
132 base.AllowDrop = value;
136 // Setting this property in MS .Net 1.1 does not have any visual effect and it
137 // does not fires a BackColorChanged event
138 public override Color BackColor
140 get { return base.BackColor; }
141 set { BackColor = value; }
144 // Setting this property in MS .Net 1.1 does not have any visual effect and it
145 // does not fires a BackgroundImageChanged event
146 public override Image BackgroundImage
148 get { return base.BackgroundImage; }
149 set {BackgroundImage = value; }
152 public new bool CausesValidation
154 get { return base.CausesValidation; }
155 set {
156 if (base.CausesValidation == value)
157 return;
159 CausesValidation = value;
160 if (CausesValidationChanged != null)
161 CausesValidationChanged (this, new EventArgs ());
165 protected override CreateParams CreateParams
167 get { return base.CreateParams; }
170 protected override ImeMode DefaultImeMode
172 get { return base.DefaultImeMode; }
175 protected override Size DefaultSize
177 get { return ThemeEngine.Current.ProgressBarDefaultSize; }
180 // Setting this property in MS .Net 1.1 does not have any visual effect and it
181 // does not fires a FontChanged event
182 public override Font Font
184 get { return base.Font; }
185 set { base.Font = value; }
188 // Setting this property in MS .Net 1.1 does not have any visual effect and it
189 // does not fires a FontChanged event
190 public override Color ForeColor
192 get { return base.ForeColor; }
193 set { base.ForeColor = value; }
196 public new ImeMode ImeMode
198 get { return base.ImeMode; }
201 if (value == base.ImeMode)
202 return;
204 base.ImeMode = value;
205 if (ImeModeChanged != null)
206 ImeModeChanged (this, EventArgs.Empty);
210 public int Maximum
212 get {
213 return maximum;
215 set {
216 if (value < 0)
217 throw new ArgumentException(
218 string.Format("Value '{0}' must be greater than or equal to 0.", value ));
220 maximum = value;
221 Refresh ();
225 public int Minimum {
226 get {
227 return minimum;
229 set {
230 if (value < 0)
231 throw new ArgumentException(
232 string.Format("Value '{0}' must be greater than or equal to 0.", value ));
234 minimum = value;
235 Refresh ();
239 public override RightToLeft RightToLeft
241 get { return base.RightToLeft; }
242 set {
243 if (base.RightToLeft == value)
244 return;
246 base.RightToLeft = value;
248 if (RightToLeftChanged != null)
249 RightToLeftChanged (this, EventArgs.Empty);
254 public int Step
256 get { return step; }
257 set {
258 step = value;
259 Refresh ();
263 public new bool TabStop
265 get { return base.TabStop; }
266 set {
267 if (base.TabStop == value)
268 return;
270 base.TabStop = value;
272 if (TabStopChanged != null)
273 TabStopChanged (this, EventArgs.Empty);
278 public override string Text
280 get { return base.Text; }
283 if (value == base.Text)
284 return;
286 if (TextChanged != null)
287 TextChanged (this, EventArgs.Empty);
289 Refresh ();
294 public int Value
296 get {
297 return val;
299 set {
300 if (value < Minimum || value > Maximum)
301 throw new ArgumentException(
302 string.Format("'{0}' is not a valid value for 'Value'. 'Value' should be between 'Minimum' and 'Maximum'", value));
304 val = value;
305 Refresh ();
310 #endregion // Protected Instance Properties
312 #region Public Instance Methods
315 public void Increment (int value)
317 int newValue = Value + value;
319 if (newValue < Minimum)
320 newValue = Minimum;
322 if (newValue > Maximum)
323 newValue = Maximum;
325 Value = newValue;
326 Refresh ();
329 protected override void OnHandleCreated (EventArgs e)
331 base.OnHandleCreated (e);
333 UpdateAreas ();
335 CreateBuffers (Width, Height);
336 Draw ();
339 public void PerformStep ()
341 if (Value >= Maximum)
342 return;
344 Value = Value + Step;
345 Refresh ();
348 public override string ToString()
350 return string.Format ("{0}, Minimum: {1}, Maximum: {2}, Value: {3}",
351 GetType().FullName.ToString (),
352 Maximum.ToString (),
353 Minimum.ToString (),
354 Value.ToString () );
357 #endregion // Public Instance Methods
359 #region Private Instance Methods
360 private void UpdateAreas ()
362 paint_area.X = paint_area.Y = 0;
363 paint_area.Width = Width;
364 paint_area.Height = Height;
366 client_area.X = client_area.Y = 2;
367 client_area.Width = Width - 4;
368 client_area.Height = Height - 4;
371 private void OnResizeTB (Object o, EventArgs e)
373 if (Width <= 0 || Height <= 0)
374 return;
376 UpdateAreas ();
379 /* Disable background painting to avoid flickering, since we do our painting*/
380 protected override void OnPaintBackground (PaintEventArgs pevent)
382 // None
385 private void Draw ()
387 ThemeEngine.Current.DrawProgressBar (DeviceContext, this.ClientRectangle, this);
390 private void OnPaintPB (Object o, PaintEventArgs pevent)
392 if (Width <= 0 || Height <= 0 || Visible == false)
393 return;
395 /* Copies memory drawing buffer to screen*/
396 Draw ();
397 pevent.Graphics.DrawImage (ImageBuffer, 0, 0);
400 #endregion