2 * Copyright 2000 Corel Corporation
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(twain
);
30 /* DG_CONTROL/DAT_CAPABILITY/MSG_GET */
31 TW_UINT16
SANE_CapabilityGet (pTW_IDENTITY pOrigin
, TW_MEMREF pData
)
33 TW_UINT16 twRC
= TWRC_SUCCESS
, twCC
= TWCC_SUCCESS
;
34 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
36 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_GET\n");
38 if (activeDS
.currentState
< 4 || activeDS
.currentState
> 7)
41 activeDS
.twCC
= TWCC_SEQERROR
;
45 twCC
= SANE_SaneCapability (pCapability
, MSG_GET
);
46 twRC
= (twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
53 /* DG_CONTROL/DAT_CAPABILITY/MSG_GETCURRENT */
54 TW_UINT16
SANE_CapabilityGetCurrent (pTW_IDENTITY pOrigin
, TW_MEMREF pData
)
56 TW_UINT16 twRC
= TWRC_SUCCESS
, twCC
= TWCC_SUCCESS
;
57 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
59 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_GETCURRENT\n");
61 if (activeDS
.currentState
< 4 || activeDS
.currentState
> 7)
64 activeDS
.twCC
= TWCC_SEQERROR
;
68 twCC
= SANE_SaneCapability (pCapability
, MSG_GETCURRENT
);
69 twRC
= (twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
76 /* DG_CONTROL/DAT_CAPABILITY/MSG_GETDEFAULT */
77 TW_UINT16
SANE_CapabilityGetDefault (pTW_IDENTITY pOrigin
, TW_MEMREF pData
)
79 TW_UINT16 twRC
= TWRC_SUCCESS
, twCC
= TWCC_SUCCESS
;
80 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
82 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_GETDEFAULT\n");
84 if (activeDS
.currentState
< 4 || activeDS
.currentState
> 7)
87 activeDS
.twCC
= TWCC_SEQERROR
;
91 twCC
= SANE_SaneCapability (pCapability
, MSG_GETDEFAULT
);
92 twRC
= (twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
99 /* DG_CONTROL/DAT_CAPABILITY/MSG_QUERYSUPPORT */
100 TW_UINT16
SANE_CapabilityQuerySupport (pTW_IDENTITY pOrigin
,
103 TW_UINT16 twRC
= TWRC_SUCCESS
, twCC
= TWCC_SUCCESS
;
104 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
106 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_QUERYSUPPORT\n");
108 if (activeDS
.currentState
< 4 || activeDS
.currentState
> 7)
111 activeDS
.twCC
= TWCC_SEQERROR
;
115 twCC
= SANE_SaneCapability (pCapability
, MSG_QUERYSUPPORT
);
116 twRC
= (twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
117 activeDS
.twCC
= twCC
;
123 /* DG_CONTROL/DAT_CAPABILITY/MSG_RESET */
124 TW_UINT16
SANE_CapabilityReset (pTW_IDENTITY pOrigin
,
127 TW_UINT16 twRC
= TWRC_SUCCESS
, twCC
= TWCC_SUCCESS
;
128 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
130 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_RESET\n");
132 if (activeDS
.currentState
< 4 || activeDS
.currentState
> 7)
135 activeDS
.twCC
= TWCC_SEQERROR
;
139 twCC
= SANE_SaneCapability (pCapability
, MSG_RESET
);
140 twRC
= (twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
141 activeDS
.twCC
= twCC
;
147 /* DG_CONTROL/DAT_CAPABILITY/MSG_SET */
148 TW_UINT16
SANE_CapabilitySet (pTW_IDENTITY pOrigin
,
151 TW_UINT16 twRC
= TWRC_SUCCESS
, twCC
= TWCC_SUCCESS
;
152 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
154 TRACE ("DG_CONTROL/DAT_CAPABILITY/MSG_SET\n");
156 if (activeDS
.currentState
!= 4)
159 activeDS
.twCC
= TWCC_SEQERROR
;
163 twCC
= SANE_SaneCapability (pCapability
, MSG_SET
);
164 if (twCC
== TWCC_CHECKSTATUS
)
167 twRC
= TWRC_CHECKSTATUS
;
170 twRC
= (twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
171 activeDS
.twCC
= twCC
;
176 /* DG_CONTROL/DAT_EVENT/MSG_PROCESSEVENT */
177 TW_UINT16
SANE_ProcessEvent (pTW_IDENTITY pOrigin
,
180 TW_UINT16 twRC
= TWRC_NOTDSEVENT
;
181 pTW_EVENT pEvent
= (pTW_EVENT
) pData
;
182 MSG
*pMsg
= pEvent
->pEvent
;
184 TRACE("DG_CONTROL/DAT_EVENT/MSG_PROCESSEVENT msg 0x%x, wParam 0x%lx\n", pMsg
->message
, pMsg
->wParam
);
186 activeDS
.twCC
= TWCC_SUCCESS
;
187 if (pMsg
->message
== activeDS
.windowMessage
&& activeDS
.windowMessage
)
190 pEvent
->TWMessage
= pMsg
->wParam
;
193 pEvent
->TWMessage
= MSG_NULL
; /* no message to the application */
195 if (activeDS
.currentState
< 5 || activeDS
.currentState
> 7)
198 activeDS
.twCC
= TWCC_SEQERROR
;
204 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER */
205 TW_UINT16
SANE_PendingXfersEndXfer (pTW_IDENTITY pOrigin
,
208 #ifndef SONAME_LIBSANE
211 TW_UINT16 twRC
= TWRC_SUCCESS
;
212 pTW_PENDINGXFERS pPendingXfers
= (pTW_PENDINGXFERS
) pData
;
215 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER\n");
217 if (activeDS
.currentState
!= 6 && activeDS
.currentState
!= 7)
220 activeDS
.twCC
= TWCC_SEQERROR
;
224 pPendingXfers
->Count
= -1;
225 activeDS
.currentState
= 6;
226 if (! activeDS
.sane_started
)
228 status
= psane_start (activeDS
.deviceHandle
);
229 if (status
!= SANE_STATUS_GOOD
)
231 TRACE("PENDINGXFERS/MSG_ENDXFER sane_start returns %s\n", psane_strstatus(status
));
232 pPendingXfers
->Count
= 0;
233 activeDS
.currentState
= 5;
234 /* Notify the application that it can close the data source */
235 if (activeDS
.windowMessage
)
236 PostMessageA(activeDS
.hwndOwner
, activeDS
.windowMessage
, MSG_CLOSEDSREQ
, 0);
239 activeDS
.sane_started
= TRUE
;
242 activeDS
.twCC
= TWCC_SUCCESS
;
249 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_GET */
250 TW_UINT16
SANE_PendingXfersGet (pTW_IDENTITY pOrigin
,
253 #ifndef SONAME_LIBSANE
256 TW_UINT16 twRC
= TWRC_SUCCESS
;
257 pTW_PENDINGXFERS pPendingXfers
= (pTW_PENDINGXFERS
) pData
;
260 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_GET\n");
262 if (activeDS
.currentState
< 4 || activeDS
.currentState
> 7)
265 activeDS
.twCC
= TWCC_SEQERROR
;
269 pPendingXfers
->Count
= -1;
270 if (! activeDS
.sane_started
)
272 status
= psane_start (activeDS
.deviceHandle
);
273 if (status
!= SANE_STATUS_GOOD
)
275 TRACE("PENDINGXFERS/MSG_GET sane_start returns %s\n", psane_strstatus(status
));
276 pPendingXfers
->Count
= 0;
279 activeDS
.sane_started
= TRUE
;
282 activeDS
.twCC
= TWCC_SUCCESS
;
289 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET */
290 TW_UINT16
SANE_PendingXfersReset (pTW_IDENTITY pOrigin
,
293 #ifndef SONAME_LIBSANE
296 TW_UINT16 twRC
= TWRC_SUCCESS
;
297 pTW_PENDINGXFERS pPendingXfers
= (pTW_PENDINGXFERS
) pData
;
299 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET\n");
301 if (activeDS
.currentState
!= 6)
304 activeDS
.twCC
= TWCC_SEQERROR
;
308 pPendingXfers
->Count
= 0;
309 activeDS
.currentState
= 5;
311 activeDS
.twCC
= TWCC_SUCCESS
;
313 if (activeDS
.sane_started
)
315 psane_cancel (activeDS
.deviceHandle
);
316 activeDS
.sane_started
= FALSE
;
324 /* DG_CONTROL/DAT_SETUPMEMXFER/MSG_GET */
325 TW_UINT16
SANE_SetupMemXferGet (pTW_IDENTITY pOrigin
,
328 #ifndef SONAME_LIBSANE
331 pTW_SETUPMEMXFER pSetupMemXfer
= (pTW_SETUPMEMXFER
)pData
;
333 TRACE("DG_CONTROL/DAT_SETUPMEMXFER/MSG_GET\n");
334 if (activeDS
.sane_param_valid
)
336 pSetupMemXfer
->MinBufSize
= activeDS
.sane_param
.bytes_per_line
;
337 pSetupMemXfer
->MaxBufSize
= activeDS
.sane_param
.bytes_per_line
* 8;
338 pSetupMemXfer
->Preferred
= activeDS
.sane_param
.bytes_per_line
* 2;
343 pSetupMemXfer
->MinBufSize
= 2000;
344 pSetupMemXfer
->MaxBufSize
= 8000;
345 pSetupMemXfer
->Preferred
= 4000;
352 /* DG_CONTROL/DAT_STATUS/MSG_GET */
353 TW_UINT16
SANE_GetDSStatus (pTW_IDENTITY pOrigin
,
356 pTW_STATUS pSourceStatus
= (pTW_STATUS
) pData
;
358 TRACE ("DG_CONTROL/DAT_STATUS/MSG_GET\n");
359 pSourceStatus
->ConditionCode
= activeDS
.twCC
;
360 /* Reset the condition code */
361 activeDS
.twCC
= TWCC_SUCCESS
;
365 /* DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS */
366 TW_UINT16
SANE_DisableDSUserInterface (pTW_IDENTITY pOrigin
,
369 TW_UINT16 twRC
= TWRC_SUCCESS
;
371 TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS\n");
373 if (activeDS
.currentState
!= 5)
376 activeDS
.twCC
= TWCC_SEQERROR
;
380 activeDS
.currentState
= 4;
382 activeDS
.twCC
= TWCC_SUCCESS
;
388 /* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS */
389 TW_UINT16
SANE_EnableDSUserInterface (pTW_IDENTITY pOrigin
,
392 TW_UINT16 twRC
= TWRC_SUCCESS
;
393 pTW_USERINTERFACE pUserInterface
= (pTW_USERINTERFACE
) pData
;
395 TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS\n");
397 if (activeDS
.currentState
!= 4)
400 activeDS
.twCC
= TWCC_SEQERROR
;
401 WARN("sequence error %d\n", activeDS
.currentState
);
405 activeDS
.hwndOwner
= pUserInterface
->hParent
;
406 if (! activeDS
.windowMessage
)
407 activeDS
.windowMessage
= RegisterWindowMessageA("SANE.DS ACTIVITY MESSAGE");
408 if (pUserInterface
->ShowUI
)
411 activeDS
.currentState
= 5; /* Transitions to state 5 */
413 pUserInterface
->ModalUI
= TRUE
;
416 if (activeDS
.windowMessage
)
417 PostMessageA(activeDS
.hwndOwner
, activeDS
.windowMessage
, MSG_CLOSEDSREQ
, 0);
419 #ifdef SONAME_LIBSANE
422 psane_get_parameters (activeDS
.deviceHandle
, &activeDS
.sane_param
);
423 activeDS
.sane_param_valid
= TRUE
;
429 /* no UI will be displayed, so source is ready to transfer data */
430 activeDS
.currentState
= 6; /* Transitions to state 6 directly */
431 if (activeDS
.windowMessage
)
432 PostMessageA(activeDS
.hwndOwner
, activeDS
.windowMessage
, MSG_XFERREADY
, 0);
436 activeDS
.twCC
= TWCC_SUCCESS
;
442 /* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY */
443 TW_UINT16
SANE_EnableDSUIOnly (pTW_IDENTITY pOrigin
,
446 TW_UINT16 twRC
= TWRC_SUCCESS
;
448 TRACE("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY\n");
450 if (activeDS
.currentState
!= 4)
453 activeDS
.twCC
= TWCC_SEQERROR
;
457 /* FIXME: we should replace xscanimage with our own UI */
458 system ("xscanimage");
459 activeDS
.currentState
= 5;
461 activeDS
.twCC
= TWCC_SUCCESS
;
467 /* DG_CONTROL/DAT_XFERGROUP/MSG_GET */
468 TW_UINT16
SANE_XferGroupGet (pTW_IDENTITY pOrigin
,
476 /* DG_CONTROL/DAT_XFERGROUP/MSG_SET */
477 TW_UINT16
SANE_XferGroupSet (pTW_IDENTITY pOrigin
,