More ICaps

This commit is contained in:
soukoku
2014-11-09 13:23:06 -05:00
parent b4c3ebd549
commit 852a055e5a
9 changed files with 1033 additions and 189 deletions

View File

@@ -354,6 +354,7 @@ namespace NTwain
/// </summary>
/// <param name="value">The value.</param>
/// <returns></returns>
/// <exception cref="System.InvalidOperationException">Simple Set() is not defined for this capability.</exception>
public ReturnCode Set(TValue value)
{
ReturnCode rc = ReturnCode.Failure;
@@ -370,6 +371,28 @@ namespace NTwain
rc = _source.DGControl.Capability.Set(cap);
}
}
else
{
throw new InvalidOperationException("Simple Set() is not defined for this capability.");
}
}
return rc;
}
/// <summary>
/// A version of Set that uses an array.
/// </summary>
/// <param name="value">The value.</param>
/// <returns></returns>
public ReturnCode Set(TWArray value)
{
ReturnCode rc = ReturnCode.Failure;
if (CanSet)
{
using (var cap = new TWCapability(Capability, value))
{
rc = _source.DGControl.Capability.Set(cap);
}
}
return rc;
}

View File

@@ -654,7 +654,6 @@ namespace NTwain.Data
public TWCapability(CapabilityId capability, TWOneValue value, IMemoryManager memoryManager)
{
Capability = capability;
ContainerType = ContainerType.OneValue;
SetOneValue(value, memoryManager);
}
@@ -675,7 +674,6 @@ namespace NTwain.Data
public TWCapability(CapabilityId capability, TWEnumeration value, IMemoryManager memoryManager)
{
Capability = capability;
ContainerType = ContainerType.Enum;
SetEnumValue(value, memoryManager);
}
@@ -696,9 +694,28 @@ namespace NTwain.Data
public TWCapability(CapabilityId capability, TWRange value, IMemoryManager memoryManager)
{
Capability = capability;
ContainerType = ContainerType.Range;
SetRangeValue(value, memoryManager);
}
/// <summary>
/// Initializes a new instance of the <see cref="TWCapability" /> class.
/// </summary>
/// <param name="capability">The capability.</param>
/// <param name="value">The value.</param>
public TWCapability(CapabilityId capability, TWArray value)
: this(capability, value, PlatformInfo.Current.MemoryManager) { }
/// <summary>
/// Initializes a new instance of the <see cref="TWCapability" /> class.
/// </summary>
/// <param name="capability">The capability.</param>
/// <param name="value">The value.</param>
/// <param name="memoryManager">The memory manager.</param>
public TWCapability(CapabilityId capability, TWArray value, IMemoryManager memoryManager)
{
Capability = capability;
SetArrayValue(value, memoryManager);
}
#endregion
#region properties
@@ -759,7 +776,6 @@ namespace NTwain.Data
memoryManager.Unlock(baseAddr);
}
void SetRangeValue(TWRange value, IMemoryManager memoryManager)
{
if (value == null) { throw new ArgumentNullException("value"); }
@@ -774,6 +790,28 @@ namespace NTwain.Data
Marshal.StructureToPtr(value, _hContainer, false);
}
}
void SetArrayValue(TWArray value, IMemoryManager memoryManager)
{
if (value == null) { throw new ArgumentNullException("value"); }
ContainerType = ContainerType.Array;
Int32 valueSize = 6 + value.ItemList.Length * TypeReader.GetItemTypeSize(value.ItemType);
int offset = 0;
_hContainer = memoryManager.Allocate((uint)valueSize);
IntPtr baseAddr = memoryManager.Lock(_hContainer);
// can't safely use StructureToPtr here so write it our own
WriteValue(baseAddr, ref offset, ItemType.UInt16, value.ItemType);
WriteValue(baseAddr, ref offset, ItemType.UInt32, (uint)value.ItemList.Length);
foreach (var item in value.ItemList)
{
WriteValue(baseAddr, ref offset, value.ItemType, item);
}
memoryManager.Unlock(baseAddr);
}
#endregion
#region writes

View File

@@ -225,7 +225,7 @@ namespace NTwain.Data
/// Corresponds to TWBP_* values.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1028:EnumStorageShouldBeInt32")]
public enum BlankPage : short
public enum BlankPage //: short
{
Invalid = 0,
Disable = -2,

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,6 @@
using NTwain.Data;
using System;
using System.Collections.Generic;
namespace NTwain
{
@@ -57,19 +58,44 @@ namespace NTwain
/// </value>
bool CanGetLabelEnum { get; }
/// <summary>
/// Gets a value indicating whether <see cref="Reset"/> is supported.
/// </summary>
/// <value>
/// <c>true</c> if this capability can reset; otherwise, <c>false</c>.
/// </value>
bool CanReset { get; }
/// <summary>
/// Gets a value indicating whether <see cref="Set"/> is supported.
/// </summary>
/// <value>
/// <c>true</c> if this capability can set; otherwise, <c>false</c>.
/// </value>
bool CanSet { get; }
/// <summary>
/// Gets a value indicating whether <see cref="SetConstraint"/> is supported.
/// </summary>
/// <value>
/// <c>true</c> if this capability can set constraint; otherwise, <c>false</c>.
/// </value>
bool CanSetConstraint { get; }
/// <summary>
/// Gets the capability.
/// </summary>
/// <value>
/// The capability.
/// </value>
NTwain.Data.CapabilityId Capability { get; }
CapabilityId Capability { get; }
/// <summary>
/// Gets all the possible values of this capability.
/// </summary>
/// <returns></returns>
System.Collections.Generic.IList<TValue> Get();
IList<TValue> Get();
/// <summary>
/// Gets the current value of this capability.
@@ -99,7 +125,7 @@ namespace NTwain
/// [Experimental] Gets the display names for possible values of this capability.
/// </summary>
/// <returns></returns>
System.Collections.Generic.IList<string> GetLabelEnum();
IList<string> GetLabelEnum();
/// <summary>
/// Gets a value indicating whether this capability is supported.
@@ -115,7 +141,7 @@ namespace NTwain
/// <value>
/// The supported actions.
/// </value>
NTwain.Data.QuerySupports SupportedActions { get; }
QuerySupports SupportedActions { get; }
}
/// <summary>
@@ -124,42 +150,24 @@ namespace NTwain
/// <typeparam name="TValue">The TWAIN type of the value.</typeparam>
public interface ICapWrapper<TValue> : IReadOnlyCapWrapper<TValue>
{
/// <summary>
/// Gets a value indicating whether <see cref="Reset"/> is supported.
/// </summary>
/// <value>
/// <c>true</c> if this capability can reset; otherwise, <c>false</c>.
/// </value>
bool CanReset { get; }
/// <summary>
/// Gets a value indicating whether <see cref="Set"/> is supported.
/// </summary>
/// <value>
/// <c>true</c> if this capability can set; otherwise, <c>false</c>.
/// </value>
bool CanSet { get; }
/// <summary>
/// Gets a value indicating whether <see cref="SetConstraint"/> is supported.
/// </summary>
/// <value>
/// <c>true</c> if this capability can set constraint; otherwise, <c>false</c>.
/// </value>
bool CanSetConstraint { get; }
/// <summary>
/// Resets the current value to power-on default.
/// </summary>
/// <returns></returns>
NTwain.Data.ReturnCode Reset();
ReturnCode Reset();
/// <summary>
/// Simplified version that sets the current value of this capability.
/// </summary>
/// <param name="value">The value.</param>
/// <returns></returns>
NTwain.Data.ReturnCode Set(TValue value);
ReturnCode Set(TValue value);/// <summary>
///
/// A version of Set that uses an array.
/// </summary>
/// <param name="value">The value.</param>
/// <returns></returns>
ReturnCode Set(TWArray value);
/// <summary>
/// Sets the constraint value of this capability.

View File

@@ -23,7 +23,7 @@ namespace NTwain
/// <summary>
/// The build release version number.
/// </summary>
public const string Build = "3.1.1"; // change this for each nuget release
public const string Build = "3.2.0"; // change this for each nuget release
}