user32: Esperanto language update.
[wine/multimedia.git] / dlls / twain / twain32_main.c
blobdf59afc22f6fe05cea26a88c6621600483a7c853
1 /*
2 * TWAIN32 functions
4 * Copyright 2000 Shi Quan He <shiquan@cyberdude.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
23 #include <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "twain.h"
28 #include "twain_i.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(twain);
33 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
35 TRACE("%p,%lx,%p\n", hinstDLL, fdwReason, lpvReserved);
37 switch (fdwReason)
39 case DLL_PROCESS_ATTACH:
40 DisableThreadLibraryCalls(hinstDLL);
41 DSM_currentState = 2;
42 DSM_instance = hinstDLL;
43 break;
45 case DLL_PROCESS_DETACH:
46 DSM_currentState = 1;
47 break;
50 return TRUE;
53 TW_UINT16 TWAIN_SourceManagerHandler (
54 pTW_IDENTITY pOrigin,
55 TW_UINT16 DAT,
56 TW_UINT16 MSG,
57 TW_MEMREF pData)
59 TW_UINT16 twRC = TWRC_SUCCESS;
61 switch (DAT)
63 case DAT_IDENTITY:
64 switch (MSG)
66 case MSG_CLOSEDS:
67 twRC = TWAIN_CloseDS (pOrigin, pData);
68 break;
70 case MSG_GETDEFAULT:
71 twRC = TWAIN_IdentityGetDefault (pOrigin, pData);
72 break;
74 case MSG_GETFIRST:
75 twRC = TWAIN_IdentityGetFirst (pOrigin, pData);
76 break;
78 case MSG_GETNEXT:
79 twRC = TWAIN_IdentityGetNext (pOrigin, pData);
80 break;
82 case MSG_OPENDS:
83 twRC = TWAIN_OpenDS (pOrigin, pData);
84 break;
86 case MSG_USERSELECT:
87 twRC = TWAIN_UserSelect (pOrigin, pData);
88 break;
90 default:
91 /* Unrecognized operation triplet */
92 twRC = TWRC_FAILURE;
93 DSM_twCC = TWCC_BADPROTOCOL;
94 WARN("unrecognized operation triplet\n");
95 break;
97 break;
99 case DAT_PARENT:
100 switch (MSG)
102 case MSG_CLOSEDSM:
103 twRC = TWAIN_CloseDSM (pOrigin, pData);
104 break;
106 case MSG_OPENDSM:
107 twRC = TWAIN_OpenDSM (pOrigin, pData);
108 break;
110 default:
111 /* Unrecognized operation triplet */
112 twRC = TWRC_FAILURE;
113 DSM_twCC = TWCC_BADPROTOCOL;
114 WARN("unrecognized operation triplet\n");
116 break;
118 case DAT_STATUS:
119 if (MSG == MSG_GET)
121 twRC = TWAIN_GetDSMStatus (pOrigin, pData);
123 else
125 twRC = TWRC_FAILURE;
126 DSM_twCC = TWCC_BADPROTOCOL;
127 WARN("unrecognized operation triplet\n");
129 break;
131 default:
132 twRC = TWRC_FAILURE;
133 DSM_twCC = TWCC_BADPROTOCOL;
134 WARN("unrecognized operation triplet\n");
135 break;
138 return twRC;
141 TW_UINT16 TWAIN_SourceControlHandler (
142 pTW_IDENTITY pOrigin,
143 pTW_IDENTITY pDest,
144 TW_UINT16 DAT,
145 TW_UINT16 MSG,
146 TW_MEMREF pData)
148 TW_UINT16 twRC = TWRC_SUCCESS;
150 switch (DAT)
152 case DAT_CAPABILITY:
153 switch (MSG)
155 case MSG_GET:
156 twRC = TWAIN_CapabilityGet (pOrigin, pDest, pData);
157 break;
158 case MSG_GETCURRENT:
159 twRC = TWAIN_CapabilityGetCurrent (pOrigin, pDest, pData);
160 break;
161 case MSG_GETDEFAULT:
162 twRC = TWAIN_CapabilityGetDefault (pOrigin, pDest, pData);
163 break;
164 case MSG_QUERYSUPPORT:
165 twRC = TWAIN_CapabilityQuerySupport (pOrigin, pDest, pData);
166 break;
167 case MSG_RESET:
168 twRC = TWAIN_CapabilityReset (pOrigin, pDest, pData);
169 break;
170 case MSG_SET:
171 twRC = TWAIN_CapabilitySet (pOrigin, pDest, pData);
172 break;
173 default:
174 twRC = TWRC_FAILURE;
175 WARN("unrecognized opertion triplet\n");
177 break;
179 case DAT_CUSTOMDSDATA:
180 switch (MSG)
182 case MSG_GET:
183 twRC = TWAIN_CustomDSDataGet (pOrigin, pDest, pData);
184 break;
185 case MSG_SET:
186 twRC = TWAIN_CustomDSDataSet (pOrigin, pDest, pData);
187 break;
188 default:
189 break;
191 break;
193 case DAT_FILESYSTEM:
194 switch (MSG)
196 /*case MSG_AUTOMATICCAPTUREDIRECTORY:
197 twRC = TWAIN_AutomaticCaptureDirectory
198 (pOrigin, pDest, pData);
199 break;*/
200 case MSG_CHANGEDIRECTORY:
201 twRC = TWAIN_ChangeDirectory (pOrigin, pDest, pData);
202 break;
203 /*case MSG_COPY:
204 twRC = TWAIN_FileSystemCopy (pOrigin, pDest, pData);
205 break;*/
206 case MSG_CREATEDIRECTORY:
207 twRC = TWAIN_CreateDirectory (pOrigin, pDest, pData);
208 break;
209 case MSG_DELETE:
210 twRC = TWAIN_FileSystemDelete (pOrigin, pDest, pData);
211 break;
212 case MSG_FORMATMEDIA:
213 twRC = TWAIN_FormatMedia (pOrigin, pDest, pData);
214 break;
215 case MSG_GETCLOSE:
216 twRC = TWAIN_FileSystemGetClose (pOrigin, pDest, pData);
217 break;
218 case MSG_GETFIRSTFILE:
219 twRC = TWAIN_FileSystemGetFirstFile
220 (pOrigin, pDest, pData);
221 break;
222 case MSG_GETINFO:
223 twRC = TWAIN_FileSystemGetInfo (pOrigin, pDest, pData);
224 break;
225 case MSG_GETNEXTFILE:
226 twRC = TWAIN_FileSystemGetNextFile
227 (pOrigin, pDest, pData);
228 break;
229 case MSG_RENAME:
230 twRC = TWAIN_FileSystemRename (pOrigin, pDest, pData);
231 break;
232 default:
233 twRC = TWRC_FAILURE;
234 break;
236 break;
238 case DAT_EVENT:
239 if (MSG == MSG_PROCESSEVENT)
240 twRC = TWAIN_ProcessEvent (pOrigin, pDest, pData);
241 else
242 twRC = TWRC_FAILURE;
243 break;
245 case DAT_PASSTHRU:
246 if (MSG == MSG_PASSTHRU)
247 twRC = TWAIN_PassThrough (pOrigin, pDest, pData);
248 else
249 twRC = TWRC_FAILURE;
250 break;
252 case DAT_PENDINGXFERS:
253 switch (MSG)
255 case MSG_ENDXFER:
256 twRC = TWAIN_PendingXfersEndXfer (pOrigin, pDest, pData);
257 break;
258 case MSG_GET:
259 twRC = TWAIN_PendingXfersGet (pOrigin, pDest, pData);
260 break;
261 case MSG_RESET:
262 twRC = TWAIN_PendingXfersReset (pOrigin, pDest, pData);
263 break;
264 /*case MSG_STOPFEEDER:
265 twRC = TWAIN_PendingXfersStopFeeder
266 (pOrigin, pDest, pData);
267 break;*/
268 default:
269 twRC = TWRC_FAILURE;
271 break;
273 case DAT_SETUPFILEXFER:
274 switch (MSG)
276 case MSG_GET:
277 twRC = TWAIN_SetupFileXferGet (pOrigin, pDest, pData);
278 break;
279 case MSG_GETDEFAULT:
280 twRC = TWAIN_SetupFileXferGetDefault
281 (pOrigin, pDest, pData);
282 break;
283 case MSG_RESET:
284 twRC = TWAIN_SetupFileXferReset (pOrigin, pDest, pData);
285 break;
286 case MSG_SET:
287 twRC = TWAIN_SetupFileXferSet (pOrigin, pDest, pData);
288 break;
289 default:
290 twRC = TWRC_FAILURE;
291 break;
293 break;
295 /*case DAT_SETUPFILEXFER2:
296 switch (MSG)
298 case MSG_GET:
299 twRC = TWAIN_SetupFileXfer2Get (pOrigin, pDest, pData);
300 break;
301 case MSG_GETDEFAULT:
302 twRC = TWAIN_SetupFileXfer2GetDefault
303 (pOrigin, pDest, pData);
304 break;
305 case MSG_RESET:
306 twRC = TWAIN_SetupFileXfer2Reset (pOrigin, pDest, pData);
307 break;
308 case MSG_SET:
309 twRC = TWAIN_SetupFileXfer2Set (pOrigin, pDest, pData);
310 break;
312 break;*/
313 case DAT_SETUPMEMXFER:
314 if (MSG == MSG_GET)
315 twRC = TWAIN_SetupMemXferGet (pOrigin, pDest, pData);
316 else
317 twRC = TWRC_FAILURE;
318 break;
320 case DAT_STATUS:
321 if (MSG == MSG_GET)
322 twRC = TWAIN_GetDSStatus (pOrigin, pDest, pData);
323 else
324 twRC = TWRC_FAILURE;
325 break;
327 case DAT_USERINTERFACE:
328 switch (MSG)
330 case MSG_DISABLEDS:
331 twRC = TWAIN_DisableDSUserInterface
332 (pOrigin, pDest, pData);
333 break;
334 case MSG_ENABLEDS:
335 twRC = TWAIN_EnableDSUserInterface
336 (pOrigin, pDest, pData);
337 break;
338 case MSG_ENABLEDSUIONLY:
339 twRC = TWAIN_EnableDSUIOnly (pOrigin, pDest, pData);
340 break;
341 default:
342 twRC = TWRC_FAILURE;
343 break;
345 break;
347 case DAT_XFERGROUP:
348 switch (MSG)
350 case MSG_GET:
351 twRC = TWAIN_XferGroupGet (pOrigin, pDest, pData);
352 break;
353 case MSG_SET:
354 twRC = TWAIN_XferGroupSet (pOrigin, pDest, pData);
355 break;
356 default:
357 twRC = TWRC_FAILURE;
358 break;
360 break;
362 default:
363 twRC = TWRC_FAILURE;
364 break;
367 return twRC;
370 TW_UINT16 TWAIN_ControlGroupHandler (
371 pTW_IDENTITY pOrigin,
372 pTW_IDENTITY pDest,
373 TW_UINT16 DAT,
374 TW_UINT16 MSG,
375 TW_MEMREF pData)
377 TW_UINT16 twRC = TWRC_SUCCESS;
379 if (pDest)
381 /* This operation's destination is a source */
382 twRC = TWAIN_SourceControlHandler (pOrigin, pDest, DAT, MSG, pData);
384 else
386 /* This operation's destination is the Source Manager */
387 twRC = TWAIN_SourceManagerHandler (pOrigin, DAT, MSG, pData);
390 return twRC;
393 TW_UINT16 TWAIN_ImageGroupHandler (
394 pTW_IDENTITY pOrigin,
395 pTW_IDENTITY pDest,
396 TW_UINT16 DAT,
397 TW_UINT16 MSG,
398 TW_MEMREF pData)
400 TW_UINT16 twRC = TWRC_SUCCESS;
402 if (pDest == NULL)
404 DSM_twCC = TWCC_BADDEST;
405 return TWRC_FAILURE;
408 switch (DAT)
410 case DAT_CIECOLOR:
411 if (MSG == MSG_GET)
412 twRC = TWAIN_CIEColorGet (pOrigin, pDest, pData);
413 else
414 twRC = TWRC_FAILURE;
415 break;
417 case DAT_EXTIMAGEINFO:
418 if (MSG == MSG_GET)
419 twRC = TWAIN_ExtImageInfoGet (pOrigin, pDest, pData);
420 else
421 twRC = TWRC_FAILURE;
422 break;
424 case DAT_GRAYRESPONSE:
425 switch (MSG)
427 case MSG_RESET:
428 twRC = TWAIN_GrayResponseReset (pOrigin, pDest, pData);
429 break;
430 case MSG_SET:
431 twRC = TWAIN_GrayResponseSet (pOrigin, pDest, pData);
432 break;
433 default:
434 twRC = TWRC_FAILURE;
435 DSM_twCC = TWCC_BADPROTOCOL;
436 WARN("unrecognized operation triplet\n");
437 break;
439 break;
440 case DAT_IMAGEFILEXFER:
441 if (MSG == MSG_GET)
442 twRC = TWAIN_ImageFileXferGet (pOrigin, pDest, pData);
443 else
444 twRC = TWRC_FAILURE;
445 break;
447 case DAT_IMAGEINFO:
448 if (MSG == MSG_GET)
449 twRC = TWAIN_ImageInfoGet (pOrigin, pDest, pData);
450 else
451 twRC = TWRC_FAILURE;
452 break;
454 case DAT_IMAGELAYOUT:
455 switch (MSG)
457 case MSG_GET:
458 twRC = TWAIN_ImageLayoutGet (pOrigin, pDest, pData);
459 break;
460 case MSG_GETDEFAULT:
461 twRC = TWAIN_ImageLayoutGetDefault (pOrigin, pDest, pData);
462 break;
463 case MSG_RESET:
464 twRC = TWAIN_ImageLayoutReset (pOrigin, pDest, pData);
465 break;
466 case MSG_SET:
467 twRC = TWAIN_ImageLayoutSet (pOrigin, pDest, pData);
468 break;
469 default:
470 twRC = TWRC_FAILURE;
471 DSM_twCC = TWCC_BADPROTOCOL;
472 WARN("unrecognized operation triplet\n");
473 break;
475 break;
477 case DAT_IMAGEMEMXFER:
478 if (MSG == MSG_GET)
479 twRC = TWAIN_ImageMemXferGet (pOrigin, pDest, pData);
480 else
481 twRC = TWRC_FAILURE;
482 break;
484 case DAT_IMAGENATIVEXFER:
485 if (MSG == MSG_GET)
486 twRC = TWAIN_ImageNativeXferGet (pOrigin, pDest, pData);
487 else
488 twRC = TWRC_FAILURE;
489 break;
491 case DAT_JPEGCOMPRESSION:
492 switch (MSG)
494 case MSG_GET:
495 twRC = TWAIN_JPEGCompressionGet (pOrigin, pDest, pData);
496 break;
497 case MSG_GETDEFAULT:
498 twRC = TWAIN_JPEGCompressionGetDefault
499 (pOrigin, pDest, pData);
500 break;
501 case MSG_RESET:
502 twRC = TWAIN_JPEGCompressionReset (pOrigin, pDest, pData);
503 break;
504 case MSG_SET:
505 twRC = TWAIN_JPEGCompressionSet (pOrigin, pDest, pData);
506 break;
507 default:
508 twRC = TWRC_FAILURE;
509 DSM_twCC = TWCC_BADPROTOCOL;
510 WARN("unrecognized operation triplet\n");
511 break;
513 break;
515 case DAT_PALETTE8:
516 switch (MSG)
518 case MSG_GET:
519 twRC = TWAIN_Palette8Get (pOrigin, pDest, pData);
520 break;
521 case MSG_GETDEFAULT:
522 twRC = TWAIN_Palette8GetDefault (pOrigin, pDest, pData);
523 break;
524 case MSG_RESET:
525 twRC = TWAIN_Palette8Reset (pOrigin, pDest, pData);
526 break;
527 case MSG_SET:
528 twRC = TWAIN_Palette8Set (pOrigin, pDest, pData);
529 break;
530 default:
531 twRC = TWRC_FAILURE;
532 DSM_twCC = TWCC_BADPROTOCOL;
533 WARN("unrecognized operation triplet\n");
535 break;
537 case DAT_RGBRESPONSE:
538 switch (MSG)
540 case MSG_RESET:
541 twRC = TWAIN_RGBResponseReset (pOrigin, pDest, pData);
542 break;
543 case MSG_SET:
544 twRC = TWAIN_RGBResponseSet (pOrigin, pDest, pData);
545 break;
546 default:
547 twRC = TWRC_FAILURE;
548 DSM_twCC = TWCC_BADPROTOCOL;
549 WARN("unrecognized operation triplet\n");
550 break;
552 break;
554 default:
555 twRC = TWRC_FAILURE;
556 DSM_twCC = TWCC_BADPROTOCOL;
557 WARN("unrecognized operation triplet\n");
559 return twRC;
562 TW_UINT16 TWAIN_AudioGroupHandler (
563 pTW_IDENTITY pOrigin,
564 pTW_IDENTITY pDest,
565 TW_UINT16 DAT,
566 TW_UINT16 MSG,
567 TW_MEMREF pData)
569 TW_UINT16 twRC = TWRC_FAILURE;
571 switch (DAT)
573 case DAT_AUDIOFILEXFER:
574 if (MSG == MSG_GET)
575 twRC = TWAIN_AudioFileXferGet (pOrigin, pDest, pData);
576 break;
578 case DAT_AUDIOINFO:
579 if (MSG == MSG_GET)
580 twRC = TWAIN_AudioInfoGet (pOrigin, pDest, pData);
581 break;
583 case DAT_AUDIONATIVEXFER:
584 if (MSG == MSG_GET)
585 twRC = TWAIN_AudioNativeXferGet (pOrigin, pDest, pData);
586 break;
588 default:
589 DSM_twCC = TWCC_BADPROTOCOL;
590 twRC = TWRC_FAILURE;
591 break;
594 return twRC;
597 /* Main entry point for the TWAIN library */
598 TW_UINT16 WINAPI
599 DSM_Entry (pTW_IDENTITY pOrigin,
600 pTW_IDENTITY pDest,
601 TW_UINT32 DG,
602 TW_UINT16 DAT,
603 TW_UINT16 MSG,
604 TW_MEMREF pData)
606 TW_UINT16 twRC = TWRC_SUCCESS; /* Return Code */
608 TRACE("(DG=%ld DAT=%d MSG=%d)\n", DG, DAT, MSG);
610 switch (DG)
612 case DG_CONTROL:
613 twRC = TWAIN_ControlGroupHandler (pOrigin,pDest,DAT,MSG,pData);
614 break;
615 case DG_IMAGE:
616 twRC = TWAIN_ImageGroupHandler (pOrigin,pDest,DAT,MSG,pData);
617 break;
618 case DG_AUDIO:
619 twRC = TWAIN_AudioGroupHandler (pOrigin,pDest,DAT,MSG,pData);
620 break;
621 default:
622 DSM_twCC = TWCC_BADPROTOCOL;
623 twRC = TWRC_FAILURE;
626 return twRC;
629 /* A helper function that looks up a destination identity in the active
630 source list */
631 activeDS *TWAIN_LookupSource (pTW_IDENTITY pDest)
633 activeDS *pSource;
635 for (pSource = activeSources; pSource; pSource = pSource->next)
636 if (pSource->identity.Id == pDest->Id)
637 break;
639 return pSource;