update dev300-m58
[ooovba.git] / extensions / source / scanner / sane.hxx
blobd7191f5c2c561c131af869122c0811d4c220c292
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sane.hxx,v $
10 * $Revision: 1.8.64.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef _SANE_HXX
31 #define _SANE_HXX
33 #include <osl/thread.h>
34 #include <osl/module.h>
35 #include <tools/string.hxx>
36 #include <vcl/bitmap.hxx>
37 #include <sane/sane.h>
38 #include <scanner.hxx>
40 // ---------------------
41 // - BitmapTransporter -
42 // ---------------------
44 class BitmapTransporter : public OWeakObject, AWT::XBitmap
46 SvMemoryStream m_aStream;
47 vos::OMutex m_aProtector;
49 public:
51 BitmapTransporter();
52 virtual ~BitmapTransporter();
55 // XInterface
56 virtual ANY SAL_CALL queryInterface( const Type & rType ) throw( RuntimeException );
57 virtual void SAL_CALL acquire() throw() { OWeakObject::acquire(); }
58 virtual void SAL_CALL release() throw() { OWeakObject::release(); }
60 virtual AWT::Size SAL_CALL getSize() throw();
61 virtual SEQ( sal_Int8 ) SAL_CALL getDIB() throw();
62 virtual SEQ( sal_Int8 ) SAL_CALL getMaskDIB() throw() { return SEQ( sal_Int8 )(); }
64 // Misc
65 void lock() { m_aProtector.acquire(); }
66 void unlock() { m_aProtector.release(); }
67 SvMemoryStream& getStream() { return m_aStream; }
70 // --------
71 // - Sane -
72 // --------
74 class Sane
76 private:
77 static int nRefCount;
78 static oslModule pSaneLib;
80 static SANE_Status (*p_init)( SANE_Int*,
81 SANE_Auth_Callback );
82 static void (*p_exit)();
83 static SANE_Status (*p_get_devices)( const SANE_Device***,
84 SANE_Bool );
85 static SANE_Status (*p_open)( SANE_String_Const, SANE_Handle );
86 static void (*p_close)( SANE_Handle );
87 static const SANE_Option_Descriptor* (*p_get_option_descriptor)(
88 SANE_Handle, SANE_Int );
89 static SANE_Status (*p_control_option)( SANE_Handle, SANE_Int,
90 SANE_Action, void*,
91 SANE_Int* );
92 static SANE_Status (*p_get_parameters)( SANE_Handle,
93 SANE_Parameters* );
94 static SANE_Status (*p_start)( SANE_Handle );
95 static SANE_Status (*p_read)( SANE_Handle, SANE_Byte*, SANE_Int,
96 SANE_Int* );
97 static void (*p_cancel)( SANE_Handle );
98 static SANE_Status (*p_set_io_mode)( SANE_Handle, SANE_Bool );
99 static SANE_Status (*p_get_select_fd)( SANE_Handle, SANE_Int* );
100 static SANE_String_Const (*p_strstatus)( SANE_Status );
102 static SANE_Int nVersion;
103 static SANE_Device** ppDevices;
104 static int nDevices;
106 const SANE_Option_Descriptor** mppOptions;
107 int mnOptions;
108 int mnDevice;
109 SANE_Handle maHandle;
111 Link maReloadOptionsLink;
113 inline oslGenericFunction
114 LoadSymbol( const char* );
115 void Init();
116 void DeInit();
118 SANE_Status ControlOption( int, SANE_Action, void* );
120 BOOL CheckConsistency( const char*, BOOL bInit = FALSE );
122 public:
123 Sane();
124 ~Sane();
126 static BOOL IsSane()
127 { return pSaneLib ? TRUE : FALSE; }
128 BOOL IsOpen()
129 { return maHandle ? TRUE : FALSE; }
130 static int CountDevices()
131 { return nDevices; }
132 static String GetName( int n )
133 { return String( ppDevices[n]->name ? ppDevices[n]->name : "", osl_getThreadTextEncoding() ); }
134 static String GetVendor( int n )
135 { return String( ppDevices[n]->vendor ? ppDevices[n]->vendor : "", osl_getThreadTextEncoding() ); }
136 static String GetModel( int n )
137 { return String( ppDevices[n]->model ? ppDevices[n]->model : "", osl_getThreadTextEncoding() ); }
138 static String GetType( int n )
139 { return String( ppDevices[n]->type ? ppDevices[n]->type : "", osl_getThreadTextEncoding() ); }
141 String GetOptionName( int n )
142 { return String( mppOptions[n]->name ? (char*)mppOptions[n]->name : "", osl_getThreadTextEncoding() ); }
143 String GetOptionTitle( int n )
144 { return String( mppOptions[n]->title ? (char*)mppOptions[n]->title : "", osl_getThreadTextEncoding() ); }
145 SANE_Value_Type GetOptionType( int n )
146 { return mppOptions[n]->type; }
147 SANE_Unit GetOptionUnit( int n )
148 { return mppOptions[n]->unit; }
149 String GetOptionUnitName( int n );
150 SANE_Int GetOptionCap( int n )
151 { return mppOptions[n]->cap; }
152 SANE_Constraint_Type GetOptionConstraintType( int n )
153 { return mppOptions[n]->constraint_type; }
154 const char** GetStringConstraint( int n )
155 { return (const char**)mppOptions[n]->constraint.string_list; }
156 int GetRange( int, double*& );
158 inline int GetOptionElements( int n );
159 int GetOptionByName( const char* );
160 BOOL GetOptionValue( int, BOOL& );
161 BOOL GetOptionValue( int, ByteString& );
162 BOOL GetOptionValue( int, double&, int nElement = 0 );
163 BOOL GetOptionValue( int, double* );
165 BOOL SetOptionValue( int, BOOL );
166 BOOL SetOptionValue( int, const String& );
167 BOOL SetOptionValue( int, double, int nElement = 0 );
168 BOOL SetOptionValue( int, double* );
170 BOOL ActivateButtonOption( int );
172 int CountOptions() { return mnOptions; }
173 int GetDeviceNumber() { return mnDevice; }
175 BOOL Open( const char* );
176 BOOL Open( int );
177 void Close();
178 void ReloadDevices();
179 void ReloadOptions();
181 BOOL Start( BitmapTransporter& );
183 inline Link SetReloadOptionsHdl( const Link& rLink );
186 inline int Sane::GetOptionElements( int n )
188 if( mppOptions[n]->type == SANE_TYPE_FIXED ||
189 mppOptions[n]->type == SANE_TYPE_INT )
191 return mppOptions[n]->size/sizeof( SANE_Word );
193 return 1;
196 inline Link Sane::SetReloadOptionsHdl( const Link& rLink )
198 Link aRet = maReloadOptionsLink;
199 maReloadOptionsLink = rLink;
200 return aRet;
203 #endif