Skip to content

Commit

Permalink
Add IntegerUpDown control.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Kovalenko committed Oct 18, 2014
1 parent 88d7797 commit bc0bd11
Show file tree
Hide file tree
Showing 9 changed files with 995 additions and 5 deletions.
733 changes: 733 additions & 0 deletions src/editors/xrSdkControls/Controls/IntegerUpDown/IntegerUpDown.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;
using System.Windows.Forms;

namespace XRay.SdkControls
{
/// <summary>
/// Comprises the information specifying how acceleration should be performed
/// on a Windows up-down control when the up/down button is pressed for certain
/// amount of time.
/// </summary>
public class IntegerUpDownAcceleration
{
private Int32 seconds; // Ideally we would use UInt32 but it is not CLS-compliant.
private Int32 increment; // Ideally we would use UInt32 but it is not CLS-compliant.

public IntegerUpDownAcceleration(Int32 seconds, Int32 increment)
{
if (seconds < 0)
{
throw new ArgumentOutOfRangeException("seconds < 0");
}

if (increment < 0)
{
throw new ArgumentOutOfRangeException("increment < 0");
}

this.seconds = seconds;
this.increment = increment;
}

/// <summary>
/// Determines the amount of time for the UpDown control to wait to set the increment
/// step when holding the up/down button.
/// </summary>
public Int32 Seconds
{
get
{
return seconds;
}
set
{
if (value < 0)
{
throw new ArgumentOutOfRangeException("seconds < 0");
}
seconds = value;
}
}

/// <summary>
/// Determines the amount to increment by.
/// </summary>
public Int32 Increment
{
get
{
return increment;
}
set
{
if (value < 0)
{
throw new ArgumentOutOfRangeException("increment < 0");
}
increment = value;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
using System;
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;

namespace XRay.SdkControls
{
/// <summary>
/// Represents a SORTED collection of IntegerUpDownAcceleration objects in the NumericUpDown Control.
/// The elements in the collection are sorted by the IntegerUpDownAcceleration.Seconds property.
/// </summary>
[ListBindable(false)]
public class IntegerUpDownAccelerationCollection :
MarshalByRefObject,
ICollection<IntegerUpDownAcceleration>,
IEnumerable<IntegerUpDownAcceleration>
{
private List<IntegerUpDownAcceleration> items;

/// <summary>
/// Class constructor.
/// </summary>
public IntegerUpDownAccelerationCollection()
{
items = new List<IntegerUpDownAcceleration>();
}

/// <summary>
/// Gets (ReadOnly) the element at the specified index. In C#, this property is the indexer for
/// the IList class.
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public IntegerUpDownAcceleration this[int index]
{
get
{
return items[index];
}
}

// ICollection<IntegerUpDownAcceleration> implementation.

/// <summary>
/// Adds an item (IntegerUpDownAcceleration object) to the ICollection.
/// The item is added preserving the collection sorted.
/// </summary>
/// <param name="acceleration"></param>
public void Add(IntegerUpDownAcceleration acceleration)
{
if (acceleration == null)
{
throw new ArgumentNullException("acceleration");
}

// Keep the array sorted, insert in the right spot.
var index = 0;

while (index < items.Count)
{
if (acceleration.Seconds < items[index].Seconds)
{
break;
}
++index;
}
items.Insert(index, acceleration);
}

/// <summary>
/// Removes all items from the ICollection.
/// </summary>
public void Clear()
{
items.Clear();
}

/// <summary>
/// Determines whether the IList contains a specific value.
/// </summary>
/// <param name="acceleration"></param>
/// <returns></returns>
public bool Contains(IntegerUpDownAcceleration acceleration)
{
return items.Contains(acceleration);
}

/// <summary>
/// Copies the elements of the ICollection to an Array, starting at a particular Array index.
/// </summary>
/// <param name="array"></param>
/// <param name="index"></param>
public void CopyTo(IntegerUpDownAcceleration[] array, int index)
{
items.CopyTo(array, index);
}

/// <summary>
/// Gets the number of elements contained in the ICollection.
/// </summary>
public int Count
{
get
{
return items.Count;
}
}

/// <summary>
/// Gets a value indicating whether the ICollection is read-only.
/// This collection property returns false always.
/// </summary>
public bool IsReadOnly
{
get
{
return false;
}
}

/// <summary>
/// Removes the specified item from the ICollection.
/// </summary>
/// <param name="acceleration"></param>
/// <returns></returns>
public bool Remove(IntegerUpDownAcceleration acceleration)
{
return items.Remove(acceleration);
}

// IEnumerable<IntegerUpDownAcceleration> implementation.


/// <summary>
/// Returns an enumerator that can iterate through the collection.
/// </summary>
/// <returns></returns>
IEnumerator<IntegerUpDownAcceleration> IEnumerable<IntegerUpDownAcceleration>.GetEnumerator()
{
return items.GetEnumerator();
}

IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable)items).GetEnumerator();
}

// IntegerUpDownAccelerationCollection methods.

/// <summary>
/// Adds the elements of specified array to the collection, keeping the collection sorted.
/// </summary>
/// <param name="accelerations"></param>
public void AddRange(params IntegerUpDownAcceleration[] accelerations)
{
if (accelerations == null)
{
throw new ArgumentNullException("accelerations");
}

// Accept the range only if ALL elements in the array are not null.
foreach (var acceleration in accelerations)
{
if (acceleration == null)
{
throw new ArgumentNullException("At least oe entry is null");
}
}

// The expected array size is typically small (5 items?), so we don't need to try to be smarter about the
// way we add the elements to the collection, just call Add.
foreach (var acceleration in accelerations)
{
Add(acceleration);
}
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 11 additions & 5 deletions src/editors/xrSdkControls/xrSdkControls.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,21 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="PropertyGrid.cs">
<Compile Include="Controls\IntegerUpDown\IntegerUpDown.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\IntegerUpDown\IntegerUpDownAcceleration.cs" />
<Compile Include="Controls\IntegerUpDown\IntegerUpDownAccelerationCollection.cs" />
<Compile Include="Controls\PropertyGrid.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="IPropertyContainer.cs" />
<Compile Include="IIncrementable.cs" />
<Compile Include="IMouseListener.cs" />
<Compile Include="IProperty.cs" />
<Compile Include="Controls\Interfaces\IPropertyContainer.cs" />
<Compile Include="Controls\Interfaces\IIncrementable.cs" />
<Compile Include="Controls\Interfaces\IMouseListener.cs" />
<Compile Include="Controls\Interfaces\IProperty.cs" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down

0 comments on commit bc0bd11

Please sign in to comment.