Expanded source disabled event args.

This commit is contained in:
Eugene Wang
2018-11-17 12:45:30 -05:00
parent 751f885949
commit 0605610665
6 changed files with 46 additions and 24 deletions

View File

@@ -0,0 +1,34 @@
using NTwain.Data;
using System;
namespace NTwain
{
/// <summary>
/// Contains data for a TWAIN source event.
/// </summary>
public class DeviceEventArgs : EventArgs
{
/// <summary>
/// Gets the detailed device event.
/// </summary>
public TW_DEVICEEVENT Data { get; internal set; }
}
/// <summary>
/// Contains data when data source came down from being enabled.
/// </summary>
public class SourceDisabledEventArgs : EventArgs
{
/// <summary>
/// Gets the affected source.
/// </summary>
public DataSource Source { get; internal set; }
/// <summary>
/// Whether the source was enabled with UI-only (no transfer).
/// The app could do something different if this is <code>true</code>, such as
/// getting the <see cref="TW_CUSTOMDSDATA"/>.
/// </summary>
public bool UIOnly { get; internal set; }
}
}

View File

@@ -980,14 +980,14 @@ namespace NTwain.Data
/// <summary>
/// Allows for a data source and application to pass custom data to each other.
/// </summary>
partial struct TW_CUSTOMDSDATA
public partial struct TW_CUSTOMDSDATA
{
/// <summary>
/// Length, in bytes, of data.
/// </summary>
public uint InfoLength { get { return _infoLength; } set { _infoLength = value; } }
/// <summary>
/// Handle to memory containing InfoLength bytes of data.
/// Handle to memory containing <see cref="InfoLength"/> bytes of data.
/// </summary>
public IntPtr Data { get { return _hData; } set { _hData = value; } }
}

View File

@@ -1,17 +0,0 @@
using NTwain.Data;
using System;
namespace NTwain
{
/// <summary>
/// Contains data for a TWAIN source event.
/// </summary>
public class DeviceEventArgs : EventArgs
{
/// <summary>
/// Gets the detailed device event.
/// </summary>
/// <value>The device event.</value>
public TW_DEVICEEVENT Data { get; internal set; }
}
}

View File

@@ -10,7 +10,7 @@ namespace NTwain.Triplets.Control
{
internal UserInterface(TwainSession session) : base(session) { }
public ReturnCode DisableDS(ref TW_USERINTERFACE ui)
public ReturnCode DisableDS(ref TW_USERINTERFACE ui, bool wasUIonly)
{
var rc = ReturnCode.Failure;
@@ -42,7 +42,11 @@ namespace NTwain.Triplets.Control
if (rc == ReturnCode.Success)
{
Session.State = TwainState.S4;
Session.OnSourceDisabled(EventArgs.Empty);
Session.OnSourceDisabled(new SourceDisabledEventArgs
{
Source = Session.CurrentSource,
UIOnly = wasUIonly
});
}
return rc;
}

View File

@@ -35,9 +35,10 @@ namespace NTwain
DoTransferRoutine();
break;
case Message.CloseDSReq:
DGControl.UserInterface.DisableDS(ref _lastEnableUI);
DGControl.UserInterface.DisableDS(ref _lastEnableUI, false);
break;
case Message.CloseDSOK:
DGControl.UserInterface.DisableDS(ref _lastEnableUI, true);
break;
}
}

View File

@@ -50,13 +50,13 @@ namespace NTwain
/// <summary>
/// Occurs when an enabled source has been disabled (back to state 4).
/// </summary>
public event EventHandler SourceDisabled;
public event EventHandler<SourceDisabledEventArgs> SourceDisabled;
/// <summary>
/// Raises the <see cref="SourceDisabled"/> event.
/// </summary>
/// <param name="e"></param>
internal protected virtual void OnSourceDisabled(EventArgs e)
internal protected virtual void OnSourceDisabled(SourceDisabledEventArgs e)
{
var handler = SourceDisabled;
handler?.Invoke(this, e);