usp10: Add ScriptGetCMap functionality to translate wchars to glyphs.
[wine] / dlls / twain / ds_ctrl.c
1 /*
2  * Copyright 2000 Corel Corporation
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include "config.h"
20
21 #ifdef HAVE_UNISTD_H
22 # include <unistd.h>
23 #endif
24 #include <stdlib.h>
25 #include "twain.h"
26 #include "twain_i.h"
27 #include "wine/debug.h"
28
29 WINE_DEFAULT_DEBUG_CHANNEL(twain);
30
31 /* DG_CONTROL/DAT_CAPABILITY/MSG_GET */
32 TW_UINT16 TWAIN_CapabilityGet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
33                                TW_MEMREF pData)
34 {
35     TW_UINT16 twRC = TWRC_SUCCESS, twCC = TWCC_SUCCESS;
36     pTW_CAPABILITY pCapability = (pTW_CAPABILITY) pData;
37     activeDS *pSource = TWAIN_LookupSource (pDest);
38
39     TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_GET\n");
40
41     if (!pDest)
42     {
43         twRC = TWRC_FAILURE;
44         DSM_twCC = TWCC_BADDEST;
45     }
46     else if (pSource->currentState < 4 || pSource->currentState > 7)
47     {
48         twRC = TWRC_FAILURE;
49         pSource->twCC = TWCC_SEQERROR;
50     }
51     else
52     {
53         twCC = TWAIN_SaneCapability (pSource, pCapability, MSG_GET);
54         twRC = (twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
55         pSource->twCC = twCC;
56     }
57
58     return twRC;
59 }
60
61 /* DG_CONTROL/DAT_CAPABILITY/MSG_GETCURRENT */
62 TW_UINT16 TWAIN_CapabilityGetCurrent (pTW_IDENTITY pOrigin,
63                                       pTW_IDENTITY pDest,TW_MEMREF pData)
64 {
65     TW_UINT16 twRC = TWRC_SUCCESS, twCC = TWCC_SUCCESS;
66     pTW_CAPABILITY pCapability = (pTW_CAPABILITY) pData;
67     activeDS *pSource = TWAIN_LookupSource (pDest);
68
69     TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_GETCURRENT\n");
70
71     if (!pSource)
72     {
73         twRC = TWRC_FAILURE;
74         DSM_twCC = TWCC_BADDEST;
75     }
76     else if (pSource->currentState < 4 || pSource->currentState > 7)
77     {
78         twRC = TWRC_FAILURE;
79         pSource->twCC = TWCC_SEQERROR;
80     }
81     else
82     {
83         twCC = TWAIN_SaneCapability (pSource, pCapability, MSG_GETCURRENT);
84         twRC = (twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
85         pSource->twCC = twCC;
86     }
87
88     return twRC;
89 }
90
91 /* DG_CONTROL/DAT_CAPABILITY/MSG_GETDEFAULT */
92 TW_UINT16 TWAIN_CapabilityGetDefault (pTW_IDENTITY pOrigin,
93                                       pTW_IDENTITY pDest, TW_MEMREF pData)
94 {
95     TW_UINT16 twRC = TWRC_SUCCESS, twCC = TWCC_SUCCESS;
96     pTW_CAPABILITY pCapability = (pTW_CAPABILITY) pData;
97     activeDS *pSource = TWAIN_LookupSource (pDest);
98
99     TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_GETDEFAULT\n");
100
101     if (!pDest)
102     {
103         twRC = TWRC_FAILURE;
104         DSM_twCC = TWCC_BADDEST;
105     }
106     else if (pSource->currentState < 4 || pSource->currentState > 7)
107     {
108         twRC = TWRC_FAILURE;
109         pSource->twCC = TWCC_SEQERROR;
110     }
111     else
112     {
113         twCC = TWAIN_SaneCapability (pSource, pCapability, MSG_GETDEFAULT);
114         twRC = (twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
115         pSource->twCC = twCC;
116     }
117
118     return twRC;
119 }
120
121 /* DG_CONTROL/DAT_CAPABILITY/MSG_QUERYSUPPORT */
122 TW_UINT16 TWAIN_CapabilityQuerySupport (pTW_IDENTITY pOrigin,
123                                         pTW_IDENTITY pDest, TW_MEMREF pData)
124 {
125     FIXME ("stub!\n");
126
127     return TWRC_FAILURE;
128 }
129
130 /* DG_CONTROL/DAT_CAPABILITY/MSG_RESET */
131 TW_UINT16 TWAIN_CapabilityReset (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
132                                  TW_MEMREF pData)
133 {
134     TW_UINT16 twRC = TWRC_SUCCESS, twCC = TWCC_SUCCESS;
135     pTW_CAPABILITY pCapability = (pTW_CAPABILITY) pData;
136     activeDS *pSource = TWAIN_LookupSource (pDest);
137
138     TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_RESET\n");
139
140     if (!pDest)
141     {
142         twRC = TWRC_FAILURE;
143         DSM_twCC = TWCC_BADDEST;
144     }
145     else if (pSource->currentState < 4 || pSource->currentState > 7)
146     {
147         twRC = TWRC_FAILURE;
148         pSource->twCC = TWCC_SEQERROR;
149     }
150     else
151     {
152         twCC = TWAIN_SaneCapability (pSource, pCapability, MSG_RESET);
153         twRC = (twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
154         pSource->twCC = twCC;
155     }
156
157     return twRC;
158 }
159
160 /* DG_CONTROL/DAT_CAPABILITY/MSG_SET */
161 TW_UINT16 TWAIN_CapabilitySet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
162                                TW_MEMREF pData)
163 {
164     TW_UINT16 twRC = TWRC_SUCCESS, twCC = TWCC_SUCCESS;
165     pTW_CAPABILITY pCapability = (pTW_CAPABILITY) pData;
166     activeDS *pSource = TWAIN_LookupSource (pDest);
167
168     TRACE ("DG_CONTROL/DAT_CAPABILITY/MSG_SET\n");
169
170     if (!pSource)
171     {
172         twRC = TWRC_FAILURE;
173         DSM_twCC = TWCC_BADDEST;
174     }
175     else if (pSource->currentState != 4)
176     {
177         twRC = TWRC_FAILURE;
178         pSource->twCC = TWCC_SEQERROR;
179     }
180     else
181     {
182         twCC = TWAIN_SaneCapability (pSource, pCapability, MSG_SET);
183         twRC = (twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
184         pSource->twCC = twCC;
185     }
186     return twRC;
187 }
188
189 /* DG_CONTROL/DAT_CUSTOMDSDATA/MSG_GET */
190 TW_UINT16 TWAIN_CustomDSDataGet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
191                                 TW_MEMREF pData)
192 {
193     FIXME ("stub!\n");
194
195     return TWRC_FAILURE;
196 }
197
198 /* DG_CONTROL/DAT_CUSTOMDSDATA/MSG_SET */
199 TW_UINT16 TWAIN_CustomDSDataSet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
200                                  TW_MEMREF pData)
201 {
202     FIXME ("stub!\n");
203
204     return TWRC_FAILURE;
205 }
206
207 /* DG_CONTROL/DAT_FILESYSTEM/MSG_AUTOMATICCAPTUREDIRECTORY */
208 TW_UINT16 TWAIN_AutomaticCaptureDirectory (pTW_IDENTITY pOrigin,
209                                            pTW_IDENTITY pDest,
210                                            TW_MEMREF pData)
211 {
212     FIXME ("stub!\n");
213
214     return TWRC_FAILURE;
215 }
216
217 /* DG_CONTROL/DAT_FILESYSTEM/MSG_CHANGEDIRECTORY */
218 TW_UINT16 TWAIN_ChangeDirectory (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
219                                  TW_MEMREF pData)
220 {
221     FIXME ("stub!\n");
222
223     return TWRC_FAILURE;
224 }
225
226 /* DG_CONTROL/DAT_FILESYSTEM/MSG_COPY */
227 TW_UINT16 TWAIN_FileSystemCopy (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
228                                 TW_MEMREF pData)
229 {
230     FIXME ("stub!\n");
231
232     return TWRC_FAILURE;
233 }
234
235 /* DG_CONTROL/DAT_FILESYSTEM/MSG_CREATEDIRECTORY */
236 TW_UINT16 TWAIN_CreateDirectory (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
237                                  TW_MEMREF pData)
238 {
239     FIXME ("stub!\n");
240
241     return TWRC_FAILURE;
242 }
243
244 /* DG_CONTROL/DAT_FILESYSTEM/MSG_DELETE */
245 TW_UINT16 TWAIN_FileSystemDelete (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
246                                   TW_MEMREF pData)
247 {
248     FIXME ("stub!\n");
249
250     return TWRC_FAILURE;
251 }
252
253 /* DG_CONTROL/DAT_FILESYSTEM/MSG_FORMATMEDIA */
254 TW_UINT16 TWAIN_FormatMedia (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
255                              TW_MEMREF pData)
256 {
257     FIXME ("stub!\n");
258
259     return TWRC_FAILURE;
260 }
261
262 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETCLOSE */
263 TW_UINT16 TWAIN_FileSystemGetClose (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
264                                     TW_MEMREF pData)
265 {
266     FIXME ("stub!\n");
267
268     return TWRC_FAILURE;
269 }
270
271 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETFIRSTFILE */
272 TW_UINT16 TWAIN_FileSystemGetFirstFile (pTW_IDENTITY pOrigin,
273                                         pTW_IDENTITY pDest,
274                                         TW_MEMREF pData)
275 {
276     FIXME ("stub!\n");
277
278     return TWRC_FAILURE;
279 }
280
281 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETINFO */
282 TW_UINT16 TWAIN_FileSystemGetInfo (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
283                                    TW_MEMREF pData)
284 {
285     FIXME ("stub!\n");
286
287     return TWRC_FAILURE;
288 }
289
290 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETNEXTFILE */
291 TW_UINT16 TWAIN_FileSystemGetNextFile (pTW_IDENTITY pOrigin,
292                                        pTW_IDENTITY pDest,
293                                        TW_MEMREF pData)
294 {
295     FIXME ("stub!\n");
296
297     return TWRC_FAILURE;
298 }
299
300 /* DG_CONTROL/DAT_FILESYSTEM/MSG_RENAME */
301 TW_UINT16 TWAIN_FileSystemRename (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
302                                   TW_MEMREF pData)
303 {
304     FIXME ("stub!\n");
305
306     return TWRC_FAILURE;
307 }
308
309 /* DG_CONTROL/DAT_EVENT/MSG_PROCESSEVENT */
310 TW_UINT16 TWAIN_ProcessEvent (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
311                               TW_MEMREF pData)
312 {
313     TW_UINT16 twRC = TWRC_SUCCESS;
314     pTW_EVENT pEvent = (pTW_EVENT) pData;
315     activeDS *pSource = TWAIN_LookupSource (pDest);
316
317     TRACE("DG_CONTROL/DAT_EVENT/MSG_PROCESSEVENT\n");
318
319     if (!pSource)
320     {
321          twRC = TWRC_FAILURE;
322          DSM_twCC = TWCC_BADDEST;
323     }
324     else if (pSource->currentState < 5 || pSource->currentState > 7)
325     {
326         twRC = TWRC_FAILURE;
327         pSource->twCC = TWCC_SEQERROR;
328     }
329     else
330     {
331         if (pSource->pendingEvent.TWMessage != MSG_NULL)
332         {
333             pEvent->TWMessage = pSource->pendingEvent.TWMessage;
334             pSource->pendingEvent.TWMessage = MSG_NULL;
335             twRC = TWRC_NOTDSEVENT;
336         }
337         else
338         {
339             pEvent->TWMessage = MSG_NULL;  /* no message to the application */
340             twRC = TWRC_NOTDSEVENT;
341         }
342         pSource->twCC = TWCC_SUCCESS;
343     }
344
345     return twRC;
346 }
347
348 /* DG_CONTROL/DAT_PASSTHRU/MSG_PASSTHRU */
349 TW_UINT16 TWAIN_PassThrough (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
350                              TW_MEMREF pData)
351 {
352     FIXME ("stub!\n");
353
354     return TWRC_FAILURE;
355 }
356
357 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER */
358 TW_UINT16 TWAIN_PendingXfersEndXfer (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
359                                      TW_MEMREF pData)
360 {
361     TW_UINT16 twRC = TWRC_SUCCESS;
362     pTW_PENDINGXFERS pPendingXfers = (pTW_PENDINGXFERS) pData;
363     activeDS *pSource = TWAIN_LookupSource (pDest);
364
365     TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER\n");
366
367     if (!pSource)
368     {
369         twRC = TWRC_FAILURE;
370         DSM_twCC = TWCC_BADDEST;
371     }
372     else if (pSource->currentState != 6 && pSource->currentState != 7)
373     {
374         twRC = TWRC_FAILURE;
375         pSource->twCC = TWCC_SEQERROR;
376     }
377     else
378     {
379         if (pPendingXfers->Count != 0)
380         {
381             pPendingXfers->Count --;
382             pSource->currentState = 6;
383         }
384         else
385         {
386             pSource->currentState = 5;
387             /* Notify the application that it can close the data source */
388             pSource->pendingEvent.TWMessage = MSG_CLOSEDSREQ;
389         }
390         twRC = TWRC_SUCCESS;
391         pSource->twCC = TWCC_SUCCESS;
392     }
393
394     return twRC;
395 }
396
397 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_GET */
398 TW_UINT16 TWAIN_PendingXfersGet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
399                                  TW_MEMREF pData)
400 {
401     TW_UINT16 twRC = TWRC_SUCCESS;
402     pTW_PENDINGXFERS pPendingXfers = (pTW_PENDINGXFERS) pData;
403     activeDS *pSource = TWAIN_LookupSource (pDest);
404
405     TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_GET\n");
406
407     if (!pSource)
408     {
409         twRC = TWRC_FAILURE;
410         DSM_twCC = TWCC_BADDEST;
411     }
412     else if (pSource->currentState < 4 || pSource->currentState > 7)
413     {
414         twRC = TWRC_FAILURE;
415         DSM_twCC = TWCC_SEQERROR;
416     }
417     else
418     {
419         /* FIXME: we shouldn't return 1 here */
420         pPendingXfers->Count = 1;
421         twRC = TWRC_SUCCESS;
422         pSource->twCC = TWCC_SUCCESS;
423     }
424
425     return twRC;
426 }
427
428 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET */
429 TW_UINT16 TWAIN_PendingXfersReset (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
430                                    TW_MEMREF pData)
431 {
432     TW_UINT16 twRC = TWRC_SUCCESS;
433     pTW_PENDINGXFERS pPendingXfers = (pTW_PENDINGXFERS) pData;
434     activeDS *pSource = TWAIN_LookupSource (pDest);
435
436     TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET\n");
437
438     if (!pSource)
439     {
440         twRC = TWRC_FAILURE;
441         DSM_twCC = TWCC_BADDEST;
442     }
443     else if (pSource->currentState != 6)
444     {
445         twRC = TWRC_FAILURE;
446         DSM_twCC = TWCC_SEQERROR;
447     }
448     else
449     {
450         pPendingXfers->Count = 0;
451         pSource->currentState = 5;
452         twRC = TWRC_SUCCESS;
453         pSource->twCC = TWCC_SUCCESS;
454     }
455
456     return twRC;
457 }
458
459 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_STOPFEEDER */
460 TW_UINT16 TWAIN_PendingXfersStopFeeder (pTW_IDENTITY pOrigin,
461                                         pTW_IDENTITY pDest, TW_MEMREF pData)
462 {
463     FIXME ("stub!\n");
464
465     return TWRC_FAILURE;
466 }
467
468 /* DG_CONTROL/DAT_SETUPFILEXFER/MSG_GET */
469 TW_UINT16 TWAIN_SetupFileXferGet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
470                                   TW_MEMREF pData)
471 {
472     FIXME ("stub!\n");
473
474     return TWRC_FAILURE;
475 }
476
477 /* DG_CONTROL/DAT_SETUPXFER/MSG_GETDEFAULT */
478 TW_UINT16 TWAIN_SetupFileXferGetDefault (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
479                                          TW_MEMREF pData)
480 {
481     FIXME ("stub!\n");
482
483     return TWRC_FAILURE;
484 }
485
486
487 /* DG_CONTROL/DAT_SETUPFILEXFER/MSG_RESET */
488 TW_UINT16 TWAIN_SetupFileXferReset (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
489                                     TW_MEMREF pData)
490 {
491     FIXME ("stub!\n");
492
493     return TWRC_FAILURE;
494 }
495
496 /* DG_CONTROL/DAT_SETUPFILEXFER/MSG_SET */
497 TW_UINT16 TWAIN_SetupFileXferSet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
498                                   TW_MEMREF pData)
499 {
500     FIXME ("stub!\n");
501
502     return TWRC_FAILURE;
503 }
504
505 /* DG_CONTROL/DAT_SETUPFILEXFER2/MSG_GET */
506 TW_UINT16 TWAIN_SetupFileXfer2Get (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
507                                    TW_MEMREF pData)
508 {
509     FIXME ("stub!\n");
510
511     return TWRC_FAILURE;
512 }
513
514 /* DG_CONTROL/DAT_SETUPFILEXFER2/MSG_GETDEFAULT */
515 TW_UINT16 TWAIN_SetupFileXfer2GetDefault (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
516                                          TW_MEMREF pData)
517 {
518     FIXME ("stub!\n");
519
520     return TWRC_FAILURE;
521 }
522
523 /* DG_CONTROL/DAT_SETUPFILEXFER2/MSG_RESET */
524 TW_UINT16 TWAIN_SetupFileXfer2Reset (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
525                                   TW_MEMREF pData)
526 {
527     FIXME ("stub!\n");
528
529     return TWRC_FAILURE;
530 }
531
532 /* DG_CONTROL/DAT_SETUPFILEXFER2/MSG_SET */
533 TW_UINT16 TWAIN_SetupFileXfer2Set (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
534                                   TW_MEMREF pData)
535 {
536     FIXME ("stub!\n");
537
538     return TWRC_FAILURE;
539 }
540
541 /* DG_CONTROL/DAT_SETUPMEMXFER/MSG_GET */
542 TW_UINT16 TWAIN_SetupMemXferGet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
543                                   TW_MEMREF pData)
544 {
545 #ifndef HAVE_SANE
546     return TWRC_FAILURE;
547 #else
548     activeDS *pSource = TWAIN_LookupSource (pDest);
549     pTW_SETUPMEMXFER  pSetupMemXfer = (pTW_SETUPMEMXFER)pData;
550
551     TRACE("DG_CONTROL/DAT_SETUPMEMXFER/MSG_GET\n");
552     if (pSource->sane_param_valid)
553     {
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;
557     }
558     else
559     {
560         /* Guessing */
561         pSetupMemXfer->MinBufSize = 2000;
562         pSetupMemXfer->MaxBufSize = 8000;
563         pSetupMemXfer->Preferred = 4000;
564     }
565
566     return TWRC_SUCCESS;
567 #endif
568 }
569
570 /* DG_CONTROL/DAT_STATUS/MSG_GET */
571 TW_UINT16 TWAIN_GetDSStatus (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
572                              TW_MEMREF pData)
573 {
574     TW_UINT16 twRC = TWRC_FAILURE;
575     pTW_STATUS pSourceStatus = (pTW_STATUS) pData;
576     activeDS *pSource = TWAIN_LookupSource (pDest);
577
578     TRACE ("DG_CONTROL/DAT_STATUS/MSG_GET\n");
579
580     if (!pSource)
581     {
582         twRC = TWRC_FAILURE;
583         DSM_twCC = TWCC_BADDEST;
584         pSourceStatus->ConditionCode = TWCC_BADDEST;
585     }
586     else
587     {
588         twRC = TWRC_SUCCESS;
589         pSourceStatus->ConditionCode = pSource->twCC;
590         /* Reset the condition code */
591         pSource->twCC = TWCC_SUCCESS;
592     }
593
594     return twRC;
595 }
596
597 /* DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS */
598 TW_UINT16 TWAIN_DisableDSUserInterface (pTW_IDENTITY pOrigin,
599                                         pTW_IDENTITY pDest, TW_MEMREF pData)
600 {
601     TW_UINT16 twRC = TWRC_SUCCESS;
602     activeDS *pSource = TWAIN_LookupSource (pDest);
603
604     TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS\n");
605
606     if (!pSource)
607     {
608         twRC = TWRC_FAILURE;
609         DSM_twCC = TWCC_BADDEST;
610     }
611     else if (pSource->currentState != 5)
612     {
613         twRC = TWRC_FAILURE;
614         pSource->twCC = TWCC_SEQERROR;
615     }
616     else
617     {
618         pSource->currentState = 4;
619         twRC = TWRC_SUCCESS;
620         pSource->twCC = TWCC_SUCCESS;
621     }
622
623     return twRC;
624 }
625
626 /* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS */
627 TW_UINT16 TWAIN_EnableDSUserInterface (pTW_IDENTITY pOrigin,
628                                        pTW_IDENTITY pDest, TW_MEMREF pData)
629 {
630     TW_UINT16 twRC = TWRC_SUCCESS;
631     pTW_USERINTERFACE pUserInterface = (pTW_USERINTERFACE) pData;
632     activeDS *pSource = TWAIN_LookupSource (pDest);
633
634     TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS\n");
635
636     if (!pSource)
637     {
638         twRC = TWRC_FAILURE;
639         DSM_twCC = TWCC_BADDEST;
640     }
641     else if (pSource->currentState != 4)
642     {
643         twRC = TWRC_FAILURE;
644         pSource->twCC = TWCC_SEQERROR;
645     }
646     else
647     {
648         if (pUserInterface->ShowUI)
649         {
650             pSource->currentState = 5; /* Transitions to state 5 */
651             /* FIXME: we should replace xscanimage with our own device UI */
652             system ("xscanimage");
653             pSource->currentState = 6;
654             pSource->pendingEvent.TWMessage = MSG_XFERREADY;
655         }
656         else
657         {
658             /* no UI will be displayed, so source is ready to transfer data */
659             pSource->pendingEvent.TWMessage = MSG_XFERREADY;
660             pSource->currentState = 6; /* Transitions to state 6 directly */
661         }
662
663         pSource->hwndOwner = pUserInterface->hParent;
664         twRC = TWRC_SUCCESS;
665         pSource->twCC = TWCC_SUCCESS;
666     }
667
668     return twRC;
669 }
670
671 /* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY */
672 TW_UINT16 TWAIN_EnableDSUIOnly (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
673                                 TW_MEMREF pData)
674 {
675     TW_UINT16 twRC = TWRC_SUCCESS;
676     activeDS *pSource = TWAIN_LookupSource (pDest);
677
678     TRACE("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY\n");
679
680     if (!pSource)
681     {
682         twRC = TWRC_FAILURE;
683         DSM_twCC = TWCC_BADDEST;
684     }
685     else if (pSource->currentState != 4)
686     {
687         twRC = TWRC_FAILURE;
688         pSource->twCC = TWCC_SEQERROR;
689     }
690     else
691     {
692         /* FIXME: we should replace xscanimage with our own UI */
693         system ("xscanimage");
694         pSource->currentState = 5;
695         twRC = TWRC_SUCCESS;
696         pSource->twCC = TWCC_SUCCESS;
697     }
698
699     return twRC;
700 }
701
702 /* DG_CONTROL/DAT_XFERGROUP/MSG_GET */
703 TW_UINT16 TWAIN_XferGroupGet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
704                               TW_MEMREF pData)
705 {
706     FIXME ("stub!\n");
707
708     return TWRC_FAILURE;
709 }
710
711 /* DG_CONTROL/DAT_XFERGROUP/MSG_SET */
712 TW_UINT16 TWAIN_XferGroupSet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
713                                   TW_MEMREF pData)
714 {
715     FIXME ("stub!\n");
716
717     return TWRC_FAILURE;
718 }