mirror of
https://github.com/soukoku/ntwain.git
synced 2026-02-25 13:04:07 +08:00
Moved triplet success logic back to twainsession to reduce dependencies and identity copying in windows.
This commit is contained in:
@@ -18,13 +18,13 @@ namespace SampleConsole
|
||||
twain.StateChanged += Twain_StateChanged;
|
||||
|
||||
var hwnd = IntPtr.Zero; // required for windows
|
||||
var rc = twain.DGControl.Parent.OpenDSM(ref hwnd);
|
||||
var rc = twain.OpenDSM(hwnd);
|
||||
Debug.WriteLine($"OpenDSM={rc}");
|
||||
|
||||
if (rc == STS.SUCCESS)
|
||||
{
|
||||
Debug.WriteLine($"CloseDSM={rc}");
|
||||
rc = twain.DGControl.Parent.CloseDSM(ref hwnd);
|
||||
rc = twain.CloseDSM();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace WinForm32
|
||||
|
||||
|
||||
var hwnd = this.Handle;
|
||||
var rc = twain.DGControl.Parent.OpenDSM(ref hwnd);
|
||||
var rc = twain.OpenDSM(hwnd);
|
||||
Debug.WriteLine($"OpenDSM={rc}");
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace WinForm32
|
||||
|
||||
private void btnSelect_Click(object sender, EventArgs e)
|
||||
{
|
||||
twain.DGControl.Identity.UserSelect();
|
||||
twain.ShowUserSelect();
|
||||
}
|
||||
|
||||
private void btnEnumSources_Click(object sender, EventArgs e)
|
||||
@@ -75,7 +75,7 @@ namespace WinForm32
|
||||
{
|
||||
if (listSources.SelectedItem is TW_IDENTITY_LEGACY ds)
|
||||
{
|
||||
twain.DGControl.Identity.Set(ds);
|
||||
twain.SetDefaultSource(ds);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,20 +85,20 @@ namespace WinForm32
|
||||
{
|
||||
twain.TryStepdown(STATE.S3);
|
||||
|
||||
twain.DGControl.Identity.OpenDS(ds);
|
||||
twain.OpenSource(ds);
|
||||
}
|
||||
}
|
||||
|
||||
private void btnClose_Click(object sender, EventArgs e)
|
||||
{
|
||||
twain.DGControl.Identity.CloseDS();
|
||||
twain.CloseSource();
|
||||
}
|
||||
|
||||
private void btnOpenDef_Click(object sender, EventArgs e)
|
||||
{
|
||||
twain.TryStepdown(STATE.S3);
|
||||
|
||||
twain.DGControl.Identity.OpenDS(twain.DefaultSource);
|
||||
twain.OpenSource(twain.DefaultSource);
|
||||
}
|
||||
|
||||
private void btnShowSettings_Click(object sender, EventArgs e)
|
||||
|
||||
@@ -6,49 +6,38 @@ namespace NTwain.Triplets.ControlDATs
|
||||
/// <summary>
|
||||
/// Contains calls used with <see cref="DG.CONTROL"/> and <see cref="DAT.CALLBACK"/>.
|
||||
/// </summary>
|
||||
public class Callback : TripletBase
|
||||
public class Callback
|
||||
{
|
||||
public Callback(TwainSession session) : base(session)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers the callback function.
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public STS RegisterCallback(ref TW_CALLBACK data)
|
||||
{
|
||||
return DoIt(MSG.REGISTER_CALLBACK, ref data);
|
||||
}
|
||||
|
||||
STS DoIt(MSG msg, ref TW_CALLBACK data)
|
||||
public STS RegisterCallback(ref TW_IDENTITY_LEGACY app, ref TW_IDENTITY_LEGACY ds, ref TW_CALLBACK 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.CALLBACK, msg, ref data);
|
||||
rc = (STS)WinLegacyDSM.DSM_Entry(ref app, ref ds, DG.CONTROL, DAT.CALLBACK, MSG.REGISTER_CALLBACK, ref data);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = (STS)WinNewDSM.DSM_Entry(ref app, ref ds, DG.CONTROL, DAT.CALLBACK, msg, ref data);
|
||||
rc = (STS)WinNewDSM.DSM_Entry(ref app, ref ds, DG.CONTROL, DAT.CALLBACK, MSG.REGISTER_CALLBACK, ref data);
|
||||
}
|
||||
}
|
||||
else if (TwainPlatform.IsMacOSX)
|
||||
{
|
||||
TW_IDENTITY_MACOSX app = Session.AppIdentity;
|
||||
TW_IDENTITY_MACOSX ds = Session.CurrentSource;
|
||||
TW_IDENTITY_MACOSX app2 = app;
|
||||
TW_IDENTITY_MACOSX ds2 = ds;
|
||||
if (TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)OSXLegacyDSM.DSM_Entry(ref app, ref ds, DG.CONTROL, DAT.CALLBACK, msg, ref data);
|
||||
rc = (STS)OSXLegacyDSM.DSM_Entry(ref app2, ref ds2, DG.CONTROL, DAT.CALLBACK, MSG.REGISTER_CALLBACK, ref data);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = (STS)OSXNewDSM.DSM_Entry(ref app, ref ds, DG.CONTROL, DAT.CALLBACK, msg, ref data);
|
||||
rc = (STS)OSXNewDSM.DSM_Entry(ref app2, ref ds2, DG.CONTROL, DAT.CALLBACK, MSG.REGISTER_CALLBACK, ref data);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
|
||||
@@ -6,49 +6,38 @@ namespace NTwain.Triplets.ControlDATs
|
||||
/// <summary>
|
||||
/// Contains calls used with <see cref="DG.CONTROL"/> and <see cref="DAT.CALLBACK2"/>.
|
||||
/// </summary>
|
||||
public class Callback2 : TripletBase
|
||||
public class Callback2
|
||||
{
|
||||
public Callback2(TwainSession session) : base(session)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers the callback function.
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public STS RegisterCallback(ref TW_CALLBACK2 data)
|
||||
{
|
||||
return DoIt(MSG.REGISTER_CALLBACK, ref data);
|
||||
}
|
||||
|
||||
STS DoIt(MSG msg, ref TW_CALLBACK2 data)
|
||||
public STS RegisterCallback(ref TW_IDENTITY_LEGACY app, ref TW_IDENTITY_LEGACY ds, ref TW_CALLBACK2 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.CALLBACK2, msg, ref data);
|
||||
rc = (STS)WinLegacyDSM.DSM_Entry(ref app, ref ds, DG.CONTROL, DAT.CALLBACK2, MSG.REGISTER_CALLBACK, ref data);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = (STS)WinNewDSM.DSM_Entry(ref app, ref ds, DG.CONTROL, DAT.CALLBACK2, msg, ref data);
|
||||
rc = (STS)WinNewDSM.DSM_Entry(ref app, ref ds, DG.CONTROL, DAT.CALLBACK2, MSG.REGISTER_CALLBACK, ref data);
|
||||
}
|
||||
}
|
||||
else if (TwainPlatform.IsMacOSX)
|
||||
{
|
||||
TW_IDENTITY_MACOSX app = Session.AppIdentity;
|
||||
TW_IDENTITY_MACOSX ds = Session.CurrentSource;
|
||||
TW_IDENTITY_MACOSX app2 = app;
|
||||
TW_IDENTITY_MACOSX ds2 = ds;
|
||||
if (TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)OSXLegacyDSM.DSM_Entry(ref app, ref ds, DG.CONTROL, DAT.CALLBACK2, msg, ref data);
|
||||
rc = (STS)OSXLegacyDSM.DSM_Entry(ref app2, ref ds2, DG.CONTROL, DAT.CALLBACK2, MSG.REGISTER_CALLBACK, ref data);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = (STS)OSXNewDSM.DSM_Entry(ref app, ref ds, DG.CONTROL, DAT.CALLBACK2, msg, ref data);
|
||||
rc = (STS)OSXNewDSM.DSM_Entry(ref app2, ref ds2, DG.CONTROL, DAT.CALLBACK2, MSG.REGISTER_CALLBACK, ref data);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
|
||||
@@ -6,21 +6,17 @@ namespace NTwain.Triplets.ControlDATs
|
||||
/// <summary>
|
||||
/// Contains calls used with <see cref="DG.CONTROL"/> and <see cref="DAT.CUSTOMDSDATA"/>.
|
||||
/// </summary>
|
||||
public class CustomDsData : TripletBase
|
||||
public class CustomDsData
|
||||
{
|
||||
public CustomDsData(TwainSession session) : base(session)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the custom DS data.
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public STS Get(out TW_CUSTOMDSDATA data)
|
||||
public STS Get(ref TW_IDENTITY_LEGACY app, ref TW_IDENTITY_LEGACY ds, out TW_CUSTOMDSDATA data)
|
||||
{
|
||||
data = default;
|
||||
return DoIt(MSG.GET, ref data);
|
||||
return DoIt(ref app, ref ds, MSG.GET, ref data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -28,18 +24,14 @@ namespace NTwain.Triplets.ControlDATs
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public STS Set(ref TW_CUSTOMDSDATA data)
|
||||
{
|
||||
return DoIt(MSG.SET, ref data);
|
||||
}
|
||||
public STS Set(ref TW_IDENTITY_LEGACY app, ref TW_IDENTITY_LEGACY ds, ref TW_CUSTOMDSDATA data)
|
||||
=> DoIt(ref app, ref ds, MSG.SET, ref data);
|
||||
|
||||
STS DoIt(MSG msg, ref TW_CUSTOMDSDATA data)
|
||||
static STS DoIt(ref TW_IDENTITY_LEGACY app, ref TW_IDENTITY_LEGACY ds, MSG msg, ref TW_CUSTOMDSDATA 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.CUSTOMDSDATA, msg, ref data);
|
||||
@@ -51,15 +43,15 @@ namespace NTwain.Triplets.ControlDATs
|
||||
}
|
||||
else if (TwainPlatform.IsMacOSX)
|
||||
{
|
||||
TW_IDENTITY_MACOSX app = Session.AppIdentity;
|
||||
TW_IDENTITY_MACOSX ds = Session.CurrentSource;
|
||||
TW_IDENTITY_MACOSX app2 = app;
|
||||
TW_IDENTITY_MACOSX ds2 = ds;
|
||||
if (TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)OSXLegacyDSM.DSM_Entry(ref app, ref ds, DG.CONTROL, DAT.CUSTOMDSDATA, msg, ref data);
|
||||
rc = (STS)OSXLegacyDSM.DSM_Entry(ref app2, ref ds2, DG.CONTROL, DAT.CUSTOMDSDATA, msg, ref data);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = (STS)OSXNewDSM.DSM_Entry(ref app, ref ds, DG.CONTROL, DAT.CUSTOMDSDATA, msg, ref data);
|
||||
rc = (STS)OSXNewDSM.DSM_Entry(ref app2, ref ds2, DG.CONTROL, DAT.CUSTOMDSDATA, msg, ref data);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
|
||||
@@ -6,30 +6,24 @@ namespace NTwain.Triplets.ControlDATs
|
||||
/// <summary>
|
||||
/// Contains calls used with <see cref="DG.CONTROL"/> and <see cref="DAT.DEVICEEVENT"/>.
|
||||
/// </summary>
|
||||
public class DeviceEvent : TripletBase
|
||||
public class DeviceEvent
|
||||
{
|
||||
public DeviceEvent(TwainSession session) : base(session)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the device event detail.
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public STS Get(out TW_DEVICEEVENT data)
|
||||
public STS Get(ref TW_IDENTITY_LEGACY app, ref TW_IDENTITY_LEGACY ds, out TW_DEVICEEVENT data)
|
||||
{
|
||||
data = default;
|
||||
return DoIt(MSG.GET, ref data);
|
||||
return DoIt(ref app, ref ds, MSG.GET, ref data);
|
||||
}
|
||||
|
||||
STS DoIt(MSG msg, ref TW_DEVICEEVENT data)
|
||||
static STS DoIt(ref TW_IDENTITY_LEGACY app, ref TW_IDENTITY_LEGACY ds, MSG msg, ref TW_DEVICEEVENT 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.DEVICEEVENT, msg, ref data);
|
||||
@@ -41,15 +35,15 @@ namespace NTwain.Triplets.ControlDATs
|
||||
}
|
||||
else if (TwainPlatform.IsMacOSX)
|
||||
{
|
||||
TW_IDENTITY_MACOSX app = Session.AppIdentity;
|
||||
TW_IDENTITY_MACOSX ds = Session.CurrentSource;
|
||||
TW_IDENTITY_MACOSX app2 = app;
|
||||
TW_IDENTITY_MACOSX ds2 = ds;
|
||||
if (TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)OSXLegacyDSM.DSM_Entry(ref app, ref ds, DG.CONTROL, DAT.DEVICEEVENT, msg, ref data);
|
||||
rc = (STS)OSXLegacyDSM.DSM_Entry(ref app2, ref ds2, DG.CONTROL, DAT.DEVICEEVENT, msg, ref data);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = (STS)OSXNewDSM.DSM_Entry(ref app, ref ds, DG.CONTROL, DAT.DEVICEEVENT, msg, ref data);
|
||||
rc = (STS)OSXNewDSM.DSM_Entry(ref app2, ref ds2, DG.CONTROL, DAT.DEVICEEVENT, msg, ref data);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
|
||||
@@ -8,22 +8,18 @@ namespace NTwain.Triplets.ControlDATs
|
||||
/// <summary>
|
||||
/// Contains calls used with <see cref="DG.CONTROL"/> and <see cref="DAT.ENTRYPOINT"/>.
|
||||
/// </summary>
|
||||
public class EntryPoint : TripletBase
|
||||
public class EntryPoint
|
||||
{
|
||||
public EntryPoint(TwainSession session) : base(session)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads and opens the DSM.
|
||||
/// </summary>
|
||||
/// <param name="entry"></param>
|
||||
/// <returns></returns>
|
||||
public STS Get(out TW_ENTRYPOINT_DELEGATES entry)
|
||||
public STS Get(ref TW_IDENTITY_LEGACY app, out TW_ENTRYPOINT_DELEGATES entry)
|
||||
{
|
||||
entry = default;
|
||||
TW_ENTRYPOINT rawentry = default;
|
||||
var rc = DoIt(MSG.GET, ref rawentry);
|
||||
var rc = DoIt(ref app, MSG.GET, ref rawentry);
|
||||
if (rc == STS.SUCCESS)
|
||||
{
|
||||
entry.Size = rawentry.Size;
|
||||
@@ -48,12 +44,11 @@ namespace NTwain.Triplets.ControlDATs
|
||||
return rc;
|
||||
}
|
||||
|
||||
STS DoIt(MSG msg, ref TW_ENTRYPOINT entry)
|
||||
static STS DoIt(ref TW_IDENTITY_LEGACY app, MSG msg, ref TW_ENTRYPOINT entry)
|
||||
{
|
||||
var rc = STS.FAILURE;
|
||||
if (TwainPlatform.IsWindows)
|
||||
{
|
||||
var app = Session.AppIdentity;
|
||||
if (TwainPlatform.Is32bit && TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)WinLegacyDSM.DSM_Entry(ref app, IntPtr.Zero, DG.CONTROL, DAT.ENTRYPOINT, msg, ref entry);
|
||||
@@ -69,14 +64,14 @@ namespace NTwain.Triplets.ControlDATs
|
||||
//}
|
||||
else if (TwainPlatform.IsMacOSX)
|
||||
{
|
||||
TW_IDENTITY_MACOSX app = Session.AppIdentity;
|
||||
TW_IDENTITY_MACOSX app2 = app;
|
||||
if (TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)OSXLegacyDSM.DSM_Entry(ref app, IntPtr.Zero, DG.CONTROL, DAT.ENTRYPOINT, msg, ref entry);
|
||||
rc = (STS)OSXLegacyDSM.DSM_Entry(ref app2, IntPtr.Zero, DG.CONTROL, DAT.ENTRYPOINT, msg, ref entry);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = (STS)OSXNewDSM.DSM_Entry(ref app, IntPtr.Zero, DG.CONTROL, DAT.ENTRYPOINT, msg, ref entry);
|
||||
rc = (STS)OSXNewDSM.DSM_Entry(ref app2, IntPtr.Zero, DG.CONTROL, DAT.ENTRYPOINT, msg, ref entry);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
|
||||
@@ -7,59 +7,32 @@ namespace NTwain.Triplets.ControlDATs
|
||||
/// <summary>
|
||||
/// Contains calls used with <see cref="DG.CONTROL"/> and <see cref="DAT.IDENTITY"/>.
|
||||
/// </summary>
|
||||
public class Identity : TripletBase
|
||||
public class Identity
|
||||
{
|
||||
public Identity(TwainSession session) : base(session)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads and opens the specified data source.
|
||||
/// </summary>
|
||||
/// <param name="ds"></param>
|
||||
/// <returns></returns>
|
||||
public STS OpenDS(TW_IDENTITY_LEGACY ds) // not a ref on purpose
|
||||
{
|
||||
STS rc;
|
||||
if ((rc = DoIt(MSG.OPENDS, ref ds)) == STS.SUCCESS)
|
||||
{
|
||||
Session.CurrentSource = ds;
|
||||
Session.RegisterCallback();
|
||||
Session.State = STATE.S4;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
public STS OpenDS(ref TW_IDENTITY_LEGACY app, ref TW_IDENTITY_LEGACY ds)
|
||||
=> DoIt(ref app, MSG.OPENDS, ref ds);
|
||||
|
||||
/// <summary>
|
||||
/// Closes the currently open data source.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public STS CloseDS()
|
||||
{
|
||||
STS rc;
|
||||
var ds = Session.CurrentSource;
|
||||
if ((rc = DoIt(MSG.CLOSEDS, ref ds)) == STS.SUCCESS)
|
||||
{
|
||||
Session.State = STATE.S3;
|
||||
Session.CurrentSource = default;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
public STS CloseDS(ref TW_IDENTITY_LEGACY app, ref TW_IDENTITY_LEGACY ds)
|
||||
=> DoIt(ref app, MSG.CLOSEDS, ref ds);
|
||||
|
||||
/// <summary>
|
||||
/// Opens the TWAIN data source selector dialog
|
||||
/// to choose the default data source.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public STS UserSelect()
|
||||
public STS UserSelect(ref TW_IDENTITY_LEGACY app, out TW_IDENTITY_LEGACY ds)
|
||||
{
|
||||
STS rc;
|
||||
var ds = Session.DefaultSource;
|
||||
if ((rc = DoIt(MSG.USERSELECT, ref ds)) == STS.SUCCESS)
|
||||
{
|
||||
Session.DefaultSource = ds;
|
||||
}
|
||||
return rc;
|
||||
ds = default;
|
||||
return DoIt(ref app, MSG.USERSELECT, ref ds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -67,10 +40,10 @@ namespace NTwain.Triplets.ControlDATs
|
||||
/// </summary>
|
||||
/// <param name="ds"></param>
|
||||
/// <returns></returns>
|
||||
public STS GetDefault(out TW_IDENTITY_LEGACY ds)
|
||||
public STS GetDefault(ref TW_IDENTITY_LEGACY app, out TW_IDENTITY_LEGACY ds)
|
||||
{
|
||||
ds = default;
|
||||
return DoIt(MSG.GETDEFAULT, ref ds);
|
||||
return DoIt(ref app, MSG.GETDEFAULT, ref ds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -78,15 +51,8 @@ namespace NTwain.Triplets.ControlDATs
|
||||
/// </summary>
|
||||
/// <param name="ds"></param>
|
||||
/// <returns></returns>
|
||||
public STS Set(TW_IDENTITY_LEGACY ds)
|
||||
{
|
||||
STS rc;
|
||||
if ((rc = DoIt(MSG.SET, ref ds)) == STS.SUCCESS)
|
||||
{
|
||||
Session.DefaultSource = ds;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
public STS Set(ref TW_IDENTITY_LEGACY app, ref TW_IDENTITY_LEGACY ds)
|
||||
=> DoIt(ref app, MSG.SET, ref ds);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the first available data source in an enumerating fashion
|
||||
@@ -94,10 +60,10 @@ namespace NTwain.Triplets.ControlDATs
|
||||
/// </summary>
|
||||
/// <param name="ds"></param>
|
||||
/// <returns></returns>
|
||||
public STS GetFirst(out TW_IDENTITY_LEGACY ds)
|
||||
public STS GetFirst(ref TW_IDENTITY_LEGACY app, out TW_IDENTITY_LEGACY ds)
|
||||
{
|
||||
ds = default;
|
||||
return DoIt(MSG.GETFIRST, ref ds);
|
||||
return DoIt(ref app, MSG.GETFIRST, ref ds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -106,19 +72,18 @@ namespace NTwain.Triplets.ControlDATs
|
||||
/// </summary>
|
||||
/// <param name="ds"></param>
|
||||
/// <returns></returns>
|
||||
public STS GetNext(out TW_IDENTITY_LEGACY ds)
|
||||
public STS GetNext(ref TW_IDENTITY_LEGACY app, out TW_IDENTITY_LEGACY ds)
|
||||
{
|
||||
ds = default;
|
||||
return DoIt(MSG.GETNEXT, ref ds);
|
||||
return DoIt(ref app, MSG.GETNEXT, ref ds);
|
||||
}
|
||||
|
||||
|
||||
STS DoIt(MSG msg, ref TW_IDENTITY_LEGACY ds)
|
||||
static STS DoIt(ref TW_IDENTITY_LEGACY app, MSG msg, ref TW_IDENTITY_LEGACY ds)
|
||||
{
|
||||
var rc = STS.FAILURE;
|
||||
if (TwainPlatform.IsWindows)
|
||||
{
|
||||
var app = Session.AppIdentity;
|
||||
if (TwainPlatform.Is32bit && TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)WinLegacyDSM.DSM_Entry(ref app, IntPtr.Zero, DG.CONTROL, DAT.IDENTITY, msg, ref ds);
|
||||
@@ -130,15 +95,15 @@ namespace NTwain.Triplets.ControlDATs
|
||||
}
|
||||
else if (TwainPlatform.IsMacOSX)
|
||||
{
|
||||
TW_IDENTITY_MACOSX app = Session.AppIdentity;
|
||||
TW_IDENTITY_MACOSX app2 = app;
|
||||
TW_IDENTITY_MACOSX osxds = ds;
|
||||
if (TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)OSXLegacyDSM.DSM_Entry(ref app, IntPtr.Zero, DG.CONTROL, DAT.IDENTITY, msg, ref osxds);
|
||||
rc = (STS)OSXLegacyDSM.DSM_Entry(ref app2, IntPtr.Zero, DG.CONTROL, DAT.IDENTITY, msg, ref osxds);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = (STS)OSXNewDSM.DSM_Entry(ref app, IntPtr.Zero, DG.CONTROL, DAT.IDENTITY, msg, ref osxds);
|
||||
rc = (STS)OSXNewDSM.DSM_Entry(ref app2, IntPtr.Zero, DG.CONTROL, DAT.IDENTITY, msg, ref osxds);
|
||||
}
|
||||
ds = osxds;
|
||||
}
|
||||
|
||||
@@ -7,68 +7,31 @@ namespace NTwain.Triplets.ControlDATs
|
||||
/// <summary>
|
||||
/// Contains calls used with <see cref="DG.CONTROL"/> and <see cref="DAT.PARENT"/>.
|
||||
/// </summary>
|
||||
public class Parent : TripletBase
|
||||
public class Parent
|
||||
{
|
||||
public Parent(TwainSession session) : base(session)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads and opens the DSM.
|
||||
/// </summary>
|
||||
/// <param name="app"></param>
|
||||
/// <param name="hwnd">Required if on Windows.</param>
|
||||
/// <returns></returns>
|
||||
public STS OpenDSM(ref IntPtr hwnd)
|
||||
{
|
||||
STS rc;
|
||||
if ((rc = DoIt(MSG.OPENDSM, ref hwnd)) == STS.SUCCESS)
|
||||
{
|
||||
Session._hwnd = hwnd;
|
||||
|
||||
// get default source
|
||||
if (Session.DGControl.Identity.GetDefault(out TW_IDENTITY_LEGACY ds) == STS.SUCCESS)
|
||||
{
|
||||
Session.DefaultSource = ds;
|
||||
}
|
||||
|
||||
// determine memory mgmt routines used
|
||||
if (((DG)Session.AppIdentity.SupportedGroups & DG.DSM2) == DG.DSM2)
|
||||
{
|
||||
if (Session.DGControl.EntryPoint.Get(out TW_ENTRYPOINT_DELEGATES entry) == STS.SUCCESS)
|
||||
{
|
||||
Session._entryPoint = entry;
|
||||
}
|
||||
}
|
||||
Session.State = STATE.S3;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
public STS OpenDSM(ref TW_IDENTITY_LEGACY app, IntPtr hwnd)
|
||||
=> DoIt(ref app, MSG.OPENDSM, hwnd);
|
||||
|
||||
/// <summary>
|
||||
/// Closes the DSM.
|
||||
/// </summary>
|
||||
/// <param name="app"></param>
|
||||
/// <param name="hwnd">Required if on Windows.</param>
|
||||
/// <returns></returns>
|
||||
public STS CloseDSM(ref IntPtr hwnd)
|
||||
{
|
||||
STS rc;
|
||||
if ((rc = DoIt(MSG.CLOSEDSM, ref hwnd)) == STS.SUCCESS)
|
||||
{
|
||||
Session.State = STATE.S2;
|
||||
Session._entryPoint = default;
|
||||
Session.DefaultSource = default;
|
||||
Session._hwnd = IntPtr.Zero;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
public STS CloseDSM(ref TW_IDENTITY_LEGACY app, IntPtr hwnd)
|
||||
=> DoIt(ref app, MSG.CLOSEDSM, hwnd);
|
||||
|
||||
|
||||
STS DoIt(MSG msg, ref IntPtr hwnd)
|
||||
static STS DoIt(ref TW_IDENTITY_LEGACY app, MSG msg, IntPtr hwnd)
|
||||
{
|
||||
var rc = STS.FAILURE;
|
||||
if (TwainPlatform.IsWindows)
|
||||
{
|
||||
var app = Session.AppIdentity;
|
||||
if (TwainPlatform.Is32bit && TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)WinLegacyDSM.DSM_Entry(ref app, IntPtr.Zero, DG.CONTROL, DAT.PARENT, msg, ref hwnd);
|
||||
@@ -77,7 +40,6 @@ namespace NTwain.Triplets.ControlDATs
|
||||
{
|
||||
rc = (STS)WinNewDSM.DSM_Entry(ref app, IntPtr.Zero, DG.CONTROL, DAT.PARENT, msg, ref hwnd);
|
||||
}
|
||||
if (rc == STS.SUCCESS) Session.AppIdentity = app;
|
||||
}
|
||||
//else if (TwainPlatform.IsLinux)
|
||||
//{
|
||||
@@ -87,18 +49,14 @@ namespace NTwain.Triplets.ControlDATs
|
||||
//}
|
||||
else if (TwainPlatform.IsMacOSX)
|
||||
{
|
||||
TW_IDENTITY_MACOSX app = Session.AppIdentity;
|
||||
TW_IDENTITY_MACOSX app2 = app;
|
||||
if (TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)OSXLegacyDSM.DSM_Entry(ref app, IntPtr.Zero, DG.CONTROL, DAT.PARENT, msg, ref hwnd);
|
||||
rc = (STS)OSXLegacyDSM.DSM_Entry(ref app2, IntPtr.Zero, DG.CONTROL, DAT.PARENT, msg, ref hwnd);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = (STS)OSXNewDSM.DSM_Entry(ref app, IntPtr.Zero, DG.CONTROL, DAT.PARENT, msg, ref hwnd);
|
||||
}
|
||||
if (rc == STS.SUCCESS)
|
||||
{
|
||||
Session.AppIdentity = app;
|
||||
rc = (STS)OSXNewDSM.DSM_Entry(ref app2, IntPtr.Zero, DG.CONTROL, DAT.PARENT, msg, ref hwnd);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
|
||||
@@ -7,24 +7,19 @@ namespace NTwain.Triplets.ControlDATs
|
||||
/// <summary>
|
||||
/// Contains calls used with <see cref="DG.CONTROL"/> and <see cref="DAT.STATUS"/>.
|
||||
/// </summary>
|
||||
public class Status : TripletBase
|
||||
public class Status
|
||||
{
|
||||
public Status(TwainSession session) : base(session)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current status for the DSM.
|
||||
/// </summary>
|
||||
/// <param name="status"></param>
|
||||
/// <returns></returns>
|
||||
public STS GetForDSM(out TW_STATUS status)
|
||||
public STS GetForDSM(ref TW_IDENTITY_LEGACY app, out TW_STATUS status)
|
||||
{
|
||||
status = default;
|
||||
var rc = STS.FAILURE;
|
||||
if (TwainPlatform.IsWindows)
|
||||
{
|
||||
var app = Session.AppIdentity;
|
||||
if (TwainPlatform.Is32bit && TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)WinLegacyDSM.DSM_Entry(ref app, IntPtr.Zero, DG.CONTROL, DAT.STATUS, MSG.GET, ref status);
|
||||
@@ -36,14 +31,14 @@ namespace NTwain.Triplets.ControlDATs
|
||||
}
|
||||
else if (TwainPlatform.IsMacOSX)
|
||||
{
|
||||
TW_IDENTITY_MACOSX app = Session.AppIdentity;
|
||||
TW_IDENTITY_MACOSX app2 = app;
|
||||
if (TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)OSXLegacyDSM.DSM_Entry(ref app, IntPtr.Zero, DG.CONTROL, DAT.STATUS, MSG.GET, ref status);
|
||||
rc = (STS)OSXLegacyDSM.DSM_Entry(ref app2, IntPtr.Zero, DG.CONTROL, DAT.STATUS, MSG.GET, ref status);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = (STS)OSXNewDSM.DSM_Entry(ref app, IntPtr.Zero, DG.CONTROL, DAT.STATUS, MSG.GET, ref status);
|
||||
rc = (STS)OSXNewDSM.DSM_Entry(ref app2, IntPtr.Zero, DG.CONTROL, DAT.STATUS, MSG.GET, ref status);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
@@ -54,14 +49,12 @@ namespace NTwain.Triplets.ControlDATs
|
||||
/// </summary>
|
||||
/// <param name="status"></param>
|
||||
/// <returns></returns>
|
||||
public STS GetForDS(out TW_STATUS status)
|
||||
public STS GetForDS(ref TW_IDENTITY_LEGACY app, ref TW_IDENTITY_LEGACY ds, out TW_STATUS status)
|
||||
{
|
||||
status = default;
|
||||
var ds = Session.CurrentSource;
|
||||
var rc = STS.FAILURE;
|
||||
if (TwainPlatform.IsWindows)
|
||||
{
|
||||
var app = Session.AppIdentity;
|
||||
if (TwainPlatform.Is32bit && TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)WinLegacyDSM.DSM_Entry(ref app, ref ds, DG.CONTROL, DAT.STATUS, MSG.GET, ref status);
|
||||
@@ -73,15 +66,15 @@ namespace NTwain.Triplets.ControlDATs
|
||||
}
|
||||
else if (TwainPlatform.IsMacOSX)
|
||||
{
|
||||
TW_IDENTITY_MACOSX app = Session.AppIdentity;
|
||||
TW_IDENTITY_MACOSX app2 = app;
|
||||
TW_IDENTITY_MACOSX osxds = ds;
|
||||
if (TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)OSXLegacyDSM.DSM_Entry(ref app, ref osxds, DG.CONTROL, DAT.STATUS, MSG.GET, ref status);
|
||||
rc = (STS)OSXLegacyDSM.DSM_Entry(ref app2, ref osxds, DG.CONTROL, DAT.STATUS, MSG.GET, ref status);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = (STS)OSXNewDSM.DSM_Entry(ref app, ref osxds, DG.CONTROL, DAT.STATUS, MSG.GET, ref status);
|
||||
rc = (STS)OSXNewDSM.DSM_Entry(ref app2, ref osxds, DG.CONTROL, DAT.STATUS, MSG.GET, ref status);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
|
||||
@@ -7,13 +7,8 @@ namespace NTwain.Triplets.ControlDATs
|
||||
/// <summary>
|
||||
/// Contains calls used with <see cref="DG.CONTROL"/> and <see cref="DAT.STATUSUTF8"/>.
|
||||
/// </summary>
|
||||
public class StatusUtf8 : TripletBase
|
||||
public class StatusUtf8
|
||||
{
|
||||
public StatusUtf8(TwainSession session) : base(session)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the extended text info for a previously received <see cref="TW_STATUS"/>.
|
||||
/// If this is called you should try to extract the string value from it once
|
||||
@@ -23,13 +18,12 @@ namespace NTwain.Triplets.ControlDATs
|
||||
/// <param name="status"></param>
|
||||
/// <param name="extendedStatus"></param>
|
||||
/// <returns></returns>
|
||||
public STS Get(TW_STATUS status, out TW_STATUSUTF8 extendedStatus)
|
||||
public STS Get(ref TW_IDENTITY_LEGACY app, TW_STATUS status, out TW_STATUSUTF8 extendedStatus)
|
||||
{
|
||||
extendedStatus = new TW_STATUSUTF8 { Status = status };
|
||||
var rc = STS.FAILURE;
|
||||
if (TwainPlatform.IsWindows)
|
||||
{
|
||||
var app = Session.AppIdentity;
|
||||
if (TwainPlatform.Is32bit && TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)WinLegacyDSM.DSM_Entry(ref app, IntPtr.Zero, DG.CONTROL, DAT.STATUSUTF8, MSG.GET, ref extendedStatus);
|
||||
@@ -41,15 +35,14 @@ namespace NTwain.Triplets.ControlDATs
|
||||
}
|
||||
else if (TwainPlatform.IsMacOSX)
|
||||
{
|
||||
TW_IDENTITY_MACOSX app = Session.AppIdentity;
|
||||
TW_IDENTITY_MACOSX ds = Session.CurrentSource;
|
||||
TW_IDENTITY_MACOSX app2 = app;
|
||||
if (TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)OSXLegacyDSM.DSM_Entry(ref app, IntPtr.Zero, DG.CONTROL, DAT.STATUSUTF8, MSG.GET, ref extendedStatus);
|
||||
rc = (STS)OSXLegacyDSM.DSM_Entry(ref app2, IntPtr.Zero, DG.CONTROL, DAT.STATUSUTF8, MSG.GET, ref extendedStatus);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = (STS)OSXNewDSM.DSM_Entry(ref app, IntPtr.Zero, DG.CONTROL, DAT.STATUSUTF8, MSG.GET, ref extendedStatus);
|
||||
rc = (STS)OSXNewDSM.DSM_Entry(ref app2, IntPtr.Zero, DG.CONTROL, DAT.STATUSUTF8, MSG.GET, ref extendedStatus);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
|
||||
@@ -6,64 +6,37 @@ namespace NTwain.Triplets.ControlDATs
|
||||
/// <summary>
|
||||
/// Contains calls used with <see cref="DG.CONTROL"/> and <see cref="DAT.USERINTERFACE"/>.
|
||||
/// </summary>
|
||||
public class UserInterface : TripletBase
|
||||
public class UserInterface
|
||||
{
|
||||
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;
|
||||
}
|
||||
public STS DisableDS(ref TW_IDENTITY_LEGACY app, ref TW_IDENTITY_LEGACY ds, ref TW_USERINTERFACE data)
|
||||
=> DoIt(ref app, ref ds, MSG.DISABLEDS, ref data);
|
||||
|
||||
/// <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;
|
||||
}
|
||||
public STS EnableDS(ref TW_IDENTITY_LEGACY app, ref TW_IDENTITY_LEGACY ds, ref TW_USERINTERFACE data)
|
||||
=> DoIt(ref app, ref ds, MSG.ENABLEDS, ref data);
|
||||
|
||||
/// <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;
|
||||
}
|
||||
public STS EnableDSUIOnly(ref TW_IDENTITY_LEGACY app, ref TW_IDENTITY_LEGACY ds, ref TW_USERINTERFACE data)
|
||||
=> DoIt(ref app, ref ds, MSG.ENABLEDSUIONLY, ref data);
|
||||
|
||||
STS DoIt(MSG msg, ref TW_USERINTERFACE data)
|
||||
static STS DoIt(ref TW_IDENTITY_LEGACY app, ref TW_IDENTITY_LEGACY ds, 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);
|
||||
@@ -75,15 +48,15 @@ namespace NTwain.Triplets.ControlDATs
|
||||
}
|
||||
else if (TwainPlatform.IsMacOSX)
|
||||
{
|
||||
TW_IDENTITY_MACOSX app = Session.AppIdentity;
|
||||
TW_IDENTITY_MACOSX ds = Session.CurrentSource;
|
||||
TW_IDENTITY_MACOSX app2 = app;
|
||||
TW_IDENTITY_MACOSX ds2 = ds;
|
||||
if (TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)OSXLegacyDSM.DSM_Entry(ref app, ref ds, DG.CONTROL, DAT.USERINTERFACE, msg, ref data);
|
||||
rc = (STS)OSXLegacyDSM.DSM_Entry(ref app2, ref ds2, DG.CONTROL, DAT.USERINTERFACE, msg, ref data);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = (STS)OSXNewDSM.DSM_Entry(ref app, ref ds, DG.CONTROL, DAT.USERINTERFACE, msg, ref data);
|
||||
rc = (STS)OSXNewDSM.DSM_Entry(ref app2, ref ds2, DG.CONTROL, DAT.USERINTERFACE, msg, ref data);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
|
||||
@@ -6,21 +6,17 @@ namespace NTwain.Triplets.ControlDATs
|
||||
/// <summary>
|
||||
/// Contains calls used with <see cref="DG.CONTROL"/> and <see cref="DAT.XFERGROUP"/>.
|
||||
/// </summary>
|
||||
public class XferGroup : TripletBase
|
||||
public class XferGroup
|
||||
{
|
||||
public XferGroup(TwainSession session) : base(session)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the transfer group used.
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public STS Get(out DG data)
|
||||
public STS Get(ref TW_IDENTITY_LEGACY app, ref TW_IDENTITY_LEGACY ds, out DG data)
|
||||
{
|
||||
data = default;
|
||||
return DoIt(MSG.GET, ref data);
|
||||
return DoIt(ref app, ref ds, MSG.GET, ref data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -28,18 +24,16 @@ namespace NTwain.Triplets.ControlDATs
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public STS Set(DG data)
|
||||
public STS Set(ref TW_IDENTITY_LEGACY app, ref TW_IDENTITY_LEGACY ds, DG data)
|
||||
{
|
||||
return DoIt(MSG.SET, ref data);
|
||||
return DoIt(ref app, ref ds, MSG.SET, ref data);
|
||||
}
|
||||
|
||||
STS DoIt(MSG msg, ref DG data)
|
||||
static STS DoIt(ref TW_IDENTITY_LEGACY app, ref TW_IDENTITY_LEGACY ds, MSG msg, ref DG 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.XFERGROUP, msg, ref data);
|
||||
@@ -51,15 +45,15 @@ namespace NTwain.Triplets.ControlDATs
|
||||
}
|
||||
else if (TwainPlatform.IsMacOSX)
|
||||
{
|
||||
TW_IDENTITY_MACOSX app = Session.AppIdentity;
|
||||
TW_IDENTITY_MACOSX ds = Session.CurrentSource;
|
||||
TW_IDENTITY_MACOSX app2 = app;
|
||||
TW_IDENTITY_MACOSX ds2 = ds;
|
||||
if (TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)OSXLegacyDSM.DSM_Entry(ref app, ref ds, DG.CONTROL, DAT.XFERGROUP, msg, ref data);
|
||||
rc = (STS)OSXLegacyDSM.DSM_Entry(ref app2, ref ds2, DG.CONTROL, DAT.XFERGROUP, msg, ref data);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = (STS)OSXNewDSM.DSM_Entry(ref app, ref ds, DG.CONTROL, DAT.XFERGROUP, msg, ref data);
|
||||
rc = (STS)OSXNewDSM.DSM_Entry(ref app2, ref ds2, DG.CONTROL, DAT.XFERGROUP, msg, ref data);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
|
||||
@@ -5,10 +5,7 @@ namespace NTwain.Triplets
|
||||
/// <summary>
|
||||
/// Contains calls used with <see cref="DG.AUDIO"/>.
|
||||
/// </summary>
|
||||
public class DGAudio : TripletBase
|
||||
public class DGAudio
|
||||
{
|
||||
public DGAudio(TwainSession session) : base(session)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,44 +5,40 @@ namespace NTwain.Triplets
|
||||
/// <summary>
|
||||
/// Contains calls used with <see cref="DG.CONTROL"/>.
|
||||
/// </summary>
|
||||
public class DGControl : TripletBase
|
||||
public class DGControl
|
||||
{
|
||||
public DGControl(TwainSession session) : base(session)
|
||||
{
|
||||
}
|
||||
|
||||
private Parent? _parent;
|
||||
public Parent Parent => _parent ??= new Parent(Session);
|
||||
public Parent Parent => _parent ??= new Parent();
|
||||
|
||||
private EntryPoint? _entryPoint;
|
||||
public EntryPoint EntryPoint => _entryPoint ??= new EntryPoint(Session);
|
||||
public EntryPoint EntryPoint => _entryPoint ??= new EntryPoint();
|
||||
|
||||
private Identity? _identity;
|
||||
public Identity Identity => _identity ??= new Identity(Session);
|
||||
public Identity Identity => _identity ??= new Identity();
|
||||
|
||||
private Status? _status;
|
||||
public Status Status => _status ??= new Status(Session);
|
||||
public Status Status => _status ??= new Status();
|
||||
|
||||
private StatusUtf8? _statusUtf8;
|
||||
public StatusUtf8 StatusUtf8 => _statusUtf8 ??= new StatusUtf8(Session);
|
||||
public StatusUtf8 StatusUtf8 => _statusUtf8 ??= new StatusUtf8();
|
||||
|
||||
private CustomDsData? _customDsData;
|
||||
public CustomDsData CustomDsData => _customDsData ??= new CustomDsData(Session);
|
||||
public CustomDsData CustomDsData => _customDsData ??= new CustomDsData();
|
||||
|
||||
private DeviceEvent? _deviceEvent;
|
||||
public DeviceEvent DeviceEvent => _deviceEvent ??= new DeviceEvent(Session);
|
||||
public DeviceEvent DeviceEvent => _deviceEvent ??= new DeviceEvent();
|
||||
|
||||
private Callback? _callback;
|
||||
public Callback Callback => _callback ??= new Callback(Session);
|
||||
public Callback Callback => _callback ??= new Callback();
|
||||
|
||||
private Callback2? _callback2;
|
||||
public Callback2 Callback2 => _callback2 ??= new Callback2(Session);
|
||||
public Callback2 Callback2 => _callback2 ??= new Callback2();
|
||||
|
||||
private XferGroup? _xferGroup;
|
||||
public XferGroup XferGroup => _xferGroup ??= new XferGroup(Session);
|
||||
public XferGroup XferGroup => _xferGroup ??= new XferGroup();
|
||||
|
||||
private UserInterface? _userInterface;
|
||||
public UserInterface UserInterface => _userInterface ??= new UserInterface(Session);
|
||||
public UserInterface UserInterface => _userInterface ??= new UserInterface();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,7 @@ namespace NTwain.Triplets
|
||||
/// <summary>
|
||||
/// Contains calls used with <see cref="DG.IMAGE"/>.
|
||||
/// </summary>
|
||||
public class DGImage : TripletBase
|
||||
public class DGImage
|
||||
{
|
||||
public DGImage(TwainSession session) : base(session)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace NTwain.Triplets
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for grouping triplet operations messages.
|
||||
/// </summary>
|
||||
public abstract class TripletBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="TripletBase" /> class.
|
||||
/// </summary>
|
||||
/// <param name="session">The session.</param>
|
||||
/// <exception cref="System.ArgumentNullException"></exception>
|
||||
public TripletBase(TwainSession session)
|
||||
{
|
||||
Session = session ?? throw new ArgumentNullException(nameof(session));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the twain session.
|
||||
/// </summary>
|
||||
public TwainSession Session { get; }
|
||||
}
|
||||
}
|
||||
@@ -36,13 +36,13 @@ namespace NTwain
|
||||
if (_appIdentity.ProtocolMajor > 2 || (_appIdentity.ProtocolMajor >= 2 && _appIdentity.ProtocolMinor >= 2))
|
||||
{
|
||||
var cb2 = new TW_CALLBACK2 { CallBackProc = cbPtr };
|
||||
rc = DGControl.Callback2.RegisterCallback(ref cb2);
|
||||
rc = DGControl.Callback2.RegisterCallback(ref _appIdentity, ref _currentDS, ref cb2);
|
||||
}
|
||||
if (rc != STS.SUCCESS)
|
||||
{
|
||||
// always try old callback
|
||||
var cb = new TW_CALLBACK { CallBackProc = cbPtr };
|
||||
DGControl.Callback.RegisterCallback(ref cb);
|
||||
DGControl.Callback.RegisterCallback(ref _appIdentity, ref _currentDS, ref cb);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using TWAINWorkingGroup;
|
||||
using static System.Collections.Specialized.BitVector32;
|
||||
|
||||
namespace NTwain
|
||||
{
|
||||
@@ -38,16 +37,11 @@ namespace NTwain
|
||||
TW_IDENTITY_LEGACY _currentDS;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default data source.
|
||||
/// Gets/sets the default data source.
|
||||
/// </summary>
|
||||
public TW_IDENTITY_LEGACY DefaultSource
|
||||
{
|
||||
get => _defaultDS;
|
||||
internal set
|
||||
{
|
||||
_defaultDS = value;
|
||||
DefaultSourceChanged?.Invoke(this, value);
|
||||
}
|
||||
}
|
||||
TW_IDENTITY_LEGACY _defaultDS;
|
||||
|
||||
@@ -78,7 +72,7 @@ namespace NTwain
|
||||
{
|
||||
get
|
||||
{
|
||||
var sts = DGControl.CustomDsData.Get(out TW_CUSTOMDSDATA data);
|
||||
var sts = DGControl.CustomDsData.Get(ref _appIdentity, ref _currentDS, out TW_CUSTOMDSDATA data);
|
||||
if (sts == STS.SUCCESS)
|
||||
{
|
||||
if (data.hData != IntPtr.Zero && data.InfoLength > 0)
|
||||
@@ -111,7 +105,7 @@ namespace NTwain
|
||||
var lockedPtr = Lock(data.hData);
|
||||
Marshal.Copy(value, 0, lockedPtr, value.Length);
|
||||
Unlock(data.hData);
|
||||
var sts = DGControl.CustomDsData.Set(ref data);
|
||||
var sts = DGControl.CustomDsData.Set(ref _appIdentity, ref _currentDS, ref data);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
@@ -14,14 +14,57 @@ namespace NTwain
|
||||
/// <returns></returns>
|
||||
public IEnumerable<TW_IDENTITY_LEGACY> GetSources()
|
||||
{
|
||||
var rc = DGControl.Identity.GetFirst(out TW_IDENTITY_LEGACY ds);
|
||||
var rc = DGControl.Identity.GetFirst(ref _appIdentity, out TW_IDENTITY_LEGACY ds);
|
||||
while (rc == STS.SUCCESS)
|
||||
{
|
||||
yield return ds;
|
||||
rc = DGControl.Identity.GetNext(out ds);
|
||||
rc = DGControl.Identity.GetNext(ref _appIdentity, out ds);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows the TWAIN source selection UI for setting the default source.
|
||||
/// </summary>
|
||||
public void ShowUserSelect()
|
||||
{
|
||||
if (DGControl.Identity.UserSelect(ref _appIdentity, out TW_IDENTITY_LEGACY ds) == STS.SUCCESS)
|
||||
{
|
||||
_defaultDS = ds;
|
||||
DefaultSourceChanged?.Invoke(this, ds);
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenSource(TW_IDENTITY_LEGACY source)
|
||||
{
|
||||
if (DGControl.Identity.OpenDS(ref _appIdentity, ref source) == STS.SUCCESS)
|
||||
{
|
||||
RegisterCallback();
|
||||
CurrentSource = source;
|
||||
State = STATE.S4;
|
||||
}
|
||||
}
|
||||
|
||||
public void CloseSource()
|
||||
{
|
||||
if (DGControl.Identity.CloseDS(ref _appIdentity, ref _currentDS) == STS.SUCCESS)
|
||||
{
|
||||
State = STATE.S3;
|
||||
CurrentSource = default;
|
||||
}
|
||||
}
|
||||
|
||||
public STS SetDefaultSource(TW_IDENTITY_LEGACY source)
|
||||
{
|
||||
var rc = DGControl.Identity.Set(ref _appIdentity, ref source);
|
||||
if (rc == STS.SUCCESS)
|
||||
{
|
||||
_defaultDS = source;
|
||||
DefaultSourceChanged?.Invoke(this, source);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Enables the currently open source.
|
||||
/// </summary>
|
||||
@@ -36,11 +79,14 @@ namespace NTwain
|
||||
ShowUI = (ushort)((showUI || uiOnly) ? 1 : 0),
|
||||
hParent = _hwnd,
|
||||
};
|
||||
var rc = uiOnly ? DGControl.UserInterface.EnableDSUIOnly(ref ui) : DGControl.UserInterface.EnableDS(ref ui);
|
||||
var rc = uiOnly ?
|
||||
DGControl.UserInterface.EnableDSUIOnly(ref _appIdentity, ref _currentDS, ref ui) :
|
||||
DGControl.UserInterface.EnableDS(ref _appIdentity, ref _currentDS, ref ui);
|
||||
if (rc == STS.SUCCESS || (!uiOnly && !showUI && rc == STS.CHECKSTATUS))
|
||||
{
|
||||
// keep it around for disable use
|
||||
_userInterface = ui;
|
||||
State = STATE.S5;
|
||||
};
|
||||
return rc;
|
||||
}
|
||||
@@ -51,7 +97,12 @@ namespace NTwain
|
||||
/// <returns></returns>
|
||||
public STS DisableSource()
|
||||
{
|
||||
return DGControl.UserInterface.DisableDS(ref _userInterface);
|
||||
var rc = DGControl.UserInterface.DisableDS(ref _appIdentity, ref _currentDS, ref _userInterface);
|
||||
if (rc == STS.SUCCESS)
|
||||
{
|
||||
State = STATE.S4;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using NTwain.Triplets;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using TWAINWorkingGroup;
|
||||
@@ -78,9 +77,9 @@ namespace NTwain
|
||||
}
|
||||
};
|
||||
|
||||
DGControl = new DGControl(this);
|
||||
DGImage = new DGImage(this);
|
||||
DGAudio = new DGAudio(this);
|
||||
DGControl = new DGControl();
|
||||
DGImage = new DGImage();
|
||||
DGAudio = new DGAudio();
|
||||
|
||||
_legacyCallbackDelegate = LegacyCallbackHandler;
|
||||
_osxCallbackDelegate = OSXCallbackHandler;
|
||||
@@ -89,6 +88,88 @@ namespace NTwain
|
||||
internal IntPtr _hwnd;
|
||||
internal TW_USERINTERFACE _userInterface;
|
||||
|
||||
/// <summary>
|
||||
/// Loads and opens the TWAIN data source manager.
|
||||
/// </summary>
|
||||
/// <param name="hwnd">Required if on Windows.</param>
|
||||
/// <returns></returns>
|
||||
public STS OpenDSM(IntPtr hwnd)
|
||||
{
|
||||
var rc = DGControl.Parent.OpenDSM(ref _appIdentity, hwnd);
|
||||
if (rc == STS.SUCCESS)
|
||||
{
|
||||
_hwnd = hwnd;
|
||||
State = STATE.S3;
|
||||
// get default source
|
||||
if (DGControl.Identity.GetDefault(ref _appIdentity, out TW_IDENTITY_LEGACY ds) == STS.SUCCESS)
|
||||
{
|
||||
_defaultDS = ds;
|
||||
DefaultSourceChanged?.Invoke(this, _defaultDS);
|
||||
}
|
||||
|
||||
// determine memory mgmt routines used
|
||||
if (((DG)AppIdentity.SupportedGroups & DG.DSM2) == DG.DSM2)
|
||||
{
|
||||
DGControl.EntryPoint.Get(ref _appIdentity, out _entryPoint);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Closes the TWAIN data source manager.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public STS CloseDSM()
|
||||
{
|
||||
var rc = DGControl.Parent.CloseDSM(ref _appIdentity, _hwnd);
|
||||
if (rc == STS.SUCCESS)
|
||||
{
|
||||
State = STATE.S2;
|
||||
_entryPoint = default;
|
||||
_defaultDS = default;
|
||||
DefaultSourceChanged?.Invoke(this, _defaultDS);
|
||||
_hwnd = IntPtr.Zero;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the last status code if an operation did not return success.
|
||||
/// This can only be done once after an error.
|
||||
/// </summary>
|
||||
/// <param name="forDsmOnly">true to get status for dsm operation error, false to get status for ds operation error,</param>
|
||||
/// <returns></returns>
|
||||
public TW_STATUS GetLastStatus(bool forDsmOnly)
|
||||
{
|
||||
if (forDsmOnly)
|
||||
{
|
||||
DGControl.Status.GetForDSM(ref _appIdentity, out TW_STATUS status);
|
||||
return status;
|
||||
}
|
||||
else
|
||||
{
|
||||
DGControl.Status.GetForDS(ref _appIdentity, ref _currentDS, out TW_STATUS status);
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get string representation of a previously gotten status
|
||||
/// from <see cref="GetLastStatus"/> if possible.
|
||||
/// </summary>
|
||||
/// <param name="status"></param>
|
||||
/// <returns></returns>
|
||||
public string? GetStatusText(TW_STATUS status)
|
||||
{
|
||||
if (DGControl.StatusUtf8.Get(ref _appIdentity, status, out TW_STATUSUTF8 extendedStatus) == STS.SUCCESS)
|
||||
{
|
||||
return extendedStatus.ReadAndFree(this);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to bring the TWAIN session down to some state.
|
||||
/// </summary>
|
||||
@@ -104,14 +185,13 @@ namespace NTwain
|
||||
switch (State)
|
||||
{
|
||||
case STATE.S5:
|
||||
DGControl.UserInterface.DisableDS(ref _userInterface);
|
||||
DisableSource();
|
||||
break;
|
||||
case STATE.S4:
|
||||
DGControl.Identity.CloseDS();
|
||||
CloseSource();
|
||||
break;
|
||||
case STATE.S3:
|
||||
// shouldn't care about handle when closing really
|
||||
DGControl.Parent.CloseDSM(ref _hwnd);
|
||||
CloseDSM();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user