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 twRC = (twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
166 activeDS.twCC = twCC;
171 /* DG_CONTROL/DAT_CUSTOMDSDATA/MSG_GET */
172 TW_UINT16 SANE_CustomDSDataGet (pTW_IDENTITY pOrigin,
180 /* DG_CONTROL/DAT_CUSTOMDSDATA/MSG_SET */
181 TW_UINT16 SANE_CustomDSDataSet (pTW_IDENTITY pOrigin,
189 /* DG_CONTROL/DAT_FILESYSTEM/MSG_AUTOMATICCAPTUREDIRECTORY */
190 TW_UINT16 SANE_AutomaticCaptureDirectory (pTW_IDENTITY pOrigin,
199 /* DG_CONTROL/DAT_FILESYSTEM/MSG_CHANGEDIRECTORY */
200 TW_UINT16 SANE_ChangeDirectory (pTW_IDENTITY pOrigin,
208 /* DG_CONTROL/DAT_FILESYSTEM/MSG_COPY */
209 TW_UINT16 SANE_FileSystemCopy (pTW_IDENTITY pOrigin,
217 /* DG_CONTROL/DAT_FILESYSTEM/MSG_CREATEDIRECTORY */
218 TW_UINT16 SANE_CreateDirectory (pTW_IDENTITY pOrigin,
226 /* DG_CONTROL/DAT_FILESYSTEM/MSG_DELETE */
227 TW_UINT16 SANE_FileSystemDelete (pTW_IDENTITY pOrigin,
235 /* DG_CONTROL/DAT_FILESYSTEM/MSG_FORMATMEDIA */
236 TW_UINT16 SANE_FormatMedia (pTW_IDENTITY pOrigin,
244 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETCLOSE */
245 TW_UINT16 SANE_FileSystemGetClose (pTW_IDENTITY pOrigin,
253 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETFIRSTFILE */
254 TW_UINT16 SANE_FileSystemGetFirstFile (pTW_IDENTITY pOrigin,
263 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETINFO */
264 TW_UINT16 SANE_FileSystemGetInfo (pTW_IDENTITY pOrigin,
272 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETNEXTFILE */
273 TW_UINT16 SANE_FileSystemGetNextFile (pTW_IDENTITY pOrigin,
282 /* DG_CONTROL/DAT_FILESYSTEM/MSG_RENAME */
283 TW_UINT16 SANE_FileSystemRename (pTW_IDENTITY pOrigin,
291 /* DG_CONTROL/DAT_EVENT/MSG_PROCESSEVENT */
292 TW_UINT16 SANE_ProcessEvent (pTW_IDENTITY pOrigin,
295 TW_UINT16 twRC = TWRC_NOTDSEVENT;
296 pTW_EVENT pEvent = (pTW_EVENT) pData;
297 MSG *pMsg = pEvent->pEvent;
299 TRACE("DG_CONTROL/DAT_EVENT/MSG_PROCESSEVENT msg 0x%x, wParam 0x%lx\n", pMsg->message, pMsg->wParam);
301 activeDS.twCC = TWCC_SUCCESS;
302 if (pMsg->message == activeDS.windowMessage && activeDS.windowMessage)
305 pEvent->TWMessage = pMsg->wParam;
308 pEvent->TWMessage = MSG_NULL; /* no message to the application */
310 if (activeDS.currentState < 5 || activeDS.currentState > 7)
313 activeDS.twCC = TWCC_SEQERROR;
319 /* DG_CONTROL/DAT_PASSTHRU/MSG_PASSTHRU */
320 TW_UINT16 SANE_PassThrough (pTW_IDENTITY pOrigin,
328 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER */
329 TW_UINT16 SANE_PendingXfersEndXfer (pTW_IDENTITY pOrigin,
332 TW_UINT16 twRC = TWRC_SUCCESS;
333 pTW_PENDINGXFERS pPendingXfers = (pTW_PENDINGXFERS) pData;
335 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER\n");
337 if (activeDS.currentState != 6 && activeDS.currentState != 7)
340 activeDS.twCC = TWCC_SEQERROR;
344 if (pPendingXfers->Count != 0)
346 pPendingXfers->Count --;
347 activeDS.currentState = 6;
351 activeDS.currentState = 5;
352 /* Notify the application that it can close the data source */
353 if (activeDS.windowMessage)
354 PostMessageA(activeDS.hwndOwner, activeDS.windowMessage, MSG_CLOSEDSREQ, 0);
357 activeDS.twCC = TWCC_SUCCESS;
363 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_GET */
364 TW_UINT16 SANE_PendingXfersGet (pTW_IDENTITY pOrigin,
367 TW_UINT16 twRC = TWRC_SUCCESS;
368 pTW_PENDINGXFERS pPendingXfers = (pTW_PENDINGXFERS) pData;
370 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_GET\n");
372 if (activeDS.currentState < 4 || activeDS.currentState > 7)
375 activeDS.twCC = TWCC_SEQERROR;
379 /* FIXME: we shouldn't return 1 here */
380 pPendingXfers->Count = 1;
382 activeDS.twCC = TWCC_SUCCESS;
388 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET */
389 TW_UINT16 SANE_PendingXfersReset (pTW_IDENTITY pOrigin,
392 TW_UINT16 twRC = TWRC_SUCCESS;
393 pTW_PENDINGXFERS pPendingXfers = (pTW_PENDINGXFERS) pData;
395 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET\n");
397 if (activeDS.currentState != 6)
400 activeDS.twCC = TWCC_SEQERROR;
404 pPendingXfers->Count = 0;
405 activeDS.currentState = 5;
407 activeDS.twCC = TWCC_SUCCESS;
413 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_STOPFEEDER */
414 TW_UINT16 SANE_PendingXfersStopFeeder (pTW_IDENTITY pOrigin,
422 /* DG_CONTROL/DAT_SETUPFILEXFER/MSG_GET */
423 TW_UINT16 SANE_SetupFileXferGet (pTW_IDENTITY pOrigin,
431 /* DG_CONTROL/DAT_SETUPXFER/MSG_GETDEFAULT */
432 TW_UINT16 SANE_SetupFileXferGetDefault (pTW_IDENTITY pOrigin,
441 /* DG_CONTROL/DAT_SETUPFILEXFER/MSG_RESET */
442 TW_UINT16 SANE_SetupFileXferReset (pTW_IDENTITY pOrigin,
450 /* DG_CONTROL/DAT_SETUPFILEXFER/MSG_SET */
451 TW_UINT16 SANE_SetupFileXferSet (pTW_IDENTITY pOrigin,
459 /* DG_CONTROL/DAT_SETUPFILEXFER2/MSG_GET */
460 TW_UINT16 SANE_SetupFileXfer2Get (pTW_IDENTITY pOrigin,
468 /* DG_CONTROL/DAT_SETUPFILEXFER2/MSG_GETDEFAULT */
469 TW_UINT16 SANE_SetupFileXfer2GetDefault (pTW_IDENTITY pOrigin,
477 /* DG_CONTROL/DAT_SETUPFILEXFER2/MSG_RESET */
478 TW_UINT16 SANE_SetupFileXfer2Reset (pTW_IDENTITY pOrigin,
486 /* DG_CONTROL/DAT_SETUPFILEXFER2/MSG_SET */
487 TW_UINT16 SANE_SetupFileXfer2Set (pTW_IDENTITY pOrigin,
495 /* DG_CONTROL/DAT_SETUPMEMXFER/MSG_GET */
496 TW_UINT16 SANE_SetupMemXferGet (pTW_IDENTITY pOrigin,
499 #ifndef SONAME_LIBSANE
502 pTW_SETUPMEMXFER pSetupMemXfer = (pTW_SETUPMEMXFER)pData;
504 TRACE("DG_CONTROL/DAT_SETUPMEMXFER/MSG_GET\n");
505 if (activeDS.sane_param_valid)
507 pSetupMemXfer->MinBufSize = activeDS.sane_param.bytes_per_line;
508 pSetupMemXfer->MaxBufSize = activeDS.sane_param.bytes_per_line * 8;
509 pSetupMemXfer->Preferred = activeDS.sane_param.bytes_per_line * 2;
514 pSetupMemXfer->MinBufSize = 2000;
515 pSetupMemXfer->MaxBufSize = 8000;
516 pSetupMemXfer->Preferred = 4000;
523 /* DG_CONTROL/DAT_STATUS/MSG_GET */
524 TW_UINT16 SANE_GetDSStatus (pTW_IDENTITY pOrigin,
527 pTW_STATUS pSourceStatus = (pTW_STATUS) pData;
529 TRACE ("DG_CONTROL/DAT_STATUS/MSG_GET\n");
530 pSourceStatus->ConditionCode = activeDS.twCC;
531 /* Reset the condition code */
532 activeDS.twCC = TWCC_SUCCESS;
536 /* DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS */
537 TW_UINT16 SANE_DisableDSUserInterface (pTW_IDENTITY pOrigin,
540 TW_UINT16 twRC = TWRC_SUCCESS;
542 TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS\n");
544 if (activeDS.currentState != 5)
547 activeDS.twCC = TWCC_SEQERROR;
551 activeDS.currentState = 4;
553 activeDS.twCC = TWCC_SUCCESS;
559 /* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS */
560 TW_UINT16 SANE_EnableDSUserInterface (pTW_IDENTITY pOrigin,
563 TW_UINT16 twRC = TWRC_SUCCESS;
564 pTW_USERINTERFACE pUserInterface = (pTW_USERINTERFACE) pData;
566 TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS\n");
568 if (activeDS.currentState != 4)
571 activeDS.twCC = TWCC_SEQERROR;
572 FIXME("sequence error %d\n", activeDS.currentState);
576 activeDS.hwndOwner = pUserInterface->hParent;
577 if (! activeDS.windowMessage)
578 activeDS.windowMessage = RegisterWindowMessageA("SANE.DS ACTIVITY MESSAGE");
579 if (pUserInterface->ShowUI)
582 activeDS.currentState = 5; /* Transitions to state 5 */
583 FIXME("showing UI\n");
585 pUserInterface->ModalUI = TRUE;
588 if (activeDS.windowMessage)
589 PostMessageA(activeDS.hwndOwner, activeDS.windowMessage, MSG_CLOSEDSREQ, 0);
591 #ifdef SONAME_LIBSANE
594 psane_get_parameters (activeDS.deviceHandle, &activeDS.sane_param);
595 activeDS.sane_param_valid = TRUE;
601 /* no UI will be displayed, so source is ready to transfer data */
602 activeDS.currentState = 6; /* Transitions to state 6 directly */
603 if (activeDS.windowMessage)
604 PostMessageA(activeDS.hwndOwner, activeDS.windowMessage, MSG_XFERREADY, 0);
608 activeDS.twCC = TWCC_SUCCESS;
614 /* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY */
615 TW_UINT16 SANE_EnableDSUIOnly (pTW_IDENTITY pOrigin,
618 TW_UINT16 twRC = TWRC_SUCCESS;
620 TRACE("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY\n");
622 if (activeDS.currentState != 4)
625 activeDS.twCC = TWCC_SEQERROR;
629 /* FIXME: we should replace xscanimage with our own UI */
630 system ("xscanimage");
631 activeDS.currentState = 5;
633 activeDS.twCC = TWCC_SUCCESS;
639 /* DG_CONTROL/DAT_XFERGROUP/MSG_GET */
640 TW_UINT16 SANE_XferGroupGet (pTW_IDENTITY pOrigin,
648 /* DG_CONTROL/DAT_XFERGROUP/MSG_SET */
649 TW_UINT16 SANE_XferGroupSet (pTW_IDENTITY pOrigin,