From b4c3ebd549426dfe6072d0fafe848b3e6357b7ee Mon Sep 17 00:00:00 2001 From: soukoku Date: Sat, 8 Nov 2014 08:58:27 -0500 Subject: [PATCH] More cap wrapper. --- NTwain/CapWrapper.cs | 93 ++++++-- NTwain/DataSource.Caps.cs | 349 ++++++++++++++++++++-------- NTwain/ICapWrapper.cs | 34 ++- Tests/Tester.WPF/MainWindow.xaml.cs | 16 +- 4 files changed, 370 insertions(+), 122 deletions(-) diff --git a/NTwain/CapWrapper.cs b/NTwain/CapWrapper.cs index 0db258a..224adf7 100644 --- a/NTwain/CapWrapper.cs +++ b/NTwain/CapWrapper.cs @@ -24,9 +24,9 @@ namespace NTwain ICapControl _source; - Func _convertRoutine; + Func _getConvertRoutine; Func _setCustomRoutine; - Func _setProvider; // an simplified way to set() that only needs on cap value + Func _setOneValueFunc; /// /// Initializes a new instance of the class. @@ -46,7 +46,7 @@ namespace NTwain if (getConversionRoutine == null) { throw new ArgumentNullException("valueConversionRoutine"); } _source = source; - _convertRoutine = getConversionRoutine; + _getConvertRoutine = getConversionRoutine; Capability = capability; SupportedActions = source.CapQuerySupport(capability); } @@ -68,15 +68,15 @@ namespace NTwain /// public CapWrapper(ICapControl source, CapabilityId capability, Func getConversionRoutine, - Func setValueProvider) + Func setValueProvider) { if (source == null) { throw new ArgumentNullException("source"); } if (getConversionRoutine == null) { throw new ArgumentNullException("valueConversionRoutine"); } if (setValueProvider == null) { throw new ArgumentNullException("setValueProvider"); } _source = source; - _convertRoutine = getConversionRoutine; - _setProvider = setValueProvider; + _getConvertRoutine = getConversionRoutine; + _setOneValueFunc = setValueProvider; Capability = capability; SupportedActions = source.CapQuerySupport(capability); } @@ -104,7 +104,7 @@ namespace NTwain if (setValueRoutine == null) { throw new ArgumentNullException("setValueRoutine"); } _source = source; - _convertRoutine = getConversionRoutine; + _getConvertRoutine = getConversionRoutine; _setCustomRoutine = setValueRoutine; Capability = capability; SupportedActions = source.CapQuerySupport(capability); @@ -206,13 +206,13 @@ namespace NTwain /// public bool CanSet { get { return Supports(QuerySupports.Set); } } - ///// - ///// Gets a value indicating whether is supported. - ///// - ///// - ///// true if this capability can set constraint; otherwise, false. - ///// - //public bool CanSetConstraint { get { return Supports(QuerySupports.SetConstraint); } } + /// + /// Gets a value indicating whether is supported. + /// + /// + /// true if this capability can set constraint; otherwise, false. + /// + public bool CanSetConstraint { get { return Supports(QuerySupports.SetConstraint); } } #endregion @@ -226,7 +226,7 @@ namespace NTwain { if (CanGetDefault) { - return _convertRoutine(_source.CapGetDefault(Capability)); + return _getConvertRoutine(_source.CapGetDefault(Capability)); } return default(TValue); } @@ -239,7 +239,7 @@ namespace NTwain { if (CanGetCurrent) { - return _convertRoutine(_source.CapGetCurrent(Capability)); + return _getConvertRoutine(_source.CapGetCurrent(Capability)); } return default(TValue); } @@ -252,7 +252,7 @@ namespace NTwain { if (CanGet) { - return _source.CapGet(Capability).Select(o => _convertRoutine(o)).ToList(); + return _source.CapGet(Capability).Select(o => _getConvertRoutine(o)).ToList(); } return new List(); } @@ -350,7 +350,7 @@ namespace NTwain } /// - /// Sets the current value of this capability. + /// Simplified version that sets the current value of this capability. /// /// The value. /// @@ -363,9 +363,9 @@ namespace NTwain { rc = _setCustomRoutine(value); } - else if (_setProvider != null) + else if (_setOneValueFunc != null) { - using (var cap = _setProvider(value)) + using (var cap = new TWCapability(Capability, _setOneValueFunc(value))) { rc = _source.DGControl.Capability.Set(cap); } @@ -374,6 +374,59 @@ namespace NTwain return rc; } + /// + /// Sets the constraint value of this capability. + /// + /// The value. + /// + public ReturnCode SetConstraint(TWOneValue value) + { + ReturnCode rc = ReturnCode.Failure; + if (CanSetConstraint) + { + using (var cap = new TWCapability(Capability, value)) + { + rc = _source.DGControl.Capability.SetConstraint(cap); + } + } + return rc; + } + + /// + /// Sets the constraint value of this capability. + /// + /// The value. + /// + public ReturnCode SetConstraint(TWEnumeration value) + { + ReturnCode rc = ReturnCode.Failure; + if (CanSetConstraint) + { + using (var cap = new TWCapability(Capability, value)) + { + rc = _source.DGControl.Capability.SetConstraint(cap); + } + } + return rc; + } + + /// + /// Sets the constraint value of this capability. + /// + /// The value. + /// + public ReturnCode SetConstraint(TWRange value) + { + ReturnCode rc = ReturnCode.Failure; + if (CanSetConstraint) + { + using (var cap = new TWCapability(Capability, value)) + { + rc = _source.DGControl.Capability.SetConstraint(cap); + } + } + return rc; + } #endregion } diff --git a/NTwain/DataSource.Caps.cs b/NTwain/DataSource.Caps.cs index 23e0faa..7528a6b 100644 --- a/NTwain/DataSource.Caps.cs +++ b/NTwain/DataSource.Caps.cs @@ -183,11 +183,11 @@ namespace NTwain get { return _audXferMech ?? (_audXferMech = new CapWrapper(this, CapabilityId.ACapXferMech, ValueExtensions.ConvertToEnum, - value => new TWCapability(CapabilityId.ACapXferMech, new TWOneValue + value => new TWOneValue { Item = (uint)value, ItemType = ItemType.UInt16 - }))); + })); } } @@ -210,11 +210,11 @@ namespace NTwain get { return _compression ?? (_compression = new CapWrapper(this, CapabilityId.ICapCompression, ValueExtensions.ConvertToEnum, - value => new TWCapability(CapabilityId.ICapCompression, new TWOneValue + value => new TWOneValue { Item = (uint)value, ItemType = ItemType.UInt16 - }))); + })); } } @@ -232,11 +232,11 @@ namespace NTwain get { return _pixelType ?? (_pixelType = new CapWrapper(this, CapabilityId.ICapPixelType, ValueExtensions.ConvertToEnum, - value => new TWCapability(CapabilityId.ICapPixelType, new TWOneValue + value => new TWOneValue { Item = (uint)value, ItemType = ItemType.UInt16 - }))); + })); } } @@ -253,11 +253,11 @@ namespace NTwain get { return _imgUnits ?? (_imgUnits = new CapWrapper(this, CapabilityId.ICapUnits, ValueExtensions.ConvertToEnum, - value => new TWCapability(CapabilityId.ICapUnits, new TWOneValue + value => new TWOneValue { Item = (uint)value, ItemType = ItemType.UInt16 - }))); + })); } } @@ -274,17 +274,16 @@ namespace NTwain get { return _imgXferMech ?? (_imgXferMech = new CapWrapper(this, CapabilityId.ICapXferMech, ValueExtensions.ConvertToEnum, - value => new TWCapability(CapabilityId.ICapXferMech, new TWOneValue + value => new TWOneValue { Item = (uint)value, ItemType = ItemType.UInt16 - }))); + })); } } #endregion - private CapWrapper _autoBright; /// @@ -297,12 +296,12 @@ namespace NTwain { get { - return _autoBright ?? (_autoBright = new CapWrapper(this, CapabilityId.ICapAutoBright, ValueExtensions.ConvertToEnum, value => - new TWCapability(CapabilityId.ICapAutoBright, new TWOneValue + return _autoBright ?? (_autoBright = new CapWrapper(this, CapabilityId.ICapAutoBright, ValueExtensions.ConvertToEnum, + value => new TWOneValue { Item = (uint)value, ItemType = ItemType.Bool - }))); + })); } } @@ -319,11 +318,11 @@ namespace NTwain get { return _brightness ?? (_brightness = new CapWrapper(this, CapabilityId.ICapBrightness, ValueExtensions.ConvertToFix32, - value => new TWCapability(CapabilityId.ICapBrightness, new TWOneValue + value => new TWOneValue { Item = (uint)value,// ((uint)dpi) << 16; ItemType = ItemType.Fix32 - }))); + })); } } @@ -340,11 +339,11 @@ namespace NTwain get { return _contrast ?? (_contrast = new CapWrapper(this, CapabilityId.ICapContrast, ValueExtensions.ConvertToFix32, - value => new TWCapability(CapabilityId.ICapContrast, new TWOneValue + value => new TWOneValue { Item = (uint)value,// ((uint)dpi) << 16; ItemType = ItemType.Fix32 - }))); + })); } } @@ -363,15 +362,14 @@ namespace NTwain get { return _exposureTime ?? (_exposureTime = new CapWrapper(this, CapabilityId.ICapExposureTime, ValueExtensions.ConvertToFix32, - value => new TWCapability(CapabilityId.ICapExposureTime, new TWOneValue + value => new TWOneValue { Item = (uint)value,// ((uint)dpi) << 16; ItemType = ItemType.Fix32 - }))); + })); } } - - + private CapWrapper _imgFilter; /// @@ -385,11 +383,11 @@ namespace NTwain get { return _imgFilter ?? (_imgFilter = new CapWrapper(this, CapabilityId.ICapFilter, ValueExtensions.ConvertToEnum, - value => new TWCapability(CapabilityId.ICapFilter, new TWOneValue + value => new TWOneValue { Item = (uint)value, ItemType = ItemType.UInt16 - }))); + })); } } @@ -406,11 +404,11 @@ namespace NTwain get { return _gamma ?? (_gamma = new CapWrapper(this, CapabilityId.ICapGamma, ValueExtensions.ConvertToFix32, - value => new TWCapability(CapabilityId.ICapGamma, new TWOneValue + value => new TWOneValue { Item = (uint)value,// ((uint)dpi) << 16; ItemType = ItemType.Fix32 - }))); + })); } } @@ -429,15 +427,14 @@ namespace NTwain get { return _highlight ?? (_highlight = new CapWrapper(this, CapabilityId.ICapHighlight, ValueExtensions.ConvertToFix32, - value => new TWCapability(CapabilityId.ICapHighlight, new TWOneValue + value => new TWOneValue { Item = (uint)value,// ((uint)dpi) << 16; ItemType = ItemType.Fix32 - }))); + })); } } - - + private CapWrapper _fileFormat; /// @@ -451,11 +448,11 @@ namespace NTwain get { return _fileFormat ?? (_fileFormat = new CapWrapper(this, CapabilityId.ICapImageFileFormat, ValueExtensions.ConvertToEnum, - value => new TWCapability(CapabilityId.ICapImageFileFormat, new TWOneValue + value => new TWOneValue { Item = (uint)value, ItemType = ItemType.UInt16 - }))); + })); } } @@ -472,16 +469,15 @@ namespace NTwain { get { - return _lampState ?? (_lampState = new CapWrapper(this, CapabilityId.ICapLampState, ValueExtensions.ConvertToEnum, value => - new TWCapability(CapabilityId.ICapLampState, new TWOneValue + return _lampState ?? (_lampState = new CapWrapper(this, CapabilityId.ICapLampState, ValueExtensions.ConvertToEnum, + value => new TWOneValue { Item = (uint)value, ItemType = ItemType.Bool - }))); + })); } } - - + private CapWrapper _lightSource; /// @@ -494,16 +490,15 @@ namespace NTwain { get { - return _lightSource ?? (_lightSource = new CapWrapper(this, CapabilityId.ICapLightSource, ValueExtensions.ConvertToEnum, value => - new TWCapability(CapabilityId.ICapLightSource, new TWOneValue + return _lightSource ?? (_lightSource = new CapWrapper(this, CapabilityId.ICapLightSource, ValueExtensions.ConvertToEnum, + value => new TWOneValue { Item = (uint)value, ItemType = ItemType.UInt16 - }))); + })); } } - - + private CapWrapper _orientation; /// @@ -516,12 +511,12 @@ namespace NTwain { get { - return _orientation ?? (_orientation = new CapWrapper(this, CapabilityId.ICapOrientation, ValueExtensions.ConvertToEnum, value => - new TWCapability(CapabilityId.ICapOrientation, new TWOneValue + return _orientation ?? (_orientation = new CapWrapper(this, CapabilityId.ICapOrientation, ValueExtensions.ConvertToEnum, + value => new TWOneValue { Item = (uint)value, ItemType = ItemType.UInt16 - }))); + })); } } @@ -570,11 +565,11 @@ namespace NTwain get { return _shadow ?? (_shadow = new CapWrapper(this, CapabilityId.ICapShadow, ValueExtensions.ConvertToFix32, - value => new TWCapability(CapabilityId.ICapShadow, new TWOneValue + value => new TWOneValue { Item = (uint)value,// ((uint)dpi) << 16; ItemType = ItemType.Fix32 - }))); + })); } } @@ -611,8 +606,7 @@ namespace NTwain return _nativeYRes ?? (_nativeYRes = new CapWrapper(this, CapabilityId.ICapYNativeResolution, ValueExtensions.ConvertToFix32)); } } - - + private CapWrapper _xResolution; /// @@ -626,11 +620,11 @@ namespace NTwain get { return _xResolution ?? (_xResolution = new CapWrapper(this, CapabilityId.ICapXResolution, ValueExtensions.ConvertToFix32, - value => new TWCapability(CapabilityId.ICapXResolution, new TWOneValue + value => new TWOneValue { Item = (uint)value,// ((uint)dpi) << 16; ItemType = ItemType.Fix32 - }))); + })); } } @@ -648,13 +642,182 @@ namespace NTwain get { return _yResolution ?? (_yResolution = new CapWrapper(this, CapabilityId.ICapYResolution, ValueExtensions.ConvertToFix32, - value => new TWCapability(CapabilityId.ICapYResolution, new TWOneValue + value => new TWOneValue { Item = (uint)value,// ((uint)dpi) << 16; ItemType = ItemType.Fix32 - }))); + })); } } + + private CapWrapper _maxFrames; + + /// + /// Gets the property to work with image max frames for the current source. + /// + /// + /// The image max frames. + /// + public ICapWrapper CapImageMaxFrames + { + get + { + return _maxFrames ?? (_maxFrames = new CapWrapper(this, CapabilityId.ICapMaxFrames, ValueExtensions.ConvertToEnum, + value => new TWOneValue + { + Item = (uint)value, + ItemType = ItemType.UInt16 + })); + } + } + + private CapWrapper _tiles; + + /// + /// Gets the property to work with image tiles flag for the current source. + /// + /// + /// The image tiles flag. + /// + public ICapWrapper CapImageTiles + { + get + { + return _tiles ?? (_tiles = new CapWrapper(this, CapabilityId.ICapTiles, ValueExtensions.ConvertToEnum, + value => new TWOneValue + { + Item = (uint)value, + ItemType = ItemType.Bool + })); + } + } + + private CapWrapper _bitOrder; + + /// + /// Gets the property to work with image for the current source. + /// + /// + /// The image bit order. + /// + public ICapWrapper CapImageBitOrder + { + get + { + return _bitOrder ?? (_bitOrder = new CapWrapper(this, CapabilityId.ICapBitOrder, ValueExtensions.ConvertToEnum, + value => new TWOneValue + { + Item = (uint)value, + ItemType = ItemType.UInt16 + })); + } + } + + private CapWrapper _ccittKFactor; + + /// + /// Gets the property to work with image CCITT K factor for the current source. + /// + /// + /// The image CCITT K factor. + /// + public ICapWrapper CapImageCCITTKFactor + { + get + { + return _ccittKFactor ?? (_ccittKFactor = new CapWrapper(this, CapabilityId.ICapCCITTKFactor, ValueExtensions.ConvertToEnum, + value => new TWOneValue + { + Item = (uint)value, + ItemType = ItemType.UInt16 + })); + } + } + + private CapWrapper _lightPath; + + /// + /// Gets the property to work with image light path for the current source. + /// + /// + /// The image light path. + /// + public ICapWrapper CapImageLightPath + { + get + { + return _lightPath ?? (_lightPath = new CapWrapper(this, CapabilityId.ICapLightPath, ValueExtensions.ConvertToEnum, + value => new TWOneValue + { + Item = (uint)value, + ItemType = ItemType.UInt16 + })); + } + } + + private CapWrapper _pixelFlavor; + + /// + /// Gets the property to work with image pixel flavor for the current source. + /// + /// + /// The image pixel flavor. + /// + public ICapWrapper CapImagePixelFlavor + { + get + { + return _pixelFlavor ?? (_pixelFlavor = new CapWrapper(this, CapabilityId.ICapPixelFlavor, ValueExtensions.ConvertToEnum, + value => new TWOneValue + { + Item = (uint)value, + ItemType = ItemType.UInt16 + })); + } + } + + private CapWrapper _planarChunky; + + /// + /// Gets the property to work with image color format for the current source. + /// + /// + /// The image color format. + /// + public ICapWrapper CapImagePlanarChunky + { + get + { + return _planarChunky ?? (_planarChunky = new CapWrapper(this, CapabilityId.ICapPlanarChunky, ValueExtensions.ConvertToEnum, + value => new TWOneValue + { + Item = (uint)value, + ItemType = ItemType.UInt16 + })); + } + } + + private CapWrapper _rotation; + + /// + /// Gets the property to work with image rotation for the current source. + /// + /// + /// The image rotation. + /// + public ICapWrapper CapImageRotation + { + get + { + return _rotation ?? (_rotation = new CapWrapper(this, CapabilityId.ICapRotation, ValueExtensions.ConvertToFix32, + value => new TWOneValue + { + Item = (uint)value,// ((uint)dpi) << 16; + ItemType = ItemType.Fix32 + })); + } + } + private CapWrapper _supportSize; @@ -669,11 +832,11 @@ namespace NTwain get { return _supportSize ?? (_supportSize = new CapWrapper(this, CapabilityId.ICapSupportedSizes, ValueExtensions.ConvertToEnum, - value => new TWCapability(CapabilityId.ICapSupportedSizes, new TWOneValue + value => new TWOneValue { Item = (uint)value, ItemType = ItemType.UInt16 - }))); + })); } } @@ -690,12 +853,12 @@ namespace NTwain { get { - return _autoDeskew ?? (_autoDeskew = new CapWrapper(this, CapabilityId.ICapAutomaticDeskew, ValueExtensions.ConvertToEnum, value => - new TWCapability(CapabilityId.ICapAutomaticDeskew, new TWOneValue + return _autoDeskew ?? (_autoDeskew = new CapWrapper(this, CapabilityId.ICapAutomaticDeskew, ValueExtensions.ConvertToEnum, + value => new TWOneValue { Item = (uint)value, ItemType = ItemType.Bool - }))); + })); } } @@ -712,12 +875,12 @@ namespace NTwain { get { - return _autoRotate ?? (_autoRotate = new CapWrapper(this, CapabilityId.ICapAutomaticRotate, ValueExtensions.ConvertToEnum, value => - new TWCapability(CapabilityId.ICapAutomaticRotate, new TWOneValue + return _autoRotate ?? (_autoRotate = new CapWrapper(this, CapabilityId.ICapAutomaticRotate, ValueExtensions.ConvertToEnum, + value => new TWOneValue { Item = (uint)value, ItemType = ItemType.Bool - }))); + })); } } @@ -734,7 +897,8 @@ 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; @@ -776,12 +940,12 @@ namespace NTwain { get { - return _xferCount ?? (_xferCount = new CapWrapper(this, CapabilityId.CapXferCount, ValueExtensions.ConvertToEnum, value => - new TWCapability(CapabilityId.CapXferCount, new TWOneValue + return _xferCount ?? (_xferCount = new CapWrapper(this, CapabilityId.CapXferCount, ValueExtensions.ConvertToEnum, + value => new TWOneValue { Item = value > 0 ? (uint)value : uint.MaxValue, ItemType = ItemType.UInt16 - }))); + })); } } @@ -816,12 +980,12 @@ namespace NTwain { get { - return _duplexEnabled ?? (_duplexEnabled = new CapWrapper(this, CapabilityId.CapDuplexEnabled, ValueExtensions.ConvertToEnum, value => - new TWCapability(CapabilityId.CapDuplexEnabled, new TWOneValue + return _duplexEnabled ?? (_duplexEnabled = new CapWrapper(this, CapabilityId.CapDuplexEnabled, ValueExtensions.ConvertToEnum, + value => new TWOneValue { Item = (uint)value, ItemType = ItemType.Bool - }))); + })); } } @@ -853,7 +1017,8 @@ namespace NTwain { get { - return _feederEnabled ?? (_feederEnabled = new CapWrapper(this, CapabilityId.CapFeederEnabled, ValueExtensions.ConvertToEnum, value => + return _feederEnabled ?? (_feederEnabled = new CapWrapper(this, CapabilityId.CapFeederEnabled, ValueExtensions.ConvertToEnum, + value => { var rc = ReturnCode.Failure; @@ -906,12 +1071,12 @@ namespace NTwain { get { - return _clearPage ?? (_clearPage = new CapWrapper(this, CapabilityId.CapClearPage, ValueExtensions.ConvertToEnum, value => - new TWCapability(CapabilityId.CapClearPage, new TWOneValue + return _clearPage ?? (_clearPage = new CapWrapper(this, CapabilityId.CapClearPage, ValueExtensions.ConvertToEnum, + value => new TWOneValue { Item = (uint)value, ItemType = ItemType.Bool - }))); + })); } } @@ -927,12 +1092,12 @@ namespace NTwain { get { - return _feedPage ?? (_feedPage = new CapWrapper(this, CapabilityId.CapFeedPage, ValueExtensions.ConvertToEnum, value => - new TWCapability(CapabilityId.CapFeedPage, new TWOneValue + return _feedPage ?? (_feedPage = new CapWrapper(this, CapabilityId.CapFeedPage, ValueExtensions.ConvertToEnum, + value => new TWOneValue { Item = (uint)value, ItemType = ItemType.Bool - }))); + })); } } @@ -948,12 +1113,12 @@ namespace NTwain { get { - return _rewindPage ?? (_rewindPage = new CapWrapper(this, CapabilityId.CapRewindPage, ValueExtensions.ConvertToEnum, value => - new TWCapability(CapabilityId.CapRewindPage, new TWOneValue + return _rewindPage ?? (_rewindPage = new CapWrapper(this, CapabilityId.CapRewindPage, ValueExtensions.ConvertToEnum, + value => new TWOneValue { Item = (uint)value, ItemType = ItemType.Bool - }))); + })); } } @@ -969,12 +1134,12 @@ namespace NTwain { get { - return _indicators ?? (_indicators = new CapWrapper(this, CapabilityId.CapIndicators, ValueExtensions.ConvertToEnum, value => - new TWCapability(CapabilityId.CapIndicators, new TWOneValue + return _indicators ?? (_indicators = new CapWrapper(this, CapabilityId.CapIndicators, ValueExtensions.ConvertToEnum, + value => new TWOneValue { Item = (uint)value, ItemType = ItemType.Bool - }))); + })); } } @@ -1038,12 +1203,12 @@ namespace NTwain { get { - return _thumbsEnabled ?? (_thumbsEnabled = new CapWrapper(this, CapabilityId.CapThumbnailsEnabled, ValueExtensions.ConvertToEnum, value => - new TWCapability(CapabilityId.CapThumbnailsEnabled, new TWOneValue + return _thumbsEnabled ?? (_thumbsEnabled = new CapWrapper(this, CapabilityId.CapThumbnailsEnabled, ValueExtensions.ConvertToEnum, + value => new TWOneValue { Item = (uint)value, ItemType = ItemType.Bool - }))); + })); } } @@ -1091,12 +1256,12 @@ namespace NTwain { get { - return _jobControl ?? (_jobControl = new CapWrapper(this, CapabilityId.CapJobControl, ValueExtensions.ConvertToEnum, value => - new TWCapability(CapabilityId.CapJobControl, new TWOneValue + return _jobControl ?? (_jobControl = new CapWrapper(this, CapabilityId.CapJobControl, ValueExtensions.ConvertToEnum, + value => new TWOneValue { Item = (uint)value, ItemType = ItemType.UInt16 - }))); + })); } } @@ -1112,12 +1277,12 @@ namespace NTwain { get { - return _alarmVolume ?? (_alarmVolume = new CapWrapper(this, CapabilityId.CapAlarmVolume, ValueExtensions.ConvertToEnum, value => - new TWCapability(CapabilityId.CapAlarmVolume, new TWOneValue + return _alarmVolume ?? (_alarmVolume = new CapWrapper(this, CapabilityId.CapAlarmVolume, ValueExtensions.ConvertToEnum, + value => new TWOneValue { Item = (uint)value, ItemType = ItemType.Int32 - }))); + })); } } @@ -1133,12 +1298,12 @@ namespace NTwain //{ // get // { - // return _autoCapture ?? (_autoCapture = new CapWrapper(this, CapabilityId.CapAutomaticCapture, ValueExtensions.ConvertToEnum, value => + // return _autoCapture ?? (_autoCapture = new CapWrapper(this, CapabilityId.CapAutomaticCapture, ValueExtensions.ConvertToEnum, // new TWCapability(CapabilityId.CapAutomaticCapture, new TWOneValue // { // Item = (uint)value, // ItemType = ItemType.Int32 - // }))); + // })); // } //} diff --git a/NTwain/ICapWrapper.cs b/NTwain/ICapWrapper.cs index 540d11a..4f9b10f 100644 --- a/NTwain/ICapWrapper.cs +++ b/NTwain/ICapWrapper.cs @@ -1,4 +1,5 @@ -using System; +using NTwain.Data; +using System; namespace NTwain { @@ -139,6 +140,14 @@ namespace NTwain /// bool CanSet { get; } + /// + /// Gets a value indicating whether is supported. + /// + /// + /// true if this capability can set constraint; otherwise, false. + /// + bool CanSetConstraint { get; } + /// /// Resets the current value to power-on default. /// @@ -146,10 +155,31 @@ namespace NTwain NTwain.Data.ReturnCode Reset(); /// - /// Sets the current value of this capability. + /// Simplified version that sets the current value of this capability. /// /// The value. /// NTwain.Data.ReturnCode Set(TValue value); + + /// + /// Sets the constraint value of this capability. + /// + /// The value. + /// + ReturnCode SetConstraint(TWOneValue value); + + /// + /// Sets the constraint value of this capability. + /// + /// The value. + /// + ReturnCode SetConstraint(TWEnumeration value); + + /// + /// Sets the constraint value of this capability. + /// + /// The value. + /// + ReturnCode SetConstraint(TWRange value); } } diff --git a/Tests/Tester.WPF/MainWindow.xaml.cs b/Tests/Tester.WPF/MainWindow.xaml.cs index 36de105..6fa7ac6 100644 --- a/Tests/Tester.WPF/MainWindow.xaml.cs +++ b/Tests/Tester.WPF/MainWindow.xaml.cs @@ -411,7 +411,7 @@ namespace Tester.WPF CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap).CastToEnum(); break; case CapabilityId.ICapBitOrder: - CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap).CastToEnum(); + CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageBitOrder.Get(); break; case CapabilityId.ICapBitOrderCodes: CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap); @@ -420,7 +420,7 @@ namespace Tester.WPF CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageBrightness.Get(); break; case CapabilityId.ICapCCITTKFactor: - CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap); + CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageCCITTKFactor.Get(); break; case CapabilityId.ICapColorManagementEnabled: CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap); @@ -501,13 +501,13 @@ namespace Tester.WPF CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageLameState.Get(); break; case CapabilityId.ICapLightPath: - CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap).CastToEnum(); + CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageLightPath.Get(); break; case CapabilityId.ICapLightSource: CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageLightSource.Get(); break; case CapabilityId.ICapMaxFrames: - CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap); + CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageMaxFrames.Get(); break; case CapabilityId.ICapMinimumHeight: CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap); @@ -553,7 +553,7 @@ namespace Tester.WPF CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImagePhysicalWidth.Get(); break; case CapabilityId.ICapPixelFlavor: - CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap).CastToEnum(); + CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImagePixelFlavor.Get(); break; case CapabilityId.ICapPixelFlavorCodes: CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap); @@ -562,10 +562,10 @@ namespace Tester.WPF CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImagePixelType.Get(); break; case CapabilityId.ICapPlanarChunky: - CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap).CastToEnum(); + CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImagePlanarChunky.Get(); break; case CapabilityId.ICapRotation: - CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap).CastToEnum(); + CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageRotation.Get(); break; case CapabilityId.ICapShadow: CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageShadow.Get(); @@ -586,7 +586,7 @@ namespace Tester.WPF CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap); break; case CapabilityId.ICapTiles: - CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap); + CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageTiles.Get(); break; case CapabilityId.ICapTimeFill: CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);