mirror of
https://github.com/soukoku/ntwain.git
synced 2025-12-20 03:59:56 +08:00
Attempt on enable source that doesn't work yet.
This commit is contained in:
13
samples/WinForm32/Form1.Designer.cs
generated
13
samples/WinForm32/Form1.Designer.cs
generated
@@ -42,6 +42,7 @@
|
||||
label3 = new System.Windows.Forms.Label();
|
||||
btnOpenDef = new System.Windows.Forms.Button();
|
||||
btnClose = new System.Windows.Forms.Button();
|
||||
btnShowSettings = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit();
|
||||
splitContainer1.Panel1.SuspendLayout();
|
||||
splitContainer1.Panel2.SuspendLayout();
|
||||
@@ -158,6 +159,7 @@
|
||||
//
|
||||
// splitContainer1.Panel2
|
||||
//
|
||||
splitContainer1.Panel2.Controls.Add(btnShowSettings);
|
||||
splitContainer1.Panel2.Controls.Add(btnClose);
|
||||
splitContainer1.Panel2.Controls.Add(label2);
|
||||
splitContainer1.Panel2.Controls.Add(lblCurrent);
|
||||
@@ -203,6 +205,16 @@
|
||||
btnClose.UseVisualStyleBackColor = true;
|
||||
btnClose.Click += btnClose_Click;
|
||||
//
|
||||
// btnShowSettings
|
||||
//
|
||||
btnShowSettings.Location = new System.Drawing.Point(161, 32);
|
||||
btnShowSettings.Name = "btnShowSettings";
|
||||
btnShowSettings.Size = new System.Drawing.Size(132, 23);
|
||||
btnShowSettings.TabIndex = 5;
|
||||
btnShowSettings.Text = "Show settings only";
|
||||
btnShowSettings.UseVisualStyleBackColor = true;
|
||||
btnShowSettings.Click += btnShowSettings_Click;
|
||||
//
|
||||
// Form1
|
||||
//
|
||||
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
@@ -236,5 +248,6 @@
|
||||
private System.Windows.Forms.Button btnOpenDef;
|
||||
private System.Windows.Forms.Label lblState;
|
||||
private System.Windows.Forms.Label label3;
|
||||
private System.Windows.Forms.Button btnShowSettings;
|
||||
}
|
||||
}
|
||||
@@ -100,5 +100,10 @@ namespace WinForm32
|
||||
|
||||
twain.DGControl.Identity.OpenDS(twain.DefaultSource);
|
||||
}
|
||||
|
||||
private void btnShowSettings_Click(object sender, EventArgs e)
|
||||
{
|
||||
twain.EnableSource(true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,5 +81,12 @@ namespace NTwain.DSM
|
||||
ref TW_IDENTITY_MACOSX origin, ref TW_IDENTITY_MACOSX dest,
|
||||
DG dg, DAT dat, MSG msg, ref DG xfergroup
|
||||
);
|
||||
|
||||
[DllImport(DsmName, CharSet = CharSet.Ansi)]
|
||||
internal static extern ushort DSM_Entry
|
||||
(
|
||||
ref TW_IDENTITY_MACOSX origin, ref TW_IDENTITY_MACOSX dest,
|
||||
DG dg, DAT dat, MSG msg, ref TW_USERINTERFACE userinterface
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,5 +81,12 @@ namespace NTwain.DSM
|
||||
ref TW_IDENTITY_MACOSX origin, ref TW_IDENTITY_MACOSX dest,
|
||||
DG dg, DAT dat, MSG msg, ref DG xfergroup
|
||||
);
|
||||
|
||||
[DllImport(DsmName, CharSet = CharSet.Ansi)]
|
||||
internal static extern ushort DSM_Entry
|
||||
(
|
||||
ref TW_IDENTITY_MACOSX origin, ref TW_IDENTITY_MACOSX dest,
|
||||
DG dg, DAT dat, MSG msg, ref TW_USERINTERFACE userinterface
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,5 +81,12 @@ namespace NTwain.DSM
|
||||
ref TW_IDENTITY_LEGACY origin, ref TW_IDENTITY_LEGACY dest,
|
||||
DG dg, DAT dat, MSG msg, ref DG xfergroup
|
||||
);
|
||||
|
||||
[DllImport(DsmName, CharSet = CharSet.Ansi)]
|
||||
internal static extern ushort DSM_Entry
|
||||
(
|
||||
ref TW_IDENTITY_LEGACY origin, ref TW_IDENTITY_LEGACY dest,
|
||||
DG dg, DAT dat, MSG msg, ref TW_USERINTERFACE userinterface
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,5 +81,12 @@ namespace NTwain.DSM
|
||||
ref TW_IDENTITY_LEGACY origin, ref TW_IDENTITY_LEGACY dest,
|
||||
DG dg, DAT dat, MSG msg, ref DG xfergroup
|
||||
);
|
||||
|
||||
[DllImport(DsmName, CharSet = CharSet.Ansi)]
|
||||
internal static extern ushort DSM_Entry
|
||||
(
|
||||
ref TW_IDENTITY_LEGACY origin, ref TW_IDENTITY_LEGACY dest,
|
||||
DG dg, DAT dat, MSG msg, ref TW_USERINTERFACE userinterface
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
92
src/NTwain/Triplets/ControlDATs/UserInterface.cs
Normal file
92
src/NTwain/Triplets/ControlDATs/UserInterface.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using NTwain.DSM;
|
||||
using TWAINWorkingGroup;
|
||||
|
||||
namespace NTwain.Triplets.ControlDATs
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains calls used with <see cref="DG.CONTROL"/> and <see cref="DAT.USERINTERFACE"/>.
|
||||
/// </summary>
|
||||
public class UserInterface : TripletBase
|
||||
{
|
||||
public UserInterface(TwainSession session) : base(session)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disables source to bring state down to <see cref="STATE.S4"/>.
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public STS DisableDS(ref TW_USERINTERFACE data)
|
||||
{
|
||||
var rc = DoIt(MSG.DISABLEDS, ref data);
|
||||
if (rc == STS.SUCCESS)
|
||||
{
|
||||
Session.State = STATE.S4;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enables source to bring state up to <see cref="STATE.S5"/>.
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public STS EnableDS(ref TW_USERINTERFACE data)
|
||||
{
|
||||
var rc = DoIt(MSG.ENABLEDS, ref data);
|
||||
if (rc == STS.SUCCESS || (data.ShowUI == 0 && rc == STS.CHECKSTATUS))
|
||||
{
|
||||
Session.State = STATE.S5;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enables source to bring state up to <see cref="STATE.S5"/>.
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public STS EnableDSUIOnly(ref TW_USERINTERFACE data)
|
||||
{
|
||||
var rc = DoIt(MSG.ENABLEDSUIONLY, ref data);
|
||||
if (rc == STS.SUCCESS)
|
||||
{
|
||||
Session.State = STATE.S5;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
STS DoIt(MSG msg, ref TW_USERINTERFACE data)
|
||||
{
|
||||
var rc = STS.FAILURE;
|
||||
if (TwainPlatform.IsWindows)
|
||||
{
|
||||
var app = Session.AppIdentity;
|
||||
var ds = Session.CurrentSource;
|
||||
if (TwainPlatform.Is32bit && TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)WinLegacyDSM.DSM_Entry(ref app, ref ds, DG.CONTROL, DAT.USERINTERFACE, msg, ref data);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = (STS)WinNewDSM.DSM_Entry(ref app, ref ds, DG.CONTROL, DAT.USERINTERFACE, msg, ref data);
|
||||
}
|
||||
}
|
||||
else if (TwainPlatform.IsMacOSX)
|
||||
{
|
||||
TW_IDENTITY_MACOSX app = Session.AppIdentity;
|
||||
TW_IDENTITY_MACOSX ds = Session.CurrentSource;
|
||||
if (TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)OSXLegacyDSM.DSM_Entry(ref app, ref ds, DG.CONTROL, DAT.USERINTERFACE, msg, ref data);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = (STS)OSXNewDSM.DSM_Entry(ref app, ref ds, DG.CONTROL, DAT.USERINTERFACE, msg, ref data);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,5 +41,8 @@ namespace NTwain.Triplets
|
||||
private XferGroup? _xferGroup;
|
||||
public XferGroup XferGroup => _xferGroup ??= new XferGroup(Session);
|
||||
|
||||
private UserInterface? _userInterface;
|
||||
public UserInterface UserInterface => _userInterface ??= new UserInterface(Session);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ namespace NTwain.Triplets
|
||||
/// <exception cref="System.ArgumentNullException"></exception>
|
||||
public TripletBase(TwainSession session)
|
||||
{
|
||||
Session = session ?? throw new ArgumentNullException("session");
|
||||
Session = session ?? throw new ArgumentNullException(nameof(session));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using TWAINWorkingGroup;
|
||||
|
||||
@@ -55,6 +56,7 @@ namespace NTwain
|
||||
IntPtr twnull
|
||||
)
|
||||
{
|
||||
Debug.WriteLine($"Legacy callback got {msg}");
|
||||
HandleSourceMsg(msg);
|
||||
return (ushort)STS.SUCCESS;
|
||||
}
|
||||
@@ -69,6 +71,7 @@ namespace NTwain
|
||||
IntPtr twnull
|
||||
)
|
||||
{
|
||||
Debug.WriteLine($"OSX callback got {msg}");
|
||||
HandleSourceMsg(msg);
|
||||
return (ushort)STS.SUCCESS;
|
||||
}
|
||||
@@ -82,10 +85,17 @@ namespace NTwain
|
||||
case MSG.DEVICEEVENT:
|
||||
break;
|
||||
case MSG.CLOSEDSOK:
|
||||
DisableSource();
|
||||
break;
|
||||
case MSG.CLOSEDSREQ:
|
||||
DisableSource();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void HandleWin32Message(uint msg)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,5 +21,37 @@ namespace NTwain
|
||||
rc = DGControl.Identity.GetNext(out ds);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enables the currently open source.
|
||||
/// </summary>
|
||||
/// <param name="showUI">Whether to show driver interface.</param>
|
||||
/// <param name="uiOnly">If true try to display only driver dialog (no capture).
|
||||
/// Otherwise capturing will begin after this.</param>
|
||||
/// <returns></returns>
|
||||
public STS EnableSource(bool showUI, bool uiOnly)
|
||||
{
|
||||
var ui = new TW_USERINTERFACE
|
||||
{
|
||||
ShowUI = (ushort)((showUI || uiOnly) ? 1 : 0),
|
||||
hParent = _hwnd,
|
||||
};
|
||||
var rc = uiOnly ? DGControl.UserInterface.EnableDSUIOnly(ref ui) : DGControl.UserInterface.EnableDS(ref ui);
|
||||
if (rc == STS.SUCCESS || (!uiOnly && !showUI && rc == STS.CHECKSTATUS))
|
||||
{
|
||||
// keep it around for disable use
|
||||
_userInterface = ui;
|
||||
};
|
||||
return rc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disables the currently enabled source.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public STS DisableSource()
|
||||
{
|
||||
return DGControl.UserInterface.DisableDS(ref _userInterface);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,6 +87,7 @@ namespace NTwain
|
||||
}
|
||||
|
||||
internal IntPtr _hwnd;
|
||||
internal TW_USERINTERFACE _userInterface;
|
||||
|
||||
/// <summary>
|
||||
/// Tries to bring the TWAIN session down to some state.
|
||||
@@ -102,6 +103,9 @@ namespace NTwain
|
||||
|
||||
switch (State)
|
||||
{
|
||||
case STATE.S5:
|
||||
DGControl.UserInterface.DisableDS(ref _userInterface);
|
||||
break;
|
||||
case STATE.S4:
|
||||
DGControl.Identity.CloseDS();
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user