DotNet 4.8.1 build of DotNetBar

This commit is contained in:
2025-02-07 10:35:23 -05:00
parent 33439b63a0
commit 6b0a5d60f4
2609 changed files with 989814 additions and 7 deletions

View File

@@ -0,0 +1,600 @@
#if FRAMEWORK20
using System;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
namespace DevComponents.DotNetBar.Schedule
{
[TypeConverter(typeof(TimeIndicatorConvertor))]
public class TimeIndicator : IDisposable
{
#region Events
/// <summary>
/// Occurs when the collection has changed
/// </summary>
[Description("Occurs when the TimeIndicator has changed.")]
public event EventHandler<EventArgs> TimeIndicatorChanged;
/// <summary>
/// Occurs when a TimeIndicator time has changed
/// </summary>
[Description("Occurs when a TimeIndicator time has changed.")]
public event EventHandler<TimeIndicatorTimeChangedEventArgs> TimeIndicatorTimeChanged;
/// <summary>
/// Occurs when a TimeIndicator Color has changed
/// </summary>
[Description("Occurs when a TimeIndicator Color has changed.")]
public event EventHandler<TimeIndicatorColorChangedEventArgs> TimeIndicatorColorChanged;
#endregion
#region Private variables
private DateTime _IndicatorTime;
private TimeSpan _IndicatorTimeOffset;
private eTimeIndicatorArea _IndicatorArea;
private eTimeIndicatorSource _IndicatorSource = eTimeIndicatorSource.SystemTime;
private eTimeIndicatorVisibility _Visibility = eTimeIndicatorVisibility.Hidden;
private eTimeIndicatorLevel _IndicatorLevel = eTimeIndicatorLevel.Bottom;
private Color _BorderColor;
private ColorDef _IndicatorColor = new ColorDef();
private int _Thickness = 4;
private bool _Enabled = true;
private bool _IsProtected;
private bool _IsDesignMode;
private int _UpdateCount;
private object _Tag;
#endregion
/// <summary>
/// Constructor
/// </summary>
public TimeIndicator()
{
_IndicatorTime = DateTime.Now;
_IndicatorColor.ColorDefChanged += IndicatorColor_ColorDefChanged;
}
#region Internal properties
#region IndicatorDisplayTime
/// <summary>
/// Gets the Indicator display time.
///
/// The DisplayTime is the addition of the IndicatorTime
/// and IndicatorTimeOffset.
/// </summary>
internal DateTime IndicatorDisplayTime
{
get
{
if (_IsDesignMode == true)
return (DateTime.Now.Date.AddHours(3));
return (_IndicatorTime.Add(_IndicatorTimeOffset));
}
}
#endregion
#region DesignMode
/// <summary>
/// Gets or sets whether we are in design mode
/// </summary>
internal bool IsDesignMode
{
get { return (_IsDesignMode); }
set { _IsDesignMode = value; }
}
#endregion
#region IsProtected
/// <summary>
/// Gets or sets whether the timer indicator
/// is protected (can't be deleted)
/// </summary>
internal bool IsProtected
{
get { return (_IsProtected); }
set { _IsProtected = value; }
}
#endregion
#endregion
#region Public properties
#region BorderColor
/// <summary>
/// Gets or sets the leading edge border color
/// </summary>
[Browsable(true), DefaultValue(typeof(Color), "Empty")]
[Description("Indicates the leading edge border color.")]
public Color BorderColor
{
get { return (_BorderColor); }
set
{
if (_BorderColor.Equals(value) == false)
{
_BorderColor = value;
OnTimeIndicatorChanged();
}
}
}
#endregion
#region Enabled
/// <summary>
/// Gets or sets whether automatic time updates are enabled.
/// This property, whose default is true, is only utilized when
/// the IndicatorSource is set to eTimeIndicatorSource.SystemTime
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool Enabled
{
get { return (_Enabled); }
set
{
if (_Enabled != value)
{
_Enabled = value;
if (_Enabled == true &&
_IndicatorSource == eTimeIndicatorSource.SystemTime)
{
IndicatorTime = DateTime.Now;
}
}
}
}
#endregion
#region IndicatorArea
/// <summary>
/// Gets or sets the Indicator Display Area.
///
/// This property determines where the Indicator is
/// drawn: in the Time Header, View Content, or both.
/// </summary>
[Browsable(true), DefaultValue(eTimeIndicatorArea.Header)]
[Description("Indicates the Indicator display area.")]
public eTimeIndicatorArea IndicatorArea
{
get { return (_IndicatorArea); }
set
{
if (_IndicatorArea != value)
{
_IndicatorArea = value;
OnTimeIndicatorChanged();
}
}
}
#endregion
#region IndicatorColor
/// <summary>
/// Gets or sets the Indicator color
/// </summary>
[Browsable(true)]
[Description("Indicates the Indicator color.")]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content)]
public ColorDef IndicatorColor
{
get { return (_IndicatorColor); }
set
{
if (_IndicatorColor != null)
_IndicatorColor.ColorDefChanged -= IndicatorColor_ColorDefChanged;
_IndicatorColor = value;
if (_IndicatorColor != null)
_IndicatorColor.ColorDefChanged += IndicatorColor_ColorDefChanged;
OnTimeIndicatorColorChanged();
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public void ResetIndicatorColor()
{
IndicatorColor = new ColorDef();
}
#endregion
#region IndicatorLevel
/// <summary>
/// Gets or sets the IndicatorTime display level
/// </summary>
[Browsable(true), DefaultValue(eTimeIndicatorLevel.Bottom)]
[Description("Indicates the Indicator display level.")]
public eTimeIndicatorLevel IndicatorLevel
{
get { return (_IndicatorLevel); }
set
{
if (_IndicatorLevel != value)
{
_IndicatorLevel = value;
OnTimeIndicatorChanged();
}
}
}
#endregion
#region IndicatorTime
/// <summary>
/// Gets or sets the Indicator time
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public DateTime IndicatorTime
{
get { return (_IndicatorTime); }
set
{
if (_IndicatorTime.Equals(value) == false)
{
DateTime oldValue = IndicatorDisplayTime;
_IndicatorTime = value;
OnTimeIndicatorTimeChanged(oldValue, _IndicatorTime.Add(_IndicatorTimeOffset));
}
}
}
#endregion
#region IndicatorTimeOffset
/// <summary>
/// Gets or sets the Indicator time offset.
///
/// This value is added to the current IndicatorTime
/// before displaying the indicator.
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public TimeSpan IndicatorTimeOffset
{
get { return (_IndicatorTimeOffset); }
set
{
if (_IndicatorTimeOffset.Equals(value) == false)
{
_IndicatorTimeOffset = value;
OnTimeIndicatorChanged();
}
}
}
#endregion
#region Visibility
/// <summary>
/// Gets or sets the Indicator visibility
/// </summary>
[Browsable(true)]
[DefaultValue(eTimeIndicatorVisibility.Hidden)]
[Description("Indicates the Indicator visibility.")]
public eTimeIndicatorVisibility Visibility
{
get { return (_Visibility); }
set
{
if (_Visibility != value)
{
_Visibility = value;
OnTimeIndicatorChanged();
}
}
}
#endregion
#region Tag
/// <summary>
/// Gets or sets the User defined data associated with the object
/// </summary>
[Browsable(false)]
public object Tag
{
get { return (_Tag); }
set { _Tag = value; }
}
#endregion
#region Thickness
/// <summary>
/// Gets or sets the thickness of the Indicator
/// </summary>
[Browsable(true), DefaultValue(4)]
[Description("Indicates the thickness of the Indicator.")]
public int Thickness
{
get { return (_Thickness); }
set
{
if (_Thickness != value)
{
_Thickness = value;
OnTimeIndicatorChanged();
}
}
}
#endregion
#region IndicatorSource
/// <summary>
/// Gets or sets the IndicatorTime source
/// </summary>
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public eTimeIndicatorSource IndicatorSource
{
get { return (_IndicatorSource); }
set
{
if (_IndicatorSource != value)
{
_IndicatorSource = value;
OnTimeIndicatorChanged();
}
}
}
#endregion
#endregion
#region IsVisible
/// <summary>
/// Gets whether the indicator is visible
/// </summary>
/// <returns></returns>
internal bool IsVisible()
{
return (_Visibility != eTimeIndicatorVisibility.Hidden);
}
/// <summary>
/// Gets whether the indicator is visible
/// in the given view
/// </summary>
/// <param name="calendarView"></param>
/// <param name="view"></param>
/// <returns></returns>
internal bool IsVisible(CalendarView calendarView, BaseView view)
{
if (_Visibility == eTimeIndicatorVisibility.Hidden)
return (false);
if (_Visibility == eTimeIndicatorVisibility.AllResources)
return (true);
return ((calendarView == null || view.DisplayedOwnerKeyIndex == -1 ||
calendarView.SelectedOwnerIndex == view.DisplayedOwnerKeyIndex));
}
#endregion
#region IndicatorColor_ColorDefChanged
/// <summary>
/// Handles ColorDefChanged events
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void IndicatorColor_ColorDefChanged(object sender, EventArgs e)
{
OnTimeIndicatorChanged();
}
#endregion
#region OnTimeIndicatorChanged
/// <summary>
/// Handles TimeIndicatorChanged propagation
/// </summary>
private void OnTimeIndicatorChanged()
{
if (TimeIndicatorChanged != null)
TimeIndicatorChanged(this, EventArgs.Empty);
}
#endregion
#region OnTimeIndicatorColorChanged
/// <summary>
/// Handles OnTimeIndicatorColorChanged propagation
/// </summary>
private void OnTimeIndicatorColorChanged()
{
if (TimeIndicatorColorChanged != null)
TimeIndicatorColorChanged(this, new TimeIndicatorColorChangedEventArgs(this));
}
#endregion
#region OnTimeIndicatorTimeChanged
/// <summary>
/// Handles TimeIndicatorTimeChanged propagation
/// </summary>
/// <param name="oldValue"></param>
/// <param name="newValue"></param>
private void OnTimeIndicatorTimeChanged(DateTime oldValue, DateTime newValue)
{
if (TimeIndicatorTimeChanged != null)
TimeIndicatorTimeChanged(this, new TimeIndicatorTimeChangedEventArgs(this, oldValue, newValue));
}
#endregion
#region Begin/EndUpdate
/// <summary>
/// Begins Update block
/// </summary>
public void BeginUpdate()
{
_UpdateCount++;
}
/// <summary>
/// Ends update block
/// </summary>
public void EndUpdate()
{
if (_UpdateCount == 0)
{
throw new InvalidOperationException(
"EndUpdate must be called After BeginUpdate");
}
_UpdateCount--;
if (_UpdateCount == 0)
OnTimeIndicatorChanged();
}
#endregion
#region IDisposable
public void Dispose()
{
if (_IndicatorColor != null)
_IndicatorColor.ColorDefChanged -= IndicatorColor_ColorDefChanged;
}
#endregion
}
#region TimeIndicatorConvertor
/// <summary>
/// TimeIndicatorConvertor
/// </summary>
public class TimeIndicatorConvertor : ExpandableObjectConverter
{
public override object ConvertTo(
ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
return (String.Empty);
}
}
#endregion
#region enums
#region eTimeIndicatorSource
/// <summary>
/// Specifies the source for the IndicatorTime
/// </summary>
public enum eTimeIndicatorSource
{
SystemTime,
UserSpecified
}
#endregion
#region eTimeIndicatorVisibility
/// <summary>
/// Specifies the Indicator visibility
/// </summary>
public enum eTimeIndicatorVisibility
{
AllResources,
SelectedResource,
Hidden
}
#endregion
#region eTimeIndicatorArea
/// <summary>
/// Specifies the Indicator display area
/// </summary>
public enum eTimeIndicatorArea
{
Header,
Content,
All
}
#endregion
#region eTimeIndicatorLevel
/// <summary>
/// Specifies the Indicator display level
/// </summary>
public enum eTimeIndicatorLevel
{
Bottom,
Top
}
#endregion
#endregion
}
#endif

View File

@@ -0,0 +1,498 @@
#if FRAMEWORK20
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Forms;
namespace DevComponents.DotNetBar.Schedule
{
public class TimeIndicatorCollection : Collection<TimeIndicator>, IDisposable
{
#region Events
/// <summary>
/// Occurs when the TimeIndicator collection has changed
/// </summary>
[Description("Occurs when the TimeIndicator collection has changed.")]
public event EventHandler<EventArgs> TimeIndicatorCollectionChanged;
/// <summary>
/// Occurs when a TimeIndicator time has changed
/// </summary>
[Description("Occurs when a TimeIndicator time has changed.")]
public event EventHandler<TimeIndicatorTimeChangedEventArgs> TimeIndicatorTimeChanged;
/// <summary>
/// Occurs when a TimeIndicator Color has changed
/// </summary>
[Description("Occurs when a TimeIndicator Color has changed.")]
public event EventHandler<TimeIndicatorColorChangedEventArgs> TimeIndicatorColorChanged;
#endregion
#region Private variables
private int _UpdateCount;
private Timer _Timer;
#endregion
#region AddRange
/// <summary>
/// Adds a range of TimeIndicators to the collection
/// </summary>
/// <param name="items">Array of items to add</param>
public void AddRange(TimeIndicator[] items)
{
try
{
BeginUpdate();
for (int i = 0; i < items.Length; i++)
Add(items[i]);
}
finally
{
EndUpdate();
}
}
#endregion
#region RemoveItem
/// <summary>
/// Processes list RemoveItem calls
/// </summary>
/// <param name="index">Index to remove</param>
protected override void RemoveItem(int index)
{
if (Items[index].IsProtected == false)
{
Items[index].TimeIndicatorChanged -= IndicatorCollectionChanged;
Items[index].TimeIndicatorTimeChanged -= IndicatorTimeChanged;
Items[index].TimeIndicatorColorChanged -= IndicatorColorChanged;
base.RemoveItem(index);
OnCollectionChanged();
}
}
#endregion
#region InsertItem
/// <summary>
/// Processes list InsertItem calls
/// </summary>
/// <param name="index">Index to add</param>
/// <param name="item">TimeIndicator to add</param>
protected override void InsertItem(int index, TimeIndicator item)
{
if (item != null)
{
item.TimeIndicatorChanged += IndicatorCollectionChanged;
item.TimeIndicatorTimeChanged += IndicatorTimeChanged;
item.TimeIndicatorColorChanged += IndicatorColorChanged;
base.InsertItem(index, item);
OnCollectionChanged();
}
}
#endregion
#region SetItem
/// <summary>
/// Processes list SetItem calls (e.g. replace)
/// </summary>
/// <param name="index">Index to replace</param>
/// <param name="newItem">TimeIndicator to replace</param>
protected override void SetItem(int index, TimeIndicator newItem)
{
if (Items[index].IsProtected == false)
{
if (newItem != null)
{
Items[index].TimeIndicatorChanged -= IndicatorCollectionChanged;
Items[index].TimeIndicatorTimeChanged -= IndicatorTimeChanged;
Items[index].TimeIndicatorColorChanged -= IndicatorColorChanged;
newItem.TimeIndicatorChanged += IndicatorCollectionChanged;
newItem.TimeIndicatorTimeChanged += IndicatorTimeChanged;
newItem.TimeIndicatorColorChanged += IndicatorColorChanged;
base.SetItem(index, newItem);
OnCollectionChanged();
}
}
}
#endregion
#region ClearItems
/// <summary>
/// Processes list Clear calls (e.g. remove all)
/// </summary>
protected override void ClearItems()
{
try
{
BeginUpdate();
for (int i = Count - 1; i>=0 ; i--)
{
if (Items[i].IsProtected == false)
{
Items[i].TimeIndicatorChanged -= IndicatorCollectionChanged;
Items[i].TimeIndicatorTimeChanged -= IndicatorTimeChanged;
Items[i].TimeIndicatorColorChanged -= IndicatorColorChanged;
RemoveAt(i);
}
}
}
finally
{
EndUpdate();
}
}
#endregion
#region Events
#region IndicatorCollectionChanged
/// <summary>
/// IndicatorCollectionChanged
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void IndicatorCollectionChanged(object sender, EventArgs e)
{
OnCollectionChanged();
}
#endregion
#region IndicatorColorChanged
/// <summary>
/// IndicatorColorChanged
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void IndicatorColorChanged(object sender, TimeIndicatorColorChangedEventArgs e)
{
OnTimeIndicatorColorChanged(e);
}
#endregion
#region IndicatorTimeChanged
/// <summary>
/// IndicatorTimeChanged
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void IndicatorTimeChanged(object sender, TimeIndicatorTimeChangedEventArgs e)
{
OnTimeIndicatorTimeChanged(e);
}
#endregion
#endregion
#region OnCollectionChanged
/// <summary>
/// Propagates TimeIndicatorCollectionChanged events
/// </summary>
protected virtual void OnCollectionChanged()
{
if (_UpdateCount == 0)
{
UpdateTimerUse();
if (TimeIndicatorCollectionChanged != null)
TimeIndicatorCollectionChanged(this, EventArgs.Empty);
}
}
#endregion
#region OnTimeIndicatorColorChanged
/// <summary>
/// Propagates OnTimeIndicatorColorChanged events
/// </summary>
/// <param name="e"></param>
protected virtual void OnTimeIndicatorColorChanged(TimeIndicatorColorChangedEventArgs e)
{
if (_UpdateCount == 0)
{
if (TimeIndicatorColorChanged != null)
TimeIndicatorColorChanged(this, e);
}
}
#endregion
#region OnTimeIndicatorTimeChanged
/// <summary>
/// Propagates OnTimeIndicatorTimeChanged events
/// </summary>
/// <param name="e"></param>
protected virtual void OnTimeIndicatorTimeChanged(TimeIndicatorTimeChangedEventArgs e)
{
if (_UpdateCount == 0)
{
if (TimeIndicatorTimeChanged != null)
TimeIndicatorTimeChanged(this, e);
}
}
#endregion
#region System Timer support
#region UpdateTimerUse
/// <summary>
/// Updates our system timer use
/// </summary>
private void UpdateTimerUse()
{
// If we need a timer, then allocate it
// and initialize it to fire approx every minute
if (TimerNeeded() == true)
{
if (_Timer == null)
{
_Timer = new Timer();
_Timer.Tick += Timer_Tick;
DateTime now = DateTime.Now;
_Timer.Interval = (60 - now.Second) * 1000 + (1050 - now.Millisecond);
_Timer.Enabled = true;
}
}
else
{
if (_Timer != null)
{
_Timer.Enabled = false;
_Timer.Tick -= Timer_Tick;
_Timer.Dispose();
_Timer = null;
}
}
}
#endregion
#region TimerNeeded
/// <summary>
/// Determines if a system timer is needed
/// </summary>
/// <returns>true if needed</returns>
private bool TimerNeeded()
{
for (int i = 0; i < Items.Count; i++)
{
TimeIndicator ti = Items[i];
if (ti.IsDesignMode == true)
return (false);
if (ti.Enabled == true &&
ti.IndicatorSource == eTimeIndicatorSource.SystemTime)
{
return (true);
}
}
return (false);
}
#endregion
#region Timer_Tick
/// <summary>
/// Handles our timer tick events
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void Timer_Tick(object sender, EventArgs e)
{
DateTime now = DateTime.Now;
_Timer.Interval = (60 - now.Second) * 1000 + (1050 - now.Millisecond);
for (int i = 0; i < Items.Count; i++)
{
TimeIndicator ti = Items[i];
if (ti.Enabled == true &&
ti.IndicatorSource == eTimeIndicatorSource.SystemTime)
{
ti.IndicatorTime = now;
}
}
}
#endregion
#endregion
#region Begin/EndUpdate
/// <summary>
/// Begins Update block
/// </summary>
public void BeginUpdate()
{
_UpdateCount++;
}
/// <summary>
/// Ends update block
/// </summary>
public void EndUpdate()
{
if (_UpdateCount == 0)
{
throw new InvalidOperationException(
"EndUpdate must be called After BeginUpdate");
}
_UpdateCount--;
if (_UpdateCount == 0)
OnCollectionChanged();
}
#endregion
#region IDisposable
public void Dispose()
{
for (int i = Count - 1; i >= 0; i--)
{
Items[i].TimeIndicatorChanged -= IndicatorCollectionChanged;
Items[i].TimeIndicatorTimeChanged -= IndicatorTimeChanged;
Items[i].TimeIndicatorColorChanged -= IndicatorColorChanged;
}
}
#endregion
}
#region TimeIndicatorTimeChangedEventArgs
/// <summary>
/// TimeIndicatorTimeChangedEventArgs
/// </summary>
public class TimeIndicatorTimeChangedEventArgs : EventArgs
{
#region Private variables
private TimeIndicator _TimeIndicator;
private DateTime _OldTime;
private DateTime _NewTime;
#endregion
public TimeIndicatorTimeChangedEventArgs(
TimeIndicator timeIndicator, DateTime oldTime, DateTime newTime)
{
_TimeIndicator = timeIndicator;
_OldTime = oldTime;
_NewTime = newTime;
}
#region Public properties
/// <summary>
/// Gets the TimeIndicator being affected
/// </summary>
public TimeIndicator TimeIndicator
{
get { return (_TimeIndicator); }
}
/// <summary>
/// Gets the old DateTime
/// </summary>
public DateTime OldTime
{
get { return (_OldTime); }
}
/// <summary>
/// Gets the new DateTime
/// </summary>
public DateTime NewTime
{
get { return (_NewTime); }
}
#endregion
}
#endregion
#region TimeIndicatorColorChangedEventArgs
/// <summary>
/// TimeIndicatorColorChangedEventArgs
/// </summary>
public class TimeIndicatorColorChangedEventArgs : EventArgs
{
#region Private variables
private TimeIndicator _TimeIndicator;
#endregion
public TimeIndicatorColorChangedEventArgs(TimeIndicator timeIndicator)
{
_TimeIndicator = timeIndicator;
}
#region Public properties
/// <summary>
/// Gets the TimeIndicator being affected
/// </summary>
public TimeIndicator TimeIndicator
{
get { return (_TimeIndicator); }
}
#endregion
}
#endregion
}
#endif