mirror of
https://github.com/soukoku/ntwain.git
synced 2025-11-24 08:47:06 +08:00
Added basic device event handling.
This commit is contained in:
17
src/NTwain/DeviceEventArgs.cs
Normal file
17
src/NTwain/DeviceEventArgs.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
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; }
|
||||
}
|
||||
}
|
||||
16
src/NTwain/Triplets/DGControl.DeviceEvent.cs
Normal file
16
src/NTwain/Triplets/DGControl.DeviceEvent.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using NTwain.Data;
|
||||
using NTwain.Internals;
|
||||
|
||||
namespace NTwain.Triplets
|
||||
{
|
||||
sealed class DeviceEvent : BaseTriplet
|
||||
{
|
||||
internal DeviceEvent(TwainSession session) : base(session) { }
|
||||
|
||||
public ReturnCode Get(ref TW_DEVICEEVENT sourceDeviceEvent)
|
||||
{
|
||||
return NativeMethods.DsmWin32(Session.Config.AppWin32, Session.CurrentSource.Identity,
|
||||
DataGroups.Control, DataArgumentType.DeviceEvent, Message.Get, ref sourceDeviceEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,5 +30,8 @@ namespace NTwain.Triplets
|
||||
|
||||
Status _status;
|
||||
internal Status Status => _status ?? (_status = new Status(Session));
|
||||
|
||||
DeviceEvent _devEvent;
|
||||
internal DeviceEvent DeviceEvent => _devEvent ?? (_devEvent = new DeviceEvent(Session));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,23 @@ namespace NTwain
|
||||
{
|
||||
private void HandleSourceMsg(Message msg)
|
||||
{
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case Message.DeviceEvent:
|
||||
TW_DEVICEEVENT de = default;
|
||||
var rc = DGControl.DeviceEvent.Get(ref de);
|
||||
if (rc == ReturnCode.Success)
|
||||
{
|
||||
OnDeviceEvent(new DeviceEventArgs { Data = de });
|
||||
}
|
||||
break;
|
||||
case Message.XferReady:
|
||||
break;
|
||||
case Message.CloseDSReq:
|
||||
break;
|
||||
case Message.CloseDSOK:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,26 @@ namespace NTwain
|
||||
public DGCustom DGCustom { get; set; }
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the source has generated an event.
|
||||
/// </summary>
|
||||
public event EventHandler<DeviceEventArgs> DeviceEvent;
|
||||
|
||||
/// <summary>
|
||||
/// Raises the <see cref="DeviceEvent"/> event.
|
||||
/// </summary>
|
||||
/// <param name="e"></param>
|
||||
protected virtual void OnDeviceEvent(DeviceEventArgs e)
|
||||
{
|
||||
OnDeviceEvent(e);
|
||||
DeviceEvent?.Invoke(this, e);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when a property value changes.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user