Started adding more wrapped caps.

This commit is contained in:
soukoku
2014-09-24 21:52:28 -04:00
parent 9506155f38
commit 57d7dbe0ef
10 changed files with 371 additions and 45 deletions

View File

@@ -6,6 +6,9 @@ using System.Text;
namespace NTwain
{
//TODO: handle multi-value sets
/// <summary>
/// Wrapped class for reading/writing a TWAIN capability associated with a <see cref="DataSource"/>.
/// </summary>
@@ -25,6 +28,30 @@ namespace NTwain
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="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>
/// <exception cref="System.ArgumentNullException">
/// source
/// or
/// valueConversionRoutine
/// </exception>
public CapWrapper(ICapControl source, CapabilityId capability,
Func<object, TValue> getConversionRoutine)
{
if (source == null) { throw new ArgumentNullException("source"); }
if (getConversionRoutine == null) { throw new ArgumentNullException("valueConversionRoutine"); }
_source = source;
_convertRoutine = getConversionRoutine;
Capability = capability;
SupportedActions = source.CapQuerySupport(capability);
}
/// <summary>
/// Initializes a new instance of the <see cref="CapWrapper{TValue}" /> class.
/// </summary>

View File

@@ -6,7 +6,10 @@ using System.Text;
namespace NTwain
{
// this contains all cap-related methods prefixed with Cap
// This contains all cap-related methods prefixed with Cap.
// It will attempt to have all known cap abilities defined
// with a wrapper unless it can only exist as part of another cap
// or it's lame & nobody uses it.
partial class DataSource : ICapControl
@@ -199,6 +202,27 @@ namespace NTwain
#region img caps
private CapWrapper<Unit> _imgUnits;
/// <summary>
/// Gets the property to work with image <see cref="Unit"/> for the current source.
/// </summary>
/// <value>
/// The image unit of measure.
/// </value>
public CapWrapper<Unit> CapImageUnits
{
get
{
return _imgUnits ?? (_imgUnits = new CapWrapper<Unit>(this, CapabilityId.ICapUnits, ValueExtensions.ConvertToEnum<Unit>,
value => new TWCapability(CapabilityId.ICapUnits, new TWOneValue
{
Item = (uint)value,
ItemType = ItemType.UInt16
})));
}
}
private CapWrapper<XferMech> _imgXferMech;
/// <summary>
@@ -322,7 +346,7 @@ namespace NTwain
get
{
return _autoDeskew ?? (_autoDeskew = new CapWrapper<BoolType>(this, CapabilityId.ICapAutomaticDeskew, ValueExtensions.ConvertToEnum<BoolType>, value =>
new TWCapability(CapabilityId.ICapAutomaticRotate, new TWOneValue
new TWCapability(CapabilityId.ICapAutomaticDeskew, new TWOneValue
{
Item = (uint)value,
ItemType = ItemType.Bool
@@ -409,7 +433,7 @@ namespace NTwain
{
get
{
return _borderDetect ?? ( _borderDetect = new CapWrapper<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;
@@ -437,6 +461,22 @@ namespace NTwain
#region other caps
private CapWrapper<Duplex> _duplex;
/// <summary>
/// Gets the property to see what's the duplex mode for the current source.
/// </summary>
/// <value>
/// The duplex mode.
/// </value>
public CapWrapper<Duplex> CapDuplex
{
get
{
return _duplex ?? (_duplex = new CapWrapper<Duplex>(this, CapabilityId.CapDuplex, ValueExtensions.ConvertToEnum<Duplex>));
}
}
private CapWrapper<BoolType> _duplexEnabled;
/// <summary>
@@ -480,6 +520,21 @@ namespace NTwain
}
}
private CapWrapper<BoolType> _feederLoaded;
/// <summary>
/// Gets the property to work with feeder loaded flag for the current source.
/// </summary>
/// <value>
/// The feeder loaded flag.
/// </value>
public CapWrapper<BoolType> CapFeederLoaded
{
get
{
return _feederLoaded ?? (_feederLoaded = new CapWrapper<BoolType>(this, CapabilityId.CapFeederLoaded, ValueExtensions.ConvertToEnum<BoolType>));
}
}
private CapWrapper<BoolType> _feederEnabled;
@@ -534,6 +589,254 @@ namespace NTwain
}
}
private CapWrapper<BoolType> _clearPage;
/// <summary>
/// Gets the property to work with clear page flag for the current source.
/// </summary>
/// <value>
/// The clear page flag.
/// </value>
public CapWrapper<BoolType> CapClearPage
{
get
{
return _clearPage ?? (_clearPage = new CapWrapper<BoolType>(this, CapabilityId.CapClearPage, ValueExtensions.ConvertToEnum<BoolType>, value =>
new TWCapability(CapabilityId.CapClearPage, new TWOneValue
{
Item = (uint)value,
ItemType = ItemType.Bool
})));
}
}
private CapWrapper<BoolType> _feedPage;
/// <summary>
/// Gets the property to work with feed page flag for the current source.
/// </summary>
/// <value>
/// The feed page flag.
/// </value>
public CapWrapper<BoolType> CapFeedPage
{
get
{
return _feedPage ?? (_feedPage = new CapWrapper<BoolType>(this, CapabilityId.CapFeedPage, ValueExtensions.ConvertToEnum<BoolType>, value =>
new TWCapability(CapabilityId.CapFeedPage, new TWOneValue
{
Item = (uint)value,
ItemType = ItemType.Bool
})));
}
}
private CapWrapper<BoolType> _rewindPage;
/// <summary>
/// Gets the property to work with rewind page flag for the current source.
/// </summary>
/// <value>
/// The rewind page flag.
/// </value>
public CapWrapper<BoolType> CapRewindPage
{
get
{
return _rewindPage ?? (_rewindPage = new CapWrapper<BoolType>(this, CapabilityId.CapRewindPage, ValueExtensions.ConvertToEnum<BoolType>, value =>
new TWCapability(CapabilityId.CapRewindPage, new TWOneValue
{
Item = (uint)value,
ItemType = ItemType.Bool
})));
}
}
private CapWrapper<BoolType> _indicators;
/// <summary>
/// Gets the property to work with indicators flag for the current source.
/// </summary>
/// <value>
/// The indicators flag.
/// </value>
public CapWrapper<BoolType> CapIndicators
{
get
{
return _indicators ?? (_indicators = new CapWrapper<BoolType>(this, CapabilityId.CapIndicators, ValueExtensions.ConvertToEnum<BoolType>, value =>
new TWCapability(CapabilityId.CapIndicators, new TWOneValue
{
Item = (uint)value,
ItemType = ItemType.Bool
})));
}
}
private CapWrapper<BoolType> _paperDetectable;
/// <summary>
/// Gets the property to work with paper sensor flag for the current source.
/// </summary>
/// <value>
/// The paper sensor flag.
/// </value>
public CapWrapper<BoolType> CapPaperDetectable
{
get
{
return _paperDetectable ?? (_paperDetectable = new CapWrapper<BoolType>(this, CapabilityId.CapPaperDetectable, ValueExtensions.ConvertToEnum<BoolType>));
}
}
private CapWrapper<BoolType> _uiControllable;
/// <summary>
/// Gets the property to work with UI controllable flag for the current source.
/// </summary>
/// <value>
/// The UI controllable flag.
/// </value>
public CapWrapper<BoolType> CapUIControllable
{
get
{
return _uiControllable ?? (_uiControllable = new CapWrapper<BoolType>(this, CapabilityId.CapUIControllable, ValueExtensions.ConvertToEnum<BoolType>));
}
}
private CapWrapper<BoolType> _devOnline;
/// <summary>
/// Gets the property to work with devince online flag for the current source.
/// </summary>
/// <value>
/// The devince online flag.
/// </value>
public CapWrapper<BoolType> CapDeviceOnline
{
get
{
return _devOnline ?? (_devOnline = new CapWrapper<BoolType>(this, CapabilityId.CapDeviceOnline, ValueExtensions.ConvertToEnum<BoolType>));
}
}
private CapWrapper<BoolType> _thumbsEnabled;
/// <summary>
/// Gets the property to work with thumbnails enabled flag for the current source.
/// </summary>
/// <value>
/// The thumbnails enabled flag.
/// </value>
public CapWrapper<BoolType> CapThumbnailsEnabled
{
get
{
return _thumbsEnabled ?? (_thumbsEnabled = new CapWrapper<BoolType>(this, CapabilityId.CapThumbnailsEnabled, ValueExtensions.ConvertToEnum<BoolType>, value =>
new TWCapability(CapabilityId.CapThumbnailsEnabled, new TWOneValue
{
Item = (uint)value,
ItemType = ItemType.Bool
})));
}
}
private CapWrapper<BoolType> _dsUIonly;
/// <summary>
/// Gets the property to see whether device supports UI only flag (no transfer).
/// </summary>
/// <value>
/// The UI only flag.
/// </value>
public CapWrapper<BoolType> CapEnableDSUIOnly
{
get
{
return _dsUIonly ?? (_dsUIonly = new CapWrapper<BoolType>(this, CapabilityId.CapEnableDSUIOnly, ValueExtensions.ConvertToEnum<BoolType>));
}
}
private CapWrapper<BoolType> _dsData;
/// <summary>
/// Gets the property to see whether device supports custom data triplets.
/// </summary>
/// <value>
/// The custom data flag.
/// </value>
public CapWrapper<BoolType> CapCustomDSData
{
get
{
return _dsData ?? (_dsData = new CapWrapper<BoolType>(this, CapabilityId.CapCustomDSData, ValueExtensions.ConvertToEnum<BoolType>));
}
}
private CapWrapper<JobControl> _jobControl;
/// <summary>
/// Gets the property to work with job control option for the current source.
/// </summary>
/// <value>
/// The job control option.
/// </value>
public CapWrapper<JobControl> CapJobControl
{
get
{
return _jobControl ?? (_jobControl = new CapWrapper<JobControl>(this, CapabilityId.CapJobControl, ValueExtensions.ConvertToEnum<JobControl>, value =>
new TWCapability(CapabilityId.CapJobControl, new TWOneValue
{
Item = (uint)value,
ItemType = ItemType.UInt16
})));
}
}
private CapWrapper<int> _alarmVolume;
/// <summary>
/// Gets the property to work with alarm volume for the current source.
/// </summary>
/// <value>
/// The alarm volume.
/// </value>
public CapWrapper<int> CapAlarmVolume
{
get
{
return _alarmVolume ?? (_alarmVolume = new CapWrapper<int>(this, CapabilityId.CapAlarmVolume, ValueExtensions.ConvertToEnum<int>, value =>
new TWCapability(CapabilityId.CapAlarmVolume, new TWOneValue
{
Item = (uint)value,
ItemType = ItemType.Int32
})));
}
}
//private CapWrapper<int> _autoCapture;
///// <summary>
///// Gets the property to work with auto capture count for the current source.
///// </summary>
///// <value>
///// The auto capture count.
///// </value>
//public CapWrapper<int> CapAutomaticCapture
//{
// get
// {
// return _autoCapture ?? (_autoCapture = new CapWrapper<int>(this, CapabilityId.CapAutomaticCapture, ValueExtensions.ConvertToEnum<int>, value =>
// new TWCapability(CapabilityId.CapAutomaticCapture, new TWOneValue
// {
// Item = (uint)value,
// ItemType = ItemType.Int32
// })));
// }
//}
#endregion

View File

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

View File

@@ -1,10 +1,10 @@
<Application x:Class="Tester.WPF.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Dummy.xaml">
StartupUri="Launcher.xaml">
<Application.Resources>
<ResourceDictionary>
<!-- Dummy Style, anything you won't use goes -->
<!-- Launcher Style, anything you won't use goes -->
<Style TargetType="{x:Type Rectangle}" />
<ResourceDictionary.MergedDictionaries>
@@ -13,7 +13,7 @@
<ResourceDictionary Source="/ModernWPF;component/Themes/ModernStyles.xaml" />
<ResourceDictionary>
<Style x:Key="AppWindow" TargetType="Window" BasedOn="{StaticResource ModernWindow}"/>
<Style x:Key="AppWindow" TargetType="Window" BasedOn="{StaticResource ModernWindowV2}"/>
<Style x:Key="AppListBoxItem" TargetType="ListBoxItem" BasedOn="{StaticResource ModernListBoxItem}">
<Setter Property="BorderThickness" Value="1"/>
<Style.Triggers>

View File

@@ -1,7 +1,8 @@
<Window x:Class="Tester.WPF.Dummy"
<Window x:Class="Tester.WPF.Launcher"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Dummy" Height="300" Width="300">
Title="Scan Launcher" Height="200" Width="250"
ResizeMode="NoResize" Style="{StaticResource AppWindow}">
<Grid>
<StackPanel VerticalAlignment="Center">
<Button Content="Open scan window" Click="Button_Click" Margin="4 0"></Button>

View File

@@ -14,11 +14,11 @@ using System.Windows.Shapes;
namespace Tester.WPF
{
/// <summary>
/// Interaction logic for Dummy.xaml
/// Interaction logic for Launcher.xaml
/// </summary>
public partial class Dummy : Window
public partial class Launcher : Window
{
public Dummy()
public Launcher()
{
InitializeComponent();
}

View File

@@ -2,7 +2,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:modern="http://modernwpf"
Title="TWAIN DS Tester" Height="600" Width="900" ResizeMode="CanResizeWithGrip"
Title="TWAIN Data Source Tester" Height="600" Width="900" ResizeMode="CanResizeWithGrip"
Style="{StaticResource AppWindow}">
<Grid>
<Grid.RowDefinitions>

View File

@@ -23,19 +23,20 @@ namespace Tester.WPF
public MainWindow()
{
InitializeComponent();
if (IntPtr.Size == 8)
{
Title = Title + " (64bit)";
}
else
{
Title = Title + " (32bit)";
}
_twainVM = new TwainVM();
this.DataContext = _twainVM;
if (!DesignerProperties.GetIsInDesignMode(this))
{
if (IntPtr.Size == 8)
{
Title = Title + " (64bit)";
}
else
{
Title = Title + " (32bit)";
}
_twainVM = new TwainVM();
this.DataContext = _twainVM;
Messenger.Default.Register<DialogMessage>(this, msg =>
{
if (Dispatcher.CheckAccess())
@@ -73,6 +74,7 @@ namespace Tester.WPF
// use this for internal msg loop
//var rc = _twainVM.Open();
// use this to hook into current app loop
var rc = _twainVM.Open(new WpfMessageLoopHook(new WindowInteropHelper(this).Handle));
@@ -88,15 +90,6 @@ namespace Tester.WPF
private void SrcList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//var test = new NTwain.Internals.InternalMessageLoopHook();
//test.StartTest();
//test.BeginInvoke(() =>
//{
// Debug.WriteLine("doodle");
// test.StopTest();
//});
if (_twainVM.State == 4)
{
_twainVM.CurrentSource.Close();
@@ -358,7 +351,7 @@ namespace Tester.WPF
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);
break;
case CapabilityId.CapXferCount:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapXferCount.Get();
break;
case CapabilityId.CustomBase:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);

View File

@@ -47,11 +47,13 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\CommonWin32.2.0.5.4\lib\net35-Client\CommonWin32.dll</HintPath>
</Reference>
<Reference Include="GalaSoft.MvvmLight">
<HintPath>..\..\packages\MvvmLightLibs.4.4.32.1\lib\net40\GalaSoft.MvvmLight.dll</HintPath>
<Reference Include="GalaSoft.MvvmLight, Version=4.4.32.16316, Culture=neutral, PublicKeyToken=6bdae7d54059775e, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\MvvmLightLibs.4.4.32.5\lib\net40\GalaSoft.MvvmLight.dll</HintPath>
</Reference>
<Reference Include="GalaSoft.MvvmLight.Extras">
<HintPath>..\..\packages\MvvmLightLibs.4.4.32.1\lib\net40\GalaSoft.MvvmLight.Extras.dll</HintPath>
<Reference Include="GalaSoft.MvvmLight.Extras, Version=4.4.32.16316, Culture=neutral, PublicKeyToken=e607f4f44c21a743, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\MvvmLightLibs.4.4.32.5\lib\net40\GalaSoft.MvvmLight.Extras.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Practices.ServiceLocation, Version=1.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
@@ -59,13 +61,13 @@
</Reference>
<Reference Include="ModernWPF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c99d0cfbea7491ef, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\ModernWPF.1.2.1\lib\net40-Client\ModernWPF.dll</HintPath>
<HintPath>..\..\packages\ModernWPF.1.2.5\lib\net40-Client\ModernWPF.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Windows.Interactivity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\MvvmLightLibs.4.4.32.1\lib\net40\System.Windows.Interactivity.dll</HintPath>
<HintPath>..\..\packages\MvvmLightLibs.4.4.32.5\lib\net40\System.Windows.Interactivity.dll</HintPath>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
@@ -84,11 +86,11 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Dummy.xaml.cs">
<DependentUpon>Dummy.xaml</DependentUpon>
<Compile Include="Launcher.xaml.cs">
<DependentUpon>Launcher.xaml</DependentUpon>
</Compile>
<Compile Include="ViewModels\TwainVM.cs" />
<Page Include="Dummy.xaml">
<Page Include="Launcher.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>

View File

@@ -2,6 +2,6 @@
<packages>
<package id="CommonServiceLocator" version="1.3" targetFramework="net40-Client" />
<package id="CommonWin32" version="2.0.5.4" targetFramework="net40-Client" />
<package id="ModernWPF" version="1.2.1" targetFramework="net40-Client" />
<package id="MvvmLightLibs" version="4.4.32.1" targetFramework="net40-Client" />
<package id="ModernWPF" version="1.2.5" targetFramework="net40-Client" />
<package id="MvvmLightLibs" version="4.4.32.5" targetFramework="net40-Client" />
</packages>