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;
335 twRC = TWRC_NOTDSEVENT;
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 (pDest);
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,
548 activeDS *pSource = TWAIN_LookupSource (pDest);
549 pTW_SETUPMEMXFER pSetupMemXfer = (pTW_SETUPMEMXFER)pData;
551 TRACE("DG_CONTROL/DAT_SETUPMEMXFER/MSG_GET\n");
552 if (pSource->sane_param_valid)
554 pSetupMemXfer->MinBufSize = pSource->sane_param.bytes_per_line;
555 pSetupMemXfer->MaxBufSize = pSource->sane_param.bytes_per_line * 8;
556 pSetupMemXfer->Preferred = pSource->sane_param.bytes_per_line * 2;
561 pSetupMemXfer->MinBufSize = 2000;
562 pSetupMemXfer->MaxBufSize = 8000;
563 pSetupMemXfer->Preferred = 4000;
570 /* DG_CONTROL/DAT_STATUS/MSG_GET */
571 TW_UINT16 TWAIN_GetDSStatus (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
574 TW_UINT16 twRC = TWRC_FAILURE;
575 pTW_STATUS pSourceStatus = (pTW_STATUS) pData;
576 activeDS *pSource = TWAIN_LookupSource (pDest);
578 TRACE ("DG_CONTROL/DAT_STATUS/MSG_GET\n");
583 DSM_twCC = TWCC_BADDEST;
584 pSourceStatus->ConditionCode = TWCC_BADDEST;
589 pSourceStatus->ConditionCode = pSource->twCC;
590 /* Reset the condition code */
591 pSource->twCC = TWCC_SUCCESS;
597 /* DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS */
598 TW_UINT16 TWAIN_DisableDSUserInterface (pTW_IDENTITY pOrigin,
599 pTW_IDENTITY pDest, TW_MEMREF pData)
601 TW_UINT16 twRC = TWRC_SUCCESS;
602 activeDS *pSource = TWAIN_LookupSource (pDest);
604 TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS\n");
609 DSM_twCC = TWCC_BADDEST;
611 else if (pSource->currentState != 5)
614 pSource->twCC = TWCC_SEQERROR;
618 pSource->currentState = 4;
620 pSource->twCC = TWCC_SUCCESS;
626 /* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS */
627 TW_UINT16 TWAIN_EnableDSUserInterface (pTW_IDENTITY pOrigin,
628 pTW_IDENTITY pDest, TW_MEMREF pData)
630 TW_UINT16 twRC = TWRC_SUCCESS;
631 pTW_USERINTERFACE pUserInterface = (pTW_USERINTERFACE) pData;
632 activeDS *pSource = TWAIN_LookupSource (pDest);
634 TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS\n");
639 DSM_twCC = TWCC_BADDEST;
641 else if (pSource->currentState != 4)
644 pSource->twCC = TWCC_SEQERROR;
648 if (pUserInterface->ShowUI)
651 pSource->currentState = 5; /* Transitions to state 5 */
652 rc = DoScannerUI(pSource);
655 pSource->pendingEvent.TWMessage = MSG_CLOSEDSREQ;
660 sane_get_parameters (pSource->deviceHandle, &pSource->sane_param);
661 pSource->sane_param_valid = TRUE;
667 /* no UI will be displayed, so source is ready to transfer data */
668 pSource->pendingEvent.TWMessage = MSG_XFERREADY;
669 pSource->currentState = 6; /* Transitions to state 6 directly */
672 pSource->hwndOwner = pUserInterface->hParent;
674 pSource->twCC = TWCC_SUCCESS;
680 /* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY */
681 TW_UINT16 TWAIN_EnableDSUIOnly (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
684 TW_UINT16 twRC = TWRC_SUCCESS;
685 activeDS *pSource = TWAIN_LookupSource (pDest);
687 TRACE("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY\n");
692 DSM_twCC = TWCC_BADDEST;
694 else if (pSource->currentState != 4)
697 pSource->twCC = TWCC_SEQERROR;
701 /* FIXME: we should replace xscanimage with our own UI */
702 system ("xscanimage");
703 pSource->currentState = 5;
705 pSource->twCC = TWCC_SUCCESS;
711 /* DG_CONTROL/DAT_XFERGROUP/MSG_GET */
712 TW_UINT16 TWAIN_XferGroupGet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
720 /* DG_CONTROL/DAT_XFERGROUP/MSG_SET */
721 TW_UINT16 TWAIN_XferGroupSet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,