File indexing completed on 2024-04-28 04:32:19

0001 /*
0002  * SPDX-FileCopyrightText: 2002-2003 Stephan Stapel <stephan dot stapel at web dot de>
0003  * SPDX-FileCopyrightText: 2008-2009 Gilles Caulier <caulier dot gilles at gmail dot com>
0004  * SPDX-FileCopyrightText: 2009, 2017 Kare Sars <kare dot sars at iki dot fi>
0005  *
0006  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007  */
0008 
0009 #ifndef TWAINIFACE_H
0010 #define TWAINIFACE_H
0011 
0012 #include "twain.h"
0013 
0014 // Windows includes
0015 #include <windows.h>
0016 
0017 #include <QWidget>
0018 
0019 namespace KSaneIface
0020 {
0021 /**
0022  * Twain interface
0023  */
0024 class KSaneWidgetPrivate : public QWidget
0025 {
0026     Q_OBJECT
0027 
0028 public:
0029 
0030     KSaneWidgetPrivate();
0031     ~KSaneWidgetPrivate();
0032 
0033     /**
0034      * Hook-in. See class documentation for details!
0035      * @result    One should return false to get the message being
0036      *            processed by the application (should return false by default!)
0037      */
0038     bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
0039 
0040     void CloseDSM();
0041     QString SelectSource();
0042     bool OpenSource(const QString &device);
0043 
0044 public Q_SLOTS:
0045     bool OpenDialog();
0046     bool ReOpenDialog();
0047 
0048 Q_SIGNALS:
0049     void ImageReady(QByteArray &data, int width, int height, int bytes_per_line, int format);
0050     void qImageReady(const QImage &image);
0051 
0052 private:
0053 
0054     bool InitTwain();
0055     void ReleaseTwain();
0056 
0057     bool ProcessMessage(MSG msg);
0058 
0059     bool SetImageCount(TW_INT16 nCount = 1);
0060     bool DSIsOpen() const;
0061 
0062     bool CallTwainProc(pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
0063                        TW_UINT32 DG, TW_UINT16 DAT, TW_UINT16 MSG,
0064                        TW_MEMREF pData);
0065 
0066     bool EnableSource(bool showUI);
0067     void CloseDS();
0068 
0069     bool GetCapability(TW_CAPABILITY &twCap, TW_UINT16 cap, TW_UINT16 conType = TWON_DONTCARE16);
0070     bool GetCapability(TW_UINT16 cap, TW_UINT32 &value);
0071     bool SetCapability(TW_UINT16 cap, TW_UINT16 value, bool sign = false);
0072     bool SetCapability(TW_CAPABILITY &twCap);
0073 
0074     bool GetImageInfo(TW_IMAGEINFO &info);
0075 
0076     void TranslateMessage(TW_EVENT &twEvent);
0077     void TransferImage();
0078     bool EndTransfer();
0079     void CancelTransfer();
0080     bool GetImage(TW_IMAGEINFO &info);
0081 
0082     void ImageData(TW_MEMREF pdata, TW_IMAGEINFO &info);
0083 
0084 protected:
0085 
0086     bool         m_bDSMOpen;
0087     bool         m_bDSOpen;
0088     bool         m_bSourceEnabled;
0089     bool         m_bModalUI;
0090 
0091     int          m_nImageCount;
0092 
0093     HINSTANCE    m_hTwainDLL;
0094     DSMENTRYPROC m_pDSMProc;
0095 
0096     TW_IDENTITY  m_AppId;
0097     TW_IDENTITY  m_Source;
0098     TW_STATUS    m_Status;
0099     TW_INT16     m_returnCode;
0100     HWND         m_hMessageWnd;
0101 };
0102 
0103 }
0104 
0105 #endif /* TWAINIFACE_H */