Skip to content

Commit bc0bd11

Browse files
author
Pavel Kovalenko
committed
Add IntegerUpDown control.
1 parent 88d7797 commit bc0bd11

File tree

9 files changed

+995
-5
lines changed

9 files changed

+995
-5
lines changed

src/editors/xrSdkControls/Controls/IntegerUpDown/IntegerUpDown.cs

Lines changed: 733 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using System;
2+
using System.Windows.Forms;
3+
4+
namespace XRay.SdkControls
5+
{
6+
/// <summary>
7+
/// Comprises the information specifying how acceleration should be performed
8+
/// on a Windows up-down control when the up/down button is pressed for certain
9+
/// amount of time.
10+
/// </summary>
11+
public class IntegerUpDownAcceleration
12+
{
13+
private Int32 seconds; // Ideally we would use UInt32 but it is not CLS-compliant.
14+
private Int32 increment; // Ideally we would use UInt32 but it is not CLS-compliant.
15+
16+
public IntegerUpDownAcceleration(Int32 seconds, Int32 increment)
17+
{
18+
if (seconds < 0)
19+
{
20+
throw new ArgumentOutOfRangeException("seconds < 0");
21+
}
22+
23+
if (increment < 0)
24+
{
25+
throw new ArgumentOutOfRangeException("increment < 0");
26+
}
27+
28+
this.seconds = seconds;
29+
this.increment = increment;
30+
}
31+
32+
/// <summary>
33+
/// Determines the amount of time for the UpDown control to wait to set the increment
34+
/// step when holding the up/down button.
35+
/// </summary>
36+
public Int32 Seconds
37+
{
38+
get
39+
{
40+
return seconds;
41+
}
42+
set
43+
{
44+
if (value < 0)
45+
{
46+
throw new ArgumentOutOfRangeException("seconds < 0");
47+
}
48+
seconds = value;
49+
}
50+
}
51+
52+
/// <summary>
53+
/// Determines the amount to increment by.
54+
/// </summary>
55+
public Int32 Increment
56+
{
57+
get
58+
{
59+
return increment;
60+
}
61+
set
62+
{
63+
if (value < 0)
64+
{
65+
throw new ArgumentOutOfRangeException("increment < 0");
66+
}
67+
increment = value;
68+
}
69+
}
70+
}
71+
}
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.Collections;
4+
using System.Collections.Generic;
5+
using System.ComponentModel;
6+
using System.Windows.Forms;
7+
8+
namespace XRay.SdkControls
9+
{
10+
/// <summary>
11+
/// Represents a SORTED collection of IntegerUpDownAcceleration objects in the NumericUpDown Control.
12+
/// The elements in the collection are sorted by the IntegerUpDownAcceleration.Seconds property.
13+
/// </summary>
14+
[ListBindable(false)]
15+
public class IntegerUpDownAccelerationCollection :
16+
MarshalByRefObject,
17+
ICollection<IntegerUpDownAcceleration>,
18+
IEnumerable<IntegerUpDownAcceleration>
19+
{
20+
private List<IntegerUpDownAcceleration> items;
21+
22+
/// <summary>
23+
/// Class constructor.
24+
/// </summary>
25+
public IntegerUpDownAccelerationCollection()
26+
{
27+
items = new List<IntegerUpDownAcceleration>();
28+
}
29+
30+
/// <summary>
31+
/// Gets (ReadOnly) the element at the specified index. In C#, this property is the indexer for
32+
/// the IList class.
33+
/// </summary>
34+
/// <param name="index"></param>
35+
/// <returns></returns>
36+
public IntegerUpDownAcceleration this[int index]
37+
{
38+
get
39+
{
40+
return items[index];
41+
}
42+
}
43+
44+
// ICollection<IntegerUpDownAcceleration> implementation.
45+
46+
/// <summary>
47+
/// Adds an item (IntegerUpDownAcceleration object) to the ICollection.
48+
/// The item is added preserving the collection sorted.
49+
/// </summary>
50+
/// <param name="acceleration"></param>
51+
public void Add(IntegerUpDownAcceleration acceleration)
52+
{
53+
if (acceleration == null)
54+
{
55+
throw new ArgumentNullException("acceleration");
56+
}
57+
58+
// Keep the array sorted, insert in the right spot.
59+
var index = 0;
60+
61+
while (index < items.Count)
62+
{
63+
if (acceleration.Seconds < items[index].Seconds)
64+
{
65+
break;
66+
}
67+
++index;
68+
}
69+
items.Insert(index, acceleration);
70+
}
71+
72+
/// <summary>
73+
/// Removes all items from the ICollection.
74+
/// </summary>
75+
public void Clear()
76+
{
77+
items.Clear();
78+
}
79+
80+
/// <summary>
81+
/// Determines whether the IList contains a specific value.
82+
/// </summary>
83+
/// <param name="acceleration"></param>
84+
/// <returns></returns>
85+
public bool Contains(IntegerUpDownAcceleration acceleration)
86+
{
87+
return items.Contains(acceleration);
88+
}
89+
90+
/// <summary>
91+
/// Copies the elements of the ICollection to an Array, starting at a particular Array index.
92+
/// </summary>
93+
/// <param name="array"></param>
94+
/// <param name="index"></param>
95+
public void CopyTo(IntegerUpDownAcceleration[] array, int index)
96+
{
97+
items.CopyTo(array, index);
98+
}
99+
100+
/// <summary>
101+
/// Gets the number of elements contained in the ICollection.
102+
/// </summary>
103+
public int Count
104+
{
105+
get
106+
{
107+
return items.Count;
108+
}
109+
}
110+
111+
/// <summary>
112+
/// Gets a value indicating whether the ICollection is read-only.
113+
/// This collection property returns false always.
114+
/// </summary>
115+
public bool IsReadOnly
116+
{
117+
get
118+
{
119+
return false;
120+
}
121+
}
122+
123+
/// <summary>
124+
/// Removes the specified item from the ICollection.
125+
/// </summary>
126+
/// <param name="acceleration"></param>
127+
/// <returns></returns>
128+
public bool Remove(IntegerUpDownAcceleration acceleration)
129+
{
130+
return items.Remove(acceleration);
131+
}
132+
133+
// IEnumerable<IntegerUpDownAcceleration> implementation.
134+
135+
136+
/// <summary>
137+
/// Returns an enumerator that can iterate through the collection.
138+
/// </summary>
139+
/// <returns></returns>
140+
IEnumerator<IntegerUpDownAcceleration> IEnumerable<IntegerUpDownAcceleration>.GetEnumerator()
141+
{
142+
return items.GetEnumerator();
143+
}
144+
145+
IEnumerator IEnumerable.GetEnumerator()
146+
{
147+
return ((IEnumerable)items).GetEnumerator();
148+
}
149+
150+
// IntegerUpDownAccelerationCollection methods.
151+
152+
/// <summary>
153+
/// Adds the elements of specified array to the collection, keeping the collection sorted.
154+
/// </summary>
155+
/// <param name="accelerations"></param>
156+
public void AddRange(params IntegerUpDownAcceleration[] accelerations)
157+
{
158+
if (accelerations == null)
159+
{
160+
throw new ArgumentNullException("accelerations");
161+
}
162+
163+
// Accept the range only if ALL elements in the array are not null.
164+
foreach (var acceleration in accelerations)
165+
{
166+
if (acceleration == null)
167+
{
168+
throw new ArgumentNullException("At least oe entry is null");
169+
}
170+
}
171+
172+
// The expected array size is typically small (5 items?), so we don't need to try to be smarter about the
173+
// way we add the elements to the collection, just call Add.
174+
foreach (var acceleration in accelerations)
175+
{
176+
Add(acceleration);
177+
}
178+
}
179+
}
180+
}

src/editors/xrSdkControls/xrSdkControls.csproj

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,21 @@
4949
<Reference Include="System.Xml" />
5050
</ItemGroup>
5151
<ItemGroup>
52-
<Compile Include="PropertyGrid.cs">
52+
<Compile Include="Controls\IntegerUpDown\IntegerUpDown.cs">
53+
<SubType>Component</SubType>
54+
</Compile>
55+
<Compile Include="Controls\IntegerUpDown\IntegerUpDownAcceleration.cs" />
56+
<Compile Include="Controls\IntegerUpDown\IntegerUpDownAccelerationCollection.cs" />
57+
<Compile Include="Controls\PropertyGrid.cs">
5358
<SubType>Component</SubType>
5459
</Compile>
5560
<Compile Include="Properties\AssemblyInfo.cs" />
56-
<Compile Include="IPropertyContainer.cs" />
57-
<Compile Include="IIncrementable.cs" />
58-
<Compile Include="IMouseListener.cs" />
59-
<Compile Include="IProperty.cs" />
61+
<Compile Include="Controls\Interfaces\IPropertyContainer.cs" />
62+
<Compile Include="Controls\Interfaces\IIncrementable.cs" />
63+
<Compile Include="Controls\Interfaces\IMouseListener.cs" />
64+
<Compile Include="Controls\Interfaces\IProperty.cs" />
6065
</ItemGroup>
66+
<ItemGroup />
6167
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
6268
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
6369
Other similar extension points exist, see Microsoft.Common.targets.

0 commit comments

Comments
 (0)