mirror of
https://github.com/soukoku/ntwain.git
synced 2025-12-29 02:05:04 +08:00
Progress testing default DS idea.
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<PackageId>NTwain</PackageId>
|
<PackageId>NTwain</PackageId>
|
||||||
<Description>Library containing the TWAIN API for dotnet.</Description>
|
<Description>Library containing the TWAIN API for dotnet.</Description>
|
||||||
<TargetFrameworks>net462;net6.0</TargetFrameworks>
|
<TargetFrameworks>net6.0;net462;</TargetFrameworks>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ namespace NTwain.Triplets
|
|||||||
var rc = STS.FAILURE;
|
var rc = STS.FAILURE;
|
||||||
if (TwainPlatform.IsWindows)
|
if (TwainPlatform.IsWindows)
|
||||||
{
|
{
|
||||||
var app = Session._appIdentityLegacy;
|
var app = Session._appIdentity;
|
||||||
TW_IDENTITY_LEGACY dummy = default;
|
TW_IDENTITY_LEGACY dummy = default;
|
||||||
if (TwainPlatform.Is32bit && TwainPlatform.PreferLegacyDSM)
|
if (TwainPlatform.Is32bit && TwainPlatform.PreferLegacyDSM)
|
||||||
{
|
{
|
||||||
@@ -64,11 +64,11 @@ namespace NTwain.Triplets
|
|||||||
}
|
}
|
||||||
//else if (TwainPlatform.IsLinux)
|
//else if (TwainPlatform.IsLinux)
|
||||||
//{
|
//{
|
||||||
// var app = Session._appIdentityLegacy;
|
// var app = Session._appIdentity;
|
||||||
//}
|
//}
|
||||||
else if (TwainPlatform.IsMacOSX)
|
else if (TwainPlatform.IsMacOSX)
|
||||||
{
|
{
|
||||||
var app = Session._appIdentityOSX;
|
TW_IDENTITY_MACOSX app = Session._appIdentity;
|
||||||
TW_IDENTITY_MACOSX dummy = default;
|
TW_IDENTITY_MACOSX dummy = default;
|
||||||
if (TwainPlatform.PreferLegacyDSM)
|
if (TwainPlatform.PreferLegacyDSM)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,14 +17,15 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ds"></param>
|
/// <param name="ds"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public STS OpenDS(ref TW_IDENTITY_LEGACY ds)
|
public STS OpenDS(TW_IDENTITY_LEGACY ds) // not a ref on purpose
|
||||||
{
|
{
|
||||||
STS rc;
|
STS rc;
|
||||||
if ((rc = DoIt(MSG.OPENDS, ref ds, true)) == STS.SUCCESS)
|
if ((rc = DoIt(MSG.OPENDS, ref ds, true)) == STS.SUCCESS)
|
||||||
{
|
{
|
||||||
|
Session._currentDS = ds;
|
||||||
Session.State = STATE.S4;
|
Session.State = STATE.S4;
|
||||||
//// determine memory mgmt routines used
|
//// determine memory mgmt routines used
|
||||||
//if ((((DG)Session._appIdentityLegacy.SupportedGroups) & DG.DSM2) == DG.DSM2)
|
//if ((((DG)Session._appIdentity.SupportedGroups) & DG.DSM2) == DG.DSM2)
|
||||||
//{
|
//{
|
||||||
// TW_ENTRYPOINT_DELEGATES entry = default;
|
// TW_ENTRYPOINT_DELEGATES entry = default;
|
||||||
// if (Session.DGControl.EntryPoint.Get(ref entry) == STS.SUCCESS)
|
// if (Session.DGControl.EntryPoint.Get(ref entry) == STS.SUCCESS)
|
||||||
@@ -36,29 +37,44 @@ namespace NTwain.Triplets
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
///// <summary>
|
/// <summary>
|
||||||
///// Closes the currently open DS.
|
/// Closes the currently open DS.
|
||||||
///// </summary>
|
/// </summary>
|
||||||
///// <returns></returns>
|
/// <returns></returns>
|
||||||
//public STS CloseDS(ref IntPtr hwnd)
|
public STS CloseDS()
|
||||||
//{
|
{
|
||||||
// STS rc;
|
STS rc;
|
||||||
// if ((rc = DoIt(MSG.CLOSEDSM, ref hwnd)) == STS.SUCCESS)
|
var ds = Session._currentDS;
|
||||||
// {
|
if ((rc = DoIt(MSG.CLOSEDS, ref ds, true)) == STS.SUCCESS)
|
||||||
// Session._hwnd = IntPtr.Zero;
|
{
|
||||||
// Session._entryPoint = default;
|
Session._currentDS = default;
|
||||||
// Session.State = STATE.S2;
|
Session.State = STATE.S3;
|
||||||
// }
|
}
|
||||||
// return rc;
|
return rc;
|
||||||
//}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Opens the TWAIN source selector dialog
|
||||||
|
/// to choose the default source.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public STS UserSelect()
|
||||||
|
{
|
||||||
|
STS rc;
|
||||||
|
var ds = Session._defaultDS;
|
||||||
|
if ((rc = DoIt(MSG.USERSELECT, ref ds, true)) == STS.SUCCESS)
|
||||||
|
{
|
||||||
|
Session._defaultDS = ds;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
STS DoIt(MSG msg, ref TW_IDENTITY_LEGACY ds, bool updateSource)
|
STS DoIt(MSG msg, ref TW_IDENTITY_LEGACY ds)
|
||||||
{
|
{
|
||||||
var rc = STS.FAILURE;
|
var rc = STS.FAILURE;
|
||||||
if (TwainPlatform.IsWindows)
|
if (TwainPlatform.IsWindows)
|
||||||
{
|
{
|
||||||
var app = Session._appIdentityLegacy;
|
var app = Session._appIdentity;
|
||||||
if (TwainPlatform.Is32bit && TwainPlatform.PreferLegacyDSM)
|
if (TwainPlatform.Is32bit && TwainPlatform.PreferLegacyDSM)
|
||||||
{
|
{
|
||||||
rc = (STS)NativeMethods.WindowsTwain32DsmEntryIdentity(ref app, IntPtr.Zero, DG.CONTROL, DAT.IDENTITY, msg, ref ds);
|
rc = (STS)NativeMethods.WindowsTwain32DsmEntryIdentity(ref app, IntPtr.Zero, DG.CONTROL, DAT.IDENTITY, msg, ref ds);
|
||||||
@@ -67,14 +83,10 @@ namespace NTwain.Triplets
|
|||||||
{
|
{
|
||||||
rc = (STS)NativeMethods.WindowsTwaindsmDsmEntryIdentity(ref app, IntPtr.Zero, DG.CONTROL, DAT.IDENTITY, msg, ref ds);
|
rc = (STS)NativeMethods.WindowsTwaindsmDsmEntryIdentity(ref app, IntPtr.Zero, DG.CONTROL, DAT.IDENTITY, msg, ref ds);
|
||||||
}
|
}
|
||||||
if (updateSource && rc == STS.SUCCESS)
|
|
||||||
{
|
|
||||||
Session._dsIdentityLegacy = ds;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (TwainPlatform.IsMacOSX)
|
else if (TwainPlatform.IsMacOSX)
|
||||||
{
|
{
|
||||||
var app = Session._appIdentityOSX;
|
TW_IDENTITY_MACOSX app = Session._appIdentity;
|
||||||
TW_IDENTITY_MACOSX osxds = ds;
|
TW_IDENTITY_MACOSX osxds = ds;
|
||||||
if (TwainPlatform.PreferLegacyDSM)
|
if (TwainPlatform.PreferLegacyDSM)
|
||||||
{
|
{
|
||||||
@@ -84,11 +96,7 @@ namespace NTwain.Triplets
|
|||||||
{
|
{
|
||||||
rc = (STS)NativeMethods.MacosxTwaindsmDsmEntryIdentity(ref app, IntPtr.Zero, DG.CONTROL, DAT.IDENTITY, msg, ref osxds);
|
rc = (STS)NativeMethods.MacosxTwaindsmDsmEntryIdentity(ref app, IntPtr.Zero, DG.CONTROL, DAT.IDENTITY, msg, ref osxds);
|
||||||
}
|
}
|
||||||
if (updateSource && rc == STS.SUCCESS)
|
ds = osxds;
|
||||||
{
|
|
||||||
Session._dsIdentityOSX = osxds;
|
|
||||||
Session._dsIdentityLegacy = osxds;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,8 +24,11 @@ namespace NTwain.Triplets
|
|||||||
{
|
{
|
||||||
Session._hwnd = hwnd;
|
Session._hwnd = hwnd;
|
||||||
Session.State = STATE.S3;
|
Session.State = STATE.S3;
|
||||||
|
|
||||||
|
// todo: get default source
|
||||||
|
|
||||||
// determine memory mgmt routines used
|
// determine memory mgmt routines used
|
||||||
if ((((DG)Session._appIdentityLegacy.SupportedGroups) & DG.DSM2) == DG.DSM2)
|
if ((((DG)Session._appIdentity.SupportedGroups) & DG.DSM2) == DG.DSM2)
|
||||||
{
|
{
|
||||||
TW_ENTRYPOINT_DELEGATES entry = default;
|
TW_ENTRYPOINT_DELEGATES entry = default;
|
||||||
if (Session.DGControl.EntryPoint.Get(ref entry) == STS.SUCCESS)
|
if (Session.DGControl.EntryPoint.Get(ref entry) == STS.SUCCESS)
|
||||||
@@ -60,7 +63,7 @@ namespace NTwain.Triplets
|
|||||||
var rc = STS.FAILURE;
|
var rc = STS.FAILURE;
|
||||||
if (TwainPlatform.IsWindows)
|
if (TwainPlatform.IsWindows)
|
||||||
{
|
{
|
||||||
var app = Session._appIdentityLegacy;
|
var app = Session._appIdentity;
|
||||||
if (TwainPlatform.Is32bit && TwainPlatform.PreferLegacyDSM)
|
if (TwainPlatform.Is32bit && TwainPlatform.PreferLegacyDSM)
|
||||||
{
|
{
|
||||||
rc = (STS)NativeMethods.WindowsTwain32DsmEntryParent(ref app, IntPtr.Zero, DG.CONTROL, DAT.PARENT, msg, ref hwnd);
|
rc = (STS)NativeMethods.WindowsTwain32DsmEntryParent(ref app, IntPtr.Zero, DG.CONTROL, DAT.PARENT, msg, ref hwnd);
|
||||||
@@ -69,17 +72,17 @@ namespace NTwain.Triplets
|
|||||||
{
|
{
|
||||||
rc = (STS)NativeMethods.WindowsTwaindsmDsmEntryParent(ref app, IntPtr.Zero, DG.CONTROL, DAT.PARENT, msg, ref hwnd);
|
rc = (STS)NativeMethods.WindowsTwaindsmDsmEntryParent(ref app, IntPtr.Zero, DG.CONTROL, DAT.PARENT, msg, ref hwnd);
|
||||||
}
|
}
|
||||||
if (rc == STS.SUCCESS) Session._appIdentityLegacy = app;
|
if (rc == STS.SUCCESS) Session._appIdentity = app;
|
||||||
}
|
}
|
||||||
//else if (TwainPlatform.IsLinux)
|
//else if (TwainPlatform.IsLinux)
|
||||||
//{
|
//{
|
||||||
// var app = Session._appIdentityLegacy;
|
// var app = Session._appIdentity;
|
||||||
// rc = (STS)NativeMethods.LinuxDsmEntryParent(ref app, IntPtr.Zero, DG.CONTROL, DAT.PARENT, msg, ref hwnd);
|
// rc = (STS)NativeMethods.LinuxDsmEntryParent(ref app, IntPtr.Zero, DG.CONTROL, DAT.PARENT, msg, ref hwnd);
|
||||||
// if (rc == STS.SUCCESS) Session._appIdentityLegacy = app;
|
// if (rc == STS.SUCCESS) Session._appIdentity = app;
|
||||||
//}
|
//}
|
||||||
else if (TwainPlatform.IsMacOSX)
|
else if (TwainPlatform.IsMacOSX)
|
||||||
{
|
{
|
||||||
var app = Session._appIdentityOSX;
|
TW_IDENTITY_MACOSX app = Session._appIdentity;
|
||||||
if (TwainPlatform.PreferLegacyDSM)
|
if (TwainPlatform.PreferLegacyDSM)
|
||||||
{
|
{
|
||||||
rc = (STS)NativeMethods.MacosxTwainDsmEntryParent(ref app, IntPtr.Zero, DG.CONTROL, DAT.PARENT, msg, ref hwnd);
|
rc = (STS)NativeMethods.MacosxTwainDsmEntryParent(ref app, IntPtr.Zero, DG.CONTROL, DAT.PARENT, msg, ref hwnd);
|
||||||
@@ -90,8 +93,7 @@ namespace NTwain.Triplets
|
|||||||
}
|
}
|
||||||
if (rc == STS.SUCCESS)
|
if (rc == STS.SUCCESS)
|
||||||
{
|
{
|
||||||
Session._appIdentityOSX = app;
|
Session._appIdentity = app;
|
||||||
Session._appIdentityLegacy = app;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
|
|||||||
@@ -21,18 +21,20 @@ namespace NTwain
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the app identity.
|
/// Gets the app identity.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TW_IDENTITY_LEGACY AppIdentity => _appIdentityLegacy;
|
public TW_IDENTITY_LEGACY AppIdentity => _appIdentity;
|
||||||
internal TW_IDENTITY_LEGACY _appIdentityLegacy;
|
internal TW_IDENTITY_LEGACY _appIdentity;
|
||||||
//internal TW_IDENTITY _appIdentity;
|
|
||||||
internal TW_IDENTITY_MACOSX _appIdentityOSX;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the current data source.
|
/// Gets the current data source.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TW_IDENTITY_LEGACY DSIdentity => _dsIdentityLegacy;
|
public TW_IDENTITY_LEGACY CurrentDS => _currentDS;
|
||||||
internal TW_IDENTITY_LEGACY _dsIdentityLegacy;
|
internal TW_IDENTITY_LEGACY _currentDS;
|
||||||
//internal TW_IDENTITY _dsIdentity;
|
|
||||||
internal TW_IDENTITY_MACOSX _dsIdentityOSX;
|
/// <summary>
|
||||||
|
/// Gets the default data source.
|
||||||
|
/// </summary>
|
||||||
|
public TW_IDENTITY_LEGACY DefaultDS => _defaultDS;
|
||||||
|
internal TW_IDENTITY_LEGACY _defaultDS;
|
||||||
|
|
||||||
private STATE _state = STATE.S1;
|
private STATE _state = STATE.S1;
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ namespace NTwain
|
|||||||
__encodingRegistered = true;
|
__encodingRegistered = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
_appIdentityLegacy = new()
|
_appIdentity; = new()
|
||||||
{
|
{
|
||||||
Manufacturer = companyName,
|
Manufacturer = companyName,
|
||||||
ProductFamily = productFamily,
|
ProductFamily = productFamily,
|
||||||
@@ -76,8 +76,8 @@ namespace NTwain
|
|||||||
MinorNum = (ushort)productVersion.Minor,
|
MinorNum = (ushort)productVersion.Minor,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
//if (TwainPlatform.IsLinux) _appIdentity = _appIdentityLegacy;
|
//if (TwainPlatform.IsLinux) _appIdentity = _appIdentity;
|
||||||
if (TwainPlatform.IsMacOSX) _appIdentityOSX = _appIdentityLegacy;
|
if (TwainPlatform.IsMacOSX) _appIdentityOSX = _appIdentity;;
|
||||||
|
|
||||||
DGControl = new DGControl(this);
|
DGControl = new DGControl(this);
|
||||||
DGImage = new DGImage(this);
|
DGImage = new DGImage(this);
|
||||||
|
|||||||
Reference in New Issue
Block a user