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,
109 /* DG_CONTROL/DAT_CAPABILITY/MSG_RESET */
110 TW_UINT16 SANE_CapabilityReset (pTW_IDENTITY pOrigin,
113 TW_UINT16 twRC = TWRC_SUCCESS, twCC = TWCC_SUCCESS;
114 pTW_CAPABILITY pCapability = (pTW_CAPABILITY) pData;
116 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_RESET\n");
118 if (activeDS.currentState < 4 || activeDS.currentState > 7)
121 activeDS.twCC = TWCC_SEQERROR;
125 twCC = SANE_SaneCapability (pCapability, MSG_RESET);
126 twRC = (twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
127 activeDS.twCC = twCC;
133 /* DG_CONTROL/DAT_CAPABILITY/MSG_SET */
134 TW_UINT16 SANE_CapabilitySet (pTW_IDENTITY pOrigin,
137 TW_UINT16 twRC = TWRC_SUCCESS, twCC = TWCC_SUCCESS;
138 pTW_CAPABILITY pCapability = (pTW_CAPABILITY) pData;
140 TRACE ("DG_CONTROL/DAT_CAPABILITY/MSG_SET\n");
142 if (activeDS.currentState != 4)
145 activeDS.twCC = TWCC_SEQERROR;
149 twCC = SANE_SaneCapability (pCapability, MSG_SET);
150 twRC = (twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
151 activeDS.twCC = twCC;
156 /* DG_CONTROL/DAT_CUSTOMDSDATA/MSG_GET */
157 TW_UINT16 SANE_CustomDSDataGet (pTW_IDENTITY pOrigin,
165 /* DG_CONTROL/DAT_CUSTOMDSDATA/MSG_SET */
166 TW_UINT16 SANE_CustomDSDataSet (pTW_IDENTITY pOrigin,
174 /* DG_CONTROL/DAT_FILESYSTEM/MSG_AUTOMATICCAPTUREDIRECTORY */
175 TW_UINT16 SANE_AutomaticCaptureDirectory (pTW_IDENTITY pOrigin,
184 /* DG_CONTROL/DAT_FILESYSTEM/MSG_CHANGEDIRECTORY */
185 TW_UINT16 SANE_ChangeDirectory (pTW_IDENTITY pOrigin,
193 /* DG_CONTROL/DAT_FILESYSTEM/MSG_COPY */
194 TW_UINT16 SANE_FileSystemCopy (pTW_IDENTITY pOrigin,
202 /* DG_CONTROL/DAT_FILESYSTEM/MSG_CREATEDIRECTORY */
203 TW_UINT16 SANE_CreateDirectory (pTW_IDENTITY pOrigin,
211 /* DG_CONTROL/DAT_FILESYSTEM/MSG_DELETE */
212 TW_UINT16 SANE_FileSystemDelete (pTW_IDENTITY pOrigin,
220 /* DG_CONTROL/DAT_FILESYSTEM/MSG_FORMATMEDIA */
221 TW_UINT16 SANE_FormatMedia (pTW_IDENTITY pOrigin,
229 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETCLOSE */
230 TW_UINT16 SANE_FileSystemGetClose (pTW_IDENTITY pOrigin,
238 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETFIRSTFILE */
239 TW_UINT16 SANE_FileSystemGetFirstFile (pTW_IDENTITY pOrigin,
248 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETINFO */
249 TW_UINT16 SANE_FileSystemGetInfo (pTW_IDENTITY pOrigin,
257 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETNEXTFILE */
258 TW_UINT16 SANE_FileSystemGetNextFile (pTW_IDENTITY pOrigin,
267 /* DG_CONTROL/DAT_FILESYSTEM/MSG_RENAME */
268 TW_UINT16 SANE_FileSystemRename (pTW_IDENTITY pOrigin,
276 /* DG_CONTROL/DAT_EVENT/MSG_PROCESSEVENT */
277 TW_UINT16 SANE_ProcessEvent (pTW_IDENTITY pOrigin,
280 TW_UINT16 twRC = TWRC_SUCCESS;
281 pTW_EVENT pEvent = (pTW_EVENT) pData;
283 TRACE("DG_CONTROL/DAT_EVENT/MSG_PROCESSEVENT\n");
285 if (activeDS.currentState < 5 || activeDS.currentState > 7)
288 activeDS.twCC = TWCC_SEQERROR;
292 if (activeDS.pendingEvent.TWMessage != MSG_NULL)
294 pEvent->TWMessage = activeDS.pendingEvent.TWMessage;
295 activeDS.pendingEvent.TWMessage = MSG_NULL;
296 twRC = TWRC_NOTDSEVENT;
300 pEvent->TWMessage = MSG_NULL; /* no message to the application */
301 twRC = TWRC_NOTDSEVENT;
303 activeDS.twCC = TWCC_SUCCESS;
309 /* DG_CONTROL/DAT_PASSTHRU/MSG_PASSTHRU */
310 TW_UINT16 SANE_PassThrough (pTW_IDENTITY pOrigin,
318 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER */
319 TW_UINT16 SANE_PendingXfersEndXfer (pTW_IDENTITY pOrigin,
322 TW_UINT16 twRC = TWRC_SUCCESS;
323 pTW_PENDINGXFERS pPendingXfers = (pTW_PENDINGXFERS) pData;
325 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER\n");
327 if (activeDS.currentState != 6 && activeDS.currentState != 7)
330 activeDS.twCC = TWCC_SEQERROR;
334 if (pPendingXfers->Count != 0)
336 pPendingXfers->Count --;
337 activeDS.currentState = 6;
341 activeDS.currentState = 5;
342 /* Notify the application that it can close the data source */
343 activeDS.pendingEvent.TWMessage = MSG_CLOSEDSREQ;
346 activeDS.twCC = TWCC_SUCCESS;
352 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_GET */
353 TW_UINT16 SANE_PendingXfersGet (pTW_IDENTITY pOrigin,
356 TW_UINT16 twRC = TWRC_SUCCESS;
357 pTW_PENDINGXFERS pPendingXfers = (pTW_PENDINGXFERS) pData;
359 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_GET\n");
361 if (activeDS.currentState < 4 || activeDS.currentState > 7)
364 activeDS.twCC = TWCC_SEQERROR;
368 /* FIXME: we shouldn't return 1 here */
369 pPendingXfers->Count = 1;
371 activeDS.twCC = TWCC_SUCCESS;
377 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET */
378 TW_UINT16 SANE_PendingXfersReset (pTW_IDENTITY pOrigin,
381 TW_UINT16 twRC = TWRC_SUCCESS;
382 pTW_PENDINGXFERS pPendingXfers = (pTW_PENDINGXFERS) pData;
384 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET\n");
386 if (activeDS.currentState != 6)
389 activeDS.twCC = TWCC_SEQERROR;
393 pPendingXfers->Count = 0;
394 activeDS.currentState = 5;
396 activeDS.twCC = TWCC_SUCCESS;
402 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_STOPFEEDER */
403 TW_UINT16 SANE_PendingXfersStopFeeder (pTW_IDENTITY pOrigin,
411 /* DG_CONTROL/DAT_SETUPFILEXFER/MSG_GET */
412 TW_UINT16 SANE_SetupFileXferGet (pTW_IDENTITY pOrigin,
420 /* DG_CONTROL/DAT_SETUPXFER/MSG_GETDEFAULT */
421 TW_UINT16 SANE_SetupFileXferGetDefault (pTW_IDENTITY pOrigin,
430 /* DG_CONTROL/DAT_SETUPFILEXFER/MSG_RESET */
431 TW_UINT16 SANE_SetupFileXferReset (pTW_IDENTITY pOrigin,
439 /* DG_CONTROL/DAT_SETUPFILEXFER/MSG_SET */
440 TW_UINT16 SANE_SetupFileXferSet (pTW_IDENTITY pOrigin,
448 /* DG_CONTROL/DAT_SETUPFILEXFER2/MSG_GET */
449 TW_UINT16 SANE_SetupFileXfer2Get (pTW_IDENTITY pOrigin,
457 /* DG_CONTROL/DAT_SETUPFILEXFER2/MSG_GETDEFAULT */
458 TW_UINT16 SANE_SetupFileXfer2GetDefault (pTW_IDENTITY pOrigin,
466 /* DG_CONTROL/DAT_SETUPFILEXFER2/MSG_RESET */
467 TW_UINT16 SANE_SetupFileXfer2Reset (pTW_IDENTITY pOrigin,
475 /* DG_CONTROL/DAT_SETUPFILEXFER2/MSG_SET */
476 TW_UINT16 SANE_SetupFileXfer2Set (pTW_IDENTITY pOrigin,
484 /* DG_CONTROL/DAT_SETUPMEMXFER/MSG_GET */
485 TW_UINT16 SANE_SetupMemXferGet (pTW_IDENTITY pOrigin,
488 #ifndef SONAME_LIBSANE
491 pTW_SETUPMEMXFER pSetupMemXfer = (pTW_SETUPMEMXFER)pData;
493 TRACE("DG_CONTROL/DAT_SETUPMEMXFER/MSG_GET\n");
494 if (activeDS.sane_param_valid)
496 pSetupMemXfer->MinBufSize = activeDS.sane_param.bytes_per_line;
497 pSetupMemXfer->MaxBufSize = activeDS.sane_param.bytes_per_line * 8;
498 pSetupMemXfer->Preferred = activeDS.sane_param.bytes_per_line * 2;
503 pSetupMemXfer->MinBufSize = 2000;
504 pSetupMemXfer->MaxBufSize = 8000;
505 pSetupMemXfer->Preferred = 4000;
512 /* DG_CONTROL/DAT_STATUS/MSG_GET */
513 TW_UINT16 SANE_GetDSStatus (pTW_IDENTITY pOrigin,
516 pTW_STATUS pSourceStatus = (pTW_STATUS) pData;
518 TRACE ("DG_CONTROL/DAT_STATUS/MSG_GET\n");
519 pSourceStatus->ConditionCode = activeDS.twCC;
520 /* Reset the condition code */
521 activeDS.twCC = TWCC_SUCCESS;
525 /* DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS */
526 TW_UINT16 SANE_DisableDSUserInterface (pTW_IDENTITY pOrigin,
529 TW_UINT16 twRC = TWRC_SUCCESS;
531 TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS\n");
533 if (activeDS.currentState != 5)
536 activeDS.twCC = TWCC_SEQERROR;
540 activeDS.currentState = 4;
542 activeDS.twCC = TWCC_SUCCESS;
548 /* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS */
549 TW_UINT16 SANE_EnableDSUserInterface (pTW_IDENTITY pOrigin,
552 TW_UINT16 twRC = TWRC_SUCCESS;
553 pTW_USERINTERFACE pUserInterface = (pTW_USERINTERFACE) pData;
555 TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS\n");
557 if (activeDS.currentState != 4)
560 activeDS.twCC = TWCC_SEQERROR;
561 FIXME("sequence error %d\n", activeDS.currentState);
565 activeDS.hwndOwner = pUserInterface->hParent;
566 if (pUserInterface->ShowUI)
569 activeDS.currentState = 5; /* Transitions to state 5 */
570 FIXME("showing UI\n");
574 activeDS.pendingEvent.TWMessage = MSG_CLOSEDSREQ;
576 #ifdef SONAME_LIBSANE
579 psane_get_parameters (activeDS.deviceHandle, &activeDS.sane_param);
580 activeDS.sane_param_valid = TRUE;
586 /* no UI will be displayed, so source is ready to transfer data */
587 activeDS.pendingEvent.TWMessage = MSG_XFERREADY;
588 activeDS.currentState = 6; /* Transitions to state 6 directly */
591 activeDS.hwndOwner = pUserInterface->hParent;
593 activeDS.twCC = TWCC_SUCCESS;
599 /* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY */
600 TW_UINT16 SANE_EnableDSUIOnly (pTW_IDENTITY pOrigin,
603 TW_UINT16 twRC = TWRC_SUCCESS;
605 TRACE("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY\n");
607 if (activeDS.currentState != 4)
610 activeDS.twCC = TWCC_SEQERROR;
614 /* FIXME: we should replace xscanimage with our own UI */
615 system ("xscanimage");
616 activeDS.currentState = 5;
618 activeDS.twCC = TWCC_SUCCESS;
624 /* DG_CONTROL/DAT_XFERGROUP/MSG_GET */
625 TW_UINT16 SANE_XferGroupGet (pTW_IDENTITY pOrigin,
633 /* DG_CONTROL/DAT_XFERGROUP/MSG_SET */
634 TW_UINT16 SANE_XferGroupSet (pTW_IDENTITY pOrigin,