mirror of
https://github.com/soukoku/ntwain.git
synced 2025-04-05 20:59:23 +08:00
Playing with more interfaces.
This commit is contained in:
parent
11b6cb1040
commit
12859f42ac
NTwain.Net35
NTwain
CapWrapper.csCapabilityReader.cs
Data
DataSource.Caps.csICapControl.csITripletControl.csInternals
NTwain.csprojTwainSessionInternal.csTests/Tester.Winform
@ -45,12 +45,12 @@
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\NTwain\CapabilityControl.cs">
|
||||
<Link>CapabilityControl.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\NTwain\CapabilityReader.cs">
|
||||
<Link>CapabilityReader.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\NTwain\CapWrapper.cs">
|
||||
<Link>CapWrapper.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\NTwain\DataSource.Caps.cs">
|
||||
<Link>DataSource.Caps.cs</Link>
|
||||
</Compile>
|
||||
@ -78,8 +78,8 @@
|
||||
<Compile Include="..\NTwain\DeviceEventArgs.cs">
|
||||
<Link>DeviceEventArgs.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\NTwain\ICapController.cs">
|
||||
<Link>ICapController.cs</Link>
|
||||
<Compile Include="..\NTwain\ICapControl.cs">
|
||||
<Link>ICapControl.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\NTwain\IDataSource.cs">
|
||||
<Link>IDataSource.cs</Link>
|
||||
@ -126,6 +126,9 @@
|
||||
<Compile Include="..\NTwain\IPlatformInfo.cs">
|
||||
<Link>IPlatformInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\NTwain\ITripletControl.cs">
|
||||
<Link>ITripletControl.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\NTwain\ITwainSession.cs">
|
||||
<Link>ITwainSession.cs</Link>
|
||||
</Compile>
|
||||
|
@ -10,15 +10,23 @@ namespace NTwain
|
||||
/// Wrapped class for reading/writing a TWAIN capability associated with a <see cref="DataSource"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="TValue">The TWAIN type of the value.</typeparam>
|
||||
public class CapabilityControl<TValue>
|
||||
public class CapWrapper<TValue>
|
||||
{
|
||||
DataSource _source;
|
||||
/// <summary>
|
||||
/// Routine that does nothing.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <returns></returns>
|
||||
public static ReturnCode NoSetRoutine(TValue value) { return ReturnCode.Failure; }
|
||||
|
||||
|
||||
ICapControl _source;
|
||||
Func<object, TValue> _convertRoutine;
|
||||
Func<TValue, ReturnCode> _setCustomRoutine;
|
||||
Func<TValue, TWCapability> _setProvider; // an simplified way to set() that only needs on cap value
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CapabilityControl{TValue}" /> class.
|
||||
/// Initializes a new instance of the <see cref="CapWrapper{TValue}" /> class.
|
||||
/// </summary>
|
||||
/// <param name="source">The source.</param>
|
||||
/// <param name="capability">The capability.</param>
|
||||
@ -31,7 +39,7 @@ namespace NTwain
|
||||
/// or
|
||||
/// setValueProvider
|
||||
/// </exception>
|
||||
public CapabilityControl(DataSource source, CapabilityId capability,
|
||||
public CapWrapper(ICapControl source, CapabilityId capability,
|
||||
Func<object, TValue> getConversionRoutine,
|
||||
Func<TValue, TWCapability> setValueProvider)
|
||||
{
|
||||
@ -47,12 +55,12 @@ namespace NTwain
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CapabilityControl{TValue}" /> class.
|
||||
/// Initializes a new instance of the <see cref="CapWrapper{TValue}" /> class.
|
||||
/// </summary>
|
||||
/// <param name="source">The source.</param>
|
||||
/// <param name="capability">The capability.</param>
|
||||
/// <param name="getConversionRoutine">The value conversion routine in Get methods.</param>
|
||||
/// <param name="setValueRoutine">Callback to perform set value.</param>
|
||||
/// <param name="setValueRoutine">Callback to perform set value. Pass <see cref="NoSetRoutine"/> to not do sets.</param>
|
||||
/// <exception cref="System.ArgumentNullException">
|
||||
/// source
|
||||
/// or
|
||||
@ -60,7 +68,7 @@ namespace NTwain
|
||||
/// or
|
||||
/// setValueRoutine
|
||||
/// </exception>
|
||||
public CapabilityControl(DataSource source, CapabilityId capability,
|
||||
public CapWrapper(ICapControl source, CapabilityId capability,
|
||||
Func<object, TValue> getConversionRoutine,
|
||||
Func<TValue, ReturnCode> setValueRoutine)
|
||||
{
|
||||
@ -306,7 +314,7 @@ namespace NTwain
|
||||
#region set methods
|
||||
|
||||
/// <summary>
|
||||
/// Resets all values and constraint to power-on defaults.
|
||||
/// Resets all values and constraints to power-on defaults.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ReturnCode ResetAll()
|
@ -25,7 +25,7 @@ namespace NTwain
|
||||
/// capability</exception>
|
||||
public static CapabilityReader ReadValue(TWCapability capability)
|
||||
{
|
||||
return ReadValue(capability, PlatformInfo.Current);
|
||||
return ReadValue(capability, PlatformInfo.Current.MemoryManager);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -33,26 +33,24 @@ namespace NTwain
|
||||
/// from a TWAIN source.
|
||||
/// </summary>
|
||||
/// <param name="capability">The capability.</param>
|
||||
/// <param name="platformInfo">The platform information.</param>
|
||||
/// <param name="memoryManager">The memory manager.</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="System.ArgumentNullException">
|
||||
/// capability
|
||||
/// <exception cref="System.ArgumentNullException">capability
|
||||
/// or
|
||||
/// platformInfo
|
||||
/// </exception>
|
||||
/// platformInfo</exception>
|
||||
/// <exception cref="System.ArgumentException">Capability contains no data.;capability
|
||||
/// or
|
||||
/// capability</exception>
|
||||
public static CapabilityReader ReadValue(TWCapability capability, IPlatformInfo platformInfo)
|
||||
public static CapabilityReader ReadValue(TWCapability capability, IMemoryManager memoryManager)
|
||||
{
|
||||
if (capability == null) { throw new ArgumentNullException("capability"); }
|
||||
if (capability.Container == IntPtr.Zero) { throw new ArgumentException(Resources.CapHasNoData, "capability"); }
|
||||
if (platformInfo == null) { throw new ArgumentNullException("platformInfo"); }
|
||||
if (memoryManager == null) { throw new ArgumentNullException("memoryManager"); }
|
||||
|
||||
IntPtr baseAddr = IntPtr.Zero;
|
||||
try
|
||||
{
|
||||
baseAddr = platformInfo.MemoryManager.Lock(capability.Container);
|
||||
baseAddr = memoryManager.Lock(capability.Container);
|
||||
switch (capability.ContainerType)
|
||||
{
|
||||
case ContainerType.Array:
|
||||
@ -83,7 +81,7 @@ namespace NTwain
|
||||
{
|
||||
if (baseAddr != IntPtr.Zero)
|
||||
{
|
||||
platformInfo.MemoryManager.Unlock(baseAddr);
|
||||
memoryManager.Unlock(baseAddr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -643,32 +643,61 @@ namespace NTwain.Data
|
||||
/// <param name="capability">The capability.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
public TWCapability(CapabilityId capability, TWOneValue 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, TWOneValue value, IMemoryManager memoryManager)
|
||||
{
|
||||
Capability = capability;
|
||||
ContainerType = ContainerType.OneValue;
|
||||
SetOneValue(value);
|
||||
SetOneValue(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, TWEnumeration 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, TWEnumeration value, IMemoryManager memoryManager)
|
||||
{
|
||||
Capability = capability;
|
||||
ContainerType = ContainerType.Enum;
|
||||
SetEnumValue(value);
|
||||
SetEnumValue(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, TWRange 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, TWRange value, IMemoryManager memoryManager)
|
||||
{
|
||||
Capability = capability;
|
||||
ContainerType = ContainerType.Range;
|
||||
SetRangeValue(value);
|
||||
SetRangeValue(value, memoryManager);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -691,7 +720,7 @@ namespace NTwain.Data
|
||||
|
||||
#region value functions
|
||||
|
||||
void SetOneValue(TWOneValue value)
|
||||
void SetOneValue(TWOneValue value, IMemoryManager memoryManager)
|
||||
{
|
||||
if (value == null) { throw new ArgumentNullException("value"); }
|
||||
ContainerType = ContainerType.OneValue;
|
||||
@ -699,14 +728,14 @@ namespace NTwain.Data
|
||||
// since one value can only house UInt32 we will not allow type size > 4
|
||||
if (TypeReader.GetItemTypeSize(value.ItemType) > 4) { throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.BadValueType, "TWOneValue")); }
|
||||
|
||||
_hContainer = PlatformInfo.Current.MemoryManager.Allocate((uint)Marshal.SizeOf(value));
|
||||
_hContainer = memoryManager.Allocate((uint)Marshal.SizeOf(value));
|
||||
if (_hContainer != IntPtr.Zero)
|
||||
{
|
||||
Marshal.StructureToPtr(value, _hContainer, false);
|
||||
}
|
||||
}
|
||||
|
||||
void SetEnumValue(TWEnumeration value)
|
||||
void SetEnumValue(TWEnumeration value, IMemoryManager memoryManager)
|
||||
{
|
||||
if (value == null) { throw new ArgumentNullException("value"); }
|
||||
ContainerType = ContainerType.Enum;
|
||||
@ -715,8 +744,8 @@ namespace NTwain.Data
|
||||
Int32 valueSize = TWEnumeration.ItemOffset + value.ItemList.Length * TypeReader.GetItemTypeSize(value.ItemType);
|
||||
|
||||
int offset = 0;
|
||||
_hContainer = PlatformInfo.Current.MemoryManager.Allocate((uint)valueSize);
|
||||
IntPtr baseAddr = PlatformInfo.Current.MemoryManager.Lock(_hContainer);
|
||||
_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);
|
||||
@ -727,11 +756,11 @@ namespace NTwain.Data
|
||||
{
|
||||
WriteValue(baseAddr, ref offset, value.ItemType, item);
|
||||
}
|
||||
PlatformInfo.Current.MemoryManager.Unlock(baseAddr);
|
||||
memoryManager.Unlock(baseAddr);
|
||||
}
|
||||
|
||||
|
||||
void SetRangeValue(TWRange value)
|
||||
void SetRangeValue(TWRange value, IMemoryManager memoryManager)
|
||||
{
|
||||
if (value == null) { throw new ArgumentNullException("value"); }
|
||||
ContainerType = ContainerType.Range;
|
||||
@ -739,7 +768,7 @@ namespace NTwain.Data
|
||||
// since range value can only house UInt32 we will not allow type size > 4
|
||||
if (TypeReader.GetItemTypeSize(value.ItemType) > 4) { throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.BadValueType, "TWRange")); }
|
||||
|
||||
_hContainer = PlatformInfo.Current.MemoryManager.Allocate((uint)Marshal.SizeOf(value));
|
||||
_hContainer = memoryManager.Allocate((uint)Marshal.SizeOf(value));
|
||||
if (_hContainer != IntPtr.Zero)
|
||||
{
|
||||
Marshal.StructureToPtr(value, _hContainer, false);
|
||||
|
@ -9,7 +9,7 @@ namespace NTwain
|
||||
// this contains all cap-related methods prefixed with Cap
|
||||
|
||||
|
||||
partial class DataSource : ICapController
|
||||
partial class DataSource : ICapControl
|
||||
{
|
||||
#region low-level cap stuff
|
||||
|
||||
@ -170,11 +170,11 @@ namespace NTwain
|
||||
|
||||
#endregion
|
||||
|
||||
#region frequently used high-level caps stuff
|
||||
#region high-level caps stuff
|
||||
|
||||
#region audio caps
|
||||
|
||||
private CapabilityControl<XferMech> _audXferMech;
|
||||
private CapWrapper<XferMech> _audXferMech;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the property to work with audio <see cref="XferMech"/> for the current source.
|
||||
@ -182,20 +182,16 @@ namespace NTwain
|
||||
/// <value>
|
||||
/// The audio xfer mech.
|
||||
/// </value>
|
||||
public CapabilityControl<XferMech> CapAudioXferMech
|
||||
public CapWrapper<XferMech> CapAudioXferMech
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_audXferMech == null)
|
||||
{
|
||||
_audXferMech = new CapabilityControl<XferMech>(this, CapabilityId.ACapXferMech, ValueExtensions.ConvertToEnum<XferMech>,
|
||||
return _audXferMech ?? (_audXferMech = new CapWrapper<XferMech>(this, CapabilityId.ACapXferMech, ValueExtensions.ConvertToEnum<XferMech>,
|
||||
value => new TWCapability(CapabilityId.ACapXferMech, new TWOneValue
|
||||
{
|
||||
Item = (uint)value,
|
||||
ItemType = ItemType.UInt16
|
||||
}));
|
||||
}
|
||||
return _audXferMech;
|
||||
})));
|
||||
}
|
||||
}
|
||||
|
||||
@ -203,7 +199,7 @@ namespace NTwain
|
||||
|
||||
#region img caps
|
||||
|
||||
private CapabilityControl<XferMech> _imgXferMech;
|
||||
private CapWrapper<XferMech> _imgXferMech;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the property to work with image <see cref="XferMech"/> for the current source.
|
||||
@ -211,25 +207,21 @@ namespace NTwain
|
||||
/// <value>
|
||||
/// The image xfer mech.
|
||||
/// </value>
|
||||
public CapabilityControl<XferMech> CapImageXferMech
|
||||
public CapWrapper<XferMech> CapImageXferMech
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_imgXferMech == null)
|
||||
{
|
||||
_imgXferMech = new CapabilityControl<XferMech>(this, CapabilityId.ICapXferMech, ValueExtensions.ConvertToEnum<XferMech>,
|
||||
return _imgXferMech ?? (_imgXferMech = new CapWrapper<XferMech>(this, CapabilityId.ICapXferMech, ValueExtensions.ConvertToEnum<XferMech>,
|
||||
value => new TWCapability(CapabilityId.ICapXferMech, new TWOneValue
|
||||
{
|
||||
Item = (uint)value,
|
||||
ItemType = ItemType.UInt16
|
||||
}));
|
||||
}
|
||||
return _imgXferMech;
|
||||
})));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private CapabilityControl<CompressionType> _compression;
|
||||
private CapWrapper<CompressionType> _compression;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the property to work with image <see cref="CompressionType"/> for the current source.
|
||||
@ -237,25 +229,21 @@ namespace NTwain
|
||||
/// <value>
|
||||
/// The image compression.
|
||||
/// </value>
|
||||
public CapabilityControl<CompressionType> CapImageCompression
|
||||
public CapWrapper<CompressionType> CapImageCompression
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_compression == null)
|
||||
{
|
||||
_compression = new CapabilityControl<CompressionType>(this, CapabilityId.ICapCompression, ValueExtensions.ConvertToEnum<CompressionType>,
|
||||
return _compression ?? (_compression = new CapWrapper<CompressionType>(this, CapabilityId.ICapCompression, ValueExtensions.ConvertToEnum<CompressionType>,
|
||||
value => new TWCapability(CapabilityId.ICapCompression, new TWOneValue
|
||||
{
|
||||
Item = (uint)value,
|
||||
ItemType = ItemType.UInt16
|
||||
}));
|
||||
}
|
||||
return _compression;
|
||||
})));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private CapabilityControl<FileFormat> _fileFormat;
|
||||
private CapWrapper<FileFormat> _fileFormat;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the property to work with image <see cref="FileFormat"/> for the current source.
|
||||
@ -263,25 +251,21 @@ namespace NTwain
|
||||
/// <value>
|
||||
/// The image file format.
|
||||
/// </value>
|
||||
public CapabilityControl<FileFormat> CapImageFileFormat
|
||||
public CapWrapper<FileFormat> CapImageFileFormat
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_fileFormat == null)
|
||||
{
|
||||
_fileFormat = new CapabilityControl<FileFormat>(this, CapabilityId.ICapImageFileFormat, ValueExtensions.ConvertToEnum<FileFormat>,
|
||||
return _fileFormat ?? (_fileFormat = new CapWrapper<FileFormat>(this, CapabilityId.ICapImageFileFormat, ValueExtensions.ConvertToEnum<FileFormat>,
|
||||
value => new TWCapability(CapabilityId.ICapImageFileFormat, new TWOneValue
|
||||
{
|
||||
Item = (uint)value,
|
||||
ItemType = ItemType.UInt16
|
||||
}));
|
||||
}
|
||||
return _fileFormat;
|
||||
})));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private CapabilityControl<PixelType> _pixelType;
|
||||
private CapWrapper<PixelType> _pixelType;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the property to work with image <see cref="PixelType"/> for the current source.
|
||||
@ -289,25 +273,21 @@ namespace NTwain
|
||||
/// <value>
|
||||
/// The image pixel type.
|
||||
/// </value>
|
||||
public CapabilityControl<PixelType> CapImagePixelType
|
||||
public CapWrapper<PixelType> CapImagePixelType
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_pixelType == null)
|
||||
{
|
||||
_pixelType = new CapabilityControl<PixelType>(this, CapabilityId.ICapPixelType, ValueExtensions.ConvertToEnum<PixelType>,
|
||||
return _pixelType ?? (_pixelType = new CapWrapper<PixelType>(this, CapabilityId.ICapPixelType, ValueExtensions.ConvertToEnum<PixelType>,
|
||||
value => new TWCapability(CapabilityId.ICapPixelType, new TWOneValue
|
||||
{
|
||||
Item = (uint)value,
|
||||
ItemType = ItemType.UInt16
|
||||
}));
|
||||
}
|
||||
return _pixelType;
|
||||
})));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private CapabilityControl<SupportedSize> _supportSize;
|
||||
private CapWrapper<SupportedSize> _supportSize;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the property to work with image <see cref="SupportedSize"/> for the current source.
|
||||
@ -315,25 +295,21 @@ namespace NTwain
|
||||
/// <value>
|
||||
/// The image supported size.
|
||||
/// </value>
|
||||
public CapabilityControl<SupportedSize> CapImageSupportedSize
|
||||
public CapWrapper<SupportedSize> CapImageSupportedSize
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_supportSize == null)
|
||||
{
|
||||
_supportSize = new CapabilityControl<SupportedSize>(this, CapabilityId.ICapSupportedSizes, ValueExtensions.ConvertToEnum<SupportedSize>,
|
||||
return _supportSize ?? (_supportSize = new CapWrapper<SupportedSize>(this, CapabilityId.ICapSupportedSizes, ValueExtensions.ConvertToEnum<SupportedSize>,
|
||||
value => new TWCapability(CapabilityId.ICapSupportedSizes, new TWOneValue
|
||||
{
|
||||
Item = (uint)value,
|
||||
ItemType = ItemType.UInt16
|
||||
}));
|
||||
}
|
||||
return _supportSize;
|
||||
})));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private CapabilityControl<BoolType> _autoDeskew;
|
||||
private CapWrapper<BoolType> _autoDeskew;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the property to work with image auto deskew flag for the current source.
|
||||
@ -341,25 +317,21 @@ namespace NTwain
|
||||
/// <value>
|
||||
/// The image auto deskew flag.
|
||||
/// </value>
|
||||
public CapabilityControl<BoolType> CapImageAutoDeskew
|
||||
public CapWrapper<BoolType> CapImageAutoDeskew
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_autoDeskew == null)
|
||||
{
|
||||
_autoDeskew = new CapabilityControl<BoolType>(this, CapabilityId.ICapAutomaticDeskew, ValueExtensions.ConvertToEnum<BoolType>, value =>
|
||||
return _autoDeskew ?? (_autoDeskew = new CapWrapper<BoolType>(this, CapabilityId.ICapAutomaticDeskew, ValueExtensions.ConvertToEnum<BoolType>, value =>
|
||||
new TWCapability(CapabilityId.ICapAutomaticRotate, new TWOneValue
|
||||
{
|
||||
Item = (uint)value,
|
||||
ItemType = ItemType.Bool
|
||||
}));
|
||||
}
|
||||
return _autoDeskew;
|
||||
})));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private CapabilityControl<BoolType> _autoRotate;
|
||||
private CapWrapper<BoolType> _autoRotate;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the property to work with image auto rotate flag for the current source.
|
||||
@ -367,25 +339,21 @@ namespace NTwain
|
||||
/// <value>
|
||||
/// The image auto rotate flag.
|
||||
/// </value>
|
||||
public CapabilityControl<BoolType> CapImageAutoRotate
|
||||
public CapWrapper<BoolType> CapImageAutoRotate
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_autoRotate == null)
|
||||
{
|
||||
_autoRotate = new CapabilityControl<BoolType>(this, CapabilityId.ICapAutomaticRotate, ValueExtensions.ConvertToEnum<BoolType>, value =>
|
||||
new TWCapability(CapabilityId.ICapAutomaticRotate, new TWOneValue
|
||||
{
|
||||
Item = (uint)value,
|
||||
ItemType = ItemType.Bool
|
||||
}));
|
||||
}
|
||||
return _autoRotate;
|
||||
return _autoRotate ?? (_autoRotate = new CapWrapper<BoolType>(this, CapabilityId.ICapAutomaticRotate, ValueExtensions.ConvertToEnum<BoolType>, value =>
|
||||
new TWCapability(CapabilityId.ICapAutomaticRotate, new TWOneValue
|
||||
{
|
||||
Item = (uint)value,
|
||||
ItemType = ItemType.Bool
|
||||
})));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private CapabilityControl<TWFix32> _xResolution;
|
||||
private CapWrapper<TWFix32> _xResolution;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the property to work with image horizontal resolution for the current source.
|
||||
@ -393,25 +361,21 @@ namespace NTwain
|
||||
/// <value>
|
||||
/// The image horizontal resolution.
|
||||
/// </value>
|
||||
public CapabilityControl<TWFix32> CapImageXResolution
|
||||
public CapWrapper<TWFix32> CapImageXResolution
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_xResolution == null)
|
||||
{
|
||||
_xResolution = new CapabilityControl<TWFix32>(this, CapabilityId.ICapXResolution, ValueExtensions.ConvertToFix32,
|
||||
return _xResolution ?? (_xResolution = new CapWrapper<TWFix32>(this, CapabilityId.ICapXResolution, ValueExtensions.ConvertToFix32,
|
||||
value => new TWCapability(CapabilityId.ICapXResolution, new TWOneValue
|
||||
{
|
||||
Item = (uint)value,// ((uint)dpi) << 16;
|
||||
ItemType = ItemType.Fix32
|
||||
}));
|
||||
}
|
||||
return _xResolution;
|
||||
})));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private CapabilityControl<TWFix32> _yResolution;
|
||||
private CapWrapper<TWFix32> _yResolution;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the property to work with image vertical resolution for the current source.
|
||||
@ -419,25 +383,21 @@ namespace NTwain
|
||||
/// <value>
|
||||
/// The image vertical resolution.
|
||||
/// </value>
|
||||
public CapabilityControl<TWFix32> CapImageYResolution
|
||||
public CapWrapper<TWFix32> CapImageYResolution
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_yResolution == null)
|
||||
{
|
||||
_yResolution = new CapabilityControl<TWFix32>(this, CapabilityId.ICapYResolution, ValueExtensions.ConvertToFix32,
|
||||
return _yResolution ?? (_yResolution = new CapWrapper<TWFix32>(this, CapabilityId.ICapYResolution, ValueExtensions.ConvertToFix32,
|
||||
value => new TWCapability(CapabilityId.ICapYResolution, new TWOneValue
|
||||
{
|
||||
Item = (uint)value,// ((uint)dpi) << 16;
|
||||
ItemType = ItemType.Fix32
|
||||
}));
|
||||
}
|
||||
return _yResolution;
|
||||
})));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private CapabilityControl<BoolType> _borderDetect;
|
||||
private CapWrapper<BoolType> _borderDetect;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the property to work with auto border detection flag for the current source.
|
||||
@ -445,13 +405,11 @@ namespace NTwain
|
||||
/// <value>
|
||||
/// The auto border detection flag.
|
||||
/// </value>
|
||||
public CapabilityControl<BoolType> CapImageAutomaticBorderDetection
|
||||
public CapWrapper<BoolType> CapImageAutomaticBorderDetection
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_borderDetect == null)
|
||||
{
|
||||
_borderDetect = new CapabilityControl<BoolType>(this, CapabilityId.ICapAutomaticBorderDetection, ValueExtensions.ConvertToEnum<BoolType>, value =>
|
||||
return _borderDetect ?? ( _borderDetect = new CapWrapper<BoolType>(this, CapabilityId.ICapAutomaticBorderDetection, ValueExtensions.ConvertToEnum<BoolType>, value =>
|
||||
{
|
||||
var rc = ReturnCode.Failure;
|
||||
|
||||
@ -471,9 +429,7 @@ namespace NTwain
|
||||
}
|
||||
|
||||
return rc;
|
||||
});
|
||||
}
|
||||
return _borderDetect;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@ -481,7 +437,7 @@ namespace NTwain
|
||||
|
||||
#region other caps
|
||||
|
||||
private CapabilityControl<BoolType> _duplexEnabled;
|
||||
private CapWrapper<BoolType> _duplexEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the property to work with duplex enabled flag for the current source.
|
||||
@ -489,25 +445,21 @@ namespace NTwain
|
||||
/// <value>
|
||||
/// The duplex enabled flag.
|
||||
/// </value>
|
||||
public CapabilityControl<BoolType> CapDuplexEnabled
|
||||
public CapWrapper<BoolType> CapDuplexEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_duplexEnabled == null)
|
||||
{
|
||||
_duplexEnabled = new CapabilityControl<BoolType>(this, CapabilityId.CapDuplexEnabled, ValueExtensions.ConvertToEnum<BoolType>, value =>
|
||||
return _duplexEnabled ?? (_duplexEnabled = new CapWrapper<BoolType>(this, CapabilityId.CapDuplexEnabled, ValueExtensions.ConvertToEnum<BoolType>, value =>
|
||||
new TWCapability(CapabilityId.CapDuplexEnabled, new TWOneValue
|
||||
{
|
||||
Item = (uint)value,
|
||||
ItemType = ItemType.Bool
|
||||
}));
|
||||
}
|
||||
return _duplexEnabled;
|
||||
})));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private CapabilityControl<int> _xferCount;
|
||||
private CapWrapper<int> _xferCount;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the property to work with xfer count for the current source.
|
||||
@ -515,25 +467,21 @@ namespace NTwain
|
||||
/// <value>
|
||||
/// The xfer count.
|
||||
/// </value>
|
||||
public CapabilityControl<int> CapXferCount
|
||||
public CapWrapper<int> CapXferCount
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_xferCount == null)
|
||||
{
|
||||
_xferCount = new CapabilityControl<int>(this, CapabilityId.CapXferCount, ValueExtensions.ConvertToEnum<int>, value =>
|
||||
return _xferCount ?? (_xferCount = new CapWrapper<int>(this, CapabilityId.CapXferCount, ValueExtensions.ConvertToEnum<int>, value =>
|
||||
new TWCapability(CapabilityId.CapXferCount, new TWOneValue
|
||||
{
|
||||
Item = value > 0 ? (uint)value : uint.MaxValue,
|
||||
ItemType = ItemType.UInt16
|
||||
}));
|
||||
}
|
||||
return _xferCount;
|
||||
})));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private CapabilityControl<BoolType> _feederEnabled;
|
||||
private CapWrapper<BoolType> _feederEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the property to work with feeder enabled flag for the current source.
|
||||
@ -541,13 +489,11 @@ namespace NTwain
|
||||
/// <value>
|
||||
/// The feeder enabled flag.
|
||||
/// </value>
|
||||
public CapabilityControl<BoolType> CapFeederEnabled
|
||||
public CapWrapper<BoolType> CapFeederEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_feederEnabled == null)
|
||||
{
|
||||
_feederEnabled = new CapabilityControl<BoolType>(this, CapabilityId.CapFeederEnabled, ValueExtensions.ConvertToEnum<BoolType>, value =>
|
||||
return _feederEnabled ?? (_feederEnabled = new CapWrapper<BoolType>(this, CapabilityId.CapFeederEnabled, ValueExtensions.ConvertToEnum<BoolType>, value =>
|
||||
{
|
||||
var rc = ReturnCode.Failure;
|
||||
|
||||
@ -584,9 +530,7 @@ namespace NTwain
|
||||
}
|
||||
|
||||
return rc;
|
||||
});
|
||||
}
|
||||
return _feederEnabled;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,38 +4,38 @@ using System.Collections.Generic;
|
||||
namespace NTwain
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for controlling caps.
|
||||
/// Interface for providing basic functions at controlling caps.
|
||||
/// </summary>
|
||||
public interface ICapController
|
||||
public interface ICapControl : ITripletControl
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// A general method that tries to get capability values from current <see cref="DataSource" />.
|
||||
/// Gets all the possible values for a capability.
|
||||
/// </summary>
|
||||
/// <param name="capabilityId">The capability unique identifier.</param>
|
||||
/// <param name="capabilityId">The capability identifier.</param>
|
||||
/// <returns></returns>
|
||||
IList<object> CapGet(CapabilityId capabilityId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current value for a capability.
|
||||
/// </summary>
|
||||
/// <param name="capId">The cap id.</param>
|
||||
/// <param name="capabilityId">The capability identifier.</param>
|
||||
/// <returns></returns>
|
||||
object CapGetCurrent(CapabilityId capId);
|
||||
object CapGetCurrent(CapabilityId capabilityId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default value for a capability.
|
||||
/// </summary>
|
||||
/// <param name="capId">The cap id.</param>
|
||||
/// <param name="capabilityId">The capability identifier.</param>
|
||||
/// <returns></returns>
|
||||
object CapGetDefault(CapabilityId capId);
|
||||
|
||||
object CapGetDefault(CapabilityId capabilityId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the actual supported operations for a capability.
|
||||
/// Gets the supported operations for a capability.
|
||||
/// </summary>
|
||||
/// <param name="capId">The cap identifier.</param>
|
||||
/// <param name="capabilityId">The capability identifier.</param>
|
||||
/// <returns></returns>
|
||||
QuerySupports CapQuerySupport(CapabilityId capId);
|
||||
QuerySupports CapQuerySupport(CapabilityId capabilityId);
|
||||
|
||||
/// <summary>
|
||||
/// Resets the current value to power-on default.
|
||||
@ -45,7 +45,7 @@ namespace NTwain
|
||||
ReturnCode CapReset(CapabilityId capabilityId);
|
||||
|
||||
/// <summary>
|
||||
/// Resets all values and constraint to power-on defaults.
|
||||
/// Resets all values and constraints to power-on defaults.
|
||||
/// </summary>
|
||||
/// <param name="capabilityId">The capability identifier.</param>
|
||||
/// <returns></returns>
|
29
NTwain/ITripletControl.cs
Normal file
29
NTwain/ITripletControl.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using NTwain.Triplets;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace NTwain
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for providing TWAIN triplet access.
|
||||
/// </summary>
|
||||
public interface ITripletControl
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the triplet operations defined for control data group.
|
||||
/// </summary>
|
||||
DGControl DGControl { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the triplet operations defined for image data group.
|
||||
/// </summary>
|
||||
DGImage DGImage { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the direct triplet operation entry for custom values.
|
||||
/// </summary>
|
||||
DGCustom DGCustom { get; }
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ namespace NTwain.Internals
|
||||
/// <summary>
|
||||
/// Extends <see cref="ITwainSession"/> with extra stuff for internal use.
|
||||
/// </summary>
|
||||
interface ITwainSessionInternal : ITwainSession
|
||||
interface ITwainSessionInternal : ITwainSession, ITripletControl
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the app id used for the session.
|
||||
@ -48,20 +48,5 @@ namespace NTwain.Internals
|
||||
/// Gets the triplet operations defined for audio data group.
|
||||
/// </summary>
|
||||
DGAudio DGAudio { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the triplet operations defined for control data group.
|
||||
/// </summary>
|
||||
DGControl DGControl { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the triplet operations defined for image data group.
|
||||
/// </summary>
|
||||
DGImage DGImage { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the direct triplet operation entry for custom values.
|
||||
/// </summary>
|
||||
DGCustom DGCustom { get; }
|
||||
}
|
||||
}
|
||||
|
@ -55,13 +55,13 @@
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CapabilityControl.cs" />
|
||||
<Compile Include="CapWrapper.cs" />
|
||||
<Compile Include="CapabilityReader.cs" />
|
||||
<Compile Include="Data\TypeReader.cs" />
|
||||
<Compile Include="Data\TwainTypesExtended.cs" />
|
||||
<Compile Include="DeviceEventArgs.cs" />
|
||||
<Compile Include="IDataSource.cs" />
|
||||
<Compile Include="ICapController.cs" />
|
||||
<Compile Include="ICapControl.cs" />
|
||||
<Compile Include="Internals\Extensions.cs" />
|
||||
<Compile Include="DataTransferredEventArgs.cs" />
|
||||
<Compile Include="IMemoryManager.cs" />
|
||||
@ -73,6 +73,7 @@
|
||||
<Compile Include="Internals\WindowsHook.cs" />
|
||||
<Compile Include="Internals\WrappedManualResetEvent.cs" />
|
||||
<Compile Include="IPlatformInfo.cs" />
|
||||
<Compile Include="ITripletControl.cs" />
|
||||
<Compile Include="ITwainSession.cs" />
|
||||
<Compile Include="Internals\WinMemoryManager.cs" />
|
||||
<Compile Include="Internals\UnsafeNativeMethods.cs" />
|
||||
|
@ -73,7 +73,7 @@ namespace NTwain
|
||||
}
|
||||
|
||||
DGControl _dgControl;
|
||||
DGControl ITwainSessionInternal.DGControl
|
||||
DGControl ITripletControl.DGControl
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -83,7 +83,7 @@ namespace NTwain
|
||||
}
|
||||
|
||||
DGImage _dgImage;
|
||||
DGImage ITwainSessionInternal.DGImage
|
||||
DGImage ITripletControl.DGImage
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -93,7 +93,7 @@ namespace NTwain
|
||||
}
|
||||
|
||||
DGCustom _dgCustom;
|
||||
DGCustom ITwainSessionInternal.DGCustom
|
||||
DGCustom ITripletControl.DGCustom
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -297,7 +297,7 @@ namespace Tester.Winform
|
||||
_loadingCaps = false;
|
||||
}
|
||||
|
||||
private void LoadPaperSize(CapabilityControl<SupportedSize> cap)
|
||||
private void LoadPaperSize(CapWrapper<SupportedSize> cap)
|
||||
{
|
||||
var list = cap.Get();
|
||||
comboSize.DataSource = list;
|
||||
@ -314,13 +314,13 @@ namespace Tester.Winform
|
||||
}
|
||||
|
||||
|
||||
private void LoadDuplex(CapabilityControl<BoolType> cap)
|
||||
private void LoadDuplex(CapWrapper<BoolType> cap)
|
||||
{
|
||||
ckDuplex.Checked = cap.GetCurrent() == BoolType.True;
|
||||
}
|
||||
|
||||
|
||||
private void LoadDPI(CapabilityControl<TWFix32> cap)
|
||||
private void LoadDPI(CapWrapper<TWFix32> cap)
|
||||
{
|
||||
// only allow dpi of certain values for those source that lists everything
|
||||
var list = cap.Get().Where(dpi => (dpi % 50) == 0).ToList();
|
||||
@ -332,7 +332,7 @@ namespace Tester.Winform
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadDepth(CapabilityControl<PixelType> cap)
|
||||
private void LoadDepth(CapWrapper<PixelType> cap)
|
||||
{
|
||||
var list = cap.Get();
|
||||
comboDepth.DataSource = list;
|
||||
|
Loading…
Reference in New Issue
Block a user