qdvd: Add IDvdGraphBuilder stub.
[wine/zf.git] / dlls / sane.ds / ds_ctrl.c
blobb7d283725c847191e6fbc83dc1d1d8bd760e6af2
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 "sane_i.h"
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(twain);
30 /* DG_CONTROL/DAT_CAPABILITY/MSG_GET */
31 TW_UINT16 SANE_CapabilityGet (pTW_IDENTITY pOrigin, TW_MEMREF pData)
33 TW_UINT16 twRC = TWRC_SUCCESS, twCC = TWCC_SUCCESS;
34 pTW_CAPABILITY pCapability = (pTW_CAPABILITY) pData;
36 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_GET\n");
38 if (activeDS.currentState < 4 || activeDS.currentState > 7)
40 twRC = TWRC_FAILURE;
41 activeDS.twCC = TWCC_SEQERROR;
43 else
45 twCC = SANE_SaneCapability (pCapability, MSG_GET);
46 twRC = (twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
47 activeDS.twCC = twCC;
50 return twRC;
53 /* DG_CONTROL/DAT_CAPABILITY/MSG_GETCURRENT */
54 TW_UINT16 SANE_CapabilityGetCurrent (pTW_IDENTITY pOrigin, TW_MEMREF pData)
56 TW_UINT16 twRC = TWRC_SUCCESS, twCC = TWCC_SUCCESS;
57 pTW_CAPABILITY pCapability = (pTW_CAPABILITY) pData;
59 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_GETCURRENT\n");
61 if (activeDS.currentState < 4 || activeDS.currentState > 7)
63 twRC = TWRC_FAILURE;
64 activeDS.twCC = TWCC_SEQERROR;
66 else
68 twCC = SANE_SaneCapability (pCapability, MSG_GETCURRENT);
69 twRC = (twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
70 activeDS.twCC = twCC;
73 return twRC;
76 /* DG_CONTROL/DAT_CAPABILITY/MSG_GETDEFAULT */
77 TW_UINT16 SANE_CapabilityGetDefault (pTW_IDENTITY pOrigin, TW_MEMREF pData)
79 TW_UINT16 twRC = TWRC_SUCCESS, twCC = TWCC_SUCCESS;
80 pTW_CAPABILITY pCapability = (pTW_CAPABILITY) pData;
82 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_GETDEFAULT\n");
84 if (activeDS.currentState < 4 || activeDS.currentState > 7)
86 twRC = TWRC_FAILURE;
87 activeDS.twCC = TWCC_SEQERROR;
89 else
91 twCC = SANE_SaneCapability (pCapability, MSG_GETDEFAULT);
92 twRC = (twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
93 activeDS.twCC = twCC;
96 return twRC;
99 /* DG_CONTROL/DAT_CAPABILITY/MSG_QUERYSUPPORT */
100 TW_UINT16 SANE_CapabilityQuerySupport (pTW_IDENTITY pOrigin,
101 TW_MEMREF pData)
103 TW_UINT16 twRC = TWRC_SUCCESS, twCC = TWCC_SUCCESS;
104 pTW_CAPABILITY pCapability = (pTW_CAPABILITY) pData;
106 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_QUERYSUPPORT\n");
108 if (activeDS.currentState < 4 || activeDS.currentState > 7)
110 twRC = TWRC_FAILURE;
111 activeDS.twCC = TWCC_SEQERROR;
113 else
115 twCC = SANE_SaneCapability (pCapability, MSG_QUERYSUPPORT);
116 twRC = (twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
117 activeDS.twCC = twCC;
120 return twRC;
123 /* DG_CONTROL/DAT_CAPABILITY/MSG_RESET */
124 TW_UINT16 SANE_CapabilityReset (pTW_IDENTITY pOrigin,
125 TW_MEMREF pData)
127 TW_UINT16 twRC = TWRC_SUCCESS, twCC = TWCC_SUCCESS;
128 pTW_CAPABILITY pCapability = (pTW_CAPABILITY) pData;
130 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_RESET\n");
132 if (activeDS.currentState < 4 || activeDS.currentState > 7)
134 twRC = TWRC_FAILURE;
135 activeDS.twCC = TWCC_SEQERROR;
137 else
139 twCC = SANE_SaneCapability (pCapability, MSG_RESET);
140 twRC = (twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
141 activeDS.twCC = twCC;
144 return twRC;
147 /* DG_CONTROL/DAT_CAPABILITY/MSG_SET */
148 TW_UINT16 SANE_CapabilitySet (pTW_IDENTITY pOrigin,
149 TW_MEMREF pData)
151 TW_UINT16 twRC = TWRC_SUCCESS, twCC = TWCC_SUCCESS;
152 pTW_CAPABILITY pCapability = (pTW_CAPABILITY) pData;
154 TRACE ("DG_CONTROL/DAT_CAPABILITY/MSG_SET\n");
156 if (activeDS.currentState != 4)
158 twRC = TWRC_FAILURE;
159 activeDS.twCC = TWCC_SEQERROR;
161 else
163 twCC = SANE_SaneCapability (pCapability, MSG_SET);
164 if (twCC == TWCC_CHECKSTATUS)
166 twCC = TWCC_SUCCESS;
167 twRC = TWRC_CHECKSTATUS;
169 else
170 twRC = (twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
171 activeDS.twCC = twCC;
173 return twRC;
176 /* DG_CONTROL/DAT_EVENT/MSG_PROCESSEVENT */
177 TW_UINT16 SANE_ProcessEvent (pTW_IDENTITY pOrigin,
178 TW_MEMREF pData)
180 TW_UINT16 twRC = TWRC_NOTDSEVENT;
181 pTW_EVENT pEvent = (pTW_EVENT) pData;
182 MSG *pMsg = pEvent->pEvent;
184 TRACE("DG_CONTROL/DAT_EVENT/MSG_PROCESSEVENT msg 0x%x, wParam 0x%lx\n", pMsg->message, pMsg->wParam);
186 activeDS.twCC = TWCC_SUCCESS;
187 pEvent->TWMessage = MSG_NULL; /* no message to the application */
189 if (activeDS.currentState < 5 || activeDS.currentState > 7)
191 twRC = TWRC_FAILURE;
192 activeDS.twCC = TWCC_SEQERROR;
195 return twRC;
198 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER */
199 TW_UINT16 SANE_PendingXfersEndXfer (pTW_IDENTITY pOrigin,
200 TW_MEMREF pData)
202 #ifndef SONAME_LIBSANE
203 return TWRC_FAILURE;
204 #else
205 TW_UINT16 twRC = TWRC_SUCCESS;
206 pTW_PENDINGXFERS pPendingXfers = (pTW_PENDINGXFERS) pData;
207 SANE_Status status;
209 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER\n");
211 if (activeDS.currentState != 6 && activeDS.currentState != 7)
213 twRC = TWRC_FAILURE;
214 activeDS.twCC = TWCC_SEQERROR;
216 else
218 pPendingXfers->Count = -1;
219 activeDS.currentState = 6;
220 if (! activeDS.sane_started)
222 status = psane_start (activeDS.deviceHandle);
223 if (status != SANE_STATUS_GOOD)
225 TRACE("PENDINGXFERS/MSG_ENDXFER sane_start returns %s\n", psane_strstatus(status));
226 pPendingXfers->Count = 0;
227 activeDS.currentState = 5;
228 /* Notify the application that it can close the data source */
229 SANE_Notify(MSG_CLOSEDSREQ);
231 else
232 activeDS.sane_started = TRUE;
234 twRC = TWRC_SUCCESS;
235 activeDS.twCC = TWCC_SUCCESS;
238 return twRC;
239 #endif
242 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_GET */
243 TW_UINT16 SANE_PendingXfersGet (pTW_IDENTITY pOrigin,
244 TW_MEMREF pData)
246 #ifndef SONAME_LIBSANE
247 return TWRC_FAILURE;
248 #else
249 TW_UINT16 twRC = TWRC_SUCCESS;
250 pTW_PENDINGXFERS pPendingXfers = (pTW_PENDINGXFERS) pData;
251 SANE_Status status;
253 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_GET\n");
255 if (activeDS.currentState < 4 || activeDS.currentState > 7)
257 twRC = TWRC_FAILURE;
258 activeDS.twCC = TWCC_SEQERROR;
260 else
262 pPendingXfers->Count = -1;
263 if (! activeDS.sane_started)
265 status = psane_start (activeDS.deviceHandle);
266 if (status != SANE_STATUS_GOOD)
268 TRACE("PENDINGXFERS/MSG_GET sane_start returns %s\n", psane_strstatus(status));
269 pPendingXfers->Count = 0;
271 else
272 activeDS.sane_started = TRUE;
274 twRC = TWRC_SUCCESS;
275 activeDS.twCC = TWCC_SUCCESS;
278 return twRC;
279 #endif
282 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET */
283 TW_UINT16 SANE_PendingXfersReset (pTW_IDENTITY pOrigin,
284 TW_MEMREF pData)
286 #ifndef SONAME_LIBSANE
287 return TWRC_FAILURE;
288 #else
289 TW_UINT16 twRC = TWRC_SUCCESS;
290 pTW_PENDINGXFERS pPendingXfers = (pTW_PENDINGXFERS) pData;
292 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET\n");
294 if (activeDS.currentState != 6)
296 twRC = TWRC_FAILURE;
297 activeDS.twCC = TWCC_SEQERROR;
299 else
301 pPendingXfers->Count = 0;
302 activeDS.currentState = 5;
303 twRC = TWRC_SUCCESS;
304 activeDS.twCC = TWCC_SUCCESS;
306 if (activeDS.sane_started)
308 psane_cancel (activeDS.deviceHandle);
309 activeDS.sane_started = FALSE;
313 return twRC;
314 #endif
317 /* DG_CONTROL/DAT_SETUPMEMXFER/MSG_GET */
318 TW_UINT16 SANE_SetupMemXferGet (pTW_IDENTITY pOrigin,
319 TW_MEMREF pData)
321 #ifndef SONAME_LIBSANE
322 return TWRC_FAILURE;
323 #else
324 pTW_SETUPMEMXFER pSetupMemXfer = (pTW_SETUPMEMXFER)pData;
326 TRACE("DG_CONTROL/DAT_SETUPMEMXFER/MSG_GET\n");
327 if (activeDS.sane_param_valid)
329 pSetupMemXfer->MinBufSize = activeDS.sane_param.bytes_per_line;
330 pSetupMemXfer->MaxBufSize = activeDS.sane_param.bytes_per_line * 8;
331 pSetupMemXfer->Preferred = activeDS.sane_param.bytes_per_line * 2;
333 else
335 /* Guessing */
336 pSetupMemXfer->MinBufSize = 2000;
337 pSetupMemXfer->MaxBufSize = 8000;
338 pSetupMemXfer->Preferred = 4000;
341 return TWRC_SUCCESS;
342 #endif
345 /* DG_CONTROL/DAT_STATUS/MSG_GET */
346 TW_UINT16 SANE_GetDSStatus (pTW_IDENTITY pOrigin,
347 TW_MEMREF pData)
349 pTW_STATUS pSourceStatus = (pTW_STATUS) pData;
351 TRACE ("DG_CONTROL/DAT_STATUS/MSG_GET\n");
352 pSourceStatus->ConditionCode = activeDS.twCC;
353 /* Reset the condition code */
354 activeDS.twCC = TWCC_SUCCESS;
355 return TWRC_SUCCESS;
358 /* DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS */
359 TW_UINT16 SANE_DisableDSUserInterface (pTW_IDENTITY pOrigin,
360 TW_MEMREF pData)
362 TW_UINT16 twRC = TWRC_SUCCESS;
364 TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS\n");
366 if (activeDS.currentState != 5)
368 twRC = TWRC_FAILURE;
369 activeDS.twCC = TWCC_SEQERROR;
371 else
373 activeDS.currentState = 4;
374 twRC = TWRC_SUCCESS;
375 activeDS.twCC = TWCC_SUCCESS;
378 return twRC;
381 /* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS */
382 TW_UINT16 SANE_EnableDSUserInterface (pTW_IDENTITY pOrigin,
383 TW_MEMREF pData)
385 TW_UINT16 twRC = TWRC_SUCCESS;
386 pTW_USERINTERFACE pUserInterface = (pTW_USERINTERFACE) pData;
388 TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS\n");
390 if (activeDS.currentState != 4)
392 twRC = TWRC_FAILURE;
393 activeDS.twCC = TWCC_SEQERROR;
394 WARN("sequence error %d\n", activeDS.currentState);
396 else
398 activeDS.hwndOwner = pUserInterface->hParent;
399 if (pUserInterface->ShowUI)
401 BOOL rc;
402 activeDS.currentState = 5; /* Transitions to state 5 */
403 rc = DoScannerUI();
404 pUserInterface->ModalUI = TRUE;
405 if (!rc)
407 SANE_Notify(MSG_CLOSEDSREQ);
409 #ifdef SONAME_LIBSANE
410 else
412 psane_get_parameters (activeDS.deviceHandle, &activeDS.sane_param);
413 activeDS.sane_param_valid = TRUE;
415 #endif
417 else
419 /* no UI will be displayed, so source is ready to transfer data */
420 activeDS.currentState = 6; /* Transitions to state 6 directly */
421 SANE_Notify(MSG_XFERREADY);
424 twRC = TWRC_SUCCESS;
425 activeDS.twCC = TWCC_SUCCESS;
428 return twRC;
431 /* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY */
432 TW_UINT16 SANE_EnableDSUIOnly (pTW_IDENTITY pOrigin,
433 TW_MEMREF pData)
435 TW_UINT16 twRC = TWRC_SUCCESS;
437 TRACE("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY\n");
439 if (activeDS.currentState != 4)
441 twRC = TWRC_FAILURE;
442 activeDS.twCC = TWCC_SEQERROR;
444 else
446 /* FIXME: we should replace xscanimage with our own UI */
447 system ("xscanimage");
448 activeDS.currentState = 5;
449 twRC = TWRC_SUCCESS;
450 activeDS.twCC = TWCC_SUCCESS;
453 return twRC;
456 /* DG_CONTROL/DAT_XFERGROUP/MSG_GET */
457 TW_UINT16 SANE_XferGroupGet (pTW_IDENTITY pOrigin,
458 TW_MEMREF pData)
460 FIXME ("stub!\n");
462 return TWRC_FAILURE;
465 /* DG_CONTROL/DAT_XFERGROUP/MSG_SET */
466 TW_UINT16 SANE_XferGroupSet (pTW_IDENTITY pOrigin,
467 TW_MEMREF pData)
469 FIXME ("stub!\n");
471 return TWRC_FAILURE;