merged tag ooo/OOO330_m14
[LibreOffice.git] / extensions / source / scanner / sane.hxx
blob44ce0d295f42429638605e448e695a8b8bfb934c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
27 #ifndef _SANE_HXX
28 #define _SANE_HXX
30 #include <osl/thread.h>
31 #include <osl/module.h>
32 #include <tools/string.hxx>
33 #include <vcl/bitmap.hxx>
34 #include <sane/sane.h>
35 #include <scanner.hxx>
37 // ---------------------
38 // - BitmapTransporter -
39 // ---------------------
41 class BitmapTransporter : public OWeakObject, AWT::XBitmap
43 SvMemoryStream m_aStream;
44 vos::OMutex m_aProtector;
46 public:
48 BitmapTransporter();
49 virtual ~BitmapTransporter();
52 // XInterface
53 virtual ANY SAL_CALL queryInterface( const Type & rType ) throw( RuntimeException );
54 virtual void SAL_CALL acquire() throw() { OWeakObject::acquire(); }
55 virtual void SAL_CALL release() throw() { OWeakObject::release(); }
57 virtual AWT::Size SAL_CALL getSize() throw();
58 virtual SEQ( sal_Int8 ) SAL_CALL getDIB() throw();
59 virtual SEQ( sal_Int8 ) SAL_CALL getMaskDIB() throw() { return SEQ( sal_Int8 )(); }
61 // Misc
62 void lock() { m_aProtector.acquire(); }
63 void unlock() { m_aProtector.release(); }
64 SvMemoryStream& getStream() { return m_aStream; }
67 // --------
68 // - Sane -
69 // --------
71 class Sane
73 private:
74 static int nRefCount;
75 static oslModule pSaneLib;
77 static SANE_Status (*p_init)( SANE_Int*,
78 SANE_Auth_Callback );
79 static void (*p_exit)();
80 static SANE_Status (*p_get_devices)( const SANE_Device***,
81 SANE_Bool );
82 static SANE_Status (*p_open)( SANE_String_Const, SANE_Handle );
83 static void (*p_close)( SANE_Handle );
84 static const SANE_Option_Descriptor* (*p_get_option_descriptor)(
85 SANE_Handle, SANE_Int );
86 static SANE_Status (*p_control_option)( SANE_Handle, SANE_Int,
87 SANE_Action, void*,
88 SANE_Int* );
89 static SANE_Status (*p_get_parameters)( SANE_Handle,
90 SANE_Parameters* );
91 static SANE_Status (*p_start)( SANE_Handle );
92 static SANE_Status (*p_read)( SANE_Handle, SANE_Byte*, SANE_Int,
93 SANE_Int* );
94 static void (*p_cancel)( SANE_Handle );
95 static SANE_Status (*p_set_io_mode)( SANE_Handle, SANE_Bool );
96 static SANE_Status (*p_get_select_fd)( SANE_Handle, SANE_Int* );
97 static SANE_String_Const (*p_strstatus)( SANE_Status );
99 static SANE_Int nVersion;
100 static SANE_Device** ppDevices;
101 static int nDevices;
103 const SANE_Option_Descriptor** mppOptions;
104 int mnOptions;
105 int mnDevice;
106 SANE_Handle maHandle;
108 Link maReloadOptionsLink;
110 inline oslGenericFunction
111 LoadSymbol( const char* );
112 void Init();
113 void DeInit();
115 SANE_Status ControlOption( int, SANE_Action, void* );
117 BOOL CheckConsistency( const char*, BOOL bInit = FALSE );
119 public:
120 Sane();
121 ~Sane();
123 static BOOL IsSane()
124 { return pSaneLib ? TRUE : FALSE; }
125 BOOL IsOpen()
126 { return maHandle ? TRUE : FALSE; }
127 static int CountDevices()
128 { return nDevices; }
129 static String GetName( int n )
130 { return String( ppDevices[n]->name ? ppDevices[n]->name : "", osl_getThreadTextEncoding() ); }
131 static String GetVendor( int n )
132 { return String( ppDevices[n]->vendor ? ppDevices[n]->vendor : "", osl_getThreadTextEncoding() ); }
133 static String GetModel( int n )
134 { return String( ppDevices[n]->model ? ppDevices[n]->model : "", osl_getThreadTextEncoding() ); }
135 static String GetType( int n )
136 { return String( ppDevices[n]->type ? ppDevices[n]->type : "", osl_getThreadTextEncoding() ); }
138 String GetOptionName( int n )
139 { return String( mppOptions[n]->name ? (char*)mppOptions[n]->name : "", osl_getThreadTextEncoding() ); }
140 String GetOptionTitle( int n )
141 { return String( mppOptions[n]->title ? (char*)mppOptions[n]->title : "", osl_getThreadTextEncoding() ); }
142 SANE_Value_Type GetOptionType( int n )
143 { return mppOptions[n]->type; }
144 SANE_Unit GetOptionUnit( int n )
145 { return mppOptions[n]->unit; }
146 String GetOptionUnitName( int n );
147 SANE_Int GetOptionCap( int n )
148 { return mppOptions[n]->cap; }
149 SANE_Constraint_Type GetOptionConstraintType( int n )
150 { return mppOptions[n]->constraint_type; }
151 const char** GetStringConstraint( int n )
152 { return (const char**)mppOptions[n]->constraint.string_list; }
153 int GetRange( int, double*& );
155 inline int GetOptionElements( int n );
156 int GetOptionByName( const char* );
157 BOOL GetOptionValue( int, BOOL& );
158 BOOL GetOptionValue( int, ByteString& );
159 BOOL GetOptionValue( int, double&, int nElement = 0 );
160 BOOL GetOptionValue( int, double* );
162 BOOL SetOptionValue( int, BOOL );
163 BOOL SetOptionValue( int, const String& );
164 BOOL SetOptionValue( int, double, int nElement = 0 );
165 BOOL SetOptionValue( int, double* );
167 BOOL ActivateButtonOption( int );
169 int CountOptions() { return mnOptions; }
170 int GetDeviceNumber() { return mnDevice; }
172 BOOL Open( const char* );
173 BOOL Open( int );
174 void Close();
175 void ReloadDevices();
176 void ReloadOptions();
178 BOOL Start( BitmapTransporter& );
180 inline Link SetReloadOptionsHdl( const Link& rLink );
183 inline int Sane::GetOptionElements( int n )
185 if( mppOptions[n]->type == SANE_TYPE_FIXED ||
186 mppOptions[n]->type == SANE_TYPE_INT )
188 return mppOptions[n]->size/sizeof( SANE_Word );
190 return 1;
193 inline Link Sane::SetReloadOptionsHdl( const Link& rLink )
195 Link aRet = maReloadOptionsLink;
196 maReloadOptionsLink = rLink;
197 return aRet;
200 #endif