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
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(twain
);
31 /* DG_CONTROL/DAT_CAPABILITY/MSG_GET */
32 TW_UINT16
SANE_CapabilityGet (pTW_IDENTITY pOrigin
, TW_MEMREF pData
)
34 TW_UINT16 twRC
= TWRC_SUCCESS
, twCC
= TWCC_SUCCESS
;
35 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
37 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_GET\n");
39 if (activeDS
.currentState
< 4 || activeDS
.currentState
> 7)
42 activeDS
.twCC
= TWCC_SEQERROR
;
46 twCC
= SANE_SaneCapability (pCapability
, MSG_GET
);
47 twRC
= (twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
54 /* DG_CONTROL/DAT_CAPABILITY/MSG_GETCURRENT */
55 TW_UINT16
SANE_CapabilityGetCurrent (pTW_IDENTITY pOrigin
, TW_MEMREF pData
)
57 TW_UINT16 twRC
= TWRC_SUCCESS
, twCC
= TWCC_SUCCESS
;
58 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
60 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_GETCURRENT\n");
62 if (activeDS
.currentState
< 4 || activeDS
.currentState
> 7)
65 activeDS
.twCC
= TWCC_SEQERROR
;
69 twCC
= SANE_SaneCapability (pCapability
, MSG_GETCURRENT
);
70 twRC
= (twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
77 /* DG_CONTROL/DAT_CAPABILITY/MSG_GETDEFAULT */
78 TW_UINT16
SANE_CapabilityGetDefault (pTW_IDENTITY pOrigin
, TW_MEMREF pData
)
80 TW_UINT16 twRC
= TWRC_SUCCESS
, twCC
= TWCC_SUCCESS
;
81 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
83 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_GETDEFAULT\n");
85 if (activeDS
.currentState
< 4 || activeDS
.currentState
> 7)
88 activeDS
.twCC
= TWCC_SEQERROR
;
92 twCC
= SANE_SaneCapability (pCapability
, MSG_GETDEFAULT
);
93 twRC
= (twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
100 /* DG_CONTROL/DAT_CAPABILITY/MSG_QUERYSUPPORT */
101 TW_UINT16
SANE_CapabilityQuerySupport (pTW_IDENTITY pOrigin
,
104 TW_UINT16 twRC
= TWRC_SUCCESS
, twCC
= TWCC_SUCCESS
;
105 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
107 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_QUERYSUPPORT\n");
109 if (activeDS
.currentState
< 4 || activeDS
.currentState
> 7)
112 activeDS
.twCC
= TWCC_SEQERROR
;
116 twCC
= SANE_SaneCapability (pCapability
, MSG_QUERYSUPPORT
);
117 twRC
= (twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
118 activeDS
.twCC
= twCC
;
124 /* DG_CONTROL/DAT_CAPABILITY/MSG_RESET */
125 TW_UINT16
SANE_CapabilityReset (pTW_IDENTITY pOrigin
,
128 TW_UINT16 twRC
= TWRC_SUCCESS
, twCC
= TWCC_SUCCESS
;
129 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
131 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_RESET\n");
133 if (activeDS
.currentState
< 4 || activeDS
.currentState
> 7)
136 activeDS
.twCC
= TWCC_SEQERROR
;
140 twCC
= SANE_SaneCapability (pCapability
, MSG_RESET
);
141 twRC
= (twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
142 activeDS
.twCC
= twCC
;
148 /* DG_CONTROL/DAT_CAPABILITY/MSG_SET */
149 TW_UINT16
SANE_CapabilitySet (pTW_IDENTITY pOrigin
,
152 TW_UINT16 twRC
= TWRC_SUCCESS
, twCC
= TWCC_SUCCESS
;
153 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
155 TRACE ("DG_CONTROL/DAT_CAPABILITY/MSG_SET\n");
157 if (activeDS
.currentState
!= 4)
160 activeDS
.twCC
= TWCC_SEQERROR
;
164 twCC
= SANE_SaneCapability (pCapability
, MSG_SET
);
165 if (twCC
== TWCC_CHECKSTATUS
)
168 twRC
= TWRC_CHECKSTATUS
;
171 twRC
= (twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
172 activeDS
.twCC
= twCC
;
177 /* DG_CONTROL/DAT_EVENT/MSG_PROCESSEVENT */
178 TW_UINT16
SANE_ProcessEvent (pTW_IDENTITY pOrigin
,
181 TW_UINT16 twRC
= TWRC_NOTDSEVENT
;
182 pTW_EVENT pEvent
= (pTW_EVENT
) pData
;
183 MSG
*pMsg
= pEvent
->pEvent
;
185 TRACE("DG_CONTROL/DAT_EVENT/MSG_PROCESSEVENT msg 0x%x, wParam 0x%lx\n", pMsg
->message
, pMsg
->wParam
);
187 activeDS
.twCC
= TWCC_SUCCESS
;
188 if (pMsg
->message
== activeDS
.windowMessage
&& activeDS
.windowMessage
)
191 pEvent
->TWMessage
= pMsg
->wParam
;
194 pEvent
->TWMessage
= MSG_NULL
; /* no message to the application */
196 if (activeDS
.currentState
< 5 || activeDS
.currentState
> 7)
199 activeDS
.twCC
= TWCC_SEQERROR
;
205 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER */
206 TW_UINT16
SANE_PendingXfersEndXfer (pTW_IDENTITY pOrigin
,
209 #ifndef SONAME_LIBSANE
212 TW_UINT16 twRC
= TWRC_SUCCESS
;
213 pTW_PENDINGXFERS pPendingXfers
= (pTW_PENDINGXFERS
) pData
;
216 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER\n");
218 if (activeDS
.currentState
!= 6 && activeDS
.currentState
!= 7)
221 activeDS
.twCC
= TWCC_SEQERROR
;
225 pPendingXfers
->Count
= -1;
226 activeDS
.currentState
= 6;
227 if (! activeDS
.sane_started
)
229 status
= psane_start (activeDS
.deviceHandle
);
230 if (status
!= SANE_STATUS_GOOD
)
232 TRACE("PENDINGXFERS/MSG_ENDXFER sane_start returns %s\n", psane_strstatus(status
));
233 pPendingXfers
->Count
= 0;
234 activeDS
.currentState
= 5;
235 /* Notify the application that it can close the data source */
236 if (activeDS
.windowMessage
)
237 PostMessageA(activeDS
.hwndOwner
, activeDS
.windowMessage
, MSG_CLOSEDSREQ
, 0);
240 activeDS
.sane_started
= TRUE
;
243 activeDS
.twCC
= TWCC_SUCCESS
;
250 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_GET */
251 TW_UINT16
SANE_PendingXfersGet (pTW_IDENTITY pOrigin
,
254 #ifndef SONAME_LIBSANE
257 TW_UINT16 twRC
= TWRC_SUCCESS
;
258 pTW_PENDINGXFERS pPendingXfers
= (pTW_PENDINGXFERS
) pData
;
261 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_GET\n");
263 if (activeDS
.currentState
< 4 || activeDS
.currentState
> 7)
266 activeDS
.twCC
= TWCC_SEQERROR
;
270 pPendingXfers
->Count
= -1;
271 if (! activeDS
.sane_started
)
273 status
= psane_start (activeDS
.deviceHandle
);
274 if (status
!= SANE_STATUS_GOOD
)
276 TRACE("PENDINGXFERS/MSG_GET sane_start returns %s\n", psane_strstatus(status
));
277 pPendingXfers
->Count
= 0;
280 activeDS
.sane_started
= TRUE
;
283 activeDS
.twCC
= TWCC_SUCCESS
;
290 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET */
291 TW_UINT16
SANE_PendingXfersReset (pTW_IDENTITY pOrigin
,
294 #ifndef SONAME_LIBSANE
297 TW_UINT16 twRC
= TWRC_SUCCESS
;
298 pTW_PENDINGXFERS pPendingXfers
= (pTW_PENDINGXFERS
) pData
;
300 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET\n");
302 if (activeDS
.currentState
!= 6)
305 activeDS
.twCC
= TWCC_SEQERROR
;
309 pPendingXfers
->Count
= 0;
310 activeDS
.currentState
= 5;
312 activeDS
.twCC
= TWCC_SUCCESS
;
314 if (activeDS
.sane_started
)
316 psane_cancel (activeDS
.deviceHandle
);
317 activeDS
.sane_started
= FALSE
;
325 /* DG_CONTROL/DAT_SETUPMEMXFER/MSG_GET */
326 TW_UINT16
SANE_SetupMemXferGet (pTW_IDENTITY pOrigin
,
329 #ifndef SONAME_LIBSANE
332 pTW_SETUPMEMXFER pSetupMemXfer
= (pTW_SETUPMEMXFER
)pData
;
334 TRACE("DG_CONTROL/DAT_SETUPMEMXFER/MSG_GET\n");
335 if (activeDS
.sane_param_valid
)
337 pSetupMemXfer
->MinBufSize
= activeDS
.sane_param
.bytes_per_line
;
338 pSetupMemXfer
->MaxBufSize
= activeDS
.sane_param
.bytes_per_line
* 8;
339 pSetupMemXfer
->Preferred
= activeDS
.sane_param
.bytes_per_line
* 2;
344 pSetupMemXfer
->MinBufSize
= 2000;
345 pSetupMemXfer
->MaxBufSize
= 8000;
346 pSetupMemXfer
->Preferred
= 4000;
353 /* DG_CONTROL/DAT_STATUS/MSG_GET */
354 TW_UINT16
SANE_GetDSStatus (pTW_IDENTITY pOrigin
,
357 pTW_STATUS pSourceStatus
= (pTW_STATUS
) pData
;
359 TRACE ("DG_CONTROL/DAT_STATUS/MSG_GET\n");
360 pSourceStatus
->ConditionCode
= activeDS
.twCC
;
361 /* Reset the condition code */
362 activeDS
.twCC
= TWCC_SUCCESS
;
366 /* DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS */
367 TW_UINT16
SANE_DisableDSUserInterface (pTW_IDENTITY pOrigin
,
370 TW_UINT16 twRC
= TWRC_SUCCESS
;
372 TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS\n");
374 if (activeDS
.currentState
!= 5)
377 activeDS
.twCC
= TWCC_SEQERROR
;
381 activeDS
.currentState
= 4;
383 activeDS
.twCC
= TWCC_SUCCESS
;
389 /* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS */
390 TW_UINT16
SANE_EnableDSUserInterface (pTW_IDENTITY pOrigin
,
393 TW_UINT16 twRC
= TWRC_SUCCESS
;
394 pTW_USERINTERFACE pUserInterface
= (pTW_USERINTERFACE
) pData
;
396 TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS\n");
398 if (activeDS
.currentState
!= 4)
401 activeDS
.twCC
= TWCC_SEQERROR
;
402 WARN("sequence error %d\n", activeDS
.currentState
);
406 activeDS
.hwndOwner
= pUserInterface
->hParent
;
407 if (! activeDS
.windowMessage
)
408 activeDS
.windowMessage
= RegisterWindowMessageA("SANE.DS ACTIVITY MESSAGE");
409 if (pUserInterface
->ShowUI
)
412 activeDS
.currentState
= 5; /* Transitions to state 5 */
414 pUserInterface
->ModalUI
= TRUE
;
417 if (activeDS
.windowMessage
)
418 PostMessageA(activeDS
.hwndOwner
, activeDS
.windowMessage
, MSG_CLOSEDSREQ
, 0);
420 #ifdef SONAME_LIBSANE
423 psane_get_parameters (activeDS
.deviceHandle
, &activeDS
.sane_param
);
424 activeDS
.sane_param_valid
= TRUE
;
430 /* no UI will be displayed, so source is ready to transfer data */
431 activeDS
.currentState
= 6; /* Transitions to state 6 directly */
432 if (activeDS
.windowMessage
)
433 PostMessageA(activeDS
.hwndOwner
, activeDS
.windowMessage
, MSG_XFERREADY
, 0);
437 activeDS
.twCC
= TWCC_SUCCESS
;
443 /* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY */
444 TW_UINT16
SANE_EnableDSUIOnly (pTW_IDENTITY pOrigin
,
447 TW_UINT16 twRC
= TWRC_SUCCESS
;
449 TRACE("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY\n");
451 if (activeDS
.currentState
!= 4)
454 activeDS
.twCC
= TWCC_SEQERROR
;
458 /* FIXME: we should replace xscanimage with our own UI */
459 system ("xscanimage");
460 activeDS
.currentState
= 5;
462 activeDS
.twCC
= TWCC_SUCCESS
;
468 /* DG_CONTROL/DAT_XFERGROUP/MSG_GET */
469 TW_UINT16
SANE_XferGroupGet (pTW_IDENTITY pOrigin
,
477 /* DG_CONTROL/DAT_XFERGROUP/MSG_SET */
478 TW_UINT16
SANE_XferGroupSet (pTW_IDENTITY pOrigin
,