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
;
33 using System
.Runtime
.InteropServices
;
35 namespace System
.Windows
.Forms
37 [DefaultProperty ("Value")]
39 [DefaultBindingProperty ("Value")]
40 [ClassInterface (ClassInterfaceType
.AutoDispatch
)]
47 class ProgressBar
: Control
49 #region Local Variables
54 internal Rectangle client_area
= new Rectangle ();
56 internal ProgressBarStyle style
;
58 #endregion // Local Variables
62 [EditorBrowsable (EditorBrowsableState
.Never
)]
63 public new event EventHandler BackColorChanged
{
64 add { base.BackColorChanged += value; }
65 remove { base.BackColorChanged -= value; }
69 [EditorBrowsable (EditorBrowsableState
.Never
)]
70 public new event EventHandler BackgroundImageChanged
{
71 add { base.BackgroundImageChanged += value; }
72 remove { base.BackgroundImageChanged -= value; }
76 [EditorBrowsable (EditorBrowsableState
.Never
)]
77 public new event EventHandler CausesValidationChanged
{
78 add { base.CausesValidationChanged += value; }
79 remove { base.CausesValidationChanged -= value; }
83 [EditorBrowsable (EditorBrowsableState
.Never
)]
84 public new event EventHandler DoubleClick
{
85 add { base.DoubleClick += value; }
86 remove { base.DoubleClick -= value; }
90 [EditorBrowsable (EditorBrowsableState
.Never
)]
91 public new event EventHandler Enter
{
92 add { base.Enter += value; }
93 remove { base.Enter -= value; }
97 [EditorBrowsable (EditorBrowsableState
.Never
)]
98 public new event EventHandler FontChanged
{
99 add { base.FontChanged += value; }
100 remove { base.FontChanged -= value; }
104 [EditorBrowsable (EditorBrowsableState
.Never
)]
105 public new event EventHandler ForeColorChanged
{
106 add { base.ForeColorChanged += value; }
107 remove { base.ForeColorChanged -= value; }
111 [EditorBrowsable (EditorBrowsableState
.Never
)]
112 public new event EventHandler ImeModeChanged
{
113 add { base.ImeModeChanged += value; }
114 remove { base.ImeModeChanged -= value; }
118 [EditorBrowsable (EditorBrowsableState
.Never
)]
119 public new event KeyEventHandler KeyDown
{
120 add { base.KeyDown += value; }
121 remove { base.KeyDown -= value; }
125 [EditorBrowsable (EditorBrowsableState
.Never
)]
126 public new event KeyPressEventHandler KeyPress
{
127 add { base.KeyPress += value; }
128 remove { base.KeyPress -= value; }
132 [EditorBrowsable (EditorBrowsableState
.Never
)]
133 public new event KeyEventHandler KeyUp
{
134 add { base.KeyUp += value; }
135 remove { base.KeyUp -= value; }
139 [EditorBrowsable (EditorBrowsableState
.Never
)]
140 public new event EventHandler Leave
{
141 add { base.Leave += value; }
142 remove { base.Leave -= value; }
146 [EditorBrowsable (EditorBrowsableState
.Never
)]
147 public new event PaintEventHandler Paint
{
148 add { base.Paint += value; }
149 remove { base.Paint -= value; }
153 [EditorBrowsable (EditorBrowsableState
.Never
)]
154 public new event EventHandler RightToLeftChanged
{
155 add { base.RightToLeftChanged += value; }
156 remove { base.RightToLeftChanged -= value; }
160 [EditorBrowsable (EditorBrowsableState
.Never
)]
161 public new event EventHandler TabStopChanged
{
162 add { base.TabStopChanged += value; }
163 remove { base.TabStopChanged -= value; }
167 [EditorBrowsable (EditorBrowsableState
.Never
)]
168 public new event EventHandler TextChanged
{
169 add { base.TextChanged += value; }
170 remove { base.TextChanged -= value; }
174 #region Public Constructors
182 base.Resize
+= new EventHandler (OnResizeTB
);
184 SetStyle (ControlStyles
.UserPaint
|
185 ControlStyles
.Selectable
|
186 ControlStyles
.ResizeRedraw
|
189 | ControlStyles
.UseTextForAccessibility
193 #endregion // Public Constructors
195 #region Public Instance Properties
198 [EditorBrowsable (EditorBrowsableState
.Never
)]
199 public override bool AllowDrop
201 get { return base.AllowDrop; }
203 base.AllowDrop
= value;
207 // Setting this property in MS .Net 1.1 does not have any visual effect and it
208 // does not fire a BackColorChanged event
210 [EditorBrowsable (EditorBrowsableState
.Never
)]
211 public override Color BackColor
213 get { return base.BackColor; }
214 set { base.BackColor = value; }
217 // Setting this property in MS .Net 1.1 does not have any visual effect and it
218 // does not fire a BackgroundImageChanged event
220 [EditorBrowsable (EditorBrowsableState
.Never
)]
221 public override Image BackgroundImage
223 get { return base.BackgroundImage; }
224 set { base.BackgroundImage = value; }
228 [EditorBrowsable (EditorBrowsableState
.Never
)]
229 public new bool CausesValidation
231 get { return base.CausesValidation; }
232 set { base.CausesValidation = value; }
235 protected override CreateParams CreateParams
237 get { return base.CreateParams; }
240 protected override ImeMode DefaultImeMode
242 get { return base.DefaultImeMode; }
245 protected override Size DefaultSize
247 get { return ThemeEngine.Current.ProgressBarDefaultSize; }
250 // Setting this property in MS .Net 1.1 does not have any visual effect and it
251 // does not fire a FontChanged event
253 [EditorBrowsable (EditorBrowsableState
.Never
)]
254 public override Font Font
256 get { return base.Font; }
257 set { base.Font = value; }
260 // Setting this property in MS .Net 1.1 does not have any visual effect and it
261 // does not fire a FontChanged event
263 [EditorBrowsable (EditorBrowsableState
.Never
)]
264 public override Color ForeColor
266 get { return base.ForeColor; }
267 set { base.ForeColor = value; }
271 [EditorBrowsable (EditorBrowsableState
.Never
)]
272 public new ImeMode ImeMode
274 get { return base.ImeMode; }
275 set { base.ImeMode = value; }
278 [RefreshProperties(RefreshProperties
.Repaint
)]
287 throw new ArgumentException(
288 string.Format("Value '{0}' must be greater than or equal to 0.", value ));
295 [RefreshProperties(RefreshProperties
.Repaint
)]
303 throw new ArgumentException(
304 string.Format("Value '{0}' must be greater than or equal to 0.", value ));
312 [EditorBrowsable (EditorBrowsableState
.Never
)]
313 public override RightToLeft RightToLeft
315 get { return base.RightToLeft; }
316 set { base.RightToLeft = value; }
330 [MonoTODO("Currently only implements the 1.1 behavior")]
332 // This means that we must implement Blocks, Continuous and Marquee
336 [DefaultValue (ProgressBarStyle
.Blocks
)]
337 [EditorBrowsable (EditorBrowsableState
.Always
)]
338 public ProgressBarStyle Style
{
348 int marquee_animation_speed
= 350;
349 [MonoTODO("Currently does nothing")]
351 public int MarqueeAnimationSpeed
{
353 return marquee_animation_speed
;
357 marquee_animation_speed
= value;
363 [EditorBrowsable (EditorBrowsableState
.Never
)]
364 public new bool TabStop
366 get { return base.TabStop; }
367 set { base.TabStop = value; }
371 [EditorBrowsable (EditorBrowsableState
.Never
)]
373 public override string Text
375 get { return base.Text; }
376 set { base.Text = value; }
387 if (value < Minimum
|| value > Maximum
)
388 throw new ArgumentException(
389 string.Format("'{0}' is not a valid value for 'Value'. 'Value' should be between 'Minimum' and 'Maximum'", value));
397 #endregion // Protected Instance Properties
399 #region Public Instance Methods
401 protected override void CreateHandle ()
403 base.CreateHandle ();
406 public void Increment (int value)
408 int newValue
= Value
+ value;
410 if (newValue
< Minimum
)
413 if (newValue
> Maximum
)
420 protected override void OnHandleCreated (EventArgs e
)
422 base.OnHandleCreated (e
);
427 public void PerformStep ()
429 if (Value
>= Maximum
)
432 Value
= Maximum
< Value
+ Step
? Maximum
: Value
+ Step
;
433 Refresh (); // FIXME - calculate delta and only expose that
436 public override string ToString()
438 return string.Format ("{0}, Minimum: {1}, Maximum: {2}, Value: {3}",
439 GetType().FullName
.ToString (),
445 #endregion // Public Instance Methods
447 #region Private Instance Methods
448 private void UpdateAreas ()
450 client_area
.X
= client_area
.Y
= 2;
451 client_area
.Width
= Width
- 4;
452 client_area
.Height
= Height
- 4;
455 private void OnResizeTB (Object o
, EventArgs e
)
457 if (Width
<= 0 || Height
<= 0)
461 Invalidate(); // Invalidate the full surface, blocks will not match
464 internal override void OnPaintInternal (PaintEventArgs pevent
)
466 ThemeEngine
.Current
.DrawProgressBar (pevent
.Graphics
, pevent
.ClipRectangle
, this);