mirror of
https://github.com/soukoku/ntwain.git
synced 2025-04-05 20:59:23 +08:00
Changed when callbacks are registered.
This commit is contained in:
parent
1ce7c5caf5
commit
8d30e9066f
@ -38,6 +38,7 @@ namespace NTwain
|
|||||||
Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: OpenSource.", Thread.CurrentThread.ManagedThreadId));
|
Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: OpenSource.", Thread.CurrentThread.ManagedThreadId));
|
||||||
|
|
||||||
rc = _session.DGControl.Identity.OpenDS(this);
|
rc = _session.DGControl.Identity.OpenDS(this);
|
||||||
|
_session.UpdateCallback();
|
||||||
});
|
});
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@ -58,6 +59,7 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
SupportedCaps = null;
|
SupportedCaps = null;
|
||||||
}
|
}
|
||||||
|
_session.UpdateCallback();
|
||||||
});
|
});
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,8 @@ namespace NTwain.Internals
|
|||||||
|
|
||||||
void ChangeCurrentSource(DataSource source);
|
void ChangeCurrentSource(DataSource source);
|
||||||
|
|
||||||
|
void UpdateCallback();
|
||||||
|
|
||||||
ReturnCode DisableSource();
|
ReturnCode DisableSource();
|
||||||
|
|
||||||
void SafeSyncableRaiseEvent(DataTransferredEventArgs e);
|
void SafeSyncableRaiseEvent(DataTransferredEventArgs e);
|
||||||
|
@ -27,6 +27,44 @@ namespace NTwain
|
|||||||
/// <value>The app id.</value>
|
/// <value>The app id.</value>
|
||||||
TWIdentity ITwainSessionInternal.AppId { get { return _appId; } }
|
TWIdentity ITwainSessionInternal.AppId { get { return _appId; } }
|
||||||
|
|
||||||
|
void ITwainSessionInternal.UpdateCallback()
|
||||||
|
{
|
||||||
|
if (State < 4)
|
||||||
|
{
|
||||||
|
_callbackObj = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ReturnCode rc = ReturnCode.Failure;
|
||||||
|
// per the spec (8-10) apps for 2.2 or higher uses callback2 so try this first
|
||||||
|
if (_appId.ProtocolMajor > 2 || (_appId.ProtocolMajor >= 2 && _appId.ProtocolMinor >= 2))
|
||||||
|
{
|
||||||
|
var cb = new TWCallback2(HandleCallback);
|
||||||
|
rc = ((ITwainSessionInternal)this).DGControl.Callback2.RegisterCallback(cb);
|
||||||
|
|
||||||
|
if (rc == ReturnCode.Success)
|
||||||
|
{
|
||||||
|
Debug.WriteLine("Registered callback2 OK.");
|
||||||
|
_callbackObj = cb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rc != ReturnCode.Success)
|
||||||
|
{
|
||||||
|
// always try old callback
|
||||||
|
var cb = new TWCallback(HandleCallback);
|
||||||
|
|
||||||
|
rc = ((ITwainSessionInternal)this).DGControl.Callback.RegisterCallback(cb);
|
||||||
|
|
||||||
|
if (rc == ReturnCode.Success)
|
||||||
|
{
|
||||||
|
Debug.WriteLine("Registered callback OK.");
|
||||||
|
_callbackObj = cb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ITwainSessionInternal.ChangeState(int newState, bool notifyChange)
|
void ITwainSessionInternal.ChangeState(int newState, bool notifyChange)
|
||||||
{
|
{
|
||||||
_state = newState;
|
_state = newState;
|
||||||
@ -122,54 +160,19 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: EnableSource with {1}.", Thread.CurrentThread.ManagedThreadId, mode));
|
Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: EnableSource with {1}.", Thread.CurrentThread.ManagedThreadId, mode));
|
||||||
|
|
||||||
// per the spec (8-10) app v2.2 or higher uses callback2
|
|
||||||
if (_appId.ProtocolMajor > 2 || (_appId.ProtocolMajor >= 2 && _appId.ProtocolMinor >= 2))
|
|
||||||
{
|
|
||||||
var cb = new TWCallback2(HandleCallback);
|
|
||||||
var rc2 = ((ITwainSessionInternal)this).DGControl.Callback2.RegisterCallback(cb);
|
|
||||||
|
|
||||||
if (rc2 == ReturnCode.Success)
|
|
||||||
{
|
|
||||||
Debug.WriteLine("Registered callback2 OK.");
|
|
||||||
_callbackObj = cb;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// all else try old callback
|
|
||||||
var cb = new TWCallback(HandleCallback);
|
|
||||||
|
|
||||||
var rc2 = ((ITwainSessionInternal)this).DGControl.Callback.RegisterCallback(cb);
|
|
||||||
|
|
||||||
if (rc2 == ReturnCode.Success)
|
|
||||||
{
|
|
||||||
Debug.WriteLine("Registered callback OK.");
|
|
||||||
_callbackObj = cb;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_twui = new TWUserInterface();
|
_twui = new TWUserInterface();
|
||||||
_twui.ShowUI = mode == SourceEnableMode.ShowUI;
|
_twui.ShowUI = mode == SourceEnableMode.ShowUI;
|
||||||
_twui.ModalUI = modal;
|
_twui.ModalUI = modal;
|
||||||
_twui.hParent = windowHandle;
|
_twui.hParent = windowHandle;
|
||||||
|
|
||||||
try
|
if (mode == SourceEnableMode.ShowUIOnly)
|
||||||
{
|
{
|
||||||
if (mode == SourceEnableMode.ShowUIOnly)
|
rc = ((ITwainSessionInternal)this).DGControl.UserInterface.EnableDSUIOnly(_twui);
|
||||||
{
|
|
||||||
rc = ((ITwainSessionInternal)this).DGControl.UserInterface.EnableDSUIOnly(_twui);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rc = ((ITwainSessionInternal)this).DGControl.UserInterface.EnableDS(_twui);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
finally
|
else
|
||||||
{
|
{
|
||||||
if (rc != ReturnCode.Success)
|
rc = ((ITwainSessionInternal)this).DGControl.UserInterface.EnableDS(_twui);
|
||||||
{
|
|
||||||
_callbackObj = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return rc;
|
return rc;
|
||||||
@ -191,7 +194,6 @@ namespace NTwain
|
|||||||
rc = ((ITwainSessionInternal)this).DGControl.UserInterface.DisableDS(_twui);
|
rc = ((ITwainSessionInternal)this).DGControl.UserInterface.DisableDS(_twui);
|
||||||
if (rc == ReturnCode.Success)
|
if (rc == ReturnCode.Success)
|
||||||
{
|
{
|
||||||
_callbackObj = null;
|
|
||||||
SafeAsyncSyncableRaiseOnEvent(OnSourceDisabled, SourceDisabled);
|
SafeAsyncSyncableRaiseOnEvent(OnSourceDisabled, SourceDisabled);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user