winecfg: Update Korean resource.
[wine/hramrach.git] / dlls / sane.ds / ds_ctrl.c
blob9901fffe4e8cea25efb97878111bc7ebaa7d85c4
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 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)
111 twRC = TWRC_FAILURE;
112 activeDS.twCC = TWCC_SEQERROR;
114 else
116 twCC = SANE_SaneCapability (pCapability, MSG_QUERYSUPPORT);
117 twRC = (twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
118 activeDS.twCC = twCC;
121 return twRC;
124 /* DG_CONTROL/DAT_CAPABILITY/MSG_RESET */
125 TW_UINT16 SANE_CapabilityReset (pTW_IDENTITY pOrigin,
126 TW_MEMREF pData)
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)
135 twRC = TWRC_FAILURE;
136 activeDS.twCC = TWCC_SEQERROR;
138 else
140 twCC = SANE_SaneCapability (pCapability, MSG_RESET);
141 twRC = (twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
142 activeDS.twCC = twCC;
145 return twRC;
148 /* DG_CONTROL/DAT_CAPABILITY/MSG_SET */
149 TW_UINT16 SANE_CapabilitySet (pTW_IDENTITY pOrigin,
150 TW_MEMREF pData)
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)
159 twRC = TWRC_FAILURE;
160 activeDS.twCC = TWCC_SEQERROR;
162 else
164 twCC = SANE_SaneCapability (pCapability, MSG_SET);
165 if (twCC == TWCC_CHECKSTATUS)
167 twCC = TWCC_SUCCESS;
168 twRC = TWRC_CHECKSTATUS;
170 else
171 twRC = (twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
172 activeDS.twCC = twCC;
174 return twRC;
177 /* DG_CONTROL/DAT_EVENT/MSG_PROCESSEVENT */
178 TW_UINT16 SANE_ProcessEvent (pTW_IDENTITY pOrigin,
179 TW_MEMREF pData)
181 TW_UINT16 twRC = TWRC_NOTDSEVENT;
182 pTW_EVENT pEvent = (pTW_EVENT) pData;
183 MSG *pMsg = pEvent->pEvent;
185 TRACE("DG_CONTROL/DAT_EVENT/MSG_PROCESSEVENT msg 0x%x, wParam 0x%lx\n", pMsg->message, pMsg->wParam);
187 activeDS.twCC = TWCC_SUCCESS;
188 if (pMsg->message == activeDS.windowMessage && activeDS.windowMessage)
190 twRC = TWRC_DSEVENT;
191 pEvent->TWMessage = pMsg->wParam;
193 else
194 pEvent->TWMessage = MSG_NULL; /* no message to the application */
196 if (activeDS.currentState < 5 || activeDS.currentState > 7)
198 twRC = TWRC_FAILURE;
199 activeDS.twCC = TWCC_SEQERROR;
202 return twRC;
205 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER */
206 TW_UINT16 SANE_PendingXfersEndXfer (pTW_IDENTITY pOrigin,
207 TW_MEMREF pData)
209 #ifndef SONAME_LIBSANE
210 return TWRC_FAILURE;
211 #else
212 TW_UINT16 twRC = TWRC_SUCCESS;
213 pTW_PENDINGXFERS pPendingXfers = (pTW_PENDINGXFERS) pData;
214 SANE_Status status;
216 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER\n");
218 if (activeDS.currentState != 6 && activeDS.currentState != 7)
220 twRC = TWRC_FAILURE;
221 activeDS.twCC = TWCC_SEQERROR;
223 else
225 pPendingXfers->Count = -1;
226 activeDS.currentState = 6;
227 if (! activeDS.sane_started)
229 status = psane_start (activeDS.deviceHandle);
230 if (status != SANE_STATUS_GOOD)
232 TRACE("PENDINGXFERS/MSG_ENDXFER sane_start returns %s\n", psane_strstatus(status));
233 pPendingXfers->Count = 0;
234 activeDS.currentState = 5;
235 /* Notify the application that it can close the data source */
236 if (activeDS.windowMessage)
237 PostMessageA(activeDS.hwndOwner, activeDS.windowMessage, MSG_CLOSEDSREQ, 0);
239 else
240 activeDS.sane_started = TRUE;
242 twRC = TWRC_SUCCESS;
243 activeDS.twCC = TWCC_SUCCESS;
246 return twRC;
247 #endif
250 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_GET */
251 TW_UINT16 SANE_PendingXfersGet (pTW_IDENTITY pOrigin,
252 TW_MEMREF pData)
254 #ifndef SONAME_LIBSANE
255 return TWRC_FAILURE;
256 #else
257 TW_UINT16 twRC = TWRC_SUCCESS;
258 pTW_PENDINGXFERS pPendingXfers = (pTW_PENDINGXFERS) pData;
259 SANE_Status status;
261 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_GET\n");
263 if (activeDS.currentState < 4 || activeDS.currentState > 7)
265 twRC = TWRC_FAILURE;
266 activeDS.twCC = TWCC_SEQERROR;
268 else
270 pPendingXfers->Count = -1;
271 if (! activeDS.sane_started)
273 status = psane_start (activeDS.deviceHandle);
274 if (status != SANE_STATUS_GOOD)
276 TRACE("PENDINGXFERS/MSG_GET sane_start returns %s\n", psane_strstatus(status));
277 pPendingXfers->Count = 0;
279 else
280 activeDS.sane_started = TRUE;
282 twRC = TWRC_SUCCESS;
283 activeDS.twCC = TWCC_SUCCESS;
286 return twRC;
287 #endif
290 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET */
291 TW_UINT16 SANE_PendingXfersReset (pTW_IDENTITY pOrigin,
292 TW_MEMREF pData)
294 #ifndef SONAME_LIBSANE
295 return TWRC_FAILURE;
296 #else
297 TW_UINT16 twRC = TWRC_SUCCESS;
298 pTW_PENDINGXFERS pPendingXfers = (pTW_PENDINGXFERS) pData;
300 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET\n");
302 if (activeDS.currentState != 6)
304 twRC = TWRC_FAILURE;
305 activeDS.twCC = TWCC_SEQERROR;
307 else
309 pPendingXfers->Count = 0;
310 activeDS.currentState = 5;
311 twRC = TWRC_SUCCESS;
312 activeDS.twCC = TWCC_SUCCESS;
314 if (activeDS.sane_started)
316 psane_cancel (activeDS.deviceHandle);
317 activeDS.sane_started = FALSE;
321 return twRC;
322 #endif
325 /* DG_CONTROL/DAT_SETUPMEMXFER/MSG_GET */
326 TW_UINT16 SANE_SetupMemXferGet (pTW_IDENTITY pOrigin,
327 TW_MEMREF pData)
329 #ifndef SONAME_LIBSANE
330 return TWRC_FAILURE;
331 #else
332 pTW_SETUPMEMXFER pSetupMemXfer = (pTW_SETUPMEMXFER)pData;
334 TRACE("DG_CONTROL/DAT_SETUPMEMXFER/MSG_GET\n");
335 if (activeDS.sane_param_valid)
337 pSetupMemXfer->MinBufSize = activeDS.sane_param.bytes_per_line;
338 pSetupMemXfer->MaxBufSize = activeDS.sane_param.bytes_per_line * 8;
339 pSetupMemXfer->Preferred = activeDS.sane_param.bytes_per_line * 2;
341 else
343 /* Guessing */
344 pSetupMemXfer->MinBufSize = 2000;
345 pSetupMemXfer->MaxBufSize = 8000;
346 pSetupMemXfer->Preferred = 4000;
349 return TWRC_SUCCESS;
350 #endif
353 /* DG_CONTROL/DAT_STATUS/MSG_GET */
354 TW_UINT16 SANE_GetDSStatus (pTW_IDENTITY pOrigin,
355 TW_MEMREF pData)
357 pTW_STATUS pSourceStatus = (pTW_STATUS) pData;
359 TRACE ("DG_CONTROL/DAT_STATUS/MSG_GET\n");
360 pSourceStatus->ConditionCode = activeDS.twCC;
361 /* Reset the condition code */
362 activeDS.twCC = TWCC_SUCCESS;
363 return TWRC_SUCCESS;
366 /* DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS */
367 TW_UINT16 SANE_DisableDSUserInterface (pTW_IDENTITY pOrigin,
368 TW_MEMREF pData)
370 TW_UINT16 twRC = TWRC_SUCCESS;
372 TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS\n");
374 if (activeDS.currentState != 5)
376 twRC = TWRC_FAILURE;
377 activeDS.twCC = TWCC_SEQERROR;
379 else
381 activeDS.currentState = 4;
382 twRC = TWRC_SUCCESS;
383 activeDS.twCC = TWCC_SUCCESS;
386 return twRC;
389 /* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS */
390 TW_UINT16 SANE_EnableDSUserInterface (pTW_IDENTITY pOrigin,
391 TW_MEMREF pData)
393 TW_UINT16 twRC = TWRC_SUCCESS;
394 pTW_USERINTERFACE pUserInterface = (pTW_USERINTERFACE) pData;
396 TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS\n");
398 if (activeDS.currentState != 4)
400 twRC = TWRC_FAILURE;
401 activeDS.twCC = TWCC_SEQERROR;
402 WARN("sequence error %d\n", activeDS.currentState);
404 else
406 activeDS.hwndOwner = pUserInterface->hParent;
407 if (! activeDS.windowMessage)
408 activeDS.windowMessage = RegisterWindowMessageA("SANE.DS ACTIVITY MESSAGE");
409 if (pUserInterface->ShowUI)
411 BOOL rc;
412 activeDS.currentState = 5; /* Transitions to state 5 */
413 rc = DoScannerUI();
414 pUserInterface->ModalUI = TRUE;
415 if (!rc)
417 if (activeDS.windowMessage)
418 PostMessageA(activeDS.hwndOwner, activeDS.windowMessage, MSG_CLOSEDSREQ, 0);
420 #ifdef SONAME_LIBSANE
421 else
423 psane_get_parameters (activeDS.deviceHandle, &activeDS.sane_param);
424 activeDS.sane_param_valid = TRUE;
426 #endif
428 else
430 /* no UI will be displayed, so source is ready to transfer data */
431 activeDS.currentState = 6; /* Transitions to state 6 directly */
432 if (activeDS.windowMessage)
433 PostMessageA(activeDS.hwndOwner, activeDS.windowMessage, MSG_XFERREADY, 0);
436 twRC = TWRC_SUCCESS;
437 activeDS.twCC = TWCC_SUCCESS;
440 return twRC;
443 /* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY */
444 TW_UINT16 SANE_EnableDSUIOnly (pTW_IDENTITY pOrigin,
445 TW_MEMREF pData)
447 TW_UINT16 twRC = TWRC_SUCCESS;
449 TRACE("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY\n");
451 if (activeDS.currentState != 4)
453 twRC = TWRC_FAILURE;
454 activeDS.twCC = TWCC_SEQERROR;
456 else
458 /* FIXME: we should replace xscanimage with our own UI */
459 system ("xscanimage");
460 activeDS.currentState = 5;
461 twRC = TWRC_SUCCESS;
462 activeDS.twCC = TWCC_SUCCESS;
465 return twRC;
468 /* DG_CONTROL/DAT_XFERGROUP/MSG_GET */
469 TW_UINT16 SANE_XferGroupGet (pTW_IDENTITY pOrigin,
470 TW_MEMREF pData)
472 FIXME ("stub!\n");
474 return TWRC_FAILURE;
477 /* DG_CONTROL/DAT_XFERGROUP/MSG_SET */
478 TW_UINT16 SANE_XferGroupSet (pTW_IDENTITY pOrigin,
479 TW_MEMREF pData)
481 FIXME ("stub!\n");
483 return TWRC_FAILURE;