Some CA changes.

This commit is contained in:
soukoku
2015-02-18 21:52:17 -05:00
parent 77b3fdfee0
commit 6f49adb06d
13 changed files with 127 additions and 125 deletions

View File

@@ -192,7 +192,7 @@ namespace NTwain
public bool IsSupported { get { return SupportedActions > QuerySupports.None; } } public bool IsSupported { get { return SupportedActions > QuerySupports.None; } }
/// <summary> /// <summary>
/// Gets a value indicating whether <see cref="Get"/> is supported. /// Gets a value indicating whether <see cref="GetValues"/> is supported.
/// </summary> /// </summary>
/// <value> /// <value>
/// <c>true</c> if this capability can get values; otherwise, <c>false</c>. /// <c>true</c> if this capability can get values; otherwise, <c>false</c>.
@@ -248,7 +248,7 @@ namespace NTwain
public bool CanReset { get { return Supports(QuerySupports.Reset); } } public bool CanReset { get { return Supports(QuerySupports.Reset); } }
/// <summary> /// <summary>
/// Gets a value indicating whether <see cref="Set"/> is supported. /// Gets a value indicating whether <see cref="SetValue"/> is supported.
/// </summary> /// </summary>
/// <value> /// <value>
/// <c>true</c> if this capability can set; otherwise, <c>false</c>. /// <c>true</c> if this capability can set; otherwise, <c>false</c>.
@@ -297,7 +297,7 @@ namespace NTwain
/// Gets all the possible values of this capability. /// Gets all the possible values of this capability.
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public IList<TValue> Get() public IList<TValue> GetValues()
{ {
return _source.CapGet(Capability).Select(o => _getConvertRoutine(o)).ToList(); return _source.CapGet(Capability).Select(o => _getConvertRoutine(o)).ToList();
} }
@@ -393,7 +393,7 @@ namespace NTwain
/// <param name="value">The value.</param> /// <param name="value">The value.</param>
/// <returns></returns> /// <returns></returns>
/// <exception cref="System.InvalidOperationException">Simple Set() is not defined for this capability.</exception> /// <exception cref="System.InvalidOperationException">Simple Set() is not defined for this capability.</exception>
public ReturnCode Set(TValue value) public ReturnCode SetValue(TValue value)
{ {
ReturnCode rc = ReturnCode.Failure; ReturnCode rc = ReturnCode.Failure;
@@ -420,7 +420,7 @@ namespace NTwain
/// </summary> /// </summary>
/// <param name="value">The value.</param> /// <param name="value">The value.</param>
/// <returns></returns> /// <returns></returns>
public ReturnCode Set(TWArray value) public ReturnCode SetValue(TWArray value)
{ {
ReturnCode rc = ReturnCode.Failure; ReturnCode rc = ReturnCode.Failure;
using (var cap = new TWCapability(Capability, value)) using (var cap = new TWCapability(Capability, value))
@@ -435,7 +435,7 @@ namespace NTwain
/// </summary> /// </summary>
/// <param name="value">The value.</param> /// <param name="value">The value.</param>
/// <returns></returns> /// <returns></returns>
public ReturnCode Set(TWEnumeration value) public ReturnCode SetValue(TWEnumeration value)
{ {
ReturnCode rc = ReturnCode.Failure; ReturnCode rc = ReturnCode.Failure;
using (var cap = new TWCapability(Capability, value)) using (var cap = new TWCapability(Capability, value))

View File

@@ -207,109 +207,107 @@ namespace NTwain
} }
break; break;
case ContainerType.Range: case ContainerType.Range:
// horrible cast but should work. PopulateRange(toPopulate);
// in the for loop we also compare against min in case the step
// is parsed as negative number and causes infinite loop.
switch (ItemType)
{
case Data.ItemType.Fix32:
{
var min = (TWFix32)RangeMinValue;
var counter = min;
var max = (TWFix32)RangeMaxValue;
var step = (TWFix32)RangeStepSize;
for (var i = min; i >= min && i <= max; i += step)
{
toPopulate.Add(i);
}
}
break;
case Data.ItemType.UInt32:
{
var min = (uint)RangeMinValue;
var counter = min;
var max = (uint)RangeMaxValue;
var step = (uint)RangeStepSize;
for (var i = min; i >= min && i <= max; i += step)
{
toPopulate.Add(i);
}
}
break;
case Data.ItemType.Int32:
{
var min = (int)RangeMinValue;
var counter = min;
var max = (int)RangeMaxValue;
var step = (int)RangeStepSize;
for (var i = min; i >= min && i <= max; i += step)
{
toPopulate.Add(i);
}
}
break;
// these should never happen since TW_ENUM fields are 4 bytes but you never know
case Data.ItemType.UInt16:
{
var min = (ushort)RangeMinValue;
var counter = min;
var max = (ushort)RangeMaxValue;
var step = (ushort)RangeStepSize;
for (var i = min; i >= min && i <= max; i += step)
{
toPopulate.Add(i);
}
}
break;
case Data.ItemType.Int16:
{
var min = (short)RangeMinValue;
var counter = min;
var max = (short)RangeMaxValue;
var step = (short)RangeStepSize;
for (var i = min; i >= min && i <= max; i += step)
{
toPopulate.Add(i);
}
}
break;
case Data.ItemType.UInt8:
{
var min = (byte)RangeMinValue;
var counter = min;
var max = (byte)RangeMaxValue;
var step = (byte)RangeStepSize;
for (var i = min; i >= min && i <= max; i += step)
{
toPopulate.Add(i);
}
}
break;
case Data.ItemType.Int8:
{
var min = (sbyte)RangeMinValue;
var counter = min;
var max = (sbyte)RangeMaxValue;
var step = (sbyte)RangeStepSize;
for (var i = min; i >= min && i <= max; i += step)
{
toPopulate.Add(i);
}
}
break;
}
break; break;
} }
return toPopulate; return toPopulate;
} }
private void PopulateRange(IList<object> toPopulate)
{
// horrible cast but should work.
// in the for loop we also compare against min in case the step
// is parsed as negative number and causes infinite loop.
switch (ItemType)
{
case Data.ItemType.Fix32:
{
var min = (TWFix32)RangeMinValue;
var max = (TWFix32)RangeMaxValue;
var step = (TWFix32)RangeStepSize;
for (var i = min; i >= min && i <= max; i += step)
{
toPopulate.Add(i);
}
}
break;
case Data.ItemType.UInt32:
{
var min = (uint)RangeMinValue;
var max = (uint)RangeMaxValue;
var step = (uint)RangeStepSize;
for (var i = min; i >= min && i <= max; i += step)
{
toPopulate.Add(i);
}
}
break;
case Data.ItemType.Int32:
{
var min = (int)RangeMinValue;
var max = (int)RangeMaxValue;
var step = (int)RangeStepSize;
for (var i = min; i >= min && i <= max; i += step)
{
toPopulate.Add(i);
}
}
break;
// these should never happen since TW_ENUM fields are 4 bytes but you never know
case Data.ItemType.UInt16:
{
var min = (ushort)RangeMinValue;
var max = (ushort)RangeMaxValue;
var step = (ushort)RangeStepSize;
for (var i = min; i >= min && i <= max; i += step)
{
toPopulate.Add(i);
}
}
break;
case Data.ItemType.Int16:
{
var min = (short)RangeMinValue;
var max = (short)RangeMaxValue;
var step = (short)RangeStepSize;
for (var i = min; i >= min && i <= max; i += step)
{
toPopulate.Add(i);
}
}
break;
case Data.ItemType.UInt8:
{
var min = (byte)RangeMinValue;
var max = (byte)RangeMaxValue;
var step = (byte)RangeStepSize;
for (var i = min; i >= min && i <= max; i += step)
{
toPopulate.Add(i);
}
}
break;
case Data.ItemType.Int8:
{
var min = (sbyte)RangeMinValue;
var max = (sbyte)RangeMaxValue;
var step = (sbyte)RangeStepSize;
for (var i = min; i >= min && i <= max; i += step)
{
toPopulate.Add(i);
}
}
break;
}
}
CapabilityReader ReadOneValue(IntPtr baseAddr) CapabilityReader ReadOneValue(IntPtr baseAddr)
{ {

View File

@@ -79,7 +79,7 @@ namespace NTwain.Data
// new method: // new method:
// try to convert to enum's underlying type first then cast to the enum // try to convert to enum's underlying type first then cast to the enum
return (TEnum)Convert.ChangeType(value, rawType); return (TEnum)Convert.ChangeType(value, rawType, CultureInfo.InvariantCulture);
} }
else if (typeof(IConvertible).IsAssignableFrom(returnType)) else if (typeof(IConvertible).IsAssignableFrom(returnType))
{ {

View File

@@ -1576,7 +1576,7 @@ namespace NTwain
}; };
// this needs to also set undefined size optino // this needs to also set undefined size optino
rc = ICapUndefinedImageSize.Set(value); rc = ICapUndefinedImageSize.SetValue(value);
using (TWCapability capValue = new TWCapability(CapabilityId.ICapAutomaticBorderDetection, one)) using (TWCapability capValue = new TWCapability(CapabilityId.ICapAutomaticBorderDetection, one))
{ {
rc = _session.DGControl.Capability.Set(capValue); rc = _session.DGControl.Capability.Set(capValue);
@@ -2002,11 +2002,11 @@ namespace NTwain
// for one of them since setting autoscan also sets autofeed // for one of them since setting autoscan also sets autofeed
if (CapAutoScan.CanSet) if (CapAutoScan.CanSet)
{ {
rc = CapAutoScan.Set(value); rc = CapAutoScan.SetValue(value);
} }
else if (CapAutoFeed.CanSet) else if (CapAutoFeed.CanSet)
{ {
rc = CapAutoFeed.Set(value); rc = CapAutoFeed.SetValue(value);
} }
return rc; return rc;

View File

@@ -174,7 +174,7 @@ namespace NTwain
{ {
if (_supportedCapsList == null && _session.State > 3) if (_supportedCapsList == null && _session.State > 3)
{ {
_supportedCapsList = CapSupportedCaps.Get(); _supportedCapsList = CapSupportedCaps.GetValues();
} }
return _supportedCapsList ?? _emptyCapList; return _supportedCapsList ?? _emptyCapList;
} }

Binary file not shown.

View File

@@ -11,7 +11,7 @@ namespace NTwain
public interface IReadOnlyCapWrapper<TValue> public interface IReadOnlyCapWrapper<TValue>
{ {
/// <summary> /// <summary>
/// Gets a value indicating whether <see cref="Get"/> is supported. /// Gets a value indicating whether <see cref="GetValues"/> is supported.
/// </summary> /// </summary>
/// <value> /// <value>
/// <c>true</c> if this capability can get values; otherwise, <c>false</c>. /// <c>true</c> if this capability can get values; otherwise, <c>false</c>.
@@ -95,7 +95,7 @@ namespace NTwain
/// Gets all the possible values of this capability. /// Gets all the possible values of this capability.
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
IList<TValue> Get(); IList<TValue> GetValues();
/// <summary> /// <summary>
/// Gets the current value of this capability. /// Gets the current value of this capability.
@@ -153,20 +153,20 @@ namespace NTwain
/// </summary> /// </summary>
/// <param name="value">The value.</param> /// <param name="value">The value.</param>
/// <returns></returns> /// <returns></returns>
ReturnCode Set(TValue value);/// <summary> ReturnCode SetValue(TValue value);/// <summary>
/// ///
/// A version of Set that uses an array. /// A version of Set that uses an array.
/// </summary> /// </summary>
/// <param name="value">The value.</param> /// <param name="value">The value.</param>
/// <returns></returns> /// <returns></returns>
ReturnCode Set(TWArray value); ReturnCode SetValue(TWArray value);
/// <summary> /// <summary>
/// A version of Set that uses an enumeration. /// A version of Set that uses an enumeration.
/// </summary> /// </summary>
/// <param name="value">The value.</param> /// <param name="value">The value.</param>
/// <returns></returns> /// <returns></returns>
ReturnCode Set(TWEnumeration value); ReturnCode SetValue(TWEnumeration value);
/// <summary> /// <summary>
/// Sets the constraint value of this capability. /// Sets the constraint value of this capability.

View File

@@ -88,7 +88,6 @@ namespace NTwain
var headerSize = Marshal.SizeOf(typeof(TIFFHEADER)); var headerSize = Marshal.SizeOf(typeof(TIFFHEADER));
var tagSize = Marshal.SizeOf(typeof(TIFFTAG)); var tagSize = Marshal.SizeOf(typeof(TIFFTAG));
var tiffSize = 0; var tiffSize = 0;
var header = (TIFFHEADER)Marshal.PtrToStructure(data, typeof(TIFFHEADER));
var tagPtr = data.ToInt64() + headerSize; var tagPtr = data.ToInt64() + headerSize;
for (int i = 0; i < 999; i++) for (int i = 0; i < 999; i++)
{ {

View File

@@ -61,6 +61,7 @@
<Compile Include="Data\TypeExtensions.cs" /> <Compile Include="Data\TypeExtensions.cs" />
<Compile Include="Data\TwainTypesExtended.cs" /> <Compile Include="Data\TwainTypesExtended.cs" />
<Compile Include="DeviceEventArgs.cs" /> <Compile Include="DeviceEventArgs.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="IDataSource.cs" /> <Compile Include="IDataSource.cs" />
<Compile Include="ICapControl.cs" /> <Compile Include="ICapControl.cs" />
<Compile Include="Internals\Extensions.cs" /> <Compile Include="Internals\Extensions.cs" />

View File

@@ -10,6 +10,10 @@ namespace NTwain
/// </summary> /// </summary>
public enum State public enum State
{ {
/// <summary>
/// Just a default value.
/// </summary>
Invalid = 0,
/// <summary> /// <summary>
/// The starting state, corresponds to state 1. /// The starting state, corresponds to state 1.
/// </summary> /// </summary>

View File

@@ -49,7 +49,7 @@ namespace Tester.WPF
//rc = DGControl.Status.Get(dsId, ref stat); //rc = DGControl.Status.Get(dsId, ref stat);
if (rc == ReturnCode.Success) if (rc == ReturnCode.Success)
{ {
foreach (var c in DS.CapSupportedCaps.Get().Select(o => new CapVM(DS, o))) foreach (var c in DS.CapSupportedCaps.GetValues().Select(o => new CapVM(DS, o)))
{ {
Caps.Add(c); Caps.Add(c);
} }

View File

@@ -248,7 +248,7 @@ namespace Tester.WPF
{ {
if (_session.CurrentSource.ICapXferMech.GetCurrent() == XferMech.File) if (_session.CurrentSource.ICapXferMech.GetCurrent() == XferMech.File)
{ {
var formats = _session.CurrentSource.ICapImageFileFormat.Get(); var formats = _session.CurrentSource.ICapImageFileFormat.GetValues();
var wantFormat = formats.Contains(FileFormat.Tiff) ? FileFormat.Tiff : FileFormat.Bmp; var wantFormat = formats.Contains(FileFormat.Tiff) ? FileFormat.Tiff : FileFormat.Bmp;
var fileSetup = new TWSetupFileXfer var fileSetup = new TWSetupFileXfer

View File

@@ -322,7 +322,7 @@ namespace Tester.Winform
private void LoadPaperSize(ICapWrapper<SupportedSize> cap) private void LoadPaperSize(ICapWrapper<SupportedSize> cap)
{ {
var list = cap.Get(); var list = cap.GetValues();
comboSize.DataSource = list; comboSize.DataSource = list;
var cur = cap.GetCurrent(); var cur = cap.GetCurrent();
if (list.Contains(cur)) if (list.Contains(cur))
@@ -346,7 +346,7 @@ namespace Tester.Winform
private void LoadDPI(ICapWrapper<TWFix32> cap) private void LoadDPI(ICapWrapper<TWFix32> cap)
{ {
// only allow dpi of certain values for those source that lists everything // only allow dpi of certain values for those source that lists everything
var list = cap.Get().Where(dpi => (dpi % 50) == 0).ToList(); var list = cap.GetValues().Where(dpi => (dpi % 50) == 0).ToList();
comboDPI.DataSource = list; comboDPI.DataSource = list;
var cur = cap.GetCurrent(); var cur = cap.GetCurrent();
if (list.Contains(cur)) if (list.Contains(cur))
@@ -357,7 +357,7 @@ namespace Tester.Winform
private void LoadDepth(ICapWrapper<PixelType> cap) private void LoadDepth(ICapWrapper<PixelType> cap)
{ {
var list = cap.Get(); var list = cap.GetValues();
comboDepth.DataSource = list; comboDepth.DataSource = list;
var cur = cap.GetCurrent(); var cur = cap.GetCurrent();
if (list.Contains(cur)) if (list.Contains(cur))
@@ -376,7 +376,7 @@ namespace Tester.Winform
if (!_loadingCaps && _twain.State == 4) if (!_loadingCaps && _twain.State == 4)
{ {
var sel = (SupportedSize)comboSize.SelectedItem; var sel = (SupportedSize)comboSize.SelectedItem;
_twain.CurrentSource.ICapSupportedSizes.Set(sel); _twain.CurrentSource.ICapSupportedSizes.SetValue(sel);
} }
} }
@@ -385,7 +385,7 @@ namespace Tester.Winform
if (!_loadingCaps && _twain.State == 4) if (!_loadingCaps && _twain.State == 4)
{ {
var sel = (PixelType)comboDepth.SelectedItem; var sel = (PixelType)comboDepth.SelectedItem;
_twain.CurrentSource.ICapPixelType.Set(sel); _twain.CurrentSource.ICapPixelType.SetValue(sel);
} }
} }
@@ -394,8 +394,8 @@ namespace Tester.Winform
if (!_loadingCaps && _twain.State == 4) if (!_loadingCaps && _twain.State == 4)
{ {
var sel = (TWFix32)comboDPI.SelectedItem; var sel = (TWFix32)comboDPI.SelectedItem;
_twain.CurrentSource.ICapXResolution.Set(sel); _twain.CurrentSource.ICapXResolution.SetValue(sel);
_twain.CurrentSource.ICapYResolution.Set(sel); _twain.CurrentSource.ICapYResolution.SetValue(sel);
} }
} }
@@ -403,7 +403,7 @@ namespace Tester.Winform
{ {
if (!_loadingCaps && _twain.State == 4) if (!_loadingCaps && _twain.State == 4)
{ {
_twain.CurrentSource.CapDuplexEnabled.Set(ckDuplex.Checked ? BoolType.True : BoolType.False); _twain.CurrentSource.CapDuplexEnabled.SetValue(ckDuplex.Checked ? BoolType.True : BoolType.False);
} }
} }