From 57d7dbe0ef9596e3a731752af145403bb28e48dd Mon Sep 17 00:00:00 2001 From: soukoku Date: Wed, 24 Sep 2014 21:52:28 -0400 Subject: [PATCH] Started adding more wrapped caps. --- NTwain/CapWrapper.cs | 27 ++ NTwain/DataSource.Caps.cs | 309 +++++++++++++++++- NTwain/Properties/VersionInfo.cs | 2 +- Tests/Tester.WPF/App.xaml | 6 +- .../Tester.WPF/{Dummy.xaml => Launcher.xaml} | 5 +- .../{Dummy.xaml.cs => Launcher.xaml.cs} | 6 +- Tests/Tester.WPF/MainWindow.xaml | 2 +- Tests/Tester.WPF/MainWindow.xaml.cs | 35 +- Tests/Tester.WPF/Tester.WPF.csproj | 20 +- Tests/Tester.WPF/packages.config | 4 +- 10 files changed, 371 insertions(+), 45 deletions(-) rename Tests/Tester.WPF/{Dummy.xaml => Launcher.xaml} (75%) rename Tests/Tester.WPF/{Dummy.xaml.cs => Launcher.xaml.cs} (83%) diff --git a/NTwain/CapWrapper.cs b/NTwain/CapWrapper.cs index 0f54c80..0654422 100644 --- a/NTwain/CapWrapper.cs +++ b/NTwain/CapWrapper.cs @@ -6,6 +6,9 @@ using System.Text; namespace NTwain { + //TODO: handle multi-value sets + + /// /// Wrapped class for reading/writing a TWAIN capability associated with a . /// @@ -25,6 +28,30 @@ namespace NTwain Func _setCustomRoutine; Func _setProvider; // an simplified way to set() that only needs on cap value + /// + /// Initializes a new instance of the class. + /// + /// The source. + /// The capability. + /// The value conversion routine in Get methods. + /// + /// source + /// or + /// valueConversionRoutine + /// + public CapWrapper(ICapControl source, CapabilityId capability, + Func 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); + } + + /// /// Initializes a new instance of the class. /// diff --git a/NTwain/DataSource.Caps.cs b/NTwain/DataSource.Caps.cs index 86d5d4d..6ba98ed 100644 --- a/NTwain/DataSource.Caps.cs +++ b/NTwain/DataSource.Caps.cs @@ -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 _imgUnits; + + /// + /// Gets the property to work with image for the current source. + /// + /// + /// The image unit of measure. + /// + public CapWrapper CapImageUnits + { + get + { + return _imgUnits ?? (_imgUnits = new CapWrapper(this, CapabilityId.ICapUnits, ValueExtensions.ConvertToEnum, + value => new TWCapability(CapabilityId.ICapUnits, new TWOneValue + { + Item = (uint)value, + ItemType = ItemType.UInt16 + }))); + } + } + private CapWrapper _imgXferMech; /// @@ -322,7 +346,7 @@ namespace NTwain get { return _autoDeskew ?? (_autoDeskew = new CapWrapper(this, CapabilityId.ICapAutomaticDeskew, ValueExtensions.ConvertToEnum, 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(this, CapabilityId.ICapAutomaticBorderDetection, ValueExtensions.ConvertToEnum, value => + return _borderDetect ?? (_borderDetect = new CapWrapper(this, CapabilityId.ICapAutomaticBorderDetection, ValueExtensions.ConvertToEnum, value => { var rc = ReturnCode.Failure; @@ -437,6 +461,22 @@ namespace NTwain #region other caps + private CapWrapper _duplex; + + /// + /// Gets the property to see what's the duplex mode for the current source. + /// + /// + /// The duplex mode. + /// + public CapWrapper CapDuplex + { + get + { + return _duplex ?? (_duplex = new CapWrapper(this, CapabilityId.CapDuplex, ValueExtensions.ConvertToEnum)); + } + } + private CapWrapper _duplexEnabled; /// @@ -480,6 +520,21 @@ namespace NTwain } } + private CapWrapper _feederLoaded; + + /// + /// Gets the property to work with feeder loaded flag for the current source. + /// + /// + /// The feeder loaded flag. + /// + public CapWrapper CapFeederLoaded + { + get + { + return _feederLoaded ?? (_feederLoaded = new CapWrapper(this, CapabilityId.CapFeederLoaded, ValueExtensions.ConvertToEnum)); + } + } private CapWrapper _feederEnabled; @@ -534,6 +589,254 @@ namespace NTwain } } + private CapWrapper _clearPage; + + /// + /// Gets the property to work with clear page flag for the current source. + /// + /// + /// The clear page flag. + /// + public CapWrapper CapClearPage + { + get + { + return _clearPage ?? (_clearPage = new CapWrapper(this, CapabilityId.CapClearPage, ValueExtensions.ConvertToEnum, value => + new TWCapability(CapabilityId.CapClearPage, new TWOneValue + { + Item = (uint)value, + ItemType = ItemType.Bool + }))); + } + } + + private CapWrapper _feedPage; + + /// + /// Gets the property to work with feed page flag for the current source. + /// + /// + /// The feed page flag. + /// + public CapWrapper CapFeedPage + { + get + { + return _feedPage ?? (_feedPage = new CapWrapper(this, CapabilityId.CapFeedPage, ValueExtensions.ConvertToEnum, value => + new TWCapability(CapabilityId.CapFeedPage, new TWOneValue + { + Item = (uint)value, + ItemType = ItemType.Bool + }))); + } + } + + private CapWrapper _rewindPage; + + /// + /// Gets the property to work with rewind page flag for the current source. + /// + /// + /// The rewind page flag. + /// + public CapWrapper CapRewindPage + { + get + { + return _rewindPage ?? (_rewindPage = new CapWrapper(this, CapabilityId.CapRewindPage, ValueExtensions.ConvertToEnum, value => + new TWCapability(CapabilityId.CapRewindPage, new TWOneValue + { + Item = (uint)value, + ItemType = ItemType.Bool + }))); + } + } + + private CapWrapper _indicators; + + /// + /// Gets the property to work with indicators flag for the current source. + /// + /// + /// The indicators flag. + /// + public CapWrapper CapIndicators + { + get + { + return _indicators ?? (_indicators = new CapWrapper(this, CapabilityId.CapIndicators, ValueExtensions.ConvertToEnum, value => + new TWCapability(CapabilityId.CapIndicators, new TWOneValue + { + Item = (uint)value, + ItemType = ItemType.Bool + }))); + } + } + + private CapWrapper _paperDetectable; + + /// + /// Gets the property to work with paper sensor flag for the current source. + /// + /// + /// The paper sensor flag. + /// + public CapWrapper CapPaperDetectable + { + get + { + return _paperDetectable ?? (_paperDetectable = new CapWrapper(this, CapabilityId.CapPaperDetectable, ValueExtensions.ConvertToEnum)); + } + } + + private CapWrapper _uiControllable; + + /// + /// Gets the property to work with UI controllable flag for the current source. + /// + /// + /// The UI controllable flag. + /// + public CapWrapper CapUIControllable + { + get + { + return _uiControllable ?? (_uiControllable = new CapWrapper(this, CapabilityId.CapUIControllable, ValueExtensions.ConvertToEnum)); + } + } + + private CapWrapper _devOnline; + + /// + /// Gets the property to work with devince online flag for the current source. + /// + /// + /// The devince online flag. + /// + public CapWrapper CapDeviceOnline + { + get + { + return _devOnline ?? (_devOnline = new CapWrapper(this, CapabilityId.CapDeviceOnline, ValueExtensions.ConvertToEnum)); + } + } + + private CapWrapper _thumbsEnabled; + + /// + /// Gets the property to work with thumbnails enabled flag for the current source. + /// + /// + /// The thumbnails enabled flag. + /// + public CapWrapper CapThumbnailsEnabled + { + get + { + return _thumbsEnabled ?? (_thumbsEnabled = new CapWrapper(this, CapabilityId.CapThumbnailsEnabled, ValueExtensions.ConvertToEnum, value => + new TWCapability(CapabilityId.CapThumbnailsEnabled, new TWOneValue + { + Item = (uint)value, + ItemType = ItemType.Bool + }))); + } + } + + private CapWrapper _dsUIonly; + + /// + /// Gets the property to see whether device supports UI only flag (no transfer). + /// + /// + /// The UI only flag. + /// + public CapWrapper CapEnableDSUIOnly + { + get + { + return _dsUIonly ?? (_dsUIonly = new CapWrapper(this, CapabilityId.CapEnableDSUIOnly, ValueExtensions.ConvertToEnum)); + } + } + + private CapWrapper _dsData; + + /// + /// Gets the property to see whether device supports custom data triplets. + /// + /// + /// The custom data flag. + /// + public CapWrapper CapCustomDSData + { + get + { + return _dsData ?? (_dsData = new CapWrapper(this, CapabilityId.CapCustomDSData, ValueExtensions.ConvertToEnum)); + } + } + + private CapWrapper _jobControl; + + /// + /// Gets the property to work with job control option for the current source. + /// + /// + /// The job control option. + /// + public CapWrapper CapJobControl + { + get + { + return _jobControl ?? (_jobControl = new CapWrapper(this, CapabilityId.CapJobControl, ValueExtensions.ConvertToEnum, value => + new TWCapability(CapabilityId.CapJobControl, new TWOneValue + { + Item = (uint)value, + ItemType = ItemType.UInt16 + }))); + } + } + + private CapWrapper _alarmVolume; + + /// + /// Gets the property to work with alarm volume for the current source. + /// + /// + /// The alarm volume. + /// + public CapWrapper CapAlarmVolume + { + get + { + return _alarmVolume ?? (_alarmVolume = new CapWrapper(this, CapabilityId.CapAlarmVolume, ValueExtensions.ConvertToEnum, value => + new TWCapability(CapabilityId.CapAlarmVolume, new TWOneValue + { + Item = (uint)value, + ItemType = ItemType.Int32 + }))); + } + } + + //private CapWrapper _autoCapture; + + ///// + ///// Gets the property to work with auto capture count for the current source. + ///// + ///// + ///// The auto capture count. + ///// + //public CapWrapper CapAutomaticCapture + //{ + // get + // { + // return _autoCapture ?? (_autoCapture = new CapWrapper(this, CapabilityId.CapAutomaticCapture, ValueExtensions.ConvertToEnum, value => + // new TWCapability(CapabilityId.CapAutomaticCapture, new TWOneValue + // { + // Item = (uint)value, + // ItemType = ItemType.Int32 + // }))); + // } + //} + #endregion diff --git a/NTwain/Properties/VersionInfo.cs b/NTwain/Properties/VersionInfo.cs index 1aef18c..4238b8b 100644 --- a/NTwain/Properties/VersionInfo.cs +++ b/NTwain/Properties/VersionInfo.cs @@ -23,7 +23,7 @@ namespace NTwain /// /// The build release version number. /// - 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 } diff --git a/Tests/Tester.WPF/App.xaml b/Tests/Tester.WPF/App.xaml index 9ea9427..baa24a5 100644 --- a/Tests/Tester.WPF/App.xaml +++ b/Tests/Tester.WPF/App.xaml @@ -1,10 +1,10 @@  + StartupUri="Launcher.xaml"> - +