dpnet: Assign to structs instead of using memcpy.
[wine.git] / dlls / sane.ds / ds_ctrl.c
blobdbd3f3eded7176a27ae75295c54477542e8f7f15
1 /*
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
19 #include "config.h"
21 #ifdef HAVE_UNISTD_H
22 # include <unistd.h>
23 #endif
24 #include <stdlib.h>
25 #include "twain.h"
26 #include "sane_i.h"
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)
41 twRC = TWRC_FAILURE;
42 activeDS.twCC = TWCC_SEQERROR;
44 else
46 twCC = SANE_SaneCapability (pCapability, MSG_GET);
47 twRC = (twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
48 activeDS.twCC = twCC;
51 return twRC;
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)
64 twRC = TWRC_FAILURE;
65 activeDS.twCC = TWCC_SEQERROR;
67 else
69 twCC = SANE_SaneCapability (pCapability, MSG_GETCURRENT);
70 twRC = (twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
71 activeDS.twCC = twCC;
74 return twRC;
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)
87 twRC = TWRC_FAILURE;
88 activeDS.twCC = TWCC_SEQERROR;
90 else
92 twCC = SANE_SaneCapability (pCapability, MSG_GETDEFAULT);
93 twRC = (twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
94 activeDS.twCC = twCC;
97 return twRC;
100 /* DG_CONTROL/DAT_CAPABILITY/MSG_QUERYSUPPORT */
101 TW_UINT16 SANE_CapabilityQuerySupport (pTW_IDENTITY pOrigin,
102 TW_MEMREF pData)
104 FIXME ("stub!\n");
106 return TWRC_FAILURE;
109 /* DG_CONTROL/DAT_CAPABILITY/MSG_RESET */
110 TW_UINT16 SANE_CapabilityReset (pTW_IDENTITY pOrigin,
111 TW_MEMREF pData)
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)
120 twRC = TWRC_FAILURE;
121 activeDS.twCC = TWCC_SEQERROR;
123 else
125 twCC = SANE_SaneCapability (pCapability, MSG_RESET);
126 twRC = (twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
127 activeDS.twCC = twCC;
130 return twRC;
133 /* DG_CONTROL/DAT_CAPABILITY/MSG_SET */
134 TW_UINT16 SANE_CapabilitySet (pTW_IDENTITY pOrigin,
135 TW_MEMREF pData)
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)
144 twRC = TWRC_FAILURE;
145 activeDS.twCC = TWCC_SEQERROR;
147 else
149 twCC = SANE_SaneCapability (pCapability, MSG_SET);
150 twRC = (twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
151 activeDS.twCC = twCC;
153 return twRC;
156 /* DG_CONTROL/DAT_CUSTOMDSDATA/MSG_GET */
157 TW_UINT16 SANE_CustomDSDataGet (pTW_IDENTITY pOrigin,
158 TW_MEMREF pData)
160 FIXME ("stub!\n");
162 return TWRC_FAILURE;
165 /* DG_CONTROL/DAT_CUSTOMDSDATA/MSG_SET */
166 TW_UINT16 SANE_CustomDSDataSet (pTW_IDENTITY pOrigin,
167 TW_MEMREF pData)
169 FIXME ("stub!\n");
171 return TWRC_FAILURE;
174 /* DG_CONTROL/DAT_FILESYSTEM/MSG_AUTOMATICCAPTUREDIRECTORY */
175 TW_UINT16 SANE_AutomaticCaptureDirectory (pTW_IDENTITY pOrigin,
177 TW_MEMREF pData)
179 FIXME ("stub!\n");
181 return TWRC_FAILURE;
184 /* DG_CONTROL/DAT_FILESYSTEM/MSG_CHANGEDIRECTORY */
185 TW_UINT16 SANE_ChangeDirectory (pTW_IDENTITY pOrigin,
186 TW_MEMREF pData)
188 FIXME ("stub!\n");
190 return TWRC_FAILURE;
193 /* DG_CONTROL/DAT_FILESYSTEM/MSG_COPY */
194 TW_UINT16 SANE_FileSystemCopy (pTW_IDENTITY pOrigin,
195 TW_MEMREF pData)
197 FIXME ("stub!\n");
199 return TWRC_FAILURE;
202 /* DG_CONTROL/DAT_FILESYSTEM/MSG_CREATEDIRECTORY */
203 TW_UINT16 SANE_CreateDirectory (pTW_IDENTITY pOrigin,
204 TW_MEMREF pData)
206 FIXME ("stub!\n");
208 return TWRC_FAILURE;
211 /* DG_CONTROL/DAT_FILESYSTEM/MSG_DELETE */
212 TW_UINT16 SANE_FileSystemDelete (pTW_IDENTITY pOrigin,
213 TW_MEMREF pData)
215 FIXME ("stub!\n");
217 return TWRC_FAILURE;
220 /* DG_CONTROL/DAT_FILESYSTEM/MSG_FORMATMEDIA */
221 TW_UINT16 SANE_FormatMedia (pTW_IDENTITY pOrigin,
222 TW_MEMREF pData)
224 FIXME ("stub!\n");
226 return TWRC_FAILURE;
229 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETCLOSE */
230 TW_UINT16 SANE_FileSystemGetClose (pTW_IDENTITY pOrigin,
231 TW_MEMREF pData)
233 FIXME ("stub!\n");
235 return TWRC_FAILURE;
238 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETFIRSTFILE */
239 TW_UINT16 SANE_FileSystemGetFirstFile (pTW_IDENTITY pOrigin,
241 TW_MEMREF pData)
243 FIXME ("stub!\n");
245 return TWRC_FAILURE;
248 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETINFO */
249 TW_UINT16 SANE_FileSystemGetInfo (pTW_IDENTITY pOrigin,
250 TW_MEMREF pData)
252 FIXME ("stub!\n");
254 return TWRC_FAILURE;
257 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETNEXTFILE */
258 TW_UINT16 SANE_FileSystemGetNextFile (pTW_IDENTITY pOrigin,
260 TW_MEMREF pData)
262 FIXME ("stub!\n");
264 return TWRC_FAILURE;
267 /* DG_CONTROL/DAT_FILESYSTEM/MSG_RENAME */
268 TW_UINT16 SANE_FileSystemRename (pTW_IDENTITY pOrigin,
269 TW_MEMREF pData)
271 FIXME ("stub!\n");
273 return TWRC_FAILURE;
276 /* DG_CONTROL/DAT_EVENT/MSG_PROCESSEVENT */
277 TW_UINT16 SANE_ProcessEvent (pTW_IDENTITY pOrigin,
278 TW_MEMREF pData)
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)
287 twRC = TWRC_FAILURE;
288 activeDS.twCC = TWCC_SEQERROR;
290 else
292 if (activeDS.pendingEvent.TWMessage != MSG_NULL)
294 pEvent->TWMessage = activeDS.pendingEvent.TWMessage;
295 activeDS.pendingEvent.TWMessage = MSG_NULL;
296 twRC = TWRC_NOTDSEVENT;
298 else
300 pEvent->TWMessage = MSG_NULL; /* no message to the application */
301 twRC = TWRC_NOTDSEVENT;
303 activeDS.twCC = TWCC_SUCCESS;
306 return twRC;
309 /* DG_CONTROL/DAT_PASSTHRU/MSG_PASSTHRU */
310 TW_UINT16 SANE_PassThrough (pTW_IDENTITY pOrigin,
311 TW_MEMREF pData)
313 FIXME ("stub!\n");
315 return TWRC_FAILURE;
318 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER */
319 TW_UINT16 SANE_PendingXfersEndXfer (pTW_IDENTITY pOrigin,
320 TW_MEMREF pData)
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)
329 twRC = TWRC_FAILURE;
330 activeDS.twCC = TWCC_SEQERROR;
332 else
334 if (pPendingXfers->Count != 0)
336 pPendingXfers->Count --;
337 activeDS.currentState = 6;
339 else
341 activeDS.currentState = 5;
342 /* Notify the application that it can close the data source */
343 activeDS.pendingEvent.TWMessage = MSG_CLOSEDSREQ;
345 twRC = TWRC_SUCCESS;
346 activeDS.twCC = TWCC_SUCCESS;
349 return twRC;
352 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_GET */
353 TW_UINT16 SANE_PendingXfersGet (pTW_IDENTITY pOrigin,
354 TW_MEMREF pData)
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)
363 twRC = TWRC_FAILURE;
364 activeDS.twCC = TWCC_SEQERROR;
366 else
368 /* FIXME: we shouldn't return 1 here */
369 pPendingXfers->Count = 1;
370 twRC = TWRC_SUCCESS;
371 activeDS.twCC = TWCC_SUCCESS;
374 return twRC;
377 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET */
378 TW_UINT16 SANE_PendingXfersReset (pTW_IDENTITY pOrigin,
379 TW_MEMREF pData)
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)
388 twRC = TWRC_FAILURE;
389 activeDS.twCC = TWCC_SEQERROR;
391 else
393 pPendingXfers->Count = 0;
394 activeDS.currentState = 5;
395 twRC = TWRC_SUCCESS;
396 activeDS.twCC = TWCC_SUCCESS;
399 return twRC;
402 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_STOPFEEDER */
403 TW_UINT16 SANE_PendingXfersStopFeeder (pTW_IDENTITY pOrigin,
404 TW_MEMREF pData)
406 FIXME ("stub!\n");
408 return TWRC_FAILURE;
411 /* DG_CONTROL/DAT_SETUPFILEXFER/MSG_GET */
412 TW_UINT16 SANE_SetupFileXferGet (pTW_IDENTITY pOrigin,
413 TW_MEMREF pData)
415 FIXME ("stub!\n");
417 return TWRC_FAILURE;
420 /* DG_CONTROL/DAT_SETUPXFER/MSG_GETDEFAULT */
421 TW_UINT16 SANE_SetupFileXferGetDefault (pTW_IDENTITY pOrigin,
422 TW_MEMREF pData)
424 FIXME ("stub!\n");
426 return TWRC_FAILURE;
430 /* DG_CONTROL/DAT_SETUPFILEXFER/MSG_RESET */
431 TW_UINT16 SANE_SetupFileXferReset (pTW_IDENTITY pOrigin,
432 TW_MEMREF pData)
434 FIXME ("stub!\n");
436 return TWRC_FAILURE;
439 /* DG_CONTROL/DAT_SETUPFILEXFER/MSG_SET */
440 TW_UINT16 SANE_SetupFileXferSet (pTW_IDENTITY pOrigin,
441 TW_MEMREF pData)
443 FIXME ("stub!\n");
445 return TWRC_FAILURE;
448 /* DG_CONTROL/DAT_SETUPFILEXFER2/MSG_GET */
449 TW_UINT16 SANE_SetupFileXfer2Get (pTW_IDENTITY pOrigin,
450 TW_MEMREF pData)
452 FIXME ("stub!\n");
454 return TWRC_FAILURE;
457 /* DG_CONTROL/DAT_SETUPFILEXFER2/MSG_GETDEFAULT */
458 TW_UINT16 SANE_SetupFileXfer2GetDefault (pTW_IDENTITY pOrigin,
459 TW_MEMREF pData)
461 FIXME ("stub!\n");
463 return TWRC_FAILURE;
466 /* DG_CONTROL/DAT_SETUPFILEXFER2/MSG_RESET */
467 TW_UINT16 SANE_SetupFileXfer2Reset (pTW_IDENTITY pOrigin,
468 TW_MEMREF pData)
470 FIXME ("stub!\n");
472 return TWRC_FAILURE;
475 /* DG_CONTROL/DAT_SETUPFILEXFER2/MSG_SET */
476 TW_UINT16 SANE_SetupFileXfer2Set (pTW_IDENTITY pOrigin,
477 TW_MEMREF pData)
479 FIXME ("stub!\n");
481 return TWRC_FAILURE;
484 /* DG_CONTROL/DAT_SETUPMEMXFER/MSG_GET */
485 TW_UINT16 SANE_SetupMemXferGet (pTW_IDENTITY pOrigin,
486 TW_MEMREF pData)
488 #ifndef SONAME_LIBSANE
489 return TWRC_FAILURE;
490 #else
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;
500 else
502 /* Guessing */
503 pSetupMemXfer->MinBufSize = 2000;
504 pSetupMemXfer->MaxBufSize = 8000;
505 pSetupMemXfer->Preferred = 4000;
508 return TWRC_SUCCESS;
509 #endif
512 /* DG_CONTROL/DAT_STATUS/MSG_GET */
513 TW_UINT16 SANE_GetDSStatus (pTW_IDENTITY pOrigin,
514 TW_MEMREF pData)
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;
522 return TWRC_SUCCESS;
525 /* DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS */
526 TW_UINT16 SANE_DisableDSUserInterface (pTW_IDENTITY pOrigin,
527 TW_MEMREF pData)
529 TW_UINT16 twRC = TWRC_SUCCESS;
531 TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS\n");
533 if (activeDS.currentState != 5)
535 twRC = TWRC_FAILURE;
536 activeDS.twCC = TWCC_SEQERROR;
538 else
540 activeDS.currentState = 4;
541 twRC = TWRC_SUCCESS;
542 activeDS.twCC = TWCC_SUCCESS;
545 return twRC;
548 /* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS */
549 TW_UINT16 SANE_EnableDSUserInterface (pTW_IDENTITY pOrigin,
550 TW_MEMREF pData)
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)
559 twRC = TWRC_FAILURE;
560 activeDS.twCC = TWCC_SEQERROR;
561 FIXME("sequence error %d\n", activeDS.currentState);
563 else
565 activeDS.hwndOwner = pUserInterface->hParent;
566 if (pUserInterface->ShowUI)
568 BOOL rc;
569 activeDS.currentState = 5; /* Transitions to state 5 */
570 FIXME("showing UI\n");
571 rc = DoScannerUI();
572 if (!rc)
574 activeDS.pendingEvent.TWMessage = MSG_CLOSEDSREQ;
576 #ifdef SONAME_LIBSANE
577 else
579 psane_get_parameters (activeDS.deviceHandle, &activeDS.sane_param);
580 activeDS.sane_param_valid = TRUE;
582 #endif
584 else
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;
592 twRC = TWRC_SUCCESS;
593 activeDS.twCC = TWCC_SUCCESS;
596 return twRC;
599 /* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY */
600 TW_UINT16 SANE_EnableDSUIOnly (pTW_IDENTITY pOrigin,
601 TW_MEMREF pData)
603 TW_UINT16 twRC = TWRC_SUCCESS;
605 TRACE("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY\n");
607 if (activeDS.currentState != 4)
609 twRC = TWRC_FAILURE;
610 activeDS.twCC = TWCC_SEQERROR;
612 else
614 /* FIXME: we should replace xscanimage with our own UI */
615 system ("xscanimage");
616 activeDS.currentState = 5;
617 twRC = TWRC_SUCCESS;
618 activeDS.twCC = TWCC_SUCCESS;
621 return twRC;
624 /* DG_CONTROL/DAT_XFERGROUP/MSG_GET */
625 TW_UINT16 SANE_XferGroupGet (pTW_IDENTITY pOrigin,
626 TW_MEMREF pData)
628 FIXME ("stub!\n");
630 return TWRC_FAILURE;
633 /* DG_CONTROL/DAT_XFERGROUP/MSG_SET */
634 TW_UINT16 SANE_XferGroupSet (pTW_IDENTITY pOrigin,
635 TW_MEMREF pData)
637 FIXME ("stub!\n");
639 return TWRC_FAILURE;