mirror of
https://github.com/soukoku/ntwain.git
synced 2025-09-19 10:08:00 +08:00
Added wrapping methods to userinterface triplets.
This commit is contained in:
@@ -21,6 +21,7 @@ namespace ConsoleApp
|
||||
using (var session = new TwainSession(config))
|
||||
{
|
||||
session.PropertyChanged += Session_PropertyChanged;
|
||||
session.SourceDisabled += Session_SourceDisabled;
|
||||
|
||||
if (session.Open(IntPtr.Zero) == NTwain.Data.ReturnCode.Success)
|
||||
{
|
||||
@@ -67,17 +68,24 @@ namespace ConsoleApp
|
||||
Console.ReadLine();
|
||||
}
|
||||
|
||||
private static void TestThisSource(TwainSession session, DataSource targetSrc)
|
||||
private static void Session_SourceDisabled(object sender, EventArgs e)
|
||||
{
|
||||
Console.WriteLine($"Testing data source {targetSrc}");
|
||||
var session = (TwainSession)sender;
|
||||
Console.WriteLine($"Session source disabled.");
|
||||
session.CurrentSource.Close();
|
||||
}
|
||||
|
||||
private static void TestThisSource(TwainSession session, DataSource source)
|
||||
{
|
||||
Console.WriteLine($"Testing data source {source}");
|
||||
Console.WriteLine();
|
||||
|
||||
targetSrc.Open();
|
||||
source.Open();
|
||||
|
||||
var testStatus = session.GetStatus();
|
||||
var testMessage = session.GetLocalizedStatus(ref testStatus);
|
||||
|
||||
targetSrc.Close();
|
||||
var rc = source.ShowUI(IntPtr.Zero);
|
||||
}
|
||||
|
||||
private static void Session_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
|
@@ -532,9 +532,9 @@ namespace NTwain.Data
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
||||
partial struct TW_USERINTERFACE
|
||||
{
|
||||
TW_BOOL _showUI;
|
||||
TW_BOOL _modalUI;
|
||||
TW_HANDLE _hParent;
|
||||
public TW_BOOL ShowUI;
|
||||
public TW_BOOL ModalUI;
|
||||
public TW_HANDLE hParent;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
||||
|
@@ -2267,43 +2267,6 @@ namespace NTwain.Data
|
||||
public uint ReceiveSize { get => _ReceiveSize; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This structure is used to handle the user interface coordination between an application and a
|
||||
/// Source.
|
||||
/// </summary>
|
||||
partial struct TW_USERINTERFACE
|
||||
{
|
||||
/// <summary>
|
||||
/// Set to TRUE by the application if the Source should activate its built-in user
|
||||
/// interface. Otherwise, set to FALSE. Note that not all sources support ShowUI =
|
||||
/// FALSE.
|
||||
/// </summary>
|
||||
public bool ShowUI
|
||||
{
|
||||
get { return _showUI > 0; }
|
||||
set { _showUI = value ? TwainConst.True : TwainConst.False; }
|
||||
}
|
||||
/// <summary>
|
||||
/// If ShowUI is TRUE, then an application setting this to TRUE requests the Source to
|
||||
/// run Modal.
|
||||
/// </summary>
|
||||
public bool ModalUI
|
||||
{
|
||||
//get { return _modalUI > 0; }
|
||||
set { _modalUI = value ? TwainConst.True : TwainConst.False; }
|
||||
}
|
||||
/// <summary>
|
||||
/// Microsoft Windows only: Application’s window handle. The Source designates
|
||||
/// the hWnd as its parent when creating the Source dialog.
|
||||
/// </summary>
|
||||
public IntPtr Parent
|
||||
{
|
||||
//get { return _hParent; }
|
||||
set { _hParent = value; }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Provides entry points required by TWAIN 2.0 Applications and Sources.
|
||||
/// </summary>
|
||||
|
@@ -34,6 +34,50 @@ namespace NTwain
|
||||
/// <returns></returns>
|
||||
public ReturnCode Close() => Session.DGControl.Identity.CloseDS(Identity32);
|
||||
|
||||
/// <summary>
|
||||
/// Showing driver configuration UI if supported.
|
||||
/// </summary>
|
||||
/// <param name="windowHandle">The parent window handle if on Windows. Use <see cref="IntPtr.Zero"/> if not applicable.</param>
|
||||
/// <param name="modal">if set to <c>true</c> the driver UI may be displayed as modal.</param>
|
||||
/// <returns></returns>
|
||||
public ReturnCode ShowUI(IntPtr windowHandle, bool modal = false)
|
||||
{
|
||||
var ui = new TW_USERINTERFACE
|
||||
{
|
||||
ShowUI = 1,
|
||||
ModalUI = (ushort)(modal ? 1 : 0),
|
||||
hParent = windowHandle
|
||||
};
|
||||
var rc = Session.DGControl.UserInterface.EnableDSUIOnly(ref ui);
|
||||
if (rc == ReturnCode.Success)
|
||||
{
|
||||
Session._lastEnableUI = ui;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enables the source for transferring data.
|
||||
/// </summary>
|
||||
/// <param name="showUI">if set to <c>true</c> then show driver UI. Not all sources support turning UI off.</param>
|
||||
/// <param name="windowHandle">The parent window handle if on Windows. Use <see cref="IntPtr.Zero"/> if not applicable.</param>
|
||||
/// <param name="modal">if set to <c>true</c> any driver UI may be displayed as modal.</param>
|
||||
/// <returns></returns>
|
||||
public ReturnCode Enable(bool showUI, IntPtr windowHandle, bool modal = false)
|
||||
{
|
||||
var ui = new TW_USERINTERFACE
|
||||
{
|
||||
ShowUI = (ushort)(showUI ? 1 : 0),
|
||||
ModalUI = (ushort)(modal ? 1 : 0),
|
||||
hParent = windowHandle
|
||||
};
|
||||
var rc = Session.DGControl.UserInterface.EnableDS(ref ui);
|
||||
if (rc == ReturnCode.Success)
|
||||
{
|
||||
Session._lastEnableUI = ui;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the source status. Useful after getting a non-success return code.
|
||||
|
@@ -42,6 +42,7 @@ namespace NTwain.Triplets.Control
|
||||
if (rc == ReturnCode.Success)
|
||||
{
|
||||
Session.State = TwainState.S4;
|
||||
Session.OnSourceDisabled(EventArgs.Empty);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
@@ -79,7 +80,7 @@ namespace NTwain.Triplets.Control
|
||||
}
|
||||
|
||||
if (!(rc == ReturnCode.Success &&
|
||||
(!ui.ShowUI && rc == ReturnCode.CheckStatus)))
|
||||
(ui.ShowUI == 0 && rc == ReturnCode.CheckStatus)))
|
||||
{
|
||||
Session.State = TwainState.S4;
|
||||
}
|
||||
|
@@ -13,6 +13,8 @@ namespace NTwain
|
||||
{
|
||||
partial class TwainSession
|
||||
{
|
||||
internal TW_USERINTERFACE _lastEnableUI;
|
||||
|
||||
private void HandleSourceMsg(Message msg)
|
||||
{
|
||||
switch (msg)
|
||||
@@ -26,12 +28,23 @@ namespace NTwain
|
||||
}
|
||||
break;
|
||||
case Message.XferReady:
|
||||
if (State < TwainState.S6)
|
||||
{
|
||||
State = TwainState.S6;
|
||||
}
|
||||
DoTransferRoutine();
|
||||
break;
|
||||
case Message.CloseDSReq:
|
||||
DGControl.UserInterface.DisableDS(ref _lastEnableUI);
|
||||
break;
|
||||
case Message.CloseDSOK:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void DoTransferRoutine()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -47,6 +47,20 @@ namespace NTwain
|
||||
///// </summary>
|
||||
//public DGCustom DGCustom { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when an enabled source has been disabled (back to state 4).
|
||||
/// </summary>
|
||||
public event EventHandler SourceDisabled;
|
||||
|
||||
/// <summary>
|
||||
/// Raises the <see cref="SourceDisabled"/> event.
|
||||
/// </summary>
|
||||
/// <param name="e"></param>
|
||||
internal protected virtual void OnSourceDisabled(EventArgs e)
|
||||
{
|
||||
var handler = SourceDisabled;
|
||||
handler?.Invoke(this, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the source has generated an event.
|
||||
|
Reference in New Issue
Block a user