make another pass at corcompare, mostly attributes on classes/properties/events/etc
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ProgressBar.cs
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.
11 //
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.
19 //
20 // Copyright (C) 2004-2006 Novell, Inc.
21 //
22 // Authors:
23 //              Jordi Mas i Hernandez   jordi@ximian.com
24 //              Peter Dennis Bartok     pbartok@novell.com
25 //
26 //
27
28
29 using System.Drawing;
30 using System.ComponentModel;
31 using System.Drawing.Imaging;
32 using System.Drawing.Drawing2D;
33 using System.Runtime.InteropServices;
34
35 namespace System.Windows.Forms
36 {
37         [DefaultProperty ("Value")]
38 #if NET_2_0
39         [DefaultBindingProperty ("Value")]
40         [ClassInterface (ClassInterfaceType.AutoDispatch)]
41         [ComVisible (true)]
42 #endif
43         public
44 #if !NET_2_0
45         sealed
46 #endif
47         class ProgressBar : Control
48         {
49                 #region Local Variables
50                 private int maximum;
51                 private int minimum;
52                 internal int step;
53                 internal int val;
54                 internal Rectangle client_area = new Rectangle ();
55 #if NET_2_0
56                 internal ProgressBarStyle style;
57 #endif          
58                 #endregion      // Local Variables
59
60                 #region events
61                 [Browsable (false)]
62                 [EditorBrowsable (EditorBrowsableState.Never)]          
63                 public new event EventHandler BackColorChanged {
64                         add { base.BackColorChanged += value; }
65                         remove { base.BackColorChanged -= value; }
66                 }
67                 
68                 [Browsable (false)]
69                 [EditorBrowsable (EditorBrowsableState.Never)]
70                 public new event EventHandler BackgroundImageChanged {
71                         add { base.BackgroundImageChanged += value; }
72                         remove { base.BackgroundImageChanged -= value; }
73                 }
74                 
75                 [Browsable (false)]
76                 [EditorBrowsable (EditorBrowsableState.Never)]
77                 public new event EventHandler CausesValidationChanged {
78                         add { base.CausesValidationChanged += value; }
79                         remove { base.CausesValidationChanged -= value; }
80                 }
81                 
82                 [Browsable (false)]
83                 [EditorBrowsable (EditorBrowsableState.Never)]
84                 public new event EventHandler DoubleClick {
85                         add { base.DoubleClick += value; }
86                         remove { base.DoubleClick -= value; }
87                 }
88                 
89                 [Browsable (false)]
90                 [EditorBrowsable (EditorBrowsableState.Never)]
91                 public new event EventHandler Enter {
92                         add { base.Enter += value; }
93                         remove { base.Enter -= value; }
94                 }
95                 
96                 [Browsable (false)]
97                 [EditorBrowsable (EditorBrowsableState.Never)]
98                 public new event EventHandler FontChanged {
99                         add { base.FontChanged += value; }
100                         remove { base.FontChanged -= value; }
101                 }
102                 
103                 [Browsable (false)]
104                 [EditorBrowsable (EditorBrowsableState.Never)]
105                 public new event EventHandler ForeColorChanged {
106                         add { base.ForeColorChanged += value; }
107                         remove { base.ForeColorChanged -= value; }
108                 }
109                 
110                 [Browsable (false)]
111                 [EditorBrowsable (EditorBrowsableState.Never)]
112                 public new event EventHandler ImeModeChanged {
113                         add { base.ImeModeChanged += value; }
114                         remove { base.ImeModeChanged -= value; }
115                 }
116                 
117                 [Browsable (false)]
118                 [EditorBrowsable (EditorBrowsableState.Never)]
119                 public new event KeyEventHandler KeyDown {
120                         add { base.KeyDown += value; }
121                         remove { base.KeyDown -= value; }
122                 }
123                 
124                 [Browsable (false)]
125                 [EditorBrowsable (EditorBrowsableState.Never)]
126                 public new event KeyPressEventHandler KeyPress {
127                         add { base.KeyPress += value; }
128                         remove { base.KeyPress -= value; }
129                 }
130                 
131                 [Browsable (false)]
132                 [EditorBrowsable (EditorBrowsableState.Never)]
133                 public new event KeyEventHandler KeyUp {
134                         add { base.KeyUp += value; }
135                         remove { base.KeyUp -= value; }
136                 }
137                 
138                 [Browsable (false)]
139                 [EditorBrowsable (EditorBrowsableState.Never)]
140                 public new event EventHandler Leave {
141                         add { base.Leave += value; }
142                         remove { base.Leave -= value; }
143                 }
144                 
145                 [Browsable (false)]
146                 [EditorBrowsable (EditorBrowsableState.Never)]
147                 public new event PaintEventHandler Paint {
148                         add { base.Paint += value; }
149                         remove { base.Paint -= value; }
150                 }
151                 
152                 [Browsable (false)]
153                 [EditorBrowsable (EditorBrowsableState.Never)]
154                 public new event EventHandler RightToLeftChanged {
155                         add { base.RightToLeftChanged += value; }
156                         remove { base.RightToLeftChanged -= value; }
157                 }
158                 
159                 [Browsable (false)]
160                 [EditorBrowsable (EditorBrowsableState.Never)]
161                 public new event EventHandler TabStopChanged {
162                         add { base.TabStopChanged += value; }
163                         remove { base.TabStopChanged -= value; }
164                 }
165                 
166                 [Browsable (false)]
167                 [EditorBrowsable (EditorBrowsableState.Never)]
168                 public new event EventHandler TextChanged {
169                         add { base.TextChanged += value; }
170                         remove { base.TextChanged -= value; }
171                 }
172                 #endregion Events
173
174                 #region Public Constructors
175                 public ProgressBar()
176                 {
177                         maximum = 100;
178                         minimum = 0;
179                         step = 10;
180                         val = 0;
181
182                         base.Resize += new EventHandler (OnResizeTB);
183
184                         SetStyle (ControlStyles.UserPaint | 
185                                 ControlStyles.Selectable | 
186                                 ControlStyles.ResizeRedraw | 
187                                 ControlStyles.Opaque
188 #if NET_2_0
189                                 | ControlStyles.UseTextForAccessibility
190 #endif
191                                 , false);
192                 }
193                 #endregion      // Public Constructors
194
195                 #region Public Instance Properties
196
197                 [Browsable (false)]
198                 [EditorBrowsable (EditorBrowsableState.Never)]
199                 public override bool AllowDrop
200                 {
201                         get { return base.AllowDrop; }
202                         set {
203                                 base.AllowDrop = value;
204                         }
205                 }
206
207                 // Setting this property in MS .Net 1.1 does not have any visual effect and it
208                 // does not fire a BackColorChanged event
209                 [Browsable (false)]
210                 [EditorBrowsable (EditorBrowsableState.Never)]
211                 public override Color BackColor
212                 {
213                         get { return base.BackColor; }
214                         set { base.BackColor = value; }
215                 }
216
217                 // Setting this property in MS .Net 1.1 does not have any visual effect and it
218                 // does not fire a BackgroundImageChanged event
219                 [Browsable (false)]
220                 [EditorBrowsable (EditorBrowsableState.Never)]
221                 public override Image BackgroundImage
222                 {
223                         get { return base.BackgroundImage; }
224                         set { base.BackgroundImage = value; }
225                 }
226
227                 [Browsable (false)]
228                 [EditorBrowsable (EditorBrowsableState.Never)]
229                 public new bool CausesValidation
230                 {
231                         get { return base.CausesValidation; }
232                         set { base.CausesValidation = value; }
233                 }
234
235                 protected override CreateParams CreateParams
236                 {
237                         get { return base.CreateParams; }
238                 }
239
240                 protected override ImeMode DefaultImeMode
241                 {
242                         get { return base.DefaultImeMode; }
243                 }
244
245                 protected override Size DefaultSize
246                 {
247                         get { return ThemeEngine.Current.ProgressBarDefaultSize; }
248                 }
249
250                 // Setting this property in MS .Net 1.1 does not have any visual effect and it
251                 // does not fire a FontChanged event
252                 [Browsable (false)]
253                 [EditorBrowsable (EditorBrowsableState.Never)]
254                 public override Font Font
255                 {
256                         get { return base.Font; }
257                         set { base.Font = value; }
258                 }
259
260                 // Setting this property in MS .Net 1.1 does not have any visual effect and it
261                 // does not fire a FontChanged event
262                 [Browsable (false)]
263                 [EditorBrowsable (EditorBrowsableState.Never)]
264                 public override Color ForeColor
265                 {
266                         get { return base.ForeColor; }
267                         set { base.ForeColor = value; }
268                 }
269
270                 [Browsable (false)]
271                 [EditorBrowsable (EditorBrowsableState.Never)]
272                 public new ImeMode ImeMode
273                 {
274                         get { return base.ImeMode; }
275                         set { base.ImeMode = value; }
276                 }
277
278                 [RefreshProperties(RefreshProperties.Repaint)]
279                 [DefaultValue (100)]
280                 public int Maximum
281                 {
282                         get {
283                                 return maximum;
284                         }
285                         set {
286                                 if (value < 0)
287                                         throw new ArgumentException(
288                                                 string.Format("Value '{0}' must be greater than or equal to 0.", value ));
289
290                                 maximum = value;
291                                 Refresh ();
292                         }
293                 }
294
295                 [RefreshProperties(RefreshProperties.Repaint)]
296                 [DefaultValue (0)]
297                 public int Minimum {
298                         get {
299                                 return minimum;
300                         }
301                         set {
302                                 if (value < 0)
303                                         throw new ArgumentException(
304                                                 string.Format("Value '{0}' must be greater than or equal to 0.", value ));
305
306                                 minimum = value;
307                                 Refresh ();
308                         }
309                 }
310
311                 [Browsable (false)]
312                 [EditorBrowsable (EditorBrowsableState.Never)]
313                 public override RightToLeft RightToLeft
314                 {
315                         get { return base.RightToLeft; }
316                         set { base.RightToLeft = value; }
317                 }
318
319                 [DefaultValue (10)]
320                 public int Step
321                 {
322                         get { return step; }
323                         set {
324                                 step = value;
325                                 Refresh ();
326                         }
327                 }
328
329 #if NET_2_0
330                 [MonoTODO("Currently only implements the 1.1 behavior")]
331                 //
332                 // This means that we must implement Blocks, Continuous and Marquee
333                 // rendering modes
334                 //
335                 [Browsable (true)]
336                 [DefaultValue (ProgressBarStyle.Blocks)]
337                 [EditorBrowsable (EditorBrowsableState.Always)]
338                 public ProgressBarStyle Style {
339                         get {
340                                 return style;
341                         }
342
343                         set {
344                                 style = value;
345                         }
346                 }
347                 
348                 int marquee_animation_speed = 350;
349                 [MonoTODO("Currently does nothing")]
350                 [DefaultValue (100)]
351                 public int MarqueeAnimationSpeed {
352                         get {
353                                 return marquee_animation_speed;
354                         }
355
356                         set {
357                                 marquee_animation_speed = value;
358                         }
359                 }
360 #endif
361
362                 [Browsable (false)]
363                 [EditorBrowsable (EditorBrowsableState.Never)]
364                 public new bool TabStop
365                 {
366                         get { return base.TabStop; }
367                         set { base.TabStop = value; }
368                 }
369
370                 [Browsable (false)]
371                 [EditorBrowsable (EditorBrowsableState.Never)]
372                 [Bindable(false)]
373                 public override string Text
374                 {
375                         get { return base.Text; }
376                         set { base.Text = value; }
377                 }
378
379                 [Bindable(true)]
380                 [DefaultValue (0)]
381                 public int Value
382                 {
383                         get {
384                                 return val;
385                         }
386                         set {
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));
390
391                                 val = value;
392                                 Refresh ();
393                         }
394                 }
395
396
397                 #endregion      // Protected Instance Properties
398
399                 #region Public Instance Methods
400                 
401                 protected override void CreateHandle ()
402                 {
403                         base.CreateHandle ();
404                 }
405
406                 public void Increment (int value)
407                 {
408                         int newValue = Value + value;
409
410                         if (newValue < Minimum)
411                                 newValue = Minimum;
412
413                         if (newValue > Maximum)
414                                 newValue = Maximum;
415
416                         Value = newValue;
417                         Refresh ();
418                 }
419
420                 protected override void OnHandleCreated (EventArgs e)
421                 {
422                         base.OnHandleCreated (e);
423
424                         UpdateAreas ();
425                 }
426
427                 public void PerformStep ()
428                 {
429                         if (Value >= Maximum)
430                                 return;
431
432                         Value = Maximum < Value + Step ? Maximum : Value + Step;
433                         Refresh ();     // FIXME - calculate delta and only expose that
434                 }
435
436                 public override string ToString()
437                 {
438                         return string.Format ("{0}, Minimum: {1}, Maximum: {2}, Value: {3}",
439                                 GetType().FullName.ToString (),
440                                 Minimum.ToString (),
441                                 Maximum.ToString (),
442                                 Value.ToString () );
443                 }
444
445                 #endregion      // Public Instance Methods
446
447                 #region Private Instance Methods
448                 private void UpdateAreas ()
449                 {
450                         client_area.X = client_area.Y = 2;
451                         client_area.Width = Width - 4;
452                         client_area.Height = Height - 4;
453                 }
454
455                 private void OnResizeTB (Object o, EventArgs e)
456                 {
457                         if (Width <= 0 || Height <= 0)
458                                 return;
459
460                         UpdateAreas ();
461                         Invalidate();   // Invalidate the full surface, blocks will not match
462                 }
463
464                 internal override void OnPaintInternal (PaintEventArgs pevent)
465                 {
466                         ThemeEngine.Current.DrawProgressBar (pevent.Graphics, pevent.ClipRectangle, this);
467                 }               
468
469                 #endregion
470         }
471 }