mirror of
https://github.com/soukoku/ntwain.git
synced 2025-04-05 17:22:26 +08:00
Added Settings property for use with CustomDSData #38.
This commit is contained in:
parent
b757cc4a42
commit
f60c2a083f
@ -19,7 +19,6 @@ namespace NTwain
|
||||
Func<object, TValue> _getConvertRoutine;
|
||||
Func<TValue, ReturnCode> _setCustomRoutine;
|
||||
Func<TValue, TWOneValue> _setOneValueFunc;
|
||||
bool _readOnly;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CapWrapper{TValue}" /> class.
|
||||
@ -40,7 +39,7 @@ namespace NTwain
|
||||
|
||||
_source = source;
|
||||
_getConvertRoutine = getConversionRoutine;
|
||||
_readOnly = readOnly;
|
||||
IsReadOnly = readOnly;
|
||||
Capability = capability;
|
||||
|
||||
CheckSupports();
|
||||
@ -125,7 +124,7 @@ namespace NTwain
|
||||
if (rc == ReturnCode.Success)
|
||||
{
|
||||
// assume can do common things
|
||||
if (_readOnly)
|
||||
if (IsReadOnly)
|
||||
{
|
||||
_supports = QuerySupports.Get | QuerySupports.GetCurrent | QuerySupports.GetDefault;
|
||||
}
|
||||
@ -191,6 +190,14 @@ namespace NTwain
|
||||
/// </value>
|
||||
public bool IsSupported { get { return SupportedActions > QuerySupports.None; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this instance is read only.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if this instance is read only; otherwise, <c>false</c>.
|
||||
/// </value>
|
||||
public bool IsReadOnly { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether <see cref="GetValues"/> is supported.
|
||||
/// </summary>
|
||||
|
@ -1032,7 +1032,7 @@ namespace NTwain.Data
|
||||
/// <summary>
|
||||
/// Allows for a data source and application to pass custom data to each other.
|
||||
/// </summary>
|
||||
public partial class TWCustomDSData
|
||||
partial class TWCustomDSData
|
||||
{
|
||||
/// <summary>
|
||||
/// Length, in bytes, of data.
|
||||
|
@ -114,7 +114,7 @@ namespace NTwain.Data
|
||||
/// <param name="offset">The offset.</param>
|
||||
/// <param name="type">The TWAIN type.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1045:DoNotPassTypesByReference", MessageId = "1#"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
|
||||
public static void WriteValue(this IntPtr baseAddr, ref int offset, ItemType type, object value)
|
||||
{
|
||||
switch (type)
|
||||
|
@ -7,6 +7,7 @@ using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
@ -158,6 +159,69 @@ namespace NTwain
|
||||
/// </value>
|
||||
public bool IsOpen { get { return _session.IsSourceOpen; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the current settings (CustomDSData) of this source if supported.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The source settings.
|
||||
/// </value>
|
||||
public byte[] Settings
|
||||
{
|
||||
get
|
||||
{
|
||||
byte[] value = null;
|
||||
if (Capabilities.CapCustomDSData.GetCurrent() == BoolType.True)
|
||||
{
|
||||
TWCustomDSData data;
|
||||
if (DGControl.CustomDSData.Get(out data) == ReturnCode.Success && data.InfoLength > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
value = new byte[data.InfoLength];
|
||||
var ptr = PlatformInfo.Current.MemoryManager.Lock(data.hData);
|
||||
Marshal.Copy(ptr, value, 0, (int)data.InfoLength);
|
||||
}
|
||||
finally
|
||||
{
|
||||
PlatformInfo.Current.MemoryManager.Unlock(data.hData);
|
||||
PlatformInfo.Current.MemoryManager.Free(data.hData);
|
||||
}
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != null && value.Length > 0 &&
|
||||
Capabilities.CapCustomDSData.GetCurrent() == BoolType.True)
|
||||
{
|
||||
TWCustomDSData data = new TWCustomDSData
|
||||
{
|
||||
InfoLength = (uint)value.Length
|
||||
};
|
||||
try
|
||||
{
|
||||
data.hData = PlatformInfo.Current.MemoryManager.Allocate(data.InfoLength);
|
||||
var ptr = PlatformInfo.Current.MemoryManager.Lock(data.hData);
|
||||
Marshal.Copy(value, 0, ptr, value.Length);
|
||||
var rc = DGControl.CustomDSData.Set(data);
|
||||
if (rc != ReturnCode.Success)
|
||||
{
|
||||
// do something
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (data.hData != IntPtr.Zero)
|
||||
{
|
||||
PlatformInfo.Current.MemoryManager.Unlock(data.hData);
|
||||
PlatformInfo.Current.MemoryManager.Free(data.hData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//static readonly CapabilityId[] _emptyCapList = new CapabilityId[0];
|
||||
|
||||
//private IList<CapabilityId> _supportedCapsList;
|
||||
|
@ -134,6 +134,14 @@ namespace NTwain
|
||||
/// <c>true</c> if this capability is supported; otherwise, <c>false</c>.
|
||||
/// </value>
|
||||
bool IsSupported { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this instance is read only.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if this instance is read only; otherwise, <c>false</c>.
|
||||
/// </value>
|
||||
bool IsReadOnly { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -72,6 +72,14 @@ namespace NTwain
|
||||
/// </value>
|
||||
Capabilities Capabilities { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the current settings (CustomDSData) of this source if supported.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The source settings.
|
||||
/// </value>
|
||||
byte[] Settings { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Opens the source for capability negotiation.
|
||||
/// </summary>
|
||||
|
@ -23,7 +23,7 @@ namespace NTwain
|
||||
/// <summary>
|
||||
/// The build release version number.
|
||||
/// </summary>
|
||||
public const string Build = "3.3.1"; // change this for each nuget release
|
||||
public const string Build = "3.3.2"; // change this for each nuget release
|
||||
|
||||
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ namespace NTwain.Triplets
|
||||
/// <summary>
|
||||
/// Represents <see cref="DataArgumentType.CustomDSData"/>.
|
||||
/// </summary>
|
||||
public sealed class CustomDSData : TripletBase
|
||||
sealed class CustomDSData : TripletBase
|
||||
{
|
||||
internal CustomDSData(ITwainSessionInternal session) : base(session) { }
|
||||
/// <summary>
|
||||
@ -16,7 +16,6 @@ namespace NTwain.Triplets
|
||||
/// </summary>
|
||||
/// <param name="customData">The custom data.</param>
|
||||
/// <returns></returns>
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "0#")]
|
||||
public ReturnCode Get(out TWCustomDSData customData)
|
||||
{
|
||||
Session.VerifyState(4, 4, DataGroups.Control, DataArgumentType.CustomDSData, Message.Get);
|
||||
|
@ -59,10 +59,7 @@ namespace NTwain.Triplets
|
||||
}
|
||||
}
|
||||
CustomDSData _customDSData;
|
||||
/// <summary>
|
||||
/// Gets the operations defined for DAT_CUSTOMDSDATA.
|
||||
/// </summary>
|
||||
public CustomDSData CustomDSData
|
||||
internal CustomDSData CustomDSData
|
||||
{
|
||||
get
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user