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
23 #include "wine/debug.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(twain
);
27 /* DG_CONTROL/DAT_CAPABILITY/MSG_GET */
28 TW_UINT16
TWAIN_CapabilityGet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
31 TW_UINT16 twRC
= TWRC_SUCCESS
, twCC
= TWCC_SUCCESS
;
32 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
33 activeDS
*pSource
= TWAIN_LookupSource (pDest
);
35 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_GET\n");
40 DSM_twCC
= TWCC_BADDEST
;
42 else if (pSource
->currentState
< 4 || pSource
->currentState
> 7)
45 pSource
->twCC
= TWCC_SEQERROR
;
49 twCC
= TWAIN_SaneCapability (pSource
, pCapability
, MSG_GET
);
50 twRC
= (twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
57 /* DG_CONTROL/DAT_CAPABILITY/MSG_GETCURRENT */
58 TW_UINT16
TWAIN_CapabilityGetCurrent (pTW_IDENTITY pOrigin
,
59 pTW_IDENTITY pDest
,TW_MEMREF pData
)
61 TW_UINT16 twRC
= TWRC_SUCCESS
, twCC
= TWCC_SUCCESS
;
62 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
63 activeDS
*pSource
= TWAIN_LookupSource (pDest
);
65 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_GETCURRENT\n");
70 DSM_twCC
= TWCC_BADDEST
;
72 else if (pSource
->currentState
< 4 || pSource
->currentState
> 7)
75 pSource
->twCC
= TWCC_SEQERROR
;
79 twCC
= TWAIN_SaneCapability (pSource
, pCapability
, MSG_GETCURRENT
);
80 twRC
= (twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
87 /* DG_CONTROL/DAT_CAPABILITY/MSG_GETDEFAULT */
88 TW_UINT16
TWAIN_CapabilityGetDefault (pTW_IDENTITY pOrigin
,
89 pTW_IDENTITY pDest
, TW_MEMREF pData
)
91 TW_UINT16 twRC
= TWRC_SUCCESS
, twCC
= TWCC_SUCCESS
;
92 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
93 activeDS
*pSource
= TWAIN_LookupSource (pDest
);
95 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_GETDEFAULT\n");
100 DSM_twCC
= TWCC_BADDEST
;
102 else if (pSource
->currentState
< 4 || pSource
->currentState
> 7)
105 pSource
->twCC
= TWCC_SEQERROR
;
109 twCC
= TWAIN_SaneCapability (pSource
, pCapability
, MSG_GETDEFAULT
);
110 twRC
= (twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
111 pSource
->twCC
= twCC
;
117 /* DG_CONTROL/DAT_CAPABILITY/MSG_QUERYSUPPORT */
118 TW_UINT16
TWAIN_CapabilityQuerySupport (pTW_IDENTITY pOrigin
,
119 pTW_IDENTITY pDest
, TW_MEMREF pData
)
126 /* DG_CONTROL/DAT_CAPABILITY/MSG_RESET */
127 TW_UINT16
TWAIN_CapabilityReset (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
130 TW_UINT16 twRC
= TWRC_SUCCESS
, twCC
= TWCC_SUCCESS
;
131 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
132 activeDS
*pSource
= TWAIN_LookupSource (pDest
);
134 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_RESET\n");
139 DSM_twCC
= TWCC_BADDEST
;
141 else if (pSource
->currentState
< 4 || pSource
->currentState
> 7)
144 pSource
->twCC
= TWCC_SEQERROR
;
148 twCC
= TWAIN_SaneCapability (pSource
, pCapability
, MSG_RESET
);
149 twRC
= (twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
150 pSource
->twCC
= twCC
;
156 /* DG_CONTROL/DAT_CAPABILITY/MSG_SET */
157 TW_UINT16
TWAIN_CapabilitySet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
160 TW_UINT16 twRC
= TWRC_SUCCESS
, twCC
= TWCC_SUCCESS
;
161 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
162 activeDS
*pSource
= TWAIN_LookupSource (pDest
);
164 TRACE ("DG_CONTROL/DAT_CAPABILITY/MSG_SET\n");
169 DSM_twCC
= TWCC_BADDEST
;
171 else if (pSource
->currentState
!= 4)
174 pSource
->twCC
= TWCC_SEQERROR
;
178 twCC
= TWAIN_SaneCapability (pSource
, pCapability
, MSG_SET
);
179 twRC
= (twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
180 pSource
->twCC
= twCC
;
185 /* DG_CONTROL/DAT_CUSTOMDSDATA/MSG_GET */
186 TW_UINT16
TWAIN_CustomDSDataGet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
194 /* DG_CONTROL/DAT_CUSTOMDSDATA/MSG_SET */
195 TW_UINT16
TWAIN_CustomDSDataSet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
203 /* DG_CONTROL/DAT_FILESYSTEM/MSG_AUTOMATICCAPTUREDIRECTORY */
204 TW_UINT16
TWAIN_AutomaticCaptureDirectory (pTW_IDENTITY pOrigin
,
213 /* DG_CONTROL/DAT_FILESYSTEM/MSG_CHANGEDIRECTORY */
214 TW_UINT16
TWAIN_ChangeDirectory (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
222 /* DG_CONTROL/DAT_FILESYSTEM/MSG_COPY */
223 TW_UINT16
TWAIN_FileSystemCopy (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
231 /* DG_CONTROL/DAT_FILESYSTEM/MSG_CREATEDIRECTORY */
232 TW_UINT16
TWAIN_CreateDirectory (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
240 /* DG_CONTROL/DAT_FILESYSTEM/MSG_DELETE */
241 TW_UINT16
TWAIN_FileSystemDelete (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
249 /* DG_CONTROL/DAT_FILESYSTEM/MSG_FORMATMEDIA */
250 TW_UINT16
TWAIN_FormatMedia (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
258 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETCLOSE */
259 TW_UINT16
TWAIN_FileSystemGetClose (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
267 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETFIRSTFILE */
268 TW_UINT16
TWAIN_FileSystemGetFirstFile (pTW_IDENTITY pOrigin
,
277 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETINFO */
278 TW_UINT16
TWAIN_FileSystemGetInfo (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
286 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETNEXTFILE */
287 TW_UINT16
TWAIN_FileSystemGetNextFile (pTW_IDENTITY pOrigin
,
296 /* DG_CONTROL/DAT_FILESYSTEM/MSG_RENAME */
297 TW_UINT16
TWAIN_FileSystemRename (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
305 /* DG_CONTROL/DAT_EVENT/MSG_PROCESSEVENT */
306 TW_UINT16
TWAIN_ProcessEvent (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
309 TW_UINT16 twRC
= TWRC_SUCCESS
;
310 pTW_EVENT pEvent
= (pTW_EVENT
) pData
;
311 activeDS
*pSource
= TWAIN_LookupSource (pDest
);
313 TRACE("DG_CONTROL/DAT_EVENT/MSG_PROCESSEVENT\n");
318 DSM_twCC
= TWCC_BADDEST
;
320 else if (pSource
->currentState
< 5 || pSource
->currentState
> 7)
323 pSource
->twCC
= TWCC_SEQERROR
;
327 if (pSource
->pendingEvent
.TWMessage
!= MSG_NULL
)
329 pEvent
->TWMessage
= pSource
->pendingEvent
.TWMessage
;
330 pSource
->pendingEvent
.TWMessage
= MSG_NULL
;
335 pEvent
->TWMessage
= MSG_NULL
; /* no message to the application */
336 twRC
= TWRC_NOTDSEVENT
;
338 pSource
->twCC
= TWCC_SUCCESS
;
344 /* DG_CONTROL/DAT_PASSTHRU/MSG_PASSTHRU */
345 TW_UINT16
TWAIN_PassThrough (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
353 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER */
354 TW_UINT16
TWAIN_PendingXfersEndXfer (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
357 TW_UINT16 twRC
= TWRC_SUCCESS
;
358 pTW_PENDINGXFERS pPendingXfers
= (pTW_PENDINGXFERS
) pData
;
359 activeDS
*pSource
= TWAIN_LookupSource (pData
);
361 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER\n");
366 DSM_twCC
= TWCC_BADDEST
;
368 else if (pSource
->currentState
!= 6 && pSource
->currentState
!= 7)
371 pSource
->twCC
= TWCC_SEQERROR
;
375 if (pPendingXfers
->Count
!= 0)
377 pPendingXfers
->Count
--;
378 pSource
->currentState
= 6;
382 pSource
->currentState
= 5;
383 /* Notify the application that it can close the data source */
384 pSource
->pendingEvent
.TWMessage
= MSG_CLOSEDSREQ
;
387 pSource
->twCC
= TWCC_SUCCESS
;
393 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_GET */
394 TW_UINT16
TWAIN_PendingXfersGet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
397 TW_UINT16 twRC
= TWRC_SUCCESS
;
398 pTW_PENDINGXFERS pPendingXfers
= (pTW_PENDINGXFERS
) pData
;
399 activeDS
*pSource
= TWAIN_LookupSource (pDest
);
401 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_GET\n");
406 DSM_twCC
= TWCC_BADDEST
;
408 else if (pSource
->currentState
< 4 || pSource
->currentState
> 7)
411 DSM_twCC
= TWCC_SEQERROR
;
415 /* FIXME: we shouldn't return 1 here */
416 pPendingXfers
->Count
= 1;
418 pSource
->twCC
= TWCC_SUCCESS
;
424 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET */
425 TW_UINT16
TWAIN_PendingXfersReset (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
428 TW_UINT16 twRC
= TWRC_SUCCESS
;
429 pTW_PENDINGXFERS pPendingXfers
= (pTW_PENDINGXFERS
) pData
;
430 activeDS
*pSource
= TWAIN_LookupSource (pDest
);
432 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET\n");
437 DSM_twCC
= TWCC_BADDEST
;
439 else if (pSource
->currentState
!= 6)
442 DSM_twCC
= TWCC_SEQERROR
;
446 pPendingXfers
->Count
= 0;
447 pSource
->currentState
= 5;
449 pSource
->twCC
= TWCC_SUCCESS
;
455 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_STOPFEEDER */
456 TW_UINT16
TWAIN_PendingXfersStopFeeder (pTW_IDENTITY pOrigin
,
457 pTW_IDENTITY pDest
, TW_MEMREF pData
)
464 /* DG_CONTROL/DAT_SETUPFILEXFER/MSG_GET */
465 TW_UINT16
TWAIN_SetupFileXferGet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
473 /* DG_CONTROL/DAT_SETUPXFER/MSG_GETDEFAULT */
474 TW_UINT16
TWAIN_SetupFileXferGetDefault (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
483 /* DG_CONTROL/DAT_SETUPFILEXFER/MSG_RESET */
484 TW_UINT16
TWAIN_SetupFileXferReset (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
492 /* DG_CONTROL/DAT_SETUPFILEXFER/MSG_SET */
493 TW_UINT16
TWAIN_SetupFileXferSet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
501 /* DG_CONTROL/DAT_SETUPFILEXFER2/MSG_GET */
502 TW_UINT16
TWAIN_SetupFileXfer2Get (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
510 /* DG_CONTROL/DAT_SETUPFILEXFER2/MSG_GETDEFAULT */
511 TW_UINT16
TWAIN_SetupFileXfer2GetDefault (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
519 /* DG_CONTROL/DAT_SETUPFILEXFER2/MSG_RESET */
520 TW_UINT16
TWAIN_SetupFileXfer2Reset (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
528 /* DG_CONTROL/DAT_SETUPFILEXFER2/MSG_SET */
529 TW_UINT16
TWAIN_SetupFileXfer2Set (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
537 /* DG_CONTROL/DAT_SETUPMEMXFER/MSG_GET */
538 TW_UINT16
TWAIN_SetupMemXferGet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
546 /* DG_CONTROL/DAT_STATUS/MSG_GET */
547 TW_UINT16
TWAIN_GetDSStatus (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
550 TW_UINT16 twRC
= TWRC_FAILURE
;
551 pTW_STATUS pSourceStatus
= (pTW_STATUS
) pData
;
552 activeDS
*pSource
= TWAIN_LookupSource (pDest
);
554 TRACE ("DG_CONTROL/DAT_STATUS/MSG_GET\n");
559 DSM_twCC
= TWCC_BADDEST
;
560 pSourceStatus
->ConditionCode
= TWCC_BADDEST
;
565 pSourceStatus
->ConditionCode
= pSource
->twCC
;
566 /* Reset the condition code */
567 pSource
->twCC
= TWCC_SUCCESS
;
573 /* DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS */
574 TW_UINT16
TWAIN_DisableDSUserInterface (pTW_IDENTITY pOrigin
,
575 pTW_IDENTITY pDest
, TW_MEMREF pData
)
577 TW_UINT16 twRC
= TWRC_SUCCESS
;
578 pTW_USERINTERFACE pUserInterface
= (pTW_USERINTERFACE
) pData
;
579 activeDS
*pSource
= TWAIN_LookupSource (pDest
);
581 TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS\n");
586 DSM_twCC
= TWCC_BADDEST
;
588 else if (pSource
->currentState
!= 5)
591 pSource
->twCC
= TWCC_SEQERROR
;
595 pSource
->currentState
= 4;
597 pSource
->twCC
= TWCC_SUCCESS
;
603 /* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS */
604 TW_UINT16
TWAIN_EnableDSUserInterface (pTW_IDENTITY pOrigin
,
605 pTW_IDENTITY pDest
, TW_MEMREF pData
)
607 TW_UINT16 twRC
= TWRC_SUCCESS
;
608 pTW_USERINTERFACE pUserInterface
= (pTW_USERINTERFACE
) pData
;
609 activeDS
*pSource
= TWAIN_LookupSource (pDest
);
611 TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS\n");
616 DSM_twCC
= TWCC_BADDEST
;
618 else if (pSource
->currentState
!= 4)
621 pSource
->twCC
= TWCC_SEQERROR
;
625 if (pUserInterface
->ShowUI
)
627 pSource
->currentState
= 5; /* Transitions to state 5 */
628 /* FIXME: we should replace xscanimage with our own device UI */
629 system ("xscanimage");
630 pSource
->currentState
= 6;
631 pSource
->pendingEvent
.TWMessage
= MSG_XFERREADY
;
635 /* no UI will be displayed, so source is ready to transfer data */
636 pSource
->pendingEvent
.TWMessage
= MSG_XFERREADY
;
637 pSource
->currentState
= 6; /* Transitions to state 6 directly */
640 pSource
->hwndOwner
= pUserInterface
->hParent
;
642 pSource
->twCC
= TWCC_SUCCESS
;
648 /* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY */
649 TW_UINT16
TWAIN_EnableDSUIOnly (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
652 TW_UINT16 twRC
= TWRC_SUCCESS
;
653 pTW_USERINTERFACE pUserInterface
= (pTW_USERINTERFACE
) pData
;
654 activeDS
*pSource
= TWAIN_LookupSource (pDest
);
656 TRACE("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY\n");
661 DSM_twCC
= TWCC_BADDEST
;
663 else if (pSource
->currentState
!= 4)
666 pSource
->twCC
= TWCC_SEQERROR
;
670 /* FIXME: we should replace xscanimage with our own UI */
671 system ("xscanimage");
672 pSource
->currentState
= 5;
674 pSource
->twCC
= TWCC_SUCCESS
;
680 /* DG_CONTROL/DAT_XFERGROUP/MSG_GET */
681 TW_UINT16
TWAIN_XferGroupGet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
689 /* DG_CONTROL/DAT_XFERGROUP/MSG_SET */
690 TW_UINT16
TWAIN_XferGroupSet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,