wxIScan
wxscan.h
Go to the documentation of this file.
00001 /***************************************************************
00002  * Name:      wxiscanframe.h
00003  * Purpose:   wxWidgets wrapper around libsane (for scanner
00004  *            access)
00005  * Author:    Daniel Nell (daniel.nell@nellresearch.de)
00006  * Created:   2008-05-04
00007  * Copyright: Daniel Nell (www.nellresearch.de)
00008  * License:   wxWindows license
00009 **************************************************************/
00010 
00011 #ifndef WXSCAN_H_INCLUDED
00012 #define WXSCAN_H_INCLUDED
00013 
00014 // Define some macros for several scanning environments.
00015 #if defined( __UNIX_LIKE__ )
00016 #   define __WXSCANSANE__   1
00017 #elif defined( __WXMSW__ )
00018 #   define wxScan           wxScanTwain
00019 #   define __WXSCANTWAIN__  1
00020 #endif
00021 
00022 // Include additional headers.
00023 #if __WXSCANSANE__
00024 #   include <sane/sane.h>
00025 #elif __WXSCANTWAIN__
00026 #
00027 #else
00028 #
00029 #endif
00030 #include <wx/arrstr.h>
00031 
00032 //////////////////////////////////////////////////////////
00033 // Class wxScanBase
00034 //
00035 /// \brief Abstract base class for all wxScan... classes.
00036 ///
00037 /// This class represents an interface to the various
00038 /// wxScan... classes. Note that every member function
00039 /// has to be implemented in the subclasses.
00040 class wxScanBase
00041 {
00042   public:
00043     /// Standard constructor
00044     wxScanBase(){}
00045 
00046     /// Virtual destructor
00047     virtual ~wxScanBase(){}
00048 
00049     /// Check if the error state is 'OK'. This function returns 'true' on 'OK'.
00050     virtual bool IsOk() = 0;
00051 
00052     /// Check if the scan device is available.
00053     virtual bool IsDeviceAvailable() = 0;
00054 
00055     /// Get the scanning resolution
00056     virtual int  GetResolution() = 0;
00057 
00058     /// \brief Scan an image.
00059     ///
00060     /// \param oImage   a reference to the image object that should hold the image
00061     ///
00062     /// The result is in the parameter oImage.
00063     virtual bool ScanImage( wxImage &oImage ) = 0;
00064 };
00065 
00066 #if __WXSCANSANE__
00067 
00068 // Define some convenience macros.
00069     #define SANE_STRING_TO_WXSTRING( SaneString )                                  \
00070         wxString( (const char *)SaneString, wxConvISO8859_1 )
00071 
00072 #define GET_DEVICE_PARAM( PARAM )                                              \
00073     if( nIndex < 0 )                                                           \
00074     {                                                                          \
00075         nIndex= m_nDeviceIndex;                                                \
00076     }                                                                          \
00077     if( ( nIndex >= 0 ) && ( nIndex < m_nDeviceCount ) )                       \
00078     {                                                                          \
00079         return SANE_STRING_TO_WXSTRING( m_ppDeviceList[nIndex]->PARAM );       \
00080     }                                                                          \
00081     return wxEmptyString;
00082 
00083 //////////////////////////////////////////////////////////
00084 // Class wxScanSane
00085 //
00086 /// \brief SANE incarnation of the the wxScan... classes.
00087 ///
00088 /// This class is the default class (wxScan) for UNIX like
00089 /// systems or any other system using SANE as its scanning
00090 /// interface.
00091 ///
00092 /// Note: There should be a SANE implementation for MS
00093 ///       Windows, too, at least for network based
00094 ///       scanning.
00095 class wxScanSane : public wxScanBase
00096 {
00097   public:
00098     /// \brief Standard constructor
00099     ///
00100     /// \param bOnlyLocalDevices    flag to use only local scanning devices
00101     ///                             (default) or devices via network, too.
00102     wxScanSane( bool bOnlyLocalDevices= false );
00103 
00104     /// Virtual destructor.
00105     virtual ~wxScanSane();
00106 
00107     /// Check if the error state is 'OK'. This function returns 'true' on 'OK'.
00108     virtual bool IsOk()
00109     {
00110         return ( m_SaneStatus == SANE_STATUS_GOOD ) ? true : false;
00111     }
00112 
00113     /// Check if the scan device is available.
00114     virtual bool IsDeviceAvailable()
00115     {
00116         return ( m_nDeviceCount <= 0 ) || ( m_nDeviceIndex < 0 ) || ( m_nDeviceIndex >= m_nDeviceCount ) ? false : true;
00117     }
00118 
00119     /// \brief Scan an image.
00120     ///
00121     /// \param oImage   a reference to the image object that should hold the image
00122     ///
00123     /// The result is in the parameter oImage.
00124     virtual bool ScanImage( wxImage &oImage );
00125 
00126     /// Get the scanning resolution
00127     virtual int GetResolution()
00128     {
00129         return m_nResolution;
00130     }
00131 
00132     /// Get the count of the detected scanning devices.
00133     virtual int GetDeviceCount()
00134     {
00135         return m_nDeviceCount;
00136     }
00137 
00138     /// Get the count of the detected scanning devices.
00139     virtual int GetDeviceIndex()
00140     {
00141         return m_nDeviceIndex;
00142     }
00143 
00144     /// Get the scanning device name by index number.
00145     virtual wxString GetDeviceName( int nIndex= -1 )
00146     {
00147         GET_DEVICE_PARAM( name )
00148     }
00149 
00150     /// Get the scanning device vender by index number.
00151     virtual wxString GetDeviceVendor( int nIndex= -1 )
00152     {
00153         GET_DEVICE_PARAM( vendor )
00154     }
00155 
00156     /// Get the scanning device model name by index number.
00157     virtual wxString GetDeviceModel( int nIndex= -1 )
00158     {
00159         GET_DEVICE_PARAM( model )
00160     }
00161 
00162     /// Get the scanning device type by index number.
00163     virtual wxString GetDeviceType( int nIndex= -1 )
00164     {
00165         GET_DEVICE_PARAM( type )
00166     }
00167 
00168     /// Select the scanning device by index number.
00169     virtual bool SetDeviceIndex( int nIndex );
00170 
00171     /// Get the SANE status.
00172     virtual SANE_Status GetSaneStatus()
00173     {
00174         return m_SaneStatus;
00175     }
00176 
00177     /// Geth the SANE status as string.
00178     virtual wxString GetSaneStatusString()
00179     {
00180         return SANE_STRING_TO_WXSTRING( ::sane_strstatus( GetSaneStatus() ) );
00181     }
00182 
00183     /// Get the scan device list.
00184     virtual bool SaneGetDevices();
00185 
00186   private:
00187     /// Flag ...
00188     bool m_bOnlyLocalDevices;
00189 
00190     /// holds the SANE status
00191     SANE_Status m_SaneStatus;
00192 
00193     /// holds the SANE device list
00194     const SANE_Device **m_ppDeviceList;
00195 
00196     /// holds the number of SANE devices
00197     int m_nDeviceCount;
00198 
00199     /// holds the index of the standard SANE device
00200     int m_nDeviceIndex;
00201 
00202     /// holds the scanning resolution
00203     int m_nResolution;
00204 };
00205 
00206 // Define the standard wxScan object.
00207 typedef wxScanSane wxScan;
00208 #endif // __WXSCANSANE__
00209 
00210 #if __WXSCANTWAIN__
00211 //////////////////////////////////////////////////////////
00212 // Class wxScanTwain
00213 //
00214 /// \brief TWAIN incarnation of the the wxScan... classes.
00215 ///
00216 /// This class is the default class (wxScan) for Windows
00217 /// systems.
00218 ///
00219 /// Note: At the moment this class is only a stub for to
00220 ///       start porting wxScan base applications to
00221 ///       MS Windows.
00222 class wxScanTwain
00223 {
00224   public:
00225     /// Standard constructor
00226     wxScanTwain(){}
00227 
00228     /// Virtual destructor
00229     virtual ~wxScanTwain(){}
00230 
00231     /// Check if the error state is 'OK'. This function returns 'true' on 'OK'.
00232     ///
00233     /// Note: This function is currently only a stub and returns a dummy value.
00234     virtual bool IsOk(){ return false; }
00235 
00236     /// Check if the scan device is available.
00237     ///
00238     /// Note: This function is currently only a stub and returns a dummy value.
00239     virtual bool IsDeviceAvailable(){ return false; }
00240 
00241     /// Get the scanning resolution
00242     ///
00243     /// Note: This function is currently only a stub and returns a dummy value.
00244     virtual int  GetResolution(){ return 0; }
00245 
00246     /// \brief Scan an image.
00247     ///
00248     /// \param oImage   a reference to the image object that should hold the image
00249     ///
00250     /// The result is in the parameter oImage.
00251     ///
00252     /// Note: This function is currently only a stub and returns a dummy value
00253     ///       (false).
00254     virtual bool ScanImage( wxImage &oImage ){ return false; };
00255 };
00256 
00257 // Define the standard wxScan object.
00258 typedef wxScanTwain wxScan;
00259 #endif // __WXSCANTWAIN__
00260 
00261 #endif // WXSCAN_H_INCLUDED