Esempio n. 1
0
        /// <summary>
        /// Rollback the TWAIN state to whatever is requested...
        /// </summary>
        /// <param name="a_state"></param>
        public void Rollback(TWAIN.STATE a_state)
        {
            TWAIN.TW_PENDINGXFERS  twpendingxfers  = default(TWAIN.TW_PENDINGXFERS);
            TWAIN.TW_USERINTERFACE twuserinterface = default(TWAIN.TW_USERINTERFACE);
            TWAIN.TW_IDENTITY      twidentity      = default(TWAIN.TW_IDENTITY);

            // Make sure we have something to work with...
            if (m_twain == null)
            {
                return;
            }

            // Walk the states, we don't care about the status returns.  Basically,
            // these need to work, or we're guaranteed to hang...

            // 7 --> 6
            if ((m_twain.GetState() == TWAIN.STATE.S7) && (a_state < TWAIN.STATE.S7))
            {
                m_twain.DatPendingxfers(TWAIN.DG.CONTROL, TWAIN.MSG.ENDXFER, ref twpendingxfers);
            }

            // 6 --> 5
            if ((m_twain.GetState() == TWAIN.STATE.S6) && (a_state < TWAIN.STATE.S6))
            {
                m_twain.DatPendingxfers(TWAIN.DG.CONTROL, TWAIN.MSG.RESET, ref twpendingxfers);
            }

            // 5 --> 4
            if ((m_twain.GetState() == TWAIN.STATE.S5) && (a_state < TWAIN.STATE.S5))
            {
                m_twain.DatUserinterface(TWAIN.DG.CONTROL, TWAIN.MSG.DISABLEDS, ref twuserinterface);
            }

            // 4 --> 3
            if ((m_twain.GetState() == TWAIN.STATE.S4) && (a_state < TWAIN.STATE.S4))
            {
                m_twain.CsvToIdentity(ref twidentity, m_twain.GetDsIdentity());
                m_twain.DatIdentity(TWAIN.DG.CONTROL, TWAIN.MSG.CLOSEDS, ref twidentity);
            }

            // 3 --> 2
            if ((m_twain.GetState() == TWAIN.STATE.S3) && (a_state < TWAIN.STATE.S3))
            {
                m_twain.DatParent(TWAIN.DG.CONTROL, TWAIN.MSG.CLOSEDSM, ref m_intptrHwnd);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Handle DG_CONTROL / DAT_USERINTERFACE / MSG_*
        /// </summary>
        /// <param name="a_dg">Data group</param>
        /// <param name="a_msg">Operation</param>
        /// <param name="a_szStatus">Result of operation</param>
        /// <param name="a_szMemref">Pointer to data</param>
        /// <returns>TWAIN status</returns>
        private STS SendDatUserinterface(TWAIN.DG a_dg, TWAIN.MSG a_msg, ref string a_szStatus, ref string a_szMemref)
        {
            TWAIN.STS sts;
            TWAIN.TW_USERINTERFACE twuserinterface;

            // Clear or get...
            a_szStatus = "";
            twuserinterface = default(TWAIN.TW_USERINTERFACE);
            if (!m_twain.CsvToUserinterface(ref twuserinterface, a_szMemref))
            {
                return (STS.BADVALUE);
            }

            // Issue the command...
            sts = m_twain.DatUserinterface(a_dg, a_msg, ref twuserinterface);
            if (sts == TWAIN.STS.SUCCESS)
            {
                // The state we want to rollback to when scanning is complete...
                if ((a_msg == TWAIN.MSG.ENABLEDS) && (twuserinterface.ShowUI != 0))
                {
                    m_stateAfterScan = TWAIN.STATE.S5;
                }
                else
                {
                    m_stateAfterScan = TWAIN.STATE.S4;
                }
            }

            // All done...
            return (CvtSts(sts));
        }