Skip to content

Commit

Permalink
Add "Show native TWAIN progress" compat option
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanfish committed Feb 18, 2024
1 parent 91717d1 commit 3304325
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 5 deletions.
7 changes: 6 additions & 1 deletion NAPS2.Lib/EtoForms/Ui/AdvancedProfileForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class AdvancedProfileForm : EtoDialogBase
});

private readonly DropDown _twainImpl = C.EnumDropDown<TwainImpl>();
private readonly CheckBox _twainProgress = new() { Text = UiStrings.ShowNativeTwainProgress };
private readonly Button _restoreDefaults = new() { Text = UiStrings.RestoreDefaults };

public AdvancedProfileForm(Naps2Config config) : base(config)
Expand Down Expand Up @@ -88,7 +89,8 @@ protected override void BuildLayout()
PlatformCompat.System.IsWiaDriverSupported ? C.Label(UiStrings.WiaVersionLabel) : C.None(),
PlatformCompat.System.IsWiaDriverSupported ? _wiaVersion : C.None(),
PlatformCompat.System.IsTwainDriverSupported ? C.Label(UiStrings.TwainImplLabel) : C.None(),
PlatformCompat.System.IsTwainDriverSupported ? _twainImpl : C.None()
PlatformCompat.System.IsTwainDriverSupported ? _twainImpl : C.None(),
PlatformCompat.System.IsTwainDriverSupported ? _twainProgress : C.None()
)
),
L.Row(
Expand All @@ -113,6 +115,7 @@ private void UpdateValues(ScanProfile scanProfile)
_cropToPageSize.Checked = scanProfile.ForcePageSizeCrop;
_flipDuplexed.Checked = scanProfile.FlipDuplexedPages;
_twainImpl.SelectedIndex = (int) scanProfile.TwainImpl;
_twainProgress.Checked = scanProfile.TwainProgress;
_excludeBlank.Checked = scanProfile.ExcludeBlankPages;
_whiteThreshold.IntValue = scanProfile.BlankPageWhiteThreshold;
_coverageThreshold.IntValue = scanProfile.BlankPageCoverageThreshold;
Expand All @@ -121,6 +124,7 @@ private void UpdateValues(ScanProfile scanProfile)
private void UpdateEnabled()
{
_twainImpl.Enabled = ScanProfile!.DriverName == DriverNames.TWAIN;
_twainProgress.Enabled = ScanProfile!.DriverName == DriverNames.TWAIN;
_offsetWidth.Enabled = ScanProfile.DriverName == DriverNames.WIA;
_wiaVersion.Enabled = ScanProfile.DriverName == DriverNames.WIA;
_quality.Enabled = !_maximumQuality.IsChecked();
Expand Down Expand Up @@ -148,6 +152,7 @@ private void SaveSettings()
{
ScanProfile.TwainImpl = (TwainImpl) _twainImpl.SelectedIndex;
}
ScanProfile.TwainProgress = _twainProgress.IsChecked();
ScanProfile.ExcludeBlankPages = _excludeBlank.IsChecked();
ScanProfile.BlankPageWhiteThreshold = _whiteThreshold.IntValue;
ScanProfile.BlankPageCoverageThreshold = _coverageThreshold.IntValue;
Expand Down
1 change: 1 addition & 0 deletions NAPS2.Lib/EtoForms/Ui/EditProfileForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ private void SaveSettings()
ForcePageSizeCrop = ScanProfile.ForcePageSizeCrop,
FlipDuplexedPages = ScanProfile.FlipDuplexedPages,
TwainImpl = ScanProfile.TwainImpl,
TwainProgress = ScanProfile.TwainProgress,

ExcludeBlankPages = ScanProfile.ExcludeBlankPages,
BlankPageWhiteThreshold = ScanProfile.BlankPageWhiteThreshold,
Expand Down
9 changes: 9 additions & 0 deletions NAPS2.Lib/Lang/Resources/UiStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions NAPS2.Lib/Lang/Resources/UiStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -870,4 +870,7 @@
<data name="OcrMultiLangFormTitle" xml:space="preserve">
<value>Multiple Languages</value>
</data>
<data name="ShowNativeTwainProgress" xml:space="preserve">
<value>Show native TWAIN progress</value>
</data>
</root>
4 changes: 3 additions & 1 deletion NAPS2.Lib/Scan/ScanPerformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ private void HandleError(Exception error)
private void ShowOperation(ScanOperation op, ScanOptions scanOptions, ScanParams scanParams)
{
bool isWia10 = scanOptions.Driver == Driver.Wia && scanOptions.WiaOptions.WiaApiVersion == WiaApiVersion.Wia10;
if (scanParams.NoUI || scanOptions.UseNativeUI && !isWia10)
bool showingTwainProgress = scanOptions.Driver == Driver.Twain && scanOptions.TwainOptions.ShowProgress;
if (scanParams.NoUI || scanOptions.UseNativeUI && !isWia10 || showingTwainProgress)
{
return;
}
Expand Down Expand Up @@ -233,6 +234,7 @@ private ScanOptions BuildOptions(ScanProfile scanProfile, ScanParams scanParams,
TransferMode = scanProfile.TwainImpl is TwainImpl.Default or TwainImpl.MemXfer
? TwainTransferMode.Memory
: TwainTransferMode.Native,
ShowProgress = scanProfile.TwainProgress,
IncludeWiaDevices = false
// TODO: Consider adding a user option for TwainOptions.ShowProgress instead of our progress window
},
Expand Down
2 changes: 2 additions & 0 deletions NAPS2.Lib/Scan/ScanProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public ScanProfile Clone()

public TwainImpl TwainImpl { get; set; }

public bool TwainProgress { get; set; }

public bool ExcludeBlankPages { get; set; }

public int BlankPageWhiteThreshold { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion NAPS2.Sdk/Scan/Internal/Twain/TwainScanDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Task Scan(ScanOptions options, CancellationToken cancelToken, IScanEvents

private void EnableWindow(ScanOptions options)
{
if (options.DialogParent != IntPtr.Zero && options.UseNativeUI)
if (options.DialogParent != IntPtr.Zero && (options.UseNativeUI || options.TwainOptions.ShowProgress))
{
// At the Windows API level, a modal window is implemented by doing two things:
// 1. Setting the parent on the child window
Expand Down
4 changes: 2 additions & 2 deletions NAPS2.Sdk/Scan/Internal/Twain/TwainSessionScanRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void Init()
try
{
_logger.LogDebug("NAPS2.TW - Opening session");
var dsmHandle = _handleManager.GetDsmHandle(_options.DialogParent, _options.UseNativeUI);
var dsmHandle = _handleManager.GetDsmHandle(_options.DialogParent, _options.UseNativeUI || _options.TwainOptions.ShowProgress);
#if NET6_0_OR_GREATER

if (!OperatingSystem.IsWindows()) throw new InvalidOperationException("Windows-only");
Expand Down Expand Up @@ -99,7 +99,7 @@ private void Init()

_logger.LogDebug("NAPS2.TW - Enabling source");
var ui = _options.UseNativeUI ? SourceEnableMode.ShowUI : SourceEnableMode.NoUI;
var enableHandle = _handleManager.GetEnableHandle(_options.DialogParent, _options.UseNativeUI);
var enableHandle = _handleManager.GetEnableHandle(_options.DialogParent, _options.UseNativeUI || _options.TwainOptions.ShowProgress);
// Note that according to the twain spec, on Windows it is recommended to set the modal parameter to false
rc = _source.Enable(ui, false, enableHandle);
if (rc != ReturnCode.Success)
Expand Down

0 comments on commit 3304325

Please sign in to comment.