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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(twain
);
31 /* DG_CONTROL/DAT_CAPABILITY/MSG_GET */
32 TW_UINT16
TWAIN_CapabilityGet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
35 TW_UINT16 twRC
= TWRC_SUCCESS
, twCC
= TWCC_SUCCESS
;
36 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
37 activeDS
*pSource
= TWAIN_LookupSource (pDest
);
39 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_GET\n");
44 DSM_twCC
= TWCC_BADDEST
;
46 else if (pSource
->currentState
< 4 || pSource
->currentState
> 7)
49 pSource
->twCC
= TWCC_SEQERROR
;
53 twCC
= TWAIN_SaneCapability (pSource
, pCapability
, MSG_GET
);
54 twRC
= (twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
61 /* DG_CONTROL/DAT_CAPABILITY/MSG_GETCURRENT */
62 TW_UINT16
TWAIN_CapabilityGetCurrent (pTW_IDENTITY pOrigin
,
63 pTW_IDENTITY pDest
,TW_MEMREF pData
)
65 TW_UINT16 twRC
= TWRC_SUCCESS
, twCC
= TWCC_SUCCESS
;
66 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
67 activeDS
*pSource
= TWAIN_LookupSource (pDest
);
69 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_GETCURRENT\n");
74 DSM_twCC
= TWCC_BADDEST
;
76 else if (pSource
->currentState
< 4 || pSource
->currentState
> 7)
79 pSource
->twCC
= TWCC_SEQERROR
;
83 twCC
= TWAIN_SaneCapability (pSource
, pCapability
, MSG_GETCURRENT
);
84 twRC
= (twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
91 /* DG_CONTROL/DAT_CAPABILITY/MSG_GETDEFAULT */
92 TW_UINT16
TWAIN_CapabilityGetDefault (pTW_IDENTITY pOrigin
,
93 pTW_IDENTITY pDest
, TW_MEMREF pData
)
95 TW_UINT16 twRC
= TWRC_SUCCESS
, twCC
= TWCC_SUCCESS
;
96 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
97 activeDS
*pSource
= TWAIN_LookupSource (pDest
);
99 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_GETDEFAULT\n");
104 DSM_twCC
= TWCC_BADDEST
;
106 else if (pSource
->currentState
< 4 || pSource
->currentState
> 7)
109 pSource
->twCC
= TWCC_SEQERROR
;
113 twCC
= TWAIN_SaneCapability (pSource
, pCapability
, MSG_GETDEFAULT
);
114 twRC
= (twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
115 pSource
->twCC
= twCC
;
121 /* DG_CONTROL/DAT_CAPABILITY/MSG_QUERYSUPPORT */
122 TW_UINT16
TWAIN_CapabilityQuerySupport (pTW_IDENTITY pOrigin
,
123 pTW_IDENTITY pDest
, TW_MEMREF pData
)
130 /* DG_CONTROL/DAT_CAPABILITY/MSG_RESET */
131 TW_UINT16
TWAIN_CapabilityReset (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
134 TW_UINT16 twRC
= TWRC_SUCCESS
, twCC
= TWCC_SUCCESS
;
135 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
136 activeDS
*pSource
= TWAIN_LookupSource (pDest
);
138 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_RESET\n");
143 DSM_twCC
= TWCC_BADDEST
;
145 else if (pSource
->currentState
< 4 || pSource
->currentState
> 7)
148 pSource
->twCC
= TWCC_SEQERROR
;
152 twCC
= TWAIN_SaneCapability (pSource
, pCapability
, MSG_RESET
);
153 twRC
= (twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
154 pSource
->twCC
= twCC
;
160 /* DG_CONTROL/DAT_CAPABILITY/MSG_SET */
161 TW_UINT16
TWAIN_CapabilitySet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
164 TW_UINT16 twRC
= TWRC_SUCCESS
, twCC
= TWCC_SUCCESS
;
165 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
166 activeDS
*pSource
= TWAIN_LookupSource (pDest
);
168 TRACE ("DG_CONTROL/DAT_CAPABILITY/MSG_SET\n");
173 DSM_twCC
= TWCC_BADDEST
;
175 else if (pSource
->currentState
!= 4)
178 pSource
->twCC
= TWCC_SEQERROR
;
182 twCC
= TWAIN_SaneCapability (pSource
, pCapability
, MSG_SET
);
183 twRC
= (twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
184 pSource
->twCC
= twCC
;
189 /* DG_CONTROL/DAT_CUSTOMDSDATA/MSG_GET */
190 TW_UINT16
TWAIN_CustomDSDataGet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
198 /* DG_CONTROL/DAT_CUSTOMDSDATA/MSG_SET */
199 TW_UINT16
TWAIN_CustomDSDataSet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
207 /* DG_CONTROL/DAT_FILESYSTEM/MSG_AUTOMATICCAPTUREDIRECTORY */
208 TW_UINT16
TWAIN_AutomaticCaptureDirectory (pTW_IDENTITY pOrigin
,
217 /* DG_CONTROL/DAT_FILESYSTEM/MSG_CHANGEDIRECTORY */
218 TW_UINT16
TWAIN_ChangeDirectory (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
226 /* DG_CONTROL/DAT_FILESYSTEM/MSG_COPY */
227 TW_UINT16
TWAIN_FileSystemCopy (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
235 /* DG_CONTROL/DAT_FILESYSTEM/MSG_CREATEDIRECTORY */
236 TW_UINT16
TWAIN_CreateDirectory (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
244 /* DG_CONTROL/DAT_FILESYSTEM/MSG_DELETE */
245 TW_UINT16
TWAIN_FileSystemDelete (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
253 /* DG_CONTROL/DAT_FILESYSTEM/MSG_FORMATMEDIA */
254 TW_UINT16
TWAIN_FormatMedia (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
262 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETCLOSE */
263 TW_UINT16
TWAIN_FileSystemGetClose (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
271 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETFIRSTFILE */
272 TW_UINT16
TWAIN_FileSystemGetFirstFile (pTW_IDENTITY pOrigin
,
281 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETINFO */
282 TW_UINT16
TWAIN_FileSystemGetInfo (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
290 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETNEXTFILE */
291 TW_UINT16
TWAIN_FileSystemGetNextFile (pTW_IDENTITY pOrigin
,
300 /* DG_CONTROL/DAT_FILESYSTEM/MSG_RENAME */
301 TW_UINT16
TWAIN_FileSystemRename (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
309 /* DG_CONTROL/DAT_EVENT/MSG_PROCESSEVENT */
310 TW_UINT16
TWAIN_ProcessEvent (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
313 TW_UINT16 twRC
= TWRC_SUCCESS
;
314 pTW_EVENT pEvent
= (pTW_EVENT
) pData
;
315 activeDS
*pSource
= TWAIN_LookupSource (pDest
);
317 TRACE("DG_CONTROL/DAT_EVENT/MSG_PROCESSEVENT\n");
322 DSM_twCC
= TWCC_BADDEST
;
324 else if (pSource
->currentState
< 5 || pSource
->currentState
> 7)
327 pSource
->twCC
= TWCC_SEQERROR
;
331 if (pSource
->pendingEvent
.TWMessage
!= MSG_NULL
)
333 pEvent
->TWMessage
= pSource
->pendingEvent
.TWMessage
;
334 pSource
->pendingEvent
.TWMessage
= MSG_NULL
;
339 pEvent
->TWMessage
= MSG_NULL
; /* no message to the application */
340 twRC
= TWRC_NOTDSEVENT
;
342 pSource
->twCC
= TWCC_SUCCESS
;
348 /* DG_CONTROL/DAT_PASSTHRU/MSG_PASSTHRU */
349 TW_UINT16
TWAIN_PassThrough (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
357 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER */
358 TW_UINT16
TWAIN_PendingXfersEndXfer (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
361 TW_UINT16 twRC
= TWRC_SUCCESS
;
362 pTW_PENDINGXFERS pPendingXfers
= (pTW_PENDINGXFERS
) pData
;
363 activeDS
*pSource
= TWAIN_LookupSource (pData
);
365 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER\n");
370 DSM_twCC
= TWCC_BADDEST
;
372 else if (pSource
->currentState
!= 6 && pSource
->currentState
!= 7)
375 pSource
->twCC
= TWCC_SEQERROR
;
379 if (pPendingXfers
->Count
!= 0)
381 pPendingXfers
->Count
--;
382 pSource
->currentState
= 6;
386 pSource
->currentState
= 5;
387 /* Notify the application that it can close the data source */
388 pSource
->pendingEvent
.TWMessage
= MSG_CLOSEDSREQ
;
391 pSource
->twCC
= TWCC_SUCCESS
;
397 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_GET */
398 TW_UINT16
TWAIN_PendingXfersGet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
401 TW_UINT16 twRC
= TWRC_SUCCESS
;
402 pTW_PENDINGXFERS pPendingXfers
= (pTW_PENDINGXFERS
) pData
;
403 activeDS
*pSource
= TWAIN_LookupSource (pDest
);
405 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_GET\n");
410 DSM_twCC
= TWCC_BADDEST
;
412 else if (pSource
->currentState
< 4 || pSource
->currentState
> 7)
415 DSM_twCC
= TWCC_SEQERROR
;
419 /* FIXME: we shouldn't return 1 here */
420 pPendingXfers
->Count
= 1;
422 pSource
->twCC
= TWCC_SUCCESS
;
428 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET */
429 TW_UINT16
TWAIN_PendingXfersReset (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
432 TW_UINT16 twRC
= TWRC_SUCCESS
;
433 pTW_PENDINGXFERS pPendingXfers
= (pTW_PENDINGXFERS
) pData
;
434 activeDS
*pSource
= TWAIN_LookupSource (pDest
);
436 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET\n");
441 DSM_twCC
= TWCC_BADDEST
;
443 else if (pSource
->currentState
!= 6)
446 DSM_twCC
= TWCC_SEQERROR
;
450 pPendingXfers
->Count
= 0;
451 pSource
->currentState
= 5;
453 pSource
->twCC
= TWCC_SUCCESS
;
459 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_STOPFEEDER */
460 TW_UINT16
TWAIN_PendingXfersStopFeeder (pTW_IDENTITY pOrigin
,
461 pTW_IDENTITY pDest
, TW_MEMREF pData
)
468 /* DG_CONTROL/DAT_SETUPFILEXFER/MSG_GET */
469 TW_UINT16
TWAIN_SetupFileXferGet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
477 /* DG_CONTROL/DAT_SETUPXFER/MSG_GETDEFAULT */
478 TW_UINT16
TWAIN_SetupFileXferGetDefault (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
487 /* DG_CONTROL/DAT_SETUPFILEXFER/MSG_RESET */
488 TW_UINT16
TWAIN_SetupFileXferReset (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
496 /* DG_CONTROL/DAT_SETUPFILEXFER/MSG_SET */
497 TW_UINT16
TWAIN_SetupFileXferSet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
505 /* DG_CONTROL/DAT_SETUPFILEXFER2/MSG_GET */
506 TW_UINT16
TWAIN_SetupFileXfer2Get (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
514 /* DG_CONTROL/DAT_SETUPFILEXFER2/MSG_GETDEFAULT */
515 TW_UINT16
TWAIN_SetupFileXfer2GetDefault (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
523 /* DG_CONTROL/DAT_SETUPFILEXFER2/MSG_RESET */
524 TW_UINT16
TWAIN_SetupFileXfer2Reset (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
532 /* DG_CONTROL/DAT_SETUPFILEXFER2/MSG_SET */
533 TW_UINT16
TWAIN_SetupFileXfer2Set (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
541 /* DG_CONTROL/DAT_SETUPMEMXFER/MSG_GET */
542 TW_UINT16
TWAIN_SetupMemXferGet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
550 /* DG_CONTROL/DAT_STATUS/MSG_GET */
551 TW_UINT16
TWAIN_GetDSStatus (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
554 TW_UINT16 twRC
= TWRC_FAILURE
;
555 pTW_STATUS pSourceStatus
= (pTW_STATUS
) pData
;
556 activeDS
*pSource
= TWAIN_LookupSource (pDest
);
558 TRACE ("DG_CONTROL/DAT_STATUS/MSG_GET\n");
563 DSM_twCC
= TWCC_BADDEST
;
564 pSourceStatus
->ConditionCode
= TWCC_BADDEST
;
569 pSourceStatus
->ConditionCode
= pSource
->twCC
;
570 /* Reset the condition code */
571 pSource
->twCC
= TWCC_SUCCESS
;
577 /* DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS */
578 TW_UINT16
TWAIN_DisableDSUserInterface (pTW_IDENTITY pOrigin
,
579 pTW_IDENTITY pDest
, TW_MEMREF pData
)
581 TW_UINT16 twRC
= TWRC_SUCCESS
;
582 activeDS
*pSource
= TWAIN_LookupSource (pDest
);
584 TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS\n");
589 DSM_twCC
= TWCC_BADDEST
;
591 else if (pSource
->currentState
!= 5)
594 pSource
->twCC
= TWCC_SEQERROR
;
598 pSource
->currentState
= 4;
600 pSource
->twCC
= TWCC_SUCCESS
;
606 /* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS */
607 TW_UINT16
TWAIN_EnableDSUserInterface (pTW_IDENTITY pOrigin
,
608 pTW_IDENTITY pDest
, TW_MEMREF pData
)
610 TW_UINT16 twRC
= TWRC_SUCCESS
;
611 pTW_USERINTERFACE pUserInterface
= (pTW_USERINTERFACE
) pData
;
612 activeDS
*pSource
= TWAIN_LookupSource (pDest
);
614 TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS\n");
619 DSM_twCC
= TWCC_BADDEST
;
621 else if (pSource
->currentState
!= 4)
624 pSource
->twCC
= TWCC_SEQERROR
;
628 if (pUserInterface
->ShowUI
)
630 pSource
->currentState
= 5; /* Transitions to state 5 */
631 /* FIXME: we should replace xscanimage with our own device UI */
632 system ("xscanimage");
633 pSource
->currentState
= 6;
634 pSource
->pendingEvent
.TWMessage
= MSG_XFERREADY
;
638 /* no UI will be displayed, so source is ready to transfer data */
639 pSource
->pendingEvent
.TWMessage
= MSG_XFERREADY
;
640 pSource
->currentState
= 6; /* Transitions to state 6 directly */
643 pSource
->hwndOwner
= pUserInterface
->hParent
;
645 pSource
->twCC
= TWCC_SUCCESS
;
651 /* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY */
652 TW_UINT16
TWAIN_EnableDSUIOnly (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
655 TW_UINT16 twRC
= TWRC_SUCCESS
;
656 activeDS
*pSource
= TWAIN_LookupSource (pDest
);
658 TRACE("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY\n");
663 DSM_twCC
= TWCC_BADDEST
;
665 else if (pSource
->currentState
!= 4)
668 pSource
->twCC
= TWCC_SEQERROR
;
672 /* FIXME: we should replace xscanimage with our own UI */
673 system ("xscanimage");
674 pSource
->currentState
= 5;
676 pSource
->twCC
= TWCC_SUCCESS
;
682 /* DG_CONTROL/DAT_XFERGROUP/MSG_GET */
683 TW_UINT16
TWAIN_XferGroupGet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
691 /* DG_CONTROL/DAT_XFERGROUP/MSG_SET */
692 TW_UINT16
TWAIN_XferGroupSet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,