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 ************************************************************************/
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
;
49 virtual ~BitmapTransporter();
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
)(); }
62 void lock() { m_aProtector
.acquire(); }
63 void unlock() { m_aProtector
.release(); }
64 SvMemoryStream
& getStream() { return m_aStream
; }
75 static oslModule pSaneLib
;
77 static SANE_Status (*p_init
)( SANE_Int
*,
79 static void (*p_exit
)();
80 static SANE_Status (*p_get_devices
)( const SANE_Device
***,
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
,
89 static SANE_Status (*p_get_parameters
)( SANE_Handle
,
91 static SANE_Status (*p_start
)( SANE_Handle
);
92 static SANE_Status (*p_read
)( SANE_Handle
, SANE_Byte
*, 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
;
103 const SANE_Option_Descriptor
** mppOptions
;
106 SANE_Handle maHandle
;
108 Link maReloadOptionsLink
;
110 inline oslGenericFunction
111 LoadSymbol( const char* );
115 SANE_Status
ControlOption( int, SANE_Action
, void* );
117 BOOL
CheckConsistency( const char*, BOOL bInit
= FALSE
);
124 { return pSaneLib
? TRUE
: FALSE
; }
126 { return maHandle
? TRUE
: FALSE
; }
127 static int CountDevices()
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* );
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
);
193 inline Link
Sane::SetReloadOptionsHdl( const Link
& rLink
)
195 Link aRet
= maReloadOptionsLink
;
196 maReloadOptionsLink
= rLink
;