1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <osl/thread.h>
23 #include <osl/module.h>
24 #include <tools/string.hxx>
25 #include <vcl/bitmap.hxx>
26 #include <sane/sane.h>
27 #include <scanner.hxx>
29 // ---------------------
30 // - BitmapTransporter -
31 // ---------------------
33 class BitmapTransporter
: public OWeakObject
, css::awt::XBitmap
35 SvMemoryStream m_aStream
;
36 osl::Mutex m_aProtector
;
41 virtual ~BitmapTransporter();
45 virtual Any SAL_CALL
queryInterface( const Type
& rType
) throw( RuntimeException
);
46 virtual void SAL_CALL
acquire() throw() { OWeakObject::acquire(); }
47 virtual void SAL_CALL
release() throw() { OWeakObject::release(); }
49 virtual css::awt::Size SAL_CALL
getSize() throw();
50 virtual Sequence
< sal_Int8
> SAL_CALL
getDIB() throw();
51 virtual Sequence
< sal_Int8
> SAL_CALL
getMaskDIB() throw() { return Sequence
< sal_Int8
>(); }
54 void lock() { m_aProtector
.acquire(); }
55 void unlock() { m_aProtector
.release(); }
56 SvMemoryStream
& getStream() { return m_aStream
; }
67 static oslModule pSaneLib
;
69 static SANE_Status (*p_init
)( SANE_Int
*,
71 static void (*p_exit
)();
72 static SANE_Status (*p_get_devices
)( const SANE_Device
***,
74 static SANE_Status (*p_open
)( SANE_String_Const
, SANE_Handle
);
75 static void (*p_close
)( SANE_Handle
);
76 static const SANE_Option_Descriptor
* (*p_get_option_descriptor
)(
77 SANE_Handle
, SANE_Int
);
78 static SANE_Status (*p_control_option
)( SANE_Handle
, SANE_Int
,
81 static SANE_Status (*p_get_parameters
)( SANE_Handle
,
83 static SANE_Status (*p_start
)( SANE_Handle
);
84 static SANE_Status (*p_read
)( SANE_Handle
, SANE_Byte
*, SANE_Int
,
86 static void (*p_cancel
)( SANE_Handle
);
87 static SANE_Status (*p_set_io_mode
)( SANE_Handle
, SANE_Bool
);
88 static SANE_Status (*p_get_select_fd
)( SANE_Handle
, SANE_Int
* );
89 static SANE_String_Const (*p_strstatus
)( SANE_Status
);
91 static SANE_Int nVersion
;
92 static SANE_Device
** ppDevices
;
95 const SANE_Option_Descriptor
** mppOptions
;
100 Link maReloadOptionsLink
;
102 inline oslGenericFunction
103 LoadSymbol( const char* );
107 SANE_Status
ControlOption( int, SANE_Action
, void* );
109 sal_Bool
CheckConsistency( const char*, sal_Bool bInit
= sal_False
);
115 static sal_Bool
IsSane()
116 { return pSaneLib
? sal_True
: sal_False
; }
118 { return maHandle
? sal_True
: sal_False
; }
119 static int CountDevices()
121 static String
GetName( int n
)
122 { return String( ppDevices
[n
]->name
? ppDevices
[n
]->name
: "", osl_getThreadTextEncoding() ); }
123 static String
GetVendor( int n
)
124 { return String( ppDevices
[n
]->vendor
? ppDevices
[n
]->vendor
: "", osl_getThreadTextEncoding() ); }
125 static String
GetModel( int n
)
126 { return String( ppDevices
[n
]->model
? ppDevices
[n
]->model
: "", osl_getThreadTextEncoding() ); }
127 static String
GetType( int n
)
128 { return String( ppDevices
[n
]->type
? ppDevices
[n
]->type
: "", osl_getThreadTextEncoding() ); }
130 String
GetOptionName( int n
)
131 { return String( mppOptions
[n
]->name
? (char*)mppOptions
[n
]->name
: "", osl_getThreadTextEncoding() ); }
132 String
GetOptionTitle( int n
)
133 { return String( mppOptions
[n
]->title
? (char*)mppOptions
[n
]->title
: "", osl_getThreadTextEncoding() ); }
134 SANE_Value_Type
GetOptionType( int n
)
135 { return mppOptions
[n
]->type
; }
136 SANE_Unit
GetOptionUnit( int n
)
137 { return mppOptions
[n
]->unit
; }
138 String
GetOptionUnitName( int n
);
139 SANE_Int
GetOptionCap( int n
)
140 { return mppOptions
[n
]->cap
; }
141 SANE_Constraint_Type
GetOptionConstraintType( int n
)
142 { return mppOptions
[n
]->constraint_type
; }
143 const char** GetStringConstraint( int n
)
144 { return (const char**)mppOptions
[n
]->constraint
.string_list
; }
145 int GetRange( int, double*& );
147 inline int GetOptionElements( int n
);
148 int GetOptionByName( const char* );
149 sal_Bool
GetOptionValue( int, sal_Bool
& );
150 sal_Bool
GetOptionValue( int, OString
& );
151 sal_Bool
GetOptionValue( int, double&, int nElement
= 0 );
152 sal_Bool
GetOptionValue( int, double* );
154 sal_Bool
SetOptionValue( int, sal_Bool
);
155 sal_Bool
SetOptionValue( int, const String
& );
156 sal_Bool
SetOptionValue( int, double, int nElement
= 0 );
157 sal_Bool
SetOptionValue( int, double* );
159 sal_Bool
ActivateButtonOption( int );
161 int CountOptions() { return mnOptions
; }
162 int GetDeviceNumber() { return mnDevice
; }
164 sal_Bool
Open( const char* );
165 sal_Bool
Open( int );
167 void ReloadDevices();
168 void ReloadOptions();
170 sal_Bool
Start( BitmapTransporter
& );
172 inline Link
SetReloadOptionsHdl( const Link
& rLink
);
175 inline int Sane::GetOptionElements( int n
)
177 if( mppOptions
[n
]->type
== SANE_TYPE_FIXED
||
178 mppOptions
[n
]->type
== SANE_TYPE_INT
)
180 return mppOptions
[n
]->size
/sizeof( SANE_Word
);
185 inline Link
Sane::SetReloadOptionsHdl( const Link
& rLink
)
187 Link aRet
= maReloadOptionsLink
;
188 maReloadOptionsLink
= rLink
;
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */