mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-23 03:39:43 -10:00
ResetForeColor override on 2.0. Fixed a few API compatibility issues. Spaces to tabs. Removed extra tabs. * ProgressBarTest.cs: Added ForeColor and ResetForeColor tests. svn path=/trunk/mcs/; revision=75502
514 lines
12 KiB
C#
514 lines
12 KiB
C#
// Permission is hereby granted, free of charge, to any person obtaining
|
|
// a copy of this software and associated documentation files (the
|
|
// "Software"), to deal in the Software without restriction, including
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
|
// permit persons to whom the Software is furnished to do so, subject to
|
|
// the following conditions:
|
|
//
|
|
// The above copyright notice and this permission notice shall be
|
|
// included in all copies or substantial portions of the Software.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
//
|
|
// Copyright (C) 2004-2006 Novell, Inc.
|
|
//
|
|
// Authors:
|
|
// Jordi Mas i Hernandez [email protected]
|
|
// Peter Dennis Bartok [email protected]
|
|
//
|
|
//
|
|
|
|
using System.Drawing;
|
|
using System.ComponentModel;
|
|
using System.Drawing.Imaging;
|
|
using System.Drawing.Drawing2D;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace System.Windows.Forms
|
|
{
|
|
[DefaultProperty ("Value")]
|
|
#if NET_2_0
|
|
[DefaultBindingProperty ("Value")]
|
|
[ClassInterface (ClassInterfaceType.AutoDispatch)]
|
|
[ComVisible (true)]
|
|
#endif
|
|
public
|
|
#if !NET_2_0
|
|
sealed
|
|
#endif
|
|
class ProgressBar : Control
|
|
{
|
|
#region Local Variables
|
|
private int maximum;
|
|
private int minimum;
|
|
internal int step;
|
|
internal int val;
|
|
internal DateTime start = DateTime.Now;
|
|
internal Rectangle client_area = new Rectangle ();
|
|
#if NET_2_0
|
|
internal ProgressBarStyle style;
|
|
Timer marquee_timer;
|
|
#endif
|
|
|
|
#if NET_2_0
|
|
private static readonly Color defaultForeColor = SystemColors.Highlight;
|
|
#endif
|
|
#endregion // Local Variables
|
|
|
|
#region events
|
|
|
|
#if ONLY_1_1
|
|
[Browsable (false)]
|
|
[EditorBrowsable (EditorBrowsableState.Never)]
|
|
public new event EventHandler BackColorChanged {
|
|
add { base.BackColorChanged += value; }
|
|
remove { base.BackColorChanged -= value; }
|
|
}
|
|
#endif
|
|
|
|
[Browsable (false)]
|
|
[EditorBrowsable (EditorBrowsableState.Never)]
|
|
public new event EventHandler BackgroundImageChanged {
|
|
add { base.BackgroundImageChanged += value; }
|
|
remove { base.BackgroundImageChanged -= value; }
|
|
}
|
|
|
|
[Browsable (false)]
|
|
[EditorBrowsable (EditorBrowsableState.Never)]
|
|
public new event EventHandler CausesValidationChanged {
|
|
add { base.CausesValidationChanged += value; }
|
|
remove { base.CausesValidationChanged -= value; }
|
|
}
|
|
|
|
[Browsable (false)]
|
|
[EditorBrowsable (EditorBrowsableState.Never)]
|
|
public new event EventHandler DoubleClick {
|
|
add { base.DoubleClick += value; }
|
|
remove { base.DoubleClick -= value; }
|
|
}
|
|
|
|
[Browsable (false)]
|
|
[EditorBrowsable (EditorBrowsableState.Never)]
|
|
public new event EventHandler Enter {
|
|
add { base.Enter += value; }
|
|
remove { base.Enter -= value; }
|
|
}
|
|
|
|
[Browsable (false)]
|
|
[EditorBrowsable (EditorBrowsableState.Never)]
|
|
public new event EventHandler FontChanged {
|
|
add { base.FontChanged += value; }
|
|
remove { base.FontChanged -= value; }
|
|
}
|
|
|
|
#if ONLY_1_1
|
|
[Browsable (false)]
|
|
[EditorBrowsable (EditorBrowsableState.Never)]
|
|
public new event EventHandler ForeColorChanged {
|
|
add { base.ForeColorChanged += value; }
|
|
remove { base.ForeColorChanged -= value; }
|
|
}
|
|
#endif
|
|
|
|
[Browsable (false)]
|
|
[EditorBrowsable (EditorBrowsableState.Never)]
|
|
public new event EventHandler ImeModeChanged {
|
|
add { base.ImeModeChanged += value; }
|
|
remove { base.ImeModeChanged -= value; }
|
|
}
|
|
|
|
[Browsable (false)]
|
|
[EditorBrowsable (EditorBrowsableState.Never)]
|
|
public new event KeyEventHandler KeyDown {
|
|
add { base.KeyDown += value; }
|
|
remove { base.KeyDown -= value; }
|
|
}
|
|
|
|
[Browsable (false)]
|
|
[EditorBrowsable (EditorBrowsableState.Never)]
|
|
public new event KeyPressEventHandler KeyPress {
|
|
add { base.KeyPress += value; }
|
|
remove { base.KeyPress -= value; }
|
|
}
|
|
|
|
[Browsable (false)]
|
|
[EditorBrowsable (EditorBrowsableState.Never)]
|
|
public new event KeyEventHandler KeyUp {
|
|
add { base.KeyUp += value; }
|
|
remove { base.KeyUp -= value; }
|
|
}
|
|
|
|
[Browsable (false)]
|
|
[EditorBrowsable (EditorBrowsableState.Never)]
|
|
public new event EventHandler Leave {
|
|
add { base.Leave += value; }
|
|
remove { base.Leave -= value; }
|
|
}
|
|
|
|
[Browsable (false)]
|
|
[EditorBrowsable (EditorBrowsableState.Never)]
|
|
public new event PaintEventHandler Paint {
|
|
add { base.Paint += value; }
|
|
remove { base.Paint -= value; }
|
|
}
|
|
|
|
#if ONLY_1_1
|
|
[Browsable (false)]
|
|
[EditorBrowsable (EditorBrowsableState.Never)]
|
|
public new event EventHandler RightToLeftChanged {
|
|
add { base.RightToLeftChanged += value; }
|
|
remove { base.RightToLeftChanged -= value; }
|
|
}
|
|
#endif
|
|
|
|
[Browsable (false)]
|
|
[EditorBrowsable (EditorBrowsableState.Never)]
|
|
public new event EventHandler TabStopChanged {
|
|
add { base.TabStopChanged += value; }
|
|
remove { base.TabStopChanged -= value; }
|
|
}
|
|
|
|
[Browsable (false)]
|
|
[EditorBrowsable (EditorBrowsableState.Never)]
|
|
public new event EventHandler TextChanged {
|
|
add { base.TextChanged += value; }
|
|
remove { base.TextChanged -= value; }
|
|
}
|
|
#endregion Events
|
|
|
|
#region Public Constructors
|
|
public ProgressBar()
|
|
{
|
|
maximum = 100;
|
|
minimum = 0;
|
|
step = 10;
|
|
val = 0;
|
|
|
|
base.Resize += new EventHandler (OnResizeTB);
|
|
|
|
SetStyle (ControlStyles.UserPaint |
|
|
ControlStyles.Selectable |
|
|
ControlStyles.ResizeRedraw |
|
|
ControlStyles.Opaque
|
|
#if NET_2_0
|
|
| ControlStyles.UseTextForAccessibility
|
|
#endif
|
|
, false);
|
|
|
|
#if NET_2_0
|
|
ForeColor = defaultForeColor;
|
|
#endif
|
|
}
|
|
#endregion // Public Constructors
|
|
|
|
#region Public Instance Properties
|
|
|
|
[Browsable (false)]
|
|
[EditorBrowsable (EditorBrowsableState.Never)]
|
|
public override bool AllowDrop
|
|
{
|
|
get { return base.AllowDrop; }
|
|
set {
|
|
base.AllowDrop = value;
|
|
}
|
|
}
|
|
|
|
// Setting this property in MS .Net 1.1 does not have any visual effect and it
|
|
// does not fire a BackColorChanged event
|
|
[Browsable (false)]
|
|
[EditorBrowsable (EditorBrowsableState.Never)]
|
|
public override Color BackColor
|
|
{
|
|
get { return base.BackColor; }
|
|
set { base.BackColor = value; }
|
|
}
|
|
|
|
// Setting this property in MS .Net 1.1 does not have any visual effect and it
|
|
// does not fire a BackgroundImageChanged event
|
|
[Browsable (false)]
|
|
[EditorBrowsable (EditorBrowsableState.Never)]
|
|
public override Image BackgroundImage
|
|
{
|
|
get { return base.BackgroundImage; }
|
|
set { base.BackgroundImage = value; }
|
|
}
|
|
|
|
[Browsable (false)]
|
|
[EditorBrowsable (EditorBrowsableState.Never)]
|
|
public new bool CausesValidation
|
|
{
|
|
get { return base.CausesValidation; }
|
|
set { base.CausesValidation = value; }
|
|
}
|
|
|
|
protected override CreateParams CreateParams
|
|
{
|
|
get { return base.CreateParams; }
|
|
}
|
|
|
|
protected override ImeMode DefaultImeMode
|
|
{
|
|
get { return base.DefaultImeMode; }
|
|
}
|
|
|
|
protected override Size DefaultSize
|
|
{
|
|
get { return ThemeEngine.Current.ProgressBarDefaultSize; }
|
|
}
|
|
|
|
// Setting this property in MS .Net 1.1 does not have any visual effect and it
|
|
// does not fire a FontChanged event
|
|
[Browsable (false)]
|
|
[EditorBrowsable (EditorBrowsableState.Never)]
|
|
public override Font Font
|
|
{
|
|
get { return base.Font; }
|
|
set { base.Font = value; }
|
|
}
|
|
|
|
#if ONLY_1_1
|
|
// Setting this property in MS .Net 1.1 does not have any visual effect and it
|
|
// does not fire a FontChanged event
|
|
[Browsable (false)]
|
|
[EditorBrowsable (EditorBrowsableState.Never)]
|
|
public override Color ForeColor
|
|
{
|
|
get { return base.ForeColor; }
|
|
set { base.ForeColor = value; }
|
|
}
|
|
#endif
|
|
|
|
[Browsable (false)]
|
|
[EditorBrowsable (EditorBrowsableState.Never)]
|
|
public new ImeMode ImeMode
|
|
{
|
|
get { return base.ImeMode; }
|
|
set { base.ImeMode = value; }
|
|
}
|
|
|
|
[RefreshProperties(RefreshProperties.Repaint)]
|
|
[DefaultValue (100)]
|
|
public int Maximum
|
|
{
|
|
get {
|
|
return maximum;
|
|
}
|
|
set {
|
|
if (value < 0)
|
|
throw new ArgumentException(
|
|
string.Format("Value '{0}' must be greater than or equal to 0.", value ));
|
|
|
|
maximum = value;
|
|
Refresh ();
|
|
}
|
|
}
|
|
|
|
[RefreshProperties(RefreshProperties.Repaint)]
|
|
[DefaultValue (0)]
|
|
public int Minimum {
|
|
get {
|
|
return minimum;
|
|
}
|
|
set {
|
|
if (value < 0)
|
|
throw new ArgumentException(
|
|
string.Format("Value '{0}' must be greater than or equal to 0.", value ));
|
|
|
|
minimum = value;
|
|
Refresh ();
|
|
}
|
|
}
|
|
|
|
#if ONLY_1_1
|
|
[Browsable (false)]
|
|
[EditorBrowsable (EditorBrowsableState.Never)]
|
|
public override RightToLeft RightToLeft
|
|
{
|
|
get { return base.RightToLeft; }
|
|
set { base.RightToLeft = value; }
|
|
}
|
|
#endif
|
|
|
|
[DefaultValue (10)]
|
|
public int Step
|
|
{
|
|
get { return step; }
|
|
set {
|
|
step = value;
|
|
Refresh ();
|
|
}
|
|
}
|
|
|
|
#if NET_2_0
|
|
[Browsable (true)]
|
|
[DefaultValue (ProgressBarStyle.Blocks)]
|
|
[EditorBrowsable (EditorBrowsableState.Always)]
|
|
public ProgressBarStyle Style {
|
|
get {
|
|
return style;
|
|
}
|
|
|
|
set {
|
|
style = value;
|
|
|
|
if (style == ProgressBarStyle.Marquee) {
|
|
if (marquee_timer == null) {
|
|
marquee_timer = new Timer ();
|
|
marquee_timer.Interval = 10;
|
|
marquee_timer.Tick += new EventHandler (marquee_timer_Tick);
|
|
}
|
|
marquee_timer.Start ();
|
|
} else {
|
|
if (marquee_timer != null) {
|
|
marquee_timer.Stop ();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void marquee_timer_Tick (object sender, EventArgs e)
|
|
{
|
|
Invalidate ();
|
|
}
|
|
|
|
int marquee_animation_speed = 100;
|
|
[DefaultValue (100)]
|
|
public int MarqueeAnimationSpeed {
|
|
get {
|
|
return marquee_animation_speed;
|
|
}
|
|
|
|
set {
|
|
marquee_animation_speed = value;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
[Browsable (false)]
|
|
[EditorBrowsable (EditorBrowsableState.Never)]
|
|
public new bool TabStop
|
|
{
|
|
get { return base.TabStop; }
|
|
set { base.TabStop = value; }
|
|
}
|
|
|
|
[Browsable (false)]
|
|
[EditorBrowsable (EditorBrowsableState.Never)]
|
|
[Bindable(false)]
|
|
public override string Text
|
|
{
|
|
get { return base.Text; }
|
|
set { base.Text = value; }
|
|
}
|
|
|
|
[Bindable(true)]
|
|
[DefaultValue (0)]
|
|
public int Value
|
|
{
|
|
get {
|
|
return val;
|
|
}
|
|
set {
|
|
if (value < Minimum || value > Maximum)
|
|
#if NET_2_0
|
|
throw new ArgumentOutOfRangeException ("Value", string.Format("'{0}' is not a valid value for 'Value'. 'Value' should be between 'Minimum' and 'Maximum'", value));
|
|
#else
|
|
throw new ArgumentException(string.Format("'{0}' is not a valid value for 'Value'. 'Value' should be between 'Minimum' and 'Maximum'", value));
|
|
#endif
|
|
val = value;
|
|
Refresh ();
|
|
}
|
|
}
|
|
|
|
|
|
#endregion // Protected Instance Properties
|
|
|
|
#region Public Instance Methods
|
|
|
|
protected override void CreateHandle ()
|
|
{
|
|
base.CreateHandle ();
|
|
}
|
|
|
|
public void Increment (int value)
|
|
{
|
|
int newValue = Value + value;
|
|
|
|
if (newValue < Minimum)
|
|
newValue = Minimum;
|
|
|
|
if (newValue > Maximum)
|
|
newValue = Maximum;
|
|
|
|
Value = newValue;
|
|
Refresh ();
|
|
}
|
|
|
|
protected override void OnHandleCreated (EventArgs e)
|
|
{
|
|
base.OnHandleCreated (e);
|
|
|
|
UpdateAreas ();
|
|
}
|
|
|
|
public void PerformStep ()
|
|
{
|
|
if (Value >= Maximum)
|
|
return;
|
|
|
|
Value = Maximum < Value + Step ? Maximum : Value + Step;
|
|
Refresh (); // FIXME - calculate delta and only expose that
|
|
}
|
|
|
|
#if NET_2_0
|
|
public override void ResetForeColor ()
|
|
{
|
|
ForeColor = defaultForeColor;
|
|
}
|
|
#endif
|
|
|
|
public override string ToString()
|
|
{
|
|
return string.Format ("{0}, Minimum: {1}, Maximum: {2}, Value: {3}",
|
|
GetType().FullName.ToString (),
|
|
Minimum.ToString (),
|
|
Maximum.ToString (),
|
|
Value.ToString () );
|
|
}
|
|
|
|
#endregion // Public Instance Methods
|
|
|
|
#region Private Instance Methods
|
|
|
|
private void UpdateAreas ()
|
|
{
|
|
client_area.X = client_area.Y = 2;
|
|
client_area.Width = Width - 4;
|
|
client_area.Height = Height - 4;
|
|
}
|
|
|
|
private void OnResizeTB (Object o, EventArgs e)
|
|
{
|
|
if (Width <= 0 || Height <= 0)
|
|
return;
|
|
|
|
UpdateAreas ();
|
|
Invalidate(); // Invalidate the full surface, blocks will not match
|
|
}
|
|
|
|
internal override void OnPaintInternal (PaintEventArgs pevent)
|
|
{
|
|
ThemeEngine.Current.DrawProgressBar (pevent.Graphics, pevent.ClipRectangle, this);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|